@lexical/yjs 0.9.2 → 0.11.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 +7 -3
- package/LexicalYjs.prod.js +22 -22
- package/index.d.ts +3 -2
- package/package.json +3 -3
package/LexicalYjs.dev.js
CHANGED
|
@@ -1598,7 +1598,8 @@ function syncLexicalSelectionToYjs(binding, provider, prevSelection, nextSelecti
|
|
|
1598
1598
|
focusPos: currentFocusPos,
|
|
1599
1599
|
name,
|
|
1600
1600
|
color,
|
|
1601
|
-
focusing
|
|
1601
|
+
focusing,
|
|
1602
|
+
awarenessData
|
|
1602
1603
|
} = localState;
|
|
1603
1604
|
let anchorPos = null;
|
|
1604
1605
|
let focusPos = null;
|
|
@@ -1617,6 +1618,7 @@ function syncLexicalSelectionToYjs(binding, provider, prevSelection, nextSelecti
|
|
|
1617
1618
|
if (shouldUpdatePosition(currentAnchorPos, anchorPos) || shouldUpdatePosition(currentFocusPos, focusPos)) {
|
|
1618
1619
|
awareness.setLocalState({
|
|
1619
1620
|
anchorPos,
|
|
1621
|
+
awarenessData,
|
|
1620
1622
|
color,
|
|
1621
1623
|
focusPos,
|
|
1622
1624
|
focusing,
|
|
@@ -1824,16 +1826,17 @@ function createUndoManager(binding, root) {
|
|
|
1824
1826
|
trackedOrigins: new Set([binding, null])
|
|
1825
1827
|
});
|
|
1826
1828
|
}
|
|
1827
|
-
function initLocalState(provider, name, color, focusing) {
|
|
1829
|
+
function initLocalState(provider, name, color, focusing, awarenessData) {
|
|
1828
1830
|
provider.awareness.setLocalState({
|
|
1829
1831
|
anchorPos: null,
|
|
1832
|
+
awarenessData,
|
|
1830
1833
|
color,
|
|
1831
1834
|
focusPos: null,
|
|
1832
1835
|
focusing: focusing,
|
|
1833
1836
|
name
|
|
1834
1837
|
});
|
|
1835
1838
|
}
|
|
1836
|
-
function setLocalStateFocus(provider, name, color, focusing) {
|
|
1839
|
+
function setLocalStateFocus(provider, name, color, focusing, awarenessData) {
|
|
1837
1840
|
const {
|
|
1838
1841
|
awareness
|
|
1839
1842
|
} = provider;
|
|
@@ -1842,6 +1845,7 @@ function setLocalStateFocus(provider, name, color, focusing) {
|
|
|
1842
1845
|
if (localState === null) {
|
|
1843
1846
|
localState = {
|
|
1844
1847
|
anchorPos: null,
|
|
1848
|
+
awarenessData,
|
|
1845
1849
|
color,
|
|
1846
1850
|
focusPos: null,
|
|
1847
1851
|
focusing: focusing,
|
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
|
|
15
|
-
function F(a,b,c,d){var e=d.__type,f=a.nodeProperties;let g=f.get(e);if(void 0===g){let
|
|
16
|
-
|
|
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 m=d[h];if(!J.has(m)){var f=a.excludedProperties.get(c.constructor);if(void 0===f||!f.has(m)){var g=c[m];f=b instanceof v.Map?b.get(m):b.getAttribute(m);if(g!==f){if(f instanceof v.Doc){let n=a.docMap;g instanceof v.Doc&&n.delete(g.guid);g=t.createEditor();let p=f.guid;g._key=p;n.set(p,f);f=g}void 0===e&&(e=c.getWritable());e[m]=f}}}}}
|
|
15
|
+
function F(a,b,c,d){var e=d.__type,f=a.nodeProperties;let g=f.get(e);if(void 0===g){let m=a.excludedProperties.get(d.constructor);g=Object.keys(d).filter(n=>!J.has(n)||m&&!m.has(n));f.set(e,g)}e=a.editor.constructor;for(f=0;f<g.length;f++){let m=g[f];var h=null===c?void 0:c[m];let n=d[m];if(h!==n){if(n instanceof e){let p=a.docMap,k;h instanceof e&&(h=h._key,k=p.get(h),p.delete(h));h=k||new v.Doc;let l=h.guid;n._key=l;p.set(l,h);n=h;a.editor.update(()=>{d.markDirty()})}b instanceof v.Map?b.set(m,
|
|
16
|
+
n):b.setAttribute(m,n)}}}function Q(a,b,c){let d=0,e=0,f=a._children,g=f.length;for(;e<g;e++){a=f[e];let h=d,m=a.getSize();d+=m;if((c?d>=b:d>b)&&a instanceof E)return c=b-h-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:h};if(e===g-1)return{length:0,node:null,nodeIndex:e+1,offset:h+1}}return{length:0,node:null,nodeIndex:0,offset:0}}
|
|
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 g=f.length,h=a.collabNodeMap,
|
|
26
|
-
null):q instanceof C||B(93)),
|
|
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 g=null===f?[]:S(f,c);f=S(b,null);let h=g.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 p=0;p<b.length;p++){var e=b[p],f=e.insert,g=e.delete;if(null!=e.retain)d+=e.retain;else if("number"===typeof g)for(f=g;0<f;){let {node:k,nodeIndex:l,offset:q,length:u}=Q(this,d,!1);if(k instanceof P||k instanceof C||k instanceof U)c.splice(l,1),--f;else if(k instanceof E){e=Math.min(f,u);g=0!==l?c[l-1]:null;var h=k.getSize();if(0===q&&1===e&&0<l&&g instanceof E&&u===h&&0===Array.from(k._map.keys()).length)g._text+=
|
|
24
|
+
k._text,c.splice(l,1);else if(0===q&&e===h)c.splice(l,1);else{g=k;h=k._text;var m=q,n=e;h=h.slice(0,m)+""+h.slice(m+n);g._text=h}f-=e}else break}else if(null!=f)if("string"===typeof f){let {node:k,offset:l}=Q(this,d,!0);k instanceof E?(e=k,g=k._text,h=l,m=f,g=g.slice(0,h)+m+g.slice(h+0),e._text=g):this._xmlText.delete(l,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 g=f.length,h=a.collabNodeMap,m=new Set,n;let p=0;var k=null;g!==e&&b.getWritable();for(let x=0;x<g;x++){var l=d[p],q=f[x];var u=q.getNode();var r=q._key;if(null!==u&&l===r)k=t.$isTextNode(u),m.add(l),k&&(q._key=l,q instanceof P?(k=q._xmlText,q.syncPropertiesFromYjs(a,null),q.applyChildrenYjsDelta(a,k.toDelta()),q.syncChildrenFromYjs(a)):q instanceof E?q.syncPropertiesAndTextFromYjs(a,null):q instanceof U?q.syncPropertiesFromYjs(a,
|
|
26
|
+
null):q instanceof C||B(93)),k=u,p++;else{if(void 0===n)for(n=new Set,r=0;r<g;r++){var w=f[r]._key;""!==w&&n.add(w)}if(null===u||void 0===l||n.has(l)){u=b.getWritable();l=a;r=q;w=c;var A=r.getType();A=l.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(l,null),r.applyChildrenYjsDelta(l,w.toDelta()),r.syncChildrenFromYjs(l)):r instanceof E?r.syncPropertiesAndTextFromYjs(l,null):r instanceof U&&r.syncPropertiesFromYjs(l,
|
|
27
|
+
null);l.collabNodeMap.set(A.__key,r);l=A;r=l.__key;h.set(r,q);null===k?(k=u.getFirstChild(),u.__first=r,null!==k&&(k=k.getWritable(),k.__prev=r,l.__next=k.__key)):(q=k.getWritable(),w=k.getNextSibling(),q.__next=r,l.__prev=k.__key,null!==w&&(k=w.getWritable(),k.__prev=r,l.__next=k.__key));x===g-1&&(u.__last=r);u.__size++;k=l}else q=K(l),T(q),x--,p++}}for(b=0;b<e;b++)f=d[b],m.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 g=null===f?[]:S(f,c);f=S(b,null);let h=g.length-1,m=f.length-1,n=a.collabNodeMap,p,k,l=0;for(b=
|
|
29
|
+
0;l<=h&&b<=m;){var q=g[l];let r=f[b];if(q===r)this._syncChildFromLexical(a,b,r,c,d,e),l++,b++;else{void 0===p&&(p=new Set(g));void 0===k&&(k=new Set(f));var u=k.has(q);q=p.has(r);u?(u=K(r),u=L(a,u,this),n.set(r,u),q?(this.splice(a,b,1,u),l++):this.splice(a,b,0,u),b++):(this.splice(a,b,1),l++)}}c=l>h;d=b>m;if(c&&!d)for(;b<=m;++b)c=f[b],d=K(c),d=L(a,d,this),this.append(d),n.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 g=f.getOffset();-1===g&&B(95);var h=this._xmlText;0!==c&&h.delete(g,f.getSize());d instanceof
|
|
31
31
|
P?h.insertEmbed(g,d._xmlText):d instanceof E?(f=d._map,null===f.parent&&h.insertEmbed(g,f),h.insert(g+1,d._text)):d instanceof C?h.insertEmbed(g,d._map):d instanceof U&&h.insertEmbed(g,d._xmlElem);if(0!==c)for(g=e.slice(b,b+c),h=0;h<g.length;h++)g[h].destroy(a);void 0!==d?e.splice(b,c,d):e.splice(b,c)}}getChildOffset(a){let b=0,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,g]=Z(a.type,a.index);if(null!==d&&null!==f){b=d.getKey();c=f.getKey();let h=t.$getSelection();t.$isRangeSelection(h)&&(a=h.focus,ba(h.anchor,b,e),ba(a,c,g))}}}
|
|
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 g=0;g<c.length;g++){let [H,la]=c[g];if(H!==d){f.add(H);let {anchorPos:ca,focusPos:da,name:ma,color:na,focusing:oa}=la;var h=null,
|
|
38
|
-
|
|
39
|
-
u.appendChild(r);h={anchor:{key:
|
|
40
|
-
if(null!=x&&null!=q){if(x===q&&t.$isLineBreakNode(x))q=[
|
|
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:g,name:h,color:
|
|
43
|
-
exports.createBinding=function(a,b,c,d,e,f){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,excludedProperties:f||new Map,id:c,nodeProperties:new Map,root:b}};exports.createUndoManager=function(a,b){return new v.UndoManager(b,{trackedOrigins:new Set([a,null])})};
|
|
44
|
-
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
|
|
45
|
-
exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,g,h){aa(a,()=>{d.read(()=>{if(h.has("collaboration")||h.has("historic")){if(0<g.size){var
|
|
46
|
-
u instanceof E&&"string"===typeof r&&(u._text=r)}}}else e.has("root")&&(
|
|
47
|
-
exports.syncYjsChangesToLexical=function(a,b,c,d){let e=a.editor,f=e._editorState;e.update(()=>{var g=e._pendingEditorState;for(var h=0;h<c.length;h++){var
|
|
48
|
-
U&&
|
|
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 g=0;g<c.length;g++){let [H,la]=c[g];if(H!==d){f.add(H);let {anchorPos:ca,focusPos:da,name:ma,color:na,focusing:oa}=la;var h=null,m=b.get(H);void 0===m&&(m={color:na,name:ma,selection:null},b.set(H,m));if(null!==ca&&null!==da&&oa){var n=v.createAbsolutePositionFromRelativePosition(ca,a.doc),p=v.createAbsolutePositionFromRelativePosition(da,a.doc);if(null!==
|
|
38
|
+
n&&null!==p){let [ea,fa]=Z(n.type,n.index),[ha,ia]=Z(p.type,p.index);if(null!==ea&&null!==ha){n=ea.getKey();var k=ha.getKey();h=m.selection;if(null===h){h=m;p=fa;var l=ia,q=h.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=h.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);h={anchor:{key:n,offset:p},caret:u,color:q,focus:{key:k,offset:l},name:r,selections:[]}}else p=h.anchor,l=h.focus,p.key=n,p.offset=fa,l.key=k,l.offset=ia}}}a:if(n=a,p=m,u=h,q=e,l=n.editor,h=l.getRootElement(),m=n.cursorsContainer,null!==m&&null!==h&&(h=m.offsetParent,null!==h))if(h=h.getBoundingClientRect(),k=p.selection,null===u)null!==k&&(p.selection=null,X(n,k));else{p.selection=u;p=u.caret;k=u.color;n=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=[l.getElementByKey(w).getBoundingClientRect()];else{q=y.createDOMRange(l,x,r.offset,q,u.offset);if(null===q)break a;q=y.createRectsFromDOMRange(l,q)}u=n.length;l=q.length;for(r=0;r<l;r++)x=q[r],w=n[r],void 0===w&&(w=document.createElement("span"),n[r]=w,A=document.createElement("span"),w.appendChild(A),m.appendChild(w)),x=`position:absolute;top:${x.top-h.top}px;left:${x.left-h.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:${k};opacity:0.3;`,r===l-1&&p.parentNode!==w&&w.appendChild(p);for(h=u-1;h>=l;h--)m.removeChild(n[h]),n.pop()}}}}c=Array.from(b.keys());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&&X(a,g),b.delete(e)))}
|
|
42
|
+
function ka(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:g,name:h,color:m,focusing:n,awarenessData:p}=e,k=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)t.$isRangeSelection(d)&&(e=V(d.anchor,a),k=V(d.focus,a)),(W(f,e)||W(g,k))&&b.setLocalState({anchorPos:e,awarenessData:p,color:m,focusPos:k,focusing:n,name:h})}}let pa=t.createCommand("CONNECTED_COMMAND"),qa=t.createCommand("TOGGLE_CONNECT_COMMAND");exports.CONNECTED_COMMAND=pa;
|
|
43
|
+
exports.TOGGLE_CONNECT_COMMAND=qa;exports.createBinding=function(a,b,c,d,e,f){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,excludedProperties:f||new Map,id:c,nodeProperties:new Map,root:b}};exports.createUndoManager=function(a,b){return new v.UndoManager(b,{trackedOrigins:new Set([a,null])})};
|
|
44
|
+
exports.initLocalState=function(a,b,c,d,e){a.awareness.setLocalState({anchorPos:null,awarenessData:e,color:c,focusPos:null,focusing:d,name:b})};exports.setLocalStateFocus=function(a,b,c,d,e){({awareness:a}=a);let f=a.getLocalState();null===f&&(f={anchorPos:null,awarenessData:e,color:c,focusPos:null,focusing:d,name:b});f.focusing=d;a.setLocalState(f)};exports.syncCursorPositions=ja;
|
|
45
|
+
exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,g,h){aa(a,()=>{d.read(()=>{if(h.has("collaboration")||h.has("historic")){if(0<g.size){var m=Array.from(g),n=a.collabNodeMap,p=[];for(let u=0;u<m.length;u++){var k=m[u],l=t.$getNodeByKey(k),q=n.get(k);if(q instanceof E)if(t.$isTextNode(l))p.push([q,l.__text]);else{l=q.getOffset();if(-1===l)continue;let r=q._parent;q._normalized=!0;r._xmlText.delete(l,1);n.delete(k);k=r._children;q=k.indexOf(q);k.splice(q,1)}}for(m=0;m<p.length;m++){let [u,r]=p[m];
|
|
46
|
+
u instanceof E&&"string"===typeof r&&(u._text=r)}}}else e.has("root")&&(p=c._nodeMap,m=t.$getRoot(),n=a.root,n.syncPropertiesFromLexical(a,m,p),n.syncChildrenFromLexical(a,m,p,e,f)),p=t.$getSelection(),ka(a,b,c._selection,p)})})};
|
|
47
|
+
exports.syncYjsChangesToLexical=function(a,b,c,d){let e=a.editor,f=e._editorState;e.update(()=>{var g=e._pendingEditorState;for(var h=0;h<c.length;h++){var m=a,n=c[h],{target:p}=n;p=O(m,p);if(p instanceof P&&n instanceof v.YTextEvent){let {keysChanged:k,childListChanged:l,delta:q}=n;0<k.size&&p.syncPropertiesFromYjs(m,k);l&&(p.applyChildrenYjsDelta(m,q),p.syncChildrenFromYjs(m))}else p instanceof E&&n instanceof v.YMapEvent?({keysChanged:n}=n,0<n.size&&p.syncPropertiesAndTextFromYjs(m,n)):p instanceof
|
|
48
|
+
U&&n instanceof v.YXmlEvent?({attributesChanged:n}=n,0<n.size&&p.syncPropertiesFromYjs(m,n)):B(82)}h=t.$getSelection();if(t.$isRangeSelection(h))if(R(h)){m=f._selection;if(t.$isRangeSelection(m)){p=z.$createOffsetView(e,0,f);g=z.$createOffsetView(e,0,g);let [k,l]=p.getOffsetsFromSelection(m);g=g.createSelectionFromOffsets(k,l,p);null!==g?t.$setSelection(g):(Y(a,b),R(h)&&(g=t.$getRoot(),0===g.getChildrenSize()&&g.append(t.$createParagraphNode()),t.$getRoot().selectEnd()))}ka(a,b,m,t.$getSelection())}else Y(a,
|
|
49
49
|
b)},{onUpdate:()=>{ja(a,b)},skipTransforms:!0,tag:d?"historic":"collaboration"})}
|
package/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export declare type UserState = {
|
|
|
15
15
|
focusing: boolean;
|
|
16
16
|
focusPos: null | RelativePosition;
|
|
17
17
|
name: string;
|
|
18
|
+
awarenessData: object;
|
|
18
19
|
};
|
|
19
20
|
export declare const CONNECTED_COMMAND: LexicalCommand<boolean>;
|
|
20
21
|
export declare const TOGGLE_CONNECT_COMMAND: LexicalCommand<boolean>;
|
|
@@ -55,7 +56,7 @@ export type { Provider };
|
|
|
55
56
|
export type { Binding, ClientID, ExcludedProperties } from './Bindings';
|
|
56
57
|
export { createBinding } from './Bindings';
|
|
57
58
|
export declare function createUndoManager(binding: Binding, root: XmlText): UndoManager;
|
|
58
|
-
export declare function initLocalState(provider: Provider, name: string, color: string, focusing: boolean): void;
|
|
59
|
-
export declare function setLocalStateFocus(provider: Provider, name: string, color: string, focusing: boolean): void;
|
|
59
|
+
export declare function initLocalState(provider: Provider, name: string, color: string, focusing: boolean, awarenessData: object): void;
|
|
60
|
+
export declare function setLocalStateFocus(provider: Provider, name: string, color: string, focusing: boolean, awarenessData: object): void;
|
|
60
61
|
export { syncCursorPositions } from './SyncCursors';
|
|
61
62
|
export { syncLexicalUpdateToYjs, syncYjsChangesToLexical, } from './SyncEditorStates';
|
package/package.json
CHANGED
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
"crdt"
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"version": "0.
|
|
14
|
+
"version": "0.11.0",
|
|
15
15
|
"main": "LexicalYjs.js",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/offset": "0.
|
|
17
|
+
"@lexical/offset": "0.11.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"lexical": "0.
|
|
20
|
+
"lexical": "0.11.0",
|
|
21
21
|
"yjs": ">=13.5.22"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|