An Ember component wrapping Ace editor.
Install this ember-ace
package and its peer dependency ace-builds
using your package manager of choice:
yarn add ember-ace ace-builds
# or
npm install ember-ace ace-builds
# or
pnpm install ember-ace ace-builds
See the application controller in this addon's test application for usage examples of several editor options.
@value: string
: the string value of the editor@update: (newValue: string) => void
: a callback invoked when the value of the editor changes@options: Partial<Ace.EditorOptions>
: options to be passed to the Ace editor instance@ready: (editor: Ace.Editor) => void
: a callback invoked when the AceEditor
is instantiated, for finer-grained control than just setting@options
Valid keys to include in @options
are any member of the Ace.EditorOptions
interface, which also includes Ace.EditSessionOptions
, Ace.MouseHandlerOptions
and Ace.VirtualRendererOptions
.
Ace distributes individual themes, editor modes, and so on in individual modules in order to allow you to opt in to having them individually included in your build rather than paying the cost in bundle size of including every single one. You can import these modules to make them available when configuring your editor.
For example, by adding the following somewhere in your project:
import 'ace-builds/src-noconflict/theme-ambiance';
You can then use the ambiance
theme for your editor:
While the paths aren't identical, generally you can map from the on-disk path ace-builds/src-noconflict/{type}-{name}
to a config value ace/{type}/{name}
, where type
is one of:
theme
: color schemes for the editor (see all)mode
: syntax highlighting and editor behaviors for different languages (see all)ext
: editor extensions, like spellcheck and Emmet abbreviations (see all)keybinding
: common keybindings from editors like Emacs and Vim (see all
Some editor modes include background workers that can perform more expensive processing to provide a richer editing experience. Since these modules are always loaded in a background worker, you can't include them directly in your build. Instead, you need to make them available to load at runtime and tell Ace where to find them.
The easiest way to do this is by asking Webpack to treat those modules as external resources, meaning the bundler will include them as standalone files in your build output and provide you with a URL for those those files when you attempt to import them.
// ember-cli-build.js
let app = new EmberApp(defaults, {
autoImport: {
webpack: {
module: {
rules: [
// Treat imports with `?resource` as external resources
{
resourceQuery: /resource/,
type: 'asset/resource',
},
],
},
},
},
});
import { config } from 'ace-builds';
import * as jsWorkerUrl from 'ace-builds/src-noconflict/worker-javascript?resource';
config.setModuleUrl('ace/mode/javascript_worker', jsWorkerUrl);
Note: under Embroider, asset modules produce a default export instead, so you'd write import jsWorkerUrl from '...'
.
For TypeScript use, you can put the following in a .d.ts
file in your project to ensure the worker URL imports are treated correctly:
declare module '*?resource' {
const url: string;
// In a classic app with auto-import:
export = url;
// In an Embroider app:
export default url;
}
See the Webpack documentation on asset modules for more details and configuration options.