@univerjs/docs
Core document model and rich-text operations for Univer Docs.
import { UniverDocsPlugin } from '@univerjs/docs'univer.registerPlugin(UniverDocsPlugin, config)Document Layout Worker
Move document layout work to a Web Worker by registering the Worker plugin after UniverDocsPlugin:
import { UniverDocsLayoutWorkerPlugin } from '@univerjs/docs'univer.registerPlugin(UniverDocsLayoutWorkerPlugin, { workerFactory: () => new Worker(new URL('./docs-layout.worker.ts', import.meta.url), { type: 'module', }), requestTimeoutMs: 15_000,})Initialize the Worker entry:
import { startDocsLayoutWorker } from '@univerjs/docs'startDocsLayoutWorker()workerFactory is required. requestTimeoutMs is optional and defaults to 15 seconds.
Entry Points
- Facade:
@univerjs/docs/facade
The root entry exports SetDocumentNameCommand and ISetDocumentNameCommandParams. The Facade exposes the same behavior through FDocument.setName(name).
IUniverDocsConfig
export interface IUniverDocsConfig { hasScroll?: boolean}Heading collapse
UniverDocsPlugin registers and exports SetHeadingCollapsedCommand (doc.command.set-heading-collapsed). Execute it through the Facade or ICommandService after creating the document:
import { SetHeadingCollapsedCommand } from '@univerjs/docs'const changed = await univerAPI.executeCommand(SetHeadingCollapsedCommand.id, { unitId: documentId, paragraphId: headingParagraphId, collapsed: true,})unitId and the stable paragraphId identify the target. collapsed: false expands it. The command returns false for an unchanged state, a disabled or Traditional document, a heading hidden by an ancestor, an empty section when collapsing, or missing edit permission.
In Modern documents, IParagraph.headingCollapsed?: boolean persists in Univer snapshots and participates in undo/redo and collaboration. Only true collapses a Heading 1–5 section; Traditional layout ignores the flag. The content remains in the snapshot. This does not guarantee preservation through Office import/export. See the interactive heading guide.
¿Cómo es esta guía?