npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-ace

v3.0.0

Published

An Ember addon for the Ace code editor

Downloads

8,201

Readme

Ember Ace Build Status

An Ember component wrapping Ace editor.

Installation

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

Usage

<AceEditor
  @value={{this.code}}
  @update={{this.updateCode}}
  @options={{hash
    minLines=5
    maxLines=20
    theme='ace/theme/chaos'
    mode='ace/mode/css'
  }}
/>

Component Args

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 Ace Editor 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.

Configuring Ace

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:

<AceEditor @options={{hash theme='ace/theme/ambiance'}} />

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

Background Workers

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.