|
1 | 1 | ## ember-mobiledoc-editor |
2 | 2 |
|
3 | 3 | [](https://badge.fury.io/js/ember-mobiledoc-editor) |
4 | | -[](https://travis-ci.org/bustle/ember-mobiledoc-editor) |
| 4 | +[](https://github.com/bustle/ember-mobiledoc-editor/actions/workflows/ci.yml) |
5 | 5 | [](https://emberobserver.com/addons/ember-mobiledoc-editor) |
6 | 6 |
|
7 | 7 | A Mobiledoc editor written using Ember.js UI components and |
@@ -75,40 +75,44 @@ The component accepts these arguments: |
75 | 75 | The action is passed the created editor instance. |
76 | 76 | This action may be fired more than once if the component's `mobiledoc` property is set to a new value. |
77 | 77 |
|
78 | | -For example, the following index route and template would log before and |
| 78 | +For example, the following component and template would log before and |
79 | 79 | after creating the MobiledocKitEditor, and every time the user modified the |
80 | 80 | mobiledoc (by typing some text, e.g.). |
81 | 81 |
|
82 | 82 | ```javascript |
83 | | -// routes/index.js |
84 | | - |
85 | | -export default Ember.Route.extend({ |
86 | | - ..., |
87 | | - actions: { |
88 | | - mobiledocWasUpdated(updatedMobiledoc) { |
89 | | - console.log('New mobiledoc:',updatedMobiledoc); |
90 | | - // note that this action will be fired for every changed character, |
91 | | - // so you may want to debounce API calls if you are using it for |
92 | | - // an "autosave" feature. |
93 | | - }, |
94 | | - willCreateEditor() { |
95 | | - console.log('about to create the editor'); |
96 | | - }, |
97 | | - didCreateEditor(editor) { |
98 | | - console.log('created the editor:', editor); |
99 | | - } |
100 | | - } |
101 | | -}); |
| 83 | +// components/my-editor.js |
| 84 | +import Component from '@glimmer/component'; |
| 85 | +import { action } from '@ember/object'; |
| 86 | + |
| 87 | +export default class MyEditor extends Component { |
| 88 | + @action |
| 89 | + mobiledocWasUpdated(updatedMobiledoc) { |
| 90 | + console.log('New mobiledoc:', updatedMobiledoc); |
| 91 | + // note that this handler will be fired for every changed character, |
| 92 | + // so you may want to debounce API calls if you are using it for |
| 93 | + // an "autosave" feature. |
| 94 | + } |
| 95 | + |
| 96 | + @action |
| 97 | + willCreateEditor() { |
| 98 | + console.log('about to create the editor'); |
| 99 | + } |
| 100 | + |
| 101 | + @action |
| 102 | + didCreateEditor(editor) { |
| 103 | + console.log('created the editor:', editor); |
| 104 | + } |
| 105 | +} |
102 | 106 | ``` |
103 | 107 |
|
104 | 108 | ```hbs |
105 | | -{{! index.hbs }} |
| 109 | +{{! components/my-editor.hbs }} |
106 | 110 |
|
107 | | -{{mobiledoc-editor |
108 | | - on-change=(action 'mobiledocWasUpdated') |
109 | | - will-create-editor=(action 'willCreateEditor') |
110 | | - did-create-editor=(action 'didCreateEditor') |
111 | | -}} |
| 111 | +<MobiledocEditor |
| 112 | + @on-change={{this.mobiledocWasUpdated}} |
| 113 | + @will-create-editor={{this.willCreateEditor}} |
| 114 | + @did-create-editor={{this.didCreateEditor}} |
| 115 | +/> |
112 | 116 | ``` |
113 | 117 |
|
114 | 118 | Of course often you want to provide a user interface to bold text, create |
@@ -294,22 +298,18 @@ components as the display and edit modes of a card. Create a list of cards |
294 | 298 | using the `createComponentCard` helper: |
295 | 299 |
|
296 | 300 | ```js |
297 | | -import Ember from 'ember'; |
| 301 | +import Component from '@glimmer/component'; |
298 | 302 | import createComponentCard from 'ember-mobiledoc-editor/utils/create-component-card'; |
299 | 303 |
|
300 | | -export default Ember.Component.extend({ |
301 | | - cards: Ember.computed(function() { |
302 | | - return [ |
303 | | - createComponentCard('demo-card') |
304 | | - ]; |
305 | | - }) |
306 | | -}); |
| 304 | +export default class MyEditor extends Component { |
| 305 | + cards = [createComponentCard('demo-card')]; |
| 306 | +} |
307 | 307 | ``` |
308 | 308 |
|
309 | 309 | And pass that list into the `{{mobiledoc-editor}}` component: |
310 | 310 |
|
311 | 311 | ```hbs |
312 | | -{{mobiledoc-editor cards=cards}} |
| 312 | +<MobiledocEditor @cards={{this.cards}} /> |
313 | 313 | ``` |
314 | 314 |
|
315 | 315 | When added to the post (or loaded from a passed-in Mobiledoc), these components |
@@ -341,27 +341,23 @@ ember-mobiledoc-editor comes with a handle helper for using Ember |
341 | 341 | components as an atom. Create a list of atoms using the `createComponentAtom` helper: |
342 | 342 |
|
343 | 343 | ```js |
344 | | -import Ember from 'ember'; |
| 344 | +import Component from '@glimmer/component'; |
345 | 345 | import createComponentAtom from 'ember-mobiledoc-editor/utils/create-component-atom'; |
346 | 346 |
|
347 | | -export default Ember.Component.extend({ |
348 | | - atoms: Ember.computed(function() { |
349 | | - return [ |
350 | | - createComponentAtom('demo-atom') |
351 | | - ]; |
352 | | - }) |
353 | | -}); |
| 347 | +export default class MyEditor extends Component { |
| 348 | + atoms = [createComponentAtom('demo-atom')]; |
| 349 | +} |
354 | 350 | ``` |
355 | 351 |
|
356 | 352 | And pass that list into the `{{mobiledoc-editor}}` component: |
357 | 353 |
|
358 | 354 | ```hbs |
359 | | -{{mobiledoc-editor atoms=atoms}} |
| 355 | +<MobiledocEditor @atoms={{this.atoms}} /> |
360 | 356 | ``` |
361 | 357 |
|
362 | 358 | ### Editor Lifecycle Hooks |
363 | 359 |
|
364 | | -Currently editor lifecycle hooks are available by available by extending the mobiledoc-editor component. |
| 360 | +Currently editor lifecycle hooks are available by extending the mobiledoc-editor component. |
365 | 361 |
|
366 | 362 | ```js |
367 | 363 | import Component from 'ember-mobiledoc-editor/components/mobiledoc-editor/component'; |
@@ -390,48 +386,47 @@ ember-mobiledoc-editor exposes two test helpers for use in your acceptance tests |
390 | 386 | Example usage: |
391 | 387 | ```javascript |
392 | 388 | // acceptance test |
393 | | -import { insertText, run } from '../../helpers/ember-mobiledoc-editor'; |
394 | | -import { find } from '@enber/test-helpers'; |
395 | | -test('visit /', function(assert) { |
396 | | - visit('/'); |
397 | | - andThen(() => { |
398 | | - let editorEl = find('.mobiledoc-editor__editor'); |
399 | | - return insertText(editorEl, 'here is some text'); |
400 | | - /* Or: |
401 | | - return run(editorEl, (postEditor) => ...); |
402 | | - */ |
403 | | - }); |
404 | | - andThen(() => { |
| 389 | +import { module, test } from 'qunit'; |
| 390 | +import { setupApplicationTest } from 'ember-qunit'; |
| 391 | +import { visit, find } from '@ember/test-helpers'; |
| 392 | +import { insertText, run } from '../helpers/ember-mobiledoc-editor'; |
| 393 | + |
| 394 | +module('Acceptance | editor', function (hooks) { |
| 395 | + setupApplicationTest(hooks); |
| 396 | + |
| 397 | + test('visiting /', async function (assert) { |
| 398 | + await visit('/'); |
| 399 | + |
| 400 | + const editorEl = find('.mobiledoc-editor__editor'); |
| 401 | + await insertText(editorEl, 'here is some text'); |
| 402 | + // Or: await run(editorEl, (postEditor) => ...); |
| 403 | + |
405 | 404 | // assert text inserted, etc. |
406 | 405 | }); |
407 | 406 | }); |
408 | 407 | ``` |
409 | 408 |
|
410 | 409 | ### Developing ember-mobiledoc-editor |
411 | 410 |
|
412 | | -Releasing a new version: |
413 | | - |
414 | | -This README outlines the details of collaborating on this Ember addon. |
415 | | - |
416 | | -## Installation |
| 411 | +#### Setup |
417 | 412 |
|
418 | | -* `git clone <repository-url>` this repository |
| 413 | +* `git clone git@github.com:bustle/ember-mobiledoc-editor.git` |
419 | 414 | * `cd ember-mobiledoc-editor` |
420 | 415 | * `pnpm install` |
421 | 416 |
|
422 | 417 | Run the development server: |
423 | 418 |
|
424 | | -* `ember serve` |
425 | | -* Visit your app at [http://localhost:4200](http://localhost:4200). |
| 419 | +* `pnpm start` |
| 420 | +* Visit the dummy app at [http://localhost:4200](http://localhost:4200). |
426 | 421 |
|
427 | | -## Running Tests |
| 422 | +#### Running Tests |
428 | 423 |
|
429 | | -* `pnpm test` (Runs `ember try:each` to test your addon against multiple Ember versions) |
430 | | -* `ember test` |
431 | | -* `ember test --server` |
| 424 | +* `pnpm test` — runs lint, the current-Ember test suite, and `ember try:each` against every supported Ember version. |
| 425 | +* `pnpm test:ember` — runs the dummy-app test suite once. |
| 426 | +* `ember test --server` — dev-friendly watcher. |
432 | 427 |
|
433 | | -## Building |
| 428 | +#### Building |
434 | 429 |
|
435 | | -* `ember build` |
| 430 | +* `pnpm build` |
436 | 431 |
|
437 | 432 | For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/). |
0 commit comments