mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
07d89262f1
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
37 lines
932 B
JavaScript
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;
|
|
}
|
|
};
|
|
}
|