@lexical/yjs 0.1.6 → 0.1.7

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.
Files changed (2) hide show
  1. package/index.js +6 -6
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -11,14 +11,14 @@ c._lexicalValue=f,c._collabNode=b,d.insert(e,[c]),N(a,b,f,c)),ba(a,b,f,c)):d.ins
11
11
  function ca(a,b,c,d,e){var f=d.get(e);const g=c.get(e);if(f!==g){let h=g._lexicalValue;g instanceof m.Map?(c=g.get("type"),"editor"===c?void 0===h&&(a=a.docMap,c=g.get("id"),f=g.get("doc"),h=v.createDecoratorEditor(c),g._lexicalValue=h,g._collabNode=b,a.set(c,f),J(()=>d.set(e,h))):"map"===c?(void 0===h&&(h=v.createDecoratorMap(a.editor),K(a,b,h,g),g._lexicalValue=h,g._collabNode=b,J(()=>d.set(e,h))),Q(a,b,g,h,null)):G(48)):g instanceof m.Array?(void 0===h&&(h=v.createDecoratorArray(a.editor),N(a,
12
12
  b,h,g),g._lexicalValue=h,g._collabNode=b,J(()=>d.set(e,h))),da(a,b,g,h)):J(()=>d.set(e,g))}}
13
13
  function ea(a,b,c,d,e){var f=d._array[e];const g=c.get(e);if(f!==g){let h=g._lexicalValue;g instanceof m.Map?(c=g.get("type"),"editor"===c?void 0===h&&(a=a.docMap,c=g.get("id"),f=g.get("doc"),h=v.createDecoratorEditor(c),g._lexicalValue=h,g._collabNode=b,a.set(c,f),J(()=>d.splice(e,0,h))):"map"===c?(void 0===h&&(h=v.createDecoratorMap(a.editor),K(a,b,h,g),g._lexicalValue=h,g._collabNode=b,J(()=>d.splice(e,0,h))),Q(a,b,g,h,null)):G(48)):g instanceof m.Array?(void 0===h&&(h=v.createDecoratorArray(a.editor),
14
- N(a,b,h,g),g._lexicalValue=h,g._collabNode=b,J(()=>d.splice(e,0,h))),da(a,b,g,h)):J(()=>d.splice(e,0,g))}}function da(a,b,c,d){const e=Math.max(c.length,d.length);for(let f=0;f<e;f++)ea(a,b,c,d,f)}function Q(a,b,c,d,e){e=null===e?Array.from(c.keys()):Array.from(e);for(let f=0;f<e.length;f++)ca(a,b,c,d,e[f])}
14
+ N(a,b,h,g),g._lexicalValue=h,g._collabNode=b,J(()=>d.splice(e,0,h))),da(a,b,g,h)):J(()=>d.splice(e,0,g))}}function da(a,b,c,d){const e=Math.max(c.length,d.getLength());for(let f=0;f<e;f++)ea(a,b,c,d,f)}function Q(a,b,c,d,e){e=null===e?Array.from(c.keys()):Array.from(e);for(let f=0;f<e.length;f++)ca(a,b,c,d,e[f])}
15
15
  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 v.$isDecoratorNode(a)?a:null}getNode(){const a=v.$getNodeByKey(this._key);return v.$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);
16
16
  c=this._xmlElem;const e=null===d?null:d.__state,f=b.__state;B(a,c,d,b);e!==f&&(b=new m.Map,c.insert(0,[b]),b._lexicalValue=f,b._collabNode=this,P(a,this,f,b),K(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;C(a,d,c,b);Q(a,this,e,f,null);K(a,this,f,e)}destroy(a){a.collabNodeMap.delete(this._key);this._unobservers.forEach(b=>b());this._unobservers.clear()}}
17
17
  function fa(a,b,c){b=new R(a,b,c);return a._collabNode=b}const ha=new Set("__key __children __parent __cachedText __text __state".split(" "));function S(a){a=v.$getNodeByKey(a);if(null===a)throw Error("Should never happen");return a}
