@lexical/yjs 0.7.9 → 0.8.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 +3 -3
- package/LexicalYjs.prod.js +21 -21
- package/SyncEditorStates.d.ts +1 -1
- package/package.json +3 -3
package/LexicalYjs.dev.js
CHANGED
|
@@ -1415,7 +1415,7 @@ function syncEvent(binding, event) {
|
|
|
1415
1415
|
}
|
|
1416
1416
|
}
|
|
1417
1417
|
}
|
|
1418
|
-
function syncYjsChangesToLexical(binding, provider, events) {
|
|
1418
|
+
function syncYjsChangesToLexical(binding, provider, events, isFromUndoManger) {
|
|
1419
1419
|
const editor = binding.editor;
|
|
1420
1420
|
const currentEditorState = editor._editorState;
|
|
1421
1421
|
editor.update(() => {
|
|
@@ -1465,7 +1465,7 @@ function syncYjsChangesToLexical(binding, provider, events) {
|
|
|
1465
1465
|
syncCursorPositions(binding, provider);
|
|
1466
1466
|
},
|
|
1467
1467
|
skipTransforms: true,
|
|
1468
|
-
tag: 'collaboration'
|
|
1468
|
+
tag: isFromUndoManger ? 'historic' : 'collaboration'
|
|
1469
1469
|
});
|
|
1470
1470
|
}
|
|
1471
1471
|
function handleNormalizationMergeConflicts(binding, normalizedNodes) {
|
|
@@ -1514,7 +1514,7 @@ function syncLexicalUpdateToYjs(binding, provider, prevEditorState, currEditorSt
|
|
|
1514
1514
|
// types a character and we get it, we don't want to then insert
|
|
1515
1515
|
// the same character again. The exception to this heuristic is
|
|
1516
1516
|
// when we need to handle normalization merge conflicts.
|
|
1517
|
-
if (tags.has('collaboration')) {
|
|
1517
|
+
if (tags.has('collaboration') || tags.has('historic')) {
|
|
1518
1518
|
if (normalizedNodes.size > 0) {
|
|
1519
1519
|
handleNormalizationMergeConflicts(binding, normalizedNodes);
|
|
1520
1520
|
}
|
package/LexicalYjs.prod.js
CHANGED
|
@@ -11,22 +11,22 @@ a=this.getOffset()+1+a;0!==b&&d.delete(a,b);""!==c&&d.insert(a,c)}syncProperties
|
|
|
11
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 __parent __cachedText __text __size __next __prev __first __last".split(" "));function K(a){a=t.$getNodeByKey(a);null===a&&B(85);return a}
|
|
12
12
|
function L(a,b,c){let d=b.__type;if(t.$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 t.$isTextNode(b)?(e=new v.Map,e=I(e,b.__text,c,d),e.syncPropertiesAndTextFromLexical(a,b,null)):t.$isLineBreakNode(b)?(a=new v.Map,a.set("__type","linebreak"),e=D(a,c)):t.$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
13
|
function O(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");null==f&&B(87);void 0===e.get(f)&&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,f);if(b instanceof v.Map)return"linebreak"===f?D(b,a):I(b,"",a,f);if(b instanceof v.XmlElement)return N(b,a,f)}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 g=d[h];if(J.has(g))continue;var f=c[g];let
|
|
15
|
-
function F(a,b,c,d){var e=d.__type,f=a.nodeProperties;let h=f.get(e);void 0===h&&(h=Object.keys(d).filter(
|
|
16
|
-
function Q(a,b,c){let d=0,e=0,f=a._children,h=f.length;for(;e<h;e++){a=f[e];let g=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 g=d[h];if(J.has(g))continue;var f=c[g];let l=b instanceof v.Map?b.get(g):b.getAttribute(g);if(f!==l){if(l instanceof v.Doc){let p=a.docMap;f instanceof v.Doc&&p.delete(f.guid);f=t.createEditor();let m=l.guid;f._key=m;p.set(m,l);l=f}void 0===e&&(e=c.getWritable());e[g]=l}}}
|
|
15
|
+
function F(a,b,c,d){var e=d.__type,f=a.nodeProperties;let h=f.get(e);void 0===h&&(h=Object.keys(d).filter(l=>!J.has(l)),f.set(e,h));e=a.editor.constructor;for(f=0;f<h.length;f++){let l=h[f];var g=null===c?void 0:c[l];let p=d[l];if(g!==p){if(p instanceof e){let m=a.docMap,n;g instanceof e&&(g=g._key,n=m.get(g),m.delete(g));g=n||new v.Doc;let k=g.guid;p._key=k;m.set(k,g);p=g;a.editor.update(()=>{d.markDirty()})}b instanceof v.Map?b.set(l,p):b.setAttribute(l,p)}}}
|
|
16
|
+
function Q(a,b,c){let d=0,e=0,f=a._children,h=f.length;for(;e<h;e++){a=f[e];let g=d,l=a.getSize();d+=l;if((c?d>=b:d>b)&&a instanceof E)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}}
|
|
17
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()||t.$isTextNode(d)&&b.offset>d.getTextContentSize()||t.$isTextNode(e)&&a.offset>e.getTextContentSize())c=!0}catch(d){c=!0}return c}function aa(a,b){a.doc.transact(b,a)}function S(a,b){let c=[];for(a=a.__first;null!==a;){let d=null===b?t.$getNodeByKey(a):b.get(a);null!==d&&void 0!==d||B(101);c.push(a);a=d.__next}return c}
|
|
18
18
|
function T(a){var b=a.getParent();if(null!==b){let e=a.getWritable();b=b.getWritable();var c=a.getPreviousSibling();a=a.getNextSibling();if(null===c)if(null!==a){var d=a.getWritable();b.__first=a.__key;d.__prev=null}else b.__first=null;else{d=c.getWritable();if(null!==a){let f=a.getWritable();f.__prev=d.__key;d.__next=f.__key}else d.__next=null;e.__prev=null}null===a?null!==c?(a=c.getWritable(),b.__last=c.__key,a.__next=null):b.__last=null:(a=a.getWritable(),null!==c?(c=c.getWritable(),c.__next=a.__key,
|
|
19
19
|
a.__prev=c.__key):a.__prev=null,e.__next=null);b.__size--;e.__parent=null}}
|
|
20
20
|
class U{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 t.$isDecoratorNode(a)?a:null}getNode(){let a=t.$getNodeByKey(this._key);return t.$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);
|
|
21
21
|
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 U(a,b,c);return a._collabNode=b}
|
|
22
22
|
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 t.$isElementNode(a)?a:null}getNode(){let a=t.$getNodeByKey(this._key);return t.$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,
|
|
23
|
-
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
|
|
24
|
-
|
|
25
|
-
null===b&&B(92);var c=b.__key;let d=S(b,null),e=d.length;var f=this._children;let h=f.length,g=a.collabNodeMap,
|
|
26
|
-
null):
|
|
27
|
-
null);
|
|
28
|
-
this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=K(c);b instanceof P&&t.$isElementNode(c)?(b.syncPropertiesFromLexical(a,c,d),b.syncChildrenFromLexical(a,c,d,e,f)):b instanceof E&&t.$isTextNode(c)?b.syncPropertiesAndTextFromLexical(a,c,d):b instanceof U&&t.$isDecoratorNode(c)&&b.syncPropertiesFromLexical(a,c,d)}syncChildrenFromLexical(a,b,c,d,e){var f=this.getPrevNode(c);let h=null===f?[]:S(f,c);f=S(b,null);let g=h.length-1,
|
|
29
|
-
0;
|
|
23
|
+
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 m=0;m<b.length;m++){var e=b[m],f=e.insert,h=e.delete;if(null!=e.retain)d+=e.retain;else if("number"===typeof h)for(f=h;0<f;){let {node:n,nodeIndex:k,offset:q,length:u}=Q(this,d,!1);if(n instanceof P||n instanceof C||n instanceof U)c.splice(k,1),--f;else if(n instanceof E){e=Math.min(f,u);h=0!==k?c[k-1]:null;var g=n.getSize();if(0===q&&1===e&&0<k&&h instanceof E&&u===g&&0===Array.from(n._map.keys()).length)h._text+=
|
|
24
|
+
n._text,c.splice(k,1);else if(0===q&&e===g)c.splice(k,1);else{h=n;g=n._text;var l=q,p=e;g=g.slice(0,l)+""+g.slice(l+p);h._text=g}f-=e}else break}else if(null!=f)if("string"===typeof f){let {node:n,offset:k}=Q(this,d,!0);n instanceof E?(e=n,h=n._text,g=k,l=f,h=h.slice(0,g)+l+h.slice(g+0),e._text=h):this._xmlText.delete(k,f.length);d+=f.length}else e=f,{nodeIndex:f}=Q(this,d,!1),e=O(a,e,this),c.splice(f,0,e),d+=1;else throw Error("Unexpected delta format");}}syncChildrenFromYjs(a){var b=this.getNode();
|
|
25
|
+
null===b&&B(92);var c=b.__key;let d=S(b,null),e=d.length;var f=this._children;let h=f.length,g=a.collabNodeMap,l=new Set,p;let m=0;var n=null;h!==e&&b.getWritable();for(let x=0;x<h;x++){var k=d[m],q=f[x];var u=q.getNode();var r=q._key;if(null!==u&&k===r)n=t.$isTextNode(u),l.add(k),n&&(q._key=k,q instanceof P?(n=q._xmlText,q.syncPropertiesFromYjs(a,null),q.applyChildrenYjsDelta(a,n.toDelta()),q.syncChildrenFromYjs(a)):q instanceof E?q.syncPropertiesAndTextFromYjs(a,null):q instanceof U?q.syncPropertiesFromYjs(a,
|
|
26
|
+
null):q instanceof C||B(93)),n=u,m++;else{if(void 0===p)for(p=new Set,r=0;r<h;r++){var w=f[r]._key;""!==w&&p.add(w)}if(null===u||void 0===k||p.has(k)){u=b.getWritable();k=a;r=q;w=c;var A=r.getType();A=k.editor._nodes.get(A);void 0===A&&B(88);A=new A.klass;A.__parent=w;r._key=A.__key;r instanceof P?(w=r._xmlText,r.syncPropertiesFromYjs(k,null),r.applyChildrenYjsDelta(k,w.toDelta()),r.syncChildrenFromYjs(k)):r instanceof E?r.syncPropertiesAndTextFromYjs(k,null):r instanceof U&&r.syncPropertiesFromYjs(k,
|
|
27
|
+
null);k.collabNodeMap.set(A.__key,r);k=A;r=k.__key;g.set(r,q);null===n?(n=u.getFirstChild(),u.__first=r,null!==n&&(n=n.getWritable(),n.__prev=r,k.__next=n.__key)):(q=n.getWritable(),w=n.getNextSibling(),q.__next=r,k.__prev=n.__key,null!==w&&(n=w.getWritable(),n.__prev=r,k.__next=n.__key));x===h-1&&(u.__last=r);u.__size++;n=k}else q=K(k),T(q),x--,m++}}for(b=0;b<e;b++)f=d[b],l.has(f)||(c=K(f),f=a.collabNodeMap.get(f),void 0!==f&&f.destroy(a),T(c))}syncPropertiesFromLexical(a,b,c){F(a,this._xmlText,
|
|
28
|
+
this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=K(c);b instanceof P&&t.$isElementNode(c)?(b.syncPropertiesFromLexical(a,c,d),b.syncChildrenFromLexical(a,c,d,e,f)):b instanceof E&&t.$isTextNode(c)?b.syncPropertiesAndTextFromLexical(a,c,d):b instanceof U&&t.$isDecoratorNode(c)&&b.syncPropertiesFromLexical(a,c,d)}syncChildrenFromLexical(a,b,c,d,e){var f=this.getPrevNode(c);let h=null===f?[]:S(f,c);f=S(b,null);let g=h.length-1,l=f.length-1,p=a.collabNodeMap,m,n,k=0;for(b=
|
|
29
|
+
0;k<=g&&b<=l;){var q=h[k];let r=f[b];if(q===r)this._syncChildFromLexical(a,b,r,c,d,e),k++,b++;else{void 0===m&&(m=new Set(h));void 0===n&&(n=new Set(f));var u=n.has(q);q=m.has(r);u?(u=K(r),u=L(a,u,this),p.set(r,u),q?(this.splice(a,b,1,u),k++):this.splice(a,b,0,u),b++):(this.splice(a,b,1),k++)}}c=k>g;d=b>l;if(c&&!d)for(;b<=l;++b)c=f[b],d=K(c),d=L(a,d,this),this.append(d),p.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=this._children;
|
|
30
30
|
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 U&&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)void 0===d&&B(94),this.append(d);else{var h=f.getOffset();-1===h&&B(95);var g=this._xmlText;0!==c&&g.delete(h,f.getSize());d instanceof
|
|
31
31
|
P?g.insertEmbed(h,d._xmlText):d instanceof E?(f=d._map,null===f.parent&&g.insertEmbed(h,f),g.insert(h+1,d._text)):d instanceof C?g.insertEmbed(h,d._map):d instanceof U&&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=a.collabNodeMap,c=this._children;for(let d=0;d<c.length;d++)c[d].destroy(a);
|
|
32
32
|
b.delete(this._key)}}function M(a,b,c){b=new P(a,b,c);return a._collabNode=b}
|
|
@@ -34,16 +34,16 @@ function V(a,b){var c=b.collabNodeMap.get(a.key);if(void 0===c)return null;b=a.o
|
|
|
34
34
|
function W(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!v.compareRelativePositions(a,b))return!0;return!1}function X(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])}}
|
|
35
35
|
function Y(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 [d,e]=Z(b.type,b.index),[f,h]=Z(a.type,a.index);if(null!==d&&null!==f){b=d.getKey();c=f.getKey();let g=t.$getSelection();t.$isRangeSelection(g)&&(a=g.focus,ba(g.anchor,b,e),ba(a,c,h))}}}
|
|
36
36
|
function ba(a,b,c){if(a.key!==b||a.offset!==c){let d=t.$getNodeByKey(b);if(null!==d&&!t.$isElementNode(d)&&!t.$isTextNode(d)){let e=d.getParentOrThrow();b=e.getKey();c=d.getIndexWithinParent();d=e}a.set(b,c,t.$isElementNode(d)?"element":"text")}}function Z(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]}
|
|
37
|
-
function ja(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 [H,la]=c[h];if(H!==d){f.add(H);let {anchorPos:ca,focusPos:da,name:ma,color:na,focusing:oa}=la;var g=null,
|
|
38
|
-
|
|
39
|
-
u.appendChild(r);g={anchor:{key:
|
|
40
|
-
if(null!=x&&null!=
|
|
41
|
-
w.style.cssText=x,w.firstChild.style.cssText=`${x}left:0;top:0;background-color:${
|
|
42
|
-
function ka(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:h,name:g,color:
|
|
37
|
+
function ja(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 [H,la]=c[h];if(H!==d){f.add(H);let {anchorPos:ca,focusPos:da,name:ma,color:na,focusing:oa}=la;var g=null,l=b.get(H);void 0===l&&(l={color:na,name:ma,selection:null},b.set(H,l));if(null!==ca&&null!==da&&oa){var p=v.createAbsolutePositionFromRelativePosition(ca,a.doc),m=v.createAbsolutePositionFromRelativePosition(da,a.doc);if(null!==
|
|
38
|
+
p&&null!==m){let [ea,fa]=Z(p.type,p.index),[ha,ia]=Z(m.type,m.index);if(null!==ea&&null!==ha){p=ea.getKey();var n=ha.getKey();g=l.selection;if(null===g){g=l;m=fa;var k=ia,q=g.color,u=document.createElement("span");u.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${q};z-index:10;`;var r=document.createElement("span");r.textContent=g.name;r.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${q};color:#fff;line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`;
|
|
39
|
+
u.appendChild(r);g={anchor:{key:p,offset:m},caret:u,color:q,focus:{key:n,offset:k},name:r,selections:[]}}else m=g.anchor,k=g.focus,m.key=p,m.offset=fa,k.key=n,k.offset=ia}}}a:if(p=a,m=l,u=g,q=e,k=p.editor,g=k.getRootElement(),l=p.cursorsContainer,null!==l&&null!==g&&(g=l.offsetParent,null!==g))if(g=g.getBoundingClientRect(),n=m.selection,null===u)null!==n&&(m.selection=null,X(p,n));else{m.selection=u;m=u.caret;n=u.color;p=u.selections;r=u.anchor;u=u.focus;var w=r.key,A=u.key,x=q.get(w);q=q.get(A);
|
|
40
|
+
if(null!=x&&null!=q){if(x===q&&t.$isLineBreakNode(x))q=[k.getElementByKey(w).getBoundingClientRect()];else{q=y.createDOMRange(k,x,r.offset,q,u.offset);if(null===q)break a;q=y.createRectsFromDOMRange(k,q)}u=p.length;k=q.length;for(r=0;r<k;r++)x=q[r],w=p[r],void 0===w&&(w=document.createElement("span"),p[r]=w,A=document.createElement("span"),w.appendChild(A),l.appendChild(w)),x=`position:absolute;top:${x.top-g.top}px;left:${x.left-g.left}px;height:${x.height}px;width:${x.width}px;pointer-events:none;z-index:5;`,
|
|
41
|
+
w.style.cssText=x,w.firstChild.style.cssText=`${x}left:0;top:0;background-color:${n};opacity:0.3;`,r===k-1&&m.parentNode!==w&&w.appendChild(m);for(g=u-1;g>=k;g--)l.removeChild(p[g]),p.pop()}}}}c=Array.from(b.keys());for(d=0;d<c.length;d++)e=c[d],f.has(e)||(h=b.get(e),void 0!==h&&(h=h.selection,null!==h&&X(a,h),b.delete(e)))}
|
|
42
|
+
function ka(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:h,name:g,color:l,focusing:p}=e,m=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)t.$isRangeSelection(d)&&(e=V(d.anchor,a),m=V(d.focus,a)),(W(f,e)||W(h,m))&&b.setLocalState({anchorPos:e,color:l,focusPos:m,focusing:p,name:g})}}let pa=t.createCommand("CONNECTED_COMMAND"),qa=t.createCommand("TOGGLE_CONNECT_COMMAND");exports.CONNECTED_COMMAND=pa;exports.TOGGLE_CONNECT_COMMAND=qa;
|
|
43
43
|
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})};
|
|
44
44
|
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=ja;
|
|
45
|
-
exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,h,g){aa(a,()=>{d.read(()=>{if(g.has("collaboration")){if(0<h.size){var
|
|
46
|
-
typeof r&&(u._text=r)}}}else e.has("root")&&(
|
|
47
|
-
exports.syncYjsChangesToLexical=function(a,b,c){let
|
|
48
|
-
U&&
|
|
49
|
-
b)},{onUpdate:()=>{ja(a,b)},skipTransforms:!0,tag:"collaboration"})}
|
|
45
|
+
exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,h,g){aa(a,()=>{d.read(()=>{if(g.has("collaboration")||g.has("historic")){if(0<h.size){var l=Array.from(h),p=a.collabNodeMap,m=[];for(let u=0;u<l.length;u++){var n=l[u],k=t.$getNodeByKey(n),q=p.get(n);if(q instanceof E)if(t.$isTextNode(k))m.push([q,k.__text]);else{k=q.getOffset();if(-1===k)continue;let r=q._parent;q._normalized=!0;r._xmlText.delete(k,1);p.delete(n);n=r._children;q=n.indexOf(q);n.splice(q,1)}}for(l=0;l<m.length;l++){let [u,r]=m[l];
|
|
46
|
+
u instanceof E&&"string"===typeof r&&(u._text=r)}}}else e.has("root")&&(m=c._nodeMap,l=t.$getRoot(),p=a.root,p.syncPropertiesFromLexical(a,l,m),p.syncChildrenFromLexical(a,l,m,e,f)),m=t.$getSelection(),ka(a,b,c._selection,m)})})};
|
|
47
|
+
exports.syncYjsChangesToLexical=function(a,b,c,d){let e=a.editor,f=e._editorState;e.update(()=>{var h=e._pendingEditorState;for(var g=0;g<c.length;g++){var l=a,p=c[g],{target:m}=p;m=O(l,m);if(m instanceof P&&p instanceof v.YTextEvent){let {keysChanged:n,childListChanged:k,delta:q}=p;0<n.size&&m.syncPropertiesFromYjs(l,n);k&&(m.applyChildrenYjsDelta(l,q),m.syncChildrenFromYjs(l))}else m instanceof E&&p instanceof v.YMapEvent?({keysChanged:p}=p,0<p.size&&m.syncPropertiesAndTextFromYjs(l,p)):m instanceof
|
|
48
|
+
U&&p instanceof v.YXmlEvent?({attributesChanged:p}=p,0<p.size&&m.syncPropertiesFromYjs(l,p)):B(82)}g=t.$getSelection();if(t.$isRangeSelection(g))if(R(g)){l=f._selection;if(t.$isRangeSelection(l)){m=z.$createOffsetView(e,0,f);h=z.$createOffsetView(e,0,h);let [n,k]=m.getOffsetsFromSelection(l);h=h.createSelectionFromOffsets(n,k,m);null!==h?t.$setSelection(h):(Y(a,b),R(g)&&(h=t.$getRoot(),0===h.getChildrenSize()&&h.append(t.$createParagraphNode()),t.$getRoot().selectEnd()))}ka(a,b,l,t.$getSelection())}else Y(a,
|
|
49
|
+
b)},{onUpdate:()=>{ja(a,b)},skipTransforms:!0,tag:d?"historic":"collaboration"})}
|
package/SyncEditorStates.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import type { EditorState, NodeKey } from 'lexical';
|
|
|
9
9
|
import { WebsocketProvider } from 'y-websocket';
|
|
10
10
|
import { Text as YText, YEvent } from 'yjs';
|
|
11
11
|
import { Binding } from '.';
|
|
12
|
-
export declare function syncYjsChangesToLexical(binding: Binding, provider: WebsocketProvider, events: Array<YEvent<YText
|
|
12
|
+
export declare function syncYjsChangesToLexical(binding: Binding, provider: WebsocketProvider, events: Array<YEvent<YText>>, isFromUndoManger: boolean): void;
|
|
13
13
|
declare type IntentionallyMarkedAsDirtyElement = boolean;
|
|
14
14
|
export declare function syncLexicalUpdateToYjs(binding: Binding, provider: WebsocketProvider, prevEditorState: EditorState, currEditorState: EditorState, dirtyElements: Map<NodeKey, IntentionallyMarkedAsDirtyElement>, dirtyLeaves: Set<NodeKey>, normalizedNodes: Set<NodeKey>, tags: Set<string>): void;
|
|
15
15
|
export {};
|
package/package.json
CHANGED
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
"crdt"
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"version": "0.
|
|
14
|
+
"version": "0.8.0",
|
|
15
15
|
"main": "LexicalYjs.js",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/offset": "0.
|
|
17
|
+
"@lexical/offset": "0.8.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"lexical": "0.
|
|
20
|
+
"lexical": "0.8.0",
|
|
21
21
|
"yjs": ">=13.5.22"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|