@lexical/yjs 0.51.0 → 0.51.1-nightly.20260921.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/LexicalYjs.dev.js
CHANGED
|
@@ -809,9 +809,9 @@ function $createCollabElementNode(xmlText, parent, type) {
|
|
|
809
809
|
|
|
810
810
|
// Stores mappings between Yjs shared types and the Lexical nodes they were last associated with.
|
|
811
811
|
class CollabV2Mapping {
|
|
812
|
-
_nodeMap = new Map();
|
|
813
|
-
_sharedTypeToNodeKeys = new Map();
|
|
814
|
-
_nodeKeyToSharedType = new Map();
|
|
812
|
+
_nodeMap = (() => new Map())();
|
|
813
|
+
_sharedTypeToNodeKeys = (() => new Map())();
|
|
814
|
+
_nodeKeyToSharedType = (() => new Map())();
|
|
815
815
|
set(sharedType, node) {
|
|
816
816
|
const isArray = node instanceof Array;
|
|
817
817
|
|
package/dist/LexicalYjs.prod.js
CHANGED
|
@@ -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 u,$getSlotNames as d,$getSlot as h,$removeSlot as p,$setSlot as g,$isRootNode as y,$getWritableNodeState as _,getDeclaredSlots as m,$getRoot as x,RootNode as S,ElementNode as b,TextNode as T,$getState as N,createState as k,getRootOwnerDocument as v,setDOMStyleObject as w,isDOMShadowRoot as C,COLLABORATION_TAG as F,HISTORIC_TAG as M,$addUpdateTag as A,SKIP_SCROLL_INTO_VIEW_TAG as O,$createParagraphNode as E,createCommand as K}from"lexical";import{XmlText as P,XmlElement as j,Map as L,Doc as z,typeListToArraySnapshot as Y,Snapshot as D,typeMapGetAllSnapshot as I,isDeleted as R,XmlHook as $,ContentString as B,ContentFormat as W,emptySnapshot as U,PermanentUserData as H,iterateDeletedStructs as q,snapshot as J,createAbsolutePositionFromRelativePosition as V,createRelativePositionFromTypeIndex as G,compareRelativePositions as X,Item as Q,YMapEvent as Z,YTextEvent as ee,YXmlEvent as te,UndoManager as ne}from"yjs";import{createDOMRange as oe,createRectsFromDOMRange as se}from"@lexical/selection";function ie(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 re(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 le{_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 instanceof le&&ie(394),this._parent.getChildOffset(this)}syncPropertiesFromLexical(e,t,n){const o=this.getPrevNode(n);$e(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();if(null===n)return;Ye(e,this._xmlElem,n,t)}syncSlotsFromYjs(e,t){Je(e,this._xmlElem,t,this)}syncSlotsFromLexical(e,t,n,o,s){Ve(e,this._xmlElem,t,n,o,s,this)}destroy(e){const t=e.collabNodeMap;Ge(e,this._xmlElem),t.get(this._key)===this&&t.delete(this._key)}}function ce(e,t,n){const o=new le(e,t,n);return e._collabNode=o,o}class ae{_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 fe(e,t){const n=new ae(e,t);return e._collabNode=n,n}class ue{_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($e(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=re(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();if(null===n)return;Ye(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 de(e,t,n,o){const s=new ue(e,t,n,o);return e._collabNode=s,s}class he{_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 e instanceof he||ie(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null!==n&&Ye(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}=We(this,o,!1);if(t instanceof he||t instanceof ae||t instanceof le)n.splice(s,1),e-=1;else{if(!(t instanceof ue))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=Be(t._text,i,o-1,"");e.length>0&&(l instanceof ue?l._text+=e:this._xmlText.delete(i,e.length))}else t._text=Be(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}=We(this,o,!0);e instanceof ue?e._text=Be(e._text,t,0,l):this._xmlText.delete(t,l.length),o+=l.length}else{const t=l;if(void 0===je(t))continue;const{node:i,nodeIndex:r,length:c}=We(this,o,!1),a=Le(e,t,this);if(i instanceof ue&&c>0&&c<i._text.length){const e=i._text,t=e.length-c;i._text=Be(e,t,c,""),n.splice(r+1,0,a),s=Be(e,0,t,"")}else n.splice(r,0,a);null!==s&&a instanceof ue&&(a._text=s+a._text,s=null),o+=1}}}}syncChildrenFromYjs(e){const t=this.getNode();if(null===t)return;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,y=null;f!==i&&(p=t.getWritable());for(let i=0;i<f;i++){const l=s[g],_=r[i],m=_.getNode(),x=_._key;if(null!==m&&l===x){const t=o(m);if(d.add(l),t)if(_._key=l,_ instanceof he){const t=_._xmlText;_.syncPropertiesFromYjs(e,null),_.applyChildrenYjsDelta(e,t.toDelta()),_.syncChildrenFromYjs(e)}else _ instanceof ue?_.syncPropertiesAndTextFromYjs(e,null):_ instanceof le?_.syncPropertiesFromYjs(e,null):_ instanceof ae||ie(93);y=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=ze(e,_,n),s=o.__key;if(u.set(s,_),null===y){const e=p.getFirstChild();if(p.__first=s,null!==e){const t=e.getWritable();t.__prev=s,o.__next=t.__key}}else{const e=y.getWritable(),t=y.getNextSibling();if(e.__next=s,o.__prev=y.__key,null!==t){const e=t.getWritable();e.__prev=s,o.__next=e.__key}}i===f-1&&(p.__last=s),p.__size++,y=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)}}this.syncSlotsFromYjs(e,t)}syncSlotsFromYjs(e,t){Je(e,this._xmlText,t,this)}syncPropertiesFromLexical(e,t,n){$e(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(t,n,s,i,l,a){const f=this._children[n],u=c(s);f instanceof he&&r(u)?(f.syncPropertiesFromLexical(t,u,i),f.syncChildrenFromLexical(t,u,i,l,a),f.syncSlotsFromLexical(t,u,i,l,a)):f instanceof ue&&o(u)?f.syncPropertiesAndTextFromLexical(t,u,i):f instanceof le&&e(u)&&(f.syncPropertiesFromLexical(t,u,i),f.syncSlotsFromLexical(t,u,i,l,a))}syncSlotsFromLexical(e,t,n,o,s){Ve(e,this._xmlText,t,n,o,s,this)}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,y=0;for(;g<=f&&y<=u;){const t=r[g],i=a[y];if(t===i)this._syncChildFromLexical(e,y,i,n,o,s),g++,y++;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=Pe(e,c(i),this);d.set(i,t),o?(this.splice(e,y,1,t),g++,y++):(this.splice(e,y,0,t),y++)}else this.splice(e,y,1),g++}}const _=g>f,m=y>u;if(_&&!m)for(;y<=u;++y){const t=a[y],n=Pe(e,c(t),this);this.append(n),d.set(t,n)}else if(m&&!_)for(let t=this._children.length-1;t>=y;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 he)t.insertEmbed(s,e._xmlText);else if(e instanceof ue){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof ae?t.insertEmbed(s,e._map):e instanceof le&&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(void 0!==o&&this.append(o));const r=i.getOffset();-1===r&&ie(95);const l=this._xmlText;if(0!==n){const o=s.slice(t,t+n);for(let t=0;t<o.length;t++)o[t].destroy(e);l.delete(r,i.getSize())}if(o instanceof he)l.insertEmbed(r,o._xmlText);else if(o instanceof ue){const e=o._map;null===e.parent&&l.insertEmbed(r,e),l.insert(r+1,o._text)}else o instanceof ae?l.insertEmbed(r,o._map):o instanceof le&&l.insertEmbed(r,o._xmlElem);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);Ge(e,this._xmlText),t.get(this._key)===this&&t.delete(this._key)}}function pe(e,t,n){const o=new he(e,t,n);return e._collabNode=o,o}class ge{_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 P){if(n||ie(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&&ie(332),o(t)&&ie(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 P){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 ye(e,t,n,o,s){const i={clientID:n.clientID,cursorHighlightSheet:null,cursors:new Map,cursorsContainer:null,doc:n,docMap:o,editor:e,excludedProperties:s||new Map,id:t,isBootstrapping:!1,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))Ae(t,o,e)||(s[t]=n);n.set(o.__type,Object.freeze(s))})})}(i),i}function _e({editor:e,id:t,doc:n,docMap:o,excludedProperties:s,rootName:i="root",getXmlText:r}){const l=r?r(n):n.get(i,P);l instanceof P&&l.doc===n||ie(401);const c=pe(l,null,"root");return c._key="root",{...ye(e,t,n,o,s),collabNodeMap:new Map,root:c}}function me(e,t,n,o,s,i){return null==o&&ie(81),_e({doc:o,docMap:s,editor:e,excludedProperties:i,id:n})}function xe(e,t,n,o,s={}){null==n&&ie(81);const{excludedProperties:i,rootName:r="root-v2",getXmlElement:l}=s,c=l?l(n):n.get(r,j);return c instanceof j&&c.doc===n||ie(402),c.nodeName!==Te&&ie(403,c.nodeName,Te),{...ye(e,t,n,o,i),mapping:new ge,root:c}}function Se(e){return Object.prototype.hasOwnProperty.call(e,"collabNodeMap")}const be="__slots",Te="UNDEFINED",Ne=new Set(["__key","__parent","__next","__prev","__state","__slotHost","__slots"]),ke=new Set(["__first","__last","__size"]),ve=new Set(["__cachedText","__textFormat","__textStyle"]),we=new Set(["__text"]);function Ce(e,t){e.setAttribute(be,t)}function Fe(e){return"__proto__"===e||"constructor"===e||"prototype"===e}function Me(t){return(r(t)||e(t))&&!t.isInline()}function Ae(e,t,n){if(Ne.has(e)||"function"==typeof t[e])return!0;if(o(t)){if(we.has(e))return!0}else if(r(t)&&(ke.has(e)||y(t)&&ve.has(e)))return!0;const s=t.constructor,i=n.excludedProperties.get(s);return null!=i&&i.has(e)}function Oe(e,t){const n=e.__type,{nodeProperties:o}=t,s=o.get(n);return void 0===s&&ie(330,n),s}function Ee(t,n,s,i,l,c){n instanceof he&&r(s)?(n.syncPropertiesFromLexical(t,s,i),n.syncChildrenFromLexical(t,s,i,l,c),n.syncSlotsFromLexical(t,s,i,l,c)):n instanceof ue&&o(s)?n.syncPropertiesAndTextFromLexical(t,s,i):n instanceof le&&e(s)&&(n.syncPropertiesFromLexical(t,s,i),n.syncSlotsFromLexical(t,s,i,l,c))}function Ke(e,t,n,o){const s=d(t),i=m(t.constructor).length>0;if(0===s.length&&!i)return;const r=new L;let l=!1;for(const o of s){const s=h(t,o);if(null===s)continue;const i=Pe(e,s,n);e.collabNodeMap.set(s.__key,i),r.set(o,i.getSharedType()),l=!0}(l||i)&&Ce(o,r)}function Pe(t,s,i){const l=s.__type;let c;if(r(s)){const e=new P;c=pe(e,i,l),c.syncPropertiesFromLexical(t,s,null),c.syncChildrenFromLexical(t,s,null,null,null),Ke(t,s,c,e)}else if(o(s)){i instanceof he||ie(389);c=de(new L,s.__text,i,l),c.syncPropertiesAndTextFromLexical(t,s,null)}else if(n(s)){i instanceof he||ie(390);const e=new L;e.set("__type","linebreak"),c=fe(e,i)}else if(e(s)){const e=new j;c=ce(e,i,l),c.syncPropertiesFromLexical(t,s,null),Ke(t,s,c,e)}else ie(86);return c._key=s.__key,c}function je(e){const t=De(e,"__type");return"string"!=typeof t&&void 0!==t&&ie(87),t}function Le(e,t,n){const o=t._collabNode;if(void 0===o){const o=e.editor._nodes,s=je(t);"string"!=typeof s&&ie(87);void 0===o.get(s)&&ie(88,s);const i=t.parent,r=void 0===n&&null!==i?Le(e,i):n||null;if(r instanceof he||r instanceof le&&function(e,t){const n=e._xmlElem.getAttribute(be);if(!(n instanceof L))return!1;for(const e of n.values())if(e===t)return!0;return!1}(r,t)||ie(391),t instanceof P)return pe(t,r,s);if(t instanceof L)return r instanceof he||ie(392),"linebreak"===s?fe(t,r):de(t,"",r,s);if(t instanceof j)return ce(t,r,s)}return o}function ze(t,n,o){const s=n.getType(),i=t.editor._nodes.get(s);void 0===i&&ie(88,s);const r=new i.klass;if(r.__parent=o,n._key=r.__key,n instanceof he){const e=n._xmlText;n.syncPropertiesFromYjs(t,null),n.applyChildrenYjsDelta(t,e.toDelta()),n.syncChildrenFromYjs(t)}else n instanceof ue?n.syncPropertiesAndTextFromYjs(t,null):n instanceof le&&(n.syncPropertiesFromYjs(t,null),e(r)||ie(393),n.syncSlotsFromYjs(t,r));return t.collabNodeMap.set(r.__key,n),r}function Ye(e,t,n,o){const s=null===o?t instanceof L?Array.from(t.keys()):t instanceof P||t instanceof j?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(Ae(r,n,e)){"__state"===r&&Se(e)&&(i||(i=n.getWritable()),Re(t,i));continue}const l=n[r];let c=De(t,r);if(l!==c){if(c instanceof z){const t=e.docMap;l instanceof z&&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 De(e,t){return e instanceof L?e.get(t):e instanceof P||e instanceof j?e.getAttribute(t):e[t]}function Ie(e,t,n){e instanceof L?e.set(t,n):e.setAttribute(t,n)}function Re(e,t){const n=De(e,"__state");n instanceof L&&_(t).updateFromJSON(n.toJSON())}function $e(e,t,n,o){const s=Object.keys(Oe(o,e)),i=e.editor.constructor;!function(e,t,n,o){const s=o.__state,i=null===t.doc?void 0:De(t,"__state");if(!s)return;const[r,l]=s.getInternalState(),c=n&&n.__state,a=i instanceof L?i:new L;if(c===s)return;const[f,u]=c&&a.doc?c.getInternalState():[void 0,new Map];if(r)for(const[e,t]of Object.entries(r))f&&t===f[e]||a.set(e,t);for(const[e,t]of l)u.get(e)!==t&&a.set(e.key,e.unparse(t));i||Ie(t,"__state",a)}(0,t,n,o);for(let r=0;r<s.length;r++){const l=s[r],c=null===n?void 0:n[l];let a=o[l];if(c!==a){if(a instanceof i){const t=e.docMap;let n;if(c instanceof i){const e=c._key;n=t.get(e),t.delete(e)}const s=n||new z,r=s.guid;a._key=r,t.set(r,s),a=s,e.editor.update(()=>{o.markDirty()})}Ie(t,l,a)}}}function Be(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function We(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 ue){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 Ue(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 He(e,t){e.doc.transact(t,e)}function qe(e,n){const o=n._nodeMap.get(e);if(!o)return void x().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():qe(i.__key,n):x().selectStart()}function Je(n,o,s,i){const l=o.getAttribute(be),c=l instanceof L?new Set(l.keys()):new Set;for(const e of d(s))if(!c.has(e)){const t=h(s,e);if(null!==t){const e=n.collabNodeMap.get(t.__key);void 0!==e&&e.destroy(n)}p(s,e)}if(l instanceof L)for(const[o,c]of l.entries()){if(Fe(o))continue;if(!(c instanceof P||c instanceof j||c instanceof L))continue;const l=h(s,o),a=null===l?void 0:n.collabNodeMap.get(l.__key);if(void 0!==a&&a.getSharedType()===c)continue;if(void 0===c._collabNode&&"string"!=typeof De(c,"__type"))continue;if(c instanceof L&&i instanceof le)continue;const f=c._collabNode;if(void 0!==f){const n=t(f._key);if(null!==n&&(n.isAttached()||(r(n)||e(n))&&null!==n.getLatest().__slotHost))continue}const u=Le(n,c,i),d=ze(n,u,null);Me(d)?(void 0!==a&&a.destroy(n),g(s,o,d)):n.collabNodeMap.get(d.__key)===u&&n.collabNodeMap.delete(d.__key)}}function Ve(e,t,n,o,s,i,r){const l=d(n),c=t.getAttribute(be);if(0===l.length&&!(c instanceof L))return;let a;c instanceof L?a=c:(a=new L,Ce(t,a));const f=new Set(l);for(const t of Array.from(a.keys()))if(!f.has(t)){const n=a.get(t),o=null==n?void 0:n._collabNode;void 0!==o&&o.destroy(e),a.delete(t)}const u=e.collabNodeMap;for(const t of l){const l=h(n,t);if(null===l)continue;const c=u.get(l.__key);if(void 0!==c&&a.get(t)===c.getSharedType())Ee(e,c,l,o,s,i);else{const n=a.get(t),o=null==n?void 0:n._collabNode;void 0!==o&&o.destroy(e);const s=Pe(e,l,r);u.set(l.__key,s),a.set(t,s.getSharedType())}}}function Ge(e,t){const n=t.getAttribute(be);if(n instanceof L)for(const t of n.keys()){const o=n.get(t),s=null==o?void 0:o._collabNode;void 0!==s&&s.destroy(e)}}const Xe=e=>e.nodeName===Te,Qe=(t,n,o,s,i,r,l)=>{let c=n.mapping.get(t);if(c&&o&&0===o.size&&!s)return c;const a=Xe(t)?S.getType():t.nodeName,f=n.editor._nodes.get(a);if(void 0===f)throw new Error(`$createOrUpdateNodeFromYElement: Node ${a} is not registered`);if(c||(c=new f.klass,o=null,s=!0),s&&c instanceof b){const e=[],o=t=>{if(t instanceof j){const o=Qe(t,n,new Set,!1,i,r,l);null!==o&&e.push(o)}else if(t instanceof P){const o=tt(t,n,i,r,l);null!==o&&o.forEach(t=>{null!==t&&e.push(t)})}else ie(329)};void 0===i||void 0===r?t.toArray().forEach(o):Y(t,new D(r.ds,i.sv)).filter(e=>!e._item.deleted||et(e._item,i)||et(e._item,r)).forEach(o),Ze(c,e)}const u=t.getAttributes(i);Xe(t)||void 0===i||(et(t._item,i)?et(t._item,r)||(u[mt("ychange")]=l?l("added",t._item.id):{type:"added"}):u[mt("ychange")]=l?l("removed",t._item.id):{type:"removed"});const y={...Oe(c,n)},m={};for(const e in u)e.startsWith(_t)?m[xt(e)]=u[e]:e!==be&&"__proto__"!==e&&"constructor"!==e&&"prototype"!==e&&(y[e]=u[e]);if(Ye(n,y,c,o),o){if(o.size>0){const e=_(c);for(const t of o)if(t.startsWith(_t)){const n=xt(t);e.updateFromUnknown(n,m[n])}}}else _(c).updateFromJSON(m);if(c instanceof b||e(c)){const e=u[be],t=new Set;if(e instanceof L){const o=void 0===i?Array.from(e.entries()):Object.entries(I(e,i));for(const[e,s]of o){if(t.add(e),Fe(e))continue;let o=null;if(s instanceof j&&(o=Qe(s,n,new Set,!1,i,r,l)),null===o)continue;const a=h(c,e);null!==a&&a.getKey()===o.getKey()||(Me(o)?null===o.getLatest().__slotHost&&g(c,e,o):o.isAttached()||ot(s,n))}}for(const e of d(c))t.has(e)||p(c,e)}const x=c.getLatest();return n.mapping.set(t,x),x},Ze=(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,[])},et=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!R(t.ds,e.id),tt=(e,t,n,s,i)=>{const r=gt(e,n,s,i);let l=t.mapping.get(e)??[];const c=r.map(e=>e.attributes.t??T.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={...Oe(n,t),...s.p},a=Object.fromEntries(Object.entries(s).filter(([e])=>e.startsWith(_t)).map(([e,t])=>[xt(e),t]));Ye(t,c,n,null),_(n).updateFromJSON(a)}const a=l.map(e=>e.getLatest());return t.mapping.set(e,a),a},nt=(e,t)=>{const n=d(e);if(0===n.length&&0===m(e.constructor).length)return;const o=new L;for(const s of n){const n=h(e,s);null!=n&&o.set(s,it(n,t))}return o},ot=(e,t)=>{if((e instanceof j||e instanceof P)&&t.mapping.delete(e),e instanceof j){const n=e.getAttribute(be);if(n instanceof L)for(const e of n.values())ot(e,t);for(const n of e.toArray())ot(n,t)}},st=(e,t)=>{const n=new j(e.getType()),o={...yt(e,t),...St(e)};for(const e in o){const t=o[e];null!==t&&n.setAttribute(e,t)}if(!(e instanceof b)){const o=nt(e,t);return void 0!==o&&(Ce(n,o),t.mapping.set(n,e)),n}const s=nt(e,t);return void 0!==s&&Ce(n,s),n.insert(0,at(e).map(e=>rt(e,t))),t.mapping.set(n,e),n},it=(t,n)=>{const o=st(t,n);return e(t)&&void 0===n.mapping.getSharedType(t)&&n.mapping.set(o,t),o},rt=(e,t)=>e instanceof Array?((e,t)=>{const n=new P;return pt(n,e,t),n})(e,t):st(e,t),lt=e=>"object"==typeof e&&null!=e,ct=(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||lt(r)&<(l)&&ct(r,l)}return o},at=e=>{if(!(e instanceof b))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},ft=(e,t,n)=>{const o=gt(e);return o.length===t.length&&o.every((e,o)=>{const s=t[o],i=e.attributes.t??T.getType(),r=e.attributes.p??{},l=Object.fromEntries(Object.entries(e.attributes).filter(([e])=>e.startsWith(_t)));return e.insert===s.getTextContent()&&i===s.getType()&&ct(r,yt(s,n))&&ct(l,St(s))})},ut=(e,t,n)=>{if(e instanceof j&&!(t instanceof Array)&&Tt(e,t)){const o=at(t),s=e.getAttributes();return delete s[be],e._length===o.length&&ct(s,{...yt(t,n),...St(t)})&&((e,t,n)=>{const o=d(t),s=e.getAttribute(be);if(!(s instanceof L))return 0===o.length;if(s.size!==o.length)return!1;for(const e of o){const o=h(t,e),i=s.get(e);if(null===o||!(i instanceof j)||n.mapping.get(i)!==o)return!1}return!0})(e,t,n)&&e.toArray().every((e,t)=>ut(e,o[t],n))}return e instanceof P&&t instanceof Array&&ft(e,t,n)},dt=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),ht=(e,t,n)=>{const o=e.toArray(),s=at(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 $)break;if(dt(n.mapping.get(e),t))f=!0;else if(!ut(e,t,n))break}for(;c+a<l;a++){const e=o[r-a-1],t=s[i-a-1];if(e instanceof $)break;if(dt(n.mapping.get(e),t))f=!0;else if(!ut(e,t,n))break}return{equalityFactor:c+a,foundMappedChild:f}},pt=(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 B?t+=n.content.str:n.content instanceof W&&(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=yt(e,n);return 0===Object.keys(i).length&&(i=null),{attributes:Object.assign({},o,{...s!==T.getType()&&{t:s},p:i,...St(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}=re(r,c,f);e.delete(h,d),e.insert(h,u),e.applyDelta(l.map(e=>({attributes:e.attributes,retain:e.insert.length})))},gt=(e,t,n,o)=>e.toDelta(t,n,o).map(e=>{const t=e.attributes??{};return"ychange"in t&&(t[mt("ychange")]=t.ychange,delete t.ychange),{...e,attributes:t}}),yt=(e,t)=>{const n=Oe(e,t),o={};return Object.entries(n).forEach(([t,n])=>{const s=e[t];s!==n&&(o[t]=s)}),o},_t="s_",mt=e=>`s_${e}`,xt=e=>{if(!e.startsWith(_t))throw new Error(`Invalid state key: ${e}`);return e.slice(_t.length)},St=e=>{const t=e.__state;if(!t)return{};const[n={},o]=t.getInternalState(),s={};for(const[e,t]of Object.entries(n))s[mt(e)]=t;for(const[e,t]of o)s[mt(e.key)]=e.unparse(t);return s},bt=(t,n,o,s,i)=>{if(n instanceof j&&n.nodeName!==o.getType()&&(!Xe(n)||o.getType()!==S.getType()))throw new Error("node name mismatch!");if(s.mapping.set(n,o),n instanceof j){const r=n.getAttributes(),l={...yt(o,s),...St(o)};for(const e in l)if(null!=l[e]){r[e]===l[e]||lt(r[e])&<(l[e])&&ct(r[e],l[e])||"ychange"===e||n.setAttribute(e,l[e])}else n.removeAttribute(e);for(const e in r)e!==be&&void 0===l[e]&&n.removeAttribute(e);(o instanceof b||e(o))&&((t,n,o,s,i)=>{const r=d(n),l=t.getAttribute(be);if(0===r.length&&!(l instanceof L)&&0===m(n.constructor).length)return;let c;l instanceof L?c=l:(c=new L,Ce(t,c));const a=new Set(r);for(const e of Array.from(c.keys()))if(!a.has(e)){const t=c.get(e);void 0!==t&&ot(t,o),c.delete(e)}for(const t of r){const r=h(n,t);if(null==r)continue;const l=c.get(t);l instanceof j&&(r instanceof b||e(r))&&l===o.mapping.getSharedType(r)?s.has(r.getKey())&&bt(i,l,r,o,s):(l instanceof j&&ot(l,o),c.set(t,it(r,o)))}})(n,o,s,i,t)}const r=at(o),l=r.length,c=n.toArray(),a=c.length,f=Math.min(l,a);let u=0,p=0;for(;u<f;u++){const n=c[u],o=r[u];if(n instanceof $)break;if(dt(s.mapping.get(n),o))o instanceof Array||!(o instanceof b||e(o))||!i.has(o.getKey())||bt(t,n,o,s,i);else{if(!ut(n,o,s))break;s.mapping.set(n,o)}}for(;p+u<f;p++){const n=c[a-p-1],o=r[l-p-1];if(n instanceof $)break;if(dt(s.mapping.get(n),o))o instanceof Array||!(o instanceof b||e(o))||!i.has(o.getKey())||bt(t,n,o,s,i);else{if(!ut(n,o,s))break;s.mapping.set(n,o)}}for(;a-u-p>0&&l-u-p>0;){const e=c[u],o=r[u],f=c[a-p-1],d=r[l-p-1];if(e instanceof P&&o instanceof Array)ft(e,o,s)||pt(e,o,s),u+=1;else{let r=e instanceof j&&Tt(e,o),l=f instanceof j&&Tt(f,d);if(r&&l){const t=ht(e,o,s),n=ht(f,d,s);t.foundMappedChild&&!n.foundMappedChild?l=!1:!t.foundMappedChild&&n.foundMappedChild||t.equalityFactor<n.equalityFactor?r=!1:l=!1}r?(bt(t,e,o,s,i),u+=1):l?(bt(t,f,d,s,i),p+=1):(s.mapping.delete(n.get(u)),n.delete(u,1),n.insert(u,[rt(o,s)]),u+=1)}}const g=a-u-p;if(1===a&&0===l&&c[0]instanceof P?(s.mapping.delete(c[0]),c[0].delete(0,c[0].length)):g>0&&(n.slice(u,u+g).forEach(e=>s.mapping.delete(e)),n.delete(u,g)),u+p<l){const e=[];for(let t=u;t<l-p;t++)e.push(rt(r[t],s));n.insert(u,e)}},Tt=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType(),Nt=/* @__PURE__ */k("ychange",{isEqual:(e,t)=>e===t,parse:e=>e??null});function kt(e){return N(e,Nt)}const vt=(e,t=J(e.doc),n=U)=>{const{doc:o}=e;o.gc&&ie(325),o.transact(s=>{const i=new H(o);i&&i.dss.forEach(e=>{q(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(()=>{x().clear(),Qe(e.root,e,null,!0,t,n,r)})},e)};function wt(){return"undefined"!=typeof Highlight&&"undefined"!=typeof CSS&&"highlights"in CSS}const Ct=/* @__PURE__ */wt();function Ft(e,t,n){if(!CSS.supports("color",n))return;const o=function(e){const t=e.editor.getRootElement(),n=v(t);let o=e.cursorHighlightSheet;null===o&&(o=new(n.defaultView||window).CSSStyleSheet,e.cursorHighlightSheet=o);const s=null!==t?t.getRootNode():null,i=C(s)?s:n;return i.adoptedStyleSheets.includes(o)||(i.adoptedStyleSheets=[...i.adoptedStyleSheets,o]),o}(e),s=o.insertRule(`::highlight(${t}) { }`,o.cssRules.length),i=o.cssRules[s];i.style.setProperty("background-color",`color-mix(in srgb, ${n} 30%, transparent)`),i.style.setProperty("color","inherit")}function Mt(e,t){const n=e.cursorHighlightSheet;if(null===n)return;const o=`::highlight(${t})`;for(let e=n.cssRules.length-1;e>=0;e--){const t=n.cssRules[e];if(null!=t&&t.selectorText===o)return void n.deleteRule(e)}}function At(e,t,n=0){const s=t.collabNodeMap.get(e.key);if(void 0===s)return null;let i=e.offset,l=s.getSharedType();if(s instanceof ue){l=s._parent._xmlText;const e=s.getOffset();if(-1===e)return null;i=e+1+i}else if(s instanceof he&&"element"===e.type){const t=e.getNode();r(t)||ie(184);let n=0,s=0,l=t.getFirstChild();for(;null!==l&&s++<i;)o(l)?n+=l.getTextContentSize()+1:n++,l=l.getNextSibling();i=n}return G(l,i,n)}function Ot(e,t,n=0){const{mapping:s}=t,{offset:i}=e,l=e.getNode(),c=s.getSharedType(l);if(void 0===c)return null;if("text"===e.type){o(l)||ie(326);let e=l.getPreviousSibling(),t=i;for(;o(e);)t+=e.getTextContentSize(),e=e.getPreviousSibling();return G(c,t,n)}if("element"===e.type){r(l)||ie(184);let e=0,t=0,s=l.getFirstChild();for(;null!==s&&t<i;){let n=s.getNextSibling();if(t++,o(s))for(;o(n);)n=n.getNextSibling(),t++;e++,s=n}return G(c,e,n)}return null}function Et(e,t){return V(e,t.doc)}function Kt(e,t){if(null==e){if(null!=t)return!0}else if(null==t||!X(e,t))return!0;return!1}function Pt(e,t){return{color:t,name:e,selection:null}}function jt(e,t){null!==t.highlight&&(CSS.highlights.delete(t.highlightName),Mt(e,t.highlightName));const n=e.cursorsContainer;if(null===n)return;t.caret.parentNode===n&&n.removeChild(t.caret);const o=t.selections;for(let e=0;e<o.length;e++)o[e].parentNode===n&&n.removeChild(o[e])}function Lt(e,t){const n=t.selection;null!==n&&jt(e,n)}function zt(e,t,n,o,s,i,r,l,c={}){const a=e.color,f=v(t.editor.getRootElement()),u=f.createElement("span");c.cursor?(u.className=c.cursor,w(u.style,{"--lexical-cursor-color":a,bottom:"0",position:"absolute",right:"-1px",top:"0"})):w(u.style,{"background-color":a,bottom:"0",position:"absolute",right:"-1px",top:"0",width:"1px","z-index":"10"});const d=f.createElement("span");d.textContent=e.name,c.cursorName?d.className=c.cursorName:w(d.style,{"background-color":a,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"}),u.appendChild(d);const h=`lexical-cursor-${t.id}-${n}`;let p=null;return l&&Ct&&(p=new Highlight,CSS.highlights.set(h,p),Ft(t,h,a)),{anchor:{key:o,offset:s},caret:u,color:a,focus:{key:i,offset:r},highlight:p,highlightName:h,name:d,selections:[]}}function Yt(e,t,o,s,i={}){const r=e.editor,l=r.getRootElement(),c=e.cursorsContainer;if(null===c||null===l)return;const a=v(l),f=c.offsetParent;if(null===f)return;const u=f.getBoundingClientRect(),d=t.selection;if(null===o)return null===d?void 0:(t.selection=null,void jt(e,d));t.selection=o;const h=o.caret,p=o.color,g=o.highlight,y=o.anchor,_=o.focus,m=y.key,x=_.key,S=s.get(m),b=s.get(x);if(null==S||null==b)return;if(null!==g){const e=oe(r,S,y.offset,b,_.offset);if(null===e)return;g.clear(),e.collapsed||g.add(e);const t=e.cloneRange();t.collapse(!1);let o=t.getBoundingClientRect();if(0===o.height&&n(b)){const e=r.getElementByKey(x);null!==e&&(o=e.getBoundingClientRect())}return w(h.style,{"background-color":i.cursor?"":p,bottom:"",height:`${o.height||16}px`,left:o.left-u.left+"px","pointer-events":"none",position:"absolute",right:"",top:o.top-u.top+"px",width:"1px","z-index":"10"}),void(h.parentNode!==c&&c.appendChild(h))}const T=o.selections;let N;if(S===b&&n(S)){N=[r.getElementByKey(m).getBoundingClientRect()]}else{const e=oe(r,S,y.offset,b,_.offset);if(null===e)return;N=se(r,e)}const k=T.length,C=N.length;for(let e=0;e<C;e++){const t=N[e];let n=T[e];if(void 0===n){n=a.createElement("span"),T[e]=n;const t=a.createElement("span");i.selectionBg&&(t.className=i.selectionBg),n.appendChild(t),c.appendChild(n)}const o=t.top-u.top,s=t.left-u.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,w(n.style,{...r,"--lexical-cursor-color":p}),w(n.firstChild.style,{height:"100%",left:"0",position:"absolute",top:"0",width:"100%"})):(w(n.style,r),w(n.firstChild.style,{...r,"background-color":p,left:"0",opacity:"0.3",top:"0","z-index":"5"})),e===C-1&&h.parentNode!==n&&n.appendChild(h)}for(let e=k-1;e>=C;e--){const t=T[e];c.removeChild(t),T.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=Et(n,e),c=Et(o,e);null!==t&&null!==c&&([s,i]=Bt(e,t.type,t.index),[r,l]=Bt(e,c.type,c.index))}return{anchorCollabNode:s,anchorOffset:i,focusCollabNode:r,focusOffset:l}}function It(e,t){const{anchorPos:n,focusPos:s}=t,i=n?Et(n,e):null,r=s?Et(s,e):null;if(null===i||null===r)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(Se(e)){const[t,n]=Bt(e,i.type,i.index),[o,s]=Bt(e,r.type,r.index);return{anchorKey:null!==t?t.getKey():null,anchorOffset:n,focusKey:null!==o?o.getKey():null,focusOffset:s}}let[l,c]=Wt(e.mapping,i),[a,f]=Wt(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 Rt(e,t){const n=t.awareness.getLocalState();if(null===n)return;const{anchorKey:o,anchorOffset:r,focusKey:l,focusOffset:c}=It(e,n);if(null!==o&&null!==l){const e=s();if(!i(e))return;$t(e.anchor,o,r),$t(e.focus,l,c)}}function $t(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 Bt(e,t,n){const o=t._collabNode;if(void 0===o||!function(e,t){const n=e.root.getSharedType();let o=t;for(;null!=o;){if(o===n)return!0;o=o.parent}return!1}(e,t))return[null,0];if(o instanceof he){const{node:e,offset:t}=We(o,n,!0);return null===e?[o,o._children.length]:[e,t]}return[null,0]}function Wt(e,t){const n=t.type,s=t.index;if(n instanceof j){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 Ut(e,t){return t.awareness.getStates()}function Ht(e,t,n){const{getAwarenessStates:o=Ut,selectionHighlight:s=!1}=n??{},i=Array.from(o(e,t)),r=e.clientID,l=e.cursors,c=e.editor,a=c._config.theme.collaboration,f=c._editorState._nodeMap,u=new Set;for(let t=0;t<i.length;t++){const n=i[t],[o,d]=n;if(0!==o&&o!==r){u.add(o);const{name:t,color:n,focusing:i}=d;let r=null,h=l.get(o);if(void 0===h?(h=Pt(t,n),l.set(o,h)):h.name===t&&h.color===n||(Lt(e,h),h.name=t,h.color=n,h.selection=null),i){const{anchorKey:t,anchorOffset:n,focusKey:i,focusOffset:l}=c.read(()=>It(e,d));if(null!==t&&null!==i)if(r=h.selection,null===r)r=zt(h,e,o,t,n,i,l,s,a);else{const e=r.anchor,o=r.focus;e.key=t,e.offset=n,o.key=i,o.offset=l}}Yt(e,h,r,f,a)}}const d=Array.from(l.keys());for(let t=0;t<d.length;t++){const n=d[t];if(!u.has(n)){const t=l.get(n);void 0!==t&&(Lt(e,t),l.delete(n))}}}function qt(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;if(null!==o&&(null===l||o.is(n))||null!==n){if(i(o)){const t=o.isCollapsed(),n=!t&&o.isBackward(),s=n?-1:0,i=t||n?0:-1;Se(e)?(h=At(o.anchor,e,s),p=At(o.focus,e,i)):(h=Ot(o.anchor,e,s),p=Ot(o.focus,e,i))}(Kt(l,h)||Kt(c,p))&&s.setLocalState({...r,anchorPos:h,awarenessData:d,color:f,focusPos:p,focusing:u,name:a})}}function Jt(e,t){if(t instanceof Z&&function(e,t){const{target:n}=t;if(!n._item||"__state"!==n._item.parentSub||void 0!==je(n)||!(n.parent instanceof P||n.parent instanceof j||n.parent instanceof L))return!1;const o=Le(e,n.parent).getNode();if(o){const e=_(o.getWritable());for(const o of t.keysChanged)e.updateFromUnknown(o,n.get(o))}return!0}(e,t))return;const{target:n}=t;if(t instanceof Z&&n instanceof L&&null!=n._item&&n._item.parentSub===be&&(n.parent instanceof P||n.parent instanceof j)){const t=Le(e,n.parent);if(t instanceof he){const n=t.getNode();null!==n&&t.syncSlotsFromYjs(e,n)}else if(t instanceof le){const n=t.getNode();null!==n&&t.syncSlotsFromYjs(e,n)}return}const o=Le(e,n);if(o instanceof he&&t instanceof ee){const{keysChanged:n,childListChanged:s,delta:i}=t;if(n.size>0&&o.syncPropertiesFromYjs(e,n),n.has(be)){const t=o.getNode();null!==t&&o.syncSlotsFromYjs(e,t)}s&&(o.applyChildrenYjsDelta(e,i),o.syncChildrenFromYjs(e))}else if(o instanceof ue&&t instanceof Z){const{keysChanged:n}=t;n.size>0&&o.syncPropertiesAndTextFromYjs(e,n)}else if(o instanceof le&&t instanceof te){const{attributesChanged:n}=t;if(n.size>0&&o.syncPropertiesFromYjs(e,n),n.has(be)){const t=o.getNode();null!==t&&o.syncSlotsFromYjs(e,t)}}else ie(82)}function Vt(e,t,n,o,s=Ht){const i=e.editor,r=i._editorState;if(n.forEach(e=>e.delta),i.update(()=>{for(let t=0;t<n.length;t++){const o=n[t];Jt(e,o)}Gt(r,e,t),o||A(O)},{onUpdate:()=>{s(e,t),e.root.isEmpty()&&i.update(()=>Xt())},skipTransforms:!0,tag:o?M:F}),n.length>0){const t=n[0].transaction;q(t,t.deleteSet,t=>{if(t.constructor===Q){const n=t.content.type;if(n){const t=n._collabNode;void 0!==t&&e.collabNodeMap.get(t._key)===t&&e.collabNodeMap.delete(t._key)}}})}}function Gt(e,t,n){const o=s();if(i(o))if(Ue(o)){const r=e._selection;if(i(r)&&(Rt(t,n),Ue(o))){qe(o.anchor.key,e)}qt(t,n,r,s())}else Rt(t,n)}function Xt(){0===x().getChildrenSize()&&x().append(E())}function Qt(e,n,i,r,l,c,a,f){He(e,()=>{r.read(()=>{if(f.has(F)||f.has(M))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 ue)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=x(),o=e.root;o.syncPropertiesFromLexical(e,n,t),o.syncChildrenFromLexical(e,n,t,l,c),o.syncSlotsFromLexical(e,n,t,l,c),0===n.getChildrenSize()&&i._nodeMap.size>1&&e.editor.update(()=>Xt())}const r=s(),u=i._selection;qt(e,n,u,r)})})}function Zt(e,t){const{target:n}=t;if(n instanceof j&&t instanceof te)Qe(n,e,t.attributesChanged,t.childListChanged);else if(n instanceof P&&t instanceof ee){const t=n.parent;t instanceof j?Qe(t,e,new Set,!0):ie(327)}else if(n instanceof L&&t instanceof Z&&null!=n._item&&n._item.parentSub===be){const t=n.parent;t instanceof j?Qe(t,e,new Set([be]),!1):ie(388)}else ie(328)}function en(e,t,n,o,s){const i=e.editor,r=i._editorState;q(o,o.deleteSet,t=>{if(t.constructor===Q){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];Zt(e,o)}Gt(r,e,t),s||A(O)},{discrete:!0,onUpdate:()=>{Ht(e,t),0===e.root.length&&i.update(()=>Xt())},skipTransforms:!0,tag:s?M:F})}function tn(e,t){e.mapping.clear();const n=e.editor;n.update(()=>{x().clear(),Qe(e.root,e,null,!0),A(F)},{discrete:!0,onUpdate:()=>{Ht(e,t),0===e.root.length&&n.update(()=>Xt())},skipTransforms:!0,tag:F})}function nn(e,t,n,o,i,r,l,c){const a=c.has(F)||c.has(M);a&&0===l.size||(l.forEach(t=>{e.mapping.deleteNode(t)}),He(e,()=>{o.read(()=>{if(i.has("root")){const t=x();bt(e.doc,e.root,t,e,new Set([...i.keys(),...r])),!a&&0===t.getChildrenSize()&&n._nodeMap.size>1&&e.editor.update(()=>Xt())}const o=s(),l=n._selection;qt(e,t,l,o)})}))}const on=/* @__PURE__ */K("CONNECTED_COMMAND"),sn=/* @__PURE__ */K("TOGGLE_CONNECT_COMMAND"),rn=/* @__PURE__ */K("DIFF_VERSIONS_COMMAND"),ln=/* @__PURE__ */K("CLEAR_DIFF_VERSIONS_COMMAND");function cn(e,t){return new ne(t,{captureTransaction:()=>!e.isBootstrapping,trackedOrigins:new Set([e,null])})}function an(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})}function fn(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{It as $getAnchorAndFocusForUserState,kt as $getYChangeState,ln as CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL,on as CONNECTED_COMMAND,rn as DIFF_VERSIONS_COMMAND__EXPERIMENTAL,sn as TOGGLE_CONNECT_COMMAND,me as createBinding,xe as createBindingV2__EXPERIMENTAL,cn as createUndoManager,_e as createYjsBinding,Dt as getAnchorAndFocusCollabNodesForUserState,an as initLocalState,Mt as removeCursorHighlightRule,vt as renderSnapshot__EXPERIMENTAL,fn as setLocalStateFocus,Ht as syncCursorPositions,Qt as syncLexicalUpdateToYjs,nn as syncLexicalUpdateToYjsV2__EXPERIMENTAL,Vt as syncYjsChangesToLexical,en as syncYjsChangesToLexicalV2__EXPERIMENTAL,tn 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,$getSlotNames as d,$getSlot as h,$removeSlot as p,$setSlot as g,$isRootNode as y,$getWritableNodeState as _,getDeclaredSlots as m,$getRoot as x,RootNode as S,ElementNode as b,TextNode as T,$getState as N,createState as k,getRootOwnerDocument as v,setDOMStyleObject as w,isDOMShadowRoot as C,COLLABORATION_TAG as F,HISTORIC_TAG as M,$addUpdateTag as A,SKIP_SCROLL_INTO_VIEW_TAG as O,$createParagraphNode as E,createCommand as K}from"lexical";import{XmlText as P,XmlElement as j,Map as L,Doc as z,typeListToArraySnapshot as Y,Snapshot as D,typeMapGetAllSnapshot as I,isDeleted as R,XmlHook as $,ContentString as B,ContentFormat as W,emptySnapshot as U,PermanentUserData as H,iterateDeletedStructs as q,snapshot as J,createAbsolutePositionFromRelativePosition as V,createRelativePositionFromTypeIndex as G,compareRelativePositions as X,Item as Q,YMapEvent as Z,YTextEvent as ee,YXmlEvent as te,UndoManager as ne}from"yjs";import{createDOMRange as oe,createRectsFromDOMRange as se}from"@lexical/selection";function ie(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 re(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 le{_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 instanceof le&&ie(394),this._parent.getChildOffset(this)}syncPropertiesFromLexical(e,t,n){const o=this.getPrevNode(n);$e(e,this._xmlElem,o,t)}syncPropertiesFromYjs(e,t){const n=this.getNode();null!==n&&Ye(e,this._xmlElem,n,t)}syncSlotsFromYjs(e,t){Je(e,this._xmlElem,t,this)}syncSlotsFromLexical(e,t,n,o,s){Ve(e,this._xmlElem,t,n,o,s,this)}destroy(e){const t=e.collabNodeMap;Ge(e,this._xmlElem),t.get(this._key)===this&&t.delete(this._key)}}function ce(e,t,n){const o=new le(e,t,n);return e._collabNode=o,o}class ae{_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 fe(e,t){const n=new ae(e,t);return e._collabNode=n,n}class ue{_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($e(e,this._map,o,t),null!==o){const e=o.__text;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=re(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();if(null===n)return;Ye(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 de(e,t,n,o){const s=new ue(e,t,n,o);return e._collabNode=s,s}class he{_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 e instanceof he||ie(90),e.getChildOffset(this)}syncPropertiesFromYjs(e,t){const n=this.getNode();null!==n&&Ye(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}=We(this,o,!1);if(t instanceof he||t instanceof ae||t instanceof le)n.splice(s,1),e-=1;else{if(!(t instanceof ue))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=Be(t._text,i,o-1,"");e.length>0&&(l instanceof ue?l._text+=e:this._xmlText.delete(i,e.length))}else t._text=Be(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}=We(this,o,!0);e instanceof ue?e._text=Be(e._text,t,0,l):this._xmlText.delete(t,l.length),o+=l.length}else{const t=l;if(void 0===je(t))continue;const{node:i,nodeIndex:r,length:c}=We(this,o,!1),a=Le(e,t,this);if(i instanceof ue&&c>0&&c<i._text.length){const e=i._text,t=e.length-c;i._text=Be(e,t,c,""),n.splice(r+1,0,a),s=Be(e,0,t,"")}else n.splice(r,0,a);null!==s&&a instanceof ue&&(a._text=s+a._text,s=null),o+=1}}}}syncChildrenFromYjs(e){const t=this.getNode();if(null===t)return;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,y=null;f!==i&&(p=t.getWritable());for(let i=0;i<f;i++){const l=s[g],_=r[i],m=_.getNode(),x=_._key;if(null!==m&&l===x){const t=o(m);if(d.add(l),t)if(_._key=l,_ instanceof he){const t=_._xmlText;_.syncPropertiesFromYjs(e,null),_.applyChildrenYjsDelta(e,t.toDelta()),_.syncChildrenFromYjs(e)}else _ instanceof ue?_.syncPropertiesAndTextFromYjs(e,null):_ instanceof le?_.syncPropertiesFromYjs(e,null):_ instanceof ae||ie(93);y=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=ze(e,_,n),s=o.__key;if(u.set(s,_),null===y){const e=p.getFirstChild();if(p.__first=s,null!==e){const t=e.getWritable();t.__prev=s,o.__next=t.__key}}else{const e=y.getWritable(),t=y.getNextSibling();if(e.__next=s,o.__prev=y.__key,null!==t){const e=t.getWritable();e.__prev=s,o.__next=e.__key}}i===f-1&&(p.__last=s),p.__size++,y=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)}}this.syncSlotsFromYjs(e,t)}syncSlotsFromYjs(e,t){Je(e,this._xmlText,t,this)}syncPropertiesFromLexical(e,t,n){$e(e,this._xmlText,this.getPrevNode(n),t)}_syncChildFromLexical(t,n,s,i,l,a){const f=this._children[n],u=c(s);f instanceof he&&r(u)?(f.syncPropertiesFromLexical(t,u,i),f.syncChildrenFromLexical(t,u,i,l,a),f.syncSlotsFromLexical(t,u,i,l,a)):f instanceof ue&&o(u)?f.syncPropertiesAndTextFromLexical(t,u,i):f instanceof le&&e(u)&&(f.syncPropertiesFromLexical(t,u,i),f.syncSlotsFromLexical(t,u,i,l,a))}syncSlotsFromLexical(e,t,n,o,s){Ve(e,this._xmlText,t,n,o,s,this)}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,y=0;for(;g<=f&&y<=u;){const t=r[g],i=a[y];if(t===i)this._syncChildFromLexical(e,y,i,n,o,s),g++,y++;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=Pe(e,c(i),this);d.set(i,t),o?(this.splice(e,y,1,t),g++,y++):(this.splice(e,y,0,t),y++)}else this.splice(e,y,1),g++}}const _=g>f,m=y>u;if(_&&!m)for(;y<=u;++y){const t=a[y],n=Pe(e,c(t),this);this.append(n),d.set(t,n)}else if(m&&!_)for(let t=this._children.length-1;t>=y;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 he)t.insertEmbed(s,e._xmlText);else if(e instanceof ue){const n=e._map;null===n.parent&&t.insertEmbed(s,n),t.insert(s+1,e._text)}else e instanceof ae?t.insertEmbed(s,e._map):e instanceof le&&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(void 0!==o&&this.append(o));const r=i.getOffset();-1===r&&ie(95);const l=this._xmlText;if(0!==n){const o=s.slice(t,t+n);for(let t=0;t<o.length;t++)o[t].destroy(e);l.delete(r,i.getSize())}if(o instanceof he)l.insertEmbed(r,o._xmlText);else if(o instanceof ue){const e=o._map;null===e.parent&&l.insertEmbed(r,e),l.insert(r+1,o._text)}else o instanceof ae?l.insertEmbed(r,o._map):o instanceof le&&l.insertEmbed(r,o._xmlElem);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);Ge(e,this._xmlText),t.get(this._key)===this&&t.delete(this._key)}}function pe(e,t,n){const o=new he(e,t,n);return e._collabNode=o,o}class ge{_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 P){if(n||ie(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&&ie(332),o(t)&&ie(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 P){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 ye(e,t,n,o,s){const i={clientID:n.clientID,cursorHighlightSheet:null,cursors:new Map,cursorsContainer:null,doc:n,docMap:o,editor:e,excludedProperties:s||new Map,id:t,isBootstrapping:!1,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))Ae(t,o,e)||(s[t]=n);n.set(o.__type,Object.freeze(s))})})}(i),i}function _e({editor:e,id:t,doc:n,docMap:o,excludedProperties:s,rootName:i="root",getXmlText:r}){const l=r?r(n):n.get(i,P);l instanceof P&&l.doc===n||ie(401);const c=pe(l,null,"root");return c._key="root",{...ye(e,t,n,o,s),collabNodeMap:new Map,root:c}}function me(e,t,n,o,s,i){return null==o&&ie(81),_e({doc:o,docMap:s,editor:e,excludedProperties:i,id:n})}function xe(e,t,n,o,s={}){null==n&&ie(81);const{excludedProperties:i,rootName:r="root-v2",getXmlElement:l}=s,c=l?l(n):n.get(r,j);return c instanceof j&&c.doc===n||ie(402),c.nodeName!==Te&&ie(403,c.nodeName,Te),{...ye(e,t,n,o,i),mapping:new ge,root:c}}function Se(e){return Object.prototype.hasOwnProperty.call(e,"collabNodeMap")}const be="__slots",Te="UNDEFINED",Ne=new Set(["__key","__parent","__next","__prev","__state","__slotHost","__slots"]),ke=new Set(["__first","__last","__size"]),ve=new Set(["__cachedText","__textFormat","__textStyle"]),we=new Set(["__text"]);function Ce(e,t){e.setAttribute(be,t)}function Fe(e){return"__proto__"===e||"constructor"===e||"prototype"===e}function Me(t){return(r(t)||e(t))&&!t.isInline()}function Ae(e,t,n){if(Ne.has(e)||"function"==typeof t[e])return!0;if(o(t)){if(we.has(e))return!0}else if(r(t)&&(ke.has(e)||y(t)&&ve.has(e)))return!0;const s=t.constructor,i=n.excludedProperties.get(s);return null!=i&&i.has(e)}function Oe(e,t){const n=e.__type,{nodeProperties:o}=t,s=o.get(n);return void 0===s&&ie(330,n),s}function Ee(t,n,s,i,l,c){n instanceof he&&r(s)?(n.syncPropertiesFromLexical(t,s,i),n.syncChildrenFromLexical(t,s,i,l,c),n.syncSlotsFromLexical(t,s,i,l,c)):n instanceof ue&&o(s)?n.syncPropertiesAndTextFromLexical(t,s,i):n instanceof le&&e(s)&&(n.syncPropertiesFromLexical(t,s,i),n.syncSlotsFromLexical(t,s,i,l,c))}function Ke(e,t,n,o){const s=d(t),i=m(t.constructor).length>0;if(0===s.length&&!i)return;const r=new L;let l=!1;for(const o of s){const s=h(t,o);if(null===s)continue;const i=Pe(e,s,n);e.collabNodeMap.set(s.__key,i),r.set(o,i.getSharedType()),l=!0}(l||i)&&Ce(o,r)}function Pe(t,s,i){const l=s.__type;let c;if(r(s)){const e=new P;c=pe(e,i,l),c.syncPropertiesFromLexical(t,s,null),c.syncChildrenFromLexical(t,s,null,null,null),Ke(t,s,c,e)}else if(o(s))i instanceof he||ie(389),c=de(new L,s.__text,i,l),c.syncPropertiesAndTextFromLexical(t,s,null);else if(n(s)){i instanceof he||ie(390);const e=new L;e.set("__type","linebreak"),c=fe(e,i)}else if(e(s)){const e=new j;c=ce(e,i,l),c.syncPropertiesFromLexical(t,s,null),Ke(t,s,c,e)}else ie(86);return c._key=s.__key,c}function je(e){const t=De(e,"__type");return"string"!=typeof t&&void 0!==t&&ie(87),t}function Le(e,t,n){const o=t._collabNode;if(void 0===o){const o=e.editor._nodes,s=je(t);"string"!=typeof s&&ie(87),void 0===o.get(s)&&ie(88,s);const i=t.parent,r=void 0===n&&null!==i?Le(e,i):n||null;if(r instanceof he||r instanceof le&&function(e,t){const n=e._xmlElem.getAttribute(be);if(!(n instanceof L))return!1;for(const e of n.values())if(e===t)return!0;return!1}(r,t)||ie(391),t instanceof P)return pe(t,r,s);if(t instanceof L)return r instanceof he||ie(392),"linebreak"===s?fe(t,r):de(t,"",r,s);if(t instanceof j)return ce(t,r,s)}return o}function ze(t,n,o){const s=n.getType(),i=t.editor._nodes.get(s);void 0===i&&ie(88,s);const r=new i.klass;if(r.__parent=o,n._key=r.__key,n instanceof he){const e=n._xmlText;n.syncPropertiesFromYjs(t,null),n.applyChildrenYjsDelta(t,e.toDelta()),n.syncChildrenFromYjs(t)}else n instanceof ue?n.syncPropertiesAndTextFromYjs(t,null):n instanceof le&&(n.syncPropertiesFromYjs(t,null),e(r)||ie(393),n.syncSlotsFromYjs(t,r));return t.collabNodeMap.set(r.__key,n),r}function Ye(e,t,n,o){const s=null===o?t instanceof L?Array.from(t.keys()):t instanceof P||t instanceof j?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(Ae(r,n,e)){"__state"===r&&Se(e)&&(i||(i=n.getWritable()),Re(t,i));continue}const l=n[r];let c=De(t,r);if(l!==c){if(c instanceof z){const t=e.docMap;l instanceof z&&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 De(e,t){return e instanceof L?e.get(t):e instanceof P||e instanceof j?e.getAttribute(t):e[t]}function Ie(e,t,n){e instanceof L?e.set(t,n):e.setAttribute(t,n)}function Re(e,t){const n=De(e,"__state");n instanceof L&&_(t).updateFromJSON(n.toJSON())}function $e(e,t,n,o){const s=Object.keys(Oe(o,e)),i=e.editor.constructor;!function(e,t,n,o){const s=o.__state,i=null===t.doc?void 0:De(t,"__state");if(!s)return;const[r,l]=s.getInternalState(),c=n&&n.__state,a=i instanceof L?i:new L;if(c===s)return;const[f,u]=c&&a.doc?c.getInternalState():[void 0,new Map];if(r)for(const[e,t]of Object.entries(r))f&&t===f[e]||a.set(e,t);for(const[e,t]of l)u.get(e)!==t&&a.set(e.key,e.unparse(t));i||Ie(t,"__state",a)}(0,t,n,o);for(let r=0;r<s.length;r++){const l=s[r],c=null===n?void 0:n[l];let a=o[l];if(c!==a){if(a instanceof i){const t=e.docMap;let n;if(c instanceof i){const e=c._key;n=t.get(e),t.delete(e)}const s=n||new z,r=s.guid;a._key=r,t.set(r,s),a=s,e.editor.update(()=>{o.markDirty()})}Ie(t,l,a)}}}function Be(e,t,n,o){return e.slice(0,t)+o+e.slice(t+n)}function We(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;if(o+=e.getSize(),(n?o>=t:o>t)&&e instanceof ue){let n=t-l-1;return n<0&&(n=0),{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 Ue(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 He(e,t){e.doc.transact(t,e)}function qe(e,n){const o=n._nodeMap.get(e);if(!o)return void x().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():qe(i.__key,n):x().selectStart()}function Je(n,o,s,i){const l=o.getAttribute(be),c=l instanceof L?new Set(l.keys()):new Set;for(const e of d(s))if(!c.has(e)){const t=h(s,e);if(null!==t){const e=n.collabNodeMap.get(t.__key);void 0!==e&&e.destroy(n)}p(s,e)}if(l instanceof L)for(const[o,c]of l.entries()){if(Fe(o))continue;if(!(c instanceof P||c instanceof j||c instanceof L))continue;const l=h(s,o),a=null===l?void 0:n.collabNodeMap.get(l.__key);if(void 0!==a&&a.getSharedType()===c)continue;if(void 0===c._collabNode&&"string"!=typeof De(c,"__type"))continue;if(c instanceof L&&i instanceof le)continue;const f=c._collabNode;if(void 0!==f){const n=t(f._key);if(null!==n&&(n.isAttached()||(r(n)||e(n))&&null!==n.getLatest().__slotHost))continue}const u=Le(n,c,i),d=ze(n,u,null);Me(d)?(void 0!==a&&a.destroy(n),g(s,o,d)):n.collabNodeMap.get(d.__key)===u&&n.collabNodeMap.delete(d.__key)}}function Ve(e,t,n,o,s,i,r){const l=d(n),c=t.getAttribute(be);if(0===l.length&&!(c instanceof L))return;let a;c instanceof L?a=c:(a=new L,Ce(t,a));const f=new Set(l);for(const t of Array.from(a.keys()))if(!f.has(t)){const n=a.get(t),o=null==n?void 0:n._collabNode;void 0!==o&&o.destroy(e),a.delete(t)}const u=e.collabNodeMap;for(const t of l){const l=h(n,t);if(null===l)continue;const c=u.get(l.__key);if(void 0!==c&&a.get(t)===c.getSharedType())Ee(e,c,l,o,s,i);else{const n=a.get(t),o=null==n?void 0:n._collabNode;void 0!==o&&o.destroy(e);const s=Pe(e,l,r);u.set(l.__key,s),a.set(t,s.getSharedType())}}}function Ge(e,t){const n=t.getAttribute(be);if(n instanceof L)for(const t of n.keys()){const o=n.get(t),s=null==o?void 0:o._collabNode;void 0!==s&&s.destroy(e)}}const Xe=e=>e.nodeName===Te,Qe=(t,n,o,s,i,r,l)=>{let c=n.mapping.get(t);if(c&&o&&0===o.size&&!s)return c;const a=Xe(t)?S.getType():t.nodeName,f=n.editor._nodes.get(a);if(void 0===f)throw new Error(`$createOrUpdateNodeFromYElement: Node ${a} is not registered`);if(c||(c=new f.klass,o=null,s=!0),s&&c instanceof b){const e=[],o=t=>{if(t instanceof j){const o=Qe(t,n,new Set,!1,i,r,l);null!==o&&e.push(o)}else if(t instanceof P){const o=tt(t,n,i,r,l);null!==o&&o.forEach(t=>{null!==t&&e.push(t)})}else ie(329)};void 0===i||void 0===r?t.toArray().forEach(o):Y(t,new D(r.ds,i.sv)).filter(e=>!e._item.deleted||et(e._item,i)||et(e._item,r)).forEach(o),Ze(c,e)}const u=t.getAttributes(i);Xe(t)||void 0===i||(et(t._item,i)?et(t._item,r)||(u[mt("ychange")]=l?l("added",t._item.id):{type:"added"}):u[mt("ychange")]=l?l("removed",t._item.id):{type:"removed"});const y={...Oe(c,n)},m={};for(const e in u)e.startsWith(_t)?m[xt(e)]=u[e]:e!==be&&"__proto__"!==e&&"constructor"!==e&&"prototype"!==e&&(y[e]=u[e]);if(Ye(n,y,c,o),o){if(o.size>0){const e=_(c);for(const t of o)if(t.startsWith(_t)){const n=xt(t);e.updateFromUnknown(n,m[n])}}}else _(c).updateFromJSON(m);if(c instanceof b||e(c)){const e=u[be],t=new Set;if(e instanceof L){const o=void 0===i?Array.from(e.entries()):Object.entries(I(e,i));for(const[e,s]of o){if(t.add(e),Fe(e))continue;let o=null;if(s instanceof j&&(o=Qe(s,n,new Set,!1,i,r,l)),null===o)continue;const a=h(c,e);null!==a&&a.getKey()===o.getKey()||(Me(o)?null===o.getLatest().__slotHost&&g(c,e,o):o.isAttached()||ot(s,n))}}for(const e of d(c))t.has(e)||p(c,e)}const x=c.getLatest();return n.mapping.set(t,x),x},Ze=(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,[])},et=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&t.sv.get(e.id.client)>e.id.clock&&!R(t.ds,e.id),tt=(e,t,n,s,i)=>{const r=gt(e,n,s,i);let l=t.mapping.get(e)??[];const c=r.map(e=>e.attributes.t??T.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={...Oe(n,t),...s.p},a=Object.fromEntries(Object.entries(s).filter(([e])=>e.startsWith(_t)).map(([e,t])=>[xt(e),t]));Ye(t,c,n,null),_(n).updateFromJSON(a)}const a=l.map(e=>e.getLatest());return t.mapping.set(e,a),a},nt=(e,t)=>{const n=d(e);if(0===n.length&&0===m(e.constructor).length)return;const o=new L;for(const s of n){const n=h(e,s);null!=n&&o.set(s,it(n,t))}return o},ot=(e,t)=>{if((e instanceof j||e instanceof P)&&t.mapping.delete(e),e instanceof j){const n=e.getAttribute(be);if(n instanceof L)for(const e of n.values())ot(e,t);for(const n of e.toArray())ot(n,t)}},st=(e,t)=>{const n=new j(e.getType()),o={...yt(e,t),...St(e)};for(const e in o){const t=o[e];null!==t&&n.setAttribute(e,t)}if(!(e instanceof b)){const o=nt(e,t);return void 0!==o&&(Ce(n,o),t.mapping.set(n,e)),n}const s=nt(e,t);return void 0!==s&&Ce(n,s),n.insert(0,at(e).map(e=>rt(e,t))),t.mapping.set(n,e),n},it=(t,n)=>{const o=st(t,n);return e(t)&&void 0===n.mapping.getSharedType(t)&&n.mapping.set(o,t),o},rt=(e,t)=>e instanceof Array?((e,t)=>{const n=new P;return pt(n,e,t),n})(e,t):st(e,t),lt=e=>"object"==typeof e&&null!=e,ct=(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||lt(r)&<(l)&&ct(r,l)}return o},at=e=>{if(!(e instanceof b))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},ft=(e,t,n)=>{const o=gt(e);return o.length===t.length&&o.every((e,o)=>{const s=t[o],i=e.attributes.t??T.getType(),r=e.attributes.p??{},l=Object.fromEntries(Object.entries(e.attributes).filter(([e])=>e.startsWith(_t)));return e.insert===s.getTextContent()&&i===s.getType()&&ct(r,yt(s,n))&&ct(l,St(s))})},ut=(e,t,n)=>{if(e instanceof j&&!(t instanceof Array)&&Tt(e,t)){const o=at(t),s=e.getAttributes();return delete s[be],e._length===o.length&&ct(s,{...yt(t,n),...St(t)})&&((e,t,n)=>{const o=d(t),s=e.getAttribute(be);if(!(s instanceof L))return 0===o.length;if(s.size!==o.length)return!1;for(const e of o){const o=h(t,e),i=s.get(e);if(null===o||!(i instanceof j)||n.mapping.get(i)!==o)return!1}return!0})(e,t,n)&&e.toArray().every((e,t)=>ut(e,o[t],n))}return e instanceof P&&t instanceof Array&&ft(e,t,n)},dt=(e,t)=>e===t||e instanceof Array&&t instanceof Array&&e.length===t.length&&e.every((e,n)=>t[n]===e),ht=(e,t,n)=>{const o=e.toArray(),s=at(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 $)break;if(dt(n.mapping.get(e),t))f=!0;else if(!ut(e,t,n))break}for(;c+a<l;a++){const e=o[r-a-1],t=s[i-a-1];if(e instanceof $)break;if(dt(n.mapping.get(e),t))f=!0;else if(!ut(e,t,n))break}return{equalityFactor:c+a,foundMappedChild:f}},pt=(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 B?t+=n.content.str:n.content instanceof W&&(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=yt(e,n);return 0===Object.keys(i).length&&(i=null),{attributes:Object.assign({},o,{...s!==T.getType()&&{t:s},p:i,...St(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}=re(r,c,f);e.delete(h,d),e.insert(h,u),e.applyDelta(l.map(e=>({attributes:e.attributes,retain:e.insert.length})))},gt=(e,t,n,o)=>e.toDelta(t,n,o).map(e=>{const t=e.attributes??{};return"ychange"in t&&(t[mt("ychange")]=t.ychange,delete t.ychange),{...e,attributes:t}}),yt=(e,t)=>{const n=Oe(e,t),o={};return Object.entries(n).forEach(([t,n])=>{const s=e[t];s!==n&&(o[t]=s)}),o},_t="s_",mt=e=>`s_${e}`,xt=e=>{if(!e.startsWith(_t))throw new Error(`Invalid state key: ${e}`);return e.slice(_t.length)},St=e=>{const t=e.__state;if(!t)return{};const[n={},o]=t.getInternalState(),s={};for(const[e,t]of Object.entries(n))s[mt(e)]=t;for(const[e,t]of o)s[mt(e.key)]=e.unparse(t);return s},bt=(t,n,o,s,i)=>{if(n instanceof j&&n.nodeName!==o.getType()&&(!Xe(n)||o.getType()!==S.getType()))throw new Error("node name mismatch!");if(s.mapping.set(n,o),n instanceof j){const r=n.getAttributes(),l={...yt(o,s),...St(o)};for(const e in l)null!=l[e]?r[e]===l[e]||lt(r[e])&<(l[e])&&ct(r[e],l[e])||"ychange"===e||n.setAttribute(e,l[e]):n.removeAttribute(e);for(const e in r)e!==be&&void 0===l[e]&&n.removeAttribute(e);(o instanceof b||e(o))&&((t,n,o,s,i)=>{const r=d(n),l=t.getAttribute(be);if(0===r.length&&!(l instanceof L)&&0===m(n.constructor).length)return;let c;l instanceof L?c=l:(c=new L,Ce(t,c));const a=new Set(r);for(const e of Array.from(c.keys()))if(!a.has(e)){const t=c.get(e);void 0!==t&&ot(t,o),c.delete(e)}for(const t of r){const r=h(n,t);if(null==r)continue;const l=c.get(t);l instanceof j&&(r instanceof b||e(r))&&l===o.mapping.getSharedType(r)?s.has(r.getKey())&&bt(i,l,r,o,s):(l instanceof j&&ot(l,o),c.set(t,it(r,o)))}})(n,o,s,i,t)}const r=at(o),l=r.length,c=n.toArray(),a=c.length,f=Math.min(l,a);let u=0,p=0;for(;u<f;u++){const n=c[u],o=r[u];if(n instanceof $)break;if(dt(s.mapping.get(n),o))o instanceof Array||!(o instanceof b||e(o))||!i.has(o.getKey())||bt(t,n,o,s,i);else{if(!ut(n,o,s))break;s.mapping.set(n,o)}}for(;p+u<f;p++){const n=c[a-p-1],o=r[l-p-1];if(n instanceof $)break;if(dt(s.mapping.get(n),o))o instanceof Array||!(o instanceof b||e(o))||!i.has(o.getKey())||bt(t,n,o,s,i);else{if(!ut(n,o,s))break;s.mapping.set(n,o)}}for(;a-u-p>0&&l-u-p>0;){const e=c[u],o=r[u],f=c[a-p-1],d=r[l-p-1];if(e instanceof P&&o instanceof Array)ft(e,o,s)||pt(e,o,s),u+=1;else{let r=e instanceof j&&Tt(e,o),l=f instanceof j&&Tt(f,d);if(r&&l){const t=ht(e,o,s),n=ht(f,d,s);t.foundMappedChild&&!n.foundMappedChild?l=!1:!t.foundMappedChild&&n.foundMappedChild||t.equalityFactor<n.equalityFactor?r=!1:l=!1}r?(bt(t,e,o,s,i),u+=1):l?(bt(t,f,d,s,i),p+=1):(s.mapping.delete(n.get(u)),n.delete(u,1),n.insert(u,[rt(o,s)]),u+=1)}}const g=a-u-p;if(1===a&&0===l&&c[0]instanceof P?(s.mapping.delete(c[0]),c[0].delete(0,c[0].length)):g>0&&(n.slice(u,u+g).forEach(e=>s.mapping.delete(e)),n.delete(u,g)),u+p<l){const e=[];for(let t=u;t<l-p;t++)e.push(rt(r[t],s));n.insert(u,e)}},Tt=(e,t)=>!(t instanceof Array)&&e.nodeName===t.getType(),Nt=/* @__PURE__ */k("ychange",{isEqual:(e,t)=>e===t,parse:e=>e??null});function kt(e){return N(e,Nt)}const vt=(e,t=J(e.doc),n=U)=>{const{doc:o}=e;o.gc&&ie(325),o.transact(s=>{const i=new H(o);i&&i.dss.forEach(e=>{q(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(()=>{x().clear(),Qe(e.root,e,null,!0,t,n,r)})},e)};function wt(){return"undefined"!=typeof Highlight&&"undefined"!=typeof CSS&&"highlights"in CSS}const Ct=/* @__PURE__ */wt();function Ft(e,t){const n=e.cursorHighlightSheet;if(null===n)return;const o=`::highlight(${t})`;for(let e=n.cssRules.length-1;e>=0;e--){const t=n.cssRules[e];if(null!=t&&t.selectorText===o)return void n.deleteRule(e)}}function Mt(e,t,n=0){const s=t.collabNodeMap.get(e.key);if(void 0===s)return null;let i=e.offset,l=s.getSharedType();if(s instanceof ue){l=s._parent._xmlText;const e=s.getOffset();if(-1===e)return null;i=e+1+i}else if(s instanceof he&&"element"===e.type){const t=e.getNode();r(t)||ie(184);let n=0,s=0,l=t.getFirstChild();for(;null!==l&&s++<i;)o(l)?n+=l.getTextContentSize()+1:n++,l=l.getNextSibling();i=n}return G(l,i,n)}function At(e,t,n=0){const{mapping:s}=t,{offset:i}=e,l=e.getNode(),c=s.getSharedType(l);if(void 0===c)return null;if("text"===e.type){o(l)||ie(326);let e=l.getPreviousSibling(),t=i;for(;o(e);)t+=e.getTextContentSize(),e=e.getPreviousSibling();return G(c,t,n)}if("element"===e.type){r(l)||ie(184);let e=0,t=0,s=l.getFirstChild();for(;null!==s&&t<i;){let n=s.getNextSibling();if(t++,o(s))for(;o(n);)n=n.getNextSibling(),t++;e++,s=n}return G(c,e,n)}return null}function Ot(e,t){return V(e,t.doc)}function Et(e,t){if(null==e){if(null!=t)return!0}else if(null==t||!X(e,t))return!0;return!1}function Kt(e,t){return{color:t,name:e,selection:null}}function Pt(e,t){null!==t.highlight&&(CSS.highlights.delete(t.highlightName),Ft(e,t.highlightName));const n=e.cursorsContainer;if(null===n)return;t.caret.parentNode===n&&n.removeChild(t.caret);const o=t.selections;for(let e=0;e<o.length;e++)o[e].parentNode===n&&n.removeChild(o[e])}function jt(e,t){const n=t.selection;null!==n&&Pt(e,n)}function Lt(e,t,n,o,s,i,r,l,c={}){const a=e.color,f=v(t.editor.getRootElement()),u=f.createElement("span");c.cursor?(u.className=c.cursor,w(u.style,{"--lexical-cursor-color":a,bottom:"0",position:"absolute",right:"-1px",top:"0"})):w(u.style,{"background-color":a,bottom:"0",position:"absolute",right:"-1px",top:"0",width:"1px","z-index":"10"});const d=f.createElement("span");d.textContent=e.name,c.cursorName?d.className=c.cursorName:w(d.style,{"background-color":a,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"}),u.appendChild(d);const h=`lexical-cursor-${t.id}-${n}`;let p=null;return l&&Ct&&(p=new Highlight,CSS.highlights.set(h,p),function(e,t,n){if(!CSS.supports("color",n))return;const o=function(e){const t=e.editor.getRootElement(),n=v(t);let o=e.cursorHighlightSheet;null===o&&(o=new(n.defaultView||window).CSSStyleSheet,e.cursorHighlightSheet=o);const s=null!==t?t.getRootNode():null,i=C(s)?s:n;return i.adoptedStyleSheets.includes(o)||(i.adoptedStyleSheets=[...i.adoptedStyleSheets,o]),o}(e),s=o.insertRule(`::highlight(${t}) { }`,o.cssRules.length),i=o.cssRules[s];i.style.setProperty("background-color",`color-mix(in srgb, ${n} 30%, transparent)`),i.style.setProperty("color","inherit")}(t,h,a)),{anchor:{key:o,offset:s},caret:u,color:a,focus:{key:i,offset:r},highlight:p,highlightName:h,name:d,selections:[]}}function zt(e,t,o,s,i={}){const r=e.editor,l=r.getRootElement(),c=e.cursorsContainer;if(null===c||null===l)return;const a=v(l),f=c.offsetParent;if(null===f)return;const u=f.getBoundingClientRect(),d=t.selection;if(null===o)return null===d?void 0:(t.selection=null,void Pt(e,d));t.selection=o;const h=o.caret,p=o.color,g=o.highlight,y=o.anchor,_=o.focus,m=y.key,x=_.key,S=s.get(m),b=s.get(x);if(null==S||null==b)return;if(null!==g){const e=oe(r,S,y.offset,b,_.offset);if(null===e)return;g.clear(),e.collapsed||g.add(e);const t=e.cloneRange();t.collapse(!1);let o=t.getBoundingClientRect();if(0===o.height&&n(b)){const e=r.getElementByKey(x);null!==e&&(o=e.getBoundingClientRect())}return w(h.style,{"background-color":i.cursor?"":p,bottom:"",height:`${o.height||16}px`,left:o.left-u.left+"px","pointer-events":"none",position:"absolute",right:"",top:o.top-u.top+"px",width:"1px","z-index":"10"}),void(h.parentNode!==c&&c.appendChild(h))}const T=o.selections;let N;if(S===b&&n(S))N=[r.getElementByKey(m).getBoundingClientRect()];else{const e=oe(r,S,y.offset,b,_.offset);if(null===e)return;N=se(r,e)}const k=T.length,C=N.length;for(let e=0;e<C;e++){const t=N[e];let n=T[e];if(void 0===n){n=a.createElement("span"),T[e]=n;const t=a.createElement("span");i.selectionBg&&(t.className=i.selectionBg),n.appendChild(t),c.appendChild(n)}const o=t.top-u.top,s=t.left-u.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,w(n.style,{...r,"--lexical-cursor-color":p}),w(n.firstChild.style,{height:"100%",left:"0",position:"absolute",top:"0",width:"100%"})):(w(n.style,r),w(n.firstChild.style,{...r,"background-color":p,left:"0",opacity:"0.3",top:"0","z-index":"5"})),e===C-1&&h.parentNode!==n&&n.appendChild(h)}for(let e=k-1;e>=C;e--){const t=T[e];c.removeChild(t),T.pop()}}function Yt(e,t){const{anchorPos:n,focusPos:o}=t;let s=null,i=0,r=null,l=0;if(null!==n&&null!==o){const t=Ot(n,e),c=Ot(o,e);null!==t&&null!==c&&([s,i]=$t(e,t.type,t.index),[r,l]=$t(e,c.type,c.index))}return{anchorCollabNode:s,anchorOffset:i,focusCollabNode:r,focusOffset:l}}function Dt(e,t){const{anchorPos:n,focusPos:s}=t,i=n?Ot(n,e):null,r=s?Ot(s,e):null;if(null===i||null===r)return{anchorKey:null,anchorOffset:0,focusKey:null,focusOffset:0};if(Se(e)){const[t,n]=$t(e,i.type,i.index),[o,s]=$t(e,r.type,r.index);return{anchorKey:null!==t?t.getKey():null,anchorOffset:n,focusKey:null!==o?o.getKey():null,focusOffset:s}}let[l,c]=Bt(e.mapping,i),[a,f]=Bt(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 It(e,t){const n=t.awareness.getLocalState();if(null===n)return;const{anchorKey:o,anchorOffset:r,focusKey:l,focusOffset:c}=Dt(e,n);if(null!==o&&null!==l){const e=s();if(!i(e))return;Rt(e.anchor,o,r),Rt(e.focus,l,c)}}function Rt(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,n){const o=t._collabNode;if(void 0===o||!function(e,t){const n=e.root.getSharedType();let o=t;for(;null!=o;){if(o===n)return!0;o=o.parent}return!1}(e,t))return[null,0];if(o instanceof he){const{node:e,offset:t}=We(o,n,!0);return null===e?[o,o._children.length]:[e,t]}return[null,0]}function Bt(e,t){const n=t.type,s=t.index;if(n instanceof j){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 Wt(e,t){return t.awareness.getStates()}function Ut(e,t,n){const{getAwarenessStates:o=Wt,selectionHighlight:s=!1}=n??{},i=Array.from(o(e,t)),r=e.clientID,l=e.cursors,c=e.editor,a=c._config.theme.collaboration,f=c._editorState._nodeMap,u=new Set;for(let t=0;t<i.length;t++){const n=i[t],[o,d]=n;if(0!==o&&o!==r){u.add(o);const{name:t,color:n,focusing:i}=d;let r=null,h=l.get(o);if(void 0===h?(h=Kt(t,n),l.set(o,h)):h.name===t&&h.color===n||(jt(e,h),h.name=t,h.color=n,h.selection=null),i){const{anchorKey:t,anchorOffset:n,focusKey:i,focusOffset:l}=c.read(()=>Dt(e,d));if(null!==t&&null!==i)if(r=h.selection,null===r)r=Lt(h,e,o,t,n,i,l,s,a);else{const e=r.anchor,o=r.focus;e.key=t,e.offset=n,o.key=i,o.offset=l}}zt(e,h,r,f,a)}}const d=Array.from(l.keys());for(let t=0;t<d.length;t++){const n=d[t];if(!u.has(n)){const t=l.get(n);void 0!==t&&(jt(e,t),l.delete(n))}}}function Ht(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;if(null!==o&&(null===l||o.is(n))||null!==n){if(i(o)){const t=o.isCollapsed(),n=!t&&o.isBackward(),s=n?-1:0,i=t||n?0:-1;Se(e)?(h=Mt(o.anchor,e,s),p=Mt(o.focus,e,i)):(h=At(o.anchor,e,s),p=At(o.focus,e,i))}(Et(l,h)||Et(c,p))&&s.setLocalState({...r,anchorPos:h,awarenessData:d,color:f,focusPos:p,focusing:u,name:a})}}function qt(e,t){if(t instanceof Z&&function(e,t){const{target:n}=t;if(!n._item||"__state"!==n._item.parentSub||void 0!==je(n)||!(n.parent instanceof P||n.parent instanceof j||n.parent instanceof L))return!1;const o=Le(e,n.parent).getNode();if(o){const e=_(o.getWritable());for(const o of t.keysChanged)e.updateFromUnknown(o,n.get(o))}return!0}(e,t))return;const{target:n}=t;if(t instanceof Z&&n instanceof L&&null!=n._item&&n._item.parentSub===be&&(n.parent instanceof P||n.parent instanceof j)){const t=Le(e,n.parent);if(t instanceof he){const n=t.getNode();null!==n&&t.syncSlotsFromYjs(e,n)}else if(t instanceof le){const n=t.getNode();null!==n&&t.syncSlotsFromYjs(e,n)}return}const o=Le(e,n);if(o instanceof he&&t instanceof ee){const{keysChanged:n,childListChanged:s,delta:i}=t;if(n.size>0&&o.syncPropertiesFromYjs(e,n),n.has(be)){const t=o.getNode();null!==t&&o.syncSlotsFromYjs(e,t)}s&&(o.applyChildrenYjsDelta(e,i),o.syncChildrenFromYjs(e))}else if(o instanceof ue&&t instanceof Z){const{keysChanged:n}=t;n.size>0&&o.syncPropertiesAndTextFromYjs(e,n)}else if(o instanceof le&&t instanceof te){const{attributesChanged:n}=t;if(n.size>0&&o.syncPropertiesFromYjs(e,n),n.has(be)){const t=o.getNode();null!==t&&o.syncSlotsFromYjs(e,t)}}else ie(82)}function Jt(e,t,n,o,s=Ut){const i=e.editor,r=i._editorState;if(n.forEach(e=>e.delta),i.update(()=>{for(let t=0;t<n.length;t++){const o=n[t];qt(e,o)}Vt(r,e,t),o||A(O)},{onUpdate:()=>{s(e,t),e.root.isEmpty()&&i.update(()=>Gt())},skipTransforms:!0,tag:o?M:F}),n.length>0){const t=n[0].transaction;q(t,t.deleteSet,t=>{if(t.constructor===Q){const n=t.content.type;if(n){const t=n._collabNode;void 0!==t&&e.collabNodeMap.get(t._key)===t&&e.collabNodeMap.delete(t._key)}}})}}function Vt(e,t,n){const o=s();if(i(o))if(Ue(o)){const r=e._selection;i(r)&&(It(t,n),Ue(o))&&qe(o.anchor.key,e),Ht(t,n,r,s())}else It(t,n)}function Gt(){0===x().getChildrenSize()&&x().append(E())}function Xt(e,n,i,r,l,c,a,f){He(e,()=>{r.read(()=>{if(f.has(F)||f.has(M))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 ue)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=x(),o=e.root;o.syncPropertiesFromLexical(e,n,t),o.syncChildrenFromLexical(e,n,t,l,c),o.syncSlotsFromLexical(e,n,t,l,c),0===n.getChildrenSize()&&i._nodeMap.size>1&&e.editor.update(()=>Gt())}const r=s(),u=i._selection;Ht(e,n,u,r)})})}function Qt(e,t){const{target:n}=t;if(n instanceof j&&t instanceof te)Qe(n,e,t.attributesChanged,t.childListChanged);else if(n instanceof P&&t instanceof ee){const t=n.parent;t instanceof j?Qe(t,e,new Set,!0):ie(327)}else if(n instanceof L&&t instanceof Z&&null!=n._item&&n._item.parentSub===be){const t=n.parent;t instanceof j?Qe(t,e,new Set([be]),!1):ie(388)}else ie(328)}function Zt(e,t,n,o,s){const i=e.editor,r=i._editorState;q(o,o.deleteSet,t=>{if(t.constructor===Q){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];Qt(e,o)}Vt(r,e,t),s||A(O)},{discrete:!0,onUpdate:()=>{Ut(e,t),0===e.root.length&&i.update(()=>Gt())},skipTransforms:!0,tag:s?M:F})}function en(e,t){e.mapping.clear();const n=e.editor;n.update(()=>{x().clear(),Qe(e.root,e,null,!0),A(F)},{discrete:!0,onUpdate:()=>{Ut(e,t),0===e.root.length&&n.update(()=>Gt())},skipTransforms:!0,tag:F})}function tn(e,t,n,o,i,r,l,c){const a=c.has(F)||c.has(M);a&&0===l.size||(l.forEach(t=>{e.mapping.deleteNode(t)}),He(e,()=>{o.read(()=>{if(i.has("root")){const t=x();bt(e.doc,e.root,t,e,new Set([...i.keys(),...r])),!a&&0===t.getChildrenSize()&&n._nodeMap.size>1&&e.editor.update(()=>Gt())}const o=s(),l=n._selection;Ht(e,t,l,o)})}))}const nn=/* @__PURE__ */K("CONNECTED_COMMAND"),on=/* @__PURE__ */K("TOGGLE_CONNECT_COMMAND"),sn=/* @__PURE__ */K("DIFF_VERSIONS_COMMAND"),rn=/* @__PURE__ */K("CLEAR_DIFF_VERSIONS_COMMAND");function ln(e,t){return new ne(t,{captureTransaction:()=>!e.isBootstrapping,trackedOrigins:new Set([e,null])})}function cn(e,t,n,o,s){e.awareness.setLocalState({anchorPos:null,awarenessData:s,color:n,focusPos:null,focusing:o,name:t})}function an(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{Dt as $getAnchorAndFocusForUserState,kt as $getYChangeState,rn as CLEAR_DIFF_VERSIONS_COMMAND__EXPERIMENTAL,nn as CONNECTED_COMMAND,sn as DIFF_VERSIONS_COMMAND__EXPERIMENTAL,on as TOGGLE_CONNECT_COMMAND,me as createBinding,xe as createBindingV2__EXPERIMENTAL,ln as createUndoManager,_e as createYjsBinding,Yt as getAnchorAndFocusCollabNodesForUserState,cn as initLocalState,Ft as removeCursorHighlightRule,vt as renderSnapshot__EXPERIMENTAL,an as setLocalStateFocus,Ut as syncCursorPositions,Xt as syncLexicalUpdateToYjs,tn as syncLexicalUpdateToYjsV2__EXPERIMENTAL,Jt as syncYjsChangesToLexical,Zt as syncYjsChangesToLexicalV2__EXPERIMENTAL,en as syncYjsStateToLexicalV2__EXPERIMENTAL};
|
package/package.json
CHANGED
|
@@ -11,13 +11,13 @@
|
|
|
11
11
|
"crdt"
|
|
12
12
|
],
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"version": "0.51.0",
|
|
14
|
+
"version": "0.51.1-nightly.20260921.0",
|
|
15
15
|
"main": "./dist/LexicalYjs.js",
|
|
16
16
|
"types": "./dist/typescript-too-old.d.ts",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@lexical/internal": "0.51.0",
|
|
19
|
-
"@lexical/selection": "0.51.0",
|
|
20
|
-
"lexical": "0.51.0"
|
|
18
|
+
"@lexical/internal": "0.51.1-nightly.20260921.0",
|
|
19
|
+
"@lexical/selection": "0.51.1-nightly.20260921.0",
|
|
20
|
+
"lexical": "0.51.1-nightly.20260921.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"yjs": "^13.6.31"
|