smartrte-core
v1.1.0
Published
Framework-agnostic document model and editing primitives for Smart RTE
Readme
smartrte-core
Framework-agnostic document model, selection, transaction, and editing primitives that power smartrte-react. Everything here is plain TypeScript with no DOM/React dependency in its core data structures — schema, operations, and history all operate on a plain JSON document tree.
If you're building a React app, install smartrte-react instead — it depends on this package and re-exports everything you're likely to need. Install smartrte-core directly only if you're building a custom editing surface (a different UI framework, a headless document pipeline, a server-side format converter) on top of the same document model.
Install
npm install smartrte-coreWhat's in here
import {
createFoundationEditor,
foundationSchema,
createPluginRegistry,
builtInPlugins,
} from "smartrte-core/foundation";- Document model & schema (
types,schema,identity) — a plain JSON tree of typed nodes (paragraph, heading, list, table, image, formula, ...), each with a stable id that survives edits. - Editing engine (
editor,transactions,operations,history) —createFoundationEditorbuilds a stateful editor: dispatch a transaction, get back an updated document plus mapped selection, with full undo/redo. - Selection & scope resolution (
scope/) — resolves "what does the current selection actually touch" (a text range, a set of list items, a table-cell rectangle, a mix) so commands can act on the right thing regardless of how deeply nested it is. - Browser input surface (
surface/) — thebeforeinput/paste/cut/drop/composition handling layer a real contentEditable-backed UI wires up to; this is whatsmartrte-reactbuilds its editing surface on. - Format adapters (
formats/) — HTML, Markdown, DOCX (viamammoth/@xmldom), and PDF (pdfjs-dist) import/export, each declaring an explicit fidelity contract (builtInFormatFidelity) for exactly what's lossless vs. lossy per format/feature pair. - Diff, versioning, comments, suggestions, plugin system (
diff/,versioning/,comments/,suggestions/,plugin/) — the primitivessmartrte-react's version history, comment threads, and track-changes UI are built on. APluginRegistry(createPluginRegistry,builtInPlugins) is how new commands, keyboard shortcuts, toolbar contributions, and renderer behavior are added — seedocs/PLUGIN_ARCHITECTURE.mdin the repository. - Collab contract (
collab/) — the operation-transform machinery (mapOperation) a real-time transport would rebase concurrent edits through. A contract for hosts building multi-writer collaboration against; no transport implementation ships here.
Subpath exports
{
".": "compatibility root (legacy pre-foundation API)",
"./foundation": "the current, actively-developed API - use this",
"./legacy": "retired raw-path contracts, kept only for migration"
}New code should import from smartrte-core/foundation exclusively. The package root is a compatibility surface for older integrations; it is not where new capability lands.
Security
Format importers (HTML, DOCX, PDF) sanitize what they parse (DOMPurify for HTML), but this package holds no storage credentials and performs no network I/O itself — persistence, uploads, and real-time transport are all host-owned boundaries (see smartrte-react's MediaProvider/VersionProvider/CommentProvider/SuggestionProvider/CollabTransport).
Development
This package lives in a pnpm workspace monorepo alongside smartrte-react.
git clone https://github.com/ayush1852017/smart-rte.git
cd smart-rte
pnpm install
pnpm --filter smartrte-core build
pnpm --filter smartrte-core testLicense
MIT — see LICENSE.
