@lexical/yjs 0.1.1 → 0.1.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/index.js +51 -48
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,49 +1,52 @@
|
|
|
1
|
-
'use strict';var r=require("yjs"),
|
|
2
|
-
class z{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
|
|
3
|
-
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;B(a,this._map,d,b);if(null!==d&&(a=d.__text,a!==c)){d=b.__key;b=a;var e=
|
|
4
|
-
d-
|
|
5
|
-
class F{constructor(a,b){this._key="";this._map=a;this._parent=b;this._type="linebreak"}getNode(){const a=
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
'use strict';var r=require("yjs"),x=require("lexical"),aa=require("lexical/ParagraphNode");
|
|
2
|
+
class z{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 x.$isTextNode(a)?a:null}getNode(){const a=x.$getNodeByKey(this._key);return x.$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=
|
|
3
|
+
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;B(a,this._map,d,b);if(null!==d&&(a=d.__text,a!==c)){d=b.__key;b=a;var e=x.$getSelection();a=c.length;null!==e&&e.isCollapsed()&&(e=e.anchor,e.key===d&&(a=e.offset));const f=b.length;d=c.length;let h=e=0;for(;e<f&&e<d&&b[e]===c[e]&&e<a;)e++;for(;h+e<f&&h+e<d&&b[f-h-1]===c[d-h-1];)h++;for(;h+e<f&&h+e<d&&b[e]===c[e];)e++;b=e;a=f-e-h;d=c.slice(e,
|
|
4
|
+
d-h);this.spliceText(b,a,d);this._text=c}}syncPropertiesAndTextFromYjs(a,b){const c=this.getNode();if(null===c)throw Error("Should never happen");C(a,this._map,c,b);a=this._text;c.__text!==a&&(c.getWritable().__text=a)}destroy(a){a.collabNodeMap.delete(this._key)}}function D(a,b,c,d){b=new z(a,b,c,d);return a._collabNode=b}
|
|
5
|
+
class F{constructor(a,b){this._key="";this._map=a;this._parent=b;this._type="linebreak"}getNode(){const a=x.$getNodeByKey(this._key);return x.$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 G(a,b){b=new F(a,b);return a._collabNode=b}
|
|
6
|
+
function H(a,b,c){b=b._map;const d=Array.from(b.keys());for(let h=0;h<d.length;h++){var e=d[h],f=b.get(e);let g=c.get(e);if(f!==g)if(x.isDecoratorMap(f))void 0===g&&(g=new r.Map,g.set("type","map"),c.set(e,g)),H(a,f,g);else if(x.isDecoratorEditor(f)){let l;void 0===g&&(g=new r.Map,g._lexicalValue=f,l=new r.Doc,g.set("doc",l),g.set("type","editor"),c.set(e,g));l=l||g.get("doc");e=g.get("id");f=f.id;if(e!==f){const k=a.docMap;k.delete(e);g.set("id",f);k.set(f,l)}}else c.set(e,f)}}
|
|
7
|
+
function I(a,b,c,d){c=c._map;d=null===d?Array.from(b.keys()):Array.from(d);for(let h=0;h<d.length;h++){const g=d[h];var e=c.get(g);const l=b.get(g);if(e!==l)if(l instanceof r.Map){var f=l.get("type");e=l._lexicalValue;if("editor"===f){if(void 0===e){f=a.docMap;const k=l.get("id"),m=l.get("doc");e=x.createDecoratorEditor(k);l._lexicalValue=e;f.set(k,m);c.set(g,e)}}else if("map"===f)void 0===e&&(e=x.createDecoratorMap(a.editor),l._lexicalValue=e,c.set(g,e)),I(a,l,e,null);else throw Error("Should never happen");
|
|
8
|
+
}else c.set(g,l)}}
|
|
9
|
+
class K{constructor(a,b,c){this._key="";this._xmlElem=a;this._parent=b;this._type=c}getPrevNode(a){if(null===a)return null;a=a.get(this._key);return x.$isDecoratorNode(a)?a:null}getNode(){const a=x.$getNodeByKey(this._key);return x.$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){const d=this.getPrevNode(c);c=this._xmlElem;const e=
|
|
10
|
+
null===d?null:d.__state,f=b.__state;B(a,c,d,b);e!==f&&(b=new r.Map,c.insert(0,[b]),b._lexicalValue=f,H(a,f,b))}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw Error("Should never happen");const d=this._xmlElem,e=d.firstChild,f=c.__state;C(a,d,c,b);I(a,e,f,null)}destroy(a){a.collabNodeMap.delete(this._key)}}function L(a,b,c){b=new K(a,b,c);return a._collabNode=b}const M=new Set("__key __children __parent __cachedText __text __state".split(" "));
|
|
11
|
+
function N(a){a=x.$getNodeByKey(a);if(null===a)throw Error("Should never happen");return a}
|
|
12
|
+
function P(a,b,c){const d=b.__type;if(x.$isElementNode(b)){var e=new r.XmlText;c=Q(e,c,d);c.syncPropertiesFromLexical(a,b,null);c.syncChildrenFromLexical(a,b,null,null,null)}else if(x.$isTextNode(b))e=new r.Map,c=D(e,b.__text,c,d),c.syncPropertiesAndTextFromLexical(a,b,null);else if(x.$isLineBreakNode(b))a=new r.Map,a.set("__type","linebreak"),c=G(a,c);else if(x.$isDecoratorNode(b))e=new r.XmlElement,c=L(e,c,d),c.syncPropertiesFromLexical(a,b,null);else throw Error("Should never happen");c._key=b.__key;
|
|
10
13
|
return c}
|
|
11
|
-
function
|
|
12
|
-
D(b,"",a,f)}if(b instanceof r.XmlElement)return
|
|
13
|
-
function B(a,b,c,d){var e=d.__type,f=a.nodeProperties;a=f.get(e);void 0===a&&(a=Object.keys(d).filter(
|
|
14
|
-
function
|
|
15
|
-
function
|
|
16
|
-
class
|
|
17
|
-
return a.getChildOffset(this)}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw this.getNode(),Error("Should never happen");C(a,this._xmlText,c,b)}applyChildrenYjsDelta(a,b){const c=this._children;let d=0;for(let k=0;k<b.length;k++){var e=b[k],f=e.insert,
|
|
18
|
-
z){e=Math.min(f,p);
|
|
19
|
-
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,
|
|
20
|
-
null),w.applyChildrenYjsDelta(a,n.toDelta()),w.syncChildrenFromYjs(a);else if(w instanceof z)w.syncPropertiesAndTextFromYjs(a,null);else if(w instanceof
|
|
21
|
-
new v.klass;v.__parent=u;n._key=v.__key;n instanceof
|
|
22
|
-
this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=
|
|
23
|
-
let
|
|
24
|
-
var c=this._children;c=c[c.length-1];c=void 0!==c?c.getOffset()+c.getSize():0;if(a instanceof
|
|
25
|
-
var
|
|
26
|
-
a.collabNodeMap,c=this._children;for(let d=0;d<c.length;d++)c[d].destroy(a);b.delete(this._key)}}function
|
|
27
|
-
function
|
|
28
|
-
function
|
|
29
|
-
b.anchor.set(c,f,
|
|
30
|
-
function
|
|
31
|
-
if(null!==k&&null!==
|
|
32
|
-
n.appendChild(u);
|
|
33
|
-
v.get(u);v=p.getElementByKey(n);p=p.getElementByKey(u);
|
|
34
|
-
parseFloat(q.paddingRight);n=Array.from(t.getClientRects());t=n.length;u=k.length;for(A=0;A<t;A++)v=n[A],v.width+q===p.width?(n.splice(A--,1),t--):(
|
|
35
|
-
for(d=0;d<c.length;d++)e=c[d],f.has(e)||(
|
|
36
|
-
class
|
|
37
|
-
|
|
38
|
-
a.anchor,c=a.focus,d=this._offsetMap;const e=b.offset;var f=c.offset;let
|
|
39
|
-
function
|
|
40
|
-
b;)a=b.key,
|
|
41
|
-
function
|
|
42
|
-
start:
|
|
43
|
-
exports.createBinding=function(a,b,c,d){b=d.get(c);if(void 0===b)throw Error("Should never happen");var e=b.get("root",r.XmlText);e=
|
|
44
|
-
exports.initLocalState=function(a,b,c,d){a.awareness.setLocalState({color:c,name:b,anchorPos:null,focusPos:null,focusing:d})};exports.setLocalStateFocus=function(a,b){({awareness:a}=a);a.setLocalState({...a.getLocalState(),focusing:b})};exports.syncCursorPositions=
|
|
45
|
-
exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,g
|
|
46
|
-
u]=l
|
|
47
|
-
exports.syncYjsChangesToLexical=function(a,b,c){const d=a.editor,e=d._editorState;d.update(()=>{var f=d._pendingEditorState;for(var
|
|
48
|
-
|
|
49
|
-
{
|
|
14
|
+
function R(a,b,c){const d=b._collabNode;if(void 0===d){var e=a.editor._registeredNodes;const f=b instanceof r.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?R(a,e):c||null;if(!(a instanceof S))throw Error("Should never happen");if(b instanceof r.XmlText)return Q(b,a,f);if(b instanceof r.Map){if(null===a)throw Error("Should never happen");return"linebreak"===f?G(b,a):
|
|
15
|
+
D(b,"",a,f)}if(b instanceof r.XmlElement)return L(b,a,f)}return d}function C(a,b,c,d){a=null===d?b instanceof r.Map?Array.from(b.keys()):Object.keys(b.getAttributes()):Array.from(d);let e;for(d=0;d<a.length;d++){const f=a[d];if(M.has(f))continue;const h=c[f],g=b instanceof r.Map?b.get(f):b.getAttribute(f);h!==g&&(void 0===e&&(e=c.getWritable()),e[f]=g)}}
|
|
16
|
+
function B(a,b,c,d){var e=d.__type,f=a.nodeProperties;a=f.get(e);void 0===a&&(a=Object.keys(d).filter(h=>!M.has(h)),f.set(e,a));for(e=0;e<a.length;e++){f=a[e];const h=d[f];(null===c?void 0:c[f])!==h&&(b instanceof r.Map?b.set(f,h):b.setAttribute(f,h))}}
|
|
17
|
+
function T(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,l=a.getSize();d+=l;if((c?d>=b:d>b)&&a instanceof z)return b=b-g-1,0>b&&(b=0),{node:a,nodeIndex:e,offset:b,length:l-b};if(d>b)return{node:a,nodeIndex:e,offset:g,length:0};if(e===h-1)return{node:null,nodeIndex:e+1,offset:g+1,length:0}}return{node:null,nodeIndex:0,offset:0,length:0}}
|
|
18
|
+
function U(a){const b=a.anchor;a=a.focus;let c=!1;try{const d=b.getNode(),e=a.getNode();if(!d.isAttached()||!e.isAttached()||x.$isTextNode(d)&&b.offset>d.getTextContentSize()||x.$isTextNode(e)&&a.offset>e.getTextContentSize())c=!0}catch(d){c=!0}return c}
|
|
19
|
+
class S{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 x.$isElementNode(a)?a:null}getNode(){const a=x.$getNodeByKey(this._key);return x.$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");
|
|
20
|
+
return a.getChildOffset(this)}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw this.getNode(),Error("Should never happen");C(a,this._xmlText,c,b)}applyChildrenYjsDelta(a,b){const c=this._children;let d=0;for(let k=0;k<b.length;k++){var e=b[k],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:m,nodeIndex:q,offset:t,length:p}=T(this,d,!1);if(m instanceof S||m instanceof F||m instanceof K)c.splice(q,1),--f;else if(m instanceof
|
|
21
|
+
z){e=Math.min(f,p);h=0!==q?c[q-1]:null;var g=m.getSize();if(0===t&&1===e&&0<q&&h instanceof z&&p===g)h._text+=m._text,c.splice(q,1);else if(0===t&&e===g)c.splice(q,1);else{h=m._text;g=t;var l=e;h=h.slice(0,g)+""+h.slice(g+l);m._text=h}f-=e}else break}else if(null!=f)if("string"===typeof f){const {node:m,offset:q}=T(this,d,!0);m instanceof z?(e=m._text,h=q,g=f,e=e.slice(0,h)+g+e.slice(h+0),m._text=e):this._xmlText.delete(q,f.length);d+=f.length}else e=f,{nodeIndex:f}=T(this,d,!1),e=R(a,e,this),c.splice(f,
|
|
22
|
+
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,l=a.collabNodeMap,k=new Set;let m,q;g!==f&&(q=V(b,q,e));let t=0;for(let y=0;y<g;y++){var p=d[t];const w=h[y];var n=w.getNode(),u=w._key;if(null!==n&&p===u){n=x.$isTextNode(n);k.add(p);if(n)if(w._key=p,w instanceof S)n=w._xmlText,w.syncPropertiesFromYjs(a,
|
|
23
|
+
null),w.applyChildrenYjsDelta(a,n.toDelta()),w.syncChildrenFromYjs(a);else if(w instanceof z)w.syncPropertiesAndTextFromYjs(a,null);else if(w instanceof K)w.syncPropertiesFromYjs(a,null);else if(!(w instanceof F))throw Error("Should never happen");e[y]=p;t++}else{if(void 0===m)for(m=new Set,u=0;u<g;u++){var v=h[u]._key;""!==v&&m.add(v)}if(null===n||void 0===p||m.has(p)){q=V(b,q,e);p=a;n=w;u=c;v=n.getType();v=p.editor._registeredNodes.get(v);if(void 0===v)throw Error("createLexicalNode failed");v=
|
|
24
|
+
new v.klass;v.__parent=u;n._key=v.__key;n instanceof S?(u=n._xmlText,n.syncPropertiesFromYjs(p,null),n.applyChildrenYjsDelta(p,u.toDelta()),n.syncChildrenFromYjs(p)):n instanceof z?n.syncPropertiesAndTextFromYjs(p,null):n instanceof K&&n.syncPropertiesFromYjs(p,null);p.collabNodeMap.set(v.__key,n);p=v.__key;l.set(p,w);e[y]=p}else y--,t++}}for(b=0;b<f;b++)e=d[b],k.has(e)||(c=N(e).getWritable(),e=a.collabNodeMap.get(e),void 0!==e&&e.destroy(a),c.__parent=null)}syncPropertiesFromLexical(a,b,c){B(a,this._xmlText,
|
|
25
|
+
this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=N(c);b instanceof S&&x.$isElementNode(c)?(b.syncPropertiesFromLexical(a,c,d),b.syncChildrenFromLexical(a,c,d,e,f)):b instanceof z&&x.$isTextNode(c)?b.syncPropertiesAndTextFromLexical(a,c,d):b instanceof K&&x.$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,l=f.length-1,k=a.collabNodeMap;
|
|
26
|
+
let m,q,t=0;for(b=0;t<=g&&b<=l;){var p=h[t];const u=f[b];if(p===u)this._syncChildFromLexical(a,b,u,c,d,e),t++,b++;else{void 0===m&&(m=new Set(h));void 0===q&&(q=new Set(f));var n=q.has(p);p=m.has(u);n?(n=N(u),n=P(a,n,this),k.set(u,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>l;if(c&&!d)for(;b<=l;++b)c=f[b],d=N(c),d=P(a,d,this),this.append(d),k.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=this._xmlText;
|
|
27
|
+
var c=this._children;c=c[c.length-1];c=void 0!==c?c.getOffset()+c.getSize():0;if(a instanceof S)b.insertEmbed(c,a._xmlText);else if(a instanceof z){const d=a._map;null===d.parent&&b.insertEmbed(c,d);b.insert(c+1,a._text)}else a instanceof F?b.insertEmbed(c,a._map):a instanceof K&&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();if(-1===h)throw Error("Should never happen");
|
|
28
|
+
var g=this._xmlText;0!==c&&g.delete(h,f.getSize());d instanceof S?g.insertEmbed(h,d._xmlText):d instanceof z?(f=d._map,null===f.parent&&g.insertEmbed(h,f),g.insert(h+1,d._text)):d instanceof F?g.insertEmbed(h,d._map):d instanceof K&&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];if(e===a)return b;b+=e.getSize()}return-1}destroy(a){const b=
|
|
29
|
+
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 Q(a,b,c){b=new S(a,b,c);return a._collabNode=b}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 z){c=b._parent._xmlText;b=b.getOffset();if(-1===b)return null;a=b+1+a}return r.createRelativePositionFromTypeIndex(c,a)}
|
|
30
|
+
function X(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!r.compareRelativePositions(a,b))return!0;return!1}function ba(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])}}function ca(a){for(;null!=a;){if(3===a.nodeType)return a;a=a.firstChild}return null}function da(a){const b=a.parentNode;if(null==b)throw Error("Should never happen");return[b,Array.from(b.childNodes).indexOf(a)]}
|
|
31
|
+
function ea(a,b){var c=b.awareness.getLocalState();if(null!==c&&(b=c.anchorPos,c=c.focusPos,null!==b&&null!==c&&(b=r.createAbsolutePositionFromRelativePosition(b,a.doc),a=r.createAbsolutePositionFromRelativePosition(c,a.doc),null!==b&&null!==a))){const [e,f]=Y(b.type,b.index),[h,g]=Y(a.type,a.index);if(null!==e&&null!==h){c=e.getKey();a=h.getKey();b=x.$getSelection();if(null===b)throw Error("TODO: syncLocalCursorPosition");var d=b.anchor;const l=b.focus;if(d.key!==c||d.offset!==f)d=x.$getNodeByKey(c),
|
|
32
|
+
b.anchor.set(c,f,x.$isElementNode(d)?"element":"text");if(l.key!==a||l.offset!==g)c=x.$getNodeByKey(a),b.focus.set(a,g,x.$isElementNode(c)?"element":"text")}}}function Y(a,b){a=a._collabNode;if(void 0===a)return[null,0];if(a instanceof S){const {node:c,offset:d}=T(a,b,!0);return null===c?[a,0]:[c,d]}return[null,0]}
|
|
33
|
+
function ka(a,b){var c=Array.from(b.awareness.getStates()),d=a.doc.clientID;b=a.cursors;var e=a.editor._editorState._nodeMap;const f=new Set;for(var h=0;h<c.length;h++){const [J,pa]=c[h];if(J!==d){f.add(J);const {anchorPos:fa,focusPos:ha,name:qa,color:ra,focusing:sa}=pa;var g=null,l=b.get(J);void 0===l&&(l={color:ra,name:qa,selection:null},b.set(J,l));if(null!==fa&&null!==ha&&sa){var k=r.createAbsolutePositionFromRelativePosition(fa,a.doc),m=r.createAbsolutePositionFromRelativePosition(ha,a.doc);
|
|
34
|
+
if(null!==k&&null!==m){const [E,O]=Y(k.type,k.index),[ia,ja]=Y(m.type,m.index);if(null!==E&&null!==ia){m=E.getKey();var q=ia.getKey();g=l.selection;if(null===g){k=l;g=m;m=O;var t=ja,p=k.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 u=document.createElement("span");u.textContent=k.name;u.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`;
|
|
35
|
+
n.appendChild(u);g={caret:n,name:u,color:p,range:document.createRange(),selections:[],anchor:{key:g,offset:m},focus:{key:q,offset:t}}}else k=g.anchor,t=g.focus,k.key=m,k.offset=O,t.key=q,t.offset=ja}}}a:{k=a;m=l;n=g;var v=e;p=k.editor;q=p.getRootElement();l=k.cursorsContainer;if(null===l||null===q)break a;g=m.selection;if(null===n){null!==g&&(m.selection=null,ba(k,g));break a}else m.selection=n;t=n.range;g=n.caret;m=n.color;k=n.selections;var y=n.anchor,w=n.focus;n=y.key;u=w.key;var A=v.get(n);const E=
|
|
36
|
+
v.get(u);v=p.getElementByKey(n);p=p.getElementByKey(u);y=y.offset;w=w.offset;x.$isTextNode(A)&&(v=ca(v));x.$isTextNode(E)&&(p=ca(p));if(void 0!==A&&void 0!==E&&null!==v&&null!==p){"BR"===v.nodeName&&([v,y]=da(v));"BR"===p.nodeName&&([p,w]=da(p));A=v.firstChild;v===p&&null!=A&&"BR"===A.nodeName&&0===y&&0===w&&(w=1);try{t.setStart(v,y),t.setEnd(p,w)}catch(O){break a}!t.collapsed||y===w&&n===u||(t.setStart(p,w),t.setEnd(v,y));p=q.getBoundingClientRect();q=getComputedStyle(q);q=parseFloat(q.paddingLeft)+
|
|
37
|
+
parseFloat(q.paddingRight);n=Array.from(t.getClientRects());t=n.length;u=k.length;for(A=0;A<t;A++)v=n[A],v.width+q===p.width?(n.splice(A--,1),t--):(y=k[A],void 0===y&&(y=document.createElement("span"),k[A]=y,l.appendChild(y)),y.style.cssText=`position:absolute;top:${v.top}px;left:${v.left}px;height:${v.height}px;width:${v.width}px;background-color:rgba(${m}, 0.3);pointer-events:none;z-index:10;`,A===t-1&&g.parentNode!==y&&y.appendChild(g));for(g=u-1;g>=t;g--)l.removeChild(k[g]),k.pop()}}}}c=Array.from(b.keys());
|
|
38
|
+
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&&ba(a,h),b.delete(e)))}function la(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:h,name:g,color:l,focusing:k}=e,m=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)null!==d&&(e=W(d.anchor,a),m=W(d.focus,a)),(X(f,e)||X(h,m))&&b.setLocalState({name:g,color:l,anchorPos:e,focusPos:m,focusing:k})}}
|
|
39
|
+
class ma{constructor(a,b,c=1){this._offsetMap=a;this._firstNode=b;this._blockOffsetSize=c}createSelectionFromOffsets(a,b,c){var d=this._firstNode;if(null===d)return null;var e=Z(d,a,this._blockOffsetSize);let f=Z(d,b,this._blockOffsetSize);void 0!==c&&(a=na(a,e,c,this,this._blockOffsetSize),e=Z(d,a,this._blockOffsetSize),b=na(b,f,c,this,this._blockOffsetSize),f=Z(d,b,this._blockOffsetSize));if(null===e||null===f)return null;c=e.key;d=f.key;const h=x.$getNodeByKey(c),g=x.$getNodeByKey(d);if(null===
|
|
40
|
+
h||null===g)return null;let l=0,k=0,m="element",q="element";"text"===e.type?(l=a-e.start,m="text",e=h.getNextSibling(),a!==b&&l===h.getTextContentSize()&&x.$isTextNode(e)&&(l=0,c=e.__key)):"inline"===e.type&&(c=h.getParentOrThrow().getKey(),l=b>e.start?e.end:e.start);"text"===f.type?(k=b-f.start,q="text"):"inline"===f.type&&(d=g.getParentOrThrow().getKey(),k=b>f.start?f.end:f.start);a=x.$createSelection();if(null===a)return null;a.anchor.set(c,l,m);a.focus.set(d,k,q);return a}getOffsetsFromSelection(a){var b=
|
|
41
|
+
a.anchor,c=a.focus,d=this._offsetMap;const e=b.offset;var f=c.offset;let h=a=-1;if("text"===b.type)b=d.get(b.key),void 0!==b&&(a=b.start+e);else{b=b.getNode().getDescendantByIndex(e);const g=d.get(b.getKey());void 0!==g&&(a=b.getIndexWithinParent()!==e?g.end:g.start)}"text"===c.type?(f=d.get(c.key),void 0!==f&&(h=f.start+c.offset)):(c=c.getNode().getDescendantByIndex(f),d=d.get(c.getKey()),void 0!==d&&(h=c.getIndexWithinParent()!==f?d.end:d.start));return[a,h]}}
|
|
42
|
+
function na(a,b,c,d,e){const f=c._offsetMap;d=d._offsetMap;const h=new Set;let g=a;for(;null!==b;){var l=b.key,k=f.get(l),m=b.end-b.start;h.add(l);void 0===k?g+=m:(l=k.end-k.start,l!==m&&(g+=m-l));m=b.prev;if(null!==m)b=m;else{for(b=b.parent;null!==b;)k=b.prev,null!==k&&(m=k.key,l=f.get(m),k=k.end-k.start,h.add(m),void 0===l?g+=k:(m=l.end-l.start,m!==k&&(g+=k-m))),b=b.parent;break}}c=c._firstNode;if(null!==c){b=Z(c,a,e);for(a=!1;null!==b;){if(!h.has(b.key)){a=!0;break}b=b.parent}if(!a)for(;null!==
|
|
43
|
+
b;)a=b.key,h.has(a)||(e=d.get(a),a=b.end-b.start,void 0===e?g-=a:(e=e.end-e.start,a!==e&&(g+=e-a))),b=b.prev}return g}function Z(a,b,c){for(;null!==a;){if(b<a.end+("element"!==a.type||0===c?1:0)){const d=a.child;if(null!==d){a=d;continue}return a}a=a.next;if(null===a)break}return null}
|
|
44
|
+
function oa(a,b,c,d,e,f){let h=null,g=null;const l=b.length;for(let v=0;v<l;v++){{var k=a;var m=b[v];var q=c,t=d,p=e,n=f,u=t.get(m);if(void 0===u)throw Error("Minified Lexical error #3; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");const y=k.offset;if(x.$isElementNode(u)){const w=u.__children;t=(u=0===w.length)?null:oa(k,w,null,t,p,n);if(!k.prevIsBlock||u)k.prevIsBlock=!0,k.offset+=n;q={child:t,prev:null,next:null,type:"element",
|
|
45
|
+
start:y,end:y,key:m,parent:q};null!==t&&(t.parent=q);q.end=k.offset;p.set(m,q);m=q}else k.prevIsBlock=!1,n=x.$isTextNode(u),k=k.offset+=n?u.__text.length:1,k={child:null,prev:null,next:null,type:n?"text":"inline",start:y,end:k,key:m,parent:q},p.set(m,k),m=k}null===g?h=m:(m.prev=g,g.next=m);g=m}return h}function ta(a,b=1,c){c=(c||a._pendingEditorState||a._editorState)._nodeMap;const d=c.get("root");a=new Map;c=oa({offset:0,prevIsBlock:!1},d.__children,null,c,a,b);return new ma(a,c,b)}
|
|
46
|
+
exports.createBinding=function(a,b,c,d){b=d.get(c);if(void 0===b)throw Error("Should never happen");var e=b.get("root",r.XmlText);e=Q(e,null,"root");e._key="root";return{collabNodeMap:new Map,nodeProperties:new Map,editor:a,id:c,cursors:new Map,cursorsContainer:null,doc:b,root:e,docMap:d}};exports.createUndoManager=function(a,b){return new r.UndoManager(b,{trackedOrigins:new Set([a,null])})};
|
|
47
|
+
exports.initLocalState=function(a,b,c,d){a.awareness.setLocalState({color:c,name:b,anchorPos:null,focusPos:null,focusing:d})};exports.setLocalStateFocus=function(a,b){({awareness:a}=a);a.setLocalState({...a.getLocalState(),focusing:b})};exports.syncCursorPositions=ka;
|
|
48
|
+
exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,h,g){window.foo=a.doc;a.doc.transact(()=>{d.read(()=>{if(g.has("collaboration")){if(0<h.size){var l=Array.from(h),k=a.collabNodeMap,m=[];for(let n=0;n<l.length;n++){var q=l[n],t=x.$getNodeByKey(q),p=k.get(q);if(p instanceof z)if(x.$isTextNode(t))m.push([p,t.__text]);else{t=p.getOffset();if(-1===t)continue;const u=p._parent;p._normalized=!0;u._xmlText.delete(t,1);k.delete(q);q=u._children;p=q.indexOf(p);q.splice(p,1)}}for(l=0;l<m.length;l++){const [n,
|
|
49
|
+
u]=m[l];n._text=u}}}else e.has("root")&&(m=c._nodeMap,l=x.$getRoot(),k=a.root,k.syncPropertiesFromLexical(a,l,m),k.syncChildrenFromLexical(a,l,m,e,f)),m=x.$getSelection(),la(a,b,c._selection,m)})},a)};
|
|
50
|
+
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,l=c[h],{target:k}=l;k=R(g,k);if(k instanceof S&&l instanceof r.YTextEvent){const {keysChanged:m,childListChanged:q,delta:t}=l;0<m.size&&k.syncPropertiesFromYjs(g,m);q&&(k.applyChildrenYjsDelta(g,t),k.syncChildrenFromYjs(g))}else if(k instanceof z&&l instanceof r.YMapEvent)({keysChanged:l}=l),0<l.size&&k.syncPropertiesAndTextFromYjs(g,l);else if(k instanceof
|
|
51
|
+
K&&l instanceof r.YXmlEvent)({attributesChanged:l}=l),0<l.size&&k.syncPropertiesFromYjs(g,l);else throw Error("Should never happen");}h=x.$getSelection();if(null!==h)if(U(h)){g=e._selection;if(null!==g){k=ta(d,0,e);f=ta(d,0,f);const [m,q]=k.getOffsetsFromSelection(g);f=f.createSelectionFromOffsets(m,q,k);null!==f?x.$setSelection(f):(ea(a,b),U(h)&&(f=x.$getRoot(),0===f.getChildrenSize()&&f.append(aa.$createParagraphNode()),x.$getRoot().selectEnd()))}la(a,b,g,x.$getSelection())}else ea(a,b)},{onUpdate:()=>
|
|
52
|
+
{ka(a,b)},skipTransforms:!0,tag:"collaboration"})};
|
package/package.json
CHANGED