@lexical/yjs 0.2.9 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LexicalYjs.d.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
+
8
9
  import type {
9
10
  Doc,
10
11
  RelativePosition,
@@ -12,6 +13,7 @@ import type {
12
13
  XmlElement,
13
14
  XmlText,
14
15
  Map as YMap,
16
+ AbstractType,
15
17
  } from 'yjs';
16
18
  import type {
17
19
  DecoratorNode,
@@ -45,13 +47,11 @@ declare interface Provider {
45
47
  connect(): void | Promise<void>;
46
48
  disconnect(): void;
47
49
  off(type: 'sync', cb: (isSynced: boolean) => void): void;
48
- // $FlowFixMe: temp
49
50
  off(type: 'update', cb: (arg0: any) => void): void;
50
51
  off(type: 'status', cb: (arg0: {status: string}) => void): void;
51
52
  off(type: 'reload', cb: (doc: Doc) => void): void;
52
53
  on(type: 'sync', cb: (isSynced: boolean) => void): void;
53
54
  on(type: 'status', cb: (arg0: {status: string}) => void): void;
54
- // $FlowFixMe: temp
55
55
  on(type: 'update', cb: (arg0: any) => void): void;
56
56
  on(type: 'reload', cb: (doc: Doc) => void): void;
57
57
  }
@@ -75,6 +75,15 @@ export type Cursor = {
75
75
  name: string;
76
76
  selection: null | CursorSelection;
77
77
  };
78
+ export type TextOperation = {
79
+ insert?: string | object | AbstractType<unknown>;
80
+ delete?: number;
81
+ retain?: number;
82
+ attributes?: {
83
+ [x: string]: unknown;
84
+ };
85
+ };
86
+
78
87
  export type Binding = {
79
88
  clientID: number;
80
89
  collabNodeMap: Map<
@@ -100,8 +109,8 @@ export declare class CollabDecoratorNode {
100
109
  _type: string;
101
110
  _unobservers: Set<() => void>;
102
111
  constructor(xmlElem: XmlElement, parent: CollabElementNode, type: string);
103
- getPrevNode(nodeMap: null | NodeMap): null | DecoratorNode<{}>;
104
- getNode(): null | DecoratorNode<{}>;
112
+ getPrevNode(nodeMap: null | NodeMap): null | DecoratorNode<unknown>;
113
+ getNode(): null | DecoratorNode<unknown>;
105
114
  getSharedType(): XmlElement;
106
115
  getType(): string;
107
116
  getKey(): NodeKey;
@@ -109,7 +118,7 @@ export declare class CollabDecoratorNode {
109
118
  getOffset(): number;
110
119
  syncPropertiesFromLexical(
111
120
  binding: Binding,
112
- nextLexicalNode: DecoratorNode<{}>,
121
+ nextLexicalNode: DecoratorNode<unknown>,
113
122
  prevNodeMap: null | NodeMap,
114
123
  ): void;
115
124
  syncPropertiesFromYjs(
@@ -188,7 +197,7 @@ export declare class CollabElementNode {
188
197
  binding: Binding,
189
198
  keysChanged: null | Set<string>,
190
199
  ): void;
191
- applyChildrenYjsDelta(binding: Binding, deltas: Array<unknown>): void;
200
+ applyChildrenYjsDelta(binding: Binding, deltas: Array<TextOperation>): void;
192
201
  syncChildrenFromYjs(binding: Binding): void;
193
202
  syncPropertiesFromLexical(
194
203
  binding: Binding,
@@ -236,19 +245,23 @@ export declare class CollabElementNode {
236
245
  ): number;
237
246
  destroy(binding: Binding): void;
238
247
  }
248
+
239
249
  export function createUndoManager(binding: Binding, root: XmlText): UndoManager;
250
+
240
251
  export function initLocalState(
241
252
  provider: Provider,
242
253
  name: string,
243
254
  color: string,
244
255
  focusing: boolean,
245
256
  ): void;
257
+
246
258
  export function setLocalStateFocus(
247
259
  provider: Provider,
248
260
  name: string,
249
261
  color: string,
250
262
  focusing: boolean,
251
263
  ): void;
264
+
252
265
  export function createBinding(
253
266
  editor: LexicalEditor,
254
267
  provider: Provider,
@@ -256,7 +269,9 @@ export function createBinding(
256
269
  doc: Doc | null | undefined,
257
270
  docMap: Map<string, Doc>,
258
271
  ): Binding;
272
+
259
273
  export function syncCursorPositions(binding: Binding, provider: Provider): void;
274
+
260
275
  export function syncLexicalUpdateToYjs(
261
276
  binding: Binding,
262
277
  provider: Provider,
@@ -267,6 +282,7 @@ export function syncLexicalUpdateToYjs(
267
282
  normalizedNodes: Set<NodeKey>,
268
283
  tags: Set<string>,
269
284
  ): void;
285
+
270
286
  export function syncYjsChangesToLexical(
271
287
  binding: Binding,
272
288
  provider: Provider,
package/LexicalYjs.dev.js CHANGED
@@ -17,7 +17,6 @@ var offset = require('@lexical/offset');
17
17
  * This source code is licensed under the MIT license found in the
18
18
  * LICENSE file in the root directory of this source tree.
19
19
  *
20
- *
21
20
  */
22
21
  class CollabLineBreakNode {
23
22
  constructor(map, parent) {
@@ -60,7 +59,7 @@ class CollabLineBreakNode {
60
59
 
61
60
  }
62
61
  function $createCollabLineBreakNode(map, parent) {
63
- const collabNode = new CollabLineBreakNode(map, parent); // $FlowFixMe: internal field
62
+ const collabNode = new CollabLineBreakNode(map, parent); // @ts-expect-error: internal field
64
63
 
65
64
  map._collabNode = collabNode;
66
65
  return collabNode;
@@ -72,7 +71,6 @@ function $createCollabLineBreakNode(map, parent) {
72
71
  * This source code is licensed under the MIT license found in the
73
72
  * LICENSE file in the root directory of this source tree.
74
73
  *
75
- *
76
74
  */
77
75
  function simpleDiffWithCursor(a, b, cursor) {
78
76
  const aLength = a.length;
@@ -110,7 +108,6 @@ function simpleDiffWithCursor(a, b, cursor) {
110
108
  * This source code is licensed under the MIT license found in the
111
109
  * LICENSE file in the root directory of this source tree.
112
110
  *
113
- *
114
111
  */
115
112
 
116
113
  function diffTextContentAndApplyDelta(collabNode, key, prevText, nextText) {
@@ -227,7 +224,7 @@ class CollabTextNode {
227
224
 
228
225
  }
229
226
  function $createCollabTextNode(map, text, parent, type) {
230
- const collabNode = new CollabTextNode(map, text, parent, type); // $FlowFixMe: internal field
227
+ const collabNode = new CollabTextNode(map, text, parent, type); // @ts-expect-error: internal field
231
228
 
232
229
  map._collabNode = collabNode;
233
230
  return collabNode;
@@ -239,7 +236,6 @@ function $createCollabTextNode(map, text, parent, type) {
239
236
  * This source code is licensed under the MIT license found in the
240
237
  * LICENSE file in the root directory of this source tree.
241
238
  *
242
- *
243
239
  */
244
240
  const excludedProperties = new Set(['__key', '__children', '__parent', '__cachedText', '__text']);
245
241
  function $getNodeByKeyOrThrow(key) {
@@ -261,7 +257,7 @@ function $createCollabNodeFromLexicalNode(binding, lexicalNode, parent) {
261
257
  collabNode.syncPropertiesFromLexical(binding, lexicalNode, null);
262
258
  collabNode.syncChildrenFromLexical(binding, lexicalNode, null, null, null);
263
259
  } else if (lexical.$isTextNode(lexicalNode)) {
264
- // TODO create a token text node for immutable, segmented or inert nodes.
260
+ // TODO create a token text node for token, segmented or inert nodes.
265
261
  const map = new yjs.Map();
266
262
  collabNode = $createCollabTextNode(map, lexicalNode.__text, parent, nodeType);
267
263
  collabNode.syncPropertiesAndTextFromLexical(binding, lexicalNode, null);
@@ -292,7 +288,7 @@ function getNodeTypeFromSharedType(sharedType) {
292
288
  }
293
289
 
294
290
  function getOrInitCollabNodeFromSharedType(binding, sharedType, parent) {
295
- // $FlowFixMe: internal field
291
+ // @ts-expect-error: internal field
296
292
  const collabNode = sharedType._collabNode;
297
293
 
298
294
  if (collabNode === undefined) {
@@ -337,8 +333,7 @@ function createLexicalNodeFromCollabNode(binding, collabNode, parentKey) {
337
333
 
338
334
  if (nodeInfo === undefined) {
339
335
  throw new Error('createLexicalNode failed');
340
- } // $FlowFixMe: needs refining
341
-
336
+ }
342
337
 
343
338
  const lexicalNode = new nodeInfo.klass();
344
339
  lexicalNode.__parent = parentKey;
@@ -367,8 +362,7 @@ function syncPropertiesFromYjs(binding, sharedType, lexicalNode, keysChanged) {
367
362
 
368
363
  if (excludedProperties.has(property)) {
369
364
  continue;
370
- } // $FlowFixMe: intentional
371
-
365
+ }
372
366
 
373
367
  const prevValue = lexicalNode[property];
374
368
  let nextValue = sharedType instanceof yjs.Map ? sharedType.get(property) : sharedType.getAttribute(property);
@@ -390,8 +384,7 @@ function syncPropertiesFromYjs(binding, sharedType, lexicalNode, keysChanged) {
390
384
 
391
385
  if (writableNode === undefined) {
392
386
  writableNode = lexicalNode.getWritable();
393
- } // $FlowFixMe
394
-
387
+ }
395
388
 
396
389
  writableNode[property] = nextValue;
397
390
  }
@@ -413,9 +406,7 @@ function syncPropertiesFromLexical(binding, sharedType, prevLexicalNode, nextLex
413
406
 
414
407
  for (let i = 0; i < properties.length; i++) {
415
408
  const property = properties[i];
416
- const prevValue = // $FlowFixMe: intentional override
417
- prevLexicalNode === null ? undefined : prevLexicalNode[property]; // $FlowFixMe: intentional override
418
-
409
+ const prevValue = prevLexicalNode === null ? undefined : prevLexicalNode[property];
419
410
  let nextValue = nextLexicalNode[property];
420
411
 
421
412
  if (prevValue !== nextValue) {
@@ -424,15 +415,16 @@ function syncPropertiesFromLexical(binding, sharedType, prevLexicalNode, nextLex
424
415
  let prevDoc;
425
416
 
426
417
  if (prevValue instanceof EditorClass) {
418
+ // @ts-expect-error Lexical node
427
419
  const prevKey = prevValue._key;
428
420
  prevDoc = yjsDocMap.get(prevKey);
429
421
  yjsDocMap.delete(prevKey);
430
422
  } // If we already have a document, use it.
431
423
 
432
424
 
433
- const doc = prevDoc || new yjs.Doc(); // $FlowFixMe: guid exists
425
+ const doc = prevDoc || new yjs.Doc();
426
+ const key = doc.guid; // @ts-expect-error Lexical node
434
427
 
435
- const key = doc.guid;
436
428
  nextValue._key = key;
437
429
  yjsDocMap.set(key, doc);
438
430
  nextValue = doc; // Mark the node dirty as we've assigned a new key to it
@@ -538,7 +530,6 @@ function syncWithTransaction(binding, fn) {
538
530
  * This source code is licensed under the MIT license found in the
539
531
  * LICENSE file in the root directory of this source tree.
540
532
  *
541
- *
542
533
  */
543
534
  class CollabDecoratorNode {
544
535
  constructor(xmlElem, parent, type) {
@@ -612,7 +603,7 @@ class CollabDecoratorNode {
612
603
 
613
604
  }
614
605
  function $createCollabDecoratorNode(xmlElem, parent, type) {
615
- const collabNode = new CollabDecoratorNode(xmlElem, parent, type); // $FlowFixMe: internal field
606
+ const collabNode = new CollabDecoratorNode(xmlElem, parent, type); // @ts-expect-error: internal field
616
607
 
617
608
  xmlElem._collabNode = collabNode;
618
609
  return collabNode;
@@ -624,7 +615,6 @@ function $createCollabDecoratorNode(xmlElem, parent, type) {
624
615
  * This source code is licensed under the MIT license found in the
625
616
  * LICENSE file in the root directory of this source tree.
626
617
  *
627
- *
628
618
  */
629
619
  class CollabElementNode {
630
620
  constructor(xmlText, parent, type) {
@@ -1095,7 +1085,7 @@ function lazilyCloneElementNode(lexicalNode, writableLexicalNode, nextLexicalChi
1095
1085
  }
1096
1086
 
1097
1087
  function $createCollabElementNode(xmlText, parent, type) {
1098
- const collabNode = new CollabElementNode(xmlText, parent, type); // $FlowFixMe: internal field
1088
+ const collabNode = new CollabElementNode(xmlText, parent, type); // @ts-expect-error: internal field
1099
1089
 
1100
1090
  xmlText._collabNode = collabNode;
1101
1091
  return collabNode;
@@ -1107,18 +1097,15 @@ function $createCollabElementNode(xmlText, parent, type) {
1107
1097
  * This source code is licensed under the MIT license found in the
1108
1098
  * LICENSE file in the root directory of this source tree.
1109
1099
  *
1110
- *
1111
1100
  */
1112
1101
  function createBinding(editor, provider, id, doc, docMap) {
1113
1102
  if (doc === undefined || doc === null) {
1114
1103
  throw new Error('Should never happen');
1115
- } // $FlowFixMe: this will work
1116
-
1104
+ }
1117
1105
 
1118
1106
  const rootXmlText = doc.get('root', yjs.XmlText);
1119
1107
  const root = $createCollabElementNode(rootXmlText, null, 'root');
1120
- root._key = 'root'; // $FlowFixMe: our Flow bindings need fixing
1121
-
1108
+ root._key = 'root';
1122
1109
  return {
1123
1110
  clientID: doc.clientID,
1124
1111
  collabNodeMap: new Map(),
@@ -1139,7 +1126,6 @@ function createBinding(editor, provider, id, doc, docMap) {
1139
1126
  * This source code is licensed under the MIT license found in the
1140
1127
  * LICENSE file in the root directory of this source tree.
1141
1128
  *
1142
- *
1143
1129
  */
1144
1130
 
1145
1131
  function createRelativePosition(point, binding) {
@@ -1356,7 +1342,6 @@ function syncLocalCursorPosition(binding, provider) {
1356
1342
  }
1357
1343
 
1358
1344
  function getCollabNodeAndOffset(sharedType, offset) {
1359
- // $FlowFixMe: internal field
1360
1345
  const collabNode = sharedType._collabNode;
1361
1346
 
1362
1347
  if (collabNode === undefined) {
@@ -1500,7 +1485,6 @@ function syncLexicalSelectionToYjs(binding, provider, prevSelection, nextSelecti
1500
1485
  * This source code is licensed under the MIT license found in the
1501
1486
  * LICENSE file in the root directory of this source tree.
1502
1487
  *
1503
- *
1504
1488
  */
1505
1489
 
1506
1490
  function syncEvent(binding, event) {
@@ -1510,6 +1494,7 @@ function syncEvent(binding, event) {
1510
1494
  const collabNode = getOrInitCollabNodeFromSharedType(binding, target);
1511
1495
 
1512
1496
  if (collabNode instanceof CollabElementNode && event instanceof yjs.YTextEvent) {
1497
+ // @ts-expect-error We need to access the private property of the class
1513
1498
  const {
1514
1499
  keysChanged,
1515
1500
  childListChanged,
@@ -1549,7 +1534,6 @@ function syncYjsChangesToLexical(binding, provider, events) {
1549
1534
  const editor = binding.editor;
1550
1535
  const currentEditorState = editor._editorState;
1551
1536
  editor.update(() => {
1552
- // $FlowFixMe: this is always true
1553
1537
  const pendingEditorState = editor._pendingEditorState;
1554
1538
 
1555
1539
  for (let i = 0; i < events.length; i++) {
@@ -1687,7 +1671,6 @@ function syncLexicalUpdateToYjs(binding, provider, prevEditorState, currEditorSt
1687
1671
  * This source code is licensed under the MIT license found in the
1688
1672
  * LICENSE file in the root directory of this source tree.
1689
1673
  *
1690
- *
1691
1674
  */
1692
1675
  const CONNECTED_COMMAND = lexical.createCommand();
1693
1676
  const TOGGLE_CONNECT_COMMAND = lexical.createCommand();
@@ -62,7 +62,14 @@ export type XmlElement = Object;
62
62
  // $FlowFixMe: work around for internal
63
63
  export type YMap = Object;
64
64
  // $FlowFixMe: work around for internal
65
- export type TextOperation = Object;
65
+ export type TextOperation = {
66
+ insert?: string | mixed,
67
+ delete?: number,
68
+ retain?: number,
69
+ attributes?: {
70
+ [x: string]: mixed,
71
+ },
72
+ };
66
73
 
67
74
  export type CursorSelection = {
68
75
  anchor: {
@@ -4,44 +4,43 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- var q=require("lexical"),v=require("yjs"),y=require("@lexical/selection"),A=require("@lexical/offset");class B{constructor(a,b){this._key="";this._map=a;this._parent=b;this._type="linebreak"}getNode(){const a=q.$getNodeByKey(this._key);return q.$isLineBreakNode(a)?a:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(a){a.collabNodeMap.delete(this._key)}}
7
+ 'use strict';var r=require("lexical"),v=require("yjs"),y=require("@lexical/selection"),A=require("@lexical/offset");class B{constructor(a,b){this._key="";this._map=a;this._parent=b;this._type="linebreak"}getNode(){let a=r.$getNodeByKey(this._key);return r.$isLineBreakNode(a)?a:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(a){a.collabNodeMap.delete(this._key)}}
8
8
  function C(a,b){b=new B(a,b);return a._collabNode=b}
9
- class D{constructor(a,b,c,d){this._key="";this._map=a;this._parent=c;this._text=b;this._type=d;this._normalized=!1}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return q.$isTextNode(a)?a:null}getNode(){const a=q.$getNodeByKey(this._key);return q.$isTextNode(a)?a:null}getSharedType(){return this._map}getType(){return this._type}getKey(){return this._key}getSize(){return this._text.length+(this._normalized?0:1)}getOffset(){return this._parent.getChildOffset(this)}spliceText(a,b,c){const d=
10
- this._parent._xmlText;a=this.getOffset()+1+a;0!==b&&d.delete(a,b);""!==c&&d.insert(a,c)}syncPropertiesAndTextFromLexical(a,b,c){var d=this.getPrevNode(c);c=b.__text;E(a,this._map,d,b);if(null!==d&&(a=d.__text,a!==c)){d=b.__key;b=a;var e=q.$getSelection();a=c.length;q.$isRangeSelection(e)&&e.isCollapsed()&&(e=e.anchor,e.key===d&&(a=e.offset));d=b.length;const f=c.length;let h=e=0;for(;e<d&&e<f&&b[e]===c[e]&&e<a;)e++;for(;h+e<d&&h+e<f&&b[d-h-1]===c[f-h-1];)h++;for(;h+e<d&&h+e<f&&b[e]===c[e];)e++;b=
11
- e;a=c.slice(e,f-h);d=d-e-h;this.spliceText(b,d,a);this._text=c}}syncPropertiesAndTextFromYjs(a,b){const c=this.getNode();if(null===c)throw Error("Should never happen");F(a,this._map,c,b);a=this._text;c.__text!==a&&(c.getWritable().__text=a)}destroy(a){a.collabNodeMap.delete(this._key)}}function G(a,b,c,d){b=new D(a,b,c,d);return a._collabNode=b}const H=new Set(["__key","__children","__parent","__cachedText","__text"]);
12
- function I(a){a=q.$getNodeByKey(a);if(null===a)throw Error("Should never happen");return a}
13
- function J(a,b,c){const d=b.__type;if(q.$isElementNode(b)){var e=new v.XmlText;c=K(e,c,d);c.syncPropertiesFromLexical(a,b,null);c.syncChildrenFromLexical(a,b,null,null,null)}else if(q.$isTextNode(b))e=new v.Map,c=G(e,b.__text,c,d),c.syncPropertiesAndTextFromLexical(a,b,null);else if(q.$isLineBreakNode(b))a=new v.Map,a.set("__type","linebreak"),c=C(a,c);else if(q.$isDecoratorNode(b))e=new v.XmlElement,c=L(e,c,d),c.syncPropertiesFromLexical(a,b,null);else throw Error("Should never happen");c._key=b.__key;
9
+ class D{constructor(a,b,c,d){this._key="";this._map=a;this._parent=c;this._text=b;this._type=d;this._normalized=!1}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return r.$isTextNode(a)?a:null}getNode(){let a=r.$getNodeByKey(this._key);return r.$isTextNode(a)?a:null}getSharedType(){return this._map}getType(){return this._type}getKey(){return this._key}getSize(){return this._text.length+(this._normalized?0:1)}getOffset(){return this._parent.getChildOffset(this)}spliceText(a,b,c){let d=this._parent._xmlText;
10
+ a=this.getOffset()+1+a;0!==b&&d.delete(a,b);""!==c&&d.insert(a,c)}syncPropertiesAndTextFromLexical(a,b,c){var d=this.getPrevNode(c);c=b.__text;E(a,this._map,d,b);if(null!==d&&(a=d.__text,a!==c)){d=b.__key;b=a;var e=r.$getSelection();a=c.length;r.$isRangeSelection(e)&&e.isCollapsed()&&(e=e.anchor,e.key===d&&(a=e.offset));d=b.length;let f=c.length,h=e=0;for(;e<d&&e<f&&b[e]===c[e]&&e<a;)e++;for(;h+e<d&&h+e<f&&b[d-h-1]===c[f-h-1];)h++;for(;h+e<d&&h+e<f&&b[e]===c[e];)e++;b=e;a=c.slice(e,f-h);d=d-e-h;this.spliceText(b,
11
+ d,a);this._text=c}}syncPropertiesAndTextFromYjs(a,b){let c=this.getNode();if(null===c)throw Error("Should never happen");F(a,this._map,c,b);a=this._text;c.__text!==a&&(c.getWritable().__text=a)}destroy(a){a.collabNodeMap.delete(this._key)}}function G(a,b,c,d){b=new D(a,b,c,d);return a._collabNode=b}let H=new Set(["__key","__children","__parent","__cachedText","__text"]);function I(a){a=r.$getNodeByKey(a);if(null===a)throw Error("Should never happen");return a}
12
+ function J(a,b,c){let d=b.__type;if(r.$isElementNode(b)){var e=new v.XmlText;c=K(e,c,d);c.syncPropertiesFromLexical(a,b,null);c.syncChildrenFromLexical(a,b,null,null,null)}else if(r.$isTextNode(b))e=new v.Map,c=G(e,b.__text,c,d),c.syncPropertiesAndTextFromLexical(a,b,null);else if(r.$isLineBreakNode(b))a=new v.Map,a.set("__type","linebreak"),c=C(a,c);else if(r.$isDecoratorNode(b))e=new v.XmlElement,c=L(e,c,d),c.syncPropertiesFromLexical(a,b,null);else throw Error("Should never happen");c._key=b.__key;
14
13
  return c}
15
- function M(a,b,c){const d=b._collabNode;if(void 0===d){var e=a.editor._nodes;const f=b instanceof v.Map?b.get("__type"):b.getAttribute("__type");if(null==f)throw Error("Should never happen");if(void 0===e.get(f))throw Error("Should never happen");e=b.parent;a=void 0===c&&null!==e?M(a,e):c||null;if(!(a instanceof N))throw Error("Should never happen");if(b instanceof v.XmlText)return K(b,a,f);if(b instanceof v.Map){if(null===a)throw Error("Should never happen");return"linebreak"===f?C(b,a):G(b,"",a,
16
- f)}if(b instanceof v.XmlElement)return L(b,a,f)}return d}function F(a,b,c,d){d=null===d?b instanceof v.Map?Array.from(b.keys()):Object.keys(b.getAttributes()):Array.from(d);let e;for(let h=0;h<d.length;h++){const g=d[h];if(H.has(g))continue;var f=c[g];let k=b instanceof v.Map?b.get(g):b.getAttribute(g);if(f!==k){if(k instanceof v.Doc){const m=a.docMap;f instanceof v.Doc&&m.delete(f.guid);f=q.createEditor();const l=k.guid;f._key=l;m.set(l,k);k=f}void 0===e&&(e=c.getWritable());e[g]=k}}}
17
- function E(a,b,c,d){var e=d.__type,f=a.nodeProperties;let h=f.get(e);void 0===h&&(h=Object.keys(d).filter(k=>!H.has(k)),f.set(e,h));e=a.editor.constructor;for(f=0;f<h.length;f++){const k=h[f];var g=null===c?void 0:c[k];let m=d[k];if(g!==m){if(m instanceof e){const l=a.docMap;let r;g instanceof e&&(g=g._key,r=l.get(g),l.delete(g));g=r||new v.Doc;const t=g.guid;m._key=t;l.set(t,g);m=g;a.editor.update(()=>{d.markDirty()})}b instanceof v.Map?b.set(k,m):b.setAttribute(k,m)}}}
18
- function O(a,b,c){let d=0,e=0;const f=a._children,h=f.length;for(;e<h;e++){a=f[e];const g=d,k=a.getSize();d+=k;if((c?d>=b:d>b)&&a instanceof D)return c=b-g-1,0>c&&(c=0),{length:d-b,node:a,nodeIndex:e,offset:c};if(d>b)return{length:0,node:a,nodeIndex:e,offset:g};if(e===h-1)return{length:0,node:null,nodeIndex:e+1,offset:g+1}}return{length:0,node:null,nodeIndex:0,offset:0}}
19
- function P(a){const b=a.anchor;a=a.focus;let c=!1;try{const d=b.getNode(),e=a.getNode();if(!d.isAttached()||!e.isAttached()||q.$isTextNode(d)&&b.offset>d.getTextContentSize()||q.$isTextNode(e)&&a.offset>e.getTextContentSize())c=!0}catch(d){c=!0}return c}function ea(a,b){a.doc.transact(b,a)}
20
- class Q{constructor(a,b,c){this._key="";this._xmlElem=a;this._parent=b;this._type=c;this._unobservers=new Set}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return q.$isDecoratorNode(a)?a:null}getNode(){const a=q.$getNodeByKey(this._key);return q.$isDecoratorNode(a)?a:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}syncPropertiesFromLexical(a,b,c){c=this.getPrevNode(c);
21
- E(a,this._xmlElem,c,b)}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw Error("Should never happen");F(a,this._xmlElem,c,b)}destroy(a){a.collabNodeMap.delete(this._key);this._unobservers.forEach(b=>b());this._unobservers.clear()}}function L(a,b,c){b=new Q(a,b,c);return a._collabNode=b}
22
- class N{constructor(a,b,c){this._key="";this._children=[];this._xmlText=a;this._type=c;this._parent=b}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return q.$isElementNode(a)?a:null}getNode(){const a=q.$getNodeByKey(this._key);return q.$isElementNode(a)?a:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){const a=this._parent;if(null===a)throw Error("Should never happen");
23
- return a.getChildOffset(this)}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw this.getNode(),Error("Should never happen");F(a,this._xmlText,c,b)}applyChildrenYjsDelta(a,b){const c=this._children;let d=0;for(let m=0;m<b.length;m++){var e=b[m],f=e.insert,h=e.delete;if(null!=e.retain)d+=e.retain;else if("number"===typeof h)for(f=h;0<f;){const {node:l,nodeIndex:r,offset:t,length:n}=O(this,d,!1);if(l instanceof N||l instanceof B||l instanceof Q)c.splice(r,1),--f;else if(l instanceof
24
- D){e=Math.min(f,n);h=0!==r?c[r-1]:null;var g=l.getSize();if(0===t&&1===e&&0<r&&h instanceof D&&n===g&&0===Array.from(l._map.keys()).length)h._text+=l._text,c.splice(r,1);else if(0===t&&e===g)c.splice(r,1);else{h=l._text;g=t;var k=e;h=h.slice(0,g)+""+h.slice(g+k);l._text=h}f-=e}else break}else if(null!=f)if("string"===typeof f){const {node:l,offset:r}=O(this,d,!0);l instanceof D?(e=l._text,h=r,g=f,e=e.slice(0,h)+g+e.slice(h+0),l._text=e):this._xmlText.delete(r,f.length);d+=f.length}else e=f,{nodeIndex:f}=
25
- O(this,d,!1),e=M(a,e,this),c.splice(f,0,e),d+=1;else throw Error("Unexpected delta format");}}syncChildrenFromYjs(a){var b=this.getNode();if(null===b)throw this.getNode(),Error("Should never happen");var c=b.__key;const d=b.__children;var e=[];const f=d.length,h=this._children,g=h.length,k=a.collabNodeMap,m=new Set;let l,r;g!==f&&(r=R(b,r,e));let t=0;for(let z=0;z<g;z++){var n=d[t];const x=h[z];var p=x.getNode(),u=x._key;if(null!==p&&n===u){p=q.$isTextNode(p);m.add(n);if(p)if(x._key=n,x instanceof
26
- N)p=x._xmlText,x.syncPropertiesFromYjs(a,null),x.applyChildrenYjsDelta(a,p.toDelta()),x.syncChildrenFromYjs(a);else if(x instanceof D)x.syncPropertiesAndTextFromYjs(a,null);else if(x instanceof Q)x.syncPropertiesFromYjs(a,null);else if(!(x instanceof B))throw Error("Should never happen");e[z]=n;t++}else{if(void 0===l)for(l=new Set,u=0;u<g;u++){var w=h[u]._key;""!==w&&l.add(w)}if(null===p||void 0===n||l.has(n)){r=R(b,r,e);n=a;p=x;u=c;w=p.getType();w=n.editor._nodes.get(w);if(void 0===w)throw Error("createLexicalNode failed");
27
- w=new w.klass;w.__parent=u;p._key=w.__key;p instanceof N?(u=p._xmlText,p.syncPropertiesFromYjs(n,null),p.applyChildrenYjsDelta(n,u.toDelta()),p.syncChildrenFromYjs(n)):p instanceof D?p.syncPropertiesAndTextFromYjs(n,null):p instanceof Q&&p.syncPropertiesFromYjs(n,null);n.collabNodeMap.set(w.__key,p);n=w.__key;k.set(n,x);e[z]=n}else z--,t++}}for(b=0;b<f;b++)e=d[b],m.has(e)||(c=I(e).getWritable(),e=a.collabNodeMap.get(e),void 0!==e&&e.destroy(a),c.__parent=null)}syncPropertiesFromLexical(a,b,c){E(a,
28
- this._xmlText,this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=I(c);b instanceof N&&q.$isElementNode(c)?(b.syncPropertiesFromLexical(a,c,d),b.syncChildrenFromLexical(a,c,d,e,f)):b instanceof D&&q.$isTextNode(c)?b.syncPropertiesAndTextFromLexical(a,c,d):b instanceof Q&&q.$isDecoratorNode(c)&&b.syncPropertiesFromLexical(a,c,d)}syncChildrenFromLexical(a,b,c,d,e){var f=this.getPrevNode(c);const h=null===f?[]:f.__children;f=b.__children;const g=h.length-1,k=f.length-1,m=
29
- a.collabNodeMap;let l,r,t=0;for(b=0;t<=g&&b<=k;){var n=h[t];const u=f[b];if(n===u)this._syncChildFromLexical(a,b,u,c,d,e),t++,b++;else{void 0===l&&(l=new Set(h));void 0===r&&(r=new Set(f));var p=r.has(n);n=l.has(u);p?(p=I(u),p=J(a,p,this),m.set(u,p),n?(this.splice(a,b,1,p),t++):this.splice(a,b,0,p),b++):(this.splice(a,b,1),t++)}}c=t>g;d=b>k;if(c&&!d)for(;b<=k;++b)c=f[b],d=I(c),d=J(a,d,this),this.append(d),m.set(c,d);else if(d&&!c)for(f=this._children.length-1;f>=b;f--)this.splice(a,f,1)}append(a){const b=
30
- this._xmlText;var c=this._children;c=c[c.length-1];c=void 0!==c?c.getOffset()+c.getSize():0;if(a instanceof N)b.insertEmbed(c,a._xmlText);else if(a instanceof D){const d=a._map;null===d.parent&&b.insertEmbed(c,d);b.insert(c+1,a._text)}else a instanceof B?b.insertEmbed(c,a._map):a instanceof Q&&b.insertEmbed(c,a._xmlElem);this._children.push(a)}splice(a,b,c,d){const e=this._children;var f=e[b];if(void 0===f)if(void 0!==d)this.append(d);else throw Error("Should never happen");else{var h=f.getOffset();
31
- if(-1===h)throw Error("Should never happen");var g=this._xmlText;0!==c&&g.delete(h,f.getSize());d instanceof N?g.insertEmbed(h,d._xmlText):d instanceof D?(f=d._map,null===f.parent&&g.insertEmbed(h,f),g.insert(h+1,d._text)):d instanceof B?g.insertEmbed(h,d._map):d instanceof Q&&g.insertEmbed(h,d._xmlElem);if(0!==c)for(h=e.slice(b,b+c),g=0;g<h.length;g++)h[g].destroy(a);void 0!==d?e.splice(b,c,d):e.splice(b,c)}}getChildOffset(a){let b=0;const c=this._children;for(let d=0;d<c.length;d++){const e=c[d];
32
- if(e===a)return b;b+=e.getSize()}return-1}destroy(a){const b=a.collabNodeMap,c=this._children;for(let d=0;d<c.length;d++)c[d].destroy(a);b.delete(this._key)}}function R(a,b,c){return void 0===b?(a=a.getWritable(),a.__children=c,a):b}function K(a,b,c){b=new N(a,b,c);return a._collabNode=b}
33
- function S(a,b){b=b.collabNodeMap.get(a.key);if(void 0===b)return null;a=a.offset;let c=b.getSharedType();if(b instanceof D){c=b._parent._xmlText;b=b.getOffset();if(-1===b)return null;a=b+1+a}return v.createRelativePositionFromTypeIndex(c,a)}function T(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!v.compareRelativePositions(a,b))return!0;return!1}function U(a,b){a=a.cursorsContainer;if(null!==a){b=b.selections;const c=b.length;for(let d=0;d<c;d++)a.removeChild(b[d])}}
34
- function V(a,b){var c=b.awareness.getLocalState();if(null!==c&&(b=c.anchorPos,c=c.focusPos,null!==b&&null!==c&&(b=v.createAbsolutePositionFromRelativePosition(b,a.doc),a=v.createAbsolutePositionFromRelativePosition(c,a.doc),null!==b&&null!==a))){const [e,f]=W(b.type,b.index),[h,g]=W(a.type,a.index);if(null!==e&&null!==h){const k=e.getKey();a=h.getKey();b=q.$getSelection();if(q.$isRangeSelection(b)){var d=b.anchor;c=b.focus;if(d.key!==k||d.offset!==f)d=q.$getNodeByKey(k),b.anchor.set(k,f,q.$isElementNode(d)?
35
- "element":"text");if(c.key!==a||c.offset!==g)c=q.$getNodeByKey(a),b.focus.set(a,g,q.$isElementNode(c)?"element":"text")}}}}function W(a,b){a=a._collabNode;if(void 0===a)return[null,0];if(a instanceof N){const {node:c,offset:d}=O(a,b,!0);return null===c?[a,0]:[c,d]}return[null,0]}
36
- function X(a,b){var c=Array.from(b.awareness.getStates()),d=a.clientID;b=a.cursors;var e=a.editor._editorState._nodeMap;const f=new Set;for(var h=0;h<c.length;h++){const [z,x]=c[h];if(z!==d){f.add(z);const {anchorPos:Y,focusPos:Z,name:ha,color:ia,focusing:ja}=x;var g=null,k=b.get(z);void 0===k&&(k={color:ia,name:ha,selection:null},b.set(z,k));if(null!==Y&&null!==Z&&ja){var m=v.createAbsolutePositionFromRelativePosition(Y,a.doc),l=v.createAbsolutePositionFromRelativePosition(Z,a.doc);if(null!==m&&
37
- null!==l){const [aa,ba]=W(m.type,m.index),[ca,da]=W(l.type,l.index);if(null!==aa&&null!==ca){l=aa.getKey();var r=ca.getKey();g=k.selection;if(null===g){m=k;g=l;l=ba;var t=da,n=m.color,p=document.createElement("span");p.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:rgb(${n});z-index:10;`;var u=document.createElement("span");u.textContent=m.name;u.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:rgb(${n});color:#fff;line-height:12px;height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`;
38
- p.appendChild(u);g={anchor:{key:g,offset:l},caret:p,color:n,focus:{key:r,offset:t},name:u,selections:[]}}else m=g.anchor,t=g.focus,m.key=l,m.offset=ba,t.key=r,t.offset=da}}}m=a;l=k;n=g;t=e;r=m.editor;g=r.getRootElement();k=m.cursorsContainer;if(null!==k&&null!==g)if(g=l.selection,null===n)null!==g&&(l.selection=null,U(m,g));else{l.selection=n;g=n.caret;l=n.color;m=n.selections;p=n.anchor;n=n.focus;var w=n.key;u=t.get(p.key);t=t.get(w);if(null!=u&&null!=t&&(n=y.createDOMRange(r,u,p.offset,t,n.offset),
39
- null!==n)){t=m.length;n=y.createRectsFromDOMRange(r,n);r=n.length;for(p=0;p<r;p++)u=n[p],w=m[p],void 0===w&&(w=document.createElement("span"),m[p]=w,k.appendChild(w)),w.style.cssText=`position:absolute;top:${u.top}px;left:${u.left}px;height:${u.height}px;width:${u.width}px;background-color:rgba(${l}, 0.3);pointer-events:none;z-index:5;`,p===r-1&&g.parentNode!==w&&w.appendChild(g);for(g=t-1;g>=r;g--)k.removeChild(m[g]),m.pop()}}}}c=Array.from(b.keys());for(d=0;d<c.length;d++)e=c[d],f.has(e)||(h=b.get(e),
40
- void 0!==h&&(h=h.selection,null!==h&&U(a,h),b.delete(e)))}function fa(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:h,name:g,color:k,focusing:m}=e,l=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)q.$isRangeSelection(d)&&(e=S(d.anchor,a),l=S(d.focus,a)),(T(f,e)||T(h,l))&&b.setLocalState({anchorPos:e,color:k,focusPos:l,focusing:m,name:g})}}const ka=q.createCommand(),la=q.createCommand();exports.CONNECTED_COMMAND=ka;exports.TOGGLE_CONNECT_COMMAND=la;
14
+ function M(a,b,c){let d=b._collabNode;if(void 0===d){var e=a.editor._nodes;let f=b instanceof v.Map?b.get("__type"):b.getAttribute("__type");if(null==f)throw Error("Should never happen");if(void 0===e.get(f))throw Error("Should never happen");e=b.parent;a=void 0===c&&null!==e?M(a,e):c||null;if(!(a instanceof N))throw Error("Should never happen");if(b instanceof v.XmlText)return K(b,a,f);if(b instanceof v.Map){if(null===a)throw Error("Should never happen");return"linebreak"===f?C(b,a):G(b,"",a,f)}if(b instanceof
15
+ v.XmlElement)return L(b,a,f)}return d}function F(a,b,c,d){d=null===d?b instanceof v.Map?Array.from(b.keys()):Object.keys(b.getAttributes()):Array.from(d);let e;for(let h=0;h<d.length;h++){let g=d[h];if(H.has(g))continue;var f=c[g];let k=b instanceof v.Map?b.get(g):b.getAttribute(g);if(f!==k){if(k instanceof v.Doc){let l=a.docMap;f instanceof v.Doc&&l.delete(f.guid);f=r.createEditor();let n=k.guid;f._key=n;l.set(n,k);k=f}void 0===e&&(e=c.getWritable());e[g]=k}}}
16
+ function E(a,b,c,d){var e=d.__type,f=a.nodeProperties;let h=f.get(e);void 0===h&&(h=Object.keys(d).filter(k=>!H.has(k)),f.set(e,h));e=a.editor.constructor;for(f=0;f<h.length;f++){let k=h[f];var g=null===c?void 0:c[k];let l=d[k];if(g!==l){if(l instanceof e){let n=a.docMap,q;g instanceof e&&(g=g._key,q=n.get(g),n.delete(g));g=q||new v.Doc;let t=g.guid;l._key=t;n.set(t,g);l=g;a.editor.update(()=>{d.markDirty()})}b instanceof v.Map?b.set(k,l):b.setAttribute(k,l)}}}
17
+ function O(a,b,c){let d=0,e=0,f=a._children,h=f.length;for(;e<h;e++){a=f[e];let g=d,k=a.getSize();d+=k;if((c?d>=b:d>b)&&a instanceof D)return c=b-g-1,0>c&&(c=0),{length:d-b,node:a,nodeIndex:e,offset:c};if(d>b)return{length:0,node:a,nodeIndex:e,offset:g};if(e===h-1)return{length:0,node:null,nodeIndex:e+1,offset:g+1}}return{length:0,node:null,nodeIndex:0,offset:0}}
18
+ function P(a){let b=a.anchor;a=a.focus;let c=!1;try{let d=b.getNode(),e=a.getNode();if(!d.isAttached()||!e.isAttached()||r.$isTextNode(d)&&b.offset>d.getTextContentSize()||r.$isTextNode(e)&&a.offset>e.getTextContentSize())c=!0}catch(d){c=!0}return c}function ea(a,b){a.doc.transact(b,a)}
19
+ class Q{constructor(a,b,c){this._key="";this._xmlElem=a;this._parent=b;this._type=c;this._unobservers=new Set}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return r.$isDecoratorNode(a)?a:null}getNode(){let a=r.$getNodeByKey(this._key);return r.$isDecoratorNode(a)?a:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}syncPropertiesFromLexical(a,b,c){c=this.getPrevNode(c);
20
+ E(a,this._xmlElem,c,b)}syncPropertiesFromYjs(a,b){let c=this.getNode();if(null===c)throw Error("Should never happen");F(a,this._xmlElem,c,b)}destroy(a){a.collabNodeMap.delete(this._key);this._unobservers.forEach(b=>b());this._unobservers.clear()}}function L(a,b,c){b=new Q(a,b,c);return a._collabNode=b}
21
+ class N{constructor(a,b,c){this._key="";this._children=[];this._xmlText=a;this._type=c;this._parent=b}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return r.$isElementNode(a)?a:null}getNode(){let a=r.$getNodeByKey(this._key);return r.$isElementNode(a)?a:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){let a=this._parent;if(null===a)throw Error("Should never happen");
22
+ return a.getChildOffset(this)}syncPropertiesFromYjs(a,b){let c=this.getNode();if(null===c)throw this.getNode(),Error("Should never happen");F(a,this._xmlText,c,b)}applyChildrenYjsDelta(a,b){let c=this._children,d=0;for(let n=0;n<b.length;n++){var e=b[n],f=e.insert,h=e.delete;if(null!=e.retain)d+=e.retain;else if("number"===typeof h)for(f=h;0<f;){let {node:q,nodeIndex:t,offset:m,length:p}=O(this,d,!1);if(q instanceof N||q instanceof B||q instanceof Q)c.splice(t,1),--f;else if(q instanceof D){e=Math.min(f,
23
+ p);h=0!==t?c[t-1]:null;var g=q.getSize();if(0===m&&1===e&&0<t&&h instanceof D&&p===g&&0===Array.from(q._map.keys()).length)h._text+=q._text,c.splice(t,1);else if(0===m&&e===g)c.splice(t,1);else{h=q;g=q._text;var k=m,l=e;g=g.slice(0,k)+""+g.slice(k+l);h._text=g}f-=e}else break}else if(null!=f)if("string"===typeof f){let {node:q,offset:t}=O(this,d,!0);q instanceof D?(e=q,h=q._text,g=t,k=f,h=h.slice(0,g)+k+h.slice(g+0),e._text=h):this._xmlText.delete(t,f.length);d+=f.length}else e=f,{nodeIndex:f}=O(this,
24
+ d,!1),e=M(a,e,this),c.splice(f,0,e),d+=1;else throw Error("Unexpected delta format");}}syncChildrenFromYjs(a){var b=this.getNode();if(null===b)throw this.getNode(),Error("Should never happen");var c=b.__key;let d=b.__children;var e=[];let f=d.length,h=this._children,g=h.length,k=a.collabNodeMap,l=new Set,n,q;g!==f&&(q=R(b,q,e));let t=0;for(let z=0;z<g;z++){var m=d[t];let x=h[z];var p=x.getNode(),u=x._key;if(null!==p&&m===u){p=r.$isTextNode(p);l.add(m);if(p)if(x._key=m,x instanceof N)p=x._xmlText,
25
+ x.syncPropertiesFromYjs(a,null),x.applyChildrenYjsDelta(a,p.toDelta()),x.syncChildrenFromYjs(a);else if(x instanceof D)x.syncPropertiesAndTextFromYjs(a,null);else if(x instanceof Q)x.syncPropertiesFromYjs(a,null);else if(!(x instanceof B))throw Error("Should never happen");e[z]=m;t++}else{if(void 0===n)for(n=new Set,u=0;u<g;u++){var w=h[u]._key;""!==w&&n.add(w)}if(null===p||void 0===m||n.has(m)){q=R(b,q,e);m=a;p=x;u=c;w=p.getType();w=m.editor._nodes.get(w);if(void 0===w)throw Error("createLexicalNode failed");
26
+ w=new w.klass;w.__parent=u;p._key=w.__key;p instanceof N?(u=p._xmlText,p.syncPropertiesFromYjs(m,null),p.applyChildrenYjsDelta(m,u.toDelta()),p.syncChildrenFromYjs(m)):p instanceof D?p.syncPropertiesAndTextFromYjs(m,null):p instanceof Q&&p.syncPropertiesFromYjs(m,null);m.collabNodeMap.set(w.__key,p);m=w.__key;k.set(m,x);e[z]=m}else z--,t++}}for(b=0;b<f;b++)e=d[b],l.has(e)||(c=I(e).getWritable(),e=a.collabNodeMap.get(e),void 0!==e&&e.destroy(a),c.__parent=null)}syncPropertiesFromLexical(a,b,c){E(a,
27
+ this._xmlText,this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=I(c);b instanceof N&&r.$isElementNode(c)?(b.syncPropertiesFromLexical(a,c,d),b.syncChildrenFromLexical(a,c,d,e,f)):b instanceof D&&r.$isTextNode(c)?b.syncPropertiesAndTextFromLexical(a,c,d):b instanceof Q&&r.$isDecoratorNode(c)&&b.syncPropertiesFromLexical(a,c,d)}syncChildrenFromLexical(a,b,c,d,e){var f=this.getPrevNode(c);let h=null===f?[]:f.__children;f=b.__children;let g=h.length-1,k=f.length-1,l=a.collabNodeMap,
28
+ n,q,t=0;for(b=0;t<=g&&b<=k;){var m=h[t];let u=f[b];if(m===u)this._syncChildFromLexical(a,b,u,c,d,e),t++,b++;else{void 0===n&&(n=new Set(h));void 0===q&&(q=new Set(f));var p=q.has(m);m=n.has(u);p?(p=I(u),p=J(a,p,this),l.set(u,p),m?(this.splice(a,b,1,p),t++):this.splice(a,b,0,p),b++):(this.splice(a,b,1),t++)}}c=t>g;d=b>k;if(c&&!d)for(;b<=k;++b)c=f[b],d=I(c),d=J(a,d,this),this.append(d),l.set(c,d);else if(d&&!c)for(f=this._children.length-1;f>=b;f--)this.splice(a,f,1)}append(a){let b=this._xmlText;var c=
29
+ this._children;c=c[c.length-1];c=void 0!==c?c.getOffset()+c.getSize():0;if(a instanceof N)b.insertEmbed(c,a._xmlText);else if(a instanceof D){let d=a._map;null===d.parent&&b.insertEmbed(c,d);b.insert(c+1,a._text)}else a instanceof B?b.insertEmbed(c,a._map):a instanceof Q&&b.insertEmbed(c,a._xmlElem);this._children.push(a)}splice(a,b,c,d){let e=this._children;var f=e[b];if(void 0===f)if(void 0!==d)this.append(d);else throw Error("Should never happen");else{var h=f.getOffset();if(-1===h)throw Error("Should never happen");
30
+ var g=this._xmlText;0!==c&&g.delete(h,f.getSize());d instanceof N?g.insertEmbed(h,d._xmlText):d instanceof D?(f=d._map,null===f.parent&&g.insertEmbed(h,f),g.insert(h+1,d._text)):d instanceof B?g.insertEmbed(h,d._map):d instanceof Q&&g.insertEmbed(h,d._xmlElem);if(0!==c)for(h=e.slice(b,b+c),g=0;g<h.length;g++)h[g].destroy(a);void 0!==d?e.splice(b,c,d):e.splice(b,c)}}getChildOffset(a){let b=0,c=this._children;for(let d=0;d<c.length;d++){let e=c[d];if(e===a)return b;b+=e.getSize()}return-1}destroy(a){let b=
31
+ a.collabNodeMap,c=this._children;for(let d=0;d<c.length;d++)c[d].destroy(a);b.delete(this._key)}}function R(a,b,c){return void 0===b?(a=a.getWritable(),a.__children=c,a):b}function K(a,b,c){b=new N(a,b,c);return a._collabNode=b}function S(a,b){b=b.collabNodeMap.get(a.key);if(void 0===b)return null;a=a.offset;let c=b.getSharedType();if(b instanceof D){c=b._parent._xmlText;b=b.getOffset();if(-1===b)return null;a=b+1+a}return v.createRelativePositionFromTypeIndex(c,a)}
32
+ function T(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!v.compareRelativePositions(a,b))return!0;return!1}function U(a,b){a=a.cursorsContainer;if(null!==a){b=b.selections;let c=b.length;for(let d=0;d<c;d++)a.removeChild(b[d])}}
33
+ function V(a,b){var c=b.awareness.getLocalState();if(null!==c&&(b=c.anchorPos,c=c.focusPos,null!==b&&null!==c&&(b=v.createAbsolutePositionFromRelativePosition(b,a.doc),a=v.createAbsolutePositionFromRelativePosition(c,a.doc),null!==b&&null!==a))){let [e,f]=W(b.type,b.index),[h,g]=W(a.type,a.index);if(null!==e&&null!==h){let k=e.getKey();a=h.getKey();b=r.$getSelection();if(r.$isRangeSelection(b)){var d=b.anchor;c=b.focus;if(d.key!==k||d.offset!==f)d=r.$getNodeByKey(k),b.anchor.set(k,f,r.$isElementNode(d)?
34
+ "element":"text");if(c.key!==a||c.offset!==g)c=r.$getNodeByKey(a),b.focus.set(a,g,r.$isElementNode(c)?"element":"text")}}}}function W(a,b){a=a._collabNode;if(void 0===a)return[null,0];if(a instanceof N){let {node:c,offset:d}=O(a,b,!0);return null===c?[a,0]:[c,d]}return[null,0]}
35
+ function X(a,b){var c=Array.from(b.awareness.getStates()),d=a.clientID;b=a.cursors;var e=a.editor._editorState._nodeMap;let f=new Set;for(var h=0;h<c.length;h++){let [z,x]=c[h];if(z!==d){f.add(z);let {anchorPos:Y,focusPos:Z,name:ha,color:ia,focusing:ja}=x;var g=null,k=b.get(z);void 0===k&&(k={color:ia,name:ha,selection:null},b.set(z,k));if(null!==Y&&null!==Z&&ja){var l=v.createAbsolutePositionFromRelativePosition(Y,a.doc),n=v.createAbsolutePositionFromRelativePosition(Z,a.doc);if(null!==l&&null!==
36
+ n){let [aa,ba]=W(l.type,l.index),[ca,da]=W(n.type,n.index);if(null!==aa&&null!==ca){n=aa.getKey();var q=ca.getKey();g=k.selection;if(null===g){l=k;g=n;n=ba;var t=da,m=l.color,p=document.createElement("span");p.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:rgb(${m});z-index:10;`;var u=document.createElement("span");u.textContent=l.name;u.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:rgb(${m});color:#fff;line-height:12px;height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`;
37
+ p.appendChild(u);g={anchor:{key:g,offset:n},caret:p,color:m,focus:{key:q,offset:t},name:u,selections:[]}}else l=g.anchor,t=g.focus,l.key=n,l.offset=ba,t.key=q,t.offset=da}}}l=a;n=k;m=g;t=e;q=l.editor;g=q.getRootElement();k=l.cursorsContainer;if(null!==k&&null!==g)if(g=n.selection,null===m)null!==g&&(n.selection=null,U(l,g));else{n.selection=m;g=m.caret;n=m.color;l=m.selections;p=m.anchor;m=m.focus;var w=m.key;u=t.get(p.key);t=t.get(w);if(null!=u&&null!=t&&(m=y.createDOMRange(q,u,p.offset,t,m.offset),
38
+ null!==m)){t=l.length;m=y.createRectsFromDOMRange(q,m);q=m.length;for(p=0;p<q;p++)u=m[p],w=l[p],void 0===w&&(w=document.createElement("span"),l[p]=w,k.appendChild(w)),w.style.cssText=`position:absolute;top:${u.top}px;left:${u.left}px;height:${u.height}px;width:${u.width}px;background-color:rgba(${n}, 0.3);pointer-events:none;z-index:5;`,p===q-1&&g.parentNode!==w&&w.appendChild(g);for(g=t-1;g>=q;g--)k.removeChild(l[g]),l.pop()}}}}c=Array.from(b.keys());for(d=0;d<c.length;d++)e=c[d],f.has(e)||(h=b.get(e),
39
+ void 0!==h&&(h=h.selection,null!==h&&U(a,h),b.delete(e)))}function fa(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:h,name:g,color:k,focusing:l}=e,n=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)r.$isRangeSelection(d)&&(e=S(d.anchor,a),n=S(d.focus,a)),(T(f,e)||T(h,n))&&b.setLocalState({anchorPos:e,color:k,focusPos:n,focusing:l,name:g})}}let ka=r.createCommand(),la=r.createCommand();exports.CONNECTED_COMMAND=ka;exports.TOGGLE_CONNECT_COMMAND=la;
41
40
  exports.createBinding=function(a,b,c,d,e){if(void 0===d||null===d)throw Error("Should never happen");b=d.get("root",v.XmlText);b=K(b,null,"root");b._key="root";return{clientID:d.clientID,collabNodeMap:new Map,cursors:new Map,cursorsContainer:null,doc:d,docMap:e,editor:a,id:c,nodeProperties:new Map,root:b}};exports.createUndoManager=function(a,b){return new v.UndoManager(b,{trackedOrigins:new Set([a,null])})};
42
41
  exports.initLocalState=function(a,b,c,d){a.awareness.setLocalState({anchorPos:null,color:c,focusPos:null,focusing:d,name:b})};exports.setLocalStateFocus=function(a,b,c,d){({awareness:a}=a);let e=a.getLocalState();null===e&&(e={anchorPos:null,color:c,focusPos:null,focusing:d,name:b});e.focusing=d;a.setLocalState(e)};exports.syncCursorPositions=X;
43
- exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,h,g){ea(a,()=>{d.read(()=>{if(g.has("collaboration")){if(0<h.size){var k=Array.from(h),m=a.collabNodeMap,l=[];for(let p=0;p<k.length;p++){var r=k[p],t=q.$getNodeByKey(r),n=m.get(r);if(n instanceof D)if(q.$isTextNode(t))l.push([n,t.__text]);else{t=n.getOffset();if(-1===t)continue;const u=n._parent;n._normalized=!0;u._xmlText.delete(t,1);m.delete(r);r=u._children;n=r.indexOf(n);r.splice(n,1)}}for(k=0;k<l.length;k++){const [p,u]=l[k];p._text=u}}}else e.has("root")&&
44
- (l=c._nodeMap,k=q.$getRoot(),m=a.root,m.syncPropertiesFromLexical(a,k,l),m.syncChildrenFromLexical(a,k,l,e,f)),l=q.$getSelection(),fa(a,b,c._selection,l)})})};
45
- exports.syncYjsChangesToLexical=function(a,b,c){const d=a.editor,e=d._editorState;d.update(()=>{var f=d._pendingEditorState;for(var h=0;h<c.length;h++){var g=a,k=c[h],{target:m}=k;m=M(g,m);if(m instanceof N&&k instanceof v.YTextEvent){const {keysChanged:l,childListChanged:r,delta:t}=k;0<l.size&&m.syncPropertiesFromYjs(g,l);r&&(m.applyChildrenYjsDelta(g,t),m.syncChildrenFromYjs(g))}else if(m instanceof D&&k instanceof v.YMapEvent)({keysChanged:k}=k),0<k.size&&m.syncPropertiesAndTextFromYjs(g,k);else if(m instanceof
46
- Q&&k instanceof v.YXmlEvent)({attributesChanged:k}=k),0<k.size&&m.syncPropertiesFromYjs(g,k);else throw Error("Should never happen");}h=q.$getSelection();if(q.$isRangeSelection(h))if(P(h)){g=e._selection;if(q.$isRangeSelection(g)){m=A.$createOffsetView(d,0,e);f=A.$createOffsetView(d,0,f);const [l,r]=m.getOffsetsFromSelection(g);f=f.createSelectionFromOffsets(l,r,m);null!==f?q.$setSelection(f):(V(a,b),P(h)&&(f=q.$getRoot(),0===f.getChildrenSize()&&f.append(q.$createParagraphNode()),q.$getRoot().selectEnd()))}fa(a,
47
- b,g,q.$getSelection())}else V(a,b)},{onUpdate:()=>{X(a,b)},skipTransforms:!0,tag:"collaboration"})};
42
+ exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,h,g){ea(a,()=>{d.read(()=>{if(g.has("collaboration")){if(0<h.size){var k=Array.from(h),l=a.collabNodeMap,n=[];for(let p=0;p<k.length;p++){var q=k[p],t=r.$getNodeByKey(q),m=l.get(q);if(m instanceof D)if(r.$isTextNode(t))n.push([m,t.__text]);else{t=m.getOffset();if(-1===t)continue;let u=m._parent;m._normalized=!0;u._xmlText.delete(t,1);l.delete(q);q=u._children;m=q.indexOf(m);q.splice(m,1)}}for(k=0;k<n.length;k++){let [p,u]=n[k];p._text=u}}}else e.has("root")&&
43
+ (n=c._nodeMap,k=r.$getRoot(),l=a.root,l.syncPropertiesFromLexical(a,k,n),l.syncChildrenFromLexical(a,k,n,e,f)),n=r.$getSelection(),fa(a,b,c._selection,n)})})};
44
+ exports.syncYjsChangesToLexical=function(a,b,c){let d=a.editor,e=d._editorState;d.update(()=>{var f=d._pendingEditorState;for(var h=0;h<c.length;h++){var g=a,k=c[h],{target:l}=k;l=M(g,l);if(l instanceof N&&k instanceof v.YTextEvent){let {keysChanged:n,childListChanged:q,delta:t}=k;0<n.size&&l.syncPropertiesFromYjs(g,n);q&&(l.applyChildrenYjsDelta(g,t),l.syncChildrenFromYjs(g))}else if(l instanceof D&&k instanceof v.YMapEvent)({keysChanged:k}=k),0<k.size&&l.syncPropertiesAndTextFromYjs(g,k);else if(l instanceof
45
+ Q&&k instanceof v.YXmlEvent)({attributesChanged:k}=k),0<k.size&&l.syncPropertiesFromYjs(g,k);else throw Error("Should never happen");}h=r.$getSelection();if(r.$isRangeSelection(h))if(P(h)){g=e._selection;if(r.$isRangeSelection(g)){l=A.$createOffsetView(d,0,e);f=A.$createOffsetView(d,0,f);let [n,q]=l.getOffsetsFromSelection(g);f=f.createSelectionFromOffsets(n,q,l);null!==f?r.$setSelection(f):(V(a,b),P(h)&&(f=r.$getRoot(),0===f.getChildrenSize()&&f.append(r.$createParagraphNode()),r.$getRoot().selectEnd()))}fa(a,
46
+ b,g,r.$getSelection())}else V(a,b)},{onUpdate:()=>{X(a,b)},skipTransforms:!0,tag:"collaboration"})}
package/package.json CHANGED
@@ -11,13 +11,13 @@
11
11
  "crdt"
12
12
  ],
13
13
  "license": "MIT",
14
- "version": "0.2.9",
14
+ "version": "0.3.0",
15
15
  "main": "LexicalYjs.js",
16
16
  "dependencies": {
17
- "@lexical/offset": "0.2.9"
17
+ "@lexical/offset": "0.3.0"
18
18
  },
19
19
  "peerDependencies": {
20
- "lexical": "0.2.9",
20
+ "lexical": "0.3.0",
21
21
  "yjs": ">=13.5.22"
22
22
  },
23
23
  "repository": {