@pagent-libs/docs-core
v0.1.0
Published
Core document editor engine for pagent-docs
Maintainers
Readme
@pagent-libs/docs-core
Core document editor engine for pagent-docs. Zero React dependencies.
Features
- Document model with blocks (paragraphs, headings, lists, tables, images)
- ProseMirror schema and state management
- Text and paragraph style pooling for memory efficiency
- Event system with batching
- Undo/redo history
- TypeScript strict mode
Usage
import { DocumentImpl, type Block } from '@pagent-libs/docs-core';
const doc = new DocumentImpl('doc_1', 'My Document');
// Get sections and blocks
const sections = doc.getSections();
const blocks = sections[0].blocks;
// Update page config
doc.setSectionPageConfig(sections[0].id, {
size: { w: 816, h: 1056 },
margins: { top: 96, right: 96, bottom: 96, left: 96, header: 48, footer: 48 },
orientation: 'portrait',
});
// Serialize/deserialize
const data = doc.getData();
doc.setData(data);Block Types
paragraph- Basic text paragraphheading- Heading levels 1-6list-item- Bulleted or numbered list itemstable- Tables with rows and cellsimage- Images with optional captions
ProseMirror Integration
The package includes ProseMirror schema and utilities for rich text editing:
import {
docsSchema,
createPlugins,
blocksToPmDoc,
proseMirrorToDocument
} from '@pagent-libs/docs-core';
// Convert blocks to ProseMirror document
const pmDoc = blocksToPmDoc(blocks, schema);
// Convert ProseMirror document back to blocks
const docModel = proseMirrorToDocument(pmNode, existingDoc);Limitations
- No collaborative editing support
- Single-section documents (multi-section support is in the data model but not implemented in the UI)
- No comments or suggestions
