1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8559],{19381:function(e,t,n){n.d(t,{L9:function(){return usePortableTextEditorSelection},YH:function(){return defaultKeyGenerator},_F:function(){return usePortableTextEditor},iV:function(){return eW},q$:function(){return PortableTextEditor}});var r=n(85893),i=n(18446),l=n(50308),o=n(67294),a=n(77493),s=n(96391),c=n(11227),d=n(7071),h=n(42702),u=n(44908),f=n(82649),p=n(73190),g=n(64540),m=n(27361),y=n(52353),k=n(14176),b=n(85564),x=n(87196),v=n(13023),_=n(68630),E=n(23493),T=n(28058),S=n(23279);let N="sanity-pte:";function debugWithName(e){let t=`${N}${e}`;return c&&c.enabled(t)?c(t):c(N)}function createKeyedPath(e,t,n){let r;let i=[e.path[0]];if(!t)return null;let l=t[i[0]];if(!l)return null;let o=[{_key:l._key}];if(l._type!==n.block.name)return o;let a=e.path.slice(0,2),s=Array.isArray(l.children)&&l.children[a[1]];return s&&(r=["children",{_key:s._key}]),r?[...o,...r]:o}function createArrayedPath(e,t){if(!t)return[];let[n,r]=Array.from(a.Editor.nodes(t,{at:[],match:t=>(0,d.Fd)(e.path[0])&&t._key===e.path[0]._key}))[0]||[void 0,void 0];if(!n||!a.Element.isElement(n))return[];if(t.isVoid(n))return[r[0],0];let l=[e.path[2]],o=n.children.findIndex(e=>i([{_key:e._key}],l));if(o>=0&&n.children[o]){let e=n.children[o];return a.Element.isElement(e)&&t.isVoid(e)?r.concat(o).concat(0):r.concat(o)}return r}function toPortableTextRange(e,t,n){if(!t)return null;let r=null,i=null,l=t.anchor&&createKeyedPath(t.anchor,e,n);l&&t.anchor&&(r={path:l,offset:t.anchor.offset});let o=t.focus&&createKeyedPath(t.focus,e,n);o&&t.focus&&(i={path:o,offset:t.focus.offset});let s=!!(a.Range.isRange(t)&&a.Range.isBackward(t));return r&&i?{anchor:r,focus:i,backward:s}:null}function toSlateRange(e,t){if(!e||!t)return null;let n={path:createArrayedPath(e.anchor,t),offset:e.anchor.offset},r={path:createArrayedPath(e.focus,t),offset:e.focus.offset};return 0===r.path.length||0===n.path.length?null:n&&r?{anchor:n,focus:r}:null}function normalizePoint(e,t){if(!e||!t)return null;let n=[],r=e.offset||0,i="object"==typeof e.path[0]&&"_key"in e.path[0]&&e.path[0]._key,l="object"==typeof e.path[2]&&"_key"in e.path[2]&&e.path[2]._key,o=t.find(e=>e._key===i);if(!o)return null;if(n.push({_key:o._key}),o&&"children"===e.path[1]){if(!o.children||Array.isArray(o.children)&&0===o.children.length)return null;let t=Array.isArray(o.children)&&o.children.find(e=>e._key===l);if(!t)return null;n.push("children"),n.push({_key:t._key}),r=t.text&&t.text.length>=e.offset?e.offset:t.text&&t.text.length||0}return{path:n,offset:r}}c(N);let w=[],P="void-child";function keepObjectEquality(e,t){let n=t[e._key];return n&&i(e,n)?n:(t[e._key]=e,e)}function toSlateValue(e,{schemaTypes:t},n={}){return e&&Array.isArray(e)?e.map(e=>{let{_type:r,_key:i,...l}=e,o=[{_key:P,_type:"span",text:"",marks:[]}];if(e&&e._type===t.block.name){let s=!1,c=typeof e.style>"u",d=typeof e.markDefs>"u",h=typeof e.children>"u",u=(e.children||[]).map(e=>{let{_type:t,_key:r,...i}=e;return"span"!==t?(s=!0,keepObjectEquality({_type:t,_key:r,children:o,value:i,__inline:!0},n)):e});return!(!c&&!d&&!h&&!s&&a.Element.isElement(e))?(c&&(l.style=t.styles[0].value),keepObjectEquality({_type:r,_key:i,...l,children:u},n)):e}return keepObjectEquality({_type:r,_key:i,children:o,value:l},n)}):[]}function fromSlateValue(e,t,n={}){return e.map(e=>{let{_key:r,_type:i}=e;if(!r||!i)throw Error("Not a valid block");if(i===t&&"children"in e&&Array.isArray(e.children)&&r){let t=!1,l=e.children.map(e=>{let{_type:r}=e;if("value"in e&&"span"!==r){t=!0;let{value:r,_key:i,_type:l,__inline:o,children:a,...s}=e;return keepObjectEquality({...s,...r,_key:i,_type:l},n)}return e});return t?keepObjectEquality({...e,children:l,_key:r,_type:i},n):e}let l="value"in e&&e.value;return keepObjectEquality({_key:r,_type:i,..."object"==typeof l?l:{}},n)})}function isEqualToEmptyEditor(e,t){return void 0===e||e&&Array.isArray(e)&&0===e.length||e&&Array.isArray(e)&&1===e.length&&a.Element.isElement(e[0])&&e[0]._type===t.block.name&&"style"in e[0]&&e[0].style===t.styles[0].value&&!("listItem"in e[0])&&Array.isArray(e[0].children)&&1===e[0].children.length&&a.Text.
1isText(e[0].children[0])&&"span"===e[0].children[0]._type&&!e[0].children[0].marks?.join("")&&""===e[0].children[0].text}let C=new WeakMap,A=new WeakMap,D=new WeakMap,R=new WeakMap,B=new WeakMap,M=new WeakMap,$=new WeakMap,O=new WeakMap,j=new WeakMap,DefaultObject=e=>(0,r.jsx)("div",{children:(0,r.jsx)("pre",{children:JSON.stringify(e.value,null,2)})}),I=h.styled.div` 2 user-select: none; 3 border: ${e=>e.selected?"1px solid blue":"1px solid transparent"}; 4`;h.styled.span` 5 background: #999; 6 border: ${e=>e.selected?"1px solid blue":"1px solid transparent"}; 7`;let L=h.styled.div` 8 &.pt-list-item { 9 width: fit-content; 10 position: relative; 11 display: block; 12 13 /* Important 'transform' in order to force refresh the ::before and ::after rules 14 in Webkit: https://stackoverflow.com/a/21947628/831480 15 */ 16 transform: translateZ(0); 17 margin-left: ${e=>(function(e){switch(Number(e)){case 1:return"1.5em";case 2:return"3em";case 3:return"4.5em";case 4:return"6em";case 5:return"7.5em";case 6:return"9em";case 7:return"10.5em";case 8:return"12em";case 9:return"13.5em";case 10:return"15em";default:return"0em"}})(e.listLevel)}; 18 } 19 &.pt-list-item > .pt-list-item-inner { 20 display: flex; 21 margin: 0; 22 padding: 0; 23 &:before { 24 justify-content: flex-start; 25 vertical-align: top; 26 } 27 } 28 &.pt-list-item-bullet > .pt-list-item-inner:before { 29 content: '${e=>{var t;return t=e.listLevel,"bullet"===e.listStyle?z[(t-1)%3]:"*"}}'; 30 font-size: 0.4375rem; /* 7px */ 31 line-height: 1.5rem; /* Same as body text */ 32 /* Optical alignment */ 33 position: relative; 34 } 35 } 36 &.pt-list-item-bullet > .pt-list-item-inner { 37 &:before { 38 min-width: 1.5rem; /* Make sure space between bullet and text never shrinks */ 39 } 40 } 41 &.pt-list-item-number { 42 counter-increment: ${e=>(function(e){switch(e){case 1:return"listItemNumber";case 2:return"listItemAlpha";case 3:return"listItemRoman";case 4:return"listItemNumberNext";case 5:return"listItemLetterNext";case 6:return"listItemRomanNext";case 7:return"listItemNumberNextNext";case 8:return"listItemAlphaNextNext";case 9:return"listItemRomanNextNext";default:return"listItemNumberNextNextNext"}})(e.listLevel)}; 43 counter-reset: ${e=>(function(e){switch(e){case 1:return"listItemAlpha";case 2:return"listItemRoman";case 3:return"listItemNumberNext";case 4:return"listItemLetterNext";case 5:return"listItemRomanNext";case 6:return"listItemNumberNextNext";case 7:return"listItemAlphaNextNext";case 8:return"listItemRomanNextNext";default:return"listItemNumberNextNextNext"}})(e.listLevel)}; 44 } 45 & + :not(.pt-list-item-number) { 46 counter-reset: listItemNumber; 47 } 48 &.pt-list-item-number > .pt-list-item-inner:before { 49 content: ${e=>(function(e){switch(e){case 1:return"counter(listItemNumber) '. '";case 2:return"counter(listItemAlpha, lower-alpha) '. '";case 3:return"counter(listItemRoman, lower-roman) '. '";case 4:return"counter(listItemNumberNext) '. '";case 5:return"counter(listItemLetterNext, lower-alpha) '. '";case 6:return"counter(listItemRomanNext, lower-roman) '. '";case 7:return"counter(listItemNumberNextNext) '. '";case 8:return"counter(listItemAlphaNextNext, lower-alpha) '. '";case 9:return"counter(listItemRomanNextNext, lower-roman) '. '";default:return"counter(listItemNumberNextNextNext) '. '"}})(e.listLevel)}; 50 min-width: 1.5rem; /* Make sure space between number and text never shrinks */ 51 /* Optical alignment */ 52 position: relative; 53 top: 1px; 54 } 55`,V=h.styled.div``,z=["â","â","â "],W=debugWithName("components:DraggableBlock"),DraggableBlock=({children:e,element:t,readOnly:n,blockRef:i})=>{let l=(0,s.useSlateStatic)(),c=(0,o.useRef)(),[d,h]=(0,o.useState)(!1),u=(0,o.useMemo)(()=>a.Editor.isVoid(l,t),[l,t]),f=(0,o.useMemo)(()=>a.Editor.isInline(l,t),[l,t]),[p,g]=(0,o.useState)(null);(0,o.useEffect)(()=>g(i?i.current:s.ReactEditor.toDOMNode(l,t)),[l,t,i]);let m=(0,o.useCallback)(e=>{let n=R.get(l);if(!n||!p)return;e.preventDefault(),e.dataTransfer.dropEffect="move",B.set(l,t);let r=p.getBoundingClientRect(),i=r.top,o=r.height,a=e.pageY,s="bottom";if(t===l.children[0]?s="top":(s=Math.abs(i-a)<o/2?"top":"bottom",M.set(l,s)),n===t){e.dataTransfer.dropEffect="none";return}h(!0)},[p,l,t]),y=(0,o.useCallback)(()=>{h(!1)},[]),k=(0,o.useCallback)(e=>{let n=B.get(l);if(n){D.set(l,!1),e.preventDefault(),e.stopPropagation(),B.delete(l),c.current&&(W("Removing drag ghost"),document.body.removeChild(c.current));let r=M.get(l);M.delete(l);let i=s.ReactEditor.findPath(l,n),o=s.ReactEditor.findPath(l,t),d=a.Path.isBefore(o,i);if("bottom"===r&&!d){if(i[0]>=l.children.length-1){W("target is already at the bottom, not moving");return}let e=i;i=a.Path.next(i),W(`Adjusting targetPath from ${JSON.stringify(e)} to ${JSON.stringify(i)}`)}if("top"===r&&d&&i[0]!==l.children.length-1){let e=i;i=a.Path.previous(i),W(`Adjusting targetPath from ${JSON.stringify(e)} to ${JSON.stringify(i)}`)}if(a.Path.equals(i,o)){e.preventDefault(),W("targetPath and myPath is the same, not moving");return}W(`Moving element ${t._key} from path ${JSON.stringify(o)} to ${JSON.stringify(i)} (${r})`),a.Transforms.moveNodes(l,{at:o,to:i}),l.onChange();return}W("No target element, not doing anything")},[l,t]),b=(0,o.useCallback)(e=>{R.get(l)&&(W("On drop (prevented)",t),e.preventDefault(),e.stopPropagation(),h(!1))},[l,t]),x=(0,o.useCallback)(e=>{if(!u){R.delete(l);return}D.set(l,!0),R.set(l,t),e.stopPropagation();let n=e.target;n instanceof HTMLElement&&(n.style.opacity="1")},[l,t,u]),v=(0,o.useCallback)(e=>{if(!u||f){W("Not dragging block"),R.delete(l),D.set(l,!1);return}if(W("Drag start"),D.set(l,!0),e.dataTransfer&&(e.dataTransfer.setData("application/portable-text","something"),e.dataTransfer.effectAllowed="move"),p&&p instanceof HTMLElement){let t=p.cloneNode(!0),n=t.querySelector("[data-pt-drag-ghost-element]");if(n&&(t=n),t.setAttribute("data-dragged",""),document.body){c.current=t,t.style.position="absolute",t.style.left="-99999px",t.style.boxSizing="border-box",document.body.appendChild(t);let n=p.getBoundingClientRect(),r=e.clientX-n.left,i=e.clientY-n.top;t.style.width=`${n.width}px`,t.style.height=`${n.height}px`,e.dataTransfer.setDragImage(t,r,i)}}x(e)},[p,l,x,f,u]),_=d&&l.children[0]===B.get(l),E=d&&l.children[l.children.length-1]===B.get(l),T=M.get(l),S=(0,o.useMemo)(()=>(0,r.jsx)("div",{className:"pt-drop-indicator",style:{position:"absolute",width:"100%",height:1,borderBottom:"1px solid currentColor",zIndex:5}}),[]);return n?(0,r.jsx)(r.Fragment,{children:e}):(0,r.jsxs)("div",{draggable:u,onDragStart:v,onDrag:x,onDragOver:m,onDragLeave:y,onDragEnd:k,onDrop:b,children:[(_||d&&!_&&!E&&"top"===T)&&S,e,(E||d&&!_&&!E&&"bottom"===T)&&S]})};debugWithName("components:Element");let q=[],U={display:"inline-block"},Element=({attributes:e,children:t,element:n,schemaTypes:i,readOnly:l,renderBlock:c,renderChild:d,renderListItem:h,renderStyle:u,spellCheck:f})=>{let p;
55let g=(0,s.useSlateStatic)(),m=(0,s.useSelected)(),y=(0,o.useRef)(null),k=(0,o.useRef)(null),b=m&&g.selection&&a.Range.isCollapsed(g.selection)||!1,x=(0,o.useMemo)(()=>fromSlateValue([n],i.block.name,O.get(g))[0],[g,n,i.block.name]),v=t,_,E=(0,o.useMemo)(()=>[{_key:n._key}],[n]);if("string"!=typeof n._type)throw Error("Expected element to have a _type property");if("string"!=typeof n._key)throw Error("Expected element to have a _key property");if(g.isInline(n)){let o=s.ReactEditor.findPath(g,n),[c]=a.Editor.node(g,o,{depth:1}),h=i.inlineObjects.find(e=>e.name===n._type);if(!h)throw Error("Could not find type for inline block element");if(a.Element.isElement(c)){let i=[{_key:c._key},"children",{_key:n._key}];return(0,r.jsxs)("span",{...e,children:[t,(0,r.jsxs)("span",{draggable:!l,className:"pt-inline-object","data-testid":"pt-inline-object",ref:k,style:U,contentEditable:!1,children:[d&&d({annotations:q,children:(0,r.jsx)(DefaultObject,{value:x}),editorElementRef:k,focused:b,path:i,schemaType:h,selected:m,type:h,value:x}),!d&&(0,r.jsx)(DefaultObject,{value:x})]},n._key)]})}throw Error("Block not found!")}if(n._type===i.block.name){let o;_="pt-block pt-text-block";let a="listItem"in n,s="style"in n&&n.style||"normal";_=`pt-block pt-text-block pt-text-block-style-${s}`;let d=i.styles.find(e=>e.value===s);if(u&&d&&(v=u({block:n,children:t,focused:b,selected:m,value:s,path:E,schemaType:d,editorElementRef:y})),a&&("number"==typeof n.level&&(o=n.level),_+=` pt-list-item pt-list-item-${n.listItem} pt-list-item-level-${o||1}`),g.isListBlock(x)&&a&&n.listItem){let e=i.lists.find(e=>e.value===n.listItem);v=h&&e?h({block:x,children:v,focused:b,selected:m,value:n.listItem,path:E,schemaType:e,level:x.level||1,editorElementRef:y}):(0,r.jsx)(L,{listStyle:x.listItem||i.lists[0].value,listLevel:x.level||1,children:(0,r.jsx)(V,{children:v})})}let p=Object.defineProperty({children:v,editorElementRef:y,focused:b,level:o,listItem:a?n.listItem:void 0,path:E,selected:m,style:s,schemaType:i.block,value:x},"type",{enumerable:!1,get:()=>(console.warn("Property 'type' is deprecated, use 'schemaType' instead."),i.block)}),k=c?c(p):t;return(0,r.jsx)("div",{...e,className:_,spellCheck:f,children:(0,r.jsx)(DraggableBlock,{element:n,readOnly:l,blockRef:y,children:(0,r.jsx)("div",{ref:y,children:k})})},n._key)}let T=i.blockObjects.find(e=>e.name===n._type);if(!T)throw Error(`Could not find schema type for block element of _type ${n._type}`);_="pt-block pt-object-block";let S=fromSlateValue([n],i.block.name,O.get(g))[0];if(c){let e=Object.defineProperty({children:(0,r.jsx)(DefaultObject,{value:x}),editorElementRef:y,focused:b,path:E,schemaType:T,selected:m,value:S},"type",{enumerable:!1,get:()=>(console.warn("Property 'type' is deprecated, use 'schemaType' instead."),T)});p=c(e)}return(0,r.jsxs)("div",{...e,className:_,children:[t,(0,r.jsxs)(DraggableBlock,{element:n,readOnly:l,blockRef:y,children:[p&&(0,r.jsx)("div",{ref:y,contentEditable:!1,children:p}),!p&&(0,r.jsx)(I,{selected:m,children:(0,r.jsx)(DefaultObject,{value:x})})]})]},n._key)},F=(0,o.createContext)(null),usePortableTextEditor=()=>{let e=(0,o.useContext)(F);if(!e)throw Error("The `usePortableTextEditor` hook must be used inside the <PortableTextEditor> component's context.");return e};function DefaultAnnotation(e){let t=(0,o.useCallback)(()=>alert(JSON.stringify(e.annotation)),[e.annotation]);return(0,r.jsx)("span",{style:{color:"blue"},onClick:t,children:e.children})}function getPortableTextMemberSchemaTypes(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 r=n.type.of;if(!r)throw Error("Valid types for block children not found in schema (required)");let i=r.find(e=>"span"===e.name);if(!i)throw Error("Span type not found in schema (required)");let l=r.filter(e=>"span"!==e.name)||[],o=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);
55if(!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:l,blockObjects:o,annotations:i.annotations}}function compileType(e){return p.V.compile({name:"blockTypeSchema",types:[e]}).get(e.name)}let J=debugWithName("operationToPatches"),H=debugWithName("API:editable");function withRemoteChanges(e,t){let n=isChangingRemotely(e)||!1;C.set(e,!0),t(),C.set(e,n)}function isChangingRemotely(e){return C.get(e)}let K=new WeakMap,G=new WeakMap;function isUndoing(e){return K.get(e)??!1}function isRedoing(e){return G.get(e)??!1}function cloneDiff(e){let[t,n]=e;return[t,n]}function getCommonOverlap(e,t){let n=e,r=t,i=n.length,l=r.length;if(0===i||0===l)return 0;i>l?n=n.substring(i-l):i<l&&(r=r.substring(0,i));let o=Math.min(i,l);if(n===r)return o;let a=0,s=1;for(let e=0;-1!==e;){let t=n.substring(o-s);if(-1===(e=r.indexOf(t)))break;s+=e,(0===e||n.substring(o-s)===r.substring(0,s))&&(a=s,s++)}return a}function getCommonPrefix(e,t){if(!e||!t||e[0]!==t[0])return 0;let n=0,r=Math.min(e.length,t.length),i=r,l=0;for(;n<i;)e.substring(l,i)===t.substring(l,i)?l=n=i:r=i,i=Math.floor((r-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,r=Math.min(e.length,t.length),i=r,l=0;for(;n<i;)e.substring(e.length-i,e.length-l)===t.substring(t.length-i,t.length-l)?l=n=i:r=i,i=Math.floor((r-n)/2+n);return i}let X=/[^a-zA-Z0-9]/,Y=/\s/,Z=/[\r\n]/,Q=/\n\r?\n$/,ee=/^\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),r=t.charAt(0),i=n.match(X),l=r.match(X),o=i&&n.match(Y),a=l&&r.match(Y),s=o&&n.match(Z),c=a&&r.match(Z),d=s&&e.match(Q),h=c&&t.match(ee);return d||h?5:s||c?4:i&&!o&&a?3:o||a?2:i||l?1:0}let n=1;for(;n<t.length-1;){if(t[n-1][0]===er&&t[n+1][0]===er){let e=t[n-1][1],r=t[n][1],i=t[n+1][1],l=getCommonSuffix(e,r);if(l){let t=r.substring(r.length-l);e=e.substring(0,e.length-l),r=t+r.substring(0,r.length-l),i=t+i}let o=e,a=r,s=i,c=diffCleanupSemanticScore(e,r)+diffCleanupSemanticScore(r,i);for(;r.charAt(0)===i.charAt(0);){e+=r.charAt(0),r=r.substring(1)+i.charAt(0),i=i.substring(1);let t=diffCleanupSemanticScore(e,r)+diffCleanupSemanticScore(r,i);t>=c&&(c=t,o=e,a=r,s=i)}t[n-1][1]!==o&&(o?t[n-1][1]=o:(t.splice(n-1,1),n--),t[n][1]=a,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([er,""]);let n=0,r=0,i=0,l="",o="",a;for(;n<t.length;)switch(t[n][0]){case en:i++,o+=t[n][1],n++;break;case et:r++,l+=t[n][1],n++;break;case er:r+i>1?(0!==r&&0!==i&&(0!==(a=getCommonPrefix(o,l))&&(n-r-i>0&&t[n-r-i-1][0]===er?t[n-r-i-1][1]+=o.substring(0,a):(t.splice(0,0,[er,o.substring(0,a)]),n++),o=o.substring(a),l=l.substring(a)),0!==(a=getCommonSuffix(o,l))&&(t[n][1]=o.substring(o.length-a)+t[n][1],o=o.substring(0,o.length-a),l=l.substring(0,l.length-a))),n-=r+i,t.splice(n,r+i),l.length&&(t.splice(n,0,[et,l]),n++),o.length&&(t.splice(n,0,[en,o]),n++),n++):0!==n&&t[n-1][0]===er?(t[n-1][1]+=t[n][1],t.splice(n,1)):n++,i=0,r=0,l="",o="";break;default:throw Error("Unknown diff operation")}""===t[t.length-1][1]&&t.pop();let s=!1;for(n=1;n<t.length-1;)t[n-1][0]===er&&t[n+1][0]===er&&(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}function bisectSplit(e,t,n,r,i){let l=e.substring(0,n),o=t.substring(0,r),a=e.substring(n),s=t.substring(r),c=doDiff(l,o,{checkLines:!1,deadline:i}),d=doDiff(a,s,{checkLines:!1,deadline:i});return c.concat(d)}function halfMatchI(e,t,n){let r=e.slice(n,n+Math.floor(e.length/4)),i=-1,l="",o,a,s,c;for(;-1!==(i=t.indexOf(r,i+1));){let r=getCommonPrefix(e.slice(n),t.slice(i)),d=getCommonSuffix(e.slice(0,n),t.slice(0,i));l.length<d+r&&(l=t.slice(i-d,i)+t.slice(i,i+r),o=e.slice(0,n-d),a=e.slice(n+r),s=t.slice(0,i-d),c=t.slice(i+r))}return 2*l.length>=e.length?[o||"",a||"",s||"",c||"",l||""]:null}let et=-1,en=1,er=0;function diff(e,t,n){var r,i;let l;if(null===e||null===t)throw Error("Null input. (diff)");let o=doDiff(e,t,{checkLines:!0,deadline:(i=(r=n||{}).timeout||1,l=1,"u">typeof i&&(l=i<=0?Number.MAX_VALUE:i),Date.now()+1e3*l),...r});return function(e){for(let t=0;t<e.length;t++){let[n,r]=e[t];if(0===r.length)continue;let i=r[0],l=r[r.length-1];(function(e){let t=e.charCodeAt(0);return t>=55296&&t<=56319})(l)&&n===er&&deisolateChar(e,t,1),function(e){let t=e.charCodeAt(0);return t>=56320&&t<=57343}(i)&&n===er&&deisolateChar(e,t,-1)}for(let t=0;t<e.length;t++)0===e[t][1].length&&e.splice(t,1)}(o),o}function doDiff(e,t,n){let r=e,i=t;if(r===i)return r?[[er,r]]:[];let l=getCommonPrefix(r,i),o=r.substring(0,l);l=getCommonSuffix(r=r.substring(l),i=i.substring(l));let a=r.substring(r.length-l),s=function(e,t,n){let r;if(!e)return[[en,t]];if(!t)return[[et,e]];let i=e.length>t.length?e:t,l=e.length>t.length?t:e,o=i.indexOf(l);if(-1!==o)return r=[[en,i.substring(0,o)],[er,l],[en,i.substring(o+l.length)]],e.length>t.length&&(r[0][0]=et,r[2][0]=et),r;if(1===l.length)return[[et,e],[en,t]];let a=function(e,t){let n,r,i,l,o;if((arguments.length>2&&void 0!==arguments[2]?arguments[2]:1)<=0)return null;let a=e.length>t.length?e:t,s=e.length>t.length?t:e;if(a.length<4||2*s.length<a.length)return null;
55let c=halfMatchI(a,s,Math.ceil(a.length/4)),d=halfMatchI(a,s,Math.ceil(a.length/2));if(c&&d)n=c[4].length>d[4].length?c:d;else{if(!c&&!d)return null;d?c||(n=d):n=c}if(!n)throw Error("Unable to find a half match.");e.length>t.length?(r=n[0],i=n[1],l=n[2],o=n[3]):(l=n[0],o=n[1],r=n[2],i=n[3]);let h=n[4];return[r,i,l,o,h]}(e,t);if(a){let e=a[0],t=a[1],r=a[2],i=a[3],l=a[4],o=doDiff(e,r,n),s=doDiff(t,i,n);return o.concat([[er,l]],s)}return n.checkLines&&e.length>100&&t.length>100?function(e,t,n){let r=e,i=t,l=function(e,t){let n=[],r={};function diffLinesToMunge(e){let t="",l=0,o=-1,a=n.length;for(;o<e.length-1;){-1===(o=e.indexOf(` 56`,l))&&(o=e.length-1);let s=e.slice(l,o+1);(r.hasOwnProperty?r.hasOwnProperty(s):void 0!==r[s])?t+=String.fromCharCode(r[s]):(a===i&&(s=e.slice(l),o=e.length),t+=String.fromCharCode(a),r[s]=a,n[a++]=s),l=o+1}return t}n[0]="";let i=4e4,l=diffLinesToMunge(e);i=65535;let o=diffLinesToMunge(t);return{chars1:l,chars2:o,lineArray:n}}(r,i);r=l.chars1,i=l.chars2;let o=l.lineArray,a=doDiff(r,i,{checkLines:!1,deadline:n.deadline});(function(e,t){for(let n=0;n<e.length;n++){let r=e[n][1],i=[];for(let e=0;e<r.length;e++)i[e]=t[r.charCodeAt(e)];e[n][1]=i.join("")}})(a,o),(a=function(e){let t=e.map(e=>cloneDiff(e)),n=!1,r=[],i=0,l=null,o=0,a=0,s=0,c=0,d=0;for(;o<t.length;)t[o][0]===er?(r[i++]=o,a=c,s=d,c=0,d=0,l=t[o][1]):(t[o][0]===en?c+=t[o][1].length:d+=t[o][1].length,l&&l.length<=Math.max(a,s)&&l.length<=Math.max(c,d)&&(t.splice(r[i-1],0,[et,l]),t[r[i-1]+1][0]=en,i--,o=--i>0?r[i-1]:-1,a=0,s=0,c=0,d=0,l=null,n=!0)),o++;for(n&&(t=cleanupMerge(t)),t=cleanupSemanticLossless(t),o=1;o<t.length;){if(t[o-1][0]===et&&t[o][0]===en){let e=t[o-1][1],n=t[o][1],r=getCommonOverlap(e,n),i=getCommonOverlap(n,e);r>=i?(r>=e.length/2||r>=n.length/2)&&(t.splice(o,0,[er,n.substring(0,r)]),t[o-1][1]=e.substring(0,e.length-r),t[o+1][1]=n.substring(r),o++):(i>=e.length/2||i>=n.length/2)&&(t.splice(o,0,[er,e.substring(0,i)]),t[o-1][0]=en,t[o-1][1]=n.substring(0,n.length-i),t[o+1][0]=et,t[o+1][1]=e.substring(i),o++),o++}o++}return t}(a)).push([er,""]);let s=0,c=0,d=0,h="",u="";for(;s<a.length;){switch(a[s][0]){case en:d++,u+=a[s][1];break;case et:c++,h+=a[s][1];break;case er:if(c>=1&&d>=1){a.splice(s-c-d,c+d),s=s-c-d;let e=doDiff(h,u,{checkLines:!1,deadline:n.deadline});for(let t=e.length-1;t>=0;t--)a.splice(s,0,e[t]);s+=e.length}d=0,c=0,h="",u="";break;default:throw Error("Unknown diff operation.")}s++}return a.pop(),a}(e,t,n):function(e,t,n){let r=e.length,i=t.length,l=Math.ceil((r+i)/2),o=2*l,a=Array(o),s=Array(o);for(let e=0;e<o;e++)a[e]=-1,s[e]=-1;a[l+1]=0,s[l+1]=0;let c=r-i,d=c%2!=0,h=0,u=0,f=0,p=0;for(let g=0;g<l&&!(Date.now()>n);g++){for(let f=-g+h;f<=g-u;f+=2){let p;let m=l+f,y=(p=f===-g||f!==g&&a[m-1]<a[m+1]?a[m+1]:a[m-1]+1)-f;for(;p<r&&y<i&&e.charAt(p)===t.charAt(y);)p++,y++;if(a[m]=p,p>r)u+=2;else if(y>i)h+=2;else if(d){let i=l+c-f;if(i>=0&&i<o&&-1!==s[i]){let l=r-s[i];if(p>=l)return bisectSplit(e,t,p,y,n)}}}for(let h=-g+f;h<=g-p;h+=2){let u;let m=l+h,y=(u=h===-g||h!==g&&s[m-1]<s[m+1]?s[m+1]:s[m-1]+1)-h;for(;u<r&&y<i&&e.charAt(r-u-1)===t.charAt(i-y-1);)u++,y++;if(s[m]=u,u>r)p+=2;else if(y>i)f+=2;else if(!d){let i=l+c-h;if(i>=0&&i<o&&-1!==a[i]){let o=a[i],s=l+o-i;if(o>=(u=r-u))return bisectSplit(e,t,o,s,n)}}}}return[[et,e],[en,t]]}(e,t,n.deadline)}(r=r.substring(0,r.length-l),i=i.substring(0,i.length-l),n);return o&&s.unshift([er,o]),a&&s.push([er,a]),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 r,i;let l=1===n?-1:1,o=null,a=null,s=t+n;for(;s>=0&&s<e.length&&(null===o||null===a);s+=n){let[r,i]=e[s];if(0!==i.length){if(r===en){null===o&&(o=s);continue}if(r===et){null===a&&(a=s);continue}if(r===er){if(null===o&&null===a){let[r,i]=splitChar(e[t][1],n);e[t][1]=r,e[s][1]=combineChar(e[s][1],i,l);return}break}}}if(null!==o&&null!==a&&(r=o,i=a,1===n?e[r][1][e[r][1].length-1]===e[i][1][e[i][1].length-1]:e[r][1][0]===e[i][1][0])){let[r,i]=splitChar(e[o][1],l),[s]=splitChar(e[a][1],l);e[o][1]=r,e[a][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===o?(e.splice(s,0,[en,d]),null!==a&&a>=s&&a++):e[o][1]=combineChar(e[o][1],d,l),null===a?e.splice(s,0,[et,d
56]):e[a][1]=combineChar(e[a][1],d,l)}let ei={threshold:.5,distance:1e3};function match(e,t,n){if(null===e||null===t||null===n)throw Error("Null input. (match())");let r=Math.max(0,Math.min(n,e.length));return e===t?0:e.length?e.substring(r,r+t.length)===t?r:function(e,t,n){let r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if(t.length>32)throw Error("Pattern too long for this browser.");let i={...ei,...r},l=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,r){let l=e/t.length,o=Math.abs(n-r);return i.distance?l+o/i.distance:o?1:l}let o=i.threshold,a=e.indexOf(t,n);-1!==a&&(o=Math.min(getBitapScore(0,a),o),-1!==(a=e.lastIndexOf(t,n+t.length))&&(o=Math.min(getBitapScore(0,a),o)));let s=1<<t.length-1;a=-1;let c,d,h=t.length+e.length,u=[];for(let r=0;r<t.length;r++){for(c=0,d=h;c<d;)getBitapScore(r,n+d)<=o?c=d:h=d,d=Math.floor((h-c)/2+c);h=d;let i=Math.max(1,n-d+1),f=Math.min(n+d,e.length)+t.length,p=Array(f+2);p[f+1]=(1<<r)-1;for(let t=f;t>=i;t--){let c=l[e.charAt(t-1)];if(0===r?p[t]=(p[t+1]<<1|1)&c:p[t]=(p[t+1]<<1|1)&c|((u[t+1]|u[t])<<1|1)|u[t+1],p[t]&s){let e=getBitapScore(r,t-1);if(e<=o){if(o=e,(a=t-1)>n)i=Math.max(1,2*n-a);else break}}}if(getBitapScore(r+1,n)>o)break;u=p}return a}(e,t,r):-1}function createPatchObject(e,t){return{diffs:[],start1:e,start2:t,utf8Start1:e,utf8Start2:t,length1:0,length2:0,utf8Length1:0,utf8Length2:0}}function diffText1(e){let t=[];for(let n=0;n<e.length;n++)e[n][0]!==en&&(t[n]=e[n][1]);return t.join("")}function diffText2(e){let t=[];for(let n=0;n<e.length;n++)e[n][0]!==et&&(t[n]=e[n][1]);return t.join("")}function countUtf8Bytes(e){let t=0;for(let n=0;n<e.length;n++){let r=e.codePointAt(n);if(typeof r>"u")throw Error("Failed to get codepoint");t+=utf8len(r)}return t}function utf8len(e){return e<=127?1:e<=2047?2:e<=65535?3:4}function xIndex(e,t){let n=0,r=0,i=0,l=0,o;for(o=0;o<e.length&&(e[o][0]!==en&&(n+=e[o][1].length),e[o][0]!==et&&(r+=e[o][1].length),!(n>t));o++)i=n,l=r;return e.length!==o&&e[o][0]===et?l:l+(t-i)}let el=/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@$/;function parse(e){if(!e)return[];let t=[],n=e.split(` 57`),r=0;for(;r<n.length;){let e=n[r].match(el);if(!e)throw Error("Invalid patch string: ".concat(n[r]));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),r++;r<n.length;){let e;let t=n[r],l=t.charAt(0);if("@"===l)break;if(""===l){r++;continue}try{e=decodeURI(t.slice(1))}catch{throw Error("Illegal escape in parse: ".concat(t))}let o=countUtf8Bytes(e)-e.length;if("-"===l)i.diffs.push([et,e]),i.length1-=o;else if("+"===l)i.diffs.push([en,e]),i.length2-=o;else if(" "===l)i.diffs.push([er,e]),i.length1-=o,i.length2-=o;else throw Error('Invalid patch mode "'.concat(l,'" in: ').concat(e));r++}}return t}function toInt(e){return parseInt(e,10)}let eo=debugWithName("applyPatches"),ea=eo.enabled&&!0;function isKeyedSegment(e){return"object"==typeof e&&"_key"in e}function debugState(e,t){ea&&(eo(`Children ${t}:`,JSON.stringify(e.children,null,2)),eo(`Selection ${t}: `,JSON.stringify(e.selection,null,2)))}function findBlockAndChildFromPath(e,t){let{block:n,path:r}=function(e,t){let n=-1,r=e.children.find((e,r)=>{let i=isKeyedSegment(t[0])?e._key===t[0]._key:r===t[0];return i&&(n=r),i});return r?{block:r,path:[n]}:{}}(e,t);if(!(a.Element.isElement(n)&&"children"===t[1]))return{block:n,blockPath:r,child:void 0,childPath:void 0};let i=-1,l=n.children.find((e,n)=>{let r=isKeyedSegment(t[2])?e._key===t[2]._key:n===t[2];return r&&(i=n),r});return l?{block:n,child:l,blockPath:r,childPath:r?.concat(i)}:{block:n,blockPath:r,child:void 0,childPath:void 0}}let es=new WeakMap;function withoutPatching(e,t){let n=es.get(e);es.set(e,!1),t(),es.set(e,n)}let ec=debugWithName("plugin:withUndoRedo"),ed=ec.enabled&&!1,eh=new WeakMap,eu=new WeakMap,isSaving=e=>{let t=eh.get(e);return void 0===t||t},getRemotePatches=e=>(eu.get(e)||eu.set(e,[]),eu.get(e)||[]);function transformOperation(e,t,n,r,l){ed&&(ec(`Adjusting '${n.type}' operation paths for '${t.type}' patch`),ec(`Operation ${JSON.stringify(n)}`),ec(`Patch ${JSON.stringify(t)}`));let o={...n};if("insert"===t.type&&1===t.path.length){let e=(r||[]).findIndex(e=>i({_key:e._key},t.path[0]));return ec(`Adjusting block path (+${t.items.length}) for '${o.type}' operation and patch '${t.type}'`),[adjustBlockPath(o,t.items.length,e)]}if("unset"===t.type&&1===t.path.length){let n=(l||[]).findIndex(e=>i({_key:e._key},t.path[0]));return"path"in o&&Array.isArray(o.path)&&o.path[0]===n?(ec("Skipping transformation that targeted removed block"),[]):(ed&&(ec(`Selection ${JSON.stringify(e.selection)}`),ec(`Adjusting block path (-1) for '${o.type}' operation and patch '${t.type}'`)),[adjustBlockPath(o,-1,n)])}if("unset"===t.type&&0===t.path.length)return ec(`Adjusting selection for unset everything patch and ${n.type} operation`),[];
57if("diffMatchPatch"===t.type){let n;let r=("set_selection"===o.type&&e.selection?n=e.children[e.selection.focus.path[0]]:"path"in o&&(n=e.children[o.path[0]]),n);return r&&i({_key:r._key},t.path[0])&&parse(t.value).forEach(e=>{let t=0,n=e.utf8Start1,{diffs:r}=e;if(r.forEach((e,i)=>{let[l,o]=e;l===en?(t+=o.length,n+=o.length):l===et?(t-=o.length,n-=o.length):l===er&&(r.slice(i).every(([e])=>e===er)||(n+=o.length))}),"insert_text"===o.type&&n<o.offset&&(o.offset+=t),"remove_text"===o.type&&n<=o.offset-o.text.length&&(o.offset+=t),"set_selection"===o.type){let e=o.properties?.focus?{...o.properties.focus}:void 0,r=o?.properties?.anchor?{...o.properties.anchor}:void 0,i=o?.newProperties?.focus?{...o.newProperties.focus}:void 0,l=o?.newProperties?.anchor?{...o.newProperties.anchor}:void 0;(e&&r||i&&l)&&([e,r,i,l].forEach(e=>{e&&n<e.offset&&(e.offset+=t)}),e&&r&&(o.properties={focus:e,anchor:r}),i&&l&&(o.newProperties={focus:i,anchor:l}))}}),[o]}return[o]}function adjustBlockPath(e,t,n){let r={...e};if(n>=0&&"set_selection"!==r.type&&Array.isArray(r.path)&&r.path[0]>=n+t&&r.path[0]+t>-1){let e=[r.path[0]+t,...r.path.slice(1)];r.path=e}if("set_selection"===r.type){let e=r.properties?.focus?{...r.properties.focus}:void 0,i=r?.properties?.anchor?{...r.properties.anchor}:void 0,l=r?.newProperties?.focus?{...r.newProperties.focus}:void 0,o=r?.newProperties?.anchor?{...r.newProperties.anchor}:void 0;(e&&i||l&&o)&&([e,i,l,o].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&&(r.properties={focus:e,anchor:i}),l&&o&&(r.newProperties={focus:l,anchor:o}))}return r}let shouldMerge=(e,t)=>!!("set_selection"===e.type||t&&"insert_text"===e.type&&"insert_text"===t.type&&e.offset===t.offset+t.text.length&&a.Path.equals(e.path,t.path)&&" "!==e.text||t&&"remove_text"===e.type&&"remove_text"===t.type&&e.offset+e.text.length===t.offset&&a.Path.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);eh.set(e,!1),t(),eh.set(e,n)}let ef=debugWithName("plugin:withPatches"),ep=debugWithName("plugin:withPlaceholderBlock"),eg=debugWithName("plugin:withPortableTextBlockStyle"),em=debugWithName("plugin:withPortableTextLists"),ey=debugWithName("plugin:withPortableTextMarkModel"),ek=debugWithName("plugin:withPortableTextSelections"),eb=ek.enabled&&!1,ex=debugWithName("plugin:withSchemaTypes"),ev=debugWithName("plugin:withUtils"),e_=debugWithName("plugin:withHotKeys"),eE={marks:{"mod+b":"strong","mod+i":"em","mod+u":"underline","mod+'":"code"},custom:{}};function validateValue(e,t,n){let r=null,i=!0,l=[t.span.name,...t.inlineObjects.map(e=>e.name)],o=[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,a)=>{if(!_(e))return r={patches:[(0,g.zN)([a])],description:`Block must be an object, got ${String(e)}`,action:"Unset invalid item",item:e,i18n:{description:"inputs.portable-text.invalid-value.not-an-object.description",action:"inputs.portable-text.invalid-value.not-an-object.action",values:{index:a}}},!0;if(!e._key||"string"!=typeof e._key)return r={patches:[(0,g.t8)({...e,_key:n()},[a])],description:`Block at index ${a} 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:a}}},!0;if(!e._type||!o.includes(e._type)){if("block"===e._type){let n=t.block.name;return r={patches:[(0,g.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 r=!e._type&&(0,d.DG)({...e,_type:t.block.name})?{patches:[(0,g.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}
57'`,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,g.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,g.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 r={patches:[(0,g.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 r={autoResolve:!0,patches:[(0,g.Cb)([],[{_key:e._key},"children"]),(0,g.$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}if(e.markDefs&&!Array.isArray(e.markDefs))return r={patches:[(0,g.t8)({...e,markDefs:w},[{_key:e._key}])],description:"Block has invalid required property 'markDefs'.",action:"Add empty markDefs array",item:e,i18n:{description:"inputs.portable-text.invalid-value.missing-or-invalid-markdefs.description",action:"inputs.portable-text.invalid-value.missing-or-invalid-markdefs.action",values:{key:e._key}}},!0;let o=u(b(e.children.filter(e=>e._type===t.span.name).map(e=>e.marks||[])));if(Array.isArray(e.markDefs)&&e.markDefs.length>0){let t=u(e.markDefs.map(e=>e._key).filter(e=>!o.includes(e)));if(t.length>0)return r={autoResolve:!0,patches:t.map(t=>(0,g.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 a=o.filter(e=>!t.decorators.map(e=>e.value).includes(e)).filter(t=>void 0===e.markDefs||!e.markDefs.find(e=>e._key===t));if(a.length>0){let n=e.children.filter(e=>e._type===t.span.name&&Array.isArray(e.marks)&&e.marks.some(e=>a.includes(e)));if(n){let t=a.join(", ");return r={autoResolve:!0,patches:n.map(t=>(0,g.t8)((t.marks||[]).filter(e=>!a.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:a.map(e=>e.toString())}}},!0}}e.children.some((i,o)=>{if(!_(i))return r={patches:[(0,g.zN)([{_key:e._key},"children",o])],description:`Child at index '${o}' 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:o}}},!0;if(!i._key||"string"!=typeof i._key){let t={...i,_key:n()};return r={autoResolve:!0,patches:[(0,g.t8)(t,[{_key:e._key},"children",o])],description:`Child at index ${o} 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.invali
57d-value.missing-child-key.description",action:"inputs.portable-text.invalid-value.missing-child-key.action",values:{key:e._key,index:o}}},!0}return i._type?l.includes(i._type)?i._type===t.span.name&&"string"!=typeof i.text&&(r={patches:[(0,g.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.invalid-span-text.description",action:"inputs.portable-text.invalid-value.invalid-span-text.action",values:{key:e._key,childKey:i._key}}},!0):(r={patches:[(0,g.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):(r={patches:[(0,g.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:r,value:e}):{valid:!1,resolution:{patches:[(0,g.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 eT=debugWithName("plugin:withInsertData"),eS={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};function _insertFragment(e,t,n){e.withoutNormalizing(()=>{if(!e.selection)return;let[r,l]=a.Editor.node(e,e.selection,{depth:1});if(e.isTextBlock(r)&&e.isTextBlock(t[0])){let{markDefs:n}=r;eT("Mixing markDefs of focusBlock and fragments[0] block",n,t[0].markDefs),i(n,t[0].markDefs)||a.Transforms.setNodes(e,{markDefs:u([...t[0].markDefs||[],...n||[]])},{at:l,mode:"lowest",voids:!1})}isEqualToEmptyEditor(e.children,n)?(a.Transforms.splitNodes(e,{at:[0,0]}),e.insertFragment(t),a.Transforms.removeNodes(e,{at:[0]})):e.insertFragment(t)}),e.onChange()}let eN=new WeakMap,withPlugins=(e,t)=>{var n;let r;let{keyGenerator:o,portableTextEditor:c,patches$:h,readOnly:f,maxBlocks:p}=t,{schemaTypes:x,change$:v}=c;e.subscriptions=[],e.destroy?e.destroy():eN.set(e,{apply:e.apply,onChange:e.onChange,normalizeNode:e.normalizeNode});let _=function(e){let t=e.block.name;return{insertNodePatch:function(e,n,r){let i=r[n.path[0]],l=e.isTextBlock(i);if(1===n.path.length){let e=0===n.path[0]?"before":"after",l=r[n.path[0]-1],o=0===n.path[0]?i?._key:l?._key;return o?[(0,g.$T)([fromSlateValue([n.node],t)[0]],e,[{_key:o}])]:[(0,g.Cb)(r,[]),(0,g.$T)([fromSlateValue([n.node],t)[0]],"before",[n.path[0]])]}if(l&&2===n.path.length&&e.children[n.path[0]]){let e=0!==i.children.length&&i.children[n.path[1]-1]?"after":"before",r={...n.node};!r._type&&a.Text.isText(r)&&(r._type="span",r.marks=[]);let l=fromSlateValue([{_key:"bogus",_type:t,children:[r]}],t)[0].children[0];return[(0,g.$T)([l],e,[{_key:i._key},"children",i.children.length<=1||!i.children[n.path[1]-1]?0:{_key:i.children[n.path[1]-1]._key}])]}return J("Something was inserted into a void block. Not producing editor patches."),[]},insertTextPatch:function(e,t,n){J.enabled&&J("Operation",JSON.stringify(t,null,2));let r=e.isTextBlock(e.children[t.path[0]])&&e.children[t.path[0]];if(!r)throw Error("Could not find block");let i=e.isTextBlock(r)&&e.isTextSpan(r.children[t.path[1]])&&r.children[t.path[1]];if(!i)throw Error("Could not find child");let l=[{_key:r._key},"children",{_key:i._key},"text"],o=n[t.path[0]],a=e.isTextBlock(o)&&o.children[t.path[1]],s=e.isTextSpan(a)?a.text:"",c=(0,g.aH)(s,i.text,l);return c.value.length?[c]:[]},mergeNodePatch:function(e,n,r){let i=[],l=r[n.path[0]],o=e.children[n.path[0]];if(1===n.path.length){if(l?._key){let r=fromSlateValue([e.children[n.path[0]-1]],t)[0];i.push((0,g.t8)(r,[{_key:r._key}])),i.push((0,g.zN)([{_key:l._key}]))}else throw Error("Target key not found!")}else if(e.isTextBlock(l)&&e.isTextBlock(o)&&2===n.path.length){let t=
57o.children[n.path[1]-1]&&e.isTextSpan(o.children[n.path[1]-1])?o.children[n.path[1]-1]:void 0,r=l.children[n.path[1]]&&e.isTextSpan(l.children[n.path[1]])?l.children[n.path[1]]:void 0;t&&(1===l.children.filter(e=>e._key===t._key).length?i.push((0,g.t8)(t.text,[{_key:l._key},"children",{_key:t._key},"text"])):console.warn(`Multiple spans have \`_key\` ${t._key}. It's ambiguous which one to update.`,JSON.stringify(l,null,2))),r&&(1===l.children.filter(e=>e._key===r._key).length?i.push((0,g.zN)([{_key:l._key},"children",{_key:r._key}])):console.warn(`Multiple spans have \`_key\` ${r._key}. It's ambiguous which one to remove.`,JSON.stringify(l,null,2)))}else J("Void nodes can't be merged, not creating any patches");return i},moveNodePatch:function(e,n,r){let i=[],l=r[n.path[0]],o=r[n.newPath[0]];if(1===n.path.length){let e=n.path[0]>n.newPath[0]?"before":"after";i.push((0,g.zN)([{_key:l._key}])),i.push((0,g.$T)([fromSlateValue([l],t)[0]],e,[{_key:o._key}]))}else if(2===n.path.length&&e.isTextBlock(l)&&e.isTextBlock(o)){let e=l.children[n.path[1]],r=o.children[n.newPath[1]],a=n.newPath[1]===o.children.length?"after":"before",s=fromSlateValue([l],t)[0].children[n.path[1]];i.push((0,g.zN)([{_key:l._key},"children",{_key:e._key}])),i.push((0,g.$T)([s],a,[{_key:o._key},"children",{_key:r._key}]))}return i},removeNodePatch:function(e,t,n){let r=n[t.path[0]];if(1===t.path.length){if(r&&r._key)return[(0,g.zN)([{_key:r._key}])];throw Error("Block not found")}if(!e.isTextBlock(r)||2!==t.path.length)return J("Not creating patch inside object block"),[];{let e=r.children[t.path[1]];return e?r.children.filter(e=>e._key===t.node._key).length>1?(console.warn(`Multiple spans have \`_key\` ${t.node._key}. It's ambiguous which one to remove.`,JSON.stringify(r,null,2)),[]):[(0,g.zN)([{_key:r._key},"children",{_key:e._key}])]:(J("Span not found in editor trying to remove node"),[])}},removeTextPatch:function(e,t,n){let r=e&&e.children[t.path[0]];if(!r)throw Error("Could not find block");let i=e.isTextBlock(r)&&r.children[t.path[1]]||void 0,l=e.isTextSpan(i)?i:void 0;if(i&&!l)throw Error("Expected span");if(!l)throw Error("Could not find child");let o=[{_key:r._key},"children",{_key:l._key},"text"],a=n[t.path[0]],s=e.isTextBlock(a)&&a.children[t.path[1]],c=e.isTextSpan(s)&&s.text,d=(0,g.aH)(c||"",l.text,o);return d.value?[d]:[]},setNodePatch:function(e,n){if(1===n.path.length){let r=e.children[n.path[0]];if("string"!=typeof r._key)throw Error("Expected block to have a _key");let i=k({...e.children[n.path[0]],...n.newProperties},y);return[(0,g.t8)(fromSlateValue([i],t)[0],[{_key:r._key}])]}if(2===n.path.length){let t=e.children[n.path[0]];if(e.isTextBlock(t)){let e=t.children[n.path[1]];if(e){let r=t._key,i=e._key,l=[],o=Object.keys(n.newProperties);return o.forEach(a=>{if(1===o.length&&"_key"===a){let i=m(n.newProperties,a);l.push((0,g.t8)(i,[{_key:r},"children",t.children.indexOf(e),a]))}else{let e=m(n.newProperties,a);l.push((0,g.t8)(e,[{_key:r},"children",{_key:i},a]))}}),l}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)}`)},splitNodePatch:function(e,n,r){let i=[],l=e.children[n.path[0]];if(!e.isTextBlock(l))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 o=r[n.path[0]];if(e.isTextBlock(o)){let r=fromSlateValue([e.children[n.path[0]+1]],t)[0];r&&(i.push((0,g.$T)([r],"after",[{_key:l._key}])),o.children.slice(n.position).forEach(e=>{let t=[{_key:o._key},"children",{_key:e._key}];i.push((0,g.zN)(t))}))}return i}if(2===n.path.length){let r=l.children[n.path[1]];if(e.isTextSpan(r)){let e=fromSlateValue([{...l,children:l.children.slice(n.path[1]+1,n.path[1]+2)}],t)[0].children;i.push((0,g.$T)(e,"after",[{_key:l._key},"children",{_key:r._key}])),i.push((0,g.t8)(r.text,[{_key:l._key},"children",{_key:r._key},"text"]))}}return i}}}(x),withObjectKeys=function(e){let{apply:t,normalizeNode:n}=e;return e.apply=n=>{if(isChangingRemotely(e)||isUndoing(e)||isRedoing(e)){t(n);return}
57if("split_node"===n.type){t({...n,properties:{...n.properties,_key:o()}});return}if("insert_node"===n.type&&!a.Editor.isEditor(n.node)){t({...n,node:{...n.node,_key:o()}});return}t(n)},e.normalizeNode=t=>{let[r,i]=t;if(a.Element.isElement(r)&&r._type===x.block.name){for(let[t,n]of(r._key||a.Transforms.setNodes(e,{_key:o()},{at:i}),a.Node.children(e,i)))if(!t._key){a.Transforms.setNodes(e,{_key:o()},{at:n});return}}n(t)},e},E=function({schemaTypes:e,keyGenerator:t}){return function(n){n.isTextBlock=t=>(0,d.DG)(t)&&t._type===e.block.name,n.isTextSpan=t=>(0,d.NG)(t)&&t._type==e.span.name,n.isListBlock=t=>(0,d.KA)(t)&&t._type===e.block.name,n.isVoid=t=>e.block.name!==t._type&&(e.blockObjects.map(e=>e.name).includes(t._type)||e.inlineObjects.map(e=>e.name).includes(t._type)),n.isInline=t=>e.inlineObjects.map(e=>e.name).includes(t._type)&&"__inline"in t&&!0===t.__inline;let{normalizeNode:r}=n;return n.normalizeNode=i=>{let[l,o]=i;if(void 0===l._type&&2===o.length){ex("Setting span type on text node without a type");let r=l._key||t();a.Transforms.setNodes(n,{...l,_type:e.span.name,_key:r},{at:o})}if(void 0===l._key&&(1===o.length||2===o.length)){ex("Setting missing key on child node without a key");let e=t();a.Transforms.setNodes(n,{_key:e},{at:o})}r(i)},n}}({schemaTypes:x,keyGenerator:o}),withEditableAPI=function(e){return c.setEditable({focus:()=>{s.ReactEditor.focus(e)},blur:()=>{s.ReactEditor.blur(e)},toggleMark:t=>{e.pteToggleMark(t)},toggleList:t=>{e.pteToggleListItem(t)},toggleBlockStyle:t=>{e.pteToggleBlockStyle(t)},isMarkActive:t=>{try{return e.pteIsMarkActive(t)}catch(e){return console.warn(e),!1}},marks:()=>({...a.Editor.marks(e)||{}}).marks||[],undo:()=>e.undo(),redo:()=>e.redo(),select:t=>{let n=toSlateRange(t,e);n?a.Transforms.select(e,n):a.Transforms.deselect(e),e.onChange()},focusBlock:()=>{if(e.selection){let t=a.Node.descendant(e,e.selection.focus.path.slice(0,1));if(t)return fromSlateValue([t],x.block.name,O.get(e))[0]}},focusChild:()=>{if(e.selection){let t=a.Node.descendant(e,e.selection.focus.path.slice(0,1));if(t&&e.isTextBlock(t))return fromSlateValue([t],x.block.name,O.get(e))[0].children[e.selection.focus.path[1]]}},insertChild:(t,n)=>{if(!e.selection)throw Error("The editor has no selection");let[r]=Array.from(a.Editor.nodes(e,{at:e.selection.focus.path.slice(0,1),match:e=>e._type===x.block.name}))[0]||[void 0];if(!r)throw Error("No focused text block");if(t.name!==x.span.name&&!x.inlineObjects.some(e=>e.name===t.name))throw Error("This type cannot be inserted as a child to a text block");let i=toSlateValue([{_key:o(),_type:x.block.name,children:[{_key:o(),_type:t.name,...n||{}}]}],c)[0].children[0],l=e.selection.focus.path.slice(0,2),s=i._type===x.span.name,d=a.Node.get(e,l);return s&&d._type!==x.span.name&&(H("Inserting span child next to inline object child, moving selection + 1"),e.move({distance:1,unit:"character"})),a.Transforms.insertNodes(e,i,{select:!0,at:e.selection}),e.onChange(),toPortableTextRange(fromSlateValue(e.children,x.block.name,O.get(e)),e.selection,x)?.focus.path||[]},insertBlock:(t,n)=>{let r=toSlateValue([{_key:o(),_type:t.name,...n||{}}],c)[0];if(!e.selection){let t=Array.from(a.Editor.nodes(e,{match:e=>!a.Editor.isEditor(e),at:[],reverse:!0}))[0];return a.Editor.insertNode(e,r),t&&isEqualToEmptyEditor([t[0]],x)&&a.Transforms.removeNodes(e,{at:t[1]}),e.onChange(),toPortableTextRange(fromSlateValue(e.children,x.block.name,O.get(e)),e.selection,x)?.focus.path??[]}let i=Array.from(a.Editor.nodes(e,{at:e.selection.focus.path.slice(0,1),match:e=>e._type===x.block.name}))[0];return a.Editor.insertNode(e,r),i&&isEqualToEmptyEditor([i[0]],x)&&a.Transforms.removeNodes(e,{at:i[1]}),e.onChange(),toPortableTextRange(fromSlateValue(e.children,x.block.name,O.get(e)),e.selection,x)?.focus.path||[]},hasBlockStyle:t=>{try{return e.pteHasBlockStyle(t)}catch{return!1}},hasListStyle:t=>{try{return e.pteHasListStyle(t)}catch{return!1}},isVoid:e=>![x.block.name,x.span.name].includes(e._type),findByPath:t=>{let n=toSlateRange({focus:{path:t,offset:0},anchor:{path:t,offset:0}},e);
57if(n){let[r,i]=a.Editor.node(e,n.focus.path.slice(0,1));if(r&&i&&"string"==typeof r._key){if(1===t.length&&1===n.focus.path.length)return[fromSlateValue([r],x.block.name)[0],[{_key:r._key}]];let i=fromSlateValue([r],x.block.name,O.get(e))[0];if(e.isTextBlock(i)){let e=i.children[n.focus.path[1]];if(e)return[e,[{_key:r._key},"children",{_key:e._key}]]}}}return[void 0,void 0]},findDOMNode:t=>{let n;try{let[r]=Array.from(a.Editor.nodes(e,{at:[],match:e=>e._key===t._key})||[])[0]||[void 0];n=s.ReactEditor.toDOMNode(e,r)}catch{}return n},activeAnnotations:()=>{if(!e.selection||e.selection.focus.path.length<2)return[];try{let t=[],n=a.Editor.nodes(e,{at:e.selection,match:e=>a.Text.isText(e)&&void 0!==e.marks&&Array.isArray(e.marks)&&e.marks.length>0});for(let[r,i]of n){let[n]=a.Editor.node(e,i,{depth:1});e.isTextBlock(n)&&n.markDefs?.forEach(e=>{a.Text.isText(r)&&r.marks&&Array.isArray(r.marks)&&r.marks.includes(e._key)&&t.push(e)})}return t}catch{return[]}},isAnnotationActive:t=>{if(!e.selection||e.selection.focus.path.length<2)return!1;try{let n=[...a.Editor.nodes(e,{at:e.selection,match:e=>a.Text.isText(e)})];if(0===n.length||n.some(([e])=>!(0,d.NG)(e)||!e.marks||e.marks?.length===0))return!1;let r=n.reduce((t,[,n])=>{let[r]=a.Editor.node(e,n,{depth:1});return e.isTextBlock(r)&&r.markDefs?[...t,...r.markDefs]:t},[]);return n.every(([e])=>!!(0,d.NG)(e)&&e.marks?.map(e=>r.find(t=>t?._key===e)?._type)?.includes(t))}catch{return!1}},addAnnotation:(t,n)=>{let r;let{selection:i}=e;if(i){let[l]=a.Editor.node(e,i.focus,{depth:1});if(!e.isTextBlock(l))return;let[s]=a.Editor.node(e,i.focus,{depth:2});if(!(0,d.NG)(s)||""===s.text)return;a.Range.isCollapsed(i)&&(e.pteExpandToWord(),e.onChange()),e.selection&&(a.Editor.withoutNormalizing(e,()=>{let c=o();a.Transforms.setNodes(e,{markDefs:[...l.markDefs||[],{_type:t.name,_key:c,...n}]},{at:i.focus}),e.onChange(),a.Transforms.setNodes(e,{},{match:a.Text.isText,split:!0}
57),e.onChange(),e.selection&&a.Text.isText(s)&&a.Transforms.setNodes(e,{marks:[...s.marks||[],c]},{at:e.selection,match:e=>e._type===x.span.name}),e.onChange();let d=toPortableTextRange(fromSlateValue(e.children,x.block.name,O.get(e)),e.selection,x);d&&(r={spanPath:d.focus.path,markDefPath:[{_key:l._key},"markDefs",{_key:c}]})}),a.Editor.normalize(e),e.onChange())}return r},delete:(t,n)=>{if(t){let r=toSlateRange(t,e);if(!(r&&r.anchor.path.length>0&&r.focus.path.length>0))throw Error("Invalid range");if(r){if(!n?.mode||n?.mode==="selected"){H("Deleting content in selection"),a.Transforms.delete(e,{at:r,hanging:!0,voids:!0}),e.onChange();return}n?.mode==="blocks"&&(H("Deleting blocks touched by selection"),a.Transforms.removeNodes(e,{at:r,voids:!0,match:t=>e.isTextBlock(t)||!e.isTextBlock(t)&&a.Element.isElement(t)})),n?.mode==="children"&&(H("Deleting children touched by selection"),a.Transforms.removeNodes(e,{at:r,voids:!0,match:t=>t._type===x.span.name||!e.isTextBlock(t)&&a.Element.isElement(t)})),0===e.children.length&&(e.children=[e.pteCreateEmptyBlock()]),e.onChange()}}},removeAnnotation:t=>{let{selection:n}=e;if(H("Removing annotation",t),n){if(a.Range.isCollapsed(n)){let[t,r]=a.Editor.node(e,n,{depth:2});a.Text.isText(t)&&t.marks&&"string"==typeof t.text&&(a.Transforms.select(e,r),n=e.selection)}a.Editor.withoutNormalizing(e,()=>{n&&a.Range.isExpanded(n)&&(n=e.selection)&&[...a.Editor.nodes(e,{at:n,match:n=>e.isTextBlock(n)&&Array.isArray(n.markDefs)&&n.markDefs.some(e=>e._type===t.name)})].forEach(([n])=>{e.isTextBlock(n)&&Array.isArray(n.markDefs)&&n.markDefs.filter(e=>e._type===t.name).forEach(t=>{a.Editor.removeMark(e,t._key)})})}),a.Editor.normalize(e),e.onChange()}},getSelection:()=>{let t=null;if(e.selection){let n=j.get(e.selection);if(n)return n;t=toPortableTextRange(fromSlateValue(e.children,x.block.name,O.get(e)),e.selection,x),j.set(e.selection,t)}return t},getValue:()=>fromSlateValue(e.children,x.block.name,O.get(e)),isCollapsedSelection:()=>!!e.selection&&a.Range.isCollapsed(e.selection),isExpandedSelection:()=>!!e.selection&&a.Range.isExpanded(e.selection),insertBreak:()=>{e.insertBreak(),e.onChange()},getFragment:()=>fromSlateValue(e.getFragment(),x.block.name),isSelectionsOverlapping:(t,n)=>{let r=toSlateRange(t,e),i=toSlateRange(n,e);return a.Range.isRange(r)&&a.Range.isRange(i)&&a.Range.includes(r,i)}}),e},T=function({change$:e,patches$:t,patchFunctions:n,readOnly:r,schemaTypes:i}){let l,o;let applyPatch=function(e,t){let n=!1;ea&&(eo(` 58 59NEW PATCH =============================================================`),eo(JSON.stringify(t,null,2)));try{switch(t.type){case"insert":n=function(e,t,n){let{block:r,child:i,blockPath:l,childPath:o}=findBlockAndChildFromPath(e,t.path);if(!r||!l)return eo("Block not found"),!1;if(t.path.length>1&&"children"!==t.path[1])return eo("Ignoring patch targeting void value"),!1;if(1===t.path.length){let{items:r,position:i}=t,o=toSlateValue(r,{schemaTypes:n},$.get(e)),s=l[0],c="after"===i?s+1:s;return eo(`Inserting blocks at path [${c}]`),debugState(e,"before"),a.Transforms.insertNodes(e,o,{at:[c]}),debugState(e,"after"),!0}let{items:s,position:c}=t;if(!i||!o)return eo("Child not found"),!1;let d=r&&toSlateValue([{...r,children:s}],{schemaTypes:n},$.get(e)),h=o[1],u=[o[0],"after"===c?h+1:h];return eo(`Inserting children at path ${u}`),debugState(e,"before"),d&&a.Element.isElement(d[0])&&a.Transforms.insertNodes(e,d[0].children,{at:u}),debugState(e,"after"),!0}(e,t,i);break;case"unset":n=function(e,t,n){if(0===t.path.length){eo("Removing everything"),debugState(e,"before");let t=e.selection;return a.Transforms.deselect(e),e.children.forEach((t,n)=>{a.Transforms.removeNodes(e,{at:[n]})}),a.Transforms.insertNodes(e,e.pteCreateEmptyBlock()),t&&a.Transforms.select(e,{anchor:{path:[0,0],offset:0},focus:{path:[0,0],offset:0}}),e.onChange(),debugState(e,"after"),!0}let{block:r,blockPath:i,child:l,childPath:o}=findBlockAndChildFromPath(e,t.path);if(1===t.path.length){if(!r||!i)return eo("Block not found"),!1;let t=i[0];return eo(`Removing block at path [${t}]`),debugState(e,"before"),a.Transforms.removeNodes(e,{at:[t]}),debugState(e,"after"),!0}return!!e.isTextBlock(r)&&"children"===t.path[1]&&3===t.path.length&&(l&&o?(eo(`Unsetting child at path ${JSON.stringify(o)}`),debugState(e,"before"),ea&&eo(`Removing child at path ${JSON.stringify(o)}`),a.Transforms.removeNodes(e,{at:o}),debugState(e,"after"),!0):(eo("Child not found"),!1))}(e,t,0);break;case"set":n=function(e,t){let n=t.value;"string"==typeof t.path[3]&&((n={})[t.path[3]]=t.value);let{block:r,blockPath:i,child:l,childPath:o}
59=findBlockAndChildFromPath(e,t.path);if(!r)return eo("Block not found"),!1;let s=e.isTextBlock(r);if(s&&t.path.length>1&&"children"!==t.path[1])return eo("Ignoring setting void value"),!1;if(debugState(e,"before"),s&&l&&o){if(a.Text.isText(n)&&a.Text.isText(l)){let t=l.text;n.text!==t&&(eo("Setting text property"),e.apply({type:"remove_text",path:o,offset:0,text:t}),e.apply({type:"insert_text",path:o,offset:0,text:n.text}),e.onChange())}else eo("Setting non-text property"),e.apply({type:"set_node",path:o,properties:{},newProperties:n});return!0}if(a.Element.isElement(r)&&1===t.path.length&&i){eo("Setting block property");let{children:t,...l}=n,{children:o,...a}=r||{children:void 0};e.apply({type:"set_node",path:i,properties:{...a},newProperties:l}),eo("Setting children"),r.children.forEach((t,n)=>{e.apply({type:"remove_node",path:i.concat(r.children.length-1-n),node:t})}),Array.isArray(t)&&t.forEach((t,n)=>{e.apply({type:"insert_node",path:i.concat(n),node:t})})}else if(r&&"value"in r){let n=(0,g.g7)([r.value],[t])[0];return a.Transforms.setNodes(e,{...r,value:n},{at:i}),!0}return debugState(e,"after"),!0}(e,t);break;case"diffMatchPatch":n=function(e,t){let{block:n,child:r,childPath:i}=findBlockAndChildFromPath(e,t.path);if(!n)return eo("Block not found"),!1;if(!r||!i)return eo("Child not found"),!1;if(!(n&&e.isTextBlock(n)&&4===t.path.length&&"children"===t.path[1]&&"text"===t.path[3])||!a.Text.isText(r))return!1;let l=parse(t.value),[o]=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("string"==typeof e)throw Error("Patches must be an array - pass the patch to `parsePatch()` first");let r=t;if(0===e.length)return[r,[]];let i=function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=0,i=0;function advanceTo(e){for(;r<e;){let e=t.codePointAt(i);if(typeof e>"u")return i;r+=utf8len(e),e>65535?i+=2:i+=1}if(!n.allowExceedingIndices&&r!==e)throw Error("Failed to determine byte offset");return i}let l=[];for(let t of e)l.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 l}(e,r,{allowExceedingIndices:n.allowExceedingIndices}),l=n.margin||4,o=n.deleteThreshold||.4,a=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4,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 r=e[0],i=r.diffs;if(0===i.length||i[0][0]!==er)i.unshift([er,n]),r.start1-=t,r.start2-=t,r.utf8Start1-=t,r.utf8Start2-=t,r.length1+=t,r.length2+=t,r.utf8Length1+=t,r.utf8Length2+=t;else if(t>i[0][1].length){let e=i[0][1].length,l=t-e;i[0][1]=n.substring(e)+i[0][1],r.start1-=l,r.start2-=l,r.utf8Start1-=l,r.utf8Start2-=l,r.length1+=l,r.length2+=l,r.utf8Length1+=l,r.utf8Length2+=l}if(0===(i=(r=e[e.length-1]).diffs).length||i[i.length-1][0]!==er)i.push([er,n]),r.length1+=t,r.length2+=t,r.utf8Length1+=t,r.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),r.length1+=e,r.length2+=e,r.utf8Length1+=e,r.utf8Length2+=e}return n}(i,l);r=a+r+a,function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4;for(let n=0;n<e.length;n++){if(e[n].length1<=32)continue;let r=e[n];e.splice(n--,1);let i=r.start1,l=r.start2,o="";for(;0!==r.diffs.length;){let a=createPatchObject(i-o.length,l-o.length),s=!0;if(""!==o){let e=countUtf8Bytes(o);a.length1=o.length,a.utf8Length1=e,a.length2=o.length,a.utf8Length2=e,a.diffs.push([er,o])}for(;0!==r.diffs.length&&a.length1<32-t;){let e=r.diffs[0][0],n=r.diffs[0][1],o=countUtf8Bytes(n);if(e===en){a.length2+=n.length,a.utf8Length2+=o,l+=n.length;let e=r.diffs.shift();e&&a.diffs.push(e),s=!1}else e===et&&1===a.diffs.length&&a.diffs[0][0]===er&&n.length>64?(a.length1+=n.length,a.utf8Length1+=o,i+=n.length,s=!1,a.diffs.push([e,n]),r.diffs.shift()):(o=countUtf8Bytes(n=n.substring(0,32-a.length1-t)),a.length1+=n.length,a.utf8Length1+=o,i+=n.length,e===er?(a.length2+=n.length,a.utf8Length2+=o,l+=n.length):s=!1,a.diffs.push([e,n]),n===r.diffs[0][1]?r.diffs.shift():r.diffs[0][1]=r.diffs[0][1].substring(n.length))}o=(o=diffText2(a.diffs)).substring(o.length-t);let c=diffText1(r.diffs).substring(0,t),d=countUtf8Bytes(c);""!==c&&(a.length1+=c.length,a.length2+=c.length,a.utf8Length1+=d,a.utf8Length2+=d,0!==a.diffs.length&&a.diffs[a.diffs.length-1][0]===er?a.diffs[a.diffs.length-1][1]+=c:a.diffs.push([er,c])),s||e.splice(++n,0,a)}}}(i,l);let s=0,c=[];for(let e=0;e<i.length;e++){let t=i[e].start2+s,n=diffText1(i[e].diffs),l,a=-1;if(n.length>32?-1!==(l=match(r,n.substring(0,32),t))&&(-1===(a=match(r,n.substring(n.length-32),t+n.length-32))||l>=a)&&(l=-1):l=match(r,n,t),-1===l)c[e]=!1,s-=i[e].length2-i[e].length1;else{let d;if(c[e]=!0,s=l-t,d=-1===a?r.substring(l,l+n.length):r.substring(l,a+32),n===d)r=r.substring(0,l)+diffText2(i[e].diffs)+r.substring(l+n.length);else{let t=diff(n,d,{checkLines:!1});if(n.length>32&&function(e){let t=0,n=0,r=0;for(let i=0;i<e.length;i++){let l=e[i][0],o=e[i][1];switch(l){case en:n+=o.length;break;case et:r+=o.length;break;case er:t+=Math.max(n,r),n=0,r=0;break;default:throw Error("Unknown diff operation.")}}return t+Math.max(n,r)}(t)/n.length>o)c[e]=!1;else{t=cleanupSemanticLossless(t);let n=0,o=0;for(let a=0;a<i[e].diffs.length;a++){let s=i[e].diffs[a];s[0]!==er&&(o=xIndex(t,n)),s[0]===en?r=r.substring(0,l+o)+s[1]+r.substring(l+o):s[0]===et&&(r=r.substring(0,l+o)+r.substring(l+xIndex(t,n+s[1].length))),s[0]!==et&&(n+=s[1].length)}}}}}return[r=r.substring(a.length,r.length-a.length),c]}(l,r.text,{allowExceedingIndices:!0}),s=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:4,n=e.map(e=>cloneDiff(e)),r=!1,i=[],l=0,o=null,a=0,s=!1,c=!1,d=!1,h=!1;for(;a<n.length;
59)n[a][0]===er?(n[a][1].length<t&&(d||h)?(i[l++]=a,s=d,c=h,o=n[a][1]):(l=0,o=null),d=!1,h=!1):(n[a][0]===et?h=!0:d=!0,o&&(s&&c&&d&&h||o.length<t/2&&3===function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.reduce((e,t)=>e+(t?1:0),0)}(s,c,d,h))&&(n.splice(i[l-1],0,[et,o]),n[i[l-1]+1][0]=en,l--,o=null,s&&c?(d=!0,h=!0,l=0):(a=--l>0?i[l-1]:-1,d=!1,h=!1),r=!0)),a++;return r&&(n=cleanupMerge(n)),n}(diff(r.text,o),5);debugState(e,"before");let c=0;for(let[t,n]of s)t===en?(e.apply({type:"insert_text",path:i,offset:c,text:n}),c+=n.length):t===et?e.apply({type:"remove_text",path:i,offset:c,text:n}):t===er&&(c+=n.length);return debugState(e,"after"),!0}(e,t);break;default:eo("Unhandled patch",t.type)}}catch(e){console.error(e)}return n};return function(o){C.set(o,!1),es.set(o,!0),l=[...o.children];let{apply:s}=o,c=[],handleBufferedRemotePatches=()=>{if(0===c.length)return;let e=c;c=[];let t=!1;withRemoteChanges(o,()=>{a.Editor.withoutNormalizing(o,()=>{withoutPatching(o,()=>{withoutSaving(o,()=>{e.forEach(e=>{ef.enabled&&ef(`Handling remote patch ${JSON.stringify(e)}`),t=applyPatch(o,e)})})})}),t&&(o.normalize(),o.onChange())})},handlePatches=({patches:e})=>{let t=e.filter(e=>"local"!==e.origin);0!==t.length&&(c=c.concat(t),handleBufferedRemotePatches())};return t&&o.subscriptions.push(()=>{ef("Subscribing to patches$");let e=t.subscribe(handlePatches);return()=>{ef("Unsubscribing to patches$"),e.unsubscribe()}}),o.apply=t=>{if(r)return s(t),o;let a=[];l=o.children;let c=isEqualToEmptyEditor(l,i);s(t);let d=isEqualToEmptyEditor(o.children,i);if(!es.get(o))return o;switch(c&&!d&&"set_selection"!==t.type&&a.push((0,g.$T)(l,"before",[0])),t.type){case"insert_text":a=[...a,...n.insertTextPatch(o,t,l)];break;case"remove_text":a=[...a,...n.removeTextPatch(o,t,l)];break;case"remove_node":a=[...a,...n.removeNodePatch(o,t,l)];break;case"split_node":a=[...a,...n.splitNodePatch(o,t,l)];break;case"insert_node":a=[...a,...n.insertNodePatch(o,t,l)];break;case"set_node":a=[...a,...n.setNodePatch(o,t,l)];break;case"merge_node":a=[...a,...n.mergeNodePatch(o,t,l)];break;case"move_node":a=[...a,...n.moveNodePatch(o,t,l)]}return!c&&d&&["merge_node","set_node","remove_text","remove_node"].includes(t.type)&&(a=[...a,(0,g.zN)([])],e.next({type:"unset",previousValue:fromSlateValue(l,i.block.name,O.get(o))})),c&&a.length>0&&(a=[(0,g.Cb)([],[]),...a]),a.length>0&&a.forEach(t=>{e.next({type:"patch",patch:{...t,origin:"local"}})}),o},o}}({change$:v,keyGenerator:o,patches$:h,patchFunctions:_,readOnly:f,schemaTypes:x}),S=(n=p||-1,function(e){let{apply:t}=e;return e.apply=r=>{if(isChangingRemotely(e)||isUndoing(e)||isRedoing(e)){t(r);return}n>0&&e.children.length>=n&&("insert_node"===r.type||"split_node"===r.type)&&1===r.path.length||t(r)},e}),withPortableTextLists=function(e){return e.pteToggleListItem=t=>{e.pteHasListStyle(t)?(em(`Remove list item '${t}'`),e.pteUnsetListItem(t)):(em(`Add list item '${t}'`),e.pteSetListItem(t))},e.pteUnsetListItem=t=>{e.selection&&[...a.Editor.nodes(e,{at:e.selection,match:e=>a.Element.isElement(e)&&e._type===x.block.name})].forEach(([n,r])=>{if(e.isListBlock(n)){let{listItem:i,level:l,...o}=n,s={...o,listItem:void 0,level:void 0};em(`Unsetting list '${t}'`),a.Transforms.setNodes(e,s,{at:r})}})},e.pteSetListItem=t=>{e.selection&&[...a.Editor.nodes(e,{at:e.selection,match:t=>e.isTextBlock(t)})].forEach(([n,r])=>{em(`Setting list '${t}'`),a.Transforms.setNodes(e,{...n,level:1,listItem:t||x.lists[0]&&x.lists[0].value},{at:r})})},e.pteEndList=()=>{if(!e.selection)return!1;let t=[...a.Editor.nodes(e,{at:e.selection,match:t=>a.Element.isElement(t)&&e.isListBlock(t)&&1===t.children.length&&a.Text.isText(t.children[0])&&""===t.children[0].text})];return 0!==t.length&&(t.forEach(([t,n])=>{a.Element.isElement(t)&&(em("Unset list"),a.Transforms.setNodes(e,{...t,level:void 0,listItem:void 0},{at:n}))}),!0)},e.pteIncrementBlockLevels=t=>{if(!e.selection)return!1;let n=[...a.Editor.nodes(e,{at:e.selection,match:t=>!!e.isListBlock(t)})];return 0!==n.length&&(n.forEach(([n,r])=>{if(e.isListBlock(n)){let i=n.level||1;t?em("Decrementing list level",Math.min(10,Math.max(1,--i))):em("Incrementing list level",Math.min(10,Math.max(1,++i))),a.Transforms.setNodes(e,{level:Math.min(10,Math.max(1,i))},{at:r})}}),!0)},e.pteHasListStyle=t=>{if(!e.selection)return!1;
59let n=[...a.Editor.nodes(e,{at:e.selection,match:t=>e.isTextBlock(t)})];return n.length>0&&n.every(([n])=>e.isListBlock(n)&&n.listItem===t)},e},N=function(e){let{readOnly:t,patches$:n,blockSchemaType:r}=e;return e=>{let i=fromSlateValue(e.children,r.name),l=getRemotePatches(e);n&&e.subscriptions.push(()=>{ec("Subscribing to patches");let t=n.subscribe(({patches:t,snapshot:n})=>{let r=!1;t.forEach(t=>{if(!r&&"local"!==t.origin&&l){if("unset"===t.type&&0===t.path.length){ec("Someone else cleared the content, resetting undo/redo history"),e.history={undos:[],redos:[]},l.splice(0,l.length),eh.set(e,!0),r=!0;return}l.push({patch:t,time:new Date,snapshot:n,previousSnapshot:i})}}),i=n});return()=>{ec("Unsubscribing to patches"),t.unsubscribe()}}),e.history={undos:[],redos:[]};let{apply:o}=e;return e.apply=n=>{if(t){o(n);return}let{operations:r,history:i}=e,{undos:l}=i,a=l[l.length-1],s=a&&a.operations&&a.operations[a.operations.length-1],c=shouldOverwrite(n,s),d=isSaving(e),h=!0;if(d){if(a?0===r.length&&(h=shouldMerge(n,s)||c):h=!1,a&&h)a.operations.push(n);else{let t={operations:[...null===e.selection?[]:[{type:"set_selection",properties:{...e.selection},newProperties:{...e.selection}}],n],timestamp:new Date};l.push(t),ec("Created new undo step",a)}for(;l.length>1e3;)l.shift();shouldClear(n)&&(i.redos=[])}o(n)},e.undo=()=>{if(t)return;let{undos:n}=e.history;if(n.length>0){let t=n[n.length-1];if(ec("Undoing",t),t.operations.length>0){let n=l.filter(e=>e.time>=t.timestamp),r=t.operations;n.forEach(t=>{r=b(r.map(n=>transformOperation(e,t.patch,n,t.snapshot,t.previousSnapshot)))});let i=r.map(a.Operation.inverse).reverse();try{a.Editor.withoutNormalizing(e,()=>{(function(e,t){let n=isUndoing(e);K.set(e,!0),t(),K.set(e,n)})(e,()=>{withoutSaving(e,()=>{i.forEach(t=>{e.apply(t)})})})}),e.normalize(),e.onChange()}catch(t){ec("Could not perform undo step",t),l.splice(0,l.length),a.Transforms.deselect(e),e.history={undos:[],redos:[]},eh.set(e,!0),K.set(e,!1),e.onChange();return}e.history.redos.push(t),e.history.undos.pop()}}},e.redo=()=>{if(t)return;let{redos:n}=e.history;if(n.length>0){let t=n[n.length-1];if(ec("Redoing",t),t.operations.length>0){let n=l.filter(e=>e.time>=t.timestamp),r=t.operations;n.forEach(t=>{r=b(r.map(n=>transformOperation(e,t.patch,n,t.snapshot,t.previousSnapshot)))});try{a.Editor.withoutNormalizing(e,()=>{(function(e,t){let n=isRedoing(e);G.set(e,!0),t(),G.set(e,n)})(e,()=>{withoutSaving(e,()=>{r.forEach(t=>{e.apply(t)})})})}),e.normalize(),e.onChange()}catch(t){ec("Could not perform redo step",t),l.splice(0,l.length),a.Transforms.deselect(e),e.history={undos:[],redos:[]},eh.set(e,!0),G.set(e,!1),e.onChange();return}e.history.undos.push(t),e.history.redos.pop()}}},e}}({readOnly:f,patches$:h,blockSchemaType:x.block}),withPortableTextMarkModel=function(e){let{apply:t,normalizeNode:n}=e,r=x.decorators.map(e=>e.value),forceNewSelection=()=>{e.selection&&(a.Transforms.select(e,{...e.selection}),e.selection={...e.selection});let t=toPortableTextRange(e.children,e.selection,x);v.next({type:"selection",selection:t})};return e.normalizeNode=t=>{let[r,l]=t;if(e.isTextBlock(r)){let t=a.Node.children(e,l);for(let[n,l]of t){let t=r.children[l[1]+1];if(e.isTextSpan(n)&&e.isTextSpan(t)&&i(n.marks,t.marks)){ey("Merging spans",JSON.stringify(n,null,2),JSON.stringify(t,null,2)),a.Transforms.mergeNodes(e,{at:[l[0],l[1]+1],voids:!0});return}}}if(e.isTextSpan(r)&&!Array.isArray(r.marks)){ey("Adding .marks to span node"),a.Transforms.setNodes(e,{marks:[]},{at:l});return}if(e.isTextSpan(r)){let t=a.Path.parent(l),[n]=a.Editor.node(e,t),i=x.decorators.map(e=>e.value),o=r.marks?.filter(e=>!i.includes(e));if(e.isTextBlock(n)&&""===r.text&&o&&o.length>0){ey("Removing annotations from empty span node"),a.Transforms.setNodes(e,{marks:r.marks?.filter(e=>i.includes(e))},{at:l});return}}if(e.isTextBlock(r)){let t=x.decorators.map(e=>e.value);for(let[n,i]of a.Node.children(e,l))if(e.isTextSpan(n)){let l=n.marks??[],o=l.filter(e=>!t.includes(e)&&!r.markDefs?.find(t=>t._key===e));if(o.length>0){ey("Removing orphaned annotations from span node"),a.Transforms.setNodes(e,{marks:l.filter(e=>!o.includes(e))},{at:i});return}}}
59if(e.isTextSpan(r)){let t=a.Path.parent(l),[n]=a.Editor.node(e,t);if(e.isTextBlock(n)){let t=x.decorators.map(e=>e.value),i=r.marks??[],o=i.filter(e=>!t.includes(e)&&!n.markDefs?.find(t=>t._key===e));if(o.length>0){ey("Removing orphaned annotations from span node"),a.Transforms.setNodes(e,{marks:i.filter(e=>!o.includes(e))},{at:l});return}}}if(e.isTextBlock(r)&&!e.operations.some(e=>"merge_node"===e.type&&"markDefs"in e.properties&&1===e.path.length)){let t=(r.markDefs||[]).filter(e=>r.children.find(t=>a.Text.isText(t)&&Array.isArray(t.marks)&&t.marks.includes(e._key)));if(r.markDefs&&!i(t,r.markDefs)){ey("Removing markDef not in use"),a.Transforms.setNodes(e,{markDefs:t},{at:l});return}}n(t)},e.apply=n=>{if(isChangingRemotely(e)||isUndoing(e)||isRedoing(e)){t(n);return}if("insert_text"===n.type){let{selection:t}=e;if(t&&a.Range.isCollapsed(t)&&a.Editor.marks(e)?.marks?.some(e=>!r.includes(e))){let[i]=Array.from(a.Editor.nodes(e,{mode:"lowest",at:t.focus,match:e=>e._type===x.span.name,voids:!1}))[0]||[void 0];if(a.Text.isText(i)&&i.text.length===t.focus.offset&&Array.isArray(i.marks)&&i.marks.length>0){let t=(({...a.Editor.marks(e)||{}}).marks||[]).filter(e=>r.includes(e));a.Transforms.insertNodes(e,{_type:"span",_key:o(),text:n.text,marks:t}),ey("Inserting text at end of annotation");return}}}if("remove_text"===n.type){var i,l;let o=Array.from(a.Editor.nodes(e,{mode:"lowest",at:{path:n.path,offset:n.offset},match:e=>e._type===x.span.name,voids:!1}))[0][0],s=a.Editor.node(e,a.Path.parent(n.path))[0];if(o&&"span"===(i=o)._type&&"text"in i&&"string"==typeof i.text&&(typeof i.marks>"u"||Array.isArray(i.marks)&&i.marks.every(e=>"string"==typeof e))&&s&&"string"==typeof(l=s)._type&&"@"!==l._type[0]&&(!("markDefs"in l)||!l.markDefs||Array.isArray(l.markDefs)&&l.markDefs.every(e=>"string"==typeof e._key))&&"children"in l&&Array.isArray(l.children)&&l.children.every(e=>"object"==typeof e&&"_type"in e)){let i=s.markDefs??[],l=(o.marks??[]).some(e=>i.find(t=>t._key===e)),c=0!==n.offset,d=n.offset+n.text.length===o.text.length;if(l&&c&&d){a.Editor.withoutNormalizing(e,()=>{a.Transforms.splitNodes(e,{match:a.Text.isText,at:{path:n.path,offset:n.offset}}),a.Transforms.removeNodes(e,{at:a.Path.next(n.path)})}),e.onChange();return}let h=0===n.offset&&d;if(l&&h){let i=(({...a.Editor.marks(e)||{}}).marks||[]).filter(e=>r.includes(e));a.Editor.withoutNormalizing(e,()=>{t(n),a.Transforms.setNodes(e,{marks:i},{at:n.path})}),e.onChange();return}if(void 0!==o.marks&&o.marks.length>0&&h){a.Editor.withoutNormalizing(e,()=>{t(n),a.Transforms.setNodes(e,{marks:[]},{at:n.path})}),e.onChange();return}}}if("merge_node"===n.type&&1===n.path.length&&"markDefs"in n.properties&&n.properties._type===x.block.name&&Array.isArray(n.properties.markDefs)&&n.properties.markDefs.length>0&&n.path[0]-1>=0){let[r,i]=a.Editor.node(e,[n.path[0]-1]);if(e.isTextBlock(r)){let l=Array.isArray(r.markDefs)&&r.markDefs||[],o=u([...l,...n.properties.markDefs]);ey("Copying markDefs over to merged block",n),a.Transforms.setNodes(e,{markDefs:o},{at:i,voids:!1}),t(n);return}}t(n)},e.addMark=t=>{if(e.selection){if(a.Range.isExpanded(e.selection))a.Editor.withoutNormalizing(e,()=>{a.Transforms.setNodes(e,{},{match:a.Text.isText,split:!0});let n=a.Range.isRange(e.selection)?[...a.Editor.nodes(e,{at:e.selection,match:a.Text.isText})]:[];n.length>1&&n.every(e=>e[0].marks?.includes(t))?e.removeMark(t):n.forEach(([n,r])=>{let i=[...(Array.isArray(n.marks)?n.marks:[]).filter(e=>e!==t),t];a.Transforms.setNodes(e,{marks:i},{at:r,match:a.Text.isText,split:!0,hanging:!0})})});else{let n={...a.Editor.marks(e)||{}}.marks||[],r={...a.Editor.marks(e)||{},marks:[...n,t]};return e.marks=r,forceNewSelection(),e}e.onChange(),forceNewSelection()}return e},e.removeMark=t=>{let{selection:n}=e;if(n){if(a.Range.isExpanded(n))a.Editor.withoutNormalizing(e,()=>{a.Transforms.setNodes(e,{},{match:a.Text.isText,split:!0}),e.selection&&[...a.Editor.nodes(e,{at:e.selection,match:a.Text.isText})].forEach(([n,r])=>{let i=e.children[r[0]];a.Element.isElement(i)&&i.children.includes(n)&&a.Transforms.setNodes(e,{marks:(Array.isArray(n.marks)?n.marks:[]).filter(e=>e!==t),_type:"span"},{at:r})})}),a.Editor.normalize(e);else{let n={...a.Editor.marks(e)||{}}.marks||[],r={...a.Editor.marks(e)||{},marks:n.filter(e=>e!==t)};return e.marks={marks:r.marks,_type:"span"},forceNewSelection(),e}e.onChange(),forceNewSelection()}return e},e.pteIsMarkActive=t=>{if(!e.selection)return!1;
59let n=Array.from(a.Editor.nodes(e,{match:a.Text.isText,at:e.selection}));return a.Range.isExpanded(e.selection)?n.every(e=>{let[n]=e;return n.marks?.includes(t)}):(({...a.Editor.marks(e)||{}}).marks||[]).includes(t)},e.pteToggleMark=t=>{e.pteIsMarkActive(t)?(ey(`Remove mark '${t}'`),a.Editor.removeMark(e,t)):(ey(`Add mark '${t}'`),a.Editor.addMark(e,t,!0))},e},w=function(e){let t=e.styles[0].value;return function(e){let{normalizeNode:n}=e;return e.normalizeNode=r=>{n(r);let[,i]=r;for(let n of e.operations)if("split_node"===n.type&&1===n.path.length&&e.isTextBlock(n.properties)&&n.properties.style!==t&&n.path[0]===i[0]&&!a.Path.equals(i,n.path)){let[r]=a.Editor.node(e,[n.path[0]+1,0]);if(a.Text.isText(r)&&""===r.text){eg(`Normalizing split node to ${t} style`,n),a.Transforms.setNodes(e,{style:t},{at:[n.path[0]+1],voids:!1});break}}},e.pteHasBlockStyle=t=>!!e.selection&&[...a.Editor.nodes(e,{at:e.selection,match:n=>e.isTextBlock(n)&&n.style===t})].length>0,e.pteToggleBlockStyle=n=>{e.selection&&([...a.Editor.nodes(e,{at:e.selection,match:t=>e.isTextBlock(t)})].forEach(([r,i])=>{e.isTextBlock(r)&&r.style===n?(eg(`Unsetting block style '${n}'`),a.Transforms.setNodes(e,{...r,style:t},{at:i})):(n?eg(`Setting style '${n}'`):eg("Setting default style",t),a.Transforms.setNodes(e,{...r,style:n||t},{at:i}))}),e.onChange())},e}}(x),withPlaceholderBlock=function(e){let{apply:t}=e;return e.apply=n=>{if(isChangingRemotely(e)||isUndoing(e)||isRedoing(e)){t(n);return}if("remove_node"===n.type){let t=n.node;if(0===n.path[0]&&a.Editor.isVoid(e,t)){let t=a.Path.next(n.path);e.children[t[0]]||(ep("Adding placeholder block"),a.Editor.insertNode(e,e.pteCreateEmptyBlock()))}}t(n)},e},withInsertBreak=function(e){let{insertBreak:t}=e;return e.insertBreak=()=>{if(e.selection){let t=e.selection.focus.path.slice(0,1),n=a.Node.descendant(e,t);if(e.isTextBlock(n)){let[,r]=a.Range.edges(e.selection),i=a.Editor.isStart(e,r,r.path),l=n&&isEqualToEmptyEditor([n],x);if(i&&!l){a.Editor.insertNode(e,e.pteCreateEmptyBlock());let[n]=a.Path.next(t);a.Transforms.select(e,{anchor:{path:[n,0],offset:0},focus:{path:[n,0],offset:0}}),e.onChange();return}}}t()},e},P=function({schemaTypes:e,keyGenerator:t,portableTextEditor:n}){return function(r){return r.pteExpandToWord=()=>{let{selection:e}=r;if(e&&!a.Range.isExpanded(e)){let[t]=a.Editor.node(r,e.focus,{depth:2});if(!t||!a.Text.isText(t)||0===t.text.length){ev("pteExpandToWord: Can't expand to word here");return}let{focus:n}=e,i=n.offset,l=t.text.slice(0,i),o=t.text.slice(i,-1),isEmpty=e=>e.match(/\s/g),s=l.split("").reverse().findIndex(e=>isEmpty(e)),c=s>-1?l.length-s:0,d=o.split("").findIndex(e=>isEmpty(e)),h=l.length+(d>-1?d:o.length+1);if(!(c===h||isNaN(c)||isNaN(h))){ev("pteExpandToWord: Expanding to focused word"),a.Transforms.setSelection(r,{anchor:{...e.anchor,offset:c},focus:{...e.focus,offset:h}});return}ev("pteExpandToWord: Can't expand to word here")}},r.pteCreateEmptyBlock=()=>toSlateValue([{_type:e.block.name,_key:t(),style:e.styles[0].value||"normal",markDefs:[],children:[{_type:"span",_key:t(),text:"",marks:[]}]}],n)[0],r}}({keyGenerator:o,schemaTypes:x,portableTextEditor:c}),A=(r=null,function(e){let emitPortableTextSelection=()=>{if(r!==e.selection){let t=null;if(e.selection){let n=j.get(e.selection);if(n)t=n;else{let n=e.children;t=toPortableTextRange(n,e.selection,x),j.set(e.selection,t)}}eb&&ek(`Emitting selection ${JSON.stringify(t||null)} (${JSON.stringify(e.selection)})`),t?v.next({type:"selection",selection:t}):v.next({type:"selection",selection:null})}r=e.selection},{onChange:t}=e;return e.onChange=()=>{let n=e.operations.length>0;t(),n&&emitPortableTextSelection()},e});return e.destroy=()=>{let t=eN.get(e);if(!t)throw Error("Could not find pristine versions of editor functions");e.apply=t.apply,e.history={undos:[],redos:[]},e.normalizeNode=t.normalizeNode,e.onChange=t.onChange},f?{editor:E(withObjectKeys(withPortableTextMarkModel(w(P(withPlaceholderBlock(withPortableTextLists(A(withEditableAPI(withInsertBreak(e)))))))))),subscribe:()=>l}:{editor:E(withObjectKeys(withPortableTextMarkModel(w(withPortableTextLists(withPlaceholderBlock(P(S(N(T(A(withEditableAPI(withInsertBreak(e))))))))))))),subscribe:()=>{let t=[];
59return e.subscriptions.forEach(e=>{t.push(e())}),()=>{t.forEach(e=>{e()})}}}},ew=debugWithName("component:PortableTextEditor:SlateContainer");function SlateContainer(e){let{patches$:t,portableTextEditor:n,readOnly:i,maxBlocks:l,keyGenerator:c}=e,[[d,h]]=(0,o.useState)(()=>{ew("Creating new Slate editor instance");let{editor:e,subscribe:r}=withPlugins((0,s.withReact)((0,a.createEditor)()),{keyGenerator:c,maxBlocks:l,patches$:t,portableTextEditor:n,readOnly:i});return O.set(e,{}),$.set(e,{}),[e,r]});(0,o.useEffect)(()=>{let e=h();return()=>{e()}},[h]),(0,o.useEffect)(()=>{ew("Re-initializing plugin chain"),withPlugins(d,{keyGenerator:c,maxBlocks:l,patches$:t,portableTextEditor:n,readOnly:i})},[c,n,l,i,t,d]);let u=(0,o.useMemo)(()=>[d.pteCreateEmptyBlock()],[d]);return(0,o.useEffect)(()=>()=>{ew("Destroying Slate editor"),d.destroy()},[d]),(0,r.jsx)(s.Slate,{editor:d,initialValue:u,children:e.children})}let defaultKeyGenerator=()=>(0,T.E2)(12),eP=(0,o.createContext)(defaultKeyGenerator),usePortableTextEditorKeyGenerator=()=>{let e=(0,o.useContext)(eP);if(void 0===e)throw Error("The `usePortableTextEditorKeyGenerator` hook must be used inside the <PortableTextEditor> component's context.");return e},eC=(0,o.createContext)(!1),usePortableTextEditorReadOnlyStatus=()=>{let e=(0,o.useContext)(eC);if(void 0===e)throw Error("The `usePortableTextEditorReadOnly` hook must be used inside the <PortableTextEditor> component's context.");return e},eA=debugWithName("hook:useSyncValue"),eD=new WeakMap,eR=debugWithName("component:PortableTextEditor:Synchronizer"),eB=eR.enabled&&!1;function Synchronizer(e){let t=usePortableTextEditor(),n=usePortableTextEditorKeyGenerator(),r=usePortableTextEditorReadOnlyStatus(),{change$:l,getValue:c,onChange:d,value:h}=e,u=(0,o.useRef)([]),f=function(e){let{portableTextEditor:t,readOnly:n,keyGenerator:r}=e,{change$:l,schemaTypes:c}=t,d=(0,o.useRef)(),h=(0,s.useSlate)(),u=(0,o.useRef)(),f=(0,o.useCallback)(()=>{let e=eD.get(t);if(d.current===e){eA("Value is the same object as previous, not need to sync");return}u.current&&e&&(eA("Updating the value debounced"),u.current(e))},[t]),p=(0,o.useMemo)(()=>S(f,1e3,{trailing:!0,leading:!1}),[f]);return(0,o.useMemo)(()=>{let updateFunction=e=>{eD.set(t,e);let o=A.get(h),s=isChangingRemotely(h);if(!n){if(o){eA("Has local changes, not syncing value right now"),p();return}if(s){eA("Has remote changes, not syncing value right now"),p();return}}let u=!1,f=!0,g=!!h.selection;if(e&&0!==e.length||(eA("Value is empty"),a.Editor.withoutNormalizing(h,()=>{withoutSaving(h,()=>{withoutPatching(h,()=>{g&&a.Transforms.deselect(h);let e=h.children.length;h.children.forEach((t,n)=>{a.Transforms.removeNodes(h,{at:[e-1-n]})}),a.Transforms.insertNodes(h,h.pteCreateEmptyBlock(),{at:[0]}),g&&a.Transforms.select(h,[0,0])})})}),u=!0),e&&e.length>0){let t=toSlateValue(e,{schemaTypes:c});a.Editor.withoutNormalizing(h,()=>{withRemoteChanges(h,()=>{withoutSaving(h,()=>{withoutPatching(h,()=>{let o=h.children.length;if(t.length<o){for(let e=o-1;e>t.length-1;e--)a.Transforms.removeNodes(h,{at:[e]});u=!0}t.forEach((t,o)=>{let s=h.children[o];if(s&&!i(t,s)&&f){let p=[e[o]],g=validateValue(p,c,r);!g.valid&&g.resolution?.autoResolve&&g.resolution?.patches.length>0&&!n&&d.current&&d.current!==e&&(console.warn(`${g.resolution.action} for block with _key '${p[0]._key}'. ${g.resolution?.description}`),g.resolution.patches.forEach(e=>{l.next({type:"patch",patch:e})})),g.valid||g.resolution?.autoResolve?(s._key===t._key?(eA.enabled&&eA("Updating block",s,t),function(e,t,n,r){if(a.Transforms.setNodes(e,t,{at:[r]}),e.isTextBlock(t)&&e.isTextBlock(n)){let l=n.children.length;t.children.length<l&&Array.from(Array(l-t.children.length)).forEach((t,n)=>{let i=l-1-n;i>0&&(eA("Removing child"),a.Transforms.removeNodes(e,{at:[r,i]}))}),t.children.forEach((t,l)=>{let o=n.children[l],s=!i(t,o),c=!i(t.text,o?.text),d=[r,l];if(s){if(t._key===o?._key){eA("Updating changed child",t,o),a.Transforms.setNodes(e,t,{at:d});let n=a.Text.isText(t)&&"span"===t._type&&a.Text.isText(o)&&"span"===o._type;n&&c?(a.Transforms.delete(e,{at:{focus:{path:d,offset:0},anchor:{path:d,offset:o.text.length}}}),a.Transforms.insertText(e,t.text,{at:d}),e.onChange()):n||(eA("Updating changed inline object child",t),a.Transforms.setNodes(e,{_key:P},{at:[...d,0],voids:!0}))}else o?(eA("Replacing child",t),a.Transforms.removeNodes(e,{at:[r,l]}),a.Transforms.insertNodes(e,t,{at:[r,l]}),e.onChange()):o||(eA("Inserting new child",t),a.Transforms.insertNodes(e,t,{at:[r,l]}),e.onChange())}})}}(h,t,s,o)):(eA.enabled&&eA("Replacing block",s,t),function(e,t,n){let r=e.selection,i=r&&r.focus.path[0]===n;i&&a.Transforms.deselect(e),a.Transforms.removeNodes(e,{at:[n]}),a.Transforms.insertNodes(e,t,{at:[n]}),e.onChange(),i&&a.Transforms.select(e,r)}(h,t,o)),u=!0):(l.next({type:"invalidValue",resolution:g.resolution,value:e}),f=!1)}if(!s&&f){let n=[e[o]],i=validateValue(n,c,r);
59eA.enabled&&eA("Validating and inserting new block in the end of the value",t),i.valid||i.resolution?.autoResolve?a.Transforms.insertNodes(h,t,{at:[o]}):(eA("Invalid",i),l.next({type:"invalidValue",resolution:i.resolution,value:e}),f=!1)}})})})})})}if(!f){eA("Invalid value, returning");return}if(u){eA("Server value changed, syncing editor");try{h.onChange()}catch(t){console.error(t),l.next({type:"invalidValue",resolution:null,value:e});return}g&&!h.selection&&(a.Transforms.select(h,{anchor:{path:[0,0],offset:0},focus:{path:[0,0],offset:0}}),h.onChange()),l.next({type:"value",value:e})}else eA("Server value and editor value is equal, no need to sync.");d.current=e};return u.current=updateFunction,updateFunction},[l,r,t,n,c,h,p])}({keyGenerator:n,onChange:d,portableTextEditor:t,readOnly:r}),p=(0,s.useSlate)();(0,o.useEffect)(()=>{A.set(p,!1)},[p]);let g=(0,o.useCallback)(()=>{if(u.current.length>0){eR("Flushing pending patches"),eB&&eR(`Patches: 60${JSON.stringify(u.current,null,2)}`);let e=c();l.next({type:"mutation",patches:u.current,snapshot:e}),u.current=[]}A.set(p,!1)},[p,c,l]),m=(0,o.useMemo)(()=>E(()=>{if(a.Editor.isNormalizing(p)){g();return}m()},1e3,{leading:!1,trailing:!0}),[g,p]);(0,o.useEffect)(()=>()=>{g()},[g]),(0,o.useEffect)(()=>{eR("Subscribing to editor changes$");let e=l.subscribe(e=>{"patch"===e.type&&(A.set(p,!0),u.current.push(e.patch),m()),d(e)});return()=>{eR("Unsubscribing to changes$"),e.unsubscribe()}},[l,d,m,p]);let y=(0,o.useCallback)(()=>{eR("Editor is online, syncing from props.value"),l.next({type:"connection",value:"online"}),f(h)},[l,f,h]),k=(0,o.useCallback)(()=>{eR("Editor is offline"),l.next({type:"connection",value:"offline"})},[l]);(0,o.useEffect)(()=>(t.props.patches$&&(window.addEventListener("online",y),window.addEventListener("offline",k)),()=>{t.props.patches$&&(window.removeEventListener("online",y),window.removeEventListener("offline",k))}));let b=(0,o.useRef)(!0);return(0,o.useEffect)(()=>{eR("Value from props changed, syncing new value"),f(h),b.current&&(l.next({type:"loading",isLoading:!1}),l.next({type:"ready"}),b.current=!1)},[l,f,h]),null}let eM=(0,o.createContext)(null),usePortableTextEditorSelection=()=>{let e=(0,o.useContext)(eM);if(void 0===e)throw Error("The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context.");return e},e$=debugWithName("component:PortableTextEditor:SelectionProvider"),eO=e$.enabled&&!1;function PortableTextEditorSelectionProvider(e){let{change$:t}=e,[n,i]=(0,o.useState)(null);return(0,o.useEffect)(()=>{e$("Subscribing to selection changes$");let e=t.subscribe(e=>{"selection"===e.type&&(0,o.startTransition)(()=>{eO&&e$("Setting selection"),i(e.selection)})});return()=>{e$("Unsubscribing to selection changes$"),e.unsubscribe()}},[t]),(0,r.jsx)(eM.Provider,{value:n,children:e.children})}let ej=debugWithName("component:PortableTextEditor");let PortableTextEditor=class PortableTextEditor extends o.Component{change$=new f.x;schemaTypes;editable;constructor(e){if(super(e),!e.schemaType)throw Error('PortableTextEditor: missing "schemaType" property');e.incomingPatches$&&console.warn("The prop 'incomingPatches$' is deprecated and renamed to 'patches$'"),this.change$.next({type:"loading",isLoading:!0}),this.schemaTypes=getPortableTextMemberSchemaTypes(e.schemaType.hasOwnProperty("jsonType")?e.schemaType:compileType(e.schemaType))}componentDidUpdate(e){this.props.schemaType!==e.schemaType&&(this.schemaTypes=getPortableTextMemberSchemaTypes(this.props.schemaType.hasOwnProperty("jsonType")?this.props.schemaType:compileType(this.props.schemaType))),this.props.editorRef!==e.editorRef&&this.props.editorRef&&(this.props.editorRef.current=this)}setEditable=e=>{this.editable={...this.editable,...e}};getValue=()=>{if(this.editable)return this.editable.getValue()};render(){let{onChange:e,value:t,children:n,patches$:i,incomingPatches$:l}=this.props,{change$:o}=this,a=typeof this.props.maxBlocks>"u"?void 0:parseInt(this.props.maxBlocks.toString(),10)||void 0,s=!!this.props.readOnly,c=this.props.keyGenerator||defaultKeyGenerator;return(0,r.jsx)(SlateContainer,{keyGenerator:c,maxBlocks:a,patches$:l||i,portableTextEditor:this,readOnly:s,children:(0,r.jsx)(eP.Provider,{value:c,children:(0,r.jsx)(F.Provider,{value:this,children:(0,r.jsx)(eC.Provider,{value:s,children:(0,r.jsxs)(PortableTextEditorSelectionProvider,{change$:o,children:[(0,r.jsx)(Synchronizer,{change$:o,getValue:this.getValue,onChange:e,value:t}),n]})})})})})}static activeAnnotations=e=>e&&e.editable?e.editable.activeAnnotations():[];static isAnnotationActive=(e,t)=>
60!!e&&!!e.editable&&e.editable.isAnnotationActive(t);static addAnnotation=(e,t,n)=>e.editable?.addAnnotation(t,n);static blur=e=>{ej("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=>{ej("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)=>(ej("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)=>{ej("Host setting selection",t),e.editable?.select(t)};static removeAnnotation=(e,t)=>e.editable?.removeAnnotation(t);static toggleBlockStyle=(e,t)=>(ej("Host is toggling block style"),e.editable?.toggleBlockStyle(t));static toggleList=(e,t)=>e.editable?.toggleList(t);static toggleMark=(e,t)=>{ej("Host toggling mark",t),e.editable?.toggleMark(t)};static getFragment=e=>(ej("Host getting fragment"),e.editable?.getFragment());static undo=e=>{ej("Host undoing"),e.editable?.undo()};static redo=e=>{ej("Host redoing"),e.editable?.redo()};static isSelectionsOverlapping=(e,t,n)=>e.editable?.isSelectionsOverlapping(t,n)};let eI=debugWithName("components:Leaf"),eL=[],Leaf=e=>{let{attributes:t,children:n,leaf:l,schemaTypes:c,renderChild:d,renderDecorator:h,renderAnnotation:f}=e,p=(0,o.useRef)(null),g=usePortableTextEditor(),m=(0,s.useSelected)(),[y,k]=(0,o.useState)(!1),[b,x]=(0,o.useState)(!1),v=n.props.parent,_=(0,o.useMemo)(()=>v?[{_key:v?._key},"children",{_key:l._key}]:[],[v,l._key]),E=(0,o.useMemo)(()=>c.decorators.map(e=>e.value),[c.decorators]),T=(0,o.useMemo)(()=>u((l.marks||eL).filter(e=>E.includes(e))),[E,l.marks]),S=Array.isArray(l.marks)?l.marks:eL,N=(0,o.useMemo)(()=>S.map(e=>!E.includes(e)&&v?.markDefs?.find(t=>t._key===e)).filter(Boolean),[S,v,E]),w=N.length>0&&m;(0,o.useEffect)(()=>{if(!w){k(!1);return}let e=PortableTextEditor.getSelection(g);e&&i(e.focus.path,_)&&PortableTextEditor.isCollapsedSelection(g)&&(0,o.startTransition)(()=>{k(!0)})},[w,_,g]);let P=(0,o.useCallback)(()=>{if(!w)return;eI("Setting selection and focus from range");let e=window.getSelection();if(!e){x(!1);return}if(e&&e.rangeCount>0){let t=e.getRangeAt(0);p.current&&t.intersectsNode(p.current)?x(!0):x(!1)}else x(!1)},[w]);(0,o.useEffect)(()=>{if(!w)return;let e=g.change$.subscribe(e=>{if("blur"===e.type){k(!1),x(!1);return}if("focus"===e.type){let e=PortableTextEditor.getSelection(g);e&&i(e.focus.path,_)&&PortableTextEditor.isCollapsedSelection(g)&&k(!0),P();return}"selection"===e.type&&(e.selection&&i(e.selection.focus.path,_)&&PortableTextEditor.isCollapsedSelection(g)?k(!0):k(!1),P())});return()=>{e.unsubscribe()}},[_,g,P,w]),(0,o.useEffect)(()=>P(),[P]);let C=(0,o.useMemo)(()=>{let e=n;if(a.Text.isText(l)&&l._type===c.span.name&&(T.forEach(t=>{let n=c.decorators.find(e=>e.value===t);if(n&&h){let r=Object.defineProperty({children:e,editorElementRef:p,focused:y,path:_,selected:b,schemaType:n,value:t},"type",{enumerable:!1,get:()=>(console.warn("Property 'type' is deprecated, use 'schemaType' instead."),n)});e=h(r)}}),v&&N.length>0&&N.forEach(t=>{let n=c.annotations.find(e=>e.name===t._type);if(n){if(f){let i=Object.defineProperty({block:v,children:e,editorElementRef:p,focused:y,path:_,selected:b,schemaType:n,value:t},"type",{enumerable:!1,get:()=>(console.warn("Property 'type' is deprecated, use 'schemaType' instead."),n)});e=(0,r.jsx)("span",{ref:p,children:f(i)})}else e=(0,r.jsx)(DefaultAnnotation,{annotation:t,children:(0,r.jsx)("span",{ref:p,children:e})})}}),v&&d)){let t=v.children.find(e=>e._key===l._key);if(t){let n=Object.defineProperty({annotations:N,children:(0,r.jsx)(r.Fragment,{children:e}),editorElementRef:p,focused:y,path:_,schemaType:c.span,selected:b,value:t},"type",{enumerable:!1,get:()=>(console.warn("Property 'type' is deprecated, use 'schemaType' instead."),c.span)});e=d(n)}}return e},[N,v,n,y,l,T,_,f,d,h,c.annotations,c.decorators,c.span,b]);return(0,o.useMemo)(()=>(0,r.jsx)("span",{...t,ref:p,children:C},l._key),[l,t,C])},eV=debugWithName("component:Editable"),ez={position:"absolute",userSelect:"none",pointerEvents:"none",left:0,right:0},eW=(0,o.forwardRef)(function(e,t){let{hotkeys:n,onBlur:c,onFocus:h,onBeforeInput:u,onPaste:f,onCopy:p,onClick:g,rangeDecorations:m,renderAnnotation:y,renderBlock:k,renderChild:b,renderDecorator:_,renderListItem:E,renderPlaceholder:T,renderStyle:S,selection:N,scrollSelectionIntoView:w,spellCheck:P,...C}=e,A=usePortableTextEditor(),D=usePortableTextEditorReadOnlyStatus(),R=usePortableTextEditorKeyGenerator(),B=(0,o.useRef)(null),[M,$]=(0,o.useState)(null),[O,j]=(0,o.useState)(!1),[I,L]=(0,o.useState)([]);(0,o.useImperativeHandle)(t,()=>B.current);let V=(0,o.useRef)(m),{change$:z,schemaTypes:W}
60=A,q=(0,s.useSlate)(),U=W.block.name,F=(0,o.useMemo)(()=>function(e){let t=W.block.name,n=W.span.name,r=W.block.options.unstable_whitespaceOnPasteMode,toPlainText=t=>t.map(t=>e.isTextBlock(t)?t.children.map(e=>e._type===n?e.text:`[${W.inlineObjects.find(t=>t.name===e._type)?.title||"Object"}]`).join(""):`[${W.blockObjects.find(e=>e.name===t._type)?.title||"Object"}]`).join(` 61 62`);return e.setFragmentData=(n,r)=>{let{selection:i}=e;if(!i)return;let[l,o]=a.Range.edges(i),c=a.Editor.void(e,{at:l.path}),d=a.Editor.void(e,{at:o.path});if(a.Range.isCollapsed(i)&&!c)return;let h=s.ReactEditor.toDOMRange(e,i),u=h.cloneContents();if(d){let[t]=d,n=h.cloneRange(),r=s.ReactEditor.toDOMNode(e,t);n.setEndAfter(r),u=n.cloneContents()}Array.from(u.querySelectorAll("[data-slate-zero-width]")).forEach(e=>{let t="n"===e.getAttribute("data-slate-zero-width");e.textContent=t?` 63`:""}),Array.from(u.querySelectorAll("*")).forEach(e=>{for(let t in e.removeAttribute("contentEditable"),e.removeAttribute("data-slate-inline"),e.removeAttribute("data-slate-leaf"),e.removeAttribute("data-slate-node"),e.removeAttribute("data-slate-spacer"),e.removeAttribute("data-slate-string"),e.removeAttribute("data-slate-zero-width"),e.removeAttribute("draggable"),e.attributes)e.hasAttribute(t)&&e.removeAttribute(t)});let f=u.ownerDocument.createElement("div");f.appendChild(u),f.setAttribute("hidden","true"),u.ownerDocument.body.appendChild(f);let p=f.innerHTML;u.ownerDocument.body.removeChild(f);let g=e.getFragment(),m=fromSlateValue(g,t),y=JSON.stringify(m),k=toPlainText(m);n.clearData(),n.setData("text/plain",k),n.setData("text/html",p),n.setData("application/json",y),n.setData("application/x-portable-text",y),eT("text",k),n.setData("application/x-portable-text-event-origin",r||"external"),eT("Set fragment data",y,p)},e.insertPortableTextData=t=>{if(!e.selection)return!1;let r=t.getData("application/x-portable-text"),i=t.getData("application/x-portable-text-event-origin");if(eT(`Inserting portable text from ${i} event`,r),r){let t=JSON.parse(r);if(Array.isArray(t)&&t.length>0){let r=toSlateValue(t,{schemaTypes:W}).map(t=>{let r={...t};if(e.isTextBlock(r)){let t=W.annotations.map(e=>e.name);if(0===t.length){let{markDefs:e,...t}=r;return{...t,_key:R()}}if((r.markDefs||[]).some(e=>!t.includes(e._type))){let e=(r.markDefs||[]).filter(e=>t.includes(e._type));return{...r,markDefs:e,_key:R()}}r.markDefs=(r.markDefs||[]).map(t=>{let i=t._key,l=R();return r.children=r.children.map(t=>t._type===n&&e.isTextSpan(t)?{...t,marks:t.marks&&t.marks.includes(i)?[...t.marks].filter(e=>e!==i).concat(l):t.marks}:t),{...t,_key:l}})}let i={...r,_key:R()};return e.isTextBlock(i)&&(i.children=i.children.map(e=>({...e,_key:R()}))),i}),i=validateValue(t,W,R);if(!i.valid&&!i.resolution?.autoResolve){let e=`${i.resolution?.description}`;return z.next({type:"error",level:"warning",name:"pasteError",description:e,data:i}),eT("Invalid insert result",i),!1}return _insertFragment(e,r,W),!0}}return!1},e.insertTextOrHTMLData=n=>{if(!e.selection)return eT("No selection, not inserting"),!1;z.next({type:"loading",isLoading:!0});let i=n.getData("text/html"),l=n.getData("text/plain");if(i||l){let o,a,s;if(eT("Inserting data",n),i){if(a=toSlateValue(o=(0,v.zW)(i,W.portableText,{unstable_whitespaceOnPasteMode:r}).map(e=>(0,v.nX)(e,{blockTypeName:t})),{schemaTypes:W}),s="HTML",0===o.length)return!1}else{let e=`<html><body>${String(l).replace(/[&<>"'`=/]/g,e=>eS[e]).split(/\n{2,}/).map(e=>e?`<p>${e.replace(/(?:\r\n|\r|\n)/g,"<br/>")}</p>`:"<p></p>").join("")}</body></html>`;a=toSlateValue(o=(0,v.zW)(e,W.portableText).map(e=>(0,v.nX)(e,{blockTypeName:t})),{schemaTypes:W}),s="text"}let c=validateValue(o,W,R);if(!c.valid){let e=`Could not validate the resulting portable text to insert. 64${c.resolution?.description} 65Try to insert as plain text (shift-paste) instead.`;return z.next({type:"error",level:"warning",name:"pasteError",description:e,data:c}),eT("Invalid insert result",c),!1}return eT(`Inserting ${s} fragment at ${JSON.stringify(e.selection)}`),_insertFragment(e,a,W),z.next({type:"loading",isLoading:!1}),!0}return z.next({type:"loading",isLoading:!1}),!1},e.insertData=t=>{e.insertPortableTextData(t)||e.insertTextOrHTMLData(t)},e.insertFragmentData=t=>{let n=t.getData("application/x-portable-text");if(n){let t=JSON.parse(n);return e.insertFragment(t),!0}return!1},e},[z,R,W]),J=(0,o.useMemo)(()=>(function(e,t,n){let r=["enter","tab","shift","delete","end"],i=n||eE;return function(n){return n.pteWithHotKeys=l=>
65{Object.keys(i).forEach(e=>{if("marks"===e)for(let t in i[e]){if(r.includes(t))throw Error(`The hotkey ${t} is reserved!`);if((0,x.P6)(t,l.nativeEvent)){l.preventDefault();let r=i[e];if(r){let e=r[t];e_(`HotKey ${t} to toggle ${e}`),n.pteToggleMark(e)}}}if("custom"===e)for(let n in i[e]){if(r.includes(n))throw Error(`The hotkey ${n} is reserved!`);if((0,x.P6)(n,l.nativeEvent)){let r=i[e];if(r){let e=r[n];e(l,t)}}}});let o=(0,x.P6)("enter",l.nativeEvent),s=(0,x.P6)("tab",l.nativeEvent),c=(0,x.P6)("shift+enter",l.nativeEvent),h=(0,x.P6)("shift+tab",l.nativeEvent),u=(0,x.P6)("backspace",l.nativeEvent),f=(0,x.P6)("delete",l.nativeEvent),p=(0,x.P6)("down",l.nativeEvent),g=(0,x.P6)("up",l.nativeEvent);if(p&&n.selection){let e=a.Node.descendant(n,n.selection.focus.path.slice(0,1));if(e&&a.Editor.isVoid(n,e)){let e=a.Path.next(n.selection.focus.path.slice(0,1));if(!a.Node.has(n,e)){a.Transforms.insertNodes(n,n.pteCreateEmptyBlock(),{at:e}),n.onChange();return}}}if(g&&n.selection){let e=0===n.selection.focus.path[0],t=a.Node.descendant(n,n.selection.focus.path.slice(0,1));if(e&&t&&a.Editor.isVoid(n,t)){a.Transforms.insertNodes(n,n.pteCreateEmptyBlock(),{at:[0]}),a.Transforms.select(n,{path:[0,0],offset:0}),n.onChange();return}}if(u&&n.selection&&0===n.selection.focus.path[0]&&a.Range.isCollapsed(n.selection)){let e=a.Node.descendant(n,n.selection.focus.path.slice(0,1)),t=a.Path.next(n.selection.focus.path.slice(0,1)),r=a.Node.has(n,t),i=(0,d.DG)(e),o=i&&1===e.children.length&&e.children?.[0]?.text==="";if(r&&i&&o){l.preventDefault(),l.stopPropagation(),a.Transforms.removeNodes(n,{match:t=>t===e}),n.onChange();return}}if(u&&n.selection&&n.selection.focus.path[0]>0&&a.Range.isCollapsed(n.selection)){let e=a.Path.previous(n.selection.focus.path.slice(0,1)),t=a.Node.descendant(n,e),r=a.Node.descendant(n,n.selection.focus.path.slice(0,1));if(t&&r&&a.Editor.isVoid(n,t)&&0===n.selection.focus.offset){e_("Preventing deleting void block above"),l.preventDefault(),l.stopPropagation();let t=(0,d.DG)(r),i=t&&1===r.children.length&&r.children?.[0]?.text==="";if(!t||i){a.Transforms.removeNodes(n,{match:e=>e===r}),a.Transforms.select(n,e),n.onChange();return}t&&!i&&(a.Transforms.select(n,e),n.onChange());return}}if(f&&n.selection&&0===n.selection.focus.offset&&a.Range.isCollapsed(n.selection)&&n.children[n.selection.focus.path[0]+1]){let e=a.Node.descendant(n,a.Path.next(n.selection.focus.path.slice(0,1))),t=n.selection.focus.path.slice(0,1),r=a.Node.descendant(n,t),i=(0,d.DG)(r)&&1===r.children.length&&r.children?.[0]?.text==="";if(e&&r&&!a.Editor.isVoid(n,r)&&a.Editor.isVoid(n,e)&&i){e_("Preventing deleting void block below"),l.preventDefault(),l.stopPropagation(),a.Transforms.removeNodes(n,{match:e=>e===r}),a.Transforms.select(n,t),n.onChange();return}}if((s||h)&&n.selection){let[e]=a.Editor.node(n,n.selection.focus,{depth:2}),[t]=(0,d.NG)(e)?a.Editor.node(n,n.selection.focus,{depth:1}):[],r=e&&(0,d.DG)(t)&&(0,d.NG)(e)&&(e.marks||[]).filter(e=>(t.markDefs||[]).map(e=>e._key).includes(e)).length>0,[i]=a.Range.edges(n.selection),o=a.Editor.isStart(n,i,i.path);e&&(0,d.NG)(e)&&(!r||o)&&n.pteIncrementBlockLevels(h)&&l.preventDefault()}if(o&&!c&&n.selection){let t=n.selection.focus.path.slice(0,1),r=a.Node.descendant(n,t);if(n.isListBlock(r)){n.pteEndList()&&l.preventDefault();return}if(n.isTextBlock(r)&&r.style&&r.style!==e.styles[0].value){let[,e]=a.Range.edges(n.selection);if(a.Editor.isEnd(n,e,e.path)){a.Editor.insertNode(n,n.pteCreateEmptyBlock()),l.preventDefault(),n.onChange();return}}if(r&&a.Editor.isVoid(n,r)){a.Editor.insertNode(n,n.pteCreateEmptyBlock()),l.preventDefault(),n.onChange();return}l.preventDefault(),n.insertBreak(),n.onChange()}if(c){l.preventDefault(),n.insertText(` 66`);return}
66if((0,x.P6)("mod+z",l.nativeEvent)){l.preventDefault(),n.undo();return}((0,x.P6)("mod+y",l.nativeEvent)||(0,x.P6)("mod+shift+z",l.nativeEvent))&&(l.preventDefault(),n.redo())},n}})(W,A,n),[n,A,W]);(0,o.useMemo)(()=>D?(eV("Editable is in read only mode"),F(q)):(eV("Editable is in edit mode"),F(J(q))),[D,q,J,F]);let H=(0,o.useCallback)(e=>(0,r.jsx)(Element,{...e,readOnly:D,renderBlock:k,renderChild:b,renderListItem:E,renderStyle:S,schemaTypes:W,spellCheck:P}),[W,P,D,k,b,E,S]),K=(0,o.useCallback)(e=>{if("span"===e.leaf._type){let t=(0,r.jsx)(Leaf,{...e,schemaTypes:W,renderAnnotation:y,renderChild:b,renderDecorator:_,readOnly:D});if(T&&e.leaf.placeholder&&""===e.text.text)return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{style:ez,contentEditable:!1,children:T()}),t]});let n=e.leaf.rangeDecoration;return n&&(t=n.component({children:t})),t}return e.children},[D,y,b,_,T,W]),G=(0,o.useCallback)(()=>{if(N){eV(`Selection from props ${JSON.stringify(N)}`);let e=function(e,t){if(!e||!t||0===t.length)return null;let n=null,r=null,{anchor:l,focus:o}=e;return l&&t.find(e=>i({_key:e._key},l.path[0]))&&(n=normalizePoint(l,t)),o&&t.find(e=>i({_key:e._key},o.path[0]))&&(r=normalizePoint(o,t)),n&&r?{anchor:n,focus:r,backward:e.backward}:null}(N,fromSlateValue(q.children,U));if(null!==e){eV(`Normalized selection from props ${JSON.stringify(e)}`);let t=toSlateRange(e,q);t&&(a.Transforms.select(q,t),q.operations.some(e=>"set_selection"===e.type)||z.next({type:"selection",selection:e}),q.onChange())}}},[N,q,U,z]),X=(0,o.useCallback)(e=>{if(m&&m.length>0){let t=[];if(m.forEach(n=>{let r;let i=toSlateRange(n.selection,q);if(!a.Range.isRange(i)){n.onMoved&&n.onMoved({newSelection:null,rangeDecoration:n,origin:"local"});return}if(e&&((r=function(e,t){let n=a.Point.transform(e.anchor,t),r=a.Point.transform(e.focus,t);return null===n||null===r?null:a.Point.equals(n,e.anchor)&&a.Point.equals(r,e.focus)?e:{anchor:n,focus:r}}(i,e))&&r!==i||null===r&&i)){let e=PortableTextEditor.getValue(A),t=toPortableTextRange(e,r,W);n.onMoved&&n.onMoved({newSelection:t,rangeDecoration:n,origin:"local"})}null!==r&&t.push({...r||i,rangeDecoration:n})}),t.length>0){L(t);return}}L([])},[A,m,W,q]);(0,o.useEffect)(()=>{let e=z.subscribe(e=>{switch(e.type){case"ready":G();break;case"invalidValue":j(!0);break;case"value":j(!1)}});return()=>{e.unsubscribe()}},[z,G]),(0,o.useEffect)(()=>{N&&!O&&G()},[O,N,G]);let Y=(0,o.useMemo)(()=>q.apply,[q]),[Z,Q]=(0,o.useState)(!1);(0,o.useEffect)(()=>{Z||(Q(!0),X())},[X,Z]),(0,o.useEffect)(()=>{i(m,V.current)||X(),V.current=m},[m,X]),(0,o.useEffect)(()=>(q.apply=e=>{Y(e),"set_selection"!==e.type&&X(e)},()=>{q.apply=Y}),[Y,q,X]);let ee=(0,o.useCallback)(e=>{p&&void 0!==p(e)&&e.preventDefault()},[p]),et=(0,o.useCallback)(e=>{if(e.preventDefault(),!q.selection)return;if(!f){eV("Pasting normally"),q.insertData(e.clipboardData);return}let t=PortableTextEditor.getValue(A),n=toPortableTextRange(t,q.selection,W)?.focus.path||[],r=f({event:e,value:t,path:n,schemaTypes:W});void 0===r?(eV("No result from custom paste handler, pasting normally"),q.insertData(e.clipboardData)):(z.next({type:"loading",isLoading:!0}),Promise.resolve(r).then(t=>{eV("Custom paste function from client resolved",t),t&&t.insert?t.insert?q.insertFragment(toSlateValue(t.insert,{schemaTypes:W})):console.warn("Your onPaste function returned something unexpected:",t):(eV("No result from custom paste handler, pasting normally"),q.insertData(e.clipboardData))}).catch(e=>(console.error(e),e)).finally(()=>{z.next({type:"loading",isLoading:!1})}))},[z,f,A,W,q]),en=(0,o.useCallback)(e=>{if(h&&h(e),!e.isDefaultPrevented()){let t=PortableTextEditor.getSelection(A);null===t&&(a.Transforms.select(q,a.Editor.start(q,[])),q.onChange()),z.next({type:"focus",event:e});let n=PortableTextEditor.getSelection(A);t===n&&z.next({type:"selection",selection:t})}},[h,A,z,q]),er=(0,o.useCallback)(e=>{if(g&&g(e),q.selection&&e.target===e.currentTarget){let[e,t]=a.Node.last(q,[]),n=q.selection.focus.path.slice(0,1),r=t.slice(0,1);if(a.Path.equals(n,r)){let n=a.Node.descendant(q,t.slice(0,1));e&&a.Editor.isVoid(q,n)&&(a.Transforms.insertNodes(q,q.pteCreateEmptyBlock()),q.onChange())}}},[g,q]),ei=(0,o.useCallback)(e=>{c&&c(e),e.isPropagationStopped()||z.next({type:"blur",event:e})},[z,c]),el=(0,o.useCallback)(e=>{u&&u(e)},[u]),eo=(0,o.useCallback)(()=>
66{if(!q.selection)return;let e=s.ReactEditor.findDocumentOrShadowRoot(q),{activeElement:t}=e;if(B.current!==t)return;let n=s.ReactEditor.getWindow(q).getSelection();if(!n||0===n.rangeCount)return;let r=n.getRangeAt(0);try{let e=s.ReactEditor.toDOMRange(q,q.selection);(e.startOffset!==r.startOffset||e.endOffset!==r.endOffset)&&(eV("DOM range out of sync, validating selection"),n?.removeAllRanges(),n.addRange(e))}catch{eV("Could not resolve selection, selecting top document"),a.Transforms.deselect(q),q.children.length>0&&a.Transforms.select(q,[0,0]),q.onChange()}},[B,q]);(0,o.useEffect)(()=>{if(M){let e=new MutationObserver(eo);return e.observe(M,{attributeOldValue:!1,attributes:!1,characterData:!1,childList:!0,subtree:!0}),()=>{e.disconnect()}}},[eo,M]);let ea=(0,o.useCallback)(t=>{e.onKeyDown&&e.onKeyDown(t),t.isDefaultPrevented()||q.pteWithHotKeys(t)},[e,q]),es=(0,o.useMemo)(()=>{if(void 0!==w)return null===w?l:(e,t)=>{w(A,t)}},[A,w]),ec=(0,o.useCallback)(([,e])=>{if(isEqualToEmptyEditor(q.children,W))return[{anchor:{path:[0,0],offset:0},focus:{path:[0,0],offset:0},placeholder:!0}];if(0===e.length)return[];let t=I.filter(t=>a.Range.isCollapsed(t)?2===e.length&&a.Path.equals(t.focus.path,e)&&a.Path.equals(t.anchor.path,e):a.Range.intersection(t,{anchor:{path:e,offset:0},focus:{path:e,offset:0}})||a.Range.includes(t,e));return t.length>0?t:[]},[q,W,I]);return(0,o.useEffect)(()=>{B.current=s.ReactEditor.toDOMNode(q,q),$(B.current)},[q,B]),A?O?null:(0,r.jsx)(s.Editable,{...C,autoFocus:!1,className:C.className||"pt-editable",decorate:ec,onBlur:ei,onCopy:ee,onClick:er,onDOMBeforeInput:el,onFocus:en,onKeyDown:ea,onPaste:et,readOnly:D,renderPlaceholder:void 0,renderElement:H,renderLeaf:K,scrollSelectionIntoView:es}):null})}}]);
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.