@lexical/yjs 0.7.2 → 0.7.4
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 +49 -13
- package/LexicalYjs.prod.js +40 -39
- package/package.json +3 -3
package/LexicalYjs.dev.js
CHANGED
|
@@ -1237,6 +1237,23 @@ function createRelativePosition(point, binding) {
|
|
|
1237
1237
|
}
|
|
1238
1238
|
|
|
1239
1239
|
offset = currentOffset + 1 + offset;
|
|
1240
|
+
} else if (collabNode instanceof CollabElementNode && point.type === 'element') {
|
|
1241
|
+
const parent = point.getNode();
|
|
1242
|
+
let accumulatedOffset = 0;
|
|
1243
|
+
let i = 0;
|
|
1244
|
+
let node = parent.getFirstChild();
|
|
1245
|
+
|
|
1246
|
+
while (node !== null && i++ < offset) {
|
|
1247
|
+
if (lexical.$isTextNode(node)) {
|
|
1248
|
+
accumulatedOffset += node.getTextContentSize() + 1;
|
|
1249
|
+
} else {
|
|
1250
|
+
accumulatedOffset++;
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
node = node.getNextSibling();
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
offset = accumulatedOffset;
|
|
1240
1257
|
}
|
|
1241
1258
|
|
|
1242
1259
|
return yjs.createRelativePositionFromTypeIndex(sharedType, offset);
|
|
@@ -1355,14 +1372,26 @@ function updateCursor(binding, cursor, nextSelection, nodeMap) {
|
|
|
1355
1372
|
return;
|
|
1356
1373
|
}
|
|
1357
1374
|
|
|
1358
|
-
|
|
1375
|
+
let selectionRects; // In the case of a collapsed selection on a linebreak, we need
|
|
1376
|
+
// to improvise as the browser will return nothing here as <br>
|
|
1377
|
+
// apparantly take up no visual space :/
|
|
1378
|
+
// This won't work in all cases, but it's better than just showing
|
|
1379
|
+
// nothing all the time.
|
|
1359
1380
|
|
|
1360
|
-
if (
|
|
1361
|
-
|
|
1381
|
+
if (anchorNode === focusNode && lexical.$isLineBreakNode(anchorNode)) {
|
|
1382
|
+
const brRect = editor.getElementByKey(anchorKey).getBoundingClientRect();
|
|
1383
|
+
selectionRects = [brRect];
|
|
1384
|
+
} else {
|
|
1385
|
+
const range = selection.createDOMRange(editor, anchorNode, anchor.offset, focusNode, focus.offset);
|
|
1386
|
+
|
|
1387
|
+
if (range === null) {
|
|
1388
|
+
return;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
selectionRects = selection.createRectsFromDOMRange(editor, range);
|
|
1362
1392
|
}
|
|
1363
1393
|
|
|
1364
1394
|
const selectionsLength = selections.length;
|
|
1365
|
-
const selectionRects = selection.createRectsFromDOMRange(editor, range);
|
|
1366
1395
|
const selectionRectsLength = selectionRects.length;
|
|
1367
1396
|
|
|
1368
1397
|
for (let i = 0; i < selectionRectsLength; i++) {
|
|
@@ -1427,18 +1456,25 @@ function syncLocalCursorPosition(binding, provider) {
|
|
|
1427
1456
|
|
|
1428
1457
|
const anchor = selection.anchor;
|
|
1429
1458
|
const focus = selection.focus;
|
|
1459
|
+
setPoint(anchor, anchorKey, anchorOffset);
|
|
1460
|
+
setPoint(focus, focusKey, focusOffset);
|
|
1461
|
+
}
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1430
1465
|
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
}
|
|
1466
|
+
function setPoint(point, key, offset) {
|
|
1467
|
+
if (point.key !== key || point.offset !== offset) {
|
|
1468
|
+
let anchorNode = lexical.$getNodeByKey(key);
|
|
1435
1469
|
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1470
|
+
if (anchorNode !== null && !lexical.$isElementNode(anchorNode) && !lexical.$isTextNode(anchorNode)) {
|
|
1471
|
+
const parent = anchorNode.getParentOrThrow();
|
|
1472
|
+
key = parent.getKey();
|
|
1473
|
+
offset = anchorNode.getIndexWithinParent();
|
|
1474
|
+
anchorNode = parent;
|
|
1441
1475
|
}
|
|
1476
|
+
|
|
1477
|
+
point.set(key, offset, lexical.$isElementNode(anchorNode) ? 'element' : 'text');
|
|
1442
1478
|
}
|
|
1443
1479
|
}
|
|
1444
1480
|
|
package/LexicalYjs.prod.js
CHANGED
|
@@ -4,46 +4,47 @@
|
|
|
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
|
|
8
|
-
class C{constructor(a,b){this._key="";this._map=a;this._parent=b;this._type="linebreak"}getNode(){let a=
|
|
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
|
|
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=
|
|
11
|
-
d,a);this._text=c}}syncPropertiesAndTextFromYjs(a,b){let c=this.getNode();null===c&&
|
|
12
|
-
function L(a,b,c){let d=b.__type;if(
|
|
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&&
|
|
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 k=b instanceof v.Map?b.get(g):b.getAttribute(g);if(f!==k){if(k instanceof v.Doc){let n=a.docMap;f instanceof v.Doc&&n.delete(f.guid);f=
|
|
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(k=>!J.has(k)),f.set(e,h));e=a.editor.constructor;for(f=0;f<h.length;f++){let k=h[f];var g=null===c?void 0:c[k];let n=d[k];if(g!==n){if(n instanceof e){let
|
|
7
|
+
'use strict';var t=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.");}
|
|
8
|
+
class C{constructor(a,b){this._key="";this._map=a;this._parent=b;this._type="linebreak"}getNode(){let a=t.$getNodeByKey(this._key);return t.$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
|
+
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 t.$isTextNode(a)?a:null}getNode(){let a=t.$getNodeByKey(this._key);return t.$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
|
+
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=t.$getSelection();a=c.length;t.$isRangeSelection(e)&&e.isCollapsed()&&(e=e.anchor,e.key===d&&(a=e.offset));d=b.length;let f=c.length,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=e;a=c.slice(e,f-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 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
|
+
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
|
+
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 k=b instanceof v.Map?b.get(g):b.getAttribute(g);if(f!==k){if(k instanceof v.Doc){let n=a.docMap;f instanceof v.Doc&&n.delete(f.guid);f=t.createEditor();let q=k.guid;f._key=q;n.set(q,k);k=f}void 0===e&&(e=c.getWritable());e[g]=k}}}
|
|
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(k=>!J.has(k)),f.set(e,h));e=a.editor.constructor;for(f=0;f<h.length;f++){let k=h[f];var g=null===c?void 0:c[k];let n=d[k];if(g!==n){if(n instanceof e){let q=a.docMap,m;g instanceof e&&(g=g._key,m=q.get(g),q.delete(g));g=m||new v.Doc;let l=g.guid;n._key=l;q.set(l,g);n=g;a.editor.update(()=>{d.markDirty()})}b instanceof v.Map?b.set(k,n):b.setAttribute(k,n)}}}
|
|
16
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,k=a.getSize();d+=k;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
|
-
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()||
|
|
18
|
-
function S(a,b){let c=[];for(a=a.__first;null!==a;){let d=null===b?
|
|
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)}
|
|
18
|
+
function S(a,b){let c=[];for(a=a.__first;null!==a;){let d=null===b?t.$getNodeByKey(a):b.get(a);if(null===d||void 0===d)throw Error("createChildrenArray: node does not exist in nodeMap");c.push(a);a=d.__next}return c}
|
|
19
19
|
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,
|
|
20
20
|
a.__prev=c.__key):a.__prev=null,e.__next=null);b.__size--;e.__parent=null}}
|
|
21
|
-
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
|
|
22
|
-
F(a,this._xmlElem,c,b)}syncPropertiesFromYjs(a,b){let c=this.getNode();null===c&&
|
|
23
|
-
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
|
|
24
|
-
b){let c=this.getNode();null===c&&
|
|
25
|
-
m._text,c.splice(l,1);else if(0===
|
|
26
|
-
null===b&&
|
|
27
|
-
null):
|
|
28
|
-
null);l.collabNodeMap.set(
|
|
29
|
-
this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=K(c);b instanceof P&&
|
|
30
|
-
0;l<=g&&b<=k;){var
|
|
31
|
-
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&&
|
|
21
|
+
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);
|
|
22
|
+
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}
|
|
23
|
+
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,
|
|
24
|
+
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 q=0;q<b.length;q++){var e=b[q],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:m,nodeIndex:l,offset:p,length:u}=Q(this,d,!1);if(m instanceof P||m instanceof C||m instanceof U)c.splice(l,1),--f;else if(m instanceof E){e=Math.min(f,u);h=0!==l?c[l-1]:null;var g=m.getSize();if(0===p&&1===e&&0<l&&h instanceof E&&u===g&&0===Array.from(m._map.keys()).length)h._text+=
|
|
25
|
+
m._text,c.splice(l,1);else if(0===p&&e===g)c.splice(l,1);else{h=m;g=m._text;var k=p,n=e;g=g.slice(0,k)+""+g.slice(k+n);h._text=g}f-=e}else break}else if(null!=f)if("string"===typeof f){let {node:m,offset:l}=Q(this,d,!0);m instanceof E?(e=m,h=m._text,g=l,k=f,h=h.slice(0,g)+k+h.slice(g+0),e._text=h):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();
|
|
26
|
+
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,k=new Set,n;let q=0;var m=null;h!==e&&b.getWritable();for(let x=0;x<h;x++){var l=d[q],p=f[x];var u=p.getNode();var r=p._key;if(null!==u&&l===r)m=t.$isTextNode(u),k.add(l),m&&(p._key=l,p instanceof P?(m=p._xmlText,p.syncPropertiesFromYjs(a,null),p.applyChildrenYjsDelta(a,m.toDelta()),p.syncChildrenFromYjs(a)):p instanceof E?p.syncPropertiesAndTextFromYjs(a,null):p instanceof U?p.syncPropertiesFromYjs(a,
|
|
27
|
+
null):p instanceof C||B(93)),m=u,q++;else{if(void 0===n)for(n=new Set,r=0;r<h;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=p;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,
|
|
28
|
+
null);l.collabNodeMap.set(A.__key,r);l=A;r=l.__key;g.set(r,p);null===m?(m=u.getFirstChild(),u.__first=r,null!==m&&(m=m.getWritable(),m.__prev=r,l.__next=m.__key)):(p=m.getWritable(),w=m.getNextSibling(),p.__next=r,l.__prev=m.__key,null!==w&&(m=w.getWritable(),m.__prev=r,l.__next=m.__key));x===h-1&&(u.__last=r);u.__size++;m=l}else p=K(l),T(p),x--,q++}}for(b=0;b<e;b++)f=d[b],k.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,
|
|
29
|
+
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,k=f.length-1,n=a.collabNodeMap,q,m,l=0;for(b=
|
|
30
|
+
0;l<=g&&b<=k;){var p=h[l];let r=f[b];if(p===r)this._syncChildFromLexical(a,b,r,c,d,e),l++,b++;else{void 0===q&&(q=new Set(h));void 0===m&&(m=new Set(f));var u=m.has(p);p=q.has(r);u?(u=K(r),u=L(a,u,this),n.set(r,u),p?(this.splice(a,b,1,u),l++):this.splice(a,b,0,u),b++):(this.splice(a,b,1),l++)}}c=l>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),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;
|
|
31
|
+
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
|
|
32
32
|
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);
|
|
33
|
-
b.delete(this._key)}}function M(a,b,c){b=new P(a,b,c);return a._collabNode=b}
|
|
34
|
-
function
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
exports.
|
|
45
|
-
exports.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
33
|
+
b.delete(this._key)}}function M(a,b,c){b=new P(a,b,c);return a._collabNode=b}
|
|
34
|
+
function V(a,b){var c=b.collabNodeMap.get(a.key);if(void 0===c)return null;b=a.offset;let d=c.getSharedType();if(c instanceof E){d=c._parent._xmlText;a=c.getOffset();if(-1===a)return null;b=a+1+b}else if(c instanceof P&&"element"===a.type){let e=c=0;for(a=a.getNode().getFirstChild();null!==a&&e++<b;)t.$isTextNode(a)?c+=a.getTextContentSize()+1:c++,a=a.getNextSibling();b=c}return v.createRelativePositionFromTypeIndex(d,b)}
|
|
35
|
+
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])}}
|
|
36
|
+
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))}}}
|
|
37
|
+
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]}
|
|
38
|
+
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,k=b.get(H);void 0===k&&(k={color:na,name:ma,selection:null},b.set(H,k));if(null!==ca&&null!==da&&oa){var n=v.createAbsolutePositionFromRelativePosition(ca,a.doc),q=v.createAbsolutePositionFromRelativePosition(da,a.doc);if(null!==
|
|
39
|
+
n&&null!==q){let [ea,fa]=Z(n.type,n.index),[ha,ia]=Z(q.type,q.index);if(null!==ea&&null!==ha){n=ea.getKey();var m=ha.getKey();g=k.selection;if(null===g){g=k;q=fa;var l=ia,p=g.color,u=document.createElement("span");u.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${p};z-index:10;`;var r=document.createElement("span");r.textContent=g.name;r.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;`;
|
|
40
|
+
u.appendChild(r);g={anchor:{key:n,offset:q},caret:u,color:p,focus:{key:m,offset:l},name:r,selections:[]}}else q=g.anchor,l=g.focus,q.key=n,q.offset=fa,l.key=m,l.offset=ia}}}a:if(n=a,q=k,u=g,p=e,l=n.editor,g=l.getRootElement(),k=n.cursorsContainer,null!==k&&null!==g&&(g=k.offsetParent,null!==g))if(g=g.getBoundingClientRect(),m=q.selection,null===u)null!==m&&(q.selection=null,X(n,m));else{q.selection=u;q=u.caret;m=u.color;n=u.selections;r=u.anchor;u=u.focus;var w=r.key,A=u.key,x=p.get(w);p=p.get(A);
|
|
41
|
+
if(null!=x&&null!=p){if(x===p&&t.$isLineBreakNode(x))p=[l.getElementByKey(w).getBoundingClientRect()];else{p=y.createDOMRange(l,x,r.offset,p,u.offset);if(null===p)break a;p=y.createRectsFromDOMRange(l,p)}u=n.length;l=p.length;for(r=0;r<l;r++)x=p[r],w=n[r],void 0===w&&(w=document.createElement("span"),n[r]=w,A=document.createElement("span"),w.appendChild(A),k.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;`,
|
|
42
|
+
w.style.cssText=x,w.firstChild.style.cssText=`${x}left:0;top:0;background-color:${m};opacity:0.3;`,r===l-1&&q.parentNode!==w&&w.appendChild(q);for(g=u-1;g>=l;g--)k.removeChild(n[g]),n.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)))}
|
|
43
|
+
function ka(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:h,name:g,color:k,focusing:n}=e,q=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)t.$isRangeSelection(d)&&(e=V(d.anchor,a),q=V(d.focus,a)),(W(f,e)||W(h,q))&&b.setLocalState({anchorPos:e,color:k,focusPos:q,focusing:n,name:g})}}let pa=t.createCommand("CONNECTED_COMMAND"),qa=t.createCommand("TOGGLE_CONNECT_COMMAND");exports.CONNECTED_COMMAND=pa;exports.TOGGLE_CONNECT_COMMAND=qa;
|
|
44
|
+
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})};
|
|
45
|
+
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;
|
|
46
|
+
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),n=a.collabNodeMap,q=[];for(let u=0;u<k.length;u++){var m=k[u],l=t.$getNodeByKey(m),p=n.get(m);if(p instanceof E)if(t.$isTextNode(l))q.push([p,l.__text]);else{l=p.getOffset();if(-1===l)continue;let r=p._parent;p._normalized=!0;r._xmlText.delete(l,1);n.delete(m);m=r._children;p=m.indexOf(p);m.splice(p,1)}}for(k=0;k<q.length;k++){let [u,r]=q[k];u instanceof E&&"string"===
|
|
47
|
+
typeof r&&(u._text=r)}}}else e.has("root")&&(q=c._nodeMap,k=t.$getRoot(),n=a.root,n.syncPropertiesFromLexical(a,k,q),n.syncChildrenFromLexical(a,k,q,e,f)),q=t.$getSelection(),ka(a,b,c._selection,q)})})};
|
|
48
|
+
exports.syncYjsChangesToLexical=function(a,b,c){let 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:n}=k;n=O(g,n);if(n instanceof P&&k instanceof v.YTextEvent){let {keysChanged:q,childListChanged:m,delta:l}=k;0<q.size&&n.syncPropertiesFromYjs(g,q);m&&(n.applyChildrenYjsDelta(g,l),n.syncChildrenFromYjs(g))}else n instanceof E&&k instanceof v.YMapEvent?({keysChanged:k}=k,0<k.size&&n.syncPropertiesAndTextFromYjs(g,k)):n instanceof
|
|
49
|
+
U&&k instanceof v.YXmlEvent?({attributesChanged:k}=k,0<k.size&&n.syncPropertiesFromYjs(g,k)):B(82)}h=t.$getSelection();if(t.$isRangeSelection(h))if(R(h)){g=e._selection;if(t.$isRangeSelection(g)){n=z.$createOffsetView(d,0,e);f=z.$createOffsetView(d,0,f);let [q,m]=n.getOffsetsFromSelection(g);f=f.createSelectionFromOffsets(q,m,n);null!==f?t.$setSelection(f):(Y(a,b),R(h)&&(f=t.$getRoot(),0===f.getChildrenSize()&&f.append(t.$createParagraphNode()),t.$getRoot().selectEnd()))}ka(a,b,g,t.$getSelection())}else Y(a,
|
|
50
|
+
b)},{onUpdate:()=>{ja(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.7.
|
|
14
|
+
"version": "0.7.4",
|
|
15
15
|
"main": "LexicalYjs.js",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/offset": "0.7.
|
|
17
|
+
"@lexical/offset": "0.7.4"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"lexical": "0.7.
|
|
20
|
+
"lexical": "0.7.4",
|
|
21
21
|
"yjs": ">=13.5.22"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|