Search page titles, headings and text across the docs.

Packages

On this page

@canvist/core

The typed half of canvist for JavaScript: the engine and document classes, every extension’s descriptor, and the types that make commands and queries of unregistered extensions a type error. It loads no WebAssembly, so the extension packages and the editors depend on it without pulling a module in.

You rarely install it yourself. @canvist/headless, @canvist/collab, @canvist/ssr, @canvist/scene, and @canvist/web bring a module and re-export what you need from here. Import from it directly in code that only needs the types or descriptors, such as a library that takes a document from its caller.

npm install @canvist/core
import { bold, heading } from "@canvist/core/extensions";
import { createEngine } from "@canvist/headless";

const engine = await createEngine([bold, heading]);
const doc = engine.create();

doc.commands.setHeading({ level: 2 }); // levels are 1 | 2 | 3 | 4 | 5 | 6
doc.commands.toggleItalic(); // type error: italic is not registered

Entry points

ImportWhat it has
@canvist/coreEngine, Doc, isCanvistError, CanvistError, EngineOptions, WasmSource, the StarterKit’s descriptors, and every type (StarterKit, Extensions, DocJson, Content, ThemeOptions, …)
@canvist/core/extensionsThe StarterKit’s descriptors, and core, the four every engine has
@canvist/core/extrasEvery other extension’s descriptor, extras, and allExtensions
@canvist/core/nativeNativeEditor and NativeBridge, the typed editor @canvist/react-native and @canvist/lynx put over the native views
@canvist/core/sceneThe scene JSON types: SceneJson, ExportOptions, NodeId, …
@canvist/core/gemojiGitHub’s emoji table, which the full modules load for emoji

Errors are CanvistErrors with the same stable codes as the Rust and Dart packages. Positions are { path, offset }, where path walks the block tree and offset counts UTF-16 code units, like JavaScript strings.

Development
npm ci
npm run generate          # regenerate the extension descriptors from the Rust metadata
npm run check:generated   # fail if they are out of date
npm run check:types       # tsc --noEmit
npm test                  # unit tests in Node
deno task test            # the same, in Deno
npm run build             # JavaScript and declarations for npm, into dist/

tests/conformance.ts runs the shared fixtures in conformance/ against an engine module. @canvist/headless and @canvist/collab drive it from their own tests.

Docs