项目作者: mwalper

项目描述 :
Add the Trix Editor into an Ember Octane Project.
高级语言: JavaScript
项目地址: git://github.com/mwalper/ember-trix.git
创建时间: 2020-10-08T09:05:02Z
项目社区:https://github.com/mwalper/ember-trix

开源协议:MIT License

下载


ember-trix

Ember Trix wraps the Trix Editor in a
Glimmer Component for use in an Ember Octane Project.

This Addon is a rewrite of ember-trix-editor
featuring Ember Octane style Glimmer Components and modifiers.
It does not rely on jQuery.

Compatibility

  • Ember.js v3.16 or above
  • Ember CLI v2.13 or above
  • Node.js v10 or above

Installation

  1. ember install ember-trix

Addon Configuration

You can optionally just import trix-core with the following setting:

  1. /* ember-cli-build.js */
  2. let app = new EmberApp(defaults, {
  3. 'ember-trix': {
  4. coreOnly: true
  5. }
  6. });

Usage

The only mandatory argument is the ID and is supposed to be unique. The onChange argument is a convenient way to receive the current state. All attributes like class or placeholder
are optional and passed down via ...attributes. Feel free to add other attributes like autofocus={{true}} etc. onto it.

  1. <TrixInput
  2. @id="myId"
  3. @value="My <em>initial</em> Content"
  4. @onChange={{this.onTrixUpdate}}
  5. class="my-class my-other-class"
  6. />
  1. import Component from '@glimmer/component';
  2. import { action } from '@ember/object';
  3. export default class MyContainerComponent extends Component
  4. {
  5. @action
  6. onTrixUpdate(formatedText) {
  7. console.log(formatedText);
  8. }
  9. }

Optionally you can listen to trix-events by adding them as arguments:

  1. <TrixInput
  2. @id="myId"
  3. @trixFocus={{this.onFocus}}
  4. @trixBlur={{this.onFocusOut}}
  5. @trixAttachmentAdd={{this.selectAttachment}}
  6. placeholder="Optional string shown when value is empty"
  7. ></TrixInput>

The the following Events are available:

  • trix-attachment-add
  • trix-attachment-remove
  • trix-blur
  • trix-focus
  • trix-change
  • trix-file-accept
  • trix-initialize
  • trix-before-initialize
  • trix-selection-change

All of them will pass up a JavaScript event from which the editor property can be extracted.

There is also a hidden input field available, holding the formatted text from the Trix editor.

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.