@lexical/yjs 0.5.1-next.1 → 0.5.1-next.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
@@ -1198,10 +1198,10 @@ function destroyCursor(binding, cursor) {
1198
1198
  function createCursorSelection(cursor, anchorKey, anchorOffset, focusKey, focusOffset) {
1199
1199
  const color = cursor.color;
1200
1200
  const caret = document.createElement('span');
1201
- caret.style.cssText = `position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:rgb(${color});z-index:10;`;
1201
+ caret.style.cssText = `position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${color};z-index:10;`;
1202
1202
  const name = document.createElement('span');
1203
1203
  name.textContent = cursor.name;
1204
- name.style.cssText = `position:absolute;left:-2px;top:-16px;background-color:rgb(${color});color:#fff;line-height:12px;height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`;
1204
+ name.style.cssText = `position:absolute;left:-2px;top:-16px;background-color:${color};color:#fff;line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`;
1205
1205
  caret.appendChild(name);
1206
1206
  return {
1207
1207
  anchor: {
@@ -1280,13 +1280,16 @@ function updateCursor(binding, cursor, nextSelection, nodeMap) {
1280
1280
  if (selection === undefined) {
1281
1281
  selection = document.createElement('span');
1282
1282
  selections[i] = selection;
1283
+ const selectionBg = document.createElement('span');
1284
+ selection.appendChild(selectionBg);
1283
1285
  cursorsContainer.appendChild(selection);
1284
1286
  }
1285
1287
 
1286
1288
  const top = selectionRect.top - containerRect.top;
1287
1289
  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;`;
1290
+ const style = `position:absolute;top:${top}px;left:${left}px;height:${selectionRect.height}px;width:${selectionRect.width}px;pointer-events:none;z-index:5;`;
1289
1291
  selection.style.cssText = style;
1292
+ selection.firstChild.style.cssText = `${style}left:0;top:0;background-color:${color};opacity:0.3;`;
1290
1293
 
1291
1294
  if (i === selectionRectsLength - 1) {
1292
1295
  if (caret.parentNode !== selection) {
@@ -4,41 +4,42 @@
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 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.");}
7
+ 'use strict';var q=require("lexical"),v=require("yjs"),z=require("@lexical/selection"),A=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
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
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
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})}}
38
- let ma=q.createCommand("CONNECTED_COMMAND"),na=q.createCommand("TOGGLE_CONNECT_COMMAND");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}};
39
- exports.createUndoManager=function(a,b){return new v.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=Y;
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 I(a,b,c,d){b=new E(a,b,c,d);return a._collabNode=b}let J=new Set(["__key","__children","__parent","__cachedText","__text"]);function K(a){a=q.$getNodeByKey(a);null===a&&B(85);return a}
12
+ function L(a,b,c){let d=b.__type;if(q.$isElementNode(b)){var e=new v.XmlText;e=M(e,c,d);e.syncPropertiesFromLexical(a,b,null);e.syncChildrenFromLexical(a,b,null,null,null)}else q.$isTextNode(b)?(e=new v.Map,e=I(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=N(e,c,d),e.syncPropertiesFromLexical(a,b,null)):B(86);e._key=b.__key;return e}
13
+ function O(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?O(a,e):c||null;a instanceof P||B(89);if(b instanceof v.XmlText)return M(b,a,g);if(b instanceof v.Map)return"linebreak"===g?D(b,a):I(b,"",a,g);if(b instanceof v.XmlElement)return N(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(J.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=>!J.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 Q(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 R(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 S{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 N(a,b,c){b=new S(a,b,c);return a._collabNode=b}
20
+ class P{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}=Q(this,d,!1);if(r instanceof P||r instanceof C||r instanceof S)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}=Q(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}=Q(this,d,!1),e=O(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=T(b,r,e));let t=0;for(let y=0;y<f;y++){var p=d[t];let x=h[y];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 P?(l=x._xmlText,x.syncPropertiesFromYjs(a,null),x.applyChildrenYjsDelta(a,l.toDelta()),x.syncChildrenFromYjs(a)):x instanceof E?x.syncPropertiesAndTextFromYjs(a,null):x instanceof S?x.syncPropertiesFromYjs(a,
24
+ null):x instanceof C||B(93)),e[y]=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=T(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 P?(u=l._xmlText,l.syncPropertiesFromYjs(p,null),l.applyChildrenYjsDelta(p,u.toDelta()),l.syncChildrenFromYjs(p)):l instanceof E?l.syncPropertiesAndTextFromYjs(p,null):l instanceof S&&l.syncPropertiesFromYjs(p,null),
25
+ p.collabNodeMap.set(w.__key,l),p=w.__key,k.set(p,x),e[y]=p):(y--,t++)}}for(b=0;b<g;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,this._xmlText,this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,g){b=this._children[b];c=K(c);b instanceof P&&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 S&&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=K(u),l=L(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=K(c),d=L(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 P)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
+ S&&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 P?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 S&&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 T(a,b,c){return void 0===b?(a=a.getWritable(),a.__children=c,a):b}function M(a,b,c){b=new P(a,b,c);return a._collabNode=b}
30
+ function U(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 V(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!v.compareRelativePositions(a,b))return!0;return!1}function W(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 X(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]=Y(b.type,b.index),[h,f]=Y(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 Y(a,b){a=a._collabNode;if(void 0===a)return[null,0];if(a instanceof P){let {node:c,offset:d}=Q(a,b,!0);return null===c?[a,0]:[c,d]}return[null,0]}
33
+ function Z(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:aa,focusPos:ba,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!==aa&&null!==ba&&la){var m=v.createAbsolutePositionFromRelativePosition(aa,a.doc),n=v.createAbsolutePositionFromRelativePosition(ba,a.doc);if(null!==m&&
34
+ null!==n){let [H,ca]=Y(m.type,m.index),[da,ea]=Y(n.type,n.index);if(null!==H&&null!==da){m=H.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:${p};z-index:10;`;var u=document.createElement("span");u.textContent=f.name;u.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${p};color:#fff;line-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,W(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,y=p.get(u.key);p=p.get(w);if(null!=
36
+ y&&null!=p&&(l=z.createDOMRange(t,y,u.offset,p,l.offset),null!==l)){p=m.length;l=z.createRectsFromDOMRange(t,l);t=l.length;for(u=0;u<t;u++){w=l[u];y=m[u];if(void 0===y){y=document.createElement("span");m[u]=y;let H=document.createElement("span");y.appendChild(H);k.appendChild(y)}w=`position:absolute;top:${w.top-f.top}px;left:${w.left-f.left}px;height:${w.height}px;width:${w.width}px;pointer-events:none;z-index:5;`;y.style.cssText=w;y.firstChild.style.cssText=`${w}left:0;top:0;background-color:${r};opacity:0.3;`;
37
+ u===t-1&&n.parentNode!==y&&y.appendChild(n)}for(f=p-1;f>=t;f--)k.removeChild(m[f]),m.pop()}}}}c=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&&W(a,h),b.delete(e)))}
38
+ 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=U(d.anchor,a),n=U(d.focus,a)),(V(g,e)||V(h,n))&&b.setLocalState({anchorPos:e,color:k,focusPos:n,focusing:m,name:f})}}let ma=q.createCommand("CONNECTED_COMMAND"),na=q.createCommand("TOGGLE_CONNECT_COMMAND");exports.CONNECTED_COMMAND=ma;exports.TOGGLE_CONNECT_COMMAND=na;
39
+ exports.createBinding=function(a,b,c,d,e){void 0!==d&&null!==d||B(81);b=d.get("root",v.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 v.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})};
40
+ 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=Z;
40
41
  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
