typewriter-editor
Version:
A rich text editor using the Delta format with decorations and rendered with a tiny virtual dom
24 lines (23 loc) • 657 B
JavaScript
import { docFromDom } from './rendering/html';
// A svelte action to set the root for your Editor to an element. E.g.
// <div class="my-editor" use:asRoot={myEditor}></div>
export function asRoot(root, editor) {
function update(newEditor) {
if (editor === newEditor)
return;
destroy();
if (newEditor)
newEditor.setRoot(root);
editor = newEditor;
}
if (root.children.length) {
editor.set(docFromDom(editor, root));
}
if (editor)
editor.setRoot(root);
function destroy() {
if (editor)
editor.destroy();
}
return { update, destroy };
}