@lexical/yjs 0.2.1 → 0.2.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 +12 -4
- package/LexicalYjs.prod.js +26 -26
- package/package.json +3 -3
package/LexicalYjs.dev.js
CHANGED
|
@@ -412,17 +412,25 @@ function syncPropertiesFromLexical(binding, sharedType, prevLexicalNode, nextLex
|
|
|
412
412
|
if (prevValue !== nextValue) {
|
|
413
413
|
if (nextValue instanceof EditorClass) {
|
|
414
414
|
const yjsDocMap = binding.docMap;
|
|
415
|
+
let prevDoc;
|
|
415
416
|
|
|
416
417
|
if (prevValue instanceof EditorClass) {
|
|
417
|
-
|
|
418
|
-
|
|
418
|
+
const prevKey = prevValue._key;
|
|
419
|
+
prevDoc = yjsDocMap.get(prevKey);
|
|
420
|
+
yjsDocMap.delete(prevKey);
|
|
421
|
+
} // If we already have a document, use it.
|
|
422
|
+
|
|
419
423
|
|
|
420
|
-
const doc = new yjs.Doc(); // $FlowFixMe: guid exists
|
|
424
|
+
const doc = prevDoc || new yjs.Doc(); // $FlowFixMe: guid exists
|
|
421
425
|
|
|
422
426
|
const key = doc.guid;
|
|
423
427
|
nextValue._key = key;
|
|
424
428
|
yjsDocMap.set(key, doc);
|
|
425
|
-
nextValue = doc;
|
|
429
|
+
nextValue = doc; // Mark the node dirty as we've assigned a new key to it
|
|
430
|
+
|
|
431
|
+
binding.editor.update(() => {
|
|
432
|
+
nextLexicalNode.markDirty();
|
|
433
|
+
});
|
|
426
434
|
}
|
|
427
435
|
|
|
428
436
|
if (sharedType instanceof yjs.Map) {
|
package/LexicalYjs.prod.js
CHANGED
|
@@ -6,43 +6,43 @@
|
|
|
6
6
|
*/
|
|
7
7
|
var q=require("lexical"),w=require("yjs"),z=require("@lexical/offset");class B{constructor(a,b){this._key="";this._map=a;this._parent=b;this._type="linebreak"}getNode(){const 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 C(a,b){b=new B(a,b);return a._collabNode=b}
|
|
8
8
|
class D{constructor(a,b,c,d){this._key="";this._map=a;this._parent=c;this._text=b;this._type=d;this._normalized=!1}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return q.$isTextNode(a)?a:null}getNode(){const 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){const d=
|
|
9
|
-
this._parent._xmlText;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;const f=c.length;let
|
|
10
|
-
e;a=c.slice(e,f-
|
|
9
|
+
this._parent._xmlText;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;const f=c.length;let h=e=0;for(;e<d&&e<f&&b[e]===c[e]&&e<a;)e++;for(;h+e<d&&h+e<f&&b[d-h-1]===c[f-h-1];)h++;for(;h+e<d&&h+e<f&&b[e]===c[e];)e++;b=
|
|
10
|
+
e;a=c.slice(e,f-h);d=d-e-h;this.spliceText(b,d,a);this._text=c}}syncPropertiesAndTextFromYjs(a,b){const c=this.getNode();if(null===c)throw Error("Should never happen");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 D(a,b,c,d);return a._collabNode=b}const J=new Set(["__key","__children","__parent","__cachedText","__text"]);
|
|
11
11
|
function K(a){a=q.$getNodeByKey(a);if(null===a)throw Error("Should never happen");return a}
|
|
12
12
|
function L(a,b,c){const d=b.__type;if(q.$isElementNode(b)){var e=new w.XmlText;c=M(e,c,d);c.syncPropertiesFromLexical(a,b,null);c.syncChildrenFromLexical(a,b,null,null,null)}else if(q.$isTextNode(b))e=new w.Map,c=H(e,b.__text,c,d),c.syncPropertiesAndTextFromLexical(a,b,null);else if(q.$isLineBreakNode(b))a=new w.Map,a.set("__type","linebreak"),c=C(a,c);else if(q.$isDecoratorNode(b))e=new w.XmlElement,c=O(e,c,d),c.syncPropertiesFromLexical(a,b,null);else throw Error("Should never happen");c._key=b.__key;
|
|
13
13
|
return c}
|
|
14
14
|
function P(a,b,c){const d=b._collabNode;if(void 0===d){var e=a.editor._nodes;const f=b instanceof w.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?P(a,e):c||null;if(!(a instanceof Q))throw Error("Should never happen");if(b instanceof w.XmlText)return M(b,a,f);if(b instanceof w.Map){if(null===a)throw Error("Should never happen");return"linebreak"===f?C(b,a):H(b,"",a,
|
|
15
|
-
f)}if(b instanceof w.XmlElement)return O(b,a,f)}return d}function G(a,b,c,d){d=null===d?b instanceof w.Map?Array.from(b.keys()):Object.keys(b.getAttributes()):Array.from(d);let e;for(let
|
|
16
|
-
function F(a,b,c,d){var e=d.__type,f=a.nodeProperties;let
|
|
17
|
-
function R(a,b,c){let d=0,e=0;const f=a._children,
|
|
15
|
+
f)}if(b instanceof w.XmlElement)return O(b,a,f)}return d}function G(a,b,c,d){d=null===d?b instanceof w.Map?Array.from(b.keys()):Object.keys(b.getAttributes()):Array.from(d);let e;for(let h=0;h<d.length;h++){const g=d[h];if(J.has(g))continue;var f=c[g];let k=b instanceof w.Map?b.get(g):b.getAttribute(g);if(f!==k){if(k instanceof w.Doc){const m=a.docMap;f instanceof w.Doc&&m.delete(f.guid);f=q.createEditor();const l=k.guid;f._key=l;m.set(l,k);k=f}void 0===e&&(e=c.getWritable());e[g]=k}}}
|
|
16
|
+
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(k=>!J.has(k)),f.set(e,h));e=a.editor.constructor;for(f=0;f<h.length;f++){const k=h[f];var g=null===c?void 0:c[k];let m=d[k];if(g!==m){if(m instanceof e){const l=a.docMap;let r;g instanceof e&&(g=g._key,r=l.get(g),l.delete(g));g=r||new w.Doc;const t=g.guid;m._key=t;l.set(t,g);m=g;a.editor.update(()=>{d.markDirty()})}b instanceof w.Map?b.set(k,m):b.setAttribute(k,m)}}}
|
|
17
|
+
function R(a,b,c){let d=0,e=0;const f=a._children,h=f.length;for(;e<h;e++){a=f[e];const g=d,k=a.getSize();d+=k;if((c?d>=b:d>b)&&a instanceof D)return b=b-g-1,0>b&&(b=0),{length:k-b,node:a,nodeIndex:e,offset:b};if(d>b)return{length:0,node:a,nodeIndex:e,offset:g};if(e===h-1)return{length:0,node:null,nodeIndex:e+1,offset:g+1}}return{length:0,node:null,nodeIndex:0,offset:0}}
|
|
18
18
|
function S(a){const b=a.anchor;a=a.focus;let c=!1;try{const 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 aa(a,b){a.doc.transact(b,a)}
|
|
19
19
|
class T{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(){const 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);
|
|
20
20
|
F(a,this._xmlElem,c,b)}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw Error("Should never happen");G(a,this._xmlElem,c,b)}destroy(a){a.collabNodeMap.delete(this._key);this._unobservers.forEach(b=>b());this._unobservers.clear()}}function O(a,b,c){b=new T(a,b,c);return a._collabNode=b}
|
|
21
21
|
class Q{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(){const 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(){const a=this._parent;if(null===a)throw Error("Should never happen");
|
|
22
|
-
return a.getChildOffset(this)}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw this.getNode(),Error("Should never happen");G(a,this._xmlText,c,b)}applyChildrenYjsDelta(a,b){const c=this._children;let d=0;for(let
|
|
23
|
-
D){e=Math.min(f,p);
|
|
24
|
-
R(this,d,!1),e=P(a,e,this),c.splice(f,0,e),d+=1;else throw Error("Unexpected delta format");}}syncChildrenFromYjs(a){var b=this.getNode();if(null===b)throw this.getNode(),Error("Should never happen");var c=b.__key;const d=b.__children;var e=[];const f=d.length,
|
|
25
|
-
Q)n=x._xmlText,x.syncPropertiesFromYjs(a,null),x.applyChildrenYjsDelta(a,n.toDelta()),x.syncChildrenFromYjs(a);else if(x instanceof D)x.syncPropertiesAndTextFromYjs(a,null);else if(x instanceof T)x.syncPropertiesFromYjs(a,null);else if(!(x instanceof B))throw Error("Should never happen");e[y]=p;t++}else{if(void 0===
|
|
26
|
-
u=new u.klass;u.__parent=v;n._key=u.__key;n instanceof Q?(v=n._xmlText,n.syncPropertiesFromYjs(p,null),n.applyChildrenYjsDelta(p,v.toDelta()),n.syncChildrenFromYjs(p)):n instanceof D?n.syncPropertiesAndTextFromYjs(p,null):n instanceof T&&n.syncPropertiesFromYjs(p,null);p.collabNodeMap.set(u.__key,n);p=u.__key;k.set(p,x);e[y]=p}else y--,t++}}for(b=0;b<f;b++)e=d[b],
|
|
27
|
-
this._xmlText,this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=K(c);b instanceof Q&&q.$isElementNode(c)?(b.syncPropertiesFromLexical(a,c,d),b.syncChildrenFromLexical(a,c,d,e,f)):b instanceof D&&q.$isTextNode(c)?b.syncPropertiesAndTextFromLexical(a,c,d):b instanceof T&&q.$isDecoratorNode(c)&&b.syncPropertiesFromLexical(a,c,d)}syncChildrenFromLexical(a,b,c,d,e){var f=this.getPrevNode(c);const
|
|
28
|
-
a.collabNodeMap;let
|
|
29
|
-
this._xmlText;var c=this._children;c=c[c.length-1];c=void 0!==c?c.getOffset()+c.getSize():0;if(a instanceof Q)b.insertEmbed(c,a._xmlText);else if(a instanceof D){const d=a._map;null===d.parent&&b.insertEmbed(c,d);b.insert(c+1,a._text)}else a instanceof B?b.insertEmbed(c,a._map):a instanceof T&&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
|
|
30
|
-
if(-1===
|
|
22
|
+
return a.getChildOffset(this)}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw this.getNode(),Error("Should never happen");G(a,this._xmlText,c,b)}applyChildrenYjsDelta(a,b){const c=this._children;let 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;){const {node:l,nodeIndex:r,offset:t,length:p}=R(this,d,!1);if(l instanceof Q||l instanceof B||l instanceof T)c.splice(r,1),--f;else if(l instanceof
|
|
23
|
+
D){e=Math.min(f,p);h=0!==r?c[r-1]:null;var g=l.getSize();if(0===t&&1===e&&0<r&&h instanceof D&&p===g&&0===Array.from(l._map.keys()).length)h._text+=l._text,c.splice(r,1);else if(0===t&&e===g)c.splice(r,1);else{h=l._text;g=t;var k=e;h=h.slice(0,g)+""+h.slice(g+k);l._text=h}f-=e}else break}else if(null!=f)if("string"===typeof f){const {node:l,offset:r}=R(this,d,!0);l instanceof D?(e=l._text,h=r,g=f,e=e.slice(0,h)+g+e.slice(h+0),l._text=e):this._xmlText.delete(r,f.length);d+=f.length}else e=f,{nodeIndex:f}=
|
|
24
|
+
R(this,d,!1),e=P(a,e,this),c.splice(f,0,e),d+=1;else throw Error("Unexpected delta format");}}syncChildrenFromYjs(a){var b=this.getNode();if(null===b)throw this.getNode(),Error("Should never happen");var c=b.__key;const d=b.__children;var e=[];const f=d.length,h=this._children,g=h.length,k=a.collabNodeMap,m=new Set;let l,r;g!==f&&(r=U(b,r,e));let t=0;for(let y=0;y<g;y++){var p=d[t];const x=h[y];var n=x.getNode(),v=x._key;if(null!==n&&p===v){n=q.$isTextNode(n);m.add(p);if(n)if(x._key=p,x instanceof
|
|
25
|
+
Q)n=x._xmlText,x.syncPropertiesFromYjs(a,null),x.applyChildrenYjsDelta(a,n.toDelta()),x.syncChildrenFromYjs(a);else if(x instanceof D)x.syncPropertiesAndTextFromYjs(a,null);else if(x instanceof T)x.syncPropertiesFromYjs(a,null);else if(!(x instanceof B))throw Error("Should never happen");e[y]=p;t++}else{if(void 0===l)for(l=new Set,v=0;v<g;v++){var u=h[v]._key;""!==u&&l.add(u)}if(null===n||void 0===p||l.has(p)){r=U(b,r,e);p=a;n=x;v=c;u=n.getType();u=p.editor._nodes.get(u);if(void 0===u)throw Error("createLexicalNode failed");
|
|
26
|
+
u=new u.klass;u.__parent=v;n._key=u.__key;n instanceof Q?(v=n._xmlText,n.syncPropertiesFromYjs(p,null),n.applyChildrenYjsDelta(p,v.toDelta()),n.syncChildrenFromYjs(p)):n instanceof D?n.syncPropertiesAndTextFromYjs(p,null):n instanceof T&&n.syncPropertiesFromYjs(p,null);p.collabNodeMap.set(u.__key,n);p=u.__key;k.set(p,x);e[y]=p}else y--,t++}}for(b=0;b<f;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,
|
|
27
|
+
this._xmlText,this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=K(c);b instanceof Q&&q.$isElementNode(c)?(b.syncPropertiesFromLexical(a,c,d),b.syncChildrenFromLexical(a,c,d,e,f)):b instanceof D&&q.$isTextNode(c)?b.syncPropertiesAndTextFromLexical(a,c,d):b instanceof T&&q.$isDecoratorNode(c)&&b.syncPropertiesFromLexical(a,c,d)}syncChildrenFromLexical(a,b,c,d,e){var f=this.getPrevNode(c);const h=null===f?[]:f.__children;f=b.__children;const g=h.length-1,k=f.length-1,m=
|
|
28
|
+
a.collabNodeMap;let l,r,t=0;for(b=0;t<=g&&b<=k;){var p=h[t];const v=f[b];if(p===v)this._syncChildFromLexical(a,b,v,c,d,e),t++,b++;else{void 0===l&&(l=new Set(h));void 0===r&&(r=new Set(f));var n=r.has(p);p=l.has(v);n?(n=K(v),n=L(a,n,this),m.set(v,n),p?(this.splice(a,b,1,n),t++):this.splice(a,b,0,n),b++):(this.splice(a,b,1),t++)}}c=t>g;d=b>k;if(c&&!d)for(;b<=k;++b)c=f[b],d=K(c),d=L(a,d,this),this.append(d),m.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=
|
|
29
|
+
this._xmlText;var c=this._children;c=c[c.length-1];c=void 0!==c?c.getOffset()+c.getSize():0;if(a instanceof Q)b.insertEmbed(c,a._xmlText);else if(a instanceof D){const d=a._map;null===d.parent&&b.insertEmbed(c,d);b.insert(c+1,a._text)}else a instanceof B?b.insertEmbed(c,a._map):a instanceof T&&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 h=f.getOffset();
|
|
30
|
+
if(-1===h)throw Error("Should never happen");var g=this._xmlText;0!==c&&g.delete(h,f.getSize());d instanceof Q?g.insertEmbed(h,d._xmlText):d instanceof D?(f=d._map,null===f.parent&&g.insertEmbed(h,f),g.insert(h+1,d._text)):d instanceof B?g.insertEmbed(h,d._map):d instanceof T&&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;const c=this._children;for(let d=0;d<c.length;d++){const e=c[d];
|
|
31
31
|
if(e===a)return b;b+=e.getSize()}return-1}destroy(a){const b=a.collabNodeMap,c=this._children;for(let d=0;d<c.length;d++)c[d].destroy(a);b.delete(this._key)}}function U(a,b,c){return void 0===b?(a=a.getWritable(),a.__children=c,a):b}function M(a,b,c){b=new Q(a,b,c);return a._collabNode=b}
|
|
32
32
|
function V(a,b){b=b.collabNodeMap.get(a.key);if(void 0===b)return null;a=a.offset;let c=b.getSharedType();if(b instanceof D){c=b._parent._xmlText;b=b.getOffset();if(-1===b)return null;a=b+1+a}return w.createRelativePositionFromTypeIndex(c,a)}function W(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!w.compareRelativePositions(a,b))return!0;return!1}function X(a,b){a=a.cursorsContainer;if(null!==a){b=b.selections;const c=b.length;for(let d=0;d<c;d++)a.removeChild(b[d])}}
|
|
33
33
|
function Y(a){for(;null!=a;){if(3===a.nodeType)return a;a=a.firstChild}return null}function ba(a){const b=a.parentNode;if(null==b)throw Error("Should never happen");return[b,Array.from(b.childNodes).indexOf(a)]}
|
|
34
|
-
function ca(a,b){var c=b.awareness.getLocalState();if(null!==c&&(b=c.anchorPos,c=c.focusPos,null!==b&&null!==c&&(b=w.createAbsolutePositionFromRelativePosition(b,a.doc),a=w.createAbsolutePositionFromRelativePosition(c,a.doc),null!==b&&null!==a))){const [e,f]=Z(b.type,b.index),[g
|
|
35
|
-
"element":"text");if(c.key!==a||c.offset!==
|
|
36
|
-
function ia(a,b){var c=Array.from(b.awareness.getStates()),d=a.clientID;b=a.cursors;var e=a.editor._editorState._nodeMap;const f=new Set;for(var
|
|
37
|
-
|
|
38
|
-
n.appendChild(v);
|
|
34
|
+
function ca(a,b){var c=b.awareness.getLocalState();if(null!==c&&(b=c.anchorPos,c=c.focusPos,null!==b&&null!==c&&(b=w.createAbsolutePositionFromRelativePosition(b,a.doc),a=w.createAbsolutePositionFromRelativePosition(c,a.doc),null!==b&&null!==a))){const [e,f]=Z(b.type,b.index),[h,g]=Z(a.type,a.index);if(null!==e&&null!==h){const 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!==f)d=q.$getNodeByKey(k),b.anchor.set(k,f,q.$isElementNode(d)?
|
|
35
|
+
"element":"text");if(c.key!==a||c.offset!==g)c=q.$getNodeByKey(a),b.focus.set(a,g,q.$isElementNode(c)?"element":"text")}}}}function Z(a,b){a=a._collabNode;if(void 0===a)return[null,0];if(a instanceof Q){const {node:c,offset:d}=R(a,b,!0);return null===c?[a,0]:[c,d]}return[null,0]}
|
|
36
|
+
function ia(a,b){var c=Array.from(b.awareness.getStates()),d=a.clientID;b=a.cursors;var e=a.editor._editorState._nodeMap;const f=new Set;for(var h=0;h<c.length;h++){const [I,ka]=c[h];if(I!==d){f.add(I);const {anchorPos:da,focusPos:ea,name:la,color:ma,focusing:na}=ka;var g=null,k=b.get(I);void 0===k&&(k={color:ma,name:la,selection:null},b.set(I,k));if(null!==da&&null!==ea&&na){var m=w.createAbsolutePositionFromRelativePosition(da,a.doc),l=w.createAbsolutePositionFromRelativePosition(ea,a.doc);if(null!==
|
|
37
|
+
m&&null!==l){const [E,N]=Z(m.type,m.index),[fa,ha]=Z(l.type,l.index);if(null!==E&&null!==fa){l=E.getKey();var r=fa.getKey();g=k.selection;if(null===g){m=k;g=l;l=N;var t=ha,p=m.color,n=document.createElement("span");n.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:rgb(${p});z-index:10;`;var v=document.createElement("span");v.textContent=m.name;v.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;`;
|
|
38
|
+
n.appendChild(v);g={anchor:{key:g,offset:l},caret:n,color:p,focus:{key:r,offset:t},name:v,range:document.createRange(),selections:[]}}else m=g.anchor,t=g.focus,m.key=l,m.offset=N,t.key=r,t.offset=ha}}}a:{m=a;l=k;n=g;var u=e;p=m.editor;r=p.getRootElement();k=m.cursorsContainer;if(null===k||null===r)break a;g=l.selection;if(null===n){null!==g&&(l.selection=null,X(m,g));break a}else l.selection=n;t=n.range;g=n.caret;l=n.color;m=n.selections;var y=n.anchor,x=n.focus;n=y.key;v=x.key;var A=u.get(n);const E=
|
|
39
39
|
u.get(v);u=p.getElementByKey(n);p=p.getElementByKey(v);y=y.offset;x=x.offset;q.$isTextNode(A)&&(u=Y(u));q.$isTextNode(E)&&(p=Y(p));if(void 0!==A&&void 0!==E&&null!==u&&null!==p){"BR"===u.nodeName&&([u,y]=ba(u));"BR"===p.nodeName&&([p,x]=ba(p));A=u.firstChild;u===p&&null!=A&&"BR"===A.nodeName&&0===y&&0===x&&(x=1);try{t.setStart(u,y),t.setEnd(p,x)}catch(N){break a}!t.collapsed||y===x&&n===v||(t.setStart(p,x),t.setEnd(u,y));p=r.getBoundingClientRect();r=getComputedStyle(r);r=parseFloat(r.paddingLeft)+
|
|
40
|
-
parseFloat(r.paddingRight);n=Array.from(t.getClientRects());t=n.length;v=
|
|
41
|
-
for(d=0;d<c.length;d++)e=c[d],f.has(e)||(
|
|
40
|
+
parseFloat(r.paddingRight);n=Array.from(t.getClientRects());t=n.length;v=m.length;for(A=0;A<t;A++)u=n[A],u.width+r===p.width?(n.splice(A--,1),t--):(y=m[A],void 0===y&&(y=document.createElement("span"),m[A]=y,k.appendChild(y)),y.style.cssText=`position:absolute;top:${u.top}px;left:${u.left}px;height:${u.height}px;width:${u.width}px;background-color:rgba(${l}, 0.3);pointer-events:none;z-index:10;`,A===t-1&&g.parentNode!==y&&y.appendChild(g));for(g=v-1;g>=t;g--)k.removeChild(m[g]),m.pop()}}}}c=Array.from(b.keys());
|
|
41
|
+
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)))}function ja(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:h,name:g,color:k,focusing:m}=e,l=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)q.$isRangeSelection(d)&&(e=V(d.anchor,a),l=V(d.focus,a)),(W(f,e)||W(h,l))&&b.setLocalState({anchorPos:e,color:k,focusPos:l,focusing:m,name:g})}}const oa=q.createCommand(),pa=q.createCommand();
|
|
42
42
|
exports.CONNECTED_COMMAND=oa;exports.TOGGLE_CONNECT_COMMAND=pa;exports.createBinding=function(a,b,c,d,e){if(void 0===d||null===d)throw Error("Should never happen");b=d.get("root",w.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 w.UndoManager(b,{trackedOrigins:new Set([a,null])})};
|
|
43
43
|
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=ia;
|
|
44
|
-
exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,g
|
|
45
|
-
(
|
|
46
|
-
exports.syncYjsChangesToLexical=function(a,b,c){const d=a.editor,e=d._editorState;d.update(()=>{var f=d._pendingEditorState;for(var
|
|
47
|
-
T&&k instanceof w.YXmlEvent)({attributesChanged:k}=k),0<k.size&&
|
|
48
|
-
b,
|
|
44
|
+
exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,h,g){aa(a,()=>{d.read(()=>{if(g.has("collaboration")){if(0<h.size){var k=Array.from(h),m=a.collabNodeMap,l=[];for(let n=0;n<k.length;n++){var r=k[n],t=q.$getNodeByKey(r),p=m.get(r);if(p instanceof D)if(q.$isTextNode(t))l.push([p,t.__text]);else{t=p.getOffset();if(-1===t)continue;const v=p._parent;p._normalized=!0;v._xmlText.delete(t,1);m.delete(r);r=v._children;p=r.indexOf(p);r.splice(p,1)}}for(k=0;k<l.length;k++){const [n,v]=l[k];n._text=v}}}else e.has("root")&&
|
|
45
|
+
(l=c._nodeMap,k=q.$getRoot(),m=a.root,m.syncPropertiesFromLexical(a,k,l),m.syncChildrenFromLexical(a,k,l,e,f)),l=q.$getSelection(),ja(a,b,c._selection,l)})})};
|
|
46
|
+
exports.syncYjsChangesToLexical=function(a,b,c){const d=a.editor,e=d._editorState;d.update(()=>{var f=d._pendingEditorState;for(var h=0;h<c.length;h++){var g=a,k=c[h],{target:m}=k;m=P(g,m);if(m instanceof Q&&k instanceof w.YTextEvent){const {keysChanged:l,childListChanged:r,delta:t}=k;0<l.size&&m.syncPropertiesFromYjs(g,l);r&&(m.applyChildrenYjsDelta(g,t),m.syncChildrenFromYjs(g))}else if(m instanceof D&&k instanceof w.YMapEvent)({keysChanged:k}=k),0<k.size&&m.syncPropertiesAndTextFromYjs(g,k);else if(m instanceof
|
|
47
|
+
T&&k instanceof w.YXmlEvent)({attributesChanged:k}=k),0<k.size&&m.syncPropertiesFromYjs(g,k);else throw Error("Should never happen");}h=q.$getSelection();if(q.$isRangeSelection(h))if(S(h)){g=e._selection;if(q.$isRangeSelection(g)){m=z.$createOffsetView(d,0,e);f=z.$createOffsetView(d,0,f);const [l,r]=m.getOffsetsFromSelection(g);f=f.createSelectionFromOffsets(l,r,m);null!==f?q.$setSelection(f):(ca(a,b),S(h)&&(f=q.$getRoot(),0===f.getChildrenSize()&&f.append(q.$createParagraphNode()),q.$getRoot().selectEnd()))}ja(a,
|
|
48
|
+
b,g,q.$getSelection())}else ca(a,b)},{onUpdate:()=>{ia(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.2.
|
|
14
|
+
"version": "0.2.2",
|
|
15
15
|
"main": "LexicalYjs.js",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/offset": "0.2.
|
|
17
|
+
"@lexical/offset": "0.2.2"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"lexical": "0.2.
|
|
20
|
+
"lexical": "0.2.2",
|
|
21
21
|
"yjs": ">=13.5.22"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|