@lexical/yjs 0.1.21 → 0.2.2

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
@@ -232,7 +232,7 @@ function $createCollabTextNode(map, text, parent, type) {
232
232
  *
233
233
  *
234
234
  */
235
- const excludedProperties = new Set(['__key', '__children', '__parent', '__cachedText', '__text', '__state']);
235
+ const excludedProperties = new Set(['__key', '__children', '__parent', '__cachedText', '__text']);
236
236
  function $getNodeByKeyOrThrow(key) {
237
237
  const node = lexical.$getNodeByKey(key);
238
238
 
@@ -362,9 +362,23 @@ function syncPropertiesFromYjs(binding, sharedType, lexicalNode, keysChanged) {
362
362
 
363
363
 
364
364
  const prevValue = lexicalNode[property];
365
- const nextValue = sharedType instanceof yjs.Map ? sharedType.get(property) : sharedType.getAttribute(property);
365
+ let nextValue = sharedType instanceof yjs.Map ? sharedType.get(property) : sharedType.getAttribute(property);
366
366
 
367
367
  if (prevValue !== nextValue) {
368
+ if (nextValue instanceof yjs.Doc) {
369
+ const yjsDocMap = binding.docMap;
370
+
371
+ if (prevValue instanceof yjs.Doc) {
372
+ yjsDocMap.delete(prevValue.guid);
373
+ }
374
+
375
+ const nestedEditor = lexical.createEditor();
376
+ const key = nextValue.guid;
377
+ nestedEditor._key = key;
378
+ yjsDocMap.set(key, nextValue);
379
+ nextValue = nestedEditor;
380
+ }
381
+
368
382
  if (writableNode === undefined) {
369
383
  writableNode = lexicalNode.getWritable();
370
384
  } // $FlowFixMe
@@ -386,14 +400,39 @@ function syncPropertiesFromLexical(binding, sharedType, prevLexicalNode, nextLex
386
400
  nodeProperties.set(type, properties);
387
401
  }
388
402
 
403
+ const EditorClass = binding.editor.constructor;
404
+
389
405
  for (let i = 0; i < properties.length; i++) {
390
406
  const property = properties[i];
391
407
  const prevValue = // $FlowFixMe: intentional override
392
408
  prevLexicalNode === null ? undefined : prevLexicalNode[property]; // $FlowFixMe: intentional override
393
409
 
394
- const nextValue = nextLexicalNode[property];
410
+ let nextValue = nextLexicalNode[property];
395
411
 
396
412
  if (prevValue !== nextValue) {
413
+ if (nextValue instanceof EditorClass) {
414
+ const yjsDocMap = binding.docMap;
415
+ let prevDoc;
416
+
417
+ if (prevValue instanceof EditorClass) {
418
+ const prevKey = prevValue._key;
419
+ prevDoc = yjsDocMap.get(prevKey);
420
+ yjsDocMap.delete(prevKey);
421
+ } // If we already have a document, use it.
422
+
423
+
424
+ const doc = prevDoc || new yjs.Doc(); // $FlowFixMe: guid exists
425
+
426
+ const key = doc.guid;
427
+ nextValue._key = key;
428
+ yjsDocMap.set(key, doc);
429
+ nextValue = doc; // Mark the node dirty as we've assigned a new key to it
430
+
431
+ binding.editor.update(() => {
432
+ nextLexicalNode.markDirty();
433
+ });
434
+ }
435
+
397
436
  if (sharedType instanceof yjs.Map) {
398
437
  sharedType.set(property, nextValue);
399
438
  } else {
@@ -484,320 +523,6 @@ function syncWithTransaction(binding, fn) {
484
523
  binding.doc.transact(fn, binding);
485
524
  }
486
525
 
487
- /**
488
- * Copyright (c) Meta Platforms, Inc. and affiliates.
489
- *
490
- * This source code is licensed under the MIT license found in the
491
- * LICENSE file in the root directory of this source tree.
492
- *
493
- *
494
- */
495
- let isMutationFromCollab = false;
496
- function mutationFromCollab(fn) {
497
- const prevIsMutationFromCollab = isMutationFromCollab;
498
-
499
- try {
500
- isMutationFromCollab = true;
501
- fn();
502
- } finally {
503
- isMutationFromCollab = prevIsMutationFromCollab;
504
- }
505
- }
506
- function observeDecoratorMap(binding, collabNode, decoratorMap, yjsMap) {
507
- const unobserve = decoratorMap.observe(changedKey => {
508
- if (isMutationFromCollab) {
509
- return;
510
- }
511
-
512
- syncWithTransaction(binding, () => syncLexicalDecoratorMapKeyToYjs(binding, collabNode, decoratorMap._map, yjsMap, changedKey));
513
- });
514
-
515
- collabNode._unobservers.add(unobserve);
516
- }
517
-
518
- function observeDecoratorArray(binding, collabNode, decoratorArray, yjsArray) {
519
- const unobserve = decoratorArray.observe((changedIndex, delCount) => {
520
- if (isMutationFromCollab) {
521
- return;
522
- }
523
-
524
- syncWithTransaction(binding, () => {
525
- if (delCount > 0) {
526
- yjsArray.delete(changedIndex, delCount);
527
- }
528
-
529
- syncLexicalDecoratorArrayValueToYjs(binding, collabNode, decoratorArray._array, yjsArray, changedIndex);
530
- });
531
- });
532
-
533
- collabNode._unobservers.add(unobserve);
534
- }
535
-
536
- function syncLexicalDecoratorMapKeyToYjs(binding, collabNode, internalMap, yjsMap, key) {
537
- const lexicalValue = internalMap.get(key);
538
- let yjsValue = yjsMap.get(key);
539
-
540
- if (lexicalValue !== yjsValue) {
541
- if (lexical.isDecoratorMap(lexicalValue)) {
542
- if (yjsValue === undefined) {
543
- yjsValue = new yjs.Map(); // $FlowFixMe: internal field
544
-
545
- yjsValue._lexicalValue = lexicalValue; // $FlowFixMe: internal field
546
-
547
- yjsValue._collabNode = collabNode;
548
- yjsValue.set('type', 'map');
549
- yjsMap.set(key, yjsValue);
550
- observeDecoratorMap(binding, collabNode, lexicalValue, yjsValue);
551
- }
552
-
553
- syncLexicalDecoratorMapToYjs(binding, collabNode, lexicalValue, yjsValue);
554
- } else if (lexical.isDecoratorEditor(lexicalValue)) {
555
- let doc;
556
-
557
- if (yjsValue === undefined) {
558
- yjsValue = new yjs.Map(); // $FlowFixMe: internal field
559
-
560
- yjsValue._lexicalValue = lexicalValue; // $FlowFixMe: internal field
561
-
562
- yjsValue._collabNode = collabNode; // Create a subdocument
563
-
564
- doc = new yjs.Doc();
565
- yjsValue.set('doc', doc);
566
- yjsValue.set('type', 'editor');
567
- yjsMap.set(key, yjsValue);
568
- }
569
-
570
- doc = doc || yjsValue.get('doc');
571
- const yjsId = yjsValue.get('id');
572
- const lexicalId = lexicalValue.id;
573
-
574
- if (yjsId !== lexicalId) {
575
- const yjsDocMap = binding.docMap;
576
- yjsDocMap.delete(yjsId);
577
- yjsValue.set('id', lexicalId);
578
- yjsDocMap.set(lexicalId, doc);
579
- }
580
- } else if (lexical.isDecoratorArray(lexicalValue)) {
581
- if (yjsValue === undefined) {
582
- yjsValue = new yjs.Array(); // $FlowFixMe: internal field
583
-
584
- yjsValue._lexicalValue = lexicalValue; // $FlowFixMe: internal field
585
-
586
- yjsValue._collabNode = collabNode;
587
- yjsMap.set(key, yjsValue);
588
- observeDecoratorArray(binding, collabNode, lexicalValue, yjsValue);
589
- }
590
-
591
- syncLexicalDecoratorArrayToYjs(binding, collabNode, lexicalValue, yjsValue);
592
- } else {
593
- if (lexical.isDecoratorArray(yjsValue) || lexical.isDecoratorMap(yjsValue)) {
594
- yjsValue.destroy();
595
- }
596
-
597
- yjsMap.set(key, lexicalValue);
598
- }
599
- }
600
- }
601
-
602
- function syncLexicalDecoratorArrayValueToYjs(binding, collabNode, internalArray, yjsArray, index) {
603
- const lexicalValue = internalArray[index];
604
- let yjsValue = yjsArray.get(index);
605
-
606
- if (lexicalValue !== yjsValue) {
607
- if (lexical.isDecoratorMap(lexicalValue)) {
608
- if (yjsValue === undefined) {
609
- yjsValue = new yjs.Map(); // $FlowFixMe: internal field
610
-
611
- yjsValue._lexicalValue = lexicalValue; // $FlowFixMe: internal field
612
-
613
- yjsValue._collabNode = collabNode;
614
- yjsValue.set('type', 'map');
615
- yjsArray.insert(index, [yjsValue]);
616
- observeDecoratorMap(binding, collabNode, lexicalValue, yjsValue);
617
- }
618
-
619
- syncLexicalDecoratorMapToYjs(binding, collabNode, lexicalValue, yjsValue);
620
- } else if (lexical.isDecoratorEditor(lexicalValue)) {
621
- let doc;
622
-
623
- if (yjsValue === undefined) {
624
- yjsValue = new yjs.Map(); // $FlowFixMe: internal field
625
-
626
- yjsValue._lexicalValue = lexicalValue; // $FlowFixMe: internal field
627
-
628
- yjsValue._collabNode = collabNode; // Create a subdocument
629
-
630
- doc = new yjs.Doc();
631
- yjsValue.set('doc', doc);
632
- yjsValue.set('type', 'editor');
633
- yjsArray.insert(index, [yjsValue]);
634
- }
635
-
636
- doc = doc || yjsValue.get('doc');
637
- const yjsId = yjsValue.get('id');
638
- const lexicalId = lexicalValue.id;
639
-
640
- if (yjsId !== lexicalId) {
641
- const yjsDocMap = binding.docMap;
642
- yjsDocMap.delete(yjsId);
643
- yjsValue.set('id', lexicalId);
644
- yjsDocMap.set(lexicalId, doc);
645
- }
646
- } else if (lexical.isDecoratorArray(lexicalValue)) {
647
- if (yjsValue === undefined) {
648
- yjsValue = new yjs.Array(); // $FlowFixMe: internal field
649
-
650
- yjsValue._lexicalValue = lexicalValue; // $FlowFixMe: internal field
651
-
652
- yjsValue._collabNode = collabNode;
653
- yjsArray.insert(index, [yjsValue]);
654
- observeDecoratorArray(binding, collabNode, lexicalValue, yjsValue);
655
- }
656
-
657
- syncLexicalDecoratorArrayToYjs(binding, collabNode, lexicalValue, yjsValue);
658
- } else {
659
- yjsArray.insert(index, [lexicalValue]);
660
- }
661
- }
662
- }
663
-
664
- function syncLexicalDecoratorMapToYjs(binding, collabNode, decoratorMap, yjsMap) {
665
- const internalMap = decoratorMap._map;
666
-
667
- for (const [key] of internalMap) {
668
- syncLexicalDecoratorMapKeyToYjs(binding, collabNode, internalMap, yjsMap, key);
669
- }
670
- }
671
-
672
- function syncLexicalDecoratorArrayToYjs(binding, collabNode, decoratorArray, yjsArray) {
673
- const internalArray = decoratorArray._array;
674
-
675
- for (let i = 0; i < internalArray.length; i++) {
676
- syncLexicalDecoratorArrayValueToYjs(binding, collabNode, internalArray, yjsArray, i);
677
- }
678
- }
679
-
680
- function syncYjsDecoratorMapKeyToLexical(binding, collabNode, yjsMap, decoratorMap, key) {
681
- const lexicalValue = decoratorMap.get(key);
682
- const yjsValue = yjsMap.get(key);
683
-
684
- if (lexicalValue !== yjsValue) {
685
- // $FlowFixMe: internal field
686
- let nextValue = yjsValue._lexicalValue;
687
-
688
- if (yjsValue instanceof yjs.Map) {
689
- const type = yjsValue.get('type');
690
-
691
- if (type === 'editor') {
692
- if (nextValue === undefined) {
693
- const yjsDocMap = binding.docMap;
694
- const id = yjsValue.get('id');
695
- const doc = yjsValue.get('doc');
696
- nextValue = lexical.createDecoratorEditor(id);
697
- yjsValue._lexicalValue = nextValue;
698
- yjsValue._collabNode = collabNode;
699
- yjsDocMap.set(id, doc);
700
- mutationFromCollab(() => decoratorMap.set(key, nextValue));
701
- }
702
- } else if (type === 'map') {
703
- if (nextValue === undefined) {
704
- nextValue = lexical.createDecoratorMap(binding.editor);
705
- observeDecoratorMap(binding, collabNode, nextValue, yjsValue);
706
- yjsValue._lexicalValue = nextValue;
707
- yjsValue._collabNode = collabNode;
708
- mutationFromCollab(() => decoratorMap.set(key, nextValue));
709
- }
710
-
711
- syncYjsDecoratorMapToLexical(binding, collabNode, yjsValue, nextValue, null);
712
- } else {
713
- {
714
- throw Error(`Should never happen`);
715
- }
716
- }
717
- } else if (yjsValue instanceof yjs.Array) {
718
- if (nextValue === undefined) {
719
- nextValue = lexical.createDecoratorArray(binding.editor);
720
- observeDecoratorArray(binding, collabNode, nextValue, yjsValue);
721
- yjsValue._lexicalValue = nextValue;
722
- yjsValue._collabNode = collabNode;
723
- mutationFromCollab(() => decoratorMap.set(key, nextValue));
724
- }
725
-
726
- syncYjsDecoratorArrayToLexical(binding, collabNode, yjsValue, nextValue);
727
- } else {
728
- mutationFromCollab(() => decoratorMap.set(key, yjsValue));
729
- }
730
- }
731
- }
732
-
733
- function syncYjsDecoratorArrayValueToLexical(binding, collabNode, yjsArray, decoratorArray, index) {
734
- const lexicalValue = decoratorArray._array[index];
735
- const yjsValue = yjsArray.get(index);
736
-
737
- if (lexicalValue !== yjsValue) {
738
- // $FlowFixMe: internal field
739
- let nextValue = yjsValue._lexicalValue;
740
-
741
- if (yjsValue instanceof yjs.Map) {
742
- const type = yjsValue.get('type');
743
-
744
- if (type === 'editor') {
745
- if (nextValue === undefined) {
746
- const yjsDocMap = binding.docMap;
747
- const id = yjsValue.get('id');
748
- const doc = yjsValue.get('doc');
749
- nextValue = lexical.createDecoratorEditor(id);
750
- yjsValue._lexicalValue = nextValue;
751
- yjsValue._collabNode = collabNode;
752
- yjsDocMap.set(id, doc);
753
- mutationFromCollab(() => decoratorArray.splice(index, 0, nextValue));
754
- }
755
- } else if (type === 'map') {
756
- if (nextValue === undefined) {
757
- nextValue = lexical.createDecoratorMap(binding.editor);
758
- observeDecoratorMap(binding, collabNode, nextValue, yjsValue);
759
- yjsValue._lexicalValue = nextValue;
760
- yjsValue._collabNode = collabNode;
761
- mutationFromCollab(() => decoratorArray.splice(index, 0, nextValue));
762
- }
763
-
764
- syncYjsDecoratorMapToLexical(binding, collabNode, yjsValue, nextValue, null);
765
- } else {
766
- {
767
- throw Error(`Should never happen`);
768
- }
769
- }
770
- } else if (yjsValue instanceof yjs.Array) {
771
- if (nextValue === undefined) {
772
- nextValue = lexical.createDecoratorArray(binding.editor);
773
- observeDecoratorArray(binding, collabNode, nextValue, yjsValue);
774
- yjsValue._lexicalValue = nextValue;
775
- yjsValue._collabNode = collabNode;
776
- mutationFromCollab(() => decoratorArray.splice(index, 0, nextValue));
777
- }
778
-
779
- syncYjsDecoratorArrayToLexical(binding, collabNode, yjsValue, nextValue);
780
- } else {
781
- mutationFromCollab(() => decoratorArray.splice(index, 0, yjsValue));
782
- }
783
- }
784
- }
785
- function syncYjsDecoratorArrayToLexical(binding, collabNode, yjsArray, decoratorArray) {
786
- const length = Math.max(yjsArray.length, decoratorArray.getLength());
787
-
788
- for (let i = 0; i < length; i++) {
789
- syncYjsDecoratorArrayValueToLexical(binding, collabNode, yjsArray, decoratorArray, i);
790
- }
791
- }
792
- function syncYjsDecoratorMapToLexical(binding, collabNode, yjsMap, decoratorMap, keysChanged) {
793
- const keys = keysChanged === null ? Array.from(yjsMap.keys()) : Array.from(keysChanged);
794
-
795
- for (let i = 0; i < keys.length; i++) {
796
- const key = keys[i];
797
- syncYjsDecoratorMapKeyToLexical(binding, collabNode, yjsMap, decoratorMap, key);
798
- }
799
- }
800
-
801
526
  /**
802
527
  * Copyright (c) Meta Platforms, Inc. and affiliates.
803
528
  *
@@ -853,20 +578,7 @@ class CollabDecoratorNode {
853
578
  syncPropertiesFromLexical(binding, nextLexicalNode, prevNodeMap) {
854
579
  const prevLexicalNode = this.getPrevNode(prevNodeMap);
855
580
  const xmlElem = this._xmlElem;
856
- const prevDecoratorMap = prevLexicalNode === null ? null : prevLexicalNode.__state;
857
- const nextDecoratorMap = nextLexicalNode.__state;
858
- syncPropertiesFromLexical(binding, xmlElem, prevLexicalNode, nextLexicalNode); // Handle bindings
859
-
860
- if (prevDecoratorMap !== nextDecoratorMap) {
861
- const yjsMap = new yjs.Map();
862
- xmlElem.insert(0, [yjsMap]); // $FlowFixMe: internal field
863
-
864
- yjsMap._lexicalValue = nextDecoratorMap; // $FlowFixMe: internal field
865
-
866
- yjsMap._collabNode = this;
867
- syncLexicalDecoratorMapToYjs(binding, this, nextDecoratorMap, yjsMap);
868
- observeDecoratorMap(binding, this, nextDecoratorMap, yjsMap);
869
- }
581
+ syncPropertiesFromLexical(binding, xmlElem, prevLexicalNode, nextLexicalNode);
870
582
  }
871
583
 
872
584
  syncPropertiesFromYjs(binding, keysChanged) {
@@ -876,17 +588,8 @@ class CollabDecoratorNode {
876
588
  throw new Error('Should never happen');
877
589
  }
878
590
 
879
- const xmlElem = this._xmlElem; // $FlowFixMe: should always be true
880
-
881
- const yjsMap = xmlElem.firstChild;
882
- const decoratorMap = lexicalNode.__state; // $FlowFixMe: internal field
883
-
884
- yjsMap._lexicalValue = decoratorMap; // $FlowFixMe: internal field
885
-
886
- yjsMap._collabNode = this;
591
+ const xmlElem = this._xmlElem;
887
592
  syncPropertiesFromYjs(binding, xmlElem, lexicalNode, keysChanged);
888
- syncYjsDecoratorMapToLexical(binding, this, yjsMap, decoratorMap, null);
889
- observeDecoratorMap(binding, this, decoratorMap, yjsMap);
890
593
  }
891
594
 
892
595
  destroy(binding) {
@@ -1867,48 +1570,7 @@ function syncEvent(binding, event) {
1867
1570
  const {
1868
1571
  target
1869
1572
  } = event;
1870
- const collabNode = getOrInitCollabNodeFromSharedType(binding, target); // $FlowFixMe: internal field
1871
-
1872
- const decoratorStateValue = target._lexicalValue; // Check if this event relates to a decorator state change.
1873
-
1874
- if (decoratorStateValue !== undefined && collabNode instanceof CollabDecoratorNode) {
1875
- if (target instanceof yjs.Map) {
1876
- // Sync decorator state value
1877
- syncYjsDecoratorMapToLexical(binding, collabNode, target, decoratorStateValue, event.keysChanged);
1878
- } else if (target instanceof yjs.Array && lexical.isDecoratorArray(decoratorStateValue)) {
1879
- // Sync decorator state value
1880
- const deltas = event.delta;
1881
- let offset = 0;
1882
-
1883
- for (let i = 0; i < deltas.length; i++) {
1884
- const delta = deltas[i];
1885
- const retainOp = delta.retain;
1886
- const deleteOp = delta.delete;
1887
- const insertOp = delta.insert;
1888
-
1889
- if (retainOp !== undefined) {
1890
- offset += retainOp;
1891
- } else if (deleteOp !== undefined) {
1892
- mutationFromCollab(() => {
1893
- const elements = decoratorStateValue._array.slice(offset, offset + deleteOp);
1894
-
1895
- elements.forEach(element => {
1896
- if (lexical.isDecoratorArray(element) || lexical.isDecoratorMap(element)) {
1897
- element.destroy();
1898
- }
1899
- });
1900
- decoratorStateValue.splice(offset, deleteOp);
1901
- });
1902
- } else if (insertOp !== undefined) {
1903
- syncYjsDecoratorArrayValueToLexical(binding, collabNode, target, decoratorStateValue, offset);
1904
- } else {
1905
- throw new Error('Not supported');
1906
- }
1907
- }
1908
- }
1909
-
1910
- return;
1911
- }
1573
+ const collabNode = getOrInitCollabNodeFromSharedType(binding, target);
1912
1574
 
1913
1575
  if (collabNode instanceof CollabElementNode && event instanceof yjs.YTextEvent) {
1914
1576
  const {
@@ -4,57 +4,45 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- var k=require("lexical"),r=require("yjs"),z=require("@lexical/offset");function B(a){throw Error(`Minified Lexical error #${a}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
- class C{constructor(a,b){this._key="";this._map=a;this._parent=b;this._type="linebreak"}getNode(){const a=k.$getNodeByKey(this._key);return k.$isLineBreakNode(a)?a:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(a){a.collabNodeMap.delete(this._key)}}function D(a,b){b=new C(a,b);return a._collabNode=b}
9
- class E{constructor(a,b,c,d){this._key="";this._map=a;this._parent=c;this._text=b;this._type=d;this._normalized=!1}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return k.$isTextNode(a)?a:null}getNode(){const a=k.$getNodeByKey(this._key);return k.$isTextNode(a)?a:null}getSharedType(){return this._map}getType(){return this._type}getKey(){return this._key}getSize(){return this._text.length+(this._normalized?0:1)}getOffset(){return this._parent.getChildOffset(this)}spliceText(a,b,c){const d=
10
- this._parent._xmlText;a=this.getOffset()+1+a;0!==b&&d.delete(a,b);""!==c&&d.insert(a,c)}syncPropertiesAndTextFromLexical(a,b,c){var d=this.getPrevNode(c);c=b.__text;F(a,this._map,d,b);if(null!==d&&(a=d.__text,a!==c)){d=b.__key;b=a;var e=k.$getSelection();a=c.length;k.$isRangeSelection(e)&&e.isCollapsed()&&(e=e.anchor,e.key===d&&(a=e.offset));d=b.length;const f=c.length;let g=e=0;for(;e<d&&e<f&&b[e]===c[e]&&e<a;)e++;for(;g+e<d&&g+e<f&&b[d-g-1]===c[f-g-1];)g++;for(;g+e<d&&g+e<f&&b[e]===c[e];)e++;b=
11
- e;a=c.slice(e,f-g);d=d-e-g;this.spliceText(b,d,a);this._text=c}}syncPropertiesAndTextFromYjs(a,b){const c=this.getNode();if(null===c)throw Error("Should never happen");G(a,this._map,c,b);a=this._text;c.__text!==a&&(c.getWritable().__text=a)}destroy(a){a.collabNodeMap.delete(this._key)}}function I(a,b,c,d){b=new E(a,b,c,d);return a._collabNode=b}const J=new Set("__key __children __parent __cachedText __text __state".split(" "));
12
- function K(a){a=k.$getNodeByKey(a);if(null===a)throw Error("Should never happen");return a}
13
- function aa(a,b,c){const d=b.__type;if(k.$isElementNode(b)){var e=new r.XmlText;c=L(e,c,d);c.syncPropertiesFromLexical(a,b,null);c.syncChildrenFromLexical(a,b,null,null,null)}else if(k.$isTextNode(b))e=new r.Map,c=I(e,b.__text,c,d),c.syncPropertiesAndTextFromLexical(a,b,null);else if(k.$isLineBreakNode(b))a=new r.Map,a.set("__type","linebreak"),c=D(a,c);else if(k.$isDecoratorNode(b))e=new r.XmlElement,c=ba(e,c,d),c.syncPropertiesFromLexical(a,b,null);else throw Error("Should never happen");c._key=
14
- b.__key;return c}
15
- function M(a,b,c){const d=b._collabNode;if(void 0===d){var e=a.editor._nodes;const f=b instanceof r.Map?b.get("__type"):b.getAttribute("__type");if(null==f)throw Error("Should never happen");if(void 0===e.get(f))throw Error("Should never happen");e=b.parent;a=void 0===c&&null!==e?M(a,e):c||null;if(!(a instanceof O))throw Error("Should never happen");if(b instanceof r.XmlText)return L(b,a,f);if(b instanceof r.Map){if(null===a)throw Error("Should never happen");return"linebreak"===f?D(b,a):I(b,"",a,
16
- f)}if(b instanceof r.XmlElement)return ba(b,a,f)}return d}function G(a,b,c,d){a=null===d?b instanceof r.Map?Array.from(b.keys()):Object.keys(b.getAttributes()):Array.from(d);let e;for(d=0;d<a.length;d++){const f=a[d];if(J.has(f))continue;const g=c[f],h=b instanceof r.Map?b.get(f):b.getAttribute(f);g!==h&&(void 0===e&&(e=c.getWritable()),e[f]=h)}}
17
- function F(a,b,c,d){var e=d.__type,f=a.nodeProperties;a=f.get(e);void 0===a&&(a=Object.keys(d).filter(g=>!J.has(g)),f.set(e,a));for(e=0;e<a.length;e++){f=a[e];const g=d[f];(null===c?void 0:c[f])!==g&&(b instanceof r.Map?b.set(f,g):b.setAttribute(f,g))}}
18
- function P(a,b,c){let d=0,e=0;const f=a._children,g=f.length;for(;e<g;e++){a=f[e];const h=d,p=a.getSize();d+=p;if((c?d>=b:d>b)&&a instanceof E)return b=b-h-1,0>b&&(b=0),{length:p-b,node:a,nodeIndex:e,offset:b};if(d>b)return{length:0,node:a,nodeIndex:e,offset:h};if(e===g-1)return{length:0,node:null,nodeIndex:e+1,offset:h+1}}return{length:0,node:null,nodeIndex:0,offset:0}}
19
- function ca(a){const b=a.anchor;a=a.focus;let c=!1;try{const d=b.getNode(),e=a.getNode();if(!d.isAttached()||!e.isAttached()||k.$isTextNode(d)&&b.offset>d.getTextContentSize()||k.$isTextNode(e)&&a.offset>e.getTextContentSize())c=!0}catch(d){c=!0}return c}function Q(a,b){a.doc.transact(b,a)}let R=!1;function S(a){const b=R;try{R=!0,a()}finally{R=b}}function T(a,b,c,d){const e=c.observe(f=>{R||Q(a,()=>da(a,b,c._map,d,f))});b._unobservers.add(e)}
20
- function V(a,b,c,d){const e=c.observe((f,g)=>{R||Q(a,()=>{0<g&&d.delete(f,g);ea(a,b,c._array,d,f)})});b._unobservers.add(e)}
21
- function da(a,b,c,d,e){const f=c.get(e);c=d.get(e);if(f!==c)if(k.isDecoratorMap(f))void 0===c&&(c=new r.Map,c._lexicalValue=f,c._collabNode=b,c.set("type","map"),d.set(e,c),T(a,b,f,c)),W(a,b,f,c);else if(k.isDecoratorEditor(f)){let g;void 0===c&&(c=new r.Map,c._lexicalValue=f,c._collabNode=b,g=new r.Doc,c.set("doc",g),c.set("type","editor"),d.set(e,c));g=g||c.get("doc");b=c.get("id");d=f.id;b!==d&&(a=a.docMap,a.delete(b),c.set("id",d),a.set(d,g))}else k.isDecoratorArray(f)?(void 0===c&&(c=new r.Array,
22
- c._lexicalValue=f,c._collabNode=b,d.set(e,c),V(a,b,f,c)),fa(a,b,f,c)):((k.isDecoratorArray(c)||k.isDecoratorMap(c))&&c.destroy(),d.set(e,f))}
23
- function ea(a,b,c,d,e){const f=c[e];c=d.get(e);if(f!==c)if(k.isDecoratorMap(f))void 0===c&&(c=new r.Map,c._lexicalValue=f,c._collabNode=b,c.set("type","map"),d.insert(e,[c]),T(a,b,f,c)),W(a,b,f,c);else if(k.isDecoratorEditor(f)){let g;void 0===c&&(c=new r.Map,c._lexicalValue=f,c._collabNode=b,g=new r.Doc,c.set("doc",g),c.set("type","editor"),d.insert(e,[c]));g=g||c.get("doc");b=c.get("id");d=f.id;b!==d&&(a=a.docMap,a.delete(b),c.set("id",d),a.set(d,g))}else k.isDecoratorArray(f)?(void 0===c&&(c=new r.Array,
24
- c._lexicalValue=f,c._collabNode=b,d.insert(e,[c]),V(a,b,f,c)),fa(a,b,f,c)):d.insert(e,[f])}function W(a,b,c,d){c=c._map;for(const [e]of c)da(a,b,c,d,e)}function fa(a,b,c,d){c=c._array;for(let e=0;e<c.length;e++)ea(a,b,c,d,e)}
25
- function ha(a,b,c,d,e){var f=d.get(e);const g=c.get(e);if(f!==g){let h=g._lexicalValue;g instanceof r.Map?(c=g.get("type"),"editor"===c?void 0===h&&(a=a.docMap,c=g.get("id"),f=g.get("doc"),h=k.createDecoratorEditor(c),g._lexicalValue=h,g._collabNode=b,a.set(c,f),S(()=>d.set(e,h))):"map"===c?(void 0===h&&(h=k.createDecoratorMap(a.editor),T(a,b,h,g),g._lexicalValue=h,g._collabNode=b,S(()=>d.set(e,h))),X(a,b,g,h,null)):B(48)):g instanceof r.Array?(void 0===h&&(h=k.createDecoratorArray(a.editor),V(a,
26
- b,h,g),g._lexicalValue=h,g._collabNode=b,S(()=>d.set(e,h))),ia(a,b,g,h)):S(()=>d.set(e,g))}}
27
- function ja(a,b,c,d,e){var f=d._array[e];const g=c.get(e);if(f!==g){let h=g._lexicalValue;g instanceof r.Map?(c=g.get("type"),"editor"===c?void 0===h&&(a=a.docMap,c=g.get("id"),f=g.get("doc"),h=k.createDecoratorEditor(c),g._lexicalValue=h,g._collabNode=b,a.set(c,f),S(()=>d.splice(e,0,h))):"map"===c?(void 0===h&&(h=k.createDecoratorMap(a.editor),T(a,b,h,g),g._lexicalValue=h,g._collabNode=b,S(()=>d.splice(e,0,h))),X(a,b,g,h,null)):B(48)):g instanceof r.Array?(void 0===h&&(h=k.createDecoratorArray(a.editor),
28
- V(a,b,h,g),g._lexicalValue=h,g._collabNode=b,S(()=>d.splice(e,0,h))),ia(a,b,g,h)):S(()=>d.splice(e,0,g))}}function ia(a,b,c,d){const e=Math.max(c.length,d.getLength());for(let f=0;f<e;f++)ja(a,b,c,d,f)}function X(a,b,c,d,e){e=null===e?Array.from(c.keys()):Array.from(e);for(let f=0;f<e.length;f++)ha(a,b,c,d,e[f])}
29
- class Y{constructor(a,b,c){this._key="";this._xmlElem=a;this._parent=b;this._type=c;this._unobservers=new Set}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return k.$isDecoratorNode(a)?a:null}getNode(){const a=k.$getNodeByKey(this._key);return k.$isDecoratorNode(a)?a:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}syncPropertiesFromLexical(a,b,c){const d=this.getPrevNode(c);
30
- c=this._xmlElem;const e=null===d?null:d.__state,f=b.__state;F(a,c,d,b);e!==f&&(b=new r.Map,c.insert(0,[b]),b._lexicalValue=f,b._collabNode=this,W(a,this,f,b),T(a,this,f,b))}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw Error("Should never happen");const d=this._xmlElem,e=d.firstChild,f=c.__state;e._lexicalValue=f;e._collabNode=this;G(a,d,c,b);X(a,this,e,f,null);T(a,this,f,e)}destroy(a){a.collabNodeMap.delete(this._key);this._unobservers.forEach(b=>b());this._unobservers.clear()}}
31
- function ba(a,b,c){b=new Y(a,b,c);return a._collabNode=b}
32
- class O{constructor(a,b,c){this._key="";this._children=[];this._xmlText=a;this._type=c;this._parent=b}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return k.$isElementNode(a)?a:null}getNode(){const a=k.$getNodeByKey(this._key);return k.$isElementNode(a)?a:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){const a=this._parent;if(null===a)throw Error("Should never happen");
33
- return a.getChildOffset(this)}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw this.getNode(),Error("Should never happen");G(a,this._xmlText,c,b)}applyChildrenYjsDelta(a,b){const c=this._children;let d=0;for(let q=0;q<b.length;q++){var e=b[q],f=e.insert,g=e.delete;if(null!=e.retain)d+=e.retain;else if("number"===typeof g)for(f=g;0<f;){const {node:l,nodeIndex:t,offset:u,length:n}=P(this,d,!1);if(l instanceof O||l instanceof C||l instanceof Y)c.splice(t,1),--f;else if(l instanceof
34
- E){e=Math.min(f,n);g=0!==t?c[t-1]:null;var h=l.getSize();if(0===u&&1===e&&0<t&&g instanceof E&&n===h&&0===Array.from(l._map.keys()).length)g._text+=l._text,c.splice(t,1);else if(0===u&&e===h)c.splice(t,1);else{g=l._text;h=u;var p=e;g=g.slice(0,h)+""+g.slice(h+p);l._text=g}f-=e}else break}else if(null!=f)if("string"===typeof f){const {node:l,offset:t}=P(this,d,!0);l instanceof E?(e=l._text,g=t,h=f,e=e.slice(0,g)+h+e.slice(g+0),l._text=e):this._xmlText.delete(t,f.length);d+=f.length}else e=f,{nodeIndex:f}=
35
- P(this,d,!1),e=M(a,e,this),c.splice(f,0,e),d+=1;else throw Error("Unexpected delta format");}}syncChildrenFromYjs(a){var b=this.getNode();if(null===b)throw this.getNode(),Error("Should never happen");var c=b.__key;const d=b.__children;var e=[];const f=d.length,g=this._children,h=g.length,p=a.collabNodeMap,q=new Set;let l,t;h!==f&&(t=ka(b,t,e));let u=0;for(let y=0;y<h;y++){var n=d[u];const x=g[y];var m=x.getNode(),w=x._key;if(null!==m&&n===w){m=k.$isTextNode(m);q.add(n);if(m)if(x._key=n,x instanceof
36
- O)m=x._xmlText,x.syncPropertiesFromYjs(a,null),x.applyChildrenYjsDelta(a,m.toDelta()),x.syncChildrenFromYjs(a);else if(x instanceof E)x.syncPropertiesAndTextFromYjs(a,null);else if(x instanceof Y)x.syncPropertiesFromYjs(a,null);else if(!(x instanceof C))throw Error("Should never happen");e[y]=n;u++}else{if(void 0===l)for(l=new Set,w=0;w<h;w++){var v=g[w]._key;""!==v&&l.add(v)}if(null===m||void 0===n||l.has(n)){t=ka(b,t,e);n=a;m=x;w=c;v=m.getType();v=n.editor._nodes.get(v);if(void 0===v)throw Error("createLexicalNode failed");
37
- v=new v.klass;v.__parent=w;m._key=v.__key;m instanceof O?(w=m._xmlText,m.syncPropertiesFromYjs(n,null),m.applyChildrenYjsDelta(n,w.toDelta()),m.syncChildrenFromYjs(n)):m instanceof E?m.syncPropertiesAndTextFromYjs(n,null):m instanceof Y&&m.syncPropertiesFromYjs(n,null);n.collabNodeMap.set(v.__key,m);n=v.__key;p.set(n,x);e[y]=n}else y--,u++}}for(b=0;b<f;b++)e=d[b],q.has(e)||(c=K(e).getWritable(),e=a.collabNodeMap.get(e),void 0!==e&&e.destroy(a),c.__parent=null)}syncPropertiesFromLexical(a,b,c){F(a,
38
- this._xmlText,this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=K(c);b instanceof O&&k.$isElementNode(c)?(b.syncPropertiesFromLexical(a,c,d),b.syncChildrenFromLexical(a,c,d,e,f)):b instanceof E&&k.$isTextNode(c)?b.syncPropertiesAndTextFromLexical(a,c,d):b instanceof Y&&k.$isDecoratorNode(c)&&b.syncPropertiesFromLexical(a,c,d)}syncChildrenFromLexical(a,b,c,d,e){var f=this.getPrevNode(c);const g=null===f?[]:f.__children;f=b.__children;const h=g.length-1,p=f.length-1,q=
39
- a.collabNodeMap;let l,t,u=0;for(b=0;u<=h&&b<=p;){var n=g[u];const w=f[b];if(n===w)this._syncChildFromLexical(a,b,w,c,d,e),u++,b++;else{void 0===l&&(l=new Set(g));void 0===t&&(t=new Set(f));var m=t.has(n);n=l.has(w);m?(m=K(w),m=aa(a,m,this),q.set(w,m),n?(this.splice(a,b,1,m),u++):this.splice(a,b,0,m),b++):(this.splice(a,b,1),u++)}}c=u>h;d=b>p;if(c&&!d)for(;b<=p;++b)c=f[b],d=K(c),d=aa(a,d,this),this.append(d),q.set(c,d);else if(d&&!c)for(f=this._children.length-1;f>=b;f--)this.splice(a,f,1)}append(a){const b=
40
- this._xmlText;var c=this._children;c=c[c.length-1];c=void 0!==c?c.getOffset()+c.getSize():0;if(a instanceof O)b.insertEmbed(c,a._xmlText);else if(a instanceof E){const d=a._map;null===d.parent&&b.insertEmbed(c,d);b.insert(c+1,a._text)}else a instanceof C?b.insertEmbed(c,a._map):a instanceof Y&&b.insertEmbed(c,a._xmlElem);this._children.push(a)}splice(a,b,c,d){const e=this._children;var f=e[b];if(void 0===f)if(void 0!==d)this.append(d);else throw Error("Should never happen");else{var g=f.getOffset();
41
- if(-1===g)throw Error("Should never happen");var h=this._xmlText;0!==c&&h.delete(g,f.getSize());d instanceof O?h.insertEmbed(g,d._xmlText):d instanceof E?(f=d._map,null===f.parent&&h.insertEmbed(g,f),h.insert(g+1,d._text)):d instanceof C?h.insertEmbed(g,d._map):d instanceof Y&&h.insertEmbed(g,d._xmlElem);if(0!==c)for(g=e.slice(b,b+c),h=0;h<g.length;h++)g[h].destroy(a);void 0!==d?e.splice(b,c,d):e.splice(b,c)}}getChildOffset(a){let b=0;const c=this._children;for(let d=0;d<c.length;d++){const e=c[d];
42
- if(e===a)return b;b+=e.getSize()}return-1}destroy(a){const b=a.collabNodeMap,c=this._children;for(let d=0;d<c.length;d++)c[d].destroy(a);b.delete(this._key)}}function ka(a,b,c){return void 0===b?(a=a.getWritable(),a.__children=c,a):b}function L(a,b,c){b=new O(a,b,c);return a._collabNode=b}
43
- function la(a,b){b=b.collabNodeMap.get(a.key);if(void 0===b)return null;a=a.offset;let c=b.getSharedType();if(b instanceof E){c=b._parent._xmlText;b=b.getOffset();if(-1===b)return null;a=b+1+a}return r.createRelativePositionFromTypeIndex(c,a)}function ma(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!r.compareRelativePositions(a,b))return!0;return!1}function na(a,b){a=a.cursorsContainer;if(null!==a){b=b.selections;const c=b.length;for(let d=0;d<c;d++)a.removeChild(b[d])}}
44
- function oa(a){for(;null!=a;){if(3===a.nodeType)return a;a=a.firstChild}return null}function pa(a){const b=a.parentNode;if(null==b)throw Error("Should never happen");return[b,Array.from(b.childNodes).indexOf(a)]}
45
- function qa(a,b){var c=b.awareness.getLocalState();if(null!==c&&(b=c.anchorPos,c=c.focusPos,null!==b&&null!==c&&(b=r.createAbsolutePositionFromRelativePosition(b,a.doc),a=r.createAbsolutePositionFromRelativePosition(c,a.doc),null!==b&&null!==a))){const [e,f]=Z(b.type,b.index),[g,h]=Z(a.type,a.index);if(null!==e&&null!==g){const p=e.getKey();a=g.getKey();b=k.$getSelection();if(k.$isRangeSelection(b)){var d=b.anchor;c=b.focus;if(d.key!==p||d.offset!==f)d=k.$getNodeByKey(p),b.anchor.set(p,f,k.$isElementNode(d)?
46
- "element":"text");if(c.key!==a||c.offset!==h)c=k.$getNodeByKey(a),b.focus.set(a,h,k.$isElementNode(c)?"element":"text")}}}}function Z(a,b){a=a._collabNode;if(void 0===a)return[null,0];if(a instanceof O){const {node:c,offset:d}=P(a,b,!0);return null===c?[a,0]:[c,d]}return[null,0]}
47
- function va(a,b){var c=Array.from(b.awareness.getStates()),d=a.clientID;b=a.cursors;var e=a.editor._editorState._nodeMap;const f=new Set;for(var g=0;g<c.length;g++){const [N,xa]=c[g];if(N!==d){f.add(N);const {anchorPos:ra,focusPos:sa,name:ya,color:za,focusing:Aa}=xa;var h=null,p=b.get(N);void 0===p&&(p={color:za,name:ya,selection:null},b.set(N,p));if(null!==ra&&null!==sa&&Aa){var q=r.createAbsolutePositionFromRelativePosition(ra,a.doc),l=r.createAbsolutePositionFromRelativePosition(sa,a.doc);if(null!==
48
- q&&null!==l){const [H,U]=Z(q.type,q.index),[ta,ua]=Z(l.type,l.index);if(null!==H&&null!==ta){l=H.getKey();var t=ta.getKey();h=p.selection;if(null===h){q=p;h=l;l=U;var u=ua,n=q.color,m=document.createElement("span");m.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:rgb(${n});z-index:10;`;var w=document.createElement("span");w.textContent=q.name;w.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:rgb(${n});color:#fff;line-height:12px;height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`;
49
- m.appendChild(w);h={anchor:{key:h,offset:l},caret:m,color:n,focus:{key:t,offset:u},name:w,range:document.createRange(),selections:[]}}else q=h.anchor,u=h.focus,q.key=l,q.offset=U,u.key=t,u.offset=ua}}}a:{q=a;l=p;m=h;var v=e;n=q.editor;t=n.getRootElement();p=q.cursorsContainer;if(null===p||null===t)break a;h=l.selection;if(null===m){null!==h&&(l.selection=null,na(q,h));break a}else l.selection=m;u=m.range;h=m.caret;l=m.color;q=m.selections;var y=m.anchor,x=m.focus;m=y.key;w=x.key;var A=v.get(m);const H=
50
- v.get(w);v=n.getElementByKey(m);n=n.getElementByKey(w);y=y.offset;x=x.offset;k.$isTextNode(A)&&(v=oa(v));k.$isTextNode(H)&&(n=oa(n));if(void 0!==A&&void 0!==H&&null!==v&&null!==n){"BR"===v.nodeName&&([v,y]=pa(v));"BR"===n.nodeName&&([n,x]=pa(n));A=v.firstChild;v===n&&null!=A&&"BR"===A.nodeName&&0===y&&0===x&&(x=1);try{u.setStart(v,y),u.setEnd(n,x)}catch(U){break a}!u.collapsed||y===x&&m===w||(u.setStart(n,x),u.setEnd(v,y));n=t.getBoundingClientRect();t=getComputedStyle(t);t=parseFloat(t.paddingLeft)+
51
- parseFloat(t.paddingRight);m=Array.from(u.getClientRects());u=m.length;w=q.length;for(A=0;A<u;A++)v=m[A],v.width+t===n.width?(m.splice(A--,1),u--):(y=q[A],void 0===y&&(y=document.createElement("span"),q[A]=y,p.appendChild(y)),y.style.cssText=`position:absolute;top:${v.top}px;left:${v.left}px;height:${v.height}px;width:${v.width}px;background-color:rgba(${l}, 0.3);pointer-events:none;z-index:10;`,A===u-1&&h.parentNode!==y&&y.appendChild(h));for(h=w-1;h>=u;h--)p.removeChild(q[h]),q.pop()}}}}c=Array.from(b.keys());
52
- for(d=0;d<c.length;d++)e=c[d],f.has(e)||(g=b.get(e),void 0!==g&&(g=g.selection,null!==g&&na(a,g),b.delete(e)))}function wa(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:g,name:h,color:p,focusing:q}=e,l=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)k.$isRangeSelection(d)&&(e=la(d.anchor,a),l=la(d.focus,a)),(ma(f,e)||ma(g,l))&&b.setLocalState({anchorPos:e,color:p,focusPos:l,focusing:q,name:h})}}
53
- function Ba(a,b){var {target:c}=b;const d=M(a,c),e=c._lexicalValue;if(void 0!==e&&d instanceof Y)if(c instanceof r.Map)X(a,d,c,e,b.keysChanged);else{if(c instanceof r.Array&&k.isDecoratorArray(e)){b=b.delta;let g=0;for(let h=0;h<b.length;h++){var f=b[h];const p=f.retain,q=f.delete;f=f.insert;if(void 0!==p)g+=p;else if(void 0!==q)S(()=>{e._array.slice(g,g+q).forEach(l=>{(k.isDecoratorArray(l)||k.isDecoratorMap(l))&&l.destroy()});e.splice(g,q)});else if(void 0!==f)ja(a,d,c,e,g);else throw Error("Not supported");
54
- }}}else if(d instanceof O&&b instanceof r.YTextEvent){const {keysChanged:g,childListChanged:h,delta:p}=b;0<g.size&&d.syncPropertiesFromYjs(a,g);h&&(d.applyChildrenYjsDelta(a,p),d.syncChildrenFromYjs(a))}else if(d instanceof E&&b instanceof r.YMapEvent)({keysChanged:c}=b),0<c.size&&d.syncPropertiesAndTextFromYjs(a,c);else if(d instanceof Y&&b instanceof r.YXmlEvent)({attributesChanged:c}=b),0<c.size&&d.syncPropertiesFromYjs(a,c);else throw Error("Should never happen");}
55
- const Ca=k.createCommand(),Da=k.createCommand();exports.CONNECTED_COMMAND=Ca;exports.TOGGLE_CONNECT_COMMAND=Da;exports.createBinding=function(a,b,c,d,e){if(void 0===d||null===d)throw Error("Should never happen");b=d.get("root",r.XmlText);b=L(b,null,"root");b._key="root";return{clientID:d.clientID,collabNodeMap:new Map,cursors:new Map,cursorsContainer:null,doc:d,docMap:e,editor:a,id:c,nodeProperties:new Map,root:b}};
56
- exports.createUndoManager=function(a,b){return new r.UndoManager(b,{trackedOrigins:new Set([a,null])})};exports.initLocalState=function(a,b,c,d){a.awareness.setLocalState({anchorPos:null,color:c,focusPos:null,focusing:d,name:b})};exports.setLocalStateFocus=function(a,b,c,d){({awareness:a}=a);let e=a.getLocalState();null===e&&(e={anchorPos:null,color:c,focusPos:null,focusing:d,name:b});e.focusing=d;a.setLocalState(e)};exports.syncCursorPositions=va;
57
- exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,g,h){Q(a,()=>{d.read(()=>{if(h.has("collaboration")){if(0<g.size){var p=Array.from(g),q=a.collabNodeMap,l=[];for(let m=0;m<p.length;m++){var t=p[m],u=k.$getNodeByKey(t),n=q.get(t);if(n instanceof E)if(k.$isTextNode(u))l.push([n,u.__text]);else{u=n.getOffset();if(-1===u)continue;const w=n._parent;n._normalized=!0;w._xmlText.delete(u,1);q.delete(t);t=w._children;n=t.indexOf(n);t.splice(n,1)}}for(p=0;p<l.length;p++){const [m,w]=l[p];m._text=w}}}else e.has("root")&&
58
- (l=c._nodeMap,p=k.$getRoot(),q=a.root,q.syncPropertiesFromLexical(a,p,l),q.syncChildrenFromLexical(a,p,l,e,f)),l=k.$getSelection(),wa(a,b,c._selection,l)})})};
59
- exports.syncYjsChangesToLexical=function(a,b,c){const d=a.editor,e=d._editorState;d.update(()=>{var f=d._pendingEditorState;for(var g=0;g<c.length;g++)Ba(a,c[g]);var h=k.$getSelection();if(k.$isRangeSelection(h))if(ca(h)){g=e._selection;if(k.$isRangeSelection(g)){const p=z.$createOffsetView(d,0,e);f=z.$createOffsetView(d,0,f);const [q,l]=p.getOffsetsFromSelection(g);f=f.createSelectionFromOffsets(q,l,p);null!==f?k.$setSelection(f):(qa(a,b),ca(h)&&(h=k.$getRoot(),0===h.getChildrenSize()&&h.append(k.$createParagraphNode()),
60
- k.$getRoot().selectEnd()))}wa(a,b,g,k.$getSelection())}else qa(a,b)},{onUpdate:()=>{va(a,b)},skipTransforms:!0,tag:"collaboration"})};
7
+ var q=require("lexical"),w=require("yjs"),z=require("@lexical/offset");class B{constructor(a,b){this._key="";this._map=a;this._parent=b;this._type="linebreak"}getNode(){const a=q.$getNodeByKey(this._key);return q.$isLineBreakNode(a)?a:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(a){a.collabNodeMap.delete(this._key)}}function C(a,b){b=new B(a,b);return a._collabNode=b}
8
+ class D{constructor(a,b,c,d){this._key="";this._map=a;this._parent=c;this._text=b;this._type=d;this._normalized=!1}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return q.$isTextNode(a)?a:null}getNode(){const a=q.$getNodeByKey(this._key);return q.$isTextNode(a)?a:null}getSharedType(){return this._map}getType(){return this._type}getKey(){return this._key}getSize(){return this._text.length+(this._normalized?0:1)}getOffset(){return this._parent.getChildOffset(this)}spliceText(a,b,c){const d=
9
+ this._parent._xmlText;a=this.getOffset()+1+a;0!==b&&d.delete(a,b);""!==c&&d.insert(a,c)}syncPropertiesAndTextFromLexical(a,b,c){var d=this.getPrevNode(c);c=b.__text;F(a,this._map,d,b);if(null!==d&&(a=d.__text,a!==c)){d=b.__key;b=a;var e=q.$getSelection();a=c.length;q.$isRangeSelection(e)&&e.isCollapsed()&&(e=e.anchor,e.key===d&&(a=e.offset));d=b.length;const f=c.length;let h=e=0;for(;e<d&&e<f&&b[e]===c[e]&&e<a;)e++;for(;h+e<d&&h+e<f&&b[d-h-1]===c[f-h-1];)h++;for(;h+e<d&&h+e<f&&b[e]===c[e];)e++;b=
10
+ e;a=c.slice(e,f-h);d=d-e-h;this.spliceText(b,d,a);this._text=c}}syncPropertiesAndTextFromYjs(a,b){const c=this.getNode();if(null===c)throw Error("Should never happen");G(a,this._map,c,b);a=this._text;c.__text!==a&&(c.getWritable().__text=a)}destroy(a){a.collabNodeMap.delete(this._key)}}function H(a,b,c,d){b=new D(a,b,c,d);return a._collabNode=b}const J=new Set(["__key","__children","__parent","__cachedText","__text"]);
11
+ function K(a){a=q.$getNodeByKey(a);if(null===a)throw Error("Should never happen");return a}
12
+ function L(a,b,c){const d=b.__type;if(q.$isElementNode(b)){var e=new w.XmlText;c=M(e,c,d);c.syncPropertiesFromLexical(a,b,null);c.syncChildrenFromLexical(a,b,null,null,null)}else if(q.$isTextNode(b))e=new w.Map,c=H(e,b.__text,c,d),c.syncPropertiesAndTextFromLexical(a,b,null);else if(q.$isLineBreakNode(b))a=new w.Map,a.set("__type","linebreak"),c=C(a,c);else if(q.$isDecoratorNode(b))e=new w.XmlElement,c=O(e,c,d),c.syncPropertiesFromLexical(a,b,null);else throw Error("Should never happen");c._key=b.__key;
13
+ return c}
14
+ function P(a,b,c){const d=b._collabNode;if(void 0===d){var e=a.editor._nodes;const f=b instanceof w.Map?b.get("__type"):b.getAttribute("__type");if(null==f)throw Error("Should never happen");if(void 0===e.get(f))throw Error("Should never happen");e=b.parent;a=void 0===c&&null!==e?P(a,e):c||null;if(!(a instanceof Q))throw Error("Should never happen");if(b instanceof w.XmlText)return M(b,a,f);if(b instanceof w.Map){if(null===a)throw Error("Should never happen");return"linebreak"===f?C(b,a):H(b,"",a,
15
+ f)}if(b instanceof w.XmlElement)return O(b,a,f)}return d}function G(a,b,c,d){d=null===d?b instanceof w.Map?Array.from(b.keys()):Object.keys(b.getAttributes()):Array.from(d);let e;for(let h=0;h<d.length;h++){const g=d[h];if(J.has(g))continue;var f=c[g];let k=b instanceof w.Map?b.get(g):b.getAttribute(g);if(f!==k){if(k instanceof w.Doc){const m=a.docMap;f instanceof w.Doc&&m.delete(f.guid);f=q.createEditor();const l=k.guid;f._key=l;m.set(l,k);k=f}void 0===e&&(e=c.getWritable());e[g]=k}}}
16
+ function F(a,b,c,d){var e=d.__type,f=a.nodeProperties;let h=f.get(e);void 0===h&&(h=Object.keys(d).filter(k=>!J.has(k)),f.set(e,h));e=a.editor.constructor;for(f=0;f<h.length;f++){const k=h[f];var g=null===c?void 0:c[k];let m=d[k];if(g!==m){if(m instanceof e){const l=a.docMap;let r;g instanceof e&&(g=g._key,r=l.get(g),l.delete(g));g=r||new w.Doc;const t=g.guid;m._key=t;l.set(t,g);m=g;a.editor.update(()=>{d.markDirty()})}b instanceof w.Map?b.set(k,m):b.setAttribute(k,m)}}}
17
+ function R(a,b,c){let d=0,e=0;const f=a._children,h=f.length;for(;e<h;e++){a=f[e];const g=d,k=a.getSize();d+=k;if((c?d>=b:d>b)&&a instanceof D)return b=b-g-1,0>b&&(b=0),{length:k-b,node:a,nodeIndex:e,offset:b};if(d>b)return{length:0,node:a,nodeIndex:e,offset:g};if(e===h-1)return{length:0,node:null,nodeIndex:e+1,offset:g+1}}return{length:0,node:null,nodeIndex:0,offset:0}}
18
+ function S(a){const b=a.anchor;a=a.focus;let c=!1;try{const d=b.getNode(),e=a.getNode();if(!d.isAttached()||!e.isAttached()||q.$isTextNode(d)&&b.offset>d.getTextContentSize()||q.$isTextNode(e)&&a.offset>e.getTextContentSize())c=!0}catch(d){c=!0}return c}function aa(a,b){a.doc.transact(b,a)}
19
+ class T{constructor(a,b,c){this._key="";this._xmlElem=a;this._parent=b;this._type=c;this._unobservers=new Set}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return q.$isDecoratorNode(a)?a:null}getNode(){const a=q.$getNodeByKey(this._key);return q.$isDecoratorNode(a)?a:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}syncPropertiesFromLexical(a,b,c){c=this.getPrevNode(c);
20
+ F(a,this._xmlElem,c,b)}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw Error("Should never happen");G(a,this._xmlElem,c,b)}destroy(a){a.collabNodeMap.delete(this._key);this._unobservers.forEach(b=>b());this._unobservers.clear()}}function O(a,b,c){b=new T(a,b,c);return a._collabNode=b}
21
+ class Q{constructor(a,b,c){this._key="";this._children=[];this._xmlText=a;this._type=c;this._parent=b}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return q.$isElementNode(a)?a:null}getNode(){const a=q.$getNodeByKey(this._key);return q.$isElementNode(a)?a:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){const a=this._parent;if(null===a)throw Error("Should never happen");
22
+ return a.getChildOffset(this)}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw this.getNode(),Error("Should never happen");G(a,this._xmlText,c,b)}applyChildrenYjsDelta(a,b){const c=this._children;let d=0;for(let m=0;m<b.length;m++){var e=b[m],f=e.insert,h=e.delete;if(null!=e.retain)d+=e.retain;else if("number"===typeof h)for(f=h;0<f;){const {node:l,nodeIndex:r,offset:t,length:p}=R(this,d,!1);if(l instanceof Q||l instanceof B||l instanceof T)c.splice(r,1),--f;else if(l instanceof
23
+ D){e=Math.min(f,p);h=0!==r?c[r-1]:null;var g=l.getSize();if(0===t&&1===e&&0<r&&h instanceof D&&p===g&&0===Array.from(l._map.keys()).length)h._text+=l._text,c.splice(r,1);else if(0===t&&e===g)c.splice(r,1);else{h=l._text;g=t;var k=e;h=h.slice(0,g)+""+h.slice(g+k);l._text=h}f-=e}else break}else if(null!=f)if("string"===typeof f){const {node:l,offset:r}=R(this,d,!0);l instanceof D?(e=l._text,h=r,g=f,e=e.slice(0,h)+g+e.slice(h+0),l._text=e):this._xmlText.delete(r,f.length);d+=f.length}else e=f,{nodeIndex:f}=
24
+ R(this,d,!1),e=P(a,e,this),c.splice(f,0,e),d+=1;else throw Error("Unexpected delta format");}}syncChildrenFromYjs(a){var b=this.getNode();if(null===b)throw this.getNode(),Error("Should never happen");var c=b.__key;const d=b.__children;var e=[];const f=d.length,h=this._children,g=h.length,k=a.collabNodeMap,m=new Set;let l,r;g!==f&&(r=U(b,r,e));let t=0;for(let y=0;y<g;y++){var p=d[t];const x=h[y];var n=x.getNode(),v=x._key;if(null!==n&&p===v){n=q.$isTextNode(n);m.add(p);if(n)if(x._key=p,x instanceof
25
+ Q)n=x._xmlText,x.syncPropertiesFromYjs(a,null),x.applyChildrenYjsDelta(a,n.toDelta()),x.syncChildrenFromYjs(a);else if(x instanceof D)x.syncPropertiesAndTextFromYjs(a,null);else if(x instanceof T)x.syncPropertiesFromYjs(a,null);else if(!(x instanceof B))throw Error("Should never happen");e[y]=p;t++}else{if(void 0===l)for(l=new Set,v=0;v<g;v++){var u=h[v]._key;""!==u&&l.add(u)}if(null===n||void 0===p||l.has(p)){r=U(b,r,e);p=a;n=x;v=c;u=n.getType();u=p.editor._nodes.get(u);if(void 0===u)throw Error("createLexicalNode failed");
26
+ u=new u.klass;u.__parent=v;n._key=u.__key;n instanceof Q?(v=n._xmlText,n.syncPropertiesFromYjs(p,null),n.applyChildrenYjsDelta(p,v.toDelta()),n.syncChildrenFromYjs(p)):n instanceof D?n.syncPropertiesAndTextFromYjs(p,null):n instanceof T&&n.syncPropertiesFromYjs(p,null);p.collabNodeMap.set(u.__key,n);p=u.__key;k.set(p,x);e[y]=p}else y--,t++}}for(b=0;b<f;b++)e=d[b],m.has(e)||(c=K(e).getWritable(),e=a.collabNodeMap.get(e),void 0!==e&&e.destroy(a),c.__parent=null)}syncPropertiesFromLexical(a,b,c){F(a,
27
+ this._xmlText,this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=K(c);b instanceof Q&&q.$isElementNode(c)?(b.syncPropertiesFromLexical(a,c,d),b.syncChildrenFromLexical(a,c,d,e,f)):b instanceof D&&q.$isTextNode(c)?b.syncPropertiesAndTextFromLexical(a,c,d):b instanceof T&&q.$isDecoratorNode(c)&&b.syncPropertiesFromLexical(a,c,d)}syncChildrenFromLexical(a,b,c,d,e){var f=this.getPrevNode(c);const h=null===f?[]:f.__children;f=b.__children;const g=h.length-1,k=f.length-1,m=
28
+ a.collabNodeMap;let l,r,t=0;for(b=0;t<=g&&b<=k;){var p=h[t];const v=f[b];if(p===v)this._syncChildFromLexical(a,b,v,c,d,e),t++,b++;else{void 0===l&&(l=new Set(h));void 0===r&&(r=new Set(f));var n=r.has(p);p=l.has(v);n?(n=K(v),n=L(a,n,this),m.set(v,n),p?(this.splice(a,b,1,n),t++):this.splice(a,b,0,n),b++):(this.splice(a,b,1),t++)}}c=t>g;d=b>k;if(c&&!d)for(;b<=k;++b)c=f[b],d=K(c),d=L(a,d,this),this.append(d),m.set(c,d);else if(d&&!c)for(f=this._children.length-1;f>=b;f--)this.splice(a,f,1)}append(a){const b=
29
+ this._xmlText;var c=this._children;c=c[c.length-1];c=void 0!==c?c.getOffset()+c.getSize():0;if(a instanceof Q)b.insertEmbed(c,a._xmlText);else if(a instanceof D){const d=a._map;null===d.parent&&b.insertEmbed(c,d);b.insert(c+1,a._text)}else a instanceof B?b.insertEmbed(c,a._map):a instanceof T&&b.insertEmbed(c,a._xmlElem);this._children.push(a)}splice(a,b,c,d){const e=this._children;var f=e[b];if(void 0===f)if(void 0!==d)this.append(d);else throw Error("Should never happen");else{var h=f.getOffset();
30
+ if(-1===h)throw Error("Should never happen");var g=this._xmlText;0!==c&&g.delete(h,f.getSize());d instanceof Q?g.insertEmbed(h,d._xmlText):d instanceof D?(f=d._map,null===f.parent&&g.insertEmbed(h,f),g.insert(h+1,d._text)):d instanceof B?g.insertEmbed(h,d._map):d instanceof T&&g.insertEmbed(h,d._xmlElem);if(0!==c)for(h=e.slice(b,b+c),g=0;g<h.length;g++)h[g].destroy(a);void 0!==d?e.splice(b,c,d):e.splice(b,c)}}getChildOffset(a){let b=0;const c=this._children;for(let d=0;d<c.length;d++){const e=c[d];
31
+ if(e===a)return b;b+=e.getSize()}return-1}destroy(a){const b=a.collabNodeMap,c=this._children;for(let d=0;d<c.length;d++)c[d].destroy(a);b.delete(this._key)}}function U(a,b,c){return void 0===b?(a=a.getWritable(),a.__children=c,a):b}function M(a,b,c){b=new Q(a,b,c);return a._collabNode=b}
32
+ function V(a,b){b=b.collabNodeMap.get(a.key);if(void 0===b)return null;a=a.offset;let c=b.getSharedType();if(b instanceof D){c=b._parent._xmlText;b=b.getOffset();if(-1===b)return null;a=b+1+a}return w.createRelativePositionFromTypeIndex(c,a)}function W(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!w.compareRelativePositions(a,b))return!0;return!1}function X(a,b){a=a.cursorsContainer;if(null!==a){b=b.selections;const c=b.length;for(let d=0;d<c;d++)a.removeChild(b[d])}}
33
+ function Y(a){for(;null!=a;){if(3===a.nodeType)return a;a=a.firstChild}return null}function ba(a){const b=a.parentNode;if(null==b)throw Error("Should never happen");return[b,Array.from(b.childNodes).indexOf(a)]}
34
+ function ca(a,b){var c=b.awareness.getLocalState();if(null!==c&&(b=c.anchorPos,c=c.focusPos,null!==b&&null!==c&&(b=w.createAbsolutePositionFromRelativePosition(b,a.doc),a=w.createAbsolutePositionFromRelativePosition(c,a.doc),null!==b&&null!==a))){const [e,f]=Z(b.type,b.index),[h,g]=Z(a.type,a.index);if(null!==e&&null!==h){const k=e.getKey();a=h.getKey();b=q.$getSelection();if(q.$isRangeSelection(b)){var d=b.anchor;c=b.focus;if(d.key!==k||d.offset!==f)d=q.$getNodeByKey(k),b.anchor.set(k,f,q.$isElementNode(d)?
35
+ "element":"text");if(c.key!==a||c.offset!==g)c=q.$getNodeByKey(a),b.focus.set(a,g,q.$isElementNode(c)?"element":"text")}}}}function Z(a,b){a=a._collabNode;if(void 0===a)return[null,0];if(a instanceof Q){const {node:c,offset:d}=R(a,b,!0);return null===c?[a,0]:[c,d]}return[null,0]}
36
+ function ia(a,b){var c=Array.from(b.awareness.getStates()),d=a.clientID;b=a.cursors;var e=a.editor._editorState._nodeMap;const f=new Set;for(var h=0;h<c.length;h++){const [I,ka]=c[h];if(I!==d){f.add(I);const {anchorPos:da,focusPos:ea,name:la,color:ma,focusing:na}=ka;var g=null,k=b.get(I);void 0===k&&(k={color:ma,name:la,selection:null},b.set(I,k));if(null!==da&&null!==ea&&na){var m=w.createAbsolutePositionFromRelativePosition(da,a.doc),l=w.createAbsolutePositionFromRelativePosition(ea,a.doc);if(null!==
37
+ m&&null!==l){const [E,N]=Z(m.type,m.index),[fa,ha]=Z(l.type,l.index);if(null!==E&&null!==fa){l=E.getKey();var r=fa.getKey();g=k.selection;if(null===g){m=k;g=l;l=N;var t=ha,p=m.color,n=document.createElement("span");n.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:rgb(${p});z-index:10;`;var v=document.createElement("span");v.textContent=m.name;v.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:rgb(${p});color:#fff;line-height:12px;height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`;
38
+ n.appendChild(v);g={anchor:{key:g,offset:l},caret:n,color:p,focus:{key:r,offset:t},name:v,range:document.createRange(),selections:[]}}else m=g.anchor,t=g.focus,m.key=l,m.offset=N,t.key=r,t.offset=ha}}}a:{m=a;l=k;n=g;var u=e;p=m.editor;r=p.getRootElement();k=m.cursorsContainer;if(null===k||null===r)break a;g=l.selection;if(null===n){null!==g&&(l.selection=null,X(m,g));break a}else l.selection=n;t=n.range;g=n.caret;l=n.color;m=n.selections;var y=n.anchor,x=n.focus;n=y.key;v=x.key;var A=u.get(n);const E=
39
+ u.get(v);u=p.getElementByKey(n);p=p.getElementByKey(v);y=y.offset;x=x.offset;q.$isTextNode(A)&&(u=Y(u));q.$isTextNode(E)&&(p=Y(p));if(void 0!==A&&void 0!==E&&null!==u&&null!==p){"BR"===u.nodeName&&([u,y]=ba(u));"BR"===p.nodeName&&([p,x]=ba(p));A=u.firstChild;u===p&&null!=A&&"BR"===A.nodeName&&0===y&&0===x&&(x=1);try{t.setStart(u,y),t.setEnd(p,x)}catch(N){break a}!t.collapsed||y===x&&n===v||(t.setStart(p,x),t.setEnd(u,y));p=r.getBoundingClientRect();r=getComputedStyle(r);r=parseFloat(r.paddingLeft)+
40
+ parseFloat(r.paddingRight);n=Array.from(t.getClientRects());t=n.length;v=m.length;for(A=0;A<t;A++)u=n[A],u.width+r===p.width?(n.splice(A--,1),t--):(y=m[A],void 0===y&&(y=document.createElement("span"),m[A]=y,k.appendChild(y)),y.style.cssText=`position:absolute;top:${u.top}px;left:${u.left}px;height:${u.height}px;width:${u.width}px;background-color:rgba(${l}, 0.3);pointer-events:none;z-index:10;`,A===t-1&&g.parentNode!==y&&y.appendChild(g));for(g=v-1;g>=t;g--)k.removeChild(m[g]),m.pop()}}}}c=Array.from(b.keys());
41
+ for(d=0;d<c.length;d++)e=c[d],f.has(e)||(h=b.get(e),void 0!==h&&(h=h.selection,null!==h&&X(a,h),b.delete(e)))}function ja(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:h,name:g,color:k,focusing:m}=e,l=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)q.$isRangeSelection(d)&&(e=V(d.anchor,a),l=V(d.focus,a)),(W(f,e)||W(h,l))&&b.setLocalState({anchorPos:e,color:k,focusPos:l,focusing:m,name:g})}}const oa=q.createCommand(),pa=q.createCommand();
42
+ exports.CONNECTED_COMMAND=oa;exports.TOGGLE_CONNECT_COMMAND=pa;exports.createBinding=function(a,b,c,d,e){if(void 0===d||null===d)throw Error("Should never happen");b=d.get("root",w.XmlText);b=M(b,null,"root");b._key="root";return{clientID:d.clientID,collabNodeMap:new Map,cursors:new Map,cursorsContainer:null,doc:d,docMap:e,editor:a,id:c,nodeProperties:new Map,root:b}};exports.createUndoManager=function(a,b){return new w.UndoManager(b,{trackedOrigins:new Set([a,null])})};
43
+ exports.initLocalState=function(a,b,c,d){a.awareness.setLocalState({anchorPos:null,color:c,focusPos:null,focusing:d,name:b})};exports.setLocalStateFocus=function(a,b,c,d){({awareness:a}=a);let e=a.getLocalState();null===e&&(e={anchorPos:null,color:c,focusPos:null,focusing:d,name:b});e.focusing=d;a.setLocalState(e)};exports.syncCursorPositions=ia;
44
+ exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,h,g){aa(a,()=>{d.read(()=>{if(g.has("collaboration")){if(0<h.size){var k=Array.from(h),m=a.collabNodeMap,l=[];for(let n=0;n<k.length;n++){var r=k[n],t=q.$getNodeByKey(r),p=m.get(r);if(p instanceof D)if(q.$isTextNode(t))l.push([p,t.__text]);else{t=p.getOffset();if(-1===t)continue;const v=p._parent;p._normalized=!0;v._xmlText.delete(t,1);m.delete(r);r=v._children;p=r.indexOf(p);r.splice(p,1)}}for(k=0;k<l.length;k++){const [n,v]=l[k];n._text=v}}}else e.has("root")&&
45
+ (l=c._nodeMap,k=q.$getRoot(),m=a.root,m.syncPropertiesFromLexical(a,k,l),m.syncChildrenFromLexical(a,k,l,e,f)),l=q.$getSelection(),ja(a,b,c._selection,l)})})};
46
+ exports.syncYjsChangesToLexical=function(a,b,c){const d=a.editor,e=d._editorState;d.update(()=>{var f=d._pendingEditorState;for(var h=0;h<c.length;h++){var g=a,k=c[h],{target:m}=k;m=P(g,m);if(m instanceof Q&&k instanceof w.YTextEvent){const {keysChanged:l,childListChanged:r,delta:t}=k;0<l.size&&m.syncPropertiesFromYjs(g,l);r&&(m.applyChildrenYjsDelta(g,t),m.syncChildrenFromYjs(g))}else if(m instanceof D&&k instanceof w.YMapEvent)({keysChanged:k}=k),0<k.size&&m.syncPropertiesAndTextFromYjs(g,k);else if(m instanceof
47
+ T&&k instanceof w.YXmlEvent)({attributesChanged:k}=k),0<k.size&&m.syncPropertiesFromYjs(g,k);else throw Error("Should never happen");}h=q.$getSelection();if(q.$isRangeSelection(h))if(S(h)){g=e._selection;if(q.$isRangeSelection(g)){m=z.$createOffsetView(d,0,e);f=z.$createOffsetView(d,0,f);const [l,r]=m.getOffsetsFromSelection(g);f=f.createSelectionFromOffsets(l,r,m);null!==f?q.$setSelection(f):(ca(a,b),S(h)&&(f=q.$getRoot(),0===f.getChildrenSize()&&f.append(q.$createParagraphNode()),q.$getRoot().selectEnd()))}ja(a,
48
+ b,g,q.$getSelection())}else ca(a,b)},{onUpdate:()=>{ia(a,b)},skipTransforms:!0,tag:"collaboration"})};
package/package.json CHANGED
@@ -11,13 +11,13 @@
11
11
  "crdt"
12
12
  ],
13
13
  "license": "MIT",
14
- "version": "0.1.21",
14
+ "version": "0.2.2",
15
15
  "main": "LexicalYjs.js",
16
16
  "dependencies": {
17
- "@lexical/offset": "0.1.21"
17
+ "@lexical/offset": "0.2.2"
18
18
  },
19
19
  "peerDependencies": {
20
- "lexical": "0.1.21",
20
+ "lexical": "0.2.2",
21
21
  "yjs": ">=13.5.22"
22
22
  },
23
23
  "repository": {