openblock-react 1.0.0-beta3
Install from the command line:
Learn more about npm packages
$ npm install @labbs/openblock-react@1.0.0-beta3
Install via package.json:
"@labbs/openblock-react": "1.0.0-beta3"
About this version
React bindings for the OpenBlock rich text editor.
npm install @labbs/openblock-react @labbs/openblock-core
# or
pnpm add @labbs/openblock-react @labbs/openblock-coreimport { useOpenBlock, OpenBlockView } from '@labbs/openblock-react';
import '@labbs/openblock-core/styles/editor.css';
function MyEditor() {
const editor = useOpenBlock({
initialContent: [
{
type: 'heading',
props: { level: 1 },
content: [{ type: 'text', text: 'Hello World', styles: {} }],
},
{
type: 'paragraph',
content: [{ type: 'text', text: 'Start editing...', styles: {} }],
},
],
});
return <OpenBlockView editor={editor} />;
}Creates and manages an OpenBlockEditor instance.
const editor = useOpenBlock({
initialContent: [...],
editable: true,
autoFocus: 'end',
onUpdate: (blocks) => console.log(blocks),
deps: [someValue], // Recreate editor when deps change
});Subscribe to document changes.
const blocks = useEditorContent(editor);
// blocks updates whenever the document changesSubscribe to selection changes.
const selectedBlocks = useEditorSelection(editor);
// selectedBlocks updates when selection changesTrack editor focus state.
const isFocused = useEditorFocus(editor);Renders the editor view.
<OpenBlockView
editor={editor}
className="my-editor"
/>With ref for imperative access:
const viewRef = useRef<OpenBlockViewRef>(null);
<OpenBlockView
ref={viewRef}
editor={editor}
/>
// Later: viewRef.current?.focus()The editor instance provides full ProseMirror access:
function MyEditor() {
const editor = useOpenBlock({...});
const handleBold = () => {
editor.toggleBold();
};
const handleCustomAction = () => {
// Direct ProseMirror access
const tr = editor.pm.createTransaction();
tr.insertText('Custom text');
editor.pm.dispatch(tr);
};
return (
<>
<button onClick={handleBold}>Bold</button>
<button onClick={handleCustomAction}>Insert</button>
<OpenBlockView editor={editor} />
</>
);
}Apache-2.0
Details
- openblock-react
-
Labbs
- about 2 months ago
- Apache-2.0
- 8 dependencies
Assets
- openblock-react-1.0.0-beta3.tgz
Download activity
- Total downloads 1
- Last 30 days 0
- Last week 0
- Today 0