42
  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"})}
43
+ 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=O(f,m);if(m instanceof P&&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
44
+ S&&k instanceof v.YXmlEvent?({attributesChanged:k}=k,0<k.size&&m.syncPropertiesFromYjs(f,k)):B(82)}h=q.$getSelection();if(q.$isRangeSelection(h))if(R(h)){f=e._selection;if(q.$isRangeSelection(f)){m=A.$createOffsetView(d,0,e);g=A.$createOffsetView(d,0,g);let [n,r]=m.getOffsetsFromSelection(f);g=g.createSelectionFromOffsets(n,r,m);null!==g?q.$setSelection(g):(X(a,b),R(h)&&(g=q.$getRoot(),0===g.getChildrenSize()&&g.append(q.$createParagraphNode()),q.$getRoot().selectEnd()))}ha(a,b,f,q.$getSelection())}else X(a,
45
+ b)},{onUpdate:()=>{Z(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.5.1-next.1",
14
+ "version": "0.5.1-next.2",
15
15
  "main": "LexicalYjs.js",
16
16
  "dependencies": {
17
- "@lexical/offset": "0.5.1-next.1"
17
+ "@lexical/offset": "0.5.1-next.2"
18
18
  },
19
19
  "peerDependencies": {
20
- "lexical": "0.5.1-next.1",
20
+ "lexical": "0.5.1-next.2",
21
21
  "yjs": ">=13.5.22"
22
22
  },
23
23
  "repository": {