A powerful document editor with schema-driven model, converter, and DSL-based rendering.
- Schema-Driven: Define document structure with validation rules and node capabilities
- Model-First Architecture: All editing operations are expressed as model operations
- Transactional: Atomic operations with rollback support
- Extensible: Plugin-based extension system for custom commands
- Keyboard Shortcuts: Rich keyboard shortcuts (Undo/Redo, Bold/Italic, Heading/Paragraph, Block movement, etc.)
- Format Conversion: Convert between HTML, Markdown, LaTeX, Office HTML, Google Docs HTML, Notion HTML
- DSL-Based Rendering: Declarative DOM rendering with template DSL
- TypeScript: Full TypeScript support with comprehensive types
Each package has its own README with detailed documentation:
@barocss/schema- Schema DSL for defining document structure, validation rules, and node capabilities@barocss/datastore- Transactional, schema-aware node store (normalizedINode/IMarkwithsid/stype)@barocss/model- Highβlevel model operations + DSL (defineOperation,defineOperationDSL,transaction)@barocss/renderer-dom- Renderer DSL for declarative DOM rendering@barocss/editor-core- Core editor logic (selection manager, keybinding, context, transaction manager)@barocss/extensions- Core editor extensions (text, delete, paragraph, move-selection, select-all, indent, copy/paste/cut, etc.)@barocss/converter- Pluggable converters for HTML/Markdown/Office/Google Docs/Notion/LaTeX β model@barocss/dsl- Low-level template and registry layer used by renderers (define,element,slot,data,defineMark)@barocss/editor-view-dom- View layer that connectsEditorand the DOM (selection sync, input handling, keybinding dispatch)@barocss/devtool- Developer tool UI for inspecting editor events, selection, transactions, and datastore state@barocss/collaboration- Core collaboration interfaces and base adapter@barocss/collaboration-yjs- Yjs adapter for collaborative editing@barocss/collaboration-liveblocks- Liveblocks adapter for collaborative editing@barocss/shared- Shared utilities and constants (platform detection, key normalization, shared helpers)@barocss/dom-observer- DOM mutation observer utilities used byeditor-view-domand devtools@barocss/text-analyzer- Experimental text analysis utilities (tokenization, statistics, helper types)
import { Editor } from '@barocss/editor-core';
import { EditorViewDOM } from '@barocss/editor-view-dom';
import { createCoreExtensions, createBasicExtensions } from '@barocss/extensions';
import { createSchema } from '@barocss/schema';
import { DataStore } from '@barocss/datastore';
import { define, element, slot, data } from '@barocss/dsl';
// 1. Define schema
const schema = createSchema('basic-doc', {
topNode: 'document',
nodes: {
document: { name: 'document', group: 'document', content: 'block+' },
paragraph: { name: 'paragraph', group: 'block', content: 'inline*' },
'inline-text': { name: 'inline-text', group: 'inline' }
}
});
// 2. Create DataStore and Editor
const dataStore = new DataStore();
dataStore.registerSchema(schema);
const editor = new Editor({
editable: true,
schema,
dataStore,
extensions: [...createCoreExtensions(), ...createBasicExtensions()]
});
// 3. Load initial document
editor.loadDocument({
sid: 'doc-1',
stype: 'document',
content: [{
sid: 'p-1',
stype: 'paragraph',
content: [{ sid: 'text-1', stype: 'inline-text', text: 'Hello, World!' }]
}]
}, 'initial');
// 4. Register renderers
define('document', element('div', { className: 'document' }, [slot('content')]));
define('paragraph', element('p', { className: 'paragraph' }, [slot('content')]));
define('inline-text', element('span', { className: 'text' }, [data('text', '')]));
// 5. Create view and render
const container = document.getElementById('editor');
const view = new EditorViewDOM(editor, {
contentEditableElement: container!
});
view.render();- Node.js >= 18.0.0
- pnpm >= 8.0.0
# Install dependencies
pnpm install
# Build all packages
pnpm build
# Start development server for test app
pnpm --filter @barocss/test-app dev# Build all packages in watch mode
pnpm dev
# Type check all packages
pnpm type-check
# Lint all packages
pnpm lint
# Clean all build artifacts
pnpm cleanAll editing behavior is expressed as model operations composed into transactions:
import { transaction, control, insertText, toggleMark } from '@barocss/model';
// Insert text
await transaction(editor, control('text-1', [
insertText({ text: 'Hello' })
])).commit();
// Toggle mark
await transaction(editor, control('text-1', [
toggleMark('bold', [0, 5])
])).commit();See @barocss/model/README.md for more details.
Define your document structure with validation rules:
import { createSchema } from '@barocss/schema';
const schema = createSchema('basic-doc', {
topNode: 'document',
nodes: {
document: { name: 'document', group: 'document', content: 'block+' },
paragraph: { name: 'paragraph', group: 'block', content: 'inline*' },
'inline-text': { name: 'inline-text', group: 'inline', marks: ['bold', 'italic'] }
},
marks: {
bold: { name: 'bold', group: 'text-style' },
italic: { name: 'italic', group: 'text-style' }
}
});See @barocss/schema/README.md for more details.
Define how nodes are rendered to DOM:
import { define, element, slot, data } from '@barocss/dsl';
define('paragraph', element('p', { className: 'paragraph' }, [slot('content')]));
define('inline-text', element('span', { className: 'text' }, [data('text', '')]));See @barocss/dsl/README.md for more details.
Extensions allow you to add custom commands and functionality. See @barocss/extensions/README.md for detailed documentation and examples.
The editor comes with a comprehensive set of keyboard shortcuts:
Mod+b- Toggle BoldMod+i- Toggle ItalicMod+u- Toggle UnderlineMod+Shift+s- Toggle StrikeThrough
Mod+Alt+1/2/3- Set Heading Level 1/2/3Mod+Alt+0- Set ParagraphAlt+ArrowUp/Down- Move Block Up/DownTab/Shift+Tab- Indent/Outdent
Mod+z- UndoMod+Shift+z/Mod+y- Redo
Mod+a- Select AllArrowLeft/Right- Move CursorAlt+ArrowLeft/Right(macOS) /Ctrl+ArrowLeft/Right(Windows/Linux) - Move by WordShift+ArrowLeft/Right- Extend SelectionEscape- Clear Selection or Blur
Mod+c- CopyMod+v- PasteMod+x- Cut
See packages/editor-core/src/keybinding/default-keybindings.ts for the complete list.
The editor is built with a modular architecture:
graph TB
subgraph "Schema Layer"
Schema["@barocss/schema<br/>Document Structure & Validation"]
end
subgraph "Data Layer"
DataStore["@barocss/datastore<br/>Transactional Node Store"]
Model["@barocss/model<br/>Operations & DSL"]
end
subgraph "Rendering Layer"
DSL["@barocss/dsl<br/>Template DSL"]
Renderer["@barocss/renderer-dom<br/>DOM Rendering"]
end
subgraph "Editor Layer"
Core["@barocss/editor-core<br/>Selection, Keybinding, Context"]
Extensions["@barocss/extensions<br/>Commands & Extensions"]
View["@barocss/editor-view-dom<br/>DOM Integration"]
end
subgraph "External"
Converter["@barocss/converter<br/>Format Conversion"]
Devtool["@barocss/devtool<br/>Debugging UI"]
end
Schema --> DataStore
DataStore --> Model
Model --> Core
Core --> Extensions
DSL --> Renderer
Model --> Renderer
Core --> View
Renderer --> View
View --> Converter
View --> Devtool
style Schema fill:#e1f5ff
style DataStore fill:#fff4e1
style Model fill:#fff4e1
style DSL fill:#e8f5e9
style Renderer fill:#e8f5e9
style Core fill:#f3e5f5
style Extensions fill:#f3e5f5
style View fill:#f3e5f5
style Converter fill:#fce4ec
style Devtool fill:#fce4ec
- Schema Layer (
@barocss/schema) - Defines document structure, validation rules, and node capabilities - Data Layer (
@barocss/datastore,@barocss/model) - Schema-aware, transactional node store and high-level editing operations - Rendering Layer (
@barocss/dsl,@barocss/renderer-dom) - Declarative DOM rendering from the model using template DSL - Editor Layer (
@barocss/editor-core,@barocss/extensions,@barocss/editor-view-dom) - Selection manager, keybinding, commands, and DOM integration - External Tools (
@barocss/converter,@barocss/devtool) - Format conversion and debugging utilities
MIT License - see LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
- Schema - Schema definition and validation
- Datastore - Node storage and transactions
- Model - Model operations and DSL
- Extensions - Creating custom extensions
- DSL - Template DSL reference
- Editor Core - Core editor API
- Editor View DOM - DOM integration
- Converter - Format conversion
For questions and support, please open an issue on GitHub.