@lexical/yjs 0.4.1 → 0.5.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
@@ -204,8 +204,8 @@ class CollabTextNode {
204
204
  syncPropertiesAndTextFromYjs(binding, keysChanged) {
205
205
  const lexicalNode = this.getNode();
206
206
 
207
- if (lexicalNode === null) {
208
- throw new Error('Should never happen');
207
+ if (!(lexicalNode !== null)) {
208
+ throw Error(`syncPropertiesAndTextFromYjs: cound not find decorator node`);
209
209
  }
210
210
 
211
211
  syncPropertiesFromYjs(binding, this._map, lexicalNode, keysChanged);
@@ -241,8 +241,8 @@ const excludedProperties = new Set(['__key', '__children', '__parent', '__cached
241
241
  function $getNodeByKeyOrThrow(key) {
242
242
  const node = lexical.$getNodeByKey(key);
243
243
 
244
- if (node === null) {
245
- throw new Error('Should never happen');
244
+ if (!(node !== null)) {
245
+ throw Error(`could not find node by key`);
246
246
  }
247
247
 
248
248
  return node;
@@ -257,7 +257,7 @@ function $createCollabNodeFromLexicalNode(binding, lexicalNode, parent) {
257
257
  collabNode.syncPropertiesFromLexical(binding, lexicalNode, null);
258
258
  collabNode.syncChildrenFromLexical(binding, lexicalNode, null, null, null);
259
259
  } else if (lexical.$isTextNode(lexicalNode)) {
260
- // TODO create a token text node for token, segmented or inert nodes.
260
+ // TODO create a token text node for token, segmented nodes.
261
261
  const map = new yjs.Map();
262
262
  collabNode = $createCollabTextNode(map, lexicalNode.__text, parent, nodeType);
263
263
  collabNode.syncPropertiesAndTextFromLexical(binding, lexicalNode, null);
@@ -270,7 +270,9 @@ function $createCollabNodeFromLexicalNode(binding, lexicalNode, parent) {
270
270
  collabNode = $createCollabDecoratorNode(xmlElem, parent, nodeType);
271
271
  collabNode.syncPropertiesFromLexical(binding, lexicalNode, null);
272
272
  } else {
273
- throw new Error('Should never happen');
273
+ {
274
+ throw Error(`Expected text, element, decorator, or linebreak node`);
275
+ }
274
276
  }
275
277
 
276
278
  collabNode._key = lexicalNode.__key;
@@ -280,8 +282,8 @@ function $createCollabNodeFromLexicalNode(binding, lexicalNode, parent) {
280
282
  function getNodeTypeFromSharedType(sharedType) {
281
283
  const type = sharedType instanceof yjs.Map ? sharedType.get('__type') : sharedType.getAttribute('__type');
282
284
 
283
- if (type == null) {
284
- throw new Error('Should never happen');
285
+ if (!(type != null)) {
286
+ throw Error(`Expected shared type to include type attribute`);
285
287
  }
286
288
 
287
289
  return type;
@@ -296,24 +298,20 @@ function getOrInitCollabNodeFromSharedType(binding, sharedType, parent) {
296
298
  const type = getNodeTypeFromSharedType(sharedType);
297
299
  const nodeInfo = registeredNodes.get(type);
298
300
 
299
- if (nodeInfo === undefined) {
300
- throw new Error('Should never happen');
301
+ if (!(nodeInfo !== undefined)) {
302
+ throw Error(`Node ${type} is not registered`);
301
303
  }
302
304
 
303
305
  const sharedParent = sharedType.parent;
304
306
  const targetParent = parent === undefined && sharedParent !== null ? getOrInitCollabNodeFromSharedType(binding, sharedParent) : parent || null;
305
307
 
306
308
  if (!(targetParent instanceof CollabElementNode)) {
307
- throw new Error('Should never happen');
309
+ throw Error(`Expected parent to be a collab element node`);
308
310
  }
309
311
 
310
312
  if (sharedType instanceof yjs.XmlText) {
311
313
  return $createCollabElementNode(sharedType, targetParent, type);
312
314
  } else if (sharedType instanceof yjs.Map) {
313
- if (targetParent === null) {
314
- throw new Error('Should never happen');
315
- }
316
-
317
315
  if (type === 'linebreak') {
318
316
  return $createCollabLineBreakNode(sharedType, targetParent);
319
317
  }
@@ -331,8 +329,8 @@ function createLexicalNodeFromCollabNode(binding, collabNode, parentKey) {
331
329
  const registeredNodes = binding.editor._nodes;
332
330
  const nodeInfo = registeredNodes.get(type);
333
331
 
334
- if (nodeInfo === undefined) {
335
- throw new Error('createLexicalNode failed');
332
+ if (!(nodeInfo !== undefined)) {
333
+ throw Error(`Node ${type} is not registered`);
336
334
  }
337
335
 
338
336
  const lexicalNode = new nodeInfo.klass();
@@ -584,8 +582,8 @@ class CollabDecoratorNode {
584
582
  syncPropertiesFromYjs(binding, keysChanged) {
585
583
  const lexicalNode = this.getNode();
586
584
 
587
- if (lexicalNode === null) {
588
- throw new Error('Should never happen');
585
+ if (!(lexicalNode !== null)) {
586
+ throw Error(`syncPropertiesFromYjs: cound not find decorator node`);
589
587
  }
590
588
 
591
589
  const xmlElem = this._xmlElem;
@@ -662,8 +660,8 @@ class CollabElementNode {
662
660
  getOffset() {
663
661
  const collabElementNode = this._parent;
664
662
 
665
- if (collabElementNode === null) {
666
- throw new Error('Should never happen');
663
+ if (!(collabElementNode !== null)) {
664
+ throw Error(`getOffset: cound not find collab element node`);
667
665
  }
668
666
 
669
667
  return collabElementNode.getChildOffset(this);
@@ -672,9 +670,8 @@ class CollabElementNode {
672
670
  syncPropertiesFromYjs(binding, keysChanged) {
673
671
  const lexicalNode = this.getNode();
674
672
 
675
- if (lexicalNode === null) {
676
- this.getNode();
677
- throw new Error('Should never happen');
673
+ if (!(lexicalNode !== null)) {
674
+ throw Error(`syncPropertiesFromYjs: cound not find element node`);
678
675
  }
679
676
 
680
677
  syncPropertiesFromYjs(binding, this._xmlText, lexicalNode, keysChanged);
@@ -768,9 +765,8 @@ class CollabElementNode {
768
765
  // Now diff the children of the collab node with that of our existing Lexical node.
769
766
  const lexicalNode = this.getNode();
770
767
 
771
- if (lexicalNode === null) {
772
- this.getNode();
773
- throw new Error('Should never happen');
768
+ if (!(lexicalNode !== null)) {
769
+ throw Error(`syncChildrenFromYjs: cound not find element node`);
774
770
  }
775
771
 
776
772
  const key = lexicalNode.__key;
@@ -815,7 +811,9 @@ class CollabElementNode {
815
811
  } else if (childCollabNode instanceof CollabDecoratorNode) {
816
812
  childCollabNode.syncPropertiesFromYjs(binding, null);
817
813
  } else if (!(childCollabNode instanceof CollabLineBreakNode)) {
818
- throw new Error('Should never happen');
814
+ {
815
+ throw Error(`syncChildrenFromYjs: expected text, element, decorator, or linebreak collab node`);
816
+ }
819
817
  }
820
818
  }
821
819
 
@@ -990,19 +988,18 @@ class CollabElementNode {
990
988
  const child = children[index];
991
989
 
992
990
  if (child === undefined) {
993
- if (collabNode !== undefined) {
994
- this.append(collabNode);
995
- } else {
996
- throw new Error('Should never happen');
991
+ if (!(collabNode !== undefined)) {
992
+ throw Error(`splice: could not find collab element node`);
997
993
  }
998
994
 
995
+ this.append(collabNode);
999
996
  return;
1000
997
  }
1001
998
 
1002
999
  const offset = child.getOffset();
1003
1000
 
1004
- if (offset === -1) {
1005
- throw new Error('Should never happen');
1001
+ if (!(offset !== -1)) {
1002
+ throw Error(`splice: expected offset to be greater than zero`);
1006
1003
  }
1007
1004
 
1008
1005
  const xmlText = this._xmlText;
@@ -1099,8 +1096,8 @@ function $createCollabElementNode(xmlText, parent, type) {
1099
1096
  *
1100
1097
  */
1101
1098
  function createBinding(editor, provider, id, doc, docMap) {
1102
- if (doc === undefined || doc === null) {
1103
- throw new Error('Should never happen');
1099
+ if (!(doc !== undefined && doc !== null)) {
1100
+ throw Error(`createBinding: doc is null or undefined`);
1104
1101
  }
1105
1102
 
1106
1103
  const rootXmlText = doc.get('root', yjs.XmlText);
@@ -1231,6 +1228,13 @@ function updateCursor(binding, cursor, nextSelection, nodeMap) {
1231
1228
  return;
1232
1229
  }
1233
1230
 
1231
+ const cursorsContainerOffsetParent = cursorsContainer.offsetParent;
1232
+
1233
+ if (cursorsContainerOffsetParent === null) {
1234
+ return;
1235
+ }
1236
+
1237
+ const containerRect = cursorsContainerOffsetParent.getBoundingClientRect();
1234
1238
  const prevSelection = cursor.selection;
1235
1239
 
1236
1240
  if (nextSelection === null) {
@@ -1279,7 +1283,9 @@ function updateCursor(binding, cursor, nextSelection, nodeMap) {
1279
1283
  cursorsContainer.appendChild(selection);
1280
1284
  }
1281
1285
 
1282
- const style = `position:absolute;top:${selectionRect.top}px;left:${selectionRect.left}px;height:${selectionRect.height}px;width:${selectionRect.width}px;background-color:rgba(${color}, 0.3);pointer-events:none;z-index:5;`;
1286
+ const top = selectionRect.top - containerRect.top;
1287
+ const left = selectionRect.left - containerRect.left;
1288
+ const style = `position:absolute;top:${top}px;left:${left}px;height:${selectionRect.height}px;width:${selectionRect.width}px;background-color:rgba(${color}, 0.3);pointer-events:none;z-index:5;`;
1283
1289
  selection.style.cssText = style;
1284
1290
 
1285
1291
  if (i === selectionRectsLength - 1) {
@@ -1527,7 +1533,9 @@ function syncEvent(binding, event) {
1527
1533
  collabNode.syncPropertiesFromYjs(binding, attributesChanged);
1528
1534
  }
1529
1535
  } else {
1530
- throw new Error('Should never happen');
1536
+ {
1537
+ throw Error(`Expected text, element, or decorator event`);
1538
+ }
1531
1539
  }
1532
1540
  }
1533
1541
 
@@ -4,43 +4,41 @@
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
- 'use strict';var r=require("lexical"),v=require("yjs"),y=require("@lexical/selection"),A=require("@lexical/offset");class B{constructor(a,b){this._key="";this._map=a;this._parent=b;this._type="linebreak"}getNode(){let a=r.$getNodeByKey(this._key);return r.$isLineBreakNode(a)?a:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(a){a.collabNodeMap.delete(this._key)}}
8
- function C(a,b){b=new B(a,b);return a._collabNode=b}
9
- class D{constructor(a,b,c,d){this._key="";this._map=a;this._parent=c;this._text=b;this._type=d;this._normalized=!1}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return r.$isTextNode(a)?a:null}getNode(){let a=r.$getNodeByKey(this._key);return r.$isTextNode(a)?a:null}getSharedType(){return this._map}getType(){return this._type}getKey(){return this._key}getSize(){return this._text.length+(this._normalized?0:1)}getOffset(){return this._parent.getChildOffset(this)}spliceText(a,b,c){let d=this._parent._xmlText;
10
- a=this.getOffset()+1+a;0!==b&&d.delete(a,b);""!==c&&d.insert(a,c)}syncPropertiesAndTextFromLexical(a,b,c){var d=this.getPrevNode(c);c=b.__text;E(a,this._map,d,b);if(null!==d&&(a=d.__text,a!==c)){d=b.__key;b=a;var e=r.$getSelection();a=c.length;r.$isRangeSelection(e)&&e.isCollapsed()&&(e=e.anchor,e.key===d&&(a=e.offset));d=b.length;let f=c.length,h=e=0;for(;e<d&&e<f&&b[e]===c[e]&&e<a;)e++;for(;h+e<d&&h+e<f&&b[d-h-1]===c[f-h-1];)h++;for(;h+e<d&&h+e<f&&b[e]===c[e];)e++;b=e;a=c.slice(e,f-h);d=d-e-h;this.spliceText(b,
11
- d,a);this._text=c}}syncPropertiesAndTextFromYjs(a,b){let c=this.getNode();if(null===c)throw Error("Should never happen");F(a,this._map,c,b);a=this._text;c.__text!==a&&(c.getWritable().__text=a)}destroy(a){a.collabNodeMap.delete(this._key)}}function G(a,b,c,d){b=new D(a,b,c,d);return a._collabNode=b}let H=new Set(["__key","__children","__parent","__cachedText","__text"]);function I(a){a=r.$getNodeByKey(a);if(null===a)throw Error("Should never happen");return a}
12
- function J(a,b,c){let d=b.__type;if(r.$isElementNode(b)){var e=new v.XmlText;c=K(e,c,d);c.syncPropertiesFromLexical(a,b,null);c.syncChildrenFromLexical(a,b,null,null,null)}else if(r.$isTextNode(b))e=new v.Map,c=G(e,b.__text,c,d),c.syncPropertiesAndTextFromLexical(a,b,null);else if(r.$isLineBreakNode(b))a=new v.Map,a.set("__type","linebreak"),c=C(a,c);else if(r.$isDecoratorNode(b))e=new v.XmlElement,c=L(e,c,d),c.syncPropertiesFromLexical(a,b,null);else throw Error("Should never happen");c._key=b.__key;
13
- return c}
14
- function M(a,b,c){let d=b._collabNode;if(void 0===d){var e=a.editor._nodes;let f=b instanceof v.Map?b.get("__type"):b.getAttribute("__type");if(null==f)throw Error("Should never happen");if(void 0===e.get(f))throw Error("Should never happen");e=b.parent;a=void 0===c&&null!==e?M(a,e):c||null;if(!(a instanceof N))throw Error("Should never happen");if(b instanceof v.XmlText)return K(b,a,f);if(b instanceof v.Map){if(null===a)throw Error("Should never happen");return"linebreak"===f?C(b,a):G(b,"",a,f)}if(b instanceof
15
- v.XmlElement)return L(b,a,f)}return d}function F(a,b,c,d){d=null===d?b instanceof v.Map?Array.from(b.keys()):Object.keys(b.getAttributes()):Array.from(d);let e;for(let h=0;h<d.length;h++){let g=d[h];if(H.has(g))continue;var f=c[g];let k=b instanceof v.Map?b.get(g):b.getAttribute(g);if(f!==k){if(k instanceof v.Doc){let l=a.docMap;f instanceof v.Doc&&l.delete(f.guid);f=r.createEditor();let n=k.guid;f._key=n;l.set(n,k);k=f}void 0===e&&(e=c.getWritable());e[g]=k}}}
16
- function E(a,b,c,d){var e=d.__type,f=a.nodeProperties;let h=f.get(e);void 0===h&&(h=Object.keys(d).filter(k=>!H.has(k)),f.set(e,h));e=a.editor.constructor;for(f=0;f<h.length;f++){let k=h[f];var g=null===c?void 0:c[k];let l=d[k];if(g!==l){if(l instanceof e){let n=a.docMap,q;g instanceof e&&(g=g._key,q=n.get(g),n.delete(g));g=q||new v.Doc;let t=g.guid;l._key=t;n.set(t,g);l=g;a.editor.update(()=>{d.markDirty()})}b instanceof v.Map?b.set(k,l):b.setAttribute(k,l)}}}
17
- function O(a,b,c){let d=0,e=0,f=a._children,h=f.length;for(;e<h;e++){a=f[e];let g=d,k=a.getSize();d+=k;if((c?d>=b:d>b)&&a instanceof D)return c=b-g-1,0>c&&(c=0),{length:d-b,node:a,nodeIndex:e,offset:c};if(d>b)return{length:0,node:a,nodeIndex:e,offset:g};if(e===h-1)return{length:0,node:null,nodeIndex:e+1,offset:g+1}}return{length:0,node:null,nodeIndex:0,offset:0}}
18
- function P(a){let b=a.anchor;a=a.focus;let c=!1;try{let d=b.getNode(),e=a.getNode();if(!d.isAttached()||!e.isAttached()||r.$isTextNode(d)&&b.offset>d.getTextContentSize()||r.$isTextNode(e)&&a.offset>e.getTextContentSize())c=!0}catch(d){c=!0}return c}function ea(a,b){a.doc.transact(b,a)}
19
- class Q{constructor(a,b,c){this._key="";this._xmlElem=a;this._parent=b;this._type=c;this._unobservers=new Set}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return r.$isDecoratorNode(a)?a:null}getNode(){let a=r.$getNodeByKey(this._key);return r.$isDecoratorNode(a)?a:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}syncPropertiesFromLexical(a,b,c){c=this.getPrevNode(c);
20
- E(a,this._xmlElem,c,b)}syncPropertiesFromYjs(a,b){let c=this.getNode();if(null===c)throw Error("Should never happen");F(a,this._xmlElem,c,b)}destroy(a){a.collabNodeMap.delete(this._key);this._unobservers.forEach(b=>b());this._unobservers.clear()}}function L(a,b,c){b=new Q(a,b,c);return a._collabNode=b}
21
- class N{constructor(a,b,c){this._key="";this._children=[];this._xmlText=a;this._type=c;this._parent=b}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return r.$isElementNode(a)?a:null}getNode(){let a=r.$getNodeByKey(this._key);return r.$isElementNode(a)?a:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){let a=this._parent;if(null===a)throw Error("Should never happen");
22
- return a.getChildOffset(this)}syncPropertiesFromYjs(a,b){let c=this.getNode();if(null===c)throw this.getNode(),Error("Should never happen");F(a,this._xmlText,c,b)}applyChildrenYjsDelta(a,b){let c=this._children,d=0;for(let n=0;n<b.length;n++){var e=b[n],f=e.insert,h=e.delete;if(null!=e.retain)d+=e.retain;else if("number"===typeof h)for(f=h;0<f;){let {node:q,nodeIndex:t,offset:m,length:p}=O(this,d,!1);if(q instanceof N||q instanceof B||q instanceof Q)c.splice(t,1),--f;else if(q instanceof D){e=Math.min(f,
23
- p);h=0!==t?c[t-1]:null;var g=q.getSize();if(0===m&&1===e&&0<t&&h instanceof D&&p===g&&0===Array.from(q._map.keys()).length)h._text+=q._text,c.splice(t,1);else if(0===m&&e===g)c.splice(t,1);else{h=q;g=q._text;var k=m,l=e;g=g.slice(0,k)+""+g.slice(k+l);h._text=g}f-=e}else break}else if(null!=f)if("string"===typeof f){let {node:q,offset:t}=O(this,d,!0);q instanceof D?(e=q,h=q._text,g=t,k=f,h=h.slice(0,g)+k+h.slice(g+0),e._text=h):this._xmlText.delete(t,f.length);d+=f.length}else e=f,{nodeIndex:f}=O(this,
24
- d,!1),e=M(a,e,this),c.splice(f,0,e),d+=1;else throw Error("Unexpected delta format");}}syncChildrenFromYjs(a){var b=this.getNode();if(null===b)throw this.getNode(),Error("Should never happen");var c=b.__key;let d=b.__children;var e=[];let f=d.length,h=this._children,g=h.length,k=a.collabNodeMap,l=new Set,n,q;g!==f&&(q=R(b,q,e));let t=0;for(let z=0;z<g;z++){var m=d[t];let x=h[z];var p=x.getNode(),u=x._key;if(null!==p&&m===u){p=r.$isTextNode(p);l.add(m);if(p)if(x._key=m,x instanceof N)p=x._xmlText,
25
- x.syncPropertiesFromYjs(a,null),x.applyChildrenYjsDelta(a,p.toDelta()),x.syncChildrenFromYjs(a);else if(x instanceof D)x.syncPropertiesAndTextFromYjs(a,null);else if(x instanceof Q)x.syncPropertiesFromYjs(a,null);else if(!(x instanceof B))throw Error("Should never happen");e[z]=m;t++}else{if(void 0===n)for(n=new Set,u=0;u<g;u++){var w=h[u]._key;""!==w&&n.add(w)}if(null===p||void 0===m||n.has(m)){q=R(b,q,e);m=a;p=x;u=c;w=p.getType();w=m.editor._nodes.get(w);if(void 0===w)throw Error("createLexicalNode failed");
26
- w=new w.klass;w.__parent=u;p._key=w.__key;p instanceof N?(u=p._xmlText,p.syncPropertiesFromYjs(m,null),p.applyChildrenYjsDelta(m,u.toDelta()),p.syncChildrenFromYjs(m)):p instanceof D?p.syncPropertiesAndTextFromYjs(m,null):p instanceof Q&&p.syncPropertiesFromYjs(m,null);m.collabNodeMap.set(w.__key,p);m=w.__key;k.set(m,x);e[z]=m}else z--,t++}}for(b=0;b<f;b++)e=d[b],l.has(e)||(c=I(e).getWritable(),e=a.collabNodeMap.get(e),void 0!==e&&e.destroy(a),c.__parent=null)}syncPropertiesFromLexical(a,b,c){E(a,
27
- this._xmlText,this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=I(c);b instanceof N&&r.$isElementNode(c)?(b.syncPropertiesFromLexical(a,c,d),b.syncChildrenFromLexical(a,c,d,e,f)):b instanceof D&&r.$isTextNode(c)?b.syncPropertiesAndTextFromLexical(a,c,d):b instanceof Q&&r.$isDecoratorNode(c)&&b.syncPropertiesFromLexical(a,c,d)}syncChildrenFromLexical(a,b,c,d,e){var f=this.getPrevNode(c);let h=null===f?[]:f.__children;f=b.__children;let g=h.length-1,k=f.length-1,l=a.collabNodeMap,
28
- n,q,t=0;for(b=0;t<=g&&b<=k;){var m=h[t];let u=f[b];if(m===u)this._syncChildFromLexical(a,b,u,c,d,e),t++,b++;else{void 0===n&&(n=new Set(h));void 0===q&&(q=new Set(f));var p=q.has(m);m=n.has(u);p?(p=I(u),p=J(a,p,this),l.set(u,p),m?(this.splice(a,b,1,p),t++):this.splice(a,b,0,p),b++):(this.splice(a,b,1),t++)}}c=t>g;d=b>k;if(c&&!d)for(;b<=k;++b)c=f[b],d=I(c),d=J(a,d,this),this.append(d),l.set(c,d);else if(d&&!c)for(f=this._children.length-1;f>=b;f--)this.splice(a,f,1)}append(a){let b=this._xmlText;var c=
29
- this._children;c=c[c.length-1];c=void 0!==c?c.getOffset()+c.getSize():0;if(a instanceof N)b.insertEmbed(c,a._xmlText);else if(a instanceof D){let d=a._map;null===d.parent&&b.insertEmbed(c,d);b.insert(c+1,a._text)}else a instanceof B?b.insertEmbed(c,a._map):a instanceof Q&&b.insertEmbed(c,a._xmlElem);this._children.push(a)}splice(a,b,c,d){let e=this._children;var f=e[b];if(void 0===f)if(void 0!==d)this.append(d);else throw Error("Should never happen");else{var h=f.getOffset();if(-1===h)throw Error("Should never happen");
30
- var g=this._xmlText;0!==c&&g.delete(h,f.getSize());d instanceof N?g.insertEmbed(h,d._xmlText):d instanceof D?(f=d._map,null===f.parent&&g.insertEmbed(h,f),g.insert(h+1,d._text)):d instanceof B?g.insertEmbed(h,d._map):d instanceof Q&&g.insertEmbed(h,d._xmlElem);if(0!==c)for(h=e.slice(b,b+c),g=0;g<h.length;g++)h[g].destroy(a);void 0!==d?e.splice(b,c,d):e.splice(b,c)}}getChildOffset(a){let b=0,c=this._children;for(let d=0;d<c.length;d++){let e=c[d];if(e===a)return b;b+=e.getSize()}return-1}destroy(a){let b=
31
- a.collabNodeMap,c=this._children;for(let d=0;d<c.length;d++)c[d].destroy(a);b.delete(this._key)}}function R(a,b,c){return void 0===b?(a=a.getWritable(),a.__children=c,a):b}function K(a,b,c){b=new N(a,b,c);return a._collabNode=b}function S(a,b){b=b.collabNodeMap.get(a.key);if(void 0===b)return null;a=a.offset;let c=b.getSharedType();if(b instanceof D){c=b._parent._xmlText;b=b.getOffset();if(-1===b)return null;a=b+1+a}return v.createRelativePositionFromTypeIndex(c,a)}
32
- function T(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!v.compareRelativePositions(a,b))return!0;return!1}function U(a,b){a=a.cursorsContainer;if(null!==a){b=b.selections;let c=b.length;for(let d=0;d<c;d++)a.removeChild(b[d])}}
33
- function V(a,b){var c=b.awareness.getLocalState();if(null!==c&&(b=c.anchorPos,c=c.focusPos,null!==b&&null!==c&&(b=v.createAbsolutePositionFromRelativePosition(b,a.doc),a=v.createAbsolutePositionFromRelativePosition(c,a.doc),null!==b&&null!==a))){let [e,f]=W(b.type,b.index),[h,g]=W(a.type,a.index);if(null!==e&&null!==h){let k=e.getKey();a=h.getKey();b=r.$getSelection();if(r.$isRangeSelection(b)){var d=b.anchor;c=b.focus;if(d.key!==k||d.offset!==f)d=r.$getNodeByKey(k),b.anchor.set(k,f,r.$isElementNode(d)?
34
- "element":"text");if(c.key!==a||c.offset!==g)c=r.$getNodeByKey(a),b.focus.set(a,g,r.$isElementNode(c)?"element":"text")}}}}function W(a,b){a=a._collabNode;if(void 0===a)return[null,0];if(a instanceof N){let {node:c,offset:d}=O(a,b,!0);return null===c?[a,0]:[c,d]}return[null,0]}
35
- function X(a,b){var c=Array.from(b.awareness.getStates()),d=a.clientID;b=a.cursors;var e=a.editor._editorState._nodeMap;let f=new Set;for(var h=0;h<c.length;h++){let [z,x]=c[h];if(z!==d){f.add(z);let {anchorPos:Y,focusPos:Z,name:ha,color:ia,focusing:ja}=x;var g=null,k=b.get(z);void 0===k&&(k={color:ia,name:ha,selection:null},b.set(z,k));if(null!==Y&&null!==Z&&ja){var l=v.createAbsolutePositionFromRelativePosition(Y,a.doc),n=v.createAbsolutePositionFromRelativePosition(Z,a.doc);if(null!==l&&null!==
36
- n){let [aa,ba]=W(l.type,l.index),[ca,da]=W(n.type,n.index);if(null!==aa&&null!==ca){n=aa.getKey();var q=ca.getKey();g=k.selection;if(null===g){l=k;g=n;n=ba;var t=da,m=l.color,p=document.createElement("span");p.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:rgb(${m});z-index:10;`;var u=document.createElement("span");u.textContent=l.name;u.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:rgb(${m});color:#fff;line-height:12px;height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`;
37
- p.appendChild(u);g={anchor:{key:g,offset:n},caret:p,color:m,focus:{key:q,offset:t},name:u,selections:[]}}else l=g.anchor,t=g.focus,l.key=n,l.offset=ba,t.key=q,t.offset=da}}}l=a;n=k;m=g;t=e;q=l.editor;g=q.getRootElement();k=l.cursorsContainer;if(null!==k&&null!==g)if(g=n.selection,null===m)null!==g&&(n.selection=null,U(l,g));else{n.selection=m;g=m.caret;n=m.color;l=m.selections;p=m.anchor;m=m.focus;var w=m.key;u=t.get(p.key);t=t.get(w);if(null!=u&&null!=t&&(m=y.createDOMRange(q,u,p.offset,t,m.offset),
38
- null!==m)){t=l.length;m=y.createRectsFromDOMRange(q,m);q=m.length;for(p=0;p<q;p++)u=m[p],w=l[p],void 0===w&&(w=document.createElement("span"),l[p]=w,k.appendChild(w)),w.style.cssText=`position:absolute;top:${u.top}px;left:${u.left}px;height:${u.height}px;width:${u.width}px;background-color:rgba(${n}, 0.3);pointer-events:none;z-index:5;`,p===q-1&&g.parentNode!==w&&w.appendChild(g);for(g=t-1;g>=q;g--)k.removeChild(l[g]),l.pop()}}}}c=Array.from(b.keys());for(d=0;d<c.length;d++)e=c[d],f.has(e)||(h=b.get(e),
39
- void 0!==h&&(h=h.selection,null!==h&&U(a,h),b.delete(e)))}function fa(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:h,name:g,color:k,focusing:l}=e,n=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)r.$isRangeSelection(d)&&(e=S(d.anchor,a),n=S(d.focus,a)),(T(f,e)||T(h,n))&&b.setLocalState({anchorPos:e,color:k,focusPos:n,focusing:l,name:g})}}let ka=r.createCommand(),la=r.createCommand();exports.CONNECTED_COMMAND=ka;exports.TOGGLE_CONNECT_COMMAND=la;
40
- exports.createBinding=function(a,b,c,d,e){if(void 0===d||null===d)throw Error("Should never happen");b=d.get("root",v.XmlText);b=K(b,null,"root");b._key="root";return{clientID:d.clientID,collabNodeMap:new Map,cursors:new Map,cursorsContainer:null,doc:d,docMap:e,editor:a,id:c,nodeProperties:new Map,root:b}};exports.createUndoManager=function(a,b){return new v.UndoManager(b,{trackedOrigins:new Set([a,null])})};
41
- exports.initLocalState=function(a,b,c,d){a.awareness.setLocalState({anchorPos:null,color:c,focusPos:null,focusing:d,name:b})};exports.setLocalStateFocus=function(a,b,c,d){({awareness:a}=a);let e=a.getLocalState();null===e&&(e={anchorPos:null,color:c,focusPos:null,focusing:d,name:b});e.focusing=d;a.setLocalState(e)};exports.syncCursorPositions=X;
42
- exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,h,g){ea(a,()=>{d.read(()=>{if(g.has("collaboration")){if(0<h.size){var k=Array.from(h),l=a.collabNodeMap,n=[];for(let p=0;p<k.length;p++){var q=k[p],t=r.$getNodeByKey(q),m=l.get(q);if(m instanceof D)if(r.$isTextNode(t))n.push([m,t.__text]);else{t=m.getOffset();if(-1===t)continue;let u=m._parent;m._normalized=!0;u._xmlText.delete(t,1);l.delete(q);q=u._children;m=q.indexOf(m);q.splice(m,1)}}for(k=0;k<n.length;k++){let [p,u]=n[k];p instanceof D&&"string"===
43
- typeof u&&(p._text=u)}}}else e.has("root")&&(n=c._nodeMap,k=r.$getRoot(),l=a.root,l.syncPropertiesFromLexical(a,k,n),l.syncChildrenFromLexical(a,k,n,e,f)),n=r.$getSelection(),fa(a,b,c._selection,n)})})};
44
- exports.syncYjsChangesToLexical=function(a,b,c){let d=a.editor,e=d._editorState;d.update(()=>{var f=d._pendingEditorState;for(var h=0;h<c.length;h++){var g=a,k=c[h],{target:l}=k;l=M(g,l);if(l instanceof N&&k instanceof v.YTextEvent){let {keysChanged:n,childListChanged:q,delta:t}=k;0<n.size&&l.syncPropertiesFromYjs(g,n);q&&(l.applyChildrenYjsDelta(g,t),l.syncChildrenFromYjs(g))}else if(l instanceof D&&k instanceof v.YMapEvent)({keysChanged:k}=k),0<k.size&&l.syncPropertiesAndTextFromYjs(g,k);else if(l instanceof
45
- Q&&k instanceof v.YXmlEvent)({attributesChanged:k}=k),0<k.size&&l.syncPropertiesFromYjs(g,k);else throw Error("Should never happen");}h=r.$getSelection();if(r.$isRangeSelection(h))if(P(h)){g=e._selection;if(r.$isRangeSelection(g)){l=A.$createOffsetView(d,0,e);f=A.$createOffsetView(d,0,f);let [n,q]=l.getOffsetsFromSelection(g);f=f.createSelectionFromOffsets(n,q,l);null!==f?r.$setSelection(f):(V(a,b),P(h)&&(f=r.$getRoot(),0===f.getChildrenSize()&&f.append(r.$createParagraphNode()),r.$getRoot().selectEnd()))}fa(a,
46
- b,g,r.$getSelection())}else V(a,b)},{onUpdate:()=>{X(a,b)},skipTransforms:!0,tag:"collaboration"})}
7
+ 'use strict';var q=require("lexical"),v=require("yjs"),y=require("@lexical/selection"),z=require("@lexical/offset");function B(a){throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?code=${a} 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(){let 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 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 q.$isTextNode(a)?a:null}getNode(){let 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){let d=this._parent._xmlText;
10
+ a=this.getOffset()+1+a;0!==b&&d.delete(a,b);""!==c&&d.insert(a,c)}syncPropertiesAndTextFromLexical(a,b,c){var d=this.getPrevNode(c);c=b.__text;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;let g=c.length,h=e=0;for(;e<d&&e<g&&b[e]===c[e]&&e<a;)e++;for(;h+e<d&&h+e<g&&b[d-h-1]===c[g-h-1];)h++;for(;h+e<d&&h+e<g&&b[e]===c[e];)e++;b=e;a=c.slice(e,g-h);d=d-e-h;this.spliceText(b,
11
+ d,a);this._text=c}}syncPropertiesAndTextFromYjs(a,b){let c=this.getNode();null===c&&B(84);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 E(a,b,c,d);return a._collabNode=b}let I=new Set(["__key","__children","__parent","__cachedText","__text"]);function J(a){a=q.$getNodeByKey(a);null===a&&B(85);return a}
12
+ function K(a,b,c){let d=b.__type;if(q.$isElementNode(b)){var e=new v.XmlText;e=L(e,c,d);e.syncPropertiesFromLexical(a,b,null);e.syncChildrenFromLexical(a,b,null,null,null)}else q.$isTextNode(b)?(e=new v.Map,e=H(e,b.__text,c,d),e.syncPropertiesAndTextFromLexical(a,b,null)):q.$isLineBreakNode(b)?(a=new v.Map,a.set("__type","linebreak"),e=D(a,c)):q.$isDecoratorNode(b)?(e=new v.XmlElement,e=M(e,c,d),e.syncPropertiesFromLexical(a,b,null)):B(86);e._key=b.__key;return e}
13
+ function N(a,b,c){let d=b._collabNode;if(void 0===d){var e=a.editor._nodes;let g=b instanceof v.Map?b.get("__type"):b.getAttribute("__type");null==g&&B(87);void 0===e.get(g)&&B(88);e=b.parent;a=void 0===c&&null!==e?N(a,e):c||null;a instanceof O||B(89);if(b instanceof v.XmlText)return L(b,a,g);if(b instanceof v.Map)return"linebreak"===g?D(b,a):H(b,"",a,g);if(b instanceof v.XmlElement)return M(b,a,g)}return d}
14
+ function G(a,b,c,d){d=null===d?b instanceof v.Map?Array.from(b.keys()):Object.keys(b.getAttributes()):Array.from(d);let e;for(let h=0;h<d.length;h++){let f=d[h];if(I.has(f))continue;var g=c[f];let k=b instanceof v.Map?b.get(f):b.getAttribute(f);if(g!==k){if(k instanceof v.Doc){let m=a.docMap;g instanceof v.Doc&&m.delete(g.guid);g=q.createEditor();let n=k.guid;g._key=n;m.set(n,k);k=g}void 0===e&&(e=c.getWritable());e[f]=k}}}
15
+ function F(a,b,c,d){var e=d.__type,g=a.nodeProperties;let h=g.get(e);void 0===h&&(h=Object.keys(d).filter(k=>!I.has(k)),g.set(e,h));e=a.editor.constructor;for(g=0;g<h.length;g++){let k=h[g];var f=null===c?void 0:c[k];let m=d[k];if(f!==m){if(m instanceof e){let n=a.docMap,r;f instanceof e&&(f=f._key,r=n.get(f),n.delete(f));f=r||new v.Doc;let t=f.guid;m._key=t;n.set(t,f);m=f;a.editor.update(()=>{d.markDirty()})}b instanceof v.Map?b.set(k,m):b.setAttribute(k,m)}}}
16
+ function P(a,b,c){let d=0,e=0,g=a._children,h=g.length;for(;e<h;e++){a=g[e];let f=d,k=a.getSize();d+=k;if((c?d>=b:d>b)&&a instanceof E)return c=b-f-1,0>c&&(c=0),{length:d-b,node:a,nodeIndex:e,offset:c};if(d>b)return{length:0,node:a,nodeIndex:e,offset:f};if(e===h-1)return{length:0,node:null,nodeIndex:e+1,offset:f+1}}return{length:0,node:null,nodeIndex:0,offset:0}}
17
+ function Q(a){let b=a.anchor;a=a.focus;let c=!1;try{let 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 fa(a,b){a.doc.transact(b,a)}
18
+ class R{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(){let 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);
19
+ F(a,this._xmlElem,c,b)}syncPropertiesFromYjs(a,b){let c=this.getNode();null===c&&B(83);G(a,this._xmlElem,c,b)}destroy(a){a.collabNodeMap.delete(this._key);this._unobservers.forEach(b=>b());this._unobservers.clear()}}function M(a,b,c){b=new R(a,b,c);return a._collabNode=b}
20
+ 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 q.$isElementNode(a)?a:null}getNode(){let 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(){let a=this._parent;null===a&&B(90);return a.getChildOffset(this)}syncPropertiesFromYjs(a,
21
+ b){let c=this.getNode();null===c&&B(91);G(a,this._xmlText,c,b)}applyChildrenYjsDelta(a,b){let c=this._children,d=0;for(let n=0;n<b.length;n++){var e=b[n],g=e.insert,h=e.delete;if(null!=e.retain)d+=e.retain;else if("number"===typeof h)for(g=h;0<g;){let {node:r,nodeIndex:t,offset:p,length:l}=P(this,d,!1);if(r instanceof O||r instanceof C||r instanceof R)c.splice(t,1),--g;else if(r instanceof E){e=Math.min(g,l);h=0!==t?c[t-1]:null;var f=r.getSize();if(0===p&&1===e&&0<t&&h instanceof E&&l===f&&0===Array.from(r._map.keys()).length)h._text+=
22
+ r._text,c.splice(t,1);else if(0===p&&e===f)c.splice(t,1);else{h=r;f=r._text;var k=p,m=e;f=f.slice(0,k)+""+f.slice(k+m);h._text=f}g-=e}else break}else if(null!=g)if("string"===typeof g){let {node:r,offset:t}=P(this,d,!0);r instanceof E?(e=r,h=r._text,f=t,k=g,h=h.slice(0,f)+k+h.slice(f+0),e._text=h):this._xmlText.delete(t,g.length);d+=g.length}else e=g,{nodeIndex:g}=P(this,d,!1),e=N(a,e,this),c.splice(g,0,e),d+=1;else throw Error("Unexpected delta format");}}syncChildrenFromYjs(a){var b=this.getNode();
23
+ null===b&&B(92);var c=b.__key;let d=b.__children;var e=[];let g=d.length,h=this._children,f=h.length,k=a.collabNodeMap,m=new Set,n,r;f!==g&&(r=S(b,r,e));let t=0;for(let A=0;A<f;A++){var p=d[t];let x=h[A];var l=x.getNode(),u=x._key;if(null!==l&&p===u)l=q.$isTextNode(l),m.add(p),l&&(x._key=p,x instanceof O?(l=x._xmlText,x.syncPropertiesFromYjs(a,null),x.applyChildrenYjsDelta(a,l.toDelta()),x.syncChildrenFromYjs(a)):x instanceof E?x.syncPropertiesAndTextFromYjs(a,null):x instanceof R?x.syncPropertiesFromYjs(a,
24
+ null):x instanceof C||B(93)),e[A]=p,t++;else{if(void 0===n)for(n=new Set,u=0;u<f;u++){var w=h[u]._key;""!==w&&n.add(w)}null===l||void 0===p||n.has(p)?(r=S(b,r,e),p=a,l=x,u=c,w=l.getType(),w=p.editor._nodes.get(w),void 0===w&&B(88),w=new w.klass,w.__parent=u,l._key=w.__key,l instanceof O?(u=l._xmlText,l.syncPropertiesFromYjs(p,null),l.applyChildrenYjsDelta(p,u.toDelta()),l.syncChildrenFromYjs(p)):l instanceof E?l.syncPropertiesAndTextFromYjs(p,null):l instanceof R&&l.syncPropertiesFromYjs(p,null),
25
+ p.collabNodeMap.set(w.__key,l),p=w.__key,k.set(p,x),e[A]=p):(A--,t++)}}for(b=0;b<g;b++)e=d[b],m.has(e)||(c=J(e).getWritable(),e=a.collabNodeMap.get(e),void 0!==e&&e.destroy(a),c.__parent=null)}syncPropertiesFromLexical(a,b,c){F(a,this._xmlText,this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,g){b=this._children[b];c=J(c);b instanceof O&&q.$isElementNode(c)?(b.syncPropertiesFromLexical(a,c,d),b.syncChildrenFromLexical(a,c,d,e,g)):b instanceof E&&q.$isTextNode(c)?b.syncPropertiesAndTextFromLexical(a,
26
+ c,d):b instanceof R&&q.$isDecoratorNode(c)&&b.syncPropertiesFromLexical(a,c,d)}syncChildrenFromLexical(a,b,c,d,e){var g=this.getPrevNode(c);let h=null===g?[]:g.__children;g=b.__children;let f=h.length-1,k=g.length-1,m=a.collabNodeMap,n,r,t=0;for(b=0;t<=f&&b<=k;){var p=h[t];let u=g[b];if(p===u)this._syncChildFromLexical(a,b,u,c,d,e),t++,b++;else{void 0===n&&(n=new Set(h));void 0===r&&(r=new Set(g));var l=r.has(p);p=n.has(u);l?(l=J(u),l=K(a,l,this),m.set(u,l),p?(this.splice(a,b,1,l),t++):this.splice(a,
27
+ b,0,l),b++):(this.splice(a,b,1),t++)}}c=t>f;d=b>k;if(c&&!d)for(;b<=k;++b)c=g[b],d=J(c),d=K(a,d,this),this.append(d),m.set(c,d);else if(d&&!c)for(g=this._children.length-1;g>=b;g--)this.splice(a,g,1)}append(a){let b=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){let 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
28
+ R&&b.insertEmbed(c,a._xmlElem);this._children.push(a)}splice(a,b,c,d){let e=this._children;var g=e[b];if(void 0===g)void 0===d&&B(94),this.append(d);else{var h=g.getOffset();-1===h&&B(95);var f=this._xmlText;0!==c&&f.delete(h,g.getSize());d instanceof O?f.insertEmbed(h,d._xmlText):d instanceof E?(g=d._map,null===g.parent&&f.insertEmbed(h,g),f.insert(h+1,d._text)):d instanceof C?f.insertEmbed(h,d._map):d instanceof R&&f.insertEmbed(h,d._xmlElem);if(0!==c)for(h=e.slice(b,b+c),f=0;f<h.length;f++)h[f].destroy(a);
29
+ void 0!==d?e.splice(b,c,d):e.splice(b,c)}}getChildOffset(a){let b=0,c=this._children;for(let d=0;d<c.length;d++){let e=c[d];if(e===a)return b;b+=e.getSize()}return-1}destroy(a){let b=a.collabNodeMap,c=this._children;for(let d=0;d<c.length;d++)c[d].destroy(a);b.delete(this._key)}}function S(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}
30
+ function T(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 v.createRelativePositionFromTypeIndex(c,a)}function U(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!v.compareRelativePositions(a,b))return!0;return!1}function V(a,b){a=a.cursorsContainer;if(null!==a){b=b.selections;let c=b.length;for(let d=0;d<c;d++)a.removeChild(b[d])}}
31
+ function W(a,b){var c=b.awareness.getLocalState();if(null!==c&&(b=c.anchorPos,c=c.focusPos,null!==b&&null!==c&&(b=v.createAbsolutePositionFromRelativePosition(b,a.doc),a=v.createAbsolutePositionFromRelativePosition(c,a.doc),null!==b&&null!==a))){let [e,g]=X(b.type,b.index),[h,f]=X(a.type,a.index);if(null!==e&&null!==h){let 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!==g)d=q.$getNodeByKey(k),b.anchor.set(k,g,q.$isElementNode(d)?
32
+ "element":"text");if(c.key!==a||c.offset!==f)c=q.$getNodeByKey(a),b.focus.set(a,f,q.$isElementNode(c)?"element":"text")}}}}function X(a,b){a=a._collabNode;if(void 0===a)return[null,0];if(a instanceof O){let {node:c,offset:d}=P(a,b,!0);return null===c?[a,0]:[c,d]}return[null,0]}
33
+ function Y(a,b){var c=Array.from(b.awareness.getStates()),d=a.clientID;b=a.cursors;var e=a.editor._editorState._nodeMap;let g=new Set;for(var h=0;h<c.length;h++){let [x,ia]=c[h];if(x!==d){g.add(x);let {anchorPos:Z,focusPos:aa,name:ja,color:ka,focusing:la}=ia;var f=null,k=b.get(x);void 0===k&&(k={color:ka,name:ja,selection:null},b.set(x,k));if(null!==Z&&null!==aa&&la){var m=v.createAbsolutePositionFromRelativePosition(Z,a.doc),n=v.createAbsolutePositionFromRelativePosition(aa,a.doc);if(null!==m&&null!==
34
+ n){let [ba,ca]=X(m.type,m.index),[da,ea]=X(n.type,n.index);if(null!==ba&&null!==da){m=ba.getKey();var r=da.getKey();f=k.selection;if(null===f){f=k;n=ca;var t=ea,p=f.color,l=document.createElement("span");l.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:rgb(${p});z-index:10;`;var u=document.createElement("span");u.textContent=f.name;u.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;`;
35
+ l.appendChild(u);f={anchor:{key:m,offset:n},caret:l,color:p,focus:{key:r,offset:t},name:u,selections:[]}}else n=f.anchor,t=f.focus,n.key=m,n.offset=ca,t.key=r,t.offset=ea}}}m=a;n=k;l=f;p=e;t=m.editor;f=t.getRootElement();k=m.cursorsContainer;if(null!==k&&null!==f&&(f=k.offsetParent,null!==f))if(f=f.getBoundingClientRect(),r=n.selection,null===l)null!==r&&(n.selection=null,V(m,r));else{n.selection=l;n=l.caret;r=l.color;m=l.selections;u=l.anchor;l=l.focus;var w=l.key,A=p.get(u.key);p=p.get(w);if(null!=
36
+ A&&null!=p&&(l=y.createDOMRange(t,A,u.offset,p,l.offset),null!==l)){p=m.length;l=y.createRectsFromDOMRange(t,l);t=l.length;for(u=0;u<t;u++)A=l[u],w=m[u],void 0===w&&(w=document.createElement("span"),m[u]=w,k.appendChild(w)),w.style.cssText=`position:absolute;top:${A.top-f.top}px;left:${A.left-f.left}px;height:${A.height}px;width:${A.width}px;background-color:rgba(${r}, 0.3);pointer-events:none;z-index:5;`,u===t-1&&n.parentNode!==w&&w.appendChild(n);for(f=p-1;f>=t;f--)k.removeChild(m[f]),m.pop()}}}}c=
37
+ Array.from(b.keys());for(d=0;d<c.length;d++)e=c[d],g.has(e)||(h=b.get(e),void 0!==h&&(h=h.selection,null!==h&&V(a,h),b.delete(e)))}function ha(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:g,focusPos:h,name:f,color:k,focusing:m}=e,n=e=null;if(null!==d&&(null===g||d.is(c))||null!==c)q.$isRangeSelection(d)&&(e=T(d.anchor,a),n=T(d.focus,a)),(U(g,e)||U(h,n))&&b.setLocalState({anchorPos:e,color:k,focusPos:n,focusing:m,name:f})}}let ma=q.createCommand(),na=q.createCommand();
38
+ exports.CONNECTED_COMMAND=ma;exports.TOGGLE_CONNECT_COMMAND=na;exports.createBinding=function(a,b,c,d,e){void 0!==d&&null!==d||B(81);b=d.get("root",v.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}};exports.createUndoManager=function(a,b){return new v.UndoManager(b,{trackedOrigins:new Set([a,null])})};
39
+ 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=Y;
40
+ exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,g,h,f){fa(a,()=>{d.read(()=>{if(f.has("collaboration")){if(0<h.size){var k=Array.from(h),m=a.collabNodeMap,n=[];for(let l=0;l<k.length;l++){var r=k[l],t=q.$getNodeByKey(r),p=m.get(r);if(p instanceof E)if(q.$isTextNode(t))n.push([p,t.__text]);else{t=p.getOffset();if(-1===t)continue;let u=p._parent;p._normalized=!0;u._xmlText.delete(t,1);m.delete(r);r=u._children;p=r.indexOf(p);r.splice(p,1)}}for(k=0;k<n.length;k++){let [l,u]=n[k];l instanceof E&&"string"===
41
+ typeof u&&(l._text=u)}}}else e.has("root")&&(n=c._nodeMap,k=q.$getRoot(),m=a.root,m.syncPropertiesFromLexical(a,k,n),m.syncChildrenFromLexical(a,k,n,e,g)),n=q.$getSelection(),ha(a,b,c._selection,n)})})};
42
+ exports.syncYjsChangesToLexical=function(a,b,c){let d=a.editor,e=d._editorState;d.update(()=>{var g=d._pendingEditorState;for(var h=0;h<c.length;h++){var f=a,k=c[h],{target:m}=k;m=N(f,m);if(m instanceof O&&k instanceof v.YTextEvent){let {keysChanged:n,childListChanged:r,delta:t}=k;0<n.size&&m.syncPropertiesFromYjs(f,n);r&&(m.applyChildrenYjsDelta(f,t),m.syncChildrenFromYjs(f))}else m instanceof E&&k instanceof v.YMapEvent?({keysChanged:k}=k,0<k.size&&m.syncPropertiesAndTextFromYjs(f,k)):m instanceof
43
+ R&&k instanceof v.YXmlEvent?({attributesChanged:k}=k,0<k.size&&m.syncPropertiesFromYjs(f,k)):B(82)}h=q.$getSelection();if(q.$isRangeSelection(h))if(Q(h)){f=e._selection;if(q.$isRangeSelection(f)){m=z.$createOffsetView(d,0,e);g=z.$createOffsetView(d,0,g);let [n,r]=m.getOffsetsFromSelection(f);g=g.createSelectionFromOffsets(n,r,m);null!==g?q.$setSelection(g):(W(a,b),Q(h)&&(g=q.$getRoot(),0===g.getChildrenSize()&&g.append(q.$createParagraphNode()),q.$getRoot().selectEnd()))}ha(a,b,f,q.$getSelection())}else W(a,
44
+ b)},{onUpdate:()=>{Y(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.4.1",
14
+ "version": "0.5.0",
15
15
  "main": "LexicalYjs.js",
16
16
  "dependencies": {
17
- "@lexical/offset": "0.4.1"
17
+ "@lexical/offset": "0.5.0"
18
18
  },
19
19
  "peerDependencies": {
20
- "lexical": "0.4.1",
20
+ "lexical": "0.5.0",
21
21
  "yjs": ">=13.5.22"
22
22
  },
23
23
  "repository": {