EXAMPLES
Try it. Read the code.
Working examples from the package guides. Changes here are temporary. Reset or switch examples to start again.
JavaScript / DOM
Create a small editor with paragraph, bold, and italic support.
Click the text, type a sentence, then try undo and redo.
LIVE PREVIEW
Source code
This is the code that runs in the preview.
import { Editor } from '@barocss/editor-core';
import { DataStore } from '@barocss/datastore';
import { createSchema, getMinimalSchemaDefinition } from '@barocss/schema';
import { createCoreExtensions, BoldExtension, ItalicExtension } from '@barocss/extensions';
import { RendererRegistry, intoRegistry, define, defineMark, element, data, slot } from '@barocss/dsl';
import { EditorViewDOM } from '@barocss/editor-view-dom';
export function mountEditor(container: HTMLElement) {
const registry = new RendererRegistry({ global: false });
intoRegistry(registry, () => {
define('document', element('div', { style: { whiteSpace: 'pre-wrap' } }, [slot('content')]));
define('paragraph', element('p', {}, [slot('content')]));
define('inline-text', element('span', {}, [data('text', '')]));
defineMark('bold', element('strong', {}, [data('text')]));
defineMark('italic', element('em', {}, [data('text')]));
});
const schema = createSchema('quick-start', getMinimalSchemaDefinition());
const editor = new Editor({
schema, dataStore: new DataStore(undefined, schema), editable: true,
extensions: [...createCoreExtensions(), BoldExtension, ItalicExtension],
});
editor.loadDocument({ stype: 'document', content: [
{ stype: 'paragraph', content: [{ stype: 'inline-text', text: 'Start writing here.' }] },
]});
const view = new EditorViewDOM(editor, { container, registry });
view.render();
return () => {
view.destroy();
editor.destroy();
};
}
See the integration guide for installation and lifecycle details. Office examples also require the host styling setup.