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-buildsSee 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 AceEditoris 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 the bundler to treat those modules as external resources, meaning they'll be included as standalone files in your build output and you'll receive the resulting URL for those files when you import them.
import { config } from 'ace-builds';
import jsWorkerUrl from 'ace-builds/src-noconflict/worker-javascript?url';
config.setModuleUrl('ace/mode/javascript_worker', jsWorkerUrl);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 '*?url' {
const url: string;
export default url;
}In Vite, the ?url suffix will automatically opt into treating the target file as an external resource.
In Webpack (via ember-auto-import or @embroider/compat), this behaviour must be configured.
// ember-cli-build.js
let app = new EmberApp(defaults, {
autoImport: {
webpack: {
module: {
rules: [
// Treat imports with `?url` as external resources
{
resourceQuery: /url/,
type: 'asset/resource',
},
],
},
},
},
});See the Webpack documentation on asset modules for more details and configuration options.