@lexical/yjs 0.26.0 → 0.26.1-nightly.20250303.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.dev.js CHANGED
@@ -13,6 +13,20 @@ var yjs = require('yjs');
13
13
  var offset = require('@lexical/offset');
14
14
  var selection = require('@lexical/selection');
15
15
 
16
+ /**
17
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
18
+ *
19
+ * This source code is licensed under the MIT license found in the
20
+ * LICENSE file in the root directory of this source tree.
21
+ *
22
+ */
23
+
24
+ // Do not require this module directly! Use normal `invariant` calls.
25
+
26
+ function formatDevErrorMessage(message) {
27
+ throw new Error(message);
28
+ }
29
+
16
30
  /**
17
31
  * Copyright (c) Meta Platforms, Inc. and affiliates.
18
32
  *
@@ -92,14 +106,6 @@ function simpleDiffWithCursor(a, b, cursor) {
92
106
  };
93
107
  }
94
108
 
95
- /**
96
- * Copyright (c) Meta Platforms, Inc. and affiliates.
97
- *
98
- * This source code is licensed under the MIT license found in the
99
- * LICENSE file in the root directory of this source tree.
100
- *
101
- */
102
-
103
109
  function $diffTextContentAndApplyDelta(collabNode, key, prevText, nextText) {
104
110
  const selection = lexical.$getSelection();
105
111
  let cursorOffset = nextText.length;
@@ -175,7 +181,7 @@ class CollabTextNode {
175
181
  syncPropertiesAndTextFromYjs(binding, keysChanged) {
176
182
  const lexicalNode = this.getNode();
177
183
  if (!(lexicalNode !== null)) {
178
- throw Error(`syncPropertiesAndTextFromYjs: could not find decorator node`);
184
+ formatDevErrorMessage(`syncPropertiesAndTextFromYjs: could not find decorator node`);
179
185
  }
180
186
  $syncPropertiesFromYjs(binding, this._map, lexicalNode, keysChanged);
181
187
  const collabText = this._text;
@@ -195,14 +201,6 @@ function $createCollabTextNode(map, text, parent, type) {
195
201
  return collabNode;
196
202
  }
197
203
 
198
- /**
199
- * Copyright (c) Meta Platforms, Inc. and affiliates.
200
- *
201
- * This source code is licensed under the MIT license found in the
202
- * LICENSE file in the root directory of this source tree.
203
- *
204
- */
205
-
206
204
  const baseExcludedProperties = new Set(['__key', '__parent', '__next', '__prev', '__state']);
207
205
  const elementExcludedProperties = new Set(['__first', '__last', '__size']);
208
206
  const rootExcludedProperties = new Set(['__cachedText']);
@@ -247,7 +245,7 @@ function $createCollabNodeFromLexicalNode(binding, lexicalNode, parent) {
247
245
  collabNode.syncPropertiesFromLexical(binding, lexicalNode, null);
248
246
  } else {
249
247
  {
250
- throw Error(`Expected text, element, decorator, or linebreak node`);
248
+ formatDevErrorMessage(`Expected text, element, decorator, or linebreak node`);
251
249
  }
252
250
  }
253
251
  collabNode._key = lexicalNode.__key;
@@ -256,7 +254,7 @@ function $createCollabNodeFromLexicalNode(binding, lexicalNode, parent) {
256
254
  function getNodeTypeFromSharedType(sharedType) {
257
255
  const type = sharedTypeGet(sharedType, '__type');
258
256
  if (!(typeof type === 'string' || typeof type === 'undefined')) {
259
- throw Error(`Expected shared type to include type attribute`);
257
+ formatDevErrorMessage(`Expected shared type to include type attribute`);
260
258
  }
261
259
  return type;
262
260
  }
@@ -266,16 +264,16 @@ function $getOrInitCollabNodeFromSharedType(binding, sharedType, parent) {
266
264
  const registeredNodes = binding.editor._nodes;
267
265
  const type = getNodeTypeFromSharedType(sharedType);
268
266
  if (!(typeof type === 'string')) {
269
- throw Error(`Expected shared type to include type attribute`);
267
+ formatDevErrorMessage(`Expected shared type to include type attribute`);
270
268
  }
271
269
  const nodeInfo = registeredNodes.get(type);
272
270
  if (!(nodeInfo !== undefined)) {
273
- throw Error(`Node ${type} is not registered`);
271
+ formatDevErrorMessage(`Node ${type} is not registered`);
274
272
  }
275
273
  const sharedParent = sharedType.parent;
276
274
  const targetParent = parent === undefined && sharedParent !== null ? $getOrInitCollabNodeFromSharedType(binding, sharedParent) : parent || null;
277
275
  if (!(targetParent instanceof CollabElementNode)) {
278
- throw Error(`Expected parent to be a collab element node`);
276
+ formatDevErrorMessage(`Expected parent to be a collab element node`);
279
277
  }
280
278
  if (sharedType instanceof yjs.XmlText) {
281
279
  return $createCollabElementNode(sharedType, targetParent, type);
@@ -295,7 +293,7 @@ function createLexicalNodeFromCollabNode(binding, collabNode, parentKey) {
295
293
  const registeredNodes = binding.editor._nodes;
296
294
  const nodeInfo = registeredNodes.get(type);
297
295
  if (!(nodeInfo !== undefined)) {
298
- throw Error(`Node ${type} is not registered`);
296
+ formatDevErrorMessage(`Node ${type} is not registered`);
299
297
  }
300
298
  const lexicalNode = new nodeInfo.klass();
301
299
  lexicalNode.__parent = parentKey;
@@ -602,14 +600,6 @@ function $moveSelectionToPreviousNode(anchorNodeKey, currentEditorState) {
602
600
  }
603
601
  }
604
602
 
605
- /**
606
- * Copyright (c) Meta Platforms, Inc. and affiliates.
607
- *
608
- * This source code is licensed under the MIT license found in the
609
- * LICENSE file in the root directory of this source tree.
610
- *
611
- */
612
-
613
603
  class CollabDecoratorNode {
614
604
  constructor(xmlElem, parent, type) {
615
605
  this._key = '';
@@ -652,7 +642,7 @@ class CollabDecoratorNode {
652
642
  syncPropertiesFromYjs(binding, keysChanged) {
653
643
  const lexicalNode = this.getNode();
654
644
  if (!(lexicalNode !== null)) {
655
- throw Error(`syncPropertiesFromYjs: could not find decorator node`);
645
+ formatDevErrorMessage(`syncPropertiesFromYjs: could not find decorator node`);
656
646
  }
657
647
  const xmlElem = this._xmlElem;
658
648
  $syncPropertiesFromYjs(binding, xmlElem, lexicalNode, keysChanged);
@@ -668,14 +658,6 @@ function $createCollabDecoratorNode(xmlElem, parent, type) {
668
658
  return collabNode;
669
659
  }
670
660
 
671
- /**
672
- * Copyright (c) Meta Platforms, Inc. and affiliates.
673
- *
674
- * This source code is licensed under the MIT license found in the
675
- * LICENSE file in the root directory of this source tree.
676
- *
677
- */
678
-
679
661
  class CollabElementNode {
680
662
  constructor(xmlText, parent, type) {
681
663
  this._key = '';
@@ -713,14 +695,14 @@ class CollabElementNode {
713
695
  getOffset() {
714
696
  const collabElementNode = this._parent;
715
697
  if (!(collabElementNode !== null)) {
716
- throw Error(`getOffset: could not find collab element node`);
698
+ formatDevErrorMessage(`getOffset: could not find collab element node`);
717
699
  }
718
700
  return collabElementNode.getChildOffset(this);
719
701
  }
720
702
  syncPropertiesFromYjs(binding, keysChanged) {
721
703
  const lexicalNode = this.getNode();
722
704
  if (!(lexicalNode !== null)) {
723
- throw Error(`syncPropertiesFromYjs: could not find element node`);
705
+ formatDevErrorMessage(`syncPropertiesFromYjs: could not find element node`);
724
706
  }
725
707
  $syncPropertiesFromYjs(binding, this._xmlText, lexicalNode, keysChanged);
726
708
  }
@@ -829,7 +811,7 @@ class CollabElementNode {
829
811
  // Now diff the children of the collab node with that of our existing Lexical node.
830
812
  const lexicalNode = this.getNode();
831
813
  if (!(lexicalNode !== null)) {
832
- throw Error(`syncChildrenFromYjs: could not find element node`);
814
+ formatDevErrorMessage(`syncChildrenFromYjs: could not find element node`);
833
815
  }
834
816
  const key = lexicalNode.__key;
835
817
  const prevLexicalChildrenKeys = offset.$createChildrenArray(lexicalNode, null);
@@ -867,7 +849,7 @@ class CollabElementNode {
867
849
  childCollabNode.syncPropertiesFromYjs(binding, null);
868
850
  } else if (!(childCollabNode instanceof CollabLineBreakNode)) {
869
851
  {
870
- throw Error(`syncChildrenFromYjs: expected text, element, decorator, or linebreak collab node`);
852
+ formatDevErrorMessage(`syncChildrenFromYjs: expected text, element, decorator, or linebreak collab node`);
871
853
  }
872
854
  }
873
855
  }
@@ -1040,14 +1022,14 @@ class CollabElementNode {
1040
1022
  const child = children[index];
1041
1023
  if (child === undefined) {
1042
1024
  if (!(collabNode !== undefined)) {
1043
- throw Error(`splice: could not find collab element node`);
1025
+ formatDevErrorMessage(`splice: could not find collab element node`);
1044
1026
  }
1045
1027
  this.append(collabNode);
1046
1028
  return;
1047
1029
  }
1048
1030
  const offset = child.getOffset();
1049
1031
  if (!(offset !== -1)) {
1050
- throw Error(`splice: expected offset to be greater than zero`);
1032
+ formatDevErrorMessage(`splice: expected offset to be greater than zero`);
1051
1033
  }
1052
1034
  const xmlText = this._xmlText;
1053
1035
  if (delCount !== 0) {
@@ -1107,17 +1089,9 @@ function $createCollabElementNode(xmlText, parent, type) {
1107
1089
  return collabNode;
1108
1090
  }
1109
1091
 
1110
- /**
1111
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1112
- *
1113
- * This source code is licensed under the MIT license found in the
1114
- * LICENSE file in the root directory of this source tree.
1115
- *
1116
- */
1117
-
1118
1092
  function createBinding(editor, provider, id, doc, docMap, excludedProperties) {
1119
1093
  if (!(doc !== undefined && doc !== null)) {
1120
- throw Error(`createBinding: doc is null or undefined`);
1094
+ formatDevErrorMessage(`createBinding: doc is null or undefined`);
1121
1095
  }
1122
1096
  const rootXmlText = doc.get('root', yjs.XmlText);
1123
1097
  const root = $createCollabElementNode(rootXmlText, null, 'root');
@@ -1137,14 +1111,6 @@ function createBinding(editor, provider, id, doc, docMap, excludedProperties) {
1137
1111
  };
1138
1112
  }
1139
1113
 
1140
- /**
1141
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1142
- *
1143
- * This source code is licensed under the MIT license found in the
1144
- * LICENSE file in the root directory of this source tree.
1145
- *
1146
- */
1147
-
1148
1114
  function createRelativePosition(point, binding) {
1149
1115
  const collabNodeMap = binding.collabNodeMap;
1150
1116
  const collabNode = collabNodeMap.get(point.key);
@@ -1163,7 +1129,7 @@ function createRelativePosition(point, binding) {
1163
1129
  } else if (collabNode instanceof CollabElementNode && point.type === 'element') {
1164
1130
  const parent = point.getNode();
1165
1131
  if (!lexical.$isElementNode(parent)) {
1166
- throw Error(`Element point must be an element node`);
1132
+ formatDevErrorMessage(`Element point must be an element node`);
1167
1133
  }
1168
1134
  let accumulatedOffset = 0;
1169
1135
  let i = 0;
@@ -1499,15 +1465,6 @@ function syncLexicalSelectionToYjs(binding, provider, prevSelection, nextSelecti
1499
1465
  }
1500
1466
  }
1501
1467
 
1502
- /**
1503
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1504
- *
1505
- * This source code is licensed under the MIT license found in the
1506
- * LICENSE file in the root directory of this source tree.
1507
- *
1508
- */
1509
-
1510
-
1511
1468
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1512
1469
  function $syncStateEvent(binding, event) {
1513
1470
  const {
@@ -1575,7 +1532,7 @@ function $syncEvent(binding, event) {
1575
1532
  }
1576
1533
  } else {
1577
1534
  {
1578
- throw Error(`Expected text, element, or decorator event`);
1535
+ formatDevErrorMessage(`Expected text, element, or decorator event`);
1579
1536
  }
1580
1537
  }
1581
1538
  }
@@ -11,6 +11,20 @@ import { XmlText, Map as Map$1, XmlElement, Doc, createAbsolutePositionFromRelat
11
11
  import { $createChildrenArray } from '@lexical/offset';
12
12
  import { createDOMRange, createRectsFromDOMRange } from '@lexical/selection';
13
13
 
14
+ /**
15
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
16
+ *
17
+ * This source code is licensed under the MIT license found in the
18
+ * LICENSE file in the root directory of this source tree.
19
+ *
20
+ */
21
+
22
+ // Do not require this module directly! Use normal `invariant` calls.
23
+
24
+ function formatDevErrorMessage(message) {
25
+ throw new Error(message);
26
+ }
27
+
14
28
  /**
15
29
  * Copyright (c) Meta Platforms, Inc. and affiliates.
16
30
  *
@@ -90,14 +104,6 @@ function simpleDiffWithCursor(a, b, cursor) {
90
104
  };
91
105
  }
92
106
 
93
- /**
94
- * Copyright (c) Meta Platforms, Inc. and affiliates.
95
- *
96
- * This source code is licensed under the MIT license found in the
97
- * LICENSE file in the root directory of this source tree.
98
- *
99
- */
100
-
101
107
  function $diffTextContentAndApplyDelta(collabNode, key, prevText, nextText) {
102
108
  const selection = $getSelection();
103
109
  let cursorOffset = nextText.length;
@@ -173,7 +179,7 @@ class CollabTextNode {
173
179
  syncPropertiesAndTextFromYjs(binding, keysChanged) {
174
180
  const lexicalNode = this.getNode();
175
181
  if (!(lexicalNode !== null)) {
176
- throw Error(`syncPropertiesAndTextFromYjs: could not find decorator node`);
182
+ formatDevErrorMessage(`syncPropertiesAndTextFromYjs: could not find decorator node`);
177
183
  }
178
184
  $syncPropertiesFromYjs(binding, this._map, lexicalNode, keysChanged);
179
185
  const collabText = this._text;
@@ -193,14 +199,6 @@ function $createCollabTextNode(map, text, parent, type) {
193
199
  return collabNode;
194
200
  }
195
201
 
196
- /**
197
- * Copyright (c) Meta Platforms, Inc. and affiliates.
198
- *
199
- * This source code is licensed under the MIT license found in the
200
- * LICENSE file in the root directory of this source tree.
201
- *
202
- */
203
-
204
202
  const baseExcludedProperties = new Set(['__key', '__parent', '__next', '__prev', '__state']);
205
203
  const elementExcludedProperties = new Set(['__first', '__last', '__size']);
206
204
  const rootExcludedProperties = new Set(['__cachedText']);
@@ -245,7 +243,7 @@ function $createCollabNodeFromLexicalNode(binding, lexicalNode, parent) {
245
243
  collabNode.syncPropertiesFromLexical(binding, lexicalNode, null);
246
244
  } else {
247
245
  {
248
- throw Error(`Expected text, element, decorator, or linebreak node`);
246
+ formatDevErrorMessage(`Expected text, element, decorator, or linebreak node`);
249
247
  }
250
248
  }
251
249
  collabNode._key = lexicalNode.__key;
@@ -254,7 +252,7 @@ function $createCollabNodeFromLexicalNode(binding, lexicalNode, parent) {
254
252
  function getNodeTypeFromSharedType(sharedType) {
255
253
  const type = sharedTypeGet(sharedType, '__type');
256
254
  if (!(typeof type === 'string' || typeof type === 'undefined')) {
257
- throw Error(`Expected shared type to include type attribute`);
255
+ formatDevErrorMessage(`Expected shared type to include type attribute`);
258
256
  }
259
257
  return type;
260
258
  }
@@ -264,16 +262,16 @@ function $getOrInitCollabNodeFromSharedType(binding, sharedType, parent) {
264
262
  const registeredNodes = binding.editor._nodes;
265
263
  const type = getNodeTypeFromSharedType(sharedType);
266
264
  if (!(typeof type === 'string')) {
267
- throw Error(`Expected shared type to include type attribute`);
265
+ formatDevErrorMessage(`Expected shared type to include type attribute`);
268
266
  }
269
267
  const nodeInfo = registeredNodes.get(type);
270
268
  if (!(nodeInfo !== undefined)) {
271
- throw Error(`Node ${type} is not registered`);
269
+ formatDevErrorMessage(`Node ${type} is not registered`);
272
270
  }
273
271
  const sharedParent = sharedType.parent;
274
272
  const targetParent = parent === undefined && sharedParent !== null ? $getOrInitCollabNodeFromSharedType(binding, sharedParent) : parent || null;
275
273
  if (!(targetParent instanceof CollabElementNode)) {
276
- throw Error(`Expected parent to be a collab element node`);
274
+ formatDevErrorMessage(`Expected parent to be a collab element node`);
277
275
  }
278
276
  if (sharedType instanceof XmlText) {
279
277
  return $createCollabElementNode(sharedType, targetParent, type);
@@ -293,7 +291,7 @@ function createLexicalNodeFromCollabNode(binding, collabNode, parentKey) {
293
291
  const registeredNodes = binding.editor._nodes;
294
292
  const nodeInfo = registeredNodes.get(type);
295
293
  if (!(nodeInfo !== undefined)) {
296
- throw Error(`Node ${type} is not registered`);
294
+ formatDevErrorMessage(`Node ${type} is not registered`);
297
295
  }
298
296
  const lexicalNode = new nodeInfo.klass();
299
297
  lexicalNode.__parent = parentKey;
@@ -600,14 +598,6 @@ function $moveSelectionToPreviousNode(anchorNodeKey, currentEditorState) {
600
598
  }
601
599
  }
602
600
 
603
- /**
604
- * Copyright (c) Meta Platforms, Inc. and affiliates.
605
- *
606
- * This source code is licensed under the MIT license found in the
607
- * LICENSE file in the root directory of this source tree.
608
- *
609
- */
610
-
611
601
  class CollabDecoratorNode {
612
602
  constructor(xmlElem, parent, type) {
613
603
  this._key = '';
@@ -650,7 +640,7 @@ class CollabDecoratorNode {
650
640
  syncPropertiesFromYjs(binding, keysChanged) {
651
641
  const lexicalNode = this.getNode();
652
642
  if (!(lexicalNode !== null)) {
653
- throw Error(`syncPropertiesFromYjs: could not find decorator node`);
643
+ formatDevErrorMessage(`syncPropertiesFromYjs: could not find decorator node`);
654
644
  }
655
645
  const xmlElem = this._xmlElem;
656
646
  $syncPropertiesFromYjs(binding, xmlElem, lexicalNode, keysChanged);
@@ -666,14 +656,6 @@ function $createCollabDecoratorNode(xmlElem, parent, type) {
666
656
  return collabNode;
667
657
  }
668
658
 
669
- /**
670
- * Copyright (c) Meta Platforms, Inc. and affiliates.
671
- *
672
- * This source code is licensed under the MIT license found in the
673
- * LICENSE file in the root directory of this source tree.
674
- *
675
- */
676
-
677
659
  class CollabElementNode {
678
660
  constructor(xmlText, parent, type) {
679
661
  this._key = '';
@@ -711,14 +693,14 @@ class CollabElementNode {
711
693
  getOffset() {
712
694
  const collabElementNode = this._parent;
713
695
  if (!(collabElementNode !== null)) {
714
- throw Error(`getOffset: could not find collab element node`);
696
+ formatDevErrorMessage(`getOffset: could not find collab element node`);
715
697
  }
716
698
  return collabElementNode.getChildOffset(this);
717
699
  }
718
700
  syncPropertiesFromYjs(binding, keysChanged) {
719
701
  const lexicalNode = this.getNode();
720
702
  if (!(lexicalNode !== null)) {
721
- throw Error(`syncPropertiesFromYjs: could not find element node`);
703
+ formatDevErrorMessage(`syncPropertiesFromYjs: could not find element node`);
722
704
  }
723
705
  $syncPropertiesFromYjs(binding, this._xmlText, lexicalNode, keysChanged);
724
706
  }
@@ -827,7 +809,7 @@ class CollabElementNode {
827
809
  // Now diff the children of the collab node with that of our existing Lexical node.
828
810
  const lexicalNode = this.getNode();
829
811
  if (!(lexicalNode !== null)) {
830
- throw Error(`syncChildrenFromYjs: could not find element node`);
812
+ formatDevErrorMessage(`syncChildrenFromYjs: could not find element node`);
831
813
  }
832
814
  const key = lexicalNode.__key;
833
815
  const prevLexicalChildrenKeys = $createChildrenArray(lexicalNode, null);
@@ -865,7 +847,7 @@ class CollabElementNode {
865
847
  childCollabNode.syncPropertiesFromYjs(binding, null);
866
848
  } else if (!(childCollabNode instanceof CollabLineBreakNode)) {
867
849
  {
868
- throw Error(`syncChildrenFromYjs: expected text, element, decorator, or linebreak collab node`);
850
+ formatDevErrorMessage(`syncChildrenFromYjs: expected text, element, decorator, or linebreak collab node`);
869
851
  }
870
852
  }
871
853
  }
@@ -1038,14 +1020,14 @@ class CollabElementNode {
1038
1020
  const child = children[index];
1039
1021
  if (child === undefined) {
1040
1022
  if (!(collabNode !== undefined)) {
1041
- throw Error(`splice: could not find collab element node`);
1023
+ formatDevErrorMessage(`splice: could not find collab element node`);
1042
1024
  }
1043
1025
  this.append(collabNode);
1044
1026
  return;
1045
1027
  }
1046
1028
  const offset = child.getOffset();
1047
1029
  if (!(offset !== -1)) {
1048
- throw Error(`splice: expected offset to be greater than zero`);
1030
+ formatDevErrorMessage(`splice: expected offset to be greater than zero`);
1049
1031
  }
1050
1032
  const xmlText = this._xmlText;
1051
1033
  if (delCount !== 0) {
@@ -1105,17 +1087,9 @@ function $createCollabElementNode(xmlText, parent, type) {
1105
1087
  return collabNode;
1106
1088
  }
1107
1089
 
1108
- /**
1109
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1110
- *
1111
- * This source code is licensed under the MIT license found in the
1112
- * LICENSE file in the root directory of this source tree.
1113
- *
1114
- */
1115
-
1116
1090
  function createBinding(editor, provider, id, doc, docMap, excludedProperties) {
1117
1091
  if (!(doc !== undefined && doc !== null)) {
1118
- throw Error(`createBinding: doc is null or undefined`);
1092
+ formatDevErrorMessage(`createBinding: doc is null or undefined`);
1119
1093
  }
1120
1094
  const rootXmlText = doc.get('root', XmlText);
1121
1095
  const root = $createCollabElementNode(rootXmlText, null, 'root');
@@ -1135,14 +1109,6 @@ function createBinding(editor, provider, id, doc, docMap, excludedProperties) {
1135
1109
  };
1136
1110
  }
1137
1111
 
1138
- /**
1139
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1140
- *
1141
- * This source code is licensed under the MIT license found in the
1142
- * LICENSE file in the root directory of this source tree.
1143
- *
1144
- */
1145
-
1146
1112
  function createRelativePosition(point, binding) {
1147
1113
  const collabNodeMap = binding.collabNodeMap;
1148
1114
  const collabNode = collabNodeMap.get(point.key);
@@ -1161,7 +1127,7 @@ function createRelativePosition(point, binding) {
1161
1127
  } else if (collabNode instanceof CollabElementNode && point.type === 'element') {
1162
1128
  const parent = point.getNode();
1163
1129
  if (!$isElementNode(parent)) {
1164
- throw Error(`Element point must be an element node`);
1130
+ formatDevErrorMessage(`Element point must be an element node`);
1165
1131
  }
1166
1132
  let accumulatedOffset = 0;
1167
1133
  let i = 0;
@@ -1497,15 +1463,6 @@ function syncLexicalSelectionToYjs(binding, provider, prevSelection, nextSelecti
1497
1463
  }
1498
1464
  }
1499
1465
 
1500
- /**
1501
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1502
- *
1503
- * This source code is licensed under the MIT license found in the
1504
- * LICENSE file in the root directory of this source tree.
1505
- *
1506
- */
1507
-
1508
-
1509
1466
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
1510
1467
  function $syncStateEvent(binding, event) {
1511
1468
  const {
@@ -1573,7 +1530,7 @@ function $syncEvent(binding, event) {
1573
1530
  }
1574
1531
  } else {
1575
1532
  {
1576
- throw Error(`Expected text, element, or decorator event`);
1533
+ formatDevErrorMessage(`Expected text, element, or decorator event`);
1577
1534
  }
1578
1535
  }
1579
1536
  }
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("lexical"),t=require("yjs"),n=require("@lexical/offset"),o=require("@lexical/selection");function s(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var l=s((function(e){const t=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",e);for(let e=1;e<arguments.length;e++)n.append("v",arguments[e]);throw t.search=n.toString(),Error(`Minified Lexical error #${e}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));class i{constructor(e,t){this._key="",this._map=e,this._parent=t,this._type="linebreak"}getNode(){const t=e.$getNodeByKey(this._key);return e.$isLineBreakNode(t)?t:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(e){e.collabNodeMap.delete(this._key)}}function r(e,t){const n=new i(e,t);return e._collabNode=n,n}class c{constructor(e,t,n,o){this._key="",this._map=e,this._parent=n,this._text=t,this._type=o,this._normalized=!1}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e.$isTextNode(n)?n:null}getNode(){const t=e.$getNodeByKey(this._key);return e.$isTextNode(t)?t: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(e,t,n){const o=this._parent._xmlText,s=this.getOffset()+1+e;0!==t&&o.delete(s,t),""!==n&&o.insert(s,n)}syncPropertiesAndTextFromLexical(t,n,o){const s=this.getPrevNode(o),l=n.__text;if(T(t,this._map,s,n),null!==s){const t=s.__text;if(t!==l){!function(t,n,o,s){const l=e.$getSelection();let i=s.length;if(e.$isRangeSelection(l)&&l.isCollapsed()){const e=l.anchor;e.key===n&&(i=e.offset)}const r=function(e,t,n){const o=e.length,s=t.length;let l=0,i=0;for(;l<o&&l<s&&e[l]===t[l]&&l<n;)l++;for(;i+l<o&&i+l<s&&e[o-i-1]===t[s-i-1];)i++;for(;i+l<o&&i+l<s&&e[l]===t[l];)l++;return{index:l,insert:t.slice(l,s-i),remove:o-l-i}}(o,s,i);t.spliceText(r.index,r.remove,r.insert)}(this,n.__key,t,l),this._text=l}}}syncPropertiesAndTextFromYjs(e,t){const n=this.getNode();null===n&&l(84),m(e,this._map,n,t);const o=this._text;if(n.__text!==o){n.getWritable().__text=o}}destroy(e){e.collabNodeMap.delete(this._key)}}function a(e,t,n,o){const s=new c(e,t,n,o);return e._collabNode=s,s}const f=new Set(["__key","__parent","__next","__prev","__state"]),u=new Set(["__first","__last","__size"]),d=new Set(["__cachedText"]),_=new Set(["__text"]);function h(t,n,o){if(f.has(t)||"function"==typeof n[t])return!0;if(e.$isTextNode(n)){if(_.has(t))return!0}else if(e.$isElementNode(n)&&(u.has(t)||e.$isRootNode(n)&&d.has(t)))return!0;const s=n.constructor,l=o.excludedProperties.get(s);return null!=l&&l.has(t)}function g(n,o,s){const i=o.__type;let c;if(e.$isElementNode(o)){c=O(new t.XmlText,s,i),c.syncPropertiesFromLexical(n,o,null),c.syncChildrenFromLexical(n,o,null,null,null)}else if(e.$isTextNode(o)){c=a(new t.Map,o.__text,s,i),c.syncPropertiesAndTextFromLexical(n,o,null)}else if(e.$isLineBreakNode(o)){const e=new t.Map;e.set("__type","linebreak"),c=r(e,s)}else if(e.$isDecoratorNode(o)){c=E(new t.XmlElement,s,i),c.syncPropertiesFromLexical(n,o,null)}else l(86);return c._key=o.__key,c}function p(e){const t=N(e,"__type");return"string"!=typeof t&&void 0!==t&&l(87),t}function y(e,n,o){const s=n._collabNode;if(void 0===s){const s=e.editor._nodes,i=p(n);"string"!=typeof i&&l(87);void 0===s.get(i)&&l(88,i);const c=n.parent,f=void 0===o&&null!==c?y(e,c):o||null;if(f instanceof M||l(89),n instanceof t.XmlText)return O(n,f,i);if(n instanceof t.Map)return"linebreak"===i?r(n,f):a(n,"",f,i);if(n instanceof t.XmlElement)return E(n,f,i)}return s}function x(e,t,n){const o=t.getType(),s=e.editor._nodes.get(o);void 0===s&&l(88,o);const i=new s.klass;if(i.__parent=n,t._key=i.__key,t instanceof M){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof c?t.syncPropertiesAndTextFromYjs(e,null):t instanceof P&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(i.__key,t),i}function m(n,o,s,l){const i=null===l?o instanceof t.Map?Array.from(o.keys()):Object.keys(o.getAttributes()):Array.from(l);let r;for(let l=0;l<i.length;l++){const c=i[l];if(h(c,s,n)){"__state"===c&&(r||(r=s.getWritable()),k(n,o,r));continue}const a=s[c];let f=N(o,c);if(a!==f){if(f instanceof t.Doc){const o=n.docMap;a instanceof t.Doc&&o.delete(a.guid);const s=e.createEditor(),l=f.guid;s._key=l,o.set(l,f),f=s}void 0===r&&(r=s.getWritable()),r[c]=f}}}function N(e,n){return e instanceof t.Map?e.get(n):e.getAttribute(n)}function b(e,n,o){e instanceof t.Map?e.set(n,o):e.setAttribute(n,o)}function k(n,o,s){const l=N(o,"__state");l instanceof t.Map&&e.$getWritableNodeState(s).updateFromJSON(l.toJSON())}function T(e,n,o,s){const l=s.__type,i=e.nodeProperties;let r=i.get(l);void 0===r&&(r=Object.keys(s).filter((t=>!h(t,s,e))),i.set(l,r));const c=e.editor.constructor;!function(e,n,o,s){const l=s.__state,i=N(n,"__state");if(!l)return;const[r,c]=l.getInternalState(),a=o&&o.__state,f=i instanceof t.Map?i:new t.Map;if(a===l)return;const[u,d]=a&&f.doc?a.getInternalState():[void 0,new Map];if(r)for(const[e,t]of Object.entries(r))u&&t!==u[e]&&f.set(e,t);for(const[e,t]of c)d.get(e)!==t&&f.set(e.key,e.unparse(t));i||b(n,"__state",f)}(0,n,o,s);for(let l=0;l<r.length;l++){const i=r[l],a=null===o?void 0:o[i];let f=s[i];if(a!==f){if(f instanceof c){const n=e.docMap;let o;if(a instanceof c){const e=a._key;o=n.get(e),n.delete(e)}const l=o||new t.Doc,i=l.guid;f._key=i,n.set(i,l),f=l,e.editor.update((()=>{s.markDirty()}))}b(n,i,f)}}}function $(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function C(e,t,n){let o=0,s=0;const l=e._children,i=l.length;for(;s<i;s++){const e=l[s],r=o;o+=e.getSize();if((n?o>=t:o>t)&&e instanceof c){let n=t-r-1;n<0&&(n=0);return{length:o-t,node:e,nodeIndex:s,offset:n}}if(o>t)return{length:0,node:e,nodeIndex:s,offset:r};if(s===i-1)return{length:0,node:null,nodeIndex:s+1,offset:r+1}}return{length:0,node:null,nodeIndex:0,offset:0}}function v(t){const n=t.anchor,o=t.focus;let s=!1;try{const t=n.getNode(),l=o.getNode();(!t.isAttached()||!l.isAttached()||e.$isTextNode(t)&&n.offset>t.getTextContentSize()||e.$isTextNode(l)&&o.offset>l.getTextContentSize())&&(s=!0)}catch(e){s=!0}return s}function S(e){const t=e.getParent();if(null!==t){const n=e.getWritable(),o=t.getWritable(),s=e.getPreviousSibling(),l=e.getNextSibling();if(null===s)if(null!==l){const e=l.getWritable();o.__first=l.__key,e.__prev=null}else o.__first=null;else{const e=s.getWritable();if(null!==l){const t=l.getWritable();t.__prev=e.__key,e.__next=t.__key}else e.__next=null;n.__prev=null}if(null===l)if(null!==s){const e=s.getWritable();o.__last=s.__key,e.__next=null}else o.__last=null;else{const e=l.getWritable();if(null!==s){const t=s.getWritable();t.__next=e.__key,e.__prev=t.__key}else e.__prev=null;n.__next=null}o.__size--,n.__parent=null}}function w(t,n){const o=n._nodeMap.get(t);if(!o)return void e.$getRoot().selectStart();const s=o.__prev;let l=null;s&&(l=e.$getNodeByKey(s)),null===l&&null!==o.__parent&&(l=e.$getNodeByKey(o.__parent)),null!==l?null!==l&&l.isAttached()?l.selectEnd():w(l.__key,n):e.$getRoot().selectStart()}class P{constructor(e,t,n){this._key="",this._xmlElem=e,this._parent=t,this._type=n}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e.$isDecoratorNode(n)?n:null}getNode(){const t=e.$getNodeByKey(this._key);return e.$isDecoratorNode(t)?t:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}syncPropertiesFromLexical(e,t,n){const o=this.getPrevNode(n);T(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&l(83);m(e,this._xmlElem,n,t)}destroy(e){e.collabNodeMap.delete(this._key)}}function E(e,t,n){const o=new P(e,t,n);return e._collabNode=o,o}class M{constructor(e,t,n){this._key="",this._children=[],this._xmlText=e,this._type=n,this._parent=t}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e.$isElementNode(n)?n:null}getNode(){const t=e.$getNodeByKey(this._key);return e.$isElementNode(t)?t:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){const e=this._parent;return null===e&&l(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&l(91),m(e,this._xmlText,n,t)}applyChildrenYjsDelta(e,t){const n=this._children;let o=0,s=null;for(let l=0;l<t.length;l++){const r=t[l],a=r.insert,f=r.delete;if(null!=r.retain)o+=r.retain;else if("number"==typeof f){let e=f;for(;e>0;){const{node:t,nodeIndex:s,offset:l,length:r}=C(this,o,!1);if(t instanceof M||t instanceof i||t instanceof P)n.splice(s,1),e-=1;else{if(!(t instanceof c))break;{const o=Math.min(e,r),i=0!==s?n[s-1]:null,a=t.getSize();if(0===l&&r===a){n.splice(s,1);const e=$(t._text,l,o-1,"");e.length>0&&(i instanceof c?i._text+=e:this._xmlText.delete(l,e.length))}else t._text=$(t._text,l,o,"");e-=o}}}}else{if(null==a)throw new Error("Unexpected delta format");if("string"==typeof a){const{node:e,offset:t}=C(this,o,!0);e instanceof c?e._text=$(e._text,t,0,a):this._xmlText.delete(t,a.length),o+=a.length}else{const t=a,{node:l,nodeIndex:i,length:r}=C(this,o,!1),f=y(e,t,this);if(l instanceof c&&r>0&&r<l._text.length){const e=l._text,t=e.length-r;l._text=$(e,t,r,""),n.splice(i+1,0,f),s=$(e,0,t,"")}else n.splice(i,0,f);null!==s&&f instanceof c&&(f._text=s+f._text,s=null),o+=1}}}}syncChildrenFromYjs(t){const o=this.getNode();null===o&&l(92);const s=o.__key,r=n.$createChildrenArray(o,null),a=r.length,f=this._children,u=f.length,d=t.collabNodeMap,_=new Set;let h,g,p=0,y=null;u!==a&&(g=o.getWritable());for(let n=0;n<u;n++){const a=r[p],m=f[n],N=m.getNode(),b=m._key;if(null!==N&&a===b){const n=e.$isTextNode(N);if(_.add(a),n)if(m._key=a,m instanceof M){const e=m._xmlText;m.syncPropertiesFromYjs(t,null),m.applyChildrenYjsDelta(t,e.toDelta()),m.syncChildrenFromYjs(t)}else m instanceof c?m.syncPropertiesAndTextFromYjs(t,null):m instanceof P?m.syncPropertiesFromYjs(t,null):m instanceof i||l(93);y=N,p++}else{if(void 0===h){h=new Set;for(let e=0;e<u;e++){const t=f[e]._key;""!==t&&h.add(t)}}if(null!==N&&void 0!==a&&!h.has(a)){S(e.$getNodeByKeyOrThrow(a)),n--,p++;continue}g=o.getWritable();const l=x(t,m,s),i=l.__key;if(d.set(i,m),null===y){const e=g.getFirstChild();if(g.__first=i,null!==e){const t=e.getWritable();t.__prev=i,l.__next=t.__key}}else{const e=y.getWritable(),t=y.getNextSibling();if(e.__next=i,l.__prev=y.__key,null!==t){const e=t.getWritable();e.__prev=i,l.__next=e.__key}}n===u-1&&(g.__last=i),g.__size++,y=l}}for(let n=0;n<a;n++){const o=r[n];if(!_.has(o)){const n=e.$getNodeByKeyOrThrow(o),s=t.collabNodeMap.get(o);void 0!==s&&s.destroy(t),S(n)}}}syncPropertiesFromLexical(e,t,n){T(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(t,n,o,s,l,i){const r=this._children[n],a=e.$getNodeByKeyOrThrow(o);r instanceof M&&e.$isElementNode(a)?(r.syncPropertiesFromLexical(t,a,s),r.syncChildrenFromLexical(t,a,s,l,i)):r instanceof c&&e.$isTextNode(a)?r.syncPropertiesAndTextFromLexical(t,a,s):r instanceof P&&e.$isDecoratorNode(a)&&r.syncPropertiesFromLexical(t,a,s)}syncChildrenFromLexical(t,o,s,l,i){const r=this.getPrevNode(s),c=null===r?[]:n.$createChildrenArray(r,s),a=n.$createChildrenArray(o,null),f=c.length-1,u=a.length-1,d=t.collabNodeMap;let _,h,p=0,y=0;for(;p<=f&&y<=u;){const n=c[p],o=a[y];if(n===o)this._syncChildFromLexical(t,y,o,s,l,i),p++,y++;else{void 0===_&&(_=new Set(c)),void 0===h&&(h=new Set(a));const s=h.has(n),l=_.has(o);if(s){const n=g(t,e.$getNodeByKeyOrThrow(o),this);d.set(o,n),l?(this.splice(t,y,1,n),p++,y++):(this.splice(t,y,0,n),y++)}else this.splice(t,y,1),p++}}const x=p>f,m=y>u;if(x&&!m)for(;y<=u;++y){const n=a[y],o=g(t,e.$getNodeByKeyOrThrow(n),this);this.append(o),d.set(n,o)}else if(m&&!x)for(let e=this._children.length-1;e>=y;e--)this.splice(t,e,1)}append(e){const t=this._xmlText,n=this._children,o=n[n.length-1],s=void 0!==o?o.getOffset()+o.getSize():0;if(e instanceof M)t.insertEmbed(s,e._xmlText);else if(e instanceof c){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof i?t.insertEmbed(s,e._map):e instanceof P&&t.insertEmbed(s,e._xmlElem);this._children.push(e)}splice(e,t,n,o){const s=this._children,r=s[t];if(void 0===r)return void 0===o&&l(94),void this.append(o);const a=r.getOffset();-1===a&&l(95);const f=this._xmlText;if(0!==n&&f.delete(a,r.getSize()),o instanceof M)f.insertEmbed(a,o._xmlText);else if(o instanceof c){const e=o._map;null===e.parent&&f.insertEmbed(a,e),f.insert(a+1,o._text)}else o instanceof i?f.insertEmbed(a,o._map):o instanceof P&&f.insertEmbed(a,o._xmlElem);if(0!==n){const o=s.slice(t,t+n);for(let t=0;t<o.length;t++)o[t].destroy(e)}void 0!==o?s.splice(t,n,o):s.splice(t,n)}getChildOffset(e){let t=0;const n=this._children;for(let o=0;o<n.length;o++){const s=n[o];if(s===e)return t;t+=s.getSize()}return-1}destroy(e){const t=e.collabNodeMap,n=this._children;for(let t=0;t<n.length;t++)n[t].destroy(e);t.delete(this._key)}}function O(e,t,n){const o=new M(e,t,n);return e._collabNode=o,o}function F(n,o){const s=o.collabNodeMap.get(n.key);if(void 0===s)return null;let i=n.offset,r=s.getSharedType();if(s instanceof c){r=s._parent._xmlText;const e=s.getOffset();if(-1===e)return null;i=e+1+i}else if(s instanceof M&&"element"===n.type){const t=n.getNode();e.$isElementNode(t)||l(184);let o=0,s=0,r=t.getFirstChild();for(;null!==r&&s++<i;)e.$isTextNode(r)?o+=r.getTextContentSize()+1:o++,r=r.getNextSibling();i=o}return t.createRelativePositionFromTypeIndex(r,i)}function L(e,n){return t.createAbsolutePositionFromRelativePosition(e,n.doc)}function A(e,n){if(null==e){if(null!=n)return!0}else if(null==n||!t.compareRelativePositions(e,n))return!0;return!1}function D(e,t){return{color:t,name:e,selection:null}}function j(e,t){const n=e.cursorsContainer;if(null!==n){const e=t.selections,o=e.length;for(let t=0;t<o;t++)n.removeChild(e[t])}}function z(e,t){const n=t.selection;null!==n&&j(e,n)}function Y(e,t,n,o,s){const l=e.color,i=document.createElement("span");i.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${l};z-index:10;`;const r=document.createElement("span");return r.textContent=e.name,r.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${l};color:#fff;line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`,i.appendChild(r),{anchor:{key:t,offset:n},caret:i,color:l,focus:{key:o,offset:s},name:r,selections:[]}}function K(t,n,s,l){const i=t.editor,r=i.getRootElement(),c=t.cursorsContainer;if(null===c||null===r)return;const a=c.offsetParent;if(null===a)return;const f=a.getBoundingClientRect(),u=n.selection;if(null===s)return null===u?void 0:(n.selection=null,void j(t,u));n.selection=s;const d=s.caret,_=s.color,h=s.selections,g=s.anchor,p=s.focus,y=g.key,x=p.key,m=l.get(y),N=l.get(x);if(null==m||null==N)return;let b;if(m===N&&e.$isLineBreakNode(m)){b=[i.getElementByKey(y).getBoundingClientRect()]}else{const e=o.createDOMRange(i,m,g.offset,N,p.offset);if(null===e)return;b=o.createRectsFromDOMRange(i,e)}const k=h.length,T=b.length;for(let e=0;e<T;e++){const t=b[e];let n=h[e];if(void 0===n){n=document.createElement("span"),h[e]=n;const t=document.createElement("span");n.appendChild(t),c.appendChild(n)}const o=`position:absolute;top:${t.top-f.top}px;left:${t.left-f.left}px;height:${t.height}px;width:${t.width}px;pointer-events:none;z-index:5;`;n.style.cssText=o,n.firstChild.style.cssText=`${o}left:0;top:0;background-color:${_};opacity:0.3;`,e===T-1&&d.parentNode!==n&&n.appendChild(d)}for(let e=k-1;e>=T;e--){const t=h[e];c.removeChild(t),h.pop()}}function R(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,l=0,i=null,r=0;if(null!==n&&null!==o){const t=L(n,e),c=L(o,e);null!==t&&null!==c&&([s,l]=I(t.type,t.index),[i,r]=I(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:l,focusCollabNode:i,focusOffset:r}}function B(t,n){const o=n.awareness.getLocalState();if(null===o)return;const{anchorCollabNode:s,anchorOffset:l,focusCollabNode:i,focusOffset:r}=R(t,o);if(null!==s&&null!==i){const t=s.getKey(),n=i.getKey(),o=e.$getSelection();if(!e.$isRangeSelection(o))return;W(o.anchor,t,l),W(o.focus,n,r)}}function W(t,n,o){if(t.key!==n||t.offset!==o){let s=e.$getNodeByKey(n);if(null!==s&&!e.$isElementNode(s)&&!e.$isTextNode(s)){const e=s.getParentOrThrow();n=e.getKey(),o=s.getIndexWithinParent(),s=e}t.set(n,o,e.$isElementNode(s)?"element":"text")}}function I(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof M){const{node:e,offset:o}=C(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function U(e,t){const n=Array.from(t.awareness.getStates()),o=e.clientID,s=e.cursors,l=e.editor._editorState._nodeMap,i=new Set;for(let t=0;t<n.length;t++){const r=n[t],[c,a]=r;if(c!==o){i.add(c);const{name:t,color:n,focusing:o}=a;let r=null,f=s.get(c);if(void 0===f&&(f=D(t,n),s.set(c,f)),o){const{anchorCollabNode:t,anchorOffset:n,focusCollabNode:o,focusOffset:s}=R(e,a);if(null!==t&&null!==o){const e=t.getKey(),l=o.getKey();if(r=f.selection,null===r)r=Y(f,e,n,l,s);else{const t=r.anchor,o=r.focus;t.key=e,t.offset=n,o.key=l,o.offset=s}}}K(e,f,r,l)}}const r=Array.from(s.keys());for(let t=0;t<r.length;t++){const n=r[t];if(!i.has(n)){const t=s.get(n);void 0!==t&&(z(e,t),s.delete(n))}}}function X(t,n,o,s){const l=n.awareness,i=l.getLocalState();if(null===i)return;const{anchorPos:r,focusPos:c,name:a,color:f,focusing:u,awarenessData:d}=i;let _=null,h=null;(null!==s&&(null===r||s.is(o))||null!==o)&&(e.$isRangeSelection(s)&&(_=F(s.anchor,t),h=F(s.focus,t)),(A(r,_)||A(c,h))&&l.setLocalState({...i,anchorPos:_,awarenessData:d,color:f,focusPos:h,focusing:u,name:a}))}function q(n,o){if(o instanceof t.YMapEvent&&function(n,o){const{target:s}=o;if(!s._item||"__state"!==s._item.parentSub||void 0!==p(s)||!(s.parent instanceof t.XmlText||s.parent instanceof t.XmlElement||s.parent instanceof t.Map))return!1;const l=y(n,s.parent).getNode();if(l){const t=e.$getWritableNodeState(l.getWritable());for(const e of o.keysChanged)t.updateFromUnknown(e,s.get(e))}return!0}(n,o))return;const{target:s}=o,i=y(n,s);if(i instanceof M&&o instanceof t.YTextEvent){const{keysChanged:e,childListChanged:t,delta:s}=o;e.size>0&&i.syncPropertiesFromYjs(n,e),t&&(i.applyChildrenYjsDelta(n,s),i.syncChildrenFromYjs(n))}else if(i instanceof c&&o instanceof t.YMapEvent){const{keysChanged:e}=o;e.size>0&&i.syncPropertiesAndTextFromYjs(n,e)}else if(i instanceof P&&o instanceof t.YXmlEvent){const{attributesChanged:e}=o;e.size>0&&i.syncPropertiesFromYjs(n,e)}else l(82)}const G=e.createCommand("CONNECTED_COMMAND"),J=e.createCommand("TOGGLE_CONNECT_COMMAND");exports.CONNECTED_COMMAND=G,exports.TOGGLE_CONNECT_COMMAND=J,exports.createBinding=function(e,n,o,s,i,r){null==s&&l(81);const c=O(s.get("root",t.XmlText),null,"root");return c._key="root",{clientID:s.clientID,collabNodeMap:new Map,cursors:new Map,cursorsContainer:null,doc:s,docMap:i,editor:e,excludedProperties:r||new Map,id:o,nodeProperties:new Map,root:c}},exports.createUndoManager=function(e,n){return new t.UndoManager(n,{trackedOrigins:new Set([e,null])})},exports.getAnchorAndFocusCollabNodesForUserState=R,exports.initLocalState=function(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})},exports.setLocalStateFocus=function(e,t,n,o,s){const{awareness:l}=e;let i=l.getLocalState();null===i&&(i={anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t}),i.focusing=o,l.setLocalState(i)},exports.syncCursorPositions=U,exports.syncLexicalUpdateToYjs=function(t,n,o,s,l,i,r,a){!function(e,t){e.doc.transact(t,e)}(t,(()=>{s.read((()=>{if(a.has("collaboration")||a.has("historic"))return void(r.size>0&&function(t,n){const o=Array.from(n),s=t.collabNodeMap,l=[],i=[];for(let t=0;t<o.length;t++){const n=o[t],r=e.$getNodeByKey(n),a=s.get(n);if(a instanceof c)if(e.$isTextNode(r))l.push([a,r.__text]);else{const e=a.getOffset();if(-1===e)continue;const t=a._parent;a._normalized=!0,t._xmlText.delete(e,1),i.push(a)}}for(let e=0;e<i.length;e++){const t=i[e],n=t.getKey();s.delete(n);const o=t._parent._children,l=o.indexOf(t);o.splice(l,1)}for(let e=0;e<l.length;e++){const[t,n]=l[e];t._text=n}}(t,r));if(l.has("root")){const n=o._nodeMap,s=e.$getRoot(),r=t.root;r.syncPropertiesFromLexical(t,s,n),r.syncChildrenFromLexical(t,s,n,l,i)}const s=e.$getSelection(),f=o._selection;X(t,n,f,s)}))}))},exports.syncYjsChangesToLexical=function(t,n,o,s,l=U){const i=t.editor,r=i._editorState;o.forEach((e=>e.delta)),i.update((()=>{for(let e=0;e<o.length;e++){const n=o[e];q(t,n)}const s=e.$getSelection();if(e.$isRangeSelection(s))if(v(s)){const o=r._selection;if(e.$isRangeSelection(o)&&(B(t,n),v(s))){w(s.anchor.key,r)}X(t,n,o,e.$getSelection())}else B(t,n)}),{onUpdate:()=>{l(t,n),i.update((()=>{0===e.$getRoot().getChildrenSize()&&e.$getRoot().append(e.$createParagraphNode())}))},skipTransforms:!0,tag:s?"historic":"collaboration"})};
9
+ "use strict";var e=require("lexical"),t=require("yjs"),n=require("@lexical/offset"),o=require("@lexical/selection");function s(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class l{constructor(e,t){this._key="",this._map=e,this._parent=t,this._type="linebreak"}getNode(){const t=e.$getNodeByKey(this._key);return e.$isLineBreakNode(t)?t:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(e){e.collabNodeMap.delete(this._key)}}function i(e,t){const n=new l(e,t);return e._collabNode=n,n}class r{constructor(e,t,n,o){this._key="",this._map=e,this._parent=n,this._text=t,this._type=o,this._normalized=!1}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e.$isTextNode(n)?n:null}getNode(){const t=e.$getNodeByKey(this._key);return e.$isTextNode(t)?t: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(e,t,n){const o=this._parent._xmlText,s=this.getOffset()+1+e;0!==t&&o.delete(s,t),""!==n&&o.insert(s,n)}syncPropertiesAndTextFromLexical(t,n,o){const s=this.getPrevNode(o),l=n.__text;if(k(t,this._map,s,n),null!==s){const t=s.__text;if(t!==l){!function(t,n,o,s){const l=e.$getSelection();let i=s.length;if(e.$isRangeSelection(l)&&l.isCollapsed()){const e=l.anchor;e.key===n&&(i=e.offset)}const r=function(e,t,n){const o=e.length,s=t.length;let l=0,i=0;for(;l<o&&l<s&&e[l]===t[l]&&l<n;)l++;for(;i+l<o&&i+l<s&&e[o-i-1]===t[s-i-1];)i++;for(;i+l<o&&i+l<s&&e[l]===t[l];)l++;return{index:l,insert:t.slice(l,s-i),remove:o-l-i}}(o,s,i);t.spliceText(r.index,r.remove,r.insert)}(this,n.__key,t,l),this._text=l}}}syncPropertiesAndTextFromYjs(e,t){const n=this.getNode();null===n&&s(84),x(e,this._map,n,t);const o=this._text;if(n.__text!==o){n.getWritable().__text=o}}destroy(e){e.collabNodeMap.delete(this._key)}}function c(e,t,n,o){const s=new r(e,t,n,o);return e._collabNode=s,s}const a=new Set(["__key","__parent","__next","__prev","__state"]),f=new Set(["__first","__last","__size"]),u=new Set(["__cachedText"]),d=new Set(["__text"]);function _(t,n,o){if(a.has(t)||"function"==typeof n[t])return!0;if(e.$isTextNode(n)){if(d.has(t))return!0}else if(e.$isElementNode(n)&&(f.has(t)||e.$isRootNode(n)&&u.has(t)))return!0;const s=n.constructor,l=o.excludedProperties.get(s);return null!=l&&l.has(t)}function h(n,o,l){const r=o.__type;let a;if(e.$isElementNode(o)){a=M(new t.XmlText,l,r),a.syncPropertiesFromLexical(n,o,null),a.syncChildrenFromLexical(n,o,null,null,null)}else if(e.$isTextNode(o)){a=c(new t.Map,o.__text,l,r),a.syncPropertiesAndTextFromLexical(n,o,null)}else if(e.$isLineBreakNode(o)){const e=new t.Map;e.set("__type","linebreak"),a=i(e,l)}else if(e.$isDecoratorNode(o)){a=P(new t.XmlElement,l,r),a.syncPropertiesFromLexical(n,o,null)}else s(86);return a._key=o.__key,a}function g(e){const t=m(e,"__type");return"string"!=typeof t&&void 0!==t&&s(87),t}function p(e,n,o){const l=n._collabNode;if(void 0===l){const l=e.editor._nodes,r=g(n);"string"!=typeof r&&s(87);void 0===l.get(r)&&s(88,r);const a=n.parent,f=void 0===o&&null!==a?p(e,a):o||null;if(f instanceof E||s(89),n instanceof t.XmlText)return M(n,f,r);if(n instanceof t.Map)return"linebreak"===r?i(n,f):c(n,"",f,r);if(n instanceof t.XmlElement)return P(n,f,r)}return l}function y(e,t,n){const o=t.getType(),l=e.editor._nodes.get(o);void 0===l&&s(88,o);const i=new l.klass;if(i.__parent=n,t._key=i.__key,t instanceof E){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof r?t.syncPropertiesAndTextFromYjs(e,null):t instanceof w&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(i.__key,t),i}function x(n,o,s,l){const i=null===l?o instanceof t.Map?Array.from(o.keys()):Object.keys(o.getAttributes()):Array.from(l);let r;for(let l=0;l<i.length;l++){const c=i[l];if(_(c,s,n)){"__state"===c&&(r||(r=s.getWritable()),b(n,o,r));continue}const a=s[c];let f=m(o,c);if(a!==f){if(f instanceof t.Doc){const o=n.docMap;a instanceof t.Doc&&o.delete(a.guid);const s=e.createEditor(),l=f.guid;s._key=l,o.set(l,f),f=s}void 0===r&&(r=s.getWritable()),r[c]=f}}}function m(e,n){return e instanceof t.Map?e.get(n):e.getAttribute(n)}function N(e,n,o){e instanceof t.Map?e.set(n,o):e.setAttribute(n,o)}function b(n,o,s){const l=m(o,"__state");l instanceof t.Map&&e.$getWritableNodeState(s).updateFromJSON(l.toJSON())}function k(e,n,o,s){const l=s.__type,i=e.nodeProperties;let r=i.get(l);void 0===r&&(r=Object.keys(s).filter((t=>!_(t,s,e))),i.set(l,r));const c=e.editor.constructor;!function(e,n,o,s){const l=s.__state,i=m(n,"__state");if(!l)return;const[r,c]=l.getInternalState(),a=o&&o.__state,f=i instanceof t.Map?i:new t.Map;if(a===l)return;const[u,d]=a&&f.doc?a.getInternalState():[void 0,new Map];if(r)for(const[e,t]of Object.entries(r))u&&t!==u[e]&&f.set(e,t);for(const[e,t]of c)d.get(e)!==t&&f.set(e.key,e.unparse(t));i||N(n,"__state",f)}(0,n,o,s);for(let l=0;l<r.length;l++){const i=r[l],a=null===o?void 0:o[i];let f=s[i];if(a!==f){if(f instanceof c){const n=e.docMap;let o;if(a instanceof c){const e=a._key;o=n.get(e),n.delete(e)}const l=o||new t.Doc,i=l.guid;f._key=i,n.set(i,l),f=l,e.editor.update((()=>{s.markDirty()}))}N(n,i,f)}}}function T(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function $(e,t,n){let o=0,s=0;const l=e._children,i=l.length;for(;s<i;s++){const e=l[s],c=o;o+=e.getSize();if((n?o>=t:o>t)&&e instanceof r){let n=t-c-1;n<0&&(n=0);return{length:o-t,node:e,nodeIndex:s,offset:n}}if(o>t)return{length:0,node:e,nodeIndex:s,offset:c};if(s===i-1)return{length:0,node:null,nodeIndex:s+1,offset:c+1}}return{length:0,node:null,nodeIndex:0,offset:0}}function C(t){const n=t.anchor,o=t.focus;let s=!1;try{const t=n.getNode(),l=o.getNode();(!t.isAttached()||!l.isAttached()||e.$isTextNode(t)&&n.offset>t.getTextContentSize()||e.$isTextNode(l)&&o.offset>l.getTextContentSize())&&(s=!0)}catch(e){s=!0}return s}function S(e){const t=e.getParent();if(null!==t){const n=e.getWritable(),o=t.getWritable(),s=e.getPreviousSibling(),l=e.getNextSibling();if(null===s)if(null!==l){const e=l.getWritable();o.__first=l.__key,e.__prev=null}else o.__first=null;else{const e=s.getWritable();if(null!==l){const t=l.getWritable();t.__prev=e.__key,e.__next=t.__key}else e.__next=null;n.__prev=null}if(null===l)if(null!==s){const e=s.getWritable();o.__last=s.__key,e.__next=null}else o.__last=null;else{const e=l.getWritable();if(null!==s){const t=s.getWritable();t.__next=e.__key,e.__prev=t.__key}else e.__prev=null;n.__next=null}o.__size--,n.__parent=null}}function v(t,n){const o=n._nodeMap.get(t);if(!o)return void e.$getRoot().selectStart();const s=o.__prev;let l=null;s&&(l=e.$getNodeByKey(s)),null===l&&null!==o.__parent&&(l=e.$getNodeByKey(o.__parent)),null!==l?null!==l&&l.isAttached()?l.selectEnd():v(l.__key,n):e.$getRoot().selectStart()}class w{constructor(e,t,n){this._key="",this._xmlElem=e,this._parent=t,this._type=n}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e.$isDecoratorNode(n)?n:null}getNode(){const t=e.$getNodeByKey(this._key);return e.$isDecoratorNode(t)?t:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}syncPropertiesFromLexical(e,t,n){const o=this.getPrevNode(n);k(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&s(83);x(e,this._xmlElem,n,t)}destroy(e){e.collabNodeMap.delete(this._key)}}function P(e,t,n){const o=new w(e,t,n);return e._collabNode=o,o}class E{constructor(e,t,n){this._key="",this._children=[],this._xmlText=e,this._type=n,this._parent=t}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e.$isElementNode(n)?n:null}getNode(){const t=e.$getNodeByKey(this._key);return e.$isElementNode(t)?t:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){const e=this._parent;return null===e&&s(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&s(91),x(e,this._xmlText,n,t)}applyChildrenYjsDelta(e,t){const n=this._children;let o=0,s=null;for(let i=0;i<t.length;i++){const c=t[i],a=c.insert,f=c.delete;if(null!=c.retain)o+=c.retain;else if("number"==typeof f){let e=f;for(;e>0;){const{node:t,nodeIndex:s,offset:i,length:c}=$(this,o,!1);if(t instanceof E||t instanceof l||t instanceof w)n.splice(s,1),e-=1;else{if(!(t instanceof r))break;{const o=Math.min(e,c),l=0!==s?n[s-1]:null,a=t.getSize();if(0===i&&c===a){n.splice(s,1);const e=T(t._text,i,o-1,"");e.length>0&&(l instanceof r?l._text+=e:this._xmlText.delete(i,e.length))}else t._text=T(t._text,i,o,"");e-=o}}}}else{if(null==a)throw new Error("Unexpected delta format");if("string"==typeof a){const{node:e,offset:t}=$(this,o,!0);e instanceof r?e._text=T(e._text,t,0,a):this._xmlText.delete(t,a.length),o+=a.length}else{const t=a,{node:l,nodeIndex:i,length:c}=$(this,o,!1),f=p(e,t,this);if(l instanceof r&&c>0&&c<l._text.length){const e=l._text,t=e.length-c;l._text=T(e,t,c,""),n.splice(i+1,0,f),s=T(e,0,t,"")}else n.splice(i,0,f);null!==s&&f instanceof r&&(f._text=s+f._text,s=null),o+=1}}}}syncChildrenFromYjs(t){const o=this.getNode();null===o&&s(92);const i=o.__key,c=n.$createChildrenArray(o,null),a=c.length,f=this._children,u=f.length,d=t.collabNodeMap,_=new Set;let h,g,p=0,x=null;u!==a&&(g=o.getWritable());for(let n=0;n<u;n++){const a=c[p],m=f[n],N=m.getNode(),b=m._key;if(null!==N&&a===b){const n=e.$isTextNode(N);if(_.add(a),n)if(m._key=a,m instanceof E){const e=m._xmlText;m.syncPropertiesFromYjs(t,null),m.applyChildrenYjsDelta(t,e.toDelta()),m.syncChildrenFromYjs(t)}else m instanceof r?m.syncPropertiesAndTextFromYjs(t,null):m instanceof w?m.syncPropertiesFromYjs(t,null):m instanceof l||s(93);x=N,p++}else{if(void 0===h){h=new Set;for(let e=0;e<u;e++){const t=f[e]._key;""!==t&&h.add(t)}}if(null!==N&&void 0!==a&&!h.has(a)){S(e.$getNodeByKeyOrThrow(a)),n--,p++;continue}g=o.getWritable();const s=y(t,m,i),l=s.__key;if(d.set(l,m),null===x){const e=g.getFirstChild();if(g.__first=l,null!==e){const t=e.getWritable();t.__prev=l,s.__next=t.__key}}else{const e=x.getWritable(),t=x.getNextSibling();if(e.__next=l,s.__prev=x.__key,null!==t){const e=t.getWritable();e.__prev=l,s.__next=e.__key}}n===u-1&&(g.__last=l),g.__size++,x=s}}for(let n=0;n<a;n++){const o=c[n];if(!_.has(o)){const n=e.$getNodeByKeyOrThrow(o),s=t.collabNodeMap.get(o);void 0!==s&&s.destroy(t),S(n)}}}syncPropertiesFromLexical(e,t,n){k(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(t,n,o,s,l,i){const c=this._children[n],a=e.$getNodeByKeyOrThrow(o);c instanceof E&&e.$isElementNode(a)?(c.syncPropertiesFromLexical(t,a,s),c.syncChildrenFromLexical(t,a,s,l,i)):c instanceof r&&e.$isTextNode(a)?c.syncPropertiesAndTextFromLexical(t,a,s):c instanceof w&&e.$isDecoratorNode(a)&&c.syncPropertiesFromLexical(t,a,s)}syncChildrenFromLexical(t,o,s,l,i){const r=this.getPrevNode(s),c=null===r?[]:n.$createChildrenArray(r,s),a=n.$createChildrenArray(o,null),f=c.length-1,u=a.length-1,d=t.collabNodeMap;let _,g,p=0,y=0;for(;p<=f&&y<=u;){const n=c[p],o=a[y];if(n===o)this._syncChildFromLexical(t,y,o,s,l,i),p++,y++;else{void 0===_&&(_=new Set(c)),void 0===g&&(g=new Set(a));const s=g.has(n),l=_.has(o);if(s){const n=h(t,e.$getNodeByKeyOrThrow(o),this);d.set(o,n),l?(this.splice(t,y,1,n),p++,y++):(this.splice(t,y,0,n),y++)}else this.splice(t,y,1),p++}}const x=p>f,m=y>u;if(x&&!m)for(;y<=u;++y){const n=a[y],o=h(t,e.$getNodeByKeyOrThrow(n),this);this.append(o),d.set(n,o)}else if(m&&!x)for(let e=this._children.length-1;e>=y;e--)this.splice(t,e,1)}append(e){const t=this._xmlText,n=this._children,o=n[n.length-1],s=void 0!==o?o.getOffset()+o.getSize():0;if(e instanceof E)t.insertEmbed(s,e._xmlText);else if(e instanceof r){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof l?t.insertEmbed(s,e._map):e instanceof w&&t.insertEmbed(s,e._xmlElem);this._children.push(e)}splice(e,t,n,o){const i=this._children,c=i[t];if(void 0===c)return void 0===o&&s(94),void this.append(o);const a=c.getOffset();-1===a&&s(95);const f=this._xmlText;if(0!==n&&f.delete(a,c.getSize()),o instanceof E)f.insertEmbed(a,o._xmlText);else if(o instanceof r){const e=o._map;null===e.parent&&f.insertEmbed(a,e),f.insert(a+1,o._text)}else o instanceof l?f.insertEmbed(a,o._map):o instanceof w&&f.insertEmbed(a,o._xmlElem);if(0!==n){const o=i.slice(t,t+n);for(let t=0;t<o.length;t++)o[t].destroy(e)}void 0!==o?i.splice(t,n,o):i.splice(t,n)}getChildOffset(e){let t=0;const n=this._children;for(let o=0;o<n.length;o++){const s=n[o];if(s===e)return t;t+=s.getSize()}return-1}destroy(e){const t=e.collabNodeMap,n=this._children;for(let t=0;t<n.length;t++)n[t].destroy(e);t.delete(this._key)}}function M(e,t,n){const o=new E(e,t,n);return e._collabNode=o,o}function O(n,o){const l=o.collabNodeMap.get(n.key);if(void 0===l)return null;let i=n.offset,c=l.getSharedType();if(l instanceof r){c=l._parent._xmlText;const e=l.getOffset();if(-1===e)return null;i=e+1+i}else if(l instanceof E&&"element"===n.type){const t=n.getNode();e.$isElementNode(t)||s(184);let o=0,l=0,r=t.getFirstChild();for(;null!==r&&l++<i;)e.$isTextNode(r)?o+=r.getTextContentSize()+1:o++,r=r.getNextSibling();i=o}return t.createRelativePositionFromTypeIndex(c,i)}function F(e,n){return t.createAbsolutePositionFromRelativePosition(e,n.doc)}function L(e,n){if(null==e){if(null!=n)return!0}else if(null==n||!t.compareRelativePositions(e,n))return!0;return!1}function A(e,t){return{color:t,name:e,selection:null}}function D(e,t){const n=e.cursorsContainer;if(null!==n){const e=t.selections,o=e.length;for(let t=0;t<o;t++)n.removeChild(e[t])}}function j(e,t){const n=t.selection;null!==n&&D(e,n)}function z(e,t,n,o,s){const l=e.color,i=document.createElement("span");i.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${l};z-index:10;`;const r=document.createElement("span");return r.textContent=e.name,r.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${l};color:#fff;line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`,i.appendChild(r),{anchor:{key:t,offset:n},caret:i,color:l,focus:{key:o,offset:s},name:r,selections:[]}}function Y(t,n,s,l){const i=t.editor,r=i.getRootElement(),c=t.cursorsContainer;if(null===c||null===r)return;const a=c.offsetParent;if(null===a)return;const f=a.getBoundingClientRect(),u=n.selection;if(null===s)return null===u?void 0:(n.selection=null,void D(t,u));n.selection=s;const d=s.caret,_=s.color,h=s.selections,g=s.anchor,p=s.focus,y=g.key,x=p.key,m=l.get(y),N=l.get(x);if(null==m||null==N)return;let b;if(m===N&&e.$isLineBreakNode(m)){b=[i.getElementByKey(y).getBoundingClientRect()]}else{const e=o.createDOMRange(i,m,g.offset,N,p.offset);if(null===e)return;b=o.createRectsFromDOMRange(i,e)}const k=h.length,T=b.length;for(let e=0;e<T;e++){const t=b[e];let n=h[e];if(void 0===n){n=document.createElement("span"),h[e]=n;const t=document.createElement("span");n.appendChild(t),c.appendChild(n)}const o=`position:absolute;top:${t.top-f.top}px;left:${t.left-f.left}px;height:${t.height}px;width:${t.width}px;pointer-events:none;z-index:5;`;n.style.cssText=o,n.firstChild.style.cssText=`${o}left:0;top:0;background-color:${_};opacity:0.3;`,e===T-1&&d.parentNode!==n&&n.appendChild(d)}for(let e=k-1;e>=T;e--){const t=h[e];c.removeChild(t),h.pop()}}function K(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,l=0,i=null,r=0;if(null!==n&&null!==o){const t=F(n,e),c=F(o,e);null!==t&&null!==c&&([s,l]=W(t.type,t.index),[i,r]=W(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:l,focusCollabNode:i,focusOffset:r}}function R(t,n){const o=n.awareness.getLocalState();if(null===o)return;const{anchorCollabNode:s,anchorOffset:l,focusCollabNode:i,focusOffset:r}=K(t,o);if(null!==s&&null!==i){const t=s.getKey(),n=i.getKey(),o=e.$getSelection();if(!e.$isRangeSelection(o))return;B(o.anchor,t,l),B(o.focus,n,r)}}function B(t,n,o){if(t.key!==n||t.offset!==o){let s=e.$getNodeByKey(n);if(null!==s&&!e.$isElementNode(s)&&!e.$isTextNode(s)){const e=s.getParentOrThrow();n=e.getKey(),o=s.getIndexWithinParent(),s=e}t.set(n,o,e.$isElementNode(s)?"element":"text")}}function W(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof E){const{node:e,offset:o}=$(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function I(e,t){const n=Array.from(t.awareness.getStates()),o=e.clientID,s=e.cursors,l=e.editor._editorState._nodeMap,i=new Set;for(let t=0;t<n.length;t++){const r=n[t],[c,a]=r;if(c!==o){i.add(c);const{name:t,color:n,focusing:o}=a;let r=null,f=s.get(c);if(void 0===f&&(f=A(t,n),s.set(c,f)),o){const{anchorCollabNode:t,anchorOffset:n,focusCollabNode:o,focusOffset:s}=K(e,a);if(null!==t&&null!==o){const e=t.getKey(),l=o.getKey();if(r=f.selection,null===r)r=z(f,e,n,l,s);else{const t=r.anchor,o=r.focus;t.key=e,t.offset=n,o.key=l,o.offset=s}}}Y(e,f,r,l)}}const r=Array.from(s.keys());for(let t=0;t<r.length;t++){const n=r[t];if(!i.has(n)){const t=s.get(n);void 0!==t&&(j(e,t),s.delete(n))}}}function U(t,n,o,s){const l=n.awareness,i=l.getLocalState();if(null===i)return;const{anchorPos:r,focusPos:c,name:a,color:f,focusing:u,awarenessData:d}=i;let _=null,h=null;(null!==s&&(null===r||s.is(o))||null!==o)&&(e.$isRangeSelection(s)&&(_=O(s.anchor,t),h=O(s.focus,t)),(L(r,_)||L(c,h))&&l.setLocalState({...i,anchorPos:_,awarenessData:d,color:f,focusPos:h,focusing:u,name:a}))}function X(n,o){if(o instanceof t.YMapEvent&&function(n,o){const{target:s}=o;if(!s._item||"__state"!==s._item.parentSub||void 0!==g(s)||!(s.parent instanceof t.XmlText||s.parent instanceof t.XmlElement||s.parent instanceof t.Map))return!1;const l=p(n,s.parent).getNode();if(l){const t=e.$getWritableNodeState(l.getWritable());for(const e of o.keysChanged)t.updateFromUnknown(e,s.get(e))}return!0}(n,o))return;const{target:l}=o,i=p(n,l);if(i instanceof E&&o instanceof t.YTextEvent){const{keysChanged:e,childListChanged:t,delta:s}=o;e.size>0&&i.syncPropertiesFromYjs(n,e),t&&(i.applyChildrenYjsDelta(n,s),i.syncChildrenFromYjs(n))}else if(i instanceof r&&o instanceof t.YMapEvent){const{keysChanged:e}=o;e.size>0&&i.syncPropertiesAndTextFromYjs(n,e)}else if(i instanceof w&&o instanceof t.YXmlEvent){const{attributesChanged:e}=o;e.size>0&&i.syncPropertiesFromYjs(n,e)}else s(82)}const q=e.createCommand("CONNECTED_COMMAND"),G=e.createCommand("TOGGLE_CONNECT_COMMAND");exports.CONNECTED_COMMAND=q,exports.TOGGLE_CONNECT_COMMAND=G,exports.createBinding=function(e,n,o,l,i,r){null==l&&s(81);const c=M(l.get("root",t.XmlText),null,"root");return c._key="root",{clientID:l.clientID,collabNodeMap:new Map,cursors:new Map,cursorsContainer:null,doc:l,docMap:i,editor:e,excludedProperties:r||new Map,id:o,nodeProperties:new Map,root:c}},exports.createUndoManager=function(e,n){return new t.UndoManager(n,{trackedOrigins:new Set([e,null])})},exports.getAnchorAndFocusCollabNodesForUserState=K,exports.initLocalState=function(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})},exports.setLocalStateFocus=function(e,t,n,o,s){const{awareness:l}=e;let i=l.getLocalState();null===i&&(i={anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t}),i.focusing=o,l.setLocalState(i)},exports.syncCursorPositions=I,exports.syncLexicalUpdateToYjs=function(t,n,o,s,l,i,c,a){!function(e,t){e.doc.transact(t,e)}(t,(()=>{s.read((()=>{if(a.has("collaboration")||a.has("historic"))return void(c.size>0&&function(t,n){const o=Array.from(n),s=t.collabNodeMap,l=[],i=[];for(let t=0;t<o.length;t++){const n=o[t],c=e.$getNodeByKey(n),a=s.get(n);if(a instanceof r)if(e.$isTextNode(c))l.push([a,c.__text]);else{const e=a.getOffset();if(-1===e)continue;const t=a._parent;a._normalized=!0,t._xmlText.delete(e,1),i.push(a)}}for(let e=0;e<i.length;e++){const t=i[e],n=t.getKey();s.delete(n);const o=t._parent._children,l=o.indexOf(t);o.splice(l,1)}for(let e=0;e<l.length;e++){const[t,n]=l[e];t._text=n}}(t,c));if(l.has("root")){const n=o._nodeMap,s=e.$getRoot(),r=t.root;r.syncPropertiesFromLexical(t,s,n),r.syncChildrenFromLexical(t,s,n,l,i)}const s=e.$getSelection(),f=o._selection;U(t,n,f,s)}))}))},exports.syncYjsChangesToLexical=function(t,n,o,s,l=I){const i=t.editor,r=i._editorState;o.forEach((e=>e.delta)),i.update((()=>{for(let e=0;e<o.length;e++){const n=o[e];X(t,n)}const s=e.$getSelection();if(e.$isRangeSelection(s))if(C(s)){const o=r._selection;if(e.$isRangeSelection(o)&&(R(t,n),C(s))){v(s.anchor.key,r)}U(t,n,o,e.$getSelection())}else R(t,n)}),{onUpdate:()=>{l(t,n),i.update((()=>{0===e.$getRoot().getChildrenSize()&&e.$getRoot().append(e.$createParagraphNode())}))},skipTransforms:!0,tag:s?"historic":"collaboration"})};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{$getNodeByKey as e,$isLineBreakNode as t,$isTextNode as n,$getSelection as o,$isRangeSelection as s,$isElementNode as l,$isDecoratorNode as i,createEditor as r,$getWritableNodeState as c,$getRoot as a,$isRootNode as f,$getNodeByKeyOrThrow as u,$createParagraphNode as d,createCommand as _}from"lexical";import{XmlText as h,Map as p,XmlElement as g,Doc as y,createAbsolutePositionFromRelativePosition as x,createRelativePositionFromTypeIndex as m,compareRelativePositions as b,YMapEvent as k,YTextEvent as v,YXmlEvent as C,UndoManager as N}from"yjs";import{$createChildrenArray as w}from"@lexical/offset";import{createDOMRange as S,createRectsFromDOMRange as P}from"@lexical/selection";function T(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var F=T((function(e){const t=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",e);for(let e=1;e<arguments.length;e++)n.append("v",arguments[e]);throw t.search=n.toString(),Error(`Minified Lexical error #${e}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));class O{constructor(e,t){this._key="",this._map=e,this._parent=t,this._type="linebreak"}getNode(){const n=e(this._key);return t(n)?n:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(e){e.collabNodeMap.delete(this._key)}}function M(e,t){const n=new O(e,t);return e._collabNode=n,n}class E{constructor(e,t,n,o){this._key="",this._map=e,this._parent=n,this._text=t,this._type=o,this._normalized=!1}getPrevNode(e){if(null===e)return null;const t=e.get(this._key);return n(t)?t:null}getNode(){const t=e(this._key);return n(t)?t: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(e,t,n){const o=this._parent._xmlText,s=this.getOffset()+1+e;0!==t&&o.delete(s,t),""!==n&&o.insert(s,n)}syncPropertiesAndTextFromLexical(e,t,n){const l=this.getPrevNode(n),i=t.__text;if(J(e,this._map,l,t),null!==l){const e=l.__text;if(e!==i){!function(e,t,n,l){const i=o();let r=l.length;if(s(i)&&i.isCollapsed()){const e=i.anchor;e.key===t&&(r=e.offset)}const c=function(e,t,n){const o=e.length,s=t.length;let l=0,i=0;for(;l<o&&l<s&&e[l]===t[l]&&l<n;)l++;for(;i+l<o&&i+l<s&&e[o-i-1]===t[s-i-1];)i++;for(;i+l<o&&i+l<s&&e[l]===t[l];)l++;return{index:l,insert:t.slice(l,s-i),remove:o-l-i}}(n,l,r);e.spliceText(c.index,c.remove,c.insert)}(this,t.__key,e,i),this._text=i}}}syncPropertiesAndTextFromYjs(e,t){const n=this.getNode();null===n&&F(84),R(e,this._map,n,t);const o=this._text;if(n.__text!==o){n.getWritable().__text=o}}destroy(e){e.collabNodeMap.delete(this._key)}}function L(e,t,n,o){const s=new E(e,t,n,o);return e._collabNode=s,s}const z=new Set(["__key","__parent","__next","__prev","__state"]),j=new Set(["__first","__last","__size"]),A=new Set(["__cachedText"]),Y=new Set(["__text"]);function W(e,t,o){if(z.has(e)||"function"==typeof t[e])return!0;if(n(t)){if(Y.has(e))return!0}else if(l(t)&&(j.has(e)||f(t)&&A.has(e)))return!0;const s=t.constructor,i=o.excludedProperties.get(s);return null!=i&&i.has(e)}function D(e,o,s){const r=o.__type;let c;if(l(o)){c=ne(new h,s,r),c.syncPropertiesFromLexical(e,o,null),c.syncChildrenFromLexical(e,o,null,null,null)}else if(n(o)){c=L(new p,o.__text,s,r),c.syncPropertiesAndTextFromLexical(e,o,null)}else if(t(o)){const e=new p;e.set("__type","linebreak"),c=M(e,s)}else if(i(o)){c=ee(new g,s,r),c.syncPropertiesFromLexical(e,o,null)}else F(86);return c._key=o.__key,c}function I(e){const t=U(e,"__type");return"string"!=typeof t&&void 0!==t&&F(87),t}function K(e,t,n){const o=t._collabNode;if(void 0===o){const o=e.editor._nodes,s=I(t);"string"!=typeof s&&F(87);void 0===o.get(s)&&F(88,s);const l=t.parent,i=void 0===n&&null!==l?K(e,l):n||null;if(i instanceof te||F(89),t instanceof h)return ne(t,i,s);if(t instanceof p)return"linebreak"===s?M(t,i):L(t,"",i,s);if(t instanceof g)return ee(t,i,s)}return o}function $(e,t,n){const o=t.getType(),s=e.editor._nodes.get(o);void 0===s&&F(88,o);const l=new s.klass;if(l.__parent=n,t._key=l.__key,t instanceof te){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof E?t.syncPropertiesAndTextFromYjs(e,null):t instanceof Z&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(l.__key,t),l}function R(e,t,n,o){const s=null===o?t instanceof p?Array.from(t.keys()):Object.keys(t.getAttributes()):Array.from(o);let l;for(let o=0;o<s.length;o++){const i=s[o];if(W(i,n,e)){"__state"===i&&(l||(l=n.getWritable()),G(e,t,l));continue}const c=n[i];let a=U(t,i);if(c!==a){if(a instanceof y){const t=e.docMap;c instanceof y&&t.delete(c.guid);const n=r(),o=a.guid;n._key=o,t.set(o,a),a=n}void 0===l&&(l=n.getWritable()),l[i]=a}}}function U(e,t){return e instanceof p?e.get(t):e.getAttribute(t)}function B(e,t,n){e instanceof p?e.set(t,n):e.setAttribute(t,n)}function G(e,t,n){const o=U(t,"__state");o instanceof p&&c(n).updateFromJSON(o.toJSON())}function J(e,t,n,o){const s=o.__type,l=e.nodeProperties;let i=l.get(s);void 0===i&&(i=Object.keys(o).filter((t=>!W(t,o,e))),l.set(s,i));const r=e.editor.constructor;!function(e,t,n,o){const s=o.__state,l=U(t,"__state");if(!s)return;const[i,r]=s.getInternalState(),c=n&&n.__state,a=l instanceof p?l:new p;if(c===s)return;const[f,u]=c&&a.doc?c.getInternalState():[void 0,new Map];if(i)for(const[e,t]of Object.entries(i))f&&t!==f[e]&&a.set(e,t);for(const[e,t]of r)u.get(e)!==t&&a.set(e.key,e.unparse(t));l||B(t,"__state",a)}(0,t,n,o);for(let s=0;s<i.length;s++){const l=i[s],c=null===n?void 0:n[l];let a=o[l];if(c!==a){if(a instanceof r){const t=e.docMap;let n;if(c instanceof r){const e=c._key;n=t.get(e),t.delete(e)}const s=n||new y,l=s.guid;a._key=l,t.set(l,s),a=s,e.editor.update((()=>{o.markDirty()}))}B(t,l,a)}}}function q(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function H(e,t,n){let o=0,s=0;const l=e._children,i=l.length;for(;s<i;s++){const e=l[s],r=o;o+=e.getSize();if((n?o>=t:o>t)&&e instanceof E){let n=t-r-1;n<0&&(n=0);return{length:o-t,node:e,nodeIndex:s,offset:n}}if(o>t)return{length:0,node:e,nodeIndex:s,offset:r};if(s===i-1)return{length:0,node:null,nodeIndex:s+1,offset:r+1}}return{length:0,node:null,nodeIndex:0,offset:0}}function Q(e){const t=e.anchor,o=e.focus;let s=!1;try{const e=t.getNode(),l=o.getNode();(!e.isAttached()||!l.isAttached()||n(e)&&t.offset>e.getTextContentSize()||n(l)&&o.offset>l.getTextContentSize())&&(s=!0)}catch(e){s=!0}return s}function V(e){const t=e.getParent();if(null!==t){const n=e.getWritable(),o=t.getWritable(),s=e.getPreviousSibling(),l=e.getNextSibling();if(null===s)if(null!==l){const e=l.getWritable();o.__first=l.__key,e.__prev=null}else o.__first=null;else{const e=s.getWritable();if(null!==l){const t=l.getWritable();t.__prev=e.__key,e.__next=t.__key}else e.__next=null;n.__prev=null}if(null===l)if(null!==s){const e=s.getWritable();o.__last=s.__key,e.__next=null}else o.__last=null;else{const e=l.getWritable();if(null!==s){const t=s.getWritable();t.__next=e.__key,e.__prev=t.__key}else e.__prev=null;n.__next=null}o.__size--,n.__parent=null}}function X(t,n){const o=n._nodeMap.get(t);if(!o)return void a().selectStart();const s=o.__prev;let l=null;s&&(l=e(s)),null===l&&null!==o.__parent&&(l=e(o.__parent)),null!==l?null!==l&&l.isAttached()?l.selectEnd():X(l.__key,n):a().selectStart()}class Z{constructor(e,t,n){this._key="",this._xmlElem=e,this._parent=t,this._type=n}getPrevNode(e){if(null===e)return null;const t=e.get(this._key);return i(t)?t:null}getNode(){const t=e(this._key);return i(t)?t:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}syncPropertiesFromLexical(e,t,n){const o=this.getPrevNode(n);J(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&F(83);R(e,this._xmlElem,n,t)}destroy(e){e.collabNodeMap.delete(this._key)}}function ee(e,t,n){const o=new Z(e,t,n);return e._collabNode=o,o}class te{constructor(e,t,n){this._key="",this._children=[],this._xmlText=e,this._type=n,this._parent=t}getPrevNode(e){if(null===e)return null;const t=e.get(this._key);return l(t)?t:null}getNode(){const t=e(this._key);return l(t)?t:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){const e=this._parent;return null===e&&F(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&F(91),R(e,this._xmlText,n,t)}applyChildrenYjsDelta(e,t){const n=this._children;let o=0,s=null;for(let l=0;l<t.length;l++){const i=t[l],r=i.insert,c=i.delete;if(null!=i.retain)o+=i.retain;else if("number"==typeof c){let e=c;for(;e>0;){const{node:t,nodeIndex:s,offset:l,length:i}=H(this,o,!1);if(t instanceof te||t instanceof O||t instanceof Z)n.splice(s,1),e-=1;else{if(!(t instanceof E))break;{const o=Math.min(e,i),r=0!==s?n[s-1]:null,c=t.getSize();if(0===l&&i===c){n.splice(s,1);const e=q(t._text,l,o-1,"");e.length>0&&(r instanceof E?r._text+=e:this._xmlText.delete(l,e.length))}else t._text=q(t._text,l,o,"");e-=o}}}}else{if(null==r)throw new Error("Unexpected delta format");if("string"==typeof r){const{node:e,offset:t}=H(this,o,!0);e instanceof E?e._text=q(e._text,t,0,r):this._xmlText.delete(t,r.length),o+=r.length}else{const t=r,{node:l,nodeIndex:i,length:c}=H(this,o,!1),a=K(e,t,this);if(l instanceof E&&c>0&&c<l._text.length){const e=l._text,t=e.length-c;l._text=q(e,t,c,""),n.splice(i+1,0,a),s=q(e,0,t,"")}else n.splice(i,0,a);null!==s&&a instanceof E&&(a._text=s+a._text,s=null),o+=1}}}}syncChildrenFromYjs(e){const t=this.getNode();null===t&&F(92);const o=t.__key,s=w(t,null),l=s.length,i=this._children,r=i.length,c=e.collabNodeMap,a=new Set;let f,d,_=0,h=null;r!==l&&(d=t.getWritable());for(let l=0;l<r;l++){const p=s[_],g=i[l],y=g.getNode(),x=g._key;if(null!==y&&p===x){const t=n(y);if(a.add(p),t)if(g._key=p,g instanceof te){const t=g._xmlText;g.syncPropertiesFromYjs(e,null),g.applyChildrenYjsDelta(e,t.toDelta()),g.syncChildrenFromYjs(e)}else g instanceof E?g.syncPropertiesAndTextFromYjs(e,null):g instanceof Z?g.syncPropertiesFromYjs(e,null):g instanceof O||F(93);h=y,_++}else{if(void 0===f){f=new Set;for(let e=0;e<r;e++){const t=i[e]._key;""!==t&&f.add(t)}}if(null!==y&&void 0!==p&&!f.has(p)){V(u(p)),l--,_++;continue}d=t.getWritable();const n=$(e,g,o),s=n.__key;if(c.set(s,g),null===h){const e=d.getFirstChild();if(d.__first=s,null!==e){const t=e.getWritable();t.__prev=s,n.__next=t.__key}}else{const e=h.getWritable(),t=h.getNextSibling();if(e.__next=s,n.__prev=h.__key,null!==t){const e=t.getWritable();e.__prev=s,n.__next=e.__key}}l===r-1&&(d.__last=s),d.__size++,h=n}}for(let t=0;t<l;t++){const n=s[t];if(!a.has(n)){const t=u(n),o=e.collabNodeMap.get(n);void 0!==o&&o.destroy(e),V(t)}}}syncPropertiesFromLexical(e,t,n){J(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(e,t,o,s,r,c){const a=this._children[t],f=u(o);a instanceof te&&l(f)?(a.syncPropertiesFromLexical(e,f,s),a.syncChildrenFromLexical(e,f,s,r,c)):a instanceof E&&n(f)?a.syncPropertiesAndTextFromLexical(e,f,s):a instanceof Z&&i(f)&&a.syncPropertiesFromLexical(e,f,s)}syncChildrenFromLexical(e,t,n,o,s){const l=this.getPrevNode(n),i=null===l?[]:w(l,n),r=w(t,null),c=i.length-1,a=r.length-1,f=e.collabNodeMap;let d,_,h=0,p=0;for(;h<=c&&p<=a;){const t=i[h],l=r[p];if(t===l)this._syncChildFromLexical(e,p,l,n,o,s),h++,p++;else{void 0===d&&(d=new Set(i)),void 0===_&&(_=new Set(r));const n=_.has(t),o=d.has(l);if(n){const t=D(e,u(l),this);f.set(l,t),o?(this.splice(e,p,1,t),h++,p++):(this.splice(e,p,0,t),p++)}else this.splice(e,p,1),h++}}const g=h>c,y=p>a;if(g&&!y)for(;p<=a;++p){const t=r[p],n=D(e,u(t),this);this.append(n),f.set(t,n)}else if(y&&!g)for(let t=this._children.length-1;t>=p;t--)this.splice(e,t,1)}append(e){const t=this._xmlText,n=this._children,o=n[n.length-1],s=void 0!==o?o.getOffset()+o.getSize():0;if(e instanceof te)t.insertEmbed(s,e._xmlText);else if(e instanceof E){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof O?t.insertEmbed(s,e._map):e instanceof Z&&t.insertEmbed(s,e._xmlElem);this._children.push(e)}splice(e,t,n,o){const s=this._children,l=s[t];if(void 0===l)return void 0===o&&F(94),void this.append(o);const i=l.getOffset();-1===i&&F(95);const r=this._xmlText;if(0!==n&&r.delete(i,l.getSize()),o instanceof te)r.insertEmbed(i,o._xmlText);else if(o instanceof E){const e=o._map;null===e.parent&&r.insertEmbed(i,e),r.insert(i+1,o._text)}else o instanceof O?r.insertEmbed(i,o._map):o instanceof Z&&r.insertEmbed(i,o._xmlElem);if(0!==n){const o=s.slice(t,t+n);for(let t=0;t<o.length;t++)o[t].destroy(e)}void 0!==o?s.splice(t,n,o):s.splice(t,n)}getChildOffset(e){let t=0;const n=this._children;for(let o=0;o<n.length;o++){const s=n[o];if(s===e)return t;t+=s.getSize()}return-1}destroy(e){const t=e.collabNodeMap,n=this._children;for(let t=0;t<n.length;t++)n[t].destroy(e);t.delete(this._key)}}function ne(e,t,n){const o=new te(e,t,n);return e._collabNode=o,o}function oe(e,t,n,o,s,l){null==o&&F(81);const i=ne(o.get("root",h),null,"root");return i._key="root",{clientID:o.clientID,collabNodeMap:new Map,cursors:new Map,cursorsContainer:null,doc:o,docMap:s,editor:e,excludedProperties:l||new Map,id:n,nodeProperties:new Map,root:i}}function se(e,t){const o=t.collabNodeMap.get(e.key);if(void 0===o)return null;let s=e.offset,i=o.getSharedType();if(o instanceof E){i=o._parent._xmlText;const e=o.getOffset();if(-1===e)return null;s=e+1+s}else if(o instanceof te&&"element"===e.type){const t=e.getNode();l(t)||F(184);let o=0,i=0,r=t.getFirstChild();for(;null!==r&&i++<s;)n(r)?o+=r.getTextContentSize()+1:o++,r=r.getNextSibling();s=o}return m(i,s)}function le(e,t){return x(e,t.doc)}function ie(e,t){if(null==e){if(null!=t)return!0}else if(null==t||!b(e,t))return!0;return!1}function re(e,t){return{color:t,name:e,selection:null}}function ce(e,t){const n=e.cursorsContainer;if(null!==n){const e=t.selections,o=e.length;for(let t=0;t<o;t++)n.removeChild(e[t])}}function ae(e,t){const n=t.selection;null!==n&&ce(e,n)}function fe(e,t,n,o,s){const l=e.color,i=document.createElement("span");i.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${l};z-index:10;`;const r=document.createElement("span");return r.textContent=e.name,r.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${l};color:#fff;line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`,i.appendChild(r),{anchor:{key:t,offset:n},caret:i,color:l,focus:{key:o,offset:s},name:r,selections:[]}}function ue(e,n,o,s){const l=e.editor,i=l.getRootElement(),r=e.cursorsContainer;if(null===r||null===i)return;const c=r.offsetParent;if(null===c)return;const a=c.getBoundingClientRect(),f=n.selection;if(null===o)return null===f?void 0:(n.selection=null,void ce(e,f));n.selection=o;const u=o.caret,d=o.color,_=o.selections,h=o.anchor,p=o.focus,g=h.key,y=p.key,x=s.get(g),m=s.get(y);if(null==x||null==m)return;let b;if(x===m&&t(x)){b=[l.getElementByKey(g).getBoundingClientRect()]}else{const e=S(l,x,h.offset,m,p.offset);if(null===e)return;b=P(l,e)}const k=_.length,v=b.length;for(let e=0;e<v;e++){const t=b[e];let n=_[e];if(void 0===n){n=document.createElement("span"),_[e]=n;const t=document.createElement("span");n.appendChild(t),r.appendChild(n)}const o=`position:absolute;top:${t.top-a.top}px;left:${t.left-a.left}px;height:${t.height}px;width:${t.width}px;pointer-events:none;z-index:5;`;n.style.cssText=o,n.firstChild.style.cssText=`${o}left:0;top:0;background-color:${d};opacity:0.3;`,e===v-1&&u.parentNode!==n&&n.appendChild(u)}for(let e=k-1;e>=v;e--){const t=_[e];r.removeChild(t),_.pop()}}function de(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,l=0,i=null,r=0;if(null!==n&&null!==o){const t=le(n,e),c=le(o,e);null!==t&&null!==c&&([s,l]=pe(t.type,t.index),[i,r]=pe(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:l,focusCollabNode:i,focusOffset:r}}function _e(e,t){const n=t.awareness.getLocalState();if(null===n)return;const{anchorCollabNode:l,anchorOffset:i,focusCollabNode:r,focusOffset:c}=de(e,n);if(null!==l&&null!==r){const e=l.getKey(),t=r.getKey(),n=o();if(!s(n))return;he(n.anchor,e,i),he(n.focus,t,c)}}function he(t,o,s){if(t.key!==o||t.offset!==s){let i=e(o);if(null!==i&&!l(i)&&!n(i)){const e=i.getParentOrThrow();o=e.getKey(),s=i.getIndexWithinParent(),i=e}t.set(o,s,l(i)?"element":"text")}}function pe(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof te){const{node:e,offset:o}=H(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function ge(e,t){const n=Array.from(t.awareness.getStates()),o=e.clientID,s=e.cursors,l=e.editor._editorState._nodeMap,i=new Set;for(let t=0;t<n.length;t++){const r=n[t],[c,a]=r;if(c!==o){i.add(c);const{name:t,color:n,focusing:o}=a;let r=null,f=s.get(c);if(void 0===f&&(f=re(t,n),s.set(c,f)),o){const{anchorCollabNode:t,anchorOffset:n,focusCollabNode:o,focusOffset:s}=de(e,a);if(null!==t&&null!==o){const e=t.getKey(),l=o.getKey();if(r=f.selection,null===r)r=fe(f,e,n,l,s);else{const t=r.anchor,o=r.focus;t.key=e,t.offset=n,o.key=l,o.offset=s}}}ue(e,f,r,l)}}const r=Array.from(s.keys());for(let t=0;t<r.length;t++){const n=r[t];if(!i.has(n)){const t=s.get(n);void 0!==t&&(ae(e,t),s.delete(n))}}}function ye(e,t,n,o){const l=t.awareness,i=l.getLocalState();if(null===i)return;const{anchorPos:r,focusPos:c,name:a,color:f,focusing:u,awarenessData:d}=i;let _=null,h=null;(null!==o&&(null===r||o.is(n))||null!==n)&&(s(o)&&(_=se(o.anchor,e),h=se(o.focus,e)),(ie(r,_)||ie(c,h))&&l.setLocalState({...i,anchorPos:_,awarenessData:d,color:f,focusPos:h,focusing:u,name:a}))}function xe(e,t){if(t instanceof k&&function(e,t){const{target:n}=t;if(!n._item||"__state"!==n._item.parentSub||void 0!==I(n)||!(n.parent instanceof h||n.parent instanceof g||n.parent instanceof p))return!1;const o=K(e,n.parent).getNode();if(o){const e=c(o.getWritable());for(const o of t.keysChanged)e.updateFromUnknown(o,n.get(o))}return!0}(e,t))return;const{target:n}=t,o=K(e,n);if(o instanceof te&&t instanceof v){const{keysChanged:n,childListChanged:s,delta:l}=t;n.size>0&&o.syncPropertiesFromYjs(e,n),s&&(o.applyChildrenYjsDelta(e,l),o.syncChildrenFromYjs(e))}else if(o instanceof E&&t instanceof k){const{keysChanged:n}=t;n.size>0&&o.syncPropertiesAndTextFromYjs(e,n)}else if(o instanceof Z&&t instanceof C){const{attributesChanged:n}=t;n.size>0&&o.syncPropertiesFromYjs(e,n)}else F(82)}function me(e,t,n,l,i=ge){const r=e.editor,c=r._editorState;n.forEach((e=>e.delta)),r.update((()=>{for(let t=0;t<n.length;t++){const o=n[t];xe(e,o)}const l=o();if(s(l))if(Q(l)){const n=c._selection;if(s(n)&&(_e(e,t),Q(l))){X(l.anchor.key,c)}ye(e,t,n,o())}else _e(e,t)}),{onUpdate:()=>{i(e,t),r.update((()=>{0===a().getChildrenSize()&&a().append(d())}))},skipTransforms:!0,tag:l?"historic":"collaboration"})}function be(t,s,l,i,r,c,f,u){!function(e,t){e.doc.transact(t,e)}(t,(()=>{i.read((()=>{if(u.has("collaboration")||u.has("historic"))return void(f.size>0&&function(t,o){const s=Array.from(o),l=t.collabNodeMap,i=[],r=[];for(let t=0;t<s.length;t++){const o=s[t],c=e(o),a=l.get(o);if(a instanceof E)if(n(c))i.push([a,c.__text]);else{const e=a.getOffset();if(-1===e)continue;const t=a._parent;a._normalized=!0,t._xmlText.delete(e,1),r.push(a)}}for(let e=0;e<r.length;e++){const t=r[e],n=t.getKey();l.delete(n);const o=t._parent._children,s=o.indexOf(t);o.splice(s,1)}for(let e=0;e<i.length;e++){const[t,n]=i[e];t._text=n}}(t,f));if(r.has("root")){const e=l._nodeMap,n=a(),o=t.root;o.syncPropertiesFromLexical(t,n,e),o.syncChildrenFromLexical(t,n,e,r,c)}const i=o(),d=l._selection;ye(t,s,d,i)}))}))}const ke=_("CONNECTED_COMMAND"),ve=_("TOGGLE_CONNECT_COMMAND");function Ce(e,t){return new N(t,{trackedOrigins:new Set([e,null])})}function Ne(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})}function we(e,t,n,o,s){const{awareness:l}=e;let i=l.getLocalState();null===i&&(i={anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t}),i.focusing=o,l.setLocalState(i)}export{ke as CONNECTED_COMMAND,ve as TOGGLE_CONNECT_COMMAND,oe as createBinding,Ce as createUndoManager,de as getAnchorAndFocusCollabNodesForUserState,Ne as initLocalState,we as setLocalStateFocus,ge as syncCursorPositions,be as syncLexicalUpdateToYjs,me as syncYjsChangesToLexical};
9
+ import{$getNodeByKey as e,$isLineBreakNode as t,$isTextNode as n,$getSelection as o,$isRangeSelection as s,$isElementNode as l,$isDecoratorNode as i,createEditor as r,$getWritableNodeState as c,$getRoot as a,$isRootNode as f,$getNodeByKeyOrThrow as u,$createParagraphNode as d,createCommand as _}from"lexical";import{XmlText as h,Map as p,XmlElement as g,Doc as y,createAbsolutePositionFromRelativePosition as x,createRelativePositionFromTypeIndex as m,compareRelativePositions as b,YMapEvent as k,YTextEvent as v,YXmlEvent as C,UndoManager as N}from"yjs";import{$createChildrenArray as S}from"@lexical/offset";import{createDOMRange as w,createRectsFromDOMRange as P}from"@lexical/selection";function T(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class F{constructor(e,t){this._key="",this._map=e,this._parent=t,this._type="linebreak"}getNode(){const n=e(this._key);return t(n)?n:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(e){e.collabNodeMap.delete(this._key)}}function O(e,t){const n=new F(e,t);return e._collabNode=n,n}class E{constructor(e,t,n,o){this._key="",this._map=e,this._parent=n,this._text=t,this._type=o,this._normalized=!1}getPrevNode(e){if(null===e)return null;const t=e.get(this._key);return n(t)?t:null}getNode(){const t=e(this._key);return n(t)?t: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(e,t,n){const o=this._parent._xmlText,s=this.getOffset()+1+e;0!==t&&o.delete(s,t),""!==n&&o.insert(s,n)}syncPropertiesAndTextFromLexical(e,t,n){const l=this.getPrevNode(n),i=t.__text;if(G(e,this._map,l,t),null!==l){const e=l.__text;if(e!==i){!function(e,t,n,l){const i=o();let r=l.length;if(s(i)&&i.isCollapsed()){const e=i.anchor;e.key===t&&(r=e.offset)}const c=function(e,t,n){const o=e.length,s=t.length;let l=0,i=0;for(;l<o&&l<s&&e[l]===t[l]&&l<n;)l++;for(;i+l<o&&i+l<s&&e[o-i-1]===t[s-i-1];)i++;for(;i+l<o&&i+l<s&&e[l]===t[l];)l++;return{index:l,insert:t.slice(l,s-i),remove:o-l-i}}(n,l,r);e.spliceText(c.index,c.remove,c.insert)}(this,t.__key,e,i),this._text=i}}}syncPropertiesAndTextFromYjs(e,t){const n=this.getNode();null===n&&T(84),$(e,this._map,n,t);const o=this._text;if(n.__text!==o){n.getWritable().__text=o}}destroy(e){e.collabNodeMap.delete(this._key)}}function M(e,t,n,o){const s=new E(e,t,n,o);return e._collabNode=s,s}const L=new Set(["__key","__parent","__next","__prev","__state"]),z=new Set(["__first","__last","__size"]),j=new Set(["__cachedText"]),A=new Set(["__text"]);function Y(e,t,o){if(L.has(e)||"function"==typeof t[e])return!0;if(n(t)){if(A.has(e))return!0}else if(l(t)&&(z.has(e)||f(t)&&j.has(e)))return!0;const s=t.constructor,i=o.excludedProperties.get(s);return null!=i&&i.has(e)}function W(e,o,s){const r=o.__type;let c;if(l(o)){c=te(new h,s,r),c.syncPropertiesFromLexical(e,o,null),c.syncChildrenFromLexical(e,o,null,null,null)}else if(n(o)){c=M(new p,o.__text,s,r),c.syncPropertiesAndTextFromLexical(e,o,null)}else if(t(o)){const e=new p;e.set("__type","linebreak"),c=O(e,s)}else if(i(o)){c=Z(new g,s,r),c.syncPropertiesFromLexical(e,o,null)}else T(86);return c._key=o.__key,c}function D(e){const t=R(e,"__type");return"string"!=typeof t&&void 0!==t&&T(87),t}function I(e,t,n){const o=t._collabNode;if(void 0===o){const o=e.editor._nodes,s=D(t);"string"!=typeof s&&T(87);void 0===o.get(s)&&T(88,s);const l=t.parent,i=void 0===n&&null!==l?I(e,l):n||null;if(i instanceof ee||T(89),t instanceof h)return te(t,i,s);if(t instanceof p)return"linebreak"===s?O(t,i):M(t,"",i,s);if(t instanceof g)return Z(t,i,s)}return o}function K(e,t,n){const o=t.getType(),s=e.editor._nodes.get(o);void 0===s&&T(88,o);const l=new s.klass;if(l.__parent=n,t._key=l.__key,t instanceof ee){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof E?t.syncPropertiesAndTextFromYjs(e,null):t instanceof X&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(l.__key,t),l}function $(e,t,n,o){const s=null===o?t instanceof p?Array.from(t.keys()):Object.keys(t.getAttributes()):Array.from(o);let l;for(let o=0;o<s.length;o++){const i=s[o];if(Y(i,n,e)){"__state"===i&&(l||(l=n.getWritable()),B(e,t,l));continue}const c=n[i];let a=R(t,i);if(c!==a){if(a instanceof y){const t=e.docMap;c instanceof y&&t.delete(c.guid);const n=r(),o=a.guid;n._key=o,t.set(o,a),a=n}void 0===l&&(l=n.getWritable()),l[i]=a}}}function R(e,t){return e instanceof p?e.get(t):e.getAttribute(t)}function U(e,t,n){e instanceof p?e.set(t,n):e.setAttribute(t,n)}function B(e,t,n){const o=R(t,"__state");o instanceof p&&c(n).updateFromJSON(o.toJSON())}function G(e,t,n,o){const s=o.__type,l=e.nodeProperties;let i=l.get(s);void 0===i&&(i=Object.keys(o).filter((t=>!Y(t,o,e))),l.set(s,i));const r=e.editor.constructor;!function(e,t,n,o){const s=o.__state,l=R(t,"__state");if(!s)return;const[i,r]=s.getInternalState(),c=n&&n.__state,a=l instanceof p?l:new p;if(c===s)return;const[f,u]=c&&a.doc?c.getInternalState():[void 0,new Map];if(i)for(const[e,t]of Object.entries(i))f&&t!==f[e]&&a.set(e,t);for(const[e,t]of r)u.get(e)!==t&&a.set(e.key,e.unparse(t));l||U(t,"__state",a)}(0,t,n,o);for(let s=0;s<i.length;s++){const l=i[s],c=null===n?void 0:n[l];let a=o[l];if(c!==a){if(a instanceof r){const t=e.docMap;let n;if(c instanceof r){const e=c._key;n=t.get(e),t.delete(e)}const s=n||new y,l=s.guid;a._key=l,t.set(l,s),a=s,e.editor.update((()=>{o.markDirty()}))}U(t,l,a)}}}function J(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function q(e,t,n){let o=0,s=0;const l=e._children,i=l.length;for(;s<i;s++){const e=l[s],r=o;o+=e.getSize();if((n?o>=t:o>t)&&e instanceof E){let n=t-r-1;n<0&&(n=0);return{length:o-t,node:e,nodeIndex:s,offset:n}}if(o>t)return{length:0,node:e,nodeIndex:s,offset:r};if(s===i-1)return{length:0,node:null,nodeIndex:s+1,offset:r+1}}return{length:0,node:null,nodeIndex:0,offset:0}}function H(e){const t=e.anchor,o=e.focus;let s=!1;try{const e=t.getNode(),l=o.getNode();(!e.isAttached()||!l.isAttached()||n(e)&&t.offset>e.getTextContentSize()||n(l)&&o.offset>l.getTextContentSize())&&(s=!0)}catch(e){s=!0}return s}function Q(e){const t=e.getParent();if(null!==t){const n=e.getWritable(),o=t.getWritable(),s=e.getPreviousSibling(),l=e.getNextSibling();if(null===s)if(null!==l){const e=l.getWritable();o.__first=l.__key,e.__prev=null}else o.__first=null;else{const e=s.getWritable();if(null!==l){const t=l.getWritable();t.__prev=e.__key,e.__next=t.__key}else e.__next=null;n.__prev=null}if(null===l)if(null!==s){const e=s.getWritable();o.__last=s.__key,e.__next=null}else o.__last=null;else{const e=l.getWritable();if(null!==s){const t=s.getWritable();t.__next=e.__key,e.__prev=t.__key}else e.__prev=null;n.__next=null}o.__size--,n.__parent=null}}function V(t,n){const o=n._nodeMap.get(t);if(!o)return void a().selectStart();const s=o.__prev;let l=null;s&&(l=e(s)),null===l&&null!==o.__parent&&(l=e(o.__parent)),null!==l?null!==l&&l.isAttached()?l.selectEnd():V(l.__key,n):a().selectStart()}class X{constructor(e,t,n){this._key="",this._xmlElem=e,this._parent=t,this._type=n}getPrevNode(e){if(null===e)return null;const t=e.get(this._key);return i(t)?t:null}getNode(){const t=e(this._key);return i(t)?t:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}syncPropertiesFromLexical(e,t,n){const o=this.getPrevNode(n);G(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&T(83);$(e,this._xmlElem,n,t)}destroy(e){e.collabNodeMap.delete(this._key)}}function Z(e,t,n){const o=new X(e,t,n);return e._collabNode=o,o}class ee{constructor(e,t,n){this._key="",this._children=[],this._xmlText=e,this._type=n,this._parent=t}getPrevNode(e){if(null===e)return null;const t=e.get(this._key);return l(t)?t:null}getNode(){const t=e(this._key);return l(t)?t:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){const e=this._parent;return null===e&&T(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&T(91),$(e,this._xmlText,n,t)}applyChildrenYjsDelta(e,t){const n=this._children;let o=0,s=null;for(let l=0;l<t.length;l++){const i=t[l],r=i.insert,c=i.delete;if(null!=i.retain)o+=i.retain;else if("number"==typeof c){let e=c;for(;e>0;){const{node:t,nodeIndex:s,offset:l,length:i}=q(this,o,!1);if(t instanceof ee||t instanceof F||t instanceof X)n.splice(s,1),e-=1;else{if(!(t instanceof E))break;{const o=Math.min(e,i),r=0!==s?n[s-1]:null,c=t.getSize();if(0===l&&i===c){n.splice(s,1);const e=J(t._text,l,o-1,"");e.length>0&&(r instanceof E?r._text+=e:this._xmlText.delete(l,e.length))}else t._text=J(t._text,l,o,"");e-=o}}}}else{if(null==r)throw new Error("Unexpected delta format");if("string"==typeof r){const{node:e,offset:t}=q(this,o,!0);e instanceof E?e._text=J(e._text,t,0,r):this._xmlText.delete(t,r.length),o+=r.length}else{const t=r,{node:l,nodeIndex:i,length:c}=q(this,o,!1),a=I(e,t,this);if(l instanceof E&&c>0&&c<l._text.length){const e=l._text,t=e.length-c;l._text=J(e,t,c,""),n.splice(i+1,0,a),s=J(e,0,t,"")}else n.splice(i,0,a);null!==s&&a instanceof E&&(a._text=s+a._text,s=null),o+=1}}}}syncChildrenFromYjs(e){const t=this.getNode();null===t&&T(92);const o=t.__key,s=S(t,null),l=s.length,i=this._children,r=i.length,c=e.collabNodeMap,a=new Set;let f,d,_=0,h=null;r!==l&&(d=t.getWritable());for(let l=0;l<r;l++){const p=s[_],g=i[l],y=g.getNode(),x=g._key;if(null!==y&&p===x){const t=n(y);if(a.add(p),t)if(g._key=p,g instanceof ee){const t=g._xmlText;g.syncPropertiesFromYjs(e,null),g.applyChildrenYjsDelta(e,t.toDelta()),g.syncChildrenFromYjs(e)}else g instanceof E?g.syncPropertiesAndTextFromYjs(e,null):g instanceof X?g.syncPropertiesFromYjs(e,null):g instanceof F||T(93);h=y,_++}else{if(void 0===f){f=new Set;for(let e=0;e<r;e++){const t=i[e]._key;""!==t&&f.add(t)}}if(null!==y&&void 0!==p&&!f.has(p)){Q(u(p)),l--,_++;continue}d=t.getWritable();const n=K(e,g,o),s=n.__key;if(c.set(s,g),null===h){const e=d.getFirstChild();if(d.__first=s,null!==e){const t=e.getWritable();t.__prev=s,n.__next=t.__key}}else{const e=h.getWritable(),t=h.getNextSibling();if(e.__next=s,n.__prev=h.__key,null!==t){const e=t.getWritable();e.__prev=s,n.__next=e.__key}}l===r-1&&(d.__last=s),d.__size++,h=n}}for(let t=0;t<l;t++){const n=s[t];if(!a.has(n)){const t=u(n),o=e.collabNodeMap.get(n);void 0!==o&&o.destroy(e),Q(t)}}}syncPropertiesFromLexical(e,t,n){G(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(e,t,o,s,r,c){const a=this._children[t],f=u(o);a instanceof ee&&l(f)?(a.syncPropertiesFromLexical(e,f,s),a.syncChildrenFromLexical(e,f,s,r,c)):a instanceof E&&n(f)?a.syncPropertiesAndTextFromLexical(e,f,s):a instanceof X&&i(f)&&a.syncPropertiesFromLexical(e,f,s)}syncChildrenFromLexical(e,t,n,o,s){const l=this.getPrevNode(n),i=null===l?[]:S(l,n),r=S(t,null),c=i.length-1,a=r.length-1,f=e.collabNodeMap;let d,_,h=0,p=0;for(;h<=c&&p<=a;){const t=i[h],l=r[p];if(t===l)this._syncChildFromLexical(e,p,l,n,o,s),h++,p++;else{void 0===d&&(d=new Set(i)),void 0===_&&(_=new Set(r));const n=_.has(t),o=d.has(l);if(n){const t=W(e,u(l),this);f.set(l,t),o?(this.splice(e,p,1,t),h++,p++):(this.splice(e,p,0,t),p++)}else this.splice(e,p,1),h++}}const g=h>c,y=p>a;if(g&&!y)for(;p<=a;++p){const t=r[p],n=W(e,u(t),this);this.append(n),f.set(t,n)}else if(y&&!g)for(let t=this._children.length-1;t>=p;t--)this.splice(e,t,1)}append(e){const t=this._xmlText,n=this._children,o=n[n.length-1],s=void 0!==o?o.getOffset()+o.getSize():0;if(e instanceof ee)t.insertEmbed(s,e._xmlText);else if(e instanceof E){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof F?t.insertEmbed(s,e._map):e instanceof X&&t.insertEmbed(s,e._xmlElem);this._children.push(e)}splice(e,t,n,o){const s=this._children,l=s[t];if(void 0===l)return void 0===o&&T(94),void this.append(o);const i=l.getOffset();-1===i&&T(95);const r=this._xmlText;if(0!==n&&r.delete(i,l.getSize()),o instanceof ee)r.insertEmbed(i,o._xmlText);else if(o instanceof E){const e=o._map;null===e.parent&&r.insertEmbed(i,e),r.insert(i+1,o._text)}else o instanceof F?r.insertEmbed(i,o._map):o instanceof X&&r.insertEmbed(i,o._xmlElem);if(0!==n){const o=s.slice(t,t+n);for(let t=0;t<o.length;t++)o[t].destroy(e)}void 0!==o?s.splice(t,n,o):s.splice(t,n)}getChildOffset(e){let t=0;const n=this._children;for(let o=0;o<n.length;o++){const s=n[o];if(s===e)return t;t+=s.getSize()}return-1}destroy(e){const t=e.collabNodeMap,n=this._children;for(let t=0;t<n.length;t++)n[t].destroy(e);t.delete(this._key)}}function te(e,t,n){const o=new ee(e,t,n);return e._collabNode=o,o}function ne(e,t,n,o,s,l){null==o&&T(81);const i=te(o.get("root",h),null,"root");return i._key="root",{clientID:o.clientID,collabNodeMap:new Map,cursors:new Map,cursorsContainer:null,doc:o,docMap:s,editor:e,excludedProperties:l||new Map,id:n,nodeProperties:new Map,root:i}}function oe(e,t){const o=t.collabNodeMap.get(e.key);if(void 0===o)return null;let s=e.offset,i=o.getSharedType();if(o instanceof E){i=o._parent._xmlText;const e=o.getOffset();if(-1===e)return null;s=e+1+s}else if(o instanceof ee&&"element"===e.type){const t=e.getNode();l(t)||T(184);let o=0,i=0,r=t.getFirstChild();for(;null!==r&&i++<s;)n(r)?o+=r.getTextContentSize()+1:o++,r=r.getNextSibling();s=o}return m(i,s)}function se(e,t){return x(e,t.doc)}function le(e,t){if(null==e){if(null!=t)return!0}else if(null==t||!b(e,t))return!0;return!1}function ie(e,t){return{color:t,name:e,selection:null}}function re(e,t){const n=e.cursorsContainer;if(null!==n){const e=t.selections,o=e.length;for(let t=0;t<o;t++)n.removeChild(e[t])}}function ce(e,t){const n=t.selection;null!==n&&re(e,n)}function ae(e,t,n,o,s){const l=e.color,i=document.createElement("span");i.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${l};z-index:10;`;const r=document.createElement("span");return r.textContent=e.name,r.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${l};color:#fff;line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`,i.appendChild(r),{anchor:{key:t,offset:n},caret:i,color:l,focus:{key:o,offset:s},name:r,selections:[]}}function fe(e,n,o,s){const l=e.editor,i=l.getRootElement(),r=e.cursorsContainer;if(null===r||null===i)return;const c=r.offsetParent;if(null===c)return;const a=c.getBoundingClientRect(),f=n.selection;if(null===o)return null===f?void 0:(n.selection=null,void re(e,f));n.selection=o;const u=o.caret,d=o.color,_=o.selections,h=o.anchor,p=o.focus,g=h.key,y=p.key,x=s.get(g),m=s.get(y);if(null==x||null==m)return;let b;if(x===m&&t(x)){b=[l.getElementByKey(g).getBoundingClientRect()]}else{const e=w(l,x,h.offset,m,p.offset);if(null===e)return;b=P(l,e)}const k=_.length,v=b.length;for(let e=0;e<v;e++){const t=b[e];let n=_[e];if(void 0===n){n=document.createElement("span"),_[e]=n;const t=document.createElement("span");n.appendChild(t),r.appendChild(n)}const o=`position:absolute;top:${t.top-a.top}px;left:${t.left-a.left}px;height:${t.height}px;width:${t.width}px;pointer-events:none;z-index:5;`;n.style.cssText=o,n.firstChild.style.cssText=`${o}left:0;top:0;background-color:${d};opacity:0.3;`,e===v-1&&u.parentNode!==n&&n.appendChild(u)}for(let e=k-1;e>=v;e--){const t=_[e];r.removeChild(t),_.pop()}}function ue(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,l=0,i=null,r=0;if(null!==n&&null!==o){const t=se(n,e),c=se(o,e);null!==t&&null!==c&&([s,l]=he(t.type,t.index),[i,r]=he(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:l,focusCollabNode:i,focusOffset:r}}function de(e,t){const n=t.awareness.getLocalState();if(null===n)return;const{anchorCollabNode:l,anchorOffset:i,focusCollabNode:r,focusOffset:c}=ue(e,n);if(null!==l&&null!==r){const e=l.getKey(),t=r.getKey(),n=o();if(!s(n))return;_e(n.anchor,e,i),_e(n.focus,t,c)}}function _e(t,o,s){if(t.key!==o||t.offset!==s){let i=e(o);if(null!==i&&!l(i)&&!n(i)){const e=i.getParentOrThrow();o=e.getKey(),s=i.getIndexWithinParent(),i=e}t.set(o,s,l(i)?"element":"text")}}function he(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof ee){const{node:e,offset:o}=q(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function pe(e,t){const n=Array.from(t.awareness.getStates()),o=e.clientID,s=e.cursors,l=e.editor._editorState._nodeMap,i=new Set;for(let t=0;t<n.length;t++){const r=n[t],[c,a]=r;if(c!==o){i.add(c);const{name:t,color:n,focusing:o}=a;let r=null,f=s.get(c);if(void 0===f&&(f=ie(t,n),s.set(c,f)),o){const{anchorCollabNode:t,anchorOffset:n,focusCollabNode:o,focusOffset:s}=ue(e,a);if(null!==t&&null!==o){const e=t.getKey(),l=o.getKey();if(r=f.selection,null===r)r=ae(f,e,n,l,s);else{const t=r.anchor,o=r.focus;t.key=e,t.offset=n,o.key=l,o.offset=s}}}fe(e,f,r,l)}}const r=Array.from(s.keys());for(let t=0;t<r.length;t++){const n=r[t];if(!i.has(n)){const t=s.get(n);void 0!==t&&(ce(e,t),s.delete(n))}}}function ge(e,t,n,o){const l=t.awareness,i=l.getLocalState();if(null===i)return;const{anchorPos:r,focusPos:c,name:a,color:f,focusing:u,awarenessData:d}=i;let _=null,h=null;(null!==o&&(null===r||o.is(n))||null!==n)&&(s(o)&&(_=oe(o.anchor,e),h=oe(o.focus,e)),(le(r,_)||le(c,h))&&l.setLocalState({...i,anchorPos:_,awarenessData:d,color:f,focusPos:h,focusing:u,name:a}))}function ye(e,t){if(t instanceof k&&function(e,t){const{target:n}=t;if(!n._item||"__state"!==n._item.parentSub||void 0!==D(n)||!(n.parent instanceof h||n.parent instanceof g||n.parent instanceof p))return!1;const o=I(e,n.parent).getNode();if(o){const e=c(o.getWritable());for(const o of t.keysChanged)e.updateFromUnknown(o,n.get(o))}return!0}(e,t))return;const{target:n}=t,o=I(e,n);if(o instanceof ee&&t instanceof v){const{keysChanged:n,childListChanged:s,delta:l}=t;n.size>0&&o.syncPropertiesFromYjs(e,n),s&&(o.applyChildrenYjsDelta(e,l),o.syncChildrenFromYjs(e))}else if(o instanceof E&&t instanceof k){const{keysChanged:n}=t;n.size>0&&o.syncPropertiesAndTextFromYjs(e,n)}else if(o instanceof X&&t instanceof C){const{attributesChanged:n}=t;n.size>0&&o.syncPropertiesFromYjs(e,n)}else T(82)}function xe(e,t,n,l,i=pe){const r=e.editor,c=r._editorState;n.forEach((e=>e.delta)),r.update((()=>{for(let t=0;t<n.length;t++){const o=n[t];ye(e,o)}const l=o();if(s(l))if(H(l)){const n=c._selection;if(s(n)&&(de(e,t),H(l))){V(l.anchor.key,c)}ge(e,t,n,o())}else de(e,t)}),{onUpdate:()=>{i(e,t),r.update((()=>{0===a().getChildrenSize()&&a().append(d())}))},skipTransforms:!0,tag:l?"historic":"collaboration"})}function me(t,s,l,i,r,c,f,u){!function(e,t){e.doc.transact(t,e)}(t,(()=>{i.read((()=>{if(u.has("collaboration")||u.has("historic"))return void(f.size>0&&function(t,o){const s=Array.from(o),l=t.collabNodeMap,i=[],r=[];for(let t=0;t<s.length;t++){const o=s[t],c=e(o),a=l.get(o);if(a instanceof E)if(n(c))i.push([a,c.__text]);else{const e=a.getOffset();if(-1===e)continue;const t=a._parent;a._normalized=!0,t._xmlText.delete(e,1),r.push(a)}}for(let e=0;e<r.length;e++){const t=r[e],n=t.getKey();l.delete(n);const o=t._parent._children,s=o.indexOf(t);o.splice(s,1)}for(let e=0;e<i.length;e++){const[t,n]=i[e];t._text=n}}(t,f));if(r.has("root")){const e=l._nodeMap,n=a(),o=t.root;o.syncPropertiesFromLexical(t,n,e),o.syncChildrenFromLexical(t,n,e,r,c)}const i=o(),d=l._selection;ge(t,s,d,i)}))}))}const be=_("CONNECTED_COMMAND"),ke=_("TOGGLE_CONNECT_COMMAND");function ve(e,t){return new N(t,{trackedOrigins:new Set([e,null])})}function Ce(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})}function Ne(e,t,n,o,s){const{awareness:l}=e;let i=l.getLocalState();null===i&&(i={anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t}),i.focusing=o,l.setLocalState(i)}export{be as CONNECTED_COMMAND,ke as TOGGLE_CONNECT_COMMAND,ne as createBinding,ve as createUndoManager,ue as getAnchorAndFocusCollabNodesForUserState,Ce as initLocalState,Ne as setLocalStateFocus,pe as syncCursorPositions,me as syncLexicalUpdateToYjs,xe as syncYjsChangesToLexical};
package/package.json CHANGED
@@ -11,13 +11,13 @@
11
11
  "crdt"
12
12
  ],
13
13
  "license": "MIT",
14
- "version": "0.26.0",
14
+ "version": "0.26.1-nightly.20250303.0",
15
15
  "main": "LexicalYjs.js",
16
16
  "types": "index.d.ts",
17
17
  "dependencies": {
18
- "@lexical/offset": "0.26.0",
19
- "@lexical/selection": "0.26.0",
20
- "lexical": "0.26.0"
18
+ "@lexical/offset": "0.26.1-nightly.20250303.0",
19
+ "@lexical/selection": "0.26.1-nightly.20250303.0",
20
+ "lexical": "0.26.1-nightly.20250303.0"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "yjs": ">=13.5.22"