1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[604],{69691:function(e,t,n){let o;n.d(t,{KU:function(){return oT},L9:function(){return oC},YH:function(){return ev},_F:function(){return eI},iV:function(){return oI},q$:function(){return oh}});var i=n(65490),r=n(67294),a=n(57301),l=n(33882),s=n(85893),c=n(94445),d=n(45289),p=n(77493),u=n(96391),h=n(11227),f=n(50387),y=n(29400),g=n(63677),m=n(83356),k=n(85344),v=n(43956),b=n(4527),x=n(7922),_=n(69369),E=n(98284),w=n(81943),S=n(43401),O=n(2674),M=n(30368),R=n(86235),N=n(303),A=n(12565),I=n(73190),T=n(69692),C=n(14845),B=n(64540),D=n(23077),j=n(86065),Y=n(29708),U=n(52436),L=n(50994),z=n(731),$=n(23207),P=n(7071),G=n(20070),F=n(17181);let K="sanity-pte:";function V(e){let t=`${K}${e}`;return h&&h.enabled(t)?h(t):h(K)}h(K);let W="void-child";function J(e,t){let n=t[e._key];return n&&m(e,n)?n:(t[e._key]=e,e)}function q(e,{schemaTypes:t},n={}){return e&&Array.isArray(e)?e.map(e=>{let{_type:o,_key:i,...r}=e;if(e&&e._type===t.block.name){let a=!1,l=typeof e.style>"u",s=typeof e.markDefs>"u",c=typeof e.children>"u",d=(e.children||[]).map(e=>{let{_type:t,_key:o,...i}=e;return"span"!==t?(a=!0,J({_type:t,_key:o,children:[{_key:W,_type:"span",text:"",marks:[]}],value:i,__inline:!0},n)):e});return!(!l&&!s&&!c&&!a&&p.W_.isElement(e))?(l&&(r.style=t.styles[0].name),J({_type:o,_key:i,...r,children:d},n)):e}return J({_type:o,_key:i,children:[{_key:W,_type:"span",text:"",marks:[]}],value:r},n)}):[]}function H(e,t,n={}){return e.map(e=>{let{_key:o,_type:i}=e;if(!o||!i)throw Error("Not a valid block");if(i===t&&"children"in e&&Array.isArray(e.children)&&o){let t=!1,r=e.children.map(e=>{let{_type:o}=e;if("value"in e&&"span"!==o){t=!0;let{value:o,_key:i,_type:r,__inline:a,children:l,...s}=e;return J({...s,...o,_key:i,_type:r},n)}return e});return t?J({...e,children:r,_key:o,_type:i},n):e}let r="value"in e&&e.value;return J({_key:o,_type:i,..."object"==typeof r?r:{}},n)})}function X(e,t){return void 0===e||e&&Array.isArray(e)&&0===e.length||e&&Array.isArray(e)&&1===e.length&&p.W_.isElement(e[0])&&e[0]._type===t.block.name&&"style"in e[0]&&e[0].style===t.styles[0].name&&!("listItem"in e[0])&&Array.isArray(e[0].children)&&1===e[0].children.length&&p.xv.isText(e[0].children[0])&&"span"===e[0].children[0]._type&&!e[0].children[0].marks?.join("")&&""===e[0].children[0].text}function Z({editor:e,_key:t}){let[,n]=Array.from(p.ML.nodes(e,{at:[],match:e=>e._key===t})).at(0)??[void 0,void 0],o=n?.at(0);if(void 0!==o)return[o]}function Q({editor:e}){if(!e.selection)return[void 0,void 0];try{return p.ML.node(e,e.selection.focus.path.slice(0,1))??[void 0,void 0]}catch{return[void 0,void 0]}}function ee({editor:e,point:t}){try{let[n]=p.ML.node(e,t.path.slice(0,1))??[void 0,void 0];return n?[n,t.path.slice(0,1)]:[void 0,void 0]}catch{return[void 0,void 0]}}function et({editor:e,point:t}){let[n,o]=ee({editor:e,point:t}),i=t.path.at(1);if(!n||!o||void 0===i)return[void 0,void 0];try{let e=p.NB.child(n,i);return e?[e,[...o,i]]:[void 0,void 0]}catch{return[void 0,void 0]}}function en({editor:e}){if(0===e.children.length)return[void 0,void 0];let t=p.ML.end(e,[]).path.at(0);try{return void 0!==t?p.ML.node(e,[t])??[void 0,void 0]:[void 0,void 0]}catch{return[void 0,void 0]}}function eo({schema:e,element:t}){return H([t],e.block.name)?.at(0)}function ei({editor:e,schema:t},n){return p.W_.isElement(n)&&!e.isInline(n)&&(t.block.name===n._type||t.blockObjects.some(e=>e.name===n._type))}function er({schema:e,editor:t,range:n}){let[o]=ee({editor:t,point:n.anchor}),[i]=ee({editor:t,point:n.focus});if(!o||!i)return null;let[r]=o._type===e.block.name?et({editor:t,point:n.anchor}):[void 0,void 0],[a]=i._type===e.block.name?et({editor:t,point:n.focus}):[void 0,void 0],l={anchor:{path:[{_key:o._key}],offset:n.anchor.offset},focus:{path:[{_key:i._key}],offset:n.focus.offset},backward:p.e6.isBackward(n)};return r&&(l.anchor.path.push("children"),l.anchor.path.push({_key:r._key})),a&&(l.focus.path.push("children"),l.focus.path.push({_key:a._key})),l}function ea({editorActor:e,slateEditor:t,event:n}){if(e.getSnapshot().matches({setup:"setting up"}))return;let o=function({slateEditor:e,event:t}){return f.y2.hasTarget(e,t.target)?f.y2.toSlateNode(e,t.target):void 0}({slateEditor:t,event:n});if(!o)return;
1let i=function({editor:e,schema:t,node:n}){if(p.ML.isEditor(n))return;if(ei({editor:e,schema:t},n))return eo({schema:t,element:n});let o=Array.from(p.ML.nodes(e,{mode:"highest",at:[],match:o=>ei({editor:e,schema:t},o)&&o.children.some(e=>e._key===n._key)})).at(0)?.at(0);return p.W_.isElement(o)?eo({schema:t,element:o}):void 0}({editor:t,schema:e.getSnapshot().context.schema,node:o}),r=function({node:e,slateEditor:t,event:n}){let[o]=function({editor:e}){if(0===e.children.length)return[void 0,void 0];let t=p.ML.start(e,[]).path.at(0);try{return void 0!==t?p.ML.node(e,[t])??[void 0,void 0]:[void 0,void 0]}catch{return[void 0,void 0]}}({editor:t});if(!o)return;let i=f.y2.toDOMNode(t,o).getBoundingClientRect();if(n.pageY<i.top)return"start";let[r]=en({editor:t});if(!r)return;let a=f.y2.toDOMNode(t,r).getBoundingClientRect();if(n.pageY>a.bottom)return"end";let l=f.y2.toDOMNode(t,e).getBoundingClientRect(),s=l.top,c=l.height;return Math.abs(s-n.pageY)<c/2?"start":"end"}({node:o,slateEditor:t,event:n}),a=function({schema:e,slateEditor:t,event:n}){let o=function(e,t){let n,o;if(!t.target||!(0,f.uF)(t.target))return;let i=f.y2.getWindow(e);if(void 0!==i.document.caretPositionFromPoint){let e=i.document.caretPositionFromPoint(t.clientX,t.clientY);if(e)try{(n=i.document.createRange()).setStart(e.offsetNode,e.offset),n.setEnd(e.offsetNode,e.offset)}catch{}}else if(void 0!==i.document.caretRangeFromPoint)n=i.document.caretRangeFromPoint(t.clientX,t.clientY)??void 0;else{console.warn("Neither caretPositionFromPoint nor caretRangeFromPoint is supported");return}if(n){try{o=f.y2.toSlateRange(e,n,{exactMatch:!1,suppressThrow:!1})}catch{}return o}}(t,n);return o?er({schema:e,editor:t,range:o}):null}({schema:e.getSnapshot().context.schema,slateEditor:t,event:n});if(i&&r&&!a&&!p.ML.isEditor(o))return{block:r,isEditor:!1,selection:{anchor:(0,y.qv)({context:e.getSnapshot().context,block:{node:i,path:[{_key:i._key}]}}),focus:(0,g.sQ)({context:e.getSnapshot().context,block:{node:i,path:[{_key:i._key}]}})}};if(!r||!a)return;let l=(0,y.Ak)(a.focus);if(void 0!==l)return(0,g.dI)(a)&&i&&l!==i._key?{block:r,isEditor:!1,selection:{anchor:(0,y.qv)({context:e.getSnapshot().context,block:{node:i,path:[{_key:i._key}]}}),focus:(0,g.sQ)({context:e.getSnapshot().context,block:{node:i,path:[{_key:i._key}]}})}}:{block:r,isEditor:p.ML.isEditor(o),selection:a}}function el(e,t){if(!e||!t)return null;let n=[],o=e.offset||0,i="object"==typeof e.path[0]&&"_key"in e.path[0]&&e.path[0]._key,r="object"==typeof e.path[2]&&"_key"in e.path[2]&&e.path[2]._key,a=t.find(e=>e._key===i);if(!a)return null;if(n.push({_key:a._key}),a&&"children"===e.path[1]){if(!a.children||Array.isArray(a.children)&&0===a.children.length)return null;let t=Array.isArray(a.children)&&a.children.find(e=>e._key===r);if(!t)return null;n.push("children"),n.push({_key:t._key}),o=t.text&&t.text.length>=e.offset?e.offset:t.text&&t.text.length||0}return{path:n,offset:o}}function es(e){if(!e.context.selection)return null;if((0,g.Gh)(e.context.selection.anchor,e.context.selection.focus)){let t=ec(e,e.context.selection.anchor,e.context.selection.backward?"forward":"backward");return t?{anchor:t,focus:t}:null}let t=ec(e,e.context.selection.anchor,e.context.selection.backward?"forward":"backward"),n=ec(e,e.context.selection.focus,e.context.selection.backward?"backward":"forward");return t&&n?{anchor:t,focus:n}:null}function ec(e,t,n){let o=(0,y.Ak)(t);if(!o)return;let i=e.blockIndexMap.get(o);if(void 0===i)return;let r=e.context.value.at(i);if(!r)return;if(!(0,y.dz)(e.context,r))return{path:[i,0],offset:0};let a=(0,y.NX)({path:t.path}),l=a?void 0:(0,y.MR)({context:{schema:e.context.schema,value:[r]},blockOffset:{path:[{_key:o}],offset:t.offset},direction:n});if(!(a=l?(0,y.NX)(l):a))return{path:[i,0],offset:0};let s=l?.offset??t.offset,c=[],d=-1,p;for(let t of r.children)if(d++,t._key===a){p=t,(0,y.dn)(e.context,t)?c=[d]:(c=[d,0],s=0);break}return 0===c.length?{path:[i,0],offset:0}:{path:[i].concat(c),offset:(0,y.dn)(e.context,p)?Math.min(p.text.length,s):s}}let ed=new WeakMap,ep=new WeakMap,eu=new WeakMap,eh=new WeakMap,ef=(0,r.createContext)({});function ey(){let e;let t=(0,i.c)(1);return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=(0,s.jsx)("div",{contentEditable:!1,
1className:"pt-drop-indicator",style:{position:"absolute",width:"100%",height:1,borderBottom:"1px solid currentColor",zIndex:5},children:(0,s.jsx)("span",{})}),t[0]=e):e=t[0],e}function eg(e){let t,n;let o=(0,i.c)(4);return o[0]===Symbol.for("react.memo_cache_sentinel")?(t={userSelect:"none"},o[0]=t):t=o[0],o[1]!==e.blockObject._key||o[2]!==e.blockObject._type?(n=(0,s.jsxs)("div",{style:t,children:["[",e.blockObject._type,": ",e.blockObject._key,"]"]}),o[1]=e.blockObject._key,o[2]=e.blockObject._type,o[3]=n):n=o[3],n}function em(e){let t,n;let o=(0,i.c)(4);return o[0]===Symbol.for("react.memo_cache_sentinel")?(t={userSelect:"none"},o[0]=t):t=o[0],o[1]!==e.inlineObject._key||o[2]!==e.inlineObject._type?(n=(0,s.jsxs)("span",{style:t,children:["[",e.inlineObject._type,": ",e.inlineObject._key,"]"]}),o[1]=e.inlineObject._key,o[2]=e.inlineObject._type,o[3]=n):n=o[3],n}function ek({eventSelection:e,snapshot:t}){let n=e;if((0,v.fX)({...t,context:{...t.context,selection:e}}))return n;let o=(0,k.dI)({context:{...t.context,selection:e}}),i=(0,k.I3)({...t,context:{...t.context,selection:e}}),r=(0,k.Cj)({...t,context:{...t.context,selection:e}});o&&i&&r&&(n={anchor:(0,y.qv)({context:t.context,block:i}),focus:(0,g.sQ)({context:t.context,block:i})});let a=(0,v.wD)(t);if(t.context.selection&&(0,k.sC)(t)&&a.length>1){let o=(0,v.Dm)(t),i=(0,v.Zq)(t);if(!o||!i)return n;let r=(0,y.qv)({context:t.context,block:o}),a=(0,g.sQ)({context:t.context,block:i});(0,v.Mf)(e)({...t,context:{...t.context,selection:{anchor:r,focus:a}}})&&(n={anchor:r,focus:a})}return n}let ev=()=>(function(e){let t=eb();return(function(e=16){let t=new Uint8Array(e);return(0,b.Z)(t),t})(12).reduce((e,n)=>e+t[n],"").slice(0,12)})(12),eb=()=>{if(o)return o;o=[];for(let e=0;e<256;++e)o[e]=(e+256).toString(16).slice(1);return o};function ex(e){return{id:ev(),name:e?.name,reference:e?.reference}}let e_=ex({name:"core"});function eE(e){let t,n;let o=(0,i.c)(5),{key:a,onSetDragPositionBlock:l}=e,s=(0,r.useContext)(ef);o[0]!==s||o[1]!==a||o[2]!==l?(t=()=>{let e=function({key:e,onSetDragPositionBlock:t}){return[{behavior:(0,x.gg)({on:"drag.dragover",guard:({snapshot:t,event:n})=>{let o=(0,k.tT)({...t,context:{...t.context,selection:n.position.selection}});if(!o||o.node._key!==e)return!1;let i=n.dragOrigin;if(!i)return!1;let r=ek({eventSelection:i.selection,snapshot:t});return!(0,v.wD)({...t,context:{...t.context,selection:r}}).some(t=>t.node._key===e)&&(0,v.u7)({...t,context:{...t.context,selection:r}})},actions:[({event:e})=>[{type:"effect",effect:()=>{t(e.position.block)}}]]}),priority:ex({reference:{priority:e_,importance:"lower"}})},{behavior:(0,x.gg)({on:"drag.*",guard:({event:e})=>"drag.dragover"!==e.type,actions:[({event:e})=>[{type:"effect",effect:()=>{t(void 0)}},(0,x.eH)(e)]]}),priority:ex({reference:{priority:e_,importance:"lower"}})}]}({key:a,onSetDragPositionBlock:l});for(let t of e)s.send({type:"add behavior",behaviorConfig:t});return()=>{for(let t of e)s.send({type:"remove behavior",behaviorConfig:t})}},n=[s,a,l],o[0]=s,o[1]=a,o[2]=l,o[3]=t,o[4]=n):(t=o[3],n=o[4]),(0,r.useEffect)(t,n)}function ew(e){let[t,n]=(0,r.useState)(),o=(0,r.useRef)(null),i=(0,u.vt)(),a=(0,u.b_)(e=>i&&null!==e.selection&&p.e6.isCollapsed(e.selection));eE({key:e.element._key,onSetDragPositionBlock:n});let l=e.legacySchema.blockObjects.find(t=>t.name===e.element._type);l||console.error(`Unable to find Block Object "${e.element._type}" in Schema`);let c=e.blockObject??{_key:e.element._key,_type:e.element._type};return(0,s.jsxs)("div",{...e.attributes,className:"pt-block pt-object-block","data-block-key":e.element._key,"data-block-name":e.element._type,"data-block-type":"object",children:["start"===t?(0,s.jsx)(ey,{}):null,e.children,(0,s.jsx)("div",{ref:o,contentEditable:!1,draggable:!e.readOnly,children:e.renderBlock&&l?e.renderBlock({children:(0,s.jsx)(eg,{blockObject:c}),editorElementRef:o,focused:a,path:[{_key:e.element._key}],schemaType:l,selected:i,type:l,value:c}):(0,s.jsx)(eg,{blockObject:c})}),"end"===t?(0,s.jsx)(ey,{}):null]})}function eS(e){let t=(0,r.useRef)(null),n=(0,u._7)(),o=(0,u.vt)(),i=(0,u.b_)(e=>o&&null!==e.selection&&p.e6.isCollapsed(e.selection)),a=e.legacySchema.inlineObjects.find(t=>t.name===e.element._type);a||console.error(`Unable to find Inline Object "${e.element._type}" in Schema`);let l=f.y2.findPath(n,e.element),[c]=ee({editor:n,point:{path:l,offset:0}});c||console.error(`Unable to find parent block of inline object ${e.element._key}`);let d={_key:e.element._key,_type:e.element._type,..."value"in e.element&&"object"==typeof e.element.value?e.element.value:{}};return(0,s.jsxs)("span",{...e.attributes,draggable:!e.readOnly,className:"pt-inline-object","data-child-key":d._key,"data-child-name":d._type,"data-child-type":"object",children:[e.children,(0,s.jsx)("span",{ref:t,style:{display:"inline-block"},children:e.renderChild&&c&&a?e.renderChild({annotations:[],children:(0,s.jsx)(em,{inlineObject:d}),editorElementRef:t,selected:o,focused:i,path:[{_key:c._key},"children",{_key:e.element._key}],schemaType:a,value:d,type:a}):(0,s.jsx)(em,{inlineObject:d})})]})}function eO(e){let[t,n]=(0,r.useState)(),o=(0,r.useRef)(null),i=(0,u.vt)(),a=(0,u.b_)(e=>i&&null!==e.selection&&p.e6.isCollapsed(e.selection));eE({key:e.element._key,onSetDragPositionBlock:n});let l=(0,u.b_)(t=>t.listIndexMap.get(e.textBlock._key)),c=e.children;if(e.renderStyle&&e.textBlock.style){let t=void 0!==e.textBlock.style?e.legacySchema.styles.find(t=>t.value===e.textBlock.style):void 0;t?c=e.renderStyle({block:e.textBlock,children:c,editorElementRef:o,focused:a,path:[{_key:e.textBlock._key}],schemaType:t,selected:i,value:e.textBlock.style}):console.error(`Unable to find Schema type for text block style ${e.textBlock.style}`)}if(e.renderListItem&&e.textBlock.listItem){let t=e.legacySchema.lists.find(t=>t.value===e.textBlock.listItem);t?c=e.renderListItem({block:e.textBlock,children:c,editorElementRef:o,focused:a,level:e.textBlock.level??1,path:[{_key:e.textBlock._key}],selected:i,value:e.textBlock.listItem,schemaType:t}):console.error(`Unable to find Schema type for text block list item ${e.textBlock.listItem}`)}return(0,s.jsxs)("div",{...e.attributes,className:["pt-block","pt-text-block",...e.textBlock.style?[`pt-text-block-style-${e.textBlock.style}`]:[],...e.textBlock.listItem?["pt-list-item",`pt-list-item-${e.textBlock.listItem}`,`pt-list-item-level-${e.textBlock.level??1}`]:[]].join(" "),spellCheck:e.spellCheck,"data-block-key":e.textBlock._key,"data-block-name":e.textBlock._type,"data-block-type":"text",...void 0!==e.textBlock.listItem?{"data-list-item":e.textBlock.listItem}:{},...void 0!==e.textBlock.level?{"data-level":e.textBlock.level}:{},...void 0!==e.textBlock.style?{"data-style":e.textBlock.style}:{},...void 0!==l?{"data-list-index":l}:{},children:["start"===t?(0,s.jsx)(ey,{}):null,(0,s.jsx)("div",{ref:o,children:e.renderBlock?e.renderBlock({children:c,editorElementRef:o,focused:a,level:e.textBlock.level,listItem:e.textBlock.listItem,path:[{_key:e.textBlock._key}],selected:i,schemaType:e.legacySchema.block,style:e.textBlock.style,type:e.legacySchema.block,value:e.textBlock}):c}),"end"===t?(0,s.jsx)(ey,{}):null]})}function eM(e){let t,n,o;let a=(0,i.c)(34),l=(0,r.useContext)(ef),d=(0,c.v9)(l,eN),p=(0,c.v9)(l,eR),h=(0,u._7)();if("__inline"in e.element&&!0===e.element.__inline){let t;return a[0]!==p||a[1]!==e.attributes||a[2]!==e.children||a[3]!==e.element||a[4]!==e.readOnly||a[5]!==e.renderChild||a[6]!==d?(t=(0,s.jsx)(eS,{attributes:e.attributes,element:e.element,legacySchema:p,readOnly:e.readOnly,renderChild:e.renderChild,schema:d,children:e.children}),a[0]=p,a[1]=e.attributes,a[2]=e.children,a[3]=e.element,a[4]=e.readOnly,a[5]=e.renderChild,a[6]=d,a[7]=t):t=a[7],t}if(a[8]!==e.element._key||a[9]!==d||a[10]!==h.blockIndexMap||a[11]!==h.value){let o=h.blockIndexMap.get(e.element._key);t=void 0!==o?h.value.at(o):void 0,n=(0,y.dz)({schema:d},t),a[8]=e.element._key,a[9]=d,a[10]=h.blockIndexMap,a[11]=h.value,a[12]=t,a[13]=n}else t=a[12],n=a[13];if(n){let n;return a[14]!==t||a[15]!==p||a[16]!==e.attributes||a[17]!==e.children||a[18]!==e.element||a[19]!==e.readOnly||a[20]!==e.renderBlock||a[21]!==e.renderListItem||a[22]!==e.renderStyle||a[23]!==e.spellCheck?(n=(0,s.jsx)(eO,{attributes:e.attributes,element:e.element,legacySchema:p,readOnly:e.readOnly,renderBlock:e.renderBlock,renderListItem:e.renderListItem,render
1Style:e.renderStyle,spellCheck:e.spellCheck,textBlock:t,children:e.children}),a[14]=t,a[15]=p,a[16]=e.attributes,a[17]=e.children,a[18]=e.element,a[19]=e.readOnly,a[20]=e.renderBlock,a[21]=e.renderListItem,a[22]=e.renderStyle,a[23]=e.spellCheck,a[24]=n):n=a[24],n}return a[25]!==t||a[26]!==p||a[27]!==e.attributes||a[28]!==e.children||a[29]!==e.element||a[30]!==e.readOnly||a[31]!==e.renderBlock||a[32]!==d?(o=(0,s.jsx)(ew,{attributes:e.attributes,blockObject:t,element:e.element,legacySchema:p,readOnly:e.readOnly,renderBlock:e.renderBlock,schema:d,children:e.children}),a[25]=t,a[26]=p,a[27]=e.attributes,a[28]=e.children,a[29]=e.element,a[30]=e.readOnly,a[31]=e.renderBlock,a[32]=d,a[33]=o):o=a[33],o}function eR(e){return e.context.getLegacySchema()}function eN(e){return e.context.schema}let eA=(0,r.createContext)(null),eI=()=>{let e=(0,r.useContext)(eA);if(!e)throw Error("The `usePortableTextEditor` hook must be used inside the <PortableTextEditor> component's context.");return e},eT=(e,t)=>{t(e);let n=e.getSnapshot().children;n&&Object.values(n).forEach(e=>{eT(e,t)})};function eC(e){let t=[];eT(e,e=>{t.push([e,e.getSnapshot()]),e.observers=new Set});let n=e.system.getSnapshot?.();e.stop(),e.system._snapshot=n,t.forEach(([e,t])=>{e._processingStatus=0,e._snapshot=t})}let eB={mimeType:"application/json",serialize:({snapshot:e,event:t})=>{let n=e.context.converters.find(e=>"application/x-portable-text"===e.mimeType);return n?{...n.serialize({snapshot:e,event:t}),mimeType:"application/json",originEvent:t.originEvent}:{type:"serialization.failure",mimeType:"application/json",originEvent:t.originEvent,reason:"No application/x-portable-text Converter found"}},deserialize:({snapshot:e,event:t})=>{let n=e.context.converters.find(e=>"application/x-portable-text"===e.mimeType);return n?{...n.deserialize({snapshot:e,event:t}),mimeType:"application/json"}:{type:"deserialization.failure",mimeType:"application/json",reason:"No application/x-portable-text Converter found"}}},eD={mimeType:"application/x-portable-text",serialize:({snapshot:e,event:t})=>{if(!e.context.selection)return{type:"serialization.failure",mimeType:"application/x-portable-text",originEvent:t.originEvent,reason:"No selection"};let n=(0,k.Ly)(e);return 0===n.length?{type:"serialization.failure",mimeType:"application/x-portable-text",reason:"No blocks serialized",originEvent:t.originEvent}:{type:"serialization.success",data:JSON.stringify(n),mimeType:"application/x-portable-text",originEvent:t.originEvent}},deserialize:({snapshot:e,event:t})=>{let n=JSON.parse(t.data);if(!Array.isArray(n))return{type:"deserialization.failure",mimeType:"application/x-portable-text",reason:"Data is not an array"};let o=n.flatMap(t=>{let n=(0,y.IX)({context:e.context,block:t,options:{refreshKeys:!0,validateFields:!1}});return n?[n]:[]});return 0===o.length&&n.length>0?{type:"deserialization.failure",mimeType:"application/x-portable-text",reason:"No blocks were parsed"}:{type:"deserialization.success",data:o,mimeType:"application/x-portable-text"}}},ej={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="},eY=new Map;function eU(e,{blockIndexMap:t,listIndexMap:n}){let o;t.clear(),n.clear(),eY.clear();for(let i=0;i<e.value.length;i++){let r=e.value.at(i);if(void 0!==r){if(t.set(r._key,i),!(0,y.dz)(e,r)||void 0===r.listItem||void 0===r.level){eY.clear(),o=void 0;continue}if(!o){o={listItem:r.listItem,level:r.level},eY.set(r.level,1),n.set(r._key,1);continue}if(o.listItem!==r.listItem){eY.clear(),o={listItem:r.listItem,level:r.level},eY.set(r.level,1),n.set(r._key,1);continue}if(o.level===r.level){let e=eY.get(r.level)??0;eY.set(r.level,e+1),o={listItem:r.listItem,level:r.level},n.set(r._key,e+1);continue}if(o.level<r.level){eY.set(r.level,1),o={listItem:r.listItem,level:r.level},n.set(r._key,1);continue}if(o.level>r.level){let e=eY.get(r.level)??0;eY.set(r.level,e+1),o={listItem:r.listItem,level:r.level},n.set(r._key,e+1)}}}}function eL(e){return{_type:e.schema.block.name,_key:e.keyGenerator(),style:e.schema.styles[0].name??"normal",markDefs:[],children:[{_type:e.schema.span.name,_key:e.keyGenerator(),text:"",marks:[]}]}}let ez=({context:e,operation:t})=>{let n={blockIndexMap:t.editor.blockIndexMap,context:{value:t.editor.value,selection:t.editor.selection?er({schema:e.schema,editor:t.editor,range:t.editor.selection}
1):null,schema:e.schema,keyGenerator:e.keyGenerator,converters:[],readOnly:!1},decoratorState:t.editor.decoratorState},o=(0,v.zd)(n),i=(0,v.WH)(n),r=(0,v.YG)(n),[a]=function({editor:e}){if(!e.selection)return[void 0,void 0];try{let[t,n]=p.ML.node(e,e.selection.focus.path);if(e.isTextSpan(t))return[t,n]}catch{}return[void 0,void 0]}({editor:t.editor});if(!a){p.YR.insertText(t.editor,t.text);return}if(o&&"unchanged"===o.state){let n=(o.marks??[]).filter(t=>e.schema.decorators.map(e=>e.name).includes(t));if(n.length===i.length&&n.every(e=>i.includes(e))){p.YR.insertText(t.editor,t.text);return}}p.YR.insertNodes(t.editor,{_type:a._type,_key:e.keyGenerator(),text:t.text,marks:[...i,...r]}),t.editor.decoratorState={}};function e$(e){return"span"===e._type&&"text"in e&&"string"==typeof e.text&&(typeof e.marks>"u"||Array.isArray(e.marks)&&e.marks.every(e=>"string"==typeof e))}function eP({editor:e,blockPath:t,spanPath:n}){let o;for(let[i,r]of p.NB.children(e,t,{reverse:!0}))if(e.isTextSpan(i)&&p.y$.isBefore(r,n)){o=i;break}return o}function eG({editor:e,blockPath:t,spanPath:n}){let o;for(let[i,r]of p.NB.children(e,t))if(e.isTextSpan(i)&&p.y$.isAfter(r,n)){o=i;break}return o}function eF(e,t){let n=eK(e)||!1;ed.set(e,!0),t(),ed.set(e,n)}function eK(e){return ed.get(e)}let eV=new WeakMap,eW=new WeakMap;function eJ(e){return eV.get(e)??!1}function eq(e){return eW.get(e)??!1}function eH({editorActorSnapshot:e,slateEditorInstance:t}){return{blockIndexMap:t.blockIndexMap,context:{converters:[...e.context.converters],keyGenerator:e.context.keyGenerator,readOnly:e.matches({"edit mode":"read only"}),schema:e.context.schema,selection:e.context.selection,value:t.value},decoratorState:t.decoratorState}}let eX=V("plugin:withPortableTextMarkModel");function eZ(e){let[t,n]=e;return[t,n]}function eQ(e,t){let n=e,o=t,i=n.length,r=o.length;if(0===i||0===r)return 0;i>r?n=n.substring(i-r):i<r&&(o=o.substring(0,i));let a=Math.min(i,r);if(n===o)return a;let l=0,s=1;for(let e=0;-1!==e;){let t=n.substring(a-s);if(-1===(e=o.indexOf(t)))break;s+=e,(0===e||n.substring(a-s)===o.substring(0,s))&&(l=s,s++)}return l}function e0(e,t){if(!e||!t||e[0]!==t[0])return 0;let n=0,o=Math.min(e.length,t.length),i=o,r=0;for(;n<i;)e.substring(r,i)===t.substring(r,i)?r=n=i:o=i,i=Math.floor((o-n)/2+n);return i}function e1(e,t){if(!e||!t||e[e.length-1]!==t[t.length-1])return 0;let n=0,o=Math.min(e.length,t.length),i=o,r=0;for(;n<i;)e.substring(e.length-i,e.length-r)===t.substring(t.length-i,t.length-r)?r=n=i:o=i,i=Math.floor((o-n)/2+n);return i}function e2(e,t,n,o,i){let r=e.substring(0,n),a=t.substring(0,o),l=e.substring(n),s=t.substring(o),c=tt(r,a,{checkLines:!1,deadline:i}),d=tt(l,s,{checkLines:!1,deadline:i});return c.concat(d)}function e3(e,t,n){let o=e.slice(n,n+Math.floor(e.length/4)),i=-1,r="",a,l,s,c;for(;-1!==(i=t.indexOf(o,i+1));){let o=e0(e.slice(n),t.slice(i)),d=e1(e.slice(0,n),t.slice(0,i));r.length<d+o&&(r=t.slice(i-d,i)+t.slice(i,i+o),a=e.slice(0,n-d),l=e.slice(n+o),s=t.slice(0,i-d),c=t.slice(i+o))}return 2*r.length>=e.length?[a||"",l||"",s||"",c||"",r||""]:null}var e8=Object.defineProperty,e6=Object.getOwnPropertySymbols,e9=Object.prototype.hasOwnProperty,e4=Object.prototype.propertyIsEnumerable,e5=(e,t,n)=>t in e?e8(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,e7=(e,t)=>{for(var n in t||(t={}))e9.call(t,n)&&e5(e,n,t[n]);if(e6)for(var n of e6(t))e4.call(t,n)&&e5(e,n,t[n]);return e};function te(e,t,n){var o,i;let r;if(null===e||null===t)throw Error("Null input. (diff)");let a=tt(e,t,e7({checkLines:!0,deadline:(i=(o=n||{}).timeout||1,r=1,"u">typeof i&&(r=i<=0?Number.MAX_VALUE:i),Date.now()+1e3*r)},o));return function(e){for(let t=0;t<e.length;t++){let[n,o]=e[t];if(0===o.length)continue;let i=o[0];(function(e){let t=e.charCodeAt(0);return t>=55296&&t<=56319})(o[o.length-1])&&0===n&&ti(e,t,1),function(e){let t=e.charCodeAt(0);return t>=56320&&t<=57343}(i)&&0===n&&ti(e,t,-1)}for(let t=0;t<e.length;t++)0===e[t][1].length&&e.splice(t,1)}(a),a}function tt(e,t,n){let o=e,i=t;if(o===i)return o?[[0,o]]:[];let r=e0(o,i),a=o.substring(0,r);r=e1(o=o.substring(r),i=i.substring(r));let l=o.substring(o.length-r),s=function(e,t,n){let o;if(!e)return[[1,t]];if(!t)return[[-1,e]];let i=e.length>t.length?e:t,r=e.length>t.length?t:e,a=i.indexOf(r);if(-1!==a)return o=[[1,i.substring(0,a)],[0,r],[1,i.substring(a+r.length)]],e.length>t.length&&(o[0][0]=-1,o[2][0]=-1),o;if(1===r.length)return[[-1,e],[1,t]];let l=function(e,t,n=1){let o,i,r,a,l;if(n<=0)return null;let s=e.length>t.length?e:t,c=e.length>t.length?t:e;if(s.length<4||2*c.length<s.length)return null;let d=e3(s,c,Math.ceil(s.length/4)),p=e3(s,c,Math.ceil(s.length/2));if(d&&p)o=d[4].length>p[4].length?d:p;else{if(!d&&!p)return null;p?d||(o=p):o=d}if(!o)throw Error("Unable to find a half match.");return e.length>t.length?(i=o[0],r=o[1],a=o[2],l=o[3]):(a=o[0],l=o[1],i=o[2],r=o[3]),[i,r,a,l,o[4]]}(e,t);if(l){let e=l[0],t=l[1],o=l[2],i=l[3],r=l[4],a=tt(e,o,n),s=tt(t,i,n);return a.concat([[0,r]],s)}return n.checkLines&&e.length>100&&t.length>100?function(e,t,n){let o=e,i=t,r=function(e,t){let n=[],o={};function i(e){let t="",i=0,a=-1,l=n.length;for(;a<e.length-1;){-1===(a=e.indexOf(`
2`,i))&&(a=e.length-1);let s=e.slice(i,a+1);(o.hasOwnProperty?o.hasOwnProperty(s):void 0!==o[s])?t+=String.fromCharCode(o[s]):(l===r&&(s=e.slice(i),a=e.length),t+=String.fromCharCode(l),o[s]=l,n[l++]=s),i=a+1}return t}n[0]="";let r=4e4,a=i(e);return r=65535,{chars1:a,chars2:i(t),lineArray:n}}(o,i);o=r.chars1,i=r.chars2;let a=r.lineArray,l=tt(o,i,{checkLines:!1,deadline:n.deadline});(function(e,t){for(let n=0;n<e.length;n++){let o=e[n][1],i=[];for(let e=0;e<o.length;e++)i[e]=t[o.charCodeAt(e)];e[n][1]=i.join("")}})(l,a),(l=function(e){let t=e.map(e=>eZ(e)),n=!1,o=[],i=0,r=null,a=0,l=0,s=0,c=0,d=0;for(;a<t.length;)0===t[a][0]?(o[i++]=a,l=c,s=d,c=0,d=0,r=t[a][1]):(1===t[a][0]?c+=t[a][1].length:d+=t[a][1].length,r&&r.length<=Math.max(l,s)&&r.length<=Math.max(c,d)&&(t.splice(o[i-1],0,[-1,r]),t[o[i-1]+1][0]=1,i--,a=--i>0?o[i-1]:-1,l=0,s=0,c=0,d=0,r=null,n=!0)),a++;for(n&&(t=tp(t)),t=td(t),a=1;a<t.length;){if(-1===t[a-1][0]&&1===t[a][0]){let e=t[a-1][1],n=t[a][1],o=eQ(e,n),i=eQ(n,e);o>=i?(o>=e.length/2||o>=n.length/2)&&(t.splice(a,0,[0,n.substring(0,o)]),t[a-1][1]=e.substring(0,e.length-o),t[a+1][1]=n.substring(o),a++):(i>=e.length/2||i>=n.length/2)&&(t.splice(a,0,[0,e.substring(0,i)]),t[a-1][0]=1,t[a-1][1]=n.substring(0,n.length-i),t[a+1][0]=-1,t[a+1][1]=e.substring(i),a++),a++}a++}return t}(l)).push([0,""]);let s=0,c=0,d=0,p="",u="";for(;s<l.length;){switch(l[s][0]){case 1:d++,u+=l[s][1];break;case -1:c++,p+=l[s][1];break;case 0:if(c>=1&&d>=1){l.splice(s-c-d,c+d),s=s-c-d;let e=tt(p,u,{checkLines:!1,deadline:n.deadline});for(let t=e.length-1;t>=0;t--)l.splice(s,0,e[t]);s+=e.length}d=0,c=0,p="",u="";break;default:throw Error("Unknown diff operation.")}s++}return l.pop(),l}(e,t,n):function(e,t,n){let o=e.length,i=t.length,r=Math.ceil((o+i)/2),a=2*r,l=Array(a),s=Array(a);for(let e=0;e<a;e++)l[e]=-1,s[e]=-1;l[r+1]=0,s[r+1]=0;let c=o-i,d=c%2!=0,p=0,u=0,h=0,f=0;for(let y=0;y<r&&!(Date.now()>n);y++){for(let h=-y+p;h<=y-u;h+=2){let f;let g=r+h,m=(f=h===-y||h!==y&&l[g-1]<l[g+1]?l[g+1]:l[g-1]+1)-h;for(;f<o&&m<i&&e.charAt(f)===t.charAt(m);)f++,m++;if(l[g]=f,f>o)u+=2;else if(m>i)p+=2;else if(d){let i=r+c-h;if(i>=0&&i<a&&-1!==s[i]&&f>=o-s[i])return e2(e,t,f,m,n)}}for(let p=-y+h;p<=y-f;p+=2){let u;let g=r+p,m=(u=p===-y||p!==y&&s[g-1]<s[g+1]?s[g+1]:s[g-1]+1)-p;for(;u<o&&m<i&&e.charAt(o-u-1)===t.charAt(i-m-1);)u++,m++;if(s[g]=u,u>o)f+=2;else if(m>i)h+=2;else if(!d){let i=r+c-p;if(i>=0&&i<a&&-1!==l[i]){let a=l[i],s=r+a-i;if(a>=(u=o-u))return e2(e,t,a,s,n)}}}}return[[-1,e],[1,t]]}(e,t,n.deadline)}(o=o.substring(0,o.length-r),i=i.substring(0,i.length-r),n);return a&&s.unshift([0,a]),l&&s.push([0,l]),s=tp(s)}function tn(e,t,n){return 1===n?e+t:t+e}function to(e,t){return 1===t?[e.substring(0,e.length-1),e[e.length-1]]:[e.substring(1),e[0]]}function ti(e,t,n){var o,i;let r=1===n?-1:1,a=null,l=null,s=t+n;for(;s>=0&&s<e.length&&(null===a||null===l);s+=n){let[o,i]=e[s];if(0!==i.length){if(1===o){null===a&&(a=s);continue}if(-1===o){null===l&&(l=s);continue}if(0===o){if(null===a&&null===l){let[o,i]=to(e[t][1],n);e[t][1]=o,e[s][1]=tn(e[s][1],i,r);return}break}}}if(null!==a&&null!==l&&(o=a,i=l,1===n?e[o][1][e[o][1].length-1]===e[i][1][e[i][1].length-1]:e[o][1][0]===e[i][1][0])){let[o,i]=to(e[a][1],r),[s]=to(e[l][1],r);e[a][1]=o,e[l][1]=s,e[t][1]=tn(e[t][1],i,n);return}let[c,d]=to(e[t][1],n);e[t][1]=c,null===a?(e.splice(s,0,[1,d]),null!==l&&l>=s&&l++):e[a][1]=tn(e[a][1],d,r),null===l?e.splice(s,0,[-1,d]):e[l][1]=tn(e[l][1],d,r)}let tr=/[^a-zA-Z0-9]/,ta=/\s/,tl=/[\r\n]/,ts=/\n\r?\n$/,tc=/^\r?\n\r?\n/;function td(e){let t=e.map(e=>eZ(e));function n(e,t){if(!e||!t)return 6;let n=e.charAt(e.length-1),o=t.charAt(0),i=n.match(tr),r=o.match(tr),a=i&&n.match(ta),l=r&&o.match(ta),s=a&&n.match(tl),c=l&&o.match(tl),d=s&&e.match(ts),p=c&&t.match(tc);return d||p?5:s||c?4:i&&!a&&l?3:a||l?2:i||r?1:0}let o=1;for(;o<t.length-1;){if(0===t[o-1][0]&&0===t[o+1][0]){let e=t[o-1][1],i=t[o][1],r=t[o+1][1],a=e1(e,i);if(a){let t=i.substring(i.length-a);e=e.substring(0,e.length-a),i=t+i.substring(0,i.length-a),r=t+r}let l=e,s=i,c=r,d=n(e,i)+n(i,r);for(;i.charAt(0)===r.charAt(0);){e+=i.charAt(0),i=i.substring(1)+r.charAt(0),r=r.substring(1);let t=n(e,i)+n(i,r);t>=d&&(d=t,l=e,s=i,c=r)}t[o-1][1]!==l&&(l?t[o-1][1]=l:(t.splice(o-1,1),o--),t[o][1]=s,c?t[o+1][1]=c:(t.splice(o+1,1),o--))}o++}return t}function tp(e){let t=e.map(e=>eZ(e));t.push([0,""]);let n=0,o=0,i=0,r="",a="",l;for(;n<t.length;)switch(t[n][0]){case 1:i++,a+=t[n][1],n++;break;case -1:o++,r+=t[n][1],n++;break;case 0:o+i>1?(0!==o&&0!==i&&(0!==(l=e0(a,r))&&(n-o-i>0&&0===t[n-o-i-1][0]?t[n-o-i-1][1]+=a.substring(0,l):(t.splice(0,0,[0,a.substring(0,l)]),n++),a=a.substring(l),r=r.substring(l)),0!==(l=e1(a,r))&&(t[n][1]=a.substring(a.length-l)+t[n][1],a=a.substring(0,a.length-l),r=r.substring(0,r.length-l))),n-=o+i,t.splice(n,o+i),r.length&&(t.splice(n,0,[-1,r]),n++),a.length&&(t.splice(n,0,[1,a]),n++),n++):0!==n&&0===t[n-1][0]?(t[n-1][1]+=t[n][1],t.splice(n,1)):n++,i=0,o=0,r="",a="";break;default:throw Error("Unknown diff operation")}""===t[t.length-1][1]&&t.pop();let s=!1;for(n=1;n<t.length-1;)0===t[n-1][0]&&0===t[n+1][0]&&(t[n][1].substring(t[n][1].length-t[n-1][1].length)===t[n-1][1]?(t[n][1]=t[n-1][1]+t[n][1].substring(0,t[n][1].length-t[n-1][1].length),t[n+1][1]=t[n-1][1]+t[n+1][1],t.splice(n-1,1),s=!0):t[n][1].substring(0,t[n+1][1].length)===t[n+1][1]&&(t[n-1][1]+=t[n+1][1],t[n][1]=t[n][1].substring(t[n+1][1].length)+t[n+1][1],t.splice(n+1,1),s=!0)),n++;return s&&(t=tp(t)),t}var tu=Object.defineProperty,th=Object.getOwnPropertySymbols,tf=Object.prototype.hasOwnProperty,ty=Object.prototype.propertyIsEnumerable,tg=(e,t,n)=>t in e?tu(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,tm=(e,t)=>
2{for(var n in t||(t={}))tf.call(t,n)&&tg(e,n,t[n]);if(th)for(var n of th(t))ty.call(t,n)&&tg(e,n,t[n]);return e};let tk={threshold:.5,distance:1e3};function tv(e,t,n,o={}){if(null===e||null===t||null===n)throw Error("Null input. (match())");let i=Math.max(0,Math.min(n,e.length));return e===t?0:e.length?e.substring(i,i+t.length)===t?i:function(e,t,n,o={}){if(t.length>32)throw Error("Pattern too long for this browser.");let i=tm(tm({},tk),o),r=function(e){let t={};for(let n=0;n<e.length;n++)t[e.charAt(n)]=0;for(let n=0;n<e.length;n++)t[e.charAt(n)]|=1<<e.length-n-1;return t}(t);function a(e,o){let r=e/t.length,a=Math.abs(n-o);return i.distance?r+a/i.distance:a?1:r}let l=i.threshold,s=e.indexOf(t,n);-1!==s&&(l=Math.min(a(0,s),l),-1!==(s=e.lastIndexOf(t,n+t.length))&&(l=Math.min(a(0,s),l)));let c=1<<t.length-1;s=-1;let d,p,u=t.length+e.length,h=[];for(let o=0;o<t.length;o++){for(d=0,p=u;d<p;)a(o,n+p)<=l?d=p:u=p,p=Math.floor((u-d)/2+d);u=p;let i=Math.max(1,n-p+1),f=Math.min(n+p,e.length)+t.length,y=Array(f+2);y[f+1]=(1<<o)-1;for(let t=f;t>=i;t--){let d=r[e.charAt(t-1)];if(0===o?y[t]=(y[t+1]<<1|1)&d:y[t]=(y[t+1]<<1|1)&d|((h[t+1]|h[t])<<1|1)|h[t+1],y[t]&c){let e=a(o,t-1);if(e<=l){if(l=e,(s=t-1)>n)i=Math.max(1,2*n-s);else break}}}if(a(o+1,n)>l)break;h=y}return s}(e,t,i,o):-1}function tb(e){let t=[];for(let n=0;n<e.length;n++)1!==e[n][0]&&(t[n]=e[n][1]);return t.join("")}function tx(e){let t=[];for(let n=0;n<e.length;n++)-1!==e[n][0]&&(t[n]=e[n][1]);return t.join("")}function t_(e,t){let n=0,o=0,i=0,r=0,a;for(a=0;a<e.length&&(1!==e[a][0]&&(n+=e[a][1].length),-1!==e[a][0]&&(o+=e[a][1].length),!(n>t));a++)i=n,r=o;return e.length!==a&&-1===e[a][0]?r:r+(t-i)}function tE(e){let t=0;for(let n=0;n<e.length;n++){let o=e.codePointAt(n);if(typeof o>"u")throw Error("Failed to get codepoint");t+=tw(o)}return t}function tw(e){return e<=127?1:e<=2047?2:e<=65535?3:4}function tS(e,t){return{diffs:[],start1:e,start2:t,utf8Start1:e,utf8Start2:t,length1:0,length2:0,utf8Length1:0,utf8Length2:0}}let tO=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;function tM(e){if(!e)return[];let t=[],n=e.split(` 3`),o=0;for(;o<n.length;){let e=n[o].match(tO);if(!e)throw Error(`Invalid patch string: ${n[o]}`);let i=tS(tR(e[1]),tR(e[3]));for(t.push(i),""===e[2]?(i.start1--,i.utf8Start1--,i.length1=1,i.utf8Length1=1):"0"===e[2]?(i.length1=0,i.utf8Length1=0):(i.start1--,i.utf8Start1--,i.utf8Length1=tR(e[2]),i.length1=i.utf8Length1),""===e[4]?(i.start2--,i.utf8Start2--,i.length2=1,i.utf8Length2=1):"0"===e[4]?(i.length2=0,i.utf8Length2=0):(i.start2--,i.utf8Start2--,i.utf8Length2=tR(e[4]),i.length2=i.utf8Length2),o++;o<n.length;){let e;let t=n[o],r=t.charAt(0);if("@"===r)break;if(""===r){o++;continue}try{e=decodeURI(t.slice(1))}catch{throw Error(`Illegal escape in parse: ${t}`)}let a=tE(e)-e.length;if("-"===r)i.diffs.push([-1,e]),i.length1-=a;else if("+"===r)i.diffs.push([1,e]),i.length2-=a;else if(" "===r)i.diffs.push([0,e]),i.length1-=a,i.length2-=a;else throw Error(`Invalid patch mode "${r}" in: ${e}`);o++}}return t}function tR(e){return parseInt(e,10)}let tN=new WeakMap;function tA(e){return tN.get(e)?.undoStepId}let tI=V("plugin:withUndoRedo"),tT=new WeakMap,tC=new WeakMap,tB=e=>{let t=tT.get(e);return void 0===t||t},tD=e=>(tC.get(e)||tC.set(e,[]),tC.get(e)||[]);function tj(e,t,n,o,i){let r={...n};if("insert"===t.type&&1===t.path.length){let e=(o||[]).findIndex(e=>m({_key:e._key},t.path[0]));return tI(`Adjusting block path (+${t.items.length}) for '${r.type}' operation and patch '${t.type}'`),[tY(r,t.items.length,e)]}if("unset"===t.type&&1===t.path.length){let e=(i||[]).findIndex(e=>m({_key:e._key},t.path[0]));return"path"in r&&Array.isArray(r.path)&&r.path[0]===e?(tI("Skipping transformation that targeted removed block"),[]):[tY(r,-1,e)]}if("unset"===t.type&&0===t.path.length)return tI(`Adjusting selection for unset everything patch and ${n.type} operation`),[];if("diffMatchPatch"===t.type){let n;let o=("set_selection"===r.type&&e.selection?n=e.children[e.selection.focus.path[0]]:"path"in r&&(n=e.children[r.path[0]]),n);return o&&m({_key:o._key}
3,t.path[0])&&tM(t.value).forEach(e=>{let t=0,n=e.utf8Start1,{diffs:o}=e;if(o.forEach((e,i)=>{let[r,a]=e;1===r?(t+=a.length,n+=a.length):-1===r?(t-=a.length,n-=a.length):0===r&&(o.slice(i).every(([e])=>0===e)||(n+=a.length))}),"insert_text"===r.type&&n<r.offset&&(r.offset+=t),"remove_text"===r.type&&n<=r.offset-r.text.length&&(r.offset+=t),"set_selection"===r.type){let e=r.properties?.focus?{...r.properties.focus}:void 0,o=r?.properties?.anchor?{...r.properties.anchor}:void 0,i=r?.newProperties?.focus?{...r.newProperties.focus}:void 0,a=r?.newProperties?.anchor?{...r.newProperties.anchor}:void 0;(e&&o||i&&a)&&([e,o,i,a].forEach(e=>{e&&n<e.offset&&(e.offset+=t)}),e&&o&&(r.properties={focus:e,anchor:o}),i&&a&&(r.newProperties={focus:i,anchor:a}))}}),[r]}return[r]}function tY(e,t,n){let o={...e};if(n>=0&&"set_selection"!==o.type&&Array.isArray(o.path)&&o.path[0]>=n+t&&o.path[0]+t>-1){let e=[o.path[0]+t,...o.path.slice(1)];o.path=e}if("set_selection"===o.type){let e=o.properties?.focus?{...o.properties.focus}:void 0,i=o?.properties?.anchor?{...o.properties.anchor}:void 0,r=o?.newProperties?.focus?{...o.newProperties.focus}:void 0,a=o?.newProperties?.anchor?{...o.newProperties.anchor}:void 0;(e&&i||r&&a)&&([e,i,r,a].forEach(e=>{e&&e.path[0]>=n+t&&e.path[0]+t>-1&&(e.path=[e.path[0]+t,...e.path.slice(1)])}),e&&i&&(o.properties={focus:e,anchor:i}),r&&a&&(o.newProperties={focus:r,anchor:a}))}return o}let tU=(e,t)=>!!("set_selection"===e.type||t&&"insert_text"===e.type&&"insert_text"===t.type&&e.offset===t.offset+t.text.length&&p.y$.equals(e.path,t.path)&&" "!==e.text||t&&"remove_text"===e.type&&"remove_text"===t.type&&e.offset+e.text.length===t.offset&&p.y$.equals(e.path,t.path)),tL=(e,t)=>!!(t&&"set_selection"===e.type&&"set_selection"===t.type),tz=e=>"set_selection"!==e.type;function t$(e,t){let n=tB(e);tT.set(e,!1),t(),tT.set(e,n)}let tP=({context:e,operation:t})=>{let n,o,i;let r=(0,y.Qe)({annotation:{_type:t.annotation.name,...t.annotation.value},context:e,options:{refreshKeys:!1,validateFields:!0}});if(!r)throw Error(`Failed to parse annotation ${JSON.stringify(t.annotation)}`);let a=t.editor;if(!a.selection||p.e6.isCollapsed(a.selection))return;let l=[],s=p.ML.nodes(a,{at:a.selection,match:e=>a.isTextBlock(e),reverse:p.e6.isBackward(a.selection)}),c=0;for(let[t,n]of s){if(0===t.children.length||1===t.children.length&&""===t.children[0].text)continue;let s=0===c?r._key:e.keyGenerator(),d=t.markDefs??[];for(let[e,c]of(void 0===d.find(e=>e._type===r._type&&e._key===s)&&(p.YR.setNodes(a,{markDefs:[...d,{...r,_key:s}]},{at:n}),i=[{_key:t._key},"markDefs",{_key:s}],p.e6.isBackward(a.selection)?l.unshift(i):l.push(i)),p.YR.setNodes(a,{},{match:p.xv.isText,split:!0}),p.NB.children(a,n))){if(!a.isTextSpan(e)||!p.e6.includes(a.selection,c))continue;let n=e.marks??[],i=n.filter(e=>d.some(t=>t._key===e&&t._type===r._type));p.YR.setNodes(a,{marks:[...n.filter(e=>!i.includes(e)),s]},{at:c}),o=[{_key:t._key},"children",{_key:e._key}]}c++}return i&&o&&(n={markDefPath:i,markDefPaths:l,spanPath:o}),n},tG={"annotation.add":tP,"annotation.remove":({operation:e})=>{let t=e.editor;if(t.selection){if(p.e6.isCollapsed(t.selection)){let[n,o]=p.ML.node(t,t.selection,{depth:1});if(!t.isTextBlock(n))return;let i=(n.markDefs??[]).filter(t=>t._type===e.annotation.name),[r,a]=p.ML.node(t,t.selection,{depth:2});if(!t.isTextSpan(r))return;let l=r.marks?.find(e=>i.some(t=>t._key===e));if(!l)return;let s=[];for(let[e,n]of p.NB.children(t,o,{reverse:!0}))if(t.isTextSpan(e)&&p.y$.isBefore(n,a)){if(e.marks?.includes(l))s.push([e,n]);else break}let c=[];for(let[e,n]of p.NB.children(t,o))if(t.isTextSpan(e)&&p.y$.isAfter(n,a)){if(e.marks?.includes(l))c.push([e,n]);else break}for(let[e,n]of[...s,[r,a],...c])p.YR.setNodes(t,{marks:e.marks?.filter(e=>e!==l)},{at:n})}else for(let[n,o]of(p.YR.setNodes(t,{},{match:e=>t.isTextSpan(e),split:!0,hanging:!0}),p.ML.nodes(t,{at:t.selection,match:e=>t.isTextBlock(e)})))for(let[i,r]of p.NB.children(t,o)){if(!t.isTextSpan(i)||!p.e6.includes(t.selection,r))continue;let o=n.markDefs??[],a=i.marks??[],l=a.filter(t=>o.find(e=>e._key===t)?._type!==e.annotation.name);l.length!==a.length&&p.YR.setNodes(t,{marks:l},{at:r})}}},"block.set":({context:e,operation:t})=>{let n=es({context:{schema:e.schema,value:t.editor.value,selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:0}}},blockIndexMap:t.editor.blockIndexMap});if(!n)throw Error(`Unable to convert ${JSON.stringify(t.at)} into a Slate Range`);let o=p.ML.node(t.editor,n,{depth:1})?.[0];if(!o)throw Error(`Unable to find block at ${JSON.stringify(t.at)}`);let i=H([o],e.schema.block.name,eu.get(t.editor)).at(0);if(!i)throw Error(`Unable to parse block at ${JSON.stringify(t.at)}`);let{_type:r,...a}=t.props,l=(0,y.IX)({context:e,block:{...i,...a},options:{refreshKeys:!1,validateFields:!0}});if(!l)throw Error(`Unable to update block at ${JSON.stringify(t.at)}`);let s=q([l],{schemaTypes:e.schema})?.at(0);if(!s)throw Error("Unable to convert block to Slate value");p.YR.setNodes(t.editor,s,{at:n})},"block.unset":({context:e,operation:t})=>{let n=es({context:{schema:e.schema,value:t.editor.value,selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:0}}},blockIndexMap:t.editor.blockIndexMap});if(!n)throw Error(`Unable to convert ${JSON.stringify(t.at)} into a Slate Range`);let o=p.ML.node(t.editor,n,{depth:1})?.[0];if(!o)throw Error(`Unable to find block at ${JSON.stringify(t.at)}`);let i=H([o],e.schema.block.name,eu.get(t.editor)).at(0);if(!i)throw Error(`Unable to parse block at ${JSON.stringify(t.at)}`);if((0,y.dz)(e,i)){let o=t.props.filter(e=>"_type"!==e),r=(0,y.IX)({context:e,block:C(i,o),options:{refreshKeys:!1,validateFields:!0}});if(!r)throw Error(`Unable to update block at ${JSON.stringify(t.at)}`);let a={};for(let e of o)e in r?a[e]=r[e]:a[e]=void 0;p.YR.setNodes(t.editor,a,{at:n});return}let r=(0,y.IX)({context:e,block:C(i,t.props.filter(e=>"_type"!==e)),options:{refreshKeys:!1,validateFields:!0}});if(!r)throw Error(`Unable to update block at ${JSON.stringify(t.at)}`);let{_type:a,_key:l,...s}=r;p.YR.setNodes(t.editor,{_type:a,_key:l,value:s},{at:n})},"child.set":({context:e,operation:t})=>{let n=es({context:{schema:e.schema,value:t.editor.value,selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:0}}},blockIndexMap:t.editor.blockIndexMap});if(!n)throw Error(`Unable to convert ${JSON.stringify(t.at)} into a Slate Range`);let o=p.ML.node(t.editor,n,{depth:2}),i=o?.[0],r=o?.[1];if(!i||!r)throw Error(`Unable to find child at ${JSON.stringify(t.at)}`);if(t.editor.isTextSpan(i)){let{_type:e,text:n,...o}=t.props;p.YR.setNodes(t.editor,{...i,...o},{at:r}),"string"==typeof n&&i.text!==n&&(t.editor.apply({type:"remove_text",path:r,offset:0,text:i.text}),t.editor.apply({type:"insert_text",path:r,offset:0,text:n}));return}
3if(p.W_.isElement(i)){let n=e.schema.inlineObjects.find(e=>e.name===i._type);if(!n)throw Error(`Unable to find schema definition for Inline Object type ${i._type}`);let o="value"in i&&"object"==typeof i.value?i.value:{},{_type:a,_key:l,...s}=t.props;for(let e in s)n.fields.some(t=>t.name===e)||delete s[e];p.YR.setNodes(t.editor,{...i,_key:"string"==typeof l?l:i._key,value:{...o,...s}},{at:r});return}throw Error(`Unable to determine the type of child at ${JSON.stringify(t.at)}`)},"child.unset":({context:e,operation:t})=>{let n=es({context:{schema:e.schema,value:t.editor.value,selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:0}}},blockIndexMap:t.editor.blockIndexMap});if(!n)throw Error(`Unable to convert ${JSON.stringify(t.at)} into a Slate Range`);let o=p.ML.node(t.editor,n,{depth:2}),i=o?.[0],r=o?.[1];if(!i||!r)throw Error(`Unable to find child at ${JSON.stringify(t.at)}`);if(t.editor.isTextSpan(i)){t.props.includes("text")&&t.editor.apply({type:"remove_text",path:r,offset:0,text:i.text});let n={};for(let o of t.props)if("_type"!==o){if("_key"===o){n._key=e.keyGenerator();continue}n[o]=null}p.YR.setNodes(t.editor,n,{at:r});return}if(p.W_.isElement(i)){let n="value"in i&&"object"==typeof i.value?i.value:{},o=t.props.map(e=>({type:"unset",path:[e]})),a=(0,B.g7)(n,o);p.YR.setNodes(t.editor,{...i,_key:t.props.includes("_key")?e.keyGenerator():i._key,value:a},{at:r});return}throw Error(`Unable to determine the type of child at ${JSON.stringify(t.at)}`)},"decorator.add":({context:e,operation:t})=>{let n=t.editor,o=t.decorator,i=H(n.children,e.schema.block.name,eu.get(n)),r=t.at?.anchor?(0,y.MR)({context:{...e,value:i},blockOffset:t.at.anchor,direction:"backward"}):void 0,a=t.at?.focus?(0,y.MR)({context:{...e,value:i},blockOffset:t.at.focus,direction:"forward"}):void 0,l=r&&a?{anchor:r,focus:a}:void 0,s=l?es({context:{schema:e.schema,value:t.editor.value,selection:l},blockIndexMap:t.editor.blockIndexMap})??n.selection:n.selection;if(!s)return;let c=er({schema:e.schema,editor:n,range:s}),d=c?(0,j.W)({context:{...e,value:i},selectionPoint:c.anchor}):void 0,u=c?(0,j.W)({context:{...e,value:i},selectionPoint:c.focus}):void 0;if(!d||!u)throw Error("Unable to find anchor or focus offset");if(p.e6.isExpanded(s)){p.YR.setNodes(n,{},{at:s,match:p.xv.isText,split:!0,hanging:!0});let i=H(n.children,e.schema.block.name,eu.get(n)),r=(0,D.iO)({context:{...e,value:i},offsets:{anchor:d,focus:u},backward:c?.backward}),a=(0,v.Vj)({blockIndexMap:n.blockIndexMap,context:{converters:[],keyGenerator:e.keyGenerator,readOnly:!1,schema:e.schema,selection:r,value:i},decoratorState:n.decoratorState});if(!a)throw Error("Unable to find trimmed selection");let l=es({context:{schema:e.schema,value:t.editor.value,selection:a},blockIndexMap:t.editor.blockIndexMap});if(!l)throw Error("Unable to find new selection");for(let[e,t]of p.e6.isRange(l)?[...p.ML.nodes(n,{at:l,match:e=>p.xv.isText(e)})]:[]){let i=[...(Array.isArray(e.marks)?e.marks:[]).filter(e=>e!==o),o];p.YR.setNodes(n,{marks:i},{at:t,match:p.xv.isText,split:!0,hanging:!0})}}else{if(!Array.from(p.ML.nodes(n,{at:s,match:e=>n.isTextSpan(e)}))?.at(0))return;let[e,t]=p.ML.node(n,s,{depth:1}),i=n.isTextBlock(e)&&1===e.children.length&&n.isTextSpan(e.children[0])&&""===e.children[0].text?e.children[0]:void 0;if(i){let e=i.marks??[],r=e.filter(e=>e!==o);p.YR.setNodes(n,{marks:e.length===r.length?[...e,o]:r},{at:t,match:e=>n.isTextSpan(e)})}else n.decoratorState[o]=!0}if(n.selection){let e=n.selection;n.selection={...e}}},"decorator.remove":({operation:e})=>{let t=e.editor,n=e.decorator,{selection:o}=t;if(o){if(p.e6.isExpanded(o))p.YR.setNodes(t,{},{match:p.xv.isText,split:!0,hanging:!0}),t.selection&&[...p.ML.nodes(t,{at:t.selection,match:p.xv.isText})].forEach(([e,o])=>{let i=t.children[o[0]];p.W_.isElement(i)&&i.children.includes(e)&&p.YR.setNodes(t,{marks:(Array.isArray(e.marks)?e.marks:[]).filter(e=>e!==n),_type:"span"},{at:o})});else{let[e,i]=p.ML.node(t,o,{depth:1}),r=t.isTextBlock(e)&&1===e.children.length&&t.isTextSpan(e.children[0])&&""===e.children[0].text?e.children[0]:void 0;if(r){let e=(r.marks??[]).filter(e=>e!==n);p.YR.setNodes(t,{marks:e},{at:i,match:e=>t.isTextSpan(e)})}else t.decoratorState[n]=!1}if(t.selection){let e=t.selection;t.selection={...e}}}},delete:({context:e,operation:t})=>{let n=(0,y.Ak)(t.at.anchor),o=(0,y.Ak)(t.at.focus),i=t.at.backward?n:o,r=t.at.backward?t.at.focus.offset:t.at.anchor.offset;if(!i)throw Error("Failed to get end block key");let a=t.editor.blockIndexMap.get(i);
3if(void 0===a)throw Error("Failed to get end block index");let l=t.editor.value.at(a);if(!l)throw Error("Failed to get end block");let s=void 0!==n?Z({editor:t.editor,_key:n}):void 0,c=void 0!==o?Z({editor:t.editor,_key:o}):void 0;if(1===t.at.anchor.path.length&&1===t.at.focus.path.length&&s&&c&&s[0]===c[0]){p.YR.removeNodes(t.editor,{at:[s[0]]}),0===t.editor.children.length&&p.YR.insertNodes(t.editor,eL(e));return}let d=es({context:{schema:e.schema,value:t.editor.value,selection:t.at},blockIndexMap:t.editor.blockIndexMap});if(!d)throw Error(`Failed to get Slate Range for selection ${JSON.stringify(t.at)}`);let u=(0,y.dz)(e,l)&&0===r;t.editor.delete({at:d,reverse:"backward"===t.direction,unit:t.unit,hanging:u})},"history.redo":({operation:e})=>{let t=e.editor,{redos:n}=t.history,o=tD(t);if(n.length>0){let e=n[n.length-1];if(tI("Redoing",e),e.operations.length>0){let n=o.filter(t=>t.time>=e.timestamp),i=e.operations;n.forEach(e=>{i=T(i.map(n=>tj(t,e.patch,n,e.snapshot,e.previousSnapshot)))});try{p.ML.withoutNormalizing(t,()=>{!function(e,t){let n=eq(e);eW.set(e,!0),t(),eW.set(e,n)}(t,()=>{t$(t,()=>{i.forEach(e=>{t.apply(e)})})})})}
3catch(e){tI("Could not perform redo step",e),o.splice(0,o.length),p.YR.deselect(t),t.history={undos:[],redos:[]},tT.set(t,!0),eW.set(t,!1),t.onChange();return}t.history.undos.push(e),t.history.redos.pop()}}},"history.undo":({operation:e})=>{let t=e.editor,{undos:n}=t.history,o=tD(t);if(n.length>0){let e=n[n.length-1];if(tI("Undoing",e),e.operations.length>0){let n=o.filter(t=>t.time>=e.timestamp),i=e.operations;n.forEach(e=>{i=T(i.map(n=>tj(t,e.patch,n,e.snapshot,e.previousSnapshot)))});let r=i.map(p.OX.inverse).reverse();try{p.ML.withoutNormalizing(t,()=>{!function(e,t){let n=eJ(e);eV.set(e,!0),t(),eV.set(e,n)}(t,()=>{t$(t,()=>{r.forEach(e=>{t.apply(e)})})})})}catch(e){tI("Could not perform undo step",e),o.splice(0,o.length),p.YR.deselect(t),t.history={undos:[],redos:[]},tT.set(t,!0),eV.set(t,!1),t.onChange();return}t.history.redos.push(e),t.history.undos.pop()}}},"insert.block":({context:e,operation:t})=>{let n=(0,y.IX)({block:t.block,context:e,options:{refreshKeys:!1,validateFields:!0}});if(!n)throw Error(`Failed to parse block ${JSON.stringify(t.block)}`);let o=q([n],{schemaTypes:e.schema})[0];if(!o)throw Error(`Failed to convert block to Slate fragment ${JSON.stringify(n)}`);!function({block:e,placement:t,select:n,editor:o,schema:i}){let[r,a]=function({editor:e}){if(!e.selection)return[void 0,void 0];let t=p.e6.start(e.selection);return ee({editor:e,point:t})}({editor:o}),[l,s]=function({editor:e}){if(!e.selection)return[void 0,void 0];let t=p.e6.end(e.selection);return ee({editor:e,point:t})}({editor:o});if(o.selection&&r&&a&&l&&s){if("before"===t){let t=o.selection,i=p.e6.start(t);p.YR.insertNodes(o,[e],{at:[i.path[0]],select:!1}),"start"===n?p.YR.select(o,p.ML.start(o,[i.path[0]])):"end"===n&&p.YR.select(o,p.ML.end(o,[i.path[0]]))}else if("after"===t){let t=o.selection,i=[p.e6.end(t).path[0]+1];p.YR.insertNodes(o,[e],{at:i,select:!1}),"start"===n?p.YR.select(o,p.ML.start(o,i)):"end"===n&&p.YR.select(o,p.ML.end(o,i))}else{let t=o.selection,r=p.ML.start(o,s);if(p.e6.isExpanded(t)&&!o.isTextBlock(e)){p.YR.delete(o,{at:t});let r=o.selection,[a,l]=Q({editor:o});p.YR.insertNodes(o,[e],{voids:!0});let s=0===r.anchor.offset?p.e6.transform(r,{type:"insert_node",node:e,path:[r.anchor.path[0]]}):r;"none"===n&&s&&p.YR.select(o,s),a&&X([a],i)&&p.YR.removeNodes(o,{at:l});return}if(o.isTextBlock(l)&&o.isTextBlock(e)){let a=p.e6.start(t);if(X([l],i)){let t=o.selection;p.YR.insertNodes(o,[e],{at:s,select:!1}),p.YR.removeNodes(o,{at:p.y$.next(s)}),"start"===n?p.YR.select(o,a):"end"===n?p.YR.select(o,p.ML.end(o,s)):p.YR.select(o,t);return}if(p.YR.setNodes(o,{markDefs:[...l.markDefs??[],...e.markDefs??[]]},{at:s}),"end"===n){p.YR.insertFragment(o,[e],{voids:!0});return}p.YR.insertFragment(o,[e],{at:t,voids:!0}),"start"===n?p.YR.select(o,a):p.E9.equals(a,r)||p.YR.select(o,a)}else if(o.isTextBlock(l)){let r=p.ML.start(o,s),a=p.ML.end(o,s),c=p.e6.start(t),d=p.e6.end(t);if(p.e6.isCollapsed(t)&&p.E9.equals(c,r))p.YR.insertNodes(o,[e],{at:s,select:!1}),("start"===n||"end"===n)&&p.YR.select(o,p.ML.start(o,s)),(0,g.PF)({schema:i},l)&&p.YR.removeNodes(o,{at:p.y$.next(s)});else if(p.e6.isCollapsed(t)&&p.E9.equals(d,a)){let t=[s[0]+1];p.YR.insertNodes(o,[e],{at:t,select:!1}),("start"===n||"end"===n)&&p.YR.select(o,p.ML.start(o,t))}else if(p.e6.isExpanded(t)&&p.E9.equals(c,r)&&p.E9.equals(d,a))p.YR.insertFragment(o,[e],{at:t}),"start"===n?p.YR.select(o,p.ML.start(o,s)):"end"===n&&p.YR.select(o,p.ML.end(o,s));else if(p.e6.isExpanded(t)&&p.E9.equals(c,r))p.YR.insertFragment(o,[e],{at:t}),"start"===n?p.YR.select(o,p.ML.start(o,s)):"end"===n&&p.YR.select(o,p.ML.end(o,s));else if(p.e6.isExpanded(t)&&p.E9.equals(d,a))p.YR.insertFragment(o,[e],{at:t}),"start"===n?p.YR.select(o,p.ML.start(o,p.y$.next(s))):"end"===n&&p.YR.select(o,p.ML.end(o,p.y$.next(s)));else{let t=o.selection,[i]=function({editor:e}){let[t,n]=Q({editor:e}),o=e.selection?.focus.path.at(1);if(!t||!n||void 0===o)return[void 0,void 0];try{let e=p.NB.child(t,o);return e?[e,[...n,o]]:[void 0,void 0]}catch{return[void 0,void 0]}}({editor:o});if(i&&o.isTextSpan(i))p.YR.splitNodes(o,{at:t}),p.YR.insertFragment(o,[e],{at:t}),"start"===n||"end"===n?p.YR.select(o,[s[0]+1]):p.YR.select(o,t);else{let i=[s[0]+1];p.YR.insertNodes(o,[e],{at:i,select:!1}),p.YR.select(o,t),"start"===n?p.YR.select(o,p.ML.start(o,i)):"end"===n&&p.YR.select(o,p.ML.end(o,i))}}}else{p.YR.insertNodes(o,[e],{select:!1});let t=[s[0]+1];"start"===n?p.YR.select(o,p.ML.start(o,t)):"end"===n&&p.YR.select(o,p.ML.end(o,t))}}}else{"none"!==n&&f.y2.focus(o);let[r,a]=en({editor:o});if("before"===t)p.YR.insertNodes(o,[e],{at:[0]}),"start"===n?p.YR.select(o,p.ML.start(o,[0])):"end"===n&&p.YR.select(o,p.ML.end(o,[0]));else if("after"===t){let t=a?[a[0]+1]:[0];p.YR.insertNodes(o,[e],{at:t}),"start"===n?p.YR.select(o,p.ML.start(o,t)):"end"===n&&p.YR.select(o,p.ML.end(o,t))}else{if(r&&X([r],i)){p.YR.removeNodes(o,{at:a}),p.YR.insertNodes(o,[e],{at:a,select:!1}),p.YR.deselect(o),"start"===n?p.YR.select(o,p.ML.start(o,a)):"end"===n&&p.YR.select(o,p.ML.end(o,a));return}if(o.isTextBlock(e)&&r&&o.isTextBlock(r)){let t=p.ML.end(o,a);p.YR.insertFragment(o,[e],{at:p.ML.end(o,a)}),"start"===n?p.YR.select(o,t):"none"===n&&p.YR.deselect(o);return}let t=a?[a[0]+1]:[0];p.YR.insertNodes(o,[e],{at:t,select:!1}),"start"===n?p.YR.select(o,p.ML.start(o,t)):"end"===n&&p.YR.select(o,p.ML.end(o,t))}}}({block:o,placement:t.placement,select:t.select??"start",editor:t.editor,schema:e.schema})},"insert.inline object":({context:e,operation:t})=>{let n=(0,y.Kw)({context:e,inlineObject:{_type:t.inlineObject.name,...t.inlineObject.value??{}},options:{refreshKeys:!1,validateFields:!0}});
3if(!n)throw Error(`Failed to parse inline object ${JSON.stringify(t.inlineObject)}`);if(!t.editor.selection){console.error("Unable to insert inline object without selection");return}let[o]=Array.from(p.ML.nodes(t.editor,{at:t.editor.selection.focus.path,match:e=>t.editor.isTextBlock(e)})).at(0)??[void 0,void 0];if(!o){console.error("Unable to perform action without focus text block");return}let i=q([{_type:e.schema.block.name,_key:e.keyGenerator(),children:[n]}],{schemaTypes:e.schema}).at(0)?.children.at(0);if(!i){console.error("Unable to insert inline object");return}p.YR.insertNodes(t.editor,i)},"insert.span":({context:e,operation:t})=>{if(!t.editor.selection){console.error("Unable to perform action without selection",t);return}let[n,o]=Array.from(p.ML.nodes(t.editor,{at:t.editor.selection.focus.path,match:e=>t.editor.isTextBlock(e)}))[0]??[void 0,void 0];if(!n||!o){console.error("Unable to perform action without focus block",t);return}let i=n.markDefs??[],r=t.annotations?t.annotations.map(t=>({_type:t.name,_key:e.keyGenerator(),...t.value})):void 0;r&&r.length>0&&p.YR.setNodes(t.editor,{markDefs:[...i,...r]}),p.YR.insertNodes(t.editor,{_type:"span",_key:e.keyGenerator(),text:t.text,marks:[...r?.map(e=>e._key)??[],...t.decorators??[]]})},"insert.text":ez,"move.backward":({operation:e})=>{p.YR.move(e.editor,{unit:"character",distance:e.distance,reverse:!0})},"move.block":({operation:e})=>{let t=(0,y.Ak)({path:e.at});if(!t)throw Error("Failed to get block key from selection point");let n=e.editor.blockIndexMap.get(t);if(void 0===n)throw Error("Failed to get block index from block key");let o=(0,y.Ak)({path:e.to});if(!o)throw Error("Failed to get block key from selection point");let i=e.editor.blockIndexMap.get(o);if(void 0===i)throw Error("Failed to get block index from block key");p.YR.moveNodes(e.editor,{at:[n],to:[i],mode:"highest"})},"move.forward":({operation:e})=>{p.YR.move(e.editor,{unit:"character",distance:e.distance})},select:({context:e,operation:t})=>{let n=es({context:{schema:e.schema,value:t.editor.value,selection:t.at},blockIndexMap:t.editor.blockIndexMap});n?p.YR.select(t.editor,n):p.YR.deselect(t.editor)}};function tF({context:e,operation:t}){try{switch(t.type){case"annotation.add":tG["annotation.add"]({context:e,operation:t});break;case"annotation.remove":tG["annotation.remove"]({context:e,operation:t});break;case"block.set":tG["block.set"]({context:e,operation:t});break;case"block.unset":tG["block.unset"]({context:e,operation:t});break;case"child.set":tG["child.set"]({context:e,operation:t});break;case"child.unset":tG["child.unset"]({context:e,operation:t});break;case"decorator.add":tG["decorator.add"]({context:e,operation:t});break;case"decorator.remove":tG["decorator.remove"]({context:e,operation:t});break;case"delete":tG.delete({context:e,operation:t});break;case"history.redo":tG["history.redo"]({context:e,operation:t});break;case"history.undo":tG["history.undo"]({context:e,operation:t});break;case"insert.block":tG["insert.block"]({context:e,operation:t});break;case"insert.inline object":tG["insert.inline object"]({context:e,operation:t});break;case"insert.span":tG["insert.span"]({context:e,operation:t});break;case"insert.text":tG["insert.text"]({context:e,operation:t});break;case"move.backward":tG["move.backward"]({context:e,operation:t});break;case"move.block":tG["move.block"]({context:e,operation:t});break;case"move.forward":tG["move.forward"]({context:e,operation:t});break;default:tG.select({context:e,operation:t})}}catch(e){console.error(Error(`Executing "${t.type}" failed due to: ${e.message}`))}}let tK=new WeakMap;function tV(e,t){tK.set(e,ev()),p.ML.withoutNormalizing(e,t),tK.set(e,void 0)}function tW(e){return void 0!==tK.get(e)}function tJ(e,t){let n=-1,o=e.find((e,o)=>{let i=(0,y.eD)(t[0])?e._key===t[0]._key:o===t[0];return i&&(n=o),i});if(o)return{node:o,index:n}}function tq(e,t){let n=e.node;if(!p.W_.isElement(n)||"children"!==t[1])return;let o=-1,i=n.children.find((e,n)=>{let i=(0,y.eD)(t[2])?e._key===t[2]._key:n===t[2];return i&&(o=n),i});if(i)return{node:i,index:o}}let tH=new WeakMap;function tX(e,t){let n=tH.get(e);tH.set(e,!1),t(),tH.set(e,n)}let tZ=V("plugin:withPatches"),tQ=V("plugin:withPlaceholderBlock"),t0=V("plugin:withSchemaTypes");function t1(e){return"object"==typeof e&&null!==e&&!("_type"in e)&&"children"in e&&Array.isArray(e.children)}function t2(e,t){return(0,y.ay)(t)&&t._type===e.schema.block.name}function t3(e,t){return"object"==typeof t&&null!==t&&!("children"in t)&&("_type"in t?t._type===e.schema.span.name:"text"in t)}function t8(e){return"object"==typeof e&&null!==e&&"text"in e&&"string"==typeof e.text}function t6(e,t){let n=t.at(0);if(!(void 0===n||1!==t.length))return e.children.at(n)}function t9(e,t,n){if(0===n.length)return t;if(1===n.length)return t6(t,n);if(2===n.length){let o=t6(t,n.slice(0,1));return o&&t2(e,o)&&o.children.at(n[1])||void 0}}function t4(e,t,n){let o=t9(e,t,n);if(o&&t3(e,o))return o}function t5(e,t,n){if(0===n.length)return;let o=n.slice(0,-1);if(0===o.length)return t;let i=o.at(0);if(void 0===i||1!==o.length)return;let r=t.children.at(i);if(r&&t2(e,r))return r}let t7=(e,t)=>{let{editorActor:n,relayActor:o}=t,i=function({editorActor:e}){return function(t){t.isTextBlock=t=>!p.ML.isEditor(t)&&(0,y.dz)(e.getSnapshot().context,t),t.isTextSpan=t=>!p.ML.isEditor(t)&&(0,y.dn)(e.getSnapshot().context,t),t.isListBlock=t=>!p.ML.isEditor(t)&&(0,y.cd)(e.getSnapshot().context,t),t.isVoid=t=>!p.ML.isEditor(t)&&e.getSnapshot().context.schema.block.name!==t._type&&(e.getSnapshot().context.schema.blockObjects.map(e=>e.name).includes(t._type)||e.getSnapshot().context.schema.inlineObjects.map(e=>e.name).includes(t._type)),t.isInline=t=>!p.ML.isEditor(t)&&e.getSnapshot().context.schema.inlineObjects.map(e=>e.name).includes(t._type)&&"__inline"in t&&!0===t.__inline;let{normalizeNode:n}=t;return t.normalizeNode=o=>{let[i,r]=o;if(void 0===i._type&&2===r.length){t0("Setting span type on text node without a type");let n=i._key||e.getSnapshot().context.keyGenerator();e.send({type:"normalizing"}),p.YR.setNodes(t,{...i,_type:e.getSnapshot().context.schema.span.name,_key:n},{at:r}),e.send({type:"done normalizing"});return}if(void 0===i._key&&(1===r.length||2===r.length)){t0("Setting missing key on child node without a key");let n=e.getSnapshot().context.keyGenerator();e.send({type:"normalizing"}),p.YR.setNodes(t,{_key:n},{at:r}),e.send({type:"done normalizing"});return}n(o)},t}}({editorActor:n}),r=function({editorActor:e,relayActor:t,subscriptions:n}){var o;let i;let r=(o=e.getSnapshot().context.schema,(e,t)=>{let n=!1;
3try{switch(t.type){case"insert":n=function(e,t,n){let o=tJ(e.children,t.path);if(!o||t.path.length>1&&"children"!==t.path[1])return!1;if(1===t.path.length){let{items:i,position:r}=t,a=q(i,{schemaTypes:n},ep.get(e)),l=o.index,s="after"===r?l+1:l,c=X(e.children,n);return p.YR.insertNodes(e,a,{at:[s]}),c&&"number"==typeof t.path[0]&&0===t.path[0]&&p.YR.removeNodes(e,{at:["before"===r?l+1:l]}),!0}let{items:i,position:r}=t,a=tq(o,t.path);if(!a)return!1;let l=q([{...o.node,children:i}],{schemaTypes:n},ep.get(e)),s="after"===r?a.index+1:a.index,c=[o.index,s];return l&&p.W_.isElement(l[0])&&p.YR.insertNodes(e,l[0].children,{at:c}),!0}(e,t,o);break;case"unset":n=function(e,t){if(0===t.path.length){let t=e.selection;for(let[t,n]of(p.YR.deselect(e),p.NB.children(e,[],{reverse:!0})))p.YR.removeNodes(e,{at:n});return p.YR.insertNodes(e,e.pteCreateTextBlock({decorators:[]})),t&&p.YR.select(e,{anchor:{path:[0,0],offset:0},focus:{path:[0,0],offset:0}}),e.onChange(),!0}let n=tJ(e.children,t.path);if(!n)return!1;if(1===t.path.length){if(1===e.children.length){let t=e.selection;return p.YR.deselect(e),p.YR.removeNodes(e,{at:[n.index]}),p.YR.insertNodes(e,e.pteCreateTextBlock({decorators:[]})),t&&p.YR.select(e,{anchor:{path:[0,0],offset:0},focus:{path:[0,0],offset:0}}),e.onChange(),!0}return p.YR.removeNodes(e,{at:[n.index]}),!0}let o=tq(n,t.path);if(e.isTextBlock(n.node)&&o&&"children"===t.path[1]&&3===t.path.length)return p.YR.removeNodes(e,{at:[n.index,o.index]}),!0;if(o&&!p.xv.isText(o.node)){let i=t.path.slice(3).at(0);if(void 0===i||"string"==typeof i&&["_key","_type","children","__inline"].includes(i))return!1;let r="value"in o.node&&"object"==typeof o.node.value?o.node.value:{},a=(0,B.g7)(r,[{...t,path:t.path.slice(3)}]);return p.YR.setNodes(e,{...o.node,value:a},{at:[n.index,o.index]}),!0}if(o&&p.xv.isText(o.node)){let i=t.path.slice(3),r=i.at(0);if(void 0===r||"string"==typeof r&&["_key","_type"].includes(r))return!1;if("string"==typeof r&&"text"===r)return e.apply({type:"remove_text",path:[n.index,o.index],offset:0,text:o.node.text}),!0;let a=Object.keys((0,B.g7)(o.node,[{...t,path:i}])),l=Object.keys(o.node).filter(e=>!a.includes(e));return p.YR.unsetNodes(e,l,{at:[n.index,o.index]}),!0}if(!o&&"value"in n.node){let o=(0,B.g7)(n.node.value,[{...t,path:t.path.slice(1)}]);return p.YR.setNodes(e,{...n.node,value:o},{at:[n.index]}),!0}return!1}(e,t);break;case"set":n=function(e,t){let n=t.value;"string"==typeof t.path[3]&&((n={})[t.path[3]]=t.value);let o=tJ(e.children,t.path);if(!o)return!1;let i=e.isTextBlock(o.node);if(i&&t.path.length>1&&"children"!==t.path[1])return!1;let r=tq(o,t.path);if(i&&r){if(p.xv.isText(r.node)){if(p.xv.isText(n)){let t=r.node.text,i=n.text;t!==i&&(e.apply({type:"remove_text",path:[o.index,r.index],offset:0,text:t}),e.apply({type:"insert_text",path:[o.index,r.index],offset:0,text:i}),e.onChange())}else{let n=t.path.slice(3),i=n.at(0);if(void 0===i||"string"==typeof i&&["_key","_type","text"].includes(i))return!1;let a=(0,B.g7)(r.node,[{...t,path:n}]);p.YR.setNodes(e,a,{at:[o.index,r.index]})}}else{let n=t.path.slice(3).at(0);if(void 0===n||"string"==typeof n&&["_key","_type","children","__inline"].includes(n))return!1;let i="value"in r.node&&"object"==typeof r.node.value?r.node.value:{},a=(0,B.g7)(i,[{...t,path:t.path.slice(3)}]);p.YR.setNodes(e,{...r.node,value:a},{at:[o.index,r.index]})}}else if(p.W_.isElement(o.node)&&1===t.path.length){let{children:t,...i}=n,{children:r,...a}=o.node||{children:void 0};e.apply({type:"set_node",path:[o.index],properties:{...a},newProperties:i});let l=o.node;l.children.forEach((t,n)=>{e.apply({type:"remove_node",path:[o.index,l.children.length-1-n],node:t})}),Array.isArray(t)&&t.forEach((t,n)=>{e.apply({type:"insert_node",path:[o.index,n],node:t})})}else if(o&&"value"in o.node){if(!(t.path.length>1)||"children"===t.path[1])return!1;{let n=(0,B.g7)(o.node.value,[{...t,path:t.path.slice(1)}]);p.YR.setNodes(e,{...o.node,value:n},{at:[o.index]})}}return!0}(e,t);break;case"diffMatchPatch":n=function(e,t){let n=tJ(e.children,t.path);if(!n)return!1;let o=tq(n,t.path);if(!o||!(n&&e.isTextBlock(n.node)&&4===t.path.length&&"children"===t.path[1]&&"text"===t.path[3])||!p.xv.isText(o.node))return!1;let[i]=function(e,t,n={}){if("string"==typeof e)throw Error("Patches must be an array - pass the patch to `parsePatch()` first");let o=t;if(0===e.length)return[o,[]];let i=function(e,t,n={}){let o=0,i=0;function r(e){for(;o<e;){let e=t.codePointAt(i);if(typeof e>"u")return i;o+=tw(e),e>65535?i+=2:i+=1}if(!n.allowExceedingIndices&&o!==e)throw Error("Failed to determine byte offset");return i}let a=[];for(let t of e)a.push({diffs:t.diffs.map(e=>eZ(e)),start1:r(t.start1),start2:r(t.start2),utf8Start1:t.utf8Start1,utf8Start2:t.utf8Start2,length1:t.length1,length2:t.length2,utf8Length1:t.utf8Length1,utf8Length2:t.utf8Length2});return a}(e,o,{allowExceedingIndices:n.allowExceedingIndices}),r=n.margin||4,a=n.deleteThreshold||.4,l=function(e,t=4){let n="";for(let e=1;e<=t;e++)n+=String.fromCharCode(e);for(let n of e)n.start1+=t,n.start2+=t,n.utf8Start1+=t,n.utf8Start2+=t;let o=e[0],i=o.diffs;if(0===i.length||0!==i[0][0])i.unshift([0,n]),o.start1-=t,o.start2-=t,o.utf8Start1-=t,o.utf8Start2-=t,o.length1+=t,o.length2+=t,o.utf8Length1+=t,o.utf8Length2+=t;else if(t>i[0][1].length){let e=i[0][1].length,r=t-e;i[0][1]=n.substring(e)+i[0][1],o.start1-=r,o.start2-=r,o.utf8Start1-=r,o.utf8Start2-=r,o.length1+=r,o.length2+=r,o.utf8Length1+=r,o.utf8Length2+=r}if(0===(i=(o=e[e.length-1]).diffs).length||0!==i[i.length-1][0])i.push([0,n]),o.length1+=t,o.length2+=t,o.utf8Length1+=t,o.utf8Length2+=t;else if(t>i[i.length-1][1].length){let e=t-i[i.length-1][1].length;i[i.length-1][1]+=n.substring(0,e),o.length1+=e,o.length2+=e,o.utf8Length1+=e,o.utf8Length2+=e}return n}(i,r);o=l+o+l,function(e,t=4){for(let n=0;n<e.length;n++){if(e[n].length1<=32)continue;let o=e[n];e.splice(n--,1);let i=o.start1,r=o.start2,a="";for(;0!==o.diffs.length;){let l=tS(i-a.length,r-a.length),s=!0;if(""!==a){let e=tE(a);l.length1=a.length,l.utf8Length1=e,l.length2=a.length,l.utf8Length2=e,l.diffs.push([0,a])}for(;0!==o.diffs.length&&l.length1<32-t;){let e=o.diffs[0][0],n=o.diffs[0][1],a=tE(n);if(1===e){l.length2+=n.length,l.utf8Length2+=a,r+=n.length;let e=o.diffs.shift();e&&l.diffs.push(e),s=!1}else -1===e&&1===l.diffs.length&&0===l.diffs[0][0]&&n.length>64?(l.length1+=n.length,l.utf8Length1+=a,i+=n.length,s=!1,l.diffs.push([e,n]),o.diffs.shift()):(a=tE(n=n.substring(0,32-l.length1-t)),l.length1+=n.length,l.utf8Length1+=a,i+=n.length,0===e?(l.length2+=n.length,l.utf8Length2+=a,r+=n.length):s=!1,l.diffs.push([e,n]),n===o.diffs[0][1]?o.diffs.shift():o.diffs[0][1]=o.diffs[0][1].substring(n.length))}a=(a=tx(l.diffs)).substring(a.length-t);let c=tb(o.diffs).substring(0,t),d=tE(c);""!==c&&(l.length1+=c.length,l.length2+=c.length,l.utf8Length1+=d,l.utf8Length2+=d,0!==l.diffs.length&&0===l.diffs[l.diffs.length-1][0]?l.diffs[l.diffs.length-1][1]+=c:l.diffs.push([0,c])),s||e.splice(++n,0,l)}}}(i,r);let s=0,c=[];for(let e=0;e<i.length;e++){let t=i[e].start2+s,n=tb(i[e].diffs),r,l=-1;if(n.length>32?-1!==(r=tv(o,n.substring(0,32),t))&&(-1===(l=tv(o,n.substring(n.length-32),t+n.length-32))||r>=l)&&(r=-1):r=tv(o,n,t),-1===r)c[e]=!1,s-=i[e].length2-i[e].length1;else{let d;if(c[e]=!0,s=r-t,d=-1===l?o.substring(r,r+n.length):o.substring(r,l+32),n===d)o=o.substring(0,r)+tx(i[e].diffs)+o.substring(r+n.length);else{let t=te(n,d,{checkLines:!1});if(n.length>32&&function(e){let t=0,n=0,o=0;for(let i=0;i<e.length;i++){let r=e[i][0],a=e[i][1];switch(r){case 1:n+=a.length;break;case -1:o+=a.length;break;case 0:t+=Math.max(n,o),n=0,o=0;break;default:throw Error("Unknown diff operation.")}}return t+Math.max(n,o)}(t)/n.length>a)c[e]=!1;else{t=td(t);let n=0,a=0;for(let l=0;l<i[e].diffs.length;l++){let s=i[e].diffs[l];0!==s[0]&&(a=t_(t,n)),1===s[0]?o=o.substring(0,r+a)+s[1]+o.substring(r+a):-1===s[0]&&(o=o.substring(0,r+a)+o.substring(r+t_(t,n+s[1].length))),-1!==s[0]&&(n+=s[1].length)}}}}}return[o=o.substring(l.length,o.length-l.length),c]}(tM(t.value),o.node.text,{allowExceedingIndices:!0}),r=function(e,t=4){let n=e.map(e=>eZ(e)),o=!1,i=[],r=0,a=null,l=0,s=!1,c=!1,d=!1,p=!1;for(;l<n.length;)0===n[l][0]?(n[l][1].length<t&&(d||p)?(i[r++]=l,s=d,c=p,a=n[l][1]):(r=0,a=null),d=!1,p=!1):(-1===n[l][0]?p=!0:d=!0,a&&(s&&c&&d&&p||a.length<t/2&&3===function(...e){return e.reduce((e,t)=>
3e+(t?1:0),0)}(s,c,d,p))&&(n.splice(i[r-1],0,[-1,a]),n[i[r-1]+1][0]=1,r--,a=null,s&&c?(d=!0,p=!0,r=0):(l=--r>0?i[r-1]:-1,d=!1,p=!1),o=!0)),l++;return o&&(n=tp(n)),n}(te(o.node.text,i),5),a=0;for(let[t,i]of r)1===t?(e.apply({type:"insert_text",path:[n.index,o.index],offset:a,text:i}),a+=i.length):-1===t?e.apply({type:"remove_text",path:[n.index,o.index],offset:a,text:i}):0===t&&(a+=i.length);return!0}(e,t)}}catch(e){console.error(e)}return n});return function(o){ed.set(o,!1),tH.set(o,!0),i=[...o.children];let{apply:a}=o,l=[],s=()=>{if(0===l.length)return;let e=l;l=[];let t=!1;eF(o,()=>{p.ML.withoutNormalizing(o,()=>{tX(o,()=>{t$(o,()=>{for(let n of e){tZ.enabled&&tZ(`Handling remote patch ${JSON.stringify(n)}`);try{t=r(o,n)}catch(e){console.error(`Applying patch ${JSON.stringify(n)} failed due to: ${e.message}`)}}})})}),t&&(o.normalize(),o.onChange())})},c=({patches:e})=>{let t=e.filter(e=>"local"!==e.origin);0!==t.length&&(l=l.concat(t),s())};return n.push(()=>{tZ("Subscribing to remote patches");let t=e.on("patches",c);return()=>{tZ("Unsubscribing to remote patches"),t.unsubscribe()}}),o.apply=n=>{let r=[],l=X(i=o.children,e.getSnapshot().context.schema);a(n);let s=X(o.children,e.getSnapshot().context.schema);if(!tH.get(o))return o;switch(l&&!s&&"set_selection"!==n.type&&r.push((0,B.$T)(i,"before",[0])),n.type){case"insert_text":r=[...r,...function(e,t,n,o){let i=(0,y.dz)({schema:e},t[n.path[0]])&&t[n.path[0]];if(!i)throw Error("Could not find block");let r=(0,y.dz)({schema:e},i)&&(0,y.dn)({schema:e},i.children[n.path[1]])&&i.children[n.path[1]];if(!r)throw Error("Could not find child");let a=[{_key:i._key},"children",{_key:r._key},"text"],l=o[n.path[0]],s=(0,y.dz)({schema:e},l)&&l.children[n.path[1]],c=(0,y.dn)({schema:e},s)?s.text:"",d=(0,B.aH)(c,r.text,a);return d.value.length?[d]:[]}(e.getSnapshot().context.schema,o.children,n,i)];break;case"remove_text":r=[...r,...function(e,t,n,o){let i=t[n.path[0]];if(!i)throw Error("Could not find block");let r=(0,y.dz)({schema:e},i)&&i.children[n.path[1]]||void 0,a=(0,y.dn)({schema:e},r)?r:void 0;if(r&&!a)throw Error("Expected span");if(!a)throw Error("Could not find child");let l=[{_key:i._key},"children",{_key:a._key},"text"],s=o[n.path[0]],c=(0,y.dz)({schema:e},s)&&s.children[n.path[1]],d=(0,y.dn)({schema:e},c)&&c.text,p=(0,B.aH)(d||"",a.text,l);return p.value?[p]:[]}(e.getSnapshot().context.schema,o.children,n,i)];break;case"remove_node":r=[...r,...function(e,t,n){let o=t[n.path[0]];if(1===n.path.length){if(o&&o._key)return[(0,B.zN)([{_key:o._key}])];throw Error("Block not found")}if(!(0,y.dz)({schema:e},o)||2!==n.path.length)return[];{let e=o.children[n.path[1]];return e?o.children.filter(e=>e._key===n.node._key).length>1?(console.warn(`Multiple spans have \`_key\` ${n.node._key}. It's ambiguous which one to remove.`,JSON.stringify(o,null,2)),[]):[(0,B.zN)([{_key:o._key},"children",{_key:e._key}])]:[]}}(e.getSnapshot().context.schema,i,n)];break;case"split_node":r=[...r,...function(e,t,n,o){let i=[],r=t[n.path[0]];if(!(0,y.dz)({schema:e},r))throw Error(`Block with path ${JSON.stringify(n.path[0])} is not a text block and can't be split`);if(1===n.path.length){let a=o[n.path[0]];if((0,y.dz)({schema:e},a)){let o=H([t[n.path[0]+1]],e.block.name)[0];o&&(i.push((0,B.$T)([o],"after",[{_key:r._key}])),a.children.slice(n.position).forEach(e=>{let t=[{_key:a._key},"children",{_key:e._key}];i.push((0,B.zN)(t))}))}return i}if(2===n.path.length){let t=r.children[n.path[1]];if((0,y.dn)({schema:e},t)){let o=H([{...r,children:r.children.slice(n.path[1]+1,n.path[1]+2)}],e.block.name)[0].children;i.push((0,B.Cb)([],[{_key:r._key},"children"])),i.push((0,B.$T)(o,"after",[{_key:r._key},"children",{_key:t._key}])),i.push((0,B.t8)(t.text,[{_key:r._key},"children",{_key:t._key},"text"]))}}return i}(e.getSnapshot().context.schema,o.children,n,i)];break;case"insert_node":r=[...r,...function(e,t,n,o){let i=o[n.path[0]];if(1===n.path.length){let t=0===n.path[0]?"before":"after",r=o[n.path[0]-1],a=0===n.path[0]?i?._key:r?._key;return a?[(0,B.$T)([H([n.node],e.block.name)[0]],t,[{_key:a}])]:[(0,B.Cb)(o,[]),(0,B.$T)([H([n.node],e.block.name)[0]],"before",[n.path[0]])]}if((0,y.dz)({schema:e},i)&&2===n.path.length&&t[n.path[0]]){let t=0!==i.children.length&&i.children[n.path[1]-1]?"after":"before",o={...n.node};
3!o._type&&p.xv.isText(o)&&(o._type="span",o.marks=[]);let r=H([{_key:"bogus",_type:e.block.name,children:[o]}],e.block.name)[0].children[0];return[(0,B.Cb)([],[{_key:i._key},"children"]),(0,B.$T)([r],t,[{_key:i._key},"children",i.children.length<=1||!i.children[n.path[1]-1]?0:{_key:i.children[n.path[1]-1]._key}])]}return[]}(e.getSnapshot().context.schema,o.children,n,i)];break;case"set_node":r=[...r,...function(e,t,n){if(1===n.path.length){let o=t[n.path[0]];if("string"!=typeof o._key)throw Error("Expected block to have a _key");let i=L({...t[n.path[0]],...n.newProperties},U);return[(0,B.t8)(H([i],e.block.name)[0],[{_key:o._key}])]}if(2===n.path.length){let o=t[n.path[0]];if((0,y.dz)({schema:e},o)){let e=o.children[n.path[1]];if(e){let t=o._key,i=e._key,r=[],a=Object.keys(n.newProperties);return a.forEach(l=>{if(1===a.length&&"_key"===l){let i=Y(n.newProperties,l);r.push((0,B.t8)(i,[{_key:t},"children",o.children.indexOf(e),l]))}else{let e=Y(n.newProperties,l);r.push((0,B.t8)(e,[{_key:t},"children",{_key:i},l]))}}),r}throw Error("Could not find a valid child")}throw Error("Could not find a valid block")}throw Error(`Unexpected path encountered: ${JSON.stringify(n.path)}`)}(e.getSnapshot().context.schema,o.children,n)];break;case"merge_node":r=[...r,...function(e,t,n,o){let i=[],r=o[n.path[0]],a=t[n.path[0]];if(1===n.path.length){if(r?._key){let o=H([t[n.path[0]-1]],e.block.name)[0];i.push((0,B.t8)(o,[{_key:o._key}])),i.push((0,B.zN)([{_key:r._key}]))}else throw Error("Target key not found!")}else if((0,y.dz)({schema:e},r)&&(0,y.dz)({schema:e},a)&&2===n.path.length){let t=a.children[n.path[1]-1]&&(0,y.dn)({schema:e},a.children[n.path[1]-1])?a.children[n.path[1]-1]:void 0,o=r.children[n.path[1]]&&(0,y.dn)({schema:e},r.children[n.path[1]])?r.children[n.path[1]]:void 0;t&&(1===r.children.filter(e=>e._key===t._key).length?i.push((0,B.t8)(t.text,[{_key:r._key},"children",{_key:t._key},"text"])):console.warn(`Multiple spans have \`_key\` ${t._key}. It's ambiguous which one to update.`,JSON.stringify(r,null,2))),o&&(1===r.children.filter(e=>e._key===o._key).length?i.push((0,B.zN)([{_key:r._key},"children",{_key:o._key}])):console.warn(`Multiple spans have \`_key\` ${o._key}. It's ambiguous which one to remove.`,JSON.stringify(r,null,2)))}return i}(e.getSnapshot().context.schema,o.children,n,i)];break;case"move_node":r=[...r,...function(e,t,n){let o=[],i=t[n.path[0]],r=t[n.newPath[0]];if(!r)return o;if(1===n.path.length){let t=n.path[0]>n.newPath[0]?"before":"after";o.push((0,B.zN)([{_key:i._key}])),o.push((0,B.$T)([H([i],e.block.name)[0]],t,[{_key:r._key}]))}else if(2===n.path.length&&(0,y.dz)({schema:e},i)&&(0,y.dz)({schema:e},r)){let t=i.children[n.path[1]],a=r.children[n.newPath[1]],l=n.newPath[1]===r.children.length?"after":"before",s=H([i],e.block.name)[0].children[n.path[1]];o.push((0,B.zN)([{_key:i._key},"children",{_key:t._key}])),o.push((0,B.Cb)([],[{_key:r._key},"children"])),o.push((0,B.$T)([s],l,[{_key:r._key},"children",{_key:a._key}]))}return o}(e.getSnapshot().context.schema,i,n)]}if(!l&&s&&["merge_node","set_node","remove_text","remove_node"].includes(n.type)&&(r=[...r,(0,B.zN)([])],t.send({type:"unset",previousValue:H(i,e.getSnapshot().context.schema.block.name,eu.get(o))})),l&&r.length>0&&(r=[(0,B.Cb)([],[]),...r]),r.length>0)for(let t of r)e.send({type:"internal.patch",patch:{...t,origin:"local"},operationId:tK.get(o),value:o.value});return o},o}}({editorActor:n,relayActor:o,subscriptions:t.subscriptions}),a=function(e){let{editorActor:t}=e;return n=>{let o=H(n.children,t.getSnapshot().context.schema.block.name),i=tD(n),r=tA(n);e.subscriptions.push(()=>{tI("Subscribing to patches");let e=t.on("patches",({patches:e,snapshot:t})=>{let r=!1;e.forEach(e=>{if(!r&&"local"!==e.origin&&i){if("unset"===e.type&&0===e.path.length){tI("Someone else cleared the content, resetting undo/redo history"),n.history={undos:[],redos:[]},i.splice(0,i.length),tT.set(n,!0),r=!0;return}i.push({patch:e,time:new Date,snapshot:t,previousSnapshot:o})}}),o=t});return()=>{tI("Unsubscribing to patches"),e.unsubscribe()}}),n.history={undos:[],redos:[]};let{apply:a}=n;return n.apply=e=>{if(t.getSnapshot().matches({"edit mode":"read only"})||eK(n)||eJ(n)||eq(n)){a(e);return}let{operations:o,history:i}=n,{undos:l}=i,s=l[l.length-1],c=s&&s.operations&&s.operations[s.operations.length-1],d=tL(e,c),p=tB(n),u=tA(n),h=u===r;if(p){if(s?0===o.length&&(h=void 0===u&&void 0===r?tU(e,c)||d:h):h=!1,s&&h)s.operations.push(e);else{let t={operations:[...null===n.selection?[]:[{type:"set_selection",properties:{...n.selection},newProperties:{...n.selection}}],e],timestamp:new Date};l.push(t),tI("Created new undo step",s)}for(;l.length>1e3;)l.shift();tz(e)&&(i.redos=[])}r=u,a(e)},n}}({editorActor:n,subscriptions:t.subscriptions});return function(e){if(void 0!==n.getSnapshot().context.maxBlocks)return e;let{delete:t,select:o}=e;return e.delete=o=>{if(tW(e)){t(o);return}let i=o?.at??e.selection;if(!i){console.error("Unexpected call to .delete(...) without `at` option");return}
3let r=p.ML.range(e,i),a=er({schema:n.getSnapshot().context.schema,editor:e,range:r});if(!a){console.error("Unexpected call to .delete(...) with invalid `at` option");return}n.send({type:"behavior event",behaviorEvent:{type:"delete",at:a,direction:o?.reverse?"backward":"forward",unit:o?.unit},editor:e})},e.deleteBackward=t=>{if(tW(e)){console.error("Unexpected call to .deleteBackward(...)");return}n.send({type:"behavior event",behaviorEvent:{type:"delete.backward",unit:t},editor:e})},e.deleteForward=t=>{if(tW(e)){console.error("Unexpected call to .deleteForward(...)");return}n.send({type:"behavior event",behaviorEvent:{type:"delete.forward",unit:t},editor:e})},e.insertBreak=()=>{if(tW(e)){console.error("Unexpected call to .insertBreak(...)");return}n.send({type:"behavior event",behaviorEvent:{type:"insert.break"},editor:e})},e.insertData=t=>{if(tW(e)){console.error("Unexpected call to .insertData(...)");return}n.send({type:"behavior event",behaviorEvent:{type:"input.*",originEvent:{dataTransfer:t}},editor:e})},e.insertSoftBreak=()=>{if(tW(e)){ez({context:{keyGenerator:n.getSnapshot().context.keyGenerator,schema:n.getSnapshot().context.schema},operation:{text:` 4`,editor:e}});return}n.send({type:"behavior event",behaviorEvent:{type:"insert.soft break"},editor:e})},e.insertText=t=>{if(tW(e)){ez({context:{keyGenerator:n.getSnapshot().context.keyGenerator,schema:n.getSnapshot().context.schema},operation:{text:t,editor:e}});return}n.send({type:"behavior event",behaviorEvent:{type:"insert.text",text:t},editor:e})},e.redo=()=>{if(tW(e)){tF({context:{keyGenerator:n.getSnapshot().context.keyGenerator,schema:n.getSnapshot().context.schema},operation:{type:"history.redo",editor:e}});return}n.send({type:"behavior event",behaviorEvent:{type:"history.redo"},editor:e})},e.select=t=>{if(tW(e)){o(t);return}let i=p.ML.range(e,t);n.send({type:"behavior event",behaviorEvent:{type:"select",at:er({schema:n.getSnapshot().context.schema,editor:e,range:i})},editor:e})},e.setFragmentData=()=>{console.error("Unexpected call to .setFragmentData(...)")},e.undo=()=>{if(tW(e)){tF({context:{keyGenerator:n.getSnapshot().context.keyGenerator,schema:n.getSnapshot().context.schema},operation:{type:"history.undo",editor:e}});return}n.send({type:"behavior event",behaviorEvent:{type:"history.undo"},editor:e})},e}(i(function(e){let{apply:t,normalizeNode:o}=e;return e.apply=o=>
4{if(eK(e)||eJ(e)||eq(e)){t(o);return}if("split_node"===o.type){let i=[...p.NB.descendants(e)].map(([e])=>e._key);t({...o,properties:{...o.properties,_key:void 0===o.properties._key||i.includes(o.properties._key)?n.getSnapshot().context.keyGenerator():o.properties._key}});return}if("insert_node"===o.type&&!p.ML.isEditor(o.node)){let i=[...p.NB.descendants(e)].map(([e])=>e._key);t({...o,node:{...o.node,_key:void 0===o.node._key||i.includes(o.node._key)?n.getSnapshot().context.keyGenerator():o.node._key}});return}t(o)},e.normalizeNode=t=>{let[i,r]=t;if(p.W_.isElement(i)&&i._type===n.getSnapshot().context.schema.block.name){if(!i._key){n.send({type:"normalizing"}),p.YR.setNodes(e,{_key:n.getSnapshot().context.keyGenerator()},{at:r}),n.send({type:"done normalizing"});return}for(let[t,o]of p.NB.children(e,r))if(!t._key){n.send({type:"normalizing"}),p.YR.setNodes(e,{_key:n.getSnapshot().context.keyGenerator()},{at:o}),n.send({type:"done normalizing"});return}}o(t)},e}(function(e){let{apply:t,normalizeNode:o}=e,i=n.getSnapshot().context.schema.decorators.map(e=>e.name);return e.normalizeNode=t=>{let[i,r]=t;if(e.isTextBlock(i))for(let[t,o]of p.NB.children(e,r)){let r=i.children[o[1]+1];if(e.isTextSpan(t)&&e.isTextSpan(r)&&t.marks?.every(e=>r.marks?.includes(e))&&r.marks?.every(e=>t.marks?.includes(e))){eX("Merging spans",JSON.stringify(t,null,2),JSON.stringify(r,null,2)),n.send({type:"normalizing"}),p.YR.mergeNodes(e,{at:[o[0],o[1]+1],voids:!0}),n.send({type:"done normalizing"});return}}if(e.isTextBlock(i)&&!Array.isArray(i.markDefs)){eX("Adding .markDefs to block node"),n.send({type:"normalizing"}),p.YR.setNodes(e,{markDefs:[]},{at:r}),n.send({type:"done normalizing"});return}if(e.isTextSpan(i)&&!Array.isArray(i.marks)){eX("Adding .marks to span node"),n.send({type:"normalizing"}),p.YR.setNodes(e,{marks:[]},{at:r}),n.send({type:"done normalizing"});return}if(e.isTextSpan(i)){let t=p.y$.parent(r),[o]=p.ML.node(e,t),a=n.getSnapshot().context.schema.decorators.map(e=>e.name),l=i.marks?.filter(e=>!a.includes(e));if(e.isTextBlock(o)&&""===i.text&&l&&l.length>0){eX("Removing annotations from empty span node"),n.send({type:"normalizing"}),p.YR.setNodes(e,{marks:i.marks?.filter(e=>a.includes(e))},{at:r}),n.send({type:"done normalizing"});return}}if(e.isTextBlock(i)){let t=n.getSnapshot().context.schema.decorators.map(e=>e.name);for(let[o,a]of p.NB.children(e,r))if(e.isTextSpan(o)){let r=o.marks??[],l=r.filter(e=>!t.includes(e)&&!i.markDefs?.find(t=>t._key===e));if(l.length>0){eX("Removing orphaned annotations from span node"),n.send({type:"normalizing"}),p.YR.setNodes(e,{marks:r.filter(e=>!l.includes(e))},{at:a}),n.send({type:"done normalizing"});return}}}if(e.isTextSpan(i)){let t=p.y$.parent(r),[o]=p.ML.node(e,t);if(e.isTextBlock(o)){let t=n.getSnapshot().context.schema.decorators.map(e=>e.name),a=i.marks??[],l=a.filter(e=>!t.includes(e)&&!o.markDefs?.find(t=>t._key===e));if(l.length>0){eX("Removing orphaned annotations from span node"),n.send({type:"normalizing"}),p.YR.setNodes(e,{marks:a.filter(e=>!l.includes(e))},{at:r}),n.send({type:"done normalizing"});return}}}if(e.isTextBlock(i)){let t=i.markDefs??[],o=new Set,a=[];for(let e of t)o.has(e._key)||(o.add(e._key),a.push(e));if(t.length!==a.length){eX("Removing duplicate markDefs"),n.send({type:"normalizing"}),p.YR.setNodes(e,{markDefs:a},{at:r}),n.send({type:"done normalizing"});return}}if(e.isTextBlock(i)&&!e.operations.some(e=>"merge_node"===e.type&&"markDefs"in e.properties&&1===e.path.length)){let t=(i.markDefs||[]).filter(e=>i.children.find(t=>p.xv.isText(t)&&Array.isArray(t.marks)&&t.marks.includes(e._key)));if(i.markDefs&&!m(t,i.markDefs)){eX("Removing markDef not in use"),n.send({type:"normalizing"}),p.YR.setNodes(e,{markDefs:t},{at:r}),n.send({type:"done normalizing"});return}}o(t)},e.apply=o=>
4{if(eK(e)||eJ(e)||eq(e)){t(o);return}if("set_selection"===o.type&&o.properties&&o.newProperties&&o.properties.anchor&&o.properties.focus&&o.newProperties.anchor&&o.newProperties.focus){let t=p.e6.isCollapsed({anchor:o.properties.anchor,focus:o.properties.focus}),n=p.e6.isCollapsed({anchor:o.newProperties.anchor,focus:o.newProperties.focus});if(t&&n){let t=Array.from(p.ML.nodes(e,{mode:"lowest",at:o.properties.focus,match:t=>e.isTextSpan(t),voids:!1}))[0]?.[0],n=Array.from(p.ML.nodes(e,{mode:"lowest",at:o.newProperties.focus,match:t=>e.isTextSpan(t),voids:!1}))[0]?.[0],i=t&&n&&o.newProperties.focus.path[0]===o.properties.focus.path[0]&&o.newProperties.focus.path[1]===o.properties.focus.path[1]+1&&t.text.length===o.properties.focus.offset&&0===o.newProperties.focus.offset,r=t&&n&&o.newProperties.focus.path[0]===o.properties.focus.path[0]&&o.newProperties.focus.path[1]===o.properties.focus.path[1]-1&&0===o.properties.focus.offset&&n.text.length===o.newProperties.focus.offset;i||r||(e.decoratorState={})}}if("insert_node"===o.type){let{selection:t}=e;if(t){let[r,a]=p.ML.node(e,t,{depth:1}),l=eP({editor:e,blockPath:a,spanPath:o.path}),s=l?l.marks?.filter(e=>!i.includes(e)):[],c=eG({editor:e,blockPath:a,spanPath:[o.path[0],o.path[1]-1]}),d=c?c.marks?.filter(e=>!i.includes(e)):[],u=s?.filter(e=>!d?.includes(e))??[],h=u.length>0;if(h&&e$(o.node)&&o.node.marks?.some(e=>u.includes(e))){p.YR.insertNodes(e,{...o.node,_key:n.getSnapshot().context.keyGenerator(),marks:o.node.marks?.filter(e=>!u.includes(e))??[]});return}let f=d?.filter(e=>!s?.includes(e))??[],y=f.length>0;if(y&&e$(o.node)&&o.node.marks?.some(e=>f.includes(e))){p.YR.insertNodes(e,{...o.node,_key:n.getSnapshot().context.keyGenerator(),marks:o.node.marks?.filter(e=>!f.includes(e))??[]});return}let g=c?.marks?.filter(e=>i.includes(e))??[];if(g.length>0&&h&&!y&&e$(o.node)&&o.node.marks?.length===0){p.YR.insertNodes(e,{...o.node,_key:n.getSnapshot().context.keyGenerator(),marks:g});return}}}if("insert_text"===o.type){let i=eH({editorActorSnapshot:n.getSnapshot(),slateEditorInstance:e}),r=(0,v.zd)(i);if(!r||"unchanged"===r.state){t(o);return}p.YR.insertNodes(e,{_type:"span",_key:n.getSnapshot().context.keyGenerator(),text:o.text,marks:r.marks});return}if("remove_text"===o.type){let{selection:a}=e;if(a&&p.e6.isExpanded(a)){var r;let[l,s]=p.ML.node(e,a,{depth:1}),[c,d]=Array.from(p.ML.nodes(e,{mode:"lowest",at:{path:o.path,offset:o.offset},match:t=>e.isTextSpan(t),voids:!1}))[0]??[void 0,void 0];if(c&&l&&"string"==typeof(r=l)._type&&"@"!==r._type[0]&&(!("markDefs"in r)||!r.markDefs||Array.isArray(r.markDefs)&&r.markDefs.every(e=>"string"==typeof e._key))&&"children"in r&&Array.isArray(r.children)&&r.children.every(e=>"object"==typeof e&&"_type"in e)){let r=l.markDefs??[],a=c.marks??[],u=a.some(e=>r.find(t=>t._key===e)),h=o.offset+o.text.length===c.text.length,f=0===o.offset&&h,y=eP({editor:e,blockPath:s,spanPath:d}),g=eG({editor:e,blockPath:s,spanPath:d}),m=!!y&&y.marks?.some(e=>!i.includes(e)&&a.includes(e)),k=!!g&&g.marks?.some(e=>!i.includes(e)&&a.includes(e));if(u&&f&&!m&&!k){let i=eH({editorActorSnapshot:n.getSnapshot(),slateEditorInstance:e});p.ML.withoutNormalizing(e,()=>{t(o),p.YR.setNodes(e,{marks:(0,v.WH)(i)},{at:o.path})}),e.onChange();return}}}}if("merge_node"===o.type&&1===o.path.length&&"markDefs"in o.properties&&o.properties._type===n.getSnapshot().context.schema.block.name&&Array.isArray(o.properties.markDefs)&&o.properties.markDefs.length>0&&o.path[0]-1>=0){let[n,i]=p.ML.node(e,[o.path[0]-1]);if(e.isTextBlock(n)){let r=_([...Array.isArray(n.markDefs)&&n.markDefs||[],...o.properties.markDefs]);eX("Copying markDefs over to merged block",o),p.YR.setNodes(e,{markDefs:r},{at:i,voids:!1}),t(o);return}}t(o)},e}(function(e){let{apply:t}=e;return e.apply=o=>
4{if(n.getSnapshot().matches({"edit mode":"read only"})||eK(e)||eJ(e)||eq(e)){t(o);return}if("remove_node"===o.type){let t=o.path.at(0),i=1===o.path.length&&0===t&&1===e.children.length,r=o.node._type!==n.getSnapshot().context.schema.block.name;i&&r&&(tQ("Adding placeholder block"),p.ML.insertNode(e,e.pteCreateTextBlock({decorators:[]})))}t(o)},e}((function({editorActor:e}){return function(t){return t.pteCreateTextBlock=t=>q([{_type:e.getSnapshot().context.schema.block.name,_key:e.getSnapshot().context.keyGenerator(),style:e.getSnapshot().context.schema.styles[0].name||"normal",...t.listItem?{listItem:t.listItem}:{},...t.level?{level:t.level}:{},markDefs:[],children:[{_type:"span",_key:e.getSnapshot().context.keyGenerator(),text:"",marks:t.decorators.filter(t=>e.getSnapshot().context.schema.decorators.find(({name:e})=>e===t))}]}],{schemaTypes:e.getSnapshot().context.schema})[0],t}})({editorActor:n})(function(e){let{apply:t}=e;return e.apply=o=>{if(n.getSnapshot().matches({"edit mode":"read only"})||eK(e)||eJ(e)||eq(e)){t(o);return}let i=n.getSnapshot().context.maxBlocks??-1;i>0&&e.children.length>=i&&("insert_node"===o.type||"split_node"===o.type)&&1===o.path.length||t(o)},e}(a(r(function(e,t){let{apply:n}=t;return t.apply=o=>
4{if("set_selection"===o.type||(t.value=function(e,t,n){let o=(0,z.P2)({children:t});try{(function(e,t,n){switch(n.type){case"insert_node":{let{path:o,node:i}=n,r=t5(e,t,o),a=o[o.length-1];if(!r||a>r.children.length)break;if(1===o.length){if(t2(e,i)){r.children.splice(a,0,{...i,children:i.children.map(e=>"__inline"in e?{_key:e._key,_type:e._type,..."value"in e&&"object"==typeof e.value?e.value:{}}:e)});break}if(p.W_.isElement(i)&&!("__inline"in i)){r.children.splice(a,0,{_key:i._key,_type:i._type,..."value"in i&&"object"==typeof i.value?i.value:{}});break}}if(2===o.length){if(!t2(e,r))break;if(t8(i)){r.children.splice(a,0,i);break}"__inline"in i&&r.children.splice(a,0,{_key:i._key,_type:i._type,..."value"in i&&"object"==typeof i.value?i.value:{}})}break}case"insert_text":{let{path:o,offset:i,text:r}=n;if(0===r.length)break;let a=t4(e,t,o);if(!a)break;let l=a.text.slice(0,i),s=a.text.slice(i);a.text=l+r+s;break}case"merge_node":{let{path:o}=n,i=t9(e,t,o),r=t9(e,t,p.y$.previous(o)),a=t5(e,t,o);if(!i||!r||!a)break;let l=o[o.length-1];if(t8(i)&&t8(r))r.text+=i.text;else if(t2(e,i)&&t2(e,r))r.children.push(...i.children);else break;a.children.splice(l,1);break}case"move_node":{let{path:o,newPath:i}=n;if(p.y$.isAncestor(o,i))break;let r=t9(e,t,o),a=t5(e,t,o),l=o[o.length-1];if(!r||!a)break;a.children.splice(l,1);let s=p.y$.transform(o,n),c=t9(e,t,p.y$.parent(s)),d=s[s.length-1];if(!c||!("children"in c)||!Array.isArray(c.children))break;c.children.splice(d,0,r);break}case"remove_node":{let{path:o}=n,i=o[o.length-1];t5(e,t,o)?.children.splice(i,1);break}case"remove_text":{let{path:o,offset:i,text:r}=n;if(0===r.length)break;let a=t4(e,t,o);if(!a)break;let l=a.text.slice(0,i),s=a.text.slice(i+r.length);a.text=l+s;break}case"set_node":{let{path:o,properties:i,newProperties:r}=n,a=t9(e,t,o);if(!a||t1(a))break;if(!t1(a)&&!t2(e,a)&&!t3(e,a)&&!t8(a)){let e="value"in i&&"object"==typeof i.value?i.value:{},t="value"in r&&"object"==typeof r.value?r.value:{};for(let e in r){if("value"===e)continue;let t=r[e];null==t?delete a[e]:a[e]=t}for(let e in i)"value"!==e&&(r.hasOwnProperty(e)||delete a[e]);for(let e in t){let n=t[e];null==n?delete a[e]:a[e]=n}for(let n in e)t.hasOwnProperty(n)||delete a[n];break}if(t2(e,a)){for(let e in r){if("children"===e||"text"===e)break;let t=r[e];null==t?delete a[e]:a[e]=t}for(let e in i)r.hasOwnProperty(e)||delete a[e];break}if(t8(a)){for(let e in r){if("text"===e)break;let t=r[e];null==t?delete a[e]:a[e]=t}for(let e in i)r.hasOwnProperty(e)||delete a[e]}break}case"split_node":{let{path:o,position:i,properties:r}=n;if(0===o.length)break;let a=t5(e,t,o),l=o[o.length-1];if(!a)break;if(t1(a)){let n=t6(t,o);if(!n||!t2(e,n))break;let s=n.children.slice(0,i),c=n.children.slice(i);n.children=s;let d={...r,children:c,_type:e.schema.block.name};a.children.splice(l+1,0,d);break}if(t2(e,a)){let n=t9(e,t,o);if(!n||!t3(e,n))break;let s=n.text.slice(0,i),c=n.text.slice(i);n.text=s;let d={...r,text:c};a.children.splice(l+1,0,d)}}}})(e,o,n)}catch(e){console.error(e)}return(0,z._x)(o).children}(e,t.value,o),"insert_text"===o.type||"remove_text"===o.type)){n(o);return}eU({schema:e.schema,value:t.value},{blockIndexMap:t.blockIndexMap,listIndexMap:t.listIndexMap}),n(o)},t}(n.getSnapshot().context,function({editor:e,editorActor:t}){let n=()=>{if(e.selection){let n=eh.get(e.selection);if(n)t.send({type:"update selection",selection:n});else{let n=er({schema:t.getSnapshot().context.schema,editor:e,range:e.selection});eh.set(e.selection,n),t.send({type:"update selection",selection:n})}}else t.send({type:"update selection",selection:null})},{onChange:o}=e;return e.onChange=()=>{o(),t.getSnapshot().matches({setup:"setting up"})||n()},e}({editorActor:n,editor:e})))))))))))},ne=V("setup");function nt(e,t){return{getBlockNodes:e=>(function(e,t){if(!t.context.selection)return[];let n=es(t);if(!n)return[];try{return Array.from(p.ML.nodes(e,{at:n,mode:"highest",match:e=>!p.ML.isEditor(e)})).map(([t])=>f.y2.toDOMNode(e,t))}catch{return[]}})(t,e),getChildNodes:e=>(function(e,t){if(!t.context.selection)return[];let n=es(t);if(!n)return[];try{return Array.from(p.ML.nodes(e,{at:n,mode:"lowest",match:e=>!p.ML.isEditor(e)})).map(([t])=>f.y2.toDOMNode(e,t))}catch{return[]}})(t,e),setDragGhost:({event:t,ghost:n})=>(function({sendBack:e,event:t,ghost:n}){t.originEvent.dataTransfer.setDragImage(n.element,n.x,n.y),e({type:"set drag ghost",ghost:n.element})})({sendBack:e,event:t,ghost:n})}}let nn=(0,x.gg)({on:"annotation.add",guard:({snapshot:e})=>
4{if(!(0,k.dI)(e))return!1;let t=(0,v.Ih)(e);return!!(t&&(0,k.sC)({context:{...e.context,selection:t}}))&&{caretWordSelection:t}},actions:[({event:e},{caretWordSelection:t})=>[(0,x.OU)({type:"select",at:t}),(0,x.OU)({type:"annotation.add",annotation:e.annotation})]]}),no={arrowDown:(0,$.vc)({default:[{key:"ArrowDown",alt:!1,ctrl:!1,meta:!1,shift:!1}]}),arrowUp:(0,$.vc)({default:[{key:"ArrowUp",alt:!1,ctrl:!1,meta:!1,shift:!1}]}),break:(0,$.vc)({default:[{key:"Enter",shift:!1}]}),lineBreak:(0,$.vc)({default:[{key:"Enter",shift:!0}]}),decorators:{strong:$.Se,em:$.pU,underline:$.eC,code:$.TU},history:{undo:$.Yw,redo:$.KX},tab:(0,$.vc)({default:[{key:"Tab",alt:!1,ctrl:!1,meta:!1,shift:!1}]}),shiftTab:(0,$.vc)({default:[{key:"Tab",alt:!1,ctrl:!1,meta:!1,shift:!0}]})},ni=(0,x.gg)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>{if(!no.arrowDown.guard(t.originEvent)||!(0,k.dI)(e))return!1;let n=(0,v.ii)(e),o=(0,v.st)(e);return n&&!o},actions:[({snapshot:e})=>[(0,x.OU)({type:"insert.block",block:{_type:e.context.schema.block.name},placement:"after"})]]}),nr=(0,x.gg)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>{if(!no.arrowUp.guard(t.originEvent)||!(0,k.dI)(e))return!1;let n=(0,v.ii)(e),o=(0,v.nt)(e);return n&&!o},actions:[({snapshot:e})=>[(0,x.OU)({type:"insert.block",block:{_type:e.context.schema.block.name},placement:"before"})]]}),na=(0,x.gg)({on:"insert.break",guard:({snapshot:e})=>{let t=(0,v.ii)(e);return(0,k.dI)(e)&&void 0!==t},actions:[({snapshot:e})=>[(0,x.OU)({type:"insert.block",block:{_type:e.context.schema.block.name},placement:"after"})]]}),nl=(0,x.gg)({on:"mouse.click",guard:({snapshot:e,event:t})=>{if(e.context.readOnly||e.context.selection&&!(0,k.dI)(e))return!1;let n=(0,v.ii)({...e,context:{...e.context,selection:t.position.selection}}),o=(0,v.nt)({...e,context:{...e.context,selection:t.position.selection}});return t.position.isEditor&&"start"===t.position.block&&n&&!o},actions:[({snapshot:e,event:t})=>[(0,x.OU)({type:"select",at:t.position.selection}),(0,x.OU)({type:"insert.block",block:{_type:e.context.schema.block.name},placement:"before",select:"start"})]]}),ns=(0,x.gg)({on:"mouse.click",guard:({snapshot:e,event:t})=>{if(e.context.readOnly||e.context.selection&&!(0,k.dI)(e))return!1;let n=(0,v.ii)({...e,context:{...e.context,selection:t.position.selection}}),o=(0,v.st)({...e,context:{...e.context,selection:t.position.selection}});return t.position.isEditor&&"end"===t.position.block&&n&&!o},actions:[({snapshot:e,event:t})=>[(0,x.OU)({type:"select",at:t.position.selection}),(0,x.OU)({type:"insert.block",block:{_type:e.context.schema.block.name},placement:"after",select:"start"})]]}),nc=(0,x.gg)({on:"delete.backward",guard:({snapshot:e})=>{let t=(0,k.I3)(e),n=(0,k.dI)(e),o=(0,v.nt)(e);return!!t&&!!n&&!!o&&!!(0,g.PF)(e.context,t.node)&&!(0,y.dz)(e.context,o.node)&&{focusTextBlock:t,previousBlock:o}},actions:[(e,{focusTextBlock:t,previousBlock:n})=>[(0,x.OU)({type:"delete.block",at:t.path}),(0,x.OU)({type:"select",at:{anchor:{path:n.path,offset:0},focus:{path:n.path,offset:0}}})]]}),nd=(0,x.gg)({on:"delete.forward",guard:({snapshot:e})=>{let t=(0,k.I3)(e),n=(0,k.dI)(e),o=(0,v.st)(e);return!!t&&!!n&&!!o&&!!(0,g.PF)(e.context,t.node)&&!(0,y.dz)(e.context,o.node)&&{focusTextBlock:t,nextBlock:o}},actions:[(e,{focusTextBlock:t,nextBlock:n})=>[(0,x.OU)({type:"delete.block",at:t.path}),(0,x.OU)({type:"select",at:{anchor:{path:n.path,offset:0},focus:{path:n.path,offset:0}}})]]}),np={strongShortcut:(0,x.gg)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>no.decorators.strong.guard(t.originEvent)&&e.context.schema.decorators.some(e=>"strong"===e.name),actions:[()=>[(0,x.OU)({type:"decorator.toggle",decorator:"strong"})]]}),emShortcut:(0,x.gg)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>no.decorators.em.guard(t.originEvent)&&e.context.schema.decorators.some(e=>"em"===e.name),actions:[()=>[(0,x.OU)({type:"decorator.toggle",decorator:"em"})]]}),underlineShortcut:(0,x.gg)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>no.decorators.underline.guard(t.originEvent)&&e.context.schema.decorators.some(e=>"underline"===e.name),actions:[()=>[(0,x.OU)({type:"decorator.toggle",decorator:"underline"})]]}),codeShortcut:(0,x.gg)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>no.decorators.code.guard(t.originEvent)&&e.context.schema.decorators.some(e=>
4"code"===e.name),actions:[()=>[(0,x.OU)({type:"decorator.toggle",decorator:"code"})]]})};function nu(e){if(0===e.length)return new DOMRect(0,0,0,0);let t=e.filter(e=>e instanceof Element),n=t.at(0)?.getBoundingClientRect();if(!n)return new DOMRect(0,0,0,0);let o=n.left,i=n.top,r=n.right,a=n.bottom;for(let e=1;e<t.length;e++){let n=t[e].getBoundingClientRect();o=Math.min(o,n.left),i=Math.min(i,n.top),r=Math.max(r,n.right),a=Math.max(a,n.bottom)}return new DOMRect(o,i,r-o,a-i)}let nh=[(0,x.gg)({on:"drag.dragstart",guard:({snapshot:e,dom:t,event:n})=>{let o=ek({snapshot:e,eventSelection:n.position.selection}),i=(0,v.u7)({...e,context:{...e.context,selection:o}}),r={blockNodes:t.getBlockNodes({...e,context:{...e.context,selection:o}}),childNodes:t.getChildNodes({...e,context:{...e.context,selection:o}})};return{dragSelection:o,draggedDomNodes:r,selectingEntireBlocks:i}},actions:[({dom:e,event:t},{dragSelection:n,draggedDomNodes:o,selectingEntireBlocks:i})=>{let r=document.createElement("div");if(i){for(let e of o.blockNodes.map(e=>e.cloneNode(!0)))e instanceof HTMLElement&&(e.style.position="relative"),r.appendChild(e);let i=r.querySelector("[data-pt-drag-ghost-element]");if(i&&r.replaceChildren(i),r.setAttribute("data-dragged",""),r.style.position="absolute",r.style.left="-99999px",r.style.boxSizing="border-box",document.body.appendChild(r),i){let o=i.getBoundingClientRect(),a=t.originEvent.clientX-o.left,l=t.originEvent.clientY-o.top;return r.style.width=`${o.width}px`,r.style.height=`${o.height}px`,[(0,x.OU)({type:"select",at:n}),(0,x.cE)(()=>{e.setDragGhost({event:t,ghost:{element:r,x:a,y:l}})}),(0,x.eH)(t)]}{let i=nu(o.blockNodes),a=t.originEvent.clientX-i.left,l=t.originEvent.clientY-i.top;return r.style.width=`${i.width}px`,r.style.height=`${i.height}px`,[(0,x.OU)({type:"select",at:n}),(0,x.cE)(()=>{e.setDragGhost({event:t,ghost:{element:r,x:a,y:l}})}),(0,x.eH)(t)]}}{for(let e of o.childNodes.map(e=>e.cloneNode(!0)))r.appendChild(e);r.style.position="absolute",r.style.left="-99999px",r.style.boxSizing="border-box",document.body.appendChild(r);let i=nu(o.childNodes),a=t.originEvent.clientX-i.left,l=t.originEvent.clientY-i.top;return r.style.width=`${i.width}px`,r.style.height=`${i.height}px`,[(0,x.OU)({type:"select",at:n}),(0,x.cE)(()=>{e.setDragGhost({event:t,ghost:{element:r,x:a,y:l}})}),(0,x.eH)(t)]}}]}),(0,x.gg)({on:"drag.dragover",guard:({snapshot:e,event:t})=>{let n=t.dragOrigin;return!!n&&(0,v.Mf)(t.position.selection)({...e,context:{...e.context,selection:n.selection}})},actions:[]}),(0,x.gg)({on:"drag.drop",guard:({snapshot:e,event:t})=>{let n=t.dragOrigin,o=t.position.selection;return!!n&&(0,v.Mf)(o)({...e,context:{...e.context,selection:n.selection}})},actions:[]}),(0,x.gg)({on:"drag.drop",guard:({event:e})=>void 0!==e.dragOrigin,actions:[({event:e})=>[(0,x.OU)({type:"deserialize",originEvent:e})]]}),(0,x.gg)({on:"drag.drop",actions:[({event:e})=>[(0,x.OU)({type:"select",at:e.position.selection}),(0,x.OU)({type:"deserialize",originEvent:e})]]}),(0,x.gg)({on:"deserialization.success",guard:({snapshot:e,event:t})=>{if("drag.drop"!==t.originEvent.type||void 0===t.originEvent.dragOrigin)return!1;let n=t.originEvent.dragOrigin,o=ek({eventSelection:n.selection,snapshot:e}),i=t.originEvent.position.selection,r=!!n&&(0,v.Mf)(i)({...e,context:{...e.context,selection:o}}),a=(0,v.u7)({...e,context:{...e.context,selection:o}}),l=(0,v.wD)({...e,context:{...e.context,selection:o}});return!r&&{dropPosition:i,draggingEntireBlocks:a,draggedBlocks:l,dragOrigin:n,originEvent:t.originEvent}},actions:[({event:e},{draggingEntireBlocks:t,draggedBlocks:n,dragOrigin:o,dropPosition:i,originEvent:r})=>[(0,x.OU)({type:"select",at:i}),...t?n.map(e=>(0,x.OU)({type:"delete.block",at:e.path})):[(0,x.OU)({type:"delete",at:o.selection})],(0,x.OU)({type:"insert.blocks",blocks:e.data,placement:t?"start"===r.position.block?"before":"end"===r.position.block?"after":"auto":"auto"})]]})],nf=(0,x.gg)({on:"insert.break",guard:({snapshot:e})=>{let t=(0,k.I3)(e),n=(0,k.dI)(e);if(!e.context.selection||!t||!n)return!1;let o=(0,v.kr)(t)(e),i=t.node.listItem,r=t.node.level;return!!o&&{focusListItem:i,focusLevel:r}},actions:[({snapshot:e},{focusListItem:t,focusLevel:n})=>[(0,x.OU)({type:"insert.block",block:{_type:e.context.schema.block.name,children:[{_type:e.context.schema.span.name,text:"",marks:[]}],markDefs:[],listItem:t,level:n,style:e.context.schema.styles[0]?.n
4ame},placement:"after"})]]}),ny=(0,x.gg)({on:"insert.break",guard:({snapshot:e})=>{let t=(0,k.I3)(e),n=(0,k.dI)(e);if(!e.context.selection||!t||!n)return!1;let o=(0,k.Cj)(e),i=o?.node.marks?.filter(t=>e.context.schema.decorators.some(e=>e.name===t)??[]),r=o?.node.marks?.filter(t=>!e.context.schema.decorators.some(e=>e.name===t))??[],a=t.node.listItem,l=t.node.level;return!!(0,v.FQ)(t)(e)&&{focusAnnotations:r,focusDecorators:i,focusListItem:a,focusLevel:l}},actions:[({snapshot:e},{focusAnnotations:t,focusDecorators:n,focusListItem:o,focusLevel:i})=>[(0,x.OU)({type:"insert.block",block:{_type:e.context.schema.block.name,children:[{_type:e.context.schema.span.name,marks:0===t.length?n:[],text:""}],listItem:o,level:i,style:e.context.schema.styles[0]?.name},placement:"before",select:"none"})]]}),ng=(0,x.gg)({on:"insert.break",guard:({snapshot:e})=>{if(!e.context.selection||!(0,k.sC)(e))return!1;let t=(0,v.Ui)(e),n=(0,v.Gm)(e);if(!t||!n)return!1;let o=(0,y.qv)({context:e.context,block:t}),i=(0,y.VG)(e.context.selection),r=(0,g.sQ)({context:e.context,block:n}),a=(0,y.OE)(e.context.selection);return!!((0,g.Gh)(o,i)&&(0,g.Gh)(r,a))&&{selection:e.context.selection}},actions:[(e,{selection:t})=>[(0,x.OU)({type:"delete",at:t})]]}),nm=(0,x.gg)({on:"insert.break",guard:({snapshot:e})=>{if(!e.context.selection||!(0,k.sC)(e))return!1;let t=(0,v.wD)(e),n=(0,v.Dm)(e),o=(0,v.Zq)(e);if(!n||!o)return!1;let i=(0,y.qv)({context:e.context,block:n}),r=(0,y.VG)(e.context.selection),a=(0,g.sQ)({context:e.context,block:o}),l=(0,y.OE)(e.context.selection);return!!((0,g.Gh)(r,i)&&(0,g.Gh)(l,a))&&{selectedBlocks:t}},actions:[({snapshot:e},{selectedBlocks:t})=>[(0,x.OU)({type:"insert.block",block:{_type:e.context.schema.block.name,children:[{_type:e.context.schema.span.name,text:"",marks:[]}]},placement:"before",select:"start"}),...t.map(e=>(0,x.OU)({type:"delete.block",at:e.path}))]]}),nk=(0,x.gg)({on:"insert.break",guard:({snapshot:e})=>{let t=(0,k.dI)(e),n=(0,v.fX)(e);return t&&n},actions:[()=>[(0,x.OU)({type:"move.forward",distance:1}),(0,x.OU)({type:"split"})]]}),nv=(0,x.gg)({on:"delete.backward",guard:({snapshot:e})=>{let t=(0,k.dI)(e),n=(0,k.I3)(e),o=(0,k.Cj)(e);return!!t&&!!n&&!!o&&n.node.children[0]._key===o.node._key&&e.context.selection?.focus.offset===0&&1===n.node.level&&{focusTextBlock:n}},actions:[(e,{focusTextBlock:t})=>[(0,x.OU)({type:"block.unset",props:["listItem","level"],at:t.path})]]}),nb=(0,x.gg)({on:"delete.backward",guard:({snapshot:e})=>{let t=(0,k.dI)(e),n=(0,k.I3)(e),o=(0,k.Cj)(e);return!!t&&!!n&&!!o&&n.node.children[0]._key===o.node._key&&e.context.selection?.focus.offset===0&&void 0!==n.node.level&&n.node.level>1&&{focusTextBlock:n,level:n.node.level-1}},actions:[(e,{focusTextBlock:t,level:n})=>[(0,x.OU)({type:"block.set",props:{level:n},at:t.path})]]}),nx=(0,x.gg)({on:"delete.forward",guard:({snapshot:e})=>{let t=(0,v.Ec)(e),n=(0,v.st)(e);return!!(t&&n&&(0,y.dz)(e.context,n.node)&&(0,g.PF)(e.context,t.node))&&{focusListBlock:t,nextBlock:n}},actions:[(e,{nextBlock:t})=>[(0,x.OU)({type:"insert.block",block:t.node,placement:"auto",select:"start"}),(0,x.OU)({type:"delete.block",at:t.path})]]}),n_=(0,x.gg)({on:"delete.backward",guard:({snapshot:e})=>{let t=(0,k.I3)(e),n=(0,v.nt)(e);return!!(t&&n&&(0,y.cd)(e.context,n.node)&&(0,g.PF)(e.context,n.node))&&{focusTextBlock:t,previousBlockEndPoint:(0,g.sQ)({context:e.context,block:n})}},actions:[(e,{focusTextBlock:t,previousBlockEndPoint:n})=>[(0,x.OU)({type:"select",at:{anchor:n,focus:n}}),(0,x.OU)({type:"insert.block",block:t.node,placement:"auto",select:"start"}),(0,x.OU)({type:"delete.block",at:t.path})]]}),nE=(0,x.gg)({on:"insert.break",guard:({snapshot:e})=>{let t=(0,k.dI)(e),n=(0,v.Ec)(e);return!!(t&&n&&(0,g.PF)(e.context,n.node))&&{focusListBlock:n}},actions:[(e,{focusListBlock:t})=>[(0,x.OU)({type:"block.unset",props:["listItem","level"],at:t.path})]]}),nw=(0,x.gg)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>{if(!no.tab.guard(t.originEvent))return!1;let n=(0,v.wD)(e),o=n.flatMap(t=>(0,y.cd)(e.context,t.node)?[{node:t.node,path:t.path}]:[]);return o.length===n.length&&{selectedListBlocks:o}},actions:[(e,{selectedListBlocks:t})=>t.map(e=>(0,x.OU)({type:"block.set",props:{level:Math.min(10,Math.max(1,e.node.level+1))},at:e.path}))]}),nS=(0,x.gg)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>{if(!no.shiftTab.guard(t.originEvent))return!1;let n=(0,v.wD)(e),o=n.flatMap(t=>(0,y.cd)(e.context,t.node)?[{node:t.node,path:t.path}]:[]);return o.length===n.length&&{selectedListBlocks:o}},actions:[(e,{selectedListBlocks:t})=>t.map(e=>(0,x.OU)({type:"block.set",props:{level:Math.min(10,Math.max(1,e.node.level-1))},at:e.path}))]}),nO=(0,x.gg)({on:"insert.blocks",guard:({snapshot:e,event:t})=>{let n=(0,v.Ec)(e);if(!n)return!1;let o=t.blocks.at(0),i=t.blocks.at(1),r=(0,y.cd)(e.context,o)?o:(0,y.cd)(e.context,i)?i:void 0;if(!r)return!1;let a=n.node.level-r.level;return 0!==a&&{levelDifference:a,insertedListBlock:r}},actions:[({snapshot:e,event:t},{levelDifference:n,insertedListBlock:o})=>{let i=!0,r=!1;return[(0,x.OU)({...t,blocks:t.blocks.map(t=>(t._key===o._key&&(r=!0),i?r&&i&&(0,y.cd)(e.context,t)?{...t,level:Math.min(10,Math.max(1,t.level+n))}:(r&&(i=!1),t):t))})]}]}),nM=(0,x.gg)({on:"insert.blocks",guard:({snapshot:e,event:t})=>{let n=(0,v.Ec)(e);if(!n||(0,g.PF)(e.context,n.node))return!1;let o=t.blocks.at(0),i=t.blocks.at(1),r=(0,y.cd)(e.context,o)?o:(0,y.cd)(e.context,i)?i:void 0;return!!r&&n.node.level===r.level&&n.node.listItem!==r.listItem&&{listItem:n.node.listItem,insertedListBlock:r}},actions:[({snapshot:e,event:t},{listItem:n,insertedListBlock:o})=>{let i=!0,r=!1;return[(0,x.OU)({...t,blocks:t.blocks.map(t=>(t._key===o._key&&(r=!0),i?r&&i&&(0,y.cd)(e.context,t)?{...t,listItem:t.level===o.level?n:t.listItem}:(r&&(i=!1),t):t))})]}]}),nR=(0,x.gg)({on:"insert.block",guard:({snapshot:e,event:t})=>{if("auto"!==t.placement||t.block._type!==e.context.schema.block.name||void 0!==t.block.listItem)return!1;let n=(0,v.Ec)(e);return!!(n&&(0,g.PF)(e.context,n.node))&&{level:n.node.level,listItem:n.node.listItem}},actions:[({event:e},{level:t,listItem:n})=>[(0,x.OU)({...e,block:{...e.block,level:t,listItem:n}})]]}),nN=[{addAnnotationOnCollapsedSelection:nn}.addAnnotationOnCollapsedSelection,np.strongShortcut,np.emShortcut,np.underlineShortcut,np.c
4odeShortcut,...nh,nl,ns,ni,nr,na,nc,nd,nv,nb,nx,n_,nE,nw,nS,nO,nM,nR,nf,ny,ng,nm,nk].map(e=>({behavior:e,priority:e_})),nA=[(0,x.gg)({on:"annotation.set",guard:({snapshot:e,event:t})=>{let n=t.at[0]._key,o=t.at[2]._key,i=(0,k.I3)({...e,context:{...e.context,selection:{anchor:{path:[{_key:n}],offset:0},focus:{path:[{_key:n}],offset:0}}}});return!!i&&{blockKey:n,updatedMarkDefs:i.node.markDefs?.map(e=>e._key===o?{...e,...t.props}:e)}},actions:[(e,{blockKey:t,updatedMarkDefs:n})=>[(0,x.OU)({type:"block.set",at:[{_key:t}],props:{markDefs:n}})]]}),(0,x.gg)({on:"annotation.toggle",guard:({snapshot:e,event:t})=>(0,v.kH)(t.annotation.name)(e),actions:[({event:e})=>[(0,x.OU)({type:"annotation.remove",annotation:e.annotation})]]}),(0,x.gg)({on:"annotation.toggle",guard:({snapshot:e,event:t})=>!(0,v.kH)(t.annotation.name)(e),actions:[({event:e})=>[(0,x.OU)({type:"annotation.add",annotation:e.annotation})]]})],nI=[(0,x.gg)({on:"decorator.toggle",guard:({snapshot:e,event:t})=>(0,v.md)(t.decorator)(e),actions:[({event:e})=>[(0,x.OU)({type:"decorator.remove",decorator:e.decorator})]]}),(0,x.gg)({on:"decorator.toggle",guard:({snapshot:e,event:t})=>{let n=t.at?(0,D.iO)({context:e.context,offsets:t.at}):null;return n?!(0,v.md)(t.decorator)({...e,context:{...e.context,selection:n}}):!(0,v.md)(t.decorator)(e)},actions:[({event:e})=>[(0,x.OU)({...e,type:"decorator.add"})]]})],nT=[(0,x.gg)({on:"delete.backward",guard:({snapshot:e})=>!!e.context.selection&&{selection:e.context.selection},actions:[({event:e},{selection:t})=>[(0,x.OU)({type:"delete",direction:"backward",unit:e.unit,at:t})]]}),(0,x.gg)({on:"delete.forward",guard:({snapshot:e})=>!!e.context.selection&&{selection:e.context.selection},actions:[({event:e},{selection:t})=>[(0,x.OU)({type:"delete",direction:"forward",unit:e.unit,at:t})]]}),(0,x.gg)({on:"delete.block",actions:[({event:e})=>[(0,x.OU)({type:"delete",at:{anchor:{path:e.at,offset:0},focus:{path:e.at,offset:0}}})]]}),(0,x.gg)({on:"delete.child",guard:({snapshot:e,event:t})=>{let n=(0,k.Yz)({...e,context:{...e.context,selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:0}}}});return!!n&&((0,y.dn)(e.context,n.node)?{selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:n.node.text.length}}}:{selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:0}}})},actions:[(e,{selection:t})=>[(0,x.OU)({type:"delete",at:t})]]}),(0,x.gg)({on:"delete.text",guard:({snapshot:e,event:t})=>{let n=(0,D.iO)({context:e.context,offsets:t.at});if(!n)return!1;let o=(0,v.Vj)({...e,context:{...e.context,value:e.context.value,selection:n}});return!!o&&{selection:o}},actions:[(e,{selection:t})=>[(0,x.OU)({type:"delete",at:t})]]})],nC=[(0,x.gg)({on:"insert.blocks",guard:({event:e})=>"before"===e.placement,actions:[({event:e})=>e.blocks.map((t,n)=>(0,x.OU)({type:"insert.block",block:t,placement:0===n?"before":"after",select:e.select??"end"}))]}),(0,x.gg)({on:"insert.blocks",guard:({event:e})=>"after"===e.placement,actions:[({event:e})=>e.blocks.map(t=>(0,x.OU)({type:"insert.block",block:t,placement:"after",select:e.select??"end"}))]}),(0,x.gg)({on:"insert.blocks",guard:({snapshot:e,event:t})=>{if("auto"!==t.placement)return!1;let n=(0,k.I3)(e);return!!n&&{focusTextBlock:n}},actions:[({snapshot:e,event:t},{focusTextBlock:n})=>1===t.blocks.length?[(0,x.OU)({type:"insert.block",block:t.blocks[0],placement:"auto",select:t.select??"end"})]:(0,g.PF)(e.context,n.node)?t.blocks.map((e,n)=>(0,x.OU)({type:"insert.block",block:e,placement:0===n?"auto":"after",select:t.select??"end"})):t.blocks.flatMap((e,n)=>0===n?[(0,x.OU)({type:"split"}),(0,x.OU)({type:"select.previous block",select:"end"}),(0,x.OU)({type:"insert.block",block:e,placement:"auto",select:t.select??"end"})]:n===t.blocks.length-1?[(0,x.OU)({type:"select.next block",select:"start"}),(0,x.OU)({type:"insert.block",block:e,placement:"auto",select:t.select??"end"})]:[(0,x.OU)({type:"insert.block",block:e,placement:"after",select:t.select??"end"})])]}),(0,x.gg)({on:"insert.blocks",guard:({event:e})=>"auto"===e.placement,actions:[({event:e})=>e.blocks.map((t,n)=>(0,x.OU)({type:"insert.block",block:t,placement:0===n?"auto":"after",select:e.select??"end"}))]}),(0,x.gg)({on:"insert.break",actions:[()=>[(0,x.OU)({type:"split"})]]}),(0,x.gg)({on:"insert.soft break",actions:[()=>[(0,x.OU)({type:"insert.text",text:` 5`})]]})],nB=[(0,x.gg)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>no.break.guard(t.originEvent)&&(0,k.dI)(e)&&(0,v.fX)(e),actions:[()=>[(0,x.OU)({type:"insert.break"})]]}),(0,x.gg)({on:"keyboard.keydown",guard:({event:e})=>no.lineBreak.guard(e.originEvent),actions:[()=>[(0,x.OU)({type:"insert.soft break"})]]}),(0,x.gg)({on:"keyboard.keydown",guard:({event:e})=>no.history.undo.guard(e.originEvent),actions:[()=>[(0,x.OU)({type:"history.undo"})]]}),(0,x.gg)({on:"keyboard.keydown",guard:({event:e})=>no.history.redo.guard(e.originEvent),actions:[()=>[(0,x.OU)({type:"history.redo"})]]})],nD=[(0,x.gg)({on:"list item.add",guard:({snapshot:e})=>({selectedTextBlocks:(0,v.JK)(e)}),actions:[({event:e},{selectedTextBlocks:t})=>t.map(t=>(0,x.OU)({type:"block.set",at:t.path,props:{level:1,listItem:e.listItem}}))]}),(0,x.gg)({on:"list item.remove",guard:({snapshot:e})=>({selectedTextBlocks:(0,v.JK)(e)}),actions:[(e,{selectedTextBlocks:t})=>t.map(e=>(0,x.OU)({type:"block.unset",at:e.path,props:["level","listItem"]}))]}),(0,x.gg)({on:"list item.toggle",guard:({snapshot:e,event:t})=>(0,v.IA)(t.listItem)(e),actions:[({event:e})=>[(0,x.OU)({type:"list item.remove",listItem:e.listItem})]]}),(0,x.gg)({on:"list item.toggle",guard:({snapshot:e,event:t})=>!(0,v.IA)(t.listItem)(e),actions:[({event:e})=>[(0,x.OU)({type:"list item.add",listItem:e.listItem})]]})],nj=[(0,x.gg)({on:"move.block up",guard:({snapshot:e,event:t})=>{let n=(0,v.nt)({...e,context:{...e.context,selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:0}}}});return!!n&&{previousBlock:n}},actions:[({event:e},{previousBlock:t})=>[(0,x.OU)({type:"move.block",at:e.at,to:t.path})]]}),(0,x.gg)({on:"move.block down",guard:({snapshot:e,event:t})=>{let n=(0,v.st)({...e,context:{...e.context,selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:0}}}});return!!n&&{nextBlock:n}},actions:[({event:e},{nextBlock:t})=>[(0,x.OU)({type:"move.block",at:e.at,to:t.path})]]})],nY=[(0,x.gg)({on:"select.previous block",guard:({snapshot:e,event:t})=>{let n=(0,v.nt)(e);if(!n)return!1;let o="end"===t.select?(0,g.sQ)({context:e.context,block:n}):(0,y.qv)({context:e.context,block:n});return{selection:{anchor:o,focus:o}}},actions:[(e,{selection:t})=>[(0,x.OU)({type:"select",at:t})]]}),(0,x.gg)({on:"select.next block",guard:({snapshot:e,event:t})=>{let n=(0,v.st)(e);if(!n)return!1;let o="end"===t.select?(0,g.sQ)({context:e.context,block:n}):(0,y.qv)({context:e.context,block:n});return{selection:{anchor:o,focus:o}}},actions:[(e,{selection:t})=>[(0,x.OU)({type:"select",at:t})]]})],nU=[(0,x.gg)({on:"split",guard:({snapshot:e})=>(0,k.dI)(e)&&(0,v.fX)(e),actions:[]}),(0,x.gg)({on:"split",guard:({snapshot:e})=>(0,k.dI)(e)&&(0,v.ii)(e),actions:[]}),(0,x.gg)({on:"split",guard:({snapshot:e})=>{let t=e.context.selection;if(!t||(0,g.dI)(t))return!1;let n=(0,v.Dm)(e),o=(0,v.Zq)(e);return!!n&&!!o&&!!(!(0,y.dz)(e.context,n.node)&&(0,y.dz)(e.context,o.node))&&{selection:t}},actions:[(e,{selection:t})=>[(0,x.OU)({type:"delete",at:t})]]}),(0,x.gg)({on:"split",guard:({snapshot:e})=>{let t=e.context.selection;return!(!t||(0,g.dI)(t))&&{selection:t}},actions:[(e,{selection:t})=>[(0,x.OU)({type:"delete",at:t}),(0,x.OU)({type:"split"})]]}),(0,x.gg)({on:"split",guard:({snapshot:e})=>{let t=e.context.selection;if(!t||!(0,g.dI)(t))return!1;let n=(0,y.VG)(t),o=(0,k.I3)(e);if(!o)return!1;let i={anchor:n,focus:(0,g.sQ)({context:e.context,block:o})},r=(0,y.IX)({block:(0,j.U)({context:{...e.context,selection:i},block:o.node}),context:e.context,options:{refreshKeys:!0,validateFields:!0}});return!!r&&{newTextBlock:r,newTextBlockSelection:i}},actions:[(e,{newTextBlock:t,newTextBlockSelection:n})=>(0,g.dI)(n)?[(0,x.OU)({type:"insert.block",block:t,placement:"after",select:"start"})]:[(0,x.OU)({type:"delete",at:n}),(0,x.OU)({type:"insert.block",block:t,placement:"after",select:"start"})]]})],nL=[(0,x.gg)({on:"style.add",guard:({snapshot:e})=>({selectedTextBlocks:(0,v.JK)(e)}),actions:[({event:e},{selectedTextBlocks:t})=>t.map(t=>(0,x.OU)({type:"block.set",at:t.path,props:{style:e.style}}))]}),(0,x.gg)({on:"style.remove",guard:({snapshot:e})=>({selectedTextBlocks:(0,v.JK)(e)}),actions:[(e,{selectedTextBlocks:t})=>t.map(e=>(0,x.OU)({type:"block.unset",at:e.path,props:["style"]}))]}),(0,x.gg)({on:"style.toggle",guard:({snapshot:e,event:t})=>(0,v.S9)(t.style)(e),actions:[({event:e})=>[(0,x.OU)({type:"style.remove",style:e.style})]]}),(0,x.gg)({on:"style.toggle",guard:({snapshot:e,event:t})=>!(0,v.S9)(t.style)(e),actions:[({event:e})=>[(0,x.OU)({type:"style.add",style:e.style})]]})],nz=(0,x.gg)({on:"deserialize",guard:({snapshot:e,event:t})=>{let n;let o=[];for(let i of e.context.converters){let r=t.originEvent.originEvent.dataTransfer.getData(i.mimeType);if(!r)continue;let a=i.deserialize({snapshot:e,event:{type:"deserialize",data:r}});if("deserialization.success"===a.type){n=a;break}o.push(a)}return n||{type:"deserialization.failure",mimeType:"*/*",reason:o.map(e=>e.reason).join(", ")}},actions:[({event:e},t)=>[(0,x.OU)({...t,originEvent:e.originEvent})]]}),n$=(0,x.gg)({on:"serialize",guard:({snapshot:e,event:t})=>{if(0===e.context.converters.length)return!1;let n=e.context.converters.map(n=>
5n.serialize({snapshot:e,event:{...t,originEvent:t.originEvent.type}}));return 0!==n.length&&n},actions:[({event:e},t)=>t.map(t=>(0,x.OU)({...t,originEvent:e.originEvent}))]}),nP=[(0,x.gg)({on:"clipboard.copy",guard:({snapshot:e})=>{let t=(0,k.Cj)(e),n=(0,k.dI)(e);return t&&n},actions:[]}),(0,x.gg)({on:"clipboard.copy",actions:[({event:e})=>[(0,x.OU)({type:"serialize",originEvent:e})]]}),(0,x.gg)({on:"clipboard.cut",guard:({snapshot:e})=>{let t=(0,k.Cj)(e),n=(0,k.dI)(e);return t&&n},actions:[]}),(0,x.gg)({on:"clipboard.cut",guard:({snapshot:e})=>!!e.context.selection&&{selection:e.context.selection},actions:[({event:e},{selection:t})=>[(0,x.OU)({type:"serialize",originEvent:e}),(0,x.OU)({type:"delete",at:t})]]}),(0,x.gg)({on:"drag.dragstart",actions:[({event:e})=>[(0,x.OU)({type:"serialize",originEvent:e})]]}),(0,x.gg)({on:"serialization.success",actions:[({event:e})=>[{type:"effect",effect:()=>{e.originEvent.originEvent.dataTransfer.setData(e.mimeType,e.data)}}]]}),(0,x.gg)({on:"serialization.failure",actions:[({event:e})=>[{type:"effect",effect:()=>{console.warn(`Serialization of ${e.mimeType} failed with reason "${e.reason}"`)}}]]}),(0,x.gg)({on:"deserialization.success",guard:({snapshot:e,event:t})=>{if((0,k.I3)(e)&&"text/plain"===t.mimeType&&"clipboard.paste"===t.originEvent.type){let n=(0,v.WH)(e);return{activeAnnotations:(0,v.$s)(e),activeDecorators:n,textRuns:t.data.flatMap(t=>(0,y.dz)(e.context,t)?[(0,y.NL)(t)]:[])}}return!1},actions:[(e,{activeAnnotations:t,activeDecorators:n,textRuns:o})=>o.flatMap((e,i)=>i!==o.length-1?[(0,x.OU)({type:"insert.span",text:e,decorators:n,annotations:t.map(({_key:e,_type:t,...n})=>({name:t,value:n}))}),(0,x.OU)({type:"insert.break"})]:[(0,x.OU)({type:"insert.span",text:e,decorators:n,annotations:t.map(({_key:e,_type:t,...n})=>({name:t,value:n}))})])]}),(0,x.gg)({on:"deserialization.success",actions:[({event:e})=>[(0,x.OU)({type:"insert.blocks",blocks:e.data,placement:"auto"})]]}),(0,x.gg)({on:"deserialization.failure",actions:[({event:e})=>[{type:"effect",effect:()=>{console.warn(`Deserialization of ${e.mimeType} failed with reason "${e.reason}"`)}}]]}),(0,x.gg)({on:"clipboard.paste",guard:({snapshot:e})=>!!(e.context.selection&&(0,k.sC)(e))&&{selection:e.context.selection},actions:[({event:e},{selection:t})=>[(0,x.OU)({type:"delete",at:t}),(0,x.OU)({type:"deserialize",originEvent:e})]]}),(0,x.gg)({on:"clipboard.paste",actions:[({event:e})=>[(0,x.OU)({type:"deserialize",originEvent:e})]]}),(0,x.gg)({on:"input.*",actions:[({event:e})=>[(0,x.OU)({type:"deserialize",originEvent:e})]]}),...nA,...nI,...nT,...nC,...nB,...nD,...nj,...nL,...nY,...nU,nz,n$];function nG(e){return!nJ(e)&&!nW(e)&&!nK(e)}let nF=["annotation.set","annotation.toggle","decorator.toggle","delete.backward","delete.block","delete.child","delete.forward","delete.text","deserialize","deserialization.success","deserialization.failure","insert.blocks","insert.break","insert.soft break","list item.add","list item.remove","list item.toggle","move.block down","move.block up","select.previous block","select.next block","serialize","serialization.success","serialization.failure","split","style.add","style.remove","style.toggle"];function nK(e){return nF.includes(e.type)}let nV=["clipboard.copy","clipboard.cut","clipboard.paste","drag.dragstart","drag.drag","drag.dragend","drag.dragenter","drag.dragover","drag.dragleave","drag.drop","input.*","keyboard.keydown","keyboard.keyup","mouse.click"];function nW(e){return nV.includes(e.type)}function nJ(e){return e.type.startsWith("custom.")}let nq=V("behaviors:event");function nH(e){return nW(e)?"native":nK(e)?"synthetic":nJ(e)?"custom":"synthetic"}let nX=V("editor machine"),nZ=(0,w.cY)({types:{context:{},events:{},emitted:{},input:{},tags:{}},actions:{"add behavior to context":(0,S.a)({behaviors:({context:e,event:t})=>((0,w.ZD)(t,"add behavior"),new Set([...e.behaviors,t.behaviorConfig])),behaviorsSorted:!1}),"remove behavior from context":(0,S.a)({behaviors:({context:e,event:t})=>((0,w.ZD)(t,"remove behavior"),e.behaviors.delete(t.behaviorConfig),new Set([...e.behaviors]))}),"emit patch event":(0,O.a)(({event:e})=>((0,w.ZD)(e,"internal.patch"),e)),"emit mutation event":(0,O.a)(({event:e})=>((0,w.ZD)(e,"mutation"),e)),"emit read only":(0,O.a)({type:"read only"}),"emit editable":(0,O.a)({type:"editable"}),"defer event":(0,S.a)({pendingEvents:({context:e,event:t})=>((0,w.ZD)(t,["internal.patch","mutation"]),[...e.pendingEvents,t])}),"emit pending events":(0,O.e)(({context:e,enqueue:t})=>{for(let n of e.pendingEvents)t.emit(n)}),"emit ready":(0,O.a)({type:"ready"}),"clear pending events":(0,S.a)({pendingEvents:[]}),"defer incoming patches":(0,S.a)({pendingIncomingPatchesEvents:({context:e,event:t})=>"patches"===t.type?[...e.pendingIncomingPatchesEvents,t]:e.pendingIncomingPatchesEvents}),"emit pending incoming patches":(0,O.e)(({context:e,enqueue:t})=>{for(let n of e.pendingIncomingPatchesEvents)t.emit(n)}),"clear pending incoming patches":(0,S.a)({pendingIncomingPatchesEvents:[]}),"handle blur":({event:e})=>{(0,w.ZD)(e,"blur");try{u.F3.blur(e.editor)}catch(e){console.error(Error(`Failed to blur editor: ${e.message}`))}},"handle focus":({context:e})=>
5{if(!e.slateEditor){console.error("No Slate editor found to focus");return}try{let t=e.slateEditor.selection;u.F3.focus(e.slateEditor),t&&p.YR.select(e.slateEditor,t)}catch(e){console.error(Error(`Failed to focus editor: ${e.message}`))}},"handle behavior event":({context:e,event:t,self:n})=>{(0,w.ZD)(t,["behavior event"]);try{let o=[...e.behaviors.values()].map(e=>e.behavior);!function e({mode:t,behaviors:n,remainingEventBehaviors:o,event:i,editor:r,keyGenerator:a,schema:l,getSnapshot:s,nativeEvent:c,sendBack:d}){nq(`(${t}:${nH(i)})`,JSON.stringify(i,null,2));let p=[...o,...nP].filter(e=>{if("*"===e.on)return!0;let[t]=e.on.includes("*")&&e.on.includes(".")?e.on.split("."):[void 0],[n]=i.type.includes(".")?i.type.split("."):[void 0];return void 0!==t&&void 0!==n&&t===n||void 0!==t&&void 0===n&&t===i.type||e.on===i.type});if(0===p.length&&nG(i)){c?.preventDefault(),tV(r,()=>{nq(`(execute:${nH(i)})`,JSON.stringify(i,null,2)),tF({context:{keyGenerator:a,schema:l},operation:{...i,editor:r}})}),r.onChange();return}let u=s(),h=!1,f=!1,y=-1;for(let t of p){y++;let o=!1;try{o=void 0===t.guard||t.guard({snapshot:u,event:i,dom:nt(d,r)})}catch(e){console.error(Error(`Evaluating guard for "${i.type}" failed due to: ${e.message}`))}if(o){for(let u of(f=!0,t.actions)){let t=s(),f=[];try{f=u({snapshot:t,event:i,dom:nt(d,r)},o)}catch(e){console.error(Error(`Evaluating actions for "${i.type}" failed due to: ${e.message}`))}if(0!==f.length){if(h=f.some(e=>"raise"===e.type||"execute"===e.type)||!f.some(e=>"forward"===e.type),f.some(e=>"execute"===e.type)){!function(e,t){let n=tN.get(e);if(n){t();return}tN.set(e,n??{undoStepId:ev()}),t(),tN.set(e,void 0)}(r,()=>{for(let t of f){if("effect"===t.type){try{t.effect()}catch(e){console.error(Error(`Executing effect as a result of "${i.type}" failed due to: ${e.message}`))}continue}if("forward"===t.type){e({mode:"forward",behaviors:n,remainingEventBehaviors:p.slice(y+1),event:t.event,editor:r,keyGenerator:a,schema:l,getSnapshot:s,nativeEvent:c,sendBack:d});continue}if("raise"===t.type){e({mode:"raise",behaviors:n,remainingEventBehaviors:n,event:t.event,editor:r,keyGenerator:a,schema:l,getSnapshot:s,nativeEvent:c,sendBack:d});continue}e({mode:"execute",behaviors:n,remainingEventBehaviors:[],event:t.event,editor:r,keyGenerator:a,schema:l,getSnapshot:s,nativeEvent:void 0,sendBack:d})}});continue}for(let t of f){if("effect"===t.type){try{t.effect()}catch(e){console.error(Error(`Executing effect as a result of "${i.type}" failed due to: ${e.message}`))}continue}if("forward"===t.type){e({mode:"forward",behaviors:n,remainingEventBehaviors:p.slice(y+1),event:t.event,editor:r,keyGenerator:a,schema:l,getSnapshot:s,nativeEvent:c,sendBack:d});continue}if("raise"===t.type){e({mode:"raise",behaviors:n,remainingEventBehaviors:n,event:t.event,editor:r,keyGenerator:a,schema:l,getSnapshot:s,nativeEvent:c,sendBack:d});continue}"execute"===t.type&&console.error("Unexpected action type: `execute`")}}}break}}!f&&nG(i)?(c?.preventDefault(),tV(r,()=>{nq(`(execute:${nH(i)})`,JSON.stringify(i,null,2)),tF({context:{keyGenerator:a,schema:l},operation:{...i,editor:r}})}),r.onChange()):h&&c?.preventDefault()}({mode:"raise",behaviors:o,remainingEventBehaviors:o,event:t.behaviorEvent,editor:t.editor,keyGenerator:e.keyGenerator,schema:e.schema,getSnapshot:()=>(function({converters:e,editor:t,keyGenerator:n,readOnly:o,schema:i}){let r=t.selection?er({schema:i,editor:t,range:t.selection}):null,a={converters:e,keyGenerator:n,readOnly:o,schema:i,selection:r,value:t.value};return{blockIndexMap:t.blockIndexMap,context:a,decoratorState:t.decoratorState}})({converters:[...e.converters],editor:t.editor,keyGenerator:e.keyGenerator,readOnly:n.getSnapshot().matches({"edit mode":"read only"}),schema:e.schema}),nativeEvent:t.nativeEvent,sendBack:e=>n.send(e)})}catch(e){console.error(Error(`Raising "${t.behaviorEvent.type}" failed due to: ${e.message}`))}},"sort behaviors":(0,S.a)({behaviors:({context:e})=>e.behaviorsSorted?e.behaviors:new Set(function(e){if(0===e.length)return[];let t=e.filter(e=>void 0!==e.priority),n=e.filter(e=>void 0===e.priority);if(0===t.length)return e;let o=new Map(t.map(e=>[e.priority.id,e])),i=new Map,r=new Map;function a(e){i.has(e)||(i.set(e,new Set),r.set(e,0))}for(let e of t)a(e.priority.id);function l(e,t){i.has(e)&&i.has(t)&&(i.get(e)?.add(t),r.set(t,(r.get(t)??0)+1))}for(let e of t){let t=e.priority.id,n=new Set,o=e.priority.reference;for(;o;){let e=o.priority.id;if(a(e),n.has(e))throw Error("Circular dependency detected in priorities");n.add(e),"higher"===o.importance?l(t,e):l(e,t),o=o.priority.reference}}let s=[];for(let[e,t]of r)0===t&&s.push(e);let c=[];for(;s.length>0;){let e=s.shift(),t=o.get(e);
5for(let n of(t&&c.push(t),i.get(e)??[])){let e=(r.get(n)??0)-1;r.set(n,e),0===e&&s.push(n)}}for(let e of t)c.includes(e)||c.push(e);return[...c,...n]}([...e.behaviors.values()])),behaviorsSorted:!0})},guards:{"slate is busy":({context:e})=>!!e.slateEditor&&e.slateEditor.operations.length>0}}).createMachine({id:"editor",context:({input:e})=>({behaviors:new Set(nN),behaviorsSorted:!1,converters:new Set(e.converters??[]),getLegacySchema:e.getLegacySchema,keyGenerator:e.keyGenerator,pendingEvents:[],pendingIncomingPatchesEvents:[],schema:e.schema,selection:null,initialReadOnly:e.readOnly??!1,maxBlocks:e.maxBlocks,initialValue:e.initialValue}),on:{"add behavior":{actions:"add behavior to context"},"remove behavior":{actions:"remove behavior from context"},"update maxBlocks":{actions:(0,S.a)({maxBlocks:({event:e})=>e.maxBlocks})},"update selection":{actions:[(0,S.a)({selection:({event:e})=>e.selection}),(0,O.a)(({event:e})=>({...e,type:"selection"}))]},"set drag ghost":{actions:(0,S.a)({dragGhost:({event:e})=>e.ghost})}},type:"parallel",states:{"edit mode":{initial:"read only",states:{"read only":{initial:"determine initial edit mode",on:{"behavior event":{actions:["sort behaviors","handle behavior event"],guard:({event:e})=>"clipboard.copy"===e.behaviorEvent.type||"mouse.click"===e.behaviorEvent.type||"serialize"===e.behaviorEvent.type||"serialization.failure"===e.behaviorEvent.type||"serialization.success"===e.behaviorEvent.type||"select"===e.behaviorEvent.type}},states:{"determine initial edit mode":{entry:[()=>{nX("entry: edit mode->read only->determine initial edit mode")}],exit:[()=>{nX("exit: edit mode->read only->determine initial edit mode")}],on:{"done syncing value":[{target:"#editor.edit mode.read only.read only",guard:({context:e})=>e.initialReadOnly},{target:"#editor.edit mode.editable"}]}},"read only":{entry:[()=>{nX("entry: edit mode->read only->read only")}],exit:[()=>{nX("exit: edit mode->read only->read only")}],on:{"update readOnly":{guard:({event:e})=>!e.readOnly,target:"#editor.edit mode.editable",actions:["emit editable"]}}}}},editable:{on:{"update readOnly":{guard:({event:e})=>e.readOnly,target:"#editor.edit mode.read only.read only",actions:["emit read only"]},"behavior event":{actions:["sort behaviors","handle behavior event"]},blur:{actions:"handle blur"},focus:{target:".focusing",actions:[(0,S.a)({slateEditor:({event:e})=>e.editor})]}},initial:"idle",states:{idle:{entry:[()=>{nX("entry: edit mode->editable->idle")}],exit:[()=>{nX("exit: edit mode->editable-idle")}],on:{dragstart:{actions:[(0,S.a)({internalDrag:({event:e})=>({origin:e.origin})})],target:"dragging internally"}}},focusing:{initial:"checking if busy",states:{"checking if busy":{entry:[()=>{nX("entry: edit mode->editable->focusing->checking if busy")}],exit:[()=>{nX("exit: edit mode->editable->focusing->checking if busy")}],always:[{guard:"slate is busy",target:"busy"},{target:"#editor.edit mode.editable.idle",actions:["handle focus"]}]},busy:{entry:[()=>{nX("entry: edit mode->editable->focusing-busy")}],exit:[()=>{nX("exit: edit mode->editable->focusing->busy")}],after:{10:{target:"checking if busy"}}}}},"dragging internally":{entry:[()=>{nX("entry: edit mode->editable->dragging internally")}],exit:[()=>{nX("exit: edit mode->editable->dragging internally")},({context:e})=>{if(e.dragGhost)try{e.dragGhost.parentNode?.removeChild(e.dragGhost)}catch(e){console.error(Error(`Removing the drag ghost failed due to: ${e.message}`))}},(0,S.a)({dragGhost:void 0}),(0,S.a)({internalDrag:void 0})],tags:["dragging internally"],on:{dragend:{target:"idle"},drop:{target:"idle"}}}}}}},setup:{initial:"setting up",states:{"setting up":{entry:[()=>{nX("entry: setup->setting up")}],exit:[()=>{nX("exit: setup->setting up")},"emit ready","emit pending incoming patches","clear pending incoming patches"],on:{"internal.patch":{actions:"defer event"},mutation:{actions:"defer event"},"done syncing value":{target:"set up"},patches:{actions:["defer incoming patches"]}}},"set up":{type:"parallel",states:{"value sync":{initial:"idle",states:{idle:{entry:[()=>{nX("entry: setup->set up->value sync->idle")}],exit:[()=>{nX("exit: setup->set up->value sync->idle")}],on:{patches:{actions:[(0,O.a)(({event:e})=>e)]},"syncing value":{target:"syncing value"}}},"syncing value":{entry:[()=>{nX("entry: setup->set up->value sync->syncing value")}],exit:[()=>{nX("exit: setup->set up->value sync->syncing value")},"emit pending incoming patches","clear pending incoming patches"],on:{patches:{actions:["defer incoming patches"]},"done syncing value":{target:"idle"}}}}},writing:{initial:"pristine",states:{pristine:{initial:"idle",states:{idle:{entry:[()=>{nX("entry: setup->set up->writing->pristine->idle")}],exit:[()=>{nX("exit: setup->set up->writing->pristine->idle")}],on:{normalizing:{target:"normalizing"},"internal.patch":{actions:"defer event",target:"#editor.setup.set up.writing.dirty"},mutation:{actions:"defer event",target:"#editor.setup.set up.writing.dirty"}}},normalizing:{entry:[()=>{nX("entry: setup->set up->writing->pristine->normalizing")}],exit:[()=>{nX("exit: setup->set up->writing->pristine->normalizing")}],on:{"done normalizing":{target:"idle"},"internal.patch":{actions:"defer event"},mutation:{actions:"defer event"}}}}},dirty:{entry:[()=>{nX("entry: setup->set up->writing->dirty")},"emit pending events","clear pending events"],exit:[()=>{nX("exit: setup->set up->writing->dirty")}],on:{"internal.patch":{actions:"emit patch event"},mutation:{actions:"emit mutation event"}}}}}}}}}}});function nQ(e){if(!e)throw Error("Parameter 'portabletextType' missing (required)");let t=e.of?.find(function e(t){return t.type?e(t.type):"block"===t.name?t:null});if(!t)throw Error("Block type is not defined in this schema (required)");let n=t.fields?.find(e=>"children"===e.name);if(!n)throw Error("Children field for block type found in schema (required)");let o=n.type.of;if(!o)throw Error("Valid types for block children not found in schema (required)");let i=o.find(e=>"span"===e.name);if(!i)throw Error("Span type not found in schema (required)");let r=o.filter(e=>"span"!==e.name)||[],a=e.of?.filter(e=>e.name!==t.name)||[];return{styles:function(e){let t=e.fields?.find(e=>"style"===e.name);if(!t)throw Error("A field with name 'style' is not defined in the block type (required).");let n=t.type.options?.list&&t.type.options.list?.filter(e=>e.value);
5if(!n||0===n.length)throw Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");return n}(t),decorators:i.decorators,lists:function(e){let t=e.fields?.find(e=>"listItem"===e.name);if(!t)throw Error("A field with name 'listItem' is not defined in the block type (required).");let n=t.type.options?.list&&t.type.options.list.filter(e=>e.value);if(!n)throw Error("The list field need at least to be an empty array");return n}(t),block:t,span:i,portableText:e,inlineObjects:r,blockObjects:a,annotations:i.annotations}}let n0=`tmp-${ev()}-image`,n1=`tmp-${ev()}-url`,n2={image:n0,url:n1},n3={[n0]:"image",[n1]:"url"},n8={image:"Image",url:"URL"},n6=V("mutation-machine"),n9=(0,w.cY)({types:{context:{},events:{},input:{},emitted:{}},actions:{"assign readOnly":(0,S.a)({readOnly:({context:e,event:t})=>"update readOnly"===t.type?t.readOnly:e.readOnly}),"emit patch":(0,O.a)(({event:e})=>((0,w.ZD)(e,"patch"),{type:"patch",patch:e.patch})),"emit has pending mutations":(0,O.a)({type:"has pending mutations"}),"emit mutations":(0,O.e)(({context:e,enqueue:t})=>{for(let n of e.pendingMutations)t.emit({type:"mutation",patches:n.patches,snapshot:n.value})}),"clear pending mutations":(0,S.a)({pendingMutations:[]}),"defer mutation":(0,S.a)({pendingMutations:({context:e,event:t})=>{if((0,w.ZD)(t,"patch"),0===e.pendingMutations.length)return[{operationId:t.operationId,value:t.value,patches:[t.patch]}];let n=e.pendingMutations.at(-1);return n&&n.operationId===t.operationId?e.pendingMutations.slice(0,-1).concat({value:t.value,operationId:n.operationId,patches:[...n.patches,t.patch]}):e.pendingMutations.concat({value:t.value,operationId:t.operationId,patches:[t.patch]})}}),"clear pending patch events":(0,S.a)({pendingPatchEvents:[]}),"defer patch":(0,S.a)({pendingPatchEvents:({context:e,event:t})=>"patch"===t.type?[...e.pendingPatchEvents,t]:e.pendingPatchEvents}),"emit pending patch events":(0,O.e)(({context:e,enqueue:t})=>{for(let n of e.pendingPatchEvents)t.emit(n)})},actors:{"type listener":(0,M.E9)(({input:e,sendBack:t})=>{let n=e.slateEditor.apply;return e.slateEditor.apply=e=>{"insert_text"===e.type||"remove_text"===e.type?t({type:"typing"}):t({type:"not typing"}),n(e)},()=>{e.slateEditor.apply=n}}),"mutation debouncer":(0,M.E9)(({sendBack:e})=>{let t=setInterval(()=>{e({type:"mutation delay passed"})},0);return()=>{clearInterval(t)}})},guards:{"is read-only":({context:e})=>e.readOnly,"is typing":(0,R.f)({typing:"typing"}),"slate is normalizing":({context:e})=>p.ML.isNormalizing(e.slateEditor)},delays:{"type debounce":250}}).createMachine({id:"mutation",context:({input:e})=>({pendingMutations:[],pendingPatchEvents:[],readOnly:e.readOnly,schema:e.schema,slateEditor:e.slateEditor}),on:{"update readOnly":{actions:["assign readOnly"]}},type:"parallel",states:{typing:{initial:"idle",invoke:{src:"type listener",input:({context:e})=>({slateEditor:e.slateEditor})},states:{idle:{entry:[()=>{n6("entry: typing->idle")}],exit:[()=>{n6("exit: typing->idle"),n6("entry: typing->typing")}],on:{typing:{target:"typing"}}},typing:{after:{"type debounce":{target:"idle",actions:[()=>{n6("exit: typing->typing")}]}},on:{"not typing":{target:"idle"},typing:{target:"typing",reenter:!0}}}}},mutations:{initial:"idle",states:{idle:{entry:[()=>{n6("entry: mutations->idle")}],exit:[()=>{n6("exit: mutations->idle")}],on:{patch:[{guard:"is read-only",actions:["defer patch","defer mutation"],target:"has pending mutations"},{actions:["emit patch","defer mutation"],target:"has pending mutations"}]}},"has pending mutations":{entry:[()=>{n6("entry: mutations->has pending mutations")},"emit has pending mutations"],exit:[()=>{n6("exit: mutations->has pending mutations")}],invoke:{src:"mutation debouncer"},on:{"mutation delay passed":{guard:(0,R.e)([(0,R.n)("is read-only"),(0,R.n)("is typing"),"slate is normalizing"]),target:"idle",actions:["emit pending patch events","clear pending patch events","emit mutations","clear pending mutations"]},patch:[{guard:"is read-only",actions:["defer patch","defer mutation"]},{actions:["emit patch","defer mutation"]}]}}}}}}),n4=V("API:editable"),n5=(0,w.cY)({types:{context:{},events:{},emitted:{}}}).createMachine({id:"relay",context:{prevSelection:null,lastEventWasFocused:!1},on:{focused:{actions:[(0,S.a)({lastEventWasFocused:!0}),(0,O.a)(({event:e})=>e)]},selection:[{guard:({context:e})=>e.lastEventWasFocused,actions:[(0,S.a)({prevSelection:({event:e})=>e.selection}),(0,O.a)(({event:e})=>e),(0,S.a)({lastEventWasFocused:!1})]},{guard:({context:e,event:t})=>e.prevSelection!==t.selection,actions:[(0,S.a)({prevSelection:({event:e})=>e.selection}),(0,O.a)(({event:e})=>e),(0,S.a)({lastEventWasFocused:!1})]}],"*":{actions:[(0,O.a)(({event:e})=>e),(0,S.a)({lastEventWasFocused:!1})]}}});
5function n7(e,t,n){let o=null,i=!0,r=[t.span.name,...t.inlineObjects.map(e=>e.name)],a=[t.block.name,...t.blockObjects.map(e=>e.name)];return void 0===e?{valid:!0,resolution:null,value:e}:Array.isArray(e)&&0!==e.length?(e.some((e,l)=>{if(!F(e))return o={patches:[(0,B.zN)([l])],description:`Block must be an object, got ${String(e)}`,action:"Unset invalid item",item:e,i18n:{description:"inputs.portable-text.invalid-value.not-an-object.description",action:"inputs.portable-text.invalid-value.not-an-object.action",values:{index:l}}},!0;if(!e._key||"string"!=typeof e._key)return o={patches:[(0,B.t8)({...e,_key:n()},[l])],description:`Block at index ${l} is missing required _key.`,action:"Set the block with a random _key value",item:e,i18n:{description:"inputs.portable-text.invalid-value.missing-key.description",action:"inputs.portable-text.invalid-value.missing-key.action",values:{index:l}}},!0;if(!e._type||!a.includes(e._type)){if("block"===e._type){let n=t.block.name;return o={patches:[(0,B.t8)({...e,_type:n},[{_key:e._key}])],description:`Block with _key '${e._key}' has invalid type name '${e._type}'. According to the schema, the block type name is '${n}'`,action:`Use type '${n}'`,item:e,i18n:{description:"inputs.portable-text.invalid-value.incorrect-block-type.description",action:"inputs.portable-text.invalid-value.incorrect-block-type.action",values:{key:e._key,expectedTypeName:n}}},!0}return o=!e._type&&(0,y.dz)({schema:t},{...e,_type:t.block.name})?{patches:[(0,B.t8)({...e,_type:t.block.name},[{_key:e._key}])],description:`Block with _key '${e._key}' is missing a type name. According to the schema, the block type name is '${t.block.name}'`,action:`Use type '${t.block.name}'`,item:e,i18n:{description:"inputs.portable-text.invalid-value.missing-block-type.description",action:"inputs.portable-text.invalid-value.missing-block-type.action",values:{key:e._key,expectedTypeName:t.block.name}}}:e._type?{patches:[(0,B.zN)([{_key:e._key}])],description:`Block with _key '${e._key}' has invalid _type '${e._type}'`,action:"Remove the block",item:e,i18n:{description:"inputs.portable-text.invalid-value.disallowed-type.description",action:"inputs.portable-text.invalid-value.disallowed-type.action",values:{key:e._key,typeName:e._type}}}:{patches:[(0,B.zN)([{_key:e._key}])],description:`Block with _key '${e._key}' is missing an _type property`,action:"Remove the block",item:e,i18n:{description:"inputs.portable-text.invalid-value.missing-type.description",action:"inputs.portable-text.invalid-value.missing-type.action",values:{key:e._key}}},!0}if(e._type===t.block.name){if(e.children&&!Array.isArray(e.children))return o={patches:[(0,B.t8)({children:[]},[{_key:e._key}])],description:`Text block with _key '${e._key}' has a invalid required property 'children'.`,action:"Reset the children property",item:e,i18n:{description:"inputs.portable-text.invalid-value.missing-or-invalid-children.description",action:"inputs.portable-text.invalid-value.missing-or-invalid-children.action",values:{key:e._key}}},!0;if(void 0===e.children||Array.isArray(e.children)&&0===e.children.length){let i={_type:t.span.name,_key:n(),text:"",marks:[]};return o={autoResolve:!0,patches:[(0,B.Cb)([],[{_key:e._key},"children"]),(0,B.$T)([i],"after",[{_key:e._key},"children",0])],description:`Children for text block with _key '${e._key}' is empty.`,action:"Insert an empty text",item:e,i18n:{description:"inputs.portable-text.invalid-value.empty-children.description",action:"inputs.portable-text.invalid-value.empty-children.action",values:{key:e._key}}},!0}let a=_(T(e.children.filter(e=>e._type===t.span.name).map(e=>e.marks||[])));if(Array.isArray(e.markDefs)&&e.markDefs.length>0){let t=_(e.markDefs.map(e=>e._key).filter(e=>!a.includes(e)));if(t.length>0)return o={autoResolve:!0,patches:t.map(t=>(0,B.zN)([{_key:e._key},"markDefs",{_key:t}])),description:`Block contains orphaned data (unused mark definitions): ${t.join(", ")}.`,action:"Remove unused mark definition item",item:e,i18n:{description:"inputs.portable-text.invalid-value.orphaned-mark-defs.description",action:"inputs.portable-text.invali
5d-value.orphaned-mark-defs.action",values:{key:e._key,unusedMarkDefs:t.map(e=>e.toString())}}},!0}let l=a.filter(e=>!t.decorators.map(e=>e.name).includes(e)).filter(t=>void 0===e.markDefs||!e.markDefs.find(e=>e._key===t));if(l.length>0){let n=e.children.filter(e=>e._type===t.span.name&&Array.isArray(e.marks)&&e.marks.some(e=>l.includes(e)));if(n){let t=l.join(", ");return o={autoResolve:!0,patches:n.map(t=>(0,B.t8)((t.marks||[]).filter(e=>!l.includes(e)),[{_key:e._key},"children",{_key:t._key},"marks"])),description:`Block with _key '${e._key}' contains marks (${t}) not supported by the current content model.`,action:"Remove invalid marks",item:e,i18n:{description:"inputs.portable-text.invalid-value.orphaned-marks.description",action:"inputs.portable-text.invalid-value.orphaned-marks.action",values:{key:e._key,orphanedMarks:l.map(e=>e.toString())}}},!0}}e.children.some((i,a)=>{if(!F(i))return o={patches:[(0,B.zN)([{_key:e._key},"children",a])],description:`Child at index '${a}' in block with key '${e._key}' is not an object.`,action:"Remove the item",item:e,i18n:{description:"inputs.portable-text.invalid-value.non-object-child.description",action:"inputs.portable-text.invalid-value.non-object-child.action",values:{key:e._key,index:a}}},!0;if(!i._key||"string"!=typeof i._key){let t={...i,_key:n()};return o={autoResolve:!0,patches:[(0,B.t8)(t,[{_key:e._key},"children",a])],description:`Child at index ${a} is missing required _key in block with _key ${e._key}.`,action:"Set a new random _key on the object",item:e,i18n:{description:"inputs.portable-text.invalid-value.missing-child-key.description",action:"inputs.portable-text.invalid-value.missing-child-key.action",values:{key:e._key,index:a}}},!0}return i._type?r.includes(i._type)?i._type===t.span.name&&"string"!=typeof i.text&&(o={patches:[(0,B.t8)({...i,text:""},[{_key:e._key},"children",{_key:i._key}])],description:`Child with _key '${i._key}' in block with key '${e._key}' has missing or invalid text property!`,action:"Write an empty text property to the object",item:e,i18n:{description:"inputs.portable-text.invalid-value.invali
5d-span-text.description",action:"inputs.portable-text.invalid-value.invalid-span-text.action",values:{key:e._key,childKey:i._key}}},!0):(o={patches:[(0,B.zN)([{_key:e._key},"children",{_key:i._key}])],description:`Child with _key '${i._key}' in block with key '${e._key}' has invalid '_type' property (${i._type}).`,action:"Remove the object",item:e,i18n:{description:"inputs.portable-text.invalid-value.disallowed-child-type.description",action:"inputs.portable-text.invalid-value.disallowed-child-type.action",values:{key:e._key,childKey:i._key,childType:i._type}}},!0):(o={patches:[(0,B.zN)([{_key:e._key},"children",{_key:i._key}])],description:`Child with _key '${i._key}' in block with key '${e._key}' is missing '_type' property.`,action:"Remove the object",item:e,i18n:{description:"inputs.portable-text.invalid-value.missing-child-type.description",action:"inputs.portable-text.invalid-value.missing-child-type.action",values:{key:e._key,childKey:i._key}}},!0)})&&(i=!1)}return!1})&&(i=!1),{valid:i,resolution:o,value:e}):{valid:!1,resolution:{patches:[(0,B.zN)([])],description:"Editor value must be an array of Portable Text blocks, or undefined.",action:"Unset the value",item:e,i18n:{description:"inputs.portable-text.invalid-value.not-an-array.description",action:"inputs.portable-text.invalid-value.not-an-array.action"}},value:e}}let oe=V("sync machine"),ot=(0,M.E9)(({sendBack:e,input:t})=>{oo({context:t.context,sendBack:e,slateEditor:t.slateEditor,value:t.value,streamBlocks:t.streamBlocks})}),on=(0,w.cY)({types:{context:{},input:{},events:{},emitted:{}},actions:{"assign initial value synced":(0,S.a)({initialValueSynced:!0}),"assign readOnly":(0,S.a)({readOnly:({event:e})=>((0,w.ZD)(e,"update readOnly"),e.readOnly)}),"assign pending value":(0,S.a)({pendingValue:({event:e})=>((0,w.ZD)(e,"update value"),e.value)}),"clear pending value":(0,S.a)({pendingValue:void 0}),"assign previous value":(0,S.a)({previousValue:({event:e})=>((0,w.ZD)(e,"done syncing"),e.value)}),"emit done syncing value":(0,O.a)({type:"done syncing value"}),"emit syncing value":(0,O.a)({type:"syncing value"})},guards:{"initial value synced":({context:e})=>e.initialValueSynced,"is busy":({context:e})=>{let t=!e.readOnly,n=e.isProcessingLocalChanges,o=eK(e.slateEditor)??!1,i=t&&(n||o);return oe("isBusy",{isBusy:i,editable:t,isProcessingLocalChanges:n,isChanging:o}),i},"is empty value":({event:e})=>"update value"===e.type&&void 0===e.value,"is empty array":({event:e})=>"update value"===e.type&&Array.isArray(e.value)&&0===e.value.length,"is new value":({context:e,event:t})=>"update value"===t.type&&e.previousValue!==t.value,"value changed while syncing":({context:e,event:t})=>((0,w.ZD)(t,"done syncing"),e.pendingValue!==t.value),"pending value equals previous value":({context:e})=>m(e.pendingValue,e.previousValue)},actors:{"sync value":ot}}).createMachine({id:"sync",context:({input:e})=>({initialValue:e.initialValue,initialValueSynced:!1,isProcessingLocalChanges:!1,keyGenerator:e.keyGenerator,schema:e.schema,readOnly:e.readOnly,slateEditor:e.slateEditor,pendingValue:void 0,previousValue:void 0}),entry:[(0,R.r)(({context:e})=>({type:"update value",value:e.initialValue}))],on:{"has pending mutations":{actions:(0,S.a)({isProcessingLocalChanges:!0})},mutation:{actions:(0,S.a)({isProcessingLocalChanges:!1})},"update readOnly":{actions:["assign readOnly"]}},initial:"idle",states:{idle:{entry:[()=>{oe("entry: syncing->idle")}],exit:[()=>{oe("exit: syncing->idle")}],on:{"update value":[{guard:(0,R.e)(["is empty value",(0,R.n)("initial value synced")]),actions:["assign initial value synced","emit done syncing value"]},{guard:(0,R.e)(["is empty array",(0,R.n)("initial value synced")]),actions:["assign initial value synced",(0,O.a)({type:"value changed",value:[]}),"emit done syncing value"]},{guard:(0,R.e)(["is busy","is new value"]),target:"busy",actions:["assign pending value"]},{guard:"is new value",target:"syncing",actions:["assign pending value"]},{guard:(0,R.n)("initial value synced"),actions:[()=>{oe("no new value â setting initial value as synced")},"assign initial value synced","emit done syncing value"]},{actions:[()=>{oe("no new value and initial value already synced")}]}]}},busy:{entry:[()=>{oe("entry: syncing->busy")}],exit:[()=>{oe("exit: syncing->busy")}
5],after:{1e3:[{guard:"is busy",target:".",reenter:!0,actions:[()=>{oe("reenter: syncing->busy")}]},{target:"syncing"}]},on:{"update value":[{guard:"is new value",actions:["assign pending value"]}]}},syncing:{entry:[()=>{oe("entry: syncing->syncing")},"emit syncing value"],exit:[()=>{oe("exit: syncing->syncing")},"emit done syncing value"],invoke:{src:"sync value",id:"sync value",input:({context:e})=>({context:{keyGenerator:e.keyGenerator,previousValue:e.previousValue,readOnly:e.readOnly,schema:e.schema},slateEditor:e.slateEditor,streamBlocks:!e.initialValueSynced,value:e.pendingValue})},on:{"update value":{guard:"is new value",actions:["assign pending value"]},patch:{actions:[(0,O.a)(({event:e})=>e)]},"invalid value":{actions:[(0,O.a)(({event:e})=>e)]},"value changed":{actions:[(0,O.a)(({event:e})=>e)]},"done syncing":[{guard:"value changed while syncing",actions:["assign previous value","assign initial value synced"],target:"syncing",reenter:!0},{target:"idle",actions:["clear pending value","assign previous value","assign initial value synced"]}]}}}});async function oo({context:e,sendBack:t,slateEditor:n,streamBlocks:o,value:i}){let r=!1,a=!1,l=!0,s=!!n.selection;if(i&&0!==i.length||(oe("Value is empty"),p.ML.withoutNormalizing(n,()=>{t$(n,()=>{eF(n,()=>{tX(n,()=>{if(r)return;s&&p.YR.deselect(n);let e=n.children.length;n.children.forEach((t,o)=>{p.YR.removeNodes(n,{at:[e-1-o]})}),p.YR.insertNodes(n,n.pteCreateTextBlock({decorators:[]}),{at:[0]}),s&&p.YR.select(n,[0,0])})})})}),a=!0),i&&i.length>0){let s=q(i,{schemaTypes:e.schema});o?await new Promise(o=>{p.ML.withoutNormalizing(n,()=>{eF(n,()=>{tX(n,()=>{if(r){o();return}a=oi({slateEditor:n,slateValueFromProps:s}),(async()=>{for await(let[o,r]of or({slateValue:s})){let{blockChanged:s,blockValid:c}=oa({context:e,sendBack:t,block:o,index:r,slateEditor:n,value:i});a=s||a,l=l&&c}o()})()})})})}):p.ML.withoutNormalizing(n,()=>{eF(n,()=>{tX(n,()=>{if(r)return;a=oi({slateEditor:n,slateValueFromProps:s});let o=0;for(let r of s){let{blockChanged:s,blockValid:c}=oa({context:e,sendBack:t,block:r,index:o,slateEditor:n,value:i});a=s||a,l=l&&c,o++}})})})}if(!l){oe("Invalid value, returning"),r=!0,t({type:"done syncing",value:i});return}if(a){oe("Server value changed, syncing editor");try{n.onChange()}catch(e){console.error(e),t({type:"invalid value",resolution:null,value:i}),r=!0,t({type:"done syncing",value:i});return}s&&!n.selection&&(p.YR.select(n,{anchor:{path:[0,0],offset:0},focus:{path:[0,0],offset:0}}),n.onChange()),t({type:"value changed",value:i})}else oe("Server value and editor value is equal, no need to sync.");r=!0,t({type:"done syncing",value:i})}function oi({slateEditor:e,slateValueFromProps:t}){let n=!1,o=e.children.length;if(t.length<o){for(let n=o-1;n>t.length-1;n--)p.YR.removeNodes(e,{at:[n]});n=!0}return n}async function*or({slateValue:e}){let t=0;for await(let n of e)t%10==0&&await new Promise(e=>setTimeout(e,0)),yield[n,t],t++}function oa({context:e,sendBack:t,block:n,index:o,slateEditor:i,value:r}){let a=!1,l=!0,s=i.children[o],c=s&&!m(n,s);return p.ML.withoutNormalizing(i,()=>{eF(i,()=>{tX(i,()=>{if(c&&l){let c=[r[o]],d=n7(c,e.schema,e.keyGenerator);!d.valid&&d.resolution?.autoResolve&&d.resolution?.patches.length>0&&!e.readOnly&&e.previousValue&&e.previousValue!==r&&(console.warn(`${d.resolution.action} for block with _key '${c[0]._key}'. ${d.resolution?.description}`),d.resolution.patches.forEach(e=>{t({type:"patch",patch:e})})),d.valid||d.resolution?.autoResolve?(s._key===n._key&&s._type===n._type?(oe.enabled&&oe("Updating block",s,n),function(e,t,n,o){if(p.YR.setNodes(e,t,{at:[o]}),e.isTextBlock(t)&&e.isTextBlock(n)){let i=n.children.length;t.children.length<i&&Array.from(Array(i-t.children.length)).forEach((t,n)=>{let r=i-1-n;r>0&&(oe("Removing child"),p.YR.removeNodes(e,{at:[o,r]}))}),t.children.forEach((t,i)=>{let r=n.children[i],a=!m(t,r),l=!m(t.text,r?.text),s=[o,i];if(a){if(t._key===r?._key&&t._type===r?._type){oe("Updating changed child",t,r),p.YR.setNodes(e,t,{at:s});let n=p.xv.isText(t)&&"span"===t._type&&p.xv.isText(r)&&"span"===r._type;n&&l?(r.text.length>0&&p.YR.delete(e,{at:{focus:{path:s,offset:0},anchor:{path:s,offset:r.text.length}}}),p.YR.insertText(e,t.text,{at:s}),e.onChange()):n||(oe("Updating changed inline object child",t),p.YR.setNodes(e,{_key:W},{at:[...s,0],voids:!0}))}else r?(oe("Replacing child",t),p.YR.removeNodes(e,{at:[o,i]}),p.YR.insertNodes(e,t,{at:[o,i]}),e.onChange()):r||(oe("Inserting new child",t),p.YR.insertNodes(e,t,{at:[o,i]}),e.onChange())}})}}(i,n,s,o)):(oe.enabled&&oe("Replacing block",s,n),function(e,t,n){let o=e.selection,i=o&&o.focus.path[0]===n;i&&p.YR.deselect(e),p.YR.removeNodes(e,{at:[n]}),p.YR.insertNodes(e,t,{at:[n]}),e.onChange(),i&&p.YR.select(e,o)}(i,n,o)),a=!0):(t({type:"invalid value",resolution:d.resolution,value:r}),l=!1)}if(!s&&l){let a=n7([r[o]],e.schema,e.keyGenerator);
5oe.enabled&&oe("Validating and inserting new block in the end of the value",n),a.valid||a.resolution?.autoResolve?p.YR.insertNodes(i,n,{at:[o]}):(oe("Invalid",a),t({type:"invalid value",resolution:a.resolution,value:r}),l=!1)}})})}),{blockChanged:a,blockValid:l}}let ol=V("setup");function os(e){ol("Creating new Editor instance");let t=[],n=(0,R.c)(nZ,{input:function(e){let{legacySchema:t,schema:n}=function(e){var t;let n=e.schemaDefinition?function(e){let t=e?.blockObjects?.map(e=>P.fe({type:"object",name:n2[e.name]??e.name,title:void 0===e.title?n8[e.name]:e.title,fields:e.fields?.map(e=>({name:e.name,type:e.type,title:e.title??G(e.name)}))??[]}))??[],n=e?.inlineObjects?.map(e=>P.fe({type:"object",name:n2[e.name]??e.name,title:void 0===e.title?n8[e.name]:e.title,fields:e.fields?.map(e=>({name:e.name,type:e.type,title:e.title??G(e.name)}))??[]}))??[],o=(0,P.Z2)({type:"array",name:"portable-text",of:[...t.map(e=>({type:e.name})),{type:"block",name:"block",of:n.map(e=>({type:e.name})),marks:{decorators:e?.decorators?.map(e=>({title:e.title??G(e.name),value:e.name}))??[],annotations:e?.annotations?.map(e=>({name:e.name,type:"object",title:e.title,fields:e.fields?.map(e=>({name:e.name,title:e.title??G(e.name),type:e.type}))??[]}))??[]},lists:e?.lists?.map(e=>({value:e.name,title:e.title??G(e.name)}))??[],styles:e?.styles?.map(e=>({value:e.name,title:e.title??G(e.name)}))??[]}]}),i=nQ(I.V.compile({types:[o,...t,...n]}).get("portable-text"));return{...i,blockObjects:i.blockObjects.map(e=>void 0!==n3[e.name]?{...e,name:n3[e.name],type:{...e.type,name:n3[e.name]}}:e),inlineObjects:i.inlineObjects.map(e=>void 0!==n3[e.name]?{...e,name:n3[e.name]}:e)}}(e.schemaDefinition):nQ(e.schema.hasOwnProperty("jsonType")?e.schema:(t=e.schema,I.V.compile({name:"blockTypeSchema",types:[t]}).get(t.name))),o={annotations:n.annotations.map(e=>({name:e.name,fields:e.fields.map(e=>({name:e.name,type:e.type.jsonType,title:e.type.title})),title:e.title})),block:{name:n.block.name},blockObjects:n.blockObjects.map(e=>({name:e.name,fields:e.fields.map(e=>({name:e.name,type:e.type.jsonType,title:e.type.title})),title:e.title})),decorators:n.decorators.map(e=>({name:e.value,title:e.title,value:e.value})),inlineObjects:n.inlineObjects.map(e=>({name:e.name,fields:e.fields.map(e=>({name:e.name,type:e.type.jsonType,title:e.type.title})),title:e.title})),span:{name:n.span.name},styles:n.styles.map(e=>({name:e.value,title:e.title,value:e.value})),lists:n.lists.map(e=>({name:e.value,title:e.title,value:e.value}))};return{legacySchema:n,schema:o}}(e);return{converters:[eB,eD,{mimeType:"text/html",serialize:({snapshot:e,event:t})=>{if(!e.context.selection)return{type:"serialization.failure",mimeType:"text/html",originEvent:t.originEvent,reason:"No selection"};let n=(0,k.Ly)(e),o=(0,A.io)(n,{onMissingComponent:!1,components:{unknownType:({children:e})=>void 0!==e?`${e}`:""}});return""===o?{type:"serialization.failure",mimeType:"text/html",originEvent:t.originEvent,reason:"Serialized HTML is empty"}:{type:"serialization.success",data:o,mimeType:"text/html",originEvent:t.originEvent}},deserialize:({snapshot:e,event:n})=>{let o=(0,N.zW)(n.data,t.portableText,{keyGenerator:e.context.keyGenerator,unstable_whitespaceOnPasteMode:t.block.options.unstable_whitespaceOnPasteMode}).flatMap(t=>{let n=(0,y.IX)({context:e.context,block:t,options:{refreshKeys:!1,validateFields:!0}});return n?[n]:[]});return 0===o.length?{type:"deserialization.failure",mimeType:"text/html",reason:"No blocks deserialized"}:{type:"deserialization.success",data:o,mimeType:"text/html"}}},{mimeType:"text/plain",serialize:({snapshot:e,event:t})=>e.context.selection?{type:"serialization.success",data:(0,k.Ly)(e).map(n=>(0,y.dz)(e.context,n)?n.children.map(n=>n._type===e.context.schema.span.name?n.text:"drag.dragstart"===t.originEvent?`[${e.context.schema.inlineObjects.find(e=>e.name===n._type)?.title??"Object"}]`:"").join(""):"drag.dragstart"===t.originEvent?`[${e.context.schema.blockObjects.find(e=>e.name===n._type)?.title??"Object"}]`:"").filter(e=>""!==e).join(` 6 7`),mimeType:"text/plain",originEvent:t.originEvent}:{type:"serialization.failure",mimeType:"text/plain",originEvent:t.originEvent,reason:"No selection"},deserialize:({snapshot:e,event:n})=>{let o=`<html><body>${String(n.data).replace(/[&<>"'`=/]/g,e=>ej[e]).split(/\n{2,}/).map(e=>e?`<p>${e.replace(/(?:\r\n|\r|\n)/g,"<br/>")}</p>`:"<p></p>").join("")}</body></html>`,i=(0,N.zW)(o,t.portableText,{keyGenerator:e.context.keyGenerator}).flatMap(t=>{let n=(0,y.IX)({context:e.context,block:t,options:{refreshKeys:!1,validateFields:!0}});return n?[n]:[]});return 0===i.length?{type:"deserialization.failure",mimeType:"text/plain",reason:"No blocks de
7serialized"}:{type:"deserialization.success",data:i,mimeType:"text/plain"}}}],getLegacySchema:()=>t,keyGenerator:e.keyGenerator??ev,maxBlocks:e.maxBlocks,readOnly:e.readOnly,schema:n,initialValue:e.initialValue}}(e)}),o=(0,R.c)(n5),i=function(e){ne("Creating new Slate editor instance");let t=t7((0,u.BU)((0,p.Jh)()),{editorActor:e.editorActor,relayActor:e.relayActor,subscriptions:e.subscriptions});eu.set(t,{}),ep.set(t,{}),t.decoratedRanges=[],t.decoratorState={};let n=eL(e.editorActor.getSnapshot().context);t.value=[n],t.blockIndexMap=new Map,t.listIndexMap=new Map,eU({schema:e.editorActor.getSnapshot().context.schema,value:t.value},{blockIndexMap:t.blockIndexMap,listIndexMap:t.listIndexMap});let o=q(t.value,{schemaTypes:e.editorActor.getSnapshot().context.schema});return{instance:t,initialValue:o}}({editorActor:n,relayActor:o,subscriptions:t}),r=function(e,t){let n=t.getSnapshot().context.schema;return{focus:()=>{t.send({type:"focus",editor:e})},blur:()=>{t.send({type:"blur",editor:e})},toggleMark:n=>{t.send({type:"behavior event",behaviorEvent:{type:"decorator.toggle",decorator:n},editor:e})},toggleList:n=>{t.send({type:"behavior event",behaviorEvent:{type:"list item.toggle",listItem:n},editor:e})},toggleBlockStyle:n=>{t.send({type:"behavior event",behaviorEvent:{type:"style.toggle",style:n},editor:e})},isMarkActive:n=>{let o=eH({editorActorSnapshot:t.getSnapshot(),slateEditorInstance:e});return(0,v.WH)(o).includes(n)},marks:()=>{let n=eH({editorActorSnapshot:t.getSnapshot(),slateEditorInstance:e});return[...(0,v.YG)(n),...(0,v.WH)(n)]},undo:()=>{t.send({type:"behavior event",behaviorEvent:{type:"history.undo"},editor:e})},redo:()=>{t.send({type:"behavior event",behaviorEvent:{type:"history.redo"},editor:e})},select:n=>{let o=es({context:{schema:t.getSnapshot().context.schema,value:e.value,selection:n},blockIndexMap:e.blockIndexMap});o?p.YR.select(e,o):p.YR.deselect(e),e.onChange()},focusBlock:()=>{if(e.selection){let t=p.NB.descendant(e,e.selection.focus.path.slice(0,1));if(t)return H([t],n.block.name,eu.get(e))[0]}},focusChild:()=>{if(e.selection){let t=p.NB.descendant(e,e.selection.focus.path.slice(0,1));if(t&&e.isTextBlock(t))return H([t],n.block.name,eu.get(e))[0].children[e.selection.focus.path[1]]}},insertChild:(o,i)=>{if(o.name!==n.span.name)return t.send({type:"behavior event",behaviorEvent:{type:"insert.inline object",inlineObject:{name:o.name,value:i}},editor:e}),e.selection?er({schema:t.getSnapshot().context.schema,editor:e,range:e.selection})?.focus.path??[]:[];if(!e.selection)throw Error("The editor has no selection");let[r]=Array.from(p.ML.nodes(e,{at:e.selection.focus.path.slice(0,1),match:e=>e._type===n.block.name}))[0]||[void 0];if(!r)throw Error("No focused text block");if(o.name!==n.span.name&&!n.inlineObjects.some(e=>e.name===o.name))throw Error("This type cannot be inserted as a child to a text block");let a=q([{_key:t.getSnapshot().context.keyGenerator(),_type:n.block.name,children:[{_key:t.getSnapshot().context.keyGenerator(),_type:o.name,...i||{}}]}],{schemaTypes:t.getSnapshot().context.schema})[0].children[0],l=e.selection.focus.path.slice(0,2),s=a._type===n.span.name,c=p.NB.get(e,l);return s&&c._type!==n.span.name&&(n4("Inserting span child next to inline object child, moving selection + 1"),e.move({distance:1,unit:"character"})),p.YR.insertNodes(e,a,{select:!0,at:e.selection}),e.onChange(),e.selection?er({schema:t.getSnapshot().context.schema,editor:e,range:e.selection})?.focus.path??[]:[]},insertBlock:(n,o)=>(t.send({type:"behavior event",behaviorEvent:{type:"insert.block",block:{_type:n.name,...o||{}},placement:"auto"},editor:e}),e.selection?er({schema:t.getSnapshot().context.schema,editor:e,range:e.selection})?.focus.path??[]:[]),hasBlockStyle:t=>{try{return function({editor:e,style:t}){if(!e.selection)return!1;let n=[...p.ML.nodes(e,{at:e.selection,match:t=>e.isTextBlock(t)})];return n.length>0&&n.every(([e])=>e.style===t)}({editor:e,style:t})}catch{return!1}},hasListStyle:t=>{try{return function({editor:e,listItem:t}){if(!e.selection)return!1;let n=[...p.ML.nodes(e,{at:e.selection,match:t=>e.isTextBlock(t)})];return n.length>0&&n.every(([n])=>e.isListBlock(n)&&n.listItem===t)}({editor:e,listItem:t})}catch{return!1}},isVoid:e=>![n.block.name,n.span.name].includes(e._type),findByPath:o=>{let i=es({context:{schema:t.getSnapshot().context.schema,value:e.value,selection:{focus:{path:o,offset:0},anchor:{path:o,offset:0}}},blockIndexMap:e.blockIndexMap});if(i){let[t,r]=p.ML.node(e,i.focus.path.slice(0,1));if(t&&r&&"string"==typeof t._key){if(1===o.length&&1===i.focus.path.length)return[H([t],n.block.name)[0],[{_key:t._key}]];let r=H([t],n.block.name,eu.get(e))[0];if(e.isTextBlock(r)){let e=r.children[i.focus.path[1]];if(e)return[e,[{_key:t._key},"children",{_key:e._key}]]}}}return[void 0,void 0]},findDOMNode:t=>{let n;try{let[o]=Array.from(p.ML.nodes(e,{at:[],match:e=>e._key===t._key})||[])[0]||[void 0];n=u.F3.toDOMNode(e,o)}catch{}return n},activeAnnotations:()=>
7{if(!e.selection||e.selection.focus.path.length<2)return[];try{let t=[];for(let[n,o]of p.ML.nodes(e,{at:e.selection,match:e=>p.xv.isText(e)&&void 0!==e.marks&&Array.isArray(e.marks)&&e.marks.length>0})){let[i]=p.ML.node(e,o,{depth:1});e.isTextBlock(i)&&i.markDefs?.forEach(e=>{p.xv.isText(n)&&n.marks&&Array.isArray(n.marks)&&n.marks.includes(e._key)&&t.push(e)})}return t}catch{return[]}},isAnnotationActive:n=>{let o=eH({editorActorSnapshot:t.getSnapshot(),slateEditorInstance:e});return(0,v.kH)(n)(o)},addAnnotation:(o,i)=>{let r;return p.ML.withoutNormalizing(e,()=>{r=tP({context:{keyGenerator:t.getSnapshot().context.keyGenerator,schema:n},operation:{annotation:{name:o.name,value:i??{}},editor:e}})}),e.onChange(),r},delete:(o,i)=>{if(o){let r=es({context:{schema:t.getSnapshot().context.schema,value:e.value,selection:o},blockIndexMap:e.blockIndexMap});if(!(r&&r.anchor.path.length>0&&r.focus.path.length>0))throw Error("Invalid range");if(r){if(!i?.mode||i?.mode==="selected"){n4("Deleting content in selection"),p.YR.delete(e,{at:r,hanging:!0,voids:!0}),e.onChange();return}if(i?.mode==="blocks"&&(n4("Deleting blocks touched by selection"),p.YR.removeNodes(e,{at:r,voids:!0,match:t=>e.isTextBlock(t)||!e.isTextBlock(t)&&p.W_.isElement(t)})),i?.mode==="children"&&(n4("Deleting children touched by selection"),p.YR.removeNodes(e,{at:r,voids:!0,match:t=>t._type===n.span.name||!e.isTextBlock(t)&&p.W_.isElement(t)})),0===e.children.length){let n=eL(t.getSnapshot().context);e.children=[n],e.value=[n],eU({schema:t.getSnapshot().context.schema,value:e.value},{blockIndexMap:e.blockIndexMap,listIndexMap:e.listIndexMap})}e.onChange()}}},removeAnnotation:n=>{t.send({type:"behavior event",behaviorEvent:{type:"annotation.remove",annotation:{name:n.name}},editor:e})},getSelection:()=>{let n=null;if(e.selection){let o=eh.get(e.selection);if(o)return o;n=er({schema:t.getSnapshot().context.schema,editor:e,range:e.selection}),eh.set(e.selection,n)}return n},getValue:()=>H(e.children,n.block.name,eu.get(e)),isCollapsedSelection:()=>!!e.selection&&p.e6.isCollapsed(e.selection),isExpandedSelection:()=>!!e.selection&&p.e6.isExpanded(e.selection),insertBreak:()=>{e.insertBreak(),e.onChange()},getFragment:()=>H(e.getFragment(),n.block.name),isSelectionsOverlapping:(n,o)=>{let i=es({context:{schema:t.getSnapshot().context.schema,value:e.value,selection:n},blockIndexMap:e.blockIndexMap}),r=es({context:{schema:t.getSnapshot().context.schema,value:e.value,selection:o},blockIndexMap:e.blockIndexMap});return p.e6.isRange(i)&&p.e6.isRange(r)&&p.e6.includes(i,r)}}}(i.instance,n),{mutationActor:a,syncActor:l}=function(e){ol("Creating new Actors");let t=(0,R.c)(n9,{input:{readOnly:e.editorActor.getSnapshot().matches({"edit mode":"read only"}),schema:e.editorActor.getSnapshot().context.schema,slateEditor:e.slateEditor}}),n=(0,R.c)(on,{input:{initialValue:e.editorActor.getSnapshot().context.initialValue,keyGenerator:e.editorActor.getSnapshot().context.keyGenerator,readOnly:e.editorActor.getSnapshot().matches({"edit mode":"read only"}),schema:e.editorActor.getSnapshot().context.schema,slateEditor:e.slateEditor}});return e.subscriptions.push(()=>{let o=t.on("*",t=>{"has pending mutations"===t.type&&n.send({type:"has pending mutations"}),"mutation"===t.type&&(n.send({type:"mutation"}),e.editorActor.send({type:"mutation",patches:t.patches,snapshot:t.snapshot,value:t.snapshot})),"patch"===t.type&&e.relayActor.send(t)});return()=>{o.unsubscribe()}}),e.subscriptions.push(()=>{let t=n.on("*",t=>{switch(t.type){case"invalid value":case"value changed":e.relayActor.send(t);break;case"patch":e.editorActor.send({...t,type:"internal.patch",value:H(e.slateEditor.children,e.editorActor.getSnapshot().context.schema.block.name,eu.get(e.slateEditor))});break;default:e.editorActor.send(t)}});return()=>{t.unsubscribe()}}),e.subscriptions.push(()=>{let o=e.editorActor.subscribe(e=>{e.matches({"edit mode":"read only"})?(t.send({type:"update readOnly",readOnly:!0}),n.send({type:"update readOnly",readOnly:!0})):(t.send({type:"update readOnly",readOnly:!1}),n.send({type:"update readOnly",readOnly:!1}))});return()=>{o.unsubscribe()}}),e.subscriptions.push(()=>{let n=e.editorActor.on("*",n=>{switch(n.type){case"editable":case"mutation":case"ready":case"read only":case"selection":e.relayActor.send(n);break;case"internal.patch":t.send({...n,type:"patch"})}});return()=>{n.unsubscribe()}}),{mutationActor:t,syncActor:n}}({editorActor:n,relayActor:o,slateEditor:i.instance,subscriptions:t}),s={dom:nt(e=>n.send(e),i.instance),getSnapshot:()=>eH({editorActorSnapshot:n.getSnapshot(),slateEditorInstance:i.instance}),registerBehavior:e=>{let t=ex({name:"custom",reference:{priority:e_,importance:"higher"}}),o={...e,priority:t};return n.send({type:"add behavior",behaviorConfig:o}),()=>{n.send({type:"remove behavior",behaviorConfig:o})}},send:e=>{switch(e.type){case"update value":l.send(e);break;case"update readOnly":case"patches":case"update maxBlocks":n.send(e);break;case"blur":n.send({type:"blur",editor:i.instance});break;case"focus":n.send({type:"focus",editor:i.instance});break;case"insert.block object":n.send({type:"behavior event",behaviorEvent:{type:"insert.block",block:{_type:e.blockObject.name,...e.blockObject.value??{}},placement:e.placement},editor:i.instance});break;default:n.send({type:"behavior event",behaviorEvent:e,editor:i.instance})}},on:(e,t)=>o.on(e,e=>{switch(e.type){case"blurred":case"done loading":case"editable":case"focused":case"invali
7d value":case"loading":case"mutation":case"patch":case"read only":case"ready":case"selection":case"value changed":t(e)}}),_internal:{editable:r,editorActor:n,slateEditor:i}};return{actors:{editorActor:n,mutationActor:a,relayActor:o,syncActor:l},editor:s,subscriptions:t}}let oc=(0,r.createContext)({});function od(e){let t,n,o;let l=(0,i.c)(7);l[0]!==e?(t=t=>e.onChange(t),l[0]=e,l[1]=t):t=l[1];let s=(0,a.i)(t);return l[2]!==s||l[3]!==e.relayActor?(n=()=>{let t=e.relayActor.on("*",e=>{let t=op(e);t&&s(t)});return()=>{t.unsubscribe()}},l[2]=s,l[3]=e.relayActor,l[4]=n):n=l[4],l[5]!==e.relayActor?(o=[e.relayActor],l[5]=e.relayActor,l[6]=o):o=l[6],(0,r.useEffect)(n,o),null}function op(e){switch(e.type){case"blurred":return{type:"blur",event:e.event};case"patch":case"mutation":case"ready":case"selection":case"unset":return e;case"loading":return{type:"loading",isLoading:!0};case"done loading":return{type:"loading",isLoading:!1};case"focused":return{type:"focus",event:e.event};case"value changed":return{type:"value",value:e.value};case"invalid value":return{type:"invalidValue",resolution:e.resolution,value:e.value}}}let ou=V("component:PortableTextEditor");class oh extends r.Component{static displayName="PortableTextEditor";change$=new E.x;subscriptions=[];unsubscribers=[];constructor(e){if(super(e),e.editor)this.editor=e.editor,this.schemaTypes=this.editor._internal.editorActor.getSnapshot().context.getLegacySchema();else{let{actors:t,editor:n,subscriptions:o}=os({initialValue:e.value,keyGenerator:e.keyGenerator,maxBlocks:void 0===e.maxBlocks?void 0:Number.parseInt(e.maxBlocks.toString(),10),readOnly:e.readOnly,schema:e.schemaType});this.subscriptions=o,this.actors=t,this.editor=n,this.schemaTypes=t.editorActor.getSnapshot().context.getLegacySchema()}this.editable=this.editor._internal.editable}componentDidMount(){if(!this.actors)return;for(let e of this.subscriptions)this.unsubscribers.push(e());let e=this.actors.relayActor.on("*",e=>{let t=op(e);t&&(this.props.editor||this.props.onChange(t),this.change$.next(t))});this.unsubscribers.push(e.unsubscribe),this.actors.editorActor.start(),this.actors.mutationActor.start(),this.actors.relayActor.start(),this.actors.syncActor.start()}componentDidUpdate(e){this.props.editor||e.editor||this.props.schemaType===e.schemaType||console.warn("Updating schema type is no longer supported"),this.props.editor||e.editor||(this.props.readOnly!==e.readOnly&&this.editor._internal.editorActor.send({type:"update readOnly",readOnly:this.props.readOnly??!1}),this.props.maxBlocks!==e.maxBlocks&&this.editor._internal.editorActor.send({type:"update maxBlocks",maxBlocks:void 0===this.props.maxBlocks?void 0:Number.parseInt(this.props.maxBlocks.toString(),10)}),this.props.value!==e.value&&this.editor.send({type:"update value",value:this.props.value}),this.props.editorRef!==e.editorRef&&this.props.editorRef&&(this.props.editorRef.current=this))}componentWillUnmount(){for(let e of this.unsubscribers)e();this.actors&&(eC(this.actors.editorActor),eC(this.actors.mutationActor),eC(this.actors.relayActor),eC(this.actors.syncActor))}setEditable=e=>{this.editor._internal.editable={...this.editor._internal.editable,...e}};render(){let e=this.props.editor?void 0:this.props.incomingPatches$??this.props.patches$;return(0,s.jsxs)(s.Fragment,{children:[e?(0,s.jsx)(of,{editorActor:this.editor._internal.editorActor,patches$:e}):null,(0,s.jsx)(ef.Provider,{value:this.editor._internal.editorActor,children:(0,s.jsx)(oc.Provider,{value:this.actors.relayActor,children:(0,s.jsx)(u.mH,{editor:this.editor._internal.slateEditor.instance,initialValue:this.editor._internal.slateEditor.initialValue,children:(0,s.jsx)(eA.Provider,{value:this,children:this.props.children})})})})]})}static activeAnnotations=e=>e&&e.editable?e.editable.activeAnnotations():[];static isAnnotationActive=(e,t)=>!!e&&!!e.editable&&e.editable.isAnnotationActive(t);static addAnnotation=(e,t,n)=>e.editable?.addAnnotation(t,n);static blur=e=>{ou("Host blurred"),e.editable?.blur()};static delete=(e,t,n)=>e.editable?.delete(t,n);static findDOMNode=(e,t)=>e.editable?.findDOMNode(t);static findByPath=(e,t)=>e.editable?.findByPath(t)||[];static focus=e=>{ou("Host requesting focus"),e.editable?.focus()};static focusBlock=e=>e.editable?.focusBlock();static focusChild=e=>e.editable?.focusChild();static getSelection=e=>e.editable?e.editable.getSelection():null;static getValue=e=>e.editable?.getValue();static hasBlockStyle=(e,t)=>
7e.editable?.hasBlockStyle(t);static hasListStyle=(e,t)=>e.editable?.hasListStyle(t);static isCollapsedSelection=e=>e.editable?.isCollapsedSelection();static isExpandedSelection=e=>e.editable?.isExpandedSelection();static isMarkActive=(e,t)=>e.editable?.isMarkActive(t);static insertChild=(e,t,n)=>(ou("Host inserting child"),e.editable?.insertChild(t,n));static insertBlock=(e,t,n)=>e.editable?.insertBlock(t,n);static insertBreak=e=>e.editable?.insertBreak();static isVoid=(e,t)=>e.editable?.isVoid(t);static isObjectPath=(e,t)=>{if(!t||!Array.isArray(t))return!1;let n=t.length>3&&"children"===t[1];return t.length>1&&"children"!==t[1]||n};static marks=e=>e.editable?.marks();static select=(e,t)=>{ou("Host setting selection",t),e.editable?.select(t)};static removeAnnotation=(e,t)=>e.editable?.removeAnnotation(t);static toggleBlockStyle=(e,t)=>(ou("Host is toggling block style"),e.editable?.toggleBlockStyle(t));static toggleList=(e,t)=>e.editable?.toggleList(t);static toggleMark=(e,t)=>{ou("Host toggling mark",t),e.editable?.toggleMark(t)};static getFragment=e=>e.editable?.getFragment();static undo=e=>{ou("Host undoing"),e.editable?.undo()};static redo=e=>{ou("Host redoing"),e.editable?.redo()};static isSelectionsOverlapping=(e,t,n)=>e.editable?.isSelectionsOverlapping(t,n)}function of(e){let t,n;let o=(0,i.c)(4);return o[0]!==e.editorActor||o[1]!==e.patches$?(t=()=>{let t=e.patches$.subscribe(t=>{e.editorActor.send({type:"patches",...t})});return()=>{t.unsubscribe()}},n=[e.editorActor,e.patches$],o[0]=e.editorActor,o[1]=e.patches$,o[2]=t,o[3]=n):(t=o[2],n=o[3]),(0,r.useEffect)(t,n),null}function oy(e){let t=(0,u._7)(),n=(0,r.useContext)(ef),o=(0,c.v9)(n,e=>e.context.getLegacySchema()),i=(0,r.useRef)(null),a=eI(),l=(0,u.vt)(),[d,p]=(0,r.useState)(!1),[h,f]=(0,r.useState)(!1),y=e.children.props.parent,g=y&&t.isTextBlock(y)?y:void 0,k=(0,r.useMemo)(()=>g?[{_key:g._key},"children",{_key:e.leaf._key}]:void 0,[g,e.leaf._key]),v=n.getSnapshot().context.schema.decorators.map(e=>e.name),b=_((e.leaf.marks??[]).filter(e=>v.includes(e))),x=(e.leaf.marks??[]).flatMap(e=>{if(v.includes(e))return[];let t=g?.markDefs?.find(t=>t._key===e);return t?[t]:[]}),E=x.length>0&&l;(0,r.useEffect)(()=>{if(!E){p(!1);return}let e=oh.getSelection(a);e&&m(e.focus.path,k)&&oh.isCollapsedSelection(a)&&(0,r.startTransition)(()=>{p(!0)})},[E,k,a]);let w=(0,r.useCallback)(()=>{if(!E)return;let e=window.getSelection();if(!e){f(!1);return}if(e&&e.rangeCount>0){let t=e.getRangeAt(0);i.current&&t.intersectsNode(i.current)?f(!0):f(!1)}else f(!1)},[E]);(0,r.useEffect)(()=>{if(!E)return;let e=n.on("blurred",()=>{p(!1),f(!1)}),t=n.on("focused",()=>{let e=oh.getSelection(a);e&&m(e.focus.path,k)&&oh.isCollapsedSelection(a)&&p(!0),w()}),o=n.on("selection",e=>{e.selection&&m(e.selection.focus.path,k)&&oh.isCollapsedSelection(a)?p(!0):p(!1),w()});return()=>{e.unsubscribe(),t.unsubscribe(),o.unsubscribe()}},[n,k,a,w,E]),(0,r.useEffect)(()=>w(),[w]);let S=e.children;for(let t of b){let n=o.decorators.find(e=>e.value===t);k&&n&&e.renderDecorator&&(S=e.renderDecorator({children:S,editorElementRef:i,focused:d,path:k,selected:h,schemaType:n,value:t,type:n}))}for(let t of x){let n=o.annotations.find(e=>e.name===t._type);n&&(S=g&&k&&e.renderAnnotation?(0,s.jsx)("span",{ref:i,children:e.renderAnnotation({block:g,children:S,editorElementRef:i,focused:d,path:k,selected:h,schemaType:n,value:t,type:n})}):(0,s.jsx)("span",{ref:i,children:S}))}if(g&&k&&e.renderChild){let t=g.children.find(t=>t._key===e.leaf._key);t&&(S=e.renderChild({annotations:x,children:S,editorElementRef:i,focused:d,path:k,schemaType:o.span,selected:h,value:t,type:o.span}))}return(0,s.jsx)("span",{...e.attributes,ref:i,children:S})}let og={position:"absolute",userSelect:"none",pointerEvents:"none",left:0,right:0};function om(e){let t;let n=(0,i.c)(12),o=(0,r.useContext)(ef),a=(0,c.v9)(o,ok);if(e.leaf._type!==a.span.name)return e.children;n[0]!==e?(t=(0,s.jsx)(oy,{...e}),n[0]=e,n[1]=t):t=n[1];let l=t;if(e.renderPlaceholder&&e.leaf.placeholder&&""===e.text.text){let t,o,i;return n[2]!==e.renderPlaceholder?(t=e.renderPlaceholder(),n[2]=e.renderPlaceholder,n[3]=t):t=n[3],n[4]!==t?(o=(0,s.jsx)("span",{style:og,contentEditable:!1,
7children:t}),n[4]=t,n[5]=o):o=n[5],n[6]!==l||n[7]!==o?(i=(0,s.jsxs)(s.Fragment,{children:[o,l]}),n[6]=l,n[7]=o,n[8]=i):i=n[8],i}let d=e.leaf.rangeDecoration;if(d){let e;n[9]!==d||n[10]!==l?(e=d.component({children:l}),n[9]=d,n[10]=l,n[11]=e):e=n[11],l=e}return l}function ok(e){return e.context.schema}function ov(e){let t;let n=(0,i.c)(5);return n[0]!==e.attributes||n[1]!==e.children||n[2]!==e.text._key||n[3]!==e.text._type?(t=(0,s.jsx)("span",{...e.attributes,"data-child-key":e.text._key,"data-child-name":e.text._type,"data-child-type":"span",children:e.children}),n[0]=e.attributes,n[1]=e.children,n[2]=e.text._key,n[3]=e.text._type,n[4]=t):t=n[4],t}let ob="u">typeof window&&/Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent),ox={alt:"altKey",control:"ctrlKey",meta:"metaKey",shift:"shiftKey"},o_={add:"+",break:"pause",cmd:"meta",command:"meta",ctl:"control",ctrl:"control",del:"delete",down:"arrowdown",esc:"escape",ins:"insert",left:"arrowleft",mod:ob?"meta":"control",opt:"alt",option:"alt",return:"enter",right:"arrowright",space:" ",spacebar:" ",up:"arrowup",win:"meta",windows:"meta"},oE={backspace:8,tab:9,enter:13,shift:16,control:17,alt:18,pause:19,capslock:20,escape:27," ":32,pageup:33,pagedown:34,end:35,home:36,arrowleft:37,arrowup:38,arrowright:39,arrowdown:40,insert:45,delete:46,meta:91,numlock:144,scrolllock:145,";":186,"=":187,",":188,"-":189,".":190,"/":191,"`":192,"[":219,"\\":220,"]":221,"'":222,f1:112,f2:113,f3:114,f4:115,f5:116,f6:117,f7:118,f8:119,f9:120,f10:121,f11:122,f12:123,f13:124,f14:125,f15:126,f16:127,f17:128,f18:129,f19:130,f20:131};function ow(e){let t={altKey:!1,ctrlKey:!1,metaKey:!1,shiftKey:!1},n=e.replace("++","+add").split("+");for(let e of n){let o=e.endsWith("?")&&e.length>1,i=o?e.slice(0,-1):e,r=oO(i),a=ox[r],l=o_[i],s=oE[r];if(i.length>1&&void 0===a&&void 0===l&&void 0===s)throw TypeError(`Unknown modifier: "${i}"`);(1===n.length||void 0===a)&&(t.key=r,t.keyCode=function(e){let t=oO(e);return oE[t]??t.toUpperCase().charCodeAt(0)}(i)),void 0!==a&&(t[a]=!o||null)}return t}function oS(e,t){return(null==e.altKey||e.altKey===t.altKey)&&(null==e.ctrlKey||e.ctrlKey===t.ctrlKey)&&(null==e.metaKey||e.metaKey===t.metaKey)&&(null==e.shiftKey||e.shiftKey===t.shiftKey)&&(void 0!==e.ke
7yCode&&void 0!==t.keyCode?91===e.keyCode&&93===t.keyCode||e.keyCode===t.keyCode:e.keyCode===t.keyCode||e.key===t.key.toLowerCase())}function oO(e){let t=e.toLowerCase();return o_[t]??t}let oM=V("plugin:withHotKeys"),oR=(0,w.cY)({types:{context:{},input:{},events:{}},actions:{"update pending range decorations":(0,S.a)({pendingRangeDecorations:({context:e,event:t})=>"range decorations updated"!==t.type?e.pendingRangeDecorations:t.rangeDecorations}),"set up initial range decorations":({context:e})=>{let t=[];for(let n of e.pendingRangeDecorations){let o=es({context:{schema:e.schema,value:e.slateEditor.value,selection:n.selection},blockIndexMap:e.slateEditor.blockIndexMap});if(!p.e6.isRange(o)){n.onMoved?.({newSelection:null,rangeDecoration:n,origin:"local"});continue}t.push({rangeDecoration:n,...o})}e.slateEditor.decoratedRanges=t},"update range decorations":({context:e,event:t})=>{if("range decorations updated"!==t.type)return;let n=[];for(let o of t.rangeDecorations){let t=es({context:{schema:e.schema,value:e.slateEditor.value,selection:o.selection},blockIndexMap:e.slateEditor.blockIndexMap});if(!p.e6.isRange(t)){o.onMoved?.({newSelection:null,rangeDecoration:o,origin:"local"});continue}n.push({rangeDecoration:o,...t})}e.slateEditor.decoratedRanges=n},"move range decorations":({context:e,event:t})=>{if("slate operation"!==t.type)return;let n=[];for(let o of e.slateEditor.decoratedRanges){let i;let r=es({context:{schema:e.schema,value:e.slateEditor.value,selection:o.rangeDecoration.selection},blockIndexMap:e.slateEditor.blockIndexMap});if(!p.e6.isRange(r)){o.rangeDecoration.onMoved?.({newSelection:null,rangeDecoration:o.rangeDecoration,origin:"local"});continue}if((i=function(e,t){let n=p.E9.transform(e.anchor,t),o=p.E9.transform(e.focus,t);return null===n||null===o?null:p.E9.equals(n,e.anchor)&&p.E9.equals(o,e.focus)?e:{anchor:n,focus:o}}(r,t.operation))&&i!==r||null===i&&r){let t=i?er({schema:e.schema,editor:e.slateEditor,range:i}):null;o.rangeDecoration.onMoved?.({newSelection:t,rangeDecoration:o.rangeDecoration,origin:"local"})}null!==i&&n.push({...i||r,rangeDecoration:{...o.rangeDecoration,selection:er({schema:e.schema,editor:e.slateEditor,range:i})}})}e.slateEditor.decoratedRanges=n},"assign readOnly":(0,S.a)({readOnly:({context:e,event:t})=>"update read only"!==t.type?e.readOnly:t.readOnly}),"update decorate":(0,S.a)({decorate:({context:e})=>({fn:oN(e.schema,e.slateEditor)})})},actors:{"slate operation listener":(0,M.E9)(({input:e,sendBack:t})=>{let n=e.slateEditor.apply;return e.slateEditor.apply=e=>{"set_selection"!==e.type&&t({type:"slate operation",operation:e}),n(e)},()=>{e.slateEditor.apply=n}})},guards:{"has pending range decorations":({context:e})=>e.pendingRangeDecorations.length>0,"has range decorations":({context:e})=>e.slateEditor.decoratedRanges.length>0,"has different decorations":({context:e,event:t})=>"range decorations updated"===t.type&&!m(e.slateEditor.decoratedRanges.map(e=>({anchor:e.rangeDecoration.selection?.anchor,focus:e.rangeDecoration.selection?.focus})),t.rangeDecorations.map(e=>({anchor:e.selection?.anchor,focus:e.selection?.focus}))),"not read only":({context:e})=>!e.readOnly,"should skip setup":({context:e})=>e.skipSetup}}).createMachine({id:"range decorations",context:({input:e})=>({readOnly:e.readOnly,pendingRangeDecorations:e.rangeDecorations,decoratedRanges:[],skipSetup:e.skipSetup,schema:e.schema,slateEditor:e.slateEditor,decorate:{fn:oN(e.schema,e.slateEditor)}}),invoke:{src:"slate operation listener",input:({context:e})=>({slateEditor:e.slateEditor})},on:{"update read only":{actions:["assign readOnly"]}},initial:"setting up",states:{"setting up":{always:[{guard:(0,R.e)(["should skip setup","has pending range decorations"]),target:"ready",actions:["set up initial range decorations","update decorate"]},{guard:"should skip setup",target:"ready"}],on:{"range decorations updated":{actions:["update pending range decorations"]},ready:[{target:"ready",guard:"has pending range decorations",actions:["set up initial range decorations","update decorate"]},{target:"ready"}]}},ready:{initial:"idle",on:{"range decorations updated":{target:".idle",guard:"has different decorations",actions:["update range decorations","update decorate"]}}
7,states:{idle:{on:{"slate operation":{target:"moving range decorations",guard:(0,R.e)(["has range decorations","not read only"])}}},"moving range decorations":{entry:["move range decorations"],always:{target:"idle"}}}}}});function oN(e,t){return function([n,o]){if(X(t.children,e))return[{anchor:{path:[0,0],offset:0},focus:{path:[0,0],offset:0},placeholder:!0}];if(0===o.length||!p.W_.isElement(n)||0===n.children.length)return[];let i=o.at(0);return void 0===i?[]:t.decoratedRanges.filter(e=>p.e6.isCollapsed(e)?n.children.some((t,n)=>p.y$.equals(e.anchor.path,[i,n])&&p.y$.equals(e.focus.path,[i,n])):p.e6.intersection(e,{anchor:{path:o,offset:0},focus:{path:o,offset:0}})||p.e6.includes(e,o))}}let oA=V("component:Editable"),oI=(0,r.forwardRef)(function(e,t){let{hotkeys:n,onBlur:o,onFocus:i,onBeforeInput:a,onPaste:l,onCopy:h,onCut:f,onClick:g,onDragStart:k,onDrag:v,onDragEnd:b,onDragEnter:x,onDragOver:_,onDrop:E,onDragLeave:w,rangeDecorations:S,renderAnnotation:O,renderBlock:M,renderChild:R,renderDecorator:N,renderListItem:A,renderPlaceholder:I,renderStyle:T,selection:C,scrollSelectionIntoView:B,spellCheck:D,...j}=e,Y=eI(),U=(0,r.useRef)(null),[L,z]=(0,r.useState)(null),[$,P]=(0,r.useState)(!1);(0,r.useImperativeHandle)(t,()=>U.current);let G=(0,r.useContext)(ef),F=(0,r.useContext)(oc),K=(0,c.v9)(G,e=>e.matches({"edit mode":"read only"})),V=(0,u.ui)(),W=(0,c.TH)(oR,{input:{rangeDecorations:S??[],readOnly:K,schema:G.getSnapshot().context.schema,slateEditor:V,skipSetup:!G.getSnapshot().matches({setup:"setting up"})}}),J=(0,c.v9)(W,e=>e.context.decorate?.fn);(0,r.useEffect)(()=>{W.send({type:"update read only",readOnly:K})},[W,K]),(0,r.useEffect)(()=>{W.send({type:"range decorations updated",rangeDecorations:S??[]})},[W,S]),(0,r.useMemo)(()=>K?V:(function(e,t,n){let o=["enter","tab","shift","delete","end"],i=n??{};return function(n){return n.pteWithHotKeys=r=>
7{Object.keys(i).forEach(a=>{var l,s;if("marks"===a)for(let t in i[a]){if(o.includes(t))throw Error(`The hotkey ${t} is reserved!`);if(l=r.nativeEvent,oS(ow(t),l)){r.preventDefault();let o=i[a];if(o){let i=o[t];oM(`HotKey ${t} to toggle ${i}`),e.send({type:"behavior event",behaviorEvent:{type:"decorator.toggle",decorator:i},editor:n})}}}if("custom"===a)for(let e in i[a]){if(o.includes(e))throw Error(`The hotkey ${e} is reserved!`);if(s=r.nativeEvent,oS(ow(e),s)){let n=i[a];n&&(0,n[e])(r,t)}}})},n}})(G,Y,n)(V),[G,n,Y,K,V]);let q=(0,r.useCallback)(e=>(0,s.jsx)(eM,{...e,readOnly:K,renderBlock:M,renderChild:R,renderListItem:A,renderStyle:T,spellCheck:D}),[D,K,M,R,A,T]),Z=(0,r.useCallback)(e=>(0,s.jsx)(om,{...e,readOnly:K,renderAnnotation:O,renderChild:R,renderDecorator:N,renderPlaceholder:I}),[K,O,R,N,I]),Q=(0,r.useCallback)(e=>(0,s.jsx)(ov,{...e}),[]),ee=(0,r.useCallback)(()=>{if(C){oA(`Selection from props ${JSON.stringify(C)}`);let e=function(e,t){if(!e||!t||0===t.length)return null;let n=null,o=null,{anchor:i,focus:r}=e;return i&&t.find(e=>m({_key:e._key},i.path[0]))&&(n=el(i,t)),r&&t.find(e=>m({_key:e._key},r.path[0]))&&(o=el(r,t)),n&&o?{anchor:n,focus:o,backward:e.backward}:null}(C,H(V.children,G.getSnapshot().context.schema.block.name));if(null!==e){oA(`Normalized selection from props ${JSON.stringify(e)}`);let t=es({context:{schema:G.getSnapshot().context.schema,value:V.value,selection:e},blockIndexMap:V.blockIndexMap});t&&(p.YR.select(V,t),V.operations.some(e=>"set_selection"===e.type)||G.send({type:"update selection",selection:e}),V.onChange())}}},[G,C,V]);(0,r.useEffect)(()=>{let e=G.on("ready",()=>{W.send({type:"ready"}),ee()}),t=G.on("invalid value",()=>{P(!0)}),n=G.on("value changed",()=>{P(!1)});return()=>{e.unsubscribe(),t.unsubscribe(),n.unsubscribe()}},[W,G,ee]),(0,r.useEffect)(()=>{C&&!$&&ee()},[$,C,ee]);let et=(0,r.useCallback)(e=>{if(h)void 0!==h(e)&&e.preventDefault();else if(e.nativeEvent.clipboardData){e.stopPropagation(),e.preventDefault();let t=V.selection?er({schema:G.getSnapshot().context.schema,editor:V,range:V.selection}):void 0,n=t?{selection:t}:void 0;if(!n){console.warn("Could not find position for copy event");return}G.send({type:"behavior event",behaviorEvent:{type:"clipboard.copy",originEvent:{dataTransfer:e.nativeEvent.clipboardData},position:n},editor:V,nativeEvent:e})}},[h,G,V]),en=(0,r.useCallback)(e=>{if(f)void 0!==f(e)&&e.preventDefault();else if(e.nativeEvent.clipboardData){e.stopPropagation(),e.preventDefault();let t=G.getSnapshot().context.selection,n=t?{selection:t}:void 0;if(!n){console.warn("Could not find position for cut event");return}G.send({type:"behavior event",behaviorEvent:{type:"clipboard.cut",originEvent:{dataTransfer:e.nativeEvent.clipboardData},position:n},editor:V,nativeEvent:e})}},[f,G,V]),eo=(0,r.useCallback)(e=>{let t=H(V.children,G.getSnapshot().context.schema.block.name,eu.get(V)),n=(V.selection?er({schema:G.getSnapshot().context.schema,editor:V,range:V.selection}):null)?.focus.path||[],o=l?.({event:e,value:t,path:n,schemaTypes:Y.schemaTypes});if(o||!V.selection)e.preventDefault(),F.send({type:"loading"}),Promise.resolve(o).then(t=>{if(oA("Custom paste function from client resolved",t),t&&t.insert)t.insert?G.send({type:"behavior event",behaviorEvent:{type:"insert.blocks",blocks:(0,y.Pj)({context:{keyGenerator:G.getSnapshot().context.keyGenerator,schema:G.getSnapshot().context.schema},blocks:t.insert,options:{refreshKeys:!0,validateFields:!0}}),placement:"auto"},editor:V}):console.warn("Your onPaste function returned something unexpected:",t);else{oA("No result from custom paste handler, pasting normally");let t=G.getSnapshot().context.selection,n=t?{selection:t}:void 0;if(!n){console.warn("Could not find position for paste event");return}G.send({type:"behavior event",behaviorEvent:{type:"clipboard.paste",originEvent:{dataTransfer:e.clipboardData},position:n},editor:V,nativeEvent:e})}}).catch(e=>(console.warn(e),e)).finally(()=>{F.send({type:"done loading"})});else if(e.nativeEvent.clipboardData){e.preventDefault(),e.stopPropagation();let t=G.getSnapshot().context.selection,n=t?{selection:t}:void 0;if(!n){console.warn("Could not find position for paste event");return}G.send({type:"behavior event",behaviorEvent:{type:"clipboard.paste",originEvent:{dataTransfer:e.nativeEvent.clipboardData},position:n},editor:V,nativeEvent:e})}oA("No result from custom paste handler, pasting normally")},[G,l,Y,F,V]),ei=(0,r.useCallback)(e=>{i&&i(e),e.isDefaultPrevented()||(F.send({type:"focused",event:e}),!V.selection&&X(V.children,G.getSnapshot().context.schema)&&(p.YR.select(V,p.ML.start(V,[])),V.onChange()))},[G,i,F,V]),ec=(0,r.useCallback)(e=>{if(g&&g(e),e.isDefaultPrevented()||e.isPropagationStopped())return;let t=ea({editorActor:G,slateEditor:V,event:e.nativeEvent});t&&G.send({type:"behavior event",behaviorEvent:{type:"mouse.click",position:t},editor:V,nativeEvent:e})},[g,G,V]),ed=(0,r.useCallback)(e=>{o&&o(e),e.isPropagationStopped()||F.send({type:"blurred",event:e})},[F,o]),ep=(0,r.useCallback)(e=>{a&&a(e)},[a]),eh=(0,r.useCallback)(()=>
7{if(!V.selection)return;let{activeElement:e}=u.F3.findDocumentOrShadowRoot(V);if(U.current!==e)return;let t=u.F3.getWindow(V).getSelection();if(!t||0===t.rangeCount)return;let n=t.getRangeAt(0);try{let e=u.F3.toDOMRange(V,V.selection);(e.startOffset!==n.startOffset||e.endOffset!==n.endOffset)&&(oA("DOM range out of sync, validating selection"),t?.removeAllRanges(),t.addRange(e))}catch{oA("Could not resolve selection, selecting top document"),p.YR.deselect(V),V.children.length>0&&p.YR.select(V,[0,0]),V.onChange()}},[U,V]);(0,r.useEffect)(()=>{if(L){let e=new MutationObserver(eh);return e.observe(L,{attributeOldValue:!1,attributes:!1,characterData:!1,childList:!0,subtree:!0}),()=>{e.disconnect()}}},[eh,L]);let ey=(0,r.useCallback)(t=>{e.onKeyDown&&e.onKeyDown(t),t.isDefaultPrevented()||V.pteWithHotKeys(t),t.isDefaultPrevented()||G.send({type:"behavior event",behaviorEvent:{type:"keyboard.keydown",originEvent:{key:t.key,code:t.code,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey}},editor:V,nativeEvent:t})},[e,G,V]),eg=(0,r.useCallback)(t=>{e.onKeyUp&&e.onKeyUp(t),t.isDefaultPrevented()||G.send({type:"behavior event",behaviorEvent:{type:"keyboard.keyup",originEvent:{key:t.key,code:t.code,altKey:t.altKey,ctrlKey:t.ctrlKey,metaKey:t.metaKey,shiftKey:t.shiftKey}},editor:V,nativeEvent:t})},[e,G,V]),em=(0,r.useMemo)(()=>{if(void 0!==B)return null===B?d:(e,t)=>{B(Y,t)}},[Y,B]);(0,r.useEffect)(()=>{U.current=u.F3.toDOMNode(V,V),z(U.current)},[V,U]),(0,r.useEffect)(()=>{let e=u.F3.getWindow(V),t=()=>{G.send({type:"dragend"})},n=()=>{G.send({type:"drop"})};return e.document.addEventListener("dragend",t),e.document.addEventListener("drop",n),()=>{e.document.removeEventListener("dragend",t),e.document.removeEventListener("drop",n)}},[V,G]);let ek=(0,r.useCallback)(e=>{if(k?.(e),e.isDefaultPrevented()||e.isPropagationStopped())return;let t=ea({editorActor:G,slateEditor:V,event:e.nativeEvent});if(!t){console.warn("Could not find position for dragstart event");return}return G.send({type:"dragstart",origin:t}),G.send({type:"behavior event",behaviorEvent:{type:"drag.dragstart",originEvent:{clientX:e.clientX,clientY:e.clientY,dataTransfer:e.dataTransfer},position:t},editor:V}),!0},[k,G,V]),ev=(0,r.useCallback)(e=>{if(v?.(e),!(e.isDefaultPrevented()||e.isPropagationStopped()||!ea({editorActor:G,slateEditor:V,event:e.nativeEvent})))return G.send({type:"behavior event",behaviorEvent:{type:"drag.drag",originEvent:{dataTransfer:e.dataTransfer}},editor:V}),!0},[v,G,V]),eb=(0,r.useCallback)(e=>{if(b?.(e),!(e.isDefaultPrevented()||e.isPropagationStopped()))return G.send({type:"behavior event",behaviorEvent:{type:"drag.dragend",originEvent:{dataTransfer:e.dataTransfer}},editor:V}),!0},[b,G,V]),ex=(0,r.useCallback)(e=>{if(x?.(e),e.isDefaultPrevented()||e.isPropagationStopped())return;let t=ea({editorActor:G,slateEditor:V,event:e.nativeEvent});if(t)return G.send({type:"behavior event",behaviorEvent:{type:"drag.dragenter",originEvent:{dataTransfer:e.dataTransfer},position:t},editor:V}),!0},[x,G,V]),e_=(0,r.useCallback)(e=>{if(_?.(e),e.isDefaultPrevented()||e.isPropagationStopped())return;let t=ea({editorActor:G,slateEditor:V,event:e.nativeEvent});if(t)return G.send({type:"behavior event",behaviorEvent:{type:"drag.dragover",originEvent:{dataTransfer:e.dataTransfer},dragOrigin:G.getSnapshot().context.internalDrag?.origin,position:t},editor:V,nativeEvent:e}),!0},[_,G,V]),eE=(0,r.useCallback)(e=>{if(E?.(e),e.isDefaultPrevented()||e.isPropagationStopped())return;let t=ea({editorActor:G,slateEditor:V,event:e.nativeEvent});if(!t){console.warn("Could not find position for drop event");return}return G.send({type:"behavior event",behaviorEvent:{type:"drag.drop",originEvent:{dataTransfer:e.dataTransfer},dragOrigin:G.getSnapshot().context.internalDrag?.origin,position:t},editor:V,nativeEvent:e}),!0},[E,G,V]),ew=(0,r.useCallback)(e=>{if(w?.(e),!(e.isDefaultPrevented()||e.isPropagationStopped()||!ea({editorActor:G,slateEditor:V,event:e.nativeEvent})))return G.send({type:"behavior event",behaviorEvent:{type:"drag.dragleave",originEvent:{dataTransfer:e.dataTransfer}},editor:V}),!0},[w,G,V]);return Y?$?null:(0,s.jsx)(u.CX,{...j,"data-read-only":K,autoFocus:!1,className:j.className||"pt-editable",decorate:J,onBlur:ed,onCopy:et,onCut:en,onClick:ec,onDOMBeforeInput:ep,onDragStart:ek,onDrag:ev,onDragEnd:eb,onDragEnter:ex,onDragOver:e_,onDrop:eE,onDragLeave:ew,onFocus:ei,onKeyDown:ey,onKeyUp:eg,onPaste:eo,readOnly:K,renderPlaceholder:void 0,renderElement:q,renderLeaf:Z,renderText:Q,scrollSelectionIntoView:em}):null});
7function oT(e){let t,n,o,a,c,d,p,h,f,y;let g=(0,i.c)(32);g[0]!==e.initialConfig?(t=()=>{let t=os(e.initialConfig),n=new oh({editor:t.editor});return{internalEditor:t,portableTextEditor:n}},g[0]=e.initialConfig,g[1]=t):t=g[1];let{internalEditor:m,portableTextEditor:k}=function(e){let t=r.useRef(null);return t.current||(t.current={constant:e()}),t.current.constant}(t);return g[2]!==m.actors.editorActor||g[3]!==m.actors.mutationActor||g[4]!==m.actors.relayActor||g[5]!==m.actors.syncActor||g[6]!==m.subscriptions?(n=()=>{let e=[];for(let t of m.subscriptions)e.push(t());return m.actors.editorActor.start(),m.actors.mutationActor.start(),m.actors.relayActor.start(),m.actors.syncActor.start(),()=>{for(let t of e)t();eC(m.actors.editorActor),eC(m.actors.mutationActor),eC(m.actors.relayActor),eC(m.actors.syncActor)}},g[2]=m.actors.editorActor,g[3]=m.actors.mutationActor,g[4]=m.actors.relayActor,g[5]=m.actors.syncActor,g[6]=m.subscriptions,g[7]=n):n=g[7],g[8]!==m?(o=[m],g[8]=m,g[9]=o):o=g[9],(0,r.useEffect)(n,o),g[10]!==k.change$?(a=e=>{k.change$.next(e)},g[10]=k.change$,g[11]=a):a=g[11],g[12]!==m.actors.relayActor||g[13]!==a?(c=(0,s.jsx)(od,{relayActor:m.actors.relayActor,onChange:a}),g[12]=m.actors.relayActor,g[13]=a,g[14]=c):c=g[14],g[15]!==k||g[16]!==e.children?(d=(0,s.jsx)(eA.Provider,{value:k,children:e.children}),g[15]=k,g[16]=e.children,g[17]=d):d=g[17],g[18]!==m.editor._internal.slateEditor.initialValue||g[19]!==m.editor._internal.slateEditor.instance||g[20]!==d?(p=(0,s.jsx)(u.mH,{editor:m.editor._internal.slateEditor.instance,initialValue:m.editor._internal.slateEditor.initialValue,children:d}),g[18]=m.editor._internal.slateEditor.initialValue,g[19]=m.editor._internal.slateEditor.instance,g[20]=d,g[21]=p):p=g[21],g[22]!==m.actors.relayActor||g[23]!==p?(h=(0,s.jsx)(oc.Provider,{value:m.actors.relayActor,children:p}),g[22]=m.actors.relayActor,g[23]=p,g[24]=h):h=g[24],g[25]!==m.actors.editorActor||g[26]!==h?(f=(0,s.jsx)(ef.Provider,{value:m.actors.editorActor,children:h}),g[25]=m.actors.editorActor,g[26]=h,g[27]=f):f=g[27],g[28]!==m.editor||g[29]!==c||g[30]!==f?(y=(0,s.jsxs)(l.r.Provider,{value:m.editor,children:[c,f]}),g[28]=m.editor,g[29]=c,g[30]=f,g[31]=y):y=g[31],y}oI.displayName="ForwardRef(PortableTextEditable)";let oC=()=>{let e,t;let n=(0,i.c)(3),o=(0,r.useContext)(ef),[a,l]=(0,r.useState)(null);return n[0]!==o?(e=()=>{let e=o.on("selection",e=>{(0,r.startTransition)(()=>{l(e.selection)})});return()=>{e.unsubscribe()}},t=[o],n[0]=o,n[1]=e,n[2]=t):(e=n[1],t=n[2]),(0,r.useEffect)(e,t),a}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.