2 * Copyright (c) Meta Platforms, Inc. and affiliates.
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
9 import type {CollabDecoratorNode} from './CollabDecoratorNode';
10 import type {CollabElementNode} from './CollabElementNode';
11 import type {CollabLineBreakNode} from './CollabLineBreakNode';
12 import type {CollabTextNode} from './CollabTextNode';
13 import type {Cursor} from './SyncCursors';
14 import type {LexicalEditor, NodeKey} from 'lexical';
15 import type {Doc} from 'yjs';
17 import {Klass, LexicalNode} from 'lexical';
18 import invariant from 'lexical/shared/invariant';
19 import {XmlText} from 'yjs';
21 import {Provider} from '.';
22 import {$createCollabElementNode} from './CollabElementNode';
24 export type ClientID = number;
25 export type Binding = {
34 cursors: Map<ClientID, Cursor>;
35 cursorsContainer: null | HTMLElement;
37 docMap: Map<string, Doc>;
38 editor: LexicalEditor;
40 nodeProperties: Map<string, Array<string>>;
41 root: CollabElementNode;
42 excludedProperties: ExcludedProperties;
44 export type ExcludedProperties = Map<Klass<LexicalNode>, Set<string>>;
46 export function createBinding(
47 editor: LexicalEditor,
50 doc: Doc | null | undefined,
51 docMap: Map<string, Doc>,
52 excludedProperties?: ExcludedProperties,
55 doc !== undefined && doc !== null,
56 'createBinding: doc is null or undefined',
58 const rootXmlText = doc.get('root', XmlText) as XmlText;
59 const root: CollabElementNode = $createCollabElementNode(
66 clientID: doc.clientID,
67 collabNodeMap: new Map(),
69 cursorsContainer: null,
73 excludedProperties: excludedProperties || new Map(),
75 nodeProperties: new Map(),