wiki-viewer 2.18.0 → 2.18.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/standalone/.next/BUILD_ID +1 -1
- package/.next/standalone/.next/build-manifest.json +3 -3
- package/.next/standalone/.next/prerender-manifest.json +3 -3
- package/.next/standalone/.next/required-server-files.json +1 -1
- package/.next/standalone/.next/server/app/_global-error.html +1 -1
- package/.next/standalone/.next/server/app/_global-error.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/api/agent/activity/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/agent/events/[...path]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/agent/files/[...path]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/agent/fs/file/[...path]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/agent/fs/ls/[[...path]]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/agent/fs/move/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/agent/fs/search/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/agent/settings/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/agent/sidecar/[...path]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/app-proxy/[...path]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/assets/[...path]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/pdf/save/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/share/[token]/asset/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/share/[token]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/share/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/system/reveal/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/system/workspaces/[id]/branch/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/system/workspaces/[id]/open/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/system/workspaces/[id]/refresh/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/system/workspaces/[id]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/system/workspaces/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/upload/[...path]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/app/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/backlinks/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/content/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/download/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/folder/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/git-branches/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/git-checkout/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/git-diff/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/git-file-info/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/git-history/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/git-pull/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/hosted-apps/[slug]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/hosted-apps/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/move/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/new-file/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/outlinks/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/page/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/presence/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/scratch/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/search/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/slugs/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/upload/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/watch/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/app/[slug]/[[...rest]]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_0k6g8yo._.js +2 -2
- package/.next/standalone/.next/server/middleware-build-manifest.js +3 -3
- package/.next/standalone/.next/server/pages/500.html +1 -1
- package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/server-reference-manifest.json +1 -1
- package/.next/standalone/.next/static/chunks/{0y3wtq_6_n5iu.js → 0rt6552th393m.js} +2 -2
- package/.next/standalone/package.json +1 -1
- package/.next/standalone/server.js +1 -1
- package/package.json +1 -1
- /package/.next/standalone/.next/static/{rjQq3BNlWxvbhPVr6pwwW → ub73n8bw8WDHUBhT-xy14}/_buildManifest.js +0 -0
- /package/.next/standalone/.next/static/{rjQq3BNlWxvbhPVr6pwwW → ub73n8bw8WDHUBhT-xy14}/_clientMiddlewareManifest.js +0 -0
- /package/.next/standalone/.next/static/{rjQq3BNlWxvbhPVr6pwwW → ub73n8bw8WDHUBhT-xy14}/_ssgManifest.js +0 -0
|
@@ -18,7 +18,7 @@ TOKEN=<paste token here>
|
|
|
18
18
|
# 3. Read snapshot
|
|
19
19
|
curl -s -H "Authorization: Bearer $TOKEN" \\
|
|
20
20
|
-H "X-Agent-Id: ai:claude" \\
|
|
21
|
-
${t}/api/agent/files/${e??"<path/to/file.md>"}`;await navigator.clipboard.writeText(r),n(!0),setTimeout(()=>n(!1),1500)},[e])}}(e??null),[d,u]=(0,m.useState)(""),p=(0,m.useRef)(null),f=window.location.origin,x=(0,m.useCallback)(()=>t1,[]),b=(0,m.useCallback)(()=>d.replace(/\$WIKI_URL/g,f),[d,f]),y=(0,m.useCallback)(()=>`npx wiki-viewer-mcp register --url ${f} --id ai:myagent --name "My Agent"`,[f]),w=(0,m.useCallback)(()=>JSON.stringify({servers:{"wiki-viewer":{command:"npx",args:["wiki-viewer-mcp"],env:{WIKI_VIEWER_URL:f,WIKI_VIEWER_TOKEN:"<token from register>",WIKI_VIEWER_AGENT_ID:"ai:myagent"}}}},null,2),[f]),k=t2(x),N=t2(b),S=t2(y),C=t2(w);return((0,m.useEffect)(()=>{if(t)return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e);function e(e){"Escape"===e.key&&n()}},[t,n]),(0,m.useEffect)(()=>{t&&p.current?.focus()},[t]),(0,m.useEffect)(()=>{if(!t)return;o();let e=setInterval(()=>void o(),1e4);return()=>clearInterval(e)},[t,o]),(0,m.useEffect)(()=>{t&&fetch((0,ev.apiUrl)("/api/agents/install")).then(e=>e.json()).then(e=>{e.bootstrapPrompt&&u(e.bootstrapPrompt)}).catch(()=>void 0)},[t]),t)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 z-40 bg-overlay backdrop-blur-[1px]",onClick:n,"aria-hidden":!0}),(0,s.jsxs)("aside",{ref:p,tabIndex:-1,role:"dialog","aria-modal":"true","aria-label":"AI Agent Panel",className:"fixed right-0 top-0 bottom-0 z-50 flex w-[90vw] max-w-sm md:w-80 flex-col border-l border-border bg-background shadow-xl outline-none",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-border px-4 py-3 shrink-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(a,{className:"h-4 w-4 text-muted-foreground"}),(0,s.jsx)("span",{className:"text-sm font-semibold",children:"AI Agent"})]}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:n,title:"Close panel (Esc)",children:(0,s.jsx)(h,{className:"h-3.5 w-3.5"})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto space-y-5 px-4 py-4",children:[(0,s.jsxs)("section",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"space-y-0.5",children:[(0,s.jsx)("p",{className:"text-sm font-semibold text-foreground",children:"1 · Set up an assistant"}),(0,s.jsx)("p",{className:"text-xs leading-relaxed text-muted-foreground",children:"Pick one way to connect. You approve it in step 2 before it can touch anything."})]}),(0,s.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,s.jsx)("p",{className:"text-xs font-semibold text-foreground",children:"Paste into a chatbot"}),(0,s.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Quickest. Copy a prompt into ChatGPT, Claude, etc. Edits come back as suggestions you accept or revert. No install."}),(0,s.jsx)(v.Button,{size:"sm",variant:"outline",className:"h-7 w-full text-xs gap-1.5",onClick:()=>void N.copy(),disabled:!d,children:N.copied?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"})," Copied!"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(e7.Copy,{className:"h-3.5 w-3.5"})," Copy prompt"]})})]}),(0,s.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,s.jsx)("p",{className:"text-xs font-semibold text-foreground",children:"Connect a coding tool"}),(0,s.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Claude Code, Cursor, Codex, etc. get native read/edit tools over MCP. Run this to request access, then copy the config:"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("code",{className:"flex-1 text-[10px] font-mono text-foreground/80 truncate bg-muted rounded px-1 py-0.5",children:y()}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0",title:"Copy this command",onClick:()=>void S.copy(),children:S.copied?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"}):(0,s.jsx)(e7.Copy,{className:"h-3.5 w-3.5"})})]}),(0,s.jsx)(v.Button,{size:"sm",variant:"outline",className:"h-7 w-full text-xs gap-1.5",onClick:()=>void C.copy(),children:C.copied?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"})," Copied!"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(e7.Copy,{className:"h-3.5 w-3.5"})," Copy config (mcp.json)"]})})]}),(0,s.jsxs)("details",{className:"text-[10px] text-muted-foreground/60",children:[(0,s.jsx)("summary",{className:"cursor-pointer select-none text-muted-foreground/50",children:"For developers"}),(0,s.jsxs)("div",{className:"mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1",children:[(0,s.jsx)("span",{children:"Install skill:"}),(0,s.jsx)("code",{className:"font-mono text-foreground/70 bg-muted rounded px-1 py-0.5",children:t1}),(0,s.jsxs)("button",{type:"button",onClick:()=>void k.copy(),className:"inline-flex items-center gap-1 text-primary hover:underline",children:[k.copied?(0,s.jsx)(g.Check,{className:"h-3 w-3 text-green-500"}):(0,s.jsx)(e7.Copy,{className:"h-3 w-3"})," copy"]}),(0,s.jsxs)("button",{type:"button",onClick:()=>void c(),className:"inline-flex items-center gap-1 text-primary hover:underline",children:[l?(0,s.jsx)(g.Check,{className:"h-3 w-3 text-green-500"}):(0,s.jsx)(e7.Copy,{className:"h-3 w-3"})," curl example"]}),(0,s.jsxs)("a",{href:(0,ev.apiUrl)("/api/agents/skill"),target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-primary hover:underline",children:[(0,s.jsx)(tC.ExternalLink,{className:"h-3 w-3"})," skill"]}),(0,s.jsxs)("a",{href:(0,ev.apiUrl)("/api/agents/install"),target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-primary hover:underline",children:[(0,s.jsx)(tC.ExternalLink,{className:"h-3 w-3"})," install JSON"]})]})]})]}),(0,s.jsx)(tR,{}),(0,s.jsxs)("div",{className:"space-y-0.5",children:[(0,s.jsx)("p",{className:"text-sm font-semibold text-foreground",children:"3 · Watch what they do"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Who is connected and every edit they make."})]}),(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsxs)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:["Active Connections"," ",(0,s.jsx)("span",{className:"normal-case font-normal text-muted-foreground/50",children:"(last 5 min)"})]}),(0,s.jsx)("div",{className:"rounded-md border border-border bg-muted/40 p-3",children:0===i.length?(0,s.jsxs)("p",{className:"text-xs text-muted-foreground/60 flex items-center gap-1.5",children:[(0,s.jsx)(tS,{className:"h-3.5 w-3.5"}),"No recent activity"]}):(0,s.jsx)("ul",{className:"space-y-1.5",children:i.map(e=>(0,s.jsxs)("li",{className:"flex items-center justify-between text-xs",children:[(0,s.jsx)("span",{className:"font-mono text-foreground/80 truncate",children:e.by}),(0,s.jsxs)("span",{className:"text-muted-foreground shrink-0",children:[e.opCount," op",1!==e.opCount?"s":""]})]},e.by))})})]}),(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Recent Activity"}),(0,s.jsx)("div",{className:"rounded-md border border-border bg-muted/40 px-3 py-2 max-h-72 overflow-y-auto",children:(0,s.jsx)(t0,{activity:r})})]}),(0,s.jsx)("section",{children:(0,s.jsx)("a",{href:(0,ev.apiUrl)("/docs/agent-collab-plan.md"),target:"_blank",rel:"noreferrer",className:"text-xs text-primary underline hover:no-underline",children:"Agent collaboration docs →"})})]})]})]}):null}var t3=e.i(406347);let t4=(0,o.default)("link",[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",key:"1cjeqo"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",key:"19qd67"}]]),t6=(0,o.default)("ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]),t9=(0,o.default)("file",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]),t7=(0,o.default)("file-plus",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]]),t8=(0,o.default)("folder-plus",[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);var ne=e.i(736099);let nt=(0,o.default)("terminal",[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]]),nn=(0,o.default)("upload",[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]);function nr(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}let ni=(0,eN.create)((e,t)=>({apps:[],loading:!1,loaded:!1,collapsed:!0,dialog:null,toggleCollapsed:()=>{let n=!t().collapsed;e({collapsed:n}),n||t().refresh()},refresh:async()=>{e({loading:!0});try{let t=await (0,tk.wsFetch)("/api/wiki/hosted-apps");if(!t.ok)return void e({loading:!1,loaded:!0});let n=await t.json();e({apps:n.apps??[],loading:!1,loaded:!0})}catch{e({loading:!1,loaded:!0})}},create:async({slug:e,relPath:n,type:r="html",script:i})=>{try{let s=await (0,tk.wsFetch)("/api/wiki/hosted-apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({slug:e,type:r,path:n,script:i})});if(!s.ok){let e=await s.json().catch(()=>({}));return{ok:!1,error:e.error,message:e.message}}return await t().refresh(),{ok:!0}}catch(e){return{ok:!1,message:String(e)}}},start:async e=>{try{await (0,tk.wsFetch)(`/api/wiki/hosted-apps/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"start"})})}finally{await t().refresh()}},stop:async e=>{try{await (0,tk.wsFetch)(`/api/wiki/hosted-apps/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"stop"})})}finally{await t().refresh()}},pin:async e=>{try{await (0,tk.wsFetch)(`/api/wiki/hosted-apps/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"pin"})})}finally{await t().refresh()}},unpin:async e=>{try{await (0,tk.wsFetch)(`/api/wiki/hosted-apps/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"unpin"})})}finally{await t().refresh()}},restart:async e=>{try{await (0,tk.wsFetch)(`/api/wiki/hosted-apps/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"restart"})})}finally{await t().refresh()}},remove:async e=>{try{await (0,tk.wsFetch)("/api/wiki/hosted-apps",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({slug:e})})}finally{await t().refresh()}},openHostDialog:(t,n,r="html")=>e({dialog:{relPath:t,defaultSlug:n,type:r}}),closeHostDialog:()=>e({dialog:null})}));function ns({pos:e,branches:t,loading:n,busyName:r,disabled:i,onPick:o,onClose:a}){let[l,c]=(0,m.useState)(""),d=(0,m.useRef)(null);if((0,m.useEffect)(()=>{let e=e=>{let t=e.target;d.current?.contains(t)||t?.closest?.("[data-branch-trigger]")||a()},t=e=>{"Escape"===e.key&&a()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[a]),"u"<typeof document)return null;let p=t.length>8,h=l.trim().toLowerCase(),f=h?t.filter(e=>e.name.toLowerCase().includes(h)):t;return(0,tf.createPortal)((0,s.jsx)("div",{ref:d,"data-branch-portal":!0,style:{position:"fixed",top:e.top,left:e.left},className:"pointer-events-auto z-[9999] flex max-h-72 w-52 flex-col overflow-hidden rounded-md border bg-popover p-1 shadow-md",children:n?(0,s.jsx)("div",{className:"flex justify-center py-2",children:(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"})}):0===t.length?(0,s.jsx)("p",{className:"px-2 py-1 text-[10px] text-muted-foreground",children:"No branches"}):(0,s.jsxs)(s.Fragment,{children:[p&&(0,s.jsx)("input",{autoFocus:!0,value:l,onChange:e=>c(e.target.value),placeholder:"Filter branches…",className:"mb-1 w-full shrink-0 rounded border bg-background px-1.5 py-1 text-[11px] outline-none focus:ring-1 focus:ring-ring"}),(0,s.jsx)("div",{className:"min-h-0 flex-1 overflow-auto",children:0===f.length?(0,s.jsx)("p",{className:"px-2 py-1 text-[10px] text-muted-foreground",children:"No match"}):f.map(e=>(0,s.jsxs)("button",{type:"button",disabled:i||e.current,className:(0,eh.cn)("flex w-full items-center gap-1.5 rounded px-2 py-1 text-left text-[11px] hover:bg-muted",e.current?"font-semibold text-foreground":"text-muted-foreground"),onClick:t=>{t.stopPropagation(),e.current||o(e.name)},children:[e.current?(0,s.jsx)(g.Check,{className:"h-3 w-3 shrink-0"}):(0,s.jsx)("span",{className:"w-3 shrink-0"}),(0,s.jsx)("span",{className:"truncate",children:e.name}),r===e.name&&(0,s.jsx)(u.Loader2,{className:"ml-auto h-3 w-3 shrink-0 animate-spin"})]},e.name))})]})}),document.body)}var no=e.i(918552),na=e.i(136131),nl="ContextMenu",[nc,nd]=(0,N.createContextScope)(nl,[no.createMenuScope]),nu=(0,no.createMenuScope)(),[np,nh]=nc(nl),nm=e=>{let{__scopeContextMenu:t,children:n,onOpenChange:r,dir:i,modal:o=!0}=e,[a,l]=m.useState(!1),c=nu(t),d=(0,na.useCallbackRef)(r),u=m.useCallback(e=>{l(e),d(e)},[d]);return(0,s.jsx)(np,{scope:t,open:a,onOpenChange:u,modal:o,children:(0,s.jsx)(no.Root,{...c,dir:i,open:a,onOpenChange:u,modal:o,children:n})})};nm.displayName=nl;var nf="ContextMenuTrigger",ng=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,disabled:r=!1,...i}=e,o=nh(nf,n),a=nu(n),l=m.useRef({x:0,y:0}),c=m.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...l.current})}),d=m.useRef(0),u=m.useCallback(()=>window.clearTimeout(d.current),[]),p=e=>{l.current={x:e.clientX,y:e.clientY},o.onOpenChange(!0)};return m.useEffect(()=>u,[u]),m.useEffect(()=>void(r&&u()),[r,u]),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(no.Anchor,{...a,virtualRef:c}),(0,s.jsx)(T.Primitive.span,{"data-state":o.open?"open":"closed","data-disabled":r?"":void 0,...i,ref:t,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:(0,w.composeEventHandlers)(e.onContextMenu,e=>{u(),p(e),e.preventDefault()}),onPointerDown:r?e.onPointerDown:(0,w.composeEventHandlers)(e.onPointerDown,nM(e=>{u(),d.current=window.setTimeout(()=>p(e),700)})),onPointerMove:r?e.onPointerMove:(0,w.composeEventHandlers)(e.onPointerMove,nM(u)),onPointerCancel:r?e.onPointerCancel:(0,w.composeEventHandlers)(e.onPointerCancel,nM(u)),onPointerUp:r?e.onPointerUp:(0,w.composeEventHandlers)(e.onPointerUp,nM(u))})]})});ng.displayName=nf;var nx=e=>{let{__scopeContextMenu:t,...n}=e,r=nu(t);return(0,s.jsx)(no.Portal,{...r,...n})};nx.displayName="ContextMenuPortal";var nb="ContextMenuContent",ny=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nh(nb,n),o=nu(n),a=m.useRef(!1);return(0,s.jsx)(no.Content,{...o,...r,ref:t,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),!t.defaultPrevented&&a.current&&t.preventDefault(),a.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||i.modal||(a.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});ny.displayName=nb,m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.Group,{...i,...r,ref:t})}).displayName="ContextMenuGroup";var nv=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.Label,{...i,...r,ref:t})});nv.displayName="ContextMenuLabel";var nw=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.Item,{...i,...r,ref:t})});nw.displayName="ContextMenuItem";var nk=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.CheckboxItem,{...i,...r,ref:t})});nk.displayName="ContextMenuCheckboxItem",m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.RadioGroup,{...i,...r,ref:t})}).displayName="ContextMenuRadioGroup";var nN=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.RadioItem,{...i,...r,ref:t})});nN.displayName="ContextMenuRadioItem";var nS=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.ItemIndicator,{...i,...r,ref:t})});nS.displayName="ContextMenuItemIndicator";var nC=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.Separator,{...i,...r,ref:t})});nC.displayName="ContextMenuSeparator",m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.Arrow,{...i,...r,ref:t})}).displayName="ContextMenuArrow";var nj=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.SubTrigger,{...i,...r,ref:t})});nj.displayName="ContextMenuSubTrigger";var nE=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.SubContent,{...i,...r,ref:t,style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});function nM(e){return t=>"mouse"!==t.pointerType?e(t):void 0}nE.displayName="ContextMenuSubContent";var nA=e.i(149427);m.forwardRef(({className:e,inset:t,children:n,...r},i)=>(0,s.jsxs)(nj,{ref:i,className:(0,eh.cn)("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,(0,s.jsx)(eY.ChevronRight,{className:"ml-auto h-4 w-4"})]})).displayName=nj.displayName,m.forwardRef(({className:e,...t},n)=>(0,s.jsx)(nE,{ref:n,className:(0,eh.cn)("z-50 min-w-[8rem] overflow-hidden rounded-sm border bg-popover p-1 text-popover-foreground shadow-golden data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t})).displayName=nE.displayName;let nT=m.forwardRef(({className:e,...t},n)=>(0,s.jsx)(nx,{children:(0,s.jsx)(ny,{ref:n,className:(0,eh.cn)("z-50 min-w-[8rem] overflow-hidden rounded-sm border bg-popover p-1 text-popover-foreground shadow-golden data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t})}));nT.displayName=ny.displayName;let nO=m.forwardRef(({className:e,inset:t,...n},r)=>(0,s.jsx)(nw,{ref:r,className:(0,eh.cn)("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));nO.displayName=nw.displayName,m.forwardRef(({className:e,children:t,checked:n,...r},i)=>(0,s.jsxs)(nk,{ref:i,className:(0,eh.cn)("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[(0,s.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,s.jsx)(nS,{children:(0,s.jsx)(g.Check,{className:"h-4 w-4"})})}),t]})).displayName=nk.displayName,m.forwardRef(({className:e,children:t,...n},r)=>(0,s.jsxs)(nN,{ref:r,className:(0,eh.cn)("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[(0,s.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,s.jsx)(nS,{children:(0,s.jsx)(nA.Circle,{className:"h-2 w-2 fill-current"})})}),t]})).displayName=nN.displayName,m.forwardRef(({className:e,inset:t,...n},r)=>(0,s.jsx)(nv,{ref:r,className:(0,eh.cn)("px-2 py-1.5 text-sm font-normal",t&&"pl-8",e),...n})).displayName=nv.displayName;let n_=m.forwardRef(({className:e,...t},n)=>(0,s.jsx)(nC,{ref:n,className:(0,eh.cn)("-mx-1 my-1 h-px bg-muted",e),...t}));n_.displayName=nC.displayName;let nD="wiki-humanize-names",nR=(0,eN.create)((e,t)=>({humanize:"1"===localStorage.getItem(nD),toggle:()=>{let n=!t().humanize;n?localStorage.setItem(nD,"1"):localStorage.removeItem(nD),e({humanize:n})}})),nI="wiki-show-hidden",nL=(0,eN.create)((e,t)=>({showHidden:"1"===localStorage.getItem(nI),toggle:()=>{let n=!t().showHidden;n?localStorage.setItem(nI,"1"):localStorage.removeItem(nI),e({showHidden:n})}}));function nP(e,t){if("node-app"===t)return"node-app";if("app"===t)return"app";if("dir"===t)return"fallback";let n=e.split("/").pop()??e;if(n.startsWith(".")&&-1===n.indexOf(".",1))return"source";let r=e.split(".").pop()?.toLowerCase()??"";return r?["md","markdown"].includes(r)?"editor":"mdx"===r?"mdx":"txt"===r?"text":["csv","tsv"].includes(r)?"csv":"pdf"===r?"pdf":["mmd","mermaid"].includes(r)?"mermaid":"ipynb"===r?"notebook":"excalidraw"===r?"canvas":["png","jpg","jpeg","gif","webp","svg","avif","ico","bmp"].includes(r)?"image":["mp4","webm","mov","m4v","mp3","wav","ogg","m4a","aac"].includes(r)?"media":"docx"===r?"docx":["xlsx","xlsm"].includes(r)?"xlsx":"pptx"===r?"pptx":"html"===r?"html":(["py","js","ts","tsx","jsx","go","rs","java","c","cpp","h","sh","bash","zsh","rb","php","swift","kt","lua","sql","yaml","yml","toml","json","xml","css","scss"].includes(r),"source"):"source"}function n$(e){return e.split(".").pop()?.toLowerCase()??""}let nz=new Set(["txt","md","markdown","json","yaml","yml","toml","csv","tsv","xml","html","css","js","ts","tsx","jsx","sh","bash","zsh","rb","py","go","rs","java","c","cpp","h","php","swift","kt","lua","sql","scss","mmd","mermaid","ini","env","log","conf"]);function nB(e){let t=nP(e,"file");return"editor"===t||"text"===t||"mdx"===t||nz.has(n$(e))}function nF(e){return["md","markdown"].includes(n$(e))}function nH(e){return"image"===nP(e,"file")}function nU(e){return"html"===nP(e,"file")}let nV={contentVisibility:"auto",containIntrinsicSize:"auto 32px"};function nW({node:e,ctx:t,isFavorited:n,activeWorkspaceId:r}){return(0,s.jsxs)(nT,{className:"w-48",children:[(0,s.jsxs)(nO,{onSelect:()=>t.copyPath(e.path),children:[(0,s.jsx)(e7.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),nF(e.name)&&(0,s.jsxs)(nO,{onSelect:()=>t.copyWikiLink(e.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,s.jsxs)(nO,{onSelect:()=>t.copyUrl(e.path),children:[(0,s.jsx)(t4,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),"file"===e.type&&nB(e.name)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(nO,{onSelect:()=>t.copyRawContent(e.path),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,s.jsxs)(nO,{onSelect:()=>t.copyFormattedContent(e.path,e.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),(0,s.jsx)(n_,{}),"dir"===e.type&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(nO,{onSelect:()=>{e.expanded||t.toggleFolder(e),t.setNewFileParent(e.path),t.setNewFileName(""),t.setFileCreateError(null)},children:[(0,s.jsx)(t7,{className:"mr-2 h-3.5 w-3.5"}),"New file here"]}),(0,s.jsxs)(nO,{onSelect:()=>t.triggerUpload(e.path),children:[(0,s.jsx)(nn,{className:"mr-2 h-3.5 w-3.5"}),"Upload here"]}),(0,s.jsxs)(nO,{onSelect:()=>ni.getState().openHostDialog(e.path,nr(e.name)),children:[(0,s.jsx)(e5,{className:"mr-2 h-3.5 w-3.5"}),"Host this app"]}),(0,s.jsxs)(nO,{onSelect:()=>{t.setNewFolderParent(e.path),t.setNewFolderName(""),t.setFolderError(null)},children:[(0,s.jsx)(t8,{className:"mr-2 h-3.5 w-3.5"}),"New subfolder"]}),(0,s.jsx)(n_,{})]}),(0,s.jsxs)(nO,{onSelect:()=>t.handleDownload(e),children:[(0,s.jsx)(t3.Download,{className:"mr-2 h-3.5 w-3.5"}),"file"===e.type?"Download":"Download as zip"]}),(0,s.jsxs)(nO,{onSelect:()=>t.toggleFavorite(e,r),children:[(0,s.jsx)(e4,{className:(0,eh.cn)("mr-2 h-3.5 w-3.5",n&&"fill-current text-amber-400")}),n?"Remove from favorites":"Add to favorites"]}),(0,s.jsx)(n_,{}),(0,s.jsxs)(nO,{className:"text-destructive focus:text-destructive",onSelect:()=>{t.setDeletingPath(e.path),t.setDeletingIsDir("file"!==e.type)},children:[(0,s.jsx)(te,{className:"mr-2 h-3.5 w-3.5"}),"Delete"]})]})}function nq({name:e,type:t}){let n="h-3.5 w-3.5 shrink-0";return"dir"===t?(0,s.jsx)(eQ,{className:(0,eh.cn)(n,"text-foreground/70")}):"app"===t?(0,s.jsx)(c,{className:(0,eh.cn)(n,"text-foreground/70")}):"node-app"===t?(0,s.jsx)(nt,{className:(0,eh.cn)(n,"text-emerald-500")}):nU(e)?(0,s.jsx)(c,{className:(0,eh.cn)(n,"text-foreground/60")}):"canvas"===nP(e,"file")?(0,s.jsx)(ne.PencilRuler,{className:(0,eh.cn)(n,"text-violet-500")}):nH(e)?(0,s.jsx)(d.Image,{className:(0,eh.cn)(n,"text-sunshine-700")}):nB(e)?(0,s.jsx)(l.FileText,{className:(0,eh.cn)(n,"text-foreground/70")}):(0,s.jsx)(t9,{className:(0,eh.cn)(n,"text-foreground/60")})}let nK=(0,m.memo)(function({node:e,depth:t,ctx:n,isMobile:r,activeWorkspaceId:i,sidebarScrollRef:o,isActive:a,isDragOver:p,isFavorited:h,isAgentActive:m,isPulling:f,branchOpen:g,branchPos:x,branches:b,branchLoading:y,checkingOut:w,onHoverEnter:k,onHoverLeave:N}){var S;let C,j,E,M,A,T=nR(e=>e.humanize);return(0,s.jsxs)(nm,{children:[(0,s.jsx)(ng,{asChild:!0,children:(0,s.jsxs)("div",{role:"treeitem",tabIndex:0,draggable:!r,onKeyDown:r=>{if("Enter"===r.key||" "===r.key)r.preventDefault(),"dir"===e.type?n.toggleFolder(e):"app"===e.type||"node-app"===e.type?(n.openViewer(e),n.toggleFolder(e)):n.openViewer(e);else if("ArrowDown"===r.key){r.preventDefault();let e=o.current;if(!e)return;let t=Array.from(e.querySelectorAll('[role="treeitem"]')),n=t.indexOf(r.currentTarget);t[n+1]?.focus()}else if("ArrowUp"===r.key){r.preventDefault();let e=o.current;if(!e)return;let t=Array.from(e.querySelectorAll('[role="treeitem"]')),n=t.indexOf(r.currentTarget);t[n-1]?.focus()}else if("ArrowRight"===r.key){if(r.preventDefault(),"dir"===e.type||"app"===e.type||"node-app"===e.type)if(e.expanded){let e=o.current;if(!e)return;let t=Array.from(e.querySelectorAll('[role="treeitem"]')),n=t.indexOf(r.currentTarget);t[n+1]?.focus()}else n.toggleFolder(e)}else if("ArrowLeft"===r.key){if(r.preventDefault(),("dir"===e.type||"app"===e.type||"node-app"===e.type)&&e.expanded)n.toggleFolder(e);else if(t>0){let e=o.current;if(!e)return;let t=Array.from(e.querySelectorAll('[role="treeitem"]')),n=r.currentTarget,i=t.indexOf(n),s=Number.parseInt(n.style.paddingLeft??"0",10);for(let e=i-1;e>=0;e--)if(Number.parseInt(t[e].style.paddingLeft??"0",10)<s){t[e].focus();break}}}},onDragStart:t=>n.handleDragStart(t,e),onDragOver:t=>"dir"===e.type?n.handleDragOver(t,e.path,"dir"):t.preventDefault(),onDragLeave:()=>n.setDragOverPath(null),onDrop:t=>"dir"===e.type?n.handleDropOnFolder(t,e.path):t.preventDefault(),onMouseEnter:()=>k(e),onMouseLeave:N,className:(0,eh.cn)("tree-row-reveal flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer group transition-colors select-none touch-target",a?"bg-accent-soft text-foreground font-medium":"hover:bg-muted",p&&"ring-2 ring-primary bg-primary-soft",e.name.startsWith(".")&&"opacity-40"),style:{paddingLeft:`${14*t+8}px`,...nV},onClick:()=>{"dir"===e.type?n.toggleFolder(e):("app"===e.type||"node-app"===e.type?(n.openViewer(e),n.toggleFolder(e)):n.openViewer(e),r&&n.setSidebarCollapsed(!0))},children:["dir"===e.type||"app"===e.type||"node-app"===e.type?e.loading?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground"}):(0,s.jsx)(eY.ChevronRight,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform duration-200 ease-out",style:{transform:e.expanded?"rotate(90deg)":"rotate(0deg)"}}):(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)("span",{className:"",children:"dir"===e.type?e.expanded?(0,s.jsx)(e0,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):(0,s.jsx)(eQ,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):"app"===e.type?(0,s.jsx)(c,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):"node-app"===e.type?(0,s.jsx)(nt,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-emerald-500")}):nU(e.name)?(0,s.jsx)(c,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/60")}):"canvas"===nP(e.name,"file")?(0,s.jsx)(ne.PencilRuler,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-violet-500")}):nH(e.name)?(0,s.jsx)(d.Image,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-sunshine-700")}):nB(e.name)?(0,s.jsx)(l.FileText,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):(0,s.jsx)(t9,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/60")})}),(0,s.jsx)("span",{className:"min-w-0 flex-1 truncate",title:T?e.name:void 0,children:T?(E=(j=(C=(S=e.name).lastIndexOf("."))>0&&C<S.length-1)?S.slice(0,C):S,M=j?S.slice(C):"",(A=E.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").split(/[\s_-]+/).filter(Boolean).map(e=>/^[A-Z0-9]+$/.test(e)?e:e[0].toUpperCase()+e.slice(1))).length?A.join(" ")+M:S):e.name}),e.git&&(0,s.jsxs)("span",{className:"relative flex shrink-0 items-center gap-0.5 rounded-sm bg-muted px-1 py-0.5 text-[10px] text-muted-foreground",children:[(0,s.jsxs)("button",{"data-branch-trigger":!0,type:"button",className:"flex items-center gap-0.5 hover:text-foreground",title:"Switch branch",onClick:t=>{if(t.stopPropagation(),g){n.setBranchDropdownNode(null),n.setBranchDropdownPos(null);return}let r=t.currentTarget.getBoundingClientRect();n.setBranchDropdownPos({top:r.bottom+4,left:r.left}),n.setBranchDropdownNode(e.path),n.loadBranches(e.path)},children:[(0,s.jsx)(e1,{className:"h-2.5 w-2.5"}),e.git.branch,e.git.dirty&&(0,s.jsx)("span",{className:"ml-0.5 text-foreground/70",children:"*"})]}),f?(0,s.jsx)(u.Loader2,{className:"ml-0.5 h-2.5 w-2.5 animate-spin"}):(0,s.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation();let r=e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")):"";n.handleGitPull(e.path,r)},className:"ml-0.5 text-muted-foreground hover:text-foreground",title:"Pull latest",children:(0,s.jsx)(tA,{className:"h-2.5 w-2.5"})}),g&&x&&(0,s.jsx)(ns,{pos:x,branches:b,loading:y,busyName:w,disabled:null!==w,onPick:t=>{let r=e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")):"";n.handleCheckout(e.path,t,r)},onClose:()=>{n.setBranchDropdownNode(null),n.setBranchDropdownPos(null)}})]}),m&&(0,s.jsx)("span",{className:"ml-0.5 h-1.5 w-1.5 rounded-full bg-emerald-400 shrink-0 animate-pulse",title:"Agent recently active"}),(0,s.jsx)("div",{className:"hover-reveal flex max-w-0 shrink-0 items-center overflow-hidden opacity-0 transition-all duration-150 group-hover:max-w-7 group-hover:opacity-100 focus-within:max-w-7 focus-within:opacity-100",onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-muted-foreground hover:text-foreground",title:"File actions",children:(0,s.jsx)(t6,{className:"h-3.5 w-3.5"})})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"end",className:"w-48",children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyPath(e.path),children:[(0,s.jsx)(e7.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),nF(e.name)&&(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyWikiLink(e.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyUrl(e.path),children:[(0,s.jsx)(t4,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),"file"===e.type&&nB(e.name)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyRawContent(e.path),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyFormattedContent(e.path,e.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),"dir"===e.type&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:async()=>{e.expanded||n.toggleFolder(e),n.setNewFileParent(e.path),n.setNewFileName(""),n.setFileCreateError(null)},children:[(0,s.jsx)(t7,{className:"mr-2 h-3.5 w-3.5"}),"New file here"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.triggerUpload(e.path),children:[(0,s.jsx)(nn,{className:"mr-2 h-3.5 w-3.5"}),"Upload here"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>{n.setNewFolderParent(e.path),n.setNewFolderName(""),n.setFolderError(null)},children:[(0,s.jsx)(t8,{className:"mr-2 h-3.5 w-3.5"}),"New subfolder"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{})]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.handleDownload(e),children:[(0,s.jsx)(t3.Download,{className:"mr-2 h-3.5 w-3.5"}),"file"===e.type?"Download":"Download as zip"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.toggleFavorite(e,i),children:[(0,s.jsx)(e4,{className:(0,eh.cn)("mr-2 h-3.5 w-3.5",h&&"fill-current text-amber-400")}),h?"Remove from favorites":"Add to favorites"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{className:"text-destructive focus:text-destructive",onClick:()=>{n.setDeletingPath(e.path),n.setDeletingIsDir("file"!==e.type)},children:[(0,s.jsx)(te,{className:"mr-2 h-3.5 w-3.5"}),"Delete"]})]})]})})]})}),(0,s.jsx)(nW,{node:e,ctx:n,isFavorited:h,activeWorkspaceId:i})]})}),nG=(0,m.memo)(function(e){let{ctx:t,openPath:n,dragOverPath:r,branchDropdownNode:i,branchDropdownPos:o,nodeBranches:a,branchesLoading:c,checkingOutBranch:d,pullingRepo:u,activePaths:p,favorites:f,isMobile:x,activeWorkspaceId:b,newFileParent:y,newFileName:w,fileCreateError:k,newFolderParent:N,newFolderName:S,folderError:C,sidebarScrollRef:j}=e,E=nL(e=>e.showHidden),M=(0,m.useRef)(null),A=(0,m.useCallback)(e=>{let n=("dir"===e.type||"app"===e.type||"node-app"===e.type)&&!e.expanded&&void 0===e.children;("file"===e.type||n)&&(M.current&&clearTimeout(M.current),M.current=setTimeout(()=>t.prefetch(e),120))},[t]),T=(0,m.useCallback)(()=>{M.current&&(clearTimeout(M.current),M.current=null)},[]),O=(0,m.useMemo)(()=>{let t=[],n=(e,r)=>{for(let i of e)!(!E&&i.name.startsWith("."))&&(t.push({kind:"row",node:i,depth:r}),"dir"===i.type&&(N===i.path&&t.push({kind:"newfolder",node:i,depth:r}),y===i.path&&t.push({kind:"newfile",node:i,depth:r})),("dir"===i.type||"app"===i.type||"node-app"===i.type)&&i.expanded&&(i.children&&i.children.length>0?n(i.children,r+1):i.children?.length===0&&t.push({kind:"empty",node:i,depth:r})))};return n(e.nodes,0),t},[e.nodes,y,N,E]);return(0,s.jsx)(s.Fragment,{children:O.map(e=>{let{node:m,depth:y}=e;if("row"===e.kind){let e=i===m.path;return(0,s.jsx)(nK,{node:m,depth:y,ctx:t,isMobile:x,activeWorkspaceId:b,sidebarScrollRef:j,isActive:n===m.path,isDragOver:r===m.path,isFavorited:f.some(e=>e.path===m.path),isAgentActive:p.has(m.path),isPulling:u===m.path,branchOpen:e,branchPos:e?o:null,branches:m.git?a[m.path]??[]:[],branchLoading:!!m.git&&!!c[m.path],checkingOut:e?d:null,onHoverEnter:A,onHoverLeave:T},m.path)}return"newfolder"===e.kind?(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1",style:{paddingLeft:`${(y+1)*14+8}px`,...nV},children:[(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)(eQ,{className:"h-4 w-4 shrink-0 text-foreground/70"}),(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"Folder name",value:S,onChange:e=>t.setNewFolderName(e.target.value),onKeyDown:e=>{"Enter"===e.key&&t.handleCreateFolder(),"Escape"===e.key&&(t.setNewFolderParent(null),t.setNewFolderName(""))}}),C&&(0,s.jsx)("span",{className:"text-xs text-destructive",children:C}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:t.handleCreateFolder,children:(0,s.jsx)(g.Check,{className:"h-3 w-3"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{t.setNewFolderParent(null),t.setNewFolderName("")},children:(0,s.jsx)(h,{className:"h-3 w-3"})})]},`nf-${m.path}`):"newfile"===e.kind?(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1",style:{paddingLeft:`${(y+1)*14+8}px`,...nV},children:[(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)(l.FileText,{className:"h-4 w-4 shrink-0 text-accent"}),(0,s.jsx)("input",{autoFocus:!0,className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"filename (default .md)",value:w,onFocus:e=>e.currentTarget.select(),onChange:e=>t.setNewFileName(e.target.value),onKeyDown:e=>{"Enter"===e.key&&t.handleCreateFile(),"Escape"===e.key&&(t.setNewFileParent(null),t.setNewFileName(""))}}),k&&(0,s.jsx)("span",{className:"text-xs text-destructive",children:k}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:t.handleCreateFile,children:(0,s.jsx)(g.Check,{className:"h-3 w-3"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{t.setNewFileParent(null),t.setNewFileName("")},children:(0,s.jsx)(h,{className:"h-3 w-3"})})]},`ff-${m.path}`):(0,s.jsx)("div",{className:"text-xs text-muted-foreground/50 py-0.5",style:{paddingLeft:`${(y+1)*14+8+14+6+16+6}px`,...nV},children:"Empty"},`empty-${m.path}`)})})});function nJ(e){return e?`wiki-pinned-files-${e}`:"wiki-pinned-files"}function nZ(e){try{let t=localStorage.getItem(nJ(e));return t?JSON.parse(t):[]}catch{return[]}}let nX=(0,eN.create)((e,t)=>({favorites:[],loadForWorkspace:t=>{e({favorites:nZ(t)})},toggle:(t,n)=>{let r=nZ(n),i=r.some(e=>e.path===t.path)?r.filter(e=>e.path!==t.path):[...r,t];localStorage.setItem(nJ(n),JSON.stringify(i)),e({favorites:i})},isFavorited:e=>t().favorites.some(t=>t.path===e)}));function nY({doc:e,node:t,extraItems:n,activeWorkspaceId:r=null}){let i=nX(e=>e.isFavorited(t.path));return(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"File actions",children:(0,s.jsx)(t6,{className:"h-3.5 w-3.5"})})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"end",className:"w-52",children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>{let e=(0,tk.withWs)(`/api/wiki/download?path=${encodeURIComponent(t.path)}`),n=document.createElement("a");n.href=e,n.download=t.name,document.body.appendChild(n),n.click(),n.remove()},children:[(0,s.jsx)(t3.Download,{className:"mr-2 h-3.5 w-3.5"}),"Download"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>{nX.getState().toggle({path:t.path,name:t.name},r)},children:[(0,s.jsx)(e4,{className:(0,eh.cn)("mr-2 h-3.5 w-3.5",i&&"fill-current text-amber-400")}),i?"Remove from favorites":"Add to favorites"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>e.copyPath(t.path),children:[(0,s.jsx)(e7.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),nF(t.name)&&(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>e.copyWikiLink(t.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>e.copyUrl(t.path),children:[(0,s.jsx)(t4,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),nB(t.name)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>void e.copyRawContent(t.path),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>void e.copyFormattedContent(t.path,t.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),n&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(ek.DropdownMenuSeparator,{}),n]})]})]})}let nQ=(0,o.default)("align-center",[["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 18H5",key:"18s9l3"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);var n0=e.i(409082);let n1=(0,o.default)("panel-left",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]]);var n2=e.i(847463),n5=e.i(917356),n3=/[\\\/_+.#"@\[\(\{&]/,n4=/[\\\/_+.#"@\[\(\{&]/g,n6=/[\s-]/,n9=/[\s-]/g;function n7(e){return e.toLowerCase().replace(n9," ")}var n8='[cmdk-group=""]',re='[cmdk-group-items=""]',rt='[cmdk-item=""]',rn=`${rt}:not([aria-disabled="true"])`,rr="cmdk-item-select",ri="data-value",rs=(e,t,n)=>{var r;return r=e,function e(t,n,r,i,s,o,a){if(o===n.length)return s===t.length?1:.99;var l=`${s},${o}`;if(void 0!==a[l])return a[l];for(var c,d,u,p,h=i.charAt(o),m=r.indexOf(h,s),f=0;m>=0;)(c=e(t,n,r,i,m+1,o+1,a))>f&&(m===s?c*=1:n3.test(t.charAt(m-1))?(c*=.8,(u=t.slice(s,m-1).match(n4))&&s>0&&(c*=Math.pow(.999,u.length))):n6.test(t.charAt(m-1))?(c*=.9,(p=t.slice(s,m-1).match(n9))&&s>0&&(c*=Math.pow(.999,p.length))):(c*=.17,s>0&&(c*=Math.pow(.999,m-s))),t.charAt(m)!==n.charAt(o)&&(c*=.9999)),(c<.1&&r.charAt(m-1)===i.charAt(o+1)||i.charAt(o+1)===i.charAt(o)&&r.charAt(m-1)!==i.charAt(o))&&.1*(d=e(t,n,r,i,m+1,o+2,a))>c&&(c=.1*d),c>f&&(f=c),m=r.indexOf(h,m+1);return a[l]=f,f}(r=n&&n.length>0?`${r+" "+n.join(" ")}`:r,t,n7(r),n7(t),0,0,{})},ro=m.createContext(void 0),ra=m.createContext(void 0),rl=m.createContext(void 0),rc=m.forwardRef((e,t)=>{let n=ry(()=>{var t,n;return{search:"",value:null!=(n=null!=(t=e.value)?t:e.defaultValue)?n:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=ry(()=>new Set),i=ry(()=>new Map),s=ry(()=>new Map),o=ry(()=>new Set),a=rx(e),{label:l,children:c,value:d,onValueChange:u,filter:p,shouldFilter:h,loop:f,disablePointerSelection:g=!1,vimBindings:x=!0,...b}=e,y=(0,S.useId)(),v=(0,S.useId)(),w=(0,S.useId)(),k=m.useRef(null),N=rk();rb(()=>{if(void 0!==d){let e=d.trim();n.current.value=e,C.emit()}},[d]),rb(()=>{N(6,O)},[]);let C=m.useMemo(()=>({subscribe:e=>(o.current.add(e),()=>o.current.delete(e)),snapshot:()=>n.current,setState:(e,t,r)=>{var i,s,o,l;if(!Object.is(n.current[e],t)){if(n.current[e]=t,"search"===e)T(),M(),N(1,A);else if("value"===e){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let e=document.getElementById(w);e?e.focus():null==(i=document.getElementById(y))||i.focus()}if(N(7,()=>{var e;n.current.selectedItemId=null==(e=_())?void 0:e.id,C.emit()}),r||N(5,O),(null==(s=a.current)?void 0:s.value)!==void 0){null==(l=(o=a.current).onValueChange)||l.call(o,null!=t?t:"");return}}C.emit()}},emit:()=>{o.current.forEach(e=>e())}}),[]),j=m.useMemo(()=>({value:(e,t,r)=>{var i;t!==(null==(i=s.current.get(e))?void 0:i.value)&&(s.current.set(e,{value:t,keywords:r}),n.current.filtered.items.set(e,E(t,r)),N(2,()=>{M(),C.emit()}))},item:(e,t)=>(r.current.add(e),t&&(i.current.has(t)?i.current.get(t).add(e):i.current.set(t,new Set([e]))),N(3,()=>{T(),M(),n.current.value||A(),C.emit()}),()=>{s.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=_();N(4,()=>{T(),(null==t?void 0:t.getAttribute("id"))===e&&A(),C.emit()})}),group:e=>(i.current.has(e)||i.current.set(e,new Set),()=>{s.current.delete(e),i.current.delete(e)}),filter:()=>a.current.shouldFilter,label:l||e["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:y,inputId:w,labelId:v,listInnerRef:k}),[]);function E(e,t){var r,i;let s=null!=(i=null==(r=a.current)?void 0:r.filter)?i:rs;return e?s(e,n.current.search,t):0}function M(){if(!n.current.search||!1===a.current.shouldFilter)return;let e=n.current.filtered.items,t=[];n.current.filtered.groups.forEach(n=>{let r=i.current.get(n),s=0;r.forEach(t=>{s=Math.max(e.get(t),s)}),t.push([n,s])});let r=k.current;D().sort((t,n)=>{var r,i;let s=t.getAttribute("id"),o=n.getAttribute("id");return(null!=(r=e.get(o))?r:0)-(null!=(i=e.get(s))?i:0)}).forEach(e=>{let t=e.closest(re);t?t.appendChild(e.parentElement===t?e:e.closest(`${re} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${re} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{var t;let n=null==(t=k.current)?void 0:t.querySelector(`${n8}[${ri}="${encodeURIComponent(e[0])}"]`);null==n||n.parentElement.appendChild(n)})}function A(){let e=D().find(e=>"true"!==e.getAttribute("aria-disabled")),t=null==e?void 0:e.getAttribute(ri);C.setState("value",t||void 0)}function T(){var e,t,o,l;if(!n.current.search||!1===a.current.shouldFilter){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let c=0;for(let i of r.current){let r=E(null!=(t=null==(e=s.current.get(i))?void 0:e.value)?t:"",null!=(l=null==(o=s.current.get(i))?void 0:o.keywords)?l:[]);n.current.filtered.items.set(i,r),r>0&&c++}for(let[e,t]of i.current)for(let r of t)if(n.current.filtered.items.get(r)>0){n.current.filtered.groups.add(e);break}n.current.filtered.count=c}function O(){var e,t,n;let r=_();r&&((null==(e=r.parentElement)?void 0:e.firstChild)===r&&(null==(n=null==(t=r.closest(n8))?void 0:t.querySelector('[cmdk-group-heading=""]'))||n.scrollIntoView({block:"nearest"})),r.scrollIntoView({block:"nearest"}))}function _(){var e;return null==(e=k.current)?void 0:e.querySelector(`${rt}[aria-selected="true"]`)}function D(){var e;return Array.from((null==(e=k.current)?void 0:e.querySelectorAll(rn))||[])}function R(e){let t=D()[e];t&&C.setState("value",t.getAttribute(ri))}function I(e){var t;let n=_(),r=D(),i=r.findIndex(e=>e===n),s=r[i+e];null!=(t=a.current)&&t.loop&&(s=i+e<0?r[r.length-1]:i+e===r.length?r[0]:r[i+e]),s&&C.setState("value",s.getAttribute(ri))}function L(e){let t=_(),n=null==t?void 0:t.closest(n8),r;for(;n&&!r;)r=null==(n=e>0?function(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}(n,n8):function(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}(n,n8))?void 0:n.querySelector(rn);r?C.setState("value",r.getAttribute(ri)):I(e)}let P=()=>R(D().length-1),$=e=>{e.preventDefault(),e.metaKey?P():e.altKey?L(1):I(1)},z=e=>{e.preventDefault(),e.metaKey?R(0):e.altKey?L(-1):I(-1)};return m.createElement(tx.div,{ref:t,tabIndex:-1,...b,"cmdk-root":"",onKeyDown:e=>{var t;null==(t=b.onKeyDown)||t.call(b,e);let n=e.nativeEvent.isComposing||229===e.keyCode;if(!(e.defaultPrevented||n))switch(e.key){case"n":case"j":x&&e.ctrlKey&&$(e);break;case"ArrowDown":$(e);break;case"p":case"k":x&&e.ctrlKey&&z(e);break;case"ArrowUp":z(e);break;case"Home":e.preventDefault(),R(0);break;case"End":e.preventDefault(),P();break;case"Enter":{e.preventDefault();let t=_();if(t){let e=new Event(rr);t.dispatchEvent(e)}}}}},m.createElement("label",{"cmdk-label":"",htmlFor:j.inputId,id:j.labelId,style:rS},l),rN(e,e=>m.createElement(ra.Provider,{value:C},m.createElement(ro.Provider,{value:j},e))))}),rd=m.forwardRef((e,t)=>{var n,r;let i=(0,S.useId)(),s=m.useRef(null),o=m.useContext(rl),a=m.useContext(ro),l=rx(e),c=null!=(r=null==(n=l.current)?void 0:n.forceMount)?r:null==o?void 0:o.forceMount;rb(()=>{if(!c)return a.item(i,null==o?void 0:o.id)},[c]);let d=rw(i,s,[e.value,e.children,s],e.keywords),u=m.useContext(ra),p=rv(e=>e.value&&e.value===d.current),h=rv(e=>!!c||!1===a.filter()||!e.search||e.filtered.items.get(i)>0);function f(){var e,t;g(),null==(t=(e=l.current).onSelect)||t.call(e,d.current)}function g(){u.setState("value",d.current,!0)}if(m.useEffect(()=>{let t=s.current;if(!(!t||e.disabled))return t.addEventListener(rr,f),()=>t.removeEventListener(rr,f)},[h,e.onSelect,e.disabled]),!h)return null;let{disabled:x,value:b,onSelect:y,forceMount:v,keywords:w,...N}=e;return m.createElement(tx.div,{ref:(0,k.composeRefs)(s,t),...N,id:i,"cmdk-item":"",role:"option","aria-disabled":!!x,"aria-selected":!!p,"data-disabled":!!x,"data-selected":!!p,onPointerMove:x||a.getDisablePointerSelection()?void 0:g,onClick:x?void 0:f},e.children)}),ru=m.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...s}=e,o=(0,S.useId)(),a=m.useRef(null),l=m.useRef(null),c=(0,S.useId)(),d=m.useContext(ro),u=rv(e=>!!i||!1===d.filter()||!e.search||e.filtered.groups.has(o));rb(()=>d.group(o),[]),rw(o,a,[e.value,e.heading,l]);let p=m.useMemo(()=>({id:o,forceMount:i}),[i]);return m.createElement(tx.div,{ref:(0,k.composeRefs)(a,t),...s,"cmdk-group":"",role:"presentation",hidden:!u||void 0},n&&m.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:c},n),rN(e,e=>m.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?c:void 0},m.createElement(rl.Provider,{value:p},e))))}),rp=m.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=m.useRef(null),s=rv(e=>!e.search);return n||s?m.createElement(tx.div,{ref:(0,k.composeRefs)(i,t),...r,"cmdk-separator":"",role:"separator"}):null}),rh=m.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=null!=e.value,s=m.useContext(ra),o=rv(e=>e.search),a=rv(e=>e.selectedItemId),l=m.useContext(ro);return m.useEffect(()=>{null!=e.value&&s.setState("search",e.value)},[e.value]),m.createElement(tx.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":a,id:l.inputId,type:"text",value:i?e.value:o,onChange:e=>{i||s.setState("search",e.target.value),null==n||n(e.target.value)}})}),rm=m.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...i}=e,s=m.useRef(null),o=m.useRef(null),a=rv(e=>e.selectedItemId),l=m.useContext(ro);return m.useEffect(()=>{if(o.current&&s.current){let e=o.current,t=s.current,n,r=new ResizeObserver(()=>{n=requestAnimationFrame(()=>{let n=e.offsetHeight;t.style.setProperty("--cmdk-list-height",n.toFixed(1)+"px")})});return r.observe(e),()=>{cancelAnimationFrame(n),r.unobserve(e)}}},[]),m.createElement(tx.div,{ref:(0,k.composeRefs)(s,t),...i,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:l.listId},rN(e,e=>m.createElement("div",{ref:(0,k.composeRefs)(o,l.listInnerRef),"cmdk-list-sizer":""},e)))}),rf=m.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:s,container:o,...a}=e;return m.createElement(B,{open:n,onOpenChange:r},m.createElement(W,{container:o},m.createElement(K,{"cmdk-overlay":"",className:i}),m.createElement(X,{"aria-label":e.label,"cmdk-dialog":"",className:s},m.createElement(rc,{ref:t,...a}))))}),rg=Object.assign(rc,{List:rm,Item:rd,Input:rh,Group:ru,Separator:rp,Dialog:rf,Empty:m.forwardRef((e,t)=>rv(e=>0===e.filtered.count)?m.createElement(tx.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),Loading:m.forwardRef((e,t)=>{let{progress:n,children:r,label:i="Loading...",...s}=e;return m.createElement(tx.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},rN(e,e=>m.createElement("div",{"aria-hidden":!0},e)))})});function rx(e){let t=m.useRef(e);return rb(()=>{t.current=e}),t}var rb="u"<typeof window?m.useEffect:m.useLayoutEffect;function ry(e){let t=m.useRef();return void 0===t.current&&(t.current=e()),t}function rv(e){let t=m.useContext(ra),n=()=>e(t.snapshot());return m.useSyncExternalStore(t.subscribe,n,n)}function rw(e,t,n,r=[]){let i=m.useRef(),s=m.useContext(ro);return rb(()=>{var o;let a=(()=>{var e;for(let t of n){if("string"==typeof t)return t.trim();if("object"==typeof t&&"current"in t)return t.current?null==(e=t.current.textContent)?void 0:e.trim():i.current}})(),l=r.map(e=>e.trim());s.value(e,a,l),null==(o=t.current)||o.setAttribute(ri,a),i.current=a}),i}var rk=()=>{let[e,t]=m.useState(),n=ry(()=>new Map);return rb(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function rN({asChild:e,children:t},n){let r;return e&&m.isValidElement(t)?m.cloneElement("function"==typeof(r=t.type)?r(t.props):"render"in r?r.render(t.props):t,{ref:t.ref},n(t.props.children)):n(t)}var rS={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};let rC=(0,o.default)("search",[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]),rj=m.forwardRef(({className:e,...t},n)=>(0,s.jsx)(rg,{ref:n,className:(0,eh.cn)("flex h-full w-full flex-col overflow-hidden rounded-sm bg-popover text-popover-foreground",e),...t}));function rE({children:e,shouldFilter:t,...n}){return(0,s.jsx)(B,{...n,children:(0,s.jsxs)(eq,{className:"overflow-hidden p-0 shadow-golden max-w-lg",children:[(0,s.jsx)(eJ,{className:"sr-only",children:"Search"}),(0,s.jsx)(rj,{shouldFilter:t,className:"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-normal [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5",children:e})]})})}rj.displayName=rg.displayName;let rM=m.forwardRef(({className:e,...t},n)=>(0,s.jsxs)("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[(0,s.jsx)(rC,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),(0,s.jsx)(rg.Input,{ref:n,className:(0,eh.cn)("flex h-11 w-full rounded-sm bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...t})]}));rM.displayName=rg.Input.displayName;let rA=m.forwardRef(({className:e,...t},n)=>(0,s.jsx)(rg.List,{ref:n,className:(0,eh.cn)("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));rA.displayName=rg.List.displayName;let rT=m.forwardRef((e,t)=>(0,s.jsx)(rg.Empty,{ref:t,className:"py-6 text-center text-sm text-muted-foreground",...e}));rT.displayName=rg.Empty.displayName;let rO=m.forwardRef(({className:e,...t},n)=>(0,s.jsx)(rg.Group,{ref:n,className:(0,eh.cn)("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-normal [&_[cmdk-group-heading]]:text-muted-foreground",e),...t}));rO.displayName=rg.Group.displayName;let r_=m.forwardRef(({className:e,...t},n)=>(0,s.jsx)(rg.Separator,{ref:n,className:(0,eh.cn)("-mx-1 h-px bg-border",e),...t}));r_.displayName=rg.Separator.displayName;let rD=m.forwardRef(({className:e,...t},n)=>(0,s.jsx)(rg.Item,{ref:n,className:(0,eh.cn)("relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",e),...t}));rD.displayName=rg.Item.displayName;let rR=null,rI=null,rL=(0,eN.create)(e=>({query:"",results:[],loading:!1,truncated:!1,open:!1,setQuery:t=>e({query:t}),setOpen:t=>e({open:t}),clear:()=>{rI&&clearTimeout(rI),rR?.abort(),e({query:"",results:[],loading:!1,truncated:!1})},search:t=>(rI&&clearTimeout(rI),t.trim())?(e({loading:!0}),new Promise(n=>{rI=setTimeout(()=>{rP(e,t).finally(n)},150)})):(rR?.abort(),e({results:[],loading:!1,truncated:!1}),Promise.resolve())}));async function rP(e,t){rR?.abort();let n=new AbortController;rR=n;try{let r=await (0,tk.wsFetch)("/api/wiki/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t,limit:30}),signal:n.signal});if(!r.ok)return void e({results:[],loading:!1,truncated:!1});let i=await r.json();if(n.signal.aborted)return;e({results:i.matches??[],truncated:!!i.truncated,loading:!1})}catch(t){"AbortError"!==t.name&&e({loading:!1})}}var r$=e.i(395624);function rz({html:e}){let t=function(e){let t,n=[],r=/<mark>([\s\S]*?)<\/mark>/g,i=0;for(;null!==(t=r.exec(e));)t.index>i&&n.push({text:e.slice(i,t.index),mark:!1}),n.push({text:t[1]??"",mark:!0}),i=t.index+t[0].length;return i<e.length&&n.push({text:e.slice(i),mark:!1}),n}(e);return(0,s.jsx)(s.Fragment,{children:t.map((e,t)=>e.mark?(0,s.jsx)("mark",{className:"bg-yellow-200 dark:bg-yellow-700 rounded-[2px] px-[1px]",children:e.text},t):(0,s.jsx)("span",{children:e.text},t))})}function rB({onOpenFile:e,recents:t=[],onToggleSidebar:n=()=>void 0,onNewFile:r=()=>void 0,onCopyPath:i=()=>void 0}){let o=rL(e=>e.open),l=rL(e=>e.setOpen),c=rL(e=>e.query),d=rL(e=>e.setQuery),u=rL(e=>e.results),p=rL(e=>e.loading),h=rL(e=>e.truncated),f=rL(e=>e.search),{resolvedTheme:g,setTheme:x}=(0,n5.useTheme)(),b=tj(e=>e.toggle),y=(0,r$.useViewWidthStore)(e=>e.width),v=(0,r$.useViewWidthStore)(e=>e.cycle),w=c.trimStart(),k=""===w||w.startsWith(">"),N=""===w&&t.length>0,S=k?"":c;function C(e){e(),l(!1),d("")}(0,m.useEffect)(()=>{function e(e){(e.metaKey||e.ctrlKey)&&"k"===e.key.toLowerCase()&&(e.preventDefault(),l(!o))}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[o,l]),(0,m.useEffect)(()=>{if(!o||k)return;let e=setTimeout(()=>{f(S)},120);return()=>clearTimeout(e)},[S,k,o,f]);let j=(r$.VIEW_WIDTH_ORDER.indexOf(y)+1)%r$.VIEW_WIDTH_ORDER.length,E=r$.VIEW_WIDTH_LABEL[r$.VIEW_WIDTH_ORDER[j]];return(0,s.jsxs)(rE,{open:o,onOpenChange:e=>{l(e),e||d("")},shouldFilter:!1,children:[(0,s.jsx)(rM,{placeholder:"Search files… ( > for actions )",value:c,onValueChange:d}),(0,s.jsxs)(rA,{children:[N&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(rO,{heading:"Recent",children:t.map(t=>(0,s.jsxs)(rD,{value:`recent:${t.path}`,onSelect:()=>{e(t.path),l(!1),d("")},children:[(0,s.jsx)(tt,{className:"mr-2 h-4 w-4"}),(0,s.jsxs)("div",{className:"flex min-w-0 flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"truncate font-medium",children:t.name}),(0,s.jsx)("span",{className:"truncate text-xs text-muted-foreground",children:t.path})]})]},t.path))}),(0,s.jsx)(r_,{})]}),k&&(0,s.jsxs)(rO,{heading:"Actions",children:[(0,s.jsxs)(rD,{value:"toggle-dark-mode",onSelect:()=>C(()=>x("dark"===g?"light":"dark")),children:["dark"===g?(0,s.jsx)(n2.Sun,{className:"mr-2 h-4 w-4"}):(0,s.jsx)(n0.Moon,{className:"mr-2 h-4 w-4"}),"dark"===g?"Switch to light mode":"Switch to dark mode"]}),(0,s.jsxs)(rD,{value:"toggle-ai-panel",onSelect:()=>C(b),children:[(0,s.jsx)(a,{className:"mr-2 h-4 w-4"}),"Toggle AI panel"]}),(0,s.jsxs)(rD,{value:"toggle-sidebar",onSelect:()=>C(n),children:[(0,s.jsx)(n1,{className:"mr-2 h-4 w-4"}),"Toggle sidebar"]}),(0,s.jsxs)(rD,{value:"new-file",onSelect:()=>C(r),children:[(0,s.jsx)(t7,{className:"mr-2 h-4 w-4"}),"New file"]}),(0,s.jsxs)(rD,{value:"copy-path",onSelect:()=>C(i),children:[(0,s.jsx)(e7.Copy,{className:"mr-2 h-4 w-4"}),"Copy current file path"]}),(0,s.jsxs)(rD,{value:"cycle-view-width",onSelect:()=>C(v),children:[(0,s.jsx)(nQ,{className:"mr-2 h-4 w-4"}),(0,s.jsxs)("span",{children:["Change view width"," ",(0,s.jsxs)("span",{className:"text-muted-foreground",children:["(",r$.VIEW_WIDTH_LABEL[y]," → ",E,")"]})]})]})]}),!k&&(0,s.jsxs)(s.Fragment,{children:[p&&(0,s.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:"Searching…"}),!p&&""!==S.trim()&&0===u.length&&(0,s.jsx)(rT,{children:"No matches."}),u.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r_,{}),(0,s.jsx)(rO,{heading:h?"Top results (refine query for more)":"Results",children:u.map(t=>(0,s.jsx)(rD,{value:t.path,onSelect:()=>{e(t.path),l(!1),d("")},children:(0,s.jsxs)("div",{className:"flex min-w-0 flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"truncate text-xs",children:t.path}),t.snippet&&(0,s.jsx)("span",{className:"truncate text-xs text-muted-foreground",children:(0,s.jsx)(rz,{html:t.snippet})})]})},t.path))})]})]})]})]})}e.i(262678);let rF=(0,o.default)("cloud-download",[["path",{d:"M12 13v8l-4-4",key:"1f5nwf"}],["path",{d:"m12 21 4-4",key:"1lfcce"}],["path",{d:"M4.393 15.269A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.436 8.284",key:"ui1hmy"}]]);var rH=e.i(301138);let rU=(0,o.default)("eye-off",[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]),rV=(0,o.default)("history",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]]),rW=(0,o.default)("panel-left-close",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m16 15-3-3 3-3",key:"14y99z"}]]),rq=(0,o.default)("plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]),rK=(0,o.default)("settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);var rG=e.i(109680);function rJ({onOpenFile:e}){let t=rL(e=>e.query),n=rL(e=>e.setQuery),r=rL(e=>e.results),i=rL(e=>e.loading),o=rL(e=>e.search),a=rL(e=>e.clear),[l,c]=(0,m.useState)(0),d=(0,m.useRef)(null);function u(t){let n=r[t];n&&(e(n.path),a())}return(0,m.useEffect)(()=>{c(0)},[r]),(0,m.useEffect)(()=>{let e=d.current?.querySelector(`[data-idx="${l}"]`);e?.scrollIntoView({block:"nearest"})},[l]),(0,s.jsxs)("div",{className:"flex flex-col gap-1 px-2 py-1.5",children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(rC,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 opacity-50"}),(0,s.jsx)("input",{type:"text",className:"w-full rounded-sm bg-muted py-1 pl-7 pr-2 text-xs outline-none focus:ring-1 focus:ring-ring",placeholder:"Search… (⌘K)",value:t,onChange:e=>{n(e.target.value),o(e.target.value)},onKeyDown:e=>{"Escape"===e.key?a():0!==r.length&&("ArrowDown"===e.key?(e.preventDefault(),c(e=>(e+1)%r.length)):"ArrowUp"===e.key?(e.preventDefault(),c(e=>(e-1+r.length)%r.length)):"Enter"===e.key&&(e.preventDefault(),u(l)))}})]}),""!==t.trim()&&(0,s.jsxs)("div",{ref:d,className:"max-h-64 overflow-y-auto rounded-sm border bg-popover",children:[i&&(0,s.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"Searching…"}),!i&&0===r.length&&(0,s.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"No matches"}),r.map((e,t)=>(0,s.jsxs)("button",{type:"button","data-idx":t,onClick:()=>u(t),onMouseEnter:()=>c(t),className:`block w-full px-2 py-1 text-left ${t===l?"bg-accent":"hover:bg-accent"}`,children:[(0,s.jsx)("div",{className:"truncate text-xs",children:e.path}),e.snippet&&(0,s.jsx)("div",{className:"truncate text-[10px] text-muted-foreground",children:(0,s.jsx)(rz,{html:e.snippet})})]},e.path))]})]})}var rZ=e.i(515288);let rX=/^[a-z0-9][a-z0-9-]*$/,rY=new Set(["api","app","s","signin","_next","assets"]);function rQ(){let e,t=ni(e=>e.dialog),n=ni(e=>e.apps),r=ni(e=>e.create),i=ni(e=>e.refresh),o=ni(e=>e.closeHostDialog),[a,l]=(0,m.useState)(""),[c,d]=(0,m.useState)(""),[p,h]=(0,m.useState)([]),[f,g]=(0,m.useState)(!1),[x,b]=(0,m.useState)(null);if((0,m.useEffect)(()=>{t&&(l(t.defaultSlug),d(""),h([]),b(null),i(),"node"===t.type&&(0,tk.wsFetch)(`/api/wiki/app?path=${encodeURIComponent(t.relPath)}`).then(async e=>{if(!e.ok)return;let t=await e.json(),n=t.scripts??[];h(n),d(t.defaultScript??n[0]??"")}).catch(()=>{}))},[t,i]),!t)return null;let y=new Set(n.map(e=>e.slug)),w=(e=a.trim())?rX.test(e)?rY.has(e)?`"${e}" is a reserved name`:y.has(e)?`"${e}" is already taken`:null:"Lowercase letters, numbers, and hyphens only (e.g. my-app)":"Slug is required",k=f||null!==w,N=async()=>{if(w)return;g(!0),b(null);let e=await r({slug:a.trim(),relPath:t.relPath,type:t.type??"html",script:"node"===t.type&&c?c:void 0});g(!1),e.ok?o():b(e.message??e.error??"Failed to host app")};return(0,s.jsx)(B,{open:!!t,onOpenChange:e=>!e&&o(),children:(0,s.jsxs)(eq,{className:"sm:max-w-md",children:[(0,s.jsxs)(eK,{children:[(0,s.jsx)(eJ,{children:"Host this app"}),(0,s.jsxs)(eZ,{children:["Give this directory a short slug. It will be reachable at"," ",(0,s.jsxs)("code",{className:"text-xs",children:["/app/",a||"<slug>","/"]}),"."]})]}),(0,s.jsxs)("div",{className:"space-y-2 py-2",children:[(0,s.jsx)(tw,{htmlFor:"host-slug",children:"Slug"}),(0,s.jsx)(tn.Input,{id:"host-slug",autoFocus:!0,value:a,onChange:e=>{l(e.target.value),b(null)},onKeyDown:e=>{"Enter"!==e.key||k||N()},placeholder:"my-app","aria-invalid":!!(w||x)}),"node"===t.type&&p.length>0&&(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(tw,{htmlFor:"host-script",children:"Start script"}),(0,s.jsx)("select",{id:"host-script",className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-1 text-sm",value:c,onChange:e=>d(e.target.value),children:p.map(e=>(0,s.jsx)("option",{value:e,children:e},e))})]}),(0,s.jsx)("p",{className:"min-h-[1rem] text-xs text-muted-foreground",children:(0,s.jsx)("span",{className:"truncate",children:t.relPath||"(workspace root)"})}),(w||x)&&(0,s.jsx)("p",{className:"text-xs text-destructive",children:x??w})]}),(0,s.jsxs)(eG,{children:[(0,s.jsx)(v.Button,{variant:"ghost",onClick:o,disabled:f,children:"Cancel"}),(0,s.jsxs)(v.Button,{onClick:()=>void N(),disabled:k,children:[f&&(0,s.jsx)(u.Loader2,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Host"]})]})]})})}let r0=(0,o.default)("pin",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]),r1=(0,o.default)("pin-off",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89",key:"znwnzq"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11",key:"c9qhm2"}]]);var r2=e.i(727551);let r5=(0,o.default)("square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);var r3=e.i(638154),r4="Popover",[r6,r9]=(0,N.createContextScope)(r4,[r3.createPopperScope]),r7=(0,r3.createPopperScope)(),[r8,ie]=r6(r4),it=e=>{let{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:o,modal:a=!1}=e,l=r7(t),c=m.useRef(null),[d,u]=m.useState(!1),[p,h]=(0,C.useControllableState)({prop:r,defaultProp:i??!1,onChange:o,caller:r4});return(0,s.jsx)(r3.Root,{...l,children:(0,s.jsx)(r8,{scope:t,contentId:(0,S.useId)(),triggerRef:c,open:p,onOpenChange:h,onOpenToggle:m.useCallback(()=>h(e=>!e),[h]),hasCustomAnchor:d,onCustomAnchorAdd:m.useCallback(()=>u(!0),[]),onCustomAnchorRemove:m.useCallback(()=>u(!1),[]),modal:a,children:n})})};it.displayName=r4;var ir="PopoverAnchor",ii=m.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=ie(ir,n),o=r7(n),{onCustomAnchorAdd:a,onCustomAnchorRemove:l}=i;return m.useEffect(()=>(a(),()=>l()),[a,l]),(0,s.jsx)(r3.Anchor,{...o,...r,ref:t})});ii.displayName=ir;var is="PopoverTrigger",io=m.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=ie(is,n),o=r7(n),a=(0,k.useComposedRefs)(t,i.triggerRef),l=(0,s.jsx)(T.Primitive.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":iv(i.open),...r,ref:a,onClick:(0,w.composeEventHandlers)(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:(0,s.jsx)(r3.Anchor,{asChild:!0,...o,children:l})});io.displayName=is;var ia="PopoverPortal",[il,ic]=r6(ia,{forceMount:void 0}),id=e=>{let{__scopePopover:t,forceMount:n,children:r,container:i}=e,o=ie(ia,t);return(0,s.jsx)(il,{scope:t,forceMount:n,children:(0,s.jsx)(A.Presence,{present:n||o.open,children:(0,s.jsx)(M.Portal,{asChild:!0,container:i,children:r})})})};id.displayName=ia;var iu="PopoverContent",ip=m.forwardRef((e,t)=>{let n=ic(iu,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,o=ie(iu,e.__scopePopover);return(0,s.jsx)(A.Presence,{present:r||o.open,children:o.modal?(0,s.jsx)(im,{...i,ref:t}):(0,s.jsx)(ig,{...i,ref:t})})});ip.displayName=iu;var ih=(0,R.createSlot)("PopoverContent.RemoveScroll"),im=m.forwardRef((e,t)=>{let n=ie(iu,e.__scopePopover),r=m.useRef(null),i=(0,k.useComposedRefs)(t,r),o=m.useRef(!1);return m.useEffect(()=>{let e=r.current;if(e)return(0,D.hideOthers)(e)},[]),(0,s.jsx)(_.RemoveScroll,{as:ih,allowPinchZoom:!0,children:(0,s.jsx)(ix,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:(0,w.composeEventHandlers)(e.onCloseAutoFocus,e=>{e.preventDefault(),o.current||n.triggerRef.current?.focus()}),onPointerDownOutside:(0,w.composeEventHandlers)(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=0===t.button&&!0===t.ctrlKey;o.current=2===t.button||n},{checkForDefaultPrevented:!1}),onFocusOutside:(0,w.composeEventHandlers)(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1})})})}),ig=m.forwardRef((e,t)=>{let n=ie(iu,e.__scopePopover),r=m.useRef(!1),i=m.useRef(!1);return(0,s.jsx)(ix,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,"pointerdown"===t.detail.originalEvent.type&&(i.current=!0));let s=t.target;n.triggerRef.current?.contains(s)&&t.preventDefault(),"focusin"===t.detail.originalEvent.type&&i.current&&t.preventDefault()}})}),ix=m.forwardRef((e,t)=>{let{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:o,disableOutsidePointerEvents:a,onEscapeKeyDown:l,onPointerDownOutside:c,onFocusOutside:d,onInteractOutside:u,...p}=e,h=ie(iu,n),m=r7(n);return(0,O.useFocusGuards)(),(0,s.jsx)(E.FocusScope,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:o,children:(0,s.jsx)(j.DismissableLayer,{asChild:!0,disableOutsidePointerEvents:a,onInteractOutside:u,onEscapeKeyDown:l,onPointerDownOutside:c,onFocusOutside:d,onDismiss:()=>h.onOpenChange(!1),children:(0,s.jsx)(r3.Content,{"data-state":iv(h.open),role:"dialog",id:h.contentId,...m,...p,ref:t,style:{...p.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),ib="PopoverClose";m.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=ie(ib,n);return(0,s.jsx)(T.Primitive.button,{type:"button",...r,ref:t,onClick:(0,w.composeEventHandlers)(e.onClick,()=>i.onOpenChange(!1))})}).displayName=ib;var iy=m.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=r7(n);return(0,s.jsx)(r3.Arrow,{...i,...r,ref:t})});function iv(e){return e?"open":"closed"}function iw(e){let t=(0,ev.apiUrl)(`/app/${e}/`);return`${window.location.origin}${t}`}function ik(){let e=ni(e=>e.collapsed),t=ni(e=>e.toggleCollapsed),n=ni(e=>e.apps),r=ni(e=>e.loading),i=ni(e=>e.loaded),o=ni(e=>e.remove),a=ni(e=>e.start),l=ni(e=>e.stop),d=ni(e=>e.pin),p=ni(e=>e.unpin),f=ni(e=>e.restart),[b,y]=(0,m.useState)(null),[w,k]=(0,m.useState)(null),N=async e=>{try{await navigator.clipboard.writeText(iw(e)),y(e),setTimeout(()=>y(t=>t===e?null:t),1200)}catch{}};return(0,s.jsxs)("div",{className:"border-b mb-1",children:[(0,s.jsxs)("button",{type:"button",className:"flex w-full items-center gap-1 px-2 py-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground hover:text-foreground",onClick:t,children:[e?(0,s.jsx)(eY.ChevronRight,{className:"h-3 w-3"}):(0,s.jsx)(x,{className:"h-3 w-3"}),(0,s.jsx)(e5,{className:"h-3 w-3"}),"Hosted Apps",(0,s.jsx)("span",{className:"ml-auto text-[9px] tabular-nums opacity-60",children:i?n.length:""})]}),!e&&(0,s.jsx)("div",{className:"pb-1",children:r&&0===n.length?(0,s.jsx)("div",{className:"flex justify-center py-3",children:(0,s.jsx)(u.Loader2,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):0===n.length?(0,s.jsx)("p",{className:"px-3 py-2 text-[11px] text-muted-foreground/70",children:"No hosted apps yet. Use “Host this app” from a website directory."}):[...n].sort((e,t)=>Number(!!t.persist)-Number(!!e.persist)).map(e=>{let t,n;return(0,s.jsxs)("div",{role:"button",tabIndex:0,className:"group flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer transition-colors select-none hover:bg-muted",onClick:()=>window.open(iw(e.slug),"_blank"),onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),window.open(iw(e.slug),"_blank"))},children:["node"===e.type?(0,s.jsx)(nt,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500"}):(0,s.jsx)(c,{className:"h-3.5 w-3.5 shrink-0 text-sky-500"}),"node"===e.type&&(t="error"===e.status||"missing"===e.status,n=(0,s.jsx)("span",{className:(0,eh.cn)("h-2 w-2 shrink-0 rounded-full","running"===e.status?"bg-emerald-500":t?"bg-destructive":"bg-muted-foreground/50"),title:e.status??"stopped"}),t?(0,s.jsxs)(it,{open:w===e.slug,onOpenChange:t=>k(t?e.slug:null),children:[(0,s.jsx)(io,{asChild:!0,children:(0,s.jsx)("button",{type:"button",className:"rounded-full focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",onClick:e=>e.stopPropagation(),"aria-label":`Show ${e.status} details for ${e.slug}`,children:n})}),(0,s.jsx)(id,{children:(0,s.jsxs)(ip,{side:"right",align:"start",className:"z-50 w-72 rounded-md border bg-popover p-3 text-popover-foreground shadow-md outline-none",onClick:e=>e.stopPropagation(),children:[(0,s.jsx)("p",{className:"text-xs font-medium text-destructive",children:"missing"===e.status?"Source directory missing":"App stopped after repeated crashes"}),(0,s.jsx)("p",{className:"mt-1 text-xs text-muted-foreground break-words",children:e.lastError??e.error??"No error details available."}),(e.logs?.length??0)>0&&(0,s.jsx)("pre",{className:"mt-2 max-h-28 overflow-auto rounded bg-muted p-2 text-[10px] leading-4 whitespace-pre-wrap",children:e.logs?.slice(-8).join("\n")}),(0,s.jsxs)(v.Button,{size:"sm",variant:"outline",className:"mt-2 h-7 gap-1.5 text-xs",disabled:"missing"===e.status,onClick:()=>{k(null),f(e.slug)},children:[(0,s.jsx)(tA,{className:"h-3 w-3"}),"Restart now"]})]})})]}):n),(0,s.jsx)("span",{className:(0,eh.cn)("min-w-0 flex-1 truncate text-xs","node"===e.type&&("error"===e.status||"missing"===e.status)&&"text-destructive"),children:e.relPath.split("/").filter(Boolean).pop()||e.slug}),(0,s.jsxs)("span",{className:"max-w-[90px] truncate text-[10px] text-muted-foreground/60",children:["/",e.slug]}),"node"===e.type&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("button",{type:"button",className:"hover-reveal shrink-0 rounded p-0.5 text-muted-foreground/50 opacity-0 transition-colors hover:bg-muted hover:text-foreground group-hover:opacity-100 focus:opacity-100",title:e.persist?"Unpin app (disable boot restore)":"Pin app (restore on boot)",onClick:t=>{t.stopPropagation(),e.persist?p(e.slug):d(e.slug)},children:e.persist?(0,s.jsx)(r0,{className:"h-3 w-3 text-primary"}):(0,s.jsx)(r1,{className:"h-3 w-3"})}),(0,s.jsx)("button",{type:"button",className:"hover-reveal shrink-0 rounded p-0.5 text-muted-foreground/50 opacity-0 transition-colors hover:bg-muted hover:text-foreground group-hover:opacity-100 focus:opacity-100",title:"running"===e.status?"Stop app":"Start app",onClick:t=>{t.stopPropagation(),"running"===e.status?l(e.slug):a(e.slug)},children:"running"===e.status?(0,s.jsx)(r5,{className:"h-3 w-3"}):(0,s.jsx)(r2.Play,{className:"h-3 w-3"})})]}),(0,s.jsx)("button",{type:"button",className:"hover-reveal shrink-0 rounded p-0.5 text-muted-foreground/50 opacity-0 transition-colors hover:bg-muted hover:text-foreground group-hover:opacity-100 focus:opacity-100",title:"Copy URL",onClick:t=>{t.stopPropagation(),N(e.slug)},children:b===e.slug?(0,s.jsx)(g.Check,{className:"h-3 w-3 text-emerald-500"}):(0,s.jsx)(e7.Copy,{className:"h-3 w-3"})}),(0,s.jsx)("button",{type:"button",className:(0,eh.cn)("hover-reveal shrink-0 rounded p-0.5 text-muted-foreground/50 opacity-0 transition-colors","hover:bg-muted hover:text-destructive group-hover:opacity-100 focus:opacity-100"),title:"Unhost",onClick:t=>{t.stopPropagation(),o(e.slug)},children:(0,s.jsx)(h,{className:"h-3 w-3"})})]},e.slug)})})]})}function iN({activeWorkspaceId:e,workspaceName:t,openPath:n,onOpen:r}){let[i,o]=(0,m.useState)(!1),[a,l]=(0,m.useState)(null);return((0,m.useEffect)(()=>{if(!e)return;let t=!1;return(async()=>{try{let e=await (0,tk.wsFetch)("/api/wiki/app?path=");if(!e.ok)return;let n=await e.json();if(t)return;o(!!n.isNodeApp),l(n.status??null)}catch{}})(),()=>{t=!0}},[e]),i)?(0,s.jsx)("div",{className:"border-b mb-1 px-2 py-1.5",children:(0,s.jsxs)("button",{type:"button",onClick:r,className:(0,eh.cn)("group flex w-full items-center gap-1.5 rounded-sm px-2 py-1 text-sm transition-colors",""===n?"bg-accent-soft text-foreground font-medium":"hover:bg-muted"),children:[(0,s.jsx)(nt,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500"}),(0,s.jsx)("span",{className:"min-w-0 flex-1 truncate text-left text-xs",children:t}),"running"===a?(0,s.jsx)("span",{className:"h-2 w-2 shrink-0 rounded-full bg-emerald-500",title:"Running"}):(0,s.jsx)(r2.Play,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/60 group-hover:text-foreground"})]})}):null}function iS(e){let t=new Date(e).getTime();if(!Number.isFinite(t))return"";let n=Math.floor(Math.max(0,Date.now()-t)/1e3);if(n<60)return"just now";let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function iC({workspaces:e,activeWorkspaceId:t,rootPath:n,isWsAdmin:r,refreshingWsId:i,switchingBranch:o,switchingBranchName:a,wsBranches:l,branchPickerWsId:c,wsBranchPos:d,onSwitchWorkspace:u,onRefreshWorkspace:p,onPromptDeleteWorkspace:h,onAddWorkspace:m,setBranchPickerWsId:f,setWsBranchPos:b,loadWsBranches:y,handleSwitchBranch:w}){return(0,s.jsxs)("div",{className:"border-t px-2 py-2 bg-muted shrink-0",children:[(0,s.jsxs)(ek.DropdownMenu,{modal:!1,onOpenChange:e=>{e||(f(null),b(null))},children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsxs)(v.Button,{size:"sm",variant:"ghost",className:"w-full h-auto justify-between gap-2 px-2 py-1.5 text-left",title:n??"",children:[(0,s.jsxs)("span",{className:"flex flex-col min-w-0",children:[(0,s.jsx)("span",{className:"truncate text-xs font-medium",children:e.find(e=>e.id===t)?.name??"Workspace"}),(0,s.jsx)("span",{className:"truncate text-[10px] text-muted-foreground",children:n??""})]}),(0,s.jsx)(x,{className:"h-3.5 w-3.5 shrink-0 opacity-60"})]})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"start",className:"w-[var(--radix-dropdown-menu-trigger-width)]",onInteractOutside:e=>{e.target?.closest?.("[data-branch-portal]")&&e.preventDefault()},children:[e.map(e=>(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>void u(e.id),onPointerMove:e=>e.preventDefault(),onPointerLeave:e=>e.preventDefault(),className:(0,eh.cn)("gap-2",e.id===t&&"font-medium"),children:[e.id===t?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 shrink-0"}):(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsxs)("span",{className:"flex flex-col min-w-0 flex-1",children:[(0,s.jsxs)("span",{className:"flex items-center gap-1.5 truncate",children:[(0,s.jsx)("span",{className:"truncate",children:e.name}),e.git?r?(0,s.jsxs)("button",{"data-branch-trigger":!0,type:"button",className:"inline-flex items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground font-normal shrink-0 hover:bg-accent",title:"Switch branch",disabled:o===e.id,onClick:t=>{if(t.stopPropagation(),t.preventDefault(),c===e.id){f(null),b(null);return}let n=t.currentTarget.getBoundingClientRect();b({top:n.bottom+4,left:n.left}),f(e.id),y(e.id)},children:[(0,s.jsx)(e1,{className:"h-2.5 w-2.5"})," ",e.git.branch??"branch"]}):(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground font-normal shrink-0",children:[(0,s.jsx)(e1,{className:"h-2.5 w-2.5"})," ",e.git.branch??"read-only"]}):e.ssh?(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground font-normal shrink-0",children:[(0,s.jsx)(e5,{className:"h-2.5 w-2.5"})," ",e.ssh.host]}):e.readOnly?(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground font-normal shrink-0",children:[(0,s.jsx)(e1,{className:"h-2.5 w-2.5"})," read-only"]}):null]}),(0,s.jsx)("span",{className:"truncate text-[10px] text-muted-foreground",children:e.rootDir}),e.git?.lastPulledAt&&iS(e.git.lastPulledAt)&&(0,s.jsxs)("span",{className:"text-[10px] text-muted-foreground/70",children:["synced ",iS(e.git.lastPulledAt)]})]}),r&&e.git&&(0,s.jsx)("button",{className:(0,eh.cn)("shrink-0 rounded p-0.5 hover:bg-accent transition-colors",e.git.lastError?"text-destructive":"text-muted-foreground hover:text-foreground"),title:e.git.lastError?`Last refresh failed: ${e.git.lastError}`:"Refresh",disabled:i===e.id,onClick:t=>{t.stopPropagation(),t.preventDefault(),p(e.id)},children:(0,s.jsx)(tA,{className:(0,eh.cn)("h-3.5 w-3.5",i===e.id&&"animate-spin")})}),r&&(0,s.jsx)("button",{className:"shrink-0 rounded p-0.5 text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors",title:"Delete workspace (does not delete files)",onClick:t=>{t.stopPropagation(),h(e.id)},children:(0,s.jsx)(te,{className:"h-3.5 w-3.5"})})]},e.id)),r&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:m,children:[(0,s.jsx)(t8,{className:"mr-2 h-3.5 w-3.5"}),"Add workspace…"]})]})]})]}),(()=>{if(!c||!d)return null;let t=e.find(e=>e.id===c);return t?(0,s.jsx)(ns,{pos:d,branches:(l[t.id]??[]).map(e=>({name:e,current:e===t.git?.branch})),loading:!l[t.id],busyName:o===t.id?a:null,disabled:o===t.id,onPick:e=>{w(t.id,e)},onClose:()=>{f(null),b(null)}}):null})()]})}iy.displayName="PopoverArrow";let ij="wiki-sidebar-width";function iE(e){return Number.isNaN(e)?288:Math.min(600,Math.max(200,Math.round(e)))}let iM=(0,eN.create)(e=>({width:function(){let e=localStorage.getItem(ij);if(e){let t=Number.parseInt(e,10);if(!Number.isNaN(t))return iE(t)}return 288}(),setWidth:t=>{let n=iE(t);localStorage.setItem(ij,String(n)),e({width:n})}}));function iA(e){return e.split("/").pop()??e}function iT({workspace:e,doc:t,fileTree:n,upload:r,isMobile:i,hideChrome:o,sidebarCollapsed:c,setSidebarCollapsed:d,sidebarResizing:p,setSidebarResizing:m,sidebarWidth:b,setSidebarWidth:y,collapsed:w,setCollapsed:k,createEntry:N,setCreateEntry:S,handleCreateFile:C,handleCreateFolder:j,dragOverPath:E,setDragOverPath:M,handleDragOver:A,handleDropOnFolder:T,sidebarScrollRef:O,treeCtx:_,favorites:D,recents:R,activePaths:I,setDialogs:L,handleRefreshWorkspace:P}){let{resolvedTheme:$,setTheme:z}=(0,n5.useTheme)(),B=nR(e=>e.humanize),F=nL(e=>e.showHidden);return(0,s.jsxs)(s.Fragment,{children:[!o&&!c&&i&&(0,s.jsx)("div",{className:"fixed inset-0 z-40 bg-overlay backdrop-blur-[1px] md:hidden",onClick:()=>d(!0),"aria-hidden":!0}),!o&&!c&&(0,s.jsxs)(rZ.Card,{style:i?void 0:{width:b},className:"fixed inset-y-0 left-0 z-50 w-[85vw] max-w-[20rem] md:relative md:z-auto md:w-auto md:max-w-none flex flex-col shrink-0 overflow-hidden rounded-none border-r border-l-0 border-t-0 border-b-0 bg-sidebar border-sidebar-border text-sidebar-foreground",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2 px-3 py-2 border-b bg-muted shrink-0",children:[(0,s.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",title:"Wiki Viewer v2.18.0",children:[(0,s.jsx)("img",{src:(0,ev.apiUrl)("/logo.svg"),alt:"Wiki Viewer",className:"h-5 w-5 shrink-0"}),(0,s.jsx)("span",{className:"truncate text-xs font-semibold leading-5 tracking-tight translate-y-[0.5px]",children:"Wiki Viewer"})]}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 shrink-0",title:"Collapse sidebar",onClick:()=>d(!0),children:(0,s.jsx)(rW,{className:"h-3.5 w-3.5"})})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between gap-1 px-3 py-1.5 border-b bg-muted/50 shrink-0",children:[(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsxs)(v.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1 px-2 text-xs",disabled:r.uploading,children:[r.uploading?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(rq,{className:"h-3.5 w-3.5"}),"New",(0,s.jsx)(x,{className:"h-3 w-3 opacity-60"})]})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"start",className:"w-44",children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>S(e=>({...e,file:{...e.file,parent:"",name:"",error:null}})),children:[(0,s.jsx)(t7,{className:"mr-2 h-3.5 w-3.5"}),"New file"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>S(e=>({...e,file:{...e.file,parent:"",name:"untitled.excalidraw",error:null}})),children:[(0,s.jsx)(ne.PencilRuler,{className:"mr-2 h-3.5 w-3.5"}),"New canvas"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>S(e=>({...e,folder:{...e.folder,parent:"",name:"",error:null}})),children:[(0,s.jsx)(t8,{className:"mr-2 h-3.5 w-3.5"}),"New folder"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>r.triggerUpload(""),disabled:r.uploading,children:[(0,s.jsx)(nn,{className:"mr-2 h-3.5 w-3.5"}),"Upload"]})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Refresh tree",onClick:()=>void n.refreshTree(),disabled:n.refreshingTree,children:n.refreshingTree?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(tA,{className:"h-3.5 w-3.5"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"AI Agent panel",onClick:()=>{tj.getState().toggle(),i&&d(!0)},children:(0,s.jsx)(a,{className:"h-3.5 w-3.5"})}),(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"More actions",children:(0,s.jsx)(t6,{className:"h-3.5 w-3.5"})})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"end",className:"w-48",children:[e.isWsAdmin&&e.workspaces.find(t=>t.id===e.activeWorkspaceId)?.git&&(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>{e.activeWorkspaceId&&P(e.activeWorkspaceId)},disabled:e.refreshingWsId===e.activeWorkspaceId,children:[e.refreshingWsId===e.activeWorkspaceId?(0,s.jsx)(u.Loader2,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(rF,{className:"mr-2 h-3.5 w-3.5"}),"Pull latest"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>nL.getState().toggle(),children:[F?(0,s.jsx)(rU,{className:"mr-2 h-3.5 w-3.5"}):(0,s.jsx)(rH.Eye,{className:"mr-2 h-3.5 w-3.5"}),F?"Hide hidden files":"Show hidden files"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>nR.getState().toggle(),children:[(0,s.jsx)(rG.Type,{className:"mr-2 h-3.5 w-3.5"}),B?"Raw file names":"Humanize names"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>z("dark"===$?"light":"dark"),children:["dark"===$?(0,s.jsx)(n2.Sun,{className:"mr-2 h-3.5 w-3.5"}):(0,s.jsx)(n0.Moon,{className:"mr-2 h-3.5 w-3.5"}),"dark"===$?"Light mode":"Dark mode"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>L(e=>({...e,settingsOpen:!0})),children:[(0,s.jsx)(rK,{className:"mr-2 h-3.5 w-3.5"}),"Settings"]})]})]})]})]}),r.uploadError&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 text-xs text-destructive bg-destructive/10 shrink-0",children:[(0,s.jsx)(f.AlertCircle,{className:"h-3.5 w-3.5 shrink-0"}),r.uploadError]}),""===N.folder.parent&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,s.jsx)(eQ,{className:"h-4 w-4 shrink-0 text-warning"}),(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"Folder name",value:N.folder.name,onChange:e=>S(t=>({...t,folder:{...t.folder,name:e.target.value}})),onKeyDown:e=>{"Enter"===e.key&&j(),"Escape"===e.key&&S(e=>({...e,folder:{...e.folder,parent:null,name:""}}))}}),N.folder.error&&(0,s.jsx)("span",{className:"text-xs text-destructive",children:N.folder.error}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:j,children:(0,s.jsx)(g.Check,{className:"h-3 w-3"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>S(e=>({...e,folder:{...e.folder,parent:null,name:""}})),children:(0,s.jsx)(h,{className:"h-3 w-3"})})]}),""===N.file.parent&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,s.jsx)(l.FileText,{className:"h-4 w-4 shrink-0 text-accent"}),(0,s.jsx)("input",{autoFocus:!0,className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"filename (default .md)",value:N.file.name,onChange:e=>S(t=>({...t,file:{...t.file,name:e.target.value}})),onKeyDown:e=>{"Enter"===e.key&&C(),"Escape"===e.key&&S(e=>({...e,file:{...e.file,parent:null,name:""}}))}}),N.file.error&&(0,s.jsx)("span",{className:"text-xs text-destructive",children:N.file.error}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:C,children:(0,s.jsx)(g.Check,{className:"h-3 w-3"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>S(e=>({...e,file:{...e.file,parent:null,name:""}})),children:(0,s.jsx)(h,{className:"h-3 w-3"})})]}),(0,s.jsx)("div",{className:"border-b",children:(0,s.jsx)(rJ,{onOpenFile:t.openFromSearch})}),(0,s.jsxs)("div",{ref:O,className:(0,eh.cn)("flex-1 overflow-auto py-1 ",""===E&&"ring-2 ring-inset ring-primary bg-primary/5"),onDragOver:e=>A(e,"","root"),onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||M(null)},onDrop:e=>T(e,""),children:[D.length>0&&(0,s.jsxs)("div",{className:"border-b mb-1",children:[(0,s.jsxs)("button",{type:"button",className:"flex w-full items-center gap-1 px-2 py-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground hover:text-foreground",onClick:()=>k(e=>({...e,favorites:!e.favorites})),children:[w.favorites?(0,s.jsx)(eY.ChevronRight,{className:"h-3 w-3"}):(0,s.jsx)(x,{className:"h-3 w-3"}),(0,s.jsx)(e4,{className:"h-3 w-3"}),"Favorites",(0,s.jsx)("span",{className:"ml-auto text-[9px] tabular-nums opacity-60",children:D.length})]}),!w.favorites&&D.map(n=>(0,s.jsxs)(nm,{children:[(0,s.jsx)(ng,{asChild:!0,children:(0,s.jsxs)("div",{role:"button",tabIndex:0,className:(0,eh.cn)("group flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer transition-colors select-none",t.openFile?.path===n.path?"bg-accent-soft text-foreground font-medium":"hover:bg-muted"),onClick:()=>{t.openFavoriteEntry(n)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),t.openFavoriteEntry(n))},children:[(0,s.jsx)(nq,{name:n.name,type:n.type??"file"}),(0,s.jsx)("span",{className:"min-w-0 flex-1 truncate text-xs",title:B?n.name:void 0,children:B?iA(n.name):n.name}),(0,s.jsx)("span",{className:"max-w-[80px] truncate text-[10px] text-muted-foreground/60",children:n.path.split("/").slice(0,-1).join("/")}),(0,s.jsx)("button",{type:"button",className:"hover-reveal shrink-0 rounded p-0.5 text-muted-foreground/50 opacity-0 transition-colors hover:bg-muted hover:text-amber-400 group-hover:opacity-100 focus:opacity-100",title:"Remove from favorites",onClick:t=>{t.stopPropagation(),nX.getState().toggle({path:n.path,name:n.name},e.activeWorkspaceId)},children:(0,s.jsx)(h,{className:"h-3 w-3"})})]})}),(0,s.jsx)(nW,{node:{path:n.path,name:n.name,type:n.type??"file"},ctx:_,isFavorited:!0,activeWorkspaceId:e.activeWorkspaceId})]},n.path))]}),R.length>0&&(0,s.jsxs)("div",{className:"border-b mb-1",children:[(0,s.jsxs)("button",{type:"button",className:"flex w-full items-center gap-1 px-2 py-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground hover:text-foreground",onClick:()=>k(e=>({...e,recent:!e.recent})),children:[w.recent?(0,s.jsx)(eY.ChevronRight,{className:"h-3 w-3"}):(0,s.jsx)(x,{className:"h-3 w-3"}),(0,s.jsx)(rV,{className:"h-3 w-3"}),"Recent",(0,s.jsx)("span",{className:"ml-auto text-[9px] tabular-nums opacity-60",children:R.length})]}),!w.recent&&R.slice(0,8).map(n=>(0,s.jsxs)(nm,{children:[(0,s.jsx)(ng,{asChild:!0,children:(0,s.jsxs)("div",{role:"button",tabIndex:0,className:(0,eh.cn)("flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer transition-colors select-none",t.openFile?.path===n.path?"bg-accent-soft text-foreground font-medium":"hover:bg-muted"),onClick:()=>{t.openViewer({path:n.path,name:n.name,type:n.type??"file",modifiedAt:""}),i&&d(!0)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),t.openViewer({path:n.path,name:n.name,type:n.type??"file",modifiedAt:""}))},children:[(0,s.jsx)(nq,{name:n.name,type:n.type??"file"}),(0,s.jsx)("span",{className:"flex-1 truncate text-xs",title:B?n.name:void 0,children:B?iA(n.name):n.name}),(0,s.jsx)("span",{className:"text-[10px] text-muted-foreground/60 truncate max-w-[80px]",children:n.path.split("/").slice(0,-1).join("/")})]})}),(0,s.jsx)(nW,{node:{path:n.path,name:n.name,type:n.type??"file"},ctx:_,isFavorited:D.some(e=>e.path===n.path),activeWorkspaceId:e.activeWorkspaceId})]},n.path))]}),(0,s.jsx)(iN,{activeWorkspaceId:e.activeWorkspaceId,workspaceName:e.workspaces.find(t=>t.id===e.activeWorkspaceId)?.name??"App",openPath:t.openFile?.path??null,onOpen:()=>{t.openViewer({path:"",name:e.workspaces.find(t=>t.id===e.activeWorkspaceId)?.name??"App",type:"node-app",modifiedAt:""}),i&&d(!0)}}),(0,s.jsx)(ik,{}),n.rootLoading?(0,s.jsx)("div",{className:"flex justify-center py-6",children:(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):0===n.roots.length?(0,s.jsxs)("div",{className:"flex flex-col items-center gap-3 px-4 py-8 text-center",children:[(0,s.jsx)("div",{className:"rounded-full bg-muted p-3",children:(0,s.jsx)(l.FileText,{className:"h-6 w-6 text-muted-foreground"})}),(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsx)("p",{className:"text-sm font-medium",children:"No files yet"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Upload files or add them to the configured directory"})]}),(0,s.jsxs)(v.Button,{size:"sm",variant:"outline",className:"w-full gap-1.5 max-w-[180px]",onClick:()=>r.triggerUpload(""),disabled:r.uploading,children:[r.uploading?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(nn,{className:"h-3.5 w-3.5"}),"Upload Files"]})]}):(0,s.jsx)(nG,{ctx:_,nodes:n.roots,openPath:t.openFile?.path??null,dragOverPath:E,branchDropdownNode:n.branchDropdownNode,branchDropdownPos:n.branchDropdownPos,nodeBranches:n.nodeBranches,branchesLoading:n.branchesLoading,checkingOutBranch:n.checkingOutBranch,pullingRepo:n.pullingRepo,activePaths:I,favorites:D,isMobile:i,activeWorkspaceId:e.activeWorkspaceId,newFileParent:N.file.parent,newFileName:N.file.name,fileCreateError:N.file.error,newFolderParent:N.folder.parent,newFolderName:N.folder.name,folderError:N.folder.error,sidebarScrollRef:O})]}),(0,s.jsx)(iC,{workspaces:e.workspaces,activeWorkspaceId:e.activeWorkspaceId,rootPath:e.rootPath,isWsAdmin:e.isWsAdmin,refreshingWsId:e.refreshingWsId,switchingBranch:e.switchingBranch,switchingBranchName:e.switchingBranchName,wsBranches:e.wsBranches,branchPickerWsId:e.branchPickerWsId,wsBranchPos:e.wsBranchPos,onSwitchWorkspace:t=>void e.switchWorkspace(t),onRefreshWorkspace:e.handleRefreshWorkspace,onPromptDeleteWorkspace:t=>e.setDeletingWorkspaceId(t),onAddWorkspace:()=>e.setAddingWorkspace(!0),setBranchPickerWsId:e.setBranchPickerWsId,setWsBranchPos:e.setWsBranchPos,loadWsBranches:e.loadWsBranches,handleSwitchBranch:e.handleSwitchBranch}),(0,s.jsx)("div",{role:"separator","aria-orientation":"vertical","aria-label":"Resize sidebar",title:"Drag to resize",onMouseDown:e=>{e.preventDefault();let t=e.clientX;m(!0);let n=document.body.style.cursor,r=document.body.style.userSelect;document.body.style.cursor="col-resize",document.body.style.userSelect="none";let i=e=>{y(b+(e.clientX-t))},s=()=>{m(!1),document.body.style.cursor=n,document.body.style.userSelect=r,window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",s)},onDoubleClick:()=>y(288),onKeyDown:e=>{"ArrowLeft"===e.key?(e.preventDefault(),y(b-16)):"ArrowRight"===e.key&&(e.preventDefault(),y(b+16))},tabIndex:0,"aria-valuemin":200,"aria-valuemax":600,"aria-valuenow":b,className:(0,eh.cn)("absolute right-0 top-0 z-20 h-full w-1.5 cursor-col-resize -mr-px transition-colors hover:bg-primary/40 focus:bg-primary/40 focus:outline-none hidden md:block",p&&"bg-primary/60")})]}),(0,s.jsx)(rQ,{})]})}function iO({workspace:e,doc:t,fileTree:n,upload:r,isMobile:i,hideChrome:o,sidebarCollapsed:a,setSidebarCollapsed:l,favorites:c,recents:d,activePaths:u,setDeleting:p,setDialogs:h}){let[f,g]=(0,m.useState)(!1),[x,b]=(0,m.useState)(null),[y,v]=(0,m.useState)({favorites:!1,recent:!0}),[w,k]=(0,m.useState)({file:{parent:null,name:"",error:null},folder:{parent:null,name:"",error:null}}),N=(0,m.useRef)(null),S=(0,m.useRef)(null),C=iM(e=>e.width),j=iM(e=>e.setWidth),E=(0,m.useCallback)(async()=>{let e=w.file.name.trim();if(!e||null===w.file.parent)return;k(e=>({...e,file:{...e.file,error:null}}));let r=e.includes(".")?e:`${e}.md`,i=w.file.parent?`${w.file.parent}/${r}`:r,s=await fetch((0,tk.withWs)("/api/wiki/new-file"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:i})});if(s.ok){let e=w.file.parent;k(e=>({...e,file:{parent:null,name:"",error:null}})),await n.reloadDir(e),t.openViewer({path:i,name:r,type:"file",modifiedAt:new Date().toISOString()})}else{let e=await s.json();k(t=>({...t,file:{...t.file,error:e.error??"Failed"}}))}},[w.file.parent,w.file.name,n,t]),M=(0,m.useCallback)(async()=>{let e=w.folder.name.trim();if(!e||null===w.folder.parent)return;k(e=>({...e,folder:{...e.folder,error:null}}));let t=w.folder.parent?`${w.folder.parent}/${e}`:e,r=await fetch((0,tk.withWs)("/api/wiki/folder"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(r.ok){let e=w.folder.parent;k(e=>({...e,folder:{parent:null,name:"",error:null}})),await n.reloadDir(e)}else{let e=await r.json();k(t=>({...t,folder:{...t.folder,error:e.error??"Failed"}}))}},[w.folder.parent,w.folder.name,n]);function A(e,t,n){e.preventDefault(),e.stopPropagation();let r=S.current;if(!r){Array.from(e.dataTransfer.types).includes("Files")&&(e.dataTransfer.dropEffect="copy",b("root"===n?"":t));return}r.path===t||t.startsWith(`${r.path}/`)||(e.dataTransfer.dropEffect="move",b("root"===n?"":t))}async function T(e,i){e.preventDefault(),e.stopPropagation(),b(null);let s=S.current;if(S.current=null,!s){e.dataTransfer.files.length>0&&await r.doUpload(e.dataTransfer.files,i);return}if(s.path===i||i.startsWith(`${s.path}/`))return;let o=i?`${i}/${s.name}`:s.name;if(o!==s.path&&(await fetch((0,tk.withWs)("/api/wiki/move"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({from:s.path,to:o})})).ok){let e=s.path.includes("/")?s.path.split("/").slice(0,-1).join("/"):"";await n.reloadDir(e),i!==e&&await n.reloadDir(i),t.openFile?.path===s.path&&t.openViewer({path:o,name:s.name,type:s.type,modifiedAt:s.modifiedAt})}}let O=(0,m.useRef)(null);O.current={toggleFolder:e=>void n.toggleFolder(e),openViewer:e=>void t.openViewer(e),copyPath:e=>t.copyPath(e),copyWikiLink:e=>t.copyWikiLink(e),copyUrl:e=>t.copyUrl(e),copyRawContent:e=>void t.copyRawContent(e),copyFormattedContent:(e,n)=>void t.copyFormattedContent(e,n),handleDownload:function(e){let t=(0,tk.withWs)(`/api/wiki/download?path=${encodeURIComponent(e.path)}`),n=document.createElement("a");n.href=t,n.download="file"===e.type?e.name:`${e.name}.zip`,document.body.appendChild(n),n.click(),n.remove()},triggerUpload:e=>r.triggerUpload(e),handleCreateFile:E,handleCreateFolder:M,handleDragStart:function(e,t){S.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t.path)},handleDragOver:A,handleDropOnFolder:(e,t)=>void T(e,t),handleGitPull:(e,t)=>void n.handleGitPull(e,t),handleCheckout:(e,t,r)=>void n.handleCheckout(e,t,r),loadBranches:e=>void n.loadBranches(e),prefetch:e=>void n.prefetch(e),toggleFavorite:(e,t)=>nX.getState().toggle({path:e.path,name:e.name,type:e.type},t),setDragOverPath:b,setSidebarCollapsed:l,setBranchDropdownNode:e=>n.setBranchDropdownNode(e),setBranchDropdownPos:e=>n.setBranchDropdownPos(e),setNewFileParent:e=>k(t=>({...t,file:{...t.file,parent:e,error:null}})),setNewFileName:e=>k(t=>({...t,file:{...t.file,name:e}})),setFileCreateError:e=>k(t=>({...t,file:{...t.file,error:e}})),setNewFolderParent:e=>k(t=>({...t,folder:{...t.folder,parent:e,error:null}})),setNewFolderName:e=>k(t=>({...t,folder:{...t.folder,name:e}})),setFolderError:e=>k(t=>({...t,folder:{...t.folder,error:e}})),setDeletingPath:e=>p(t=>({...t,path:e})),setDeletingIsDir:e=>p(t=>({...t,isDir:e}))};let _=(0,m.useMemo)(()=>({toggleFolder:e=>O.current.toggleFolder(e),openViewer:e=>O.current.openViewer(e),copyPath:e=>O.current.copyPath(e),copyWikiLink:e=>O.current.copyWikiLink(e),copyUrl:e=>O.current.copyUrl(e),copyRawContent:e=>O.current.copyRawContent(e),copyFormattedContent:(e,t)=>O.current.copyFormattedContent(e,t),handleDownload:e=>O.current.handleDownload(e),triggerUpload:e=>O.current.triggerUpload(e),handleCreateFile:()=>O.current.handleCreateFile(),handleCreateFolder:()=>O.current.handleCreateFolder(),handleDragStart:(e,t)=>O.current.handleDragStart(e,t),handleDragOver:(e,t,n)=>O.current.handleDragOver(e,t,n),handleDropOnFolder:(e,t)=>O.current.handleDropOnFolder(e,t),handleGitPull:(e,t)=>O.current.handleGitPull(e,t),handleCheckout:(e,t,n)=>O.current.handleCheckout(e,t,n),loadBranches:e=>O.current.loadBranches(e),prefetch:e=>O.current.prefetch(e),toggleFavorite:(e,t)=>O.current.toggleFavorite(e,t),setDragOverPath:e=>O.current.setDragOverPath(e),setSidebarCollapsed:e=>O.current.setSidebarCollapsed(e),setBranchDropdownNode:e=>O.current.setBranchDropdownNode(e),setBranchDropdownPos:e=>O.current.setBranchDropdownPos(e),setNewFileParent:e=>O.current.setNewFileParent(e),setNewFileName:e=>O.current.setNewFileName(e),setFileCreateError:e=>O.current.setFileCreateError(e),setNewFolderParent:e=>O.current.setNewFolderParent(e),setNewFolderName:e=>O.current.setNewFolderName(e),setFolderError:e=>O.current.setFolderError(e),setDeletingPath:e=>O.current.setDeletingPath(e),setDeletingIsDir:e=>O.current.setDeletingIsDir(e)}),[]);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(rB,{onOpenFile:t.openFromSearch,recents:d,onToggleSidebar:()=>l(e=>{let t=!e;return i&&!1===t&&tj.getState().close(),t}),onNewFile:()=>k(e=>({...e,file:{...e.file,parent:""}})),onCopyPath:()=>{t.openFile&&t.copyPath(t.openFile.path)}}),(0,s.jsx)(iT,{workspace:e,doc:t,fileTree:n,upload:r,isMobile:i,hideChrome:o,sidebarCollapsed:a,setSidebarCollapsed:l,sidebarResizing:f,setSidebarResizing:g,sidebarWidth:C,setSidebarWidth:j,collapsed:y,setCollapsed:v,createEntry:w,setCreateEntry:k,handleCreateFile:E,handleCreateFolder:M,dragOverPath:x,setDragOverPath:b,handleDragOver:A,handleDropOnFolder:T,sidebarScrollRef:N,treeCtx:_,favorites:c,recents:d,activePaths:u,setDialogs:h,handleRefreshWorkspace:e.handleRefreshWorkspace})]})}let i_=(0,o.default)("code-xml",[["path",{d:"m18 16 4-4-4-4",key:"1inbqp"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}],["path",{d:"m14.5 4-5 16",key:"e7oirm"}]]),iD=(0,o.default)("file-plus-2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M3 15h6",key:"4e2qda"}],["path",{d:"M6 12v6",key:"1u72j0"}]]),iR=(0,o.default)("maximize-2",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]]),iI=(0,o.default)("pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]),iL=(0,o.default)("share",[["path",{d:"M12 2v13",key:"1km8f5"}],["path",{d:"m16 6-4-4-4 4",key:"13yo43"}],["path",{d:"M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8",key:"1b2hhj"}]]),iP=(0,o.default)("user",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);var i$=e.i(905381),iz=e.i(801273),iB=e.i(61086);function iF(e){let t=[],n="",r=!1,i=[];for(let s=0;s<e.length;s++){let o=e[s],a=e[s+1];r?'"'===o&&'"'===a?(n+='"',s++):'"'===o?r=!1:n+=o:'"'===o?r=!0:","===o?(i.push(n),n=""):"\n"===o||"\r"===o&&"\n"===a?(i.push(n),n="",i.length>0&&t.push(i),i=[],"\r"===o&&s++):n+=o}return i.push(n),i.some(e=>""!==e)&&t.push(i),t}function iH(e){return e.map(e=>e.map(e=>e.includes(",")||e.includes('"')||e.includes("\n")?`"${e.replace(/"/g,'""')}"`:e).join(",")).join("\n")}function iU({path:e}){let[t,n]=(0,m.useState)([]),[r,i]=(0,m.useState)(""),[o,a]=(0,m.useState)(!1),[l,c]=(0,m.useState)(!1),[d,u]=(0,m.useState)(!1),[p,h]=(0,m.useState)(null),[f,g]=(0,m.useState)(!1),[x,b]=(0,m.useState)(1e3),y=(0,tk.withWs)(`/api/assets/${e}`);(0,m.useEffect)(()=>{fetch(y).then(e=>e.text()).then(e=>{let t=iF(e),r=e.length>2097152||t.length>2e3;i(e),n(t),g(r),a(r),c(!1)})},[y]);let w=(0,m.useCallback)((e,t,r)=>{n(n=>{let i=n.map(e=>[...e]);for(;i.length<=e;)i.push([]);for(;i[e].length<=t;)i[e].push("");return i[e][t]=r,i}),c(!0)},[]),k=async()=>{u(!0);let s=o?r:iH(t);try{await (0,tk.wsFetch)(`/api/assets/${e}`,{method:"PUT",headers:{"Content-Type":"text/plain"},body:s}),o?n(iF(r)):i(s),c(!1)}catch(e){console.error("Failed to save CSV:",e)}u(!1)},N=t[0]||[],S=t.slice(1),C=f?S.slice(0,x):S,j=f&&x<S.length;return(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)(iB.ViewerToolbar,{path:e,badge:`CSV${t.length>0?` (${t.length-1} rows)`:""}`,children:[l&&(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:k,disabled:d,children:[(0,s.jsx)(iz.Save,{className:"h-3.5 w-3.5"}),d?"Saving...":"Save"]}),f&&(0,s.jsxs)("span",{className:"text-[11px] text-amber-600 dark:text-amber-400 px-1",children:["Large file (",(r.length/1048576).toFixed(1)," MB,"," ",t.length.toLocaleString()," rows)"]}),(0,s.jsxs)("button",{onClick:()=>{o?n(iF(r)):i(iH(t)),a(!o)},className:`flex items-center gap-1.5 px-2.5 py-1 text-[11px] rounded-md transition-colors border border-border ${o?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent"}`,children:[(0,s.jsx)(i_,{className:"h-3 w-3"}),o?"Table":"Source"]}),(0,s.jsx)("button",{onClick:()=>window.open(y,"_blank"),className:"inline-flex items-center justify-center rounded-md h-8 w-8 hover:bg-accent hover:text-accent-foreground transition-colors cursor-pointer",title:"Download CSV",children:(0,s.jsx)(t3.Download,{className:"h-4 w-4"})})]}),o?(0,s.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:(0,s.jsx)("textarea",{value:r,onChange:e=>{i(e.target.value),c(!0)},className:"w-full h-full min-h-[calc(100vh-12rem)] bg-transparent font-mono text-[13px] leading-relaxed resize-none focus:outline-none",spellCheck:!1})}):(0,s.jsxs)("div",{className:"flex-1 overflow-auto",children:[(0,s.jsxs)("table",{className:"w-full border-collapse text-[13px]",children:[(0,s.jsx)("thead",{className:"sticky top-0 z-10",children:(0,s.jsxs)("tr",{className:"bg-muted/80 backdrop-blur-sm",children:[(0,s.jsx)("th",{className:"border border-border px-1 py-1 text-center text-[10px] text-muted-foreground w-8",children:"#"}),N.map((e,t)=>(0,s.jsx)("th",{className:"border border-border px-3 py-1.5 text-left font-medium text-foreground min-w-[100px]",children:p?.r===0&&p?.c===t?(0,s.jsx)("input",{autoFocus:!0,className:"w-full bg-transparent outline-none",value:e,onChange:e=>w(0,t,e.target.value),onBlur:()=>h(null),onKeyDown:e=>{("Enter"===e.key||"Escape"===e.key)&&h(null),"Tab"===e.key&&(e.preventDefault(),h({r:0,c:t+1<N.length?t+1:0}))}}):(0,s.jsx)("span",{className:"cursor-text",onDoubleClick:()=>h({r:0,c:t}),children:e||" "})},t))]})}),(0,s.jsx)("tbody",{children:C.map((e,t)=>{let r=t+1;return(0,s.jsxs)("tr",{className:"hover:bg-accent/30 transition-colors group",children:[(0,s.jsxs)("td",{className:"border border-border px-1 py-1 text-center text-[10px] text-muted-foreground/50",children:[(0,s.jsx)("span",{className:"group-hover:hidden",children:t+1}),(0,s.jsx)("button",{className:"hidden group-hover:inline text-destructive hover:text-destructive/80 text-[10px]",onClick:()=>{n(e=>e.filter((e,t)=>t!==r)),c(!0)},title:"Delete row",children:"×"})]}),N.map((t,n)=>{let i=e[n]??"",o=p?.r===r&&p?.c===n;return(0,s.jsx)("td",{className:"border border-border px-3 py-1.5",children:o?(0,s.jsx)("input",{autoFocus:!0,className:"w-full bg-transparent outline-none",value:i,onChange:e=>w(r,n,e.target.value),onBlur:()=>h(null),onKeyDown:e=>{"Escape"===e.key&&h(null),"Enter"===e.key&&h({r:r+1,c:n}),"Tab"===e.key&&(e.preventDefault(),e.shiftKey?h({r,c:Math.max(0,n-1)}):h({r:n+1>=N.length?r+1:r,c:n+1>=N.length?0:n+1}))}}):(0,s.jsx)("span",{className:"cursor-text",onDoubleClick:()=>h({r,c:n}),children:i||" "})},n)})]},t)})})]}),j&&(0,s.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2 border-t border-border",children:[(0,s.jsxs)("button",{onClick:()=>b(e=>e+1e3),className:"text-[11px] text-foreground hover:bg-accent transition-colors px-2.5 py-1 rounded border border-border",children:["Show"," ",Math.min(1e3,S.length-x).toLocaleString()," ","more rows"]}),(0,s.jsxs)("span",{className:"text-[11px] text-muted-foreground",children:[x.toLocaleString()," /"," ",S.length.toLocaleString()," rows"]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 border-t border-border",children:[(0,s.jsx)("button",{onClick:()=>{let e=t[0]?.length||1;n(t=>[...t,Array(e).fill("")]),c(!0)},className:"text-[11px] text-muted-foreground hover:text-foreground transition-colors px-2 py-1 rounded hover:bg-accent",children:"+ Add row"}),(0,s.jsx)("button",{onClick:()=>{n(e=>e.map(e=>[...e,""])),c(!0)},className:"text-[11px] text-muted-foreground hover:text-foreground transition-colors px-2 py-1 rounded hover:bg-accent",children:"+ Add column"})]})]})]})}function iV(e){this.content=e}iV.prototype={constructor:iV,find:function(e){for(var t=0;t<this.content.length;t+=2)if(this.content[t]===e)return t;return -1},get:function(e){var t=this.find(e);return -1==t?void 0:this.content[t+1]},update:function(e,t,n){var r=n&&n!=e?this.remove(n):this,i=r.find(e),s=r.content.slice();return -1==i?s.push(n||e,t):(s[i+1]=t,n&&(s[i]=n)),new iV(s)},remove:function(e){var t=this.find(e);if(-1==t)return this;var n=this.content.slice();return n.splice(t,2),new iV(n)},addToStart:function(e,t){return new iV([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var n=this.remove(e).content.slice();return n.push(e,t),new iV(n)},addBefore:function(e,t,n){var r=this.remove(t),i=r.content.slice(),s=r.find(e);return i.splice(-1==s?i.length:s,0,t,n),new iV(i)},forEach:function(e){for(var t=0;t<this.content.length;t+=2)e(this.content[t],this.content[t+1])},prepend:function(e){return(e=iV.from(e)).size?new iV(e.content.concat(this.subtract(e).content)):this},append:function(e){return(e=iV.from(e)).size?new iV(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=iV.from(e);for(var n=0;n<e.content.length;n+=2)t=t.remove(e.content[n]);return t},toObject:function(){var e={};return this.forEach(function(t,n){e[t]=n}),e},get size(){return this.content.length>>1}},iV.from=function(e){if(e instanceof iV)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new iV(t)};class iW{constructor(e,t){if(this.content=e,this.size=t||0,null==t)for(let t=0;t<e.length;t++)this.size+=e[t].nodeSize}nodesBetween(e,t,n,r=0,i){for(let s=0,o=0;o<t;s++){let a=this.content[s],l=o+a.nodeSize;if(l>e&&!1!==n(a,r+o,i||null,s)&&a.content.size){let i=o+1;a.nodesBetween(Math.max(0,e-i),Math.min(a.content.size,t-i),n,r+i)}o=l}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i="",s=!0;return this.nodesBetween(e,t,(o,a)=>{let l=o.isText?o.text.slice(Math.max(e,a)-a,t-a):o.isLeaf?r?"function"==typeof r?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):"":"";o.isBlock&&(o.isLeaf&&l||o.isTextblock)&&n&&(s?s=!1:i+=n),i+=l},0),i}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,r=this.content.slice(),i=0;for(t.isText&&t.sameMarkup(n)&&(r[r.length-1]=t.withText(t.text+n.text),i=1);i<e.content.length;i++)r.push(e.content[i]);return new iW(r,this.size+e.size)}cut(e,t=this.size){if(0==e&&t==this.size)return this;let n=[],r=0;if(t>e)for(let i=0,s=0;s<t;i++){let o=this.content[i],a=s+o.nodeSize;a>e&&((s<e||a>t)&&(o=o.isText?o.cut(Math.max(0,e-s),Math.min(o.text.length,t-s)):o.cut(Math.max(0,e-s-1),Math.min(o.content.size,t-s-1))),n.push(o),r+=o.nodeSize),s=a}return new iW(n,r)}cutByIndex(e,t){return e==t?iW.empty:0==e&&t==this.content.length?this:new iW(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let r=this.content.slice(),i=this.size+t.nodeSize-n.nodeSize;return r[e]=t,new iW(r,i)}addToStart(e){return new iW([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new iW(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let r=this.content[t];e(r,n,t),n+=r.nodeSize}}findDiffStart(e,t=0){return function e(t,n,r){for(let i=0;;i++){if(i==t.childCount||i==n.childCount)return t.childCount==n.childCount?null:r;let s=t.child(i),o=n.child(i);if(s==o){r+=s.nodeSize;continue}if(!s.sameMarkup(o))return r;if(s.isText&&s.text!=o.text){for(let e=0;s.text[e]==o.text[e];e++)r++;return r}if(s.content.size||o.content.size){let t=e(s.content,o.content,r+1);if(null!=t)return t}r+=s.nodeSize}}(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return function e(t,n,r,i){for(let s=t.childCount,o=n.childCount;;){if(0==s||0==o)return s==o?null:{a:r,b:i};let a=t.child(--s),l=n.child(--o),c=a.nodeSize;if(a==l){r-=c,i-=c;continue}if(!a.sameMarkup(l))return{a:r,b:i};if(a.isText&&a.text!=l.text){let e=0,t=Math.min(a.text.length,l.text.length);for(;e<t&&a.text[a.text.length-e-1]==l.text[l.text.length-e-1];)e++,r--,i--;return{a:r,b:i}}if(a.content.size||l.content.size){let t=e(a.content,l.content,r-1,i-1);if(t)return t}r-=c,i-=c}}(this,e,t,n)}findIndex(e){if(0==e)return iK(0,e);if(e==this.size)return iK(this.content.length,e);if(e>this.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=n+this.child(t).nodeSize;if(r>=e){if(r==e)return iK(t+1,r);return iK(t,n)}n=r}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return iW.empty;if(!Array.isArray(t))throw RangeError("Invalid input for Fragment.fromJSON");return iW.fromArray(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return iW.empty;let t,n=0;for(let r=0;r<e.length;r++){let i=e[r];n+=i.nodeSize,r&&i.isText&&e[r-1].sameMarkup(i)?(t||(t=e.slice(0,r)),t[t.length-1]=i.withText(t[t.length-1].text+i.text)):t&&t.push(i)}return new iW(t||e,n)}static from(e){if(!e)return iW.empty;if(e instanceof iW)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new iW([e],e.nodeSize);throw RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}iW.empty=new iW([],0);let iq={index:0,offset:0};function iK(e,t){return iq.index=e,iq.offset=t,iq}function iG(e,t){if(e===t)return!0;if(!(e&&"object"==typeof e)||!(t&&"object"==typeof t))return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!iG(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!iG(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}class iJ{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(this.eq(i))return e;if(this.type.excludes(i.type))t||(t=e.slice(0,r));else{if(i.type.excludes(this.type))return e;!n&&i.type.rank>this.type.rank&&(t||(t=e.slice(0,r)),t.push(this),n=!0),t&&t.push(i)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&iG(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw RangeError("Invalid input for Mark.fromJSON");let n=e.marks[t.type];if(!n)throw RangeError(`There is no mark type ${t.type} in this schema`);let r=n.create(t.attrs);return n.checkAttrs(r.attrs),r}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&0==e.length)return iJ.none;if(e instanceof iJ)return[e];let t=e.slice();return t.sort((e,t)=>e.type.rank-t.type.rank),t}}iJ.none=[];class iZ extends Error{}class iX{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=function e(t,n,r,i,s,o){let{index:a,offset:l}=t.findIndex(n),c=t.maybeChild(a);if(l==n||c.isText)return o&&i<=0&&s<=0&&!o.canReplace(a,a,r)?null:t.cut(0,n).append(r).append(t.cut(n));let d=e(c.content,n-l-1,r,0==a?i-1:0,a==t.childCount-1?s-1:0,c);return d&&t.replaceChild(a,c.copy(d))}(this.content,e+this.openStart,t,this.openStart+1,this.openEnd+1);return n&&new iX(n,this.openStart,this.openEnd)}removeBetween(e,t){return new iX(function e(t,n,r){let{index:i,offset:s}=t.findIndex(n),o=t.maybeChild(i),{index:a,offset:l}=t.findIndex(r);if(s==n||o.isText){if(l!=r&&!t.child(a).isText)throw RangeError("Removing non-flat range");return t.cut(0,n).append(t.cut(r))}if(i!=a)throw RangeError("Removing non-flat range");return t.replaceChild(i,o.copy(e(o.content,n-s-1,r-s-1)))}(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return iX.empty;let n=t.openStart||0,r=t.openEnd||0;if("number"!=typeof n||"number"!=typeof r)throw RangeError("Invalid input for Slice.fromJSON");return new iX(iW.fromJSON(e,t.content),n,r)}static maxOpen(e,t=!0){let n=0,r=0;for(let r=e.firstChild;r&&!r.isLeaf&&(t||!r.type.spec.isolating);r=r.firstChild)n++;for(let n=e.lastChild;n&&!n.isLeaf&&(t||!n.type.spec.isolating);n=n.lastChild)r++;return new iX(e,n,r)}}function iY(e,t){if(!t.type.compatibleContent(e.type))throw new iZ("Cannot join "+t.type.name+" onto "+e.type.name)}function iQ(e,t,n){let r=e.node(n);return iY(r,t.node(n)),r}function i0(e,t){let n=t.length-1;n>=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function i1(e,t,n,r){let i=(t||e).node(n),s=0,o=t?t.index(n):i.childCount;e&&(s=e.index(n),e.depth>n?s++:e.textOffset&&(i0(e.nodeAfter,r),s++));for(let e=s;e<o;e++)i0(i.child(e),r);t&&t.depth==n&&t.textOffset&&i0(t.nodeBefore,r)}function i2(e,t){return e.type.checkContent(t),e.copy(t)}function i5(e,t,n){let r=[];return i1(null,e,n,r),e.depth>n&&i0(i2(iQ(e,t,n+1),i5(e,t,n+1)),r),i1(t,null,n,r),new iW(r)}iX.empty=new iX(iW.empty,0,0);class i3{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return null==e?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[3*this.resolveDepth(e)]}index(e){return this.path[3*this.resolveDepth(e)+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e!=this.depth||this.textOffset?1:0)}start(e){return 0==(e=this.resolveDepth(e))?0:this.path[3*e-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(!(e=this.resolveDepth(e)))throw RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]}after(e){if(!(e=this.resolveDepth(e)))throw RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]+this.path[3*e].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):0==e?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[3*t],r=0==t?0:this.path[3*t-1]+1;for(let t=0;t<e;t++)r+=n.child(t).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(0==e.content.size)return iJ.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),r=e.maybeChild(t);if(!n){let e=n;n=r,r=e}let i=n.marks;for(var s=0;s<i.length;s++)!1!==i[s].type.spec.inclusive||r&&i[s].isInSet(r.marks)||(i=i[s--].removeFromSet(i));return i}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,r=e.parent.maybeChild(e.index());for(var i=0;i<n.length;i++)!1!==n[i].type.spec.inclusive||r&&n[i].isInSet(r.marks)||(n=n[i--].removeFromSet(n));return n}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let n=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);n>=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new i7(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw RangeError("Position "+t+" out of range");let n=[],r=0,i=t;for(let t=e;;){let{index:e,offset:s}=t.content.findIndex(i),o=i-s;if(n.push(t,e,r+s),!o||(t=t.child(e)).isText)break;i=o-1,r+=s+1}return new i3(t,n,i)}static resolveCached(e,t){let n=i9.get(e);if(n)for(let e=0;e<n.elts.length;e++){let r=n.elts[e];if(r.pos==t)return r}else i9.set(e,n=new i4);let r=n.elts[n.i]=i3.resolve(e,t);return n.i=(n.i+1)%i6,r}}class i4{constructor(){this.elts=[],this.i=0}}let i6=12,i9=new WeakMap;class i7{constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}let i8=Object.create(null);class se{constructor(e,t,n,r=iJ.none){this.type=e,this.attrs=t,this.marks=r,this.content=n||iW.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n,r=0){this.content.nodesBetween(e,t,n,r,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,n,r){return this.content.textBetween(e,t,n,r)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,n){return this.type==e&&iG(this.attrs,t||e.defaultAttrs||i8)&&iJ.sameSet(this.marks,n||iJ.none)}copy(e=null){return e==this.content?this:new se(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new se(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return 0==e&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return iX.empty;let r=this.resolve(e),i=this.resolve(t),s=n?0:r.sharedDepth(t),o=r.start(s);return new iX(r.node(s).content.cut(r.pos-o,i.pos-o),r.depth-s,i.depth-s)}replace(e,t,n){var r=this.resolve(e),i=this.resolve(t);if(n.openStart>r.depth)throw new iZ("Inserted content deeper than insertion position");if(r.depth-n.openStart!=i.depth-n.openEnd)throw new iZ("Inconsistent open depths");return function e(t,n,r,i){let s=t.index(i),o=t.node(i);if(s==n.index(i)&&i<t.depth-r.openStart){let a=e(t,n,r,i+1);return o.copy(o.content.replaceChild(s,a))}if(!r.content.size)return i2(o,i5(t,n,i));if(r.openStart||r.openEnd||t.depth!=i||n.depth!=i){let{start:e,end:s}=function(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(iW.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}(r,t);return i2(o,function e(t,n,r,i,s){let o=t.depth>s&&iQ(t,n,s+1),a=i.depth>s&&iQ(r,i,s+1),l=[];return i1(null,t,s,l),o&&a&&n.index(s)==r.index(s)?(iY(o,a),i0(i2(o,e(t,n,r,i,s+1)),l)):(o&&i0(i2(o,i5(t,n,s+1)),l),i1(n,r,s,l),a&&i0(i2(a,i5(r,i,s+1)),l)),i1(i,null,s,l),new iW(l)}(t,e,s,n,i))}{let e=t.parent,i=e.content;return i2(e,i.cut(0,t.parentOffset).append(r.content).append(i.cut(n.parentOffset)))}}(r,i,n,0)}nodeAt(e){for(let t=this;;){let{index:n,offset:r}=t.content.findIndex(e);if(!(t=t.maybeChild(n)))return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:n}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:n}}childBefore(e){if(0==e)return{node:null,index:0,offset:0};let{index:t,offset:n}=this.content.findIndex(e);if(n<e)return{node:this.content.child(t),index:t,offset:n};let r=this.content.child(t-1);return{node:r,index:t-1,offset:n-r.nodeSize}}resolve(e){return i3.resolveCached(this,e)}resolveNoCache(e){return i3.resolve(this,e)}rangeHasMark(e,t,n){let r=!1;return t>e&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),sn(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,n=iW.empty,r=0,i=n.childCount){let s=this.contentMatchAt(e).matchFragment(n,r,i),o=s&&s.matchFragment(this.content,t);if(!o||!o.validEnd)return!1;for(let e=r;e<i;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n,r){if(r&&!this.type.allowsMarks(r))return!1;let i=this.contentMatchAt(e).matchType(n),s=i&&i.matchFragment(this.content,t);return!!s&&s.validEnd}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=iJ.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];n.type.checkAttrs(n.attrs),e=n.addToSet(e)}if(!iJ.sameSet(e,this.marks))throw RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(e=>e.type.name)}`);this.content.forEach(e=>e.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}static fromJSON(e,t){let n;if(!t)throw RangeError("Invalid input for Node.fromJSON");if(t.marks){if(!Array.isArray(t.marks))throw RangeError("Invalid mark data for Node.fromJSON");n=t.marks.map(e.markFromJSON)}if("text"==t.type){if("string"!=typeof t.text)throw RangeError("Invalid text node in JSON");return e.text(t.text,n)}let r=iW.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}}se.prototype.text=void 0;class st extends se{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):sn(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new st(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new st(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return 0==e&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function sn(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+"("+t+")";return t}class sr{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){var n;let r,i=new si(e,t);if(null==i.next)return sr.empty;let s=function e(t){let n=[];do n.push(function(t){let n=[];do n.push(function(t){let n=function(t){if(t.eat("(")){let n=e(t);return t.eat(")")||t.err("Missing closing paren"),n}if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=(function(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let i=[];for(let e in n){let r=n[e];r.isInGroup(t)&&i.push(r)}return 0==i.length&&e.err("No node type or group '"+t+"' found"),i})(t,t.next).map(e=>(null==t.inline?t.inline=e.isInline:t.inline!=e.isInline&&t.err("Mixing inline and block content"),{type:"name",value:e}));return t.pos++,1==e.length?e[0]:{type:"choice",exprs:e}}}(t);for(;;)if(t.eat("+"))n={type:"plus",expr:n};else if(t.eat("*"))n={type:"star",expr:n};else if(t.eat("?"))n={type:"opt",expr:n};else if(t.eat("{"))n=function(e,t){let n=ss(e),r=n;return e.eat(",")&&(r="}"!=e.next?ss(e):-1),e.eat("}")||e.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:t}}(t,n);else break;return n}(t));while(t.next&&")"!=t.next&&"|"!=t.next)return 1==n.length?n[0]:{type:"seq",exprs:n}}(t));while(t.eat("|"))return 1==n.length?n[0]:{type:"choice",exprs:n}}(i);i.next&&i.err("Unexpected trailing text");let o=(n=function(e){let t=[[]];return i(function e(t,s){if("choice"==t.type)return t.exprs.reduce((t,n)=>t.concat(e(n,s)),[]);if("seq"==t.type)for(let r=0;;r++){let o=e(t.exprs[r],s);if(r==t.exprs.length-1)return o;i(o,s=n())}else if("star"==t.type){let o=n();return r(s,o),i(e(t.expr,o),o),[r(o)]}else if("plus"==t.type){let o=n();return i(e(t.expr,s),o),i(e(t.expr,o),o),[r(o)]}else if("opt"==t.type)return[r(s)].concat(e(t.expr,s));else if("range"==t.type){let o=s;for(let r=0;r<t.min;r++){let r=n();i(e(t.expr,o),r),o=r}if(-1==t.max)i(e(t.expr,o),o);else for(let s=t.min;s<t.max;s++){let s=n();r(o,s),i(e(t.expr,o),s),o=s}return[r(o)]}else if("name"==t.type)return[r(s,void 0,t.value)];else throw Error("Unknown expr type")}(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let i={term:r,to:n};return t[e].push(i),i}function i(e,t){e.forEach(e=>e.to=t)}}(s),r=Object.create(null),function e(t){let i=[];t.forEach(e=>{n[e].forEach(({term:e,to:t})=>{let r;if(e){for(let t=0;t<i.length;t++)i[t][0]==e&&(r=i[t][1]);sa(n,t).forEach(t=>{r||i.push([e,r=[]]),-1==r.indexOf(t)&&r.push(t)})}})});let s=r[t.join(",")]=new sr(t.indexOf(n.length-1)>-1);for(let t=0;t<i.length;t++){let n=i[t][1].sort(so);s.next.push({type:i[t][0],next:r[n.join(",")]||e(n)})}return s}(sa(n,0)));return function(e,t){for(let n=0,r=[e];n<r.length;n++){let e=r[n],i=!e.validEnd,s=[];for(let t=0;t<e.next.length;t++){let{type:n,next:o}=e.next[t];s.push(n.name),i&&!(n.isText||n.hasRequiredAttrs())&&(i=!1),-1==r.indexOf(o)&&r.push(o)}i&&t.err("Only non-generatable nodes ("+s.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(o,i),o}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,n=e.childCount){let r=this;for(let i=t;r&&i<n;i++)r=r.matchType(e.child(i).type);return r}get inlineContent(){return 0!=this.next.length&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let n=0;n<e.next.length;n++)if(this.next[t].type==e.next[n].type)return!0;return!1}fillBefore(e,t=!1,n=0){let r=[this];return function i(s,o){let a=s.matchFragment(e,n);if(a&&(!t||a.validEnd))return iW.from(o.map(e=>e.createAndFill()));for(let e=0;e<s.next.length;e++){let{type:t,next:n}=s.next[e];if(!(t.isText||t.hasRequiredAttrs())&&-1==r.indexOf(n)){r.push(n);let e=i(n,o.concat(t));if(e)return e}}return null}(this,[])}findWrapping(e){for(let t=0;t<this.wrapCache.length;t+=2)if(this.wrapCache[t]==e)return this.wrapCache[t+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let r=n.shift(),i=r.match;if(i.matchType(e)){let e=[];for(let t=r;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<i.next.length;e++){let{type:s,next:o}=i.next[e];s.isLeaf||s.hasRequiredAttrs()||s.name in t||r.type&&!o.validEnd||(n.push({match:s.contentMatch,type:s,via:r}),t[s.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];return!function t(n){e.push(n);for(let r=0;r<n.next.length;r++)-1==e.indexOf(n.next[r].next)&&t(n.next[r].next)}(this),e.map((t,n)=>{let r=n+(t.validEnd?"*":" ")+" ";for(let n=0;n<t.next.length;n++)r+=(n?", ":"")+t.next[n].type.name+"->"+e.indexOf(t.next[n].next);return r}).join("\n")}}sr.empty=new sr(!0);class si{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),""==this.tokens[this.tokens.length-1]&&this.tokens.pop(),""==this.tokens[0]&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw SyntaxError(e+" (in content expression '"+this.string+"')")}}function ss(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function so(e,t){return t-e}function sa(e,t){let n=[];return function t(r){let i=e[r];if(1==i.length&&!i[0].term)return t(i[0].to);n.push(r);for(let e=0;e<i.length;e++){let{term:r,to:s}=i[e];r||-1!=n.indexOf(s)||t(s)}}(t),n.sort(so)}function sl(e){let t=Object.create(null);for(let n in e){let r=e[n];if(!r.hasDefault)return null;t[n]=r.default}return t}function sc(e,t){let n=Object.create(null);for(let r in e){let i=t&&t[r];if(void 0===i){let t=e[r];if(t.hasDefault)i=t.default;else throw RangeError("No value supplied for attribute "+r)}n[r]=i}return n}function sd(e,t,n,r){for(let r in t)if(!(r in e))throw RangeError(`Unsupported attribute ${r} for ${n} of type ${r}`);for(let n in e){let r=e[n];r.validate&&r.validate(t[n])}}function su(e,t){let n=Object.create(null);if(t)for(let r in t)n[r]=new sh(e,r,t[r]);return n}class sp{constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(" "):[],this.attrs=su(e,n.attrs),this.defaultAttrs=sl(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||"text"==e),this.isText="text"==e}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==sr.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:sc(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error("NodeType.create can't construct text nodes");return new se(this,this.computeAttrs(e),iW.from(t),iJ.setFrom(n))}createChecked(e=null,t,n){return t=iW.from(t),this.checkContent(t),new se(this,this.computeAttrs(e),t,iJ.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),(t=iW.from(t)).size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let r=this.contentMatch.matchFragment(t),i=r&&r.fillBefore(iW.empty,!0);return i?new se(this,e,t.append(i),iJ.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t<e.childCount;t++)if(!this.allowsMarks(e.child(t).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){sd(this.attrs,e,"node",this.name)}allowsMarkType(e){return null==this.markSet||this.markSet.indexOf(e)>-1}allowsMarks(e){if(null==this.markSet)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){let t;if(null==this.markSet)return e;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||(t=e.slice(0,n));return t?t.length?t:iJ.none:e}static compile(e,t){let n=Object.create(null);e.forEach((e,r)=>n[e]=new sp(e,t,r));let r=t.spec.topNode||"doc";if(!n[r])throw RangeError("Schema is missing its top node type ('"+r+"')");if(!n.text)throw RangeError("Every schema needs a 'text' type");for(let e in n.text.attrs)throw RangeError("The text node type should not have attributes");return n}}class sh{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate="string"==typeof n.validate?function(e,t,n){let r=n.split("|");return n=>{let i=null===n?"null":typeof n;if(0>r.indexOf(i))throw RangeError(`Expected value of type ${r} for attribute ${t} on type ${e}, got ${i}`)}}(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class sm{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=su(e,r.attrs),this.excluded=null;let i=sl(this.attrs);this.instance=i?new iJ(this,i):null}create(e=null){return!e&&this.instance?this.instance:new iJ(this,sc(this.attrs,e))}static compile(e,t){let n=Object.create(null),r=0;return e.forEach((e,i)=>n[e]=new sm(e,r++,t,i)),n}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){sd(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class sf{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=iV.from(e.nodes),t.marks=iV.from(e.marks||{}),this.nodes=sp.compile(this.spec.nodes,this),this.marks=sm.compile(this.spec.marks,this);let n=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw RangeError(e+" can not be both a node and a mark");let t=this.nodes[e],r=t.spec.content||"",i=t.spec.marks;if(t.contentMatch=n[r]||(n[r]=sr.parse(r,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError("Multiple linebreak nodes defined");if(!t.isInline||!t.isLeaf)throw RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=t}t.markSet="_"==i?null:i?sg(this,i.split(" ")):""!=i&&t.inlineContent?null:[]}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=null==n?[t]:""==n?[]:sg(this,n.split(" "))}this.nodeFromJSON=e=>se.fromJSON(this,e),this.markFromJSON=e=>iJ.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if("string"==typeof e)e=this.nodeType(e);else if(e instanceof sp){if(e.schema!=this)throw RangeError("Node type from different schema used ("+e.name+")")}else throw RangeError("Invalid node type: "+e);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new st(n,n.defaultAttrs,e,iJ.setFrom(t))}mark(e,t){return"string"==typeof e&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw RangeError("Unknown node type: "+e);return t}}function sg(e,t){let n=[];for(let r=0;r<t.length;r++){let i=t[r],s=e.marks[i],o=s;if(s)n.push(s);else for(let t in e.marks){let r=e.marks[t];("_"==i||r.spec.group&&r.spec.group.split(" ").indexOf(i)>-1)&&n.push(o=r)}if(!o)throw SyntaxError("Unknown mark type: '"+t[r]+"'")}return n}class sx{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(null!=e.tag)this.tags.push(e);else if(null!=e.style){let t=/[^=]*/.exec(e.style)[0];0>n.indexOf(t)&&n.push(t),this.styles.push(e)}}),this.normalizeLists=!this.tags.some(t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)})}parse(e,t={}){let n=new sN(this,t,!1);return n.addAll(e,iJ.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new sN(this,t,!0);return n.addAll(e,iJ.none,t.from,t.to),iX.maxOpen(n.finish())}matchTag(e,t,n){for(let s=n?this.tags.indexOf(n)+1:0;s<this.tags.length;s++){var r,i;let n=this.tags[s];if(r=e,i=n.tag,(r.matches||r.msMatchesSelector||r.webkitMatchesSelector||r.mozMatchesSelector).call(r,i)&&(void 0===n.namespace||e.namespaceURI==n.namespace)&&(!n.context||t.matchesContext(n.context))){if(n.getAttrs){let t=n.getAttrs(e);if(!1===t)continue;n.attrs=t||void 0}return n}}}matchStyle(e,t,n,r){for(let i=r?this.styles.indexOf(r)+1:0;i<this.styles.length;i++){let r=this.styles[i],s=r.style;if(0==s.indexOf(e)&&(!r.context||n.matchesContext(r.context))&&(!(s.length>e.length)||61==s.charCodeAt(e.length)&&s.slice(e.length+1)==t)){if(r.getAttrs){let e=r.getAttrs(t);if(!1===e)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=null==e.priority?50:e.priority,r=0;for(;r<t.length;r++){let e=t[r];if((null==e.priority?50:e.priority)<n)break}t.splice(r,0,e)}for(let t in e.marks){let r=e.marks[t].spec.parseDOM;r&&r.forEach(e=>{n(e=sS(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach(e=>{n(e=sS(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new sx(e,sx.schemaRules(e)))}}let sb={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},sy={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},sv={ol:!0,ul:!0};function sw(e,t,n){return null!=t?!!t|2*("full"===t):e&&"pre"==e.whitespace?3:-5&n}class sk{constructor(e,t,n,r,i,s){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=s,this.content=[],this.activeMarks=iJ.none,this.match=i||(4&s?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(iW.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let t=this.type.contentMatch,n;return(n=t.findWrapping(e.type))?(this.match=t,n):null}}return this.match.findWrapping(e.type)}finish(e){if(!(1&this.options)){let e=this.content[this.content.length-1],t;e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))&&(e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=e.withText(e.text.slice(0,e.text.length-t[0].length)))}let t=iW.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(iW.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!sb.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class sN{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,i,s=sw(null,t.preserveWhitespace,0)|4*!!n;i=r?new sk(r.type,r.attrs,iJ.none,!0,t.topMatch||r.type.contentMatch,s):n?new sk(null,null,iJ.none,!0,null,s):new sk(e.schema.topNodeType,null,iJ.none,!0,null,s),this.nodes=[i],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){3==e.nodeType?this.addTextNode(e,t):1==e.nodeType&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,r=this.top,i=2&r.options?"full":this.localPreserveWS||(1&r.options)>0,{schema:s}=this.parser;if("full"===i||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(i)if("full"===i)n=n.replace(/\r\n?/g,"\n");else if(s.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(s.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n<e.length;n++)n&&this.insertNode(s.linebreakReplacement.create(),t,!0),e[n]&&this.insertNode(s.text(e[n]),t,!/\S/.test(e[n]));n=""}else n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=r.content[r.content.length-1],i=e.previousSibling;(!t||i&&"BR"==i.nodeName||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}n&&this.insertNode(s.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let r=this.localPreserveWS,i=this.top;("PRE"==e.tagName||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let s=e.nodeName.toLowerCase(),o;sv.hasOwnProperty(s)&&this.parser.normalizeLists&&function(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=1==t.nodeType?t.nodeName.toLowerCase():null;e&&sv.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):"li"==e?n=t:e&&(n=null)}}(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,n));e:if(a?a.ignore:sy.hasOwnProperty(s))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let n,r=this.needsBlock;if(sb.hasOwnProperty(s))i.content.length&&i.content[0].isInline&&this.open&&(this.open--,i=this.top),n=!0,i.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let o=a&&a.skip?t:this.readStyles(e,t);o&&this.addAll(e,o),n&&this.sync(i),this.needsBlock=r}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,a,n,!1===a.consuming?o:void 0)}this.localPreserveWS=r}leafFallback(e,t){"BR"==e.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode("\n"),t)}ignoreFallback(e,t){"BR"!=e.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let e=0;e<this.parser.matchedStyles.length;e++){let r=this.parser.matchedStyles[e],i=n.getPropertyValue(r);if(i)for(let e;;){let n=this.parser.matchStyle(r,i,this,e);if(!n)break;if(n.ignore)return null;if(t=n.clearMark?t.filter(e=>!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),!1===n.consuming)e=n;else break}}return t}addElementByRule(e,t,n,r){let i,s;if(t.node)if((s=this.parser.schema.nodes[t.node]).isLeaf)this.insertNode(s.create(t.attrs),n,"BR"==e.nodeName)||this.leafFallback(e,n);else{let e=this.enter(s,t.attrs||null,n,t.preserveWhitespace);e&&(i=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let o=this.top;if(s&&s.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let r=e;"string"==typeof t.contentElement?r=e.querySelector(t.contentElement):"function"==typeof t.contentElement?r=t.contentElement(e):t.contentElement&&(r=t.contentElement),this.findAround(e,r,!0),this.addAll(r,n),this.findAround(e,r,!1)}i&&this.sync(o)&&this.open--}addAll(e,t,n,r){let i=n||0;for(let s=n?e.childNodes[n]:e.firstChild,o=null==r?null:e.childNodes[r];s!=o;s=s.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(s,t);this.findAtPoint(e,i)}findPlace(e,t,n){let r,i;for(let t=this.open,s=0;t>=0;t--){let o=this.nodes[t],a=o.findWrapping(e);if(a&&(!r||r.length>a.length+s)&&(r=a,i=o,!a.length))break;if(o.solid){if(n)break;s+=2}}if(!r)return null;this.sync(i);for(let e=0;e<r.length;e++)t=this.enterInner(r[e],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let e=this.textblockFromContext();e&&(t=this.enterInner(e,null,t))}let r=this.findPlace(e,t,n);if(r){this.closeExtra();let t=this.top;t.match&&(t.match=t.match.matchType(e.type));let n=iJ.none;for(let i of r.concat(e.marks))(t.type?t.type.allowsMarkType(i.type):sC(i.type,e.type))&&(n=i.addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n,r){let i=this.findPlace(e.create(t),n,!1);return i&&(i=this.enterInner(e,t,n,!0,r)),i}enterInner(e,t,n,r=!1,i){this.closeExtra();let s=this.top;s.match=s.match&&s.match.matchType(e);let o=sw(e,i,s.options);4&s.options&&0==s.content.length&&(o|=4);let a=iJ.none;return n=n.filter(t=>(s.type?!s.type.allowsMarkType(t.type):!sC(t.type,e))||(a=t.addToSet(a),!1)),this.nodes.push(new sk(e,t,a,r,null,o)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;else this.localPreserveWS&&(this.nodes[t].options|=1);return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)null==this.find[t].pos&&1==e.nodeType&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let r=0;r<this.find.length;r++)null==this.find[r].pos&&1==e.nodeType&&e.contains(this.find[r].node)&&t.compareDocumentPosition(this.find[r].node)&(n?2:4)&&(this.find[r].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),n=this.options.context,r=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),i=-(n?n.depth+1:0)+ +!r,s=(e,o)=>{for(;e>=0;e--){let a=t[e];if(""==a){if(e==t.length-1||0==e)continue;for(;o>=i;o--)if(s(e-1,o))return!0;return!1}{let e=o>0||0==o&&r?this.nodes[o].type:n&&o>=i?n.node(o-i).type:null;if(!e||e.name!=a&&!e.isInGroup(a))return!1;o--}}return!0};return s(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}}function sS(e){let t={};for(let n in e)t[n]=e[n];return t}function sC(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let s=[],o=e=>{s.push(e);for(let n=0;n<e.edgeCount;n++){let{type:r,next:i}=e.edge(n);if(r==t||0>s.indexOf(i)&&o(i))return!0}};if(o(i.contentMatch))return!0}}class sj{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=sM(t).createDocumentFragment());let r=n,i=[];return e.forEach(e=>{if(i.length||e.marks.length){let n=0,s=0;for(;n<i.length&&s<e.marks.length;){let t=e.marks[s];if(!this.marks[t.type.name]){s++;continue}if(!t.eq(i[n][0])||!1===t.type.spec.spanning)break;n++,s++}for(;n<i.length;)r=i.pop()[1];for(;s<e.marks.length;){let n=e.marks[s++],o=this.serializeMark(n,e.isInline,t);o&&(i.push([n,r]),r.appendChild(o.dom),r=o.contentDOM||o.dom)}}r.appendChild(this.serializeNodeInner(e,t))}),n}serializeNodeInner(e,t){if(e.isText)return sM(t).createTextNode(e.text);let{dom:n,contentDOM:r}=sT(sM(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,r)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let r=e.marks.length-1;r>=0;r--){let i=this.serializeMark(e.marks[r],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(n),n=i.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&sT(sM(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return"string"==typeof t?{dom:e.createTextNode(t)}:sT(e,t,n,r)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new sj(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=sE(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return sE(e.marks)}}function sE(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function sM(e){return e.document||window.document}let sA=new WeakMap;function sT(e,t,n,r){let i,s,o;if(1==t.nodeType)return{dom:t};if(t.dom&&1==t.dom.nodeType)return t;let a=t[0],l;if("string"!=typeof a)throw RangeError("Invalid array passed to renderSpec");if(r&&(void 0===(s=sA.get(r))&&sA.set(r,(o=null,!function e(t){if(t&&"object"==typeof t)if(Array.isArray(t))if("string"==typeof t[0])o||(o=[]),o.push(t);else for(let n=0;n<t.length;n++)e(t[n]);else for(let n in t)e(t[n])}(r),s=o)),l=s)&&l.indexOf(t)>-1)throw RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let c=a.indexOf(" ");c>0&&(n=a.slice(0,c),a=a.slice(c+1));let d=n?e.createElementNS(n,a):e.createElement(a),u=t[1],p=1;if(u&&"object"==typeof u&&null==u.nodeType&&!Array.isArray(u)){for(let e in p=2,u)if(null!=u[e]){let t=e.indexOf(" ");t>0?d.setAttributeNS(e.slice(0,t),e.slice(t+1),u[e]):"style"==e&&d.style?d.style.cssText=u[e]:d.setAttribute(e,u[e])}}for(let s=p;s<t.length;s++){let o=t[s];if(0===o){if(s<t.length-1||s>p)throw RangeError("Content hole must be the only child of its parent node");return{dom:d,contentDOM:d}}if("string"==typeof o)d.appendChild(e.createTextNode(o));else{let{dom:t,contentDOM:s}=sT(e,o,n,r);if(d.appendChild(t),s){if(i)throw RangeError("Multiple content holes");i=s}}}return{dom:d,contentDOM:i}}class sO{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(8&this.delInfo)>0}get deletedBefore(){return(5&this.delInfo)>0}get deletedAfter(){return(6&this.delInfo)>0}get deletedAcross(){return(4&this.delInfo)>0}}class s_{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&s_.empty)return s_.empty}recover(e){let t=0,n=65535&e;if(!this.inverted)for(let e=0;e<n;e++)t+=this.ranges[3*e+2]-this.ranges[3*e+1];return this.ranges[3*n]+t+(e-(65535&e))/65536}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,n){let r=0,i=this.inverted?2:1,s=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let a=this.ranges[o]-(this.inverted?r:0);if(a>e)break;let l=this.ranges[o+i],c=this.ranges[o+s],d=a+l;if(e<=d){let i=l?e==a?-1:e==d?1:t:t,s=a+r+(i<0?0:c);if(n)return s;let u=e==(t<0?a:d)?null:o/3+(e-a)*65536,p=e==a?2:e==d?1:4;return(t<0?e!=a:e!=d)&&(p|=8),new sO(s,p,u)}r+=c-l}return n?e+r:new sO(e+r,0,null)}touches(e,t){let n=0,r=65535&t,i=this.inverted?2:1,s=this.inverted?1:2;for(let t=0;t<this.ranges.length;t+=3){let o=this.ranges[t]-(this.inverted?n:0);if(o>e)break;let a=this.ranges[t+i];if(e<=o+a&&t==3*r)return!0;n+=this.ranges[t+s]-a}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r<this.ranges.length;r+=3){let s=this.ranges[r],o=s-(this.inverted?i:0),a=s+(this.inverted?0:i),l=this.ranges[r+t],c=this.ranges[r+n];e(o,o+l,a,a+c),i+=c-l}}invert(){return new s_(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return 0==e?s_.empty:new s_(e<0?[0,-e,0]:[0,0,e])}}s_.empty=new s_([]);class sD{constructor(e,t,n=0,r=e?e.length:0){this.mirror=t,this.from=n,this.to=r,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new sD(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),null!=t&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let r=e.getMirror(t);this.appendMap(e._maps[t],null!=r&&r<t?n+r:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),null!=r&&r>t?n-r-1:void 0)}}invert(){let e=new sD;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this._maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let r=0;for(let n=this.from;n<this.to;n++){let i=this._maps[n].mapResult(e,t);if(null!=i.recover){let t=this.getMirror(n);if(null!=t&&t>n&&t<this.to){n=t,e=this._maps[t].recover(i.recover);continue}}r|=i.delInfo,e=i.pos}return n?e:new sO(e,r,null)}}let sR=Object.create(null);class sI{getMap(){return s_.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw RangeError("Invalid input for Step.fromJSON");let n=sR[t.stepType];if(!n)throw RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in sR)throw RangeError("Duplicate use of step JSON ID "+e);return sR[e]=t,t.prototype.jsonID=e,t}}class sL{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new sL(e,null)}static fail(e){return new sL(null,e)}static fromReplace(e,t,n,r){try{return sL.ok(e.replace(t,n,r))}catch(e){if(e instanceof iZ)return sL.fail(e.message);throw e}}}function sP(e,t,n){let r=[];for(let i=0;i<e.childCount;i++){let s=e.child(i);s.content.size&&(s=s.copy(sP(s.content,t,s))),s.isInline&&(s=t(s,n,i)),r.push(s)}return iW.fromArray(r)}class s$ extends sI{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=e.resolve(this.from),r=n.node(n.sharedDepth(this.to)),i=new iX(sP(t.content,(e,t)=>e.isAtom&&t.type.allowsMarkType(this.mark.type)?e.mark(this.mark.addToSet(e.marks)):e,r),t.openStart,t.openEnd);return sL.fromReplace(e,this.from,this.to,i)}invert(){return new sz(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new s$(t.pos,n.pos,this.mark)}merge(e){return e instanceof s$&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new s$(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw RangeError("Invalid input for AddMarkStep.fromJSON");return new s$(t.from,t.to,e.markFromJSON(t.mark))}}sI.jsonID("addMark",s$);class sz extends sI{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new iX(sP(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return sL.fromReplace(e,this.from,this.to,n)}invert(){return new s$(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new sz(t.pos,n.pos,this.mark)}merge(e){return e instanceof sz&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new sz(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw RangeError("Invalid input for RemoveMarkStep.fromJSON");return new sz(t.from,t.to,e.markFromJSON(t.mark))}}sI.jsonID("removeMark",sz);class sB extends sI{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return sL.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return sL.fromReplace(e,this.pos,this.pos+1,new iX(iW.from(n),0,+!t.isLeaf))}invert(e){let t=e.nodeAt(this.pos);if(t){let e=this.mark.addToSet(t.marks);if(e.length==t.marks.length){for(let n=0;n<t.marks.length;n++)if(!t.marks[n].isInSet(e))return new sB(this.pos,t.marks[n]);return new sB(this.pos,this.mark)}}return new sF(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new sB(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if("number"!=typeof t.pos)throw RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new sB(t.pos,e.markFromJSON(t.mark))}}sI.jsonID("addNodeMark",sB);class sF extends sI{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return sL.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return sL.fromReplace(e,this.pos,this.pos+1,new iX(iW.from(n),0,+!t.isLeaf))}invert(e){let t=e.nodeAt(this.pos);return t&&this.mark.isInSet(t.marks)?new sB(this.pos,this.mark):this}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new sF(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if("number"!=typeof t.pos)throw RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new sF(t.pos,e.markFromJSON(t.mark))}}sI.jsonID("removeNodeMark",sF);class sH extends sI{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&sV(e,this.from,this.to)?sL.fail("Structure replace would overwrite content"):sL.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new s_([this.from,this.to-this.from,this.slice.size])}invert(e){return new sH(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.to,-1),n=this.from==this.to&&sH.MAP_BIAS<0?t:e.mapResult(this.from,1);return n.deletedAcross&&t.deletedAcross?null:new sH(n.pos,Math.max(n.pos,t.pos),this.slice,this.structure)}merge(e){if(!(e instanceof sH)||e.structure||this.structure)return null;if(this.from+this.slice.size!=e.from||this.slice.openEnd||e.slice.openStart)if(e.to!=this.from||this.slice.openStart||e.slice.openEnd)return null;else{let t=this.slice.size+e.slice.size==0?iX.empty:new iX(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new sH(e.from,this.to,t,this.structure)}{let t=this.slice.size+e.slice.size==0?iX.empty:new iX(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new sH(this.from,this.to+(e.to-e.from),t,this.structure)}}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw RangeError("Invalid input for ReplaceStep.fromJSON");return new sH(t.from,t.to,iX.fromJSON(e,t.slice),!!t.structure)}}sH.MAP_BIAS=1,sI.jsonID("replace",sH);class sU extends sI{constructor(e,t,n,r,i,s,o=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=i,this.insert=s,this.structure=o}apply(e){if(this.structure&&(sV(e,this.from,this.gapFrom)||sV(e,this.gapTo,this.to)))return sL.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return sL.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?sL.fromReplace(e,this.from,this.to,n):sL.fail("Content does not fit in gap")}getMap(){return new s_([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new sU(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1),r=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),i=this.to==this.gapTo?n.pos:e.map(this.gapTo,1);return t.deletedAcross&&n.deletedAcross||r<t.pos||i>n.pos?null:new sU(t.pos,n.pos,r,i,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to||"number"!=typeof t.gapFrom||"number"!=typeof t.gapTo||"number"!=typeof t.insert)throw RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new sU(t.from,t.to,t.gapFrom,t.gapTo,iX.fromJSON(e,t.slice),t.insert,!!t.structure)}}function sV(e,t,n){let r=e.resolve(t),i=n-t,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let e=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function sW(e,t,n,r=n.contentMatch,i=!0){let s=e.doc.nodeAt(t),o=[],a=t+1;for(let t=0;t<s.childCount;t++){let l=s.child(t),c=a+l.nodeSize,d=r.matchType(l.type);if(d){r=d;for(let t=0;t<l.marks.length;t++)n.allowsMarkType(l.marks[t].type)||e.step(new sz(a,c,l.marks[t]));if(i&&l.isText&&"pre"!=n.whitespace){let e,t=/\r?\n|\r/g,r;for(;e=t.exec(l.text);)r||(r=new iX(iW.from(n.schema.text(" ",n.allowedMarks(l.marks))),0,0)),o.push(new sH(a+e.index,a+e.index+e[0].length,r))}}else o.push(new sH(a,c,iX.empty));a=c}if(!r.validEnd){let t=r.fillBefore(iW.empty,!0);e.replace(a,a,new iX(t,0,0))}for(let t=o.length-1;t>=0;t--)e.step(o[t])}function sq(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth,r=0,i=0;;--n){let s=e.$from.node(n),o=e.$from.index(n)+r,a=e.$to.indexAfter(n)-i;if(n<e.depth&&s.canReplace(o,a,t))return n;if(0==n||s.type.spec.isolating||!((0==o||s.canReplace(o,s.childCount))&&(a==s.childCount||s.canReplace(0,a))))break;o&&(r=1),a<s.childCount&&(i=1)}return null}function sK(e,t,n=null,r=e){let i=function(e,t){let{parent:n,startIndex:r,endIndex:i}=e,s=n.contentMatchAt(r).findWrapping(t);if(!s)return null;let o=s.length?s[0]:t;return n.canReplaceWith(r,i,o)?s:null}(e,t),s=i&&function(e,t){let{parent:n,startIndex:r,endIndex:i}=e,s=n.child(r),o=t.contentMatch.findWrapping(s.type);if(!o)return null;let a=(o.length?o[o.length-1]:t).contentMatch;for(let e=r;a&&e<i;e++)a=a.matchType(n.child(e).type);return a&&a.validEnd?o:null}(r,t);return s?i.map(sG).concat({type:t,attrs:n}).concat(s.map(sG)):null}function sG(e){return{type:e,attrs:null}}function sJ(e,t,n,r){t.forEach((i,s)=>{if(i.isText){let o,a=/\r?\n|\r/g;for(;o=a.exec(i.text);){let i=e.mapping.slice(r).map(n+1+s+o.index);e.replaceWith(i,i+1,t.type.schema.linebreakReplacement.create())}}})}function sZ(e,t,n,r){t.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let i=e.mapping.slice(r).map(n+1+s);e.replaceWith(i,i+1,t.type.schema.text("\n"))}})}function sX(e,t,n=1,r){let i=e.resolve(t),s=i.depth-n,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let e=i.depth-1,t=n-2;e>s;e--,t--){let n=i.node(e),s=i.index(e);if(n.type.spec.isolating)return!1;let o=n.content.cutByIndex(s,n.childCount),a=r&&r[t+1];a&&(o=o.replaceChild(0,a.type.create(a.attrs)));let l=r&&r[t]||n;if(!n.canReplace(s+1,n.childCount)||!l.type.validContent(o))return!1}let a=i.indexAfter(s),l=r&&r[0];return i.node(s).canReplaceWith(a,a,l?l.type:i.node(s+1).type)}function sY(e,t){let n=e.resolve(t),r=n.index();return sQ(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function sQ(e,t){return!!(e&&t&&!e.isLeaf&&function(e,t){t.content.size||e.type.compatibleContent(t.type);let n=e.contentMatchAt(e.childCount),{linebreakReplacement:r}=e.type.schema;for(let i=0;i<t.childCount;i++){let s=t.child(i),o=s.type==r?e.type.schema.nodes.text:s.type;if(!(n=n.matchType(o))||!e.type.allowsMarks(s.marks))return!1}return n.validEnd}(e,t))}function s0(e,t,n=-1){let r=e.resolve(t);for(let e=r.depth;;e--){let i,s,o=r.index(e);if(e==r.depth?(i=r.nodeBefore,s=r.nodeAfter):n>0?(i=r.node(e+1),o++,s=r.node(e).maybeChild(o)):(i=r.node(e).maybeChild(o-1),s=r.node(e+1)),i&&!i.isTextblock&&sQ(i,s)&&r.node(e).canReplace(o,o+1))return t;if(0==e)break;t=n<0?r.before(e):r.after(e)}}function s1(e,t,n){let r=e.resolve(t);if(!n.content.size)return t;let i=n.content;for(let e=0;e<n.openStart;e++)i=i.firstChild.content;for(let e=1;e<=(0==n.openStart&&n.size?2:1);e++)for(let t=r.depth;t>=0;t--){let n=t==r.depth?0:r.pos<=(r.start(t+1)+r.end(t+1))/2?-1:1,s=r.index(t)+ +(n>0),o=r.node(t),a=!1;if(1==e)a=o.canReplace(s,s,i);else{let e=o.contentMatchAt(s).findWrapping(i.firstChild.type);a=e&&o.canReplaceWith(s,s,e[0])}if(a)return 0==n?r.pos:n<0?r.before(t+1):r.after(t+1)}return null}function s2(e,t,n=t,r=iX.empty){if(t==n&&!r.size)return null;let i=e.resolve(t),s=e.resolve(n);return s5(i,s,r)?new sH(t,n,r):new s3(i,s,r).fit()}function s5(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}sI.jsonID("replaceAround",sU);class s3{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=iW.empty;for(let t=0;t<=e.depth;t++){let n=e.node(t);this.frontier.push({type:n.type,match:n.contentMatchAt(e.indexAfter(t))})}for(let t=e.depth;t>0;t--)this.placed=iW.from(e.node(t).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let e=this.findFittable();e?this.placeNodes(e):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(e<0?this.$to:n.doc.resolve(e));if(!r)return null;let i=this.placed,s=n.depth,o=r.depth;for(;s&&o&&1==i.childCount;)i=i.firstChild.content,s--,o--;let a=new iX(i,s,o);return e>-1?new sU(n.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||n.pos!=this.$to.pos?new sH(n.pos,r.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,r=this.unplaced.openEnd;n<e;n++){let i=t.firstChild;if(t.childCount>1&&(r=0),i.type.spec.isolating&&r<=n){e=n;break}t=i.content}for(let t=1;t<=2;t++)for(let n=1==t?e:this.unplaced.openStart;n>=0;n--){let e=null,r=(n?(e=s9(this.unplaced.content,n-1).firstChild).content:this.unplaced.content).firstChild;for(let i=this.depth;i>=0;i--){let{type:s,match:o}=this.frontier[i],a,l=null;if(1==t&&(r?o.matchType(r.type)||(l=o.fillBefore(iW.from(r),!1)):e&&s.compatibleContent(e.type)))return{sliceDepth:n,frontierDepth:i,parent:e,inject:l};if(2==t&&r&&(a=o.findWrapping(r.type)))return{sliceDepth:n,frontierDepth:i,parent:e,wrap:a};if(e&&o.matchType(e.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=s9(e,t);return!!r.childCount&&!r.firstChild.isLeaf&&(this.unplaced=new iX(e,t+1,Math.max(n,r.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=s9(e,t);if(r.childCount<=1&&t>0){let i=e.size-t<=t+r.size;this.unplaced=new iX(s4(e,t-1,1),t-1,i?t-1:n)}else this.unplaced=new iX(s4(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:r,wrap:i}){for(;this.depth>t;)this.closeFrontierNode();if(i)for(let e=0;e<i.length;e++)this.openFrontierNode(i[e]);let s=this.unplaced,o=n?n.content:s.content,a=s.openStart-e,l=0,c=[],{match:d,type:u}=this.frontier[t];if(r){for(let e=0;e<r.childCount;e++)c.push(r.child(e));d=d.matchFragment(r)}let p=o.size+e-(s.content.size-s.openEnd);for(;l<o.childCount;){let e=o.child(l),t=d.matchType(e.type);if(!t)break;(++l>1||0==a||e.content.size)&&(d=t,c.push(function e(t,n,r){if(n<=0)return t;let i=t.content;return n>1&&(i=i.replaceChild(0,e(i.firstChild,n-1,1==i.childCount?r-1:0))),n>0&&(i=t.type.contentMatch.fillBefore(i).append(i),r<=0&&(i=i.append(t.type.contentMatch.matchFragment(i).fillBefore(iW.empty,!0)))),t.copy(i)}(e.mark(u.allowedMarks(e.marks)),1==l?a:0,l==o.childCount?p:-1)))}let h=l==o.childCount;h||(p=-1),this.placed=s6(this.placed,t,iW.from(c)),this.frontier[t].match=d,h&&p<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=o;e<p;e++){let e=t.lastChild;this.frontier.push({type:e.type,match:e.contentMatchAt(e.childCount)}),t=e.content}this.unplaced=h?0==e?iX.empty:new iX(s4(s.content,e-1,1),e-1,p<0?s.openEnd:e-1):new iX(s4(s.content,e,l),s.openStart,s.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return -1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!s7(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return -1;let{depth:n}=this.$to,r=this.$to.after(n);for(;n>1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){t:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],i=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),s=s7(e,t,r,n,i);if(s){for(let n=t-1;n>=0;n--){let{match:t,type:r}=this.frontier[n],i=s7(e,n,r,t,!0);if(!i||i.childCount)continue t}return{depth:t,fit:s,move:i?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=s6(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),r=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,r)}return e}openFrontierNode(e,t=null,n){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=s6(this.placed,this.depth,iW.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(iW.empty,!0);e.childCount&&(this.placed=s6(this.placed,this.frontier.length,e))}}function s4(e,t,n){return 0==t?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(s4(e.firstChild.content,t-1,n)))}function s6(e,t,n){return 0==t?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(s6(e.lastChild.content,t-1,n)))}function s9(e,t){for(let n=0;n<t;n++)e=e.firstChild.content;return e}function s7(e,t,n,r,i){let s=e.node(t),o=i?e.indexAfter(t):e.index(t);if(o==s.childCount&&!n.compatibleContent(s.type))return null;let a=r.fillBefore(s.content,!0,o);return a&&!function(e,t,n){for(let r=n;r<t.childCount;r++)if(!e.allowsMarks(t.child(r).marks))return!0;return!1}(n,s.content,o)?a:null}function s8(e,t){let n=[],r=Math.min(e.depth,t.depth);for(let i=r;i>=0;i--){let r=e.start(i);if(r<e.pos-(e.depth-i)||t.end(i)>t.pos+(t.depth-i)||e.node(i).type.spec.isolating||t.node(i).type.spec.isolating)break;(r==t.start(i)||i==e.depth&&i==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&i&&t.start(i-1)==r-1)&&n.push(i)}return n}class oe extends sI{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return sL.fail("No node at attribute step's position");let n=Object.create(null);for(let e in t.attrs)n[e]=t.attrs[e];n[this.attr]=this.value;let r=t.type.create(n,null,t.marks);return sL.fromReplace(e,this.pos,this.pos+1,new iX(iW.from(r),0,+!t.isLeaf))}getMap(){return s_.empty}invert(e){return new oe(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new oe(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if("number"!=typeof t.pos||"string"!=typeof t.attr)throw RangeError("Invalid input for AttrStep.fromJSON");return new oe(t.pos,t.attr,t.value)}}sI.jsonID("attr",oe);class ot extends sI{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let n in e.attrs)t[n]=e.attrs[n];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return sL.ok(n)}getMap(){return s_.empty}invert(e){return new ot(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if("string"!=typeof t.attr)throw RangeError("Invalid input for DocAttrStep.fromJSON");return new ot(t.attr,t.value)}}sI.jsonID("docAttr",ot);let on=class extends Error{};(on=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n}).prototype=Object.create(Error.prototype),on.prototype.constructor=on,on.prototype.name="TransformError";class or{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new sD}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new on(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let n=0;n<this.mapping.maps.length;n++){let r=this.mapping.maps[n];n&&(e=r.map(e,1),t=r.map(t,-1)),r.forEach((n,r,i,s)=>{e=Math.min(e,i),t=Math.max(t,s)})}return 1e9==e?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=iX.empty){let r=s2(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new iX(iW.from(n),0,0))}delete(e,t){return this.replace(e,t,iX.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return!function(e,t,n,r){if(!r.size)return e.deleteRange(t,n);let i=e.doc.resolve(t),s=e.doc.resolve(n);if(s5(i,s,r))return e.step(new sH(t,n,r));let o=s8(i,s);0==o[o.length-1]&&o.pop();let a=-(i.depth+1);o.unshift(a);for(let e=i.depth,t=i.pos-1;e>0;e--,t--){let n=i.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;o.indexOf(e)>-1?a=e:i.before(e)==t&&o.splice(1,0,-e)}let l=o.indexOf(a),c=[],d=r.openStart;for(let e=r.content,t=0;;t++){let n=e.firstChild;if(c.push(n),t==r.openStart)break;e=n.content}for(let e=d-1;e>=0;e--){var u;let t=c[e],n=(u=t.type).spec.defining||u.spec.definingForContent;if(n&&!t.sameMarkup(i.node(Math.abs(a)-1)))d=e;else if(n||!t.type.isTextblock)break}for(let t=r.openStart;t>=0;t--){let a=(t+d+1)%(r.openStart+1),u=c[a];if(u)for(let t=0;t<o.length;t++){let c=o[(t+l)%o.length],d=!0;c<0&&(d=!1,c=-c);let p=i.node(c-1),h=i.index(c-1);if(p.canReplaceWith(h,h,u.type,u.marks))return e.replace(i.before(c),d?s.after(c):n,new iX(function e(t,n,r,i,s){if(n<r){let s=t.firstChild;t=t.replaceChild(0,s.copy(e(s.content,n+1,r,i,s)))}if(n>i){let e=s.contentMatchAt(0),n=e.fillBefore(t).append(t);t=n.append(e.matchFragment(n).fillBefore(iW.empty,!0))}return t}(r.content,0,r.openStart,a),a,r.openEnd))}}let p=e.steps.length;for(let a=o.length-1;a>=0&&(e.replace(t,n,r),!(e.steps.length>p));a--){let e=o[a];e<0||(t=i.before(e),n=s.after(e))}}(this,e,t,n),this}replaceRangeWith(e,t,n){var r=e,i=t;if(!n.isInline&&r==i&&this.doc.resolve(r).parent.content.size){let e=function(e,t,n){let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;if(0==r.parentOffset)for(let e=r.depth-1;e>=0;e--){let t=r.index(e);if(r.node(e).canReplaceWith(t,t,n))return r.before(e+1);if(t>0)return null}if(r.parentOffset==r.parent.content.size)for(let e=r.depth-1;e>=0;e--){let t=r.indexAfter(e);if(r.node(e).canReplaceWith(t,t,n))return r.after(e+1);if(t<r.node(e).childCount)break}return null}(this.doc,r,n.type);null!=e&&(r=i=e)}return this.replaceRange(r,i,new iX(iW.from(n),0,0)),this}deleteRange(e,t){return!function(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n);if(r.parent.isTextblock&&i.parent.isTextblock&&r.start()!=i.start()&&0==r.parentOffset&&0==i.parentOffset){let s=r.sharedDepth(n),o=!1;for(let e=r.depth;e>s;e--)r.node(e).type.spec.isolating&&(o=!0);for(let e=i.depth;e>s;e--)i.node(e).type.spec.isolating&&(o=!0);if(!o){for(let e=r.depth;e>0&&t==r.start(e);e--)t=r.before(e);for(let e=i.depth;e>0&&n==i.start(e);e--)n=i.before(e);r=e.doc.resolve(t),i=e.doc.resolve(n)}}let s=s8(r,i);for(let t=0;t<s.length;t++){let n=s[t],o=t==s.length-1;if(o&&0==n||r.node(n).type.contentMatch.validEnd)return e.delete(r.start(n),i.end(n));if(n>0&&(o||r.node(n-1).canReplace(r.index(n-1),i.indexAfter(n-1))))return e.delete(r.before(n),i.after(n))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(t-r.start(s)==r.depth-s&&n>r.end(s)&&i.end(s)-n!=i.depth-s&&r.start(s-1)==i.start(s-1)&&r.node(s-1).canReplace(r.index(s-1),i.index(s-1)))return e.delete(r.before(s),n);e.delete(t,n)}(this,e,t),this}lift(e,t){return!function(e,t,n){let{$from:r,$to:i,depth:s}=t,o=r.before(s+1),a=i.after(s+1),l=o,c=a,d=iW.empty,u=0;for(let e=s,t=!1;e>n;e--)t||r.index(e)>0?(t=!0,d=iW.from(r.node(e).copy(d)),u++):l--;let p=iW.empty,h=0;for(let e=s,t=!1;e>n;e--)t||i.after(e+1)<i.end(e)?(t=!0,p=iW.from(i.node(e).copy(p)),h++):c++;e.step(new sU(l,c,o,a,new iX(d.append(p),u,h),d.size-u,!0))}(this,e,t),this}join(e,t=1){return!function(e,t,n){let r=null,{linebreakReplacement:i}=e.doc.type.schema,s=e.doc.resolve(t-n),o=s.node().type;if(i&&o.inlineContent){let e="pre"==o.whitespace,t=!!o.contentMatch.matchType(i);e&&!t?r=!1:!e&&t&&(r=!0)}let a=e.steps.length;if(!1===r){let r=e.doc.resolve(t+n);sZ(e,r.node(),r.before(),a)}o.inlineContent&&sW(e,t+n-1,o,s.node().contentMatchAt(s.index()),null==r);let l=e.mapping.slice(a),c=l.map(t-n);if(e.step(new sH(c,l.map(t+n,-1),iX.empty,!0)),!0===r){let t=e.doc.resolve(c);sJ(e,t.node(),t.before(),e.steps.length)}}(this,e,t),this}wrap(e,t){return!function(e,t,n){let r=iW.empty;for(let e=n.length-1;e>=0;e--){if(r.size){let t=n[e].type.contentMatch.matchFragment(r);if(!t||!t.validEnd)throw RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=iW.from(n[e].type.create(n[e].attrs,r))}let i=t.start,s=t.end;e.step(new sU(i,s,i,s,new iX(r,0,0),n.length,!0))}(this,e,t),this}setBlockType(e,t=e,n,r=null){var i=this;if(!n.isTextblock)throw RangeError("Type given to setBlockType should be a textblock");let s=i.steps.length;return i.doc.nodesBetween(e,t,(e,t)=>{var o,a,l;let c,d,u="function"==typeof r?r(e):r;if(e.isTextblock&&!e.hasMarkup(n,u)&&(o=i.doc,a=i.mapping.slice(s).map(t),l=n,d=(c=o.resolve(a)).index(),c.parent.canReplaceWith(d,d+1,l))){let r=null;if(n.schema.linebreakReplacement){let e="pre"==n.whitespace,t=!!n.contentMatch.matchType(n.schema.linebreakReplacement);e&&!t?r=!1:!e&&t&&(r=!0)}!1===r&&sZ(i,e,t,s),sW(i,i.mapping.slice(s).map(t,1),n,void 0,null===r);let o=i.mapping.slice(s),a=o.map(t,1),l=o.map(t+e.nodeSize,1);return i.step(new sU(a,l,a+1,l-1,new iX(iW.from(n.create(u,null,e.marks)),0,0),1,!0)),!0===r&&sJ(i,e,t,s),!1}}),this}setNodeMarkup(e,t,n=null,r){return!function(e,t,n,r,i){let s=e.doc.nodeAt(t);if(!s)throw RangeError("No node at given position");n||(n=s.type);let o=n.create(r,null,i||s.marks);if(s.isLeaf)return e.replaceWith(t,t+s.nodeSize,o);if(!n.validContent(s.content))throw RangeError("Invalid content for node type "+n.name);e.step(new sU(t,t+s.nodeSize,t+1,t+s.nodeSize-1,new iX(iW.from(o),0,0),1,!0))}(this,e,t,n,r),this}setNodeAttribute(e,t,n){return this.step(new oe(e,t,n)),this}setDocAttribute(e,t){return this.step(new ot(e,t)),this}addNodeMark(e,t){return this.step(new sB(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw RangeError("No node at position "+e);if(t instanceof iJ)t.isInSet(n.marks)&&this.step(new sF(e,t));else{let r=n.marks,i,s=[];for(;i=t.isInSet(r);)s.push(new sF(e,i)),r=i.removeFromSet(r);for(let e=s.length-1;e>=0;e--)this.step(s[e])}return this}split(e,t=1,n){return!function(e,t,n=1,r){let i=e.doc.resolve(t),s=iW.empty,o=iW.empty;for(let e=i.depth,t=i.depth-n,a=n-1;e>t;e--,a--){s=iW.from(i.node(e).copy(s));let t=r&&r[a];o=iW.from(t?t.type.create(t.attrs,o):i.node(e).copy(o))}e.step(new sH(t,t,new iX(s.append(o),n,n),!0))}(this,e,t,n),this}addMark(e,t,n){var r;let i,s,o,a;return r=this,o=[],a=[],r.doc.nodesBetween(e,t,(r,l,c)=>{if(!r.isInline)return;let d=r.marks;if(!n.isInSet(d)&&c.type.allowsMarkType(n.type)){let c=Math.max(l,e),u=Math.min(l+r.nodeSize,t),p=n.addToSet(d);for(let e=0;e<d.length;e++)d[e].isInSet(p)||(i&&i.to==c&&i.mark.eq(d[e])?i.to=u:o.push(i=new sz(c,u,d[e])));s&&s.to==c?s.to=u:a.push(s=new s$(c,u,n))}}),o.forEach(e=>r.step(e)),a.forEach(e=>r.step(e)),this}removeMark(e,t,n){var r;let i,s;return r=this,i=[],s=0,r.doc.nodesBetween(e,t,(r,o)=>{if(!r.isInline)return;s++;let a=null;if(n instanceof sm){let e=r.marks,t;for(;t=n.isInSet(e);)(a||(a=[])).push(t),e=t.removeFromSet(e)}else n?n.isInSet(r.marks)&&(a=[n]):a=r.marks;if(a&&a.length){let n=Math.min(o+r.nodeSize,t);for(let t=0;t<a.length;t++){let r=a[t],l;for(let e=0;e<i.length;e++){let t=i[e];t.step==s-1&&r.eq(i[e].style)&&(l=t)}l?(l.to=n,l.step=s):i.push({style:r,from:Math.max(o,e),to:n,step:s})}}}),i.forEach(e=>r.step(new sz(e.from,e.to,e.style))),this}clearIncompatible(e,t,n){return sW(this,e,t,n),this}}let oi=Object.create(null);class oo{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new oa(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=iX.empty){let n=t.content.lastChild,r=null;for(let e=0;e<t.openEnd;e++)r=n,n=n.lastChild;let i=e.steps.length,s=this.ranges;for(let o=0;o<s.length;o++){let{$from:a,$to:l}=s[o],c=e.mapping.slice(i);e.replaceRange(c.map(a.pos),c.map(l.pos),o?iX.empty:t),0==o&&ox(e,i,(n?n.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:s,$to:o}=r[i],a=e.mapping.slice(n),l=a.map(s.pos),c=a.map(o.pos);i?e.deleteRange(l,c):(e.replaceRangeWith(l,c,t),ox(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new od(e):og(e.node(0),e.parent,e.pos,e.index(),t,n);if(r)return r;for(let r=e.depth-1;r>=0;r--){let i=t<0?og(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):og(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,t,n);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new om(e.node(0))}static atStart(e){return og(e,e,0,0,1)||new om(e)}static atEnd(e){return og(e,e,e.content.size,e.childCount,-1)||new om(e)}static fromJSON(e,t){if(!t||!t.type)throw RangeError("Invalid input for Selection.fromJSON");let n=oi[t.type];if(!n)throw RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in oi)throw RangeError("Duplicate use of selection JSON ID "+e);return oi[e]=t,t.prototype.jsonID=e,t}getBookmark(){return od.between(this.$anchor,this.$head).getBookmark()}}oo.prototype.visible=!0;class oa{constructor(e,t){this.$from=e,this.$to=t}}let ol=!1;function oc(e){ol||e.parent.inlineContent||(ol=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class od extends oo{constructor(e,t=e){oc(e),oc(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return oo.near(n);let r=e.resolve(t.map(this.anchor));return new od(r.parent.inlineContent?r:n,n)}replace(e,t=iX.empty){if(super.replace(e,t),t==iX.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(e){return e instanceof od&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new ou(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if("number"!=typeof t.anchor||"number"!=typeof t.head)throw RangeError("Invalid input for TextSelection.fromJSON");return new od(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(e,t,n){let r=e.pos-t.pos;if((!n||r)&&(n=r>=0?1:-1),!t.parent.inlineContent){let e=oo.findFrom(t,n,!0)||oo.findFrom(t,-n,!0);if(!e)return oo.near(t,n);t=e.$head}return e.parent.inlineContent||(0==r?e=t:(e=(oo.findFrom(e,-n,!0)||oo.findFrom(e,n,!0)).$anchor).pos<t.pos!=r<0&&(e=t)),new od(e,t)}}oo.jsonID("text",od);class ou{constructor(e,t){this.anchor=e,this.head=t}map(e){return new ou(e.map(this.anchor),e.map(this.head))}resolve(e){return od.between(e.resolve(this.anchor),e.resolve(this.head))}}class op extends oo{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(e,t){let{deleted:n,pos:r}=t.mapResult(this.anchor),i=e.resolve(r);return n?oo.near(i):new op(i)}content(){return new iX(iW.from(this.node),0,0)}eq(e){return e instanceof op&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new oh(this.anchor)}static fromJSON(e,t){if("number"!=typeof t.anchor)throw RangeError("Invalid input for NodeSelection.fromJSON");return new op(e.resolve(t.anchor))}static create(e,t){return new op(e.resolve(t))}static isSelectable(e){return!e.isText&&!1!==e.type.spec.selectable}}op.prototype.visible=!1,oo.jsonID("node",op);class oh{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new ou(n,n):new oh(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&op.isSelectable(n)?new op(t):oo.near(t)}}class om extends oo{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=iX.empty){if(t==iX.empty){e.delete(0,e.doc.content.size);let t=oo.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new om(e)}map(e){return new om(e)}eq(e){return e instanceof om}getBookmark(){return of}}oo.jsonID("all",om);let of={map(){return this},resolve:e=>new om(e)};function og(e,t,n,r,i,s=!1){if(t.inlineContent)return od.create(e,n);for(let o=r-(i>0?0:1);i>0?o<t.childCount:o>=0;o+=i){let r=t.child(o);if(r.isAtom){if(!s&&op.isSelectable(r))return op.create(e,n-(i<0?r.nodeSize:0))}else{let t=og(e,r,n+i,i<0?r.childCount:0,i,s);if(t)return t}n+=r.nodeSize*i}return null}function ox(e,t,n){let r,i=e.steps.length-1;if(i<t)return;let s=e.steps[i];(s instanceof sH||s instanceof sU)&&(e.mapping.maps[i].forEach((e,t,n,i)=>{null==r&&(r=i)}),e.setSelection(oo.near(e.doc.resolve(r),n)))}class ob extends or{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(1|this.updated)&-3,this.storedMarks=null,this}get selectionSet(){return(1&this.updated)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=2,this}ensureMarks(e){return iJ.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(2&this.updated)>0}addStep(e,t){super.addStep(e,t),this.updated=-3&this.updated,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||iJ.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(null==t)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(null==n&&(n=t),!e)return this.deleteRange(t,n);let i=this.storedMarks;if(!i){let e=this.doc.resolve(t);i=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,i)),this.selection.empty||this.selection.to!=t+e.length||this.setSelection(oo.near(this.selection.$to)),this}}setMeta(e,t){return this.meta["string"==typeof e?e:e.key]=t,this}getMeta(e){return this.meta["string"==typeof e?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=4,this}get scrolledIntoView(){return(4&this.updated)>0}}function oy(e,t){return t&&e?e.bind(t):e}class ov{constructor(e,t,n){this.name=e,this.init=oy(t.init,n),this.apply=oy(t.apply,n)}}let ow=[new ov("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new ov("selection",{init:(e,t)=>e.selection||oo.atStart(t.doc),apply:e=>e.selection}),new ov("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,r)=>r.selection.$cursor?e.storedMarks:null}),new ov("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t})];class ok{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=ow.slice(),t&&t.forEach(e=>{if(this.pluginsByKey[e.key])throw RangeError("Adding different instances of a keyed plugin ("+e.key+")");this.plugins.push(e),this.pluginsByKey[e.key]=e,e.spec.state&&this.fields.push(new ov(e.key,e.spec.state,e))})}}class oN{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;n<this.config.plugins.length;n++)if(n!=t){let t=this.config.plugins[n];if(t.spec.filterTransaction&&!t.spec.filterTransaction.call(t,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),r=null;for(;;){let i=!1;for(let s=0;s<this.config.plugins.length;s++){let o=this.config.plugins[s];if(o.spec.appendTransaction){let a=r?r[s].n:0,l=r?r[s].state:this,c=a<t.length&&o.spec.appendTransaction.call(o,a?t.slice(a):t,l,n);if(c&&n.filterTransaction(c,s)){if(c.setMeta("appendedTransaction",e),!r){r=[];for(let e=0;e<this.config.plugins.length;e++)r.push(e<s?{state:n,n:t.length}:{state:this,n:0})}t.push(c),n=n.applyInner(c),i=!0}r&&(r[s]={state:n,n:t.length})}}if(!i)return{state:n,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw RangeError("Applying a mismatched transaction");let t=new oN(this.config),n=this.config.fields;for(let r=0;r<n.length;r++){let i=n[r];t[i.name]=i.apply(e,this[i.name],this,t)}return t}get tr(){return new ob(this)}static create(e){let t=new ok(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new oN(t);for(let r=0;r<t.fields.length;r++)n[t.fields[r].name]=t.fields[r].init(e,n);return n}reconfigure(e){let t=new ok(this.schema,e.plugins),n=t.fields,r=new oN(t);for(let t=0;t<n.length;t++){let i=n[t].name;r[i]=this.hasOwnProperty(i)?this[i]:n[t].init(e,r)}return r}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(e=>e.toJSON())),e&&"object"==typeof e)for(let n in e){if("doc"==n||"selection"==n)throw RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[n],i=r.spec.state;i&&i.toJSON&&(t[n]=i.toJSON.call(r,this[r.key]))}return t}static fromJSON(e,t,n){if(!t)throw RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw RangeError("Required config field 'schema' missing");let r=new ok(e.schema,e.plugins),i=new oN(r);return r.fields.forEach(r=>{if("doc"==r.name)i.doc=se.fromJSON(e.schema,t.doc);else if("selection"==r.name)i.selection=oo.fromJSON(i.doc,t.selection);else if("storedMarks"==r.name)t.storedMarks&&(i.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let s in n){let o=n[s],a=o.spec.state;if(o.key==r.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,s)){i[r.name]=a.fromJSON.call(o,e,t[s],i);return}}i[r.name]=r.init(e,i)}}),i}}class oS{constructor(e){this.spec=e,this.props={},e.props&&function e(t,n,r){for(let i in t){let s=t[i];s instanceof Function?s=s.bind(n):"handleDOMEvents"==i&&(s=e(s,n,{})),r[i]=s}return r}(e.props,this,this.props),this.key=e.key?e.key.key:oj("plugin")}getState(e){return e[this.key]}}let oC=Object.create(null);function oj(e){return e in oC?e+"$"+ ++oC[e]:(oC[e]=0,e+"$")}class oE{constructor(e="key"){this.key=oj(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}let oM=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},oA=function(e){let t=e.assignedSlot||e.parentNode;return t&&11==t.nodeType?t.host:t},oT=null,oO=function(e,t,n){let r=oT||(oT=document.createRange());return r.setEnd(e,null==n?e.nodeValue.length:n),r.setStart(e,t||0),r},o_=function(){oT=null},oD=function(e,t,n,r){return n&&(oI(e,t,n,r,-1)||oI(e,t,n,r,1))},oR=/^(img|br|input|textarea|hr)$/i;function oI(e,t,n,r,i){for(var s;;){if(e==n&&t==r)return!0;if(t==(i<0?0:oL(e))){let n=e.parentNode;if(!n||1!=n.nodeType||oP(e)||oR.test(e.nodeName)||"false"==e.contentEditable)return!1;t=oM(e)+(i<0?0:1),e=n}else{if(1!=e.nodeType)return!1;let n=e.childNodes[t+(i<0?-1:0)];if(1==n.nodeType&&"false"==n.contentEditable)if(null==(s=n.pmViewDesc)||!s.ignoreForSelection)return!1;else t+=i;else e=n,t=i<0?oL(e):0}}}function oL(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function oP(e){let t;for(let n=e;n&&!(t=n.pmViewDesc);n=n.parentNode);return t&&t.node&&t.node.isBlock&&(t.dom==e||t.contentDOM==e)}let o$=function(e){return e.focusNode&&oD(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function oz(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}let oB="u">typeof navigator?navigator:null,oF="u">typeof document?document:null,oH=oB&&oB.userAgent||"",oU=/Edge\/(\d+)/.exec(oH),oV=/MSIE \d/.exec(oH),oW=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(oH),oq=!!(oV||oW||oU),oK=oV?document.documentMode:oW?+oW[1]:oU?+oU[1]:0,oG=!oq&&/gecko\/(\d+)/i.test(oH);oG&&(/Firefox\/(\d+)/.exec(oH)||[0,0])[1];let oJ=!oq&&/Chrome\/(\d+)/.exec(oH),oZ=!!oJ,oX=oJ?+oJ[1]:0,oY=!oq&&!!oB&&/Apple Computer/.test(oB.vendor),oQ=oY&&(/Mobile\/\w+/.test(oH)||!!oB&&oB.maxTouchPoints>2),o0=oQ||!!oB&&/Mac/.test(oB.platform),o1=!!oB&&/Win/.test(oB.platform),o2=/Android \d/.test(oH),o5=!!oF&&"webkitFontSmoothing"in oF.documentElement.style,o3=o5?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function o4(e,t){return"number"==typeof e?e:e[t]}function o6(e,t,n){let r=e.someProp("scrollThreshold")||0,i=e.someProp("scrollMargin")||5,s=e.dom.ownerDocument;for(let o=n||e.dom;o;){if(1!=o.nodeType){o=oA(o);continue}let e=o,n=e==s.body,a=n?function(e){let t=e.defaultView&&e.defaultView.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}(s):function(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}(e),l=0,c=0;if(t.top<a.top+o4(r,"top")?c=-(a.top-t.top+o4(i,"top")):t.bottom>a.bottom-o4(r,"bottom")&&(c=t.bottom-t.top>a.bottom-a.top?t.top+o4(i,"top")-a.top:t.bottom-a.bottom+o4(i,"bottom")),t.left<a.left+o4(r,"left")?l=-(a.left-t.left+o4(i,"left")):t.right>a.right-o4(r,"right")&&(l=t.right-a.right+o4(i,"right")),l||c)if(n)s.defaultView.scrollBy(l,c);else{let n=e.scrollLeft,r=e.scrollTop;c&&(e.scrollTop+=c),l&&(e.scrollLeft+=l);let i=e.scrollLeft-n,s=e.scrollTop-r;t={left:t.left-i,top:t.top-s,right:t.right-i,bottom:t.bottom-s}}let d=n?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(d))break;o="absolute"==d?o.offsetParent:oA(o)}}function o9(e){let t=[],n=e.ownerDocument;for(let r=e;r&&(t.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),e!=n);r=oA(r));return t}function o7(e,t){for(let n=0;n<e.length;n++){let{dom:r,top:i,left:s}=e[n];r.scrollTop!=i+t&&(r.scrollTop=i+t),r.scrollLeft!=s&&(r.scrollLeft=s)}}let o8=null;function ae(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function at(e){return e.top<e.bottom||e.left<e.right}function an(e,t){let n=e.getClientRects();if(n.length){let e=n[t<0?0:n.length-1];if(at(e))return e}return Array.prototype.find.call(n,at)||e.getBoundingClientRect()}let ar=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function ai(e,t,n){let{node:r,offset:i,atom:s}=e.docView.domFromPos(t,n<0?-1:1),o=o5||oG;if(3==r.nodeType)if(o&&(ar.test(r.nodeValue)||(n<0?!i:i==r.nodeValue.length))){let e=an(oO(r,i,i),n);if(oG&&i&&/\s/.test(r.nodeValue[i-1])&&i<r.nodeValue.length){let t=an(oO(r,i-1,i-1),-1);if(t.top==e.top){let n=an(oO(r,i,i+1),-1);if(n.top!=e.top)return as(n,n.left<t.left)}}return e}else{let e=i,t=i,s=n<0?1:-1;return n<0&&!i?(t++,s=-1):n>=0&&i==r.nodeValue.length?(e--,s=1):n<0?e--:t++,as(an(oO(r,e,t),s),s<0)}if(!e.state.doc.resolve(t-(s||0)).parent.inlineContent){if(null==s&&i&&(n<0||i==oL(r))){let e=r.childNodes[i-1];if(1==e.nodeType)return ao(e.getBoundingClientRect(),!1)}if(null==s&&i<oL(r)){let e=r.childNodes[i];if(1==e.nodeType)return ao(e.getBoundingClientRect(),!0)}return ao(r.getBoundingClientRect(),n>=0)}if(null==s&&i&&(n<0||i==oL(r))){let e=r.childNodes[i-1],t=3==e.nodeType?oO(e,oL(e)-!o):1!=e.nodeType||"BR"==e.nodeName&&e.nextSibling?null:e;if(t)return as(an(t,1),!1)}if(null==s&&i<oL(r)){let e=r.childNodes[i];for(;e.pmViewDesc&&e.pmViewDesc.ignoreForCoords;)e=e.nextSibling;let t=e?3==e.nodeType?oO(e,0,+!o):1==e.nodeType?e:null:null;if(t)return as(an(t,-1),!0)}return as(an(3==r.nodeType?oO(r):r,-n),n>=0)}function as(e,t){if(0==e.width)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function ao(e,t){if(0==e.height)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function aa(e,t,n){let r=e.state,i=e.root.activeElement;r!=t&&e.updateState(t),i!=e.dom&&e.focus();try{return n()}finally{r!=t&&e.updateState(r),i!=e.dom&&i&&i.focus()}}let al=/[\u0590-\u08ac]/,ac=null,ad=null,au=!1;class ap{constructor(e,t,n,r){this.parent=e,this.children=t,this.dom=n,this.contentDOM=r,this.dirty=0,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let t=0,n=this.posAtStart;;t++){let r=this.children[t];if(r==e)return n;n+=r.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,t,n){let r;if(this.contentDOM&&this.contentDOM.contains(1==e.nodeType?e:e.parentNode))if(n<0){let n,r;if(e==this.contentDOM)n=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.previousSibling}for(;n&&!((r=n.pmViewDesc)&&r.parent==this);)n=n.previousSibling;return n?this.posBeforeChild(r)+r.size:this.posAtStart}else{let n,r;if(e==this.contentDOM)n=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.nextSibling}for(;n&&!((r=n.pmViewDesc)&&r.parent==this);)n=n.nextSibling;return n?this.posBeforeChild(r):this.posAtEnd}if(e==this.dom&&this.contentDOM)r=t>oM(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=2&e.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==t)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!1;break}if(t.previousSibling)break}if(null==r&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!0;break}if(t.nextSibling)break}}return(null==r?n>0:r)?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,r=e;r;r=r.parentNode){let i=this.getDesc(r),s;if(i&&(!t||i.node))if(!n||!(s=i.nodeDOM)||(1==s.nodeType?s.contains(1==e.nodeType?e:e.parentNode):s==e))return i;else n=!1}}getDesc(e){let t=e.pmViewDesc;for(let e=t;e;e=e.parent)if(e==this)return t}posFromDOM(e,t,n){for(let r=e;r;r=r.parentNode){let i=this.getDesc(r);if(i)return i.localPosFromDOM(e,t,n)}return -1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let r=this.children[t],i=n+r.size;if(n==e&&i!=n){for(;!r.border&&r.children.length;)for(let e=0;e<r.children.length;e++){let t=r.children[e];if(t.size){r=t;break}}return r}if(e<i)return r.descAt(e-n-r.border);n=i}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,r=0;for(let t=0;n<this.children.length;n++){let i=this.children[n],s=t+i.size;if(s>e||i instanceof ay){r=e-t;break}t=s}if(r)return this.children[n].domFromPos(r-this.children[n].border,t);for(let e;n&&!(e=this.children[n-1]).size&&e instanceof ah&&e.side>=0;n--);if(t<=0){let e,r=!0;for(;(e=n?this.children[n-1]:null)&&e.dom.parentNode!=this.contentDOM;n--,r=!1);return e&&t&&r&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?oM(e.dom)+1:0}}{let e,r=!0;for(;(e=n<this.children.length?this.children[n]:null)&&e.dom.parentNode!=this.contentDOM;n++,r=!1);return e&&r&&!e.border&&!e.domAtom?e.domFromPos(0,t):{node:this.contentDOM,offset:e?oM(e.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,n=0){if(0==this.children.length)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let r=-1,i=-1;for(let s=n,o=0;;o++){let n=this.children[o],a=s+n.size;if(-1==r&&e<=a){let i=s+n.border;if(e>=i&&t<=a-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,i);e=s;for(let t=o;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){r=oM(n.dom)+1;break}e-=n.size}-1==r&&(r=0)}if(r>-1&&(a>t||o==this.children.length-1)){t=a;for(let e=o+1;e<this.children.length;e++){let n=this.children[e];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(-1)){i=oM(n.dom);break}t+=n.size}-1==i&&(i=this.contentDOM.childNodes.length);break}s=a}return{node:this.contentDOM,from:e,to:t,fromOffset:r,toOffset:i}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return 0==t.size||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:n}=this.domFromPos(e,0);if(1!=t.nodeType||n==t.childNodes.length)throw RangeError("No node after pos "+e);return t.childNodes[n]}setSelection(e,t,n,r=!1){let i=Math.min(e,t),s=Math.max(e,t);for(let o=0,a=0;o<this.children.length;o++){let l=this.children[o],c=a+l.size;if(i>a&&s<c)return l.setSelection(e-a-l.border,t-a-l.border,n,r);a=c}let o=this.domFromPos(e,e?-1:1),a=t==e?o:this.domFromPos(t,t?-1:1),l=n.root.getSelection(),c=n.domSelectionRange(),d=!1;if((oG||oY)&&e==t){let{node:e,offset:t}=o;if(3==e.nodeType){if((d=!!(t&&"\n"==e.nodeValue[t-1]))&&t==e.nodeValue.length)for(let t=e,n;t;t=t.parentNode){if(n=t.nextSibling){"BR"==n.nodeName&&(o=a={node:n.parentNode,offset:oM(n)+1});break}let e=t.pmViewDesc;if(e&&e.node&&e.node.isBlock)break}}else{let n=e.childNodes[t-1];d=n&&("BR"==n.nodeName||"false"==n.contentEditable)}}if(oG&&c.focusNode&&c.focusNode!=a.node&&1==c.focusNode.nodeType){let e=c.focusNode.childNodes[c.focusOffset];e&&"false"==e.contentEditable&&(r=!0)}if(!(r||d&&oY)&&oD(o.node,o.offset,c.anchorNode,c.anchorOffset)&&oD(a.node,a.offset,c.focusNode,c.focusOffset))return;let u=!1;if((l.extend||e==t)&&!(d&&oG)){l.collapse(o.node,o.offset);try{e!=t&&l.extend(a.node,a.offset),u=!0}catch(e){}}if(!u){if(e>t){let e=o;o=a,a=e}let n=document.createRange();n.setEnd(a.node,a.offset),n.setStart(o.node,o.offset),l.removeAllRanges(),l.addRange(n)}}ignoreMutation(e){return!this.contentDOM&&"selection"!=e.type}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,r=0;r<this.children.length;r++){let i=this.children[r],s=n+i.size;if(n==s?e<=s&&t>=n:e<s&&t>n){let r=n+i.border,o=s-i.border;if(e>=r&&t<=o){this.dirty=e==n||t==s?2:1,e==r&&t==o&&(i.contentLost||i.dom.parentNode!=this.contentDOM)?i.dirty=3:i.markDirty(e-r,t-r);return}i.dirty=i.dom!=i.contentDOM||i.dom.parentNode!=this.contentDOM||i.children.length?3:2}n=s}this.dirty=2}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=1==e?2:1;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class ah extends ap{constructor(e,t,n,r){let i,s=t.type.toDOM;if("function"==typeof s&&(s=s(n,()=>i?i.parent?i.parent.posBeforeChild(i):void 0:r)),!t.type.spec.raw){if(1!=s.nodeType){let e=document.createElement("span");e.appendChild(s),s=e}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,i=this}matchesWidget(e){return 0==this.dirty&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return!!t&&t(e)}ignoreMutation(e){return"selection"!=e.type||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class am extends ap{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return"characterData"===e.type&&e.target.nodeValue==e.oldValue}}class af extends ap{constructor(e,t,n,r,i){super(e,[],n,r),this.mark=t,this.spec=i}static create(e,t,n,r){let i=r.nodeViews[t.type.name],s=i&&i(t,r,n);return s&&s.dom||(s=sj.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new af(e,t,s.dom,s.contentDOM||s.dom,s)}parseRule(){return 3&this.dirty||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return 3!=this.dirty&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),0!=this.dirty){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty<this.dirty&&(e.dirty=this.dirty),this.dirty=0}}slice(e,t,n){let r=af.create(this.parent,this.mark,!0,n),i=this.children,s=this.size;t<s&&(i=aT(i,t,s,n)),e>0&&(i=aT(i,0,e,n));for(let e=0;e<i.length;e++)i[e].parent=r;return r.children=i,r}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class ag extends ap{constructor(e,t,n,r,i,s,o,a,l){super(e,[],i,s),this.node=t,this.outerDeco=n,this.innerDeco=r,this.nodeDOM=o}static create(e,t,n,r,i,s){let o=i.nodeViews[t.type.name],a,l=o&&o(t,i,()=>a?a.parent?a.parent.posBeforeChild(a):void 0:s,n,r),c=l&&l.dom,d=l&&l.contentDOM;if(t.isText)if(c){if(3!=c.nodeType)throw RangeError("Text must be rendered as a DOM text node")}else c=document.createTextNode(t.text);else if(!c){let e=sj.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs);({dom:c,contentDOM:d}=e)}d||t.isText||"BR"==c.nodeName||(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let u=c;return(c=aC(c,n,t),l)?a=new av(e,t,n,r,c,d||null,u,l,i,s+1):t.isText?new ab(e,t,n,r,c,u,i):new ag(e,t,n,r,c,d||null,u,i,s+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if("pre"==this.node.type.whitespace&&(e.preserveWhitespace="full"),this.contentDOM)if(this.contentLost){for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>iW.empty)}else e.contentElement=this.contentDOM;else e.getContent=()=>this.node.content;return e}matchesNode(e,t,n){return 0==this.dirty&&e.eq(this.node)&&aj(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return+!this.node.isLeaf}updateChildren(e,t){let n=this.node.inlineContent,r=t,i=e.composing?this.localCompositionInfo(e,t):null,s=i&&i.pos>-1?i:null,o=i&&i.pos<0,a=new aM(this,s&&s.node,e);(function(e,t,n,r){let i=t.locals(e),s=0;if(0==i.length){for(let n=0;n<e.childCount;n++){let o=e.child(n);r(o,i,t.forChild(s,o),n),s+=o.nodeSize}return}let o=0,a=[],l=null;for(let c=0;;){let d,u,p,h;for(;o<i.length&&i[o].to==s;){let e=i[o++];e.widget&&(d?(u||(u=[d])).push(e):d=e)}if(d)if(u){u.sort(aA);for(let e=0;e<u.length;e++)n(u[e],c,!!l)}else n(d,c,!!l);if(l)h=-1,p=l,l=null;else if(c<e.childCount)h=c,p=e.child(c++);else break;for(let e=0;e<a.length;e++)a[e].to<=s&&a.splice(e--,1);for(;o<i.length&&i[o].from<=s&&i[o].to>s;)a.push(i[o++]);let m=s+p.nodeSize;if(p.isText){let e=m;o<i.length&&i[o].from<e&&(e=i[o].from);for(let t=0;t<a.length;t++)a[t].to<e&&(e=a[t].to);e<m&&(l=p.cut(e-s),p=p.cut(0,e-s),m=e,h=-1)}else for(;o<i.length&&i[o].to<m;)o++;let f=p.isInline&&!p.isLeaf?a.filter(e=>!e.inline):a.slice();r(p,f,t.forChild(s,p),h),s=m}})(this.node,this.innerDeco,(t,i,s)=>{t.spec.marks?a.syncToMarks(t.spec.marks,n,e,i):t.type.side>=0&&!s&&a.syncToMarks(i==this.node.childCount?iJ.none:this.node.child(i).marks,n,e,i),a.placeWidget(t,e,r)},(t,s,l,c)=>{let d;a.syncToMarks(t.marks,n,e,c),a.findNodeMatch(t,s,l,c)||o&&e.state.selection.from>r&&e.state.selection.to<r+t.nodeSize&&(d=a.findIndexWithChild(i.node))>-1&&a.updateNodeAt(t,s,l,d,e)||a.updateNextNode(t,s,l,e,c,r)||a.addNode(t,s,l,e,r),r+=t.nodeSize}),a.syncToMarks([],n,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||2==this.dirty)&&(s&&this.protectLocalComposition(e,s),function e(t,n,r){let i=t.firstChild,s=!1;for(let o=0;o<n.length;o++){let a=n[o],l=a.dom;if(l.parentNode==t){for(;l!=i;)i=aE(i),s=!0;i=i.nextSibling}else s=!0,t.insertBefore(l,i);if(a instanceof af){let n=i?i.previousSibling:t.lastChild;e(a.contentDOM,a.children,r),i=n?n.nextSibling:t.firstChild}}for(;i;)i=aE(i),s=!0;s&&r.trackWrites==t&&(r.trackWrites=null)}(this.contentDOM,this.children,e),oQ&&function(e){if("UL"==e.nodeName||"OL"==e.nodeName){let t=e.style.cssText;e.style.cssText=t+"; list-style: square !important",window.getComputedStyle(e).listStyle,e.style.cssText=t}}(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof od)||n<t||r>t+this.node.content.size)return null;let i=e.input.compositionNode;if(!i||!this.dom.contains(i.parentNode))return null;if(!this.node.inlineContent)return{node:i,pos:-1,text:""};{let e=i.nodeValue,s=function(e,t,n,r){for(let i=0,s=0;i<e.childCount&&s<=r;){let o=e.child(i++),a=s;if(s+=o.nodeSize,!o.isText)continue;let l=o.text;for(;i<e.childCount;){let t=e.child(i++);if(s+=t.nodeSize,!t.isText)break;l+=t.text}if(s>=n){if(s>=r&&l.slice(r-t.length-a,r-a)==t)return r-t.length;let e=a<r?l.lastIndexOf(t,r-a-1):-1;if(e>=0&&e+t.length+a>=n)return a+e;if(n==r&&l.length>=r+t.length-a&&l.slice(r-a,r-a+t.length)==t)return r}}return -1}(this.node.content,e,n-t,r-t);return s<0?null:{node:i,pos:s,text:e}}}protectLocalComposition(e,{node:t,pos:n,text:r}){if(this.getDesc(t))return;let i=t;for(;i.parentNode!=this.contentDOM;i=i.parentNode){for(;i.previousSibling;)i.parentNode.removeChild(i.previousSibling);for(;i.nextSibling;)i.parentNode.removeChild(i.nextSibling);i.pmViewDesc&&(i.pmViewDesc=void 0)}let s=new am(this,i,t,r);e.input.compositionNodes.push(s),this.children=aT(this.children,n,n+r.length,e,s)}update(e,t,n,r){return 3!=this.dirty&&!!e.sameMarkup(this.node)&&(this.updateInner(e,t,n,r),!0)}updateInner(e,t,n,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=0}updateOuterDeco(e){if(aj(e,this.outerDeco))return;let t=1!=this.nodeDOM.nodeType,n=this.dom;this.dom=aS(this.dom,this.nodeDOM,aN(this.outerDeco,this.node,t),aN(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function ax(e,t,n,r,i){aC(r,t,e);let s=new ag(void 0,e,t,n,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class ab extends ag{constructor(e,t,n,r,i,s,o){super(e,t,n,r,i,null,s,o,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return 3!=this.dirty&&(0==this.dirty||!!this.inParent())&&!!e.sameMarkup(this.node)&&(this.updateOuterDeco(t),(0!=this.dirty||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=0,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return"characterData"!=e.type&&"selection"!=e.type}slice(e,t,n){let r=this.node.cut(e,t),i=document.createTextNode(r.text);return new ab(this.parent,r,this.outerDeco,this.innerDeco,i,i,n)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(0==e||t==this.nodeDOM.nodeValue.length)&&(this.dirty=3)}get domAtom(){return!1}isText(e){return this.node.text==e}}class ay extends ap{parseRule(){return{ignore:!0}}matchesHack(e){return 0==this.dirty&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return"IMG"==this.dom.nodeName}}class av extends ag{constructor(e,t,n,r,i,s,o,a,l,c){super(e,t,n,r,i,s,o,l,c),this.spec=a}update(e,t,n,r){if(3==this.dirty)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let i=this.spec.update(e,t,n);return i&&this.updateInner(e,t,n,r),i}return(!!this.contentDOM||!!e.isLeaf)&&super.update(e,t,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,r){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return!!this.spec.stopEvent&&this.spec.stopEvent(e)}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}let aw=function(e){e&&(this.nodeName=e)};aw.prototype=Object.create(null);let ak=[new aw];function aN(e,t,n){if(0==e.length)return ak;let r=n?ak[0]:new aw,i=[r];for(let s=0;s<e.length;s++){let o=e[s].type.attrs;if(o)for(let e in o.nodeName&&i.push(r=new aw(o.nodeName)),o){let s=o[e];null!=s&&(n&&1==i.length&&i.push(r=new aw(t.isInline?"span":"div")),"class"==e?r.class=(r.class?r.class+" ":"")+s:"style"==e?r.style=(r.style?r.style+";":"")+s:"nodeName"!=e&&(r[e]=s))}}return i}function aS(e,t,n,r){if(n==ak&&r==ak)return t;let i=t;for(let t=0;t<r.length;t++){let s=r[t],o=n[t];if(t){let t;o&&o.nodeName==s.nodeName&&i!=e&&(t=i.parentNode)&&t.nodeName.toLowerCase()==s.nodeName||((t=document.createElement(s.nodeName)).pmIsDeco=!0,t.appendChild(i),o=ak[0]),i=t}!function(e,t,n){for(let r in t)"class"==r||"style"==r||"nodeName"==r||r in n||e.removeAttribute(r);for(let r in n)"class"!=r&&"style"!=r&&"nodeName"!=r&&n[r]!=t[r]&&e.setAttribute(r,n[r]);if(t.class!=n.class){let r=t.class?t.class.split(" ").filter(Boolean):[],i=n.class?n.class.split(" ").filter(Boolean):[];for(let t=0;t<r.length;t++)-1==i.indexOf(r[t])&&e.classList.remove(r[t]);for(let t=0;t<i.length;t++)-1==r.indexOf(i[t])&&e.classList.add(i[t]);0==e.classList.length&&e.removeAttribute("class")}if(t.style!=n.style){if(t.style){let n=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,r;for(;r=n.exec(t.style);)e.style.removeProperty(r[1])}n.style&&(e.style.cssText+=n.style)}}(i,o||ak[0],s)}return i}function aC(e,t,n){return aS(e,e,ak,aN(t,n,1!=e.nodeType))}function aj(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].type.eq(t[n].type))return!1;return!0}function aE(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}class aM{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=function(e,t){let n=t,r=n.children.length,i=e.childCount,s=new Map,o=[];n:for(;i>0;){let a;for(;;)if(r){let e=n.children[r-1];if(e instanceof af)n=e,r=e.children.length;else{a=e,r--;break}}else if(n==t)break n;else r=n.parent.children.indexOf(n),n=n.parent;let l=a.node;if(l){if(l!=e.child(i-1))break;--i,s.set(a,i),o.push(a)}}return{index:i,matched:s,matches:o.reverse()}}(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let n=e;n<t;n++)this.top.children[n].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,n,r){let i=0,s=this.stack.length>>1,o=Math.min(s,e.length);for(;i<o&&(i==s-1?this.top:this.stack[i+1<<1]).matchesMark(e[i])&&!1!==e[i].type.spec.spanning;)i++;for(;i<s;)this.destroyRest(),this.top.dirty=0,this.index=this.stack.pop(),this.top=this.stack.pop(),s--;for(;s<e.length;){this.stack.push(this.top,this.index+1);let i=-1,o=this.top.children.length;r<this.preMatch.index&&(o=Math.min(this.index+3,o));for(let t=this.index;t<o;t++){let n=this.top.children[t];if(n.matchesMark(e[s])&&!this.isLocked(n.dom)){i=t;break}}if(i>-1)i>this.index&&(this.changed=!0,this.destroyBetween(this.index,i)),this.top=this.top.children[this.index];else{let r=af.create(this.top,e[s],t,n);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,n,r){let i=-1,s;if(r>=this.preMatch.index&&(s=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,n))i=this.top.children.indexOf(s,this.index);else for(let r=this.index,s=Math.min(this.top.children.length,r+5);r<s;r++){let s=this.top.children[r];if(s.matchesNode(e,t,n)&&!this.preMatch.matched.has(s)){i=r;break}}return!(i<0)&&(this.destroyBetween(this.index,i),this.index++,!0)}updateNodeAt(e,t,n,r,i){let s=this.top.children[r];return 3==s.dirty&&s.dom==s.contentDOM&&(s.dirty=2),!!s.update(e,t,n,i)&&(this.destroyBetween(this.index,r),this.index++,!0)}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return -1;if(t==this.top.contentDOM){let t=e.pmViewDesc;if(t){for(let e=this.index;e<this.top.children.length;e++)if(this.top.children[e]==t)return e}return -1}e=t}}updateNextNode(e,t,n,r,i,s){for(let o=this.index;o<this.top.children.length;o++){let a=this.top.children[o];if(a instanceof ag){let l=this.preMatch.matched.get(a);if(null!=l&&l!=i)return!1;let c=a.dom,d,u=this.isLocked(c)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&3!=a.dirty&&aj(t,a.outerDeco));if(!u&&a.update(e,t,n,r))return this.destroyBetween(this.index,o),a.dom!=c&&(this.changed=!0),this.index++,!0;if(!u&&(d=this.recreateWrapper(a,e,t,n,r,s)))return this.destroyBetween(this.index,o),this.top.children[this.index]=d,d.contentDOM&&(d.dirty=2,d.updateChildren(r,s+1),d.dirty=0),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,r,i,s){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!aj(n,e.outerDeco)||!r.eq(e.innerDeco))return null;let o=ag.create(this.top,t,n,r,i,s);if(o.contentDOM)for(let t of(o.children=e.children,e.children=[],o.children))t.parent=o;return e.destroy(),o}addNode(e,t,n,r,i){let s=ag.create(this.top,e,t,n,r,i);s.contentDOM&&s.updateChildren(r,i+1),this.top.children.splice(this.index++,0,s),this.changed=!0}placeWidget(e,t,n){let r=this.index<this.top.children.length?this.top.children[this.index]:null;if(r&&r.matchesWidget(e)&&(e==r.widget||!r.widget.type.toDOM.parentNode))this.index++;else{let r=new ah(this.top,e,t,n);this.top.children.splice(this.index++,0,r),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof af;)e=(t=e).children[t.children.length-1];(!e||!(e instanceof ab)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((oY||oZ)&&e&&"false"==e.dom.contentEditable&&this.addHackNode("IMG",t),this.addHackNode("BR",this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.children[this.index].matchesHack(e))this.index++;else{let n=document.createElement(e);"IMG"==e&&(n.className="ProseMirror-separator",n.alt=""),"BR"==e&&(n.className="ProseMirror-trailingBreak");let r=new ay(this.top,[],n,null);t!=this.top?t.children.push(r):t.children.splice(this.index++,0,r),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||1==e.nodeType&&e.contains(this.lock.parentNode))}}function aA(e,t){return e.type.side-t.type.side}function aT(e,t,n,r,i){let s=[];for(let o=0,a=0;o<e.length;o++){let l=e[o],c=a,d=a+=l.size;c>=n||d<=t?s.push(l):(c<t&&s.push(l.slice(0,t-c,r)),i&&(s.push(i),i=void 0),d>n&&s.push(l.slice(n-c,l.size,r)))}return s}function aO(e,t=null){let n=e.domSelectionRange(),r=e.state.doc;if(!n.focusNode)return null;let i=e.docView.nearestDesc(n.focusNode),s=i&&0==i.size,o=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(o<0)return null;let a=r.resolve(o),l,c;if(o$(n)){for(l=o;i&&!i.node;)i=i.parent;let e=i.node;if(i&&e.isAtom&&op.isSelectable(e)&&i.parent&&!(e.isInline&&function(e,t,n){for(let r=0==t,i=t==oL(e);r||i;){if(e==n)return!0;let t=oM(e);if(!(e=e.parentNode))return!1;r=r&&0==t,i=i&&t==oL(e)}}(n.focusNode,n.focusOffset,i.dom))){let e=i.posBefore;c=new op(o==e?a:r.resolve(e))}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=o,i=o;for(let r=0;r<n.rangeCount;r++){let s=n.getRangeAt(r);t=Math.min(t,e.docView.posFromDOM(s.startContainer,s.startOffset,1)),i=Math.max(i,e.docView.posFromDOM(s.endContainer,s.endOffset,-1))}if(t<0)return null;[l,o]=i==e.state.selection.anchor?[i,t]:[t,i],a=r.resolve(o)}else l=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(l<0)return null}let d=r.resolve(l);if(!c){let n="pointer"==t||e.state.selection.head<a.pos&&!s?1:-1;c=aB(e,d,a,n)}return c}function a_(e){return e.editable?e.hasFocus():aH(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function aD(e,t=!1){let n=e.state.selection;if(a$(e,n),a_(e)){if(!t&&e.input.mouseDown&&e.input.mouseDown.allowDefault&&oZ){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&oD(t.anchorNode,t.anchorOffset,n.anchorNode,n.anchorOffset)){e.input.mouseDown.delayedSelectionSync=!0,e.domObserver.setCurSelection();return}}if(e.domObserver.disconnectSelection(),e.cursorWrapper)!function(e){let t=e.domSelection();if(!t)return;let n=e.cursorWrapper.dom,r="IMG"==n.nodeName;r?t.collapse(n.parentNode,oM(n)+1):t.collapse(n,0),!r&&!e.state.selection.visible&&oq&&oK<=11&&(n.disabled=!0,n.disabled=!1)}(e);else{var r;let i,s,o,a,{anchor:l,head:c}=n,d,u;aR&&!(n instanceof od)&&(n.$from.parent.inlineContent||(d=aI(e,n.from)),n.empty||n.$from.parent.inlineContent||(u=aI(e,n.to))),e.docView.setSelection(l,c,e,t),aR&&(d&&aP(d),u&&aP(u)),n.visible?e.dom.classList.remove("ProseMirror-hideselection"):(e.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&((i=(r=e).dom.ownerDocument).removeEventListener("selectionchange",r.input.hideSelectionGuard),o=(s=r.domSelectionRange()).anchorNode,a=s.anchorOffset,i.addEventListener("selectionchange",r.input.hideSelectionGuard=()=>{(s.anchorNode!=o||s.anchorOffset!=a)&&(i.removeEventListener("selectionchange",r.input.hideSelectionGuard),setTimeout(()=>{(!a_(r)||r.state.selection.visible)&&r.dom.classList.remove("ProseMirror-hideselection")},20))})))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}let aR=oY||oZ&&oX<63;function aI(e,t){let{node:n,offset:r}=e.docView.domFromPos(t,0),i=r<n.childNodes.length?n.childNodes[r]:null,s=r?n.childNodes[r-1]:null;if(oY&&i&&"false"==i.contentEditable)return aL(i);if((!i||"false"==i.contentEditable)&&(!s||"false"==s.contentEditable)){if(i)return aL(i);else if(s)return aL(s)}}function aL(e){return e.contentEditable="true",oY&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function aP(e){e.contentEditable="false",e.wasDraggable&&(e.draggable=!0,e.wasDraggable=null)}function a$(e,t){if(t instanceof op){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(az(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else az(e)}function az(e){e.lastSelectedViewDesc&&(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),e.lastSelectedViewDesc=void 0)}function aB(e,t,n,r){return e.someProp("createSelectionBetween",r=>r(e,t,n))||od.between(t,n,r)}function aF(e){return(!e.editable||!!e.hasFocus())&&aH(e)}function aH(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return e.dom.contains(3==t.anchorNode.nodeType?t.anchorNode.parentNode:t.anchorNode)&&(e.editable||e.dom.contains(3==t.focusNode.nodeType?t.focusNode.parentNode:t.focusNode))}catch(e){return!1}}function aU(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),s=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):null:i;return s&&oo.findFrom(s,t)}function aV(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function aW(e,t,n){let r=e.state.selection;if(r instanceof od){if(n.indexOf("s")>-1){let{$head:n}=r,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!i||i.isText||!i.isLeaf)return!1;let s=e.state.doc.resolve(n.pos+i.nodeSize*(t<0?-1:1));return aV(e,new od(r.$anchor,s))}else if(!r.empty)return!1;else if(e.endOfTextblock(t>0?"forward":"backward")){let n=aU(e.state,t);return!!n&&n instanceof op&&aV(e,n)}else if(!(o0&&n.indexOf("m")>-1)){let n=r.$head,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter,s;if(!i||i.isText)return!1;let o=t<0?n.pos-i.nodeSize:n.pos;return!!(i.isAtom||(s=e.docView.descAt(o))&&!s.contentDOM)&&(op.isSelectable(i)?aV(e,new op(t<0?e.state.doc.resolve(n.pos-i.nodeSize):n)):!!o5&&aV(e,new od(e.state.doc.resolve(t<0?o:o+i.nodeSize))))}}else{if(r instanceof op&&r.node.isInline)return aV(e,new od(t>0?r.$to:r.$from));let n=aU(e.state,t);return!!n&&aV(e,n)}}function aq(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function aK(e,t){let n=e.pmViewDesc;return n&&0==n.size&&(t<0||e.nextSibling||"BR"!=e.nodeName)}function aG(e,t){return t<0?function(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i,s,o=!1;for(oG&&1==n.nodeType&&r<aq(n)&&aK(n.childNodes[r],-1)&&(o=!0);;)if(r>0)if(1!=n.nodeType)break;else{let e=n.childNodes[r-1];if(aK(e,-1))i=n,s=--r;else if(3==e.nodeType)r=(n=e).nodeValue.length;else break}else if(aJ(n))break;else{let t=n.previousSibling;for(;t&&aK(t,-1);)i=n.parentNode,s=oM(t),t=t.previousSibling;if(t)r=aq(n=t);else{if((n=n.parentNode)==e.dom)break;r=0}}o?aZ(e,n,r):i&&aZ(e,i,s)}(e):function(e){let t,n,r=e.domSelectionRange(),i=r.focusNode,s=r.focusOffset;if(!i)return;let o=aq(i);for(;;)if(s<o){if(1!=i.nodeType)break;if(aK(i.childNodes[s],1))t=i,n=++s;else break}else if(aJ(i))break;else{let r=i.nextSibling;for(;r&&aK(r,1);)t=r.parentNode,n=oM(r)+1,r=r.nextSibling;if(r)s=0,o=aq(i=r);else{if((i=i.parentNode)==e.dom)break;s=o=0}}t&&aZ(e,t,n)}(e)}function aJ(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function aZ(e,t,n){if(3!=t.nodeType){let e,r;(r=function(e,t){for(;e&&t==e.childNodes.length&&!oP(e);)t=oM(e)+1,e=e.parentNode;for(;e&&t<e.childNodes.length;){let n=e.childNodes[t];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;e=n,t=0}}(t,n))?(t=r,n=0):(e=function(e,t){for(;e&&!t&&!oP(e);)t=oM(e),e=e.parentNode;for(;e&&t;){let n=e.childNodes[t-1];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;t=(e=n).childNodes.length}}(t,n))&&(t=e,n=e.nodeValue.length)}let r=e.domSelection();if(!r)return;if(o$(r)){let e=document.createRange();e.setEnd(t,n),e.setStart(t,n),r.removeAllRanges(),r.addRange(e)}else r.extend&&r.extend(t,n);e.domObserver.setCurSelection();let{state:i}=e;setTimeout(()=>{e.state==i&&aD(e)},50)}function aX(e,t){let n=e.state.doc.resolve(t);if(!(oZ||o1)&&n.parent.inlineContent){let r=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),i=(n.top+n.bottom)/2;if(i>r.top&&i<r.bottom&&Math.abs(n.left-r.left)>1)return n.left<r.left?"ltr":"rtl"}if(t<n.end()){let n=e.coordsAtPos(t+1),i=(n.top+n.bottom)/2;if(i>r.top&&i<r.bottom&&Math.abs(n.left-r.left)>1)return n.left>r.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(e.dom).direction?"rtl":"ltr"}function aY(e,t,n){let r=e.state.selection;if(r instanceof od&&!r.empty||n.indexOf("s")>-1||o0&&n.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||e.endOfTextblock(t<0?"up":"down")){let n=aU(e.state,t);if(n&&n instanceof op)return aV(e,n)}if(!i.parent.inlineContent){let n=t<0?i:s,o=r instanceof om?oo.near(n,t):oo.findFrom(n,t);return!!o&&aV(e,o)}return!1}function aQ(e,t){if(!(e.state.selection instanceof od))return!0;let{$head:n,$anchor:r,empty:i}=e.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(e.endOfTextblock(t>0?"forward":"backward"))return!0;let s=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(s&&!s.isText){let r=e.state.tr;return t<0?r.delete(n.pos-s.nodeSize,n.pos):r.delete(n.pos,n.pos+s.nodeSize),e.dispatch(r),!0}return!1}function a0(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function a1(e,t){e.someProp("transformCopied",n=>{t=n(t,e)});let n=[],{content:r,openStart:i,openEnd:s}=t;for(;i>1&&s>1&&1==r.childCount&&1==r.firstChild.childCount;){i--,s--;let e=r.firstChild;n.push(e.type.name,e.attrs!=e.type.defaultAttrs?e.attrs:null),r=e.content}let o=e.someProp("clipboardSerializer")||sj.fromSchema(e.state.schema),a=a8(),l=a.createElement("div");l.appendChild(o.serializeFragment(r,{document:a}));let c=l.firstChild,d,u=0;for(;c&&1==c.nodeType&&(d=a9[c.nodeName.toLowerCase()]);){for(let e=d.length-1;e>=0;e--){let t=a.createElement(d[e]);for(;l.firstChild;)t.appendChild(l.firstChild);l.appendChild(t),u++}c=l.firstChild}return c&&1==c.nodeType&&c.setAttribute("data-pm-slice",`${i} ${s}${u?` -${u}`:""} ${JSON.stringify(n)}`),{dom:l,text:e.someProp("clipboardTextSerializer",n=>n(t,e))||t.content.textBetween(0,t.content.size,"\n\n"),slice:t}}function a2(e,t,n,r,i){let s,o,a=i.parent.type.spec.code;if(!n&&!t)return null;let l=!!t&&(r||a||!n);if(l){if(e.someProp("transformPastedText",n=>{t=n(t,a||r,e)}),a)return o=new iX(iW.from(e.state.schema.text(t.replace(/\r\n?/g,"\n"))),0,0),e.someProp("transformPasted",t=>{o=t(o,e,!0)}),o;let n=e.someProp("clipboardTextParser",n=>n(t,i,r,e));if(n)o=n;else{let n=i.marks(),{schema:r}=e.state,o=sj.fromSchema(r);s=document.createElement("div"),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=s.appendChild(document.createElement("p"));e&&t.appendChild(o.serializeNode(r.text(e,n)))})}}else e.someProp("transformPastedHTML",t=>{n=t(n,e)}),s=function(e){var t;let n,r=/^(\s*<meta [^>]*>)*/.exec(e);r&&(e=e.slice(r[0].length));let i=a8().createElement("div"),s=/<([a-z][^>\s]+)/i.exec(e),o;if((o=s&&a9[s[1].toLowerCase()])&&(e=o.map(e=>"<"+e+">").join("")+e+o.map(e=>"</"+e+">").reverse().join("")),i.innerHTML=(t=e,(n=window.trustedTypes)?(le||(le=n.defaultPolicy||n.createPolicy("ProseMirrorClipboard",{createHTML:e=>e})),le.createHTML(t)):t),o)for(let e=0;e<o.length;e++)i=i.querySelector(o[e])||i;return i}(n),o5&&function(e){let t=e.querySelectorAll(oZ?"span:not([class]):not([style])":"span.Apple-converted-space");for(let n=0;n<t.length;n++){let r=t[n];1==r.childNodes.length&&" "==r.textContent&&r.parentNode&&r.parentNode.replaceChild(e.ownerDocument.createTextNode(" "),r)}}(s);let c=s&&s.querySelector("[data-pm-slice]"),d=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(d&&d[3])for(let e=+d[3];e>0;e--){let e=s.firstChild;for(;e&&1!=e.nodeType;)e=e.nextSibling;if(!e)break;s=e}if(o||(o=(e.someProp("clipboardParser")||e.someProp("domParser")||sx.fromSchema(e.state.schema)).parseSlice(s,{preserveWhitespace:!!(l||d),context:i,ruleFromNode:e=>"BR"!=e.nodeName||e.nextSibling||!e.parentNode||a5.test(e.parentNode.nodeName)?null:{ignore:!0}})),d)o=function(e,t){if(!e.size)return e;let n=e.content.firstChild.type.schema,r;try{r=JSON.parse(t)}catch(t){return e}let{content:i,openStart:s,openEnd:o}=e;for(let e=r.length-2;e>=0;e-=2){let t=n.nodes[r[e]];if(!t||t.hasRequiredAttrs())break;i=iW.from(t.create(r[e+1],i)),s++,o++}return new iX(i,s,o)}(a6(o,+d[1],+d[2]),d[4]);else if((o=iX.maxOpen(function(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.index(n)),i,s=[];if(e.forEach(e=>{if(!s)return;let t=r.findWrapping(e.type),n;if(!t)return s=null;if(n=s.length&&i.length&&function e(t,n,r,i,s){if(s<t.length&&s<n.length&&t[s]==n[s]){let o=e(t,n,r,i.lastChild,s+1);if(o)return i.copy(i.content.replaceChild(i.childCount-1,o));if(i.contentMatchAt(i.childCount).matchType(s==t.length-1?r.type:t[s+1]))return i.copy(i.content.append(iW.from(a3(r,t,s+1))))}}(t,i,e,s[s.length-1],0))s[s.length-1]=n;else{s.length&&(s[s.length-1]=function e(t,n){if(0==n)return t;let r=t.content.replaceChild(t.childCount-1,e(t.lastChild,n-1)),i=t.contentMatchAt(t.childCount).fillBefore(iW.empty,!0);return t.copy(r.append(i))}(s[s.length-1],i.length));let n=a3(e,t);s.push(n),r=r.matchType(n.type),i=t}}),s)return iW.from(s)}return e}(o.content,i),!0)).openStart||o.openEnd){let e=0,t=0;for(let t=o.content.firstChild;e<o.openStart&&!t.type.spec.isolating;e++,t=t.firstChild);for(let e=o.content.lastChild;t<o.openEnd&&!e.type.spec.isolating;t++,e=e.lastChild);o=a6(o,e,t)}return e.someProp("transformPasted",t=>{o=t(o,e,l)}),o}let a5=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function a3(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,iW.from(e));return e}function a4(e,t,n,r,i,s){let o=t<0?e.firstChild:e.lastChild,a=o.content;return e.childCount>1&&(s=0),i<r-1&&(a=a4(a,t,n,r,i+1,s)),i>=n&&(a=t<0?o.contentMatchAt(0).fillBefore(a,s<=i).append(a):a.append(o.contentMatchAt(o.childCount).fillBefore(iW.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(a))}function a6(e,t,n){return t<e.openStart&&(e=new iX(a4(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new iX(a4(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}let a9={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]},a7=null;function a8(){return a7||(a7=document.implementation.createHTMLDocument("title"))}let le=null,lt={},ln={},lr={touchstart:!0,touchmove:!0};class li{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function ls(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function lo(e){e.someProp("handleDOMEvents",t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>la(e,t))})}function la(e,t){return e.someProp("handleDOMEvents",n=>{let r=n[t.type];return!!r&&(r(e,t)||t.defaultPrevented)})}function ll(e){return{left:e.clientX,top:e.clientY}}function lc(e,t,n,r,i){if(-1==r)return!1;let s=e.state.doc.resolve(r);for(let r=s.depth+1;r>0;r--)if(e.someProp(t,t=>r>s.depth?t(e,n,s.nodeAfter,s.before(r),i,!0):t(e,n,s.node(r),s.before(r),i,!1)))return!0;return!1}function ld(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let r=e.state.tr.setSelection(t);"pointer"==n&&r.setMeta("pointer",!0),e.dispatch(r)}ln.keydown=(e,t)=>{if((e.input.shiftKey=16==t.keyCode||t.shiftKey,!lh(e,t))&&(e.input.lastKeyCode=t.keyCode,e.input.lastKeyCodeTime=Date.now(),!o2||!oZ||13!=t.keyCode))if(229!=t.keyCode&&e.domObserver.forceFlush(),!oQ||13!=t.keyCode||t.ctrlKey||t.altKey||t.metaKey)e.someProp("handleKeyDown",n=>n(e,t))||function(e,t){let n,r=t.keyCode,i=(n="",t.ctrlKey&&(n+="c"),t.metaKey&&(n+="m"),t.altKey&&(n+="a"),t.shiftKey&&(n+="s"),n);if(8==r||o0&&72==r&&"c"==i)return aQ(e,-1)||aG(e,-1);if(46==r&&!t.shiftKey||o0&&68==r&&"c"==i)return aQ(e,1)||aG(e,1);if(13==r||27==r)return!0;if(37==r||o0&&66==r&&"c"==i){let t=37==r?"ltr"==aX(e,e.state.selection.from)?-1:1:-1;return aW(e,t,i)||aG(e,t)}if(39==r||o0&&70==r&&"c"==i){let t=39==r?"ltr"==aX(e,e.state.selection.from)?1:-1:1;return aW(e,t,i)||aG(e,t)}else if(38==r||o0&&80==r&&"c"==i)return aY(e,-1,i)||aG(e,-1);else if(40==r||o0&&78==r&&"c"==i)return function(e){if(!oY||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(t&&1==t.nodeType&&0==n&&t.firstChild&&"false"==t.firstChild.contentEditable){let n=t.firstChild;a0(e,n,"true"),setTimeout(()=>a0(e,n,"false"),20)}return!1}(e)||aY(e,1,i)||aG(e,1);else if(i==(o0?"m":"c")&&(66==r||73==r||89==r||90==r))return!0;return!1}(e,t)?t.preventDefault():ls(e,"key");else{let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{e.input.lastIOSEnter==t&&(e.someProp("handleKeyDown",t=>t(e,oz(13,"Enter"))),e.input.lastIOSEnter=0)},200)}},ln.keyup=(e,t)=>{16==t.keyCode&&(e.input.shiftKey=!1)},ln.keypress=(e,t)=>{if(lh(e,t)||!t.charCode||t.ctrlKey&&!t.altKey||o0&&t.metaKey)return;if(e.someProp("handleKeyPress",n=>n(e,t)))return void t.preventDefault();let n=e.state.selection;if(!(n instanceof od)||!n.$from.sameParent(n.$to)){let r=String.fromCharCode(t.charCode),i=()=>e.state.tr.insertText(r).scrollIntoView();/[\r\n]/.test(r)||e.someProp("handleTextInput",t=>t(e,n.$from.pos,n.$to.pos,r,i))||e.dispatch(i()),t.preventDefault()}};let lu=o0?"metaKey":"ctrlKey";lt.mousedown=(e,t)=>{var n;let r,i;e.input.shiftKey=t.shiftKey;let s=lx(e),o=Date.now(),a="singleClick";o-e.input.lastClick.time<500&&(r=(n=e.input.lastClick).x-t.clientX)*r+(i=n.y-t.clientY)*i<100&&!t[lu]&&e.input.lastClick.button==t.button&&("singleClick"==e.input.lastClick.type?a="doubleClick":"doubleClick"==e.input.lastClick.type&&(a="tripleClick")),e.input.lastClick={time:o,x:t.clientX,y:t.clientY,type:a,button:t.button};let l=e.posAtCoords(ll(t));l&&("singleClick"==a?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new lp(e,l,t,!!s)):("doubleClick"==a?function(e,t,n,r){return lc(e,"handleDoubleClickOn",t,n,r)||e.someProp("handleDoubleClick",n=>n(e,t,r))}:function(e,t,n,r){return lc(e,"handleTripleClickOn",t,n,r)||e.someProp("handleTripleClick",n=>n(e,t,r))||function(e,t,n){if(0!=n.button)return!1;let r=e.state.doc;if(-1==t)return!!r.inlineContent&&(ld(e,od.create(r,0,r.content.size),"pointer"),!0);let i=r.resolve(t);for(let t=i.depth+1;t>0;t--){let n=t>i.depth?i.nodeAfter:i.node(t),s=i.before(t);if(n.inlineContent)ld(e,od.create(r,s+1,s+1+n.content.size),"pointer");else{if(!op.isSelectable(n))continue;ld(e,op.create(r,s),"pointer")}return!0}}(e,n,r)})(e,l.pos,l.inside,t)?t.preventDefault():ls(e,"pointer"))};class lp{constructor(e,t,n,r){let i,s;if(this.view=e,this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[lu],this.allowDefault=n.shiftKey,t.inside>-1)i=e.state.doc.nodeAt(t.inside),s=t.inside;else{let n=e.state.doc.resolve(t.pos);i=n.parent,s=n.depth?n.before():0}const o=r?null:n.target,a=o?e.docView.nearestDesc(o,!0):null;this.target=a&&1==a.nodeDOM.nodeType?a.nodeDOM:null;let{selection:l}=e.state;0==n.button&&(i.type.spec.draggable&&!1!==i.type.spec.selectable||l instanceof op&&l.from<=s&&l.to>s)&&(this.mightDrag={node:i,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&oG&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),ls(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>aD(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;if(this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(ll(e))),this.updateAllowDefault(e),this.allowDefault||!t)ls(this.view,"pointer");else{var n,r,i,s;(n=this.view,r=t.pos,i=t.inside,s=this.selectNode,lc(n,"handleClickOn",r,i,e)||n.someProp("handleClick",t=>t(n,r,e))||(s?function(e,t){if(-1==t)return!1;let n=e.state.selection,r,i;n instanceof op&&(r=n.node);let s=e.state.doc.resolve(t);for(let e=s.depth+1;e>0;e--){let t=e>s.depth?s.nodeAfter:s.node(e);if(op.isSelectable(t)){i=r&&n.$from.depth>0&&e>=n.$from.depth&&s.before(n.$from.depth+1)==n.$from.pos?s.before(n.$from.depth):s.before(e);break}}return null!=i&&(ld(e,op.create(e.state.doc,i),"pointer"),!0)}(n,i):function(e,t){if(-1==t)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return!!(r&&r.isAtom&&op.isSelectable(r))&&(ld(e,new op(n),"pointer"),!0)}(n,i)))?e.preventDefault():0==e.button&&(this.flushed||oY&&this.mightDrag&&!this.mightDrag.node.isAtom||oZ&&!this.view.state.selection.visible&&2>=Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to)))?(ld(this.view,oo.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):ls(this.view,"pointer")}}move(e){this.updateAllowDefault(e),ls(this.view,"pointer"),0==e.buttons&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}function lh(e,t){return!!e.composing||!!(oY&&500>Math.abs(t.timeStamp-e.input.compositionEndedAt))&&(e.input.compositionEndedAt=-2e8,!0)}lt.touchstart=e=>{e.input.lastTouch=Date.now(),lx(e),ls(e,"pointer")},lt.touchmove=e=>{e.input.lastTouch=Date.now(),ls(e,"pointer")},lt.contextmenu=e=>lx(e);let lm=o2?5e3:-1;function lf(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>lx(e),t))}function lg(e){let t;for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=((t=document.createEvent("Event")).initEvent("event",!0,!0),t.timeStamp));e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function lx(e,t=!1){if(!o2||!(e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),lg(e),t||e.docView&&e.docView.dirty){let n=aO(e),r=e.state.selection;return n&&!n.eq(r)?e.dispatch(e.state.tr.setSelection(n)):(e.markCursor||t)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?e.dispatch(e.state.tr.deleteSelection()):e.updateState(e.state),!0}return!1}}ln.compositionstart=ln.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof od&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>!1===e.type.spec.inclusive)||oZ&&o1&&function(e){let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(!t||1!=t.nodeType||n>=t.childNodes.length)return!1;let r=t.childNodes[n];return 1==r.nodeType&&"false"==r.contentEditable}(e)))e.markCursor=e.state.storedMarks||n.marks(),lx(e,!0),e.markCursor=null;else if(lx(e,!t.selection.empty),oG&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,r=t.focusOffset;n&&1==n.nodeType&&0!=r;){let t=r<0?n.lastChild:n.childNodes[r-1];if(!t)break;if(3==t.nodeType){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}n=t,r=-1}}e.input.composing=!0}lf(e,lm)},ln.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=t.timeStamp,e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.badSafariComposition?e.domObserver.forceFlush():e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,lf(e,20))};let lb=oq&&oK<15||oQ&&o3<604;function ly(e,t,n,r,i){let s=a2(e,t,n,r,e.state.selection.$from);if(e.someProp("handlePaste",t=>t(e,i,s||iX.empty)))return!0;if(!s)return!1;let o=0==s.openStart&&0==s.openEnd&&1==s.content.childCount?s.content.firstChild:null,a=o?e.state.tr.replaceSelectionWith(o,r):e.state.tr.replaceSelection(s);return e.dispatch(a.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function lv(e){let t=e.getData("text/plain")||e.getData("Text");if(t)return t;let n=e.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}lt.copy=ln.cut=(e,t)=>{let n=e.state.selection,r="cut"==t.type;if(n.empty)return;let i=lb?null:t.clipboardData,{dom:s,text:o}=a1(e,n.content());i?(t.preventDefault(),i.clearData(),i.setData("text/html",s.innerHTML),i.setData("text/plain",o)):function(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(t),n.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}(e,s),r&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},ln.paste=(e,t)=>{if(e.composing&&!o2)return;let n=lb?null:t.clipboardData,r=e.input.shiftKey&&45!=e.input.lastKeyCode;n&&ly(e,lv(n),n.getData("text/html"),r,t)?t.preventDefault():function(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,r=e.dom.parentNode.appendChild(document.createElement(n?"textarea":"div"));n||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=e.input.shiftKey&&45!=e.input.lastKeyCode;setTimeout(()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?ly(e,r.value,null,i,t):ly(e,r.textContent,r.innerHTML,i,t)},50)}(e,t)};class lw{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}let lk=o0?"altKey":"ctrlKey";function lN(e,t){let n;return e.someProp("dragCopies",e=>{n=n||e(t)}),null!=n?!n:!t[lk]}for(let e in lt.dragstart=(e,t)=>{let n,r=e.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=e.state.selection,s=i.empty?null:e.posAtCoords(ll(t));if(s&&s.pos>=i.from&&s.pos<=(i instanceof op?i.to-1:i.to));else if(r&&r.mightDrag)n=op.create(e.state.doc,r.mightDrag.pos);else if(t.target&&1==t.target.nodeType){let r=e.docView.nearestDesc(t.target,!0);r&&r.node.type.spec.draggable&&r!=e.docView&&(n=op.create(e.state.doc,r.posBefore))}let o=(n||e.state.selection).content(),{dom:a,text:l,slice:c}=a1(e,o);t.dataTransfer.files.length&&oZ&&!(oX>120)||t.dataTransfer.clearData(),t.dataTransfer.setData(lb?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",lb||t.dataTransfer.setData("text/plain",l),e.dragging=new lw(c,lN(e,t),n)},lt.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},ln.dragover=ln.dragenter=(e,t)=>t.preventDefault(),ln.drop=(e,t)=>{try{!function(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(ll(t));if(!r)return;let i=e.state.doc.resolve(r.pos),s=n&&n.slice;s?e.someProp("transformPasted",t=>{s=t(s,e,!1)}):s=a2(e,lv(t.dataTransfer),lb?null:t.dataTransfer.getData("text/html"),!1,i);let o=!!(n&&lN(e,t));if(e.someProp("handleDrop",n=>n(e,t,s||iX.empty,o)))return t.preventDefault();if(!s)return;t.preventDefault();let a=s?s1(e.state.doc,i.pos,s):i.pos;null==a&&(a=i.pos);let l=e.state.tr;if(o){let{node:e}=n;e?e.replace(l):l.deleteSelection()}let c=l.mapping.map(a),d=0==s.openStart&&0==s.openEnd&&1==s.content.childCount,u=l.doc;if(d?l.replaceRangeWith(c,c,s.content.firstChild):l.replaceRange(c,c,s),l.doc.eq(u))return;let p=l.doc.resolve(c);if(d&&op.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))l.setSelection(new op(p));else{let t=l.mapping.map(a);l.mapping.maps[l.mapping.maps.length-1].forEach((e,n,r,i)=>t=i),l.setSelection(aB(e,p,l.doc.resolve(t)))}e.focus(),e.dispatch(l.setMeta("uiEvent","drop"))}(e,t,e.dragging)}finally{e.dragging=null}},lt.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add("ProseMirror-focused"),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&aD(e)},20))},lt.blur=(e,t)=>{e.focused&&(e.domObserver.stop(),e.dom.classList.remove("ProseMirror-focused"),e.domObserver.start(),t.relatedTarget&&e.dom.contains(t.relatedTarget)&&e.domObserver.currentSelection.clear(),e.focused=!1)},lt.beforeinput=(e,t)=>{if(oZ&&o2&&"deleteContentBackward"==t.inputType){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t||(e.dom.blur(),e.focus(),e.someProp("handleKeyDown",t=>t(e,oz(8,"Backspace")))))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())},50)}},ln)lt[e]=ln[e];function lS(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}class lC{constructor(e,t){this.toDOM=e,this.spec=t||lT,this.side=this.spec.side||0}map(e,t,n,r){let{pos:i,deleted:s}=e.mapResult(t.from+r,this.side<0?-1:1);return s?null:new lM(i-n,i-n,this)}valid(){return!0}eq(e){return this==e||e instanceof lC&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&lS(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class lj{constructor(e,t){this.attrs=e,this.spec=t||lT}map(e,t,n,r){let i=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,s=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return i>=s?null:new lM(i,s,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof lj&&lS(this.attrs,e.attrs)&&lS(this.spec,e.spec)}static is(e){return e.type instanceof lj}destroy(){}}class lE{constructor(e,t){this.attrs=e,this.spec=t||lT}map(e,t,n,r){let i=e.mapResult(t.from+r,1);if(i.deleted)return null;let s=e.mapResult(t.to+r,-1);return s.deleted||s.pos<=i.pos?null:new lM(i.pos-n,s.pos-n,this)}valid(e,t){let{index:n,offset:r}=e.content.findIndex(t.from),i;return r==t.from&&!(i=e.child(n)).isText&&r+i.nodeSize==t.to}eq(e){return this==e||e instanceof lE&&lS(this.attrs,e.attrs)&&lS(this.spec,e.spec)}destroy(){}}class lM{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new lM(e,t,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,n){return this.type.map(e,this,t,n)}static widget(e,t,n){return new lM(e,e,new lC(t,n))}static inline(e,t,n,r){return new lM(e,t,new lj(n,r))}static node(e,t,n,r){return new lM(e,t,new lE(n,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof lj}get widget(){return this.type instanceof lC}}let lA=[],lT={};class lO{constructor(e,t){this.local=e.length?e:lA,this.children=t.length?t:lA}static create(e,t){return t.length?lP(t,e,0,lT):l_}find(e,t,n){let r=[];return this.findInner(null==e?0:e,null==t?1e9:t,r,0,n),r}findInner(e,t,n,r,i){for(let s=0;s<this.local.length;s++){let o=this.local[s];o.from<=t&&o.to>=e&&(!i||i(o.spec))&&n.push(o.copy(o.from+r,o.to+r))}for(let s=0;s<this.children.length;s+=3)if(this.children[s]<t&&this.children[s+1]>e){let o=this.children[s]+1;this.children[s+2].findInner(e-o,t-o,n,r+o,i)}}map(e,t,n){return this==l_||0==e.maps.length?this:this.mapInner(e,t,0,0,n||lT)}mapInner(e,t,n,r,i){let s;for(let o=0;o<this.local.length;o++){let a=this.local[o].map(e,n,r);a&&a.type.valid(t,a)?(s||(s=[])).push(a):i.onRemove&&i.onRemove(this.local[o].spec)}return this.children.length?function(e,t,n,r,i,s,o){let a=e.slice();for(let e=0,t=s;e<n.maps.length;e++){let r=0;n.maps[e].forEach((e,n,i,s)=>{let o=s-i-(n-e);for(let i=0;i<a.length;i+=3){let s=a[i+1];if(s<0||e>s+t-r)continue;let l=a[i]+t-r;n>=l?a[i+1]=e<=l?-2:-1:e>=t&&o&&(a[i]+=o,a[i+1]+=o)}r+=o}),t=n.maps[e].map(t,-1)}let l=!1;for(let t=0;t<a.length;t+=3)if(a[t+1]<0){if(-2==a[t+1]){l=!0,a[t+1]=-1;continue}let c=n.map(e[t]+s),d=c-i;if(d<0||d>=r.content.size){l=!0;continue}let u=n.map(e[t+1]+s,-1)-i,{index:p,offset:h}=r.content.findIndex(d),m=r.maybeChild(p);if(m&&h==d&&h+m.nodeSize==u){let r=a[t+2].mapInner(n,m,c+1,e[t]+s+1,o);r!=l_?(a[t]=d,a[t+1]=u,a[t+2]=r):(a[t+1]=-2,l=!0)}else l=!0}if(l){let l=lP(function(e,t,n,r,i,s,o){for(let a=0;a<e.length;a+=3)-1==e[a+1]&&function e(t,s){for(let e=0;e<t.local.length;e++){let a=t.local[e].map(r,i,s);a?n.push(a):o.onRemove&&o.onRemove(t.local[e].spec)}for(let n=0;n<t.children.length;n+=3)e(t.children[n+2],t.children[n]+s+1)}(e[a+2],t[a]+s+1);return n}(a,e,t,n,i,s,o),r,0,o);t=l.local;for(let e=0;e<a.length;e+=3)a[e+1]<0&&(a.splice(e,3),e-=3);for(let e=0,t=0;e<l.children.length;e+=3){let n=l.children[e];for(;t<a.length&&a[t]<n;)t+=3;a.splice(t,0,l.children[e],l.children[e+1],l.children[e+2])}}return new lO(t.sort(l$),a)}(this.children,s||[],e,t,n,r,i):s?new lO(s.sort(l$),lA):l_}add(e,t){return t.length?this==l_?lO.create(e,t):this.addInner(e,t,0):this}addInner(e,t,n){let r,i=0;e.forEach((e,s)=>{let o=s+n,a;if(a=lI(t,e,o)){for(r||(r=this.children.slice());i<r.length&&r[i]<s;)i+=3;r[i]==s?r[i+2]=r[i+2].addInner(e,a,o+1):r.splice(i,0,s,s+e.nodeSize,lP(a,e,o+1,lT)),i+=3}});let s=lR(i?lL(t):t,-n);for(let t=0;t<s.length;t++)s[t].type.valid(e,s[t])||s.splice(t--,1);return new lO(s.length?this.local.concat(s).sort(l$):this.local,r||this.children)}remove(e){return 0==e.length||this==l_?this:this.removeInner(e,0)}removeInner(e,t){let n=this.children,r=this.local;for(let r=0;r<n.length;r+=3){let i,s=n[r]+t,o=n[r+1]+t;for(let t=0,n;t<e.length;t++)(n=e[t])&&n.from>s&&n.to<o&&(e[t]=null,(i||(i=[])).push(n));if(!i)continue;n==this.children&&(n=this.children.slice());let a=n[r+2].removeInner(i,s+1);a!=l_?n[r+2]=a:(n.splice(r,3),r-=3)}if(r.length){for(let n=0,i;n<e.length;n++)if(i=e[n])for(let e=0;e<r.length;e++)r[e].eq(i,t)&&(r==this.local&&(r=this.local.slice()),r.splice(e--,1))}return n==this.children&&r==this.local?this:r.length||n.length?new lO(r,n):l_}forChild(e,t){let n,r;if(this==l_)return this;if(t.isLeaf)return lO.empty;for(let t=0;t<this.children.length;t+=3)if(this.children[t]>=e){this.children[t]==e&&(n=this.children[t+2]);break}let i=e+1,s=i+t.content.size;for(let e=0;e<this.local.length;e++){let t=this.local[e];if(t.from<s&&t.to>i&&t.type instanceof lj){let e=Math.max(i,t.from)-i,n=Math.min(s,t.to)-i;e<n&&(r||(r=[])).push(t.copy(e,n))}}if(r){let e=new lO(r.sort(l$),lA);return n?new lD([e,n]):e}return n||l_}eq(e){if(this==e)return!0;if(!(e instanceof lO)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let t=0;t<this.local.length;t++)if(!this.local[t].eq(e.local[t]))return!1;for(let t=0;t<this.children.length;t+=3)if(this.children[t]!=e.children[t]||this.children[t+1]!=e.children[t+1]||!this.children[t+2].eq(e.children[t+2]))return!1;return!0}locals(e){return lz(this.localsInner(e))}localsInner(e){if(this==l_)return lA;if(e.inlineContent||!this.local.some(lj.is))return this.local;let t=[];for(let e=0;e<this.local.length;e++)this.local[e].type instanceof lj||t.push(this.local[e]);return t}forEachSet(e){e(this)}}lO.empty=new lO([],[]),lO.removeOverlap=lz;let l_=lO.empty;class lD{constructor(e){this.members=e}map(e,t){let n=this.members.map(n=>n.map(e,t,lT));return lD.from(n)}forChild(e,t){if(t.isLeaf)return lO.empty;let n=[];for(let r=0;r<this.members.length;r++){let i=this.members[r].forChild(e,t);i!=l_&&(i instanceof lD?n=n.concat(i.members):n.push(i))}return lD.from(n)}eq(e){if(!(e instanceof lD)||e.members.length!=this.members.length)return!1;for(let t=0;t<this.members.length;t++)if(!this.members[t].eq(e.members[t]))return!1;return!0}locals(e){let t,n=!0;for(let r=0;r<this.members.length;r++){let i=this.members[r].localsInner(e);if(i.length)if(t){n&&(t=t.slice(),n=!1);for(let e=0;e<i.length;e++)t.push(i[e])}else t=i}return t?lz(n?t:t.sort(l$)):lA}static from(e){switch(e.length){case 0:return l_;case 1:return e[0];default:return new lD(e.every(e=>e instanceof lO)?e:e.reduce((e,t)=>e.concat(t instanceof lO?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function lR(e,t){if(!t||!e.length)return e;let n=[];for(let r=0;r<e.length;r++){let i=e[r];n.push(new lM(i.from+t,i.to+t,i.type))}return n}function lI(e,t,n){if(t.isLeaf)return null;let r=n+t.nodeSize,i=null;for(let t=0,s;t<e.length;t++)(s=e[t])&&s.from>n&&s.to<r&&((i||(i=[])).push(s),e[t]=null);return i}function lL(e){let t=[];for(let n=0;n<e.length;n++)null!=e[n]&&t.push(e[n]);return t}function lP(e,t,n,r){let i=[],s=!1;t.forEach((t,o)=>{let a=lI(e,t,o+n);if(a){s=!0;let e=lP(a,t,n+o+1,r);e!=l_&&i.push(o,o+t.nodeSize,e)}});let o=lR(s?lL(e):e,-n).sort(l$);for(let e=0;e<o.length;e++)o[e].type.valid(t,o[e])||(r.onRemove&&r.onRemove(o[e].spec),o.splice(e--,1));return o.length||i.length?new lO(o,i):l_}function l$(e,t){return e.from-t.from||e.to-t.to}function lz(e){let t=e;for(let n=0;n<t.length-1;n++){let r=t[n];if(r.from!=r.to)for(let i=n+1;i<t.length;i++){let s=t[i];if(s.from==r.from){s.to!=r.to&&(t==e&&(t=e.slice()),t[i]=s.copy(s.from,r.to),lB(t,i+1,s.copy(r.to,s.to)));continue}s.from<r.to&&(t==e&&(t=e.slice()),t[n]=r.copy(r.from,s.from),lB(t,i,r.copy(s.from,r.to)));break}}return t}function lB(e,t,n){for(;t<e.length&&l$(n,e[t])>0;)t++;e.splice(t,0,n)}function lF(e){let t=[];return e.someProp("decorations",n=>{let r=n(e.state);r&&r!=l_&&t.push(r)}),e.cursorWrapper&&t.push(lO.create(e.state.doc,[e.cursorWrapper.deco])),lD.from(t)}let lH={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},lU=oq&&oK<=11;class lV{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class lW{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new lV,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(t=>{for(let e=0;e<t.length;e++)this.queue.push(t[e]);oq&&oK<=11&&t.some(e=>"childList"==e.type&&e.removedNodes.length||"characterData"==e.type&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():oY&&e.composing&&t.some(e=>"childList"==e.type&&"TR"==e.target.nodeName)?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),lU&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,lH)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(aF(this.view)){if(this.suppressingSelectionUpdates)return aD(this.view);if(oq&&oK<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&oD(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let n=e.focusNode;n;n=oA(n))t.add(n);for(let r=e.anchorNode;r;r=oA(r))if(t.has(r)){n=r;break}let r=n&&this.view.docView.nearestDesc(n);if(r&&r.ignoreMutation({type:"selection",target:3==n.nodeType?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){var e;let{view:t}=this;if(!t.docView||this.flushingSoon>-1)return;let n=this.pendingRecords();n.length&&(this.queue=[]);let r=t.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&aF(t)&&!this.ignoreSelectionChange(r),s=-1,o=-1,a=!1,l=[];if(t.editable)for(let e=0;e<n.length;e++){let t=this.registerMutation(n[e],l);t&&(s=s<0?t.from:Math.min(t.from,s),o=o<0?t.to:Math.max(t.to,o),t.typeOver&&(a=!0))}if(l.some(e=>"BR"==e.nodeName)&&(8==t.input.lastKeyCode||46==t.input.lastKeyCode)){for(let e of l)if("BR"==e.nodeName&&e.parentNode){let t=e.nextSibling;for(;t&&1==t.nodeType;){if("false"==t.contentEditable){e.parentNode.removeChild(e);break}t=t.firstChild}}}else if(oG&&l.length){let e=l.filter(e=>"BR"==e.nodeName);if(2==e.length){let[t,n]=e;t.parentNode&&t.parentNode.parentNode==n.parentNode?n.remove():t.remove()}else{let{focusNode:n}=this.currentSelection;for(let r of e){let e=r.parentNode;e&&"LI"==e.nodeName&&(!n||function(e,t){for(let n=t.parentNode;n&&n!=e.dom;n=n.parentNode){let t=e.docView.nearestDesc(n,!0);if(t&&t.node.isBlock)return n}return null}(t,n)!=e)&&r.remove()}}}let c=null;s<0&&i&&t.input.lastFocus>Date.now()-200&&Math.max(t.input.lastTouch,t.input.lastClick.time)<Date.now()-300&&o$(r)&&(c=aO(t))&&c.eq(oo.near(t.state.doc.resolve(0),1))?(t.input.lastFocus=0,aD(t),this.currentSelection.set(r),t.scrollToSelection()):(s>-1||i)&&(s>-1&&(t.docView.markDirty(s,o),e=t,!lq.has(e)&&(lq.set(e,null),-1!==["normal","nowrap","pre-line"].indexOf(getComputedStyle(e.dom).whiteSpace))&&(e.requiresGeckoHackNode=oG,lK||(console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),lK=!0))),t.input.badSafariComposition&&(t.input.badSafariComposition=!1,function(e,t){var n;let{focusNode:r,focusOffset:i}=e.domSelectionRange();for(let s of t)if((null==(n=s.parentNode)?void 0:n.nodeName)=="TR"){let t=s.nextSibling;for(;t&&"TD"!=t.nodeName&&"TH"!=t.nodeName;)t=t.nextSibling;if(t){let n=t;for(;;){let e=n.firstChild;if(!e||1!=e.nodeType||"false"==e.contentEditable||/^(BR|IMG)$/.test(e.nodeName))break;n=e}n.insertBefore(s,n.firstChild),r==s&&e.domSelection().collapse(s,i)}else s.parentNode.removeChild(s)}}(t,l)),this.handleDOMChange(s,o,a,l),t.docView&&t.docView.dirty?t.updateState(t.state):this.currentSelection.eq(r)||aD(t),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if("attributes"==e.type&&(n==this.view.docView||"contenteditable"==e.attributeName||"style"==e.attributeName&&!e.oldValue&&!e.target.getAttribute("style"))||!n||n.ignoreMutation(e))return null;if("childList"==e.type){for(let n=0;n<e.addedNodes.length;n++){let r=e.addedNodes[n];t.push(r),3==r.nodeType&&(this.lastChangedTextNode=r)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let r=e.previousSibling,i=e.nextSibling;if(oq&&oK<=11&&e.addedNodes.length)for(let t=0;t<e.addedNodes.length;t++){let{previousSibling:n,nextSibling:s}=e.addedNodes[t];(!n||0>Array.prototype.indexOf.call(e.addedNodes,n))&&(r=n),(!s||0>Array.prototype.indexOf.call(e.addedNodes,s))&&(i=s)}let s=r&&r.parentNode==e.target?oM(r)+1:0,o=n.localPosFromDOM(e.target,s,-1),a=i&&i.parentNode==e.target?oM(i):e.target.childNodes.length;return{from:o,to:n.localPosFromDOM(e.target,a,1)}}return"attributes"==e.type?{from:n.posAtStart-n.border,to:n.posAtEnd+n.border}:(this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let lq=new WeakMap,lK=!1;function lG(e,t){let n=t.startContainer,r=t.startOffset,i=t.endContainer,s=t.endOffset,o=e.domAtPos(e.state.selection.anchor);return oD(o.node,o.offset,i,s)&&([n,r,i,s]=[i,s,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:s}}function lJ(e){let t=e.pmViewDesc;if(t)return t.parseRule();if("BR"==e.nodeName&&e.parentNode){if(oY&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let e=document.createElement("div");return e.appendChild(document.createElement("li")),{skip:e}}else if(e.parentNode.lastChild==e||oY&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if("IMG"==e.nodeName&&e.getAttribute("mark-placeholder"))return{ignore:!0};return null}let lZ=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function lX(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:aB(e,t.resolve(n.anchor),t.resolve(n.head))}function lY(e,t,n){let r=e.depth,i=t?e.end():e.pos;for(;r>0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,i++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,i++}return i}function lQ(e){if(2!=e.length)return!1;let t=e.charCodeAt(0),n=e.charCodeAt(1);return t>=56320&&t<=57343&&n>=55296&&n<=56319}class l0{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new li,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(l4),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):"function"==typeof e?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=l5(this),l2(this),this.nodeViews=l3(this),this.docView=ax(this.state.doc,l1(this),lF(this),this.dom,this),this.domObserver=new lW(this,(e,t,n,r)=>(function(e,t,n,r,i){let s,o,a,l=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);if(e.input.compositionPendingChanges=0,t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=aO(e,t);if(n&&!e.state.selection.eq(n)){if(oZ&&o2&&13===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime&&e.someProp("handleKeyDown",t=>t(e,oz(13,"Enter"))))return;let r=e.state.tr.setSelection(n);"pointer"==t?r.setMeta("pointer",!0):"key"==t&&r.scrollIntoView(),l&&r.setMeta("composition",l),e.dispatch(r)}return}let c=e.state.doc.resolve(t),d=c.sharedDepth(n);t=c.before(d+1),n=e.state.doc.resolve(n).after(d+1);let u=e.state.selection,p=function(e,t,n){let r,{node:i,fromOffset:s,toOffset:o,from:a,to:l}=e.docView.parseRange(t,n),c=e.domSelectionRange(),d=c.anchorNode;if(d&&e.dom.contains(1==d.nodeType?d:d.parentNode)&&(r=[{node:d,offset:c.anchorOffset}],o$(c)||r.push({node:c.focusNode,offset:c.focusOffset})),oZ&&8===e.input.lastKeyCode)for(let e=o;e>s;e--){let t=i.childNodes[e-1],n=t.pmViewDesc;if("BR"==t.nodeName&&!n){o=e;break}if(!n||n.size)break}let u=e.state.doc,p=e.someProp("domParser")||sx.fromSchema(e.state.schema),h=u.resolve(a),m=null,f=p.parse(i,{topNode:h.parent,topMatch:h.parent.contentMatchAt(h.index()),topOpen:!0,from:s,to:o,preserveWhitespace:"pre"!=h.parent.type.whitespace||"full",findPositions:r,ruleFromNode:lJ,context:h});if(r&&null!=r[0].pos){let e=r[0].pos,t=r[1]&&r[1].pos;null==t&&(t=e),m={anchor:e+a,head:t+a}}return{doc:f,sel:m,from:a,to:l}}(e,t,n),h=e.state.doc,m=h.slice(p.from,p.to);8===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime?(s=e.state.selection.to,o="end"):(s=e.state.selection.from,o="start"),e.input.lastKeyCode=null;let f=function(e,t,n,r,i){let s=e.findDiffStart(t,n);if(null==s)return null;let{a:o,b:a}=e.findDiffEnd(t,n+e.size,n+t.size);if("end"==i){let e=Math.max(0,s-Math.min(o,a));r-=o+e-s}if(o<s&&e.size<t.size){let e=r<=s&&r>=o?s-r:0;(s-=e)&&s<t.size&&lQ(t.textBetween(s-1,s+1))&&(s+=e?1:-1),a=s+(a-o),o=s}else if(a<s){let t=r<=s&&r>=a?s-r:0;(s-=t)&&s<e.size&&lQ(e.textBetween(s-1,s+1))&&(s+=t?1:-1),o=s+(o-a),a=s}return{start:s,endA:o,endB:a}}(m.content,p.doc.content,p.from,s,o);if(f&&e.input.domChangeCount++,(oQ&&e.input.lastIOSEnter>Date.now()-225||o2)&&i.some(e=>1==e.nodeType&&!lZ.test(e.nodeName))&&(!f||f.endA>=f.endB)&&e.someProp("handleKeyDown",t=>t(e,oz(13,"Enter")))){e.input.lastIOSEnter=0;return}if(!f)if(r&&u instanceof od&&!u.empty&&u.$head.sameParent(u.$anchor)&&!e.composing&&!(p.sel&&p.sel.anchor!=p.sel.head))f={start:u.from,endA:u.to,endB:u.to};else{if(p.sel){let t=lX(e,e.state.doc,p.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);l&&n.setMeta("composition",l),e.dispatch(n)}}return}e.state.selection.from<e.state.selection.to&&f.start==f.endB&&e.state.selection instanceof od&&(f.start>e.state.selection.from&&f.start<=e.state.selection.from+2&&e.state.selection.from>=p.from?f.start=e.state.selection.from:f.endA<e.state.selection.to&&f.endA>=e.state.selection.to-2&&e.state.selection.to<=p.to&&(f.endB+=e.state.selection.to-f.endA,f.endA=e.state.selection.to)),oq&&oK<=11&&f.endB==f.start+1&&f.endA==f.start&&f.start>p.from&&" "==p.doc.textBetween(f.start-p.from-1,f.start-p.from+1)&&(f.start--,f.endA--,f.endB--);let g=p.doc.resolveNoCache(f.start-p.from),x=p.doc.resolveNoCache(f.endB-p.from),b=h.resolve(f.start),y=g.sameParent(x)&&g.parent.inlineContent&&b.end()>=f.endA;if((oQ&&e.input.lastIOSEnter>Date.now()-225&&(!y||i.some(e=>"DIV"==e.nodeName||"P"==e.nodeName))||!y&&g.pos<p.doc.content.size&&(!g.sameParent(x)||!g.parent.inlineContent)&&g.pos<x.pos&&!/\S/.test(p.doc.textBetween(g.pos,x.pos,"","")))&&e.someProp("handleKeyDown",t=>t(e,oz(13,"Enter")))){e.input.lastIOSEnter=0;return}if(e.state.selection.anchor>f.start&&function(e,t,n,r,i){if(n-t<=i.pos-r.pos||lY(r,!0,!1)<i.pos)return!1;let s=e.resolve(t);if(!r.parent.isTextblock){let e=s.nodeAfter;return null!=e&&n==t+e.nodeSize}if(s.parentOffset<s.parent.content.size||!s.parent.isTextblock)return!1;let o=e.resolve(lY(s,!0,!0));return!(!o.parent.isTextblock||o.pos>n||lY(o,!0,!1)<n)&&r.parent.content.cut(r.parentOffset).eq(o.parent.content)}(h,f.start,f.endA,g,x)&&e.someProp("handleKeyDown",t=>t(e,oz(8,"Backspace")))){o2&&oZ&&e.domObserver.suppressSelectionUpdates();return}oZ&&f.endB==f.start&&(e.input.lastChromeDelete=Date.now()),o2&&!y&&g.start()!=x.start()&&0==x.parentOffset&&g.depth==x.depth&&p.sel&&p.sel.anchor==p.sel.head&&p.sel.head==f.endA&&(f.endB-=2,x=p.doc.resolveNoCache(f.endB-p.from),setTimeout(()=>{e.someProp("handleKeyDown",function(t){return t(e,oz(13,"Enter"))})},20));let v=f.start,w=f.endA,k=t=>{let n=t||e.state.tr.replace(v,w,p.doc.slice(f.start-p.from,f.endB-p.from));if(p.sel){let t=lX(e,n.doc,p.sel);t&&!(oZ&&e.composing&&t.empty&&(f.start!=f.endB||e.input.lastChromeDelete<Date.now()-100)&&(t.head==v||t.head==n.mapping.map(w)-1)||oq&&t.empty&&t.head==v)&&n.setSelection(t)}return l&&n.setMeta("composition",l),n.scrollIntoView()};if(y)if(g.pos==x.pos){oq&&oK<=11&&0==g.parentOffset&&(e.domObserver.suppressSelectionUpdates(),setTimeout(()=>aD(e),20));let t=k(e.state.tr.delete(v,w)),n=h.resolve(f.start).marksAcross(h.resolve(f.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(f.endA==f.endB&&(a=function(e,t){let n=e.firstChild.marks,r=t.firstChild.marks,i=n,s=r,o,a,l;for(let e=0;e<r.length;e++)i=r[e].removeFromSet(i);for(let e=0;e<n.length;e++)s=n[e].removeFromSet(s);if(1==i.length&&0==s.length)a=i[0],o="add",l=e=>e.mark(a.addToSet(e.marks));else{if(0!=i.length||1!=s.length)return null;a=s[0],o="remove",l=e=>e.mark(a.removeFromSet(e.marks))}let c=[];for(let e=0;e<t.childCount;e++)c.push(l(t.child(e)));if(iW.from(c).eq(e))return{mark:a,type:o}}(g.parent.content.cut(g.parentOffset,x.parentOffset),b.parent.content.cut(b.parentOffset,f.endA-b.start())))){let t=k(e.state.tr);"add"==a.type?t.addMark(v,w,a.mark):t.removeMark(v,w,a.mark),e.dispatch(t)}else if(g.parent.child(g.index()).isText&&g.index()==x.index()-!x.textOffset){let t=g.parent.textBetween(g.parentOffset,x.parentOffset),n=()=>k(e.state.tr.insertText(t,v,w));e.someProp("handleTextInput",r=>r(e,v,w,t,n))||e.dispatch(n())}else e.dispatch(k());else e.dispatch(k())})(this,e,t,n,r)),this.domObserver.start(),function(e){for(let t in lt){let n=lt[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{!function(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||11==n.nodeType||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}(e,t)||la(e,t)||!e.editable&&t.type in ln||n(e,t)},lr[t]?{passive:!0}:void 0)}oY&&e.dom.addEventListener("input",()=>null),lo(e)}(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;for(let t in this._props={},e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&lo(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(l4),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];for(let n in t.state=this.state,e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var n,r,i;let s=this.state,o=!1,a=!1;e.storedMarks&&this.composing&&(lg(this),a=!0),this.state=e;let l=s.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=l3(this);(function(e,t){let n=0,r=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let e in t)r++;return n!=r})(e,this.nodeViews)&&(this.nodeViews=e,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&lo(this),this.editable=l5(this),l2(this);let c=lF(this),d=l1(this),u=s.plugins==e.plugins||s.doc.eq(e.doc)?e.scrollToSelection>s.scrollToSelection?"to selection":"preserve":"reset",p=o||!this.docView.matchesNode(e.doc,d,c);(p||!e.selection.eq(s.selection))&&(a=!0);let h="preserve"==u&&a&&null==this.dom.style.overflowAnchor&&function(e){let t,n,r=e.dom.getBoundingClientRect(),i=Math.max(0,r.top);for(let s=(r.left+r.right)/2,o=i+1;o<Math.min(innerHeight,r.bottom);o+=5){let r=e.root.elementFromPoint(s,o);if(!r||r==e.dom||!e.dom.contains(r))continue;let a=r.getBoundingClientRect();if(a.top>=i-20){t=r,n=a.top;break}}return{refDOM:t,refTop:n,stack:o9(e.dom)}}(this);if(a){let t,n,a;this.domObserver.stop();let l=p&&(oq||oZ)&&!this.composing&&!s.selection.empty&&!e.selection.empty&&(r=s.selection,i=e.selection,a=Math.min(r.$anchor.sharedDepth(r.head),i.$anchor.sharedDepth(i.head)),r.$anchor.start(a)!=i.$anchor.start(a));if(p){let t=oZ?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=function(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=function(e,t){for(;;){if(3==e.nodeType&&t)return e;if(1==e.nodeType&&t>0){if("false"==e.contentEditable)return null;t=oL(e=e.childNodes[t-1])}else{if(!e.parentNode||oP(e))return null;t=oM(e),e=e.parentNode}}}(t.focusNode,t.focusOffset),r=function(e,t){for(;;){if(3==e.nodeType&&t<e.nodeValue.length)return e;if(1==e.nodeType&&t<e.childNodes.length){if("false"==e.contentEditable)return null;e=e.childNodes[t],t=0}else{if(!e.parentNode||oP(e))return null;t=oM(e)+1,e=e.parentNode}}}(t.focusNode,t.focusOffset);if(n&&r&&n!=r){let t=r.pmViewDesc,i=e.domObserver.lastChangedTextNode;if(n==i||r==i)return i;if(!t||!t.isText(r.nodeValue))return r;if(e.input.compositionNode==r){let e=n.pmViewDesc;if(!(!e||!e.isText(n.nodeValue)))return r}}return n||r}(this)),(o||!this.docView.update(e.doc,d,c,this))&&(this.docView.updateOuterDeco(d),this.docView.destroy(),this.docView=ax(e.doc,d,c,this.dom,this)),!t||this.trackWrites&&this.dom.contains(this.trackWrites)||(l=!0)}l||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&(t=this.docView.domFromPos(this.state.selection.anchor,0),n=this.domSelectionRange(),oD(t.node,t.offset,n.anchorNode,n.anchorOffset)))?aD(this,l):(a$(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(s),(null==(n=this.dragging)?void 0:n.node)&&!s.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,s),"reset"==u?this.dom.scrollTop=0:"to selection"==u?this.scrollToSelection():h&&function({refDOM:e,refTop:t,stack:n}){let r=e?e.getBoundingClientRect().top:0;o7(n,0==r?0:r-t)}(h)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(e&&this.dom.contains(1==e.nodeType?e:e.parentNode))if(this.someProp("handleScrollToSelection",e=>e(this)));else if(this.state.selection instanceof op){let t=this.docView.domAfterPos(this.state.selection.from);1==t.nodeType&&o6(this,t.getBoundingClientRect(),e)}else o6(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(e&&e.plugins==this.state.plugins&&this.directPlugins==this.prevDirectPlugins)for(let t=0;t<this.pluginViews.length;t++){let n=this.pluginViews[t];n.update&&n.update(this,e)}else{this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let e=0;e<this.directPlugins.length;e++){let t=this.directPlugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}for(let e=0;e<this.state.plugins.length;e++){let t=this.state.plugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}}}updateDraggedNode(e,t){let n=e.node,r=-1;if(n.from<this.state.doc.content.size&&this.state.doc.nodeAt(n.from)==n.node)r=n.from;else{let e=n.from+(this.state.doc.content.size-t.doc.content.size);(e>0&&e<this.state.doc.content.size&&this.state.doc.nodeAt(e))==n.node&&(r=e)}this.dragging=new lw(e.slice,e.move,r<0?void 0:op.create(this.state.doc,r))}someProp(e,t){let n=this._props&&this._props[e],r;if(null!=n&&(r=t?t(n):n))return r;for(let n=0;n<this.directPlugins.length;n++){let i=this.directPlugins[n].props[e];if(null!=i&&(r=t?t(i):i))return r}let i=this.state.plugins;if(i)for(let n=0;n<i.length;n++){let s=i[n].props[e];if(null!=s&&(r=t?t(s):s))return r}}hasFocus(){if(oq){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if("false"==e.contentEditable)return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&function(e){if(e.setActive)return e.setActive();if(o8)return e.focus(o8);let t=o9(e);e.focus(null==o8?{get preventScroll(){return o8={preventScroll:!0},!0}}:void 0),o8||(o8=!1,o7(t,0))}(this.dom),aD(this),this.domObserver.start()}get root(){let e=this._root;if(null==e){for(let e=this.dom.parentNode;e;e=e.parentNode)if(9==e.nodeType||11==e.nodeType&&e.host)return e.getSelection||(Object.getPrototypeOf(e).getSelection=()=>e.ownerDocument.getSelection()),this._root=e}return e||document}updateRoot(){this._root=null}posAtCoords(e){return function(e,t){var n;let r,i,s=e.dom.ownerDocument,o,a=0,l=function(e,t,n){if(e.caretPositionFromPoint)try{let r=e.caretPositionFromPoint(t,n);if(r)return{node:r.offsetNode,offset:Math.min(oL(r.offsetNode),r.offset)}}catch(e){}if(e.caretRangeFromPoint){let r=e.caretRangeFromPoint(t,n);if(r)return{node:r.startContainer,offset:Math.min(oL(r.startContainer),r.startOffset)}}}(s,t.left,t.top);l&&({node:o,offset:a}=l);let c=(e.root.elementFromPoint?e.root:s).elementFromPoint(t.left,t.top);if(!c||!e.dom.contains(1!=c.nodeType?c.parentNode:c)){let n=e.dom.getBoundingClientRect();if(!ae(t,n)||!(c=function e(t,n,r){let i=t.childNodes.length;if(i&&r.top<r.bottom)for(let s=Math.max(0,Math.min(i-1,Math.floor(i*(n.top-r.top)/(r.bottom-r.top))-2)),o=s;;){let r=t.childNodes[o];if(1==r.nodeType){let t=r.getClientRects();for(let i=0;i<t.length;i++){let s=t[i];if(ae(n,s))return e(r,n,s)}}if((o=(o+1)%i)==s)break}return t}(e.dom,t,n)))return null}if(oY)for(let e=c;o&&e;e=oA(e))e.draggable&&(o=void 0);if(c=(r=(n=c).parentNode)&&/^li$/i.test(r.nodeName)&&t.left<n.getBoundingClientRect().left?r:n,o){let n;if(oG&&1==o.nodeType&&(a=Math.min(a,o.childNodes.length))<o.childNodes.length){let e=o.childNodes[a],n;"IMG"==e.nodeName&&(n=e.getBoundingClientRect()).right<=t.left&&n.bottom>t.top&&a++}o5&&a&&1==o.nodeType&&1==(n=o.childNodes[a-1]).nodeType&&"false"==n.contentEditable&&n.getBoundingClientRect().top>=t.top&&a--,o==e.dom&&a==o.childNodes.length-1&&1==o.lastChild.nodeType&&t.top>o.lastChild.getBoundingClientRect().bottom?i=e.state.doc.content.size:(0==a||1!=o.nodeType||"BR"!=o.childNodes[a-1].nodeName)&&(i=function(e,t,n,r){let i=-1;for(let n=t,s=!1;n!=e.dom;){let t=e.docView.nearestDesc(n,!0),o;if(!t)return null;if(1==t.dom.nodeType&&(t.node.isBlock&&t.parent||!t.contentDOM)&&((o=t.dom.getBoundingClientRect()).width||o.height)&&(t.node.isBlock&&t.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(t.dom.nodeName)&&(!s&&o.left>r.left||o.top>r.top?i=t.posBefore:(!s&&o.right<r.left||o.bottom<r.top)&&(i=t.posAfter),s=!0),!t.contentDOM&&i<0&&!t.node.isText))return(t.node.isBlock?r.top<(o.top+o.bottom)/2:r.left<(o.left+o.right)/2)?t.posBefore:t.posAfter;n=t.dom.parentNode}return i>-1?i:e.docView.posFromDOM(t,n,-1)}(e,o,a,t))}null==i&&(i=function(e,t,n){let{node:r,offset:i}=function e(t,n){let r,i,s,o=2e8,a,l=0,c=n.top,d=n.top;for(let e=t.firstChild,u=0;e;e=e.nextSibling,u++){let t;if(1==e.nodeType)t=e.getClientRects();else{if(3!=e.nodeType)continue;t=oO(e).getClientRects()}for(let p=0;p<t.length;p++){let h=t[p];if(h.top<=c&&h.bottom>=d){c=Math.max(h.bottom,c),d=Math.min(h.top,d);let t=h.left>n.left?h.left-n.left:h.right<n.left?n.left-h.right:0;if(t<o){s=e,o=t,a=t&&3==s.nodeType?{left:h.right<n.left?h.right:h.left,top:n.top}:n,1==e.nodeType&&t&&(l=u+ +(n.left>=(h.left+h.right)/2));continue}}else h.top>n.top&&!r&&h.left<=n.left&&h.right>=n.left&&(r=e,i={left:Math.max(h.left,Math.min(h.right,n.left)),top:h.top});!s&&(n.left>=h.right&&n.top>=h.top||n.left>=h.left&&n.top>=h.bottom)&&(l=u+1)}}return(!s&&r&&(s=r,a=i,o=0),s&&3==s.nodeType)?function(e,t){let n=e.nodeValue.length,r=document.createRange(),i;for(let s=0;s<n;s++){r.setEnd(e,s+1),r.setStart(e,s);let n=an(r,1);if(n.top!=n.bottom&&ae(t,n)){i={node:e,offset:s+ +(t.left>=(n.left+n.right)/2)};break}}return r.detach(),i||{node:e,offset:0}}(s,a):!s||o&&1==s.nodeType?{node:t,offset:l}:e(s,a)}(t,n),s=-1;if(1==r.nodeType&&!r.firstChild){let e=r.getBoundingClientRect();s=e.left!=e.right&&n.left>(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(r,i,s)}(e,c,t));let d=e.docView.nearestDesc(c,!0);return{pos:i,inside:d?d.posAtStart-d.border:-1}}(this,e)}coordsAtPos(e,t=1){return ai(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let r=this.docView.posFromDOM(e,t,n);if(null==r)throw RangeError("DOM position not inside the editor");return r}endOfTextblock(e,t){return function(e,t,n){let r,i;return ac==t&&ad==n?au:(ac=t,ad=n,au="up"==n||"down"==n?(r=t.selection,i="up"==n?r.$from:r.$to,aa(e,t,()=>{let{node:t}=e.docView.domFromPos(i.pos,"up"==n?-1:1);for(;;){let n=e.docView.nearestDesc(t,!0);if(!n)break;if(n.node.isBlock){t=n.contentDOM||n.dom;break}t=n.dom.parentNode}let r=ai(e,i.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(1==e.nodeType)t=e.getClientRects();else{if(3!=e.nodeType)continue;t=oO(e,0,e.nodeValue.length).getClientRects()}for(let e=0;e<t.length;e++){let i=t[e];if(i.bottom>i.top+1&&("up"==n?r.top-i.top>(i.bottom-r.top)*2:i.bottom-r.bottom>(r.bottom-i.top)*2))return!1}}return!0})):function(e,t,n){let{$head:r}=t.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=i==r.parent.content.size,o=e.domSelection();return o?al.test(r.parent.textContent)&&o.modify?aa(e,t,()=>{let{focusNode:t,focusOffset:i,anchorNode:s,anchorOffset:a}=e.domSelectionRange(),l=o.caretBidiLevel;o.modify("move",n,"character");let c=r.depth?e.docView.domAfterPos(r.before()):e.dom,{focusNode:d,focusOffset:u}=e.domSelectionRange(),p=d&&!c.contains(1==d.nodeType?d:d.parentNode)||t==d&&i==u;try{o.collapse(s,a),t&&(t!=s||i!=a)&&o.extend&&o.extend(t,i)}catch(e){}return null!=l&&(o.caretBidiLevel=l),p}):"left"==n||"backward"==n?!i:s:r.pos==r.start()||r.pos==r.end()}(e,t,n))}(this,t||this.state,e)}pasteHTML(e,t){return ly(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return ly(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return a1(this,e)}destroy(){if(this.docView){for(let e in this.domObserver.stop(),this.input.eventHandlers)this.dom.removeEventListener(e,this.input.eventHandlers[e]);clearTimeout(this.input.composingTimeout),clearTimeout(this.input.lastIOSEnterFallbackTimeout),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],lF(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,o_()}}get isDestroyed(){return null==this.docView}dispatchEvent(e){!la(this,e)&<[e.type]&&(this.editable||!(e.type in ln))&<[e.type](this,e)}domSelectionRange(){let e=this.domSelection();return e?oY&&11===this.root.nodeType&&function(e){let t=e.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}(this.dom.ownerDocument)==this.dom&&function(e,t){let n;if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return lG(e,n)}function r(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.dom.addEventListener("beforeinput",r,!0),document.execCommand("indent"),e.dom.removeEventListener("beforeinput",r,!0),n?lG(e,n):null}(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function l1(e){let t=Object.create(null);return t.class="ProseMirror",t.contenteditable=String(e.editable),e.someProp("attributes",n=>{if("function"==typeof n&&(n=n(e.state)),n)for(let e in n)"class"==e?t.class+=" "+n[e]:"style"==e?t.style=(t.style?t.style+";":"")+n[e]:t[e]||"contenteditable"==e||"nodeName"==e||(t[e]=String(n[e]))}),t.translate||(t.translate="no"),[lM.node(0,e.state.doc.content.size,t)]}function l2(e){if(e.markCursor){let t=document.createElement("img");t.className="ProseMirror-separator",t.setAttribute("mark-placeholder","true"),t.setAttribute("alt",""),e.cursorWrapper={dom:t,deco:lM.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function l5(e){return!e.someProp("editable",t=>!1===t(e.state))}function l3(e){let t=Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp("nodeViews",n),e.someProp("markViews",n),t}function l4(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw RangeError("Plugins passed directly to the view must not have a state component")}l0.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};for(var l6={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},l9={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},l7="u">typeof navigator&&/Mac/.test(navigator.platform),l8="u">typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),ce=0;ce<10;ce++)l6[48+ce]=l6[96+ce]=String(ce);for(var ce=1;ce<=24;ce++)l6[ce+111]="F"+ce;for(var ce=65;ce<=90;ce++)l6[ce]=String.fromCharCode(ce+32),l9[ce]=String.fromCharCode(ce);for(var ct in l6)l9.hasOwnProperty(ct)||(l9[ct]=l6[ct]);let cn="u">typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),cr="u">typeof navigator&&/Win/.test(navigator.platform);function ci(e,t,n=!0){return t.altKey&&(e="Alt-"+e),t.ctrlKey&&(e="Ctrl-"+e),t.metaKey&&(e="Meta-"+e),n&&t.shiftKey&&(e="Shift-"+e),e}function cs(e){let t=function(e){let t=Object.create(null);for(let n in e)t[function(e){let t,n,r,i,s=e.split(/-(?!$)/),o=s[s.length-1];"Space"==o&&(o=" ");for(let e=0;e<s.length-1;e++){let o=s[e];if(/^(cmd|meta|m)$/i.test(o))i=!0;else if(/^a(lt)?$/i.test(o))t=!0;else if(/^(c|ctrl|control)$/i.test(o))n=!0;else if(/^s(hift)?$/i.test(o))r=!0;else if(/^mod$/i.test(o))cn?i=!0:n=!0;else throw Error("Unrecognized modifier name: "+o)}return t&&(o="Alt-"+o),n&&(o="Ctrl-"+o),i&&(o="Meta-"+o),r&&(o="Shift-"+o),o}(n)]=e[n];return t}(e);return function(e,n){var r;let i=("Esc"==(r=!(l7&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||l8&&n.shiftKey&&n.key&&1==n.key.length||"Unidentified"==n.key)&&n.key||(n.shiftKey?l9:l6)[n.keyCode]||n.key||"Unidentified")&&(r="Escape"),"Del"==r&&(r="Delete"),"Left"==r&&(r="ArrowLeft"),"Up"==r&&(r="ArrowUp"),"Right"==r&&(r="ArrowRight"),"Down"==r&&(r="ArrowDown"),r),s,o=t[ci(i,n)];if(o&&o(e.state,e.dispatch,e))return!0;if(1==i.length&&" "!=i){if(n.shiftKey){let r=t[ci(i,n,!1)];if(r&&r(e.state,e.dispatch,e))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(cr&&n.ctrlKey&&n.altKey)&&(s=l6[n.keyCode])&&s!=i){let r=t[ci(s,n)];if(r&&r(e.state,e.dispatch,e))return!0}}return!1}}if("u">typeof WeakMap){let e=new WeakMap;t=t=>e.get(t),n=(t,n)=>(e.set(t,n),n)}else{let e=[],r=0;t=t=>{for(let n=0;n<e.length;n+=2)if(e[n]==t)return e[n+1]},n=(t,n)=>(10==r&&(r=0),e[r++]=t,e[r++]=n)}var co=class{constructor(e,t,n,r){this.width=e,this.height=t,this.map=n,this.problems=r}findCell(e){for(let t=0;t<this.map.length;t++){let n=this.map[t];if(n!=e)continue;let r=t%this.width,i=t/this.width|0,s=r+1,o=i+1;for(let e=1;s<this.width&&this.map[t+e]==n;e++)s++;for(let e=1;o<this.height&&this.map[t+this.width*e]==n;e++)o++;return{left:r,top:i,right:s,bottom:o}}throw RangeError(`No cell with offset ${e} found`)}colCount(e){for(let t=0;t<this.map.length;t++)if(this.map[t]==e)return t%this.width;throw RangeError(`No cell with offset ${e} found`)}nextCell(e,t,n){let{left:r,right:i,top:s,bottom:o}=this.findCell(e);return"horiz"==t?(n<0?0==r:i==this.width)?null:this.map[s*this.width+(n<0?r-1:i)]:(n<0?0==s:o==this.height)?null:this.map[r+this.width*(n<0?s-1:o)]}rectBetween(e,t){let{left:n,right:r,top:i,bottom:s}=this.findCell(e),{left:o,right:a,top:l,bottom:c}=this.findCell(t);return{left:Math.min(n,o),top:Math.min(i,l),right:Math.max(r,a),bottom:Math.max(s,c)}}cellsInRect(e){let t=[],n={};for(let r=e.top;r<e.bottom;r++)for(let i=e.left;i<e.right;i++){let s=r*this.width+i,o=this.map[s];!n[o]&&(n[o]=!0,i==e.left&&i&&this.map[s-1]==o||r==e.top&&r&&this.map[s-this.width]==o||t.push(o))}return t}positionAt(e,t,n){for(let r=0,i=0;;r++){let s=i+n.child(r).nodeSize;if(r==e){let n=t+e*this.width,r=(e+1)*this.width;for(;n<r&&this.map[n]<i;)n++;return n==r?s-1:this.map[n]}i=s}}static get(e){return t(e)||n(e,function(e){if("table"!=e.type.spec.tableRole)throw RangeError("Not a table node: "+e.type.name);let t=function(e){let t=-1,n=!1;for(let r=0;r<e.childCount;r++){let i=e.child(r),s=0;if(n)for(let t=0;t<r;t++){let n=e.child(t);for(let e=0;e<n.childCount;e++){let i=n.child(e);t+i.attrs.rowspan>r&&(s+=i.attrs.colspan)}}for(let e=0;e<i.childCount;e++){let t=i.child(e);s+=t.attrs.colspan,t.attrs.rowspan>1&&(n=!0)}-1==t?t=s:t!=s&&(t=Math.max(t,s))}return t}(e),n=e.childCount,r=[],i=0,s=null,o=[];for(let e=0,i=t*n;e<i;e++)r[e]=0;for(let a=0,l=0;a<n;a++){let c=e.child(a);l++;for(let e=0;;e++){for(;i<r.length&&0!=r[i];)i++;if(e==c.childCount)break;let d=c.child(e),{colspan:u,rowspan:p,colwidth:h}=d.attrs;for(let e=0;e<p;e++){if(e+a>=n){(s||(s=[])).push({type:"overlong_rowspan",pos:l,n:p-e});break}let c=i+e*t;for(let e=0;e<u;e++){0==r[c+e]?r[c+e]=l:(s||(s=[])).push({type:"collision",row:a,pos:l,n:u-e});let n=h&&h[e];if(n){let r=(c+e)%t*2,i=o[r];null==i||i!=n&&1==o[r+1]?(o[r]=n,o[r+1]=1):i==n&&o[r+1]++}}}i+=u,l+=d.nodeSize}let d=(a+1)*t,u=0;for(;i<d;)0==r[i++]&&u++;u&&(s||(s=[])).push({type:"missing",row:a,n:u}),l++}(0===t||0===n)&&(s||(s=[])).push({type:"zero_sized"});let a=new co(t,n,r,s),l=!1;for(let e=0;!l&&e<o.length;e+=2)null!=o[e]&&o[e+1]<n&&(l=!0);return l&&function(e,t,n){e.problems||(e.problems=[]);let r={};for(let i=0;i<e.map.length;i++){let s=e.map[i];if(r[s])continue;r[s]=!0;let o=n.nodeAt(s);if(!o)throw RangeError(`No cell with offset ${s} found`);let a=null,l=o.attrs;for(let n=0;n<l.colspan;n++){let r=t[(i+n)%e.width*2];null==r||l.colwidth&&l.colwidth[n]==r||((a||(a=function(e){if(e.colwidth)return e.colwidth.slice();let t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}(l)))[n]=r)}a&&e.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:a})}}(a,o,e),a}(e))}};function ca(e){let t=e.cached.tableNodeTypes;if(!t)for(let n in t=e.cached.tableNodeTypes={},e.nodes){let r=e.nodes[n],i=r.spec.tableRole;i&&(t[i]=r)}return t}let cl=new oE("selectingCells");function cc(e){for(let t=e.depth-1;t>0;t--)if("row"==e.node(t).type.spec.tableRole)return e.node(0).resolve(e.before(t+1));return null}function cd(e){let t=e.selection.$head;for(let e=t.depth;e>0;e--)if("row"==t.node(e).type.spec.tableRole)return!0;return!1}function cu(e){let t=e.selection;if("$anchorCell"in t&&t.$anchorCell)return t.$anchorCell.pos>t.$headCell.pos?t.$anchorCell:t.$headCell;if("node"in t&&t.node&&"cell"==t.node.type.spec.tableRole)return t.$anchor;let n=cc(t.$head)||function(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){let r=t.type.spec.tableRole;if("cell"==r||"header_cell"==r)return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){let r=t.type.spec.tableRole;if("cell"==r||"header_cell"==r)return e.doc.resolve(n-t.nodeSize)}}(t.$head);if(n)return n;throw RangeError(`No cell found around position ${t.head}`)}function cp(e){return"row"==e.parent.type.spec.tableRole&&!!e.nodeAfter}function ch(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function cm(e,t,n){let r=e.node(-1),i=co.get(r),s=e.start(-1),o=i.nextCell(e.pos-s,t,n);return null==o?null:e.node(0).resolve(s+o)}function cf(e,t,n=1){let r={...e,colspan:e.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(t,n),r.colwidth.some(e=>e>0)||(r.colwidth=null)),r}function cg(e,t,n=1){let r={...e,colspan:e.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let e=0;e<n;e++)r.colwidth.splice(t,0,0)}return r}var cx=class e extends oo{constructor(e,t=e){const n=e.node(-1),r=co.get(n),i=e.start(-1),s=r.rectBetween(e.pos-i,t.pos-i),o=e.node(0),a=r.cellsInRect(s).filter(e=>e!=t.pos-i);a.unshift(t.pos-i);const l=a.map(e=>{let t=n.nodeAt(e);if(!t)throw RangeError(`No cell with offset ${e} found`);let r=i+e+1;return new oa(o.resolve(r),o.resolve(r+t.content.size))});super(l[0].$from,l[0].$to,l),this.$anchorCell=e,this.$headCell=t}map(t,n){let r=t.resolve(n.map(this.$anchorCell.pos)),i=t.resolve(n.map(this.$headCell.pos));if(cp(r)&&cp(i)&&ch(r,i)){let t=this.$anchorCell.node(-1)!=r.node(-1);return t&&this.isRowSelection()?e.rowSelection(r,i):t&&this.isColSelection()?e.colSelection(r,i):new e(r,i)}return od.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=co.get(e),n=this.$anchorCell.start(-1),r=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),i={},s=[];for(let n=r.top;n<r.bottom;n++){let o=[];for(let s=n*t.width+r.left,a=r.left;a<r.right;a++,s++){let n=t.map[s];if(i[n])continue;i[n]=!0;let a=t.findCell(n),l=e.nodeAt(n);if(!l)throw RangeError(`No cell with offset ${n} found`);let c=r.left-a.left,d=a.right-r.right;if(c>0||d>0){let e=l.attrs;if(c>0&&(e=cf(e,0,c)),d>0&&(e=cf(e,e.colspan-d,d)),a.left<r.left){if(!(l=l.type.createAndFill(e)))throw RangeError(`Could not create cell with attrs ${JSON.stringify(e)}`)}else l=l.type.create(e,l.content)}if(a.top<r.top||a.bottom>r.bottom){let e={...l.attrs,rowspan:Math.min(a.bottom,r.bottom)-Math.max(a.top,r.top)};l=a.top<r.top?l.type.createAndFill(e):l.type.create(e,l.content)}o.push(l)}s.push(e.child(n).copy(iW.from(o)))}let o=this.isColSelection()&&this.isRowSelection()?e:s;return new iX(iW.from(o),1,1)}replace(e,t=iX.empty){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:s,$to:o}=r[i],a=e.mapping.slice(n);e.replace(a.map(s.pos),a.map(o.pos),i?iX.empty:t)}let i=oo.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);i&&e.setSelection(i)}replaceWith(e,t){this.replace(e,new iX(iW.from(t),0,0))}forEachCell(e){let t=this.$anchorCell.node(-1),n=co.get(t),r=this.$anchorCell.start(-1),i=n.cellsInRect(n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r));for(let n=0;n<i.length;n++)e(t.nodeAt(i[n]),r+i[n])}isColSelection(){let e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);return!(Math.min(e,t)>0)&&Math.max(e+this.$anchorCell.nodeAfter.attrs.rowspan,t+this.$headCell.nodeAfter.attrs.rowspan)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){let r=t.node(-1),i=co.get(r),s=t.start(-1),o=i.findCell(t.pos-s),a=i.findCell(n.pos-s),l=t.node(0);return o.top<=a.top?(o.top>0&&(t=l.resolve(s+i.map[o.left])),a.bottom<i.height&&(n=l.resolve(s+i.map[i.width*(i.height-1)+a.right-1]))):(a.top>0&&(n=l.resolve(s+i.map[a.left])),o.bottom<i.height&&(t=l.resolve(s+i.map[i.width*(i.height-1)+o.right-1]))),new e(t,n)}isRowSelection(){let e=this.$anchorCell.node(-1),t=co.get(e),n=this.$anchorCell.start(-1),r=t.colCount(this.$anchorCell.pos-n),i=t.colCount(this.$headCell.pos-n);return!(Math.min(r,i)>0)&&Math.max(r+this.$anchorCell.nodeAfter.attrs.colspan,i+this.$headCell.nodeAfter.attrs.colspan)==t.width}eq(t){return t instanceof e&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){let r=t.node(-1),i=co.get(r),s=t.start(-1),o=i.findCell(t.pos-s),a=i.findCell(n.pos-s),l=t.node(0);return o.left<=a.left?(o.left>0&&(t=l.resolve(s+i.map[o.top*i.width])),a.right<i.width&&(n=l.resolve(s+i.map[i.width*(a.top+1)-1]))):(a.left>0&&(n=l.resolve(s+i.map[a.top*i.width])),o.right<i.width&&(t=l.resolve(s+i.map[i.width*(o.top+1)-1]))),new e(t,n)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(t,n){return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){return new e(t.resolve(n),t.resolve(r))}getBookmark(){return new cb(this.$anchorCell.pos,this.$headCell.pos)}};cx.prototype.visible=!1,oo.jsonID("cell",cx);var cb=class e{constructor(e,t){this.anchor=e,this.head=t}map(t){return new e(t.map(this.anchor),t.map(this.head))}resolve(e){let t=e.resolve(this.anchor),n=e.resolve(this.head);return"row"==t.parent.type.spec.tableRole&&"row"==n.parent.type.spec.tableRole&&t.index()<t.parent.childCount&&n.index()<n.parent.childCount&&ch(t,n)?new cx(t,n):oo.near(n,1)}};function cy(e){if(!(e.selection instanceof cx))return null;let t=[];return e.selection.forEachCell((e,n)=>{t.push(lM.node(n,n+e.nodeSize,{class:"selectedCell"}))}),lO.create(e.doc,t)}let cv=new oE("fix-tables");function cw(e,t){let n,r=(t,r)=>{"table"==t.type.spec.tableRole&&(n=function(e,t,n,r){let i,s,o=co.get(t);if(!o.problems)return r;r||(r=e.tr);let a=[];for(let e=0;e<o.height;e++)a.push(0);for(let e=0;e<o.problems.length;e++){let i=o.problems[e];if("collision"==i.type){let e=t.nodeAt(i.pos);if(!e)continue;let s=e.attrs;for(let e=0;e<s.rowspan;e++)a[i.row+e]+=i.n;r.setNodeMarkup(r.mapping.map(n+1+i.pos),null,cf(s,s.colspan-i.n,i.n))}else if("missing"==i.type)a[i.row]+=i.n;else if("overlong_rowspan"==i.type){let e=t.nodeAt(i.pos);if(!e)continue;r.setNodeMarkup(r.mapping.map(n+1+i.pos),null,{...e.attrs,rowspan:e.attrs.rowspan-i.n})}else if("colwidth mismatch"==i.type){let e=t.nodeAt(i.pos);if(!e)continue;r.setNodeMarkup(r.mapping.map(n+1+i.pos),null,{...e.attrs,colwidth:i.colwidth})}else if("zero_sized"==i.type){let e=r.mapping.map(n);r.delete(e,e+t.nodeSize)}}for(let e=0;e<a.length;e++)a[e]&&(null==i&&(i=e),s=e);for(let l=0,c=n+1;l<o.height;l++){let n=t.child(l),o=c+n.nodeSize,d=a[l];if(d>0){let t="cell";n.firstChild&&(t=n.firstChild.type.spec.tableRole);let a=[];for(let n=0;n<d;n++){let n=ca(e.schema)[t].createAndFill();n&&a.push(n)}let u=(0==l||i==l-1)&&s==l?c+1:o-1;r.insert(r.mapping.map(u),a)}c=o}return r.setMeta(cv,{fixTables:!0})}(e,t,r,n))};return t?t.doc!=e.doc&&function e(t,n,r,i){let s=t.childCount,o=n.childCount;n:for(let a=0,l=0;a<o;a++){let o=n.child(a);for(let e=l,n=Math.min(s,a+3);e<n;e++)if(t.child(e)==o){l=e+1,r+=o.nodeSize;continue n}i(o,r),l<s&&t.child(l).sameMarkup(o)?e(t.child(l),o,r+1,i):o.nodesBetween(0,o.content.size,i,r+1),r+=o.nodeSize}}(t.doc,e.doc,0,r):e.doc.descendants(r),n}function ck(e){let t=co.get(e),n=[],r=t.height,i=t.width;for(let s=0;s<r;s++){let r=[];for(let n=0;n<i;n++){let o=s*i+n,a=t.map[o];if(s>0){let e=o-i;if(a===t.map[e]){r.push(null);continue}}if(n>0){let e=o-1;if(a===t.map[e]){r.push(null);continue}}r.push(e.nodeAt(a))}n.push(r)}return n}function cN(e,t){let n=[],r=co.get(e),i=r.height,s=r.width;for(let o=0;o<i;o++){let i=e.child(o),a=[];for(let n=0;n<s;n++){let i=t[o][n];if(!i)continue;let s=r.map[o*r.width+n],l=e.nodeAt(s);if(!l)continue;let c=l.type.createChecked(i.attrs,i.content,i.marks);a.push(c)}let l=i.type.createChecked(i.attrs,a,i.marks);n.push(l)}return e.type.createChecked(e.attrs,n,e.marks)}function cS(e,t,n,r){let i,s=t[0]>n[0]?-1:1,o=e.splice(t[0],t.length),a=+(o.length%2==0);return i=-1===r&&1===s?n[0]-1:1===r&&-1===s?n[n.length-1]-a+1:-1===s?n[0]:n[n.length-1]-a,e.splice(i,0,...o),e}function cC(e){var t=e;for(let e=t.depth;e>=0;e-=1){let n=t.node(e);if((e=>"table"===e.type.spec.tableRole)(n))return{node:n,pos:0===e?0:t.before(e),start:t.start(e),depth:e}}return null}function cj(e,t){let n=cC(t.$from);if(!n)return;let r=co.get(n.node);if(!(e<0)&&!(e>r.width-1))return r.cellsInRect({left:e,right:e+1,top:0,bottom:r.height}).map(e=>{let t=n.node.nodeAt(e),r=e+n.start;return{pos:r,start:r+1,node:t,depth:n.depth+2}})}function cE(e,t){let n=cC(t.$from);if(!n)return;let r=co.get(n.node);if(!(e<0)&&!(e>r.height-1))return r.cellsInRect({left:0,right:r.width,top:e,bottom:e+1}).map(e=>{let t=n.node.nodeAt(e),r=e+n.start;return{pos:r,start:r+1,node:t,depth:n.depth+2}})}function cM(e,t,n=t){let r,i=t,s=n;for(let n=t;n>=0;n--){let t=cj(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.colspan+n-1;t>=i&&(i=n),t>s&&(s=t)})}for(let n=t;n<=s;n++){let t=cj(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.colspan+n-1;e.node.attrs.colspan>1&&t>s&&(s=t)})}let o=[];for(let t=i;t<=s;t++){let n=cj(t,e.selection);n&&n.length>0&&o.push(t)}i=o[0],s=o[o.length-1];let a=cj(i,e.selection),l=cE(0,e.selection);if(!a||!l)return;let c=e.doc.resolve(a[a.length-1].pos);for(let t=s;t>=i;t--){let n=cj(t,e.selection);if(n&&n.length>0){for(let e=l.length-1;e>=0;e--)if(l[e].pos===n[0].pos){r=n[0];break}if(r)break}}if(r)return{$anchor:c,$head:e.doc.resolve(r.pos),indexes:o}}function cA(e,t,n=t){let r,i=t,s=n;for(let n=t;n>=0;n--){let t=cE(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.rowspan+n-1;t>=i&&(i=n),t>s&&(s=t)})}for(let n=t;n<=s;n++){let t=cE(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.rowspan+n-1;e.node.attrs.rowspan>1&&t>s&&(s=t)})}let o=[];for(let t=i;t<=s;t++){let n=cE(t,e.selection);n&&n.length>0&&o.push(t)}i=o[0],s=o[o.length-1];let a=cE(i,e.selection),l=cj(0,e.selection);if(!a||!l)return;let c=e.doc.resolve(a[a.length-1].pos);for(let t=s;t>=i;t--){let n=cE(t,e.selection);if(n&&n.length>0){for(let e=l.length-1;e>=0;e--)if(l[e].pos===n[0].pos){r=n[0];break}if(r)break}}if(r)return{$anchor:c,$head:e.doc.resolve(r.pos),indexes:o}}function cT(e){return e[0].map((t,n)=>e.map(e=>e[n]))}function cO(e){let t=e.selection,n=cu(e),r=n.node(-1),i=n.start(-1),s=co.get(r);return{...t instanceof cx?s.rectBetween(t.$anchorCell.pos-i,t.$headCell.pos-i):s.findCell(n.pos-i),tableStart:i,map:s,table:r}}function c_(e,{map:t,tableStart:n,table:r},i){let s=i>0?-1:0;(function(e,t,n){let r=ca(t.type.schema).header_cell;for(let i=0;i<e.height;i++)if(t.nodeAt(e.map[n+i*e.width]).type!=r)return!1;return!0})(t,r,i+s)&&(s=0==i||i==t.width?null:0);for(let o=0;o<t.height;o++){let a=o*t.width+i;if(i>0&&i<t.width&&t.map[a-1]==t.map[a]){let s=t.map[a],l=r.nodeAt(s);e.setNodeMarkup(e.mapping.map(n+s),null,cg(l.attrs,i-t.colCount(s))),o+=l.attrs.rowspan-1}else{let l=null==s?ca(r.type.schema).cell:r.nodeAt(t.map[a+s]).type,c=t.positionAt(o,i,r);e.insert(e.mapping.map(n+c),l.createAndFill())}}return e}function cD(e,{map:t,tableStart:n,table:r},i){let s=n;for(let e=0;e<i;e++)s+=r.child(e).nodeSize;let o=[],a=i>0?-1:0;(function(e,t,n){var r;let i=ca(t.type.schema).header_cell;for(let s=0;s<e.width;s++)if((null==(r=t.nodeAt(e.map[s+n*e.width]))?void 0:r.type)!=i)return!1;return!0})(t,r,i+a)&&(a=0==i||i==t.height?null:0);for(let s=0,c=t.width*i;s<t.width;s++,c++)if(i>0&&i<t.height&&t.map[c]==t.map[c-t.width]){let i=t.map[c],o=r.nodeAt(i).attrs;e.setNodeMarkup(n+i,null,{...o,rowspan:o.rowspan+1}),s+=o.colspan-1}else{var l;let e=null==a?ca(r.type.schema).cell:null==(l=r.nodeAt(t.map[c+a*t.width]))?void 0:l.type,n=null==e?void 0:e.createAndFill();n&&o.push(n)}return e.insert(s,ca(r.type.schema).row.create(null,o)),e}function cR(e){let t=e.content;return 1==t.childCount&&t.child(0).isTextblock&&0==t.child(0).childCount}function cI(e,t){let n=e.selection;if(!(n instanceof cx)||n.$anchorCell.pos==n.$headCell.pos)return!1;let r=cO(e),{map:i}=r;if(function({width:e,height:t,map:n},r){let i=r.top*e+r.left,s=i,o=(r.bottom-1)*e+r.left,a=i+(r.right-r.left-1);for(let t=r.top;t<r.bottom;t++){if(r.left>0&&n[s]==n[s-1]||r.right<e&&n[a]==n[a+1])return!0;s+=e,a+=e}for(let s=r.left;s<r.right;s++){if(r.top>0&&n[i]==n[i-e]||r.bottom<t&&n[o]==n[o+e])return!0;i++,o++}return!1}(i,r))return!1;if(t){let n,s,o=e.tr,a={},l=iW.empty;for(let e=r.top;e<r.bottom;e++)for(let t=r.left;t<r.right;t++){let c=i.map[e*i.width+t],d=r.table.nodeAt(c);if(!a[c]&&d)if(a[c]=!0,null==n)n=c,s=d;else{cR(d)||(l=l.append(d.content));let e=o.mapping.map(c+r.tableStart);o.delete(e,e+d.nodeSize)}}if(null==n||null==s)return!0;if(o.setNodeMarkup(n+r.tableStart,null,{...cg(s.attrs,s.attrs.colspan,r.right-r.left-s.attrs.colspan),rowspan:r.bottom-r.top}),l.size>0){let e=n+1+s.content.size,t=cR(s)?n+1:e;o.replaceWith(t+r.tableStart,e+r.tableStart,l)}o.setSelection(new cx(o.doc.resolve(n+r.tableStart))),t(o)}return!0}function cL(e,t){var n;let r=ca(e.schema);return(n=({node:e})=>r[e.type.spec.tableRole],(e,t)=>{let r,i,s=e.selection;if(s instanceof cx){if(s.$anchorCell.pos!=s.$headCell.pos)return!1;r=s.$anchorCell.nodeAfter,i=s.$anchorCell.pos}else{var o;if(!(r=function(e){for(let t=e.depth;t>0;t--){let n=e.node(t).type.spec.tableRole;if("cell"===n||"header_cell"===n)return e.node(t)}return null}(s.$from)))return!1;i=null==(o=cc(s.$from))?void 0:o.pos}if(null==r||null==i||1==r.attrs.colspan&&1==r.attrs.rowspan)return!1;if(t){let o,a=r.attrs,l=[],c=a.colwidth;a.rowspan>1&&(a={...a,rowspan:1}),a.colspan>1&&(a={...a,colspan:1});let d=cO(e),u=e.tr;for(let e=0;e<d.right-d.left;e++)l.push(c?{...a,colwidth:c&&c[e]?[c[e]]:null}:a);for(let e=d.top;e<d.bottom;e++){let t=d.map.positionAt(e,d.left,d.table);e==d.top&&(t+=r.nodeSize);for(let i=d.left,s=0;i<d.right;i++,s++)(i!=d.left||e!=d.top)&&u.insert(o=u.mapping.map(t+d.tableStart,1),n({node:r,row:e,col:i}).createAndFill(l[s]))}u.setNodeMarkup(i,n({node:r,row:d.top,col:d.left}),l[0]),s instanceof cx&&u.setSelection(new cx(u.doc.resolve(s.$anchorCell.pos),o?u.doc.resolve(o):void 0)),t(u)}return!0})(e,t)}function cP(e,t,n){let r=t.map.cellsInRect({left:0,top:0,right:"row"==e?t.map.width:1,bottom:"column"==e?t.map.height:1});for(let e=0;e<r.length;e++){let i=t.table.nodeAt(r[e]);if(i&&i.type!==n.header_cell)return!1}return!0}function c$(e,t){if((t=t||{useDeprecatedLogic:!1}).useDeprecatedLogic)return function(t,n){if(!cd(t))return!1;if(n){let r=ca(t.schema),i=cO(t),s=t.tr,o=i.map.cellsInRect("column"==e?{left:i.left,top:0,right:i.right,bottom:i.map.height}:"row"==e?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),a=o.map(e=>i.table.nodeAt(e));for(let e=0;e<o.length;e++)a[e].type==r.header_cell&&s.setNodeMarkup(i.tableStart+o[e],r.cell,a[e].attrs);if(0===s.steps.length)for(let e=0;e<o.length;e++)s.setNodeMarkup(i.tableStart+o[e],r.header_cell,a[e].attrs);n(s)}return!0};return function(t,n){if(!cd(t))return!1;if(n){let r=ca(t.schema),i=cO(t),s=t.tr,o=cP("row",i,r),a=cP("column",i,r),l=+("column"===e?!!o:"row"===e&&!!a),c="column"==e?{left:0,top:l,right:1,bottom:i.map.height}:"row"==e?{left:l,top:0,right:i.map.width,bottom:1}:i,d="column"==e?a?r.cell:r.header_cell:"row"==e?o?r.cell:r.header_cell:r.cell;i.map.cellsInRect(c).forEach(e=>{let t=e+i.tableStart,n=s.doc.nodeAt(t);n&&s.setNodeMarkup(t,d,n.attrs)}),n(s)}return!0}}c$("row",{useDeprecatedLogic:!0}),c$("column",{useDeprecatedLogic:!0});let cz=c$("cell",{useDeprecatedLogic:!0});function cB(e){return function(t,n){if(!cd(t))return!1;let r=function(e,t){if(t<0){let t=e.nodeBefore;if(t)return e.pos-t.nodeSize;for(let t=e.index(-1)-1,n=e.before();t>=0;t--){let r=e.node(-1).child(t),i=r.lastChild;if(i)return n-1-i.nodeSize;n-=r.nodeSize}}else{if(e.index()<e.parent.childCount-1)return e.pos+e.nodeAfter.nodeSize;let t=e.node(-1);for(let n=e.indexAfter(-1),r=e.after();n<t.childCount;n++){let e=t.child(n);if(e.childCount)return r+1;r+=e.nodeSize}}return null}(cu(t),e);if(null==r)return!1;if(n){let e=t.doc.resolve(r);n(t.tr.setSelection(od.between(e,e.node(0).resolve(e.pos+e.nodeAfter.nodeSize))).scrollIntoView())}return!0}}function cF(e,t){let n=e.selection;if(!(n instanceof cx))return!1;if(t){let r=e.tr,i=ca(e.schema).cell.createAndFill().content;n.forEachCell((e,t)=>{e.content.eq(i)||r.replace(r.mapping.map(t+1),r.mapping.map(t+e.nodeSize-1),new iX(i,0,0))}),r.docChanged&&t(r)}return!0}function cH(e,t){let n=e.createAndFill();return new or(n).replace(0,n.content.size,t).doc}function cU(e,t,n,r,i,s,o,a){if(0==o||o==t.height)return!1;let l=!1;for(let c=i;c<s;c++){let i=o*t.width+c,s=t.map[i];if(t.map[i-t.width]==s){l=!0;let i=n.nodeAt(s),{top:d,left:u}=t.findCell(s);e.setNodeMarkup(e.mapping.slice(a).map(s+r),null,{...i.attrs,rowspan:o-d}),e.insert(e.mapping.slice(a).map(t.positionAt(o,u,n)),i.type.createAndFill({...i.attrs,rowspan:d+i.attrs.rowspan-o})),c+=i.attrs.colspan-1}}return l}function cV(e,t,n,r,i,s,o,a){if(0==o||o==t.width)return!1;let l=!1;for(let c=i;c<s;c++){let i=c*t.width+o,s=t.map[i];if(t.map[i-1]==s){l=!0;let i=n.nodeAt(s),d=t.colCount(s),u=e.mapping.slice(a).map(s+r);e.setNodeMarkup(u,null,cf(i.attrs,o-d,i.attrs.colspan-(o-d))),e.insert(u+i.nodeSize,i.type.createAndFill(cf(i.attrs,0,o-d))),c+=i.attrs.rowspan-1}}return l}function cW(e,t,n,r,i){let s=n?e.doc.nodeAt(n-1):e.doc;if(!s)throw Error("No table found");let o=co.get(s),{top:a,left:l}=r,c=l+i.width,d=a+i.height,u=e.tr,p=0;function h(){if(!(s=n?u.doc.nodeAt(n-1):u.doc))throw Error("No table found");o=co.get(s),p=u.mapping.maps.length}(function(e,t,n,r,i,s){let o,a,l=ca(e.doc.type.schema);if(i>t.width)for(let s=0,c=0;s<t.height;s++){let d,u=n.child(s);c+=u.nodeSize;let p=[];d=null==u.lastChild||u.lastChild.type==l.cell?o||(o=l.cell.createAndFill()):a||(a=l.header_cell.createAndFill());for(let e=t.width;e<i;e++)p.push(d);e.insert(e.mapping.slice(0).map(c-1+r),p)}if(s>t.height){let c=[];for(let e=0,r=(t.height-1)*t.width;e<Math.max(t.width,i);e++){let i=!(e>=t.width)&&n.nodeAt(t.map[r+e]).type==l.header_cell;c.push(i?a||(a=l.header_cell.createAndFill()):o||(o=l.cell.createAndFill()))}let d=l.row.create(null,iW.from(c)),u=[];for(let e=t.height;e<s;e++)u.push(d);e.insert(e.mapping.slice(0).map(r+n.nodeSize-2),u)}return!!(o||a)})(u,o,s,n,c,d)&&h(),cU(u,o,s,n,l,c,a,p)&&h(),cU(u,o,s,n,l,c,d,p)&&h(),cV(u,o,s,n,a,d,l,p)&&h(),cV(u,o,s,n,a,d,c,p)&&h();for(let e=a;e<d;e++){let t=o.positionAt(e,l,s),r=o.positionAt(e,c,s);u.replace(u.mapping.slice(p).map(t+n),u.mapping.slice(p).map(r+n),new iX(i.rows[e-a],0,0))}h(),u.setSelection(new cx(u.doc.resolve(n+o.positionAt(a,l,s)),u.doc.resolve(n+o.positionAt(d-1,c-1,s)))),t(u)}let cq=cs({ArrowLeft:cG("horiz",-1),ArrowRight:cG("horiz",1),ArrowUp:cG("vert",-1),ArrowDown:cG("vert",1),"Shift-ArrowLeft":cJ("horiz",-1),"Shift-ArrowRight":cJ("horiz",1),"Shift-ArrowUp":cJ("vert",-1),"Shift-ArrowDown":cJ("vert",1),Backspace:cF,"Mod-Backspace":cF,Delete:cF,"Mod-Delete":cF});function cK(e,t,n){return!n.eq(e.selection)&&(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function cG(e,t){return(n,r,i)=>{if(!i)return!1;let s=n.selection;if(s instanceof cx)return cK(n,r,oo.near(s.$headCell,t));if("horiz"!=e&&!s.empty)return!1;let o=cQ(i,e,t);if(null==o)return!1;if("horiz"==e)return cK(n,r,oo.near(n.doc.resolve(s.head+t),t));{let i,s=n.doc.resolve(o),a=cm(s,e,t);return i=a?oo.near(a,1):t<0?oo.near(n.doc.resolve(s.before(-1)),-1):oo.near(n.doc.resolve(s.after(-1)),1),cK(n,r,i)}}}function cJ(e,t){return(n,r,i)=>{let s;if(!i)return!1;let o=n.selection;if(o instanceof cx)s=o;else{let r=cQ(i,e,t);if(null==r)return!1;s=new cx(n.doc.resolve(r))}let a=cm(s.$headCell,e,t);return!!a&&cK(n,r,new cx(s.$anchorCell,a))}}function cZ(e,t){let n=cc(e.state.doc.resolve(t));return!!n&&(e.dispatch(e.state.tr.setSelection(new cx(n))),!0)}function cX(e,t,n){if(!cd(e.state))return!1;let r=function(e){if(0===e.size)return null;let{content:t,openStart:n,openEnd:r}=e;for(;1==t.childCount&&(n>0&&r>0||"table"==t.child(0).type.spec.tableRole);)n--,r--,t=t.child(0).content;let i=t.child(0),s=i.type.spec.tableRole,o=i.type.schema,a=[];if("row"==s)for(let e=0;e<t.childCount;e++){let i=t.child(e).content,s=e?0:Math.max(0,n-1),l=e<t.childCount-1?0:Math.max(0,r-1);(s||l)&&(i=cH(ca(o).row,new iX(i,s,l)).content),a.push(i)}else{if("cell"!=s&&"header_cell"!=s)return null;a.push(n||r?cH(ca(o).row,new iX(t,n,r)).content:t)}return function(e,t){let n=[];for(let e=0;e<t.length;e++){let r=t[e];for(let t=r.childCount-1;t>=0;t--){let{rowspan:i,colspan:s}=r.child(t).attrs;for(let t=e;t<e+i;t++)n[t]=(n[t]||0)+s}}let r=0;for(let e=0;e<n.length;e++)r=Math.max(r,n[e]);for(let i=0;i<n.length;i++)if(i>=t.length&&t.push(iW.empty),n[i]<r){let s=ca(e).cell.createAndFill(),o=[];for(let e=n[i];e<r;e++)o.push(s);t[i]=t[i].append(iW.from(o))}return{height:t.length,width:r,rows:t}}(o,a)}(n),i=e.state.selection;if(i instanceof cx){r||(r={width:1,height:1,rows:[iW.from(cH(ca(e.state.schema).cell,n))]});let t=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),o=co.get(t).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=function({width:e,height:t,rows:n},r,i){if(e!=r){let t=[],i=[];for(let e=0;e<n.length;e++){let s=n[e],o=[];for(let n=t[e]||0,i=0;n<r;i++){let a=s.child(i%s.childCount);n+a.attrs.colspan>r&&(a=a.type.createChecked(cf(a.attrs,a.attrs.colspan,n+a.attrs.colspan-r),a.content)),o.push(a),n+=a.attrs.colspan;for(let n=1;n<a.attrs.rowspan;n++)t[e+n]=(t[e+n]||0)+a.attrs.colspan}i.push(iW.from(o))}n=i,e=r}if(t!=i){let e=[];for(let r=0,s=0;r<i;r++,s++){let o=[],a=n[s%t];for(let e=0;e<a.childCount;e++){let t=a.child(e);r+t.attrs.rowspan>i&&(t=t.type.create({...t.attrs,rowspan:Math.max(1,i-t.attrs.rowspan)},t.content)),o.push(t)}e.push(iW.from(o))}n=e,t=i}return{width:e,height:t,rows:n}}(r,o.right-o.left,o.bottom-o.top),cW(e.state,e.dispatch,s,o,r),!0}if(!r)return!1;{let t=cu(e.state),n=t.start(-1);return cW(e.state,e.dispatch,n,co.get(t.node(-1)).findCell(t.pos-n),r),!0}}function cY(e,t){var n;let r;if(0!=t.button||t.ctrlKey||t.metaKey)return;let i=c0(e,t.target);if(t.shiftKey&&e.state.selection instanceof cx)s(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&i&&null!=(r=cc(e.state.selection.$anchor))&&(null==(n=c1(e,t))?void 0:n.pos)!=r.pos)s(r,t),t.preventDefault();else if(!i)return;function s(t,n){let r=c1(e,n),i=null==cl.getState(e.state);if(!r||!ch(t,r))if(!i)return;else r=t;let s=new cx(t,r);if(i||!e.state.selection.eq(s)){let n=e.state.tr.setSelection(s);i&&n.setMeta(cl,t.pos),e.dispatch(n)}}function o(){e.root.removeEventListener("mouseup",o),e.root.removeEventListener("dragstart",o),e.root.removeEventListener("mousemove",a),null!=cl.getState(e.state)&&e.dispatch(e.state.tr.setMeta(cl,-1))}function a(n){let r,a=cl.getState(e.state);if(null!=a)r=e.state.doc.resolve(a);else if(c0(e,n.target)!=i&&!(r=c1(e,t)))return o();r&&s(r,n)}e.root.addEventListener("mouseup",o),e.root.addEventListener("dragstart",o),e.root.addEventListener("mousemove",a)}function cQ(e,t,n){if(!(e.state.selection instanceof od))return null;let{$head:r}=e.state.selection;for(let i=r.depth-1;i>=0;i--){let s=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:s.childCount))break;if("cell"==s.type.spec.tableRole||"header_cell"==s.type.spec.tableRole){let s=r.before(i),o="vert"==t?n>0?"down":"up":n>0?"right":"left";return e.endOfTextblock(o)?s:null}}return null}function c0(e,t){for(;t&&t!=e.dom;t=t.parentNode)if("TD"==t.nodeName||"TH"==t.nodeName)return t;return null}function c1(e,t){let n=e.posAtCoords({left:t.clientX,top:t.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&cc(e.state.doc.resolve(r))||cc(e.state.doc.resolve(i))}var c2=class{constructor(e,t){this.node=e,this.defaultCellMinWidth=t,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${t}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),c5(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type==this.node.type&&(this.node=e,c5(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return"attributes"==e.type&&(e.target==this.table||this.colgroup.contains(e.target))}};function c5(e,t,n,r,i,s){let o=0,a=!0,l=t.firstChild,c=e.firstChild;if(c){for(let e=0,n=0;e<c.childCount;e++){let{colspan:d,colwidth:u}=c.child(e).attrs;for(let e=0;e<d;e++,n++){let c=i==n?s:u&&u[e],d=c?c+"px":"";if(o+=c||r,c||(a=!1),l)l.style.width!=d&&(l.style.width=d),l=l.nextSibling;else{let e=document.createElement("col");e.style.width=d,t.appendChild(e)}}}for(;l;){var d;let e=l.nextSibling;null==(d=l.parentNode)||d.removeChild(l),l=e}a?(n.style.width=o+"px",n.style.minWidth=""):(n.style.width="",n.style.minWidth=o+"px")}}let c3=new oE("tableColumnResizing");var c4=class e{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(t){let n=t.getMeta(c3);if(n&&null!=n.setHandle)return new e(n.setHandle,!1);if(n&&void 0!==n.setDragging)return new e(this.activeHandle,n.setDragging);if(this.activeHandle>-1&&t.docChanged){let n=t.mapping.map(this.activeHandle,-1);return cp(t.doc.resolve(n))||(n=-1),new e(n,this.dragging)}return this}};function c6(e,t,n,r){let i=e.posAtCoords({left:t.clientX+("right"==n?-r:r),top:t.clientY});if(!i)return -1;let{pos:s}=i,o=cc(e.state.doc.resolve(s));if(!o)return -1;if("right"==n)return o.pos;let a=co.get(o.node(-1)),l=o.start(-1),c=a.map.indexOf(o.pos-l);return c%a.width==0?-1:l+a.map[c-1]}function c9(e,t,n){let r=t.clientX-e.startX;return Math.max(n,e.startWidth+r)}function c7(e,t){e.dispatch(e.state.tr.setMeta(c3,{setHandle:t}))}function c8(e,t,n,r){let i=e.state.doc.resolve(t),s=i.node(-1),o=i.start(-1),a=co.get(s).colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1,l=e.domAtPos(i.start(-1)).node;for(;l&&"TABLE"!=l.nodeName;)l=l.parentNode;l&&c5(s,l.firstChild,l,r,a,n)}var de=m,dt=e.i(3909);let dn=(e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function dr(e,t){let{$cursor:n}=e.selection;return n&&(t?t.endOfTextblock("backward",e):!(n.parentOffset>0))?n:null}let di=(e,t,n)=>{let r=dr(e,n);if(!r)return!1;let i=dc(r);if(!i){let n=r.blockRange(),i=n&&sq(n);return null!=i&&(t&&t(e.tr.lift(n,i).scrollIntoView()),!0)}let s=i.nodeBefore;if(dy(e,i,t,-1))return!0;if(0==r.parent.content.size&&(da(s,"end")||op.isSelectable(s)))for(let n=r.depth;;n--){let o=s2(e.doc,r.before(n),r.after(n),iX.empty);if(o&&o.slice.size<o.to-o.from){if(t){let n=e.tr.step(o);n.setSelection(da(s,"end")?oo.findFrom(n.doc.resolve(n.mapping.map(i.pos,-1)),-1):op.create(n.doc,i.pos-s.nodeSize)),t(n.scrollIntoView())}return!0}if(1==n||r.node(n-1).childCount>1)break}return!!s.isAtom&&i.depth==r.depth-1&&(t&&t(e.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0)};function ds(e,t,n){let r=t.nodeBefore,i=t.pos-1;for(;!r.isTextblock;i--){if(r.type.spec.isolating)return!1;let e=r.lastChild;if(!e)return!1;r=e}let s=t.nodeAfter,o=t.pos+1;for(;!s.isTextblock;o++){if(s.type.spec.isolating)return!1;let e=s.firstChild;if(!e)return!1;s=e}let a=s2(e.doc,i,o,iX.empty);if(!a||a.from!=i||a instanceof sH&&a.slice.size>=o-i)return!1;if(n){let t=e.tr.step(a);t.setSelection(od.create(t.doc,i)),n(t.scrollIntoView())}return!0}function da(e,t,n=!1){for(let r=e;r;r="start"==t?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&1!=r.childCount)break}return!1}let dl=(e,t,n)=>{let{$head:r,empty:i}=e.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",e):r.parentOffset>0)return!1;s=dc(r)}let o=s&&s.nodeBefore;return!!o&&!!op.isSelectable(o)&&(t&&t(e.tr.setSelection(op.create(e.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function dc(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}function dd(e,t){let{$cursor:n}=e.selection;return n&&(t?t.endOfTextblock("forward",e):!(n.parentOffset<n.parent.content.size))?n:null}let du=(e,t,n)=>{let r=dd(e,n);if(!r)return!1;let i=dh(r);if(!i)return!1;let s=i.nodeAfter;if(dy(e,i,t,1))return!0;if(0==r.parent.content.size&&(da(s,"start")||op.isSelectable(s))){let n=s2(e.doc,r.before(),r.after(),iX.empty);if(n&&n.slice.size<n.to-n.from){if(t){let r=e.tr.step(n);r.setSelection(da(s,"start")?oo.findFrom(r.doc.resolve(r.mapping.map(i.pos)),1):op.create(r.doc,r.mapping.map(i.pos))),t(r.scrollIntoView())}return!0}}return!!s.isAtom&&i.depth==r.depth-1&&(t&&t(e.tr.delete(i.pos,i.pos+s.nodeSize).scrollIntoView()),!0)},dp=(e,t,n)=>{let{$head:r,empty:i}=e.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",e):r.parentOffset<r.parent.content.size)return!1;s=dh(r)}let o=s&&s.nodeAfter;return!!o&&!!op.isSelectable(o)&&(t&&t(e.tr.setSelection(op.create(e.doc,s.pos)).scrollIntoView()),!0)};function dh(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){let n=e.node(t);if(e.index(t)+1<n.childCount)return e.doc.resolve(e.after(t+1));if(n.type.spec.isolating)break}return null}let dm=(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 df(e){for(let t=0;t<e.edgeCount;t++){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}let dg=(e,t)=>{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),s=n.indexAfter(-1),o=df(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(t){let r=n.after(),i=e.tr.replaceWith(r,r,o.createAndFill());i.setSelection(oo.near(i.doc.resolve(r),1)),t(i.scrollIntoView())}return!0},dx=(e,t)=>{let n=e.selection,{$from:r,$to:i}=n;if(n instanceof om||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=df(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(t){let n=(!r.parentOffset&&i.index()<i.parent.childCount?r:i).pos,o=e.tr.insert(n,s.createAndFill());o.setSelection(od.create(o.doc,n+1)),t(o.scrollIntoView())}return!0},db=(e,t)=>{let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(sX(e.doc,r))return t&&t(e.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),i=r&&sq(r);return null!=i&&(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)};function dy(e,t,n,r){let i,s,o,a=t.nodeBefore,l=t.nodeAfter,c,d,u=a.type.spec.isolating||l.type.spec.isolating;if(!u&&(i=t.nodeBefore,s=t.nodeAfter,o=t.index(),i&&s&&i.type.compatibleContent(s.type)&&(!i.content.size&&t.parent.canReplace(o-1,o)?(n&&n(e.tr.delete(t.pos-i.nodeSize,t.pos).scrollIntoView()),!0):!!t.parent.canReplace(o,o+1)&&!!(s.isTextblock||sY(e.doc,t.pos))&&(n&&n(e.tr.join(t.pos).scrollIntoView()),!0))))return!0;let p=!u&&t.parent.canReplace(t.index(),t.index()+1);if(p&&(c=(d=a.contentMatchAt(a.childCount)).findWrapping(l.type))&&d.matchType(c[0]||l.type).validEnd){if(n){let r=t.pos+l.nodeSize,i=iW.empty;for(let e=c.length-1;e>=0;e--)i=iW.from(c[e].create(null,i));i=iW.from(a.copy(i));let s=e.tr.step(new sU(t.pos-1,r,t.pos,r,new iX(i,1,0),c.length,!0)),o=s.doc.resolve(r+2*c.length);o.nodeAfter&&o.nodeAfter.type==a.type&&sY(s.doc,o.pos)&&s.join(o.pos),n(s.scrollIntoView())}return!0}let h=l.type.spec.isolating||r>0&&u?null:oo.findFrom(t,1),m=h&&h.$from.blockRange(h.$to),f=m&&sq(m);if(null!=f&&f>=t.depth)return n&&n(e.tr.lift(m,f).scrollIntoView()),!0;if(p&&da(l,"start",!0)&&da(a,"end")){let r=a,i=[];for(;i.push(r),!r.isTextblock;)r=r.lastChild;let s=l,o=1;for(;!s.isTextblock;s=s.firstChild)o++;if(r.canReplace(r.childCount,r.childCount,s.content)){if(n){let r=iW.empty;for(let e=i.length-1;e>=0;e--)r=iW.from(i[e].copy(r));n(e.tr.step(new sU(t.pos-i.length,t.pos+l.nodeSize,t.pos+o,t.pos+l.nodeSize-o,new iX(r,i.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function dv(e){return function(t,n){let r=t.selection,i=e<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return!!i.node(s).isTextblock&&(n&&n(t.tr.setSelection(od.create(t.doc,e<0?i.start(s):i.end(s)))),!0)}}let dw=dv(-1),dk=dv(1);function dN(e,t=null){return function(n,r){let i=!1;for(let r=0;r<n.selection.ranges.length&&!i;r++){let{$from:{pos:s},$to:{pos:o}}=n.selection.ranges[r];n.doc.nodesBetween(s,o,(r,s)=>{if(i)return!1;if(!(!r.isTextblock||r.hasMarkup(e,t)))if(r.type==e)i=!0;else{let t=n.doc.resolve(s),r=t.index();i=t.parent.canReplaceWith(r,r+1,e)}})}if(!i)return!1;if(r){let i=n.tr;for(let r=0;r<n.selection.ranges.length;r++){let{$from:{pos:s},$to:{pos:o}}=n.selection.ranges[r];i.setBlockType(s,o,e,t)}r(i.scrollIntoView())}return!0}}function dS(...e){return function(t,n,r){for(let i=0;i<e.length;i++)if(e[i](t,n,r))return!0;return!1}}let dC=dS(dn,di,dl),dj=dS(dn,du,dp),dE={Enter:dS(dm,dx,db,(e,t)=>{let{$from:n,$to:r}=e.selection;if(e.selection instanceof op&&e.selection.node.isBlock)return!!n.parentOffset&&!!sX(e.doc,n.pos)&&(t&&t(e.tr.split(n.pos).scrollIntoView()),!0);if(!n.depth)return!1;let i=[],s,o,a=!1,l=!1;for(let e=n.depth;;e--){if(n.node(e).isBlock){let t;a=n.end(e)==n.pos+(n.depth-e),l=n.start(e)==n.pos-(n.depth-e),o=df(n.node(e-1).contentMatchAt(n.indexAfter(e-1)));i.unshift(t||(a&&o?{type:o}:null)),s=e;break}if(1==e)return!1;i.unshift(null)}let c=e.tr;(e.selection instanceof od||e.selection instanceof om)&&c.deleteSelection();let d=c.mapping.map(n.pos),u=sX(c.doc,d,i.length,i);if(u||(i[0]=o?{type:o}:null,u=sX(c.doc,d,i.length,i)),!u)return!1;if(c.split(d,i.length,i),!a&&l&&n.node(s).type!=o){let e=c.mapping.map(n.before(s)),t=c.doc.resolve(e);o&&n.node(s-1).canReplaceWith(t.index(),t.index()+1,o)&&c.setNodeMarkup(c.mapping.map(n.before(s)),o)}return t&&t(c.scrollIntoView()),!0}),"Mod-Enter":dg,Backspace:dC,"Mod-Backspace":dC,"Shift-Backspace":dC,Delete:dj,"Mod-Delete":dj,"Mod-a":(e,t)=>(t&&t(e.tr.setSelection(new om(e.doc))),!0)},dM={"Ctrl-h":dE.Backspace,"Alt-Backspace":dE["Mod-Backspace"],"Ctrl-d":dE.Delete,"Ctrl-Alt-Backspace":dE["Mod-Delete"],"Alt-Delete":dE["Mod-Delete"],"Alt-d":dE["Mod-Delete"],"Ctrl-a":dw,"Ctrl-e":dk};for(let e in dE)dM[e]=dE[e];"u">typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):"u">typeof os&&os.platform&&os.platform();var dA=Object.defineProperty,dT=(e,t)=>{for(var n in t)dA(e,n,{get:t[n],enumerable:!0})};function dO(e){let{state:t,transaction:n}=e,{selection:r}=n,{doc:i}=n,{storedMarks:s}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return s},get selection(){return r},get doc(){return i},get tr(){return r=n.selection,i=n.doc,s=n.storedMarks,n}}}var d_=class{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){let{rawCommands:e,editor:t,state:n}=this,{view:r}=t,{tr:i}=n,s=this.buildProps(i);return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,(...e)=>{let n=t(...e)(s);return i.getMeta("preventDispatch")||this.hasCustomState||r.dispatch(i),n}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:s}=r,o=[],a=!!e,l=e||i.tr,c=()=>(a||!t||l.getMeta("preventDispatch")||this.hasCustomState||s.dispatch(l),o.every(e=>!0===e)),d={...Object.fromEntries(Object.entries(n).map(([e,n])=>[e,(...e)=>{let r=this.buildProps(l,t),i=n(...e)(r);return o.push(i),d}])),run:c};return d}createCan(e){let{rawCommands:t,state:n}=this,r=e||n.tr,i=this.buildProps(r,!1);return{...Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>t(...e)({...i,dispatch:void 0})])),chain:()=>this.createChain(r,!1)}}buildProps(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:s}=r,o={tr:e,editor:r,view:s,state:dO({state:i,transaction:e}),dispatch:t?()=>void 0:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,(...e)=>t(...e)(o)]))}};return o}},dD={};dT(dD,{blur:()=>dR,clearContent:()=>dI,clearNodes:()=>dL,command:()=>dP,createParagraphNear:()=>d$,cut:()=>dz,deleteCurrentNode:()=>dB,deleteNode:()=>dH,deleteRange:()=>dU,deleteSelection:()=>dW,enter:()=>dq,exitCode:()=>dK,extendMarkRange:()=>d0,first:()=>d1,focus:()=>d9,forEach:()=>d7,insertContent:()=>d8,insertContentAt:()=>ur,joinBackward:()=>uo,joinDown:()=>us,joinForward:()=>ua,joinItemBackward:()=>ul,joinItemForward:()=>uc,joinTextblockBackward:()=>ud,joinTextblockForward:()=>uu,joinUp:()=>ui,keyboardShortcut:()=>uh,lift:()=>uf,liftEmptyBlock:()=>ug,liftListItem:()=>ux,newlineInCode:()=>ub,resetAttributes:()=>uw,scrollIntoView:()=>uk,selectAll:()=>uN,selectNodeBackward:()=>uS,selectNodeForward:()=>uC,selectParentNode:()=>uj,selectTextblockEnd:()=>uE,selectTextblockStart:()=>uM,setContent:()=>uT,setMark:()=>pi,setMeta:()=>ps,setNode:()=>po,setNodeSelection:()=>pa,setTextDirection:()=>pl,setTextSelection:()=>pc,sinkListItem:()=>pd,splitBlock:()=>pp,splitListItem:()=>ph,toggleList:()=>pg,toggleMark:()=>px,toggleNode:()=>pb,toggleWrap:()=>py,undoInputRule:()=>pv,unsetAllMarks:()=>pw,unsetMark:()=>pk,unsetTextDirection:()=>pN,updateAttributes:()=>pS,wrapIn:()=>pC,wrapInList:()=>pj});var dR=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),null==(n=null==window?void 0:window.getSelection())||n.removeAllRanges())}),!0),dI=(e=!0)=>({commands:t})=>t.setContent("",{emitUpdate:e}),dL=()=>({state:e,tr:t,dispatch:n})=>{let{selection:r}=t,{ranges:i}=r;return!n||(i.forEach(({$from:n,$to:r})=>{e.doc.nodesBetween(n.pos,r.pos,(e,n)=>{if(e.type.isText)return;let{doc:r,mapping:i}=t,s=r.resolve(i.map(n)),o=r.resolve(i.map(n+e.nodeSize)),a=s.blockRange(o);if(!a)return;let l=sq(a);if(e.type.isTextblock){let{defaultType:e}=s.parent.contentMatchAt(s.index());t.setNodeMarkup(a.start,e)}(l||0===l)&&t.lift(a,l)})}),!0)},dP=e=>t=>e(t),d$=()=>({state:e,dispatch:t})=>dx(e,t),dz=(e,t)=>({editor:n,tr:r})=>{let{state:i}=n,s=i.doc.slice(e.from,e.to);r.deleteRange(e.from,e.to);let o=r.mapping.map(t);return r.insert(o,s.content),r.setSelection(new od(r.doc.resolve(Math.max(o-1,0)))),!0},dB=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;let i=e.selection.$anchor;for(let n=i.depth;n>0;n-=1)if(i.node(n).type===r.type){if(t){let t=i.before(n),r=i.after(n);e.delete(t,r).scrollIntoView()}return!0}return!1};function dF(e,t){if("string"==typeof e){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}var dH=e=>({tr:t,state:n,dispatch:r})=>{let i=dF(e,n.schema),s=t.selection.$anchor;for(let e=s.depth;e>0;e-=1)if(s.node(e).type===i){if(r){let n=s.before(e),r=s.after(e);t.delete(n,r).scrollIntoView()}return!0}return!1},dU=e=>({tr:t,dispatch:n})=>{let{from:r,to:i}=e;return n&&t.delete(r,i),!0},dV=(e,t,n)=>{var r;return!e.parent.isInline||"left"===n&&e.pos>e.start()||"right"===n&&e.pos<e.end()?e.pos:(r=t.nodes[e.parent.type.name].spec).content&&/^text(\*|\+)/.test(r.content)?"left"===n?e.start()-1:e.end()+1:e.pos},dW=()=>({state:e,dispatch:t})=>{var n;let{$from:r,$to:i}=e.selection;if(e.selection.empty)return!1;let{from:s,to:o}={from:dV(r,n=e.schema,"left"),to:dV(i,n,"right")};return t&&(e.tr.deleteRange(s,o).scrollIntoView(),t(e.tr)),!0},dq=()=>({commands:e})=>e.keyboardShortcut("Enter"),dK=()=>({state:e,dispatch:t})=>dg(e,t);function dG(e){return"[object RegExp]"===Object.prototype.toString.call(e)}function dJ(e,t,n={strict:!0}){let r=Object.keys(t);return!r.length||r.every(r=>n.strict?t[r]===e[r]:dG(t[r])?t[r].test(e[r]):t[r]===e[r])}function dZ(e,t,n={}){return e.find(e=>e.type===t&&dJ(Object.fromEntries(Object.keys(n).map(t=>[t,e.attrs[t]])),n))}function dX(e,t,n={}){return!!dZ(e,t,n)}function dY(e,t,n){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if(r.node&&r.node.marks.some(e=>e.type===t)||(r=e.parent.childBefore(e.parentOffset)),!r.node||!r.node.marks.some(e=>e.type===t))return;if(!n){let e=r.node.marks.find(e=>e.type===t);e&&(n=e.attrs)}if(!dZ([...r.node.marks],t,n))return;let i=r.index,s=e.start()+r.offset,o=i+1,a=s+r.node.nodeSize;for(;i>0&&dX([...e.parent.child(i-1).marks],t,n);)i-=1,s-=e.parent.child(i).nodeSize;for(;o<e.parent.childCount&&dX([...e.parent.child(o).marks],t,n);)a+=e.parent.child(o).nodeSize,o+=1;return{from:s,to:a}}function dQ(e,t){if("string"==typeof e){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}var d0=(e,t)=>({tr:n,state:r,dispatch:i})=>{let s=dQ(e,r.schema),{doc:o,selection:a}=n,{$from:l,from:c,to:d}=a;if(i){let e=dY(l,s,t);if(e&&e.from<=c&&e.to>=d){let t=od.create(o,e.from,e.to);n.setSelection(t)}}return!0},d1=e=>t=>{let n="function"==typeof e?e(t):e;for(let e=0;e<n.length;e+=1)if(n[e](t))return!0;return!1};function d2(e){return e instanceof od}function d5(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function d3(e,t=null){if(!t)return null;let n=oo.atStart(e),r=oo.atEnd(e);if("start"===t||!0===t)return n;if("end"===t)return r;let i=n.from,s=r.to;return"all"===t?od.create(e,d5(0,i,s),d5(e.content.size,i,s)):od.create(e,d5(t,i,s),d5(t,i,s))}function d4(){return"Android"===navigator.platform||/android/i.test(navigator.userAgent)}function d6(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}var d9=(e=null,t={})=>({editor:n,view:r,tr:i,dispatch:s})=>{t={scrollIntoView:!0,...t};let o=()=>{(d6()||d4())&&r.dom.focus(),"u">typeof navigator&&/^((?!chrome|android).)*safari/i.test(navigator.userAgent)&&!d6()&&!d4()&&r.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{!n.isDestroyed&&(r.focus(),(null==t?void 0:t.scrollIntoView)&&n.commands.scrollIntoView())})};try{if(r.hasFocus()&&null===e||!1===e)return!0}catch{return!1}if(s&&null===e&&!d2(n.state.selection))return o(),!0;let a=d3(i.doc,e)||n.state.selection,l=n.state.selection.eq(a);return s&&(l||i.setSelection(a),l&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},d7=(e,t)=>n=>e.every((e,r)=>t(e,{...n,index:r})),d8=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),ue=e=>{let t=e.childNodes;for(let n=t.length-1;n>=0;n-=1){let r=t[n];3===r.nodeType&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?e.removeChild(r):1===r.nodeType&&ue(r)}return e};function ut(e){if("u"<typeof window)throw Error("[tiptap error]: there is no window object available, so this function cannot be used");let t=`<body>${e}</body>`;return ue(new window.DOMParser().parseFromString(t,"text/html").body)}function un(e,t,n){if(e instanceof se||e instanceof iW)return e;n={slice:!0,parseOptions:{},...n};let r="object"==typeof e&&null!==e,i="string"==typeof e;if(r)try{if(Array.isArray(e)&&e.length>0)return iW.fromArray(e.map(e=>t.nodeFromJSON(e)));let r=t.nodeFromJSON(e);return n.errorOnInvalidContent&&r.check(),r}catch(r){if(n.errorOnInvalidContent)throw Error("[tiptap error]: Invalid JSON content",{cause:r});return console.warn("[tiptap warn]: Invalid content.","Passed value:",e,"Error:",r),un("",t,n)}if(i){if(n.errorOnInvalidContent){let r=!1,i="",s=new sf({topNode:t.spec.topNode,marks:t.spec.marks,nodes:t.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:e=>(r=!0,i="string"==typeof e?e:e.outerHTML,null)}]}})});if(n.slice?sx.fromSchema(s).parseSlice(ut(e),n.parseOptions):sx.fromSchema(s).parse(ut(e),n.parseOptions),n.errorOnInvalidContent&&r)throw Error("[tiptap error]: Invalid HTML content",{cause:Error(`Invalid element found: ${i}`)})}let r=sx.fromSchema(t);return n.slice?r.parseSlice(ut(e),n.parseOptions).content:r.parse(ut(e),n.parseOptions)}return un("",t,n)}var ur=(e,t,n)=>({tr:r,dispatch:i,editor:s})=>{var o;if(i){let i,a;n={parseOptions:s.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let l=e=>{s.emit("contentError",{editor:s,error:e,disableCollaboration:()=>{"collaboration"in s.storage&&"object"==typeof s.storage.collaboration&&s.storage.collaboration&&(s.storage.collaboration.isDisabled=!0)}})},c={preserveWhitespace:"full",...n.parseOptions};if(!n.errorOnInvalidContent&&!s.options.enableContentCheck&&s.options.emitContentError)try{un(t,s.schema,{parseOptions:c,errorOnInvalidContent:!0})}catch(e){l(e)}try{i=un(t,s.schema,{parseOptions:c,errorOnInvalidContent:null!=(o=n.errorOnInvalidContent)?o:s.options.enableContentCheck})}catch(e){return l(e),!1}let{from:d,to:u}="number"==typeof e?{from:e,to:e}:{from:e.from,to:e.to},p=!0,h=!0;if((!("type"in i)?i:[i]).forEach(e=>{e.check(),p=!!p&&e.isText&&0===e.marks.length,h=!!h&&e.isBlock}),d===u&&h){let{parent:e}=r.doc.resolve(d);!e.isTextblock||e.type.spec.code||e.childCount||(d-=1,u+=1)}if(p){if(Array.isArray(t))a=t.map(e=>e.text||"").join("");else if(t instanceof iW){let e="";t.forEach(t=>{t.text&&(e+=t.text)}),a=e}else a="object"==typeof t&&t&&t.text?t.text:t;r.insertText(a,d,u)}else{a=i;let e=r.doc.resolve(d),t=e.node(),n=0===e.parentOffset,s=t.isText||t.isTextblock,o=t.content.size>0;n&&s&&o&&h&&(d=Math.max(0,d-1)),r.replaceWith(d,u,a)}n.updateSelection&&function(e,t){let n=e.steps.length-1;if(n<t)return;let r=e.steps[n];if(!(r instanceof sH||r instanceof sU))return;let i=e.mapping.maps[n],s=0;i.forEach((e,t,n,r)=>{0===s&&(s=r)}),e.setSelection(oo.near(e.doc.resolve(s),-1))}(r,r.steps.length-1),n.applyInputRules&&r.setMeta("applyInputRules",{from:d,text:a}),n.applyPasteRules&&r.setMeta("applyPasteRules",{from:d,text:a})}return!0},ui=()=>({state:e,dispatch:t})=>((e,t)=>{let n=e.selection,r=n instanceof op,i;if(r){if(n.node.isTextblock||!sY(e.doc,n.from))return!1;i=n.from}else if(null==(i=s0(e.doc,n.from,-1)))return!1;if(t){let n=e.tr.join(i);r&&n.setSelection(op.create(n.doc,i-e.doc.resolve(i).nodeBefore.nodeSize)),t(n.scrollIntoView())}return!0})(e,t),us=()=>({state:e,dispatch:t})=>((e,t)=>{let n=e.selection,r;if(n instanceof op){if(n.node.isTextblock||!sY(e.doc,n.to))return!1;r=n.to}else if(null==(r=s0(e.doc,n.to,1)))return!1;return t&&t(e.tr.join(r).scrollIntoView()),!0})(e,t),uo=()=>({state:e,dispatch:t})=>di(e,t),ua=()=>({state:e,dispatch:t})=>du(e,t),ul=()=>({state:e,dispatch:t,tr:n})=>{try{let r=s0(e.doc,e.selection.$from.pos,-1);if(null==r)return!1;return n.join(r,2),t&&t(n),!0}catch{return!1}},uc=()=>({state:e,dispatch:t,tr:n})=>{try{let r=s0(e.doc,e.selection.$from.pos,1);if(null==r)return!1;return n.join(r,2),t&&t(n),!0}catch{return!1}},ud=()=>({state:e,dispatch:t})=>((e,t,n)=>{let r=dr(e,n);if(!r)return!1;let i=dc(r);return!!i&&ds(e,i,t)})(e,t),uu=()=>({state:e,dispatch:t})=>((e,t,n)=>{let r=dd(e,n);if(!r)return!1;let i=dh(r);return!!i&&ds(e,i,t)})(e,t);function up(){return"u">typeof navigator&&/Mac/.test(navigator.platform)}var uh=e=>({editor:t,view:n,tr:r,dispatch:i})=>{let s=(function(e){let t,n,r,i,s=e.split(/-(?!$)/),o=s[s.length-1];"Space"===o&&(o=" ");for(let e=0;e<s.length-1;e+=1){let o=s[e];if(/^(cmd|meta|m)$/i.test(o))i=!0;else if(/^a(lt)?$/i.test(o))t=!0;else if(/^(c|ctrl|control)$/i.test(o))n=!0;else if(/^s(hift)?$/i.test(o))r=!0;else if(/^mod$/i.test(o))d6()||up()?i=!0:n=!0;else throw Error(`Unrecognized modifier name: ${o}`)}return t&&(o=`Alt-${o}`),n&&(o=`Ctrl-${o}`),i&&(o=`Meta-${o}`),r&&(o=`Shift-${o}`),o})(e).split(/-(?!$)/),o=s.find(e=>!["Alt","Ctrl","Meta","Shift"].includes(e)),a=new KeyboardEvent("keydown",{key:"Space"===o?" ":o,altKey:s.includes("Alt"),ctrlKey:s.includes("Ctrl"),metaKey:s.includes("Meta"),shiftKey:s.includes("Shift"),bubbles:!0,cancelable:!0}),l=t.captureTransaction(()=>{n.someProp("handleKeyDown",e=>e(n,a))});return null==l||l.steps.forEach(e=>{let t=e.map(r.mapping);t&&i&&r.maybeStep(t)}),!0};function um(e,t,n={}){let{from:r,to:i,empty:s}=e.selection,o=t?dF(t,e.schema):null,a=[];e.doc.nodesBetween(r,i,(e,t)=>{if(e.isText)return;let n=Math.max(r,t),s=Math.min(i,t+e.nodeSize);a.push({node:e,from:n,to:s})});let l=i-r,c=a.filter(e=>!o||o.name===e.node.type.name).filter(e=>dJ(e.node.attrs,n,{strict:!1}));return s?!!c.length:c.reduce((e,t)=>e+t.to-t.from,0)>=l}var uf=(e,t={})=>({state:n,dispatch:r})=>{let i=dF(e,n.schema);return!!um(n,i,t)&&((e,t)=>{let{$from:n,$to:r}=e.selection,i=n.blockRange(r),s=i&&sq(i);return null!=s&&(t&&t(e.tr.lift(i,s).scrollIntoView()),!0)})(n,r)},ug=()=>({state:e,dispatch:t})=>db(e,t),ux=e=>({state:t,dispatch:n})=>{var r;return(r=dF(e,t.schema),function(e,t){let{$from:n,$to:i}=e.selection,s=n.blockRange(i,e=>e.childCount>0&&e.firstChild.type==r);return!!s&&(!t||(n.node(s.depth-1).type==r?function(e,t,n,r){let i=e.tr,s=r.end,o=r.$to.end(r.depth);s<o&&(i.step(new sU(s-1,o,s,o,new iX(iW.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new i7(i.doc.resolve(r.$from.pos),i.doc.resolve(o),r.depth));let a=sq(r);if(null==a)return!1;i.lift(r,a);let l=i.doc.resolve(i.mapping.map(s,-1)-1);return sY(i.doc,l.pos)&&l.nodeBefore.type==l.nodeAfter.type&&i.join(l.pos),t(i.scrollIntoView()),!0}(e,t,r,s):function(e,t,n){let r=e.tr,i=n.parent;for(let e=n.end,t=n.endIndex-1,s=n.startIndex;t>s;t--)e-=i.child(t).nodeSize,r.delete(e-1,e+1);let s=r.doc.resolve(n.start),o=s.nodeAfter;if(r.mapping.map(n.end)!=n.start+s.nodeAfter.nodeSize)return!1;let a=0==n.startIndex,l=n.endIndex==i.childCount,c=s.node(-1),d=s.index(-1);if(!c.canReplace(d+ +!a,d+1,o.content.append(l?iW.empty:iW.from(i))))return!1;let u=s.pos,p=u+o.nodeSize;return r.step(new sU(u-!!a,p+ +!!l,u+1,p-1,new iX((a?iW.empty:iW.from(i.copy(iW.empty))).append(l?iW.empty:iW.from(i.copy(iW.empty))),+!a,+!l),+!a)),t(r.scrollIntoView()),!0}(e,t,s)))})(t,n)},ub=()=>({state:e,dispatch:t})=>dm(e,t);function uy(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function uv(e,t){let n="string"==typeof t?[t]:t;return Object.keys(e).reduce((t,r)=>(n.includes(r)||(t[r]=e[r]),t),{})}var uw=(e,t)=>({tr:n,state:r,dispatch:i})=>{let s=null,o=null,a=uy("string"==typeof e?e:e.name,r.schema);if(!a)return!1;"node"===a&&(s=dF(e,r.schema)),"mark"===a&&(o=dQ(e,r.schema));let l=!1;return n.selection.ranges.forEach(e=>{r.doc.nodesBetween(e.$from.pos,e.$to.pos,(e,r)=>{s&&s===e.type&&(l=!0,i&&n.setNodeMarkup(r,void 0,uv(e.attrs,t))),o&&e.marks.length&&e.marks.forEach(s=>{o===s.type&&(l=!0,i&&n.addMark(r,r+e.nodeSize,o.create(uv(s.attrs,t))))})})}),l},uk=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),uN=()=>({tr:e,dispatch:t})=>{if(t){let t=new om(e.doc);e.setSelection(t)}return!0},uS=()=>({state:e,dispatch:t})=>dl(e,t),uC=()=>({state:e,dispatch:t})=>dp(e,t),uj=()=>({state:e,dispatch:t})=>((e,t)=>{let{$from:n,to:r}=e.selection,i,s=n.sharedDepth(r);return 0!=s&&(i=n.before(s),t&&t(e.tr.setSelection(op.create(e.doc,i))),!0)})(e,t),uE=()=>({state:e,dispatch:t})=>dk(e,t),uM=()=>({state:e,dispatch:t})=>dw(e,t);function uA(e,t,n={},r={}){return un(e,t,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}var uT=(e,{errorOnInvalidContent:t,emitUpdate:n=!0,parseOptions:r={}}={})=>({editor:i,tr:s,dispatch:o,commands:a})=>{let{doc:l}=s;if("full"!==r.preserveWhitespace){let a=uA(e,i.schema,r,{errorOnInvalidContent:null!=t?t:i.options.enableContentCheck});return o&&s.replaceWith(0,l.content.size,a).setMeta("preventUpdate",!n),!0}return o&&s.setMeta("preventUpdate",!n),a.insertContentAt({from:0,to:l.content.size},e,{parseOptions:r,errorOnInvalidContent:null!=t?t:i.options.enableContentCheck})};function uO(e,t){let n=dQ(t,e.schema),{from:r,to:i,empty:s}=e.selection,o=[];s?(e.storedMarks&&o.push(...e.storedMarks),o.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,i,e=>{o.push(...e.marks)});let a=o.find(e=>e.type.name===n.name);return a?{...a.attrs}:{}}function u_(e,t){let n=new or(e);return t.forEach(e=>{e.steps.forEach(e=>{n.step(e)})}),n}function uD(e,t){let n=[];return e.descendants((e,r)=>{t(e)&&n.push({node:e,pos:r})}),n}function uR(e,t){for(let n=e.depth;n>0;n-=1){let r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function uI(e){return t=>uR(t.$from,e)}function uL(e,t,n){return void 0===e.config[t]&&e.parent?uL(e.parent,t,n):"function"==typeof e.config[t]?e.config[t].bind({...n,parent:e.parent?uL(e.parent,t,n):null}):e.config[t]}function uP(e){return e.map(e=>{let t={name:e.name,options:e.options,storage:e.storage},n=uL(e,"addExtensions",t);return n?[e,...uP(n())]:e}).flat(10)}function u$(e,t){let n=sj.fromSchema(t).serializeFragment(e),r=document.implementation.createHTMLDocument().createElement("div");return r.appendChild(n),r.innerHTML}function uz(e){return"function"==typeof e}function uB(e,t,...n){return uz(e)?t?e.bind(t)(...n):e(...n):e}function uF(e){let t=e.filter(e=>"extension"===e.type);return{baseExtensions:t,nodeExtensions:e.filter(e=>"node"===e.type),markExtensions:e.filter(e=>"mark"===e.type)}}function uH(e){let t=[],{nodeExtensions:n,markExtensions:r}=uF(e),i=[...n,...r],s={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1},o=n.filter(e=>"text"!==e.name).map(e=>e.name),a=r.map(e=>e.name),l=[...o,...a];return e.forEach(e=>{let n={name:e.name,options:e.options,storage:e.storage,extensions:i},r=uL(e,"addGlobalAttributes",n);r&&r().forEach(e=>{(Array.isArray(e.types)?e.types:"*"===e.types?l:"nodes"===e.types?o:"marks"===e.types?a:[]).forEach(n=>{Object.entries(e.attributes).forEach(([e,r])=>{t.push({type:n,name:e,attribute:{...s,...r}})})})})}),i.forEach(e=>{let n={name:e.name,options:e.options,storage:e.storage},r=uL(e,"addAttributes",n);r&&Object.entries(r()).forEach(([n,r])=>{let i={...s,...r};"function"==typeof(null==i?void 0:i.default)&&(i.default=i.default()),(null==i?void 0:i.isRequired)&&(null==i?void 0:i.default)===void 0&&delete i.default,t.push({type:e.name,name:n,attribute:i})})}),t}function uU(e){let t=[],n=function(e){let t=[],n="",r=!1,i=!1,s=0,o=e.length;for(let a=0;a<o;a+=1){let o=e[a];if("'"===o&&!i){r=!r,n+=o;continue}if('"'===o&&!r){i=!i,n+=o;continue}if(!r&&!i){if("("===o){s+=1,n+=o;continue}if(")"===o&&s>0){s-=1,n+=o;continue}if(";"===o&&0===s){t.push(n),n="";continue}}n+=o}return n&&t.push(n),t}(e||""),r=n.length;for(let e=0;e<r;e+=1){let r=n[e],i=r.indexOf(":");if(-1===i)continue;let s=r.slice(0,i).trim(),o=r.slice(i+1).trim();s&&o&&t.push([s,o])}return t}function uV(...e){return e.filter(e=>!!e).reduce((e,t)=>{let n={...e};return Object.entries(t).forEach(([e,t])=>{if(!n[e]){n[e]=t;return}if("class"===e){let r=t?String(t).split(" "):[],i=n[e]?n[e].split(" "):[],s=r.filter(e=>!i.includes(e));n[e]=[...i,...s].join(" ")}else if("style"===e){let r=new Map([...uU(n[e]),...uU(t)]);n[e]=Array.from(r.entries()).map(([e,t])=>`${e}: ${t}`).join("; ")}else n[e]=t}),n},{})}function uW(e,t){return t.filter(t=>t.type===e.type.name).filter(e=>e.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(e.attrs)||{}:{[t.name]:e.attrs[t.name]}).reduce((e,t)=>uV(e,t),{})}function uq(e,t){return"style"in e?e:{...e,getAttrs:n=>{let r=e.getAttrs?e.getAttrs(n):e.attrs;if(!1===r)return!1;let i=t.reduce((e,t)=>{var r;let i=t.attribute.parseHTML?t.attribute.parseHTML(n):"string"!=typeof(r=n.getAttribute(t.name))?r:r.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(r):"true"===r||"false"!==r&&r;return null==i?e:{...e,[t.name]:i}},{});return{...r,...i}}}}function uK(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>!("attrs"===e&&function(e={}){return 0===Object.keys(e).length&&e.constructor===Object}(t))&&null!=t))}function uG(e){var t,n;let r={};return!(null==(t=null==e?void 0:e.attribute)?void 0:t.isRequired)&&"default"in((null==e?void 0:e.attribute)||{})&&(r.default=e.attribute.default),(null==(n=null==e?void 0:e.attribute)?void 0:n.validate)!==void 0&&(r.validate=e.attribute.validate),[e.name,r]}function uJ(e){return e.sort((e,t)=>{let n=uL(e,"priority")||100,r=uL(t,"priority")||100;return n>r?-1:+(n<r)})}function uZ(e){var t;let n=uJ(uP(e)),r=Array.from(new Set((t=n.map(e=>e.name)).filter((e,n)=>t.indexOf(e)!==n)));return r.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${r.map(e=>`'${e}'`).join(", ")}]. This can lead to issues.`),n}function uX(e,t,n){let{from:r,to:i}=t,{blockSeparator:s="\n\n",textSerializers:o={}}=n||{},a="";return e.nodesBetween(r,i,(e,n,l,c)=>{var d;e.isBlock&&n>r&&(a+=s);let u=null==o?void 0:o[e.type.name];if(u)return l&&(a+=u({node:e,pos:n,parent:l,index:c,range:t})),!1;e.isText&&(a+=null==(d=null==e?void 0:e.text)?void 0:d.slice(Math.max(r,n)-n,i-n))}),a}function uY(e,t){let n={from:0,to:e.content.size};return uX(e,n,t)}function uQ(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function u0(e,t){let n=uy("string"==typeof t?t:t.name,e.schema);return"node"===n?function(e,t){let n=dF(t,e.schema),{from:r,to:i}=e.selection,s=[];e.doc.nodesBetween(r,i,e=>{s.push(e)});let o=s.reverse().find(e=>e.type.name===n.name);return o?{...o.attrs}:{}}(e,t):"mark"===n?uO(e,t):{}}function u1(e){let t,{mapping:n,steps:r}=e,i=[];return n.maps.forEach((e,t)=>{let s=[];if(e.ranges.length)e.forEach((e,t)=>{s.push({from:e,to:t})});else{let{from:e,to:n}=r[t];if(void 0===e||void 0===n)return;s.push({from:e,to:n})}s.forEach(({from:e,to:r})=>{let s=n.slice(t).map(e,-1),o=n.slice(t).map(r),a=n.invert().map(s,-1),l=n.invert().map(o);i.push({oldRange:{from:a,to:l},newRange:{from:s,to:o}})})}),1===(t=function(e,t=JSON.stringify){let n={};return e.filter(e=>{let r=t(e);return!Object.prototype.hasOwnProperty.call(n,r)&&(n[r]=!0)})}(i)).length?t:t.filter((e,n)=>!t.filter((e,t)=>t!==n).some(t=>e.oldRange.from>=t.oldRange.from&&e.oldRange.to<=t.oldRange.to&&e.newRange.from>=t.newRange.from&&e.newRange.to<=t.newRange.to))}function u2(e,t,n){let r=[];return e===t?n.resolve(e).marks().forEach(t=>{let i=dY(n.resolve(e),t.type);i&&r.push({mark:t,...i})}):n.nodesBetween(e,t,(e,t)=>{e&&(null==e?void 0:e.nodeSize)!==void 0&&r.push(...e.marks.map(n=>({from:t,to:t+e.nodeSize,mark:n})))}),r}function u5(e,t){return t.nodes[e]||t.marks[e]||null}function u3(e,t,n){return Object.fromEntries(Object.entries(n).filter(([n])=>{let r=e.find(e=>e.type===t&&e.name===n);return!!r&&r.attribute.keepOnSplit}))}function u4(e,t,n={}){let{empty:r,ranges:i}=e.selection,s=t?dQ(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(e=>!s||s.name===e.type.name).find(e=>dJ(e.attrs,n,{strict:!1}));let o=0,a=[];if(i.forEach(({$from:t,$to:n})=>{let r=t.pos,i=n.pos;e.doc.nodesBetween(r,i,(e,t)=>{if(s&&e.inlineContent&&!e.type.allowsMarkType(s))return!1;if(!e.isText&&!e.marks.length)return;let n=Math.max(r,t),l=Math.min(i,t+e.nodeSize);o+=l-n,a.push(...e.marks.map(e=>({mark:e,from:n,to:l})))})}),0===o)return!1;let l=a.filter(e=>!s||s.name===e.mark.type.name).filter(e=>dJ(e.mark.attrs,n,{strict:!1})).reduce((e,t)=>e+t.to-t.from,0),c=a.filter(e=>!s||e.mark.type!==s&&e.mark.type.excludes(s)).reduce((e,t)=>e+t.to-t.from,0);return(l>0?l+c:l)>=o}function u6(e,t){return Array.isArray(t)?t.some(t=>("string"==typeof t?t:t.name)===e.name):t}function u9(e,t){let{nodeExtensions:n}=uF(t),r=n.find(t=>t.name===e);if(!r)return!1;let i={name:r.name,options:r.options,storage:r.storage},s=uB(uL(r,"group",i));return"string"==typeof s&&s.split(" ").includes("list")}function u7(e,{checkChildren:t=!0,ignoreWhitespace:n=!1}={}){var r;if(n){if("hardBreak"===e.type.name)return!0;if(e.isText)return!/\S/.test(null!=(r=e.text)?r:"")}if(e.isText)return!e.text;if(e.isAtom||e.isLeaf)return!1;if(0===e.content.childCount)return!0;if(t){let r=!0;return e.content.forEach(e=>{!1!==r&&(u7(e,{ignoreWhitespace:n,checkChildren:t})||(r=!1))}),r}return!1}function u8(e){return e instanceof op}var pe=class e{constructor(e){this.position=e}static fromJSON(t){return new e(t.position)}toJSON(){return{position:this.position}}};function pt(e,t){let n=t.mapping.mapResult(e.position);return{position:new pe(n.pos),mapResult:n}}function pn(e){return new pe(e)}function pr(e,t,n){let r=e.state.doc.content.size,i=d5(t,0,r),s=d5(n,0,r),o=e.coordsAtPos(i),a=e.coordsAtPos(s,-1),l=Math.min(o.top,a.top),c=Math.max(o.bottom,a.bottom),d=Math.min(o.left,a.left),u=Math.max(o.right,a.right),p={top:l,bottom:c,left:d,right:u,width:u-d,height:c-l,x:d,y:l};return{...p,toJSON:()=>p}}var pi=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{selection:s}=n,{empty:o,ranges:a}=s,l=dQ(e,r.schema);if(i)if(o){let e=uO(r,l);n.addStoredMark(l.create({...e,...t}))}else a.forEach(e=>{let i=e.$from.pos,s=e.$to.pos;r.doc.nodesBetween(i,s,(e,r)=>{let o=Math.max(r,i),a=Math.min(r+e.nodeSize,s);e.marks.find(e=>e.type===l)?e.marks.forEach(e=>{l===e.type&&n.addMark(o,a,l.create({...e.attrs,...t}))}):n.addMark(o,a,l.create(t))})});return function(e,t,n){var r;let{selection:i}=t,s=null;if(d2(i)&&(s=i.$cursor),s){let t=null!=(r=e.storedMarks)?r:s.marks();return s.parent.type.allowsMarkType(n)&&(!!n.isInSet(t)||!t.some(e=>e.type.excludes(n)))}let{ranges:o}=i;return o.some(({$from:t,$to:r})=>{let i=0===t.depth&&e.doc.inlineContent&&e.doc.type.allowsMarkType(n);return e.doc.nodesBetween(t.pos,r.pos,(e,t,r)=>{if(i)return!1;if(e.isInline){let t=!r||r.type.allowsMarkType(n),s=!!n.isInSet(e.marks)||!e.marks.some(e=>e.type.excludes(n));i=t&&s}return!i}),i})}(r,n,l)},ps=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),po=(e,t={})=>({state:n,dispatch:r,chain:i})=>{let s,o=dF(e,n.schema);return(n.selection.$anchor.sameParent(n.selection.$head)&&(s=n.selection.$anchor.parent.attrs),o.isTextblock)?i().command(({commands:e})=>!!dN(o,{...s,...t})(n)||e.clearNodes()).command(({state:e})=>dN(o,{...s,...t})(e,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},pa=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,r=d5(e,0,n.content.size),i=op.create(n,r);t.setSelection(i)}return!0},pl=(e,t)=>({tr:n,state:r,dispatch:i})=>{let s,o,{selection:a}=r;return"number"==typeof t?(s=t,o=t):t&&"from"in t&&"to"in t?(s=t.from,o=t.to):(s=a.from,o=a.to),i&&n.doc.nodesBetween(s,o,(t,r)=>{t.isText||n.setNodeMarkup(r,void 0,{...t.attrs,dir:e})}),!0},pc=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,{from:r,to:i}="number"==typeof e?{from:e,to:e}:e,s=od.atStart(n).from,o=od.atEnd(n).to,a=d5(r,s,o),l=d5(i,s,o),c=od.create(n,a,l);t.setSelection(c)}return!0},pd=e=>({state:t,dispatch:n})=>{var r;return(r=dF(e,t.schema),function(e,t){let{$from:n,$to:i}=e.selection,s=n.blockRange(i,e=>e.childCount>0&&e.firstChild.type==r);if(!s)return!1;let o=s.startIndex;if(0==o)return!1;let a=s.parent,l=a.child(o-1);if(l.type!=r)return!1;if(t){let n=l.lastChild&&l.lastChild.type==a.type,i=iW.from(n?r.create():null),o=new iX(iW.from(r.create(null,iW.from(a.type.create(null,i)))),n?3:1,0),c=s.start,d=s.end;t(e.tr.step(new sU(c-(n?3:1),d,c,d,o,1,!0)).scrollIntoView())}return!0})(t,n)};function pu(e,t){let n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){let r=n.filter(e=>null==t?void 0:t.includes(e.type.name));e.tr.ensureMarks(r)}}var pp=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{let{selection:s,doc:o}=t,{$from:a,$to:l}=s,c=u3(i.extensionManager.attributes,a.node().type.name,a.node().attrs);if(s instanceof op&&s.node.isBlock)return!!a.parentOffset&&!!sX(o,a.pos)&&(r&&(e&&pu(n,i.extensionManager.splittableMarks),t.split(a.pos).scrollIntoView()),!0);if(!a.parent.isBlock)return!1;let d=l.parentOffset===l.parent.content.size,u=0===a.depth?void 0:function(e){for(let t=0;t<e.edgeCount;t+=1){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}(a.node(-1).contentMatchAt(a.indexAfter(-1))),p=d&&u?[{type:u,attrs:c}]:void 0,h=sX(t.doc,t.mapping.map(a.pos),1,p);if(!p&&!h&&sX(t.doc,t.mapping.map(a.pos),1,u?[{type:u}]:void 0)&&(h=!0,p=u?[{type:u,attrs:c}]:void 0),r){if(h&&(s instanceof od&&t.deleteSelection(),t.split(t.mapping.map(a.pos),1,p),u&&!d&&!a.parentOffset&&a.parent.type!==u)){let e=t.mapping.map(a.before()),n=t.doc.resolve(e);a.node(-1).canReplaceWith(n.index(),n.index()+1,u)&&t.setNodeMarkup(t.mapping.map(a.before()),u)}e&&pu(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return h},ph=(e,t={})=>({tr:n,state:r,dispatch:i,editor:s})=>{var o;let a=dF(e,r.schema),{$from:l,$to:c}=r.selection,d=r.selection.node;if(d&&d.isBlock||l.depth<2||!l.sameParent(c))return!1;let u=l.node(-1);if(u.type!==a)return!1;let p=s.extensionManager.attributes;if(0===l.parent.content.size&&l.node(-1).childCount===l.indexAfter(-1)){if(2===l.depth||l.node(-3).type!==a||l.index(-2)!==l.node(-2).childCount-1)return!1;if(i){let e=iW.empty,r=l.index(-1)?1:l.index(-2)?2:3;for(let t=l.depth-r;t>=l.depth-3;t-=1)e=iW.from(l.node(t).copy(e));let i=l.indexAfter(-1)<l.node(-2).childCount?1:l.indexAfter(-2)<l.node(-3).childCount?2:3,s={...u3(p,l.node().type.name,l.node().attrs),...t},c=(null==(o=a.contentMatch.defaultType)?void 0:o.createAndFill(s))||void 0;e=e.append(iW.from(a.createAndFill(null,c)||void 0));let d=l.before(l.depth-(r-1));n.replace(d,l.after(-i),new iX(e,4-r,0));let u=-1;n.doc.nodesBetween(d,n.doc.content.size,(e,t)=>{if(u>-1)return!1;e.isTextblock&&0===e.content.size&&(u=t+1)}),u>-1&&n.setSelection(od.near(n.doc.resolve(u))),n.scrollIntoView()}return!0}let h=c.pos===l.end()?u.contentMatchAt(0).defaultType:null,m={...u3(p,u.type.name,u.attrs),...t},f={...u3(p,l.node().type.name,l.node().attrs),...t};n.delete(l.pos,c.pos);let g=h?[{type:a,attrs:m},{type:h,attrs:f}]:[{type:a,attrs:m}];if(!sX(n.doc,l.pos,2))return!1;if(i){let{selection:e,storedMarks:t}=r,{splittableMarks:o}=s.extensionManager,a=t||e.$to.parentOffset&&e.$from.marks();if(n.split(l.pos,2,g).scrollIntoView(),!a||!i)return!0;let c=a.filter(e=>o.includes(e.type.name));n.ensureMarks(c)}return!0},pm=(e,t)=>{let n=uI(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(void 0===r)return!0;let i=e.doc.nodeAt(r);return!(n.node.type===(null==i?void 0:i.type)&&sY(e.doc,n.pos))||(e.join(n.pos),!0)},pf=(e,t)=>{let n=uI(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(n.start).after(n.depth);if(void 0===r)return!0;let i=e.doc.nodeAt(r);return!(n.node.type===(null==i?void 0:i.type)&&sY(e.doc,r))||(e.join(r),!0)},pg=(e,t,n,r={})=>({editor:i,tr:s,state:o,dispatch:a,chain:l,commands:c,can:d})=>{let{extensions:u,splittableMarks:p}=i.extensionManager,h=dF(e,o.schema),m=dF(t,o.schema),{selection:f,storedMarks:g}=o,{$from:x,$to:b}=f,y=x.blockRange(b),v=g||f.$to.parentOffset&&f.$from.marks();if(!y)return!1;let w=uI(e=>u9(e.type.name,u))(f),k=0===f.from&&f.to===o.doc.content.size,N=o.doc.content.content,S=1===N.length?N[0]:null,C=k&&S&&u9(S.type.name,u)?{node:S,pos:0,depth:0}:null,j=null!=w?w:C,E=!!w&&y.depth>=1&&y.depth-w.depth<=1,M=!!C;if((E||M)&&j){if(j.node.type===h)return k&&M?l().command(({tr:e,dispatch:t})=>{let n=function(e){let t=e.doc,n=t.firstChild;if(!n)return null;let r=t.resolve(1),i=t.resolve(n.nodeSize-1);return od.between(r,i)}(e);return!!n&&(e.setSelection(n),t&&t(e),!0)}).liftListItem(m).run():c.liftListItem(m);if(u9(j.node.type.name,u)&&h.validContent(j.node.content))return l().command(()=>(s.setNodeMarkup(j.pos,h),!0)).command(()=>pm(s,h)).command(()=>pf(s,h)).run()}return n&&v&&a?l().command(()=>{let e=d().wrapInList(h,r),t=v.filter(e=>p.includes(e.type.name));return s.ensureMarks(t),!!e||c.clearNodes()}).wrapInList(h,r).command(()=>pm(s,h)).command(()=>pf(s,h)).run():l().command(()=>!!d().wrapInList(h,r)||c.clearNodes()).wrapInList(h,r).command(()=>pm(s,h)).command(()=>pf(s,h)).run()},px=(e,t={},n={})=>({state:r,commands:i})=>{let{extendEmptyMarkRange:s=!1}=n,o=dQ(e,r.schema);return u4(r,o,t)?i.unsetMark(o,{extendEmptyMarkRange:s}):i.setMark(o,t)},pb=(e,t,n={})=>({state:r,commands:i})=>{let s,o=dF(e,r.schema),a=dF(t,r.schema),l=um(r,o,n);return(r.selection.$anchor.sameParent(r.selection.$head)&&(s=r.selection.$anchor.parent.attrs),l)?i.setNode(a,s):i.setNode(o,{...s,...n})},py=(e,t={})=>({state:n,commands:r})=>{let i=dF(e,n.schema);return um(n,i,t)?r.lift(i):r.wrapIn(i,t)},pv=()=>({state:e,dispatch:t})=>{let n=e.plugins;for(let r=0;r<n.length;r+=1){let i,s=n[r];if(s.spec.isInputRules&&(i=s.getState(e))){if(t){let t=e.tr,n=i.transform;for(let e=n.steps.length-1;e>=0;e-=1)t.step(n.steps[e].invert(n.docs[e]));if(i.text){let n=t.doc.resolve(i.from).marks();t.replaceWith(i.from,i.to,e.schema.text(i.text,n))}else t.delete(i.from,i.to)}return!0}}return!1},pw=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,{empty:r,ranges:i}=n;return!!r||(t&&i.forEach(t=>{e.removeMark(t.$from.pos,t.$to.pos)}),!0)},pk=(e,t={})=>({tr:n,state:r,dispatch:i})=>{var s;let{extendEmptyMarkRange:o=!1}=t,{selection:a}=n,l=dQ(e,r.schema),{$from:c,empty:d,ranges:u}=a;if(!i)return!0;if(d&&o){let{from:e,to:t}=a,r=null==(s=c.marks().find(e=>e.type===l))?void 0:s.attrs,i=dY(c,l,r);i&&(e=i.from,t=i.to),n.removeMark(e,t,l)}else u.forEach(e=>{n.removeMark(e.$from.pos,e.$to.pos,l)});return n.removeStoredMark(l),!0},pN=e=>({tr:t,state:n,dispatch:r})=>{let i,s,{selection:o}=n;return"number"==typeof e?(i=e,s=e):e&&"from"in e&&"to"in e?(i=e.from,s=e.to):(i=o.from,s=o.to),r&&t.doc.nodesBetween(i,s,(e,n)=>{if(e.isText)return;let r={...e.attrs};delete r.dir,t.setNodeMarkup(n,void 0,r)}),!0},pS=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let s=null,o=null,a=uy("string"==typeof e?e:e.name,r.schema);if(!a)return!1;"node"===a&&(s=dF(e,r.schema)),"mark"===a&&(o=dQ(e,r.schema));let l=!1;return n.selection.ranges.forEach(e=>{let a,c,d,u,p=e.$from.pos,h=e.$to.pos;n.selection.empty?r.doc.nodesBetween(p,h,(e,t)=>{s&&s===e.type&&(l=!0,d=Math.max(t,p),u=Math.min(t+e.nodeSize,h),a=t,c=e)}):r.doc.nodesBetween(p,h,(e,r)=>{r<p&&s&&s===e.type&&(l=!0,d=Math.max(r,p),u=Math.min(r+e.nodeSize,h),a=r,c=e),r>=p&&r<=h&&(s&&s===e.type&&(l=!0,i&&n.setNodeMarkup(r,void 0,{...e.attrs,...t})),o&&e.marks.length&&e.marks.forEach(s=>{if(o===s.type&&(l=!0,i)){let i=Math.max(r,p),a=Math.min(r+e.nodeSize,h);n.addMark(i,a,o.create({...s.attrs,...t}))}}))}),c&&(void 0!==a&&i&&n.setNodeMarkup(a,void 0,{...c.attrs,...t}),o&&c.marks.length&&c.marks.forEach(e=>{o===e.type&&i&&n.addMark(d,u,o.create({...e.attrs,...t}))}))}),l},pC=(e,t={})=>({state:n,dispatch:r})=>(function(e,t=null){return function(n,r){let{$from:i,$to:s}=n.selection,o=i.blockRange(s),a=o&&sK(o,e,t);return!!a&&(r&&r(n.tr.wrap(o,a).scrollIntoView()),!0)}})(dF(e,n.schema),t)(n,r),pj=(e,t={})=>({state:n,dispatch:r})=>(function(e,t=null){return function(n,r){let{$from:i,$to:s}=n.selection,o=i.blockRange(s);if(!o)return!1;let a=r?n.tr:null;return!!function(e,t,n,r=null){let i=!1,s=t,o=t.$from.doc;if(t.depth>=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&0==t.startIndex){if(0==t.$from.index(t.depth-1))return!1;let e=o.resolve(t.start-2);s=new i7(e,e,t.depth),t.endIndex<t.parent.childCount&&(t=new i7(t.$from,o.resolve(t.$to.end(t.depth)),t.depth)),i=!0}let a=sK(s,n,r,t);return!!a&&(e&&function(e,t,n,r,i){let s=iW.empty;for(let e=n.length-1;e>=0;e--)s=iW.from(n[e].type.create(n[e].attrs,s));e.step(new sU(t.start-2*!!r,t.end,t.start,t.end,new iX(s,0,0),n.length,!0));let o=0;for(let e=0;e<n.length;e++)n[e].type==i&&(o=e+1);let a=n.length-o,l=t.start+n.length-2*!!r,c=t.parent;for(let n=t.startIndex,r=t.endIndex,i=!0;n<r;n++,i=!1)!i&&sX(e.doc,l,a)&&(e.split(l,a),l+=2*a),l+=c.child(n).nodeSize}(e,t,a,i,n),!0)}(a,o,e,t)&&(r&&r(a.scrollIntoView()),!0)}})(dF(e,n.schema),t)(n,r),pE=class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){let n=this.callbacks[e];return n&&n.forEach(e=>e.apply(this,t)),this}off(e,t){let n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e]),this}once(e,t){let n=(...r)=>{this.off(e,n),t.apply(this,r)};return this.on(e,n)}removeAllListeners(){this.callbacks={}}},pM=class{constructor(e){var t;this.find=e.find,this.handler=e.handler,this.undoable=null==(t=e.undoable)||t}};function pA(e){var t;let{editor:n,from:r,to:i,text:s,rules:o,plugin:a}=e,{view:l}=n;if(l.composing)return!1;let c=l.state.doc.resolve(r);if(c.parent.type.spec.code||(null==(t=c.nodeBefore||c.nodeAfter)?void 0:t.marks.find(e=>e.type.spec.code)))return!1;let d=!1,u=((e,t=500)=>{let n="",r=e.parentOffset;return e.parent.nodesBetween(Math.max(0,r-t),r,(e,t,i,s)=>{var o,a;let l=(null==(a=(o=e.type.spec).toText)?void 0:a.call(o,{node:e,pos:t,parent:i,index:s}))||e.textContent||"%leaf%";n+=e.isAtom&&!e.isText?l:l.slice(0,Math.max(0,r-t))}),n})(c)+s;return o.forEach(e=>{if(d)return;let t=((e,t)=>{if(dG(t))return t.exec(e);let n=t(e);if(!n)return null;let r=[n.text];return r.index=n.index,r.input=e,r.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith)||console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'),r.push(n.replaceWith)),r})(u,e.find);if(!t)return;let o=l.state.tr,c=dO({state:l.state,transaction:o}),p={from:r-(t[0].length-s.length),to:i},{commands:h,chain:m,can:f}=new d_({editor:n,state:c});null!==e.handler({state:c,range:p,match:t,commands:h,chain:m,can:f})&&o.steps.length&&(e.undoable&&o.setMeta(a,{transform:o,from:r,to:i,text:s}),l.dispatch(o),d=!0)}),d}function pT(e){return"Object"===Object.prototype.toString.call(e).slice(8,-1)&&e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}var pO=class{constructor(e={}){this.type="extendable",this.parent=null,this.child=null,this.name="",this.config={name:this.name},this.config={...this.config,...e},this.name=this.config.name}get options(){return{...uB(uL(this,"addOptions",{name:this.name}))}}get storage(){return{...uB(uL(this,"addStorage",{name:this.name,options:this.options}))}}configure(e={}){let t=this.extend({...this.config,addOptions:()=>(function e(t,n){let r={...t};return pT(t)&&pT(n)&&Object.keys(n).forEach(i=>{pT(n[i])&&pT(t[i])?r[i]=e(t[i],n[i]):r[i]=n[i]}),r})(this.options,e)});return t.name=this.name,t.parent=this.parent,this.child=null,t}extend(e={}){let t=new this.constructor({...this.config,...e});return t.parent=this,this.child=t,t.name="name"in e?e.name:t.parent.name,t}},p_=class e extends pO{constructor(){super(...arguments),this.type="mark"}static create(t={}){return new e("function"==typeof t?t():t)}static handleExit({editor:e,mark:t}){let{tr:n}=e.state,r=e.state.selection.$from;if(r.pos===r.end()){let i=r.marks();if(!i.find(e=>(null==e?void 0:e.type.name)===t.name))return!1;let s=i.find(e=>(null==e?void 0:e.type.name)===t.name);return s&&n.removeStoredMark(s),n.insertText(" ",r.pos),e.view.dispatch(n),!0}return!1}configure(e){return super.configure(e)}extend(e){let t="function"==typeof e?e():e;return super.extend(t)}},pD=class{constructor(e){this.find=e.find,this.handler=e.handler}},pR=null,pI=class{constructor(e,t){this.splittableMarks=[],this.editor=t,this.baseExtensions=e,this.extensions=uZ(e),this.schema=function(e,t){var n;let r=uH(e),{nodeExtensions:i,markExtensions:s}=uF(e),o=null==(n=i.find(e=>uL(e,"topNode")))?void 0:n.name;return new sf({topNode:o,nodes:Object.fromEntries(i.map(n=>{let i=r.filter(e=>e.type===n.name),s={name:n.name,options:n.options,storage:n.storage,editor:t},o=uK({...e.reduce((e,t)=>{let r=uL(t,"extendNodeSchema",s);return{...e,...r?r(n):{}}},{}),content:uB(uL(n,"content",s)),marks:uB(uL(n,"marks",s)),group:uB(uL(n,"group",s)),inline:uB(uL(n,"inline",s)),atom:uB(uL(n,"atom",s)),selectable:uB(uL(n,"selectable",s)),draggable:uB(uL(n,"draggable",s)),code:uB(uL(n,"code",s)),whitespace:uB(uL(n,"whitespace",s)),linebreakReplacement:uB(uL(n,"linebreakReplacement",s)),defining:uB(uL(n,"defining",s)),isolating:uB(uL(n,"isolating",s)),attrs:Object.fromEntries(i.map(uG))}),a=uB(uL(n,"parseHTML",s));a&&(o.parseDOM=a.map(e=>uq(e,i)));let l=uL(n,"renderHTML",s);l&&(o.toDOM=e=>l({node:e,HTMLAttributes:uW(e,i)}));let c=uL(n,"renderText",s);return c&&(o.toText=c),[n.name,o]})),marks:Object.fromEntries(s.map(n=>{let i=r.filter(e=>e.type===n.name),s={name:n.name,options:n.options,storage:n.storage,editor:t},o=uK({...e.reduce((e,t)=>{let r=uL(t,"extendMarkSchema",s);return{...e,...r?r(n):{}}},{}),inclusive:uB(uL(n,"inclusive",s)),excludes:uB(uL(n,"excludes",s)),group:uB(uL(n,"group",s)),spanning:uB(uL(n,"spanning",s)),code:uB(uL(n,"code",s)),attrs:Object.fromEntries(i.map(uG))}),a=uB(uL(n,"parseHTML",s));a&&(o.parseDOM=a.map(e=>uq(e,i)));let l=uL(n,"renderHTML",s);return l&&(o.toDOM=e=>l({mark:e,HTMLAttributes:uW(e,i)})),[n.name,o]}))})}(this.extensions,t),this.setupExtensions()}get commands(){return this.extensions.reduce((e,t)=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:this.editor,type:u5(t.name,this.schema)},r=uL(t,"addCommands",n);return r?{...e,...r()}:e},{})}get plugins(){let{editor:e}=this;return uJ([...this.extensions].reverse()).flatMap(t=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:u5(t.name,this.schema)},r=[],i=uL(t,"addKeyboardShortcuts",n),s={};if("mark"===t.type&&uL(t,"exitable",n)&&(s.ArrowRight=()=>p_.handleExit({editor:e,mark:t})),i){let t=Object.fromEntries(Object.entries(i()).map(([t,n])=>[t,()=>n({editor:e})]));s={...s,...t}}let o=new oS({props:{handleKeyDown:cs(s)}});r.push(o);let a=uL(t,"addInputRules",n);if(u6(t,e.options.enableInputRules)&&a){let t=a();if(t&&t.length){let n=function(e){let{editor:t,rules:n}=e,r=new oS({state:{init:()=>null,apply(e,i,s){let o=e.getMeta(r);if(o)return o;let a=e.getMeta("applyInputRules");return a&&setTimeout(()=>{let{text:e}=a;"string"==typeof e||(e=u$(iW.from(e),s.schema));let{from:i}=a,o=i+e.length;pA({editor:t,from:i,to:o,text:e,rules:n,plugin:r})}),e.selectionSet||e.docChanged?null:i}},props:{handleTextInput:(e,i,s,o)=>pA({editor:t,from:i,to:s,text:o,rules:n,plugin:r}),handleDOMEvents:{compositionend:e=>(setTimeout(()=>{let{$cursor:i}=e.state.selection;i&&pA({editor:t,from:i.pos,to:i.pos,text:"",rules:n,plugin:r})}),!1)},handleKeyDown(e,i){if("Enter"!==i.key)return!1;let{$cursor:s}=e.state.selection;return!!s&&pA({editor:t,from:s.pos,to:s.pos,text:"\n",rules:n,plugin:r})}},isInputRules:!0});return r}({editor:e,rules:t}),i=Array.isArray(n)?n:[n];r.push(...i)}}let l=uL(t,"addPasteRules",n);if(u6(t,e.options.enablePasteRules)&&l){let t=l();if(t&&t.length){let n=function(e){let t,{editor:n,rules:r}=e,i=null,s=!1,o=!1,a="u">typeof ClipboardEvent?new ClipboardEvent("paste"):null;try{t="u">typeof DragEvent?new DragEvent("drop"):null}catch{t=null}let l=({state:e,from:r,to:i,rule:s,pasteEvt:o})=>{let l=e.tr;if(function(e){let{editor:t,state:n,from:r,to:i,rule:s,pasteEvent:o,dropEvent:a}=e,{commands:l,chain:c,can:d}=new d_({editor:t,state:n}),u=[];return n.doc.nodesBetween(r,i,(e,t)=>{var p,h,m,f,g;if((null==(h=null==(p=e.type)?void 0:p.spec)?void 0:h.code)||!(e.isText||e.isTextblock||e.isInline))return;let x=null!=(g=null!=(f=null==(m=e.content)?void 0:m.size)?f:e.nodeSize)?g:0,b=Math.max(r,t),y=Math.min(i,t+x);b>=y||((e,t,n)=>{if(dG(t))return[...e.matchAll(t)];let r=t(e,n);return r?r.map(t=>{let n=[t.text];return n.index=t.index,n.input=e,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),n.push(t.replaceWith)),n}):[]})(e.isText?e.text||"":e.textBetween(b-t,y-t,void 0,""),s.find,o).forEach(e=>{if(void 0===e.index)return;let t=b+e.index+1,r=t+e[0].length,i={from:n.tr.mapping.map(t),to:n.tr.mapping.map(r)},p=s.handler({state:n,range:i,match:e,commands:l,chain:c,can:d,pasteEvent:o,dropEvent:a});u.push(p)})}),u.every(e=>null!==e)}({editor:n,state:dO({state:e,transaction:l}),from:Math.max(r-1,0),to:i.b-1,rule:s,pasteEvent:o,dropEvent:t})&&l.steps.length){try{t="u">typeof DragEvent?new DragEvent("drop"):null}catch{t=null}return a="u">typeof ClipboardEvent?new ClipboardEvent("paste"):null,l}};return r.map(e=>new oS({view(e){let t=t=>{var r;(i=(null==(r=e.dom.parentElement)?void 0:r.contains(t.target))?e.dom.parentElement:null)&&(pR=n)},r=()=>{pR&&(pR=null)};return window.addEventListener("dragstart",t),window.addEventListener("dragend",r),{destroy(){window.removeEventListener("dragstart",t),window.removeEventListener("dragend",r)}}},props:{handleDOMEvents:{drop:(e,n)=>{if(o=i===e.dom.parentElement,t=n,!o){let e=pR;(null==e?void 0:e.isEditable)&&setTimeout(()=>{let t=e.state.selection;t&&e.commands.deleteRange({from:t.from,to:t.to})},10)}return!1},paste:(e,t)=>{var n;let r=null==(n=t.clipboardData)?void 0:n.getData("text/html");return a=t,s=!!(null==r?void 0:r.includes("data-pm-slice")),!1}}},appendTransaction:(t,n,r)=>{let i=t[0],c="paste"===i.getMeta("uiEvent")&&!s,d="drop"===i.getMeta("uiEvent")&&!o,u=i.getMeta("applyPasteRules"),p=!!u;if(!c&&!d&&!p)return;if(p){var h,m;let t,{text:n}=u;"string"==typeof n||(n=u$(iW.from(n),r.schema));let{from:i}=u,s=i+n.length;return l({rule:e,state:r,from:i,to:{b:s},pasteEvt:(h=n,null==(m=(t=new ClipboardEvent("paste",{clipboardData:new DataTransfer})).clipboardData)||m.setData("text/html",h),t)})}let f=n.doc.content.findDiffStart(r.doc.content),g=n.doc.content.findDiffEnd(r.doc.content);if("number"==typeof f&&g&&f!==g.b)return l({rule:e,state:r,from:f,to:g,pasteEvt:a})}}))}({editor:e,rules:t});r.push(...n)}}let c=uL(t,"addProseMirrorPlugins",n);if(c){let e=c();r.push(...e)}return r})}get attributes(){return uH(this.extensions)}get nodeViews(){let{editor:e}=this,{nodeExtensions:t}=uF(this.extensions);return Object.fromEntries(t.filter(e=>!!uL(e,"addNodeView")).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:dF(t.name,this.schema)},i=uL(t,"addNodeView",r);if(!i)return[];let s=i();return s?[t.name,(r,i,o,a,l)=>{let c=uW(r,n);return s({node:r,view:i,getPos:o,decorations:a,innerDecorations:l,editor:e,extension:t,HTMLAttributes:c})}]:[]}))}dispatchTransaction(e){let{editor:t}=this;return uJ([...this.extensions].reverse()).reduceRight((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:u5(n.name,this.schema)},i=uL(n,"dispatchTransaction",r);return i?t=>{i.call(r,{transaction:t,next:e})}:e},e)}transformPastedHTML(e){let{editor:t}=this;return uJ([...this.extensions]).reduce((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:u5(n.name,this.schema)},i=uL(n,"transformPastedHTML",r);return i?(t,n)=>{let s=e(t,n);return i.call(r,s)}:e},e||(e=>e))}get markViews(){let{editor:e}=this,{markExtensions:t}=uF(this.extensions);return Object.fromEntries(t.filter(e=>!!uL(e,"addMarkView")).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:dQ(t.name,this.schema)},i=uL(t,"addMarkView",r);return i?[t.name,(r,s,o)=>{let a=uW(r,n);return i()({mark:r,view:s,inline:o,editor:e,extension:t,HTMLAttributes:a,updateAttributes:t=>{!function(e,t,n={}){let{state:r}=t,{doc:i,tr:s}=r;i.descendants((t,r)=>{let i=s.mapping.map(r),o=s.mapping.map(r)+t.nodeSize,a=null;if(t.marks.forEach(t=>{if(t!==e)return!1;a=t}),!a)return;let l=!1;if(Object.keys(n).forEach(e=>{n[e]!==a.attrs[e]&&(l=!0)}),l){let t=e.type.create({...e.attrs,...n});s.removeMark(i,o,e.type),s.addMark(i,o,t)}}),s.docChanged&&t.view.dispatch(s)}(r,e,t)}})}]:[]}))}destroy(){this.extensions.forEach(e=>{let t=e;for(;t.parent;){let e=t.parent;e.child===t&&(e.child=null),t=e}}),this.extensions=[],this.baseExtensions=[],this.schema=null,this.editor=null}setupExtensions(){let e=this.extensions;this.editor.extensionStorage=Object.fromEntries(e.map(e=>[e.name,e.storage])),e.forEach(e=>{var t;let n={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:u5(e.name,this.schema)};"mark"===e.type&&(null==(t=uB(uL(e,"keepOnSplit",n)))||t)&&this.splittableMarks.push(e.name);let r=uL(e,"onBeforeCreate",n),i=uL(e,"onCreate",n),s=uL(e,"onUpdate",n),o=uL(e,"onSelectionUpdate",n),a=uL(e,"onTransaction",n),l=uL(e,"onFocus",n),c=uL(e,"onBlur",n),d=uL(e,"onDestroy",n);r&&this.editor.on("beforeCreate",r),i&&this.editor.on("create",i),s&&this.editor.on("update",s),o&&this.editor.on("selectionUpdate",o),a&&this.editor.on("transaction",a),l&&this.editor.on("focus",l),c&&this.editor.on("blur",c),d&&this.editor.on("destroy",d)})}};pI.resolve=uZ,pI.sort=uJ,pI.flatten=uP,dT({},{ClipboardTextSerializer:()=>pP,Commands:()=>p$,Delete:()=>pz,Drop:()=>pB,Editable:()=>pF,FocusEvents:()=>pU,Keymap:()=>pV,Paste:()=>pW,Tabindex:()=>pq,TextDirection:()=>pK,focusEventsPluginKey:()=>pH});var pL=class e extends pO{constructor(){super(...arguments),this.type="extension"}static create(t={}){return new e("function"==typeof t?t():t)}configure(e){return super.configure(e)}extend(e){let t="function"==typeof e?e():e;return super.extend(t)}},pP=pL.create({name:"clipboardTextSerializer",addOptions:()=>({blockSeparator:void 0}),addProseMirrorPlugins(){return[new oS({key:new oE("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{let{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:i}=t,{ranges:s}=i,o=Math.min(...s.map(e=>e.$from.pos)),a=Math.max(...s.map(e=>e.$to.pos)),l=uQ(n);return uX(r,{from:o,to:a},{...void 0!==this.options.blockSeparator?{blockSeparator:this.options.blockSeparator}:{},textSerializers:l})}}})]}}),p$=pL.create({name:"commands",addCommands:()=>({...dD})}),pz=pL.create({name:"delete",onUpdate({transaction:e,appendedTransactions:t}){var n,r,i;let s=()=>{var n,r,i,s;if(null!=(s=null==(i=null==(r=null==(n=this.editor.options.coreExtensionOptions)?void 0:n.delete)?void 0:r.filterTransaction)?void 0:i.call(r,e))?s:e.getMeta("y-sync$"))return;let o=u_(e.before,[e,...t]);u1(o).forEach(t=>{o.mapping.mapResult(t.oldRange.from).deletedAfter&&o.mapping.mapResult(t.oldRange.to).deletedBefore&&o.before.nodesBetween(t.oldRange.from,t.oldRange.to,(n,r)=>{let i=r+n.nodeSize-2,s=t.oldRange.from<=r&&i<=t.oldRange.to;this.editor.emit("delete",{type:"node",node:n,from:r,to:i,newFrom:o.mapping.map(r),newTo:o.mapping.map(i),deletedRange:t.oldRange,newRange:t.newRange,partial:!s,editor:this.editor,transaction:e,combinedTransform:o})})});let a=o.mapping;o.steps.forEach((t,n)=>{var r,i;if(t instanceof sz){let s=a.slice(n).map(t.from,-1),l=a.slice(n).map(t.to),c=a.invert().map(s,-1),d=a.invert().map(l),u=s>0&&(null==(r=o.doc.nodeAt(s-1))?void 0:r.marks.some(e=>e.eq(t.mark))),p=null==(i=o.doc.nodeAt(l))?void 0:i.marks.some(e=>e.eq(t.mark));this.editor.emit("delete",{type:"mark",mark:t.mark,from:t.from,to:t.to,deletedRange:{from:c,to:d},newRange:{from:s,to:l},partial:!!(p||u),editor:this.editor,transaction:e,combinedTransform:o})}})};null==(i=null==(r=null==(n=this.editor.options.coreExtensionOptions)?void 0:n.delete)?void 0:r.async)||i?setTimeout(s,0):s()}}),pB=pL.create({name:"drop",addProseMirrorPlugins(){return[new oS({key:new oE("tiptapDrop"),props:{handleDrop:(e,t,n,r)=>{this.editor.emit("drop",{editor:this.editor,event:t,slice:n,moved:r})}}})]}}),pF=pL.create({name:"editable",addProseMirrorPlugins(){return[new oS({key:new oE("editable"),props:{editable:()=>this.editor.options.editable}})]}}),pH=new oE("focusEvents"),pU=pL.create({name:"focusEvents",addProseMirrorPlugins(){let{editor:e}=this;return[new oS({key:pH,props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;let r=e.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;let r=e.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1}}}})]}}),pV=pL.create({name:"keymap",addKeyboardShortcuts(){let e=()=>this.editor.commands.first(({commands:e})=>[()=>e.undoInputRule(),()=>e.command(({tr:t})=>{let{selection:n,doc:r}=t,{empty:i,$anchor:s}=n,{pos:o,parent:a}=s,l=s.parent.isTextblock&&o>0?t.doc.resolve(o-1):s,c=l.parent.type.spec.isolating,d=s.pos-s.parentOffset,u=c&&1===l.parent.childCount?d===s.pos:oo.atStart(r).from===o;return!!i&&!!a.type.isTextblock&&!a.textContent.length&&!!u&&(!u||"paragraph"!==s.parent.type.name)&&e.clearNodes()}),()=>e.deleteSelection(),()=>e.joinBackward(),()=>e.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:e})=>[()=>e.deleteSelection(),()=>e.deleteCurrentNode(),()=>e.joinForward(),()=>e.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:e})=>[()=>e.newlineInCode(),()=>e.createParagraphNear(),()=>e.liftEmptyBlock(),()=>e.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},r={...n},i={...n,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return d6()||up()?i:r},addProseMirrorPlugins(){return[new oS({key:new oE("clearDocument"),appendTransaction:(e,t,n)=>{if(e.some(e=>e.getMeta("composition")))return;let r=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),i=e.some(e=>e.getMeta("preventClearDocument"));if(!r||i)return;let{empty:s,from:o,to:a}=t.selection,l=oo.atStart(t.doc).from,c=oo.atEnd(t.doc).to;if(s||o!==l||a!==c||!u7(n.doc))return;let d=n.tr,u=dO({state:n,transaction:d}),{commands:p}=new d_({editor:this.editor,state:u});if(p.clearNodes(),d.steps.length)return d}})]}}),pW=pL.create({name:"paste",addProseMirrorPlugins(){return[new oS({key:new oE("tiptapPaste"),props:{handlePaste:(e,t,n)=>{this.editor.emit("paste",{editor:this.editor,event:t,slice:n})}}})]}}),pq=pL.create({name:"tabindex",addOptions:()=>({value:void 0}),addProseMirrorPlugins(){return[new oS({key:new oE("tabindex"),props:{attributes:()=>{var e;return this.editor.isEditable||void 0!==this.options.value?{tabindex:null!=(e=this.options.value)?e:"0"}:{}}}})]}}),pK=pL.create({name:"textDirection",addOptions:()=>({direction:void 0}),addGlobalAttributes(){if(!this.options.direction)return[];let{nodeExtensions:e}=uF(this.extensions);return[{types:e.filter(e=>"text"!==e.name).map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{let t=e.getAttribute("dir");return t&&("ltr"===t||"rtl"===t||"auto"===t)?t:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new oS({key:new oE("textDirection"),props:{attributes:()=>{let e=this.options.direction;return e?{dir:e}:{}}}})]}}),pG=class e{constructor(e,t,n=!1,r=null){this.currentNode=null,this.actualDepth=null,this.isBlock=n,this.resolvedPos=e,this.editor=t,this.currentNode=r}get name(){return this.node.type.name}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){var e;return null!=(e=this.actualDepth)?e:this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,n=this.to;if(this.isBlock){if(0===this.content.size)return void console.error(`You can\u2019t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);t=this.from+1,n=this.to-1}this.editor.commands.insertContentAt({from:t,to:n},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+ +!this.node.isText}get parent(){if(0===this.depth)return null;let t=this.resolvedPos.start(this.resolvedPos.depth-1);return new e(this.resolvedPos.doc.resolve(t),this.editor)}get before(){let t=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.from-3)),new e(t,this.editor)}get after(){let t=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.to+3)),new e(t,this.editor)}get children(){let t=[];return this.node.content.forEach((n,r)=>{let i=n.isBlock&&!n.isTextblock,s=n.isAtom&&!n.isText,o=n.isInline,a=this.pos+r+ +!s;if(a<0||a>this.resolvedPos.doc.nodeSize-2)return;let l=this.resolvedPos.doc.resolve(a);if(!i&&!o&&l.depth<=this.depth)return;let c=new e(l,this.editor,i,i||o?n:null);i&&(c.actualDepth=this.depth+1),t.push(c)}),t}get firstChild(){return this.children[0]||null}get lastChild(){let e=this.children;return e[e.length-1]||null}closest(e,t={}){let n=null,r=this.parent;for(;r&&!n;){if(r.node.type.name===e)if(Object.keys(t).length>0){let e=r.node.attrs,n=Object.keys(t);for(let r=0;r<n.length;r+=1){let i=n[r];if(e[i]!==t[i])break}}else n=r;r=r.parent}return n}querySelector(e,t={}){return this.querySelectorAll(e,t,!0)[0]||null}querySelectorAll(e,t={},n=!1){let r=[];if(!this.children||0===this.children.length)return r;let i=Object.keys(t);return this.children.forEach(s=>{n&&r.length>0||(s.node.type.name===e&&i.every(e=>t[e]===s.node.attrs[e])&&r.push(s),n&&r.length>0||(r=r.concat(s.querySelectorAll(e,t,n))))}),r}setAttribute(e){let{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}},pJ=`.ProseMirror {
|
|
21
|
+
${t}/api/agent/files/${e??"<path/to/file.md>"}`;await navigator.clipboard.writeText(r),n(!0),setTimeout(()=>n(!1),1500)},[e])}}(e??null),[d,u]=(0,m.useState)(""),p=(0,m.useRef)(null),f=window.location.origin,x=(0,m.useCallback)(()=>t1,[]),b=(0,m.useCallback)(()=>d.replace(/\$WIKI_URL/g,f),[d,f]),y=(0,m.useCallback)(()=>`npx wiki-viewer-mcp register --url ${f} --id ai:myagent --name "My Agent"`,[f]),w=(0,m.useCallback)(()=>JSON.stringify({servers:{"wiki-viewer":{command:"npx",args:["wiki-viewer-mcp"],env:{WIKI_VIEWER_URL:f,WIKI_VIEWER_TOKEN:"<token from register>",WIKI_VIEWER_AGENT_ID:"ai:myagent"}}}},null,2),[f]),k=t2(x),N=t2(b),S=t2(y),C=t2(w);return((0,m.useEffect)(()=>{if(t)return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e);function e(e){"Escape"===e.key&&n()}},[t,n]),(0,m.useEffect)(()=>{t&&p.current?.focus()},[t]),(0,m.useEffect)(()=>{if(!t)return;o();let e=setInterval(()=>void o(),1e4);return()=>clearInterval(e)},[t,o]),(0,m.useEffect)(()=>{t&&fetch((0,ev.apiUrl)("/api/agents/install")).then(e=>e.json()).then(e=>{e.bootstrapPrompt&&u(e.bootstrapPrompt)}).catch(()=>void 0)},[t]),t)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"fixed inset-0 z-40 bg-overlay backdrop-blur-[1px]",onClick:n,"aria-hidden":!0}),(0,s.jsxs)("aside",{ref:p,tabIndex:-1,role:"dialog","aria-modal":"true","aria-label":"AI Agent Panel",className:"fixed right-0 top-0 bottom-0 z-50 flex w-[90vw] max-w-sm md:w-80 flex-col border-l border-border bg-background shadow-xl outline-none",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b border-border px-4 py-3 shrink-0",children:[(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)(a,{className:"h-4 w-4 text-muted-foreground"}),(0,s.jsx)("span",{className:"text-sm font-semibold",children:"AI Agent"})]}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:n,title:"Close panel (Esc)",children:(0,s.jsx)(h,{className:"h-3.5 w-3.5"})})]}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto space-y-5 px-4 py-4",children:[(0,s.jsxs)("section",{className:"space-y-3",children:[(0,s.jsxs)("div",{className:"space-y-0.5",children:[(0,s.jsx)("p",{className:"text-sm font-semibold text-foreground",children:"1 · Set up an assistant"}),(0,s.jsx)("p",{className:"text-xs leading-relaxed text-muted-foreground",children:"Pick one way to connect. You approve it in step 2 before it can touch anything."})]}),(0,s.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,s.jsx)("p",{className:"text-xs font-semibold text-foreground",children:"Paste into a chatbot"}),(0,s.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Quickest. Copy a prompt into ChatGPT, Claude, etc. Edits come back as suggestions you accept or revert. No install."}),(0,s.jsx)(v.Button,{size:"sm",variant:"outline",className:"h-7 w-full text-xs gap-1.5",onClick:()=>void N.copy(),disabled:!d,children:N.copied?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"})," Copied!"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(e7.Copy,{className:"h-3.5 w-3.5"})," Copy prompt"]})})]}),(0,s.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,s.jsx)("p",{className:"text-xs font-semibold text-foreground",children:"Connect a coding tool"}),(0,s.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Claude Code, Cursor, Codex, etc. get native read/edit tools over MCP. Run this to request access, then copy the config:"}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsx)("code",{className:"flex-1 text-[10px] font-mono text-foreground/80 truncate bg-muted rounded px-1 py-0.5",children:y()}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0",title:"Copy this command",onClick:()=>void S.copy(),children:S.copied?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"}):(0,s.jsx)(e7.Copy,{className:"h-3.5 w-3.5"})})]}),(0,s.jsx)(v.Button,{size:"sm",variant:"outline",className:"h-7 w-full text-xs gap-1.5",onClick:()=>void C.copy(),children:C.copied?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"})," Copied!"]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(e7.Copy,{className:"h-3.5 w-3.5"})," Copy config (mcp.json)"]})})]}),(0,s.jsxs)("details",{className:"text-[10px] text-muted-foreground/60",children:[(0,s.jsx)("summary",{className:"cursor-pointer select-none text-muted-foreground/50",children:"For developers"}),(0,s.jsxs)("div",{className:"mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1",children:[(0,s.jsx)("span",{children:"Install skill:"}),(0,s.jsx)("code",{className:"font-mono text-foreground/70 bg-muted rounded px-1 py-0.5",children:t1}),(0,s.jsxs)("button",{type:"button",onClick:()=>void k.copy(),className:"inline-flex items-center gap-1 text-primary hover:underline",children:[k.copied?(0,s.jsx)(g.Check,{className:"h-3 w-3 text-green-500"}):(0,s.jsx)(e7.Copy,{className:"h-3 w-3"})," copy"]}),(0,s.jsxs)("button",{type:"button",onClick:()=>void c(),className:"inline-flex items-center gap-1 text-primary hover:underline",children:[l?(0,s.jsx)(g.Check,{className:"h-3 w-3 text-green-500"}):(0,s.jsx)(e7.Copy,{className:"h-3 w-3"})," curl example"]}),(0,s.jsxs)("a",{href:(0,ev.apiUrl)("/api/agents/skill"),target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-primary hover:underline",children:[(0,s.jsx)(tC.ExternalLink,{className:"h-3 w-3"})," skill"]}),(0,s.jsxs)("a",{href:(0,ev.apiUrl)("/api/agents/install"),target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-primary hover:underline",children:[(0,s.jsx)(tC.ExternalLink,{className:"h-3 w-3"})," install JSON"]})]})]})]}),(0,s.jsx)(tR,{}),(0,s.jsxs)("div",{className:"space-y-0.5",children:[(0,s.jsx)("p",{className:"text-sm font-semibold text-foreground",children:"3 · Watch what they do"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Who is connected and every edit they make."})]}),(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsxs)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:["Active Connections"," ",(0,s.jsx)("span",{className:"normal-case font-normal text-muted-foreground/50",children:"(last 5 min)"})]}),(0,s.jsx)("div",{className:"rounded-md border border-border bg-muted/40 p-3",children:0===i.length?(0,s.jsxs)("p",{className:"text-xs text-muted-foreground/60 flex items-center gap-1.5",children:[(0,s.jsx)(tS,{className:"h-3.5 w-3.5"}),"No recent activity"]}):(0,s.jsx)("ul",{className:"space-y-1.5",children:i.map(e=>(0,s.jsxs)("li",{className:"flex items-center justify-between text-xs",children:[(0,s.jsx)("span",{className:"font-mono text-foreground/80 truncate",children:e.by}),(0,s.jsxs)("span",{className:"text-muted-foreground shrink-0",children:[e.opCount," op",1!==e.opCount?"s":""]})]},e.by))})})]}),(0,s.jsxs)("section",{className:"space-y-2",children:[(0,s.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Recent Activity"}),(0,s.jsx)("div",{className:"rounded-md border border-border bg-muted/40 px-3 py-2 max-h-72 overflow-y-auto",children:(0,s.jsx)(t0,{activity:r})})]}),(0,s.jsx)("section",{children:(0,s.jsx)("a",{href:(0,ev.apiUrl)("/docs/agent-collab-plan.md"),target:"_blank",rel:"noreferrer",className:"text-xs text-primary underline hover:no-underline",children:"Agent collaboration docs →"})})]})]})]}):null}var t3=e.i(406347);let t4=(0,o.default)("link",[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",key:"1cjeqo"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",key:"19qd67"}]]),t6=(0,o.default)("ellipsis",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]),t9=(0,o.default)("file",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]),t7=(0,o.default)("file-plus",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]]),t8=(0,o.default)("folder-plus",[["path",{d:"M12 10v6",key:"1bos4e"}],["path",{d:"M9 13h6",key:"1uhe8q"}],["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);var ne=e.i(736099);let nt=(0,o.default)("terminal",[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]]),nn=(0,o.default)("upload",[["path",{d:"M12 3v12",key:"1x0j5s"}],["path",{d:"m17 8-5-5-5 5",key:"7q97r8"}],["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}]]);function nr(e){return e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}let ni=(0,eN.create)((e,t)=>({apps:[],loading:!1,loaded:!1,collapsed:!0,dialog:null,toggleCollapsed:()=>{let n=!t().collapsed;e({collapsed:n}),n||t().refresh()},refresh:async()=>{e({loading:!0});try{let t=await (0,tk.wsFetch)("/api/wiki/hosted-apps");if(!t.ok)return void e({loading:!1,loaded:!0});let n=await t.json();e({apps:n.apps??[],loading:!1,loaded:!0})}catch{e({loading:!1,loaded:!0})}},create:async({slug:e,relPath:n,type:r="html",script:i})=>{try{let s=await (0,tk.wsFetch)("/api/wiki/hosted-apps",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({slug:e,type:r,path:n,script:i})});if(!s.ok){let e=await s.json().catch(()=>({}));return{ok:!1,error:e.error,message:e.message}}return await t().refresh(),{ok:!0}}catch(e){return{ok:!1,message:String(e)}}},start:async e=>{try{await (0,tk.wsFetch)(`/api/wiki/hosted-apps/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"start"})})}finally{await t().refresh()}},stop:async e=>{try{await (0,tk.wsFetch)(`/api/wiki/hosted-apps/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"stop"})})}finally{await t().refresh()}},pin:async e=>{try{await (0,tk.wsFetch)(`/api/wiki/hosted-apps/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"pin"})})}finally{await t().refresh()}},unpin:async e=>{try{await (0,tk.wsFetch)(`/api/wiki/hosted-apps/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"unpin"})})}finally{await t().refresh()}},restart:async e=>{try{await (0,tk.wsFetch)(`/api/wiki/hosted-apps/${encodeURIComponent(e)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"restart"})})}finally{await t().refresh()}},remove:async e=>{try{await (0,tk.wsFetch)("/api/wiki/hosted-apps",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({slug:e})})}finally{await t().refresh()}},openHostDialog:(t,n,r="html")=>e({dialog:{relPath:t,defaultSlug:n,type:r}}),closeHostDialog:()=>e({dialog:null})}));function ns({pos:e,branches:t,loading:n,busyName:r,disabled:i,onPick:o,onClose:a}){let[l,c]=(0,m.useState)(""),d=(0,m.useRef)(null);if((0,m.useEffect)(()=>{let e=e=>{let t=e.target;d.current?.contains(t)||t?.closest?.("[data-branch-trigger]")||a()},t=e=>{"Escape"===e.key&&a()};return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[a]),"u"<typeof document)return null;let p=t.length>8,h=l.trim().toLowerCase(),f=h?t.filter(e=>e.name.toLowerCase().includes(h)):t;return(0,tf.createPortal)((0,s.jsx)("div",{ref:d,"data-branch-portal":!0,style:{position:"fixed",top:e.top,left:e.left},className:"pointer-events-auto z-[9999] flex max-h-72 w-52 flex-col overflow-hidden rounded-md border bg-popover p-1 shadow-md",children:n?(0,s.jsx)("div",{className:"flex justify-center py-2",children:(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"})}):0===t.length?(0,s.jsx)("p",{className:"px-2 py-1 text-[10px] text-muted-foreground",children:"No branches"}):(0,s.jsxs)(s.Fragment,{children:[p&&(0,s.jsx)("input",{autoFocus:!0,value:l,onChange:e=>c(e.target.value),placeholder:"Filter branches…",className:"mb-1 w-full shrink-0 rounded border bg-background px-1.5 py-1 text-[11px] outline-none focus:ring-1 focus:ring-ring"}),(0,s.jsx)("div",{className:"min-h-0 flex-1 overflow-auto",children:0===f.length?(0,s.jsx)("p",{className:"px-2 py-1 text-[10px] text-muted-foreground",children:"No match"}):f.map(e=>(0,s.jsxs)("button",{type:"button",disabled:i||e.current,className:(0,eh.cn)("flex w-full items-center gap-1.5 rounded px-2 py-1 text-left text-[11px] hover:bg-muted",e.current?"font-semibold text-foreground":"text-muted-foreground"),onClick:t=>{t.stopPropagation(),e.current||o(e.name)},children:[e.current?(0,s.jsx)(g.Check,{className:"h-3 w-3 shrink-0"}):(0,s.jsx)("span",{className:"w-3 shrink-0"}),(0,s.jsx)("span",{className:"truncate",children:e.name}),r===e.name&&(0,s.jsx)(u.Loader2,{className:"ml-auto h-3 w-3 shrink-0 animate-spin"})]},e.name))})]})}),document.body)}var no=e.i(918552),na=e.i(136131),nl="ContextMenu",[nc,nd]=(0,N.createContextScope)(nl,[no.createMenuScope]),nu=(0,no.createMenuScope)(),[np,nh]=nc(nl),nm=e=>{let{__scopeContextMenu:t,children:n,onOpenChange:r,dir:i,modal:o=!0}=e,[a,l]=m.useState(!1),c=nu(t),d=(0,na.useCallbackRef)(r),u=m.useCallback(e=>{l(e),d(e)},[d]);return(0,s.jsx)(np,{scope:t,open:a,onOpenChange:u,modal:o,children:(0,s.jsx)(no.Root,{...c,dir:i,open:a,onOpenChange:u,modal:o,children:n})})};nm.displayName=nl;var nf="ContextMenuTrigger",ng=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,disabled:r=!1,...i}=e,o=nh(nf,n),a=nu(n),l=m.useRef({x:0,y:0}),c=m.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...l.current})}),d=m.useRef(0),u=m.useCallback(()=>window.clearTimeout(d.current),[]),p=e=>{l.current={x:e.clientX,y:e.clientY},o.onOpenChange(!0)};return m.useEffect(()=>u,[u]),m.useEffect(()=>void(r&&u()),[r,u]),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(no.Anchor,{...a,virtualRef:c}),(0,s.jsx)(T.Primitive.span,{"data-state":o.open?"open":"closed","data-disabled":r?"":void 0,...i,ref:t,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:(0,w.composeEventHandlers)(e.onContextMenu,e=>{u(),p(e),e.preventDefault()}),onPointerDown:r?e.onPointerDown:(0,w.composeEventHandlers)(e.onPointerDown,nM(e=>{u(),d.current=window.setTimeout(()=>p(e),700)})),onPointerMove:r?e.onPointerMove:(0,w.composeEventHandlers)(e.onPointerMove,nM(u)),onPointerCancel:r?e.onPointerCancel:(0,w.composeEventHandlers)(e.onPointerCancel,nM(u)),onPointerUp:r?e.onPointerUp:(0,w.composeEventHandlers)(e.onPointerUp,nM(u))})]})});ng.displayName=nf;var nx=e=>{let{__scopeContextMenu:t,...n}=e,r=nu(t);return(0,s.jsx)(no.Portal,{...r,...n})};nx.displayName="ContextMenuPortal";var nb="ContextMenuContent",ny=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nh(nb,n),o=nu(n),a=m.useRef(!1);return(0,s.jsx)(no.Content,{...o,...r,ref:t,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),!t.defaultPrevented&&a.current&&t.preventDefault(),a.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||i.modal||(a.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});ny.displayName=nb,m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.Group,{...i,...r,ref:t})}).displayName="ContextMenuGroup";var nv=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.Label,{...i,...r,ref:t})});nv.displayName="ContextMenuLabel";var nw=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.Item,{...i,...r,ref:t})});nw.displayName="ContextMenuItem";var nk=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.CheckboxItem,{...i,...r,ref:t})});nk.displayName="ContextMenuCheckboxItem",m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.RadioGroup,{...i,...r,ref:t})}).displayName="ContextMenuRadioGroup";var nN=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.RadioItem,{...i,...r,ref:t})});nN.displayName="ContextMenuRadioItem";var nS=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.ItemIndicator,{...i,...r,ref:t})});nS.displayName="ContextMenuItemIndicator";var nC=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.Separator,{...i,...r,ref:t})});nC.displayName="ContextMenuSeparator",m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.Arrow,{...i,...r,ref:t})}).displayName="ContextMenuArrow";var nj=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.SubTrigger,{...i,...r,ref:t})});nj.displayName="ContextMenuSubTrigger";var nE=m.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nu(n);return(0,s.jsx)(no.SubContent,{...i,...r,ref:t,style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});function nM(e){return t=>"mouse"!==t.pointerType?e(t):void 0}nE.displayName="ContextMenuSubContent";var nA=e.i(149427);m.forwardRef(({className:e,inset:t,children:n,...r},i)=>(0,s.jsxs)(nj,{ref:i,className:(0,eh.cn)("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",t&&"pl-8",e),...r,children:[n,(0,s.jsx)(eY.ChevronRight,{className:"ml-auto h-4 w-4"})]})).displayName=nj.displayName,m.forwardRef(({className:e,...t},n)=>(0,s.jsx)(nE,{ref:n,className:(0,eh.cn)("z-50 min-w-[8rem] overflow-hidden rounded-sm border bg-popover p-1 text-popover-foreground shadow-golden data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t})).displayName=nE.displayName;let nT=m.forwardRef(({className:e,...t},n)=>(0,s.jsx)(nx,{children:(0,s.jsx)(ny,{ref:n,className:(0,eh.cn)("z-50 min-w-[8rem] overflow-hidden rounded-sm border bg-popover p-1 text-popover-foreground shadow-golden data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...t})}));nT.displayName=ny.displayName;let nO=m.forwardRef(({className:e,inset:t,...n},r)=>(0,s.jsx)(nw,{ref:r,className:(0,eh.cn)("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));nO.displayName=nw.displayName,m.forwardRef(({className:e,children:t,checked:n,...r},i)=>(0,s.jsxs)(nk,{ref:i,className:(0,eh.cn)("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),checked:n,...r,children:[(0,s.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,s.jsx)(nS,{children:(0,s.jsx)(g.Check,{className:"h-4 w-4"})})}),t]})).displayName=nk.displayName,m.forwardRef(({className:e,children:t,...n},r)=>(0,s.jsxs)(nN,{ref:r,className:(0,eh.cn)("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[(0,s.jsx)("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:(0,s.jsx)(nS,{children:(0,s.jsx)(nA.Circle,{className:"h-2 w-2 fill-current"})})}),t]})).displayName=nN.displayName,m.forwardRef(({className:e,inset:t,...n},r)=>(0,s.jsx)(nv,{ref:r,className:(0,eh.cn)("px-2 py-1.5 text-sm font-normal",t&&"pl-8",e),...n})).displayName=nv.displayName;let n_=m.forwardRef(({className:e,...t},n)=>(0,s.jsx)(nC,{ref:n,className:(0,eh.cn)("-mx-1 my-1 h-px bg-muted",e),...t}));n_.displayName=nC.displayName;let nD="wiki-humanize-names",nR=(0,eN.create)((e,t)=>({humanize:"1"===localStorage.getItem(nD),toggle:()=>{let n=!t().humanize;n?localStorage.setItem(nD,"1"):localStorage.removeItem(nD),e({humanize:n})}})),nI="wiki-show-hidden",nL=(0,eN.create)((e,t)=>({showHidden:"1"===localStorage.getItem(nI),toggle:()=>{let n=!t().showHidden;n?localStorage.setItem(nI,"1"):localStorage.removeItem(nI),e({showHidden:n})}}));function nP(e,t){if("node-app"===t)return"node-app";if("app"===t)return"app";if("dir"===t)return"fallback";let n=e.split("/").pop()??e;if(n.startsWith(".")&&-1===n.indexOf(".",1))return"source";let r=e.split(".").pop()?.toLowerCase()??"";return r?["md","markdown"].includes(r)?"editor":"mdx"===r?"mdx":"txt"===r?"text":["csv","tsv"].includes(r)?"csv":"pdf"===r?"pdf":["mmd","mermaid"].includes(r)?"mermaid":"ipynb"===r?"notebook":"excalidraw"===r?"canvas":["png","jpg","jpeg","gif","webp","svg","avif","ico","bmp"].includes(r)?"image":["mp4","webm","mov","m4v","mp3","wav","ogg","m4a","aac"].includes(r)?"media":"docx"===r?"docx":["xlsx","xlsm"].includes(r)?"xlsx":"pptx"===r?"pptx":"html"===r?"html":(["py","js","ts","tsx","jsx","go","rs","java","c","cpp","h","sh","bash","zsh","rb","php","swift","kt","lua","sql","yaml","yml","toml","json","xml","css","scss"].includes(r),"source"):"source"}function n$(e){return e.split(".").pop()?.toLowerCase()??""}let nz=new Set(["txt","md","markdown","json","yaml","yml","toml","csv","tsv","xml","html","css","js","ts","tsx","jsx","sh","bash","zsh","rb","py","go","rs","java","c","cpp","h","php","swift","kt","lua","sql","scss","mmd","mermaid","ini","env","log","conf"]);function nB(e){let t=nP(e,"file");return"editor"===t||"text"===t||"mdx"===t||nz.has(n$(e))}function nF(e){return["md","markdown"].includes(n$(e))}function nH(e){return"image"===nP(e,"file")}function nU(e){return"html"===nP(e,"file")}let nV={contentVisibility:"auto",containIntrinsicSize:"auto 32px"};function nW({node:e,ctx:t,isFavorited:n,activeWorkspaceId:r}){return(0,s.jsxs)(nT,{className:"w-48",children:[(0,s.jsxs)(nO,{onSelect:()=>t.copyPath(e.path),children:[(0,s.jsx)(e7.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),nF(e.name)&&(0,s.jsxs)(nO,{onSelect:()=>t.copyWikiLink(e.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,s.jsxs)(nO,{onSelect:()=>t.copyUrl(e.path),children:[(0,s.jsx)(t4,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),"file"===e.type&&nB(e.name)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(nO,{onSelect:()=>t.copyRawContent(e.path),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,s.jsxs)(nO,{onSelect:()=>t.copyFormattedContent(e.path,e.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),(0,s.jsx)(n_,{}),"dir"===e.type&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(nO,{onSelect:()=>{e.expanded||t.toggleFolder(e),t.setNewFileParent(e.path),t.setNewFileName(""),t.setFileCreateError(null)},children:[(0,s.jsx)(t7,{className:"mr-2 h-3.5 w-3.5"}),"New file here"]}),(0,s.jsxs)(nO,{onSelect:()=>t.triggerUpload(e.path),children:[(0,s.jsx)(nn,{className:"mr-2 h-3.5 w-3.5"}),"Upload here"]}),(0,s.jsxs)(nO,{onSelect:()=>ni.getState().openHostDialog(e.path,nr(e.name)),children:[(0,s.jsx)(e5,{className:"mr-2 h-3.5 w-3.5"}),"Host this app"]}),(0,s.jsxs)(nO,{onSelect:()=>{t.setNewFolderParent(e.path),t.setNewFolderName(""),t.setFolderError(null)},children:[(0,s.jsx)(t8,{className:"mr-2 h-3.5 w-3.5"}),"New subfolder"]}),(0,s.jsx)(n_,{})]}),(0,s.jsxs)(nO,{onSelect:()=>t.handleDownload(e),children:[(0,s.jsx)(t3.Download,{className:"mr-2 h-3.5 w-3.5"}),"file"===e.type?"Download":"Download as zip"]}),(0,s.jsxs)(nO,{onSelect:()=>t.toggleFavorite(e,r),children:[(0,s.jsx)(e4,{className:(0,eh.cn)("mr-2 h-3.5 w-3.5",n&&"fill-current text-amber-400")}),n?"Remove from favorites":"Add to favorites"]}),(0,s.jsx)(n_,{}),(0,s.jsxs)(nO,{className:"text-destructive focus:text-destructive",onSelect:()=>{t.setDeletingPath(e.path),t.setDeletingIsDir("file"!==e.type)},children:[(0,s.jsx)(te,{className:"mr-2 h-3.5 w-3.5"}),"Delete"]})]})}function nq({name:e,type:t}){let n="h-3.5 w-3.5 shrink-0";return"dir"===t?(0,s.jsx)(eQ,{className:(0,eh.cn)(n,"text-foreground/70")}):"app"===t?(0,s.jsx)(c,{className:(0,eh.cn)(n,"text-foreground/70")}):"node-app"===t?(0,s.jsx)(nt,{className:(0,eh.cn)(n,"text-emerald-500")}):nU(e)?(0,s.jsx)(c,{className:(0,eh.cn)(n,"text-foreground/60")}):"canvas"===nP(e,"file")?(0,s.jsx)(ne.PencilRuler,{className:(0,eh.cn)(n,"text-violet-500")}):nH(e)?(0,s.jsx)(d.Image,{className:(0,eh.cn)(n,"text-sunshine-700")}):nB(e)?(0,s.jsx)(l.FileText,{className:(0,eh.cn)(n,"text-foreground/70")}):(0,s.jsx)(t9,{className:(0,eh.cn)(n,"text-foreground/60")})}let nK=(0,m.memo)(function({node:e,depth:t,ctx:n,isMobile:r,activeWorkspaceId:i,sidebarScrollRef:o,isActive:a,isDragOver:p,isFavorited:h,isAgentActive:m,isPulling:f,branchOpen:g,branchPos:x,branches:b,branchLoading:y,checkingOut:w,onHoverEnter:k,onHoverLeave:N}){var S;let C,j,E,M,A,T=nR(e=>e.humanize);return(0,s.jsxs)(nm,{children:[(0,s.jsx)(ng,{asChild:!0,children:(0,s.jsxs)("div",{role:"treeitem",tabIndex:0,draggable:!r,onKeyDown:r=>{if("Enter"===r.key||" "===r.key)r.preventDefault(),"dir"===e.type?n.toggleFolder(e):"app"===e.type||"node-app"===e.type?(n.openViewer(e),n.toggleFolder(e)):n.openViewer(e);else if("ArrowDown"===r.key){r.preventDefault();let e=o.current;if(!e)return;let t=Array.from(e.querySelectorAll('[role="treeitem"]')),n=t.indexOf(r.currentTarget);t[n+1]?.focus()}else if("ArrowUp"===r.key){r.preventDefault();let e=o.current;if(!e)return;let t=Array.from(e.querySelectorAll('[role="treeitem"]')),n=t.indexOf(r.currentTarget);t[n-1]?.focus()}else if("ArrowRight"===r.key){if(r.preventDefault(),"dir"===e.type||"app"===e.type||"node-app"===e.type)if(e.expanded){let e=o.current;if(!e)return;let t=Array.from(e.querySelectorAll('[role="treeitem"]')),n=t.indexOf(r.currentTarget);t[n+1]?.focus()}else n.toggleFolder(e)}else if("ArrowLeft"===r.key){if(r.preventDefault(),("dir"===e.type||"app"===e.type||"node-app"===e.type)&&e.expanded)n.toggleFolder(e);else if(t>0){let e=o.current;if(!e)return;let t=Array.from(e.querySelectorAll('[role="treeitem"]')),n=r.currentTarget,i=t.indexOf(n),s=Number.parseInt(n.style.paddingLeft??"0",10);for(let e=i-1;e>=0;e--)if(Number.parseInt(t[e].style.paddingLeft??"0",10)<s){t[e].focus();break}}}},onDragStart:t=>n.handleDragStart(t,e),onDragOver:t=>"dir"===e.type?n.handleDragOver(t,e.path,"dir"):t.preventDefault(),onDragLeave:()=>n.setDragOverPath(null),onDrop:t=>"dir"===e.type?n.handleDropOnFolder(t,e.path):t.preventDefault(),onMouseEnter:()=>k(e),onMouseLeave:N,className:(0,eh.cn)("tree-row-reveal flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer group transition-colors select-none touch-target",a?"bg-accent-soft text-foreground font-medium":"hover:bg-muted",p&&"ring-2 ring-primary bg-primary-soft",e.name.startsWith(".")&&"opacity-40"),style:{paddingLeft:`${14*t+8}px`,...nV},onClick:()=>{"dir"===e.type?n.toggleFolder(e):("app"===e.type||"node-app"===e.type?(n.openViewer(e),n.toggleFolder(e)):n.openViewer(e),r&&n.setSidebarCollapsed(!0))},children:["dir"===e.type||"app"===e.type||"node-app"===e.type?e.loading?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground"}):(0,s.jsx)(eY.ChevronRight,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground transition-transform duration-200 ease-out",style:{transform:e.expanded?"rotate(90deg)":"rotate(0deg)"}}):(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)("span",{className:"",children:"dir"===e.type?e.expanded?(0,s.jsx)(e0,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):(0,s.jsx)(eQ,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):"app"===e.type?(0,s.jsx)(c,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):"node-app"===e.type?(0,s.jsx)(nt,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-emerald-500")}):nU(e.name)?(0,s.jsx)(c,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/60")}):"canvas"===nP(e.name,"file")?(0,s.jsx)(ne.PencilRuler,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-violet-500")}):nH(e.name)?(0,s.jsx)(d.Image,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-sunshine-700")}):nB(e.name)?(0,s.jsx)(l.FileText,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):(0,s.jsx)(t9,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/60")})}),(0,s.jsx)("span",{className:"min-w-0 flex-1 truncate",title:T?e.name:void 0,children:T?(E=(j=(C=(S=e.name).lastIndexOf("."))>0&&C<S.length-1)?S.slice(0,C):S,M=j?S.slice(C):"",(A=E.replace(/([a-z0-9])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").split(/[\s_-]+/).filter(Boolean).map(e=>/^[A-Z0-9]+$/.test(e)?e:e[0].toUpperCase()+e.slice(1))).length?A.join(" ")+M:S):e.name}),e.git&&(0,s.jsxs)("span",{className:"relative flex shrink-0 items-center gap-0.5 rounded-sm bg-muted px-1 py-0.5 text-[10px] text-muted-foreground",children:[(0,s.jsxs)("button",{"data-branch-trigger":!0,type:"button",className:"flex items-center gap-0.5 hover:text-foreground",title:"Switch branch",onClick:t=>{if(t.stopPropagation(),g){n.setBranchDropdownNode(null),n.setBranchDropdownPos(null);return}let r=t.currentTarget.getBoundingClientRect();n.setBranchDropdownPos({top:r.bottom+4,left:r.left}),n.setBranchDropdownNode(e.path),n.loadBranches(e.path)},children:[(0,s.jsx)(e1,{className:"h-2.5 w-2.5"}),e.git.branch,e.git.dirty&&(0,s.jsx)("span",{className:"ml-0.5 text-foreground/70",children:"*"})]}),f?(0,s.jsx)(u.Loader2,{className:"ml-0.5 h-2.5 w-2.5 animate-spin"}):(0,s.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation();let r=e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")):"";n.handleGitPull(e.path,r)},className:"ml-0.5 text-muted-foreground hover:text-foreground",title:"Pull latest",children:(0,s.jsx)(tA,{className:"h-2.5 w-2.5"})}),g&&x&&(0,s.jsx)(ns,{pos:x,branches:b,loading:y,busyName:w,disabled:null!==w,onPick:t=>{let r=e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")):"";n.handleCheckout(e.path,t,r)},onClose:()=>{n.setBranchDropdownNode(null),n.setBranchDropdownPos(null)}})]}),m&&(0,s.jsx)("span",{className:"ml-0.5 h-1.5 w-1.5 rounded-full bg-emerald-400 shrink-0 animate-pulse",title:"Agent recently active"}),(0,s.jsx)("div",{className:"hover-reveal flex max-w-0 shrink-0 items-center overflow-hidden opacity-0 transition-all duration-150 group-hover:max-w-7 group-hover:opacity-100 focus-within:max-w-7 focus-within:opacity-100",onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),children:(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-muted-foreground hover:text-foreground",title:"File actions",children:(0,s.jsx)(t6,{className:"h-3.5 w-3.5"})})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"end",className:"w-48",children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyPath(e.path),children:[(0,s.jsx)(e7.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),nF(e.name)&&(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyWikiLink(e.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyUrl(e.path),children:[(0,s.jsx)(t4,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),"file"===e.type&&nB(e.name)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyRawContent(e.path),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.copyFormattedContent(e.path,e.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),"dir"===e.type&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:async()=>{e.expanded||n.toggleFolder(e),n.setNewFileParent(e.path),n.setNewFileName(""),n.setFileCreateError(null)},children:[(0,s.jsx)(t7,{className:"mr-2 h-3.5 w-3.5"}),"New file here"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.triggerUpload(e.path),children:[(0,s.jsx)(nn,{className:"mr-2 h-3.5 w-3.5"}),"Upload here"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>{n.setNewFolderParent(e.path),n.setNewFolderName(""),n.setFolderError(null)},children:[(0,s.jsx)(t8,{className:"mr-2 h-3.5 w-3.5"}),"New subfolder"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{})]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.handleDownload(e),children:[(0,s.jsx)(t3.Download,{className:"mr-2 h-3.5 w-3.5"}),"file"===e.type?"Download":"Download as zip"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n.toggleFavorite(e,i),children:[(0,s.jsx)(e4,{className:(0,eh.cn)("mr-2 h-3.5 w-3.5",h&&"fill-current text-amber-400")}),h?"Remove from favorites":"Add to favorites"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{className:"text-destructive focus:text-destructive",onClick:()=>{n.setDeletingPath(e.path),n.setDeletingIsDir("file"!==e.type)},children:[(0,s.jsx)(te,{className:"mr-2 h-3.5 w-3.5"}),"Delete"]})]})]})})]})}),(0,s.jsx)(nW,{node:e,ctx:n,isFavorited:h,activeWorkspaceId:i})]})}),nG=(0,m.memo)(function(e){let{ctx:t,openPath:n,dragOverPath:r,branchDropdownNode:i,branchDropdownPos:o,nodeBranches:a,branchesLoading:c,checkingOutBranch:d,pullingRepo:u,activePaths:p,favorites:f,isMobile:x,activeWorkspaceId:b,newFileParent:y,newFileName:w,fileCreateError:k,newFolderParent:N,newFolderName:S,folderError:C,sidebarScrollRef:j}=e,E=nL(e=>e.showHidden),M=(0,m.useRef)(null),A=(0,m.useCallback)(e=>{let n=("dir"===e.type||"app"===e.type||"node-app"===e.type)&&!e.expanded&&void 0===e.children;("file"===e.type||n)&&(M.current&&clearTimeout(M.current),M.current=setTimeout(()=>t.prefetch(e),120))},[t]),T=(0,m.useCallback)(()=>{M.current&&(clearTimeout(M.current),M.current=null)},[]),O=(0,m.useMemo)(()=>{let t=[],n=(e,r)=>{for(let i of e)!(!E&&i.name.startsWith("."))&&(t.push({kind:"row",node:i,depth:r}),"dir"===i.type&&(N===i.path&&t.push({kind:"newfolder",node:i,depth:r}),y===i.path&&t.push({kind:"newfile",node:i,depth:r})),("dir"===i.type||"app"===i.type||"node-app"===i.type)&&i.expanded&&(i.children&&i.children.length>0?n(i.children,r+1):i.children?.length===0&&t.push({kind:"empty",node:i,depth:r})))};return n(e.nodes,0),t},[e.nodes,y,N,E]);return(0,s.jsx)(s.Fragment,{children:O.map(e=>{let{node:m,depth:y}=e;if("row"===e.kind){let e=i===m.path;return(0,s.jsx)(nK,{node:m,depth:y,ctx:t,isMobile:x,activeWorkspaceId:b,sidebarScrollRef:j,isActive:n===m.path,isDragOver:r===m.path,isFavorited:f.some(e=>e.path===m.path),isAgentActive:p.has(m.path),isPulling:u===m.path,branchOpen:e,branchPos:e?o:null,branches:m.git?a[m.path]??[]:[],branchLoading:!!m.git&&!!c[m.path],checkingOut:e?d:null,onHoverEnter:A,onHoverLeave:T},m.path)}return"newfolder"===e.kind?(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1",style:{paddingLeft:`${(y+1)*14+8}px`,...nV},children:[(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)(eQ,{className:"h-4 w-4 shrink-0 text-foreground/70"}),(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"Folder name",value:S,onChange:e=>t.setNewFolderName(e.target.value),onKeyDown:e=>{"Enter"===e.key&&t.handleCreateFolder(),"Escape"===e.key&&(t.setNewFolderParent(null),t.setNewFolderName(""))}}),C&&(0,s.jsx)("span",{className:"text-xs text-destructive",children:C}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:t.handleCreateFolder,children:(0,s.jsx)(g.Check,{className:"h-3 w-3"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{t.setNewFolderParent(null),t.setNewFolderName("")},children:(0,s.jsx)(h,{className:"h-3 w-3"})})]},`nf-${m.path}`):"newfile"===e.kind?(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1",style:{paddingLeft:`${(y+1)*14+8}px`,...nV},children:[(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)(l.FileText,{className:"h-4 w-4 shrink-0 text-accent"}),(0,s.jsx)("input",{autoFocus:!0,className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"filename (default .md)",value:w,onFocus:e=>e.currentTarget.select(),onChange:e=>t.setNewFileName(e.target.value),onKeyDown:e=>{"Enter"===e.key&&t.handleCreateFile(),"Escape"===e.key&&(t.setNewFileParent(null),t.setNewFileName(""))}}),k&&(0,s.jsx)("span",{className:"text-xs text-destructive",children:k}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:t.handleCreateFile,children:(0,s.jsx)(g.Check,{className:"h-3 w-3"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{t.setNewFileParent(null),t.setNewFileName("")},children:(0,s.jsx)(h,{className:"h-3 w-3"})})]},`ff-${m.path}`):(0,s.jsx)("div",{className:"text-xs text-muted-foreground/50 py-0.5",style:{paddingLeft:`${(y+1)*14+8+14+6+16+6}px`,...nV},children:"Empty"},`empty-${m.path}`)})})});function nJ(e){return e?`wiki-pinned-files-${e}`:"wiki-pinned-files"}function nZ(e){try{let t=localStorage.getItem(nJ(e));return t?JSON.parse(t):[]}catch{return[]}}let nX=(0,eN.create)((e,t)=>({favorites:[],loadForWorkspace:t=>{e({favorites:nZ(t)})},toggle:(t,n)=>{let r=nZ(n),i=r.some(e=>e.path===t.path)?r.filter(e=>e.path!==t.path):[...r,t];localStorage.setItem(nJ(n),JSON.stringify(i)),e({favorites:i})},isFavorited:e=>t().favorites.some(t=>t.path===e)}));function nY({doc:e,node:t,extraItems:n,activeWorkspaceId:r=null}){let i=nX(e=>e.isFavorited(t.path));return(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"File actions",children:(0,s.jsx)(t6,{className:"h-3.5 w-3.5"})})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"end",className:"w-52",children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>{let e=(0,tk.withWs)(`/api/wiki/download?path=${encodeURIComponent(t.path)}`),n=document.createElement("a");n.href=e,n.download=t.name,document.body.appendChild(n),n.click(),n.remove()},children:[(0,s.jsx)(t3.Download,{className:"mr-2 h-3.5 w-3.5"}),"Download"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>{nX.getState().toggle({path:t.path,name:t.name},r)},children:[(0,s.jsx)(e4,{className:(0,eh.cn)("mr-2 h-3.5 w-3.5",i&&"fill-current text-amber-400")}),i?"Remove from favorites":"Add to favorites"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>e.copyPath(t.path),children:[(0,s.jsx)(e7.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),nF(t.name)&&(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>e.copyWikiLink(t.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>e.copyUrl(t.path),children:[(0,s.jsx)(t4,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),nB(t.name)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>void e.copyRawContent(t.path),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>void e.copyFormattedContent(t.path,t.name),children:[(0,s.jsx)(l.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),n&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(ek.DropdownMenuSeparator,{}),n]})]})]})}let nQ=(0,o.default)("align-center",[["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 18H5",key:"18s9l3"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);var n0=e.i(409082);let n1=(0,o.default)("panel-left",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}]]);var n2=e.i(847463),n5=e.i(917356),n3=/[\\\/_+.#"@\[\(\{&]/,n4=/[\\\/_+.#"@\[\(\{&]/g,n6=/[\s-]/,n9=/[\s-]/g;function n7(e){return e.toLowerCase().replace(n9," ")}var n8='[cmdk-group=""]',re='[cmdk-group-items=""]',rt='[cmdk-item=""]',rn=`${rt}:not([aria-disabled="true"])`,rr="cmdk-item-select",ri="data-value",rs=(e,t,n)=>{var r;return r=e,function e(t,n,r,i,s,o,a){if(o===n.length)return s===t.length?1:.99;var l=`${s},${o}`;if(void 0!==a[l])return a[l];for(var c,d,u,p,h=i.charAt(o),m=r.indexOf(h,s),f=0;m>=0;)(c=e(t,n,r,i,m+1,o+1,a))>f&&(m===s?c*=1:n3.test(t.charAt(m-1))?(c*=.8,(u=t.slice(s,m-1).match(n4))&&s>0&&(c*=Math.pow(.999,u.length))):n6.test(t.charAt(m-1))?(c*=.9,(p=t.slice(s,m-1).match(n9))&&s>0&&(c*=Math.pow(.999,p.length))):(c*=.17,s>0&&(c*=Math.pow(.999,m-s))),t.charAt(m)!==n.charAt(o)&&(c*=.9999)),(c<.1&&r.charAt(m-1)===i.charAt(o+1)||i.charAt(o+1)===i.charAt(o)&&r.charAt(m-1)!==i.charAt(o))&&.1*(d=e(t,n,r,i,m+1,o+2,a))>c&&(c=.1*d),c>f&&(f=c),m=r.indexOf(h,m+1);return a[l]=f,f}(r=n&&n.length>0?`${r+" "+n.join(" ")}`:r,t,n7(r),n7(t),0,0,{})},ro=m.createContext(void 0),ra=m.createContext(void 0),rl=m.createContext(void 0),rc=m.forwardRef((e,t)=>{let n=ry(()=>{var t,n;return{search:"",value:null!=(n=null!=(t=e.value)?t:e.defaultValue)?n:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),r=ry(()=>new Set),i=ry(()=>new Map),s=ry(()=>new Map),o=ry(()=>new Set),a=rx(e),{label:l,children:c,value:d,onValueChange:u,filter:p,shouldFilter:h,loop:f,disablePointerSelection:g=!1,vimBindings:x=!0,...b}=e,y=(0,S.useId)(),v=(0,S.useId)(),w=(0,S.useId)(),k=m.useRef(null),N=rk();rb(()=>{if(void 0!==d){let e=d.trim();n.current.value=e,C.emit()}},[d]),rb(()=>{N(6,O)},[]);let C=m.useMemo(()=>({subscribe:e=>(o.current.add(e),()=>o.current.delete(e)),snapshot:()=>n.current,setState:(e,t,r)=>{var i,s,o,l;if(!Object.is(n.current[e],t)){if(n.current[e]=t,"search"===e)T(),M(),N(1,A);else if("value"===e){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let e=document.getElementById(w);e?e.focus():null==(i=document.getElementById(y))||i.focus()}if(N(7,()=>{var e;n.current.selectedItemId=null==(e=_())?void 0:e.id,C.emit()}),r||N(5,O),(null==(s=a.current)?void 0:s.value)!==void 0){null==(l=(o=a.current).onValueChange)||l.call(o,null!=t?t:"");return}}C.emit()}},emit:()=>{o.current.forEach(e=>e())}}),[]),j=m.useMemo(()=>({value:(e,t,r)=>{var i;t!==(null==(i=s.current.get(e))?void 0:i.value)&&(s.current.set(e,{value:t,keywords:r}),n.current.filtered.items.set(e,E(t,r)),N(2,()=>{M(),C.emit()}))},item:(e,t)=>(r.current.add(e),t&&(i.current.has(t)?i.current.get(t).add(e):i.current.set(t,new Set([e]))),N(3,()=>{T(),M(),n.current.value||A(),C.emit()}),()=>{s.current.delete(e),r.current.delete(e),n.current.filtered.items.delete(e);let t=_();N(4,()=>{T(),(null==t?void 0:t.getAttribute("id"))===e&&A(),C.emit()})}),group:e=>(i.current.has(e)||i.current.set(e,new Set),()=>{s.current.delete(e),i.current.delete(e)}),filter:()=>a.current.shouldFilter,label:l||e["aria-label"],getDisablePointerSelection:()=>a.current.disablePointerSelection,listId:y,inputId:w,labelId:v,listInnerRef:k}),[]);function E(e,t){var r,i;let s=null!=(i=null==(r=a.current)?void 0:r.filter)?i:rs;return e?s(e,n.current.search,t):0}function M(){if(!n.current.search||!1===a.current.shouldFilter)return;let e=n.current.filtered.items,t=[];n.current.filtered.groups.forEach(n=>{let r=i.current.get(n),s=0;r.forEach(t=>{s=Math.max(e.get(t),s)}),t.push([n,s])});let r=k.current;D().sort((t,n)=>{var r,i;let s=t.getAttribute("id"),o=n.getAttribute("id");return(null!=(r=e.get(o))?r:0)-(null!=(i=e.get(s))?i:0)}).forEach(e=>{let t=e.closest(re);t?t.appendChild(e.parentElement===t?e:e.closest(`${re} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${re} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{var t;let n=null==(t=k.current)?void 0:t.querySelector(`${n8}[${ri}="${encodeURIComponent(e[0])}"]`);null==n||n.parentElement.appendChild(n)})}function A(){let e=D().find(e=>"true"!==e.getAttribute("aria-disabled")),t=null==e?void 0:e.getAttribute(ri);C.setState("value",t||void 0)}function T(){var e,t,o,l;if(!n.current.search||!1===a.current.shouldFilter){n.current.filtered.count=r.current.size;return}n.current.filtered.groups=new Set;let c=0;for(let i of r.current){let r=E(null!=(t=null==(e=s.current.get(i))?void 0:e.value)?t:"",null!=(l=null==(o=s.current.get(i))?void 0:o.keywords)?l:[]);n.current.filtered.items.set(i,r),r>0&&c++}for(let[e,t]of i.current)for(let r of t)if(n.current.filtered.items.get(r)>0){n.current.filtered.groups.add(e);break}n.current.filtered.count=c}function O(){var e,t,n;let r=_();r&&((null==(e=r.parentElement)?void 0:e.firstChild)===r&&(null==(n=null==(t=r.closest(n8))?void 0:t.querySelector('[cmdk-group-heading=""]'))||n.scrollIntoView({block:"nearest"})),r.scrollIntoView({block:"nearest"}))}function _(){var e;return null==(e=k.current)?void 0:e.querySelector(`${rt}[aria-selected="true"]`)}function D(){var e;return Array.from((null==(e=k.current)?void 0:e.querySelectorAll(rn))||[])}function R(e){let t=D()[e];t&&C.setState("value",t.getAttribute(ri))}function I(e){var t;let n=_(),r=D(),i=r.findIndex(e=>e===n),s=r[i+e];null!=(t=a.current)&&t.loop&&(s=i+e<0?r[r.length-1]:i+e===r.length?r[0]:r[i+e]),s&&C.setState("value",s.getAttribute(ri))}function L(e){let t=_(),n=null==t?void 0:t.closest(n8),r;for(;n&&!r;)r=null==(n=e>0?function(e,t){let n=e.nextElementSibling;for(;n;){if(n.matches(t))return n;n=n.nextElementSibling}}(n,n8):function(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}(n,n8))?void 0:n.querySelector(rn);r?C.setState("value",r.getAttribute(ri)):I(e)}let P=()=>R(D().length-1),$=e=>{e.preventDefault(),e.metaKey?P():e.altKey?L(1):I(1)},z=e=>{e.preventDefault(),e.metaKey?R(0):e.altKey?L(-1):I(-1)};return m.createElement(tx.div,{ref:t,tabIndex:-1,...b,"cmdk-root":"",onKeyDown:e=>{var t;null==(t=b.onKeyDown)||t.call(b,e);let n=e.nativeEvent.isComposing||229===e.keyCode;if(!(e.defaultPrevented||n))switch(e.key){case"n":case"j":x&&e.ctrlKey&&$(e);break;case"ArrowDown":$(e);break;case"p":case"k":x&&e.ctrlKey&&z(e);break;case"ArrowUp":z(e);break;case"Home":e.preventDefault(),R(0);break;case"End":e.preventDefault(),P();break;case"Enter":{e.preventDefault();let t=_();if(t){let e=new Event(rr);t.dispatchEvent(e)}}}}},m.createElement("label",{"cmdk-label":"",htmlFor:j.inputId,id:j.labelId,style:rS},l),rN(e,e=>m.createElement(ra.Provider,{value:C},m.createElement(ro.Provider,{value:j},e))))}),rd=m.forwardRef((e,t)=>{var n,r;let i=(0,S.useId)(),s=m.useRef(null),o=m.useContext(rl),a=m.useContext(ro),l=rx(e),c=null!=(r=null==(n=l.current)?void 0:n.forceMount)?r:null==o?void 0:o.forceMount;rb(()=>{if(!c)return a.item(i,null==o?void 0:o.id)},[c]);let d=rw(i,s,[e.value,e.children,s],e.keywords),u=m.useContext(ra),p=rv(e=>e.value&&e.value===d.current),h=rv(e=>!!c||!1===a.filter()||!e.search||e.filtered.items.get(i)>0);function f(){var e,t;g(),null==(t=(e=l.current).onSelect)||t.call(e,d.current)}function g(){u.setState("value",d.current,!0)}if(m.useEffect(()=>{let t=s.current;if(!(!t||e.disabled))return t.addEventListener(rr,f),()=>t.removeEventListener(rr,f)},[h,e.onSelect,e.disabled]),!h)return null;let{disabled:x,value:b,onSelect:y,forceMount:v,keywords:w,...N}=e;return m.createElement(tx.div,{ref:(0,k.composeRefs)(s,t),...N,id:i,"cmdk-item":"",role:"option","aria-disabled":!!x,"aria-selected":!!p,"data-disabled":!!x,"data-selected":!!p,onPointerMove:x||a.getDisablePointerSelection()?void 0:g,onClick:x?void 0:f},e.children)}),ru=m.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...s}=e,o=(0,S.useId)(),a=m.useRef(null),l=m.useRef(null),c=(0,S.useId)(),d=m.useContext(ro),u=rv(e=>!!i||!1===d.filter()||!e.search||e.filtered.groups.has(o));rb(()=>d.group(o),[]),rw(o,a,[e.value,e.heading,l]);let p=m.useMemo(()=>({id:o,forceMount:i}),[i]);return m.createElement(tx.div,{ref:(0,k.composeRefs)(a,t),...s,"cmdk-group":"",role:"presentation",hidden:!u||void 0},n&&m.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:c},n),rN(e,e=>m.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?c:void 0},m.createElement(rl.Provider,{value:p},e))))}),rp=m.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=m.useRef(null),s=rv(e=>!e.search);return n||s?m.createElement(tx.div,{ref:(0,k.composeRefs)(i,t),...r,"cmdk-separator":"",role:"separator"}):null}),rh=m.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=null!=e.value,s=m.useContext(ra),o=rv(e=>e.search),a=rv(e=>e.selectedItemId),l=m.useContext(ro);return m.useEffect(()=>{null!=e.value&&s.setState("search",e.value)},[e.value]),m.createElement(tx.input,{ref:t,...r,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":l.listId,"aria-labelledby":l.labelId,"aria-activedescendant":a,id:l.inputId,type:"text",value:i?e.value:o,onChange:e=>{i||s.setState("search",e.target.value),null==n||n(e.target.value)}})}),rm=m.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...i}=e,s=m.useRef(null),o=m.useRef(null),a=rv(e=>e.selectedItemId),l=m.useContext(ro);return m.useEffect(()=>{if(o.current&&s.current){let e=o.current,t=s.current,n,r=new ResizeObserver(()=>{n=requestAnimationFrame(()=>{let n=e.offsetHeight;t.style.setProperty("--cmdk-list-height",n.toFixed(1)+"px")})});return r.observe(e),()=>{cancelAnimationFrame(n),r.unobserve(e)}}},[]),m.createElement(tx.div,{ref:(0,k.composeRefs)(s,t),...i,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:l.listId},rN(e,e=>m.createElement("div",{ref:(0,k.composeRefs)(o,l.listInnerRef),"cmdk-list-sizer":""},e)))}),rf=m.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:s,container:o,...a}=e;return m.createElement(B,{open:n,onOpenChange:r},m.createElement(W,{container:o},m.createElement(K,{"cmdk-overlay":"",className:i}),m.createElement(X,{"aria-label":e.label,"cmdk-dialog":"",className:s},m.createElement(rc,{ref:t,...a}))))}),rg=Object.assign(rc,{List:rm,Item:rd,Input:rh,Group:ru,Separator:rp,Dialog:rf,Empty:m.forwardRef((e,t)=>rv(e=>0===e.filtered.count)?m.createElement(tx.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),Loading:m.forwardRef((e,t)=>{let{progress:n,children:r,label:i="Loading...",...s}=e;return m.createElement(tx.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},rN(e,e=>m.createElement("div",{"aria-hidden":!0},e)))})});function rx(e){let t=m.useRef(e);return rb(()=>{t.current=e}),t}var rb="u"<typeof window?m.useEffect:m.useLayoutEffect;function ry(e){let t=m.useRef();return void 0===t.current&&(t.current=e()),t}function rv(e){let t=m.useContext(ra),n=()=>e(t.snapshot());return m.useSyncExternalStore(t.subscribe,n,n)}function rw(e,t,n,r=[]){let i=m.useRef(),s=m.useContext(ro);return rb(()=>{var o;let a=(()=>{var e;for(let t of n){if("string"==typeof t)return t.trim();if("object"==typeof t&&"current"in t)return t.current?null==(e=t.current.textContent)?void 0:e.trim():i.current}})(),l=r.map(e=>e.trim());s.value(e,a,l),null==(o=t.current)||o.setAttribute(ri,a),i.current=a}),i}var rk=()=>{let[e,t]=m.useState(),n=ry(()=>new Map);return rb(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function rN({asChild:e,children:t},n){let r;return e&&m.isValidElement(t)?m.cloneElement("function"==typeof(r=t.type)?r(t.props):"render"in r?r.render(t.props):t,{ref:t.ref},n(t.props.children)):n(t)}var rS={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};let rC=(0,o.default)("search",[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]),rj=m.forwardRef(({className:e,...t},n)=>(0,s.jsx)(rg,{ref:n,className:(0,eh.cn)("flex h-full w-full flex-col overflow-hidden rounded-sm bg-popover text-popover-foreground",e),...t}));function rE({children:e,shouldFilter:t,...n}){return(0,s.jsx)(B,{...n,children:(0,s.jsxs)(eq,{className:"overflow-hidden p-0 shadow-golden max-w-lg",children:[(0,s.jsx)(eJ,{className:"sr-only",children:"Search"}),(0,s.jsx)(rj,{shouldFilter:t,className:"[&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-normal [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5",children:e})]})})}rj.displayName=rg.displayName;let rM=m.forwardRef(({className:e,...t},n)=>(0,s.jsxs)("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[(0,s.jsx)(rC,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),(0,s.jsx)(rg.Input,{ref:n,className:(0,eh.cn)("flex h-11 w-full rounded-sm bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",e),...t})]}));rM.displayName=rg.Input.displayName;let rA=m.forwardRef(({className:e,...t},n)=>(0,s.jsx)(rg.List,{ref:n,className:(0,eh.cn)("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));rA.displayName=rg.List.displayName;let rT=m.forwardRef((e,t)=>(0,s.jsx)(rg.Empty,{ref:t,className:"py-6 text-center text-sm text-muted-foreground",...e}));rT.displayName=rg.Empty.displayName;let rO=m.forwardRef(({className:e,...t},n)=>(0,s.jsx)(rg.Group,{ref:n,className:(0,eh.cn)("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-normal [&_[cmdk-group-heading]]:text-muted-foreground",e),...t}));rO.displayName=rg.Group.displayName;let r_=m.forwardRef(({className:e,...t},n)=>(0,s.jsx)(rg.Separator,{ref:n,className:(0,eh.cn)("-mx-1 h-px bg-border",e),...t}));r_.displayName=rg.Separator.displayName;let rD=m.forwardRef(({className:e,...t},n)=>(0,s.jsx)(rg.Item,{ref:n,className:(0,eh.cn)("relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",e),...t}));rD.displayName=rg.Item.displayName;let rR=null,rI=null,rL=(0,eN.create)(e=>({query:"",results:[],loading:!1,truncated:!1,open:!1,setQuery:t=>e({query:t}),setOpen:t=>e({open:t}),clear:()=>{rI&&clearTimeout(rI),rR?.abort(),e({query:"",results:[],loading:!1,truncated:!1})},search:t=>(rI&&clearTimeout(rI),t.trim())?(e({loading:!0}),new Promise(n=>{rI=setTimeout(()=>{rP(e,t).finally(n)},150)})):(rR?.abort(),e({results:[],loading:!1,truncated:!1}),Promise.resolve())}));async function rP(e,t){rR?.abort();let n=new AbortController;rR=n;try{let r=await (0,tk.wsFetch)("/api/wiki/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t,limit:30}),signal:n.signal});if(!r.ok)return void e({results:[],loading:!1,truncated:!1});let i=await r.json();if(n.signal.aborted)return;e({results:i.matches??[],truncated:!!i.truncated,loading:!1})}catch(t){"AbortError"!==t.name&&e({loading:!1})}}var r$=e.i(395624);function rz({html:e}){let t=function(e){let t,n=[],r=/<mark>([\s\S]*?)<\/mark>/g,i=0;for(;null!==(t=r.exec(e));)t.index>i&&n.push({text:e.slice(i,t.index),mark:!1}),n.push({text:t[1]??"",mark:!0}),i=t.index+t[0].length;return i<e.length&&n.push({text:e.slice(i),mark:!1}),n}(e);return(0,s.jsx)(s.Fragment,{children:t.map((e,t)=>e.mark?(0,s.jsx)("mark",{className:"bg-yellow-200 dark:bg-yellow-700 rounded-[2px] px-[1px]",children:e.text},t):(0,s.jsx)("span",{children:e.text},t))})}function rB({onOpenFile:e,recents:t=[],onToggleSidebar:n=()=>void 0,onNewFile:r=()=>void 0,onCopyPath:i=()=>void 0}){let o=rL(e=>e.open),l=rL(e=>e.setOpen),c=rL(e=>e.query),d=rL(e=>e.setQuery),u=rL(e=>e.results),p=rL(e=>e.loading),h=rL(e=>e.truncated),f=rL(e=>e.search),{resolvedTheme:g,setTheme:x}=(0,n5.useTheme)(),b=tj(e=>e.toggle),y=(0,r$.useViewWidthStore)(e=>e.width),v=(0,r$.useViewWidthStore)(e=>e.cycle),w=c.trimStart(),k=""===w||w.startsWith(">"),N=""===w&&t.length>0,S=k?"":c;function C(e){e(),l(!1),d("")}(0,m.useEffect)(()=>{function e(e){(e.metaKey||e.ctrlKey)&&"k"===e.key.toLowerCase()&&(e.preventDefault(),l(!o))}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[o,l]),(0,m.useEffect)(()=>{if(!o||k)return;let e=setTimeout(()=>{f(S)},120);return()=>clearTimeout(e)},[S,k,o,f]);let j=(r$.VIEW_WIDTH_ORDER.indexOf(y)+1)%r$.VIEW_WIDTH_ORDER.length,E=r$.VIEW_WIDTH_LABEL[r$.VIEW_WIDTH_ORDER[j]];return(0,s.jsxs)(rE,{open:o,onOpenChange:e=>{l(e),e||d("")},shouldFilter:!1,children:[(0,s.jsx)(rM,{placeholder:"Search files… ( > for actions )",value:c,onValueChange:d}),(0,s.jsxs)(rA,{children:[N&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(rO,{heading:"Recent",children:t.map(t=>(0,s.jsxs)(rD,{value:`recent:${t.path}`,onSelect:()=>{e(t.path),l(!1),d("")},children:[(0,s.jsx)(tt,{className:"mr-2 h-4 w-4"}),(0,s.jsxs)("div",{className:"flex min-w-0 flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"truncate font-medium",children:t.name}),(0,s.jsx)("span",{className:"truncate text-xs text-muted-foreground",children:t.path})]})]},t.path))}),(0,s.jsx)(r_,{})]}),k&&(0,s.jsxs)(rO,{heading:"Actions",children:[(0,s.jsxs)(rD,{value:"toggle-dark-mode",onSelect:()=>C(()=>x("dark"===g?"light":"dark")),children:["dark"===g?(0,s.jsx)(n2.Sun,{className:"mr-2 h-4 w-4"}):(0,s.jsx)(n0.Moon,{className:"mr-2 h-4 w-4"}),"dark"===g?"Switch to light mode":"Switch to dark mode"]}),(0,s.jsxs)(rD,{value:"toggle-ai-panel",onSelect:()=>C(b),children:[(0,s.jsx)(a,{className:"mr-2 h-4 w-4"}),"Toggle AI panel"]}),(0,s.jsxs)(rD,{value:"toggle-sidebar",onSelect:()=>C(n),children:[(0,s.jsx)(n1,{className:"mr-2 h-4 w-4"}),"Toggle sidebar"]}),(0,s.jsxs)(rD,{value:"new-file",onSelect:()=>C(r),children:[(0,s.jsx)(t7,{className:"mr-2 h-4 w-4"}),"New file"]}),(0,s.jsxs)(rD,{value:"copy-path",onSelect:()=>C(i),children:[(0,s.jsx)(e7.Copy,{className:"mr-2 h-4 w-4"}),"Copy current file path"]}),(0,s.jsxs)(rD,{value:"cycle-view-width",onSelect:()=>C(v),children:[(0,s.jsx)(nQ,{className:"mr-2 h-4 w-4"}),(0,s.jsxs)("span",{children:["Change view width"," ",(0,s.jsxs)("span",{className:"text-muted-foreground",children:["(",r$.VIEW_WIDTH_LABEL[y]," → ",E,")"]})]})]})]}),!k&&(0,s.jsxs)(s.Fragment,{children:[p&&(0,s.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:"Searching…"}),!p&&""!==S.trim()&&0===u.length&&(0,s.jsx)(rT,{children:"No matches."}),u.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(r_,{}),(0,s.jsx)(rO,{heading:h?"Top results (refine query for more)":"Results",children:u.map(t=>(0,s.jsx)(rD,{value:t.path,onSelect:()=>{e(t.path),l(!1),d("")},children:(0,s.jsxs)("div",{className:"flex min-w-0 flex-col gap-0.5",children:[(0,s.jsx)("span",{className:"truncate text-xs",children:t.path}),t.snippet&&(0,s.jsx)("span",{className:"truncate text-xs text-muted-foreground",children:(0,s.jsx)(rz,{html:t.snippet})})]})},t.path))})]})]})]})]})}e.i(262678);let rF=(0,o.default)("cloud-download",[["path",{d:"M12 13v8l-4-4",key:"1f5nwf"}],["path",{d:"m12 21 4-4",key:"1lfcce"}],["path",{d:"M4.393 15.269A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.436 8.284",key:"ui1hmy"}]]);var rH=e.i(301138);let rU=(0,o.default)("eye-off",[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]),rV=(0,o.default)("history",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M12 7v5l4 2",key:"1fdv2h"}]]),rW=(0,o.default)("panel-left-close",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M9 3v18",key:"fh3hqa"}],["path",{d:"m16 15-3-3 3-3",key:"14y99z"}]]),rq=(0,o.default)("plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]),rK=(0,o.default)("settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);var rG=e.i(109680);function rJ({onOpenFile:e}){let t=rL(e=>e.query),n=rL(e=>e.setQuery),r=rL(e=>e.results),i=rL(e=>e.loading),o=rL(e=>e.search),a=rL(e=>e.clear),[l,c]=(0,m.useState)(0),d=(0,m.useRef)(null);function u(t){let n=r[t];n&&(e(n.path),a())}return(0,m.useEffect)(()=>{c(0)},[r]),(0,m.useEffect)(()=>{let e=d.current?.querySelector(`[data-idx="${l}"]`);e?.scrollIntoView({block:"nearest"})},[l]),(0,s.jsxs)("div",{className:"flex flex-col gap-1 px-2 py-1.5",children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)(rC,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 opacity-50"}),(0,s.jsx)("input",{type:"text",className:"w-full rounded-sm bg-muted py-1 pl-7 pr-2 text-xs outline-none focus:ring-1 focus:ring-ring",placeholder:"Search… (⌘K)",value:t,onChange:e=>{n(e.target.value),o(e.target.value)},onKeyDown:e=>{"Escape"===e.key?a():0!==r.length&&("ArrowDown"===e.key?(e.preventDefault(),c(e=>(e+1)%r.length)):"ArrowUp"===e.key?(e.preventDefault(),c(e=>(e-1+r.length)%r.length)):"Enter"===e.key&&(e.preventDefault(),u(l)))}})]}),""!==t.trim()&&(0,s.jsxs)("div",{ref:d,className:"max-h-64 overflow-y-auto rounded-sm border bg-popover",children:[i&&(0,s.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"Searching…"}),!i&&0===r.length&&(0,s.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"No matches"}),r.map((e,t)=>(0,s.jsxs)("button",{type:"button","data-idx":t,onClick:()=>u(t),onMouseEnter:()=>c(t),className:`block w-full px-2 py-1 text-left ${t===l?"bg-accent":"hover:bg-accent"}`,children:[(0,s.jsx)("div",{className:"truncate text-xs",children:e.path}),e.snippet&&(0,s.jsx)("div",{className:"truncate text-[10px] text-muted-foreground",children:(0,s.jsx)(rz,{html:e.snippet})})]},e.path))]})]})}var rZ=e.i(515288);let rX=/^[a-z0-9][a-z0-9-]*$/,rY=new Set(["api","app","s","signin","_next","assets"]);function rQ(){let e,t=ni(e=>e.dialog),n=ni(e=>e.apps),r=ni(e=>e.create),i=ni(e=>e.refresh),o=ni(e=>e.closeHostDialog),[a,l]=(0,m.useState)(""),[c,d]=(0,m.useState)(""),[p,h]=(0,m.useState)([]),[f,g]=(0,m.useState)(!1),[x,b]=(0,m.useState)(null);if((0,m.useEffect)(()=>{t&&(l(t.defaultSlug),d(""),h([]),b(null),i(),"node"===t.type&&(0,tk.wsFetch)(`/api/wiki/app?path=${encodeURIComponent(t.relPath)}`).then(async e=>{if(!e.ok)return;let t=await e.json(),n=t.scripts??[];h(n),d(t.defaultScript??n[0]??"")}).catch(()=>{}))},[t,i]),!t)return null;let y=new Set(n.map(e=>e.slug)),w=(e=a.trim())?rX.test(e)?rY.has(e)?`"${e}" is a reserved name`:y.has(e)?`"${e}" is already taken`:null:"Lowercase letters, numbers, and hyphens only (e.g. my-app)":"Slug is required",k=f||null!==w,N=async()=>{if(w)return;g(!0),b(null);let e=await r({slug:a.trim(),relPath:t.relPath,type:t.type??"html",script:"node"===t.type&&c?c:void 0});g(!1),e.ok?o():b(e.message??e.error??"Failed to host app")};return(0,s.jsx)(B,{open:!!t,onOpenChange:e=>!e&&o(),children:(0,s.jsxs)(eq,{className:"sm:max-w-md",children:[(0,s.jsxs)(eK,{children:[(0,s.jsx)(eJ,{children:"Host this app"}),(0,s.jsxs)(eZ,{children:["Give this directory a short slug. It will be reachable at"," ",(0,s.jsxs)("code",{className:"text-xs",children:["/app/",a||"<slug>","/"]}),"."]})]}),(0,s.jsxs)("div",{className:"space-y-2 py-2",children:[(0,s.jsx)(tw,{htmlFor:"host-slug",children:"Slug"}),(0,s.jsx)(tn.Input,{id:"host-slug",autoFocus:!0,value:a,onChange:e=>{l(e.target.value),b(null)},onKeyDown:e=>{"Enter"!==e.key||k||N()},placeholder:"my-app","aria-invalid":!!(w||x)}),"node"===t.type&&p.length>0&&(0,s.jsxs)("div",{className:"space-y-2",children:[(0,s.jsx)(tw,{htmlFor:"host-script",children:"Start script"}),(0,s.jsx)("select",{id:"host-script",className:"flex h-9 w-full rounded-md border border-input bg-background px-3 py-1 text-sm",value:c,onChange:e=>d(e.target.value),children:p.map(e=>(0,s.jsx)("option",{value:e,children:e},e))})]}),(0,s.jsx)("p",{className:"min-h-[1rem] text-xs text-muted-foreground",children:(0,s.jsx)("span",{className:"truncate",children:t.relPath||"(workspace root)"})}),(w||x)&&(0,s.jsx)("p",{className:"text-xs text-destructive",children:x??w})]}),(0,s.jsxs)(eG,{children:[(0,s.jsx)(v.Button,{variant:"ghost",onClick:o,disabled:f,children:"Cancel"}),(0,s.jsxs)(v.Button,{onClick:()=>void N(),disabled:k,children:[f&&(0,s.jsx)(u.Loader2,{className:"mr-2 h-3.5 w-3.5 animate-spin"}),"Host"]})]})]})})}let r0=(0,o.default)("pin",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]),r1=(0,o.default)("pin-off",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89",key:"znwnzq"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11",key:"c9qhm2"}]]);var r2=e.i(727551);let r5=(0,o.default)("square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);var r3=e.i(638154),r4="Popover",[r6,r9]=(0,N.createContextScope)(r4,[r3.createPopperScope]),r7=(0,r3.createPopperScope)(),[r8,ie]=r6(r4),it=e=>{let{__scopePopover:t,children:n,open:r,defaultOpen:i,onOpenChange:o,modal:a=!1}=e,l=r7(t),c=m.useRef(null),[d,u]=m.useState(!1),[p,h]=(0,C.useControllableState)({prop:r,defaultProp:i??!1,onChange:o,caller:r4});return(0,s.jsx)(r3.Root,{...l,children:(0,s.jsx)(r8,{scope:t,contentId:(0,S.useId)(),triggerRef:c,open:p,onOpenChange:h,onOpenToggle:m.useCallback(()=>h(e=>!e),[h]),hasCustomAnchor:d,onCustomAnchorAdd:m.useCallback(()=>u(!0),[]),onCustomAnchorRemove:m.useCallback(()=>u(!1),[]),modal:a,children:n})})};it.displayName=r4;var ir="PopoverAnchor",ii=m.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=ie(ir,n),o=r7(n),{onCustomAnchorAdd:a,onCustomAnchorRemove:l}=i;return m.useEffect(()=>(a(),()=>l()),[a,l]),(0,s.jsx)(r3.Anchor,{...o,...r,ref:t})});ii.displayName=ir;var is="PopoverTrigger",io=m.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=ie(is,n),o=r7(n),a=(0,k.useComposedRefs)(t,i.triggerRef),l=(0,s.jsx)(T.Primitive.button,{type:"button","aria-haspopup":"dialog","aria-expanded":i.open,"aria-controls":i.contentId,"data-state":iv(i.open),...r,ref:a,onClick:(0,w.composeEventHandlers)(e.onClick,i.onOpenToggle)});return i.hasCustomAnchor?l:(0,s.jsx)(r3.Anchor,{asChild:!0,...o,children:l})});io.displayName=is;var ia="PopoverPortal",[il,ic]=r6(ia,{forceMount:void 0}),id=e=>{let{__scopePopover:t,forceMount:n,children:r,container:i}=e,o=ie(ia,t);return(0,s.jsx)(il,{scope:t,forceMount:n,children:(0,s.jsx)(A.Presence,{present:n||o.open,children:(0,s.jsx)(M.Portal,{asChild:!0,container:i,children:r})})})};id.displayName=ia;var iu="PopoverContent",ip=m.forwardRef((e,t)=>{let n=ic(iu,e.__scopePopover),{forceMount:r=n.forceMount,...i}=e,o=ie(iu,e.__scopePopover);return(0,s.jsx)(A.Presence,{present:r||o.open,children:o.modal?(0,s.jsx)(im,{...i,ref:t}):(0,s.jsx)(ig,{...i,ref:t})})});ip.displayName=iu;var ih=(0,R.createSlot)("PopoverContent.RemoveScroll"),im=m.forwardRef((e,t)=>{let n=ie(iu,e.__scopePopover),r=m.useRef(null),i=(0,k.useComposedRefs)(t,r),o=m.useRef(!1);return m.useEffect(()=>{let e=r.current;if(e)return(0,D.hideOthers)(e)},[]),(0,s.jsx)(_.RemoveScroll,{as:ih,allowPinchZoom:!0,children:(0,s.jsx)(ix,{...e,ref:i,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:(0,w.composeEventHandlers)(e.onCloseAutoFocus,e=>{e.preventDefault(),o.current||n.triggerRef.current?.focus()}),onPointerDownOutside:(0,w.composeEventHandlers)(e.onPointerDownOutside,e=>{let t=e.detail.originalEvent,n=0===t.button&&!0===t.ctrlKey;o.current=2===t.button||n},{checkForDefaultPrevented:!1}),onFocusOutside:(0,w.composeEventHandlers)(e.onFocusOutside,e=>e.preventDefault(),{checkForDefaultPrevented:!1})})})}),ig=m.forwardRef((e,t)=>{let n=ie(iu,e.__scopePopover),r=m.useRef(!1),i=m.useRef(!1);return(0,s.jsx)(ix,{...e,ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:t=>{e.onCloseAutoFocus?.(t),t.defaultPrevented||(r.current||n.triggerRef.current?.focus(),t.preventDefault()),r.current=!1,i.current=!1},onInteractOutside:t=>{e.onInteractOutside?.(t),t.defaultPrevented||(r.current=!0,"pointerdown"===t.detail.originalEvent.type&&(i.current=!0));let s=t.target;n.triggerRef.current?.contains(s)&&t.preventDefault(),"focusin"===t.detail.originalEvent.type&&i.current&&t.preventDefault()}})}),ix=m.forwardRef((e,t)=>{let{__scopePopover:n,trapFocus:r,onOpenAutoFocus:i,onCloseAutoFocus:o,disableOutsidePointerEvents:a,onEscapeKeyDown:l,onPointerDownOutside:c,onFocusOutside:d,onInteractOutside:u,...p}=e,h=ie(iu,n),m=r7(n);return(0,O.useFocusGuards)(),(0,s.jsx)(E.FocusScope,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:i,onUnmountAutoFocus:o,children:(0,s.jsx)(j.DismissableLayer,{asChild:!0,disableOutsidePointerEvents:a,onInteractOutside:u,onEscapeKeyDown:l,onPointerDownOutside:c,onFocusOutside:d,onDismiss:()=>h.onOpenChange(!1),children:(0,s.jsx)(r3.Content,{"data-state":iv(h.open),role:"dialog",id:h.contentId,...m,...p,ref:t,style:{...p.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),ib="PopoverClose";m.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=ie(ib,n);return(0,s.jsx)(T.Primitive.button,{type:"button",...r,ref:t,onClick:(0,w.composeEventHandlers)(e.onClick,()=>i.onOpenChange(!1))})}).displayName=ib;var iy=m.forwardRef((e,t)=>{let{__scopePopover:n,...r}=e,i=r7(n);return(0,s.jsx)(r3.Arrow,{...i,...r,ref:t})});function iv(e){return e?"open":"closed"}function iw(e){let t=(0,ev.apiUrl)(`/app/${e}/`);return`${window.location.origin}${t}`}function ik(){let e=ni(e=>e.collapsed),t=ni(e=>e.toggleCollapsed),n=ni(e=>e.apps),r=ni(e=>e.loading),i=ni(e=>e.loaded),o=ni(e=>e.remove),a=ni(e=>e.start),l=ni(e=>e.stop),d=ni(e=>e.pin),p=ni(e=>e.unpin),f=ni(e=>e.restart),[b,y]=(0,m.useState)(null),[w,k]=(0,m.useState)(null),N=async e=>{try{await navigator.clipboard.writeText(iw(e)),y(e),setTimeout(()=>y(t=>t===e?null:t),1200)}catch{}};return(0,s.jsxs)("div",{className:"border-b mb-1",children:[(0,s.jsxs)("button",{type:"button",className:"flex w-full items-center gap-1 px-2 py-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground hover:text-foreground",onClick:t,children:[e?(0,s.jsx)(eY.ChevronRight,{className:"h-3 w-3"}):(0,s.jsx)(x,{className:"h-3 w-3"}),(0,s.jsx)(e5,{className:"h-3 w-3"}),"Hosted Apps",(0,s.jsx)("span",{className:"ml-auto text-[9px] tabular-nums opacity-60",children:i?n.length:""})]}),!e&&(0,s.jsx)("div",{className:"pb-1",children:r&&0===n.length?(0,s.jsx)("div",{className:"flex justify-center py-3",children:(0,s.jsx)(u.Loader2,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):0===n.length?(0,s.jsx)("p",{className:"px-3 py-2 text-[11px] text-muted-foreground/70",children:"No hosted apps yet. Use “Host this app” from a website directory."}):[...n].sort((e,t)=>Number(!!t.persist)-Number(!!e.persist)).map(e=>{let t,n;return(0,s.jsxs)("div",{role:"button",tabIndex:0,className:"group flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer transition-colors select-none hover:bg-muted",onClick:()=>window.open(iw(e.slug),"_blank"),onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),window.open(iw(e.slug),"_blank"))},children:["node"===e.type?(0,s.jsx)(nt,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500"}):(0,s.jsx)(c,{className:"h-3.5 w-3.5 shrink-0 text-sky-500"}),"node"===e.type&&(t="error"===e.status||"missing"===e.status,n=(0,s.jsx)("span",{className:(0,eh.cn)("h-2 w-2 shrink-0 rounded-full","running"===e.status?"bg-emerald-500":t?"bg-destructive":"bg-muted-foreground/50"),title:e.status??"stopped"}),t?(0,s.jsxs)(it,{open:w===e.slug,onOpenChange:t=>k(t?e.slug:null),children:[(0,s.jsx)(io,{asChild:!0,children:(0,s.jsx)("button",{type:"button",className:"rounded-full focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",onClick:e=>e.stopPropagation(),"aria-label":`Show ${e.status} details for ${e.slug}`,children:n})}),(0,s.jsx)(id,{children:(0,s.jsxs)(ip,{side:"right",align:"start",className:"z-50 w-72 rounded-md border bg-popover p-3 text-popover-foreground shadow-md outline-none",onClick:e=>e.stopPropagation(),children:[(0,s.jsx)("p",{className:"text-xs font-medium text-destructive",children:"missing"===e.status?"Source directory missing":"App stopped after repeated crashes"}),(0,s.jsx)("p",{className:"mt-1 text-xs text-muted-foreground break-words",children:e.lastError??e.error??"No error details available."}),(e.logs?.length??0)>0&&(0,s.jsx)("pre",{className:"mt-2 max-h-28 overflow-auto rounded bg-muted p-2 text-[10px] leading-4 whitespace-pre-wrap",children:e.logs?.slice(-8).join("\n")}),(0,s.jsxs)(v.Button,{size:"sm",variant:"outline",className:"mt-2 h-7 gap-1.5 text-xs",disabled:"missing"===e.status,onClick:()=>{k(null),f(e.slug)},children:[(0,s.jsx)(tA,{className:"h-3 w-3"}),"Restart now"]})]})})]}):n),(0,s.jsx)("span",{className:(0,eh.cn)("min-w-0 flex-1 truncate text-xs","node"===e.type&&("error"===e.status||"missing"===e.status)&&"text-destructive"),children:e.relPath.split("/").filter(Boolean).pop()||e.slug}),(0,s.jsxs)("span",{className:"max-w-[90px] truncate text-[10px] text-muted-foreground/60",children:["/",e.slug]}),"node"===e.type&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("button",{type:"button",className:"hover-reveal shrink-0 rounded p-0.5 text-muted-foreground/50 opacity-0 transition-colors hover:bg-muted hover:text-foreground group-hover:opacity-100 focus:opacity-100",title:e.persist?"Unpin app (disable boot restore)":"Pin app (restore on boot)",onClick:t=>{t.stopPropagation(),e.persist?p(e.slug):d(e.slug)},children:e.persist?(0,s.jsx)(r0,{className:"h-3 w-3 text-primary"}):(0,s.jsx)(r1,{className:"h-3 w-3"})}),(0,s.jsx)("button",{type:"button",className:"hover-reveal shrink-0 rounded p-0.5 text-muted-foreground/50 opacity-0 transition-colors hover:bg-muted hover:text-foreground group-hover:opacity-100 focus:opacity-100",title:"running"===e.status?"Stop app":"Start app",onClick:t=>{t.stopPropagation(),"running"===e.status?l(e.slug):a(e.slug)},children:"running"===e.status?(0,s.jsx)(r5,{className:"h-3 w-3"}):(0,s.jsx)(r2.Play,{className:"h-3 w-3"})})]}),(0,s.jsx)("button",{type:"button",className:"hover-reveal shrink-0 rounded p-0.5 text-muted-foreground/50 opacity-0 transition-colors hover:bg-muted hover:text-foreground group-hover:opacity-100 focus:opacity-100",title:"Copy URL",onClick:t=>{t.stopPropagation(),N(e.slug)},children:b===e.slug?(0,s.jsx)(g.Check,{className:"h-3 w-3 text-emerald-500"}):(0,s.jsx)(e7.Copy,{className:"h-3 w-3"})}),(0,s.jsx)("button",{type:"button",className:(0,eh.cn)("hover-reveal shrink-0 rounded p-0.5 text-muted-foreground/50 opacity-0 transition-colors","hover:bg-muted hover:text-destructive group-hover:opacity-100 focus:opacity-100"),title:"Unhost",onClick:t=>{t.stopPropagation(),o(e.slug)},children:(0,s.jsx)(h,{className:"h-3 w-3"})})]},e.slug)})})]})}function iN({activeWorkspaceId:e,workspaceName:t,openPath:n,onOpen:r}){let[i,o]=(0,m.useState)(!1),[a,l]=(0,m.useState)(null);return((0,m.useEffect)(()=>{if(!e)return;let t=!1;return(async()=>{try{let e=await (0,tk.wsFetch)("/api/wiki/app?path=");if(!e.ok)return;let n=await e.json();if(t)return;o(!!n.isNodeApp),l(n.status??null)}catch{}})(),()=>{t=!0}},[e]),i)?(0,s.jsx)("div",{className:"border-b mb-1 px-2 py-1.5",children:(0,s.jsxs)("button",{type:"button",onClick:r,className:(0,eh.cn)("group flex w-full items-center gap-1.5 rounded-sm px-2 py-1 text-sm transition-colors",""===n?"bg-accent-soft text-foreground font-medium":"hover:bg-muted"),children:[(0,s.jsx)(nt,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500"}),(0,s.jsx)("span",{className:"min-w-0 flex-1 truncate text-left text-xs",children:t}),"running"===a?(0,s.jsx)("span",{className:"h-2 w-2 shrink-0 rounded-full bg-emerald-500",title:"Running"}):(0,s.jsx)(r2.Play,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground/60 group-hover:text-foreground"})]})}):null}function iS(e){let t=new Date(e).getTime();if(!Number.isFinite(t))return"";let n=Math.floor(Math.max(0,Date.now()-t)/1e3);if(n<60)return"just now";let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:`${Math.floor(i/24)}d ago`}function iC({workspaces:e,activeWorkspaceId:t,rootPath:n,isWsAdmin:r,refreshingWsId:i,switchingBranch:o,switchingBranchName:a,wsBranches:l,branchPickerWsId:c,wsBranchPos:d,onSwitchWorkspace:u,onRefreshWorkspace:p,onPromptDeleteWorkspace:h,onAddWorkspace:m,setBranchPickerWsId:f,setWsBranchPos:b,loadWsBranches:y,handleSwitchBranch:w}){return(0,s.jsxs)("div",{className:"border-t px-2 py-2 bg-muted shrink-0",children:[(0,s.jsxs)(ek.DropdownMenu,{modal:!1,onOpenChange:e=>{e||(f(null),b(null))},children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsxs)(v.Button,{size:"sm",variant:"ghost",className:"w-full h-auto justify-between gap-2 px-2 py-1.5 text-left",title:n??"",children:[(0,s.jsxs)("span",{className:"flex flex-col min-w-0",children:[(0,s.jsx)("span",{className:"truncate text-xs font-medium",children:e.find(e=>e.id===t)?.name??"Workspace"}),(0,s.jsx)("span",{className:"truncate text-[10px] text-muted-foreground",children:n??""})]}),(0,s.jsx)(x,{className:"h-3.5 w-3.5 shrink-0 opacity-60"})]})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"start",className:"w-[var(--radix-dropdown-menu-trigger-width)]",onInteractOutside:e=>{e.target?.closest?.("[data-branch-portal]")&&e.preventDefault()},children:[e.map(e=>(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>void u(e.id),onPointerMove:e=>e.preventDefault(),onPointerLeave:e=>e.preventDefault(),className:(0,eh.cn)("gap-2",e.id===t&&"font-medium"),children:[e.id===t?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 shrink-0"}):(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsxs)("span",{className:"flex flex-col min-w-0 flex-1",children:[(0,s.jsxs)("span",{className:"flex items-center gap-1.5 truncate",children:[(0,s.jsx)("span",{className:"truncate",children:e.name}),e.git?r?(0,s.jsxs)("button",{"data-branch-trigger":!0,type:"button",className:"inline-flex items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground font-normal shrink-0 hover:bg-accent",title:"Switch branch",disabled:o===e.id,onClick:t=>{if(t.stopPropagation(),t.preventDefault(),c===e.id){f(null),b(null);return}let n=t.currentTarget.getBoundingClientRect();b({top:n.bottom+4,left:n.left}),f(e.id),y(e.id)},children:[(0,s.jsx)(e1,{className:"h-2.5 w-2.5"})," ",e.git.branch??"branch"]}):(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground font-normal shrink-0",children:[(0,s.jsx)(e1,{className:"h-2.5 w-2.5"})," ",e.git.branch??"read-only"]}):e.ssh?(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground font-normal shrink-0",children:[(0,s.jsx)(e5,{className:"h-2.5 w-2.5"})," ",e.ssh.host]}):e.readOnly?(0,s.jsxs)("span",{className:"inline-flex items-center gap-0.5 rounded bg-muted px-1.5 text-[10px] text-muted-foreground font-normal shrink-0",children:[(0,s.jsx)(e1,{className:"h-2.5 w-2.5"})," read-only"]}):null]}),(0,s.jsx)("span",{className:"truncate text-[10px] text-muted-foreground",children:e.rootDir}),e.git?.lastPulledAt&&iS(e.git.lastPulledAt)&&(0,s.jsxs)("span",{className:"text-[10px] text-muted-foreground/70",children:["synced ",iS(e.git.lastPulledAt)]})]}),r&&e.git&&(0,s.jsx)("button",{className:(0,eh.cn)("shrink-0 rounded p-0.5 hover:bg-accent transition-colors",e.git.lastError?"text-destructive":"text-muted-foreground hover:text-foreground"),title:e.git.lastError?`Last refresh failed: ${e.git.lastError}`:"Refresh",disabled:i===e.id,onClick:t=>{t.stopPropagation(),t.preventDefault(),p(e.id)},children:(0,s.jsx)(tA,{className:(0,eh.cn)("h-3.5 w-3.5",i===e.id&&"animate-spin")})}),r&&(0,s.jsx)("button",{className:"shrink-0 rounded p-0.5 text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors",title:"Delete workspace (does not delete files)",onClick:t=>{t.stopPropagation(),h(e.id)},children:(0,s.jsx)(te,{className:"h-3.5 w-3.5"})})]},e.id)),r&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:m,children:[(0,s.jsx)(t8,{className:"mr-2 h-3.5 w-3.5"}),"Add workspace…"]})]})]})]}),(()=>{if(!c||!d)return null;let t=e.find(e=>e.id===c);return t?(0,s.jsx)(ns,{pos:d,branches:(l[t.id]??[]).map(e=>({name:e,current:e===t.git?.branch})),loading:!l[t.id],busyName:o===t.id?a:null,disabled:o===t.id,onPick:e=>{w(t.id,e)},onClose:()=>{f(null),b(null)}}):null})()]})}iy.displayName="PopoverArrow";let ij="wiki-sidebar-width";function iE(e){return Number.isNaN(e)?288:Math.min(600,Math.max(200,Math.round(e)))}let iM=(0,eN.create)(e=>({width:function(){let e=localStorage.getItem(ij);if(e){let t=Number.parseInt(e,10);if(!Number.isNaN(t))return iE(t)}return 288}(),setWidth:t=>{let n=iE(t);localStorage.setItem(ij,String(n)),e({width:n})}}));function iA(e){return e.split("/").pop()??e}function iT({workspace:e,doc:t,fileTree:n,upload:r,isMobile:i,hideChrome:o,sidebarCollapsed:c,setSidebarCollapsed:d,sidebarResizing:p,setSidebarResizing:m,sidebarWidth:b,setSidebarWidth:y,collapsed:w,setCollapsed:k,createEntry:N,setCreateEntry:S,handleCreateFile:C,handleCreateFolder:j,dragOverPath:E,setDragOverPath:M,handleDragOver:A,handleDropOnFolder:T,sidebarScrollRef:O,treeCtx:_,favorites:D,recents:R,activePaths:I,setDialogs:L,handleRefreshWorkspace:P}){let{resolvedTheme:$,setTheme:z}=(0,n5.useTheme)(),B=nR(e=>e.humanize),F=nL(e=>e.showHidden);return(0,s.jsxs)(s.Fragment,{children:[!o&&!c&&i&&(0,s.jsx)("div",{className:"fixed inset-0 z-40 bg-overlay backdrop-blur-[1px] md:hidden",onClick:()=>d(!0),"aria-hidden":!0}),!o&&!c&&(0,s.jsxs)(rZ.Card,{style:i?void 0:{width:b},className:"fixed inset-y-0 left-0 z-50 w-[85vw] max-w-[20rem] md:relative md:z-auto md:w-auto md:max-w-none flex flex-col shrink-0 overflow-hidden rounded-none border-r border-l-0 border-t-0 border-b-0 bg-sidebar border-sidebar-border text-sidebar-foreground",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between gap-2 px-3 py-2 border-b bg-muted shrink-0",children:[(0,s.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",title:"Wiki Viewer v2.18.2",children:[(0,s.jsx)("img",{src:(0,ev.apiUrl)("/logo.svg"),alt:"Wiki Viewer",className:"h-5 w-5 shrink-0"}),(0,s.jsx)("span",{className:"truncate text-xs font-semibold leading-5 tracking-tight translate-y-[0.5px]",children:"Wiki Viewer"})]}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 shrink-0",title:"Collapse sidebar",onClick:()=>d(!0),children:(0,s.jsx)(rW,{className:"h-3.5 w-3.5"})})]}),(0,s.jsxs)("div",{className:"flex items-center justify-between gap-1 px-3 py-1.5 border-b bg-muted/50 shrink-0",children:[(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsxs)(v.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1 px-2 text-xs",disabled:r.uploading,children:[r.uploading?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(rq,{className:"h-3.5 w-3.5"}),"New",(0,s.jsx)(x,{className:"h-3 w-3 opacity-60"})]})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"start",className:"w-44",children:[(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>S(e=>({...e,file:{...e.file,parent:"",name:"",error:null}})),children:[(0,s.jsx)(t7,{className:"mr-2 h-3.5 w-3.5"}),"New file"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>S(e=>({...e,file:{...e.file,parent:"",name:"untitled.excalidraw",error:null}})),children:[(0,s.jsx)(ne.PencilRuler,{className:"mr-2 h-3.5 w-3.5"}),"New canvas"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>S(e=>({...e,folder:{...e.folder,parent:"",name:"",error:null}})),children:[(0,s.jsx)(t8,{className:"mr-2 h-3.5 w-3.5"}),"New folder"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>r.triggerUpload(""),disabled:r.uploading,children:[(0,s.jsx)(nn,{className:"mr-2 h-3.5 w-3.5"}),"Upload"]})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Refresh tree",onClick:()=>void n.refreshTree(),disabled:n.refreshingTree,children:n.refreshingTree?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(tA,{className:"h-3.5 w-3.5"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"AI Agent panel",onClick:()=>{tj.getState().toggle(),i&&d(!0)},children:(0,s.jsx)(a,{className:"h-3.5 w-3.5"})}),(0,s.jsxs)(ek.DropdownMenu,{children:[(0,s.jsx)(ek.DropdownMenuTrigger,{asChild:!0,children:(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"More actions",children:(0,s.jsx)(t6,{className:"h-3.5 w-3.5"})})}),(0,s.jsxs)(ek.DropdownMenuContent,{align:"end",className:"w-48",children:[e.isWsAdmin&&e.workspaces.find(t=>t.id===e.activeWorkspaceId)?.git&&(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>{e.activeWorkspaceId&&P(e.activeWorkspaceId)},disabled:e.refreshingWsId===e.activeWorkspaceId,children:[e.refreshingWsId===e.activeWorkspaceId?(0,s.jsx)(u.Loader2,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(rF,{className:"mr-2 h-3.5 w-3.5"}),"Pull latest"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>nL.getState().toggle(),children:[F?(0,s.jsx)(rU,{className:"mr-2 h-3.5 w-3.5"}):(0,s.jsx)(rH.Eye,{className:"mr-2 h-3.5 w-3.5"}),F?"Hide hidden files":"Show hidden files"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>nR.getState().toggle(),children:[(0,s.jsx)(rG.Type,{className:"mr-2 h-3.5 w-3.5"}),B?"Raw file names":"Humanize names"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>z("dark"===$?"light":"dark"),children:["dark"===$?(0,s.jsx)(n2.Sun,{className:"mr-2 h-3.5 w-3.5"}):(0,s.jsx)(n0.Moon,{className:"mr-2 h-3.5 w-3.5"}),"dark"===$?"Light mode":"Dark mode"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>L(e=>({...e,settingsOpen:!0})),children:[(0,s.jsx)(rK,{className:"mr-2 h-3.5 w-3.5"}),"Settings"]})]})]})]})]}),r.uploadError&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-3 py-1.5 text-xs text-destructive bg-destructive/10 shrink-0",children:[(0,s.jsx)(f.AlertCircle,{className:"h-3.5 w-3.5 shrink-0"}),r.uploadError]}),""===N.folder.parent&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,s.jsx)(eQ,{className:"h-4 w-4 shrink-0 text-warning"}),(0,s.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"Folder name",value:N.folder.name,onChange:e=>S(t=>({...t,folder:{...t.folder,name:e.target.value}})),onKeyDown:e=>{"Enter"===e.key&&j(),"Escape"===e.key&&S(e=>({...e,folder:{...e.folder,parent:null,name:""}}))}}),N.folder.error&&(0,s.jsx)("span",{className:"text-xs text-destructive",children:N.folder.error}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:j,children:(0,s.jsx)(g.Check,{className:"h-3 w-3"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>S(e=>({...e,folder:{...e.folder,parent:null,name:""}})),children:(0,s.jsx)(h,{className:"h-3 w-3"})})]}),""===N.file.parent&&(0,s.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,s.jsx)(l.FileText,{className:"h-4 w-4 shrink-0 text-accent"}),(0,s.jsx)("input",{autoFocus:!0,className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"filename (default .md)",value:N.file.name,onChange:e=>S(t=>({...t,file:{...t.file,name:e.target.value}})),onKeyDown:e=>{"Enter"===e.key&&C(),"Escape"===e.key&&S(e=>({...e,file:{...e.file,parent:null,name:""}}))}}),N.file.error&&(0,s.jsx)("span",{className:"text-xs text-destructive",children:N.file.error}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:C,children:(0,s.jsx)(g.Check,{className:"h-3 w-3"})}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>S(e=>({...e,file:{...e.file,parent:null,name:""}})),children:(0,s.jsx)(h,{className:"h-3 w-3"})})]}),(0,s.jsx)("div",{className:"border-b",children:(0,s.jsx)(rJ,{onOpenFile:t.openFromSearch})}),(0,s.jsxs)("div",{ref:O,className:(0,eh.cn)("flex-1 overflow-auto py-1 ",""===E&&"ring-2 ring-inset ring-primary bg-primary/5"),onDragOver:e=>A(e,"","root"),onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||M(null)},onDrop:e=>T(e,""),children:[D.length>0&&(0,s.jsxs)("div",{className:"border-b mb-1",children:[(0,s.jsxs)("button",{type:"button",className:"flex w-full items-center gap-1 px-2 py-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground hover:text-foreground",onClick:()=>k(e=>({...e,favorites:!e.favorites})),children:[w.favorites?(0,s.jsx)(eY.ChevronRight,{className:"h-3 w-3"}):(0,s.jsx)(x,{className:"h-3 w-3"}),(0,s.jsx)(e4,{className:"h-3 w-3"}),"Favorites",(0,s.jsx)("span",{className:"ml-auto text-[9px] tabular-nums opacity-60",children:D.length})]}),!w.favorites&&D.map(n=>(0,s.jsxs)(nm,{children:[(0,s.jsx)(ng,{asChild:!0,children:(0,s.jsxs)("div",{role:"button",tabIndex:0,className:(0,eh.cn)("group flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer transition-colors select-none",t.openFile?.path===n.path?"bg-accent-soft text-foreground font-medium":"hover:bg-muted"),onClick:()=>{t.openFavoriteEntry(n)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),t.openFavoriteEntry(n))},children:[(0,s.jsx)(nq,{name:n.name,type:n.type??"file"}),(0,s.jsx)("span",{className:"min-w-0 flex-1 truncate text-xs",title:B?n.name:void 0,children:B?iA(n.name):n.name}),(0,s.jsx)("span",{className:"max-w-[80px] truncate text-[10px] text-muted-foreground/60",children:n.path.split("/").slice(0,-1).join("/")}),(0,s.jsx)("button",{type:"button",className:"hover-reveal shrink-0 rounded p-0.5 text-muted-foreground/50 opacity-0 transition-colors hover:bg-muted hover:text-amber-400 group-hover:opacity-100 focus:opacity-100",title:"Remove from favorites",onClick:t=>{t.stopPropagation(),nX.getState().toggle({path:n.path,name:n.name},e.activeWorkspaceId)},children:(0,s.jsx)(h,{className:"h-3 w-3"})})]})}),(0,s.jsx)(nW,{node:{path:n.path,name:n.name,type:n.type??"file"},ctx:_,isFavorited:!0,activeWorkspaceId:e.activeWorkspaceId})]},n.path))]}),R.length>0&&(0,s.jsxs)("div",{className:"border-b mb-1",children:[(0,s.jsxs)("button",{type:"button",className:"flex w-full items-center gap-1 px-2 py-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground hover:text-foreground",onClick:()=>k(e=>({...e,recent:!e.recent})),children:[w.recent?(0,s.jsx)(eY.ChevronRight,{className:"h-3 w-3"}):(0,s.jsx)(x,{className:"h-3 w-3"}),(0,s.jsx)(rV,{className:"h-3 w-3"}),"Recent",(0,s.jsx)("span",{className:"ml-auto text-[9px] tabular-nums opacity-60",children:R.length})]}),!w.recent&&R.slice(0,8).map(n=>(0,s.jsxs)(nm,{children:[(0,s.jsx)(ng,{asChild:!0,children:(0,s.jsxs)("div",{role:"button",tabIndex:0,className:(0,eh.cn)("flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer transition-colors select-none",t.openFile?.path===n.path?"bg-accent-soft text-foreground font-medium":"hover:bg-muted"),onClick:()=>{t.openViewer({path:n.path,name:n.name,type:n.type??"file",modifiedAt:""}),i&&d(!0)},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),t.openViewer({path:n.path,name:n.name,type:n.type??"file",modifiedAt:""}))},children:[(0,s.jsx)(nq,{name:n.name,type:n.type??"file"}),(0,s.jsx)("span",{className:"flex-1 truncate text-xs",title:B?n.name:void 0,children:B?iA(n.name):n.name}),(0,s.jsx)("span",{className:"text-[10px] text-muted-foreground/60 truncate max-w-[80px]",children:n.path.split("/").slice(0,-1).join("/")})]})}),(0,s.jsx)(nW,{node:{path:n.path,name:n.name,type:n.type??"file"},ctx:_,isFavorited:D.some(e=>e.path===n.path),activeWorkspaceId:e.activeWorkspaceId})]},n.path))]}),(0,s.jsx)(iN,{activeWorkspaceId:e.activeWorkspaceId,workspaceName:e.workspaces.find(t=>t.id===e.activeWorkspaceId)?.name??"App",openPath:t.openFile?.path??null,onOpen:()=>{t.openViewer({path:"",name:e.workspaces.find(t=>t.id===e.activeWorkspaceId)?.name??"App",type:"node-app",modifiedAt:""}),i&&d(!0)}}),(0,s.jsx)(ik,{}),n.rootLoading?(0,s.jsx)("div",{className:"flex justify-center py-6",children:(0,s.jsx)(u.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):0===n.roots.length?(0,s.jsxs)("div",{className:"flex flex-col items-center gap-3 px-4 py-8 text-center",children:[(0,s.jsx)("div",{className:"rounded-full bg-muted p-3",children:(0,s.jsx)(l.FileText,{className:"h-6 w-6 text-muted-foreground"})}),(0,s.jsxs)("div",{className:"space-y-1",children:[(0,s.jsx)("p",{className:"text-sm font-medium",children:"No files yet"}),(0,s.jsx)("p",{className:"text-xs text-muted-foreground",children:"Upload files or add them to the configured directory"})]}),(0,s.jsxs)(v.Button,{size:"sm",variant:"outline",className:"w-full gap-1.5 max-w-[180px]",onClick:()=>r.triggerUpload(""),disabled:r.uploading,children:[r.uploading?(0,s.jsx)(u.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,s.jsx)(nn,{className:"h-3.5 w-3.5"}),"Upload Files"]})]}):(0,s.jsx)(nG,{ctx:_,nodes:n.roots,openPath:t.openFile?.path??null,dragOverPath:E,branchDropdownNode:n.branchDropdownNode,branchDropdownPos:n.branchDropdownPos,nodeBranches:n.nodeBranches,branchesLoading:n.branchesLoading,checkingOutBranch:n.checkingOutBranch,pullingRepo:n.pullingRepo,activePaths:I,favorites:D,isMobile:i,activeWorkspaceId:e.activeWorkspaceId,newFileParent:N.file.parent,newFileName:N.file.name,fileCreateError:N.file.error,newFolderParent:N.folder.parent,newFolderName:N.folder.name,folderError:N.folder.error,sidebarScrollRef:O})]}),(0,s.jsx)(iC,{workspaces:e.workspaces,activeWorkspaceId:e.activeWorkspaceId,rootPath:e.rootPath,isWsAdmin:e.isWsAdmin,refreshingWsId:e.refreshingWsId,switchingBranch:e.switchingBranch,switchingBranchName:e.switchingBranchName,wsBranches:e.wsBranches,branchPickerWsId:e.branchPickerWsId,wsBranchPos:e.wsBranchPos,onSwitchWorkspace:t=>void e.switchWorkspace(t),onRefreshWorkspace:e.handleRefreshWorkspace,onPromptDeleteWorkspace:t=>e.setDeletingWorkspaceId(t),onAddWorkspace:()=>e.setAddingWorkspace(!0),setBranchPickerWsId:e.setBranchPickerWsId,setWsBranchPos:e.setWsBranchPos,loadWsBranches:e.loadWsBranches,handleSwitchBranch:e.handleSwitchBranch}),(0,s.jsx)("div",{role:"separator","aria-orientation":"vertical","aria-label":"Resize sidebar",title:"Drag to resize",onMouseDown:e=>{e.preventDefault();let t=e.clientX;m(!0);let n=document.body.style.cursor,r=document.body.style.userSelect;document.body.style.cursor="col-resize",document.body.style.userSelect="none";let i=e=>{y(b+(e.clientX-t))},s=()=>{m(!1),document.body.style.cursor=n,document.body.style.userSelect=r,window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",i),window.addEventListener("mouseup",s)},onDoubleClick:()=>y(288),onKeyDown:e=>{"ArrowLeft"===e.key?(e.preventDefault(),y(b-16)):"ArrowRight"===e.key&&(e.preventDefault(),y(b+16))},tabIndex:0,"aria-valuemin":200,"aria-valuemax":600,"aria-valuenow":b,className:(0,eh.cn)("absolute right-0 top-0 z-20 h-full w-1.5 cursor-col-resize -mr-px transition-colors hover:bg-primary/40 focus:bg-primary/40 focus:outline-none hidden md:block",p&&"bg-primary/60")})]}),(0,s.jsx)(rQ,{})]})}function iO({workspace:e,doc:t,fileTree:n,upload:r,isMobile:i,hideChrome:o,sidebarCollapsed:a,setSidebarCollapsed:l,favorites:c,recents:d,activePaths:u,setDeleting:p,setDialogs:h}){let[f,g]=(0,m.useState)(!1),[x,b]=(0,m.useState)(null),[y,v]=(0,m.useState)({favorites:!1,recent:!0}),[w,k]=(0,m.useState)({file:{parent:null,name:"",error:null},folder:{parent:null,name:"",error:null}}),N=(0,m.useRef)(null),S=(0,m.useRef)(null),C=iM(e=>e.width),j=iM(e=>e.setWidth),E=(0,m.useCallback)(async()=>{let e=w.file.name.trim();if(!e||null===w.file.parent)return;k(e=>({...e,file:{...e.file,error:null}}));let r=e.includes(".")?e:`${e}.md`,i=w.file.parent?`${w.file.parent}/${r}`:r,s=await fetch((0,tk.withWs)("/api/wiki/new-file"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:i})});if(s.ok){let e=w.file.parent;k(e=>({...e,file:{parent:null,name:"",error:null}})),await n.reloadDir(e),t.openViewer({path:i,name:r,type:"file",modifiedAt:new Date().toISOString()})}else{let e=await s.json();k(t=>({...t,file:{...t.file,error:e.error??"Failed"}}))}},[w.file.parent,w.file.name,n,t]),M=(0,m.useCallback)(async()=>{let e=w.folder.name.trim();if(!e||null===w.folder.parent)return;k(e=>({...e,folder:{...e.folder,error:null}}));let t=w.folder.parent?`${w.folder.parent}/${e}`:e,r=await fetch((0,tk.withWs)("/api/wiki/folder"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(r.ok){let e=w.folder.parent;k(e=>({...e,folder:{parent:null,name:"",error:null}})),await n.reloadDir(e)}else{let e=await r.json();k(t=>({...t,folder:{...t.folder,error:e.error??"Failed"}}))}},[w.folder.parent,w.folder.name,n]);function A(e,t,n){e.preventDefault(),e.stopPropagation();let r=S.current;if(!r){Array.from(e.dataTransfer.types).includes("Files")&&(e.dataTransfer.dropEffect="copy",b("root"===n?"":t));return}r.path===t||t.startsWith(`${r.path}/`)||(e.dataTransfer.dropEffect="move",b("root"===n?"":t))}async function T(e,i){e.preventDefault(),e.stopPropagation(),b(null);let s=S.current;if(S.current=null,!s){e.dataTransfer.files.length>0&&await r.doUpload(e.dataTransfer.files,i);return}if(s.path===i||i.startsWith(`${s.path}/`))return;let o=i?`${i}/${s.name}`:s.name;if(o!==s.path&&(await fetch((0,tk.withWs)("/api/wiki/move"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({from:s.path,to:o})})).ok){let e=s.path.includes("/")?s.path.split("/").slice(0,-1).join("/"):"";await n.reloadDir(e),i!==e&&await n.reloadDir(i),t.openFile?.path===s.path&&t.openViewer({path:o,name:s.name,type:s.type,modifiedAt:s.modifiedAt})}}let O=(0,m.useRef)(null);O.current={toggleFolder:e=>void n.toggleFolder(e),openViewer:e=>void t.openViewer(e),copyPath:e=>t.copyPath(e),copyWikiLink:e=>t.copyWikiLink(e),copyUrl:e=>t.copyUrl(e),copyRawContent:e=>void t.copyRawContent(e),copyFormattedContent:(e,n)=>void t.copyFormattedContent(e,n),handleDownload:function(e){let t=(0,tk.withWs)(`/api/wiki/download?path=${encodeURIComponent(e.path)}`),n=document.createElement("a");n.href=t,n.download="file"===e.type?e.name:`${e.name}.zip`,document.body.appendChild(n),n.click(),n.remove()},triggerUpload:e=>r.triggerUpload(e),handleCreateFile:E,handleCreateFolder:M,handleDragStart:function(e,t){S.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t.path)},handleDragOver:A,handleDropOnFolder:(e,t)=>void T(e,t),handleGitPull:(e,t)=>void n.handleGitPull(e,t),handleCheckout:(e,t,r)=>void n.handleCheckout(e,t,r),loadBranches:e=>void n.loadBranches(e),prefetch:e=>void n.prefetch(e),toggleFavorite:(e,t)=>nX.getState().toggle({path:e.path,name:e.name,type:e.type},t),setDragOverPath:b,setSidebarCollapsed:l,setBranchDropdownNode:e=>n.setBranchDropdownNode(e),setBranchDropdownPos:e=>n.setBranchDropdownPos(e),setNewFileParent:e=>k(t=>({...t,file:{...t.file,parent:e,error:null}})),setNewFileName:e=>k(t=>({...t,file:{...t.file,name:e}})),setFileCreateError:e=>k(t=>({...t,file:{...t.file,error:e}})),setNewFolderParent:e=>k(t=>({...t,folder:{...t.folder,parent:e,error:null}})),setNewFolderName:e=>k(t=>({...t,folder:{...t.folder,name:e}})),setFolderError:e=>k(t=>({...t,folder:{...t.folder,error:e}})),setDeletingPath:e=>p(t=>({...t,path:e})),setDeletingIsDir:e=>p(t=>({...t,isDir:e}))};let _=(0,m.useMemo)(()=>({toggleFolder:e=>O.current.toggleFolder(e),openViewer:e=>O.current.openViewer(e),copyPath:e=>O.current.copyPath(e),copyWikiLink:e=>O.current.copyWikiLink(e),copyUrl:e=>O.current.copyUrl(e),copyRawContent:e=>O.current.copyRawContent(e),copyFormattedContent:(e,t)=>O.current.copyFormattedContent(e,t),handleDownload:e=>O.current.handleDownload(e),triggerUpload:e=>O.current.triggerUpload(e),handleCreateFile:()=>O.current.handleCreateFile(),handleCreateFolder:()=>O.current.handleCreateFolder(),handleDragStart:(e,t)=>O.current.handleDragStart(e,t),handleDragOver:(e,t,n)=>O.current.handleDragOver(e,t,n),handleDropOnFolder:(e,t)=>O.current.handleDropOnFolder(e,t),handleGitPull:(e,t)=>O.current.handleGitPull(e,t),handleCheckout:(e,t,n)=>O.current.handleCheckout(e,t,n),loadBranches:e=>O.current.loadBranches(e),prefetch:e=>O.current.prefetch(e),toggleFavorite:(e,t)=>O.current.toggleFavorite(e,t),setDragOverPath:e=>O.current.setDragOverPath(e),setSidebarCollapsed:e=>O.current.setSidebarCollapsed(e),setBranchDropdownNode:e=>O.current.setBranchDropdownNode(e),setBranchDropdownPos:e=>O.current.setBranchDropdownPos(e),setNewFileParent:e=>O.current.setNewFileParent(e),setNewFileName:e=>O.current.setNewFileName(e),setFileCreateError:e=>O.current.setFileCreateError(e),setNewFolderParent:e=>O.current.setNewFolderParent(e),setNewFolderName:e=>O.current.setNewFolderName(e),setFolderError:e=>O.current.setFolderError(e),setDeletingPath:e=>O.current.setDeletingPath(e),setDeletingIsDir:e=>O.current.setDeletingIsDir(e)}),[]);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(rB,{onOpenFile:t.openFromSearch,recents:d,onToggleSidebar:()=>l(e=>{let t=!e;return i&&!1===t&&tj.getState().close(),t}),onNewFile:()=>k(e=>({...e,file:{...e.file,parent:""}})),onCopyPath:()=>{t.openFile&&t.copyPath(t.openFile.path)}}),(0,s.jsx)(iT,{workspace:e,doc:t,fileTree:n,upload:r,isMobile:i,hideChrome:o,sidebarCollapsed:a,setSidebarCollapsed:l,sidebarResizing:f,setSidebarResizing:g,sidebarWidth:C,setSidebarWidth:j,collapsed:y,setCollapsed:v,createEntry:w,setCreateEntry:k,handleCreateFile:E,handleCreateFolder:M,dragOverPath:x,setDragOverPath:b,handleDragOver:A,handleDropOnFolder:T,sidebarScrollRef:N,treeCtx:_,favorites:c,recents:d,activePaths:u,setDialogs:h,handleRefreshWorkspace:e.handleRefreshWorkspace})]})}let i_=(0,o.default)("code-xml",[["path",{d:"m18 16 4-4-4-4",key:"1inbqp"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}],["path",{d:"m14.5 4-5 16",key:"e7oirm"}]]),iD=(0,o.default)("file-plus-2",[["path",{d:"M4 22h14a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v4",key:"1pf5j1"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M3 15h6",key:"4e2qda"}],["path",{d:"M6 12v6",key:"1u72j0"}]]),iR=(0,o.default)("maximize-2",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]]),iI=(0,o.default)("pencil",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]]),iL=(0,o.default)("share",[["path",{d:"M12 2v13",key:"1km8f5"}],["path",{d:"m16 6-4-4-4 4",key:"13yo43"}],["path",{d:"M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8",key:"1b2hhj"}]]),iP=(0,o.default)("user",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);var i$=e.i(905381),iz=e.i(801273),iB=e.i(61086);function iF(e){let t=[],n="",r=!1,i=[];for(let s=0;s<e.length;s++){let o=e[s],a=e[s+1];r?'"'===o&&'"'===a?(n+='"',s++):'"'===o?r=!1:n+=o:'"'===o?r=!0:","===o?(i.push(n),n=""):"\n"===o||"\r"===o&&"\n"===a?(i.push(n),n="",i.length>0&&t.push(i),i=[],"\r"===o&&s++):n+=o}return i.push(n),i.some(e=>""!==e)&&t.push(i),t}function iH(e){return e.map(e=>e.map(e=>e.includes(",")||e.includes('"')||e.includes("\n")?`"${e.replace(/"/g,'""')}"`:e).join(",")).join("\n")}function iU({path:e}){let[t,n]=(0,m.useState)([]),[r,i]=(0,m.useState)(""),[o,a]=(0,m.useState)(!1),[l,c]=(0,m.useState)(!1),[d,u]=(0,m.useState)(!1),[p,h]=(0,m.useState)(null),[f,g]=(0,m.useState)(!1),[x,b]=(0,m.useState)(1e3),y=(0,tk.withWs)(`/api/assets/${e}`);(0,m.useEffect)(()=>{fetch(y).then(e=>e.text()).then(e=>{let t=iF(e),r=e.length>2097152||t.length>2e3;i(e),n(t),g(r),a(r),c(!1)})},[y]);let w=(0,m.useCallback)((e,t,r)=>{n(n=>{let i=n.map(e=>[...e]);for(;i.length<=e;)i.push([]);for(;i[e].length<=t;)i[e].push("");return i[e][t]=r,i}),c(!0)},[]),k=async()=>{u(!0);let s=o?r:iH(t);try{await (0,tk.wsFetch)(`/api/assets/${e}`,{method:"PUT",headers:{"Content-Type":"text/plain"},body:s}),o?n(iF(r)):i(s),c(!1)}catch(e){console.error("Failed to save CSV:",e)}u(!1)},N=t[0]||[],S=t.slice(1),C=f?S.slice(0,x):S,j=f&&x<S.length;return(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)(iB.ViewerToolbar,{path:e,badge:`CSV${t.length>0?` (${t.length-1} rows)`:""}`,children:[l&&(0,s.jsxs)(v.Button,{variant:"ghost",size:"sm",className:"h-7 gap-1.5 text-xs",onClick:k,disabled:d,children:[(0,s.jsx)(iz.Save,{className:"h-3.5 w-3.5"}),d?"Saving...":"Save"]}),f&&(0,s.jsxs)("span",{className:"text-[11px] text-amber-600 dark:text-amber-400 px-1",children:["Large file (",(r.length/1048576).toFixed(1)," MB,"," ",t.length.toLocaleString()," rows)"]}),(0,s.jsxs)("button",{onClick:()=>{o?n(iF(r)):i(iH(t)),a(!o)},className:`flex items-center gap-1.5 px-2.5 py-1 text-[11px] rounded-md transition-colors border border-border ${o?"bg-primary text-primary-foreground":"text-muted-foreground hover:bg-accent"}`,children:[(0,s.jsx)(i_,{className:"h-3 w-3"}),o?"Table":"Source"]}),(0,s.jsx)("button",{onClick:()=>window.open(y,"_blank"),className:"inline-flex items-center justify-center rounded-md h-8 w-8 hover:bg-accent hover:text-accent-foreground transition-colors cursor-pointer",title:"Download CSV",children:(0,s.jsx)(t3.Download,{className:"h-4 w-4"})})]}),o?(0,s.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:(0,s.jsx)("textarea",{value:r,onChange:e=>{i(e.target.value),c(!0)},className:"w-full h-full min-h-[calc(100vh-12rem)] bg-transparent font-mono text-[13px] leading-relaxed resize-none focus:outline-none",spellCheck:!1})}):(0,s.jsxs)("div",{className:"flex-1 overflow-auto",children:[(0,s.jsxs)("table",{className:"w-full border-collapse text-[13px]",children:[(0,s.jsx)("thead",{className:"sticky top-0 z-10",children:(0,s.jsxs)("tr",{className:"bg-muted/80 backdrop-blur-sm",children:[(0,s.jsx)("th",{className:"border border-border px-1 py-1 text-center text-[10px] text-muted-foreground w-8",children:"#"}),N.map((e,t)=>(0,s.jsx)("th",{className:"border border-border px-3 py-1.5 text-left font-medium text-foreground min-w-[100px]",children:p?.r===0&&p?.c===t?(0,s.jsx)("input",{autoFocus:!0,className:"w-full bg-transparent outline-none",value:e,onChange:e=>w(0,t,e.target.value),onBlur:()=>h(null),onKeyDown:e=>{("Enter"===e.key||"Escape"===e.key)&&h(null),"Tab"===e.key&&(e.preventDefault(),h({r:0,c:t+1<N.length?t+1:0}))}}):(0,s.jsx)("span",{className:"cursor-text",onDoubleClick:()=>h({r:0,c:t}),children:e||" "})},t))]})}),(0,s.jsx)("tbody",{children:C.map((e,t)=>{let r=t+1;return(0,s.jsxs)("tr",{className:"hover:bg-accent/30 transition-colors group",children:[(0,s.jsxs)("td",{className:"border border-border px-1 py-1 text-center text-[10px] text-muted-foreground/50",children:[(0,s.jsx)("span",{className:"group-hover:hidden",children:t+1}),(0,s.jsx)("button",{className:"hidden group-hover:inline text-destructive hover:text-destructive/80 text-[10px]",onClick:()=>{n(e=>e.filter((e,t)=>t!==r)),c(!0)},title:"Delete row",children:"×"})]}),N.map((t,n)=>{let i=e[n]??"",o=p?.r===r&&p?.c===n;return(0,s.jsx)("td",{className:"border border-border px-3 py-1.5",children:o?(0,s.jsx)("input",{autoFocus:!0,className:"w-full bg-transparent outline-none",value:i,onChange:e=>w(r,n,e.target.value),onBlur:()=>h(null),onKeyDown:e=>{"Escape"===e.key&&h(null),"Enter"===e.key&&h({r:r+1,c:n}),"Tab"===e.key&&(e.preventDefault(),e.shiftKey?h({r,c:Math.max(0,n-1)}):h({r:n+1>=N.length?r+1:r,c:n+1>=N.length?0:n+1}))}}):(0,s.jsx)("span",{className:"cursor-text",onDoubleClick:()=>h({r,c:n}),children:i||" "})},n)})]},t)})})]}),j&&(0,s.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2 border-t border-border",children:[(0,s.jsxs)("button",{onClick:()=>b(e=>e+1e3),className:"text-[11px] text-foreground hover:bg-accent transition-colors px-2.5 py-1 rounded border border-border",children:["Show"," ",Math.min(1e3,S.length-x).toLocaleString()," ","more rows"]}),(0,s.jsxs)("span",{className:"text-[11px] text-muted-foreground",children:[x.toLocaleString()," /"," ",S.length.toLocaleString()," rows"]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 border-t border-border",children:[(0,s.jsx)("button",{onClick:()=>{let e=t[0]?.length||1;n(t=>[...t,Array(e).fill("")]),c(!0)},className:"text-[11px] text-muted-foreground hover:text-foreground transition-colors px-2 py-1 rounded hover:bg-accent",children:"+ Add row"}),(0,s.jsx)("button",{onClick:()=>{n(e=>e.map(e=>[...e,""])),c(!0)},className:"text-[11px] text-muted-foreground hover:text-foreground transition-colors px-2 py-1 rounded hover:bg-accent",children:"+ Add column"})]})]})]})}function iV(e){this.content=e}iV.prototype={constructor:iV,find:function(e){for(var t=0;t<this.content.length;t+=2)if(this.content[t]===e)return t;return -1},get:function(e){var t=this.find(e);return -1==t?void 0:this.content[t+1]},update:function(e,t,n){var r=n&&n!=e?this.remove(n):this,i=r.find(e),s=r.content.slice();return -1==i?s.push(n||e,t):(s[i+1]=t,n&&(s[i]=n)),new iV(s)},remove:function(e){var t=this.find(e);if(-1==t)return this;var n=this.content.slice();return n.splice(t,2),new iV(n)},addToStart:function(e,t){return new iV([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var n=this.remove(e).content.slice();return n.push(e,t),new iV(n)},addBefore:function(e,t,n){var r=this.remove(t),i=r.content.slice(),s=r.find(e);return i.splice(-1==s?i.length:s,0,t,n),new iV(i)},forEach:function(e){for(var t=0;t<this.content.length;t+=2)e(this.content[t],this.content[t+1])},prepend:function(e){return(e=iV.from(e)).size?new iV(e.content.concat(this.subtract(e).content)):this},append:function(e){return(e=iV.from(e)).size?new iV(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=iV.from(e);for(var n=0;n<e.content.length;n+=2)t=t.remove(e.content[n]);return t},toObject:function(){var e={};return this.forEach(function(t,n){e[t]=n}),e},get size(){return this.content.length>>1}},iV.from=function(e){if(e instanceof iV)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new iV(t)};class iW{constructor(e,t){if(this.content=e,this.size=t||0,null==t)for(let t=0;t<e.length;t++)this.size+=e[t].nodeSize}nodesBetween(e,t,n,r=0,i){for(let s=0,o=0;o<t;s++){let a=this.content[s],l=o+a.nodeSize;if(l>e&&!1!==n(a,r+o,i||null,s)&&a.content.size){let i=o+1;a.nodesBetween(Math.max(0,e-i),Math.min(a.content.size,t-i),n,r+i)}o=l}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i="",s=!0;return this.nodesBetween(e,t,(o,a)=>{let l=o.isText?o.text.slice(Math.max(e,a)-a,t-a):o.isLeaf?r?"function"==typeof r?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):"":"";o.isBlock&&(o.isLeaf&&l||o.isTextblock)&&n&&(s?s=!1:i+=n),i+=l},0),i}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,r=this.content.slice(),i=0;for(t.isText&&t.sameMarkup(n)&&(r[r.length-1]=t.withText(t.text+n.text),i=1);i<e.content.length;i++)r.push(e.content[i]);return new iW(r,this.size+e.size)}cut(e,t=this.size){if(0==e&&t==this.size)return this;let n=[],r=0;if(t>e)for(let i=0,s=0;s<t;i++){let o=this.content[i],a=s+o.nodeSize;a>e&&((s<e||a>t)&&(o=o.isText?o.cut(Math.max(0,e-s),Math.min(o.text.length,t-s)):o.cut(Math.max(0,e-s-1),Math.min(o.content.size,t-s-1))),n.push(o),r+=o.nodeSize),s=a}return new iW(n,r)}cutByIndex(e,t){return e==t?iW.empty:0==e&&t==this.content.length?this:new iW(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let r=this.content.slice(),i=this.size+t.nodeSize-n.nodeSize;return r[e]=t,new iW(r,i)}addToStart(e){return new iW([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new iW(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let r=this.content[t];e(r,n,t),n+=r.nodeSize}}findDiffStart(e,t=0){return function e(t,n,r){for(let i=0;;i++){if(i==t.childCount||i==n.childCount)return t.childCount==n.childCount?null:r;let s=t.child(i),o=n.child(i);if(s==o){r+=s.nodeSize;continue}if(!s.sameMarkup(o))return r;if(s.isText&&s.text!=o.text){for(let e=0;s.text[e]==o.text[e];e++)r++;return r}if(s.content.size||o.content.size){let t=e(s.content,o.content,r+1);if(null!=t)return t}r+=s.nodeSize}}(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return function e(t,n,r,i){for(let s=t.childCount,o=n.childCount;;){if(0==s||0==o)return s==o?null:{a:r,b:i};let a=t.child(--s),l=n.child(--o),c=a.nodeSize;if(a==l){r-=c,i-=c;continue}if(!a.sameMarkup(l))return{a:r,b:i};if(a.isText&&a.text!=l.text){let e=0,t=Math.min(a.text.length,l.text.length);for(;e<t&&a.text[a.text.length-e-1]==l.text[l.text.length-e-1];)e++,r--,i--;return{a:r,b:i}}if(a.content.size||l.content.size){let t=e(a.content,l.content,r-1,i-1);if(t)return t}r-=c,i-=c}}(this,e,t,n)}findIndex(e){if(0==e)return iK(0,e);if(e==this.size)return iK(this.content.length,e);if(e>this.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=n+this.child(t).nodeSize;if(r>=e){if(r==e)return iK(t+1,r);return iK(t,n)}n=r}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return iW.empty;if(!Array.isArray(t))throw RangeError("Invalid input for Fragment.fromJSON");return iW.fromArray(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return iW.empty;let t,n=0;for(let r=0;r<e.length;r++){let i=e[r];n+=i.nodeSize,r&&i.isText&&e[r-1].sameMarkup(i)?(t||(t=e.slice(0,r)),t[t.length-1]=i.withText(t[t.length-1].text+i.text)):t&&t.push(i)}return new iW(t||e,n)}static from(e){if(!e)return iW.empty;if(e instanceof iW)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new iW([e],e.nodeSize);throw RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}iW.empty=new iW([],0);let iq={index:0,offset:0};function iK(e,t){return iq.index=e,iq.offset=t,iq}function iG(e,t){if(e===t)return!0;if(!(e&&"object"==typeof e)||!(t&&"object"==typeof t))return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!iG(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!iG(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}class iJ{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(this.eq(i))return e;if(this.type.excludes(i.type))t||(t=e.slice(0,r));else{if(i.type.excludes(this.type))return e;!n&&i.type.rank>this.type.rank&&(t||(t=e.slice(0,r)),t.push(this),n=!0),t&&t.push(i)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&iG(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw RangeError("Invalid input for Mark.fromJSON");let n=e.marks[t.type];if(!n)throw RangeError(`There is no mark type ${t.type} in this schema`);let r=n.create(t.attrs);return n.checkAttrs(r.attrs),r}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&0==e.length)return iJ.none;if(e instanceof iJ)return[e];let t=e.slice();return t.sort((e,t)=>e.type.rank-t.type.rank),t}}iJ.none=[];class iZ extends Error{}class iX{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=function e(t,n,r,i,s,o){let{index:a,offset:l}=t.findIndex(n),c=t.maybeChild(a);if(l==n||c.isText)return o&&i<=0&&s<=0&&!o.canReplace(a,a,r)?null:t.cut(0,n).append(r).append(t.cut(n));let d=e(c.content,n-l-1,r,0==a?i-1:0,a==t.childCount-1?s-1:0,c);return d&&t.replaceChild(a,c.copy(d))}(this.content,e+this.openStart,t,this.openStart+1,this.openEnd+1);return n&&new iX(n,this.openStart,this.openEnd)}removeBetween(e,t){return new iX(function e(t,n,r){let{index:i,offset:s}=t.findIndex(n),o=t.maybeChild(i),{index:a,offset:l}=t.findIndex(r);if(s==n||o.isText){if(l!=r&&!t.child(a).isText)throw RangeError("Removing non-flat range");return t.cut(0,n).append(t.cut(r))}if(i!=a)throw RangeError("Removing non-flat range");return t.replaceChild(i,o.copy(e(o.content,n-s-1,r-s-1)))}(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return iX.empty;let n=t.openStart||0,r=t.openEnd||0;if("number"!=typeof n||"number"!=typeof r)throw RangeError("Invalid input for Slice.fromJSON");return new iX(iW.fromJSON(e,t.content),n,r)}static maxOpen(e,t=!0){let n=0,r=0;for(let r=e.firstChild;r&&!r.isLeaf&&(t||!r.type.spec.isolating);r=r.firstChild)n++;for(let n=e.lastChild;n&&!n.isLeaf&&(t||!n.type.spec.isolating);n=n.lastChild)r++;return new iX(e,n,r)}}function iY(e,t){if(!t.type.compatibleContent(e.type))throw new iZ("Cannot join "+t.type.name+" onto "+e.type.name)}function iQ(e,t,n){let r=e.node(n);return iY(r,t.node(n)),r}function i0(e,t){let n=t.length-1;n>=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function i1(e,t,n,r){let i=(t||e).node(n),s=0,o=t?t.index(n):i.childCount;e&&(s=e.index(n),e.depth>n?s++:e.textOffset&&(i0(e.nodeAfter,r),s++));for(let e=s;e<o;e++)i0(i.child(e),r);t&&t.depth==n&&t.textOffset&&i0(t.nodeBefore,r)}function i2(e,t){return e.type.checkContent(t),e.copy(t)}function i5(e,t,n){let r=[];return i1(null,e,n,r),e.depth>n&&i0(i2(iQ(e,t,n+1),i5(e,t,n+1)),r),i1(t,null,n,r),new iW(r)}iX.empty=new iX(iW.empty,0,0);class i3{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return null==e?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[3*this.resolveDepth(e)]}index(e){return this.path[3*this.resolveDepth(e)+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e!=this.depth||this.textOffset?1:0)}start(e){return 0==(e=this.resolveDepth(e))?0:this.path[3*e-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(!(e=this.resolveDepth(e)))throw RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]}after(e){if(!(e=this.resolveDepth(e)))throw RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]+this.path[3*e].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):0==e?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[3*t],r=0==t?0:this.path[3*t-1]+1;for(let t=0;t<e;t++)r+=n.child(t).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(0==e.content.size)return iJ.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),r=e.maybeChild(t);if(!n){let e=n;n=r,r=e}let i=n.marks;for(var s=0;s<i.length;s++)!1!==i[s].type.spec.inclusive||r&&i[s].isInSet(r.marks)||(i=i[s--].removeFromSet(i));return i}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,r=e.parent.maybeChild(e.index());for(var i=0;i<n.length;i++)!1!==n[i].type.spec.inclusive||r&&n[i].isInSet(r.marks)||(n=n[i--].removeFromSet(n));return n}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let n=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);n>=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new i7(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw RangeError("Position "+t+" out of range");let n=[],r=0,i=t;for(let t=e;;){let{index:e,offset:s}=t.content.findIndex(i),o=i-s;if(n.push(t,e,r+s),!o||(t=t.child(e)).isText)break;i=o-1,r+=s+1}return new i3(t,n,i)}static resolveCached(e,t){let n=i9.get(e);if(n)for(let e=0;e<n.elts.length;e++){let r=n.elts[e];if(r.pos==t)return r}else i9.set(e,n=new i4);let r=n.elts[n.i]=i3.resolve(e,t);return n.i=(n.i+1)%i6,r}}class i4{constructor(){this.elts=[],this.i=0}}let i6=12,i9=new WeakMap;class i7{constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}let i8=Object.create(null);class se{constructor(e,t,n,r=iJ.none){this.type=e,this.attrs=t,this.marks=r,this.content=n||iW.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n,r=0){this.content.nodesBetween(e,t,n,r,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,n,r){return this.content.textBetween(e,t,n,r)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,n){return this.type==e&&iG(this.attrs,t||e.defaultAttrs||i8)&&iJ.sameSet(this.marks,n||iJ.none)}copy(e=null){return e==this.content?this:new se(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new se(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return 0==e&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return iX.empty;let r=this.resolve(e),i=this.resolve(t),s=n?0:r.sharedDepth(t),o=r.start(s);return new iX(r.node(s).content.cut(r.pos-o,i.pos-o),r.depth-s,i.depth-s)}replace(e,t,n){var r=this.resolve(e),i=this.resolve(t);if(n.openStart>r.depth)throw new iZ("Inserted content deeper than insertion position");if(r.depth-n.openStart!=i.depth-n.openEnd)throw new iZ("Inconsistent open depths");return function e(t,n,r,i){let s=t.index(i),o=t.node(i);if(s==n.index(i)&&i<t.depth-r.openStart){let a=e(t,n,r,i+1);return o.copy(o.content.replaceChild(s,a))}if(!r.content.size)return i2(o,i5(t,n,i));if(r.openStart||r.openEnd||t.depth!=i||n.depth!=i){let{start:e,end:s}=function(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(iW.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}(r,t);return i2(o,function e(t,n,r,i,s){let o=t.depth>s&&iQ(t,n,s+1),a=i.depth>s&&iQ(r,i,s+1),l=[];return i1(null,t,s,l),o&&a&&n.index(s)==r.index(s)?(iY(o,a),i0(i2(o,e(t,n,r,i,s+1)),l)):(o&&i0(i2(o,i5(t,n,s+1)),l),i1(n,r,s,l),a&&i0(i2(a,i5(r,i,s+1)),l)),i1(i,null,s,l),new iW(l)}(t,e,s,n,i))}{let e=t.parent,i=e.content;return i2(e,i.cut(0,t.parentOffset).append(r.content).append(i.cut(n.parentOffset)))}}(r,i,n,0)}nodeAt(e){for(let t=this;;){let{index:n,offset:r}=t.content.findIndex(e);if(!(t=t.maybeChild(n)))return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:n}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:n}}childBefore(e){if(0==e)return{node:null,index:0,offset:0};let{index:t,offset:n}=this.content.findIndex(e);if(n<e)return{node:this.content.child(t),index:t,offset:n};let r=this.content.child(t-1);return{node:r,index:t-1,offset:n-r.nodeSize}}resolve(e){return i3.resolveCached(this,e)}resolveNoCache(e){return i3.resolve(this,e)}rangeHasMark(e,t,n){let r=!1;return t>e&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),sn(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,n=iW.empty,r=0,i=n.childCount){let s=this.contentMatchAt(e).matchFragment(n,r,i),o=s&&s.matchFragment(this.content,t);if(!o||!o.validEnd)return!1;for(let e=r;e<i;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n,r){if(r&&!this.type.allowsMarks(r))return!1;let i=this.contentMatchAt(e).matchType(n),s=i&&i.matchFragment(this.content,t);return!!s&&s.validEnd}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=iJ.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];n.type.checkAttrs(n.attrs),e=n.addToSet(e)}if(!iJ.sameSet(e,this.marks))throw RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(e=>e.type.name)}`);this.content.forEach(e=>e.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}static fromJSON(e,t){let n;if(!t)throw RangeError("Invalid input for Node.fromJSON");if(t.marks){if(!Array.isArray(t.marks))throw RangeError("Invalid mark data for Node.fromJSON");n=t.marks.map(e.markFromJSON)}if("text"==t.type){if("string"!=typeof t.text)throw RangeError("Invalid text node in JSON");return e.text(t.text,n)}let r=iW.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}}se.prototype.text=void 0;class st extends se{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):sn(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new st(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new st(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return 0==e&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function sn(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+"("+t+")";return t}class sr{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){var n;let r,i=new si(e,t);if(null==i.next)return sr.empty;let s=function e(t){let n=[];do n.push(function(t){let n=[];do n.push(function(t){let n=function(t){if(t.eat("(")){let n=e(t);return t.eat(")")||t.err("Missing closing paren"),n}if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=(function(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let i=[];for(let e in n){let r=n[e];r.isInGroup(t)&&i.push(r)}return 0==i.length&&e.err("No node type or group '"+t+"' found"),i})(t,t.next).map(e=>(null==t.inline?t.inline=e.isInline:t.inline!=e.isInline&&t.err("Mixing inline and block content"),{type:"name",value:e}));return t.pos++,1==e.length?e[0]:{type:"choice",exprs:e}}}(t);for(;;)if(t.eat("+"))n={type:"plus",expr:n};else if(t.eat("*"))n={type:"star",expr:n};else if(t.eat("?"))n={type:"opt",expr:n};else if(t.eat("{"))n=function(e,t){let n=ss(e),r=n;return e.eat(",")&&(r="}"!=e.next?ss(e):-1),e.eat("}")||e.err("Unclosed braced range"),{type:"range",min:n,max:r,expr:t}}(t,n);else break;return n}(t));while(t.next&&")"!=t.next&&"|"!=t.next)return 1==n.length?n[0]:{type:"seq",exprs:n}}(t));while(t.eat("|"))return 1==n.length?n[0]:{type:"choice",exprs:n}}(i);i.next&&i.err("Unexpected trailing text");let o=(n=function(e){let t=[[]];return i(function e(t,s){if("choice"==t.type)return t.exprs.reduce((t,n)=>t.concat(e(n,s)),[]);if("seq"==t.type)for(let r=0;;r++){let o=e(t.exprs[r],s);if(r==t.exprs.length-1)return o;i(o,s=n())}else if("star"==t.type){let o=n();return r(s,o),i(e(t.expr,o),o),[r(o)]}else if("plus"==t.type){let o=n();return i(e(t.expr,s),o),i(e(t.expr,o),o),[r(o)]}else if("opt"==t.type)return[r(s)].concat(e(t.expr,s));else if("range"==t.type){let o=s;for(let r=0;r<t.min;r++){let r=n();i(e(t.expr,o),r),o=r}if(-1==t.max)i(e(t.expr,o),o);else for(let s=t.min;s<t.max;s++){let s=n();r(o,s),i(e(t.expr,o),s),o=s}return[r(o)]}else if("name"==t.type)return[r(s,void 0,t.value)];else throw Error("Unknown expr type")}(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let i={term:r,to:n};return t[e].push(i),i}function i(e,t){e.forEach(e=>e.to=t)}}(s),r=Object.create(null),function e(t){let i=[];t.forEach(e=>{n[e].forEach(({term:e,to:t})=>{let r;if(e){for(let t=0;t<i.length;t++)i[t][0]==e&&(r=i[t][1]);sa(n,t).forEach(t=>{r||i.push([e,r=[]]),-1==r.indexOf(t)&&r.push(t)})}})});let s=r[t.join(",")]=new sr(t.indexOf(n.length-1)>-1);for(let t=0;t<i.length;t++){let n=i[t][1].sort(so);s.next.push({type:i[t][0],next:r[n.join(",")]||e(n)})}return s}(sa(n,0)));return function(e,t){for(let n=0,r=[e];n<r.length;n++){let e=r[n],i=!e.validEnd,s=[];for(let t=0;t<e.next.length;t++){let{type:n,next:o}=e.next[t];s.push(n.name),i&&!(n.isText||n.hasRequiredAttrs())&&(i=!1),-1==r.indexOf(o)&&r.push(o)}i&&t.err("Only non-generatable nodes ("+s.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(o,i),o}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,n=e.childCount){let r=this;for(let i=t;r&&i<n;i++)r=r.matchType(e.child(i).type);return r}get inlineContent(){return 0!=this.next.length&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let n=0;n<e.next.length;n++)if(this.next[t].type==e.next[n].type)return!0;return!1}fillBefore(e,t=!1,n=0){let r=[this];return function i(s,o){let a=s.matchFragment(e,n);if(a&&(!t||a.validEnd))return iW.from(o.map(e=>e.createAndFill()));for(let e=0;e<s.next.length;e++){let{type:t,next:n}=s.next[e];if(!(t.isText||t.hasRequiredAttrs())&&-1==r.indexOf(n)){r.push(n);let e=i(n,o.concat(t));if(e)return e}}return null}(this,[])}findWrapping(e){for(let t=0;t<this.wrapCache.length;t+=2)if(this.wrapCache[t]==e)return this.wrapCache[t+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let r=n.shift(),i=r.match;if(i.matchType(e)){let e=[];for(let t=r;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<i.next.length;e++){let{type:s,next:o}=i.next[e];s.isLeaf||s.hasRequiredAttrs()||s.name in t||r.type&&!o.validEnd||(n.push({match:s.contentMatch,type:s,via:r}),t[s.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];return!function t(n){e.push(n);for(let r=0;r<n.next.length;r++)-1==e.indexOf(n.next[r].next)&&t(n.next[r].next)}(this),e.map((t,n)=>{let r=n+(t.validEnd?"*":" ")+" ";for(let n=0;n<t.next.length;n++)r+=(n?", ":"")+t.next[n].type.name+"->"+e.indexOf(t.next[n].next);return r}).join("\n")}}sr.empty=new sr(!0);class si{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),""==this.tokens[this.tokens.length-1]&&this.tokens.pop(),""==this.tokens[0]&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw SyntaxError(e+" (in content expression '"+this.string+"')")}}function ss(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function so(e,t){return t-e}function sa(e,t){let n=[];return function t(r){let i=e[r];if(1==i.length&&!i[0].term)return t(i[0].to);n.push(r);for(let e=0;e<i.length;e++){let{term:r,to:s}=i[e];r||-1!=n.indexOf(s)||t(s)}}(t),n.sort(so)}function sl(e){let t=Object.create(null);for(let n in e){let r=e[n];if(!r.hasDefault)return null;t[n]=r.default}return t}function sc(e,t){let n=Object.create(null);for(let r in e){let i=t&&t[r];if(void 0===i){let t=e[r];if(t.hasDefault)i=t.default;else throw RangeError("No value supplied for attribute "+r)}n[r]=i}return n}function sd(e,t,n,r){for(let r in t)if(!(r in e))throw RangeError(`Unsupported attribute ${r} for ${n} of type ${r}`);for(let n in e){let r=e[n];r.validate&&r.validate(t[n])}}function su(e,t){let n=Object.create(null);if(t)for(let r in t)n[r]=new sh(e,r,t[r]);return n}class sp{constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(" "):[],this.attrs=su(e,n.attrs),this.defaultAttrs=sl(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||"text"==e),this.isText="text"==e}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==sr.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:sc(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error("NodeType.create can't construct text nodes");return new se(this,this.computeAttrs(e),iW.from(t),iJ.setFrom(n))}createChecked(e=null,t,n){return t=iW.from(t),this.checkContent(t),new se(this,this.computeAttrs(e),t,iJ.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),(t=iW.from(t)).size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let r=this.contentMatch.matchFragment(t),i=r&&r.fillBefore(iW.empty,!0);return i?new se(this,e,t.append(i),iJ.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t<e.childCount;t++)if(!this.allowsMarks(e.child(t).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){sd(this.attrs,e,"node",this.name)}allowsMarkType(e){return null==this.markSet||this.markSet.indexOf(e)>-1}allowsMarks(e){if(null==this.markSet)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){let t;if(null==this.markSet)return e;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||(t=e.slice(0,n));return t?t.length?t:iJ.none:e}static compile(e,t){let n=Object.create(null);e.forEach((e,r)=>n[e]=new sp(e,t,r));let r=t.spec.topNode||"doc";if(!n[r])throw RangeError("Schema is missing its top node type ('"+r+"')");if(!n.text)throw RangeError("Every schema needs a 'text' type");for(let e in n.text.attrs)throw RangeError("The text node type should not have attributes");return n}}class sh{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate="string"==typeof n.validate?function(e,t,n){let r=n.split("|");return n=>{let i=null===n?"null":typeof n;if(0>r.indexOf(i))throw RangeError(`Expected value of type ${r} for attribute ${t} on type ${e}, got ${i}`)}}(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class sm{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=su(e,r.attrs),this.excluded=null;let i=sl(this.attrs);this.instance=i?new iJ(this,i):null}create(e=null){return!e&&this.instance?this.instance:new iJ(this,sc(this.attrs,e))}static compile(e,t){let n=Object.create(null),r=0;return e.forEach((e,i)=>n[e]=new sm(e,r++,t,i)),n}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){sd(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class sf{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=iV.from(e.nodes),t.marks=iV.from(e.marks||{}),this.nodes=sp.compile(this.spec.nodes,this),this.marks=sm.compile(this.spec.marks,this);let n=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw RangeError(e+" can not be both a node and a mark");let t=this.nodes[e],r=t.spec.content||"",i=t.spec.marks;if(t.contentMatch=n[r]||(n[r]=sr.parse(r,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError("Multiple linebreak nodes defined");if(!t.isInline||!t.isLeaf)throw RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=t}t.markSet="_"==i?null:i?sg(this,i.split(" ")):""!=i&&t.inlineContent?null:[]}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=null==n?[t]:""==n?[]:sg(this,n.split(" "))}this.nodeFromJSON=e=>se.fromJSON(this,e),this.markFromJSON=e=>iJ.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if("string"==typeof e)e=this.nodeType(e);else if(e instanceof sp){if(e.schema!=this)throw RangeError("Node type from different schema used ("+e.name+")")}else throw RangeError("Invalid node type: "+e);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new st(n,n.defaultAttrs,e,iJ.setFrom(t))}mark(e,t){return"string"==typeof e&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw RangeError("Unknown node type: "+e);return t}}function sg(e,t){let n=[];for(let r=0;r<t.length;r++){let i=t[r],s=e.marks[i],o=s;if(s)n.push(s);else for(let t in e.marks){let r=e.marks[t];("_"==i||r.spec.group&&r.spec.group.split(" ").indexOf(i)>-1)&&n.push(o=r)}if(!o)throw SyntaxError("Unknown mark type: '"+t[r]+"'")}return n}class sx{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(null!=e.tag)this.tags.push(e);else if(null!=e.style){let t=/[^=]*/.exec(e.style)[0];0>n.indexOf(t)&&n.push(t),this.styles.push(e)}}),this.normalizeLists=!this.tags.some(t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)})}parse(e,t={}){let n=new sN(this,t,!1);return n.addAll(e,iJ.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new sN(this,t,!0);return n.addAll(e,iJ.none,t.from,t.to),iX.maxOpen(n.finish())}matchTag(e,t,n){for(let s=n?this.tags.indexOf(n)+1:0;s<this.tags.length;s++){var r,i;let n=this.tags[s];if(r=e,i=n.tag,(r.matches||r.msMatchesSelector||r.webkitMatchesSelector||r.mozMatchesSelector).call(r,i)&&(void 0===n.namespace||e.namespaceURI==n.namespace)&&(!n.context||t.matchesContext(n.context))){if(n.getAttrs){let t=n.getAttrs(e);if(!1===t)continue;n.attrs=t||void 0}return n}}}matchStyle(e,t,n,r){for(let i=r?this.styles.indexOf(r)+1:0;i<this.styles.length;i++){let r=this.styles[i],s=r.style;if(0==s.indexOf(e)&&(!r.context||n.matchesContext(r.context))&&(!(s.length>e.length)||61==s.charCodeAt(e.length)&&s.slice(e.length+1)==t)){if(r.getAttrs){let e=r.getAttrs(t);if(!1===e)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=null==e.priority?50:e.priority,r=0;for(;r<t.length;r++){let e=t[r];if((null==e.priority?50:e.priority)<n)break}t.splice(r,0,e)}for(let t in e.marks){let r=e.marks[t].spec.parseDOM;r&&r.forEach(e=>{n(e=sS(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach(e=>{n(e=sS(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new sx(e,sx.schemaRules(e)))}}let sb={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},sy={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},sv={ol:!0,ul:!0};function sw(e,t,n){return null!=t?!!t|2*("full"===t):e&&"pre"==e.whitespace?3:-5&n}class sk{constructor(e,t,n,r,i,s){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=s,this.content=[],this.activeMarks=iJ.none,this.match=i||(4&s?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(iW.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let t=this.type.contentMatch,n;return(n=t.findWrapping(e.type))?(this.match=t,n):null}}return this.match.findWrapping(e.type)}finish(e){if(!(1&this.options)){let e=this.content[this.content.length-1],t;e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))&&(e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=e.withText(e.text.slice(0,e.text.length-t[0].length)))}let t=iW.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(iW.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!sb.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class sN{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,i,s=sw(null,t.preserveWhitespace,0)|4*!!n;i=r?new sk(r.type,r.attrs,iJ.none,!0,t.topMatch||r.type.contentMatch,s):n?new sk(null,null,iJ.none,!0,null,s):new sk(e.schema.topNodeType,null,iJ.none,!0,null,s),this.nodes=[i],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){3==e.nodeType?this.addTextNode(e,t):1==e.nodeType&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,r=this.top,i=2&r.options?"full":this.localPreserveWS||(1&r.options)>0,{schema:s}=this.parser;if("full"===i||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(i)if("full"===i)n=n.replace(/\r\n?/g,"\n");else if(s.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(s.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n<e.length;n++)n&&this.insertNode(s.linebreakReplacement.create(),t,!0),e[n]&&this.insertNode(s.text(e[n]),t,!/\S/.test(e[n]));n=""}else n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=r.content[r.content.length-1],i=e.previousSibling;(!t||i&&"BR"==i.nodeName||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}n&&this.insertNode(s.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let r=this.localPreserveWS,i=this.top;("PRE"==e.tagName||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let s=e.nodeName.toLowerCase(),o;sv.hasOwnProperty(s)&&this.parser.normalizeLists&&function(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=1==t.nodeType?t.nodeName.toLowerCase():null;e&&sv.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):"li"==e?n=t:e&&(n=null)}}(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,n));e:if(a?a.ignore:sy.hasOwnProperty(s))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let n,r=this.needsBlock;if(sb.hasOwnProperty(s))i.content.length&&i.content[0].isInline&&this.open&&(this.open--,i=this.top),n=!0,i.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let o=a&&a.skip?t:this.readStyles(e,t);o&&this.addAll(e,o),n&&this.sync(i),this.needsBlock=r}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,a,n,!1===a.consuming?o:void 0)}this.localPreserveWS=r}leafFallback(e,t){"BR"==e.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode("\n"),t)}ignoreFallback(e,t){"BR"!=e.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let e=0;e<this.parser.matchedStyles.length;e++){let r=this.parser.matchedStyles[e],i=n.getPropertyValue(r);if(i)for(let e;;){let n=this.parser.matchStyle(r,i,this,e);if(!n)break;if(n.ignore)return null;if(t=n.clearMark?t.filter(e=>!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),!1===n.consuming)e=n;else break}}return t}addElementByRule(e,t,n,r){let i,s;if(t.node)if((s=this.parser.schema.nodes[t.node]).isLeaf)this.insertNode(s.create(t.attrs),n,"BR"==e.nodeName)||this.leafFallback(e,n);else{let e=this.enter(s,t.attrs||null,n,t.preserveWhitespace);e&&(i=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let o=this.top;if(s&&s.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let r=e;"string"==typeof t.contentElement?r=e.querySelector(t.contentElement):"function"==typeof t.contentElement?r=t.contentElement(e):t.contentElement&&(r=t.contentElement),this.findAround(e,r,!0),this.addAll(r,n),this.findAround(e,r,!1)}i&&this.sync(o)&&this.open--}addAll(e,t,n,r){let i=n||0;for(let s=n?e.childNodes[n]:e.firstChild,o=null==r?null:e.childNodes[r];s!=o;s=s.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(s,t);this.findAtPoint(e,i)}findPlace(e,t,n){let r,i;for(let t=this.open,s=0;t>=0;t--){let o=this.nodes[t],a=o.findWrapping(e);if(a&&(!r||r.length>a.length+s)&&(r=a,i=o,!a.length))break;if(o.solid){if(n)break;s+=2}}if(!r)return null;this.sync(i);for(let e=0;e<r.length;e++)t=this.enterInner(r[e],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let e=this.textblockFromContext();e&&(t=this.enterInner(e,null,t))}let r=this.findPlace(e,t,n);if(r){this.closeExtra();let t=this.top;t.match&&(t.match=t.match.matchType(e.type));let n=iJ.none;for(let i of r.concat(e.marks))(t.type?t.type.allowsMarkType(i.type):sC(i.type,e.type))&&(n=i.addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n,r){let i=this.findPlace(e.create(t),n,!1);return i&&(i=this.enterInner(e,t,n,!0,r)),i}enterInner(e,t,n,r=!1,i){this.closeExtra();let s=this.top;s.match=s.match&&s.match.matchType(e);let o=sw(e,i,s.options);4&s.options&&0==s.content.length&&(o|=4);let a=iJ.none;return n=n.filter(t=>(s.type?!s.type.allowsMarkType(t.type):!sC(t.type,e))||(a=t.addToSet(a),!1)),this.nodes.push(new sk(e,t,a,r,null,o)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;else this.localPreserveWS&&(this.nodes[t].options|=1);return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)null==this.find[t].pos&&1==e.nodeType&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let r=0;r<this.find.length;r++)null==this.find[r].pos&&1==e.nodeType&&e.contains(this.find[r].node)&&t.compareDocumentPosition(this.find[r].node)&(n?2:4)&&(this.find[r].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),n=this.options.context,r=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),i=-(n?n.depth+1:0)+ +!r,s=(e,o)=>{for(;e>=0;e--){let a=t[e];if(""==a){if(e==t.length-1||0==e)continue;for(;o>=i;o--)if(s(e-1,o))return!0;return!1}{let e=o>0||0==o&&r?this.nodes[o].type:n&&o>=i?n.node(o-i).type:null;if(!e||e.name!=a&&!e.isInGroup(a))return!1;o--}}return!0};return s(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}}function sS(e){let t={};for(let n in e)t[n]=e[n];return t}function sC(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let s=[],o=e=>{s.push(e);for(let n=0;n<e.edgeCount;n++){let{type:r,next:i}=e.edge(n);if(r==t||0>s.indexOf(i)&&o(i))return!0}};if(o(i.contentMatch))return!0}}class sj{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=sM(t).createDocumentFragment());let r=n,i=[];return e.forEach(e=>{if(i.length||e.marks.length){let n=0,s=0;for(;n<i.length&&s<e.marks.length;){let t=e.marks[s];if(!this.marks[t.type.name]){s++;continue}if(!t.eq(i[n][0])||!1===t.type.spec.spanning)break;n++,s++}for(;n<i.length;)r=i.pop()[1];for(;s<e.marks.length;){let n=e.marks[s++],o=this.serializeMark(n,e.isInline,t);o&&(i.push([n,r]),r.appendChild(o.dom),r=o.contentDOM||o.dom)}}r.appendChild(this.serializeNodeInner(e,t))}),n}serializeNodeInner(e,t){if(e.isText)return sM(t).createTextNode(e.text);let{dom:n,contentDOM:r}=sT(sM(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,r)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let r=e.marks.length-1;r>=0;r--){let i=this.serializeMark(e.marks[r],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(n),n=i.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&sT(sM(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return"string"==typeof t?{dom:e.createTextNode(t)}:sT(e,t,n,r)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new sj(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=sE(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return sE(e.marks)}}function sE(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function sM(e){return e.document||window.document}let sA=new WeakMap;function sT(e,t,n,r){let i,s,o;if(1==t.nodeType)return{dom:t};if(t.dom&&1==t.dom.nodeType)return t;let a=t[0],l;if("string"!=typeof a)throw RangeError("Invalid array passed to renderSpec");if(r&&(void 0===(s=sA.get(r))&&sA.set(r,(o=null,!function e(t){if(t&&"object"==typeof t)if(Array.isArray(t))if("string"==typeof t[0])o||(o=[]),o.push(t);else for(let n=0;n<t.length;n++)e(t[n]);else for(let n in t)e(t[n])}(r),s=o)),l=s)&&l.indexOf(t)>-1)throw RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let c=a.indexOf(" ");c>0&&(n=a.slice(0,c),a=a.slice(c+1));let d=n?e.createElementNS(n,a):e.createElement(a),u=t[1],p=1;if(u&&"object"==typeof u&&null==u.nodeType&&!Array.isArray(u)){for(let e in p=2,u)if(null!=u[e]){let t=e.indexOf(" ");t>0?d.setAttributeNS(e.slice(0,t),e.slice(t+1),u[e]):"style"==e&&d.style?d.style.cssText=u[e]:d.setAttribute(e,u[e])}}for(let s=p;s<t.length;s++){let o=t[s];if(0===o){if(s<t.length-1||s>p)throw RangeError("Content hole must be the only child of its parent node");return{dom:d,contentDOM:d}}if("string"==typeof o)d.appendChild(e.createTextNode(o));else{let{dom:t,contentDOM:s}=sT(e,o,n,r);if(d.appendChild(t),s){if(i)throw RangeError("Multiple content holes");i=s}}}return{dom:d,contentDOM:i}}class sO{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(8&this.delInfo)>0}get deletedBefore(){return(5&this.delInfo)>0}get deletedAfter(){return(6&this.delInfo)>0}get deletedAcross(){return(4&this.delInfo)>0}}class s_{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&s_.empty)return s_.empty}recover(e){let t=0,n=65535&e;if(!this.inverted)for(let e=0;e<n;e++)t+=this.ranges[3*e+2]-this.ranges[3*e+1];return this.ranges[3*n]+t+(e-(65535&e))/65536}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,n){let r=0,i=this.inverted?2:1,s=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let a=this.ranges[o]-(this.inverted?r:0);if(a>e)break;let l=this.ranges[o+i],c=this.ranges[o+s],d=a+l;if(e<=d){let i=l?e==a?-1:e==d?1:t:t,s=a+r+(i<0?0:c);if(n)return s;let u=e==(t<0?a:d)?null:o/3+(e-a)*65536,p=e==a?2:e==d?1:4;return(t<0?e!=a:e!=d)&&(p|=8),new sO(s,p,u)}r+=c-l}return n?e+r:new sO(e+r,0,null)}touches(e,t){let n=0,r=65535&t,i=this.inverted?2:1,s=this.inverted?1:2;for(let t=0;t<this.ranges.length;t+=3){let o=this.ranges[t]-(this.inverted?n:0);if(o>e)break;let a=this.ranges[t+i];if(e<=o+a&&t==3*r)return!0;n+=this.ranges[t+s]-a}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r<this.ranges.length;r+=3){let s=this.ranges[r],o=s-(this.inverted?i:0),a=s+(this.inverted?0:i),l=this.ranges[r+t],c=this.ranges[r+n];e(o,o+l,a,a+c),i+=c-l}}invert(){return new s_(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return 0==e?s_.empty:new s_(e<0?[0,-e,0]:[0,0,e])}}s_.empty=new s_([]);class sD{constructor(e,t,n=0,r=e?e.length:0){this.mirror=t,this.from=n,this.to=r,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new sD(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),null!=t&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let r=e.getMirror(t);this.appendMap(e._maps[t],null!=r&&r<t?n+r:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),null!=r&&r>t?n-r-1:void 0)}}invert(){let e=new sD;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this._maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let r=0;for(let n=this.from;n<this.to;n++){let i=this._maps[n].mapResult(e,t);if(null!=i.recover){let t=this.getMirror(n);if(null!=t&&t>n&&t<this.to){n=t,e=this._maps[t].recover(i.recover);continue}}r|=i.delInfo,e=i.pos}return n?e:new sO(e,r,null)}}let sR=Object.create(null);class sI{getMap(){return s_.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw RangeError("Invalid input for Step.fromJSON");let n=sR[t.stepType];if(!n)throw RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in sR)throw RangeError("Duplicate use of step JSON ID "+e);return sR[e]=t,t.prototype.jsonID=e,t}}class sL{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new sL(e,null)}static fail(e){return new sL(null,e)}static fromReplace(e,t,n,r){try{return sL.ok(e.replace(t,n,r))}catch(e){if(e instanceof iZ)return sL.fail(e.message);throw e}}}function sP(e,t,n){let r=[];for(let i=0;i<e.childCount;i++){let s=e.child(i);s.content.size&&(s=s.copy(sP(s.content,t,s))),s.isInline&&(s=t(s,n,i)),r.push(s)}return iW.fromArray(r)}class s$ extends sI{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=e.resolve(this.from),r=n.node(n.sharedDepth(this.to)),i=new iX(sP(t.content,(e,t)=>e.isAtom&&t.type.allowsMarkType(this.mark.type)?e.mark(this.mark.addToSet(e.marks)):e,r),t.openStart,t.openEnd);return sL.fromReplace(e,this.from,this.to,i)}invert(){return new sz(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new s$(t.pos,n.pos,this.mark)}merge(e){return e instanceof s$&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new s$(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw RangeError("Invalid input for AddMarkStep.fromJSON");return new s$(t.from,t.to,e.markFromJSON(t.mark))}}sI.jsonID("addMark",s$);class sz extends sI{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new iX(sP(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return sL.fromReplace(e,this.from,this.to,n)}invert(){return new s$(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new sz(t.pos,n.pos,this.mark)}merge(e){return e instanceof sz&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new sz(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw RangeError("Invalid input for RemoveMarkStep.fromJSON");return new sz(t.from,t.to,e.markFromJSON(t.mark))}}sI.jsonID("removeMark",sz);class sB extends sI{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return sL.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return sL.fromReplace(e,this.pos,this.pos+1,new iX(iW.from(n),0,+!t.isLeaf))}invert(e){let t=e.nodeAt(this.pos);if(t){let e=this.mark.addToSet(t.marks);if(e.length==t.marks.length){for(let n=0;n<t.marks.length;n++)if(!t.marks[n].isInSet(e))return new sB(this.pos,t.marks[n]);return new sB(this.pos,this.mark)}}return new sF(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new sB(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if("number"!=typeof t.pos)throw RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new sB(t.pos,e.markFromJSON(t.mark))}}sI.jsonID("addNodeMark",sB);class sF extends sI{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return sL.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return sL.fromReplace(e,this.pos,this.pos+1,new iX(iW.from(n),0,+!t.isLeaf))}invert(e){let t=e.nodeAt(this.pos);return t&&this.mark.isInSet(t.marks)?new sB(this.pos,this.mark):this}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new sF(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if("number"!=typeof t.pos)throw RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new sF(t.pos,e.markFromJSON(t.mark))}}sI.jsonID("removeNodeMark",sF);class sH extends sI{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&sV(e,this.from,this.to)?sL.fail("Structure replace would overwrite content"):sL.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new s_([this.from,this.to-this.from,this.slice.size])}invert(e){return new sH(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.to,-1),n=this.from==this.to&&sH.MAP_BIAS<0?t:e.mapResult(this.from,1);return n.deletedAcross&&t.deletedAcross?null:new sH(n.pos,Math.max(n.pos,t.pos),this.slice,this.structure)}merge(e){if(!(e instanceof sH)||e.structure||this.structure)return null;if(this.from+this.slice.size!=e.from||this.slice.openEnd||e.slice.openStart)if(e.to!=this.from||this.slice.openStart||e.slice.openEnd)return null;else{let t=this.slice.size+e.slice.size==0?iX.empty:new iX(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new sH(e.from,this.to,t,this.structure)}{let t=this.slice.size+e.slice.size==0?iX.empty:new iX(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new sH(this.from,this.to+(e.to-e.from),t,this.structure)}}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw RangeError("Invalid input for ReplaceStep.fromJSON");return new sH(t.from,t.to,iX.fromJSON(e,t.slice),!!t.structure)}}sH.MAP_BIAS=1,sI.jsonID("replace",sH);class sU extends sI{constructor(e,t,n,r,i,s,o=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=i,this.insert=s,this.structure=o}apply(e){if(this.structure&&(sV(e,this.from,this.gapFrom)||sV(e,this.gapTo,this.to)))return sL.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return sL.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?sL.fromReplace(e,this.from,this.to,n):sL.fail("Content does not fit in gap")}getMap(){return new s_([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new sU(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1),r=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),i=this.to==this.gapTo?n.pos:e.map(this.gapTo,1);return t.deletedAcross&&n.deletedAcross||r<t.pos||i>n.pos?null:new sU(t.pos,n.pos,r,i,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to||"number"!=typeof t.gapFrom||"number"!=typeof t.gapTo||"number"!=typeof t.insert)throw RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new sU(t.from,t.to,t.gapFrom,t.gapTo,iX.fromJSON(e,t.slice),t.insert,!!t.structure)}}function sV(e,t,n){let r=e.resolve(t),i=n-t,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let e=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function sW(e,t,n,r=n.contentMatch,i=!0){let s=e.doc.nodeAt(t),o=[],a=t+1;for(let t=0;t<s.childCount;t++){let l=s.child(t),c=a+l.nodeSize,d=r.matchType(l.type);if(d){r=d;for(let t=0;t<l.marks.length;t++)n.allowsMarkType(l.marks[t].type)||e.step(new sz(a,c,l.marks[t]));if(i&&l.isText&&"pre"!=n.whitespace){let e,t=/\r?\n|\r/g,r;for(;e=t.exec(l.text);)r||(r=new iX(iW.from(n.schema.text(" ",n.allowedMarks(l.marks))),0,0)),o.push(new sH(a+e.index,a+e.index+e[0].length,r))}}else o.push(new sH(a,c,iX.empty));a=c}if(!r.validEnd){let t=r.fillBefore(iW.empty,!0);e.replace(a,a,new iX(t,0,0))}for(let t=o.length-1;t>=0;t--)e.step(o[t])}function sq(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth,r=0,i=0;;--n){let s=e.$from.node(n),o=e.$from.index(n)+r,a=e.$to.indexAfter(n)-i;if(n<e.depth&&s.canReplace(o,a,t))return n;if(0==n||s.type.spec.isolating||!((0==o||s.canReplace(o,s.childCount))&&(a==s.childCount||s.canReplace(0,a))))break;o&&(r=1),a<s.childCount&&(i=1)}return null}function sK(e,t,n=null,r=e){let i=function(e,t){let{parent:n,startIndex:r,endIndex:i}=e,s=n.contentMatchAt(r).findWrapping(t);if(!s)return null;let o=s.length?s[0]:t;return n.canReplaceWith(r,i,o)?s:null}(e,t),s=i&&function(e,t){let{parent:n,startIndex:r,endIndex:i}=e,s=n.child(r),o=t.contentMatch.findWrapping(s.type);if(!o)return null;let a=(o.length?o[o.length-1]:t).contentMatch;for(let e=r;a&&e<i;e++)a=a.matchType(n.child(e).type);return a&&a.validEnd?o:null}(r,t);return s?i.map(sG).concat({type:t,attrs:n}).concat(s.map(sG)):null}function sG(e){return{type:e,attrs:null}}function sJ(e,t,n,r){t.forEach((i,s)=>{if(i.isText){let o,a=/\r?\n|\r/g;for(;o=a.exec(i.text);){let i=e.mapping.slice(r).map(n+1+s+o.index);e.replaceWith(i,i+1,t.type.schema.linebreakReplacement.create())}}})}function sZ(e,t,n,r){t.forEach((i,s)=>{if(i.type==i.type.schema.linebreakReplacement){let i=e.mapping.slice(r).map(n+1+s);e.replaceWith(i,i+1,t.type.schema.text("\n"))}})}function sX(e,t,n=1,r){let i=e.resolve(t),s=i.depth-n,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let e=i.depth-1,t=n-2;e>s;e--,t--){let n=i.node(e),s=i.index(e);if(n.type.spec.isolating)return!1;let o=n.content.cutByIndex(s,n.childCount),a=r&&r[t+1];a&&(o=o.replaceChild(0,a.type.create(a.attrs)));let l=r&&r[t]||n;if(!n.canReplace(s+1,n.childCount)||!l.type.validContent(o))return!1}let a=i.indexAfter(s),l=r&&r[0];return i.node(s).canReplaceWith(a,a,l?l.type:i.node(s+1).type)}function sY(e,t){let n=e.resolve(t),r=n.index();return sQ(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function sQ(e,t){return!!(e&&t&&!e.isLeaf&&function(e,t){t.content.size||e.type.compatibleContent(t.type);let n=e.contentMatchAt(e.childCount),{linebreakReplacement:r}=e.type.schema;for(let i=0;i<t.childCount;i++){let s=t.child(i),o=s.type==r?e.type.schema.nodes.text:s.type;if(!(n=n.matchType(o))||!e.type.allowsMarks(s.marks))return!1}return n.validEnd}(e,t))}function s0(e,t,n=-1){let r=e.resolve(t);for(let e=r.depth;;e--){let i,s,o=r.index(e);if(e==r.depth?(i=r.nodeBefore,s=r.nodeAfter):n>0?(i=r.node(e+1),o++,s=r.node(e).maybeChild(o)):(i=r.node(e).maybeChild(o-1),s=r.node(e+1)),i&&!i.isTextblock&&sQ(i,s)&&r.node(e).canReplace(o,o+1))return t;if(0==e)break;t=n<0?r.before(e):r.after(e)}}function s1(e,t,n){let r=e.resolve(t);if(!n.content.size)return t;let i=n.content;for(let e=0;e<n.openStart;e++)i=i.firstChild.content;for(let e=1;e<=(0==n.openStart&&n.size?2:1);e++)for(let t=r.depth;t>=0;t--){let n=t==r.depth?0:r.pos<=(r.start(t+1)+r.end(t+1))/2?-1:1,s=r.index(t)+ +(n>0),o=r.node(t),a=!1;if(1==e)a=o.canReplace(s,s,i);else{let e=o.contentMatchAt(s).findWrapping(i.firstChild.type);a=e&&o.canReplaceWith(s,s,e[0])}if(a)return 0==n?r.pos:n<0?r.before(t+1):r.after(t+1)}return null}function s2(e,t,n=t,r=iX.empty){if(t==n&&!r.size)return null;let i=e.resolve(t),s=e.resolve(n);return s5(i,s,r)?new sH(t,n,r):new s3(i,s,r).fit()}function s5(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}sI.jsonID("replaceAround",sU);class s3{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=iW.empty;for(let t=0;t<=e.depth;t++){let n=e.node(t);this.frontier.push({type:n.type,match:n.contentMatchAt(e.indexAfter(t))})}for(let t=e.depth;t>0;t--)this.placed=iW.from(e.node(t).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let e=this.findFittable();e?this.placeNodes(e):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(e<0?this.$to:n.doc.resolve(e));if(!r)return null;let i=this.placed,s=n.depth,o=r.depth;for(;s&&o&&1==i.childCount;)i=i.firstChild.content,s--,o--;let a=new iX(i,s,o);return e>-1?new sU(n.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||n.pos!=this.$to.pos?new sH(n.pos,r.pos,a):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,r=this.unplaced.openEnd;n<e;n++){let i=t.firstChild;if(t.childCount>1&&(r=0),i.type.spec.isolating&&r<=n){e=n;break}t=i.content}for(let t=1;t<=2;t++)for(let n=1==t?e:this.unplaced.openStart;n>=0;n--){let e=null,r=(n?(e=s9(this.unplaced.content,n-1).firstChild).content:this.unplaced.content).firstChild;for(let i=this.depth;i>=0;i--){let{type:s,match:o}=this.frontier[i],a,l=null;if(1==t&&(r?o.matchType(r.type)||(l=o.fillBefore(iW.from(r),!1)):e&&s.compatibleContent(e.type)))return{sliceDepth:n,frontierDepth:i,parent:e,inject:l};if(2==t&&r&&(a=o.findWrapping(r.type)))return{sliceDepth:n,frontierDepth:i,parent:e,wrap:a};if(e&&o.matchType(e.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=s9(e,t);return!!r.childCount&&!r.firstChild.isLeaf&&(this.unplaced=new iX(e,t+1,Math.max(n,r.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=s9(e,t);if(r.childCount<=1&&t>0){let i=e.size-t<=t+r.size;this.unplaced=new iX(s4(e,t-1,1),t-1,i?t-1:n)}else this.unplaced=new iX(s4(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:r,wrap:i}){for(;this.depth>t;)this.closeFrontierNode();if(i)for(let e=0;e<i.length;e++)this.openFrontierNode(i[e]);let s=this.unplaced,o=n?n.content:s.content,a=s.openStart-e,l=0,c=[],{match:d,type:u}=this.frontier[t];if(r){for(let e=0;e<r.childCount;e++)c.push(r.child(e));d=d.matchFragment(r)}let p=o.size+e-(s.content.size-s.openEnd);for(;l<o.childCount;){let e=o.child(l),t=d.matchType(e.type);if(!t)break;(++l>1||0==a||e.content.size)&&(d=t,c.push(function e(t,n,r){if(n<=0)return t;let i=t.content;return n>1&&(i=i.replaceChild(0,e(i.firstChild,n-1,1==i.childCount?r-1:0))),n>0&&(i=t.type.contentMatch.fillBefore(i).append(i),r<=0&&(i=i.append(t.type.contentMatch.matchFragment(i).fillBefore(iW.empty,!0)))),t.copy(i)}(e.mark(u.allowedMarks(e.marks)),1==l?a:0,l==o.childCount?p:-1)))}let h=l==o.childCount;h||(p=-1),this.placed=s6(this.placed,t,iW.from(c)),this.frontier[t].match=d,h&&p<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=o;e<p;e++){let e=t.lastChild;this.frontier.push({type:e.type,match:e.contentMatchAt(e.childCount)}),t=e.content}this.unplaced=h?0==e?iX.empty:new iX(s4(s.content,e-1,1),e-1,p<0?s.openEnd:e-1):new iX(s4(s.content,e,l),s.openStart,s.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return -1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!s7(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return -1;let{depth:n}=this.$to,r=this.$to.after(n);for(;n>1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){t:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],i=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),s=s7(e,t,r,n,i);if(s){for(let n=t-1;n>=0;n--){let{match:t,type:r}=this.frontier[n],i=s7(e,n,r,t,!0);if(!i||i.childCount)continue t}return{depth:t,fit:s,move:i?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=s6(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),r=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,r)}return e}openFrontierNode(e,t=null,n){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=s6(this.placed,this.depth,iW.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(iW.empty,!0);e.childCount&&(this.placed=s6(this.placed,this.frontier.length,e))}}function s4(e,t,n){return 0==t?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(s4(e.firstChild.content,t-1,n)))}function s6(e,t,n){return 0==t?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(s6(e.lastChild.content,t-1,n)))}function s9(e,t){for(let n=0;n<t;n++)e=e.firstChild.content;return e}function s7(e,t,n,r,i){let s=e.node(t),o=i?e.indexAfter(t):e.index(t);if(o==s.childCount&&!n.compatibleContent(s.type))return null;let a=r.fillBefore(s.content,!0,o);return a&&!function(e,t,n){for(let r=n;r<t.childCount;r++)if(!e.allowsMarks(t.child(r).marks))return!0;return!1}(n,s.content,o)?a:null}function s8(e,t){let n=[],r=Math.min(e.depth,t.depth);for(let i=r;i>=0;i--){let r=e.start(i);if(r<e.pos-(e.depth-i)||t.end(i)>t.pos+(t.depth-i)||e.node(i).type.spec.isolating||t.node(i).type.spec.isolating)break;(r==t.start(i)||i==e.depth&&i==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&i&&t.start(i-1)==r-1)&&n.push(i)}return n}class oe extends sI{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return sL.fail("No node at attribute step's position");let n=Object.create(null);for(let e in t.attrs)n[e]=t.attrs[e];n[this.attr]=this.value;let r=t.type.create(n,null,t.marks);return sL.fromReplace(e,this.pos,this.pos+1,new iX(iW.from(r),0,+!t.isLeaf))}getMap(){return s_.empty}invert(e){return new oe(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new oe(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if("number"!=typeof t.pos||"string"!=typeof t.attr)throw RangeError("Invalid input for AttrStep.fromJSON");return new oe(t.pos,t.attr,t.value)}}sI.jsonID("attr",oe);class ot extends sI{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let n in e.attrs)t[n]=e.attrs[n];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return sL.ok(n)}getMap(){return s_.empty}invert(e){return new ot(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if("string"!=typeof t.attr)throw RangeError("Invalid input for DocAttrStep.fromJSON");return new ot(t.attr,t.value)}}sI.jsonID("docAttr",ot);let on=class extends Error{};(on=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n}).prototype=Object.create(Error.prototype),on.prototype.constructor=on,on.prototype.name="TransformError";class or{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new sD}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new on(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let n=0;n<this.mapping.maps.length;n++){let r=this.mapping.maps[n];n&&(e=r.map(e,1),t=r.map(t,-1)),r.forEach((n,r,i,s)=>{e=Math.min(e,i),t=Math.max(t,s)})}return 1e9==e?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=iX.empty){let r=s2(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new iX(iW.from(n),0,0))}delete(e,t){return this.replace(e,t,iX.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return!function(e,t,n,r){if(!r.size)return e.deleteRange(t,n);let i=e.doc.resolve(t),s=e.doc.resolve(n);if(s5(i,s,r))return e.step(new sH(t,n,r));let o=s8(i,s);0==o[o.length-1]&&o.pop();let a=-(i.depth+1);o.unshift(a);for(let e=i.depth,t=i.pos-1;e>0;e--,t--){let n=i.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;o.indexOf(e)>-1?a=e:i.before(e)==t&&o.splice(1,0,-e)}let l=o.indexOf(a),c=[],d=r.openStart;for(let e=r.content,t=0;;t++){let n=e.firstChild;if(c.push(n),t==r.openStart)break;e=n.content}for(let e=d-1;e>=0;e--){var u;let t=c[e],n=(u=t.type).spec.defining||u.spec.definingForContent;if(n&&!t.sameMarkup(i.node(Math.abs(a)-1)))d=e;else if(n||!t.type.isTextblock)break}for(let t=r.openStart;t>=0;t--){let a=(t+d+1)%(r.openStart+1),u=c[a];if(u)for(let t=0;t<o.length;t++){let c=o[(t+l)%o.length],d=!0;c<0&&(d=!1,c=-c);let p=i.node(c-1),h=i.index(c-1);if(p.canReplaceWith(h,h,u.type,u.marks))return e.replace(i.before(c),d?s.after(c):n,new iX(function e(t,n,r,i,s){if(n<r){let s=t.firstChild;t=t.replaceChild(0,s.copy(e(s.content,n+1,r,i,s)))}if(n>i){let e=s.contentMatchAt(0),n=e.fillBefore(t).append(t);t=n.append(e.matchFragment(n).fillBefore(iW.empty,!0))}return t}(r.content,0,r.openStart,a),a,r.openEnd))}}let p=e.steps.length;for(let a=o.length-1;a>=0&&(e.replace(t,n,r),!(e.steps.length>p));a--){let e=o[a];e<0||(t=i.before(e),n=s.after(e))}}(this,e,t,n),this}replaceRangeWith(e,t,n){var r=e,i=t;if(!n.isInline&&r==i&&this.doc.resolve(r).parent.content.size){let e=function(e,t,n){let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;if(0==r.parentOffset)for(let e=r.depth-1;e>=0;e--){let t=r.index(e);if(r.node(e).canReplaceWith(t,t,n))return r.before(e+1);if(t>0)return null}if(r.parentOffset==r.parent.content.size)for(let e=r.depth-1;e>=0;e--){let t=r.indexAfter(e);if(r.node(e).canReplaceWith(t,t,n))return r.after(e+1);if(t<r.node(e).childCount)break}return null}(this.doc,r,n.type);null!=e&&(r=i=e)}return this.replaceRange(r,i,new iX(iW.from(n),0,0)),this}deleteRange(e,t){return!function(e,t,n){let r=e.doc.resolve(t),i=e.doc.resolve(n);if(r.parent.isTextblock&&i.parent.isTextblock&&r.start()!=i.start()&&0==r.parentOffset&&0==i.parentOffset){let s=r.sharedDepth(n),o=!1;for(let e=r.depth;e>s;e--)r.node(e).type.spec.isolating&&(o=!0);for(let e=i.depth;e>s;e--)i.node(e).type.spec.isolating&&(o=!0);if(!o){for(let e=r.depth;e>0&&t==r.start(e);e--)t=r.before(e);for(let e=i.depth;e>0&&n==i.start(e);e--)n=i.before(e);r=e.doc.resolve(t),i=e.doc.resolve(n)}}let s=s8(r,i);for(let t=0;t<s.length;t++){let n=s[t],o=t==s.length-1;if(o&&0==n||r.node(n).type.contentMatch.validEnd)return e.delete(r.start(n),i.end(n));if(n>0&&(o||r.node(n-1).canReplace(r.index(n-1),i.indexAfter(n-1))))return e.delete(r.before(n),i.after(n))}for(let s=1;s<=r.depth&&s<=i.depth;s++)if(t-r.start(s)==r.depth-s&&n>r.end(s)&&i.end(s)-n!=i.depth-s&&r.start(s-1)==i.start(s-1)&&r.node(s-1).canReplace(r.index(s-1),i.index(s-1)))return e.delete(r.before(s),n);e.delete(t,n)}(this,e,t),this}lift(e,t){return!function(e,t,n){let{$from:r,$to:i,depth:s}=t,o=r.before(s+1),a=i.after(s+1),l=o,c=a,d=iW.empty,u=0;for(let e=s,t=!1;e>n;e--)t||r.index(e)>0?(t=!0,d=iW.from(r.node(e).copy(d)),u++):l--;let p=iW.empty,h=0;for(let e=s,t=!1;e>n;e--)t||i.after(e+1)<i.end(e)?(t=!0,p=iW.from(i.node(e).copy(p)),h++):c++;e.step(new sU(l,c,o,a,new iX(d.append(p),u,h),d.size-u,!0))}(this,e,t),this}join(e,t=1){return!function(e,t,n){let r=null,{linebreakReplacement:i}=e.doc.type.schema,s=e.doc.resolve(t-n),o=s.node().type;if(i&&o.inlineContent){let e="pre"==o.whitespace,t=!!o.contentMatch.matchType(i);e&&!t?r=!1:!e&&t&&(r=!0)}let a=e.steps.length;if(!1===r){let r=e.doc.resolve(t+n);sZ(e,r.node(),r.before(),a)}o.inlineContent&&sW(e,t+n-1,o,s.node().contentMatchAt(s.index()),null==r);let l=e.mapping.slice(a),c=l.map(t-n);if(e.step(new sH(c,l.map(t+n,-1),iX.empty,!0)),!0===r){let t=e.doc.resolve(c);sJ(e,t.node(),t.before(),e.steps.length)}}(this,e,t),this}wrap(e,t){return!function(e,t,n){let r=iW.empty;for(let e=n.length-1;e>=0;e--){if(r.size){let t=n[e].type.contentMatch.matchFragment(r);if(!t||!t.validEnd)throw RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=iW.from(n[e].type.create(n[e].attrs,r))}let i=t.start,s=t.end;e.step(new sU(i,s,i,s,new iX(r,0,0),n.length,!0))}(this,e,t),this}setBlockType(e,t=e,n,r=null){var i=this;if(!n.isTextblock)throw RangeError("Type given to setBlockType should be a textblock");let s=i.steps.length;return i.doc.nodesBetween(e,t,(e,t)=>{var o,a,l;let c,d,u="function"==typeof r?r(e):r;if(e.isTextblock&&!e.hasMarkup(n,u)&&(o=i.doc,a=i.mapping.slice(s).map(t),l=n,d=(c=o.resolve(a)).index(),c.parent.canReplaceWith(d,d+1,l))){let r=null;if(n.schema.linebreakReplacement){let e="pre"==n.whitespace,t=!!n.contentMatch.matchType(n.schema.linebreakReplacement);e&&!t?r=!1:!e&&t&&(r=!0)}!1===r&&sZ(i,e,t,s),sW(i,i.mapping.slice(s).map(t,1),n,void 0,null===r);let o=i.mapping.slice(s),a=o.map(t,1),l=o.map(t+e.nodeSize,1);return i.step(new sU(a,l,a+1,l-1,new iX(iW.from(n.create(u,null,e.marks)),0,0),1,!0)),!0===r&&sJ(i,e,t,s),!1}}),this}setNodeMarkup(e,t,n=null,r){return!function(e,t,n,r,i){let s=e.doc.nodeAt(t);if(!s)throw RangeError("No node at given position");n||(n=s.type);let o=n.create(r,null,i||s.marks);if(s.isLeaf)return e.replaceWith(t,t+s.nodeSize,o);if(!n.validContent(s.content))throw RangeError("Invalid content for node type "+n.name);e.step(new sU(t,t+s.nodeSize,t+1,t+s.nodeSize-1,new iX(iW.from(o),0,0),1,!0))}(this,e,t,n,r),this}setNodeAttribute(e,t,n){return this.step(new oe(e,t,n)),this}setDocAttribute(e,t){return this.step(new ot(e,t)),this}addNodeMark(e,t){return this.step(new sB(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw RangeError("No node at position "+e);if(t instanceof iJ)t.isInSet(n.marks)&&this.step(new sF(e,t));else{let r=n.marks,i,s=[];for(;i=t.isInSet(r);)s.push(new sF(e,i)),r=i.removeFromSet(r);for(let e=s.length-1;e>=0;e--)this.step(s[e])}return this}split(e,t=1,n){return!function(e,t,n=1,r){let i=e.doc.resolve(t),s=iW.empty,o=iW.empty;for(let e=i.depth,t=i.depth-n,a=n-1;e>t;e--,a--){s=iW.from(i.node(e).copy(s));let t=r&&r[a];o=iW.from(t?t.type.create(t.attrs,o):i.node(e).copy(o))}e.step(new sH(t,t,new iX(s.append(o),n,n),!0))}(this,e,t,n),this}addMark(e,t,n){var r;let i,s,o,a;return r=this,o=[],a=[],r.doc.nodesBetween(e,t,(r,l,c)=>{if(!r.isInline)return;let d=r.marks;if(!n.isInSet(d)&&c.type.allowsMarkType(n.type)){let c=Math.max(l,e),u=Math.min(l+r.nodeSize,t),p=n.addToSet(d);for(let e=0;e<d.length;e++)d[e].isInSet(p)||(i&&i.to==c&&i.mark.eq(d[e])?i.to=u:o.push(i=new sz(c,u,d[e])));s&&s.to==c?s.to=u:a.push(s=new s$(c,u,n))}}),o.forEach(e=>r.step(e)),a.forEach(e=>r.step(e)),this}removeMark(e,t,n){var r;let i,s;return r=this,i=[],s=0,r.doc.nodesBetween(e,t,(r,o)=>{if(!r.isInline)return;s++;let a=null;if(n instanceof sm){let e=r.marks,t;for(;t=n.isInSet(e);)(a||(a=[])).push(t),e=t.removeFromSet(e)}else n?n.isInSet(r.marks)&&(a=[n]):a=r.marks;if(a&&a.length){let n=Math.min(o+r.nodeSize,t);for(let t=0;t<a.length;t++){let r=a[t],l;for(let e=0;e<i.length;e++){let t=i[e];t.step==s-1&&r.eq(i[e].style)&&(l=t)}l?(l.to=n,l.step=s):i.push({style:r,from:Math.max(o,e),to:n,step:s})}}}),i.forEach(e=>r.step(new sz(e.from,e.to,e.style))),this}clearIncompatible(e,t,n){return sW(this,e,t,n),this}}let oi=Object.create(null);class oo{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new oa(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=iX.empty){let n=t.content.lastChild,r=null;for(let e=0;e<t.openEnd;e++)r=n,n=n.lastChild;let i=e.steps.length,s=this.ranges;for(let o=0;o<s.length;o++){let{$from:a,$to:l}=s[o],c=e.mapping.slice(i);e.replaceRange(c.map(a.pos),c.map(l.pos),o?iX.empty:t),0==o&&ox(e,i,(n?n.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:s,$to:o}=r[i],a=e.mapping.slice(n),l=a.map(s.pos),c=a.map(o.pos);i?e.deleteRange(l,c):(e.replaceRangeWith(l,c,t),ox(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new od(e):og(e.node(0),e.parent,e.pos,e.index(),t,n);if(r)return r;for(let r=e.depth-1;r>=0;r--){let i=t<0?og(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):og(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,t,n);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new om(e.node(0))}static atStart(e){return og(e,e,0,0,1)||new om(e)}static atEnd(e){return og(e,e,e.content.size,e.childCount,-1)||new om(e)}static fromJSON(e,t){if(!t||!t.type)throw RangeError("Invalid input for Selection.fromJSON");let n=oi[t.type];if(!n)throw RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in oi)throw RangeError("Duplicate use of selection JSON ID "+e);return oi[e]=t,t.prototype.jsonID=e,t}getBookmark(){return od.between(this.$anchor,this.$head).getBookmark()}}oo.prototype.visible=!0;class oa{constructor(e,t){this.$from=e,this.$to=t}}let ol=!1;function oc(e){ol||e.parent.inlineContent||(ol=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class od extends oo{constructor(e,t=e){oc(e),oc(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return oo.near(n);let r=e.resolve(t.map(this.anchor));return new od(r.parent.inlineContent?r:n,n)}replace(e,t=iX.empty){if(super.replace(e,t),t==iX.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(e){return e instanceof od&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new ou(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if("number"!=typeof t.anchor||"number"!=typeof t.head)throw RangeError("Invalid input for TextSelection.fromJSON");return new od(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(e,t,n){let r=e.pos-t.pos;if((!n||r)&&(n=r>=0?1:-1),!t.parent.inlineContent){let e=oo.findFrom(t,n,!0)||oo.findFrom(t,-n,!0);if(!e)return oo.near(t,n);t=e.$head}return e.parent.inlineContent||(0==r?e=t:(e=(oo.findFrom(e,-n,!0)||oo.findFrom(e,n,!0)).$anchor).pos<t.pos!=r<0&&(e=t)),new od(e,t)}}oo.jsonID("text",od);class ou{constructor(e,t){this.anchor=e,this.head=t}map(e){return new ou(e.map(this.anchor),e.map(this.head))}resolve(e){return od.between(e.resolve(this.anchor),e.resolve(this.head))}}class op extends oo{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(e,t){let{deleted:n,pos:r}=t.mapResult(this.anchor),i=e.resolve(r);return n?oo.near(i):new op(i)}content(){return new iX(iW.from(this.node),0,0)}eq(e){return e instanceof op&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new oh(this.anchor)}static fromJSON(e,t){if("number"!=typeof t.anchor)throw RangeError("Invalid input for NodeSelection.fromJSON");return new op(e.resolve(t.anchor))}static create(e,t){return new op(e.resolve(t))}static isSelectable(e){return!e.isText&&!1!==e.type.spec.selectable}}op.prototype.visible=!1,oo.jsonID("node",op);class oh{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new ou(n,n):new oh(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&op.isSelectable(n)?new op(t):oo.near(t)}}class om extends oo{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=iX.empty){if(t==iX.empty){e.delete(0,e.doc.content.size);let t=oo.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new om(e)}map(e){return new om(e)}eq(e){return e instanceof om}getBookmark(){return of}}oo.jsonID("all",om);let of={map(){return this},resolve:e=>new om(e)};function og(e,t,n,r,i,s=!1){if(t.inlineContent)return od.create(e,n);for(let o=r-(i>0?0:1);i>0?o<t.childCount:o>=0;o+=i){let r=t.child(o);if(r.isAtom){if(!s&&op.isSelectable(r))return op.create(e,n-(i<0?r.nodeSize:0))}else{let t=og(e,r,n+i,i<0?r.childCount:0,i,s);if(t)return t}n+=r.nodeSize*i}return null}function ox(e,t,n){let r,i=e.steps.length-1;if(i<t)return;let s=e.steps[i];(s instanceof sH||s instanceof sU)&&(e.mapping.maps[i].forEach((e,t,n,i)=>{null==r&&(r=i)}),e.setSelection(oo.near(e.doc.resolve(r),n)))}class ob extends or{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(1|this.updated)&-3,this.storedMarks=null,this}get selectionSet(){return(1&this.updated)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=2,this}ensureMarks(e){return iJ.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(2&this.updated)>0}addStep(e,t){super.addStep(e,t),this.updated=-3&this.updated,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||iJ.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(null==t)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(null==n&&(n=t),!e)return this.deleteRange(t,n);let i=this.storedMarks;if(!i){let e=this.doc.resolve(t);i=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,i)),this.selection.empty||this.selection.to!=t+e.length||this.setSelection(oo.near(this.selection.$to)),this}}setMeta(e,t){return this.meta["string"==typeof e?e:e.key]=t,this}getMeta(e){return this.meta["string"==typeof e?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=4,this}get scrolledIntoView(){return(4&this.updated)>0}}function oy(e,t){return t&&e?e.bind(t):e}class ov{constructor(e,t,n){this.name=e,this.init=oy(t.init,n),this.apply=oy(t.apply,n)}}let ow=[new ov("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new ov("selection",{init:(e,t)=>e.selection||oo.atStart(t.doc),apply:e=>e.selection}),new ov("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,r)=>r.selection.$cursor?e.storedMarks:null}),new ov("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t})];class ok{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=ow.slice(),t&&t.forEach(e=>{if(this.pluginsByKey[e.key])throw RangeError("Adding different instances of a keyed plugin ("+e.key+")");this.plugins.push(e),this.pluginsByKey[e.key]=e,e.spec.state&&this.fields.push(new ov(e.key,e.spec.state,e))})}}class oN{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;n<this.config.plugins.length;n++)if(n!=t){let t=this.config.plugins[n];if(t.spec.filterTransaction&&!t.spec.filterTransaction.call(t,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),r=null;for(;;){let i=!1;for(let s=0;s<this.config.plugins.length;s++){let o=this.config.plugins[s];if(o.spec.appendTransaction){let a=r?r[s].n:0,l=r?r[s].state:this,c=a<t.length&&o.spec.appendTransaction.call(o,a?t.slice(a):t,l,n);if(c&&n.filterTransaction(c,s)){if(c.setMeta("appendedTransaction",e),!r){r=[];for(let e=0;e<this.config.plugins.length;e++)r.push(e<s?{state:n,n:t.length}:{state:this,n:0})}t.push(c),n=n.applyInner(c),i=!0}r&&(r[s]={state:n,n:t.length})}}if(!i)return{state:n,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw RangeError("Applying a mismatched transaction");let t=new oN(this.config),n=this.config.fields;for(let r=0;r<n.length;r++){let i=n[r];t[i.name]=i.apply(e,this[i.name],this,t)}return t}get tr(){return new ob(this)}static create(e){let t=new ok(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new oN(t);for(let r=0;r<t.fields.length;r++)n[t.fields[r].name]=t.fields[r].init(e,n);return n}reconfigure(e){let t=new ok(this.schema,e.plugins),n=t.fields,r=new oN(t);for(let t=0;t<n.length;t++){let i=n[t].name;r[i]=this.hasOwnProperty(i)?this[i]:n[t].init(e,r)}return r}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(e=>e.toJSON())),e&&"object"==typeof e)for(let n in e){if("doc"==n||"selection"==n)throw RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[n],i=r.spec.state;i&&i.toJSON&&(t[n]=i.toJSON.call(r,this[r.key]))}return t}static fromJSON(e,t,n){if(!t)throw RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw RangeError("Required config field 'schema' missing");let r=new ok(e.schema,e.plugins),i=new oN(r);return r.fields.forEach(r=>{if("doc"==r.name)i.doc=se.fromJSON(e.schema,t.doc);else if("selection"==r.name)i.selection=oo.fromJSON(i.doc,t.selection);else if("storedMarks"==r.name)t.storedMarks&&(i.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(n)for(let s in n){let o=n[s],a=o.spec.state;if(o.key==r.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,s)){i[r.name]=a.fromJSON.call(o,e,t[s],i);return}}i[r.name]=r.init(e,i)}}),i}}class oS{constructor(e){this.spec=e,this.props={},e.props&&function e(t,n,r){for(let i in t){let s=t[i];s instanceof Function?s=s.bind(n):"handleDOMEvents"==i&&(s=e(s,n,{})),r[i]=s}return r}(e.props,this,this.props),this.key=e.key?e.key.key:oj("plugin")}getState(e){return e[this.key]}}let oC=Object.create(null);function oj(e){return e in oC?e+"$"+ ++oC[e]:(oC[e]=0,e+"$")}class oE{constructor(e="key"){this.key=oj(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}let oM=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},oA=function(e){let t=e.assignedSlot||e.parentNode;return t&&11==t.nodeType?t.host:t},oT=null,oO=function(e,t,n){let r=oT||(oT=document.createRange());return r.setEnd(e,null==n?e.nodeValue.length:n),r.setStart(e,t||0),r},o_=function(){oT=null},oD=function(e,t,n,r){return n&&(oI(e,t,n,r,-1)||oI(e,t,n,r,1))},oR=/^(img|br|input|textarea|hr)$/i;function oI(e,t,n,r,i){for(var s;;){if(e==n&&t==r)return!0;if(t==(i<0?0:oL(e))){let n=e.parentNode;if(!n||1!=n.nodeType||oP(e)||oR.test(e.nodeName)||"false"==e.contentEditable)return!1;t=oM(e)+(i<0?0:1),e=n}else{if(1!=e.nodeType)return!1;let n=e.childNodes[t+(i<0?-1:0)];if(1==n.nodeType&&"false"==n.contentEditable)if(null==(s=n.pmViewDesc)||!s.ignoreForSelection)return!1;else t+=i;else e=n,t=i<0?oL(e):0}}}function oL(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function oP(e){let t;for(let n=e;n&&!(t=n.pmViewDesc);n=n.parentNode);return t&&t.node&&t.node.isBlock&&(t.dom==e||t.contentDOM==e)}let o$=function(e){return e.focusNode&&oD(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function oz(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}let oB="u">typeof navigator?navigator:null,oF="u">typeof document?document:null,oH=oB&&oB.userAgent||"",oU=/Edge\/(\d+)/.exec(oH),oV=/MSIE \d/.exec(oH),oW=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(oH),oq=!!(oV||oW||oU),oK=oV?document.documentMode:oW?+oW[1]:oU?+oU[1]:0,oG=!oq&&/gecko\/(\d+)/i.test(oH);oG&&(/Firefox\/(\d+)/.exec(oH)||[0,0])[1];let oJ=!oq&&/Chrome\/(\d+)/.exec(oH),oZ=!!oJ,oX=oJ?+oJ[1]:0,oY=!oq&&!!oB&&/Apple Computer/.test(oB.vendor),oQ=oY&&(/Mobile\/\w+/.test(oH)||!!oB&&oB.maxTouchPoints>2),o0=oQ||!!oB&&/Mac/.test(oB.platform),o1=!!oB&&/Win/.test(oB.platform),o2=/Android \d/.test(oH),o5=!!oF&&"webkitFontSmoothing"in oF.documentElement.style,o3=o5?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function o4(e,t){return"number"==typeof e?e:e[t]}function o6(e,t,n){let r=e.someProp("scrollThreshold")||0,i=e.someProp("scrollMargin")||5,s=e.dom.ownerDocument;for(let o=n||e.dom;o;){if(1!=o.nodeType){o=oA(o);continue}let e=o,n=e==s.body,a=n?function(e){let t=e.defaultView&&e.defaultView.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}(s):function(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}(e),l=0,c=0;if(t.top<a.top+o4(r,"top")?c=-(a.top-t.top+o4(i,"top")):t.bottom>a.bottom-o4(r,"bottom")&&(c=t.bottom-t.top>a.bottom-a.top?t.top+o4(i,"top")-a.top:t.bottom-a.bottom+o4(i,"bottom")),t.left<a.left+o4(r,"left")?l=-(a.left-t.left+o4(i,"left")):t.right>a.right-o4(r,"right")&&(l=t.right-a.right+o4(i,"right")),l||c)if(n)s.defaultView.scrollBy(l,c);else{let n=e.scrollLeft,r=e.scrollTop;c&&(e.scrollTop+=c),l&&(e.scrollLeft+=l);let i=e.scrollLeft-n,s=e.scrollTop-r;t={left:t.left-i,top:t.top-s,right:t.right-i,bottom:t.bottom-s}}let d=n?"fixed":getComputedStyle(o).position;if(/^(fixed|sticky)$/.test(d))break;o="absolute"==d?o.offsetParent:oA(o)}}function o9(e){let t=[],n=e.ownerDocument;for(let r=e;r&&(t.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),e!=n);r=oA(r));return t}function o7(e,t){for(let n=0;n<e.length;n++){let{dom:r,top:i,left:s}=e[n];r.scrollTop!=i+t&&(r.scrollTop=i+t),r.scrollLeft!=s&&(r.scrollLeft=s)}}let o8=null;function ae(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function at(e){return e.top<e.bottom||e.left<e.right}function an(e,t){let n=e.getClientRects();if(n.length){let e=n[t<0?0:n.length-1];if(at(e))return e}return Array.prototype.find.call(n,at)||e.getBoundingClientRect()}let ar=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function ai(e,t,n){let{node:r,offset:i,atom:s}=e.docView.domFromPos(t,n<0?-1:1),o=o5||oG;if(3==r.nodeType)if(o&&(ar.test(r.nodeValue)||(n<0?!i:i==r.nodeValue.length))){let e=an(oO(r,i,i),n);if(oG&&i&&/\s/.test(r.nodeValue[i-1])&&i<r.nodeValue.length){let t=an(oO(r,i-1,i-1),-1);if(t.top==e.top){let n=an(oO(r,i,i+1),-1);if(n.top!=e.top)return as(n,n.left<t.left)}}return e}else{let e=i,t=i,s=n<0?1:-1;return n<0&&!i?(t++,s=-1):n>=0&&i==r.nodeValue.length?(e--,s=1):n<0?e--:t++,as(an(oO(r,e,t),s),s<0)}if(!e.state.doc.resolve(t-(s||0)).parent.inlineContent){if(null==s&&i&&(n<0||i==oL(r))){let e=r.childNodes[i-1];if(1==e.nodeType)return ao(e.getBoundingClientRect(),!1)}if(null==s&&i<oL(r)){let e=r.childNodes[i];if(1==e.nodeType)return ao(e.getBoundingClientRect(),!0)}return ao(r.getBoundingClientRect(),n>=0)}if(null==s&&i&&(n<0||i==oL(r))){let e=r.childNodes[i-1],t=3==e.nodeType?oO(e,oL(e)-!o):1!=e.nodeType||"BR"==e.nodeName&&e.nextSibling?null:e;if(t)return as(an(t,1),!1)}if(null==s&&i<oL(r)){let e=r.childNodes[i];for(;e.pmViewDesc&&e.pmViewDesc.ignoreForCoords;)e=e.nextSibling;let t=e?3==e.nodeType?oO(e,0,+!o):1==e.nodeType?e:null:null;if(t)return as(an(t,-1),!0)}return as(an(3==r.nodeType?oO(r):r,-n),n>=0)}function as(e,t){if(0==e.width)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function ao(e,t){if(0==e.height)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function aa(e,t,n){let r=e.state,i=e.root.activeElement;r!=t&&e.updateState(t),i!=e.dom&&e.focus();try{return n()}finally{r!=t&&e.updateState(r),i!=e.dom&&i&&i.focus()}}let al=/[\u0590-\u08ac]/,ac=null,ad=null,au=!1;class ap{constructor(e,t,n,r){this.parent=e,this.children=t,this.dom=n,this.contentDOM=r,this.dirty=0,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let t=0,n=this.posAtStart;;t++){let r=this.children[t];if(r==e)return n;n+=r.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,t,n){let r;if(this.contentDOM&&this.contentDOM.contains(1==e.nodeType?e:e.parentNode))if(n<0){let n,r;if(e==this.contentDOM)n=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.previousSibling}for(;n&&!((r=n.pmViewDesc)&&r.parent==this);)n=n.previousSibling;return n?this.posBeforeChild(r)+r.size:this.posAtStart}else{let n,r;if(e==this.contentDOM)n=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.nextSibling}for(;n&&!((r=n.pmViewDesc)&&r.parent==this);)n=n.nextSibling;return n?this.posBeforeChild(r):this.posAtEnd}if(e==this.dom&&this.contentDOM)r=t>oM(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=2&e.compareDocumentPosition(this.contentDOM);else if(this.dom.firstChild){if(0==t)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!1;break}if(t.previousSibling)break}if(null==r&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!0;break}if(t.nextSibling)break}}return(null==r?n>0:r)?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,r=e;r;r=r.parentNode){let i=this.getDesc(r),s;if(i&&(!t||i.node))if(!n||!(s=i.nodeDOM)||(1==s.nodeType?s.contains(1==e.nodeType?e:e.parentNode):s==e))return i;else n=!1}}getDesc(e){let t=e.pmViewDesc;for(let e=t;e;e=e.parent)if(e==this)return t}posFromDOM(e,t,n){for(let r=e;r;r=r.parentNode){let i=this.getDesc(r);if(i)return i.localPosFromDOM(e,t,n)}return -1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let r=this.children[t],i=n+r.size;if(n==e&&i!=n){for(;!r.border&&r.children.length;)for(let e=0;e<r.children.length;e++){let t=r.children[e];if(t.size){r=t;break}}return r}if(e<i)return r.descAt(e-n-r.border);n=i}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,r=0;for(let t=0;n<this.children.length;n++){let i=this.children[n],s=t+i.size;if(s>e||i instanceof ay){r=e-t;break}t=s}if(r)return this.children[n].domFromPos(r-this.children[n].border,t);for(let e;n&&!(e=this.children[n-1]).size&&e instanceof ah&&e.side>=0;n--);if(t<=0){let e,r=!0;for(;(e=n?this.children[n-1]:null)&&e.dom.parentNode!=this.contentDOM;n--,r=!1);return e&&t&&r&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?oM(e.dom)+1:0}}{let e,r=!0;for(;(e=n<this.children.length?this.children[n]:null)&&e.dom.parentNode!=this.contentDOM;n++,r=!1);return e&&r&&!e.border&&!e.domAtom?e.domFromPos(0,t):{node:this.contentDOM,offset:e?oM(e.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,n=0){if(0==this.children.length)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let r=-1,i=-1;for(let s=n,o=0;;o++){let n=this.children[o],a=s+n.size;if(-1==r&&e<=a){let i=s+n.border;if(e>=i&&t<=a-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,i);e=s;for(let t=o;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){r=oM(n.dom)+1;break}e-=n.size}-1==r&&(r=0)}if(r>-1&&(a>t||o==this.children.length-1)){t=a;for(let e=o+1;e<this.children.length;e++){let n=this.children[e];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(-1)){i=oM(n.dom);break}t+=n.size}-1==i&&(i=this.contentDOM.childNodes.length);break}s=a}return{node:this.contentDOM,from:e,to:t,fromOffset:r,toOffset:i}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return 0==t.size||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:n}=this.domFromPos(e,0);if(1!=t.nodeType||n==t.childNodes.length)throw RangeError("No node after pos "+e);return t.childNodes[n]}setSelection(e,t,n,r=!1){let i=Math.min(e,t),s=Math.max(e,t);for(let o=0,a=0;o<this.children.length;o++){let l=this.children[o],c=a+l.size;if(i>a&&s<c)return l.setSelection(e-a-l.border,t-a-l.border,n,r);a=c}let o=this.domFromPos(e,e?-1:1),a=t==e?o:this.domFromPos(t,t?-1:1),l=n.root.getSelection(),c=n.domSelectionRange(),d=!1;if((oG||oY)&&e==t){let{node:e,offset:t}=o;if(3==e.nodeType){if((d=!!(t&&"\n"==e.nodeValue[t-1]))&&t==e.nodeValue.length)for(let t=e,n;t;t=t.parentNode){if(n=t.nextSibling){"BR"==n.nodeName&&(o=a={node:n.parentNode,offset:oM(n)+1});break}let e=t.pmViewDesc;if(e&&e.node&&e.node.isBlock)break}}else{let n=e.childNodes[t-1];d=n&&("BR"==n.nodeName||"false"==n.contentEditable)}}if(oG&&c.focusNode&&c.focusNode!=a.node&&1==c.focusNode.nodeType){let e=c.focusNode.childNodes[c.focusOffset];e&&"false"==e.contentEditable&&(r=!0)}if(!(r||d&&oY)&&oD(o.node,o.offset,c.anchorNode,c.anchorOffset)&&oD(a.node,a.offset,c.focusNode,c.focusOffset))return;let u=!1;if((l.extend||e==t)&&!(d&&oG)){l.collapse(o.node,o.offset);try{e!=t&&l.extend(a.node,a.offset),u=!0}catch(e){}}if(!u){if(e>t){let e=o;o=a,a=e}let n=document.createRange();n.setEnd(a.node,a.offset),n.setStart(o.node,o.offset),l.removeAllRanges(),l.addRange(n)}}ignoreMutation(e){return!this.contentDOM&&"selection"!=e.type}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,r=0;r<this.children.length;r++){let i=this.children[r],s=n+i.size;if(n==s?e<=s&&t>=n:e<s&&t>n){let r=n+i.border,o=s-i.border;if(e>=r&&t<=o){this.dirty=e==n||t==s?2:1,e==r&&t==o&&(i.contentLost||i.dom.parentNode!=this.contentDOM)?i.dirty=3:i.markDirty(e-r,t-r);return}i.dirty=i.dom!=i.contentDOM||i.dom.parentNode!=this.contentDOM||i.children.length?3:2}n=s}this.dirty=2}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=1==e?2:1;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class ah extends ap{constructor(e,t,n,r){let i,s=t.type.toDOM;if("function"==typeof s&&(s=s(n,()=>i?i.parent?i.parent.posBeforeChild(i):void 0:r)),!t.type.spec.raw){if(1!=s.nodeType){let e=document.createElement("span");e.appendChild(s),s=e}s.contentEditable="false",s.classList.add("ProseMirror-widget")}super(e,[],s,null),this.widget=t,this.widget=t,i=this}matchesWidget(e){return 0==this.dirty&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return!!t&&t(e)}ignoreMutation(e){return"selection"!=e.type||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class am extends ap{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return"characterData"===e.type&&e.target.nodeValue==e.oldValue}}class af extends ap{constructor(e,t,n,r,i){super(e,[],n,r),this.mark=t,this.spec=i}static create(e,t,n,r){let i=r.nodeViews[t.type.name],s=i&&i(t,r,n);return s&&s.dom||(s=sj.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new af(e,t,s.dom,s.contentDOM||s.dom,s)}parseRule(){return 3&this.dirty||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return 3!=this.dirty&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),0!=this.dirty){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty<this.dirty&&(e.dirty=this.dirty),this.dirty=0}}slice(e,t,n){let r=af.create(this.parent,this.mark,!0,n),i=this.children,s=this.size;t<s&&(i=aT(i,t,s,n)),e>0&&(i=aT(i,0,e,n));for(let e=0;e<i.length;e++)i[e].parent=r;return r.children=i,r}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class ag extends ap{constructor(e,t,n,r,i,s,o,a,l){super(e,[],i,s),this.node=t,this.outerDeco=n,this.innerDeco=r,this.nodeDOM=o}static create(e,t,n,r,i,s){let o=i.nodeViews[t.type.name],a,l=o&&o(t,i,()=>a?a.parent?a.parent.posBeforeChild(a):void 0:s,n,r),c=l&&l.dom,d=l&&l.contentDOM;if(t.isText)if(c){if(3!=c.nodeType)throw RangeError("Text must be rendered as a DOM text node")}else c=document.createTextNode(t.text);else if(!c){let e=sj.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs);({dom:c,contentDOM:d}=e)}d||t.isText||"BR"==c.nodeName||(c.hasAttribute("contenteditable")||(c.contentEditable="false"),t.type.spec.draggable&&(c.draggable=!0));let u=c;return(c=aC(c,n,t),l)?a=new av(e,t,n,r,c,d||null,u,l,i,s+1):t.isText?new ab(e,t,n,r,c,u,i):new ag(e,t,n,r,c,d||null,u,i,s+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if("pre"==this.node.type.whitespace&&(e.preserveWhitespace="full"),this.contentDOM)if(this.contentLost){for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>iW.empty)}else e.contentElement=this.contentDOM;else e.getContent=()=>this.node.content;return e}matchesNode(e,t,n){return 0==this.dirty&&e.eq(this.node)&&aj(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return+!this.node.isLeaf}updateChildren(e,t){let n=this.node.inlineContent,r=t,i=e.composing?this.localCompositionInfo(e,t):null,s=i&&i.pos>-1?i:null,o=i&&i.pos<0,a=new aM(this,s&&s.node,e);(function(e,t,n,r){let i=t.locals(e),s=0;if(0==i.length){for(let n=0;n<e.childCount;n++){let o=e.child(n);r(o,i,t.forChild(s,o),n),s+=o.nodeSize}return}let o=0,a=[],l=null;for(let c=0;;){let d,u,p,h;for(;o<i.length&&i[o].to==s;){let e=i[o++];e.widget&&(d?(u||(u=[d])).push(e):d=e)}if(d)if(u){u.sort(aA);for(let e=0;e<u.length;e++)n(u[e],c,!!l)}else n(d,c,!!l);if(l)h=-1,p=l,l=null;else if(c<e.childCount)h=c,p=e.child(c++);else break;for(let e=0;e<a.length;e++)a[e].to<=s&&a.splice(e--,1);for(;o<i.length&&i[o].from<=s&&i[o].to>s;)a.push(i[o++]);let m=s+p.nodeSize;if(p.isText){let e=m;o<i.length&&i[o].from<e&&(e=i[o].from);for(let t=0;t<a.length;t++)a[t].to<e&&(e=a[t].to);e<m&&(l=p.cut(e-s),p=p.cut(0,e-s),m=e,h=-1)}else for(;o<i.length&&i[o].to<m;)o++;let f=p.isInline&&!p.isLeaf?a.filter(e=>!e.inline):a.slice();r(p,f,t.forChild(s,p),h),s=m}})(this.node,this.innerDeco,(t,i,s)=>{t.spec.marks?a.syncToMarks(t.spec.marks,n,e,i):t.type.side>=0&&!s&&a.syncToMarks(i==this.node.childCount?iJ.none:this.node.child(i).marks,n,e,i),a.placeWidget(t,e,r)},(t,s,l,c)=>{let d;a.syncToMarks(t.marks,n,e,c),a.findNodeMatch(t,s,l,c)||o&&e.state.selection.from>r&&e.state.selection.to<r+t.nodeSize&&(d=a.findIndexWithChild(i.node))>-1&&a.updateNodeAt(t,s,l,d,e)||a.updateNextNode(t,s,l,e,c,r)||a.addNode(t,s,l,e,r),r+=t.nodeSize}),a.syncToMarks([],n,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||2==this.dirty)&&(s&&this.protectLocalComposition(e,s),function e(t,n,r){let i=t.firstChild,s=!1;for(let o=0;o<n.length;o++){let a=n[o],l=a.dom;if(l.parentNode==t){for(;l!=i;)i=aE(i),s=!0;i=i.nextSibling}else s=!0,t.insertBefore(l,i);if(a instanceof af){let n=i?i.previousSibling:t.lastChild;e(a.contentDOM,a.children,r),i=n?n.nextSibling:t.firstChild}}for(;i;)i=aE(i),s=!0;s&&r.trackWrites==t&&(r.trackWrites=null)}(this.contentDOM,this.children,e),oQ&&function(e){if("UL"==e.nodeName||"OL"==e.nodeName){let t=e.style.cssText;e.style.cssText=t+"; list-style: square !important",window.getComputedStyle(e).listStyle,e.style.cssText=t}}(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof od)||n<t||r>t+this.node.content.size)return null;let i=e.input.compositionNode;if(!i||!this.dom.contains(i.parentNode))return null;if(!this.node.inlineContent)return{node:i,pos:-1,text:""};{let e=i.nodeValue,s=function(e,t,n,r){for(let i=0,s=0;i<e.childCount&&s<=r;){let o=e.child(i++),a=s;if(s+=o.nodeSize,!o.isText)continue;let l=o.text;for(;i<e.childCount;){let t=e.child(i++);if(s+=t.nodeSize,!t.isText)break;l+=t.text}if(s>=n){if(s>=r&&l.slice(r-t.length-a,r-a)==t)return r-t.length;let e=a<r?l.lastIndexOf(t,r-a-1):-1;if(e>=0&&e+t.length+a>=n)return a+e;if(n==r&&l.length>=r+t.length-a&&l.slice(r-a,r-a+t.length)==t)return r}}return -1}(this.node.content,e,n-t,r-t);return s<0?null:{node:i,pos:s,text:e}}}protectLocalComposition(e,{node:t,pos:n,text:r}){if(this.getDesc(t))return;let i=t;for(;i.parentNode!=this.contentDOM;i=i.parentNode){for(;i.previousSibling;)i.parentNode.removeChild(i.previousSibling);for(;i.nextSibling;)i.parentNode.removeChild(i.nextSibling);i.pmViewDesc&&(i.pmViewDesc=void 0)}let s=new am(this,i,t,r);e.input.compositionNodes.push(s),this.children=aT(this.children,n,n+r.length,e,s)}update(e,t,n,r){return 3!=this.dirty&&!!e.sameMarkup(this.node)&&(this.updateInner(e,t,n,r),!0)}updateInner(e,t,n,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=0}updateOuterDeco(e){if(aj(e,this.outerDeco))return;let t=1!=this.nodeDOM.nodeType,n=this.dom;this.dom=aS(this.dom,this.nodeDOM,aN(this.outerDeco,this.node,t),aN(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){1==this.nodeDOM.nodeType&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function ax(e,t,n,r,i){aC(r,t,e);let s=new ag(void 0,e,t,n,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class ab extends ag{constructor(e,t,n,r,i,s,o){super(e,t,n,r,i,null,s,o,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return 3!=this.dirty&&(0==this.dirty||!!this.inParent())&&!!e.sameMarkup(this.node)&&(this.updateOuterDeco(t),(0!=this.dirty||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=0,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return"characterData"!=e.type&&"selection"!=e.type}slice(e,t,n){let r=this.node.cut(e,t),i=document.createTextNode(r.text);return new ab(this.parent,r,this.outerDeco,this.innerDeco,i,i,n)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(0==e||t==this.nodeDOM.nodeValue.length)&&(this.dirty=3)}get domAtom(){return!1}isText(e){return this.node.text==e}}class ay extends ap{parseRule(){return{ignore:!0}}matchesHack(e){return 0==this.dirty&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return"IMG"==this.dom.nodeName}}class av extends ag{constructor(e,t,n,r,i,s,o,a,l,c){super(e,t,n,r,i,s,o,l,c),this.spec=a}update(e,t,n,r){if(3==this.dirty)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let i=this.spec.update(e,t,n);return i&&this.updateInner(e,t,n,r),i}return(!!this.contentDOM||!!e.isLeaf)&&super.update(e,t,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,r){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return!!this.spec.stopEvent&&this.spec.stopEvent(e)}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}let aw=function(e){e&&(this.nodeName=e)};aw.prototype=Object.create(null);let ak=[new aw];function aN(e,t,n){if(0==e.length)return ak;let r=n?ak[0]:new aw,i=[r];for(let s=0;s<e.length;s++){let o=e[s].type.attrs;if(o)for(let e in o.nodeName&&i.push(r=new aw(o.nodeName)),o){let s=o[e];null!=s&&(n&&1==i.length&&i.push(r=new aw(t.isInline?"span":"div")),"class"==e?r.class=(r.class?r.class+" ":"")+s:"style"==e?r.style=(r.style?r.style+";":"")+s:"nodeName"!=e&&(r[e]=s))}}return i}function aS(e,t,n,r){if(n==ak&&r==ak)return t;let i=t;for(let t=0;t<r.length;t++){let s=r[t],o=n[t];if(t){let t;o&&o.nodeName==s.nodeName&&i!=e&&(t=i.parentNode)&&t.nodeName.toLowerCase()==s.nodeName||((t=document.createElement(s.nodeName)).pmIsDeco=!0,t.appendChild(i),o=ak[0]),i=t}!function(e,t,n){for(let r in t)"class"==r||"style"==r||"nodeName"==r||r in n||e.removeAttribute(r);for(let r in n)"class"!=r&&"style"!=r&&"nodeName"!=r&&n[r]!=t[r]&&e.setAttribute(r,n[r]);if(t.class!=n.class){let r=t.class?t.class.split(" ").filter(Boolean):[],i=n.class?n.class.split(" ").filter(Boolean):[];for(let t=0;t<r.length;t++)-1==i.indexOf(r[t])&&e.classList.remove(r[t]);for(let t=0;t<i.length;t++)-1==r.indexOf(i[t])&&e.classList.add(i[t]);0==e.classList.length&&e.removeAttribute("class")}if(t.style!=n.style){if(t.style){let n=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,r;for(;r=n.exec(t.style);)e.style.removeProperty(r[1])}n.style&&(e.style.cssText+=n.style)}}(i,o||ak[0],s)}return i}function aC(e,t,n){return aS(e,e,ak,aN(t,n,1!=e.nodeType))}function aj(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].type.eq(t[n].type))return!1;return!0}function aE(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}class aM{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=function(e,t){let n=t,r=n.children.length,i=e.childCount,s=new Map,o=[];n:for(;i>0;){let a;for(;;)if(r){let e=n.children[r-1];if(e instanceof af)n=e,r=e.children.length;else{a=e,r--;break}}else if(n==t)break n;else r=n.parent.children.indexOf(n),n=n.parent;let l=a.node;if(l){if(l!=e.child(i-1))break;--i,s.set(a,i),o.push(a)}}return{index:i,matched:s,matches:o.reverse()}}(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let n=e;n<t;n++)this.top.children[n].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,n,r){let i=0,s=this.stack.length>>1,o=Math.min(s,e.length);for(;i<o&&(i==s-1?this.top:this.stack[i+1<<1]).matchesMark(e[i])&&!1!==e[i].type.spec.spanning;)i++;for(;i<s;)this.destroyRest(),this.top.dirty=0,this.index=this.stack.pop(),this.top=this.stack.pop(),s--;for(;s<e.length;){this.stack.push(this.top,this.index+1);let i=-1,o=this.top.children.length;r<this.preMatch.index&&(o=Math.min(this.index+3,o));for(let t=this.index;t<o;t++){let n=this.top.children[t];if(n.matchesMark(e[s])&&!this.isLocked(n.dom)){i=t;break}}if(i>-1)i>this.index&&(this.changed=!0,this.destroyBetween(this.index,i)),this.top=this.top.children[this.index];else{let r=af.create(this.top,e[s],t,n);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,n,r){let i=-1,s;if(r>=this.preMatch.index&&(s=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&s.matchesNode(e,t,n))i=this.top.children.indexOf(s,this.index);else for(let r=this.index,s=Math.min(this.top.children.length,r+5);r<s;r++){let s=this.top.children[r];if(s.matchesNode(e,t,n)&&!this.preMatch.matched.has(s)){i=r;break}}return!(i<0)&&(this.destroyBetween(this.index,i),this.index++,!0)}updateNodeAt(e,t,n,r,i){let s=this.top.children[r];return 3==s.dirty&&s.dom==s.contentDOM&&(s.dirty=2),!!s.update(e,t,n,i)&&(this.destroyBetween(this.index,r),this.index++,!0)}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return -1;if(t==this.top.contentDOM){let t=e.pmViewDesc;if(t){for(let e=this.index;e<this.top.children.length;e++)if(this.top.children[e]==t)return e}return -1}e=t}}updateNextNode(e,t,n,r,i,s){for(let o=this.index;o<this.top.children.length;o++){let a=this.top.children[o];if(a instanceof ag){let l=this.preMatch.matched.get(a);if(null!=l&&l!=i)return!1;let c=a.dom,d,u=this.isLocked(c)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&3!=a.dirty&&aj(t,a.outerDeco));if(!u&&a.update(e,t,n,r))return this.destroyBetween(this.index,o),a.dom!=c&&(this.changed=!0),this.index++,!0;if(!u&&(d=this.recreateWrapper(a,e,t,n,r,s)))return this.destroyBetween(this.index,o),this.top.children[this.index]=d,d.contentDOM&&(d.dirty=2,d.updateChildren(r,s+1),d.dirty=0),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,r,i,s){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!aj(n,e.outerDeco)||!r.eq(e.innerDeco))return null;let o=ag.create(this.top,t,n,r,i,s);if(o.contentDOM)for(let t of(o.children=e.children,e.children=[],o.children))t.parent=o;return e.destroy(),o}addNode(e,t,n,r,i){let s=ag.create(this.top,e,t,n,r,i);s.contentDOM&&s.updateChildren(r,i+1),this.top.children.splice(this.index++,0,s),this.changed=!0}placeWidget(e,t,n){let r=this.index<this.top.children.length?this.top.children[this.index]:null;if(r&&r.matchesWidget(e)&&(e==r.widget||!r.widget.type.toDOM.parentNode))this.index++;else{let r=new ah(this.top,e,t,n);this.top.children.splice(this.index++,0,r),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof af;)e=(t=e).children[t.children.length-1];(!e||!(e instanceof ab)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((oY||oZ)&&e&&"false"==e.dom.contentEditable&&this.addHackNode("IMG",t),this.addHackNode("BR",this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.children[this.index].matchesHack(e))this.index++;else{let n=document.createElement(e);"IMG"==e&&(n.className="ProseMirror-separator",n.alt=""),"BR"==e&&(n.className="ProseMirror-trailingBreak");let r=new ay(this.top,[],n,null);t!=this.top?t.children.push(r):t.children.splice(this.index++,0,r),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||1==e.nodeType&&e.contains(this.lock.parentNode))}}function aA(e,t){return e.type.side-t.type.side}function aT(e,t,n,r,i){let s=[];for(let o=0,a=0;o<e.length;o++){let l=e[o],c=a,d=a+=l.size;c>=n||d<=t?s.push(l):(c<t&&s.push(l.slice(0,t-c,r)),i&&(s.push(i),i=void 0),d>n&&s.push(l.slice(n-c,l.size,r)))}return s}function aO(e,t=null){let n=e.domSelectionRange(),r=e.state.doc;if(!n.focusNode)return null;let i=e.docView.nearestDesc(n.focusNode),s=i&&0==i.size,o=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(o<0)return null;let a=r.resolve(o),l,c;if(o$(n)){for(l=o;i&&!i.node;)i=i.parent;let e=i.node;if(i&&e.isAtom&&op.isSelectable(e)&&i.parent&&!(e.isInline&&function(e,t,n){for(let r=0==t,i=t==oL(e);r||i;){if(e==n)return!0;let t=oM(e);if(!(e=e.parentNode))return!1;r=r&&0==t,i=i&&t==oL(e)}}(n.focusNode,n.focusOffset,i.dom))){let e=i.posBefore;c=new op(o==e?a:r.resolve(e))}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=o,i=o;for(let r=0;r<n.rangeCount;r++){let s=n.getRangeAt(r);t=Math.min(t,e.docView.posFromDOM(s.startContainer,s.startOffset,1)),i=Math.max(i,e.docView.posFromDOM(s.endContainer,s.endOffset,-1))}if(t<0)return null;[l,o]=i==e.state.selection.anchor?[i,t]:[t,i],a=r.resolve(o)}else l=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(l<0)return null}let d=r.resolve(l);if(!c){let n="pointer"==t||e.state.selection.head<a.pos&&!s?1:-1;c=aB(e,d,a,n)}return c}function a_(e){return e.editable?e.hasFocus():aH(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function aD(e,t=!1){let n=e.state.selection;if(a$(e,n),a_(e)){if(!t&&e.input.mouseDown&&e.input.mouseDown.allowDefault&&oZ){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&oD(t.anchorNode,t.anchorOffset,n.anchorNode,n.anchorOffset)){e.input.mouseDown.delayedSelectionSync=!0,e.domObserver.setCurSelection();return}}if(e.domObserver.disconnectSelection(),e.cursorWrapper)!function(e){let t=e.domSelection();if(!t)return;let n=e.cursorWrapper.dom,r="IMG"==n.nodeName;r?t.collapse(n.parentNode,oM(n)+1):t.collapse(n,0),!r&&!e.state.selection.visible&&oq&&oK<=11&&(n.disabled=!0,n.disabled=!1)}(e);else{var r;let i,s,o,a,{anchor:l,head:c}=n,d,u;aR&&!(n instanceof od)&&(n.$from.parent.inlineContent||(d=aI(e,n.from)),n.empty||n.$from.parent.inlineContent||(u=aI(e,n.to))),e.docView.setSelection(l,c,e,t),aR&&(d&&aP(d),u&&aP(u)),n.visible?e.dom.classList.remove("ProseMirror-hideselection"):(e.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&((i=(r=e).dom.ownerDocument).removeEventListener("selectionchange",r.input.hideSelectionGuard),o=(s=r.domSelectionRange()).anchorNode,a=s.anchorOffset,i.addEventListener("selectionchange",r.input.hideSelectionGuard=()=>{(s.anchorNode!=o||s.anchorOffset!=a)&&(i.removeEventListener("selectionchange",r.input.hideSelectionGuard),setTimeout(()=>{(!a_(r)||r.state.selection.visible)&&r.dom.classList.remove("ProseMirror-hideselection")},20))})))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}let aR=oY||oZ&&oX<63;function aI(e,t){let{node:n,offset:r}=e.docView.domFromPos(t,0),i=r<n.childNodes.length?n.childNodes[r]:null,s=r?n.childNodes[r-1]:null;if(oY&&i&&"false"==i.contentEditable)return aL(i);if((!i||"false"==i.contentEditable)&&(!s||"false"==s.contentEditable)){if(i)return aL(i);else if(s)return aL(s)}}function aL(e){return e.contentEditable="true",oY&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function aP(e){e.contentEditable="false",e.wasDraggable&&(e.draggable=!0,e.wasDraggable=null)}function a$(e,t){if(t instanceof op){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(az(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else az(e)}function az(e){e.lastSelectedViewDesc&&(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),e.lastSelectedViewDesc=void 0)}function aB(e,t,n,r){return e.someProp("createSelectionBetween",r=>r(e,t,n))||od.between(t,n,r)}function aF(e){return(!e.editable||!!e.hasFocus())&&aH(e)}function aH(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return e.dom.contains(3==t.anchorNode.nodeType?t.anchorNode.parentNode:t.anchorNode)&&(e.editable||e.dom.contains(3==t.focusNode.nodeType?t.focusNode.parentNode:t.focusNode))}catch(e){return!1}}function aU(e,t){let{$anchor:n,$head:r}=e.selection,i=t>0?n.max(r):n.min(r),s=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):null:i;return s&&oo.findFrom(s,t)}function aV(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function aW(e,t,n){let r=e.state.selection;if(r instanceof od){if(n.indexOf("s")>-1){let{$head:n}=r,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!i||i.isText||!i.isLeaf)return!1;let s=e.state.doc.resolve(n.pos+i.nodeSize*(t<0?-1:1));return aV(e,new od(r.$anchor,s))}else if(!r.empty)return!1;else if(e.endOfTextblock(t>0?"forward":"backward")){let n=aU(e.state,t);return!!n&&n instanceof op&&aV(e,n)}else if(!(o0&&n.indexOf("m")>-1)){let n=r.$head,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter,s;if(!i||i.isText)return!1;let o=t<0?n.pos-i.nodeSize:n.pos;return!!(i.isAtom||(s=e.docView.descAt(o))&&!s.contentDOM)&&(op.isSelectable(i)?aV(e,new op(t<0?e.state.doc.resolve(n.pos-i.nodeSize):n)):!!o5&&aV(e,new od(e.state.doc.resolve(t<0?o:o+i.nodeSize))))}}else{if(r instanceof op&&r.node.isInline)return aV(e,new od(t>0?r.$to:r.$from));let n=aU(e.state,t);return!!n&&aV(e,n)}}function aq(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function aK(e,t){let n=e.pmViewDesc;return n&&0==n.size&&(t<0||e.nextSibling||"BR"!=e.nodeName)}function aG(e,t){return t<0?function(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let i,s,o=!1;for(oG&&1==n.nodeType&&r<aq(n)&&aK(n.childNodes[r],-1)&&(o=!0);;)if(r>0)if(1!=n.nodeType)break;else{let e=n.childNodes[r-1];if(aK(e,-1))i=n,s=--r;else if(3==e.nodeType)r=(n=e).nodeValue.length;else break}else if(aJ(n))break;else{let t=n.previousSibling;for(;t&&aK(t,-1);)i=n.parentNode,s=oM(t),t=t.previousSibling;if(t)r=aq(n=t);else{if((n=n.parentNode)==e.dom)break;r=0}}o?aZ(e,n,r):i&&aZ(e,i,s)}(e):function(e){let t,n,r=e.domSelectionRange(),i=r.focusNode,s=r.focusOffset;if(!i)return;let o=aq(i);for(;;)if(s<o){if(1!=i.nodeType)break;if(aK(i.childNodes[s],1))t=i,n=++s;else break}else if(aJ(i))break;else{let r=i.nextSibling;for(;r&&aK(r,1);)t=r.parentNode,n=oM(r)+1,r=r.nextSibling;if(r)s=0,o=aq(i=r);else{if((i=i.parentNode)==e.dom)break;s=o=0}}t&&aZ(e,t,n)}(e)}function aJ(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function aZ(e,t,n){if(3!=t.nodeType){let e,r;(r=function(e,t){for(;e&&t==e.childNodes.length&&!oP(e);)t=oM(e)+1,e=e.parentNode;for(;e&&t<e.childNodes.length;){let n=e.childNodes[t];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;e=n,t=0}}(t,n))?(t=r,n=0):(e=function(e,t){for(;e&&!t&&!oP(e);)t=oM(e),e=e.parentNode;for(;e&&t;){let n=e.childNodes[t-1];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;t=(e=n).childNodes.length}}(t,n))&&(t=e,n=e.nodeValue.length)}let r=e.domSelection();if(!r)return;if(o$(r)){let e=document.createRange();e.setEnd(t,n),e.setStart(t,n),r.removeAllRanges(),r.addRange(e)}else r.extend&&r.extend(t,n);e.domObserver.setCurSelection();let{state:i}=e;setTimeout(()=>{e.state==i&&aD(e)},50)}function aX(e,t){let n=e.state.doc.resolve(t);if(!(oZ||o1)&&n.parent.inlineContent){let r=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),i=(n.top+n.bottom)/2;if(i>r.top&&i<r.bottom&&Math.abs(n.left-r.left)>1)return n.left<r.left?"ltr":"rtl"}if(t<n.end()){let n=e.coordsAtPos(t+1),i=(n.top+n.bottom)/2;if(i>r.top&&i<r.bottom&&Math.abs(n.left-r.left)>1)return n.left>r.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(e.dom).direction?"rtl":"ltr"}function aY(e,t,n){let r=e.state.selection;if(r instanceof od&&!r.empty||n.indexOf("s")>-1||o0&&n.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||e.endOfTextblock(t<0?"up":"down")){let n=aU(e.state,t);if(n&&n instanceof op)return aV(e,n)}if(!i.parent.inlineContent){let n=t<0?i:s,o=r instanceof om?oo.near(n,t):oo.findFrom(n,t);return!!o&&aV(e,o)}return!1}function aQ(e,t){if(!(e.state.selection instanceof od))return!0;let{$head:n,$anchor:r,empty:i}=e.state.selection;if(!n.sameParent(r))return!0;if(!i)return!1;if(e.endOfTextblock(t>0?"forward":"backward"))return!0;let s=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(s&&!s.isText){let r=e.state.tr;return t<0?r.delete(n.pos-s.nodeSize,n.pos):r.delete(n.pos,n.pos+s.nodeSize),e.dispatch(r),!0}return!1}function a0(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function a1(e,t){e.someProp("transformCopied",n=>{t=n(t,e)});let n=[],{content:r,openStart:i,openEnd:s}=t;for(;i>1&&s>1&&1==r.childCount&&1==r.firstChild.childCount;){i--,s--;let e=r.firstChild;n.push(e.type.name,e.attrs!=e.type.defaultAttrs?e.attrs:null),r=e.content}let o=e.someProp("clipboardSerializer")||sj.fromSchema(e.state.schema),a=a8(),l=a.createElement("div");l.appendChild(o.serializeFragment(r,{document:a}));let c=l.firstChild,d,u=0;for(;c&&1==c.nodeType&&(d=a9[c.nodeName.toLowerCase()]);){for(let e=d.length-1;e>=0;e--){let t=a.createElement(d[e]);for(;l.firstChild;)t.appendChild(l.firstChild);l.appendChild(t),u++}c=l.firstChild}return c&&1==c.nodeType&&c.setAttribute("data-pm-slice",`${i} ${s}${u?` -${u}`:""} ${JSON.stringify(n)}`),{dom:l,text:e.someProp("clipboardTextSerializer",n=>n(t,e))||t.content.textBetween(0,t.content.size,"\n\n"),slice:t}}function a2(e,t,n,r,i){let s,o,a=i.parent.type.spec.code;if(!n&&!t)return null;let l=!!t&&(r||a||!n);if(l){if(e.someProp("transformPastedText",n=>{t=n(t,a||r,e)}),a)return o=new iX(iW.from(e.state.schema.text(t.replace(/\r\n?/g,"\n"))),0,0),e.someProp("transformPasted",t=>{o=t(o,e,!0)}),o;let n=e.someProp("clipboardTextParser",n=>n(t,i,r,e));if(n)o=n;else{let n=i.marks(),{schema:r}=e.state,o=sj.fromSchema(r);s=document.createElement("div"),t.split(/(?:\r\n?|\n)+/).forEach(e=>{let t=s.appendChild(document.createElement("p"));e&&t.appendChild(o.serializeNode(r.text(e,n)))})}}else e.someProp("transformPastedHTML",t=>{n=t(n,e)}),s=function(e){var t;let n,r=/^(\s*<meta [^>]*>)*/.exec(e);r&&(e=e.slice(r[0].length));let i=a8().createElement("div"),s=/<([a-z][^>\s]+)/i.exec(e),o;if((o=s&&a9[s[1].toLowerCase()])&&(e=o.map(e=>"<"+e+">").join("")+e+o.map(e=>"</"+e+">").reverse().join("")),i.innerHTML=(t=e,(n=window.trustedTypes)?(le||(le=n.defaultPolicy||n.createPolicy("ProseMirrorClipboard",{createHTML:e=>e})),le.createHTML(t)):t),o)for(let e=0;e<o.length;e++)i=i.querySelector(o[e])||i;return i}(n),o5&&function(e){let t=e.querySelectorAll(oZ?"span:not([class]):not([style])":"span.Apple-converted-space");for(let n=0;n<t.length;n++){let r=t[n];1==r.childNodes.length&&" "==r.textContent&&r.parentNode&&r.parentNode.replaceChild(e.ownerDocument.createTextNode(" "),r)}}(s);let c=s&&s.querySelector("[data-pm-slice]"),d=c&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(c.getAttribute("data-pm-slice")||"");if(d&&d[3])for(let e=+d[3];e>0;e--){let e=s.firstChild;for(;e&&1!=e.nodeType;)e=e.nextSibling;if(!e)break;s=e}if(o||(o=(e.someProp("clipboardParser")||e.someProp("domParser")||sx.fromSchema(e.state.schema)).parseSlice(s,{preserveWhitespace:!!(l||d),context:i,ruleFromNode:e=>"BR"!=e.nodeName||e.nextSibling||!e.parentNode||a5.test(e.parentNode.nodeName)?null:{ignore:!0}})),d)o=function(e,t){if(!e.size)return e;let n=e.content.firstChild.type.schema,r;try{r=JSON.parse(t)}catch(t){return e}let{content:i,openStart:s,openEnd:o}=e;for(let e=r.length-2;e>=0;e-=2){let t=n.nodes[r[e]];if(!t||t.hasRequiredAttrs())break;i=iW.from(t.create(r[e+1],i)),s++,o++}return new iX(i,s,o)}(a6(o,+d[1],+d[2]),d[4]);else if((o=iX.maxOpen(function(e,t){if(e.childCount<2)return e;for(let n=t.depth;n>=0;n--){let r=t.node(n).contentMatchAt(t.index(n)),i,s=[];if(e.forEach(e=>{if(!s)return;let t=r.findWrapping(e.type),n;if(!t)return s=null;if(n=s.length&&i.length&&function e(t,n,r,i,s){if(s<t.length&&s<n.length&&t[s]==n[s]){let o=e(t,n,r,i.lastChild,s+1);if(o)return i.copy(i.content.replaceChild(i.childCount-1,o));if(i.contentMatchAt(i.childCount).matchType(s==t.length-1?r.type:t[s+1]))return i.copy(i.content.append(iW.from(a3(r,t,s+1))))}}(t,i,e,s[s.length-1],0))s[s.length-1]=n;else{s.length&&(s[s.length-1]=function e(t,n){if(0==n)return t;let r=t.content.replaceChild(t.childCount-1,e(t.lastChild,n-1)),i=t.contentMatchAt(t.childCount).fillBefore(iW.empty,!0);return t.copy(r.append(i))}(s[s.length-1],i.length));let n=a3(e,t);s.push(n),r=r.matchType(n.type),i=t}}),s)return iW.from(s)}return e}(o.content,i),!0)).openStart||o.openEnd){let e=0,t=0;for(let t=o.content.firstChild;e<o.openStart&&!t.type.spec.isolating;e++,t=t.firstChild);for(let e=o.content.lastChild;t<o.openEnd&&!e.type.spec.isolating;t++,e=e.lastChild);o=a6(o,e,t)}return e.someProp("transformPasted",t=>{o=t(o,e,l)}),o}let a5=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function a3(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,iW.from(e));return e}function a4(e,t,n,r,i,s){let o=t<0?e.firstChild:e.lastChild,a=o.content;return e.childCount>1&&(s=0),i<r-1&&(a=a4(a,t,n,r,i+1,s)),i>=n&&(a=t<0?o.contentMatchAt(0).fillBefore(a,s<=i).append(a):a.append(o.contentMatchAt(o.childCount).fillBefore(iW.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(a))}function a6(e,t,n){return t<e.openStart&&(e=new iX(a4(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new iX(a4(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}let a9={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]},a7=null;function a8(){return a7||(a7=document.implementation.createHTMLDocument("title"))}let le=null,lt={},ln={},lr={touchstart:!0,touchmove:!0};class li{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function ls(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function lo(e){e.someProp("handleDOMEvents",t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>la(e,t))})}function la(e,t){return e.someProp("handleDOMEvents",n=>{let r=n[t.type];return!!r&&(r(e,t)||t.defaultPrevented)})}function ll(e){return{left:e.clientX,top:e.clientY}}function lc(e,t,n,r,i){if(-1==r)return!1;let s=e.state.doc.resolve(r);for(let r=s.depth+1;r>0;r--)if(e.someProp(t,t=>r>s.depth?t(e,n,s.nodeAfter,s.before(r),i,!0):t(e,n,s.node(r),s.before(r),i,!1)))return!0;return!1}function ld(e,t,n){if(e.focused||e.focus(),e.state.selection.eq(t))return;let r=e.state.tr.setSelection(t);"pointer"==n&&r.setMeta("pointer",!0),e.dispatch(r)}ln.keydown=(e,t)=>{if((e.input.shiftKey=16==t.keyCode||t.shiftKey,!lh(e,t))&&(e.input.lastKeyCode=t.keyCode,e.input.lastKeyCodeTime=Date.now(),!o2||!oZ||13!=t.keyCode))if(229!=t.keyCode&&e.domObserver.forceFlush(),!oQ||13!=t.keyCode||t.ctrlKey||t.altKey||t.metaKey)e.someProp("handleKeyDown",n=>n(e,t))||function(e,t){let n,r=t.keyCode,i=(n="",t.ctrlKey&&(n+="c"),t.metaKey&&(n+="m"),t.altKey&&(n+="a"),t.shiftKey&&(n+="s"),n);if(8==r||o0&&72==r&&"c"==i)return aQ(e,-1)||aG(e,-1);if(46==r&&!t.shiftKey||o0&&68==r&&"c"==i)return aQ(e,1)||aG(e,1);if(13==r||27==r)return!0;if(37==r||o0&&66==r&&"c"==i){let t=37==r?"ltr"==aX(e,e.state.selection.from)?-1:1:-1;return aW(e,t,i)||aG(e,t)}if(39==r||o0&&70==r&&"c"==i){let t=39==r?"ltr"==aX(e,e.state.selection.from)?1:-1:1;return aW(e,t,i)||aG(e,t)}else if(38==r||o0&&80==r&&"c"==i)return aY(e,-1,i)||aG(e,-1);else if(40==r||o0&&78==r&&"c"==i)return function(e){if(!oY||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(t&&1==t.nodeType&&0==n&&t.firstChild&&"false"==t.firstChild.contentEditable){let n=t.firstChild;a0(e,n,"true"),setTimeout(()=>a0(e,n,"false"),20)}return!1}(e)||aY(e,1,i)||aG(e,1);else if(i==(o0?"m":"c")&&(66==r||73==r||89==r||90==r))return!0;return!1}(e,t)?t.preventDefault():ls(e,"key");else{let t=Date.now();e.input.lastIOSEnter=t,e.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{e.input.lastIOSEnter==t&&(e.someProp("handleKeyDown",t=>t(e,oz(13,"Enter"))),e.input.lastIOSEnter=0)},200)}},ln.keyup=(e,t)=>{16==t.keyCode&&(e.input.shiftKey=!1)},ln.keypress=(e,t)=>{if(lh(e,t)||!t.charCode||t.ctrlKey&&!t.altKey||o0&&t.metaKey)return;if(e.someProp("handleKeyPress",n=>n(e,t)))return void t.preventDefault();let n=e.state.selection;if(!(n instanceof od)||!n.$from.sameParent(n.$to)){let r=String.fromCharCode(t.charCode),i=()=>e.state.tr.insertText(r).scrollIntoView();/[\r\n]/.test(r)||e.someProp("handleTextInput",t=>t(e,n.$from.pos,n.$to.pos,r,i))||e.dispatch(i()),t.preventDefault()}};let lu=o0?"metaKey":"ctrlKey";lt.mousedown=(e,t)=>{var n;let r,i;e.input.shiftKey=t.shiftKey;let s=lx(e),o=Date.now(),a="singleClick";o-e.input.lastClick.time<500&&(r=(n=e.input.lastClick).x-t.clientX)*r+(i=n.y-t.clientY)*i<100&&!t[lu]&&e.input.lastClick.button==t.button&&("singleClick"==e.input.lastClick.type?a="doubleClick":"doubleClick"==e.input.lastClick.type&&(a="tripleClick")),e.input.lastClick={time:o,x:t.clientX,y:t.clientY,type:a,button:t.button};let l=e.posAtCoords(ll(t));l&&("singleClick"==a?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new lp(e,l,t,!!s)):("doubleClick"==a?function(e,t,n,r){return lc(e,"handleDoubleClickOn",t,n,r)||e.someProp("handleDoubleClick",n=>n(e,t,r))}:function(e,t,n,r){return lc(e,"handleTripleClickOn",t,n,r)||e.someProp("handleTripleClick",n=>n(e,t,r))||function(e,t,n){if(0!=n.button)return!1;let r=e.state.doc;if(-1==t)return!!r.inlineContent&&(ld(e,od.create(r,0,r.content.size),"pointer"),!0);let i=r.resolve(t);for(let t=i.depth+1;t>0;t--){let n=t>i.depth?i.nodeAfter:i.node(t),s=i.before(t);if(n.inlineContent)ld(e,od.create(r,s+1,s+1+n.content.size),"pointer");else{if(!op.isSelectable(n))continue;ld(e,op.create(r,s),"pointer")}return!0}}(e,n,r)})(e,l.pos,l.inside,t)?t.preventDefault():ls(e,"pointer"))};class lp{constructor(e,t,n,r){let i,s;if(this.view=e,this.pos=t,this.event=n,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!n[lu],this.allowDefault=n.shiftKey,t.inside>-1)i=e.state.doc.nodeAt(t.inside),s=t.inside;else{let n=e.state.doc.resolve(t.pos);i=n.parent,s=n.depth?n.before():0}const o=r?null:n.target,a=o?e.docView.nearestDesc(o,!0):null;this.target=a&&1==a.nodeDOM.nodeType?a.nodeDOM:null;let{selection:l}=e.state;0==n.button&&(i.type.spec.draggable&&!1!==i.type.spec.selectable||l instanceof op&&l.from<=s&&l.to>s)&&(this.mightDrag={node:i,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&oG&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),ls(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>aD(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;if(this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(ll(e))),this.updateAllowDefault(e),this.allowDefault||!t)ls(this.view,"pointer");else{var n,r,i,s;(n=this.view,r=t.pos,i=t.inside,s=this.selectNode,lc(n,"handleClickOn",r,i,e)||n.someProp("handleClick",t=>t(n,r,e))||(s?function(e,t){if(-1==t)return!1;let n=e.state.selection,r,i;n instanceof op&&(r=n.node);let s=e.state.doc.resolve(t);for(let e=s.depth+1;e>0;e--){let t=e>s.depth?s.nodeAfter:s.node(e);if(op.isSelectable(t)){i=r&&n.$from.depth>0&&e>=n.$from.depth&&s.before(n.$from.depth+1)==n.$from.pos?s.before(n.$from.depth):s.before(e);break}}return null!=i&&(ld(e,op.create(e.state.doc,i),"pointer"),!0)}(n,i):function(e,t){if(-1==t)return!1;let n=e.state.doc.resolve(t),r=n.nodeAfter;return!!(r&&r.isAtom&&op.isSelectable(r))&&(ld(e,new op(n),"pointer"),!0)}(n,i)))?e.preventDefault():0==e.button&&(this.flushed||oY&&this.mightDrag&&!this.mightDrag.node.isAtom||oZ&&!this.view.state.selection.visible&&2>=Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to)))?(ld(this.view,oo.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):ls(this.view,"pointer")}}move(e){this.updateAllowDefault(e),ls(this.view,"pointer"),0==e.buttons&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}function lh(e,t){return!!e.composing||!!(oY&&500>Math.abs(t.timeStamp-e.input.compositionEndedAt))&&(e.input.compositionEndedAt=-2e8,!0)}lt.touchstart=e=>{e.input.lastTouch=Date.now(),lx(e),ls(e,"pointer")},lt.touchmove=e=>{e.input.lastTouch=Date.now(),ls(e,"pointer")},lt.contextmenu=e=>lx(e);let lm=o2?5e3:-1;function lf(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>lx(e),t))}function lg(e){let t;for(e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=((t=document.createEvent("Event")).initEvent("event",!0,!0),t.timeStamp));e.input.compositionNodes.length>0;)e.input.compositionNodes.pop().markParentsDirty()}function lx(e,t=!1){if(!o2||!(e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),lg(e),t||e.docView&&e.docView.dirty){let n=aO(e),r=e.state.selection;return n&&!n.eq(r)?e.dispatch(e.state.tr.setSelection(n)):(e.markCursor||t)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?e.dispatch(e.state.tr.deleteSelection()):e.updateState(e.state),!0}return!1}}ln.compositionstart=ln.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof od&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>!1===e.type.spec.inclusive)||oZ&&o1&&function(e){let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(!t||1!=t.nodeType||n>=t.childNodes.length)return!1;let r=t.childNodes[n];return 1==r.nodeType&&"false"==r.contentEditable}(e)))e.markCursor=e.state.storedMarks||n.marks(),lx(e,!0),e.markCursor=null;else if(lx(e,!t.selection.empty),oG&&t.selection.empty&&n.parentOffset&&!n.textOffset&&n.nodeBefore.marks.length){let t=e.domSelectionRange();for(let n=t.focusNode,r=t.focusOffset;n&&1==n.nodeType&&0!=r;){let t=r<0?n.lastChild:n.childNodes[r-1];if(!t)break;if(3==t.nodeType){let n=e.domSelection();n&&n.collapse(t,t.nodeValue.length);break}n=t,r=-1}}e.input.composing=!0}lf(e,lm)},ln.compositionend=(e,t)=>{e.composing&&(e.input.composing=!1,e.input.compositionEndedAt=t.timeStamp,e.input.compositionPendingChanges=e.domObserver.pendingRecords().length?e.input.compositionID:0,e.input.compositionNode=null,e.input.badSafariComposition?e.domObserver.forceFlush():e.input.compositionPendingChanges&&Promise.resolve().then(()=>e.domObserver.flush()),e.input.compositionID++,lf(e,20))};let lb=oq&&oK<15||oQ&&o3<604;function ly(e,t,n,r,i){let s=a2(e,t,n,r,e.state.selection.$from);if(e.someProp("handlePaste",t=>t(e,i,s||iX.empty)))return!0;if(!s)return!1;let o=0==s.openStart&&0==s.openEnd&&1==s.content.childCount?s.content.firstChild:null,a=o?e.state.tr.replaceSelectionWith(o,r):e.state.tr.replaceSelection(s);return e.dispatch(a.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function lv(e){let t=e.getData("text/plain")||e.getData("Text");if(t)return t;let n=e.getData("text/uri-list");return n?n.replace(/\r?\n/g," "):""}lt.copy=ln.cut=(e,t)=>{let n=e.state.selection,r="cut"==t.type;if(n.empty)return;let i=lb?null:t.clipboardData,{dom:s,text:o}=a1(e,n.content());i?(t.preventDefault(),i.clearData(),i.setData("text/html",s.innerHTML),i.setData("text/plain",o)):function(e,t){if(!e.dom.parentNode)return;let n=e.dom.parentNode.appendChild(document.createElement("div"));n.appendChild(t),n.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(t),e.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{n.parentNode&&n.parentNode.removeChild(n),e.focus()},50)}(e,s),r&&e.dispatch(e.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))},ln.paste=(e,t)=>{if(e.composing&&!o2)return;let n=lb?null:t.clipboardData,r=e.input.shiftKey&&45!=e.input.lastKeyCode;n&&ly(e,lv(n),n.getData("text/html"),r,t)?t.preventDefault():function(e,t){if(!e.dom.parentNode)return;let n=e.input.shiftKey||e.state.selection.$from.parent.type.spec.code,r=e.dom.parentNode.appendChild(document.createElement(n?"textarea":"div"));n||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=e.input.shiftKey&&45!=e.input.lastKeyCode;setTimeout(()=>{e.focus(),r.parentNode&&r.parentNode.removeChild(r),n?ly(e,r.value,null,i,t):ly(e,r.textContent,r.innerHTML,i,t)},50)}(e,t)};class lw{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}let lk=o0?"altKey":"ctrlKey";function lN(e,t){let n;return e.someProp("dragCopies",e=>{n=n||e(t)}),null!=n?!n:!t[lk]}for(let e in lt.dragstart=(e,t)=>{let n,r=e.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=e.state.selection,s=i.empty?null:e.posAtCoords(ll(t));if(s&&s.pos>=i.from&&s.pos<=(i instanceof op?i.to-1:i.to));else if(r&&r.mightDrag)n=op.create(e.state.doc,r.mightDrag.pos);else if(t.target&&1==t.target.nodeType){let r=e.docView.nearestDesc(t.target,!0);r&&r.node.type.spec.draggable&&r!=e.docView&&(n=op.create(e.state.doc,r.posBefore))}let o=(n||e.state.selection).content(),{dom:a,text:l,slice:c}=a1(e,o);t.dataTransfer.files.length&&oZ&&!(oX>120)||t.dataTransfer.clearData(),t.dataTransfer.setData(lb?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",lb||t.dataTransfer.setData("text/plain",l),e.dragging=new lw(c,lN(e,t),n)},lt.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},ln.dragover=ln.dragenter=(e,t)=>t.preventDefault(),ln.drop=(e,t)=>{try{!function(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(ll(t));if(!r)return;let i=e.state.doc.resolve(r.pos),s=n&&n.slice;s?e.someProp("transformPasted",t=>{s=t(s,e,!1)}):s=a2(e,lv(t.dataTransfer),lb?null:t.dataTransfer.getData("text/html"),!1,i);let o=!!(n&&lN(e,t));if(e.someProp("handleDrop",n=>n(e,t,s||iX.empty,o)))return t.preventDefault();if(!s)return;t.preventDefault();let a=s?s1(e.state.doc,i.pos,s):i.pos;null==a&&(a=i.pos);let l=e.state.tr;if(o){let{node:e}=n;e?e.replace(l):l.deleteSelection()}let c=l.mapping.map(a),d=0==s.openStart&&0==s.openEnd&&1==s.content.childCount,u=l.doc;if(d?l.replaceRangeWith(c,c,s.content.firstChild):l.replaceRange(c,c,s),l.doc.eq(u))return;let p=l.doc.resolve(c);if(d&&op.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))l.setSelection(new op(p));else{let t=l.mapping.map(a);l.mapping.maps[l.mapping.maps.length-1].forEach((e,n,r,i)=>t=i),l.setSelection(aB(e,p,l.doc.resolve(t)))}e.focus(),e.dispatch(l.setMeta("uiEvent","drop"))}(e,t,e.dragging)}finally{e.dragging=null}},lt.focus=e=>{e.input.lastFocus=Date.now(),e.focused||(e.domObserver.stop(),e.dom.classList.add("ProseMirror-focused"),e.domObserver.start(),e.focused=!0,setTimeout(()=>{e.docView&&e.hasFocus()&&!e.domObserver.currentSelection.eq(e.domSelectionRange())&&aD(e)},20))},lt.blur=(e,t)=>{e.focused&&(e.domObserver.stop(),e.dom.classList.remove("ProseMirror-focused"),e.domObserver.start(),t.relatedTarget&&e.dom.contains(t.relatedTarget)&&e.domObserver.currentSelection.clear(),e.focused=!1)},lt.beforeinput=(e,t)=>{if(oZ&&o2&&"deleteContentBackward"==t.inputType){e.domObserver.flushSoon();let{domChangeCount:t}=e.input;setTimeout(()=>{if(e.input.domChangeCount!=t||(e.dom.blur(),e.focus(),e.someProp("handleKeyDown",t=>t(e,oz(8,"Backspace")))))return;let{$cursor:n}=e.state.selection;n&&n.pos>0&&e.dispatch(e.state.tr.delete(n.pos-1,n.pos).scrollIntoView())},50)}},ln)lt[e]=ln[e];function lS(e,t){if(e==t)return!0;for(let n in e)if(e[n]!==t[n])return!1;for(let n in t)if(!(n in e))return!1;return!0}class lC{constructor(e,t){this.toDOM=e,this.spec=t||lT,this.side=this.spec.side||0}map(e,t,n,r){let{pos:i,deleted:s}=e.mapResult(t.from+r,this.side<0?-1:1);return s?null:new lM(i-n,i-n,this)}valid(){return!0}eq(e){return this==e||e instanceof lC&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&lS(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class lj{constructor(e,t){this.attrs=e,this.spec=t||lT}map(e,t,n,r){let i=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-n,s=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-n;return i>=s?null:new lM(i,s,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof lj&&lS(this.attrs,e.attrs)&&lS(this.spec,e.spec)}static is(e){return e.type instanceof lj}destroy(){}}class lE{constructor(e,t){this.attrs=e,this.spec=t||lT}map(e,t,n,r){let i=e.mapResult(t.from+r,1);if(i.deleted)return null;let s=e.mapResult(t.to+r,-1);return s.deleted||s.pos<=i.pos?null:new lM(i.pos-n,s.pos-n,this)}valid(e,t){let{index:n,offset:r}=e.content.findIndex(t.from),i;return r==t.from&&!(i=e.child(n)).isText&&r+i.nodeSize==t.to}eq(e){return this==e||e instanceof lE&&lS(this.attrs,e.attrs)&&lS(this.spec,e.spec)}destroy(){}}class lM{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new lM(e,t,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,n){return this.type.map(e,this,t,n)}static widget(e,t,n){return new lM(e,e,new lC(t,n))}static inline(e,t,n,r){return new lM(e,t,new lj(n,r))}static node(e,t,n,r){return new lM(e,t,new lE(n,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof lj}get widget(){return this.type instanceof lC}}let lA=[],lT={};class lO{constructor(e,t){this.local=e.length?e:lA,this.children=t.length?t:lA}static create(e,t){return t.length?lP(t,e,0,lT):l_}find(e,t,n){let r=[];return this.findInner(null==e?0:e,null==t?1e9:t,r,0,n),r}findInner(e,t,n,r,i){for(let s=0;s<this.local.length;s++){let o=this.local[s];o.from<=t&&o.to>=e&&(!i||i(o.spec))&&n.push(o.copy(o.from+r,o.to+r))}for(let s=0;s<this.children.length;s+=3)if(this.children[s]<t&&this.children[s+1]>e){let o=this.children[s]+1;this.children[s+2].findInner(e-o,t-o,n,r+o,i)}}map(e,t,n){return this==l_||0==e.maps.length?this:this.mapInner(e,t,0,0,n||lT)}mapInner(e,t,n,r,i){let s;for(let o=0;o<this.local.length;o++){let a=this.local[o].map(e,n,r);a&&a.type.valid(t,a)?(s||(s=[])).push(a):i.onRemove&&i.onRemove(this.local[o].spec)}return this.children.length?function(e,t,n,r,i,s,o){let a=e.slice();for(let e=0,t=s;e<n.maps.length;e++){let r=0;n.maps[e].forEach((e,n,i,s)=>{let o=s-i-(n-e);for(let i=0;i<a.length;i+=3){let s=a[i+1];if(s<0||e>s+t-r)continue;let l=a[i]+t-r;n>=l?a[i+1]=e<=l?-2:-1:e>=t&&o&&(a[i]+=o,a[i+1]+=o)}r+=o}),t=n.maps[e].map(t,-1)}let l=!1;for(let t=0;t<a.length;t+=3)if(a[t+1]<0){if(-2==a[t+1]){l=!0,a[t+1]=-1;continue}let c=n.map(e[t]+s),d=c-i;if(d<0||d>=r.content.size){l=!0;continue}let u=n.map(e[t+1]+s,-1)-i,{index:p,offset:h}=r.content.findIndex(d),m=r.maybeChild(p);if(m&&h==d&&h+m.nodeSize==u){let r=a[t+2].mapInner(n,m,c+1,e[t]+s+1,o);r!=l_?(a[t]=d,a[t+1]=u,a[t+2]=r):(a[t+1]=-2,l=!0)}else l=!0}if(l){let l=lP(function(e,t,n,r,i,s,o){for(let a=0;a<e.length;a+=3)-1==e[a+1]&&function e(t,s){for(let e=0;e<t.local.length;e++){let a=t.local[e].map(r,i,s);a?n.push(a):o.onRemove&&o.onRemove(t.local[e].spec)}for(let n=0;n<t.children.length;n+=3)e(t.children[n+2],t.children[n]+s+1)}(e[a+2],t[a]+s+1);return n}(a,e,t,n,i,s,o),r,0,o);t=l.local;for(let e=0;e<a.length;e+=3)a[e+1]<0&&(a.splice(e,3),e-=3);for(let e=0,t=0;e<l.children.length;e+=3){let n=l.children[e];for(;t<a.length&&a[t]<n;)t+=3;a.splice(t,0,l.children[e],l.children[e+1],l.children[e+2])}}return new lO(t.sort(l$),a)}(this.children,s||[],e,t,n,r,i):s?new lO(s.sort(l$),lA):l_}add(e,t){return t.length?this==l_?lO.create(e,t):this.addInner(e,t,0):this}addInner(e,t,n){let r,i=0;e.forEach((e,s)=>{let o=s+n,a;if(a=lI(t,e,o)){for(r||(r=this.children.slice());i<r.length&&r[i]<s;)i+=3;r[i]==s?r[i+2]=r[i+2].addInner(e,a,o+1):r.splice(i,0,s,s+e.nodeSize,lP(a,e,o+1,lT)),i+=3}});let s=lR(i?lL(t):t,-n);for(let t=0;t<s.length;t++)s[t].type.valid(e,s[t])||s.splice(t--,1);return new lO(s.length?this.local.concat(s).sort(l$):this.local,r||this.children)}remove(e){return 0==e.length||this==l_?this:this.removeInner(e,0)}removeInner(e,t){let n=this.children,r=this.local;for(let r=0;r<n.length;r+=3){let i,s=n[r]+t,o=n[r+1]+t;for(let t=0,n;t<e.length;t++)(n=e[t])&&n.from>s&&n.to<o&&(e[t]=null,(i||(i=[])).push(n));if(!i)continue;n==this.children&&(n=this.children.slice());let a=n[r+2].removeInner(i,s+1);a!=l_?n[r+2]=a:(n.splice(r,3),r-=3)}if(r.length){for(let n=0,i;n<e.length;n++)if(i=e[n])for(let e=0;e<r.length;e++)r[e].eq(i,t)&&(r==this.local&&(r=this.local.slice()),r.splice(e--,1))}return n==this.children&&r==this.local?this:r.length||n.length?new lO(r,n):l_}forChild(e,t){let n,r;if(this==l_)return this;if(t.isLeaf)return lO.empty;for(let t=0;t<this.children.length;t+=3)if(this.children[t]>=e){this.children[t]==e&&(n=this.children[t+2]);break}let i=e+1,s=i+t.content.size;for(let e=0;e<this.local.length;e++){let t=this.local[e];if(t.from<s&&t.to>i&&t.type instanceof lj){let e=Math.max(i,t.from)-i,n=Math.min(s,t.to)-i;e<n&&(r||(r=[])).push(t.copy(e,n))}}if(r){let e=new lO(r.sort(l$),lA);return n?new lD([e,n]):e}return n||l_}eq(e){if(this==e)return!0;if(!(e instanceof lO)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let t=0;t<this.local.length;t++)if(!this.local[t].eq(e.local[t]))return!1;for(let t=0;t<this.children.length;t+=3)if(this.children[t]!=e.children[t]||this.children[t+1]!=e.children[t+1]||!this.children[t+2].eq(e.children[t+2]))return!1;return!0}locals(e){return lz(this.localsInner(e))}localsInner(e){if(this==l_)return lA;if(e.inlineContent||!this.local.some(lj.is))return this.local;let t=[];for(let e=0;e<this.local.length;e++)this.local[e].type instanceof lj||t.push(this.local[e]);return t}forEachSet(e){e(this)}}lO.empty=new lO([],[]),lO.removeOverlap=lz;let l_=lO.empty;class lD{constructor(e){this.members=e}map(e,t){let n=this.members.map(n=>n.map(e,t,lT));return lD.from(n)}forChild(e,t){if(t.isLeaf)return lO.empty;let n=[];for(let r=0;r<this.members.length;r++){let i=this.members[r].forChild(e,t);i!=l_&&(i instanceof lD?n=n.concat(i.members):n.push(i))}return lD.from(n)}eq(e){if(!(e instanceof lD)||e.members.length!=this.members.length)return!1;for(let t=0;t<this.members.length;t++)if(!this.members[t].eq(e.members[t]))return!1;return!0}locals(e){let t,n=!0;for(let r=0;r<this.members.length;r++){let i=this.members[r].localsInner(e);if(i.length)if(t){n&&(t=t.slice(),n=!1);for(let e=0;e<i.length;e++)t.push(i[e])}else t=i}return t?lz(n?t:t.sort(l$)):lA}static from(e){switch(e.length){case 0:return l_;case 1:return e[0];default:return new lD(e.every(e=>e instanceof lO)?e:e.reduce((e,t)=>e.concat(t instanceof lO?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function lR(e,t){if(!t||!e.length)return e;let n=[];for(let r=0;r<e.length;r++){let i=e[r];n.push(new lM(i.from+t,i.to+t,i.type))}return n}function lI(e,t,n){if(t.isLeaf)return null;let r=n+t.nodeSize,i=null;for(let t=0,s;t<e.length;t++)(s=e[t])&&s.from>n&&s.to<r&&((i||(i=[])).push(s),e[t]=null);return i}function lL(e){let t=[];for(let n=0;n<e.length;n++)null!=e[n]&&t.push(e[n]);return t}function lP(e,t,n,r){let i=[],s=!1;t.forEach((t,o)=>{let a=lI(e,t,o+n);if(a){s=!0;let e=lP(a,t,n+o+1,r);e!=l_&&i.push(o,o+t.nodeSize,e)}});let o=lR(s?lL(e):e,-n).sort(l$);for(let e=0;e<o.length;e++)o[e].type.valid(t,o[e])||(r.onRemove&&r.onRemove(o[e].spec),o.splice(e--,1));return o.length||i.length?new lO(o,i):l_}function l$(e,t){return e.from-t.from||e.to-t.to}function lz(e){let t=e;for(let n=0;n<t.length-1;n++){let r=t[n];if(r.from!=r.to)for(let i=n+1;i<t.length;i++){let s=t[i];if(s.from==r.from){s.to!=r.to&&(t==e&&(t=e.slice()),t[i]=s.copy(s.from,r.to),lB(t,i+1,s.copy(r.to,s.to)));continue}s.from<r.to&&(t==e&&(t=e.slice()),t[n]=r.copy(r.from,s.from),lB(t,i,r.copy(s.from,r.to)));break}}return t}function lB(e,t,n){for(;t<e.length&&l$(n,e[t])>0;)t++;e.splice(t,0,n)}function lF(e){let t=[];return e.someProp("decorations",n=>{let r=n(e.state);r&&r!=l_&&t.push(r)}),e.cursorWrapper&&t.push(lO.create(e.state.doc,[e.cursorWrapper.deco])),lD.from(t)}let lH={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},lU=oq&&oK<=11;class lV{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class lW{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new lV,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(t=>{for(let e=0;e<t.length;e++)this.queue.push(t[e]);oq&&oK<=11&&t.some(e=>"childList"==e.type&&e.removedNodes.length||"characterData"==e.type&&e.oldValue.length>e.target.nodeValue.length)?this.flushSoon():oY&&e.composing&&t.some(e=>"childList"==e.type&&"TR"==e.target.nodeName)?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),lU&&(this.onCharData=e=>{this.queue.push({target:e.target,type:"characterData",oldValue:e.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,lH)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(aF(this.view)){if(this.suppressingSelectionUpdates)return aD(this.view);if(oq&&oK<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&oD(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,n;for(let n=e.focusNode;n;n=oA(n))t.add(n);for(let r=e.anchorNode;r;r=oA(r))if(t.has(r)){n=r;break}let r=n&&this.view.docView.nearestDesc(n);if(r&&r.ignoreMutation({type:"selection",target:3==n.nodeType?n.parentNode:n}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){var e;let{view:t}=this;if(!t.docView||this.flushingSoon>-1)return;let n=this.pendingRecords();n.length&&(this.queue=[]);let r=t.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&aF(t)&&!this.ignoreSelectionChange(r),s=-1,o=-1,a=!1,l=[];if(t.editable)for(let e=0;e<n.length;e++){let t=this.registerMutation(n[e],l);t&&(s=s<0?t.from:Math.min(t.from,s),o=o<0?t.to:Math.max(t.to,o),t.typeOver&&(a=!0))}if(l.some(e=>"BR"==e.nodeName)&&(8==t.input.lastKeyCode||46==t.input.lastKeyCode)){for(let e of l)if("BR"==e.nodeName&&e.parentNode){let t=e.nextSibling;for(;t&&1==t.nodeType;){if("false"==t.contentEditable){e.parentNode.removeChild(e);break}t=t.firstChild}}}else if(oG&&l.length){let e=l.filter(e=>"BR"==e.nodeName);if(2==e.length){let[t,n]=e;t.parentNode&&t.parentNode.parentNode==n.parentNode?n.remove():t.remove()}else{let{focusNode:n}=this.currentSelection;for(let r of e){let e=r.parentNode;e&&"LI"==e.nodeName&&(!n||function(e,t){for(let n=t.parentNode;n&&n!=e.dom;n=n.parentNode){let t=e.docView.nearestDesc(n,!0);if(t&&t.node.isBlock)return n}return null}(t,n)!=e)&&r.remove()}}}let c=null;s<0&&i&&t.input.lastFocus>Date.now()-200&&Math.max(t.input.lastTouch,t.input.lastClick.time)<Date.now()-300&&o$(r)&&(c=aO(t))&&c.eq(oo.near(t.state.doc.resolve(0),1))?(t.input.lastFocus=0,aD(t),this.currentSelection.set(r),t.scrollToSelection()):(s>-1||i)&&(s>-1&&(t.docView.markDirty(s,o),e=t,!lq.has(e)&&(lq.set(e,null),-1!==["normal","nowrap","pre-line"].indexOf(getComputedStyle(e.dom).whiteSpace))&&(e.requiresGeckoHackNode=oG,lK||(console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),lK=!0))),t.input.badSafariComposition&&(t.input.badSafariComposition=!1,function(e,t){var n;let{focusNode:r,focusOffset:i}=e.domSelectionRange();for(let s of t)if((null==(n=s.parentNode)?void 0:n.nodeName)=="TR"){let t=s.nextSibling;for(;t&&"TD"!=t.nodeName&&"TH"!=t.nodeName;)t=t.nextSibling;if(t){let n=t;for(;;){let e=n.firstChild;if(!e||1!=e.nodeType||"false"==e.contentEditable||/^(BR|IMG)$/.test(e.nodeName))break;n=e}n.insertBefore(s,n.firstChild),r==s&&e.domSelection().collapse(s,i)}else s.parentNode.removeChild(s)}}(t,l)),this.handleDOMChange(s,o,a,l),t.docView&&t.docView.dirty?t.updateState(t.state):this.currentSelection.eq(r)||aD(t),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let n=this.view.docView.nearestDesc(e.target);if("attributes"==e.type&&(n==this.view.docView||"contenteditable"==e.attributeName||"style"==e.attributeName&&!e.oldValue&&!e.target.getAttribute("style"))||!n||n.ignoreMutation(e))return null;if("childList"==e.type){for(let n=0;n<e.addedNodes.length;n++){let r=e.addedNodes[n];t.push(r),3==r.nodeType&&(this.lastChangedTextNode=r)}if(n.contentDOM&&n.contentDOM!=n.dom&&!n.contentDOM.contains(e.target))return{from:n.posBefore,to:n.posAfter};let r=e.previousSibling,i=e.nextSibling;if(oq&&oK<=11&&e.addedNodes.length)for(let t=0;t<e.addedNodes.length;t++){let{previousSibling:n,nextSibling:s}=e.addedNodes[t];(!n||0>Array.prototype.indexOf.call(e.addedNodes,n))&&(r=n),(!s||0>Array.prototype.indexOf.call(e.addedNodes,s))&&(i=s)}let s=r&&r.parentNode==e.target?oM(r)+1:0,o=n.localPosFromDOM(e.target,s,-1),a=i&&i.parentNode==e.target?oM(i):e.target.childNodes.length;return{from:o,to:n.localPosFromDOM(e.target,a,1)}}return"attributes"==e.type?{from:n.posAtStart-n.border,to:n.posAtEnd+n.border}:(this.lastChangedTextNode=e.target,{from:n.posAtStart,to:n.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let lq=new WeakMap,lK=!1;function lG(e,t){let n=t.startContainer,r=t.startOffset,i=t.endContainer,s=t.endOffset,o=e.domAtPos(e.state.selection.anchor);return oD(o.node,o.offset,i,s)&&([n,r,i,s]=[i,s,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:s}}function lJ(e){let t=e.pmViewDesc;if(t)return t.parseRule();if("BR"==e.nodeName&&e.parentNode){if(oY&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let e=document.createElement("div");return e.appendChild(document.createElement("li")),{skip:e}}else if(e.parentNode.lastChild==e||oY&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if("IMG"==e.nodeName&&e.getAttribute("mark-placeholder"))return{ignore:!0};return null}let lZ=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function lX(e,t,n){return Math.max(n.anchor,n.head)>t.content.size?null:aB(e,t.resolve(n.anchor),t.resolve(n.head))}function lY(e,t,n){let r=e.depth,i=t?e.end():e.pos;for(;r>0&&(t||e.indexAfter(r)==e.node(r).childCount);)r--,i++,t=!1;if(n){let t=e.node(r).maybeChild(e.indexAfter(r));for(;t&&!t.isLeaf;)t=t.firstChild,i++}return i}function lQ(e){if(2!=e.length)return!1;let t=e.charCodeAt(0),n=e.charCodeAt(1);return t>=56320&&t<=57343&&n>=55296&&n<=56319}class l0{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new li,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(l4),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):"function"==typeof e?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=l5(this),l2(this),this.nodeViews=l3(this),this.docView=ax(this.state.doc,l1(this),lF(this),this.dom,this),this.domObserver=new lW(this,(e,t,n,r)=>(function(e,t,n,r,i){let s,o,a,l=e.input.compositionPendingChanges||(e.composing?e.input.compositionID:0);if(e.input.compositionPendingChanges=0,t<0){let t=e.input.lastSelectionTime>Date.now()-50?e.input.lastSelectionOrigin:null,n=aO(e,t);if(n&&!e.state.selection.eq(n)){if(oZ&&o2&&13===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime&&e.someProp("handleKeyDown",t=>t(e,oz(13,"Enter"))))return;let r=e.state.tr.setSelection(n);"pointer"==t?r.setMeta("pointer",!0):"key"==t&&r.scrollIntoView(),l&&r.setMeta("composition",l),e.dispatch(r)}return}let c=e.state.doc.resolve(t),d=c.sharedDepth(n);t=c.before(d+1),n=e.state.doc.resolve(n).after(d+1);let u=e.state.selection,p=function(e,t,n){let r,{node:i,fromOffset:s,toOffset:o,from:a,to:l}=e.docView.parseRange(t,n),c=e.domSelectionRange(),d=c.anchorNode;if(d&&e.dom.contains(1==d.nodeType?d:d.parentNode)&&(r=[{node:d,offset:c.anchorOffset}],o$(c)||r.push({node:c.focusNode,offset:c.focusOffset})),oZ&&8===e.input.lastKeyCode)for(let e=o;e>s;e--){let t=i.childNodes[e-1],n=t.pmViewDesc;if("BR"==t.nodeName&&!n){o=e;break}if(!n||n.size)break}let u=e.state.doc,p=e.someProp("domParser")||sx.fromSchema(e.state.schema),h=u.resolve(a),m=null,f=p.parse(i,{topNode:h.parent,topMatch:h.parent.contentMatchAt(h.index()),topOpen:!0,from:s,to:o,preserveWhitespace:"pre"!=h.parent.type.whitespace||"full",findPositions:r,ruleFromNode:lJ,context:h});if(r&&null!=r[0].pos){let e=r[0].pos,t=r[1]&&r[1].pos;null==t&&(t=e),m={anchor:e+a,head:t+a}}return{doc:f,sel:m,from:a,to:l}}(e,t,n),h=e.state.doc,m=h.slice(p.from,p.to);8===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime?(s=e.state.selection.to,o="end"):(s=e.state.selection.from,o="start"),e.input.lastKeyCode=null;let f=function(e,t,n,r,i){let s=e.findDiffStart(t,n);if(null==s)return null;let{a:o,b:a}=e.findDiffEnd(t,n+e.size,n+t.size);if("end"==i){let e=Math.max(0,s-Math.min(o,a));r-=o+e-s}if(o<s&&e.size<t.size){let e=r<=s&&r>=o?s-r:0;(s-=e)&&s<t.size&&lQ(t.textBetween(s-1,s+1))&&(s+=e?1:-1),a=s+(a-o),o=s}else if(a<s){let t=r<=s&&r>=a?s-r:0;(s-=t)&&s<e.size&&lQ(e.textBetween(s-1,s+1))&&(s+=t?1:-1),o=s+(o-a),a=s}return{start:s,endA:o,endB:a}}(m.content,p.doc.content,p.from,s,o);if(f&&e.input.domChangeCount++,(oQ&&e.input.lastIOSEnter>Date.now()-225||o2)&&i.some(e=>1==e.nodeType&&!lZ.test(e.nodeName))&&(!f||f.endA>=f.endB)&&e.someProp("handleKeyDown",t=>t(e,oz(13,"Enter")))){e.input.lastIOSEnter=0;return}if(!f)if(r&&u instanceof od&&!u.empty&&u.$head.sameParent(u.$anchor)&&!e.composing&&!(p.sel&&p.sel.anchor!=p.sel.head))f={start:u.from,endA:u.to,endB:u.to};else{if(p.sel){let t=lX(e,e.state.doc,p.sel);if(t&&!t.eq(e.state.selection)){let n=e.state.tr.setSelection(t);l&&n.setMeta("composition",l),e.dispatch(n)}}return}e.state.selection.from<e.state.selection.to&&f.start==f.endB&&e.state.selection instanceof od&&(f.start>e.state.selection.from&&f.start<=e.state.selection.from+2&&e.state.selection.from>=p.from?f.start=e.state.selection.from:f.endA<e.state.selection.to&&f.endA>=e.state.selection.to-2&&e.state.selection.to<=p.to&&(f.endB+=e.state.selection.to-f.endA,f.endA=e.state.selection.to)),oq&&oK<=11&&f.endB==f.start+1&&f.endA==f.start&&f.start>p.from&&" "==p.doc.textBetween(f.start-p.from-1,f.start-p.from+1)&&(f.start--,f.endA--,f.endB--);let g=p.doc.resolveNoCache(f.start-p.from),x=p.doc.resolveNoCache(f.endB-p.from),b=h.resolve(f.start),y=g.sameParent(x)&&g.parent.inlineContent&&b.end()>=f.endA;if((oQ&&e.input.lastIOSEnter>Date.now()-225&&(!y||i.some(e=>"DIV"==e.nodeName||"P"==e.nodeName))||!y&&g.pos<p.doc.content.size&&(!g.sameParent(x)||!g.parent.inlineContent)&&g.pos<x.pos&&!/\S/.test(p.doc.textBetween(g.pos,x.pos,"","")))&&e.someProp("handleKeyDown",t=>t(e,oz(13,"Enter")))){e.input.lastIOSEnter=0;return}if(e.state.selection.anchor>f.start&&function(e,t,n,r,i){if(n-t<=i.pos-r.pos||lY(r,!0,!1)<i.pos)return!1;let s=e.resolve(t);if(!r.parent.isTextblock){let e=s.nodeAfter;return null!=e&&n==t+e.nodeSize}if(s.parentOffset<s.parent.content.size||!s.parent.isTextblock)return!1;let o=e.resolve(lY(s,!0,!0));return!(!o.parent.isTextblock||o.pos>n||lY(o,!0,!1)<n)&&r.parent.content.cut(r.parentOffset).eq(o.parent.content)}(h,f.start,f.endA,g,x)&&e.someProp("handleKeyDown",t=>t(e,oz(8,"Backspace")))){o2&&oZ&&e.domObserver.suppressSelectionUpdates();return}oZ&&f.endB==f.start&&(e.input.lastChromeDelete=Date.now()),o2&&!y&&g.start()!=x.start()&&0==x.parentOffset&&g.depth==x.depth&&p.sel&&p.sel.anchor==p.sel.head&&p.sel.head==f.endA&&(f.endB-=2,x=p.doc.resolveNoCache(f.endB-p.from),setTimeout(()=>{e.someProp("handleKeyDown",function(t){return t(e,oz(13,"Enter"))})},20));let v=f.start,w=f.endA,k=t=>{let n=t||e.state.tr.replace(v,w,p.doc.slice(f.start-p.from,f.endB-p.from));if(p.sel){let t=lX(e,n.doc,p.sel);t&&!(oZ&&e.composing&&t.empty&&(f.start!=f.endB||e.input.lastChromeDelete<Date.now()-100)&&(t.head==v||t.head==n.mapping.map(w)-1)||oq&&t.empty&&t.head==v)&&n.setSelection(t)}return l&&n.setMeta("composition",l),n.scrollIntoView()};if(y)if(g.pos==x.pos){oq&&oK<=11&&0==g.parentOffset&&(e.domObserver.suppressSelectionUpdates(),setTimeout(()=>aD(e),20));let t=k(e.state.tr.delete(v,w)),n=h.resolve(f.start).marksAcross(h.resolve(f.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(f.endA==f.endB&&(a=function(e,t){let n=e.firstChild.marks,r=t.firstChild.marks,i=n,s=r,o,a,l;for(let e=0;e<r.length;e++)i=r[e].removeFromSet(i);for(let e=0;e<n.length;e++)s=n[e].removeFromSet(s);if(1==i.length&&0==s.length)a=i[0],o="add",l=e=>e.mark(a.addToSet(e.marks));else{if(0!=i.length||1!=s.length)return null;a=s[0],o="remove",l=e=>e.mark(a.removeFromSet(e.marks))}let c=[];for(let e=0;e<t.childCount;e++)c.push(l(t.child(e)));if(iW.from(c).eq(e))return{mark:a,type:o}}(g.parent.content.cut(g.parentOffset,x.parentOffset),b.parent.content.cut(b.parentOffset,f.endA-b.start())))){let t=k(e.state.tr);"add"==a.type?t.addMark(v,w,a.mark):t.removeMark(v,w,a.mark),e.dispatch(t)}else if(g.parent.child(g.index()).isText&&g.index()==x.index()-!x.textOffset){let t=g.parent.textBetween(g.parentOffset,x.parentOffset),n=()=>k(e.state.tr.insertText(t,v,w));e.someProp("handleTextInput",r=>r(e,v,w,t,n))||e.dispatch(n())}else e.dispatch(k());else e.dispatch(k())})(this,e,t,n,r)),this.domObserver.start(),function(e){for(let t in lt){let n=lt[t];e.dom.addEventListener(t,e.input.eventHandlers[t]=t=>{!function(e,t){if(!t.bubbles)return!0;if(t.defaultPrevented)return!1;for(let n=t.target;n!=e.dom;n=n.parentNode)if(!n||11==n.nodeType||n.pmViewDesc&&n.pmViewDesc.stopEvent(t))return!1;return!0}(e,t)||la(e,t)||!e.editable&&t.type in ln||n(e,t)},lr[t]?{passive:!0}:void 0)}oY&&e.dom.addEventListener("input",()=>null),lo(e)}(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;for(let t in this._props={},e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&lo(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(l4),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let e in this._props)t[e]=this._props[e];for(let n in t.state=this.state,e)t[n]=e[n];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var n,r,i;let s=this.state,o=!1,a=!1;e.storedMarks&&this.composing&&(lg(this),a=!0),this.state=e;let l=s.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let e=l3(this);(function(e,t){let n=0,r=0;for(let r in e){if(e[r]!=t[r])return!0;n++}for(let e in t)r++;return n!=r})(e,this.nodeViews)&&(this.nodeViews=e,o=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&lo(this),this.editable=l5(this),l2(this);let c=lF(this),d=l1(this),u=s.plugins==e.plugins||s.doc.eq(e.doc)?e.scrollToSelection>s.scrollToSelection?"to selection":"preserve":"reset",p=o||!this.docView.matchesNode(e.doc,d,c);(p||!e.selection.eq(s.selection))&&(a=!0);let h="preserve"==u&&a&&null==this.dom.style.overflowAnchor&&function(e){let t,n,r=e.dom.getBoundingClientRect(),i=Math.max(0,r.top);for(let s=(r.left+r.right)/2,o=i+1;o<Math.min(innerHeight,r.bottom);o+=5){let r=e.root.elementFromPoint(s,o);if(!r||r==e.dom||!e.dom.contains(r))continue;let a=r.getBoundingClientRect();if(a.top>=i-20){t=r,n=a.top;break}}return{refDOM:t,refTop:n,stack:o9(e.dom)}}(this);if(a){let t,n,a;this.domObserver.stop();let l=p&&(oq||oZ)&&!this.composing&&!s.selection.empty&&!e.selection.empty&&(r=s.selection,i=e.selection,a=Math.min(r.$anchor.sharedDepth(r.head),i.$anchor.sharedDepth(i.head)),r.$anchor.start(a)!=i.$anchor.start(a));if(p){let t=oZ?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=function(e){let t=e.domSelectionRange();if(!t.focusNode)return null;let n=function(e,t){for(;;){if(3==e.nodeType&&t)return e;if(1==e.nodeType&&t>0){if("false"==e.contentEditable)return null;t=oL(e=e.childNodes[t-1])}else{if(!e.parentNode||oP(e))return null;t=oM(e),e=e.parentNode}}}(t.focusNode,t.focusOffset),r=function(e,t){for(;;){if(3==e.nodeType&&t<e.nodeValue.length)return e;if(1==e.nodeType&&t<e.childNodes.length){if("false"==e.contentEditable)return null;e=e.childNodes[t],t=0}else{if(!e.parentNode||oP(e))return null;t=oM(e)+1,e=e.parentNode}}}(t.focusNode,t.focusOffset);if(n&&r&&n!=r){let t=r.pmViewDesc,i=e.domObserver.lastChangedTextNode;if(n==i||r==i)return i;if(!t||!t.isText(r.nodeValue))return r;if(e.input.compositionNode==r){let e=n.pmViewDesc;if(!(!e||!e.isText(n.nodeValue)))return r}}return n||r}(this)),(o||!this.docView.update(e.doc,d,c,this))&&(this.docView.updateOuterDeco(d),this.docView.destroy(),this.docView=ax(e.doc,d,c,this.dom,this)),!t||this.trackWrites&&this.dom.contains(this.trackWrites)||(l=!0)}l||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&(t=this.docView.domFromPos(this.state.selection.anchor,0),n=this.domSelectionRange(),oD(t.node,t.offset,n.anchorNode,n.anchorOffset)))?aD(this,l):(a$(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(s),(null==(n=this.dragging)?void 0:n.node)&&!s.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,s),"reset"==u?this.dom.scrollTop=0:"to selection"==u?this.scrollToSelection():h&&function({refDOM:e,refTop:t,stack:n}){let r=e?e.getBoundingClientRect().top:0;o7(n,0==r?0:r-t)}(h)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(e&&this.dom.contains(1==e.nodeType?e:e.parentNode))if(this.someProp("handleScrollToSelection",e=>e(this)));else if(this.state.selection instanceof op){let t=this.docView.domAfterPos(this.state.selection.from);1==t.nodeType&&o6(this,t.getBoundingClientRect(),e)}else o6(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(e&&e.plugins==this.state.plugins&&this.directPlugins==this.prevDirectPlugins)for(let t=0;t<this.pluginViews.length;t++){let n=this.pluginViews[t];n.update&&n.update(this,e)}else{this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let e=0;e<this.directPlugins.length;e++){let t=this.directPlugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}for(let e=0;e<this.state.plugins.length;e++){let t=this.state.plugins[e];t.spec.view&&this.pluginViews.push(t.spec.view(this))}}}updateDraggedNode(e,t){let n=e.node,r=-1;if(n.from<this.state.doc.content.size&&this.state.doc.nodeAt(n.from)==n.node)r=n.from;else{let e=n.from+(this.state.doc.content.size-t.doc.content.size);(e>0&&e<this.state.doc.content.size&&this.state.doc.nodeAt(e))==n.node&&(r=e)}this.dragging=new lw(e.slice,e.move,r<0?void 0:op.create(this.state.doc,r))}someProp(e,t){let n=this._props&&this._props[e],r;if(null!=n&&(r=t?t(n):n))return r;for(let n=0;n<this.directPlugins.length;n++){let i=this.directPlugins[n].props[e];if(null!=i&&(r=t?t(i):i))return r}let i=this.state.plugins;if(i)for(let n=0;n<i.length;n++){let s=i[n].props[e];if(null!=s&&(r=t?t(s):s))return r}}hasFocus(){if(oq){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if("false"==e.contentEditable)return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&function(e){if(e.setActive)return e.setActive();if(o8)return e.focus(o8);let t=o9(e);e.focus(null==o8?{get preventScroll(){return o8={preventScroll:!0},!0}}:void 0),o8||(o8=!1,o7(t,0))}(this.dom),aD(this),this.domObserver.start()}get root(){let e=this._root;if(null==e){for(let e=this.dom.parentNode;e;e=e.parentNode)if(9==e.nodeType||11==e.nodeType&&e.host)return e.getSelection||(Object.getPrototypeOf(e).getSelection=()=>e.ownerDocument.getSelection()),this._root=e}return e||document}updateRoot(){this._root=null}posAtCoords(e){return function(e,t){var n;let r,i,s=e.dom.ownerDocument,o,a=0,l=function(e,t,n){if(e.caretPositionFromPoint)try{let r=e.caretPositionFromPoint(t,n);if(r)return{node:r.offsetNode,offset:Math.min(oL(r.offsetNode),r.offset)}}catch(e){}if(e.caretRangeFromPoint){let r=e.caretRangeFromPoint(t,n);if(r)return{node:r.startContainer,offset:Math.min(oL(r.startContainer),r.startOffset)}}}(s,t.left,t.top);l&&({node:o,offset:a}=l);let c=(e.root.elementFromPoint?e.root:s).elementFromPoint(t.left,t.top);if(!c||!e.dom.contains(1!=c.nodeType?c.parentNode:c)){let n=e.dom.getBoundingClientRect();if(!ae(t,n)||!(c=function e(t,n,r){let i=t.childNodes.length;if(i&&r.top<r.bottom)for(let s=Math.max(0,Math.min(i-1,Math.floor(i*(n.top-r.top)/(r.bottom-r.top))-2)),o=s;;){let r=t.childNodes[o];if(1==r.nodeType){let t=r.getClientRects();for(let i=0;i<t.length;i++){let s=t[i];if(ae(n,s))return e(r,n,s)}}if((o=(o+1)%i)==s)break}return t}(e.dom,t,n)))return null}if(oY)for(let e=c;o&&e;e=oA(e))e.draggable&&(o=void 0);if(c=(r=(n=c).parentNode)&&/^li$/i.test(r.nodeName)&&t.left<n.getBoundingClientRect().left?r:n,o){let n;if(oG&&1==o.nodeType&&(a=Math.min(a,o.childNodes.length))<o.childNodes.length){let e=o.childNodes[a],n;"IMG"==e.nodeName&&(n=e.getBoundingClientRect()).right<=t.left&&n.bottom>t.top&&a++}o5&&a&&1==o.nodeType&&1==(n=o.childNodes[a-1]).nodeType&&"false"==n.contentEditable&&n.getBoundingClientRect().top>=t.top&&a--,o==e.dom&&a==o.childNodes.length-1&&1==o.lastChild.nodeType&&t.top>o.lastChild.getBoundingClientRect().bottom?i=e.state.doc.content.size:(0==a||1!=o.nodeType||"BR"!=o.childNodes[a-1].nodeName)&&(i=function(e,t,n,r){let i=-1;for(let n=t,s=!1;n!=e.dom;){let t=e.docView.nearestDesc(n,!0),o;if(!t)return null;if(1==t.dom.nodeType&&(t.node.isBlock&&t.parent||!t.contentDOM)&&((o=t.dom.getBoundingClientRect()).width||o.height)&&(t.node.isBlock&&t.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(t.dom.nodeName)&&(!s&&o.left>r.left||o.top>r.top?i=t.posBefore:(!s&&o.right<r.left||o.bottom<r.top)&&(i=t.posAfter),s=!0),!t.contentDOM&&i<0&&!t.node.isText))return(t.node.isBlock?r.top<(o.top+o.bottom)/2:r.left<(o.left+o.right)/2)?t.posBefore:t.posAfter;n=t.dom.parentNode}return i>-1?i:e.docView.posFromDOM(t,n,-1)}(e,o,a,t))}null==i&&(i=function(e,t,n){let{node:r,offset:i}=function e(t,n){let r,i,s,o=2e8,a,l=0,c=n.top,d=n.top;for(let e=t.firstChild,u=0;e;e=e.nextSibling,u++){let t;if(1==e.nodeType)t=e.getClientRects();else{if(3!=e.nodeType)continue;t=oO(e).getClientRects()}for(let p=0;p<t.length;p++){let h=t[p];if(h.top<=c&&h.bottom>=d){c=Math.max(h.bottom,c),d=Math.min(h.top,d);let t=h.left>n.left?h.left-n.left:h.right<n.left?n.left-h.right:0;if(t<o){s=e,o=t,a=t&&3==s.nodeType?{left:h.right<n.left?h.right:h.left,top:n.top}:n,1==e.nodeType&&t&&(l=u+ +(n.left>=(h.left+h.right)/2));continue}}else h.top>n.top&&!r&&h.left<=n.left&&h.right>=n.left&&(r=e,i={left:Math.max(h.left,Math.min(h.right,n.left)),top:h.top});!s&&(n.left>=h.right&&n.top>=h.top||n.left>=h.left&&n.top>=h.bottom)&&(l=u+1)}}return(!s&&r&&(s=r,a=i,o=0),s&&3==s.nodeType)?function(e,t){let n=e.nodeValue.length,r=document.createRange(),i;for(let s=0;s<n;s++){r.setEnd(e,s+1),r.setStart(e,s);let n=an(r,1);if(n.top!=n.bottom&&ae(t,n)){i={node:e,offset:s+ +(t.left>=(n.left+n.right)/2)};break}}return r.detach(),i||{node:e,offset:0}}(s,a):!s||o&&1==s.nodeType?{node:t,offset:l}:e(s,a)}(t,n),s=-1;if(1==r.nodeType&&!r.firstChild){let e=r.getBoundingClientRect();s=e.left!=e.right&&n.left>(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(r,i,s)}(e,c,t));let d=e.docView.nearestDesc(c,!0);return{pos:i,inside:d?d.posAtStart-d.border:-1}}(this,e)}coordsAtPos(e,t=1){return ai(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,n=-1){let r=this.docView.posFromDOM(e,t,n);if(null==r)throw RangeError("DOM position not inside the editor");return r}endOfTextblock(e,t){return function(e,t,n){let r,i;return ac==t&&ad==n?au:(ac=t,ad=n,au="up"==n||"down"==n?(r=t.selection,i="up"==n?r.$from:r.$to,aa(e,t,()=>{let{node:t}=e.docView.domFromPos(i.pos,"up"==n?-1:1);for(;;){let n=e.docView.nearestDesc(t,!0);if(!n)break;if(n.node.isBlock){t=n.contentDOM||n.dom;break}t=n.dom.parentNode}let r=ai(e,i.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(1==e.nodeType)t=e.getClientRects();else{if(3!=e.nodeType)continue;t=oO(e,0,e.nodeValue.length).getClientRects()}for(let e=0;e<t.length;e++){let i=t[e];if(i.bottom>i.top+1&&("up"==n?r.top-i.top>(i.bottom-r.top)*2:i.bottom-r.bottom>(r.bottom-i.top)*2))return!1}}return!0})):function(e,t,n){let{$head:r}=t.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=i==r.parent.content.size,o=e.domSelection();return o?al.test(r.parent.textContent)&&o.modify?aa(e,t,()=>{let{focusNode:t,focusOffset:i,anchorNode:s,anchorOffset:a}=e.domSelectionRange(),l=o.caretBidiLevel;o.modify("move",n,"character");let c=r.depth?e.docView.domAfterPos(r.before()):e.dom,{focusNode:d,focusOffset:u}=e.domSelectionRange(),p=d&&!c.contains(1==d.nodeType?d:d.parentNode)||t==d&&i==u;try{o.collapse(s,a),t&&(t!=s||i!=a)&&o.extend&&o.extend(t,i)}catch(e){}return null!=l&&(o.caretBidiLevel=l),p}):"left"==n||"backward"==n?!i:s:r.pos==r.start()||r.pos==r.end()}(e,t,n))}(this,t||this.state,e)}pasteHTML(e,t){return ly(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return ly(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return a1(this,e)}destroy(){if(this.docView){for(let e in this.domObserver.stop(),this.input.eventHandlers)this.dom.removeEventListener(e,this.input.eventHandlers[e]);clearTimeout(this.input.composingTimeout),clearTimeout(this.input.lastIOSEnterFallbackTimeout),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],lF(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,o_()}}get isDestroyed(){return null==this.docView}dispatchEvent(e){!la(this,e)&<[e.type]&&(this.editable||!(e.type in ln))&<[e.type](this,e)}domSelectionRange(){let e=this.domSelection();return e?oY&&11===this.root.nodeType&&function(e){let t=e.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}(this.dom.ownerDocument)==this.dom&&function(e,t){let n;if(t.getComposedRanges){let n=t.getComposedRanges(e.root)[0];if(n)return lG(e,n)}function r(e){e.preventDefault(),e.stopImmediatePropagation(),n=e.getTargetRanges()[0]}return e.dom.addEventListener("beforeinput",r,!0),document.execCommand("indent"),e.dom.removeEventListener("beforeinput",r,!0),n?lG(e,n):null}(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function l1(e){let t=Object.create(null);return t.class="ProseMirror",t.contenteditable=String(e.editable),e.someProp("attributes",n=>{if("function"==typeof n&&(n=n(e.state)),n)for(let e in n)"class"==e?t.class+=" "+n[e]:"style"==e?t.style=(t.style?t.style+";":"")+n[e]:t[e]||"contenteditable"==e||"nodeName"==e||(t[e]=String(n[e]))}),t.translate||(t.translate="no"),[lM.node(0,e.state.doc.content.size,t)]}function l2(e){if(e.markCursor){let t=document.createElement("img");t.className="ProseMirror-separator",t.setAttribute("mark-placeholder","true"),t.setAttribute("alt",""),e.cursorWrapper={dom:t,deco:lM.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function l5(e){return!e.someProp("editable",t=>!1===t(e.state))}function l3(e){let t=Object.create(null);function n(e){for(let n in e)Object.prototype.hasOwnProperty.call(t,n)||(t[n]=e[n])}return e.someProp("nodeViews",n),e.someProp("markViews",n),t}function l4(e){if(e.spec.state||e.spec.filterTransaction||e.spec.appendTransaction)throw RangeError("Plugins passed directly to the view must not have a state component")}l0.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};for(var l6={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},l9={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},l7="u">typeof navigator&&/Mac/.test(navigator.platform),l8="u">typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),ce=0;ce<10;ce++)l6[48+ce]=l6[96+ce]=String(ce);for(var ce=1;ce<=24;ce++)l6[ce+111]="F"+ce;for(var ce=65;ce<=90;ce++)l6[ce]=String.fromCharCode(ce+32),l9[ce]=String.fromCharCode(ce);for(var ct in l6)l9.hasOwnProperty(ct)||(l9[ct]=l6[ct]);let cn="u">typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),cr="u">typeof navigator&&/Win/.test(navigator.platform);function ci(e,t,n=!0){return t.altKey&&(e="Alt-"+e),t.ctrlKey&&(e="Ctrl-"+e),t.metaKey&&(e="Meta-"+e),n&&t.shiftKey&&(e="Shift-"+e),e}function cs(e){let t=function(e){let t=Object.create(null);for(let n in e)t[function(e){let t,n,r,i,s=e.split(/-(?!$)/),o=s[s.length-1];"Space"==o&&(o=" ");for(let e=0;e<s.length-1;e++){let o=s[e];if(/^(cmd|meta|m)$/i.test(o))i=!0;else if(/^a(lt)?$/i.test(o))t=!0;else if(/^(c|ctrl|control)$/i.test(o))n=!0;else if(/^s(hift)?$/i.test(o))r=!0;else if(/^mod$/i.test(o))cn?i=!0:n=!0;else throw Error("Unrecognized modifier name: "+o)}return t&&(o="Alt-"+o),n&&(o="Ctrl-"+o),i&&(o="Meta-"+o),r&&(o="Shift-"+o),o}(n)]=e[n];return t}(e);return function(e,n){var r;let i=("Esc"==(r=!(l7&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||l8&&n.shiftKey&&n.key&&1==n.key.length||"Unidentified"==n.key)&&n.key||(n.shiftKey?l9:l6)[n.keyCode]||n.key||"Unidentified")&&(r="Escape"),"Del"==r&&(r="Delete"),"Left"==r&&(r="ArrowLeft"),"Up"==r&&(r="ArrowUp"),"Right"==r&&(r="ArrowRight"),"Down"==r&&(r="ArrowDown"),r),s,o=t[ci(i,n)];if(o&&o(e.state,e.dispatch,e))return!0;if(1==i.length&&" "!=i){if(n.shiftKey){let r=t[ci(i,n,!1)];if(r&&r(e.state,e.dispatch,e))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(cr&&n.ctrlKey&&n.altKey)&&(s=l6[n.keyCode])&&s!=i){let r=t[ci(s,n)];if(r&&r(e.state,e.dispatch,e))return!0}}return!1}}if("u">typeof WeakMap){let e=new WeakMap;t=t=>e.get(t),n=(t,n)=>(e.set(t,n),n)}else{let e=[],r=0;t=t=>{for(let n=0;n<e.length;n+=2)if(e[n]==t)return e[n+1]},n=(t,n)=>(10==r&&(r=0),e[r++]=t,e[r++]=n)}var co=class{constructor(e,t,n,r){this.width=e,this.height=t,this.map=n,this.problems=r}findCell(e){for(let t=0;t<this.map.length;t++){let n=this.map[t];if(n!=e)continue;let r=t%this.width,i=t/this.width|0,s=r+1,o=i+1;for(let e=1;s<this.width&&this.map[t+e]==n;e++)s++;for(let e=1;o<this.height&&this.map[t+this.width*e]==n;e++)o++;return{left:r,top:i,right:s,bottom:o}}throw RangeError(`No cell with offset ${e} found`)}colCount(e){for(let t=0;t<this.map.length;t++)if(this.map[t]==e)return t%this.width;throw RangeError(`No cell with offset ${e} found`)}nextCell(e,t,n){let{left:r,right:i,top:s,bottom:o}=this.findCell(e);return"horiz"==t?(n<0?0==r:i==this.width)?null:this.map[s*this.width+(n<0?r-1:i)]:(n<0?0==s:o==this.height)?null:this.map[r+this.width*(n<0?s-1:o)]}rectBetween(e,t){let{left:n,right:r,top:i,bottom:s}=this.findCell(e),{left:o,right:a,top:l,bottom:c}=this.findCell(t);return{left:Math.min(n,o),top:Math.min(i,l),right:Math.max(r,a),bottom:Math.max(s,c)}}cellsInRect(e){let t=[],n={};for(let r=e.top;r<e.bottom;r++)for(let i=e.left;i<e.right;i++){let s=r*this.width+i,o=this.map[s];!n[o]&&(n[o]=!0,i==e.left&&i&&this.map[s-1]==o||r==e.top&&r&&this.map[s-this.width]==o||t.push(o))}return t}positionAt(e,t,n){for(let r=0,i=0;;r++){let s=i+n.child(r).nodeSize;if(r==e){let n=t+e*this.width,r=(e+1)*this.width;for(;n<r&&this.map[n]<i;)n++;return n==r?s-1:this.map[n]}i=s}}static get(e){return t(e)||n(e,function(e){if("table"!=e.type.spec.tableRole)throw RangeError("Not a table node: "+e.type.name);let t=function(e){let t=-1,n=!1;for(let r=0;r<e.childCount;r++){let i=e.child(r),s=0;if(n)for(let t=0;t<r;t++){let n=e.child(t);for(let e=0;e<n.childCount;e++){let i=n.child(e);t+i.attrs.rowspan>r&&(s+=i.attrs.colspan)}}for(let e=0;e<i.childCount;e++){let t=i.child(e);s+=t.attrs.colspan,t.attrs.rowspan>1&&(n=!0)}-1==t?t=s:t!=s&&(t=Math.max(t,s))}return t}(e),n=e.childCount,r=[],i=0,s=null,o=[];for(let e=0,i=t*n;e<i;e++)r[e]=0;for(let a=0,l=0;a<n;a++){let c=e.child(a);l++;for(let e=0;;e++){for(;i<r.length&&0!=r[i];)i++;if(e==c.childCount)break;let d=c.child(e),{colspan:u,rowspan:p,colwidth:h}=d.attrs;for(let e=0;e<p;e++){if(e+a>=n){(s||(s=[])).push({type:"overlong_rowspan",pos:l,n:p-e});break}let c=i+e*t;for(let e=0;e<u;e++){0==r[c+e]?r[c+e]=l:(s||(s=[])).push({type:"collision",row:a,pos:l,n:u-e});let n=h&&h[e];if(n){let r=(c+e)%t*2,i=o[r];null==i||i!=n&&1==o[r+1]?(o[r]=n,o[r+1]=1):i==n&&o[r+1]++}}}i+=u,l+=d.nodeSize}let d=(a+1)*t,u=0;for(;i<d;)0==r[i++]&&u++;u&&(s||(s=[])).push({type:"missing",row:a,n:u}),l++}(0===t||0===n)&&(s||(s=[])).push({type:"zero_sized"});let a=new co(t,n,r,s),l=!1;for(let e=0;!l&&e<o.length;e+=2)null!=o[e]&&o[e+1]<n&&(l=!0);return l&&function(e,t,n){e.problems||(e.problems=[]);let r={};for(let i=0;i<e.map.length;i++){let s=e.map[i];if(r[s])continue;r[s]=!0;let o=n.nodeAt(s);if(!o)throw RangeError(`No cell with offset ${s} found`);let a=null,l=o.attrs;for(let n=0;n<l.colspan;n++){let r=t[(i+n)%e.width*2];null==r||l.colwidth&&l.colwidth[n]==r||((a||(a=function(e){if(e.colwidth)return e.colwidth.slice();let t=[];for(let n=0;n<e.colspan;n++)t.push(0);return t}(l)))[n]=r)}a&&e.problems.unshift({type:"colwidth mismatch",pos:s,colwidth:a})}}(a,o,e),a}(e))}};function ca(e){let t=e.cached.tableNodeTypes;if(!t)for(let n in t=e.cached.tableNodeTypes={},e.nodes){let r=e.nodes[n],i=r.spec.tableRole;i&&(t[i]=r)}return t}let cl=new oE("selectingCells");function cc(e){for(let t=e.depth-1;t>0;t--)if("row"==e.node(t).type.spec.tableRole)return e.node(0).resolve(e.before(t+1));return null}function cd(e){let t=e.selection.$head;for(let e=t.depth;e>0;e--)if("row"==t.node(e).type.spec.tableRole)return!0;return!1}function cu(e){let t=e.selection;if("$anchorCell"in t&&t.$anchorCell)return t.$anchorCell.pos>t.$headCell.pos?t.$anchorCell:t.$headCell;if("node"in t&&t.node&&"cell"==t.node.type.spec.tableRole)return t.$anchor;let n=cc(t.$head)||function(e){for(let t=e.nodeAfter,n=e.pos;t;t=t.firstChild,n++){let r=t.type.spec.tableRole;if("cell"==r||"header_cell"==r)return e.doc.resolve(n)}for(let t=e.nodeBefore,n=e.pos;t;t=t.lastChild,n--){let r=t.type.spec.tableRole;if("cell"==r||"header_cell"==r)return e.doc.resolve(n-t.nodeSize)}}(t.$head);if(n)return n;throw RangeError(`No cell found around position ${t.head}`)}function cp(e){return"row"==e.parent.type.spec.tableRole&&!!e.nodeAfter}function ch(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function cm(e,t,n){let r=e.node(-1),i=co.get(r),s=e.start(-1),o=i.nextCell(e.pos-s,t,n);return null==o?null:e.node(0).resolve(s+o)}function cf(e,t,n=1){let r={...e,colspan:e.colspan-n};return r.colwidth&&(r.colwidth=r.colwidth.slice(),r.colwidth.splice(t,n),r.colwidth.some(e=>e>0)||(r.colwidth=null)),r}function cg(e,t,n=1){let r={...e,colspan:e.colspan+n};if(r.colwidth){r.colwidth=r.colwidth.slice();for(let e=0;e<n;e++)r.colwidth.splice(t,0,0)}return r}var cx=class e extends oo{constructor(e,t=e){const n=e.node(-1),r=co.get(n),i=e.start(-1),s=r.rectBetween(e.pos-i,t.pos-i),o=e.node(0),a=r.cellsInRect(s).filter(e=>e!=t.pos-i);a.unshift(t.pos-i);const l=a.map(e=>{let t=n.nodeAt(e);if(!t)throw RangeError(`No cell with offset ${e} found`);let r=i+e+1;return new oa(o.resolve(r),o.resolve(r+t.content.size))});super(l[0].$from,l[0].$to,l),this.$anchorCell=e,this.$headCell=t}map(t,n){let r=t.resolve(n.map(this.$anchorCell.pos)),i=t.resolve(n.map(this.$headCell.pos));if(cp(r)&&cp(i)&&ch(r,i)){let t=this.$anchorCell.node(-1)!=r.node(-1);return t&&this.isRowSelection()?e.rowSelection(r,i):t&&this.isColSelection()?e.colSelection(r,i):new e(r,i)}return od.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=co.get(e),n=this.$anchorCell.start(-1),r=t.rectBetween(this.$anchorCell.pos-n,this.$headCell.pos-n),i={},s=[];for(let n=r.top;n<r.bottom;n++){let o=[];for(let s=n*t.width+r.left,a=r.left;a<r.right;a++,s++){let n=t.map[s];if(i[n])continue;i[n]=!0;let a=t.findCell(n),l=e.nodeAt(n);if(!l)throw RangeError(`No cell with offset ${n} found`);let c=r.left-a.left,d=a.right-r.right;if(c>0||d>0){let e=l.attrs;if(c>0&&(e=cf(e,0,c)),d>0&&(e=cf(e,e.colspan-d,d)),a.left<r.left){if(!(l=l.type.createAndFill(e)))throw RangeError(`Could not create cell with attrs ${JSON.stringify(e)}`)}else l=l.type.create(e,l.content)}if(a.top<r.top||a.bottom>r.bottom){let e={...l.attrs,rowspan:Math.min(a.bottom,r.bottom)-Math.max(a.top,r.top)};l=a.top<r.top?l.type.createAndFill(e):l.type.create(e,l.content)}o.push(l)}s.push(e.child(n).copy(iW.from(o)))}let o=this.isColSelection()&&this.isRowSelection()?e:s;return new iX(iW.from(o),1,1)}replace(e,t=iX.empty){let n=e.steps.length,r=this.ranges;for(let i=0;i<r.length;i++){let{$from:s,$to:o}=r[i],a=e.mapping.slice(n);e.replace(a.map(s.pos),a.map(o.pos),i?iX.empty:t)}let i=oo.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);i&&e.setSelection(i)}replaceWith(e,t){this.replace(e,new iX(iW.from(t),0,0))}forEachCell(e){let t=this.$anchorCell.node(-1),n=co.get(t),r=this.$anchorCell.start(-1),i=n.cellsInRect(n.rectBetween(this.$anchorCell.pos-r,this.$headCell.pos-r));for(let n=0;n<i.length;n++)e(t.nodeAt(i[n]),r+i[n])}isColSelection(){let e=this.$anchorCell.index(-1),t=this.$headCell.index(-1);return!(Math.min(e,t)>0)&&Math.max(e+this.$anchorCell.nodeAfter.attrs.rowspan,t+this.$headCell.nodeAfter.attrs.rowspan)==this.$headCell.node(-1).childCount}static colSelection(t,n=t){let r=t.node(-1),i=co.get(r),s=t.start(-1),o=i.findCell(t.pos-s),a=i.findCell(n.pos-s),l=t.node(0);return o.top<=a.top?(o.top>0&&(t=l.resolve(s+i.map[o.left])),a.bottom<i.height&&(n=l.resolve(s+i.map[i.width*(i.height-1)+a.right-1]))):(a.top>0&&(n=l.resolve(s+i.map[a.left])),o.bottom<i.height&&(t=l.resolve(s+i.map[i.width*(i.height-1)+o.right-1]))),new e(t,n)}isRowSelection(){let e=this.$anchorCell.node(-1),t=co.get(e),n=this.$anchorCell.start(-1),r=t.colCount(this.$anchorCell.pos-n),i=t.colCount(this.$headCell.pos-n);return!(Math.min(r,i)>0)&&Math.max(r+this.$anchorCell.nodeAfter.attrs.colspan,i+this.$headCell.nodeAfter.attrs.colspan)==t.width}eq(t){return t instanceof e&&t.$anchorCell.pos==this.$anchorCell.pos&&t.$headCell.pos==this.$headCell.pos}static rowSelection(t,n=t){let r=t.node(-1),i=co.get(r),s=t.start(-1),o=i.findCell(t.pos-s),a=i.findCell(n.pos-s),l=t.node(0);return o.left<=a.left?(o.left>0&&(t=l.resolve(s+i.map[o.top*i.width])),a.right<i.width&&(n=l.resolve(s+i.map[i.width*(a.top+1)-1]))):(a.left>0&&(n=l.resolve(s+i.map[a.top*i.width])),o.right<i.width&&(t=l.resolve(s+i.map[i.width*(o.top+1)-1]))),new e(t,n)}toJSON(){return{type:"cell",anchor:this.$anchorCell.pos,head:this.$headCell.pos}}static fromJSON(t,n){return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(t,n,r=n){return new e(t.resolve(n),t.resolve(r))}getBookmark(){return new cb(this.$anchorCell.pos,this.$headCell.pos)}};cx.prototype.visible=!1,oo.jsonID("cell",cx);var cb=class e{constructor(e,t){this.anchor=e,this.head=t}map(t){return new e(t.map(this.anchor),t.map(this.head))}resolve(e){let t=e.resolve(this.anchor),n=e.resolve(this.head);return"row"==t.parent.type.spec.tableRole&&"row"==n.parent.type.spec.tableRole&&t.index()<t.parent.childCount&&n.index()<n.parent.childCount&&ch(t,n)?new cx(t,n):oo.near(n,1)}};function cy(e){if(!(e.selection instanceof cx))return null;let t=[];return e.selection.forEachCell((e,n)=>{t.push(lM.node(n,n+e.nodeSize,{class:"selectedCell"}))}),lO.create(e.doc,t)}let cv=new oE("fix-tables");function cw(e,t){let n,r=(t,r)=>{"table"==t.type.spec.tableRole&&(n=function(e,t,n,r){let i,s,o=co.get(t);if(!o.problems)return r;r||(r=e.tr);let a=[];for(let e=0;e<o.height;e++)a.push(0);for(let e=0;e<o.problems.length;e++){let i=o.problems[e];if("collision"==i.type){let e=t.nodeAt(i.pos);if(!e)continue;let s=e.attrs;for(let e=0;e<s.rowspan;e++)a[i.row+e]+=i.n;r.setNodeMarkup(r.mapping.map(n+1+i.pos),null,cf(s,s.colspan-i.n,i.n))}else if("missing"==i.type)a[i.row]+=i.n;else if("overlong_rowspan"==i.type){let e=t.nodeAt(i.pos);if(!e)continue;r.setNodeMarkup(r.mapping.map(n+1+i.pos),null,{...e.attrs,rowspan:e.attrs.rowspan-i.n})}else if("colwidth mismatch"==i.type){let e=t.nodeAt(i.pos);if(!e)continue;r.setNodeMarkup(r.mapping.map(n+1+i.pos),null,{...e.attrs,colwidth:i.colwidth})}else if("zero_sized"==i.type){let e=r.mapping.map(n);r.delete(e,e+t.nodeSize)}}for(let e=0;e<a.length;e++)a[e]&&(null==i&&(i=e),s=e);for(let l=0,c=n+1;l<o.height;l++){let n=t.child(l),o=c+n.nodeSize,d=a[l];if(d>0){let t="cell";n.firstChild&&(t=n.firstChild.type.spec.tableRole);let a=[];for(let n=0;n<d;n++){let n=ca(e.schema)[t].createAndFill();n&&a.push(n)}let u=(0==l||i==l-1)&&s==l?c+1:o-1;r.insert(r.mapping.map(u),a)}c=o}return r.setMeta(cv,{fixTables:!0})}(e,t,r,n))};return t?t.doc!=e.doc&&function e(t,n,r,i){let s=t.childCount,o=n.childCount;n:for(let a=0,l=0;a<o;a++){let o=n.child(a);for(let e=l,n=Math.min(s,a+3);e<n;e++)if(t.child(e)==o){l=e+1,r+=o.nodeSize;continue n}i(o,r),l<s&&t.child(l).sameMarkup(o)?e(t.child(l),o,r+1,i):o.nodesBetween(0,o.content.size,i,r+1),r+=o.nodeSize}}(t.doc,e.doc,0,r):e.doc.descendants(r),n}function ck(e){let t=co.get(e),n=[],r=t.height,i=t.width;for(let s=0;s<r;s++){let r=[];for(let n=0;n<i;n++){let o=s*i+n,a=t.map[o];if(s>0){let e=o-i;if(a===t.map[e]){r.push(null);continue}}if(n>0){let e=o-1;if(a===t.map[e]){r.push(null);continue}}r.push(e.nodeAt(a))}n.push(r)}return n}function cN(e,t){let n=[],r=co.get(e),i=r.height,s=r.width;for(let o=0;o<i;o++){let i=e.child(o),a=[];for(let n=0;n<s;n++){let i=t[o][n];if(!i)continue;let s=r.map[o*r.width+n],l=e.nodeAt(s);if(!l)continue;let c=l.type.createChecked(i.attrs,i.content,i.marks);a.push(c)}let l=i.type.createChecked(i.attrs,a,i.marks);n.push(l)}return e.type.createChecked(e.attrs,n,e.marks)}function cS(e,t,n,r){let i,s=t[0]>n[0]?-1:1,o=e.splice(t[0],t.length),a=+(o.length%2==0);return i=-1===r&&1===s?n[0]-1:1===r&&-1===s?n[n.length-1]-a+1:-1===s?n[0]:n[n.length-1]-a,e.splice(i,0,...o),e}function cC(e){var t=e;for(let e=t.depth;e>=0;e-=1){let n=t.node(e);if((e=>"table"===e.type.spec.tableRole)(n))return{node:n,pos:0===e?0:t.before(e),start:t.start(e),depth:e}}return null}function cj(e,t){let n=cC(t.$from);if(!n)return;let r=co.get(n.node);if(!(e<0)&&!(e>r.width-1))return r.cellsInRect({left:e,right:e+1,top:0,bottom:r.height}).map(e=>{let t=n.node.nodeAt(e),r=e+n.start;return{pos:r,start:r+1,node:t,depth:n.depth+2}})}function cE(e,t){let n=cC(t.$from);if(!n)return;let r=co.get(n.node);if(!(e<0)&&!(e>r.height-1))return r.cellsInRect({left:0,right:r.width,top:e,bottom:e+1}).map(e=>{let t=n.node.nodeAt(e),r=e+n.start;return{pos:r,start:r+1,node:t,depth:n.depth+2}})}function cM(e,t,n=t){let r,i=t,s=n;for(let n=t;n>=0;n--){let t=cj(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.colspan+n-1;t>=i&&(i=n),t>s&&(s=t)})}for(let n=t;n<=s;n++){let t=cj(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.colspan+n-1;e.node.attrs.colspan>1&&t>s&&(s=t)})}let o=[];for(let t=i;t<=s;t++){let n=cj(t,e.selection);n&&n.length>0&&o.push(t)}i=o[0],s=o[o.length-1];let a=cj(i,e.selection),l=cE(0,e.selection);if(!a||!l)return;let c=e.doc.resolve(a[a.length-1].pos);for(let t=s;t>=i;t--){let n=cj(t,e.selection);if(n&&n.length>0){for(let e=l.length-1;e>=0;e--)if(l[e].pos===n[0].pos){r=n[0];break}if(r)break}}if(r)return{$anchor:c,$head:e.doc.resolve(r.pos),indexes:o}}function cA(e,t,n=t){let r,i=t,s=n;for(let n=t;n>=0;n--){let t=cE(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.rowspan+n-1;t>=i&&(i=n),t>s&&(s=t)})}for(let n=t;n<=s;n++){let t=cE(n,e.selection);t&&t.forEach(e=>{let t=e.node.attrs.rowspan+n-1;e.node.attrs.rowspan>1&&t>s&&(s=t)})}let o=[];for(let t=i;t<=s;t++){let n=cE(t,e.selection);n&&n.length>0&&o.push(t)}i=o[0],s=o[o.length-1];let a=cE(i,e.selection),l=cj(0,e.selection);if(!a||!l)return;let c=e.doc.resolve(a[a.length-1].pos);for(let t=s;t>=i;t--){let n=cE(t,e.selection);if(n&&n.length>0){for(let e=l.length-1;e>=0;e--)if(l[e].pos===n[0].pos){r=n[0];break}if(r)break}}if(r)return{$anchor:c,$head:e.doc.resolve(r.pos),indexes:o}}function cT(e){return e[0].map((t,n)=>e.map(e=>e[n]))}function cO(e){let t=e.selection,n=cu(e),r=n.node(-1),i=n.start(-1),s=co.get(r);return{...t instanceof cx?s.rectBetween(t.$anchorCell.pos-i,t.$headCell.pos-i):s.findCell(n.pos-i),tableStart:i,map:s,table:r}}function c_(e,{map:t,tableStart:n,table:r},i){let s=i>0?-1:0;(function(e,t,n){let r=ca(t.type.schema).header_cell;for(let i=0;i<e.height;i++)if(t.nodeAt(e.map[n+i*e.width]).type!=r)return!1;return!0})(t,r,i+s)&&(s=0==i||i==t.width?null:0);for(let o=0;o<t.height;o++){let a=o*t.width+i;if(i>0&&i<t.width&&t.map[a-1]==t.map[a]){let s=t.map[a],l=r.nodeAt(s);e.setNodeMarkup(e.mapping.map(n+s),null,cg(l.attrs,i-t.colCount(s))),o+=l.attrs.rowspan-1}else{let l=null==s?ca(r.type.schema).cell:r.nodeAt(t.map[a+s]).type,c=t.positionAt(o,i,r);e.insert(e.mapping.map(n+c),l.createAndFill())}}return e}function cD(e,{map:t,tableStart:n,table:r},i){let s=n;for(let e=0;e<i;e++)s+=r.child(e).nodeSize;let o=[],a=i>0?-1:0;(function(e,t,n){var r;let i=ca(t.type.schema).header_cell;for(let s=0;s<e.width;s++)if((null==(r=t.nodeAt(e.map[s+n*e.width]))?void 0:r.type)!=i)return!1;return!0})(t,r,i+a)&&(a=0==i||i==t.height?null:0);for(let s=0,c=t.width*i;s<t.width;s++,c++)if(i>0&&i<t.height&&t.map[c]==t.map[c-t.width]){let i=t.map[c],o=r.nodeAt(i).attrs;e.setNodeMarkup(n+i,null,{...o,rowspan:o.rowspan+1}),s+=o.colspan-1}else{var l;let e=null==a?ca(r.type.schema).cell:null==(l=r.nodeAt(t.map[c+a*t.width]))?void 0:l.type,n=null==e?void 0:e.createAndFill();n&&o.push(n)}return e.insert(s,ca(r.type.schema).row.create(null,o)),e}function cR(e){let t=e.content;return 1==t.childCount&&t.child(0).isTextblock&&0==t.child(0).childCount}function cI(e,t){let n=e.selection;if(!(n instanceof cx)||n.$anchorCell.pos==n.$headCell.pos)return!1;let r=cO(e),{map:i}=r;if(function({width:e,height:t,map:n},r){let i=r.top*e+r.left,s=i,o=(r.bottom-1)*e+r.left,a=i+(r.right-r.left-1);for(let t=r.top;t<r.bottom;t++){if(r.left>0&&n[s]==n[s-1]||r.right<e&&n[a]==n[a+1])return!0;s+=e,a+=e}for(let s=r.left;s<r.right;s++){if(r.top>0&&n[i]==n[i-e]||r.bottom<t&&n[o]==n[o+e])return!0;i++,o++}return!1}(i,r))return!1;if(t){let n,s,o=e.tr,a={},l=iW.empty;for(let e=r.top;e<r.bottom;e++)for(let t=r.left;t<r.right;t++){let c=i.map[e*i.width+t],d=r.table.nodeAt(c);if(!a[c]&&d)if(a[c]=!0,null==n)n=c,s=d;else{cR(d)||(l=l.append(d.content));let e=o.mapping.map(c+r.tableStart);o.delete(e,e+d.nodeSize)}}if(null==n||null==s)return!0;if(o.setNodeMarkup(n+r.tableStart,null,{...cg(s.attrs,s.attrs.colspan,r.right-r.left-s.attrs.colspan),rowspan:r.bottom-r.top}),l.size>0){let e=n+1+s.content.size,t=cR(s)?n+1:e;o.replaceWith(t+r.tableStart,e+r.tableStart,l)}o.setSelection(new cx(o.doc.resolve(n+r.tableStart))),t(o)}return!0}function cL(e,t){var n;let r=ca(e.schema);return(n=({node:e})=>r[e.type.spec.tableRole],(e,t)=>{let r,i,s=e.selection;if(s instanceof cx){if(s.$anchorCell.pos!=s.$headCell.pos)return!1;r=s.$anchorCell.nodeAfter,i=s.$anchorCell.pos}else{var o;if(!(r=function(e){for(let t=e.depth;t>0;t--){let n=e.node(t).type.spec.tableRole;if("cell"===n||"header_cell"===n)return e.node(t)}return null}(s.$from)))return!1;i=null==(o=cc(s.$from))?void 0:o.pos}if(null==r||null==i||1==r.attrs.colspan&&1==r.attrs.rowspan)return!1;if(t){let o,a=r.attrs,l=[],c=a.colwidth;a.rowspan>1&&(a={...a,rowspan:1}),a.colspan>1&&(a={...a,colspan:1});let d=cO(e),u=e.tr;for(let e=0;e<d.right-d.left;e++)l.push(c?{...a,colwidth:c&&c[e]?[c[e]]:null}:a);for(let e=d.top;e<d.bottom;e++){let t=d.map.positionAt(e,d.left,d.table);e==d.top&&(t+=r.nodeSize);for(let i=d.left,s=0;i<d.right;i++,s++)(i!=d.left||e!=d.top)&&u.insert(o=u.mapping.map(t+d.tableStart,1),n({node:r,row:e,col:i}).createAndFill(l[s]))}u.setNodeMarkup(i,n({node:r,row:d.top,col:d.left}),l[0]),s instanceof cx&&u.setSelection(new cx(u.doc.resolve(s.$anchorCell.pos),o?u.doc.resolve(o):void 0)),t(u)}return!0})(e,t)}function cP(e,t,n){let r=t.map.cellsInRect({left:0,top:0,right:"row"==e?t.map.width:1,bottom:"column"==e?t.map.height:1});for(let e=0;e<r.length;e++){let i=t.table.nodeAt(r[e]);if(i&&i.type!==n.header_cell)return!1}return!0}function c$(e,t){if((t=t||{useDeprecatedLogic:!1}).useDeprecatedLogic)return function(t,n){if(!cd(t))return!1;if(n){let r=ca(t.schema),i=cO(t),s=t.tr,o=i.map.cellsInRect("column"==e?{left:i.left,top:0,right:i.right,bottom:i.map.height}:"row"==e?{left:0,top:i.top,right:i.map.width,bottom:i.bottom}:i),a=o.map(e=>i.table.nodeAt(e));for(let e=0;e<o.length;e++)a[e].type==r.header_cell&&s.setNodeMarkup(i.tableStart+o[e],r.cell,a[e].attrs);if(0===s.steps.length)for(let e=0;e<o.length;e++)s.setNodeMarkup(i.tableStart+o[e],r.header_cell,a[e].attrs);n(s)}return!0};return function(t,n){if(!cd(t))return!1;if(n){let r=ca(t.schema),i=cO(t),s=t.tr,o=cP("row",i,r),a=cP("column",i,r),l=+("column"===e?!!o:"row"===e&&!!a),c="column"==e?{left:0,top:l,right:1,bottom:i.map.height}:"row"==e?{left:l,top:0,right:i.map.width,bottom:1}:i,d="column"==e?a?r.cell:r.header_cell:"row"==e?o?r.cell:r.header_cell:r.cell;i.map.cellsInRect(c).forEach(e=>{let t=e+i.tableStart,n=s.doc.nodeAt(t);n&&s.setNodeMarkup(t,d,n.attrs)}),n(s)}return!0}}c$("row",{useDeprecatedLogic:!0}),c$("column",{useDeprecatedLogic:!0});let cz=c$("cell",{useDeprecatedLogic:!0});function cB(e){return function(t,n){if(!cd(t))return!1;let r=function(e,t){if(t<0){let t=e.nodeBefore;if(t)return e.pos-t.nodeSize;for(let t=e.index(-1)-1,n=e.before();t>=0;t--){let r=e.node(-1).child(t),i=r.lastChild;if(i)return n-1-i.nodeSize;n-=r.nodeSize}}else{if(e.index()<e.parent.childCount-1)return e.pos+e.nodeAfter.nodeSize;let t=e.node(-1);for(let n=e.indexAfter(-1),r=e.after();n<t.childCount;n++){let e=t.child(n);if(e.childCount)return r+1;r+=e.nodeSize}}return null}(cu(t),e);if(null==r)return!1;if(n){let e=t.doc.resolve(r);n(t.tr.setSelection(od.between(e,e.node(0).resolve(e.pos+e.nodeAfter.nodeSize))).scrollIntoView())}return!0}}function cF(e,t){let n=e.selection;if(!(n instanceof cx))return!1;if(t){let r=e.tr,i=ca(e.schema).cell.createAndFill().content;n.forEachCell((e,t)=>{e.content.eq(i)||r.replace(r.mapping.map(t+1),r.mapping.map(t+e.nodeSize-1),new iX(i,0,0))}),r.docChanged&&t(r)}return!0}function cH(e,t){let n=e.createAndFill();return new or(n).replace(0,n.content.size,t).doc}function cU(e,t,n,r,i,s,o,a){if(0==o||o==t.height)return!1;let l=!1;for(let c=i;c<s;c++){let i=o*t.width+c,s=t.map[i];if(t.map[i-t.width]==s){l=!0;let i=n.nodeAt(s),{top:d,left:u}=t.findCell(s);e.setNodeMarkup(e.mapping.slice(a).map(s+r),null,{...i.attrs,rowspan:o-d}),e.insert(e.mapping.slice(a).map(t.positionAt(o,u,n)),i.type.createAndFill({...i.attrs,rowspan:d+i.attrs.rowspan-o})),c+=i.attrs.colspan-1}}return l}function cV(e,t,n,r,i,s,o,a){if(0==o||o==t.width)return!1;let l=!1;for(let c=i;c<s;c++){let i=c*t.width+o,s=t.map[i];if(t.map[i-1]==s){l=!0;let i=n.nodeAt(s),d=t.colCount(s),u=e.mapping.slice(a).map(s+r);e.setNodeMarkup(u,null,cf(i.attrs,o-d,i.attrs.colspan-(o-d))),e.insert(u+i.nodeSize,i.type.createAndFill(cf(i.attrs,0,o-d))),c+=i.attrs.rowspan-1}}return l}function cW(e,t,n,r,i){let s=n?e.doc.nodeAt(n-1):e.doc;if(!s)throw Error("No table found");let o=co.get(s),{top:a,left:l}=r,c=l+i.width,d=a+i.height,u=e.tr,p=0;function h(){if(!(s=n?u.doc.nodeAt(n-1):u.doc))throw Error("No table found");o=co.get(s),p=u.mapping.maps.length}(function(e,t,n,r,i,s){let o,a,l=ca(e.doc.type.schema);if(i>t.width)for(let s=0,c=0;s<t.height;s++){let d,u=n.child(s);c+=u.nodeSize;let p=[];d=null==u.lastChild||u.lastChild.type==l.cell?o||(o=l.cell.createAndFill()):a||(a=l.header_cell.createAndFill());for(let e=t.width;e<i;e++)p.push(d);e.insert(e.mapping.slice(0).map(c-1+r),p)}if(s>t.height){let c=[];for(let e=0,r=(t.height-1)*t.width;e<Math.max(t.width,i);e++){let i=!(e>=t.width)&&n.nodeAt(t.map[r+e]).type==l.header_cell;c.push(i?a||(a=l.header_cell.createAndFill()):o||(o=l.cell.createAndFill()))}let d=l.row.create(null,iW.from(c)),u=[];for(let e=t.height;e<s;e++)u.push(d);e.insert(e.mapping.slice(0).map(r+n.nodeSize-2),u)}return!!(o||a)})(u,o,s,n,c,d)&&h(),cU(u,o,s,n,l,c,a,p)&&h(),cU(u,o,s,n,l,c,d,p)&&h(),cV(u,o,s,n,a,d,l,p)&&h(),cV(u,o,s,n,a,d,c,p)&&h();for(let e=a;e<d;e++){let t=o.positionAt(e,l,s),r=o.positionAt(e,c,s);u.replace(u.mapping.slice(p).map(t+n),u.mapping.slice(p).map(r+n),new iX(i.rows[e-a],0,0))}h(),u.setSelection(new cx(u.doc.resolve(n+o.positionAt(a,l,s)),u.doc.resolve(n+o.positionAt(d-1,c-1,s)))),t(u)}let cq=cs({ArrowLeft:cG("horiz",-1),ArrowRight:cG("horiz",1),ArrowUp:cG("vert",-1),ArrowDown:cG("vert",1),"Shift-ArrowLeft":cJ("horiz",-1),"Shift-ArrowRight":cJ("horiz",1),"Shift-ArrowUp":cJ("vert",-1),"Shift-ArrowDown":cJ("vert",1),Backspace:cF,"Mod-Backspace":cF,Delete:cF,"Mod-Delete":cF});function cK(e,t,n){return!n.eq(e.selection)&&(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function cG(e,t){return(n,r,i)=>{if(!i)return!1;let s=n.selection;if(s instanceof cx)return cK(n,r,oo.near(s.$headCell,t));if("horiz"!=e&&!s.empty)return!1;let o=cQ(i,e,t);if(null==o)return!1;if("horiz"==e)return cK(n,r,oo.near(n.doc.resolve(s.head+t),t));{let i,s=n.doc.resolve(o),a=cm(s,e,t);return i=a?oo.near(a,1):t<0?oo.near(n.doc.resolve(s.before(-1)),-1):oo.near(n.doc.resolve(s.after(-1)),1),cK(n,r,i)}}}function cJ(e,t){return(n,r,i)=>{let s;if(!i)return!1;let o=n.selection;if(o instanceof cx)s=o;else{let r=cQ(i,e,t);if(null==r)return!1;s=new cx(n.doc.resolve(r))}let a=cm(s.$headCell,e,t);return!!a&&cK(n,r,new cx(s.$anchorCell,a))}}function cZ(e,t){let n=cc(e.state.doc.resolve(t));return!!n&&(e.dispatch(e.state.tr.setSelection(new cx(n))),!0)}function cX(e,t,n){if(!cd(e.state))return!1;let r=function(e){if(0===e.size)return null;let{content:t,openStart:n,openEnd:r}=e;for(;1==t.childCount&&(n>0&&r>0||"table"==t.child(0).type.spec.tableRole);)n--,r--,t=t.child(0).content;let i=t.child(0),s=i.type.spec.tableRole,o=i.type.schema,a=[];if("row"==s)for(let e=0;e<t.childCount;e++){let i=t.child(e).content,s=e?0:Math.max(0,n-1),l=e<t.childCount-1?0:Math.max(0,r-1);(s||l)&&(i=cH(ca(o).row,new iX(i,s,l)).content),a.push(i)}else{if("cell"!=s&&"header_cell"!=s)return null;a.push(n||r?cH(ca(o).row,new iX(t,n,r)).content:t)}return function(e,t){let n=[];for(let e=0;e<t.length;e++){let r=t[e];for(let t=r.childCount-1;t>=0;t--){let{rowspan:i,colspan:s}=r.child(t).attrs;for(let t=e;t<e+i;t++)n[t]=(n[t]||0)+s}}let r=0;for(let e=0;e<n.length;e++)r=Math.max(r,n[e]);for(let i=0;i<n.length;i++)if(i>=t.length&&t.push(iW.empty),n[i]<r){let s=ca(e).cell.createAndFill(),o=[];for(let e=n[i];e<r;e++)o.push(s);t[i]=t[i].append(iW.from(o))}return{height:t.length,width:r,rows:t}}(o,a)}(n),i=e.state.selection;if(i instanceof cx){r||(r={width:1,height:1,rows:[iW.from(cH(ca(e.state.schema).cell,n))]});let t=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),o=co.get(t).rectBetween(i.$anchorCell.pos-s,i.$headCell.pos-s);return r=function({width:e,height:t,rows:n},r,i){if(e!=r){let t=[],i=[];for(let e=0;e<n.length;e++){let s=n[e],o=[];for(let n=t[e]||0,i=0;n<r;i++){let a=s.child(i%s.childCount);n+a.attrs.colspan>r&&(a=a.type.createChecked(cf(a.attrs,a.attrs.colspan,n+a.attrs.colspan-r),a.content)),o.push(a),n+=a.attrs.colspan;for(let n=1;n<a.attrs.rowspan;n++)t[e+n]=(t[e+n]||0)+a.attrs.colspan}i.push(iW.from(o))}n=i,e=r}if(t!=i){let e=[];for(let r=0,s=0;r<i;r++,s++){let o=[],a=n[s%t];for(let e=0;e<a.childCount;e++){let t=a.child(e);r+t.attrs.rowspan>i&&(t=t.type.create({...t.attrs,rowspan:Math.max(1,i-t.attrs.rowspan)},t.content)),o.push(t)}e.push(iW.from(o))}n=e,t=i}return{width:e,height:t,rows:n}}(r,o.right-o.left,o.bottom-o.top),cW(e.state,e.dispatch,s,o,r),!0}if(!r)return!1;{let t=cu(e.state),n=t.start(-1);return cW(e.state,e.dispatch,n,co.get(t.node(-1)).findCell(t.pos-n),r),!0}}function cY(e,t){var n;let r;if(0!=t.button||t.ctrlKey||t.metaKey)return;let i=c0(e,t.target);if(t.shiftKey&&e.state.selection instanceof cx)s(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&i&&null!=(r=cc(e.state.selection.$anchor))&&(null==(n=c1(e,t))?void 0:n.pos)!=r.pos)s(r,t),t.preventDefault();else if(!i)return;function s(t,n){let r=c1(e,n),i=null==cl.getState(e.state);if(!r||!ch(t,r))if(!i)return;else r=t;let s=new cx(t,r);if(i||!e.state.selection.eq(s)){let n=e.state.tr.setSelection(s);i&&n.setMeta(cl,t.pos),e.dispatch(n)}}function o(){e.root.removeEventListener("mouseup",o),e.root.removeEventListener("dragstart",o),e.root.removeEventListener("mousemove",a),null!=cl.getState(e.state)&&e.dispatch(e.state.tr.setMeta(cl,-1))}function a(n){let r,a=cl.getState(e.state);if(null!=a)r=e.state.doc.resolve(a);else if(c0(e,n.target)!=i&&!(r=c1(e,t)))return o();r&&s(r,n)}e.root.addEventListener("mouseup",o),e.root.addEventListener("dragstart",o),e.root.addEventListener("mousemove",a)}function cQ(e,t,n){if(!(e.state.selection instanceof od))return null;let{$head:r}=e.state.selection;for(let i=r.depth-1;i>=0;i--){let s=r.node(i);if((n<0?r.index(i):r.indexAfter(i))!=(n<0?0:s.childCount))break;if("cell"==s.type.spec.tableRole||"header_cell"==s.type.spec.tableRole){let s=r.before(i),o="vert"==t?n>0?"down":"up":n>0?"right":"left";return e.endOfTextblock(o)?s:null}}return null}function c0(e,t){for(;t&&t!=e.dom;t=t.parentNode)if("TD"==t.nodeName||"TH"==t.nodeName)return t;return null}function c1(e,t){let n=e.posAtCoords({left:t.clientX,top:t.clientY});if(!n)return null;let{inside:r,pos:i}=n;return r>=0&&cc(e.state.doc.resolve(r))||cc(e.state.doc.resolve(i))}var c2=class{constructor(e,t){this.node=e,this.defaultCellMinWidth=t,this.dom=document.createElement("div"),this.dom.className="tableWrapper",this.table=this.dom.appendChild(document.createElement("table")),this.table.style.setProperty("--default-cell-min-width",`${t}px`),this.colgroup=this.table.appendChild(document.createElement("colgroup")),c5(e,this.colgroup,this.table,t),this.contentDOM=this.table.appendChild(document.createElement("tbody"))}update(e){return e.type==this.node.type&&(this.node=e,c5(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return"attributes"==e.type&&(e.target==this.table||this.colgroup.contains(e.target))}};function c5(e,t,n,r,i,s){let o=0,a=!0,l=t.firstChild,c=e.firstChild;if(c){for(let e=0,n=0;e<c.childCount;e++){let{colspan:d,colwidth:u}=c.child(e).attrs;for(let e=0;e<d;e++,n++){let c=i==n?s:u&&u[e],d=c?c+"px":"";if(o+=c||r,c||(a=!1),l)l.style.width!=d&&(l.style.width=d),l=l.nextSibling;else{let e=document.createElement("col");e.style.width=d,t.appendChild(e)}}}for(;l;){var d;let e=l.nextSibling;null==(d=l.parentNode)||d.removeChild(l),l=e}a?(n.style.width=o+"px",n.style.minWidth=""):(n.style.width="",n.style.minWidth=o+"px")}}let c3=new oE("tableColumnResizing");var c4=class e{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(t){let n=t.getMeta(c3);if(n&&null!=n.setHandle)return new e(n.setHandle,!1);if(n&&void 0!==n.setDragging)return new e(this.activeHandle,n.setDragging);if(this.activeHandle>-1&&t.docChanged){let n=t.mapping.map(this.activeHandle,-1);return cp(t.doc.resolve(n))||(n=-1),new e(n,this.dragging)}return this}};function c6(e,t,n,r){let i=e.posAtCoords({left:t.clientX+("right"==n?-r:r),top:t.clientY});if(!i)return -1;let{pos:s}=i,o=cc(e.state.doc.resolve(s));if(!o)return -1;if("right"==n)return o.pos;let a=co.get(o.node(-1)),l=o.start(-1),c=a.map.indexOf(o.pos-l);return c%a.width==0?-1:l+a.map[c-1]}function c9(e,t,n){let r=t.clientX-e.startX;return Math.max(n,e.startWidth+r)}function c7(e,t){e.dispatch(e.state.tr.setMeta(c3,{setHandle:t}))}function c8(e,t,n,r){let i=e.state.doc.resolve(t),s=i.node(-1),o=i.start(-1),a=co.get(s).colCount(i.pos-o)+i.nodeAfter.attrs.colspan-1,l=e.domAtPos(i.start(-1)).node;for(;l&&"TABLE"!=l.nodeName;)l=l.parentNode;l&&c5(s,l.firstChild,l,r,a,n)}var de=m,dt=e.i(3909);let dn=(e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function dr(e,t){let{$cursor:n}=e.selection;return n&&(t?t.endOfTextblock("backward",e):!(n.parentOffset>0))?n:null}let di=(e,t,n)=>{let r=dr(e,n);if(!r)return!1;let i=dc(r);if(!i){let n=r.blockRange(),i=n&&sq(n);return null!=i&&(t&&t(e.tr.lift(n,i).scrollIntoView()),!0)}let s=i.nodeBefore;if(dy(e,i,t,-1))return!0;if(0==r.parent.content.size&&(da(s,"end")||op.isSelectable(s)))for(let n=r.depth;;n--){let o=s2(e.doc,r.before(n),r.after(n),iX.empty);if(o&&o.slice.size<o.to-o.from){if(t){let n=e.tr.step(o);n.setSelection(da(s,"end")?oo.findFrom(n.doc.resolve(n.mapping.map(i.pos,-1)),-1):op.create(n.doc,i.pos-s.nodeSize)),t(n.scrollIntoView())}return!0}if(1==n||r.node(n-1).childCount>1)break}return!!s.isAtom&&i.depth==r.depth-1&&(t&&t(e.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0)};function ds(e,t,n){let r=t.nodeBefore,i=t.pos-1;for(;!r.isTextblock;i--){if(r.type.spec.isolating)return!1;let e=r.lastChild;if(!e)return!1;r=e}let s=t.nodeAfter,o=t.pos+1;for(;!s.isTextblock;o++){if(s.type.spec.isolating)return!1;let e=s.firstChild;if(!e)return!1;s=e}let a=s2(e.doc,i,o,iX.empty);if(!a||a.from!=i||a instanceof sH&&a.slice.size>=o-i)return!1;if(n){let t=e.tr.step(a);t.setSelection(od.create(t.doc,i)),n(t.scrollIntoView())}return!0}function da(e,t,n=!1){for(let r=e;r;r="start"==t?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(n&&1!=r.childCount)break}return!1}let dl=(e,t,n)=>{let{$head:r,empty:i}=e.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("backward",e):r.parentOffset>0)return!1;s=dc(r)}let o=s&&s.nodeBefore;return!!o&&!!op.isSelectable(o)&&(t&&t(e.tr.setSelection(op.create(e.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function dc(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}function dd(e,t){let{$cursor:n}=e.selection;return n&&(t?t.endOfTextblock("forward",e):!(n.parentOffset<n.parent.content.size))?n:null}let du=(e,t,n)=>{let r=dd(e,n);if(!r)return!1;let i=dh(r);if(!i)return!1;let s=i.nodeAfter;if(dy(e,i,t,1))return!0;if(0==r.parent.content.size&&(da(s,"start")||op.isSelectable(s))){let n=s2(e.doc,r.before(),r.after(),iX.empty);if(n&&n.slice.size<n.to-n.from){if(t){let r=e.tr.step(n);r.setSelection(da(s,"start")?oo.findFrom(r.doc.resolve(r.mapping.map(i.pos)),1):op.create(r.doc,r.mapping.map(i.pos))),t(r.scrollIntoView())}return!0}}return!!s.isAtom&&i.depth==r.depth-1&&(t&&t(e.tr.delete(i.pos,i.pos+s.nodeSize).scrollIntoView()),!0)},dp=(e,t,n)=>{let{$head:r,empty:i}=e.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(n?!n.endOfTextblock("forward",e):r.parentOffset<r.parent.content.size)return!1;s=dh(r)}let o=s&&s.nodeAfter;return!!o&&!!op.isSelectable(o)&&(t&&t(e.tr.setSelection(op.create(e.doc,s.pos)).scrollIntoView()),!0)};function dh(e){if(!e.parent.type.spec.isolating)for(let t=e.depth-1;t>=0;t--){let n=e.node(t);if(e.index(t)+1<n.childCount)return e.doc.resolve(e.after(t+1));if(n.type.spec.isolating)break}return null}let dm=(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 df(e){for(let t=0;t<e.edgeCount;t++){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}let dg=(e,t)=>{let{$head:n,$anchor:r}=e.selection;if(!n.parent.type.spec.code||!n.sameParent(r))return!1;let i=n.node(-1),s=n.indexAfter(-1),o=df(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(t){let r=n.after(),i=e.tr.replaceWith(r,r,o.createAndFill());i.setSelection(oo.near(i.doc.resolve(r),1)),t(i.scrollIntoView())}return!0},dx=(e,t)=>{let n=e.selection,{$from:r,$to:i}=n;if(n instanceof om||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=df(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(t){let n=(!r.parentOffset&&i.index()<i.parent.childCount?r:i).pos,o=e.tr.insert(n,s.createAndFill());o.setSelection(od.create(o.doc,n+1)),t(o.scrollIntoView())}return!0},db=(e,t)=>{let{$cursor:n}=e.selection;if(!n||n.parent.content.size)return!1;if(n.depth>1&&n.after()!=n.end(-1)){let r=n.before();if(sX(e.doc,r))return t&&t(e.tr.split(r).scrollIntoView()),!0}let r=n.blockRange(),i=r&&sq(r);return null!=i&&(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)};function dy(e,t,n,r){let i,s,o,a=t.nodeBefore,l=t.nodeAfter,c,d,u=a.type.spec.isolating||l.type.spec.isolating;if(!u&&(i=t.nodeBefore,s=t.nodeAfter,o=t.index(),i&&s&&i.type.compatibleContent(s.type)&&(!i.content.size&&t.parent.canReplace(o-1,o)?(n&&n(e.tr.delete(t.pos-i.nodeSize,t.pos).scrollIntoView()),!0):!!t.parent.canReplace(o,o+1)&&!!(s.isTextblock||sY(e.doc,t.pos))&&(n&&n(e.tr.join(t.pos).scrollIntoView()),!0))))return!0;let p=!u&&t.parent.canReplace(t.index(),t.index()+1);if(p&&(c=(d=a.contentMatchAt(a.childCount)).findWrapping(l.type))&&d.matchType(c[0]||l.type).validEnd){if(n){let r=t.pos+l.nodeSize,i=iW.empty;for(let e=c.length-1;e>=0;e--)i=iW.from(c[e].create(null,i));i=iW.from(a.copy(i));let s=e.tr.step(new sU(t.pos-1,r,t.pos,r,new iX(i,1,0),c.length,!0)),o=s.doc.resolve(r+2*c.length);o.nodeAfter&&o.nodeAfter.type==a.type&&sY(s.doc,o.pos)&&s.join(o.pos),n(s.scrollIntoView())}return!0}let h=l.type.spec.isolating||r>0&&u?null:oo.findFrom(t,1),m=h&&h.$from.blockRange(h.$to),f=m&&sq(m);if(null!=f&&f>=t.depth)return n&&n(e.tr.lift(m,f).scrollIntoView()),!0;if(p&&da(l,"start",!0)&&da(a,"end")){let r=a,i=[];for(;i.push(r),!r.isTextblock;)r=r.lastChild;let s=l,o=1;for(;!s.isTextblock;s=s.firstChild)o++;if(r.canReplace(r.childCount,r.childCount,s.content)){if(n){let r=iW.empty;for(let e=i.length-1;e>=0;e--)r=iW.from(i[e].copy(r));n(e.tr.step(new sU(t.pos-i.length,t.pos+l.nodeSize,t.pos+o,t.pos+l.nodeSize-o,new iX(r,i.length,0),0,!0)).scrollIntoView())}return!0}}return!1}function dv(e){return function(t,n){let r=t.selection,i=e<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return!!i.node(s).isTextblock&&(n&&n(t.tr.setSelection(od.create(t.doc,e<0?i.start(s):i.end(s)))),!0)}}let dw=dv(-1),dk=dv(1);function dN(e,t=null){return function(n,r){let i=!1;for(let r=0;r<n.selection.ranges.length&&!i;r++){let{$from:{pos:s},$to:{pos:o}}=n.selection.ranges[r];n.doc.nodesBetween(s,o,(r,s)=>{if(i)return!1;if(!(!r.isTextblock||r.hasMarkup(e,t)))if(r.type==e)i=!0;else{let t=n.doc.resolve(s),r=t.index();i=t.parent.canReplaceWith(r,r+1,e)}})}if(!i)return!1;if(r){let i=n.tr;for(let r=0;r<n.selection.ranges.length;r++){let{$from:{pos:s},$to:{pos:o}}=n.selection.ranges[r];i.setBlockType(s,o,e,t)}r(i.scrollIntoView())}return!0}}function dS(...e){return function(t,n,r){for(let i=0;i<e.length;i++)if(e[i](t,n,r))return!0;return!1}}let dC=dS(dn,di,dl),dj=dS(dn,du,dp),dE={Enter:dS(dm,dx,db,(e,t)=>{let{$from:n,$to:r}=e.selection;if(e.selection instanceof op&&e.selection.node.isBlock)return!!n.parentOffset&&!!sX(e.doc,n.pos)&&(t&&t(e.tr.split(n.pos).scrollIntoView()),!0);if(!n.depth)return!1;let i=[],s,o,a=!1,l=!1;for(let e=n.depth;;e--){if(n.node(e).isBlock){let t;a=n.end(e)==n.pos+(n.depth-e),l=n.start(e)==n.pos-(n.depth-e),o=df(n.node(e-1).contentMatchAt(n.indexAfter(e-1)));i.unshift(t||(a&&o?{type:o}:null)),s=e;break}if(1==e)return!1;i.unshift(null)}let c=e.tr;(e.selection instanceof od||e.selection instanceof om)&&c.deleteSelection();let d=c.mapping.map(n.pos),u=sX(c.doc,d,i.length,i);if(u||(i[0]=o?{type:o}:null,u=sX(c.doc,d,i.length,i)),!u)return!1;if(c.split(d,i.length,i),!a&&l&&n.node(s).type!=o){let e=c.mapping.map(n.before(s)),t=c.doc.resolve(e);o&&n.node(s-1).canReplaceWith(t.index(),t.index()+1,o)&&c.setNodeMarkup(c.mapping.map(n.before(s)),o)}return t&&t(c.scrollIntoView()),!0}),"Mod-Enter":dg,Backspace:dC,"Mod-Backspace":dC,"Shift-Backspace":dC,Delete:dj,"Mod-Delete":dj,"Mod-a":(e,t)=>(t&&t(e.tr.setSelection(new om(e.doc))),!0)},dM={"Ctrl-h":dE.Backspace,"Alt-Backspace":dE["Mod-Backspace"],"Ctrl-d":dE.Delete,"Ctrl-Alt-Backspace":dE["Mod-Delete"],"Alt-Delete":dE["Mod-Delete"],"Alt-d":dE["Mod-Delete"],"Ctrl-a":dw,"Ctrl-e":dk};for(let e in dE)dM[e]=dE[e];"u">typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):"u">typeof os&&os.platform&&os.platform();var dA=Object.defineProperty,dT=(e,t)=>{for(var n in t)dA(e,n,{get:t[n],enumerable:!0})};function dO(e){let{state:t,transaction:n}=e,{selection:r}=n,{doc:i}=n,{storedMarks:s}=n;return{...t,apply:t.apply.bind(t),applyTransaction:t.applyTransaction.bind(t),plugins:t.plugins,schema:t.schema,reconfigure:t.reconfigure.bind(t),toJSON:t.toJSON.bind(t),get storedMarks(){return s},get selection(){return r},get doc(){return i},get tr(){return r=n.selection,i=n.doc,s=n.storedMarks,n}}}var d_=class{constructor(e){this.editor=e.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=e.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){let{rawCommands:e,editor:t,state:n}=this,{view:r}=t,{tr:i}=n,s=this.buildProps(i);return Object.fromEntries(Object.entries(e).map(([e,t])=>[e,(...e)=>{let n=t(...e)(s);return i.getMeta("preventDispatch")||this.hasCustomState||r.dispatch(i),n}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:s}=r,o=[],a=!!e,l=e||i.tr,c=()=>(a||!t||l.getMeta("preventDispatch")||this.hasCustomState||s.dispatch(l),o.every(e=>!0===e)),d={...Object.fromEntries(Object.entries(n).map(([e,n])=>[e,(...e)=>{let r=this.buildProps(l,t),i=n(...e)(r);return o.push(i),d}])),run:c};return d}createCan(e){let{rawCommands:t,state:n}=this,r=e||n.tr,i=this.buildProps(r,!1);return{...Object.fromEntries(Object.entries(t).map(([e,t])=>[e,(...e)=>t(...e)({...i,dispatch:void 0})])),chain:()=>this.createChain(r,!1)}}buildProps(e,t=!0){let{rawCommands:n,editor:r,state:i}=this,{view:s}=r,o={tr:e,editor:r,view:s,state:dO({state:i,transaction:e}),dispatch:t?()=>void 0:void 0,chain:()=>this.createChain(e,t),can:()=>this.createCan(e),get commands(){return Object.fromEntries(Object.entries(n).map(([e,t])=>[e,(...e)=>t(...e)(o)]))}};return o}},dD={};dT(dD,{blur:()=>dR,clearContent:()=>dI,clearNodes:()=>dL,command:()=>dP,createParagraphNear:()=>d$,cut:()=>dz,deleteCurrentNode:()=>dB,deleteNode:()=>dH,deleteRange:()=>dU,deleteSelection:()=>dW,enter:()=>dq,exitCode:()=>dK,extendMarkRange:()=>d0,first:()=>d1,focus:()=>d9,forEach:()=>d7,insertContent:()=>d8,insertContentAt:()=>ur,joinBackward:()=>uo,joinDown:()=>us,joinForward:()=>ua,joinItemBackward:()=>ul,joinItemForward:()=>uc,joinTextblockBackward:()=>ud,joinTextblockForward:()=>uu,joinUp:()=>ui,keyboardShortcut:()=>uh,lift:()=>uf,liftEmptyBlock:()=>ug,liftListItem:()=>ux,newlineInCode:()=>ub,resetAttributes:()=>uw,scrollIntoView:()=>uk,selectAll:()=>uN,selectNodeBackward:()=>uS,selectNodeForward:()=>uC,selectParentNode:()=>uj,selectTextblockEnd:()=>uE,selectTextblockStart:()=>uM,setContent:()=>uT,setMark:()=>pi,setMeta:()=>ps,setNode:()=>po,setNodeSelection:()=>pa,setTextDirection:()=>pl,setTextSelection:()=>pc,sinkListItem:()=>pd,splitBlock:()=>pp,splitListItem:()=>ph,toggleList:()=>pg,toggleMark:()=>px,toggleNode:()=>pb,toggleWrap:()=>py,undoInputRule:()=>pv,unsetAllMarks:()=>pw,unsetMark:()=>pk,unsetTextDirection:()=>pN,updateAttributes:()=>pS,wrapIn:()=>pC,wrapInList:()=>pj});var dR=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),null==(n=null==window?void 0:window.getSelection())||n.removeAllRanges())}),!0),dI=(e=!0)=>({commands:t})=>t.setContent("",{emitUpdate:e}),dL=()=>({state:e,tr:t,dispatch:n})=>{let{selection:r}=t,{ranges:i}=r;return!n||(i.forEach(({$from:n,$to:r})=>{e.doc.nodesBetween(n.pos,r.pos,(e,n)=>{if(e.type.isText)return;let{doc:r,mapping:i}=t,s=r.resolve(i.map(n)),o=r.resolve(i.map(n+e.nodeSize)),a=s.blockRange(o);if(!a)return;let l=sq(a);if(e.type.isTextblock){let{defaultType:e}=s.parent.contentMatchAt(s.index());t.setNodeMarkup(a.start,e)}(l||0===l)&&t.lift(a,l)})}),!0)},dP=e=>t=>e(t),d$=()=>({state:e,dispatch:t})=>dx(e,t),dz=(e,t)=>({editor:n,tr:r})=>{let{state:i}=n,s=i.doc.slice(e.from,e.to);r.deleteRange(e.from,e.to);let o=r.mapping.map(t);return r.insert(o,s.content),r.setSelection(new od(r.doc.resolve(Math.max(o-1,0)))),!0},dB=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,r=n.$anchor.node();if(r.content.size>0)return!1;let i=e.selection.$anchor;for(let n=i.depth;n>0;n-=1)if(i.node(n).type===r.type){if(t){let t=i.before(n),r=i.after(n);e.delete(t,r).scrollIntoView()}return!0}return!1};function dF(e,t){if("string"==typeof e){if(!t.nodes[e])throw Error(`There is no node type named '${e}'. Maybe you forgot to add the extension?`);return t.nodes[e]}return e}var dH=e=>({tr:t,state:n,dispatch:r})=>{let i=dF(e,n.schema),s=t.selection.$anchor;for(let e=s.depth;e>0;e-=1)if(s.node(e).type===i){if(r){let n=s.before(e),r=s.after(e);t.delete(n,r).scrollIntoView()}return!0}return!1},dU=e=>({tr:t,dispatch:n})=>{let{from:r,to:i}=e;return n&&t.delete(r,i),!0},dV=(e,t,n)=>{var r;return!e.parent.isInline||"left"===n&&e.pos>e.start()||"right"===n&&e.pos<e.end()?e.pos:(r=t.nodes[e.parent.type.name].spec).content&&/^text(\*|\+)/.test(r.content)?"left"===n?e.start()-1:e.end()+1:e.pos},dW=()=>({state:e,dispatch:t})=>{var n;let{$from:r,$to:i}=e.selection;if(e.selection.empty)return!1;let{from:s,to:o}={from:dV(r,n=e.schema,"left"),to:dV(i,n,"right")};return t&&(e.tr.deleteRange(s,o).scrollIntoView(),t(e.tr)),!0},dq=()=>({commands:e})=>e.keyboardShortcut("Enter"),dK=()=>({state:e,dispatch:t})=>dg(e,t);function dG(e){return"[object RegExp]"===Object.prototype.toString.call(e)}function dJ(e,t,n={strict:!0}){let r=Object.keys(t);return!r.length||r.every(r=>n.strict?t[r]===e[r]:dG(t[r])?t[r].test(e[r]):t[r]===e[r])}function dZ(e,t,n={}){return e.find(e=>e.type===t&&dJ(Object.fromEntries(Object.keys(n).map(t=>[t,e.attrs[t]])),n))}function dX(e,t,n={}){return!!dZ(e,t,n)}function dY(e,t,n){if(!e||!t)return;let r=e.parent.childAfter(e.parentOffset);if(r.node&&r.node.marks.some(e=>e.type===t)||(r=e.parent.childBefore(e.parentOffset)),!r.node||!r.node.marks.some(e=>e.type===t))return;if(!n){let e=r.node.marks.find(e=>e.type===t);e&&(n=e.attrs)}if(!dZ([...r.node.marks],t,n))return;let i=r.index,s=e.start()+r.offset,o=i+1,a=s+r.node.nodeSize;for(;i>0&&dX([...e.parent.child(i-1).marks],t,n);)i-=1,s-=e.parent.child(i).nodeSize;for(;o<e.parent.childCount&&dX([...e.parent.child(o).marks],t,n);)a+=e.parent.child(o).nodeSize,o+=1;return{from:s,to:a}}function dQ(e,t){if("string"==typeof e){if(!t.marks[e])throw Error(`There is no mark type named '${e}'. Maybe you forgot to add the extension?`);return t.marks[e]}return e}var d0=(e,t)=>({tr:n,state:r,dispatch:i})=>{let s=dQ(e,r.schema),{doc:o,selection:a}=n,{$from:l,from:c,to:d}=a;if(i){let e=dY(l,s,t);if(e&&e.from<=c&&e.to>=d){let t=od.create(o,e.from,e.to);n.setSelection(t)}}return!0},d1=e=>t=>{let n="function"==typeof e?e(t):e;for(let e=0;e<n.length;e+=1)if(n[e](t))return!0;return!1};function d2(e){return e instanceof od}function d5(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function d3(e,t=null){if(!t)return null;let n=oo.atStart(e),r=oo.atEnd(e);if("start"===t||!0===t)return n;if("end"===t)return r;let i=n.from,s=r.to;return"all"===t?od.create(e,d5(0,i,s),d5(e.content.size,i,s)):od.create(e,d5(t,i,s),d5(t,i,s))}function d4(){return"Android"===navigator.platform||/android/i.test(navigator.userAgent)}function d6(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}var d9=(e=null,t={})=>({editor:n,view:r,tr:i,dispatch:s})=>{t={scrollIntoView:!0,...t};let o=()=>{(d6()||d4())&&r.dom.focus(),"u">typeof navigator&&/^((?!chrome|android).)*safari/i.test(navigator.userAgent)&&!d6()&&!d4()&&r.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{!n.isDestroyed&&(r.focus(),(null==t?void 0:t.scrollIntoView)&&n.commands.scrollIntoView())})};try{if(r.hasFocus()&&null===e||!1===e)return!0}catch{return!1}if(s&&null===e&&!d2(n.state.selection))return o(),!0;let a=d3(i.doc,e)||n.state.selection,l=n.state.selection.eq(a);return s&&(l||i.setSelection(a),l&&i.storedMarks&&i.setStoredMarks(i.storedMarks),o()),!0},d7=(e,t)=>n=>e.every((e,r)=>t(e,{...n,index:r})),d8=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),ue=e=>{let t=e.childNodes;for(let n=t.length-1;n>=0;n-=1){let r=t[n];3===r.nodeType&&r.nodeValue&&/^(\n\s\s|\n)$/.test(r.nodeValue)?e.removeChild(r):1===r.nodeType&&ue(r)}return e};function ut(e){if("u"<typeof window)throw Error("[tiptap error]: there is no window object available, so this function cannot be used");let t=`<body>${e}</body>`;return ue(new window.DOMParser().parseFromString(t,"text/html").body)}function un(e,t,n){if(e instanceof se||e instanceof iW)return e;n={slice:!0,parseOptions:{},...n};let r="object"==typeof e&&null!==e,i="string"==typeof e;if(r)try{if(Array.isArray(e)&&e.length>0)return iW.fromArray(e.map(e=>t.nodeFromJSON(e)));let r=t.nodeFromJSON(e);return n.errorOnInvalidContent&&r.check(),r}catch(r){if(n.errorOnInvalidContent)throw Error("[tiptap error]: Invalid JSON content",{cause:r});return console.warn("[tiptap warn]: Invalid content.","Passed value:",e,"Error:",r),un("",t,n)}if(i){if(n.errorOnInvalidContent){let r=!1,i="",s=new sf({topNode:t.spec.topNode,marks:t.spec.marks,nodes:t.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:e=>(r=!0,i="string"==typeof e?e:e.outerHTML,null)}]}})});if(n.slice?sx.fromSchema(s).parseSlice(ut(e),n.parseOptions):sx.fromSchema(s).parse(ut(e),n.parseOptions),n.errorOnInvalidContent&&r)throw Error("[tiptap error]: Invalid HTML content",{cause:Error(`Invalid element found: ${i}`)})}let r=sx.fromSchema(t);return n.slice?r.parseSlice(ut(e),n.parseOptions).content:r.parse(ut(e),n.parseOptions)}return un("",t,n)}var ur=(e,t,n)=>({tr:r,dispatch:i,editor:s})=>{var o;if(i){let i,a;n={parseOptions:s.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...n};let l=e=>{s.emit("contentError",{editor:s,error:e,disableCollaboration:()=>{"collaboration"in s.storage&&"object"==typeof s.storage.collaboration&&s.storage.collaboration&&(s.storage.collaboration.isDisabled=!0)}})},c={preserveWhitespace:"full",...n.parseOptions};if(!n.errorOnInvalidContent&&!s.options.enableContentCheck&&s.options.emitContentError)try{un(t,s.schema,{parseOptions:c,errorOnInvalidContent:!0})}catch(e){l(e)}try{i=un(t,s.schema,{parseOptions:c,errorOnInvalidContent:null!=(o=n.errorOnInvalidContent)?o:s.options.enableContentCheck})}catch(e){return l(e),!1}let{from:d,to:u}="number"==typeof e?{from:e,to:e}:{from:e.from,to:e.to},p=!0,h=!0;if((!("type"in i)?i:[i]).forEach(e=>{e.check(),p=!!p&&e.isText&&0===e.marks.length,h=!!h&&e.isBlock}),d===u&&h){let{parent:e}=r.doc.resolve(d);!e.isTextblock||e.type.spec.code||e.childCount||(d-=1,u+=1)}if(p){if(Array.isArray(t))a=t.map(e=>e.text||"").join("");else if(t instanceof iW){let e="";t.forEach(t=>{t.text&&(e+=t.text)}),a=e}else a="object"==typeof t&&t&&t.text?t.text:t;r.insertText(a,d,u)}else{a=i;let e=r.doc.resolve(d),t=e.node(),n=0===e.parentOffset,s=t.isText||t.isTextblock,o=t.content.size>0;n&&s&&o&&h&&(d=Math.max(0,d-1)),r.replaceWith(d,u,a)}n.updateSelection&&function(e,t){let n=e.steps.length-1;if(n<t)return;let r=e.steps[n];if(!(r instanceof sH||r instanceof sU))return;let i=e.mapping.maps[n],s=0;i.forEach((e,t,n,r)=>{0===s&&(s=r)}),e.setSelection(oo.near(e.doc.resolve(s),-1))}(r,r.steps.length-1),n.applyInputRules&&r.setMeta("applyInputRules",{from:d,text:a}),n.applyPasteRules&&r.setMeta("applyPasteRules",{from:d,text:a})}return!0},ui=()=>({state:e,dispatch:t})=>((e,t)=>{let n=e.selection,r=n instanceof op,i;if(r){if(n.node.isTextblock||!sY(e.doc,n.from))return!1;i=n.from}else if(null==(i=s0(e.doc,n.from,-1)))return!1;if(t){let n=e.tr.join(i);r&&n.setSelection(op.create(n.doc,i-e.doc.resolve(i).nodeBefore.nodeSize)),t(n.scrollIntoView())}return!0})(e,t),us=()=>({state:e,dispatch:t})=>((e,t)=>{let n=e.selection,r;if(n instanceof op){if(n.node.isTextblock||!sY(e.doc,n.to))return!1;r=n.to}else if(null==(r=s0(e.doc,n.to,1)))return!1;return t&&t(e.tr.join(r).scrollIntoView()),!0})(e,t),uo=()=>({state:e,dispatch:t})=>di(e,t),ua=()=>({state:e,dispatch:t})=>du(e,t),ul=()=>({state:e,dispatch:t,tr:n})=>{try{let r=s0(e.doc,e.selection.$from.pos,-1);if(null==r)return!1;return n.join(r,2),t&&t(n),!0}catch{return!1}},uc=()=>({state:e,dispatch:t,tr:n})=>{try{let r=s0(e.doc,e.selection.$from.pos,1);if(null==r)return!1;return n.join(r,2),t&&t(n),!0}catch{return!1}},ud=()=>({state:e,dispatch:t})=>((e,t,n)=>{let r=dr(e,n);if(!r)return!1;let i=dc(r);return!!i&&ds(e,i,t)})(e,t),uu=()=>({state:e,dispatch:t})=>((e,t,n)=>{let r=dd(e,n);if(!r)return!1;let i=dh(r);return!!i&&ds(e,i,t)})(e,t);function up(){return"u">typeof navigator&&/Mac/.test(navigator.platform)}var uh=e=>({editor:t,view:n,tr:r,dispatch:i})=>{let s=(function(e){let t,n,r,i,s=e.split(/-(?!$)/),o=s[s.length-1];"Space"===o&&(o=" ");for(let e=0;e<s.length-1;e+=1){let o=s[e];if(/^(cmd|meta|m)$/i.test(o))i=!0;else if(/^a(lt)?$/i.test(o))t=!0;else if(/^(c|ctrl|control)$/i.test(o))n=!0;else if(/^s(hift)?$/i.test(o))r=!0;else if(/^mod$/i.test(o))d6()||up()?i=!0:n=!0;else throw Error(`Unrecognized modifier name: ${o}`)}return t&&(o=`Alt-${o}`),n&&(o=`Ctrl-${o}`),i&&(o=`Meta-${o}`),r&&(o=`Shift-${o}`),o})(e).split(/-(?!$)/),o=s.find(e=>!["Alt","Ctrl","Meta","Shift"].includes(e)),a=new KeyboardEvent("keydown",{key:"Space"===o?" ":o,altKey:s.includes("Alt"),ctrlKey:s.includes("Ctrl"),metaKey:s.includes("Meta"),shiftKey:s.includes("Shift"),bubbles:!0,cancelable:!0}),l=t.captureTransaction(()=>{n.someProp("handleKeyDown",e=>e(n,a))});return null==l||l.steps.forEach(e=>{let t=e.map(r.mapping);t&&i&&r.maybeStep(t)}),!0};function um(e,t,n={}){let{from:r,to:i,empty:s}=e.selection,o=t?dF(t,e.schema):null,a=[];e.doc.nodesBetween(r,i,(e,t)=>{if(e.isText)return;let n=Math.max(r,t),s=Math.min(i,t+e.nodeSize);a.push({node:e,from:n,to:s})});let l=i-r,c=a.filter(e=>!o||o.name===e.node.type.name).filter(e=>dJ(e.node.attrs,n,{strict:!1}));return s?!!c.length:c.reduce((e,t)=>e+t.to-t.from,0)>=l}var uf=(e,t={})=>({state:n,dispatch:r})=>{let i=dF(e,n.schema);return!!um(n,i,t)&&((e,t)=>{let{$from:n,$to:r}=e.selection,i=n.blockRange(r),s=i&&sq(i);return null!=s&&(t&&t(e.tr.lift(i,s).scrollIntoView()),!0)})(n,r)},ug=()=>({state:e,dispatch:t})=>db(e,t),ux=e=>({state:t,dispatch:n})=>{var r;return(r=dF(e,t.schema),function(e,t){let{$from:n,$to:i}=e.selection,s=n.blockRange(i,e=>e.childCount>0&&e.firstChild.type==r);return!!s&&(!t||(n.node(s.depth-1).type==r?function(e,t,n,r){let i=e.tr,s=r.end,o=r.$to.end(r.depth);s<o&&(i.step(new sU(s-1,o,s,o,new iX(iW.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new i7(i.doc.resolve(r.$from.pos),i.doc.resolve(o),r.depth));let a=sq(r);if(null==a)return!1;i.lift(r,a);let l=i.doc.resolve(i.mapping.map(s,-1)-1);return sY(i.doc,l.pos)&&l.nodeBefore.type==l.nodeAfter.type&&i.join(l.pos),t(i.scrollIntoView()),!0}(e,t,r,s):function(e,t,n){let r=e.tr,i=n.parent;for(let e=n.end,t=n.endIndex-1,s=n.startIndex;t>s;t--)e-=i.child(t).nodeSize,r.delete(e-1,e+1);let s=r.doc.resolve(n.start),o=s.nodeAfter;if(r.mapping.map(n.end)!=n.start+s.nodeAfter.nodeSize)return!1;let a=0==n.startIndex,l=n.endIndex==i.childCount,c=s.node(-1),d=s.index(-1);if(!c.canReplace(d+ +!a,d+1,o.content.append(l?iW.empty:iW.from(i))))return!1;let u=s.pos,p=u+o.nodeSize;return r.step(new sU(u-!!a,p+ +!!l,u+1,p-1,new iX((a?iW.empty:iW.from(i.copy(iW.empty))).append(l?iW.empty:iW.from(i.copy(iW.empty))),+!a,+!l),+!a)),t(r.scrollIntoView()),!0}(e,t,s)))})(t,n)},ub=()=>({state:e,dispatch:t})=>dm(e,t);function uy(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function uv(e,t){let n="string"==typeof t?[t]:t;return Object.keys(e).reduce((t,r)=>(n.includes(r)||(t[r]=e[r]),t),{})}var uw=(e,t)=>({tr:n,state:r,dispatch:i})=>{let s=null,o=null,a=uy("string"==typeof e?e:e.name,r.schema);if(!a)return!1;"node"===a&&(s=dF(e,r.schema)),"mark"===a&&(o=dQ(e,r.schema));let l=!1;return n.selection.ranges.forEach(e=>{r.doc.nodesBetween(e.$from.pos,e.$to.pos,(e,r)=>{s&&s===e.type&&(l=!0,i&&n.setNodeMarkup(r,void 0,uv(e.attrs,t))),o&&e.marks.length&&e.marks.forEach(s=>{o===s.type&&(l=!0,i&&n.addMark(r,r+e.nodeSize,o.create(uv(s.attrs,t))))})})}),l},uk=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),uN=()=>({tr:e,dispatch:t})=>{if(t){let t=new om(e.doc);e.setSelection(t)}return!0},uS=()=>({state:e,dispatch:t})=>dl(e,t),uC=()=>({state:e,dispatch:t})=>dp(e,t),uj=()=>({state:e,dispatch:t})=>((e,t)=>{let{$from:n,to:r}=e.selection,i,s=n.sharedDepth(r);return 0!=s&&(i=n.before(s),t&&t(e.tr.setSelection(op.create(e.doc,i))),!0)})(e,t),uE=()=>({state:e,dispatch:t})=>dk(e,t),uM=()=>({state:e,dispatch:t})=>dw(e,t);function uA(e,t,n={},r={}){return un(e,t,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}var uT=(e,{errorOnInvalidContent:t,emitUpdate:n=!0,parseOptions:r={}}={})=>({editor:i,tr:s,dispatch:o,commands:a})=>{let{doc:l}=s;if("full"!==r.preserveWhitespace){let a=uA(e,i.schema,r,{errorOnInvalidContent:null!=t?t:i.options.enableContentCheck});return o&&s.replaceWith(0,l.content.size,a).setMeta("preventUpdate",!n),!0}return o&&s.setMeta("preventUpdate",!n),a.insertContentAt({from:0,to:l.content.size},e,{parseOptions:r,errorOnInvalidContent:null!=t?t:i.options.enableContentCheck})};function uO(e,t){let n=dQ(t,e.schema),{from:r,to:i,empty:s}=e.selection,o=[];s?(e.storedMarks&&o.push(...e.storedMarks),o.push(...e.selection.$head.marks())):e.doc.nodesBetween(r,i,e=>{o.push(...e.marks)});let a=o.find(e=>e.type.name===n.name);return a?{...a.attrs}:{}}function u_(e,t){let n=new or(e);return t.forEach(e=>{e.steps.forEach(e=>{n.step(e)})}),n}function uD(e,t){let n=[];return e.descendants((e,r)=>{t(e)&&n.push({node:e,pos:r})}),n}function uR(e,t){for(let n=e.depth;n>0;n-=1){let r=e.node(n);if(t(r))return{pos:n>0?e.before(n):0,start:e.start(n),depth:n,node:r}}}function uI(e){return t=>uR(t.$from,e)}function uL(e,t,n){return void 0===e.config[t]&&e.parent?uL(e.parent,t,n):"function"==typeof e.config[t]?e.config[t].bind({...n,parent:e.parent?uL(e.parent,t,n):null}):e.config[t]}function uP(e){return e.map(e=>{let t={name:e.name,options:e.options,storage:e.storage},n=uL(e,"addExtensions",t);return n?[e,...uP(n())]:e}).flat(10)}function u$(e,t){let n=sj.fromSchema(t).serializeFragment(e),r=document.implementation.createHTMLDocument().createElement("div");return r.appendChild(n),r.innerHTML}function uz(e){return"function"==typeof e}function uB(e,t,...n){return uz(e)?t?e.bind(t)(...n):e(...n):e}function uF(e){let t=e.filter(e=>"extension"===e.type);return{baseExtensions:t,nodeExtensions:e.filter(e=>"node"===e.type),markExtensions:e.filter(e=>"mark"===e.type)}}function uH(e){let t=[],{nodeExtensions:n,markExtensions:r}=uF(e),i=[...n,...r],s={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1},o=n.filter(e=>"text"!==e.name).map(e=>e.name),a=r.map(e=>e.name),l=[...o,...a];return e.forEach(e=>{let n={name:e.name,options:e.options,storage:e.storage,extensions:i},r=uL(e,"addGlobalAttributes",n);r&&r().forEach(e=>{(Array.isArray(e.types)?e.types:"*"===e.types?l:"nodes"===e.types?o:"marks"===e.types?a:[]).forEach(n=>{Object.entries(e.attributes).forEach(([e,r])=>{t.push({type:n,name:e,attribute:{...s,...r}})})})})}),i.forEach(e=>{let n={name:e.name,options:e.options,storage:e.storage},r=uL(e,"addAttributes",n);r&&Object.entries(r()).forEach(([n,r])=>{let i={...s,...r};"function"==typeof(null==i?void 0:i.default)&&(i.default=i.default()),(null==i?void 0:i.isRequired)&&(null==i?void 0:i.default)===void 0&&delete i.default,t.push({type:e.name,name:n,attribute:i})})}),t}function uU(e){let t=[],n=function(e){let t=[],n="",r=!1,i=!1,s=0,o=e.length;for(let a=0;a<o;a+=1){let o=e[a];if("'"===o&&!i){r=!r,n+=o;continue}if('"'===o&&!r){i=!i,n+=o;continue}if(!r&&!i){if("("===o){s+=1,n+=o;continue}if(")"===o&&s>0){s-=1,n+=o;continue}if(";"===o&&0===s){t.push(n),n="";continue}}n+=o}return n&&t.push(n),t}(e||""),r=n.length;for(let e=0;e<r;e+=1){let r=n[e],i=r.indexOf(":");if(-1===i)continue;let s=r.slice(0,i).trim(),o=r.slice(i+1).trim();s&&o&&t.push([s,o])}return t}function uV(...e){return e.filter(e=>!!e).reduce((e,t)=>{let n={...e};return Object.entries(t).forEach(([e,t])=>{if(!n[e]){n[e]=t;return}if("class"===e){let r=t?String(t).split(" "):[],i=n[e]?n[e].split(" "):[],s=r.filter(e=>!i.includes(e));n[e]=[...i,...s].join(" ")}else if("style"===e){let r=new Map([...uU(n[e]),...uU(t)]);n[e]=Array.from(r.entries()).map(([e,t])=>`${e}: ${t}`).join("; ")}else n[e]=t}),n},{})}function uW(e,t){return t.filter(t=>t.type===e.type.name).filter(e=>e.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(e.attrs)||{}:{[t.name]:e.attrs[t.name]}).reduce((e,t)=>uV(e,t),{})}function uq(e,t){return"style"in e?e:{...e,getAttrs:n=>{let r=e.getAttrs?e.getAttrs(n):e.attrs;if(!1===r)return!1;let i=t.reduce((e,t)=>{var r;let i=t.attribute.parseHTML?t.attribute.parseHTML(n):"string"!=typeof(r=n.getAttribute(t.name))?r:r.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(r):"true"===r||"false"!==r&&r;return null==i?e:{...e,[t.name]:i}},{});return{...r,...i}}}}function uK(e){return Object.fromEntries(Object.entries(e).filter(([e,t])=>!("attrs"===e&&function(e={}){return 0===Object.keys(e).length&&e.constructor===Object}(t))&&null!=t))}function uG(e){var t,n;let r={};return!(null==(t=null==e?void 0:e.attribute)?void 0:t.isRequired)&&"default"in((null==e?void 0:e.attribute)||{})&&(r.default=e.attribute.default),(null==(n=null==e?void 0:e.attribute)?void 0:n.validate)!==void 0&&(r.validate=e.attribute.validate),[e.name,r]}function uJ(e){return e.sort((e,t)=>{let n=uL(e,"priority")||100,r=uL(t,"priority")||100;return n>r?-1:+(n<r)})}function uZ(e){var t;let n=uJ(uP(e)),r=Array.from(new Set((t=n.map(e=>e.name)).filter((e,n)=>t.indexOf(e)!==n)));return r.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${r.map(e=>`'${e}'`).join(", ")}]. This can lead to issues.`),n}function uX(e,t,n){let{from:r,to:i}=t,{blockSeparator:s="\n\n",textSerializers:o={}}=n||{},a="";return e.nodesBetween(r,i,(e,n,l,c)=>{var d;e.isBlock&&n>r&&(a+=s);let u=null==o?void 0:o[e.type.name];if(u)return l&&(a+=u({node:e,pos:n,parent:l,index:c,range:t})),!1;e.isText&&(a+=null==(d=null==e?void 0:e.text)?void 0:d.slice(Math.max(r,n)-n,i-n))}),a}function uY(e,t){let n={from:0,to:e.content.size};return uX(e,n,t)}function uQ(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function u0(e,t){let n=uy("string"==typeof t?t:t.name,e.schema);return"node"===n?function(e,t){let n=dF(t,e.schema),{from:r,to:i}=e.selection,s=[];e.doc.nodesBetween(r,i,e=>{s.push(e)});let o=s.reverse().find(e=>e.type.name===n.name);return o?{...o.attrs}:{}}(e,t):"mark"===n?uO(e,t):{}}function u1(e){let t,{mapping:n,steps:r}=e,i=[];return n.maps.forEach((e,t)=>{let s=[];if(e.ranges.length)e.forEach((e,t)=>{s.push({from:e,to:t})});else{let{from:e,to:n}=r[t];if(void 0===e||void 0===n)return;s.push({from:e,to:n})}s.forEach(({from:e,to:r})=>{let s=n.slice(t).map(e,-1),o=n.slice(t).map(r),a=n.invert().map(s,-1),l=n.invert().map(o);i.push({oldRange:{from:a,to:l},newRange:{from:s,to:o}})})}),1===(t=function(e,t=JSON.stringify){let n={};return e.filter(e=>{let r=t(e);return!Object.prototype.hasOwnProperty.call(n,r)&&(n[r]=!0)})}(i)).length?t:t.filter((e,n)=>!t.filter((e,t)=>t!==n).some(t=>e.oldRange.from>=t.oldRange.from&&e.oldRange.to<=t.oldRange.to&&e.newRange.from>=t.newRange.from&&e.newRange.to<=t.newRange.to))}function u2(e,t,n){let r=[];return e===t?n.resolve(e).marks().forEach(t=>{let i=dY(n.resolve(e),t.type);i&&r.push({mark:t,...i})}):n.nodesBetween(e,t,(e,t)=>{e&&(null==e?void 0:e.nodeSize)!==void 0&&r.push(...e.marks.map(n=>({from:t,to:t+e.nodeSize,mark:n})))}),r}function u5(e,t){return t.nodes[e]||t.marks[e]||null}function u3(e,t,n){return Object.fromEntries(Object.entries(n).filter(([n])=>{let r=e.find(e=>e.type===t&&e.name===n);return!!r&&r.attribute.keepOnSplit}))}function u4(e,t,n={}){let{empty:r,ranges:i}=e.selection,s=t?dQ(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(e=>!s||s.name===e.type.name).find(e=>dJ(e.attrs,n,{strict:!1}));let o=0,a=[];if(i.forEach(({$from:t,$to:n})=>{let r=t.pos,i=n.pos;e.doc.nodesBetween(r,i,(e,t)=>{if(s&&e.inlineContent&&!e.type.allowsMarkType(s))return!1;if(!e.isText&&!e.marks.length)return;let n=Math.max(r,t),l=Math.min(i,t+e.nodeSize);o+=l-n,a.push(...e.marks.map(e=>({mark:e,from:n,to:l})))})}),0===o)return!1;let l=a.filter(e=>!s||s.name===e.mark.type.name).filter(e=>dJ(e.mark.attrs,n,{strict:!1})).reduce((e,t)=>e+t.to-t.from,0),c=a.filter(e=>!s||e.mark.type!==s&&e.mark.type.excludes(s)).reduce((e,t)=>e+t.to-t.from,0);return(l>0?l+c:l)>=o}function u6(e,t){return Array.isArray(t)?t.some(t=>("string"==typeof t?t:t.name)===e.name):t}function u9(e,t){let{nodeExtensions:n}=uF(t),r=n.find(t=>t.name===e);if(!r)return!1;let i={name:r.name,options:r.options,storage:r.storage},s=uB(uL(r,"group",i));return"string"==typeof s&&s.split(" ").includes("list")}function u7(e,{checkChildren:t=!0,ignoreWhitespace:n=!1}={}){var r;if(n){if("hardBreak"===e.type.name)return!0;if(e.isText)return!/\S/.test(null!=(r=e.text)?r:"")}if(e.isText)return!e.text;if(e.isAtom||e.isLeaf)return!1;if(0===e.content.childCount)return!0;if(t){let r=!0;return e.content.forEach(e=>{!1!==r&&(u7(e,{ignoreWhitespace:n,checkChildren:t})||(r=!1))}),r}return!1}function u8(e){return e instanceof op}var pe=class e{constructor(e){this.position=e}static fromJSON(t){return new e(t.position)}toJSON(){return{position:this.position}}};function pt(e,t){let n=t.mapping.mapResult(e.position);return{position:new pe(n.pos),mapResult:n}}function pn(e){return new pe(e)}function pr(e,t,n){let r=e.state.doc.content.size,i=d5(t,0,r),s=d5(n,0,r),o=e.coordsAtPos(i),a=e.coordsAtPos(s,-1),l=Math.min(o.top,a.top),c=Math.max(o.bottom,a.bottom),d=Math.min(o.left,a.left),u=Math.max(o.right,a.right),p={top:l,bottom:c,left:d,right:u,width:u-d,height:c-l,x:d,y:l};return{...p,toJSON:()=>p}}var pi=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{selection:s}=n,{empty:o,ranges:a}=s,l=dQ(e,r.schema);if(i)if(o){let e=uO(r,l);n.addStoredMark(l.create({...e,...t}))}else a.forEach(e=>{let i=e.$from.pos,s=e.$to.pos;r.doc.nodesBetween(i,s,(e,r)=>{let o=Math.max(r,i),a=Math.min(r+e.nodeSize,s);e.marks.find(e=>e.type===l)?e.marks.forEach(e=>{l===e.type&&n.addMark(o,a,l.create({...e.attrs,...t}))}):n.addMark(o,a,l.create(t))})});return function(e,t,n){var r;let{selection:i}=t,s=null;if(d2(i)&&(s=i.$cursor),s){let t=null!=(r=e.storedMarks)?r:s.marks();return s.parent.type.allowsMarkType(n)&&(!!n.isInSet(t)||!t.some(e=>e.type.excludes(n)))}let{ranges:o}=i;return o.some(({$from:t,$to:r})=>{let i=0===t.depth&&e.doc.inlineContent&&e.doc.type.allowsMarkType(n);return e.doc.nodesBetween(t.pos,r.pos,(e,t,r)=>{if(i)return!1;if(e.isInline){let t=!r||r.type.allowsMarkType(n),s=!!n.isInSet(e.marks)||!e.marks.some(e=>e.type.excludes(n));i=t&&s}return!i}),i})}(r,n,l)},ps=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),po=(e,t={})=>({state:n,dispatch:r,chain:i})=>{let s,o=dF(e,n.schema);return(n.selection.$anchor.sameParent(n.selection.$head)&&(s=n.selection.$anchor.parent.attrs),o.isTextblock)?i().command(({commands:e})=>!!dN(o,{...s,...t})(n)||e.clearNodes()).command(({state:e})=>dN(o,{...s,...t})(e,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},pa=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,r=d5(e,0,n.content.size),i=op.create(n,r);t.setSelection(i)}return!0},pl=(e,t)=>({tr:n,state:r,dispatch:i})=>{let s,o,{selection:a}=r;return"number"==typeof t?(s=t,o=t):t&&"from"in t&&"to"in t?(s=t.from,o=t.to):(s=a.from,o=a.to),i&&n.doc.nodesBetween(s,o,(t,r)=>{t.isText||n.setNodeMarkup(r,void 0,{...t.attrs,dir:e})}),!0},pc=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,{from:r,to:i}="number"==typeof e?{from:e,to:e}:e,s=od.atStart(n).from,o=od.atEnd(n).to,a=d5(r,s,o),l=d5(i,s,o),c=od.create(n,a,l);t.setSelection(c)}return!0},pd=e=>({state:t,dispatch:n})=>{var r;return(r=dF(e,t.schema),function(e,t){let{$from:n,$to:i}=e.selection,s=n.blockRange(i,e=>e.childCount>0&&e.firstChild.type==r);if(!s)return!1;let o=s.startIndex;if(0==o)return!1;let a=s.parent,l=a.child(o-1);if(l.type!=r)return!1;if(t){let n=l.lastChild&&l.lastChild.type==a.type,i=iW.from(n?r.create():null),o=new iX(iW.from(r.create(null,iW.from(a.type.create(null,i)))),n?3:1,0),c=s.start,d=s.end;t(e.tr.step(new sU(c-(n?3:1),d,c,d,o,1,!0)).scrollIntoView())}return!0})(t,n)};function pu(e,t){let n=e.storedMarks||e.selection.$to.parentOffset&&e.selection.$from.marks();if(n){let r=n.filter(e=>null==t?void 0:t.includes(e.type.name));e.tr.ensureMarks(r)}}var pp=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{let{selection:s,doc:o}=t,{$from:a,$to:l}=s,c=u3(i.extensionManager.attributes,a.node().type.name,a.node().attrs);if(s instanceof op&&s.node.isBlock)return!!a.parentOffset&&!!sX(o,a.pos)&&(r&&(e&&pu(n,i.extensionManager.splittableMarks),t.split(a.pos).scrollIntoView()),!0);if(!a.parent.isBlock)return!1;let d=l.parentOffset===l.parent.content.size,u=0===a.depth?void 0:function(e){for(let t=0;t<e.edgeCount;t+=1){let{type:n}=e.edge(t);if(n.isTextblock&&!n.hasRequiredAttrs())return n}return null}(a.node(-1).contentMatchAt(a.indexAfter(-1))),p=d&&u?[{type:u,attrs:c}]:void 0,h=sX(t.doc,t.mapping.map(a.pos),1,p);if(!p&&!h&&sX(t.doc,t.mapping.map(a.pos),1,u?[{type:u}]:void 0)&&(h=!0,p=u?[{type:u,attrs:c}]:void 0),r){if(h&&(s instanceof od&&t.deleteSelection(),t.split(t.mapping.map(a.pos),1,p),u&&!d&&!a.parentOffset&&a.parent.type!==u)){let e=t.mapping.map(a.before()),n=t.doc.resolve(e);a.node(-1).canReplaceWith(n.index(),n.index()+1,u)&&t.setNodeMarkup(t.mapping.map(a.before()),u)}e&&pu(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return h},ph=(e,t={})=>({tr:n,state:r,dispatch:i,editor:s})=>{var o;let a=dF(e,r.schema),{$from:l,$to:c}=r.selection,d=r.selection.node;if(d&&d.isBlock||l.depth<2||!l.sameParent(c))return!1;let u=l.node(-1);if(u.type!==a)return!1;let p=s.extensionManager.attributes;if(0===l.parent.content.size&&l.node(-1).childCount===l.indexAfter(-1)){if(2===l.depth||l.node(-3).type!==a||l.index(-2)!==l.node(-2).childCount-1)return!1;if(i){let e=iW.empty,r=l.index(-1)?1:l.index(-2)?2:3;for(let t=l.depth-r;t>=l.depth-3;t-=1)e=iW.from(l.node(t).copy(e));let i=l.indexAfter(-1)<l.node(-2).childCount?1:l.indexAfter(-2)<l.node(-3).childCount?2:3,s={...u3(p,l.node().type.name,l.node().attrs),...t},c=(null==(o=a.contentMatch.defaultType)?void 0:o.createAndFill(s))||void 0;e=e.append(iW.from(a.createAndFill(null,c)||void 0));let d=l.before(l.depth-(r-1));n.replace(d,l.after(-i),new iX(e,4-r,0));let u=-1;n.doc.nodesBetween(d,n.doc.content.size,(e,t)=>{if(u>-1)return!1;e.isTextblock&&0===e.content.size&&(u=t+1)}),u>-1&&n.setSelection(od.near(n.doc.resolve(u))),n.scrollIntoView()}return!0}let h=c.pos===l.end()?u.contentMatchAt(0).defaultType:null,m={...u3(p,u.type.name,u.attrs),...t},f={...u3(p,l.node().type.name,l.node().attrs),...t};n.delete(l.pos,c.pos);let g=h?[{type:a,attrs:m},{type:h,attrs:f}]:[{type:a,attrs:m}];if(!sX(n.doc,l.pos,2))return!1;if(i){let{selection:e,storedMarks:t}=r,{splittableMarks:o}=s.extensionManager,a=t||e.$to.parentOffset&&e.$from.marks();if(n.split(l.pos,2,g).scrollIntoView(),!a||!i)return!0;let c=a.filter(e=>o.includes(e.type.name));n.ensureMarks(c)}return!0},pm=(e,t)=>{let n=uI(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(Math.max(0,n.pos-1)).before(n.depth);if(void 0===r)return!0;let i=e.doc.nodeAt(r);return!(n.node.type===(null==i?void 0:i.type)&&sY(e.doc,n.pos))||(e.join(n.pos),!0)},pf=(e,t)=>{let n=uI(e=>e.type===t)(e.selection);if(!n)return!0;let r=e.doc.resolve(n.start).after(n.depth);if(void 0===r)return!0;let i=e.doc.nodeAt(r);return!(n.node.type===(null==i?void 0:i.type)&&sY(e.doc,r))||(e.join(r),!0)},pg=(e,t,n,r={})=>({editor:i,tr:s,state:o,dispatch:a,chain:l,commands:c,can:d})=>{let{extensions:u,splittableMarks:p}=i.extensionManager,h=dF(e,o.schema),m=dF(t,o.schema),{selection:f,storedMarks:g}=o,{$from:x,$to:b}=f,y=x.blockRange(b),v=g||f.$to.parentOffset&&f.$from.marks();if(!y)return!1;let w=uI(e=>u9(e.type.name,u))(f),k=0===f.from&&f.to===o.doc.content.size,N=o.doc.content.content,S=1===N.length?N[0]:null,C=k&&S&&u9(S.type.name,u)?{node:S,pos:0,depth:0}:null,j=null!=w?w:C,E=!!w&&y.depth>=1&&y.depth-w.depth<=1,M=!!C;if((E||M)&&j){if(j.node.type===h)return k&&M?l().command(({tr:e,dispatch:t})=>{let n=function(e){let t=e.doc,n=t.firstChild;if(!n)return null;let r=t.resolve(1),i=t.resolve(n.nodeSize-1);return od.between(r,i)}(e);return!!n&&(e.setSelection(n),t&&t(e),!0)}).liftListItem(m).run():c.liftListItem(m);if(u9(j.node.type.name,u)&&h.validContent(j.node.content))return l().command(()=>(s.setNodeMarkup(j.pos,h),!0)).command(()=>pm(s,h)).command(()=>pf(s,h)).run()}return n&&v&&a?l().command(()=>{let e=d().wrapInList(h,r),t=v.filter(e=>p.includes(e.type.name));return s.ensureMarks(t),!!e||c.clearNodes()}).wrapInList(h,r).command(()=>pm(s,h)).command(()=>pf(s,h)).run():l().command(()=>!!d().wrapInList(h,r)||c.clearNodes()).wrapInList(h,r).command(()=>pm(s,h)).command(()=>pf(s,h)).run()},px=(e,t={},n={})=>({state:r,commands:i})=>{let{extendEmptyMarkRange:s=!1}=n,o=dQ(e,r.schema);return u4(r,o,t)?i.unsetMark(o,{extendEmptyMarkRange:s}):i.setMark(o,t)},pb=(e,t,n={})=>({state:r,commands:i})=>{let s,o=dF(e,r.schema),a=dF(t,r.schema),l=um(r,o,n);return(r.selection.$anchor.sameParent(r.selection.$head)&&(s=r.selection.$anchor.parent.attrs),l)?i.setNode(a,s):i.setNode(o,{...s,...n})},py=(e,t={})=>({state:n,commands:r})=>{let i=dF(e,n.schema);return um(n,i,t)?r.lift(i):r.wrapIn(i,t)},pv=()=>({state:e,dispatch:t})=>{let n=e.plugins;for(let r=0;r<n.length;r+=1){let i,s=n[r];if(s.spec.isInputRules&&(i=s.getState(e))){if(t){let t=e.tr,n=i.transform;for(let e=n.steps.length-1;e>=0;e-=1)t.step(n.steps[e].invert(n.docs[e]));if(i.text){let n=t.doc.resolve(i.from).marks();t.replaceWith(i.from,i.to,e.schema.text(i.text,n))}else t.delete(i.from,i.to)}return!0}}return!1},pw=()=>({tr:e,dispatch:t})=>{let{selection:n}=e,{empty:r,ranges:i}=n;return!!r||(t&&i.forEach(t=>{e.removeMark(t.$from.pos,t.$to.pos)}),!0)},pk=(e,t={})=>({tr:n,state:r,dispatch:i})=>{var s;let{extendEmptyMarkRange:o=!1}=t,{selection:a}=n,l=dQ(e,r.schema),{$from:c,empty:d,ranges:u}=a;if(!i)return!0;if(d&&o){let{from:e,to:t}=a,r=null==(s=c.marks().find(e=>e.type===l))?void 0:s.attrs,i=dY(c,l,r);i&&(e=i.from,t=i.to),n.removeMark(e,t,l)}else u.forEach(e=>{n.removeMark(e.$from.pos,e.$to.pos,l)});return n.removeStoredMark(l),!0},pN=e=>({tr:t,state:n,dispatch:r})=>{let i,s,{selection:o}=n;return"number"==typeof e?(i=e,s=e):e&&"from"in e&&"to"in e?(i=e.from,s=e.to):(i=o.from,s=o.to),r&&t.doc.nodesBetween(i,s,(e,n)=>{if(e.isText)return;let r={...e.attrs};delete r.dir,t.setNodeMarkup(n,void 0,r)}),!0},pS=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let s=null,o=null,a=uy("string"==typeof e?e:e.name,r.schema);if(!a)return!1;"node"===a&&(s=dF(e,r.schema)),"mark"===a&&(o=dQ(e,r.schema));let l=!1;return n.selection.ranges.forEach(e=>{let a,c,d,u,p=e.$from.pos,h=e.$to.pos;n.selection.empty?r.doc.nodesBetween(p,h,(e,t)=>{s&&s===e.type&&(l=!0,d=Math.max(t,p),u=Math.min(t+e.nodeSize,h),a=t,c=e)}):r.doc.nodesBetween(p,h,(e,r)=>{r<p&&s&&s===e.type&&(l=!0,d=Math.max(r,p),u=Math.min(r+e.nodeSize,h),a=r,c=e),r>=p&&r<=h&&(s&&s===e.type&&(l=!0,i&&n.setNodeMarkup(r,void 0,{...e.attrs,...t})),o&&e.marks.length&&e.marks.forEach(s=>{if(o===s.type&&(l=!0,i)){let i=Math.max(r,p),a=Math.min(r+e.nodeSize,h);n.addMark(i,a,o.create({...s.attrs,...t}))}}))}),c&&(void 0!==a&&i&&n.setNodeMarkup(a,void 0,{...c.attrs,...t}),o&&c.marks.length&&c.marks.forEach(e=>{o===e.type&&i&&n.addMark(d,u,o.create({...e.attrs,...t}))}))}),l},pC=(e,t={})=>({state:n,dispatch:r})=>(function(e,t=null){return function(n,r){let{$from:i,$to:s}=n.selection,o=i.blockRange(s),a=o&&sK(o,e,t);return!!a&&(r&&r(n.tr.wrap(o,a).scrollIntoView()),!0)}})(dF(e,n.schema),t)(n,r),pj=(e,t={})=>({state:n,dispatch:r})=>(function(e,t=null){return function(n,r){let{$from:i,$to:s}=n.selection,o=i.blockRange(s);if(!o)return!1;let a=r?n.tr:null;return!!function(e,t,n,r=null){let i=!1,s=t,o=t.$from.doc;if(t.depth>=2&&t.$from.node(t.depth-1).type.compatibleContent(n)&&0==t.startIndex){if(0==t.$from.index(t.depth-1))return!1;let e=o.resolve(t.start-2);s=new i7(e,e,t.depth),t.endIndex<t.parent.childCount&&(t=new i7(t.$from,o.resolve(t.$to.end(t.depth)),t.depth)),i=!0}let a=sK(s,n,r,t);return!!a&&(e&&function(e,t,n,r,i){let s=iW.empty;for(let e=n.length-1;e>=0;e--)s=iW.from(n[e].type.create(n[e].attrs,s));e.step(new sU(t.start-2*!!r,t.end,t.start,t.end,new iX(s,0,0),n.length,!0));let o=0;for(let e=0;e<n.length;e++)n[e].type==i&&(o=e+1);let a=n.length-o,l=t.start+n.length-2*!!r,c=t.parent;for(let n=t.startIndex,r=t.endIndex,i=!0;n<r;n++,i=!1)!i&&sX(e.doc,l,a)&&(e.split(l,a),l+=2*a),l+=c.child(n).nodeSize}(e,t,a,i,n),!0)}(a,o,e,t)&&(r&&r(a.scrollIntoView()),!0)}})(dF(e,n.schema),t)(n,r),pE=class{constructor(){this.callbacks={}}on(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this}emit(e,...t){let n=this.callbacks[e];return n&&n.forEach(e=>e.apply(this,t)),this}off(e,t){let n=this.callbacks[e];return n&&(t?this.callbacks[e]=n.filter(e=>e!==t):delete this.callbacks[e]),this}once(e,t){let n=(...r)=>{this.off(e,n),t.apply(this,r)};return this.on(e,n)}removeAllListeners(){this.callbacks={}}},pM=class{constructor(e){var t;this.find=e.find,this.handler=e.handler,this.undoable=null==(t=e.undoable)||t}};function pA(e){var t;let{editor:n,from:r,to:i,text:s,rules:o,plugin:a}=e,{view:l}=n;if(l.composing)return!1;let c=l.state.doc.resolve(r);if(c.parent.type.spec.code||(null==(t=c.nodeBefore||c.nodeAfter)?void 0:t.marks.find(e=>e.type.spec.code)))return!1;let d=!1,u=((e,t=500)=>{let n="",r=e.parentOffset;return e.parent.nodesBetween(Math.max(0,r-t),r,(e,t,i,s)=>{var o,a;let l=(null==(a=(o=e.type.spec).toText)?void 0:a.call(o,{node:e,pos:t,parent:i,index:s}))||e.textContent||"%leaf%";n+=e.isAtom&&!e.isText?l:l.slice(0,Math.max(0,r-t))}),n})(c)+s;return o.forEach(e=>{if(d)return;let t=((e,t)=>{if(dG(t))return t.exec(e);let n=t(e);if(!n)return null;let r=[n.text];return r.index=n.index,r.input=e,r.data=n.data,n.replaceWith&&(n.text.includes(n.replaceWith)||console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'),r.push(n.replaceWith)),r})(u,e.find);if(!t)return;let o=l.state.tr,c=dO({state:l.state,transaction:o}),p={from:r-(t[0].length-s.length),to:i},{commands:h,chain:m,can:f}=new d_({editor:n,state:c});null!==e.handler({state:c,range:p,match:t,commands:h,chain:m,can:f})&&o.steps.length&&(e.undoable&&o.setMeta(a,{transform:o,from:r,to:i,text:s}),l.dispatch(o),d=!0)}),d}function pT(e){return"Object"===Object.prototype.toString.call(e).slice(8,-1)&&e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}var pO=class{constructor(e={}){this.type="extendable",this.parent=null,this.child=null,this.name="",this.config={name:this.name},this.config={...this.config,...e},this.name=this.config.name}get options(){return{...uB(uL(this,"addOptions",{name:this.name}))}}get storage(){return{...uB(uL(this,"addStorage",{name:this.name,options:this.options}))}}configure(e={}){let t=this.extend({...this.config,addOptions:()=>(function e(t,n){let r={...t};return pT(t)&&pT(n)&&Object.keys(n).forEach(i=>{pT(n[i])&&pT(t[i])?r[i]=e(t[i],n[i]):r[i]=n[i]}),r})(this.options,e)});return t.name=this.name,t.parent=this.parent,this.child=null,t}extend(e={}){let t=new this.constructor({...this.config,...e});return t.parent=this,this.child=t,t.name="name"in e?e.name:t.parent.name,t}},p_=class e extends pO{constructor(){super(...arguments),this.type="mark"}static create(t={}){return new e("function"==typeof t?t():t)}static handleExit({editor:e,mark:t}){let{tr:n}=e.state,r=e.state.selection.$from;if(r.pos===r.end()){let i=r.marks();if(!i.find(e=>(null==e?void 0:e.type.name)===t.name))return!1;let s=i.find(e=>(null==e?void 0:e.type.name)===t.name);return s&&n.removeStoredMark(s),n.insertText(" ",r.pos),e.view.dispatch(n),!0}return!1}configure(e){return super.configure(e)}extend(e){let t="function"==typeof e?e():e;return super.extend(t)}},pD=class{constructor(e){this.find=e.find,this.handler=e.handler}},pR=null,pI=class{constructor(e,t){this.splittableMarks=[],this.editor=t,this.baseExtensions=e,this.extensions=uZ(e),this.schema=function(e,t){var n;let r=uH(e),{nodeExtensions:i,markExtensions:s}=uF(e),o=null==(n=i.find(e=>uL(e,"topNode")))?void 0:n.name;return new sf({topNode:o,nodes:Object.fromEntries(i.map(n=>{let i=r.filter(e=>e.type===n.name),s={name:n.name,options:n.options,storage:n.storage,editor:t},o=uK({...e.reduce((e,t)=>{let r=uL(t,"extendNodeSchema",s);return{...e,...r?r(n):{}}},{}),content:uB(uL(n,"content",s)),marks:uB(uL(n,"marks",s)),group:uB(uL(n,"group",s)),inline:uB(uL(n,"inline",s)),atom:uB(uL(n,"atom",s)),selectable:uB(uL(n,"selectable",s)),draggable:uB(uL(n,"draggable",s)),code:uB(uL(n,"code",s)),whitespace:uB(uL(n,"whitespace",s)),linebreakReplacement:uB(uL(n,"linebreakReplacement",s)),defining:uB(uL(n,"defining",s)),isolating:uB(uL(n,"isolating",s)),attrs:Object.fromEntries(i.map(uG))}),a=uB(uL(n,"parseHTML",s));a&&(o.parseDOM=a.map(e=>uq(e,i)));let l=uL(n,"renderHTML",s);l&&(o.toDOM=e=>l({node:e,HTMLAttributes:uW(e,i)}));let c=uL(n,"renderText",s);return c&&(o.toText=c),[n.name,o]})),marks:Object.fromEntries(s.map(n=>{let i=r.filter(e=>e.type===n.name),s={name:n.name,options:n.options,storage:n.storage,editor:t},o=uK({...e.reduce((e,t)=>{let r=uL(t,"extendMarkSchema",s);return{...e,...r?r(n):{}}},{}),inclusive:uB(uL(n,"inclusive",s)),excludes:uB(uL(n,"excludes",s)),group:uB(uL(n,"group",s)),spanning:uB(uL(n,"spanning",s)),code:uB(uL(n,"code",s)),attrs:Object.fromEntries(i.map(uG))}),a=uB(uL(n,"parseHTML",s));a&&(o.parseDOM=a.map(e=>uq(e,i)));let l=uL(n,"renderHTML",s);return l&&(o.toDOM=e=>l({mark:e,HTMLAttributes:uW(e,i)})),[n.name,o]}))})}(this.extensions,t),this.setupExtensions()}get commands(){return this.extensions.reduce((e,t)=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:this.editor,type:u5(t.name,this.schema)},r=uL(t,"addCommands",n);return r?{...e,...r()}:e},{})}get plugins(){let{editor:e}=this;return uJ([...this.extensions].reverse()).flatMap(t=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:u5(t.name,this.schema)},r=[],i=uL(t,"addKeyboardShortcuts",n),s={};if("mark"===t.type&&uL(t,"exitable",n)&&(s.ArrowRight=()=>p_.handleExit({editor:e,mark:t})),i){let t=Object.fromEntries(Object.entries(i()).map(([t,n])=>[t,()=>n({editor:e})]));s={...s,...t}}let o=new oS({props:{handleKeyDown:cs(s)}});r.push(o);let a=uL(t,"addInputRules",n);if(u6(t,e.options.enableInputRules)&&a){let t=a();if(t&&t.length){let n=function(e){let{editor:t,rules:n}=e,r=new oS({state:{init:()=>null,apply(e,i,s){let o=e.getMeta(r);if(o)return o;let a=e.getMeta("applyInputRules");return a&&setTimeout(()=>{let{text:e}=a;"string"==typeof e||(e=u$(iW.from(e),s.schema));let{from:i}=a,o=i+e.length;pA({editor:t,from:i,to:o,text:e,rules:n,plugin:r})}),e.selectionSet||e.docChanged?null:i}},props:{handleTextInput:(e,i,s,o)=>pA({editor:t,from:i,to:s,text:o,rules:n,plugin:r}),handleDOMEvents:{compositionend:e=>(setTimeout(()=>{let{$cursor:i}=e.state.selection;i&&pA({editor:t,from:i.pos,to:i.pos,text:"",rules:n,plugin:r})}),!1)},handleKeyDown(e,i){if("Enter"!==i.key)return!1;let{$cursor:s}=e.state.selection;return!!s&&pA({editor:t,from:s.pos,to:s.pos,text:"\n",rules:n,plugin:r})}},isInputRules:!0});return r}({editor:e,rules:t}),i=Array.isArray(n)?n:[n];r.push(...i)}}let l=uL(t,"addPasteRules",n);if(u6(t,e.options.enablePasteRules)&&l){let t=l();if(t&&t.length){let n=function(e){let t,{editor:n,rules:r}=e,i=null,s=!1,o=!1,a="u">typeof ClipboardEvent?new ClipboardEvent("paste"):null;try{t="u">typeof DragEvent?new DragEvent("drop"):null}catch{t=null}let l=({state:e,from:r,to:i,rule:s,pasteEvt:o})=>{let l=e.tr;if(function(e){let{editor:t,state:n,from:r,to:i,rule:s,pasteEvent:o,dropEvent:a}=e,{commands:l,chain:c,can:d}=new d_({editor:t,state:n}),u=[];return n.doc.nodesBetween(r,i,(e,t)=>{var p,h,m,f,g;if((null==(h=null==(p=e.type)?void 0:p.spec)?void 0:h.code)||!(e.isText||e.isTextblock||e.isInline))return;let x=null!=(g=null!=(f=null==(m=e.content)?void 0:m.size)?f:e.nodeSize)?g:0,b=Math.max(r,t),y=Math.min(i,t+x);b>=y||((e,t,n)=>{if(dG(t))return[...e.matchAll(t)];let r=t(e,n);return r?r.map(t=>{let n=[t.text];return n.index=t.index,n.input=e,n.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),n.push(t.replaceWith)),n}):[]})(e.isText?e.text||"":e.textBetween(b-t,y-t,void 0,""),s.find,o).forEach(e=>{if(void 0===e.index)return;let t=b+e.index+1,r=t+e[0].length,i={from:n.tr.mapping.map(t),to:n.tr.mapping.map(r)},p=s.handler({state:n,range:i,match:e,commands:l,chain:c,can:d,pasteEvent:o,dropEvent:a});u.push(p)})}),u.every(e=>null!==e)}({editor:n,state:dO({state:e,transaction:l}),from:Math.max(r-1,0),to:i.b-1,rule:s,pasteEvent:o,dropEvent:t})&&l.steps.length){try{t="u">typeof DragEvent?new DragEvent("drop"):null}catch{t=null}return a="u">typeof ClipboardEvent?new ClipboardEvent("paste"):null,l}};return r.map(e=>new oS({view(e){let t=t=>{var r;(i=(null==(r=e.dom.parentElement)?void 0:r.contains(t.target))?e.dom.parentElement:null)&&(pR=n)},r=()=>{pR&&(pR=null)};return window.addEventListener("dragstart",t),window.addEventListener("dragend",r),{destroy(){window.removeEventListener("dragstart",t),window.removeEventListener("dragend",r)}}},props:{handleDOMEvents:{drop:(e,n)=>{if(o=i===e.dom.parentElement,t=n,!o){let e=pR;(null==e?void 0:e.isEditable)&&setTimeout(()=>{let t=e.state.selection;t&&e.commands.deleteRange({from:t.from,to:t.to})},10)}return!1},paste:(e,t)=>{var n;let r=null==(n=t.clipboardData)?void 0:n.getData("text/html");return a=t,s=!!(null==r?void 0:r.includes("data-pm-slice")),!1}}},appendTransaction:(t,n,r)=>{let i=t[0],c="paste"===i.getMeta("uiEvent")&&!s,d="drop"===i.getMeta("uiEvent")&&!o,u=i.getMeta("applyPasteRules"),p=!!u;if(!c&&!d&&!p)return;if(p){var h,m;let t,{text:n}=u;"string"==typeof n||(n=u$(iW.from(n),r.schema));let{from:i}=u,s=i+n.length;return l({rule:e,state:r,from:i,to:{b:s},pasteEvt:(h=n,null==(m=(t=new ClipboardEvent("paste",{clipboardData:new DataTransfer})).clipboardData)||m.setData("text/html",h),t)})}let f=n.doc.content.findDiffStart(r.doc.content),g=n.doc.content.findDiffEnd(r.doc.content);if("number"==typeof f&&g&&f!==g.b)return l({rule:e,state:r,from:f,to:g,pasteEvt:a})}}))}({editor:e,rules:t});r.push(...n)}}let c=uL(t,"addProseMirrorPlugins",n);if(c){let e=c();r.push(...e)}return r})}get attributes(){return uH(this.extensions)}get nodeViews(){let{editor:e}=this,{nodeExtensions:t}=uF(this.extensions);return Object.fromEntries(t.filter(e=>!!uL(e,"addNodeView")).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:dF(t.name,this.schema)},i=uL(t,"addNodeView",r);if(!i)return[];let s=i();return s?[t.name,(r,i,o,a,l)=>{let c=uW(r,n);return s({node:r,view:i,getPos:o,decorations:a,innerDecorations:l,editor:e,extension:t,HTMLAttributes:c})}]:[]}))}dispatchTransaction(e){let{editor:t}=this;return uJ([...this.extensions].reverse()).reduceRight((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:u5(n.name,this.schema)},i=uL(n,"dispatchTransaction",r);return i?t=>{i.call(r,{transaction:t,next:e})}:e},e)}transformPastedHTML(e){let{editor:t}=this;return uJ([...this.extensions]).reduce((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:u5(n.name,this.schema)},i=uL(n,"transformPastedHTML",r);return i?(t,n)=>{let s=e(t,n);return i.call(r,s)}:e},e||(e=>e))}get markViews(){let{editor:e}=this,{markExtensions:t}=uF(this.extensions);return Object.fromEntries(t.filter(e=>!!uL(e,"addMarkView")).map(t=>{let n=this.attributes.filter(e=>e.type===t.name),r={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:dQ(t.name,this.schema)},i=uL(t,"addMarkView",r);return i?[t.name,(r,s,o)=>{let a=uW(r,n);return i()({mark:r,view:s,inline:o,editor:e,extension:t,HTMLAttributes:a,updateAttributes:t=>{!function(e,t,n={}){let{state:r}=t,{doc:i,tr:s}=r;i.descendants((t,r)=>{let i=s.mapping.map(r),o=s.mapping.map(r)+t.nodeSize,a=null;if(t.marks.forEach(t=>{if(t!==e)return!1;a=t}),!a)return;let l=!1;if(Object.keys(n).forEach(e=>{n[e]!==a.attrs[e]&&(l=!0)}),l){let t=e.type.create({...e.attrs,...n});s.removeMark(i,o,e.type),s.addMark(i,o,t)}}),s.docChanged&&t.view.dispatch(s)}(r,e,t)}})}]:[]}))}destroy(){this.extensions.forEach(e=>{let t=e;for(;t.parent;){let e=t.parent;e.child===t&&(e.child=null),t=e}}),this.extensions=[],this.baseExtensions=[],this.schema=null,this.editor=null}setupExtensions(){let e=this.extensions;this.editor.extensionStorage=Object.fromEntries(e.map(e=>[e.name,e.storage])),e.forEach(e=>{var t;let n={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:u5(e.name,this.schema)};"mark"===e.type&&(null==(t=uB(uL(e,"keepOnSplit",n)))||t)&&this.splittableMarks.push(e.name);let r=uL(e,"onBeforeCreate",n),i=uL(e,"onCreate",n),s=uL(e,"onUpdate",n),o=uL(e,"onSelectionUpdate",n),a=uL(e,"onTransaction",n),l=uL(e,"onFocus",n),c=uL(e,"onBlur",n),d=uL(e,"onDestroy",n);r&&this.editor.on("beforeCreate",r),i&&this.editor.on("create",i),s&&this.editor.on("update",s),o&&this.editor.on("selectionUpdate",o),a&&this.editor.on("transaction",a),l&&this.editor.on("focus",l),c&&this.editor.on("blur",c),d&&this.editor.on("destroy",d)})}};pI.resolve=uZ,pI.sort=uJ,pI.flatten=uP,dT({},{ClipboardTextSerializer:()=>pP,Commands:()=>p$,Delete:()=>pz,Drop:()=>pB,Editable:()=>pF,FocusEvents:()=>pU,Keymap:()=>pV,Paste:()=>pW,Tabindex:()=>pq,TextDirection:()=>pK,focusEventsPluginKey:()=>pH});var pL=class e extends pO{constructor(){super(...arguments),this.type="extension"}static create(t={}){return new e("function"==typeof t?t():t)}configure(e){return super.configure(e)}extend(e){let t="function"==typeof e?e():e;return super.extend(t)}},pP=pL.create({name:"clipboardTextSerializer",addOptions:()=>({blockSeparator:void 0}),addProseMirrorPlugins(){return[new oS({key:new oE("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{let{editor:e}=this,{state:t,schema:n}=e,{doc:r,selection:i}=t,{ranges:s}=i,o=Math.min(...s.map(e=>e.$from.pos)),a=Math.max(...s.map(e=>e.$to.pos)),l=uQ(n);return uX(r,{from:o,to:a},{...void 0!==this.options.blockSeparator?{blockSeparator:this.options.blockSeparator}:{},textSerializers:l})}}})]}}),p$=pL.create({name:"commands",addCommands:()=>({...dD})}),pz=pL.create({name:"delete",onUpdate({transaction:e,appendedTransactions:t}){var n,r,i;let s=()=>{var n,r,i,s;if(null!=(s=null==(i=null==(r=null==(n=this.editor.options.coreExtensionOptions)?void 0:n.delete)?void 0:r.filterTransaction)?void 0:i.call(r,e))?s:e.getMeta("y-sync$"))return;let o=u_(e.before,[e,...t]);u1(o).forEach(t=>{o.mapping.mapResult(t.oldRange.from).deletedAfter&&o.mapping.mapResult(t.oldRange.to).deletedBefore&&o.before.nodesBetween(t.oldRange.from,t.oldRange.to,(n,r)=>{let i=r+n.nodeSize-2,s=t.oldRange.from<=r&&i<=t.oldRange.to;this.editor.emit("delete",{type:"node",node:n,from:r,to:i,newFrom:o.mapping.map(r),newTo:o.mapping.map(i),deletedRange:t.oldRange,newRange:t.newRange,partial:!s,editor:this.editor,transaction:e,combinedTransform:o})})});let a=o.mapping;o.steps.forEach((t,n)=>{var r,i;if(t instanceof sz){let s=a.slice(n).map(t.from,-1),l=a.slice(n).map(t.to),c=a.invert().map(s,-1),d=a.invert().map(l),u=s>0&&(null==(r=o.doc.nodeAt(s-1))?void 0:r.marks.some(e=>e.eq(t.mark))),p=null==(i=o.doc.nodeAt(l))?void 0:i.marks.some(e=>e.eq(t.mark));this.editor.emit("delete",{type:"mark",mark:t.mark,from:t.from,to:t.to,deletedRange:{from:c,to:d},newRange:{from:s,to:l},partial:!!(p||u),editor:this.editor,transaction:e,combinedTransform:o})}})};null==(i=null==(r=null==(n=this.editor.options.coreExtensionOptions)?void 0:n.delete)?void 0:r.async)||i?setTimeout(s,0):s()}}),pB=pL.create({name:"drop",addProseMirrorPlugins(){return[new oS({key:new oE("tiptapDrop"),props:{handleDrop:(e,t,n,r)=>{this.editor.emit("drop",{editor:this.editor,event:t,slice:n,moved:r})}}})]}}),pF=pL.create({name:"editable",addProseMirrorPlugins(){return[new oS({key:new oE("editable"),props:{editable:()=>this.editor.options.editable}})]}}),pH=new oE("focusEvents"),pU=pL.create({name:"focusEvents",addProseMirrorPlugins(){let{editor:e}=this;return[new oS({key:pH,props:{handleDOMEvents:{focus:(t,n)=>{e.isFocused=!0;let r=e.state.tr.setMeta("focus",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1},blur:(t,n)=>{e.isFocused=!1;let r=e.state.tr.setMeta("blur",{event:n}).setMeta("addToHistory",!1);return t.dispatch(r),!1}}}})]}}),pV=pL.create({name:"keymap",addKeyboardShortcuts(){let e=()=>this.editor.commands.first(({commands:e})=>[()=>e.undoInputRule(),()=>e.command(({tr:t})=>{let{selection:n,doc:r}=t,{empty:i,$anchor:s}=n,{pos:o,parent:a}=s,l=s.parent.isTextblock&&o>0?t.doc.resolve(o-1):s,c=l.parent.type.spec.isolating,d=s.pos-s.parentOffset,u=c&&1===l.parent.childCount?d===s.pos:oo.atStart(r).from===o;return!!i&&!!a.type.isTextblock&&!a.textContent.length&&!!u&&(!u||"paragraph"!==s.parent.type.name)&&e.clearNodes()}),()=>e.deleteSelection(),()=>e.joinBackward(),()=>e.selectNodeBackward()]),t=()=>this.editor.commands.first(({commands:e})=>[()=>e.deleteSelection(),()=>e.deleteCurrentNode(),()=>e.joinForward(),()=>e.selectNodeForward()]),n={Enter:()=>this.editor.commands.first(({commands:e})=>[()=>e.newlineInCode(),()=>e.createParagraphNear(),()=>e.liftEmptyBlock(),()=>e.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:e,"Mod-Backspace":e,"Shift-Backspace":e,Delete:t,"Mod-Delete":t,"Mod-a":()=>this.editor.commands.selectAll()},r={...n},i={...n,"Ctrl-h":e,"Alt-Backspace":e,"Ctrl-d":t,"Ctrl-Alt-Backspace":t,"Alt-Delete":t,"Alt-d":t,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return d6()||up()?i:r},addProseMirrorPlugins(){return[new oS({key:new oE("clearDocument"),appendTransaction:(e,t,n)=>{if(e.some(e=>e.getMeta("composition")))return;let r=e.some(e=>e.docChanged)&&!t.doc.eq(n.doc),i=e.some(e=>e.getMeta("preventClearDocument"));if(!r||i)return;let{empty:s,from:o,to:a}=t.selection,l=oo.atStart(t.doc).from,c=oo.atEnd(t.doc).to;if(s||o!==l||a!==c||!u7(n.doc))return;let d=n.tr,u=dO({state:n,transaction:d}),{commands:p}=new d_({editor:this.editor,state:u});if(p.clearNodes(),d.steps.length)return d}})]}}),pW=pL.create({name:"paste",addProseMirrorPlugins(){return[new oS({key:new oE("tiptapPaste"),props:{handlePaste:(e,t,n)=>{this.editor.emit("paste",{editor:this.editor,event:t,slice:n})}}})]}}),pq=pL.create({name:"tabindex",addOptions:()=>({value:void 0}),addProseMirrorPlugins(){return[new oS({key:new oE("tabindex"),props:{attributes:()=>{var e;return this.editor.isEditable||void 0!==this.options.value?{tabindex:null!=(e=this.options.value)?e:"0"}:{}}}})]}}),pK=pL.create({name:"textDirection",addOptions:()=>({direction:void 0}),addGlobalAttributes(){if(!this.options.direction)return[];let{nodeExtensions:e}=uF(this.extensions);return[{types:e.filter(e=>"text"!==e.name).map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{let t=e.getAttribute("dir");return t&&("ltr"===t||"rtl"===t||"auto"===t)?t:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new oS({key:new oE("textDirection"),props:{attributes:()=>{let e=this.options.direction;return e?{dir:e}:{}}}})]}}),pG=class e{constructor(e,t,n=!1,r=null){this.currentNode=null,this.actualDepth=null,this.isBlock=n,this.resolvedPos=e,this.editor=t,this.currentNode=r}get name(){return this.node.type.name}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){var e;return null!=(e=this.actualDepth)?e:this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,n=this.to;if(this.isBlock){if(0===this.content.size)return void console.error(`You can\u2019t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);t=this.from+1,n=this.to-1}this.editor.commands.insertContentAt({from:t,to:n},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+ +!this.node.isText}get parent(){if(0===this.depth)return null;let t=this.resolvedPos.start(this.resolvedPos.depth-1);return new e(this.resolvedPos.doc.resolve(t),this.editor)}get before(){let t=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.from-3)),new e(t,this.editor)}get after(){let t=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return t.depth!==this.depth&&(t=this.resolvedPos.doc.resolve(this.to+3)),new e(t,this.editor)}get children(){let t=[];return this.node.content.forEach((n,r)=>{let i=n.isBlock&&!n.isTextblock,s=n.isAtom&&!n.isText,o=n.isInline,a=this.pos+r+ +!s;if(a<0||a>this.resolvedPos.doc.nodeSize-2)return;let l=this.resolvedPos.doc.resolve(a);if(!i&&!o&&l.depth<=this.depth)return;let c=new e(l,this.editor,i,i||o?n:null);i&&(c.actualDepth=this.depth+1),t.push(c)}),t}get firstChild(){return this.children[0]||null}get lastChild(){let e=this.children;return e[e.length-1]||null}closest(e,t={}){let n=null,r=this.parent;for(;r&&!n;){if(r.node.type.name===e)if(Object.keys(t).length>0){let e=r.node.attrs,n=Object.keys(t);for(let r=0;r<n.length;r+=1){let i=n[r];if(e[i]!==t[i])break}}else n=r;r=r.parent}return n}querySelector(e,t={}){return this.querySelectorAll(e,t,!0)[0]||null}querySelectorAll(e,t={},n=!1){let r=[];if(!this.children||0===this.children.length)return r;let i=Object.keys(t);return this.children.forEach(s=>{n&&r.length>0||(s.node.type.name===e&&i.every(e=>t[e]===s.node.attrs[e])&&r.push(s),n&&r.length>0||(r=r.concat(s.querySelectorAll(e,t,n))))}),r}setAttribute(e){let{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}},pJ=`.ProseMirror {
|
|
22
22
|
position: relative;
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -159,6 +159,7 @@ ${i}
|
|
|
159
159
|
<script type="module">
|
|
160
160
|
import React from 'react';
|
|
161
161
|
import { createRoot } from 'react-dom/client';
|
|
162
|
+
${p}
|
|
162
163
|
function reportError(e) {
|
|
163
164
|
const root = document.getElementById('root');
|
|
164
165
|
if (root) root.innerHTML = '<pre class="mdx-error">' + String(e && e.stack ? e.stack : e) + '</pre>';
|
|
@@ -174,7 +175,6 @@ class ErrorBoundary extends React.Component {
|
|
|
174
175
|
}
|
|
175
176
|
}
|
|
176
177
|
try {
|
|
177
|
-
${p}
|
|
178
178
|
createRoot(document.getElementById('root')).render(
|
|
179
179
|
React.createElement(ErrorBoundary, null, React.createElement(MDXContent))
|
|
180
180
|
);
|