How to use the mobiledoc-kit/editor/editor function in mobiledoc-kit

To help you get started, we’ve selected a few mobiledoc-kit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TryGhost / Ghost-Admin / lib / koenig-editor / addon / components / koenig-basic-html-input.js View on Github external
this.willCreateEditor();

        // teardown any old editor that might be around
        let editor = this.editor;
        if (editor) {
            editor.destroy();
        }

        // create a new editor
        let editorOptions = this.editorOptions;
        editorOptions.mobiledoc = mobiledoc;
        editorOptions.showLinkTooltips = false;
        editorOptions.undoDepth = UNDO_DEPTH;
        editorOptions.parserPlugins = parserPlugins;

        editor = new Editor(editorOptions);

        registerKeyCommands(editor, this, BASIC_KEY_COMMANDS);
        registerBasicTextExpansions(editor);

        // set up editor hooks
        editor.willRender(() => {
            // The editor's render/rerender will happen after this `editor.willRender`,
            // so we explicitly start a runloop here if there is none, so that the
            // add/remove card hooks happen inside a runloop.
            // When pasting text that gets turned into a card, for example,
            // the add card hook would run outside the runloop if we didn't begin a new
            // one now.
            if (!run.currentRunLoop) {
                this._startedRunLoop = true;
                run.begin();
            }
github bustle / ember-mobiledoc-editor / addon / components / mobiledoc-editor / component.js View on Github external
});
        return { atom, element };
      },
      [REMOVE_CARD_HOOK]: (card) => {
        this.get('componentCards').removeObject(card);
      },
      [REMOVE_ATOM_HOOK]: (atom) => {
        this.get('componentAtoms').removeObject(atom);
      }
    };
    if (editorOptions.cardOptions) {
      editorOptions.cardOptions = assign(editorOptions.cardOptions, componentHooks);
    } else {
      editorOptions.cardOptions = componentHooks;
    }
    editor = new Editor(editorOptions);
    editor.willRender(() => {
      // The editor's render/rerender will happen after this `editor.willRender`,
      // so we explicitly start a runloop here if there is none, so that the
      // add/remove card hooks happen inside a runloop.
      // When pasting text that gets turned into a card, for example,
      // the add card hook would run outside the runloop if we didn't begin a new
      // one now.
      if (!run.currentRunLoop) {
        this._startedRunLoop = true;
        begin();
      }
    });
    editor.didRender(() => {
      // If we had explicitly started a run loop in `editor.willRender`,
      // we must explicitly end it here.
      if (this._startedRunLoop) {
github TryGhost / Ghost-Admin / lib / koenig-editor / addon / components / koenig-editor.js View on Github external
// after render we render the full ember card via {{-in-element}}
                run.schedule('afterRender', () => {
                    this.componentCards.pushObject(card);
                });

                // render the destination element inside the editor
                return {card, element: destinationElement};
            },
            // triggered when a card section is removed from the mobiledoc
            [REMOVE_CARD_HOOK]: (card) => {
                this.componentCards.removeObject(card);
            }
        };
        editorOptions.cardOptions = componentHooks;

        editor = new Editor(editorOptions);

        // set up key commands and text expansions (MD conversion)
        // TODO: this will override any passed in options, we should allow the
        // default behaviour to be overridden by addon consumers
        registerKeyCommands(editor, this);
        registerTextExpansions(editor, this);

        // set up editor hooks
        editor.willRender(() => {
            // The editor's render/rerender will happen after this `editor.willRender`,
            // so we explicitly start a runloop here if there is none, so that the
            // add/remove card hooks happen inside a runloop.
            // When pasting text that gets turned into a card, for example,
            // the add card hook would run outside the runloop if we didn't begin a new
            // one now.
            if (!run.currentRunLoop) {
github TryGhost / Ghost-Admin / lib / gh-koenig--old / addon / components / gh-koenig.js View on Github external
this._willCreateEditor();

        // teardown any old editor that might be around
        let editor = this.get('editor');
        if (editor) {
            editor.destroy();
        }

        // create a new editor
        let editorOptions = this.get('editorOptions');
        editorOptions.mobiledoc = mobiledoc;

        // TODO: instantiate component hooks?
        // https://github.com/bustlelabs/ember-mobiledoc-editor/blob/master/addon/components/mobiledoc-editor/component.js#L163-L227

        editor = new Editor(editorOptions);

        // set up our default key handling and text expansions to emulate MD behaviour
        // TODO: better place to do this?
        registerKeyCommands(editor);
        registerTextExpansions(editor);

        editor.willRender(() => {
            // The editor's render/rerender will happen after this `editor.willRender`,
            // so we explicitly start a runloop here if there is none, so that the
            // add/remove card hooks happen inside a runloop.
            // When pasting text that gets turned into a card, for example,
            // the add card hook would run outside the runloop if we didn't begin a new
            // one now.
            if (!run.currentRunLoop) {
                this._startedRunLoop = true;
                run.begin();
github bustle / mobiledoc-kit / tests / helpers / mobiledoc.js View on Github external
function renderInto(element, treeFn, editorOptions={}) {
  let mobiledoc = build(treeFn);
  mergeWithOptions(editorOptions, {mobiledoc});
  let editor = new Editor(editorOptions);
  editor.render(element);
  return editor;
}
github bustle / mobiledoc-kit / tests / helpers / mobiledoc.js View on Github external
function renderPostInto(element, post, editorOptions={}) {
  let mobiledoc = mobiledocRenderers.render(post);
  mergeWithOptions(editorOptions, {mobiledoc});
  let editor = new Editor(editorOptions);
  editor.render(element);
  return editor;
}
github bustle / mobiledoc-kit / tests / helpers / editor.js View on Github external
function buildFromText(texts, editorOptions={}) {
  let renderElement = editorOptions.element;
  delete editorOptions.element;

  let {post, range} = PostAbstractHelpers.buildFromText(texts);
  let mobiledoc = MobiledocRenderer.render(post);
  editorOptions.mobiledoc = mobiledoc;
  let editor = new Editor(editorOptions);
  if (renderElement) {
    editor.render(renderElement);
    range = retargetRange(range, editor.post);
    editor.selectRange(range);
  }
  return editor;
}