Collaboration
Backend Development in Progress - Demo Unavailable.
Features
- The yjs plugin enables support for collaboration using slate-yjs and Hocuspocus.
- By default remote cursors are not rendered unless you install the remote cursor overlay and include it in the config.
- Cursors are rendered slightly faded and become solid on hover. Use the
data
field incursorOptions
to customise the display name and color.
Frontend
Installation
npm install @udecode/plate-yjs
Usage
import { YjsPlugin } from '@udecode/plate-yjs/react';
import { RemoteCursorOverlay } from '@/components/plate-ui/remote-cursor-overlay';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
YjsPlugin.configure({
render: {
afterEditable: RemoteCursorOverlay,
},
options: {
cursorOptions: {
autoSend: true,
data: { name: 'A plate user', color: '#5AC990' },
},
disableCursors: false,
hocuspocusProviderOptions: {
url: 'https://hocuspocus.test/hocuspocus',
name: 'test',
},
},
}),
],
});
Editor Container
The editor requires a container component above PlateContent
to ensure correct cursor overlay positioning:
export const EditorContainer = (
props: React.HTMLAttributes<HTMLDivElement>
) => {
const editor = useEditorRef();
const containerRef = useEditorContainerRef();
return <div id={editor.uid} ref={containerRef} {...props} />;
};
This component is available in Editor.
Backend
Follow the backend instructions in Hocuspocus docs.
Plugins
YjsPlugin
Configuration for handling cursors in the editor.
Configuration for the Hocuspocus provider.
Optional configuration for the Yjs integration.
See WithYjsOptions API.
Whether to disable the cursor feature in the editor.
API
useYjsStore
withTYjs
Higher-order function that wraps a Plate editor with Yjs support, allowing for real-time collaborative editing.
Types
PlateYjsEditorProps
YHistoryEditorProps
See YHistoryEditor API.
YjsEditorProps
See YjsEditor API.