Repository: CarterLi/vue3-ace-editor Branch: master Commit: 68e4aef2e31b Files: 9 Total size: 18.2 KB Directory structure: gitextract_hmq5fgcx/ ├── .gitignore ├── LICENSE ├── README.md ├── index.d.ts ├── index.js ├── index.ts ├── package.json ├── tsconfig.json └── types.d.ts ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ /node_modules /*.log /demo-source ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2020 Carter Li Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ vue3-ace-editor ==================== [![npm](https://img.shields.io/npm/v/vue3-ace-editor.svg)](https://www.npmjs.com/package/vue3-ace-editor) A packaging of [ace](https://ace.c9.io/). Inspired by [vue2-ace-editor](https://github.com/chairuosen/vue2-ace-editor), but supports [Vue 3](https://github.com/vuejs/vue-next) ## Install `ace-builds` must be installed alongside `vue3-ace-editor` using your favorite package manager. * npm i vue3-ace-editor ace-builds * yarn add vue3-ace-editor ace-builds * pnpm i vue3-ace-editor ace-builds ## Usage ```vue ``` Property `v-model:value` is required. `` has no height by default. Its height must be specified manually, or set both `min-lines` and `max-lines` to make the editor's height auto-grow. Property `lang`, `theme` is same as [ace-editor's doc](https://github.com/ajaxorg/ace) ## Load modes and themes (**REQUIRED**) Using of `ace-builds/webpack-resolver` is removed due to bug https://github.com/CarterLi/vue3-ace-editor/issues/3. You **MUST** import `theme` and `mode` yourself. eg. ```js // You MUST make sure that `ace-builds` or `vue3-ace-editor` (which imports `ace-builds` internally) is loaded before importing `mode` and `theme` import 'ace-builds/src-noconflict/mode-json'; import 'ace-builds/src-noconflict/theme-chrome'; ``` To use dynamic loading to avoid first-load overhead ```js import ace from 'ace-builds'; import modeJsonUrl from 'ace-builds/src-noconflict/mode-json?url'; ace.config.setModuleUrl('ace/mode/json', modeJsonUrl); import themeChromeUrl from 'ace-builds/src-noconflict/theme-chrome?url'; ace.config.setModuleUrl('ace/theme/chrome', themeChromeUrl); ``` Note that to make search box (`Ctrl+F` or `Command+F`) work, `ext-searchbox` must also be loaded. ```js import extSearchboxUrl from 'ace-builds/src-noconflict/ext-searchbox?url'; ace.config.setModuleUrl('ace/ext/searchbox', extSearchboxUrl); ``` Find all supported themes and modes in `node_modules/ace-builds/src-noconflict` ## Deferences with [vue2-ace-editor](https://github.com/chairuosen/vue2-ace-editor) 1. This component uses [ace-builds](https://www.npmjs.com/package/ace-builds) directly, instead of the outdated wrapper [brace](https://www.npmjs.com/package/brace) 1. DOM size changes are detected automatically using [ResizeObserver](resize-observer-polyfill), thus no `width` / `height` props needed. 1. For easier usage, more props / events added / emitted. 1. Prop `readonly`: This Boolean attribute indicates that the user cannot modify the value of the control. 1. Prop `placeholder`: A hint to the user of what can be entered in the control. 1. Prop `wrap`: Indicates whether the control wraps text. 1. Prop `printMargin`: A short hand of `showPrintMargin` and `printMarginColumn`. 1. Prop `minLines` and `maxLines`: Specifiy the minimum and maximum number of lines. 1. All ace events emitted. Docs can be found here: 1. Some commonly used methods `focus`, `blur`, `selectAll` provided as shortcuts. ## Get raw ace instance Use `getAceInstance` ```vue ``` `@init` is provided for `vue2-ace-editor` compatibility only but is not recommanded to use. ## Enable syntax checking To enable syntax checking, module `ace/mode/lang_worker` must be registered, and option `useWorker: true` must be set. Take JSON for example: ```ts import workerJsonUrl from 'ace-builds/src-noconflict/worker-json?url'; // For vite import workerJsonUrl from 'file-loader?esModule=false!ace-builds/src-noconflict/worker-json.js'; // For webpack / vue-cli ace.config.setModuleUrl('ace/mode/json_worker', workerJsonUrl); ``` ```html ``` See also https://github.com/CarterLi/vue3-ace-editor/issues/3#issuecomment-768190528 to load the worker file from CDN ## Minimal example using vite * Preview: * Source: ## Use it with Nuxt Since ace doesn't support SSR, using it with Nuxt can be tricky. You must make sure that `ace` related things are loaded only at client side. ```vue