18
18
  function ia(a,b,c){const d=b.__type;if(v.$isElementNode(b)){var e=new m.XmlText;c=T(e,c,d);c.syncPropertiesFromLexical(a,b,null);c.syncChildrenFromLexical(a,b,null,null,null)}else if(v.$isTextNode(b))e=new m.Map,c=D(e,b.__text,c,d),c.syncPropertiesAndTextFromLexical(a,b,null);else if(v.$isLineBreakNode(b))a=new m.Map,a.set("__type","linebreak"),c=F(a,c);else if(v.$isDecoratorNode(b))e=new m.XmlElement,c=fa(e,c,d),c.syncPropertiesFromLexical(a,b,null);else throw Error("Should never happen");c._key=
19
19
  b.__key;return c}
20
- function U(a,b,c){const d=b._collabNode;if(void 0===d){var e=a.editor._registeredNodes;const f=b instanceof m.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?U(a,e):c||null;if(!(a instanceof V))throw Error("Should never happen");if(b instanceof m.XmlText)return T(b,a,f);if(b instanceof m.Map){if(null===a)throw Error("Should never happen");return"linebreak"===f?F(b,a):
21
- D(b,"",a,f)}if(b instanceof m.XmlElement)return fa(b,a,f)}return d}function C(a,b,c,d){a=null===d?b instanceof m.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(ha.has(f))continue;const g=c[f],h=b instanceof m.Map?b.get(f):b.getAttribute(f);g!==h&&(void 0===e&&(e=c.getWritable()),e[f]=h)}}
20
+ function U(a,b,c){const d=b._collabNode;if(void 0===d){var e=a.editor._nodes;const f=b instanceof m.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?U(a,e):c||null;if(!(a instanceof V))throw Error("Should never happen");if(b instanceof m.XmlText)return T(b,a,f);if(b instanceof m.Map){if(null===a)throw Error("Should never happen");return"linebreak"===f?F(b,a):D(b,"",a,
21
+ f)}if(b instanceof m.XmlElement)return fa(b,a,f)}return d}function C(a,b,c,d){a=null===d?b instanceof m.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(ha.has(f))continue;const g=c[f],h=b instanceof m.Map?b.get(f):b.getAttribute(f);g!==h&&(void 0===e&&(e=c.getWritable()),e[f]=h)}}
22
22
  function B(a,b,c,d){var e=d.__type,f=a.nodeProperties;a=f.get(e);void 0===a&&(a=Object.keys(d).filter(g=>!ha.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 m.Map?b.set(f,g):b.setAttribute(f,g))}}
23
23
  function X(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,n=a.getSize();d+=n;if((c?d>=b:d>b)&&a instanceof z)return b=b-h-1,0>b&&(b=0),{node:a,nodeIndex:e,offset:b,length:n-b};if(d>b)return{node:a,nodeIndex:e,offset:h,length:0};if(e===g-1)return{node:null,nodeIndex:e+1,offset:h+1,length:0}}return{node:null,nodeIndex:0,offset:0,length:0}}
24
24
  function ja(a){const b=a.anchor;a=a.focus;let c=!1;try{const d=b.getNode(),e=a.getNode();if(!d.isAttached()||!e.isAttached()||v.$isTextNode(d)&&b.offset>d.getTextContentSize()||v.$isTextNode(e)&&a.offset>e.getTextContentSize())c=!0}catch(d){c=!0}return c}function L(a,b){a.doc.transact(b,a)}
