sykpcomposer 0.0.320 → 0.0.321

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/index.umd.js CHANGED
@@ -1514,5 +1514,5 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
1514
1514
  `,D.append(k),b=k}!N&&x.width<1&&r.length>1&&(D.style.width="3px")}_.forEach(C=>{this.hoverList.push([C,b,i])})});this.remoteSelections=[],this.isEditingInProgress=!1,this.hoverList=[],this.trackedNodesKeys=new Set,this.remoteSelectionDOMsMap={},this.activeEditorsKeys={},this.keyboardBindedListener=this._keyboardEventsListener.bind(this),this.mouseBindedListener=this._mouseEventsListener.bind(this),this.resizeBindedListener=this._resizeEventListener.bind(this),this.hideInUI=!1}_mouseEventsListener(t){let o=!1,e=t.target,a=!1,r=3;for(;r&&e;){if(e.__codox_track){o=!0;break}if(e.__lexicalEditor){o=!0,a=!0;break}e=e.parentNode,r--}if(!o)return;let n=null;for(let s in this.activeEditorsKeys){if(e[`__lexicalKey_${s}`]){n=s;break}e.__lexicalEditor&&(n=e.__lexicalEditor._key)}if(!n)return;let i=a?"root":e[`__lexicalKey_${n}`];if(!i||!this.trackedNodesKeys.has(`${i}__${n}`))return;let l=new Set;for(let s=0;s<this.hoverList.length;s++){let d=this.hoverList[s],[c,p,f]=d;if(l.has(f))continue;let h=so.isMousePositionWithinElementCords(t,c);t.type===Io.mouseover&&h&&(p.style.animation=this.isEditingInProgress?so.tooltipAnimations.hideAtOnce:so.tooltipAnimations.showAtOnce,l.add(f)),t.type===Io.mouseout&&(p.style.animation=so.tooltipAnimations.hideWithDelay,l.add(f)),t.type===Io.mousemove&&h&&(p.style.animation=this.isEditingInProgress?so.tooltipAnimations.hideAtOnce:so.tooltipAnimations.showAtOnce,l.add(f))}}_keyboardEventsListener(t){t.type===Io.keypress&&(this.isEditingInProgress||(this.isEditingInProgress=!0)),t.type===Io.keyup&&this.isEditingInProgress&&(this.isEditingInProgress=!1)}_resizeEventListener(t){Vt.mainEditorExists()&&this.paintRemoteSelections(this.remoteSelections)}mount(){window.addEventListener(Io.keypress,this.keyboardBindedListener),window.addEventListener(Io.keyup,this.keyboardBindedListener),window.addEventListener(Io.resize,this.resizeBindedListener),window.addEventListener(Io.scroll,this.resizeBindedListener);for(const t of gx)window.addEventListener(t,this.mouseBindedListener)}unmount(){window.removeEventListener(Io.keypress,this.keyboardBindedListener),window.removeEventListener(Io.keyup,this.keyboardBindedListener),window.removeEventListener(Io.resize,this.resizeBindedListener),window.removeEventListener(Io.scroll,this.resizeBindedListener);for(const t of gx)window.removeEventListener(t,this.mouseBindedListener);this.gcPrevPaintedRemoteSelections()}shouldUpdateRemoteSelections(){return!0}gcPrevPaintedRemoteSelections(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];for(let o in this.remoteSelectionDOMsMap)this.remoteSelectionDOMsMap[o].remove();this.hoverList=[],this.trackedNodesKeys=new Set,this.remoteSelections=t||[],this.remoteSelectionDOMsMap={},this.activeEditorsKeys={}}paintRemoteSelections(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[];this.gcPrevPaintedRemoteSelections(t);let o=Vt.getMainEditorState();o.read&&o.read(()=>{for(let e of this.remoteSelections)if(cy.validateJSONSelection(e,sy.remote))if(cn.isNestedSelectionJSON(e)){let{nestedSelectionJSON:a,nestedEditor:r}=cn.getNestedSelectionJSONFromMainSelectionJSON(e);if(!r)continue;r.getEditorState().read(()=>{let n=cn.JSONToLexical(a);if(n)try{this.paintSingleRemoteSelection({editor:r,selectionJSON:e,lexicalSelection:n,selectedNodes:n.getNodes(),isBackward:n.isBackward()})}catch(i){Pt.warn("[PAINT REMOTE SELECTION] failed for nested editor - ",{error:i,nestedSelectionJSON:a,fullSelection:e,lexicalSelection:n})}else Pt.error("DEBUGGER: [paintRemoteSelections] nested selection from json to lexical is null: ",{selection:e,nestedSelectionJSON:a,lexicalSelection:n})})}else{let a=cn.JSONToLexical(e);if(!a){Pt.error("DEBUGGER: [paintRemoteSelections] selection from json to lexical is null: ",{selection:e,lexicalSelection:a});continue}try{this.paintSingleRemoteSelection({editor:Vt.getMainEditor(),selectionJSON:e,lexicalSelection:a,selectedNodes:a.getNodes(),isBackward:a.isBackward()})}catch(r){Pt.warn("[PAINT REMOTE SELECTION] failed - ",{error:r,fullSelection:e,lexicalSelection:a})}}})}updateRemoteSelections(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";this.shouldUpdateRemoteSelections(t)&&(Pt.log("[updateRemoteSelections] "+o,{newRemoteSelections:t}),Promise.resolve().then(()=>{this.paintRemoteSelections(t),this.hideInUI&&this.hideRemoteSelectionsFromUI()}))}clear(){this.gcPrevPaintedRemoteSelections()}getCurrentRemoteSelections(){return this.remoteSelections}hideRemoteSelectionsFromUI(){this.hideInUI||(this.hideInUI=!0);const t=document.querySelectorAll(".codox_remote_selection");for(let o of t)o.classList.add("hidden_codox_remote_selection")}showHiddenRemoteSelectionsInUI(){this.hideInUI=!1;const t=document.querySelectorAll(".hidden_codox_remote_selection");for(let o of t)o.classList.remove("hidden_codox_remote_selection")}}const ts=new yP;function bP(){return(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).findIndex(u=>u===Nl.editorState)}function Vp(u){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:null,o=Vt.getMainEditorNodesClassesMap();const{klass:e}=o.get(u.type)||{};if(!e)return;const a=e.importJSON(u);if(u.children&&u.children.length)for(const r of u.children)Vp(r,a);return t&&t.getChildrenSize&&t.splice(t.getChildrenSize(),0,[a]),a}function Jp(u){if(u.getChildren)for(let t of u.getChildren())Jp(t);u.remove()}function Ix(u){u.__parent=null,u.__next=null,u.__prev=null}function Mx(u,t){return!!Vt.isLexicalEditorInstance(u)&&!(typeof t!="object"||!t.editorState||(u.update(()=>{try{let o=(0,zt.$getSelection)();const e=u.parseEditorState(t.editorState);if(e.isEmpty())return(0,zt.$getRoot)().clear(),!0;(0,zt.$setSelection)(o),u.setEditorState(e)}catch(o){Pt.error("[stateUpdates][updateNestedEditorState] update nested state and selection error: ",o)}}),0))}function vP(u,t){let o=t;for(const e of u)o=o[e];return o}function Pl(u){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:null,o=arguments.length>2&&arguments[2]!==void 0&&arguments[2],e=null,a=vP(u,o?t:Vt.getMainEditorState().toJSON());return a&&(e=Ml(a)?(0,zt.$getRoot)():Tr.get(a.codoxId)),e||Pt.debug("[WARNING][getLexicalNodeByPathOutOfJSONState] lexical node not found: ",{jsonNode:a,lexicalNode:e,pathArray:u,currentStateJSON:Vt.getMainEditorState().toJSON(),newStateJSON:t,codoxNodes:Tr.nodesToArray(),searchInNewState:o}),e||(o?e:Pl(u,t,!0))}function Rx(u){Pt.log("[applyFullLexicalStateReplace] clear current state and apply new");const t=(0,zt.$getRoot)();t.clear();let o=Vt.getMainEditorNodesClassesMap();function e(a){const r=o.get(a.type).klass.importJSON(a);if(a.children)for(const n of a.children)r.append(e(n));return r}for(const a of u.root.children)t.append(e(a))}function _P(u){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[];if(t.length){Pt.log("[applyDeltasToLexicalState] Original Deltas: ",{newStateJSON:u,deltas:JSON.parse(JSON.stringify(t))});for(const o of t){let{p:e}=o;const a=e[e.length-1],r=a==="children",n=typeof a=="number",i=!n&&!r,l=bP(e),s=l!==-1,d=o.hasOwnProperty("lm")&&typeof o.lm=="number";if(e.length)if(s){let c=l-1,p=Pl(e.slice(0,c),u);if(p){let f=e.slice(0,l),h=u;for(const m of f)h=h[m];let g=kd(e[c]);Mx(p.getWritable()[g],h)}}else{if(r){let c=o.oi;if(!c){Pt.warn("[applyDeltasToLexicalState][====WARNING====] SKIPPED. Delta oi attr expected for path",{delta:o});continue}if(c.some(f=>!(!f.hasOwnProperty("text")||typeof f.text=="string"))){Pt.warn("[applyDeltasToLexicalState][====WARNING====] SKIPPED. Delta oi children contain invalid text value",{delta:o});continue}e.length=e.length-1;let p=Pl(e,u);if(!p)continue;if(c.some(f=>!!f.codoxDId)){try{p=p.getWritable()}catch(m){Pt.debug("[applyDeltasToLexicalState][shouldUpdateLeaves] getWritable error: ",{err:m,delta:o,fullStateJSON:u});continue}let f={};for(let m of p.getChildren())m.codoxDId?f[m.codoxDId]=m:Jp(m);let h=[],g=["codoxDId","codoxId","__key","__parent","__prev","__next"];for(let m=0;m<c.length;m++){let v=c[m],_=m===0,b=m===c.length-1,S=null,C=m>=0?h[m-1]:null;if(v.codoxDId){let x=f[v.codoxDId];if(x){x=x.getWritable();let y=Vp(v);if(Pt.debug("[DELTA_DECORATOR_UPDATE]: ",{exisingDecorator:x,tmpDecorator:y}),!y){Pt.debug("[DELTA_DECORATOR_UPDATE] UPADATE SKIPPED: ",{exisingDecorator:x,tmpDecorator:y});continue}for(let w in y)if(y.hasOwnProperty(w)&&!g.includes(w))if(Vt.isLexicalEditorInstance(y[w])){let E={editorState:y[w].getEditorState().toJSON()};Mx(x[w],E)}else{let E=iy(w),I=v[E];if(I===x[w]||!v.hasOwnProperty(E))continue;let j=I!==void 0&&y[w]!==I?I:y[w];E!=="height"&&E!=="width"||y[w]==="inherit"&&I===0&&(j=y[w]),x[w]=j}y.remove(),Ix(x),S=x,delete f[v.codoxDId]}}S||(S=Vp(v),S.codoxDId&&S.__type==="excalidraw"&&S.__data==="[]"&&(S.__data="{}")),S=S.getWritable(),h.push(S),S.__parent=p.__key,_?(p.__first=S.__key,S.__prev=null,b&&(p.__last=S.__key)):b?(p.__last=S.__key,S.__next=null,S.__prev=C.__key,C.__next=S.__key):(S.__prev=C.__key,C.__next=S.__key),p.__size=h.length}for(let m in f){let v=f[m];v=v.getWritable(),Ix(v),Jp(v),delete f[m]}}else{let f=c.map(h=>Vp(h));p.splice(0,p.getChildrenSize(),f)}}if(n){if(o.ld){const c=o.ld,p=Tr.get(c.codoxId);p.getChildrenSize&&p.getChildrenSize()?Jp(p):p.remove()}if(o.li){let c=Vt.getMainEditorNodesClassesMap();const p=o.li,f=c.get(p.type).klass.importJSON(p);if(e.length===1&&e[0]==="root")(0,zt.$getRoot)().splice(0,0,[f]);else{const h=e[e.length-1];e.length=e.length-2;let g=Pl(e,u);g&&g.splice(h,0,[f])}if(p.children&&p.children.length){let h=function(g,m){const v=c.get(g.type).klass.importJSON(g);if(m.splice(m.getChildrenSize(),0,[v]),g.children&&g.children.length)for(const _ of g.children)h(_,v)};for(const g of p.children)h(g,f)}}if(o.oi||o.od){let{p:c,oi:p,od:f}=o,h=Pl(c,u);if(h)try{let g=h.getWritable();if(p){let m=Object.keys(p);for(let v of m)g[kd(v)]=p[v]}if(f){let m=Object.keys(f);for(let v of m)delete g[kd(v)]}}catch(g){Pt.debug("[applyDeltasToLexicalState][delta oi/od] getWritable error: ",{err:g,delta:o})}}if(d){let{p:c,lm:p}=o,f=c[c.length-1],h=p,g=h<f,m=Pl(c,u);if(m){let v=m.getParent().getChildren(),_=v[f],b=v[h];g?b.insertBefore(_):b.insertAfter(_)}}}if(i){const c=e[e.length-1];let p=kd(c);e.length=e.length-1;let f,h=Pl(e,u);if(!h){Pt.error("Missing node when update node attr from delta: ",{path:e,delta:o,fullStateJSON:u,currentEditorState:Vt.getMainEditorState().toJSON()});continue}try{f=h.getWritable()}catch(m){Pt.debug("[applyDeltasToLexicalState][shouldUpdateBlockAttr] getWritable error: ",{err:m,delta:o})}if(!f)continue;let g=o.oi;if(c==="format"&&(g=vj(g)),c==="direction"&&(h.hasOwnProperty(p)||(p="__dir")),!f.hasOwnProperty(p)){let m=Object.keys(f);for(let v of m){let _=iy(v);if(c.startsWith(_)){p=v;break}}}f[p]=g}}else if(o.oi&&o.oi.root)return Rx(o.oi)}}else Pt.log("[applyDeltasToLexicalState] stop, no deltas: ",t)}function xP(u){let t=null,o=!1;try{t=u.clipboardData.getData(xj.paste),t=JSON.parse(t),typeof t=="object"&&t.nodes&&Array.isArray(t.nodes)&&(o=!0)}catch{return!1}if(!o)return!1;if(o){Tr.clearPastedIds();const e=a=>{if(a.codoxId&&Tr.addPastedId(a.codoxId),a.children&&a.children.length)for(const r of a.children)e(r)};for(const a of t.nodes)e(a)}return!1}var wP=u=>{var t={};return Tn.d(t,u),t};const Dx=wP({useCollaborationContext:()=>Lp});var SP=u=>{var t={};return Tn.d(t,u),t};const Da=SP({LexicalComposerContext:()=>Fu,useLexicalComposerContext:()=>Gn});class Lx{constructor(){this.blacklist=Object.keys(mx).reduce((t,o)=>{let e=mx[o];return t[o]=e.reduce((a,r)=>(a[r]=r,a),{}),t},{}),this._isBlacklistedFound=!1,this._clientCallback=null}_shouldSkipNode(t){return t instanceof zt.TextNode||t instanceof zt.ParagraphNode||t instanceof zt.RootNode}setClientCallback(t){this._clientCallback=t}removeClientCallback(){this._clientCallback=null}invokeClientCallback(){this._clientCallback&&this._clientCallback()}trackBlacklisted(t){let o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"",e=arguments.length>2?arguments[2]:void 0;if(uy||o!==xi.created||this._isBlacklistedFound||!t||!t.__type||this._shouldSkipNode(t))return;let a=e||Vt.getMainEditorState(),r=t.__type,n=this.blacklist[r];n&&a.read(()=>{let i=t.getParent();for(;i!==null;){let l=i?i.__type:null;if(!l)return;if(n[l])return Pt.warn("[ContentNestingsWatcher][trackBlacklisted] FOUND: ",{targetNode:t,targetType:r,parent:i,parentType:l,mutationType:o}),void(this._isBlacklistedFound=!0);i=i.getParent()}})}trackBlacklistedInNestedEditor(t){let o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"",e=arguments.length>3?arguments[3]:void 0;if(o!==xi.created||this._isBlacklistedFound||this._shouldSkipNode(t))return;let a=e.__type,r=t.__type;if(!a||!r)return;let n=this.blacklist[r];n&&n[a]&&(this._isBlacklistedFound=!0,Pt.warn("[ContentNestingsWatcher][trackBlacklistedInNestedEditor] FOUND: ",{targetNode:t,targetType:r,rootNode:e,rootType:a,mutationType:o}))}isBlacklistedFound(){let t=this._isBlacklistedFound;return t&&(this._isBlacklistedFound=!1),t}}const CP=new Lx,La=CP,EP=["editorState","prevEditorState","dirtyElements","dirtyLeaves"];function kP(u,t){if(u==null)return{};var o,e,a=OP(u,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(u);for(e=0;e<r.length;e++)o=r[e],t.includes(o)||{}.propertyIsEnumerable.call(u,o)&&(a[o]=u[o])}return a}function OP(u,t){if(u==null)return{};var o={};for(var e in u)if({}.hasOwnProperty.call(u,e)){if(t.includes(e))continue;o[e]=u[e]}return o}class TP{constructor(){this.nestedEditorsListenersMap={}}_createNestedEditorUpdatesListener(t,o){let e=!1;return function(a){let{editorState:r,prevEditorState:n,dirtyElements:i,dirtyLeaves:l}=a,s=(kP(a,EP),Vt.getMainEditor()),d=Vt.getMainEditorState(),c=r.toJSON(),p=n.toJSON(),f=ly(c,p),h=r._selection,g=n._selection,m=!1,v=null,_=Vt.isOnlySelectionChanged(i,l),b=t[o];if(Pt.debug("[NESTED EDITOR LISTENER] invoked: ",{lexicalNode:t,key:t.__key,onlySelectionChanged:_,newEditorStateJSON:c,prevEditorStateJSON:p,isSameState:f,lexicalSelection:h,prevLexicalSelection:g,mainDirtyLeaves:s._dirtyLeaves.size,mainDirtyElements:s._dirtyElements.size,nestedDirtyLeaves:b._dirtyLeaves.size,nestedDirtyElements:b._dirtyElements.size,nestedEditorKey:b._key}),La.isBlacklistedFound())return e=!0,Pt.debug("[NESTED EDITOR LISTENER] BLACKLISTED FOUND - revert to prev state"),Vt.scanLexicalNodeForNestedEditorAttribute(t)?(b.update(()=>{try{const S=b.parseEditorState(p);if(S.isEmpty())return(0,zt.$getRoot)().clear(),!0;b.setEditorState(S)}catch(S){Pt.error("[NESTED EDITOR LISTENER] BLACKLISTED FOUND - ROLLBACK ERROR: ",S)}}),void La.invokeClientCallback()):void 0;if(e)e=!1;else{if(t.codoxId||t.codoxDId){let S=null;d.read(()=>{S=cn.getNodeAncestorsCodoxIds(t),!t.codoxId&&t.codoxDId&&S.push(t.codoxDId)}),r.read(()=>{let C=iy(o),x=cn.lexicalToJSONNested(h,C,S);v=Vt.getCurrentNestedSelectionJSON(),m=cn.equalSelectionsJSON(v,x),m||Vt.setNestedSelectionJSON(x)})}f&&m||s.update(()=>{try{Pt.debug("[NESTED EDITOR LISTENER] MARKING DIRTY TO TRIGGER UPDATE",{mainTags:s._updateTags,nestedTags:b&&b._updateTags,isSameState:f,isSameSelection:m,onlyNestedSelectionChanged:_,mainDirtyLeaves:s._dirtyLeaves.size,mainDirtyElements:s._dirtyElements.size,nestedDirtyLeaves:b._dirtyLeaves.size,nestedDirtyElements:b._dirtyElements.size,lexicalNode:t,lexicalSelection:h,prevLexicalSelection:g,mainEditorTags:s._updateTags,mainEditorTagsSize:s._updateTags.size}),Vt.addUpdateTag({fromNestedEditor:!0}),t.markDirty()}catch(S){Pt.error("[NESTED EDITOR LISTENER] MARKING DIRTY TO TRIGGER UPDATE - ERROR: ",S)}})}}}_isNestedEditorManaged(t){return!!this.nestedEditorsListenersMap[t]}gc(){for(let t in this.nestedEditorsListenersMap)if(!Vt.getLexicalNodeByKey(t)){let o=this.nestedEditorsListenersMap[t];o&&o(),delete this.nestedEditorsListenersMap[t]}}manageNestedEditorInLexicalNode(t){if(this._isNestedEditorManaged(t.getKey()))return;let o=Vt.scanLexicalNodeForNestedEditorAttribute(t);if(o){let e=t[o],a=this._createNestedEditorUpdatesListener(t,o),r=[];e._nodes.forEach((l,s,d)=>{let{klass:c}=l,p=e.registerMutationListener(c,f=>{for(let[h,g]of f)if(g===xi.created){let m=e.getEditorState()._nodeMap.get(h);m&&La.trackBlacklistedInNestedEditor(m,g,e.getEditorState(),t)}});r.push(p)});let n=(0,Rc.mergeRegister)(e.registerUpdateListener(a),...r),i=t.getKey();this.nestedEditorsListenersMap[i]=n}}gcNestedEditorListenerInLexicalNode(t){let o=t.getKey(),e=this.nestedEditorsListenersMap[o];e&&(e(),delete this.nestedEditorsListenersMap[o])}manageNestedEditorInClonedLexicalNode(t,o){let e=t.getKey();e!==o.getKey()&&this._isNestedEditorManaged(e)&&(this.gcNestedEditorListenerInLexicalNode(t),this.manageNestedEditorInLexicalNode(o))}setNestedEditorSelection(t){let{nestedSelectionJSON:o,nestedEditor:e}=cn.getNestedSelectionJSONFromMainSelectionJSON(t);if(!e)return!1;let a=!0;return e.update(()=>{try{let r=cn.JSONToLexical(o);(0,zt.$setSelection)(r),Pt.debug("[setNestedEditorSelection]: lexical nested selection: ",r)}catch(r){Pt.error("[setNestedEditorSelection] set nested selection error: ",r),a=!1}}),a}clearListeners(){for(let t in this.nestedEditorsListenersMap){let o=this.nestedEditorsListenersMap[t];o&&o(),delete this.nestedEditorsListenersMap[t]}}}const AP=new TP,ta=AP,NP=function(u){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[];try{let o=(0,zt.createEditor)({namespace:"validation",nodes:[...t],onError:i=>{throw i},parentEditor:null});const e=new Lx,a=o.parseEditorState(u);if(a.isEmpty())return;o.setEditorState(a);let r=o.getEditorState();const n=r._nodeMap[Symbol.iterator]();for(const i of n){let[l,s]=i;if(s&&(e.trackBlacklisted(s,xi.created,r),e.isBlacklistedFound()))throw new Error(wj)}}catch(o){throw o}};class jP{constructor(){this.removeCandidateTableKeys=new Set,this.validateTableCandidateKeys=new Set,this.tableFixActions=[]}_scanForCellHeaderState(t,o,e,a){if(o.length<a)return null;let r,n=o.some(l=>l.__headerState===Ma.BOTH||l.__headerState===Ma.ROW),i=t.some((l,s)=>{if(l.__size<a)return!1;let d=l.getChildAtIndex(e);return!(!d||d.__headerState!==Ma.BOTH&&d.__headerState!==Ma.COLUMN)});return n&&i?r=Ma.BOTH:n&&!i?r=Ma.ROW:i&&!n&&(r=Ma.COLUMN),r}_isValidCellChildren(t){for(let o of t)if(Uc(o)||!zc(o)&&xr(o))return!1;return!0}_createEmptyCell(){let t=(0,kr.$createTableCellNode)();return t.append((0,zt.$createParagraphNode)()),t}_wrapInvalidCellChildrenIntoParagraph(t){let o=(0,zt.$createParagraphNode)().getWritable(),e=t.getChildren();(t=t.getWritable()).__first=o.__key,t.__last=o.__key,t.__size=1,o.__parent=t.__key,e.forEach((a,r)=>{(a=a.getWritable()).__parent=null,o.append(a)})}_createFixAction_APPEND_CELLS_TO_ROW(t,o){return()=>{Pt.debug("[TablesValidator][FIX TABLE ACTION - APPEND_CELLS_TO_ROW] invoked: ",{rowKey:t,numOfCellsToAppend:o});let e=(0,zt.$getNodeByKey)(t);for(;o;){let a=(0,kr.$createTableCellNode)().append((0,zt.$createParagraphNode)());a.setRowSpan(1).setColSpan(1),e.append(a),o--}}}_createFixAction_ADD_PARAGRAPH_TO_EMPTY_CELL(t){return()=>{Pt.debug("[TablesValidator][FIX TABLE ACTION - ADD_PARAGRAPH_TO_EMPTY_CELL] invoked: ",{cellKey:t}),(0,zt.$getNodeByKey)(t).append((0,zt.$createParagraphNode)())}}_createFixAction_WRAP_CELL_CHILDREN_IN_PARAGRAPH(t){return()=>{Pt.debug("[TablesValidator][FIX TABLE ACTION - WRAP_CELL_CHILDREN_IN_PARAGRAPH] invoked: ",{cellKey:t});let o=(0,zt.$getNodeByKey)(t);this._wrapInvalidCellChildrenIntoParagraph(o)}}_createFixAction_ADD_ROW_CELL_TO_TABLE_NODE(t){return()=>{Pt.debug("[TablesValidator][FIX TABLE ACTION - ADD_ROW_CELL_TO_EMPTY_TABLE_NODE] invoked: ",{tableKey:t});let o=(0,zt.$getNodeByKey)(t),e=(0,kr.$createTableRowNode)();e.append(this._createEmptyCell()),o.append(e)}}_createFixAction_ADD_CELL_TO_EMPTY_ROW_NODE(t,o){return()=>{for(o||(o=1);o;)(0,zt.$getNodeByKey)(t).append(this._createEmptyCell()),o--}}_createFixAction_WRAP_INVALID_ROW_NODE(t,o){return()=>{Pt.debug("[TablesValidator][FIX TABLE ACTION - WRAP_INVALID_ROW_NODE] invoked: ",{tableKey:t,rowKey:o});let e=(0,zt.$getNodeByKey)(t);if(!e)return;let a=(0,zt.$getNodeByKey)(o);if(!a)return;e=e.getWritable(),a=a.getWritable();let r=a.getPreviousSibling(),n=a.getNextSibling();a.__parent=null,a.__prev=null,a.__next=null;let i=(0,kr.$createTableRowNode)();if((0,kr.$isTableCellNode)(a))a.getChildren().length?this._isValidCellChildren()||this._wrapInvalidCellChildrenIntoParagraph(a):a.append((0,zt.$createParagraphNode)()),i.append(a);else{let l=this._isValidCellChildren([a]),s=(0,kr.$createTableCellNode)();if(i.append(s),l)s.append(a);else{let d=(0,zt.$createParagraphNode)();d.append(a),s.append(d)}}i.__parent=e.__key,e.__first===a.__key&&(e.__first=i.__key),e.__last===a.__key&&(e.__last=i.__key),r&&(r=r.getWritable(),r.__next=i.__key,i.__prev=r.__key),n&&(n=n.getWritable(),n.__prev=i.__key,i.__next=n.__key)}}_createFixAction_WRAP_INVALID_CELL_NODE(t,o){return()=>{Pt.debug("[TablesValidator][FIX TABLE ACTION - WRAP_INVALID_CELL_NODE] invoked: ",{rowKey:t,cellKey:o});let e=(0,zt.$getNodeByKey)(t);if(!e)return;let a=(0,zt.$getNodeByKey)(o);if(a.remove(),a=(0,zt.$createParagraphNode)(),!a)return;e=e.getWritable(),a=a.getWritable();let r=a.getPreviousSibling(),n=a.getNextSibling(),i=(0,kr.$createTableCellNode)();if(i.__parent=e.__key,e.__first===a.__key&&(e.__first=i.__key),e.__last===a.__key&&(e.__last=i.__key),r&&(r=r.getWritable(),r.__next=i.__key,i.__prev=r.__key),n&&(n=n.getWritable(),n.__prev=i.__key,i.__next=n.__key),a.__parent=null,a.__prev=null,a.__next=null,this._isValidCellChildren([a]))i.append(a);else{let l=(0,zt.$createParagraphNode)();l.append(a),i.append(l)}}}_createFixAction_APPLY_HEADER_STATE_TO_CELL(t,o){return()=>{Pt.debug("[TablesValidator][FIX TABLE ACTION - APPLY_HEADER_STATE_TO_CELL] invoked: ",{cellKey:t,headerStateToApply:o});let e=(0,zt.$getNodeByKey)(t);e&&(e=e.getWritable(),e.__headerState=o)}}clear(){this.removeCandidateTableKeys=new Set,this.validateTableCandidateKeys=new Set,this.tableFixActions=[]}tableRemoveEventListener(t){let o=Vt.getMainEditorState()._selection;if(Pt.debug(`[${t}]`,{selection:o}),!(0,zt.$isRangeSelection)(o))return;let e=[];try{let a=Vt.getLexicalNodeByKey(o.anchor.key),r=Vt.getLexicalNodeByKey(o.focus.key);a&&r&&(e=o.isBackward()?r.getNodesBetween(a):a.getNodesBetween(r))}catch(a){Pt.warn("[TablesValidator][tableRemoveEventListener] get range selection nodes internal lexical error: ",a)}e.forEach(a=>{(0,kr.$isTableNode)(a)&&this.removeCandidateTableKeys.add(a.__key)})}tableNodeRemoveListener(t){this.removeCandidateTableKeys.has(t)&&this.removeCandidateTableKeys.delete(t)}shouldGCRemovedTables(){return!!this.removeCandidateTableKeys.size}gcRemovedTables(){Pt.debug("[TablesValidator][gcRemovedTable] candidate table keys ",{tableKeys:this.removeCandidateTableKeys}),Vt.getMainEditor().update(()=>{Array.from(this.removeCandidateTableKeys).forEach(t=>{let o=(0,zt.$getNodeByKey)(t);o&&o.remove()}),this.removeCandidateTableKeys.clear(),(0,zt.$addUpdateTag)(Li.historic)})}tableUpdateListener(t){this.validateTableCandidateKeys.add(t)}tableRowNodeChangesListener(t){let o=arguments.length>1&&arguments[1]!==void 0&&arguments[1],e=Vt.getLexicalNodeByKey(t);if(!e)return void(o&&Pt.debug("[TablesValidator][tableRowNodeChangesListener] no row node found in lexical: ",{tableRowNodeKey:t}));let a=e.__parent;a?this.validateTableCandidateKeys.add(a):Pt.debug("[tableRowNodeChangesListener] no parent table for row node found in lexical: ",{rowNode:e})}tableCellNodeChangesListener(t){let o=Vt.getLexicalNodeByKey(t);if(!o||!o.__parent)return;let e=Vt.getLexicalNodeByKey(o.__parent);e&&e.__parent&&this.validateTableCandidateKeys.add(e.__parent)}shouldValidateUpdatedTables(){return!!this.validateTableCandidateKeys.size}validateUpdatedTables(){let t=Array.from(this.validateTableCandidateKeys);return Vt.getMainEditorState().read(()=>{for(let o of t){let e=Vt.getLexicalNodeByKey(o);if(!e)continue;let a=e.getChildren();if(!a.length){this.tableFixActions.push(this._createFixAction_ADD_ROW_CELL_TO_TABLE_NODE(o));continue}let r=0;a.forEach(s=>{s.__size>r&&(r=s.__size)});let n=[],i=a.map((s,d)=>{if(!(0,kr.$isTableRowNode)(s))return this.tableFixActions.push(this._createFixAction_WRAP_INVALID_ROW_NODE(o,s.__key)),"invalid_row_node";let c=s.getChildren();if(!c.length&&!n.length)return this.tableFixActions.push(this._createFixAction_ADD_CELL_TO_EMPTY_ROW_NODE(s.__key,r)),"empty_row_should_add_cell";if(!c.length&&n.length)return n=[],"empty_row_should_be_empty";let p=0;if(n.length){let h=[];n.forEach(g=>{let[m,v]=g;p+=v,m--,m&&h.push([m,v])}),n=[...h]}let f=c.map((h,g)=>{if(!(0,kr.$isTableCellNode)(h))return this.tableFixActions.push(this._createFixAction_WRAP_INVALID_CELL_NODE(s.__key,h.__key)),p++,"invalid_cell_node_should_wrap_in_cell";let m,v=h.getChildren(),_=!v.length;if(_?this.tableFixActions.push(this._createFixAction_ADD_PARAGRAPH_TO_EMPTY_CELL(h.__key)):(m=this._isValidCellChildren(v),m||this.tableFixActions.push(this._createFixAction_WRAP_CELL_CHILDREN_IN_PARAGRAPH(h.__key))),h.__rowSpan>1){let b=h.__rowSpan,S=h.__colSpan;n.push([b-1,S])}if(p+=h.__colSpan,h.__headerState===Ma.NO_STATUS){let b=this._scanForCellHeaderState(a,c,g,r);b&&this.tableFixActions.push(this._createFixAction_APPLY_HEADER_STATE_TO_CELL(h.__key,b))}return{cellKey:h.__key,rowKey:s.__key,tableKey:o,colSpan:h.__colSpan,rowSpan:h.__rowSpan,headerState:h.__headerState,childrenAreValid:m,isEmptyCell:_}});if(p<r){let h=r-p;this.tableFixActions.push(this._createFixAction_APPEND_CELLS_TO_ROW(s.__key,h))}return{realRowLength:p,rowKey:s.__key,tableKey:o,cells:f}}),l=!this.tableFixActions.length;Pt[l?"debug":"warn"](`[TablesValidator][validateUpdatedTables] IS TABLE VALID: ${l}`,{tableNodeKey:o,tableValidationMatrix:i,requiredRowLength:r}),this.validateTableCandidateKeys.delete(o)}}),!this.tableFixActions.length}shouldFixTablesStructure(){return!!this.tableFixActions.length}fixTablesStructure(){if(!this.tableFixActions.length)return;let t=Vt.getMainEditor();Pt.log("[TablesValidator][fixTablesStructure]: fix actions to apply - count: ",this.tableFixActions.length),t.update(()=>{for(let o of this.tableFixActions)o();this.tableFixActions=[],(0,zt.$addUpdateTag)(Li.historic)})}ensureDocTablesAreValid(t){return this.shouldGCRemovedTables()?(Pt.warn("[TablesValidator][GARBAGE COLLECT TABLE NODES AFTER TABLE REMOVAL ATTEMPT]"),this.gcRemovedTables(),!1):!(this.shouldValidateUpdatedTables()&&(Pt.debug("[TablesValidator][shouldValidateUpdatedTables] invoked"),!this.validateUpdatedTables()))||(Pt.warn("[TablesValidator][shouldValidateUpdatedTables] INVALID LEXICAL TABLE(S) STRUCTURE FOUND - FIXING",{state:JSON.parse(JSON.stringify(t.toJSON()))}),this.fixTablesStructure(),!1)}}const ws=new jP,PP=["contentChanged"],IP=["state","remoteSelection"];function Bx(u,t){var o=Object.keys(u);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(u);t&&(e=e.filter(function(a){return Object.getOwnPropertyDescriptor(u,a).enumerable})),o.push.apply(o,e)}return o}function Bc(u){for(var t=1;t<arguments.length;t++){var o=arguments[t]!=null?arguments[t]:{};t%2?Bx(Object(o),!0).forEach(function(e){MP(u,e,o[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(u,Object.getOwnPropertyDescriptors(o)):Bx(Object(o)).forEach(function(e){Object.defineProperty(u,e,Object.getOwnPropertyDescriptor(o,e))})}return u}function MP(u,t,o){return(t=RP(t))in u?Object.defineProperty(u,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):u[t]=o,u}function RP(u){var t=DP(u,"string");return typeof t=="symbol"?t:t+""}function DP(u,t){if(typeof u!="object"||!u)return u;var o=u[Symbol.toPrimitive];if(o!==void 0){var e=o.call(u,t||"default");if(typeof e!="object")return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(u)}function Fx(u,t){if(u==null)return{};var o,e,a=LP(u,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(u);for(e=0;e<r.length;e++)o=r[e],t.includes(o)||{}.propertyIsEnumerable.call(u,o)&&(a[o]=u[o])}return a}function LP(u,t){if(u==null)return{};var o={};for(var e in u)if({}.hasOwnProperty.call(u,e)){if(t.includes(e))continue;o[e]=u[e]}return o}const uy={DEBUG:!1,VERSION:"1.0.5",NAME:"@codoxhq/lexical-provider",SDKUI_SOURCE_PATH:"../../../sdkui/dist-production2/codox.bundle.js"}.LOCAL==="true";Pt.info("MODE: ","production");const BP=u=>async()=>{const{state:t,timestamp:o}=await u();if(!Vt.isValidJSONState(t))throw new Error("Invalid state received from fetchDocOnNetworkReconnect hook");const{commentThreads:e,root:a}=t,r={content:{comments:e,root:a},timestamp:o};return Pt.info("[decorateFetchOnReconnctHook] hook invoked: ",{returnObj:r}),r};let Kp=0,Il=null,dy=!1,Bi={},fy={};const FP=(0,pt.forwardRef)((u,t)=>{let{onBlacklistedInsert:o}=u;const e=(0,pt.useContext)(Da.LexicalComposerContext);if(!e)throw new Error("[CodoxCollabPlugin] CodoxCollabPlugin must be inited inside <LexicalComposer> component - LexicalComposerContext is missing");const[a]=(0,Da.useLexicalComposerContext)(),r=(0,Dx.useCollaborationContext)();(0,pt.useEffect)(()=>{if(Pt.debug("[INIT] lexical context check: ",{lexicalContext:e,editor:a}),!a)return;Pt.log("[useEffect][editor] Editor instance changed: ",{editor:a,key:a._key}),Vt.setMainEditor(a),Tr.gcAbandonedNodes(),ta.gc(),ws.clear(),Pt.log("[useEffect][editor] subscribe to editor changes");const _=(0,Rc.mergeRegister)(a.registerUpdateListener(g),a.registerCommand(zt.PASTE_COMMAND,xP,zt.COMMAND_PRIORITY_CRITICAL),a.registerCommand(zt.UNDO_COMMAND,()=>{Vt.setUndoInvoked(!0)},zt.COMMAND_PRIORITY_CRITICAL),a.registerCommand(zt.REDO_COMMAND,()=>{Vt.setRedoInvoked(!0)},zt.COMMAND_PRIORITY_CRITICAL),a.registerCommand(zt.KEY_DELETE_COMMAND,(S,C)=>{ws.tableRemoveEventListener("KEY_DELETE_COMMAND")},zt.COMMAND_PRIORITY_CRITICAL),a.registerCommand(zt.KEY_BACKSPACE_COMMAND,(S,C)=>{ws.tableRemoveEventListener("KEY_BACKSPACE_COMMAND")},zt.COMMAND_PRIORITY_CRITICAL),a.registerCommand(zt.CUT_COMMAND,(S,C)=>{ws.tableRemoveEventListener("CUT_COMMAND")},zt.COMMAND_PRIORITY_CRITICAL),...m());ts.mount(),Vt.alignStateSelectionJSONsFromLatestEditor(),Pt.debug("New editor mounted: ",{isCodoxStarted:Vt.isCodoxStarted,codoxLexicalEditorManager:Vt,nestedEditorsProcessor:ta});let b=a._onError;return a._onError=S=>{Pt.error("[ERROR HANDLER WRAPPER] error from editor: ",S),b&&b(S),h()},o&&La.setClientCallback(o),()=>{Vt.getMainEditorKey()&&(Pt.debug("Unmount prev editor"),_(),Vt.removeMainEditor(),ts.unmount(),Vt.clearJSONs(),_r.clear(),ws.clear(),Vt.isCodoxStarted&&(Pt.debug("EDITOR USE_EFFECT stopping codox"),n(),Vt.setIsCodoxStarted(!1)),La.removeClientCallback())}},[a]);const n=()=>{Vt.isCodoxStarted&&(Pt.log("[stopCodoxInstance] stopping codox"),Vt.setIsCodoxStarted(!1),uy||xs().stop(),Vt.clearJSONs(),Tr.clearAll(),ts.clear(),_r.resetComments(),ta.clearListeners())},i=async _=>{Pt.debug("[startCodoxInstance] invoked",{codoxConfigFromClient:_}),Vt.isCodoxStarted&&n(),xs().createNewInstance(),Pt.debug("[startCodoxInstance] instance created");for(let B in fy)xs().instance.on(B,fy[B]);if(Pt.debug("[startCodoxInstance] events subscribed"),Bi=_,Il=Bi.docId,!Il)return Pt.error("[startCodoxInstance] - start codox skipped - docId is missing",{docId:Il});let b=_r.initialCommentsExist();Pt.debug("[startCodoxInstance] initCommentsExist: ",b),b&&(_r.activateInitialComments(a,Tr),Pt.log("[activateInitialComments] "));let S=Vt.getMainEditorContentStateJSON();if(!Vt.isValidJSONState(S))throw Pt.error("[startCodoxInstance] - start codox skipped - invalid init state",{docId:Il,initJSONState:S}),new Error("start codox skipped - invalid init state");Pt.log("[startCodoxInstance] starting codox with: ",{docId:Il,initJSONState:S,config:Bi,codoxComments:_r});let{username:C,apiKey:x,getServerState:y,domain:w="",demo:E=!1,hooks:I}=Bi;I&&I.fetchDocOnNetworkReconnect&&(I.fetchDocOnNetworkReconnect=BP(I.fetchDocOnNetworkReconnect));const j=Fx(I,PP);await xs().start(xs().createConfig(Bc(Bc({},Bi),{},{docId:Il,username:C,apiKey:x,domain:w,hooks:Bc({syncState:d,getState:s,getServerState:async()=>await y(Il)},j),editorInstanceHooks:{getSelection:()=>Vt.getCurrentActiveSelectionJSON(),setSelection:B=>c(B),getState:s,setState:B=>{const{root:N,comments:D}=B;Pt.info("DEBUG: EDITOR INSTANCE setState:",{fullState:B}),p({state:{root:N},selection:Vt.getCurrentActiveSelectionJSON()},ts.getCurrentRemoteSelections()),_r.setAllComments(D)},enableEditor:()=>{Vt.disableEditorReadOnlyMode()},disableEditor:()=>{console.log("[CodoxCollabPlugin] disabling editor"),Vt.enableEditorReadOnlyMode(),ts.updateRemoteSelections([])},getContent:()=>{let B=Vt.composeFullStateWithRootAndComments();return Pt.info("[getContent]: ",B),{state:B}}},appServer:Bi.appServer,demo:E}))),Pt.log("[startCodoxInstance] codox started - first sync invoking"),Vt.setIsCodoxStarted(!0),r.clientID=Bi.username,r.name=Bi.username,f({shouldValidateLexicalState:!1})},l=()=>{i(Bi)},s=()=>({state:Bc(Bc({},Vt.getMainEditorContentStateJSON()),{},{comments:_r.getAllComments()})}),d=_=>{if(!Vt.isCodoxStarted)return;Pt.log("[SYNC_STATE]: Before sync payload = ",_);const b=xs().sync({meta:_}),{state:S,remoteSelection:C=[]}=b,x=Fx(b,IP);if(Pt.log("[SYNC_STATE]: After sync",{state:S,remoteSelection:C,rest:x}),!S)return Pt.error("[SYNC_STATE] abort apply - synced state is not valid - restarting codox"),l();const y=S.state;Pt.log("[SYNC_STATE] synced state: ",{synced:JSON.parse(JSON.stringify(y))});let{stateFromSync:w,commentsFromSync:E}=Vt.extractStateAndCommentsFromSynced(y);if(!Vt.isValidJSONState(w.state))return Pt.error("[SYNC_STATE] - invalid state from sync - local update skipped - restarting codox",{contentState:w.state}),l();p(w,C),_r.setAllComments(E)},c=_=>{if(!Vt.isCodoxStarted||(Pt.log("[setLocalSelectionFromSync] synced selection: ",{syncedSelectionJSON:_}),!cy.validateJSONSelection(_,sy.local)))return;let b=Vt.getCurrentActiveSelectionJSON();if(cn.equalSelectionsJSON(b,_))return void Pt.log("[setLocalSelectionFromSync] STOP - local and synced selections are equal");let S=cn.isNestedSelectionJSON(_);a.update(()=>{Pt.log("[setLocalSelectionFromSync] json selection to apply: ",{syncedSelectionJSON:_});const C=cn.JSONToLexical(_);if(Pt.log("[setLocalSelectionFromSync] lexical selection to apply: ",C),S){let x=ta.setNestedEditorSelection(_);Vt.setNestedSelectionJSON(x?_:null)}else(0,zt.$setSelection)(C),Vt.setMainSelectionJSON(_);Pt.log("[setLocalSelectionFromSync] selection updated. latest selection: ",{latestSelectionJSON:Vt.getCurrentActiveSelectionJSON()})})},p=function(){let{state:_,selection:b,stateReplace:S}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},C=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[],x=arguments.length>2&&arguments[2]!==void 0?arguments[2]:"",y=Vt.getMainEditorContentStateJSON();Pt.log("[updateEditor] invoked: ",{currentContentStateJSON:JSON.parse(JSON.stringify(y)),newStateJSON:JSON.parse(JSON.stringify(_)),newSelectionJSON:b,remoteSelection:C,stateReplace:S,editor:a}),b===void 0&&Pt.error("SELECTION FROm SYNC IS UNDEFINED - will default prev selection",b);const w=ly(y,_),E=cn.equalSelectionsJSON(Vt.getCurrentActiveSelectionJSON(),b);a.update(()=>{if(Vt.addUpdateTag({isSameState:w,isSameSelection:E,updateTag:x}),S)Pt.log("[updateEditor] invoke full stateReplace after sync"),Rx(_),(0,zt.$addUpdateTag)("codox_sync_state_changes");else{Pt.log("[updateEditor] invoke deltas diff");let j=xs().diff(y,_,{keyNames:{default:"codoxId"}});Pt.log("JSON_DIFF_ANALYSIS: ",{currentContentStateJSON:JSON.parse(JSON.stringify(y)),newStateJSON:_,deltas:j&&JSON.parse(JSON.stringify(j))}),j&&j.length&&(Pt.log("[updateEditor] apply deltas to lexical state"),_P(_,j),(0,zt.$addUpdateTag)("codox_sync_state_changes"))}let I=cn.isNestedSelectionJSON(b);if(cy.validateJSONSelection(b,sy.local)||(b=Vt.getCurrentActiveSelectionJSON()),I){let j=ta.setNestedEditorSelection(b);Vt.setNestedSelectionJSON(j?b:null),Pt.log("[updateEditor] nested selection updated",j?b:null)}else if(b!==void 0){const j=cn.JSONToLexical(b);Pt.log("[updateEditor] updated selection to apply: ",{isSameSelection:E,newSelectionJSON:b,lexicalSelection:j}),(0,zt.$setSelection)(j),Vt.setMainSelectionJSON(b),Pt.log("[updateEditor] selection updated",b)}},{onUpdate:()=>{w||ts.updateRemoteSelections(C,"from onUpdate hook")}}),w&&ts.updateRemoteSelections(C,"from direct updateEditor")},f=function(){let{upd_call_counter:_="",shouldValidateLexicalState:b=!0}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!Vt.isCodoxStarted)return;let S=Vt.composeFullStateWithRootAndComments();if(b&&!Vt.isValidJSONState(S))return Pt.error("[invokeSync] - invalid lexical state for sync - sync invoke skipped - restarting codox",{lexicalJSONState:{root:S.root}}),l();Pt.log("[invokeSync] SYNC INVOKED ",{upd_call_counter:_});const C={state:{state:S,selection:Vt.getCurrentActiveSelectionJSON()}};Pt.log("[codoxSync]: Before sync",{local:C,upd_call_counter:_}),Pt.log("[codoxSync]: Before sync state",JSON.parse(JSON.stringify(C.state)));let{state:x,remoteSelection:y=[],changes:w}=xs().sync({state:C,meta:{}});if(Pt.log("[codoxSync]: After sync",{afterSyncState:JSON.parse(JSON.stringify(x)),remoteSelection:y,changes:w}),!x)return Pt.error("[codoxSync] abort apply - synced state is not valid - restarting codox "),l();const E=x.state;Pt.log("[codoxSync]: synced state: ",JSON.parse(JSON.stringify(E)),_);let{stateFromSync:I,commentsFromSync:j}=Vt.extractStateAndCommentsFromSynced(E);if(!Vt.isValidJSONState(I.state))return Pt.error("[invokeSync] - invalid state from sync - local update skipped - restarting codox",{contentState:I.state}),l();p(I,y),_r.setAllComments(j)},h=()=>{Pt.warn("[rollbackStateDuringUpdateError] rollback invoked");let _=Vt.getPrevContentStateJSON(),b=Vt.getPrevMainSelectionJSON();Pt.log("[rollbackStateDuringUpdateError] values: ",{prevState:_,currentState:Vt.getMainEditorContentStateJSON(),prevSelection:b,currentSelection:Vt.getCurrentActiveSelectionJSON(),codoxComments:_r}),p({state:_,selection:b},ts.getCurrentRemoteSelections(),Li.historic);let S=Vt.undoInvoked(),C=Vt.redoInvoked();_r.gcAbandonedNodeKeys(Vt.getMainEditorStateNodesMap()),S&&a.dispatchCommand(zt.CAN_REDO_COMMAND,!1),C&&a.dispatchCommand(zt.CAN_UNDO_COMMAND,!1)},g=_=>{let{editorState:b,prevEditorState:S,tags:C,dirtyElements:x,dirtyLeaves:y}=_;if(dy)return dy=!1,void Pt.debug("[editorUpdatesListener] invoked blacklisted queued selection change - stop");if(La.isBlacklistedFound())return dy=!0,Pt.warn("[editorUpdatesListener] BLACKLISTED CHANGES FOUND - revert back to prev state"),((H,W)=>{let K=null,F=null;W.read(()=>{K=cn.lexicalToJSON(W._selection),F=W.toJSON()});let q=null;H.read(()=>{let $=(0,zt.$getSelection)();q=cn.lexicalToJSON($),H.toJSON()}),Vt.setMainSelectionJSON(q),p({state:F,selection:K},ts.getCurrentRemoteSelections(),Li.historic),a.dispatchCommand(zt.CAN_REDO_COMMAND,!1),a.dispatchCommand(zt.CAN_UNDO_COMMAND,!1)})(b,S),void La.invokeClientCallback();if(!ws.ensureDocTablesAreValid(b))return;Kp++,Pt.log("[editorUpdatesListener] invoked by lexical. call counter: ",{upd_call_counter:Kp,isCodoxStarted:Vt.isCodoxStarted});let w=Vt.isOnlySelectionChanged(x,y),E=null,I=null,j=null,B=null,N=C.has("codox_sync_state_changes"),D=C.has(Od),P=Vt.undoInvoked(),k=Vt.redoInvoked(),A=Vt.canUndo(),L=Vt.canRedo();E=b.toJSON(),I=S.toJSON(),S.read(()=>{B=cn.lexicalToJSON(S._selection)}),b.read(()=>{let H=(0,zt.$getSelection)();j=cn.lexicalToJSON(H);let W=cn.JSONToLexical(j),K=H===null&&W===null||H.is(W);Pt.log("[editorUpdatesListener] new values: ",{newContentStateJSON:E,prevContentStateJSON:JSON.parse(JSON.stringify(I)),currentCommentsJSON:JSON.parse(JSON.stringify(_r.getAllComments())),newSelectionJSON:JSON.parse(JSON.stringify(j)),currentMainSelectionJSON:JSON.parse(JSON.stringify(Vt.getCurrentMainSelectionJSON())),currentNestedSelectionJSON:JSON.parse(JSON.stringify(Vt.getCurrentNestedSelectionJSON())),currentActiveSelectionJSON:JSON.parse(JSON.stringify(Vt.getCurrentActiveSelectionJSON())),lexicalSelection:H,convertedBackMainSelection:W,isMainSelectionConvertionCorrect:K,nodes:a._editorState._nodeMap,fullEditor:a,codoxNodesMap:Tr.toArray(),codoxComments:_r,isUpdateFromSync:N,isUpdateFromComments:D,tags:C,onlySelectionChanged:w,undoInvoked:P,redoInvoked:k,canUndo:A,canRedo:L})});let R=ly(E,I),J=cn.equalSelectionsJSON(Vt.getCurrentActiveSelectionJSON(),j);Pt.log("[editorUpdatesListener] compares: ",{isStateSame:R,isSelectionSame:J});let T=R&&J&&!D;if(!R||D||N){Pt.log("[editorUpdatesListener] should trigger content_changed for client");let H=Bc({},E),W=_r.getAllComments();W.length&&(H.commentThreads=W);let K={source:N?yx.remote:yx.local,content:H};Bi.hooks&&Bi.hooks.contentChanged&&Bi.hooks.contentChanged(K),xs().instance&&xs().instance.emit("content_changed",K)}if(T)Pt.log("[editorUpdatesListener] STOP - state and selection and comments are same ",Kp);else if(Vt.undoInvoked()&&Vt.setUndoInvoked(!1),Vt.redoInvoked()&&Vt.setRedoInvoked(!1),Vt.setPrevContentStateJSON(I),Vt.setMainSelectionJSON(j),Vt.setPrevMainSelectionJSON(B),Vt.isCodoxStarted)if(uy){let H=Vt.getCurrentActiveSelectionJSON();p({state:Vt.getMainEditorContentStateJSON(),selection:H},[])}else f({upd_call_counter:Kp});else Pt.log("[editorUpdatesListener] STOP - Codox is not started - prevent sync invoke")},m=()=>{let _=[];return Vt.getMainEditorNodesClassesMap().forEach((b,S,C)=>{let{klass:x}=b,y=a.registerMutationListener(x,w=>{for(let[E,I]of w){if(!xi[I])continue;const j=Vt.getLexicalNodeByKey(E);if(I===xi.created&&j&&La.trackBlacklisted(j,I),x.name===kr.TableNode.name&&(I===xi.destroyed?ws.tableNodeRemoveListener(E):ws.tableUpdateListener(E)),x.name===kr.TableRowNode.name&&I!==xi.destroyed&&ws.tableRowNodeChangesListener(E,I===xi.updated),x.name===kr.TableCellNode.name&&I===xi.updated&&ws.tableCellNodeChangesListener(E),x.name===Di.MarkNode.name&&(Pt.debug("[MUTATION LISTENER] MARK node: ",{nodeKey:E,node:j,mutationType:I,codoxComments:_r}),I===xi.destroyed?_r.removeRelatedNodeKey(E):j&&_r.addRelatedNodeKey(j.__key,j.__ids,I===xi.created)),j&&j.codoxId){if(I===xi.destroyed)return void(j.codoxId&&Tr.remove(j.codoxId));Jx(j)||Pt.warn("[MutationListener Error] duplicating codoxId detected - such codoxId already exists in codoxNodesMap - updating node ref to latest: ",{mutationType:I,node:j}),Tr.add(j.codoxId,j)}}_.push(y)})}),_},v={start:i,stop:n,on:(_,b)=>{Pt.info(`Subscribing client to codox ${_} event`),fy[_]=b},cursor:{hide:()=>{ts.hideRemoteSelectionsFromUI()},show:()=>{ts.showHiddenRemoteSelectionsInUI()}},initComments:_=>{_r.setInitialComments(_)}};return(0,pt.useImperativeHandle)(t,()=>v),null}),zP=FP,UP=["comments"];function zx(u,t){var o=Object.keys(u);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(u);t&&(e=e.filter(function(a){return Object.getOwnPropertyDescriptor(u,a).enumerable})),o.push.apply(o,e)}return o}function py(u){for(var t=1;t<arguments.length;t++){var o=arguments[t]!=null?arguments[t]:{};t%2?zx(Object(o),!0).forEach(function(e){HP(u,e,o[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(u,Object.getOwnPropertyDescriptors(o)):zx(Object(o)).forEach(function(e){Object.defineProperty(u,e,Object.getOwnPropertyDescriptor(o,e))})}return u}function HP(u,t,o){return(t=$P(t))in u?Object.defineProperty(u,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):u[t]=o,u}function $P(u){var t=qP(u,"string");return typeof t=="symbol"?t:t+""}function qP(u,t){if(typeof u!="object"||!u)return u;var o=u[Symbol.toPrimitive];if(o!==void 0){var e=o.call(u,t||"default");if(typeof e!="object")return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(u)}function WP(u,t){if(u==null)return{};var o,e,a=VP(u,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(u);for(e=0;e<r.length;e++)o=r[e],t.includes(o)||{}.propertyIsEnumerable.call(u,o)&&(a[o]=u[o])}return a}function VP(u,t){if(u==null)return{};var o={};for(var e in u)if({}.hasOwnProperty.call(u,e)){if(t.includes(e))continue;o[e]=u[e]}return o}class JP extends hx{constructor(){super(),this.mainEditor=null,this.mainEditorKey=null,this.currentMainSelectionJSON=null,this.currentNestedSelectionJSON=null,this._isCodoxStarted=!1,this.prevContentStateJSON=null,this.prevMainSelectionJSON=null,this._undoInvoked=!1,this._redoInvoked=!1,this._canUndo=!1,this._canRedo=!1}setCanUndo(t){this._canUndo=t}setCanRedo(t){this._canRedo=t}canUndo(){return this._canUndo}canRedo(){return this._canRedo}setUndoInvoked(t){this._undoInvoked=t}setRedoInvoked(t){this._redoInvoked=t}undoInvoked(){return this._undoInvoked}redoInvoked(){return this._redoInvoked}setIsCodoxStarted(){let t=arguments.length>0&&arguments[0]!==void 0&&arguments[0];this._isCodoxStarted=t}get isCodoxStarted(){return this._isCodoxStarted}getMainEditorKey(){return this.mainEditorKey}setMainEditor(t){this.mainEditor=t,this.mainEditorKey=t._key}clearJSONs(){Pt.debug("[CodoxLexicalEditorManager][clearJSONs] invoked"),this.currentMainSelectionJSON=null,this.currentNestedSelectionJSON=null,this.prevContentStateJSON=null,this.prevMainSelectionJSON=null}removeMainEditor(){this.mainEditor=null,this.mainEditorKey=null,this._undoInvoked=!1,this._redoInvoked=!1,this._canUndo=!1,this._canRedo=!1,super.clear()}getMainEditor(){return this.mainEditor}alignStateSelectionJSONsFromLatestEditor(){this.getMainEditorState().read(()=>{this.setMainSelectionJSON(cn.lexicalToJSON((0,zt.$getSelection)()))})}mainEditorExists(){return!!this.mainEditor}getMainEditorState(){return this.mainEditor?this.mainEditor.getEditorState():{}}getMainEditorNodesClassesMap(){return this.mainEditor?this.mainEditor._nodes:new Map}getMainEditorStateNodesMap(){return this.mainEditor?this.mainEditor.getEditorState()._nodeMap:new Map}getLexicalNodeByKey(t){return this.mainEditor?this.getMainEditorState()._nodeMap.get(t):null}isLexicalEditorInstance(t){return t&&typeof t=="object"&&!!t.setEditorState}getMainEditorContentStateJSON(){return this.getMainEditorState().toJSON()}setPrevContentStateJSON(t){this.prevContentStateJSON=t}getPrevContentStateJSON(){return this.prevContentStateJSON}setMainSelectionJSON(t){this.currentMainSelectionJSON=t,this.currentMainSelectionJSON&&this.currentNestedSelectionJSON&&(this.currentNestedSelectionJSON=null)}setNestedSelectionJSON(t){this.currentNestedSelectionJSON=t,this.currentNestedSelectionJSON&&this.currentMainSelectionJSON&&(this.currentMainSelectionJSON=null)}getCurrentMainSelectionJSON(){return this.currentMainSelectionJSON}getCurrentNestedSelectionJSON(){return this.currentNestedSelectionJSON}getCurrentActiveSelectionJSON(){return!this.currentMainSelectionJSON&&this.currentNestedSelectionJSON?this.currentNestedSelectionJSON:this.currentMainSelectionJSON}clearSelectionJSON(){this.currentMainSelectionJSON=null,this.currentNestedSelectionJSON=null}setPrevMainSelectionJSON(t){this.prevMainSelectionJSON=t}getPrevMainSelectionJSON(){return this.prevMainSelectionJSON}extractStateAndCommentsFromSynced(t){let{state:{comments:o},selection:e,stateReplace:a}=t;return{stateFromSync:{state:py({},WP(t.state,UP)),selection:e,stateReplace:a},commentsFromSync:o}}composeFullStateWithRootAndComments(){return py(py({},this.getMainEditorState().toJSON()),{},{comments:_r.getAllComments()})}isValidJSONState(t){let o=!1;try{if(!t)throw new Error("State is undefined");if(!t.root)throw new Error("State 'root' node is missing");let e=this.getMainEditorNodesClassesMap(),a=function(r){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"",i=r,l=e.get(i.type);if(!l)throw new Error(`Node with type "${i.type}" is not registered in editor`);let{klass:s}=l;if(n==="root"){let d=s.prototype instanceof zt.ElementNode,c=s.prototype instanceof zt.DecoratorNode;if(!d&&!c)throw new Error("State root node can have only element nodes as children")}if(i.children)for(let d of i.children)a(d,i.type)};a(t.root),o=!0}catch(e){Pt.error("[isValidJSONState] invalid state found: ",e.message),o=!1}return o}scanLexicalNodeForNestedEditorAttribute(t){for(let o in t){let e=t[o];if(this.isLexicalEditorInstance(e))return o}return""}isOnlySelectionChanged(t,o){return t.size===0&&o.size===0}addUpdateTag(){let{isSameState:t,isSameSelection:o,fromNestedEditor:e=!1,updateTag:a=""}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return a?(Pt.log(`[addUpdateTag] explicit add of tag "${a}" `),void(0,zt.$addUpdateTag)(a)):e?(Pt.log(`[addUpdateTag] add "${Li.historic}" tag - change invoked by nested editor`),void(0,zt.$addUpdateTag)(Li.historic)):void(t?(Pt.log(`[addUpdateTag] add "${Li.historic}" tag - state is same`),(0,zt.$addUpdateTag)(Li.historic)):(Pt.log(`[addUpdateTag] add "${Li.historyMerge}" tag - state is different`),(0,zt.$addUpdateTag)(Li.historyMerge)))}enableEditorReadOnlyMode(){this.mainEditor&&this.mainEditor.isEditable()&&this.mainEditor.setEditable(!1)}disableEditorReadOnlyMode(){this.mainEditor&&(this.mainEditor.isEditable()||this.mainEditor.setEditable(!0))}}const KP=new JP,Vt=KP;class GP{constructor(){this._nodesMap=new Map,this._pastedNodesCodoxIds=new Set}get size(){return this._nodesMap.size}add(t,o){this._nodesMap.set(t,o)}get(t){return this._nodesMap.get(t)||null}remove(t){this._nodesMap.delete(t)}has(t){return this._nodesMap.has(t)}nodesToArray(){return Array.from(this._nodesMap.values())}keysToArray(){return Array.from(this._nodesMap.keys())}toArray(){return Array.from(this._nodesMap.entries())}addPastedId(t){this._pastedNodesCodoxIds.add(t)}removePastedId(t){this._pastedNodesCodoxIds.delete(t)}hasPastedId(t){return this._pastedNodesCodoxIds.has(t)}clearPastedIds(){this._pastedNodesCodoxIds.size>0&&this._pastedNodesCodoxIds.clear()}isEmptyPastedIds(){return this._pastedNodesCodoxIds.size===0}getPastedIdsSize(){return this._pastedNodesCodoxIds.size}clearAll(){this._nodesMap.clear(),this._pastedNodesCodoxIds.clear()}gcAbandonedNodes(){let t=Vt.getMainEditorState();if(!t._nodeMap)return;let o=this.nodesToArray();for(let e of o)t._nodeMap.has(e.__key)||this.remove(e.codoxId)}}const YP=new GP,Tr=YP;function Ux(u,t){var o=Object.keys(u);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(u);t&&(e=e.filter(function(a){return Object.getOwnPropertyDescriptor(u,a).enumerable})),o.push.apply(o,e)}return o}function Hx(u){for(var t=1;t<arguments.length;t++){var o=arguments[t]!=null?arguments[t]:{};t%2?Ux(Object(o),!0).forEach(function(e){ZP(u,e,o[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(u,Object.getOwnPropertyDescriptors(o)):Ux(Object(o)).forEach(function(e){Object.defineProperty(u,e,Object.getOwnPropertyDescriptor(o,e))})}return u}function ZP(u,t,o){return(t=QP(t))in u?Object.defineProperty(u,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):u[t]=o,u}function QP(u){var t=XP(u,"string");return typeof t=="symbol"?t:t+""}function XP(u,t){if(typeof u!="object"||!u)return u;var o=u[Symbol.toPrimitive];if(o!==void 0){var e=o.call(u,t||"default");if(typeof e!="object")return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(u)}const hy=()=>aj(),$x=u=>typeof u=="number";function Fc(u){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"";const o=function(){for(var e=arguments.length,a=new Array(e),r=0;r<e;r++)a[r]=arguments[r];return u.apply(this,a)};return Object.defineProperty(o,"name",{value:t,writable:!0}),o}const Ml=u=>u.__type==="root"||u.type==="root",qx=u=>Ml(u.getParent()),Vr=u=>u.__type===Hp.text||u.type===Hp.text||u.hasOwnProperty("__text")||u.hasOwnProperty("text"),zc=u=>(0,zt.$isElementNode)(u),Uc=u=>(0,kr.$isTableNode)(u)||(0,kr.$isTableRowNode)(u)||(0,kr.$isTableCellNode)(u),e5=u=>!u.getChildren,Wx=u=>!!u.getChildren,xr=u=>(0,zt.$isDecoratorNode)(u),Ad=u=>(0,XN.$isLinkNode)(u),Nd=u=>u.__type==="mark"||u.type==="mark",gy=u=>(0,zt.$isLineBreakNode)(u),Ba=u=>Vr(u)||gy(u),my=u=>u.__type===Hp.horizontalrule||u.type===Hp.horizontalrule,Vx=u=>{if(Ba(u)||Ad(u)||Nd(u))return!1;if(!u.__parent||u.__parent==="root"||(0,zt.$isParagraphNode)(u))return!0;let t=u.getParent().getChildren();return t.length===1&&t[0].__key===u.__key?!((xr(u)||Ad(u)||Nd(u))&&!my(u)):!t.some(o=>{let e=my(o);return o.__key!==u.__key&&(Ba(o)||xr(o)&&!e||Ad(o)||Nd(o))})},Jx=u=>{const t=Tr.get(u.codoxId);return!t||u.__key===t.__key},Hc=function(u){const t=(arguments.length>1&&arguments[1]!==void 0?arguments[1]:null)||hy();u.codoxId=t,Tr.add(t,u)},Kx=u=>{Tr.remove(u.codoxId),delete u.codoxId},t5=u=>{if(!Wx(u)||!u.getChildrenSize())return;const t=u.getChildren();if(t.some(a=>!!(0,zt.$isParagraphNode)(a)))return;let o=!1,e=[];for(let a of t)(Ba(a)||xr(a)||Ad(a)||Nd(a))&&!o&&(my(a)||(o=!0)),(Wx(a)||xr(a))&&e.push(a);for(let a of e)o||a.codoxId?o&&a.codoxId&&(a=a.getWritable(),Kx(a)):(a=a.getWritable(),Hc(a))},n5=u=>{const t=Hx({},u);for(const o in u)u[o]===void 0&&u.hasOwnProperty(o)&&delete t[o];return t},r5=u=>{const t=`__nativeCreateDOM_${u.name}`;u.prototype[t]=Fc(u.prototype.createDOM,t),u.prototype.createDOM=function(o,e){if(Vx(this))if(this.codoxId){if(!Jx(this)){let r=Tr.get(this.codoxId);r.__type===this.__type&&this.isAttached()&&!r.isAttached()?(Pt.warn("[createDOM][Non-unique codoxId] overwrite abandoned existing node with latest: ",{latestNode:this,existingNode:r}),Tr.add(this.codoxId,this)):Hc(this)}}else Hc(this);else this.codoxId&&Kx(this);xr(this)&&!this.codoxDId&&(this.codoxDId=hy()),ta.manageNestedEditorInLexicalNode(this);let a=this[t](o,e);return a.__codox_track=!0,a}},o5=u=>{const t=`__nativeUpdateDOM_${u.name}`;return u.prototype[t]=Fc(u.prototype.updateDOM,t),u.prototype.updateDOM=function(){const o=this[t](...arguments);return t5(this),o},u},i5=u=>{const t=`__nativeRemove_${u.name}`;return u.prototype[t]=Fc(u.prototype.remove,t),u.prototype.remove=function(){const o=this.codoxId;return o&&Tr.remove(o),ta.gcNestedEditorListenerInLexicalNode(this),this[t](...arguments)},u},s5=u=>{const t=`__nativeExportJSON_${u.name}`;u.prototype[t]=Fc(u.prototype.exportJSON,t),u.prototype.exportJSON=function(){const o=this[t]();return this.codoxId&&(o.codoxId=this.codoxId),this.codoxDId&&(o.codoxDId=this.codoxDId),Vr(this)&&$x(o.format)&&this.hasFormat&&(o.format=bj(this)),n5(o)}},a5=u=>{const t="__nativeImportJSON";u[t]=Fc(u.importJSON,t),u.importJSON=function(o){const e=Hx({},o);Vr(e)&&!$x(e.format)&&(e.format=yj(e.format));const a=u[t](e);ta.manageNestedEditorInLexicalNode(a);const r=Vx(a);return r&&e.codoxId&&(Tr.hasPastedId(e.codoxId)&&Tr.has(e.codoxId)?(Tr.removePastedId(e.codoxId),Hc(a)):Hc(a,e.codoxId)),r&&!a.codoxId&&Hc(a),e.codoxDId&&(a.codoxDId=e.codoxDId),a}},l5=u=>{const t="__nativeClone";u[t]=Fc(u.clone,t),u.clone=function(o){const e=u[t](o);return o.codoxId&&(e.codoxId=o.codoxId),o.codoxDId&&(e.codoxDId=o.codoxDId),ta.manageNestedEditorInClonedLexicalNode(o,e),e}},c5=u=>{let t=!1,o=!1,e=!1,a=!1;u.forEach(n=>{n.name===zt.TextNode.name?t=!0:n.name===zt.ParagraphNode.name?o=!0:n.name===zt.LineBreakNode.name?e=!0:n.name===Di.MarkNode.name&&(a=!0)});let r=[];return t||r.push(zt.TextNode),o||r.push(zt.ParagraphNode),e||r.push(zt.LineBreakNode),a||r.push(Di.MarkNode),r.length?[...r,...u]:u},u5=function(){return c5(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).map(u=>(u.hasOwnProperty("__isCodoxExtended")||(r5(u),o5(u),s5(u),i5(u),a5(u),l5(u),Object.defineProperty(u,"__isCodoxExtended",{value:!0,writable:!1})),u))};var Gp=Tn(777),$c={};$c.styleTagTransform=ea(),$c.setAttributes=Qs(),$c.insert=Zs().bind(null,"head"),$c.domAPI=Ys(),$c.insertStyleElement=Xs(),Gs()(Gp.A,$c),Gp.A&&Gp.A.locals&&Gp.A.locals;var d5=u=>{var t={};return Tn.d(t,u),t};const f5=d5({AutoFocusPlugin:()=>Tp});var p5=u=>{var t={};return Tn.d(t,u),t};const h5=p5({ClearEditorPlugin:()=>sx});var g5=u=>{var t={};return Tn.d(t,u),t};const m5=g5({LexicalComposer:()=>np});var y5=u=>{var t={};return Tn.d(t,u),t};const Gx=y5({default:()=>Ol});var b5=u=>{var t={};return Tn.d(t,u),t};const v5=b5({HistoryPlugin:()=>Fp});var _5=u=>{var t={};return Tn.d(t,u),t};const x5=_5({OnChangePlugin:()=>zp});var w5=u=>{var t={};return Tn.d(t,u),t};const S5=w5({PlainTextPlugin:()=>oy});var C5=u=>{var t={};return Tn.d(t,u),t};const Yx=C5({$isRootTextContentEmpty:()=>Jm,$rootTextContent:()=>Vm});var E5=u=>{var t={};return Tn.d(t,u),t};const qc=E5({createPortal:()=>yf.createPortal}),k5=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0,O5=k5?pt.useLayoutEffect:pt.useEffect,Zx=O5;var Yp=Tn(253),Wc={};Wc.styleTagTransform=ea(),Wc.setAttributes=Qs(),Wc.insert=Zs().bind(null,"head"),Wc.domAPI=Ys(),Wc.insertStyleElement=Xs(),Gs()(Yp.A,Wc),Yp.A&&Yp.A.locals&&Yp.A.locals;function T5(u){let{onClose:t,children:o,title:e,closeOnClickOutside:a}=u;const r=(0,pt.useRef)(null);return(0,pt.useEffect)(()=>{r.current!==null&&r.current.focus()},[]),(0,pt.useEffect)(()=>{let n=null;const i=d=>{d.key==="Escape"&&t()},l=d=>{const c=d.target;r.current!==null&&!r.current.contains(c)&&a&&t()},s=r.current;return s!==null&&(n=s.parentElement,n!==null&&n.addEventListener("click",l)),window.addEventListener("keydown",i),()=>{window.removeEventListener("keydown",i),n!==null&&(n==null||n.removeEventListener("click",l))}},[a,t]),pt.createElement("div",{className:"Modal__overlay",role:"dialog"},pt.createElement("div",{className:"Modal__modal",tabIndex:-1,ref:r},pt.createElement("h2",{className:"Modal__title"},e),pt.createElement("button",{className:"Modal__closeButton","aria-label":"Close modal",type:"button",onClick:t},"X"),pt.createElement("div",{className:"Modal__content"},o)))}function A5(u){let{onClose:t,children:o,title:e,closeOnClickOutside:a=!1}=u;return(0,qc.createPortal)(pt.createElement(T5,{onClose:t,title:e,closeOnClickOutside:a},o),document.body)}function Qx(){const[u,t]=(0,pt.useState)(null),o=(0,pt.useCallback)(()=>{t(null)},[]),e=(0,pt.useMemo)(()=>{if(u===null)return null;const{title:r,content:n,closeOnClickOutside:i}=u;return pt.createElement(A5,{onClose:o,title:r,closeOnClickOutside:i},n)},[u,o]),a=(0,pt.useCallback)(function(r,n){t({closeOnClickOutside:arguments.length>2&&arguments[2]!==void 0&&arguments[2],content:n(o),title:r})},[o]);return[e,a]}var Zp=Tn(191),Vc={};Vc.styleTagTransform=ea(),Vc.setAttributes=Qs(),Vc.insert=Zs().bind(null,"head"),Vc.domAPI=Ys(),Vc.insertStyleElement=Xs(),Gs()(Zp.A,Vc),Zp.A&&Zp.A.locals&&Zp.A.locals;const N5={blockCursor:"CommentEditorTheme__blockCursor",characterLimit:"CommentEditorTheme__characterLimit",code:"CommentEditorTheme__code",codeHighlight:{atrule:"CommentEditorTheme__tokenAttr",attr:"CommentEditorTheme__tokenAttr",boolean:"CommentEditorTheme__tokenProperty",builtin:"CommentEditorTheme__tokenSelector",cdata:"CommentEditorTheme__tokenComment",char:"CommentEditorTheme__tokenSelector",class:"CommentEditorTheme__tokenFunction","class-name":"CommentEditorTheme__tokenFunction",comment:"CommentEditorTheme__tokenComment",constant:"CommentEditorTheme__tokenProperty",deleted:"CommentEditorTheme__tokenProperty",doctype:"CommentEditorTheme__tokenComment",entity:"CommentEditorTheme__tokenOperator",function:"CommentEditorTheme__tokenFunction",important:"CommentEditorTheme__tokenVariable",inserted:"CommentEditorTheme__tokenSelector",keyword:"CommentEditorTheme__tokenAttr",namespace:"CommentEditorTheme__tokenVariable",number:"CommentEditorTheme__tokenProperty",operator:"CommentEditorTheme__tokenOperator",prolog:"CommentEditorTheme__tokenComment",property:"CommentEditorTheme__tokenProperty",punctuation:"CommentEditorTheme__tokenPunctuation",regex:"CommentEditorTheme__tokenVariable",selector:"CommentEditorTheme__tokenSelector",string:"CommentEditorTheme__tokenSelector",symbol:"CommentEditorTheme__tokenProperty",tag:"CommentEditorTheme__tokenProperty",url:"CommentEditorTheme__tokenOperator",variable:"CommentEditorTheme__tokenVariable"},embedBlock:{base:"CommentEditorTheme__embedBlock",focus:"CommentEditorTheme__embedBlockFocus"},hashtag:"CommentEditorTheme__hashtag",heading:{h1:"CommentEditorTheme__h1",h2:"CommentEditorTheme__h2",h3:"CommentEditorTheme__h3",h4:"CommentEditorTheme__h4",h5:"CommentEditorTheme__h5",h6:"CommentEditorTheme__h6"},image:"editor-image",indent:"CommentEditorTheme__indent",inlineImage:"inline-editor-image",layoutContainer:"CommentEditorTheme__layoutContainer",layoutItem:"CommentEditorTheme__layoutItem",link:"CommentEditorTheme__link",list:{checklist:"CommentEditorTheme__checklist",listitem:"CommentEditorTheme__listItem",listitemChecked:"CommentEditorTheme__listItemChecked",listitemUnchecked:"CommentEditorTheme__listItemUnchecked",nested:{listitem:"CommentEditorTheme__nestedListItem"},olDepth:["CommentEditorTheme__ol1","CommentEditorTheme__ol2","CommentEditorTheme__ol3","CommentEditorTheme__ol4","CommentEditorTheme__ol5"],ul:"CommentEditorTheme__ul"},ltr:"CommentEditorTheme__ltr",mark:"CommentEditorTheme__mark",markOverlap:"CommentEditorTheme__markOverlap",paragraph:"CommentEditorTheme__paragraph",quote:"CommentEditorTheme__quote",rtl:"CommentEditorTheme__rtl",table:"CommentEditorTheme__table",tableCell:"CommentEditorTheme__tableCell",tableCellActionButton:"CommentEditorTheme__tableCellActionButton",tableCellActionButtonContainer:"CommentEditorTheme__tableCellActionButtonContainer",tableCellEditing:"CommentEditorTheme__tableCellEditing",tableCellHeader:"CommentEditorTheme__tableCellHeader",tableCellPrimarySelected:"CommentEditorTheme__tableCellPrimarySelected",tableCellResizer:"CommentEditorTheme__tableCellResizer",tableCellSelected:"CommentEditorTheme__tableCellSelected",tableCellSortedIndicator:"CommentEditorTheme__tableCellSortedIndicator",tableResizeRuler:"CommentEditorTheme__tableCellResizeRuler",tableSelected:"CommentEditorTheme__tableSelected",tableSelection:"CommentEditorTheme__tableSelection",text:{bold:"CommentEditorTheme__textBold",code:"CommentEditorTheme__textCode",italic:"CommentEditorTheme__textItalic",strikethrough:"CommentEditorTheme__textStrikethrough",subscript:"CommentEditorTheme__textSubscript",superscript:"CommentEditorTheme__textSuperscript",underline:"CommentEditorTheme__textUnderline",underlineStrikethrough:"CommentEditorTheme__textUnderlineStrikethrough"}},j5=N5;var Qp=Tn(72),Jc={};Jc.styleTagTransform=ea(),Jc.setAttributes=Qs(),Jc.insert=Zs().bind(null,"head"),Jc.domAPI=Ys(),Jc.insertStyleElement=Xs(),Gs()(Qp.A,Jc),Qp.A&&Qp.A.locals&&Qp.A.locals;function P5(){for(var u=arguments.length,t=new Array(u),o=0;o<u;o++)t[o]=arguments[o];return t.filter(Boolean).join(" ")}function yy(){return yy=Object.assign?Object.assign.bind():function(u){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var e in o)({}).hasOwnProperty.call(o,e)&&(u[e]=o[e])}return u},yy.apply(null,arguments)}function Fa(u){let{"data-test-id":t,children:o,className:e,onClick:a,disabled:r,small:n,title:i}=u;return pt.createElement("button",yy({disabled:r,className:P5("Button__root",r&&"Button__disabled",n&&"Button__small",e),onClick:a,title:i,"aria-label":i},t&&{"data-test-id":t}),o)}var Xp=Tn(129),Kc={};Kc.styleTagTransform=ea(),Kc.setAttributes=Qs(),Kc.insert=Zs().bind(null,"head"),Kc.domAPI=Ys(),Kc.insertStyleElement=Xs(),Gs()(Xp.A,Kc),Xp.A&&Xp.A.locals&&Xp.A.locals;var I5=u=>{var t={};return Tn.d(t,u),t};const M5=I5({ContentEditable:()=>Cd});function R5(u){let{className:t}=u;return pt.createElement(M5.ContentEditable,{className:t||"ContentEditable__root"})}var eh=Tn(457),Gc={};Gc.styleTagTransform=ea(),Gc.setAttributes=Qs(),Gc.insert=Zs().bind(null,"head"),Gc.domAPI=Ys(),Gc.insertStyleElement=Xs(),Gs()(eh.A,Gc),eh.A&&eh.A.locals&&eh.A.locals;function D5(u){let{children:t,className:o}=u;return pt.createElement("div",{className:o||"Placeholder__root"},t)}const L5=Gx.default.LexicalErrorBoundary||Gx.default,B5=()=>pt.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"#050505",className:"codox-add-comment-right"},pt.createElement("path",{d:"M14 1a1 1 0 0 1 1 1v8a1 1 0 0 1-1 1H4.414A2 2 0 0 0 3 11.586l-2 2V2a1 1 0 0 1 1-1h12zM2 0a2 2 0 0 0-2 2v12.793a.5.5 0 0 0 .854.353l2.853-2.853A1 1 0 0 1 4.414 12H14a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2z"}),pt.createElement("path",{d:"M3 3.5a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5zM3 6a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9A.5.5 0 0 1 3 6zm0 2.5a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5a.5.5 0 0 1-.5-.5z"})),Xx=()=>pt.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",fill:"currentColor",className:"codox-remove-comment"},pt.createElement("path",{d:"M6.5 1h3a.5.5 0 0 1 .5.5v1H6v-1a.5.5 0 0 1 .5-.5ZM11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3A1.5 1.5 0 0 0 5 1.5v1H2.506a.58.58 0 0 0-.01 0H1.5a.5.5 0 0 0 0 1h.538l.853 10.66A2 2 0 0 0 4.885 16h6.23a2 2 0 0 0 1.994-1.84l.853-10.66h.538a.5.5 0 0 0 0-1h-.995a.59.59 0 0 0-.01 0H11Zm1.958 1-.846 10.58a1 1 0 0 1-.997.92h-6.23a1 1 0 0 1-.997-.92L3.042 3.5h9.916Zm-7.487 1a.5.5 0 0 1 .528.47l.5 8.5a.5.5 0 0 1-.998.06L5 5.03a.5.5 0 0 1 .47-.53Zm5.058 0a.5.5 0 0 1 .47.53l-.5 8.5a.5.5 0 1 1-.998-.06l.5-8.5a.5.5 0 0 1 .528-.47ZM8 4.5a.5.5 0 0 1 .5.5v8.5a.5.5 0 0 1-1 0V5a.5.5 0 0 1 .5-.5Z"})),F5=()=>pt.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",fill:"currentColor",className:"codox-add-comment"},pt.createElement("path",{d:"M15.854.146a.5.5 0 0 1 .11.54l-5.819 14.547a.75.75 0 0 1-1.329.124l-3.178-4.995L.643 7.184a.75.75 0 0 1 .124-1.33L15.314.037a.5.5 0 0 1 .54.11ZM6.636 10.07l2.761 4.338L14.13 2.576 6.636 10.07Zm6.787-8.201L1.591 6.602l4.339 2.76 7.494-7.493Z"})),z5=()=>pt.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",fill:"#0000008c",className:"codox-hide-show-comments"},pt.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M13 5.885v1.166a3.95 3.95 0 0 1-3.949 3.95H6.917a.748.748 0 0 0-.45.15l-1.345 1.007a.752.752 0 0 0-.032 1.181A2.933 2.933 0 0 0 6.95 14h2.716l2.534 1.901a.506.506 0 0 0 .524.047A.501.501 0 0 0 13 15.5V14h.051a2.949 2.949 0 0 0 2.95-2.949v-3.05a3.002 3.002 0 0 0-2.002-2.83.756.756 0 0 0-.999.714"}),pt.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M9.05 1H2.95A2.952 2.952 0 0 0 0 3.949v3.102A2.952 2.952 0 0 0 2.949 10H3v1.5a.502.502 0 0 0 .8.4L6.334 10H9.05A2.952 2.952 0 0 0 12 7.05V3.95A2.952 2.952 0 0 0 9.05 1"}));function ew(u,t,o){let e=arguments.length>3&&arguments[3]!==void 0?arguments[3]:performance.now(),a=arguments.length>4&&arguments[4]!==void 0&&arguments[4];return _r.createNewCommentObj({content:u,author:t,codoxId:o,timeStamp:e,deleted:a})}function U5(u,t,o){return _r.createNewThreadObj({quote:u,comments:t,codoxId:o})}function H5(u){let{anchorKey:t,editor:o,onAddComment:e}=u;const a=(0,pt.useRef)(null),r=(0,pt.useCallback)(()=>{const n=a.current,i=o.getRootElement(),l=o.getElementByKey(t);if(n!==null&&i!==null&&l!==null){const{right:s}=i.getBoundingClientRect(),{top:d}=l.getBoundingClientRect();n.style.left=s-20+"px",n.style.top=d-30+"px"}},[t,o]);return(0,pt.useEffect)(()=>(window.addEventListener("resize",r),()=>{window.removeEventListener("resize",r)}),[o,r]),Zx(()=>{r()},[t,o,r]),pt.createElement("div",{className:"CodoxCommentPlugin_AddCommentBox",ref:a},pt.createElement("button",{className:"CodoxCommentPlugin_AddCommentBox_button",onClick:e},pt.createElement(B5,null)))}function $5(u){let{onEscape:t}=u;const[o]=(0,Da.useLexicalComposerContext)();return(0,pt.useEffect)(()=>o.registerCommand(zt.KEY_ESCAPE_COMMAND,e=>t(e),2),[o,t]),null}function q5(u){let{editorRef:t}=u;const[o]=(0,Da.useLexicalComposerContext)();return typeof t=="function"?t(o):typeof t=="object"&&(t.current=o),null}function tw(u){let{className:t,autoFocus:o,onEscape:e,onChange:a,editorRef:r,placeholder:n="Type a comment...",onEditorClick:i=()=>{}}=u;const l={namespace:"Commenting",nodes:[],onError:s=>{throw s},theme:j5};return pt.createElement(m5.LexicalComposer,{initialConfig:l},pt.createElement("div",{className:"CodoxCommentPlugin_CommentInputBox_EditorContainer",onClick:i},pt.createElement(S5.PlainTextPlugin,{contentEditable:pt.createElement(R5,{className:t}),placeholder:pt.createElement(D5,null,n),ErrorBoundary:L5}),pt.createElement(x5.OnChangePlugin,{onChange:a}),pt.createElement(v5.HistoryPlugin,null),o!==!1&&pt.createElement(f5.AutoFocusPlugin,null),pt.createElement($5,{onEscape:e}),pt.createElement(h5.ClearEditorPlugin,null),r!==void 0&&pt.createElement(q5,{editorRef:r})))}function nw(u,t){return(0,pt.useCallback)((o,e)=>{o.read(()=>{u((0,Yx.$rootTextContent)()),t(!(0,Yx.$isRootTextContentEmpty)(e.isComposing(),!0))})},[t,u])}function W5(u){let{editor:t,cancelAddComment:o,submitAddComment:e}=u;const[a,r]=(0,pt.useState)(""),[n,i]=(0,pt.useState)(!1),l=(0,pt.useRef)(null),s=(0,pt.useMemo)(()=>({container:document.createElement("div"),elements:[]}),[]),d=(0,pt.useRef)(null),c=iw(),p=(0,pt.useCallback)(()=>{t.getEditorState().read(()=>{const h=(0,zt.$getSelection)();if((0,zt.$isRangeSelection)(h)){d.current=h.clone();const g=h.anchor,m=h.focus,v=(0,jl.createDOMRange)(t,g.getNode(),g.offset,m.getNode(),m.offset),_=l.current;if(v!==null&&_!==null){const{left:b,bottom:S,width:C}=v.getBoundingClientRect(),x=(0,jl.createRectsFromDOMRange)(t,v);let y=x.length===1?b+C/2-125:b-125;y<10&&(y=10),_.style.left=`${y}px`,_.style.top=`${S+20+(window.pageYOffset||document.documentElement.scrollTop)}px`;const w=x.length,{container:E}=s,I=s.elements,j=I.length;for(let B=0;B<w;B++){const N=x[B];let D=I[B];D===void 0&&(D=document.createElement("span"),I[B]=D,E.appendChild(D));const P="255, 212, 0",k=`position:absolute;top:${N.top+(window.pageYOffset||document.documentElement.scrollTop)}px;left:${N.left}px;height:${N.height}px;width:${N.width}px;background-color:rgba(${P}, 0.3);pointer-events:none;z-index:5;`;D.style.cssText=k}for(let B=j-1;B>=w;B--){const N=I[B];E.removeChild(N),I.pop()}}}})},[t,s]);Zx(()=>{p();const h=s.container,g=document.body;if(g!==null)return g.appendChild(h),()=>{g.removeChild(h)}},[s.container,p]),(0,pt.useEffect)(()=>(window.addEventListener("resize",p),()=>{window.removeEventListener("resize",p)}),[p]);const f=nw(r,i);return pt.createElement("div",{className:"CodoxCommentPlugin_CommentInputBox",ref:l},pt.createElement(tw,{className:"CodoxCommentPlugin_CommentInputBox_Editor",onEscape:h=>(h.preventDefault(),o(),!0),onChange:f}),pt.createElement("div",{className:"CodoxCommentPlugin_CommentInputBox_Buttons"},pt.createElement(Fa,{onClick:o,className:"CodoxCommentPlugin_CommentInputBox_Button"},"Cancel"),pt.createElement(Fa,{onClick:()=>{if(n){let h=t.getEditorState().read(()=>{const g=d.current;return g?g.getTextContent():""});h.length>100&&(h=h.slice(0,99)+"…"),e(U5(h,[ew(a,c)]),!0,void 0,d.current),d.current=null}},disabled:!n,className:"CodoxCommentPlugin_CommentInputBox_Button primary"},"Comment")))}function V5(u){let{submitAddComment:t,thread:o,placeholder:e}=u;const[a,r]=(0,pt.useState)(""),[n,i]=(0,pt.useState)(!1),l=(0,pt.useRef)(null),s=iw(),d=nw(r,i);return pt.createElement(pt.Fragment,null,pt.createElement(tw,{className:"CodoxCommentPlugin_CommentsPanel_Editor",autoFocus:!1,onEscape:()=>!0,onChange:d,editorRef:l,placeholder:e}),pt.createElement(Fa,{className:"CodoxCommentPlugin_CommentsPanel_SendButton",onClick:()=>{if(n){t(ew(a,s),!1,o);const c=l.current;c!==null&&c.dispatchCommand(zt.CLEAR_EDITOR_COMMAND,void 0)}},disabled:!n},pt.createElement(F5,null)))}function rw(u){let{commentOrThread:t,deleteCommentOrThread:o,onClose:e,thread:a}=u;return pt.createElement(pt.Fragment,null,"Are you sure you want to delete this ",t.type,"?",pt.createElement("div",{className:"Modal__content"},pt.createElement(Fa,{onClick:()=>{o(t,a),e()}},"Delete")," ",pt.createElement(Fa,{onClick:()=>{e()}},"Cancel")))}function ow(u){let{comment:t,deleteComment:o,thread:e,rtf:a}=u;const r=Math.round((t.timeStamp-performance.now())/1e3),n=Math.round(r/60),[i,l]=Qx();return pt.createElement("li",{className:"CodoxCommentPlugin_CommentsPanel_List_Comment"},pt.createElement("div",{className:"CodoxCommentPlugin_CommentsPanel_List_Details"},pt.createElement("span",{className:"CodoxCommentPlugin_CommentsPanel_List_Comment_Author"},t.author),pt.createElement("span",{className:"CodoxCommentPlugin_CommentsPanel_List_Comment_Time"},"· ",r>-10?"Just now":a.format(n,"minute"))),pt.createElement("p",{className:t.deleted?"CodoxCommentPlugin_CommentsPanel_DeletedComment":""},t.content),!t.deleted&&pt.createElement(pt.Fragment,null,pt.createElement(Fa,{onClick:()=>{l("Delete Comment",s=>pt.createElement(rw,{commentOrThread:t,deleteCommentOrThread:o,thread:e,onClose:s}))},className:"CodoxCommentPlugin_CommentsPanel_List_DeleteButton"},pt.createElement(Xx,null)),i))}function J5(u){let{activeIDs:t,comments:o,deleteCommentOrThread:e,listRef:a,submitAddComment:r,markNodeMap:n}=u;const[i]=(0,Da.useLexicalComposerContext)(),[l,s]=(0,pt.useState)(0),[d,c]=Qx(),p=(0,pt.useMemo)(()=>new Intl.RelativeTimeFormat("en",{localeMatcher:"best fit",numeric:"auto",style:"short"}),[]);return(0,pt.useEffect)(()=>{const f=setTimeout(()=>{s(l+1)},1e4);return()=>{clearTimeout(f)}},[l]),pt.createElement("ul",{className:"CodoxCommentPlugin_CommentsPanel_List",ref:a},o.map(f=>{const h=f.codoxId;if(!h)return null;if(f.type==="thread"){const g=()=>{if(n.get(h)!==void 0&&(t===null||t.indexOf(h)===-1)){const m=document.activeElement;i.update(()=>{(0,zt.$setSelection)(null)},{onUpdate(){m!==null&&m.focus()}})}};return pt.createElement("li",{key:h,onClick:g,className:`CodoxCommentPlugin_CommentsPanel_List_Thread ${n.has(h)?"interactive":""} ${t.indexOf(h)===-1?"":"active"}`},pt.createElement("div",{className:"CodoxCommentPlugin_CommentsPanel_List_Thread_QuoteBox"},pt.createElement("blockquote",{className:"CodoxCommentPlugin_CommentsPanel_List_Thread_Quote"},"> ",pt.createElement("span",null,f.quote)),pt.createElement(Fa,{onClick:()=>{c("Delete Thread",m=>pt.createElement(rw,{commentOrThread:f,deleteCommentOrThread:e,onClose:m}))},className:"CodoxCommentPlugin_CommentsPanel_List_DeleteButton"},pt.createElement(Xx,null)),d),pt.createElement("ul",{className:"CodoxCommentPlugin_CommentsPanel_List_Thread_Comments"},f.comments.map(m=>pt.createElement(ow,{key:m.codoxId,comment:m,deleteComment:e,thread:f,rtf:p}))),pt.createElement("div",{className:"CodoxCommentPlugin_CommentsPanel_List_Thread_Editor"},pt.createElement(V5,{submitAddComment:r,thread:f,placeholder:"Reply to comment..."})))}return pt.createElement(ow,{key:h,comment:f,deleteComment:e,rtf:p})}))}function K5(u){let{activeIDs:t,deleteCommentOrThread:o,comments:e,submitAddComment:a,markNodeMap:r}=u;const n=(0,pt.useRef)(null),i=e.length===0;return pt.createElement("div",{className:"CodoxCommentPlugin_CommentsPanel"},pt.createElement("h2",{className:"CodoxCommentPlugin_CommentsPanel_Heading"},"Comments"),i?pt.createElement("div",{className:"CodoxCommentPlugin_CommentsPanel_Empty"},"No Comments"):pt.createElement(J5,{activeIDs:t,comments:e,deleteCommentOrThread:o,listRef:n,submitAddComment:a,markNodeMap:r}))}function iw(){const u=(0,Dx.useCollaborationContext)(),{yjsDocMap:t,name:o}=u;return o||"Playground User"}function G5(u){const[t]=(0,Da.useLexicalComposerContext)(),o=jj(),e=(0,pt.useMemo)(()=>new Map,[]),[a,r]=(0,pt.useState)(),[n,i]=(0,pt.useState)([]),[l,s]=(0,pt.useState)(!1),[d,c]=(0,pt.useState)(!1);(0,pt.useEffect)(()=>{!o.length&&d?c(!1):o.length},[o]);const p=(0,pt.useCallback)(()=>{t.update(()=>{const g=(0,zt.$getSelection)();g!==null&&(g.dirty=!0)}),s(!1)},[t]),f=(0,pt.useCallback)((g,m)=>{if(g.type==="comment"){if(Pt.log("[deleteCommentOrThread]: type comment new values",{comment:g,thread:m,markNodeMap:e}),_r.removeComment(m.codoxId,g.codoxId),!m)return;const v=m.codoxId,_=e.get(v);t.update(()=>{_?_.forEach((b,S)=>{const C=(0,zt.$getNodeByKey)(S);Pt.log("[deleteCommentOrThread]: type comment new values",{lexicalNode:C}),C&&C.markDirty()}):(0,zt.$getRoot)().markDirty(),(0,zt.$addUpdateTag)(Li.historic),(0,zt.$addUpdateTag)(Od)})}else{Pt.log("[deleteCommentOrThread]: type thread new values",{comment:g,markNodeMap:e});const v=m!==void 0?m.codoxId:g.codoxId,_=e.get(v);setTimeout(()=>{t.update(()=>{if(_)for(const b of _){const S=(0,zt.$getNodeByKey)(b);Pt.log("[deleteCommentOrThread]: type thread new values",{node:S}),(0,Di.$isMarkNode)(S)&&(S.deleteID(v),S.getIDs().length===0&&(0,Di.$unwrapMarkNode)(S))}else(0,zt.$getRoot)().markDirty(),Pt.debug("[deleteCommentOrThread][refreshComments]");_r.refreshComments(!0),(0,zt.$addUpdateTag)(Od)})})}},[t,e]),h=(0,pt.useCallback)((g,m,v,_)=>{if(Pt.log("[submitAddComment]: new values",{commentOrThread:g,isInlineComment:m,thread:v,markNodeMap:e}),v?_r.addComment(v.codoxId,g):_r.addCommentThread(g),m)t.update(()=>{if((0,zt.$isRangeSelection)(_)){const b=_.isBackward(),S=g.codoxId;(0,Di.$wrapSelectionInMarkNode)(_,b,S),(0,zt.$addUpdateTag)(Od)}}),s(!1);else if(!m&&v){const b=v.codoxId,S=e.get(b);if(!S)return void _r.removeComment(v.codoxId,g.codoxId);t.update(()=>{S.forEach((C,x)=>{let y=(0,zt.$getNodeByKey)(x);y&&y.markDirty()}),(0,zt.$addUpdateTag)(Li.historic),(0,zt.$addUpdateTag)(Od)})}},[t]);return(0,pt.useEffect)(()=>{const g=[];for(let m=0;m<n.length;m++){const v=n[m],_=e.get(v);if(_!==void 0)for(const b of _){const S=t.getElementByKey(b);S!==null&&(S.classList.add("selected"),g.push(S),c(!0))}}return()=>{for(let m=0;m<g.length;m++)g[m].classList.remove("selected")}},[n,t,e]),(0,pt.useEffect)(()=>{const g=new Map;return(0,Rc.mergeRegister)((0,Rc.registerNestedElementResolver)(t,Di.MarkNode,m=>(0,Di.$createMarkNode)(m.getIDs()),(m,v)=>{m.getIDs().forEach(_=>{v.addID(_)})}),t.registerMutationListener(Di.MarkNode,m=>{t.getEditorState().read(()=>{for(const[v,_]of m){const b=(0,zt.$getNodeByKey)(v);let S=[];_==="destroyed"?S=g.get(v)||[]:(0,Di.$isMarkNode)(b)&&(S=b.getIDs());for(let C=0;C<S.length;C++){const x=S[C];let y=e.get(x);g.set(v,S),_==="destroyed"?y!==void 0&&(y.delete(v),y.size===0&&e.delete(x)):(y===void 0&&(y=new Set,e.set(x,y)),y.has(v)||y.add(v))}}})}),t.registerUpdateListener(m=>{let{editorState:v,tags:_}=m;v.read(()=>{const b=(0,zt.$getSelection)();let S=!1,C=!1;if((0,zt.$isRangeSelection)(b)){const x=b.anchor.getNode();if((0,zt.$isTextNode)(x)){const y=(0,Di.$getMarkIDs)(x,b.anchor.offset);y!==null&&(i(y),S=!0),b.isCollapsed()||(r(x.getKey()),C=!0)}}S||i(x=>x.length===0?x:[]),C||r(null),(0,zt.$isRangeSelection)(b)&&s(!1)})}),t.registerCommand(ay,()=>{const m=window.getSelection();return m!==null&&m.removeAllRanges(),s(!0),!0},zt.COMMAND_PRIORITY_EDITOR))},[t,e]),pt.createElement(pt.Fragment,null,l&&(0,qc.createPortal)(pt.createElement(W5,{editor:t,cancelAddComment:p,submitAddComment:h}),document.body),a!=null&&!l&&(0,qc.createPortal)(pt.createElement(H5,{anchorKey:a,editor:t,onAddComment:()=>{t.dispatchCommand(ay,void 0)}}),document.body),(0,qc.createPortal)(pt.createElement(Fa,{className:"CodoxCommentPlugin_ShowCommentsButton "+(d?"active":""),onClick:()=>c(!d),title:d?"Hide Comments":"Show Comments"},pt.createElement(z5,null)),document.body),d&&(0,qc.createPortal)(pt.createElement(K5,{comments:o,submitAddComment:h,deleteCommentOrThread:f,activeIDs:n,markNodeMap:e}),document.body))}var th=Tn(766),Yc={};Yc.styleTagTransform=ea(),Yc.setAttributes=Qs(),Yc.insert=Zs().bind(null,"head"),Yc.domAPI=Ys(),Yc.insertStyleElement=Xs(),Gs()(th.A,Yc),th.A&&th.A.locals&&th.A.locals;var nh=Tn(225),Zc={};Zc.styleTagTransform=ea(),Zc.setAttributes=Qs(),Zc.insert=Zs().bind(null,"head"),Zc.domAPI=Ys(),Zc.insertStyleElement=Xs(),Gs()(nh.A,Zc),nh.A&&nh.A.locals&&nh.A.locals;function Y5(u){let{label:t,value:o,onChange:e,placeholder:a="","data-test-id":r,type:n="text"}=u;return pt.createElement("div",{className:"CodoxInput__wrapper"},pt.createElement("label",{className:"CodoxInput__label"},t),pt.createElement("input",{type:n,className:"CodoxInput__input",placeholder:a,value:o,onChange:i=>{e(i.target.value)},"data-test-id":r}))}function sw(u,t){var o=Object.keys(u);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(u);t&&(e=e.filter(function(a){return Object.getOwnPropertyDescriptor(u,a).enumerable})),o.push.apply(o,e)}return o}function rh(u){for(var t=1;t<arguments.length;t++){var o=arguments[t]!=null?arguments[t]:{};t%2?sw(Object(o),!0).forEach(function(e){Z5(u,e,o[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(u,Object.getOwnPropertyDescriptors(o)):sw(Object(o)).forEach(function(e){Object.defineProperty(u,e,Object.getOwnPropertyDescriptor(o,e))})}return u}function Z5(u,t,o){return(t=Q5(t))in u?Object.defineProperty(u,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):u[t]=o,u}function Q5(u){var t=X5(u,"string");return typeof t=="symbol"?t:t+""}function X5(u,t){if(typeof u!="object"||!u)return u;var o=u[Symbol.toPrimitive];if(o!==void 0){var e=o.call(u,t||"default");if(typeof e!="object")return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(u)}let jd=!1;const eI=["#d0021b","#f5a623","#f8e71c","#8b572a","#7ed321","#417505","#bd10e0","#9013fe","#4a90e2","#50e3c2","#b8e986","#000000","#4a4a4a","#9b9b9b","#ffffff"];function tI(u){let{color:t,onChange:o}=u;const[e,a]=(0,pt.useState)(Qc("hex",t)),[r,n]=(0,pt.useState)(t),i=(0,pt.useRef)(null),l=(0,pt.useMemo)(()=>({x:e.hsv.s/100*214,y:(100-e.hsv.v)/100*150}),[e.hsv.s,e.hsv.v]),s=(0,pt.useMemo)(()=>({x:e.hsv.h/360*214}),[e.hsv]);return(0,pt.useEffect)(()=>{i.current!==null&&o&&n(e.hex)},[e,o]),(0,pt.useEffect)(()=>{if(t===void 0)return;const d=Qc("hex",t);a(d),n(d.hex)},[t]),pt.createElement("div",{className:"codox-color-picker-wrapper",style:{width:214},ref:i},pt.createElement(Y5,{label:"Hex",onChange:d=>{if(n(d),/^#[0-9A-Fa-f]{6}$/i.test(d)){const c=Qc("hex",d);a(c)}},value:r}),pt.createElement("div",{className:"codox-color-picker-basic-color"},eI.map(d=>pt.createElement("button",{className:d===e.hex?" active":"",key:d,style:{backgroundColor:d},onClick:()=>(c=>{n(c);let p=Qc("hex",c);a(p),o(p.hex,jd)})(d)}))),pt.createElement(aw,{className:"codox-color-picker-saturation",style:{backgroundColor:`hsl(${e.hsv.h}, 100%, 50%)`},onChange:d=>{let{x:c,y:p}=d;const f=Qc("hsv",rh(rh({},e.hsv),{},{s:c/214*100,v:100-p/150*100}));a(f),n(f.hex),o(f.hex,jd)}},pt.createElement("div",{className:"codox-color-picker-saturation_cursor",style:{backgroundColor:e.hex,left:l.x,top:l.y}})),pt.createElement(aw,{className:"codox-color-picker-hue",onChange:d=>{let{x:c}=d;const p=Qc("hsv",rh(rh({},e.hsv),{},{h:c/214*360}));a(p),n(p.hex),o(p.hex,jd)}},pt.createElement("div",{className:"codox-color-picker-hue_cursor",style:{backgroundColor:`hsl(${e.hsv.h}, 100%, 50%)`,left:s.x}})),pt.createElement("div",{className:"codox-color-picker-color",style:{backgroundColor:e.hex}}))}function aw(u){let{className:t,style:o,onChange:e,children:a}=u;const r=(0,pt.useRef)(null),n=(0,pt.useRef)(!1),i=l=>{if(r.current){const{current:s}=r,{width:d,height:c,left:p,top:f}=s.getBoundingClientRect(),h=lw(l.clientX-p,d,0),g=lw(l.clientY-f,c,0);e({x:h,y:g})}};return pt.createElement("div",{ref:r,className:t,style:o,onMouseDown:l=>{if(l.button!==0)return;i(l);const s=c=>{n.current=!0,jd=!0,i(c)},d=c=>{n.current&&(jd=!1),document.removeEventListener("mousemove",s,!1),document.removeEventListener("mouseup",d,!1),i(c),n.current=!1};document.addEventListener("mousemove",s,!1),document.addEventListener("mouseup",d,!1)}},a)}function lw(u,t,o){return u>t?t:u<o?o:u}function cw(u){if(!u.startsWith("#")){const t=document.createElement("canvas").getContext("2d");if(!t)throw new Error("2d context not supported or canvas already initialized");return t.fillStyle=u,t.fillStyle}return u.length===4||u.length===5?u=u.split("").map((t,o)=>o?t+t:"#").join(""):u.length===7||u.length===9?u:"#000000"}function uw(u){const t=(u.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i,(o,e,a,r)=>"#"+e+e+a+a+r+r).substring(1).match(/.{2}/g)||[]).map(o=>parseInt(o,16));return{b:t[2],g:t[1],r:t[0]}}function by(u){let{r:t,g:o,b:e}=u;t/=255,o/=255,e/=255;const a=Math.max(t,o,e),r=a-Math.min(t,o,e);return{h:r?60*(a===t?(o-e)/r+(o<e?6:0):a===o?2+(e-t)/r:4+(t-o)/r):0,s:a?r/a*100:0,v:100*a}}function nI(u){let{h:t,s:o,v:e}=u;o/=100,e/=100;const a=~~(t/60),r=t/60-a,n=e*(1-o),i=e*(1-o*r),l=e*(1-o*(1-r)),s=a%6,d=Math.round(255*[e,i,n,n,l,e][s]),c=Math.round(255*[l,e,e,i,n,n][s]);return{b:Math.round(255*[n,n,l,e,e,i][s]),g:c,r:d}}function dw(u){let{b:t,g:o,r:e}=u;return"#"+[e,o,t].map(a=>a.toString(16).padStart(2,"0")).join("")}function Qc(u,t){let o=cw("#121212"),e=uw(o),a=by(e);return u==="hex"?(o=cw(t),e=uw(o),a=by(e)):u==="rgb"?(e=t,o=dw(e),a=by(e)):u==="hsv"&&(a=t,e=nI(a),o=dw(e)),{hex:o,hsv:a,rgb:e}}const rI=pt.createContext(null);function oI(u){let{children:t,dropDownRef:o,onClose:e,dropdownClassName:a}=u;const[r,n]=(0,pt.useState)(),[i,l]=(0,pt.useState)(),s=(0,pt.useCallback)(c=>{n(p=>p?[...p,c]:[c])},[n]),d=(0,pt.useMemo)(()=>({registerItem:s}),[s]);return(0,pt.useEffect)(()=>{r&&!i&&l(r[0]),i&&i.current&&i.current.focus()},[r,i]),pt.createElement(rI.Provider,{value:d},pt.createElement("div",{className:a,ref:o,onKeyDown:c=>{if(!r)return;const p=c.key;["Escape","ArrowUp","ArrowDown","Tab"].includes(p)&&c.preventDefault(),p==="Escape"||p==="Tab"?e():p==="ArrowUp"?l(f=>{if(!f)return r[0];const h=r.indexOf(f)-1;return r[h===-1?r.length-1:h]}):p==="ArrowDown"&&l(f=>f?r[r.indexOf(f)+1]:r[0])}},t))}function iI(u){let{disabled:t=!1,buttonLabel:o,buttonAriaLabel:e,buttonClassName:a,buttonIconClassName:r,children:n,stopCloseOnClickSelf:i,dropdownClassName:l,buttonLabelClassName:s,dropdownChevronClassName:d}=u;const c=(0,pt.useRef)(null),p=(0,pt.useRef)(null),[f,h]=(0,pt.useState)(!1);return(0,pt.useEffect)(()=>{const g=p.current,m=c.current;if(f&&g!==null&&m!==null){const{top:v,left:_}=g.getBoundingClientRect();m.style.top=`${v+g.offsetHeight+4}px`,m.style.left=`${Math.min(_,window.innerWidth-m.offsetWidth-20)}px`}},[c,p,f]),(0,pt.useEffect)(()=>{const g=p.current;if(g!==null&&f){const m=v=>{const _=v.target;i&&c.current&&c.current.contains(_)||g.contains(_)||h(!1)};return document.addEventListener("click",m),()=>{document.removeEventListener("click",m)}}},[c,p,f,i]),(0,pt.useEffect)(()=>{const g=()=>{if(f){const m=p.current,v=c.current;if(m!==null&&v!==null){const{top:_}=m.getBoundingClientRect(),b=_+m.offsetHeight+4;b!==v.getBoundingClientRect().top&&(v.style.top=`${b}px`)}}};return document.addEventListener("scroll",g),()=>{document.removeEventListener("scroll",g)}},[p,c,f]),pt.createElement(pt.Fragment,null,pt.createElement("button",{type:"button",disabled:t,"aria-label":e||o,className:a,onClick:()=>h(!f),ref:p},r&&pt.createElement("span",{className:r}),o&&pt.createElement("span",{className:s},o),pt.createElement("i",{className:d})),f&&(0,qc.createPortal)(pt.createElement(oI,{dropDownRef:c,onClose:()=>{h(!1),p&&p.current&&p.current.focus()},dropdownClassName:l},n),document.body))}const sI=["disabled","stopCloseOnClickSelf","color","onChange"];function vy(){return vy=Object.assign?Object.assign.bind():function(u){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var e in o)({}).hasOwnProperty.call(o,e)&&(u[e]=o[e])}return u},vy.apply(null,arguments)}function aI(u,t){if(u==null)return{};var o,e,a=lI(u,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(u);for(e=0;e<r.length;e++)o=r[e],t.includes(o)||{}.propertyIsEnumerable.call(u,o)&&(a[o]=u[o])}return a}function lI(u,t){if(u==null)return{};var o={};for(var e in u)if({}.hasOwnProperty.call(u,e)){if(t.includes(e))continue;o[e]=u[e]}return o}function fw(u){let{disabled:t=!1,stopCloseOnClickSelf:o=!0,color:e,onChange:a}=u,r=aI(u,sI);return pt.createElement(iI,vy({},r,{disabled:t,stopCloseOnClickSelf:o}),pt.createElement(tI,{color:e,onChange:a}))}const cI=u=>{let{onColorChange:t,buttonClassName:o,buttonIconClassName:e,buttonAriaLabel:a,buttonLabel:r,dropdownClassName:n,buttonLabelClassName:i,dropdownChevronClassName:l}=u;const[s]=(0,Da.useLexicalComposerContext)(),[d,c]=(0,pt.useState)(()=>s.isEditable()),[p,f]=(0,pt.useState)("");(0,pt.useEffect)(()=>(0,Rc.mergeRegister)(s.registerEditableListener(g=>{c(g)}),s.registerUpdateListener(g=>{let{editorState:m}=g;m.read(()=>{const v=(0,zt.$getSelection)();if((0,zt.$isRangeSelection)(v)){let _=(0,jl.$getSelectionStyleValueForProperty)(v,"color");_!==p&&(f(_||""),t(_))}})})),[s]);const h=(0,pt.useCallback)((g,m)=>{s.update(()=>{const v=(0,zt.$getSelection)();v!==null&&(0,jl.$patchStyleText)(v,{color:g})})},[s]);return pt.createElement(fw,{disabled:!d,color:p,onChange:h,buttonClassName:o||"",buttonIconClassName:e||"",buttonAriaLabel:a||"",buttonLabel:r||"",dropdownClassName:n||"",buttonLabelClassName:i||"",dropdownChevronClassName:l||""})},uI=cI,dI=u=>{let{onColorChange:t,buttonClassName:o,buttonIconClassName:e,buttonAriaLabel:a,buttonLabel:r,dropdownClassName:n,buttonLabelClassName:i,dropdownChevronClassName:l}=u;const[s]=(0,Da.useLexicalComposerContext)(),[d,c]=(0,pt.useState)(()=>s.isEditable()),[p,f]=(0,pt.useState)("#fff");(0,pt.useEffect)(()=>(0,Rc.mergeRegister)(s.registerEditableListener(g=>{c(g)}),s.registerUpdateListener(g=>{let{editorState:m}=g;m.read(()=>{const v=(0,zt.$getSelection)();if((0,zt.$isRangeSelection)(v)){let _=(0,jl.$getSelectionStyleValueForProperty)(v,"background-color");_!==p&&(f(_||""),t(_))}})})),[s]);const h=(0,pt.useCallback)((g,m)=>{s.update(()=>{const v=(0,zt.$getSelection)();v!==null&&(0,jl.$patchStyleText)(v,{"background-color":g})})},[s]);return pt.createElement(fw,{disabled:!d,color:p,onChange:h,buttonClassName:o||"",buttonIconClassName:e||"",buttonAriaLabel:a||"",buttonLabel:r||"",dropdownClassName:n||"",buttonLabelClassName:i||"",dropdownChevronClassName:l||""})},fI=dI;var pw=Pa.yy;Pa._U,Pa.a8,Pa.Vs,Pa.Cn;var hw=Pa.gK;Pa.vv;const pI=typeof window<"u"&&window.document!==void 0&&window.document.createElement!==void 0?ve.useLayoutEffect:ve.useEffect,gw=u=>{const t=document.getElementById("typeahead-menu");if(!t)return;const o=t.getBoundingClientRect();o.top+o.height>window.innerHeight&&t.scrollIntoView({block:"center"}),o.top<0&&t.scrollIntoView({block:"center"}),u.scrollIntoView({block:"nearest"})};function mw(u,t){const o=u.getBoundingClientRect(),e=t.getBoundingClientRect();return o.top>e.top&&o.top<e.bottom}function hI(u,t,o,e){const[a]=Gn();ve.useEffect(()=>{if(t!=null&&u!=null){const r=a.getRootElement(),n=r!=null?function(c,p){let f=getComputedStyle(c);const h=f.position==="absolute",g=/(auto|scroll)/;if(f.position==="fixed")return document.body;for(let m=c;m=m.parentElement;)if(f=getComputedStyle(m),(!h||f.position!=="static")&&g.test(f.overflow+f.overflowY+f.overflowX))return m;return document.body}(r):document.body;let i=!1,l=mw(t,n);const s=function(){i||(window.requestAnimationFrame(function(){o(),i=!1}),i=!0);const c=mw(t,n);c!==l&&(l=c,e!=null&&e(c))},d=new ResizeObserver(o);return window.addEventListener("resize",o),document.addEventListener("scroll",s,{capture:!0,passive:!0}),d.observe(t),()=>{d.unobserve(t),window.removeEventListener("resize",o),document.removeEventListener("scroll",s,!0)}}},[t,a,e,o,u])}const yw=jo();function gI({close:u,editor:t,anchorElementRef:o,resolution:e,options:a,menuRenderFn:r,onSelectOption:n,shouldSplitNodeWithQuery:i=!1,commandPriority:l=In}){const[s,d]=ve.useState(null),c=e.match&&e.match.matchingString;ve.useEffect(()=>{d(0)},[c]);const p=ve.useCallback(h=>{t.update(()=>{const g=e.match!=null&&i?function(m){const v=Ot();if(!xt(v)||!v.isCollapsed())return null;const _=v.anchor;if(_.type!=="text")return null;const b=_.getNode();if(!b.isSimpleText())return null;const S=_.offset,C=b.getTextContent().slice(0,S),x=m.replaceableString.length,y=S-function(E,I,j){let B=j;for(let N=B;N<=I.length;N++)E.substr(-N)===I.substr(0,N)&&(B=N);return B}(C,m.matchingString,x);if(y<0)return null;let w;return y===0?[w]=b.splitText(S):[,w]=b.splitText(y,S),w}(e.match):null;n(h,g,u,e.match?e.match.matchingString:"")})},[t,i,e.match,n,u]),f=ve.useCallback(h=>{const g=t.getRootElement();g!==null&&(g.setAttribute("aria-activedescendant","typeahead-item-"+h),d(h))},[t]);return ve.useEffect(()=>()=>{const h=t.getRootElement();h!==null&&h.removeAttribute("aria-activedescendant")},[t]),pI(()=>{a===null?d(null):s===null&&f(0)},[a,s,f]),ve.useEffect(()=>Br(t.registerCommand(yw,({option:h})=>!(!h.ref||h.ref.current==null)&&(gw(h.ref.current),!0),l)),[t,f,l]),ve.useEffect(()=>Br(t.registerCommand(Wu,h=>{const g=h;if(a!==null&&a.length&&s!==null){const m=s!==a.length-1?s+1:0;f(m);const v=a[m];v.ref!=null&&v.ref.current&&t.dispatchCommand(yw,{index:m,option:v}),g.preventDefault(),g.stopImmediatePropagation()}return!0},l),t.registerCommand(qu,h=>{const g=h;if(a!==null&&a.length&&s!==null){const m=s!==0?s-1:a.length-1;f(m);const v=a[m];v.ref!=null&&v.ref.current&&gw(v.ref.current),g.preventDefault(),g.stopImmediatePropagation()}return!0},l),t.registerCommand(Fs,h=>{const g=h;return g.preventDefault(),g.stopImmediatePropagation(),u(),!0},l),t.registerCommand(_f,h=>{const g=h;return a!==null&&s!==null&&a[s]!=null&&(g.preventDefault(),g.stopImmediatePropagation(),p(a[s]),!0)},l),t.registerCommand(ds,h=>a!==null&&s!==null&&a[s]!=null&&(h!==null&&(h.preventDefault(),h.stopImmediatePropagation()),p(a[s]),!0),l)),[p,u,t,a,s,f,l]),r(o,ve.useMemo(()=>({options:a,selectOptionAndCleanUp:p,selectedIndex:s,setHighlightedIndex:d}),[p,s,a]),e.match?e.match.matchingString:"")}function mI({options:u,onQueryChange:t,onSelectOption:o,onOpen:e,onClose:a,menuRenderFn:r,triggerFn:n,anchorClassName:i,commandPriority:l=In,parent:s}){const[d]=Gn(),[c,p]=ve.useState(null),f=function(m,v,_,b=document.body){const[S]=Gn(),C=ve.useRef(document.createElement("div")),x=ve.useCallback(()=>{C.current.style.top=C.current.style.bottom;const w=S.getRootElement(),E=C.current,I=E.firstChild;if(w!==null&&m!==null){const{left:j,top:B,width:N,height:D}=m.getRect(),P=C.current.offsetHeight;if(E.style.top=`${B+window.pageYOffset+P+3}px`,E.style.left=`${j+window.pageXOffset}px`,E.style.height=`${D}px`,E.style.width=`${N}px`,I!==null){I.style.top=`${B}`;const k=I.getBoundingClientRect(),A=k.height,L=k.width,R=w.getBoundingClientRect();j+L>R.right&&(E.style.left=`${R.right-L+window.pageXOffset}px`),(B+A>window.innerHeight||B+A>R.bottom)&&B-R.top>A+D&&(E.style.top=B-A+window.pageYOffset-D+"px")}E.isConnected||(_!=null&&(E.className=_),E.setAttribute("aria-label","Typeahead menu"),E.setAttribute("id","typeahead-menu"),E.setAttribute("role","listbox"),E.style.display="block",E.style.position="absolute",b.append(E)),C.current=E,w.setAttribute("aria-controls","typeahead-menu")}},[S,m,_,b]);ve.useEffect(()=>{const w=S.getRootElement();if(m!==null)return x(),()=>{w!==null&&w.removeAttribute("aria-controls");const E=C.current;E!==null&&E.isConnected&&E.remove()}},[S,x,m]);const y=ve.useCallback(w=>{m!==null&&(w||v(null))},[m,v]);return hI(m,C.current,x,y),C}(c,p,i,s),h=ve.useCallback(()=>{p(null),a!=null&&c!==null&&a()},[a,c]),g=ve.useCallback(m=>{p(m),e!=null&&c===null&&e(m)},[e,c]);return ve.useEffect(()=>{const m=d.registerUpdateListener(()=>{d.getEditorState().read(()=>{const v=d._window||window,_=v.document.createRange(),b=Ot(),S=function(y){let w=null;return y.getEditorState().read(()=>{const E=Ot();xt(E)&&(w=function(I){const j=I.anchor;if(j.type!=="text")return null;const B=j.getNode();if(!B.isSimpleText())return null;const N=j.offset;return B.getTextContent().slice(0,N)}(E))}),w}(d);if(!xt(b)||!b.isCollapsed()||S===null||_===null)return void h();const C=n(S,d);if(t(C?C.matchingString:null),C!==null&&!function(y,w){return w===0&&y.getEditorState().read(()=>{const E=Ot();if(xt(E)){const I=E.anchor.getNode().getPreviousSibling();return kt(I)&&I.isTextEntity()}return!1})}(d,C.leadOffset)&&function(w,E,I){const j=I.getSelection();if(j===null||!j.isCollapsed)return!1;const B=j.anchorNode,N=w,D=j.anchorOffset;if(B==null||D==null)return!1;try{E.setStart(B,N),E.setEnd(B,D)}catch{return!1}return!0}(C.leadOffset,_,v)!==null)return x=()=>g({getRect:()=>_.getBoundingClientRect(),match:C}),void(ur.startTransition?ur.startTransition(x):x());var x;h()})});return()=>{m()}},[d,n,t,c,h,g]),c===null||d===null?null:ke.jsx(gI,{close:h,resolution:c,editor:d,anchorElementRef:f,options:u,menuRenderFn:r,shouldSplitNodeWithQuery:!0,onSelectOption:o,commandPriority:l})}function bw(u,t){return u.getEditorState().read(()=>{const o=Qn(t);return o!==null&&o.isSelected()})}function oh(u){const[t]=Gn(),[o,e]=ve.useState(()=>bw(t,u));return ve.useEffect(()=>{let a=!0;const r=t.registerUpdateListener(()=>{a&&e(bw(t,u))});return()=>{a=!1,r()}},[t,u]),[o,ve.useCallback(a=>{t.update(()=>{let r=Ot();pr(r)||(r=Kf(),nr(r)),pr(r)&&(a?r.add(u):r.delete(u))})},[t,u]),ve.useCallback(()=>{t.update(()=>{const a=Ot();pr(a)&&a.clear()})},[t])]}const Xc=typeof window<"u"&&typeof window.document.createElement<"u",yI=Xc&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,Pd=Xc&&window.matchMedia("(pointer: coarse)").matches,bI=Xc?ve.useLayoutEffect:ve.useEffect,_y=()=>{const[u]=Gn(),[t,o]=ve.useState(()=>Xc?u.getRootElement()===document.activeElement:!1);return bI(()=>Br(u.registerCommand(Cf,()=>(o(!0),!1),pd),u.registerCommand(Ef,()=>(o(!1),!1),pd)),[u]),t};function vI(u){const{value:t,trigger:o,data:e,className:a,classNameFocused:r,classNames:n,nodeKey:i,component:l}=u,[s]=Gn(),d=_y(),[c,p,f]=oh(i),h=ve.useRef(null),g=o+t,m=ve.useMemo(()=>{if(a){const y=[a];return c&&d&&r&&y.push(r),y.join(" ").trim()||void 0}return""},[c,a,r,d]),v=ve.useCallback(y=>{if(c&&pr(Ot())){y.preventDefault();const w=Qn(i);Dl(w)&&w.remove()}return!1},[c,i]),_=ve.useCallback(y=>{const w=Qn(i);if(!(w!=null&&w.isSelected()))return!1;let E=!1;const I=ah(w);return dt(I)&&(I.selectEnd(),E=!0),kt(I)&&(I.select(),E=!0),or(I)&&(I.selectNext(),E=!0),I===null&&(w.selectPrevious(),E=!0),E&&y.preventDefault(),E},[i]),b=ve.useCallback(y=>{const w=Qn(i);if(!(w!=null&&w.isSelected()))return!1;let E=!1;const I=sh(w);return dt(I)&&(I.selectStart(),E=!0),kt(I)&&(I.select(0,0),E=!0),or(I)&&(I.selectPrevious(),E=!0),I===null&&(w.selectNext(),E=!0),E&&y.preventDefault(),E},[i]),S=ve.useCallback(y=>{var w;return y.target===h.current||!((w=h.current)===null||w===void 0)&&w.contains(y.target)?(y.shiftKey||f(),p(!0),!0):!1},[f,p]),C=ve.useCallback(()=>{const y=Qn(i);if(!(y!=null&&y.isSelected()))return!1;const w=Ot();return pr(w)&&nr(null),!1},[i]),x=ve.useCallback(()=>yI&&c?(p(!1),!0):!1,[c,p]);return ve.useEffect(()=>{const y=Br(s.registerCommand(ma,S,In),s.registerCommand(zs,v,In),s.registerCommand(Vi,v,In),s.registerCommand($u,_,In),s.registerCommand(Hu,b,In),s.registerCommand(Ef,C,In),s.registerCommand(ti,x,In));return()=>{y()}},[s,_,b,S,v,C,x]),l?ke.jsx(l,{ref:h,trigger:o,value:t,data:e,className:m,"data-beautiful-mention":g,children:g}):n?ke.jsxs("span",{ref:h,className:c&&n.containerFocused?n.containerFocused:n.container,"data-beautiful-mention":g,children:[ke.jsx("span",{className:n.trigger,children:o}),ke.jsx("span",{className:n.value,children:t})]}):ke.jsx("span",{ref:h,className:m,"data-beautiful-mention":g,children:g})}function _I(u){const t=u.getAttribute("data-lexical-beautiful-mention-trigger"),o=u.getAttribute("data-lexical-beautiful-mention-value");let e;const a=u.getAttribute("data-lexical-beautiful-mention-data");if(a)try{e=JSON.parse(a)}catch(r){console.warn("Failed to parse data attribute of beautiful mention node",r)}return t!=null&&o!==null?{node:Id(t,o,e)}:null}class Rl extends yc{static getType(){return"beautifulMention"}static clone(t){return new Rl(t.__trigger,t.__value,t.__data,t.__key)}constructor(t,o,e,a){super(a),this.__trigger=t,this.__value=o,this.__data=e}createDOM(){return document.createElement("span")}updateDOM(){return!1}exportDOM(){const t=document.createElement("span");return t.setAttribute("data-lexical-beautiful-mention","true"),t.setAttribute("data-lexical-beautiful-mention-trigger",this.__trigger),t.setAttribute("data-lexical-beautiful-mention-value",this.__value),this.__data&&t.setAttribute("data-lexical-beautiful-mention-data",JSON.stringify(this.__data)),t.textContent=this.getTextContent(),{element:t}}static importDOM(){return{span:t=>t.hasAttribute("data-lexical-beautiful-mention")?{conversion:_I,priority:1}:null}}static importJSON(t){return Id(t.trigger,t.value,t.data)}exportJSON(){const t=this.__data;return Object.assign(Object.assign({trigger:this.__trigger,value:this.__value},t?{data:t}:{}),{type:"beautifulMention",version:1})}getTextContent(){const t=this.getLatest();return t.__trigger+t.__value}getTrigger(){return this.getLatest().__trigger}getValue(){return this.getLatest().__value}setValue(t){const o=this.getWritable();o.__value=t}getData(){return this.getLatest().__data}setData(t){const o=this.getWritable();o.__data=t}component(){return null}decorate(t,o){const{className:e,classNameFocused:a,classNames:r}=this.getCssClassesFromTheme(o);return ke.jsx(vI,{nodeKey:this.getKey(),trigger:this.getTrigger(),value:this.getValue(),data:this.getData(),className:e,classNameFocused:a,classNames:r,component:this.component()})}getCssClassesFromTheme(t){var o;const e=t.theme.beautifulMentions||{},a=Object.entries(e).find(([d])=>new RegExp(d).test(this.__trigger)),r=(o=a==null?void 0:a[0])!==null&&o!==void 0?o:"",n=a==null?void 0:a[1],i=typeof n=="string"?n:void 0,l=i&&typeof e[r+"Focused"]=="string"?e[r+"Focused"]:void 0;return{className:i,classNameFocused:l,classNames:a&&typeof n!="string"?n:void 0}}}function Id(u,t,o){const e=new Rl(u,t,o);return mo(e)}function Dl(u){return u instanceof Rl}const xI="​";class ih extends ni{static getType(){return"zeroWidth"}static clone(t){return new ih(t.__textContent,t.__key)}static importJSON(t){return wI()}constructor(t,o){super(xI,o),this.__textContent=t}exportJSON(){return Object.assign(Object.assign({},super.exportJSON()),{text:"",type:"zeroWidth"})}updateDOM(){return!1}static importDOM(){return null}exportDOM(t){return{element:null}}isTextEntity(){return!0}getTextContent(){return this.__textContent}}function wI(u=""){const t=new ih(u);return t.setMode("segmented"),mo(t)}function xy(u){return u instanceof ih}const SI=`\\.,\\*\\?\\$\\|#{}\\(\\)\\^\\[\\]\\\\/!%'"~=<>_:;`,CI="\\(",EI=u=>"(?:"+u.join("|")+")",vw=(u,t)=>(u.length===0?"":"(?!"+u.join("|")+")")+"[^\\s"+t+"]",kI=75;function wy(u,t,o){return new RegExp(vw(t,o)).test(u)}function Md(u,t){const o=Ot();if(!o||!xt(o))return;const e=o.anchor,a=o.focus,[r]=o.getNodes();if(e.key!==a.key||e.offset!==a.offset||!r)return;const n=kt(r)&&r.isSimpleText(),i=e.type,l=e.offset,s=Ss(r),d=l===0,c=s.length===l,p=s.charAt(l-1),f=s.charAt(l),h=wy(p,u,t),g=wy(f,u,t),m=/\s/.test(p),v=/\s/.test(f),_=ah(r),b=sh(r),S=r.getParent(),C={node:r,type:i,offset:l,isTextNode:n,textContent:s,selection:o,prevNode:_,nextNode:b,parentNode:S,cursorAtStartOfNode:d,cursorAtEndOfNode:c,wordCharBeforeCursor:h,wordCharAfterCursor:g,spaceBeforeCursor:m,spaceAfterCursor:v};return n?Object.assign(Object.assign({},C),{isTextNode:!0,node:r}):Object.assign(Object.assign({},C),{isTextNode:!1,node:r})}function sh(u){let t=u.getNextSibling();for(;t!==null&&xy(t);)t=t.getNextSibling();return t}function ah(u){let t=u.getPreviousSibling();for(;t!==null&&xy(t);)t=t.getPreviousSibling();return t}function Ss(u){return xy(u)?"":u.getTextContent()}function OI(u,t){return typeof u=="string"||typeof u=="boolean"?u:t===null?!1:typeof u=="object"?u[t]:!1}function TI(u,t){return typeof u=="number"||u===!1?u:typeof u>"u"?5:t===null?!1:typeof u=="object"?u[t]:5}function AI(u){const t=u.getLastDescendant();return dt(t)||kt(t)?t:or(t)?t.getParent():u}function Sy(){const u=Zn(),t=AI(u),o=t==null?void 0:t.getKey(),e=dt(t)?t.getChildrenSize():kt(t)?Ss(t).length:0,a=dt(t)?"element":"text";if(o){const r=hc();r.anchor.set(o,e,a),r.focus.set(o,e,a),nr(r)}}function Cy(u){return u=u??a2(),Mg(Rl)}class Ey{constructor(t,o,e){this.value=t,this.displayValue=o,this.data=e,this.key=e?JSON.stringify(Object.assign(Object.assign({},e),{value:t})):t,this.displayValue=o??t,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(t){this.ref={current:t}}}function _w(u){const t=Ot();if(!xt(t)||!t.isCollapsed())return null;const o=t.anchor;if(o.type!=="text")return null;const e=o.getNode();if(!e.isSimpleText())return null;const a=o.offset,r=Ss(e).slice(0,a),n=u.replaceableString.length,i=NI(r,u.matchingString,n),l=a-i;if(l<0)return null;let s;return l===0?[s]=e.splitText(a):[,s]=e.splitText(l,a),s}function NI(u,t,o){let e=o;for(let a=e;a<=t.length;a++)u.substring(-a)===t.substring(0,a)&&(e=a);return e}class lh extends Jo{static getType(){return"placeholder"}static clone(t){return new lh(t.__textContent,t.__key)}constructor(t,o){super(o),this.__textContent=t}createDOM(t){const o=document.createElement("img");return o.style.display="inline",o.style.border="none",o.style.margin="0",o.style.height="1px",o.style.width="1px",o}updateDOM(){return!1}static importDOM(){return null}static importJSON(t){return jI()}isInline(){return!0}exportJSON(){return Object.assign(Object.assign({},super.exportJSON()),{type:"placeholder"})}getTextContent(){return""}}function jI(u=""){const t=new lh(u);return mo(t)}function PI(u){return u instanceof lh}const II=jo(),MI=jo(),RI=jo(),DI=jo();function xw(u,t,o,e){return ww(u,t,o,void 0,void 0,e)}function LI(u,t,o,e,a,r){return ww(u,t,o,e,a,r)}function ww(u,t,o,e,a,r){const n=Md(u,t);if(!n)return!1;const{node:i,selection:l,wordCharBeforeCursor:s,wordCharAfterCursor:d,cursorAtStartOfNode:c,cursorAtEndOfNode:p,prevNode:f,nextNode:h}=n,g=e?Id(o,e,a):Xn(o),m=[];if(!(Zi(i)&&c)&&!kt(i))return r&&m.push(Xn(" ")),m.push(g),l.insertNodes(m),!0;let v=null;return r&&(s||c&&f!==null&&!kt(f))&&m.push(Xn(" ")),m.push(g),r&&(d||p&&h!==null&&!kt(h))&&(v=Xn(" "),m.push(v)),l.insertNodes(m),m.length>1&&(kt(g)?g.select():v&&v.selectPrevious()),!0}function BI(u,t,o=!0){let e=!1,a=null,r=null;const n=Cy();for(const i of n){const l=i.getTrigger()===u,s=i.getValue()===t;l&&(s||!t)&&(a=ah(i),r=sh(i),i.remove(),e=!0,kt(a)&&Ss(a).endsWith(" ")&&r&&Ss(r).startsWith(" ")&&a.setTextContent(Ss(a).slice(0,-1)),(r===null||PI(r))&&kt(a)&&Ss(a).endsWith(" ")&&a.setTextContent(Ss(a).trimEnd()))}return e&&o?Sw(a,r):o||nr(null),e}function FI(u,t,o,e=!0){const a=Cy();let r=null;for(const n of a){const i=n.getTrigger()===u,l=n.getValue()===o;i&&(l||!o)&&(r=n,n.setValue(t))}if(r&&e){const n=ah(r),i=sh(r);Sw(n,i),i&&kt(i)?i.select(0,0):Sy()}else e||nr(null);return r!==null}function Sw(u,t){t&&kt(t)?t.select(0,0):u&&kt(u)?u.select():Sy()}class ky extends Ey{constructor(t,o,e,a={}){super(o,e,a),this.itemType=t,this.comboboxItem={itemType:t,value:o,displayValue:e,data:a},this.menuOption=new Ey(o,e,a)}}function Oy(u){let t=null;return u.getEditorState().read(()=>{const o=Ot();xt(o)&&(t=zI(o))}),t}function zI(u){const t=u.anchor;if(t.type!=="text")return null;const o=t.getNode();if(!o.isSimpleText())return null;const e=t.offset;return Ss(o).slice(0,e)}function UI(u){return u.key.length===1&&!u.ctrlKey&&!u.altKey&&!u.metaKey&&!u.repeat}function HI(u,t,o){const[e]=Gn(),[a,r]=ve.useState(t??null),[n,i]=ve.useState(null);return ve.useEffect(()=>{if(t){r(t);return}return e.registerRootListener(l=>{l&&r(l.parentElement)})},[e,t]),ve.useEffect(()=>{if(!a)return;if(!u){n&&(n.remove(),i(null));return}const{height:l}=a.getBoundingClientRect(),s=n??document.createElement("div");s.style.position="absolute",s.style.left="0",s.style.right="0",s.style.paddingTop=`${l}px`,a.prepend(s),n||i(s);const d=new ResizeObserver(([c])=>{s.style.paddingTop=`${c.contentRect.height}px`});return d.observe(a),setTimeout(()=>{s.className=o??""}),()=>{d.disconnect(),a.removeChild(s)}},[a,u,n,o]),n}function $I(u,t){var o;const e=(o=u.split(/\s/).pop())!==null&&o!==void 0?o:u,a=u!==e?u.lastIndexOf(e):0;return t.some(n=>n.startsWith(e)&&n!==e)?{leadOffset:a,matchingString:e,replaceableString:e}:null}function qI(u){var t;const{onSelectOption:o,triggers:e,punctuation:a,autoSpace:r,loading:n,triggerFn:i,onQueryChange:l,onReset:s,comboboxAnchor:d,comboboxAnchorClassName:c,comboboxComponent:p="div",comboboxItemComponent:f="div",onComboboxOpen:h,onComboboxClose:g,onComboboxFocusChange:m,comboboxAdditionalItems:v=[],onComboboxItemSelect:_}=u,b=_y(),[S]=Gn(),[C,x]=ve.useState(null),[y,w]=ve.useState(null),[E,I]=ve.useState(null),[j,B]=ve.useState(null),N=u.options.length===0?"trigger":"value",D=ve.useMemo(()=>{const Z=v.map(X=>new ky("additional",X.value,X.displayValue,X.data));if(N==="trigger"){const X=e.map(ee=>new ky("trigger",ee,ee));return!j||X.every(ee=>!ee.value.startsWith(j))?[...X,...Z]:[...X.filter(ee=>ee.value.startsWith(j)),...Z]}return[...u.options.map(X=>new ky("value",X.value,X.displayValue,X.data)),...Z]},[v,N,u.options,e,j]),[P,k]=ve.useState((t=u.comboboxOpen)!==null&&t!==void 0?t:!1),A=HI(P,d,c),L=ve.useCallback(Z=>{Pd||x(Z)},[]),R=ve.useCallback(Z=>{var X;const ne=(X=D[Z].ref)===null||X===void 0?void 0:X.current;ne&&ne.scrollIntoView({block:"nearest"})},[D]),J=ve.useCallback((Z,X)=>{if(!b)return!1;let ee;return X==="up"?C===null?ee=D.length-1:C===0?ee=null:ee=C-1:C===null?ee=0:C===D.length-1?ee=null:ee=C+1,L(ee),ee&&R(ee),Z.preventDefault(),Z.stopImmediatePropagation(),!0},[b,C,D.length,R,L]),T=ve.useCallback(Z=>{L(Z),R(Z)},[R,L]),H=ve.useCallback(()=>{L(null)},[L]),W=ve.useCallback(Z=>{const X=D[Z];_==null||_(X.comboboxItem),X.itemType!=="additional"&&(S.update(()=>{const ee=E?_w(E):null;o(X.menuOption,ee)}),I(null),l(null),B(null),L(null))},[D,S,l,L,_,E,o]),K=ve.useCallback(Z=>{const X=D[Z];_==null||_(X.comboboxItem),X.itemType!=="additional"&&(S.update(()=>{const ee=y?_w(y):null;if(ee){const ne=Xn(X.value);ee.replace(ne),ne.select()}else xw(e,a,X.value,r)}),w(null),B(null),L(0))},[D,S,L,_,y,e,a,r]),F=ve.useCallback(Z=>{N==="trigger"&&K(Z),N==="value"&&W(Z)},[N,K,W]),q=ve.useCallback(Z=>{if(!b||C===null)return!1;let X=!1;return N==="trigger"&&(X=!0,K(C)),N==="value"&&(X=!0,W(C)),X&&(Z.preventDefault(),Z.stopImmediatePropagation()),X},[b,W,K,N,C]),$=ve.useCallback(()=>{const Z=Oy(S),X=Z?Z.substring(0,Z.length-1):void 0;return X!=null&&X.trim()||L(null),!1},[S,L]),z=ve.useCallback(Z=>{if(k(!0),!UI(Z))return!1;const X=Oy(S),ne=(X===null?Z.key:X+Z.key).trim();return D.some(ce=>ce.displayValue.startsWith(ne)&&ne.length<=ce.displayValue.length)?L(0):N==="trigger"&&L(null),!1},[S,D,N,L]),Y=ve.useCallback(()=>(k(!0),!1),[]),G=ve.useCallback(()=>(k(!1),j||(B(null),w(null),I(null)),!1),[j]);return ve.useEffect(()=>Br(S.registerCommand(Wu,Z=>J(Z,"down"),In),S.registerCommand(qu,Z=>J(Z,"up"),In),S.registerCommand(ds,q,pd),S.registerCommand(_f,q,In),S.registerCommand(Vi,$,In),S.registerCommand(hg,z,In),S.registerCommand(Cf,Y,pd),S.registerCommand(ma,()=>(P||k(!0),!1),In),S.registerCommand(Fs,()=>(k(!1),!1),In)),[S,P,J,q,$,z,Y]),ve.useEffect(()=>{const Z=()=>{S.getEditorState().read(()=>{const X=Oy(S);if(X===null){s(),w(null),I(null),l(null),B(null);return}const ee=$I(X,e);if(w(ee),ee){B(ee.matchingString),I(null);return}const ne=i(X,S);if(I(ne),l(ne?ne.matchingString:null),ne!=null&&ne.matchingString){B(ne.matchingString);return}B(null)})};return S.registerUpdateListener(Z)},[S,i,l,s,e]),ve.useEffect(()=>{var Z;k((Z=u.comboboxOpen)!==null&&Z!==void 0?Z:!1)},[u.comboboxOpen]),ve.useEffect(()=>{P?h==null||h():(x(null),g==null||g())},[h,g,P]),ve.useEffect(()=>{C!==null&&D[C]?m==null||m(D[C].comboboxItem):m==null||m(null)},[C,D,m]),ve.useEffect(()=>{if(!Xc)return;const Z=S.getRootElement(),X=ee=>{A&&!A.contains(ee.target)&&Z&&!Z.contains(ee.target)&&G()};return document.addEventListener("mousedown",X),()=>{document.removeEventListener("mousedown",X)}},[A,S,G]),!P||!A?null:yf.createPortal(ke.jsx(p,{loading:n,itemType:N,role:"menu","aria-activedescendant":C!==null&&D[C]?D[C].displayValue:"","aria-label":"Choose trigger and value","aria-hidden":!P,children:D.map((Z,X)=>ke.jsx(f,{selected:X===C,role:"menuitem","aria-selected":C===X,"aria-label":`Choose ${Z.value}`,item:Z.comboboxItem,ref:Z.setRefElement,onClick:()=>{F(X)},onMouseEnter:()=>{T(X)},onMouseLeave:H,onMouseDown:ee=>{ee.preventDefault()},children:Z.displayValue},Z.key))}),A)}function WI(u,t){const[o,e]=ve.useState(u);return ve.useEffect(()=>{const a=setTimeout(()=>{e(u)},t);return()=>{clearTimeout(a)}},[u,t]),o}function VI(u){const{queryString:t,trigger:o,searchDelay:e,items:a,onSearch:r,justSelectedAnOption:n}=u,i=WI(t,e),[l,s]=ve.useState(!1),[d,c]=ve.useState([]),[p,f]=ve.useState(null);return ve.useEffect(()=>{if(!a)return;if(o===null){c([]),f(null);return}const h=Object.entries(a).find(([m])=>new RegExp(m).test(o));if(!h)return;const g=t?h[1].filter(m=>(typeof m=="string"?m:m.value).toLowerCase().includes(t.toLowerCase())):[...h[1]];c(g),f(t)},[a,o,t]),ve.useEffect(()=>{if(r){if(o===null||i===null){c([]),f(null);return}s(!0),f(i),r(o,n!=null&&n.current?"":i).then(h=>{c(h)}).finally(()=>{s(!1)}),n!=null&&n.current&&(n.current=!1)}},[i,r,o,n]),ve.useMemo(()=>({loading:l,results:d,query:p}),[l,d,p])}var JI=globalThis&&globalThis.__rest||function(u,t){var o={};for(var e in u)Object.prototype.hasOwnProperty.call(u,e)&&t.indexOf(e)<0&&(o[e]=u[e]);if(u!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,e=Object.getOwnPropertySymbols(u);a<e.length;a++)t.indexOf(e[a])<0&&Object.prototype.propertyIsEnumerable.call(u,e[a])&&(o[e[a]]=u[e[a]]);return o};class ch extends Ey{constructor(t,o,e,a){super(o,e,a),this.trigger=t,this.menuItem={trigger:t,value:o,displayValue:e,data:a}}}const KI=u=>"(?:\\.[ |$]|\\s|["+u+"]|)";function GI(u,t,o,e){return new RegExp((t?`(^|\\s|${t})(`:"(^|\\s)(")+EI(u)+"((?:"+vw(u,o)+(e?KI(o):"")+"){0,"+kI+"}))$")}function Cw(u,t,o,e,a){const r=GI(t,o,e,a).exec(u);if(r!==null){const n=r[1],i=r[2],l=r[3];if(i.length>=1)return{leadOffset:r.index+n.length,matchingString:l,replaceableString:i}}return null}function YI(u){const{items:t,onSearch:o,autoSpace:e=!0,searchDelay:a=u.onSearch?250:0,allowSpaces:r=!0,insertOnBlur:n=!0,menuComponent:i="ul",menuItemComponent:l="li",emptyComponent:s,menuAnchorClassName:d,showMentionsOnDelete:c,showCurrentMentionsAsSuggestions:p=!0,mentionEnclosure:f,onMenuOpen:h,onMenuClose:g,onMenuItemSelect:m,punctuation:v=SI,preTriggerChars:_=CI}=u,b=ve.useRef(!1),S=_y(),C=ve.useMemo(()=>{var G;return(G=u.triggers)!==null&&G!==void 0?G:Object.keys(t??{})},[u.triggers,t]),[x]=Gn(),[y,w]=ve.useState(null),[E,I]=ve.useState(null),{results:j,loading:B,query:N}=VI({queryString:y,searchDelay:a,trigger:E,items:t,onSearch:o,justSelectedAnOption:b}),D=ve.useRef(),P=ve.useRef(null),k=OI(u.creatable,E),A=TI(u.menuItemLimit,E),L=ve.useMemo(()=>{if(!E)return[];let G=j.map(X=>{if(typeof X=="string")return new ch(E,X,X);{const{value:ee}=X,ne=JI(X,["value"]);return new ch(E,ee,ee,ne)}});if(A!==!1&&A>0&&(G=G.slice(0,A)),(!o||!B&&N!==null)&&p&&x.getEditorState().read(()=>{const X=Cy(x);for(const ee of X){const ne=ee.getValue(),ce=ee.getData();ee.getTrigger()===E&&(N===null||ee.getValue().startsWith(N))&&G.every(ae=>ae.value!==ne)&&G.push(new ch(E,ne,ne,ce))}}),N&&G.every(X=>X.displayValue!==N)){const X=typeof k=="string"?k.replace("{{name}}",N):typeof k>"u"||k?`Add "${N}"`:void 0;X&&G.push(new ch(E,N,X))}return G},[j,o,B,N,x,E,k,A,p]),R=!!L.length||B,J=ve.useCallback(()=>{I(null)},[]),T=ve.useCallback((G,Z,X)=>{x.update(()=>{if(!E)return;const ne=!!k&&G.value!==G.displayValue&&f&&/\s/.test(G.value)?f+G.value+f:G.value,ce=Id(E,ne,G.data);if(Z){const ae=Z.getNextSibling();if(Z.replace(ce),ae instanceof ni){const de=ae.getTextContent();!/\s/.test(de)&&ne.includes(de)&&ae.remove()}}X==null||X(),b.current=!0})},[x,E,k,f]),H=ve.useCallback((G,Z,X)=>{E&&(m==null||m({trigger:E,value:G.value,displayValue:G.displayValue,data:G.data}),T(G,Z,X))},[T,m,E]),W=ve.useCallback(G=>{const Z=Cw(G,C,_,v,r);if(Z){const{replaceableString:X,matchingString:ee}=Z,ne=X.lastIndexOf(ee),ce=ne===-1?X:X.substring(0,ne)+X.substring(ne+ee.length);if(I(ce||null),Z.replaceableString)return Z}else I(null);return null},[_,r,v,C]),K=ve.useCallback(()=>{const G=D.current;let Z=typeof G=="number"?L[G]:void 0;const X=L.find(se=>se.value!==se.displayValue);if(X&&(Pd||Z===null)&&(Z=X),!Z)return!1;const ee=Md(C,v);if(!E||!(ee!=null&&ee.isTextNode))return!1;const ne=ee.node,ce=Ss(ne),ae=Cw(ce,C,_,v,r);if(ae===null)return!1;const de=ce.search(new RegExp(`${ae.replaceableString}\\s?$`));if(de===-1)return!1;const xe=Id(E,Z.value,Z.data);return x.update(()=>{ne.setTextContent(ce.substring(0,de)),ne.insertAfter(xe),xe.selectNext()},{tag:"history-merge"}),!0},[x,L,_,v,E,C,r]),F=ve.useCallback(()=>{const G=Ot();if((!G||pr(G))&&P.current){const Z=P.current.clone();nr(Z)}else G||Sy();P.current&&(P.current=null)},[]),q=ve.useCallback(G=>{if(!c)return!1;const Z=Md(C,v);if(Z){const{node:X,prevNode:ee,offset:ne}=Z,ce=Dl(X)?X:Dl(ee)&&ne===0?ee:null;if(ce){const ae=ce.getTrigger();return ce.replace(Xn(ae)),G.preventDefault(),!0}}return!1},[c,C,v]),$=ve.useCallback((G=!1)=>{if(!e)return;const Z=Md(C,v);if(!Z)return;const{node:X,offset:ee,type:ne,parentNode:ce,isTextNode:ae,textContent:de,prevNode:xe,nextNode:se,wordCharAfterCursor:ue,cursorAtStartOfNode:Pe,cursorAtEndOfNode:Be}=Z;if(ae&&Pe&&Dl(xe)){X.insertBefore(Xn(" "));return}if(Dl(X)&&xe===null&&Zi(ce)&&ne==="element"&&ee===0){const Ce=Xn(" ");X.insertBefore(Ce),Ce.selectStart();return}if(ae&&Be&&Dl(se)){X.insertAfter(Xn(" "));return}if(ae&&G&&ue){const Ce=de.substring(0,ee)+" "+de.substring(ee);X.setTextContent(Ce);return}Dl(X)&&se===null&&X.insertAfter(Xn(" "))},[v,C,e]),z=ve.useCallback(G=>{var Z;const{key:X,metaKey:ee,ctrlKey:ne}=G,ce=X.length===1,ae=wy(X,C,v),de=r&&/^\s$/.test(X);if(!ce||ee||ne)return!1;let xe=X;const se=Md(C,v);if(se!=null&&se.isTextNode){const{textContent:Pe,offset:Be}=se;xe=(((Z=Pe.substring(0,Be).split(/\s+/).at(-1))!==null&&Z!==void 0?Z:"")+X).trim()}const ue=C.some(Pe=>xe===Pe);return!ae&&!ue&&!de?K():($(ue),!1)},[$,v,K,C,r]),Y=ve.useCallback(G=>{var Z;const X=(Z=G.clipboardData)===null||Z===void 0?void 0:Z.getData("text/plain"),ee=X==null?void 0:X.charAt(0),ne=C.some(ae=>ee===ae),ce=ee&&new RegExp(`[\\s${v}]`).test(ee);return(ne||!ce)&&$(),!1},[$,C,v]);return ve.useEffect(()=>{if(!x.hasNodes([Rl]))throw new Error("BeautifulMentionsPlugin: BeautifulMentionNode not registered on editor");return Br(x.registerCommand(ti,()=>{const G=Ot();return G&&!pr(G)?P.current=G:G||(P.current=null),!1},In),x.registerCommand(hg,z,In),x.registerCommand(Vi,q,In),x.registerCommand(Ef,()=>n?K():!1,In),x.registerCommand(cb,()=>!r&&k?K():!1,In),x.registerCommand(II,({trigger:G,value:Z,data:X,focus:ee=!0})=>{F();const ne=LI(C,v,G,Z,X,e);return ee||nr(null),ne},In),x.registerCommand(MI,({trigger:G,value:Z,focus:X})=>{const ee=BI(G,Z,X);return X||(P.current=null),ee},In),x.registerCommand(RI,({trigger:G,newValue:Z,value:X,focus:ee})=>FI(G,Z,X,ee),In),x.registerCommand(DI,({trigger:G})=>(F(),xw(C,v,G,e)),In),x.registerCommand(va,Y,In))},[x,C,v,e,r,n,k,S,K,z,q,Y,F]),ve.useEffect(()=>{R&&S?h==null||h():g==null||g(),R&&!S&&J()},[h,g,R,S,J]),Xc?u.combobox?ke.jsx(qI,{options:L,loading:B,onQueryChange:w,onSelectOption:T,onReset:()=>{I(null)},triggerFn:W,triggers:C,punctuation:v,creatable:k,comboboxOpen:u.comboboxOpen,comboboxAnchor:u.comboboxAnchor,comboboxAnchorClassName:u.comboboxAnchorClassName,comboboxComponent:u.comboboxComponent,comboboxItemComponent:u.comboboxItemComponent,comboboxAdditionalItems:u.comboboxAdditionalItems,onComboboxOpen:u.onComboboxOpen,onComboboxClose:u.onComboboxClose,onComboboxFocusChange:u.onComboboxFocusChange,onComboboxItemSelect:u.onComboboxItemSelect}):ke.jsx(mI,{commandPriority:pd,onQueryChange:w,onSelectOption:H,triggerFn:W,options:L,anchorClassName:d,onClose:J,menuRenderFn:(G,{selectedIndex:Z,selectOptionAndCleanUp:X,setHighlightedIndex:ee})=>(D.current=Z,G.current&&L.length===0&&N&&!B&&S&&s?yf.createPortal(ke.jsx(s,{}),G.current):G.current&&R?yf.createPortal(ke.jsx(i,{loading:B,role:"menu","aria-label":"Choose a mention","aria-hidden":!R,"aria-activedescendant":!Pd&&Z!==null&&L[Z]?L[Z].displayValue:"",children:L.map((ne,ce)=>ke.jsx(l,Object.assign({tabIndex:-1,selected:!Pd&&Z===ce,ref:ne.setRefElement,role:"menuitem","aria-selected":!Pd&&Z===ce,"aria-label":`Choose ${ne.value}`,item:ne.menuItem,itemValue:ne.value,label:ne.displayValue},ne.data,{onClick:()=>{ee(ce),X(ne)},onMouseDown:ae=>{ae.preventDefault()},onMouseEnter:()=>{ee(ce)},children:ne.displayValue}),ne.key))}),G.current):null)}):null}const ZI=({loading:u,...t})=>u?ke.jsx("ul",{id:"mention-container",className:"mentionsContainer",...t,children:ke.jsx("li",{className:"mentionsContainerItem",children:"Loading..."})}):ke.jsx("ul",{id:"mention-container",className:"mentionsContainer",...t}),QI=ve.forwardRef(({selected:u,item:t,children:o,...e},a)=>{var r,n,i;return ke.jsx("li",{className:`mentionsContainerItem ${u&&"selected"}`,...e,ref:a,"data-id":(r=t==null?void 0:t.data)==null?void 0:r.id,"data-list-name":(n=t==null?void 0:t.data)==null?void 0:n.listName,"data-value":(i=t==null?void 0:t.data)==null?void 0:i.value,children:t.value})});let Rd=[];function XI({nodeKey:u}){const[t]=Gn(),[o,e,a]=oh(u),[r,n]=ur.useState(Rd),i=ve.useCallback(l=>{const s=Ot();return pr(s)&&t.update(()=>{s.getNodes().forEach(d=>{if(tM(d)){d.remove();const c=[...r];c.pop(),n(c),Rd=c}})}),!1},[t,o]);return ve.useEffect(()=>Br(t.registerCommand(ma,l=>{const s=t.getElementByKey(u);return l.target===s?(l.shiftKey&&a(),e(!o),!0):!1},In),t.registerCommand(zs,i,In),t.registerCommand(Vi,i,In)),[a,t,o,u,i,e]),ve.useEffect(()=>{const l=t.getElementByKey(u);l!==null&&(l.className="")},[t,o,u]),null}class Dd extends yc{static getType(){return"page-break"}static clone(t){return new Dd(t.__key)}static importJSON(t){return Ew()}static importDOM(){return{figure:t=>t.getAttribute("type")!==this.getType()?null:{conversion:eM,priority:vi}}}exportJSON(){return{type:this.getType(),version:1}}createDOM(){const t=document.createElement("figure");return t.style.pageBreakAfter="always",t.setAttribute("type",this.getType()),Rd.push(Rd.length+1),t.textContent=String(Rd.length),t}getTextContent(){return`
1515
1515
  `}isInline(){return!1}updateDOM(){return!1}decorate(){return ke.jsx(XI,{nodeKey:this.__key})}}function eM(){return{node:Ew()}}function Ew(){return new Dd}function tM(u){return u instanceof Dd}function nM({editorRef:u}){const[t]=Gn();return ur.useEffect(()=>{typeof u=="function"?u(t):typeof u=="object"&&(u.current=t)},[t]),null}const kw=pm?ve.useLayoutEffect:ve.useEffect,rM="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxNiIgaGVpZ2h0PSIxNiIgZmlsbD0iY3VycmVudENvbG9yIiBjbGFzcz0iYmkgYmktY2hhdC1yaWdodC10ZXh0Ij48cGF0aCBkPSJNMiAxYTEgMSAwIDAgMC0xIDF2OGExIDEgMCAwIDAgMSAxaDkuNTg2YTIgMiAwIDAgMSAxLjQxNC41ODZsMiAyVjJhMSAxIDAgMCAwLTEtMUgyem0xMi0xYTIgMiAwIDAgMSAyIDJ2MTIuNzkzYS41LjUgMCAwIDEtLjg1NC4zNTNsLTIuODUzLTIuODUzYTEgMSAwIDAgMC0uNzA3LS4yOTNIMmEyIDIgMCAwIDEtMi0yVjJhMiAyIDAgMCAxIDItMmgxMnoiLz48cGF0aCBkPSJNMyAzLjVhLjUuNSAwIDAgMSAuNS0uNWg5YS41LjUgMCAwIDEgMCAxaC05YS41LjUgMCAwIDEtLjUtLjV6TTMgNmEuNS41IDAgMCAxIC41LS41aDlhLjUuNSAwIDAgMSAwIDFoLTlBLjUuNSAwIDAgMSAzIDZ6bTAgMi41YS41LjUgMCAwIDEgLjUtLjVoNWEuNS41IDAgMCAxIDAgMWgtNWEuNS41IDAgMCAxLS41LS41eiIvPjwvc3ZnPg==",oM="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IiB3aWR0aD0iMTIyLjg4MXB4IiBoZWlnaHQ9Ijg5Ljg0MnB4IiB2aWV3Qm94PSIwIDAgMTIyLjg4MSA4OS44NDIiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDEyMi44ODEgODkuODQyIiB4bWw6c3BhY2U9InByZXNlcnZlIj48Zz48cGF0aCBkPSJNMS4yMzIsNTUuNTQxYy0xLjUzMy0xLjM4OC0xLjY1Mi0zLjc1Ni0wLjI2NS01LjI4OWMxLjM4OC0xLjUzNCwzLjc1Ni0xLjY1Miw1LjI5LTAuMjY1bDM0LjA1MywzMC44NzhsNzYuMDk5LTc5LjY5OSBjMS40MjktMS41MDEsMy44MDQtMS41NjEsNS4zMDUtMC4xMzJjMS41MDIsMS40MjgsMS41NjEsMy44MDMsMC4xMzMsNS4zMDVMNDMuMjIzLDg4LjY4M2wtMC4wMDUtMC4wMDUgYy0xLjM5NiwxLjQ2OC0zLjcxNiwxLjU2My01LjIyNywwLjE5NkwxLjIzMiw1NS41NDFMMS4yMzIsNTUuNTQxeiIvPjwvZz48L3N2Zz4=",Cs=()=>new Map,Ty=u=>{const t=Cs();return u.forEach((o,e)=>{t.set(e,o)}),t},eu=(u,t,o)=>{let e=u.get(t);return e===void 0&&u.set(t,e=o()),e},iM=(u,t)=>{const o=[];for(const[e,a]of u)o.push(t(a,e));return o},sM=(u,t)=>{for(const[o,e]of u)if(t(e,o))return!0;return!1},tu=()=>new Set,Ay=u=>u[u.length-1],nu=Array.from,aM=Array.isArray;class lM{constructor(){this._observers=Cs()}on(t,o){return eu(this._observers,t,tu).add(o),o}once(t,o){const e=(...a)=>{this.off(t,e),o(...a)};this.on(t,e)}off(t,o){const e=this._observers.get(t);e!==void 0&&(e.delete(o),e.size===0&&this._observers.delete(t))}emit(t,o){return nu((this._observers.get(t)||Cs()).values()).forEach(e=>e(...o))}destroy(){this._observers=Cs()}}const Ll=Math.floor,uh=Math.abs,Ow=(u,t)=>u<t?u:t,ru=(u,t)=>u>t?u:t,cM=u=>u!==0?u<0:1/u<0,Tw=1,Aw=2,Ny=4,jy=8,uM=32,Nw=64,dh=128,dM=31,jw=63,Ld=127,fM=2147483647,pM=Number.isInteger||(u=>typeof u=="number"&&isFinite(u)&&Ll(u)===u),hM=u=>u.toLowerCase(),gM=/^\s*/g,mM=u=>u.replace(gM,""),yM=/([A-Z])/g,Pw=(u,t)=>mM(u.replace(yM,o=>`${t}${hM(o)}`)),bM=u=>{const t=unescape(encodeURIComponent(u)),o=t.length,e=new Uint8Array(o);for(let a=0;a<o;a++)e[a]=t.codePointAt(a);return e},Bd=typeof TextEncoder<"u"?new TextEncoder:null,vM=Bd?u=>Bd.encode(u):bM;let Py=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});Py&&Py.decode(new Uint8Array).length===1&&(Py=null);class Fd{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}}const Iy=()=>new Fd,_M=u=>{let t=u.cpos;for(let o=0;o<u.bufs.length;o++)t+=u.bufs[o].length;return t},na=u=>{const t=new Uint8Array(_M(u));let o=0;for(let e=0;e<u.bufs.length;e++){const a=u.bufs[e];t.set(a,o),o+=a.length}return t.set(new Uint8Array(u.cbuf.buffer,0,u.cpos),o),t},xM=(u,t)=>{const o=u.cbuf.length;o-u.cpos<t&&(u.bufs.push(new Uint8Array(u.cbuf.buffer,0,u.cpos)),u.cbuf=new Uint8Array(ru(o,t)*2),u.cpos=0)},vo=(u,t)=>{const o=u.cbuf.length;u.cpos===o&&(u.bufs.push(u.cbuf),u.cbuf=new Uint8Array(o*2),u.cpos=0),u.cbuf[u.cpos++]=t},My=vo,Ar=(u,t)=>{for(;t>Ld;)vo(u,dh|Ld&t),t=Ll(t/128);vo(u,Ld&t)},Ry=(u,t)=>{const o=cM(t);for(o&&(t=-t),vo(u,(t>jw?dh:0)|(o?Nw:0)|jw&t),t=Ll(t/64);t>0;)vo(u,(t>Ld?dh:0)|Ld&t),t=Ll(t/128)},Dy=new Uint8Array(3e4),wM=Dy.length/3,SM=(u,t)=>{if(t.length<wM){const o=Bd.encodeInto(t,Dy).written||0;Ar(u,o);for(let e=0;e<o;e++)vo(u,Dy[e])}else wi(u,vM(t))},CM=(u,t)=>{const o=unescape(encodeURIComponent(t)),e=o.length;Ar(u,e);for(let a=0;a<e;a++)vo(u,o.codePointAt(a))},ou=Bd&&Bd.encodeInto?SM:CM,Ly=(u,t)=>{const o=u.cbuf.length,e=u.cpos,a=Ow(o-e,t.length),r=t.length-a;u.cbuf.set(t.subarray(0,a),e),u.cpos+=a,r>0&&(u.bufs.push(u.cbuf),u.cbuf=new Uint8Array(ru(o*2,r)),u.cbuf.set(t.subarray(a)),u.cpos=r)},wi=(u,t)=>{Ar(u,t.byteLength),Ly(u,t)},By=(u,t)=>{xM(u,t);const o=new DataView(u.cbuf.buffer,u.cpos,t);return u.cpos+=t,o},EM=(u,t)=>By(u,4).setFloat32(0,t,!1),kM=(u,t)=>By(u,8).setFloat64(0,t,!1),OM=(u,t)=>By(u,8).setBigInt64(0,t,!1),Iw=new DataView(new ArrayBuffer(4)),TM=u=>(Iw.setFloat32(0,u),Iw.getFloat32(0)===u),zd=(u,t)=>{switch(typeof t){case"string":vo(u,119),ou(u,t);break;case"number":pM(t)&&uh(t)<=fM?(vo(u,125),Ry(u,t)):TM(t)?(vo(u,124),EM(u,t)):(vo(u,123),kM(u,t));break;case"bigint":vo(u,122),OM(u,t);break;case"object":if(t===null)vo(u,126);else if(aM(t)){vo(u,117),Ar(u,t.length);for(let o=0;o<t.length;o++)zd(u,t[o])}else if(t instanceof Uint8Array)vo(u,116),wi(u,t);else{vo(u,118);const o=Object.keys(t);Ar(u,o.length);for(let e=0;e<o.length;e++){const a=o[e];ou(u,a),zd(u,t[a])}}break;case"boolean":vo(u,t?120:121);break;default:vo(u,127)}};class Mw extends Fd{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&Ar(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}}const Rw=u=>{u.count>0&&(Ry(u.encoder,u.count===1?u.s:-u.s),u.count>1&&Ar(u.encoder,u.count-2))};class fh{constructor(){this.encoder=new Fd,this.s=0,this.count=0}write(t){this.s===t?this.count++:(Rw(this),this.count=1,this.s=t)}toUint8Array(){return Rw(this),na(this.encoder)}}const Dw=u=>{if(u.count>0){const t=u.diff*2+(u.count===1?0:1);Ry(u.encoder,t),u.count>1&&Ar(u.encoder,u.count-2)}};class Fy{constructor(){this.encoder=new Fd,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(Dw(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return Dw(this),na(this.encoder)}}class AM{constructor(){this.sarr=[],this.s="",this.lensE=new fh}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){const t=new Fd;return this.sarr.push(this.s),this.s="",ou(t,this.sarr.join("")),Ly(t,this.lensE.toUint8Array()),na(t)}}const iu=u=>new Error(u),Es=()=>{throw iu("Method unimplemented")},Bl=()=>{throw iu("Unexpected case")},NM=crypto.getRandomValues.bind(crypto),Lw=()=>NM(new Uint32Array(1))[0],jM=[1e7]+-1e3+-4e3+-8e3+-1e11,PM=()=>jM.replace(/[018]/g,u=>(u^Lw()&15>>u/4).toString(16)),Bw=u=>new Promise(u);Promise.all.bind(Promise);const Fw=u=>u===void 0?null:u;class IM{constructor(){this.map=new Map}setItem(t,o){this.map.set(t,o)}getItem(t){return this.map.get(t)}}let zw=new IM,MM=!0;try{typeof localStorage<"u"&&localStorage&&(zw=localStorage,MM=!1)}catch{}const RM=zw,DM=Object.assign,LM=Object.keys,BM=(u,t)=>{for(const o in u)t(u[o],o)},Uw=u=>LM(u).length,FM=u=>{for(const t in u)return!1;return!0},zM=(u,t)=>{for(const o in u)if(!t(u[o],o))return!1;return!0},UM=(u,t)=>Object.prototype.hasOwnProperty.call(u,t),HM=(u,t)=>u===t||Uw(u)===Uw(t)&&zM(u,(o,e)=>(o!==void 0||UM(t,e))&&t[e]===o),$M=Object.freeze,Hw=u=>{for(const t in u){const o=u[t];(typeof o=="object"||typeof o=="function")&&Hw(u[t])}return $M(u)},zy=(u,t,o=0)=>{try{for(;o<u.length;o++)u[o](...t)}finally{o<u.length&&zy(u,t,o+1)}},qM=(u,t)=>t.includes(u),Ud=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<"u"?process:0)==="[object process]";let ks;const WM=()=>{if(ks===void 0)if(Ud){ks=Cs();const u=process.argv;let t=null;for(let o=0;o<u.length;o++){const e=u[o];e[0]==="-"?(t!==null&&ks.set(t,""),t=e):t!==null&&(ks.set(t,e),t=null)}t!==null&&ks.set(t,"")}else typeof location=="object"?(ks=Cs(),(location.search||"?").slice(1).split("&").forEach(u=>{if(u.length!==0){const[t,o]=u.split("=");ks.set(`--${Pw(t,"-")}`,o),ks.set(`-${Pw(t,"-")}`,o)}})):ks=Cs();return ks},Uy=u=>WM().has(u),ph=u=>Fw(Ud?process.env[u.toUpperCase().replaceAll("-","_")]:RM.getItem(u)),$w=u=>Uy("--"+u)||ph(u)!==null;$w("production");const VM=Ud&&qM(process.env.FORCE_COLOR,["true","1","2"])||!Uy("--no-colors")&&!$w("no-color")&&(!Ud||process.stdout.isTTY)&&(!Ud||Uy("--color")||ph("COLORTERM")!==null||(ph("TERM")||"").includes("color"));class JM{constructor(t,o){this.left=t,this.right=o}}const ra=(u,t)=>new JM(u,t);typeof DOMParser<"u"&&new DOMParser;const KM=u=>iM(u,(t,o)=>`${o}:${t};`).join(""),oa=Symbol,qw=oa(),Ww=oa(),GM=oa(),YM=oa(),ZM=oa(),Vw=oa(),QM=oa(),Hy=oa(),XM=oa(),eR=u=>{var a;u.length===1&&((a=u[0])==null?void 0:a.constructor)===Function&&(u=u[0]());const t=[],o=[];let e=0;for(;e<u.length;e++){const r=u[e];if(r===void 0)break;if(r.constructor===String||r.constructor===Number)t.push(r);else if(r.constructor===Object)break}for(e>0&&o.push(t.join(""));e<u.length;e++){const r=u[e];r instanceof Symbol||o.push(r)}return o},tR={[qw]:ra("font-weight","bold"),[Ww]:ra("font-weight","normal"),[GM]:ra("color","blue"),[ZM]:ra("color","green"),[YM]:ra("color","grey"),[Vw]:ra("color","red"),[QM]:ra("color","purple"),[Hy]:ra("color","orange"),[XM]:ra("color","black")},Jw=VM?u=>{var n;u.length===1&&((n=u[0])==null?void 0:n.constructor)===Function&&(u=u[0]());const t=[],o=[],e=Cs();let a=[],r=0;for(;r<u.length;r++){const i=u[r],l=tR[i];if(l!==void 0)e.set(l.left,l.right);else{if(i===void 0)break;if(i.constructor===String||i.constructor===Number){const s=KM(e);r>0||s.length>0?(t.push("%c"+i),o.push(s)):t.push(i)}else break}}for(r>0&&(a=o,a.unshift(t.join("")));r<u.length;r++){const i=u[r];i instanceof Symbol||a.push(i)}return a}:eR,nR=(...u)=>{console.log(...Jw(u)),Kw.forEach(t=>t.print(u))},rR=(...u)=>{console.warn(...Jw(u)),u.unshift(Hy),Kw.forEach(t=>t.print(u))},Kw=tu(),Gw=u=>({[Symbol.iterator](){return this},next:u}),oR=(u,t)=>Gw(()=>{let o;do o=u.next();while(!o.done&&!t(o.value));return o}),$y=(u,t)=>Gw(()=>{const{done:o,value:e}=u.next();return{done:o,value:o?void 0:t(e)}});class iR{constructor(t,o){this.clock=t,this.len=o}}class sR{constructor(){this.clients=new Map}}const Yw=(u,t,o)=>t.clients.forEach((e,a)=>{const r=u.doc.store.clients.get(a);for(let n=0;n<e.length;n++){const i=e[n];aS(u,r,i.clock,i.len,o)}}),aR=(u,t)=>{let o=0,e=u.length-1;for(;o<=e;){const a=Ll((o+e)/2),r=u[a],n=r.clock;if(n<=t){if(t<n+r.len)return a;o=a+1}else e=a-1}return null},Zw=(u,t)=>{const o=u.clients.get(t.client);return o!==void 0&&aR(o,t.clock)!==null},Qw=u=>{u.clients.forEach(t=>{t.sort((a,r)=>a.clock-r.clock);let o,e;for(o=1,e=1;o<t.length;o++){const a=t[e-1],r=t[o];a.clock+a.len>=r.clock?a.len=ru(a.len,r.clock+r.len-a.clock):(e<o&&(t[e]=r),e++)}t.length=e})},Xw=(u,t,o,e)=>{eu(u.clients,t,()=>[]).push(new iR(o,e))},lR=(u,t)=>{Ar(u.restEncoder,t.clients.size),nu(t.clients.entries()).sort((o,e)=>e[0]-o[0]).forEach(([o,e])=>{u.resetDsCurVal(),Ar(u.restEncoder,o);const a=e.length;Ar(u.restEncoder,a);for(let r=0;r<a;r++){const n=e[r];u.writeDsClock(n.clock),u.writeDsLen(n.len)}})},eS=Lw;class Hd extends lM{constructor({guid:t=PM(),collectionid:o=null,gc:e=!0,gcFilter:a=()=>!0,meta:r=null,autoLoad:n=!1,shouldLoad:i=!0}={}){super(),this.gc=e,this.gcFilter=a,this.clientID=eS(),this.guid=t,this.collectionid=o,this.share=new Map,this.store=new bR,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=i,this.autoLoad=n,this.meta=r,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Bw(s=>{this.on("load",()=>{this.isLoaded=!0,s(this)})});const l=()=>Bw(s=>{const d=c=>{(c===void 0||c===!0)&&(this.off("sync",d),s())};this.on("sync",d)});this.on("sync",s=>{s===!1&&this.isSynced&&(this.whenSynced=l()),this.isSynced=s===void 0||s===!0,this.isSynced&&!this.isLoaded&&this.emit("load",[this])}),this.whenSynced=l()}load(){const t=this._item;t!==null&&!this.shouldLoad&&Lr(t.parent.doc,o=>{o.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(nu(this.subdocs).map(t=>t.guid))}transact(t,o=null){return Lr(this,t,o)}get(t,o=Oo){const e=eu(this.share,t,()=>{const r=new o;return r._integrate(this,null),r}),a=e.constructor;if(o!==Oo&&a!==o)if(a===Oo){const r=new o;r._map=e._map,e._map.forEach(n=>{for(;n!==null;n=n.left)n.parent=r}),r._start=e._start;for(let n=r._start;n!==null;n=n.right)n.parent=r;return r._length=e._length,this.share.set(t,r),r._integrate(this,null),r}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return e}getArray(t=""){return this.get(t,Fl)}getText(t=""){return this.get(t,Ch)}getMap(t=""){return this.get(t,au)}getXmlElement(t=""){return this.get(t,Wd)}getXmlFragment(t=""){return this.get(t,cu)}toJSON(){const t={};return this.share.forEach((o,e)=>{t[e]=o.toJSON()}),t}destroy(){this.isDestroyed=!0,nu(this.subdocs).forEach(o=>o.destroy());const t=this._item;if(t!==null){this._item=null;const o=t.content;o.doc=new Hd({guid:this.guid,...o.opts,shouldLoad:!1}),o.doc._item=t,Lr(t.parent.doc,e=>{const a=o.doc;t.deleted||e.subdocsAdded.add(a),e.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}}class cR{constructor(){this.restEncoder=Iy()}toUint8Array(){return na(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){Ar(this.restEncoder,t)}writeDsLen(t){Ar(this.restEncoder,t)}}class uR extends cR{writeLeftID(t){Ar(this.restEncoder,t.client),Ar(this.restEncoder,t.clock)}writeRightID(t){Ar(this.restEncoder,t.client),Ar(this.restEncoder,t.clock)}writeClient(t){Ar(this.restEncoder,t)}writeInfo(t){My(this.restEncoder,t)}writeString(t){ou(this.restEncoder,t)}writeParentInfo(t){Ar(this.restEncoder,t?1:0)}writeTypeRef(t){Ar(this.restEncoder,t)}writeLen(t){Ar(this.restEncoder,t)}writeAny(t){zd(this.restEncoder,t)}writeBuf(t){wi(this.restEncoder,t)}writeJSON(t){ou(this.restEncoder,JSON.stringify(t))}writeKey(t){ou(this.restEncoder,t)}}class dR{constructor(){this.restEncoder=Iy(),this.dsCurrVal=0}toUint8Array(){return na(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){const o=t-this.dsCurrVal;this.dsCurrVal=t,Ar(this.restEncoder,o)}writeDsLen(t){t===0&&Bl(),Ar(this.restEncoder,t-1),this.dsCurrVal+=t}}class fR extends dR{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Fy,this.clientEncoder=new fh,this.leftClockEncoder=new Fy,this.rightClockEncoder=new Fy,this.infoEncoder=new Mw(My),this.stringEncoder=new AM,this.parentInfoEncoder=new Mw(My),this.typeRefEncoder=new fh,this.lenEncoder=new fh}toUint8Array(){const t=Iy();return Ar(t,0),wi(t,this.keyClockEncoder.toUint8Array()),wi(t,this.clientEncoder.toUint8Array()),wi(t,this.leftClockEncoder.toUint8Array()),wi(t,this.rightClockEncoder.toUint8Array()),wi(t,na(this.infoEncoder)),wi(t,this.stringEncoder.toUint8Array()),wi(t,na(this.parentInfoEncoder)),wi(t,this.typeRefEncoder.toUint8Array()),wi(t,this.lenEncoder.toUint8Array()),Ly(t,na(this.restEncoder)),na(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){zd(this.restEncoder,t)}writeBuf(t){wi(this.restEncoder,t)}writeJSON(t){zd(this.restEncoder,t)}writeKey(t){const o=this.keyMap.get(t);o===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(o)}}const pR=(u,t,o,e)=>{e=ru(e,t[0].id.clock);const a=ia(t,e);Ar(u.restEncoder,t.length-a),u.writeClient(o),Ar(u.restEncoder,e);const r=t[a];r.write(u,e-r.id.clock);for(let n=a+1;n<t.length;n++)t[n].write(u,0)},hR=(u,t,o)=>{const e=new Map;o.forEach((a,r)=>{ai(t,r)>a&&e.set(r,a)}),Wy(t).forEach((a,r)=>{o.has(r)||e.set(r,0)}),Ar(u.restEncoder,e.size),nu(e.entries()).sort((a,r)=>r[0]-a[0]).forEach(([a,r])=>{pR(u,t.clients.get(a),a,r)})},gR=(u,t)=>hR(u,t.doc.store,t.beforeState);class mR{constructor(){this.l=[]}}const tS=()=>new mR,nS=(u,t)=>u.l.push(t),rS=(u,t)=>{const o=u.l,e=o.length;u.l=o.filter(a=>t!==a),e===u.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},oS=(u,t,o)=>zy(u.l,[t,o]);class hh{constructor(t,o){this.client=t,this.clock=o}}const gh=(u,t)=>u===t||u!==null&&t!==null&&u.client===t.client&&u.clock===t.clock,Yr=(u,t)=>new hh(u,t),yR=u=>{for(const[t,o]of u.doc.share.entries())if(o===u)return t;throw Bl()},su=(u,t)=>t===void 0?!u.deleted:t.sv.has(u.id.client)&&(t.sv.get(u.id.client)||0)>u.id.clock&&!Zw(t.ds,u.id),qy=(u,t)=>{const o=eu(u.meta,qy,tu),e=u.doc.store;o.has(t)||(t.sv.forEach((a,r)=>{a<ai(e,r)&&za(u,Yr(r,a))}),Yw(u,t.ds,a=>{}),o.add(t))};class bR{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}}const Wy=u=>{const t=new Map;return u.clients.forEach((o,e)=>{const a=o[o.length-1];t.set(e,a.id.clock+a.length)}),t},ai=(u,t)=>{const o=u.clients.get(t);if(o===void 0)return 0;const e=o[o.length-1];return e.id.clock+e.length},iS=(u,t)=>{let o=u.clients.get(t.id.client);if(o===void 0)o=[],u.clients.set(t.id.client,o);else{const e=o[o.length-1];if(e.id.clock+e.length!==t.id.clock)throw Bl()}o.push(t)},ia=(u,t)=>{let o=0,e=u.length-1,a=u[e],r=a.id.clock;if(r===t)return e;let n=Ll(t/(r+a.length-1)*e);for(;o<=e;){if(a=u[n],r=a.id.clock,r<=t){if(t<r+a.length)return n;o=n+1}else e=n-1;n=Ll((o+e)/2)}throw Bl()},Vy=(u,t)=>{const o=u.clients.get(t.client);return o[ia(o,t.clock)]},Jy=(u,t,o)=>{const e=ia(t,o),a=t[e];return a.id.clock<o&&a instanceof Ro?(t.splice(e+1,0,PS(u,a,o-a.id.clock)),e+1):e},za=(u,t)=>{const o=u.doc.store.clients.get(t.client);return o[Jy(u,o,t.clock)]},sS=(u,t,o)=>{const e=t.clients.get(o.client),a=ia(e,o.clock),r=e[a];return o.clock!==r.id.clock+r.length-1&&r.constructor!==Ha&&e.splice(a+1,0,PS(u,r,o.clock-r.id.clock+1)),r},vR=(u,t,o)=>{const e=u.clients.get(t.id.client);e[ia(e,t.id.clock)]=o},aS=(u,t,o,e,a)=>{if(e===0)return;const r=o+e;let n=Jy(u,t,o),i;do i=t[n++],r<i.id.clock+i.length&&Jy(u,t,r),a(i);while(n<t.length&&t[n].id.clock<r)};class _R{constructor(t,o,e){this.doc=t,this.deleteSet=new sR,this.beforeState=Wy(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=o,this.meta=new Map,this.local=e,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}}const lS=(u,t)=>t.deleteSet.clients.size===0&&!sM(t.afterState,(o,e)=>t.beforeState.get(e)!==o)?!1:(Qw(t.deleteSet),gR(u,t),lR(u,t.deleteSet),!0),cS=(u,t,o)=>{const e=t._item;(e===null||e.id.clock<(u.beforeState.get(e.id.client)||0)&&!e.deleted)&&eu(u.changed,t,tu).add(o)},mh=(u,t)=>{let o=u[t],e=u[t-1],a=t;for(;a>0;o=e,e=u[--a-1]){if(e.deleted===o.deleted&&e.constructor===o.constructor&&e.mergeWith(o)){o instanceof Ro&&o.parentSub!==null&&o.parent._map.get(o.parentSub)===o&&o.parent._map.set(o.parentSub,e);continue}break}const r=t-a;return r&&u.splice(t+1-r,r),r},xR=(u,t,o)=>{for(const[e,a]of u.clients.entries()){const r=t.clients.get(e);for(let n=a.length-1;n>=0;n--){const i=a[n],l=i.clock+i.len;for(let s=ia(r,i.clock),d=r[s];s<r.length&&d.id.clock<l;d=r[++s]){const c=r[s];if(i.clock+i.len<=c.id.clock)break;c instanceof Ro&&c.deleted&&!c.keep&&o(c)&&c.gc(t,!1)}}}},wR=(u,t)=>{u.clients.forEach((o,e)=>{const a=t.clients.get(e);for(let r=o.length-1;r>=0;r--){const n=o[r],i=Ow(a.length-1,1+ia(a,n.clock+n.len-1));for(let l=i,s=a[l];l>0&&s.id.clock>=n.clock;s=a[l])l-=1+mh(a,l)}})},uS=(u,t)=>{if(t<u.length){const o=u[t],e=o.doc,a=e.store,r=o.deleteSet,n=o._mergeStructs;try{Qw(r),o.afterState=Wy(o.doc.store),e.emit("beforeObserverCalls",[o,e]);const i=[];o.changed.forEach((l,s)=>i.push(()=>{(s._item===null||!s._item.deleted)&&s._callObserver(o,l)})),i.push(()=>{o.changedParentTypes.forEach((l,s)=>{s._dEH.l.length>0&&(s._item===null||!s._item.deleted)&&(l=l.filter(d=>d.target._item===null||!d.target._item.deleted),l.forEach(d=>{d.currentTarget=s,d._path=null}),l.sort((d,c)=>d.path.length-c.path.length),oS(s._dEH,l,o))})}),i.push(()=>e.emit("afterTransaction",[o,e])),zy(i,[]),o._needFormattingCleanup&&IR(o)}finally{e.gc&&xR(r,a,e.gcFilter),wR(r,a),o.afterState.forEach((d,c)=>{const p=o.beforeState.get(c)||0;if(p!==d){const f=a.clients.get(c),h=ru(ia(f,p),1);for(let g=f.length-1;g>=h;)g-=1+mh(f,g)}});for(let d=n.length-1;d>=0;d--){const{client:c,clock:p}=n[d].id,f=a.clients.get(c),h=ia(f,p);h+1<f.length&&mh(f,h+1)>1||h>0&&mh(f,h)}if(!o.local&&o.afterState.get(e.clientID)!==o.beforeState.get(e.clientID)&&(nR(Hy,qw,"[yjs] ",Ww,Vw,"Changed the client-id because another client seems to be using it."),e.clientID=eS()),e.emit("afterTransactionCleanup",[o,e]),e._observers.has("update")){const d=new uR;lS(d,o)&&e.emit("update",[d.toUint8Array(),o.origin,e,o])}if(e._observers.has("updateV2")){const d=new fR;lS(d,o)&&e.emit("updateV2",[d.toUint8Array(),o.origin,e,o])}const{subdocsAdded:i,subdocsLoaded:l,subdocsRemoved:s}=o;(i.size>0||s.size>0||l.size>0)&&(i.forEach(d=>{d.clientID=e.clientID,d.collectionid==null&&(d.collectionid=e.collectionid),e.subdocs.add(d)}),s.forEach(d=>e.subdocs.delete(d)),e.emit("subdocs",[{loaded:l,added:i,removed:s},e,o]),s.forEach(d=>d.destroy())),u.length<=t+1?(e._transactionCleanups=[],e.emit("afterAllTransactions",[e,u])):uS(u,t+1)}}},Lr=(u,t,o=null,e=!0)=>{const a=u._transactionCleanups;let r=!1,n=null;u._transaction===null&&(r=!0,u._transaction=new _R(u,o,e),a.push(u._transaction),a.length===1&&u.emit("beforeAllTransactions",[u]),u.emit("beforeTransaction",[u._transaction,u]));try{n=t(u._transaction)}finally{if(r){const i=u._transaction===a[0];u._transaction=null,i&&uS(a,0)}}return n},dS="You must not compute changes after the event-handler fired.";class yh{constructor(t,o){this.target=t,this.currentTarget=t,this.transaction=o,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||(this._path=SR(this.currentTarget,this.target))}deletes(t){return Zw(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw iu(dS);const t=new Map,o=this.target;this.transaction.changed.get(o).forEach(a=>{if(a!==null){const r=o._map.get(a);let n,i;if(this.adds(r)){let l=r.left;for(;l!==null&&this.adds(l);)l=l.left;if(this.deletes(r))if(l!==null&&this.deletes(l))n="delete",i=Ay(l.content.getContent());else return;else l!==null&&this.deletes(l)?(n="update",i=Ay(l.content.getContent())):(n="add",i=void 0)}else if(this.deletes(r))n="delete",i=Ay(r.content.getContent());else return;t.set(a,{action:n,oldValue:i})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){if(this.transaction.doc._transactionCleanups.length===0)throw iu(dS);const o=this.target,e=tu(),a=tu(),r=[];if(t={added:e,deleted:a,delta:r,keys:this.keys},this.transaction.changed.get(o).has(null)){let i=null;const l=()=>{i&&r.push(i)};for(let s=o._start;s!==null;s=s.right)s.deleted?this.deletes(s)&&!this.adds(s)&&((i===null||i.delete===void 0)&&(l(),i={delete:0}),i.delete+=s.length,a.add(s)):this.adds(s)?((i===null||i.insert===void 0)&&(l(),i={insert:[]}),i.insert=i.insert.concat(s.content.getContent()),e.add(s)):((i===null||i.retain===void 0)&&(l(),i={retain:0}),i.retain+=s.length);i!==null&&i.retain===void 0&&l()}this._changes=t}return t}}const SR=(u,t)=>{const o=[];for(;t._item!==null&&t!==u;){if(t._item.parentSub!==null)o.unshift(t._item.parentSub);else{let e=0,a=t._item.parent._start;for(;a!==t._item&&a!==null;)!a.deleted&&a.countable&&(e+=a.length),a=a.right;o.unshift(e)}t=t._item.parent}return o},Mo=()=>{rR("Invalid access: Add Yjs type to a document before reading data.")},fS=80;let Ky=0;class CR{constructor(t,o){t.marker=!0,this.p=t,this.index=o,this.timestamp=Ky++}}const ER=u=>{u.timestamp=Ky++},pS=(u,t,o)=>{u.p.marker=!1,u.p=t,t.marker=!0,u.index=o,u.timestamp=Ky++},kR=(u,t,o)=>{if(u.length>=fS){const e=u.reduce((a,r)=>a.timestamp<r.timestamp?a:r);return pS(e,t,o),e}else{const e=new CR(t,o);return u.push(e),e}},bh=(u,t)=>{if(u._start===null||t===0||u._searchMarker===null)return null;const o=u._searchMarker.length===0?null:u._searchMarker.reduce((r,n)=>uh(t-r.index)<uh(t-n.index)?r:n);let e=u._start,a=0;for(o!==null&&(e=o.p,a=o.index,ER(o));e.right!==null&&a<t;){if(!e.deleted&&e.countable){if(t<a+e.length)break;a+=e.length}e=e.right}for(;e.left!==null&&a>t;)e=e.left,!e.deleted&&e.countable&&(a-=e.length);for(;e.left!==null&&e.left.id.client===e.id.client&&e.left.id.clock+e.left.length===e.id.clock;)e=e.left,!e.deleted&&e.countable&&(a-=e.length);return o!==null&&uh(o.index-a)<e.parent.length/fS?(pS(o,e,a),o):kR(u._searchMarker,e,a)},$d=(u,t,o)=>{for(let e=u.length-1;e>=0;e--){const a=u[e];if(o>0){let r=a.p;for(r.marker=!1;r&&(r.deleted||!r.countable);)r=r.left,r&&!r.deleted&&r.countable&&(a.index-=r.length);if(r===null||r.marker===!0){u.splice(e,1);continue}a.p=r,r.marker=!0}(t<a.index||o>0&&t===a.index)&&(a.index=ru(t,a.index+o))}},vh=(u,t,o)=>{const e=u,a=t.changedParentTypes;for(;eu(a,u,()=>[]).push(o),u._item!==null;)u=u._item.parent;oS(e._eH,o,t)};class Oo{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=tS(),this._dEH=tS(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,o){this.doc=t,this._item=o}_copy(){throw Es()}clone(){throw Es()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,o){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){nS(this._eH,t)}observeDeep(t){nS(this._dEH,t)}unobserve(t){rS(this._eH,t)}unobserveDeep(t){rS(this._dEH,t)}toJSON(){}}const hS=(u,t,o)=>{u.doc??Mo(),t<0&&(t=u._length+t),o<0&&(o=u._length+o);let e=o-t;const a=[];let r=u._start;for(;r!==null&&e>0;){if(r.countable&&!r.deleted){const n=r.content.getContent();if(n.length<=t)t-=n.length;else{for(let i=t;i<n.length&&e>0;i++)a.push(n[i]),e--;t=0}}r=r.right}return a},gS=u=>{u.doc??Mo();const t=[];let o=u._start;for(;o!==null;){if(o.countable&&!o.deleted){const e=o.content.getContent();for(let a=0;a<e.length;a++)t.push(e[a])}o=o.right}return t},qd=(u,t)=>{let o=0,e=u._start;for(u.doc??Mo();e!==null;){if(e.countable&&!e.deleted){const a=e.content.getContent();for(let r=0;r<a.length;r++)t(a[r],o++,u)}e=e.right}},mS=(u,t)=>{const o=[];return qd(u,(e,a)=>{o.push(t(e,a,u))}),o},OR=u=>{let t=u._start,o=null,e=0;return{[Symbol.iterator](){return this},next:()=>{if(o===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};o=t.content.getContent(),e=0,t=t.right}const a=o[e++];return o.length<=e&&(o=null),{done:!1,value:a}}}},yS=(u,t)=>{u.doc??Mo();const o=bh(u,t);let e=u._start;for(o!==null&&(e=o.p,t-=o.index);e!==null;e=e.right)if(!e.deleted&&e.countable){if(t<e.length)return e.content.getContent()[t];t-=e.length}},_h=(u,t,o,e)=>{let a=o;const r=u.doc,n=r.clientID,i=r.store,l=o===null?t._start:o.right;let s=[];const d=()=>{s.length>0&&(a=new Ro(Yr(n,ai(i,n)),a,a&&a.lastId,l,l&&l.id,t,null,new du(s)),a.integrate(u,0),s=[])};e.forEach(c=>{if(c===null)s.push(c);else switch(c.constructor){case Number:case Object:case Boolean:case Array:case String:s.push(c);break;default:switch(d(),c.constructor){case Uint8Array:case ArrayBuffer:a=new Ro(Yr(n,ai(i,n)),a,a&&a.lastId,l,l&&l.id,t,null,new Eh(new Uint8Array(c))),a.integrate(u,0);break;case Hd:a=new Ro(Yr(n,ai(i,n)),a,a&&a.lastId,l,l&&l.id,t,null,new Oh(c)),a.integrate(u,0);break;default:if(c instanceof Oo)a=new Ro(Yr(n,ai(i,n)),a,a&&a.lastId,l,l&&l.id,t,null,new $a(c)),a.integrate(u,0);else throw new Error("Unexpected content type in insert operation")}}}),d()},bS=()=>iu("Length exceeded!"),vS=(u,t,o,e)=>{if(o>t._length)throw bS();if(o===0)return t._searchMarker&&$d(t._searchMarker,o,e.length),_h(u,t,null,e);const a=o,r=bh(t,o);let n=t._start;for(r!==null&&(n=r.p,o-=r.index,o===0&&(n=n.prev,o+=n&&n.countable&&!n.deleted?n.length:0));n!==null;n=n.right)if(!n.deleted&&n.countable){if(o<=n.length){o<n.length&&za(u,Yr(n.id.client,n.id.clock+o));break}o-=n.length}return t._searchMarker&&$d(t._searchMarker,a,e.length),_h(u,t,n,e)},TR=(u,t,o)=>{let a=(t._searchMarker||[]).reduce((r,n)=>n.index>r.index?n:r,{index:0,p:t._start}).p;if(a)for(;a.right;)a=a.right;return _h(u,t,a,o)},_S=(u,t,o,e)=>{if(e===0)return;const a=o,r=e,n=bh(t,o);let i=t._start;for(n!==null&&(i=n.p,o-=n.index);i!==null&&o>0;i=i.right)!i.deleted&&i.countable&&(o<i.length&&za(u,Yr(i.id.client,i.id.clock+o)),o-=i.length);for(;e>0&&i!==null;)i.deleted||(e<i.length&&za(u,Yr(i.id.client,i.id.clock+e)),i.delete(u),e-=i.length),i=i.right;if(e>0)throw bS();t._searchMarker&&$d(t._searchMarker,a,-r+e)},xh=(u,t,o)=>{const e=t._map.get(o);e!==void 0&&e.delete(u)},Gy=(u,t,o,e)=>{const a=t._map.get(o)||null,r=u.doc,n=r.clientID;let i;if(e==null)i=new du([e]);else switch(e.constructor){case Number:case Object:case Boolean:case Array:case String:i=new du([e]);break;case Uint8Array:i=new Eh(e);break;case Hd:i=new Oh(e);break;default:if(e instanceof Oo)i=new $a(e);else throw new Error("Unexpected content type")}new Ro(Yr(n,ai(r.store,n)),a,a&&a.lastId,null,null,t,o,i).integrate(u,0)},Yy=(u,t)=>{u.doc??Mo();const o=u._map.get(t);return o!==void 0&&!o.deleted?o.content.getContent()[o.length-1]:void 0},xS=u=>{const t={};return u.doc??Mo(),u._map.forEach((o,e)=>{o.deleted||(t[e]=o.content.getContent()[o.length-1])}),t},wS=(u,t)=>{u.doc??Mo();const o=u._map.get(t);return o!==void 0&&!o.deleted},AR=(u,t)=>{const o={};return u._map.forEach((e,a)=>{let r=e;for(;r!==null&&(!t.sv.has(r.id.client)||r.id.clock>=(t.sv.get(r.id.client)||0));)r=r.left;r!==null&&su(r,t)&&(o[a]=r.content.getContent()[r.length-1])}),o},wh=u=>(u.doc??Mo(),oR(u._map.entries(),t=>!t[1].deleted));class SS extends yh{}class Fl extends Oo{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){const o=new Fl;return o.push(t),o}_integrate(t,o){super._integrate(t,o),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new Fl}clone(){const t=new Fl;return t.insert(0,this.toArray().map(o=>o instanceof Oo?o.clone():o)),t}get length(){return this.doc??Mo(),this._length}_callObserver(t,o){super._callObserver(t,o),vh(this,t,new SS(this,t))}insert(t,o){this.doc!==null?Lr(this.doc,e=>{vS(e,this,t,o)}):this._prelimContent.splice(t,0,...o)}push(t){this.doc!==null?Lr(this.doc,o=>{TR(o,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,o=1){this.doc!==null?Lr(this.doc,e=>{_S(e,this,t,o)}):this._prelimContent.splice(t,o)}get(t){return yS(this,t)}toArray(){return gS(this)}slice(t=0,o=this.length){return hS(this,t,o)}toJSON(){return this.map(t=>t instanceof Oo?t.toJSON():t)}map(t){return mS(this,t)}forEach(t){qd(this,t)}[Symbol.iterator](){return OR(this)}_write(t){t.writeTypeRef(FR)}}class NR extends yh{constructor(t,o,e){super(t,o),this.keysChanged=e}}class au extends Oo{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,o){super._integrate(t,o),this._prelimContent.forEach((e,a)=>{this.set(a,e)}),this._prelimContent=null}_copy(){return new au}clone(){const t=new au;return this.forEach((o,e)=>{t.set(e,o instanceof Oo?o.clone():o)}),t}_callObserver(t,o){vh(this,t,new NR(this,t,o))}toJSON(){this.doc??Mo();const t={};return this._map.forEach((o,e)=>{if(!o.deleted){const a=o.content.getContent()[o.length-1];t[e]=a instanceof Oo?a.toJSON():a}}),t}get size(){return[...wh(this)].length}keys(){return $y(wh(this),t=>t[0])}values(){return $y(wh(this),t=>t[1].content.getContent()[t[1].length-1])}entries(){return $y(wh(this),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){this.doc??Mo(),this._map.forEach((o,e)=>{o.deleted||t(o.content.getContent()[o.length-1],e,this)})}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?Lr(this.doc,o=>{xh(o,this,t)}):this._prelimContent.delete(t)}set(t,o){return this.doc!==null?Lr(this.doc,e=>{Gy(e,this,t,o)}):this._prelimContent.set(t,o),o}get(t){return Yy(this,t)}has(t){return wS(this,t)}clear(){this.doc!==null?Lr(this.doc,t=>{this.forEach(function(o,e,a){xh(t,a,e)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(zR)}}const Ua=(u,t)=>u===t||typeof u=="object"&&typeof t=="object"&&u&&t&&HM(u,t);class Zy{constructor(t,o,e,a){this.left=t,this.right=o,this.index=e,this.currentAttributes=a}forward(){switch(this.right===null&&Bl(),this.right.content.constructor){case _o:this.right.deleted||lu(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}}const CS=(u,t,o)=>{for(;t.right!==null&&o>0;){switch(t.right.content.constructor){case _o:t.right.deleted||lu(t.currentAttributes,t.right.content);break;default:t.right.deleted||(o<t.right.length&&za(u,Yr(t.right.id.client,t.right.id.clock+o)),t.index+=t.right.length,o-=t.right.length);break}t.left=t.right,t.right=t.right.right}return t},Sh=(u,t,o,e)=>{const a=new Map,r=e?bh(t,o):null;if(r){const n=new Zy(r.p.left,r.p,r.index,a);return CS(u,n,o-r.index)}else{const n=new Zy(null,t._start,0,a);return CS(u,n,o)}},ES=(u,t,o,e)=>{for(;o.right!==null&&(o.right.deleted===!0||o.right.content.constructor===_o&&Ua(e.get(o.right.content.key),o.right.content.value));)o.right.deleted||e.delete(o.right.content.key),o.forward();const a=u.doc,r=a.clientID;e.forEach((n,i)=>{const l=o.left,s=o.right,d=new Ro(Yr(r,ai(a.store,r)),l,l&&l.lastId,s,s&&s.id,t,null,new _o(i,n));d.integrate(u,0),o.right=d,o.forward()})},lu=(u,t)=>{const{key:o,value:e}=t;e===null?u.delete(o):u.set(o,e)},kS=(u,t)=>{for(;u.right!==null;){if(!(u.right.deleted||u.right.content.constructor===_o&&Ua(t[u.right.content.key]??null,u.right.content.value)))break;u.forward()}},OS=(u,t,o,e)=>{const a=u.doc,r=a.clientID,n=new Map;for(const i in e){const l=e[i],s=o.currentAttributes.get(i)??null;if(!Ua(s,l)){n.set(i,s);const{left:d,right:c}=o;o.right=new Ro(Yr(r,ai(a.store,r)),d,d&&d.lastId,c,c&&c.id,t,null,new _o(i,l)),o.right.integrate(u,0),o.forward()}}return n},Qy=(u,t,o,e,a)=>{o.currentAttributes.forEach((p,f)=>{a[f]===void 0&&(a[f]=null)});const r=u.doc,n=r.clientID;kS(o,a);const i=OS(u,t,o,a),l=e.constructor===String?new sa(e):e instanceof Oo?new $a(e):new uu(e);let{left:s,right:d,index:c}=o;t._searchMarker&&$d(t._searchMarker,o.index,l.getLength()),d=new Ro(Yr(n,ai(r.store,n)),s,s&&s.lastId,d,d&&d.id,t,null,l),d.integrate(u,0),o.right=d,o.index=c,o.forward(),ES(u,t,o,i)},TS=(u,t,o,e,a)=>{const r=u.doc,n=r.clientID;kS(o,a);const i=OS(u,t,o,a);e:for(;o.right!==null&&(e>0||i.size>0&&(o.right.deleted||o.right.content.constructor===_o));){if(!o.right.deleted)switch(o.right.content.constructor){case _o:{const{key:l,value:s}=o.right.content,d=a[l];if(d!==void 0){if(Ua(d,s))i.delete(l);else{if(e===0)break e;i.set(l,s)}o.right.delete(u)}else o.currentAttributes.set(l,s);break}default:e<o.right.length&&za(u,Yr(o.right.id.client,o.right.id.clock+e)),e-=o.right.length;break}o.forward()}if(e>0){let l="";for(;e>0;e--)l+=`
1516
1516
  `;o.right=new Ro(Yr(n,ai(r.store,n)),o.left,o.left&&o.left.lastId,o.right,o.right&&o.right.id,t,null,new sa(l)),o.right.integrate(u,0),o.forward()}ES(u,t,o,i)},AS=(u,t,o,e,a)=>{let r=t;const n=Cs();for(;r&&(!r.countable||r.deleted);){if(!r.deleted&&r.content.constructor===_o){const s=r.content;n.set(s.key,s)}r=r.right}let i=0,l=!1;for(;t!==r;){if(o===t&&(l=!0),!t.deleted){const s=t.content;switch(s.constructor){case _o:{const{key:d,value:c}=s,p=e.get(d)??null;(n.get(d)!==s||p===c)&&(t.delete(u),i++,!l&&(a.get(d)??null)===c&&p!==c&&(p===null?a.delete(d):a.set(d,p))),!l&&!t.deleted&&lu(a,s);break}}}t=t.right}return i},jR=(u,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const o=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===_o){const e=t.content.key;o.has(e)?t.delete(u):o.add(e)}t=t.left}},PR=u=>{let t=0;return Lr(u.doc,o=>{let e=u._start,a=u._start,r=Cs();const n=Ty(r);for(;a;){if(a.deleted===!1)switch(a.content.constructor){case _o:lu(n,a.content);break;default:t+=AS(o,e,a,r,n),r=Ty(n),e=a;break}a=a.right}}),t},IR=u=>{const t=new Set,o=u.doc;for(const[e,a]of u.afterState.entries()){const r=u.beforeState.get(e)||0;a!==r&&aS(u,o.store.clients.get(e),r,a,n=>{!n.deleted&&n.content.constructor===_o&&n.constructor!==Ha&&t.add(n.parent)})}Lr(o,e=>{Yw(u,u.deleteSet,a=>{if(a instanceof Ha||!a.parent._hasFormatting||t.has(a.parent))return;const r=a.parent;a.content.constructor===_o?t.add(r):jR(e,a)});for(const a of t)PR(a)})},NS=(u,t,o)=>{const e=o,a=Ty(t.currentAttributes),r=t.right;for(;o>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case $a:case uu:case sa:o<t.right.length&&za(u,Yr(t.right.id.client,t.right.id.clock+o)),o-=t.right.length,t.right.delete(u);break}t.forward()}r&&AS(u,r,t.right,a,t.currentAttributes);const n=(t.left||t.right).parent;return n._searchMarker&&$d(n._searchMarker,t.index,-e+o),t};class MR extends yh{constructor(t,o,e){super(t,o),this.childListChanged=!1,this.keysChanged=new Set,e.forEach(a=>{a===null?this.childListChanged=!0:this.keysChanged.add(a)})}get changes(){if(this._changes===null){const t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){const t=this.target.doc,o=[];Lr(t,e=>{const a=new Map,r=new Map;let n=this.target._start,i=null;const l={};let s="",d=0,c=0;const p=()=>{if(i!==null){let f=null;switch(i){case"delete":c>0&&(f={delete:c}),c=0;break;case"insert":(typeof s=="object"||s.length>0)&&(f={insert:s},a.size>0&&(f.attributes={},a.forEach((h,g)=>{h!==null&&(f.attributes[g]=h)}))),s="";break;case"retain":d>0&&(f={retain:d},FM(l)||(f.attributes=DM({},l))),d=0;break}f&&o.push(f),i=null}};for(;n!==null;){switch(n.content.constructor){case $a:case uu:this.adds(n)?this.deletes(n)||(p(),i="insert",s=n.content.getContent()[0],p()):this.deletes(n)?(i!=="delete"&&(p(),i="delete"),c+=1):n.deleted||(i!=="retain"&&(p(),i="retain"),d+=1);break;case sa:this.adds(n)?this.deletes(n)||(i!=="insert"&&(p(),i="insert"),s+=n.content.str):this.deletes(n)?(i!=="delete"&&(p(),i="delete"),c+=n.length):n.deleted||(i!=="retain"&&(p(),i="retain"),d+=n.length);break;case _o:{const{key:f,value:h}=n.content;if(this.adds(n)){if(!this.deletes(n)){const g=a.get(f)??null;Ua(g,h)?h!==null&&n.delete(e):(i==="retain"&&p(),Ua(h,r.get(f)??null)?delete l[f]:l[f]=h)}}else if(this.deletes(n)){r.set(f,h);const g=a.get(f)??null;Ua(g,h)||(i==="retain"&&p(),l[f]=g)}else if(!n.deleted){r.set(f,h);const g=l[f];g!==void 0&&(Ua(g,h)?g!==null&&n.delete(e):(i==="retain"&&p(),h===null?delete l[f]:l[f]=h))}n.deleted||(i==="insert"&&p(),lu(a,n.content));break}}n=n.right}for(p();o.length>0;){const f=o[o.length-1];if(f.retain!==void 0&&f.attributes===void 0)o.pop();else break}}),this._delta=o}return this._delta}}class Ch extends Oo{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??Mo(),this._length}_integrate(t,o){super._integrate(t,o);try{this._pending.forEach(e=>e())}catch(e){console.error(e)}this._pending=null}_copy(){return new Ch}clone(){const t=new Ch;return t.applyDelta(this.toDelta()),t}_callObserver(t,o){super._callObserver(t,o);const e=new MR(this,t,o);vh(this,t,e),!t.local&&this._hasFormatting&&(t._needFormattingCleanup=!0)}toString(){this.doc??Mo();let t="",o=this._start;for(;o!==null;)!o.deleted&&o.countable&&o.content.constructor===sa&&(t+=o.content.str),o=o.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:o=!0}={}){this.doc!==null?Lr(this.doc,e=>{const a=new Zy(null,this._start,0,new Map);for(let r=0;r<t.length;r++){const n=t[r];if(n.insert!==void 0){const i=!o&&typeof n.insert=="string"&&r===t.length-1&&a.right===null&&n.insert.slice(-1)===`
1517
- `?n.insert.slice(0,-1):n.insert;(typeof i!="string"||i.length>0)&&Qy(e,this,a,i,n.attributes||{})}else n.retain!==void 0?TS(e,this,a,n.retain,n.attributes||{}):n.delete!==void 0&&NS(e,a,n.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,o,e){this.doc??Mo();const a=[],r=new Map,n=this.doc;let i="",l=this._start;function s(){if(i.length>0){const c={};let p=!1;r.forEach((h,g)=>{p=!0,c[g]=h});const f={insert:i};p&&(f.attributes=c),a.push(f),i=""}}const d=()=>{for(;l!==null;){if(su(l,t)||o!==void 0&&su(l,o))switch(l.content.constructor){case sa:{const c=r.get("ychange");t!==void 0&&!su(l,t)?(c===void 0||c.user!==l.id.client||c.type!=="removed")&&(s(),r.set("ychange",e?e("removed",l.id):{type:"removed"})):o!==void 0&&!su(l,o)?(c===void 0||c.user!==l.id.client||c.type!=="added")&&(s(),r.set("ychange",e?e("added",l.id):{type:"added"})):c!==void 0&&(s(),r.delete("ychange")),i+=l.content.str;break}case $a:case uu:{s();const c={insert:l.content.getContent()[0]};if(r.size>0){const p={};c.attributes=p,r.forEach((f,h)=>{p[h]=f})}a.push(c);break}case _o:su(l,t)&&(s(),lu(r,l.content));break}l=l.right}s()};return t||o?Lr(n,c=>{t&&qy(c,t),o&&qy(c,o),d()},"cleanup"):d(),a}insert(t,o,e){if(o.length<=0)return;const a=this.doc;a!==null?Lr(a,r=>{const n=Sh(r,this,t,!e);e||(e={},n.currentAttributes.forEach((i,l)=>{e[l]=i})),Qy(r,this,n,o,e)}):this._pending.push(()=>this.insert(t,o,e))}insertEmbed(t,o,e){const a=this.doc;a!==null?Lr(a,r=>{const n=Sh(r,this,t,!e);Qy(r,this,n,o,e||{})}):this._pending.push(()=>this.insertEmbed(t,o,e||{}))}delete(t,o){if(o===0)return;const e=this.doc;e!==null?Lr(e,a=>{NS(a,Sh(a,this,t,!0),o)}):this._pending.push(()=>this.delete(t,o))}format(t,o,e){if(o===0)return;const a=this.doc;a!==null?Lr(a,r=>{const n=Sh(r,this,t,!1);n.right!==null&&TS(r,this,n,o,e)}):this._pending.push(()=>this.format(t,o,e))}removeAttribute(t){this.doc!==null?Lr(this.doc,o=>{xh(o,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,o){this.doc!==null?Lr(this.doc,e=>{Gy(e,this,t,o)}):this._pending.push(()=>this.setAttribute(t,o))}getAttribute(t){return Yy(this,t)}getAttributes(){return xS(this)}_write(t){t.writeTypeRef(UR)}}class Xy{constructor(t,o=()=>!0){this._filter=o,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??Mo()}[Symbol.iterator](){return this}next(){let t=this._currentNode,o=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(o)))do if(o=t.content.type,!t.deleted&&(o.constructor===Wd||o.constructor===cu)&&o._start!==null)t=o._start;else for(;t!==null;)if(t.right!==null){t=t.right;break}else t.parent===this._root?t=null:t=t.parent._item;while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class cu extends Oo{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,o){super._integrate(t,o),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new cu}clone(){const t=new cu;return t.insert(0,this.toArray().map(o=>o instanceof Oo?o.clone():o)),t}get length(){return this.doc??Mo(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Xy(this,t)}querySelector(t){t=t.toUpperCase();const e=new Xy(this,a=>a.nodeName&&a.nodeName.toUpperCase()===t).next();return e.done?null:e.value}querySelectorAll(t){return t=t.toUpperCase(),nu(new Xy(this,o=>o.nodeName&&o.nodeName.toUpperCase()===t))}_callObserver(t,o){vh(this,t,new RR(this,o,t))}toString(){return mS(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,o={},e){const a=t.createDocumentFragment();return e!==void 0&&e._createAssociation(a,this),qd(this,r=>{a.insertBefore(r.toDOM(t,o,e),null)}),a}insert(t,o){this.doc!==null?Lr(this.doc,e=>{vS(e,this,t,o)}):this._prelimContent.splice(t,0,...o)}insertAfter(t,o){if(this.doc!==null)Lr(this.doc,e=>{const a=t&&t instanceof Oo?t._item:t;_h(e,this,a,o)});else{const e=this._prelimContent,a=t===null?0:e.findIndex(r=>r===t)+1;if(a===0&&t!==null)throw iu("Reference item not found");e.splice(a,0,...o)}}delete(t,o=1){this.doc!==null?Lr(this.doc,e=>{_S(e,this,t,o)}):this._prelimContent.splice(t,o)}toArray(){return gS(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return yS(this,t)}slice(t=0,o=this.length){return hS(this,t,o)}forEach(t){qd(this,t)}_write(t){t.writeTypeRef($R)}}class Wd extends cu{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,o){super._integrate(t,o),this._prelimAttrs.forEach((e,a)=>{this.setAttribute(a,e)}),this._prelimAttrs=null}_copy(){return new Wd(this.nodeName)}clone(){const t=new Wd(this.nodeName),o=this.getAttributes();return BM(o,(e,a)=>{typeof e=="string"&&t.setAttribute(a,e)}),t.insert(0,this.toArray().map(e=>e instanceof Oo?e.clone():e)),t}toString(){const t=this.getAttributes(),o=[],e=[];for(const i in t)e.push(i);e.sort();const a=e.length;for(let i=0;i<a;i++){const l=e[i];o.push(l+'="'+t[l]+'"')}const r=this.nodeName.toLocaleLowerCase(),n=o.length>0?" "+o.join(" "):"";return`<${r}${n}>${super.toString()}</${r}>`}removeAttribute(t){this.doc!==null?Lr(this.doc,o=>{xh(o,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,o){this.doc!==null?Lr(this.doc,e=>{Gy(e,this,t,o)}):this._prelimAttrs.set(t,o)}getAttribute(t){return Yy(this,t)}hasAttribute(t){return wS(this,t)}getAttributes(t){return t?AR(this,t):xS(this)}toDOM(t=document,o={},e){const a=t.createElement(this.nodeName),r=this.getAttributes();for(const n in r){const i=r[n];typeof i=="string"&&a.setAttribute(n,i)}return qd(this,n=>{a.appendChild(n.toDOM(t,o,e))}),e!==void 0&&e._createAssociation(a,this),a}_write(t){t.writeTypeRef(HR),t.writeKey(this.nodeName)}}class RR extends yh{constructor(t,o,e){super(t,e),this.childListChanged=!1,this.attributesChanged=new Set,o.forEach(a=>{a===null?this.childListChanged=!0:this.attributesChanged.add(a)})}}class jS{constructor(t,o){this.id=t,this.length=o}get deleted(){throw Es()}mergeWith(t){return!1}write(t,o,e){throw Es()}integrate(t,o){throw Es()}}const DR=0;class Ha extends jS{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,o){o>0&&(this.id.clock+=o,this.length-=o),iS(t.doc.store,this)}write(t,o){t.writeInfo(DR),t.writeLen(this.length-o)}getMissing(t,o){return null}}class Eh{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Eh(this.content)}splice(t){throw Es()}mergeWith(t){return!1}integrate(t,o){}delete(t){}gc(t){}write(t,o){t.writeBuf(this.content)}getRef(){return 3}}class kh{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new kh(this.len)}splice(t){const o=new kh(this.len-t);return this.len=t,o}mergeWith(t){return this.len+=t.len,!0}integrate(t,o){Xw(t.deleteSet,o.id.client,o.id.clock,this.len),o.markDeleted()}delete(t){}gc(t){}write(t,o){t.writeLen(this.len-o)}getRef(){return 1}}const LR=(u,t)=>new Hd({guid:u,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Oh{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const o={};this.opts=o,t.gc||(o.gc=!1),t.autoLoad&&(o.autoLoad=!0),t.meta!==null&&(o.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Oh(LR(this.doc.guid,this.opts))}splice(t){throw Es()}mergeWith(t){return!1}integrate(t,o){this.doc._item=o,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,o){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}class uu{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new uu(this.embed)}splice(t){throw Es()}mergeWith(t){return!1}integrate(t,o){}delete(t){}gc(t){}write(t,o){t.writeJSON(this.embed)}getRef(){return 5}}class _o{constructor(t,o){this.key=t,this.value=o}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new _o(this.key,this.value)}splice(t){throw Es()}mergeWith(t){return!1}integrate(t,o){const e=o.parent;e._searchMarker=null,e._hasFormatting=!0}delete(t){}gc(t){}write(t,o){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}const BR=ph("node_env")==="development";class du{constructor(t){this.arr=t,BR&&Hw(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new du(this.arr)}splice(t){const o=new du(this.arr.slice(t));return this.arr=this.arr.slice(0,t),o}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,o){}delete(t){}gc(t){}write(t,o){const e=this.arr.length;t.writeLen(e-o);for(let a=o;a<e;a++){const r=this.arr[a];t.writeAny(r)}}getRef(){return 8}}class sa{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new sa(this.str)}splice(t){const o=new sa(this.str.slice(t));this.str=this.str.slice(0,t);const e=this.str.charCodeAt(t-1);return e>=55296&&e<=56319&&(this.str=this.str.slice(0,t-1)+"�",o.str="�"+o.str.slice(1)),o}mergeWith(t){return this.str+=t.str,!0}integrate(t,o){}delete(t){}gc(t){}write(t,o){t.writeString(o===0?this.str:this.str.slice(o))}getRef(){return 4}}const FR=0,zR=1,UR=2,HR=3,$R=4;class $a{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new $a(this.type._copy())}splice(t){throw Es()}mergeWith(t){return!1}integrate(t,o){this.type._integrate(t.doc,o)}delete(t){let o=this.type._start;for(;o!==null;)o.deleted?o.id.clock<(t.beforeState.get(o.id.client)||0)&&t._mergeStructs.push(o):o.delete(t),o=o.right;this.type._map.forEach(e=>{e.deleted?e.id.clock<(t.beforeState.get(e.id.client)||0)&&t._mergeStructs.push(e):e.delete(t)}),t.changed.delete(this.type)}gc(t){let o=this.type._start;for(;o!==null;)o.gc(t,!0),o=o.right;this.type._start=null,this.type._map.forEach(e=>{for(;e!==null;)e.gc(t,!0),e=e.left}),this.type._map=new Map}write(t,o){this.type._write(t)}getRef(){return 7}}const PS=(u,t,o)=>{const{client:e,clock:a}=t.id,r=new Ro(Yr(e,a+o),t,Yr(e,a+o-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(o));return t.deleted&&r.markDeleted(),t.keep&&(r.keep=!0),t.redone!==null&&(r.redone=Yr(t.redone.client,t.redone.clock+o)),t.right=r,r.right!==null&&(r.right.left=r),u._mergeStructs.push(r),r.parentSub!==null&&r.right===null&&r.parent._map.set(r.parentSub,r),t.length=o,r};class Ro extends jS{constructor(t,o,e,a,r,n,i,l){super(t,l.getLength()),this.origin=e,this.left=o,this.right=a,this.rightOrigin=r,this.parent=n,this.parentSub=i,this.redone=null,this.content=l,this.info=this.content.isCountable()?Aw:0}set marker(t){(this.info&jy)>0!==t&&(this.info^=jy)}get marker(){return(this.info&jy)>0}get keep(){return(this.info&Tw)>0}set keep(t){this.keep!==t&&(this.info^=Tw)}get countable(){return(this.info&Aw)>0}get deleted(){return(this.info&Ny)>0}set deleted(t){this.deleted!==t&&(this.info^=Ny)}markDeleted(){this.info|=Ny}getMissing(t,o){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=ai(o,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=ai(o,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===hh&&this.id.client!==this.parent.client&&this.parent.clock>=ai(o,this.parent.client))return this.parent.client;if(this.origin&&(this.left=sS(t,o,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=za(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===Ha||this.right&&this.right.constructor===Ha)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===Ro&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===Ro&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===hh){const e=Vy(o,this.parent);e.constructor===Ha?this.parent=null:this.parent=e.content.type}return null}integrate(t,o){if(o>0&&(this.id.clock+=o,this.left=sS(t,t.doc.store,Yr(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(o),this.length-=o),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let e=this.left,a;if(e!==null)a=e.right;else if(this.parentSub!==null)for(a=this.parent._map.get(this.parentSub)||null;a!==null&&a.left!==null;)a=a.left;else a=this.parent._start;const r=new Set,n=new Set;for(;a!==null&&a!==this.right;){if(n.add(a),r.add(a),gh(this.origin,a.origin)){if(a.id.client<this.id.client)e=a,r.clear();else if(gh(this.rightOrigin,a.rightOrigin))break}else if(a.origin!==null&&n.has(Vy(t.doc.store,a.origin)))r.has(Vy(t.doc.store,a.origin))||(e=a,r.clear());else break;a=a.right}this.left=e}if(this.left!==null){const e=this.left.right;this.right=e,this.left.right=this}else{let e;if(this.parentSub!==null)for(e=this.parent._map.get(this.parentSub)||null;e!==null&&e.left!==null;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),iS(t.doc.store,this),this.content.integrate(t,this),cS(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new Ha(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:Yr(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&gh(t.origin,this.lastId)&&this.right===t&&gh(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const o=this.parent._searchMarker;return o&&o.forEach(e=>{e.p===t&&(e.p=this,!this.deleted&&this.countable&&(e.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const o=this.parent;this.countable&&this.parentSub===null&&(o._length-=this.length),this.markDeleted(),Xw(t.deleteSet,this.id.client,this.id.clock,this.length),cS(t,o,this.parentSub),this.content.delete(t)}}gc(t,o){if(!this.deleted)throw Bl();this.content.gc(t),o?vR(t,this,new Ha(this.id,this.length)):this.content=new kh(this.length)}write(t,o){const e=o>0?Yr(this.id.client,this.id.clock+o-1):this.origin,a=this.rightOrigin,r=this.parentSub,n=this.content.getRef()&dM|(e===null?0:dh)|(a===null?0:Nw)|(r===null?0:uM);if(t.writeInfo(n),e!==null&&t.writeLeftID(e),a!==null&&t.writeRightID(a),e===null&&a===null){const i=this.parent;if(i._item!==void 0){const l=i._item;if(l===null){const s=yR(i);t.writeParentInfo(!0),t.writeString(s)}else t.writeParentInfo(!1),t.writeLeftID(l.id)}else i.constructor===String?(t.writeParentInfo(!0),t.writeString(i)):i.constructor===hh?(t.writeParentInfo(!1),t.writeLeftID(i)):Bl();r!==null&&t.writeString(r)}this.content.write(t,o)}}const IS=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},MS="__ $YJS$ __";IS[MS]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),IS[MS]=!0;function qR(u){return u&&u.__esModule&&Object.prototype.hasOwnProperty.call(u,"default")?u.default:u}qR(function(u){const t=new URLSearchParams;t.append("code",u);for(let o=1;o<arguments.length;o++)t.append("v",arguments[o]);throw Error(`Minified Lexical error #${u}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)});const WR=jo();function RS(){return Math.random().toString(36).replace(/[^a-z]+/g,"").substr(0,5)}function Th(u,t,o,e,a){return{author:t,content:u,deleted:a===void 0?!1:a,id:o===void 0?RS():o,timeStamp:e===void 0?performance.now():e,type:"comment"}}function DS(u,t,o){return{comments:t,id:o===void 0?RS():o,quote:u,type:"thread",resolved:!1}}function LS(u){return{comments:Array.from(u.comments),id:u.id,quote:u.quote,type:"thread",resolved:!1}}function VR(u){return{author:u.author,content:"[Deleted Comment]",deleted:!0,id:u.id,timeStamp:u.timeStamp,type:"comment"}}function e0(u){const t=u._changeListeners;for(const o of t)o()}class JR{constructor(t){qr(this,"_editor");qr(this,"_comments");qr(this,"_changeListeners");qr(this,"_collabProvider");this._comments=[],this._editor=t,this._collabProvider=null,this._changeListeners=new Set}isCollaborative(){return this._collabProvider!==null}getComments(){return this._comments}addComment(t,o,e){const a=Array.from(this._comments),r=this._getCollabComments();if(o!==void 0&&t.type==="comment")for(let n=0;n<a.length;n++){const i=a[n];if(i.type==="thread"&&i.id===o.id){const l=LS(i);a.splice(n,1,l);const s=e!==void 0?e:l.comments.length;if(this.isCollaborative()&&r!==null){const d=r.get(n).get("comments");this._withRemoteTransaction(()=>{const c=this._createCollabSharedMap(t);d.insert(s,[c])})}l.comments.splice(s,0,t);break}}else{const n=e!==void 0?e:a.length;this.isCollaborative()&&r!==null&&this._withRemoteTransaction(()=>{const i=this._createCollabSharedMap(t);r.insert(n,[i])}),a.splice(n,0,t)}this._comments=a,e0(this)}deleteCommentOrThread(t,o){const e=Array.from(this._comments),a=this._getCollabComments();let r=null;if(o!==void 0)for(let n=0;n<e.length;n++){const i=e[n];if(i.type==="thread"&&i.id===o.id){const l=LS(i);e.splice(n,1,l);const s=l.comments;if(r=s.indexOf(t),this.isCollaborative()&&a!==null){const d=a.get(n).get("comments");this._withRemoteTransaction(()=>{d.delete(r)})}s.splice(r,1);break}}else r=e.indexOf(t),this.isCollaborative()&&a!==null&&this._withRemoteTransaction(()=>{a.delete(r)}),e.splice(r,1);return this._comments=e,e0(this),t.type==="comment"?{index:r,markedComment:VR(t)}:null}resolveThread(t){const o={...t,resolved:!0},e=Array.from(this._comments),a=e.findIndex(r=>r.id===o.id);a!==-1&&(e[a]=o),this._comments=e,e0(this)}registerOnChange(t){const o=this._changeListeners;return o.add(t),()=>{o.delete(t)}}_withRemoteTransaction(t){const o=this._collabProvider;o!==null&&o.doc.transact(t,this)}_withLocalTransaction(t){const o=this._collabProvider;try{this._collabProvider=null,t()}finally{this._collabProvider=o}}_getCollabComments(){const t=this._collabProvider;return t!==null?t.doc.get("comments",Fl):null}_createCollabSharedMap(t){const o=new au,e=t.type,a=t.id;if(o.set("type",e),o.set("id",a),e==="comment")o.set("author",t.author),o.set("content",t.content),o.set("deleted",t.deleted),o.set("timeStamp",t.timeStamp);else{o.set("quote",t.quote);const r=new Fl;t.comments.forEach((n,i)=>{const l=this._createCollabSharedMap(n);r.insert(i,[l])}),o.set("comments",r)}return o}registerCollaboration(t){this._collabProvider=t;const o=this._getCollabComments(),e=()=>{t.connect()},a=()=>{try{t.disconnect()}catch{}},r=this._editor.registerCommand(WR,i=>(e!==void 0&&a!==void 0&&(i?(console.log("Comments connected!"),e()):(console.log("Comments disconnected!"),a())),!1),In),n=(i,l)=>{if(l.origin!==this)for(let s=0;s<i.length;s++){const d=i[s];if(d instanceof SS){const c=d.target,p=d.delta;let f=0;for(let h=0;h<p.length;h++){const g=p[h],m=g.insert,v=g.retain,_=g.delete,b=c.parent,S=c===o?void 0:b instanceof au&&this._comments.find(C=>C.id===b.get("id"));if(Array.isArray(m))m.slice().reverse().forEach(C=>{const x=C.get("id"),w=C.get("type")==="thread"?DS(C.get("quote"),C.get("comments").toArray().map(E=>Th(E.get("content"),E.get("author"),E.get("id"),E.get("timeStamp"),E.get("deleted"))),x):Th(C.get("content"),C.get("author"),x,C.get("timeStamp"),C.get("deleted"));this._withLocalTransaction(()=>{this.addComment(w,S,f)})});else if(typeof v=="number")f+=v;else if(typeof _=="number")for(let C=0;C<_;C++){const x=S===void 0||S===!1?this._comments[f]:S.comments[f];this._withLocalTransaction(()=>{this.deleteCommentOrThread(x,S)}),f++}}}}};return o===null?()=>null:(o.observeDeep(n),e(),()=>{o.unobserveDeep(n),r(),this._collabProvider=null})}}function KR(u){const[t,o]=ve.useState(u.getComments());return ve.useEffect(()=>u.registerOnChange(()=>{o(u.getComments())}),[u]),t}const r4="";function t0({className:u,style:t}){return ke.jsx(Cd,{className:u||"ContentEditable__root",style:t})}const BS=jo();function GR({anchorKey:u,editor:t,onAddComment:o}){const e=ve.useRef(null),a=ve.useCallback(()=>{const r=e.current,n=t.getRootElement(),i=t.getElementByKey(u);if(r!==null&&n!==null&&i!==null){const{right:l}=n.getBoundingClientRect(),{top:s}=i.getBoundingClientRect();r.style.left=`${l-20}px`,r.style.top=`${s-30}px`}},[u,t]);return ve.useEffect(()=>(window.addEventListener("resize",a),()=>{window.removeEventListener("resize",a)}),[t,a]),kw(()=>{a()},[u,t,a]),ke.jsx("div",{className:"CommentPlugin_AddCommentBox",ref:e,children:ke.jsx("button",{className:"CommentPlugin_AddCommentBox_button",onClick:o,children:ke.jsx("i",{className:"icon add-comment"})})})}function YR({onEscape:u}){const[t]=Gn();return ve.useEffect(()=>t.registerCommand(Fs,o=>u(o),2),[t,u]),null}function FS({className:u,autoFocus:t,onEscape:o,onChange:e,editorRef:a,placeholder:r="Type a comment..."}){const n={namespace:"Commenting",nodes:[],onError:i=>{throw i},theme:cm};return ke.jsx(np,{initialConfig:n,children:ke.jsxs("div",{className:"CommentPlugin_CommentInputBox_EditorContainer",children:[ke.jsx(oy,{contentEditable:ke.jsx(t0,{className:u}),placeholder:ke.jsx(ke.Fragment,{}),ErrorBoundary:Ol}),ke.jsx(zp,{onChange:e}),ke.jsx(Fp,{}),t!==!1&&ke.jsx(Tp,{}),ke.jsx(YR,{onEscape:o}),ke.jsx(sx,{}),a!==void 0&&ke.jsx(nM,{editorRef:a})]})})}function zS(u,t){return ve.useCallback((o,e)=>{o.read(()=>{u(Vm()),t(!Jm(e.isComposing(),!0))})},[t,u])}function ZR({editor:u,cancelAddComment:t,submitAddComment:o}){const[e,a]=ve.useState(""),[r,n]=ve.useState(!1),i=ve.useRef(null),l=ve.useMemo(()=>({container:document.createElement("div"),elements:[]}),[]),s=ve.useRef(null),d=$S(),c=ve.useCallback(()=>{u.getEditorState().read(()=>{const g=Ot();if(xt(g)){s.current=g.clone();const m=g.anchor,v=g.focus,_=Rv(u,m.getNode(),m.offset,v.getNode(),v.offset),b=i.current;if(_!==null&&b!==null){const{left:S,bottom:C,width:x}=_.getBoundingClientRect(),y=Dv(u,_);let w=y.length===1?S+x/2-125:S-125;w<10&&(w=10),b.style.left=`${w}px`,b.style.top=`${C+20+(window.pageYOffset||document.documentElement.scrollTop)}px`;const E=y.length,{container:I}=l,j=l.elements,B=j.length;for(let N=0;N<E;N++){const D=y[N];let P=j[N];P===void 0&&(P=document.createElement("span"),j[N]=P,I.appendChild(P));const k="255, 212, 0",A=`position:absolute;top:${D.top+(window.pageYOffset||document.documentElement.scrollTop)}px;left:${D.left}px;height:${D.height}px;width:${D.width}px;background-color:rgba(${k}, 0.3);pointer-events:none;z-index:5;`;P.style.cssText=A}for(let N=B-1;N>=E;N--){const D=j[N];I.removeChild(D),j.pop()}}}})},[u,l]);kw(()=>{c();const g=l.container,m=document.body;if(m!==null)return m.appendChild(g),()=>{m.removeChild(g)}},[l.container,c]),ve.useEffect(()=>(window.addEventListener("resize",c),()=>{window.removeEventListener("resize",c)}),[c]);const p=g=>(g.preventDefault(),t(),!0),f=()=>{if(r){let g=u.getEditorState().read(()=>{const m=s.current;return m?m.getTextContent():""});g.length>100&&(g=g.slice(0,99)+"…"),o(DS(g,[Th(e,d)]),!0,void 0,s.current),s.current=null}},h=zS(a,n);return ke.jsxs("div",{className:"CommentPlugin_CommentInputBox",ref:i,children:[ke.jsx(FS,{className:"CommentPlugin_CommentInputBox_Editor",onEscape:p,onChange:h}),ke.jsxs("div",{className:"CommentPlugin_CommentInputBox_Buttons",children:[ke.jsx(Vs,{onClick:t,className:"CommentPlugin_CommentInputBox_Button",children:"Cancel"}),ke.jsx(Vs,{onClick:f,disabled:!r,className:"CommentPlugin_CommentInputBox_Button primary",children:"Comment"})]})]})}function QR({submitAddComment:u,thread:t,placeholder:o}){const[e,a]=ve.useState(""),[r,n]=ve.useState(!1),i=ve.useRef(null),l=$S(),s=zS(a,n),d=()=>{if(r){u(Th(e,l),!1,t);const c=i.current;c!==null&&c.dispatchCommand(Sf,void 0)}};return ke.jsxs(ke.Fragment,{children:[ke.jsx(FS,{className:"CommentPlugin_CommentsPanel_Editor",autoFocus:!1,onEscape:()=>!0,onChange:s,editorRef:i,placeholder:o}),ke.jsx(Vs,{className:"CommentPlugin_CommentsPanel_SendButton",onClick:d,disabled:!r,children:ke.jsx("i",{className:"send"})})]})}function US({commentOrThread:u,deleteCommentOrThread:t,onClose:o,thread:e=void 0}){return ke.jsxs(ke.Fragment,{children:["Are you sure you want to delete this ",u.type,"?",ke.jsxs("div",{className:"Modal__content",children:[ke.jsx(Vs,{onClick:()=>{t(u,e),o()},children:"Delete"})," ",ke.jsx(Vs,{onClick:()=>{o()},children:"Cancel"})]})]})}function HS({comment:u,deleteComment:t,thread:o,rtf:e}){const a=Math.round((u.timeStamp-performance.now())/1e3),r=Math.round(a/60),[n,i]=Sp();return ke.jsxs("li",{className:"CommentPlugin_CommentsPanel_List_Comment",children:[ke.jsxs("div",{className:"CommentPlugin_CommentsPanel_List_Details",children:[ke.jsx("span",{className:"CommentPlugin_CommentsPanel_List_Comment_Author",children:u.author}),ke.jsxs("span",{className:"CommentPlugin_CommentsPanel_List_Comment_Time",children:["· ",a>-10?"Just now":e.format(r,"minute")]})]}),ke.jsx("p",{className:u.deleted?"CommentPlugin_CommentsPanel_DeletedComment":"",children:u.content}),!u.deleted&&ke.jsxs(ke.Fragment,{children:[ke.jsx(Vs,{onClick:()=>{i("Delete Comment",l=>ke.jsx(US,{commentOrThread:u,deleteCommentOrThread:t,thread:o,onClose:l}))},className:"CommentPlugin_CommentsPanel_List_DeleteButton",children:ke.jsx("i",{className:"delete"})}),n]})]})}function XR({activeIDs:u,comments:t,deleteCommentOrThread:o,listRef:e,submitAddComment:a,markNodeMap:r,resolveThread:n}){const[i]=Gn(),[l,s]=ve.useState(0),[d,c]=Sp(),p=ve.useMemo(()=>new Intl.RelativeTimeFormat("en",{localeMatcher:"best fit",numeric:"auto",style:"short"}),[]);return ve.useEffect(()=>{const f=setTimeout(()=>{s(l+1)},1e4);return()=>{clearTimeout(f)}},[l]),ke.jsx("ul",{className:"CommentPlugin_CommentsPanel_List",ref:e,children:t.map(f=>{const h=f.id;if(f.type==="thread"){const g=()=>{const m=r.get(h);if(m!==void 0&&(u===null||u.indexOf(h)===-1)){const v=document.activeElement;i.update(()=>{const _=Array.from(m)[0],b=Qn(_);Rp(b)&&b.selectStart()},{onUpdate(){v!==null&&v.focus()}})}};return console.log(f,"commentOrThread"),ke.jsxs("li",{onClick:g,className:`CommentPlugin_CommentsPanel_List_Thread ${r.has(h)?"interactive":""} ${u.indexOf(h)===-1?"":"active"}`,children:[ke.jsxs("div",{className:"CommentPlugin_CommentsPanel_List_Thread_QuoteBox",children:[ke.jsxs("blockquote",{className:"CommentPlugin_CommentsPanel_List_Thread_Quote",children:[ke.jsx("img",{className:"add-toolbar-image-icon",src:rM,alt:"Add Image"}),ke.jsx("span",{children:f.quote}),ke.jsx("img",{className:`add-toolbar-image-icon CommentPlugin_CommentsPanel_List_ResolveButton ${f.resolved?"opacity-full":""}`,src:oM,alt:"Resolve Comment",onClick:()=>n(f)})]}),ke.jsx(Vs,{onClick:()=>{c("Delete Thread",m=>ke.jsx(US,{commentOrThread:f,deleteCommentOrThread:o,onClose:m}))},className:"CommentPlugin_CommentsPanel_List_DeleteButton",children:ke.jsx("i",{className:"delete"})}),d]}),ke.jsx("ul",{className:"CommentPlugin_CommentsPanel_List_Thread_Comments",children:f.comments.map(m=>m.deleted?null:ke.jsx(HS,{comment:m,deleteComment:o,thread:f,rtf:p},m.id))}),!f.resolved&&ke.jsx("div",{className:"CommentPlugin_CommentsPanel_List_Thread_Editor",children:ke.jsx(QR,{submitAddComment:a,thread:f,placeholder:"Reply to comment..."})})]},h)}return ke.jsx(HS,{comment:f,deleteComment:o,rtf:p},h)})})}function e3({activeIDs:u,deleteCommentOrThread:t,comments:o,submitAddComment:e,markNodeMap:a,resolveThread:r}){const n=ve.useRef(null),i=o.length===0;return ke.jsxs("div",{className:"CommentPlugin_CommentsPanel",children:[ke.jsx("h2",{className:"CommentPlugin_CommentsPanel_Heading",children:"Comments"}),i?ke.jsx("div",{className:"CommentPlugin_CommentsPanel_Empty",children:"No Comments"}):ke.jsx(XR,{activeIDs:u,comments:o,deleteCommentOrThread:t,listRef:n,submitAddComment:e,markNodeMap:a,resolveThread:r})]})}function $S(){const u=Lp(),{yjsDocMap:t,name:o}=u;return t.has("comments")?o:"Playground User"}function t3({providerFactory:u,showComments:t,setShowComments:o}){const e=Lp(),[a]=Gn(),r=ve.useMemo(()=>new JR(a),[a]),n=KR(r),i=ve.useMemo(()=>new Map,[]),[l,s]=ve.useState(),[d,c]=ve.useState([]),[p,f]=ve.useState(!1),{yjsDocMap:h}=e;ve.useEffect(()=>{if(u){const S=u("comments",h);return r.registerCollaboration(S)}},[r,u,h]);const g=ve.useCallback(()=>{a.update(()=>{const S=Ot();S!==null&&(S.dirty=!0)}),f(!1)},[a]),m=ve.useCallback((S,C)=>{if(S.type==="comment"){const x=r.deleteCommentOrThread(S,C);if(!x)return;const{markedComment:y,index:w}=x;r.addComment(y,C,w)}else{r.deleteCommentOrThread(S);const x=C!==void 0?C.id:S.id,y=i.get(x);y!==void 0&&setTimeout(()=>{a.update(()=>{for(const w of y){const E=Qn(w);Rp(E)&&(E.deleteID(x),E.getIDs().length===0&&nx(E))}})})}},[r,a,i]),v=S=>{S&&S.type==="thread"&&r.resolveThread(S)},_=ve.useCallback((S,C,x,y)=>{r.addComment(S,x),C&&(a.update(()=>{if(xt(y)){const w=y.isBackward(),E=S.id;rx(y,w,E)}}),f(!1))},[r,a]);ve.useEffect(()=>{console.log("askjdhasdhasjkdh");const S=[];for(let C=0;C<d.length;C++){const x=d[C],y=i.get(x);if(y!==void 0)for(const w of y){const E=a.getElementByKey(w);E!==null&&(E.classList.add("selected"),S.push(E),o(!0))}}return()=>{for(let C=0;C<S.length;C++)S[C].classList.remove("selected")}},[d,a,i]),ve.useEffect(()=>{const S=new Map;return Br($v(a,Dp,C=>ex(C.getIDs()),(C,x)=>{C.getIDs().forEach(w=>{x.addID(w)})}),a.registerMutationListener(Dp,C=>{a.getEditorState().read(()=>{for(const[x,y]of C){const w=Qn(x);let E=[];y==="destroyed"?E=S.get(x)||[]:Rp(w)&&(E=w.getIDs());for(let I=0;I<E.length;I++){const j=E[I];let B=i.get(j);S.set(x,E),y==="destroyed"?B!==void 0&&(B.delete(x),B.size===0&&i.delete(j)):(B===void 0&&(B=new Set,i.set(j,B)),B.has(x)||B.add(x))}}})}),a.registerUpdateListener(({editorState:C,tags:x})=>{C.read(()=>{const y=Ot();let w=!1,E=!1;if(xt(y)){const I=y.anchor.getNode();if(kt(I)){const j=tx(I,y.anchor.offset);j!==null&&(c(j),w=!0),y.isCollapsed()||(s(I.getKey()),E=!0)}}w||c(I=>I.length===0?I:[]),E||s(null),!x.has("collaboration")&&xt(y)&&f(!1)})}),a.registerCommand(BS,()=>{const C=window.getSelection();return C!==null&&C.removeAllRanges(),f(!0),!0},On))},[a,i]);const b=()=>{a.dispatchCommand(BS,void 0)};return ke.jsxs(ke.Fragment,{children:[p&&go.createPortal(ke.jsx(ZR,{editor:a,cancelAddComment:g,submitAddComment:_}),document.body),l!=null&&!p&&go.createPortal(ke.jsx(GR,{anchorKey:l,editor:a,onAddComment:b}),document.body),t&&go.createPortal(ke.jsx(e3,{comments:n,submitAddComment:_,deleteCommentOrThread:m,activeIDs:d,markNodeMap:i,resolveThread:v}),document.body)]})}const n3=({onChange:u})=>{const[t]=Gn(),[o,e]=ve.useState(!0),a=ve.useRef(""),r=a.current,n=ve.useCallback(()=>{t.update(()=>{const i=l1(t);o?e(!1):i!==r&&(u(i),a.current=i)})},[t,o,u,r]);return ve.useEffect(()=>{const i=t.registerUpdateListener(n);return()=>i()},[t,n]),null};function r3(){const[u]=Gn();return ve.useEffect(()=>{if(!u.hasNodes([Ep,Sd]))throw new Error("ListPlugin: ListNode and/or ListItemNode not registered on editor")},[u]),function(t){ve.useEffect(()=>Br(t.registerCommand(Wm,()=>(p_(t,"number"),!0),In),t.registerCommand(kp,()=>(p_(t,"bullet"),!0),In),t.registerCommand(WT,()=>(BT(t),!0),In),t.registerCommand(dl,()=>!!UT(),In)),[t])}(u),null}const o3=({onlUser:u,codoxStarted:t})=>{const[o]=Gn(),e=()=>{t?o.setEditable(!0):o.setEditable(!1)};return ke.jsx(zp,{onChange:e})},i3=hw([...[Sd,Ep,Qi,xl,Ws,fp,pp,gp,Rl,Dd,Dp]]);function s3({collabApiKey:u,userObj:t,styleConfig:o,docId:e,onlUser:a,setonlUser:r,savedSpfEditorState:n,setSavedEditorState:i,setSavedEditorState2:l,mentionItems:s,showtoolbar:d=!0,customHeight:c,customWidth:p,disabled:f,editorId:h,onPaste:g,source:m,useCustomOnChange:v=!1,onChangePlugin:_=ke.jsx(ke.Fragment,{}),customClassName:b="",editorForComment:S=!1,isCollab:C=!1}){const x=ve.useRef(null),[y,w]=ve.useState(!1),{pageMarginTop:E,pageMarginLeft:I,pageMarginBottom:j,pageMarginRight:B,heading:N}=o||{};ve.useState("");const[D,P]=ve.useState(!0),k=ve.useRef(null),[A,L]=ve.useState(!1),[R,J]=ve.useState([]),T=ve.useRef(),[H,W]=ve.useState({root:null});ve.useState(0);const[K,F]=ve.useState(!0),[q,$]=ve.useState(!1);let z={namespace:`editor_${h}`,nodes:[...i3],onError(se){throw se},theme:cm,editorState:se=>{se.update(()=>{if(n&&D){const Pe=new DOMParser().parseFromString(n,"text/html"),Be=Sm(se,Pe);Be.forEach(Ce=>{Ce instanceof Ws&&Ce.setStyle("font-weight: normal")}),Zn(),gc(Be),P(!1)}})}};ve.useEffect(()=>{setTimeout(()=>{kc(".custom-margin").css({paddingTop:`${E||"16px"}`,paddingRight:`${B||"16px"}`,paddingLeft:`${I||"16px"}`,paddingBottom:`${j||"16px"}`}),kc(".editor-inner").css({maxHeight:c?`${c}px`:"100%",overflow:"scroll",height:c?`${c}px`:"100%",minHeight:"200px",maxWidth:p?`${p}px`:"100%"}),kc(`.${h}`).attr("contentEditable",!f)},500)},[]);const{userName:Y,userId:G,userEmail:Z}=t,ee={docId:h,apiKey:u,user:{name:Y,id:G,email:Z},showCursor:!1,cursorAlwaysOn:!1,showPointer:!1,hooks:{contentChanged:({source:se,content:ue})=>{},usersUpdate:se=>{J(se),renderOnlineUsers(se)}}},ne=()=>{T.current&&T.current.start(ee).then(()=>{console.log("[Lexical Demo][codox.start] success"),L(!0)}).catch(se=>console.log("[Lexical Demo][codox.start] error",se))};ve.useEffect(()=>(T.current.cursor.hide(),()=>{ce()}),[]);const ce=()=>{T.current&&T.current.stop(),L(!1)};ve.useEffect(()=>{H&&e&&!A&&ne()},[H,e,A]),ve.useEffect(()=>{let se=[],ue=[];R&&R.length>0&&R.map((Pe,Be)=>{ue.includes(Pe.name)||(ue.push(Pe.name),se.push(ke.jsxs("div",{title:Pe.email,className:`avatarStyle avatar-color-${Be+1}`,children:[" ",Pe.name&&Pe.name[0],Pe.name&&Pe.name[4]]},Be)))}),r(se)},[R]);const ae=ve.useCallback(se=>{k.current&&clearTimeout(k.current),k.current=setTimeout(()=>{i(se)},500)},[h,i,l]),de=ve.useCallback(se=>{k.current&&clearTimeout(k.current),k.current=setTimeout(()=>{l(se)},500)},[h,i,l]),xe=()=>{w(!0)};return ke.jsxs("div",{ref:x,children:[ke.jsx(Rk,{children:ke.jsxs(np,{initialConfig:z,children:[ke.jsx(pw,{ref:T}),ke.jsxs("div",{className:"editor-container",children:[d&&ke.jsx("div",{style:{pointerEvents:f?"none":"all"},children:ke.jsx(JT,{openModal:xe,styleConfig:o,onlUser:a,stopCodox:ce,startCodox:ne,source:m,onPaste:g,block:K,setBlock:F,showComments:q,setShowComments:$})}),S?ke.jsx("div",{className:"CommentPlugin_CommentInputBox_EditorContainer",children:ke.jsx(oy,{contentEditable:ke.jsx(Cd,{className:b}),placeholder:null,ErrorBoundary:Ol})}):ke.jsxs("div",{className:"editor-inner",children:[ke.jsx(Op,{contentEditable:ke.jsxs("div",{className:"custom-margin",children:[ke.jsx(Cd,{className:`editor-input ${h}`,contentEditable:!1}),C===!0?ke.jsx(o3,{onlUser:a}):""]}),placeholder:null,ErrorBoundary:Ol}),ke.jsx(r3,{}),ke.jsx(Tp,{})]})]}),ke.jsx(_k,{disabled:f}),ke.jsx(nA,{disabled:f}),ke.jsx(Ok,{disabled:f}),ke.jsx(Bk,{disabled:f}),ke.jsx(Fp,{}),ke.jsx(YI,{items:s,menuComponent:ZI,menuItemComponent:QI}),v?ke.jsx(ke.Fragment,{children:_}):ke.jsx(n3,{onChange:h.includes("objective")?ae:de}),ke.jsx(t3,{showComments:q,setShowComments:$})]})}),ke.jsx(BO,{styleConfig:o})]})}const a3=hw([...[]]);function l3({collabApiKey:u,userObj:t,docId:o,setonlUser:e,savedSpfEditorState:a,setSavedEditorState:r,customHeight:n,customWidth:i,editorId:l}){const s=ve.useRef(null),[d,c]=ve.useState(!0),[p,f]=ve.useState(!1),[h,g]=ve.useState([]),m=ve.useRef(),[v,_]=ve.useState({root:null});ve.useState(0);const b=ve.useRef(""),S={namespace:`editor_${l}`,nodes:[...a3],onError(B){throw B},theme:cm,editorState:B=>{B.update(()=>{if(a&&d){const D=new DOMParser().parseFromString(a,"text/html"),P=Sm(B,D);Zn(),gc(P),c(!1)}})}};ve.useEffect(()=>{setTimeout(()=>{kc(".custom-margin-2").css({height:`${n}px`}),kc(".editor-inner-2").css({background:"#fff",position:"relative",top:"20px",padding:"20px",borderRadius:"0 0 10px 10px",maxHeight:`${n}px`,overflow:"scroll",height:`${n}px`,minHeight:"200px",maxWidth:i?`${i}px`:"100%"})},500)},[]);const{userName:C,userId:x,userEmail:y}=t,E={docId:l,apiKey:u,user:{name:C,id:x,email:y},showCursor:!1,cursorAlwaysOn:!1,showPointer:!1,hooks:{contentChanged:({source:B,content:N})=>{},usersUpdate:B=>{g(B),renderOnlineUsers(B)}}},I=()=>{m.current&&m.current.start(E).then(()=>{console.log("[Lexical Demo][codox.start] success"),f(!0)}).catch(B=>console.log("[Lexical Demo][codox.start] error",B))};ve.useEffect(()=>{v&&o&&!p&&I()},[v,o,p]),ve.useEffect(()=>{let B=[],N=[];h&&h.length>0&&h.map((D,P)=>{N.includes(D.name)||(N.push(D.name),B.push(ke.jsxs("div",{title:D.email,className:`avatarStyle avatar-color-${P+1}`,children:[" ",D.name&&D.name[0],D.name&&D.name[4]]},P)))}),e(B)},[h]);const j=()=>{let B=kc(".editor-input-2").html();B!==b.current&&(console.log("Editor Variant 2 HTML",B),r(B),b.current=B)};return ke.jsx("div",{ref:s,children:ke.jsxs(np,{initialConfig:S,children:[ke.jsx(pw,{ref:m}),ke.jsx("div",{className:"editor-container",children:ke.jsxs("div",{className:"editor-inner-2",children:[ke.jsx(Op,{contentEditable:ke.jsx("div",{className:"custom-margin-2",children:ke.jsx(Cd,{className:"editor-input-2 inpt-2"})}),placeholder:null,ErrorBoundary:Ol}),ke.jsx(zp,{onChange:j}),ke.jsx(Tp,{})]})}),ke.jsx(Fp,{})]})})}const s4="";function c3(u){return u&&u.__esModule&&Object.prototype.hasOwnProperty.call(u,"default")?u.default:u}var u3=c3(function(u){const t=new URLSearchParams;t.append("code",u);for(let o=1;o<arguments.length;o++)t.append("v",arguments[o]);throw Error(`Minified Lexical error #${u}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)});function qS(u){const t=u.transform();return t!==null?new Set([t]):new Set}function WS({initialEditor:u,children:t,initialNodes:o,initialTheme:e,skipCollabChecks:a}){const r=ve.useRef(!1),n=ve.useContext(Fu);n==null&&u3(9);const[i,{getTheme:l}]=n,s=ve.useMemo(()=>{const f=e||l()||void 0,h=ab(n,f);if(f!==void 0&&(u._config.theme=f),u._parentEditor=i,o)for(let g of o){let m=null,v=null;if(typeof g!="function"){const b=g;g=b.replace,m=b.with,v=b.withKlass||null}const _=u._nodes.get(g.getType());u._nodes.set(g.getType(),{exportDOM:_?_.exportDOM:void 0,klass:g,replace:m,replaceWithKlass:v,transforms:qS(g)})}else{const g=u._nodes=new Map(i._nodes);for(const[m,v]of g)u._nodes.set(m,{exportDOM:v.exportDOM,klass:v.klass,replace:v.replace,replaceWithKlass:v.replaceWithKlass,transforms:qS(v.klass)})}return u._config.namespace=i._config.namespace,u._editable=i._editable,[u,h]},[]),{isCollabActive:d,yjsDocMap:c}=Lp(),p=a||r.current||c.has(u.getKey());return ve.useEffect(()=>{p&&(r.current=!0)},[p]),ve.useEffect(()=>i.registerEditableListener(f=>{u.setEditable(f)}),[u,i]),ke.jsx(Fu.Provider,{value:s,children:!d||p?t:null})}function n0(u,t,o){return Math.min(Math.max(u,t),o)}const Nr={east:1,north:8,south:2,west:4};function d3({onResizeStart:u,onResizeEnd:t,buttonRef:o,imageRef:e,maxWidth:a,editor:r,showCaption:n,setShowCaption:i,captionsEnabled:l}){const s=ve.useRef(null),d=ve.useRef({priority:"",value:"default"}),c=ve.useRef({currentHeight:0,currentWidth:0,direction:0,isResizing:!1,ratio:0,startHeight:0,startWidth:0,startX:0,startY:0}),p=r.getRootElement(),f=p!==null?p.getBoundingClientRect().width-20:100,h=p!==null?p.getBoundingClientRect().height-20:100,g=100,m=100,v=x=>{const y=x===Nr.east||x===Nr.west,w=x===Nr.north||x===Nr.south,E=x&Nr.north&&x&Nr.west||x&Nr.south&&x&Nr.east,I=y?"ew":w?"ns":E?"nwse":"nesw";p!==null&&p.style.setProperty("cursor",`${I}-resize`,"important"),document.body!==null&&(document.body.style.setProperty("cursor",`${I}-resize`,"important"),d.current.value=document.body.style.getPropertyValue("-webkit-user-select"),d.current.priority=document.body.style.getPropertyPriority("-webkit-user-select"),document.body.style.setProperty("-webkit-user-select","none","important"))},_=()=>{p!==null&&p.style.setProperty("cursor","text"),document.body!==null&&(document.body.style.setProperty("cursor","default"),document.body.style.setProperty("-webkit-user-select",d.current.value,d.current.priority))},b=(x,y)=>{if(!r.isEditable())return;const w=e.current,E=s.current;if(w!==null&&E!==null){x.preventDefault();const{width:I,height:j}=w.getBoundingClientRect(),B=c.current;B.startWidth=I,B.startHeight=j,B.ratio=I/j,B.currentWidth=I,B.currentHeight=j,B.startX=x.clientX,B.startY=x.clientY,B.isResizing=!0,B.direction=y,v(y),u(),E.classList.add("image-control-wrapper--resizing"),w.style.height=`${j}px`,w.style.width=`${I}px`,document.addEventListener("pointermove",S),document.addEventListener("pointerup",C)}},S=x=>{const y=e.current,w=c.current,E=w.direction&(Nr.east|Nr.west),I=w.direction&(Nr.south|Nr.north);if(y!==null&&w.isResizing){if(E&&I){let j=Math.floor(w.startX-x.clientX);j=w.direction&Nr.east?-j:j;const B=n0(w.startWidth+j,g,f),N=B/w.ratio;y.style.width=`${B}px`,y.style.height=`${N}px`,w.currentHeight=N,w.currentWidth=B}else if(I){let j=Math.floor(w.startY-x.clientY);j=w.direction&Nr.south?-j:j;const B=n0(w.startHeight+j,m,h);y.style.height=`${B}px`,y.style.maxHeight=`${B}px`,w.currentHeight=B}else{let j=Math.floor(w.startX-x.clientX);j=w.direction&Nr.east?-j:j;const B=n0(w.startWidth+j,g,f);y.style.width=`${B}px`,y.style.maxWidth=`${B}px`,w.currentWidth=B}y&&(y.setAttribute("width",`${w.currentWidth}`),y.setAttribute("height",`${w.currentHeight}`))}},C=()=>{const x=e.current,y=c.current,w=s.current;if(x!==null&&w!==null&&y.isResizing){const E=y.currentWidth,I=y.currentHeight;y.startWidth=0,y.startHeight=0,y.ratio=0,y.startX=0,y.startY=0,y.currentWidth=0,y.currentHeight=0,y.isResizing=!1,w.classList.remove("image-control-wrapper--resizing"),_(),t(E,I),document.removeEventListener("pointermove",S),document.removeEventListener("pointerup",C)}};return ke.jsxs("div",{ref:s,children:[ke.jsx("div",{className:"image-resizer image-resizer-n",onPointerDown:x=>{b(x,Nr.north)}}),ke.jsx("div",{className:"image-resizer image-resizer-ne",onPointerDown:x=>{b(x,Nr.north|Nr.east)}}),ke.jsx("div",{className:"image-resizer image-resizer-e",onPointerDown:x=>{b(x,Nr.east)}}),ke.jsx("div",{className:"image-resizer image-resizer-se",onPointerDown:x=>{b(x,Nr.south|Nr.east)}}),ke.jsx("div",{className:"image-resizer image-resizer-s",onPointerDown:x=>{b(x,Nr.south)}}),ke.jsx("div",{className:"image-resizer image-resizer-sw",onPointerDown:x=>{b(x,Nr.south|Nr.west)}}),ke.jsx("div",{className:"image-resizer image-resizer-w",onPointerDown:x=>{b(x,Nr.west)}}),ke.jsx("div",{className:"image-resizer image-resizer-nw",onPointerDown:x=>{b(x,Nr.north|Nr.west)}})]})}const a4="";function VS({children:u,className:t}){return ke.jsx("div",{className:t||"Placeholder__root",children:u})}const Ah={x:0,y:0,width:0,height:0,unit:"px"},fu=(u,t,o)=>Math.min(Math.max(u,t),o),f3=(...u)=>u.filter(t=>t&&typeof t=="string").join(" "),JS=(u,t)=>u===t||u.width===t.width&&u.height===t.height&&u.x===t.x&&u.y===t.y&&u.unit===t.unit;function pu(u,t,o){return u.unit==="%"?{...Ah,...u,unit:"%"}:{unit:"%",x:u.x?u.x/t*100:0,y:u.y?u.y/o*100:0,width:u.width?u.width/t*100:0,height:u.height?u.height/o*100:0}}function qa(u,t,o){return u.unit?u.unit==="px"?{...Ah,...u,unit:"px"}:{unit:"px",x:u.x?u.x*t/100:0,y:u.y?u.y*o/100:0,width:u.width?u.width*t/100:0,height:u.height?u.height*o/100:0}:{...Ah,...u,unit:"px"}}function KS(u,t,o,e,a,r=0,n=0,i=e,l=a){const s={...u};let d=Math.min(r,e),c=Math.min(n,a),p=Math.min(i,e),f=Math.min(l,a);t&&(t>1?(d=n?n*t:d,c=d/t,p=i*t):(c=r?r/t:c,d=c*t,f=l/t)),s.y<0&&(s.height=Math.max(s.height+s.y,c),s.y=0),s.x<0&&(s.width=Math.max(s.width+s.x,d),s.x=0);const h=e-(s.x+s.width);h<0&&(s.x=Math.min(s.x,e-d),s.width+=h);const g=a-(s.y+s.height);if(g<0&&(s.y=Math.min(s.y,a-c),s.height+=g),s.width<d&&((o==="sw"||o=="nw")&&(s.x-=d-s.width),s.width=d),s.height<c&&((o==="nw"||o=="ne")&&(s.y-=c-s.height),s.height=c),s.width>p&&((o==="sw"||o=="nw")&&(s.x-=p-s.width),s.width=p),s.height>f&&((o==="nw"||o=="ne")&&(s.y-=f-s.height),s.height=f),t){const m=s.width/s.height;if(m<t){const v=Math.max(s.width/t,c);(o==="nw"||o=="ne")&&(s.y-=v-s.height),s.height=v}else if(m>t){const v=Math.max(s.height*t,d);(o==="sw"||o=="nw")&&(s.x-=v-s.width),s.width=v}}return s}function p3(u,t,o,e){const a={...u};return t==="ArrowLeft"?e==="nw"?(a.x-=o,a.y-=o,a.width+=o,a.height+=o):e==="w"?(a.x-=o,a.width+=o):e==="sw"?(a.x-=o,a.width+=o,a.height+=o):e==="ne"?(a.y+=o,a.width-=o,a.height-=o):e==="e"?a.width-=o:e==="se"&&(a.width-=o,a.height-=o):t==="ArrowRight"&&(e==="nw"?(a.x+=o,a.y+=o,a.width-=o,a.height-=o):e==="w"?(a.x+=o,a.width-=o):e==="sw"?(a.x+=o,a.width-=o,a.height-=o):e==="ne"?(a.y-=o,a.width+=o,a.height+=o):e==="e"?a.width+=o:e==="se"&&(a.width+=o,a.height+=o)),t==="ArrowUp"?e==="nw"?(a.x-=o,a.y-=o,a.width+=o,a.height+=o):e==="n"?(a.y-=o,a.height+=o):e==="ne"?(a.y-=o,a.width+=o,a.height+=o):e==="sw"?(a.x+=o,a.width-=o,a.height-=o):e==="s"?a.height-=o:e==="se"&&(a.width-=o,a.height-=o):t==="ArrowDown"&&(e==="nw"?(a.x+=o,a.y+=o,a.width-=o,a.height-=o):e==="n"?(a.y+=o,a.height-=o):e==="ne"?(a.y+=o,a.width-=o,a.height-=o):e==="sw"?(a.x-=o,a.width+=o,a.height+=o):e==="s"?a.height+=o:e==="se"&&(a.width+=o,a.height+=o)),a}const hu={capture:!0,passive:!1};let h3=0;const Wa=class us extends ve.PureComponent{constructor(){super(...arguments),this.docMoveBound=!1,this.mouseDownOnCrop=!1,this.dragStarted=!1,this.evData={startClientX:0,startClientY:0,startCropX:0,startCropY:0,clientX:0,clientY:0,isResize:!0},this.componentRef=ve.createRef(),this.mediaRef=ve.createRef(),this.initChangeCalled=!1,this.instanceId=`rc-${h3++}`,this.state={cropIsActive:!1,newCropIsBeingDrawn:!1},this.onCropPointerDown=t=>{const{crop:o,disabled:e}=this.props,a=this.getBox();if(!o)return;const r=qa(o,a.width,a.height);if(e)return;t.cancelable&&t.preventDefault(),this.bindDocMove(),this.componentRef.current.focus({preventScroll:!0});const n=t.target.dataset.ord,i=!!n;let l=t.clientX,s=t.clientY,d=r.x,c=r.y;if(n){const p=t.clientX-a.x,f=t.clientY-a.y;let h=0,g=0;n==="ne"||n=="e"?(h=p-(r.x+r.width),g=f-r.y,d=r.x,c=r.y+r.height):n==="se"||n==="s"?(h=p-(r.x+r.width),g=f-(r.y+r.height),d=r.x,c=r.y):n==="sw"||n=="w"?(h=p-r.x,g=f-(r.y+r.height),d=r.x+r.width,c=r.y):(n==="nw"||n=="n")&&(h=p-r.x,g=f-r.y,d=r.x+r.width,c=r.y+r.height),l=d+a.x+h,s=c+a.y+g}this.evData={startClientX:l,startClientY:s,startCropX:d,startCropY:c,clientX:t.clientX,clientY:t.clientY,isResize:i,ord:n},this.mouseDownOnCrop=!0,this.setState({cropIsActive:!0})},this.onComponentPointerDown=t=>{const{crop:o,disabled:e,locked:a,keepSelection:r,onChange:n}=this.props,i=this.getBox();if(e||a||r&&o)return;t.cancelable&&t.preventDefault(),this.bindDocMove(),this.componentRef.current.focus({preventScroll:!0});const l=t.clientX-i.x,s=t.clientY-i.y,d={unit:"px",x:l,y:s,width:0,height:0};this.evData={startClientX:t.clientX,startClientY:t.clientY,startCropX:l,startCropY:s,clientX:t.clientX,clientY:t.clientY,isResize:!0},this.mouseDownOnCrop=!0,n(qa(d,i.width,i.height),pu(d,i.width,i.height)),this.setState({cropIsActive:!0,newCropIsBeingDrawn:!0})},this.onDocPointerMove=t=>{const{crop:o,disabled:e,onChange:a,onDragStart:r}=this.props,n=this.getBox();if(e||!o||!this.mouseDownOnCrop)return;t.cancelable&&t.preventDefault(),this.dragStarted||(this.dragStarted=!0,r&&r(t));const{evData:i}=this;i.clientX=t.clientX,i.clientY=t.clientY;let l;i.isResize?l=this.resizeCrop():l=this.dragCrop(),JS(o,l)||a(qa(l,n.width,n.height),pu(l,n.width,n.height))},this.onComponentKeyDown=t=>{const{crop:o,disabled:e,onChange:a,onComplete:r}=this.props;if(e)return;const n=t.key;let i=!1;if(!o)return;const l=this.getBox(),s=this.makePixelCrop(l),d=(navigator.platform.match("Mac")?t.metaKey:t.ctrlKey)?us.nudgeStepLarge:t.shiftKey?us.nudgeStepMedium:us.nudgeStep;if(n==="ArrowLeft"?(s.x-=d,i=!0):n==="ArrowRight"?(s.x+=d,i=!0):n==="ArrowUp"?(s.y-=d,i=!0):n==="ArrowDown"&&(s.y+=d,i=!0),i){t.cancelable&&t.preventDefault(),s.x=fu(s.x,0,l.width-s.width),s.y=fu(s.y,0,l.height-s.height);const c=qa(s,l.width,l.height),p=pu(s,l.width,l.height);a(c,p),r&&r(c,p)}},this.onHandlerKeyDown=(t,o)=>{const{aspect:e=0,crop:a,disabled:r,minWidth:n=0,minHeight:i=0,maxWidth:l,maxHeight:s,onChange:d,onComplete:c}=this.props,p=this.getBox();if(r||!a)return;if(t.key==="ArrowUp"||t.key==="ArrowDown"||t.key==="ArrowLeft"||t.key==="ArrowRight")t.stopPropagation(),t.preventDefault();else return;const f=(navigator.platform.match("Mac")?t.metaKey:t.ctrlKey)?us.nudgeStepLarge:t.shiftKey?us.nudgeStepMedium:us.nudgeStep,h=qa(a,p.width,p.height),g=p3(h,t.key,f,o),m=KS(g,e,o,p.width,p.height,n,i,l,s);if(!JS(a,m)){const v=pu(m,p.width,p.height);d(m,v),c&&c(m,v)}},this.onDocPointerDone=t=>{const{crop:o,disabled:e,onComplete:a,onDragEnd:r}=this.props,n=this.getBox();this.unbindDocMove(),!(e||!o)&&this.mouseDownOnCrop&&(this.mouseDownOnCrop=!1,this.dragStarted=!1,r&&r(t),a&&a(qa(o,n.width,n.height),pu(o,n.width,n.height)),this.setState({cropIsActive:!1,newCropIsBeingDrawn:!1}))},this.onDragFocus=()=>{var t;(t=this.componentRef.current)==null||t.scrollTo(0,0)}}get document(){return document}getBox(){const t=this.mediaRef.current;if(!t)return{x:0,y:0,width:0,height:0};const{x:o,y:e,width:a,height:r}=t.getBoundingClientRect();return{x:o,y:e,width:a,height:r}}componentDidUpdate(t){const{crop:o,onComplete:e}=this.props;if(e&&!t.crop&&o){const{width:a,height:r}=this.getBox();a&&r&&e(qa(o,a,r),pu(o,a,r))}}componentWillUnmount(){this.resizeObserver&&this.resizeObserver.disconnect(),this.unbindDocMove()}bindDocMove(){this.docMoveBound||(this.document.addEventListener("pointermove",this.onDocPointerMove,hu),this.document.addEventListener("pointerup",this.onDocPointerDone,hu),this.document.addEventListener("pointercancel",this.onDocPointerDone,hu),this.docMoveBound=!0)}unbindDocMove(){this.docMoveBound&&(this.document.removeEventListener("pointermove",this.onDocPointerMove,hu),this.document.removeEventListener("pointerup",this.onDocPointerDone,hu),this.document.removeEventListener("pointercancel",this.onDocPointerDone,hu),this.docMoveBound=!1)}getCropStyle(){const{crop:t}=this.props;if(t)return{top:`${t.y}${t.unit}`,left:`${t.x}${t.unit}`,width:`${t.width}${t.unit}`,height:`${t.height}${t.unit}`}}dragCrop(){const{evData:t}=this,o=this.getBox(),e=this.makePixelCrop(o),a=t.clientX-t.startClientX,r=t.clientY-t.startClientY;return e.x=fu(t.startCropX+a,0,o.width-e.width),e.y=fu(t.startCropY+r,0,o.height-e.height),e}getPointRegion(t,o,e,a){const{evData:r}=this,n=r.clientX-t.x,i=r.clientY-t.y;let l;a&&o?l=o==="nw"||o==="n"||o==="ne":l=i<r.startCropY;let s;return e&&o?s=o==="nw"||o==="w"||o==="sw":s=n<r.startCropX,s?l?"nw":"sw":l?"ne":"se"}resolveMinDimensions(t,o,e=0,a=0){const r=Math.min(e,t.width),n=Math.min(a,t.height);return!o||!r&&!n?[r,n]:o>1?r?[r,r/o]:[n*o,n]:n?[n*o,n]:[r,r/o]}resizeCrop(){const{evData:t}=this,{aspect:o=0,maxWidth:e,maxHeight:a}=this.props,r=this.getBox(),[n,i]=this.resolveMinDimensions(r,o,this.props.minWidth,this.props.minHeight);let l=this.makePixelCrop(r);const s=this.getPointRegion(r,t.ord,n,i),d=t.ord||s;let c=t.clientX-t.startClientX,p=t.clientY-t.startClientY;(n&&d==="nw"||d==="w"||d==="sw")&&(c=Math.min(c,-n)),(i&&d==="nw"||d==="n"||d==="ne")&&(p=Math.min(p,-i));const f={unit:"px",x:0,y:0,width:0,height:0};s==="ne"?(f.x=t.startCropX,f.width=c,o?(f.height=f.width/o,f.y=t.startCropY-f.height):(f.height=Math.abs(p),f.y=t.startCropY-f.height)):s==="se"?(f.x=t.startCropX,f.y=t.startCropY,f.width=c,o?f.height=f.width/o:f.height=p):s==="sw"?(f.x=t.startCropX+c,f.y=t.startCropY,f.width=Math.abs(c),o?f.height=f.width/o:f.height=p):s==="nw"&&(f.x=t.startCropX+c,f.width=Math.abs(c),o?(f.height=f.width/o,f.y=t.startCropY-f.height):(f.height=Math.abs(p),f.y=t.startCropY+p));const h=KS(f,o,s,r.width,r.height,n,i,e,a);return o||us.xyOrds.indexOf(d)>-1?l=h:us.xOrds.indexOf(d)>-1?(l.x=h.x,l.width=h.width):us.yOrds.indexOf(d)>-1&&(l.y=h.y,l.height=h.height),l.x=fu(l.x,0,r.width-l.width),l.y=fu(l.y,0,r.height-l.height),l}renderCropSelection(){const{ariaLabels:t=us.defaultProps.ariaLabels,disabled:o,locked:e,renderSelectionAddon:a,ruleOfThirds:r,crop:n}=this.props,i=this.getCropStyle();if(n)return ve.createElement("div",{style:i,className:"ReactCrop__crop-selection",onPointerDown:this.onCropPointerDown,"aria-label":t.cropArea,tabIndex:0,onKeyDown:this.onComponentKeyDown,role:"group"},!o&&!e&&ve.createElement("div",{className:"ReactCrop__drag-elements",onFocus:this.onDragFocus},ve.createElement("div",{className:"ReactCrop__drag-bar ord-n","data-ord":"n"}),ve.createElement("div",{className:"ReactCrop__drag-bar ord-e","data-ord":"e"}),ve.createElement("div",{className:"ReactCrop__drag-bar ord-s","data-ord":"s"}),ve.createElement("div",{className:"ReactCrop__drag-bar ord-w","data-ord":"w"}),ve.createElement("div",{className:"ReactCrop__drag-handle ord-nw","data-ord":"nw",tabIndex:0,"aria-label":t.nwDragHandle,onKeyDown:l=>this.onHandlerKeyDown(l,"nw"),role:"button"}),ve.createElement("div",{className:"ReactCrop__drag-handle ord-n","data-ord":"n",tabIndex:0,"aria-label":t.nDragHandle,onKeyDown:l=>this.onHandlerKeyDown(l,"n"),role:"button"}),ve.createElement("div",{className:"ReactCrop__drag-handle ord-ne","data-ord":"ne",tabIndex:0,"aria-label":t.neDragHandle,onKeyDown:l=>this.onHandlerKeyDown(l,"ne"),role:"button"}),ve.createElement("div",{className:"ReactCrop__drag-handle ord-e","data-ord":"e",tabIndex:0,"aria-label":t.eDragHandle,onKeyDown:l=>this.onHandlerKeyDown(l,"e"),role:"button"}),ve.createElement("div",{className:"ReactCrop__drag-handle ord-se","data-ord":"se",tabIndex:0,"aria-label":t.seDragHandle,onKeyDown:l=>this.onHandlerKeyDown(l,"se"),role:"button"}),ve.createElement("div",{className:"ReactCrop__drag-handle ord-s","data-ord":"s",tabIndex:0,"aria-label":t.sDragHandle,onKeyDown:l=>this.onHandlerKeyDown(l,"s"),role:"button"}),ve.createElement("div",{className:"ReactCrop__drag-handle ord-sw","data-ord":"sw",tabIndex:0,"aria-label":t.swDragHandle,onKeyDown:l=>this.onHandlerKeyDown(l,"sw"),role:"button"}),ve.createElement("div",{className:"ReactCrop__drag-handle ord-w","data-ord":"w",tabIndex:0,"aria-label":t.wDragHandle,onKeyDown:l=>this.onHandlerKeyDown(l,"w"),role:"button"})),a&&ve.createElement("div",{className:"ReactCrop__selection-addon",onPointerDown:l=>l.stopPropagation()},a(this.state)),r&&ve.createElement(ve.Fragment,null,ve.createElement("div",{className:"ReactCrop__rule-of-thirds-hz"}),ve.createElement("div",{className:"ReactCrop__rule-of-thirds-vt"})))}makePixelCrop(t){const o={...Ah,...this.props.crop||{}};return qa(o,t.width,t.height)}render(){const{aspect:t,children:o,circularCrop:e,className:a,crop:r,disabled:n,locked:i,style:l,ruleOfThirds:s}=this.props,{cropIsActive:d,newCropIsBeingDrawn:c}=this.state,p=r?this.renderCropSelection():null,f=f3("ReactCrop",a,d&&"ReactCrop--active",n&&"ReactCrop--disabled",i&&"ReactCrop--locked",c&&"ReactCrop--new-crop",r&&t&&"ReactCrop--fixed-aspect",r&&e&&"ReactCrop--circular-crop",r&&s&&"ReactCrop--rule-of-thirds",!this.dragStarted&&r&&!r.width&&!r.height&&"ReactCrop--invisible-crop",e&&"ReactCrop--no-animate");return ve.createElement("div",{ref:this.componentRef,className:f,style:l},ve.createElement("div",{ref:this.mediaRef,className:"ReactCrop__child-wrapper",onPointerDown:this.onComponentPointerDown},o),r?ve.createElement("svg",{className:"ReactCrop__crop-mask",width:"100%",height:"100%"},ve.createElement("defs",null,ve.createElement("mask",{id:`hole-${this.instanceId}`},ve.createElement("rect",{width:"100%",height:"100%",fill:"white"}),e?ve.createElement("ellipse",{cx:`${r.x+r.width/2}${r.unit}`,cy:`${r.y+r.height/2}${r.unit}`,rx:`${r.width/2}${r.unit}`,ry:`${r.height/2}${r.unit}`,fill:"black"}):ve.createElement("rect",{x:`${r.x}${r.unit}`,y:`${r.y}${r.unit}`,width:`${r.width}${r.unit}`,height:`${r.height}${r.unit}`,fill:"black"}))),ve.createElement("rect",{fill:"black",fillOpacity:.5,width:"100%",height:"100%",mask:`url(#hole-${this.instanceId})`})):void 0,p)}};Wa.xOrds=["e","w"],Wa.yOrds=["n","s"],Wa.xyOrds=["nw","ne","se","sw"],Wa.nudgeStep=1,Wa.nudgeStepMedium=10,Wa.nudgeStepLarge=100,Wa.defaultProps={ariaLabels:{cropArea:"Use the arrow keys to move the crop selection area",nwDragHandle:"Use the arrow keys to move the north west drag handle to change the crop selection area",nDragHandle:"Use the up and down arrow keys to move the north drag handle to change the crop selection area",neDragHandle:"Use the arrow keys to move the north east drag handle to change the crop selection area",eDragHandle:"Use the up and down arrow keys to move the east drag handle to change the crop selection area",seDragHandle:"Use the arrow keys to move the south east drag handle to change the crop selection area",sDragHandle:"Use the up and down arrow keys to move the south drag handle to change the crop selection area",swDragHandle:"Use the arrow keys to move the south west drag handle to change the crop selection area",wDragHandle:"Use the up and down arrow keys to move the west drag handle to change the crop selection area"}};let g3=Wa;const l4="",r0=jo();function m3({altText:u,className:t,src:o,width:e,height:a,maxWidth:r,imageRef:n,startCrop:i,setStartCrop:l,isFocused:s,nodeKey:d}){const[c,p]=ve.useState(null),[f,h]=ve.useState(null),[g,m]=ve.useState({unit:"px",x:25,y:25,width:50,height:50}),[v]=Gn(),_=()=>{if(c){const y=n.current;if(!y||!c)return;const w=y.naturalWidth/y.width,E=y.naturalHeight/y.height,I=new OffscreenCanvas(c.width*w,c.height*E),j=I.getContext("2d");if(!j)throw new Error("No 2D context available");j.drawImage(y,c.x*w,c.y*E,c.width*w,c.height*E,0,0,c.width*w,c.height*E),I.convertToBlob({type:"image/png"}).then(B=>{const N=URL.createObjectURL(B);h(N),l(!1);const D=new FileReader;D.onload=()=>{const P=D.result;v.update(()=>{const k=Qn(d);xc(k)&&P&&k.setSrc(P)})},D.onerror=()=>{console.log("error")},D.readAsDataURL(B)})}},b=()=>{i||l(y=>{if(y===!1){const w=n.current;m({unit:"px",x:0,y:0,width:w.width,height:w.height})}return!y})},S=ve.useRef(null),C=ve.useRef(null);ve.useEffect(()=>{c&&(S.current=c)},[c]);const x=y=>{C.current&&!C.current.contains(y.target)&&l(!1)};return ve.useEffect(()=>(document.addEventListener("mousedown",x),()=>{document.removeEventListener("mousedown",x)}),[]),ke.jsxs("div",{ref:C,children:[s&&ke.jsx("button",{style:{zIndex:999},className:"image-caption-button",onClick:()=>b(),children:"Crop"}),i&&ke.jsx("button",{style:{zIndex:999},className:"image-caption-button",onClick:()=>_(),children:"Apply Crop"}),i?ke.jsx(g3,{crop:g,onChange:y=>m(y),onComplete:y=>p(y),children:ke.jsx("img",{className:t||void 0,src:f||o,alt:u,ref:n,style:{height:a,maxWidth:r,width:e},draggable:"false"})}):ke.jsx("img",{className:t||void 0,src:f||o,alt:u,ref:n,style:{height:a,maxWidth:r,width:e},draggable:"false"})]})}function y3({src:u,altText:t,nodeKey:o,width:e,height:a,maxWidth:r,resizable:n,showCaption:i,caption:l}){const s=ve.useRef(null),d=ve.useRef(null),[c,p,f]=oh(o),[h,g]=ve.useState(!1),[m]=Gn(),[v,_]=ve.useState(null),[b,S]=ve.useState(!1),C=ve.useRef(null),x=async A=>{const R=await(await fetch(A)).blob();return new Promise((J,T)=>{const H=new FileReader;H.readAsDataURL(R),H.onloadend=()=>{const W=H.result;J(W)},H.onerror=T})};ve.useEffect(()=>{/^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/i.test(u)&&x(u).then(L=>{m.update(()=>{const R=Qn(o);xc(R)&&L&&R.setSrc(L)})})},[u]);const y=ve.useCallback(A=>{if(c&&pr(Ot())){A.preventDefault();const R=Qn(o);if(xc(R))return R.remove(),!0}return!1},[c,o]),w=ve.useCallback(A=>{const L=Ot(),R=d.current;if(c&&pr(L)&&L.getNodes().length===1){if(i)return nr(null),A.preventDefault(),l.focus(),!0;if(R!==null&&R!==document.activeElement)return A.preventDefault(),R.focus(),!0}return!1},[l,c,i]),E=ve.useCallback(A=>C.current===l||d.current===A.target?(nr(null),m.update(()=>{p(!0);const L=m.getRootElement();L!==null&&L.focus()}),!0):!1,[l,m,p]),I=ve.useCallback(A=>{const L=A;return h?!0:L.target===s.current?(L.shiftKey?p(!c):(f(),p(!0)),!0):!1},[h,c,p,f]),j=ve.useCallback(A=>{m.getEditorState().read(()=>{const L=Ot();A.target.tagName==="IMG"&&xt(L)&&L.getNodes().length===1&&m.dispatchCommand(r0,A)})},[m]);ve.useEffect(()=>{let A=!0;const L=m.getRootElement(),R=Br(m.registerUpdateListener(({editorState:J})=>{A&&_(J.read(()=>Ot()))}),m.registerCommand(ti,(J,T)=>(C.current=T,!1),In),m.registerCommand(ma,I,In),m.registerCommand(r0,I,In),m.registerCommand(pl,J=>J.target===s.current?(J.preventDefault(),!0):!1,In),m.registerCommand(zs,y,In),m.registerCommand(Vi,y,In),m.registerCommand(ds,w,In),m.registerCommand(Fs,E,In));return L==null||L.addEventListener("contextmenu",j),()=>{A=!1,R(),L==null||L.removeEventListener("contextmenu",j)}},[f,m,h,c,o,y,w,E,I,j,p]);const B=()=>{m.update(()=>{const A=Qn(o);xc(A)&&A.setShowCaption(!0)})},N=(A,L)=>{setTimeout(()=>{g(!1)},200),m.update(()=>{const R=Qn(o);console.log(R,"node"),xc(R)&&R.setWidthAndHeight(A,L)})},D=()=>{b||g(!0)},P=c&&pr(v)&&!h,k=c||h;return ke.jsx(ve.Suspense,{fallback:null,children:ke.jsxs(ke.Fragment,{children:[ke.jsx("div",{draggable:P,children:ke.jsx(m3,{className:k?`focused ${pr(v)?"draggable":""}`:null,src:u,altText:t,width:e,height:a,maxWidth:r,imageRef:s,startCrop:b,setStartCrop:S,isFocused:k,nodeKey:o})}),i&&ke.jsx("div",{className:"image-caption-container",children:ke.jsx(WS,{initialEditor:l,children:ke.jsx(Op,{contentEditable:ke.jsx(t0,{className:"ImageNode__contentEditable"}),placeholder:ke.jsx(VS,{className:"ImageNode__placeholder",children:"Enter a caption..."}),ErrorBoundary:Ol})})}),!b&&n&&pr(v)&&k&&ke.jsx(d3,{showCaption:i,setShowCaption:B,editor:m,buttonRef:d,maxWidth:r,onResizeStart:b?()=>{}:D,onResizeEnd:b?()=>{}:N,captionsEnabled:!1,imageRef:s})]})})}const b3=Object.freeze(Object.defineProperty({__proto__:null,RIGHT_CLICK_IMAGE_COMMAND:r0,default:y3},Symbol.toStringTag,{value:"Module"})),GS=new Set;function v3(u){if(!GS.has(u))throw new Promise(t=>{const o=new Image;o.src=u,o.onload=()=>{GS.add(u),t(null)}})}function _3({altText:u,className:t,imageRef:o,src:e,width:a,height:r,position:n}){return v3(e),ke.jsx("img",{className:t||void 0,src:e,alt:u,ref:o,"data-position":n,style:{display:"block",height:r,width:a},draggable:"false"})}function YS({activeEditor:u,nodeKey:t,onClose:o}){const a=u.getEditorState().read(()=>Qn(t)),[r,n]=ve.useState(a.getAltText()),[i,l]=ve.useState(a.getShowCaption()),[s,d]=ve.useState(a.getPosition()),c=h=>{l(h.target.checked)},p=h=>{d(h.target.value)},f=()=>{const h={altText:r,position:s,showCaption:i};a&&u.update(()=>{a.update(h)}),o()};return ke.jsxs(ke.Fragment,{children:[ke.jsx("div",{style:{marginBottom:"1em"},children:ke.jsx(C1,{label:"Alt Text",placeholder:"Descriptive alternative text",onChange:n,value:r,"data-test-id":"image-modal-alt-text-input"})}),ke.jsxs(Dk,{style:{marginBottom:"1em",width:"208px"},value:s,label:"Position",name:"position",id:"position-select",onChange:p,children:[ke.jsx("option",{value:"left",children:"Left"}),ke.jsx("option",{value:"right",children:"Right"}),ke.jsx("option",{value:"full",children:"Full Width"})]}),ke.jsxs("div",{className:"Input__wrapper",children:[ke.jsx("input",{id:"caption",type:"checkbox",checked:i,onChange:c}),ke.jsx("label",{htmlFor:"caption",children:"Show Caption"})]}),ke.jsx(E1,{children:ke.jsx(Vs,{"data-test-id":"image-modal-file-upload-btn",onClick:()=>f(),children:"Confirm"})})]})}function x3({src:u,altText:t,nodeKey:o,width:e,height:a,showCaption:r,caption:n,position:i}){const[l,s]=Sp(),d=ve.useRef(null),c=ve.useRef(null),[p,f,h]=oh(o),[g]=Gn(),[m,v]=ve.useState(null),_=ve.useRef(null),b=ve.useCallback(w=>{if(p&&pr(Ot())){w.preventDefault();const I=Qn(o);if(a1(I))return I.remove(),!0}return!1},[p,o]),S=ve.useCallback(w=>{const E=Ot(),I=c.current;if(p&&pr(E)&&E.getNodes().length===1){if(r)return nr(null),w.preventDefault(),n.focus(),!0;if(I!==null&&I!==document.activeElement)return w.preventDefault(),I.focus(),!0}return!1},[n,p,r]),C=ve.useCallback(w=>_.current===n||c.current===w.target?(nr(null),g.update(()=>{f(!0);const E=g.getRootElement();E!==null&&E.focus()}),!0):!1,[n,g,f]);ve.useEffect(()=>{let w=!0;const E=Br(g.registerUpdateListener(({editorState:I})=>{w&&v(I.read(()=>Ot()))}),g.registerCommand(ti,(I,j)=>(_.current=j,!1),In),g.registerCommand(ma,I=>{const j=I;return j.target===d.current?(j.shiftKey?f(!p):(h(),f(!0)),!0):!1},In),g.registerCommand(pl,I=>I.target===d.current?(I.preventDefault(),!0):!1,In),g.registerCommand(zs,b,In),g.registerCommand(Vi,b,In),g.registerCommand(ds,S,In),g.registerCommand(Fs,C,In));return()=>{w=!1,E()}},[h,g,p,o,b,S,C,f]);const x=p&&pr(m),y=p;return ke.jsxs(ve.Suspense,{fallback:null,children:[ke.jsxs(ke.Fragment,{children:[ke.jsxs("div",{draggable:x,children:[ke.jsx("button",{className:"image-edit-button",ref:c,onClick:()=>{s("Update Inline Image",w=>ke.jsx(YS,{activeEditor:g,nodeKey:o,onClose:w}))},children:"Edit"}),ke.jsx(_3,{className:y?`focused ${pr(m)?"draggable":""}`:null,src:u,altText:t,imageRef:d,width:e,height:a,position:i})]}),r&&ke.jsx("div",{className:"image-caption-container",children:ke.jsx(WS,{initialEditor:n,children:ke.jsx(Op,{contentEditable:ke.jsx(t0,{className:"InlineImageNode__contentEditable"}),placeholder:ke.jsx(VS,{className:"InlineImageNode__placeholder",children:"Enter a caption..."}),ErrorBoundary:Ol})})})]}),l]})}const w3=Object.freeze(Object.defineProperty({__proto__:null,UpdateInlineImageDialog:YS,default:x3},Symbol.toStringTag,{value:"Module"}));Ho.Editor=s3,Ho.EditorVariant2=l3,Object.defineProperty(Ho,Symbol.toStringTag,{value:"Module"})});
1517
+ `?n.insert.slice(0,-1):n.insert;(typeof i!="string"||i.length>0)&&Qy(e,this,a,i,n.attributes||{})}else n.retain!==void 0?TS(e,this,a,n.retain,n.attributes||{}):n.delete!==void 0&&NS(e,a,n.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,o,e){this.doc??Mo();const a=[],r=new Map,n=this.doc;let i="",l=this._start;function s(){if(i.length>0){const c={};let p=!1;r.forEach((h,g)=>{p=!0,c[g]=h});const f={insert:i};p&&(f.attributes=c),a.push(f),i=""}}const d=()=>{for(;l!==null;){if(su(l,t)||o!==void 0&&su(l,o))switch(l.content.constructor){case sa:{const c=r.get("ychange");t!==void 0&&!su(l,t)?(c===void 0||c.user!==l.id.client||c.type!=="removed")&&(s(),r.set("ychange",e?e("removed",l.id):{type:"removed"})):o!==void 0&&!su(l,o)?(c===void 0||c.user!==l.id.client||c.type!=="added")&&(s(),r.set("ychange",e?e("added",l.id):{type:"added"})):c!==void 0&&(s(),r.delete("ychange")),i+=l.content.str;break}case $a:case uu:{s();const c={insert:l.content.getContent()[0]};if(r.size>0){const p={};c.attributes=p,r.forEach((f,h)=>{p[h]=f})}a.push(c);break}case _o:su(l,t)&&(s(),lu(r,l.content));break}l=l.right}s()};return t||o?Lr(n,c=>{t&&qy(c,t),o&&qy(c,o),d()},"cleanup"):d(),a}insert(t,o,e){if(o.length<=0)return;const a=this.doc;a!==null?Lr(a,r=>{const n=Sh(r,this,t,!e);e||(e={},n.currentAttributes.forEach((i,l)=>{e[l]=i})),Qy(r,this,n,o,e)}):this._pending.push(()=>this.insert(t,o,e))}insertEmbed(t,o,e){const a=this.doc;a!==null?Lr(a,r=>{const n=Sh(r,this,t,!e);Qy(r,this,n,o,e||{})}):this._pending.push(()=>this.insertEmbed(t,o,e||{}))}delete(t,o){if(o===0)return;const e=this.doc;e!==null?Lr(e,a=>{NS(a,Sh(a,this,t,!0),o)}):this._pending.push(()=>this.delete(t,o))}format(t,o,e){if(o===0)return;const a=this.doc;a!==null?Lr(a,r=>{const n=Sh(r,this,t,!1);n.right!==null&&TS(r,this,n,o,e)}):this._pending.push(()=>this.format(t,o,e))}removeAttribute(t){this.doc!==null?Lr(this.doc,o=>{xh(o,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,o){this.doc!==null?Lr(this.doc,e=>{Gy(e,this,t,o)}):this._pending.push(()=>this.setAttribute(t,o))}getAttribute(t){return Yy(this,t)}getAttributes(){return xS(this)}_write(t){t.writeTypeRef(UR)}}class Xy{constructor(t,o=()=>!0){this._filter=o,this._root=t,this._currentNode=t._start,this._firstCall=!0,t.doc??Mo()}[Symbol.iterator](){return this}next(){let t=this._currentNode,o=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(o)))do if(o=t.content.type,!t.deleted&&(o.constructor===Wd||o.constructor===cu)&&o._start!==null)t=o._start;else for(;t!==null;)if(t.right!==null){t=t.right;break}else t.parent===this._root?t=null:t=t.parent._item;while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class cu extends Oo{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,o){super._integrate(t,o),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new cu}clone(){const t=new cu;return t.insert(0,this.toArray().map(o=>o instanceof Oo?o.clone():o)),t}get length(){return this.doc??Mo(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Xy(this,t)}querySelector(t){t=t.toUpperCase();const e=new Xy(this,a=>a.nodeName&&a.nodeName.toUpperCase()===t).next();return e.done?null:e.value}querySelectorAll(t){return t=t.toUpperCase(),nu(new Xy(this,o=>o.nodeName&&o.nodeName.toUpperCase()===t))}_callObserver(t,o){vh(this,t,new RR(this,o,t))}toString(){return mS(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,o={},e){const a=t.createDocumentFragment();return e!==void 0&&e._createAssociation(a,this),qd(this,r=>{a.insertBefore(r.toDOM(t,o,e),null)}),a}insert(t,o){this.doc!==null?Lr(this.doc,e=>{vS(e,this,t,o)}):this._prelimContent.splice(t,0,...o)}insertAfter(t,o){if(this.doc!==null)Lr(this.doc,e=>{const a=t&&t instanceof Oo?t._item:t;_h(e,this,a,o)});else{const e=this._prelimContent,a=t===null?0:e.findIndex(r=>r===t)+1;if(a===0&&t!==null)throw iu("Reference item not found");e.splice(a,0,...o)}}delete(t,o=1){this.doc!==null?Lr(this.doc,e=>{_S(e,this,t,o)}):this._prelimContent.splice(t,o)}toArray(){return gS(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return yS(this,t)}slice(t=0,o=this.length){return hS(this,t,o)}forEach(t){qd(this,t)}_write(t){t.writeTypeRef($R)}}class Wd extends cu{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,o){super._integrate(t,o),this._prelimAttrs.forEach((e,a)=>{this.setAttribute(a,e)}),this._prelimAttrs=null}_copy(){return new Wd(this.nodeName)}clone(){const t=new Wd(this.nodeName),o=this.getAttributes();return BM(o,(e,a)=>{typeof e=="string"&&t.setAttribute(a,e)}),t.insert(0,this.toArray().map(e=>e instanceof Oo?e.clone():e)),t}toString(){const t=this.getAttributes(),o=[],e=[];for(const i in t)e.push(i);e.sort();const a=e.length;for(let i=0;i<a;i++){const l=e[i];o.push(l+'="'+t[l]+'"')}const r=this.nodeName.toLocaleLowerCase(),n=o.length>0?" "+o.join(" "):"";return`<${r}${n}>${super.toString()}</${r}>`}removeAttribute(t){this.doc!==null?Lr(this.doc,o=>{xh(o,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,o){this.doc!==null?Lr(this.doc,e=>{Gy(e,this,t,o)}):this._prelimAttrs.set(t,o)}getAttribute(t){return Yy(this,t)}hasAttribute(t){return wS(this,t)}getAttributes(t){return t?AR(this,t):xS(this)}toDOM(t=document,o={},e){const a=t.createElement(this.nodeName),r=this.getAttributes();for(const n in r){const i=r[n];typeof i=="string"&&a.setAttribute(n,i)}return qd(this,n=>{a.appendChild(n.toDOM(t,o,e))}),e!==void 0&&e._createAssociation(a,this),a}_write(t){t.writeTypeRef(HR),t.writeKey(this.nodeName)}}class RR extends yh{constructor(t,o,e){super(t,e),this.childListChanged=!1,this.attributesChanged=new Set,o.forEach(a=>{a===null?this.childListChanged=!0:this.attributesChanged.add(a)})}}class jS{constructor(t,o){this.id=t,this.length=o}get deleted(){throw Es()}mergeWith(t){return!1}write(t,o,e){throw Es()}integrate(t,o){throw Es()}}const DR=0;class Ha extends jS{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,o){o>0&&(this.id.clock+=o,this.length-=o),iS(t.doc.store,this)}write(t,o){t.writeInfo(DR),t.writeLen(this.length-o)}getMissing(t,o){return null}}class Eh{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new Eh(this.content)}splice(t){throw Es()}mergeWith(t){return!1}integrate(t,o){}delete(t){}gc(t){}write(t,o){t.writeBuf(this.content)}getRef(){return 3}}class kh{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new kh(this.len)}splice(t){const o=new kh(this.len-t);return this.len=t,o}mergeWith(t){return this.len+=t.len,!0}integrate(t,o){Xw(t.deleteSet,o.id.client,o.id.clock,this.len),o.markDeleted()}delete(t){}gc(t){}write(t,o){t.writeLen(this.len-o)}getRef(){return 1}}const LR=(u,t)=>new Hd({guid:u,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Oh{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const o={};this.opts=o,t.gc||(o.gc=!1),t.autoLoad&&(o.autoLoad=!0),t.meta!==null&&(o.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Oh(LR(this.doc.guid,this.opts))}splice(t){throw Es()}mergeWith(t){return!1}integrate(t,o){this.doc._item=o,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,o){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}class uu{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new uu(this.embed)}splice(t){throw Es()}mergeWith(t){return!1}integrate(t,o){}delete(t){}gc(t){}write(t,o){t.writeJSON(this.embed)}getRef(){return 5}}class _o{constructor(t,o){this.key=t,this.value=o}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new _o(this.key,this.value)}splice(t){throw Es()}mergeWith(t){return!1}integrate(t,o){const e=o.parent;e._searchMarker=null,e._hasFormatting=!0}delete(t){}gc(t){}write(t,o){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}const BR=ph("node_env")==="development";class du{constructor(t){this.arr=t,BR&&Hw(t)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new du(this.arr)}splice(t){const o=new du(this.arr.slice(t));return this.arr=this.arr.slice(0,t),o}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,o){}delete(t){}gc(t){}write(t,o){const e=this.arr.length;t.writeLen(e-o);for(let a=o;a<e;a++){const r=this.arr[a];t.writeAny(r)}}getRef(){return 8}}class sa{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new sa(this.str)}splice(t){const o=new sa(this.str.slice(t));this.str=this.str.slice(0,t);const e=this.str.charCodeAt(t-1);return e>=55296&&e<=56319&&(this.str=this.str.slice(0,t-1)+"�",o.str="�"+o.str.slice(1)),o}mergeWith(t){return this.str+=t.str,!0}integrate(t,o){}delete(t){}gc(t){}write(t,o){t.writeString(o===0?this.str:this.str.slice(o))}getRef(){return 4}}const FR=0,zR=1,UR=2,HR=3,$R=4;class $a{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new $a(this.type._copy())}splice(t){throw Es()}mergeWith(t){return!1}integrate(t,o){this.type._integrate(t.doc,o)}delete(t){let o=this.type._start;for(;o!==null;)o.deleted?o.id.clock<(t.beforeState.get(o.id.client)||0)&&t._mergeStructs.push(o):o.delete(t),o=o.right;this.type._map.forEach(e=>{e.deleted?e.id.clock<(t.beforeState.get(e.id.client)||0)&&t._mergeStructs.push(e):e.delete(t)}),t.changed.delete(this.type)}gc(t){let o=this.type._start;for(;o!==null;)o.gc(t,!0),o=o.right;this.type._start=null,this.type._map.forEach(e=>{for(;e!==null;)e.gc(t,!0),e=e.left}),this.type._map=new Map}write(t,o){this.type._write(t)}getRef(){return 7}}const PS=(u,t,o)=>{const{client:e,clock:a}=t.id,r=new Ro(Yr(e,a+o),t,Yr(e,a+o-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(o));return t.deleted&&r.markDeleted(),t.keep&&(r.keep=!0),t.redone!==null&&(r.redone=Yr(t.redone.client,t.redone.clock+o)),t.right=r,r.right!==null&&(r.right.left=r),u._mergeStructs.push(r),r.parentSub!==null&&r.right===null&&r.parent._map.set(r.parentSub,r),t.length=o,r};class Ro extends jS{constructor(t,o,e,a,r,n,i,l){super(t,l.getLength()),this.origin=e,this.left=o,this.right=a,this.rightOrigin=r,this.parent=n,this.parentSub=i,this.redone=null,this.content=l,this.info=this.content.isCountable()?Aw:0}set marker(t){(this.info&jy)>0!==t&&(this.info^=jy)}get marker(){return(this.info&jy)>0}get keep(){return(this.info&Tw)>0}set keep(t){this.keep!==t&&(this.info^=Tw)}get countable(){return(this.info&Aw)>0}get deleted(){return(this.info&Ny)>0}set deleted(t){this.deleted!==t&&(this.info^=Ny)}markDeleted(){this.info|=Ny}getMissing(t,o){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=ai(o,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=ai(o,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===hh&&this.id.client!==this.parent.client&&this.parent.clock>=ai(o,this.parent.client))return this.parent.client;if(this.origin&&(this.left=sS(t,o,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=za(t,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===Ha||this.right&&this.right.constructor===Ha)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===Ro&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===Ro&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===hh){const e=Vy(o,this.parent);e.constructor===Ha?this.parent=null:this.parent=e.content.type}return null}integrate(t,o){if(o>0&&(this.id.clock+=o,this.left=sS(t,t.doc.store,Yr(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(o),this.length-=o),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let e=this.left,a;if(e!==null)a=e.right;else if(this.parentSub!==null)for(a=this.parent._map.get(this.parentSub)||null;a!==null&&a.left!==null;)a=a.left;else a=this.parent._start;const r=new Set,n=new Set;for(;a!==null&&a!==this.right;){if(n.add(a),r.add(a),gh(this.origin,a.origin)){if(a.id.client<this.id.client)e=a,r.clear();else if(gh(this.rightOrigin,a.rightOrigin))break}else if(a.origin!==null&&n.has(Vy(t.doc.store,a.origin)))r.has(Vy(t.doc.store,a.origin))||(e=a,r.clear());else break;a=a.right}this.left=e}if(this.left!==null){const e=this.left.right;this.right=e,this.left.right=this}else{let e;if(this.parentSub!==null)for(e=this.parent._map.get(this.parentSub)||null;e!==null&&e.left!==null;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),iS(t.doc.store,this),this.content.integrate(t,this),cS(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new Ha(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:Yr(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&gh(t.origin,this.lastId)&&this.right===t&&gh(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const o=this.parent._searchMarker;return o&&o.forEach(e=>{e.p===t&&(e.p=this,!this.deleted&&this.countable&&(e.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const o=this.parent;this.countable&&this.parentSub===null&&(o._length-=this.length),this.markDeleted(),Xw(t.deleteSet,this.id.client,this.id.clock,this.length),cS(t,o,this.parentSub),this.content.delete(t)}}gc(t,o){if(!this.deleted)throw Bl();this.content.gc(t),o?vR(t,this,new Ha(this.id,this.length)):this.content=new kh(this.length)}write(t,o){const e=o>0?Yr(this.id.client,this.id.clock+o-1):this.origin,a=this.rightOrigin,r=this.parentSub,n=this.content.getRef()&dM|(e===null?0:dh)|(a===null?0:Nw)|(r===null?0:uM);if(t.writeInfo(n),e!==null&&t.writeLeftID(e),a!==null&&t.writeRightID(a),e===null&&a===null){const i=this.parent;if(i._item!==void 0){const l=i._item;if(l===null){const s=yR(i);t.writeParentInfo(!0),t.writeString(s)}else t.writeParentInfo(!1),t.writeLeftID(l.id)}else i.constructor===String?(t.writeParentInfo(!0),t.writeString(i)):i.constructor===hh?(t.writeParentInfo(!1),t.writeLeftID(i)):Bl();r!==null&&t.writeString(r)}this.content.write(t,o)}}const IS=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},MS="__ $YJS$ __";IS[MS]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),IS[MS]=!0;function qR(u){return u&&u.__esModule&&Object.prototype.hasOwnProperty.call(u,"default")?u.default:u}qR(function(u){const t=new URLSearchParams;t.append("code",u);for(let o=1;o<arguments.length;o++)t.append("v",arguments[o]);throw Error(`Minified Lexical error #${u}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)});const WR=jo();function RS(){return Math.random().toString(36).replace(/[^a-z]+/g,"").substr(0,5)}function Th(u,t,o,e,a){return{author:t,content:u,deleted:a===void 0?!1:a,id:o===void 0?RS():o,timeStamp:e===void 0?performance.now():e,type:"comment"}}function DS(u,t,o){return{comments:t,id:o===void 0?RS():o,quote:u,type:"thread",resolved:!1}}function LS(u){return{comments:Array.from(u.comments),id:u.id,quote:u.quote,type:"thread",resolved:!1}}function VR(u){return{author:u.author,content:"[Deleted Comment]",deleted:!0,id:u.id,timeStamp:u.timeStamp,type:"comment"}}function e0(u){const t=u._changeListeners;for(const o of t)o()}class JR{constructor(t){qr(this,"_editor");qr(this,"_comments");qr(this,"_changeListeners");qr(this,"_collabProvider");this._comments=[],this._editor=t,this._collabProvider=null,this._changeListeners=new Set}isCollaborative(){return this._collabProvider!==null}getComments(){return this._comments}addComment(t,o,e){const a=Array.from(this._comments),r=this._getCollabComments();if(o!==void 0&&t.type==="comment")for(let n=0;n<a.length;n++){const i=a[n];if(i.type==="thread"&&i.id===o.id){const l=LS(i);a.splice(n,1,l);const s=e!==void 0?e:l.comments.length;if(this.isCollaborative()&&r!==null){const d=r.get(n).get("comments");this._withRemoteTransaction(()=>{const c=this._createCollabSharedMap(t);d.insert(s,[c])})}l.comments.splice(s,0,t);break}}else{const n=e!==void 0?e:a.length;this.isCollaborative()&&r!==null&&this._withRemoteTransaction(()=>{const i=this._createCollabSharedMap(t);r.insert(n,[i])}),a.splice(n,0,t)}this._comments=a,e0(this)}deleteCommentOrThread(t,o){const e=Array.from(this._comments),a=this._getCollabComments();let r=null;if(o!==void 0)for(let n=0;n<e.length;n++){const i=e[n];if(i.type==="thread"&&i.id===o.id){const l=LS(i);e.splice(n,1,l);const s=l.comments;if(r=s.indexOf(t),this.isCollaborative()&&a!==null){const d=a.get(n).get("comments");this._withRemoteTransaction(()=>{d.delete(r)})}s.splice(r,1);break}}else r=e.indexOf(t),this.isCollaborative()&&a!==null&&this._withRemoteTransaction(()=>{a.delete(r)}),e.splice(r,1);return this._comments=e,e0(this),t.type==="comment"?{index:r,markedComment:VR(t)}:null}resolveThread(t){const o={...t,resolved:!0},e=Array.from(this._comments),a=e.findIndex(r=>r.id===o.id);a!==-1&&(e[a]=o),this._comments=e,e0(this)}registerOnChange(t){const o=this._changeListeners;return o.add(t),()=>{o.delete(t)}}_withRemoteTransaction(t){const o=this._collabProvider;o!==null&&o.doc.transact(t,this)}_withLocalTransaction(t){const o=this._collabProvider;try{this._collabProvider=null,t()}finally{this._collabProvider=o}}_getCollabComments(){const t=this._collabProvider;return t!==null?t.doc.get("comments",Fl):null}_createCollabSharedMap(t){const o=new au,e=t.type,a=t.id;if(o.set("type",e),o.set("id",a),e==="comment")o.set("author",t.author),o.set("content",t.content),o.set("deleted",t.deleted),o.set("timeStamp",t.timeStamp);else{o.set("quote",t.quote);const r=new Fl;t.comments.forEach((n,i)=>{const l=this._createCollabSharedMap(n);r.insert(i,[l])}),o.set("comments",r)}return o}registerCollaboration(t){this._collabProvider=t;const o=this._getCollabComments(),e=()=>{t.connect()},a=()=>{try{t.disconnect()}catch{}},r=this._editor.registerCommand(WR,i=>(e!==void 0&&a!==void 0&&(i?(console.log("Comments connected!"),e()):(console.log("Comments disconnected!"),a())),!1),In),n=(i,l)=>{if(l.origin!==this)for(let s=0;s<i.length;s++){const d=i[s];if(d instanceof SS){const c=d.target,p=d.delta;let f=0;for(let h=0;h<p.length;h++){const g=p[h],m=g.insert,v=g.retain,_=g.delete,b=c.parent,S=c===o?void 0:b instanceof au&&this._comments.find(C=>C.id===b.get("id"));if(Array.isArray(m))m.slice().reverse().forEach(C=>{const x=C.get("id"),w=C.get("type")==="thread"?DS(C.get("quote"),C.get("comments").toArray().map(E=>Th(E.get("content"),E.get("author"),E.get("id"),E.get("timeStamp"),E.get("deleted"))),x):Th(C.get("content"),C.get("author"),x,C.get("timeStamp"),C.get("deleted"));this._withLocalTransaction(()=>{this.addComment(w,S,f)})});else if(typeof v=="number")f+=v;else if(typeof _=="number")for(let C=0;C<_;C++){const x=S===void 0||S===!1?this._comments[f]:S.comments[f];this._withLocalTransaction(()=>{this.deleteCommentOrThread(x,S)}),f++}}}}};return o===null?()=>null:(o.observeDeep(n),e(),()=>{o.unobserveDeep(n),r(),this._collabProvider=null})}}function KR(u){const[t,o]=ve.useState(u.getComments());return ve.useEffect(()=>u.registerOnChange(()=>{o(u.getComments())}),[u]),t}const r4="";function t0({className:u,style:t}){return ke.jsx(Cd,{className:u||"ContentEditable__root",style:t})}const BS=jo();function GR({anchorKey:u,editor:t,onAddComment:o}){const e=ve.useRef(null),a=ve.useCallback(()=>{const r=e.current,n=t.getRootElement(),i=t.getElementByKey(u);if(r!==null&&n!==null&&i!==null){const{right:l}=n.getBoundingClientRect(),{top:s}=i.getBoundingClientRect();r.style.left=`${l-20}px`,r.style.top=`${s-30}px`}},[u,t]);return ve.useEffect(()=>(window.addEventListener("resize",a),()=>{window.removeEventListener("resize",a)}),[t,a]),kw(()=>{a()},[u,t,a]),ke.jsx("div",{className:"CommentPlugin_AddCommentBox",ref:e,children:ke.jsx("button",{className:"CommentPlugin_AddCommentBox_button",onClick:o,children:ke.jsx("i",{className:"icon add-comment"})})})}function YR({onEscape:u}){const[t]=Gn();return ve.useEffect(()=>t.registerCommand(Fs,o=>u(o),2),[t,u]),null}function FS({className:u,autoFocus:t,onEscape:o,onChange:e,editorRef:a,placeholder:r="Type a comment..."}){const n={namespace:"Commenting",nodes:[],onError:i=>{throw i},theme:cm};return ke.jsx(np,{initialConfig:n,children:ke.jsxs("div",{className:"CommentPlugin_CommentInputBox_EditorContainer",children:[ke.jsx(oy,{contentEditable:ke.jsx(t0,{className:u}),placeholder:ke.jsx(ke.Fragment,{}),ErrorBoundary:Ol}),ke.jsx(zp,{onChange:e}),ke.jsx(Fp,{}),t!==!1&&ke.jsx(Tp,{}),ke.jsx(YR,{onEscape:o}),ke.jsx(sx,{}),a!==void 0&&ke.jsx(nM,{editorRef:a})]})})}function zS(u,t){return ve.useCallback((o,e)=>{o.read(()=>{u(Vm()),t(!Jm(e.isComposing(),!0))})},[t,u])}function ZR({editor:u,cancelAddComment:t,submitAddComment:o}){const[e,a]=ve.useState(""),[r,n]=ve.useState(!1),i=ve.useRef(null),l=ve.useMemo(()=>({container:document.createElement("div"),elements:[]}),[]),s=ve.useRef(null),d=$S(),c=ve.useCallback(()=>{u.getEditorState().read(()=>{const g=Ot();if(xt(g)){s.current=g.clone();const m=g.anchor,v=g.focus,_=Rv(u,m.getNode(),m.offset,v.getNode(),v.offset),b=i.current;if(_!==null&&b!==null){const{left:S,bottom:C,width:x}=_.getBoundingClientRect(),y=Dv(u,_);let w=y.length===1?S+x/2-125:S-125;w<10&&(w=10),b.style.left=`${w}px`,b.style.top=`${C+20+(window.pageYOffset||document.documentElement.scrollTop)}px`;const E=y.length,{container:I}=l,j=l.elements,B=j.length;for(let N=0;N<E;N++){const D=y[N];let P=j[N];P===void 0&&(P=document.createElement("span"),j[N]=P,I.appendChild(P));const k="255, 212, 0",A=`position:absolute;top:${D.top+(window.pageYOffset||document.documentElement.scrollTop)}px;left:${D.left}px;height:${D.height}px;width:${D.width}px;background-color:rgba(${k}, 0.3);pointer-events:none;z-index:5;`;P.style.cssText=A}for(let N=B-1;N>=E;N--){const D=j[N];I.removeChild(D),j.pop()}}}})},[u,l]);kw(()=>{c();const g=l.container,m=document.body;if(m!==null)return m.appendChild(g),()=>{m.removeChild(g)}},[l.container,c]),ve.useEffect(()=>(window.addEventListener("resize",c),()=>{window.removeEventListener("resize",c)}),[c]);const p=g=>(g.preventDefault(),t(),!0),f=()=>{if(r){let g=u.getEditorState().read(()=>{const m=s.current;return m?m.getTextContent():""});g.length>100&&(g=g.slice(0,99)+"…"),o(DS(g,[Th(e,d)]),!0,void 0,s.current),s.current=null}},h=zS(a,n);return ke.jsxs("div",{className:"CommentPlugin_CommentInputBox",ref:i,children:[ke.jsx(FS,{className:"CommentPlugin_CommentInputBox_Editor",onEscape:p,onChange:h}),ke.jsxs("div",{className:"CommentPlugin_CommentInputBox_Buttons",children:[ke.jsx(Vs,{onClick:t,className:"CommentPlugin_CommentInputBox_Button",children:"Cancel"}),ke.jsx(Vs,{onClick:f,disabled:!r,className:"CommentPlugin_CommentInputBox_Button primary",children:"Comment"})]})]})}function QR({submitAddComment:u,thread:t,placeholder:o}){const[e,a]=ve.useState(""),[r,n]=ve.useState(!1),i=ve.useRef(null),l=$S(),s=zS(a,n),d=()=>{if(r){u(Th(e,l),!1,t);const c=i.current;c!==null&&c.dispatchCommand(Sf,void 0)}};return ke.jsxs(ke.Fragment,{children:[ke.jsx(FS,{className:"CommentPlugin_CommentsPanel_Editor",autoFocus:!1,onEscape:()=>!0,onChange:s,editorRef:i,placeholder:o}),ke.jsx(Vs,{className:"CommentPlugin_CommentsPanel_SendButton",onClick:d,disabled:!r,children:ke.jsx("i",{className:"send"})})]})}function US({commentOrThread:u,deleteCommentOrThread:t,onClose:o,thread:e=void 0}){return ke.jsxs(ke.Fragment,{children:["Are you sure you want to delete this ",u.type,"?",ke.jsxs("div",{className:"Modal__content",children:[ke.jsx(Vs,{onClick:()=>{t(u,e),o()},children:"Delete"})," ",ke.jsx(Vs,{onClick:()=>{o()},children:"Cancel"})]})]})}function HS({comment:u,deleteComment:t,thread:o,rtf:e}){const a=Math.round((u.timeStamp-performance.now())/1e3),r=Math.round(a/60),[n,i]=Sp();return ke.jsxs("li",{className:"CommentPlugin_CommentsPanel_List_Comment",children:[ke.jsxs("div",{className:"CommentPlugin_CommentsPanel_List_Details",children:[ke.jsx("span",{className:"CommentPlugin_CommentsPanel_List_Comment_Author",children:u.author}),ke.jsxs("span",{className:"CommentPlugin_CommentsPanel_List_Comment_Time",children:["· ",a>-10?"Just now":e.format(r,"minute")]})]}),ke.jsx("p",{className:u.deleted?"CommentPlugin_CommentsPanel_DeletedComment":"",children:u.content}),!u.deleted&&ke.jsxs(ke.Fragment,{children:[ke.jsx(Vs,{onClick:()=>{i("Delete Comment",l=>ke.jsx(US,{commentOrThread:u,deleteCommentOrThread:t,thread:o,onClose:l}))},className:"CommentPlugin_CommentsPanel_List_DeleteButton",children:ke.jsx("i",{className:"delete"})}),n]})]})}function XR({activeIDs:u,comments:t,deleteCommentOrThread:o,listRef:e,submitAddComment:a,markNodeMap:r,resolveThread:n}){const[i]=Gn(),[l,s]=ve.useState(0),[d,c]=Sp(),p=ve.useMemo(()=>new Intl.RelativeTimeFormat("en",{localeMatcher:"best fit",numeric:"auto",style:"short"}),[]);return ve.useEffect(()=>{const f=setTimeout(()=>{s(l+1)},1e4);return()=>{clearTimeout(f)}},[l]),ke.jsx("ul",{className:"CommentPlugin_CommentsPanel_List",ref:e,children:t.map(f=>{const h=f.id;if(f.type==="thread"){const g=()=>{const m=r.get(h);if(m!==void 0&&(u===null||u.indexOf(h)===-1)){const v=document.activeElement;i.update(()=>{const _=Array.from(m)[0],b=Qn(_);Rp(b)&&b.selectStart()},{onUpdate(){v!==null&&v.focus()}})}};return console.log(f,"commentOrThread"),ke.jsxs("li",{onClick:g,className:`CommentPlugin_CommentsPanel_List_Thread ${r.has(h)?"interactive":""} ${u.indexOf(h)===-1?"":"active"}`,children:[ke.jsxs("div",{className:"CommentPlugin_CommentsPanel_List_Thread_QuoteBox",children:[ke.jsxs("blockquote",{className:"CommentPlugin_CommentsPanel_List_Thread_Quote",children:[ke.jsx("img",{className:"add-toolbar-image-icon",src:rM,alt:"Add Image"}),ke.jsx("span",{children:f.quote}),ke.jsx("img",{className:`add-toolbar-image-icon CommentPlugin_CommentsPanel_List_ResolveButton ${f.resolved?"opacity-full":""}`,src:oM,alt:"Resolve Comment",onClick:()=>n(f)})]}),ke.jsx(Vs,{onClick:()=>{c("Delete Thread",m=>ke.jsx(US,{commentOrThread:f,deleteCommentOrThread:o,onClose:m}))},className:"CommentPlugin_CommentsPanel_List_DeleteButton",children:ke.jsx("i",{className:"delete"})}),d]}),ke.jsx("ul",{className:"CommentPlugin_CommentsPanel_List_Thread_Comments",children:f.comments.map(m=>m.deleted?null:ke.jsx(HS,{comment:m,deleteComment:o,thread:f,rtf:p},m.id))}),!f.resolved&&ke.jsx("div",{className:"CommentPlugin_CommentsPanel_List_Thread_Editor",children:ke.jsx(QR,{submitAddComment:a,thread:f,placeholder:"Reply to comment..."})})]},h)}return ke.jsx(HS,{comment:f,deleteComment:o,rtf:p},h)})})}function e3({activeIDs:u,deleteCommentOrThread:t,comments:o,submitAddComment:e,markNodeMap:a,resolveThread:r}){const n=ve.useRef(null),i=o.length===0;return ke.jsxs("div",{className:"CommentPlugin_CommentsPanel",children:[ke.jsx("h2",{className:"CommentPlugin_CommentsPanel_Heading",children:"Comments"}),i?ke.jsx("div",{className:"CommentPlugin_CommentsPanel_Empty",children:"No Comments"}):ke.jsx(XR,{activeIDs:u,comments:o,deleteCommentOrThread:t,listRef:n,submitAddComment:e,markNodeMap:a,resolveThread:r})]})}function $S(){const u=Lp(),{yjsDocMap:t,name:o}=u;return t.has("comments")?o:"Playground User"}function t3({providerFactory:u,showComments:t,setShowComments:o}){const e=Lp(),[a]=Gn(),r=ve.useMemo(()=>new JR(a),[a]),n=KR(r),i=ve.useMemo(()=>new Map,[]),[l,s]=ve.useState(),[d,c]=ve.useState([]),[p,f]=ve.useState(!1),{yjsDocMap:h}=e;ve.useEffect(()=>{if(u){const S=u("comments",h);return r.registerCollaboration(S)}},[r,u,h]);const g=ve.useCallback(()=>{a.update(()=>{const S=Ot();S!==null&&(S.dirty=!0)}),f(!1)},[a]),m=ve.useCallback((S,C)=>{if(S.type==="comment"){const x=r.deleteCommentOrThread(S,C);if(!x)return;const{markedComment:y,index:w}=x;r.addComment(y,C,w)}else{r.deleteCommentOrThread(S);const x=C!==void 0?C.id:S.id,y=i.get(x);y!==void 0&&setTimeout(()=>{a.update(()=>{for(const w of y){const E=Qn(w);Rp(E)&&(E.deleteID(x),E.getIDs().length===0&&nx(E))}})})}},[r,a,i]),v=S=>{S&&S.type==="thread"&&r.resolveThread(S)},_=ve.useCallback((S,C,x,y)=>{r.addComment(S,x),C&&(a.update(()=>{if(xt(y)){const w=y.isBackward(),E=S.id;rx(y,w,E)}}),f(!1))},[r,a]);ve.useEffect(()=>{console.log("askjdhasdhasjkdh");const S=[];for(let C=0;C<d.length;C++){const x=d[C],y=i.get(x);if(y!==void 0)for(const w of y){const E=a.getElementByKey(w);E!==null&&(E.classList.add("selected"),S.push(E),o(!0))}}return()=>{for(let C=0;C<S.length;C++)S[C].classList.remove("selected")}},[d,a,i]),ve.useEffect(()=>{const S=new Map;return Br($v(a,Dp,C=>ex(C.getIDs()),(C,x)=>{C.getIDs().forEach(w=>{x.addID(w)})}),a.registerMutationListener(Dp,C=>{a.getEditorState().read(()=>{for(const[x,y]of C){const w=Qn(x);let E=[];y==="destroyed"?E=S.get(x)||[]:Rp(w)&&(E=w.getIDs());for(let I=0;I<E.length;I++){const j=E[I];let B=i.get(j);S.set(x,E),y==="destroyed"?B!==void 0&&(B.delete(x),B.size===0&&i.delete(j)):(B===void 0&&(B=new Set,i.set(j,B)),B.has(x)||B.add(x))}}})}),a.registerUpdateListener(({editorState:C,tags:x})=>{C.read(()=>{const y=Ot();let w=!1,E=!1;if(xt(y)){const I=y.anchor.getNode();if(kt(I)){const j=tx(I,y.anchor.offset);j!==null&&(c(j),w=!0),y.isCollapsed()||(s(I.getKey()),E=!0)}}w||c(I=>I.length===0?I:[]),E||s(null),!x.has("collaboration")&&xt(y)&&f(!1)})}),a.registerCommand(BS,()=>{const C=window.getSelection();return C!==null&&C.removeAllRanges(),f(!0),!0},On))},[a,i]);const b=()=>{a.dispatchCommand(BS,void 0)};return ke.jsxs(ke.Fragment,{children:[p&&go.createPortal(ke.jsx(ZR,{editor:a,cancelAddComment:g,submitAddComment:_}),document.body),l!=null&&!p&&go.createPortal(ke.jsx(GR,{anchorKey:l,editor:a,onAddComment:b}),document.body),t&&go.createPortal(ke.jsx(e3,{comments:n,submitAddComment:_,deleteCommentOrThread:m,activeIDs:d,markNodeMap:i,resolveThread:v}),document.body)]})}const n3=({onChange:u})=>{const[t]=Gn(),[o,e]=ve.useState(!0),a=ve.useRef(""),r=a.current,n=ve.useCallback(()=>{t.update(()=>{const i=l1(t);o?e(!1):i!==r&&(u(i),a.current=i)})},[t,o,u,r]);return ve.useEffect(()=>{const i=t.registerUpdateListener(n);return()=>i()},[t,n]),null};function r3(){const[u]=Gn();return ve.useEffect(()=>{if(!u.hasNodes([Ep,Sd]))throw new Error("ListPlugin: ListNode and/or ListItemNode not registered on editor")},[u]),function(t){ve.useEffect(()=>Br(t.registerCommand(Wm,()=>(p_(t,"number"),!0),In),t.registerCommand(kp,()=>(p_(t,"bullet"),!0),In),t.registerCommand(WT,()=>(BT(t),!0),In),t.registerCommand(dl,()=>!!UT(),In)),[t])}(u),null}const o3=({onlUser:u,codoxStarted:t,isCollab:o})=>{const[e]=Gn(),a=()=>{if(!o){e.setEditable(!0);return}if(t){e.setEditable(!0);return}else{e.setEditable(!1);return}};return ke.jsx(zp,{onChange:a})},i3=hw([...[Sd,Ep,Qi,xl,Ws,fp,pp,gp,Rl,Dd,Dp]]);function s3({collabApiKey:u,userObj:t,styleConfig:o,docId:e,onlUser:a,setonlUser:r,savedSpfEditorState:n,setSavedEditorState:i,setSavedEditorState2:l,mentionItems:s,showtoolbar:d=!0,customHeight:c,customWidth:p,disabled:f,editorId:h,onPaste:g,source:m,useCustomOnChange:v=!1,onChangePlugin:_=ke.jsx(ke.Fragment,{}),customClassName:b="",editorForComment:S=!1,isCollab:C=!1}){const x=ve.useRef(null),[y,w]=ve.useState(!1),{pageMarginTop:E,pageMarginLeft:I,pageMarginBottom:j,pageMarginRight:B,heading:N}=o||{};ve.useState("");const[D,P]=ve.useState(!0),k=ve.useRef(null),[A,L]=ve.useState(!1),[R,J]=ve.useState([]),T=ve.useRef(),[H,W]=ve.useState({root:null});ve.useState(0);const[K,F]=ve.useState(!0),[q,$]=ve.useState(!1);let z={namespace:`editor_${h}`,nodes:[...i3],onError(se){throw se},theme:cm,editorState:se=>{se.update(()=>{if(n&&D){const Pe=new DOMParser().parseFromString(n,"text/html"),Be=Sm(se,Pe);Be.forEach(Ce=>{Ce instanceof Ws&&Ce.setStyle("font-weight: normal")}),Zn(),gc(Be),P(!1)}})}};ve.useEffect(()=>{setTimeout(()=>{kc(".custom-margin").css({paddingTop:`${E||"16px"}`,paddingRight:`${B||"16px"}`,paddingLeft:`${I||"16px"}`,paddingBottom:`${j||"16px"}`}),kc(".editor-inner").css({maxHeight:c?`${c}px`:"100%",overflow:"scroll",height:c?`${c}px`:"100%",minHeight:"200px",maxWidth:p?`${p}px`:"100%"}),kc(`.${h}`).attr("contentEditable",!f)},500)},[]);const{userName:Y,userId:G,userEmail:Z}=t,ee={docId:h,apiKey:u,user:{name:Y,id:G,email:Z},showCursor:!1,cursorAlwaysOn:!1,showPointer:!1,hooks:{contentChanged:({source:se,content:ue})=>{},usersUpdate:se=>{J(se),renderOnlineUsers(se)}}},ne=()=>{T.current&&T.current.start(ee).then(()=>{console.log("[Lexical Demo][codox.start] success"),L(!0)}).catch(se=>console.log("[Lexical Demo][codox.start] error",se))};ve.useEffect(()=>(T.current.cursor.hide(),()=>{ce()}),[]);const ce=()=>{T.current&&T.current.stop(),L(!1)};ve.useEffect(()=>{H&&e&&!A&&ne()},[H,e,A]),ve.useEffect(()=>{let se=[],ue=[];R&&R.length>0&&R.map((Pe,Be)=>{ue.includes(Pe.name)||(ue.push(Pe.name),se.push(ke.jsxs("div",{title:Pe.email,className:`avatarStyle avatar-color-${Be+1}`,children:[" ",Pe.name&&Pe.name[0],Pe.name&&Pe.name[4]]},Be)))}),r(se)},[R]);const ae=ve.useCallback(se=>{k.current&&clearTimeout(k.current),k.current=setTimeout(()=>{i(se)},500)},[h,i,l]),de=ve.useCallback(se=>{k.current&&clearTimeout(k.current),k.current=setTimeout(()=>{l(se)},500)},[h,i,l]),xe=()=>{w(!0)};return ke.jsxs("div",{ref:x,children:[ke.jsx(Rk,{children:ke.jsxs(np,{initialConfig:z,children:[ke.jsx(pw,{ref:T}),ke.jsxs("div",{className:"editor-container",children:[d&&ke.jsx("div",{style:{pointerEvents:f?"none":"all"},children:ke.jsx(JT,{openModal:xe,styleConfig:o,onlUser:a,stopCodox:ce,startCodox:ne,source:m,onPaste:g,block:K,setBlock:F,showComments:q,setShowComments:$})}),S?ke.jsx("div",{className:"CommentPlugin_CommentInputBox_EditorContainer",children:ke.jsx(oy,{contentEditable:ke.jsx(Cd,{className:b}),placeholder:null,ErrorBoundary:Ol})}):ke.jsxs("div",{className:"editor-inner",children:[ke.jsx(Op,{contentEditable:ke.jsxs("div",{className:"custom-margin",children:[ke.jsx(Cd,{className:`editor-input ${h}`,contentEditable:!1}),C===!0?ke.jsx(o3,{onlUser:a,codoxStarted:A,isCollab:C}):""]}),placeholder:null,ErrorBoundary:Ol}),ke.jsx(r3,{}),ke.jsx(Tp,{})]})]}),ke.jsx(_k,{disabled:f}),ke.jsx(nA,{disabled:f}),ke.jsx(Ok,{disabled:f}),ke.jsx(Bk,{disabled:f}),ke.jsx(Fp,{}),ke.jsx(YI,{items:s,menuComponent:ZI,menuItemComponent:QI}),v?ke.jsx(ke.Fragment,{children:_}):ke.jsx(n3,{onChange:h.includes("objective")?ae:de}),ke.jsx(t3,{showComments:q,setShowComments:$})]})}),ke.jsx(BO,{styleConfig:o})]})}const a3=hw([...[]]);function l3({collabApiKey:u,userObj:t,docId:o,setonlUser:e,savedSpfEditorState:a,setSavedEditorState:r,customHeight:n,customWidth:i,editorId:l}){const s=ve.useRef(null),[d,c]=ve.useState(!0),[p,f]=ve.useState(!1),[h,g]=ve.useState([]),m=ve.useRef(),[v,_]=ve.useState({root:null});ve.useState(0);const b=ve.useRef(""),S={namespace:`editor_${l}`,nodes:[...a3],onError(B){throw B},theme:cm,editorState:B=>{B.update(()=>{if(a&&d){const D=new DOMParser().parseFromString(a,"text/html"),P=Sm(B,D);Zn(),gc(P),c(!1)}})}};ve.useEffect(()=>{setTimeout(()=>{kc(".custom-margin-2").css({height:`${n}px`}),kc(".editor-inner-2").css({background:"#fff",position:"relative",top:"20px",padding:"20px",borderRadius:"0 0 10px 10px",maxHeight:`${n}px`,overflow:"scroll",height:`${n}px`,minHeight:"200px",maxWidth:i?`${i}px`:"100%"})},500)},[]);const{userName:C,userId:x,userEmail:y}=t,E={docId:l,apiKey:u,user:{name:C,id:x,email:y},showCursor:!1,cursorAlwaysOn:!1,showPointer:!1,hooks:{contentChanged:({source:B,content:N})=>{},usersUpdate:B=>{g(B),renderOnlineUsers(B)}}},I=()=>{m.current&&m.current.start(E).then(()=>{console.log("[Lexical Demo][codox.start] success"),f(!0)}).catch(B=>console.log("[Lexical Demo][codox.start] error",B))};ve.useEffect(()=>{v&&o&&!p&&I()},[v,o,p]),ve.useEffect(()=>{let B=[],N=[];h&&h.length>0&&h.map((D,P)=>{N.includes(D.name)||(N.push(D.name),B.push(ke.jsxs("div",{title:D.email,className:`avatarStyle avatar-color-${P+1}`,children:[" ",D.name&&D.name[0],D.name&&D.name[4]]},P)))}),e(B)},[h]);const j=()=>{let B=kc(".editor-input-2").html();B!==b.current&&(console.log("Editor Variant 2 HTML",B),r(B),b.current=B)};return ke.jsx("div",{ref:s,children:ke.jsxs(np,{initialConfig:S,children:[ke.jsx(pw,{ref:m}),ke.jsx("div",{className:"editor-container",children:ke.jsxs("div",{className:"editor-inner-2",children:[ke.jsx(Op,{contentEditable:ke.jsx("div",{className:"custom-margin-2",children:ke.jsx(Cd,{className:"editor-input-2 inpt-2"})}),placeholder:null,ErrorBoundary:Ol}),ke.jsx(zp,{onChange:j}),ke.jsx(Tp,{})]})}),ke.jsx(Fp,{})]})})}const s4="";function c3(u){return u&&u.__esModule&&Object.prototype.hasOwnProperty.call(u,"default")?u.default:u}var u3=c3(function(u){const t=new URLSearchParams;t.append("code",u);for(let o=1;o<arguments.length;o++)t.append("v",arguments[o]);throw Error(`Minified Lexical error #${u}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)});function qS(u){const t=u.transform();return t!==null?new Set([t]):new Set}function WS({initialEditor:u,children:t,initialNodes:o,initialTheme:e,skipCollabChecks:a}){const r=ve.useRef(!1),n=ve.useContext(Fu);n==null&&u3(9);const[i,{getTheme:l}]=n,s=ve.useMemo(()=>{const f=e||l()||void 0,h=ab(n,f);if(f!==void 0&&(u._config.theme=f),u._parentEditor=i,o)for(let g of o){let m=null,v=null;if(typeof g!="function"){const b=g;g=b.replace,m=b.with,v=b.withKlass||null}const _=u._nodes.get(g.getType());u._nodes.set(g.getType(),{exportDOM:_?_.exportDOM:void 0,klass:g,replace:m,replaceWithKlass:v,transforms:qS(g)})}else{const g=u._nodes=new Map(i._nodes);for(const[m,v]of g)u._nodes.set(m,{exportDOM:v.exportDOM,klass:v.klass,replace:v.replace,replaceWithKlass:v.replaceWithKlass,transforms:qS(v.klass)})}return u._config.namespace=i._config.namespace,u._editable=i._editable,[u,h]},[]),{isCollabActive:d,yjsDocMap:c}=Lp(),p=a||r.current||c.has(u.getKey());return ve.useEffect(()=>{p&&(r.current=!0)},[p]),ve.useEffect(()=>i.registerEditableListener(f=>{u.setEditable(f)}),[u,i]),ke.jsx(Fu.Provider,{value:s,children:!d||p?t:null})}function n0(u,t,o){return Math.min(Math.max(u,t),o)}const Nr={east:1,north:8,south:2,west:4};function d3({onResizeStart:u,onResizeEnd:t,buttonRef:o,imageRef:e,maxWidth:a,editor:r,showCaption:n,setShowCaption:i,captionsEnabled:l}){const s=ve.useRef(null),d=ve.useRef({priority:"",value:"default"}),c=ve.useRef({currentHeight:0,currentWidth:0,direction:0,isResizing:!1,ratio:0,startHeight:0,startWidth:0,startX:0,startY:0}),p=r.getRootElement(),f=p!==null?p.getBoundingClientRect().width-20:100,h=p!==null?p.getBoundingClientRect().height-20:100,g=100,m=100,v=x=>{const y=x===Nr.east||x===Nr.west,w=x===Nr.north||x===Nr.south,E=x&Nr.north&&x&Nr.west||x&Nr.south&&x&Nr.east,I=y?"ew":w?"ns":E?"nwse":"nesw";p!==null&&p.style.setProperty("cursor",`${I}-resize`,"important"),document.body!==null&&(document.body.style.setProperty("cursor",`${I}-resize`,"important"),d.current.value=document.body.style.getPropertyValue("-webkit-user-select"),d.current.priority=document.body.style.getPropertyPriority("-webkit-user-select"),document.body.style.setProperty("-webkit-user-select","none","important"))},_=()=>{p!==null&&p.style.setProperty("cursor","text"),document.body!==null&&(document.body.style.setProperty("cursor","default"),document.body.style.setProperty("-webkit-user-select",d.current.value,d.current.priority))},b=(x,y)=>{if(!r.isEditable())return;const w=e.current,E=s.current;if(w!==null&&E!==null){x.preventDefault();const{width:I,height:j}=w.getBoundingClientRect(),B=c.current;B.startWidth=I,B.startHeight=j,B.ratio=I/j,B.currentWidth=I,B.currentHeight=j,B.startX=x.clientX,B.startY=x.clientY,B.isResizing=!0,B.direction=y,v(y),u(),E.classList.add("image-control-wrapper--resizing"),w.style.height=`${j}px`,w.style.width=`${I}px`,document.addEventListener("pointermove",S),document.addEventListener("pointerup",C)}},S=x=>{const y=e.current,w=c.current,E=w.direction&(Nr.east|Nr.west),I=w.direction&(Nr.south|Nr.north);if(y!==null&&w.isResizing){if(E&&I){let j=Math.floor(w.startX-x.clientX);j=w.direction&Nr.east?-j:j;const B=n0(w.startWidth+j,g,f),N=B/w.ratio;y.style.width=`${B}px`,y.style.height=`${N}px`,w.currentHeight=N,w.currentWidth=B}else if(I){let j=Math.floor(w.startY-x.clientY);j=w.direction&Nr.south?-j:j;const B=n0(w.startHeight+j,m,h);y.style.height=`${B}px`,y.style.maxHeight=`${B}px`,w.currentHeight=B}else{let j=Math.floor(w.startX-x.clientX);j=w.direction&Nr.east?-j:j;const B=n0(w.startWidth+j,g,f);y.style.width=`${B}px`,y.style.maxWidth=`${B}px`,w.currentWidth=B}y&&(y.setAttribute("width",`${w.currentWidth}`),y.setAttribute("height",`${w.currentHeight}`))}},C=()=>{const x=e.current,y=c.current,w=s.current;if(x!==null&&w!==null&&y.isResizing){const E=y.currentWidth,I=y.currentHeight;y.startWidth=0,y.startHeight=0,y.ratio=0,y.startX=0,y.startY=0,y.currentWidth=0,y.currentHeight=0,y.isResizing=!1,w.classList.remove("image-control-wrapper--resizing"),_(),t(E,I),document.removeEventListener("pointermove",S),document.removeEventListener("pointerup",C)}};return ke.jsxs("div",{ref:s,children:[ke.jsx("div",{className:"image-resizer image-resizer-n",onPointerDown:x=>{b(x,Nr.north)}}),ke.jsx("div",{className:"image-resizer image-resizer-ne",onPointerDown:x=>{b(x,Nr.north|Nr.east)}}),ke.jsx("div",{className:"image-resizer image-resizer-e",onPointerDown:x=>{b(x,Nr.east)}}),ke.jsx("div",{className:"image-resizer image-resizer-se",onPointerDown:x=>{b(x,Nr.south|Nr.east)}}),ke.jsx("div",{className:"image-resizer image-resizer-s",onPointerDown:x=>{b(x,Nr.south)}}),ke.jsx("div",{className:"image-resizer image-resizer-sw",onPointerDown:x=>{b(x,Nr.south|Nr.west)}}),ke.jsx("div",{className:"image-resizer image-resizer-w",onPointerDown:x=>{b(x,Nr.west)}}),ke.jsx("div",{className:"image-resizer image-resizer-nw",onPointerDown:x=>{b(x,Nr.north|Nr.west)}})]})}const a4="";function VS({children:u,className:t}){return ke.jsx("div",{className:t||"Placeholder__root",children:u})}const Ah={x:0,y:0,width:0,height:0,unit:"px"},fu=(u,t,o)=>Math.min(Math.max(u,t),o),f3=(...u)=>u.filter(t=>t&&typeof t=="string").join(" "),JS=(u,t)=>u===t||u.width===t.width&&u.height===t.height&&u.x===t.x&&u.y===t.y&&u.unit===t.unit;function pu(u,t,o){return u.unit==="%"?{...Ah,...u,unit:"%"}:{unit:"%",x:u.x?u.x/t*100:0,y:u.y?u.y/o*100:0,width:u.width?u.width/t*100:0,height:u.height?u.height/o*100:0}}function qa(u,t,o){return u.unit?u.unit==="px"?{...Ah,...u,unit:"px"}:{unit:"px",x:u.x?u.x*t/100:0,y:u.y?u.y*o/100:0,width:u.width?u.width*t/100:0,height:u.height?u.height*o/100:0}:{...Ah,...u,unit:"px"}}function KS(u,t,o,e,a,r=0,n=0,i=e,l=a){const s={...u};let d=Math.min(r,e),c=Math.min(n,a),p=Math.min(i,e),f=Math.min(l,a);t&&(t>1?(d=n?n*t:d,c=d/t,p=i*t):(c=r?r/t:c,d=c*t,f=l/t)),s.y<0&&(s.height=Math.max(s.height+s.y,c),s.y=0),s.x<0&&(s.width=Math.max(s.width+s.x,d),s.x=0);const h=e-(s.x+s.width);h<0&&(s.x=Math.min(s.x,e-d),s.width+=h);const g=a-(s.y+s.height);if(g<0&&(s.y=Math.min(s.y,a-c),s.height+=g),s.width<d&&((o==="sw"||o=="nw")&&(s.x-=d-s.width),s.width=d),s.height<c&&((o==="nw"||o=="ne")&&(s.y-=c-s.height),s.height=c),s.width>p&&((o==="sw"||o=="nw")&&(s.x-=p-s.width),s.width=p),s.height>f&&((o==="nw"||o=="ne")&&(s.y-=f-s.height),s.height=f),t){const m=s.width/s.height;if(m<t){const v=Math.max(s.width/t,c);(o==="nw"||o=="ne")&&(s.y-=v-s.height),s.height=v}else if(m>t){const v=Math.max(s.height*t,d);(o==="sw"||o=="nw")&&(s.x-=v-s.width),s.width=v}}return s}function p3(u,t,o,e){const a={...u};return t==="ArrowLeft"?e==="nw"?(a.x-=o,a.y-=o,a.width+=o,a.height+=o):e==="w"?(a.x-=o,a.width+=o):e==="sw"?(a.x-=o,a.width+=o,a.height+=o):e==="ne"?(a.y+=o,a.width-=o,a.height-=o):e==="e"?a.width-=o:e==="se"&&(a.width-=o,a.height-=o):t==="ArrowRight"&&(e==="nw"?(a.x+=o,a.y+=o,a.width-=o,a.height-=o):e==="w"?(a.x+=o,a.width-=o):e==="sw"?(a.x+=o,a.width-=o,a.height-=o):e==="ne"?(a.y-=o,a.width+=o,a.height+=o):e==="e"?a.width+=o:e==="se"&&(a.width+=o,a.height+=o)),t==="ArrowUp"?e==="nw"?(a.x-=o,a.y-=o,a.width+=o,a.height+=o):e==="n"?(a.y-=o,a.height+=o):e==="ne"?(a.y-=o,a.width+=o,a.height+=o):e==="sw"?(a.x+=o,a.width-=o,a.height-=o):e==="s"?a.height-=o:e==="se"&&(a.width-=o,a.height-=o):t==="ArrowDown"&&(e==="nw"?(a.x+=o,a.y+=o,a.width-=o,a.height-=o):e==="n"?(a.y+=o,a.height-=o):e==="ne"?(a.y+=o,a.width-=o,a.height-=o):e==="sw"?(a.x-=o,a.width+=o,a.height+=o):e==="s"?a.height+=o:e==="se"&&(a.width+=o,a.height+=o)),a}const hu={capture:!0,passive:!1};let h3=0;const Wa=class us extends ve.PureComponent{constructor(){super(...arguments),this.docMoveBound=!1,this.mouseDownOnCrop=!1,this.dragStarted=!1,this.evData={startClientX:0,startClientY:0,startCropX:0,startCropY:0,clientX:0,clientY:0,isResize:!0},this.componentRef=ve.createRef(),this.mediaRef=ve.createRef(),this.initChangeCalled=!1,this.instanceId=`rc-${h3++}`,this.state={cropIsActive:!1,newCropIsBeingDrawn:!1},this.onCropPointerDown=t=>{const{crop:o,disabled:e}=this.props,a=this.getBox();if(!o)return;const r=qa(o,a.width,a.height);if(e)return;t.cancelable&&t.preventDefault(),this.bindDocMove(),this.componentRef.current.focus({preventScroll:!0});const n=t.target.dataset.ord,i=!!n;let l=t.clientX,s=t.clientY,d=r.x,c=r.y;if(n){const p=t.clientX-a.x,f=t.clientY-a.y;let h=0,g=0;n==="ne"||n=="e"?(h=p-(r.x+r.width),g=f-r.y,d=r.x,c=r.y+r.height):n==="se"||n==="s"?(h=p-(r.x+r.width),g=f-(r.y+r.height),d=r.x,c=r.y):n==="sw"||n=="w"?(h=p-r.x,g=f-(r.y+r.height),d=r.x+r.width,c=r.y):(n==="nw"||n=="n")&&(h=p-r.x,g=f-r.y,d=r.x+r.width,c=r.y+r.height),l=d+a.x+h,s=c+a.y+g}this.evData={startClientX:l,startClientY:s,startCropX:d,startCropY:c,clientX:t.clientX,clientY:t.clientY,isResize:i,ord:n},this.mouseDownOnCrop=!0,this.setState({cropIsActive:!0})},this.onComponentPointerDown=t=>{const{crop:o,disabled:e,locked:a,keepSelection:r,onChange:n}=this.props,i=this.getBox();if(e||a||r&&o)return;t.cancelable&&t.preventDefault(),this.bindDocMove(),this.componentRef.current.focus({preventScroll:!0});const l=t.clientX-i.x,s=t.clientY-i.y,d={unit:"px",x:l,y:s,width:0,height:0};this.evData={startClientX:t.clientX,startClientY:t.clientY,startCropX:l,startCropY:s,clientX:t.clientX,clientY:t.clientY,isResize:!0},this.mouseDownOnCrop=!0,n(qa(d,i.width,i.height),pu(d,i.width,i.height)),this.setState({cropIsActive:!0,newCropIsBeingDrawn:!0})},this.onDocPointerMove=t=>{const{crop:o,disabled:e,onChange:a,onDragStart:r}=this.props,n=this.getBox();if(e||!o||!this.mouseDownOnCrop)return;t.cancelable&&t.preventDefault(),this.dragStarted||(this.dragStarted=!0,r&&r(t));const{evData:i}=this;i.clientX=t.clientX,i.clientY=t.clientY;let l;i.isResize?l=this.resizeCrop():l=this.dragCrop(),JS(o,l)||a(qa(l,n.width,n.height),pu(l,n.width,n.height))},this.onComponentKeyDown=t=>{const{crop:o,disabled:e,onChange:a,onComplete:r}=this.props;if(e)return;const n=t.key;let i=!1;if(!o)return;const l=this.getBox(),s=this.makePixelCrop(l),d=(navigator.platform.match("Mac")?t.metaKey:t.ctrlKey)?us.nudgeStepLarge:t.shiftKey?us.nudgeStepMedium:us.nudgeStep;if(n==="ArrowLeft"?(s.x-=d,i=!0):n==="ArrowRight"?(s.x+=d,i=!0):n==="ArrowUp"?(s.y-=d,i=!0):n==="ArrowDown"&&(s.y+=d,i=!0),i){t.cancelable&&t.preventDefault(),s.x=fu(s.x,0,l.width-s.width),s.y=fu(s.y,0,l.height-s.height);const c=qa(s,l.width,l.height),p=pu(s,l.width,l.height);a(c,p),r&&r(c,p)}},this.onHandlerKeyDown=(t,o)=>{const{aspect:e=0,crop:a,disabled:r,minWidth:n=0,minHeight:i=0,maxWidth:l,maxHeight:s,onChange:d,onComplete:c}=this.props,p=this.getBox();if(r||!a)return;if(t.key==="ArrowUp"||t.key==="ArrowDown"||t.key==="ArrowLeft"||t.key==="ArrowRight")t.stopPropagation(),t.preventDefault();else return;const f=(navigator.platform.match("Mac")?t.metaKey:t.ctrlKey)?us.nudgeStepLarge:t.shiftKey?us.nudgeStepMedium:us.nudgeStep,h=qa(a,p.width,p.height),g=p3(h,t.key,f,o),m=KS(g,e,o,p.width,p.height,n,i,l,s);if(!JS(a,m)){const v=pu(m,p.width,p.height);d(m,v),c&&c(m,v)}},this.onDocPointerDone=t=>{const{crop:o,disabled:e,onComplete:a,onDragEnd:r}=this.props,n=this.getBox();this.unbindDocMove(),!(e||!o)&&this.mouseDownOnCrop&&(this.mouseDownOnCrop=!1,this.dragStarted=!1,r&&r(t),a&&a(qa(o,n.width,n.height),pu(o,n.width,n.height)),this.setState({cropIsActive:!1,newCropIsBeingDrawn:!1}))},this.onDragFocus=()=>{var t;(t=this.componentRef.current)==null||t.scrollTo(0,0)}}get document(){return document}getBox(){const t=this.mediaRef.current;if(!t)return{x:0,y:0,width:0,height:0};const{x:o,y:e,width:a,height:r}=t.getBoundingClientRect();return{x:o,y:e,width:a,height:r}}componentDidUpdate(t){const{crop:o,onComplete:e}=this.props;if(e&&!t.crop&&o){const{width:a,height:r}=this.getBox();a&&r&&e(qa(o,a,r),pu(o,a,r))}}componentWillUnmount(){this.resizeObserver&&this.resizeObserver.disconnect(),this.unbindDocMove()}bindDocMove(){this.docMoveBound||(this.document.addEventListener("pointermove",this.onDocPointerMove,hu),this.document.addEventListener("pointerup",this.onDocPointerDone,hu),this.document.addEventListener("pointercancel",this.onDocPointerDone,hu),this.docMoveBound=!0)}unbindDocMove(){this.docMoveBound&&(this.document.removeEventListener("pointermove",this.onDocPointerMove,hu),this.document.removeEventListener("pointerup",this.onDocPointerDone,hu),this.document.removeEventListener("pointercancel",this.onDocPointerDone,hu),this.docMoveBound=!1)}getCropStyle(){const{crop:t}=this.props;if(t)return{top:`${t.y}${t.unit}`,left:`${t.x}${t.unit}`,width:`${t.width}${t.unit}`,height:`${t.height}${t.unit}`}}dragCrop(){const{evData:t}=this,o=this.getBox(),e=this.makePixelCrop(o),a=t.clientX-t.startClientX,r=t.clientY-t.startClientY;return e.x=fu(t.startCropX+a,0,o.width-e.width),e.y=fu(t.startCropY+r,0,o.height-e.height),e}getPointRegion(t,o,e,a){const{evData:r}=this,n=r.clientX-t.x,i=r.clientY-t.y;let l;a&&o?l=o==="nw"||o==="n"||o==="ne":l=i<r.startCropY;let s;return e&&o?s=o==="nw"||o==="w"||o==="sw":s=n<r.startCropX,s?l?"nw":"sw":l?"ne":"se"}resolveMinDimensions(t,o,e=0,a=0){const r=Math.min(e,t.width),n=Math.min(a,t.height);return!o||!r&&!n?[r,n]:o>1?r?[r,r/o]:[n*o,n]:n?[n*o,n]:[r,r/o]}resizeCrop(){const{evData:t}=this,{aspect:o=0,maxWidth:e,maxHeight:a}=this.props,r=this.getBox(),[n,i]=this.resolveMinDimensions(r,o,this.props.minWidth,this.props.minHeight);let l=this.makePixelCrop(r);const s=this.getPointRegion(r,t.ord,n,i),d=t.ord||s;let c=t.clientX-t.startClientX,p=t.clientY-t.startClientY;(n&&d==="nw"||d==="w"||d==="sw")&&(c=Math.min(c,-n)),(i&&d==="nw"||d==="n"||d==="ne")&&(p=Math.min(p,-i));const f={unit:"px",x:0,y:0,width:0,height:0};s==="ne"?(f.x=t.startCropX,f.width=c,o?(f.height=f.width/o,f.y=t.startCropY-f.height):(f.height=Math.abs(p),f.y=t.startCropY-f.height)):s==="se"?(f.x=t.startCropX,f.y=t.startCropY,f.width=c,o?f.height=f.width/o:f.height=p):s==="sw"?(f.x=t.startCropX+c,f.y=t.startCropY,f.width=Math.abs(c),o?f.height=f.width/o:f.height=p):s==="nw"&&(f.x=t.startCropX+c,f.width=Math.abs(c),o?(f.height=f.width/o,f.y=t.startCropY-f.height):(f.height=Math.abs(p),f.y=t.startCropY+p));const h=KS(f,o,s,r.width,r.height,n,i,e,a);return o||us.xyOrds.indexOf(d)>-1?l=h:us.xOrds.indexOf(d)>-1?(l.x=h.x,l.width=h.width):us.yOrds.indexOf(d)>-1&&(l.y=h.y,l.height=h.height),l.x=fu(l.x,0,r.width-l.width),l.y=fu(l.y,0,r.height-l.height),l}renderCropSelection(){const{ariaLabels:t=us.defaultProps.ariaLabels,disabled:o,locked:e,renderSelectionAddon:a,ruleOfThirds:r,crop:n}=this.props,i=this.getCropStyle();if(n)return ve.createElement("div",{style:i,className:"ReactCrop__crop-selection",onPointerDown:this.onCropPointerDown,"aria-label":t.cropArea,tabIndex:0,onKeyDown:this.onComponentKeyDown,role:"group"},!o&&!e&&ve.createElement("div",{className:"ReactCrop__drag-elements",onFocus:this.onDragFocus},ve.createElement("div",{className:"ReactCrop__drag-bar ord-n","data-ord":"n"}),ve.createElement("div",{className:"ReactCrop__drag-bar ord-e","data-ord":"e"}),ve.createElement("div",{className:"ReactCrop__drag-bar ord-s","data-ord":"s"}),ve.createElement("div",{className:"ReactCrop__drag-bar ord-w","data-ord":"w"}),ve.createElement("div",{className:"ReactCrop__drag-handle ord-nw","data-ord":"nw",tabIndex:0,"aria-label":t.nwDragHandle,onKeyDown:l=>this.onHandlerKeyDown(l,"nw"),role:"button"}),ve.createElement("div",{className:"ReactCrop__drag-handle ord-n","data-ord":"n",tabIndex:0,"aria-label":t.nDragHandle,onKeyDown:l=>this.onHandlerKeyDown(l,"n"),role:"button"}),ve.createElement("div",{className:"ReactCrop__drag-handle ord-ne","data-ord":"ne",tabIndex:0,"aria-label":t.neDragHandle,onKeyDown:l=>this.onHandlerKeyDown(l,"ne"),role:"button"}),ve.createElement("div",{className:"ReactCrop__drag-handle ord-e","data-ord":"e",tabIndex:0,"aria-label":t.eDragHandle,onKeyDown:l=>this.onHandlerKeyDown(l,"e"),role:"button"}),ve.createElement("div",{className:"ReactCrop__drag-handle ord-se","data-ord":"se",tabIndex:0,"aria-label":t.seDragHandle,onKeyDown:l=>this.onHandlerKeyDown(l,"se"),role:"button"}),ve.createElement("div",{className:"ReactCrop__drag-handle ord-s","data-ord":"s",tabIndex:0,"aria-label":t.sDragHandle,onKeyDown:l=>this.onHandlerKeyDown(l,"s"),role:"button"}),ve.createElement("div",{className:"ReactCrop__drag-handle ord-sw","data-ord":"sw",tabIndex:0,"aria-label":t.swDragHandle,onKeyDown:l=>this.onHandlerKeyDown(l,"sw"),role:"button"}),ve.createElement("div",{className:"ReactCrop__drag-handle ord-w","data-ord":"w",tabIndex:0,"aria-label":t.wDragHandle,onKeyDown:l=>this.onHandlerKeyDown(l,"w"),role:"button"})),a&&ve.createElement("div",{className:"ReactCrop__selection-addon",onPointerDown:l=>l.stopPropagation()},a(this.state)),r&&ve.createElement(ve.Fragment,null,ve.createElement("div",{className:"ReactCrop__rule-of-thirds-hz"}),ve.createElement("div",{className:"ReactCrop__rule-of-thirds-vt"})))}makePixelCrop(t){const o={...Ah,...this.props.crop||{}};return qa(o,t.width,t.height)}render(){const{aspect:t,children:o,circularCrop:e,className:a,crop:r,disabled:n,locked:i,style:l,ruleOfThirds:s}=this.props,{cropIsActive:d,newCropIsBeingDrawn:c}=this.state,p=r?this.renderCropSelection():null,f=f3("ReactCrop",a,d&&"ReactCrop--active",n&&"ReactCrop--disabled",i&&"ReactCrop--locked",c&&"ReactCrop--new-crop",r&&t&&"ReactCrop--fixed-aspect",r&&e&&"ReactCrop--circular-crop",r&&s&&"ReactCrop--rule-of-thirds",!this.dragStarted&&r&&!r.width&&!r.height&&"ReactCrop--invisible-crop",e&&"ReactCrop--no-animate");return ve.createElement("div",{ref:this.componentRef,className:f,style:l},ve.createElement("div",{ref:this.mediaRef,className:"ReactCrop__child-wrapper",onPointerDown:this.onComponentPointerDown},o),r?ve.createElement("svg",{className:"ReactCrop__crop-mask",width:"100%",height:"100%"},ve.createElement("defs",null,ve.createElement("mask",{id:`hole-${this.instanceId}`},ve.createElement("rect",{width:"100%",height:"100%",fill:"white"}),e?ve.createElement("ellipse",{cx:`${r.x+r.width/2}${r.unit}`,cy:`${r.y+r.height/2}${r.unit}`,rx:`${r.width/2}${r.unit}`,ry:`${r.height/2}${r.unit}`,fill:"black"}):ve.createElement("rect",{x:`${r.x}${r.unit}`,y:`${r.y}${r.unit}`,width:`${r.width}${r.unit}`,height:`${r.height}${r.unit}`,fill:"black"}))),ve.createElement("rect",{fill:"black",fillOpacity:.5,width:"100%",height:"100%",mask:`url(#hole-${this.instanceId})`})):void 0,p)}};Wa.xOrds=["e","w"],Wa.yOrds=["n","s"],Wa.xyOrds=["nw","ne","se","sw"],Wa.nudgeStep=1,Wa.nudgeStepMedium=10,Wa.nudgeStepLarge=100,Wa.defaultProps={ariaLabels:{cropArea:"Use the arrow keys to move the crop selection area",nwDragHandle:"Use the arrow keys to move the north west drag handle to change the crop selection area",nDragHandle:"Use the up and down arrow keys to move the north drag handle to change the crop selection area",neDragHandle:"Use the arrow keys to move the north east drag handle to change the crop selection area",eDragHandle:"Use the up and down arrow keys to move the east drag handle to change the crop selection area",seDragHandle:"Use the arrow keys to move the south east drag handle to change the crop selection area",sDragHandle:"Use the up and down arrow keys to move the south drag handle to change the crop selection area",swDragHandle:"Use the arrow keys to move the south west drag handle to change the crop selection area",wDragHandle:"Use the up and down arrow keys to move the west drag handle to change the crop selection area"}};let g3=Wa;const l4="",r0=jo();function m3({altText:u,className:t,src:o,width:e,height:a,maxWidth:r,imageRef:n,startCrop:i,setStartCrop:l,isFocused:s,nodeKey:d}){const[c,p]=ve.useState(null),[f,h]=ve.useState(null),[g,m]=ve.useState({unit:"px",x:25,y:25,width:50,height:50}),[v]=Gn(),_=()=>{if(c){const y=n.current;if(!y||!c)return;const w=y.naturalWidth/y.width,E=y.naturalHeight/y.height,I=new OffscreenCanvas(c.width*w,c.height*E),j=I.getContext("2d");if(!j)throw new Error("No 2D context available");j.drawImage(y,c.x*w,c.y*E,c.width*w,c.height*E,0,0,c.width*w,c.height*E),I.convertToBlob({type:"image/png"}).then(B=>{const N=URL.createObjectURL(B);h(N),l(!1);const D=new FileReader;D.onload=()=>{const P=D.result;v.update(()=>{const k=Qn(d);xc(k)&&P&&k.setSrc(P)})},D.onerror=()=>{console.log("error")},D.readAsDataURL(B)})}},b=()=>{i||l(y=>{if(y===!1){const w=n.current;m({unit:"px",x:0,y:0,width:w.width,height:w.height})}return!y})},S=ve.useRef(null),C=ve.useRef(null);ve.useEffect(()=>{c&&(S.current=c)},[c]);const x=y=>{C.current&&!C.current.contains(y.target)&&l(!1)};return ve.useEffect(()=>(document.addEventListener("mousedown",x),()=>{document.removeEventListener("mousedown",x)}),[]),ke.jsxs("div",{ref:C,children:[s&&ke.jsx("button",{style:{zIndex:999},className:"image-caption-button",onClick:()=>b(),children:"Crop"}),i&&ke.jsx("button",{style:{zIndex:999},className:"image-caption-button",onClick:()=>_(),children:"Apply Crop"}),i?ke.jsx(g3,{crop:g,onChange:y=>m(y),onComplete:y=>p(y),children:ke.jsx("img",{className:t||void 0,src:f||o,alt:u,ref:n,style:{height:a,maxWidth:r,width:e},draggable:"false"})}):ke.jsx("img",{className:t||void 0,src:f||o,alt:u,ref:n,style:{height:a,maxWidth:r,width:e},draggable:"false"})]})}function y3({src:u,altText:t,nodeKey:o,width:e,height:a,maxWidth:r,resizable:n,showCaption:i,caption:l}){const s=ve.useRef(null),d=ve.useRef(null),[c,p,f]=oh(o),[h,g]=ve.useState(!1),[m]=Gn(),[v,_]=ve.useState(null),[b,S]=ve.useState(!1),C=ve.useRef(null),x=async A=>{const R=await(await fetch(A)).blob();return new Promise((J,T)=>{const H=new FileReader;H.readAsDataURL(R),H.onloadend=()=>{const W=H.result;J(W)},H.onerror=T})};ve.useEffect(()=>{/^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/i.test(u)&&x(u).then(L=>{m.update(()=>{const R=Qn(o);xc(R)&&L&&R.setSrc(L)})})},[u]);const y=ve.useCallback(A=>{if(c&&pr(Ot())){A.preventDefault();const R=Qn(o);if(xc(R))return R.remove(),!0}return!1},[c,o]),w=ve.useCallback(A=>{const L=Ot(),R=d.current;if(c&&pr(L)&&L.getNodes().length===1){if(i)return nr(null),A.preventDefault(),l.focus(),!0;if(R!==null&&R!==document.activeElement)return A.preventDefault(),R.focus(),!0}return!1},[l,c,i]),E=ve.useCallback(A=>C.current===l||d.current===A.target?(nr(null),m.update(()=>{p(!0);const L=m.getRootElement();L!==null&&L.focus()}),!0):!1,[l,m,p]),I=ve.useCallback(A=>{const L=A;return h?!0:L.target===s.current?(L.shiftKey?p(!c):(f(),p(!0)),!0):!1},[h,c,p,f]),j=ve.useCallback(A=>{m.getEditorState().read(()=>{const L=Ot();A.target.tagName==="IMG"&&xt(L)&&L.getNodes().length===1&&m.dispatchCommand(r0,A)})},[m]);ve.useEffect(()=>{let A=!0;const L=m.getRootElement(),R=Br(m.registerUpdateListener(({editorState:J})=>{A&&_(J.read(()=>Ot()))}),m.registerCommand(ti,(J,T)=>(C.current=T,!1),In),m.registerCommand(ma,I,In),m.registerCommand(r0,I,In),m.registerCommand(pl,J=>J.target===s.current?(J.preventDefault(),!0):!1,In),m.registerCommand(zs,y,In),m.registerCommand(Vi,y,In),m.registerCommand(ds,w,In),m.registerCommand(Fs,E,In));return L==null||L.addEventListener("contextmenu",j),()=>{A=!1,R(),L==null||L.removeEventListener("contextmenu",j)}},[f,m,h,c,o,y,w,E,I,j,p]);const B=()=>{m.update(()=>{const A=Qn(o);xc(A)&&A.setShowCaption(!0)})},N=(A,L)=>{setTimeout(()=>{g(!1)},200),m.update(()=>{const R=Qn(o);console.log(R,"node"),xc(R)&&R.setWidthAndHeight(A,L)})},D=()=>{b||g(!0)},P=c&&pr(v)&&!h,k=c||h;return ke.jsx(ve.Suspense,{fallback:null,children:ke.jsxs(ke.Fragment,{children:[ke.jsx("div",{draggable:P,children:ke.jsx(m3,{className:k?`focused ${pr(v)?"draggable":""}`:null,src:u,altText:t,width:e,height:a,maxWidth:r,imageRef:s,startCrop:b,setStartCrop:S,isFocused:k,nodeKey:o})}),i&&ke.jsx("div",{className:"image-caption-container",children:ke.jsx(WS,{initialEditor:l,children:ke.jsx(Op,{contentEditable:ke.jsx(t0,{className:"ImageNode__contentEditable"}),placeholder:ke.jsx(VS,{className:"ImageNode__placeholder",children:"Enter a caption..."}),ErrorBoundary:Ol})})}),!b&&n&&pr(v)&&k&&ke.jsx(d3,{showCaption:i,setShowCaption:B,editor:m,buttonRef:d,maxWidth:r,onResizeStart:b?()=>{}:D,onResizeEnd:b?()=>{}:N,captionsEnabled:!1,imageRef:s})]})})}const b3=Object.freeze(Object.defineProperty({__proto__:null,RIGHT_CLICK_IMAGE_COMMAND:r0,default:y3},Symbol.toStringTag,{value:"Module"})),GS=new Set;function v3(u){if(!GS.has(u))throw new Promise(t=>{const o=new Image;o.src=u,o.onload=()=>{GS.add(u),t(null)}})}function _3({altText:u,className:t,imageRef:o,src:e,width:a,height:r,position:n}){return v3(e),ke.jsx("img",{className:t||void 0,src:e,alt:u,ref:o,"data-position":n,style:{display:"block",height:r,width:a},draggable:"false"})}function YS({activeEditor:u,nodeKey:t,onClose:o}){const a=u.getEditorState().read(()=>Qn(t)),[r,n]=ve.useState(a.getAltText()),[i,l]=ve.useState(a.getShowCaption()),[s,d]=ve.useState(a.getPosition()),c=h=>{l(h.target.checked)},p=h=>{d(h.target.value)},f=()=>{const h={altText:r,position:s,showCaption:i};a&&u.update(()=>{a.update(h)}),o()};return ke.jsxs(ke.Fragment,{children:[ke.jsx("div",{style:{marginBottom:"1em"},children:ke.jsx(C1,{label:"Alt Text",placeholder:"Descriptive alternative text",onChange:n,value:r,"data-test-id":"image-modal-alt-text-input"})}),ke.jsxs(Dk,{style:{marginBottom:"1em",width:"208px"},value:s,label:"Position",name:"position",id:"position-select",onChange:p,children:[ke.jsx("option",{value:"left",children:"Left"}),ke.jsx("option",{value:"right",children:"Right"}),ke.jsx("option",{value:"full",children:"Full Width"})]}),ke.jsxs("div",{className:"Input__wrapper",children:[ke.jsx("input",{id:"caption",type:"checkbox",checked:i,onChange:c}),ke.jsx("label",{htmlFor:"caption",children:"Show Caption"})]}),ke.jsx(E1,{children:ke.jsx(Vs,{"data-test-id":"image-modal-file-upload-btn",onClick:()=>f(),children:"Confirm"})})]})}function x3({src:u,altText:t,nodeKey:o,width:e,height:a,showCaption:r,caption:n,position:i}){const[l,s]=Sp(),d=ve.useRef(null),c=ve.useRef(null),[p,f,h]=oh(o),[g]=Gn(),[m,v]=ve.useState(null),_=ve.useRef(null),b=ve.useCallback(w=>{if(p&&pr(Ot())){w.preventDefault();const I=Qn(o);if(a1(I))return I.remove(),!0}return!1},[p,o]),S=ve.useCallback(w=>{const E=Ot(),I=c.current;if(p&&pr(E)&&E.getNodes().length===1){if(r)return nr(null),w.preventDefault(),n.focus(),!0;if(I!==null&&I!==document.activeElement)return w.preventDefault(),I.focus(),!0}return!1},[n,p,r]),C=ve.useCallback(w=>_.current===n||c.current===w.target?(nr(null),g.update(()=>{f(!0);const E=g.getRootElement();E!==null&&E.focus()}),!0):!1,[n,g,f]);ve.useEffect(()=>{let w=!0;const E=Br(g.registerUpdateListener(({editorState:I})=>{w&&v(I.read(()=>Ot()))}),g.registerCommand(ti,(I,j)=>(_.current=j,!1),In),g.registerCommand(ma,I=>{const j=I;return j.target===d.current?(j.shiftKey?f(!p):(h(),f(!0)),!0):!1},In),g.registerCommand(pl,I=>I.target===d.current?(I.preventDefault(),!0):!1,In),g.registerCommand(zs,b,In),g.registerCommand(Vi,b,In),g.registerCommand(ds,S,In),g.registerCommand(Fs,C,In));return()=>{w=!1,E()}},[h,g,p,o,b,S,C,f]);const x=p&&pr(m),y=p;return ke.jsxs(ve.Suspense,{fallback:null,children:[ke.jsxs(ke.Fragment,{children:[ke.jsxs("div",{draggable:x,children:[ke.jsx("button",{className:"image-edit-button",ref:c,onClick:()=>{s("Update Inline Image",w=>ke.jsx(YS,{activeEditor:g,nodeKey:o,onClose:w}))},children:"Edit"}),ke.jsx(_3,{className:y?`focused ${pr(m)?"draggable":""}`:null,src:u,altText:t,imageRef:d,width:e,height:a,position:i})]}),r&&ke.jsx("div",{className:"image-caption-container",children:ke.jsx(WS,{initialEditor:n,children:ke.jsx(Op,{contentEditable:ke.jsx(t0,{className:"InlineImageNode__contentEditable"}),placeholder:ke.jsx(VS,{className:"InlineImageNode__placeholder",children:"Enter a caption..."}),ErrorBoundary:Ol})})})]}),l]})}const w3=Object.freeze(Object.defineProperty({__proto__:null,UpdateInlineImageDialog:YS,default:x3},Symbol.toStringTag,{value:"Module"}));Ho.Editor=s3,Ho.EditorVariant2=l3,Object.defineProperty(Ho,Symbol.toStringTag,{value:"Module"})});
1518
1518
  //# sourceMappingURL=index.umd.js.map