Registry / roosterjs-content-model-api

roosterjs-content-model-api

JSON →
library9.51.0jsnpmunverified

Format API package for the roosterjs rich-text editor (v9.51.0, stable). Provides content model-level formatting operations like toggleBold, toggleItalic, setFontSize, insertTable, and changeHeading. Part of the roosterjs 9.x ecosystem, which reworked the editor around a middle-layer Content Model for consistent behavior. Active development with frequent releases (~monthly). Differentiator: framework-independent, operates on its own content model rather than directly on DOM, enabling undo/redo and structured editing. Requires roosterjs-content-model-core and roosterjs-content-model-types as peer dependencies.

npm install roosterjs-content-model-api
INSTALL
IMPORT
SIG · ROOSTERJS-CONTENT-
R
roosterjs-content-model-api
javascriptv9.51.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

toggleBold
import { toggleBold } from 'roosterjs-content-model-api'
const toggleBold = require('roosterjs-content-model-api').toggleBold
ESM-only; no CommonJS support. Types included.
setFontSize
import { setFontSize } from 'roosterjs-content-model-api'
import { setFontSize } from 'roosterjs'
Not exported from facade roosterjs; must import from this specific package.
insertTable
import { insertTable } from 'roosterjs-content-model-api'
Requires an IEditor instance from roosterjs-content-model-core.

Creates an editor instance and demonstrates basic formatting APIs: toggleBold, toggleItalic, setFontSize, insertTable.

import { createEditor } from 'roosterjs-content-model-core'; import { toggleBold, toggleItalic, setFontSize, insertTable } from 'roosterjs-content-model-api'; const editor = createEditor(document.getElementById('editor') as HTMLDivElement, { plugins: [], defaultSegmentFormat: { fontSize: '11pt', fontFamily: 'Calibri', }, }); // Make the selected text bold toggleBold(editor); // Make the selected text italic toggleItalic(editor); // Set font size to 18pt on the selected text setFontSize(editor, '18pt'); // Insert a 3x4 table at the current cursor position insertTable(editor, { column: 3, row: 4 }); // Clean up when done editor.dispose();
Debug
Known issues
breakingroosterjs-content-model-api v9+ is incompatible with roosterjs-editor-api from v8.x. All API signatures changed.
fix
Upgrade to roosterjs-content-model-api and use the new functions (e.g., toggleBold instead of toggleBold on Editor).
affects: >=9.0.0
gotchaFunctions like toggleBold do not return a value; they mutate the editor's content model directly. Do not expect a boolean or the editor state.
fix
If you need to know the current state, use the editor's isBold() or track formatting via plugins.
affects: >=9.0.0
deprecatedThe old `setFontSize` signature with a number is deprecated; use a string like '12pt' or '1.5em'.
fix
Pass fontSize as a string with unit (e.g., '14px', '1.2em', '12pt').
affects: >=9.40.0
gotchainsertTable expects an options object with column and row as numbers, but the table is inserted at the cursor. If no selection, insertion may fail silently.
fix
Ensure there is a selection/cursor position before calling insertTable.
affects: >=9.0.0
gotchaThe package is ESM-only and not bundled for browser use; must be used with a bundler (webpack, rollup, etc.)
fix
Use a bundler that supports ESM and tree-shaking.
affects: >=9.0.0
Errors
Common errors & fixes
Cannot find module 'roosterjs-content-model-api' or its corresponding type declarations.
Package not installed or missing in tsconfig.json paths.
fix
npm install roosterjs-content-model-api --save
TypeError: toggleBold is not a function
Importing from wrong package (e.g., 'roosterjs' instead of 'roosterjs-content-model-api') or incorrect import syntax.
fix
import { toggleBold } from 'roosterjs-content-model-api';
Property 'setFontSize' does not exist on type 'typeof import(...)'
Importing from 'roosterjs' facade which re-exports only a subset.
fix
import { setFontSize } from 'roosterjs-content-model-api';
Upgrade
Version history
9.51.0latest on npm
Audit
Dependencies
roosterjs-content-model-corerequiredProvides the Editor class and plugin infrastructure that uses these APIs
roosterjs-content-model-typesrequiredDefines the public types and interfaces used by the APIs
Agent activity
2 hits · last 30 days
node
2
Resources
roosterjs-content-model-api — npm install roosterjs-content-model-api · libregistry