@@ -26,8 +26,8 @@ class V{constructor(a,b,c){this._key="";this._children=[];this._xmlText=a;this._
26
26
  return a.getChildOffset(this)}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw this.getNode(),Error("Should never happen");C(a,this._xmlText,c,b)}applyChildrenYjsDelta(a,b){const c=this._children;let d=0;for(let l=0;l<b.length;l++){var e=b[l],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:k,nodeIndex:r,offset:t,length:q}=X(this,d,!1);if(k instanceof V||k instanceof E||k instanceof R)c.splice(r,1),--f;else if(k instanceof
27
27
  z){e=Math.min(f,q);g=0!==r?c[r-1]:null;var h=k.getSize();if(0===t&&1===e&&0<r&&g instanceof z&&q===h)g._text+=k._text,c.splice(r,1);else if(0===t&&e===h)c.splice(r,1);else{g=k._text;h=t;var n=e;g=g.slice(0,h)+""+g.slice(h+n);k._text=g}f-=e}else break}else if(null!=f)if("string"===typeof f){const {node:k,offset:r}=X(this,d,!0);k instanceof z?(e=k._text,g=r,h=f,e=e.slice(0,g)+h+e.slice(g+0),k._text=e):this._xmlText.delete(r,f.length);d+=f.length}else e=f,{nodeIndex:f}=X(this,d,!1),e=U(a,e,this),c.splice(f,
28
28
  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,n=a.collabNodeMap,l=new Set;let k,r;h!==f&&(r=ka(b,r,e));let t=0;for(let y=0;y<h;y++){var q=d[t];const x=g[y];var p=x.getNode(),u=x._key;if(null!==p&&q===u){p=v.$isTextNode(p);l.add(q);if(p)if(x._key=q,x instanceof V)p=x._xmlText,x.syncPropertiesFromYjs(a,
29
- null),x.applyChildrenYjsDelta(a,p.toDelta()),x.syncChildrenFromYjs(a);else if(x instanceof z)x.syncPropertiesAndTextFromYjs(a,null);else if(x instanceof R)x.syncPropertiesFromYjs(a,null);else if(!(x instanceof E))throw Error("Should never happen");e[y]=q;t++}else{if(void 0===k)for(k=new Set,u=0;u<h;u++){var w=g[u]._key;""!==w&&k.add(w)}if(null===p||void 0===q||k.has(q)){r=ka(b,r,e);q=a;p=x;u=c;w=p.getType();w=q.editor._registeredNodes.get(w);if(void 0===w)throw Error("createLexicalNode failed");w=
30
- new w.klass;w.__parent=u;p._key=w.__key;p instanceof V?(u=p._xmlText,p.syncPropertiesFromYjs(q,null),p.applyChildrenYjsDelta(q,u.toDelta()),p.syncChildrenFromYjs(q)):p instanceof z?p.syncPropertiesAndTextFromYjs(q,null):p instanceof R&&p.syncPropertiesFromYjs(q,null);q.collabNodeMap.set(w.__key,p);q=w.__key;n.set(q,x);e[y]=q}else y--,t++}}for(b=0;b<f;b++)e=d[b],l.has(e)||(c=S(e).getWritable(),e=a.collabNodeMap.get(e),void 0!==e&&e.destroy(a),c.__parent=null)}syncPropertiesFromLexical(a,b,c){B(a,this._xmlText,
29
+ null),x.applyChildrenYjsDelta(a,p.toDelta()),x.syncChildrenFromYjs(a);else if(x instanceof z)x.syncPropertiesAndTextFromYjs(a,null);else if(x instanceof R)x.syncPropertiesFromYjs(a,null);else if(!(x instanceof E))throw Error("Should never happen");e[y]=q;t++}else{if(void 0===k)for(k=new Set,u=0;u<h;u++){var w=g[u]._key;""!==w&&k.add(w)}if(null===p||void 0===q||k.has(q)){r=ka(b,r,e);q=a;p=x;u=c;w=p.getType();w=q.editor._nodes.get(w);if(void 0===w)throw Error("createLexicalNode failed");w=new w.klass;
30
+ w.__parent=u;p._key=w.__key;p instanceof V?(u=p._xmlText,p.syncPropertiesFromYjs(q,null),p.applyChildrenYjsDelta(q,u.toDelta()),p.syncChildrenFromYjs(q)):p instanceof z?p.syncPropertiesAndTextFromYjs(q,null):p instanceof R&&p.syncPropertiesFromYjs(q,null);q.collabNodeMap.set(w.__key,p);q=w.__key;n.set(q,x);e[y]=q}else y--,t++}}for(b=0;b<f;b++)e=d[b],l.has(e)||(c=S(e).getWritable(),e=a.collabNodeMap.get(e),void 0!==e&&e.destroy(a),c.__parent=null)}syncPropertiesFromLexical(a,b,c){B(a,this._xmlText,
31
31
  this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=S(c);b instanceof V&&v.$isElementNode(c)?(b.syncPropertiesFromLexical(a,c,d),b.syncChildrenFromLexical(a,c,d,e,f)):b instanceof z&&v.$isTextNode(c)?b.syncPropertiesAndTextFromLexical(a,c,d):b instanceof R&&v.$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,n=f.length-1,l=a.collabNodeMap;
32
32
  let k,r,t=0;for(b=0;t<=h&&b<=n;){var q=g[t];const u=f[b];if(q===u)this._syncChildFromLexical(a,b,u,c,d,e),t++,b++;else{void 0===k&&(k=new Set(g));void 0===r&&(r=new Set(f));var p=r.has(q);q=k.has(u);p?(p=S(u),p=ia(a,p,this),l.set(u,p),q?(this.splice(a,b,1,p),t++):this.splice(a,b,0,p),b++):(this.splice(a,b,1),t++)}}c=t>h;d=b>n;if(c&&!d)for(;b<=n;++b)c=f[b],d=S(c),d=ia(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){const b=this._xmlText;
33
33
  var c=this._children;c=c[c.length-1];c=void 0!==c?c.getOffset()+c.getSize():0;if(a instanceof V)b.insertEmbed(c,a._xmlText);else if(a instanceof z){const d=a._map;null===d.parent&&b.insertEmbed(c,d);b.insert(c+1,a._text)}else a instanceof E?b.insertEmbed(c,a._map):a instanceof R&&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();if(-1===g)throw Error("Should never happen");
@@ -43,7 +43,7 @@ w.get(u);w=q.getElementByKey(p);q=q.getElementByKey(u);y=y.offset;x=x.offset;v.$
43
43
  parseFloat(r.paddingRight);p=Array.from(t.getClientRects());t=p.length;u=l.length;for(A=0;A<t;A++)w=p[A],w.width+r===q.width?(p.splice(A--,1),t--):(y=l[A],void 0===y&&(y=document.createElement("span"),l[A]=y,n.appendChild(y)),y.style.cssText=`position:absolute;top:${w.top}px;left:${w.left}px;height:${w.height}px;width:${w.width}px;background-color:rgba(${k}, 0.3);pointer-events:none;z-index:10;`,A===t-1&&h.parentNode!==y&&y.appendChild(h));for(h=u-1;h>=t;h--)n.removeChild(l[h]),l.pop()}}}}c=Array.from(b.keys());
