@lexical/yjs 0.45.1-dev.0 → 0.45.1-nightly.20260531.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.
@@ -1309,8 +1309,11 @@ const $createOrUpdateNodeFromYElement = (el, binding, keysChanged, childListChan
1309
1309
  const state = {};
1310
1310
  for (const k in attrs) {
1311
1311
  if (k.startsWith(STATE_KEY_PREFIX)) {
1312
+ // State keys route through NodeState.updateFromJSON, which guards
1313
+ // against prototype-polluting keys.
1312
1314
  state[attrKeyToStateKey(k)] = attrs[k];
1313
- } else {
1315
+ } else if (k !== '__proto__' && k !== 'constructor' && k !== 'prototype') {
1316
+ // Skip prototype-polluting property keys from untrusted remote attrs.
1314
1317
  properties[k] = attrs[k];
1315
1318
  }
1316
1319
  }
@@ -1307,8 +1307,11 @@ const $createOrUpdateNodeFromYElement = (el, binding, keysChanged, childListChan
1307
1307
  const state = {};
1308
1308
  for (const k in attrs) {
1309
1309
  if (k.startsWith(STATE_KEY_PREFIX)) {
1310
+ // State keys route through NodeState.updateFromJSON, which guards
1311
+ // against prototype-polluting keys.
1310
1312
  state[attrKeyToStateKey(k)] = attrs[k];
1311
- } else {
1313
+ } else if (k !== '__proto__' && k !== 'constructor' && k !== 'prototype') {
1314
+ // Skip prototype-polluting property keys from untrusted remote attrs.
1312
1315
  properties[k] = attrs[k];
1313
1316
  }
1314
1317
  }
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("lexical"),t=require("yjs"),n=require("@lexical/selection");function o(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.`)}function s(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 i{_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);M(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&o(83);C(e,this._xmlElem,n,t)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function r(e,t,n){const o=new i(e,t,n);return e._collabNode=o,o}class l{_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 c(e,t){const n=new l(e,t);return e._collabNode=n,n}class a{_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 i=this.getPrevNode(o),r=n.__text;if(M(t,this._map,i,n),null!==i){const t=i.__text;if(t!==r){!function(t,n,o,i){const r=e.$getSelection();let l=i.length;if(e.$isRangeSelection(r)&&r.isCollapsed()){const e=r.anchor;e.key===n&&(l=e.offset)}const c=s(o,i,l);t.spliceText(c.index,c.remove,c.insert)}(this,n.__key,t,r),this._text=r}}}syncPropertiesAndTextFromYjs(e,t){const n=this.getNode();null===n&&o(84),C(e,this._map,n,t);const s=this._text;n.__text!==s&&n.setTextContent(s)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function d(e,t,n,o){const s=new a(e,t,n,o);return e._collabNode=s,s}class f{_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&&o(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&o(91),C(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 c=t[r],d=c.insert,u=c.delete;if(null!=c.retain)o+=c.retain;else if("number"==typeof u){let e=u;for(;e>0;){const{node:t,nodeIndex:s,offset:r,length:c}=w(this,o,!1);if(t instanceof f||t instanceof l||t instanceof i)n.splice(s,1),e-=1;else{if(!(t instanceof a))break;{const o=Math.min(e,c),i=0!==s?n[s-1]:null,l=t.getSize();if(0===r&&c===l){n.splice(s,1);const e=A(t._text,r,o-1,"");e.length>0&&(i instanceof a?i._text+=e:this._xmlText.delete(r,e.length))}else t._text=A(t._text,r,o,"");e-=o}}}}else{if(null==d)throw new Error("Unexpected delta format");if("string"==typeof d){const{node:e,offset:t}=w(this,o,!0);e instanceof a?e._text=A(e._text,t,0,d):this._xmlText.delete(t,d.length),o+=d.length}else{const t=d,{node:i,nodeIndex:r,length:l}=w(this,o,!1),c=E(e,t,this);if(i instanceof a&&l>0&&l<i._text.length){const e=i._text,t=e.length-l;i._text=A(e,t,l,""),n.splice(r+1,0,c),s=A(e,0,t,"")}else n.splice(r,0,c);null!==s&&c instanceof a&&(c._text=s+c._text,s=null),o+=1}}}}syncChildrenFromYjs(t){const n=this.getNode();null===n&&o(92);const s=n.__key,r=e.$createChildrenArray(n,null),c=r.length,d=this._children,u=d.length,h=t.collabNodeMap,p=new Set;let g,y,_=0,m=null;u!==c&&(y=n.getWritable());for(let c=0;c<u;c++){const x=r[_],T=d[c],N=T.getNode(),S=T._key;if(null!==N&&x===S){const n=e.$isTextNode(N);if(p.add(x),n)if(T._key=x,T instanceof f){const e=T._xmlText;T.syncPropertiesFromYjs(t,null),T.applyChildrenYjsDelta(t,e.toDelta()),T.syncChildrenFromYjs(t)}else T instanceof a?T.syncPropertiesAndTextFromYjs(t,null):T instanceof i?T.syncPropertiesFromYjs(t,null):T instanceof l||o(93);m=N,_++}else{if(void 0===g){g=new Set;for(let e=0;e<u;e++){const t=d[e]._key;""!==t&&g.add(t)}}if(null!==N&&void 0!==x&&!g.has(x)){const t=e.$getNodeByKeyOrThrow(x);e.removeFromParent(t),c--,_++;continue}y=n.getWritable();const o=O(t,T,s),i=o.__key;if(h.set(i,T),null===m){const e=y.getFirstChild();if(y.__first=i,null!==e){const t=e.getWritable();t.__prev=i,o.__next=t.__key}}else{const e=m.getWritable(),t=m.getNextSibling();if(e.__next=i,o.__prev=m.__key,null!==t){const e=t.getWritable();e.__prev=i,o.__next=e.__key}}c===u-1&&(y.__last=i),y.__size++,m=o}}for(let n=0;n<c;n++){const o=r[n];if(!p.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){M(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(t,n,o,s,r,l){const c=this._children[n],d=e.$getNodeByKeyOrThrow(o);c instanceof f&&e.$isElementNode(d)?(c.syncPropertiesFromLexical(t,d,s),c.syncChildrenFromLexical(t,d,s,r,l)):c instanceof a&&e.$isTextNode(d)?c.syncPropertiesAndTextFromLexical(t,d,s):c instanceof i&&e.$isDecoratorNode(d)&&c.syncPropertiesFromLexical(t,d,s)}syncChildrenFromLexical(t,n,o,s,i){const r=this.getPrevNode(o),l=null===r?[]:e.$createChildrenArray(r,o),c=e.$createChildrenArray(n,null),a=l.length-1,d=c.length-1,f=t.collabNodeMap;let u,h,p=0,g=0;for(;p<=a&&g<=d;){const n=l[p],r=c[g];if(n===r)this._syncChildFromLexical(t,g,r,o,s,i),p++,g++;else{void 0===u&&(u=new Set(l)),void 0===h&&(h=new Set(c));const o=h.has(n),s=u.has(r);if(o){const n=S(t,e.$getNodeByKeyOrThrow(r),this);f.set(r,n),s?(this.splice(t,g,1,n),p++,g++):(this.splice(t,g,0,n),g++)}else this.splice(t,g,1),p++}}const y=p>a,_=g>d;if(y&&!_)for(;g<=d;++g){const n=c[g],o=S(t,e.$getNodeByKeyOrThrow(n),this);this.append(o),f.set(n,o)}else if(_&&!y)for(let e=this._children.length-1;e>=g;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 f)t.insertEmbed(s,e._xmlText);else if(e instanceof a){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof l?t.insertEmbed(s,e._map):e instanceof i&&t.insertEmbed(s,e._xmlElem);this._children.push(e)}splice(e,t,n,s){const r=this._children,c=r[t];if(void 0===c)return void 0===s&&o(94),void this.append(s);const d=c.getOffset();-1===d&&o(95);const u=this._xmlText;if(0!==n&&u.delete(d,c.getSize()),s instanceof f)u.insertEmbed(d,s._xmlText);else if(s instanceof a){const e=s._map;null===e.parent&&u.insertEmbed(d,e),u.insert(d+1,s._text)}else s instanceof l?u.insertEmbed(d,s._map):s instanceof i&&u.insertEmbed(d,s._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!==s?r.splice(t,n,s):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 u(e,t,n){const o=new f(e,t,n);return e._collabNode=o,o}class h{_nodeMap=new Map;_sharedTypeToNodeKeys=new Map;_nodeKeyToSharedType=new Map;set(n,s){const i=s instanceof Array;this.delete(n);const r=i?s:[s];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||o(331),0===s.length)return;this._sharedTypeToNodeKeys.set(n,s.map(e=>e.getKey()));for(const e of s)this._nodeMap.set(e.getKey(),e),this._nodeKeyToSharedType.set(e.getKey(),n)}else i&&o(332),e.$isTextNode(s)&&o(333),this._sharedTypeToNodeKeys.set(n,[s.getKey()]),this._nodeMap.set(s.getKey(),s),this._nodeKeyToSharedType.set(s.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)}clear(){this._nodeMap.clear(),this._sharedTypeToNodeKeys.clear(),this._nodeKeyToSharedType.clear()}}function p(e,t,n,s,i){null==n&&o(81);const r={clientID:n.clientID,cursors:new Map,cursorsContainer:null,doc:n,docMap:s,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))T(t,o,e)||(s[t]=n);n.set(o.__type,Object.freeze(s))})})}(r),r}function g(e){return Object.prototype.hasOwnProperty.call(e,"collabNodeMap")}const y=new Set(["__key","__parent","__next","__prev","__state"]),_=new Set(["__first","__last","__size"]),m=new Set(["__cachedText"]),x=new Set(["__text"]);function T(t,n,o){if(y.has(t)||"function"==typeof n[t])return!0;if(e.$isTextNode(n)){if(x.has(t))return!0}else if(e.$isElementNode(n)&&(_.has(t)||e.$isRootNode(n)&&m.has(t)))return!0;const s=n.constructor,i=o.excludedProperties.get(s);return null!=i&&i.has(t)}function N(e,t){const n=e.__type,{nodeProperties:s}=t,i=s.get(n);return void 0===i&&o(330,n),i}function S(n,s,i){const l=s.__type;let a;if(e.$isElementNode(s)){a=u(new t.XmlText,i,l),a.syncPropertiesFromLexical(n,s,null),a.syncChildrenFromLexical(n,s,null,null,null)}else if(e.$isTextNode(s)){a=d(new t.Map,s.__text,i,l),a.syncPropertiesAndTextFromLexical(n,s,null)}else if(e.$isLineBreakNode(s)){const e=new t.Map;e.set("__type","linebreak"),a=c(e,i)}else if(e.$isDecoratorNode(s)){a=r(new t.XmlElement,i,l),a.syncPropertiesFromLexical(n,s,null)}else o(86);return a._key=s.__key,a}function b(e){const t=k(e,"__type");return"string"!=typeof t&&void 0!==t&&o(87),t}function E(e,n,s){const i=n._collabNode;if(void 0===i){const i=e.editor._nodes,l=b(n);"string"!=typeof l&&o(87);void 0===i.get(l)&&o(88,l);const a=n.parent,h=void 0===s&&null!==a?E(e,a):s||null;if(h instanceof f||o(89),n instanceof t.XmlText)return u(n,h,l);if(n instanceof t.Map)return"linebreak"===l?c(n,h):d(n,"",h,l);if(n instanceof t.XmlElement)return r(n,h,l)}return i}function O(e,t,n){const s=t.getType(),r=e.editor._nodes.get(s);void 0===r&&o(88,s);const l=new r.klass;if(l.__parent=n,t._key=l.__key,t instanceof f){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof a?t.syncPropertiesAndTextFromYjs(e,null):t instanceof i&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(l.__key,t),l}function C(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(T(c,s,n)){"__state"===c&&g(n)&&(l||(l=s.getWritable()),v(o,l));continue}const a=s[c];let d=k(o,c);if(a!==d){if(d instanceof t.Doc){const o=n.docMap;a instanceof t.Doc&&o.delete(a.guid);const s=d.guid;if(o.set(s,d),e.isLexicalEditor(a))a._key=s,d=a;else{const t=e.createEditor();t._key=s,d=t}}void 0===l&&(l=s.getWritable()),l[c]=d}}}function k(e,n){return e instanceof t.Map?e.get(n):e instanceof t.XmlText||e instanceof t.XmlElement?e.getAttribute(n):e[n]}function $(e,n,o){e instanceof t.Map?e.set(n,o):e.setAttribute(n,o)}function v(n,o){const s=k(n,"__state");s instanceof t.Map&&e.$getWritableNodeState(o).updateFromJSON(s.toJSON())}function M(e,n,o,s){const i=Object.keys(N(s,e)),r=e.editor.constructor;!function(e,n,o,s){const i=s.__state,r=null===n.doc?void 0:k(n,"__state");if(!i)return;const[l,c]=i.getInternalState(),a=o&&o.__state,d=r instanceof t.Map?r:new t.Map;if(a===i)return;const[f,u]=a&&d.doc?a.getInternalState():[void 0,new Map];if(l)for(const[e,t]of Object.entries(l))f&&t!==f[e]&&d.set(e,t);for(const[e,t]of c)u.get(e)!==t&&d.set(e.key,e.unparse(t));r||$(n,"__state",d)}(0,n,o,s);for(let l=0;l<i.length;l++){const c=i[l],a=null===o?void 0:o[c];let d=s[c];if(a!==d){if(d 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;d._key=l,n.set(l,i),d=i,e.editor.update(()=>{s.markDirty()})}$(n,c,d)}}}function A(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function w(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 a){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 P(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 K(e,t){e.doc.transact(t,e)}function L(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():L(i.__key,n):e.$getRoot().selectStart()}const F=e=>"UNDEFINED"===e.nodeName,I=(n,s,i,r,l,c,a)=>{let d=s.mapping.get(n);if(d&&i&&0===i.size&&!r)return d;const f=F(n)?e.RootNode.getType():n.nodeName,u=s.editor._nodes.get(f);if(void 0===u)throw new Error(`$createOrUpdateNodeFromYElement: Node ${f} is not registered`);if(d||(d=new u.klass,i=null,r=!0),r&&d instanceof e.ElementNode){const e=[],i=n=>{if(n instanceof t.XmlElement){const t=I(n,s,new Set,!1,l,c,a);null!==t&&e.push(t)}else if(n instanceof t.XmlText){const t=j(n,s,l,c,a);null!==t&&t.forEach(t=>{null!==t&&e.push(t)})}else o(329)};void 0===l||void 0===c?n.toArray().forEach(i):t.typeListToArraySnapshot(n,new t.Snapshot(c.ds,l.sv)).filter(e=>!e._item.deleted||D(e._item,l)||D(e._item,c)).forEach(i),R(d,e)}const h=n.getAttributes(l);F(n)||void 0===l||(D(n._item,l)?D(n._item,c)||(h[Z("ychange")]=a?a("added",n._item.id):{type:"added"}):h[Z("ychange")]=a?a("removed",n._item.id):{type:"removed"});const p={...N(d,s)},g={};for(const e in h)e.startsWith(Q)?g[ee(e)]=h[e]:p[e]=h[e];if(C(s,p,d,i),i){if(i.size>0){const t=e.$getWritableNodeState(d);for(const e of i)if(e.startsWith(Q)){const n=ee(e);t.updateFromUnknown(n,g[n])}}}else e.$getWritableNodeState(d).updateFromJSON(g);const y=d.getLatest();return s.mapping.set(n,y),y},R=(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),d=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 f=t[c];d?(e.splice(c,1,[f]),l++,c++):(e.splice(c,0,[f]),c++)}const a=l>i,d=c>r;a&&!d?e.append(...t.slice(c)):d&&!a&&e.splice(t.length,e.getChildrenSize()-t.length,[])},D=(e,n)=>void 0===n?!e.deleted:n.sv.has(e.id.client)&&n.sv.get(e.id.client)>e.id.clock&&!t.isDeleted(n.ds,e.id),j=(t,n,o,s,i)=>{const r=q(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={...N(o,n),...i.p},d=Object.fromEntries(Object.entries(i).filter(([e])=>e.startsWith(Q)).map(([e,t])=>[ee(e),t]));C(n,a,o,null),e.$getWritableNodeState(o).updateFromJSON(d)}const a=l.map(e=>e.getLatest());return n.mapping.set(t,a),a},X=(n,o)=>n instanceof Array?((e,n)=>{const o=new t.XmlText;return H(o,e,n),o})(n,o):((n,o)=>{const s=new t.XmlElement(n.getType()),i={...J(n,o),...te(n)};for(const e in i){const t=i[e];null!==t&&s.setAttribute(e,t)}return n instanceof e.ElementNode?(s.insert(0,B(n).map(e=>X(e,o))),o.mapping.set(s,n),s):s})(n,o),z=e=>"object"==typeof e&&null!=e,Y=(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||z(r)&&z(l)&&Y(r,l)}return o},B=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},U=(t,n,o)=>{const s=q(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(Q)));return t.insert===i.getTextContent()&&r===i.getType()&&Y(l,J(i,o))&&Y(c,te(i))})},W=(e,n,o)=>{if(e instanceof t.XmlElement&&!(n instanceof Array)&&oe(e,n)){const t=B(n);return e._length===t.length&&Y(e.getAttributes(),{...J(n,o),...te(n)})&&e.toArray().every((e,n)=>W(e,t[n],o))}return e instanceof t.XmlText&&n instanceof Array&&U(e,n,o)},G=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),V=(e,n,o)=>{const s=e.toArray(),i=B(n),r=i.length,l=s.length,c=Math.min(l,r);let a=0,d=0,f=!1;for(;a<c;a++){const e=s[a],n=i[a];if(e instanceof t.XmlHook)break;if(G(o.mapping.get(e),n))f=!0;else if(!W(e,n,o))break}for(;a+d<c;d++){const e=s[l-d-1],n=i[r-d-1];if(e instanceof t.XmlHook)break;if(G(o.mapping.get(e),n))f=!0;else if(!W(e,n,o))break}return{equalityFactor:a+d,foundMappedChild:f}},H=(n,o,i)=>{i.mapping.set(n,o);const{nAttrs:r,str:l}=(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 s=J(t,i);return 0===Object.keys(s).length&&(s=null),{attributes:Object.assign({},r,{...o!==e.TextNode.getType()&&{t:o},p:s,...te(t),...n>0&&{i:n}}),insert:t.getTextContent(),nodeKey:t.getKey()}}),a=c.map(e=>e.insert).join(""),d=e.$getSelection();let f;if(e.$isRangeSelection(d)&&d.isCollapsed()){f=0;for(const e of c){if(e.nodeKey===d.anchor.key){f+=d.anchor.offset;break}f+=e.insert.length}}else f=a.length;const{insert:u,remove:h,index:p}=s(l,a,f);n.delete(p,h),n.insert(p,u),n.applyDelta(c.map(e=>({attributes:e.attributes,retain:e.insert.length})))},q=(e,t,n,o)=>e.toDelta(t,n,o).map(e=>{const t=e.attributes??{};return"ychange"in t&&(t[Z("ychange")]=t.ychange,delete t.ychange),{...e,attributes:t}}),J=(e,t)=>{const n=N(e,t),o={};return Object.entries(n).forEach(([t,n])=>{const s=e[t];s!==n&&(o[t]=s)}),o},Q="s_",Z=e=>`s_${e}`,ee=e=>{if(!e.startsWith(Q))throw new Error(`Invalid state key: ${e}`);return e.slice(Q.length)},te=e=>{const t=e.__state;if(!t)return{};const[n={},o]=t.getInternalState(),s={};for(const[e,t]of Object.entries(n))s[Z(e)]=t;for(const[e,t]of o)s[Z(e.key)]=e.unparse(t);return s},ne=(n,o,s,i,r)=>{if(o instanceof t.XmlElement&&o.nodeName!==s.getType()&&(!F(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={...J(s,i),...te(s)};for(const n in t)if(null!=t[n]){e[n]===t[n]||z(e[n])&&z(t[n])&&Y(e[n],t[n])||"ychange"===n||o.setAttribute(n,t[n])}else o.removeAttribute(n);for(const n in e)void 0===t[n]&&o.removeAttribute(n)}const l=B(s),c=l.length,a=o.toArray(),d=a.length,f=Math.min(c,d);let u=0,h=0;for(;u<f;u++){const o=a[u],s=l[u];if(o instanceof t.XmlHook)break;if(G(i.mapping.get(o),s))s instanceof e.ElementNode&&r.has(s.getKey())&&ne(n,o,s,i,r);else{if(!W(o,s,i))break;i.mapping.set(o,s)}}for(;h+u<f;h++){const o=a[d-h-1],s=l[c-h-1];if(o instanceof t.XmlHook)break;if(G(i.mapping.get(o),s))s instanceof e.ElementNode&&r.has(s.getKey())&&ne(n,o,s,i,r);else{if(!W(o,s,i))break;i.mapping.set(o,s)}}for(;d-u-h>0&&c-u-h>0;){const e=a[u],s=l[u],f=a[d-h-1],p=l[c-h-1];if(e instanceof t.XmlText&&s instanceof Array)U(e,s,i)||H(e,s,i),u+=1;else{let l=e instanceof t.XmlElement&&oe(e,s),c=f instanceof t.XmlElement&&oe(f,p);if(l&&c){const t=V(e,s,i),n=V(f,p,i);t.foundMappedChild&&!n.foundMappedChild?c=!1:!t.foundMappedChild&&n.foundMappedChild||t.equalityFactor<n.equalityFactor?l=!1:c=!1}l?(ne(n,e,s,i,r),u+=1):c?(ne(n,f,p,i,r),h+=1):(i.mapping.delete(o.get(u)),o.delete(u,1),o.insert(u,[X(s,i)]),u+=1)}}const p=d-u-h;if(1===d&&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(X(l[t],i));o.insert(u,e)}},oe=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType(),se=e.createState("ychange",{isEqual:(e,t)=>e===t,parse:e=>e??null});function ie(n,s){const i=s.collabNodeMap.get(n.key);if(void 0===i)return null;let r=n.offset,l=i.getSharedType();if(i instanceof a){l=i._parent._xmlText;const e=i.getOffset();if(-1===e)return null;r=e+1+r}else if(i instanceof f&&"element"===n.type){const t=n.getNode();e.$isElementNode(t)||o(184);let s=0,i=0,l=t.getFirstChild();for(;null!==l&&i++<r;)e.$isTextNode(l)?s+=l.getTextContentSize()+1:s++,l=l.getNextSibling();r=s}return t.createRelativePositionFromTypeIndex(l,r)}function re(n,s){const{mapping:i}=s,{offset:r}=n,l=n.getNode(),c=i.getSharedType(l);if(void 0===c)return null;if("text"===n.type){e.$isTextNode(l)||o(326);let n=l.getPreviousSibling(),s=r;for(;e.$isTextNode(n);)s+=n.getTextContentSize(),n=n.getPreviousSibling();return t.createRelativePositionFromTypeIndex(c,s)}if("element"===n.type){e.$isElementNode(l)||o(184);let n=0,s=l.getFirstChild();for(;null!==s&&n<r;){if(e.$isTextNode(s)){let t=s.getNextSibling();for(;e.$isTextNode(t);)t=t.getNextSibling()}n++,s=s.getNextSibling()}return t.createRelativePositionFromTypeIndex(c,n)}return null}function le(e,n){return t.createAbsolutePositionFromRelativePosition(e,n.doc)}function ce(e,n){if(null==e){if(null!=n)return!0}else if(null==n||!t.compareRelativePositions(e,n))return!0;return!1}function ae(e,t){return{color:t,name:e,selection:null}}function de(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 fe(e,t){const n=t.selection;null!==n&&de(e,n)}function ue(t,n,o,s,i,r={}){const l=t.color,c=document.createElement("span");r.cursor?(c.className=r.cursor,e.setDOMStyleObject(c.style,{"--lexical-cursor-color":l,bottom:"0",position:"absolute",right:"-1px",top:"0"})):e.setDOMStyleObject(c.style,{"background-color":l,bottom:"0",position:"absolute",right:"-1px",top:"0",width:"1px","z-index":"10"});const a=document.createElement("span");return a.textContent=t.name,r.cursorName?a.className=r.cursorName:e.setDOMStyleObject(a.style,{"background-color":l,color:"#fff","font-family":"Arial","font-size":"12px","font-weight":"bold",left:"-2px","line-height":"12px",padding:"2px",position:"absolute",top:"-16px","white-space":"nowrap"}),c.appendChild(a),{anchor:{key:n,offset:o},caret:c,color:l,focus:{key:s,offset:i},name:a,selections:[]}}function he(t,o,s,i,r={}){const l=t.editor,c=l.getRootElement(),a=t.cursorsContainer;if(null===a||null===c)return;const d=a.offsetParent;if(null===d)return;const f=d.getBoundingClientRect(),u=o.selection;if(null===s)return null===u?void 0:(o.selection=null,void de(t,u));o.selection=s;const h=s.caret,p=s.color,g=s.selections,y=s.anchor,_=s.focus,m=y.key,x=_.key,T=i.get(m),N=i.get(x);if(null==T||null==N)return;let S;if(T===N&&e.$isLineBreakNode(T)){S=[l.getElementByKey(m).getBoundingClientRect()]}else{const e=n.createDOMRange(l,T,y.offset,N,_.offset);if(null===e)return;S=n.createRectsFromDOMRange(l,e)}const b=g.length,E=S.length;for(let t=0;t<E;t++){const n=S[t];let o=g[t];if(void 0===o){o=document.createElement("span"),g[t]=o;const e=document.createElement("span");r.selectionBg&&(e.className=r.selectionBg),o.appendChild(e),a.appendChild(o)}const s=n.top-f.top,i=n.left-f.left,l={height:`${n.height}px`,left:`${i}px`,"pointer-events":"none",position:"absolute",top:`${s}px`,width:`${n.width}px`};r.selection?(o.className=r.selection,e.setDOMStyleObject(o.style,{...l,"--lexical-cursor-color":p}),e.setDOMStyleObject(o.firstChild.style,{height:"100%",left:"0",position:"absolute",top:"0",width:"100%"})):(e.setDOMStyleObject(o.style,l),e.setDOMStyleObject(o.firstChild.style,{...l,"background-color":p,left:"0",opacity:"0.3",top:"0","z-index":"5"})),t===E-1&&h.parentNode!==o&&o.appendChild(h)}for(let e=b-1;e>=E;e--){const t=g[e];a.removeChild(t),g.pop()}}function pe(t,n){const{anchorPos:o,focusPos:s}=n,i=o?le(o,t):null,r=s?le(s,t):null;if(null===i||null===r)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(g(t)){const[e,t]=_e(i.type,i.index),[n,o]=_e(r.type,r.index);return{anchorKey:null!==e?e.getKey():null,anchorOffset:t,focusKey:null!==n?n.getKey():null,focusOffset:o}}let[l,c]=me(t.mapping,i),[a,d]=me(t.mapping,r);if(a&&l&&(a!==l||d!==c)){const t=a.isBefore(l),n=t?a:l,o=t?d:c;e.$isTextNode(n)&&e.$isTextNode(n.getNextSibling())&&o===n.getTextContentSize()&&(t?(a=n.getNextSibling(),d=0):(l=n.getNextSibling(),c=0))}return{anchorKey:null!==l?l.getKey():null,anchorOffset:c,focusKey:null!==a?a.getKey():null,focusOffset:d}}function ge(t,n){const o=n.awareness.getLocalState();if(null===o)return;const{anchorKey:s,anchorOffset:i,focusKey:r,focusOffset:l}=pe(t,o);if(null!==s&&null!==r){const t=e.$getSelection();if(!e.$isRangeSelection(t))return;ye(t.anchor,s,i),ye(t.focus,r,l)}}function ye(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 _e(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof f){const{node:e,offset:o}=w(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function me(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 xe(e,t){return t.awareness.getStates()}function Te(e,t,n){const{getAwarenessStates:o=xe}=n??{},s=Array.from(o(e,t)),i=e.clientID,r=e.cursors,l=e.editor,c=l._config.theme.collaboration,a=l._editorState._nodeMap,d=new Set;for(let t=0;t<s.length;t++){const n=s[t],[o,f]=n;if(0!==o&&o!==i){d.add(o);const{name:t,color:n,focusing:s}=f;let i=null,u=r.get(o);if(void 0===u&&(u=ae(t,n),r.set(o,u)),s){const{anchorKey:t,anchorOffset:n,focusKey:o,focusOffset:s}=l.read(()=>pe(e,f));if(null!==t&&null!==o)if(i=u.selection,null===i)i=ue(u,t,n,o,s,c);else{const e=i.anchor,r=i.focus;e.key=t,e.offset=n,r.key=o,r.offset=s}}he(e,u,i,a,c)}}const f=Array.from(r.keys());for(let t=0;t<f.length;t++){const n=f[t];if(!d.has(n)){const t=r.get(n);void 0!==t&&(fe(e,t),r.delete(n))}}}function Ne(t,n,o,s){const i=n.awareness,r=i.getLocalState();if(null===r)return;const{anchorPos:l,focusPos:c,name:a,color:d,focusing:f,awarenessData:u}=r;let h=null,p=null;(null!==s&&(null===l||s.is(o))||null!==o)&&(e.$isRangeSelection(s)&&(g(t)?(h=ie(s.anchor,t),p=ie(s.focus,t)):(h=re(s.anchor,t),p=re(s.focus,t))),(ce(l,h)||ce(c,p))&&i.setLocalState({...r,anchorPos:h,awarenessData:u,color:d,focusPos:p,focusing:f,name:a}))}function Se(n,s){if(s instanceof t.YMapEvent&&function(n,o){const{target:s}=o;if(!s._item||"__state"!==s._item.parentSub||void 0!==b(s)||!(s.parent instanceof t.XmlText||s.parent instanceof t.XmlElement||s.parent instanceof t.Map))return!1;const i=E(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,s))return;const{target:r}=s,l=E(n,r);if(l instanceof f&&s instanceof t.YTextEvent){const{keysChanged:e,childListChanged:t,delta:o}=s;e.size>0&&l.syncPropertiesFromYjs(n,e),t&&(l.applyChildrenYjsDelta(n,o),l.syncChildrenFromYjs(n))}else if(l instanceof a&&s instanceof t.YMapEvent){const{keysChanged:e}=s;e.size>0&&l.syncPropertiesAndTextFromYjs(n,e)}else if(l instanceof i&&s instanceof t.YXmlEvent){const{attributesChanged:e}=s;e.size>0&&l.syncPropertiesFromYjs(n,e)}else o(82)}function be(t,n,o){const s=e.$getSelection();if(e.$isRangeSelection(s))if(P(s)){const i=t._selection;if(e.$isRangeSelection(i)&&(ge(n,o),P(s))){L(s.anchor.key,t)}Ne(n,o,i,e.$getSelection())}else ge(n,o)}function Ee(){0===e.$getRoot().getChildrenSize()&&e.$getRoot().append(e.$createParagraphNode())}function Oe(e,n){const{target:s}=n;if(s instanceof t.XmlElement&&n instanceof t.YXmlEvent)I(s,e,n.attributesChanged,n.childListChanged);else if(s instanceof t.XmlText&&n instanceof t.YTextEvent){const n=s.parent;n instanceof t.XmlElement?I(n,e,new Set,!0):o(327)}else o(328)}const Ce=e.createCommand("CONNECTED_COMMAND"),ke=e.createCommand("TOGGLE_CONNECT_COMMAND"),$e=e.createCommand("DIFF_VERSIONS_COMMAND"),ve=e.createCommand("CLEAR_DIFF_VERSIONS_COMMAND");exports.$getYChangeState=function(t){return e.$getState(t,se)},exports.CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL=ve,exports.CONNECTED_COMMAND=Ce,exports.DIFF_VERSIONS_COMMAND__EXPERIMENTAL=$e,exports.TOGGLE_CONNECT_COMMAND=ke,exports.createBinding=function(e,n,s,i,r,l){null==i&&o(81);const c=u(i.get("root",t.XmlText),null,"root");return c._key="root",{...p(e,s,i,r,l),collabNodeMap:new Map,root:c}},exports.createBindingV2__EXPERIMENTAL=function(e,n,s,i,r={}){null==s&&o(81);const{excludedProperties:l,rootName:c="root-v2"}=r;return{...p(e,n,s,i,l),mapping:new h,root:s.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=le(n,e),c=le(o,e);null!==t&&null!==c&&([s,i]=_e(t.type,t.index),[r,l]=_e(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.renderSnapshot__EXPERIMENTAL=(n,s=t.snapshot(n.doc),i=t.emptySnapshot)=>{const{doc:r}=n;r.gc&&o(325),r.transact(o=>{const l=new t.PermanentUserData(r);l&&l.dss.forEach(e=>{t.iterateDeletedStructs(o,e,e=>{})});const c=(e,t)=>({id:t,type:e,user:("added"===e?l.getUserByClientId(t.client):l.getUserByDeletedId(t))??null});n.mapping.clear(),n.editor.update(()=>{e.$getRoot().clear(),I(n.root,n,null,!0,s,i,c)})},n)},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=Te,exports.syncLexicalUpdateToYjs=function(t,n,o,s,i,r,l,c){K(t,()=>{s.read(()=>{if(c.has(e.COLLABORATION_TAG)||c.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),c=s.get(n);if(c instanceof a)if(e.$isTextNode(l))i.push([c,l.__text]);else{const e=c.getOffset();if(-1===e)continue;const t=c._parent;c._normalized=!0,t._xmlText.delete(e,1),r.push(c)}}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(),d=o._selection;Ne(t,n,d,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)}),K(t,()=>{s.read(()=>{i.has("root")&&ne(t.doc,t.root,e.$getRoot(),t,new Set(i.keys()));const s=e.$getSelection(),r=o._selection;Ne(t,n,r,s)})}))},exports.syncYjsChangesToLexical=function(t,n,o,s,i=Te){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];Se(t,n)}be(l,t,n),s||e.$addUpdateTag(e.SKIP_SCROLL_INTO_VIEW_TAG)},{onUpdate:()=>{i(t,n),r.update(()=>Ee())},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];Oe(n,t)}be(c,n,o),r||e.$addUpdateTag(e.SKIP_SCROLL_INTO_VIEW_TAG)},{discrete:!0,onUpdate:()=>{Te(n,o),l.update(()=>Ee())},skipTransforms:!0,tag:r?e.HISTORIC_TAG:e.COLLABORATION_TAG})},exports.syncYjsStateToLexicalV2__EXPERIMENTAL=function(t,n){t.mapping.clear();const o=t.editor;o.update(()=>{e.$getRoot().clear(),I(t.root,t,null,!0),e.$addUpdateTag(e.COLLABORATION_TAG)},{discrete:!0,onUpdate:()=>{Te(t,n),o.update(()=>Ee())},skipTransforms:!0,tag:e.COLLABORATION_TAG})};
9
+ "use strict";var e=require("lexical"),t=require("yjs"),n=require("@lexical/selection");function o(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.`)}function s(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 i{_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);M(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&o(83);C(e,this._xmlElem,n,t)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function r(e,t,n){const o=new i(e,t,n);return e._collabNode=o,o}class l{_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 c(e,t){const n=new l(e,t);return e._collabNode=n,n}class a{_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 i=this.getPrevNode(o),r=n.__text;if(M(t,this._map,i,n),null!==i){const t=i.__text;if(t!==r){!function(t,n,o,i){const r=e.$getSelection();let l=i.length;if(e.$isRangeSelection(r)&&r.isCollapsed()){const e=r.anchor;e.key===n&&(l=e.offset)}const c=s(o,i,l);t.spliceText(c.index,c.remove,c.insert)}(this,n.__key,t,r),this._text=r}}}syncPropertiesAndTextFromYjs(e,t){const n=this.getNode();null===n&&o(84),C(e,this._map,n,t);const s=this._text;n.__text!==s&&n.setTextContent(s)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function d(e,t,n,o){const s=new a(e,t,n,o);return e._collabNode=s,s}class f{_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&&o(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&o(91),C(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 c=t[r],d=c.insert,u=c.delete;if(null!=c.retain)o+=c.retain;else if("number"==typeof u){let e=u;for(;e>0;){const{node:t,nodeIndex:s,offset:r,length:c}=w(this,o,!1);if(t instanceof f||t instanceof l||t instanceof i)n.splice(s,1),e-=1;else{if(!(t instanceof a))break;{const o=Math.min(e,c),i=0!==s?n[s-1]:null,l=t.getSize();if(0===r&&c===l){n.splice(s,1);const e=A(t._text,r,o-1,"");e.length>0&&(i instanceof a?i._text+=e:this._xmlText.delete(r,e.length))}else t._text=A(t._text,r,o,"");e-=o}}}}else{if(null==d)throw new Error("Unexpected delta format");if("string"==typeof d){const{node:e,offset:t}=w(this,o,!0);e instanceof a?e._text=A(e._text,t,0,d):this._xmlText.delete(t,d.length),o+=d.length}else{const t=d,{node:i,nodeIndex:r,length:l}=w(this,o,!1),c=E(e,t,this);if(i instanceof a&&l>0&&l<i._text.length){const e=i._text,t=e.length-l;i._text=A(e,t,l,""),n.splice(r+1,0,c),s=A(e,0,t,"")}else n.splice(r,0,c);null!==s&&c instanceof a&&(c._text=s+c._text,s=null),o+=1}}}}syncChildrenFromYjs(t){const n=this.getNode();null===n&&o(92);const s=n.__key,r=e.$createChildrenArray(n,null),c=r.length,d=this._children,u=d.length,h=t.collabNodeMap,p=new Set;let g,_,y=0,m=null;u!==c&&(_=n.getWritable());for(let c=0;c<u;c++){const x=r[y],T=d[c],N=T.getNode(),S=T._key;if(null!==N&&x===S){const n=e.$isTextNode(N);if(p.add(x),n)if(T._key=x,T instanceof f){const e=T._xmlText;T.syncPropertiesFromYjs(t,null),T.applyChildrenYjsDelta(t,e.toDelta()),T.syncChildrenFromYjs(t)}else T instanceof a?T.syncPropertiesAndTextFromYjs(t,null):T instanceof i?T.syncPropertiesFromYjs(t,null):T instanceof l||o(93);m=N,y++}else{if(void 0===g){g=new Set;for(let e=0;e<u;e++){const t=d[e]._key;""!==t&&g.add(t)}}if(null!==N&&void 0!==x&&!g.has(x)){const t=e.$getNodeByKeyOrThrow(x);e.removeFromParent(t),c--,y++;continue}_=n.getWritable();const o=O(t,T,s),i=o.__key;if(h.set(i,T),null===m){const e=_.getFirstChild();if(_.__first=i,null!==e){const t=e.getWritable();t.__prev=i,o.__next=t.__key}}else{const e=m.getWritable(),t=m.getNextSibling();if(e.__next=i,o.__prev=m.__key,null!==t){const e=t.getWritable();e.__prev=i,o.__next=e.__key}}c===u-1&&(_.__last=i),_.__size++,m=o}}for(let n=0;n<c;n++){const o=r[n];if(!p.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){M(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(t,n,o,s,r,l){const c=this._children[n],d=e.$getNodeByKeyOrThrow(o);c instanceof f&&e.$isElementNode(d)?(c.syncPropertiesFromLexical(t,d,s),c.syncChildrenFromLexical(t,d,s,r,l)):c instanceof a&&e.$isTextNode(d)?c.syncPropertiesAndTextFromLexical(t,d,s):c instanceof i&&e.$isDecoratorNode(d)&&c.syncPropertiesFromLexical(t,d,s)}syncChildrenFromLexical(t,n,o,s,i){const r=this.getPrevNode(o),l=null===r?[]:e.$createChildrenArray(r,o),c=e.$createChildrenArray(n,null),a=l.length-1,d=c.length-1,f=t.collabNodeMap;let u,h,p=0,g=0;for(;p<=a&&g<=d;){const n=l[p],r=c[g];if(n===r)this._syncChildFromLexical(t,g,r,o,s,i),p++,g++;else{void 0===u&&(u=new Set(l)),void 0===h&&(h=new Set(c));const o=h.has(n),s=u.has(r);if(o){const n=S(t,e.$getNodeByKeyOrThrow(r),this);f.set(r,n),s?(this.splice(t,g,1,n),p++,g++):(this.splice(t,g,0,n),g++)}else this.splice(t,g,1),p++}}const _=p>a,y=g>d;if(_&&!y)for(;g<=d;++g){const n=c[g],o=S(t,e.$getNodeByKeyOrThrow(n),this);this.append(o),f.set(n,o)}else if(y&&!_)for(let e=this._children.length-1;e>=g;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 f)t.insertEmbed(s,e._xmlText);else if(e instanceof a){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof l?t.insertEmbed(s,e._map):e instanceof i&&t.insertEmbed(s,e._xmlElem);this._children.push(e)}splice(e,t,n,s){const r=this._children,c=r[t];if(void 0===c)return void 0===s&&o(94),void this.append(s);const d=c.getOffset();-1===d&&o(95);const u=this._xmlText;if(0!==n&&u.delete(d,c.getSize()),s instanceof f)u.insertEmbed(d,s._xmlText);else if(s instanceof a){const e=s._map;null===e.parent&&u.insertEmbed(d,e),u.insert(d+1,s._text)}else s instanceof l?u.insertEmbed(d,s._map):s instanceof i&&u.insertEmbed(d,s._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!==s?r.splice(t,n,s):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 u(e,t,n){const o=new f(e,t,n);return e._collabNode=o,o}class h{_nodeMap=new Map;_sharedTypeToNodeKeys=new Map;_nodeKeyToSharedType=new Map;set(n,s){const i=s instanceof Array;this.delete(n);const r=i?s:[s];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||o(331),0===s.length)return;this._sharedTypeToNodeKeys.set(n,s.map(e=>e.getKey()));for(const e of s)this._nodeMap.set(e.getKey(),e),this._nodeKeyToSharedType.set(e.getKey(),n)}else i&&o(332),e.$isTextNode(s)&&o(333),this._sharedTypeToNodeKeys.set(n,[s.getKey()]),this._nodeMap.set(s.getKey(),s),this._nodeKeyToSharedType.set(s.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)}clear(){this._nodeMap.clear(),this._sharedTypeToNodeKeys.clear(),this._nodeKeyToSharedType.clear()}}function p(e,t,n,s,i){null==n&&o(81);const r={clientID:n.clientID,cursors:new Map,cursorsContainer:null,doc:n,docMap:s,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))T(t,o,e)||(s[t]=n);n.set(o.__type,Object.freeze(s))})})}(r),r}function g(e){return Object.prototype.hasOwnProperty.call(e,"collabNodeMap")}const _=new Set(["__key","__parent","__next","__prev","__state"]),y=new Set(["__first","__last","__size"]),m=new Set(["__cachedText"]),x=new Set(["__text"]);function T(t,n,o){if(_.has(t)||"function"==typeof n[t])return!0;if(e.$isTextNode(n)){if(x.has(t))return!0}else if(e.$isElementNode(n)&&(y.has(t)||e.$isRootNode(n)&&m.has(t)))return!0;const s=n.constructor,i=o.excludedProperties.get(s);return null!=i&&i.has(t)}function N(e,t){const n=e.__type,{nodeProperties:s}=t,i=s.get(n);return void 0===i&&o(330,n),i}function S(n,s,i){const l=s.__type;let a;if(e.$isElementNode(s)){a=u(new t.XmlText,i,l),a.syncPropertiesFromLexical(n,s,null),a.syncChildrenFromLexical(n,s,null,null,null)}else if(e.$isTextNode(s)){a=d(new t.Map,s.__text,i,l),a.syncPropertiesAndTextFromLexical(n,s,null)}else if(e.$isLineBreakNode(s)){const e=new t.Map;e.set("__type","linebreak"),a=c(e,i)}else if(e.$isDecoratorNode(s)){a=r(new t.XmlElement,i,l),a.syncPropertiesFromLexical(n,s,null)}else o(86);return a._key=s.__key,a}function b(e){const t=k(e,"__type");return"string"!=typeof t&&void 0!==t&&o(87),t}function E(e,n,s){const i=n._collabNode;if(void 0===i){const i=e.editor._nodes,l=b(n);"string"!=typeof l&&o(87);void 0===i.get(l)&&o(88,l);const a=n.parent,h=void 0===s&&null!==a?E(e,a):s||null;if(h instanceof f||o(89),n instanceof t.XmlText)return u(n,h,l);if(n instanceof t.Map)return"linebreak"===l?c(n,h):d(n,"",h,l);if(n instanceof t.XmlElement)return r(n,h,l)}return i}function O(e,t,n){const s=t.getType(),r=e.editor._nodes.get(s);void 0===r&&o(88,s);const l=new r.klass;if(l.__parent=n,t._key=l.__key,t instanceof f){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof a?t.syncPropertiesAndTextFromYjs(e,null):t instanceof i&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(l.__key,t),l}function C(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(T(c,s,n)){"__state"===c&&g(n)&&(l||(l=s.getWritable()),v(o,l));continue}const a=s[c];let d=k(o,c);if(a!==d){if(d instanceof t.Doc){const o=n.docMap;a instanceof t.Doc&&o.delete(a.guid);const s=d.guid;if(o.set(s,d),e.isLexicalEditor(a))a._key=s,d=a;else{const t=e.createEditor();t._key=s,d=t}}void 0===l&&(l=s.getWritable()),l[c]=d}}}function k(e,n){return e instanceof t.Map?e.get(n):e instanceof t.XmlText||e instanceof t.XmlElement?e.getAttribute(n):e[n]}function $(e,n,o){e instanceof t.Map?e.set(n,o):e.setAttribute(n,o)}function v(n,o){const s=k(n,"__state");s instanceof t.Map&&e.$getWritableNodeState(o).updateFromJSON(s.toJSON())}function M(e,n,o,s){const i=Object.keys(N(s,e)),r=e.editor.constructor;!function(e,n,o,s){const i=s.__state,r=null===n.doc?void 0:k(n,"__state");if(!i)return;const[l,c]=i.getInternalState(),a=o&&o.__state,d=r instanceof t.Map?r:new t.Map;if(a===i)return;const[f,u]=a&&d.doc?a.getInternalState():[void 0,new Map];if(l)for(const[e,t]of Object.entries(l))f&&t!==f[e]&&d.set(e,t);for(const[e,t]of c)u.get(e)!==t&&d.set(e.key,e.unparse(t));r||$(n,"__state",d)}(0,n,o,s);for(let l=0;l<i.length;l++){const c=i[l],a=null===o?void 0:o[c];let d=s[c];if(a!==d){if(d 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;d._key=l,n.set(l,i),d=i,e.editor.update(()=>{s.markDirty()})}$(n,c,d)}}}function A(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function w(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 a){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 P(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 K(e,t){e.doc.transact(t,e)}function L(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():L(i.__key,n):e.$getRoot().selectStart()}const F=e=>"UNDEFINED"===e.nodeName,I=(n,s,i,r,l,c,a)=>{let d=s.mapping.get(n);if(d&&i&&0===i.size&&!r)return d;const f=F(n)?e.RootNode.getType():n.nodeName,u=s.editor._nodes.get(f);if(void 0===u)throw new Error(`$createOrUpdateNodeFromYElement: Node ${f} is not registered`);if(d||(d=new u.klass,i=null,r=!0),r&&d instanceof e.ElementNode){const e=[],i=n=>{if(n instanceof t.XmlElement){const t=I(n,s,new Set,!1,l,c,a);null!==t&&e.push(t)}else if(n instanceof t.XmlText){const t=j(n,s,l,c,a);null!==t&&t.forEach(t=>{null!==t&&e.push(t)})}else o(329)};void 0===l||void 0===c?n.toArray().forEach(i):t.typeListToArraySnapshot(n,new t.Snapshot(c.ds,l.sv)).filter(e=>!e._item.deleted||D(e._item,l)||D(e._item,c)).forEach(i),R(d,e)}const h=n.getAttributes(l);F(n)||void 0===l||(D(n._item,l)?D(n._item,c)||(h[Z("ychange")]=a?a("added",n._item.id):{type:"added"}):h[Z("ychange")]=a?a("removed",n._item.id):{type:"removed"});const p={...N(d,s)},g={};for(const e in h)e.startsWith(Q)?g[ee(e)]=h[e]:"__proto__"!==e&&"constructor"!==e&&"prototype"!==e&&(p[e]=h[e]);if(C(s,p,d,i),i){if(i.size>0){const t=e.$getWritableNodeState(d);for(const e of i)if(e.startsWith(Q)){const n=ee(e);t.updateFromUnknown(n,g[n])}}}else e.$getWritableNodeState(d).updateFromJSON(g);const _=d.getLatest();return s.mapping.set(n,_),_},R=(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),d=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 f=t[c];d?(e.splice(c,1,[f]),l++,c++):(e.splice(c,0,[f]),c++)}const a=l>i,d=c>r;a&&!d?e.append(...t.slice(c)):d&&!a&&e.splice(t.length,e.getChildrenSize()-t.length,[])},D=(e,n)=>void 0===n?!e.deleted:n.sv.has(e.id.client)&&n.sv.get(e.id.client)>e.id.clock&&!t.isDeleted(n.ds,e.id),j=(t,n,o,s,i)=>{const r=q(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={...N(o,n),...i.p},d=Object.fromEntries(Object.entries(i).filter(([e])=>e.startsWith(Q)).map(([e,t])=>[ee(e),t]));C(n,a,o,null),e.$getWritableNodeState(o).updateFromJSON(d)}const a=l.map(e=>e.getLatest());return n.mapping.set(t,a),a},X=(n,o)=>n instanceof Array?((e,n)=>{const o=new t.XmlText;return H(o,e,n),o})(n,o):((n,o)=>{const s=new t.XmlElement(n.getType()),i={...J(n,o),...te(n)};for(const e in i){const t=i[e];null!==t&&s.setAttribute(e,t)}return n instanceof e.ElementNode?(s.insert(0,B(n).map(e=>X(e,o))),o.mapping.set(s,n),s):s})(n,o),z=e=>"object"==typeof e&&null!=e,Y=(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||z(r)&&z(l)&&Y(r,l)}return o},B=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},U=(t,n,o)=>{const s=q(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(Q)));return t.insert===i.getTextContent()&&r===i.getType()&&Y(l,J(i,o))&&Y(c,te(i))})},W=(e,n,o)=>{if(e instanceof t.XmlElement&&!(n instanceof Array)&&oe(e,n)){const t=B(n);return e._length===t.length&&Y(e.getAttributes(),{...J(n,o),...te(n)})&&e.toArray().every((e,n)=>W(e,t[n],o))}return e instanceof t.XmlText&&n instanceof Array&&U(e,n,o)},G=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),V=(e,n,o)=>{const s=e.toArray(),i=B(n),r=i.length,l=s.length,c=Math.min(l,r);let a=0,d=0,f=!1;for(;a<c;a++){const e=s[a],n=i[a];if(e instanceof t.XmlHook)break;if(G(o.mapping.get(e),n))f=!0;else if(!W(e,n,o))break}for(;a+d<c;d++){const e=s[l-d-1],n=i[r-d-1];if(e instanceof t.XmlHook)break;if(G(o.mapping.get(e),n))f=!0;else if(!W(e,n,o))break}return{equalityFactor:a+d,foundMappedChild:f}},H=(n,o,i)=>{i.mapping.set(n,o);const{nAttrs:r,str:l}=(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 s=J(t,i);return 0===Object.keys(s).length&&(s=null),{attributes:Object.assign({},r,{...o!==e.TextNode.getType()&&{t:o},p:s,...te(t),...n>0&&{i:n}}),insert:t.getTextContent(),nodeKey:t.getKey()}}),a=c.map(e=>e.insert).join(""),d=e.$getSelection();let f;if(e.$isRangeSelection(d)&&d.isCollapsed()){f=0;for(const e of c){if(e.nodeKey===d.anchor.key){f+=d.anchor.offset;break}f+=e.insert.length}}else f=a.length;const{insert:u,remove:h,index:p}=s(l,a,f);n.delete(p,h),n.insert(p,u),n.applyDelta(c.map(e=>({attributes:e.attributes,retain:e.insert.length})))},q=(e,t,n,o)=>e.toDelta(t,n,o).map(e=>{const t=e.attributes??{};return"ychange"in t&&(t[Z("ychange")]=t.ychange,delete t.ychange),{...e,attributes:t}}),J=(e,t)=>{const n=N(e,t),o={};return Object.entries(n).forEach(([t,n])=>{const s=e[t];s!==n&&(o[t]=s)}),o},Q="s_",Z=e=>`s_${e}`,ee=e=>{if(!e.startsWith(Q))throw new Error(`Invalid state key: ${e}`);return e.slice(Q.length)},te=e=>{const t=e.__state;if(!t)return{};const[n={},o]=t.getInternalState(),s={};for(const[e,t]of Object.entries(n))s[Z(e)]=t;for(const[e,t]of o)s[Z(e.key)]=e.unparse(t);return s},ne=(n,o,s,i,r)=>{if(o instanceof t.XmlElement&&o.nodeName!==s.getType()&&(!F(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={...J(s,i),...te(s)};for(const n in t)if(null!=t[n]){e[n]===t[n]||z(e[n])&&z(t[n])&&Y(e[n],t[n])||"ychange"===n||o.setAttribute(n,t[n])}else o.removeAttribute(n);for(const n in e)void 0===t[n]&&o.removeAttribute(n)}const l=B(s),c=l.length,a=o.toArray(),d=a.length,f=Math.min(c,d);let u=0,h=0;for(;u<f;u++){const o=a[u],s=l[u];if(o instanceof t.XmlHook)break;if(G(i.mapping.get(o),s))s instanceof e.ElementNode&&r.has(s.getKey())&&ne(n,o,s,i,r);else{if(!W(o,s,i))break;i.mapping.set(o,s)}}for(;h+u<f;h++){const o=a[d-h-1],s=l[c-h-1];if(o instanceof t.XmlHook)break;if(G(i.mapping.get(o),s))s instanceof e.ElementNode&&r.has(s.getKey())&&ne(n,o,s,i,r);else{if(!W(o,s,i))break;i.mapping.set(o,s)}}for(;d-u-h>0&&c-u-h>0;){const e=a[u],s=l[u],f=a[d-h-1],p=l[c-h-1];if(e instanceof t.XmlText&&s instanceof Array)U(e,s,i)||H(e,s,i),u+=1;else{let l=e instanceof t.XmlElement&&oe(e,s),c=f instanceof t.XmlElement&&oe(f,p);if(l&&c){const t=V(e,s,i),n=V(f,p,i);t.foundMappedChild&&!n.foundMappedChild?c=!1:!t.foundMappedChild&&n.foundMappedChild||t.equalityFactor<n.equalityFactor?l=!1:c=!1}l?(ne(n,e,s,i,r),u+=1):c?(ne(n,f,p,i,r),h+=1):(i.mapping.delete(o.get(u)),o.delete(u,1),o.insert(u,[X(s,i)]),u+=1)}}const p=d-u-h;if(1===d&&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(X(l[t],i));o.insert(u,e)}},oe=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType(),se=e.createState("ychange",{isEqual:(e,t)=>e===t,parse:e=>e??null});function ie(n,s){const i=s.collabNodeMap.get(n.key);if(void 0===i)return null;let r=n.offset,l=i.getSharedType();if(i instanceof a){l=i._parent._xmlText;const e=i.getOffset();if(-1===e)return null;r=e+1+r}else if(i instanceof f&&"element"===n.type){const t=n.getNode();e.$isElementNode(t)||o(184);let s=0,i=0,l=t.getFirstChild();for(;null!==l&&i++<r;)e.$isTextNode(l)?s+=l.getTextContentSize()+1:s++,l=l.getNextSibling();r=s}return t.createRelativePositionFromTypeIndex(l,r)}function re(n,s){const{mapping:i}=s,{offset:r}=n,l=n.getNode(),c=i.getSharedType(l);if(void 0===c)return null;if("text"===n.type){e.$isTextNode(l)||o(326);let n=l.getPreviousSibling(),s=r;for(;e.$isTextNode(n);)s+=n.getTextContentSize(),n=n.getPreviousSibling();return t.createRelativePositionFromTypeIndex(c,s)}if("element"===n.type){e.$isElementNode(l)||o(184);let n=0,s=l.getFirstChild();for(;null!==s&&n<r;){if(e.$isTextNode(s)){let t=s.getNextSibling();for(;e.$isTextNode(t);)t=t.getNextSibling()}n++,s=s.getNextSibling()}return t.createRelativePositionFromTypeIndex(c,n)}return null}function le(e,n){return t.createAbsolutePositionFromRelativePosition(e,n.doc)}function ce(e,n){if(null==e){if(null!=n)return!0}else if(null==n||!t.compareRelativePositions(e,n))return!0;return!1}function ae(e,t){return{color:t,name:e,selection:null}}function de(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 fe(e,t){const n=t.selection;null!==n&&de(e,n)}function ue(t,n,o,s,i,r={}){const l=t.color,c=document.createElement("span");r.cursor?(c.className=r.cursor,e.setDOMStyleObject(c.style,{"--lexical-cursor-color":l,bottom:"0",position:"absolute",right:"-1px",top:"0"})):e.setDOMStyleObject(c.style,{"background-color":l,bottom:"0",position:"absolute",right:"-1px",top:"0",width:"1px","z-index":"10"});const a=document.createElement("span");return a.textContent=t.name,r.cursorName?a.className=r.cursorName:e.setDOMStyleObject(a.style,{"background-color":l,color:"#fff","font-family":"Arial","font-size":"12px","font-weight":"bold",left:"-2px","line-height":"12px",padding:"2px",position:"absolute",top:"-16px","white-space":"nowrap"}),c.appendChild(a),{anchor:{key:n,offset:o},caret:c,color:l,focus:{key:s,offset:i},name:a,selections:[]}}function he(t,o,s,i,r={}){const l=t.editor,c=l.getRootElement(),a=t.cursorsContainer;if(null===a||null===c)return;const d=a.offsetParent;if(null===d)return;const f=d.getBoundingClientRect(),u=o.selection;if(null===s)return null===u?void 0:(o.selection=null,void de(t,u));o.selection=s;const h=s.caret,p=s.color,g=s.selections,_=s.anchor,y=s.focus,m=_.key,x=y.key,T=i.get(m),N=i.get(x);if(null==T||null==N)return;let S;if(T===N&&e.$isLineBreakNode(T)){S=[l.getElementByKey(m).getBoundingClientRect()]}else{const e=n.createDOMRange(l,T,_.offset,N,y.offset);if(null===e)return;S=n.createRectsFromDOMRange(l,e)}const b=g.length,E=S.length;for(let t=0;t<E;t++){const n=S[t];let o=g[t];if(void 0===o){o=document.createElement("span"),g[t]=o;const e=document.createElement("span");r.selectionBg&&(e.className=r.selectionBg),o.appendChild(e),a.appendChild(o)}const s=n.top-f.top,i=n.left-f.left,l={height:`${n.height}px`,left:`${i}px`,"pointer-events":"none",position:"absolute",top:`${s}px`,width:`${n.width}px`};r.selection?(o.className=r.selection,e.setDOMStyleObject(o.style,{...l,"--lexical-cursor-color":p}),e.setDOMStyleObject(o.firstChild.style,{height:"100%",left:"0",position:"absolute",top:"0",width:"100%"})):(e.setDOMStyleObject(o.style,l),e.setDOMStyleObject(o.firstChild.style,{...l,"background-color":p,left:"0",opacity:"0.3",top:"0","z-index":"5"})),t===E-1&&h.parentNode!==o&&o.appendChild(h)}for(let e=b-1;e>=E;e--){const t=g[e];a.removeChild(t),g.pop()}}function pe(t,n){const{anchorPos:o,focusPos:s}=n,i=o?le(o,t):null,r=s?le(s,t):null;if(null===i||null===r)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(g(t)){const[e,t]=ye(i.type,i.index),[n,o]=ye(r.type,r.index);return{anchorKey:null!==e?e.getKey():null,anchorOffset:t,focusKey:null!==n?n.getKey():null,focusOffset:o}}let[l,c]=me(t.mapping,i),[a,d]=me(t.mapping,r);if(a&&l&&(a!==l||d!==c)){const t=a.isBefore(l),n=t?a:l,o=t?d:c;e.$isTextNode(n)&&e.$isTextNode(n.getNextSibling())&&o===n.getTextContentSize()&&(t?(a=n.getNextSibling(),d=0):(l=n.getNextSibling(),c=0))}return{anchorKey:null!==l?l.getKey():null,anchorOffset:c,focusKey:null!==a?a.getKey():null,focusOffset:d}}function ge(t,n){const o=n.awareness.getLocalState();if(null===o)return;const{anchorKey:s,anchorOffset:i,focusKey:r,focusOffset:l}=pe(t,o);if(null!==s&&null!==r){const t=e.$getSelection();if(!e.$isRangeSelection(t))return;_e(t.anchor,s,i),_e(t.focus,r,l)}}function _e(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 ye(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof f){const{node:e,offset:o}=w(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function me(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 xe(e,t){return t.awareness.getStates()}function Te(e,t,n){const{getAwarenessStates:o=xe}=n??{},s=Array.from(o(e,t)),i=e.clientID,r=e.cursors,l=e.editor,c=l._config.theme.collaboration,a=l._editorState._nodeMap,d=new Set;for(let t=0;t<s.length;t++){const n=s[t],[o,f]=n;if(0!==o&&o!==i){d.add(o);const{name:t,color:n,focusing:s}=f;let i=null,u=r.get(o);if(void 0===u&&(u=ae(t,n),r.set(o,u)),s){const{anchorKey:t,anchorOffset:n,focusKey:o,focusOffset:s}=l.read(()=>pe(e,f));if(null!==t&&null!==o)if(i=u.selection,null===i)i=ue(u,t,n,o,s,c);else{const e=i.anchor,r=i.focus;e.key=t,e.offset=n,r.key=o,r.offset=s}}he(e,u,i,a,c)}}const f=Array.from(r.keys());for(let t=0;t<f.length;t++){const n=f[t];if(!d.has(n)){const t=r.get(n);void 0!==t&&(fe(e,t),r.delete(n))}}}function Ne(t,n,o,s){const i=n.awareness,r=i.getLocalState();if(null===r)return;const{anchorPos:l,focusPos:c,name:a,color:d,focusing:f,awarenessData:u}=r;let h=null,p=null;(null!==s&&(null===l||s.is(o))||null!==o)&&(e.$isRangeSelection(s)&&(g(t)?(h=ie(s.anchor,t),p=ie(s.focus,t)):(h=re(s.anchor,t),p=re(s.focus,t))),(ce(l,h)||ce(c,p))&&i.setLocalState({...r,anchorPos:h,awarenessData:u,color:d,focusPos:p,focusing:f,name:a}))}function Se(n,s){if(s instanceof t.YMapEvent&&function(n,o){const{target:s}=o;if(!s._item||"__state"!==s._item.parentSub||void 0!==b(s)||!(s.parent instanceof t.XmlText||s.parent instanceof t.XmlElement||s.parent instanceof t.Map))return!1;const i=E(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,s))return;const{target:r}=s,l=E(n,r);if(l instanceof f&&s instanceof t.YTextEvent){const{keysChanged:e,childListChanged:t,delta:o}=s;e.size>0&&l.syncPropertiesFromYjs(n,e),t&&(l.applyChildrenYjsDelta(n,o),l.syncChildrenFromYjs(n))}else if(l instanceof a&&s instanceof t.YMapEvent){const{keysChanged:e}=s;e.size>0&&l.syncPropertiesAndTextFromYjs(n,e)}else if(l instanceof i&&s instanceof t.YXmlEvent){const{attributesChanged:e}=s;e.size>0&&l.syncPropertiesFromYjs(n,e)}else o(82)}function be(t,n,o){const s=e.$getSelection();if(e.$isRangeSelection(s))if(P(s)){const i=t._selection;if(e.$isRangeSelection(i)&&(ge(n,o),P(s))){L(s.anchor.key,t)}Ne(n,o,i,e.$getSelection())}else ge(n,o)}function Ee(){0===e.$getRoot().getChildrenSize()&&e.$getRoot().append(e.$createParagraphNode())}function Oe(e,n){const{target:s}=n;if(s instanceof t.XmlElement&&n instanceof t.YXmlEvent)I(s,e,n.attributesChanged,n.childListChanged);else if(s instanceof t.XmlText&&n instanceof t.YTextEvent){const n=s.parent;n instanceof t.XmlElement?I(n,e,new Set,!0):o(327)}else o(328)}const Ce=e.createCommand("CONNECTED_COMMAND"),ke=e.createCommand("TOGGLE_CONNECT_COMMAND"),$e=e.createCommand("DIFF_VERSIONS_COMMAND"),ve=e.createCommand("CLEAR_DIFF_VERSIONS_COMMAND");exports.$getYChangeState=function(t){return e.$getState(t,se)},exports.CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL=ve,exports.CONNECTED_COMMAND=Ce,exports.DIFF_VERSIONS_COMMAND__EXPERIMENTAL=$e,exports.TOGGLE_CONNECT_COMMAND=ke,exports.createBinding=function(e,n,s,i,r,l){null==i&&o(81);const c=u(i.get("root",t.XmlText),null,"root");return c._key="root",{...p(e,s,i,r,l),collabNodeMap:new Map,root:c}},exports.createBindingV2__EXPERIMENTAL=function(e,n,s,i,r={}){null==s&&o(81);const{excludedProperties:l,rootName:c="root-v2"}=r;return{...p(e,n,s,i,l),mapping:new h,root:s.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=le(n,e),c=le(o,e);null!==t&&null!==c&&([s,i]=ye(t.type,t.index),[r,l]=ye(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.renderSnapshot__EXPERIMENTAL=(n,s=t.snapshot(n.doc),i=t.emptySnapshot)=>{const{doc:r}=n;r.gc&&o(325),r.transact(o=>{const l=new t.PermanentUserData(r);l&&l.dss.forEach(e=>{t.iterateDeletedStructs(o,e,e=>{})});const c=(e,t)=>({id:t,type:e,user:("added"===e?l.getUserByClientId(t.client):l.getUserByDeletedId(t))??null});n.mapping.clear(),n.editor.update(()=>{e.$getRoot().clear(),I(n.root,n,null,!0,s,i,c)})},n)},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=Te,exports.syncLexicalUpdateToYjs=function(t,n,o,s,i,r,l,c){K(t,()=>{s.read(()=>{if(c.has(e.COLLABORATION_TAG)||c.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),c=s.get(n);if(c instanceof a)if(e.$isTextNode(l))i.push([c,l.__text]);else{const e=c.getOffset();if(-1===e)continue;const t=c._parent;c._normalized=!0,t._xmlText.delete(e,1),r.push(c)}}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(),d=o._selection;Ne(t,n,d,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)}),K(t,()=>{s.read(()=>{i.has("root")&&ne(t.doc,t.root,e.$getRoot(),t,new Set(i.keys()));const s=e.$getSelection(),r=o._selection;Ne(t,n,r,s)})}))},exports.syncYjsChangesToLexical=function(t,n,o,s,i=Te){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];Se(t,n)}be(l,t,n),s||e.$addUpdateTag(e.SKIP_SCROLL_INTO_VIEW_TAG)},{onUpdate:()=>{i(t,n),r.update(()=>Ee())},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];Oe(n,t)}be(c,n,o),r||e.$addUpdateTag(e.SKIP_SCROLL_INTO_VIEW_TAG)},{discrete:!0,onUpdate:()=>{Te(n,o),l.update(()=>Ee())},skipTransforms:!0,tag:r?e.HISTORIC_TAG:e.COLLABORATION_TAG})},exports.syncYjsStateToLexicalV2__EXPERIMENTAL=function(t,n){t.mapping.clear();const o=t.editor;o.update(()=>{e.$getRoot().clear(),I(t.root,t,null,!0),e.$addUpdateTag(e.COLLABORATION_TAG)},{discrete:!0,onUpdate:()=>{Te(t,n),o.update(()=>Ee())},skipTransforms:!0,tag:e.COLLABORATION_TAG})};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{$isDecoratorNode as e,$getNodeByKey as t,$isLineBreakNode as n,$isTextNode as o,$getSelection as s,$isRangeSelection as i,$isElementNode as r,$createChildrenArray as l,$getNodeByKeyOrThrow as c,removeFromParent as a,isLexicalEditor as f,createEditor as d,$isRootNode as u,$getWritableNodeState as h,$getRoot as p,RootNode as g,ElementNode as _,TextNode as y,$getState as m,createState as x,setDOMStyleObject as b,COLLABORATION_TAG as T,HISTORIC_TAG as k,$addUpdateTag as N,SKIP_SCROLL_INTO_VIEW_TAG as S,$createParagraphNode as v,createCommand as w}from"lexical";import{XmlText as C,XmlElement as O,Map as K,Doc as M,typeListToArraySnapshot as P,Snapshot as E,isDeleted as F,XmlHook as A,ContentString as j,ContentFormat as z,emptySnapshot as L,PermanentUserData as D,iterateDeletedStructs as Y,snapshot as I,createAbsolutePositionFromRelativePosition as W,createRelativePositionFromTypeIndex as $,compareRelativePositions as U,Item as B,YMapEvent as R,YTextEvent as q,YXmlEvent as J,UndoManager as G}from"yjs";import{createDOMRange as V,createRectsFromDOMRange as H}from"@lexical/selection";function Q(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.`)}function X(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 Z{_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(n)?n:null}getNode(){const n=t(this._key);return e(n)?n: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);we(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&Q(83);ke(e,this._xmlElem,n,t)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function ee(e,t,n){const o=new Z(e,t,n);return e._collabNode=o,o}class te{_map;_key;_parent;_type;constructor(e,t){this._key="",this._map=e,this._parent=t,this._type="linebreak"}getNode(){const e=t(this._key);return n(e)?e: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 ne(e,t){const n=new te(e,t);return e._collabNode=n,n}class oe{_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 o(t)?t:null}getNode(){const e=t(this._key);return o(e)?e: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 o=this.getPrevNode(n),r=t.__text;if(we(e,this._map,o,t),null!==o){const e=o.__text;if(e!==r){!function(e,t,n,o){const r=s();let l=o.length;if(i(r)&&r.isCollapsed()){const e=r.anchor;e.key===t&&(l=e.offset)}const c=X(n,o,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&&Q(84),ke(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 se(e,t,n,o){const s=new oe(e,t,n,o);return e._collabNode=s,s}class ie{_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 e=t(this._key);return r(e)?e: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&&Q(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&Q(91),ke(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}=Oe(this,o,!1);if(t instanceof ie||t instanceof te||t instanceof Z)n.splice(s,1),e-=1;else{if(!(t instanceof oe))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 oe?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}=Oe(this,o,!0);e instanceof oe?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}=Oe(this,o,!1),a=be(e,t,this);if(i instanceof oe&&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 oe&&(a._text=s+a._text,s=null),o+=1}}}}syncChildrenFromYjs(e){const t=this.getNode();null===t&&Q(92);const n=t.__key,s=l(t,null),i=s.length,r=this._children,f=r.length,d=e.collabNodeMap,u=new Set;let h,p,g=0,_=null;f!==i&&(p=t.getWritable());for(let i=0;i<f;i++){const l=s[g],y=r[i],m=y.getNode(),x=y._key;if(null!==m&&l===x){const t=o(m);if(u.add(l),t)if(y._key=l,y instanceof ie){const t=y._xmlText;y.syncPropertiesFromYjs(e,null),y.applyChildrenYjsDelta(e,t.toDelta()),y.syncChildrenFromYjs(e)}else y instanceof oe?y.syncPropertiesAndTextFromYjs(e,null):y instanceof Z?y.syncPropertiesFromYjs(e,null):y instanceof te||Q(93);_=m,g++}else{if(void 0===h){h=new Set;for(let e=0;e<f;e++){const t=r[e]._key;""!==t&&h.add(t)}}if(null!==m&&void 0!==l&&!h.has(l)){const e=c(l);a(e),i--,g++;continue}p=t.getWritable();const o=Te(e,y,n),s=o.__key;if(d.set(s,y),null===_){const e=p.getFirstChild();if(p.__first=s,null!==e){const t=e.getWritable();t.__prev=s,o.__next=t.__key}}else{const e=_.getWritable(),t=_.getNextSibling();if(e.__next=s,o.__prev=_.__key,null!==t){const e=t.getWritable();e.__prev=s,o.__next=e.__key}}i===f-1&&(p.__last=s),p.__size++,_=o}}for(let t=0;t<i;t++){const n=s[t];if(!u.has(n)){const t=c(n),o=e.collabNodeMap.get(n);void 0!==o&&o.destroy(e),a(t)}}}syncPropertiesFromLexical(e,t,n){we(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(t,n,s,i,l,a){const f=this._children[n],d=c(s);f instanceof ie&&r(d)?(f.syncPropertiesFromLexical(t,d,i),f.syncChildrenFromLexical(t,d,i,l,a)):f instanceof oe&&o(d)?f.syncPropertiesAndTextFromLexical(t,d,i):f instanceof Z&&e(d)&&f.syncPropertiesFromLexical(t,d,i)}syncChildrenFromLexical(e,t,n,o,s){const i=this.getPrevNode(n),r=null===i?[]:l(i,n),a=l(t,null),f=r.length-1,d=a.length-1,u=e.collabNodeMap;let h,p,g=0,_=0;for(;g<=f&&_<=d;){const t=r[g],i=a[_];if(t===i)this._syncChildFromLexical(e,_,i,n,o,s),g++,_++;else{void 0===h&&(h=new Set(r)),void 0===p&&(p=new Set(a));const n=p.has(t),o=h.has(i);if(n){const t=me(e,c(i),this);u.set(i,t),o?(this.splice(e,_,1,t),g++,_++):(this.splice(e,_,0,t),_++)}else this.splice(e,_,1),g++}}const y=g>f,m=_>d;if(y&&!m)for(;_<=d;++_){const t=a[_],n=me(e,c(t),this);this.append(n),u.set(t,n)}else if(m&&!y)for(let t=this._children.length-1;t>=_;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 ie)t.insertEmbed(s,e._xmlText);else if(e instanceof oe){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof te?t.insertEmbed(s,e._map):e instanceof Z&&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&&Q(94),void this.append(o);const r=i.getOffset();-1===r&&Q(95);const l=this._xmlText;if(0!==n&&l.delete(r,i.getSize()),o instanceof ie)l.insertEmbed(r,o._xmlText);else if(o instanceof oe){const e=o._map;null===e.parent&&l.insertEmbed(r,e),l.insert(r+1,o._text)}else o instanceof te?l.insertEmbed(r,o._map):o instanceof Z&&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 re(e,t,n){const o=new ie(e,t,n);return e._collabNode=o,o}class le{_nodeMap=new Map;_sharedTypeToNodeKeys=new Map;_nodeKeyToSharedType=new Map;set(e,t){const n=t instanceof Array;this.delete(e);const s=n?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 C){if(n||Q(331),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 n&&Q(332),o(t)&&Q(333),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 C){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)}clear(){this._nodeMap.clear(),this._sharedTypeToNodeKeys.clear(),this._nodeKeyToSharedType.clear()}}function ce(e,t,n,o,s){null==n&&Q(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))_e(t,o,e)||(s[t]=n);n.set(o.__type,Object.freeze(s))})})}(i),i}function ae(e,t,n,o,s,i){null==o&&Q(81);const r=re(o.get("root",C),null,"root");return r._key="root",{...ce(e,n,o,s,i),collabNodeMap:new Map,root:r}}function fe(e,t,n,o,s={}){null==n&&Q(81);const{excludedProperties:i,rootName:r="root-v2"}=s;return{...ce(e,t,n,o,i),mapping:new le,root:n.get(r,O)}}function de(e){return Object.prototype.hasOwnProperty.call(e,"collabNodeMap")}const ue=new Set(["__key","__parent","__next","__prev","__state"]),he=new Set(["__first","__last","__size"]),pe=new Set(["__cachedText"]),ge=new Set(["__text"]);function _e(e,t,n){if(ue.has(e)||"function"==typeof t[e])return!0;if(o(t)){if(ge.has(e))return!0}else if(r(t)&&(he.has(e)||u(t)&&pe.has(e)))return!0;const s=t.constructor,i=n.excludedProperties.get(s);return null!=i&&i.has(e)}function ye(e,t){const n=e.__type,{nodeProperties:o}=t,s=o.get(n);return void 0===s&&Q(330,n),s}function me(t,s,i){const l=s.__type;let c;if(r(s)){c=re(new C,i,l),c.syncPropertiesFromLexical(t,s,null),c.syncChildrenFromLexical(t,s,null,null,null)}else if(o(s)){c=se(new K,s.__text,i,l),c.syncPropertiesAndTextFromLexical(t,s,null)}else if(n(s)){const e=new K;e.set("__type","linebreak"),c=ne(e,i)}else if(e(s)){c=ee(new O,i,l),c.syncPropertiesFromLexical(t,s,null)}else Q(86);return c._key=s.__key,c}function xe(e){const t=Ne(e,"__type");return"string"!=typeof t&&void 0!==t&&Q(87),t}function be(e,t,n){const o=t._collabNode;if(void 0===o){const o=e.editor._nodes,s=xe(t);"string"!=typeof s&&Q(87);void 0===o.get(s)&&Q(88,s);const i=t.parent,r=void 0===n&&null!==i?be(e,i):n||null;if(r instanceof ie||Q(89),t instanceof C)return re(t,r,s);if(t instanceof K)return"linebreak"===s?ne(t,r):se(t,"",r,s);if(t instanceof O)return ee(t,r,s)}return o}function Te(e,t,n){const o=t.getType(),s=e.editor._nodes.get(o);void 0===s&&Q(88,o);const i=new s.klass;if(i.__parent=n,t._key=i.__key,t instanceof ie){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof oe?t.syncPropertiesAndTextFromYjs(e,null):t instanceof Z&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(i.__key,t),i}function ke(e,t,n,o){const s=null===o?t instanceof K?Array.from(t.keys()):t instanceof C||t instanceof O?Object.keys(t.getAttributes()):Object.keys(t):Array.from(o);let i;for(let o=0;o<s.length;o++){const r=s[o];if(_e(r,n,e)){"__state"===r&&de(e)&&(i||(i=n.getWritable()),ve(t,i));continue}const l=n[r];let c=Ne(t,r);if(l!==c){if(c instanceof M){const t=e.docMap;l instanceof M&&t.delete(l.guid);const n=c.guid;if(t.set(n,c),f(l))l._key=n,c=l;else{const e=d();e._key=n,c=e}}void 0===i&&(i=n.getWritable()),i[r]=c}}}function Ne(e,t){return e instanceof K?e.get(t):e instanceof C||e instanceof O?e.getAttribute(t):e[t]}function Se(e,t,n){e instanceof K?e.set(t,n):e.setAttribute(t,n)}function ve(e,t){const n=Ne(e,"__state");n instanceof K&&h(t).updateFromJSON(n.toJSON())}function we(e,t,n,o){const s=Object.keys(ye(o,e)),i=e.editor.constructor;!function(e,t,n,o){const s=o.__state,i=null===t.doc?void 0:Ne(t,"__state");if(!s)return;const[r,l]=s.getInternalState(),c=n&&n.__state,a=i instanceof K?i:new K;if(c===s)return;const[f,d]=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)d.get(e)!==t&&a.set(e.key,e.unparse(t));i||Se(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 M,r=s.guid;a._key=r,t.set(r,s),a=s,e.editor.update(()=>{o.markDirty()})}Se(t,l,a)}}}function Ce(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function Oe(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 oe){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 Ke(e){const t=e.anchor,n=e.focus;let s=!1;try{const e=t.getNode(),i=n.getNode();(!e.isAttached()||!i.isAttached()||o(e)&&t.offset>e.getTextContentSize()||o(i)&&n.offset>i.getTextContentSize())&&(s=!0)}catch(e){s=!0}return s}function Me(e,t){e.doc.transact(t,e)}function Pe(e,n){const o=n._nodeMap.get(e);if(!o)return void p().selectStart();const s=o.__prev;let i=null;s&&(i=t(s)),null===i&&null!==o.__parent&&(i=t(o.__parent)),null!==i?null!==i&&i.isAttached()?i.selectEnd():Pe(i.__key,n):p().selectStart()}const Ee=e=>"UNDEFINED"===e.nodeName,Fe=(e,t,n,o,s,i,r)=>{let l=t.mapping.get(e);if(l&&n&&0===n.size&&!o)return l;const c=Ee(e)?g.getType():e.nodeName,a=t.editor._nodes.get(c);if(void 0===a)throw new Error(`$createOrUpdateNodeFromYElement: Node ${c} is not registered`);if(l||(l=new a.klass,n=null,o=!0),o&&l instanceof _){const n=[],o=e=>{if(e instanceof O){const o=Fe(e,t,new Set,!1,s,i,r);null!==o&&n.push(o)}else if(e instanceof C){const o=ze(e,t,s,i,r);null!==o&&o.forEach(e=>{null!==e&&n.push(e)})}else Q(329)};void 0===s||void 0===i?e.toArray().forEach(o):P(e,new E(i.ds,s.sv)).filter(e=>!e._item.deleted||je(e._item,s)||je(e._item,i)).forEach(o),Ae(l,n)}const f=e.getAttributes(s);Ee(e)||void 0===s||(je(e._item,s)?je(e._item,i)||(f[Ve("ychange")]=r?r("added",e._item.id):{type:"added"}):f[Ve("ychange")]=r?r("removed",e._item.id):{type:"removed"});const d={...ye(l,t)},u={};for(const e in f)e.startsWith(Ge)?u[He(e)]=f[e]:d[e]=f[e];if(ke(t,d,l,n),n){if(n.size>0){const e=h(l);for(const t of n)if(t.startsWith(Ge)){const n=He(t);e.updateFromUnknown(n,u[n])}}}else h(l).updateFromJSON(u);const p=l.getLatest();return t.mapping.set(e,p),p},Ae=(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,[])},je=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!F(t.ds,e.id),ze=(e,t,n,s,i)=>{const r=qe(e,n,s,i);let l=t.mapping.get(e)??[];const c=r.map(e=>e.attributes.t??y.getType());if(!(l.length===c.length&&l.every((e,t)=>e.getType()===c[t]))){const e=t.editor._nodes;l=c.map(t=>{const n=e.get(t);if(void 0===n)throw new Error(`$createTextNodesFromYText: Node ${t} is not registered`);const s=new n.klass;if(!o(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={...ye(n,t),...s.p},a=Object.fromEntries(Object.entries(s).filter(([e])=>e.startsWith(Ge)).map(([e,t])=>[He(e),t]));ke(t,c,n,null),h(n).updateFromJSON(a)}const a=l.map(e=>e.getLatest());return t.mapping.set(e,a),a},Le=(e,t)=>e instanceof Array?((e,t)=>{const n=new C;return Re(n,e,t),n})(e,t):((e,t)=>{const n=new O(e.getType()),o={...Je(e,t),...Qe(e)};for(const e in o){const t=o[e];null!==t&&n.setAttribute(e,t)}return e instanceof _?(n.insert(0,Ie(e).map(e=>Le(e,t))),t.mapping.set(n,e),n):n})(e,t),De=e=>"object"==typeof e&&null!=e,Ye=(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||De(r)&&De(l)&&Ye(r,l)}return o},Ie=e=>{if(!(e instanceof _))return[];const t=e.getChildren(),n=[];for(let e=0;e<t.length;e++){const s=t[e];if(o(s)){const s=[];for(let n=t[e];e<t.length&&o(n);n=t[++e])s.push(n);e--,n.push(s)}else n.push(s)}return n},We=(e,t,n)=>{const o=qe(e);return o.length===t.length&&o.every((e,o)=>{const s=t[o],i=e.attributes.t??y.getType(),r=e.attributes.p??{},l=Object.fromEntries(Object.entries(e.attributes).filter(([e])=>e.startsWith(Ge)));return e.insert===s.getTextContent()&&i===s.getType()&&Ye(r,Je(s,n))&&Ye(l,Qe(s))})},$e=(e,t,n)=>{if(e instanceof O&&!(t instanceof Array)&&Ze(e,t)){const o=Ie(t);return e._length===o.length&&Ye(e.getAttributes(),{...Je(t,n),...Qe(t)})&&e.toArray().every((e,t)=>$e(e,o[t],n))}return e instanceof C&&t instanceof Array&&We(e,t,n)},Ue=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),Be=(e,t,n)=>{const o=e.toArray(),s=Ie(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 A)break;if(Ue(n.mapping.get(e),t))f=!0;else if(!$e(e,t,n))break}for(;c+a<l;a++){const e=o[r-a-1],t=s[i-a-1];if(e instanceof A)break;if(Ue(n.mapping.get(e),t))f=!0;else if(!$e(e,t,n))break}return{equalityFactor:c+a,foundMappedChild:f}},Re=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:o,str:r}=(e=>{let t="",n=e._start;const o={};for(;null!==n;)n.deleted||(n.countable&&n.content instanceof j?t+=n.content.str:n.content instanceof z&&(o[n.content.key]=null)),n=n.right;return{nAttrs:o,str:t}})(e),l=t.map((e,t)=>{const s=e.getType();let i=Je(e,n);return 0===Object.keys(i).length&&(i=null),{attributes:Object.assign({},o,{...s!==y.getType()&&{t:s},p:i,...Qe(e),...t>0&&{i:t}}),insert:e.getTextContent(),nodeKey:e.getKey()}}),c=l.map(e=>e.insert).join(""),a=s();let f;if(i(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:d,remove:u,index:h}=X(r,c,f);e.delete(h,u),e.insert(h,d),e.applyDelta(l.map(e=>({attributes:e.attributes,retain:e.insert.length})))},qe=(e,t,n,o)=>e.toDelta(t,n,o).map(e=>{const t=e.attributes??{};return"ychange"in t&&(t[Ve("ychange")]=t.ychange,delete t.ychange),{...e,attributes:t}}),Je=(e,t)=>{const n=ye(e,t),o={};return Object.entries(n).forEach(([t,n])=>{const s=e[t];s!==n&&(o[t]=s)}),o},Ge="s_",Ve=e=>`s_${e}`,He=e=>{if(!e.startsWith(Ge))throw new Error(`Invalid state key: ${e}`);return e.slice(Ge.length)},Qe=e=>{const t=e.__state;if(!t)return{};const[n={},o]=t.getInternalState(),s={};for(const[e,t]of Object.entries(n))s[Ve(e)]=t;for(const[e,t]of o)s[Ve(e.key)]=e.unparse(t);return s},Xe=(e,t,n,o,s)=>{if(t instanceof O&&t.nodeName!==n.getType()&&(!Ee(t)||n.getType()!==g.getType()))throw new Error("node name mismatch!");if(o.mapping.set(t,n),t instanceof O){const e=t.getAttributes(),s={...Je(n,o),...Qe(n)};for(const n in s)if(null!=s[n]){e[n]===s[n]||De(e[n])&&De(s[n])&&Ye(e[n],s[n])||"ychange"===n||t.setAttribute(n,s[n])}else t.removeAttribute(n);for(const n in e)void 0===s[n]&&t.removeAttribute(n)}const i=Ie(n),r=i.length,l=t.toArray(),c=l.length,a=Math.min(r,c);let f=0,d=0;for(;f<a;f++){const t=l[f],n=i[f];if(t instanceof A)break;if(Ue(o.mapping.get(t),n))n instanceof _&&s.has(n.getKey())&&Xe(e,t,n,o,s);else{if(!$e(t,n,o))break;o.mapping.set(t,n)}}for(;d+f<a;d++){const t=l[c-d-1],n=i[r-d-1];if(t instanceof A)break;if(Ue(o.mapping.get(t),n))n instanceof _&&s.has(n.getKey())&&Xe(e,t,n,o,s);else{if(!$e(t,n,o))break;o.mapping.set(t,n)}}for(;c-f-d>0&&r-f-d>0;){const n=l[f],a=i[f],u=l[c-d-1],h=i[r-d-1];if(n instanceof C&&a instanceof Array)We(n,a,o)||Re(n,a,o),f+=1;else{let i=n instanceof O&&Ze(n,a),r=u instanceof O&&Ze(u,h);if(i&&r){const e=Be(n,a,o),t=Be(u,h,o);e.foundMappedChild&&!t.foundMappedChild?r=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor<t.equalityFactor?i=!1:r=!1}i?(Xe(e,n,a,o,s),f+=1):r?(Xe(e,u,h,o,s),d+=1):(o.mapping.delete(t.get(f)),t.delete(f,1),t.insert(f,[Le(a,o)]),f+=1)}}const u=c-f-d;if(1===c&&0===r&&l[0]instanceof C?(o.mapping.delete(l[0]),l[0].delete(0,l[0].length)):u>0&&(t.slice(f,f+u).forEach(e=>o.mapping.delete(e)),t.delete(f,u)),f+d<r){const e=[];for(let t=f;t<r-d;t++)e.push(Le(i[t],o));t.insert(f,e)}},Ze=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType(),et=x("ychange",{isEqual:(e,t)=>e===t,parse:e=>e??null});function tt(e){return m(e,et)}const nt=(e,t=I(e.doc),n=L)=>{const{doc:o}=e;o.gc&&Q(325),o.transact(s=>{const i=new D(o);i&&i.dss.forEach(e=>{Y(s,e,e=>{})});const r=(e,t)=>({id:t,type:e,user:("added"===e?i.getUserByClientId(t.client):i.getUserByDeletedId(t))??null});e.mapping.clear(),e.editor.update(()=>{p().clear(),Fe(e.root,e,null,!0,t,n,r)})},e)};function ot(e,t){const n=t.collabNodeMap.get(e.key);if(void 0===n)return null;let s=e.offset,i=n.getSharedType();if(n instanceof oe){i=n._parent._xmlText;const e=n.getOffset();if(-1===e)return null;s=e+1+s}else if(n instanceof ie&&"element"===e.type){const t=e.getNode();r(t)||Q(184);let n=0,i=0,l=t.getFirstChild();for(;null!==l&&i++<s;)o(l)?n+=l.getTextContentSize()+1:n++,l=l.getNextSibling();s=n}return $(i,s)}function st(e,t){const{mapping:n}=t,{offset:s}=e,i=e.getNode(),l=n.getSharedType(i);if(void 0===l)return null;if("text"===e.type){o(i)||Q(326);let e=i.getPreviousSibling(),t=s;for(;o(e);)t+=e.getTextContentSize(),e=e.getPreviousSibling();return $(l,t)}if("element"===e.type){r(i)||Q(184);let e=0,t=i.getFirstChild();for(;null!==t&&e<s;){if(o(t)){let e=t.getNextSibling();for(;o(e);)e=e.getNextSibling()}e++,t=t.getNextSibling()}return $(l,e)}return null}function it(e,t){return W(e,t.doc)}function rt(e,t){if(null==e){if(null!=t)return!0}else if(null==t||!U(e,t))return!0;return!1}function lt(e,t){return{color:t,name:e,selection:null}}function ct(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 at(e,t){const n=t.selection;null!==n&&ct(e,n)}function ft(e,t,n,o,s,i={}){const r=e.color,l=document.createElement("span");i.cursor?(l.className=i.cursor,b(l.style,{"--lexical-cursor-color":r,bottom:"0",position:"absolute",right:"-1px",top:"0"})):b(l.style,{"background-color":r,bottom:"0",position:"absolute",right:"-1px",top:"0",width:"1px","z-index":"10"});const c=document.createElement("span");return c.textContent=e.name,i.cursorName?c.className=i.cursorName:b(c.style,{"background-color":r,color:"#fff","font-family":"Arial","font-size":"12px","font-weight":"bold",left:"-2px","line-height":"12px",padding:"2px",position:"absolute",top:"-16px","white-space":"nowrap"}),l.appendChild(c),{anchor:{key:t,offset:n},caret:l,color:r,focus:{key:o,offset:s},name:c,selections:[]}}function dt(e,t,o,s,i={}){const r=e.editor,l=r.getRootElement(),c=e.cursorsContainer;if(null===c||null===l)return;const a=c.offsetParent;if(null===a)return;const f=a.getBoundingClientRect(),d=t.selection;if(null===o)return null===d?void 0:(t.selection=null,void ct(e,d));t.selection=o;const u=o.caret,h=o.color,p=o.selections,g=o.anchor,_=o.focus,y=g.key,m=_.key,x=s.get(y),T=s.get(m);if(null==x||null==T)return;let k;if(x===T&&n(x)){k=[r.getElementByKey(y).getBoundingClientRect()]}else{const e=V(r,x,g.offset,T,_.offset);if(null===e)return;k=H(r,e)}const N=p.length,S=k.length;for(let e=0;e<S;e++){const t=k[e];let n=p[e];if(void 0===n){n=document.createElement("span"),p[e]=n;const t=document.createElement("span");i.selectionBg&&(t.className=i.selectionBg),n.appendChild(t),c.appendChild(n)}const o=t.top-f.top,s=t.left-f.left,r={height:`${t.height}px`,left:`${s}px`,"pointer-events":"none",position:"absolute",top:`${o}px`,width:`${t.width}px`};i.selection?(n.className=i.selection,b(n.style,{...r,"--lexical-cursor-color":h}),b(n.firstChild.style,{height:"100%",left:"0",position:"absolute",top:"0",width:"100%"})):(b(n.style,r),b(n.firstChild.style,{...r,"background-color":h,left:"0",opacity:"0.3",top:"0","z-index":"5"})),e===S-1&&u.parentNode!==n&&n.appendChild(u)}for(let e=N-1;e>=S;e--){const t=p[e];c.removeChild(t),p.pop()}}function ut(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,i=0,r=null,l=0;if(null!==n&&null!==o){const t=it(n,e),c=it(o,e);null!==t&&null!==c&&([s,i]=_t(t.type,t.index),[r,l]=_t(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:i,focusCollabNode:r,focusOffset:l}}function ht(e,t){const{anchorPos:n,focusPos:s}=t,i=n?it(n,e):null,r=s?it(s,e):null;if(null===i||null===r)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(de(e)){const[e,t]=_t(i.type,i.index),[n,o]=_t(r.type,r.index);return{anchorKey:null!==e?e.getKey():null,anchorOffset:t,focusKey:null!==n?n.getKey():null,focusOffset:o}}let[l,c]=yt(e.mapping,i),[a,f]=yt(e.mapping,r);if(a&&l&&(a!==l||f!==c)){const e=a.isBefore(l),t=e?a:l,n=e?f:c;o(t)&&o(t.getNextSibling())&&n===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 pt(e,t){const n=t.awareness.getLocalState();if(null===n)return;const{anchorKey:o,anchorOffset:r,focusKey:l,focusOffset:c}=ht(e,n);if(null!==o&&null!==l){const e=s();if(!i(e))return;gt(e.anchor,o,r),gt(e.focus,l,c)}}function gt(e,n,s){if(e.key!==n||e.offset!==s){let i=t(n);if(null!==i&&!r(i)&&!o(i)){const e=i.getParentOrThrow();n=e.getKey(),s=i.getIndexWithinParent(),i=e}e.set(n,s,r(i)?"element":"text")}}function _t(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof ie){const{node:e,offset:o}=Oe(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function yt(e,t){const n=t.type,s=t.index;if(n instanceof O){const t=e.get(n);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,o(e))for(;l<c.length&&o(c[l]);)l+=1}return[t,l]}{const t=e.get(n);if(void 0===t)return[null,0];let o=0,i=s;for(;i>t[o].getTextContentSize()&&o+1<t.length;)i-=t[o].getTextContentSize(),o++;const r=t[o];return[r,Math.min(i,r.getTextContentSize())]}}function mt(e,t){return t.awareness.getStates()}function xt(e,t,n){const{getAwarenessStates:o=mt}=n??{},s=Array.from(o(e,t)),i=e.clientID,r=e.cursors,l=e.editor,c=l._config.theme.collaboration,a=l._editorState._nodeMap,f=new Set;for(let t=0;t<s.length;t++){const n=s[t],[o,d]=n;if(0!==o&&o!==i){f.add(o);const{name:t,color:n,focusing:s}=d;let i=null,u=r.get(o);if(void 0===u&&(u=lt(t,n),r.set(o,u)),s){const{anchorKey:t,anchorOffset:n,focusKey:o,focusOffset:s}=l.read(()=>ht(e,d));if(null!==t&&null!==o)if(i=u.selection,null===i)i=ft(u,t,n,o,s,c);else{const e=i.anchor,r=i.focus;e.key=t,e.offset=n,r.key=o,r.offset=s}}dt(e,u,i,a,c)}}const d=Array.from(r.keys());for(let t=0;t<d.length;t++){const n=d[t];if(!f.has(n)){const t=r.get(n);void 0!==t&&(at(e,t),r.delete(n))}}}function bt(e,t,n,o){const s=t.awareness,r=s.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!==o&&(null===l||o.is(n))||null!==n)&&(i(o)&&(de(e)?(h=ot(o.anchor,e),p=ot(o.focus,e)):(h=st(o.anchor,e),p=st(o.focus,e))),(rt(l,h)||rt(c,p))&&s.setLocalState({...r,anchorPos:h,awarenessData:u,color:f,focusPos:p,focusing:d,name:a}))}function Tt(e,t){if(t instanceof R&&function(e,t){const{target:n}=t;if(!n._item||"__state"!==n._item.parentSub||void 0!==xe(n)||!(n.parent instanceof C||n.parent instanceof O||n.parent instanceof K))return!1;const o=be(e,n.parent).getNode();if(o){const e=h(o.getWritable());for(const o of t.keysChanged)e.updateFromUnknown(o,n.get(o))}return!0}(e,t))return;const{target:n}=t,o=be(e,n);if(o instanceof ie&&t instanceof q){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 oe&&t instanceof R){const{keysChanged:n}=t;n.size>0&&o.syncPropertiesAndTextFromYjs(e,n)}else if(o instanceof Z&&t instanceof J){const{attributesChanged:n}=t;n.size>0&&o.syncPropertiesFromYjs(e,n)}else Q(82)}function kt(e,t,n,o,s=xt){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];Tt(e,o)}Nt(r,e,t),o||N(S)},{onUpdate:()=>{s(e,t),i.update(()=>St())},skipTransforms:!0,tag:o?k:T})}function Nt(e,t,n){const o=s();if(i(o))if(Ke(o)){const r=e._selection;if(i(r)&&(pt(t,n),Ke(o))){Pe(o.anchor.key,e)}bt(t,n,r,s())}else pt(t,n)}function St(){0===p().getChildrenSize()&&p().append(v())}function vt(e,n,i,r,l,c,a,f){Me(e,()=>{r.read(()=>{if(f.has(T)||f.has(k))return void(a.size>0&&function(e,n){const s=Array.from(n),i=e.collabNodeMap,r=[],l=[];for(let e=0;e<s.length;e++){const n=s[e],c=t(n),a=i.get(n);if(a instanceof oe)if(o(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}}(e,a));if(l.has("root")){const t=i._nodeMap,n=p(),o=e.root;o.syncPropertiesFromLexical(e,n,t),o.syncChildrenFromLexical(e,n,t,l,c)}const r=s(),d=i._selection;bt(e,n,d,r)})})}function wt(e,t){const{target:n}=t;if(n instanceof O&&t instanceof J)Fe(n,e,t.attributesChanged,t.childListChanged);else if(n instanceof C&&t instanceof q){const t=n.parent;t instanceof O?Fe(t,e,new Set,!0):Q(327)}else Q(328)}function Ct(e,t,n,o,s){const i=e.editor,r=i._editorState;Y(o,o.deleteSet,t=>{if(t.constructor===B){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];wt(e,o)}Nt(r,e,t),s||N(S)},{discrete:!0,onUpdate:()=>{xt(e,t),i.update(()=>St())},skipTransforms:!0,tag:s?k:T})}function Ot(e,t){e.mapping.clear();const n=e.editor;n.update(()=>{p().clear(),Fe(e.root,e,null,!0),N(T)},{discrete:!0,onUpdate:()=>{xt(e,t),n.update(()=>St())},skipTransforms:!0,tag:T})}function Kt(e,t,n,o,i,r,l){(l.has(T)||l.has(k))&&0===r.size||(r.forEach(t=>{e.mapping.deleteNode(t)}),Me(e,()=>{o.read(()=>{i.has("root")&&Xe(e.doc,e.root,p(),e,new Set(i.keys()));const o=s(),r=n._selection;bt(e,t,r,o)})}))}const Mt=w("CONNECTED_COMMAND"),Pt=w("TOGGLE_CONNECT_COMMAND"),Et=w("DIFF_VERSIONS_COMMAND"),Ft=w("CLEAR_DIFF_VERSIONS_COMMAND");function At(e,t){return new G(t,{trackedOrigins:new Set([e,null])})}function jt(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})}function zt(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{tt as $getYChangeState,Ft as CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL,Mt as CONNECTED_COMMAND,Et as DIFF_VERSIONS_COMMAND__EXPERIMENTAL,Pt as TOGGLE_CONNECT_COMMAND,ae as createBinding,fe as createBindingV2__EXPERIMENTAL,At as createUndoManager,ut as getAnchorAndFocusCollabNodesForUserState,jt as initLocalState,nt as renderSnapshot__EXPERIMENTAL,zt as setLocalStateFocus,xt as syncCursorPositions,vt as syncLexicalUpdateToYjs,Kt as syncLexicalUpdateToYjsV2__EXPERIMENTAL,kt as syncYjsChangesToLexical,Ct as syncYjsChangesToLexicalV2__EXPERIMENTAL,Ot as syncYjsStateToLexicalV2__EXPERIMENTAL};
9
+ import{$isDecoratorNode as e,$getNodeByKey as t,$isLineBreakNode as n,$isTextNode as o,$getSelection as s,$isRangeSelection as i,$isElementNode as r,$createChildrenArray as l,$getNodeByKeyOrThrow as c,removeFromParent as a,isLexicalEditor as f,createEditor as u,$isRootNode as d,$getWritableNodeState as h,$getRoot as p,RootNode as g,ElementNode as _,TextNode as y,$getState as m,createState as x,setDOMStyleObject as b,COLLABORATION_TAG as T,HISTORIC_TAG as k,$addUpdateTag as N,SKIP_SCROLL_INTO_VIEW_TAG as S,$createParagraphNode as v,createCommand as w}from"lexical";import{XmlText as C,XmlElement as O,Map as K,Doc as M,typeListToArraySnapshot as P,Snapshot as E,isDeleted as F,XmlHook as A,ContentString as j,ContentFormat as z,emptySnapshot as L,PermanentUserData as D,iterateDeletedStructs as Y,snapshot as I,createAbsolutePositionFromRelativePosition as W,createRelativePositionFromTypeIndex as $,compareRelativePositions as U,Item as B,YMapEvent as R,YTextEvent as q,YXmlEvent as J,UndoManager as G}from"yjs";import{createDOMRange as V,createRectsFromDOMRange as H}from"@lexical/selection";function Q(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.`)}function X(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 Z{_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(n)?n:null}getNode(){const n=t(this._key);return e(n)?n: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);we(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&Q(83);ke(e,this._xmlElem,n,t)}destroy(e){const t=e.collabNodeMap;t.get(this._key)===this&&t.delete(this._key)}}function ee(e,t,n){const o=new Z(e,t,n);return e._collabNode=o,o}class te{_map;_key;_parent;_type;constructor(e,t){this._key="",this._map=e,this._parent=t,this._type="linebreak"}getNode(){const e=t(this._key);return n(e)?e: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 ne(e,t){const n=new te(e,t);return e._collabNode=n,n}class oe{_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 o(t)?t:null}getNode(){const e=t(this._key);return o(e)?e: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 o=this.getPrevNode(n),r=t.__text;if(we(e,this._map,o,t),null!==o){const e=o.__text;if(e!==r){!function(e,t,n,o){const r=s();let l=o.length;if(i(r)&&r.isCollapsed()){const e=r.anchor;e.key===t&&(l=e.offset)}const c=X(n,o,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&&Q(84),ke(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 se(e,t,n,o){const s=new oe(e,t,n,o);return e._collabNode=s,s}class ie{_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 e=t(this._key);return r(e)?e: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&&Q(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null===n&&Q(91),ke(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}=Oe(this,o,!1);if(t instanceof ie||t instanceof te||t instanceof Z)n.splice(s,1),e-=1;else{if(!(t instanceof oe))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 oe?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}=Oe(this,o,!0);e instanceof oe?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}=Oe(this,o,!1),a=be(e,t,this);if(i instanceof oe&&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 oe&&(a._text=s+a._text,s=null),o+=1}}}}syncChildrenFromYjs(e){const t=this.getNode();null===t&&Q(92);const n=t.__key,s=l(t,null),i=s.length,r=this._children,f=r.length,u=e.collabNodeMap,d=new Set;let h,p,g=0,_=null;f!==i&&(p=t.getWritable());for(let i=0;i<f;i++){const l=s[g],y=r[i],m=y.getNode(),x=y._key;if(null!==m&&l===x){const t=o(m);if(d.add(l),t)if(y._key=l,y instanceof ie){const t=y._xmlText;y.syncPropertiesFromYjs(e,null),y.applyChildrenYjsDelta(e,t.toDelta()),y.syncChildrenFromYjs(e)}else y instanceof oe?y.syncPropertiesAndTextFromYjs(e,null):y instanceof Z?y.syncPropertiesFromYjs(e,null):y instanceof te||Q(93);_=m,g++}else{if(void 0===h){h=new Set;for(let e=0;e<f;e++){const t=r[e]._key;""!==t&&h.add(t)}}if(null!==m&&void 0!==l&&!h.has(l)){const e=c(l);a(e),i--,g++;continue}p=t.getWritable();const o=Te(e,y,n),s=o.__key;if(u.set(s,y),null===_){const e=p.getFirstChild();if(p.__first=s,null!==e){const t=e.getWritable();t.__prev=s,o.__next=t.__key}}else{const e=_.getWritable(),t=_.getNextSibling();if(e.__next=s,o.__prev=_.__key,null!==t){const e=t.getWritable();e.__prev=s,o.__next=e.__key}}i===f-1&&(p.__last=s),p.__size++,_=o}}for(let t=0;t<i;t++){const n=s[t];if(!d.has(n)){const t=c(n),o=e.collabNodeMap.get(n);void 0!==o&&o.destroy(e),a(t)}}}syncPropertiesFromLexical(e,t,n){we(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(t,n,s,i,l,a){const f=this._children[n],u=c(s);f instanceof ie&&r(u)?(f.syncPropertiesFromLexical(t,u,i),f.syncChildrenFromLexical(t,u,i,l,a)):f instanceof oe&&o(u)?f.syncPropertiesAndTextFromLexical(t,u,i):f instanceof Z&&e(u)&&f.syncPropertiesFromLexical(t,u,i)}syncChildrenFromLexical(e,t,n,o,s){const i=this.getPrevNode(n),r=null===i?[]:l(i,n),a=l(t,null),f=r.length-1,u=a.length-1,d=e.collabNodeMap;let h,p,g=0,_=0;for(;g<=f&&_<=u;){const t=r[g],i=a[_];if(t===i)this._syncChildFromLexical(e,_,i,n,o,s),g++,_++;else{void 0===h&&(h=new Set(r)),void 0===p&&(p=new Set(a));const n=p.has(t),o=h.has(i);if(n){const t=me(e,c(i),this);d.set(i,t),o?(this.splice(e,_,1,t),g++,_++):(this.splice(e,_,0,t),_++)}else this.splice(e,_,1),g++}}const y=g>f,m=_>u;if(y&&!m)for(;_<=u;++_){const t=a[_],n=me(e,c(t),this);this.append(n),d.set(t,n)}else if(m&&!y)for(let t=this._children.length-1;t>=_;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 ie)t.insertEmbed(s,e._xmlText);else if(e instanceof oe){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof te?t.insertEmbed(s,e._map):e instanceof Z&&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&&Q(94),void this.append(o);const r=i.getOffset();-1===r&&Q(95);const l=this._xmlText;if(0!==n&&l.delete(r,i.getSize()),o instanceof ie)l.insertEmbed(r,o._xmlText);else if(o instanceof oe){const e=o._map;null===e.parent&&l.insertEmbed(r,e),l.insert(r+1,o._text)}else o instanceof te?l.insertEmbed(r,o._map):o instanceof Z&&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 re(e,t,n){const o=new ie(e,t,n);return e._collabNode=o,o}class le{_nodeMap=new Map;_sharedTypeToNodeKeys=new Map;_nodeKeyToSharedType=new Map;set(e,t){const n=t instanceof Array;this.delete(e);const s=n?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 C){if(n||Q(331),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 n&&Q(332),o(t)&&Q(333),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 C){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)}clear(){this._nodeMap.clear(),this._sharedTypeToNodeKeys.clear(),this._nodeKeyToSharedType.clear()}}function ce(e,t,n,o,s){null==n&&Q(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))_e(t,o,e)||(s[t]=n);n.set(o.__type,Object.freeze(s))})})}(i),i}function ae(e,t,n,o,s,i){null==o&&Q(81);const r=re(o.get("root",C),null,"root");return r._key="root",{...ce(e,n,o,s,i),collabNodeMap:new Map,root:r}}function fe(e,t,n,o,s={}){null==n&&Q(81);const{excludedProperties:i,rootName:r="root-v2"}=s;return{...ce(e,t,n,o,i),mapping:new le,root:n.get(r,O)}}function ue(e){return Object.prototype.hasOwnProperty.call(e,"collabNodeMap")}const de=new Set(["__key","__parent","__next","__prev","__state"]),he=new Set(["__first","__last","__size"]),pe=new Set(["__cachedText"]),ge=new Set(["__text"]);function _e(e,t,n){if(de.has(e)||"function"==typeof t[e])return!0;if(o(t)){if(ge.has(e))return!0}else if(r(t)&&(he.has(e)||d(t)&&pe.has(e)))return!0;const s=t.constructor,i=n.excludedProperties.get(s);return null!=i&&i.has(e)}function ye(e,t){const n=e.__type,{nodeProperties:o}=t,s=o.get(n);return void 0===s&&Q(330,n),s}function me(t,s,i){const l=s.__type;let c;if(r(s)){c=re(new C,i,l),c.syncPropertiesFromLexical(t,s,null),c.syncChildrenFromLexical(t,s,null,null,null)}else if(o(s)){c=se(new K,s.__text,i,l),c.syncPropertiesAndTextFromLexical(t,s,null)}else if(n(s)){const e=new K;e.set("__type","linebreak"),c=ne(e,i)}else if(e(s)){c=ee(new O,i,l),c.syncPropertiesFromLexical(t,s,null)}else Q(86);return c._key=s.__key,c}function xe(e){const t=Ne(e,"__type");return"string"!=typeof t&&void 0!==t&&Q(87),t}function be(e,t,n){const o=t._collabNode;if(void 0===o){const o=e.editor._nodes,s=xe(t);"string"!=typeof s&&Q(87);void 0===o.get(s)&&Q(88,s);const i=t.parent,r=void 0===n&&null!==i?be(e,i):n||null;if(r instanceof ie||Q(89),t instanceof C)return re(t,r,s);if(t instanceof K)return"linebreak"===s?ne(t,r):se(t,"",r,s);if(t instanceof O)return ee(t,r,s)}return o}function Te(e,t,n){const o=t.getType(),s=e.editor._nodes.get(o);void 0===s&&Q(88,o);const i=new s.klass;if(i.__parent=n,t._key=i.__key,t instanceof ie){const n=t._xmlText;t.syncPropertiesFromYjs(e,null),t.applyChildrenYjsDelta(e,n.toDelta()),t.syncChildrenFromYjs(e)}else t instanceof oe?t.syncPropertiesAndTextFromYjs(e,null):t instanceof Z&&t.syncPropertiesFromYjs(e,null);return e.collabNodeMap.set(i.__key,t),i}function ke(e,t,n,o){const s=null===o?t instanceof K?Array.from(t.keys()):t instanceof C||t instanceof O?Object.keys(t.getAttributes()):Object.keys(t):Array.from(o);let i;for(let o=0;o<s.length;o++){const r=s[o];if(_e(r,n,e)){"__state"===r&&ue(e)&&(i||(i=n.getWritable()),ve(t,i));continue}const l=n[r];let c=Ne(t,r);if(l!==c){if(c instanceof M){const t=e.docMap;l instanceof M&&t.delete(l.guid);const n=c.guid;if(t.set(n,c),f(l))l._key=n,c=l;else{const e=u();e._key=n,c=e}}void 0===i&&(i=n.getWritable()),i[r]=c}}}function Ne(e,t){return e instanceof K?e.get(t):e instanceof C||e instanceof O?e.getAttribute(t):e[t]}function Se(e,t,n){e instanceof K?e.set(t,n):e.setAttribute(t,n)}function ve(e,t){const n=Ne(e,"__state");n instanceof K&&h(t).updateFromJSON(n.toJSON())}function we(e,t,n,o){const s=Object.keys(ye(o,e)),i=e.editor.constructor;!function(e,t,n,o){const s=o.__state,i=null===t.doc?void 0:Ne(t,"__state");if(!s)return;const[r,l]=s.getInternalState(),c=n&&n.__state,a=i instanceof K?i:new K;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||Se(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 M,r=s.guid;a._key=r,t.set(r,s),a=s,e.editor.update(()=>{o.markDirty()})}Se(t,l,a)}}}function Ce(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function Oe(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 oe){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 Ke(e){const t=e.anchor,n=e.focus;let s=!1;try{const e=t.getNode(),i=n.getNode();(!e.isAttached()||!i.isAttached()||o(e)&&t.offset>e.getTextContentSize()||o(i)&&n.offset>i.getTextContentSize())&&(s=!0)}catch(e){s=!0}return s}function Me(e,t){e.doc.transact(t,e)}function Pe(e,n){const o=n._nodeMap.get(e);if(!o)return void p().selectStart();const s=o.__prev;let i=null;s&&(i=t(s)),null===i&&null!==o.__parent&&(i=t(o.__parent)),null!==i?null!==i&&i.isAttached()?i.selectEnd():Pe(i.__key,n):p().selectStart()}const Ee=e=>"UNDEFINED"===e.nodeName,Fe=(e,t,n,o,s,i,r)=>{let l=t.mapping.get(e);if(l&&n&&0===n.size&&!o)return l;const c=Ee(e)?g.getType():e.nodeName,a=t.editor._nodes.get(c);if(void 0===a)throw new Error(`$createOrUpdateNodeFromYElement: Node ${c} is not registered`);if(l||(l=new a.klass,n=null,o=!0),o&&l instanceof _){const n=[],o=e=>{if(e instanceof O){const o=Fe(e,t,new Set,!1,s,i,r);null!==o&&n.push(o)}else if(e instanceof C){const o=ze(e,t,s,i,r);null!==o&&o.forEach(e=>{null!==e&&n.push(e)})}else Q(329)};void 0===s||void 0===i?e.toArray().forEach(o):P(e,new E(i.ds,s.sv)).filter(e=>!e._item.deleted||je(e._item,s)||je(e._item,i)).forEach(o),Ae(l,n)}const f=e.getAttributes(s);Ee(e)||void 0===s||(je(e._item,s)?je(e._item,i)||(f[Ve("ychange")]=r?r("added",e._item.id):{type:"added"}):f[Ve("ychange")]=r?r("removed",e._item.id):{type:"removed"});const u={...ye(l,t)},d={};for(const e in f)e.startsWith(Ge)?d[He(e)]=f[e]:"__proto__"!==e&&"constructor"!==e&&"prototype"!==e&&(u[e]=f[e]);if(ke(t,u,l,n),n){if(n.size>0){const e=h(l);for(const t of n)if(t.startsWith(Ge)){const n=He(t);e.updateFromUnknown(n,d[n])}}}else h(l).updateFromJSON(d);const p=l.getLatest();return t.mapping.set(e,p),p},Ae=(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,[])},je=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!F(t.ds,e.id),ze=(e,t,n,s,i)=>{const r=qe(e,n,s,i);let l=t.mapping.get(e)??[];const c=r.map(e=>e.attributes.t??y.getType());if(!(l.length===c.length&&l.every((e,t)=>e.getType()===c[t]))){const e=t.editor._nodes;l=c.map(t=>{const n=e.get(t);if(void 0===n)throw new Error(`$createTextNodesFromYText: Node ${t} is not registered`);const s=new n.klass;if(!o(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={...ye(n,t),...s.p},a=Object.fromEntries(Object.entries(s).filter(([e])=>e.startsWith(Ge)).map(([e,t])=>[He(e),t]));ke(t,c,n,null),h(n).updateFromJSON(a)}const a=l.map(e=>e.getLatest());return t.mapping.set(e,a),a},Le=(e,t)=>e instanceof Array?((e,t)=>{const n=new C;return Re(n,e,t),n})(e,t):((e,t)=>{const n=new O(e.getType()),o={...Je(e,t),...Qe(e)};for(const e in o){const t=o[e];null!==t&&n.setAttribute(e,t)}return e instanceof _?(n.insert(0,Ie(e).map(e=>Le(e,t))),t.mapping.set(n,e),n):n})(e,t),De=e=>"object"==typeof e&&null!=e,Ye=(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||De(r)&&De(l)&&Ye(r,l)}return o},Ie=e=>{if(!(e instanceof _))return[];const t=e.getChildren(),n=[];for(let e=0;e<t.length;e++){const s=t[e];if(o(s)){const s=[];for(let n=t[e];e<t.length&&o(n);n=t[++e])s.push(n);e--,n.push(s)}else n.push(s)}return n},We=(e,t,n)=>{const o=qe(e);return o.length===t.length&&o.every((e,o)=>{const s=t[o],i=e.attributes.t??y.getType(),r=e.attributes.p??{},l=Object.fromEntries(Object.entries(e.attributes).filter(([e])=>e.startsWith(Ge)));return e.insert===s.getTextContent()&&i===s.getType()&&Ye(r,Je(s,n))&&Ye(l,Qe(s))})},$e=(e,t,n)=>{if(e instanceof O&&!(t instanceof Array)&&Ze(e,t)){const o=Ie(t);return e._length===o.length&&Ye(e.getAttributes(),{...Je(t,n),...Qe(t)})&&e.toArray().every((e,t)=>$e(e,o[t],n))}return e instanceof C&&t instanceof Array&&We(e,t,n)},Ue=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),Be=(e,t,n)=>{const o=e.toArray(),s=Ie(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 A)break;if(Ue(n.mapping.get(e),t))f=!0;else if(!$e(e,t,n))break}for(;c+a<l;a++){const e=o[r-a-1],t=s[i-a-1];if(e instanceof A)break;if(Ue(n.mapping.get(e),t))f=!0;else if(!$e(e,t,n))break}return{equalityFactor:c+a,foundMappedChild:f}},Re=(e,t,n)=>{n.mapping.set(e,t);const{nAttrs:o,str:r}=(e=>{let t="",n=e._start;const o={};for(;null!==n;)n.deleted||(n.countable&&n.content instanceof j?t+=n.content.str:n.content instanceof z&&(o[n.content.key]=null)),n=n.right;return{nAttrs:o,str:t}})(e),l=t.map((e,t)=>{const s=e.getType();let i=Je(e,n);return 0===Object.keys(i).length&&(i=null),{attributes:Object.assign({},o,{...s!==y.getType()&&{t:s},p:i,...Qe(e),...t>0&&{i:t}}),insert:e.getTextContent(),nodeKey:e.getKey()}}),c=l.map(e=>e.insert).join(""),a=s();let f;if(i(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}=X(r,c,f);e.delete(h,d),e.insert(h,u),e.applyDelta(l.map(e=>({attributes:e.attributes,retain:e.insert.length})))},qe=(e,t,n,o)=>e.toDelta(t,n,o).map(e=>{const t=e.attributes??{};return"ychange"in t&&(t[Ve("ychange")]=t.ychange,delete t.ychange),{...e,attributes:t}}),Je=(e,t)=>{const n=ye(e,t),o={};return Object.entries(n).forEach(([t,n])=>{const s=e[t];s!==n&&(o[t]=s)}),o},Ge="s_",Ve=e=>`s_${e}`,He=e=>{if(!e.startsWith(Ge))throw new Error(`Invalid state key: ${e}`);return e.slice(Ge.length)},Qe=e=>{const t=e.__state;if(!t)return{};const[n={},o]=t.getInternalState(),s={};for(const[e,t]of Object.entries(n))s[Ve(e)]=t;for(const[e,t]of o)s[Ve(e.key)]=e.unparse(t);return s},Xe=(e,t,n,o,s)=>{if(t instanceof O&&t.nodeName!==n.getType()&&(!Ee(t)||n.getType()!==g.getType()))throw new Error("node name mismatch!");if(o.mapping.set(t,n),t instanceof O){const e=t.getAttributes(),s={...Je(n,o),...Qe(n)};for(const n in s)if(null!=s[n]){e[n]===s[n]||De(e[n])&&De(s[n])&&Ye(e[n],s[n])||"ychange"===n||t.setAttribute(n,s[n])}else t.removeAttribute(n);for(const n in e)void 0===s[n]&&t.removeAttribute(n)}const i=Ie(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 A)break;if(Ue(o.mapping.get(t),n))n instanceof _&&s.has(n.getKey())&&Xe(e,t,n,o,s);else{if(!$e(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 A)break;if(Ue(o.mapping.get(t),n))n instanceof _&&s.has(n.getKey())&&Xe(e,t,n,o,s);else{if(!$e(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 C&&a instanceof Array)We(n,a,o)||Re(n,a,o),f+=1;else{let i=n instanceof O&&Ze(n,a),r=d instanceof O&&Ze(d,h);if(i&&r){const e=Be(n,a,o),t=Be(d,h,o);e.foundMappedChild&&!t.foundMappedChild?r=!1:!e.foundMappedChild&&t.foundMappedChild||e.equalityFactor<t.equalityFactor?i=!1:r=!1}i?(Xe(e,n,a,o,s),f+=1):r?(Xe(e,d,h,o,s),u+=1):(o.mapping.delete(t.get(f)),t.delete(f,1),t.insert(f,[Le(a,o)]),f+=1)}}const d=c-f-u;if(1===c&&0===r&&l[0]instanceof C?(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(Le(i[t],o));t.insert(f,e)}},Ze=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType(),et=x("ychange",{isEqual:(e,t)=>e===t,parse:e=>e??null});function tt(e){return m(e,et)}const nt=(e,t=I(e.doc),n=L)=>{const{doc:o}=e;o.gc&&Q(325),o.transact(s=>{const i=new D(o);i&&i.dss.forEach(e=>{Y(s,e,e=>{})});const r=(e,t)=>({id:t,type:e,user:("added"===e?i.getUserByClientId(t.client):i.getUserByDeletedId(t))??null});e.mapping.clear(),e.editor.update(()=>{p().clear(),Fe(e.root,e,null,!0,t,n,r)})},e)};function ot(e,t){const n=t.collabNodeMap.get(e.key);if(void 0===n)return null;let s=e.offset,i=n.getSharedType();if(n instanceof oe){i=n._parent._xmlText;const e=n.getOffset();if(-1===e)return null;s=e+1+s}else if(n instanceof ie&&"element"===e.type){const t=e.getNode();r(t)||Q(184);let n=0,i=0,l=t.getFirstChild();for(;null!==l&&i++<s;)o(l)?n+=l.getTextContentSize()+1:n++,l=l.getNextSibling();s=n}return $(i,s)}function st(e,t){const{mapping:n}=t,{offset:s}=e,i=e.getNode(),l=n.getSharedType(i);if(void 0===l)return null;if("text"===e.type){o(i)||Q(326);let e=i.getPreviousSibling(),t=s;for(;o(e);)t+=e.getTextContentSize(),e=e.getPreviousSibling();return $(l,t)}if("element"===e.type){r(i)||Q(184);let e=0,t=i.getFirstChild();for(;null!==t&&e<s;){if(o(t)){let e=t.getNextSibling();for(;o(e);)e=e.getNextSibling()}e++,t=t.getNextSibling()}return $(l,e)}return null}function it(e,t){return W(e,t.doc)}function rt(e,t){if(null==e){if(null!=t)return!0}else if(null==t||!U(e,t))return!0;return!1}function lt(e,t){return{color:t,name:e,selection:null}}function ct(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 at(e,t){const n=t.selection;null!==n&&ct(e,n)}function ft(e,t,n,o,s,i={}){const r=e.color,l=document.createElement("span");i.cursor?(l.className=i.cursor,b(l.style,{"--lexical-cursor-color":r,bottom:"0",position:"absolute",right:"-1px",top:"0"})):b(l.style,{"background-color":r,bottom:"0",position:"absolute",right:"-1px",top:"0",width:"1px","z-index":"10"});const c=document.createElement("span");return c.textContent=e.name,i.cursorName?c.className=i.cursorName:b(c.style,{"background-color":r,color:"#fff","font-family":"Arial","font-size":"12px","font-weight":"bold",left:"-2px","line-height":"12px",padding:"2px",position:"absolute",top:"-16px","white-space":"nowrap"}),l.appendChild(c),{anchor:{key:t,offset:n},caret:l,color:r,focus:{key:o,offset:s},name:c,selections:[]}}function ut(e,t,o,s,i={}){const r=e.editor,l=r.getRootElement(),c=e.cursorsContainer;if(null===c||null===l)return;const a=c.offsetParent;if(null===a)return;const f=a.getBoundingClientRect(),u=t.selection;if(null===o)return null===u?void 0:(t.selection=null,void ct(e,u));t.selection=o;const d=o.caret,h=o.color,p=o.selections,g=o.anchor,_=o.focus,y=g.key,m=_.key,x=s.get(y),T=s.get(m);if(null==x||null==T)return;let k;if(x===T&&n(x)){k=[r.getElementByKey(y).getBoundingClientRect()]}else{const e=V(r,x,g.offset,T,_.offset);if(null===e)return;k=H(r,e)}const N=p.length,S=k.length;for(let e=0;e<S;e++){const t=k[e];let n=p[e];if(void 0===n){n=document.createElement("span"),p[e]=n;const t=document.createElement("span");i.selectionBg&&(t.className=i.selectionBg),n.appendChild(t),c.appendChild(n)}const o=t.top-f.top,s=t.left-f.left,r={height:`${t.height}px`,left:`${s}px`,"pointer-events":"none",position:"absolute",top:`${o}px`,width:`${t.width}px`};i.selection?(n.className=i.selection,b(n.style,{...r,"--lexical-cursor-color":h}),b(n.firstChild.style,{height:"100%",left:"0",position:"absolute",top:"0",width:"100%"})):(b(n.style,r),b(n.firstChild.style,{...r,"background-color":h,left:"0",opacity:"0.3",top:"0","z-index":"5"})),e===S-1&&d.parentNode!==n&&n.appendChild(d)}for(let e=N-1;e>=S;e--){const t=p[e];c.removeChild(t),p.pop()}}function dt(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,i=0,r=null,l=0;if(null!==n&&null!==o){const t=it(n,e),c=it(o,e);null!==t&&null!==c&&([s,i]=_t(t.type,t.index),[r,l]=_t(c.type,c.index))}return{anchorCollabNode:s,anchorOffset:i,focusCollabNode:r,focusOffset:l}}function ht(e,t){const{anchorPos:n,focusPos:s}=t,i=n?it(n,e):null,r=s?it(s,e):null;if(null===i||null===r)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(ue(e)){const[e,t]=_t(i.type,i.index),[n,o]=_t(r.type,r.index);return{anchorKey:null!==e?e.getKey():null,anchorOffset:t,focusKey:null!==n?n.getKey():null,focusOffset:o}}let[l,c]=yt(e.mapping,i),[a,f]=yt(e.mapping,r);if(a&&l&&(a!==l||f!==c)){const e=a.isBefore(l),t=e?a:l,n=e?f:c;o(t)&&o(t.getNextSibling())&&n===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 pt(e,t){const n=t.awareness.getLocalState();if(null===n)return;const{anchorKey:o,anchorOffset:r,focusKey:l,focusOffset:c}=ht(e,n);if(null!==o&&null!==l){const e=s();if(!i(e))return;gt(e.anchor,o,r),gt(e.focus,l,c)}}function gt(e,n,s){if(e.key!==n||e.offset!==s){let i=t(n);if(null!==i&&!r(i)&&!o(i)){const e=i.getParentOrThrow();n=e.getKey(),s=i.getIndexWithinParent(),i=e}e.set(n,s,r(i)?"element":"text")}}function _t(e,t){const n=e._collabNode;if(void 0===n)return[null,0];if(n instanceof ie){const{node:e,offset:o}=Oe(n,t,!0);return null===e?[n,0]:[e,o]}return[null,0]}function yt(e,t){const n=t.type,s=t.index;if(n instanceof O){const t=e.get(n);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,o(e))for(;l<c.length&&o(c[l]);)l+=1}return[t,l]}{const t=e.get(n);if(void 0===t)return[null,0];let o=0,i=s;for(;i>t[o].getTextContentSize()&&o+1<t.length;)i-=t[o].getTextContentSize(),o++;const r=t[o];return[r,Math.min(i,r.getTextContentSize())]}}function mt(e,t){return t.awareness.getStates()}function xt(e,t,n){const{getAwarenessStates:o=mt}=n??{},s=Array.from(o(e,t)),i=e.clientID,r=e.cursors,l=e.editor,c=l._config.theme.collaboration,a=l._editorState._nodeMap,f=new Set;for(let t=0;t<s.length;t++){const n=s[t],[o,u]=n;if(0!==o&&o!==i){f.add(o);const{name:t,color:n,focusing:s}=u;let i=null,d=r.get(o);if(void 0===d&&(d=lt(t,n),r.set(o,d)),s){const{anchorKey:t,anchorOffset:n,focusKey:o,focusOffset:s}=l.read(()=>ht(e,u));if(null!==t&&null!==o)if(i=d.selection,null===i)i=ft(d,t,n,o,s,c);else{const e=i.anchor,r=i.focus;e.key=t,e.offset=n,r.key=o,r.offset=s}}ut(e,d,i,a,c)}}const u=Array.from(r.keys());for(let t=0;t<u.length;t++){const n=u[t];if(!f.has(n)){const t=r.get(n);void 0!==t&&(at(e,t),r.delete(n))}}}function bt(e,t,n,o){const s=t.awareness,r=s.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)&&(i(o)&&(ue(e)?(h=ot(o.anchor,e),p=ot(o.focus,e)):(h=st(o.anchor,e),p=st(o.focus,e))),(rt(l,h)||rt(c,p))&&s.setLocalState({...r,anchorPos:h,awarenessData:d,color:f,focusPos:p,focusing:u,name:a}))}function Tt(e,t){if(t instanceof R&&function(e,t){const{target:n}=t;if(!n._item||"__state"!==n._item.parentSub||void 0!==xe(n)||!(n.parent instanceof C||n.parent instanceof O||n.parent instanceof K))return!1;const o=be(e,n.parent).getNode();if(o){const e=h(o.getWritable());for(const o of t.keysChanged)e.updateFromUnknown(o,n.get(o))}return!0}(e,t))return;const{target:n}=t,o=be(e,n);if(o instanceof ie&&t instanceof q){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 oe&&t instanceof R){const{keysChanged:n}=t;n.size>0&&o.syncPropertiesAndTextFromYjs(e,n)}else if(o instanceof Z&&t instanceof J){const{attributesChanged:n}=t;n.size>0&&o.syncPropertiesFromYjs(e,n)}else Q(82)}function kt(e,t,n,o,s=xt){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];Tt(e,o)}Nt(r,e,t),o||N(S)},{onUpdate:()=>{s(e,t),i.update(()=>St())},skipTransforms:!0,tag:o?k:T})}function Nt(e,t,n){const o=s();if(i(o))if(Ke(o)){const r=e._selection;if(i(r)&&(pt(t,n),Ke(o))){Pe(o.anchor.key,e)}bt(t,n,r,s())}else pt(t,n)}function St(){0===p().getChildrenSize()&&p().append(v())}function vt(e,n,i,r,l,c,a,f){Me(e,()=>{r.read(()=>{if(f.has(T)||f.has(k))return void(a.size>0&&function(e,n){const s=Array.from(n),i=e.collabNodeMap,r=[],l=[];for(let e=0;e<s.length;e++){const n=s[e],c=t(n),a=i.get(n);if(a instanceof oe)if(o(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}}(e,a));if(l.has("root")){const t=i._nodeMap,n=p(),o=e.root;o.syncPropertiesFromLexical(e,n,t),o.syncChildrenFromLexical(e,n,t,l,c)}const r=s(),u=i._selection;bt(e,n,u,r)})})}function wt(e,t){const{target:n}=t;if(n instanceof O&&t instanceof J)Fe(n,e,t.attributesChanged,t.childListChanged);else if(n instanceof C&&t instanceof q){const t=n.parent;t instanceof O?Fe(t,e,new Set,!0):Q(327)}else Q(328)}function Ct(e,t,n,o,s){const i=e.editor,r=i._editorState;Y(o,o.deleteSet,t=>{if(t.constructor===B){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];wt(e,o)}Nt(r,e,t),s||N(S)},{discrete:!0,onUpdate:()=>{xt(e,t),i.update(()=>St())},skipTransforms:!0,tag:s?k:T})}function Ot(e,t){e.mapping.clear();const n=e.editor;n.update(()=>{p().clear(),Fe(e.root,e,null,!0),N(T)},{discrete:!0,onUpdate:()=>{xt(e,t),n.update(()=>St())},skipTransforms:!0,tag:T})}function Kt(e,t,n,o,i,r,l){(l.has(T)||l.has(k))&&0===r.size||(r.forEach(t=>{e.mapping.deleteNode(t)}),Me(e,()=>{o.read(()=>{i.has("root")&&Xe(e.doc,e.root,p(),e,new Set(i.keys()));const o=s(),r=n._selection;bt(e,t,r,o)})}))}const Mt=w("CONNECTED_COMMAND"),Pt=w("TOGGLE_CONNECT_COMMAND"),Et=w("DIFF_VERSIONS_COMMAND"),Ft=w("CLEAR_DIFF_VERSIONS_COMMAND");function At(e,t){return new G(t,{trackedOrigins:new Set([e,null])})}function jt(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})}function zt(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{tt as $getYChangeState,Ft as CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL,Mt as CONNECTED_COMMAND,Et as DIFF_VERSIONS_COMMAND__EXPERIMENTAL,Pt as TOGGLE_CONNECT_COMMAND,ae as createBinding,fe as createBindingV2__EXPERIMENTAL,At as createUndoManager,dt as getAnchorAndFocusCollabNodesForUserState,jt as initLocalState,nt as renderSnapshot__EXPERIMENTAL,zt as setLocalStateFocus,xt as syncCursorPositions,vt as syncLexicalUpdateToYjs,Kt as syncLexicalUpdateToYjsV2__EXPERIMENTAL,kt as syncYjsChangesToLexical,Ct as syncYjsChangesToLexicalV2__EXPERIMENTAL,Ot as syncYjsStateToLexicalV2__EXPERIMENTAL};
package/package.json CHANGED
@@ -11,13 +11,13 @@
11
11
  "crdt"
12
12
  ],
13
13
  "license": "MIT",
14
- "version": "0.45.1-dev.0",
14
+ "version": "0.45.1-nightly.20260531.0",
15
15
  "main": "./dist/LexicalYjs.js",
16
16
  "types": "./dist/index.d.ts",
17
17
  "dependencies": {
18
- "@lexical/selection": "0.45.1-dev.0",
19
- "lexical": "0.45.1-dev.0",
20
- "@lexical/internal": "0.45.1-dev.0"
18
+ "@lexical/internal": "0.45.1-nightly.20260531.0",
19
+ "@lexical/selection": "0.45.1-nightly.20260531.0",
20
+ "lexical": "0.45.1-nightly.20260531.0"
21
21
  },
22
22
  "devDependencies": {
23
23
  "yjs": "^13.6.30"
package/src/SyncV2.ts CHANGED
@@ -172,8 +172,11 @@ export const $createOrUpdateNodeFromYElement = (
172
172
  const state: Record<string, unknown> = {};
173
173
  for (const k in attrs) {
174
174
  if (k.startsWith(STATE_KEY_PREFIX)) {
175
+ // State keys route through NodeState.updateFromJSON, which guards
176
+ // against prototype-polluting keys.
175
177
  state[attrKeyToStateKey(k)] = attrs[k];
176
- } else {
178
+ } else if (k !== '__proto__' && k !== 'constructor' && k !== 'prototype') {
179
+ // Skip prototype-polluting property keys from untrusted remote attrs.
177
180
  properties[k] = attrs[k];
178
181
  }
179
182
  }