@folijs/core
v0.2.0
Published
Document model and headless editing engine of Foli: format, validation, schema, transactions, history, commands. No DOM.
Downloads
591
Readme
@folijs/core
The document model and headless editing engine of Foli: document format and validation, schema, transactions, undo history and commands. No DOM: runs in the browser, Node and workers.
Early release: the API may change in any 0.x minor version (changes in
CHANGELOG.md).
npm install @folijs/coreimport { createDocument, createEditor, parseDocument } from "@folijs/core";
const text = JSON.stringify(createDocument()); // stand-in for a saved document
const doc = parseDocument(JSON.parse(text)); // throws FoliDocumentError on invalid input
const editor = createEditor({ document: doc });
editor.subscribe((_state, transactions) => {
if (transactions.some((tr) => tr.docChanged)) console.log("content changed");
});
editor.select(1); // inside the first paragraph
editor.commands.toggleMark("bold"); // the next typed text is bold
editor.commands.insertText("Hello");
const saved = JSON.stringify(editor.getDocument());To show and edit a document in the browser, use @folijs/react
or @folijs/view.
MIT