44
44
  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:n,focusing:l}=e,k=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)null!==d&&(e=la(d.anchor,a),k=la(d.focus,a)),(ma(f,e)||ma(g,k))&&b.setLocalState({name:h,color:n,anchorPos:e,focusPos:k,focusing:l})}}
45
45
  class xa{constructor(a,b,c=1){this._offsetMap=a;this._firstNode=b;this._blockOffsetSize=c}createSelectionFromOffsets(a,b,c){var d=this._firstNode;if(null===d)return null;var e=Z(d,a,this._blockOffsetSize);let f=Z(d,b,this._blockOffsetSize);void 0!==c&&(a=ya(a,e,c,this,this._blockOffsetSize),e=Z(d,a,this._blockOffsetSize),b=ya(b,f,c,this,this._blockOffsetSize),f=Z(d,b,this._blockOffsetSize));if(null===e||null===f)return null;c=e.key;d=f.key;const g=v.$getNodeByKey(c),h=v.$getNodeByKey(d);if(null===
46
- g||null===h)return null;let n=0,l=0,k="element",r="element";"text"===e.type?(n=a-e.start,k="text",e=g.getNextSibling(),a!==b&&n===g.getTextContentSize()&&v.$isTextNode(e)&&(n=0,c=e.__key)):"inline"===e.type&&(c=g.getParentOrThrow().getKey(),n=b>e.start?e.end:e.start);"text"===f.type?(l=b-f.start,r="text"):"inline"===f.type&&(d=h.getParentOrThrow().getKey(),l=b>f.start?f.end:f.start);a=v.$createSelection();if(null===a)return null;a.anchor.set(c,n,k);a.focus.set(d,l,r);return a}getOffsetsFromSelection(a){var b=
46
+ g||null===h)return null;let n=0,l=0,k="element",r="element";"text"===e.type?(n=a-e.start,k="text",e=g.getNextSibling(),a!==b&&n===g.getTextContentSize()&&v.$isTextNode(e)&&(n=0,c=e.__key)):"inline"===e.type&&(c=g.getParentOrThrow().getKey(),n=b>e.start?e.end:e.start);"text"===f.type?(l=b-f.start,r="text"):"inline"===f.type&&(d=h.getParentOrThrow().getKey(),l=b>f.start?f.end:f.start);a=v.$createRangeSelection();if(null===a)return null;a.anchor.set(c,n,k);a.focus.set(d,l,r);return a}getOffsetsFromSelection(a){var b=
47
47
  a.anchor,c=a.focus,d=this._offsetMap;const e=b.offset;var f=c.offset;let g=a=-1;if("text"===b.type)b=d.get(b.key),void 0!==b&&(a=b.start+e);else{b=b.getNode().getDescendantByIndex(e);const h=d.get(b.getKey());void 0!==h&&(a=b.getIndexWithinParent()!==e?h.end:h.start)}"text"===c.type?(f=d.get(c.key),void 0!==f&&(g=f.start+c.offset)):(c=c.getNode().getDescendantByIndex(f),d=d.get(c.getKey()),void 0!==d&&(g=c.getIndexWithinParent()!==f?d.end:d.start));return[a,g]}}
