1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4313],{15361:(e,t,n)=>{n.d(t,{LF:()=>o_,Og:()=>oi,l0:()=>ek,pq:()=>ow,v$:()=>eT,zz:()=>oE});var o=n(64192),i=n(14232),r=n(17858),a=n(80121),l=n(37876),s=n(24877),c=n(57410),d=n(91805),p=n(82767),h=n(71673),u=n(59620),f=n(3203),y=n(10943),g=n(41946),m=n(63150),k=n(70305),v=n(36463),b=n(44869),x=n(44239),_=n(80662),E=n(1277),w=n(54589),S=n(39413),B=n(98698),A=n(21215),O=n(25437),K=n(23243),T=n(77050),N=n(7344),C=n(74023),j=n(40487),I=n(61312),M=n(27378),D=n(7766),P=n(99342),z=n(87278),$=n(64609),R=n(80330),L=n(27278),V=n(6612),G=n(11565);let U="sanity-pte:";function F(e){let t=`${U}${e}`;return h&&h.enabled(t)?h(t):h(U)}h(U);let W="void-child";function Q(e,t){let n=t[e._key];return n&&g(e,n)?n:(t[e._key]=e,e)}function J(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",p=(e.children||[]).map(e=>{let{_type:t,_key:o,...i}=e;return"span"!==t?(a=!0,Q({_type:t,_key:o,children:[{_key:W,_type:"span",text:"",marks:[]}],value:i,__inline:!0},n)):e});return!(!l&&!s&&!c&&!a&&d.Hg.isElement(e))?(l&&(r.style=t.styles[0].name),Q({_type:o,_key:i,...r,children:p},n)):e}return Q({_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 Q({...s,...o,_key:i,_type:r},n)}return e});return t?Q({...e,children:r,_key:o,_type:i},n):e}let r="value"in e&&e.value;return Q({_key:o,_type:i,..."object"==typeof r?r:{}},n)})}function Y(e,t){return void 0===e||e&&Array.isArray(e)&&0===e.length||e&&Array.isArray(e)&&1===e.length&&d.Hg.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&&d.EY.isText(e[0].children[0])&&"span"===e[0].children[0]._type&&!e[0].children[0].marks?.join("")&&""===e[0].children[0].text}function q({editor:e,_key:t}){let[,n]=Array.from(d.KE.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 Z({editor:e}){if(!e.selection)return[void 0,void 0];try{return d.KE.node(e,e.selection.focus.path.slice(0,1))??[void 0,void 0]}catch{return[void 0,void 0]}}function X({editor:e,point:t}){try{let[n]=d.KE.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 ee({editor:e,point:t}){let[n,o]=X({editor:e,point:t}),i=t.path.at(1);if(!n||!o||void 0===i)return[void 0,void 0];try{let e=d.bP.child(n,i);return e?[e,[...o,i]]:[void 0,void 0]}catch{return[void 0,void 0]}}function et({editor:e}){if(0===e.children.length)return[void 0,void 0];let t=d.KE.end(e,[]).path.at(0);try{return void 0!==t?d.KE.node(e,[t])??[void 0,void 0]:[void 0,void 0]}catch{return[void 0,void 0]}}function en({schema:e,element:t}){return H([t],e.block.name)?.at(0)}function eo({editor:e,schema:t},n){return d.Hg.isElement(n)&&!e.isInline(n)&&(t.block.name===n._type||t.blockObjects.some(e=>e.name===n._type))}function ei({schema:e,editor:t,range:n}){let[o]=X({editor:t,point:n.anchor}),[i]=X({editor:t,point:n.focus});if(!o||!i)return null;let[r]=o._type===e.block.name?ee({editor:t,point:n.anchor}):[void 0,void 0],[a]=i._type===e.block.name?ee({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:d.Q6.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 er({editorActor:e,slateEditor:t,event:n}){if(e.getSnapshot().matches({setup:"setting up"}))return;let o=function({slateEditor:e,event:t}){return u.wE.hasTarget(e,t.target)?u.wE.toSlateNode(e,t.target):void 0}({slateEditor:t,event:n});if(!o)return;
1let i=function({editor:e,schema:t,node:n}){if(d.KE.isEditor(n))return;if(eo({editor:e,schema:t},n))return en({schema:t,element:n});let o=Array.from(d.KE.nodes(e,{mode:"highest",at:[],match:o=>eo({editor:e,schema:t},o)&&o.children.some(e=>e._key===n._key)})).at(0)?.at(0);return d.Hg.isElement(o)?en({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=d.KE.start(e,[]).path.at(0);try{return void 0!==t?d.KE.node(e,[t])??[void 0,void 0]:[void 0,void 0]}catch{return[void 0,void 0]}}({editor:t});if(!o)return;let i=u.wE.toDOMNode(t,o).getBoundingClientRect();if(n.pageY<i.top)return"start";let[r]=et({editor:t});if(!r)return;let a=u.wE.toDOMNode(t,r).getBoundingClientRect();if(n.pageY>a.bottom)return"end";let l=u.wE.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,u.vA)(t.target))return;let i=u.wE.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)return void console.warn("Neither caretPositionFromPoint nor caretRangeFromPoint is supported");n=i.document.caretRangeFromPoint(t.clientX,t.clientY)??void 0}if(n){try{o=u.wE.toSlateRange(e,n,{exactMatch:!1,suppressThrow:!1})}catch{}return o}}(t,n);return o?ei({schema:e,editor:t,range:o}):null}({schema:e.getSnapshot().context.schema,slateEditor:t,event:n});if(i&&r&&!a&&!d.KE.isEditor(o))return{block:r,isEditor:!1,selection:{anchor:(0,f.u3)({context:e.getSnapshot().context,block:{node:i,path:[{_key:i._key}]}}),focus:(0,y.J8)({context:e.getSnapshot().context,block:{node:i,path:[{_key:i._key}]}})}};if(!r||!a)return;let l=(0,f.XE)(a.focus);if(void 0!==l)return(0,y.WV)(a)&&i&&l!==i._key?{block:r,isEditor:!1,selection:{anchor:(0,f.u3)({context:e.getSnapshot().context,block:{node:i,path:[{_key:i._key}]}}),focus:(0,y.J8)({context:e.getSnapshot().context,block:{node:i,path:[{_key:i._key}]}})}}:{block:r,isEditor:d.KE.isEditor(o),selection:a}}function ea(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 el(e){if(!e.context.selection)return null;if((0,y._Q)(e.context.selection.anchor,e.context.selection.focus)){let t=es(e,e.context.selection.anchor,e.context.selection.backward?"forward":"backward");return t?{anchor:t,focus:t}:null}let t=es(e,e.context.selection.anchor,e.context.selection.backward?"forward":"backward"),n=es(e,e.context.selection.focus,e.context.selection.backward?"backward":"forward");return t&&n?{anchor:t,focus:n}:null}
1function es(e,t,n){let o=(0,f.XE)(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,f.zS)(e.context,r))return{path:[i,0],offset:0};let a=(0,f.qX)({path:t.path}),l=a?void 0:(0,f.m4)({context:{schema:e.context.schema,value:[r]},blockOffset:{path:[{_key:o}],offset:t.offset},direction:n});if(!(a=l?(0,f.qX)(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,f.bl)(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,f.bl)(e.context,p)?Math.min(p.text.length,s):s}}let ec=new WeakMap,ed=new WeakMap,ep=new WeakMap,eh=new WeakMap,eu=(0,i.createContext)({});function ef(){let e,t=(0,o.c)(1);return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=(0,l.jsx)("div",{contentEditable:!1,className:"pt-drop-indicator",style:{position:"absolute",width:"100%",height:1,borderBottom:"1px solid currentColor",zIndex:5},children:(0,l.jsx)("span",{})}),t[0]=e):e=t[0],e}function ey(e){let t,n,i=(0,o.c)(4);return i[0]===Symbol.for("react.memo_cache_sentinel")?(t={userSelect:"none"},i[0]=t):t=i[0],i[1]!==e.blockObject._key||i[2]!==e.blockObject._type?(n=(0,l.jsxs)("div",{style:t,children:["[",e.blockObject._type,": ",e.blockObject._key,"]"]}),i[1]=e.blockObject._key,i[2]=e.blockObject._type,i[3]=n):n=i[3],n}function eg(e){let t,n,i=(0,o.c)(4);return i[0]===Symbol.for("react.memo_cache_sentinel")?(t={userSelect:"none"},i[0]=t):t=i[0],i[1]!==e.inlineObject._key||i[2]!==e.inlineObject._type?(n=(0,l.jsxs)("span",{style:t,children:["[",e.inlineObject._type,": ",e.inlineObject._key,"]"]}),i[1]=e.inlineObject._key,i[2]=e.inlineObject._type,i[3]=n):n=i[3],n}function em({eventSelection:e,snapshot:t}){let n=e;if((0,k.Rt)({...t,context:{...t.context,selection:e}}))return n;let o=(0,m.WV)({context:{...t.context,selection:e}}),i=(0,m.hH)({...t,context:{...t.context,selection:e}}),r=(0,m.d2)({...t,context:{...t.context,selection:e}});o&&i&&r&&(n={anchor:(0,f.u3)({context:t.context,block:i}),focus:(0,y.J8)({context:t.context,block:i})});let a=(0,k.wx)(t);if(t.context.selection&&(0,m.gR)(t)&&a.length>1){let o=(0,k.GB)(t),i=(0,k.P$)(t);if(!o||!i)return n;let r=(0,f.u3)({context:t.context,block:o}),a=(0,y.J8)({context:t.context,block:i});(0,k.Q)(e)({...t,context:{...t.context,selection:{anchor:r,focus:a}}})&&(n={anchor:r,focus:a})}return n}let ek=()=>(function(e){let t=ev();return(function(e=16){let t=new Uint8Array(e);return(0,v.A)(t),t})(12).reduce((e,n)=>e+t[n],"").slice(0,e)})(12),ev=(()=>{let e;return()=>{if(e)return e;e=[];for(let t=0;t<256;++t)e[t]=(t+256).toString(16).slice(1);return e}})();function eb(e){return{id:ek(),name:e?.name,reference:e?.reference}}let ex=eb({name:"core"});function e_(e){let t,n,r=(0,o.c)(5),{key:a,onSetDragPositionBlock:l}=e,s=(0,i.useContext)(eu);r[0]!==s||r[1]!==a||r[2]!==l?(t=()=>{let e=function({key:e,onSetDragPositionBlock:t}){return[{behavior:(0,b.Ke)({on:"drag.dragover",guard:({snapshot:t,event:n})=>{let o=(0,m.gU)({...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=em({eventSelection:i.selection,snapshot:t});return!(0,k.wx)({...t,context:{...t.context,selection:r}}).some(t=>t.node._key===e)&&(0,k.iE)({...t,context:{...t.context,selection:r}})},actions:[({event:e})=>[{type:"effect",effect:()=>{t(e.position.block)}}]]}),priority:eb({reference:{priority:ex,importance:"lower"}})},{behavior:(0,b.Ke)({on:"drag.*",guard:({event:e})=>"drag.dragover"!==e.type,actions:[({event:e})=>[{type:"effect",effect:()=>{t(void 0)}},(0,b.sY)(e)]]}),priority:eb({reference:{priority:ex,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],r[0]=s,r[1]=a,r[2]=l,r[3]=t,r[4]=n):(t=r[3],n=r[4]),(0,i.useEffect)(t,n)}function eE(e){let[t,n]=(0,i.useState)(),o=(0,i.useRef)(null),r=(0,p.f7)(),a=(0,p.s1)(e=>r&&null!==e.selection&&d.Q6.isCollapsed(e.selection));e_({key:e.element._key,onSetDragPositionBlock:n});let s=e.legacySchema.blockObjects.find(t=>t.name===e.element._type);s||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,l.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,l.jsx)(ef,{}):null,e.children,(0,l.jsx)("div",{ref:o,contentEditable:!1,draggable:!e.readOnly,children:e.renderBlock&&s?e.renderBlock({children:(0,l.jsx)(ey,{blockObject:c}),editorElementRef:o,focused:a,path:[{_key:e.element._key}],schemaType:s,selected:r,type:s,value:c}):(0,l.jsx)(ey,{blockObject:c})}),"end"===t?(0,l.jsx)(ef,{}):null]})}function ew(e){let t=(0,i.useRef)(null),n=(0,p.RV)(),o=(0,p.f7)(),r=(0,p.s1)(e=>o&&null!==e.selection&&d.Q6.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 s=u.wE.findPath(n,e.element),[c]=X({editor:n,point:{path:s,offset:0}});c||console.error(`Unable to find parent block of inline object ${e.element._key}`);let h={_key:e.element._key,_type:e.element._type,..."value"in e.element&&"object"==typeof e.element.value?e.element.value:{}};return(0,l.jsxs)("span",{...e.attributes,draggable:!e.readOnly,className:"pt-inline-object","data-child-key":h._key,"data-child-name":h._type,"data-child-type":"object",children:[e.children,(0,l.jsx)("span",{ref:t,style:{display:"inline-block"},children:e.renderChild&&c&&a?e.renderChild({annotations:[],children:(0,l.jsx)(eg,{inlineObject:h}),editorElementRef:t,selected:o,focused:r,path:[{_key:c._key},"children",{_key:e.element._key}],schemaType:a,value:h,type:a}):(0,l.jsx)(eg,{inlineObject:h})})]})}function eS(e){let[t,n]=(0,i.useState)(),o=(0,i.useRef)(null),r=(0,p.f7)(),a=(0,p.s1)(e=>r&&null!==e.selection&&d.Q6.isCollapsed(e.selection));e_({key:e.element._key,onSetDragPositionBlock:n});let s=(0,p.s1)(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:r,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:r,value:e.textBlock.listItem,schemaType:t}):console.error(`Unable to find Schema type for text block list item ${e.textBlock.listItem}`)}return(0,l.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!==s?{"data-list-index":s}:{},children:["start"===t?(0,l.jsx)(ef,{}):null,(0,l.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:r,schemaType:e.legacySchema.block,style:e.textBlock.style,type:e.legacySchema.block,value:e.textBlock}):c}),"end"===t?(0,l.jsx)(ef,{}):null]})}function eB(e){let t,n,r,a=(0,o.c)(34),c=(0,i.useContext)(eu),d=(0,s.d4)(c,eO),h=(0,s.d4)(c,eA),u=(0,p.RV)();if("__inline"in e.element&&!0===e.element.__inline){let t;return a[0]!==h||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,l.jsx)(ew,{attributes:e.attributes,element:e.element,legacySchema:h,readOnly:e.readOnly,renderChild:e.renderChild,schema:d,children:e.children}),a[0]=h,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]!==u.blockIndexMap||a[11]!==u.value){let o=u.blockIndexMap.get(e.element._key);t=void 0!==o?u.value.at(o):void 0,n=(0,f.zS)({schema:d},t),a[8]=e.element._key,a[9]=d,a[10]=u.blockIndexMap,a[11]=u.value,a[12]=t,a[13]=n}else t=a[12],n=a[13];if(n){let n;
1return a[14]!==t||a[15]!==h||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,l.jsx)(eS,{attributes:e.attributes,element:e.element,legacySchema:h,readOnly:e.readOnly,renderBlock:e.renderBlock,renderListItem:e.renderListItem,renderStyle:e.renderStyle,spellCheck:e.spellCheck,textBlock:t,children:e.children}),a[14]=t,a[15]=h,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]!==h||a[27]!==e.attributes||a[28]!==e.children||a[29]!==e.element||a[30]!==e.readOnly||a[31]!==e.renderBlock||a[32]!==d?(r=(0,l.jsx)(eE,{attributes:e.attributes,blockObject:t,element:e.element,legacySchema:h,readOnly:e.readOnly,renderBlock:e.renderBlock,schema:d,children:e.children}),a[25]=t,a[26]=h,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]=r):r=a[33],r}function eA(e){return e.context.getLegacySchema()}function eO(e){return e.context.schema}let eK=(0,i.createContext)(null),eT=()=>{let e=(0,i.useContext)(eK);if(!e)throw Error("The `usePortableTextEditor` hook must be used inside the <PortableTextEditor> component's context.");return e},eN=(e,t)=>{t(e);let n=e.getSnapshot().children;n&&Object.values(n).forEach(e=>{eN(e,t)})};function eC(e){let t=[];eN(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 ej={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"}}},eI={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,m.lN)(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,f.rT)({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"}}},eM={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="},eD=new Map;function eP(e,{blockIndexMap:t,listIndexMap:n}){let o;t.clear(),n.clear(),eD.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,f.zS)(e,r)||void 0===r.listItem||void 0===r.level){eD.clear(),o=void 0;continue}if(!o){o={listItem:r.listItem,level:r.level},eD.set(r.level,1),n.set(r._key,1);continue}if(o.listItem!==r.listItem){eD.clear(),o={listItem:r.listItem,level:r.level},eD.set(r.level,1),n.set(r._key,1);continue}if(o.level===r.level){let e=eD.get(r.level)??0;eD.set(r.level,e+1),o={listItem:r.listItem,level:r.level},n.set(r._key,e+1);continue}if(o.level<r.level){eD.set(r.level,1),o={listItem:r.listItem,level:r.level},n.set(r._key,1);continue}if(o.level>r.level){let e=eD.get(r.level)??0;eD.set(r.level,e+1),o={listItem:r.listItem,level:r.level},n.set(r._key,e+1)}}}}function ez(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 e$=({context:e,operation:t})=>{let n={blockIndexMap:t.editor.blockIndexMap,context:{value:t.editor.value,selection:t.editor.selection?ei({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,k.JB)(n),i=(0,k.rm)(n),r=(0,k.N2)(n),[a]=function({editor:e}){if(!e.selection)return[void 0,void 0];try{let[t,n]=d.KE.node(e,e.selection.focus.path);if(e.isTextSpan(t))return[t,n]}catch{}return[void 0,void 0]}({editor:t.editor});if(!a)return void d.gB.insertText(t.editor,t.text);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)))return void d.gB.insertText(t.editor,t.text)}d.gB.insertNodes(t.editor,{_type:a._type,_key:e.keyGenerator(),text:t.text,marks:[...i,...r]}),t.editor.decoratorState={}};function eR(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 eL({editor:e,blockPath:t,spanPath:n}){let o;for(let[i,r]of d.bP.children(e,t,{reverse:!0}))if(e.isTextSpan(i)&&d.wA.isBefore(r,n)){o=i;break}return o}function eV({editor:e,blockPath:t,spanPath:n}){let o;for(let[i,r]of d.bP.children(e,t))if(e.isTextSpan(i)&&d.wA.isAfter(r,n)){o=i;break}return o}function eG(e,t){let n=eU(e)||!1;ec.set(e,!0),t(),ec.set(e,n)}function eU(e){return ec.get(e)}let eF=new WeakMap,eW=new WeakMap;function eQ(e){return eF.get(e)??!1}function eJ(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 eY=F("plugin:withPortableTextMarkModel");function eq(e){let[t,n]=e;return[t,n]}function eZ(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 eX(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 e0(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 e1(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=e9(r,a,{checkLines:!1,deadline:i}),d=e9(l,s,{checkLines:!1,deadline:i});return c.concat(d)}function e2(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=eX(e.slice(n),t.slice(i)),d=e0(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 e3=Object.defineProperty,e8=Object.getOwnPropertySymbols,e6=Object.prototype.hasOwnProperty,e4=Object.prototype.propertyIsEnumerable,e5=(e,t,n)=>t in e?e3(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;function e7(e,t,n){if(null===e||null===t)throw Error("Null input. (diff)");let o=e9(e,t,function(e){let t;var n,o={checkLines:!0,deadline:(n=e.timeout||1,t=1,"u">typeof n&&(t=n<=0?Number.MAX_VALUE:n),Date.now()+1e3*t)},i=e;for(var r in i||(i={}))e6.call(i,r)&&e5(o,r,i[r]);if(e8)for(var r of e8(i))e4.call(i,r)&&e5(o,r,i[r]);return o}(n||{}));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&&tn(e,t,1),function(e){let t=e.charCodeAt(0);return t>=56320&&t<=57343}(i)&&0===n&&tn(e,t,-1)}for(let t=0;t<e.length;t++)0===e[t][1].length&&e.splice(t,1)}(o),o}function e9(e,t,n){let o=e,i=t;if(o===i)return o?[[0,o]]:[];let r=eX(o,i),a=o.substring(0,r);r=e0(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=e2(s,c,Math.ceil(s.length/4)),p=e2(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=e9(e,o,n),s=e9(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=e9(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=>eq(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=tc(t)),t=ts(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=eZ(e,n),i=eZ(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="",h="";for(;s<l.length;){switch(l[s][0]){case 1:d++,h+=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=e9(p,h,{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="",h="";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,h=0,u=0,f=0;for(let y=0;y<r&&!(Date.now()>n);y++){for(let u=-y+p;u<=y-h;u+=2){let f,g=r+u,m=(f=u===-y||u!==y&&l[g-1]<l[g+1]?l[g+1]:l[g-1]+1)-u;for(;f<o&&m<i&&e.charAt(f)===t.charAt(m);)f++,m++;if(l[g]=f,f>o)h+=2;else if(m>i)p+=2;else if(d){let i=r+c-u;if(i>=0&&i<a&&-1!==s[i]&&f>=o-s[i])return e1(e,t,f,m,n)}}for(let p=-y+u;p<=y-f;p+=2){let h,g=r+p,m=(h=p===-y||p!==y&&s[g-1]<s[g+1]?s[g+1]:s[g-1]+1)-p;for(;h<o&&m<i&&e.charAt(o-h-1)===t.charAt(i-m-1);)h++,m++;if(s[g]=h,h>o)f+=2;else if(m>i)u+=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>=(h=o-h))return e1(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=tc(s)}function te(e,t,n){return 1===n?e+t:t+e}function tt(e,t){return 1===t?[e.substring(0,e.length-1),e[e.length-1]]:[e.substring(1),e[0]]}function tn(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}else if(-1===o){null===l&&(l=s);continue}else if(0===o){if(null===a&&null===l){let[o,i]=tt(e[t][1],n);e[t][1]=o,e[s][1]=te(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]=tt(e[a][1],r),[s]=tt(e[l][1],r);e[a][1]=o,e[l][1]=s,e[t][1]=te(e[t][1],i,n);return}let[c,d]=tt(e[t][1],n);e[t][1]=c,null===a?(e.splice(s,0,[1,d]),null!==l&&l>=s&&l++):e[a][1]=te(e[a][1],d,r),null===l?e.splice(s,0,[-1,d]):e[l][1]=te(e[l][1],d,r)}let to=/[^a-zA-Z0-9]/,ti=/\s/,tr=/[\r\n]/,ta=/\n\r?\n$/,tl=/^\r?\n\r?\n/;function ts(e){let t=e.map(e=>eq(e));function n(e,t){if(!e||!t)return 6;let n=e.charAt(e.length-1),o=t.charAt(0),i=n.match(to),r=o.match(to),a=i&&n.match(ti),l=r&&o.match(ti),s=a&&n.match(tr),c=l&&o.match(tr),d=s&&e.match(ta),p=c&&t.match(tl);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=e0(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 tc(e){let t=e.map(e=>eq(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=eX(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=e0(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=tc(t)),t}var td=Object.defineProperty,tp=Object.getOwnPropertySymbols,th=Object.prototype.hasOwnProperty,tu=Object.prototype.propertyIsEnumerable,tf=(e,t,n)=>t in e?td(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ty=(e,t)=>{for(var n in t||(t={}))th.call(t,n)&&tf(e,n,t[n]);if(tp)for(var n of tp(t))tu.call(t,n)&&tf(e,n,t[n]);return e};let tg={threshold:.5,distance:1e3};function tm(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=ty(ty({},tg),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,h=t.length+e.length,u=[];for(let o=0;o<t.length;o++){for(d=0,p=h;d<p;)a(o,n+p)<=l?d=p:h=p,p=Math.floor((h-d)/2+d);h=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|((u[t+1]|u[t])<<1|1)|u[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;u=y}return s}(e,t,i,o):-1}function tk(e){let t=[];for(let n=0;n<e.length;n++)1!==e[n][0]&&(t[n]=e[n][1]);return t.join("")}function tv(e){let t=[];for(let n=0;n<e.length;n++)-1!==e[n][0]&&(t[n]=e[n][1]);return t.join("")}function tb(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 tx(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+=t_(o)}return t}function t_(e){return e<=127?1:e<=2047?2:e<=65535?3:4}function tE(e,t){return{diffs:[],start1:e,start2:t,utf8Start1:e,utf8Start2:t,length1:0,length2:0,utf8Length1:0,utf8Length2:0}}let tw=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;function tS(e){if(!e)return[];let t=[],n=e.split(` 3`),o=0;for(;o<n.length;){let e=n[o].match(tw);if(!e)throw Error(`Invalid patch string: ${n[o]}`);let i=tE(tB(e[1]),tB(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=tB(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=tB(e[4]),i.length2=i.utf8Length2),o++;o<n.length;){let e,t=n[o],r=t.charAt(0);if("@"===r)break;
3if(""===r){o++;continue}try{e=decodeURI(t.slice(1))}catch{throw Error(`Illegal escape in parse: ${t}`)}let a=tx(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 tB(e){return parseInt(e,10)}let tA=new WeakMap;function tO(e){return tA.get(e)?.undoStepId}let tK=F("plugin:withUndoRedo"),tT=new WeakMap,tN=new WeakMap,tC=e=>{let t=tT.get(e);return void 0===t||t},tj=e=>(tN.get(e)||tN.set(e,[]),tN.get(e)||[]);function tI(e,t,n,o,i){let r={...n};if("insert"===t.type&&1===t.path.length){let e=(o||[]).findIndex(e=>g({_key:e._key},t.path[0]));return tK(`Adjusting block path (+${t.items.length}) for '${r.type}' operation and patch '${t.type}'`),[tM(r,t.items.length,e)]}if("unset"===t.type&&1===t.path.length){let e=(i||[]).findIndex(e=>g({_key:e._key},t.path[0]));return"path"in r&&Array.isArray(r.path)&&r.path[0]===e?(tK("Skipping transformation that targeted removed block"),[]):[tM(r,-1,e)]}if("unset"===t.type&&0===t.path.length)return tK(`Adjusting selection for unset everything patch and ${n.type} operation`),[];if("diffMatchPatch"===t.type){var a,l;let n,o=(a=e,"set_selection"===(l=r).type&&a.selection?n=a.children[a.selection.focus.path[0]]:"path"in l&&(n=a.children[l.path[0]]),n);return o&&g({_key:o._key},t.path[0])&&tS(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 tM(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}function tD(e,t){let n=tC(e);tT.set(e,!1),t(),tT.set(e,n)}let tP=({context:e,operation:t})=>{let n,o,i,r=(0,f.fr)({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||d.Q6.isCollapsed(a.selection))return;let l=[],s=d.KE.nodes(a,{at:a.selection,match:e=>a.isTextBlock(e),reverse:d.Q6.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(),p=t.markDefs??[];for(let[e,c]of(void 0===p.find(e=>e._type===r._type&&e._key===s)&&(d.gB.setNodes(a,{markDefs:[...p,{...r,_key:s}]},{at:n}),i=[{_key:t._key},"markDefs",{_key:s}],d.Q6.isBackward(a.selection)?l.unshift(i):l.push(i)),d.gB.setNodes(a,{},{match:d.EY.isText,split:!0}),d.bP.children(a,n))){if(!a.isTextSpan(e)||!d.Q6.includes(a.selection,c))continue;let n=e.marks??[],i=n.filter(e=>p.some(t=>t._key===e&&t._type===r._type));d.gB.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},tz={"annotation.add":tP,"annotation.remove":({operation:e})=>{let t=e.editor;if(t.selection)if(d.Q6.isCollapsed(t.selection)){let[n,o]=d.KE.node(t,t.selection,{depth:1});if(!t.isTextBlock(n))return;let i=(n.markDefs??[]).filter(t=>t._type===e.annotation.name),[r,a]=d.KE.node(t,t.selection,{depth:2});if(!t.isTextSpan(r))return;
3let l=r.marks?.find(e=>i.some(t=>t._key===e));if(!l)return;let s=[];for(let[e,n]of d.bP.children(t,o,{reverse:!0}))if(t.isTextSpan(e)&&d.wA.isBefore(n,a))if(e.marks?.includes(l))s.push([e,n]);else break;let c=[];for(let[e,n]of d.bP.children(t,o))if(t.isTextSpan(e)&&d.wA.isAfter(n,a))if(e.marks?.includes(l))c.push([e,n]);else break;for(let[e,n]of[...s,[r,a],...c])d.gB.setNodes(t,{marks:e.marks?.filter(e=>e!==l)},{at:n})}else for(let[n,o]of(d.gB.setNodes(t,{},{match:e=>t.isTextSpan(e),split:!0,hanging:!0}),d.KE.nodes(t,{at:t.selection,match:e=>t.isTextBlock(e)})))for(let[i,r]of d.bP.children(t,o)){if(!t.isTextSpan(i)||!d.Q6.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&&d.gB.setNodes(t,{marks:l},{at:r})}},"block.set":({context:e,operation:t})=>{let n=el({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=d.KE.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,ep.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,f.rT)({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=J([l],{schemaTypes:e.schema})?.at(0);if(!s)throw Error("Unable to convert block to Slate value");d.gB.setNodes(t.editor,s,{at:n})},"block.unset":({context:e,operation:t})=>{let n=el({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=d.KE.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,ep.get(t.editor)).at(0);if(!i)throw Error(`Unable to parse block at ${JSON.stringify(t.at)}`);if((0,f.zS)(e,i)){let o=t.props.filter(e=>"_type"!==e),r=(0,f.rT)({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;d.gB.setNodes(t.editor,a,{at:n});return}let r=(0,f.rT)({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;d.gB.setNodes(t.editor,{_type:a,_key:l,value:s},{at:n})},"child.set":({context:e,operation:t})=>{let n=el({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=d.KE.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;d.gB.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}if(d.Hg.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];d.gB.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=el({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=d.KE.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}d.gB.setNodes(t.editor,n,{at:r});return}if(d.Hg.isElement(i)){let n="value"in i&&"object"==typeof i.value?i.value:{},o=t.props.map(e=>({type:"unset",path:[e]})),a=(0,j.yl)(n,o);d.gB.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,ep.get(n)),r=t.at?.anchor?(0,f.m4)({context:{...e,value:i},blockOffset:t.at.anchor,direction:"backward"}):void 0,a=t.at?.focus?(0,f.m4)({context:{...e,value:i},blockOffset:t.at.focus,direction:"forward"}):void 0,l=r&&a?{anchor:r,focus:a}:void 0,s=l?el({context:{schema:e.schema,value:t.editor.value,selection:l},blockIndexMap:t.editor.blockIndexMap})??n.selection:n.selection;if(!s)return;let c=ei({schema:e.schema,editor:n,range:s}),p=c?(0,M.e)({context:{...e,value:i},selectionPoint:c.anchor}):void 0,h=c?(0,M.e)({context:{...e,value:i},selectionPoint:c.focus}):void 0;if(!p||!h)throw Error("Unable to find anchor or focus offset");if(d.Q6.isExpanded(s)){d.gB.setNodes(n,{},{at:s,match:d.EY.isText,split:!0,hanging:!0});let i=H(n.children,e.schema.block.name,ep.get(n)),r=(0,I.lv)({context:{...e,value:i},offsets:{anchor:p,focus:h},backward:c?.backward}),a=(0,k.bu)({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=el({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 d.Q6.isRange(l)?[...d.KE.nodes(n,{at:l,match:e=>d.EY.isText(e)})]:[]){let i=[...(Array.isArray(e.marks)?e.marks:[]).filter(e=>e!==o),o];d.gB.setNodes(n,{marks:i},{at:t,match:d.EY.isText,split:!0,hanging:!0})}}else{if(!Array.from(d.KE.nodes(n,{at:s,match:e=>n.isTextSpan(e)}))?.at(0))return;let[e,t]=d.KE.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);d.gB.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(d.Q6.isExpanded(o))d.gB.setNodes(t,{},{match:d.EY.isText,split:!0,hanging:!0}),t.selection&&[...d.KE.nodes(t,{at:t.selection,match:d.EY.isText}
3)].forEach(([e,o])=>{let i=t.children[o[0]];d.Hg.isElement(i)&&i.children.includes(e)&&d.gB.setNodes(t,{marks:(Array.isArray(e.marks)?e.marks:[]).filter(e=>e!==n),_type:"span"},{at:o})});else{let[e,i]=d.KE.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);d.gB.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,f.XE)(t.at.anchor),o=(0,f.XE)(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);if(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?q({editor:t.editor,_key:n}):void 0,c=void 0!==o?q({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]){d.gB.removeNodes(t.editor,{at:[s[0]]}),0===t.editor.children.length&&d.gB.insertNodes(t.editor,ez(e));return}let p=el({context:{schema:e.schema,value:t.editor.value,selection:t.at},blockIndexMap:t.editor.blockIndexMap});if(!p)throw Error(`Failed to get Slate Range for selection ${JSON.stringify(t.at)}`);let h=(0,f.zS)(e,l)&&0===r;t.editor.delete({at:p,reverse:"backward"===t.direction,unit:t.unit,hanging:h})},"history.redo":({operation:e})=>{let t=e.editor,{redos:n}=t.history,o=tj(t);if(n.length>0){let e=n[n.length-1];if(tK("Redoing",e),e.operations.length>0){let n=o.filter(t=>t.time>=e.timestamp),i=e.operations;n.forEach(e=>{i=N(i.map(n=>tI(t,e.patch,n,e.snapshot,e.previousSnapshot)))});try{d.KE.withoutNormalizing(t,()=>{!function(e,t){let n=eJ(e);eW.set(e,!0),t(),eW.set(e,n)}(t,()=>{tD(t,()=>{i.forEach(e=>{t.apply(e)})})})})}catch(e){tK("Could not perform redo step",e),o.splice(0,o.length),d.gB.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=tj(t);if(n.length>0){let e=n[n.length-1];if(tK("Undoing",e),e.operations.length>0){let n=o.filter(t=>t.time>=e.timestamp),i=e.operations;n.forEach(e=>{i=N(i.map(n=>tI(t,e.patch,n,e.snapshot,e.previousSnapshot)))});let r=i.map(d.I.inverse).reverse();try{d.KE.withoutNormalizing(t,()=>{!function(e,t){let n=eQ(e);eF.set(e,!0),t(),eF.set(e,n)}(t,()=>{tD(t,()=>{r.forEach(e=>{t.apply(e)})})})})}catch(e){tK("Could not perform undo step",e),o.splice(0,o.length),d.gB.deselect(t),t.history={undos:[],redos:[]},tT.set(t,!0),eF.set(t,!1),t.onChange();return}t.history.redos.push(e),t.history.undos.pop()}}},"insert.block":({context:e,operation:t})=>{let n=(0,f.rT)({block:t.block,context:e,options:{refreshKeys:!1,validateFields:!0}});if(!n)throw Error(`Failed to parse block ${JSON.stringify(t.block)}`);let o=J([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=d.Q6.start(e.selection);return X({editor:e,point:t})}({editor:o}),[l,s]=function({editor:e}){if(!e.selection)return[void 0,void 0];let t=d.Q6.end(e.selection);return X({editor:e,point:t})}({editor:o});if(o.selection&&r&&a&&l&&s)if("before"===t){let t=o.selection,i=d.Q6.start(t);d.gB.insertNodes(o,[e],{at:[i.path[0]],select:!1}),"start"===n?d.gB.select(o,d.KE.start(o,[i.path[0]])):"end"===n&&d.gB.select(o,d.KE.end(o,[i.path[0]]))}else if("after"===t){let t=o.selection,i=[d.Q6.end(t).path[0]+1];d.gB.insertNodes(o,[e],{at:i,select:!1}),"start"===n?d.gB.select(o,d.KE.start(o,i)):"end"===n&&d.gB.select(o,d.KE.end(o,i))}else{let t=o.selection,r=d.KE.start(o,s);if(d.Q6.isExpanded(t)&&!o.isTextBlock(e)){d.gB.delete(o,{at:t});let r=o.selection,[a,l]=Z({editor:o});d.gB.insertNodes(o,[e],{voids:!0});let s=0===r.anchor.offset?d.Q6.transform(r,{type:"insert_node",node:e,path:[r.anchor.path[0]]}):r;"none"===n&&s&&d.gB.select(o,s),a&&Y([a],i)&&d.gB.removeNodes(o,{at:l});return}if(o.isTextBlock(l)&&o.isTextBlock(e)){let a=d.Q6.start(t);
3if(Y([l],i)){let t=o.selection;d.gB.insertNodes(o,[e],{at:s,select:!1}),d.gB.removeNodes(o,{at:d.wA.next(s)}),"start"===n?d.gB.select(o,a):"end"===n?d.gB.select(o,d.KE.end(o,s)):d.gB.select(o,t);return}if(d.gB.setNodes(o,{markDefs:[...l.markDefs??[],...e.markDefs??[]]},{at:s}),"end"===n)return d.gB.insertFragment(o,[e],{voids:!0});d.gB.insertFragment(o,[e],{at:t,voids:!0}),"start"===n?d.gB.select(o,a):d.bR.equals(a,r)||d.gB.select(o,a)}else if(o.isTextBlock(l)){let r=d.KE.start(o,s),a=d.KE.end(o,s),c=d.Q6.start(t),p=d.Q6.end(t);if(d.Q6.isCollapsed(t)&&d.bR.equals(c,r))d.gB.insertNodes(o,[e],{at:s,select:!1}),("start"===n||"end"===n)&&d.gB.select(o,d.KE.start(o,s)),(0,y.wm)({schema:i},l)&&d.gB.removeNodes(o,{at:d.wA.next(s)});else if(d.Q6.isCollapsed(t)&&d.bR.equals(p,a)){let t=[s[0]+1];d.gB.insertNodes(o,[e],{at:t,select:!1}),("start"===n||"end"===n)&&d.gB.select(o,d.KE.start(o,t))}else if(d.Q6.isExpanded(t)&&d.bR.equals(c,r)&&d.bR.equals(p,a))d.gB.insertFragment(o,[e],{at:t}),"start"===n?d.gB.select(o,d.KE.start(o,s)):"end"===n&&d.gB.select(o,d.KE.end(o,s));else if(d.Q6.isExpanded(t)&&d.bR.equals(c,r))d.gB.insertFragment(o,[e],{at:t}),"start"===n?d.gB.select(o,d.KE.start(o,s)):"end"===n&&d.gB.select(o,d.KE.end(o,s));else if(d.Q6.isExpanded(t)&&d.bR.equals(p,a))d.gB.insertFragment(o,[e],{at:t}),"start"===n?d.gB.select(o,d.KE.start(o,d.wA.next(s))):"end"===n&&d.gB.select(o,d.KE.end(o,d.wA.next(s)));else{let t=o.selection,[i]=function({editor:e}){let[t,n]=Z({editor:e}),o=e.selection?.focus.path.at(1);if(!t||!n||void 0===o)return[void 0,void 0];try{let e=d.bP.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))d.gB.splitNodes(o,{at:t}),d.gB.insertFragment(o,[e],{at:t}),"start"===n||"end"===n?d.gB.select(o,[s[0]+1]):d.gB.select(o,t);else{let i=[s[0]+1];d.gB.insertNodes(o,[e],{at:i,select:!1}),d.gB.select(o,t),"start"===n?d.gB.select(o,d.KE.start(o,i)):"end"===n&&d.gB.select(o,d.KE.end(o,i))}}}else{d.gB.insertNodes(o,[e],{select:!1});let t=[s[0]+1];"start"===n?d.gB.select(o,d.KE.start(o,t)):"end"===n&&d.gB.select(o,d.KE.end(o,t))}}else{"none"!==n&&u.wE.focus(o);let[r,a]=et({editor:o});if("before"===t)d.gB.insertNodes(o,[e],{at:[0]}),"start"===n?d.gB.select(o,d.KE.start(o,[0])):"end"===n&&d.gB.select(o,d.KE.end(o,[0]));else if("after"===t){let t=a?[a[0]+1]:[0];d.gB.insertNodes(o,[e],{at:t}),"start"===n?d.gB.select(o,d.KE.start(o,t)):"end"===n&&d.gB.select(o,d.KE.end(o,t))}else{if(r&&Y([r],i)){d.gB.removeNodes(o,{at:a}),d.gB.insertNodes(o,[e],{at:a,select:!1}),d.gB.deselect(o),"start"===n?d.gB.select(o,d.KE.start(o,a)):"end"===n&&d.gB.select(o,d.KE.end(o,a));return}if(o.isTextBlock(e)&&r&&o.isTextBlock(r)){let t=d.KE.end(o,a);d.gB.insertFragment(o,[e],{at:d.KE.end(o,a)}),"start"===n?d.gB.select(o,t):"none"===n&&d.gB.deselect(o);return}let t=a?[a[0]+1]:[0];d.gB.insertNodes(o,[e],{at:t,select:!1}),"start"===n?d.gB.select(o,d.KE.start(o,t)):"end"===n&&d.gB.select(o,d.KE.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,f.lV)({context:e,inlineObject:{_type:t.inlineObject.name,...t.inlineObject.value??{}},options:{refreshKeys:!1,validateFields:!0}});if(!n)throw Error(`Failed to parse inline object ${JSON.stringify(t.inlineObject)}`);if(!t.editor.selection)return void console.error("Unable to insert inline object without selection");let[o]=Array.from(d.KE.nodes(t.editor,{at:t.editor.selection.focus.path,match:e=>t.editor.isTextBlock(e)})).at(0)??[void 0,void 0];if(!o)return void console.error("Unable to perform action without focus text block");let i=J([{_type:e.schema.block.name,_key:e.keyGenerator(),children:[n]}],{schemaTypes:e.schema}).at(0)?.children.at(0);if(!i)return void console.error("Unable to insert inline object");d.gB.insertNodes(t.editor,i)},"insert.span":({context:e,operation:t})=>{if(!t.editor.selection)return void console.error("Unable to perform action without selection",t);let[n,o]=Array.from(d.KE.nodes(t.editor,{at:t.editor.selection.focus.path,match:e=>t.editor.isTextBlock(e)}))[0]??[void 0,void 0];if(!n||!o)return void console.error("Unable to perform action without focus block",t);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&&d.gB.setNodes(t.editor,{markDefs:[...i,...r]}),d.gB.insertNodes(t.editor,{_type:"span",_key:e.keyGenerator(),text:t.text,marks:[...r?.map(e=>e._key)??[],...t.decorators??[]]})},"insert.text":e$,"move.backward":({operation:e})=>{d.gB.move(e.editor,{unit:"character",distance:e.distance,reverse:!0})},"move.block":({operation:e})=>{let t=(0,f.XE)({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,f.XE)({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");d.gB.moveNodes(e.editor,{at:[n],to:[i],mode:"highest"})},"move.forward":({operation:e})=>{d.gB.move(e.editor,{unit:"character",distance:e.distance})},select:({context:e,operation:t})=>{let n=el({context:{schema:e.schema,value:t.editor.value,selection:t.at},blockIndexMap:t.editor.blockIndexMap});n?d.gB.select(t.editor,n):d.gB.deselect(t.editor)}};function t$({context:e,operation:t}){try{switch(t.type){case"annotation.add":tz["annotation.add"]({context:e,operation:t});break;case"annotation.remove":tz["annotation.remove"]({context:e,operation:t});break;case"block.set":tz["block.set"]({context:e,operation:t});break;case"block.unset":tz["block.unset"]({context:e,operation:t});break;case"child.set":tz["child.set"]({context:e,operation:t});break;case"child.unset":tz["child.unset"]({context:e,operation:t});break;case"decorator.add":tz["decorator.add"]({context:e,operation:t});break;case"decorator.remove":tz["decorator.remove"]({context:e,operation:t});break;case"delete":tz.delete({context:e,operation:t});break;case"history.redo":tz["history.redo"]({context:e,operation:t});break;case"history.undo":tz["history.undo"]({context:e,operation:t});break;case"insert.block":tz["insert.block"]({context:e,operation:t});break;case"insert.inline object":tz["insert.inline object"]({context:e,operation:t});break;case"insert.span":tz["insert.span"]({context:e,operation:t});break;case"insert.text":tz["insert.text"]({context:e,operation:t});break;case"move.backward":tz["move.backward"]({context:e,operation:t});break;case"move.block":tz["move.block"]({context:e,operation:t});break;case"move.forward":tz["move.forward"]({context:e,operation:t});break;default:tz.select({context:e,operation:t})}}catch(e){console.error(Error(`Executing "${t.type}" failed due to: ${e.message}`))}}let tR=new WeakMap;function tL(e,t){tR.set(e,ek()),d.KE.withoutNormalizing(e,t),tR.set(e,void 0)}function tV(e){return void 0!==tR.get(e)}function tG(e,t){let n=-1,o=e.find((e,o)=>{let i=(0,f.wE)(t[0])?e._key===t[0]._key:o===t[0];return i&&(n=o),i});if(o)return{node:o,index:n}}function tU(e,t){let n=e.node;if(!d.Hg.isElement(n)||"children"!==t[1])return;let o=-1,i=n.children.find((e,n)=>{let i=(0,f.wE)(t[2])?e._key===t[2]._key:n===t[2];return i&&(o=n),i});if(i)return{node:i,index:o}}let tF=new WeakMap;function tW(e,t){var n;let o=(n=e,tF.get(n));tF.set(e,!1),t(),tF.set(e,o)}let tQ=F("plugin:withPatches"),tJ=F("plugin:withPlaceholderBlock"),tH=F("plugin:withSchemaTypes");function tY(e){return"object"==typeof e&&null!==e&&!("_type"in e)&&"children"in e&&Array.isArray(e.children)}function tq(e,t){return(0,f.Kk)(t)&&t._type===e.schema.block.name}function tZ(e,t){return"object"==typeof t&&null!==t&&!("children"in t)&&("_type"in t?t._type===e.schema.span.name:"text"in t)}function tX(e){return"object"==typeof e&&null!==e&&"text"in e&&"string"==typeof e.text}function t0(e,t){let n=t.at(0);if(void 0!==n&&1===t.length)return e.children.at(n)}
3function t1(e,t,n){if(0===n.length)return t;if(1===n.length)return t0(t,n);if(2===n.length){let o=t0(t,n.slice(0,1));return o&&tq(e,o)&&o.children.at(n[1])||void 0}}function t2(e,t,n){let o=t1(e,t,n);if(o&&tZ(e,o))return o}function t3(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&&tq(e,r))return r}let t8=F("setup");function t6(e,t){return{getBlockNodes:e=>(function(e,t){if(!t.context.selection)return[];let n=el(t);if(!n)return[];try{return Array.from(d.KE.nodes(e,{at:n,mode:"highest",match:e=>!d.KE.isEditor(e)})).map(([t])=>u.wE.toDOMNode(e,t))}catch{return[]}})(t,e),getChildNodes:e=>(function(e,t){if(!t.context.selection)return[];let n=el(t);if(!n)return[];try{return Array.from(d.KE.nodes(e,{at:n,mode:"lowest",match:e=>!d.KE.isEditor(e)})).map(([t])=>u.wE.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 t4=(0,b.Ke)({on:"annotation.add",guard:({snapshot:e})=>{if(!(0,m.WV)(e))return!1;let t=(0,k.UH)(e);return!!t&&!!(0,m.gR)({context:{...e.context,selection:t}})&&{caretWordSelection:t}},actions:[({event:e},{caretWordSelection:t})=>[(0,b.xl)({type:"select",at:t}),(0,b.xl)({type:"annotation.add",annotation:e.annotation})]]}),t5={arrowDown:(0,R.mn)({default:[{key:"ArrowDown",alt:!1,ctrl:!1,meta:!1,shift:!1}]}),arrowUp:(0,R.mn)({default:[{key:"ArrowUp",alt:!1,ctrl:!1,meta:!1,shift:!1}]}),break:(0,R.mn)({default:[{key:"Enter",shift:!1}]}),lineBreak:(0,R.mn)({default:[{key:"Enter",shift:!0}]}),decorators:{strong:R.Cr,em:R.TN,underline:R.V1,code:R.aY},history:{undo:R.tN,redo:R.ZS},tab:(0,R.mn)({default:[{key:"Tab",alt:!1,ctrl:!1,meta:!1,shift:!1}]}),shiftTab:(0,R.mn)({default:[{key:"Tab",alt:!1,ctrl:!1,meta:!1,shift:!0}]})},t7=(0,b.Ke)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>{if(!t5.arrowDown.guard(t.originEvent)||!(0,m.WV)(e))return!1;let n=(0,k.lA)(e),o=(0,k.RL)(e);return n&&!o},actions:[({snapshot:e})=>[(0,b.xl)({type:"insert.block",block:{_type:e.context.schema.block.name},placement:"after"})]]}),t9=(0,b.Ke)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>{if(!t5.arrowUp.guard(t.originEvent)||!(0,m.WV)(e))return!1;let n=(0,k.lA)(e),o=(0,k.HA)(e);return n&&!o},actions:[({snapshot:e})=>[(0,b.xl)({type:"insert.block",block:{_type:e.context.schema.block.name},placement:"before"})]]}),ne=(0,b.Ke)({on:"insert.break",guard:({snapshot:e})=>{let t=(0,k.lA)(e);return(0,m.WV)(e)&&void 0!==t},actions:[({snapshot:e})=>[(0,b.xl)({type:"insert.block",block:{_type:e.context.schema.block.name},placement:"after"})]]}),nt=(0,b.Ke)({on:"mouse.click",guard:({snapshot:e,event:t})=>{if(e.context.readOnly||e.context.selection&&!(0,m.WV)(e))return!1;let n=(0,k.lA)({...e,context:{...e.context,selection:t.position.selection}}),o=(0,k.HA)({...e,context:{...e.context,selection:t.position.selection}});return t.position.isEditor&&"start"===t.position.block&&n&&!o},actions:[({snapshot:e,event:t})=>[(0,b.xl)({type:"select",at:t.position.selection}),(0,b.xl)({type:"insert.block",block:{_type:e.context.schema.block.name},placement:"before",select:"start"})]]}),nn=(0,b.Ke)({on:"mouse.click",guard:({snapshot:e,event:t})=>{if(e.context.readOnly||e.context.selection&&!(0,m.WV)(e))return!1;let n=(0,k.lA)({...e,context:{...e.context,selection:t.position.selection}}),o=(0,k.RL)({...e,context:{...e.context,selection:t.position.selection}});return t.position.isEditor&&"end"===t.position.block&&n&&!o},actions:[({snapshot:e,event:t})=>[(0,b.xl)({type:"select",at:t.position.selection}),(0,b.xl)({type:"insert.block",block:{_type:e.context.schema.block.name},placement:"after",select:"start"})]]}),no={arrowDownOnLonelyBlockObject:t7,arrowUpOnLonelyBlockObject:t9,breakingBlockObject:ne,clickingAboveLonelyBlockObject:nt,clickingBelowLonelyBlockObject:nn,deletingEmptyTextBlockAfterBlockObject:(0,b.Ke)({on:"delete.backward",guard:({snapshot:e})=>{let t=(0,m.hH)(e),n=(0,m.WV)(e),o=(0,k.HA)(e);return!!t&&!!n&&!!o&&!(!(0,y.wm)(e.context,t.node)||(0,f.zS)(e.context,o.node))&&{focusTextBlock:t,previousBlock:o}},actions:[(e,{focusTextBlock:t,previousBlock:n})=>[(0,b.xl)({type:"delete.block",at:t.path}),(0,b.xl)({type:"select",at:{anchor:{path:n.path,offset:0},focus:{path:n.path,offset:0}}})]]}),deletingEmptyTextBlockBeforeBlockObject:(0,b.Ke)({on:"delete.forward",guard:({snapshot:e})=>{let t=(0,m.hH)(e),n=(0,m.WV)(e),o=(0,k.RL)(e);return!!t&&!!n&&!!o&&!(!(0,y.wm)(e.context,t.node)||(0,f.zS)(e.context,o.node))&&{focusTextBlock:t,nextBlock:o}},actions:[(e,{focusTextBlock:t,nextBlock:n})=>[(0,b.xl)({type:"delete.block",at:t.path}),(0,b.xl)({type:"select",at:{anchor:{path:n.path,offset:0},focus:{path:n.path,offset:0}}})]]})},ni={strongShortcut:(0,b.Ke)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>t5.decorators.strong.guard(t.originEvent)&&e.context.schema.decorators.some(e=>"strong"===e.name),actions:[()=>[(0,b.xl)({type:"decorator.toggle",decorator:"strong"})]]}),emShortcut:(0,b.Ke)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>t5.decorators.em.guard(t.originEvent)&&e.context.schema.decorators.some(e=>"em"===e.name),actions:[()=>[(0,b.xl)({type:"decorator.toggle",decorator:"em"})]]}),underlineShortcut:(0,b.Ke)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>t5.decorators.underline.guard(t.originEvent)&&e.context.schema.decorators.some(e=>"underline"===e.name),actions:[()=>[(0,b.xl)({type:"decorator.toggle",decorator:"underline"})]]}),codeShortcut:(0,b.Ke)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>t5.decorators.code.guard(t.originEvent)&&e.context.schema.decorators.some(e=>
3"code"===e.name),actions:[()=>[(0,b.xl)({type:"decorator.toggle",decorator:"code"})]]})};function nr(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 na=[(0,b.Ke)({on:"drag.dragstart",guard:({snapshot:e,dom:t,event:n})=>{let o=em({snapshot:e,eventSelection:n.position.selection}),i=(0,k.iE)({...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,b.xl)({type:"select",at:n}),(0,b.QZ)(()=>{e.setDragGhost({event:t,ghost:{element:r,x:a,y:l}})}),(0,b.sY)(t)]}{let i=nr(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,b.xl)({type:"select",at:n}),(0,b.QZ)(()=>{e.setDragGhost({event:t,ghost:{element:r,x:a,y:l}})}),(0,b.sY)(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=nr(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,b.xl)({type:"select",at:n}),(0,b.QZ)(()=>{e.setDragGhost({event:t,ghost:{element:r,x:a,y:l}})}),(0,b.sY)(t)]}}]}),(0,b.Ke)({on:"drag.dragover",guard:({snapshot:e,event:t})=>{let n=t.dragOrigin;return!!n&&(0,k.Q)(t.position.selection)({...e,context:{...e.context,selection:n.selection}})},actions:[]}),(0,b.Ke)({on:"drag.drop",guard:({snapshot:e,event:t})=>{let n=t.dragOrigin,o=t.position.selection;return!!n&&(0,k.Q)(o)({...e,context:{...e.context,selection:n.selection}})},actions:[]}),(0,b.Ke)({on:"drag.drop",guard:({event:e})=>void 0!==e.dragOrigin,actions:[({event:e})=>[(0,b.xl)({type:"deserialize",originEvent:e})]]}),(0,b.Ke)({on:"drag.drop",actions:[({event:e})=>[(0,b.xl)({type:"select",at:e.position.selection}),(0,b.xl)({type:"deserialize",originEvent:e})]]}),(0,b.Ke)({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=em({eventSelection:n.selection,snapshot:e}),i=t.originEvent.position.selection,r=!!n&&(0,k.Q)(i)({...e,context:{...e.context,selection:o}}),a=(0,k.iE)({...e,context:{...e.context,selection:o}}),l=(0,k.wx)({...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,b.xl)({type:"select",at:i}),...t?n.map(e=>(0,b.xl)({type:"delete.block",at:e.path})):[(0,b.xl)({type:"delete",at:o.selection})],(0,b.xl)({type:"insert.blocks",blocks:e.data,placement:t?"start"===r.position.block?"before":"end"===r.position.block?"after":"auto":"auto"})]]})],nl=(0,b.Ke)({on:"insert.break",guard:({snapshot:e})=>{let t=(0,m.hH)(e),n=(0,m.WV)(e);if(!e.context.selection||!t||!n)return!1;let o=(0,k.Qm)(t)(e),i=t.node.listItem,r=t.node.level;return!!o&&{focusListItem:i,focusLevel:r}},actions:[({snapshot:e},{focusListItem:t,focusLevel:n})=>[(0,b.xl)({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
3ame},placement:"after"})]]}),ns=(0,b.Ke)({on:"insert.break",guard:({snapshot:e})=>{let t=(0,m.hH)(e),n=(0,m.WV)(e);if(!e.context.selection||!t||!n)return!1;let o=(0,m.d2)(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,k.HX)(t)(e)&&{focusAnnotations:r,focusDecorators:i,focusListItem:a,focusLevel:l}},actions:[({snapshot:e},{focusAnnotations:t,focusDecorators:n,focusListItem:o,focusLevel:i})=>[(0,b.xl)({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"})]]}),nc=(0,b.Ke)({on:"insert.break",guard:({snapshot:e})=>{if(!e.context.selection||!(0,m.gR)(e))return!1;let t=(0,k.W2)(e),n=(0,k.qm)(e);if(!t||!n)return!1;let o=(0,f.u3)({context:e.context,block:t}),i=(0,f.Jo)(e.context.selection),r=(0,y.J8)({context:e.context,block:n}),a=(0,f.aR)(e.context.selection);return!!((0,y._Q)(o,i)&&(0,y._Q)(r,a))&&{selection:e.context.selection}},actions:[(e,{selection:t})=>[(0,b.xl)({type:"delete",at:t})]]}),nd={breakingAtTheEndOfTextBlock:nl,breakingAtTheStartOfTextBlock:ns,breakingEntireDocument:nc,breakingEntireBlocks:(0,b.Ke)({on:"insert.break",guard:({snapshot:e})=>{if(!e.context.selection||!(0,m.gR)(e))return!1;let t=(0,k.wx)(e),n=(0,k.GB)(e),o=(0,k.P$)(e);if(!n||!o)return!1;let i=(0,f.u3)({context:e.context,block:n}),r=(0,f.Jo)(e.context.selection),a=(0,y.J8)({context:e.context,block:o}),l=(0,f.aR)(e.context.selection);return!!((0,y._Q)(r,i)&&(0,y._Q)(l,a))&&{selectedBlocks:t}},actions:[({snapshot:e},{selectedBlocks:t})=>[(0,b.xl)({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,b.xl)({type:"delete.block",at:e.path}))]]}),breakingInlineObject:(0,b.Ke)({on:"insert.break",guard:({snapshot:e})=>{let t=(0,m.WV)(e),n=(0,k.Rt)(e);return t&&n},actions:[()=>[(0,b.xl)({type:"move.forward",distance:1}),(0,b.xl)({type:"split"})]]})},np=(0,b.Ke)({on:"delete.backward",guard:({snapshot:e})=>{let t=(0,m.WV)(e),n=(0,m.hH)(e),o=(0,m.d2)(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,b.xl)({type:"block.unset",props:["listItem","level"],at:t.path})]]}),nh=(0,b.Ke)({on:"delete.backward",guard:({snapshot:e})=>{let t=(0,m.WV)(e),n=(0,m.hH)(e),o=(0,m.d2)(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,b.xl)({type:"block.set",props:{level:n},at:t.path})]]}),nu=(0,b.Ke)({on:"delete.forward",guard:({snapshot:e})=>{let t=(0,k.iL)(e),n=(0,k.RL)(e);return!!t&&!!n&&!!(0,f.zS)(e.context,n.node)&&!!(0,y.wm)(e.context,t.node)&&{focusListBlock:t,nextBlock:n}},actions:[(e,{nextBlock:t})=>[(0,b.xl)({type:"insert.block",block:t.node,placement:"auto",select:"start"}),(0,b.xl)({type:"delete.block",at:t.path})]]}),nf=(0,b.Ke)({on:"delete.backward",guard:({snapshot:e})=>{let t=(0,m.hH)(e),n=(0,k.HA)(e);return!!t&&!!n&&!!(0,f.Eg)(e.context,n.node)&&!!(0,y.wm)(e.context,n.node)&&{focusTextBlock:t,previousBlockEndPoint:(0,y.J8)({context:e.context,block:n})}},actions:[(e,{focusTextBlock:t,previousBlockEndPoint:n})=>[(0,b.xl)({type:"select",at:{anchor:n,focus:n}}),(0,b.xl)({type:"insert.block",block:t.node,placement:"auto",select:"start"}),(0,b.xl)({type:"delete.block",at:t.path})]]}),ny=(0,b.Ke)({on:"insert.break",guard:({snapshot:e})=>{let t=(0,m.WV)(e),n=(0,k.iL)(e);return!!t&&!!n&&!!(0,y.wm)(e.context,n.node)&&{focusListBlock:n}},actions:[(e,{focusListBlock:t})=>[(0,b.xl)({type:"block.unset",props:["listItem","level"],at:t.path})]]}),ng=(0,b.Ke)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>{if(!t5.tab.guard(t.originEvent))return!1;let n=(0,k.wx)(e),o=n.flatMap(t=>(0,f.Eg)(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,b.xl)({type:"block.set",props:{level:Math.min(10,Math.max(1,e.node.level+1))},at:e.path}))]}),nm=(0,b.Ke)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>{if(!t5.shiftTab.guard(t.originEvent))return!1;let n=(0,k.wx)(e),o=n.flatMap(t=>(0,f.Eg)(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,b.xl)({type:"block.set",props:{level:Math.min(10,Math.max(1,e.node.level-1))},at:e.path}))]}),nk=(0,b.Ke)({on:"insert.blocks",guard:({snapshot:e,event:t})=>{let n=(0,k.iL)(e);if(!n)return!1;let o=t.blocks.at(0),i=t.blocks.at(1),r=(0,f.Eg)(e.context,o)?o:(0,f.Eg)(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,b.xl)({...t,blocks:t.blocks.map(t=>(t._key===o._key&&(r=!0),i?r&&i&&(0,f.Eg)(e.context,t)?{...t,level:Math.min(10,Math.max(1,t.level+n))}:(r&&(i=!1),t):t))})]}]}),nv={clearListOnBackspace:np,unindentListOnBackspace:nh,mergeTextIntoListOnDelete:nu,mergeTextIntoListOnBackspace:nf,clearListOnEnter:ny,indentListOnTab:ng,unindentListOnShiftTab:nm,inheritListLevel:nk,inheritListItem:(0,b.Ke)({on:"insert.blocks",guard:({snapshot:e,event:t})=>{let n=(0,k.iL)(e);if(!n||(0,y.wm)(e.context,n.node))return!1;let o=t.blocks.at(0),i=t.blocks.at(1),r=(0,f.Eg)(e.context,o)?o:(0,f.Eg)(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,b.xl)({...t,blocks:t.blocks.map(t=>(t._key===o._key&&(r=!0),i?r&&i&&(0,f.Eg)(e.context,t)?{...t,listItem:t.level===o.level?n:t.listItem}:(r&&(i=!1),t):t))})]}]}),inheritListProperties:(0,b.Ke)({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,k.iL)(e);return!!n&&!!(0,y.wm)(e.context,n.node)&&{level:n.node.level,listItem:n.node.listItem}},actions:[({event:e},{level:t,listItem:n})=>[(0,b.xl)({...e,block:{...e.block,level:t,listItem:n}})]]})},nb=[{addAnnotationOnCollapsedSelection:t4}.addAnnotationOnCollapsedSelection,ni.strongShortcut,ni.emShortcut,ni.underlineShortcut,ni.codeShortcut,...na,no.clickingAboveLonelyBlockObject,no.clickingBelowLonelyBlockObject,no.arrowDownOnLonelyBlockObject,no.arrowUpOnLonelyBlockObject,no.breakingBlockObject,no.deletingEmptyTextBlockAfterBlockObject,no.deletingEmptyTextBlockBeforeBlockObject,nv.clearListOnBackspace,nv.unindentListOnBackspace,nv.mergeTextIntoListOnDelete,nv.mergeTextIntoListOnBackspace,nv.clearListOnEnter,nv.indentListOnTab,nv.unindentListOnShiftTab,nv.inheritListLevel,nv.inheritListItem,nv.inheritListProperties,nd.breakingAtTheEndOfTextBlock,nd.breakingAtTheStartOfTextBlock,nd.breakingEntireDocument,nd.breakingEntireBlocks,nd.breakingInlineObject].map(e=>({behavior:e,priority:ex})),nx=[(0,b.Ke)({on:"annotation.set",guard:({snapshot:e,event:t})=>{let n=t.at[0]._key,o=t.at[2]._key,i=(0,m.hH)({...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,b.xl)({type:"block.set",at:[{_key:t}],props:{markDefs:n}})]]}),(0,b.Ke)({on:"annotation.toggle",guard:({snapshot:e,event:t})=>(0,k.kK)(t.annotation.name)(e),actions:[({event:e})=>[(0,b.xl)({type:"annotation.remove",annotation:e.annotation})]]}),(0,b.Ke)({on:"annotation.toggle",guard:({snapshot:e,event:t})=>!(0,k.kK)(t.annotation.name)(e),actions:[({event:e})=>[(0,b.xl)({type:"annotation.add",annotation:e.annotation})]]})],n_=[(0,b.Ke)({on:"decorator.toggle",guard:({snapshot:e,event:t})=>(0,k.Y1)(t.decorator)(e),actions:[({event:e})=>[(0,b.xl)({type:"decorator.remove",decorator:e.decorator})]]}),(0,b.Ke)({on:"decorator.toggle",guard:({snapshot:e,event:t})=>{let n=t.at?(0,I.lv)({context:e.context,offsets:t.at}):null;return n?!(0,k.Y1)(t.decorator)({...e,context:{...e.context,selection:n}}):!(0,k.Y1)(t.decorator)(e)},actions:[({event:e})=>[(0,b.xl)({...e,type:"decorator.add"})]]})],nE=[(0,b.Ke)({on:"delete.backward",guard:({snapshot:e})=>!!e.context.selection&&{selection:e.context.selection},actions:[({event:e},{selection:t})=>[(0,b.xl)({type:"delete",direction:"backward",unit:e.unit,at:t})]]}),(0,b.Ke)({on:"delete.forward",guard:({snapshot:e})=>!!e.context.selection&&{selection:e.context.selection},actions:[({event:e},{selection:t})=>[(0,b.xl)({type:"delete",direction:"forward",unit:e.unit,at:t})]]}),(0,b.Ke)({on:"delete.block",actions:[({event:e})=>[(0,b.xl)({type:"delete",at:{anchor:{path:e.at,offset:0},focus:{path:e.at,offset:0}}})]]}),(0,b.Ke)({on:"delete.child",guard:({snapshot:e,event:t})=>{let n=(0,m.jR)({...e,context:{...e.context,selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:0}}}});return!!n&&((0,f.bl)(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,b.xl)({type:"delete",at:t})]]}),(0,b.Ke)({on:"delete.text",guard:({snapshot:e,event:t})=>{let n=(0,I.lv)({context:e.context,offsets:t.at});if(!n)return!1;let o=(0,k.bu)({...e,context:{...e.context,value:e.context.value,selection:n}});return!!o&&{selection:o}},actions:[(e,{selection:t})=>[(0,b.xl)({type:"delete",at:t})]]})],nw=[(0,b.Ke)({on:"insert.blocks",guard:({event:e})=>"before"===e.placement,actions:[({event:e})=>e.blocks.map((t,n)=>(0,b.xl)({type:"insert.block",block:t,placement:0===n?"before":"after",select:e.select??"end"}))]}),(0,b.Ke)({on:"insert.blocks",guard:({event:e})=>"after"===e.placement,actions:[({event:e})=>e.blocks.map(t=>(0,b.xl)({type:"insert.block",block:t,placement:"after",select:e.select??"end"}))]}),(0,b.Ke)({on:"insert.blocks",guard:({snapshot:e,event:t})=>{if("auto"!==t.placement)return!1;let n=(0,m.hH)(e);return!!n&&{focusTextBlock:n}},actions:[({snapshot:e,event:t},{focusTextBlock:n})=>1===t.blocks.length?[(0,b.xl)({type:"insert.block",block:t.blocks[0],placement:"auto",select:t.select??"end"})]:(0,y.wm)(e.context,n.node)?t.blocks.map((e,n)=>(0,b.xl)({type:"insert.block",block:e,placement:0===n?"auto":"after",select:t.select??"end"})):t.blocks.flatMap((e,n)=>0===n?[(0,b.xl)({type:"split"}),(0,b.xl)({type:"select.previous block",select:"end"}),(0,b.xl)({type:"insert.block",block:e,placement:"auto",select:t.select??"end"})]:n===t.blocks.length-1?[(0,b.xl)({type:"select.next block",select:"start"}),(0,b.xl)({type:"insert.block",block:e,placement:"auto",select:t.select??"end"})]:[(0,b.xl)({type:"insert.block",block:e,placement:"after",select:t.select??"end"})])]}),(0,b.Ke)({on:"insert.blocks",guard:({event:e})=>"auto"===e.placement,actions:[({event:e})=>e.blocks.map((t,n)=>(0,b.xl)({type:"insert.block",block:t,placement:0===n?"auto":"after",select:e.select??"end"}))]}),(0,b.Ke)({on:"insert.break",actions:[()=>[(0,b.xl)({type:"split"})]]}),(0,b.Ke)({on:"insert.soft break",actions:[()=>[(0,b.xl)({type:"insert.text",text:` 4`})]]})],nS=[(0,b.Ke)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>t5.break.guard(t.originEvent)&&(0,m.WV)(e)&&(0,k.Rt)(e),actions:[()=>[(0,b.xl)({type:"insert.break"})]]}),(0,b.Ke)({on:"keyboard.keydown",guard:({event:e})=>t5.lineBreak.guard(e.originEvent),actions:[()=>[(0,b.xl)({type:"insert.soft break"})]]}),(0,b.Ke)({on:"keyboard.keydown",guard:({event:e})=>t5.history.undo.guard(e.originEvent),actions:[()=>[(0,b.xl)({type:"history.undo"})]]}),(0,b.Ke)({on:"keyboard.keydown",guard:({event:e})=>t5.history.redo.guard(e.originEvent),actions:[()=>[(0,b.xl)({type:"history.redo"})]]})],nB=[(0,b.Ke)({on:"list item.add",guard:({snapshot:e})=>({selectedTextBlocks:(0,k.Lw)(e)}),actions:[({event:e},{selectedTextBlocks:t})=>t.map(t=>(0,b.xl)({type:"block.set",at:t.path,props:{level:1,listItem:e.listItem}}))]}),(0,b.Ke)({on:"list item.remove",guard:({snapshot:e})=>({selectedTextBlocks:(0,k.Lw)(e)}),actions:[(e,{selectedTextBlocks:t})=>t.map(e=>(0,b.xl)({type:"block.unset",at:e.path,props:["level","listItem"]}))]}),(0,b.Ke)({on:"list item.toggle",guard:({snapshot:e,event:t})=>(0,k.oZ)(t.listItem)(e),actions:[({event:e})=>[(0,b.xl)({type:"list item.remove",listItem:e.listItem})]]}),(0,b.Ke)({on:"list item.toggle",guard:({snapshot:e,event:t})=>!(0,k.oZ)(t.listItem)(e),actions:[({event:e})=>[(0,b.xl)({type:"list item.add",listItem:e.listItem})]]})],nA=[(0,b.Ke)({on:"move.block up",guard:({snapshot:e,event:t})=>{let n=(0,k.HA)({...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,b.xl)({type:"move.block",at:e.at,to:t.path})]]}),(0,b.Ke)({on:"move.block down",guard:({snapshot:e,event:t})=>{let n=(0,k.RL)({...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,b.xl)({type:"move.block",at:e.at,to:t.path})]]})],nO=[(0,b.Ke)({on:"select.previous block",guard:({snapshot:e,event:t})=>{let n=(0,k.HA)(e);if(!n)return!1;let o="end"===t.select?(0,y.J8)({context:e.context,block:n}):(0,f.u3)({context:e.context,block:n});return{selection:{anchor:o,focus:o}}},actions:[(e,{selection:t})=>[(0,b.xl)({type:"select",at:t})]]}),(0,b.Ke)({on:"select.next block",guard:({snapshot:e,event:t})=>{let n=(0,k.RL)(e);if(!n)return!1;let o="end"===t.select?(0,y.J8)({context:e.context,block:n}):(0,f.u3)({context:e.context,block:n});return{selection:{anchor:o,focus:o}}},actions:[(e,{selection:t})=>[(0,b.xl)({type:"select",at:t})]]})],nK=[(0,b.Ke)({on:"split",guard:({snapshot:e})=>(0,m.WV)(e)&&(0,k.Rt)(e),actions:[]}),(0,b.Ke)({on:"split",guard:({snapshot:e})=>(0,m.WV)(e)&&(0,k.lA)(e),actions:[]}),(0,b.Ke)({on:"split",guard:({snapshot:e})=>{let t=e.context.selection;if(!t||(0,y.WV)(t))return!1;let n=(0,k.GB)(e),o=(0,k.P$)(e);return!!n&&!!o&&!!(!(0,f.zS)(e.context,n.node)&&(0,f.zS)(e.context,o.node))&&{selection:t}},actions:[(e,{selection:t})=>[(0,b.xl)({type:"delete",at:t})]]}),(0,b.Ke)({on:"split",guard:({snapshot:e})=>{let t=e.context.selection;return!(!t||(0,y.WV)(t))&&{selection:t}},actions:[(e,{selection:t})=>[(0,b.xl)({type:"delete",at:t}),(0,b.xl)({type:"split"})]]}),(0,b.Ke)({on:"split",guard:({snapshot:e})=>{let t=e.context.selection;if(!t||!(0,y.WV)(t))return!1;let n=(0,f.Jo)(t),o=(0,m.hH)(e);if(!o)return!1;let i={anchor:n,focus:(0,y.J8)({context:e.context,block:o})},r=(0,f.rT)({block:(0,M.B)({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,y.WV)(n)?[(0,b.xl)({type:"insert.block",block:t,placement:"after",select:"start"})]:[(0,b.xl)({type:"delete",at:n}),(0,b.xl)({type:"insert.block",block:t,placement:"after",select:"start"})]]})],nT=[(0,b.Ke)({on:"style.add",guard:({snapshot:e})=>({selectedTextBlocks:(0,k.Lw)(e)}),actions:[({event:e},{selectedTextBlocks:t})=>t.map(t=>(0,b.xl)({type:"block.set",at:t.path,props:{style:e.style}}))]}),(0,b.Ke)({on:"style.remove",guard:({snapshot:e})=>({selectedTextBlocks:(0,k.Lw)(e)}),actions:[(e,{selectedTextBlocks:t})=>t.map(e=>(0,b.xl)({type:"block.unset",at:e.path,props:["style"]}))]}),(0,b.Ke)({on:"style.toggle",guard:({snapshot:e,event:t})=>(0,k.ER)(t.style)(e),actions:[({event:e})=>[(0,b.xl)({type:"style.remove",style:e.style})]]}),(0,b.Ke)({on:"style.toggle",guard:({snapshot:e,event:t})=>!(0,k.ER)(t.style)(e),actions:[({event:e})=>[(0,b.xl)({type:"style.add",style:e.style})]]})],nN=(0,b.Ke)({on:"deserialize",guard:({snapshot:e,event:t})=>{let n,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
4("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,b.xl)({...t,originEvent:e.originEvent})]]}),nC=(0,b.Ke)({on:"serialize",guard:({snapshot:e,event:t})=>{if(0===e.context.converters.length)return!1;let n=e.context.converters.map(n=>n.serialize({snapshot:e,event:{...t,originEvent:t.originEvent.type}}));return 0!==n.length&&n},actions:[({event:e},t)=>t.map(t=>(0,b.xl)({...t,originEvent:e.originEvent}))]}),nj=[(0,b.Ke)({on:"clipboard.copy",guard:({snapshot:e})=>{let t=(0,m.d2)(e),n=(0,m.WV)(e);return t&&n},actions:[]}),(0,b.Ke)({on:"clipboard.copy",actions:[({event:e})=>[(0,b.xl)({type:"serialize",originEvent:e})]]}),(0,b.Ke)({on:"clipboard.cut",guard:({snapshot:e})=>{let t=(0,m.d2)(e),n=(0,m.WV)(e);return t&&n},actions:[]}),(0,b.Ke)({on:"clipboard.cut",guard:({snapshot:e})=>!!e.context.selection&&{selection:e.context.selection},actions:[({event:e},{selection:t})=>[(0,b.xl)({type:"serialize",originEvent:e}),(0,b.xl)({type:"delete",at:t})]]}),(0,b.Ke)({on:"drag.dragstart",actions:[({event:e})=>[(0,b.xl)({type:"serialize",originEvent:e})]]}),(0,b.Ke)({on:"serialization.success",actions:[({event:e})=>[{type:"effect",effect:()=>{e.originEvent.originEvent.dataTransfer.setData(e.mimeType,e.data)}}]]}),(0,b.Ke)({on:"serialization.failure",actions:[({event:e})=>[{type:"effect",effect:()=>{console.warn(`Serialization of ${e.mimeType} failed with reason "${e.reason}"`)}}]]}),(0,b.Ke)({on:"deserialization.success",guard:({snapshot:e,event:t})=>{if((0,m.hH)(e)&&"text/plain"===t.mimeType&&"clipboard.paste"===t.originEvent.type){let n=(0,k.rm)(e);return{activeAnnotations:(0,k.Bg)(e),activeDecorators:n,textRuns:t.data.flatMap(t=>(0,f.zS)(e.context,t)?[(0,f.so)(t)]:[])}}return!1},actions:[(e,{activeAnnotations:t,activeDecorators:n,textRuns:o})=>o.flatMap((e,i)=>i!==o.length-1?[(0,b.xl)({type:"insert.span",text:e,decorators:n,annotations:t.map(({_key:e,_type:t,...n})=>({name:t,value:n}))}),(0,b.xl)({type:"insert.break"})]:[(0,b.xl)({type:"insert.span",text:e,decorators:n,annotations:t.map(({_key:e,_type:t,...n})=>({name:t,value:n}))})])]}),(0,b.Ke)({on:"deserialization.success",actions:[({event:e})=>[(0,b.xl)({type:"insert.blocks",blocks:e.data,placement:"auto"})]]}),(0,b.Ke)({on:"deserialization.failure",actions:[({event:e})=>[{type:"effect",effect:()=>{console.warn(`Deserialization of ${e.mimeType} failed with reason "${e.reason}"`)}}]]}),(0,b.Ke)({on:"clipboard.paste",guard:({snapshot:e})=>!!(e.context.selection&&(0,m.gR)(e))&&{selection:e.context.selection},actions:[({event:e},{selection:t})=>[(0,b.xl)({type:"delete",at:t}),(0,b.xl)({type:"deserialize",originEvent:e})]]}),(0,b.Ke)({on:"clipboard.paste",actions:[({event:e})=>[(0,b.xl)({type:"deserialize",originEvent:e})]]}),(0,b.Ke)({on:"input.*",actions:[({event:e})=>[(0,b.xl)({type:"deserialize",originEvent:e})]]}),...nx,...n_,...nE,...nw,...nS,...nB,...nA,...nT,...nO,...nK,nN,nC];function nI(e){return!n$(e)&&!nz(e)&&!nD(e)}let nM=["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 nD(e){return nM.includes(e.type)}let nP=["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 nz(e){return nP.includes(e.type)}function n$(e){return e.type.startsWith("custom.")}let nR=F("behaviors:event");function nL(e){return nz(e)?"native":nD(e)?"synthetic":n$(e)?"custom":"synthetic"}let nV=F("editor machine"),nG=(0,E.mj)({types:{context:{},events:{},emitted:{},input:{},tags:{}},actions:{"add behavior to context":(0,w.a)({behaviors:({context:e,event:t})=>((0,E.DT)(t,"add behavior"),new Set([...e.behaviors,t.behaviorConfig])),behaviorsSorted:!1}),"remove behavior from context":(0,w.a)({behaviors:({context:e,event:t})=>((0,E.DT)(t,"remove behavior"),e.behaviors.delete(t.behaviorConfig),new Set([...e.behaviors]))}),"emit patch event":(0,S.a)(({event:e})=>((0,E.DT)(e,"internal.patch"),e)),"emit mutation event":(0,S.a)(({event:e})=>((0,E.DT)(e,"mutation"),e)),"emit read only":(0,S.a)({type:"read only"}),"emit editable":(0,S.a)({type:"editable"}),"defer event":(0,w.a)({pendingEvents:({context:e,event:t})=>((0,E.DT)(t,["internal.patch","mutation"]),[...e.pendingEvents,t])}),"emit pending events":(0,S.e)(({context:e,enqueue:t})=>{for(let n of e.pendingEvents)t.emit(n)}),"emit ready":(0,S.a)({type:"ready"}),"clear pending events":(0,w.a)({pendingEvents:[]}),"defer incoming patches":(0,w.a)({pendingIncomingPatchesEvents:({context:e,event:t})=>"patches"===t.type?[...e.pendingIncomingPatchesEvents,t]:e.pendingIncomingPatchesEvents}),"emit pending incoming patches":(0,S.e)(({context:e,enqueue:t})=>{for(let n of e.pendingIncomingPatchesEvents)t.emit(n)}),"clear pending incoming patches":(0,w.a)({pendingIncomingPatchesEvents:[]}),"handle blur":({event:e})=>{(0,E.DT)(e,"blur");try{p.rL.blur(e.editor)}catch(e){console.error(Error(`Failed to blur editor: ${e.message}`))}},"handle focus":({context:e})=>
4{if(!e.slateEditor)return void console.error("No Slate editor found to focus");try{let t=e.slateEditor.selection;p.rL.focus(e.slateEditor),t&&d.gB.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,E.DT)(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}){nR(`(${t}:${nL(i)})`,JSON.stringify(i,null,2));let p=[...o,...nj].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&&nI(i)){c?.preventDefault(),tL(r,()=>{nR(`(execute:${nL(i)})`,JSON.stringify(i,null,2)),t$({context:{keyGenerator:a,schema:l},operation:{...i,editor:r}})}),r.onChange();return}let h=s(),u=!1,f=!1,y=-1;for(let t of p){y++;let o=!1;try{o=void 0===t.guard||t.guard({snapshot:h,event:i,dom:t6(d,r)})}catch(e){console.error(Error(`Evaluating guard for "${i.type}" failed due to: ${e.message}`))}if(o){for(let h of(f=!0,t.actions)){let t=s(),f=[];try{f=h({snapshot:t,event:i,dom:t6(d,r)},o)}catch(e){console.error(Error(`Evaluating actions for "${i.type}" failed due to: ${e.message}`))}if(0!==f.length){if(u=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=tA.get(e);if(n)return t();tA.set(e,n??{undoStepId:ek()}),t(),tA.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&&nI(i)?(c?.preventDefault(),tL(r,()=>{nR(`(execute:${nL(i)})`,JSON.stringify(i,null,2)),t$({context:{keyGenerator:a,schema:l},operation:{...i,editor:r}})}),r.onChange()):u&&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?ei({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,w.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);
4for(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(nb),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,w.a)({maxBlocks:({event:e})=>e.maxBlocks})},"update selection":{actions:[(0,w.a)({selection:({event:e})=>e.selection}),(0,S.a)(({event:e})=>({...e,type:"selection"}))]},"set drag ghost":{actions:(0,w.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:[()=>{nV("entry: edit mode->read only->determine initial edit mode")}],exit:[()=>{nV("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:[()=>{nV("entry: edit mode->read only->read only")}],exit:[()=>{nV("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,w.a)({slateEditor:({event:e})=>e.editor})]}},initial:"idle",states:{idle:{entry:[()=>{nV("entry: edit mode->editable->idle")}],exit:[()=>{nV("exit: edit mode->editable-idle")}],on:{dragstart:{actions:[(0,w.a)({internalDrag:({event:e})=>({origin:e.origin})})],target:"dragging internally"}}},focusing:{initial:"checking if busy",states:{"checking if busy":{entry:[()=>{nV("entry: edit mode->editable->focusing->checking if busy")}],exit:[()=>{nV("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:[()=>{nV("entry: edit mode->editable->focusing-busy")}],exit:[()=>{nV("exit: edit mode->editable->focusing->busy")}],after:{10:{target:"checking if busy"}}}}},"dragging internally":{entry:[()=>{nV("entry: edit mode->editable->dragging internally")}],exit:[()=>{nV("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,w.a)({dragGhost:void 0}),(0,w.a)({internalDrag:void 0})],tags:["dragging internally"],on:{dragend:{target:"idle"},drop:{target:"idle"}}}}}}},setup:{initial:"setting up",states:{"setting up":{entry:[()=>{nV("entry: setup->setting up")}],exit:[()=>{nV("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:[()=>{nV("entry: setup->set up->value sync->idle")}],exit:[()=>{nV("exit: setup->set up->value sync->idle")}],on:{patches:{actions:[(0,S.a)(({event:e})=>e)]},"syncing value":{target:"syncing value"}}},"syncing value":{entry:[()=>{nV("entry: setup->set up->value sync->syncing value")}],exit:[()=>{nV("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:[()=>{nV("entry: setup->set up->writing->pristine->idle")}],exit:[()=>{nV("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:[()=>{nV("entry: setup->set up->writing->pristine->normalizing")}],exit:[()=>{nV("exit: setup->set up->writing->pristine->normalizing")}],on:{"done normalizing":{target:"idle"},"internal.patch":{actions:"defer event"},mutation:{actions:"defer event"}}}}},dirty:{entry:[()=>{nV("entry: setup->set up->writing->dirty")},"emit pending events","clear pending events"],exit:[()=>{nV("exit: setup->set up->writing->dirty")}],on:{"internal.patch":{actions:"emit patch event"},mutation:{actions:"emit mutation event"}}}}}}}}}}});function nU(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);
4if(!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 nF=`tmp-${ek()}-image`,nW=`tmp-${ek()}-url`,nQ={image:nF,url:nW},nJ={[nF]:"image",[nW]:"url"},nH={image:"Image",url:"URL"},nY=F("mutation-machine"),nq=(0,E.mj)({types:{context:{},events:{},input:{},emitted:{}},actions:{"assign readOnly":(0,w.a)({readOnly:({context:e,event:t})=>"update readOnly"===t.type?t.readOnly:e.readOnly}),"emit patch":(0,S.a)(({event:e})=>((0,E.DT)(e,"patch"),{type:"patch",patch:e.patch})),"emit has pending mutations":(0,S.a)({type:"has pending mutations"}),"emit mutations":(0,S.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,w.a)({pendingMutations:[]}),"defer mutation":(0,w.a)({pendingMutations:({context:e,event:t})=>{if((0,E.DT)(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,w.a)({pendingPatchEvents:[]}),"defer patch":(0,w.a)({pendingPatchEvents:({context:e,event:t})=>"patch"===t.type?[...e.pendingPatchEvents,t]:e.pendingPatchEvents}),"emit pending patch events":(0,S.e)(({context:e,enqueue:t})=>{for(let n of e.pendingPatchEvents)t.emit(n)})},actors:{"type listener":(0,B.SP)(({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,B.SP)(({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,A.l)({typing:"typing"}),"slate is normalizing":({context:e})=>d.KE.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:[()=>{nY("entry: typing->idle")}],exit:[()=>{nY("exit: typing->idle"),nY("entry: typing->typing")}],on:{typing:{target:"typing"}}},typing:{after:{"type debounce":{target:"idle",actions:[()=>{nY("exit: typing->typing")}]}},on:{"not typing":{target:"idle"},typing:{target:"typing",reenter:!0}}}}},mutations:{initial:"idle",states:{idle:{entry:[()=>{nY("entry: mutations->idle")}],exit:[()=>{nY("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:[()=>{nY("entry: mutations->has pending mutations")},"emit has pending mutations"],exit:[()=>{nY("exit: mutations->has pending mutations")}],invoke:{src:"mutation debouncer"},on:{"mutation delay passed":{guard:(0,A.k)([(0,A.n)("is read-only"),(0,A.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"]}]}}}}}}),nZ=F("API:editable"),nX=(0,E.mj)({types:{context:{},events:{},emitted:{}}}).createMachine({id:"relay",context:{prevSelection:null,lastEventWasFocused:!1},on:{focused:{actions:[(0,w.a)({lastEventWasFocused:!0}),(0,S.a)(({event:e})=>e)]},selection:[{guard:({context:e})=>e.lastEventWasFocused,actions:[(0,w.a)({prevSelection:({event:e})=>e.selection}),(0,S.a)(({event:e})=>e),(0,w.a)({lastEventWasFocused:!1})]},{guard:({context:e,event:t})=>e.prevSelection!==t.selection,actions:[(0,w.a)({prevSelection:({event:e})=>e.selection}),(0,S.a)(({event:e})=>e),(0,w.a)({lastEventWasFocused:!1})]}],"*":{actions:[(0,S.a)(({event:e})=>e),(0,w.a)({lastEventWasFocused:!1})]}}});function n0(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(!G(e))return o={patches:[(0,j.wC)([l])],description:`Block must be an object, got ${String(e)}`,action:"Unset invalid item",item:e,i18n:{description:"inputs.portable-text.invali
4d-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,j.hZ)({...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,j.hZ)({...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,f.zS)({schema:t},{...e,_type:t.block.name})?{patches:[(0,j.hZ)({...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,j.wC)([{_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,j.wC)([{_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,j.hZ)({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,j.Wm)([],[{_key:e._key},"children"]),(0,j.Yr)([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=x(N(e.children.filter(e=>e._type===t.span.name).map(e=>e.marks||[])));if(Array.isArray(e.markDefs)&&e.markDefs.length>0){let t=x(e.markDefs.map(e=>e._key).filter(e=>!a.includes(e)));if(t.length>0)return o={autoResolve:!0,patches:t.map(t=>(0,j.wC)([{_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.invalid-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,j.hZ)((t.marks||[]).filter(e=>
4!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(!G(i))return o={patches:[(0,j.wC)([{_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,j.hZ)(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,j.hZ)({...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
4d-span-text.description",action:"inputs.portable-text.invalid-value.invalid-span-text.action",values:{key:e._key,childKey:i._key}}},!0):(o={patches:[(0,j.wC)([{_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,j.wC)([{_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,j.wC)([])],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 n1=F("sync machine"),n2=(0,B.SP)(({sendBack:e,input:t})=>{n8({context:t.context,sendBack:e,slateEditor:t.slateEditor,value:t.value,streamBlocks:t.streamBlocks})}),n3=(0,E.mj)({types:{context:{},input:{},events:{},emitted:{}},actions:{"assign initial value synced":(0,w.a)({initialValueSynced:!0}),"assign readOnly":(0,w.a)({readOnly:({event:e})=>((0,E.DT)(e,"update readOnly"),e.readOnly)}),"assign pending value":(0,w.a)({pendingValue:({event:e})=>((0,E.DT)(e,"update value"),e.value)}),"clear pending value":(0,w.a)({pendingValue:void 0}),"assign previous value":(0,w.a)({previousValue:({event:e})=>((0,E.DT)(e,"done syncing"),e.value)}),"emit done syncing value":(0,S.a)({type:"done syncing value"}),"emit syncing value":(0,S.a)({type:"syncing value"})},guards:{"initial value synced":({context:e})=>e.initialValueSynced,"is busy":({context:e})=>{let t=!e.readOnly,n=e.isProcessingLocalChanges,o=eU(e.slateEditor)??!1,i=t&&(n||o);return n1("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,E.DT)(t,"done syncing"),e.pendingValue!==t.value),"pending value equals previous value":({context:e})=>g(e.pendingValue,e.previousValue)},actors:{"sync value":n2}}).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,A.r)(({context:e})=>({type:"update value",value:e.initialValue}))],on:{"has pending mutations":{actions:(0,w.a)({isProcessingLocalChanges:!0})},mutation:{actions:(0,w.a)({isProcessingLocalChanges:!1})},"update readOnly":{actions:["assign readOnly"]}},initial:"idle",states:{idle:{entry:[()=>{n1("entry: syncing->idle")}],exit:[()=>{n1("exit: syncing->idle")}],on:{"update value":[{guard:(0,A.k)(["is empty value",(0,A.n)("initial value synced")]),actions:["assign initial value synced","emit done syncing value"]},{guard:(0,A.k)(["is empty array",(0,A.n)("initial value synced")]),actions:["assign initial value synced",(0,S.a)({type:"value changed",value:[]}),"emit done syncing value"]},{guard:(0,A.k)(["is busy","is new value"]),target:"busy",actions:["assign pending value"]},{guard:"is new value",target:"syncing",actions:["assign pending value"]},{guard:(0,A.n)("initial value synced"),actions:[()=>{n1("no new value – setting initial value as synced")},"assign initial value synced","emit done syncing value"]},{actions:[()=>{n1("no new value and initial value already synced")}]}]}},busy:{entry:[()=>{n1("entry: syncing->busy")}],exit:[()=>{n1("exit: syncing->busy")}
4],after:{1e3:[{guard:"is busy",target:".",reenter:!0,actions:[()=>{n1("reenter: syncing->busy")}]},{target:"syncing"}]},on:{"update value":[{guard:"is new value",actions:["assign pending value"]}]}},syncing:{entry:[()=>{n1("entry: syncing->syncing")},"emit syncing value"],exit:[()=>{n1("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,S.a)(({event:e})=>e)]},"invalid value":{actions:[(0,S.a)(({event:e})=>e)]},"value changed":{actions:[(0,S.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 n8({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||(n1("Value is empty"),d.KE.withoutNormalizing(n,()=>{tD(n,()=>{eG(n,()=>{tW(n,()=>{if(r)return;s&&d.gB.deselect(n);let e=n.children.length;n.children.forEach((t,o)=>{d.gB.removeNodes(n,{at:[e-1-o]})}),d.gB.insertNodes(n,n.pteCreateTextBlock({decorators:[]}),{at:[0]}),s&&d.gB.select(n,[0,0])})})})}),a=!0),i&&i.length>0){let s=J(i,{schemaTypes:e.schema});o?await new Promise(o=>{d.KE.withoutNormalizing(n,()=>{eG(n,()=>{tW(n,()=>{if(r)return void o();a=n6({slateEditor:n,slateValueFromProps:s}),(async()=>{for await(let[o,r]of n4({slateValue:s})){let{blockChanged:s,blockValid:c}=n5({context:e,sendBack:t,block:o,index:r,slateEditor:n,value:i});a=s||a,l=l&&c}o()})()})})})}):d.KE.withoutNormalizing(n,()=>{eG(n,()=>{tW(n,()=>{if(r)return;a=n6({slateEditor:n,slateValueFromProps:s});let o=0;for(let r of s){let{blockChanged:s,blockValid:c}=n5({context:e,sendBack:t,block:r,index:o,slateEditor:n,value:i});a=s||a,l=l&&c,o++}})})})}if(!l){n1("Invalid value, returning"),r=!0,t({type:"done syncing",value:i});return}if(a){n1("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&&(d.gB.select(n,{anchor:{path:[0,0],offset:0},focus:{path:[0,0],offset:0}}),n.onChange()),t({type:"value changed",value:i})}else n1("Server value and editor value is equal, no need to sync.");r=!0,t({type:"done syncing",value:i})}function n6({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--)d.gB.removeNodes(e,{at:[n]});n=!0}return n}async function*n4({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 n5({context:e,sendBack:t,block:n,index:o,slateEditor:i,value:r}){let a=!1,l=!0,s=i.children[o],c=s&&!g(n,s);return d.KE.withoutNormalizing(i,()=>{eG(i,()=>{tW(i,()=>{if(c&&l){let c=[r[o]],p=n0(c,e.schema,e.keyGenerator);!p.valid&&p.resolution?.autoResolve&&p.resolution?.patches.length>0&&!e.readOnly&&e.previousValue&&e.previousValue!==r&&(console.warn(`${p.resolution.action} for block with _key '${c[0]._key}'. ${p.resolution?.description}`),p.resolution.patches.forEach(e=>{t({type:"patch",patch:e})})),p.valid||p.resolution?.autoResolve?(s._key===n._key&&s._type===n._type?(n1.enabled&&n1("Updating block",s,n),function(e,t,n,o){if(d.gB.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&&(n1("Removing child"),d.gB.removeNodes(e,{at:[o,r]}))}),t.children.forEach((t,i)=>{let r=n.children[i],a=!g(t,r),l=!g(t.text,r?.text),s=[o,i];if(a)if(t._key===r?._key&&t._type===r?._type){n1("Updating changed child",t,r),d.gB.setNodes(e,t,{at:s});let n=d.EY.isText(t)&&"span"===t._type&&d.EY.isText(r)&&"span"===r._type;n&&l?(r.text.length>0&&d.gB.delete(e,{at:{focus:{path:s,offset:0},anchor:{path:s,offset:r.text.length}}}),d.gB.insertText(e,t.text,{at:s}),e.onChange()):n||(n1("Updating changed inline object child",t),d.gB.setNodes(e,{_key:W},{at:[...s,0],voids:!0}))}else r?(n1("Replacing child",t),d.gB.removeNodes(e,{at:[o,i]}),d.gB.insertNodes(e,t,{at:[o,i]}),e.onChange()):r||(n1("Inserting new child",t),d.gB.insertNodes(e,t,{at:[o,i]}),e.onChange())})}}(i,n,s,o)):(n1.enabled&&n1("Replacing block",s,n),function(e,t,n){let o=e.selection,i=o&&o.focus.path[0]===n;i&&d.gB.deselect(e),d.gB.removeNodes(e,{at:[n]}),d.gB.insertNodes(e,t,{at:[n]}),e.onChange(),i&&d.gB.select(e,o)}(i,n,o)),a=!0):(t({type:"invalid value",resolution:p.resolution,value:r}),l=!1)}if(!s&&l){let a=n0([r[o]],e.schema,e.keyGenerator);
4n1.enabled&&n1("Validating and inserting new block in the end of the value",n),a.valid||a.resolution?.autoResolve?d.gB.insertNodes(i,n,{at:[o]}):(n1("Invalid",a),t({type:"invalid value",resolution:a.resolution,value:r}),l=!1)}})})}),{blockChanged:a,blockValid:l}}let n7=F("setup");function n9(e){n7("Creating new Editor instance");let t=[],n=(0,A.c)(nG,{input:function(e){let{legacySchema:t,schema:n}=function(e){var t;let n=e.schemaDefinition?function(e){let t=e?.blockObjects?.map(e=>(0,L.U8)({type:"object",name:nQ[e.name]??e.name,title:void 0===e.title?nH[e.name]:e.title,fields:e.fields?.map(e=>({name:e.name,type:e.type,title:e.title??V(e.name)}))??[]}))??[],n=e?.inlineObjects?.map(e=>(0,L.U8)({type:"object",name:nQ[e.name]??e.name,title:void 0===e.title?nH[e.name]:e.title,fields:e.fields?.map(e=>({name:e.name,type:e.type,title:e.title??V(e.name)}))??[]}))??[],o=(0,L.MI)({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??V(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??V(e.name),type:e.type}))??[]}))??[]},lists:e?.lists?.map(e=>({value:e.name,title:e.title??V(e.name)}))??[],styles:e?.styles?.map(e=>({value:e.name,title:e.title??V(e.name)}))??[]}]}),i=nU(T.S.compile({types:[o,...t,...n]}).get("portable-text"));return{...i,blockObjects:i.blockObjects.map(e=>void 0!==nJ[e.name]?{...e,name:nJ[e.name],type:{...e.type,name:nJ[e.name]}}:e),inlineObjects:i.inlineObjects.map(e=>void 0!==nJ[e.name]?{...e,name:nJ[e.name]}:e)}}(e.schemaDefinition):nU(e.schema.hasOwnProperty("jsonType")?e.schema:(t=e.schema,T.S.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:[ej,eI,{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,m.lN)(e),o=(0,K.FE)(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,O.l$)(n.data,t.portableText,{keyGenerator:e.context.keyGenerator,unstable_whitespaceOnPasteMode:t.block.options.unstable_whitespaceOnPasteMode}).flatMap(t=>{let n=(0,f.rT)({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,m.lN)(e).map(n=>(0,f.zS)(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(` 5 6`),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=>eM[e]).split(/\n{2,}/).map(e=>e?`<p>${e.replace(/(?:\r\n|\r|\n)/g,"<br/>")}</p>`:"<p></p>").join("")}</body></html>`,i=(0,O.l$)(o,t.portableText,{keyGenerator:e.context.keyGenerator}).flatMap(t=>{let n=(0,f.rT)({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
6serialized"}:{type:"deserialization.success",data:i,mimeType:"text/plain"}}}],getLegacySchema:()=>t,keyGenerator:e.keyGenerator??ek,maxBlocks:e.maxBlocks,readOnly:e.readOnly,schema:n,initialValue:e.initialValue}}(e)}),o=(0,A.c)(nX),i=function(e){t8("Creating new Slate editor instance");let t=((e,t)=>{var n,o,i,r,a;let{editorActor:l,relayActor:s}=t,c=(n=l,function(e){let{apply:t,normalizeNode:o}=e;return e.apply=o=>{if(eU(e)||eQ(e)||eJ(e))return void t(o);if("split_node"===o.type){let i=[...d.bP.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&&!d.KE.isEditor(o.node)){let i=[...d.bP.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(d.Hg.isElement(i)&&i._type===n.getSnapshot().context.schema.block.name){if(!i._key){n.send({type:"normalizing"}),d.gB.setNodes(e,{_key:n.getSnapshot().context.keyGenerator()},{at:r}),n.send({type:"done normalizing"});return}for(let[t,o]of d.bP.children(e,r))if(!t._key){n.send({type:"normalizing"}),d.gB.setNodes(e,{_key:n.getSnapshot().context.keyGenerator()},{at:o}),n.send({type:"done normalizing"});return}}o(t)},e}),p=function({editorActor:e}){return function(t){t.isTextBlock=t=>!d.KE.isEditor(t)&&(0,f.zS)(e.getSnapshot().context,t),t.isTextSpan=t=>!d.KE.isEditor(t)&&(0,f.bl)(e.getSnapshot().context,t),t.isListBlock=t=>!d.KE.isEditor(t)&&(0,f.Eg)(e.getSnapshot().context,t),t.isVoid=t=>!d.KE.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=>!d.KE.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){tH("Setting span type on text node without a type");let n=i._key||e.getSnapshot().context.keyGenerator();e.send({type:"normalizing"}),d.gB.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)){tH("Setting missing key on child node without a key");let n=e.getSnapshot().context.keyGenerator();e.send({type:"normalizing"}),d.gB.setNodes(t,{_key:n},{at:r}),e.send({type:"done normalizing"});return}n(o)},t}}({editorActor:l}),h=function({editorActor:e,relayActor:t,subscriptions:n}){var o;let i,r=(o=e.getSnapshot().context.schema,(e,t)=>{let n=!1;try{switch(t.type){case"insert":n=function(e,t,n){let o=tG(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=J(i,{schemaTypes:n},ed.get(e)),l=o.index,s="after"===r?l+1:l,c=Y(e.children,n);return d.gB.insertNodes(e,a,{at:[s]}),c&&"number"==typeof t.path[0]&&0===t.path[0]&&d.gB.removeNodes(e,{at:["before"===r?l+1:l]}),!0}let{items:i,position:r}=t,a=tU(o,t.path);if(!a)return!1;let l=J([{...o.node,children:i}],{schemaTypes:n},ed.get(e)),s="after"===r?a.index+1:a.index,c=[o.index,s];return l&&d.Hg.isElement(l[0])&&d.gB.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(d.gB.deselect(e),d.bP.children(e,[],{reverse:!0})))d.gB.removeNodes(e,{at:n});return d.gB.insertNodes(e,e.pteCreateTextBlock({decorators:[]})),t&&d.gB.select(e,{anchor:{path:[0,0],offset:0},focus:{path:[0,0],offset:0}}),e.onChange(),!0}let n=tG(e.children,t.path);if(!n)return!1;if(1===t.path.length){if(1===e.children.length){let t=e.selection;return d.gB.deselect(e),d.gB.removeNodes(e,{at:[n.index]}),d.gB.insertNodes(e,e.pteCreateTextBlock({decorators:[]})),t&&d.gB.select(e,{anchor:{path:[0,0],offset:0},focus:{path:[0,0],offset:0}}),e.onChange(),!0}return d.gB.removeNodes(e,{at:[n.index]}),!0}let o=tU(n,t.path);if(e.isTextBlock(n.node)&&o&&"children"===t.path[1]&&3===t.path.length)return d.gB.removeNodes(e,{at:[n.index,o.index]}),!0;if(o&&!d.EY.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,j.yl)(r,[{...t,path:t.path.slice(3)}]);return d.gB.setNodes(e,{...o.node,value:a},{at:[n.index,o.index]}),!0}if(o&&d.EY.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,j.yl)(o.node,[{...t,path:i}])),l=Object.keys(o.node).filter(e=>!a.includes(e));return d.gB.unsetNodes(e,l,{at:[n.index,o.index]}),!0}if(!o&&"value"in n.node){let o=(0,j.yl)(n.node.value,[{...t,path:t.path.slice(1)}]);return d.gB.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=tG(e.children,t.path);if(!o)return!1;let i=e.isTextBlock(o.node);
6if(i&&t.path.length>1&&"children"!==t.path[1])return!1;let r=tU(o,t.path);if(i&&r)if(d.EY.isText(r.node))if(d.EY.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,j.yl)(r.node,[{...t,path:n}]);d.gB.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,j.yl)(i,[{...t,path:t.path.slice(3)}]);d.gB.setNodes(e,{...r.node,value:a},{at:[o.index,r.index]})}else if(d.Hg.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.forEac
6h((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;else{let n=(0,j.yl)(o.node.value,[{...t,path:t.path.slice(1)}]);d.gB.setNodes(e,{...o.node,value:n},{at:[o.index]})}return!0}(e,t);break;case"diffMatchPatch":n=function(e,t){let n=tG(e.children,t.path);if(!n)return!1;let o=tU(n,t.path);if(!o||!(n&&e.isTextBlock(n.node)&&4===t.path.length&&"children"===t.path[1]&&"text"===t.path[3])||!d.EY.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+=t_(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=>eq(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=tE(i-a.length,r-a.length),s=!0;if(""!==a){let e=tx(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=tx(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=tx(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=tv(l.diffs)).substring(a.length-t);let c=tk(o.diffs).substring(0,t),d=tx(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=tk(i[e].diffs),r,l=-1;if(n.length>32?-1!==(r=tm(o,n.substring(0,32),t))&&(-1===(l=tm(o,n.substring(n.length-32),t+n.length-32))||r>=l)&&(r=-1):r=tm(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)+tv(i[e].diffs)+o.substring(r+n.length);else{let t=e7(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=ts(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=tb(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+tb(t,n+s[1].length))),-1!==s[0]&&(n+=s[1].length)}}}}}return[o=o.substring(l.length,o.length-l.length),c]}(tS(t.value),o.node.text,{allowExceedingIndices:!0}),r=function(e,t=4){let n=e.map(e=>eq(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)=>
6e+ +!!t,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=tc(n)),n}(e7(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){ec.set(o,!1),tF.set(o,!0),i=[...o.children];let{apply:a}=o,l=[],s=({patches:e})=>{let t=e.filter(e=>"local"!==e.origin);0!==t.length&&(l=l.concat(t),(()=>{if(0===l.length)return;let e=l;l=[];let t=!1;eG(o,()=>{d.KE.withoutNormalizing(o,()=>{tW(o,()=>{tD(o,()=>{for(let n of e){tQ.enabled&&tQ(`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())})})())};return n.push(()=>{tQ("Subscribing to remote patches");let t=e.on("patches",s);return()=>{tQ("Unsubscribing to remote patches"),t.unsubscribe()}}),o.apply=n=>{let r=[],l=Y(i=o.children,e.getSnapshot().context.schema);a(n);let s=Y(o.children,e.getSnapshot().context.schema);if(!tF.get(o))return o;switch(l&&!s&&"set_selection"!==n.type&&r.push((0,j.Yr)(i,"before",[0])),n.type){case"insert_text":r=[...r,...function(e,t,n,o){let i=(0,f.zS)({schema:e},t[n.path[0]])&&t[n.path[0]];if(!i)throw Error("Could not find block");let r=(0,f.zS)({schema:e},i)&&(0,f.bl)({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,f.zS)({schema:e},l)&&l.children[n.path[1]],c=(0,f.bl)({schema:e},s)?s.text:"",d=(0,j.jo)(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,f.zS)({schema:e},i)&&i.children[n.path[1]]||void 0,a=(0,f.bl)({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,f.zS)({schema:e},s)&&s.children[n.path[1]],d=(0,f.bl)({schema:e},c)&&c.text,p=(0,j.jo)(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,j.wC)([{_key:o._key}])];throw Error("Block not found")}if(!(0,f.zS)({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,j.wC)([{_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,f.zS)({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,f.zS)({schema:e},a)){let o=H([t[n.path[0]+1]],e.block.name)[0];o&&(i.push((0,j.Yr)([o],"after",[{_key:r._key}])),a.children.slice(n.position).forEach(e=>{let t=[{_key:a._key},"children",{_key:e._key}];i.push((0,j.wC)(t))}))}return i}if(2===n.path.length){let t=r.children[n.path[1]];if((0,f.bl)({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,j.Wm)([],[{_key:r._key},"children"])),i.push((0,j.Yr)(o,"after",[{_key:r._key},"children",{_key:t._key}])),i.push((0,j.hZ)(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,j.Yr)([H([n.node],e.block.name)[0]],t,[{_key:a}])]:[(0,j.Wm)(o,[]),(0,j.Yr)([H([n.node],e.block.name)[0]],"before",[n.path[0]])]}if((0,f.zS)({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};
6!o._type&&d.EY.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,j.Wm)([],[{_key:i._key},"children"]),(0,j.Yr)([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=z({...t[n.path[0]],...n.newProperties},P);return[(0,j.hZ)(H([i],e.block.name)[0],[{_key:o._key}])]}if(2===n.path.length){let o=t[n.path[0]];if((0,f.zS)({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=D(n.newProperties,l);r.push((0,j.hZ)(i,[{_key:t},"children",o.children.indexOf(e),l]))}else{let e=D(n.newProperties,l);r.push((0,j.hZ)(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,j.hZ)(o,[{_key:o._key}])),i.push((0,j.wC)([{_key:r._key}]))}else throw Error("Target key not found!");else if((0,f.zS)({schema:e},r)&&(0,f.zS)({schema:e},a)&&2===n.path.length){let t=a.children[n.path[1]-1]&&(0,f.bl)({schema:e},a.children[n.path[1]-1])?a.children[n.path[1]-1]:void 0,o=r.children[n.path[1]]&&(0,f.bl)({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,j.hZ)(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,j.wC)([{_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,j.wC)([{_key:i._key}])),o.push((0,j.Yr)([H([i],e.block.name)[0]],t,[{_key:r._key}]))}else if(2===n.path.length&&(0,f.zS)({schema:e},i)&&(0,f.zS)({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,j.wC)([{_key:i._key},"children",{_key:t._key}])),o.push((0,j.Wm)([],[{_key:r._key},"children"])),o.push((0,j.Yr)([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,j.wC)([])],t.send({type:"unset",previousValue:H(i,e.getSnapshot().context.schema.block.name,ep.get(o))})),l&&r.length>0&&(r=[(0,j.Wm)([],[]),...r]),r.length>0)for(let t of r)e.send({type:"internal.patch",patch:{...t,origin:"local"},operationId:tR.get(o),value:o.value});return o},o}}({editorActor:l,relayActor:s,subscriptions:t.subscriptions}),u=(o=l,function(e){let{apply:t}=e;return e.apply=n=>{if(o.getSnapshot().matches({"edit mode":"read only"})||eU(e)||eQ(e)||eJ(e))return void t(n);let i=o.getSnapshot().context.maxBlocks??-1;i>0&&e.children.length>=i&&("insert_node"===n.type||"split_node"===n.type)&&1===n.path.length||t(n)},e}),y=function(e){let{editorActor:t}=e;return n=>{let o=H(n.children,t.getSnapshot().context.schema.block.name),i=tj(n),r=tO(n);e.subscriptions.push(()=>{tK("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){tK("Someone else cleared the content, resetting undo/redo history"),n.history={undos:[],redos:[]}
6,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()=>{tK("Unsubscribing to patches"),e.unsubscribe()}}),n.history={undos:[],redos:[]};let{apply:a}=n;return n.apply=e=>{let o,i;if(t.getSnapshot().matches({"edit mode":"read only"})||eU(n)||eQ(n)||eJ(n))return void a(e);let{operations:l,history:s}=n,{undos:c}=s,p=c[c.length-1],h=p&&p.operations&&p.operations[p.operations.length-1],u=(o=e,!!((i=h)&&"set_selection"===o.type&&"set_selection"===i.type)),f=tC(n),y=tO(n),g=y===r;if(f){let t,o;if(p?0===l.length&&(g=void 0===y&&void 0===r?(t=e,o=h,!!("set_selection"===t.type||o&&"insert_text"===t.type&&"insert_text"===o.type&&t.offset===o.offset+o.text.length&&d.wA.equals(t.path,o.path)&&" "!==t.text||o&&"remove_text"===t.type&&"remove_text"===o.type&&t.offset+t.text.length===o.offset&&d.wA.equals(t.path,o.path))||u):g):g=!1,p&&g)p.operations.push(e);else{var m;let t={operations:[...null===n.selection?[]:[{type:"set_selection",properties:{...(m=n).selection},newProperties:{...m.selection}}],e],timestamp:new Date};c.push(t),tK("Created new undo step",p)}for(;c.length>1e3;)c.shift();"set_selection"!==e.type&&(s.redos=[])}r=y,a(e)},n}}({editorActor:l,subscriptions:t.subscriptions}),m=(i=l,function(e){let{apply:t,normalizeNode:n}=e,o=i.getSnapshot().context.schema.decorators.map(e=>e.name);return e.normalizeNode=t=>{let[o,r]=t;if(e.isTextBlock(o))for(let[t,n]of d.bP.children(e,r)){let r=o.children[n[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))){eY("Merging spans",JSON.stringify(t,null,2),JSON.stringify(r,null,2)),i.send({type:"normalizing"}),d.gB.mergeNodes(e,{at:[n[0],n[1]+1],voids:!0}),i.send({type:"done normalizing"});return}}if(e.isTextBlock(o)&&!Array.isArray(o.markDefs)){eY("Adding .markDefs to block node"),i.send({type:"normalizing"}),d.gB.setNodes(e,{markDefs:[]},{at:r}),i.send({type:"done normalizing"});return}if(e.isTextSpan(o)&&!Array.isArray(o.marks)){eY("Adding .marks to span node"),i.send({type:"normalizing"}),d.gB.setNodes(e,{marks:[]},{at:r}),i.send({type:"done normalizing"});return}if(e.isTextSpan(o)){let t=d.wA.parent(r),[n]=d.KE.node(e,t),a=i.getSnapshot().context.schema.decorators.map(e=>e.name),l=o.marks?.filter(e=>!a.includes(e));if(e.isTextBlock(n)&&""===o.text&&l&&l.length>0){eY("Removing annotations from empty span node"),i.send({type:"normalizing"}),d.gB.setNodes(e,{marks:o.marks?.filter(e=>a.includes(e))},{at:r}),i.send({type:"done normalizing"});return}}if(e.isTextBlock(o)){let t=i.getSnapshot().context.schema.decorators.map(e=>e.name);for(let[n,a]of d.bP.children(e,r))if(e.isTextSpan(n)){let r=n.marks??[],l=r.filter(e=>!t.includes(e)&&!o.markDefs?.find(t=>t._key===e));if(l.length>0){eY("Removing orphaned annotations from span node"),i.send({type:"normalizing"}),d.gB.setNodes(e,{marks:r.filter(e=>!l.includes(e))},{at:a}),i.send({type:"done normalizing"});return}}}if(e.isTextSpan(o)){let t=d.wA.parent(r),[n]=d.KE.node(e,t);if(e.isTextBlock(n)){let t=i.getSnapshot().context.schema.decorators.map(e=>e.name),a=o.marks??[],l=a.filter(e=>!t.includes(e)&&!n.markDefs?.find(t=>t._key===e));if(l.length>0){eY("Removing orphaned annotations from span node"),i.send({type:"normalizing"}),d.gB.setNodes(e,{marks:a.filter(e=>!l.includes(e))},{at:r}),i.send({type:"done normalizing"});return}}}if(e.isTextBlock(o)){let t=o.markDefs??[],n=new Set,a=[];for(let e of t)n.has(e._key)||(n.add(e._key),a.push(e));if(t.length!==a.length){eY("Removing duplicate markDefs"),i.send({type:"normalizing"}),d.gB.setNodes(e,{markDefs:a},{at:r}),i.send({type:"done normalizing"});return}}if(e.isTextBlock(o)&&!e.operations.some(e=>"merge_node"===e.type&&"markDefs"in e.properties&&1===e.path.length)){let t=(o.markDefs||[]).filter(e=>o.children.find(t=>d.EY.isText(t)&&Array.isArray(t.marks)&&t.marks.includes(e._key)));if(o.markDefs&&!g(t,o.markDefs)){eY("Removing markDef not in use"),i.send({type:"normalizing"}),d.gB.setNodes(e,{markDefs:t},{at:r}),i.send({type:"done normalizing"});return}}n(t)},e.apply=n=>{if(eU(e)||eQ(e)||eJ(e))return void t(n);if("set_selection"===n.type&&n.properties&&n.newProperties&&n.properties.anchor&&n.properties.focus&&n.newProperties.anchor&&n.newProperties.focus){let t=d.Q6.isCollapsed({anchor:n.properties.anchor,focus:n.properties.focus}),o=d.Q6.isCollapsed({anchor:n.newProperties.anchor,focus:n.newProperties.focus});if(t&&o){let t=Array.from(d.KE.nodes(e,{mode:"lowest",at:n.properties.focus,match:t=>e.isTextSpan(t),voids:!1}
6))[0]?.[0],o=Array.from(d.KE.nodes(e,{mode:"lowest",at:n.newProperties.focus,match:t=>e.isTextSpan(t),voids:!1}))[0]?.[0],i=t&&o&&n.newProperties.focus.path[0]===n.properties.focus.path[0]&&n.newProperties.focus.path[1]===n.properties.focus.path[1]+1&&t.text.length===n.properties.focus.offset&&0===n.newProperties.focus.offset,r=t&&o&&n.newProperties.focus.path[0]===n.properties.focus.path[0]&&n.newProperties.focus.path[1]===n.properties.focus.path[1]-1&&0===n.properties.focus.offset&&o.text.length===n.newProperties.focus.offset;i||r||(e.decoratorState={})}}if("insert_node"===n.type){let{selection:t}=e;if(t){let[r,a]=d.KE.node(e,t,{depth:1}),l=eL({editor:e,blockPath:a,spanPath:n.path}),s=l?l.marks?.filter(e=>!o.includes(e)):[],c=eV({editor:e,blockPath:a,spanPath:[n.path[0],n.path[1]-1]}),p=c?c.marks?.filter(e=>!o.includes(e)):[],h=s?.filter(e=>!p?.includes(e))??[],u=h.length>0;if(u&&eR(n.node)&&n.node.marks?.some(e=>h.includes(e)))return void d.gB.insertNodes(e,{...n.node,_key:i.getSnapshot().context.keyGenerator(),marks:n.node.marks?.filter(e=>!h.includes(e))??[]});let f=p?.filter(e=>!s?.includes(e))??[],y=f.length>0;if(y&&eR(n.node)&&n.node.marks?.some(e=>f.includes(e)))return void d.gB.insertNodes(e,{...n.node,_key:i.getSnapshot().context.keyGenerator(),marks:n.node.marks?.filter(e=>!f.includes(e))??[]});let g=c?.marks?.filter(e=>o.includes(e))??[];if(g.length>0&&u&&!y&&eR(n.node)&&n.node.marks?.length===0)return void d.gB.insertNodes(e,{...n.node,_key:i.getSnapshot().context.keyGenerator(),marks:g})}}if("insert_text"===n.type){let o=eH({editorActorSnapshot:i.getSnapshot(),slateEditorInstance:e}),r=(0,k.JB)(o);return r&&"unchanged"!==r.state?void d.gB.insertNodes(e,{_type:"span",_key:i.getSnapshot().context.keyGenerator(),text:n.text,marks:r.marks}):void t(n)}if("remove_text"===n.type){let{selection:a}=e;if(a&&d.Q6.isExpanded(a)){var r;let[l,s]=d.KE.node(e,a,{depth:1}),[c,p]=Array.from(d.KE.nodes(e,{mode:"lowest",at:{path:n.path,offset:n.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??[],h=a.some(e=>r.find(t=>t._key===e)),u=n.offset+n.text.length===c.text.length,f=0===n.offset&&u,y=eL({editor:e,blockPath:s,spanPath:p}),g=eV({editor:e,blockPath:s,spanPath:p}),m=!!y&&y.marks?.some(e=>!o.includes(e)&&a.includes(e)),v=!!g&&g.marks?.some(e=>!o.includes(e)&&a.includes(e));if(h&&f&&!m&&!v){let o=eH({editorActorSnapshot:i.getSnapshot(),slateEditorInstance:e});d.KE.withoutNormalizing(e,()=>{t(n),d.gB.setNodes(e,{marks:(0,k.rm)(o)},{at:n.path})}),e.onChange();return}}}}if("merge_node"===n.type&&1===n.path.length&&"markDefs"in n.properties&&n.properties._type===i.getSnapshot().context.schema.block.name&&Array.isArray(n.properties.markDefs)&&n.properties.markDefs.length>0&&n.path[0]-1>=0){let[o,i]=d.KE.node(e,[n.path[0]-1]);if(e.isTextBlock(o)){let r=x([...Array.isArray(o.markDefs)&&o.markDefs||[],...n.properties.markDefs]);eY("Copying markDefs over to merged block",n),d.gB.setNodes(e,{markDefs:r},{at:i,voids:!1}),t(n);return}}t(n)},e}),v=(r=l,function(e){let{apply:t}=e;return e.apply=n=>{if(r.getSnapshot().matches({"edit mode":"read only"})||eU(e)||eQ(e)||eJ(e))return void t(n);if("remove_node"===n.type){let t=n.path.at(0),o=1===n.path.length&&0===t&&1===e.children.length,i=n.node._type!==r.getSnapshot().context.schema.block.name;o&&i&&(tJ("Adding placeholder block"),d.KE.insertNode(e,e.pteCreateTextBlock({decorators:[]})))}t(n)},e}),b=function({editorActor:e}){return function(t){return t.pteCreateTextBlock=t=>J([{_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:l});return(a=l,function(e){if(void 0!==a.getSnapshot().context.maxBlocks)return e;let{delete:t,select:n}=e;return e.delete=n=>{if(tV(e))return void t(n);let o=n?.at??e.selection;if(!o)return void console.error("Unexpected call to .delete(...) without `at` option");let i=d.KE.range(e,o),r=ei({schema:a.getSnapshot().context.schema,editor:e,range:i});if(!r)return void console.error("Unexpected call to .delete(...) with invali
6d `at` option");a.send({type:"behavior event",behaviorEvent:{type:"delete",at:r,direction:n?.reverse?"backward":"forward",unit:n?.unit},editor:e})},e.deleteBackward=t=>{if(tV(e))return void console.error("Unexpected call to .deleteBackward(...)");a.send({type:"behavior event",behaviorEvent:{type:"delete.backward",unit:t},editor:e})},e.deleteForward=t=>{if(tV(e))return void console.error("Unexpected call to .deleteForward(...)");a.send({type:"behavior event",behaviorEvent:{type:"delete.forward",unit:t},editor:e})},e.insertBreak=()=>{if(tV(e))return void console.error("Unexpected call to .insertBreak(...)");a.send({type:"behavior event",behaviorEvent:{type:"insert.break"},editor:e})},e.insertData=t=>{if(tV(e))return void console.error("Unexpected call to .insertData(...)");a.send({type:"behavior event",behaviorEvent:{type:"input.*",originEvent:{dataTransfer:t}},editor:e})},e.insertSoftBreak=()=>{if(tV(e))return void e$({context:{keyGenerator:a.getSnapshot().context.keyGenerator,schema:a.getSnapshot().context.schema},operation:{text:` 7`,editor:e}});a.send({type:"behavior event",behaviorEvent:{type:"insert.soft break"},editor:e})},e.insertText=t=>{if(tV(e))return void e$({context:{keyGenerator:a.getSnapshot().context.keyGenerator,schema:a.getSnapshot().context.schema},operation:{text:t,editor:e}});a.send({type:"behavior event",behaviorEvent:{type:"insert.text",text:t},editor:e})},e.redo=()=>{if(tV(e))return void t$({context:{keyGenerator:a.getSnapshot().context.keyGenerator,schema:a.getSnapshot().context.schema},operation:{type:"history.redo",editor:e}});a.send({type:"behavior event",behaviorEvent:{type:"history.redo"},editor:e})},e.select=t=>{if(tV(e))return void n(t);let o=d.KE.range(e,t);a.send({type:"behavior event",behaviorEvent:{type:"select",at:ei({schema:a.getSnapshot().context.schema,editor:e,range:o})},editor:e})},e.setFragmentData=()=>{console.error("Unexpected call to .setFragmentData(...)")},e.undo=()=>{if(tV(e))return void t$({context:{keyGenerator:a.getSnapshot().context.keyGenerator,schema:a.getSnapshot().context.schema},operation:{type:"history.undo",editor:e}});a.send({type:"behavior event",behaviorEvent:{type:"history.undo"},editor:e})},e})(p(c(m(v(b(u(y(h(function(e,t){let{apply:n}=t;return t.apply=o=>
7{if("set_selection"===o.type||(t.value=function(e,t,n){let o=(0,$.mq)({children:t});try{!function(e,t,n){switch(n.type){case"insert_node":{let{path:o,node:i}=n,r=t3(e,t,o),a=o[o.length-1];if(!r||a>r.children.length)break;if(1===o.length){if(tq(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(d.Hg.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(!tq(e,r))break;if(tX(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=t2(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=t1(e,t,o),r=t1(e,t,d.wA.previous(o)),a=t3(e,t,o);if(!i||!r||!a)break;let l=o[o.length-1];
7if(tX(i)&&tX(r))r.text+=i.text;else if(tq(e,i)&&tq(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(d.wA.isAncestor(o,i))break;let r=t1(e,t,o),a=t3(e,t,o),l=o[o.length-1];if(!r||!a)break;a.children.splice(l,1);let s=d.wA.transform(o,n),c=t1(e,t,d.wA.parent(s)),p=s[s.length-1];if(!c||!("children"in c)||!Array.isArray(c.children))break;c.children.splice(p,0,r);break}case"remove_node":{let{path:o}=n,i=o[o.length-1];t3(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=t2(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=t1(e,t,o);if(!a||tY(a))break;if(!tY(a)&&!tq(e,a)&&!tZ(e,a)&&!tX(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(tq(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(tX(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=t3(e,t,o),l=o[o.length-1];if(!a)break;if(tY(a)){let n=t0(t,o);if(!n||!tq(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(tq(e,a)){let n=t1(e,t,o);if(!n||!tZ(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,$.vD)(o).children}(e,t.value,o),"insert_text"===o.type||"remove_text"===o.type))return void n(o);eP({schema:e.schema,value:t.value},{blockIndexMap:t.blockIndexMap,listIndexMap:t.listIndexMap}),n(o)},t}(l.getSnapshot().context,function({editor:e,editorActor:t}){let{onChange:n}=e;return e.onChange=()=>{n(),t.getSnapshot().matches({setup:"setting up"})||(()=>{if(e.selection){let n=eh.get(e.selection);if(n)t.send({type:"update selection",selection:n});else{let n=ei({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})})()},e}({editorActor:l,editor:e})))))))))))})((0,p.o$)((0,d.ie)()),{editorActor:e.editorActor,relayActor:e.relayActor,subscriptions:e.subscriptions});ep.set(t,{}),ed.set(t,{}),t.decoratedRanges=[],t.decoratorState={},t.value=[ez(e.editorActor.getSnapshot().context)],t.blockIndexMap=new Map,t.listIndexMap=new Map,eP({schema:e.editorActor.getSnapshot().context.schema,value:t.value},{blockIndexMap:t.blockIndexMap,listIndexMap:t.listIndexMap});let n=J(t.value,{schemaTypes:e.editorActor.getSnapshot().context.schema});return{instance:t,initialValue:n}}({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,k.rm)(o).includes(n)},marks:()=>{let n=eH({editorActorSnapshot:t.getSnapshot(),slateEditorInstance:e});return[...(0,k.N2)(n),...(0,k.rm)(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=>
7{let o=el({context:{schema:t.getSnapshot().context.schema,value:e.value,selection:n},blockIndexMap:e.blockIndexMap});o?d.gB.select(e,o):d.gB.deselect(e),e.onChange()},focusBlock:()=>{if(e.selection){let t=d.bP.descendant(e,e.selection.focus.path.slice(0,1));if(t)return H([t],n.block.name,ep.get(e))[0]}},focusChild:()=>{if(e.selection){let t=d.bP.descendant(e,e.selection.focus.path.slice(0,1));if(t&&e.isTextBlock(t))return H([t],n.block.name,ep.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?ei({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(d.KE.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=J([{_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=d.bP.get(e,l);return s&&c._type!==n.span.name&&(nZ("Inserting span child next to inline object child, moving selection + 1"),e.move({distance:1,unit:"character"})),d.gB.insertNodes(e,a,{select:!0,at:e.selection}),e.onChange(),e.selection?ei({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?ei({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=[...d.KE.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=[...d.KE.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=el({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]=d.KE.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,ep.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(d.KE.nodes(e,{at:[],match:e=>e._key===t._key})||[])[0]||[void 0];n=p.rL.toDOMNode(e,o)}catch{}return n},activeAnnotations:()=>{if(!e.selection||e.selection.focus.path.length<2)return[];try{let t=[];for(let[n,o]of d.KE.nodes(e,{at:e.selection,match:e=>d.EY.isText(e)&&void 0!==e.marks&&Array.isArray(e.marks)&&e.marks.length>0})){let[i]=d.KE.node(e,o,{depth:1});e.isTextBlock(i)&&i.markDefs?.forEach(e=>{d.EY.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,k.kK)(n)(o)},addAnnotation:(o,i)=>{let r;return d.KE.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=el({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"){nZ("Deleting content in selection"),d.gB.delete(e,{at:r,hanging:!0,voids:!0}),e.onChange();return}if(i?.mode==="blocks"&&(nZ("Deleting blocks touched by selection"),d.gB.removeNodes(e,{at:r,voids:!0,match:t=>e.isTextBlock(t)||!e.isTextBlock(t)&&d.Hg.isElement(t)})),i?.mode==="children"&&(nZ("Deleting children touched by selection"),d.gB.removeNodes(e,{at:r,voids:!0,match:t=>t._type===n.span.name||!e.isTextBlock(t)&&d.Hg.isElement(t)})),0===e.children.length){let n=ez(t.getSnapshot().context);e.children=[n],e.value=[n],eP({schema:t.getSnapshot().context.schema,value:e.value},{blockIndexMap:e.blockIndexMap,listIndexMap:e.listIndexMap})}e.onChange()}}},removeAnnotation:n=>
7{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=ei({schema:t.getSnapshot().context.schema,editor:e,range:e.selection}),eh.set(e.selection,n)}return n},getValue:()=>H(e.children,n.block.name,ep.get(e)),isCollapsedSelection:()=>!!e.selection&&d.Q6.isCollapsed(e.selection),isExpandedSelection:()=>!!e.selection&&d.Q6.isExpanded(e.selection),insertBreak:()=>{e.insertBreak(),e.onChange()},getFragment:()=>H(e.getFragment(),n.block.name),isSelectionsOverlapping:(n,o)=>{let i=el({context:{schema:t.getSnapshot().context.schema,value:e.value,selection:n},blockIndexMap:e.blockIndexMap}),r=el({context:{schema:t.getSnapshot().context.schema,value:e.value,selection:o},blockIndexMap:e.blockIndexMap});return d.Q6.isRange(i)&&d.Q6.isRange(r)&&d.Q6.includes(i,r)}}}(i.instance,n),{mutationActor:a,syncActor:l}=function(e){n7("Creating new Actors");let t=(0,A.c)(nq,{input:{readOnly:e.editorActor.getSnapshot().matches({"edit mode":"read only"}),schema:e.editorActor.getSnapshot().context.schema,slateEditor:e.slateEditor}}),n=(0,A.c)(n3,{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,ep.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:t6(e=>n.send(e),i.instance),getSnapshot:()=>eH({editorActorSnapshot:n.getSnapshot(),slateEditorInstance:i.instance}),registerBehavior:e=>{let t=eb({name:"custom",reference:{priority:ex,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"invalid 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 oe=(0,i.createContext)({});function ot(e){let t,n,a,l=(0,o.c)(7);l[0]!==e?(t=t=>e.onChange(t),l[0]=e,l[1]=t):t=l[1];let s=(0,r.J)(t);return l[2]!==s||l[3]!==e.relayActor?(n=()=>{let t=e.relayActor.on("*",e=>
7{let t=on(e);t&&s(t)});return()=>{t.unsubscribe()}},l[2]=s,l[3]=e.relayActor,l[4]=n):n=l[4],l[5]!==e.relayActor?(a=[e.relayActor],l[5]=e.relayActor,l[6]=a):a=l[6],(0,i.useEffect)(n,a),null}function on(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 oo=F("component:PortableTextEditor");class oi extends i.Component{static displayName="PortableTextEditor";change$=new _.B;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}=n9({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=on(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,l.jsxs)(l.Fragment,{children:[e?(0,l.jsx)(or,{editorActor:this.editor._internal.editorActor,patches$:e}):null,(0,l.jsx)(eu.Provider,{value:this.editor._internal.editorActor,children:(0,l.jsx)(oe.Provider,{value:this.actors.relayActor,children:(0,l.jsx)(p.A,{editor:this.editor._internal.slateEditor.instance,initialValue:this.editor._internal.slateEditor.initialValue,children:(0,l.jsx)(eK.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=>{oo("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=>{oo("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)=>e.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)=>
7e.editable?.isMarkActive(t);static insertChild=(e,t,n)=>(oo("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)=>{oo("Host setting selection",t),e.editable?.select(t)};static removeAnnotation=(e,t)=>e.editable?.removeAnnotation(t);static toggleBlockStyle=(e,t)=>(oo("Host is toggling block style"),e.editable?.toggleBlockStyle(t));static toggleList=(e,t)=>e.editable?.toggleList(t);static toggleMark=(e,t)=>{oo("Host toggling mark",t),e.editable?.toggleMark(t)};static getFragment=e=>e.editable?.getFragment();static undo=e=>{oo("Host undoing"),e.editable?.undo()};static redo=e=>{oo("Host redoing"),e.editable?.redo()};static isSelectionsOverlapping=(e,t,n)=>e.editable?.isSelectionsOverlapping(t,n)}function or(e){let t,n,r=(0,o.c)(4);return r[0]!==e.editorActor||r[1]!==e.patches$?(t=()=>{let t=e.patches$.subscribe(t=>{e.editorActor.send({type:"patches",...t})});return()=>{t.unsubscribe()}},n=[e.editorActor,e.patches$],r[0]=e.editorActor,r[1]=e.patches$,r[2]=t,r[3]=n):(t=r[2],n=r[3]),(0,i.useEffect)(t,n),null}function oa(e){let t=(0,p.RV)(),n=(0,i.useContext)(eu),o=(0,s.d4)(n,e=>e.context.getLegacySchema()),r=(0,i.useRef)(null),a=eT(),c=(0,p.f7)(),[d,h]=(0,i.useState)(!1),[u,f]=(0,i.useState)(!1),y=e.children.props.parent,m=y&&t.isTextBlock(y)?y:void 0,k=(0,i.useMemo)(()=>m?[{_key:m._key},"children",{_key:e.leaf._key}]:void 0,[m,e.leaf._key]),v=n.getSnapshot().context.schema.decorators.map(e=>e.name),b=x((e.leaf.marks??[]).filter(e=>v.includes(e))),_=(e.leaf.marks??[]).flatMap(e=>{if(v.includes(e))return[];let t=m?.markDefs?.find(t=>t._key===e);return t?[t]:[]}),E=_.length>0&&c;(0,i.useEffect)(()=>{if(!E)return void h(!1);let e=oi.getSelection(a);e&&g(e.focus.path,k)&&oi.isCollapsedSelection(a)&&(0,i.startTransition)(()=>{h(!0)})},[E,k,a]);let w=(0,i.useCallback)(()=>{if(!E)return;let e=window.getSelection();if(!e)return void f(!1);if(e&&e.rangeCount>0){let t=e.getRangeAt(0);r.current&&t.intersectsNode(r.current)?f(!0):f(!1)}else f(!1)},[E]);(0,i.useEffect)(()=>{if(!E)return;let e=n.on("blurred",()=>{h(!1),f(!1)}),t=n.on("focused",()=>{let e=oi.getSelection(a);e&&g(e.focus.path,k)&&oi.isCollapsedSelection(a)&&h(!0),w()}),o=n.on("selection",e=>{e.selection&&g(e.selection.focus.path,k)&&oi.isCollapsedSelection(a)?h(!0):h(!1),w()});return()=>{e.unsubscribe(),t.unsubscribe(),o.unsubscribe()}},[n,k,a,w,E]),(0,i.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:r,focused:d,path:k,selected:u,schemaType:n,value:t,type:n}))}for(let t of _){let n=o.annotations.find(e=>e.name===t._type);n&&(S=m&&k&&e.renderAnnotation?(0,l.jsx)("span",{ref:r,children:e.renderAnnotation({block:m,children:S,editorElementRef:r,focused:d,path:k,selected:u,schemaType:n,value:t,type:n})}):(0,l.jsx)("span",{ref:r,children:S}))}if(m&&k&&e.renderChild){let t=m.children.find(t=>t._key===e.leaf._key);t&&(S=e.renderChild({annotations:_,children:S,editorElementRef:r,focused:d,path:k,schemaType:o.span,selected:u,value:t,type:o.span}))}return(0,l.jsx)("span",{...e.attributes,ref:r,children:S})}let ol={position:"absolute",userSelect:"none",pointerEvents:"none",left:0,right:0};function os(e){let t,n=(0,o.c)(12),r=(0,i.useContext)(eu),a=(0,s.d4)(r,oc);if(e.leaf._type!==a.span.name)return e.children;n[0]!==e?(t=(0,l.jsx)(oa,{...e}),n[0]=e,n[1]=t):t=n[1];let c=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,l.jsx)("span",{style:ol,contentEditable:!1,children:t}),n[4]=t,n[5]=o):o=n[5],n[6]!==c||n[7]!==o?(i=(0,l.jsxs)(l.Fragment,{children:[o,c]}),n[6]=c,n[7]=o,n[8]=i):i=n[8],i}let d=e.leaf.rangeDecoration;if(d){let e;n[9]!==d||n[10]!==c?(e=d.component({children:c}),n[9]=d,n[10]=c,n[11]=e):e=n[11],c=e}return c}function oc(e){return e.context.schema}function od(e){let t,n=(0,o.c)(5);return n[0]!==e.attributes||n[1]!==e.children||n[2]!==e.text._key||n[3]!==e.text._type?(t=(0,l.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 op="u">typeof window&&/Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent),oh={alt:"altKey",control:"ctrlKey",meta:"metaKey",shift:"shiftKey"},ou={add:"+",break:"pause",cmd:"meta",command:"meta",ctl:"control",ctrl:"control",del:"delete",down:"arrowdown",esc:"escape",ins:"insert",left:"arrowleft",mod:op?"meta":"control",opt:"alt",option:"alt",return:"enter",right:"arrowright",space:" ",spacebar:" ",up:"arrowup",win:"meta",windows:"meta"},of={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 oy(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=om(i),a=oh[r],l=ou[i],s=of[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=om(e);
7return of[t]??t.toUpperCase().charCodeAt(0)}(i)),void 0!==a&&(t[a]=!o||null)}return t}function og(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.keyCode&&void 0!==t.keyCode?91===e.keyCode&&93===t.keyCode||e.keyCode===t.keyCode:e.keyCode===t.keyCode||e.key===t.key.toLowerCase())}function om(e){let t=e.toLowerCase();return ou[t]??t}let ok=F("plugin:withHotKeys"),ov=(0,E.mj)({types:{context:{},input:{},events:{}},actions:{"update pending range decorations":(0,w.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=el({context:{schema:e.schema,value:e.slateEditor.value,selection:n.selection},blockIndexMap:e.slateEditor.blockIndexMap});if(!d.Q6.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=el({context:{schema:e.schema,value:e.slateEditor.value,selection:o.selection},blockIndexMap:e.slateEditor.blockIndexMap});if(!d.Q6.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,r=el({context:{schema:e.schema,value:e.slateEditor.value,selection:o.rangeDecoration.selection},blockIndexMap:e.slateEditor.blockIndexMap});if(!d.Q6.isRange(r)){o.rangeDecoration.onMoved?.({newSelection:null,rangeDecoration:o.rangeDecoration,origin:"local"});continue}if((i=function(e,t){let n=d.bR.transform(e.anchor,t),o=d.bR.transform(e.focus,t);return null===n||null===o?null:d.bR.equals(n,e.anchor)&&d.bR.equals(o,e.focus)?e:{anchor:n,focus:o}}(r,t.operation))&&i!==r||null===i&&r){let t=i?ei({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:ei({schema:e.schema,editor:e.slateEditor,range:i})}})}e.slateEditor.decoratedRanges=n},"assign readOnly":(0,w.a)({readOnly:({context:e,event:t})=>"update read only"!==t.type?e.readOnly:t.readOnly}),"update decorate":(0,w.a)({decorate:({context:e})=>({fn:ob(e.schema,e.slateEditor)})})},actors:{"slate operation listener":(0,B.SP)(({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&&!g(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:ob(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,A.k)(["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,A.k)(["has range decorations","not read only"])}}},"moving range decorations":{entry:["move range decorations"],always:{target:"idle"}}}}}});function ob(e,t){return function([n,o]){if(Y(t.children,e))return[{anchor:{path:[0,0],offset:0},focus:{path:[0,0],offset:0},placeholder:!0}];if(0===o.length||!d.Hg.isElement(n)||0===n.children.length)return[];let i=o.at(0);return void 0===i?[]:t.decoratedRanges.filter(e=>d.Q6.isCollapsed(e)?n.children.some((t,n)=>d.wA.equals(e.anchor.path,[i,n])&&d.wA.equals(e.focus.path,[i,n])):d.Q6.intersection(e,{anchor:{path:o,offset:0},focus:{path:o,offset:0}})||d.Q6.includes(e,o))}}let ox=F("component:Editable"),o_=(0,i.forwardRef)(function(e,t){let{hotkeys:n,onBlur:o,onFocus:r,onBeforeInput:a,onPaste:h,onCopy:u,onCut:y,onClick:m,onDragStart:k,onDrag:v,onDragEnd:b,onDragEnter:x,onDragOver:_,onDrop:E,onDragLeave:w,rangeDecorations:S,renderAnnotation:B,renderBlock:A,renderChild:O,renderDecorator:K,renderListItem:T,renderPlaceholder:N,renderStyle:C,selection:j,scrollSelectionIntoView:I,spellCheck:M,...D}=e,P=eT(),z=(0,i.useRef)(null),[$,R]=(0,i.useState)(null),[L,V]=(0,i.useState)(!1);(0,i.useImperativeHandle)(t,()=>z.current);let G=(0,i.useContext)(eu),U=(0,i.useContext)(oe),F=(0,s.d4)(G,e=>e.matches({"edit mode":"read only"})),W=(0,p.Zi)(),Q=(0,s.qf)(ov,{input:{rangeDecorations:S??[],readOnly:F,schema:G.getSnapshot().context.schema,slateEditor:W,skipSetup:!G.getSnapshot().matches({setup:"setting up"})}}),J=(0,s.d4)(Q,e=>e.context.decorate?.fn);(0,i.useEffect)(()=>{Q.send({type:"update read only",readOnly:F})},[Q,F]),(0,i.useEffect)(()=>{Q.send({type:"range decorations updated",rangeDecorations:S??[]})},[Q,S]),(0,i.useMemo)(()=>F?W:(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,og(oy(t),l)){r.preventDefault();let o=i[a];if(o){let i=o[t];ok(`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,og(oy(e),s)){let n=i[a];n&&(0,n[e])(r,t)}}})},n}})(G,P,n)(W),[G,n,P,F,W]);let q=(0,i.useCallback)(e=>(0,l.jsx)(eB,{...e,readOnly:F,renderBlock:A,renderChild:O,renderListItem:T,renderStyle:C,spellCheck:M}),[M,F,A,O,T,C]),Z=(0,i.useCallback)(e=>(0,l.jsx)(os,{...e,readOnly:F,renderAnnotation:B,renderChild:O,renderDecorator:K,renderPlaceholder:N}),[F,B,O,K,N]),X=(0,i.useCallback)(e=>(0,l.jsx)(od,{...e}),[]),ee=(0,i.useCallback)(()=>{if(j){ox(`Selection from props ${JSON.stringify(j)}`);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=>g({_key:e._key},i.path[0]))&&(n=ea(i,t)),r&&t.find(e=>g({_key:e._key},r.path[0]))&&(o=ea(r,t)),n&&o?{anchor:n,focus:o,backward:e.backward}:null}(j,H(W.children,G.getSnapshot().context.schema.block.name));if(null!==e){ox(`Normalized selection from props ${JSON.stringify(e)}`);let t=el({context:{schema:G.getSnapshot().context.schema,value:W.value,selection:e},blockIndexMap:W.blockIndexMap});t&&(d.gB.select(W,t),W.operations.some(e=>"set_selection"===e.type)||G.send({type:"update selection",selection:e}),W.onChange())}}},[G,j,W]);(0,i.useEffect)(()=>{let e=G.on("ready",()=>{Q.send({type:"ready"}),ee()}),t=G.on("invalid value",()=>{V(!0)}),n=G.on("value changed",()=>{V(!1)});return()=>{e.unsubscribe(),t.unsubscribe(),n.unsubscribe()}},[Q,G,ee]),(0,i.useEffect)(()=>{j&&!L&&ee()},[L,j,ee]);let et=(0,i.useCallback)(e=>{if(u)void 0!==u(e)&&e.preventDefault();else if(e.nativeEvent.clipboardData){e.stopPropagation(),e.preventDefault();let t=W.selection?ei({schema:G.getSnapshot().context.schema,editor:W,range:W.selection}):void 0,n=t?{selection:t}:void 0;if(!n)return void console.warn("Could not find position for copy event");G.send({type:"behavior event",behaviorEvent:{type:"clipboard.copy",originEvent:{dataTransfer:e.nativeEvent.clipboardData},position:n},editor:W,nativeEvent:e})}},[u,G,W]),en=(0,i.useCallback)(e=>{if(y)void 0!==y(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)return void console.warn("Could not find position for cut event");G.send({type:"behavior event",behaviorEvent:{type:"clipboard.cut",originEvent:{dataTransfer:e.nativeEvent.clipboardData},position:n},editor:W,nativeEvent:e})}},[y,G,W]),eo=(0,i.useCallback)(e=>{let t=H(W.children,G.getSnapshot().context.schema.block.name,ep.get(W)),n=(W.selection?ei({schema:G.getSnapshot().context.schema,editor:W,range:W.selection}):null)?.focus.path||[],o=h?.({event:e,value:t,path:n,schemaTypes:P.schemaTypes});if(o||!W.selection)e.preventDefault(),U.send({type:"loading"}),Promise.resolve(o).then(t=>{if(ox("Custom paste function from client resolved",t),t&&t.insert)t.insert?G.send({type:"behavior event",behaviorEvent:{type:"insert.blocks",blocks:(0,f.SV)({context:{keyGenerator:G.getSnapshot().context.keyGenerator,schema:G.getSnapshot().context.schema},blocks:t.insert,options:{refreshKeys:!0,validateFields:!0}}),placement:"auto"},editor:W}):console.warn("Your onPaste function returned something unexpected:",t);else{ox("No result from custom paste handler, pasting normally");let t=G.getSnapshot().context.selection,n=t?{selection:t}:void 0;if(!n)return void console.warn("Could not find position for paste event");G.send({type:"behavior event",behaviorEvent:{type:"clipboard.paste",originEvent:{dataTransfer:e.clipboardData},position:n},editor:W,nativeEvent:e})}}).catch(e=>(console.warn(e),e)).finally(()=>{U.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)return void console.warn("Could not find position for paste event");G.send({type:"behavior event",behaviorEvent:{type:"clipboard.paste",originEvent:{dataTransfer:e.nativeEvent.clipboardData},position:n},editor:W,nativeEvent:e})}ox("No result from custom paste handler, pasting normally")},[G,h,P,U,W]),es=(0,i.useCallback)(e=>{r&&r(e),e.isDefaultPrevented()||(U.send({type:"focused",event:e}),!W.selection&&Y(W.children,G.getSnapshot().context.schema)&&(d.gB.select(W,d.KE.start(W,[])),W.onChange()))},[G,r,U,W]),ec=(0,i.useCallback)(e=>{if(m&&m(e),e.isDefaultPrevented()||e.isPropagationStopped())return;let t=er({editorActor:G,slateEditor:W,event:e.nativeEvent});t&&G.send({type:"behavior event",behaviorEvent:{type:"mouse.click",position:t},editor:W,nativeEvent:e})},[m,G,W]),ed=(0,i.useCallback)(e=>{o&&o(e),e.isPropagationStopped()||U.send({type:"blurred",event:e})},[U,o]),eh=(0,i.useCallback)(e=>{a&&a(e)},[a]),ef=(0,i.useCallback)(()=>
7{if(!W.selection)return;let{activeElement:e}=p.rL.findDocumentOrShadowRoot(W);if(z.current!==e)return;let t=p.rL.getWindow(W).getSelection();if(!t||0===t.rangeCount)return;let n=t.getRangeAt(0);try{let e=p.rL.toDOMRange(W,W.selection);(e.startOffset!==n.startOffset||e.endOffset!==n.endOffset)&&(ox("DOM range out of sync, validating selection"),t?.removeAllRanges(),t.addRange(e))}catch{ox("Could not resolve selection, selecting top document"),d.gB.deselect(W),W.children.length>0&&d.gB.select(W,[0,0]),W.onChange()}},[z,W]);(0,i.useEffect)(()=>{if($){let e=new MutationObserver(ef);return e.observe($,{attributeOldValue:!1,attributes:!1,characterData:!1,childList:!0,subtree:!0}),()=>{e.disconnect()}}},[ef,$]);let ey=(0,i.useCallback)(t=>{e.onKeyDown&&e.onKeyDown(t),t.isDefaultPrevented()||W.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:W,nativeEvent:t})},[e,G,W]),eg=(0,i.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:W,nativeEvent:t})},[e,G,W]),em=(0,i.useMemo)(()=>{if(void 0!==I)return null===I?c:(e,t)=>{I(P,t)}},[P,I]);(0,i.useEffect)(()=>{z.current=p.rL.toDOMNode(W,W),R(z.current)},[W,z]),(0,i.useEffect)(()=>{let e=p.rL.getWindow(W),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)}},[W,G]);let ek=(0,i.useCallback)(e=>{if(k?.(e),e.isDefaultPrevented()||e.isPropagationStopped())return;let t=er({editorActor:G,slateEditor:W,event:e.nativeEvent});return t?(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:W}),!0):void console.warn("Could not find position for dragstart event")},[k,G,W]),ev=(0,i.useCallback)(e=>{if(v?.(e),!(e.isDefaultPrevented()||e.isPropagationStopped()||!er({editorActor:G,slateEditor:W,event:e.nativeEvent})))return G.send({type:"behavior event",behaviorEvent:{type:"drag.drag",originEvent:{dataTransfer:e.dataTransfer}},editor:W}),!0},[v,G,W]),eb=(0,i.useCallback)(e=>{if(b?.(e),!(e.isDefaultPrevented()||e.isPropagationStopped()))return G.send({type:"behavior event",behaviorEvent:{type:"drag.dragend",originEvent:{dataTransfer:e.dataTransfer}},editor:W}),!0},[b,G,W]),ex=(0,i.useCallback)(e=>{if(x?.(e),e.isDefaultPrevented()||e.isPropagationStopped())return;let t=er({editorActor:G,slateEditor:W,event:e.nativeEvent});if(t)return G.send({type:"behavior event",behaviorEvent:{type:"drag.dragenter",originEvent:{dataTransfer:e.dataTransfer},position:t},editor:W}),!0},[x,G,W]),e_=(0,i.useCallback)(e=>{if(_?.(e),e.isDefaultPrevented()||e.isPropagationStopped())return;let t=er({editorActor:G,slateEditor:W,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:W,nativeEvent:e}),!0},[_,G,W]),eE=(0,i.useCallback)(e=>{if(E?.(e),e.isDefaultPrevented()||e.isPropagationStopped())return;let t=er({editorActor:G,slateEditor:W,event:e.nativeEvent});return t?(G.send({type:"behavior event",behaviorEvent:{type:"drag.drop",originEvent:{dataTransfer:e.dataTransfer},dragOrigin:G.getSnapshot().context.internalDrag?.origin,position:t},editor:W,nativeEvent:e}),!0):void console.warn("Could not find position for drop event")},[E,G,W]),ew=(0,i.useCallback)(e=>{if(w?.(e),!(e.isDefaultPrevented()||e.isPropagationStopped()||!er({editorActor:G,slateEditor:W,event:e.nativeEvent})))return G.send({type:"behavior event",behaviorEvent:{type:"drag.dragleave",originEvent:{dataTransfer:e.dataTransfer}},editor:W}),!0},[w,G,W]);return P?L?null:(0,l.jsx)(p.Fo,{...D,"data-read-only":F,autoFocus:!1,className:D.className||"pt-editable",decorate:J,onBlur:ed,onCopy:et,onCut:en,onClick:ec,onDOMBeforeInput:eh,onDragStart:ek,onDrag:ev,onDragEnd:eb,onDragEnter:ex,onDragOver:e_,onDrop:eE,onDragLeave:ew,onFocus:es,onKeyDown:ey,onKeyUp:eg,onPaste:eo,readOnly:F,renderPlaceholder:void 0,renderElement:q,renderLeaf:Z,renderText:X,scrollSelectionIntoView:em}):null});function oE(e){let t,n,r,s,c,d,h,u,f,y,g=(0,o.c)(32);g[0]!==e.initialConfig?(t=()=>{let t=n9(e.initialConfig),n=new oi({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=i.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?(r=[m],g[8]=m,g[9]=r):r=g[9],(0,i.useEffect)(n,r),g[10]!==k.change$?(s=e=>{k.change$.next(e)},g[10]=k.change$,g[11]=s):s=g[11],g[12]!==m.actors.relayActor||g[13]!==s?(c=(0,l.jsx)(ot,{relayActor:m.actors.relayActor,onChange:s}),g[12]=m.actors.relayActor,g[13]=s,g[14]=c):c=g[14],g[15]!==k||g[16
7]!==e.children?(d=(0,l.jsx)(eK.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?(h=(0,l.jsx)(p.A,{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]=h):h=g[21],g[22]!==m.actors.relayActor||g[23]!==h?(u=(0,l.jsx)(oe.Provider,{value:m.actors.relayActor,children:h}),g[22]=m.actors.relayActor,g[23]=h,g[24]=u):u=g[24],g[25]!==m.actors.editorActor||g[26]!==u?(f=(0,l.jsx)(eu.Provider,{value:m.actors.editorActor,children:u}),g[25]=m.actors.editorActor,g[26]=u,g[27]=f):f=g[27],g[28]!==m.editor||g[29]!==c||g[30]!==f?(y=(0,l.jsxs)(a.p.Provider,{value:m.editor,children:[c,f]}),g[28]=m.editor,g[29]=c,g[30]=f,g[31]=y):y=g[31],y}o_.displayName="ForwardRef(PortableTextEditable)";let ow=()=>{let e,t,n=(0,o.c)(3),r=(0,i.useContext)(eu),[a,l]=(0,i.useState)(null);return n[0]!==r?(e=()=>{let e=r.on("selection",e=>{(0,i.startTransition)(()=>{l(e.selection)})});return()=>{e.unsubscribe()}},t=[r],n[0]=r,n[1]=e,n[2]=t):(e=n[1],t=n[2]),(0,i.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.