@lexical/yjs 0.36.3-nightly.20251003.0 → 0.36.3-nightly.20251006.0
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.prod.js +1 -1
- package/LexicalYjs.prod.mjs +1 -1
- package/package.json +4 -4
package/LexicalYjs.prod.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("lexical"),t=require("yjs"),n=require("@lexical/offset"),o=require("@lexical/selection");function s(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class i{_map;_key;_parent;_type;constructor(e,t){this._key="",this._map=e,this._parent=t,this._type="linebreak"}getNode(){const t=e.$getNodeByKey(this._key);return e.$isLineBreakNode(t)?t:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function r(e,t){const n=new i(e,t);return e._collabNode=n,n}function l(e,t,n){const o=e.length,s=t.length;let i=0,r=0;for(;i<o&&i<s&&e[i]===t[i]&&i<n;)i++;for(;r+i<o&&r+i<s&&e[o-r-1]===t[s-r-1];)r++;for(;r+i<o&&r+i<s&&e[i]===t[i];)i++;return{index:i,insert:t.slice(i,s-r),remove:o-i-r}}class c{_map;_key;_parent;_text;_type;_normalized;constructor(e,t,n,o){this._key="",this._map=e,this._parent=n,this._text=t,this._type=o,this._normalized=!1}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e.$isTextNode(n)?n:null}getNode(){const t=e.$getNodeByKey(this._key);return e.$isTextNode(t)?t: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(e,t,n){const o=this._parent._xmlText,s=this.getOffset()+1+e;0!==t&&o.delete(s,t),""!==n&&o.insert(s,n)}syncPropertiesAndTextFromLexical(t,n,o){const s=this.getPrevNode(o),i=n.__text;if(k(t,this._map,s,n),null!==s){const t=s.__text;if(t!==i){!function(t,n,o,s){const i=e.$getSelection();let r=s.length;if(e.$isRangeSelection(i)&&i.isCollapsed()){const e=i.anchor;e.key===n&&(r=e.offset)}const c=l(o,s,r);t.spliceText(c.index,c.remove,c.insert)}(this,n.__key,t,i),this._text=i}}}syncPropertiesAndTextFromYjs(e,t){const n=this.getNode();null===n&&s(84),T(e,this._map,n,t);const o=this._text;n.__text!==o&&n.setTextContent(o)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function a(e,t,n,o){const s=new c(e,t,n,o);return e._collabNode=s,s}const f=new Set(["__key","__parent","__next","__prev","__state"]),d=new Set(["__first","__last","__size"]),u=new Set(["__cachedText"]),h=new Set(["__text"]);function p(t,n,o){if(f.has(t)||"function"==typeof n[t])return!0;if(e.$isTextNode(n)){if(h.has(t))return!0}else if(e.$isElementNode(n)&&(d.has(t)||e.$isRootNode(n)&&u.has(t)))return!0;const s=n.constructor,i=o.excludedProperties.get(s);return null!=i&&i.has(t)}function g(e,t){const n=e.__type,{nodeProperties:o}=t,i=o.get(n);return void 0===i&&s(326,n),i}function y(n,o,i){const l=o.__type;let c;if(e.$isElementNode(o)){c=M(new t.XmlText,i,l),c.syncPropertiesFromLexical(n,o,null),c.syncChildrenFromLexical(n,o,null,null,null)}else if(e.$isTextNode(o)){c=a(new t.Map,o.__text,i,l),c.syncPropertiesAndTextFromLexical(n,o,null)}else if(e.$isLineBreakNode(o)){const e=new t.Map;e.set("__type","linebreak"),c=r(e,i)}else if(e.$isDecoratorNode(o)){c=A(new t.XmlElement,i,l),c.syncPropertiesFromLexical(n,o,null)}else s(86);return c._key=o.__key,c}function _(e){const t=N(e,"__type");return"string"!=typeof t&&void 0!==t&&s(87),t}function m(e,n,o){const i=n._collabNode;if(void 0===i){const i=e.editor._nodes,l=_(n);"string"!=typeof l&&s(87);void 0===i.get(l)&&s(88,l);const c=n.parent,f=void 0===o&&null!==c?m(e,c):o||null;if(f instanceof K||s(89),n instanceof t.XmlText)return M(n,f,l);if(n instanceof t.Map)return"linebreak"===l?r(n,f):a(n,"",f,l);if(n instanceof t.XmlElement)return A(n,f,l)}return i}function x(e,t,n){const o=t.getType(),i=e.editor._nodes.get(o);void 0===i&&s(88,o);const r=new i.klass;if(r.__parent=n,t._key=r.__key,t instanceof K){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof c?t.syncPropertiesAndTextFromYjs(e,null):t instanceof w&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(r.__key,t),r}function T(n,o,s,i){const r=null===i?o instanceof t.Map?Array.from(o.keys()):o instanceof t.XmlText||o instanceof t.XmlElement?Object.keys(o.getAttributes()):Object.keys(o):Array.from(i);let l;for(let i=0;i<r.length;i++){const c=r[i];if(p(c,s,n)){"__state"===c&&L(n)&&(l||(l=s.getWritable()),S(o,l));continue}const a=s[c];let f=N(o,c);if(a!==f){if(f instanceof t.Doc){const o=n.docMap;a instanceof t.Doc&&o.delete(a.guid);const s=e.createEditor(),i=f.guid;s._key=i,o.set(i,f),f=s}void 0===l&&(l=s.getWritable()),l[c]=f}}}function N(e,n){return e instanceof t.Map?e.get(n):e instanceof t.XmlText||e instanceof t.XmlElement?e.getAttribute(n):e[n]}function b(e,n,o){e instanceof t.Map?e.set(n,o):e.setAttribute(n,o)}function S(n,o){const s=N(n,"__state");s instanceof t.Map&&e.$getWritableNodeState(o).updateFromJSON(s.toJSON())}function k(e,n,o,s){const i=Object.keys(g(s,e)),r=e.editor.constructor;!function(e,n,o,s){const i=s.__state,r=N(n,"__state");if(!i)return;const[l,c]=i.getInternalState(),a=o&&o.__state,f=r instanceof t.Map?r:new t.Map;if(a===i)return;const[d,u]=a&&f.doc?a.getInternalState():[void 0,new Map];if(l)for(const[e,t]of Object.entries(l))d&&t!==d[e]&&f.set(e,t);for(const[e,t]of c)u.get(e)!==t&&f.set(e.key,e.unparse(t));r||b(n,"__state",f)}(0,n,o,s);for(let l=0;l<i.length;l++){const c=i[l],a=null===o?void 0:o[c];let f=s[c];if(a!==f){if(f instanceof r){const n=e.docMap;let o;if(a instanceof r){const e=a._key;o=n.get(e),n.delete(e)}const i=o||new t.Doc,l=i.guid;f._key=l,n.set(l,i),f=i,e.editor.update(()=>{s.markDirty()})}b(n,c,f)}}}function C(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function $(e,t,n){let o=0,s=0;const i=e._children,r=i.length;for(;s<r;s++){const e=i[s],l=o;o+=e.getSize();if((n?o>=t:o>t)&&e instanceof c){let n=t-l-1;n<0&&(n=0);return{length:o-t,node:e,nodeIndex:s,offset:n}}if(o>t)return{length:0,node:e,nodeIndex:s,offset:l};if(s===r-1)return{length:0,node:null,nodeIndex:s+1,offset:l+1}}return{length:0,node:null,nodeIndex:0,offset:0}}function E(t){const n=t.anchor,o=t.focus;let s=!1;try{const t=n.getNode(),i=o.getNode();(!t.isAttached()||!i.isAttached()||e.$isTextNode(t)&&n.offset>t.getTextContentSize()||e.$isTextNode(i)&&o.offset>i.getTextContentSize())&&(s=!0)}catch(e){s=!0}return s}function O(e,t){e.doc.transact(t,e)}function v(t,n){const o=n._nodeMap.get(t);if(!o)return void e.$getRoot().selectStart();const s=o.__prev;let i=null;s&&(i=e.$getNodeByKey(s)),null===i&&null!==o.__parent&&(i=e.$getNodeByKey(o.__parent)),null!==i?null!==i&&i.isAttached()?i.selectEnd():v(i.__key,n):e.$getRoot().selectStart()}class w{_xmlElem;_key;_parent;_type;constructor(e,t,n){this._key="",this._xmlElem=e,this._parent=t,this._type=n}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e.$isDecoratorNode(n)?n:null}getNode(){const t=e.$getNodeByKey(this._key);return e.$isDecoratorNode(t)?t:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}syncPropertiesFromLexical(e,t,n){const o=this.getPrevNode(n);k(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&s(83);T(e,this._xmlElem,n,t)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function A(e,t,n){const o=new w(e,t,n);return e._collabNode=o,o}class K{_key;_children;_xmlText;_type;_parent;constructor(e,t,n){this._key="",this._children=[],this._xmlText=e,this._type=n,this._parent=t}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e.$isElementNode(n)?n:null}getNode(){const t=e.$getNodeByKey(this._key);return e.$isElementNode(t)?t:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){const e=this._parent;return null===e&&s(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&s(91),T(e,this._xmlText,n,t)}applyChildrenYjsDelta(e,t){const n=this._children;let o=0,s=null;for(let r=0;r<t.length;r++){const l=t[r],a=l.insert,f=l.delete;if(null!=l.retain)o+=l.retain;else if("number"==typeof f){let e=f;for(;e>0;){const{node:t,nodeIndex:s,offset:r,length:l}=$(this,o,!1);if(t instanceof K||t instanceof i||t instanceof w)n.splice(s,1),e-=1;else{if(!(t instanceof c))break;{const o=Math.min(e,l),i=0!==s?n[s-1]:null,a=t.getSize();if(0===r&&l===a){n.splice(s,1);const e=C(t._text,r,o-1,"");e.length>0&&(i instanceof c?i._text+=e:this._xmlText.delete(r,e.length))}else t._text=C(t._text,r,o,"");e-=o}}}}else{if(null==a)throw new Error("Unexpected delta format");if("string"==typeof a){const{node:e,offset:t}=$(this,o,!0);e instanceof c?e._text=C(e._text,t,0,a):this._xmlText.delete(t,a.length),o+=a.length}else{const t=a,{node:i,nodeIndex:r,length:l}=$(this,o,!1),f=m(e,t,this);if(i instanceof c&&l>0&&l<i._text.length){const e=i._text,t=e.length-l;i._text=C(e,t,l,""),n.splice(r+1,0,f),s=C(e,0,t,"")}else n.splice(r,0,f);null!==s&&f instanceof c&&(f._text=s+f._text,s=null),o+=1}}}}syncChildrenFromYjs(t){const o=this.getNode();null===o&&s(92);const r=o.__key,l=n.$createChildrenArray(o,null),a=l.length,f=this._children,d=f.length,u=t.collabNodeMap,h=new Set;let p,g,y=0,_=null;d!==a&&(g=o.getWritable());for(let n=0;n<d;n++){const a=l[y],m=f[n],T=m.getNode(),N=m._key;if(null!==T&&a===N){const n=e.$isTextNode(T);if(h.add(a),n)if(m._key=a,m instanceof K){const e=m._xmlText;m.syncPropertiesFromYjs(t,null),m.applyChildrenYjsDelta(t,e.toDelta()),m.syncChildrenFromYjs(t)}else m instanceof c?m.syncPropertiesAndTextFromYjs(t,null):m instanceof w?m.syncPropertiesFromYjs(t,null):m instanceof i||s(93);_=T,y++}else{if(void 0===p){p=new Set;for(let e=0;e<d;e++){const t=f[e]._key;""!==t&&p.add(t)}}if(null!==T&&void 0!==a&&!p.has(a)){const t=e.$getNodeByKeyOrThrow(a);e.removeFromParent(t),n--,y++;continue}g=o.getWritable();const s=x(t,m,r),i=s.__key;if(u.set(i,m),null===_){const e=g.getFirstChild();if(g.__first=i,null!==e){const t=e.getWritable();t.__prev=i,s.__next=t.__key}}else{const e=_.getWritable(),t=_.getNextSibling();if(e.__next=i,s.__prev=_.__key,null!==t){const e=t.getWritable();e.__prev=i,s.__next=e.__key}}n===d-1&&(g.__last=i),g.__size++,_=s}}for(let n=0;n<a;n++){const o=l[n];if(!h.has(o)){const n=e.$getNodeByKeyOrThrow(o),s=t.collabNodeMap.get(o);void 0!==s&&s.destroy(t),e.removeFromParent(n)}}}syncPropertiesFromLexical(e,t,n){k(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(t,n,o,s,i,r){const l=this._children[n],a=e.$getNodeByKeyOrThrow(o);l instanceof K&&e.$isElementNode(a)?(l.syncPropertiesFromLexical(t,a,s),l.syncChildrenFromLexical(t,a,s,i,r)):l instanceof c&&e.$isTextNode(a)?l.syncPropertiesAndTextFromLexical(t,a,s):l instanceof w&&e.$isDecoratorNode(a)&&l.syncPropertiesFromLexical(t,a,s)}syncChildrenFromLexical(t,o,s,i,r){const l=this.getPrevNode(s),c=null===l?[]:n.$createChildrenArray(l,s),a=n.$createChildrenArray(o,null),f=c.length-1,d=a.length-1,u=t.collabNodeMap;let h,p,g=0,_=0;for(;g<=f&&_<=d;){const n=c[g],o=a[_];if(n===o)this._syncChildFromLexical(t,_,o,s,i,r),g++,_++;else{void 0===h&&(h=new Set(c)),void 0===p&&(p=new Set(a));const s=p.has(n),i=h.has(o);if(s){const n=y(t,e.$getNodeByKeyOrThrow(o),this);u.set(o,n),i?(this.splice(t,_,1,n),g++,_++):(this.splice(t,_,0,n),_++)}else this.splice(t,_,1),g++}}const m=g>f,x=_>d;if(m&&!x)for(;_<=d;++_){const n=a[_],o=y(t,e.$getNodeByKeyOrThrow(n),this);this.append(o),u.set(n,o)}else if(x&&!m)for(let e=this._children.length-1;e>=_;e--)this.splice(t,e,1)}append(e){const t=this._xmlText,n=this._children,o=n[n.length-1],s=void 0!==o?o.getOffset()+o.getSize():0;if(e instanceof K)t.insertEmbed(s,e._xmlText);else if(e instanceof c){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof i?t.insertEmbed(s,e._map):e instanceof w&&t.insertEmbed(s,e._xmlElem);this._children.push(e)}splice(e,t,n,o){const r=this._children,l=r[t];if(void 0===l)return void 0===o&&s(94),void this.append(o);const a=l.getOffset();-1===a&&s(95);const f=this._xmlText;if(0!==n&&f.delete(a,l.getSize()),o instanceof K)f.insertEmbed(a,o._xmlText);else if(o instanceof c){const e=o._map;null===e.parent&&f.insertEmbed(a,e),f.insert(a+1,o._text)}else o instanceof i?f.insertEmbed(a,o._map):o instanceof w&&f.insertEmbed(a,o._xmlElem);if(0!==n){const o=r.slice(t,t+n);for(let t=0;t<o.length;t++)o[t].destroy(e)}void 0!==o?r.splice(t,n,o):r.splice(t,n)}getChildOffset(e){let t=0;const n=this._children;for(let o=0;o<n.length;o++){const s=n[o];if(s===e)return t;t+=s.getSize()}return-1}destroy(e){const t=e.collabNodeMap,n=this._children;for(let t=0;t<n.length;t++)n[t].destroy(e);t.get(this._key)===this&&t.delete(this._key)}}function M(e,t,n){const o=new K(e,t,n);return e._collabNode=o,o}class P{_nodeMap=new Map;_sharedTypeToNodeKeys=new Map;_nodeKeyToSharedType=new Map;set(n,o){const i=o instanceof Array;this.delete(n);const r=i?o:[o];for(const e of r){const t=e.getKey();if(this._nodeKeyToSharedType.has(t)){const e=this._nodeKeyToSharedType.get(t),n=this._sharedTypeToNodeKeys.get(e).indexOf(t);-1!==n&&this._sharedTypeToNodeKeys.get(e).splice(n,1),this._nodeKeyToSharedType.delete(t),this._nodeMap.delete(t)}}if(n instanceof t.XmlText){if(i||s(328),0===o.length)return;this._sharedTypeToNodeKeys.set(n,o.map(e=>e.getKey()));for(const e of o)this._nodeMap.set(e.getKey(),e),this._nodeKeyToSharedType.set(e.getKey(),n)}else i&&s(329),e.$isTextNode(o)&&s(330),this._sharedTypeToNodeKeys.set(n,[o.getKey()]),this._nodeMap.set(o.getKey(),o),this._nodeKeyToSharedType.set(o.getKey(),n)}get(e){const n=this._sharedTypeToNodeKeys.get(e);if(void 0!==n){if(e instanceof t.XmlText){const e=Array.from(n.map(e=>this._nodeMap.get(e)));return e.length>0?e:void 0}return this._nodeMap.get(n[0])}}getSharedType(e){return this._nodeKeyToSharedType.get(e.getKey())}delete(e){const t=this._sharedTypeToNodeKeys.get(e);if(void 0!==t){for(const e of t)this._nodeMap.delete(e),this._nodeKeyToSharedType.delete(e);this._sharedTypeToNodeKeys.delete(e)}}deleteNode(e){const t=this._nodeKeyToSharedType.get(e);t&&this.delete(t),this._nodeMap.delete(e)}has(e){return this._sharedTypeToNodeKeys.has(e)}}function F(e,t,n,o,i){null==n&&s(81);const r={clientID:n.clientID,cursors:new Map,cursorsContainer:null,doc:n,docMap:o,editor:e,excludedProperties:i||new Map,id:t,nodeProperties:new Map};return function(e){const{editor:t,nodeProperties:n}=e;t.update(()=>{t._nodes.forEach(t=>{const o=new t.klass,s={};for(const[t,n]of Object.entries(o))p(t,o,e)||(s[t]=n);n.set(o.__type,Object.freeze(s))})})}(r),r}function L(e){return Object.hasOwn(e,"collabNodeMap")}function j(n,o){const i=o.collabNodeMap.get(n.key);if(void 0===i)return null;let r=n.offset,l=i.getSharedType();if(i instanceof c){l=i._parent._xmlText;const e=i.getOffset();if(-1===e)return null;r=e+1+r}else if(i instanceof K&&"element"===n.type){const t=n.getNode();e.$isElementNode(t)||s(184);let o=0,i=0,l=t.getFirstChild();for(;null!==l&&i++<r;)e.$isTextNode(l)?o+=l.getTextContentSize()+1:o++,l=l.getNextSibling();r=o}return t.createRelativePositionFromTypeIndex(l,r)}function R(n,o){const{mapping:i}=o,{offset:r}=n,l=n.getNode(),c=i.getSharedType(l);if(void 0===c)return null;if("text"===n.type){e.$isTextNode(l)||s(323);let n=l.getPreviousSibling(),o=r;for(;e.$isTextNode(n);)o+=n.getTextContentSize(),n=n.getPreviousSibling();return t.createRelativePositionFromTypeIndex(c,o)}if("element"===n.type){e.$isElementNode(l)||s(184);let n=0,o=l.getFirstChild();for(;null!==o&&n<r;){if(e.$isTextNode(o)){let t=o.getNextSibling();for(;e.$isTextNode(t);)t=t.getNextSibling()}n++,o=o.getNextSibling()}return t.createRelativePositionFromTypeIndex(c,n)}return null}function I(e,n){return t.createAbsolutePositionFromRelativePosition(e,n.doc)}function X(e,n){if(null==e){if(null!=n)return!0}else if(null==n||!t.compareRelativePositions(e,n))return!0;return!1}function z(e,t){return{color:t,name:e,selection:null}}function D(e,t){const n=e.cursorsContainer;if(null!==n){const e=t.selections,o=e.length;for(let t=0;t<o;t++)n.removeChild(e[t])}}function Y(e,t){const n=t.selection;null!==n&&D(e,n)}function B(e,t,n,o,s){const i=e.color,r=document.createElement("span");r.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${i};z-index:10;`;const l=document.createElement("span");return l.textContent=e.name,l.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${i};color:#fff;line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`,r.appendChild(l),{anchor:{key:t,offset:n},caret:r,color:i,focus:{key:o,offset:s},name:l,selections:[]}}function W(t,n,s,i){const r=t.editor,l=r.getRootElement(),c=t.cursorsContainer;if(null===c||null===l)return;const a=c.offsetParent;if(null===a)return;const f=a.getBoundingClientRect(),d=n.selection;if(null===s)return null===d?void 0:(n.selection=null,void D(t,d));n.selection=s;const u=s.caret,h=s.color,p=s.selections,g=s.anchor,y=s.focus,_=g.key,m=y.key,x=i.get(_),T=i.get(m);if(null==x||null==T)return;let N;if(x===T&&e.$isLineBreakNode(x)){N=[r.getElementByKey(_).getBoundingClientRect()]}else{const e=o.createDOMRange(r,x,g.offset,T,y.offset);if(null===e)return;N=o.createRectsFromDOMRange(r,e)}const b=p.length,S=N.length;for(let e=0;e<S;e++){const t=N[e];let n=p[e];if(void 0===n){n=document.createElement("span"),p[e]=n;const t=document.createElement("span");n.appendChild(t),c.appendChild(n)}const o=`position:absolute;top:${t.top-f.top}px;left:${t.left-f.left}px;height:${t.height}px;width:${t.width}px;pointer-events:none;z-index:5;`;n.style.cssText=o,n.firstChild.style.cssText=`${o}left:0;top:0;background-color:${h};opacity:0.3;`,e===S-1&&u.parentNode!==n&&n.appendChild(u)}for(let e=b-1;e>=S;e--){const t=p[e];c.removeChild(t),p.pop()}}function U(t,n){const{anchorPos:o,focusPos:s}=n,i=o?I(o,t):null,r=s?I(s,t):null;if(null===i||null===r)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(L(t)){const[e,t]=q(i.type,i.index),[n,o]=q(r.type,r.index);return{anchorKey:null!==e?e.getKey():null,anchorOffset:t,focusKey:null!==n?n.getKey():null,focusOffset:o}}let[l,c]=V(t.mapping,i),[a,f]=V(t.mapping,r);if(a&&l&&(a!==l||f!==c)){const t=a.isBefore(l),n=t?a:l,o=t?f:c;e.$isTextNode(n)&&e.$isTextNode(n.getNextSibling())&&o===n.getTextContentSize()&&(t?(a=n.getNextSibling(),f=0):(l=n.getNextSibling(),c=0))}return{anchorKey:null!==l?l.getKey():null,anchorOffset:c,focusKey:null!==a?a.getKey():null,focusOffset:f}}function G(t,n){const o=n.awareness.getLocalState();if(null===o)return;const{anchorKey:s,anchorOffset:i,focusKey:r,focusOffset:l}=U(t,o);if(null!==s&&null!==r){const t=e.$getSelection();if(!e.$isRangeSelection(t))return;H(t.anchor,s,i),H(t.focus,r,l)}}function H(t,n,o){if(t.key!==n||t.offset!==o){let s=e.$getNodeByKey(n);if(null!==s&&!e.$isElementNode(s)&&!e.$isTextNode(s)){const e=s.getParentOrThrow();n=e.getKey(),o=s.getIndexWithinParent(),s=e}t.set(n,o,e.$isElementNode(s)?"element":"text")}}function q(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof K){const{node:e,offset:o}=$(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function V(n,o){const s=o.type,i=o.index;if(s instanceof t.XmlElement){const t=n.get(s);if(void 0===t)return[null,0];if(!e.$isElementNode(t))return[t,i];let o=i,r=0;const l=t.getChildren();for(;o>0&&r<l.length;){const t=l[r];if(o-=1,r+=1,e.$isTextNode(t))for(;r<l.length&&e.$isTextNode(l[r]);)r+=1}return[t,r]}{const e=n.get(s);if(void 0===e)return[null,0];let t=0,o=i;for(;o>e[t].getTextContentSize()&&t+1<e.length;)o-=e[t].getTextContentSize(),t++;const r=e[t];return[r,Math.min(o,r.getTextContentSize())]}}function J(e,t){return t.awareness.getStates()}function Q(e,t,n){const{getAwarenessStates:o=J}=n??{},s=Array.from(o(e,t)),i=e.clientID,r=e.cursors,l=e.editor,c=l._editorState._nodeMap,a=new Set;for(let t=0;t<s.length;t++){const n=s[t],[o,f]=n;if(o!==i){a.add(o);const{name:t,color:n,focusing:s}=f;let i=null,d=r.get(o);if(void 0===d&&(d=z(t,n),r.set(o,d)),s){const{anchorKey:t,anchorOffset:n,focusKey:o,focusOffset:s}=l.read(()=>U(e,f));if(null!==t&&null!==o)if(i=d.selection,null===i)i=B(d,t,n,o,s);else{const e=i.anchor,r=i.focus;e.key=t,e.offset=n,r.key=o,r.offset=s}}W(e,d,i,c)}}const f=Array.from(r.keys());for(let t=0;t<f.length;t++){const n=f[t];if(!a.has(n)){const t=r.get(n);void 0!==t&&(Y(e,t),r.delete(n))}}}function Z(t,n,o,s){const i=n.awareness,r=i.getLocalState();if(null===r)return;const{anchorPos:l,focusPos:c,name:a,color:f,focusing:d,awarenessData:u}=r;let h=null,p=null;(null!==s&&(null===l||s.is(o))||null!==o)&&(e.$isRangeSelection(s)&&(L(t)?(h=j(s.anchor,t),p=j(s.focus,t)):(h=R(s.anchor,t),p=R(s.focus,t))),(X(l,h)||X(c,p))&&i.setLocalState({...r,anchorPos:h,awarenessData:u,color:f,focusPos:p,focusing:d,name:a}))}const ee=e=>"UNDEFINED"===e.nodeName,te=(n,o,i,r,l,c,a)=>{let f=o.mapping.get(n);if(f&&i&&0===i.size&&!r)return f;const d=ee(n)?e.RootNode.getType():n.nodeName,u=o.editor._nodes.get(d);if(void 0===u)throw new Error(`$createOrUpdateNodeFromYElement: Node ${d} is not registered`);if(f||(f=new u.klass,i=null,r=!0),r&&f instanceof e.ElementNode){const e=[],i=n=>{if(n instanceof t.XmlElement){const t=te(n,o,new Set,!1,l,c,a);null!==t&&e.push(t)}else if(n instanceof t.XmlText){const t=oe(n,o,l,c,a);null!==t&&t.forEach(t=>{null!==t&&e.push(t)})}else s(327)};n.toArray().forEach(i),ne(f,e)}const h=n.getAttributes(l),p={...g(f,o)},y={};for(const e in h)e.startsWith(ge)?y[_e(e)]=h[e]:p[e]=h[e];if(T(o,p,f,i),i){const t=Object.keys(y).filter(e=>i.has(ye(e)));if(t.length>0){const n=e.$getWritableNodeState(f);for(const e of t)n.updateFromUnknown(e,y[e])}}else e.$getWritableNodeState(f).updateFromJSON(y);const _=f.getLatest();return o.mapping.set(n,_),_},ne=(e,t)=>{const n=e.getChildren(),o=new Set(n.map(e=>e.getKey())),s=new Set(t.map(e=>e.getKey())),i=n.length-1,r=t.length-1;let l=0,c=0;for(;l<=i&&c<=r;){const i=n[l].getKey(),r=t[c].getKey();if(i===r){l++,c++;continue}const a=s.has(i),f=o.has(r);if(!a){if(0===c&&1===e.getChildrenSize())return void e.splice(c,1,t.slice(c));e.splice(c,1,[]),l++;continue}const d=t[c];f?(e.splice(c,1,[d]),l++,c++):(e.splice(c,0,[d]),c++)}const a=l>i,f=c>r;a&&!f?e.append(...t.slice(c)):f&&!a&&e.splice(t.length,e.getChildrenSize()-t.length,[])},oe=(t,n,o,s,i)=>{const r=he(t,o,s,i);let l=n.mapping.get(t)??[];const c=r.map(t=>t.attributes.t??e.TextNode.getType());if(!(l.length===c.length&&l.every((e,t)=>e.getType()===c[t]))){const t=n.editor._nodes;l=c.map(n=>{const o=t.get(n);if(void 0===o)throw new Error(`$createTextNodesFromYText: Node ${n} is not registered`);const s=new o.klass;if(!e.$isTextNode(s))throw new Error(`$createTextNodesFromYText: Node ${n} is not a TextNode`);return s})}for(let t=0;t<r.length;t++){const o=l[t],s=r[t],{attributes:i,insert:c}=s;o.__text!==c&&o.setTextContent(c);const a={...g(o,n),...i.p},f=Object.fromEntries(Object.entries(i).filter(([e])=>e.startsWith(ge)).map(([e,t])=>[_e(e),t]));T(n,a,o,null),e.$getWritableNodeState(o).updateFromJSON(f)}const a=l.map(e=>e.getLatest());return n.mapping.set(t,a),a},se=(n,o)=>n instanceof Array?((e,n)=>{const o=new t.XmlText;return ue(o,e,n),o})(n,o):((n,o)=>{const s=new t.XmlElement(n.getType()),i={...pe(n,o),...me(n)};for(const e in i){const t=i[e];null!==t&&s.setAttribute(e,t)}return n instanceof e.ElementNode?(s.insert(0,le(n).map(e=>se(e,o))),o.mapping.set(s,n),s):s})(n,o),ie=e=>"object"==typeof e&&null!=e,re=(e,t)=>{const n=Object.keys(e).filter(t=>null!==e[t]);if(null==t)return 0===n.length;let o=n.length===Object.keys(t).filter(e=>null!==t[e]).length;for(let s=0;s<n.length&&o;s++){const i=n[s],r=e[i],l=t[i];o="ychange"===i||r===l||ie(r)&&ie(l)&&re(r,l)}return o},le=t=>{if(!(t instanceof e.ElementNode))return[];const n=t.getChildren(),o=[];for(let t=0;t<n.length;t++){const s=n[t];if(e.$isTextNode(s)){const s=[];for(let o=n[t];t<n.length&&e.$isTextNode(o);o=n[++t])s.push(o);t--,o.push(s)}else o.push(s)}return o},ce=(t,n,o)=>{const s=he(t);return s.length===n.length&&s.every((t,s)=>{const i=n[s],r=t.attributes.t??e.TextNode.getType(),l=t.attributes.p??{},c=Object.fromEntries(Object.entries(t.attributes).filter(([e])=>e.startsWith(ge)));return t.insert===i.getTextContent()&&r===i.getType()&&re(l,pe(i,o))&&re(c,me(i))})},ae=(e,n,o)=>{if(e instanceof t.XmlElement&&!(n instanceof Array)&&Te(e,n)){const t=le(n);return e._length===t.length&&re(e.getAttributes(),{...pe(n,o),...me(n)})&&e.toArray().every((e,n)=>ae(e,t[n],o))}return e instanceof t.XmlText&&n instanceof Array&&ce(e,n,o)},fe=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),de=(e,n,o)=>{const s=e.toArray(),i=le(n),r=i.length,l=s.length,c=Math.min(l,r);let a=0,f=0,d=!1;for(;a<c;a++){const e=s[a],n=i[a];if(e instanceof t.XmlHook)break;if(fe(o.mapping.get(e),n))d=!0;else if(!ae(e,n,o))break}for(;a+f<c;f++){const e=s[l-f-1],n=i[r-f-1];if(e instanceof t.XmlHook)break;if(fe(o.mapping.get(e),n))d=!0;else if(!ae(e,n,o))break}return{equalityFactor:a+f,foundMappedChild:d}},ue=(n,o,s)=>{s.mapping.set(n,o);const{nAttrs:i,str:r}=(e=>{let n="",o=e._start;const s={};for(;null!==o;)o.deleted||(o.countable&&o.content instanceof t.ContentString?n+=o.content.str:o.content instanceof t.ContentFormat&&(s[o.content.key]=null)),o=o.right;return{nAttrs:s,str:n}})(n),c=o.map((t,n)=>{const o=t.getType();let r=pe(t,s);return 0===Object.keys(r).length&&(r=null),{attributes:Object.assign({},i,{...o!==e.TextNode.getType()&&{t:o},p:r,...me(t),...n>0&&{i:n}}),insert:t.getTextContent(),nodeKey:t.getKey()}}),a=c.map(e=>e.insert).join(""),f=e.$getSelection();let d;if(e.$isRangeSelection(f)&&f.isCollapsed()){d=0;for(const e of c){if(e.nodeKey===f.anchor.key){d+=f.anchor.offset;break}d+=e.insert.length}}else d=a.length;const{insert:u,remove:h,index:p}=l(r,a,d);n.delete(p,h),n.insert(p,u),n.applyDelta(c.map(e=>({attributes:e.attributes,retain:e.insert.length})))},he=(e,t,n,o)=>e.toDelta(t,n,o).map(e=>({...e,attributes:e.attributes??{}})),pe=(e,t)=>{const n=g(e,t),o={};return Object.entries(n).forEach(([t,n])=>{const s=e[t];s!==n&&(o[t]=s)}),o},ge="s_",ye=e=>ge+e,_e=e=>{if(!e.startsWith(ge))throw new Error(`Invalid state key: ${e}`);return e.slice(ge.length)},me=e=>{const t=e.__state;if(!t)return{};const[n={},o]=t.getInternalState(),s={};for(const[e,t]of Object.entries(n))s[ye(e)]=t;for(const[e,t]of o)s[ye(e.key)]=e.unparse(t);return s},xe=(n,o,s,i,r)=>{if(o instanceof t.XmlElement&&o.nodeName!==s.getType()&&(!ee(o)||s.getType()!==e.RootNode.getType()))throw new Error("node name mismatch!");if(i.mapping.set(o,s),o instanceof t.XmlElement){const e=o.getAttributes(),t={...pe(s,i),...me(s)};for(const n in t)null!=t[n]?e[n]!==t[n]&&"ychange"!==n&&o.setAttribute(n,t[n]):o.removeAttribute(n);for(const n in e)void 0===t[n]&&o.removeAttribute(n)}const l=le(s),c=l.length,a=o.toArray(),f=a.length,d=Math.min(c,f);let u=0,h=0;for(;u<d;u++){const o=a[u],s=l[u];if(o instanceof t.XmlHook)break;if(fe(i.mapping.get(o),s))s instanceof e.ElementNode&&r.has(s.getKey())&&xe(n,o,s,i,r);else{if(!ae(o,s,i))break;i.mapping.set(o,s)}}for(;h+u<d;h++){const o=a[f-h-1],s=l[c-h-1];if(o instanceof t.XmlHook)break;if(fe(i.mapping.get(o),s))s instanceof e.ElementNode&&r.has(s.getKey())&&xe(n,o,s,i,r);else{if(!ae(o,s,i))break;i.mapping.set(o,s)}}for(;f-u-h>0&&c-u-h>0;){const e=a[u],s=l[u],d=a[f-h-1],p=l[c-h-1];if(e instanceof t.XmlText&&s instanceof Array)ce(e,s,i)||ue(e,s,i),u+=1;else{let l=e instanceof t.XmlElement&&Te(e,s),c=d instanceof t.XmlElement&&Te(d,p);if(l&&c){const t=de(e,s,i),n=de(d,p,i);t.foundMappedChild&&!n.foundMappedChild?c=!1:!t.foundMappedChild&&n.foundMappedChild||t.equalityFactor<n.equalityFactor?l=!1:c=!1}l?(xe(n,e,s,i,r),u+=1):c?(xe(n,d,p,i,r),h+=1):(i.mapping.delete(o.get(u)),o.delete(u,1),o.insert(u,[se(s,i)]),u+=1)}}const p=f-u-h;if(1===f&&0===c&&a[0]instanceof t.XmlText?(i.mapping.delete(a[0]),a[0].delete(0,a[0].length)):p>0&&(o.slice(u,u+p).forEach(e=>i.mapping.delete(e)),o.delete(u,p)),u+h<c){const e=[];for(let t=u;t<c-h;t++)e.push(se(l[t],i));o.insert(u,e)}},Te=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType();function Ne(n,o){if(o instanceof t.YMapEvent&&function(n,o){const{target:s}=o;if(!s._item||"__state"!==s._item.parentSub||void 0!==_(s)||!(s.parent instanceof t.XmlText||s.parent instanceof t.XmlElement||s.parent instanceof t.Map))return!1;const i=m(n,s.parent).getNode();if(i){const t=e.$getWritableNodeState(i.getWritable());for(const e of o.keysChanged)t.updateFromUnknown(e,s.get(e))}return!0}(n,o))return;const{target:i}=o,r=m(n,i);if(r instanceof K&&o instanceof t.YTextEvent){const{keysChanged:e,childListChanged:t,delta:s}=o;e.size>0&&r.syncPropertiesFromYjs(n,e),t&&(r.applyChildrenYjsDelta(n,s),r.syncChildrenFromYjs(n))}else if(r instanceof c&&o instanceof t.YMapEvent){const{keysChanged:e}=o;e.size>0&&r.syncPropertiesAndTextFromYjs(n,e)}else if(r instanceof w&&o instanceof t.YXmlEvent){const{attributesChanged:e}=o;e.size>0&&r.syncPropertiesFromYjs(n,e)}else s(82)}function be(t,n,o){const s=e.$getSelection();if(e.$isRangeSelection(s))if(E(s)){const i=t._selection;if(e.$isRangeSelection(i)&&(G(n,o),E(s))){v(s.anchor.key,t)}Z(n,o,i,e.$getSelection())}else G(n,o)}function Se(){0===e.$getRoot().getChildrenSize()&&e.$getRoot().append(e.$createParagraphNode())}function ke(e,n){const{target:o}=n;if(o instanceof t.XmlElement&&n instanceof t.YXmlEvent)te(o,e,n.attributesChanged,n.childListChanged);else if(o instanceof t.XmlText&&n instanceof t.YTextEvent){const n=o.parent;n instanceof t.XmlElement?te(n,e,new Set,!0):s(324)}else s(325)}const Ce=e.createCommand("CONNECTED_COMMAND"),$e=e.createCommand("TOGGLE_CONNECT_COMMAND");exports.CONNECTED_COMMAND=Ce,exports.TOGGLE_CONNECT_COMMAND=$e,exports.createBinding=function(e,n,o,i,r,l){null==i&&s(81);const c=M(i.get("root",t.XmlText),null,"root");return c._key="root",{...F(e,o,i,r,l),collabNodeMap:new Map,root:c}},exports.createBindingV2__EXPERIMENTAL=function(e,n,o,i,r={}){null==o&&s(81);const{excludedProperties:l,rootName:c="root-v2"}=r;return{...F(e,n,o,i,l),mapping:new P,root:o.get(c,t.XmlElement)}},exports.createUndoManager=function(e,n){return new t.UndoManager(n,{trackedOrigins:new Set([e,null])})},exports.getAnchorAndFocusCollabNodesForUserState=function(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,i=0,r=null,l=0;if(null!==n&&null!==o){const t=I(n,e),c=I(o,e);null!==t&&null!==c&&([s,i]=q(t.type,t.index),[r,l]=q(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:i,focusCollabNode:r,focusOffset:l}},exports.initLocalState=function(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})},exports.setLocalStateFocus=function(e,t,n,o,s){const{awareness:i}=e;let r=i.getLocalState();null===r&&(r={anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t}),r.focusing=o,i.setLocalState(r)},exports.syncCursorPositions=Q,exports.syncLexicalUpdateToYjs=function(t,n,o,s,i,r,l,a){O(t,()=>{s.read(()=>{if(a.has(e.COLLABORATION_TAG)||a.has(e.HISTORIC_TAG))return void(l.size>0&&function(t,n){const o=Array.from(n),s=t.collabNodeMap,i=[],r=[];for(let t=0;t<o.length;t++){const n=o[t],l=e.$getNodeByKey(n),a=s.get(n);if(a instanceof c)if(e.$isTextNode(l))i.push([a,l.__text]);else{const e=a.getOffset();if(-1===e)continue;const t=a._parent;a._normalized=!0,t._xmlText.delete(e,1),r.push(a)}}for(let e=0;e<r.length;e++){const t=r[e],n=t.getKey();s.delete(n);const o=t._parent._children,i=o.indexOf(t);o.splice(i,1)}for(let e=0;e<i.length;e++){const[t,n]=i[e];t._text=n}}(t,l));if(i.has("root")){const n=o._nodeMap,s=e.$getRoot(),l=t.root;l.syncPropertiesFromLexical(t,s,n),l.syncChildrenFromLexical(t,s,n,i,r)}const s=e.$getSelection(),f=o._selection;Z(t,n,f,s)})})},exports.syncLexicalUpdateToYjsV2__EXPERIMENTAL=function(t,n,o,s,i,r,l){(l.has(e.COLLABORATION_TAG)||l.has(e.HISTORIC_TAG))&&0===r.size||(r.forEach(e=>{t.mapping.deleteNode(e)}),O(t,()=>{s.read(()=>{i.has("root")&&xe(t.doc,t.root,e.$getRoot(),t,new Set(i.keys()));const s=e.$getSelection(),r=o._selection;Z(t,n,r,s)})}))},exports.syncYjsChangesToLexical=function(t,n,o,s,i=Q){const r=t.editor,l=r._editorState;o.forEach(e=>e.delta),r.update(()=>{for(let e=0;e<o.length;e++){const n=o[e];Ne(t,n)}be(l,t,n),s||e.$addUpdateTag(e.SKIP_SCROLL_INTO_VIEW_TAG)},{onUpdate:()=>{i(t,n),r.update(()=>Se())},skipTransforms:!0,tag:s?e.HISTORIC_TAG:e.COLLABORATION_TAG})},exports.syncYjsChangesToLexicalV2__EXPERIMENTAL=function(n,o,s,i,r){const l=n.editor,c=l._editorState;t.iterateDeletedStructs(i,i.deleteSet,e=>{if(e.constructor===t.Item){const t=e.content.type;t&&n.mapping.delete(t)}}),s.forEach(e=>e.delta),l.update(()=>{for(let e=0;e<s.length;e++){const t=s[e];ke(n,t)}be(c,n,o),r||e.$addUpdateTag(e.SKIP_SCROLL_INTO_VIEW_TAG)},{discrete:!0,onUpdate:()=>{Q(n,o),l.update(()=>Se())},skipTransforms:!0,tag:r?e.HISTORIC_TAG:e.COLLABORATION_TAG})};
|
|
9
|
+
"use strict";var e=require("lexical"),t=require("yjs"),n=require("@lexical/offset"),o=require("@lexical/selection");function s(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class i{_map;_key;_parent;_type;constructor(e,t){this._key="",this._map=e,this._parent=t,this._type="linebreak"}getNode(){const t=e.$getNodeByKey(this._key);return e.$isLineBreakNode(t)?t:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function r(e,t){const n=new i(e,t);return e._collabNode=n,n}function l(e,t,n){const o=e.length,s=t.length;let i=0,r=0;for(;i<o&&i<s&&e[i]===t[i]&&i<n;)i++;for(;r+i<o&&r+i<s&&e[o-r-1]===t[s-r-1];)r++;for(;r+i<o&&r+i<s&&e[i]===t[i];)i++;return{index:i,insert:t.slice(i,s-r),remove:o-i-r}}class c{_map;_key;_parent;_text;_type;_normalized;constructor(e,t,n,o){this._key="",this._map=e,this._parent=n,this._text=t,this._type=o,this._normalized=!1}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e.$isTextNode(n)?n:null}getNode(){const t=e.$getNodeByKey(this._key);return e.$isTextNode(t)?t: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(e,t,n){const o=this._parent._xmlText,s=this.getOffset()+1+e;0!==t&&o.delete(s,t),""!==n&&o.insert(s,n)}syncPropertiesAndTextFromLexical(t,n,o){const s=this.getPrevNode(o),i=n.__text;if(k(t,this._map,s,n),null!==s){const t=s.__text;if(t!==i){!function(t,n,o,s){const i=e.$getSelection();let r=s.length;if(e.$isRangeSelection(i)&&i.isCollapsed()){const e=i.anchor;e.key===n&&(r=e.offset)}const c=l(o,s,r);t.spliceText(c.index,c.remove,c.insert)}(this,n.__key,t,i),this._text=i}}}syncPropertiesAndTextFromYjs(e,t){const n=this.getNode();null===n&&s(84),T(e,this._map,n,t);const o=this._text;n.__text!==o&&n.setTextContent(o)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function a(e,t,n,o){const s=new c(e,t,n,o);return e._collabNode=s,s}const f=new Set(["__key","__parent","__next","__prev","__state"]),d=new Set(["__first","__last","__size"]),u=new Set(["__cachedText"]),h=new Set(["__text"]);function p(t,n,o){if(f.has(t)||"function"==typeof n[t])return!0;if(e.$isTextNode(n)){if(h.has(t))return!0}else if(e.$isElementNode(n)&&(d.has(t)||e.$isRootNode(n)&&u.has(t)))return!0;const s=n.constructor,i=o.excludedProperties.get(s);return null!=i&&i.has(t)}function g(e,t){const n=e.__type,{nodeProperties:o}=t,i=o.get(n);return void 0===i&&s(326,n),i}function y(n,o,i){const l=o.__type;let c;if(e.$isElementNode(o)){c=M(new t.XmlText,i,l),c.syncPropertiesFromLexical(n,o,null),c.syncChildrenFromLexical(n,o,null,null,null)}else if(e.$isTextNode(o)){c=a(new t.Map,o.__text,i,l),c.syncPropertiesAndTextFromLexical(n,o,null)}else if(e.$isLineBreakNode(o)){const e=new t.Map;e.set("__type","linebreak"),c=r(e,i)}else if(e.$isDecoratorNode(o)){c=A(new t.XmlElement,i,l),c.syncPropertiesFromLexical(n,o,null)}else s(86);return c._key=o.__key,c}function _(e){const t=N(e,"__type");return"string"!=typeof t&&void 0!==t&&s(87),t}function m(e,n,o){const i=n._collabNode;if(void 0===i){const i=e.editor._nodes,l=_(n);"string"!=typeof l&&s(87);void 0===i.get(l)&&s(88,l);const c=n.parent,f=void 0===o&&null!==c?m(e,c):o||null;if(f instanceof K||s(89),n instanceof t.XmlText)return M(n,f,l);if(n instanceof t.Map)return"linebreak"===l?r(n,f):a(n,"",f,l);if(n instanceof t.XmlElement)return A(n,f,l)}return i}function x(e,t,n){const o=t.getType(),i=e.editor._nodes.get(o);void 0===i&&s(88,o);const r=new i.klass;if(r.__parent=n,t._key=r.__key,t instanceof K){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof c?t.syncPropertiesAndTextFromYjs(e,null):t instanceof w&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(r.__key,t),r}function T(n,o,s,i){const r=null===i?o instanceof t.Map?Array.from(o.keys()):o instanceof t.XmlText||o instanceof t.XmlElement?Object.keys(o.getAttributes()):Object.keys(o):Array.from(i);let l;for(let i=0;i<r.length;i++){const c=r[i];if(p(c,s,n)){"__state"===c&&L(n)&&(l||(l=s.getWritable()),S(o,l));continue}const a=s[c];let f=N(o,c);if(a!==f){if(f instanceof t.Doc){const o=n.docMap;a instanceof t.Doc&&o.delete(a.guid);const s=e.createEditor(),i=f.guid;s._key=i,o.set(i,f),f=s}void 0===l&&(l=s.getWritable()),l[c]=f}}}function N(e,n){return e instanceof t.Map?e.get(n):e instanceof t.XmlText||e instanceof t.XmlElement?e.getAttribute(n):e[n]}function b(e,n,o){e instanceof t.Map?e.set(n,o):e.setAttribute(n,o)}function S(n,o){const s=N(n,"__state");s instanceof t.Map&&e.$getWritableNodeState(o).updateFromJSON(s.toJSON())}function k(e,n,o,s){const i=Object.keys(g(s,e)),r=e.editor.constructor;!function(e,n,o,s){const i=s.__state,r=N(n,"__state");if(!i)return;const[l,c]=i.getInternalState(),a=o&&o.__state,f=r instanceof t.Map?r:new t.Map;if(a===i)return;const[d,u]=a&&f.doc?a.getInternalState():[void 0,new Map];if(l)for(const[e,t]of Object.entries(l))d&&t!==d[e]&&f.set(e,t);for(const[e,t]of c)u.get(e)!==t&&f.set(e.key,e.unparse(t));r||b(n,"__state",f)}(0,n,o,s);for(let l=0;l<i.length;l++){const c=i[l],a=null===o?void 0:o[c];let f=s[c];if(a!==f){if(f instanceof r){const n=e.docMap;let o;if(a instanceof r){const e=a._key;o=n.get(e),n.delete(e)}const i=o||new t.Doc,l=i.guid;f._key=l,n.set(l,i),f=i,e.editor.update(()=>{s.markDirty()})}b(n,c,f)}}}function C(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function $(e,t,n){let o=0,s=0;const i=e._children,r=i.length;for(;s<r;s++){const e=i[s],l=o;o+=e.getSize();if((n?o>=t:o>t)&&e instanceof c){let n=t-l-1;n<0&&(n=0);return{length:o-t,node:e,nodeIndex:s,offset:n}}if(o>t)return{length:0,node:e,nodeIndex:s,offset:l};if(s===r-1)return{length:0,node:null,nodeIndex:s+1,offset:l+1}}return{length:0,node:null,nodeIndex:0,offset:0}}function E(t){const n=t.anchor,o=t.focus;let s=!1;try{const t=n.getNode(),i=o.getNode();(!t.isAttached()||!i.isAttached()||e.$isTextNode(t)&&n.offset>t.getTextContentSize()||e.$isTextNode(i)&&o.offset>i.getTextContentSize())&&(s=!0)}catch(e){s=!0}return s}function O(e,t){e.doc.transact(t,e)}function v(t,n){const o=n._nodeMap.get(t);if(!o)return void e.$getRoot().selectStart();const s=o.__prev;let i=null;s&&(i=e.$getNodeByKey(s)),null===i&&null!==o.__parent&&(i=e.$getNodeByKey(o.__parent)),null!==i?null!==i&&i.isAttached()?i.selectEnd():v(i.__key,n):e.$getRoot().selectStart()}class w{_xmlElem;_key;_parent;_type;constructor(e,t,n){this._key="",this._xmlElem=e,this._parent=t,this._type=n}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e.$isDecoratorNode(n)?n:null}getNode(){const t=e.$getNodeByKey(this._key);return e.$isDecoratorNode(t)?t:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}syncPropertiesFromLexical(e,t,n){const o=this.getPrevNode(n);k(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&s(83);T(e,this._xmlElem,n,t)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function A(e,t,n){const o=new w(e,t,n);return e._collabNode=o,o}class K{_key;_children;_xmlText;_type;_parent;constructor(e,t,n){this._key="",this._children=[],this._xmlText=e,this._type=n,this._parent=t}getPrevNode(t){if(null===t)return null;const n=t.get(this._key);return e.$isElementNode(n)?n:null}getNode(){const t=e.$getNodeByKey(this._key);return e.$isElementNode(t)?t:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){const e=this._parent;return null===e&&s(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&s(91),T(e,this._xmlText,n,t)}applyChildrenYjsDelta(e,t){const n=this._children;let o=0,s=null;for(let r=0;r<t.length;r++){const l=t[r],a=l.insert,f=l.delete;if(null!=l.retain)o+=l.retain;else if("number"==typeof f){let e=f;for(;e>0;){const{node:t,nodeIndex:s,offset:r,length:l}=$(this,o,!1);if(t instanceof K||t instanceof i||t instanceof w)n.splice(s,1),e-=1;else{if(!(t instanceof c))break;{const o=Math.min(e,l),i=0!==s?n[s-1]:null,a=t.getSize();if(0===r&&l===a){n.splice(s,1);const e=C(t._text,r,o-1,"");e.length>0&&(i instanceof c?i._text+=e:this._xmlText.delete(r,e.length))}else t._text=C(t._text,r,o,"");e-=o}}}}else{if(null==a)throw new Error("Unexpected delta format");if("string"==typeof a){const{node:e,offset:t}=$(this,o,!0);e instanceof c?e._text=C(e._text,t,0,a):this._xmlText.delete(t,a.length),o+=a.length}else{const t=a,{node:i,nodeIndex:r,length:l}=$(this,o,!1),f=m(e,t,this);if(i instanceof c&&l>0&&l<i._text.length){const e=i._text,t=e.length-l;i._text=C(e,t,l,""),n.splice(r+1,0,f),s=C(e,0,t,"")}else n.splice(r,0,f);null!==s&&f instanceof c&&(f._text=s+f._text,s=null),o+=1}}}}syncChildrenFromYjs(t){const o=this.getNode();null===o&&s(92);const r=o.__key,l=n.$createChildrenArray(o,null),a=l.length,f=this._children,d=f.length,u=t.collabNodeMap,h=new Set;let p,g,y=0,_=null;d!==a&&(g=o.getWritable());for(let n=0;n<d;n++){const a=l[y],m=f[n],T=m.getNode(),N=m._key;if(null!==T&&a===N){const n=e.$isTextNode(T);if(h.add(a),n)if(m._key=a,m instanceof K){const e=m._xmlText;m.syncPropertiesFromYjs(t,null),m.applyChildrenYjsDelta(t,e.toDelta()),m.syncChildrenFromYjs(t)}else m instanceof c?m.syncPropertiesAndTextFromYjs(t,null):m instanceof w?m.syncPropertiesFromYjs(t,null):m instanceof i||s(93);_=T,y++}else{if(void 0===p){p=new Set;for(let e=0;e<d;e++){const t=f[e]._key;""!==t&&p.add(t)}}if(null!==T&&void 0!==a&&!p.has(a)){const t=e.$getNodeByKeyOrThrow(a);e.removeFromParent(t),n--,y++;continue}g=o.getWritable();const s=x(t,m,r),i=s.__key;if(u.set(i,m),null===_){const e=g.getFirstChild();if(g.__first=i,null!==e){const t=e.getWritable();t.__prev=i,s.__next=t.__key}}else{const e=_.getWritable(),t=_.getNextSibling();if(e.__next=i,s.__prev=_.__key,null!==t){const e=t.getWritable();e.__prev=i,s.__next=e.__key}}n===d-1&&(g.__last=i),g.__size++,_=s}}for(let n=0;n<a;n++){const o=l[n];if(!h.has(o)){const n=e.$getNodeByKeyOrThrow(o),s=t.collabNodeMap.get(o);void 0!==s&&s.destroy(t),e.removeFromParent(n)}}}syncPropertiesFromLexical(e,t,n){k(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(t,n,o,s,i,r){const l=this._children[n],a=e.$getNodeByKeyOrThrow(o);l instanceof K&&e.$isElementNode(a)?(l.syncPropertiesFromLexical(t,a,s),l.syncChildrenFromLexical(t,a,s,i,r)):l instanceof c&&e.$isTextNode(a)?l.syncPropertiesAndTextFromLexical(t,a,s):l instanceof w&&e.$isDecoratorNode(a)&&l.syncPropertiesFromLexical(t,a,s)}syncChildrenFromLexical(t,o,s,i,r){const l=this.getPrevNode(s),c=null===l?[]:n.$createChildrenArray(l,s),a=n.$createChildrenArray(o,null),f=c.length-1,d=a.length-1,u=t.collabNodeMap;let h,p,g=0,_=0;for(;g<=f&&_<=d;){const n=c[g],o=a[_];if(n===o)this._syncChildFromLexical(t,_,o,s,i,r),g++,_++;else{void 0===h&&(h=new Set(c)),void 0===p&&(p=new Set(a));const s=p.has(n),i=h.has(o);if(s){const n=y(t,e.$getNodeByKeyOrThrow(o),this);u.set(o,n),i?(this.splice(t,_,1,n),g++,_++):(this.splice(t,_,0,n),_++)}else this.splice(t,_,1),g++}}const m=g>f,x=_>d;if(m&&!x)for(;_<=d;++_){const n=a[_],o=y(t,e.$getNodeByKeyOrThrow(n),this);this.append(o),u.set(n,o)}else if(x&&!m)for(let e=this._children.length-1;e>=_;e--)this.splice(t,e,1)}append(e){const t=this._xmlText,n=this._children,o=n[n.length-1],s=void 0!==o?o.getOffset()+o.getSize():0;if(e instanceof K)t.insertEmbed(s,e._xmlText);else if(e instanceof c){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof i?t.insertEmbed(s,e._map):e instanceof w&&t.insertEmbed(s,e._xmlElem);this._children.push(e)}splice(e,t,n,o){const r=this._children,l=r[t];if(void 0===l)return void 0===o&&s(94),void this.append(o);const a=l.getOffset();-1===a&&s(95);const f=this._xmlText;if(0!==n&&f.delete(a,l.getSize()),o instanceof K)f.insertEmbed(a,o._xmlText);else if(o instanceof c){const e=o._map;null===e.parent&&f.insertEmbed(a,e),f.insert(a+1,o._text)}else o instanceof i?f.insertEmbed(a,o._map):o instanceof w&&f.insertEmbed(a,o._xmlElem);if(0!==n){const o=r.slice(t,t+n);for(let t=0;t<o.length;t++)o[t].destroy(e)}void 0!==o?r.splice(t,n,o):r.splice(t,n)}getChildOffset(e){let t=0;const n=this._children;for(let o=0;o<n.length;o++){const s=n[o];if(s===e)return t;t+=s.getSize()}return-1}destroy(e){const t=e.collabNodeMap,n=this._children;for(let t=0;t<n.length;t++)n[t].destroy(e);t.get(this._key)===this&&t.delete(this._key)}}function M(e,t,n){const o=new K(e,t,n);return e._collabNode=o,o}class P{_nodeMap=new Map;_sharedTypeToNodeKeys=new Map;_nodeKeyToSharedType=new Map;set(n,o){const i=o instanceof Array;this.delete(n);const r=i?o:[o];for(const e of r){const t=e.getKey();if(this._nodeKeyToSharedType.has(t)){const e=this._nodeKeyToSharedType.get(t),n=this._sharedTypeToNodeKeys.get(e).indexOf(t);-1!==n&&this._sharedTypeToNodeKeys.get(e).splice(n,1),this._nodeKeyToSharedType.delete(t),this._nodeMap.delete(t)}}if(n instanceof t.XmlText){if(i||s(327),0===o.length)return;this._sharedTypeToNodeKeys.set(n,o.map(e=>e.getKey()));for(const e of o)this._nodeMap.set(e.getKey(),e),this._nodeKeyToSharedType.set(e.getKey(),n)}else i&&s(328),e.$isTextNode(o)&&s(329),this._sharedTypeToNodeKeys.set(n,[o.getKey()]),this._nodeMap.set(o.getKey(),o),this._nodeKeyToSharedType.set(o.getKey(),n)}get(e){const n=this._sharedTypeToNodeKeys.get(e);if(void 0!==n){if(e instanceof t.XmlText){const e=Array.from(n.map(e=>this._nodeMap.get(e)));return e.length>0?e:void 0}return this._nodeMap.get(n[0])}}getSharedType(e){return this._nodeKeyToSharedType.get(e.getKey())}delete(e){const t=this._sharedTypeToNodeKeys.get(e);if(void 0!==t){for(const e of t)this._nodeMap.delete(e),this._nodeKeyToSharedType.delete(e);this._sharedTypeToNodeKeys.delete(e)}}deleteNode(e){const t=this._nodeKeyToSharedType.get(e);t&&this.delete(t),this._nodeMap.delete(e)}has(e){return this._sharedTypeToNodeKeys.has(e)}}function F(e,t,n,o,i){null==n&&s(81);const r={clientID:n.clientID,cursors:new Map,cursorsContainer:null,doc:n,docMap:o,editor:e,excludedProperties:i||new Map,id:t,nodeProperties:new Map};return function(e){const{editor:t,nodeProperties:n}=e;t.update(()=>{t._nodes.forEach(t=>{const o=new t.klass,s={};for(const[t,n]of Object.entries(o))p(t,o,e)||(s[t]=n);n.set(o.__type,Object.freeze(s))})})}(r),r}function L(e){return Object.hasOwn(e,"collabNodeMap")}function j(n,o){const i=o.collabNodeMap.get(n.key);if(void 0===i)return null;let r=n.offset,l=i.getSharedType();if(i instanceof c){l=i._parent._xmlText;const e=i.getOffset();if(-1===e)return null;r=e+1+r}else if(i instanceof K&&"element"===n.type){const t=n.getNode();e.$isElementNode(t)||s(184);let o=0,i=0,l=t.getFirstChild();for(;null!==l&&i++<r;)e.$isTextNode(l)?o+=l.getTextContentSize()+1:o++,l=l.getNextSibling();r=o}return t.createRelativePositionFromTypeIndex(l,r)}function R(n,o){const{mapping:i}=o,{offset:r}=n,l=n.getNode(),c=i.getSharedType(l);if(void 0===c)return null;if("text"===n.type){e.$isTextNode(l)||s(325);let n=l.getPreviousSibling(),o=r;for(;e.$isTextNode(n);)o+=n.getTextContentSize(),n=n.getPreviousSibling();return t.createRelativePositionFromTypeIndex(c,o)}if("element"===n.type){e.$isElementNode(l)||s(184);let n=0,o=l.getFirstChild();for(;null!==o&&n<r;){if(e.$isTextNode(o)){let t=o.getNextSibling();for(;e.$isTextNode(t);)t=t.getNextSibling()}n++,o=o.getNextSibling()}return t.createRelativePositionFromTypeIndex(c,n)}return null}function I(e,n){return t.createAbsolutePositionFromRelativePosition(e,n.doc)}function X(e,n){if(null==e){if(null!=n)return!0}else if(null==n||!t.compareRelativePositions(e,n))return!0;return!1}function z(e,t){return{color:t,name:e,selection:null}}function D(e,t){const n=e.cursorsContainer;if(null!==n){const e=t.selections,o=e.length;for(let t=0;t<o;t++)n.removeChild(e[t])}}function Y(e,t){const n=t.selection;null!==n&&D(e,n)}function B(e,t,n,o,s){const i=e.color,r=document.createElement("span");r.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${i};z-index:10;`;const l=document.createElement("span");return l.textContent=e.name,l.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${i};color:#fff;line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`,r.appendChild(l),{anchor:{key:t,offset:n},caret:r,color:i,focus:{key:o,offset:s},name:l,selections:[]}}function W(t,n,s,i){const r=t.editor,l=r.getRootElement(),c=t.cursorsContainer;if(null===c||null===l)return;const a=c.offsetParent;if(null===a)return;const f=a.getBoundingClientRect(),d=n.selection;if(null===s)return null===d?void 0:(n.selection=null,void D(t,d));n.selection=s;const u=s.caret,h=s.color,p=s.selections,g=s.anchor,y=s.focus,_=g.key,m=y.key,x=i.get(_),T=i.get(m);if(null==x||null==T)return;let N;if(x===T&&e.$isLineBreakNode(x)){N=[r.getElementByKey(_).getBoundingClientRect()]}else{const e=o.createDOMRange(r,x,g.offset,T,y.offset);if(null===e)return;N=o.createRectsFromDOMRange(r,e)}const b=p.length,S=N.length;for(let e=0;e<S;e++){const t=N[e];let n=p[e];if(void 0===n){n=document.createElement("span"),p[e]=n;const t=document.createElement("span");n.appendChild(t),c.appendChild(n)}const o=`position:absolute;top:${t.top-f.top}px;left:${t.left-f.left}px;height:${t.height}px;width:${t.width}px;pointer-events:none;z-index:5;`;n.style.cssText=o,n.firstChild.style.cssText=`${o}left:0;top:0;background-color:${h};opacity:0.3;`,e===S-1&&u.parentNode!==n&&n.appendChild(u)}for(let e=b-1;e>=S;e--){const t=p[e];c.removeChild(t),p.pop()}}function U(t,n){const{anchorPos:o,focusPos:s}=n,i=o?I(o,t):null,r=s?I(s,t):null;if(null===i||null===r)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(L(t)){const[e,t]=q(i.type,i.index),[n,o]=q(r.type,r.index);return{anchorKey:null!==e?e.getKey():null,anchorOffset:t,focusKey:null!==n?n.getKey():null,focusOffset:o}}let[l,c]=V(t.mapping,i),[a,f]=V(t.mapping,r);if(a&&l&&(a!==l||f!==c)){const t=a.isBefore(l),n=t?a:l,o=t?f:c;e.$isTextNode(n)&&e.$isTextNode(n.getNextSibling())&&o===n.getTextContentSize()&&(t?(a=n.getNextSibling(),f=0):(l=n.getNextSibling(),c=0))}return{anchorKey:null!==l?l.getKey():null,anchorOffset:c,focusKey:null!==a?a.getKey():null,focusOffset:f}}function G(t,n){const o=n.awareness.getLocalState();if(null===o)return;const{anchorKey:s,anchorOffset:i,focusKey:r,focusOffset:l}=U(t,o);if(null!==s&&null!==r){const t=e.$getSelection();if(!e.$isRangeSelection(t))return;H(t.anchor,s,i),H(t.focus,r,l)}}function H(t,n,o){if(t.key!==n||t.offset!==o){let s=e.$getNodeByKey(n);if(null!==s&&!e.$isElementNode(s)&&!e.$isTextNode(s)){const e=s.getParentOrThrow();n=e.getKey(),o=s.getIndexWithinParent(),s=e}t.set(n,o,e.$isElementNode(s)?"element":"text")}}function q(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof K){const{node:e,offset:o}=$(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function V(n,o){const s=o.type,i=o.index;if(s instanceof t.XmlElement){const t=n.get(s);if(void 0===t)return[null,0];if(!e.$isElementNode(t))return[t,i];let o=i,r=0;const l=t.getChildren();for(;o>0&&r<l.length;){const t=l[r];if(o-=1,r+=1,e.$isTextNode(t))for(;r<l.length&&e.$isTextNode(l[r]);)r+=1}return[t,r]}{const e=n.get(s);if(void 0===e)return[null,0];let t=0,o=i;for(;o>e[t].getTextContentSize()&&t+1<e.length;)o-=e[t].getTextContentSize(),t++;const r=e[t];return[r,Math.min(o,r.getTextContentSize())]}}function J(e,t){return t.awareness.getStates()}function Q(e,t,n){const{getAwarenessStates:o=J}=n??{},s=Array.from(o(e,t)),i=e.clientID,r=e.cursors,l=e.editor,c=l._editorState._nodeMap,a=new Set;for(let t=0;t<s.length;t++){const n=s[t],[o,f]=n;if(o!==i){a.add(o);const{name:t,color:n,focusing:s}=f;let i=null,d=r.get(o);if(void 0===d&&(d=z(t,n),r.set(o,d)),s){const{anchorKey:t,anchorOffset:n,focusKey:o,focusOffset:s}=l.read(()=>U(e,f));if(null!==t&&null!==o)if(i=d.selection,null===i)i=B(d,t,n,o,s);else{const e=i.anchor,r=i.focus;e.key=t,e.offset=n,r.key=o,r.offset=s}}W(e,d,i,c)}}const f=Array.from(r.keys());for(let t=0;t<f.length;t++){const n=f[t];if(!a.has(n)){const t=r.get(n);void 0!==t&&(Y(e,t),r.delete(n))}}}function Z(t,n,o,s){const i=n.awareness,r=i.getLocalState();if(null===r)return;const{anchorPos:l,focusPos:c,name:a,color:f,focusing:d,awarenessData:u}=r;let h=null,p=null;(null!==s&&(null===l||s.is(o))||null!==o)&&(e.$isRangeSelection(s)&&(L(t)?(h=j(s.anchor,t),p=j(s.focus,t)):(h=R(s.anchor,t),p=R(s.focus,t))),(X(l,h)||X(c,p))&&i.setLocalState({...r,anchorPos:h,awarenessData:u,color:f,focusPos:p,focusing:d,name:a}))}const ee=e=>"UNDEFINED"===e.nodeName,te=(n,o,i,r,l,c,a)=>{let f=o.mapping.get(n);if(f&&i&&0===i.size&&!r)return f;const d=ee(n)?e.RootNode.getType():n.nodeName,u=o.editor._nodes.get(d);if(void 0===u)throw new Error(`$createOrUpdateNodeFromYElement: Node ${d} is not registered`);if(f||(f=new u.klass,i=null,r=!0),r&&f instanceof e.ElementNode){const e=[],i=n=>{if(n instanceof t.XmlElement){const t=te(n,o,new Set,!1,l,c,a);null!==t&&e.push(t)}else if(n instanceof t.XmlText){const t=oe(n,o,l,c,a);null!==t&&t.forEach(t=>{null!==t&&e.push(t)})}else s(330)};n.toArray().forEach(i),ne(f,e)}const h=n.getAttributes(l),p={...g(f,o)},y={};for(const e in h)e.startsWith(ge)?y[_e(e)]=h[e]:p[e]=h[e];if(T(o,p,f,i),i){const t=Object.keys(y).filter(e=>i.has(ye(e)));if(t.length>0){const n=e.$getWritableNodeState(f);for(const e of t)n.updateFromUnknown(e,y[e])}}else e.$getWritableNodeState(f).updateFromJSON(y);const _=f.getLatest();return o.mapping.set(n,_),_},ne=(e,t)=>{const n=e.getChildren(),o=new Set(n.map(e=>e.getKey())),s=new Set(t.map(e=>e.getKey())),i=n.length-1,r=t.length-1;let l=0,c=0;for(;l<=i&&c<=r;){const i=n[l].getKey(),r=t[c].getKey();if(i===r){l++,c++;continue}const a=s.has(i),f=o.has(r);if(!a){if(0===c&&1===e.getChildrenSize())return void e.splice(c,1,t.slice(c));e.splice(c,1,[]),l++;continue}const d=t[c];f?(e.splice(c,1,[d]),l++,c++):(e.splice(c,0,[d]),c++)}const a=l>i,f=c>r;a&&!f?e.append(...t.slice(c)):f&&!a&&e.splice(t.length,e.getChildrenSize()-t.length,[])},oe=(t,n,o,s,i)=>{const r=he(t,o,s,i);let l=n.mapping.get(t)??[];const c=r.map(t=>t.attributes.t??e.TextNode.getType());if(!(l.length===c.length&&l.every((e,t)=>e.getType()===c[t]))){const t=n.editor._nodes;l=c.map(n=>{const o=t.get(n);if(void 0===o)throw new Error(`$createTextNodesFromYText: Node ${n} is not registered`);const s=new o.klass;if(!e.$isTextNode(s))throw new Error(`$createTextNodesFromYText: Node ${n} is not a TextNode`);return s})}for(let t=0;t<r.length;t++){const o=l[t],s=r[t],{attributes:i,insert:c}=s;o.__text!==c&&o.setTextContent(c);const a={...g(o,n),...i.p},f=Object.fromEntries(Object.entries(i).filter(([e])=>e.startsWith(ge)).map(([e,t])=>[_e(e),t]));T(n,a,o,null),e.$getWritableNodeState(o).updateFromJSON(f)}const a=l.map(e=>e.getLatest());return n.mapping.set(t,a),a},se=(n,o)=>n instanceof Array?((e,n)=>{const o=new t.XmlText;return ue(o,e,n),o})(n,o):((n,o)=>{const s=new t.XmlElement(n.getType()),i={...pe(n,o),...me(n)};for(const e in i){const t=i[e];null!==t&&s.setAttribute(e,t)}return n instanceof e.ElementNode?(s.insert(0,le(n).map(e=>se(e,o))),o.mapping.set(s,n),s):s})(n,o),ie=e=>"object"==typeof e&&null!=e,re=(e,t)=>{const n=Object.keys(e).filter(t=>null!==e[t]);if(null==t)return 0===n.length;let o=n.length===Object.keys(t).filter(e=>null!==t[e]).length;for(let s=0;s<n.length&&o;s++){const i=n[s],r=e[i],l=t[i];o="ychange"===i||r===l||ie(r)&&ie(l)&&re(r,l)}return o},le=t=>{if(!(t instanceof e.ElementNode))return[];const n=t.getChildren(),o=[];for(let t=0;t<n.length;t++){const s=n[t];if(e.$isTextNode(s)){const s=[];for(let o=n[t];t<n.length&&e.$isTextNode(o);o=n[++t])s.push(o);t--,o.push(s)}else o.push(s)}return o},ce=(t,n,o)=>{const s=he(t);return s.length===n.length&&s.every((t,s)=>{const i=n[s],r=t.attributes.t??e.TextNode.getType(),l=t.attributes.p??{},c=Object.fromEntries(Object.entries(t.attributes).filter(([e])=>e.startsWith(ge)));return t.insert===i.getTextContent()&&r===i.getType()&&re(l,pe(i,o))&&re(c,me(i))})},ae=(e,n,o)=>{if(e instanceof t.XmlElement&&!(n instanceof Array)&&Te(e,n)){const t=le(n);return e._length===t.length&&re(e.getAttributes(),{...pe(n,o),...me(n)})&&e.toArray().every((e,n)=>ae(e,t[n],o))}return e instanceof t.XmlText&&n instanceof Array&&ce(e,n,o)},fe=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),de=(e,n,o)=>{const s=e.toArray(),i=le(n),r=i.length,l=s.length,c=Math.min(l,r);let a=0,f=0,d=!1;for(;a<c;a++){const e=s[a],n=i[a];if(e instanceof t.XmlHook)break;if(fe(o.mapping.get(e),n))d=!0;else if(!ae(e,n,o))break}for(;a+f<c;f++){const e=s[l-f-1],n=i[r-f-1];if(e instanceof t.XmlHook)break;if(fe(o.mapping.get(e),n))d=!0;else if(!ae(e,n,o))break}return{equalityFactor:a+f,foundMappedChild:d}},ue=(n,o,s)=>{s.mapping.set(n,o);const{nAttrs:i,str:r}=(e=>{let n="",o=e._start;const s={};for(;null!==o;)o.deleted||(o.countable&&o.content instanceof t.ContentString?n+=o.content.str:o.content instanceof t.ContentFormat&&(s[o.content.key]=null)),o=o.right;return{nAttrs:s,str:n}})(n),c=o.map((t,n)=>{const o=t.getType();let r=pe(t,s);return 0===Object.keys(r).length&&(r=null),{attributes:Object.assign({},i,{...o!==e.TextNode.getType()&&{t:o},p:r,...me(t),...n>0&&{i:n}}),insert:t.getTextContent(),nodeKey:t.getKey()}}),a=c.map(e=>e.insert).join(""),f=e.$getSelection();let d;if(e.$isRangeSelection(f)&&f.isCollapsed()){d=0;for(const e of c){if(e.nodeKey===f.anchor.key){d+=f.anchor.offset;break}d+=e.insert.length}}else d=a.length;const{insert:u,remove:h,index:p}=l(r,a,d);n.delete(p,h),n.insert(p,u),n.applyDelta(c.map(e=>({attributes:e.attributes,retain:e.insert.length})))},he=(e,t,n,o)=>e.toDelta(t,n,o).map(e=>({...e,attributes:e.attributes??{}})),pe=(e,t)=>{const n=g(e,t),o={};return Object.entries(n).forEach(([t,n])=>{const s=e[t];s!==n&&(o[t]=s)}),o},ge="s_",ye=e=>ge+e,_e=e=>{if(!e.startsWith(ge))throw new Error(`Invalid state key: ${e}`);return e.slice(ge.length)},me=e=>{const t=e.__state;if(!t)return{};const[n={},o]=t.getInternalState(),s={};for(const[e,t]of Object.entries(n))s[ye(e)]=t;for(const[e,t]of o)s[ye(e.key)]=e.unparse(t);return s},xe=(n,o,s,i,r)=>{if(o instanceof t.XmlElement&&o.nodeName!==s.getType()&&(!ee(o)||s.getType()!==e.RootNode.getType()))throw new Error("node name mismatch!");if(i.mapping.set(o,s),o instanceof t.XmlElement){const e=o.getAttributes(),t={...pe(s,i),...me(s)};for(const n in t)null!=t[n]?e[n]!==t[n]&&"ychange"!==n&&o.setAttribute(n,t[n]):o.removeAttribute(n);for(const n in e)void 0===t[n]&&o.removeAttribute(n)}const l=le(s),c=l.length,a=o.toArray(),f=a.length,d=Math.min(c,f);let u=0,h=0;for(;u<d;u++){const o=a[u],s=l[u];if(o instanceof t.XmlHook)break;if(fe(i.mapping.get(o),s))s instanceof e.ElementNode&&r.has(s.getKey())&&xe(n,o,s,i,r);else{if(!ae(o,s,i))break;i.mapping.set(o,s)}}for(;h+u<d;h++){const o=a[f-h-1],s=l[c-h-1];if(o instanceof t.XmlHook)break;if(fe(i.mapping.get(o),s))s instanceof e.ElementNode&&r.has(s.getKey())&&xe(n,o,s,i,r);else{if(!ae(o,s,i))break;i.mapping.set(o,s)}}for(;f-u-h>0&&c-u-h>0;){const e=a[u],s=l[u],d=a[f-h-1],p=l[c-h-1];if(e instanceof t.XmlText&&s instanceof Array)ce(e,s,i)||ue(e,s,i),u+=1;else{let l=e instanceof t.XmlElement&&Te(e,s),c=d instanceof t.XmlElement&&Te(d,p);if(l&&c){const t=de(e,s,i),n=de(d,p,i);t.foundMappedChild&&!n.foundMappedChild?c=!1:!t.foundMappedChild&&n.foundMappedChild||t.equalityFactor<n.equalityFactor?l=!1:c=!1}l?(xe(n,e,s,i,r),u+=1):c?(xe(n,d,p,i,r),h+=1):(i.mapping.delete(o.get(u)),o.delete(u,1),o.insert(u,[se(s,i)]),u+=1)}}const p=f-u-h;if(1===f&&0===c&&a[0]instanceof t.XmlText?(i.mapping.delete(a[0]),a[0].delete(0,a[0].length)):p>0&&(o.slice(u,u+p).forEach(e=>i.mapping.delete(e)),o.delete(u,p)),u+h<c){const e=[];for(let t=u;t<c-h;t++)e.push(se(l[t],i));o.insert(u,e)}},Te=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType();function Ne(n,o){if(o instanceof t.YMapEvent&&function(n,o){const{target:s}=o;if(!s._item||"__state"!==s._item.parentSub||void 0!==_(s)||!(s.parent instanceof t.XmlText||s.parent instanceof t.XmlElement||s.parent instanceof t.Map))return!1;const i=m(n,s.parent).getNode();if(i){const t=e.$getWritableNodeState(i.getWritable());for(const e of o.keysChanged)t.updateFromUnknown(e,s.get(e))}return!0}(n,o))return;const{target:i}=o,r=m(n,i);if(r instanceof K&&o instanceof t.YTextEvent){const{keysChanged:e,childListChanged:t,delta:s}=o;e.size>0&&r.syncPropertiesFromYjs(n,e),t&&(r.applyChildrenYjsDelta(n,s),r.syncChildrenFromYjs(n))}else if(r instanceof c&&o instanceof t.YMapEvent){const{keysChanged:e}=o;e.size>0&&r.syncPropertiesAndTextFromYjs(n,e)}else if(r instanceof w&&o instanceof t.YXmlEvent){const{attributesChanged:e}=o;e.size>0&&r.syncPropertiesFromYjs(n,e)}else s(82)}function be(t,n,o){const s=e.$getSelection();if(e.$isRangeSelection(s))if(E(s)){const i=t._selection;if(e.$isRangeSelection(i)&&(G(n,o),E(s))){v(s.anchor.key,t)}Z(n,o,i,e.$getSelection())}else G(n,o)}function Se(){0===e.$getRoot().getChildrenSize()&&e.$getRoot().append(e.$createParagraphNode())}function ke(e,n){const{target:o}=n;if(o instanceof t.XmlElement&&n instanceof t.YXmlEvent)te(o,e,n.attributesChanged,n.childListChanged);else if(o instanceof t.XmlText&&n instanceof t.YTextEvent){const n=o.parent;n instanceof t.XmlElement?te(n,e,new Set,!0):s(323)}else s(324)}const Ce=e.createCommand("CONNECTED_COMMAND"),$e=e.createCommand("TOGGLE_CONNECT_COMMAND");exports.CONNECTED_COMMAND=Ce,exports.TOGGLE_CONNECT_COMMAND=$e,exports.createBinding=function(e,n,o,i,r,l){null==i&&s(81);const c=M(i.get("root",t.XmlText),null,"root");return c._key="root",{...F(e,o,i,r,l),collabNodeMap:new Map,root:c}},exports.createBindingV2__EXPERIMENTAL=function(e,n,o,i,r={}){null==o&&s(81);const{excludedProperties:l,rootName:c="root-v2"}=r;return{...F(e,n,o,i,l),mapping:new P,root:o.get(c,t.XmlElement)}},exports.createUndoManager=function(e,n){return new t.UndoManager(n,{trackedOrigins:new Set([e,null])})},exports.getAnchorAndFocusCollabNodesForUserState=function(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,i=0,r=null,l=0;if(null!==n&&null!==o){const t=I(n,e),c=I(o,e);null!==t&&null!==c&&([s,i]=q(t.type,t.index),[r,l]=q(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:i,focusCollabNode:r,focusOffset:l}},exports.initLocalState=function(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})},exports.setLocalStateFocus=function(e,t,n,o,s){const{awareness:i}=e;let r=i.getLocalState();null===r&&(r={anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t}),r.focusing=o,i.setLocalState(r)},exports.syncCursorPositions=Q,exports.syncLexicalUpdateToYjs=function(t,n,o,s,i,r,l,a){O(t,()=>{s.read(()=>{if(a.has(e.COLLABORATION_TAG)||a.has(e.HISTORIC_TAG))return void(l.size>0&&function(t,n){const o=Array.from(n),s=t.collabNodeMap,i=[],r=[];for(let t=0;t<o.length;t++){const n=o[t],l=e.$getNodeByKey(n),a=s.get(n);if(a instanceof c)if(e.$isTextNode(l))i.push([a,l.__text]);else{const e=a.getOffset();if(-1===e)continue;const t=a._parent;a._normalized=!0,t._xmlText.delete(e,1),r.push(a)}}for(let e=0;e<r.length;e++){const t=r[e],n=t.getKey();s.delete(n);const o=t._parent._children,i=o.indexOf(t);o.splice(i,1)}for(let e=0;e<i.length;e++){const[t,n]=i[e];t._text=n}}(t,l));if(i.has("root")){const n=o._nodeMap,s=e.$getRoot(),l=t.root;l.syncPropertiesFromLexical(t,s,n),l.syncChildrenFromLexical(t,s,n,i,r)}const s=e.$getSelection(),f=o._selection;Z(t,n,f,s)})})},exports.syncLexicalUpdateToYjsV2__EXPERIMENTAL=function(t,n,o,s,i,r,l){(l.has(e.COLLABORATION_TAG)||l.has(e.HISTORIC_TAG))&&0===r.size||(r.forEach(e=>{t.mapping.deleteNode(e)}),O(t,()=>{s.read(()=>{i.has("root")&&xe(t.doc,t.root,e.$getRoot(),t,new Set(i.keys()));const s=e.$getSelection(),r=o._selection;Z(t,n,r,s)})}))},exports.syncYjsChangesToLexical=function(t,n,o,s,i=Q){const r=t.editor,l=r._editorState;o.forEach(e=>e.delta),r.update(()=>{for(let e=0;e<o.length;e++){const n=o[e];Ne(t,n)}be(l,t,n),s||e.$addUpdateTag(e.SKIP_SCROLL_INTO_VIEW_TAG)},{onUpdate:()=>{i(t,n),r.update(()=>Se())},skipTransforms:!0,tag:s?e.HISTORIC_TAG:e.COLLABORATION_TAG})},exports.syncYjsChangesToLexicalV2__EXPERIMENTAL=function(n,o,s,i,r){const l=n.editor,c=l._editorState;t.iterateDeletedStructs(i,i.deleteSet,e=>{if(e.constructor===t.Item){const t=e.content.type;t&&n.mapping.delete(t)}}),s.forEach(e=>e.delta),l.update(()=>{for(let e=0;e<s.length;e++){const t=s[e];ke(n,t)}be(c,n,o),r||e.$addUpdateTag(e.SKIP_SCROLL_INTO_VIEW_TAG)},{discrete:!0,onUpdate:()=>{Q(n,o),l.update(()=>Se())},skipTransforms:!0,tag:r?e.HISTORIC_TAG:e.COLLABORATION_TAG})};
|
package/LexicalYjs.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{$getNodeByKey as e,$isLineBreakNode as t,$isTextNode as n,$getSelection as o,$isRangeSelection as s,createEditor as i,$isElementNode as r,$isDecoratorNode as l,$isRootNode as c,$getWritableNodeState as a,$getRoot as f,$getNodeByKeyOrThrow as u,removeFromParent as d,RootNode as h,ElementNode as p,TextNode as g,COLLABORATION_TAG as _,HISTORIC_TAG as y,$addUpdateTag as m,SKIP_SCROLL_INTO_VIEW_TAG as x,$createParagraphNode as T,createCommand as b}from"lexical";import{XmlText as k,Map as S,XmlElement as N,Doc as w,createAbsolutePositionFromRelativePosition as C,createRelativePositionFromTypeIndex as v,compareRelativePositions as O,XmlHook as K,ContentString as P,ContentFormat as M,iterateDeletedStructs as E,Item as F,YMapEvent as A,YTextEvent as j,YXmlEvent as z,UndoManager as L}from"yjs";import{$createChildrenArray as Y}from"@lexical/offset";import{createDOMRange as D,createRectsFromDOMRange as $}from"@lexical/selection";function I(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class W{_map;_key;_parent;_type;constructor(e,t){this._key="",this._map=e,this._parent=t,this._type="linebreak"}getNode(){const n=e(this._key);return t(n)?n:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function U(e,t){const n=new W(e,t);return e._collabNode=n,n}function R(e,t,n){const o=e.length,s=t.length;let i=0,r=0;for(;i<o&&i<s&&e[i]===t[i]&&i<n;)i++;for(;r+i<o&&r+i<s&&e[o-r-1]===t[s-r-1];)r++;for(;r+i<o&&r+i<s&&e[i]===t[i];)i++;return{index:i,insert:t.slice(i,s-r),remove:o-i-r}}class B{_map;_key;_parent;_text;_type;_normalized;constructor(e,t,n,o){this._key="",this._map=e,this._parent=n,this._text=t,this._type=o,this._normalized=!1}getPrevNode(e){if(null===e)return null;const t=e.get(this._key);return n(t)?t:null}getNode(){const t=e(this._key);return n(t)?t: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(e,t,n){const o=this._parent._xmlText,s=this.getOffset()+1+e;0!==t&&o.delete(s,t),""!==n&&o.insert(s,n)}syncPropertiesAndTextFromLexical(e,t,n){const i=this.getPrevNode(n),r=t.__text;if(le(e,this._map,i,t),null!==i){const e=i.__text;if(e!==r){!function(e,t,n,i){const r=o();let l=i.length;if(s(r)&&r.isCollapsed()){const e=r.anchor;e.key===t&&(l=e.offset)}const c=R(n,i,l);e.spliceText(c.index,c.remove,c.insert)}(this,t.__key,e,r),this._text=r}}}syncPropertiesAndTextFromYjs(e,t){const n=this.getNode();null===n&&I(84),oe(e,this._map,n,t);const o=this._text;n.__text!==o&&n.setTextContent(o)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function J(e,t,n,o){const s=new B(e,t,n,o);return e._collabNode=s,s}const q=new Set(["__key","__parent","__next","__prev","__state"]),G=new Set(["__first","__last","__size"]),H=new Set(["__cachedText"]),Q=new Set(["__text"]);function V(e,t,o){if(q.has(e)||"function"==typeof t[e])return!0;if(n(t)){if(Q.has(e))return!0}else if(r(t)&&(G.has(e)||c(t)&&H.has(e)))return!0;const s=t.constructor,i=o.excludedProperties.get(s);return null!=i&&i.has(e)}function X(e,t){const n=e.__type,{nodeProperties:o}=t,s=o.get(n);return void 0===s&&I(326,n),s}function Z(e,o,s){const i=o.__type;let c;if(r(o)){c=_e(new k,s,i),c.syncPropertiesFromLexical(e,o,null),c.syncChildrenFromLexical(e,o,null,null,null)}else if(n(o)){c=J(new S,o.__text,s,i),c.syncPropertiesAndTextFromLexical(e,o,null)}else if(t(o)){const e=new S;e.set("__type","linebreak"),c=U(e,s)}else if(l(o)){c=pe(new N,s,i),c.syncPropertiesFromLexical(e,o,null)}else I(86);return c._key=o.__key,c}function ee(e){const t=se(e,"__type");return"string"!=typeof t&&void 0!==t&&I(87),t}function te(e,t,n){const o=t._collabNode;if(void 0===o){const o=e.editor._nodes,s=ee(t);"string"!=typeof s&&I(87);void 0===o.get(s)&&I(88,s);const i=t.parent,r=void 0===n&&null!==i?te(e,i):n||null;if(r instanceof ge||I(89),t instanceof k)return _e(t,r,s);if(t instanceof S)return"linebreak"===s?U(t,r):J(t,"",r,s);if(t instanceof N)return pe(t,r,s)}return o}function ne(e,t,n){const o=t.getType(),s=e.editor._nodes.get(o);void 0===s&&I(88,o);const i=new s.klass;if(i.__parent=n,t._key=i.__key,t instanceof ge){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof B?t.syncPropertiesAndTextFromYjs(e,null):t instanceof he&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(i.__key,t),i}function oe(e,t,n,o){const s=null===o?t instanceof S?Array.from(t.keys()):t instanceof k||t instanceof N?Object.keys(t.getAttributes()):Object.keys(t):Array.from(o);let r;for(let o=0;o<s.length;o++){const l=s[o];if(V(l,n,e)){"__state"===l&&be(e)&&(r||(r=n.getWritable()),re(t,r));continue}const c=n[l];let a=se(t,l);if(c!==a){if(a instanceof w){const t=e.docMap;c instanceof w&&t.delete(c.guid);const n=i(),o=a.guid;n._key=o,t.set(o,a),a=n}void 0===r&&(r=n.getWritable()),r[l]=a}}}function se(e,t){return e instanceof S?e.get(t):e instanceof k||e instanceof N?e.getAttribute(t):e[t]}function ie(e,t,n){e instanceof S?e.set(t,n):e.setAttribute(t,n)}function re(e,t){const n=se(e,"__state");n instanceof S&&a(t).updateFromJSON(n.toJSON())}function le(e,t,n,o){const s=Object.keys(X(o,e)),i=e.editor.constructor;!function(e,t,n,o){const s=o.__state,i=se(t,"__state");if(!s)return;const[r,l]=s.getInternalState(),c=n&&n.__state,a=i instanceof S?i:new S;if(c===s)return;const[f,u]=c&&a.doc?c.getInternalState():[void 0,new Map];if(r)for(const[e,t]of Object.entries(r))f&&t!==f[e]&&a.set(e,t);for(const[e,t]of l)u.get(e)!==t&&a.set(e.key,e.unparse(t));i||ie(t,"__state",a)}(0,t,n,o);for(let r=0;r<s.length;r++){const l=s[r],c=null===n?void 0:n[l];let a=o[l];if(c!==a){if(a instanceof i){const t=e.docMap;let n;if(c instanceof i){const e=c._key;n=t.get(e),t.delete(e)}const s=n||new w,r=s.guid;a._key=r,t.set(r,s),a=s,e.editor.update(()=>{o.markDirty()})}ie(t,l,a)}}}function ce(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function ae(e,t,n){let o=0,s=0;const i=e._children,r=i.length;for(;s<r;s++){const e=i[s],l=o;o+=e.getSize();if((n?o>=t:o>t)&&e instanceof B){let n=t-l-1;n<0&&(n=0);return{length:o-t,node:e,nodeIndex:s,offset:n}}if(o>t)return{length:0,node:e,nodeIndex:s,offset:l};if(s===r-1)return{length:0,node:null,nodeIndex:s+1,offset:l+1}}return{length:0,node:null,nodeIndex:0,offset:0}}function fe(e){const t=e.anchor,o=e.focus;let s=!1;try{const e=t.getNode(),i=o.getNode();(!e.isAttached()||!i.isAttached()||n(e)&&t.offset>e.getTextContentSize()||n(i)&&o.offset>i.getTextContentSize())&&(s=!0)}catch(e){s=!0}return s}function ue(e,t){e.doc.transact(t,e)}function de(t,n){const o=n._nodeMap.get(t);if(!o)return void f().selectStart();const s=o.__prev;let i=null;s&&(i=e(s)),null===i&&null!==o.__parent&&(i=e(o.__parent)),null!==i?null!==i&&i.isAttached()?i.selectEnd():de(i.__key,n):f().selectStart()}class he{_xmlElem;_key;_parent;_type;constructor(e,t,n){this._key="",this._xmlElem=e,this._parent=t,this._type=n}getPrevNode(e){if(null===e)return null;const t=e.get(this._key);return l(t)?t:null}getNode(){const t=e(this._key);return l(t)?t:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}syncPropertiesFromLexical(e,t,n){const o=this.getPrevNode(n);le(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&I(83);oe(e,this._xmlElem,n,t)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function pe(e,t,n){const o=new he(e,t,n);return e._collabNode=o,o}class ge{_key;_children;_xmlText;_type;_parent;constructor(e,t,n){this._key="",this._children=[],this._xmlText=e,this._type=n,this._parent=t}getPrevNode(e){if(null===e)return null;const t=e.get(this._key);return r(t)?t:null}getNode(){const t=e(this._key);return r(t)?t:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){const e=this._parent;return null===e&&I(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&I(91),oe(e,this._xmlText,n,t)}applyChildrenYjsDelta(e,t){const n=this._children;let o=0,s=null;for(let i=0;i<t.length;i++){const r=t[i],l=r.insert,c=r.delete;if(null!=r.retain)o+=r.retain;else if("number"==typeof c){let e=c;for(;e>0;){const{node:t,nodeIndex:s,offset:i,length:r}=ae(this,o,!1);if(t instanceof ge||t instanceof W||t instanceof he)n.splice(s,1),e-=1;else{if(!(t instanceof B))break;{const o=Math.min(e,r),l=0!==s?n[s-1]:null,c=t.getSize();if(0===i&&r===c){n.splice(s,1);const e=ce(t._text,i,o-1,"");e.length>0&&(l instanceof B?l._text+=e:this._xmlText.delete(i,e.length))}else t._text=ce(t._text,i,o,"");e-=o}}}}else{if(null==l)throw new Error("Unexpected delta format");if("string"==typeof l){const{node:e,offset:t}=ae(this,o,!0);e instanceof B?e._text=ce(e._text,t,0,l):this._xmlText.delete(t,l.length),o+=l.length}else{const t=l,{node:i,nodeIndex:r,length:c}=ae(this,o,!1),a=te(e,t,this);if(i instanceof B&&c>0&&c<i._text.length){const e=i._text,t=e.length-c;i._text=ce(e,t,c,""),n.splice(r+1,0,a),s=ce(e,0,t,"")}else n.splice(r,0,a);null!==s&&a instanceof B&&(a._text=s+a._text,s=null),o+=1}}}}syncChildrenFromYjs(e){const t=this.getNode();null===t&&I(92);const o=t.__key,s=Y(t,null),i=s.length,r=this._children,l=r.length,c=e.collabNodeMap,a=new Set;let f,h,p=0,g=null;l!==i&&(h=t.getWritable());for(let i=0;i<l;i++){const _=s[p],y=r[i],m=y.getNode(),x=y._key;if(null!==m&&_===x){const t=n(m);if(a.add(_),t)if(y._key=_,y instanceof ge){const t=y._xmlText;y.syncPropertiesFromYjs(e,null),y.applyChildrenYjsDelta(e,t.toDelta()),y.syncChildrenFromYjs(e)}else y instanceof B?y.syncPropertiesAndTextFromYjs(e,null):y instanceof he?y.syncPropertiesFromYjs(e,null):y instanceof W||I(93);g=m,p++}else{if(void 0===f){f=new Set;for(let e=0;e<l;e++){const t=r[e]._key;""!==t&&f.add(t)}}if(null!==m&&void 0!==_&&!f.has(_)){const e=u(_);d(e),i--,p++;continue}h=t.getWritable();const n=ne(e,y,o),s=n.__key;if(c.set(s,y),null===g){const e=h.getFirstChild();if(h.__first=s,null!==e){const t=e.getWritable();t.__prev=s,n.__next=t.__key}}else{const e=g.getWritable(),t=g.getNextSibling();if(e.__next=s,n.__prev=g.__key,null!==t){const e=t.getWritable();e.__prev=s,n.__next=e.__key}}i===l-1&&(h.__last=s),h.__size++,g=n}}for(let t=0;t<i;t++){const n=s[t];if(!a.has(n)){const t=u(n),o=e.collabNodeMap.get(n);void 0!==o&&o.destroy(e),d(t)}}}syncPropertiesFromLexical(e,t,n){le(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(e,t,o,s,i,c){const a=this._children[t],f=u(o);a instanceof ge&&r(f)?(a.syncPropertiesFromLexical(e,f,s),a.syncChildrenFromLexical(e,f,s,i,c)):a instanceof B&&n(f)?a.syncPropertiesAndTextFromLexical(e,f,s):a instanceof he&&l(f)&&a.syncPropertiesFromLexical(e,f,s)}syncChildrenFromLexical(e,t,n,o,s){const i=this.getPrevNode(n),r=null===i?[]:Y(i,n),l=Y(t,null),c=r.length-1,a=l.length-1,f=e.collabNodeMap;let d,h,p=0,g=0;for(;p<=c&&g<=a;){const t=r[p],i=l[g];if(t===i)this._syncChildFromLexical(e,g,i,n,o,s),p++,g++;else{void 0===d&&(d=new Set(r)),void 0===h&&(h=new Set(l));const n=h.has(t),o=d.has(i);if(n){const t=Z(e,u(i),this);f.set(i,t),o?(this.splice(e,g,1,t),p++,g++):(this.splice(e,g,0,t),g++)}else this.splice(e,g,1),p++}}const _=p>c,y=g>a;if(_&&!y)for(;g<=a;++g){const t=l[g],n=Z(e,u(t),this);this.append(n),f.set(t,n)}else if(y&&!_)for(let t=this._children.length-1;t>=g;t--)this.splice(e,t,1)}append(e){const t=this._xmlText,n=this._children,o=n[n.length-1],s=void 0!==o?o.getOffset()+o.getSize():0;if(e instanceof ge)t.insertEmbed(s,e._xmlText);else if(e instanceof B){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof W?t.insertEmbed(s,e._map):e instanceof he&&t.insertEmbed(s,e._xmlElem);this._children.push(e)}splice(e,t,n,o){const s=this._children,i=s[t];if(void 0===i)return void 0===o&&I(94),void this.append(o);const r=i.getOffset();-1===r&&I(95);const l=this._xmlText;if(0!==n&&l.delete(r,i.getSize()),o instanceof ge)l.insertEmbed(r,o._xmlText);else if(o instanceof B){const e=o._map;null===e.parent&&l.insertEmbed(r,e),l.insert(r+1,o._text)}else o instanceof W?l.insertEmbed(r,o._map):o instanceof he&&l.insertEmbed(r,o._xmlElem);if(0!==n){const o=s.slice(t,t+n);for(let t=0;t<o.length;t++)o[t].destroy(e)}void 0!==o?s.splice(t,n,o):s.splice(t,n)}getChildOffset(e){let t=0;const n=this._children;for(let o=0;o<n.length;o++){const s=n[o];if(s===e)return t;t+=s.getSize()}return-1}destroy(e){const t=e.collabNodeMap,n=this._children;for(let t=0;t<n.length;t++)n[t].destroy(e);t.get(this._key)===this&&t.delete(this._key)}}function _e(e,t,n){const o=new ge(e,t,n);return e._collabNode=o,o}class ye{_nodeMap=new Map;_sharedTypeToNodeKeys=new Map;_nodeKeyToSharedType=new Map;set(e,t){const o=t instanceof Array;this.delete(e);const s=o?t:[t];for(const e of s){const t=e.getKey();if(this._nodeKeyToSharedType.has(t)){const e=this._nodeKeyToSharedType.get(t),n=this._sharedTypeToNodeKeys.get(e).indexOf(t);-1!==n&&this._sharedTypeToNodeKeys.get(e).splice(n,1),this._nodeKeyToSharedType.delete(t),this._nodeMap.delete(t)}}if(e instanceof k){if(o||I(328),0===t.length)return;this._sharedTypeToNodeKeys.set(e,t.map(e=>e.getKey()));for(const n of t)this._nodeMap.set(n.getKey(),n),this._nodeKeyToSharedType.set(n.getKey(),e)}else o&&I(329),n(t)&&I(330),this._sharedTypeToNodeKeys.set(e,[t.getKey()]),this._nodeMap.set(t.getKey(),t),this._nodeKeyToSharedType.set(t.getKey(),e)}get(e){const t=this._sharedTypeToNodeKeys.get(e);if(void 0!==t){if(e instanceof k){const e=Array.from(t.map(e=>this._nodeMap.get(e)));return e.length>0?e:void 0}return this._nodeMap.get(t[0])}}getSharedType(e){return this._nodeKeyToSharedType.get(e.getKey())}delete(e){const t=this._sharedTypeToNodeKeys.get(e);if(void 0!==t){for(const e of t)this._nodeMap.delete(e),this._nodeKeyToSharedType.delete(e);this._sharedTypeToNodeKeys.delete(e)}}deleteNode(e){const t=this._nodeKeyToSharedType.get(e);t&&this.delete(t),this._nodeMap.delete(e)}has(e){return this._sharedTypeToNodeKeys.has(e)}}function me(e,t,n,o,s){null==n&&I(81);const i={clientID:n.clientID,cursors:new Map,cursorsContainer:null,doc:n,docMap:o,editor:e,excludedProperties:s||new Map,id:t,nodeProperties:new Map};return function(e){const{editor:t,nodeProperties:n}=e;t.update(()=>{t._nodes.forEach(t=>{const o=new t.klass,s={};for(const[t,n]of Object.entries(o))V(t,o,e)||(s[t]=n);n.set(o.__type,Object.freeze(s))})})}(i),i}function xe(e,t,n,o,s,i){null==o&&I(81);const r=_e(o.get("root",k),null,"root");return r._key="root",{...me(e,n,o,s,i),collabNodeMap:new Map,root:r}}function Te(e,t,n,o,s={}){null==n&&I(81);const{excludedProperties:i,rootName:r="root-v2"}=s;return{...me(e,t,n,o,i),mapping:new ye,root:n.get(r,N)}}function be(e){return Object.hasOwn(e,"collabNodeMap")}function ke(e,t){const o=t.collabNodeMap.get(e.key);if(void 0===o)return null;let s=e.offset,i=o.getSharedType();if(o instanceof B){i=o._parent._xmlText;const e=o.getOffset();if(-1===e)return null;s=e+1+s}else if(o instanceof ge&&"element"===e.type){const t=e.getNode();r(t)||I(184);let o=0,i=0,l=t.getFirstChild();for(;null!==l&&i++<s;)n(l)?o+=l.getTextContentSize()+1:o++,l=l.getNextSibling();s=o}return v(i,s)}function Se(e,t){const{mapping:o}=t,{offset:s}=e,i=e.getNode(),l=o.getSharedType(i);if(void 0===l)return null;if("text"===e.type){n(i)||I(323);let e=i.getPreviousSibling(),t=s;for(;n(e);)t+=e.getTextContentSize(),e=e.getPreviousSibling();return v(l,t)}if("element"===e.type){r(i)||I(184);let e=0,t=i.getFirstChild();for(;null!==t&&e<s;){if(n(t)){let e=t.getNextSibling();for(;n(e);)e=e.getNextSibling()}e++,t=t.getNextSibling()}return v(l,e)}return null}function Ne(e,t){return C(e,t.doc)}function we(e,t){if(null==e){if(null!=t)return!0}else if(null==t||!O(e,t))return!0;return!1}function Ce(e,t){return{color:t,name:e,selection:null}}function ve(e,t){const n=e.cursorsContainer;if(null!==n){const e=t.selections,o=e.length;for(let t=0;t<o;t++)n.removeChild(e[t])}}function Oe(e,t){const n=t.selection;null!==n&&ve(e,n)}function Ke(e,t,n,o,s){const i=e.color,r=document.createElement("span");r.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${i};z-index:10;`;const l=document.createElement("span");return l.textContent=e.name,l.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${i};color:#fff;line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`,r.appendChild(l),{anchor:{key:t,offset:n},caret:r,color:i,focus:{key:o,offset:s},name:l,selections:[]}}function Pe(e,n,o,s){const i=e.editor,r=i.getRootElement(),l=e.cursorsContainer;if(null===l||null===r)return;const c=l.offsetParent;if(null===c)return;const a=c.getBoundingClientRect(),f=n.selection;if(null===o)return null===f?void 0:(n.selection=null,void ve(e,f));n.selection=o;const u=o.caret,d=o.color,h=o.selections,p=o.anchor,g=o.focus,_=p.key,y=g.key,m=s.get(_),x=s.get(y);if(null==m||null==x)return;let T;if(m===x&&t(m)){T=[i.getElementByKey(_).getBoundingClientRect()]}else{const e=D(i,m,p.offset,x,g.offset);if(null===e)return;T=$(i,e)}const b=h.length,k=T.length;for(let e=0;e<k;e++){const t=T[e];let n=h[e];if(void 0===n){n=document.createElement("span"),h[e]=n;const t=document.createElement("span");n.appendChild(t),l.appendChild(n)}const o=`position:absolute;top:${t.top-a.top}px;left:${t.left-a.left}px;height:${t.height}px;width:${t.width}px;pointer-events:none;z-index:5;`;n.style.cssText=o,n.firstChild.style.cssText=`${o}left:0;top:0;background-color:${d};opacity:0.3;`,e===k-1&&u.parentNode!==n&&n.appendChild(u)}for(let e=b-1;e>=k;e--){const t=h[e];l.removeChild(t),h.pop()}}function Me(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,i=0,r=null,l=0;if(null!==n&&null!==o){const t=Ne(n,e),c=Ne(o,e);null!==t&&null!==c&&([s,i]=je(t.type,t.index),[r,l]=je(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:i,focusCollabNode:r,focusOffset:l}}function Ee(e,t){const{anchorPos:o,focusPos:s}=t,i=o?Ne(o,e):null,r=s?Ne(s,e):null;if(null===i||null===r)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(be(e)){const[e,t]=je(i.type,i.index),[n,o]=je(r.type,r.index);return{anchorKey:null!==e?e.getKey():null,anchorOffset:t,focusKey:null!==n?n.getKey():null,focusOffset:o}}let[l,c]=ze(e.mapping,i),[a,f]=ze(e.mapping,r);if(a&&l&&(a!==l||f!==c)){const e=a.isBefore(l),t=e?a:l,o=e?f:c;n(t)&&n(t.getNextSibling())&&o===t.getTextContentSize()&&(e?(a=t.getNextSibling(),f=0):(l=t.getNextSibling(),c=0))}return{anchorKey:null!==l?l.getKey():null,anchorOffset:c,focusKey:null!==a?a.getKey():null,focusOffset:f}}function Fe(e,t){const n=t.awareness.getLocalState();if(null===n)return;const{anchorKey:i,anchorOffset:r,focusKey:l,focusOffset:c}=Ee(e,n);if(null!==i&&null!==l){const e=o();if(!s(e))return;Ae(e.anchor,i,r),Ae(e.focus,l,c)}}function Ae(t,o,s){if(t.key!==o||t.offset!==s){let i=e(o);if(null!==i&&!r(i)&&!n(i)){const e=i.getParentOrThrow();o=e.getKey(),s=i.getIndexWithinParent(),i=e}t.set(o,s,r(i)?"element":"text")}}function je(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof ge){const{node:e,offset:o}=ae(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function ze(e,t){const o=t.type,s=t.index;if(o instanceof N){const t=e.get(o);if(void 0===t)return[null,0];if(!r(t))return[t,s];let i=s,l=0;const c=t.getChildren();for(;i>0&&l<c.length;){const e=c[l];if(i-=1,l+=1,n(e))for(;l<c.length&&n(c[l]);)l+=1}return[t,l]}{const t=e.get(o);if(void 0===t)return[null,0];let n=0,i=s;for(;i>t[n].getTextContentSize()&&n+1<t.length;)i-=t[n].getTextContentSize(),n++;const r=t[n];return[r,Math.min(i,r.getTextContentSize())]}}function Le(e,t){return t.awareness.getStates()}function Ye(e,t,n){const{getAwarenessStates:o=Le}=n??{},s=Array.from(o(e,t)),i=e.clientID,r=e.cursors,l=e.editor,c=l._editorState._nodeMap,a=new Set;for(let t=0;t<s.length;t++){const n=s[t],[o,f]=n;if(o!==i){a.add(o);const{name:t,color:n,focusing:s}=f;let i=null,u=r.get(o);if(void 0===u&&(u=Ce(t,n),r.set(o,u)),s){const{anchorKey:t,anchorOffset:n,focusKey:o,focusOffset:s}=l.read(()=>Ee(e,f));if(null!==t&&null!==o)if(i=u.selection,null===i)i=Ke(u,t,n,o,s);else{const e=i.anchor,r=i.focus;e.key=t,e.offset=n,r.key=o,r.offset=s}}Pe(e,u,i,c)}}const f=Array.from(r.keys());for(let t=0;t<f.length;t++){const n=f[t];if(!a.has(n)){const t=r.get(n);void 0!==t&&(Oe(e,t),r.delete(n))}}}function De(e,t,n,o){const i=t.awareness,r=i.getLocalState();if(null===r)return;const{anchorPos:l,focusPos:c,name:a,color:f,focusing:u,awarenessData:d}=r;let h=null,p=null;(null!==o&&(null===l||o.is(n))||null!==n)&&(s(o)&&(be(e)?(h=ke(o.anchor,e),p=ke(o.focus,e)):(h=Se(o.anchor,e),p=Se(o.focus,e))),(we(l,h)||we(c,p))&&i.setLocalState({...r,anchorPos:h,awarenessData:d,color:f,focusPos:p,focusing:u,name:a}))}const $e=e=>"UNDEFINED"===e.nodeName,Ie=(e,t,n,o,s,i,r)=>{let l=t.mapping.get(e);if(l&&n&&0===n.size&&!o)return l;const c=$e(e)?h.getType():e.nodeName,f=t.editor._nodes.get(c);if(void 0===f)throw new Error(`$createOrUpdateNodeFromYElement: Node ${c} is not registered`);if(l||(l=new f.klass,n=null,o=!0),o&&l instanceof p){const n=[],o=e=>{if(e instanceof N){const o=Ie(e,t,new Set,!1,s,i,r);null!==o&&n.push(o)}else if(e instanceof k){const o=Ue(e,t,s,i,r);null!==o&&o.forEach(e=>{null!==e&&n.push(e)})}else I(327)};e.toArray().forEach(o),We(l,n)}const u=e.getAttributes(s),d={...X(l,t)},g={};for(const e in u)e.startsWith(tt)?g[ot(e)]=u[e]:d[e]=u[e];if(oe(t,d,l,n),n){const e=Object.keys(g).filter(e=>n.has(nt(e)));if(e.length>0){const t=a(l);for(const n of e)t.updateFromUnknown(n,g[n])}}else a(l).updateFromJSON(g);const _=l.getLatest();return t.mapping.set(e,_),_},We=(e,t)=>{const n=e.getChildren(),o=new Set(n.map(e=>e.getKey())),s=new Set(t.map(e=>e.getKey())),i=n.length-1,r=t.length-1;let l=0,c=0;for(;l<=i&&c<=r;){const i=n[l].getKey(),r=t[c].getKey();if(i===r){l++,c++;continue}const a=s.has(i),f=o.has(r);if(!a){if(0===c&&1===e.getChildrenSize())return void e.splice(c,1,t.slice(c));e.splice(c,1,[]),l++;continue}const u=t[c];f?(e.splice(c,1,[u]),l++,c++):(e.splice(c,0,[u]),c++)}const a=l>i,f=c>r;a&&!f?e.append(...t.slice(c)):f&&!a&&e.splice(t.length,e.getChildrenSize()-t.length,[])},Ue=(e,t,o,s,i)=>{const r=Ze(e,o,s,i);let l=t.mapping.get(e)??[];const c=r.map(e=>e.attributes.t??g.getType());if(!(l.length===c.length&&l.every((e,t)=>e.getType()===c[t]))){const e=t.editor._nodes;l=c.map(t=>{const o=e.get(t);if(void 0===o)throw new Error(`$createTextNodesFromYText: Node ${t} is not registered`);const s=new o.klass;if(!n(s))throw new Error(`$createTextNodesFromYText: Node ${t} is not a TextNode`);return s})}for(let e=0;e<r.length;e++){const n=l[e],o=r[e],{attributes:s,insert:i}=o;n.__text!==i&&n.setTextContent(i);const c={...X(n,t),...s.p},f=Object.fromEntries(Object.entries(s).filter(([e])=>e.startsWith(tt)).map(([e,t])=>[ot(e),t]));oe(t,c,n,null),a(n).updateFromJSON(f)}const f=l.map(e=>e.getLatest());return t.mapping.set(e,f),f},Re=(e,t)=>e instanceof Array?((e,t)=>{const n=new k;return Xe(n,e,t),n})(e,t):((e,t)=>{const n=new N(e.getType()),o={...et(e,t),...st(e)};for(const e in o){const t=o[e];null!==t&&n.setAttribute(e,t)}return e instanceof p?(n.insert(0,qe(e).map(e=>Re(e,t))),t.mapping.set(n,e),n):n})(e,t),Be=e=>"object"==typeof e&&null!=e,Je=(e,t)=>{const n=Object.keys(e).filter(t=>null!==e[t]);if(null==t)return 0===n.length;let o=n.length===Object.keys(t).filter(e=>null!==t[e]).length;for(let s=0;s<n.length&&o;s++){const i=n[s],r=e[i],l=t[i];o="ychange"===i||r===l||Be(r)&&Be(l)&&Je(r,l)}return o},qe=e=>{if(!(e instanceof p))return[];const t=e.getChildren(),o=[];for(let e=0;e<t.length;e++){const s=t[e];if(n(s)){const s=[];for(let o=t[e];e<t.length&&n(o);o=t[++e])s.push(o);e--,o.push(s)}else o.push(s)}return o},Ge=(e,t,n)=>{const o=Ze(e);return o.length===t.length&&o.every((e,o)=>{const s=t[o],i=e.attributes.t??g.getType(),r=e.attributes.p??{},l=Object.fromEntries(Object.entries(e.attributes).filter(([e])=>e.startsWith(tt)));return e.insert===s.getTextContent()&&i===s.getType()&&Je(r,et(s,n))&&Je(l,st(s))})},He=(e,t,n)=>{if(e instanceof N&&!(t instanceof Array)&&rt(e,t)){const o=qe(t);return e._length===o.length&&Je(e.getAttributes(),{...et(t,n),...st(t)})&&e.toArray().every((e,t)=>He(e,o[t],n))}return e instanceof k&&t instanceof Array&&Ge(e,t,n)},Qe=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),Ve=(e,t,n)=>{const o=e.toArray(),s=qe(t),i=s.length,r=o.length,l=Math.min(r,i);let c=0,a=0,f=!1;for(;c<l;c++){const e=o[c],t=s[c];if(e instanceof K)break;if(Qe(n.mapping.get(e),t))f=!0;else if(!He(e,t,n))break}for(;c+a<l;a++){const e=o[r-a-1],t=s[i-a-1];if(e instanceof K)break;if(Qe(n.mapping.get(e),t))f=!0;else if(!He(e,t,n))break}return{equalityFactor:c+a,foundMappedChild:f}},Xe=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:i,str:r}=(e=>{let t="",n=e._start;const o={};for(;null!==n;)n.deleted||(n.countable&&n.content instanceof P?t+=n.content.str:n.content instanceof M&&(o[n.content.key]=null)),n=n.right;return{nAttrs:o,str:t}})(e),l=t.map((e,t)=>{const o=e.getType();let s=et(e,n);return 0===Object.keys(s).length&&(s=null),{attributes:Object.assign({},i,{...o!==g.getType()&&{t:o},p:s,...st(e),...t>0&&{i:t}}),insert:e.getTextContent(),nodeKey:e.getKey()}}),c=l.map(e=>e.insert).join(""),a=o();let f;if(s(a)&&a.isCollapsed()){f=0;for(const e of l){if(e.nodeKey===a.anchor.key){f+=a.anchor.offset;break}f+=e.insert.length}}else f=c.length;const{insert:u,remove:d,index:h}=R(r,c,f);e.delete(h,d),e.insert(h,u),e.applyDelta(l.map(e=>({attributes:e.attributes,retain:e.insert.length})))},Ze=(e,t,n,o)=>e.toDelta(t,n,o).map(e=>({...e,attributes:e.attributes??{}})),et=(e,t)=>{const n=X(e,t),o={};return Object.entries(n).forEach(([t,n])=>{const s=e[t];s!==n&&(o[t]=s)}),o},tt="s_",nt=e=>tt+e,ot=e=>{if(!e.startsWith(tt))throw new Error(`Invalid state key: ${e}`);return e.slice(tt.length)},st=e=>{const t=e.__state;if(!t)return{};const[n={},o]=t.getInternalState(),s={};for(const[e,t]of Object.entries(n))s[nt(e)]=t;for(const[e,t]of o)s[nt(e.key)]=e.unparse(t);return s},it=(e,t,n,o,s)=>{if(t instanceof N&&t.nodeName!==n.getType()&&(!$e(t)||n.getType()!==h.getType()))throw new Error("node name mismatch!");if(o.mapping.set(t,n),t instanceof N){const e=t.getAttributes(),s={...et(n,o),...st(n)};for(const n in s)null!=s[n]?e[n]!==s[n]&&"ychange"!==n&&t.setAttribute(n,s[n]):t.removeAttribute(n);for(const n in e)void 0===s[n]&&t.removeAttribute(n)}const i=qe(n),r=i.length,l=t.toArray(),c=l.length,a=Math.min(r,c);let f=0,u=0;for(;f<a;f++){const t=l[f],n=i[f];if(t instanceof K)break;if(Qe(o.mapping.get(t),n))n instanceof p&&s.has(n.getKey())&&it(e,t,n,o,s);else{if(!He(t,n,o))break;o.mapping.set(t,n)}}for(;u+f<a;u++){const t=l[c-u-1],n=i[r-u-1];if(t instanceof K)break;if(Qe(o.mapping.get(t),n))n instanceof p&&s.has(n.getKey())&&it(e,t,n,o,s);else{if(!He(t,n,o))break;o.mapping.set(t,n)}}for(;c-f-u>0&&r-f-u>0;){const n=l[f],a=i[f],d=l[c-u-1],h=i[r-u-1];if(n instanceof k&&a instanceof Array)Ge(n,a,o)||Xe(n,a,o),f+=1;else{let i=n instanceof N&&rt(n,a),r=d instanceof N&&rt(d,h);if(i&&r){const e=Ve(n,a,o),t=Ve(d,h,o);e.foundMappedChild&&!t.foundMappedChild?r=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor<t.equalityFactor?i=!1:r=!1}i?(it(e,n,a,o,s),f+=1):r?(it(e,d,h,o,s),u+=1):(o.mapping.delete(t.get(f)),t.delete(f,1),t.insert(f,[Re(a,o)]),f+=1)}}const d=c-f-u;if(1===c&&0===r&&l[0]instanceof k?(o.mapping.delete(l[0]),l[0].delete(0,l[0].length)):d>0&&(t.slice(f,f+d).forEach(e=>o.mapping.delete(e)),t.delete(f,d)),f+u<r){const e=[];for(let t=f;t<r-u;t++)e.push(Re(i[t],o));t.insert(f,e)}},rt=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType();function lt(e,t){if(t instanceof A&&function(e,t){const{target:n}=t;if(!n._item||"__state"!==n._item.parentSub||void 0!==ee(n)||!(n.parent instanceof k||n.parent instanceof N||n.parent instanceof S))return!1;const o=te(e,n.parent).getNode();if(o){const e=a(o.getWritable());for(const o of t.keysChanged)e.updateFromUnknown(o,n.get(o))}return!0}(e,t))return;const{target:n}=t,o=te(e,n);if(o instanceof ge&&t instanceof j){const{keysChanged:n,childListChanged:s,delta:i}=t;n.size>0&&o.syncPropertiesFromYjs(e,n),s&&(o.applyChildrenYjsDelta(e,i),o.syncChildrenFromYjs(e))}else if(o instanceof B&&t instanceof A){const{keysChanged:n}=t;n.size>0&&o.syncPropertiesAndTextFromYjs(e,n)}else if(o instanceof he&&t instanceof z){const{attributesChanged:n}=t;n.size>0&&o.syncPropertiesFromYjs(e,n)}else I(82)}function ct(e,t,n,o,s=Ye){const i=e.editor,r=i._editorState;n.forEach(e=>e.delta),i.update(()=>{for(let t=0;t<n.length;t++){const o=n[t];lt(e,o)}at(r,e,t),o||m(x)},{onUpdate:()=>{s(e,t),i.update(()=>ft())},skipTransforms:!0,tag:o?y:_})}function at(e,t,n){const i=o();if(s(i))if(fe(i)){const r=e._selection;if(s(r)&&(Fe(t,n),fe(i))){de(i.anchor.key,e)}De(t,n,r,o())}else Fe(t,n)}function ft(){0===f().getChildrenSize()&&f().append(T())}function ut(t,s,i,r,l,c,a,u){ue(t,()=>{r.read(()=>{if(u.has(_)||u.has(y))return void(a.size>0&&function(t,o){const s=Array.from(o),i=t.collabNodeMap,r=[],l=[];for(let t=0;t<s.length;t++){const o=s[t],c=e(o),a=i.get(o);if(a instanceof B)if(n(c))r.push([a,c.__text]);else{const e=a.getOffset();if(-1===e)continue;const t=a._parent;a._normalized=!0,t._xmlText.delete(e,1),l.push(a)}}for(let e=0;e<l.length;e++){const t=l[e],n=t.getKey();i.delete(n);const o=t._parent._children,s=o.indexOf(t);o.splice(s,1)}for(let e=0;e<r.length;e++){const[t,n]=r[e];t._text=n}}(t,a));if(l.has("root")){const e=i._nodeMap,n=f(),o=t.root;o.syncPropertiesFromLexical(t,n,e),o.syncChildrenFromLexical(t,n,e,l,c)}const r=o(),d=i._selection;De(t,s,d,r)})})}function dt(e,t){const{target:n}=t;if(n instanceof N&&t instanceof z)Ie(n,e,t.attributesChanged,t.childListChanged);else if(n instanceof k&&t instanceof j){const t=n.parent;t instanceof N?Ie(t,e,new Set,!0):I(324)}else I(325)}function ht(e,t,n,o,s){const i=e.editor,r=i._editorState;E(o,o.deleteSet,t=>{if(t.constructor===F){const n=t.content.type;n&&e.mapping.delete(n)}}),n.forEach(e=>e.delta),i.update(()=>{for(let t=0;t<n.length;t++){const o=n[t];dt(e,o)}at(r,e,t),s||m(x)},{discrete:!0,onUpdate:()=>{Ye(e,t),i.update(()=>ft())},skipTransforms:!0,tag:s?y:_})}function pt(e,t,n,s,i,r,l){(l.has(_)||l.has(y))&&0===r.size||(r.forEach(t=>{e.mapping.deleteNode(t)}),ue(e,()=>{s.read(()=>{i.has("root")&&it(e.doc,e.root,f(),e,new Set(i.keys()));const s=o(),r=n._selection;De(e,t,r,s)})}))}const gt=b("CONNECTED_COMMAND"),_t=b("TOGGLE_CONNECT_COMMAND");function yt(e,t){return new L(t,{trackedOrigins:new Set([e,null])})}function mt(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})}function xt(e,t,n,o,s){const{awareness:i}=e;let r=i.getLocalState();null===r&&(r={anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t}),r.focusing=o,i.setLocalState(r)}export{gt as CONNECTED_COMMAND,_t as TOGGLE_CONNECT_COMMAND,xe as createBinding,Te as createBindingV2__EXPERIMENTAL,yt as createUndoManager,Me as getAnchorAndFocusCollabNodesForUserState,mt as initLocalState,xt as setLocalStateFocus,Ye as syncCursorPositions,ut as syncLexicalUpdateToYjs,pt as syncLexicalUpdateToYjsV2__EXPERIMENTAL,ct as syncYjsChangesToLexical,ht as syncYjsChangesToLexicalV2__EXPERIMENTAL};
|
|
9
|
+
import{$getNodeByKey as e,$isLineBreakNode as t,$isTextNode as n,$getSelection as o,$isRangeSelection as s,createEditor as i,$isElementNode as r,$isDecoratorNode as l,$isRootNode as c,$getWritableNodeState as a,$getRoot as f,$getNodeByKeyOrThrow as u,removeFromParent as d,RootNode as h,ElementNode as p,TextNode as g,COLLABORATION_TAG as _,HISTORIC_TAG as y,$addUpdateTag as m,SKIP_SCROLL_INTO_VIEW_TAG as x,$createParagraphNode as T,createCommand as b}from"lexical";import{XmlText as k,Map as S,XmlElement as N,Doc as w,createAbsolutePositionFromRelativePosition as C,createRelativePositionFromTypeIndex as v,compareRelativePositions as O,XmlHook as K,ContentString as P,ContentFormat as M,iterateDeletedStructs as E,Item as F,YMapEvent as A,YTextEvent as j,YXmlEvent as z,UndoManager as L}from"yjs";import{$createChildrenArray as Y}from"@lexical/offset";import{createDOMRange as D,createRectsFromDOMRange as $}from"@lexical/selection";function I(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class W{_map;_key;_parent;_type;constructor(e,t){this._key="",this._map=e,this._parent=t,this._type="linebreak"}getNode(){const n=e(this._key);return t(n)?n:null}getKey(){return this._key}getSharedType(){return this._map}getType(){return this._type}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function U(e,t){const n=new W(e,t);return e._collabNode=n,n}function R(e,t,n){const o=e.length,s=t.length;let i=0,r=0;for(;i<o&&i<s&&e[i]===t[i]&&i<n;)i++;for(;r+i<o&&r+i<s&&e[o-r-1]===t[s-r-1];)r++;for(;r+i<o&&r+i<s&&e[i]===t[i];)i++;return{index:i,insert:t.slice(i,s-r),remove:o-i-r}}class B{_map;_key;_parent;_text;_type;_normalized;constructor(e,t,n,o){this._key="",this._map=e,this._parent=n,this._text=t,this._type=o,this._normalized=!1}getPrevNode(e){if(null===e)return null;const t=e.get(this._key);return n(t)?t:null}getNode(){const t=e(this._key);return n(t)?t: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(e,t,n){const o=this._parent._xmlText,s=this.getOffset()+1+e;0!==t&&o.delete(s,t),""!==n&&o.insert(s,n)}syncPropertiesAndTextFromLexical(e,t,n){const i=this.getPrevNode(n),r=t.__text;if(le(e,this._map,i,t),null!==i){const e=i.__text;if(e!==r){!function(e,t,n,i){const r=o();let l=i.length;if(s(r)&&r.isCollapsed()){const e=r.anchor;e.key===t&&(l=e.offset)}const c=R(n,i,l);e.spliceText(c.index,c.remove,c.insert)}(this,t.__key,e,r),this._text=r}}}syncPropertiesAndTextFromYjs(e,t){const n=this.getNode();null===n&&I(84),oe(e,this._map,n,t);const o=this._text;n.__text!==o&&n.setTextContent(o)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function J(e,t,n,o){const s=new B(e,t,n,o);return e._collabNode=s,s}const q=new Set(["__key","__parent","__next","__prev","__state"]),G=new Set(["__first","__last","__size"]),H=new Set(["__cachedText"]),Q=new Set(["__text"]);function V(e,t,o){if(q.has(e)||"function"==typeof t[e])return!0;if(n(t)){if(Q.has(e))return!0}else if(r(t)&&(G.has(e)||c(t)&&H.has(e)))return!0;const s=t.constructor,i=o.excludedProperties.get(s);return null!=i&&i.has(e)}function X(e,t){const n=e.__type,{nodeProperties:o}=t,s=o.get(n);return void 0===s&&I(326,n),s}function Z(e,o,s){const i=o.__type;let c;if(r(o)){c=_e(new k,s,i),c.syncPropertiesFromLexical(e,o,null),c.syncChildrenFromLexical(e,o,null,null,null)}else if(n(o)){c=J(new S,o.__text,s,i),c.syncPropertiesAndTextFromLexical(e,o,null)}else if(t(o)){const e=new S;e.set("__type","linebreak"),c=U(e,s)}else if(l(o)){c=pe(new N,s,i),c.syncPropertiesFromLexical(e,o,null)}else I(86);return c._key=o.__key,c}function ee(e){const t=se(e,"__type");return"string"!=typeof t&&void 0!==t&&I(87),t}function te(e,t,n){const o=t._collabNode;if(void 0===o){const o=e.editor._nodes,s=ee(t);"string"!=typeof s&&I(87);void 0===o.get(s)&&I(88,s);const i=t.parent,r=void 0===n&&null!==i?te(e,i):n||null;if(r instanceof ge||I(89),t instanceof k)return _e(t,r,s);if(t instanceof S)return"linebreak"===s?U(t,r):J(t,"",r,s);if(t instanceof N)return pe(t,r,s)}return o}function ne(e,t,n){const o=t.getType(),s=e.editor._nodes.get(o);void 0===s&&I(88,o);const i=new s.klass;if(i.__parent=n,t._key=i.__key,t instanceof ge){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof B?t.syncPropertiesAndTextFromYjs(e,null):t instanceof he&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(i.__key,t),i}function oe(e,t,n,o){const s=null===o?t instanceof S?Array.from(t.keys()):t instanceof k||t instanceof N?Object.keys(t.getAttributes()):Object.keys(t):Array.from(o);let r;for(let o=0;o<s.length;o++){const l=s[o];if(V(l,n,e)){"__state"===l&&be(e)&&(r||(r=n.getWritable()),re(t,r));continue}const c=n[l];let a=se(t,l);if(c!==a){if(a instanceof w){const t=e.docMap;c instanceof w&&t.delete(c.guid);const n=i(),o=a.guid;n._key=o,t.set(o,a),a=n}void 0===r&&(r=n.getWritable()),r[l]=a}}}function se(e,t){return e instanceof S?e.get(t):e instanceof k||e instanceof N?e.getAttribute(t):e[t]}function ie(e,t,n){e instanceof S?e.set(t,n):e.setAttribute(t,n)}function re(e,t){const n=se(e,"__state");n instanceof S&&a(t).updateFromJSON(n.toJSON())}function le(e,t,n,o){const s=Object.keys(X(o,e)),i=e.editor.constructor;!function(e,t,n,o){const s=o.__state,i=se(t,"__state");if(!s)return;const[r,l]=s.getInternalState(),c=n&&n.__state,a=i instanceof S?i:new S;if(c===s)return;const[f,u]=c&&a.doc?c.getInternalState():[void 0,new Map];if(r)for(const[e,t]of Object.entries(r))f&&t!==f[e]&&a.set(e,t);for(const[e,t]of l)u.get(e)!==t&&a.set(e.key,e.unparse(t));i||ie(t,"__state",a)}(0,t,n,o);for(let r=0;r<s.length;r++){const l=s[r],c=null===n?void 0:n[l];let a=o[l];if(c!==a){if(a instanceof i){const t=e.docMap;let n;if(c instanceof i){const e=c._key;n=t.get(e),t.delete(e)}const s=n||new w,r=s.guid;a._key=r,t.set(r,s),a=s,e.editor.update(()=>{o.markDirty()})}ie(t,l,a)}}}function ce(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function ae(e,t,n){let o=0,s=0;const i=e._children,r=i.length;for(;s<r;s++){const e=i[s],l=o;o+=e.getSize();if((n?o>=t:o>t)&&e instanceof B){let n=t-l-1;n<0&&(n=0);return{length:o-t,node:e,nodeIndex:s,offset:n}}if(o>t)return{length:0,node:e,nodeIndex:s,offset:l};if(s===r-1)return{length:0,node:null,nodeIndex:s+1,offset:l+1}}return{length:0,node:null,nodeIndex:0,offset:0}}function fe(e){const t=e.anchor,o=e.focus;let s=!1;try{const e=t.getNode(),i=o.getNode();(!e.isAttached()||!i.isAttached()||n(e)&&t.offset>e.getTextContentSize()||n(i)&&o.offset>i.getTextContentSize())&&(s=!0)}catch(e){s=!0}return s}function ue(e,t){e.doc.transact(t,e)}function de(t,n){const o=n._nodeMap.get(t);if(!o)return void f().selectStart();const s=o.__prev;let i=null;s&&(i=e(s)),null===i&&null!==o.__parent&&(i=e(o.__parent)),null!==i?null!==i&&i.isAttached()?i.selectEnd():de(i.__key,n):f().selectStart()}class he{_xmlElem;_key;_parent;_type;constructor(e,t,n){this._key="",this._xmlElem=e,this._parent=t,this._type=n}getPrevNode(e){if(null===e)return null;const t=e.get(this._key);return l(t)?t:null}getNode(){const t=e(this._key);return l(t)?t:null}getSharedType(){return this._xmlElem}getType(){return this._type}getKey(){return this._key}getSize(){return 1}getOffset(){return this._parent.getChildOffset(this)}syncPropertiesFromLexical(e,t,n){const o=this.getPrevNode(n);le(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&I(83);oe(e,this._xmlElem,n,t)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function pe(e,t,n){const o=new he(e,t,n);return e._collabNode=o,o}class ge{_key;_children;_xmlText;_type;_parent;constructor(e,t,n){this._key="",this._children=[],this._xmlText=e,this._type=n,this._parent=t}getPrevNode(e){if(null===e)return null;const t=e.get(this._key);return r(t)?t:null}getNode(){const t=e(this._key);return r(t)?t:null}getSharedType(){return this._xmlText}getType(){return this._type}getKey(){return this._key}isEmpty(){return 0===this._children.length}getSize(){return 1}getOffset(){const e=this._parent;return null===e&&I(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&I(91),oe(e,this._xmlText,n,t)}applyChildrenYjsDelta(e,t){const n=this._children;let o=0,s=null;for(let i=0;i<t.length;i++){const r=t[i],l=r.insert,c=r.delete;if(null!=r.retain)o+=r.retain;else if("number"==typeof c){let e=c;for(;e>0;){const{node:t,nodeIndex:s,offset:i,length:r}=ae(this,o,!1);if(t instanceof ge||t instanceof W||t instanceof he)n.splice(s,1),e-=1;else{if(!(t instanceof B))break;{const o=Math.min(e,r),l=0!==s?n[s-1]:null,c=t.getSize();if(0===i&&r===c){n.splice(s,1);const e=ce(t._text,i,o-1,"");e.length>0&&(l instanceof B?l._text+=e:this._xmlText.delete(i,e.length))}else t._text=ce(t._text,i,o,"");e-=o}}}}else{if(null==l)throw new Error("Unexpected delta format");if("string"==typeof l){const{node:e,offset:t}=ae(this,o,!0);e instanceof B?e._text=ce(e._text,t,0,l):this._xmlText.delete(t,l.length),o+=l.length}else{const t=l,{node:i,nodeIndex:r,length:c}=ae(this,o,!1),a=te(e,t,this);if(i instanceof B&&c>0&&c<i._text.length){const e=i._text,t=e.length-c;i._text=ce(e,t,c,""),n.splice(r+1,0,a),s=ce(e,0,t,"")}else n.splice(r,0,a);null!==s&&a instanceof B&&(a._text=s+a._text,s=null),o+=1}}}}syncChildrenFromYjs(e){const t=this.getNode();null===t&&I(92);const o=t.__key,s=Y(t,null),i=s.length,r=this._children,l=r.length,c=e.collabNodeMap,a=new Set;let f,h,p=0,g=null;l!==i&&(h=t.getWritable());for(let i=0;i<l;i++){const _=s[p],y=r[i],m=y.getNode(),x=y._key;if(null!==m&&_===x){const t=n(m);if(a.add(_),t)if(y._key=_,y instanceof ge){const t=y._xmlText;y.syncPropertiesFromYjs(e,null),y.applyChildrenYjsDelta(e,t.toDelta()),y.syncChildrenFromYjs(e)}else y instanceof B?y.syncPropertiesAndTextFromYjs(e,null):y instanceof he?y.syncPropertiesFromYjs(e,null):y instanceof W||I(93);g=m,p++}else{if(void 0===f){f=new Set;for(let e=0;e<l;e++){const t=r[e]._key;""!==t&&f.add(t)}}if(null!==m&&void 0!==_&&!f.has(_)){const e=u(_);d(e),i--,p++;continue}h=t.getWritable();const n=ne(e,y,o),s=n.__key;if(c.set(s,y),null===g){const e=h.getFirstChild();if(h.__first=s,null!==e){const t=e.getWritable();t.__prev=s,n.__next=t.__key}}else{const e=g.getWritable(),t=g.getNextSibling();if(e.__next=s,n.__prev=g.__key,null!==t){const e=t.getWritable();e.__prev=s,n.__next=e.__key}}i===l-1&&(h.__last=s),h.__size++,g=n}}for(let t=0;t<i;t++){const n=s[t];if(!a.has(n)){const t=u(n),o=e.collabNodeMap.get(n);void 0!==o&&o.destroy(e),d(t)}}}syncPropertiesFromLexical(e,t,n){le(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(e,t,o,s,i,c){const a=this._children[t],f=u(o);a instanceof ge&&r(f)?(a.syncPropertiesFromLexical(e,f,s),a.syncChildrenFromLexical(e,f,s,i,c)):a instanceof B&&n(f)?a.syncPropertiesAndTextFromLexical(e,f,s):a instanceof he&&l(f)&&a.syncPropertiesFromLexical(e,f,s)}syncChildrenFromLexical(e,t,n,o,s){const i=this.getPrevNode(n),r=null===i?[]:Y(i,n),l=Y(t,null),c=r.length-1,a=l.length-1,f=e.collabNodeMap;let d,h,p=0,g=0;for(;p<=c&&g<=a;){const t=r[p],i=l[g];if(t===i)this._syncChildFromLexical(e,g,i,n,o,s),p++,g++;else{void 0===d&&(d=new Set(r)),void 0===h&&(h=new Set(l));const n=h.has(t),o=d.has(i);if(n){const t=Z(e,u(i),this);f.set(i,t),o?(this.splice(e,g,1,t),p++,g++):(this.splice(e,g,0,t),g++)}else this.splice(e,g,1),p++}}const _=p>c,y=g>a;if(_&&!y)for(;g<=a;++g){const t=l[g],n=Z(e,u(t),this);this.append(n),f.set(t,n)}else if(y&&!_)for(let t=this._children.length-1;t>=g;t--)this.splice(e,t,1)}append(e){const t=this._xmlText,n=this._children,o=n[n.length-1],s=void 0!==o?o.getOffset()+o.getSize():0;if(e instanceof ge)t.insertEmbed(s,e._xmlText);else if(e instanceof B){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof W?t.insertEmbed(s,e._map):e instanceof he&&t.insertEmbed(s,e._xmlElem);this._children.push(e)}splice(e,t,n,o){const s=this._children,i=s[t];if(void 0===i)return void 0===o&&I(94),void this.append(o);const r=i.getOffset();-1===r&&I(95);const l=this._xmlText;if(0!==n&&l.delete(r,i.getSize()),o instanceof ge)l.insertEmbed(r,o._xmlText);else if(o instanceof B){const e=o._map;null===e.parent&&l.insertEmbed(r,e),l.insert(r+1,o._text)}else o instanceof W?l.insertEmbed(r,o._map):o instanceof he&&l.insertEmbed(r,o._xmlElem);if(0!==n){const o=s.slice(t,t+n);for(let t=0;t<o.length;t++)o[t].destroy(e)}void 0!==o?s.splice(t,n,o):s.splice(t,n)}getChildOffset(e){let t=0;const n=this._children;for(let o=0;o<n.length;o++){const s=n[o];if(s===e)return t;t+=s.getSize()}return-1}destroy(e){const t=e.collabNodeMap,n=this._children;for(let t=0;t<n.length;t++)n[t].destroy(e);t.get(this._key)===this&&t.delete(this._key)}}function _e(e,t,n){const o=new ge(e,t,n);return e._collabNode=o,o}class ye{_nodeMap=new Map;_sharedTypeToNodeKeys=new Map;_nodeKeyToSharedType=new Map;set(e,t){const o=t instanceof Array;this.delete(e);const s=o?t:[t];for(const e of s){const t=e.getKey();if(this._nodeKeyToSharedType.has(t)){const e=this._nodeKeyToSharedType.get(t),n=this._sharedTypeToNodeKeys.get(e).indexOf(t);-1!==n&&this._sharedTypeToNodeKeys.get(e).splice(n,1),this._nodeKeyToSharedType.delete(t),this._nodeMap.delete(t)}}if(e instanceof k){if(o||I(327),0===t.length)return;this._sharedTypeToNodeKeys.set(e,t.map(e=>e.getKey()));for(const n of t)this._nodeMap.set(n.getKey(),n),this._nodeKeyToSharedType.set(n.getKey(),e)}else o&&I(328),n(t)&&I(329),this._sharedTypeToNodeKeys.set(e,[t.getKey()]),this._nodeMap.set(t.getKey(),t),this._nodeKeyToSharedType.set(t.getKey(),e)}get(e){const t=this._sharedTypeToNodeKeys.get(e);if(void 0!==t){if(e instanceof k){const e=Array.from(t.map(e=>this._nodeMap.get(e)));return e.length>0?e:void 0}return this._nodeMap.get(t[0])}}getSharedType(e){return this._nodeKeyToSharedType.get(e.getKey())}delete(e){const t=this._sharedTypeToNodeKeys.get(e);if(void 0!==t){for(const e of t)this._nodeMap.delete(e),this._nodeKeyToSharedType.delete(e);this._sharedTypeToNodeKeys.delete(e)}}deleteNode(e){const t=this._nodeKeyToSharedType.get(e);t&&this.delete(t),this._nodeMap.delete(e)}has(e){return this._sharedTypeToNodeKeys.has(e)}}function me(e,t,n,o,s){null==n&&I(81);const i={clientID:n.clientID,cursors:new Map,cursorsContainer:null,doc:n,docMap:o,editor:e,excludedProperties:s||new Map,id:t,nodeProperties:new Map};return function(e){const{editor:t,nodeProperties:n}=e;t.update(()=>{t._nodes.forEach(t=>{const o=new t.klass,s={};for(const[t,n]of Object.entries(o))V(t,o,e)||(s[t]=n);n.set(o.__type,Object.freeze(s))})})}(i),i}function xe(e,t,n,o,s,i){null==o&&I(81);const r=_e(o.get("root",k),null,"root");return r._key="root",{...me(e,n,o,s,i),collabNodeMap:new Map,root:r}}function Te(e,t,n,o,s={}){null==n&&I(81);const{excludedProperties:i,rootName:r="root-v2"}=s;return{...me(e,t,n,o,i),mapping:new ye,root:n.get(r,N)}}function be(e){return Object.hasOwn(e,"collabNodeMap")}function ke(e,t){const o=t.collabNodeMap.get(e.key);if(void 0===o)return null;let s=e.offset,i=o.getSharedType();if(o instanceof B){i=o._parent._xmlText;const e=o.getOffset();if(-1===e)return null;s=e+1+s}else if(o instanceof ge&&"element"===e.type){const t=e.getNode();r(t)||I(184);let o=0,i=0,l=t.getFirstChild();for(;null!==l&&i++<s;)n(l)?o+=l.getTextContentSize()+1:o++,l=l.getNextSibling();s=o}return v(i,s)}function Se(e,t){const{mapping:o}=t,{offset:s}=e,i=e.getNode(),l=o.getSharedType(i);if(void 0===l)return null;if("text"===e.type){n(i)||I(325);let e=i.getPreviousSibling(),t=s;for(;n(e);)t+=e.getTextContentSize(),e=e.getPreviousSibling();return v(l,t)}if("element"===e.type){r(i)||I(184);let e=0,t=i.getFirstChild();for(;null!==t&&e<s;){if(n(t)){let e=t.getNextSibling();for(;n(e);)e=e.getNextSibling()}e++,t=t.getNextSibling()}return v(l,e)}return null}function Ne(e,t){return C(e,t.doc)}function we(e,t){if(null==e){if(null!=t)return!0}else if(null==t||!O(e,t))return!0;return!1}function Ce(e,t){return{color:t,name:e,selection:null}}function ve(e,t){const n=e.cursorsContainer;if(null!==n){const e=t.selections,o=e.length;for(let t=0;t<o;t++)n.removeChild(e[t])}}function Oe(e,t){const n=t.selection;null!==n&&ve(e,n)}function Ke(e,t,n,o,s){const i=e.color,r=document.createElement("span");r.style.cssText=`position:absolute;top:0;bottom:0;right:-1px;width:1px;background-color:${i};z-index:10;`;const l=document.createElement("span");return l.textContent=e.name,l.style.cssText=`position:absolute;left:-2px;top:-16px;background-color:${i};color:#fff;line-height:12px;font-size:12px;padding:2px;font-family:Arial;font-weight:bold;white-space:nowrap;`,r.appendChild(l),{anchor:{key:t,offset:n},caret:r,color:i,focus:{key:o,offset:s},name:l,selections:[]}}function Pe(e,n,o,s){const i=e.editor,r=i.getRootElement(),l=e.cursorsContainer;if(null===l||null===r)return;const c=l.offsetParent;if(null===c)return;const a=c.getBoundingClientRect(),f=n.selection;if(null===o)return null===f?void 0:(n.selection=null,void ve(e,f));n.selection=o;const u=o.caret,d=o.color,h=o.selections,p=o.anchor,g=o.focus,_=p.key,y=g.key,m=s.get(_),x=s.get(y);if(null==m||null==x)return;let T;if(m===x&&t(m)){T=[i.getElementByKey(_).getBoundingClientRect()]}else{const e=D(i,m,p.offset,x,g.offset);if(null===e)return;T=$(i,e)}const b=h.length,k=T.length;for(let e=0;e<k;e++){const t=T[e];let n=h[e];if(void 0===n){n=document.createElement("span"),h[e]=n;const t=document.createElement("span");n.appendChild(t),l.appendChild(n)}const o=`position:absolute;top:${t.top-a.top}px;left:${t.left-a.left}px;height:${t.height}px;width:${t.width}px;pointer-events:none;z-index:5;`;n.style.cssText=o,n.firstChild.style.cssText=`${o}left:0;top:0;background-color:${d};opacity:0.3;`,e===k-1&&u.parentNode!==n&&n.appendChild(u)}for(let e=b-1;e>=k;e--){const t=h[e];l.removeChild(t),h.pop()}}function Me(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,i=0,r=null,l=0;if(null!==n&&null!==o){const t=Ne(n,e),c=Ne(o,e);null!==t&&null!==c&&([s,i]=je(t.type,t.index),[r,l]=je(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:i,focusCollabNode:r,focusOffset:l}}function Ee(e,t){const{anchorPos:o,focusPos:s}=t,i=o?Ne(o,e):null,r=s?Ne(s,e):null;if(null===i||null===r)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(be(e)){const[e,t]=je(i.type,i.index),[n,o]=je(r.type,r.index);return{anchorKey:null!==e?e.getKey():null,anchorOffset:t,focusKey:null!==n?n.getKey():null,focusOffset:o}}let[l,c]=ze(e.mapping,i),[a,f]=ze(e.mapping,r);if(a&&l&&(a!==l||f!==c)){const e=a.isBefore(l),t=e?a:l,o=e?f:c;n(t)&&n(t.getNextSibling())&&o===t.getTextContentSize()&&(e?(a=t.getNextSibling(),f=0):(l=t.getNextSibling(),c=0))}return{anchorKey:null!==l?l.getKey():null,anchorOffset:c,focusKey:null!==a?a.getKey():null,focusOffset:f}}function Fe(e,t){const n=t.awareness.getLocalState();if(null===n)return;const{anchorKey:i,anchorOffset:r,focusKey:l,focusOffset:c}=Ee(e,n);if(null!==i&&null!==l){const e=o();if(!s(e))return;Ae(e.anchor,i,r),Ae(e.focus,l,c)}}function Ae(t,o,s){if(t.key!==o||t.offset!==s){let i=e(o);if(null!==i&&!r(i)&&!n(i)){const e=i.getParentOrThrow();o=e.getKey(),s=i.getIndexWithinParent(),i=e}t.set(o,s,r(i)?"element":"text")}}function je(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof ge){const{node:e,offset:o}=ae(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function ze(e,t){const o=t.type,s=t.index;if(o instanceof N){const t=e.get(o);if(void 0===t)return[null,0];if(!r(t))return[t,s];let i=s,l=0;const c=t.getChildren();for(;i>0&&l<c.length;){const e=c[l];if(i-=1,l+=1,n(e))for(;l<c.length&&n(c[l]);)l+=1}return[t,l]}{const t=e.get(o);if(void 0===t)return[null,0];let n=0,i=s;for(;i>t[n].getTextContentSize()&&n+1<t.length;)i-=t[n].getTextContentSize(),n++;const r=t[n];return[r,Math.min(i,r.getTextContentSize())]}}function Le(e,t){return t.awareness.getStates()}function Ye(e,t,n){const{getAwarenessStates:o=Le}=n??{},s=Array.from(o(e,t)),i=e.clientID,r=e.cursors,l=e.editor,c=l._editorState._nodeMap,a=new Set;for(let t=0;t<s.length;t++){const n=s[t],[o,f]=n;if(o!==i){a.add(o);const{name:t,color:n,focusing:s}=f;let i=null,u=r.get(o);if(void 0===u&&(u=Ce(t,n),r.set(o,u)),s){const{anchorKey:t,anchorOffset:n,focusKey:o,focusOffset:s}=l.read(()=>Ee(e,f));if(null!==t&&null!==o)if(i=u.selection,null===i)i=Ke(u,t,n,o,s);else{const e=i.anchor,r=i.focus;e.key=t,e.offset=n,r.key=o,r.offset=s}}Pe(e,u,i,c)}}const f=Array.from(r.keys());for(let t=0;t<f.length;t++){const n=f[t];if(!a.has(n)){const t=r.get(n);void 0!==t&&(Oe(e,t),r.delete(n))}}}function De(e,t,n,o){const i=t.awareness,r=i.getLocalState();if(null===r)return;const{anchorPos:l,focusPos:c,name:a,color:f,focusing:u,awarenessData:d}=r;let h=null,p=null;(null!==o&&(null===l||o.is(n))||null!==n)&&(s(o)&&(be(e)?(h=ke(o.anchor,e),p=ke(o.focus,e)):(h=Se(o.anchor,e),p=Se(o.focus,e))),(we(l,h)||we(c,p))&&i.setLocalState({...r,anchorPos:h,awarenessData:d,color:f,focusPos:p,focusing:u,name:a}))}const $e=e=>"UNDEFINED"===e.nodeName,Ie=(e,t,n,o,s,i,r)=>{let l=t.mapping.get(e);if(l&&n&&0===n.size&&!o)return l;const c=$e(e)?h.getType():e.nodeName,f=t.editor._nodes.get(c);if(void 0===f)throw new Error(`$createOrUpdateNodeFromYElement: Node ${c} is not registered`);if(l||(l=new f.klass,n=null,o=!0),o&&l instanceof p){const n=[],o=e=>{if(e instanceof N){const o=Ie(e,t,new Set,!1,s,i,r);null!==o&&n.push(o)}else if(e instanceof k){const o=Ue(e,t,s,i,r);null!==o&&o.forEach(e=>{null!==e&&n.push(e)})}else I(330)};e.toArray().forEach(o),We(l,n)}const u=e.getAttributes(s),d={...X(l,t)},g={};for(const e in u)e.startsWith(tt)?g[ot(e)]=u[e]:d[e]=u[e];if(oe(t,d,l,n),n){const e=Object.keys(g).filter(e=>n.has(nt(e)));if(e.length>0){const t=a(l);for(const n of e)t.updateFromUnknown(n,g[n])}}else a(l).updateFromJSON(g);const _=l.getLatest();return t.mapping.set(e,_),_},We=(e,t)=>{const n=e.getChildren(),o=new Set(n.map(e=>e.getKey())),s=new Set(t.map(e=>e.getKey())),i=n.length-1,r=t.length-1;let l=0,c=0;for(;l<=i&&c<=r;){const i=n[l].getKey(),r=t[c].getKey();if(i===r){l++,c++;continue}const a=s.has(i),f=o.has(r);if(!a){if(0===c&&1===e.getChildrenSize())return void e.splice(c,1,t.slice(c));e.splice(c,1,[]),l++;continue}const u=t[c];f?(e.splice(c,1,[u]),l++,c++):(e.splice(c,0,[u]),c++)}const a=l>i,f=c>r;a&&!f?e.append(...t.slice(c)):f&&!a&&e.splice(t.length,e.getChildrenSize()-t.length,[])},Ue=(e,t,o,s,i)=>{const r=Ze(e,o,s,i);let l=t.mapping.get(e)??[];const c=r.map(e=>e.attributes.t??g.getType());if(!(l.length===c.length&&l.every((e,t)=>e.getType()===c[t]))){const e=t.editor._nodes;l=c.map(t=>{const o=e.get(t);if(void 0===o)throw new Error(`$createTextNodesFromYText: Node ${t} is not registered`);const s=new o.klass;if(!n(s))throw new Error(`$createTextNodesFromYText: Node ${t} is not a TextNode`);return s})}for(let e=0;e<r.length;e++){const n=l[e],o=r[e],{attributes:s,insert:i}=o;n.__text!==i&&n.setTextContent(i);const c={...X(n,t),...s.p},f=Object.fromEntries(Object.entries(s).filter(([e])=>e.startsWith(tt)).map(([e,t])=>[ot(e),t]));oe(t,c,n,null),a(n).updateFromJSON(f)}const f=l.map(e=>e.getLatest());return t.mapping.set(e,f),f},Re=(e,t)=>e instanceof Array?((e,t)=>{const n=new k;return Xe(n,e,t),n})(e,t):((e,t)=>{const n=new N(e.getType()),o={...et(e,t),...st(e)};for(const e in o){const t=o[e];null!==t&&n.setAttribute(e,t)}return e instanceof p?(n.insert(0,qe(e).map(e=>Re(e,t))),t.mapping.set(n,e),n):n})(e,t),Be=e=>"object"==typeof e&&null!=e,Je=(e,t)=>{const n=Object.keys(e).filter(t=>null!==e[t]);if(null==t)return 0===n.length;let o=n.length===Object.keys(t).filter(e=>null!==t[e]).length;for(let s=0;s<n.length&&o;s++){const i=n[s],r=e[i],l=t[i];o="ychange"===i||r===l||Be(r)&&Be(l)&&Je(r,l)}return o},qe=e=>{if(!(e instanceof p))return[];const t=e.getChildren(),o=[];for(let e=0;e<t.length;e++){const s=t[e];if(n(s)){const s=[];for(let o=t[e];e<t.length&&n(o);o=t[++e])s.push(o);e--,o.push(s)}else o.push(s)}return o},Ge=(e,t,n)=>{const o=Ze(e);return o.length===t.length&&o.every((e,o)=>{const s=t[o],i=e.attributes.t??g.getType(),r=e.attributes.p??{},l=Object.fromEntries(Object.entries(e.attributes).filter(([e])=>e.startsWith(tt)));return e.insert===s.getTextContent()&&i===s.getType()&&Je(r,et(s,n))&&Je(l,st(s))})},He=(e,t,n)=>{if(e instanceof N&&!(t instanceof Array)&&rt(e,t)){const o=qe(t);return e._length===o.length&&Je(e.getAttributes(),{...et(t,n),...st(t)})&&e.toArray().every((e,t)=>He(e,o[t],n))}return e instanceof k&&t instanceof Array&&Ge(e,t,n)},Qe=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),Ve=(e,t,n)=>{const o=e.toArray(),s=qe(t),i=s.length,r=o.length,l=Math.min(r,i);let c=0,a=0,f=!1;for(;c<l;c++){const e=o[c],t=s[c];if(e instanceof K)break;if(Qe(n.mapping.get(e),t))f=!0;else if(!He(e,t,n))break}for(;c+a<l;a++){const e=o[r-a-1],t=s[i-a-1];if(e instanceof K)break;if(Qe(n.mapping.get(e),t))f=!0;else if(!He(e,t,n))break}return{equalityFactor:c+a,foundMappedChild:f}},Xe=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:i,str:r}=(e=>{let t="",n=e._start;const o={};for(;null!==n;)n.deleted||(n.countable&&n.content instanceof P?t+=n.content.str:n.content instanceof M&&(o[n.content.key]=null)),n=n.right;return{nAttrs:o,str:t}})(e),l=t.map((e,t)=>{const o=e.getType();let s=et(e,n);return 0===Object.keys(s).length&&(s=null),{attributes:Object.assign({},i,{...o!==g.getType()&&{t:o},p:s,...st(e),...t>0&&{i:t}}),insert:e.getTextContent(),nodeKey:e.getKey()}}),c=l.map(e=>e.insert).join(""),a=o();let f;if(s(a)&&a.isCollapsed()){f=0;for(const e of l){if(e.nodeKey===a.anchor.key){f+=a.anchor.offset;break}f+=e.insert.length}}else f=c.length;const{insert:u,remove:d,index:h}=R(r,c,f);e.delete(h,d),e.insert(h,u),e.applyDelta(l.map(e=>({attributes:e.attributes,retain:e.insert.length})))},Ze=(e,t,n,o)=>e.toDelta(t,n,o).map(e=>({...e,attributes:e.attributes??{}})),et=(e,t)=>{const n=X(e,t),o={};return Object.entries(n).forEach(([t,n])=>{const s=e[t];s!==n&&(o[t]=s)}),o},tt="s_",nt=e=>tt+e,ot=e=>{if(!e.startsWith(tt))throw new Error(`Invalid state key: ${e}`);return e.slice(tt.length)},st=e=>{const t=e.__state;if(!t)return{};const[n={},o]=t.getInternalState(),s={};for(const[e,t]of Object.entries(n))s[nt(e)]=t;for(const[e,t]of o)s[nt(e.key)]=e.unparse(t);return s},it=(e,t,n,o,s)=>{if(t instanceof N&&t.nodeName!==n.getType()&&(!$e(t)||n.getType()!==h.getType()))throw new Error("node name mismatch!");if(o.mapping.set(t,n),t instanceof N){const e=t.getAttributes(),s={...et(n,o),...st(n)};for(const n in s)null!=s[n]?e[n]!==s[n]&&"ychange"!==n&&t.setAttribute(n,s[n]):t.removeAttribute(n);for(const n in e)void 0===s[n]&&t.removeAttribute(n)}const i=qe(n),r=i.length,l=t.toArray(),c=l.length,a=Math.min(r,c);let f=0,u=0;for(;f<a;f++){const t=l[f],n=i[f];if(t instanceof K)break;if(Qe(o.mapping.get(t),n))n instanceof p&&s.has(n.getKey())&&it(e,t,n,o,s);else{if(!He(t,n,o))break;o.mapping.set(t,n)}}for(;u+f<a;u++){const t=l[c-u-1],n=i[r-u-1];if(t instanceof K)break;if(Qe(o.mapping.get(t),n))n instanceof p&&s.has(n.getKey())&&it(e,t,n,o,s);else{if(!He(t,n,o))break;o.mapping.set(t,n)}}for(;c-f-u>0&&r-f-u>0;){const n=l[f],a=i[f],d=l[c-u-1],h=i[r-u-1];if(n instanceof k&&a instanceof Array)Ge(n,a,o)||Xe(n,a,o),f+=1;else{let i=n instanceof N&&rt(n,a),r=d instanceof N&&rt(d,h);if(i&&r){const e=Ve(n,a,o),t=Ve(d,h,o);e.foundMappedChild&&!t.foundMappedChild?r=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor<t.equalityFactor?i=!1:r=!1}i?(it(e,n,a,o,s),f+=1):r?(it(e,d,h,o,s),u+=1):(o.mapping.delete(t.get(f)),t.delete(f,1),t.insert(f,[Re(a,o)]),f+=1)}}const d=c-f-u;if(1===c&&0===r&&l[0]instanceof k?(o.mapping.delete(l[0]),l[0].delete(0,l[0].length)):d>0&&(t.slice(f,f+d).forEach(e=>o.mapping.delete(e)),t.delete(f,d)),f+u<r){const e=[];for(let t=f;t<r-u;t++)e.push(Re(i[t],o));t.insert(f,e)}},rt=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType();function lt(e,t){if(t instanceof A&&function(e,t){const{target:n}=t;if(!n._item||"__state"!==n._item.parentSub||void 0!==ee(n)||!(n.parent instanceof k||n.parent instanceof N||n.parent instanceof S))return!1;const o=te(e,n.parent).getNode();if(o){const e=a(o.getWritable());for(const o of t.keysChanged)e.updateFromUnknown(o,n.get(o))}return!0}(e,t))return;const{target:n}=t,o=te(e,n);if(o instanceof ge&&t instanceof j){const{keysChanged:n,childListChanged:s,delta:i}=t;n.size>0&&o.syncPropertiesFromYjs(e,n),s&&(o.applyChildrenYjsDelta(e,i),o.syncChildrenFromYjs(e))}else if(o instanceof B&&t instanceof A){const{keysChanged:n}=t;n.size>0&&o.syncPropertiesAndTextFromYjs(e,n)}else if(o instanceof he&&t instanceof z){const{attributesChanged:n}=t;n.size>0&&o.syncPropertiesFromYjs(e,n)}else I(82)}function ct(e,t,n,o,s=Ye){const i=e.editor,r=i._editorState;n.forEach(e=>e.delta),i.update(()=>{for(let t=0;t<n.length;t++){const o=n[t];lt(e,o)}at(r,e,t),o||m(x)},{onUpdate:()=>{s(e,t),i.update(()=>ft())},skipTransforms:!0,tag:o?y:_})}function at(e,t,n){const i=o();if(s(i))if(fe(i)){const r=e._selection;if(s(r)&&(Fe(t,n),fe(i))){de(i.anchor.key,e)}De(t,n,r,o())}else Fe(t,n)}function ft(){0===f().getChildrenSize()&&f().append(T())}function ut(t,s,i,r,l,c,a,u){ue(t,()=>{r.read(()=>{if(u.has(_)||u.has(y))return void(a.size>0&&function(t,o){const s=Array.from(o),i=t.collabNodeMap,r=[],l=[];for(let t=0;t<s.length;t++){const o=s[t],c=e(o),a=i.get(o);if(a instanceof B)if(n(c))r.push([a,c.__text]);else{const e=a.getOffset();if(-1===e)continue;const t=a._parent;a._normalized=!0,t._xmlText.delete(e,1),l.push(a)}}for(let e=0;e<l.length;e++){const t=l[e],n=t.getKey();i.delete(n);const o=t._parent._children,s=o.indexOf(t);o.splice(s,1)}for(let e=0;e<r.length;e++){const[t,n]=r[e];t._text=n}}(t,a));if(l.has("root")){const e=i._nodeMap,n=f(),o=t.root;o.syncPropertiesFromLexical(t,n,e),o.syncChildrenFromLexical(t,n,e,l,c)}const r=o(),d=i._selection;De(t,s,d,r)})})}function dt(e,t){const{target:n}=t;if(n instanceof N&&t instanceof z)Ie(n,e,t.attributesChanged,t.childListChanged);else if(n instanceof k&&t instanceof j){const t=n.parent;t instanceof N?Ie(t,e,new Set,!0):I(323)}else I(324)}function ht(e,t,n,o,s){const i=e.editor,r=i._editorState;E(o,o.deleteSet,t=>{if(t.constructor===F){const n=t.content.type;n&&e.mapping.delete(n)}}),n.forEach(e=>e.delta),i.update(()=>{for(let t=0;t<n.length;t++){const o=n[t];dt(e,o)}at(r,e,t),s||m(x)},{discrete:!0,onUpdate:()=>{Ye(e,t),i.update(()=>ft())},skipTransforms:!0,tag:s?y:_})}function pt(e,t,n,s,i,r,l){(l.has(_)||l.has(y))&&0===r.size||(r.forEach(t=>{e.mapping.deleteNode(t)}),ue(e,()=>{s.read(()=>{i.has("root")&&it(e.doc,e.root,f(),e,new Set(i.keys()));const s=o(),r=n._selection;De(e,t,r,s)})}))}const gt=b("CONNECTED_COMMAND"),_t=b("TOGGLE_CONNECT_COMMAND");function yt(e,t){return new L(t,{trackedOrigins:new Set([e,null])})}function mt(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})}function xt(e,t,n,o,s){const{awareness:i}=e;let r=i.getLocalState();null===r&&(r={anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t}),r.focusing=o,i.setLocalState(r)}export{gt as CONNECTED_COMMAND,_t as TOGGLE_CONNECT_COMMAND,xe as createBinding,Te as createBindingV2__EXPERIMENTAL,yt as createUndoManager,Me as getAnchorAndFocusCollabNodesForUserState,mt as initLocalState,xt as setLocalStateFocus,Ye as syncCursorPositions,ut as syncLexicalUpdateToYjs,pt as syncLexicalUpdateToYjsV2__EXPERIMENTAL,ct as syncYjsChangesToLexical,ht as syncYjsChangesToLexicalV2__EXPERIMENTAL};
|
package/package.json
CHANGED
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
"crdt"
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"version": "0.36.3-nightly.
|
|
14
|
+
"version": "0.36.3-nightly.20251006.0",
|
|
15
15
|
"main": "LexicalYjs.js",
|
|
16
16
|
"types": "index.d.ts",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@lexical/offset": "0.36.3-nightly.
|
|
19
|
-
"@lexical/selection": "0.36.3-nightly.
|
|
20
|
-
"lexical": "0.36.3-nightly.
|
|
18
|
+
"@lexical/offset": "0.36.3-nightly.20251006.0",
|
|
19
|
+
"@lexical/selection": "0.36.3-nightly.20251006.0",
|
|
20
|
+
"lexical": "0.36.3-nightly.20251006.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"yjs": ">=13.5.22"
|