48
48
  function ya(a,b,c,d,e){const f=c._offsetMap;d=d._offsetMap;const g=new Set;let h=a;for(;null!==b;){var n=b.key,l=f.get(n),k=b.end-b.start;g.add(n);void 0===l?h+=k:(n=l.end-l.start,n!==k&&(h+=k-n));k=b.prev;if(null!==k)b=k;else{for(b=b.parent;null!==b;)l=b.prev,null!==l&&(k=l.key,n=f.get(k),l=l.end-l.start,g.add(k),void 0===n?h+=l:(k=n.end-n.start,k!==l&&(h+=l-k))),b=b.parent;break}}c=c._firstNode;if(null!==c){b=Z(c,a,e);for(a=!1;null!==b;){if(!g.has(b.key)){a=!0;break}b=b.parent}if(!a)for(;null!==
49
49
  b;)a=b.key,g.has(a)||(e=d.get(a),a=b.end-b.start,void 0===e?h-=a:(e=e.end-e.start,a!==e&&(h+=e-a))),b=b.prev}return h}function Z(a,b,c){for(;null!==a;){if(b<a.end+("element"!==a.type||0===c?1:0)){const d=a.child;if(null!==d){a=d;continue}return a}a=a.next;if(null===a)break}return null}
package/package.json CHANGED
@@ -15,10 +15,10 @@
15
15
  "crdt"
16
16
  ],
17
17
  "license": "MIT",
18
- "version": "0.1.6",
18
+ "version": "0.1.7",
19
19
  "main": "LexicalYjs.js",
20
20
  "peerDependencies": {
21
- "lexical": "0.1.6",
21
+ "lexical": "0.1.7",
22
22
  "yjs": ">=13.5.22"
23
23
  },
24
24
  "repository": {