Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lexical/yjs

Package Overview
Dependencies
Maintainers
1
Versions
213
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lexical/yjs - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

99

index.js

@@ -1,49 +0,52 @@

'use strict';var r=require("yjs"),y=require("lexical"),aa=require("lexical/ParagraphNode");
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 y.$isTextNode(a)?a:null}getNode(){const a=y.$getNodeByKey(this._key);return y.$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=
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=y.$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 g=e=0;for(;e<f&&e<d&&b[e]===c[e]&&e<a;)e++;for(;g+e<f&&g+e<d&&b[f-g-1]===c[d-g-1];)g++;for(;g+e<f&&g+e<d&&b[e]===c[e];)e++;b=e;a=f-e-g;d=c.slice(e,
d-g);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}
class F{constructor(a,b){this._key="";this._map=a;this._parent=b;this._type="linebreak"}getNode(){const a=y.$getNodeByKey(this._key);return y.$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}
class H{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 y.$isDecoratorNode(a)?a:null}getNode(){const a=y.$getNodeByKey(this._key);return y.$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=
null===d?null:d.__ref,f=b.__ref;B(a,c,d,b);if(e!==f)if(null===f)c.removeAttribute("__ref"),null!==c.firstChild&&c.delete(0,1);else{const {id:g,_type:h}=f;c.setAttribute("__ref",{id:g,type:h});a=a.docMap;b=new r.Doc;c.insert(0,[b]);a.set(g,b)}}syncPropertiesFromYjs(a,b){const c=this.getNode();if(null===c)throw Error("Should never happen");var d=this._xmlElem,e=d.getAttribute("__ref"),f=c.__ref;C(a,d,c,b);if(void 0===e)null!==f&&(d=c.getWritable(),a=a.docMap,{id:f}=f,a.delete(f),d.__ref=null);else if("string"!==
typeof e&&(null===f||f.id!==e.id||f._type!==e.type)){f=c.getWritable();const {id:g,type:h}=e;"editorstate"===h&&(e=y.createEditorStateRef(g,null),d=d.firstChild,null!==d&&a.docMap.set(g,d),f.__ref=e)}}destroy(a){a.collabNodeMap.delete(this._key)}}function I(a,b,c){b=new H(a,b,c);return a._collabNode=b}const K=new Set("__key __children __parent __cachedText __text __ref".split(" "));function L(a){a=y.$getNodeByKey(a);if(null===a)throw Error("Should never happen");return a}
function M(a,b,c){const d=b.__type;if(y.$isElementNode(b)){var e=new r.XmlText;c=N(e,c,d);c.syncPropertiesFromLexical(a,b,null);c.syncChildrenFromLexical(a,b,null,null,null)}else if(y.$isTextNode(b))e=new r.Map,c=D(e,b.__text,c,d),c.syncPropertiesAndTextFromLexical(a,b,null);else if(y.$isLineBreakNode(b))a=new r.Map,a.set("__type","linebreak"),c=G(a,c);else if(y.$isDecoratorNode(b))e=new r.XmlElement,c=I(e,c,d),c.syncPropertiesFromLexical(a,b,null);else throw Error("Should never happen");c._key=b.__key;
'use strict';var r=require("yjs"),x=require("lexical"),aa=require("lexical/ParagraphNode");
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=
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,
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}
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}
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)}}
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");
}else c.set(g,l)}}
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=
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(" "));
function N(a){a=x.$getNodeByKey(a);if(null===a)throw Error("Should never happen");return a}
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;
return c}
function P(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?P(a,e):c||null;if(!(a instanceof Q))throw Error("Should never happen");if(b instanceof r.XmlText)return N(b,a,f);if(b instanceof r.Map){if(null===a)throw Error("Should never happen");return"linebreak"===f?G(b,a):
D(b,"",a,f)}if(b instanceof r.XmlElement)return I(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(K.has(f))continue;const g=c[f],h=b instanceof r.Map?b.get(f):b.getAttribute(f);g!==h&&(void 0===e&&(e=c.getWritable()),e[f]=h)}}
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(g=>!K.has(g)),f.set(e,a));for(e=0;e<a.length;e++){f=a[e];const g=d[f];(null===c?void 0:c[f])!==g&&(b instanceof r.Map?b.set(f,g):b.setAttribute(f,g))}}
function R(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,m=a.getSize();d+=m;if((c?d>=b:d>b)&&a instanceof z)return b=b-h-1,0>b&&(b=0),{node:a,nodeIndex:e,offset:b,length:m-b};if(d>b)return{node:a,nodeIndex:e,offset:h,length:0};if(e===g-1)return{node:null,nodeIndex:e+1,offset:h+1,length:0}}return{node:null,nodeIndex:0,offset:0,length:0}}
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()||y.$isTextNode(d)&&b.offset>d.getTextContentSize()||y.$isTextNode(e)&&a.offset>e.getTextContentSize())c=!0}catch(d){c=!0}return c}
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 y.$isElementNode(a)?a:null}getNode(){const a=y.$getNodeByKey(this._key);return y.$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");
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,g=e.delete;if(null!=e.retain)d+=e.retain;else if("number"===typeof g)for(f=g;0<f;){const {node:l,nodeIndex:q,offset:t,length:p}=R(this,d,!1);if(l instanceof Q||l instanceof F||l instanceof H)c.splice(q,1),--f;else if(l instanceof
z){e=Math.min(f,p);g=0!==q?c[q-1]:null;var h=l.getSize();if(0===t&&1===e&&0<q&&g instanceof z&&p===h)g._text+=l._text,c.splice(q,1);else if(0===t&&e===h)c.splice(q,1);else{g=l._text;h=t;var m=e;g=g.slice(0,h)+""+g.slice(h+m);l._text=g}f-=e}else break}else if(null!=f)if("string"===typeof f){const {node:l,offset:q}=R(this,d,!0);l instanceof z?(e=l._text,g=q,h=f,e=e.slice(0,g)+h+e.slice(g+0),l._text=e):this._xmlText.delete(q,f.length);d+=f.length}else e=f,{nodeIndex:f}=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,g=this._children,h=g.length,m=a.collabNodeMap,k=new Set;let l,q;h!==f&&(q=T(b,q,e));let t=0;for(let x=0;x<h;x++){var p=d[t];const w=g[x];var n=w.getNode(),u=w._key;if(null!==n&&p===u){n=y.$isTextNode(n);k.add(p);if(n)if(w._key=p,w instanceof Q)n=w._xmlText,w.syncPropertiesFromYjs(a,
null),w.applyChildrenYjsDelta(a,n.toDelta()),w.syncChildrenFromYjs(a);else if(w instanceof z)w.syncPropertiesAndTextFromYjs(a,null);else if(w instanceof H)w.syncPropertiesFromYjs(a,null);else if(!(w instanceof F))throw Error("Should never happen");e[x]=p;t++}else{if(void 0===l)for(l=new Set,u=0;u<h;u++){var v=g[u]._key;""!==v&&l.add(v)}if(null===n||void 0===p||l.has(p)){q=T(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=
new v.klass;v.__parent=u;n._key=v.__key;n instanceof Q?(u=n._xmlText,n.syncPropertiesFromYjs(p,null),n.applyChildrenYjsDelta(p,u.toDelta()),n.syncChildrenFromYjs(p)):n instanceof z?n.syncPropertiesAndTextFromYjs(p,null):n instanceof H&&n.syncPropertiesFromYjs(p,null);p.collabNodeMap.set(v.__key,n);p=v.__key;m.set(p,w);e[x]=p}else x--,t++}}for(b=0;b<f;b++)e=d[b],k.has(e)||(c=L(e).getWritable(),e=a.collabNodeMap.get(e),void 0!==e&&e.destroy(a),c.__parent=null)}syncPropertiesFromLexical(a,b,c){B(a,this._xmlText,
this.getPrevNode(c),b)}_syncChildFromLexical(a,b,c,d,e,f){b=this._children[b];c=L(c);b instanceof Q&&y.$isElementNode(c)?(b.syncPropertiesFromLexical(a,c,d),b.syncChildrenFromLexical(a,c,d,e,f)):b instanceof z&&y.$isTextNode(c)?b.syncPropertiesAndTextFromLexical(a,c,d):b instanceof H&&y.$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,m=f.length-1,k=a.collabNodeMap;
let l,q,t=0;for(b=0;t<=h&&b<=m;){var p=g[t];const u=f[b];if(p===u)this._syncChildFromLexical(a,b,u,c,d,e),t++,b++;else{void 0===l&&(l=new Set(g));void 0===q&&(q=new Set(f));var n=q.has(p);p=l.has(u);n?(n=L(u),n=M(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>h;d=b>m;if(c&&!d)for(;b<=m;++b)c=f[b],d=L(c),d=M(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;
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 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 H&&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();if(-1===g)throw Error("Should never happen");
var h=this._xmlText;0!==c&&h.delete(g,f.getSize());d instanceof Q?h.insertEmbed(g,d._xmlText):d instanceof z?(f=d._map,null===f.parent&&h.insertEmbed(g,f),h.insert(g+1,d._text)):d instanceof F?h.insertEmbed(g,d._map):d instanceof H&&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];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 T(a,b,c){return void 0===b?(a=a.getWritable(),a.__children=c,a):b}function N(a,b,c){b=new Q(a,b,c);return a._collabNode=b}function U(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)}
function V(a,b){if(null==a){if(null!=b)return!0}else if(null==b||!r.compareRelativePositions(a,b))return!0;return!1}function W(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 X(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)]}
function ca(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),[g,h]=Y(a.type,a.index);if(null!==e&&null!==g){c=e.getKey();a=g.getKey();b=y.$getSelection();if(null===b)throw Error("TODO: syncLocalCursorPosition");var d=b.anchor;const m=b.focus;if(d.key!==c||d.offset!==f)d=y.$getNodeByKey(c),
b.anchor.set(c,f,y.$isElementNode(d)?"element":"text");if(m.key!==a||m.offset!==h)c=y.$getNodeByKey(a),b.focus.set(a,h,y.$isElementNode(c)?"element":"text")}}}function Y(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]}
function ia(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 g=0;g<c.length;g++){const [J,na]=c[g];if(J!==d){f.add(J);const {anchorPos:da,focusPos:ea,name:oa,color:pa,focusing:qa}=na;var h=null,m=b.get(J);void 0===m&&(m={color:pa,name:oa,selection:null},b.set(J,m));if(null!==da&&null!==ea&&qa){var k=r.createAbsolutePositionFromRelativePosition(da,a.doc),l=r.createAbsolutePositionFromRelativePosition(ea,a.doc);
if(null!==k&&null!==l){const [E,O]=Y(k.type,k.index),[fa,ha]=Y(l.type,l.index);if(null!==E&&null!==fa){l=E.getKey();var q=fa.getKey();h=m.selection;if(null===h){k=m;h=l;l=O;var t=ha,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`;
n.appendChild(u);h={caret:n,name:u,color:p,range:document.createRange(),selections:[],anchor:{key:h,offset:l},focus:{key:q,offset:t}}}else k=h.anchor,t=h.focus,k.key=l,k.offset=O,t.key=q,t.offset=ha}}}a:{k=a;l=m;n=h;var v=e;p=k.editor;q=p.getRootElement();m=k.cursorsContainer;if(null===m||null===q)break a;h=l.selection;if(null===n){null!==h&&(l.selection=null,W(k,h));break a}else l.selection=n;t=n.range;h=n.caret;l=n.color;k=n.selections;var x=n.anchor,w=n.focus;n=x.key;u=w.key;var A=v.get(n);const E=
v.get(u);v=p.getElementByKey(n);p=p.getElementByKey(u);x=x.offset;w=w.offset;y.$isTextNode(A)&&(v=X(v));y.$isTextNode(E)&&(p=X(p));if(void 0!==A&&void 0!==E&&null!==v&&null!==p){"BR"===v.nodeName&&([v,x]=ba(v));"BR"===p.nodeName&&([p,w]=ba(p));A=v.firstChild;v===p&&null!=A&&"BR"===A.nodeName&&0===x&&0===w&&(w=1);try{t.setStart(v,x),t.setEnd(p,w)}catch(O){break a}!t.collapsed||x===w&&n===u||(t.setStart(p,w),t.setEnd(v,x));p=q.getBoundingClientRect();q=getComputedStyle(q);q=parseFloat(q.paddingLeft)+
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--):(x=k[A],void 0===x&&(x=document.createElement("span"),k[A]=x,m.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(${l}, 0.3);pointer-events:none;z-index:10;`,A===t-1&&h.parentNode!==x&&x.appendChild(h));for(h=u-1;h>=t;h--)m.removeChild(k[h]),k.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&&W(a,g),b.delete(e)))}function ja(a,b,c,d){b=b.awareness;var e=b.getLocalState();if(null!==e){var {anchorPos:f,focusPos:g,name:h,color:m,focusing:k}=e,l=e=null;if(null!==d&&(null===f||d.is(c))||null!==c)null!==d&&(e=U(d.anchor,a),l=U(d.focus,a)),(V(f,e)||V(g,l))&&b.setLocalState({name:h,color:m,anchorPos:e,focusPos:l,focusing:k})}}
class ka{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=la(a,e,c,this,this._blockOffsetSize),e=Z(d,a,this._blockOffsetSize),b=la(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 g=y.$getNodeByKey(c),h=y.$getNodeByKey(d);if(null===
g||null===h)return null;let m=0,k=0,l="element",q="element";"text"===e.type?(m=a-e.start,l="text",e=g.getNextSibling(),a!==b&&m===g.getTextContentSize()&&y.$isTextNode(e)&&(m=0,c=e.__key)):"inline"===e.type&&(c=g.getParentOrThrow().getKey(),m=b>e.start?e.end:e.start);"text"===f.type?(k=b-f.start,q="text"):"inline"===f.type&&(d=h.getParentOrThrow().getKey(),k=b>f.start?f.end:f.start);a=y.$createSelection();if(null===a)return null;a.anchor.set(c,m,l);a.focus.set(d,k,q);return a}getOffsetsFromSelection(a){var b=
a.anchor,c=a.focus,d=this._offsetMap;const e=b.offset;var f=c.offset;let g=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 h=d.get(b.getKey());void 0!==h&&(a=b.getIndexWithinParent()!==e?h.end:h.start)}"text"===c.type?(f=d.get(c.key),void 0!==f&&(g=f.start+c.offset)):(c=c.getNode().getDescendantByIndex(f),d=d.get(c.getKey()),void 0!==d&&(g=c.getIndexWithinParent()!==f?d.end:d.start));return[a,g]}}
function la(a,b,c,d,e){const f=c._offsetMap;d=d._offsetMap;const g=new Set;let h=a;for(;null!==b;){var m=b.key,k=f.get(m),l=b.end-b.start;g.add(m);void 0===k?h+=l:(m=k.end-k.start,m!==l&&(h+=l-m));l=b.prev;if(null!==l)b=l;else{for(b=b.parent;null!==b;)k=b.prev,null!==k&&(l=k.key,m=f.get(l),k=k.end-k.start,g.add(l),void 0===m?h+=k:(l=m.end-m.start,l!==k&&(h+=k-l))),b=b.parent;break}}c=c._firstNode;if(null!==c){b=Z(c,a,e);for(a=!1;null!==b;){if(!g.has(b.key)){a=!0;break}b=b.parent}if(!a)for(;null!==
b;)a=b.key,g.has(a)||(e=d.get(a),a=b.end-b.start,void 0===e?h-=a:(e=e.end-e.start,a!==e&&(h+=e-a))),b=b.prev}return h}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}
function ma(a,b,c,d,e,f){let g=null,h=null;const m=b.length;for(let v=0;v<m;v++){{var k=a;var l=b[v];var q=c,t=d,p=e,n=f,u=t.get(l);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 x=k.offset;if(y.$isElementNode(u)){const w=u.__children;t=(u=0===w.length)?null:ma(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",
start:x,end:x,key:l,parent:q};null!==t&&(t.parent=q);q.end=k.offset;p.set(l,q);l=q}else k.prevIsBlock=!1,n=y.$isTextNode(u),k=k.offset+=n?u.__text.length:1,k={child:null,prev:null,next:null,type:n?"text":"inline",start:x,end:k,key:l,parent:q},p.set(l,k),l=k}null===h?g=l:(l.prev=h,h.next=l);h=l}return g}function ra(a,b=1,c){c=(c||a._pendingEditorState||a._editorState)._nodeMap;const d=c.get("root");a=new Map;c=ma({offset:0,prevIsBlock:!1},d.__children,null,c,a,b);return new ka(a,c,b)}
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=N(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])})};
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=ia;
exports.syncLexicalUpdateToYjs=function(a,b,c,d,e,f,g,h){window.foo=a.doc;a.doc.transact(()=>{d.read(()=>{if(h.has("collaboration")){if(0<g.size){var m=Array.from(g),k=a.collabNodeMap,l=[];for(let n=0;n<m.length;n++){var q=m[n],t=y.$getNodeByKey(q),p=k.get(q);if(p instanceof z)if(y.$isTextNode(t))l.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(m=0;m<l.length;m++){const [n,
u]=l[m];n._text=u}}}else e.has("root")&&(l=c._nodeMap,m=y.$getRoot(),k=a.root,k.syncPropertiesFromLexical(a,m,l),k.syncChildrenFromLexical(a,m,l,e,f)),l=y.$getSelection(),ja(a,b,c._selection,l)})},a)};
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,m=c[g],{target:k}=m;k=P(h,k);if(k instanceof Q&&m instanceof r.YTextEvent){const {keysChanged:l,childListChanged:q,delta:t}=m;0<l.size&&k.syncPropertiesFromYjs(h,l);q&&(k.applyChildrenYjsDelta(h,t),k.syncChildrenFromYjs(h))}else if(k instanceof z&&m instanceof r.YMapEvent)({keysChanged:m}=m),0<m.size&&k.syncPropertiesAndTextFromYjs(h,m);else if(k instanceof
H&&m instanceof r.YXmlEvent)({attributesChanged:m}=m),0<m.size&&k.syncPropertiesFromYjs(h,m);else throw Error("Should never happen");}g=y.$getSelection();if(null!==g)if(S(g)){h=e._selection;if(null!==h){k=ra(d,0,e);f=ra(d,0,f);const [l,q]=k.getOffsetsFromSelection(h);f=f.createSelectionFromOffsets(l,q,k);null!==f?y.$setSelection(f):(ca(a,b),S(g)&&(f=y.$getRoot(),0===f.getChildrenSize()&&f.append(aa.$createParagraphNode()),y.$getRoot().selectEnd()))}ja(a,b,h,y.$getSelection())}else ca(a,b)},{onUpdate:()=>
{ia(a,b)},skipTransforms:!0,tag:"collaboration"})};
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):
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)}}
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))}}
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}}
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}
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");
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
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,
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,
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=
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,
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;
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;
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");
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=
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)}
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)]}
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),
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]}
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);
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`;
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=
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)+
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());
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})}}
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===
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=
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]}}
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!==
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}
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",
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)}
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])})};
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;
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,
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)};
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
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:()=>
{ka(a,b)},skipTransforms:!0,tag:"collaboration"})};

@@ -18,6 +18,6 @@ {

"license": "MIT",
"version": "0.1.1",
"version": "0.1.2",
"main": "LexicalYjs.js",
"dependencies": {
"lexical": "0.1.1",
"lexical": "0.1.2",
"yjs": ">=13.5.22"

@@ -24,0 +24,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc