1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[604],{69691:function(e,t,n){let o;n.d(t,{KU:function(){return EditorProvider},L9:function(){return usePortableTextEditorSelection},YH:function(){return defaultKeyGenerator},_F:function(){return usePortableTextEditor},iV:function(){return tY},q$:function(){return PortableTextEditor}});var i=n(65490),r=n(67294),a=n(57301),l=n(33882),s=n(85893),c=n(3527),d=n(50308),p=n(77493),u=n(96391),h=n(11227),f=n(50083),g=n(29400),y=n(63677),m=n(18446),k=n(85344),v=n(43956),b=n(4527),x=n(7922),_=n(44908),E=n(82649),S=n(65932),w=n(20547),O=n(14008),R=n(30368),B=n(25427),T=n(303),N=n(12565),M=n(73190),C=n(85564),A=n(57557),I=n(64540),P=n(23077),D=n(86065),j=n(27361),L=n(52353),U=n(14176),Y=n(93513),$=n(23207),z=n(7071),V=n(20070),G=n(68630);let F="sanity-pte:";function debugWithName(e){let t=`${F}${e}`;return h&&h.enabled(t)?h(t):h(F)}h(F);let K="void-child";function keepObjectEquality(e,t){let n=t[e._key];return n&&m(e,n)?n:(t[e._key]=e,e)}function toSlateValue(e,{schemaTypes:t},n={}){return e&&Array.isArray(e)?e.map(e=>{let{_type:o,_key:i,...r}=e;if(e&&e._type===t.block.name){let a=!1,l=typeof e.style>"u",s=typeof e.markDefs>"u",c=typeof e.children>"u",d=(e.children||[]).map(e=>{let{_type:t,_key:o,...i}=e;return"span"!==t?(a=!0,keepObjectEquality({_type:t,_key:o,children:[{_key:K,_type:"span",text:"",marks:[]}],value:i,__inline:!0},n)):e});return!(!l&&!s&&!c&&!a&&p.W_.isElement(e))?(l&&(r.style=t.styles[0].name),keepObjectEquality({_type:o,_key:i,...r,children:d},n)):e}return keepObjectEquality({_type:o,_key:i,children:[{_key:K,_type:"span",text:"",marks:[]}],value:r},n)}):[]}function fromSlateValue(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 keepObjectEquality({...s,...o,_key:i,_type:r},n)}return e});return t?keepObjectEquality({...e,children:r,_key:o,_type:i},n):e}let r="value"in e&&e.value;return keepObjectEquality({_key:o,_type:i,..."object"==typeof r?r:{}},n)})}function isEqualToEmptyEditor(e,t){return void 0===e||e&&Array.isArray(e)&&0===e.length||e&&Array.isArray(e)&&1===e.length&&p.W_.isElement(e[0])&&e[0]._type===t.block.name&&"style"in e[0]&&e[0].style===t.styles[0].name&&!("listItem"in e[0])&&Array.isArray(e[0].children)&&1===e[0].children.length&&p.xv.isText(e[0].children[0])&&"span"===e[0].children[0]._type&&!e[0].children[0].marks?.join("")&&""===e[0].children[0].text}function getBlockPath({editor:e,_key:t}){let[,n]=Array.from(p.ML.nodes(e,{at:[],match:e=>e._key===t})).at(0)??[void 0,void 0],o=n?.at(0);if(void 0!==o)return[o]}function getFocusBlock({editor:e}){if(!e.selection)return[void 0,void 0];try{return p.ML.node(e,e.selection.focus.path.slice(0,1))??[void 0,void 0]}catch{return[void 0,void 0]}}function getPointBlock({editor:e,point:t}){try{let[n]=p.ML.node(e,t.path.slice(0,1))??[void 0,void 0];return n?[n,t.path.slice(0,1)]:[void 0,void 0]}catch{return[void 0,void 0]}}function getPointChild({editor:e,point:t}){let[n,o]=getPointBlock({editor:e,point:t}),i=t.path.at(1);if(!n||!o||void 0===i)return[void 0,void 0];try{let e=p.NB.child(n,i);return e?[e,[...o,i]]:[void 0,void 0]}catch{return[void 0,void 0]}}function getLastBlock({editor:e}){if(0===e.children.length)return[void 0,void 0];let t=p.ML.end(e,[]).path.at(0);try{return void 0!==t?p.ML.node(e,[t])??[void 0,void 0]:[void 0,void 0]}catch{return[void 0,void 0]}}function elementToBlock({schema:e,element:t}){return fromSlateValue([t],e.block.name)?.at(0)}function isBlockElement({editor:e,schema:t},n){return p.W_.isElement(n)&&!e.isInline(n)&&(t.block.name===n._type||t.blockObjects.some(e=>e.name===n._type))}function slateRangeToSelection({schema:e,editor:t,range:n}){let[o]=getPointBlock({editor:t,point:n.anchor}),[i]=getPointBlock({editor:t,point:n.focus});if(!o||!i)return null;let[r]=o._type===e.block.name?getPointChild({editor:t,point:n.anchor}):[void 0,void 0],[a]=i._type===e.block.name?getPointChild({editor:t,point:n.focus}):[void 0,void 0],l={anchor:{path:[{_key:o._key}],offset:n.anchor.offset},focus:{path:[{_key:i._key}],offset:n.focus.offset},backward:p.e6.isBackward(n)};return r&&(l.anchor.path.push("children"),l.anchor.path.push({_key:r._key})),a&&(l.focus.path.push("children"),l.focus.path.push({_key:a._key}
1)),l}function getEventPosition({editorActor:e,slateEditor:t,event:n}){if(e.getSnapshot().matches({setup:"setting up"}))return;let o=function({slateEditor:e,event:t}){return f.y2.hasTarget(e,t.target)?f.y2.toSlateNode(e,t.target):void 0}({slateEditor:t,event:n});if(!o)return;let i=function({editor:e,schema:t,node:n}){if(p.ML.isEditor(n))return;if(isBlockElement({editor:e,schema:t},n))return elementToBlock({schema:t,element:n});let o=Array.from(p.ML.nodes(e,{mode:"highest",at:[],match:o=>isBlockElement({editor:e,schema:t},o)&&o.children.some(e=>e._key===n._key)})).at(0)?.at(0);return p.W_.isElement(o)?elementToBlock({schema:t,element:o}):void 0}({editor:t,schema:e.getSnapshot().context.schema,node:o}),r=function({node:e,slateEditor:t,event:n}){let[o]=function({editor:e}){if(0===e.children.length)return[void 0,void 0];let t=p.ML.start(e,[]).path.at(0);try{return void 0!==t?p.ML.node(e,[t])??[void 0,void 0]:[void 0,void 0]}catch{return[void 0,void 0]}}({editor:t});if(!o)return;let i=f.y2.toDOMNode(t,o).getBoundingClientRect();if(n.pageY<i.top)return"start";let[r]=getLastBlock({editor:t});if(!r)return;let a=f.y2.toDOMNode(t,r).getBoundingClientRect();if(n.pageY>a.bottom)return"end";let l=f.y2.toDOMNode(t,e).getBoundingClientRect(),s=l.top,c=l.height;return Math.abs(s-n.pageY)<c/2?"start":"end"}({node:o,slateEditor:t,event:n}),a=function({schema:e,slateEditor:t,event:n}){let o=function(e,t){let n,o;if(!t.target||!(0,f.uF)(t.target))return;let i=f.y2.getWindow(e);if(void 0!==i.document.caretPositionFromPoint){let e=i.document.caretPositionFromPoint(t.clientX,t.clientY);if(e)try{(n=i.document.createRange()).setStart(e.offsetNode,e.offset),n.setEnd(e.offsetNode,e.offset)}catch{}}else if(void 0!==i.document.caretRangeFromPoint)n=i.document.caretRangeFromPoint(t.clientX,t.clientY)??void 0;else{console.warn("Neither caretPositionFromPoint nor caretRangeFromPoint is supported");return}if(n){try{o=f.y2.toSlateRange(e,n,{exactMatch:!1,suppressThrow:!1})}catch{}return o}}(t,n);return o?slateRangeToSelection({schema:e,editor:t,range:o}):null}({schema:e.getSnapshot().context.schema,slateEditor:t,event:n});if(i&&r&&!a&&!p.ML.isEditor(o))return{block:r,isEditor:!1,selection:{anchor:(0,g.qv)({context:e.getSnapshot().context,block:{node:i,path:[{_key:i._key}]}}),focus:(0,y.sQ)({context:e.getSnapshot().context,block:{node:i,path:[{_key:i._key}]}})}};if(!r||!a)return;let l=(0,g.Ak)(a.focus);if(void 0!==l)return(0,y.dI)(a)&&i&&l!==i._key?{block:r,isEditor:!1,selection:{anchor:(0,g.qv)({context:e.getSnapshot().context,block:{node:i,path:[{_key:i._key}]}}),focus:(0,y.sQ)({context:e.getSnapshot().context,block:{node:i,path:[{_key:i._key}]}})}}:{block:r,isEditor:p.ML.isEditor(o),selection:a}}function normalizePoint(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 toSlateRange(e){if(!e.context.selection)return null;if((0,y.Gh)(e.context.selection.anchor,e.context.selection.focus)){let t=toSlateSelectionPoint(e,e.context.selection.anchor,e.context.selection.backward?"forward":"backward");return t?{anchor:t,focus:t}:null}let t=toSlateSelectionPoint(e,e.context.selection.anchor,e.context.selection.backward?"forward":"backward"),n=toSlateSelectionPoint(e,e.context.selection.focus,e.context.selection.backward?"backward":"forward");return t&&n?{anchor:t,focus:n}:null}function toSlateSelectionPoint(e,t,n){let o=(0,g.Ak)(t);if(!o)return;let i=e.blockIndexMap.get(o);if(void 0===i)return;let r=e.context.value.at(i);if(!r)return;if(!(0,g.dz)(e.context,r))return{path:[i,0],offset:0};let a=(0,g.NX)({path:t.path}),l=a?void 0:(0,g.MR)({context:{schema:e.context.schema,value:[r]},blockOffset:{path:[{_key:o}],offset:t.offset},direction:n});if(!(a=l?(0,g.NX)(l):a))return{path:[i,0],offset:0};let s=l?.offset??t.offset,c=[],d=-1,p;for(let t of r.children)if(d++,t._key===a){p=t,(0,g.dn)(e.context,t)?c=[d]:(c=[d,0],s=0);break}return 0===c.length?{path:[i,0],offset:0}:{path:[i].concat(c),offset:(0,g.dn)(e.context,p)?Math.min(p.text.length,s):s}}let W=new WeakMap,q=new WeakMap,H=new WeakMap,J=new WeakMap,X=(0,r.createContext)({});function DropIndicator(){let e;let t=(0,i.c)(1);return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=(0,s.jsx)("div",{contentEditable:!1,
1className:"pt-drop-indicator",style:{position:"absolute",width:"100%",height:1,borderBottom:"1px solid currentColor",zIndex:5},children:(0,s.jsx)("span",{})}),t[0]=e):e=t[0],e}function RenderDefaultBlockObject(e){let t,n;let o=(0,i.c)(4);return o[0]===Symbol.for("react.memo_cache_sentinel")?(t={userSelect:"none"},o[0]=t):t=o[0],o[1]!==e.blockObject._key||o[2]!==e.blockObject._type?(n=(0,s.jsxs)("div",{style:t,children:["[",e.blockObject._type,": ",e.blockObject._key,"]"]}),o[1]=e.blockObject._key,o[2]=e.blockObject._type,o[3]=n):n=o[3],n}function RenderDefaultInlineObject(e){let t,n;let o=(0,i.c)(4);return o[0]===Symbol.for("react.memo_cache_sentinel")?(t={userSelect:"none"},o[0]=t):t=o[0],o[1]!==e.inlineObject._key||o[2]!==e.inlineObject._type?(n=(0,s.jsxs)("span",{style:t,children:["[",e.inlineObject._type,": ",e.inlineObject._key,"]"]}),o[1]=e.inlineObject._key,o[2]=e.inlineObject._type,o[3]=n):n=o[3],n}function getDragSelection({eventSelection:e,snapshot:t}){let n=e;if((0,v.fX)({...t,context:{...t.context,selection:e}}))return n;let o=(0,k.dI)({context:{...t.context,selection:e}}),i=(0,k.I3)({...t,context:{...t.context,selection:e}}),r=(0,k.Cj)({...t,context:{...t.context,selection:e}});o&&i&&r&&(n={anchor:(0,g.qv)({context:t.context,block:i}),focus:(0,y.sQ)({context:t.context,block:i})});let a=(0,v.wD)(t);if(t.context.selection&&(0,k.sC)(t)&&a.length>1){let o=(0,v.Dm)(t),i=(0,v.Zq)(t);if(!o||!i)return n;let r=(0,g.qv)({context:t.context,block:o}),a=(0,y.sQ)({context:t.context,block:i});(0,v.Mf)(e)({...t,context:{...t.context,selection:{anchor:r,focus:a}}})&&(n={anchor:r,focus:a})}return n}let defaultKeyGenerator=()=>(function(e){let t=getByteHexTable();return(function(e=16){let t=new Uint8Array(e);return(0,b.Z)(t),t})(e).reduce((e,n)=>e+t[n],"").slice(0,e)})(12),getByteHexTable=()=>{if(o)return o;o=[];for(let e=0;e<256;++e)o[e]=(e+256).toString(16).slice(1);return o};function createEditorPriority(e){return{id:defaultKeyGenerator(),name:e?.name,reference:e?.reference}}let Z=createEditorPriority({name:"core"});function useCoreBlockElementBehaviors(e){let t,n;let o=(0,i.c)(5),{key:a,onSetDragPositionBlock:l}=e,s=(0,r.useContext)(X);o[0]!==s||o[1]!==a||o[2]!==l?(t=()=>{let e=function({key:e,onSetDragPositionBlock:t}){return[{behavior:(0,x.gg)({on:"drag.dragover",guard:({snapshot:t,event:n})=>{let o=(0,k.tT)({...t,context:{...t.context,selection:n.position.selection}});if(!o||o.node._key!==e)return!1;let i=n.dragOrigin;if(!i)return!1;let r=getDragSelection({eventSelection:i.selection,snapshot:t});return!(0,v.wD)({...t,context:{...t.context,selection:r}}).some(t=>t.node._key===e)&&(0,v.u7)({...t,context:{...t.context,selection:r}})},actions:[({event:e})=>[{type:"effect",effect:()=>{t(e.position.block)}}]]}),priority:createEditorPriority({reference:{priority:Z,importance:"lower"}})},{behavior:(0,x.gg)({on:"drag.*",guard:({event:e})=>"drag.dragover"!==e.type,actions:[({event:e})=>[{type:"effect",effect:()=>{t(void 0)}},(0,x.eH)(e)]]}),priority:createEditorPriority({reference:{priority:Z,importance:"lower"}})}]}({key:a,onSetDragPositionBlock:l});for(let t of e)s.send({type:"add behavior",behaviorConfig:t});return()=>{for(let t of e)s.send({type:"remove behavior",behaviorConfig:t})}},n=[s,a,l],o[0]=s,o[1]=a,o[2]=l,o[3]=t,o[4]=n):(t=o[3],n=o[4]),(0,r.useEffect)(t,n)}function RenderBlockObject(e){let[t,n]=(0,r.useState)(),o=(0,r.useRef)(null),i=(0,u.vt)(),a=(0,u.b_)(e=>i&&null!==e.selection&&p.e6.isCollapsed(e.selection));useCoreBlockElementBehaviors({key:e.element._key,onSetDragPositionBlock:n});let l=e.legacySchema.blockObjects.find(t=>t.name===e.element._type);l||console.error(`Unable to find Block Object "${e.element._type}" in Schema`);let c=e.blockObject??{_key:e.element._key,_type:e.element._type};return(0,s.jsxs)("div",{...e.attributes,className:"pt-block pt-object-block","data-block-key":e.element._key,"data-block-name":e.element._type,"data-block-type":"object",children:["start"===t?(0,s.jsx)(DropIndicator,{}):null,e.children,(0,s.jsx)("div",{ref:o,contentEditable:!1,draggable:!e.readOnly,children:e.renderBlock&&l?e.renderBlock({children:(0,s.jsx)(RenderDefaultBlockObject,{blockObject:c}),editorElementRef:o,focused:a,path:[{_key:e.element._key}],schemaType:l,selected:i,type:l,value:c}):(0,s.jsx)(RenderDefaultBlockObject,{blockObject:c})}),"end"===t?(0,s.jsx)(DropIndicator,{}):null]})}
1function RenderInlineObject(e){let t=(0,r.useRef)(null),n=(0,u._7)(),o=(0,u.vt)(),i=(0,u.b_)(e=>o&&null!==e.selection&&p.e6.isCollapsed(e.selection)),a=e.legacySchema.inlineObjects.find(t=>t.name===e.element._type);a||console.error(`Unable to find Inline Object "${e.element._type}" in Schema`);let l=f.y2.findPath(n,e.element),[c]=getPointBlock({editor:n,point:{path:l,offset:0}});c||console.error(`Unable to find parent block of inline object ${e.element._key}`);let d={_key:e.element._key,_type:e.element._type,..."value"in e.element&&"object"==typeof e.element.value?e.element.value:{}};return(0,s.jsxs)("span",{...e.attributes,draggable:!e.readOnly,className:"pt-inline-object","data-child-key":d._key,"data-child-name":d._type,"data-child-type":"object",children:[e.children,(0,s.jsx)("span",{ref:t,style:{display:"inline-block"},children:e.renderChild&&c&&a?e.renderChild({annotations:[],children:(0,s.jsx)(RenderDefaultInlineObject,{inlineObject:d}),editorElementRef:t,selected:o,focused:i,path:[{_key:c._key},"children",{_key:e.element._key}],schemaType:a,value:d,type:a}):(0,s.jsx)(RenderDefaultInlineObject,{inlineObject:d})})]})}function RenderTextBlock(e){let[t,n]=(0,r.useState)(),o=(0,r.useRef)(null),i=(0,u.vt)(),a=(0,u.b_)(e=>i&&null!==e.selection&&p.e6.isCollapsed(e.selection));useCoreBlockElementBehaviors({key:e.element._key,onSetDragPositionBlock:n});let l=(0,u.b_)(t=>t.listIndexMap.get(e.textBlock._key)),c=e.children;if(e.renderStyle&&e.textBlock.style){let t=void 0!==e.textBlock.style?e.legacySchema.styles.find(t=>t.value===e.textBlock.style):void 0;t?c=e.renderStyle({block:e.textBlock,children:c,editorElementRef:o,focused:a,path:[{_key:e.textBlock._key}],schemaType:t,selected:i,value:e.textBlock.style}):console.error(`Unable to find Schema type for text block style ${e.textBlock.style}`)}if(e.renderListItem&&e.textBlock.listItem){let t=e.legacySchema.lists.find(t=>t.value===e.textBlock.listItem);t?c=e.renderListItem({block:e.textBlock,children:c,editorElementRef:o,focused:a,level:e.textBlock.level??1,path:[{_key:e.textBlock._key}],selected:i,value:e.textBlock.listItem,schemaType:t}):console.error(`Unable to find Schema type for text block list item ${e.textBlock.listItem}`)}return(0,s.jsxs)("div",{...e.attributes,className:["pt-block","pt-text-block",...e.textBlock.style?[`pt-text-block-style-${e.textBlock.style}`]:[],...e.textBlock.listItem?["pt-list-item",`pt-list-item-${e.textBlock.listItem}`,`pt-list-item-level-${e.textBlock.level??1}`]:[]].join(" "),spellCheck:e.spellCheck,"data-block-key":e.textBlock._key,"data-block-name":e.textBlock._type,"data-block-type":"text",...void 0!==e.textBlock.listItem?{"data-list-item":e.textBlock.listItem}:{},...void 0!==e.textBlock.level?{"data-level":e.textBlock.level}:{},...void 0!==e.textBlock.style?{"data-style":e.textBlock.style}:{},...void 0!==l?{"data-list-index":l}:{},children:["start"===t?(0,s.jsx)(DropIndicator,{}):null,(0,s.jsx)("div",{ref:o,children:e.renderBlock?e.renderBlock({children:c,editorElementRef:o,focused:a,level:e.textBlock.level,listItem:e.textBlock.listItem,path:[{_key:e.textBlock._key}],selected:i,schemaType:e.legacySchema.block,style:e.textBlock.style,type:e.legacySchema.block,value:e.textBlock}):c}),"end"===t?(0,s.jsx)(DropIndicator,{}):null]})}function RenderElement(e){let t,n,o;let a=(0,i.c)(34),l=(0,r.useContext)(X),d=(0,c.v9)(l,_temp$1),p=(0,c.v9)(l,_temp2),h=(0,u._7)();if("__inline"in e.element&&!0===e.element.__inline){let t;return a[0]!==p||a[1]!==e.attributes||a[2]!==e.children||a[3]!==e.element||a[4]!==e.readOnly||a[5]!==e.renderChild||a[6]!==d?(t=(0,s.jsx)(RenderInlineObject,{attributes:e.attributes,element:e.element,legacySchema:p,readOnly:e.readOnly,renderChild:e.renderChild,schema:d,children:e.children}),a[0]=p,a[1]=e.attributes,a[2]=e.children,a[3]=e.element,a[4]=e.readOnly,a[5]=e.renderChild,a[6]=d,a[7]=t):t=a[7],t}if(a[8]!==e.element._key||a[9]!==d||a[10]!==h.blockIndexMap||a[11]!==h.value){let o=h.blockIndexMap.get(e.element._key);t=void 0!==o?h.value.at(o):void 0,n=(0,g.dz)({schema:d},t),a[8]=e.element._key,a[9]=d,a[10]=h.blockIndexMap,a[11]=h.value,a[12]=t,a[13]=n}else t=a[12],n=a[13];if(n){let n;return a[14]!==t||a[15]!==p||a[16]!==e.attributes||a[17]!==e.children||a[18]!==e.element||a[19]!==e.readOnly||a[20]!==e.renderBlock||a[21]!==e.renderListItem||a[22]!==e.renderStyle||a[23]!==e.spellCheck?(n=(0,s.jsx)(RenderTextBlock,{attributes:e.attributes,element:e.element,legacySchema:p,readOnly:e.readOnly,renderBlock:e.renderBlock,renderListItem:e.renderListItem,render
1Style:e.renderStyle,spellCheck:e.spellCheck,textBlock:t,children:e.children}),a[14]=t,a[15]=p,a[16]=e.attributes,a[17]=e.children,a[18]=e.element,a[19]=e.readOnly,a[20]=e.renderBlock,a[21]=e.renderListItem,a[22]=e.renderStyle,a[23]=e.spellCheck,a[24]=n):n=a[24],n}return a[25]!==t||a[26]!==p||a[27]!==e.attributes||a[28]!==e.children||a[29]!==e.element||a[30]!==e.readOnly||a[31]!==e.renderBlock||a[32]!==d?(o=(0,s.jsx)(RenderBlockObject,{attributes:e.attributes,blockObject:t,element:e.element,legacySchema:p,readOnly:e.readOnly,renderBlock:e.renderBlock,schema:d,children:e.children}),a[25]=t,a[26]=p,a[27]=e.attributes,a[28]=e.children,a[29]=e.element,a[30]=e.readOnly,a[31]=e.renderBlock,a[32]=d,a[33]=o):o=a[33],o}function _temp2(e){return e.context.getLegacySchema()}function _temp$1(e){return e.context.schema}let Q=(0,r.createContext)(null),usePortableTextEditor=()=>{let e=(0,r.useContext)(Q);if(!e)throw Error("The `usePortableTextEditor` hook must be used inside the <PortableTextEditor> component's context.");return e},forEachActor=(e,t)=>{t(e);let n=e.getSnapshot().children;n&&Object.values(n).forEach(e=>{forEachActor(e,t)})};function stopActor(e){let t=[];forEachActor(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 ee={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"}}},et={mimeType:"application/x-portable-text",serialize:({snapshot:e,event:t})=>{if(!e.context.selection)return{type:"serialization.failure",mimeType:"application/x-portable-text",originEvent:t.originEvent,reason:"No selection"};let n=(0,k.Ly)(e);return 0===n.length?{type:"serialization.failure",mimeType:"application/x-portable-text",reason:"No blocks serialized",originEvent:t.originEvent}:{type:"serialization.success",data:JSON.stringify(n),mimeType:"application/x-portable-text",originEvent:t.originEvent}},deserialize:({snapshot:e,event:t})=>{let n=JSON.parse(t.data);if(!Array.isArray(n))return{type:"deserialization.failure",mimeType:"application/x-portable-text",reason:"Data is not an array"};let o=n.flatMap(t=>{let n=(0,g.IX)({context:e.context,block:t,options:{refreshKeys:!0,validateFields:!1}});return n?[n]:[]});return 0===o.length&&n.length>0?{type:"deserialization.failure",mimeType:"application/x-portable-text",reason:"No blocks were parsed"}:{type:"deserialization.success",data:o,mimeType:"application/x-portable-text"}}},en={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="},eo=new Map;function buildIndexMaps(e,{blockIndexMap:t,listIndexMap:n}){let o;t.clear(),n.clear(),eo.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,g.dz)(e,r)||void 0===r.listItem||void 0===r.level){eo.clear(),o=void 0;continue}if(!o){o={listItem:r.listItem,level:r.level},eo.set(r.level,1),n.set(r._key,1);continue}if(o.listItem!==r.listItem){eo.clear(),o={listItem:r.listItem,level:r.level},eo.set(r.level,1),n.set(r._key,1);continue}if(o.level===r.level){let e=eo.get(r.level)??0;eo.set(r.level,e+1),o={listItem:r.listItem,level:r.level},n.set(r._key,e+1);continue}if(o.level<r.level){eo.set(r.level,1),o={listItem:r.listItem,level:r.level},n.set(r._key,1);continue}if(o.level>r.level){let e=eo.get(r.level)??0;eo.set(r.level,e+1),o={listItem:r.listItem,level:r.level},n.set(r._key,e+1)}}}}function createPlaceholderBlock(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 insertTextOperationImplementation=({context:e,operation:t})=>{let n={blockIndexMap:t.editor.blockIndexMap,context:{value:t.editor.value,selection:t.editor.selection?slateRangeToSelection({schema:e.schema,editor:t.editor,range:t.editor.selection}
1):null,schema:e.schema,keyGenerator:e.keyGenerator,converters:[],readOnly:!1},decoratorState:t.editor.decoratorState},o=(0,v.zd)(n),i=(0,v.WH)(n),r=(0,v.YG)(n),[a]=function({editor:e}){if(!e.selection)return[void 0,void 0];try{let[t,n]=p.ML.node(e,e.selection.focus.path);if(e.isTextSpan(t))return[t,n]}catch{}return[void 0,void 0]}({editor:t.editor});if(!a){p.YR.insertText(t.editor,t.text);return}if(o&&"unchanged"===o.state){let n=(o.marks??[]).filter(t=>e.schema.decorators.map(e=>e.name).includes(t));if(n.length===i.length&&n.every(e=>i.includes(e))){p.YR.insertText(t.editor,t.text);return}}p.YR.insertNodes(t.editor,{_type:a._type,_key:e.keyGenerator(),text:t.text,marks:[...i,...r]}),t.editor.decoratorState={}};function isPortableTextSpan(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 getPreviousSpan({editor:e,blockPath:t,spanPath:n}){let o;for(let[i,r]of p.NB.children(e,t,{reverse:!0}))if(e.isTextSpan(i)&&p.y$.isBefore(r,n)){o=i;break}return o}function getNextSpan({editor:e,blockPath:t,spanPath:n}){let o;for(let[i,r]of p.NB.children(e,t))if(e.isTextSpan(i)&&p.y$.isAfter(r,n)){o=i;break}return o}function withRemoteChanges(e,t){let n=isChangingRemotely(e)||!1;W.set(e,!0),t(),W.set(e,n)}function isChangingRemotely(e){return W.get(e)}let ei=new WeakMap,er=new WeakMap;function isUndoing(e){return ei.get(e)??!1}function isRedoing(e){return er.get(e)??!1}function getEditorSnapshot({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 ea=debugWithName("plugin:withPortableTextMarkModel");function cloneDiff(e){let[t,n]=e;return[t,n]}function getCommonOverlap(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 getCommonPrefix(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 getCommonSuffix(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 bisectSplit(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=doDiff(r,a,{checkLines:!1,deadline:i}),d=doDiff(l,s,{checkLines:!1,deadline:i});return c.concat(d)}function halfMatchI(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=getCommonPrefix(e.slice(n),t.slice(i)),d=getCommonSuffix(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 el=Object.defineProperty,es=Object.getOwnPropertySymbols,ec=Object.prototype.hasOwnProperty,ed=Object.prototype.propertyIsEnumerable,__defNormalProp$2=(e,t,n)=>t in e?el(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,__spreadValues$2=(e,t)=>{for(var n in t||(t={}))ec.call(t,n)&&__defNormalProp$2(e,n,t[n]);if(es)for(var n of es(t))ed.call(t,n)&&__defNormalProp$2(e,n,t[n]);return e};function diff(e,t,n){var o,i;let r;if(null===e||null===t)throw Error("Null input. (diff)");let a=doDiff(e,t,__spreadValues$2({checkLines:!0,deadline:(i=(o=n||{}).timeout||1,r=1,"u">typeof i&&(r=i<=0?Number.MAX_VALUE:i),Date.now()+1e3*r)},o));return function(e){for(let t=0;t<e.length;t++){let[n,o]=e[t];if(0===o.length)continue;let i=o[0],r=o[o.length-1];(function(e){let t=e.charCodeAt(0);return t>=55296&&t<=56319})(r)&&0===n&&deisolateChar(e,t,1),function(e){let t=e.charCodeAt(0);return t>=56320&&t<=57343}(i)&&0===n&&deisolateChar(e,t,-1)}for(let t=0;t<e.length;t++)0===e[t][1].length&&e.splice(t,1)}(a),a}function doDiff(e,t,n){let o=e,i=t;if(o===i)return o?[[0,o]]:[];let r=getCommonPrefix(o,i),a=o.substring(0,r);r=getCommonSuffix(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=halfMatchI(s,c,Math.ceil(s.length/4)),p=halfMatchI(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.");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]);let u=o[4];return[i,r,a,l,u]}(e,t);if(l){let e=l[0],t=l[1],o=l[2],i=l[3],r=l[4],a=doDiff(e,o,n),s=doDiff(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 diffLinesToMunge(e){let t="",r=0,a=-1,l=n.length;for(;a<e.length-1;){-1===(a=e.indexOf(` 2`,r))&&(a=e.length-1);let s=e.slice(r,a+1);(o.hasOwnProperty?o.hasOwnProperty(s):void 0!==o[s])?t+=String.fromCharCode(o[s]):(l===i&&(s=e.slice(r),a=e.length),t+=String.fromCharCode(l),o[s]=l,n[l++]=s),r=a+1}return t}n[0]="";let i=4e4,r=diffLinesToMunge(e);i=65535;let a=diffLinesToMunge(t);return{chars1:r,chars2:a,lineArray:n}}(o,i);o=r.chars1,i=r.chars2;let a=r.lineArray,l=doDiff(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=>cloneDiff(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=cleanupMerge(t)),t=cleanupSemanticLossless(t),a=1;a<t.length;
2){if(-1===t[a-1][0]&&1===t[a][0]){let e=t[a-1][1],n=t[a][1],o=getCommonOverlap(e,n),i=getCommonOverlap(n,e);o>=i?(o>=e.length/2||o>=n.length/2)&&(t.splice(a,0,[0,n.substring(0,o)]),t[a-1][1]=e.substring(0,e.length-o),t[a+1][1]=n.substring(o),a++):(i>=e.length/2||i>=n.length/2)&&(t.splice(a,0,[0,e.substring(0,i)]),t[a-1][0]=1,t[a-1][1]=n.substring(0,n.length-i),t[a+1][0]=-1,t[a+1][1]=e.substring(i),a++),a++}a++}return t}(l)).push([0,""]);let s=0,c=0,d=0,p="",u="";for(;s<l.length;){switch(l[s][0]){case 1:d++,u+=l[s][1];break;case -1:c++,p+=l[s][1];break;case 0:if(c>=1&&d>=1){l.splice(s-c-d,c+d),s=s-c-d;let e=doDiff(p,u,{checkLines:!1,deadline:n.deadline});for(let t=e.length-1;t>=0;t--)l.splice(s,0,e[t]);s+=e.length}d=0,c=0,p="",u="";break;default:throw Error("Unknown diff operation.")}s++}return l.pop(),l}(e,t,n):function(e,t,n){let o=e.length,i=t.length,r=Math.ceil((o+i)/2),a=2*r,l=Array(a),s=Array(a);for(let e=0;e<a;e++)l[e]=-1,s[e]=-1;l[r+1]=0,s[r+1]=0;let c=o-i,d=c%2!=0,p=0,u=0,h=0,f=0;for(let g=0;g<r&&!(Date.now()>n);g++){for(let h=-g+p;h<=g-u;h+=2){let f;let y=r+h,m=(f=h===-g||h!==g&&l[y-1]<l[y+1]?l[y+1]:l[y-1]+1)-h;for(;f<o&&m<i&&e.charAt(f)===t.charAt(m);)f++,m++;if(l[y]=f,f>o)u+=2;else if(m>i)p+=2;else if(d){let i=r+c-h;if(i>=0&&i<a&&-1!==s[i]){let r=o-s[i];if(f>=r)return bisectSplit(e,t,f,m,n)}}}for(let p=-g+h;p<=g-f;p+=2){let u;let y=r+p,m=(u=p===-g||p!==g&&s[y-1]<s[y+1]?s[y+1]:s[y-1]+1)-p;for(;u<o&&m<i&&e.charAt(o-u-1)===t.charAt(i-m-1);)u++,m++;if(s[y]=u,u>o)f+=2;else if(m>i)h+=2;else if(!d){let i=r+c-p;if(i>=0&&i<a&&-1!==l[i]){let a=l[i],s=r+a-i;if(a>=(u=o-u))return bisectSplit(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=cleanupMerge(s)}function combineChar(e,t,n){return 1===n?e+t:t+e}function splitChar(e,t){return 1===t?[e.substring(0,e.length-1),e[e.length-1]]:[e.substring(1),e[0]]}function deisolateChar(e,t,n){var o,i;let r=1===n?-1:1,a=null,l=null,s=t+n;for(;s>=0&&s<e.length&&(null===a||null===l);s+=n){let[o,i]=e[s];if(0!==i.length){if(1===o){null===a&&(a=s);continue}if(-1===o){null===l&&(l=s);continue}if(0===o){if(null===a&&null===l){let[o,i]=splitChar(e[t][1],n);e[t][1]=o,e[s][1]=combineChar(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]=splitChar(e[a][1],r),[s]=splitChar(e[l][1],r);e[a][1]=o,e[l][1]=s,e[t][1]=combineChar(e[t][1],i,n);return}let[c,d]=splitChar(e[t][1],n);e[t][1]=c,null===a?(e.splice(s,0,[1,d]),null!==l&&l>=s&&l++):e[a][1]=combineChar(e[a][1],d,r),null===l?e.splice(s,0,[-1,d]):e[l][1]=combineChar(e[l][1],d,r)}let ep=/[^a-zA-Z0-9]/,eu=/\s/,eh=/[\r\n]/,ef=/\n\r?\n$/,eg=/^\r?\n\r?\n/;function cleanupSemanticLossless(e){let t=e.map(e=>cloneDiff(e));function diffCleanupSemanticScore(e,t){if(!e||!t)return 6;let n=e.charAt(e.length-1),o=t.charAt(0),i=n.match(ep),r=o.match(ep),a=i&&n.match(eu),l=r&&o.match(eu),s=a&&n.match(eh),c=l&&o.match(eh),d=s&&e.match(ef),p=c&&t.match(eg);return d||p?5:s||c?4:i&&!a&&l?3:a||l?2:i||r?1:0}let n=1;for(;n<t.length-1;){if(0===t[n-1][0]&&0===t[n+1][0]){let e=t[n-1][1],o=t[n][1],i=t[n+1][1],r=getCommonSuffix(e,o);if(r){let t=o.substring(o.length-r);e=e.substring(0,e.length-r),o=t+o.substring(0,o.length-r),i=t+i}let a=e,l=o,s=i,c=diffCleanupSemanticScore(e,o)+diffCleanupSemanticScore(o,i);for(;o.charAt(0)===i.charAt(0);){e+=o.charAt(0),o=o.substring(1)+i.charAt(0),i=i.substring(1);let t=diffCleanupSemanticScore(e,o)+diffCleanupSemanticScore(o,i);t>=c&&(c=t,a=e,l=o,s=i)}t[n-1][1]!==a&&(a?t[n-1][1]=a:(t.splice(n-1,1),n--),t[n][1]=l,s?t[n+1][1]=s:(t.splice(n+1,1),n--))}n++}return t}function cleanupMerge(e){let t=e.map(e=>cloneDiff(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=getCommonPrefix(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=getCommonSuffix(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=cleanupMerge(t)),t}var ey=Object.defineProperty,em=Object.getOwnPropertySymbols,ek=Object.prototype.hasOwnProperty,ev=Object.prototype.propertyIsEnumerable,__defNormalProp$1=(e,t,n)=>t in e?ey(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,__spreadValues$1=(e,t)=>{for(var n in t||(t={}
2))ek.call(t,n)&&__defNormalProp$1(e,n,t[n]);if(em)for(var n of em(t))ev.call(t,n)&&__defNormalProp$1(e,n,t[n]);return e};let eb={threshold:.5,distance:1e3};function match(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=__spreadValues$1(__spreadValues$1({},eb),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 getBitapScore(e,o){let r=e/t.length,a=Math.abs(n-o);return i.distance?r+a/i.distance:a?1:r}let a=i.threshold,l=e.indexOf(t,n);-1!==l&&(a=Math.min(getBitapScore(0,l),a),-1!==(l=e.lastIndexOf(t,n+t.length))&&(a=Math.min(getBitapScore(0,l),a)));let s=1<<t.length-1;l=-1;let c,d,p=t.length+e.length,u=[];for(let o=0;o<t.length;o++){for(c=0,d=p;c<d;)getBitapScore(o,n+d)<=a?c=d:p=d,d=Math.floor((p-c)/2+c);p=d;let i=Math.max(1,n-d+1),h=Math.min(n+d,e.length)+t.length,f=Array(h+2);f[h+1]=(1<<o)-1;for(let t=h;t>=i;t--){let c=r[e.charAt(t-1)];if(0===o?f[t]=(f[t+1]<<1|1)&c:f[t]=(f[t+1]<<1|1)&c|((u[t+1]|u[t])<<1|1)|u[t+1],f[t]&s){let e=getBitapScore(o,t-1);if(e<=a){if(a=e,(l=t-1)>n)i=Math.max(1,2*n-l);else break}}}if(getBitapScore(o+1,n)>a)break;u=f}return l}(e,t,i,o):-1}function diffText1(e){let t=[];for(let n=0;n<e.length;n++)1!==e[n][0]&&(t[n]=e[n][1]);return t.join("")}function diffText2(e){let t=[];for(let n=0;n<e.length;n++)-1!==e[n][0]&&(t[n]=e[n][1]);return t.join("")}function xIndex(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 countUtf8Bytes(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+=utf8len(o)}return t}function utf8len(e){return e<=127?1:e<=2047?2:e<=65535?3:4}function createPatchObject(e,t){return{diffs:[],start1:e,start2:t,utf8Start1:e,utf8Start2:t,length1:0,length2:0,utf8Length1:0,utf8Length2:0}}let ex=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;function parse(e){if(!e)return[];let t=[],n=e.split(` 3`),o=0;for(;o<n.length;){let e=n[o].match(ex);if(!e)throw Error(`Invalid patch string: ${n[o]}`);let i=createPatchObject(toInt(e[1]),toInt(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=toInt(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=toInt(e[4]),i.length2=i.utf8Length2),o++;o<n.length;){let e;let t=n[o],r=t.charAt(0);if("@"===r)break;if(""===r){o++;continue}try{e=decodeURI(t.slice(1))}catch{throw Error(`Illegal escape in parse: ${t}`)}let a=countUtf8Bytes(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 toInt(e){return parseInt(e,10)}let e_=new WeakMap;function getCurrentUndoStepId(e){return e_.get(e)?.undoStepId}let eE=debugWithName("plugin:withUndoRedo"),eS=new WeakMap,ew=new WeakMap,isSaving=e=>{let t=eS.get(e);return void 0===t||t},getRemotePatches=e=>(ew.get(e)||ew.set(e,[]),ew.get(e)||[]);function transformOperation(e,t,n,o,i){let r={...n};if("insert"===t.type&&1===t.path.length){let e=(o||[]).findIndex(e=>m({_key:e._key},t.path[0]));return eE(`Adjusting block path (+${t.items.length}) for '${r.type}' operation and patch '${t.type}'`),[adjustBlockPath(r,t.items.length,e)]}if("unset"===t.type&&1===t.path.length){let e=(i||[]).findIndex(e=>m({_key:e._key},t.path[0]));return"path"in r&&Array.isArray(r.path)&&r.path[0]===e?(eE("Skipping transformation that targeted removed block"),[]):[adjustBlockPath(r,-1,e)]}if("unset"===t.type&&0===t.path.length)return eE(`Adjusting selection for unset everything patch and ${n.type} operation`),[];
3if("diffMatchPatch"===t.type){let n;let o=("set_selection"===r.type&&e.selection?n=e.children[e.selection.focus.path[0]]:"path"in r&&(n=e.children[r.path[0]]),n);return o&&m({_key:o._key},t.path[0])&&parse(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 adjustBlockPath(e,t,n){let o={...e};if(n>=0&&"set_selection"!==o.type&&Array.isArray(o.path)&&o.path[0]>=n+t&&o.path[0]+t>-1){let e=[o.path[0]+t,...o.path.slice(1)];o.path=e}if("set_selection"===o.type){let e=o.properties?.focus?{...o.properties.focus}:void 0,i=o?.properties?.anchor?{...o.properties.anchor}:void 0,r=o?.newProperties?.focus?{...o.newProperties.focus}:void 0,a=o?.newProperties?.anchor?{...o.newProperties.anchor}:void 0;(e&&i||r&&a)&&([e,i,r,a].forEach(e=>{e&&e.path[0]>=n+t&&e.path[0]+t>-1&&(e.path=[e.path[0]+t,...e.path.slice(1)])}),e&&i&&(o.properties={focus:e,anchor:i}),r&&a&&(o.newProperties={focus:r,anchor:a}))}return o}let shouldMerge=(e,t)=>!!("set_selection"===e.type||t&&"insert_text"===e.type&&"insert_text"===t.type&&e.offset===t.offset+t.text.length&&p.y$.equals(e.path,t.path)&&" "!==e.text||t&&"remove_text"===e.type&&"remove_text"===t.type&&e.offset+e.text.length===t.offset&&p.y$.equals(e.path,t.path)),shouldOverwrite=(e,t)=>!!(t&&"set_selection"===e.type&&"set_selection"===t.type),shouldClear=e=>"set_selection"!==e.type;function withoutSaving(e,t){let n=isSaving(e);eS.set(e,!1),t(),eS.set(e,n)}let addAnnotationOperationImplementation=({context:e,operation:t})=>{let n,o,i;let r=(0,g.Qe)({annotation:{_type:t.annotation.name,...t.annotation.value},context:e,options:{refreshKeys:!1,validateFields:!0}});if(!r)throw Error(`Failed to parse annotation ${JSON.stringify(t.annotation)}`);let a=t.editor;if(!a.selection||p.e6.isCollapsed(a.selection))return;let l=[],s=p.ML.nodes(a,{at:a.selection,match:e=>a.isTextBlock(e),reverse:p.e6.isBackward(a.selection)}),c=0;for(let[t,n]of s){if(0===t.children.length||1===t.children.length&&""===t.children[0].text)continue;let s=0===c?r._key:e.keyGenerator(),d=t.markDefs??[];void 0===d.find(e=>e._type===r._type&&e._key===s)&&(p.YR.setNodes(a,{markDefs:[...d,{...r,_key:s}]},{at:n}),i=[{_key:t._key},"markDefs",{_key:s}],p.e6.isBackward(a.selection)?l.unshift(i):l.push(i)),p.YR.setNodes(a,{},{match:p.xv.isText,split:!0});let u=p.NB.children(a,n);for(let[e,n]of u){if(!a.isTextSpan(e)||!p.e6.includes(a.selection,n))continue;let i=e.marks??[],l=i.filter(e=>d.some(t=>t._key===e&&t._type===r._type));p.YR.setNodes(a,{marks:[...i.filter(e=>!l.includes(e)),s]},{at:n}),o=[{_key:t._key},"children",{_key:e._key}]}c++}return i&&o&&(n={markDefPath:i,markDefPaths:l,spanPath:o}),n},eO={"annotation.add":addAnnotationOperationImplementation,"annotation.remove":({operation:e})=>{let t=e.editor;if(t.selection){if(p.e6.isCollapsed(t.selection)){let[n,o]=p.ML.node(t,t.selection,{depth:1});if(!t.isTextBlock(n))return;let i=(n.markDefs??[]).filter(t=>t._type===e.annotation.name),[r,a]=p.ML.node(t,t.selection,{depth:2});if(!t.isTextSpan(r))return;let l=r.marks?.find(e=>i.some(t=>t._key===e));if(!l)return;let s=[];for(let[e,n]of p.NB.children(t,o,{reverse:!0}))if(t.isTextSpan(e)&&p.y$.isBefore(n,a)){if(e.marks?.includes(l))s.push([e,n]);else break}let c=[];for(let[e,n]of p.NB.children(t,o))if(t.isTextSpan(e)&&p.y$.isAfter(n,a)){if(e.marks?.includes(l))c.push([e,n]);else break}for(let[e,n]of[...s,[r,a],...c])p.YR.setNodes(t,{marks:e.marks?.filter(e=>e!==l)},{at:n})}else{p.YR.setNodes(t,{},{match:e=>t.isTextSpan(e),split:!0,hanging:!0});let n=p.ML.nodes(t,{at:t.selection,match:e=>t.isTextBlock(e)});for(let[o,i]of n){let n=p.NB.children(t,i);
3for(let[i,r]of n){if(!t.isTextSpan(i)||!p.e6.includes(t.selection,r))continue;let n=o.markDefs??[],a=i.marks??[],l=a.filter(t=>n.find(e=>e._key===t)?._type!==e.annotation.name);l.length!==a.length&&p.YR.setNodes(t,{marks:l},{at:r})}}}}},"block.set":({context:e,operation:t})=>{let n=toSlateRange({context:{schema:e.schema,value:t.editor.value,selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:0}}},blockIndexMap:t.editor.blockIndexMap});if(!n)throw Error(`Unable to convert ${JSON.stringify(t.at)} into a Slate Range`);let o=p.ML.node(t.editor,n,{depth:1})?.[0];if(!o)throw Error(`Unable to find block at ${JSON.stringify(t.at)}`);let i=fromSlateValue([o],e.schema.block.name,H.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,g.IX)({context:e,block:{...i,...a},options:{refreshKeys:!1,validateFields:!0}});if(!l)throw Error(`Unable to update block at ${JSON.stringify(t.at)}`);let s=toSlateValue([l],{schemaTypes:e.schema})?.at(0);if(!s)throw Error("Unable to convert block to Slate value");p.YR.setNodes(t.editor,s,{at:n})},"block.unset":({context:e,operation:t})=>{let n=toSlateRange({context:{schema:e.schema,value:t.editor.value,selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:0}}},blockIndexMap:t.editor.blockIndexMap});if(!n)throw Error(`Unable to convert ${JSON.stringify(t.at)} into a Slate Range`);let o=p.ML.node(t.editor,n,{depth:1})?.[0];if(!o)throw Error(`Unable to find block at ${JSON.stringify(t.at)}`);let i=fromSlateValue([o],e.schema.block.name,H.get(t.editor)).at(0);if(!i)throw Error(`Unable to parse block at ${JSON.stringify(t.at)}`);if((0,g.dz)(e,i)){let o=t.props.filter(e=>"_type"!==e),r=(0,g.IX)({context:e,block:A(i,o),options:{refreshKeys:!1,validateFields:!0}});if(!r)throw Error(`Unable to update block at ${JSON.stringify(t.at)}`);let a={};for(let e of o)e in r?a[e]=r[e]:a[e]=void 0;p.YR.setNodes(t.editor,a,{at:n});return}let r=(0,g.IX)({context:e,block:A(i,t.props.filter(e=>"_type"!==e)),options:{refreshKeys:!1,validateFields:!0}});if(!r)throw Error(`Unable to update block at ${JSON.stringify(t.at)}`);let{_type:a,_key:l,...s}=r;p.YR.setNodes(t.editor,{_type:a,_key:l,value:s},{at:n})},"child.set":({context:e,operation:t})=>{let n=toSlateRange({context:{schema:e.schema,value:t.editor.value,selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:0}}},blockIndexMap:t.editor.blockIndexMap});if(!n)throw Error(`Unable to convert ${JSON.stringify(t.at)} into a Slate Range`);let o=p.ML.node(t.editor,n,{depth:2}),i=o?.[0],r=o?.[1];if(!i||!r)throw Error(`Unable to find child at ${JSON.stringify(t.at)}`);if(t.editor.isTextSpan(i)){let{_type:e,text:n,...o}=t.props;p.YR.setNodes(t.editor,{...i,...o},{at:r}),"string"==typeof n&&i.text!==n&&(t.editor.apply({type:"remove_text",path:r,offset:0,text:i.text}),t.editor.apply({type:"insert_text",path:r,offset:0,text:n}));return}if(p.W_.isElement(i)){let n=e.schema.inlineObjects.find(e=>e.name===i._type);if(!n)throw Error(`Unable to find schema definition for Inline Object type ${i._type}`);let o="value"in i&&"object"==typeof i.value?i.value:{},{_type:a,_key:l,...s}=t.props;for(let e in s)n.fields.some(t=>t.name===e)||delete s[e];p.YR.setNodes(t.editor,{...i,_key:"string"==typeof l?l:i._key,value:{...o,...s}},{at:r});return}throw Error(`Unable to determine the type of child at ${JSON.stringify(t.at)}`)},"child.unset":({context:e,operation:t})=>{let n=toSlateRange({context:{schema:e.schema,value:t.editor.value,selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:0}}},blockIndexMap:t.editor.blockIndexMap});if(!n)throw Error(`Unable to convert ${JSON.stringify(t.at)} into a Slate Range`);let o=p.ML.node(t.editor,n,{depth:2}),i=o?.[0],r=o?.[1];if(!i||!r)throw Error(`Unable to find child at ${JSON.stringify(t.at)}`);if(t.editor.isTextSpan(i)){t.props.includes("text")&&t.editor.apply({type:"remove_text",path:r,offset:0,text:i.text});let n={};for(let o of t.props)if("_type"!==o){if("_key"===o){n._key=e.keyGenerator();continue}n[o]=null}p.YR.setNodes(t.editor,n,{at:r});return}if(p.W_.isElement(i)){let n="value"in i&&"object"==typeof i.value?i.value:{},o=t.props.map(e=>({type:"unset",path:[e]})),a=(0,I.g7)(n,o);p.YR.setNodes(t.editor,{...i,_key:t.props.includes("_key")?e.keyGenerator():i._key,value:a},{at:r});return}throw Error(`Unable to determine the type of child at ${JSON.stringify(t.at)}`)},"decorator.add":({context:e,operation:t})=>{let n=t.editor,o=t.decorator,i=fromSlateValue(n.children,e.schema.block.name,H.get(n)),r=t.at?.anchor?(0,g.MR)({context:{...e,value:i},blockOffset:t.at.anchor,direction:"backward"}):void 0,a=t.at?.focus?(0,g.MR)({context:{...e,value:i},blockOffset:t.at.focus,direction:"forward"}):void 0,l=r&&a?{anchor:r,focus:a}:void 0,s=l?toSlateRange({context:{schema:e.schema,value:t.editor.value,selection:l},blockIndexMap:t.editor.blockIndexMap})??n.selection:n.selection;if(!s)return;let c=slateRangeToSelection({schema:e.schema,editor:n,range:s}),d=c?(0,D.W)({context:{...e,value:i},selectionPoint:c.anchor}):void 0,u=c?(0,D.W)({context:{...e,value:i},selectionPoint:c.focus}):void 0;if(!d||!u)throw Error("Unable to find anchor or focus offset");if(p.e6.isExpanded(s)){p.YR.setNodes(n,{},{at:s,match:p.xv.isText,split:!0,hanging:!0});let i=fromSlateValue(n.children,e.schema.block.name,H.get(n)),r=(0,P.iO)({context:{...e,value:i},offsets:{anchor:d,focus:u},backward:c?.backward}),a=(0,v.Vj)({blockIndexMap:n.blockIndexMap,context:{converters:[],keyGenerator:e.keyGenerator,readOnly:!1,schema:e.schema,selection:r,value:i},decoratorState:n.decoratorState});if(!a)throw Error("Unable to find trimmed selection");let l=toSlateRange({context:{schema:e.schema,value:t.editor.value,selection:a},blockIndexMap:t.editor.blockIndexMap});if(!l)throw Error("Unable to find new selection");let h=p.e6.isRange(l)?[...p.ML.nodes(n,{at:l,match:e=>p.xv.isText(e)})]:[];for(let[e,t]of h){let i=[...(Array.isArray(e.marks)?e.marks:[]).filter(e=>e!==o),o];p.YR.setNodes(n,{marks:i},{at:t,match:p.xv.isText,split:!0,hanging:!0})}}else{if(!Array.from(p.ML.nodes(n,{at:s,match:e=>n.isTextSpan(e)}))?.at(0))return;let[e,t]=p.ML.node(n,s,{depth:1}),i=n.isTextBlock(e)&&1===e.children.length&&n.isTextSpan(e.children[0])&&""===e.children[0].text?e.children[0]:void 0;if(i){let e=i.marks??[],r=e.filter(e=>e!==o);p.YR.setNodes(n,{marks:e.length===r.length?[...e,o]:r},{at:t,match:e=>n.isTextSpan(e)})}else n.decoratorState[o]=!0}if(n.selection){let e=n.selection;n.selection={...e}}},"decorator.remove":({operation:e})=>{let t=e.editor,n=e.decorator,{selection:o}=t;if(o){if(p.e6.isExpanded(o))p.YR.setNodes(t,{},{match:p.xv.isText,split:!0,hanging:!0}),t.selection&&[...p.ML.nodes(t,{at:t.selection,match:p.xv.isText}
3)].forEach(([e,o])=>{let i=t.children[o[0]];p.W_.isElement(i)&&i.children.includes(e)&&p.YR.setNodes(t,{marks:(Array.isArray(e.marks)?e.marks:[]).filter(e=>e!==n),_type:"span"},{at:o})});else{let[e,i]=p.ML.node(t,o,{depth:1}),r=t.isTextBlock(e)&&1===e.children.length&&t.isTextSpan(e.children[0])&&""===e.children[0].text?e.children[0]:void 0;if(r){let e=(r.marks??[]).filter(e=>e!==n);p.YR.setNodes(t,{marks:e},{at:i,match:e=>t.isTextSpan(e)})}else t.decoratorState[n]=!1}if(t.selection){let e=t.selection;t.selection={...e}}}},delete:({context:e,operation:t})=>{let n=(0,g.Ak)(t.at.anchor),o=(0,g.Ak)(t.at.focus),i=t.at.backward?n:o,r=t.at.backward?t.at.focus.offset:t.at.anchor.offset;if(!i)throw Error("Failed to get end block key");let a=t.editor.blockIndexMap.get(i);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?getBlockPath({editor:t.editor,_key:n}):void 0,c=void 0!==o?getBlockPath({editor:t.editor,_key:o}):void 0;if(1===t.at.anchor.path.length&&1===t.at.focus.path.length&&s&&c&&s[0]===c[0]){p.YR.removeNodes(t.editor,{at:[s[0]]}),0===t.editor.children.length&&p.YR.insertNodes(t.editor,createPlaceholderBlock(e));return}let d=toSlateRange({context:{schema:e.schema,value:t.editor.value,selection:t.at},blockIndexMap:t.editor.blockIndexMap});if(!d)throw Error(`Failed to get Slate Range for selection ${JSON.stringify(t.at)}`);let u=(0,g.dz)(e,l)&&0===r;t.editor.delete({at:d,reverse:"backward"===t.direction,unit:t.unit,hanging:u})},"history.redo":({operation:e})=>{let t=e.editor,{redos:n}=t.history,o=getRemotePatches(t);if(n.length>0){let e=n[n.length-1];if(eE("Redoing",e),e.operations.length>0){let n=o.filter(t=>t.time>=e.timestamp),i=e.operations;n.forEach(e=>{i=C(i.map(n=>transformOperation(t,e.patch,n,e.snapshot,e.previousSnapshot)))});try{p.ML.withoutNormalizing(t,()=>{!function(e,t){let n=isRedoing(e);er.set(e,!0),t(),er.set(e,n)}(t,()=>{withoutSaving(t,()=>{i.forEach(e=>{t.apply(e)})})})})}catch(e){eE("Could not perform redo step",e),o.splice(0,o.length),p.YR.deselect(t),t.history={undos:[],redos:[]},eS.set(t,!0),er.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=getRemotePatches(t);if(n.length>0){let e=n[n.length-1];if(eE("Undoing",e),e.operations.length>0){let n=o.filter(t=>t.time>=e.timestamp),i=e.operations;n.forEach(e=>{i=C(i.map(n=>transformOperation(t,e.patch,n,e.snapshot,e.previousSnapshot)))});let r=i.map(p.OX.inverse).reverse();try{p.ML.withoutNormalizing(t,()=>{!function(e,t){let n=isUndoing(e);ei.set(e,!0),t(),ei.set(e,n)}(t,()=>{withoutSaving(t,()=>{r.forEach(e=>{t.apply(e)})})})})}catch(e){eE("Could not perform undo step",e),o.splice(0,o.length),p.YR.deselect(t),t.history={undos:[],redos:[]},eS.set(t,!0),ei.set(t,!1),t.onChange();return}t.history.redos.push(e),t.history.undos.pop()}}},"insert.block":({context:e,operation:t})=>{let n=(0,g.IX)({block:t.block,context:e,options:{refreshKeys:!1,validateFields:!0}});if(!n)throw Error(`Failed to parse block ${JSON.stringify(t.block)}`);let o=toSlateValue([n],{schemaTypes:e.schema})[0];if(!o)throw Error(`Failed to convert block to Slate fragment ${JSON.stringify(n)}`);!function({block:e,placement:t,select:n,editor:o,schema:i}){let[r,a]=function({editor:e}){if(!e.selection)return[void 0,void 0];let t=p.e6.start(e.selection);return getPointBlock({editor:e,point:t})}({editor:o}),[l,s]=function({editor:e}){if(!e.selection)return[void 0,void 0];let t=p.e6.end(e.selection);return getPointBlock({editor:e,point:t})}({editor:o});if(o.selection&&r&&a&&l&&s){if("before"===t){let t=o.selection,i=p.e6.start(t);p.YR.insertNodes(o,[e],{at:[i.path[0]],select:!1}),"start"===n?p.YR.select(o,p.ML.start(o,[i.path[0]])):"end"===n&&p.YR.select(o,p.ML.end(o,[i.path[0]]))}else if("after"===t){let t=o.selection,i=[p.e6.end(t).path[0]+1];p.YR.insertNodes(o,[e],{at:i,select:!1}),"start"===n?p.YR.select(o,p.ML.start(o,i)):"end"===n&&p.YR.select(o,p.ML.end(o,i))}else{let t=o.selection,r=p.ML.start(o,s);if(p.e6.isExpanded(t)&&!o.isTextBlock(e)){p.YR.delete(o,{at:t});let r=o.selection,[a,l]=getFocusBlock({editor:o});p.YR.insertNodes(o,[e],{voids:!0});let s=0===r.anchor.offset?p.e6.transform(r,{type:"insert_node",node:e,path:[r.anchor.path[0]]}):r;"none"===n&&s&&p.YR.select(o,s),a&&isEqualToEmptyEditor([a],i)&&p.YR.removeNodes(o,{at:l});return}if(o.isTextBlock(l)&&o.isTextBlock(e)){let a=p.e6.start(t);
3if(isEqualToEmptyEditor([l],i)){let t=o.selection;p.YR.insertNodes(o,[e],{at:s,select:!1}),p.YR.removeNodes(o,{at:p.y$.next(s)}),"start"===n?p.YR.select(o,a):"end"===n?p.YR.select(o,p.ML.end(o,s)):p.YR.select(o,t);return}if(p.YR.setNodes(o,{markDefs:[...l.markDefs??[],...e.markDefs??[]]},{at:s}),"end"===n){p.YR.insertFragment(o,[e],{voids:!0});return}p.YR.insertFragment(o,[e],{at:t,voids:!0}),"start"===n?p.YR.select(o,a):p.E9.equals(a,r)||p.YR.select(o,a)}else if(o.isTextBlock(l)){let r=p.ML.start(o,s),a=p.ML.end(o,s),c=p.e6.start(t),d=p.e6.end(t);if(p.e6.isCollapsed(t)&&p.E9.equals(c,r))p.YR.insertNodes(o,[e],{at:s,select:!1}),("start"===n||"end"===n)&&p.YR.select(o,p.ML.start(o,s)),(0,y.PF)({schema:i},l)&&p.YR.removeNodes(o,{at:p.y$.next(s)});else if(p.e6.isCollapsed(t)&&p.E9.equals(d,a)){let t=[s[0]+1];p.YR.insertNodes(o,[e],{at:t,select:!1}),("start"===n||"end"===n)&&p.YR.select(o,p.ML.start(o,t))}else if(p.e6.isExpanded(t)&&p.E9.equals(c,r)&&p.E9.equals(d,a))p.YR.insertFragment(o,[e],{at:t}),"start"===n?p.YR.select(o,p.ML.start(o,s)):"end"===n&&p.YR.select(o,p.ML.end(o,s));else if(p.e6.isExpanded(t)&&p.E9.equals(c,r))p.YR.insertFragment(o,[e],{at:t}),"start"===n?p.YR.select(o,p.ML.start(o,s)):"end"===n&&p.YR.select(o,p.ML.end(o,s));else if(p.e6.isExpanded(t)&&p.E9.equals(d,a))p.YR.insertFragment(o,[e],{at:t}),"start"===n?p.YR.select(o,p.ML.start(o,p.y$.next(s))):"end"===n&&p.YR.select(o,p.ML.end(o,p.y$.next(s)));else{let t=o.selection,[i]=function({editor:e}){let[t,n]=getFocusBlock({editor:e}),o=e.selection?.focus.path.at(1);if(!t||!n||void 0===o)return[void 0,void 0];try{let e=p.NB.child(t,o);return e?[e,[...n,o]]:[void 0,void 0]}catch{return[void 0,void 0]}}({editor:o});if(i&&o.isTextSpan(i))p.YR.splitNodes(o,{at:t}),p.YR.insertFragment(o,[e],{at:t}),"start"===n||"end"===n?p.YR.select(o,[s[0]+1]):p.YR.select(o,t);else{let i=[s[0]+1];p.YR.insertNodes(o,[e],{at:i,select:!1}),p.YR.select(o,t),"start"===n?p.YR.select(o,p.ML.start(o,i)):"end"===n&&p.YR.select(o,p.ML.end(o,i))}}}else{p.YR.insertNodes(o,[e],{select:!1});let t=[s[0]+1];"start"===n?p.YR.select(o,p.ML.start(o,t)):"end"===n&&p.YR.select(o,p.ML.end(o,t))}}}else{"none"!==n&&f.y2.focus(o);let[r,a]=getLastBlock({editor:o});if("before"===t)p.YR.insertNodes(o,[e],{at:[0]}),"start"===n?p.YR.select(o,p.ML.start(o,[0])):"end"===n&&p.YR.select(o,p.ML.end(o,[0]));else if("after"===t){let t=a?[a[0]+1]:[0];p.YR.insertNodes(o,[e],{at:t}),"start"===n?p.YR.select(o,p.ML.start(o,t)):"end"===n&&p.YR.select(o,p.ML.end(o,t))}else{if(r&&isEqualToEmptyEditor([r],i)){p.YR.removeNodes(o,{at:a}),p.YR.insertNodes(o,[e],{at:a,select:!1}),p.YR.deselect(o),"start"===n?p.YR.select(o,p.ML.start(o,a)):"end"===n&&p.YR.select(o,p.ML.end(o,a));return}if(o.isTextBlock(e)&&r&&o.isTextBlock(r)){let t=p.ML.end(o,a);p.YR.insertFragment(o,[e],{at:p.ML.end(o,a)}),"start"===n?p.YR.select(o,t):"none"===n&&p.YR.deselect(o);return}let t=a?[a[0]+1]:[0];p.YR.insertNodes(o,[e],{at:t,select:!1}),"start"===n?p.YR.select(o,p.ML.start(o,t)):"end"===n&&p.YR.select(o,p.ML.end(o,t))}}}({block:o,placement:t.placement,select:t.select??"start",editor:t.editor,schema:e.schema})},"insert.inline object":({context:e,operation:t})=>{let n=(0,g.Kw)({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){console.error("Unable to insert inline object without selection");return}let[o]=Array.from(p.ML.nodes(t.editor,{at:t.editor.selection.focus.path,match:e=>t.editor.isTextBlock(e)})).at(0)??[void 0,void 0];if(!o){console.error("Unable to perform action without focus text block");return}let i=toSlateValue([{_type:e.schema.block.name,_key:e.keyGenerator(),children:[n]}],{schemaTypes:e.schema}).at(0)?.children.at(0);if(!i){console.error("Unable to insert inline object");return}p.YR.insertNodes(t.editor,i)},"insert.span":({context:e,operation:t})=>{if(!t.editor.selection){console.error("Unable to perform action without selection",t);return}let[n,o]=Array.from(p.ML.nodes(t.editor,{at:t.editor.selection.focus.path,match:e=>t.editor.isTextBlock(e)}))[0]??[void 0,void 0];if(!n||!o){console.error("Unable to perform action without focus block",t);return}let i=n.markDefs??[],r=t.annotations?t.annotations.map(t=>({_type:t.name,_key:e.keyGenerator(),...t.value})):void 0;r&&r.length>0&&p.YR.setNodes(t.editor,{markDefs:[...i,...r]}),p.YR.insertNodes(t.editor,{_type:"span",_key:e.keyGenerator(),text:t.text,marks:[...r?.map(e=>e._key)??[],...t.decorators??[]]})},"insert.text":insertTextOperationImplementation,"move.backward":({operation:e})=>{p.YR.move(e.editor,{unit:"character",distance:e.distance,reverse:!0})},"move.block":({operation:e})=>{let t=(0,g.Ak)({path:e.at});if(!t)throw Error("Failed to get block key from selection point");let n=e.editor.blockIndexMap.get(t);if(void 0===n)throw Error("Failed to get block index from block key");let o=(0,g.Ak)({path:e.to});if(!o)throw Error("Failed to get block key from selection point");let i=e.editor.blockIndexMap.get(o);if(void 0===i)throw Error("Failed to get block index from block key");p.YR.moveNodes(e.editor,{at:[n],to:[i],mode:"highest"})},"move.forward":({operation:e})=>{p.YR.move(e.editor,{unit:"character",distance:e.distance})},select:({context:e,operation:t})=>{let n=toSlateRange({context:{schema:e.schema,value:t.editor.value,selection:t.at},blockIndexMap:t.editor.blockIndexMap});n?p.YR.select(t.editor,n):p.YR.deselect(t.editor)}};function performOperation({context:e,operation:t}){try{switch(t.type){case"annotation.add":eO["annotation.add"]({context:e,operation:t});break;case"annotation.remove":eO["annotation.remove"]({context:e,operation:t});break;case"block.set":eO["block.set"]({context:e,operation:t});break;case"block.unset":eO["block.unset"]({context:e,operation:t});break;case"child.set":eO["child.set"]({context:e,operation:t});break;case"child.unset":eO["child.unset"]({context:e,operation:t});break;case"decorator.add":eO["decorator.add"]({context:e,operation:t});break;case"decorator.remove":eO["decorator.remove"]({context:e,operation:t});break;case"delete":eO.delete({context:e,operation:t});break;case"history.redo":eO["history.redo"]({context:e,operation:t});break;case"history.undo":eO["history.undo"]({context:e,operation:t});break;case"insert.block":eO["insert.block"]({context:e,operation:t});break;case"insert.inline object":eO["insert.inline object"]({context:e,operation:t});break;case"insert.span":eO["insert.span"]({context:e,operation:t});break;case"insert.text":eO["insert.text"]({context:e,operation:t});break;case"move.backward":eO["move.backward"]({context:e,operation:t});break;case"move.block":eO["move.block"]({context:e,operation:t});break;case"move.forward":eO["move.forward"]({context:e,operation:t});break;default:eO.select({context:e,operation:t})}}catch(e){console.error(Error(`Executing "${t.type}" failed due to: ${e.message}`))}}let eR=new WeakMap;function withApplyingBehaviorOperations(e,t){eR.set(e,defaultKeyGenerator()),p.ML.withoutNormalizing(e,t),eR.set(e,void 0)}function isApplyingBehaviorOperations(e){return void 0!==eR.get(e)}function findBlock(e,t){let n=-1,o=e.find((e,o)=>{let i=(0,g.eD)(t[0])?e._key===t[0]._key:o===t[0];return i&&(n=o),i});if(o)return{node:o,index:n}}function findBlockChild(e,t){let n=e.node;if(!p.W_.isElement(n)||"children"!==t[1])return;let o=-1,i=n.children.find((e,n)=>{let i=(0,g.eD)(t[2])?e._key===t[2]._key:n===t[2];return i&&(o=n),i});if(i)return{node:i,index:o}}let eB=new WeakMap;function withoutPatching(e,t){let n=eB.get(e);eB.set(e,!1),t(),eB.set(e,n)}let eT=debugWithName("plugin:withPatches"),eN=debugWithName("plugin:withPlaceholderBlock"),eM=debugWithName("plugin:withSchemaTypes");function isEditorNode(e){return"object"==typeof e&&null!==e&&!("_type"in e)&&"children"in e&&Array.isArray(e.children)}function isTextBlockNode(e,t){return(0,g.ay)(t)&&t._type===e.schema.block.name}function isSpanNode(e,t){return"object"==typeof t&&null!==t&&!("children"in t)&&("_type"in t?t._type===e.schema.span.name:"text"in t)}function isPartialSpanNode(e){return"object"==typeof e&&null!==e&&"text"in e&&"string"==typeof e.text}function getBlock(e,t){let n=t.at(0);if(!(void 0===n||1!==t.length))return e.children.at(n)}function getNode(e,t,n){if(0===n.length)return t;if(1===n.length)return getBlock(t,n);if(2===n.length){let o=getBlock(t,n.slice(0,1));return o&&isTextBlockNode(e,o)&&o.children.at(n[1])||void 0}}function getSpan(e,t,n){let o=getNode(e,t,n);if(o&&isSpanNode(e,o))return o}function getParent(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&&isTextBlockNode(e,r))return r}let withPlugins=(e,t)=>{let{editorActor:n,relayActor:o}=t,i=function({editorActor:e}){return function(t){t.isTextBlock=t=>!p.ML.isEditor(t)&&(0,g.dz)(e.getSnapshot().context,t),t.isTextSpan=t=>!p.ML.isEditor(t)&&(0,g.dn)(e.getSnapshot().context,t),t.isListBlock=t=>!p.ML.isEditor(t)&&(0,g.cd)(e.getSnapshot().context,t),t.isVoid=t=>!p.ML.isEditor(t)&&e.getSnapshot().context.schema.block.name!==t._type&&(e.getSnapshot().context.schema.blockObjects.map(e=>e.name).includes(t._type)||e.getSnapshot().context.schema.inlineObjects.map(e=>e.name).includes(t._type)),t.isInline=t=>!p.ML.isEditor(t)&&e.getSnapshot().context.schema.inlineObjects.map(e=>e.name).includes(t._type)&&"__inline"in t&&!0===t.__inline;let{normalizeNode:n}=t;return t.normalizeNode=o=>{let[i,r]=o;if(void 0===i._type&&2===r.length){eM("Setting span type on text node without a type");let n=i._key||e.getSnapshot().context.keyGenerator();e.send({type:"normalizing"}),p.YR.setNodes(t,{...i,_type:e.getSnapshot().context.schema.span.name,_key:n},{at:r}),e.send({type:"done normalizing"});return}if(void 0===i._key&&(1===r.length||2===r.length)){eM("Setting missing key on child node without a key");let n=e.getSnapshot().context.keyGenerator();e.send({type:"normalizing"}),p.YR.setNodes(t,{_key:n},{at:r}),e.send({type:"done normalizing"});return}n(o)},t}}({editorActor:n}),r=function({editorActor:e,relayActor:t,subscriptions:n}){var o;let i;let r=(o=e.getSnapshot().context.schema,(e,t)=>{let n=!1;
3try{switch(t.type){case"insert":n=function(e,t,n){let o=findBlock(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=toSlateValue(i,{schemaTypes:n},q.get(e)),l=o.index,s=isEqualToEmptyEditor(e.children,n);return p.YR.insertNodes(e,a,{at:["after"===r?l+1:l]}),s&&"number"==typeof t.path[0]&&0===t.path[0]&&p.YR.removeNodes(e,{at:["before"===r?l+1:l]}),!0}let{items:i,position:r}=t,a=findBlockChild(o,t.path);if(!a)return!1;let l=toSlateValue([{...o.node,children:i}],{schemaTypes:n},q.get(e)),s="after"===r?a.index+1:a.index,c=[o.index,s];return l&&p.W_.isElement(l[0])&&p.YR.insertNodes(e,l[0].children,{at:c}),!0}(e,t,o);break;case"unset":n=function(e,t){if(0===t.path.length){let t=e.selection;p.YR.deselect(e);let n=p.NB.children(e,[],{reverse:!0});for(let[t,o]of n)p.YR.removeNodes(e,{at:o});return p.YR.insertNodes(e,e.pteCreateTextBlock({decorators:[]})),t&&p.YR.select(e,{anchor:{path:[0,0],offset:0},focus:{path:[0,0],offset:0}}),e.onChange(),!0}let n=findBlock(e.children,t.path);if(!n)return!1;if(1===t.path.length){if(1===e.children.length){let t=e.selection;return p.YR.deselect(e),p.YR.removeNodes(e,{at:[n.index]}),p.YR.insertNodes(e,e.pteCreateTextBlock({decorators:[]})),t&&p.YR.select(e,{anchor:{path:[0,0],offset:0},focus:{path:[0,0],offset:0}}),e.onChange(),!0}return p.YR.removeNodes(e,{at:[n.index]}),!0}let o=findBlockChild(n,t.path);if(e.isTextBlock(n.node)&&o&&"children"===t.path[1]&&3===t.path.length)return p.YR.removeNodes(e,{at:[n.index,o.index]}),!0;if(o&&!p.xv.isText(o.node)){let i=t.path.slice(3).at(0);if(void 0===i||"string"==typeof i&&["_key","_type","children","__inline"].includes(i))return!1;let r="value"in o.node&&"object"==typeof o.node.value?o.node.value:{},a=(0,I.g7)(r,[{...t,path:t.path.slice(3)}]);return p.YR.setNodes(e,{...o.node,value:a},{at:[n.index,o.index]}),!0}if(o&&p.xv.isText(o.node)){let i=t.path.slice(3),r=i.at(0);if(void 0===r||"string"==typeof r&&["_key","_type"].includes(r))return!1;if("string"==typeof r&&"text"===r)return e.apply({type:"remove_text",path:[n.index,o.index],offset:0,text:o.node.text}),!0;let a=(0,I.g7)(o.node,[{...t,path:i}]),l=Object.keys(a),s=Object.keys(o.node).filter(e=>!l.includes(e));return p.YR.unsetNodes(e,s,{at:[n.index,o.index]}),!0}if(!o&&"value"in n.node){let o=(0,I.g7)(n.node.value,[{...t,path:t.path.slice(1)}]);return p.YR.setNodes(e,{...n.node,value:o},{at:[n.index]}),!0}return!1}(e,t);break;case"set":n=function(e,t){let n=t.value;"string"==typeof t.path[3]&&((n={})[t.path[3]]=t.value);let o=findBlock(e.children,t.path);if(!o)return!1;let i=e.isTextBlock(o.node);if(i&&t.path.length>1&&"children"!==t.path[1])return!1;let r=findBlockChild(o,t.path);if(i&&r){if(p.xv.isText(r.node)){if(p.xv.isText(n)){let t=r.node.text,i=n.text;t!==i&&(e.apply({type:"remove_text",path:[o.index,r.index],offset:0,text:t}),e.apply({type:"insert_text",path:[o.index,r.index],offset:0,text:i}),e.onChange())}else{let n=t.path.slice(3),i=n.at(0);if(void 0===i||"string"==typeof i&&["_key","_type","text"].includes(i))return!1;let a=(0,I.g7)(r.node,[{...t,path:n}]);p.YR.setNodes(e,a,{at:[o.index,r.index]})}}else{let n=t.path.slice(3),i=n.at(0);if(void 0===i||"string"==typeof i&&["_key","_type","children","__inline"].includes(i))return!1;let a="value"in r.node&&"object"==typeof r.node.value?r.node.value:{},l=(0,I.g7)(a,[{...t,path:t.path.slice(3)}]);p.YR.setNodes(e,{...r.node,value:l},{at:[o.index,r.index]})}}else if(p.W_.isElement(o.node)&&1===t.path.length){let{children:t,...i}=n,{children:r,...a}=o.node||{children:void 0};e.apply({type:"set_node",path:[o.index],properties:{...a},newProperties:i});let l=o.node;l.children.forEach((t,n)=>{e.apply({type:"remove_node",path:[o.index,l.children.length-1-n],node:t})}),Array.isArray(t)&&t.forEach((t,n)=>{e.apply({type:"insert_node",path:[o.index,n],node:t})})}else if(o&&"value"in o.node){if(!(t.path.length>1)||"children"===t.path[1])return!1;{let n=(0,I.g7)(o.node.value,[{...t,path:t.path.slice(1)}]);p.YR.setNodes(e,{...o.node,value:n},{at:[o.index]})}}return!0}(e,t);break;case"diffMatchPatch":n=function(e,t){let n=findBlock(e.children,t.path);if(!n)return!1;let o=findBlockChild(n,t.path);if(!o||!(n&&e.isTextBlock(n.node)&&4===t.path.length&&"children"===t.path[1]&&"text"===t.path[3])||!p.xv.isText(o.node))return!1;let i=parse(t.value),[r]=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 advanceTo(e){for(;o<e;){let e=t.codePointAt(i);if(typeof e>"u")return i;o+=utf8len(e),e>65535?i+=2:i+=1}if(!n.allowExceedingIndices&&o!==e)throw Error("Failed to determine byte offset");return i}let r=[];for(let t of e)r.push({diffs:t.diffs.map(e=>cloneDiff(e)),start1:advanceTo(t.start1),start2:advanceTo(t.start2),utf8Start1:t.utf8Start1,utf8Start2:t.utf8Start2,length1:t.length1,length2:t.length2,utf8Length1:t.utf8Length1,utf8Length2:t.utf8Length2});return r}(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=createPatchObject(i-a.length,r-a.length),s=!0;if(""!==a){let e=countUtf8Bytes(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=countUtf8Bytes(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=countUtf8Bytes(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=diffText2(l.diffs)).substring(a.length-t);let c=diffText1(o.diffs).substring(0,t),d=countUtf8Bytes(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=diffText1(i[e].diffs),r,l=-1;if(n.length>32?-1!==(r=match(o,n.substring(0,32),t))&&(-1===(l=match(o,n.substring(n.length-32),t+n.length-32))||r>=l)&&(r=-1):r=match(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)+diffText2(i[e].diffs)+o.substring(r+n.length);else{let t=diff(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=cleanupSemanticLossless(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=xIndex(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+xIndex(t,n+s[1].length))),-1!==s[0]&&(n+=s[1].length)}}}}}return[o=o.substring(l.length,o.length-l.length),c]}(i,o.node.text,{allowExceedingIndices:!0}),a=function(e,t=4){let n=e.map(e=>cloneDiff(e)),o=!1,i=[],r=0,a=null,l=0,s=!1,c=!1,d=!1,p=!1;for(;l<n.length;)0===n[l][0]?(n[l][1].length<t&&(d||p)?(i[r++]=l,s=d,c=p,a=n[l][1]):(r=0,a=null),d=!1,p=!1):(-1===n[l][0]?p=!0:d=!0,a&&(s&&c&&d&&p||a.length<t/2&&3===function(...e){return e.reduce((e,t)=>
3e+(t?1:0),0)}(s,c,d,p))&&(n.splice(i[r-1],0,[-1,a]),n[i[r-1]+1][0]=1,r--,a=null,s&&c?(d=!0,p=!0,r=0):(l=--r>0?i[r-1]:-1,d=!1,p=!1),o=!0)),l++;return o&&(n=cleanupMerge(n)),n}(diff(o.node.text,r),5),l=0;for(let[t,i]of a)1===t?(e.apply({type:"insert_text",path:[n.index,o.index],offset:l,text:i}),l+=i.length):-1===t?e.apply({type:"remove_text",path:[n.index,o.index],offset:l,text:i}):0===t&&(l+=i.length);return!0}(e,t)}}catch(e){console.error(e)}return n});return function(o){W.set(o,!1),eB.set(o,!0),i=[...o.children];let{apply:a}=o,l=[],handleBufferedRemotePatches=()=>{if(0===l.length)return;let e=l;l=[];let t=!1;withRemoteChanges(o,()=>{p.ML.withoutNormalizing(o,()=>{withoutPatching(o,()=>{withoutSaving(o,()=>{for(let n of e){eT.enabled&&eT(`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())})},handlePatches=({patches:e})=>{let t=e.filter(e=>"local"!==e.origin);0!==t.length&&(l=l.concat(t),handleBufferedRemotePatches())};return n.push(()=>{eT("Subscribing to remote patches");let t=e.on("patches",handlePatches);return()=>{eT("Unsubscribing to remote patches"),t.unsubscribe()}}),o.apply=n=>{let r=[];i=o.children;let l=isEqualToEmptyEditor(i,e.getSnapshot().context.schema);a(n);let s=isEqualToEmptyEditor(o.children,e.getSnapshot().context.schema);if(!eB.get(o))return o;switch(l&&!s&&"set_selection"!==n.type&&r.push((0,I.$T)(i,"before",[0])),n.type){case"insert_text":r=[...r,...function(e,t,n,o){let i=(0,g.dz)({schema:e},t[n.path[0]])&&t[n.path[0]];if(!i)throw Error("Could not find block");let r=(0,g.dz)({schema:e},i)&&(0,g.dn)({schema:e},i.children[n.path[1]])&&i.children[n.path[1]];if(!r)throw Error("Could not find child");let a=[{_key:i._key},"children",{_key:r._key},"text"],l=o[n.path[0]],s=(0,g.dz)({schema:e},l)&&l.children[n.path[1]],c=(0,g.dn)({schema:e},s)?s.text:"",d=(0,I.aH)(c,r.text,a);return d.value.length?[d]:[]}(e.getSnapshot().context.schema,o.children,n,i)];break;case"remove_text":r=[...r,...function(e,t,n,o){let i=t[n.path[0]];if(!i)throw Error("Could not find block");let r=(0,g.dz)({schema:e},i)&&i.children[n.path[1]]||void 0,a=(0,g.dn)({schema:e},r)?r:void 0;if(r&&!a)throw Error("Expected span");if(!a)throw Error("Could not find child");let l=[{_key:i._key},"children",{_key:a._key},"text"],s=o[n.path[0]],c=(0,g.dz)({schema:e},s)&&s.children[n.path[1]],d=(0,g.dn)({schema:e},c)&&c.text,p=(0,I.aH)(d||"",a.text,l);return p.value?[p]:[]}(e.getSnapshot().context.schema,o.children,n,i)];break;case"remove_node":r=[...r,...function(e,t,n){let o=t[n.path[0]];if(1===n.path.length){if(o&&o._key)return[(0,I.zN)([{_key:o._key}])];throw Error("Block not found")}if(!(0,g.dz)({schema:e},o)||2!==n.path.length)return[];{let e=o.children[n.path[1]];return e?o.children.filter(e=>e._key===n.node._key).length>1?(console.warn(`Multiple spans have \`_key\` ${n.node._key}. It's ambiguous which one to remove.`,JSON.stringify(o,null,2)),[]):[(0,I.zN)([{_key:o._key},"children",{_key:e._key}])]:[]}}(e.getSnapshot().context.schema,i,n)];break;case"split_node":r=[...r,...function(e,t,n,o){let i=[],r=t[n.path[0]];if(!(0,g.dz)({schema:e},r))throw Error(`Block with path ${JSON.stringify(n.path[0])} is not a text block and can't be split`);if(1===n.path.length){let a=o[n.path[0]];if((0,g.dz)({schema:e},a)){let o=fromSlateValue([t[n.path[0]+1]],e.block.name)[0];o&&(i.push((0,I.$T)([o],"after",[{_key:r._key}])),a.children.slice(n.position).forEach(e=>{let t=[{_key:a._key},"children",{_key:e._key}];i.push((0,I.zN)(t))}))}return i}if(2===n.path.length){let t=r.children[n.path[1]];if((0,g.dn)({schema:e},t)){let o=fromSlateValue([{...r,children:r.children.slice(n.path[1]+1,n.path[1]+2)}],e.block.name)[0].children;i.push((0,I.Cb)([],[{_key:r._key},"children"])),i.push((0,I.$T)(o,"after",[{_key:r._key},"children",{_key:t._key}])),i.push((0,I.t8)(t.text,[{_key:r._key},"children",{_key:t._key},"text"]))}}return i}(e.getSnapshot().context.schema,o.children,n,i)];break;case"insert_node":r=[...r,...function(e,t,n,o){let i=o[n.path[0]];if(1===n.path.length){let t=0===n.path[0]?"before":"after",r=o[n.path[0]-1],a=0===n.path[0]?i?._key:r?._key;return a?[(0,I.$T)([fromSlateValue([n.node],e.block.name)[0]],t,[{_key:a}])]:[(0,I.Cb)(o,[]),(0,I.$T)([fromSlateValue([n.node],e.block.name)[0]],"before",[n.path[0]])]}if((0,g.dz)({schema:e},i)&&2===n.path.length&&t[n.path[0]]){let t=0!==i.children.length&&i.children[n.path[1]-1]?"after":"before",o={...n.node};
3!o._type&&p.xv.isText(o)&&(o._type="span",o.marks=[]);let r=fromSlateValue([{_key:"bogus",_type:e.block.name,children:[o]}],e.block.name)[0].children[0];return[(0,I.Cb)([],[{_key:i._key},"children"]),(0,I.$T)([r],t,[{_key:i._key},"children",i.children.length<=1||!i.children[n.path[1]-1]?0:{_key:i.children[n.path[1]-1]._key}])]}return[]}(e.getSnapshot().context.schema,o.children,n,i)];break;case"set_node":r=[...r,...function(e,t,n){if(1===n.path.length){let o=t[n.path[0]];if("string"!=typeof o._key)throw Error("Expected block to have a _key");let i=U({...t[n.path[0]],...n.newProperties},L);return[(0,I.t8)(fromSlateValue([i],e.block.name)[0],[{_key:o._key}])]}if(2===n.path.length){let o=t[n.path[0]];if((0,g.dz)({schema:e},o)){let e=o.children[n.path[1]];if(e){let t=o._key,i=e._key,r=[],a=Object.keys(n.newProperties);return a.forEach(l=>{if(1===a.length&&"_key"===l){let i=j(n.newProperties,l);r.push((0,I.t8)(i,[{_key:t},"children",o.children.indexOf(e),l]))}else{let e=j(n.newProperties,l);r.push((0,I.t8)(e,[{_key:t},"children",{_key:i},l]))}}),r}throw Error("Could not find a valid child")}throw Error("Could not find a valid block")}throw Error(`Unexpected path encountered: ${JSON.stringify(n.path)}`)}(e.getSnapshot().context.schema,o.children,n)];break;case"merge_node":r=[...r,...function(e,t,n,o){let i=[],r=o[n.path[0]],a=t[n.path[0]];if(1===n.path.length){if(r?._key){let o=fromSlateValue([t[n.path[0]-1]],e.block.name)[0];i.push((0,I.t8)(o,[{_key:o._key}])),i.push((0,I.zN)([{_key:r._key}]))}else throw Error("Target key not found!")}else if((0,g.dz)({schema:e},r)&&(0,g.dz)({schema:e},a)&&2===n.path.length){let t=a.children[n.path[1]-1]&&(0,g.dn)({schema:e},a.children[n.path[1]-1])?a.children[n.path[1]-1]:void 0,o=r.children[n.path[1]]&&(0,g.dn)({schema:e},r.children[n.path[1]])?r.children[n.path[1]]:void 0;t&&(1===r.children.filter(e=>e._key===t._key).length?i.push((0,I.t8)(t.text,[{_key:r._key},"children",{_key:t._key},"text"])):console.warn(`Multiple spans have \`_key\` ${t._key}. It's ambiguous which one to update.`,JSON.stringify(r,null,2))),o&&(1===r.children.filter(e=>e._key===o._key).length?i.push((0,I.zN)([{_key:r._key},"children",{_key:o._key}])):console.warn(`Multiple spans have \`_key\` ${o._key}. It's ambiguous which one to remove.`,JSON.stringify(r,null,2)))}return i}(e.getSnapshot().context.schema,o.children,n,i)];break;case"move_node":r=[...r,...function(e,t,n){let o=[],i=t[n.path[0]],r=t[n.newPath[0]];if(!r)return o;if(1===n.path.length){let t=n.path[0]>n.newPath[0]?"before":"after";o.push((0,I.zN)([{_key:i._key}])),o.push((0,I.$T)([fromSlateValue([i],e.block.name)[0]],t,[{_key:r._key}]))}else if(2===n.path.length&&(0,g.dz)({schema:e},i)&&(0,g.dz)({schema:e},r)){let t=i.children[n.path[1]],a=r.children[n.newPath[1]],l=n.newPath[1]===r.children.length?"after":"before",s=fromSlateValue([i],e.block.name)[0].children[n.path[1]];o.push((0,I.zN)([{_key:i._key},"children",{_key:t._key}])),o.push((0,I.Cb)([],[{_key:r._key},"children"])),o.push((0,I.$T)([s],l,[{_key:r._key},"children",{_key:a._key}]))}return o}(e.getSnapshot().context.schema,i,n)]}if(!l&&s&&["merge_node","set_node","remove_text","remove_node"].includes(n.type)&&(r=[...r,(0,I.zN)([])],t.send({type:"unset",previousValue:fromSlateValue(i,e.getSnapshot().context.schema.block.name,H.get(o))})),l&&r.length>0&&(r=[(0,I.Cb)([],[]),...r]),r.length>0)for(let t of r)e.send({type:"internal.patch",patch:{...t,origin:"local"},operationId:eR.get(o),value:o.value});return o},o}}({editorActor:n,relayActor:o,subscriptions:t.subscriptions}),a=function(e){let{editorActor:t}=e;return n=>{let o=fromSlateValue(n.children,t.getSnapshot().context.schema.block.name),i=getRemotePatches(n),r=getCurrentUndoStepId(n);e.subscriptions.push(()=>{eE("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){eE("Someone else cleared the content, resetting undo/redo history"),n.history={undos:[],redos:[]},i.splice(0,i.length),eS.set(n,!0),r=!0;return}
3i.push({patch:e,time:new Date,snapshot:t,previousSnapshot:o})}}),o=t});return()=>{eE("Unsubscribing to patches"),e.unsubscribe()}}),n.history={undos:[],redos:[]};let{apply:a}=n;return n.apply=e=>{if(t.getSnapshot().matches({"edit mode":"read only"})||isChangingRemotely(n)||isUndoing(n)||isRedoing(n)){a(e);return}let{operations:o,history:i}=n,{undos:l}=i,s=l[l.length-1],c=s&&s.operations&&s.operations[s.operations.length-1],d=shouldOverwrite(e,c),p=isSaving(n),u=getCurrentUndoStepId(n),h=u===r;if(p){if(s?0===o.length&&(h=void 0===u&&void 0===r?shouldMerge(e,c)||d:h):h=!1,s&&h)s.operations.push(e);else{let t={operations:[...null===n.selection?[]:[{type:"set_selection",properties:{...n.selection},newProperties:{...n.selection}}],e],timestamp:new Date};l.push(t),eE("Created new undo step",s)}for(;l.length>1e3;)l.shift();shouldClear(e)&&(i.redos=[])}r=u,a(e)},n}}({editorActor:n,subscriptions:t.subscriptions}),l=function({editorActor:e}){return function(t){return t.pteCreateTextBlock=t=>toSlateValue([{_type:e.getSnapshot().context.schema.block.name,_key:e.getSnapshot().context.keyGenerator(),style:e.getSnapshot().context.schema.styles[0].name||"normal",...t.listItem?{listItem:t.listItem}:{},...t.level?{level:t.level}:{},markDefs:[],children:[{_type:"span",_key:e.getSnapshot().context.keyGenerator(),text:"",marks:t.decorators.filter(t=>e.getSnapshot().context.schema.decorators.find(({name:e})=>e===t))}]}],{schemaTypes:e.getSnapshot().context.schema})[0],t}}({editorActor:n});return function(e){if(void 0!==n.getSnapshot().context.maxBlocks)return e;let{delete:t,select:o}=e;return e.delete=o=>{if(isApplyingBehaviorOperations(e)){t(o);return}let i=o?.at??e.selection;if(!i){console.error("Unexpected call to .delete(...) without `at` option");return}let r=p.ML.range(e,i),a=slateRangeToSelection({schema:n.getSnapshot().context.schema,editor:e,range:r});if(!a){console.error("Unexpected call to .delete(...) with invalid `at` option");return}n.send({type:"behavior event",behaviorEvent:{type:"delete",at:a,direction:o?.reverse?"backward":"forward",unit:o?.unit},editor:e})},e.deleteBackward=t=>{if(isApplyingBehaviorOperations(e)){console.error("Unexpected call to .deleteBackward(...)");return}n.send({type:"behavior event",behaviorEvent:{type:"delete.backward",unit:t},editor:e})},e.deleteForward=t=>{if(isApplyingBehaviorOperations(e)){console.error("Unexpected call to .deleteForward(...)");return}n.send({type:"behavior event",behaviorEvent:{type:"delete.forward",unit:t},editor:e})},e.insertBreak=()=>{if(isApplyingBehaviorOperations(e)){console.error("Unexpected call to .insertBreak(...)");return}n.send({type:"behavior event",behaviorEvent:{type:"insert.break"},editor:e})},e.insertData=t=>{if(isApplyingBehaviorOperations(e)){console.error("Unexpected call to .insertData(...)");return}n.send({type:"behavior event",behaviorEvent:{type:"input.*",originEvent:{dataTransfer:t}},editor:e})},e.insertSoftBreak=()=>{if(isApplyingBehaviorOperations(e)){insertTextOperationImplementation({context:{keyGenerator:n.getSnapshot().context.keyGenerator,schema:n.getSnapshot().context.schema},operation:{text:` 4`,editor:e}});return}n.send({type:"behavior event",behaviorEvent:{type:"insert.soft break"},editor:e})},e.insertText=t=>{if(isApplyingBehaviorOperations(e)){insertTextOperationImplementation({context:{keyGenerator:n.getSnapshot().context.keyGenerator,schema:n.getSnapshot().context.schema},operation:{text:t,editor:e}});return}n.send({type:"behavior event",behaviorEvent:{type:"insert.text",text:t},editor:e})},e.redo=()=>{if(isApplyingBehaviorOperations(e)){performOperation({context:{keyGenerator:n.getSnapshot().context.keyGenerator,schema:n.getSnapshot().context.schema},operation:{type:"history.redo",editor:e}});return}n.send({type:"behavior event",behaviorEvent:{type:"history.redo"},editor:e})},e.select=t=>{if(isApplyingBehaviorOperations(e)){o(t);return}let i=p.ML.range(e,t);n.send({type:"behavior event",behaviorEvent:{type:"select",at:slateRangeToSelection({schema:n.getSnapshot().context.schema,editor:e,range:i})},editor:e})},e.setFragmentData=()=>{console.error("Unexpected call to .setFragmentData(...)")},e.undo=()=>
4{if(isApplyingBehaviorOperations(e)){performOperation({context:{keyGenerator:n.getSnapshot().context.keyGenerator,schema:n.getSnapshot().context.schema},operation:{type:"history.undo",editor:e}});return}n.send({type:"behavior event",behaviorEvent:{type:"history.undo"},editor:e})},e}(i(function(e){let{apply:t,normalizeNode:o}=e;return e.apply=o=>{if(isChangingRemotely(e)||isUndoing(e)||isRedoing(e)){t(o);return}if("split_node"===o.type){let i=[...p.NB.descendants(e)].map(([e])=>e._key);t({...o,properties:{...o.properties,_key:void 0===o.properties._key||i.includes(o.properties._key)?n.getSnapshot().context.keyGenerator():o.properties._key}});return}if("insert_node"===o.type&&!p.ML.isEditor(o.node)){let i=[...p.NB.descendants(e)].map(([e])=>e._key);t({...o,node:{...o.node,_key:void 0===o.node._key||i.includes(o.node._key)?n.getSnapshot().context.keyGenerator():o.node._key}});return}t(o)},e.normalizeNode=t=>{let[i,r]=t;if(p.W_.isElement(i)&&i._type===n.getSnapshot().context.schema.block.name){if(!i._key){n.send({type:"normalizing"}),p.YR.setNodes(e,{_key:n.getSnapshot().context.keyGenerator()},{at:r}),n.send({type:"done normalizing"});return}for(let[t,o]of p.NB.children(e,r))if(!t._key){n.send({type:"normalizing"}),p.YR.setNodes(e,{_key:n.getSnapshot().context.keyGenerator()},{at:o}),n.send({type:"done normalizing"});return}}o(t)},e}(function(e){let{apply:t,normalizeNode:o}=e,i=n.getSnapshot().context.schema.decorators.map(e=>e.name);return e.normalizeNode=t=>{let[i,r]=t;if(e.isTextBlock(i)){let t=p.NB.children(e,r);for(let[o,r]of t){let t=i.children[r[1]+1];if(e.isTextSpan(o)&&e.isTextSpan(t)&&o.marks?.every(e=>t.marks?.includes(e))&&t.marks?.every(e=>o.marks?.includes(e))){ea("Merging spans",JSON.stringify(o,null,2),JSON.stringify(t,null,2)),n.send({type:"normalizing"}),p.YR.mergeNodes(e,{at:[r[0],r[1]+1],voids:!0}),n.send({type:"done normalizing"});return}}}if(e.isTextBlock(i)&&!Array.isArray(i.markDefs)){ea("Adding .markDefs to block node"),n.send({type:"normalizing"}),p.YR.setNodes(e,{markDefs:[]},{at:r}),n.send({type:"done normalizing"});return}if(e.isTextSpan(i)&&!Array.isArray(i.marks)){ea("Adding .marks to span node"),n.send({type:"normalizing"}),p.YR.setNodes(e,{marks:[]},{at:r}),n.send({type:"done normalizing"});return}if(e.isTextSpan(i)){let t=p.y$.parent(r),[o]=p.ML.node(e,t),a=n.getSnapshot().context.schema.decorators.map(e=>e.name),l=i.marks?.filter(e=>!a.includes(e));if(e.isTextBlock(o)&&""===i.text&&l&&l.length>0){ea("Removing annotations from empty span node"),n.send({type:"normalizing"}),p.YR.setNodes(e,{marks:i.marks?.filter(e=>a.includes(e))},{at:r}),n.send({type:"done normalizing"});return}}if(e.isTextBlock(i)){let t=n.getSnapshot().context.schema.decorators.map(e=>e.name);for(let[o,a]of p.NB.children(e,r))if(e.isTextSpan(o)){let r=o.marks??[],l=r.filter(e=>!t.includes(e)&&!i.markDefs?.find(t=>t._key===e));if(l.length>0){ea("Removing orphaned annotations from span node"),n.send({type:"normalizing"}),p.YR.setNodes(e,{marks:r.filter(e=>!l.includes(e))},{at:a}),n.send({type:"done normalizing"});return}}}if(e.isTextSpan(i)){let t=p.y$.parent(r),[o]=p.ML.node(e,t);if(e.isTextBlock(o)){let t=n.getSnapshot().context.schema.decorators.map(e=>e.name),a=i.marks??[],l=a.filter(e=>!t.includes(e)&&!o.markDefs?.find(t=>t._key===e));if(l.length>0){ea("Removing orphaned annotations from span node"),n.send({type:"normalizing"}),p.YR.setNodes(e,{marks:a.filter(e=>!l.includes(e))},{at:r}),n.send({type:"done normalizing"});return}}}if(e.isTextBlock(i)){let t=i.markDefs??[],o=new Set,a=[];for(let e of t)o.has(e._key)||(o.add(e._key),a.push(e));if(t.length!==a.length){ea("Removing duplicate markDefs"),n.send({type:"normalizing"}),p.YR.setNodes(e,{markDefs:a},{at:r}),n.send({type:"done normalizing"});return}}if(e.isTextBlock(i)&&!e.operations.some(e=>"merge_node"===e.type&&"markDefs"in e.properties&&1===e.path.length)){let t=(i.markDefs||[]).filter(e=>i.children.find(t=>p.xv.isText(t)&&Array.isArray(t.marks)&&t.marks.includes(e._key)));if(i.markDefs&&!m(t,i.markDefs)){ea("Removing markDef not in use"),n.send({type:"normalizing"}),p.YR.setNodes(e,{markDefs:t},{at:r}),n.send({type:"done normalizing"});return}}o(t)},e.apply=o=>
4{if(isChangingRemotely(e)||isUndoing(e)||isRedoing(e)){t(o);return}if("set_selection"===o.type&&o.properties&&o.newProperties&&o.properties.anchor&&o.properties.focus&&o.newProperties.anchor&&o.newProperties.focus){let t=p.e6.isCollapsed({anchor:o.properties.anchor,focus:o.properties.focus}),n=p.e6.isCollapsed({anchor:o.newProperties.anchor,focus:o.newProperties.focus});if(t&&n){let t=Array.from(p.ML.nodes(e,{mode:"lowest",at:o.properties.focus,match:t=>e.isTextSpan(t),voids:!1}))[0]?.[0],n=Array.from(p.ML.nodes(e,{mode:"lowest",at:o.newProperties.focus,match:t=>e.isTextSpan(t),voids:!1}))[0]?.[0],i=t&&n&&o.newProperties.focus.path[0]===o.properties.focus.path[0]&&o.newProperties.focus.path[1]===o.properties.focus.path[1]+1&&t.text.length===o.properties.focus.offset&&0===o.newProperties.focus.offset,r=t&&n&&o.newProperties.focus.path[0]===o.properties.focus.path[0]&&o.newProperties.focus.path[1]===o.properties.focus.path[1]-1&&0===o.properties.focus.offset&&n.text.length===o.newProperties.focus.offset;i||r||(e.decoratorState={})}}if("insert_node"===o.type){let{selection:t}=e;if(t){let[r,a]=p.ML.node(e,t,{depth:1}),l=getPreviousSpan({editor:e,blockPath:a,spanPath:o.path}),s=l?l.marks?.filter(e=>!i.includes(e)):[],c=getNextSpan({editor:e,blockPath:a,spanPath:[o.path[0],o.path[1]-1]}),d=c?c.marks?.filter(e=>!i.includes(e)):[],u=s?.filter(e=>!d?.includes(e))??[],h=u.length>0;if(h&&isPortableTextSpan(o.node)&&o.node.marks?.some(e=>u.includes(e))){p.YR.insertNodes(e,{...o.node,_key:n.getSnapshot().context.keyGenerator(),marks:o.node.marks?.filter(e=>!u.includes(e))??[]});return}let f=d?.filter(e=>!s?.includes(e))??[],g=f.length>0;if(g&&isPortableTextSpan(o.node)&&o.node.marks?.some(e=>f.includes(e))){p.YR.insertNodes(e,{...o.node,_key:n.getSnapshot().context.keyGenerator(),marks:o.node.marks?.filter(e=>!f.includes(e))??[]});return}let y=c?.marks?.filter(e=>i.includes(e))??[];if(y.length>0&&h&&!g&&isPortableTextSpan(o.node)&&o.node.marks?.length===0){p.YR.insertNodes(e,{...o.node,_key:n.getSnapshot().context.keyGenerator(),marks:y});return}}}if("insert_text"===o.type){let i=getEditorSnapshot({editorActorSnapshot:n.getSnapshot(),slateEditorInstance:e}),r=(0,v.zd)(i);if(!r||"unchanged"===r.state){t(o);return}p.YR.insertNodes(e,{_type:"span",_key:n.getSnapshot().context.keyGenerator(),text:o.text,marks:r.marks});return}if("remove_text"===o.type){let{selection:a}=e;if(a&&p.e6.isExpanded(a)){var r;let[l,s]=p.ML.node(e,a,{depth:1}),[c,d]=Array.from(p.ML.nodes(e,{mode:"lowest",at:{path:o.path,offset:o.offset},match:t=>e.isTextSpan(t),voids:!1}))[0]??[void 0,void 0];if(c&&l&&"string"==typeof(r=l)._type&&"@"!==r._type[0]&&(!("markDefs"in r)||!r.markDefs||Array.isArray(r.markDefs)&&r.markDefs.every(e=>"string"==typeof e._key))&&"children"in r&&Array.isArray(r.children)&&r.children.every(e=>"object"==typeof e&&"_type"in e)){let r=l.markDefs??[],a=c.marks??[],u=a.some(e=>r.find(t=>t._key===e)),h=o.offset+o.text.length===c.text.length,f=0===o.offset&&h,g=getPreviousSpan({editor:e,blockPath:s,spanPath:d}),y=getNextSpan({editor:e,blockPath:s,spanPath:d}),m=!!g&&g.marks?.some(e=>!i.includes(e)&&a.includes(e)),k=!!y&&y.marks?.some(e=>!i.includes(e)&&a.includes(e));if(u&&f&&!m&&!k){let i=getEditorSnapshot({editorActorSnapshot:n.getSnapshot(),slateEditorInstance:e});p.ML.withoutNormalizing(e,()=>{t(o),p.YR.setNodes(e,{marks:(0,v.WH)(i)},{at:o.path})}),e.onChange();return}}}}if("merge_node"===o.type&&1===o.path.length&&"markDefs"in o.properties&&o.properties._type===n.getSnapshot().context.schema.block.name&&Array.isArray(o.properties.markDefs)&&o.properties.markDefs.length>0&&o.path[0]-1>=0){let[n,i]=p.ML.node(e,[o.path[0]-1]);if(e.isTextBlock(n)){let r=Array.isArray(n.markDefs)&&n.markDefs||[],a=_([...r,...o.properties.markDefs]);ea("Copying markDefs over to merged block",o),p.YR.setNodes(e,{markDefs:a},{at:i,voids:!1}),t(o);return}}t(o)},e}(function(e){let{apply:t}=e;return e.apply=o=>
4{if(n.getSnapshot().matches({"edit mode":"read only"})||isChangingRemotely(e)||isUndoing(e)||isRedoing(e)){t(o);return}if("remove_node"===o.type){let t=o.path.at(0),i=1===o.path.length&&0===t&&1===e.children.length,r=o.node._type!==n.getSnapshot().context.schema.block.name;i&&r&&(eN("Adding placeholder block"),p.ML.insertNode(e,e.pteCreateTextBlock({decorators:[]})))}t(o)},e}(l(function(e){let{apply:t}=e;return e.apply=o=>{if(n.getSnapshot().matches({"edit mode":"read only"})||isChangingRemotely(e)||isUndoing(e)||isRedoing(e)){t(o);return}let i=n.getSnapshot().context.maxBlocks??-1;i>0&&e.children.length>=i&&("insert_node"===o.type||"split_node"===o.type)&&1===o.path.length||t(o)},e}(a(r(function(e,t){let{apply:n}=t;return t.apply=o=>{if("set_selection"===o.type||(t.value=function(e,t,n){let o=(0,Y.P2)({children:t});try{(function(e,t,n){switch(n.type){case"insert_node":{let{path:o,node:i}=n,r=getParent(e,t,o),a=o[o.length-1];if(!r||a>r.children.length)break;if(1===o.length){if(isTextBlockNode(e,i)){r.children.splice(a,0,{...i,children:i.children.map(e=>"__inline"in e?{_key:e._key,_type:e._type,..."value"in e&&"object"==typeof e.value?e.value:{}}:e)});break}if(p.W_.isElement(i)&&!("__inline"in i)){r.children.splice(a,0,{_key:i._key,_type:i._type,..."value"in i&&"object"==typeof i.value?i.value:{}});break}}if(2===o.length){if(!isTextBlockNode(e,r))break;if(isPartialSpanNode(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=getSpan(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=getNode(e,t,o),r=p.y$.previous(o),a=getNode(e,t,r),l=getParent(e,t,o);if(!i||!a||!l)break;let s=o[o.length-1];if(isPartialSpanNode(i)&&isPartialSpanNode(a))a.text+=i.text;else if(isTextBlockNode(e,i)&&isTextBlockNode(e,a))a.children.push(...i.children);else break;l.children.splice(s,1);break}case"move_node":{let{path:o,newPath:i}=n;if(p.y$.isAncestor(o,i))break;let r=getNode(e,t,o),a=getParent(e,t,o),l=o[o.length-1];if(!r||!a)break;a.children.splice(l,1);let s=p.y$.transform(o,n),c=getNode(e,t,p.y$.parent(s)),d=s[s.length-1];if(!c||!("children"in c)||!Array.isArray(c.children))break;c.children.splice(d,0,r);break}case"remove_node":{let{path:o}=n,i=o[o.length-1];getParent(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=getSpan(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=getNode(e,t,o);if(!a||isEditorNode(a))break;if(!isEditorNode(a)&&!isTextBlockNode(e,a)&&!isSpanNode(e,a)&&!isPartialSpanNode(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(isTextBlockNode(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(isPartialSpanNode(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=getParent(e,t,o),l=o[o.length-1];if(!a)break;if(isEditorNode(a)){let n=getBlock(t,o);if(!n||!isTextBlockNode(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(isTextBlockNode(e,a)){let n=getNode(e,t,o);if(!n||!isSpanNode(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,Y._x)(o).children}(e,t.value,o),"insert_text"===o.type||"remove_text"===o.type)){n(o);return}buildIndexMaps({schema:e.schema,value:t.value},{blockIndexMap:t.blockIndexMap,listIndexMap:t.listIndexMap}),n(o)},t}(n.getSnapshot().context,function({editor:e,editorActor:t}){let updateSelection=()=>
4{if(e.selection){let n=J.get(e.selection);if(n)t.send({type:"update selection",selection:n});else{let n=slateRangeToSelection({schema:t.getSnapshot().context.schema,editor:e,range:e.selection});J.set(e.selection,n),t.send({type:"update selection",selection:n})}}else t.send({type:"update selection",selection:null})},{onChange:n}=e;return e.onChange=()=>{n(),t.getSnapshot().matches({setup:"setting up"})||updateSelection()},e}({editorActor:n,editor:e})))))))))))},eC=debugWithName("setup");function createEditorDom(e,t){return{getBlockNodes:e=>(function(e,t){if(!t.context.selection)return[];let n=toSlateRange(t);if(!n)return[];try{return Array.from(p.ML.nodes(e,{at:n,mode:"highest",match:e=>!p.ML.isEditor(e)})).map(([t])=>f.y2.toDOMNode(e,t))}catch{return[]}})(t,e),getChildNodes:e=>(function(e,t){if(!t.context.selection)return[];let n=toSlateRange(t);if(!n)return[];try{return Array.from(p.ML.nodes(e,{at:n,mode:"lowest",match:e=>!p.ML.isEditor(e)})).map(([t])=>f.y2.toDOMNode(e,t))}catch{return[]}})(t,e),setDragGhost:({event:t,ghost:n})=>(function({sendBack:e,event:t,ghost:n}){t.originEvent.dataTransfer.setDragImage(n.element,n.x,n.y),e({type:"set drag ghost",ghost:n.element})})({sendBack:e,event:t,ghost:n})}}let eA=(0,x.gg)({on:"annotation.add",guard:({snapshot:e})=>{if(!(0,k.dI)(e))return!1;let t=(0,v.Ih)(e);return!!(t&&(0,k.sC)({context:{...e.context,selection:t}}))&&{caretWordSelection:t}},actions:[({event:e},{caretWordSelection:t})=>[(0,x.OU)({type:"select",at:t}),(0,x.OU)({type:"annotation.add",annotation:e.annotation})]]}),eI={arrowDown:(0,$.vc)({default:[{key:"ArrowDown",alt:!1,ctrl:!1,meta:!1,shift:!1}]}),arrowUp:(0,$.vc)({default:[{key:"ArrowUp",alt:!1,ctrl:!1,meta:!1,shift:!1}]}),break:(0,$.vc)({default:[{key:"Enter",shift:!1}]}),lineBreak:(0,$.vc)({default:[{key:"Enter",shift:!0}]}),decorators:{strong:$.Se,em:$.pU,underline:$.eC,code:$.TU},history:{undo:$.Yw,redo:$.KX},tab:(0,$.vc)({default:[{key:"Tab",alt:!1,ctrl:!1,meta:!1,shift:!1}]}),shiftTab:(0,$.vc)({default:[{key:"Tab",alt:!1,ctrl:!1,meta:!1,shift:!0}]})},eP=(0,x.gg)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>{if(!eI.arrowDown.guard(t.originEvent)||!(0,k.dI)(e))return!1;let n=(0,v.ii)(e),o=(0,v.st)(e);return n&&!o},actions:[({snapshot:e})=>[(0,x.OU)({type:"insert.block",block:{_type:e.context.schema.block.name},placement:"after"})]]}),eD=(0,x.gg)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>{if(!eI.arrowUp.guard(t.originEvent)||!(0,k.dI)(e))return!1;let n=(0,v.ii)(e),o=(0,v.nt)(e);return n&&!o},actions:[({snapshot:e})=>[(0,x.OU)({type:"insert.block",block:{_type:e.context.schema.block.name},placement:"before"})]]}),ej=(0,x.gg)({on:"insert.break",guard:({snapshot:e})=>{let t=(0,v.ii)(e);return(0,k.dI)(e)&&void 0!==t},actions:[({snapshot:e})=>[(0,x.OU)({type:"insert.block",block:{_type:e.context.schema.block.name},placement:"after"})]]}),eL=(0,x.gg)({on:"mouse.click",guard:({snapshot:e,event:t})=>{if(e.context.readOnly||e.context.selection&&!(0,k.dI)(e))return!1;let n=(0,v.ii)({...e,context:{...e.context,selection:t.position.selection}}),o=(0,v.nt)({...e,context:{...e.context,selection:t.position.selection}});return t.position.isEditor&&"start"===t.position.block&&n&&!o},actions:[({snapshot:e,event:t})=>[(0,x.OU)({type:"select",at:t.position.selection}),(0,x.OU)({type:"insert.block",block:{_type:e.context.schema.block.name},placement:"before",select:"start"})]]}),eU=(0,x.gg)({on:"mouse.click",guard:({snapshot:e,event:t})=>{if(e.context.readOnly||e.context.selection&&!(0,k.dI)(e))return!1;let n=(0,v.ii)({...e,context:{...e.context,selection:t.position.selection}}),o=(0,v.st)({...e,context:{...e.context,selection:t.position.selection}});return t.position.isEditor&&"end"===t.position.block&&n&&!o},actions:[({snapshot:e,event:t})=>[(0,x.OU)({type:"select",at:t.position.selection}),(0,x.OU)({type:"insert.block",block:{_type:e.context.schema.block.name},placement:"after",select:"start"})]]}),eY=(0,x.gg)({on:"delete.backward",guard:({snapshot:e})=>{let t=(0,k.I3)(e),n=(0,k.dI)(e),o=(0,v.nt)(e);return!!t&&!!n&&!!o&&!!(0,y.PF)(e.context,t.node)&&!(0,g.dz)(e.context,o.node)&&{focusTextBlock:t,previousBlock:o}},actions:[(e,{focusTextBlock:t,previousBlock:n})=>[(0,x.OU)({type:"delete.block",at:t.path}),(0,x.OU)({type:"select",at:{anchor:{path:n.path,offset:0},focus:{path:n.path,offset:0}}})]]}),e$=(0,x.gg)({on:"delete.forward",guard:({snapshot:e})=>{let t=(0,k.I3)(e),n=(0,k.dI)(e),o=(0,v.st)(e);return!!t&&!!n&&!!o&&!!(0,y.PF)(e.context,t.node)&&!(0,g.dz)(e.context,o.node)&&{focusTextBlock:t,nextBlock:o}},actions:[(e,{focusTextBlock:t,nextBlock:n})=>[(0,x.OU)({type:"delete.block",at:t.path}),(0,x.OU)({type:"select",at:{anchor:{path:n.path,offset:0},focus:{path:n.path,offset:0}}})]]}),ez={arrowDownOnLonelyBlockObject:eP,arrowUpOnLonelyBlockObject:eD,breakingBlockObject:ej,clickingAboveLonelyBlockObject:eL,clickingBelowLonelyBlockObject:eU,deletingEmptyTextBlockAfterBlockObject:eY,deletingEmptyTextBlockBeforeBlockObject:e$},eV={strongShortcut:(0,x.gg)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>eI.decorators.strong.guard(t.originEvent)&&e.context.schema.decorators.some(e=>"strong"===e.name),actions:[()=>[(0,x.OU)({type:"decorator.toggle",decorator:"strong"})]]}),emShortcut:(0,x.gg)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>eI.decorators.em.guard(t.originEvent)&&e.context.schema.decorators.some(e=>"em"===e.name),actions:[()=>[(0,x.OU)({type:"decorator.toggle",decorator:"em"})]]}),underlineShortcut:(0,x.gg)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>eI.decorators.underline.guard(t.originEvent)&&e.context.schema.decorators.some(e=>"underline"===e.name),actions:[()=>[(0,x.OU)({type:"decorator.toggle",decorator:"underline"})]]}),codeShortcut:(0,x.gg)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>eI.decorators.code.guard(t.originEvent)&&e.context.schema.decorators.some(e=>
4"code"===e.name),actions:[()=>[(0,x.OU)({type:"decorator.toggle",decorator:"code"})]]})};function getCompoundClientRect(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 eG=[(0,x.gg)({on:"drag.dragstart",guard:({snapshot:e,dom:t,event:n})=>{let o=getDragSelection({snapshot:e,eventSelection:n.position.selection}),i=(0,v.u7)({...e,context:{...e.context,selection:o}}),r={blockNodes:t.getBlockNodes({...e,context:{...e.context,selection:o}}),childNodes:t.getChildNodes({...e,context:{...e.context,selection:o}})};return{dragSelection:o,draggedDomNodes:r,selectingEntireBlocks:i}},actions:[({dom:e,event:t},{dragSelection:n,draggedDomNodes:o,selectingEntireBlocks:i})=>{let r=document.createElement("div");if(i){let i=o.blockNodes.map(e=>e.cloneNode(!0));for(let e of i)e instanceof HTMLElement&&(e.style.position="relative"),r.appendChild(e);let a=r.querySelector("[data-pt-drag-ghost-element]");if(a&&r.replaceChildren(a),r.setAttribute("data-dragged",""),r.style.position="absolute",r.style.left="-99999px",r.style.boxSizing="border-box",document.body.appendChild(r),a){let o=a.getBoundingClientRect(),i=t.originEvent.clientX-o.left,l=t.originEvent.clientY-o.top;return r.style.width=`${o.width}px`,r.style.height=`${o.height}px`,[(0,x.OU)({type:"select",at:n}),(0,x.cE)(()=>{e.setDragGhost({event:t,ghost:{element:r,x:i,y:l}})}),(0,x.eH)(t)]}{let i=getCompoundClientRect(o.blockNodes),a=t.originEvent.clientX-i.left,l=t.originEvent.clientY-i.top;return r.style.width=`${i.width}px`,r.style.height=`${i.height}px`,[(0,x.OU)({type:"select",at:n}),(0,x.cE)(()=>{e.setDragGhost({event:t,ghost:{element:r,x:a,y:l}})}),(0,x.eH)(t)]}}{let i=o.childNodes.map(e=>e.cloneNode(!0));for(let e of i)r.appendChild(e);r.style.position="absolute",r.style.left="-99999px",r.style.boxSizing="border-box",document.body.appendChild(r);let a=getCompoundClientRect(o.childNodes),l=t.originEvent.clientX-a.left,s=t.originEvent.clientY-a.top;return r.style.width=`${a.width}px`,r.style.height=`${a.height}px`,[(0,x.OU)({type:"select",at:n}),(0,x.cE)(()=>{e.setDragGhost({event:t,ghost:{element:r,x:l,y:s}})}),(0,x.eH)(t)]}}]}),(0,x.gg)({on:"drag.dragover",guard:({snapshot:e,event:t})=>{let n=t.dragOrigin;return!!n&&(0,v.Mf)(t.position.selection)({...e,context:{...e.context,selection:n.selection}})},actions:[]}),(0,x.gg)({on:"drag.drop",guard:({snapshot:e,event:t})=>{let n=t.dragOrigin,o=t.position.selection;return!!n&&(0,v.Mf)(o)({...e,context:{...e.context,selection:n.selection}})},actions:[]}),(0,x.gg)({on:"drag.drop",guard:({event:e})=>void 0!==e.dragOrigin,actions:[({event:e})=>[(0,x.OU)({type:"deserialize",originEvent:e})]]}),(0,x.gg)({on:"drag.drop",actions:[({event:e})=>[(0,x.OU)({type:"select",at:e.position.selection}),(0,x.OU)({type:"deserialize",originEvent:e})]]}),(0,x.gg)({on:"deserialization.success",guard:({snapshot:e,event:t})=>{if("drag.drop"!==t.originEvent.type||void 0===t.originEvent.dragOrigin)return!1;let n=t.originEvent.dragOrigin,o=getDragSelection({eventSelection:n.selection,snapshot:e}),i=t.originEvent.position.selection,r=!!n&&(0,v.Mf)(i)({...e,context:{...e.context,selection:o}}),a=(0,v.u7)({...e,context:{...e.context,selection:o}}),l=(0,v.wD)({...e,context:{...e.context,selection:o}});return!r&&{dropPosition:i,draggingEntireBlocks:a,draggedBlocks:l,dragOrigin:n,originEvent:t.originEvent}},actions:[({event:e},{draggingEntireBlocks:t,draggedBlocks:n,dragOrigin:o,dropPosition:i,originEvent:r})=>[(0,x.OU)({type:"select",at:i}),...t?n.map(e=>(0,x.OU)({type:"delete.block",at:e.path})):[(0,x.OU)({type:"delete",at:o.selection})],(0,x.OU)({type:"insert.blocks",blocks:e.data,placement:t?"start"===r.position.block?"before":"end"===r.position.block?"after":"auto":"auto"})]]})],eF=(0,x.gg)({on:"insert.break",guard:({snapshot:e})=>{let t=(0,k.I3)(e),n=(0,k.dI)(e);if(!e.context.selection||!t||!n)return!1;let o=(0,v.kr)(t)(e),i=t.node.listItem,r=t.node.level;return!!o&&{focusListItem:i,focusLevel:r}},actions:[({snapshot:e},{focusListItem:t,focusLevel:n})=>[(0,x.OU)({type:"insert.block",block:{_type:e.context.schema.block.name,children:[{_type:e.context.schema.span.name,text:"",marks:[]}],markDefs:[],listItem:t,level:n,style:e.context.schema.styles[0]?.n
4ame},placement:"after"})]]}),eK=(0,x.gg)({on:"insert.break",guard:({snapshot:e})=>{let t=(0,k.I3)(e),n=(0,k.dI)(e);if(!e.context.selection||!t||!n)return!1;let o=(0,k.Cj)(e),i=o?.node.marks?.filter(t=>e.context.schema.decorators.some(e=>e.name===t)??[]),r=o?.node.marks?.filter(t=>!e.context.schema.decorators.some(e=>e.name===t))??[],a=t.node.listItem,l=t.node.level;return!!(0,v.FQ)(t)(e)&&{focusAnnotations:r,focusDecorators:i,focusListItem:a,focusLevel:l}},actions:[({snapshot:e},{focusAnnotations:t,focusDecorators:n,focusListItem:o,focusLevel:i})=>[(0,x.OU)({type:"insert.block",block:{_type:e.context.schema.block.name,children:[{_type:e.context.schema.span.name,marks:0===t.length?n:[],text:""}],listItem:o,level:i,style:e.context.schema.styles[0]?.name},placement:"before",select:"none"})]]}),eW=(0,x.gg)({on:"insert.break",guard:({snapshot:e})=>{if(!e.context.selection||!(0,k.sC)(e))return!1;let t=(0,v.Ui)(e),n=(0,v.Gm)(e);if(!t||!n)return!1;let o=(0,g.qv)({context:e.context,block:t}),i=(0,g.VG)(e.context.selection),r=(0,y.sQ)({context:e.context,block:n}),a=(0,g.OE)(e.context.selection);return!!((0,y.Gh)(o,i)&&(0,y.Gh)(r,a))&&{selection:e.context.selection}},actions:[(e,{selection:t})=>[(0,x.OU)({type:"delete",at:t})]]}),eq=(0,x.gg)({on:"insert.break",guard:({snapshot:e})=>{if(!e.context.selection||!(0,k.sC)(e))return!1;let t=(0,v.wD)(e),n=(0,v.Dm)(e),o=(0,v.Zq)(e);if(!n||!o)return!1;let i=(0,g.qv)({context:e.context,block:n}),r=(0,g.VG)(e.context.selection),a=(0,y.sQ)({context:e.context,block:o}),l=(0,g.OE)(e.context.selection);return!!((0,y.Gh)(r,i)&&(0,y.Gh)(l,a))&&{selectedBlocks:t}},actions:[({snapshot:e},{selectedBlocks:t})=>[(0,x.OU)({type:"insert.block",block:{_type:e.context.schema.block.name,children:[{_type:e.context.schema.span.name,text:"",marks:[]}]},placement:"before",select:"start"}),...t.map(e=>(0,x.OU)({type:"delete.block",at:e.path}))]]}),eH=(0,x.gg)({on:"insert.break",guard:({snapshot:e})=>{let t=(0,k.dI)(e),n=(0,v.fX)(e);return t&&n},actions:[()=>[(0,x.OU)({type:"move.forward",distance:1}),(0,x.OU)({type:"split"})]]}),eJ={breakingAtTheEndOfTextBlock:eF,breakingAtTheStartOfTextBlock:eK,breakingEntireDocument:eW,breakingEntireBlocks:eq,breakingInlineObject:eH},eX=(0,x.gg)({on:"delete.backward",guard:({snapshot:e})=>{let t=(0,k.dI)(e),n=(0,k.I3)(e),o=(0,k.Cj)(e);return!!t&&!!n&&!!o&&n.node.children[0]._key===o.node._key&&e.context.selection?.focus.offset===0&&1===n.node.level&&{focusTextBlock:n}},actions:[(e,{focusTextBlock:t})=>[(0,x.OU)({type:"block.unset",props:["listItem","level"],at:t.path})]]}),eZ=(0,x.gg)({on:"delete.backward",guard:({snapshot:e})=>{let t=(0,k.dI)(e),n=(0,k.I3)(e),o=(0,k.Cj)(e);return!!t&&!!n&&!!o&&n.node.children[0]._key===o.node._key&&e.context.selection?.focus.offset===0&&void 0!==n.node.level&&n.node.level>1&&{focusTextBlock:n,level:n.node.level-1}},actions:[(e,{focusTextBlock:t,level:n})=>[(0,x.OU)({type:"block.set",props:{level:n},at:t.path})]]}),eQ=(0,x.gg)({on:"delete.forward",guard:({snapshot:e})=>{let t=(0,v.Ec)(e),n=(0,v.st)(e);return!!(t&&n&&(0,g.dz)(e.context,n.node)&&(0,y.PF)(e.context,t.node))&&{focusListBlock:t,nextBlock:n}},actions:[(e,{nextBlock:t})=>[(0,x.OU)({type:"insert.block",block:t.node,placement:"auto",select:"start"}),(0,x.OU)({type:"delete.block",at:t.path})]]}),e0=(0,x.gg)({on:"delete.backward",guard:({snapshot:e})=>{let t=(0,k.I3)(e),n=(0,v.nt)(e);if(!t||!n||!(0,g.cd)(e.context,n.node)||!(0,y.PF)(e.context,n.node))return!1;let o=(0,y.sQ)({context:e.context,block:n});return{focusTextBlock:t,previousBlockEndPoint:o}},actions:[(e,{focusTextBlock:t,previousBlockEndPoint:n})=>[(0,x.OU)({type:"select",at:{anchor:n,focus:n}}),(0,x.OU)({type:"insert.block",block:t.node,placement:"auto",select:"start"}),(0,x.OU)({type:"delete.block",at:t.path})]]}),e1=(0,x.gg)({on:"insert.break",guard:({snapshot:e})=>{let t=(0,k.dI)(e),n=(0,v.Ec)(e);return!!(t&&n&&(0,y.PF)(e.context,n.node))&&{focusListBlock:n}},actions:[(e,{focusListBlock:t})=>[(0,x.OU)({type:"block.unset",props:["listItem","level"],at:t.path})]]}),e2=(0,x.gg)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>{if(!eI.tab.guard(t.originEvent))return!1;let n=(0,v.wD)(e),o=n.flatMap(t=>(0,g.cd)(e.context,t.node)?[{node:t.node,path:t.path}]:[]);return o.length===n.length&&{selectedListBlocks:o}},actions:[(e,{selectedListBlocks:t})=>t.map(e=>(0,x.OU)({type:"block.set",props:{level:Math.min(10,Math.max(1,e.node.level+1))},at:e.path}))]}),e3=(0,x.gg)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>{if(!eI.shiftTab.guard(t.originEvent))return!1;let n=(0,v.wD)(e),o=n.flatMap(t=>(0,g.cd)(e.context,t.node)?[{node:t.node,path:t.path}]:[]);return o.length===n.length&&{selectedListBlocks:o}},actions:[(e,{selectedListBlocks:t})=>t.map(e=>(0,x.OU)({type:"block.set",props:{level:Math.min(10,Math.max(1,e.node.level-1))},at:e.path}))]}),e8=(0,x.gg)({on:"insert.blocks",guard:({snapshot:e,event:t})=>{let n=(0,v.Ec)(e);if(!n)return!1;let o=t.blocks.at(0),i=t.blocks.at(1),r=(0,g.cd)(e.context,o)?o:(0,g.cd)(e.context,i)?i:void 0;if(!r)return!1;let a=n.node.level-r.level;return 0!==a&&{levelDifference:a,insertedListBlock:r}},actions:[({snapshot:e,event:t},{levelDifference:n,insertedListBlock:o})=>{let i=!0,r=!1;return[(0,x.OU)({...t,blocks:t.blocks.map(t=>(t._key===o._key&&(r=!0),i?r&&i&&(0,g.cd)(e.context,t)?{...t,level:Math.min(10,Math.max(1,t.level+n))}:(r&&(i=!1),t):t))})]}]}),e6=(0,x.gg)({on:"insert.blocks",guard:({snapshot:e,event:t})=>{let n=(0,v.Ec)(e);if(!n||(0,y.PF)(e.context,n.node))return!1;let o=t.blocks.at(0),i=t.blocks.at(1),r=(0,g.cd)(e.context,o)?o:(0,g.cd)(e.context,i)?i:void 0;return!!r&&n.node.level===r.level&&n.node.listItem!==r.listItem&&{listItem:n.node.listItem,insertedListBlock:r}},actions:[({snapshot:e,event:t},{listItem:n,insertedListBlock:o})=>{let i=!0,r=!1;return[(0,x.OU)({...t,blocks:t.blocks.map(t=>(t._key===o._key&&(r=!0),i?r&&i&&(0,g.cd)(e.context,t)?{...t,listItem:t.level===o.level?n:t.listItem}:(r&&(i=!1),t):t))})]}]}),e9=(0,x.gg)({on:"insert.block",guard:({snapshot:e,event:t})=>{if("auto"!==t.placement||t.block._type!==e.context.schema.block.name||void 0!==t.block.listItem)return!1;let n=(0,v.Ec)(e);return!!(n&&(0,y.PF)(e.context,n.node))&&{level:n.node.level,listItem:n.node.listItem}},actions:[({event:e},{level:t,listItem:n})=>[(0,x.OU)({...e,block:{...e.block,level:t,listItem:n}})]]}),e4={clearListOnBackspace:eX,unindentListOnBackspace:eZ,mergeTextIntoListOnDelete:eQ,mergeTextIntoListOnBackspace:e0,clearListOnEnter:e1,indentListOnTab:e2,unindentListOnShiftTab:e3,inheritListLevel:e8,inheritListItem:e6,inheritListProperties:e9},e5=[{addAnnotationOnCollapsedSelection:eA}.addAnnotationOnCollapsedSelection,eV.strongShortcut,eV.emShortcut,eV.underlineShortcut,eV.codeShortcut,...eG,ez.clickingAboveLonelyBlockObject,ez.clickingBelowLonelyBlockObject,ez.arrowDownOnLonelyBlockObject,ez.arrowUpOnLonelyBlockObject,ez.breakingBlockObject,ez.deletingEmptyTextBlockAfterBlockObject,ez.deletingEmptyTextBlockBeforeBlockObject,e4.clearListOnBackspace,e4.unindentListOnBackspace,e4.mergeTextIntoListOnDelete,e4.mergeTextIntoListOnBackspace,e4.clearListOnEnter,e4.indentListOnTab,e4.unindentListOnShiftTab,e4.inheritListLevel,e4.inheritListItem,e4.inheritListProperties,eJ.breakingAtTheEndOfTextBlock,eJ.breakingAtTheStartOfTextBlock,eJ.breakingEntireDocument,eJ.breakingEntireBlocks,eJ.breakingInlineObject].map(e=>({behavior:e,priority:Z})),e7=[(0,x.gg)({on:"annotation.set",guard:({snapshot:e,event:t})=>{let n=t.at[0]._key,o=t.at[2]._key,i=(0,k.I3)({...e,context:{...e.context,selection:{anchor:{path:[{_key:n}],offset:0},focus:{path:[{_key:n}],offset:0}}}});if(!i)return!1;let r=i.node.markDefs?.map(e=>e._key===o?{...e,...t.props}:e);return{blockKey:n,updatedMarkDefs:r}},actions:[(e,{blockKey:t,updatedMarkDefs:n})=>[(0,x.OU)({type:"block.set",at:[{_key:t}],props:{markDefs:n}})]]}),(0,x.gg)({on:"annotation.toggle",guard:({snapshot:e,event:t})=>(0,v.kH)(t.annotation.name)(e),actions:[({event:e})=>[(0,x.OU)({type:"annotation.remove",annotation:e.annotation})]]}),(0,x.gg)({on:"annotation.toggle",guard:({snapshot:e,event:t})=>!(0,v.kH)(t.annotation.name)(e),actions:[({event:e})=>[(0,x.OU)({type:"annotation.add",annotation:e.annotation})]]})],te=[(0,x.gg)({on:"decorator.toggle",guard:({snapshot:e,event:t})=>(0,v.md)(t.decorator)(e),actions:[({event:e})=>[(0,x.OU)({type:"decorator.remove",decorator:e.decorator})]]}),(0,x.gg)({on:"decorator.toggle",guard:({snapshot:e,event:t})=>{let n=t.at?(0,P.iO)({context:e.context,offsets:t.at}):null;return n?!(0,v.md)(t.decorator)({...e,context:{...e.context,selection:n}}):!(0,v.md)(t.decorator)(e)},actions:[({event:e})=>[(0,x.OU)({...e,type:"decorator.add"})]]})],tt=[(0,x.gg)({on:"delete.backward",guard:({snapshot:e})=>!!e.context.selection&&{selection:e.context.selection},actions:[({event:e},{selection:t})=>[(0,x.OU)({type:"delete",direction:"backward",unit:e.unit,at:t})]]}),(0,x.gg)({on:"delete.forward",guard:({snapshot:e})=>!!e.context.selection&&{selection:e.context.selection},actions:[({event:e},{selection:t})=>[(0,x.OU)({type:"delete",direction:"forward",unit:e.unit,at:t})]]}),(0,x.gg)({on:"delete.block",actions:[({event:e})=>[(0,x.OU)({type:"delete",at:{anchor:{path:e.at,offset:0},focus:{path:e.at,offset:0}}})]]}),(0,x.gg)({on:"delete.child",guard:({snapshot:e,event:t})=>{let n=(0,k.Yz)({...e,context:{...e.context,selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:0}}}});return!!n&&((0,g.dn)(e.context,n.node)?{selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:n.node.text.length}}}:{selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:0}}})},actions:[(e,{selection:t})=>[(0,x.OU)({type:"delete",at:t})]]}),(0,x.gg)({on:"delete.text",guard:({snapshot:e,event:t})=>{let n=(0,P.iO)({context:e.context,offsets:t.at});if(!n)return!1;let o=(0,v.Vj)({...e,context:{...e.context,value:e.context.value,selection:n}});return!!o&&{selection:o}},actions:[(e,{selection:t})=>[(0,x.OU)({type:"delete",at:t})]]})],tn=[(0,x.gg)({on:"insert.blocks",guard:({event:e})=>"before"===e.placement,actions:[({event:e})=>e.blocks.map((t,n)=>(0,x.OU)({type:"insert.block",block:t,placement:0===n?"before":"after",select:e.select??"end"}))]}),(0,x.gg)({on:"insert.blocks",guard:({event:e})=>"after"===e.placement,actions:[({event:e})=>e.blocks.map(t=>(0,x.OU)({type:"insert.block",block:t,placement:"after",select:e.select??"end"}))]}),(0,x.gg)({on:"insert.blocks",guard:({snapshot:e,event:t})=>{if("auto"!==t.placement)return!1;let n=(0,k.I3)(e);return!!n&&{focusTextBlock:n}},actions:[({snapshot:e,event:t},{focusTextBlock:n})=>1===t.blocks.length?[(0,x.OU)({type:"insert.block",block:t.blocks[0],placement:"auto",select:t.select??"end"})]:(0,y.PF)(e.context,n.node)?t.blocks.map((e,n)=>(0,x.OU)({type:"insert.block",block:e,placement:0===n?"auto":"after",select:t.select??"end"})):t.blocks.flatMap((e,n)=>0===n?[(0,x.OU)({type:"split"}),(0,x.OU)({type:"select.previous block",select:"end"}),(0,x.OU)({type:"insert.block",block:e,placement:"auto",select:t.select??"end"})]:n===t.blocks.length-1?[(0,x.OU)({type:"select.next block",select:"start"}),(0,x.OU)({type:"insert.block",block:e,placement:"auto",select:t.select??"end"})]:[(0,x.OU)({type:"insert.block",block:e,placement:"after",select:t.select??"end"})])]}),(0,x.gg)({on:"insert.blocks",guard:({event:e})=>"auto"===e.placement,actions:[({event:e})=>e.blocks.map((t,n)=>(0,x.OU)({type:"insert.block",block:t,placement:0===n?"auto":"after",select:e.select??"end"}))]}),(0,x.gg)({on:"insert.break",actions:[()=>[(0,x.OU)({type:"split"})]]}),(0,x.gg)({on:"insert.soft break",actions:[()=>[(0,x.OU)({type:"insert.text",text:` 5`})]]})],to=[(0,x.gg)({on:"keyboard.keydown",guard:({snapshot:e,event:t})=>eI.break.guard(t.originEvent)&&(0,k.dI)(e)&&(0,v.fX)(e),actions:[()=>[(0,x.OU)({type:"insert.break"})]]}),(0,x.gg)({on:"keyboard.keydown",guard:({event:e})=>eI.lineBreak.guard(e.originEvent),actions:[()=>[(0,x.OU)({type:"insert.soft break"})]]}),(0,x.gg)({on:"keyboard.keydown",guard:({event:e})=>eI.history.undo.guard(e.originEvent),actions:[()=>[(0,x.OU)({type:"history.undo"})]]}),(0,x.gg)({on:"keyboard.keydown",guard:({event:e})=>eI.history.redo.guard(e.originEvent),actions:[()=>[(0,x.OU)({type:"history.redo"})]]})],ti=[(0,x.gg)({on:"list item.add",guard:({snapshot:e})=>({selectedTextBlocks:(0,v.JK)(e)}),actions:[({event:e},{selectedTextBlocks:t})=>t.map(t=>(0,x.OU)({type:"block.set",at:t.path,props:{level:1,listItem:e.listItem}}))]}),(0,x.gg)({on:"list item.remove",guard:({snapshot:e})=>({selectedTextBlocks:(0,v.JK)(e)}),actions:[(e,{selectedTextBlocks:t})=>t.map(e=>(0,x.OU)({type:"block.unset",at:e.path,props:["level","listItem"]}))]}),(0,x.gg)({on:"list item.toggle",guard:({snapshot:e,event:t})=>(0,v.IA)(t.listItem)(e),actions:[({event:e})=>[(0,x.OU)({type:"list item.remove",listItem:e.listItem})]]}),(0,x.gg)({on:"list item.toggle",guard:({snapshot:e,event:t})=>!(0,v.IA)(t.listItem)(e),actions:[({event:e})=>[(0,x.OU)({type:"list item.add",listItem:e.listItem})]]})],tr=[(0,x.gg)({on:"move.block up",guard:({snapshot:e,event:t})=>{let n=(0,v.nt)({...e,context:{...e.context,selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:0}}}});return!!n&&{previousBlock:n}},actions:[({event:e},{previousBlock:t})=>[(0,x.OU)({type:"move.block",at:e.at,to:t.path})]]}),(0,x.gg)({on:"move.block down",guard:({snapshot:e,event:t})=>{let n=(0,v.st)({...e,context:{...e.context,selection:{anchor:{path:t.at,offset:0},focus:{path:t.at,offset:0}}}});return!!n&&{nextBlock:n}},actions:[({event:e},{nextBlock:t})=>[(0,x.OU)({type:"move.block",at:e.at,to:t.path})]]})],ta=[(0,x.gg)({on:"select.previous block",guard:({snapshot:e,event:t})=>{let n=(0,v.nt)(e);if(!n)return!1;let o="end"===t.select?(0,y.sQ)({context:e.context,block:n}):(0,g.qv)({context:e.context,block:n});return{selection:{anchor:o,focus:o}}},actions:[(e,{selection:t})=>[(0,x.OU)({type:"select",at:t})]]}),(0,x.gg)({on:"select.next block",guard:({snapshot:e,event:t})=>{let n=(0,v.st)(e);if(!n)return!1;let o="end"===t.select?(0,y.sQ)({context:e.context,block:n}):(0,g.qv)({context:e.context,block:n});return{selection:{anchor:o,focus:o}}},actions:[(e,{selection:t})=>[(0,x.OU)({type:"select",at:t})]]})],tl=[(0,x.gg)({on:"split",guard:({snapshot:e})=>(0,k.dI)(e)&&(0,v.fX)(e),actions:[]}),(0,x.gg)({on:"split",guard:({snapshot:e})=>(0,k.dI)(e)&&(0,v.ii)(e),actions:[]}),(0,x.gg)({on:"split",guard:({snapshot:e})=>{let t=e.context.selection;if(!t||(0,y.dI)(t))return!1;let n=(0,v.Dm)(e),o=(0,v.Zq)(e);return!!n&&!!o&&!!(!(0,g.dz)(e.context,n.node)&&(0,g.dz)(e.context,o.node))&&{selection:t}},actions:[(e,{selection:t})=>[(0,x.OU)({type:"delete",at:t})]]}),(0,x.gg)({on:"split",guard:({snapshot:e})=>{let t=e.context.selection;return!(!t||(0,y.dI)(t))&&{selection:t}},actions:[(e,{selection:t})=>[(0,x.OU)({type:"delete",at:t}),(0,x.OU)({type:"split"})]]}),(0,x.gg)({on:"split",guard:({snapshot:e})=>{let t=e.context.selection;if(!t||!(0,y.dI)(t))return!1;let n=(0,g.VG)(t),o=(0,k.I3)(e);if(!o)return!1;let i=(0,y.sQ)({context:e.context,block:o}),r={anchor:n,focus:i},a=(0,g.IX)({block:(0,D.U)({context:{...e.context,selection:r},block:o.node}),context:e.context,options:{refreshKeys:!0,validateFields:!0}});return!!a&&{newTextBlock:a,newTextBlockSelection:r}},actions:[(e,{newTextBlock:t,newTextBlockSelection:n})=>(0,y.dI)(n)?[(0,x.OU)({type:"insert.block",block:t,placement:"after",select:"start"})]:[(0,x.OU)({type:"delete",at:n}),(0,x.OU)({type:"insert.block",block:t,placement:"after",select:"start"})]]})],ts=[(0,x.gg)({on:"style.add",guard:({snapshot:e})=>({selectedTextBlocks:(0,v.JK)(e)}),actions:[({event:e},{selectedTextBlocks:t})=>t.map(t=>(0,x.OU)({type:"block.set",at:t.path,props:{style:e.style}}))]}),(0,x.gg)({on:"style.remove",guard:({snapshot:e})=>({selectedTextBlocks:(0,v.JK)(e)}),actions:[(e,{selectedTextBlocks:t})=>t.map(e=>(0,x.OU)({type:"block.unset",at:e.path,props:["style"]}))]}),(0,x.gg)({on:"style.toggle",guard:({snapshot:e,event:t})=>(0,v.S9)(t.style)(e),actions:[({event:e})=>[(0,x.OU)({type:"style.remove",style:e.style})]]}),(0,x.gg)({on:"style.toggle",guard:({snapshot:e,event:t})=>!(0,v.S9)(t.style)(e),actions:[({event:e})=>[(0,x.OU)({type:"style.add",style:e.style})]]})],tc=(0,x.gg)({on:"deserialize",guard:({snapshot:e,event:t})=>{let n;let o=[];for(let i of e.context.converters){let r=t.originEvent.originEvent.dataTransfer.getData(i.mimeType);if(!r)continue;let a=i.dese
5rialize({snapshot:e,event:{type:"deserialize",data:r}});if("deserialization.success"===a.type){n=a;break}o.push(a)}return n||{type:"deserialization.failure",mimeType:"*/*",reason:o.map(e=>e.reason).join(", ")}},actions:[({event:e},t)=>[(0,x.OU)({...t,originEvent:e.originEvent})]]}),td=(0,x.gg)({on:"serialize",guard:({snapshot:e,event:t})=>{if(0===e.context.converters.length)return!1;let n=e.context.converters.map(n=>n.serialize({snapshot:e,event:{...t,originEvent:t.originEvent.type}}));return 0!==n.length&&n},actions:[({event:e},t)=>t.map(t=>(0,x.OU)({...t,originEvent:e.originEvent}))]}),tp=[(0,x.gg)({on:"clipboard.copy",guard:({snapshot:e})=>{let t=(0,k.Cj)(e),n=(0,k.dI)(e);return t&&n},actions:[]}),(0,x.gg)({on:"clipboard.copy",actions:[({event:e})=>[(0,x.OU)({type:"serialize",originEvent:e})]]}),(0,x.gg)({on:"clipboard.cut",guard:({snapshot:e})=>{let t=(0,k.Cj)(e),n=(0,k.dI)(e);return t&&n},actions:[]}),(0,x.gg)({on:"clipboard.cut",guard:({snapshot:e})=>!!e.context.selection&&{selection:e.context.selection},actions:[({event:e},{selection:t})=>[(0,x.OU)({type:"serialize",originEvent:e}),(0,x.OU)({type:"delete",at:t})]]}),(0,x.gg)({on:"drag.dragstart",actions:[({event:e})=>[(0,x.OU)({type:"serialize",originEvent:e})]]}),(0,x.gg)({on:"serialization.success",actions:[({event:e})=>[{type:"effect",effect:()=>{e.originEvent.originEvent.dataTransfer.setData(e.mimeType,e.data)}}]]}),(0,x.gg)({on:"serialization.failure",actions:[({event:e})=>[{type:"effect",effect:()=>{console.warn(`Serialization of ${e.mimeType} failed with reason "${e.reason}"`)}}]]}),(0,x.gg)({on:"deserialization.success",guard:({snapshot:e,event:t})=>{if((0,k.I3)(e)&&"text/plain"===t.mimeType&&"clipboard.paste"===t.originEvent.type){let n=(0,v.WH)(e);return{activeAnnotations:(0,v.$s)(e),activeDecorators:n,textRuns:t.data.flatMap(t=>(0,g.dz)(e.context,t)?[(0,g.NL)(t)]:[])}}return!1},actions:[(e,{activeAnnotations:t,activeDecorators:n,textRuns:o})=>o.flatMap((e,i)=>i!==o.length-1?[(0,x.OU)({type:"insert.span",text:e,decorators:n,annotations:t.map(({_key:e,_type:t,...n})=>({name:t,value:n}))}),(0,x.OU)({type:"insert.break"})]:[(0,x.OU)({type:"insert.span",text:e,decorators:n,annotations:t.map(({_key:e,_type:t,...n})=>({name:t,value:n}))})])]}),(0,x.gg)({on:"deserialization.success",actions:[({event:e})=>[(0,x.OU)({type:"insert.blocks",blocks:e.data,placement:"auto"})]]}),(0,x.gg)({on:"deserialization.failure",actions:[({event:e})=>[{type:"effect",effect:()=>{console.warn(`Deserialization of ${e.mimeType} failed with reason "${e.reason}"`)}}]]}),(0,x.gg)({on:"clipboard.paste",guard:({snapshot:e})=>!!(e.context.selection&&(0,k.sC)(e))&&{selection:e.context.selection},actions:[({event:e},{selection:t})=>[(0,x.OU)({type:"delete",at:t}),(0,x.OU)({type:"deserialize",originEvent:e})]]}),(0,x.gg)({on:"clipboard.paste",actions:[({event:e})=>[(0,x.OU)({type:"deserialize",originEvent:e})]]}),(0,x.gg)({on:"input.*",actions:[({event:e})=>[(0,x.OU)({type:"deserialize",originEvent:e})]]}),...e7,...te,...tt,...tn,...to,...ti,...tr,...ts,...ta,...tl,tc,td];function isSyntheticBehaviorEvent(e){return!isCustomBehaviorEvent(e)&&!isNativeBehaviorEvent(e)&&!isAbstractBehaviorEvent(e)}let tu=["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 isAbstractBehaviorEvent(e){return tu.includes(e.type)}let th=["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 isNativeBehaviorEvent(e){return th.includes(e.type)}function isCustomBehaviorEvent(e){return e.type.startsWith("custom.")}let tf=debugWithName("behaviors:event");function eventCategory(e){return isNativeBehaviorEvent(e)?"native":isAbstractBehaviorEvent(e)?"synthetic":isCustomBehaviorEvent(e)?"custom"
5:"synthetic"}let tg=debugWithName("editor machine"),ty=(0,S.cY)({types:{context:{},events:{},emitted:{},input:{},tags:{}},actions:{"add behavior to context":(0,w.a)({behaviors:({context:e,event:t})=>((0,S.ZD)(t,"add behavior"),new Set([...e.behaviors,t.behaviorConfig])),behaviorsSorted:!1}),"remove behavior from context":(0,w.a)({behaviors:({context:e,event:t})=>((0,S.ZD)(t,"remove behavior"),e.behaviors.delete(t.behaviorConfig),new Set([...e.behaviors]))}),"emit patch event":(0,O.a)(({event:e})=>((0,S.ZD)(e,"internal.patch"),e)),"emit mutation event":(0,O.a)(({event:e})=>((0,S.ZD)(e,"mutation"),e)),"emit read only":(0,O.a)({type:"read only"}),"emit editable":(0,O.a)({type:"editable"}),"defer event":(0,w.a)({pendingEvents:({context:e,event:t})=>((0,S.ZD)(t,["internal.patch","mutation"]),[...e.pendingEvents,t])}),"emit pending events":(0,O.e)(({context:e,enqueue:t})=>{for(let n of e.pendingEvents)t.emit(n)}),"emit ready":(0,O.a)({type:"ready"}),"clear pending events":(0,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,O.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,S.ZD)(e,"blur");try{u.F3.blur(e.editor)}catch(e){console.error(Error(`Failed to blur editor: ${e.message}`))}},"handle focus":({context:e})=>{if(!e.slateEditor){console.error("No Slate editor found to focus");return}try{let t=e.slateEditor.selection;u.F3.focus(e.slateEditor),t&&p.YR.select(e.slateEditor,t)}catch(e){console.error(Error(`Failed to focus editor: ${e.message}`))}},"handle behavior event":({context:e,event:t,self:n})=>{(0,S.ZD)(t,["behavior event"]);try{let o=[...e.behaviors.values()].map(e=>e.behavior);!function performEvent({mode:e,behaviors:t,remainingEventBehaviors:n,event:o,editor:i,keyGenerator:r,schema:a,getSnapshot:l,nativeEvent:s,sendBack:c}){tf(`(${e}:${eventCategory(o)})`,JSON.stringify(o,null,2));let d=[...n,...tp].filter(e=>{if("*"===e.on)return!0;let[t]=e.on.includes("*")&&e.on.includes(".")?e.on.split("."):[void 0],[n]=o.type.includes(".")?o.type.split("."):[void 0];return void 0!==t&&void 0!==n&&t===n||void 0!==t&&void 0===n&&t===o.type||e.on===o.type});if(0===d.length&&isSyntheticBehaviorEvent(o)){s?.preventDefault(),withApplyingBehaviorOperations(i,()=>{tf(`(execute:${eventCategory(o)})`,JSON.stringify(o,null,2)),performOperation({context:{keyGenerator:r,schema:a},operation:{...o,editor:i}})}),i.onChange();return}let p=l(),u=!1,h=!1,f=-1;for(let e of d){f++;let n=!1;try{n=void 0===e.guard||e.guard({snapshot:p,event:o,dom:createEditorDom(c,i)})}catch(e){console.error(Error(`Evaluating guard for "${o.type}" failed due to: ${e.message}`))}if(n){for(let p of(h=!0,e.actions)){let e=l(),h=[];try{h=p({snapshot:e,event:o,dom:createEditorDom(c,i)},n)}catch(e){console.error(Error(`Evaluating actions for "${o.type}" failed due to: ${e.message}`))}if(0!==h.length){if(u=h.some(e=>"raise"===e.type||"execute"===e.type)||!h.some(e=>"forward"===e.type),h.some(e=>"execute"===e.type)){!function(e,t){let n=e_.get(e);if(n){t();return}e_.set(e,n??{undoStepId:defaultKeyGenerator()}),t(),e_.set(e,void 0)}(i,()=>{for(let e of h){if("effect"===e.type){try{e.effect()}catch(e){console.error(Error(`Executing effect as a result of "${o.type}" failed due to: ${e.message}`))}continue}if("forward"===e.type){let n=d.slice(f+1);performEvent({mode:"forward",behaviors:t,remainingEventBehaviors:n,event:e.event,editor:i,keyGenerator:r,schema:a,getSnapshot:l,nativeEvent:s,sendBack:c});continue}if("raise"===e.type){performEvent({mode:"raise",behaviors:t,remainingEventBehaviors:t,event:e.event,editor:i,keyGenerator:r,schema:a,getSnapshot:l,nativeEvent:s,sendBack:c});continue}performEvent({mode:"execute",behaviors:t,remainingEventBehaviors:[],event:e.event,editor:i,keyGenerator:r,schema:a,getSnapshot:l,nativeEvent:void 0,sendBack:c})}});continue}for(let e of h){if("effect"===e.type){try{e.effect()}catch(e){console.error(Error(`Executing effect as a result of "${o.type}" failed due to: ${e.message}`))}continue}if("forward"===e.type){let n=d.slice(f+1);performEvent({mode:"forward",behaviors:t,remainingEventBehaviors:n,event:e.event,editor:i,keyGenerator:r,schema:a,getSnapshot:l,nativeEvent:s,sendBack:c});continue}if("raise"===e.type){performEvent({mode:"raise",behaviors:t,remainingEventBehaviors:t,event:e.event,editor:i,keyGenerator:r,schema:a,getSnapshot:l,nativeEvent:s,sendBack:c});continue}"execute"===e.type&&console.error("Unexpected action type: `execute`")}}}break}}!h&&isSyntheticBehaviorEvent(o)?(s?.preventDefault(),withApplyingBehaviorOperations(i,()=>{tf(`(execute:${eventCategory(o)})`,JSON.stringify(o,null,2)),performOperation({context:{keyGenerator:r,schema:a},operation:{...o,editor:i}})}),i.onChange()):u&&s?.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?slateRangeToSelection({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 ensureNode(e){i.has(e)||(i.set(e,new Set),r.set(e,0))}for(let e of t){let t=e.priority.id;ensureNode(t)}function addEdge(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(ensureNode(e),n.has(e))throw Error("Circular dependency detected in priorities");n.add(e),"higher"===o.importance?addEdge(t,e):addEdge(e,t),o=o.priority.reference}}let a=[];for(let[e,t]of r)0===t&&a.push(e);let l=[];for(;a.length>0;){let e=a.shift(),t=o.get(e);
5for(let n of(t&&l.push(t),i.get(e)??[])){let e=(r.get(n)??0)-1;r.set(n,e),0===e&&a.push(n)}}for(let e of t)l.includes(e)||l.push(e);return[...l,...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(e5),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,O.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:[()=>{tg("entry: edit mode->read only->determine initial edit mode")}],exit:[()=>{tg("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:[()=>{tg("entry: edit mode->read only->read only")}],exit:[()=>{tg("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:[()=>{tg("entry: edit mode->editable->idle")}],exit:[()=>{tg("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:[()=>{tg("entry: edit mode->editable->focusing->checking if busy")}],exit:[()=>{tg("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:[()=>{tg("entry: edit mode->editable->focusing-busy")}],exit:[()=>{tg("exit: edit mode->editable->focusing->busy")}],after:{10:{target:"checking if busy"}}}}},"dragging internally":{entry:[()=>{tg("entry: edit mode->editable->dragging internally")}],exit:[()=>{tg("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:[()=>{tg("entry: setup->setting up")}],exit:[()=>{tg("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:[()=>{tg("entry: setup->set up->value sync->idle")}],exit:[()=>{tg("exit: setup->set up->value sync->idle")}],on:{patches:{actions:[(0,O.a)(({event:e})=>e)]},"syncing value":{target:"syncing value"}}},"syncing value":{entry:[()=>{tg("entry: setup->set up->value sync->syncing value")}],exit:[()=>{tg("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:[()=>{tg("entry: setup->set up->writing->pristine->idle")}],exit:[()=>{tg("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:[()=>{tg("entry: setup->set up->writing->pristine->normalizing")}],exit:[()=>{tg("exit: setup->set up->writing->pristine->normalizing")}],on:{"done normalizing":{target:"idle"},"internal.patch":{actions:"defer event"},mutation:{actions:"defer event"}}}}},dirty:{entry:[()=>{tg("entry: setup->set up->writing->dirty")},"emit pending events","clear pending events"],exit:[()=>{tg("exit: setup->set up->writing->dirty")}],on:{"internal.patch":{actions:"emit patch event"},mutation:{actions:"emit mutation event"}}}}}}}}}}});function createLegacySchema(e){if(!e)throw Error("Parameter 'portabletextType' missing (required)");let t=e.of?.find(function findBlockType(e){return e.type?findBlockType(e.type):"block"===e.name?e:null});if(!t)throw Error("Block type is not defined in this schema (required)");let n=t.fields?.find(e=>"children"===e.name);if(!n)throw Error("Children field for block type found in schema (required)");let o=n.type.of;if(!o)throw Error("Valid types for block children not found in schema (required)");let i=o.find(e=>"span"===e.name);if(!i)throw Error("Span type not found in schema (required)");let r=o.filter(e=>"span"!==e.name)||[],a=e.of?.filter(e=>e.name!==t.name)||[];return{styles:function(e){let t=e.fields?.find(e=>"style"===e.name);if(!t)throw Error("A field with name 'style' is not defined in the block type (required).");let n=t.type.options?.list&&t.type.options.list?.filter(e=>e.value);
5if(!n||0===n.length)throw Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");return n}(t),decorators:i.decorators,lists:function(e){let t=e.fields?.find(e=>"listItem"===e.name);if(!t)throw Error("A field with name 'listItem' is not defined in the block type (required).");let n=t.type.options?.list&&t.type.options.list.filter(e=>e.value);if(!n)throw Error("The list field need at least to be an empty array");return n}(t),block:t,span:i,portableText:e,inlineObjects:r,blockObjects:a,annotations:i.annotations}}let tm=`tmp-${defaultKeyGenerator()}-image`,tk=`tmp-${defaultKeyGenerator()}-url`,tv={image:tm,url:tk},tb={[tm]:"image",[tk]:"url"},tx={image:"Image",url:"URL"},t_=debugWithName("mutation-machine"),tE=(0,S.cY)({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,O.a)(({event:e})=>((0,S.ZD)(e,"patch"),{type:"patch",patch:e.patch})),"emit has pending mutations":(0,O.a)({type:"has pending mutations"}),"emit mutations":(0,O.e)(({context:e,enqueue:t})=>{for(let n of e.pendingMutations)t.emit({type:"mutation",patches:n.patches,snapshot:n.value})}),"clear pending mutations":(0,w.a)({pendingMutations:[]}),"defer mutation":(0,w.a)({pendingMutations:({context:e,event:t})=>{if((0,S.ZD)(t,"patch"),0===e.pendingMutations.length)return[{operationId:t.operationId,value:t.value,patches:[t.patch]}];let n=e.pendingMutations.at(-1);return n&&n.operationId===t.operationId?e.pendingMutations.slice(0,-1).concat({value:t.value,operationId:n.operationId,patches:[...n.patches,t.patch]}):e.pendingMutations.concat({value:t.value,operationId:t.operationId,patches:[t.patch]})}}),"clear pending patch events":(0,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,O.e)(({context:e,enqueue:t})=>{for(let n of e.pendingPatchEvents)t.emit(n)})},actors:{"type listener":(0,R.E9)(({input:e,sendBack:t})=>{let n=e.slateEditor.apply;return e.slateEditor.apply=e=>{"insert_text"===e.type||"remove_text"===e.type?t({type:"typing"}):t({type:"not typing"}),n(e)},()=>{e.slateEditor.apply=n}}),"mutation debouncer":(0,R.E9)(({sendBack:e})=>{let t=setInterval(()=>{e({type:"mutation delay passed"})},0);return()=>{clearInterval(t)}})},guards:{"is read-only":({context:e})=>e.readOnly,"is typing":(0,B.k)({typing:"typing"}),"slate is normalizing":({context:e})=>p.ML.isNormalizing(e.slateEditor)},delays:{"type debounce":250}}).createMachine({id:"mutation",context:({input:e})=>({pendingMutations:[],pendingPatchEvents:[],readOnly:e.readOnly,schema:e.schema,slateEditor:e.slateEditor}),on:{"update readOnly":{actions:["assign readOnly"]}},type:"parallel",states:{typing:{initial:"idle",invoke:{src:"type listener",input:({context:e})=>({slateEditor:e.slateEditor})},states:{idle:{entry:[()=>{t_("entry: typing->idle")}],exit:[()=>{t_("exit: typing->idle"),t_("entry: typing->typing")}],on:{typing:{target:"typing"}}},typing:{after:{"type debounce":{target:"idle",actions:[()=>{t_("exit: typing->typing")}]}},on:{"not typing":{target:"idle"},typing:{target:"typing",reenter:!0}}}}},mutations:{initial:"idle",states:{idle:{entry:[()=>{t_("entry: mutations->idle")}],exit:[()=>{t_("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:[()=>{t_("entry: mutations->has pending mutations")},"emit has pending mutations"],exit:[()=>{t_("exit: mutations->has pending mutations")}],invoke:{src:"mutation debouncer"},on:{"mutation delay passed":{guard:(0,B.j)([(0,B.n)("is read-only"),(0,B.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"]}]}}}}}}),tS=debugWithName("API:editable"),tw=(0,S.cY)({types:{context:{},events:{},emitted:{}}}).createMachine({id:"relay",context:{prevSelection:null,lastEventWasFocused:!1},on:{focused:{actions:[(0,w.a)({lastEventWasFocused:!0}),(0,O.a)(({event:e})=>e)]},selection:[{guard:({context:e})=>e.lastEventWasFocused,actions:[(0,w.a)({prevSelection:({event:e})=>e.selection}),(0,O.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,O.a)(({event:e})=>e),(0,w.a)({lastEventWasFocused:!1})]}],"*":{actions:[(0,O.a)(({event:e})=>e),(0,w.a)({lastEventWasFocused:!1})]}}});function validateValue(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,I.zN)([l])],description:`Block must be an object, got ${String(e)}`,action:"Unset invalid item",item:e,i18n:{description:"inputs.portable-text.invali
5d-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,I.t8)({...e,_key:n()},[l])],description:`Block at index ${l} is missing required _key.`,action:"Set the block with a random _key value",item:e,i18n:{description:"inputs.portable-text.invalid-value.missing-key.description",action:"inputs.portable-text.invalid-value.missing-key.action",values:{index:l}}},!0;if(!e._type||!a.includes(e._type)){if("block"===e._type){let n=t.block.name;return o={patches:[(0,I.t8)({...e,_type:n},[{_key:e._key}])],description:`Block with _key '${e._key}' has invalid type name '${e._type}'. According to the schema, the block type name is '${n}'`,action:`Use type '${n}'`,item:e,i18n:{description:"inputs.portable-text.invalid-value.incorrect-block-type.description",action:"inputs.portable-text.invalid-value.incorrect-block-type.action",values:{key:e._key,expectedTypeName:n}}},!0}return o=!e._type&&(0,g.dz)({schema:t},{...e,_type:t.block.name})?{patches:[(0,I.t8)({...e,_type:t.block.name},[{_key:e._key}])],description:`Block with _key '${e._key}' is missing a type name. According to the schema, the block type name is '${t.block.name}'`,action:`Use type '${t.block.name}'`,item:e,i18n:{description:"inputs.portable-text.invalid-value.missing-block-type.description",action:"inputs.portable-text.invalid-value.missing-block-type.action",values:{key:e._key,expectedTypeName:t.block.name}}}:e._type?{patches:[(0,I.zN)([{_key:e._key}])],description:`Block with _key '${e._key}' has invalid _type '${e._type}'`,action:"Remove the block",item:e,i18n:{description:"inputs.portable-text.invalid-value.disallowed-type.description",action:"inputs.portable-text.invalid-value.disallowed-type.action",values:{key:e._key,typeName:e._type}}}:{patches:[(0,I.zN)([{_key:e._key}])],description:`Block with _key '${e._key}' is missing an _type property`,action:"Remove the block",item:e,i18n:{description:"inputs.portable-text.invalid-value.missing-type.description",action:"inputs.portable-text.invalid-value.missing-type.action",values:{key:e._key}}},!0}if(e._type===t.block.name){if(e.children&&!Array.isArray(e.children))return o={patches:[(0,I.t8)({children:[]},[{_key:e._key}])],description:`Text block with _key '${e._key}' has a invalid required property 'children'.`,action:"Reset the children property",item:e,i18n:{description:"inputs.portable-text.invalid-value.missing-or-invalid-children.description",action:"inputs.portable-text.invalid-value.missing-or-invalid-children.action",values:{key:e._key}}},!0;if(void 0===e.children||Array.isArray(e.children)&&0===e.children.length){let i={_type:t.span.name,_key:n(),text:"",marks:[]};return o={autoResolve:!0,patches:[(0,I.Cb)([],[{_key:e._key},"children"]),(0,I.$T)([i],"after",[{_key:e._key},"children",0])],description:`Children for text block with _key '${e._key}' is empty.`,action:"Insert an empty text",item:e,i18n:{description:"inputs.portable-text.invalid-value.empty-children.description",action:"inputs.portable-text.invalid-value.empty-children.action",values:{key:e._key}}},!0}let a=_(C(e.children.filter(e=>e._type===t.span.name).map(e=>e.marks||[])));if(Array.isArray(e.markDefs)&&e.markDefs.length>0){let t=_(e.markDefs.map(e=>e._key).filter(e=>!a.includes(e)));if(t.length>0)return o={autoResolve:!0,patches:t.map(t=>(0,I.zN)([{_key:e._key},"markDefs",{_key:t}])),description:`Block contains orphaned data (unused mark definitions): ${t.join(", ")}.`,action:"Remove unused mark definition item",item:e,i18n:{description:"inputs.portable-text.invalid-value.orphaned-mark-defs.description",action:"inputs.portable-text.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,I.t8)((t.marks||[]).filter(e=>
5!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,I.zN)([{_key:e._key},"children",a])],description:`Child at index '${a}' in block with key '${e._key}' is not an object.`,action:"Remove the item",item:e,i18n:{description:"inputs.portable-text.invalid-value.non-object-child.description",action:"inputs.portable-text.invalid-value.non-object-child.action",values:{key:e._key,index:a}}},!0;if(!i._key||"string"!=typeof i._key){let t={...i,_key:n()};return o={autoResolve:!0,patches:[(0,I.t8)(t,[{_key:e._key},"children",a])],description:`Child at index ${a} is missing required _key in block with _key ${e._key}.`,action:"Set a new random _key on the object",item:e,i18n:{description:"inputs.portable-text.invalid-value.missing-child-key.description",action:"inputs.portable-text.invalid-value.missing-child-key.action",values:{key:e._key,index:a}}},!0}return i._type?r.includes(i._type)?i._type===t.span.name&&"string"!=typeof i.text&&(o={patches:[(0,I.t8)({...i,text:""},[{_key:e._key},"children",{_key:i._key}])],description:`Child with _key '${i._key}' in block with key '${e._key}' has missing or invalid text property!`,action:"Write an empty text property to the object",item:e,i18n:{description:"inputs.portable-text.invalid-value.invali
5d-span-text.description",action:"inputs.portable-text.invalid-value.invalid-span-text.action",values:{key:e._key,childKey:i._key}}},!0):(o={patches:[(0,I.zN)([{_key:e._key},"children",{_key:i._key}])],description:`Child with _key '${i._key}' in block with key '${e._key}' has invalid '_type' property (${i._type}).`,action:"Remove the object",item:e,i18n:{description:"inputs.portable-text.invalid-value.disallowed-child-type.description",action:"inputs.portable-text.invalid-value.disallowed-child-type.action",values:{key:e._key,childKey:i._key,childType:i._type}}},!0):(o={patches:[(0,I.zN)([{_key:e._key},"children",{_key:i._key}])],description:`Child with _key '${i._key}' in block with key '${e._key}' is missing '_type' property.`,action:"Remove the object",item:e,i18n:{description:"inputs.portable-text.invalid-value.missing-child-type.description",action:"inputs.portable-text.invalid-value.missing-child-type.action",values:{key:e._key,childKey:i._key}}},!0)})&&(i=!1)}return!1})&&(i=!1),{valid:i,resolution:o,value:e}):{valid:!1,resolution:{patches:[(0,I.zN)([])],description:"Editor value must be an array of Portable Text blocks, or undefined.",action:"Unset the value",item:e,i18n:{description:"inputs.portable-text.invalid-value.not-an-array.description",action:"inputs.portable-text.invalid-value.not-an-array.action"}},value:e}}let tO=debugWithName("sync machine"),tR=(0,R.E9)(({sendBack:e,input:t})=>{updateValue({context:t.context,sendBack:e,slateEditor:t.slateEditor,value:t.value,streamBlocks:t.streamBlocks})}),tB=(0,S.cY)({types:{context:{},input:{},events:{},emitted:{}},actions:{"assign initial value synced":(0,w.a)({initialValueSynced:!0}),"assign readOnly":(0,w.a)({readOnly:({event:e})=>((0,S.ZD)(e,"update readOnly"),e.readOnly)}),"assign pending value":(0,w.a)({pendingValue:({event:e})=>((0,S.ZD)(e,"update value"),e.value)}),"clear pending value":(0,w.a)({pendingValue:void 0}),"assign previous value":(0,w.a)({previousValue:({event:e})=>((0,S.ZD)(e,"done syncing"),e.value)}),"emit done syncing value":(0,O.a)({type:"done syncing value"}),"emit syncing value":(0,O.a)({type:"syncing value"})},guards:{"initial value synced":({context:e})=>e.initialValueSynced,"is busy":({context:e})=>{let t=!e.readOnly,n=e.isProcessingLocalChanges,o=isChangingRemotely(e.slateEditor)??!1,i=t&&(n||o);return tO("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,S.ZD)(t,"done syncing"),e.pendingValue!==t.value),"pending value equals previous value":({context:e})=>m(e.pendingValue,e.previousValue)},actors:{"sync value":tR}}).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,B.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:[()=>{tO("entry: syncing->idle")}],exit:[()=>{tO("exit: syncing->idle")}],on:{"update value":[{guard:(0,B.j)(["is empty value",(0,B.n)("initial value synced")]),actions:["assign initial value synced","emit done syncing value"]},{guard:(0,B.j)(["is empty array",(0,B.n)("initial value synced")]),actions:["assign initial value synced",(0,O.a)({type:"value changed",value:[]}),"emit done syncing value"]},{guard:(0,B.j)(["is busy","is new value"]),target:"busy",actions:["assign pending value"]},{guard:"is new value",target:"syncing",actions:["assign pending value"]},{guard:(0,B.n)("initial value synced"),actions:[()=>{tO("no new value â setting initial value as synced")},"assign initial value synced","emit done syncing value"]},{actions:[()=>{tO("no new value and initial value already synced")}]}]}},busy:{entry:[()=>{tO("entry: syncing->busy")}],exit:[()=>{tO("exit: syncing->busy")}
5],after:{1e3:[{guard:"is busy",target:".",reenter:!0,actions:[()=>{tO("reenter: syncing->busy")}]},{target:"syncing"}]},on:{"update value":[{guard:"is new value",actions:["assign pending value"]}]}},syncing:{entry:[()=>{tO("entry: syncing->syncing")},"emit syncing value"],exit:[()=>{tO("exit: syncing->syncing")},"emit done syncing value"],invoke:{src:"sync value",id:"sync value",input:({context:e})=>({context:{keyGenerator:e.keyGenerator,previousValue:e.previousValue,readOnly:e.readOnly,schema:e.schema},slateEditor:e.slateEditor,streamBlocks:!e.initialValueSynced,value:e.pendingValue})},on:{"update value":{guard:"is new value",actions:["assign pending value"]},patch:{actions:[(0,O.a)(({event:e})=>e)]},"invalid value":{actions:[(0,O.a)(({event:e})=>e)]},"value changed":{actions:[(0,O.a)(({event:e})=>e)]},"done syncing":[{guard:"value changed while syncing",actions:["assign previous value","assign initial value synced"],target:"syncing",reenter:!0},{target:"idle",actions:["clear pending value","assign previous value","assign initial value synced"]}]}}}});async function updateValue({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||(tO("Value is empty"),p.ML.withoutNormalizing(n,()=>{withoutSaving(n,()=>{withRemoteChanges(n,()=>{withoutPatching(n,()=>{if(r)return;s&&p.YR.deselect(n);let e=n.children.length;n.children.forEach((t,o)=>{p.YR.removeNodes(n,{at:[e-1-o]})}),p.YR.insertNodes(n,n.pteCreateTextBlock({decorators:[]}),{at:[0]}),s&&p.YR.select(n,[0,0])})})})}),a=!0),i&&i.length>0){let s=toSlateValue(i,{schemaTypes:e.schema});o?await new Promise(o=>{p.ML.withoutNormalizing(n,()=>{withRemoteChanges(n,()=>{withoutPatching(n,()=>{if(r){o();return}a=removeExtraBlocks({slateEditor:n,slateValueFromProps:s}),(async()=>{for await(let[o,r]of getStreamedBlocks({slateValue:s})){let{blockChanged:s,blockValid:c}=syncBlock({context:e,sendBack:t,block:o,index:r,slateEditor:n,value:i});a=s||a,l=l&&c}o()})()})})})}):p.ML.withoutNormalizing(n,()=>{withRemoteChanges(n,()=>{withoutPatching(n,()=>{if(r)return;a=removeExtraBlocks({slateEditor:n,slateValueFromProps:s});let o=0;for(let r of s){let{blockChanged:s,blockValid:c}=syncBlock({context:e,sendBack:t,block:r,index:o,slateEditor:n,value:i});a=s||a,l=l&&c,o++}})})})}if(!l){tO("Invalid value, returning"),r=!0,t({type:"done syncing",value:i});return}if(a){tO("Server value changed, syncing editor");try{n.onChange()}catch(e){console.error(e),t({type:"invalid value",resolution:null,value:i}),r=!0,t({type:"done syncing",value:i});return}s&&!n.selection&&(p.YR.select(n,{anchor:{path:[0,0],offset:0},focus:{path:[0,0],offset:0}}),n.onChange()),t({type:"value changed",value:i})}else tO("Server value and editor value is equal, no need to sync.");r=!0,t({type:"done syncing",value:i})}function removeExtraBlocks({slateEditor:e,slateValueFromProps:t}){let n=!1,o=e.children.length;if(t.length<o){for(let n=o-1;n>t.length-1;n--)p.YR.removeNodes(e,{at:[n]});n=!0}return n}async function*getStreamedBlocks({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 syncBlock({context:e,sendBack:t,block:n,index:o,slateEditor:i,value:r}){let a=!1,l=!0,s=i.children[o],c=s&&!m(n,s);return p.ML.withoutNormalizing(i,()=>{withRemoteChanges(i,()=>{withoutPatching(i,()=>{if(c&&l){let c=[r[o]],d=validateValue(c,e.schema,e.keyGenerator);!d.valid&&d.resolution?.autoResolve&&d.resolution?.patches.length>0&&!e.readOnly&&e.previousValue&&e.previousValue!==r&&(console.warn(`${d.resolution.action} for block with _key '${c[0]._key}'. ${d.resolution?.description}`),d.resolution.patches.forEach(e=>{t({type:"patch",patch:e})})),d.valid||d.resolution?.autoResolve?(s._key===n._key&&s._type===n._type?(tO.enabled&&tO("Updating block",s,n),function(e,t,n,o){if(p.YR.setNodes(e,t,{at:[o]}),e.isTextBlock(t)&&e.isTextBlock(n)){let i=n.children.length;t.children.length<i&&Array.from(Array(i-t.children.length)).forEach((t,n)=>{let r=i-1-n;r>0&&(tO("Removing child"),p.YR.removeNodes(e,{at:[o,r]}))}),t.children.forEach((t,i)=>{let r=n.children[i],a=!m(t,r),l=!m(t.text,r?.text),s=[o,i];if(a){if(t._key===r?._key&&t._type===r?._type){tO("Updating changed child",t,r),p.YR.setNodes(e,t,{at:s});let n=p.xv.isText(t)&&"span"===t._type&&p.xv.isText(r)&&"span"===r._type;n&&l?(r.text.length>0&&p.YR.delete(e,{at:{focus:{path:s,offset:0},anchor:{path:s,offset:r.text.length}}}),p.YR.insertText(e,t.text,{at:s}),e.onChange()):n||(tO("Updating changed inline object child",t),p.YR.setNodes(e,{_key:K},{at:[...s,0],voids:!0}))}else r?(tO("Replacing child",t),p.YR.removeNodes(e,{at:[o,i]}),p.YR.insertNodes(e,t,{at:[o,i]}),e.onChange()):r||(tO("Inserting new child",t),p.YR.insertNodes(e,t,{at:[o,i]}),e.onChange())}})}}(i,n,s,o)):(tO.enabled&&tO("Replacing block",s,n),function(e,t,n){let o=e.selection,i=o&&o.focus.path[0]===n;i&&p.YR.deselect(e),p.YR.removeNodes(e,{at:[n]}),p.YR.insertNodes(e,t,{at:[n]}),e.onChange(),i&&p.YR.select(e,o)}(i,n,o)),a=!0):(t({type:"invalid value",resolution:d.resolution,value:r}),l=!1)}if(!s&&l){let a=[r[o]],s=validateValue(a,e.schema,e.keyGenerator);
5tO.enabled&&tO("Validating and inserting new block in the end of the value",n),s.valid||s.resolution?.autoResolve?p.YR.insertNodes(i,n,{at:[o]}):(tO("Invalid",s),t({type:"invalid value",resolution:s.resolution,value:r}),l=!1)}})})}),{blockChanged:a,blockValid:l}}let tT=debugWithName("setup");function createInternalEditor(e){tT("Creating new Editor instance");let t=[],n=(0,B.c)(ty,{input:function(e){let{legacySchema:t,schema:n}=function(e){var t;let n=e.schemaDefinition?function(e){let t=e?.blockObjects?.map(e=>z.fe({type:"object",name:tv[e.name]??e.name,title:void 0===e.title?tx[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=>z.fe({type:"object",name:tv[e.name]??e.name,title:void 0===e.title?tx[e.name]:e.title,fields:e.fields?.map(e=>({name:e.name,type:e.type,title:e.title??V(e.name)}))??[]}))??[],o=(0,z.Z2)({type:"array",name:"portable-text",of:[...t.map(e=>({type:e.name})),{type:"block",name:"block",of:n.map(e=>({type:e.name})),marks:{decorators:e?.decorators?.map(e=>({title:e.title??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=M.V.compile({types:[o,...t,...n]}).get("portable-text"),r=createLegacySchema(i);return{...r,blockObjects:r.blockObjects.map(e=>void 0!==tb[e.name]?{...e,name:tb[e.name],type:{...e.type,name:tb[e.name]}}:e),inlineObjects:r.inlineObjects.map(e=>void 0!==tb[e.name]?{...e,name:tb[e.name]}:e)}}(e.schemaDefinition):createLegacySchema(e.schema.hasOwnProperty("jsonType")?e.schema:(t=e.schema,M.V.compile({name:"blockTypeSchema",types:[t]}).get(t.name))),o={annotations:n.annotations.map(e=>({name:e.name,fields:e.fields.map(e=>({name:e.name,type:e.type.jsonType,title:e.type.title})),title:e.title})),block:{name:n.block.name},blockObjects:n.blockObjects.map(e=>({name:e.name,fields:e.fields.map(e=>({name:e.name,type:e.type.jsonType,title:e.type.title})),title:e.title})),decorators:n.decorators.map(e=>({name:e.value,title:e.title,value:e.value})),inlineObjects:n.inlineObjects.map(e=>({name:e.name,fields:e.fields.map(e=>({name:e.name,type:e.type.jsonType,title:e.type.title})),title:e.title})),span:{name:n.span.name},styles:n.styles.map(e=>({name:e.value,title:e.title,value:e.value})),lists:n.lists.map(e=>({name:e.value,title:e.title,value:e.value}))};return{legacySchema:n,schema:o}}(e);return{converters:[ee,et,{mimeType:"text/html",serialize:({snapshot:e,event:t})=>{if(!e.context.selection)return{type:"serialization.failure",mimeType:"text/html",originEvent:t.originEvent,reason:"No selection"};let n=(0,k.Ly)(e),o=(0,N.io)(n,{onMissingComponent:!1,components:{unknownType:({children:e})=>void 0!==e?`${e}`:""}});return""===o?{type:"serialization.failure",mimeType:"text/html",originEvent:t.originEvent,reason:"Serialized HTML is empty"}:{type:"serialization.success",data:o,mimeType:"text/html",originEvent:t.originEvent}},deserialize:({snapshot:e,event:n})=>{let o=(0,T.zW)(n.data,t.portableText,{keyGenerator:e.context.keyGenerator,unstable_whitespaceOnPasteMode:t.block.options.unstable_whitespaceOnPasteMode}).flatMap(t=>{let n=(0,g.IX)({context:e.context,block:t,options:{refreshKeys:!1,validateFields:!0}});return n?[n]:[]});return 0===o.length?{type:"deserialization.failure",mimeType:"text/html",reason:"No blocks deserialized"}:{type:"deserialization.success",data:o,mimeType:"text/html"}}},{mimeType:"text/plain",serialize:({snapshot:e,event:t})=>e.context.selection?{type:"serialization.success",data:(0,k.Ly)(e).map(n=>(0,g.dz)(e.context,n)?n.children.map(n=>n._type===e.context.schema.span.name?n.text:"drag.dragstart"===t.originEvent?`[${e.context.schema.inlineObjects.find(e=>e.name===n._type)?.title??"Object"}]`:"").join(""):"drag.dragstart"===t.originEvent?`[${e.context.schema.blockObjects.find(e=>e.name===n._type)?.title??"Object"}]`:"").filter(e=>""!==e).join(` 6 7`),mimeType:"text/plain",originEvent:t.originEvent}:{type:"serialization.failure",mimeType:"text/plain",originEvent:t.originEvent,reason:"No selection"},deserialize:({snapshot:e,event:n})=>{let o=`<html><body>${String(n.data).replace(/[&<>"'`=/]/g,e=>en[e]).split(/\n{2,}/).map(e=>e?`<p>${e.replace(/(?:\r\n|\r|\n)/g,"<br/>")}</p>`:"<p></p>").join("")}</body></html>`,i=(0,T.zW)(o,t.portableText,{keyGenerator:e.context.keyGenerator}).flatMap(t=>{let n=(0,g.IX)({context:e.context,block:t,options:{refreshKeys:!1,validateFields:!0}});return n?[n]:[]});return 0===i.length?{type:"deserialization.failure",mimeType:"text/plain",reason:"No blocks de
7serialized"}:{type:"deserialization.success",data:i,mimeType:"text/plain"}}}],getLegacySchema:()=>t,keyGenerator:e.keyGenerator??defaultKeyGenerator,maxBlocks:e.maxBlocks,readOnly:e.readOnly,schema:n,initialValue:e.initialValue}}(e)}),o=(0,B.c)(tw),i=function(e){eC("Creating new Slate editor instance");let t=withPlugins((0,u.BU)((0,p.Jh)()),{editorActor:e.editorActor,relayActor:e.relayActor,subscriptions:e.subscriptions});H.set(t,{}),q.set(t,{}),t.decoratedRanges=[],t.decoratorState={};let n=createPlaceholderBlock(e.editorActor.getSnapshot().context);t.value=[n],t.blockIndexMap=new Map,t.listIndexMap=new Map,buildIndexMaps({schema:e.editorActor.getSnapshot().context.schema,value:t.value},{blockIndexMap:t.blockIndexMap,listIndexMap:t.listIndexMap});let o=toSlateValue(t.value,{schemaTypes:e.editorActor.getSnapshot().context.schema});return{instance:t,initialValue:o}}({editorActor:n,relayActor:o,subscriptions:t}),r=function(e,t){let n=t.getSnapshot().context.schema;return{focus:()=>{t.send({type:"focus",editor:e})},blur:()=>{t.send({type:"blur",editor:e})},toggleMark:n=>{t.send({type:"behavior event",behaviorEvent:{type:"decorator.toggle",decorator:n},editor:e})},toggleList:n=>{t.send({type:"behavior event",behaviorEvent:{type:"list item.toggle",listItem:n},editor:e})},toggleBlockStyle:n=>{t.send({type:"behavior event",behaviorEvent:{type:"style.toggle",style:n},editor:e})},isMarkActive:n=>{let o=getEditorSnapshot({editorActorSnapshot:t.getSnapshot(),slateEditorInstance:e});return(0,v.WH)(o).includes(n)},marks:()=>{let n=getEditorSnapshot({editorActorSnapshot:t.getSnapshot(),slateEditorInstance:e}),o=(0,v.YG)(n),i=(0,v.WH)(n);return[...o,...i]},undo:()=>{t.send({type:"behavior event",behaviorEvent:{type:"history.undo"},editor:e})},redo:()=>{t.send({type:"behavior event",behaviorEvent:{type:"history.redo"},editor:e})},select:n=>{let o=toSlateRange({context:{schema:t.getSnapshot().context.schema,value:e.value,selection:n},blockIndexMap:e.blockIndexMap});o?p.YR.select(e,o):p.YR.deselect(e),e.onChange()},focusBlock:()=>{if(e.selection){let t=p.NB.descendant(e,e.selection.focus.path.slice(0,1));if(t)return fromSlateValue([t],n.block.name,H.get(e))[0]}},focusChild:()=>{if(e.selection){let t=p.NB.descendant(e,e.selection.focus.path.slice(0,1));if(t&&e.isTextBlock(t))return fromSlateValue([t],n.block.name,H.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?slateRangeToSelection({schema:t.getSnapshot().context.schema,editor:e,range:e.selection})?.focus.path??[]:[];if(!e.selection)throw Error("The editor has no selection");let[r]=Array.from(p.ML.nodes(e,{at:e.selection.focus.path.slice(0,1),match:e=>e._type===n.block.name}))[0]||[void 0];if(!r)throw Error("No focused text block");if(o.name!==n.span.name&&!n.inlineObjects.some(e=>e.name===o.name))throw Error("This type cannot be inserted as a child to a text block");let a=toSlateValue([{_key:t.getSnapshot().context.keyGenerator(),_type:n.block.name,children:[{_key:t.getSnapshot().context.keyGenerator(),_type:o.name,...i||{}}]}],{schemaTypes:t.getSnapshot().context.schema})[0].children[0],l=e.selection.focus.path.slice(0,2),s=a._type===n.span.name,c=p.NB.get(e,l);return s&&c._type!==n.span.name&&(tS("Inserting span child next to inline object child, moving selection + 1"),e.move({distance:1,unit:"character"})),p.YR.insertNodes(e,a,{select:!0,at:e.selection}),e.onChange(),e.selection?slateRangeToSelection({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?slateRangeToSelection({schema:t.getSnapshot().context.schema,editor:e,range:e.selection})?.focus.path??[]:[]),hasBlockStyle:t=>{try{return function({editor:e,style:t}){if(!e.selection)return!1;let n=[...p.ML.nodes(e,{at:e.selection,match:t=>e.isTextBlock(t)})];return n.length>0&&n.every(([e])=>e.style===t)}({editor:e,style:t})}catch{return!1}},hasListStyle:t=>{try{return function({editor:e,listItem:t}
7){if(!e.selection)return!1;let n=[...p.ML.nodes(e,{at:e.selection,match:t=>e.isTextBlock(t)})];return n.length>0&&n.every(([n])=>e.isListBlock(n)&&n.listItem===t)}({editor:e,listItem:t})}catch{return!1}},isVoid:e=>![n.block.name,n.span.name].includes(e._type),findByPath:o=>{let i=toSlateRange({context:{schema:t.getSnapshot().context.schema,value:e.value,selection:{focus:{path:o,offset:0},anchor:{path:o,offset:0}}},blockIndexMap:e.blockIndexMap});if(i){let[t,r]=p.ML.node(e,i.focus.path.slice(0,1));if(t&&r&&"string"==typeof t._key){if(1===o.length&&1===i.focus.path.length)return[fromSlateValue([t],n.block.name)[0],[{_key:t._key}]];let r=fromSlateValue([t],n.block.name,H.get(e))[0];if(e.isTextBlock(r)){let e=r.children[i.focus.path[1]];if(e)return[e,[{_key:t._key},"children",{_key:e._key}]]}}}return[void 0,void 0]},findDOMNode:t=>{let n;try{let[o]=Array.from(p.ML.nodes(e,{at:[],match:e=>e._key===t._key})||[])[0]||[void 0];n=u.F3.toDOMNode(e,o)}catch{}return n},activeAnnotations:()=>{if(!e.selection||e.selection.focus.path.length<2)return[];try{let t=[],n=p.ML.nodes(e,{at:e.selection,match:e=>p.xv.isText(e)&&void 0!==e.marks&&Array.isArray(e.marks)&&e.marks.length>0});for(let[o,i]of n){let[n]=p.ML.node(e,i,{depth:1});e.isTextBlock(n)&&n.markDefs?.forEach(e=>{p.xv.isText(o)&&o.marks&&Array.isArray(o.marks)&&o.marks.includes(e._key)&&t.push(e)})}return t}catch{return[]}},isAnnotationActive:n=>{let o=getEditorSnapshot({editorActorSnapshot:t.getSnapshot(),slateEditorInstance:e});return(0,v.kH)(n)(o)},addAnnotation:(o,i)=>{let r;return p.ML.withoutNormalizing(e,()=>{r=addAnnotationOperationImplementation({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=toSlateRange({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"){tS("Deleting content in selection"),p.YR.delete(e,{at:r,hanging:!0,voids:!0}),e.onChange();return}if(i?.mode==="blocks"&&(tS("Deleting blocks touched by selection"),p.YR.removeNodes(e,{at:r,voids:!0,match:t=>e.isTextBlock(t)||!e.isTextBlock(t)&&p.W_.isElement(t)})),i?.mode==="children"&&(tS("Deleting children touched by selection"),p.YR.removeNodes(e,{at:r,voids:!0,match:t=>t._type===n.span.name||!e.isTextBlock(t)&&p.W_.isElement(t)})),0===e.children.length){let n=createPlaceholderBlock(t.getSnapshot().context);e.children=[n],e.value=[n],buildIndexMaps({schema:t.getSnapshot().context.schema,value:e.value},{blockIndexMap:e.blockIndexMap,listIndexMap:e.listIndexMap})}e.onChange()}}},removeAnnotation:n=>{t.send({type:"behavior event",behaviorEvent:{type:"annotation.remove",annotation:{name:n.name}},editor:e})},getSelection:()=>{let n=null;if(e.selection){let o=J.get(e.selection);if(o)return o;n=slateRangeToSelection({schema:t.getSnapshot().context.schema,editor:e,range:e.selection}),J.set(e.selection,n)}return n},getValue:()=>fromSlateValue(e.children,n.block.name,H.get(e)),isCollapsedSelection:()=>!!e.selection&&p.e6.isCollapsed(e.selection),isExpandedSelection:()=>!!e.selection&&p.e6.isExpanded(e.selection),insertBreak:()=>{e.insertBreak(),e.onChange()},getFragment:()=>fromSlateValue(e.getFragment(),n.block.name),isSelectionsOverlapping:(n,o)=>{let i=toSlateRange({context:{schema:t.getSnapshot().context.schema,value:e.value,selection:n},blockIndexMap:e.blockIndexMap}),r=toSlateRange({context:{schema:t.getSnapshot().context.schema,value:e.value,selection:o},blockIndexMap:e.blockIndexMap});return p.e6.isRange(i)&&p.e6.isRange(r)&&p.e6.includes(i,r)}}}(i.instance,n),{mutationActor:a,syncActor:l}=function(e){tT("Creating new Actors");let t=(0,B.c)(tE,{input:{readOnly:e.editorActor.getSnapshot().matches({"edit mode":"read only"}),schema:e.editorActor.getSnapshot().context.schema,slateEditor:e.slateEditor}}),n=(0,B.c)(tB,{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=>
7{switch(t.type){case"invalid value":case"value changed":e.relayActor.send(t);break;case"patch":e.editorActor.send({...t,type:"internal.patch",value:fromSlateValue(e.slateEditor.children,e.editorActor.getSnapshot().context.schema.block.name,H.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:createEditorDom(e=>n.send(e),i.instance),getSnapshot:()=>getEditorSnapshot({editorActorSnapshot:n.getSnapshot(),slateEditorInstance:i.instance}),registerBehavior:e=>{let t=createEditorPriority({name:"custom",reference:{priority:Z,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 tN=(0,r.createContext)({});function RouteEventsToChanges(e){let t,n,o;let l=(0,i.c)(7);l[0]!==e?(t=t=>e.onChange(t),l[0]=e,l[1]=t):t=l[1];let s=(0,a.i)(t);return l[2]!==s||l[3]!==e.relayActor?(n=()=>{let t=e.relayActor.on("*",e=>{let t=eventToChange(e);t&&s(t)});return()=>{t.unsubscribe()}},l[2]=s,l[3]=e.relayActor,l[4]=n):n=l[4],l[5]!==e.relayActor?(o=[e.relayActor],l[5]=e.relayActor,l[6]=o):o=l[6],(0,r.useEffect)(n,o),null}function eventToChange(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 tM=debugWithName("component:PortableTextEditor");let PortableTextEditor=class PortableTextEditor extends r.Component{static displayName="PortableTextEditor";change$=new E.x;subscriptions=[];unsubscribers=[];constructor(e){if(super(e),e.editor)this.editor=e.editor,this.schemaTypes=this.editor._internal.editorActor.getSnapshot().context.getLegacySchema();else{let{actors:t,editor:n,subscriptions:o}=createInternalEditor({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=eventToChange(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&&(stopActor(this.actors.editorActor),stopActor(this.actors.mutationActor),stopActor(this.actors.relayActor),stopActor(this.actors.syncActor))}setEditable=e=>{this.editor._internal.editable={...this.editor._internal.editable,...e}};render(){let e=this.props.editor?void 0:this.props.incomingPatches$??this.props.patches$;return(0,s.jsxs)(s.Fragment,{children:[e?(0,s.jsx)(RoutePatchesObservableToEditorActor,{editorActor:this.editor._internal.editorActor,patches$:e}):null,(0,s.jsx)(X.Provider,{value:this.editor._internal.editorActor,children:(0,s.jsx)(tN.Provider,{value:this.actors.relayActor,children:(0,s.jsx)(u.mH,{editor:this.editor._internal.slateEditor.instance,initialValue:this.editor._internal.slateEditor.initialValue,children:(0,s.jsx)(Q.Provider,{value:this,children:this.props.children})})})})]})}static activeAnnotations=e=>e&&e.editable?e.editable.activeAnnotations():[];static isAnnotationActive=(e,t)=>
7!!e&&!!e.editable&&e.editable.isAnnotationActive(t);static addAnnotation=(e,t,n)=>e.editable?.addAnnotation(t,n);static blur=e=>{tM("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=>{tM("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)=>e.editable?.isMarkActive(t);static insertChild=(e,t,n)=>(tM("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)=>{tM("Host setting selection",t),e.editable?.select(t)};static removeAnnotation=(e,t)=>e.editable?.removeAnnotation(t);static toggleBlockStyle=(e,t)=>(tM("Host is toggling block style"),e.editable?.toggleBlockStyle(t));static toggleList=(e,t)=>e.editable?.toggleList(t);static toggleMark=(e,t)=>{tM("Host toggling mark",t),e.editable?.toggleMark(t)};static getFragment=e=>e.editable?.getFragment();static undo=e=>{tM("Host undoing"),e.editable?.undo()};static redo=e=>{tM("Host redoing"),e.editable?.redo()};static isSelectionsOverlapping=(e,t,n)=>e.editable?.isSelectionsOverlapping(t,n)};function RoutePatchesObservableToEditorActor(e){let t,n;let o=(0,i.c)(4);return o[0]!==e.editorActor||o[1]!==e.patches$?(t=()=>{let t=e.patches$.subscribe(t=>{e.editorActor.send({type:"patches",...t})});return()=>{t.unsubscribe()}},n=[e.editorActor,e.patches$],o[0]=e.editorActor,o[1]=e.patches$,o[2]=t,o[3]=n):(t=o[2],n=o[3]),(0,r.useEffect)(t,n),null}function RenderSpan(e){let t=(0,u._7)(),n=(0,r.useContext)(X),o=(0,c.v9)(n,e=>e.context.getLegacySchema()),i=(0,r.useRef)(null),a=usePortableTextEditor(),l=(0,u.vt)(),[d,p]=(0,r.useState)(!1),[h,f]=(0,r.useState)(!1),g=e.children.props.parent,y=g&&t.isTextBlock(g)?g:void 0,k=(0,r.useMemo)(()=>y?[{_key:y._key},"children",{_key:e.leaf._key}]:void 0,[y,e.leaf._key]),v=n.getSnapshot().context.schema.decorators.map(e=>e.name),b=_((e.leaf.marks??[]).filter(e=>v.includes(e))),x=(e.leaf.marks??[]).flatMap(e=>{if(v.includes(e))return[];let t=y?.markDefs?.find(t=>t._key===e);return t?[t]:[]}),E=x.length>0&&l;(0,r.useEffect)(()=>{if(!E){p(!1);return}let e=PortableTextEditor.getSelection(a);e&&m(e.focus.path,k)&&PortableTextEditor.isCollapsedSelection(a)&&(0,r.startTransition)(()=>{p(!0)})},[E,k,a]);let S=(0,r.useCallback)(()=>{if(!E)return;let e=window.getSelection();if(!e){f(!1);return}if(e&&e.rangeCount>0){let t=e.getRangeAt(0);i.current&&t.intersectsNode(i.current)?f(!0):f(!1)}else f(!1)},[E]);(0,r.useEffect)(()=>{if(!E)return;let e=n.on("blurred",()=>{p(!1),f(!1)}),t=n.on("focused",()=>{let e=PortableTextEditor.getSelection(a);e&&m(e.focus.path,k)&&PortableTextEditor.isCollapsedSelection(a)&&p(!0),S()}),o=n.on("selection",e=>{e.selection&&m(e.selection.focus.path,k)&&PortableTextEditor.isCollapsedSelection(a)?p(!0):p(!1),S()});return()=>{e.unsubscribe(),t.unsubscribe(),o.unsubscribe()}},[n,k,a,S,E]),(0,r.useEffect)(()=>S(),[S]);let w=e.children;for(let t of b){let n=o.decorators.find(e=>e.value===t);k&&n&&e.renderDecorator&&(w=e.renderDecorator({children:w,editorElementRef:i,focused:d,path:k,selected:h,schemaType:n,value:t,type:n}))}for(let t of x){let n=o.annotations.find(e=>e.name===t._type);n&&(w=y&&k&&e.renderAnnotation?(0,s.jsx)("span",{ref:i,children:e.renderAnnotation({block:y,children:w,editorElementRef:i,focused:d,path:k,selected:h,schemaType:n,value:t,type:n})}):(0,s.jsx)("span",{ref:i,children:w}))}if(y&&k&&e.renderChild){let t=y.children.find(t=>t._key===e.leaf._key);t&&(w=e.renderChild({annotations:x,children:w,editorElementRef:i,focused:d,path:k,schemaType:o.span,selected:h,value:t,type:o.span}))}return(0,s.jsx)("span",{...e.attributes,ref:i,children:w})}let tC={position:"absolute",userSelect:"none",pointerEvents:"none",left:0,right:0};
7function RenderLeaf(e){let t;let n=(0,i.c)(12),o=(0,r.useContext)(X),a=(0,c.v9)(o,_temp);if(e.leaf._type!==a.span.name)return e.children;n[0]!==e?(t=(0,s.jsx)(RenderSpan,{...e}),n[0]=e,n[1]=t):t=n[1];let l=t;if(e.renderPlaceholder&&e.leaf.placeholder&&""===e.text.text){let t,o,i;return n[2]!==e.renderPlaceholder?(t=e.renderPlaceholder(),n[2]=e.renderPlaceholder,n[3]=t):t=n[3],n[4]!==t?(o=(0,s.jsx)("span",{style:tC,contentEditable:!1,children:t}),n[4]=t,n[5]=o):o=n[5],n[6]!==l||n[7]!==o?(i=(0,s.jsxs)(s.Fragment,{children:[o,l]}),n[6]=l,n[7]=o,n[8]=i):i=n[8],i}let d=e.leaf.rangeDecoration;if(d){let e;n[9]!==d||n[10]!==l?(e=d.component({children:l}),n[9]=d,n[10]=l,n[11]=e):e=n[11],l=e}return l}function _temp(e){return e.context.schema}function RenderText(e){let t;let n=(0,i.c)(5);return n[0]!==e.attributes||n[1]!==e.children||n[2]!==e.text._key||n[3]!==e.text._type?(t=(0,s.jsx)("span",{...e.attributes,"data-child-key":e.text._key,"data-child-name":e.text._type,"data-child-type":"span",children:e.children}),n[0]=e.attributes,n[1]=e.children,n[2]=e.text._key,n[3]=e.text._type,n[4]=t):t=n[4],t}let tA="u">typeof window&&/Mac|iPod|iPhone|iPad/.test(window.navigator.userAgent),tI={alt:"altKey",control:"ctrlKey",meta:"metaKey",shift:"shiftKey"},tP={add:"+",break:"pause",cmd:"meta",command:"meta",ctl:"control",ctrl:"control",del:"delete",down:"arrowdown",esc:"escape",ins:"insert",left:"arrowleft",mod:tA?"meta":"control",opt:"alt",option:"alt",return:"enter",right:"arrowright",space:" ",spacebar:" ",up:"arrowup",win:"meta",windows:"meta"},tD={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 parseHotkey(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=toKeyName(i),a=tI[r],l=tP[i],s=tD[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=toKeyName(e);return tD[t]??t.toUpperCase().charCodeAt(0)}(i)),void 0!==a&&(t[a]=!o||null)}return t}function compareHotkey(e,t){return(null==e.altKey||e.altKey===t.altKey)&&(null==e.ctrlKey||e.ctrlKey===t.ctrlKey)&&(null==e.metaKey||e.metaKey===t.metaKey)&&(null==e.shiftKey||e.shiftKey===t.shiftKey)&&(void 0!==e.ke
7yCode&&void 0!==t.keyCode?91===e.keyCode&&93===t.keyCode||e.keyCode===t.keyCode:e.keyCode===t.keyCode||e.key===t.key.toLowerCase())}function toKeyName(e){let t=e.toLowerCase();return tP[t]??t}let tj=debugWithName("plugin:withHotKeys"),tL=(0,S.cY)({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=toSlateRange({context:{schema:e.schema,value:e.slateEditor.value,selection:n.selection},blockIndexMap:e.slateEditor.blockIndexMap});if(!p.e6.isRange(o)){n.onMoved?.({newSelection:null,rangeDecoration:n,origin:"local"});continue}t.push({rangeDecoration:n,...o})}e.slateEditor.decoratedRanges=t},"update range decorations":({context:e,event:t})=>{if("range decorations updated"!==t.type)return;let n=[];for(let o of t.rangeDecorations){let t=toSlateRange({context:{schema:e.schema,value:e.slateEditor.value,selection:o.selection},blockIndexMap:e.slateEditor.blockIndexMap});if(!p.e6.isRange(t)){o.onMoved?.({newSelection:null,rangeDecoration:o,origin:"local"});continue}n.push({rangeDecoration:o,...t})}e.slateEditor.decoratedRanges=n},"move range decorations":({context:e,event:t})=>{if("slate operation"!==t.type)return;let n=[];for(let o of e.slateEditor.decoratedRanges){let i;let r=toSlateRange({context:{schema:e.schema,value:e.slateEditor.value,selection:o.rangeDecoration.selection},blockIndexMap:e.slateEditor.blockIndexMap});if(!p.e6.isRange(r)){o.rangeDecoration.onMoved?.({newSelection:null,rangeDecoration:o.rangeDecoration,origin:"local"});continue}if((i=function(e,t){let n=p.E9.transform(e.anchor,t),o=p.E9.transform(e.focus,t);return null===n||null===o?null:p.E9.equals(n,e.anchor)&&p.E9.equals(o,e.focus)?e:{anchor:n,focus:o}}(r,t.operation))&&i!==r||null===i&&r){let t=i?slateRangeToSelection({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:slateRangeToSelection({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:createDecorate(e.schema,e.slateEditor)})})},actors:{"slate operation listener":(0,R.E9)(({input:e,sendBack:t})=>{let n=e.slateEditor.apply;return e.slateEditor.apply=e=>{"set_selection"!==e.type&&t({type:"slate operation",operation:e}),n(e)},()=>{e.slateEditor.apply=n}})},guards:{"has pending range decorations":({context:e})=>e.pendingRangeDecorations.length>0,"has range decorations":({context:e})=>e.slateEditor.decoratedRanges.length>0,"has different decorations":({context:e,event:t})=>{if("range decorations updated"!==t.type)return!1;let n=e.slateEditor.decoratedRanges.map(e=>({anchor:e.rangeDecoration.selection?.anchor,focus:e.rangeDecoration.selection?.focus})),o=t.rangeDecorations.map(e=>({anchor:e.selection?.anchor,focus:e.selection?.focus}));return!m(n,o)},"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:createDecorate(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,B.j)(["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,B.j)(["has range decorations","not read only"])}}},"moving range decorations":{entry:["move range decorations"],always:{target:"idle"}}}}}});function createDecorate(e,t){return function([n,o]){if(isEqualToEmptyEditor(t.children,e))return[{anchor:{path:[0,0],offset:0},focus:{path:[0,0],offset:0},placeholder:!0}];if(0===o.length||!p.W_.isElement(n)||0===n.children.length)return[];let i=o.at(0);return void 0===i?[]:t.decoratedRanges.filter(e=>p.e6.isCollapsed(e)?n.children.some((t,n)=>p.y$.equals(e.anchor.path,[i,n])&&p.y$.equals(e.focus.path,[i,n])):p.e6.intersection(e,{anchor:{path:o,offset:0},focus:{path:o,offset:0}})||p.e6.includes(e,o))}}let tU=debugWithName("component:Editable"),tY=(0,r.forwardRef)(function(e,t){let{hotkeys:n,onBlur:o,onFocus:i,onBeforeInput:a,onPaste:l,onCopy:h,onCut:f,onClick:y,onDragStart:k,onDrag:v,onDragEnd:b,onDragEnter:x,onDragOver:_,onDrop:E,onDragLeave:S,rangeDecorations:w,renderAnnotation:O,renderBlock:R,renderChild:B,renderDecorator:T,renderListItem:N,renderPlaceholder:M,renderStyle:C,selection:A,scrollSelectionIntoView:I,spellCheck:P,...D}=e,j=usePortableTextEditor(),L=(0,r.useRef)(null),[U,Y]=(0,r.useState)(null),[$,z]=(0,r.useState)(!1);(0,r.useImperativeHandle)(t,()=>L.current);let V=(0,r.useContext)(X),G=(0,r.useContext)(tN),F=(0,c.v9)(V,e=>e.matches({"edit mode":"read only"})),K=(0,u.ui)(),W=(0,c.TH)(tL,{input:{rangeDecorations:w??[],readOnly:F,schema:V.getSnapshot().context.schema,slateEditor:K,skipSetup:!V.getSnapshot().matches({setup:"setting up"})}}),q=(0,c.v9)(W,e=>e.context.decorate?.fn);(0,r.useEffect)(()=>{W.send({type:"update read only",readOnly:F})},[W,F]),(0,r.useEffect)(()=>{W.send({type:"range decorations updated",rangeDecorations:w??[]})},[W,w]),(0,r.useMemo)(()=>F?K:(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,compareHotkey(parseHotkey(t),l)){r.preventDefault();let o=i[a];if(o){let i=o[t];tj(`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,compareHotkey(parseHotkey(e),s)){let n=i[a];if(n){let o=n[e];o(r,t)}}}})},n}})(V,j,n)(K),[V,n,j,F,K]);let J=(0,r.useCallback)(e=>(0,s.jsx)(RenderElement,{...e,readOnly:F,renderBlock:R,renderChild:B,renderListItem:N,renderStyle:C,spellCheck:P}),[P,F,R,B,N,C]),Z=(0,r.useCallback)(e=>(0,s.jsx)(RenderLeaf,{...e,readOnly:F,renderAnnotation:O,renderChild:B,renderDecorator:T,renderPlaceholder:M}),[F,O,B,T,M]),Q=(0,r.useCallback)(e=>(0,s.jsx)(RenderText,{...e}),[]),ee=(0,r.useCallback)(()=>{if(A){tU(`Selection from props ${JSON.stringify(A)}`);let e=function(e,t){if(!e||!t||0===t.length)return null;let n=null,o=null,{anchor:i,focus:r}=e;return i&&t.find(e=>m({_key:e._key},i.path[0]))&&(n=normalizePoint(i,t)),r&&t.find(e=>m({_key:e._key},r.path[0]))&&(o=normalizePoint(r,t)),n&&o?{anchor:n,focus:o,backward:e.backward}:null}(A,fromSlateValue(K.children,V.getSnapshot().context.schema.block.name));if(null!==e){tU(`Normalized selection from props ${JSON.stringify(e)}`);let t=toSlateRange({context:{schema:V.getSnapshot().context.schema,value:K.value,selection:e},blockIndexMap:K.blockIndexMap});t&&(p.YR.select(K,t),K.operations.some(e=>"set_selection"===e.type)||V.send({type:"update selection",selection:e}),K.onChange())}}},[V,A,K]);(0,r.useEffect)(()=>{let e=V.on("ready",()=>{W.send({type:"ready"}),ee()}),t=V.on("invalid value",()=>{z(!0)}),n=V.on("value changed",()=>{z(!1)});return()=>{e.unsubscribe(),t.unsubscribe(),n.unsubscribe()}},[W,V,ee]),(0,r.useEffect)(()=>{A&&!$&&ee()},[$,A,ee]);let et=(0,r.useCallback)(e=>{if(h)void 0!==h(e)&&e.preventDefault();else if(e.nativeEvent.clipboardData){e.stopPropagation(),e.preventDefault();let t=K.selection?slateRangeToSelection({schema:V.getSnapshot().context.schema,editor:K,range:K.selection}):void 0,n=t?{selection:t}:void 0;if(!n){console.warn("Could not find position for copy event");return}V.send({type:"behavior event",behaviorEvent:{type:"clipboard.copy",originEvent:{dataTransfer:e.nativeEvent.clipboardData},position:n},editor:K,nativeEvent:e})}},[h,V,K]),en=(0,r.useCallback)(e=>{if(f)void 0!==f(e)&&e.preventDefault();else if(e.nativeEvent.clipboardData){e.stopPropagation(),e.preventDefault();let t=V.getSnapshot().context.selection,n=t?{selection:t}:void 0;if(!n){console.warn("Could not find position for cut event");return}V.send({type:"behavior event",behaviorEvent:{type:"clipboard.cut",originEvent:{dataTransfer:e.nativeEvent.clipboardData},position:n},editor:K,nativeEvent:e})}},[f,V,K]),eo=(0,r.useCallback)(e=>{let t=fromSlateValue(K.children,V.getSnapshot().context.schema.block.name,H.get(K)),n=(K.selection?slateRangeToSelection({schema:V.getSnapshot().context.schema,editor:K,range:K.selection}):null)?.focus.path||[],o=l?.({event:e,value:t,path:n,schemaTypes:j.schemaTypes});if(o||!K.selection)e.preventDefault(),G.send({type:"loading"}),Promise.resolve(o).then(t=>{if(tU("Custom paste function from client resolved",t),t&&t.insert)t.insert?V.send({type:"behavior event",behaviorEvent:{type:"insert.blocks",blocks:(0,g.Pj)({context:{keyGenerator:V.getSnapshot().context.keyGenerator,schema:V.getSnapshot().context.schema},blocks:t.insert,options:{refreshKeys:!0,validateFields:!0}}),placement:"auto"},editor:K}):console.warn("Your onPaste function returned something unexpected:",t);else{tU("No result from custom paste handler, pasting normally");let t=V.getSnapshot().context.selection,n=t?{selection:t}:void 0;if(!n){console.warn("Could not find position for paste event");return}V.send({type:"behavior event",behaviorEvent:{type:"clipboard.paste",originEvent:{dataTransfer:e.clipboardData},position:n},editor:K,nativeEvent:e})}}).catch(e=>(console.warn(e),e)).finally(()=>{G.send({type:"done loading"})});else if(e.nativeEvent.clipboardData){e.preventDefault(),e.stopPropagation();
7let t=V.getSnapshot().context.selection,n=t?{selection:t}:void 0;if(!n){console.warn("Could not find position for paste event");return}V.send({type:"behavior event",behaviorEvent:{type:"clipboard.paste",originEvent:{dataTransfer:e.nativeEvent.clipboardData},position:n},editor:K,nativeEvent:e})}tU("No result from custom paste handler, pasting normally")},[V,l,j,G,K]),ei=(0,r.useCallback)(e=>{i&&i(e),e.isDefaultPrevented()||(G.send({type:"focused",event:e}),!K.selection&&isEqualToEmptyEditor(K.children,V.getSnapshot().context.schema)&&(p.YR.select(K,p.ML.start(K,[])),K.onChange()))},[V,i,G,K]),er=(0,r.useCallback)(e=>{if(y&&y(e),e.isDefaultPrevented()||e.isPropagationStopped())return;let t=getEventPosition({editorActor:V,slateEditor:K,event:e.nativeEvent});t&&V.send({type:"behavior event",behaviorEvent:{type:"mouse.click",position:t},editor:K,nativeEvent:e})},[y,V,K]),ea=(0,r.useCallback)(e=>{o&&o(e),e.isPropagationStopped()||G.send({type:"blurred",event:e})},[G,o]),el=(0,r.useCallback)(e=>{a&&a(e)},[a]),es=(0,r.useCallback)(()=>{if(!K.selection)return;let e=u.F3.findDocumentOrShadowRoot(K),{activeElement:t}=e;if(L.current!==t)return;let n=u.F3.getWindow(K).getSelection();if(!n||0===n.rangeCount)return;let o=n.getRangeAt(0);try{let e=u.F3.toDOMRange(K,K.selection);(e.startOffset!==o.startOffset||e.endOffset!==o.endOffset)&&(tU("DOM range out of sync, validating selection"),n?.removeAllRanges(),n.addRange(e))}catch{tU("Could not resolve selection, selecting top document"),p.YR.deselect(K),K.children.length>0&&p.YR.select(K,[0,0]),K.onChange()}},[L,K]);(0,r.useEffect)(()=>{if(U){let e=new MutationObserver(es);return e.observe(U,{attributeOldValue:!1,attributes:!1,characterData:!1,childList:!0,subtree:!0}),()=>{e.disconnect()}}},[es,U]);let ec=(0,r.useCallback)(t=>{e.onKeyDown&&e.onKeyDown(t),t.isDefaultPrevented()||K.pteWithHotKeys(t),t.isDefaultPrevented()||V.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:K,nativeEvent:t})},[e,V,K]),ed=(0,r.useCallback)(t=>{e.onKeyUp&&e.onKeyUp(t),t.isDefaultPrevented()||V.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:K,nativeEvent:t})},[e,V,K]),ep=(0,r.useMemo)(()=>{if(void 0!==I)return null===I?d:(e,t)=>{I(j,t)}},[j,I]);(0,r.useEffect)(()=>{L.current=u.F3.toDOMNode(K,K),Y(L.current)},[K,L]),(0,r.useEffect)(()=>{let e=u.F3.getWindow(K),onDragEnd_0=()=>{V.send({type:"dragend"})},onDrop_0=()=>{V.send({type:"drop"})};return e.document.addEventListener("dragend",onDragEnd_0),e.document.addEventListener("drop",onDrop_0),()=>{e.document.removeEventListener("dragend",onDragEnd_0),e.document.removeEventListener("drop",onDrop_0)}},[K,V]);let eu=(0,r.useCallback)(e=>{if(k?.(e),e.isDefaultPrevented()||e.isPropagationStopped())return;let t=getEventPosition({editorActor:V,slateEditor:K,event:e.nativeEvent});if(!t){console.warn("Could not find position for dragstart event");return}return V.send({type:"dragstart",origin:t}),V.send({type:"behavior event",behaviorEvent:{type:"drag.dragstart",originEvent:{clientX:e.clientX,clientY:e.clientY,dataTransfer:e.dataTransfer},position:t},editor:K}),!0},[k,V,K]),eh=(0,r.useCallback)(e=>{if(v?.(e),!(e.isDefaultPrevented()||e.isPropagationStopped()||!getEventPosition({editorActor:V,slateEditor:K,event:e.nativeEvent})))return V.send({type:"behavior event",behaviorEvent:{type:"drag.drag",originEvent:{dataTransfer:e.dataTransfer}},editor:K}),!0},[v,V,K]),ef=(0,r.useCallback)(e=>{if(b?.(e),!(e.isDefaultPrevented()||e.isPropagationStopped()))return V.send({type:"behavior event",behaviorEvent:{type:"drag.dragend",originEvent:{dataTransfer:e.dataTransfer}},editor:K}),!0},[b,V,K]),eg=(0,r.useCallback)(e=>{if(x?.(e),e.isDefaultPrevented()||e.isPropagationStopped())return;let t=getEventPosition({editorActor:V,slateEditor:K,event:e.nativeEvent});if(t)return V.send({type:"behavior event",behaviorEvent:{type:"drag.dragenter",originEvent:{dataTransfer:e.dataTransfer},position:t},editor:K}),!0},[x,V,K]),ey=(0,r.useCallback)(e=>{if(_?.(e),e.isDefaultPrevented()||e.isPropagationStopped())return;let t=getEventPosition({editorActor:V,slateEditor:K,event:e.nativeEvent});if(t)return V.send({type:"behavior event",behaviorEvent:{type:"drag.dragover",originEvent:{dataTransfer:e.dataTransfer}
7,dragOrigin:V.getSnapshot().context.internalDrag?.origin,position:t},editor:K,nativeEvent:e}),!0},[_,V,K]),em=(0,r.useCallback)(e=>{if(E?.(e),e.isDefaultPrevented()||e.isPropagationStopped())return;let t=getEventPosition({editorActor:V,slateEditor:K,event:e.nativeEvent});if(!t){console.warn("Could not find position for drop event");return}return V.send({type:"behavior event",behaviorEvent:{type:"drag.drop",originEvent:{dataTransfer:e.dataTransfer},dragOrigin:V.getSnapshot().context.internalDrag?.origin,position:t},editor:K,nativeEvent:e}),!0},[E,V,K]),ek=(0,r.useCallback)(e=>{if(S?.(e),!(e.isDefaultPrevented()||e.isPropagationStopped()||!getEventPosition({editorActor:V,slateEditor:K,event:e.nativeEvent})))return V.send({type:"behavior event",behaviorEvent:{type:"drag.dragleave",originEvent:{dataTransfer:e.dataTransfer}},editor:K}),!0},[S,V,K]);return j?$?null:(0,s.jsx)(u.CX,{...D,"data-read-only":F,autoFocus:!1,className:D.className||"pt-editable",decorate:q,onBlur:ea,onCopy:et,onCut:en,onClick:er,onDOMBeforeInput:el,onDragStart:eu,onDrag:eh,onDragEnd:ef,onDragEnter:eg,onDragOver:ey,onDrop:em,onDragLeave:ek,onFocus:ei,onKeyDown:ec,onKeyUp:ed,onPaste:eo,readOnly:F,renderPlaceholder:void 0,renderElement:J,renderLeaf:Z,renderText:Q,scrollSelectionIntoView:ep}):null});function EditorProvider(e){let t,n,o,a,c,d,p,h,f,g;let y=(0,i.c)(32);y[0]!==e.initialConfig?(t=()=>{let t=createInternalEditor(e.initialConfig),n=new PortableTextEditor({editor:t.editor});return{internalEditor:t,portableTextEditor:n}},y[0]=e.initialConfig,y[1]=t):t=y[1];let{internalEditor:m,portableTextEditor:k}=function(e){let t=r.useRef(null);return t.current||(t.current={constant:e()}),t.current.constant}(t);return y[2]!==m.actors.editorActor||y[3]!==m.actors.mutationActor||y[4]!==m.actors.relayActor||y[5]!==m.actors.syncActor||y[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();stopActor(m.actors.editorActor),stopActor(m.actors.mutationActor),stopActor(m.actors.relayActor),stopActor(m.actors.syncActor)}},y[2]=m.actors.editorActor,y[3]=m.actors.mutationActor,y[4]=m.actors.relayActor,y[5]=m.actors.syncActor,y[6]=m.subscriptions,y[7]=n):n=y[7],y[8]!==m?(o=[m],y[8]=m,y[9]=o):o=y[9],(0,r.useEffect)(n,o),y[10]!==k.change$?(a=e=>{k.change$.next(e)},y[10]=k.change$,y[11]=a):a=y[11],y[12]!==m.actors.relayActor||y[13]!==a?(c=(0,s.jsx)(RouteEventsToChanges,{relayActor:m.actors.relayActor,onChange:a}),y[12]=m.actors.relayActor,y[13]=a,y[14]=c):c=y[14],y[15]!==k||y[16]!==e.children?(d=(0,s.jsx)(Q.Provider,{value:k,children:e.children}),y[15]=k,y[16]=e.children,y[17]=d):d=y[17],y[18]!==m.editor._internal.slateEditor.initialValue||y[19]!==m.editor._internal.slateEditor.instance||y[20]!==d?(p=(0,s.jsx)(u.mH,{editor:m.editor._internal.slateEditor.instance,initialValue:m.editor._internal.slateEditor.initialValue,children:d}),y[18]=m.editor._internal.slateEditor.initialValue,y[19]=m.editor._internal.slateEditor.instance,y[20]=d,y[21]=p):p=y[21],y[22]!==m.actors.relayActor||y[23]!==p?(h=(0,s.jsx)(tN.Provider,{value:m.actors.relayActor,children:p}),y[22]=m.actors.relayActor,y[23]=p,y[24]=h):h=y[24],y[25]!==m.actors.editorActor||y[26]!==h?(f=(0,s.jsx)(X.Provider,{value:m.actors.editorActor,children:h}),y[25]=m.actors.editorActor,y[26]=h,y[27]=f):f=y[27],y[28]!==m.editor||y[29]!==c||y[30]!==f?(g=(0,s.jsxs)(l.r.Provider,{value:m.editor,children:[c,f]}),y[28]=m.editor,y[29]=c,y[30]=f,y[31]=g):g=y[31],g}tY.displayName="ForwardRef(PortableTextEditable)";let usePortableTextEditorSelection=()=>{let e,t;let n=(0,i.c)(3),o=(0,r.useContext)(X),[a,l]=(0,r.useState)(null);return n[0]!==o?(e=()=>{let e=o.on("selection",e=>{(0,r.startTransition)(()=>{l(e.selection)})});return()=>{e.unsubscribe()}},t=[o],n[0]=o,n[1]=e,n[2]=t):(e=n[1],t=n[2]),(0,r.useEffect)(e,t),a}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.