(self.webpackChunksubstack=self.webpackChunksubstack||[]).push([["6890"],{8400:function(e,t,n){var r=n(14259),o=n(16612),i=n(40554),l=Math.ceil,s=Math.max;e.exports=function(e,t,n){t=(n?o(e,t,n):void 0===t)?1:s(i(t),0);var d=null==e?0:e.length;if(!d||t<1)return[];for(var c=0,a=0,p=Array(l(d/t));cv,NM:()=>u,T5:()=>w,fW:()=>g,jE:()=>a,kg:()=>d,ms:()=>y});var r=n(36779),o=n(98661),i=n(88897);let l=({renderers:e})=>o.default.createElement(o.default.Fragment,null,Object.entries(e).map(([e,t])=>o.default.createPortal(t.reactElement,t.element,e)));class s extends o.default.Component{constructor(e){super(e),this.editorContentRef=o.default.createRef(),this.initialized=!1,this.state={renderers:{}}}componentDidMount(){this.init()}componentDidUpdate(){this.init()}init(){let{editor:e}=this.props;if(e&&e.options.element){if(e.contentComponent)return;let t=this.editorContentRef.current;t.append(...e.options.element.childNodes),e.setOptions({element:t}),e.contentComponent=this,e.createNodeViews(),this.initialized=!0}}maybeFlushSync(e){this.initialized?(0,o.flushSync)(e):e()}setRenderer(e,t){this.maybeFlushSync(()=>{this.setState(({renderers:n})=>({renderers:{...n,[e]:t}}))})}removeRenderer(e){this.maybeFlushSync(()=>{this.setState(({renderers:t})=>{let n={...t};return delete n[e],{renderers:n}})})}componentWillUnmount(){let{editor:e}=this.props;if(!e||(this.initialized=!1,e.isDestroyed||e.view.setProps({nodeViews:{}}),e.contentComponent=null,!e.options.element.firstChild))return;let t=document.createElement("div");t.append(...e.options.element.childNodes),e.setOptions({element:t})}render(){let{editor:e,...t}=this.props;return o.default.createElement(o.default.Fragment,null,o.default.createElement("div",{ref:this.editorContentRef,...t}),o.default.createElement(l,{renderers:this.state.renderers}))}}let d=o.default.memo(e=>{let t=o.default.useMemo(()=>Math.floor(0xffffffff*Math.random()).toString(),[e.editor]);return o.default.createElement(s,{key:t,...e})});class c extends i.ML{constructor(){super(...arguments),this.contentComponent=null}}let a=(e={},t=[])=>{let[n,r]=(0,o.useState)(null),i=function(){let[,e]=(0,o.useState)(0);return()=>e(e=>e+1)}(),{onBeforeCreate:l,onBlur:s,onCreate:d,onDestroy:a,onFocus:p,onSelectionUpdate:f,onTransaction:u,onUpdate:h}=e,m=(0,o.useRef)(l),y=(0,o.useRef)(s),w=(0,o.useRef)(d),v=(0,o.useRef)(a),b=(0,o.useRef)(p),g=(0,o.useRef)(f),C=(0,o.useRef)(u),x=(0,o.useRef)(h);return(0,o.useEffect)(()=>{n&&(l&&(n.off("beforeCreate",m.current),n.on("beforeCreate",l),m.current=l),s&&(n.off("blur",y.current),n.on("blur",s),y.current=s),d&&(n.off("create",w.current),n.on("create",d),w.current=d),a&&(n.off("destroy",v.current),n.on("destroy",a),v.current=a),p&&(n.off("focus",b.current),n.on("focus",p),b.current=p),f&&(n.off("selectionUpdate",g.current),n.on("selectionUpdate",f),g.current=f),u&&(n.off("transaction",C.current),n.on("transaction",u),C.current=u),h&&(n.off("update",x.current),n.on("update",h),x.current=h))},[l,s,d,a,p,f,u,h,n]),(0,o.useEffect)(()=>{let t=!0,n=new c(e);return r(n),n.on("transaction",()=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{t&&i()})})}),()=>{t=!1}},t),(0,o.useEffect)(()=>()=>{null==n||n.destroy()},[n]),n},p=(0,o.createContext)({editor:null});p.Consumer;let f=()=>(0,o.useContext)(p),u=e=>{let[t,n]=(0,o.useState)(null),{editor:i}=f();return(0,o.useEffect)(()=>{var n;if(!t||(null===(n=e.editor)||void 0===n?void 0:n.isDestroyed)||(null==i?void 0:i.isDestroyed))return;let{pluginKey:o="bubbleMenu",editor:l,tippyOptions:s={},updateDelay:d,shouldShow:c=null}=e,a=l||i;if(!a){console.warn("BubbleMenu component is not rendered inside of an editor component or does not have editor prop.");return}let p=(0,r.q3)({updateDelay:d,editor:a,element:t,pluginKey:o,shouldShow:c,tippyOptions:s});return a.registerPlugin(p),()=>a.unregisterPlugin(o)},[e.editor,i,t]),o.default.createElement("div",{ref:n,className:e.className,style:{visibility:"hidden"}},e.children)},h=(0,o.createContext)({onDragStart:void 0}),m=()=>(0,o.useContext)(h),y=e=>{let t=e.as||"div",{nodeViewContentRef:n}=m();return o.default.createElement(t,{...e,ref:n,"data-node-view-content":"",style:{whiteSpace:"pre-wrap",...e.style}})},w=o.default.forwardRef((e,t)=>{let{onDragStart:n}=m(),r=e.as||"div";return o.default.createElement(r,{...e,ref:t,"data-node-view-wrapper":"",onDragStart:n,style:{whiteSpace:"normal",...e.style}})});class v{constructor(e,{editor:t,props:n={},as:r="div",className:o="",attrs:i}){this.ref=null,this.id=Math.floor(0xffffffff*Math.random()).toString(),this.component=e,this.editor=t,this.props=n,this.element=document.createElement(r),this.element.classList.add("react-renderer"),o&&this.element.classList.add(...o.split(" ")),i&&Object.keys(i).forEach(e=>{this.element.setAttribute(e,i[e])}),this.render()}render(){var e,t,n;let r=this.component,i=this.props;("function"==typeof r&&r.prototype&&r.prototype.isReactComponent||"object"==typeof r&&(null===(n=r.$$typeof)||void 0===n?void 0:n.toString())==="Symbol(react.forward_ref)")&&(i.ref=e=>{this.ref=e}),this.reactElement=o.default.createElement(r,{...i}),null===(t=null===(e=this.editor)||void 0===e?void 0:e.contentComponent)||void 0===t||t.setRenderer(this.id,this)}updateProps(e={}){this.props={...this.props,...e},this.render()}destroy(){var e,t;null===(t=null===(e=this.editor)||void 0===e?void 0:e.contentComponent)||void 0===t||t.removeRenderer(this.id)}}class b extends i.DK{mount(){let e={editor:this.editor,node:this.node,decorations:this.decorations,selected:!1,extension:this.extension,getPos:()=>this.getPos(),updateAttributes:(e={})=>this.updateAttributes(e),deleteNode:()=>this.deleteNode()};if(!this.component.displayName){let e;this.component.displayName=(e=this.extension.name).charAt(0).toUpperCase()+e.substring(1)}let t=e=>{let t=this.component,n=this.onDragStart.bind(this);return o.default.createElement(o.default.Fragment,null,o.default.createElement(h.Provider,{value:{onDragStart:n,nodeViewContentRef:e=>{e&&this.contentDOMElement&&e.firstChild!==this.contentDOMElement&&e.appendChild(this.contentDOMElement)}}},o.default.createElement(t,{...e})))};t.displayName="ReactNodeView",this.contentDOMElement=this.node.isLeaf?null:document.createElement(this.node.isInline?"span":"div"),this.contentDOMElement&&(this.contentDOMElement.style.whiteSpace="inherit");let n=this.node.isInline?"span":"div";this.options.as&&(n=this.options.as);let{className:r=""}=this.options;this.handleSelectionUpdate=this.handleSelectionUpdate.bind(this),this.editor.on("selectionUpdate",this.handleSelectionUpdate),this.renderer=new v(t,{editor:this.editor,props:e,as:n,className:`node-${this.node.type.name} ${r}`.trim(),attrs:this.options.attrs})}get dom(){var e;if(this.renderer.element.firstElementChild&&!(null===(e=this.renderer.element.firstElementChild)||void 0===e?void 0:e.hasAttribute("data-node-view-wrapper")))throw Error("Please use the NodeViewWrapper component for your node view.");return this.renderer.element}get contentDOM(){return this.node.isLeaf?null:this.contentDOMElement}handleSelectionUpdate(){let{from:e,to:t}=this.editor.state.selection;e<=this.getPos()&&t>=this.getPos()+this.node.nodeSize?this.selectNode():this.deselectNode()}update(e,t){let n=e=>{this.renderer.updateProps(e)};if(e.type!==this.node.type)return!1;if("function"==typeof this.options.update){let r=this.node,o=this.decorations;return this.node=e,this.decorations=t,this.options.update({oldNode:r,oldDecorations:o,newNode:e,newDecorations:t,updateProps:()=>n({node:e,decorations:t})})}return e===this.node&&this.decorations===t||(this.node=e,this.decorations=t,n({node:e,decorations:t}),!0)}selectNode(){this.renderer.updateProps({selected:!0}),this.renderer.element.classList.add("ProseMirror-selectednode")}deselectNode(){this.renderer.updateProps({selected:!1}),this.renderer.element.classList.remove("ProseMirror-selectednode")}destroy(){this.renderer.destroy(),this.editor.off("selectionUpdate",this.handleSelectionUpdate),this.contentDOMElement=null}}function g(e,t){return n=>n.editor.contentComponent?new b(e,n,t):{}}},21834:function(e,t,n){"use strict";n.d(t,{Ig:()=>m,MI:()=>h,N0:()=>x,NE:()=>l,QK:()=>w,U9:()=>M,X0:()=>C,Y_:()=>p,_M:()=>c,al:()=>s,mD:()=>g,nw:()=>I,o:()=>f,uJ:()=>E,uo:()=>b,xb:()=>y,ym:()=>R});var r=n(83311),o=n(76405),i=n(92007);let l=(e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0),s=(e,t,n)=>{let l=function(e,t){let{$cursor:n}=e.selection;return n&&(t?t.endOfTextblock("backward",e):!(n.parentOffset>0))?n:null}(e,n);if(!l)return!1;let s=a(l);if(!s){let n=l.blockRange(),o=n&&(0,r.k9)(n);return null!=o&&(t&&t(e.tr.lift(n,o).scrollIntoView()),!0)}let c=s.nodeBefore;if(!c.type.spec.isolating&&S(e,s,t))return!0;if(0==l.parent.content.size&&(d(c,"end")||i.qv.isSelectable(c))){let n=(0,r.dR)(e.doc,l.before(),l.after(),o.p2.empty);if(n&&n.slice.size{let{$head:r,empty:o}=e.selection,l=r;if(!o)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",e):r.parentOffset>0)return!1;l=a(r)}let s=l&&l.nodeBefore;return!!(s&&i.qv.isSelectable(s))&&(t&&t(e.tr.setSelection(i.qv.create(e.doc,l.pos-s.nodeSize)).scrollIntoView()),!0)};function a(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){if(e.index(t)>0)return e.doc.resolve(e.before(t+1));if(e.node(t).type.spec.isolating)break}return null}let p=(e,t,n)=>{let l=function(e,t){let{$cursor:n}=e.selection;return n&&(t?t.endOfTextblock("forward",e):!(n.parentOffset{let{$head:r,empty:o}=e.selection,l=r;if(!o)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",e):r.parentOffset=0;t--){let n=e.node(t);if(e.index(t)+1{let n=e.selection,o=n instanceof i.qv,l;if(o){if(n.node.isTextblock||!(0,r.Mn)(e.doc,n.from))return!1;l=n.from}else if(null==(l=(0,r.GJ)(e.doc,n.from,-1)))return!1;if(t){let n=e.tr.join(l);o&&n.setSelection(i.qv.create(n.doc,l-e.doc.resolve(l).nodeBefore.nodeSize)),t(n.scrollIntoView())}return!0},m=(e,t)=>{let n=e.selection,o;if(n instanceof i.qv){if(n.node.isTextblock||!(0,r.Mn)(e.doc,n.to))return!1;o=n.to}else if(null==(o=(0,r.GJ)(e.doc,n.to,1)))return!1;return t&&t(e.tr.join(o).scrollIntoView()),!0},y=(e,t)=>{let{$from:n,$to:o}=e.selection,i=n.blockRange(o),l=i&&(0,r.k9)(i);return null!=l&&(t&&t(e.tr.lift(i,l).scrollIntoView()),!0)},w=(e,t)=>{let{$head:n,$anchor:r}=e.selection;return!!(n.parent.type.spec.code&&n.sameParent(r))&&(t&&t(e.tr.insertText("\n").scrollIntoView()),!0)};function v(e){for(let t=0;t{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let o=n.node(-1),l=n.indexAfter(-1),s=v(o.contentMatchAt(l));if(!s||!o.canReplaceWith(l,l,s))return!1;if(t){let r=n.after(),o=e.tr.replaceWith(r,r,s.createAndFill());o.setSelection(i.Y1.near(o.doc.resolve(r),1)),t(o.scrollIntoView())}return!0},g=(e,t)=>{let n=e.selection,{$from:r,$to:o}=n;if(n instanceof i.C1||r.parent.inlineContent||o.parent.inlineContent)return!1;let l=v(o.parent.contentMatchAt(o.indexAfter()));if(!l||!l.isTextblock)return!1;if(t){let n=(!r.parentOffset&&o.index(){let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let o=n.before();if((0,r.Ax)(e.doc,o))return t&&t(e.tr.split(o).scrollIntoView()),!0}let o=n.blockRange(),i=o&&(0,r.k9)(o);return null!=i&&(t&&t(e.tr.lift(o,i).scrollIntoView()),!0)},x=(e,t)=>{let{$from:n,to:r}=e.selection,o,l=n.sharedDepth(r);return 0!=l&&(o=n.before(l),t&&t(e.tr.setSelection(i.qv.create(e.doc,o))),!0)};function S(e,t,n){let l,s,c,a=t.nodeBefore,p=t.nodeAfter,f,u;if(a.type.spec.isolating||p.type.spec.isolating)return!1;if(l=t.nodeBefore,s=t.nodeAfter,c=t.index(),l&&s&&l.type.compatibleContent(s.type)&&(!l.content.size&&t.parent.canReplace(c-1,c)?(n&&n(e.tr.delete(t.pos-l.nodeSize,t.pos).scrollIntoView()),!0):!!(t.parent.canReplace(c,c+1)&&(s.isTextblock||(0,r.Mn)(e.doc,t.pos)))&&(n&&n(e.tr.clearIncompatible(t.pos,l.type,l.contentMatchAt(l.childCount)).join(t.pos).scrollIntoView()),!0)))return!0;let h=t.parent.canReplace(t.index(),t.index()+1);if(h&&(f=(u=a.contentMatchAt(a.childCount)).findWrapping(p.type))&&u.matchType(f[0]||p.type).validEnd){if(n){let i=t.pos+p.nodeSize,l=o.HY.empty;for(let e=f.length-1;e>=0;e--)l=o.HY.from(f[e].create(null,l));l=o.HY.from(a.copy(l));let s=e.tr.step(new r.FC(t.pos-1,i,t.pos,i,new o.p2(l,1,0),f.length,!0)),d=i+2*f.length;(0,r.Mn)(s.doc,d)&&s.join(d),n(s.scrollIntoView())}return!0}let m=i.Y1.findFrom(t,1),y=m&&m.$from.blockRange(m.$to),w=y&&(0,r.k9)(y);if(null!=w&&w>=t.depth)return n&&n(e.tr.lift(y,w).scrollIntoView()),!0;if(h&&d(p,"start",!0)&&d(a,"end")){let i=a,l=[];for(;l.push(i),!i.isTextblock;)i=i.lastChild;let s=p,d=1;for(;!s.isTextblock;s=s.firstChild)d++;if(i.canReplace(i.childCount,i.childCount,s.content)){if(n){let i=o.HY.empty;for(let e=l.length-1;e>=0;e--)i=o.HY.from(l[e].copy(i));n(e.tr.step(new r.FC(t.pos-l.length,t.pos+p.nodeSize,t.pos+d,t.pos+p.nodeSize-d,new o.p2(i,l.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function k(e){return function(t,n){let r=t.selection,o=e<0?r.$from:r.$to,l=o.depth;for(;o.node(l).isInline;){if(!l)return!1;l--}return!!o.node(l).isTextblock&&(n&&n(t.tr.setSelection(i.Bs.create(t.doc,e<0?o.start(l):o.end(l)))),!0)}}let M=k(-1),I=k(1);function R(e,t=null){return function(n,o){let{$from:i,$to:l}=n.selection,s=i.blockRange(l),d=s&&(0,r.nd)(s,e,t);return!!d&&(o&&o(n.tr.wrap(s,d).scrollIntoView()),!0)}}function E(e,t=null){return function(n,r){let o=!1;for(let r=0;r{if(o)return!1;if(!(!r.isTextblock||r.hasMarkup(e,t))){if(r.type==e)o=!0;else{let t=n.doc.resolve(i),r=t.index();o=t.parent.canReplaceWith(r,r+1,e)}}})}if(!o)return!1;if(r){let o=n.tr;for(let r=0;r{let{$from:n,$to:o}=e.selection;if(e.selection instanceof i.qv&&e.selection.node.isBlock)return!!(n.parentOffset&&(0,r.Ax)(e.doc,n.pos))&&(t&&t(e.tr.split(n.pos).scrollIntoView()),!0);if(!n.parent.isBlock)return!1;if(t){let l=o.parentOffset==o.parent.content.size,s=e.tr;(e.selection instanceof i.Bs||e.selection instanceof i.C1)&&s.deleteSelection();let d=0==n.depth?null:v(n.node(-1).contentMatchAt(n.indexAfter(-1))),c,a=c?[c]:l&&d?[{type:d}]:void 0,p=(0,r.Ax)(s.doc,s.mapping.map(n.pos),1,a);if(!a&&!p&&(0,r.Ax)(s.doc,s.mapping.map(n.pos),1,d?[{type:d}]:void 0)&&(d&&(a=[{type:d}]),p=!0),p&&(s.split(s.mapping.map(n.pos),1,a),!l&&!n.parentOffset&&n.parent.type!=d)){let e=s.mapping.map(n.before()),t=s.doc.resolve(e);d&&n.node(-1).canReplaceWith(t.index(),t.index()+1,d)&&s.setNodeMarkup(s.mapping.map(n.before()),d)}t(s.scrollIntoView())}return!0}),"Mod-Enter":b,Backspace:V,"Mod-Backspace":V,"Shift-Backspace":V,Delete:D,"Mod-Delete":D,"Mod-a":(e,t)=>(t&&t(e.tr.setSelection(new i.C1(e.doc))),!0)},O={"Ctrl-h":z.Backspace,"Alt-Backspace":z["Mod-Backspace"],"Ctrl-d":z.Delete,"Ctrl-Alt-Backspace":z["Mod-Delete"],"Alt-Delete":z["Mod-Delete"],"Alt-d":z["Mod-Delete"],"Ctrl-a":M,"Ctrl-e":I};for(let e in z)O[e]=z[e];"undefined"!=typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):"undefined"!=typeof os&&os.platform&&os.platform()},18923:function(e,t,n){"use strict";n.d(t,{IB:()=>l,KI:()=>i,bw:()=>s});var r=n(83311),o=n(76405);function i(e,t=null){return function(n,i){let{$from:l,$to:s}=n.selection,d=l.blockRange(s),c=!1,a=d;if(!d)return!1;if(d.depth>=2&&l.node(d.depth-1).type.compatibleContent(e)&&0==d.startIndex){if(0==l.index(d.depth-1))return!1;let e=n.doc.resolve(d.start-2);a=new o.Ts(e,e,d.depth),d.endIndex=0;e--)s=o.HY.from(n[e].type.create(n[e].attrs,s));e.step(new r.FC(t.start-2*!!i,t.end,t.start,t.end,new o.p2(s,0,0),n.length,!0));let d=0;for(let e=0;et.childCount>0&&t.firstChild.type==e);return!!s&&(!n||(i.node(s.depth-1).type==e?function(e,t,n,i){let l=e.tr,s=i.end,d=i.$to.end(i.depth);sr;t--)e-=l.child(t).nodeSize,i.delete(e-1,e+1);let s=i.doc.resolve(n.start),d=s.nodeAfter;if(i.mapping.map(n.end)!=n.start+s.nodeAfter.nodeSize)return!1;let c=0==n.startIndex,a=n.endIndex==l.childCount,p=s.node(-1),f=s.index(-1);if(!p.canReplace(f+ +!c,f+1,d.content.append(a?o.HY.empty:o.HY.from(l))))return!1;let u=s.pos,h=u+d.nodeSize;return i.step(new r.FC(u-+!!c,h+ +!!a,u+1,h-1,new o.p2((c?o.HY.empty:o.HY.from(l.copy(o.HY.empty))).append(a?o.HY.empty:o.HY.from(l.copy(o.HY.empty))),+!c,+!a),+!c)),t(i.scrollIntoView()),!0}(t,n,s)))}}function s(e){return function(t,n){let{$from:i,$to:l}=t.selection,s=i.blockRange(l,t=>t.childCount>0&&t.firstChild.type==e);if(!s)return!1;let d=s.startIndex;if(0==d)return!1;let c=s.parent,a=c.child(d-1);if(a.type!=e)return!1;if(n){let i=a.lastChild&&a.lastChild.type==c.type,l=o.HY.from(i?e.create():null),d=new o.p2(o.HY.from(e.create(null,o.HY.from(c.type.create(null,l)))),i?3:1,0),p=s.start,f=s.end;n(t.tr.step(new r.FC(p-(i?3:1),f,p,f,d,1,!0)).scrollIntoView())}return!0}}}}]);