Ghost/ghost/admin/lib/koenig-editor/addon/utils/create-component-atom.js
Kevin Ansfield 07d89262f1 Prototyped component based atoms in the editor
refs https://github.com/TryGhost/Team/issues/931

- adds handling for component atoms
- add prototype button atom to test atom behaviour
- add `Cmd+Shift+B` keyboard shortcut to create a dummy button atom when the `emailCardSegments` feature is enabled
2021-07-22 18:54:46 +01:00

37 lines
932 B
JavaScript

import {
ADD_ATOM_HOOK,
REMOVE_ATOM_HOOK
} from '../components/koenig-editor';
const RENDER_TYPE = 'dom';
function renderFallback(doc) {
let element = doc.createElement('span');
let text = doc.createTextNode('[placeholder for Ember component atom]');
element.appendChild(text);
return element;
}
// sets up boilderplate for an Ember component atom
export default function createComponentAtom(name, doc = window.document) {
return {
name,
type: RENDER_TYPE,
// Called when the atom is added to a mobiledoc document.
render(atomArgs) {
const {env, options} = atomArgs;
if (!options[ADD_ATOM_HOOK]) {
return renderFallback(doc);
}
const {atom, element} = options[ADD_ATOM_HOOK](atomArgs);
env.onTeardown(() => options[REMOVE_ATOM_HOOK](atom));
return element;
}
};
}