@lexical/yjs 0.2.0 → 0.2.3
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 +23 -7
- package/LexicalYjs.prod.js +40 -39
- 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) {
|
|
@@ -1329,17 +1337,25 @@ function updateCursor(binding, cursor, nextSelection, nodeMap) {
|
|
|
1329
1337
|
const selectionRects = Array.from(range.getClientRects());
|
|
1330
1338
|
let selectionRectsLength = selectionRects.length;
|
|
1331
1339
|
const selectionsLength = selections.length;
|
|
1340
|
+
let prevRect;
|
|
1332
1341
|
|
|
1333
1342
|
for (let i = 0; i < selectionRectsLength; i++) {
|
|
1334
|
-
const selectionRect = selectionRects[i];
|
|
1343
|
+
const selectionRect = selectionRects[i]; // Exclude a rect that is the exact same as the last rect. getClientRects() can return
|
|
1344
|
+
// the same rect twice for some elements. A more sophisticated thing to do here is to
|
|
1345
|
+
// merge all the rects together into a set of rects that don't overlap, so we don't
|
|
1346
|
+
// generate backgrounds that are too dark.
|
|
1347
|
+
|
|
1348
|
+
const isDuplicateRect = prevRect && prevRect.top === selectionRect.top && prevRect.left === selectionRect.left && prevRect.width === selectionRect.width && prevRect.height === selectionRect.height; // Exclude selections that span the entire element
|
|
1349
|
+
|
|
1350
|
+
const selectionSpansElement = selectionRect.width + rootPadding === rootRect.width;
|
|
1335
1351
|
|
|
1336
|
-
if (
|
|
1337
|
-
// Exclude selections that span the entire element
|
|
1352
|
+
if (isDuplicateRect || selectionSpansElement) {
|
|
1338
1353
|
selectionRects.splice(i--, 1);
|
|
1339
1354
|
selectionRectsLength--;
|
|
1340
1355
|
continue;
|
|
1341
1356
|
}
|
|
1342
1357
|
|
|
1358
|
+
prevRect = selectionRect;
|
|
1343
1359
|
let selection = selections[i];
|
|
1344
1360
|
|
|
1345
1361
|
if (selection === undefined) {
|
package/LexicalYjs.prod.js
CHANGED
|
@@ -6,43 +6,44 @@
|
|
|
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;
|
|
10
|
-
e;a=c.slice(e,f-g);d=d-e-g;this.spliceText(b,d,a);this._text=c}}syncPropertiesAndTextFromYjs(a,b){const c=this.getNode();if(null===c)throw Error("Should never happen");
|
|
11
|
-
function
|
|
12
|
-
function
|
|
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;G(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 g=e=0;for(;e<d&&e<f&&b[e]===c[e]&&e<a;)e++;for(;g+e<d&&g+e<f&&b[d-g-1]===c[f-g-1];)g++;for(;g+e<d&&g+e<f&&b[e]===c[e];)e++;b=
|
|
10
|
+
e;a=c.slice(e,f-g);d=d-e-g;this.spliceText(b,d,a);this._text=c}}syncPropertiesAndTextFromYjs(a,b){const c=this.getNode();if(null===c)throw Error("Should never happen");H(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 D(a,b,c,d);return a._collabNode=b}const K=new Set(["__key","__children","__parent","__cachedText","__text"]);
|
|
11
|
+
function L(a){a=q.$getNodeByKey(a);if(null===a)throw Error("Should never happen");return a}
|
|
12
|
+
function M(a,b,c){const d=b.__type;if(q.$isElementNode(b)){var e=new w.XmlText;c=N(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=I(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=P(e,c,d),c.syncPropertiesFromLexical(a,b,null);else throw Error("Should never happen");c._key=b.__key;
|
|
13
13
|
return c}
|
|
14
|
-
function
|
|
15
|
-
f)}if(b instanceof w.XmlElement)return
|
|
16
|
-
function
|
|
17
|
-
function
|
|
18
|
-
function
|
|
19
|
-
class
|
|
20
|
-
|
|
21
|
-
class
|
|
22
|
-
return a.getChildOffset(this)}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw this.getNode(),Error("Should never happen");
|
|
23
|
-
D){e=Math.min(f,p);g=0!==
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this._xmlText,this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=
|
|
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
|
|
30
|
-
if(-1===g)throw Error("Should never happen");var h=this._xmlText;0!==c&&h.delete(g,f.getSize());d instanceof
|
|
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
|
|
32
|
-
function
|
|
33
|
-
function
|
|
34
|
-
function
|
|
35
|
-
"element":"text");if(c.key!==a||c.offset!==h)c=q.$getNodeByKey(a),b.focus.set(a,h,q.$isElementNode(c)?"element":"text")}}}}function Z(a,b){a=a._collabNode;if(void 0===a)return[null,0];if(a instanceof
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
n.appendChild(
|
|
39
|
-
|
|
40
|
-
parseFloat(
|
|
41
|
-
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&&
|
|
42
|
-
|
|
43
|
-
exports.
|
|
44
|
-
exports.
|
|
45
|
-
(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
14
|
+
function Q(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?Q(a,e):c||null;if(!(a instanceof R))throw Error("Should never happen");if(b instanceof w.XmlText)return N(b,a,f);if(b instanceof w.Map){if(null===a)throw Error("Should never happen");return"linebreak"===f?C(b,a):I(b,"",a,
|
|
15
|
+
f)}if(b instanceof w.XmlElement)return P(b,a,f)}return d}function H(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 g=0;g<d.length;g++){const h=d[g];if(K.has(h))continue;var f=c[h];let k=b instanceof w.Map?b.get(h):b.getAttribute(h);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[h]=k}}}
|
|
16
|
+
function G(a,b,c,d){var e=d.__type,f=a.nodeProperties;let g=f.get(e);void 0===g&&(g=Object.keys(d).filter(k=>!K.has(k)),f.set(e,g));e=a.editor.constructor;for(f=0;f<g.length;f++){const k=g[f];var h=null===c?void 0:c[k];let m=d[k];if(h!==m){if(m instanceof e){const l=a.docMap;let t;h instanceof e&&(h=h._key,t=l.get(h),l.delete(h));h=t||new w.Doc;const u=h.guid;m._key=u;l.set(u,h);m=h;a.editor.update(()=>{d.markDirty()})}b instanceof w.Map?b.set(k,m):b.setAttribute(k,m)}}}
|
|
17
|
+
function S(a,b,c){let d=0,e=0;const f=a._children,g=f.length;for(;e<g;e++){a=f[e];const h=d,k=a.getSize();d+=k;if((c?d>=b:d>b)&&a instanceof D)return b=b-h-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: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}}
|
|
18
|
+
function T(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
|
+
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 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
|
+
G(a,this._xmlElem,c,b)}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw Error("Should never happen");H(a,this._xmlElem,c,b)}destroy(a){a.collabNodeMap.delete(this._key);this._unobservers.forEach(b=>b());this._unobservers.clear()}}function P(a,b,c){b=new U(a,b,c);return a._collabNode=b}
|
|
21
|
+
class R{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");H(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,g=e.delete;if(null!=e.retain)d+=e.retain;else if("number"===typeof g)for(f=g;0<f;){const {node:l,nodeIndex:t,offset:u,length:p}=S(this,d,!1);if(l instanceof R||l instanceof B||l instanceof U)c.splice(t,1),--f;else if(l instanceof
|
|
23
|
+
D){e=Math.min(f,p);g=0!==t?c[t-1]:null;var h=l.getSize();if(0===u&&1===e&&0<t&&g instanceof D&&p===h&&0===Array.from(l._map.keys()).length)g._text+=l._text,c.splice(t,1);else if(0===u&&e===h)c.splice(t,1);else{g=l._text;h=u;var k=e;g=g.slice(0,h)+""+g.slice(h+k);l._text=g}f-=e}else break}else if(null!=f)if("string"===typeof f){const {node:l,offset:t}=S(this,d,!0);l instanceof D?(e=l._text,g=t,h=f,e=e.slice(0,g)+h+e.slice(g+0),l._text=e):this._xmlText.delete(t,f.length);d+=f.length}else e=f,{nodeIndex:f}=
|
|
24
|
+
S(this,d,!1),e=Q(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,g=this._children,h=g.length,k=a.collabNodeMap,m=new Set;let l,t;h!==f&&(t=V(b,t,e));let u=0;for(let x=0;x<h;x++){var p=d[u];const y=g[x];var n=y.getNode(),r=y._key;if(null!==n&&p===r){n=q.$isTextNode(n);m.add(p);if(n)if(y._key=p,y instanceof
|
|
25
|
+
R)n=y._xmlText,y.syncPropertiesFromYjs(a,null),y.applyChildrenYjsDelta(a,n.toDelta()),y.syncChildrenFromYjs(a);else if(y instanceof D)y.syncPropertiesAndTextFromYjs(a,null);else if(y instanceof U)y.syncPropertiesFromYjs(a,null);else if(!(y instanceof B))throw Error("Should never happen");e[x]=p;u++}else{if(void 0===l)for(l=new Set,r=0;r<h;r++){var v=g[r]._key;""!==v&&l.add(v)}if(null===n||void 0===p||l.has(p)){t=V(b,t,e);p=a;n=y;r=c;v=n.getType();v=p.editor._nodes.get(v);if(void 0===v)throw Error("createLexicalNode failed");
|
|
26
|
+
v=new v.klass;v.__parent=r;n._key=v.__key;n instanceof R?(r=n._xmlText,n.syncPropertiesFromYjs(p,null),n.applyChildrenYjsDelta(p,r.toDelta()),n.syncChildrenFromYjs(p)):n instanceof D?n.syncPropertiesAndTextFromYjs(p,null):n instanceof U&&n.syncPropertiesFromYjs(p,null);p.collabNodeMap.set(v.__key,n);p=v.__key;k.set(p,y);e[x]=p}else x--,u++}}for(b=0;b<f;b++)e=d[b],m.has(e)||(c=L(e).getWritable(),e=a.collabNodeMap.get(e),void 0!==e&&e.destroy(a),c.__parent=null)}syncPropertiesFromLexical(a,b,c){G(a,
|
|
27
|
+
this._xmlText,this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=L(c);b instanceof R&&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 U&&q.$isDecoratorNode(c)&&b.syncPropertiesFromLexical(a,c,d)}syncChildrenFromLexical(a,b,c,d,e){var f=this.getPrevNode(c);const g=null===f?[]:f.__children;f=b.__children;const h=g.length-1,k=f.length-1,m=
|
|
28
|
+
a.collabNodeMap;let l,t,u=0;for(b=0;u<=h&&b<=k;){var p=g[u];const r=f[b];if(p===r)this._syncChildFromLexical(a,b,r,c,d,e),u++,b++;else{void 0===l&&(l=new Set(g));void 0===t&&(t=new Set(f));var n=t.has(p);p=l.has(r);n?(n=L(r),n=M(a,n,this),m.set(r,n),p?(this.splice(a,b,1,n),u++):this.splice(a,b,0,n),b++):(this.splice(a,b,1),u++)}}c=u>h;d=b>k;if(c&&!d)for(;b<=k;++b)c=f[b],d=L(c),d=M(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 R)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 U&&b.insertEmbed(c,a._xmlElem);this._children.push(a)}splice(a,b,c,d){const e=this._children;var f=e[b];if(void 0===f)if(void 0!==d)this.append(d);else throw Error("Should never happen");else{var g=f.getOffset();
|
|
30
|
+
if(-1===g)throw Error("Should never happen");var h=this._xmlText;0!==c&&h.delete(g,f.getSize());d instanceof R?h.insertEmbed(g,d._xmlText):d instanceof D?(f=d._map,null===f.parent&&h.insertEmbed(g,f),h.insert(g+1,d._text)):d instanceof B?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;const c=this._children;for(let d=0;d<c.length;d++){const e=c[d];
|
|
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 V(a,b,c){return void 0===b?(a=a.getWritable(),a.__children=c,a):b}function N(a,b,c){b=new R(a,b,c);return a._collabNode=b}
|
|
32
|
+
function W(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 X(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!w.compareRelativePositions(a,b))return!0;return!1}function Y(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
|
+
function ba(a){for(;null!=a;){if(3===a.nodeType)return a;a=a.firstChild}return null}function ca(a){const b=a.parentNode;if(null==b)throw Error("Should never happen");return[b,Array.from(b.childNodes).indexOf(a)]}
|
|
34
|
+
function da(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,h]=Z(a.type,a.index);if(null!==e&&null!==g){const k=e.getKey();a=g.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!==h)c=q.$getNodeByKey(a),b.focus.set(a,h,q.$isElementNode(c)?"element":"text")}}}}function Z(a,b){a=a._collabNode;if(void 0===a)return[null,0];if(a instanceof R){const {node:c,offset:d}=S(a,b,!0);return null===c?[a,0]:[c,d]}return[null,0]}
|
|
36
|
+
function ja(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 g=0;g<c.length;g++){const [J,la]=c[g];if(J!==d){f.add(J);const {anchorPos:ea,focusPos:fa,name:ma,color:na,focusing:oa}=la;var h=null,k=b.get(J);void 0===k&&(k={color:na,name:ma,selection:null},b.set(J,k));if(null!==ea&&null!==fa&&oa){var m=w.createAbsolutePositionFromRelativePosition(ea,a.doc),l=w.createAbsolutePositionFromRelativePosition(fa,a.doc);if(null!==
|
|
37
|
+
m&&null!==l){const [E,O]=Z(m.type,m.index),[ha,ia]=Z(l.type,l.index);if(null!==E&&null!==ha){l=E.getKey();var t=ha.getKey();h=k.selection;if(null===h){m=k;h=O;var u=ia,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 r=document.createElement("span");r.textContent=m.name;r.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(r);h={anchor:{key:l,offset:h},caret:n,color:p,focus:{key:t,offset:u},name:r,range:document.createRange(),selections:[]}}else m=h.anchor,u=h.focus,m.key=l,m.offset=O,u.key=t,u.offset=ia}}}a:{m=void 0;l=a;t=k;r=h;var v=e;n=l.editor;u=n.getRootElement();k=l.cursorsContainer;if(null===k||null===u)break a;h=t.selection;if(null===r){null!==h&&(t.selection=null,Y(l,h));break a}else t.selection=r;p=r.range;h=r.caret;t=r.color;l=r.selections;var x=r.anchor,y=r.focus;r=x.key;var F=y.key,A=v.get(r);
|
|
39
|
+
const E=v.get(F);v=n.getElementByKey(r);n=n.getElementByKey(F);x=x.offset;y=y.offset;q.$isTextNode(A)&&(v=ba(v));q.$isTextNode(E)&&(n=ba(n));if(void 0!==A&&void 0!==E&&null!==v&&null!==n){"BR"===v.nodeName&&([v,x]=ca(v));"BR"===n.nodeName&&([n,y]=ca(n));A=v.firstChild;v===n&&null!=A&&"BR"===A.nodeName&&0===x&&0===y&&(y=1);try{p.setStart(v,x),p.setEnd(n,y)}catch(O){break a}!p.collapsed||x===y&&r===F||(p.setStart(n,y),p.setEnd(v,x));n=u.getBoundingClientRect();u=getComputedStyle(u);u=parseFloat(u.paddingLeft)+
|
|
40
|
+
parseFloat(u.paddingRight);r=Array.from(p.getClientRects());p=r.length;F=l.length;for(A=0;A<p;A++)v=r[A],x=v.width+u===n.width,m&&m.top===v.top&&m.left===v.left&&m.width===v.width&&m.height===v.height||x?(r.splice(A--,1),p--):(m=v,x=l[A],void 0===x&&(x=document.createElement("span"),l[A]=x,k.appendChild(x)),x.style.cssText=`position:absolute;top:${v.top}px;left:${v.left}px;height:${v.height}px;width:${v.width}px;background-color:rgba(${t}, 0.3);pointer-events:none;z-index:10;`,A===p-1&&h.parentNode!==
|
|
41
|
+
x&&x.appendChild(h));for(m=F-1;m>=p;m--)k.removeChild(l[m]),l.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&&Y(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:k,focusing:m}=e,l=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)q.$isRangeSelection(d)&&(e=W(d.anchor,a),l=W(d.focus,a)),(X(f,e)||X(g,l))&&b.setLocalState({anchorPos:e,color:k,focusPos:l,focusing:m,name:h})}}const pa=q.createCommand(),qa=q.createCommand();exports.CONNECTED_COMMAND=pa;exports.TOGGLE_CONNECT_COMMAND=qa;
|
|
43
|
+
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=N(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])})};
|
|
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 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,g,h){aa(a,()=>{d.read(()=>{if(h.has("collaboration")){if(0<g.size){var k=Array.from(g),m=a.collabNodeMap,l=[];for(let n=0;n<k.length;n++){var t=k[n],u=q.$getNodeByKey(t),p=m.get(t);if(p instanceof D)if(q.$isTextNode(u))l.push([p,u.__text]);else{u=p.getOffset();if(-1===u)continue;const r=p._parent;p._normalized=!0;r._xmlText.delete(u,1);m.delete(t);t=r._children;p=t.indexOf(p);t.splice(p,1)}}for(k=0;k<l.length;k++){const [n,r]=l[k];n._text=r}}}else e.has("root")&&
|
|
46
|
+
(l=c._nodeMap,k=q.$getRoot(),m=a.root,m.syncPropertiesFromLexical(a,k,l),m.syncChildrenFromLexical(a,k,l,e,f)),l=q.$getSelection(),ka(a,b,c._selection,l)})})};
|
|
47
|
+
exports.syncYjsChangesToLexical=function(a,b,c){const d=a.editor,e=d._editorState;d.update(()=>{var f=d._pendingEditorState;for(var g=0;g<c.length;g++){var h=a,k=c[g],{target:m}=k;m=Q(h,m);if(m instanceof R&&k instanceof w.YTextEvent){const {keysChanged:l,childListChanged:t,delta:u}=k;0<l.size&&m.syncPropertiesFromYjs(h,l);t&&(m.applyChildrenYjsDelta(h,u),m.syncChildrenFromYjs(h))}else if(m instanceof D&&k instanceof w.YMapEvent)({keysChanged:k}=k),0<k.size&&m.syncPropertiesAndTextFromYjs(h,k);else if(m instanceof
|
|
48
|
+
U&&k instanceof w.YXmlEvent)({attributesChanged:k}=k),0<k.size&&m.syncPropertiesFromYjs(h,k);else throw Error("Should never happen");}g=q.$getSelection();if(q.$isRangeSelection(g))if(T(g)){h=e._selection;if(q.$isRangeSelection(h)){m=z.$createOffsetView(d,0,e);f=z.$createOffsetView(d,0,f);const [l,t]=m.getOffsetsFromSelection(h);f=f.createSelectionFromOffsets(l,t,m);null!==f?q.$setSelection(f):(da(a,b),T(g)&&(f=q.$getRoot(),0===f.getChildrenSize()&&f.append(q.$createParagraphNode()),q.$getRoot().selectEnd()))}ka(a,
|
|
49
|
+
b,h,q.$getSelection())}else da(a,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.2.
|
|
14
|
+
"version": "0.2.3",
|
|
15
15
|
"main": "LexicalYjs.js",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/offset": "0.2.
|
|
17
|
+
"@lexical/offset": "0.2.3"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"lexical": "0.2.
|
|
20
|
+
"lexical": "0.2.3",
|
|
21
21
|
"yjs": ">=13.5.22"
|
|
22
22
|
},
|
|
23
23
|
"repository": {
|