-
Notifications
You must be signed in to change notification settings - Fork 821
/
Copy pathwithPlateYjs.ts
47 lines (38 loc) · 1.08 KB
/
withPlateYjs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import type { ExtendEditor, SlateEditor } from '@udecode/plate';
import * as Y from 'yjs';
import type { YjsConfig } from './BaseYjsPlugin';
import { type PlateYjsEditorProps, withTCursors } from './withTCursors';
import { withTYHistory } from './withTYHistory';
import { withTYjs } from './withTYjs';
export const withPlateYjs: ExtendEditor<YjsConfig> = ({
editor: e,
getOptions,
}) => {
const editor = e as unknown as PlateYjsEditorProps & SlateEditor;
// not reactive
const { cursorOptions, disableCursors, provider, yjsOptions } = getOptions();
if (!provider)
throw new Error('HocuspocusProvider configuration is required');
const sharedType = provider.document.get(
'content',
Y.XmlText
) as any as Y.XmlText;
if (disableCursors) {
return withTYHistory(
withTYjs(editor, sharedType, {
autoConnect: false,
...yjsOptions,
})
);
}
return withTYHistory(
withTCursors(
withTYjs(editor, sharedType, {
autoConnect: false,
...yjsOptions,
}),
provider.awareness!,
cursorOptions
)
);
};