|
1 | | -# openblock |
| 1 | +<p align="center"> |
| 2 | + <h1 align="center">OpenBlock</h1> |
| 3 | + <p align="center"> |
| 4 | + A fully open-source block editor with public ProseMirror API |
| 5 | + </p> |
| 6 | +</p> |
| 7 | + |
| 8 | +<p align="center"> |
| 9 | + <a href="#features">Features</a> • |
| 10 | + <a href="#quick-start">Quick Start</a> • |
| 11 | + <a href="#api">API</a> • |
| 12 | + <a href="#documentation">Docs</a> • |
| 13 | + <a href="https://labbs.github.io/openblock/">Live Demo</a> |
| 14 | +</p> |
| 15 | + |
| 16 | +--- |
| 17 | + |
| 18 | +## Why OpenBlock? |
| 19 | + |
| 20 | +Unlike other editors (BlockNote, Tiptap), **OpenBlock exposes all ProseMirror internals** through a typed, documented API. No more hacks. |
| 21 | + |
| 22 | +```typescript |
| 23 | +// ✅ OpenBlock - clean, typed, documented |
| 24 | +editor.pm.view // EditorView |
| 25 | +editor.pm.state // EditorState |
| 26 | +editor.pm.dispatch(tr) // Dispatch transactions |
| 27 | +editor.pm.setNodeAttrs(pos, attrs) |
| 28 | + |
| 29 | +// ❌ Other editors - hacky, undocumented |
| 30 | +(editor as any).prosemirrorView |
| 31 | +(editor as any)._tiptapEditor.view |
| 32 | +``` |
| 33 | + |
| 34 | +## Features |
| 35 | + |
| 36 | +- **Public ProseMirror API** — Full access via `editor.pm.*` |
| 37 | +- **Block-based JSON** — Notion-like format, easy to store and transform |
| 38 | +- **Framework-agnostic** — Vanilla JS core with React bindings (Vue, Svelte coming) |
| 39 | +- **TypeScript first** — Full type safety throughout |
| 40 | +- **Rich block types** — Headings, lists, code blocks, columns, and more |
| 41 | +- **Built-in UI** — Slash menu, bubble menu, drag & drop |
| 42 | + |
| 43 | +## Quick Start |
| 44 | + |
| 45 | +### Installation |
| 46 | + |
| 47 | +```bash |
| 48 | +npm install @openblock/core @openblock/react |
| 49 | +``` |
| 50 | + |
| 51 | +### React |
| 52 | + |
| 53 | +```tsx |
| 54 | +import { useOpenBlock, OpenBlockView, SlashMenu, BubbleMenu } from '@openblock/react'; |
| 55 | +import '@openblock/core/styles/editor.css'; |
| 56 | + |
| 57 | +function Editor() { |
| 58 | + const editor = useOpenBlock({ |
| 59 | + initialContent: [ |
| 60 | + { |
| 61 | + id: '1', |
| 62 | + type: 'paragraph', |
| 63 | + props: {}, |
| 64 | + content: [{ type: 'text', text: 'Hello, World!', styles: {} }] |
| 65 | + } |
| 66 | + ], |
| 67 | + }); |
| 68 | + |
| 69 | + return ( |
| 70 | + <> |
| 71 | + <OpenBlockView editor={editor} /> |
| 72 | + <SlashMenu editor={editor} /> |
| 73 | + <BubbleMenu editor={editor} /> |
| 74 | + </> |
| 75 | + ); |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +### Vanilla JS |
| 80 | + |
| 81 | +```typescript |
| 82 | +import { OpenBlockEditor } from '@openblock/core'; |
| 83 | +import '@openblock/core/styles/editor.css'; |
| 84 | + |
| 85 | +const editor = new OpenBlockEditor({ |
| 86 | + initialContent: [/* blocks */], |
| 87 | +}); |
| 88 | + |
| 89 | +editor.mount(document.getElementById('editor')); |
| 90 | +``` |
| 91 | + |
| 92 | +## API |
| 93 | + |
| 94 | +### Document Operations |
| 95 | + |
| 96 | +```typescript |
| 97 | +editor.getDocument() // Get all blocks |
| 98 | +editor.setDocument(blocks) // Replace document |
| 99 | +editor.getBlock(id) // Find block by ID |
| 100 | +editor.insertBlocks(blocks, ref, pos) // Insert blocks |
| 101 | +editor.updateBlock(id, update) // Update block |
| 102 | +editor.removeBlocks(ids) // Delete blocks |
| 103 | +``` |
| 104 | + |
| 105 | +### Text Formatting |
| 106 | + |
| 107 | +```typescript |
| 108 | +editor.toggleBold() |
| 109 | +editor.toggleItalic() |
| 110 | +editor.toggleUnderline() |
| 111 | +editor.toggleStrikethrough() |
| 112 | +editor.toggleCode() |
| 113 | +editor.setTextColor(color) |
| 114 | +editor.setBackgroundColor(color) |
| 115 | +``` |
| 116 | + |
| 117 | +### Block Types |
| 118 | + |
| 119 | +```typescript |
| 120 | +editor.setBlockType('heading', { level: 1 }) |
| 121 | +editor.setBlockType('codeBlock', { language: 'typescript' }) |
| 122 | +editor.setBlockType('bulletList') |
| 123 | +editor.setBlockType('orderedList') |
| 124 | +editor.setBlockType('blockquote') |
| 125 | +``` |
| 126 | + |
| 127 | +### ProseMirror Access |
| 128 | + |
| 129 | +```typescript |
| 130 | +editor.pm.view // EditorView |
| 131 | +editor.pm.state // EditorState |
| 132 | +editor.pm.doc // Document |
| 133 | +editor.pm.dispatch(tr) // Dispatch transaction |
| 134 | +editor.pm.setNodeAttrs(pos, attrs) |
| 135 | +``` |
| 136 | + |
| 137 | +## Block Format |
| 138 | + |
| 139 | +```typescript |
| 140 | +interface Block { |
| 141 | + id: string; |
| 142 | + type: string; |
| 143 | + props: Record<string, unknown>; |
| 144 | + content?: InlineContent[]; |
| 145 | + children?: Block[]; |
| 146 | +} |
| 147 | + |
| 148 | +// Example document |
| 149 | +const blocks = [ |
| 150 | + { |
| 151 | + id: 'heading-1', |
| 152 | + type: 'heading', |
| 153 | + props: { level: 1 }, |
| 154 | + content: [{ type: 'text', text: 'Welcome', styles: { bold: true } }] |
| 155 | + }, |
| 156 | + { |
| 157 | + id: 'para-1', |
| 158 | + type: 'paragraph', |
| 159 | + props: {}, |
| 160 | + content: [{ type: 'text', text: 'Hello world', styles: {} }] |
| 161 | + } |
| 162 | +]; |
| 163 | +``` |
| 164 | + |
| 165 | +## Packages |
| 166 | + |
| 167 | +| Package | Description | |
| 168 | +|---------|-------------| |
| 169 | +| [@openblock/core](packages/core) | Framework-agnostic editor core | |
| 170 | +| [@openblock/react](packages/react) | React bindings and components | |
| 171 | + |
| 172 | +## Development |
| 173 | + |
| 174 | +```bash |
| 175 | +# Install dependencies |
| 176 | +pnpm install |
| 177 | + |
| 178 | +# Build all packages |
| 179 | +pnpm build |
| 180 | + |
| 181 | +# Run example in dev mode |
| 182 | +pnpm dev |
| 183 | +``` |
| 184 | + |
| 185 | +## License |
| 186 | + |
| 187 | +[Apache-2.0](LICENSE) |
0 commit comments