wiki-viewer 2.11.3 → 2.11.4

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.
Files changed (72) hide show
  1. package/.next/standalone/.next/BUILD_ID +1 -1
  2. package/.next/standalone/.next/build-manifest.json +3 -3
  3. package/.next/standalone/.next/prerender-manifest.json +3 -3
  4. package/.next/standalone/.next/required-server-files.json +1 -1
  5. package/.next/standalone/.next/server/app/_global-error.html +1 -1
  6. package/.next/standalone/.next/server/app/_global-error.rsc +1 -1
  7. package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  8. package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  9. package/.next/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  10. package/.next/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  11. package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  12. package/.next/standalone/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  13. package/.next/standalone/.next/server/app/api/agent/activity/route.js.nft.json +1 -1
  14. package/.next/standalone/.next/server/app/api/agent/events/[...path]/route.js.nft.json +1 -1
  15. package/.next/standalone/.next/server/app/api/agent/files/[...path]/route.js.nft.json +1 -1
  16. package/.next/standalone/.next/server/app/api/agent/fs/file/[...path]/route.js.nft.json +1 -1
  17. package/.next/standalone/.next/server/app/api/agent/fs/ls/[[...path]]/route.js.nft.json +1 -1
  18. package/.next/standalone/.next/server/app/api/agent/fs/move/route.js.nft.json +1 -1
  19. package/.next/standalone/.next/server/app/api/agent/fs/search/route.js.nft.json +1 -1
  20. package/.next/standalone/.next/server/app/api/agent/internal/span/route.js.nft.json +1 -1
  21. package/.next/standalone/.next/server/app/api/agent/settings/route.js.nft.json +1 -1
  22. package/.next/standalone/.next/server/app/api/agent/sidecar/[...path]/route.js.nft.json +1 -1
  23. package/.next/standalone/.next/server/app/api/app-proxy/[...path]/route.js.nft.json +1 -1
  24. package/.next/standalone/.next/server/app/api/assets/[...path]/route.js.nft.json +1 -1
  25. package/.next/standalone/.next/server/app/api/pdf/save/route.js.nft.json +1 -1
  26. package/.next/standalone/.next/server/app/api/share/[token]/asset/route.js.nft.json +1 -1
  27. package/.next/standalone/.next/server/app/api/share/[token]/route.js.nft.json +1 -1
  28. package/.next/standalone/.next/server/app/api/share/route.js.nft.json +1 -1
  29. package/.next/standalone/.next/server/app/api/system/reveal/route.js.nft.json +1 -1
  30. package/.next/standalone/.next/server/app/api/system/workspaces/[id]/branch/route.js.nft.json +1 -1
  31. package/.next/standalone/.next/server/app/api/system/workspaces/[id]/open/route.js.nft.json +1 -1
  32. package/.next/standalone/.next/server/app/api/system/workspaces/[id]/refresh/route.js.nft.json +1 -1
  33. package/.next/standalone/.next/server/app/api/system/workspaces/[id]/route.js.nft.json +1 -1
  34. package/.next/standalone/.next/server/app/api/system/workspaces/route.js.nft.json +1 -1
  35. package/.next/standalone/.next/server/app/api/upload/[...path]/route.js.nft.json +1 -1
  36. package/.next/standalone/.next/server/app/api/wiki/app/route.js.nft.json +1 -1
  37. package/.next/standalone/.next/server/app/api/wiki/backlinks/route.js.nft.json +1 -1
  38. package/.next/standalone/.next/server/app/api/wiki/content/route.js.nft.json +1 -1
  39. package/.next/standalone/.next/server/app/api/wiki/download/route.js.nft.json +1 -1
  40. package/.next/standalone/.next/server/app/api/wiki/folder/route.js.nft.json +1 -1
  41. package/.next/standalone/.next/server/app/api/wiki/git-branches/route.js.nft.json +1 -1
  42. package/.next/standalone/.next/server/app/api/wiki/git-checkout/route.js.nft.json +1 -1
  43. package/.next/standalone/.next/server/app/api/wiki/git-diff/route.js.nft.json +1 -1
  44. package/.next/standalone/.next/server/app/api/wiki/git-file-info/route.js.nft.json +1 -1
  45. package/.next/standalone/.next/server/app/api/wiki/git-history/route.js.nft.json +1 -1
  46. package/.next/standalone/.next/server/app/api/wiki/git-pull/route.js.nft.json +1 -1
  47. package/.next/standalone/.next/server/app/api/wiki/move/route.js.nft.json +1 -1
  48. package/.next/standalone/.next/server/app/api/wiki/new-file/route.js.nft.json +1 -1
  49. package/.next/standalone/.next/server/app/api/wiki/outlinks/route.js.nft.json +1 -1
  50. package/.next/standalone/.next/server/app/api/wiki/page/route.js.nft.json +1 -1
  51. package/.next/standalone/.next/server/app/api/wiki/presence/route.js.nft.json +1 -1
  52. package/.next/standalone/.next/server/app/api/wiki/route.js.nft.json +1 -1
  53. package/.next/standalone/.next/server/app/api/wiki/search/route.js.nft.json +1 -1
  54. package/.next/standalone/.next/server/app/api/wiki/slugs/route.js.nft.json +1 -1
  55. package/.next/standalone/.next/server/app/api/wiki/upload/route.js.nft.json +1 -1
  56. package/.next/standalone/.next/server/app/api/wiki/watch/route.js.nft.json +1 -1
  57. package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  58. package/.next/standalone/.next/server/app/s/[token]/page_client-reference-manifest.js +1 -1
  59. package/.next/standalone/.next/server/app/signin/page_client-reference-manifest.js +1 -1
  60. package/.next/standalone/.next/server/chunks/ssr/_0oq8kwv._.js +1 -1
  61. package/.next/standalone/.next/server/middleware-build-manifest.js +3 -3
  62. package/.next/standalone/.next/server/pages/500.html +1 -1
  63. package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
  64. package/.next/standalone/.next/server/server-reference-manifest.json +1 -1
  65. package/.next/standalone/.next/static/chunks/{16a.4k1u_jc2v.js → 078zm3b1n76-7.js} +1 -1
  66. package/.next/standalone/.next/static/chunks/{06l3_t96g__d2.css → 0~uyhld0wvekn.css} +2 -2
  67. package/.next/standalone/package.json +1 -1
  68. package/.next/standalone/server.js +1 -1
  69. package/package.json +1 -1
  70. /package/.next/standalone/.next/static/{vlPEhXvukCQTNa1mne8yh → 3vqIsEfg3Z_zStz4UWIyh}/_buildManifest.js +0 -0
  71. /package/.next/standalone/.next/static/{vlPEhXvukCQTNa1mne8yh → 3vqIsEfg3Z_zStz4UWIyh}/_clientMiddlewareManifest.js +0 -0
  72. /package/.next/standalone/.next/static/{vlPEhXvukCQTNa1mne8yh → 3vqIsEfg3Z_zStz4UWIyh}/_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,f.useState)(""),p=(0,f.useRef)(null),m=window.location.origin,b=(0,f.useCallback)(()=>t9,[]),x=(0,f.useCallback)(()=>d.replace(/\$WIKI_URL/g,m),[d,m]),y=(0,f.useCallback)(()=>`npx wiki-viewer-mcp register --url ${m} --id ai:myagent --name "My Agent"`,[m]),w=(0,f.useCallback)(()=>JSON.stringify({servers:{"wiki-viewer":{command:"npx",args:["wiki-viewer-mcp"],env:{WIKI_VIEWER_URL:m,WIKI_VIEWER_TOKEN:"<token from register>",WIKI_VIEWER_AGENT_ID:"ai:myagent"}}}},null,2),[m]),k=t7(b),N=t7(x),S=t7(y),C=t7(w);return((0,f.useEffect)(()=>{if(t)return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e);function e(e){"Escape"===e.key&&n()}},[t,n]),(0,f.useEffect)(()=>{t&&p.current?.focus()},[t]),(0,f.useEffect)(()=>{if(!t)return;o();let e=setInterval(()=>void o(),1e4);return()=>clearInterval(e)},[t,o]),(0,f.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:"rounded-md border border-border bg-muted/30 p-3",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-foreground",children:"Work with this wiki using AI"}),(0,s.jsxs)("p",{className:"mt-1 text-xs leading-relaxed text-muted-foreground",children:["Connect Claude, Cursor, ChatGPT, and more. Pick by what you want — each option gives a copy-paste setup. You approve every assistant in ",(0,s.jsx)("span",{className:"font-medium text-foreground/80",children:"Agents"})," below before it gets access."]})]}),(0,s.jsxs)("section",{className:"space-y-3",children:[(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:"Co-write docs with you"}),(0,s.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Edits arrive as suggestions with comments you accept or revert. No MCP needed."}),(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)(tr.Copy,{className:"h-3.5 w-3.5"})," Paste into any chatbot"]})}),(0,s.jsxs)("p",{className:"text-[10px] text-muted-foreground/50 pt-1",children:["Or install once so it sticks"," ",(0,s.jsx)("span",{className:"text-muted-foreground/40",children:"· Claude, OpenCode"}),":"]}),(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:t9}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0",title:"Copy this command",onClick:()=>void k.copy(),children:k.copied?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"}):(0,s.jsx)(tr.Copy,{className:"h-3.5 w-3.5"})})]})]}),(0,s.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,s.jsxs)("p",{className:"text-xs font-semibold text-foreground",children:["Edit files directly"," ",(0,s.jsx)("span",{className:"font-normal text-muted-foreground/60",children:"· Claude Code, Cursor, Codex"})]}),(0,s.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Native read / search / edit tools over MCP. Run to request access:"}),(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)(tr.Copy,{className:"h-3.5 w-3.5"})})]}),(0,s.jsxs)("p",{className:"text-[10px] text-muted-foreground/50",children:["Approve in ",(0,s.jsx)("span",{className:"font-medium text-foreground/70",children:"Agents"}),", then add to your tool:"]}),(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)(tr.Copy,{className:"h-3.5 w-3.5"})," Copy config (mcp.json)"]})})]}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[(0,s.jsx)("span",{className:"text-[10px] text-muted-foreground/50",children:"For developers:"}),(0,s.jsxs)("button",{type:"button",onClick:()=>void c(),className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[l?(0,s.jsx)(g.Check,{className:"h-3 w-3 text-green-500"}):(0,s.jsx)(tr.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-[10px] text-primary hover:underline",children:[(0,s.jsx)(tT.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-[10px] text-primary hover:underline",children:[(0,s.jsx)(tT.ExternalLink,{className:"h-3 w-3"})," install JSON"]})]})]}),(0,s.jsx)(t$,{}),(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)(tA,{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)(t6,{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 ne=e.i(406347);let nt=(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"}]]),nn=(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"}]]),nr=(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"}]]),ni=(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"}]]),ns=(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"}]]),no=(0,o.default)("terminal",[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]]),na=(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 nl({pos:e,branches:t,loading:n,busyName:r,disabled:i,onPick:o,onClose:a}){let[l,c]=(0,f.useState)(""),d=(0,f.useRef)(null);if((0,f.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(),m=h?t.filter(e=>e.name.toLowerCase().includes(h)):t;return(0,tv.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===m.length?(0,s.jsx)("p",{className:"px-2 py-1 text-[10px] text-muted-foreground",children:"No match"}):m.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 nc=e.i(918552),nd=e.i(136131),nu="ContextMenu",[np,nh]=(0,N.createContextScope)(nu,[nc.createMenuScope]),nf=(0,nc.createMenuScope)(),[nm,ng]=np(nu),nb=e=>{let{__scopeContextMenu:t,children:n,onOpenChange:r,dir:i,modal:o=!0}=e,[a,l]=f.useState(!1),c=nf(t),d=(0,nd.useCallbackRef)(r),u=f.useCallback(e=>{l(e),d(e)},[d]);return(0,s.jsx)(nm,{scope:t,open:a,onOpenChange:u,modal:o,children:(0,s.jsx)(nc.Root,{...c,dir:i,open:a,onOpenChange:u,modal:o,children:n})})};nb.displayName=nu;var nx="ContextMenuTrigger",ny=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,disabled:r=!1,...i}=e,o=ng(nx,n),a=nf(n),l=f.useRef({x:0,y:0}),c=f.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...l.current})}),d=f.useRef(0),u=f.useCallback(()=>window.clearTimeout(d.current),[]),p=e=>{l.current={x:e.clientX,y:e.clientY},o.onOpenChange(!0)};return f.useEffect(()=>u,[u]),f.useEffect(()=>void(r&&u()),[r,u]),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(nc.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,nO(e=>{u(),d.current=window.setTimeout(()=>p(e),700)})),onPointerMove:r?e.onPointerMove:(0,w.composeEventHandlers)(e.onPointerMove,nO(u)),onPointerCancel:r?e.onPointerCancel:(0,w.composeEventHandlers)(e.onPointerCancel,nO(u)),onPointerUp:r?e.onPointerUp:(0,w.composeEventHandlers)(e.onPointerUp,nO(u))})]})});ny.displayName=nx;var nv=e=>{let{__scopeContextMenu:t,...n}=e,r=nf(t);return(0,s.jsx)(nc.Portal,{...r,...n})};nv.displayName="ContextMenuPortal";var nw="ContextMenuContent",nk=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=ng(nw,n),o=nf(n),a=f.useRef(!1);return(0,s.jsx)(nc.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)"}})});nk.displayName=nw,f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Group,{...i,...r,ref:t})}).displayName="ContextMenuGroup";var nN=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Label,{...i,...r,ref:t})});nN.displayName="ContextMenuLabel";var nS=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Item,{...i,...r,ref:t})});nS.displayName="ContextMenuItem";var nC=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.CheckboxItem,{...i,...r,ref:t})});nC.displayName="ContextMenuCheckboxItem",f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.RadioGroup,{...i,...r,ref:t})}).displayName="ContextMenuRadioGroup";var nj=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.RadioItem,{...i,...r,ref:t})});nj.displayName="ContextMenuRadioItem";var nE=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.ItemIndicator,{...i,...r,ref:t})});nE.displayName="ContextMenuItemIndicator";var nM=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Separator,{...i,...r,ref:t})});nM.displayName="ContextMenuSeparator",f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Arrow,{...i,...r,ref:t})}).displayName="ContextMenuArrow";var nA=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.SubTrigger,{...i,...r,ref:t})});nA.displayName="ContextMenuSubTrigger";var nT=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.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 nO(e){return t=>"mouse"!==t.pointerType?e(t):void 0}nT.displayName="ContextMenuSubContent";var n_=e.i(149427);f.forwardRef(({className:e,inset:t,children:n,...r},i)=>(0,s.jsxs)(nA,{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)(e3.ChevronRight,{className:"ml-auto h-4 w-4"})]})).displayName=nA.displayName,f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(nT,{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=nT.displayName;let nD=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(nv,{children:(0,s.jsx)(nk,{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})}));nD.displayName=nk.displayName;let nR=f.forwardRef(({className:e,inset:t,...n},r)=>(0,s.jsx)(nS,{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}));nR.displayName=nS.displayName,f.forwardRef(({className:e,children:t,checked:n,...r},i)=>(0,s.jsxs)(nC,{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)(nE,{children:(0,s.jsx)(g.Check,{className:"h-4 w-4"})})}),t]})).displayName=nC.displayName,f.forwardRef(({className:e,children:t,...n},r)=>(0,s.jsxs)(nj,{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)(nE,{children:(0,s.jsx)(n_.Circle,{className:"h-2 w-2 fill-current"})})}),t]})).displayName=nj.displayName,f.forwardRef(({className:e,inset:t,...n},r)=>(0,s.jsx)(nN,{ref:r,className:(0,eh.cn)("px-2 py-1.5 text-sm font-normal",t&&"pl-8",e),...n})).displayName=nN.displayName;let nI=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(nM,{ref:n,className:(0,eh.cn)("-mx-1 my-1 h-px bg-muted",e),...t}));nI.displayName=nM.displayName;let nL="wiki-humanize-names",nP=(0,eN.create)((e,t)=>({humanize:"1"===localStorage.getItem(nL),toggle:()=>{let n=!t().humanize;n?localStorage.setItem(nL,"1"):localStorage.removeItem(nL),e({humanize:n})}})),nz="wiki-show-hidden",n$=(0,eN.create)((e,t)=>({showHidden:"1"===localStorage.getItem(nz),toggle:()=>{let n=!t().showHidden;n?localStorage.setItem(nz,"1"):localStorage.removeItem(nz),e({showHidden:n})}}));function nB(e){return e.split(".").pop()?.toLowerCase()??""}function nF(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=nB(e);return r?["md","markdown"].includes(r)?"editor":"txt"===r?"text":["csv","tsv"].includes(r)?"csv":"pdf"===r?"pdf":["mmd","mermaid"].includes(r)?"mermaid":"ipynb"===r?"notebook":["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"}let nH=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 nU(e){let t=nF(e,"file");return"editor"===t||"text"===t||nH.has(nB(e))}function nV(e){return["md","markdown"].includes(nB(e))}function nW(e){return"image"===nF(e,"file")}function nq(e){return"html"===nF(e,"file")}let nK={contentVisibility:"auto",containIntrinsicSize:"auto 32px"};function nG({node:e,ctx:t,isFavorited:n,activeWorkspaceId:r}){return(0,s.jsxs)(nD,{className:"w-48",children:[(0,s.jsxs)(nR,{onSelect:()=>t.copyPath(e.path),children:[(0,s.jsx)(tr.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),nV(e.name)&&(0,s.jsxs)(nR,{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)(nR,{onSelect:()=>t.copyUrl(e.path),children:[(0,s.jsx)(nt,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),"file"===e.type&&nU(e.name)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(nR,{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)(nR,{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)(nI,{}),"dir"===e.type&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(nR,{onSelect:()=>{e.expanded||t.toggleFolder(e),t.setNewFileParent(e.path),t.setNewFileName(""),t.setFileCreateError(null)},children:[(0,s.jsx)(ni,{className:"mr-2 h-3.5 w-3.5"}),"New file here"]}),(0,s.jsxs)(nR,{onSelect:()=>t.triggerUpload(e.path),children:[(0,s.jsx)(na,{className:"mr-2 h-3.5 w-3.5"}),"Upload here"]}),(0,s.jsxs)(nR,{onSelect:()=>{t.setNewFolderParent(e.path),t.setNewFolderName(""),t.setFolderError(null)},children:[(0,s.jsx)(ns,{className:"mr-2 h-3.5 w-3.5"}),"New subfolder"]}),(0,s.jsx)(nI,{})]}),(0,s.jsxs)(nR,{onSelect:()=>t.handleDownload(e),children:[(0,s.jsx)(ne.Download,{className:"mr-2 h-3.5 w-3.5"}),"file"===e.type?"Download":"Download as zip"]}),(0,s.jsxs)(nR,{onSelect:()=>t.toggleFavorite(e,r),children:[(0,s.jsx)(te,{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)(nI,{}),(0,s.jsxs)(nR,{className:"text-destructive focus:text-destructive",onSelect:()=>{t.setDeletingPath(e.path),t.setDeletingIsDir("file"!==e.type)},children:[(0,s.jsx)(ts,{className:"mr-2 h-3.5 w-3.5"}),"Delete"]})]})}function nJ({name:e,type:t}){let n="h-3.5 w-3.5 shrink-0";return"dir"===t?(0,s.jsx)(e5,{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)(no,{className:(0,eh.cn)(n,"text-emerald-500")}):nq(e)?(0,s.jsx)(c,{className:(0,eh.cn)(n,"text-foreground/60")}):nW(e)?(0,s.jsx)(d.Image,{className:(0,eh.cn)(n,"text-sunshine-700")}):nU(e)?(0,s.jsx)(l.FileText,{className:(0,eh.cn)(n,"text-foreground/70")}):(0,s.jsx)(nr,{className:(0,eh.cn)(n,"text-foreground/60")})}let nZ=(0,f.memo)(function({node:e,depth:t,ctx:n,isMobile:r,activeWorkspaceId:i,sidebarScrollRef:o,isActive:a,isDragOver:p,isFavorited:h,isAgentActive:f,isPulling:m,branchOpen:g,branchPos:b,branches:x,branchLoading:y,checkingOut:w,onHoverEnter:k,onHoverLeave:N}){var S;let C,j,E,M,A,T=nP(e=>e.humanize);return(0,s.jsxs)(nb,{children:[(0,s.jsx)(ny,{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`,...nK},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)(e3.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)(e4,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):(0,s.jsx)(e5,{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)(no,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-emerald-500")}):nq(e.name)?(0,s.jsx)(c,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/60")}):nW(e.name)?(0,s.jsx)(d.Image,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-sunshine-700")}):nU(e.name)?(0,s.jsx)(l.FileText,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):(0,s.jsx)(nr,{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)(e6,{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:"*"})]}),m?(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)(tR,{className:"h-2.5 w-2.5"})}),g&&b&&(0,s.jsx)(nl,{pos:b,branches:x,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)}})]}),f&&(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)(nn,{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)(tr.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),nV(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)(nt,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),"file"===e.type&&nU(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)(ni,{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)(na,{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)(ns,{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)(ne.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)(te,{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)(ts,{className:"mr-2 h-3.5 w-3.5"}),"Delete"]})]})]})})]})}),(0,s.jsx)(nG,{node:e,ctx:n,isFavorited:h,activeWorkspaceId:i})]})}),nX=(0,f.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:m,isMobile:b,activeWorkspaceId:x,newFileParent:y,newFileName:w,fileCreateError:k,newFolderParent:N,newFolderName:S,folderError:C,sidebarScrollRef:j}=e,E=n$(e=>e.showHidden),M=(0,f.useRef)(null),A=(0,f.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,f.useCallback)(()=>{M.current&&(clearTimeout(M.current),M.current=null)},[]),O=(0,f.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:f,depth:y}=e;if("row"===e.kind){let e=i===f.path;return(0,s.jsx)(nZ,{node:f,depth:y,ctx:t,isMobile:b,activeWorkspaceId:x,sidebarScrollRef:j,isActive:n===f.path,isDragOver:r===f.path,isFavorited:m.some(e=>e.path===f.path),isAgentActive:p.has(f.path),isPulling:u===f.path,branchOpen:e,branchPos:e?o:null,branches:f.git?a[f.path]??[]:[],branchLoading:!!f.git&&!!c[f.path],checkingOut:e?d:null,onHoverEnter:A,onHoverLeave:T},f.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`,...nK},children:[(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)(e5,{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-${f.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`,...nK},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,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-${f.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`,...nK},children:"Empty"},`empty-${f.path}`)})})});function nY(e){return e?`wiki-pinned-files-${e}`:"wiki-pinned-files"}function nQ(e){try{let t=localStorage.getItem(nY(e));return t?JSON.parse(t):[]}catch{return[]}}let n0=(0,eN.create)((e,t)=>({favorites:[],loadForWorkspace:t=>{e({favorites:nQ(t)})},toggle:(t,n)=>{let r=nQ(n),i=r.some(e=>e.path===t.path)?r.filter(e=>e.path!==t.path):[...r,t];localStorage.setItem(nY(n),JSON.stringify(i)),e({favorites:i})},isFavorited:e=>t().favorites.some(t=>t.path===e)}));function n1({doc:e,node:t,extraItems:n,activeWorkspaceId:r=null}){let i=n0(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)(nn,{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,tE.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)(ne.Download,{className:"mr-2 h-3.5 w-3.5"}),"Download"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>{n0.getState().toggle({path:t.path,name:t.name},r)},children:[(0,s.jsx)(te,{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)(tr.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),nV(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)(nt,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),nU(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 n2=(0,o.default)("align-center",[["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 18H5",key:"18s9l3"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);var n3=e.i(409082);let n5=(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 n4=e.i(847463),n6=e.i(917356),n9=/[\\\/_+.#"@\[\(\{&]/,n7=/[\\\/_+.#"@\[\(\{&]/g,n8=/[\s-]/,re=/[\s-]/g;function rt(e){return e.toLowerCase().replace(re," ")}var rn='[cmdk-group=""]',rr='[cmdk-group-items=""]',ri='[cmdk-item=""]',rs=`${ri}:not([aria-disabled="true"])`,ro="cmdk-item-select",ra="data-value",rl=(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),f=r.indexOf(h,s),m=0;f>=0;)(c=e(t,n,r,i,f+1,o+1,a))>m&&(f===s?c*=1:n9.test(t.charAt(f-1))?(c*=.8,(u=t.slice(s,f-1).match(n7))&&s>0&&(c*=Math.pow(.999,u.length))):n8.test(t.charAt(f-1))?(c*=.9,(p=t.slice(s,f-1).match(re))&&s>0&&(c*=Math.pow(.999,p.length))):(c*=.17,s>0&&(c*=Math.pow(.999,f-s))),t.charAt(f)!==n.charAt(o)&&(c*=.9999)),(c<.1&&r.charAt(f-1)===i.charAt(o+1)||i.charAt(o+1)===i.charAt(o)&&r.charAt(f-1)!==i.charAt(o))&&.1*(d=e(t,n,r,i,f+1,o+2,a))>c&&(c=.1*d),c>m&&(m=c),f=r.indexOf(h,f+1);return a[l]=m,m}(r=n&&n.length>0?`${r+" "+n.join(" ")}`:r,t,rt(r),rt(t),0,0,{})},rc=f.createContext(void 0),rd=f.createContext(void 0),ru=f.createContext(void 0),rp=f.forwardRef((e,t)=>{let n=rk(()=>{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=rk(()=>new Set),i=rk(()=>new Map),s=rk(()=>new Map),o=rk(()=>new Set),a=rv(e),{label:l,children:c,value:d,onValueChange:u,filter:p,shouldFilter:h,loop:m,disablePointerSelection:g=!1,vimBindings:b=!0,...x}=e,y=(0,S.useId)(),v=(0,S.useId)(),w=(0,S.useId)(),k=f.useRef(null),N=rC();rw(()=>{if(void 0!==d){let e=d.trim();n.current.value=e,C.emit()}},[d]),rw(()=>{N(6,O)},[]);let C=f.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=f.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:rl;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(rr);t?t.appendChild(e.parentElement===t?e:e.closest(`${rr} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${rr} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{var t;let n=null==(t=k.current)?void 0:t.querySelector(`${rn}[${ra}="${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(ra);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(rn))?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(`${ri}[aria-selected="true"]`)}function D(){var e;return Array.from((null==(e=k.current)?void 0:e.querySelectorAll(rs))||[])}function R(e){let t=D()[e];t&&C.setState("value",t.getAttribute(ra))}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(ra))}function L(e){let t=_(),n=null==t?void 0:t.closest(rn),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,rn):function(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}(n,rn))?void 0:n.querySelector(rs);r?C.setState("value",r.getAttribute(ra)):I(e)}let P=()=>R(D().length-1),z=e=>{e.preventDefault(),e.metaKey?P():e.altKey?L(1):I(1)},$=e=>{e.preventDefault(),e.metaKey?R(0):e.altKey?L(-1):I(-1)};return f.createElement(tk.div,{ref:t,tabIndex:-1,...x,"cmdk-root":"",onKeyDown:e=>{var t;null==(t=x.onKeyDown)||t.call(x,e);let n=e.nativeEvent.isComposing||229===e.keyCode;if(!(e.defaultPrevented||n))switch(e.key){case"n":case"j":b&&e.ctrlKey&&z(e);break;case"ArrowDown":z(e);break;case"p":case"k":b&&e.ctrlKey&&$(e);break;case"ArrowUp":$(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(ro);t.dispatchEvent(e)}}}}},f.createElement("label",{"cmdk-label":"",htmlFor:j.inputId,id:j.labelId,style:rE},l),rj(e,e=>f.createElement(rd.Provider,{value:C},f.createElement(rc.Provider,{value:j},e))))}),rh=f.forwardRef((e,t)=>{var n,r;let i=(0,S.useId)(),s=f.useRef(null),o=f.useContext(ru),a=f.useContext(rc),l=rv(e),c=null!=(r=null==(n=l.current)?void 0:n.forceMount)?r:null==o?void 0:o.forceMount;rw(()=>{if(!c)return a.item(i,null==o?void 0:o.id)},[c]);let d=rS(i,s,[e.value,e.children,s],e.keywords),u=f.useContext(rd),p=rN(e=>e.value&&e.value===d.current),h=rN(e=>!!c||!1===a.filter()||!e.search||e.filtered.items.get(i)>0);function m(){var e,t;g(),null==(t=(e=l.current).onSelect)||t.call(e,d.current)}function g(){u.setState("value",d.current,!0)}if(f.useEffect(()=>{let t=s.current;if(!(!t||e.disabled))return t.addEventListener(ro,m),()=>t.removeEventListener(ro,m)},[h,e.onSelect,e.disabled]),!h)return null;let{disabled:b,value:x,onSelect:y,forceMount:v,keywords:w,...N}=e;return f.createElement(tk.div,{ref:(0,k.composeRefs)(s,t),...N,id:i,"cmdk-item":"",role:"option","aria-disabled":!!b,"aria-selected":!!p,"data-disabled":!!b,"data-selected":!!p,onPointerMove:b||a.getDisablePointerSelection()?void 0:g,onClick:b?void 0:m},e.children)}),rf=f.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...s}=e,o=(0,S.useId)(),a=f.useRef(null),l=f.useRef(null),c=(0,S.useId)(),d=f.useContext(rc),u=rN(e=>!!i||!1===d.filter()||!e.search||e.filtered.groups.has(o));rw(()=>d.group(o),[]),rS(o,a,[e.value,e.heading,l]);let p=f.useMemo(()=>({id:o,forceMount:i}),[i]);return f.createElement(tk.div,{ref:(0,k.composeRefs)(a,t),...s,"cmdk-group":"",role:"presentation",hidden:!u||void 0},n&&f.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:c},n),rj(e,e=>f.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?c:void 0},f.createElement(ru.Provider,{value:p},e))))}),rm=f.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=f.useRef(null),s=rN(e=>!e.search);return n||s?f.createElement(tk.div,{ref:(0,k.composeRefs)(i,t),...r,"cmdk-separator":"",role:"separator"}):null}),rg=f.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=null!=e.value,s=f.useContext(rd),o=rN(e=>e.search),a=rN(e=>e.selectedItemId),l=f.useContext(rc);return f.useEffect(()=>{null!=e.value&&s.setState("search",e.value)},[e.value]),f.createElement(tk.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)}})}),rb=f.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...i}=e,s=f.useRef(null),o=f.useRef(null),a=rN(e=>e.selectedItemId),l=f.useContext(rc);return f.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)}}},[]),f.createElement(tk.div,{ref:(0,k.composeRefs)(s,t),...i,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:l.listId},rj(e,e=>f.createElement("div",{ref:(0,k.composeRefs)(o,l.listInnerRef),"cmdk-list-sizer":""},e)))}),rx=f.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:s,container:o,...a}=e;return f.createElement(B,{open:n,onOpenChange:r},f.createElement(W,{container:o},f.createElement(K,{"cmdk-overlay":"",className:i}),f.createElement(X,{"aria-label":e.label,"cmdk-dialog":"",className:s},f.createElement(rp,{ref:t,...a}))))}),ry=Object.assign(rp,{List:rb,Item:rh,Input:rg,Group:rf,Separator:rm,Dialog:rx,Empty:f.forwardRef((e,t)=>rN(e=>0===e.filtered.count)?f.createElement(tk.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),Loading:f.forwardRef((e,t)=>{let{progress:n,children:r,label:i="Loading...",...s}=e;return f.createElement(tk.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},rj(e,e=>f.createElement("div",{"aria-hidden":!0},e)))})});function rv(e){let t=f.useRef(e);return rw(()=>{t.current=e}),t}var rw="u"<typeof window?f.useEffect:f.useLayoutEffect;function rk(e){let t=f.useRef();return void 0===t.current&&(t.current=e()),t}function rN(e){let t=f.useContext(rd),n=()=>e(t.snapshot());return f.useSyncExternalStore(t.subscribe,n,n)}function rS(e,t,n,r=[]){let i=f.useRef(),s=f.useContext(rc);return rw(()=>{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(ra,a),i.current=a}),i}var rC=()=>{let[e,t]=f.useState(),n=rk(()=>new Map);return rw(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function rj({asChild:e,children:t},n){let r;return e&&f.isValidElement(t)?f.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 rE={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};let rM=(0,o.default)("search",[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]),rA=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry,{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 rT({children:e,shouldFilter:t,...n}){return(0,s.jsx)(B,{...n,children:(0,s.jsxs)(eX,{className:"overflow-hidden p-0 shadow-golden max-w-lg",children:[(0,s.jsx)(e0,{className:"sr-only",children:"Search"}),(0,s.jsx)(rA,{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})]})})}rA.displayName=ry.displayName;let rO=f.forwardRef(({className:e,...t},n)=>(0,s.jsxs)("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[(0,s.jsx)(rM,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),(0,s.jsx)(ry.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})]}));rO.displayName=ry.Input.displayName;let r_=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry.List,{ref:n,className:(0,eh.cn)("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));r_.displayName=ry.List.displayName;let rD=f.forwardRef((e,t)=>(0,s.jsx)(ry.Empty,{ref:t,className:"py-6 text-center text-sm text-muted-foreground",...e}));rD.displayName=ry.Empty.displayName;let rR=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry.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}));rR.displayName=ry.Group.displayName;let rI=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry.Separator,{ref:n,className:(0,eh.cn)("-mx-1 h-px bg-border",e),...t}));rI.displayName=ry.Separator.displayName;let rL=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry.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}));rL.displayName=ry.Item.displayName;let rP=null,rz=null,r$=(0,eN.create)(e=>({query:"",results:[],loading:!1,truncated:!1,open:!1,setQuery:t=>e({query:t}),setOpen:t=>e({open:t}),clear:()=>{rz&&clearTimeout(rz),rP?.abort(),e({query:"",results:[],loading:!1,truncated:!1})},search:t=>(rz&&clearTimeout(rz),t.trim())?(e({loading:!0}),new Promise(n=>{rz=setTimeout(()=>{rB(e,t).finally(n)},150)})):(rP?.abort(),e({results:[],loading:!1,truncated:!1}),Promise.resolve())}));async function rB(e,t){rP?.abort();let n=new AbortController;rP=n;try{let r=await (0,tE.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 rF=e.i(395624);function rH({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 rU({onOpenFile:e,recents:t=[],onToggleSidebar:n=()=>void 0,onNewFile:r=()=>void 0,onCopyPath:i=()=>void 0}){let o=r$(e=>e.open),l=r$(e=>e.setOpen),c=r$(e=>e.query),d=r$(e=>e.setQuery),u=r$(e=>e.results),p=r$(e=>e.loading),h=r$(e=>e.truncated),m=r$(e=>e.search),{resolvedTheme:g,setTheme:b}=(0,n6.useTheme)(),x=tO(e=>e.toggle),y=(0,rF.useViewWidthStore)(e=>e.width),v=(0,rF.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,f.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,f.useEffect)(()=>{if(!o||k)return;let e=setTimeout(()=>{m(S)},120);return()=>clearTimeout(e)},[S,k,o,m]);let j=(rF.VIEW_WIDTH_ORDER.indexOf(y)+1)%rF.VIEW_WIDTH_ORDER.length,E=rF.VIEW_WIDTH_LABEL[rF.VIEW_WIDTH_ORDER[j]];return(0,s.jsxs)(rT,{open:o,onOpenChange:e=>{l(e),e||d("")},shouldFilter:!1,children:[(0,s.jsx)(rO,{placeholder:"Search files… ( > for actions )",value:c,onValueChange:d}),(0,s.jsxs)(r_,{children:[N&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(rR,{heading:"Recent",children:t.map(t=>(0,s.jsxs)(rL,{value:`recent:${t.path}`,onSelect:()=>{e(t.path),l(!1),d("")},children:[(0,s.jsx)(to,{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)(rI,{})]}),k&&(0,s.jsxs)(rR,{heading:"Actions",children:[(0,s.jsxs)(rL,{value:"toggle-dark-mode",onSelect:()=>C(()=>b("dark"===g?"light":"dark")),children:["dark"===g?(0,s.jsx)(n4.Sun,{className:"mr-2 h-4 w-4"}):(0,s.jsx)(n3.Moon,{className:"mr-2 h-4 w-4"}),"dark"===g?"Switch to light mode":"Switch to dark mode"]}),(0,s.jsxs)(rL,{value:"toggle-ai-panel",onSelect:()=>C(x),children:[(0,s.jsx)(a,{className:"mr-2 h-4 w-4"}),"Toggle AI panel"]}),(0,s.jsxs)(rL,{value:"toggle-sidebar",onSelect:()=>C(n),children:[(0,s.jsx)(n5,{className:"mr-2 h-4 w-4"}),"Toggle sidebar"]}),(0,s.jsxs)(rL,{value:"new-file",onSelect:()=>C(r),children:[(0,s.jsx)(ni,{className:"mr-2 h-4 w-4"}),"New file"]}),(0,s.jsxs)(rL,{value:"copy-path",onSelect:()=>C(i),children:[(0,s.jsx)(tr.Copy,{className:"mr-2 h-4 w-4"}),"Copy current file path"]}),(0,s.jsxs)(rL,{value:"cycle-view-width",onSelect:()=>C(v),children:[(0,s.jsx)(n2,{className:"mr-2 h-4 w-4"}),(0,s.jsxs)("span",{children:["Change view width"," ",(0,s.jsxs)("span",{className:"text-muted-foreground",children:["(",rF.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)(rD,{children:"No matches."}),u.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(rI,{}),(0,s.jsx)(rR,{heading:h?"Top results (refine query for more)":"Results",children:u.map(t=>(0,s.jsx)(rL,{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)(rH,{html:t.snippet})})]})},t.path))})]})]})]})]})}e.i(335884);let rV=(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 rW=e.i(301138);let rq=(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"}]]),rK=(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"}]]),rG=(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"}]]),rJ=(0,o.default)("plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]),rZ=(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 rX=e.i(109680);function rY({onOpenFile:e}){let t=r$(e=>e.query),n=r$(e=>e.setQuery),r=r$(e=>e.results),i=r$(e=>e.loading),o=r$(e=>e.search),a=r$(e=>e.clear),[l,c]=(0,f.useState)(0),d=(0,f.useRef)(null);function u(t){let n=r[t];n&&(e(n.path),a())}return(0,f.useEffect)(()=>{c(0)},[r]),(0,f.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)(rM,{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)(rH,{html:e.snippet})})]},e.path))]})]})}var rQ=e.i(515288);function r0(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 r1({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:f,setBranchPickerWsId:m,setWsBranchPos:x,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||(m(null),x(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)(b,{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){m(null),x(null);return}let n=t.currentTarget.getBoundingClientRect();x({top:n.bottom+4,left:n.left}),m(e.id),y(e.id)},children:[(0,s.jsx)(e6,{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)(e6,{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)(e7,{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)(e6,{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&&r0(e.git.lastPulledAt)&&(0,s.jsxs)("span",{className:"text-[10px] text-muted-foreground/70",children:["synced ",r0(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)(tR,{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)(ts,{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:f,children:[(0,s.jsx)(ns,{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)(nl,{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:()=>{m(null),x(null)}}):null})()]})}let r2="wiki-sidebar-width";function r3(e){return Number.isNaN(e)?288:Math.min(600,Math.max(200,Math.round(e)))}let r5=(0,eN.create)(e=>({width:function(){let e=localStorage.getItem(r2);if(e){let t=Number.parseInt(e,10);if(!Number.isNaN(t))return r3(t)}return 288}(),setWidth:t=>{let n=r3(t);localStorage.setItem(r2,String(n)),e({width:n})}}));function r4(e){return e.split("/").pop()??e}function r6({workspace:e,doc:t,fileTree:n,upload:r,isMobile:i,hideChrome:o,sidebarCollapsed:c,setSidebarCollapsed:d,sidebarResizing:p,setSidebarResizing:f,sidebarWidth:x,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:z,setTheme:$}=(0,n6.useTheme)(),B=nP(e=>e.humanize),F=n$(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)(rQ.Card,{style:i?void 0:{width:x},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.11.3",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)(rG,{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)(rJ,{className:"h-3.5 w-3.5"}),"New",(0,s.jsx)(b,{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)(ni,{className:"mr-2 h-3.5 w-3.5"}),"New file"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>S(e=>({...e,folder:{...e.folder,parent:"",name:"",error:null}})),children:[(0,s.jsx)(ns,{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)(na,{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)(tR,{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:()=>{tO.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)(nn,{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)(rV,{className:"mr-2 h-3.5 w-3.5"}),"Pull latest"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n$.getState().toggle(),children:[F?(0,s.jsx)(rq,{className:"mr-2 h-3.5 w-3.5"}):(0,s.jsx)(rW.Eye,{className:"mr-2 h-3.5 w-3.5"}),F?"Hide hidden files":"Show hidden files"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>nP.getState().toggle(),children:[(0,s.jsx)(rX.Type,{className:"mr-2 h-3.5 w-3.5"}),B?"Raw file names":"Humanize names"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>$("dark"===z?"light":"dark"),children:["dark"===z?(0,s.jsx)(n4.Sun,{className:"mr-2 h-3.5 w-3.5"}):(0,s.jsx)(n3.Moon,{className:"mr-2 h-3.5 w-3.5"}),"dark"===z?"Light mode":"Dark mode"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>L(e=>({...e,settingsOpen:!0})),children:[(0,s.jsx)(rZ,{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)(m.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)(e5,{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)(rY,{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)(e3.ChevronRight,{className:"h-3 w-3"}):(0,s.jsx)(b,{className:"h-3 w-3"}),(0,s.jsx)(te,{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)(nb,{children:[(0,s.jsx)(ny,{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)(nJ,{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?r4(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(),n0.getState().toggle({path:n.path,name:n.name},e.activeWorkspaceId)},children:(0,s.jsx)(h,{className:"h-3 w-3"})})]})}),(0,s.jsx)(nG,{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)(e3.ChevronRight,{className:"h-3 w-3"}):(0,s.jsx)(b,{className:"h-3 w-3"}),(0,s.jsx)(rK,{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)(nb,{children:[(0,s.jsx)(ny,{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)(nJ,{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?r4(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)(nG,{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))]}),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)(na,{className:"h-3.5 w-3.5"}),"Upload Files"]})]}):(0,s.jsx)(nX,{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)(r1,{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;f(!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(x+(e.clientX-t))},s=()=>{f(!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(x-16)):"ArrowRight"===e.key&&(e.preventDefault(),y(x+16))},tabIndex:0,"aria-valuemin":200,"aria-valuemax":600,"aria-valuenow":x,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")})]})]})}function r9({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[m,g]=(0,f.useState)(!1),[b,x]=(0,f.useState)(null),[y,v]=(0,f.useState)({favorites:!1,recent:!0}),[w,k]=(0,f.useState)({file:{parent:null,name:"",error:null},folder:{parent:null,name:"",error:null}}),N=(0,f.useRef)(null),S=(0,f.useRef)(null),C=r5(e=>e.width),j=r5(e=>e.setWidth),E=(0,f.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,tE.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,f.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,tE.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",x("root"===n?"":t));return}r.path===t||t.startsWith(`${r.path}/`)||(e.dataTransfer.dropEffect="move",x("root"===n?"":t))}async function T(e,i){e.preventDefault(),e.stopPropagation(),x(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,tE.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,f.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,tE.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)=>n0.getState().toggle({path:e.path,name:e.name,type:e.type},t),setDragOverPath:x,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,f.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)(rU,{onOpenFile:t.openFromSearch,recents:d,onToggleSidebar:()=>l(e=>{let t=!e;return i&&!1===t&&tO.getState().close(),t}),onNewFile:()=>k(e=>({...e,file:{...e.file,parent:""}})),onCopyPath:()=>{t.openFile&&t.copyPath(t.openFile.path)}}),(0,s.jsx)(r6,{workspace:e,doc:t,fileTree:n,upload:r,isMobile:i,hideChrome:o,sidebarCollapsed:a,setSidebarCollapsed:l,sidebarResizing:m,setSidebarResizing:g,sidebarWidth:C,setSidebarWidth:j,collapsed:y,setCollapsed:v,createEntry:w,setCreateEntry:k,handleCreateFile:E,handleCreateFolder:M,dragOverPath:b,setDragOverPath:x,handleDragOver:A,handleDropOnFolder:T,sidebarScrollRef:N,treeCtx:_,favorites:c,recents:d,activePaths:u,setDialogs:h,handleRefreshWorkspace:e.handleRefreshWorkspace})]})}let r7=(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"}]]),r8=(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"}]]),ie=(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"}]]),it=(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"}]]),ir=(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 ii=e.i(75470),is=e.i(801273),io=e.i(61086);function ia(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 il(e){return e.map(e=>e.map(e=>e.includes(",")||e.includes('"')||e.includes("\n")?`"${e.replace(/"/g,'""')}"`:e).join(",")).join("\n")}function ic({path:e}){let[t,n]=(0,f.useState)([]),[r,i]=(0,f.useState)(""),[o,a]=(0,f.useState)(!1),[l,c]=(0,f.useState)(!1),[d,u]=(0,f.useState)(!1),[p,h]=(0,f.useState)(null),[m,g]=(0,f.useState)(!1),[b,x]=(0,f.useState)(1e3),y=(0,tE.withWs)(`/api/assets/${e}`);(0,f.useEffect)(()=>{fetch(y).then(e=>e.text()).then(e=>{let t=ia(e),r=e.length>2097152||t.length>2e3;i(e),n(t),g(r),a(r),c(!1)})},[y]);let w=(0,f.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:il(t);try{await (0,tE.wsFetch)(`/api/assets/${e}`,{method:"PUT",headers:{"Content-Type":"text/plain"},body:s}),o?n(ia(r)):i(s),c(!1)}catch(e){console.error("Failed to save CSV:",e)}u(!1)},N=t[0]||[],S=t.slice(1),C=m?S.slice(0,b):S,j=m&&b<S.length;return(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)(io.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)(is.Save,{className:"h-3.5 w-3.5"}),d?"Saving...":"Save"]}),m&&(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(ia(r)):i(il(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)(r7,{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)(ne.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:()=>x(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-b).toLocaleString()," ","more rows"]}),(0,s.jsxs)("span",{className:"text-[11px] text-muted-foreground",children:[b.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 id(e){this.content=e}id.prototype={constructor:id,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 id(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 id(n)},addToStart:function(e,t){return new id([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var n=this.remove(e).content.slice();return n.push(e,t),new id(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 id(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=id.from(e)).size?new id(e.content.concat(this.subtract(e).content)):this},append:function(e){return(e=id.from(e)).size?new id(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=id.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}},id.from=function(e){if(e instanceof id)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new id(t)};class iu{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 iu(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 iu(n,r)}cutByIndex(e,t){return e==t?iu.empty:0==e&&t==this.content.length?this:new iu(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 iu(r,i)}addToStart(e){return new iu([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new iu(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 ih(0,e);if(e==this.size)return ih(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 ih(t+1,r);return ih(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 iu.empty;if(!Array.isArray(t))throw RangeError("Invalid input for Fragment.fromJSON");return iu.fromArray(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return iu.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 iu(t||e,n)}static from(e){if(!e)return iu.empty;if(e instanceof iu)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new iu([e],e.nodeSize);throw RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}iu.empty=new iu([],0);let ip={index:0,offset:0};function ih(e,t){return ip.index=e,ip.offset=t,ip}function im(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(!im(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!im(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}class ig{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&&im(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 ig.none;if(e instanceof ig)return[e];let t=e.slice();return t.sort((e,t)=>e.type.rank-t.type.rank),t}}ig.none=[];class ib 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(iu.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 ib("Cannot join "+t.type.name+" onto "+e.type.name)}function iv(e,t,n){let r=e.node(n);return iy(r,t.node(n)),r}function iw(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 ik(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&&(iw(e.nodeAfter,r),s++));for(let e=s;e<o;e++)iw(i.child(e),r);t&&t.depth==n&&t.textOffset&&iw(t.nodeBefore,r)}function iN(e,t){return e.type.checkContent(t),e.copy(t)}function iS(e,t,n){let r=[];return ik(null,e,n,r),e.depth>n&&iw(iN(iv(e,t,n+1),iS(e,t,n+1)),r),ik(t,null,n,r),new iu(r)}ix.empty=new ix(iu.empty,0,0);class iC{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 ig.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 iA(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 iC(t,n,i)}static resolveCached(e,t){let n=iM.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 iM.set(e,n=new ij);let r=n.elts[n.i]=iC.resolve(e,t);return n.i=(n.i+1)%iE,r}}class ij{constructor(){this.elts=[],this.i=0}}let iE=12,iM=new WeakMap;class iA{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 iT=Object.create(null);class iO{constructor(e,t,n,r=ig.none){this.type=e,this.attrs=t,this.marks=r,this.content=n||iu.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&&im(this.attrs,t||e.defaultAttrs||iT)&&ig.sameSet(this.marks,n||ig.none)}copy(e=null){return e==this.content?this:new iO(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new iO(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 ib("Inserted content deeper than insertion position");if(r.depth-n.openStart!=i.depth-n.openEnd)throw new ib("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 iN(o,iS(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(iu.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}(r,t);return iN(o,function e(t,n,r,i,s){let o=t.depth>s&&iv(t,n,s+1),a=i.depth>s&&iv(r,i,s+1),l=[];return ik(null,t,s,l),o&&a&&n.index(s)==r.index(s)?(iy(o,a),iw(iN(o,e(t,n,r,i,s+1)),l)):(o&&iw(iN(o,iS(t,n,s+1)),l),ik(n,r,s,l),a&&iw(iN(a,iS(r,i,s+1)),l)),ik(i,null,s,l),new iu(l)}(t,e,s,n,i))}{let e=t.parent,i=e.content;return iN(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 iC.resolveCached(this,e)}resolveNoCache(e){return iC.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()+")"),iD(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=iu.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=ig.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(!ig.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=iu.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}}iO.prototype.text=void 0;class i_ extends iO{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):iD(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 i_(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new i_(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 iD(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+"("+t+")";return t}class iR{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){var n;let r,i=new iI(e,t);if(null==i.next)return iR.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=iL(e),r=n;return e.eat(",")&&(r="}"!=e.next?iL(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]);iz(n,t).forEach(t=>{r||i.push([e,r=[]]),-1==r.indexOf(t)&&r.push(t)})}})});let s=r[t.join(",")]=new iR(t.indexOf(n.length-1)>-1);for(let t=0;t<i.length;t++){let n=i[t][1].sort(iP);s.next.push({type:i[t][0],next:r[n.join(",")]||e(n)})}return s}(iz(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 iu.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")}}iR.empty=new iR(!0);class iI{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 iL(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function iP(e,t){return t-e}function iz(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(iP)}function i$(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 iB(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 iF(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 iH(e,t){let n=Object.create(null);if(t)for(let r in t)n[r]=new iV(e,r,t[r]);return n}class iU{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=iH(e,n.attrs),this.defaultAttrs=i$(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==iR.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:iB(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error("NodeType.create can't construct text nodes");return new iO(this,this.computeAttrs(e),iu.from(t),ig.setFrom(n))}createChecked(e=null,t,n){return t=iu.from(t),this.checkContent(t),new iO(this,this.computeAttrs(e),t,ig.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),(t=iu.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(iu.empty,!0);return i?new iO(this,e,t.append(i),ig.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){iF(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:ig.none:e}static compile(e,t){let n=Object.create(null);e.forEach((e,r)=>n[e]=new iU(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 iV{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 iW{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=iH(e,r.attrs),this.excluded=null;let i=i$(this.attrs);this.instance=i?new ig(this,i):null}create(e=null){return!e&&this.instance?this.instance:new ig(this,iB(this.attrs,e))}static compile(e,t){let n=Object.create(null),r=0;return e.forEach((e,i)=>n[e]=new iW(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){iF(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class iq{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=id.from(e.nodes),t.marks=id.from(e.marks||{}),this.nodes=iU.compile(this.spec.nodes,this),this.marks=iW.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]=iR.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?iK(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?[]:iK(this,n.split(" "))}this.nodeFromJSON=e=>iO.fromJSON(this,e),this.markFromJSON=e=>ig.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 iU){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 i_(n,n.defaultAttrs,e,ig.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 iK(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 iG{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 i0(this,t,!1);return n.addAll(e,ig.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new i0(this,t,!0);return n.addAll(e,ig.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=i1(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=i1(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new iG(e,iG.schemaRules(e)))}}let iJ={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},iZ={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},iX={ol:!0,ul:!0};function iY(e,t,n){return null!=t?!!t|2*("full"===t):e&&"pre"==e.whitespace?3:-5&n}class iQ{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=ig.none,this.match=i||(4&s?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(iu.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=iu.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(iu.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&&!iJ.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class i0{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=iY(null,t.preserveWhitespace,0)|4*!!n;i=r?new iQ(r.type,r.attrs,ig.none,!0,t.topMatch||r.type.contentMatch,s):n?new iQ(null,null,ig.none,!0,null,s):new iQ(e.schema.topNodeType,null,ig.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;iX.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&&iX.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:iZ.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(iJ.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=ig.none;for(let i of r.concat(e.marks))(t.type?t.type.allowsMarkType(i.type):i2(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=iY(e,i,s.options);4&s.options&&0==s.content.length&&(o|=4);let a=ig.none;return n=n.filter(t=>(s.type?!s.type.allowsMarkType(t.type):!i2(t.type,e))||(a=t.addToSet(a),!1)),this.nodes.push(new iQ(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 i1(e){let t={};for(let n in e)t[n]=e[n];return t}function i2(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 i3{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=i4(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 i4(t).createTextNode(e.text);let{dom:n,contentDOM:r}=i9(i4(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&&i9(i4(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return"string"==typeof t?{dom:e.createTextNode(t)}:i9(e,t,n,r)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new i3(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=i5(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return i5(e.marks)}}function i5(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function i4(e){return e.document||window.document}let i6=new WeakMap;function i9(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=i6.get(r))&&i6.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}=i9(e,o,n,r);if(d.appendChild(t),s){if(i)throw RangeError("Multiple content holes");i=s}}}return{dom:d,contentDOM:i}}class i7{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 i8{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&i8.empty)return i8.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 i7(s,p,u)}r+=c-l}return n?e+r:new i7(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 i8(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return 0==e?i8.empty:new i8(e<0?[0,-e,0]:[0,0,e])}}i8.empty=new i8([]);class se{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 se(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 se;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 i7(e,r,null)}}let st=Object.create(null);class sn{getMap(){return i8.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw RangeError("Invalid input for Step.fromJSON");let n=st[t.stepType];if(!n)throw RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in st)throw RangeError("Duplicate use of step JSON ID "+e);return st[e]=t,t.prototype.jsonID=e,t}}class sr{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new sr(e,null)}static fail(e){return new sr(null,e)}static fromReplace(e,t,n,r){try{return sr.ok(e.replace(t,n,r))}catch(e){if(e instanceof ib)return sr.fail(e.message);throw e}}}function si(e,t,n){let r=[];for(let i=0;i<e.childCount;i++){let s=e.child(i);s.content.size&&(s=s.copy(si(s.content,t,s))),s.isInline&&(s=t(s,n,i)),r.push(s)}return iu.fromArray(r)}class ss extends sn{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(si(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 sr.fromReplace(e,this.from,this.to,i)}invert(){return new so(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 ss(t.pos,n.pos,this.mark)}merge(e){return e instanceof ss&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ss(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 ss(t.from,t.to,e.markFromJSON(t.mark))}}sn.jsonID("addMark",ss);class so extends sn{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(si(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return sr.fromReplace(e,this.from,this.to,n)}invert(){return new ss(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 so(t.pos,n.pos,this.mark)}merge(e){return e instanceof so&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new so(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 so(t.from,t.to,e.markFromJSON(t.mark))}}sn.jsonID("removeMark",so);class sa extends sn{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return sr.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return sr.fromReplace(e,this.pos,this.pos+1,new ix(iu.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 sa(this.pos,t.marks[n]);return new sa(this.pos,this.mark)}}return new sl(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new sa(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 sa(t.pos,e.markFromJSON(t.mark))}}sn.jsonID("addNodeMark",sa);class sl extends sn{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return sr.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return sr.fromReplace(e,this.pos,this.pos+1,new ix(iu.from(n),0,+!t.isLeaf))}invert(e){let t=e.nodeAt(this.pos);return t&&this.mark.isInSet(t.marks)?new sa(this.pos,this.mark):this}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new sl(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 sl(t.pos,e.markFromJSON(t.mark))}}sn.jsonID("removeNodeMark",sl);class sc extends sn{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&su(e,this.from,this.to)?sr.fail("Structure replace would overwrite content"):sr.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new i8([this.from,this.to-this.from,this.slice.size])}invert(e){return new sc(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&&sc.MAP_BIAS<0?t:e.mapResult(this.from,1);return n.deletedAcross&&t.deletedAcross?null:new sc(n.pos,Math.max(n.pos,t.pos),this.slice,this.structure)}merge(e){if(!(e instanceof sc)||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 sc(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 sc(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 sc(t.from,t.to,ix.fromJSON(e,t.slice),!!t.structure)}}sc.MAP_BIAS=1,sn.jsonID("replace",sc);class sd extends sn{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&&(su(e,this.from,this.gapFrom)||su(e,this.gapTo,this.to)))return sr.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return sr.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?sr.fromReplace(e,this.from,this.to,n):sr.fail("Content does not fit in gap")}getMap(){return new i8([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 sd(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 sd(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 sd(t.from,t.to,t.gapFrom,t.gapTo,ix.fromJSON(e,t.slice),t.insert,!!t.structure)}}function su(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 sp(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 so(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(iu.from(n.schema.text(" ",n.allowedMarks(l.marks))),0,0)),o.push(new sc(a+e.index,a+e.index+e[0].length,r))}}else o.push(new sc(a,c,ix.empty));a=c}if(!r.validEnd){let t=r.fillBefore(iu.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 sh(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 sf(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(sm).concat({type:t,attrs:n}).concat(s.map(sm)):null}function sm(e){return{type:e,attrs:null}}function sg(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 sb(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 sv(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function sv(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 sw(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&&sv(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 sk(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 sN(e,t,n=t,r=ix.empty){if(t==n&&!r.size)return null;let i=e.resolve(t),s=e.resolve(n);return sS(i,s,r)?new sc(t,n,r):new sC(i,s,r).fit()}function sS(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}sn.jsonID("replaceAround",sd);class sC{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=iu.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=iu.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 sd(n.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||n.pos!=this.$to.pos?new sc(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=sM(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(iu.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=sM(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=sM(e,t);if(r.childCount<=1&&t>0){let i=e.size-t<=t+r.size;this.unplaced=new ix(sj(e,t-1,1),t-1,i?t-1:n)}else this.unplaced=new ix(sj(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(iu.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=sE(this.placed,t,iu.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(sj(s.content,e-1,1),e-1,p<0?s.openEnd:e-1):new ix(sj(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||!sA(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=sA(e,t,r,n,i);if(s){for(let n=t-1;n>=0;n--){let{match:t,type:r}=this.frontier[n],i=sA(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=sE(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=sE(this.placed,this.depth,iu.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(iu.empty,!0);e.childCount&&(this.placed=sE(this.placed,this.frontier.length,e))}}function sj(e,t,n){return 0==t?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(sj(e.firstChild.content,t-1,n)))}function sE(e,t,n){return 0==t?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(sE(e.lastChild.content,t-1,n)))}function sM(e,t){for(let n=0;n<t;n++)e=e.firstChild.content;return e}function sA(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 sT(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 sO extends sn{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 sr.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 sr.fromReplace(e,this.pos,this.pos+1,new ix(iu.from(r),0,+!t.isLeaf))}getMap(){return i8.empty}invert(e){return new sO(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 sO(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 sO(t.pos,t.attr,t.value)}}sn.jsonID("attr",sO);class s_ extends sn{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 sr.ok(n)}getMap(){return i8.empty}invert(e){return new s_(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 s_(t.attr,t.value)}}sn.jsonID("docAttr",s_);let sD=class extends Error{};(sD=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n}).prototype=Object.create(Error.prototype),sD.prototype.constructor=sD,sD.prototype.name="TransformError";class sR{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new se}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new sD(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=sN(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new ix(iu.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(sS(i,s,r))return e.step(new sc(t,n,r));let o=sT(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(iu.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(iu.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=sT(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=iu.empty,u=0;for(let e=s,t=!1;e>n;e--)t||r.index(e)>0?(t=!0,d=iu.from(r.node(e).copy(d)),u++):l--;let p=iu.empty,h=0;for(let e=s,t=!1;e>n;e--)t||i.after(e+1)<i.end(e)?(t=!0,p=iu.from(i.node(e).copy(p)),h++):c++;e.step(new sd(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);sb(e,r.node(),r.before(),a)}o.inlineContent&&sp(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 sc(c,l.map(t+n,-1),ix.empty,!0)),!0===r){let t=e.doc.resolve(c);sg(e,t.node(),t.before(),e.steps.length)}}(this,e,t),this}wrap(e,t){return!function(e,t,n){let r=iu.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=iu.from(n[e].type.create(n[e].attrs,r))}let i=t.start,s=t.end;e.step(new sd(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&&sb(i,e,t,s),sp(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 sd(a,l,a+1,l-1,new ix(iu.from(n.create(u,null,e.marks)),0,0),1,!0)),!0===r&&sg(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 sd(t,t+s.nodeSize,t+1,t+s.nodeSize-1,new ix(iu.from(o),0,0),1,!0))}(this,e,t,n,r),this}setNodeAttribute(e,t,n){return this.step(new sO(e,t,n)),this}setDocAttribute(e,t){return this.step(new s_(e,t)),this}addNodeMark(e,t){return this.step(new sa(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw RangeError("No node at position "+e);if(t instanceof ig)t.isInSet(n.marks)&&this.step(new sl(e,t));else{let r=n.marks,i,s=[];for(;i=t.isInSet(r);)s.push(new sl(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=iu.empty,o=iu.empty;for(let e=i.depth,t=i.depth-n,a=n-1;e>t;e--,a--){s=iu.from(i.node(e).copy(s));let t=r&&r[a];o=iu.from(t?t.type.create(t.attrs,o):i.node(e).copy(o))}e.step(new sc(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 so(c,u,d[e])));s&&s.to==c?s.to=u:a.push(s=new ss(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 iW){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 so(e.from,e.to,e.style))),this}clearIncompatible(e,t,n){return sp(this,e,t,n),this}}let sI=Object.create(null);class sL{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new sP(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&&sK(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),sK(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new sB(e):sq(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?sq(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):sq(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 sV(e.node(0))}static atStart(e){return sq(e,e,0,0,1)||new sV(e)}static atEnd(e){return sq(e,e,e.content.size,e.childCount,-1)||new sV(e)}static fromJSON(e,t){if(!t||!t.type)throw RangeError("Invalid input for Selection.fromJSON");let n=sI[t.type];if(!n)throw RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in sI)throw RangeError("Duplicate use of selection JSON ID "+e);return sI[e]=t,t.prototype.jsonID=e,t}getBookmark(){return sB.between(this.$anchor,this.$head).getBookmark()}}sL.prototype.visible=!0;class sP{constructor(e,t){this.$from=e,this.$to=t}}let sz=!1;function s$(e){sz||e.parent.inlineContent||(sz=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class sB extends sL{constructor(e,t=e){s$(e),s$(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 sL.near(n);let r=e.resolve(t.map(this.anchor));return new sB(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 sB&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new sF(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 sB(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=sL.findFrom(t,n,!0)||sL.findFrom(t,-n,!0);if(!e)return sL.near(t,n);t=e.$head}return e.parent.inlineContent||(0==r?e=t:(e=(sL.findFrom(e,-n,!0)||sL.findFrom(e,n,!0)).$anchor).pos<t.pos!=r<0&&(e=t)),new sB(e,t)}}sL.jsonID("text",sB);class sF{constructor(e,t){this.anchor=e,this.head=t}map(e){return new sF(e.map(this.anchor),e.map(this.head))}resolve(e){return sB.between(e.resolve(this.anchor),e.resolve(this.head))}}class sH extends sL{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?sL.near(i):new sH(i)}content(){return new ix(iu.from(this.node),0,0)}eq(e){return e instanceof sH&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new sU(this.anchor)}static fromJSON(e,t){if("number"!=typeof t.anchor)throw RangeError("Invalid input for NodeSelection.fromJSON");return new sH(e.resolve(t.anchor))}static create(e,t){return new sH(e.resolve(t))}static isSelectable(e){return!e.isText&&!1!==e.type.spec.selectable}}sH.prototype.visible=!1,sL.jsonID("node",sH);class sU{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new sF(n,n):new sU(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&sH.isSelectable(n)?new sH(t):sL.near(t)}}class sV extends sL{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=sL.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new sV(e)}map(e){return new sV(e)}eq(e){return e instanceof sV}getBookmark(){return sW}}sL.jsonID("all",sV);let sW={map(){return this},resolve:e=>new sV(e)};function sq(e,t,n,r,i,s=!1){if(t.inlineContent)return sB.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&&sH.isSelectable(r))return sH.create(e,n-(i<0?r.nodeSize:0))}else{let t=sq(e,r,n+i,i<0?r.childCount:0,i,s);if(t)return t}n+=r.nodeSize*i}return null}function sK(e,t,n){let r,i=e.steps.length-1;if(i<t)return;let s=e.steps[i];(s instanceof sc||s instanceof sd)&&(e.mapping.maps[i].forEach((e,t,n,i)=>{null==r&&(r=i)}),e.setSelection(sL.near(e.doc.resolve(r),n)))}class sG extends sR{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 ig.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)||ig.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(sL.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 sJ(e,t){return t&&e?e.bind(t):e}class sZ{constructor(e,t,n){this.name=e,this.init=sJ(t.init,n),this.apply=sJ(t.apply,n)}}let sX=[new sZ("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new sZ("selection",{init:(e,t)=>e.selection||sL.atStart(t.doc),apply:e=>e.selection}),new sZ("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,r)=>r.selection.$cursor?e.storedMarks:null}),new sZ("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t})];class sY{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=sX.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 sZ(e.key,e.spec.state,e))})}}class sQ{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 sQ(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 sG(this)}static create(e){let t=new sY(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new sQ(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 sY(this.schema,e.plugins),n=t.fields,r=new sQ(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 sY(e.schema,e.plugins),i=new sQ(r);return r.fields.forEach(r=>{if("doc"==r.name)i.doc=iO.fromJSON(e.schema,t.doc);else if("selection"==r.name)i.selection=sL.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 s0{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:s2("plugin")}getState(e){return e[this.key]}}let s1=Object.create(null);function s2(e){return e in s1?e+"$"+ ++s1[e]:(s1[e]=0,e+"$")}class s3{constructor(e="key"){this.key=s2(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}let s5=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},s4=function(e){let t=e.assignedSlot||e.parentNode;return t&&11==t.nodeType?t.host:t},s6=null,s9=function(e,t,n){let r=s6||(s6=document.createRange());return r.setEnd(e,null==n?e.nodeValue.length:n),r.setStart(e,t||0),r},s7=function(){s6=null},s8=function(e,t,n,r){return n&&(ot(e,t,n,r,-1)||ot(e,t,n,r,1))},oe=/^(img|br|input|textarea|hr)$/i;function ot(e,t,n,r,i){for(var s;;){if(e==n&&t==r)return!0;if(t==(i<0?0:on(e))){let n=e.parentNode;if(!n||1!=n.nodeType||or(e)||oe.test(e.nodeName)||"false"==e.contentEditable)return!1;t=s5(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?on(e):0}}}function on(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function or(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 oi=function(e){return e.focusNode&&s8(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function oo(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}let oa="u">typeof navigator?navigator:null,ol="u">typeof document?document:null,oc=oa&&oa.userAgent||"",od=/Edge\/(\d+)/.exec(oc),ou=/MSIE \d/.exec(oc),op=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(oc),oh=!!(ou||op||od),of=ou?document.documentMode:op?+op[1]:od?+od[1]:0,om=!oh&&/gecko\/(\d+)/i.test(oc);om&&(/Firefox\/(\d+)/.exec(oc)||[0,0])[1];let og=!oh&&/Chrome\/(\d+)/.exec(oc),ob=!!og,ox=og?+og[1]:0,oy=!oh&&!!oa&&/Apple Computer/.test(oa.vendor),ov=oy&&(/Mobile\/\w+/.test(oc)||!!oa&&oa.maxTouchPoints>2),ow=ov||!!oa&&/Mac/.test(oa.platform),ok=!!oa&&/Win/.test(oa.platform),oN=/Android \d/.test(oc),oS=!!ol&&"webkitFontSmoothing"in ol.documentElement.style,oC=oS?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function oj(e,t){return"number"==typeof e?e:e[t]}function oE(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=s4(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+oj(r,"top")?c=-(a.top-t.top+oj(i,"top")):t.bottom>a.bottom-oj(r,"bottom")&&(c=t.bottom-t.top>a.bottom-a.top?t.top+oj(i,"top")-a.top:t.bottom-a.bottom+oj(i,"bottom")),t.left<a.left+oj(r,"left")?l=-(a.left-t.left+oj(i,"left")):t.right>a.right-oj(r,"right")&&(l=t.right-a.right+oj(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:s4(o)}}function oM(e){let t=[],n=e.ownerDocument;for(let r=e;r&&(t.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),e!=n);r=s4(r));return t}function oA(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 oT=null;function oO(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function o_(e){return e.top<e.bottom||e.left<e.right}function oD(e,t){let n=e.getClientRects();if(n.length){let e=n[t<0?0:n.length-1];if(o_(e))return e}return Array.prototype.find.call(n,o_)||e.getBoundingClientRect()}let oR=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function oI(e,t,n){let{node:r,offset:i,atom:s}=e.docView.domFromPos(t,n<0?-1:1),o=oS||om;if(3==r.nodeType)if(o&&(oR.test(r.nodeValue)||(n<0?!i:i==r.nodeValue.length))){let e=oD(s9(r,i,i),n);if(om&&i&&/\s/.test(r.nodeValue[i-1])&&i<r.nodeValue.length){let t=oD(s9(r,i-1,i-1),-1);if(t.top==e.top){let n=oD(s9(r,i,i+1),-1);if(n.top!=e.top)return oL(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++,oL(oD(s9(r,e,t),s),s<0)}if(!e.state.doc.resolve(t-(s||0)).parent.inlineContent){if(null==s&&i&&(n<0||i==on(r))){let e=r.childNodes[i-1];if(1==e.nodeType)return oP(e.getBoundingClientRect(),!1)}if(null==s&&i<on(r)){let e=r.childNodes[i];if(1==e.nodeType)return oP(e.getBoundingClientRect(),!0)}return oP(r.getBoundingClientRect(),n>=0)}if(null==s&&i&&(n<0||i==on(r))){let e=r.childNodes[i-1],t=3==e.nodeType?s9(e,on(e)-!o):1!=e.nodeType||"BR"==e.nodeName&&e.nextSibling?null:e;if(t)return oL(oD(t,1),!1)}if(null==s&&i<on(r)){let e=r.childNodes[i];for(;e.pmViewDesc&&e.pmViewDesc.ignoreForCoords;)e=e.nextSibling;let t=e?3==e.nodeType?s9(e,0,+!o):1==e.nodeType?e:null:null;if(t)return oL(oD(t,-1),!0)}return oL(oD(3==r.nodeType?s9(r):r,-n),n>=0)}function oL(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 oP(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 oz(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 o$=/[\u0590-\u08ac]/,oB=null,oF=null,oH=!1;class oU{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>s5(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 oZ){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 oV&&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?s5(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?s5(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=s5(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=s5(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((om||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:s5(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(om&&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)&&s8(o.node,o.offset,c.anchorNode,c.anchorOffset)&&s8(a.node,a.offset,c.focusNode,c.focusOffset))return;let u=!1;if((l.extend||e==t)&&!(d&&om)){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 oV extends oU{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 oW extends oU{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 oq extends oU{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=i3.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new oq(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=oq.create(this.parent,this.mark,!0,n),i=this.children,s=this.size;t<s&&(i=o9(i,t,s,n)),e>0&&(i=o9(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 oK extends oU{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=i3.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=o2(c,n,t),l)?a=new oX(e,t,n,r,c,d||null,u,l,i,s+1):t.isText?new oJ(e,t,n,r,c,u,i):new oK(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=()=>iu.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)&&o3(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 o4(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(o6);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 f=s+p.nodeSize;if(p.isText){let e=f;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<f&&(l=p.cut(e-s),p=p.cut(0,e-s),f=e,h=-1)}else for(;o<i.length&&i[o].to<f;)o++;let m=p.isInline&&!p.isLeaf?a.filter(e=>!e.inline):a.slice();r(p,m,t.forChild(s,p),h),s=f}})(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?ig.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=o5(i),s=!0;i=i.nextSibling}else s=!0,t.insertBefore(l,i);if(a instanceof oq){let n=i?i.previousSibling:t.lastChild;e(a.contentDOM,a.children,r),i=n?n.nextSibling:t.firstChild}}for(;i;)i=o5(i),s=!0;s&&r.trackWrites==t&&(r.trackWrites=null)}(this.contentDOM,this.children,e),ov&&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 sB)||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 oW(this,i,t,r);e.input.compositionNodes.push(s),this.children=o9(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(o3(e,this.outerDeco))return;let t=1!=this.nodeDOM.nodeType,n=this.dom;this.dom=o1(this.dom,this.nodeDOM,o0(this.outerDeco,this.node,t),o0(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 oG(e,t,n,r,i){o2(r,t,e);let s=new oK(void 0,e,t,n,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class oJ extends oK{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 oJ(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 oZ extends oU{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 oX extends oK{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 oY=function(e){e&&(this.nodeName=e)};oY.prototype=Object.create(null);let oQ=[new oY];function o0(e,t,n){if(0==e.length)return oQ;let r=n?oQ[0]:new oY,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 oY(o.nodeName)),o){let s=o[e];null!=s&&(n&&1==i.length&&i.push(r=new oY(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 o1(e,t,n,r){if(n==oQ&&r==oQ)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=oQ[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||oQ[0],s)}return i}function o2(e,t,n){return o1(e,e,oQ,o0(t,n,1!=e.nodeType))}function o3(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 o5(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}class o4{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 oq)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=oq.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 oK){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&&o3(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)||!o3(n,e.outerDeco)||!r.eq(e.innerDeco))return null;let o=oK.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=oK.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 oV(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 oq;)e=(t=e).children[t.children.length-1];(!e||!(e instanceof oJ)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((oy||ob)&&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 oZ(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 o6(e,t){return e.type.side-t.type.side}function o9(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 o7(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(oi(n)){for(l=o;i&&!i.node;)i=i.parent;let e=i.node;if(i&&e.isAtom&&sH.isSelectable(e)&&i.parent&&!(e.isInline&&function(e,t,n){for(let r=0==t,i=t==on(e);r||i;){if(e==n)return!0;let t=s5(e);if(!(e=e.parentNode))return!1;r=r&&0==t,i=i&&t==on(e)}}(n.focusNode,n.focusOffset,i.dom))){let e=i.posBefore;c=new sH(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=aa(e,d,a,n)}return c}function o8(e){return e.editable?e.hasFocus():ac(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function ae(e,t=!1){let n=e.state.selection;if(as(e,n),o8(e)){if(!t&&e.input.mouseDown&&e.input.mouseDown.allowDefault&&ob){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&s8(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,s5(n)+1):t.collapse(n,0),!r&&!e.state.selection.visible&&oh&&of<=11&&(n.disabled=!0,n.disabled=!1)}(e);else{var r;let i,s,o,a,{anchor:l,head:c}=n,d,u;at&&!(n instanceof sB)&&(n.$from.parent.inlineContent||(d=an(e,n.from)),n.empty||n.$from.parent.inlineContent||(u=an(e,n.to))),e.docView.setSelection(l,c,e,t),at&&(d&&ai(d),u&&ai(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(()=>{(!o8(r)||r.state.selection.visible)&&r.dom.classList.remove("ProseMirror-hideselection")},20))})))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}let at=oy||ob&&ox<63;function an(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 ar(i);if((!i||"false"==i.contentEditable)&&(!s||"false"==s.contentEditable)){if(i)return ar(i);else if(s)return ar(s)}}function ar(e){return e.contentEditable="true",oy&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function ai(e){e.contentEditable="false",e.wasDraggable&&(e.draggable=!0,e.wasDraggable=null)}function as(e,t){if(t instanceof sH){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(ao(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else ao(e)}function ao(e){e.lastSelectedViewDesc&&(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),e.lastSelectedViewDesc=void 0)}function aa(e,t,n,r){return e.someProp("createSelectionBetween",r=>r(e,t,n))||sB.between(t,n,r)}function al(e){return(!e.editable||!!e.hasFocus())&&ac(e)}function ac(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 ad(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&&sL.findFrom(s,t)}function au(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function ap(e,t,n){let r=e.state.selection;if(r instanceof sB){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 au(e,new sB(r.$anchor,s))}else if(!r.empty)return!1;else if(e.endOfTextblock(t>0?"forward":"backward")){let n=ad(e.state,t);return!!n&&n instanceof sH&&au(e,n)}else if(!(ow&&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)&&(sH.isSelectable(i)?au(e,new sH(t<0?e.state.doc.resolve(n.pos-i.nodeSize):n)):!!oS&&au(e,new sB(e.state.doc.resolve(t<0?o:o+i.nodeSize))))}}else{if(r instanceof sH&&r.node.isInline)return au(e,new sB(t>0?r.$to:r.$from));let n=ad(e.state,t);return!!n&&au(e,n)}}function ah(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function af(e,t){let n=e.pmViewDesc;return n&&0==n.size&&(t<0||e.nextSibling||"BR"!=e.nodeName)}function am(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(om&&1==n.nodeType&&r<ah(n)&&af(n.childNodes[r],-1)&&(o=!0);;)if(r>0)if(1!=n.nodeType)break;else{let e=n.childNodes[r-1];if(af(e,-1))i=n,s=--r;else if(3==e.nodeType)r=(n=e).nodeValue.length;else break}else if(ag(n))break;else{let t=n.previousSibling;for(;t&&af(t,-1);)i=n.parentNode,s=s5(t),t=t.previousSibling;if(t)r=ah(n=t);else{if((n=n.parentNode)==e.dom)break;r=0}}o?ab(e,n,r):i&&ab(e,i,s)}(e):function(e){let t,n,r=e.domSelectionRange(),i=r.focusNode,s=r.focusOffset;if(!i)return;let o=ah(i);for(;;)if(s<o){if(1!=i.nodeType)break;if(af(i.childNodes[s],1))t=i,n=++s;else break}else if(ag(i))break;else{let r=i.nextSibling;for(;r&&af(r,1);)t=r.parentNode,n=s5(r)+1,r=r.nextSibling;if(r)s=0,o=ah(i=r);else{if((i=i.parentNode)==e.dom)break;s=o=0}}t&&ab(e,t,n)}(e)}function ag(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function ab(e,t,n){if(3!=t.nodeType){let e,r;(r=function(e,t){for(;e&&t==e.childNodes.length&&!or(e);)t=s5(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&&!or(e);)t=s5(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(oi(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&&ae(e)},50)}function ax(e,t){let n=e.state.doc.resolve(t);if(!(ob||ok)&&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 sB&&!r.empty||n.indexOf("s")>-1||ow&&n.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||e.endOfTextblock(t<0?"up":"down")){let n=ad(e.state,t);if(n&&n instanceof sH)return au(e,n)}if(!i.parent.inlineContent){let n=t<0?i:s,o=r instanceof sV?sL.near(n,t):sL.findFrom(n,t);return!!o&&au(e,o)}return!1}function av(e,t){if(!(e.state.selection instanceof sB))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 aw(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function ak(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")||i3.fromSchema(e.state.schema),a=aT(),l=a.createElement("div");l.appendChild(o.serializeFragment(r,{document:a}));let c=l.firstChild,d,u=0;for(;c&&1==c.nodeType&&(d=aM[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 aN(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(iu.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=i3.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=aT().createElement("div"),s=/<([a-z][^>\s]+)/i.exec(e),o;if((o=s&&aM[s[1].toLowerCase()])&&(e=o.map(e=>"<"+e+">").join("")+e+o.map(e=>"</"+e+">").reverse().join("")),i.innerHTML=(t=e,(n=window.trustedTypes)?(aO||(aO=n.defaultPolicy||n.createPolicy("ProseMirrorClipboard",{createHTML:e=>e})),aO.createHTML(t)):t),o)for(let e=0;e<o.length;e++)i=i.querySelector(o[e])||i;return i}(n),oS&&function(e){let t=e.querySelectorAll(ob?"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")||iG.fromSchema(e.state.schema)).parseSlice(s,{preserveWhitespace:!!(l||d),context:i,ruleFromNode:e=>"BR"!=e.nodeName||e.nextSibling||!e.parentNode||aS.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=iu.from(t.create(r[e+1],i)),s++,o++}return new ix(i,s,o)}(aE(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(iu.from(aC(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(iu.empty,!0);return t.copy(r.append(i))}(s[s.length-1],i.length));let n=aC(e,t);s.push(n),r=r.matchType(n.type),i=t}}),s)return iu.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=aE(o,e,t)}return e.someProp("transformPasted",t=>{o=t(o,e,l)}),o}let aS=/^(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 aC(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,iu.from(e));return e}function aj(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=aj(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(iu.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(a))}function aE(e,t,n){return t<e.openStart&&(e=new ix(aj(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new ix(aj(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}let aM={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]},aA=null;function aT(){return aA||(aA=document.implementation.createHTMLDocument("title"))}let aO=null,a_={},aD={},aR={touchstart:!0,touchmove:!0};class aI{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 aL(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function aP(e){e.someProp("handleDOMEvents",t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>az(e,t))})}function az(e,t){return e.someProp("handleDOMEvents",n=>{let r=n[t.type];return!!r&&(r(e,t)||t.defaultPrevented)})}function a$(e){return{left:e.clientX,top:e.clientY}}function aB(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 aF(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)}aD.keydown=(e,t)=>{if((e.input.shiftKey=16==t.keyCode||t.shiftKey,!aV(e,t))&&(e.input.lastKeyCode=t.keyCode,e.input.lastKeyCodeTime=Date.now(),!oN||!ob||13!=t.keyCode))if(229!=t.keyCode&&e.domObserver.forceFlush(),!ov||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||ow&&72==r&&"c"==i)return av(e,-1)||am(e,-1);if(46==r&&!t.shiftKey||ow&&68==r&&"c"==i)return av(e,1)||am(e,1);if(13==r||27==r)return!0;if(37==r||ow&&66==r&&"c"==i){let t=37==r?"ltr"==ax(e,e.state.selection.from)?-1:1:-1;return ap(e,t,i)||am(e,t)}if(39==r||ow&&70==r&&"c"==i){let t=39==r?"ltr"==ax(e,e.state.selection.from)?1:-1:1;return ap(e,t,i)||am(e,t)}else if(38==r||ow&&80==r&&"c"==i)return ay(e,-1,i)||am(e,-1);else if(40==r||ow&&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;aw(e,n,"true"),setTimeout(()=>aw(e,n,"false"),20)}return!1}(e)||ay(e,1,i)||am(e,1);else if(i==(ow?"m":"c")&&(66==r||73==r||89==r||90==r))return!0;return!1}(e,t)?t.preventDefault():aL(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,oo(13,"Enter"))),e.input.lastIOSEnter=0)},200)}},aD.keyup=(e,t)=>{16==t.keyCode&&(e.input.shiftKey=!1)},aD.keypress=(e,t)=>{if(aV(e,t)||!t.charCode||t.ctrlKey&&!t.altKey||ow&&t.metaKey)return;if(e.someProp("handleKeyPress",n=>n(e,t)))return void t.preventDefault();let n=e.state.selection;if(!(n instanceof sB)||!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 aH=ow?"metaKey":"ctrlKey";a_.mousedown=(e,t)=>{var n;let r,i;e.input.shiftKey=t.shiftKey;let s=aG(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[aH]&&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(a$(t));l&&("singleClick"==a?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new aU(e,l,t,!!s)):("doubleClick"==a?function(e,t,n,r){return aB(e,"handleDoubleClickOn",t,n,r)||e.someProp("handleDoubleClick",n=>n(e,t,r))}:function(e,t,n,r){return aB(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&&(aF(e,sB.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)aF(e,sB.create(r,s+1,s+1+n.content.size),"pointer");else{if(!sH.isSelectable(n))continue;aF(e,sH.create(r,s),"pointer")}return!0}}(e,n,r)})(e,l.pos,l.inside,t)?t.preventDefault():aL(e,"pointer"))};class aU{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[aH],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 sH&&l.from<=s&&l.to>s)&&(this.mightDrag={node:i,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&om&&!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)),aL(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(()=>ae(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(a$(e))),this.updateAllowDefault(e),this.allowDefault||!t)aL(this.view,"pointer");else{var n,r,i,s;(n=this.view,r=t.pos,i=t.inside,s=this.selectNode,aB(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 sH&&(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(sH.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&&(aF(e,sH.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&&sH.isSelectable(r))&&(aF(e,new sH(n),"pointer"),!0)}(n,i)))?e.preventDefault():0==e.button&&(this.flushed||oy&&this.mightDrag&&!this.mightDrag.node.isAtom||ob&&!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)))?(aF(this.view,sL.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):aL(this.view,"pointer")}}move(e){this.updateAllowDefault(e),aL(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 aV(e,t){return!!e.composing||!!(oy&&500>Math.abs(t.timeStamp-e.input.compositionEndedAt))&&(e.input.compositionEndedAt=-2e8,!0)}a_.touchstart=e=>{e.input.lastTouch=Date.now(),aG(e),aL(e,"pointer")},a_.touchmove=e=>{e.input.lastTouch=Date.now(),aL(e,"pointer")},a_.contextmenu=e=>aG(e);let aW=oN?5e3:-1;function aq(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>aG(e),t))}function aK(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 aG(e,t=!1){if(!oN||!(e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),aK(e),t||e.docView&&e.docView.dirty){let n=o7(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}}aD.compositionstart=aD.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof sB&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>!1===e.type.spec.inclusive)||ob&&ok&&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(),aG(e,!0),e.markCursor=null;else if(aG(e,!t.selection.empty),om&&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}aq(e,aW)},aD.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++,aq(e,20))};let aJ=oh&&of<15||ov&&oC<604;function aZ(e,t,n,r,i){let s=aN(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 aX(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," "):""}a_.copy=aD.cut=(e,t)=>{let n=e.state.selection,r="cut"==t.type;if(n.empty)return;let i=aJ?null:t.clipboardData,{dom:s,text:o}=ak(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"))},aD.paste=(e,t)=>{if(e.composing&&!oN)return;let n=aJ?null:t.clipboardData,r=e.input.shiftKey&&45!=e.input.lastKeyCode;n&&aZ(e,aX(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?aZ(e,r.value,null,i,t):aZ(e,r.textContent,r.innerHTML,i,t)},50)}(e,t)};class aY{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}let aQ=ow?"altKey":"ctrlKey";function a0(e,t){let n;return e.someProp("dragCopies",e=>{n=n||e(t)}),null!=n?!n:!t[aQ]}for(let e in a_.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(a$(t));if(s&&s.pos>=i.from&&s.pos<=(i instanceof sH?i.to-1:i.to));else if(r&&r.mightDrag)n=sH.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=sH.create(e.state.doc,r.posBefore))}let o=(n||e.state.selection).content(),{dom:a,text:l,slice:c}=ak(e,o);t.dataTransfer.files.length&&ob&&!(ox>120)||t.dataTransfer.clearData(),t.dataTransfer.setData(aJ?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",aJ||t.dataTransfer.setData("text/plain",l),e.dragging=new aY(c,a0(e,t),n)},a_.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},aD.dragover=aD.dragenter=(e,t)=>t.preventDefault(),aD.drop=(e,t)=>{try{!function(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(a$(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=aN(e,aX(t.dataTransfer),aJ?null:t.dataTransfer.getData("text/html"),!1,i);let o=!!(n&&a0(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?sk(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&&sH.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))l.setSelection(new sH(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(aa(e,p,l.doc.resolve(t)))}e.focus(),e.dispatch(l.setMeta("uiEvent","drop"))}(e,t,e.dragging)}finally{e.dragging=null}},a_.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())&&ae(e)},20))},a_.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)},a_.beforeinput=(e,t)=>{if(ob&&oN&&"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,oo(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)}},aD)a_[e]=aD[e];function a1(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 a2{constructor(e,t){this.toDOM=e,this.spec=t||a9,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 a4(i-n,i-n,this)}valid(){return!0}eq(e){return this==e||e instanceof a2&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&a1(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class a3{constructor(e,t){this.attrs=e,this.spec=t||a9}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 a4(i,s,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof a3&&a1(this.attrs,e.attrs)&&a1(this.spec,e.spec)}static is(e){return e.type instanceof a3}destroy(){}}class a5{constructor(e,t){this.attrs=e,this.spec=t||a9}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 a4(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 a5&&a1(this.attrs,e.attrs)&&a1(this.spec,e.spec)}destroy(){}}class a4{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new a4(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 a4(e,e,new a2(t,n))}static inline(e,t,n,r){return new a4(e,t,new a3(n,r))}static node(e,t,n,r){return new a4(e,t,new a5(n,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof a3}get widget(){return this.type instanceof a2}}let a6=[],a9={};class a7{constructor(e,t){this.local=e.length?e:a6,this.children=t.length?t:a6}static create(e,t){return t.length?li(t,e,0,a9):a8}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==a8||0==e.maps.length?this:this.mapInner(e,t,0,0,n||a9)}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),f=r.maybeChild(p);if(f&&h==d&&h+f.nodeSize==u){let r=a[t+2].mapInner(n,f,c+1,e[t]+s+1,o);r!=a8?(a[t]=d,a[t+1]=u,a[t+2]=r):(a[t+1]=-2,l=!0)}else l=!0}if(l){let l=li(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 a7(t.sort(ls),a)}(this.children,s||[],e,t,n,r,i):s?new a7(s.sort(ls),a6):a8}add(e,t){return t.length?this==a8?a7.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=ln(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,li(a,e,o+1,a9)),i+=3}});let s=lt(i?lr(t):t,-n);for(let t=0;t<s.length;t++)s[t].type.valid(e,s[t])||s.splice(t--,1);return new a7(s.length?this.local.concat(s).sort(ls):this.local,r||this.children)}remove(e){return 0==e.length||this==a8?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!=a8?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 a7(r,n):a8}forChild(e,t){let n,r;if(this==a8)return this;if(t.isLeaf)return a7.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 a3){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 a7(r.sort(ls),a6);return n?new le([e,n]):e}return n||a8}eq(e){if(this==e)return!0;if(!(e instanceof a7)||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 lo(this.localsInner(e))}localsInner(e){if(this==a8)return a6;if(e.inlineContent||!this.local.some(a3.is))return this.local;let t=[];for(let e=0;e<this.local.length;e++)this.local[e].type instanceof a3||t.push(this.local[e]);return t}forEachSet(e){e(this)}}a7.empty=new a7([],[]),a7.removeOverlap=lo;let a8=a7.empty;class le{constructor(e){this.members=e}map(e,t){let n=this.members.map(n=>n.map(e,t,a9));return le.from(n)}forChild(e,t){if(t.isLeaf)return a7.empty;let n=[];for(let r=0;r<this.members.length;r++){let i=this.members[r].forChild(e,t);i!=a8&&(i instanceof le?n=n.concat(i.members):n.push(i))}return le.from(n)}eq(e){if(!(e instanceof le)||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?lo(n?t:t.sort(ls)):a6}static from(e){switch(e.length){case 0:return a8;case 1:return e[0];default:return new le(e.every(e=>e instanceof a7)?e:e.reduce((e,t)=>e.concat(t instanceof a7?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function lt(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 a4(i.from+t,i.to+t,i.type))}return n}function ln(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 lr(e){let t=[];for(let n=0;n<e.length;n++)null!=e[n]&&t.push(e[n]);return t}function li(e,t,n,r){let i=[],s=!1;t.forEach((t,o)=>{let a=ln(e,t,o+n);if(a){s=!0;let e=li(a,t,n+o+1,r);e!=a8&&i.push(o,o+t.nodeSize,e)}});let o=lt(s?lr(e):e,-n).sort(ls);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 a7(o,i):a8}function ls(e,t){return e.from-t.from||e.to-t.to}function lo(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),la(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),la(t,i,r.copy(s.from,r.to)));break}}return t}function la(e,t,n){for(;t<e.length&&ls(n,e[t])>0;)t++;e.splice(t,0,n)}function ll(e){let t=[];return e.someProp("decorations",n=>{let r=n(e.state);r&&r!=a8&&t.push(r)}),e.cursorWrapper&&t.push(a7.create(e.state.doc,[e.cursorWrapper.deco])),le.from(t)}let lc={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},ld=oh&&of<=11;class lu{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 lp{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new lu,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]);oh&&of<=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()}),ld&&(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,lc)),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(al(this.view)){if(this.suppressingSelectionUpdates)return ae(this.view);if(oh&&of<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&s8(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=s4(n))t.add(n);for(let r=e.anchorNode;r;r=s4(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)&&al(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(om&&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&&oi(r)&&(c=o7(t))&&c.eq(sL.near(t.state.doc.resolve(0),1))?(t.input.lastFocus=0,ae(t),this.currentSelection.set(r),t.scrollToSelection()):(s>-1||i)&&(s>-1&&(t.docView.markDirty(s,o),e=t,!lh.has(e)&&(lh.set(e,null),-1!==["normal","nowrap","pre-line"].indexOf(getComputedStyle(e.dom).whiteSpace))&&(e.requiresGeckoHackNode=om,lf||(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."),lf=!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)||ae(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(oh&&of<=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?s5(r)+1:0,o=n.localPosFromDOM(e.target,s,-1),a=i&&i.parentNode==e.target?s5(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 lh=new WeakMap,lf=!1;function lm(e,t){let n=t.startContainer,r=t.startOffset,i=t.endContainer,s=t.endOffset,o=e.domAtPos(e.state.selection.anchor);return s8(o.node,o.offset,i,s)&&([n,r,i,s]=[i,s,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:s}}function lg(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 lb=/^(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:aa(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 lv(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 lw{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 aI,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(lj),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=lS(this),lN(this),this.nodeViews=lC(this),this.docView=oG(this.state.doc,lk(this),ll(this),this.dom,this),this.domObserver=new lp(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=o7(e,t);if(n&&!e.state.selection.eq(n)){if(ob&&oN&&13===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime&&e.someProp("handleKeyDown",t=>t(e,oo(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}],oi(c)||r.push({node:c.focusNode,offset:c.focusOffset})),ob&&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")||iG.fromSchema(e.state.schema),h=u.resolve(a),f=null,m=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:lg,context:h});if(r&&null!=r[0].pos){let e=r[0].pos,t=r[1]&&r[1].pos;null==t&&(t=e),f={anchor:e+a,head:t+a}}return{doc:m,sel:f,from:a,to:l}}(e,t,n),h=e.state.doc,f=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 m=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&&lv(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&&lv(e.textBetween(s-1,s+1))&&(s+=t?1:-1),o=s+(o-a),a=s}return{start:s,endA:o,endB:a}}(f.content,p.doc.content,p.from,s,o);if(m&&e.input.domChangeCount++,(ov&&e.input.lastIOSEnter>Date.now()-225||oN)&&i.some(e=>1==e.nodeType&&!lb.test(e.nodeName))&&(!m||m.endA>=m.endB)&&e.someProp("handleKeyDown",t=>t(e,oo(13,"Enter")))){e.input.lastIOSEnter=0;return}if(!m)if(r&&u instanceof sB&&!u.empty&&u.$head.sameParent(u.$anchor)&&!e.composing&&!(p.sel&&p.sel.anchor!=p.sel.head))m={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&&m.start==m.endB&&e.state.selection instanceof sB&&(m.start>e.state.selection.from&&m.start<=e.state.selection.from+2&&e.state.selection.from>=p.from?m.start=e.state.selection.from:m.endA<e.state.selection.to&&m.endA>=e.state.selection.to-2&&e.state.selection.to<=p.to&&(m.endB+=e.state.selection.to-m.endA,m.endA=e.state.selection.to)),oh&&of<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>p.from&&"  "==p.doc.textBetween(m.start-p.from-1,m.start-p.from+1)&&(m.start--,m.endA--,m.endB--);let g=p.doc.resolveNoCache(m.start-p.from),b=p.doc.resolveNoCache(m.endB-p.from),x=h.resolve(m.start),y=g.sameParent(b)&&g.parent.inlineContent&&x.end()>=m.endA;if((ov&&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(b)||!g.parent.inlineContent)&&g.pos<b.pos&&!/\S/.test(p.doc.textBetween(g.pos,b.pos,"","")))&&e.someProp("handleKeyDown",t=>t(e,oo(13,"Enter")))){e.input.lastIOSEnter=0;return}if(e.state.selection.anchor>m.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,m.start,m.endA,g,b)&&e.someProp("handleKeyDown",t=>t(e,oo(8,"Backspace")))){oN&&ob&&e.domObserver.suppressSelectionUpdates();return}ob&&m.endB==m.start&&(e.input.lastChromeDelete=Date.now()),oN&&!y&&g.start()!=b.start()&&0==b.parentOffset&&g.depth==b.depth&&p.sel&&p.sel.anchor==p.sel.head&&p.sel.head==m.endA&&(m.endB-=2,b=p.doc.resolveNoCache(m.endB-p.from),setTimeout(()=>{e.someProp("handleKeyDown",function(t){return t(e,oo(13,"Enter"))})},20));let v=m.start,w=m.endA,k=t=>{let n=t||e.state.tr.replace(v,w,p.doc.slice(m.start-p.from,m.endB-p.from));if(p.sel){let t=lx(e,n.doc,p.sel);t&&!(ob&&e.composing&&t.empty&&(m.start!=m.endB||e.input.lastChromeDelete<Date.now()-100)&&(t.head==v||t.head==n.mapping.map(w)-1)||oh&&t.empty&&t.head==v)&&n.setSelection(t)}return l&&n.setMeta("composition",l),n.scrollIntoView()};if(y)if(g.pos==b.pos){oh&&of<=11&&0==g.parentOffset&&(e.domObserver.suppressSelectionUpdates(),setTimeout(()=>ae(e),20));let t=k(e.state.tr.delete(v,w)),n=h.resolve(m.start).marksAcross(h.resolve(m.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(m.endA==m.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(iu.from(c).eq(e))return{mark:a,type:o}}(g.parent.content.cut(g.parentOffset,b.parentOffset),x.parent.content.cut(x.parentOffset,m.endA-x.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()==b.index()-!b.textOffset){let t=g.parent.textBetween(g.parentOffset,b.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 a_){let n=a_[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)||az(e,t)||!e.editable&&t.type in aD||n(e,t)},aR[t]?{passive:!0}:void 0)}oy&&e.dom.addEventListener("input",()=>null),aP(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&&aP(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(lj),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&&(aK(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=lC(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)&&aP(this),this.editable=lS(this),lN(this);let c=ll(this),d=lk(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:oM(e.dom)}}(this);if(a){let t,n,a;this.domObserver.stop();let l=p&&(oh||ob)&&!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=ob?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=on(e=e.childNodes[t-1])}else{if(!e.parentNode||or(e))return null;t=s5(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||or(e))return null;t=s5(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=oG(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(),s8(t.node,t.offset,n.anchorNode,n.anchorOffset)))?ae(this,l):(as(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;oA(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 sH){let t=this.docView.domAfterPos(this.state.selection.from);1==t.nodeType&&oE(this,t.getBoundingClientRect(),e)}else oE(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 aY(e.slice,e.move,r<0?void 0:sH.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(oh){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(oT)return e.focus(oT);let t=oM(e);e.focus(null==oT?{get preventScroll(){return oT={preventScroll:!0},!0}}:void 0),oT||(oT=!1,oA(t,0))}(this.dom),ae(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(on(r.offsetNode),r.offset)}}catch(e){}if(e.caretRangeFromPoint){let r=e.caretRangeFromPoint(t,n);if(r)return{node:r.startContainer,offset:Math.min(on(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(!oO(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(oO(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=s4(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(om&&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++}oS&&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=s9(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=oD(r,1);if(n.top!=n.bottom&&oO(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 oI(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 oB==t&&oF==n?oH:(oB=t,oF=n,oH="up"==n||"down"==n?(r=t.selection,i="up"==n?r.$from:r.$to,oz(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=oI(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=s9(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?o$.test(r.parent.textContent)&&o.modify?oz(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 aZ(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return aZ(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return ak(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,[],ll(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,s7()}}get isDestroyed(){return null==this.docView}dispatchEvent(e){!az(this,e)&&a_[e.type]&&(this.editable||!(e.type in aD))&&a_[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 lm(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?lm(e,n):null}(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function lk(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"),[a4.node(0,e.state.doc.content.size,t)]}function lN(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:a4.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function lS(e){return!e.someProp("editable",t=>!1===t(e.state))}function lC(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 lj(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")}lw.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};for(var lE={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:"'"},lM={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},lA="u">typeof navigator&&/Mac/.test(navigator.platform),lT="u">typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),lO=0;lO<10;lO++)lE[48+lO]=lE[96+lO]=String(lO);for(var lO=1;lO<=24;lO++)lE[lO+111]="F"+lO;for(var lO=65;lO<=90;lO++)lE[lO]=String.fromCharCode(lO+32),lM[lO]=String.fromCharCode(lO);for(var l_ in lE)lM.hasOwnProperty(l_)||(lM[l_]=lE[l_]);let lD="u">typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),lR="u">typeof navigator&&/Win/.test(navigator.platform);function lI(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 lL(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))lD?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=!(lA&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||lT&&n.shiftKey&&n.key&&1==n.key.length||"Unidentified"==n.key)&&n.key||(n.shiftKey?lM:lE)[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[lI(i,n)];if(o&&o(e.state,e.dispatch,e))return!0;if(1==i.length&&" "!=i){if(n.shiftKey){let r=t[lI(i,n,!1)];if(r&&r(e.state,e.dispatch,e))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(lR&&n.ctrlKey&&n.altKey)&&(s=lE[n.keyCode])&&s!=i){let r=t[lI(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 lP=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 lP(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 lz(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 l$=new s3("selectingCells");function lB(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 lF(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 lH(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=lB(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 lU(e){return"row"==e.parent.type.spec.tableRole&&!!e.nodeAfter}function lV(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function lW(e,t,n){let r=e.node(-1),i=lP.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 lq(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 lK(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 lG=class e extends sL{constructor(e,t=e){const n=e.node(-1),r=lP.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 sP(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(lU(r)&&lU(i)&&lV(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 sB.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=lP.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=lq(e,0,c)),d>0&&(e=lq(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(iu.from(o)))}let o=this.isColSelection()&&this.isRowSelection()?e:s;return new ix(iu.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=sL.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);i&&e.setSelection(i)}replaceWith(e,t){this.replace(e,new ix(iu.from(t),0,0))}forEachCell(e){let t=this.$anchorCell.node(-1),n=lP.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=lP.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=lP.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=lP.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 lJ(this.$anchorCell.pos,this.$headCell.pos)}};lG.prototype.visible=!1,sL.jsonID("cell",lG);var lJ=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&&lV(t,n)?new lG(t,n):sL.near(n,1)}};function lZ(e){if(!(e.selection instanceof lG))return null;let t=[];return e.selection.forEachCell((e,n)=>{t.push(a4.node(n,n+e.nodeSize,{class:"selectedCell"}))}),a7.create(e.doc,t)}let lX=new s3("fix-tables");function lY(e,t){let n,r=(t,r)=>{"table"==t.type.spec.tableRole&&(n=function(e,t,n,r){let i,s,o=lP.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,lq(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=lz(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(lX,{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 lQ(e){let t=lP.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 l0(e,t){let n=[],r=lP.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 l1(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 l2(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 l3(e,t){let n=l2(t.$from);if(!n)return;let r=lP.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 l5(e,t){let n=l2(t.$from);if(!n)return;let r=lP.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 l4(e,t,n=t){let r,i=t,s=n;for(let n=t;n>=0;n--){let t=l3(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=l3(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=l3(t,e.selection);n&&n.length>0&&o.push(t)}i=o[0],s=o[o.length-1];let a=l3(i,e.selection),l=l5(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=l3(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 l6(e,t,n=t){let r,i=t,s=n;for(let n=t;n>=0;n--){let t=l5(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=l5(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=l5(t,e.selection);n&&n.length>0&&o.push(t)}i=o[0],s=o[o.length-1];let a=l5(i,e.selection),l=l3(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=l5(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 l9(e){return e[0].map((t,n)=>e.map(e=>e[n]))}function l7(e){let t=e.selection,n=lH(e),r=n.node(-1),i=n.start(-1),s=lP.get(r);return{...t instanceof lG?s.rectBetween(t.$anchorCell.pos-i,t.$headCell.pos-i):s.findCell(n.pos-i),tableStart:i,map:s,table:r}}function l8(e,{map:t,tableStart:n,table:r},i){let s=i>0?-1:0;(function(e,t,n){let r=lz(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,lK(l.attrs,i-t.colCount(s))),o+=l.attrs.rowspan-1}else{let l=null==s?lz(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 ce(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=lz(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?lz(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,lz(r.type.schema).row.create(null,o)),e}function ct(e){let t=e.content;return 1==t.childCount&&t.child(0).isTextblock&&0==t.child(0).childCount}function cn(e,t){let n=e.selection;if(!(n instanceof lG)||n.$anchorCell.pos==n.$headCell.pos)return!1;let r=l7(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=iu.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{ct(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,{...lK(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=ct(s)?n+1:e;o.replaceWith(t+r.tableStart,e+r.tableStart,l)}o.setSelection(new lG(o.doc.resolve(n+r.tableStart))),t(o)}return!0}function cr(e,t){var n;let r=lz(e.schema);return(n=({node:e})=>r[e.type.spec.tableRole],(e,t)=>{let r,i,s=e.selection;if(s instanceof lG){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=lB(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=l7(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 lG&&u.setSelection(new lG(u.doc.resolve(s.$anchorCell.pos),o?u.doc.resolve(o):void 0)),t(u)}return!0})(e,t)}function ci(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 cs(e,t){if((t=t||{useDeprecatedLogic:!1}).useDeprecatedLogic)return function(t,n){if(!lF(t))return!1;if(n){let r=lz(t.schema),i=l7(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(!lF(t))return!1;if(n){let r=lz(t.schema),i=l7(t),s=t.tr,o=ci("row",i,r),a=ci("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}}cs("row",{useDeprecatedLogic:!0}),cs("column",{useDeprecatedLogic:!0});let co=cs("cell",{useDeprecatedLogic:!0});function ca(e){return function(t,n){if(!lF(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}(lH(t),e);if(null==r)return!1;if(n){let e=t.doc.resolve(r);n(t.tr.setSelection(sB.between(e,e.node(0).resolve(e.pos+e.nodeAfter.nodeSize))).scrollIntoView())}return!0}}function cl(e,t){let n=e.selection;if(!(n instanceof lG))return!1;if(t){let r=e.tr,i=lz(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 cc(e,t){let n=e.createAndFill();return new sR(n).replace(0,n.content.size,t).doc}function cd(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 cu(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,lq(i.attrs,o-d,i.attrs.colspan-(o-d))),e.insert(u+i.nodeSize,i.type.createAndFill(lq(i.attrs,0,o-d))),c+=i.attrs.rowspan-1}}return l}function cp(e,t,n,r,i){let s=n?e.doc.nodeAt(n-1):e.doc;if(!s)throw Error("No table found");let o=lP.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=lP.get(s),p=u.mapping.maps.length}(function(e,t,n,r,i,s){let o,a,l=lz(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,iu.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(),cd(u,o,s,n,l,c,a,p)&&h(),cd(u,o,s,n,l,c,d,p)&&h(),cu(u,o,s,n,a,d,l,p)&&h(),cu(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 lG(u.doc.resolve(n+o.positionAt(a,l,s)),u.doc.resolve(n+o.positionAt(d-1,c-1,s)))),t(u)}let ch=lL({ArrowLeft:cm("horiz",-1),ArrowRight:cm("horiz",1),ArrowUp:cm("vert",-1),ArrowDown:cm("vert",1),"Shift-ArrowLeft":cg("horiz",-1),"Shift-ArrowRight":cg("horiz",1),"Shift-ArrowUp":cg("vert",-1),"Shift-ArrowDown":cg("vert",1),Backspace:cl,"Mod-Backspace":cl,Delete:cl,"Mod-Delete":cl});function cf(e,t,n){return!n.eq(e.selection)&&(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function cm(e,t){return(n,r,i)=>{if(!i)return!1;let s=n.selection;if(s instanceof lG)return cf(n,r,sL.near(s.$headCell,t));if("horiz"!=e&&!s.empty)return!1;let o=cv(i,e,t);if(null==o)return!1;if("horiz"==e)return cf(n,r,sL.near(n.doc.resolve(s.head+t),t));{let i,s=n.doc.resolve(o),a=lW(s,e,t);return i=a?sL.near(a,1):t<0?sL.near(n.doc.resolve(s.before(-1)),-1):sL.near(n.doc.resolve(s.after(-1)),1),cf(n,r,i)}}}function cg(e,t){return(n,r,i)=>{let s;if(!i)return!1;let o=n.selection;if(o instanceof lG)s=o;else{let r=cv(i,e,t);if(null==r)return!1;s=new lG(n.doc.resolve(r))}let a=lW(s.$headCell,e,t);return!!a&&cf(n,r,new lG(s.$anchorCell,a))}}function cb(e,t){let n=lB(e.state.doc.resolve(t));return!!n&&(e.dispatch(e.state.tr.setSelection(new lG(n))),!0)}function cx(e,t,n){if(!lF(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=cc(lz(o).row,new ix(i,s,l)).content),a.push(i)}else{if("cell"!=s&&"header_cell"!=s)return null;a.push(n||r?cc(lz(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(iu.empty),n[i]<r){let s=lz(e).cell.createAndFill(),o=[];for(let e=n[i];e<r;e++)o.push(s);t[i]=t[i].append(iu.from(o))}return{height:t.length,width:r,rows:t}}(o,a)}(n),i=e.state.selection;if(i instanceof lG){r||(r={width:1,height:1,rows:[iu.from(cc(lz(e.state.schema).cell,n))]});let t=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),o=lP.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(lq(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(iu.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(iu.from(o))}n=e,t=i}return{width:e,height:t,rows:n}}(r,o.right-o.left,o.bottom-o.top),cp(e.state,e.dispatch,s,o,r),!0}if(!r)return!1;{let t=lH(e.state),n=t.start(-1);return cp(e.state,e.dispatch,n,lP.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=cw(e,t.target);if(t.shiftKey&&e.state.selection instanceof lG)s(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&i&&null!=(r=lB(e.state.selection.$anchor))&&(null==(n=ck(e,t))?void 0:n.pos)!=r.pos)s(r,t),t.preventDefault();else if(!i)return;function s(t,n){let r=ck(e,n),i=null==l$.getState(e.state);if(!r||!lV(t,r))if(!i)return;else r=t;let s=new lG(t,r);if(i||!e.state.selection.eq(s)){let n=e.state.tr.setSelection(s);i&&n.setMeta(l$,t.pos),e.dispatch(n)}}function o(){e.root.removeEventListener("mouseup",o),e.root.removeEventListener("dragstart",o),e.root.removeEventListener("mousemove",a),null!=l$.getState(e.state)&&e.dispatch(e.state.tr.setMeta(l$,-1))}function a(n){let r,a=l$.getState(e.state);if(null!=a)r=e.state.doc.resolve(a);else if(cw(e,n.target)!=i&&!(r=ck(e,t)))return o();r&&s(r,n)}e.root.addEventListener("mouseup",o),e.root.addEventListener("dragstart",o),e.root.addEventListener("mousemove",a)}function cv(e,t,n){if(!(e.state.selection instanceof sB))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 cw(e,t){for(;t&&t!=e.dom;t=t.parentNode)if("TD"==t.nodeName||"TH"==t.nodeName)return t;return null}function ck(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&&lB(e.state.doc.resolve(r))||lB(e.state.doc.resolve(i))}var cN=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")),cS(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,cS(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return"attributes"==e.type&&(e.target==this.table||this.colgroup.contains(e.target))}};function cS(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 cC=new s3("tableColumnResizing");var cj=class e{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(t){let n=t.getMeta(cC);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 lU(t.doc.resolve(n))||(n=-1),new e(n,this.dragging)}return this}};function cE(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=lB(e.state.doc.resolve(s));if(!o)return -1;if("right"==n)return o.pos;let a=lP.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 cM(e,t,n){let r=t.clientX-e.startX;return Math.max(n,e.startWidth+r)}function cA(e,t){e.dispatch(e.state.tr.setMeta(cC,{setHandle:t}))}function cT(e,t,n,r){let i=e.state.doc.resolve(t),s=i.node(-1),o=i.start(-1),a=lP.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&&cS(s,l.firstChild,l,r,a,n)}var cO=f,c_=e.i(3909);let cD=(e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function cR(e,t){let{$cursor:n}=e.selection;return n&&(t?t.endOfTextblock("backward",e):!(n.parentOffset>0))?n:null}let cI=(e,t,n)=>{let r=cR(e,n);if(!r)return!1;let i=c$(r);if(!i){let n=r.blockRange(),i=n&&sh(n);return null!=i&&(t&&t(e.tr.lift(n,i).scrollIntoView()),!0)}let s=i.nodeBefore;if(cJ(e,i,t,-1))return!0;if(0==r.parent.content.size&&(cP(s,"end")||sH.isSelectable(s)))for(let n=r.depth;;n--){let o=sN(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(cP(s,"end")?sL.findFrom(n.doc.resolve(n.mapping.map(i.pos,-1)),-1):sH.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 cL(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=sN(e.doc,i,o,ix.empty);if(!a||a.from!=i||a instanceof sc&&a.slice.size>=o-i)return!1;if(n){let t=e.tr.step(a);t.setSelection(sB.create(t.doc,i)),n(t.scrollIntoView())}return!0}function cP(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 cz=(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=c$(r)}let o=s&&s.nodeBefore;return!!o&&!!sH.isSelectable(o)&&(t&&t(e.tr.setSelection(sH.create(e.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function c$(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 cB(e,t){let{$cursor:n}=e.selection;return n&&(t?t.endOfTextblock("forward",e):!(n.parentOffset<n.parent.content.size))?n:null}let cF=(e,t,n)=>{let r=cB(e,n);if(!r)return!1;let i=cU(r);if(!i)return!1;let s=i.nodeAfter;if(cJ(e,i,t,1))return!0;if(0==r.parent.content.size&&(cP(s,"start")||sH.isSelectable(s))){let n=sN(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(cP(s,"start")?sL.findFrom(r.doc.resolve(r.mapping.map(i.pos)),1):sH.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)},cH=(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=cU(r)}let o=s&&s.nodeAfter;return!!o&&!!sH.isSelectable(o)&&(t&&t(e.tr.setSelection(sH.create(e.doc,s.pos)).scrollIntoView()),!0)};function cU(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 cV=(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 cW(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 cq=(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=cW(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(sL.near(i.doc.resolve(r),1)),t(i.scrollIntoView())}return!0},cK=(e,t)=>{let n=e.selection,{$from:r,$to:i}=n;if(n instanceof sV||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=cW(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(sB.create(o.doc,n+1)),t(o.scrollIntoView())}return!0},cG=(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&&sh(r);return null!=i&&(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)};function cJ(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=iu.empty;for(let e=c.length-1;e>=0;e--)i=iu.from(c[e].create(null,i));i=iu.from(a.copy(i));let s=e.tr.step(new sd(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:sL.findFrom(t,1),f=h&&h.$from.blockRange(h.$to),m=f&&sh(f);if(null!=m&&m>=t.depth)return n&&n(e.tr.lift(f,m).scrollIntoView()),!0;if(p&&cP(l,"start",!0)&&cP(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=iu.empty;for(let e=i.length-1;e>=0;e--)r=iu.from(i[e].copy(r));n(e.tr.step(new sd(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 cZ(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(sB.create(t.doc,e<0?i.start(s):i.end(s)))),!0)}}let cX=cZ(-1),cY=cZ(1);function cQ(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 c0(...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 c1=c0(cD,cI,cz),c2=c0(cD,cF,cH),c3={Enter:c0(cV,cK,cG,(e,t)=>{let{$from:n,$to:r}=e.selection;if(e.selection instanceof sH&&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=cW(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 sB||e.selection instanceof sV)&&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":cq,Backspace:c1,"Mod-Backspace":c1,"Shift-Backspace":c1,Delete:c2,"Mod-Delete":c2,"Mod-a":(e,t)=>(t&&t(e.tr.setSelection(new sV(e.doc))),!0)},c5={"Ctrl-h":c3.Backspace,"Alt-Backspace":c3["Mod-Backspace"],"Ctrl-d":c3.Delete,"Ctrl-Alt-Backspace":c3["Mod-Delete"],"Alt-Delete":c3["Mod-Delete"],"Alt-d":c3["Mod-Delete"],"Ctrl-a":cX,"Ctrl-e":cY};for(let e in c3)c5[e]=c3[e];"u">typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):"u">typeof os&&os.platform&&os.platform();var c4=Object.defineProperty,c6=(e,t)=>{for(var n in t)c4(e,n,{get:t[n],enumerable:!0})};function c9(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 c7=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:c9({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}},c8={};c6(c8,{blur:()=>de,clearContent:()=>dt,clearNodes:()=>dn,command:()=>dr,createParagraphNear:()=>di,cut:()=>ds,deleteCurrentNode:()=>da,deleteNode:()=>dc,deleteRange:()=>dd,deleteSelection:()=>dp,enter:()=>dh,exitCode:()=>df,extendMarkRange:()=>dw,first:()=>dk,focus:()=>dM,forEach:()=>dA,insertContent:()=>dT,insertContentAt:()=>dR,joinBackward:()=>dP,joinDown:()=>dL,joinForward:()=>dz,joinItemBackward:()=>d$,joinItemForward:()=>dB,joinTextblockBackward:()=>dF,joinTextblockForward:()=>dH,joinUp:()=>dI,keyboardShortcut:()=>dV,lift:()=>dq,liftEmptyBlock:()=>dK,liftListItem:()=>dG,newlineInCode:()=>dJ,resetAttributes:()=>dY,scrollIntoView:()=>dQ,selectAll:()=>d0,selectNodeBackward:()=>d1,selectNodeForward:()=>d2,selectParentNode:()=>d3,selectTextblockEnd:()=>d5,selectTextblockStart:()=>d4,setContent:()=>d9,setMark:()=>uI,setMeta:()=>uL,setNode:()=>uP,setNodeSelection:()=>uz,setTextDirection:()=>u$,setTextSelection:()=>uB,sinkListItem:()=>uF,splitBlock:()=>uU,splitListItem:()=>uV,toggleList:()=>uK,toggleMark:()=>uG,toggleNode:()=>uJ,toggleWrap:()=>uZ,undoInputRule:()=>uX,unsetAllMarks:()=>uY,unsetMark:()=>uQ,unsetTextDirection:()=>u0,updateAttributes:()=>u1,wrapIn:()=>u2,wrapInList:()=>u3});var de=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),null==(n=null==window?void 0:window.getSelection())||n.removeAllRanges())}),!0),dt=(e=!0)=>({commands:t})=>t.setContent("",{emitUpdate:e}),dn=()=>({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=sh(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)},dr=e=>t=>e(t),di=()=>({state:e,dispatch:t})=>cK(e,t),ds=(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 sB(r.doc.resolve(Math.max(o-1,0)))),!0},da=()=>({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 dl(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 dc=e=>({tr:t,state:n,dispatch:r})=>{let i=dl(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},dd=e=>({tr:t,dispatch:n})=>{let{from:r,to:i}=e;return n&&t.delete(r,i),!0},du=(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},dp=()=>({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:du(r,n=e.schema,"left"),to:du(i,n,"right")};return t&&(e.tr.deleteRange(s,o).scrollIntoView(),t(e.tr)),!0},dh=()=>({commands:e})=>e.keyboardShortcut("Enter"),df=()=>({state:e,dispatch:t})=>cq(e,t);function dm(e){return"[object RegExp]"===Object.prototype.toString.call(e)}function dg(e,t,n={strict:!0}){let r=Object.keys(t);return!r.length||r.every(r=>n.strict?t[r]===e[r]:dm(t[r])?t[r].test(e[r]):t[r]===e[r])}function db(e,t,n={}){return e.find(e=>e.type===t&&dg(Object.fromEntries(Object.keys(n).map(t=>[t,e.attrs[t]])),n))}function dx(e,t,n={}){return!!db(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(!db([...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 dv(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 dw=(e,t)=>({tr:n,state:r,dispatch:i})=>{let s=dv(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=sB.create(o,e.from,e.to);n.setSelection(t)}}return!0},dk=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 dN(e){return e instanceof sB}function dS(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function dC(e,t=null){if(!t)return null;let n=sL.atStart(e),r=sL.atEnd(e);if("start"===t||!0===t)return n;if("end"===t)return r;let i=n.from,s=r.to;return"all"===t?sB.create(e,dS(0,i,s),dS(e.content.size,i,s)):sB.create(e,dS(t,i,s),dS(t,i,s))}function dj(){return"Android"===navigator.platform||/android/i.test(navigator.userAgent)}function dE(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}var dM=(e=null,t={})=>({editor:n,view:r,tr:i,dispatch:s})=>{t={scrollIntoView:!0,...t};let o=()=>{(dE()||dj())&&r.dom.focus(),"u">typeof navigator&&/^((?!chrome|android).)*safari/i.test(navigator.userAgent)&&!dE()&&!dj()&&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&&!dN(n.state.selection))return o(),!0;let a=dC(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},dA=(e,t)=>n=>e.every((e,r)=>t(e,{...n,index:r})),dT=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),dO=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&&dO(r)}return e};function d_(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 dO(new window.DOMParser().parseFromString(t,"text/html").body)}function dD(e,t,n){if(e instanceof iO||e instanceof iu)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 iu.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),dD("",t,n)}if(i){if(n.errorOnInvalidContent){let r=!1,i="",s=new iq({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?iG.fromSchema(s).parseSlice(d_(e),n.parseOptions):iG.fromSchema(s).parse(d_(e),n.parseOptions),n.errorOnInvalidContent&&r)throw Error("[tiptap error]: Invalid HTML content",{cause:Error(`Invalid element found: ${i}`)})}let r=iG.fromSchema(t);return n.slice?r.parseSlice(d_(e),n.parseOptions).content:r.parse(d_(e),n.parseOptions)}return dD("",t,n)}var dR=(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{dD(t,s.schema,{parseOptions:c,errorOnInvalidContent:!0})}catch(e){l(e)}try{i=dD(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 iu){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 sc||r instanceof sd))return;let i=e.mapping.maps[n],s=0;i.forEach((e,t,n,r)=>{0===s&&(s=r)}),e.setSelection(sL.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},dI=()=>({state:e,dispatch:t})=>((e,t)=>{let n=e.selection,r=n instanceof sH,i;if(r){if(n.node.isTextblock||!sy(e.doc,n.from))return!1;i=n.from}else if(null==(i=sw(e.doc,n.from,-1)))return!1;if(t){let n=e.tr.join(i);r&&n.setSelection(sH.create(n.doc,i-e.doc.resolve(i).nodeBefore.nodeSize)),t(n.scrollIntoView())}return!0})(e,t),dL=()=>({state:e,dispatch:t})=>((e,t)=>{let n=e.selection,r;if(n instanceof sH){if(n.node.isTextblock||!sy(e.doc,n.to))return!1;r=n.to}else if(null==(r=sw(e.doc,n.to,1)))return!1;return t&&t(e.tr.join(r).scrollIntoView()),!0})(e,t),dP=()=>({state:e,dispatch:t})=>cI(e,t),dz=()=>({state:e,dispatch:t})=>cF(e,t),d$=()=>({state:e,dispatch:t,tr:n})=>{try{let r=sw(e.doc,e.selection.$from.pos,-1);if(null==r)return!1;return n.join(r,2),t&&t(n),!0}catch{return!1}},dB=()=>({state:e,dispatch:t,tr:n})=>{try{let r=sw(e.doc,e.selection.$from.pos,1);if(null==r)return!1;return n.join(r,2),t&&t(n),!0}catch{return!1}},dF=()=>({state:e,dispatch:t})=>((e,t,n)=>{let r=cR(e,n);if(!r)return!1;let i=c$(r);return!!i&&cL(e,i,t)})(e,t),dH=()=>({state:e,dispatch:t})=>((e,t,n)=>{let r=cB(e,n);if(!r)return!1;let i=cU(r);return!!i&&cL(e,i,t)})(e,t);function dU(){return"u">typeof navigator&&/Mac/.test(navigator.platform)}var dV=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))dE()||dU()?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 dW(e,t,n={}){let{from:r,to:i,empty:s}=e.selection,o=t?dl(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=>dg(e.node.attrs,n,{strict:!1}));return s?!!c.length:c.reduce((e,t)=>e+t.to-t.from,0)>=l}var dq=(e,t={})=>({state:n,dispatch:r})=>{let i=dl(e,n.schema);return!!dW(n,i,t)&&((e,t)=>{let{$from:n,$to:r}=e.selection,i=n.blockRange(r),s=i&&sh(i);return null!=s&&(t&&t(e.tr.lift(i,s).scrollIntoView()),!0)})(n,r)},dK=()=>({state:e,dispatch:t})=>cG(e,t),dG=e=>({state:t,dispatch:n})=>{var r;return(r=dl(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 sd(s-1,o,s,o,new ix(iu.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new iA(i.doc.resolve(r.$from.pos),i.doc.resolve(o),r.depth));let a=sh(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?iu.empty:iu.from(i))))return!1;let u=s.pos,p=u+o.nodeSize;return r.step(new sd(u-!!a,p+ +!!l,u+1,p-1,new ix((a?iu.empty:iu.from(i.copy(iu.empty))).append(l?iu.empty:iu.from(i.copy(iu.empty))),+!a,+!l),+!a)),t(r.scrollIntoView()),!0}(e,t,s)))})(t,n)},dJ=()=>({state:e,dispatch:t})=>cV(e,t);function dZ(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function dX(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 dY=(e,t)=>({tr:n,state:r,dispatch:i})=>{let s=null,o=null,a=dZ("string"==typeof e?e:e.name,r.schema);if(!a)return!1;"node"===a&&(s=dl(e,r.schema)),"mark"===a&&(o=dv(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,dX(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(dX(s.attrs,t))))})})}),l},dQ=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),d0=()=>({tr:e,dispatch:t})=>{if(t){let t=new sV(e.doc);e.setSelection(t)}return!0},d1=()=>({state:e,dispatch:t})=>cz(e,t),d2=()=>({state:e,dispatch:t})=>cH(e,t),d3=()=>({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(sH.create(e.doc,i))),!0)})(e,t),d5=()=>({state:e,dispatch:t})=>cY(e,t),d4=()=>({state:e,dispatch:t})=>cX(e,t);function d6(e,t,n={},r={}){return dD(e,t,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}var d9=(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=d6(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 d7(e,t){let n=dv(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 d8(e,t){let n=new sR(e);return t.forEach(e=>{e.steps.forEach(e=>{n.step(e)})}),n}function ue(e,t){let n=[];return e.descendants((e,r)=>{t(e)&&n.push({node:e,pos:r})}),n}function ut(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 un(e){return t=>ut(t.$from,e)}function ur(e,t,n){return void 0===e.config[t]&&e.parent?ur(e.parent,t,n):"function"==typeof e.config[t]?e.config[t].bind({...n,parent:e.parent?ur(e.parent,t,n):null}):e.config[t]}function ui(e){return e.map(e=>{let t={name:e.name,options:e.options,storage:e.storage},n=ur(e,"addExtensions",t);return n?[e,...ui(n())]:e}).flat(10)}function us(e,t){let n=i3.fromSchema(t).serializeFragment(e),r=document.implementation.createHTMLDocument().createElement("div");return r.appendChild(n),r.innerHTML}function uo(e){return"function"==typeof e}function ua(e,t,...n){return uo(e)?t?e.bind(t)(...n):e(...n):e}function ul(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 uc(e){let t=[],{nodeExtensions:n,markExtensions:r}=ul(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=ur(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=ur(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 ud(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 uu(...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([...ud(n[e]),...ud(t)]);n[e]=Array.from(r.entries()).map(([e,t])=>`${e}: ${t}`).join("; ")}else n[e]=t}),n},{})}function up(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)=>uu(e,t),{})}function uh(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 uf(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 um(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 ug(e){return e.sort((e,t)=>{let n=ur(e,"priority")||100,r=ur(t,"priority")||100;return n>r?-1:+(n<r)})}function ub(e){var t;let n=ug(ui(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 uv(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function uw(e,t){let n=dZ("string"==typeof t?t:t.name,e.schema);return"node"===n?function(e,t){let n=dl(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?d7(e,t):{}}function uk(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 uN(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 uS(e,t){return t.nodes[e]||t.marks[e]||null}function uC(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 uj(e,t,n={}){let{empty:r,ranges:i}=e.selection,s=t?dv(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(e=>!s||s.name===e.type.name).find(e=>dg(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=>dg(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 uE(e,t){return Array.isArray(t)?t.some(t=>("string"==typeof t?t:t.name)===e.name):t}function uM(e,t){let{nodeExtensions:n}=ul(t),r=n.find(t=>t.name===e);if(!r)return!1;let i={name:r.name,options:r.options,storage:r.storage},s=ua(ur(r,"group",i));return"string"==typeof s&&s.split(" ").includes("list")}function uA(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&&(uA(e,{ignoreWhitespace:n,checkChildren:t})||(r=!1))}),r}return!1}function uT(e){return e instanceof sH}var uO=class e{constructor(e){this.position=e}static fromJSON(t){return new e(t.position)}toJSON(){return{position:this.position}}};function u_(e,t){let n=t.mapping.mapResult(e.position);return{position:new uO(n.pos),mapResult:n}}function uD(e){return new uO(e)}function uR(e,t,n){let r=e.state.doc.content.size,i=dS(t,0,r),s=dS(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 uI=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{selection:s}=n,{empty:o,ranges:a}=s,l=dv(e,r.schema);if(i)if(o){let e=d7(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(dN(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)},uL=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),uP=(e,t={})=>({state:n,dispatch:r,chain:i})=>{let s,o=dl(e,n.schema);return(n.selection.$anchor.sameParent(n.selection.$head)&&(s=n.selection.$anchor.parent.attrs),o.isTextblock)?i().command(({commands:e})=>!!cQ(o,{...s,...t})(n)||e.clearNodes()).command(({state:e})=>cQ(o,{...s,...t})(e,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},uz=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,r=dS(e,0,n.content.size),i=sH.create(n,r);t.setSelection(i)}return!0},u$=(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},uB=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,{from:r,to:i}="number"==typeof e?{from:e,to:e}:e,s=sB.atStart(n).from,o=sB.atEnd(n).to,a=dS(r,s,o),l=dS(i,s,o),c=sB.create(n,a,l);t.setSelection(c)}return!0},uF=e=>({state:t,dispatch:n})=>{var r;return(r=dl(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=iu.from(n?r.create():null),o=new ix(iu.from(r.create(null,iu.from(a.type.create(null,i)))),n?3:1,0),c=s.start,d=s.end;t(e.tr.step(new sd(c-(n?3:1),d,c,d,o,1,!0)).scrollIntoView())}return!0})(t,n)};function uH(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 uU=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{let{selection:s,doc:o}=t,{$from:a,$to:l}=s,c=uC(i.extensionManager.attributes,a.node().type.name,a.node().attrs);if(s instanceof sH&&s.node.isBlock)return!!a.parentOffset&&!!sx(o,a.pos)&&(r&&(e&&uH(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 sB&&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&&uH(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return h},uV=(e,t={})=>({tr:n,state:r,dispatch:i,editor:s})=>{var o;let a=dl(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=iu.empty,r=l.index(-1)?1:l.index(-2)?2:3;for(let t=l.depth-r;t>=l.depth-3;t-=1)e=iu.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={...uC(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(iu.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(sB.near(n.doc.resolve(u))),n.scrollIntoView()}return!0}let h=c.pos===l.end()?u.contentMatchAt(0).defaultType:null,f={...uC(p,u.type.name,u.attrs),...t},m={...uC(p,l.node().type.name,l.node().attrs),...t};n.delete(l.pos,c.pos);let g=h?[{type:a,attrs:f},{type:h,attrs:m}]:[{type:a,attrs:f}];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},uW=(e,t)=>{let n=un(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)},uq=(e,t)=>{let n=un(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)},uK=(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=dl(e,o.schema),f=dl(t,o.schema),{selection:m,storedMarks:g}=o,{$from:b,$to:x}=m,y=b.blockRange(x),v=g||m.$to.parentOffset&&m.$from.marks();if(!y)return!1;let w=un(e=>uM(e.type.name,u))(m),k=0===m.from&&m.to===o.doc.content.size,N=o.doc.content.content,S=1===N.length?N[0]:null,C=k&&S&&uM(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 sB.between(r,i)}(e);return!!n&&(e.setSelection(n),t&&t(e),!0)}).liftListItem(f).run():c.liftListItem(f);if(uM(j.node.type.name,u)&&h.validContent(j.node.content))return l().command(()=>(s.setNodeMarkup(j.pos,h),!0)).command(()=>uW(s,h)).command(()=>uq(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(()=>uW(s,h)).command(()=>uq(s,h)).run():l().command(()=>!!d().wrapInList(h,r)||c.clearNodes()).wrapInList(h,r).command(()=>uW(s,h)).command(()=>uq(s,h)).run()},uG=(e,t={},n={})=>({state:r,commands:i})=>{let{extendEmptyMarkRange:s=!1}=n,o=dv(e,r.schema);return uj(r,o,t)?i.unsetMark(o,{extendEmptyMarkRange:s}):i.setMark(o,t)},uJ=(e,t,n={})=>({state:r,commands:i})=>{let s,o=dl(e,r.schema),a=dl(t,r.schema),l=dW(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})},uZ=(e,t={})=>({state:n,commands:r})=>{let i=dl(e,n.schema);return dW(n,i,t)?r.lift(i):r.wrapIn(i,t)},uX=()=>({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},uY=()=>({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)},uQ=(e,t={})=>({tr:n,state:r,dispatch:i})=>{var s;let{extendEmptyMarkRange:o=!1}=t,{selection:a}=n,l=dv(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},u0=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},u1=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let s=null,o=null,a=dZ("string"==typeof e?e:e.name,r.schema);if(!a)return!1;"node"===a&&(s=dl(e,r.schema)),"mark"===a&&(o=dv(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},u2=(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&&sf(o,e,t);return!!a&&(r&&r(n.tr.wrap(o,a).scrollIntoView()),!0)}})(dl(e,n.schema),t)(n,r),u3=(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 iA(e,e,t.depth),t.endIndex<t.parent.childCount&&(t=new iA(t.$from,o.resolve(t.$to.end(t.depth)),t.depth)),i=!0}let a=sf(s,n,r,t);return!!a&&(e&&function(e,t,n,r,i){let s=iu.empty;for(let e=n.length-1;e>=0;e--)s=iu.from(n[e].type.create(n[e].attrs,s));e.step(new sd(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)}})(dl(e,n.schema),t)(n,r),u5=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={}}},u4=class{constructor(e){var t;this.find=e.find,this.handler=e.handler,this.undoable=null==(t=e.undoable)||t}};function u6(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(dm(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=c9({state:l.state,transaction:o}),p={from:r-(t[0].length-s.length),to:i},{commands:h,chain:f,can:m}=new c7({editor:n,state:c});null!==e.handler({state:c,range:p,match:t,commands:h,chain:f,can:m})&&o.steps.length&&(e.undoable&&o.setMeta(a,{transform:o,from:r,to:i,text:s}),l.dispatch(o),d=!0)}),d}function u9(e){return"Object"===Object.prototype.toString.call(e).slice(8,-1)&&e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}var u7=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{...ua(ur(this,"addOptions",{name:this.name}))}}get storage(){return{...ua(ur(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 u9(t)&&u9(n)&&Object.keys(n).forEach(i=>{u9(n[i])&&u9(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}},u8=class e extends u7{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)}},pe=class{constructor(e){this.find=e.find,this.handler=e.handler}},pt=null,pn=class{constructor(e,t){this.splittableMarks=[],this.editor=t,this.baseExtensions=e,this.extensions=ub(e),this.schema=function(e,t){var n;let r=uc(e),{nodeExtensions:i,markExtensions:s}=ul(e),o=null==(n=i.find(e=>ur(e,"topNode")))?void 0:n.name;return new iq({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=uf({...e.reduce((e,t)=>{let r=ur(t,"extendNodeSchema",s);return{...e,...r?r(n):{}}},{}),content:ua(ur(n,"content",s)),marks:ua(ur(n,"marks",s)),group:ua(ur(n,"group",s)),inline:ua(ur(n,"inline",s)),atom:ua(ur(n,"atom",s)),selectable:ua(ur(n,"selectable",s)),draggable:ua(ur(n,"draggable",s)),code:ua(ur(n,"code",s)),whitespace:ua(ur(n,"whitespace",s)),linebreakReplacement:ua(ur(n,"linebreakReplacement",s)),defining:ua(ur(n,"defining",s)),isolating:ua(ur(n,"isolating",s)),attrs:Object.fromEntries(i.map(um))}),a=ua(ur(n,"parseHTML",s));a&&(o.parseDOM=a.map(e=>uh(e,i)));let l=ur(n,"renderHTML",s);l&&(o.toDOM=e=>l({node:e,HTMLAttributes:up(e,i)}));let c=ur(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=uf({...e.reduce((e,t)=>{let r=ur(t,"extendMarkSchema",s);return{...e,...r?r(n):{}}},{}),inclusive:ua(ur(n,"inclusive",s)),excludes:ua(ur(n,"excludes",s)),group:ua(ur(n,"group",s)),spanning:ua(ur(n,"spanning",s)),code:ua(ur(n,"code",s)),attrs:Object.fromEntries(i.map(um))}),a=ua(ur(n,"parseHTML",s));a&&(o.parseDOM=a.map(e=>uh(e,i)));let l=ur(n,"renderHTML",s);return l&&(o.toDOM=e=>l({mark:e,HTMLAttributes:up(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:uS(t.name,this.schema)},r=ur(t,"addCommands",n);return r?{...e,...r()}:e},{})}get plugins(){let{editor:e}=this;return ug([...this.extensions].reverse()).flatMap(t=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:uS(t.name,this.schema)},r=[],i=ur(t,"addKeyboardShortcuts",n),s={};if("mark"===t.type&&ur(t,"exitable",n)&&(s.ArrowRight=()=>u8.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 s0({props:{handleKeyDown:lL(s)}});r.push(o);let a=ur(t,"addInputRules",n);if(uE(t,e.options.enableInputRules)&&a){let t=a();if(t&&t.length){let n=function(e){let{editor:t,rules:n}=e,r=new s0({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=us(iu.from(e),s.schema));let{from:i}=a,o=i+e.length;u6({editor:t,from:i,to:o,text:e,rules:n,plugin:r})}),e.selectionSet||e.docChanged?null:i}},props:{handleTextInput:(e,i,s,o)=>u6({editor:t,from:i,to:s,text:o,rules:n,plugin:r}),handleDOMEvents:{compositionend:e=>(setTimeout(()=>{let{$cursor:i}=e.state.selection;i&&u6({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&&u6({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=ur(t,"addPasteRules",n);if(uE(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 c7({editor:t,state:n}),u=[];return n.doc.nodesBetween(r,i,(e,t)=>{var p,h,f,m,g;if((null==(h=null==(p=e.type)?void 0:p.spec)?void 0:h.code)||!(e.isText||e.isTextblock||e.isInline))return;let b=null!=(g=null!=(m=null==(f=e.content)?void 0:f.size)?m:e.nodeSize)?g:0,x=Math.max(r,t),y=Math.min(i,t+b);x>=y||((e,t,n)=>{if(dm(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(x-t,y-t,void 0,""),s.find,o).forEach(e=>{if(void 0===e.index)return;let t=x+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:c9({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 s0({view(e){let t=t=>{var r;(i=(null==(r=e.dom.parentElement)?void 0:r.contains(t.target))?e.dom.parentElement:null)&&(pt=n)},r=()=>{pt&&(pt=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=pt;(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,f;let t,{text:n}=u;"string"==typeof n||(n=us(iu.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==(f=(t=new ClipboardEvent("paste",{clipboardData:new DataTransfer})).clipboardData)||f.setData("text/html",h),t)})}let m=n.doc.content.findDiffStart(r.doc.content),g=n.doc.content.findDiffEnd(r.doc.content);if("number"==typeof m&&g&&m!==g.b)return l({rule:e,state:r,from:m,to:g,pasteEvt:a})}}))}({editor:e,rules:t});r.push(...n)}}let c=ur(t,"addProseMirrorPlugins",n);if(c){let e=c();r.push(...e)}return r})}get attributes(){return uc(this.extensions)}get nodeViews(){let{editor:e}=this,{nodeExtensions:t}=ul(this.extensions);return Object.fromEntries(t.filter(e=>!!ur(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:dl(t.name,this.schema)},i=ur(t,"addNodeView",r);if(!i)return[];let s=i();return s?[t.name,(r,i,o,a,l)=>{let c=up(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 ug([...this.extensions].reverse()).reduceRight((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:uS(n.name,this.schema)},i=ur(n,"dispatchTransaction",r);return i?t=>{i.call(r,{transaction:t,next:e})}:e},e)}transformPastedHTML(e){let{editor:t}=this;return ug([...this.extensions]).reduce((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:uS(n.name,this.schema)},i=ur(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}=ul(this.extensions);return Object.fromEntries(t.filter(e=>!!ur(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:dv(t.name,this.schema)},i=ur(t,"addMarkView",r);return i?[t.name,(r,s,o)=>{let a=up(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:uS(e.name,this.schema)};"mark"===e.type&&(null==(t=ua(ur(e,"keepOnSplit",n)))||t)&&this.splittableMarks.push(e.name);let r=ur(e,"onBeforeCreate",n),i=ur(e,"onCreate",n),s=ur(e,"onUpdate",n),o=ur(e,"onSelectionUpdate",n),a=ur(e,"onTransaction",n),l=ur(e,"onFocus",n),c=ur(e,"onBlur",n),d=ur(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)})}};pn.resolve=ub,pn.sort=ug,pn.flatten=ui,c6({},{ClipboardTextSerializer:()=>pi,Commands:()=>ps,Delete:()=>po,Drop:()=>pa,Editable:()=>pl,FocusEvents:()=>pd,Keymap:()=>pu,Paste:()=>pp,Tabindex:()=>ph,TextDirection:()=>pf,focusEventsPluginKey:()=>pc});var pr=class e extends u7{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)}},pi=pr.create({name:"clipboardTextSerializer",addOptions:()=>({blockSeparator:void 0}),addProseMirrorPlugins(){return[new s0({key:new s3("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=uv(n);return ux(r,{from:o,to:a},{...void 0!==this.options.blockSeparator?{blockSeparator:this.options.blockSeparator}:{},textSerializers:l})}}})]}}),ps=pr.create({name:"commands",addCommands:()=>({...c8})}),po=pr.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=d8(e.before,[e,...t]);uk(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 so){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()}}),pa=pr.create({name:"drop",addProseMirrorPlugins(){return[new s0({key:new s3("tiptapDrop"),props:{handleDrop:(e,t,n,r)=>{this.editor.emit("drop",{editor:this.editor,event:t,slice:n,moved:r})}}})]}}),pl=pr.create({name:"editable",addProseMirrorPlugins(){return[new s0({key:new s3("editable"),props:{editable:()=>this.editor.options.editable}})]}}),pc=new s3("focusEvents"),pd=pr.create({name:"focusEvents",addProseMirrorPlugins(){let{editor:e}=this;return[new s0({key:pc,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}}}})]}}),pu=pr.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:sL.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 dE()||dU()?i:r},addProseMirrorPlugins(){return[new s0({key:new s3("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=sL.atStart(t.doc).from,c=sL.atEnd(t.doc).to;if(s||o!==l||a!==c||!uA(n.doc))return;let d=n.tr,u=c9({state:n,transaction:d}),{commands:p}=new c7({editor:this.editor,state:u});if(p.clearNodes(),d.steps.length)return d}})]}}),pp=pr.create({name:"paste",addProseMirrorPlugins(){return[new s0({key:new s3("tiptapPaste"),props:{handlePaste:(e,t,n)=>{this.editor.emit("paste",{editor:this.editor,event:t,slice:n})}}})]}}),ph=pr.create({name:"tabindex",addOptions:()=>({value:void 0}),addProseMirrorPlugins(){return[new s0({key:new s3("tabindex"),props:{attributes:()=>{var e;return this.editor.isEditable||void 0!==this.options.value?{tabindex:null!=(e=this.options.value)?e:"0"}:{}}}})]}}),pf=pr.create({name:"textDirection",addOptions:()=>({direction:void 0}),addGlobalAttributes(){if(!this.options.direction)return[];let{nodeExtensions:e}=ul(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 s0({key:new s3("textDirection"),props:{attributes:()=>{let e=this.options.direction;return e?{dir:e}:{}}}})]}}),pm=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)}},pg=`.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,f.useState)(""),p=(0,f.useRef)(null),m=window.location.origin,b=(0,f.useCallback)(()=>t9,[]),x=(0,f.useCallback)(()=>d.replace(/\$WIKI_URL/g,m),[d,m]),y=(0,f.useCallback)(()=>`npx wiki-viewer-mcp register --url ${m} --id ai:myagent --name "My Agent"`,[m]),w=(0,f.useCallback)(()=>JSON.stringify({servers:{"wiki-viewer":{command:"npx",args:["wiki-viewer-mcp"],env:{WIKI_VIEWER_URL:m,WIKI_VIEWER_TOKEN:"<token from register>",WIKI_VIEWER_AGENT_ID:"ai:myagent"}}}},null,2),[m]),k=t7(b),N=t7(x),S=t7(y),C=t7(w);return((0,f.useEffect)(()=>{if(t)return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e);function e(e){"Escape"===e.key&&n()}},[t,n]),(0,f.useEffect)(()=>{t&&p.current?.focus()},[t]),(0,f.useEffect)(()=>{if(!t)return;o();let e=setInterval(()=>void o(),1e4);return()=>clearInterval(e)},[t,o]),(0,f.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:"rounded-md border border-border bg-muted/30 p-3",children:[(0,s.jsx)("p",{className:"text-sm font-medium text-foreground",children:"Work with this wiki using AI"}),(0,s.jsxs)("p",{className:"mt-1 text-xs leading-relaxed text-muted-foreground",children:["Connect Claude, Cursor, ChatGPT, and more. Pick by what you want — each option gives a copy-paste setup. You approve every assistant in ",(0,s.jsx)("span",{className:"font-medium text-foreground/80",children:"Agents"})," below before it gets access."]})]}),(0,s.jsxs)("section",{className:"space-y-3",children:[(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:"Co-write docs with you"}),(0,s.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Edits arrive as suggestions with comments you accept or revert. No MCP needed."}),(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)(tr.Copy,{className:"h-3.5 w-3.5"})," Paste into any chatbot"]})}),(0,s.jsxs)("p",{className:"text-[10px] text-muted-foreground/50 pt-1",children:["Or install once so it sticks"," ",(0,s.jsx)("span",{className:"text-muted-foreground/40",children:"· Claude, OpenCode"}),":"]}),(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:t9}),(0,s.jsx)(v.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0",title:"Copy this command",onClick:()=>void k.copy(),children:k.copied?(0,s.jsx)(g.Check,{className:"h-3.5 w-3.5 text-green-500"}):(0,s.jsx)(tr.Copy,{className:"h-3.5 w-3.5"})})]})]}),(0,s.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,s.jsxs)("p",{className:"text-xs font-semibold text-foreground",children:["Edit files directly"," ",(0,s.jsx)("span",{className:"font-normal text-muted-foreground/60",children:"· Claude Code, Cursor, Codex"})]}),(0,s.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Native read / search / edit tools over MCP. Run to request access:"}),(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)(tr.Copy,{className:"h-3.5 w-3.5"})})]}),(0,s.jsxs)("p",{className:"text-[10px] text-muted-foreground/50",children:["Approve in ",(0,s.jsx)("span",{className:"font-medium text-foreground/70",children:"Agents"}),", then add to your tool:"]}),(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)(tr.Copy,{className:"h-3.5 w-3.5"})," Copy config (mcp.json)"]})})]}),(0,s.jsxs)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[(0,s.jsx)("span",{className:"text-[10px] text-muted-foreground/50",children:"For developers:"}),(0,s.jsxs)("button",{type:"button",onClick:()=>void c(),className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[l?(0,s.jsx)(g.Check,{className:"h-3 w-3 text-green-500"}):(0,s.jsx)(tr.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-[10px] text-primary hover:underline",children:[(0,s.jsx)(tT.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-[10px] text-primary hover:underline",children:[(0,s.jsx)(tT.ExternalLink,{className:"h-3 w-3"})," install JSON"]})]})]}),(0,s.jsx)(t$,{}),(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)(tA,{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)(t6,{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 ne=e.i(406347);let nt=(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"}]]),nn=(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"}]]),nr=(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"}]]),ni=(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"}]]),ns=(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"}]]),no=(0,o.default)("terminal",[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]]),na=(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 nl({pos:e,branches:t,loading:n,busyName:r,disabled:i,onPick:o,onClose:a}){let[l,c]=(0,f.useState)(""),d=(0,f.useRef)(null);if((0,f.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(),m=h?t.filter(e=>e.name.toLowerCase().includes(h)):t;return(0,tv.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===m.length?(0,s.jsx)("p",{className:"px-2 py-1 text-[10px] text-muted-foreground",children:"No match"}):m.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 nc=e.i(918552),nd=e.i(136131),nu="ContextMenu",[np,nh]=(0,N.createContextScope)(nu,[nc.createMenuScope]),nf=(0,nc.createMenuScope)(),[nm,ng]=np(nu),nb=e=>{let{__scopeContextMenu:t,children:n,onOpenChange:r,dir:i,modal:o=!0}=e,[a,l]=f.useState(!1),c=nf(t),d=(0,nd.useCallbackRef)(r),u=f.useCallback(e=>{l(e),d(e)},[d]);return(0,s.jsx)(nm,{scope:t,open:a,onOpenChange:u,modal:o,children:(0,s.jsx)(nc.Root,{...c,dir:i,open:a,onOpenChange:u,modal:o,children:n})})};nb.displayName=nu;var nx="ContextMenuTrigger",ny=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,disabled:r=!1,...i}=e,o=ng(nx,n),a=nf(n),l=f.useRef({x:0,y:0}),c=f.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...l.current})}),d=f.useRef(0),u=f.useCallback(()=>window.clearTimeout(d.current),[]),p=e=>{l.current={x:e.clientX,y:e.clientY},o.onOpenChange(!0)};return f.useEffect(()=>u,[u]),f.useEffect(()=>void(r&&u()),[r,u]),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(nc.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,nO(e=>{u(),d.current=window.setTimeout(()=>p(e),700)})),onPointerMove:r?e.onPointerMove:(0,w.composeEventHandlers)(e.onPointerMove,nO(u)),onPointerCancel:r?e.onPointerCancel:(0,w.composeEventHandlers)(e.onPointerCancel,nO(u)),onPointerUp:r?e.onPointerUp:(0,w.composeEventHandlers)(e.onPointerUp,nO(u))})]})});ny.displayName=nx;var nv=e=>{let{__scopeContextMenu:t,...n}=e,r=nf(t);return(0,s.jsx)(nc.Portal,{...r,...n})};nv.displayName="ContextMenuPortal";var nw="ContextMenuContent",nk=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=ng(nw,n),o=nf(n),a=f.useRef(!1);return(0,s.jsx)(nc.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)"}})});nk.displayName=nw,f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Group,{...i,...r,ref:t})}).displayName="ContextMenuGroup";var nN=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Label,{...i,...r,ref:t})});nN.displayName="ContextMenuLabel";var nS=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Item,{...i,...r,ref:t})});nS.displayName="ContextMenuItem";var nC=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.CheckboxItem,{...i,...r,ref:t})});nC.displayName="ContextMenuCheckboxItem",f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.RadioGroup,{...i,...r,ref:t})}).displayName="ContextMenuRadioGroup";var nj=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.RadioItem,{...i,...r,ref:t})});nj.displayName="ContextMenuRadioItem";var nE=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.ItemIndicator,{...i,...r,ref:t})});nE.displayName="ContextMenuItemIndicator";var nM=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Separator,{...i,...r,ref:t})});nM.displayName="ContextMenuSeparator",f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.Arrow,{...i,...r,ref:t})}).displayName="ContextMenuArrow";var nA=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.SubTrigger,{...i,...r,ref:t})});nA.displayName="ContextMenuSubTrigger";var nT=f.forwardRef((e,t)=>{let{__scopeContextMenu:n,...r}=e,i=nf(n);return(0,s.jsx)(nc.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 nO(e){return t=>"mouse"!==t.pointerType?e(t):void 0}nT.displayName="ContextMenuSubContent";var n_=e.i(149427);f.forwardRef(({className:e,inset:t,children:n,...r},i)=>(0,s.jsxs)(nA,{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)(e3.ChevronRight,{className:"ml-auto h-4 w-4"})]})).displayName=nA.displayName,f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(nT,{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=nT.displayName;let nD=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(nv,{children:(0,s.jsx)(nk,{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})}));nD.displayName=nk.displayName;let nR=f.forwardRef(({className:e,inset:t,...n},r)=>(0,s.jsx)(nS,{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}));nR.displayName=nS.displayName,f.forwardRef(({className:e,children:t,checked:n,...r},i)=>(0,s.jsxs)(nC,{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)(nE,{children:(0,s.jsx)(g.Check,{className:"h-4 w-4"})})}),t]})).displayName=nC.displayName,f.forwardRef(({className:e,children:t,...n},r)=>(0,s.jsxs)(nj,{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)(nE,{children:(0,s.jsx)(n_.Circle,{className:"h-2 w-2 fill-current"})})}),t]})).displayName=nj.displayName,f.forwardRef(({className:e,inset:t,...n},r)=>(0,s.jsx)(nN,{ref:r,className:(0,eh.cn)("px-2 py-1.5 text-sm font-normal",t&&"pl-8",e),...n})).displayName=nN.displayName;let nI=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(nM,{ref:n,className:(0,eh.cn)("-mx-1 my-1 h-px bg-muted",e),...t}));nI.displayName=nM.displayName;let nL="wiki-humanize-names",nP=(0,eN.create)((e,t)=>({humanize:"1"===localStorage.getItem(nL),toggle:()=>{let n=!t().humanize;n?localStorage.setItem(nL,"1"):localStorage.removeItem(nL),e({humanize:n})}})),nz="wiki-show-hidden",n$=(0,eN.create)((e,t)=>({showHidden:"1"===localStorage.getItem(nz),toggle:()=>{let n=!t().showHidden;n?localStorage.setItem(nz,"1"):localStorage.removeItem(nz),e({showHidden:n})}}));function nB(e){return e.split(".").pop()?.toLowerCase()??""}function nF(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=nB(e);return r?["md","markdown"].includes(r)?"editor":"txt"===r?"text":["csv","tsv"].includes(r)?"csv":"pdf"===r?"pdf":["mmd","mermaid"].includes(r)?"mermaid":"ipynb"===r?"notebook":["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"}let nH=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 nU(e){let t=nF(e,"file");return"editor"===t||"text"===t||nH.has(nB(e))}function nV(e){return["md","markdown"].includes(nB(e))}function nW(e){return"image"===nF(e,"file")}function nq(e){return"html"===nF(e,"file")}let nK={contentVisibility:"auto",containIntrinsicSize:"auto 32px"};function nG({node:e,ctx:t,isFavorited:n,activeWorkspaceId:r}){return(0,s.jsxs)(nD,{className:"w-48",children:[(0,s.jsxs)(nR,{onSelect:()=>t.copyPath(e.path),children:[(0,s.jsx)(tr.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),nV(e.name)&&(0,s.jsxs)(nR,{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)(nR,{onSelect:()=>t.copyUrl(e.path),children:[(0,s.jsx)(nt,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),"file"===e.type&&nU(e.name)&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(nR,{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)(nR,{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)(nI,{}),"dir"===e.type&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(nR,{onSelect:()=>{e.expanded||t.toggleFolder(e),t.setNewFileParent(e.path),t.setNewFileName(""),t.setFileCreateError(null)},children:[(0,s.jsx)(ni,{className:"mr-2 h-3.5 w-3.5"}),"New file here"]}),(0,s.jsxs)(nR,{onSelect:()=>t.triggerUpload(e.path),children:[(0,s.jsx)(na,{className:"mr-2 h-3.5 w-3.5"}),"Upload here"]}),(0,s.jsxs)(nR,{onSelect:()=>{t.setNewFolderParent(e.path),t.setNewFolderName(""),t.setFolderError(null)},children:[(0,s.jsx)(ns,{className:"mr-2 h-3.5 w-3.5"}),"New subfolder"]}),(0,s.jsx)(nI,{})]}),(0,s.jsxs)(nR,{onSelect:()=>t.handleDownload(e),children:[(0,s.jsx)(ne.Download,{className:"mr-2 h-3.5 w-3.5"}),"file"===e.type?"Download":"Download as zip"]}),(0,s.jsxs)(nR,{onSelect:()=>t.toggleFavorite(e,r),children:[(0,s.jsx)(te,{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)(nI,{}),(0,s.jsxs)(nR,{className:"text-destructive focus:text-destructive",onSelect:()=>{t.setDeletingPath(e.path),t.setDeletingIsDir("file"!==e.type)},children:[(0,s.jsx)(ts,{className:"mr-2 h-3.5 w-3.5"}),"Delete"]})]})}function nJ({name:e,type:t}){let n="h-3.5 w-3.5 shrink-0";return"dir"===t?(0,s.jsx)(e5,{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)(no,{className:(0,eh.cn)(n,"text-emerald-500")}):nq(e)?(0,s.jsx)(c,{className:(0,eh.cn)(n,"text-foreground/60")}):nW(e)?(0,s.jsx)(d.Image,{className:(0,eh.cn)(n,"text-sunshine-700")}):nU(e)?(0,s.jsx)(l.FileText,{className:(0,eh.cn)(n,"text-foreground/70")}):(0,s.jsx)(nr,{className:(0,eh.cn)(n,"text-foreground/60")})}let nZ=(0,f.memo)(function({node:e,depth:t,ctx:n,isMobile:r,activeWorkspaceId:i,sidebarScrollRef:o,isActive:a,isDragOver:p,isFavorited:h,isAgentActive:f,isPulling:m,branchOpen:g,branchPos:b,branches:x,branchLoading:y,checkingOut:w,onHoverEnter:k,onHoverLeave:N}){var S;let C,j,E,M,A,T=nP(e=>e.humanize);return(0,s.jsxs)(nb,{children:[(0,s.jsx)(ny,{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`,...nK},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)(e3.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)(e4,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):(0,s.jsx)(e5,{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)(no,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-emerald-500")}):nq(e.name)?(0,s.jsx)(c,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/60")}):nW(e.name)?(0,s.jsx)(d.Image,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-sunshine-700")}):nU(e.name)?(0,s.jsx)(l.FileText,{className:(0,eh.cn)("h-4 w-4 shrink-0",!a&&"text-foreground/70")}):(0,s.jsx)(nr,{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)(e6,{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:"*"})]}),m?(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)(tR,{className:"h-2.5 w-2.5"})}),g&&b&&(0,s.jsx)(nl,{pos:b,branches:x,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)}})]}),f&&(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)(nn,{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)(tr.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),nV(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)(nt,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),"file"===e.type&&nU(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)(ni,{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)(na,{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)(ns,{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)(ne.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)(te,{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)(ts,{className:"mr-2 h-3.5 w-3.5"}),"Delete"]})]})]})})]})}),(0,s.jsx)(nG,{node:e,ctx:n,isFavorited:h,activeWorkspaceId:i})]})}),nX=(0,f.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:m,isMobile:b,activeWorkspaceId:x,newFileParent:y,newFileName:w,fileCreateError:k,newFolderParent:N,newFolderName:S,folderError:C,sidebarScrollRef:j}=e,E=n$(e=>e.showHidden),M=(0,f.useRef)(null),A=(0,f.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,f.useCallback)(()=>{M.current&&(clearTimeout(M.current),M.current=null)},[]),O=(0,f.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:f,depth:y}=e;if("row"===e.kind){let e=i===f.path;return(0,s.jsx)(nZ,{node:f,depth:y,ctx:t,isMobile:b,activeWorkspaceId:x,sidebarScrollRef:j,isActive:n===f.path,isDragOver:r===f.path,isFavorited:m.some(e=>e.path===f.path),isAgentActive:p.has(f.path),isPulling:u===f.path,branchOpen:e,branchPos:e?o:null,branches:f.git?a[f.path]??[]:[],branchLoading:!!f.git&&!!c[f.path],checkingOut:e?d:null,onHoverEnter:A,onHoverLeave:T},f.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`,...nK},children:[(0,s.jsx)("span",{className:"w-3.5 shrink-0"}),(0,s.jsx)(e5,{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-${f.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`,...nK},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,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-${f.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`,...nK},children:"Empty"},`empty-${f.path}`)})})});function nY(e){return e?`wiki-pinned-files-${e}`:"wiki-pinned-files"}function nQ(e){try{let t=localStorage.getItem(nY(e));return t?JSON.parse(t):[]}catch{return[]}}let n0=(0,eN.create)((e,t)=>({favorites:[],loadForWorkspace:t=>{e({favorites:nQ(t)})},toggle:(t,n)=>{let r=nQ(n),i=r.some(e=>e.path===t.path)?r.filter(e=>e.path!==t.path):[...r,t];localStorage.setItem(nY(n),JSON.stringify(i)),e({favorites:i})},isFavorited:e=>t().favorites.some(t=>t.path===e)}));function n1({doc:e,node:t,extraItems:n,activeWorkspaceId:r=null}){let i=n0(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)(nn,{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,tE.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)(ne.Download,{className:"mr-2 h-3.5 w-3.5"}),"Download"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>{n0.getState().toggle({path:t.path,name:t.name},r)},children:[(0,s.jsx)(te,{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)(tr.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),nV(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)(nt,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),nU(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 n2=(0,o.default)("align-center",[["path",{d:"M17 12H7",key:"16if0g"}],["path",{d:"M19 18H5",key:"18s9l3"}],["path",{d:"M21 6H3",key:"1jwq7v"}]]);var n3=e.i(409082);let n5=(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 n4=e.i(847463),n6=e.i(917356),n9=/[\\\/_+.#"@\[\(\{&]/,n7=/[\\\/_+.#"@\[\(\{&]/g,n8=/[\s-]/,re=/[\s-]/g;function rt(e){return e.toLowerCase().replace(re," ")}var rn='[cmdk-group=""]',rr='[cmdk-group-items=""]',ri='[cmdk-item=""]',rs=`${ri}:not([aria-disabled="true"])`,ro="cmdk-item-select",ra="data-value",rl=(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),f=r.indexOf(h,s),m=0;f>=0;)(c=e(t,n,r,i,f+1,o+1,a))>m&&(f===s?c*=1:n9.test(t.charAt(f-1))?(c*=.8,(u=t.slice(s,f-1).match(n7))&&s>0&&(c*=Math.pow(.999,u.length))):n8.test(t.charAt(f-1))?(c*=.9,(p=t.slice(s,f-1).match(re))&&s>0&&(c*=Math.pow(.999,p.length))):(c*=.17,s>0&&(c*=Math.pow(.999,f-s))),t.charAt(f)!==n.charAt(o)&&(c*=.9999)),(c<.1&&r.charAt(f-1)===i.charAt(o+1)||i.charAt(o+1)===i.charAt(o)&&r.charAt(f-1)!==i.charAt(o))&&.1*(d=e(t,n,r,i,f+1,o+2,a))>c&&(c=.1*d),c>m&&(m=c),f=r.indexOf(h,f+1);return a[l]=m,m}(r=n&&n.length>0?`${r+" "+n.join(" ")}`:r,t,rt(r),rt(t),0,0,{})},rc=f.createContext(void 0),rd=f.createContext(void 0),ru=f.createContext(void 0),rp=f.forwardRef((e,t)=>{let n=rk(()=>{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=rk(()=>new Set),i=rk(()=>new Map),s=rk(()=>new Map),o=rk(()=>new Set),a=rv(e),{label:l,children:c,value:d,onValueChange:u,filter:p,shouldFilter:h,loop:m,disablePointerSelection:g=!1,vimBindings:b=!0,...x}=e,y=(0,S.useId)(),v=(0,S.useId)(),w=(0,S.useId)(),k=f.useRef(null),N=rC();rw(()=>{if(void 0!==d){let e=d.trim();n.current.value=e,C.emit()}},[d]),rw(()=>{N(6,O)},[]);let C=f.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=f.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:rl;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(rr);t?t.appendChild(e.parentElement===t?e:e.closest(`${rr} > *`)):r.appendChild(e.parentElement===r?e:e.closest(`${rr} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{var t;let n=null==(t=k.current)?void 0:t.querySelector(`${rn}[${ra}="${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(ra);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(rn))?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(`${ri}[aria-selected="true"]`)}function D(){var e;return Array.from((null==(e=k.current)?void 0:e.querySelectorAll(rs))||[])}function R(e){let t=D()[e];t&&C.setState("value",t.getAttribute(ra))}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(ra))}function L(e){let t=_(),n=null==t?void 0:t.closest(rn),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,rn):function(e,t){let n=e.previousElementSibling;for(;n;){if(n.matches(t))return n;n=n.previousElementSibling}}(n,rn))?void 0:n.querySelector(rs);r?C.setState("value",r.getAttribute(ra)):I(e)}let P=()=>R(D().length-1),z=e=>{e.preventDefault(),e.metaKey?P():e.altKey?L(1):I(1)},$=e=>{e.preventDefault(),e.metaKey?R(0):e.altKey?L(-1):I(-1)};return f.createElement(tk.div,{ref:t,tabIndex:-1,...x,"cmdk-root":"",onKeyDown:e=>{var t;null==(t=x.onKeyDown)||t.call(x,e);let n=e.nativeEvent.isComposing||229===e.keyCode;if(!(e.defaultPrevented||n))switch(e.key){case"n":case"j":b&&e.ctrlKey&&z(e);break;case"ArrowDown":z(e);break;case"p":case"k":b&&e.ctrlKey&&$(e);break;case"ArrowUp":$(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(ro);t.dispatchEvent(e)}}}}},f.createElement("label",{"cmdk-label":"",htmlFor:j.inputId,id:j.labelId,style:rE},l),rj(e,e=>f.createElement(rd.Provider,{value:C},f.createElement(rc.Provider,{value:j},e))))}),rh=f.forwardRef((e,t)=>{var n,r;let i=(0,S.useId)(),s=f.useRef(null),o=f.useContext(ru),a=f.useContext(rc),l=rv(e),c=null!=(r=null==(n=l.current)?void 0:n.forceMount)?r:null==o?void 0:o.forceMount;rw(()=>{if(!c)return a.item(i,null==o?void 0:o.id)},[c]);let d=rS(i,s,[e.value,e.children,s],e.keywords),u=f.useContext(rd),p=rN(e=>e.value&&e.value===d.current),h=rN(e=>!!c||!1===a.filter()||!e.search||e.filtered.items.get(i)>0);function m(){var e,t;g(),null==(t=(e=l.current).onSelect)||t.call(e,d.current)}function g(){u.setState("value",d.current,!0)}if(f.useEffect(()=>{let t=s.current;if(!(!t||e.disabled))return t.addEventListener(ro,m),()=>t.removeEventListener(ro,m)},[h,e.onSelect,e.disabled]),!h)return null;let{disabled:b,value:x,onSelect:y,forceMount:v,keywords:w,...N}=e;return f.createElement(tk.div,{ref:(0,k.composeRefs)(s,t),...N,id:i,"cmdk-item":"",role:"option","aria-disabled":!!b,"aria-selected":!!p,"data-disabled":!!b,"data-selected":!!p,onPointerMove:b||a.getDisablePointerSelection()?void 0:g,onClick:b?void 0:m},e.children)}),rf=f.forwardRef((e,t)=>{let{heading:n,children:r,forceMount:i,...s}=e,o=(0,S.useId)(),a=f.useRef(null),l=f.useRef(null),c=(0,S.useId)(),d=f.useContext(rc),u=rN(e=>!!i||!1===d.filter()||!e.search||e.filtered.groups.has(o));rw(()=>d.group(o),[]),rS(o,a,[e.value,e.heading,l]);let p=f.useMemo(()=>({id:o,forceMount:i}),[i]);return f.createElement(tk.div,{ref:(0,k.composeRefs)(a,t),...s,"cmdk-group":"",role:"presentation",hidden:!u||void 0},n&&f.createElement("div",{ref:l,"cmdk-group-heading":"","aria-hidden":!0,id:c},n),rj(e,e=>f.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?c:void 0},f.createElement(ru.Provider,{value:p},e))))}),rm=f.forwardRef((e,t)=>{let{alwaysRender:n,...r}=e,i=f.useRef(null),s=rN(e=>!e.search);return n||s?f.createElement(tk.div,{ref:(0,k.composeRefs)(i,t),...r,"cmdk-separator":"",role:"separator"}):null}),rg=f.forwardRef((e,t)=>{let{onValueChange:n,...r}=e,i=null!=e.value,s=f.useContext(rd),o=rN(e=>e.search),a=rN(e=>e.selectedItemId),l=f.useContext(rc);return f.useEffect(()=>{null!=e.value&&s.setState("search",e.value)},[e.value]),f.createElement(tk.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)}})}),rb=f.forwardRef((e,t)=>{let{children:n,label:r="Suggestions",...i}=e,s=f.useRef(null),o=f.useRef(null),a=rN(e=>e.selectedItemId),l=f.useContext(rc);return f.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)}}},[]),f.createElement(tk.div,{ref:(0,k.composeRefs)(s,t),...i,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":a,"aria-label":r,id:l.listId},rj(e,e=>f.createElement("div",{ref:(0,k.composeRefs)(o,l.listInnerRef),"cmdk-list-sizer":""},e)))}),rx=f.forwardRef((e,t)=>{let{open:n,onOpenChange:r,overlayClassName:i,contentClassName:s,container:o,...a}=e;return f.createElement(B,{open:n,onOpenChange:r},f.createElement(W,{container:o},f.createElement(K,{"cmdk-overlay":"",className:i}),f.createElement(X,{"aria-label":e.label,"cmdk-dialog":"",className:s},f.createElement(rp,{ref:t,...a}))))}),ry=Object.assign(rp,{List:rb,Item:rh,Input:rg,Group:rf,Separator:rm,Dialog:rx,Empty:f.forwardRef((e,t)=>rN(e=>0===e.filtered.count)?f.createElement(tk.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),Loading:f.forwardRef((e,t)=>{let{progress:n,children:r,label:i="Loading...",...s}=e;return f.createElement(tk.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":i},rj(e,e=>f.createElement("div",{"aria-hidden":!0},e)))})});function rv(e){let t=f.useRef(e);return rw(()=>{t.current=e}),t}var rw="u"<typeof window?f.useEffect:f.useLayoutEffect;function rk(e){let t=f.useRef();return void 0===t.current&&(t.current=e()),t}function rN(e){let t=f.useContext(rd),n=()=>e(t.snapshot());return f.useSyncExternalStore(t.subscribe,n,n)}function rS(e,t,n,r=[]){let i=f.useRef(),s=f.useContext(rc);return rw(()=>{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(ra,a),i.current=a}),i}var rC=()=>{let[e,t]=f.useState(),n=rk(()=>new Map);return rw(()=>{n.current.forEach(e=>e()),n.current=new Map},[e]),(e,r)=>{n.current.set(e,r),t({})}};function rj({asChild:e,children:t},n){let r;return e&&f.isValidElement(t)?f.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 rE={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};let rM=(0,o.default)("search",[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]),rA=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry,{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 rT({children:e,shouldFilter:t,...n}){return(0,s.jsx)(B,{...n,children:(0,s.jsxs)(eX,{className:"overflow-hidden p-0 shadow-golden max-w-lg",children:[(0,s.jsx)(e0,{className:"sr-only",children:"Search"}),(0,s.jsx)(rA,{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})]})})}rA.displayName=ry.displayName;let rO=f.forwardRef(({className:e,...t},n)=>(0,s.jsxs)("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[(0,s.jsx)(rM,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),(0,s.jsx)(ry.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})]}));rO.displayName=ry.Input.displayName;let r_=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry.List,{ref:n,className:(0,eh.cn)("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...t}));r_.displayName=ry.List.displayName;let rD=f.forwardRef((e,t)=>(0,s.jsx)(ry.Empty,{ref:t,className:"py-6 text-center text-sm text-muted-foreground",...e}));rD.displayName=ry.Empty.displayName;let rR=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry.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}));rR.displayName=ry.Group.displayName;let rI=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry.Separator,{ref:n,className:(0,eh.cn)("-mx-1 h-px bg-border",e),...t}));rI.displayName=ry.Separator.displayName;let rL=f.forwardRef(({className:e,...t},n)=>(0,s.jsx)(ry.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}));rL.displayName=ry.Item.displayName;let rP=null,rz=null,r$=(0,eN.create)(e=>({query:"",results:[],loading:!1,truncated:!1,open:!1,setQuery:t=>e({query:t}),setOpen:t=>e({open:t}),clear:()=>{rz&&clearTimeout(rz),rP?.abort(),e({query:"",results:[],loading:!1,truncated:!1})},search:t=>(rz&&clearTimeout(rz),t.trim())?(e({loading:!0}),new Promise(n=>{rz=setTimeout(()=>{rB(e,t).finally(n)},150)})):(rP?.abort(),e({results:[],loading:!1,truncated:!1}),Promise.resolve())}));async function rB(e,t){rP?.abort();let n=new AbortController;rP=n;try{let r=await (0,tE.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 rF=e.i(395624);function rH({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 rU({onOpenFile:e,recents:t=[],onToggleSidebar:n=()=>void 0,onNewFile:r=()=>void 0,onCopyPath:i=()=>void 0}){let o=r$(e=>e.open),l=r$(e=>e.setOpen),c=r$(e=>e.query),d=r$(e=>e.setQuery),u=r$(e=>e.results),p=r$(e=>e.loading),h=r$(e=>e.truncated),m=r$(e=>e.search),{resolvedTheme:g,setTheme:b}=(0,n6.useTheme)(),x=tO(e=>e.toggle),y=(0,rF.useViewWidthStore)(e=>e.width),v=(0,rF.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,f.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,f.useEffect)(()=>{if(!o||k)return;let e=setTimeout(()=>{m(S)},120);return()=>clearTimeout(e)},[S,k,o,m]);let j=(rF.VIEW_WIDTH_ORDER.indexOf(y)+1)%rF.VIEW_WIDTH_ORDER.length,E=rF.VIEW_WIDTH_LABEL[rF.VIEW_WIDTH_ORDER[j]];return(0,s.jsxs)(rT,{open:o,onOpenChange:e=>{l(e),e||d("")},shouldFilter:!1,children:[(0,s.jsx)(rO,{placeholder:"Search files… ( > for actions )",value:c,onValueChange:d}),(0,s.jsxs)(r_,{children:[N&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(rR,{heading:"Recent",children:t.map(t=>(0,s.jsxs)(rL,{value:`recent:${t.path}`,onSelect:()=>{e(t.path),l(!1),d("")},children:[(0,s.jsx)(to,{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)(rI,{})]}),k&&(0,s.jsxs)(rR,{heading:"Actions",children:[(0,s.jsxs)(rL,{value:"toggle-dark-mode",onSelect:()=>C(()=>b("dark"===g?"light":"dark")),children:["dark"===g?(0,s.jsx)(n4.Sun,{className:"mr-2 h-4 w-4"}):(0,s.jsx)(n3.Moon,{className:"mr-2 h-4 w-4"}),"dark"===g?"Switch to light mode":"Switch to dark mode"]}),(0,s.jsxs)(rL,{value:"toggle-ai-panel",onSelect:()=>C(x),children:[(0,s.jsx)(a,{className:"mr-2 h-4 w-4"}),"Toggle AI panel"]}),(0,s.jsxs)(rL,{value:"toggle-sidebar",onSelect:()=>C(n),children:[(0,s.jsx)(n5,{className:"mr-2 h-4 w-4"}),"Toggle sidebar"]}),(0,s.jsxs)(rL,{value:"new-file",onSelect:()=>C(r),children:[(0,s.jsx)(ni,{className:"mr-2 h-4 w-4"}),"New file"]}),(0,s.jsxs)(rL,{value:"copy-path",onSelect:()=>C(i),children:[(0,s.jsx)(tr.Copy,{className:"mr-2 h-4 w-4"}),"Copy current file path"]}),(0,s.jsxs)(rL,{value:"cycle-view-width",onSelect:()=>C(v),children:[(0,s.jsx)(n2,{className:"mr-2 h-4 w-4"}),(0,s.jsxs)("span",{children:["Change view width"," ",(0,s.jsxs)("span",{className:"text-muted-foreground",children:["(",rF.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)(rD,{children:"No matches."}),u.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(rI,{}),(0,s.jsx)(rR,{heading:h?"Top results (refine query for more)":"Results",children:u.map(t=>(0,s.jsx)(rL,{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)(rH,{html:t.snippet})})]})},t.path))})]})]})]})]})}e.i(335884);let rV=(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 rW=e.i(301138);let rq=(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"}]]),rK=(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"}]]),rG=(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"}]]),rJ=(0,o.default)("plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]),rZ=(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 rX=e.i(109680);function rY({onOpenFile:e}){let t=r$(e=>e.query),n=r$(e=>e.setQuery),r=r$(e=>e.results),i=r$(e=>e.loading),o=r$(e=>e.search),a=r$(e=>e.clear),[l,c]=(0,f.useState)(0),d=(0,f.useRef)(null);function u(t){let n=r[t];n&&(e(n.path),a())}return(0,f.useEffect)(()=>{c(0)},[r]),(0,f.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)(rM,{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)(rH,{html:e.snippet})})]},e.path))]})]})}var rQ=e.i(515288);function r0(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 r1({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:f,setBranchPickerWsId:m,setWsBranchPos:x,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||(m(null),x(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)(b,{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){m(null),x(null);return}let n=t.currentTarget.getBoundingClientRect();x({top:n.bottom+4,left:n.left}),m(e.id),y(e.id)},children:[(0,s.jsx)(e6,{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)(e6,{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)(e7,{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)(e6,{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&&r0(e.git.lastPulledAt)&&(0,s.jsxs)("span",{className:"text-[10px] text-muted-foreground/70",children:["synced ",r0(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)(tR,{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)(ts,{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:f,children:[(0,s.jsx)(ns,{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)(nl,{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:()=>{m(null),x(null)}}):null})()]})}let r2="wiki-sidebar-width";function r3(e){return Number.isNaN(e)?288:Math.min(600,Math.max(200,Math.round(e)))}let r5=(0,eN.create)(e=>({width:function(){let e=localStorage.getItem(r2);if(e){let t=Number.parseInt(e,10);if(!Number.isNaN(t))return r3(t)}return 288}(),setWidth:t=>{let n=r3(t);localStorage.setItem(r2,String(n)),e({width:n})}}));function r4(e){return e.split("/").pop()??e}function r6({workspace:e,doc:t,fileTree:n,upload:r,isMobile:i,hideChrome:o,sidebarCollapsed:c,setSidebarCollapsed:d,sidebarResizing:p,setSidebarResizing:f,sidebarWidth:x,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:z,setTheme:$}=(0,n6.useTheme)(),B=nP(e=>e.humanize),F=n$(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)(rQ.Card,{style:i?void 0:{width:x},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.11.4",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)(rG,{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)(rJ,{className:"h-3.5 w-3.5"}),"New",(0,s.jsx)(b,{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)(ni,{className:"mr-2 h-3.5 w-3.5"}),"New file"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>S(e=>({...e,folder:{...e.folder,parent:"",name:"",error:null}})),children:[(0,s.jsx)(ns,{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)(na,{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)(tR,{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:()=>{tO.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)(nn,{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)(rV,{className:"mr-2 h-3.5 w-3.5"}),"Pull latest"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>n$.getState().toggle(),children:[F?(0,s.jsx)(rq,{className:"mr-2 h-3.5 w-3.5"}):(0,s.jsx)(rW.Eye,{className:"mr-2 h-3.5 w-3.5"}),F?"Hide hidden files":"Show hidden files"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>nP.getState().toggle(),children:[(0,s.jsx)(rX.Type,{className:"mr-2 h-3.5 w-3.5"}),B?"Raw file names":"Humanize names"]}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>$("dark"===z?"light":"dark"),children:["dark"===z?(0,s.jsx)(n4.Sun,{className:"mr-2 h-3.5 w-3.5"}):(0,s.jsx)(n3.Moon,{className:"mr-2 h-3.5 w-3.5"}),"dark"===z?"Light mode":"Dark mode"]}),(0,s.jsx)(ek.DropdownMenuSeparator,{}),(0,s.jsxs)(ek.DropdownMenuItem,{onClick:()=>L(e=>({...e,settingsOpen:!0})),children:[(0,s.jsx)(rZ,{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)(m.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)(e5,{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)(rY,{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)(e3.ChevronRight,{className:"h-3 w-3"}):(0,s.jsx)(b,{className:"h-3 w-3"}),(0,s.jsx)(te,{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)(nb,{children:[(0,s.jsx)(ny,{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)(nJ,{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?r4(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(),n0.getState().toggle({path:n.path,name:n.name},e.activeWorkspaceId)},children:(0,s.jsx)(h,{className:"h-3 w-3"})})]})}),(0,s.jsx)(nG,{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)(e3.ChevronRight,{className:"h-3 w-3"}):(0,s.jsx)(b,{className:"h-3 w-3"}),(0,s.jsx)(rK,{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)(nb,{children:[(0,s.jsx)(ny,{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)(nJ,{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?r4(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)(nG,{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))]}),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)(na,{className:"h-3.5 w-3.5"}),"Upload Files"]})]}):(0,s.jsx)(nX,{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)(r1,{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;f(!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(x+(e.clientX-t))},s=()=>{f(!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(x-16)):"ArrowRight"===e.key&&(e.preventDefault(),y(x+16))},tabIndex:0,"aria-valuemin":200,"aria-valuemax":600,"aria-valuenow":x,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")})]})]})}function r9({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[m,g]=(0,f.useState)(!1),[b,x]=(0,f.useState)(null),[y,v]=(0,f.useState)({favorites:!1,recent:!0}),[w,k]=(0,f.useState)({file:{parent:null,name:"",error:null},folder:{parent:null,name:"",error:null}}),N=(0,f.useRef)(null),S=(0,f.useRef)(null),C=r5(e=>e.width),j=r5(e=>e.setWidth),E=(0,f.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,tE.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,f.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,tE.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",x("root"===n?"":t));return}r.path===t||t.startsWith(`${r.path}/`)||(e.dataTransfer.dropEffect="move",x("root"===n?"":t))}async function T(e,i){e.preventDefault(),e.stopPropagation(),x(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,tE.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,f.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,tE.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)=>n0.getState().toggle({path:e.path,name:e.name,type:e.type},t),setDragOverPath:x,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,f.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)(rU,{onOpenFile:t.openFromSearch,recents:d,onToggleSidebar:()=>l(e=>{let t=!e;return i&&!1===t&&tO.getState().close(),t}),onNewFile:()=>k(e=>({...e,file:{...e.file,parent:""}})),onCopyPath:()=>{t.openFile&&t.copyPath(t.openFile.path)}}),(0,s.jsx)(r6,{workspace:e,doc:t,fileTree:n,upload:r,isMobile:i,hideChrome:o,sidebarCollapsed:a,setSidebarCollapsed:l,sidebarResizing:m,setSidebarResizing:g,sidebarWidth:C,setSidebarWidth:j,collapsed:y,setCollapsed:v,createEntry:w,setCreateEntry:k,handleCreateFile:E,handleCreateFolder:M,dragOverPath:b,setDragOverPath:x,handleDragOver:A,handleDropOnFolder:T,sidebarScrollRef:N,treeCtx:_,favorites:c,recents:d,activePaths:u,setDialogs:h,handleRefreshWorkspace:e.handleRefreshWorkspace})]})}let r7=(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"}]]),r8=(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"}]]),ie=(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"}]]),it=(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"}]]),ir=(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 ii=e.i(75470),is=e.i(801273),io=e.i(61086);function ia(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 il(e){return e.map(e=>e.map(e=>e.includes(",")||e.includes('"')||e.includes("\n")?`"${e.replace(/"/g,'""')}"`:e).join(",")).join("\n")}function ic({path:e}){let[t,n]=(0,f.useState)([]),[r,i]=(0,f.useState)(""),[o,a]=(0,f.useState)(!1),[l,c]=(0,f.useState)(!1),[d,u]=(0,f.useState)(!1),[p,h]=(0,f.useState)(null),[m,g]=(0,f.useState)(!1),[b,x]=(0,f.useState)(1e3),y=(0,tE.withWs)(`/api/assets/${e}`);(0,f.useEffect)(()=>{fetch(y).then(e=>e.text()).then(e=>{let t=ia(e),r=e.length>2097152||t.length>2e3;i(e),n(t),g(r),a(r),c(!1)})},[y]);let w=(0,f.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:il(t);try{await (0,tE.wsFetch)(`/api/assets/${e}`,{method:"PUT",headers:{"Content-Type":"text/plain"},body:s}),o?n(ia(r)):i(s),c(!1)}catch(e){console.error("Failed to save CSV:",e)}u(!1)},N=t[0]||[],S=t.slice(1),C=m?S.slice(0,b):S,j=m&&b<S.length;return(0,s.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,s.jsxs)(io.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)(is.Save,{className:"h-3.5 w-3.5"}),d?"Saving...":"Save"]}),m&&(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(ia(r)):i(il(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)(r7,{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)(ne.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:()=>x(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-b).toLocaleString()," ","more rows"]}),(0,s.jsxs)("span",{className:"text-[11px] text-muted-foreground",children:[b.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 id(e){this.content=e}id.prototype={constructor:id,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 id(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 id(n)},addToStart:function(e,t){return new id([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var n=this.remove(e).content.slice();return n.push(e,t),new id(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 id(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=id.from(e)).size?new id(e.content.concat(this.subtract(e).content)):this},append:function(e){return(e=id.from(e)).size?new id(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=id.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}},id.from=function(e){if(e instanceof id)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new id(t)};class iu{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 iu(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 iu(n,r)}cutByIndex(e,t){return e==t?iu.empty:0==e&&t==this.content.length?this:new iu(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 iu(r,i)}addToStart(e){return new iu([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new iu(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 ih(0,e);if(e==this.size)return ih(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 ih(t+1,r);return ih(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 iu.empty;if(!Array.isArray(t))throw RangeError("Invalid input for Fragment.fromJSON");return iu.fromArray(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return iu.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 iu(t||e,n)}static from(e){if(!e)return iu.empty;if(e instanceof iu)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new iu([e],e.nodeSize);throw RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}iu.empty=new iu([],0);let ip={index:0,offset:0};function ih(e,t){return ip.index=e,ip.offset=t,ip}function im(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(!im(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!im(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}class ig{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&&im(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 ig.none;if(e instanceof ig)return[e];let t=e.slice();return t.sort((e,t)=>e.type.rank-t.type.rank),t}}ig.none=[];class ib 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(iu.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 ib("Cannot join "+t.type.name+" onto "+e.type.name)}function iv(e,t,n){let r=e.node(n);return iy(r,t.node(n)),r}function iw(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 ik(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&&(iw(e.nodeAfter,r),s++));for(let e=s;e<o;e++)iw(i.child(e),r);t&&t.depth==n&&t.textOffset&&iw(t.nodeBefore,r)}function iN(e,t){return e.type.checkContent(t),e.copy(t)}function iS(e,t,n){let r=[];return ik(null,e,n,r),e.depth>n&&iw(iN(iv(e,t,n+1),iS(e,t,n+1)),r),ik(t,null,n,r),new iu(r)}ix.empty=new ix(iu.empty,0,0);class iC{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 ig.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 iA(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 iC(t,n,i)}static resolveCached(e,t){let n=iM.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 iM.set(e,n=new ij);let r=n.elts[n.i]=iC.resolve(e,t);return n.i=(n.i+1)%iE,r}}class ij{constructor(){this.elts=[],this.i=0}}let iE=12,iM=new WeakMap;class iA{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 iT=Object.create(null);class iO{constructor(e,t,n,r=ig.none){this.type=e,this.attrs=t,this.marks=r,this.content=n||iu.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&&im(this.attrs,t||e.defaultAttrs||iT)&&ig.sameSet(this.marks,n||ig.none)}copy(e=null){return e==this.content?this:new iO(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new iO(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 ib("Inserted content deeper than insertion position");if(r.depth-n.openStart!=i.depth-n.openEnd)throw new ib("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 iN(o,iS(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(iu.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}(r,t);return iN(o,function e(t,n,r,i,s){let o=t.depth>s&&iv(t,n,s+1),a=i.depth>s&&iv(r,i,s+1),l=[];return ik(null,t,s,l),o&&a&&n.index(s)==r.index(s)?(iy(o,a),iw(iN(o,e(t,n,r,i,s+1)),l)):(o&&iw(iN(o,iS(t,n,s+1)),l),ik(n,r,s,l),a&&iw(iN(a,iS(r,i,s+1)),l)),ik(i,null,s,l),new iu(l)}(t,e,s,n,i))}{let e=t.parent,i=e.content;return iN(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 iC.resolveCached(this,e)}resolveNoCache(e){return iC.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()+")"),iD(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=iu.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=ig.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(!ig.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=iu.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}}iO.prototype.text=void 0;class i_ extends iO{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):iD(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 i_(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new i_(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 iD(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+"("+t+")";return t}class iR{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){var n;let r,i=new iI(e,t);if(null==i.next)return iR.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=iL(e),r=n;return e.eat(",")&&(r="}"!=e.next?iL(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]);iz(n,t).forEach(t=>{r||i.push([e,r=[]]),-1==r.indexOf(t)&&r.push(t)})}})});let s=r[t.join(",")]=new iR(t.indexOf(n.length-1)>-1);for(let t=0;t<i.length;t++){let n=i[t][1].sort(iP);s.next.push({type:i[t][0],next:r[n.join(",")]||e(n)})}return s}(iz(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 iu.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")}}iR.empty=new iR(!0);class iI{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 iL(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function iP(e,t){return t-e}function iz(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(iP)}function i$(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 iB(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 iF(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 iH(e,t){let n=Object.create(null);if(t)for(let r in t)n[r]=new iV(e,r,t[r]);return n}class iU{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=iH(e,n.attrs),this.defaultAttrs=i$(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==iR.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:iB(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error("NodeType.create can't construct text nodes");return new iO(this,this.computeAttrs(e),iu.from(t),ig.setFrom(n))}createChecked(e=null,t,n){return t=iu.from(t),this.checkContent(t),new iO(this,this.computeAttrs(e),t,ig.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),(t=iu.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(iu.empty,!0);return i?new iO(this,e,t.append(i),ig.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){iF(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:ig.none:e}static compile(e,t){let n=Object.create(null);e.forEach((e,r)=>n[e]=new iU(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 iV{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 iW{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=iH(e,r.attrs),this.excluded=null;let i=i$(this.attrs);this.instance=i?new ig(this,i):null}create(e=null){return!e&&this.instance?this.instance:new ig(this,iB(this.attrs,e))}static compile(e,t){let n=Object.create(null),r=0;return e.forEach((e,i)=>n[e]=new iW(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){iF(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class iq{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=id.from(e.nodes),t.marks=id.from(e.marks||{}),this.nodes=iU.compile(this.spec.nodes,this),this.marks=iW.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]=iR.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?iK(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?[]:iK(this,n.split(" "))}this.nodeFromJSON=e=>iO.fromJSON(this,e),this.markFromJSON=e=>ig.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 iU){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 i_(n,n.defaultAttrs,e,ig.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 iK(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 iG{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 i0(this,t,!1);return n.addAll(e,ig.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new i0(this,t,!0);return n.addAll(e,ig.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=i1(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=i1(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new iG(e,iG.schemaRules(e)))}}let iJ={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},iZ={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},iX={ol:!0,ul:!0};function iY(e,t,n){return null!=t?!!t|2*("full"===t):e&&"pre"==e.whitespace?3:-5&n}class iQ{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=ig.none,this.match=i||(4&s?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(iu.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=iu.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(iu.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&&!iJ.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class i0{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=iY(null,t.preserveWhitespace,0)|4*!!n;i=r?new iQ(r.type,r.attrs,ig.none,!0,t.topMatch||r.type.contentMatch,s):n?new iQ(null,null,ig.none,!0,null,s):new iQ(e.schema.topNodeType,null,ig.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;iX.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&&iX.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:iZ.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(iJ.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=ig.none;for(let i of r.concat(e.marks))(t.type?t.type.allowsMarkType(i.type):i2(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=iY(e,i,s.options);4&s.options&&0==s.content.length&&(o|=4);let a=ig.none;return n=n.filter(t=>(s.type?!s.type.allowsMarkType(t.type):!i2(t.type,e))||(a=t.addToSet(a),!1)),this.nodes.push(new iQ(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 i1(e){let t={};for(let n in e)t[n]=e[n];return t}function i2(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 i3{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=i4(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 i4(t).createTextNode(e.text);let{dom:n,contentDOM:r}=i9(i4(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&&i9(i4(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return"string"==typeof t?{dom:e.createTextNode(t)}:i9(e,t,n,r)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new i3(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=i5(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return i5(e.marks)}}function i5(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function i4(e){return e.document||window.document}let i6=new WeakMap;function i9(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=i6.get(r))&&i6.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}=i9(e,o,n,r);if(d.appendChild(t),s){if(i)throw RangeError("Multiple content holes");i=s}}}return{dom:d,contentDOM:i}}class i7{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 i8{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&i8.empty)return i8.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 i7(s,p,u)}r+=c-l}return n?e+r:new i7(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 i8(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return 0==e?i8.empty:new i8(e<0?[0,-e,0]:[0,0,e])}}i8.empty=new i8([]);class se{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 se(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 se;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 i7(e,r,null)}}let st=Object.create(null);class sn{getMap(){return i8.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw RangeError("Invalid input for Step.fromJSON");let n=st[t.stepType];if(!n)throw RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in st)throw RangeError("Duplicate use of step JSON ID "+e);return st[e]=t,t.prototype.jsonID=e,t}}class sr{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new sr(e,null)}static fail(e){return new sr(null,e)}static fromReplace(e,t,n,r){try{return sr.ok(e.replace(t,n,r))}catch(e){if(e instanceof ib)return sr.fail(e.message);throw e}}}function si(e,t,n){let r=[];for(let i=0;i<e.childCount;i++){let s=e.child(i);s.content.size&&(s=s.copy(si(s.content,t,s))),s.isInline&&(s=t(s,n,i)),r.push(s)}return iu.fromArray(r)}class ss extends sn{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(si(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 sr.fromReplace(e,this.from,this.to,i)}invert(){return new so(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 ss(t.pos,n.pos,this.mark)}merge(e){return e instanceof ss&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new ss(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 ss(t.from,t.to,e.markFromJSON(t.mark))}}sn.jsonID("addMark",ss);class so extends sn{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(si(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return sr.fromReplace(e,this.from,this.to,n)}invert(){return new ss(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 so(t.pos,n.pos,this.mark)}merge(e){return e instanceof so&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new so(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 so(t.from,t.to,e.markFromJSON(t.mark))}}sn.jsonID("removeMark",so);class sa extends sn{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return sr.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return sr.fromReplace(e,this.pos,this.pos+1,new ix(iu.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 sa(this.pos,t.marks[n]);return new sa(this.pos,this.mark)}}return new sl(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new sa(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 sa(t.pos,e.markFromJSON(t.mark))}}sn.jsonID("addNodeMark",sa);class sl extends sn{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return sr.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return sr.fromReplace(e,this.pos,this.pos+1,new ix(iu.from(n),0,+!t.isLeaf))}invert(e){let t=e.nodeAt(this.pos);return t&&this.mark.isInSet(t.marks)?new sa(this.pos,this.mark):this}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new sl(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 sl(t.pos,e.markFromJSON(t.mark))}}sn.jsonID("removeNodeMark",sl);class sc extends sn{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&su(e,this.from,this.to)?sr.fail("Structure replace would overwrite content"):sr.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new i8([this.from,this.to-this.from,this.slice.size])}invert(e){return new sc(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&&sc.MAP_BIAS<0?t:e.mapResult(this.from,1);return n.deletedAcross&&t.deletedAcross?null:new sc(n.pos,Math.max(n.pos,t.pos),this.slice,this.structure)}merge(e){if(!(e instanceof sc)||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 sc(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 sc(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 sc(t.from,t.to,ix.fromJSON(e,t.slice),!!t.structure)}}sc.MAP_BIAS=1,sn.jsonID("replace",sc);class sd extends sn{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&&(su(e,this.from,this.gapFrom)||su(e,this.gapTo,this.to)))return sr.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return sr.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?sr.fromReplace(e,this.from,this.to,n):sr.fail("Content does not fit in gap")}getMap(){return new i8([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 sd(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 sd(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 sd(t.from,t.to,t.gapFrom,t.gapTo,ix.fromJSON(e,t.slice),t.insert,!!t.structure)}}function su(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 sp(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 so(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(iu.from(n.schema.text(" ",n.allowedMarks(l.marks))),0,0)),o.push(new sc(a+e.index,a+e.index+e[0].length,r))}}else o.push(new sc(a,c,ix.empty));a=c}if(!r.validEnd){let t=r.fillBefore(iu.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 sh(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 sf(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(sm).concat({type:t,attrs:n}).concat(s.map(sm)):null}function sm(e){return{type:e,attrs:null}}function sg(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 sb(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 sv(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function sv(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 sw(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&&sv(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 sk(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 sN(e,t,n=t,r=ix.empty){if(t==n&&!r.size)return null;let i=e.resolve(t),s=e.resolve(n);return sS(i,s,r)?new sc(t,n,r):new sC(i,s,r).fit()}function sS(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}sn.jsonID("replaceAround",sd);class sC{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=iu.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=iu.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 sd(n.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||n.pos!=this.$to.pos?new sc(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=sM(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(iu.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=sM(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=sM(e,t);if(r.childCount<=1&&t>0){let i=e.size-t<=t+r.size;this.unplaced=new ix(sj(e,t-1,1),t-1,i?t-1:n)}else this.unplaced=new ix(sj(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(iu.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=sE(this.placed,t,iu.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(sj(s.content,e-1,1),e-1,p<0?s.openEnd:e-1):new ix(sj(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||!sA(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=sA(e,t,r,n,i);if(s){for(let n=t-1;n>=0;n--){let{match:t,type:r}=this.frontier[n],i=sA(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=sE(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=sE(this.placed,this.depth,iu.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(iu.empty,!0);e.childCount&&(this.placed=sE(this.placed,this.frontier.length,e))}}function sj(e,t,n){return 0==t?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(sj(e.firstChild.content,t-1,n)))}function sE(e,t,n){return 0==t?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(sE(e.lastChild.content,t-1,n)))}function sM(e,t){for(let n=0;n<t;n++)e=e.firstChild.content;return e}function sA(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 sT(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 sO extends sn{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 sr.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 sr.fromReplace(e,this.pos,this.pos+1,new ix(iu.from(r),0,+!t.isLeaf))}getMap(){return i8.empty}invert(e){return new sO(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 sO(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 sO(t.pos,t.attr,t.value)}}sn.jsonID("attr",sO);class s_ extends sn{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 sr.ok(n)}getMap(){return i8.empty}invert(e){return new s_(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 s_(t.attr,t.value)}}sn.jsonID("docAttr",s_);let sD=class extends Error{};(sD=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n}).prototype=Object.create(Error.prototype),sD.prototype.constructor=sD,sD.prototype.name="TransformError";class sR{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new se}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new sD(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=sN(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new ix(iu.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(sS(i,s,r))return e.step(new sc(t,n,r));let o=sT(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(iu.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(iu.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=sT(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=iu.empty,u=0;for(let e=s,t=!1;e>n;e--)t||r.index(e)>0?(t=!0,d=iu.from(r.node(e).copy(d)),u++):l--;let p=iu.empty,h=0;for(let e=s,t=!1;e>n;e--)t||i.after(e+1)<i.end(e)?(t=!0,p=iu.from(i.node(e).copy(p)),h++):c++;e.step(new sd(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);sb(e,r.node(),r.before(),a)}o.inlineContent&&sp(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 sc(c,l.map(t+n,-1),ix.empty,!0)),!0===r){let t=e.doc.resolve(c);sg(e,t.node(),t.before(),e.steps.length)}}(this,e,t),this}wrap(e,t){return!function(e,t,n){let r=iu.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=iu.from(n[e].type.create(n[e].attrs,r))}let i=t.start,s=t.end;e.step(new sd(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&&sb(i,e,t,s),sp(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 sd(a,l,a+1,l-1,new ix(iu.from(n.create(u,null,e.marks)),0,0),1,!0)),!0===r&&sg(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 sd(t,t+s.nodeSize,t+1,t+s.nodeSize-1,new ix(iu.from(o),0,0),1,!0))}(this,e,t,n,r),this}setNodeAttribute(e,t,n){return this.step(new sO(e,t,n)),this}setDocAttribute(e,t){return this.step(new s_(e,t)),this}addNodeMark(e,t){return this.step(new sa(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw RangeError("No node at position "+e);if(t instanceof ig)t.isInSet(n.marks)&&this.step(new sl(e,t));else{let r=n.marks,i,s=[];for(;i=t.isInSet(r);)s.push(new sl(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=iu.empty,o=iu.empty;for(let e=i.depth,t=i.depth-n,a=n-1;e>t;e--,a--){s=iu.from(i.node(e).copy(s));let t=r&&r[a];o=iu.from(t?t.type.create(t.attrs,o):i.node(e).copy(o))}e.step(new sc(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 so(c,u,d[e])));s&&s.to==c?s.to=u:a.push(s=new ss(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 iW){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 so(e.from,e.to,e.style))),this}clearIncompatible(e,t,n){return sp(this,e,t,n),this}}let sI=Object.create(null);class sL{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new sP(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&&sK(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),sK(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new sB(e):sq(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?sq(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):sq(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 sV(e.node(0))}static atStart(e){return sq(e,e,0,0,1)||new sV(e)}static atEnd(e){return sq(e,e,e.content.size,e.childCount,-1)||new sV(e)}static fromJSON(e,t){if(!t||!t.type)throw RangeError("Invalid input for Selection.fromJSON");let n=sI[t.type];if(!n)throw RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in sI)throw RangeError("Duplicate use of selection JSON ID "+e);return sI[e]=t,t.prototype.jsonID=e,t}getBookmark(){return sB.between(this.$anchor,this.$head).getBookmark()}}sL.prototype.visible=!0;class sP{constructor(e,t){this.$from=e,this.$to=t}}let sz=!1;function s$(e){sz||e.parent.inlineContent||(sz=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class sB extends sL{constructor(e,t=e){s$(e),s$(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 sL.near(n);let r=e.resolve(t.map(this.anchor));return new sB(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 sB&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new sF(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 sB(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=sL.findFrom(t,n,!0)||sL.findFrom(t,-n,!0);if(!e)return sL.near(t,n);t=e.$head}return e.parent.inlineContent||(0==r?e=t:(e=(sL.findFrom(e,-n,!0)||sL.findFrom(e,n,!0)).$anchor).pos<t.pos!=r<0&&(e=t)),new sB(e,t)}}sL.jsonID("text",sB);class sF{constructor(e,t){this.anchor=e,this.head=t}map(e){return new sF(e.map(this.anchor),e.map(this.head))}resolve(e){return sB.between(e.resolve(this.anchor),e.resolve(this.head))}}class sH extends sL{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?sL.near(i):new sH(i)}content(){return new ix(iu.from(this.node),0,0)}eq(e){return e instanceof sH&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new sU(this.anchor)}static fromJSON(e,t){if("number"!=typeof t.anchor)throw RangeError("Invalid input for NodeSelection.fromJSON");return new sH(e.resolve(t.anchor))}static create(e,t){return new sH(e.resolve(t))}static isSelectable(e){return!e.isText&&!1!==e.type.spec.selectable}}sH.prototype.visible=!1,sL.jsonID("node",sH);class sU{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new sF(n,n):new sU(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&sH.isSelectable(n)?new sH(t):sL.near(t)}}class sV extends sL{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=sL.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new sV(e)}map(e){return new sV(e)}eq(e){return e instanceof sV}getBookmark(){return sW}}sL.jsonID("all",sV);let sW={map(){return this},resolve:e=>new sV(e)};function sq(e,t,n,r,i,s=!1){if(t.inlineContent)return sB.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&&sH.isSelectable(r))return sH.create(e,n-(i<0?r.nodeSize:0))}else{let t=sq(e,r,n+i,i<0?r.childCount:0,i,s);if(t)return t}n+=r.nodeSize*i}return null}function sK(e,t,n){let r,i=e.steps.length-1;if(i<t)return;let s=e.steps[i];(s instanceof sc||s instanceof sd)&&(e.mapping.maps[i].forEach((e,t,n,i)=>{null==r&&(r=i)}),e.setSelection(sL.near(e.doc.resolve(r),n)))}class sG extends sR{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 ig.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)||ig.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(sL.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 sJ(e,t){return t&&e?e.bind(t):e}class sZ{constructor(e,t,n){this.name=e,this.init=sJ(t.init,n),this.apply=sJ(t.apply,n)}}let sX=[new sZ("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new sZ("selection",{init:(e,t)=>e.selection||sL.atStart(t.doc),apply:e=>e.selection}),new sZ("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,r)=>r.selection.$cursor?e.storedMarks:null}),new sZ("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t})];class sY{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=sX.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 sZ(e.key,e.spec.state,e))})}}class sQ{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 sQ(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 sG(this)}static create(e){let t=new sY(e.doc?e.doc.type.schema:e.schema,e.plugins),n=new sQ(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 sY(this.schema,e.plugins),n=t.fields,r=new sQ(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 sY(e.schema,e.plugins),i=new sQ(r);return r.fields.forEach(r=>{if("doc"==r.name)i.doc=iO.fromJSON(e.schema,t.doc);else if("selection"==r.name)i.selection=sL.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 s0{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:s2("plugin")}getState(e){return e[this.key]}}let s1=Object.create(null);function s2(e){return e in s1?e+"$"+ ++s1[e]:(s1[e]=0,e+"$")}class s3{constructor(e="key"){this.key=s2(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}let s5=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},s4=function(e){let t=e.assignedSlot||e.parentNode;return t&&11==t.nodeType?t.host:t},s6=null,s9=function(e,t,n){let r=s6||(s6=document.createRange());return r.setEnd(e,null==n?e.nodeValue.length:n),r.setStart(e,t||0),r},s7=function(){s6=null},s8=function(e,t,n,r){return n&&(ot(e,t,n,r,-1)||ot(e,t,n,r,1))},oe=/^(img|br|input|textarea|hr)$/i;function ot(e,t,n,r,i){for(var s;;){if(e==n&&t==r)return!0;if(t==(i<0?0:on(e))){let n=e.parentNode;if(!n||1!=n.nodeType||or(e)||oe.test(e.nodeName)||"false"==e.contentEditable)return!1;t=s5(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?on(e):0}}}function on(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function or(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 oi=function(e){return e.focusNode&&s8(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function oo(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}let oa="u">typeof navigator?navigator:null,ol="u">typeof document?document:null,oc=oa&&oa.userAgent||"",od=/Edge\/(\d+)/.exec(oc),ou=/MSIE \d/.exec(oc),op=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(oc),oh=!!(ou||op||od),of=ou?document.documentMode:op?+op[1]:od?+od[1]:0,om=!oh&&/gecko\/(\d+)/i.test(oc);om&&(/Firefox\/(\d+)/.exec(oc)||[0,0])[1];let og=!oh&&/Chrome\/(\d+)/.exec(oc),ob=!!og,ox=og?+og[1]:0,oy=!oh&&!!oa&&/Apple Computer/.test(oa.vendor),ov=oy&&(/Mobile\/\w+/.test(oc)||!!oa&&oa.maxTouchPoints>2),ow=ov||!!oa&&/Mac/.test(oa.platform),ok=!!oa&&/Win/.test(oa.platform),oN=/Android \d/.test(oc),oS=!!ol&&"webkitFontSmoothing"in ol.documentElement.style,oC=oS?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function oj(e,t){return"number"==typeof e?e:e[t]}function oE(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=s4(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+oj(r,"top")?c=-(a.top-t.top+oj(i,"top")):t.bottom>a.bottom-oj(r,"bottom")&&(c=t.bottom-t.top>a.bottom-a.top?t.top+oj(i,"top")-a.top:t.bottom-a.bottom+oj(i,"bottom")),t.left<a.left+oj(r,"left")?l=-(a.left-t.left+oj(i,"left")):t.right>a.right-oj(r,"right")&&(l=t.right-a.right+oj(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:s4(o)}}function oM(e){let t=[],n=e.ownerDocument;for(let r=e;r&&(t.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),e!=n);r=s4(r));return t}function oA(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 oT=null;function oO(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function o_(e){return e.top<e.bottom||e.left<e.right}function oD(e,t){let n=e.getClientRects();if(n.length){let e=n[t<0?0:n.length-1];if(o_(e))return e}return Array.prototype.find.call(n,o_)||e.getBoundingClientRect()}let oR=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function oI(e,t,n){let{node:r,offset:i,atom:s}=e.docView.domFromPos(t,n<0?-1:1),o=oS||om;if(3==r.nodeType)if(o&&(oR.test(r.nodeValue)||(n<0?!i:i==r.nodeValue.length))){let e=oD(s9(r,i,i),n);if(om&&i&&/\s/.test(r.nodeValue[i-1])&&i<r.nodeValue.length){let t=oD(s9(r,i-1,i-1),-1);if(t.top==e.top){let n=oD(s9(r,i,i+1),-1);if(n.top!=e.top)return oL(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++,oL(oD(s9(r,e,t),s),s<0)}if(!e.state.doc.resolve(t-(s||0)).parent.inlineContent){if(null==s&&i&&(n<0||i==on(r))){let e=r.childNodes[i-1];if(1==e.nodeType)return oP(e.getBoundingClientRect(),!1)}if(null==s&&i<on(r)){let e=r.childNodes[i];if(1==e.nodeType)return oP(e.getBoundingClientRect(),!0)}return oP(r.getBoundingClientRect(),n>=0)}if(null==s&&i&&(n<0||i==on(r))){let e=r.childNodes[i-1],t=3==e.nodeType?s9(e,on(e)-!o):1!=e.nodeType||"BR"==e.nodeName&&e.nextSibling?null:e;if(t)return oL(oD(t,1),!1)}if(null==s&&i<on(r)){let e=r.childNodes[i];for(;e.pmViewDesc&&e.pmViewDesc.ignoreForCoords;)e=e.nextSibling;let t=e?3==e.nodeType?s9(e,0,+!o):1==e.nodeType?e:null:null;if(t)return oL(oD(t,-1),!0)}return oL(oD(3==r.nodeType?s9(r):r,-n),n>=0)}function oL(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 oP(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 oz(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 o$=/[\u0590-\u08ac]/,oB=null,oF=null,oH=!1;class oU{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>s5(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 oZ){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 oV&&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?s5(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?s5(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=s5(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=s5(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((om||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:s5(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(om&&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)&&s8(o.node,o.offset,c.anchorNode,c.anchorOffset)&&s8(a.node,a.offset,c.focusNode,c.focusOffset))return;let u=!1;if((l.extend||e==t)&&!(d&&om)){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 oV extends oU{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 oW extends oU{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 oq extends oU{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=i3.renderSpec(document,t.type.spec.toDOM(t,n),null,t.attrs)),new oq(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=oq.create(this.parent,this.mark,!0,n),i=this.children,s=this.size;t<s&&(i=o9(i,t,s,n)),e>0&&(i=o9(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 oK extends oU{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=i3.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=o2(c,n,t),l)?a=new oX(e,t,n,r,c,d||null,u,l,i,s+1):t.isText?new oJ(e,t,n,r,c,u,i):new oK(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=()=>iu.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)&&o3(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 o4(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(o6);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 f=s+p.nodeSize;if(p.isText){let e=f;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<f&&(l=p.cut(e-s),p=p.cut(0,e-s),f=e,h=-1)}else for(;o<i.length&&i[o].to<f;)o++;let m=p.isInline&&!p.isLeaf?a.filter(e=>!e.inline):a.slice();r(p,m,t.forChild(s,p),h),s=f}})(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?ig.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=o5(i),s=!0;i=i.nextSibling}else s=!0,t.insertBefore(l,i);if(a instanceof oq){let n=i?i.previousSibling:t.lastChild;e(a.contentDOM,a.children,r),i=n?n.nextSibling:t.firstChild}}for(;i;)i=o5(i),s=!0;s&&r.trackWrites==t&&(r.trackWrites=null)}(this.contentDOM,this.children,e),ov&&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 sB)||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 oW(this,i,t,r);e.input.compositionNodes.push(s),this.children=o9(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(o3(e,this.outerDeco))return;let t=1!=this.nodeDOM.nodeType,n=this.dom;this.dom=o1(this.dom,this.nodeDOM,o0(this.outerDeco,this.node,t),o0(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 oG(e,t,n,r,i){o2(r,t,e);let s=new oK(void 0,e,t,n,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}class oJ extends oK{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 oJ(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 oZ extends oU{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 oX extends oK{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 oY=function(e){e&&(this.nodeName=e)};oY.prototype=Object.create(null);let oQ=[new oY];function o0(e,t,n){if(0==e.length)return oQ;let r=n?oQ[0]:new oY,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 oY(o.nodeName)),o){let s=o[e];null!=s&&(n&&1==i.length&&i.push(r=new oY(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 o1(e,t,n,r){if(n==oQ&&r==oQ)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=oQ[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||oQ[0],s)}return i}function o2(e,t,n){return o1(e,e,oQ,o0(t,n,1!=e.nodeType))}function o3(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 o5(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}class o4{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 oq)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=oq.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 oK){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&&o3(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)||!o3(n,e.outerDeco)||!r.eq(e.innerDeco))return null;let o=oK.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=oK.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 oV(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 oq;)e=(t=e).children[t.children.length-1];(!e||!(e instanceof oJ)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((oy||ob)&&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 oZ(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 o6(e,t){return e.type.side-t.type.side}function o9(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 o7(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(oi(n)){for(l=o;i&&!i.node;)i=i.parent;let e=i.node;if(i&&e.isAtom&&sH.isSelectable(e)&&i.parent&&!(e.isInline&&function(e,t,n){for(let r=0==t,i=t==on(e);r||i;){if(e==n)return!0;let t=s5(e);if(!(e=e.parentNode))return!1;r=r&&0==t,i=i&&t==on(e)}}(n.focusNode,n.focusOffset,i.dom))){let e=i.posBefore;c=new sH(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=aa(e,d,a,n)}return c}function o8(e){return e.editable?e.hasFocus():ac(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function ae(e,t=!1){let n=e.state.selection;if(as(e,n),o8(e)){if(!t&&e.input.mouseDown&&e.input.mouseDown.allowDefault&&ob){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&s8(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,s5(n)+1):t.collapse(n,0),!r&&!e.state.selection.visible&&oh&&of<=11&&(n.disabled=!0,n.disabled=!1)}(e);else{var r;let i,s,o,a,{anchor:l,head:c}=n,d,u;at&&!(n instanceof sB)&&(n.$from.parent.inlineContent||(d=an(e,n.from)),n.empty||n.$from.parent.inlineContent||(u=an(e,n.to))),e.docView.setSelection(l,c,e,t),at&&(d&&ai(d),u&&ai(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(()=>{(!o8(r)||r.state.selection.visible)&&r.dom.classList.remove("ProseMirror-hideselection")},20))})))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}let at=oy||ob&&ox<63;function an(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 ar(i);if((!i||"false"==i.contentEditable)&&(!s||"false"==s.contentEditable)){if(i)return ar(i);else if(s)return ar(s)}}function ar(e){return e.contentEditable="true",oy&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function ai(e){e.contentEditable="false",e.wasDraggable&&(e.draggable=!0,e.wasDraggable=null)}function as(e,t){if(t instanceof sH){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(ao(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else ao(e)}function ao(e){e.lastSelectedViewDesc&&(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),e.lastSelectedViewDesc=void 0)}function aa(e,t,n,r){return e.someProp("createSelectionBetween",r=>r(e,t,n))||sB.between(t,n,r)}function al(e){return(!e.editable||!!e.hasFocus())&&ac(e)}function ac(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 ad(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&&sL.findFrom(s,t)}function au(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function ap(e,t,n){let r=e.state.selection;if(r instanceof sB){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 au(e,new sB(r.$anchor,s))}else if(!r.empty)return!1;else if(e.endOfTextblock(t>0?"forward":"backward")){let n=ad(e.state,t);return!!n&&n instanceof sH&&au(e,n)}else if(!(ow&&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)&&(sH.isSelectable(i)?au(e,new sH(t<0?e.state.doc.resolve(n.pos-i.nodeSize):n)):!!oS&&au(e,new sB(e.state.doc.resolve(t<0?o:o+i.nodeSize))))}}else{if(r instanceof sH&&r.node.isInline)return au(e,new sB(t>0?r.$to:r.$from));let n=ad(e.state,t);return!!n&&au(e,n)}}function ah(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function af(e,t){let n=e.pmViewDesc;return n&&0==n.size&&(t<0||e.nextSibling||"BR"!=e.nodeName)}function am(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(om&&1==n.nodeType&&r<ah(n)&&af(n.childNodes[r],-1)&&(o=!0);;)if(r>0)if(1!=n.nodeType)break;else{let e=n.childNodes[r-1];if(af(e,-1))i=n,s=--r;else if(3==e.nodeType)r=(n=e).nodeValue.length;else break}else if(ag(n))break;else{let t=n.previousSibling;for(;t&&af(t,-1);)i=n.parentNode,s=s5(t),t=t.previousSibling;if(t)r=ah(n=t);else{if((n=n.parentNode)==e.dom)break;r=0}}o?ab(e,n,r):i&&ab(e,i,s)}(e):function(e){let t,n,r=e.domSelectionRange(),i=r.focusNode,s=r.focusOffset;if(!i)return;let o=ah(i);for(;;)if(s<o){if(1!=i.nodeType)break;if(af(i.childNodes[s],1))t=i,n=++s;else break}else if(ag(i))break;else{let r=i.nextSibling;for(;r&&af(r,1);)t=r.parentNode,n=s5(r)+1,r=r.nextSibling;if(r)s=0,o=ah(i=r);else{if((i=i.parentNode)==e.dom)break;s=o=0}}t&&ab(e,t,n)}(e)}function ag(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function ab(e,t,n){if(3!=t.nodeType){let e,r;(r=function(e,t){for(;e&&t==e.childNodes.length&&!or(e);)t=s5(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&&!or(e);)t=s5(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(oi(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&&ae(e)},50)}function ax(e,t){let n=e.state.doc.resolve(t);if(!(ob||ok)&&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 sB&&!r.empty||n.indexOf("s")>-1||ow&&n.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||e.endOfTextblock(t<0?"up":"down")){let n=ad(e.state,t);if(n&&n instanceof sH)return au(e,n)}if(!i.parent.inlineContent){let n=t<0?i:s,o=r instanceof sV?sL.near(n,t):sL.findFrom(n,t);return!!o&&au(e,o)}return!1}function av(e,t){if(!(e.state.selection instanceof sB))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 aw(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function ak(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")||i3.fromSchema(e.state.schema),a=aT(),l=a.createElement("div");l.appendChild(o.serializeFragment(r,{document:a}));let c=l.firstChild,d,u=0;for(;c&&1==c.nodeType&&(d=aM[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 aN(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(iu.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=i3.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=aT().createElement("div"),s=/<([a-z][^>\s]+)/i.exec(e),o;if((o=s&&aM[s[1].toLowerCase()])&&(e=o.map(e=>"<"+e+">").join("")+e+o.map(e=>"</"+e+">").reverse().join("")),i.innerHTML=(t=e,(n=window.trustedTypes)?(aO||(aO=n.defaultPolicy||n.createPolicy("ProseMirrorClipboard",{createHTML:e=>e})),aO.createHTML(t)):t),o)for(let e=0;e<o.length;e++)i=i.querySelector(o[e])||i;return i}(n),oS&&function(e){let t=e.querySelectorAll(ob?"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")||iG.fromSchema(e.state.schema)).parseSlice(s,{preserveWhitespace:!!(l||d),context:i,ruleFromNode:e=>"BR"!=e.nodeName||e.nextSibling||!e.parentNode||aS.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=iu.from(t.create(r[e+1],i)),s++,o++}return new ix(i,s,o)}(aE(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(iu.from(aC(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(iu.empty,!0);return t.copy(r.append(i))}(s[s.length-1],i.length));let n=aC(e,t);s.push(n),r=r.matchType(n.type),i=t}}),s)return iu.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=aE(o,e,t)}return e.someProp("transformPasted",t=>{o=t(o,e,l)}),o}let aS=/^(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 aC(e,t,n=0){for(let r=t.length-1;r>=n;r--)e=t[r].create(null,iu.from(e));return e}function aj(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=aj(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(iu.empty,!0))),e.replaceChild(t<0?0:e.childCount-1,o.copy(a))}function aE(e,t,n){return t<e.openStart&&(e=new ix(aj(e.content,-1,t,e.openStart,0,e.openEnd),t,e.openEnd)),n<e.openEnd&&(e=new ix(aj(e.content,1,n,e.openEnd,0,0),e.openStart,n)),e}let aM={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]},aA=null;function aT(){return aA||(aA=document.implementation.createHTMLDocument("title"))}let aO=null,a_={},aD={},aR={touchstart:!0,touchmove:!0};class aI{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 aL(e,t){e.input.lastSelectionOrigin=t,e.input.lastSelectionTime=Date.now()}function aP(e){e.someProp("handleDOMEvents",t=>{for(let n in t)e.input.eventHandlers[n]||e.dom.addEventListener(n,e.input.eventHandlers[n]=t=>az(e,t))})}function az(e,t){return e.someProp("handleDOMEvents",n=>{let r=n[t.type];return!!r&&(r(e,t)||t.defaultPrevented)})}function a$(e){return{left:e.clientX,top:e.clientY}}function aB(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 aF(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)}aD.keydown=(e,t)=>{if((e.input.shiftKey=16==t.keyCode||t.shiftKey,!aV(e,t))&&(e.input.lastKeyCode=t.keyCode,e.input.lastKeyCodeTime=Date.now(),!oN||!ob||13!=t.keyCode))if(229!=t.keyCode&&e.domObserver.forceFlush(),!ov||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||ow&&72==r&&"c"==i)return av(e,-1)||am(e,-1);if(46==r&&!t.shiftKey||ow&&68==r&&"c"==i)return av(e,1)||am(e,1);if(13==r||27==r)return!0;if(37==r||ow&&66==r&&"c"==i){let t=37==r?"ltr"==ax(e,e.state.selection.from)?-1:1:-1;return ap(e,t,i)||am(e,t)}if(39==r||ow&&70==r&&"c"==i){let t=39==r?"ltr"==ax(e,e.state.selection.from)?1:-1:1;return ap(e,t,i)||am(e,t)}else if(38==r||ow&&80==r&&"c"==i)return ay(e,-1,i)||am(e,-1);else if(40==r||ow&&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;aw(e,n,"true"),setTimeout(()=>aw(e,n,"false"),20)}return!1}(e)||ay(e,1,i)||am(e,1);else if(i==(ow?"m":"c")&&(66==r||73==r||89==r||90==r))return!0;return!1}(e,t)?t.preventDefault():aL(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,oo(13,"Enter"))),e.input.lastIOSEnter=0)},200)}},aD.keyup=(e,t)=>{16==t.keyCode&&(e.input.shiftKey=!1)},aD.keypress=(e,t)=>{if(aV(e,t)||!t.charCode||t.ctrlKey&&!t.altKey||ow&&t.metaKey)return;if(e.someProp("handleKeyPress",n=>n(e,t)))return void t.preventDefault();let n=e.state.selection;if(!(n instanceof sB)||!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 aH=ow?"metaKey":"ctrlKey";a_.mousedown=(e,t)=>{var n;let r,i;e.input.shiftKey=t.shiftKey;let s=aG(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[aH]&&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(a$(t));l&&("singleClick"==a?(e.input.mouseDown&&e.input.mouseDown.done(),e.input.mouseDown=new aU(e,l,t,!!s)):("doubleClick"==a?function(e,t,n,r){return aB(e,"handleDoubleClickOn",t,n,r)||e.someProp("handleDoubleClick",n=>n(e,t,r))}:function(e,t,n,r){return aB(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&&(aF(e,sB.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)aF(e,sB.create(r,s+1,s+1+n.content.size),"pointer");else{if(!sH.isSelectable(n))continue;aF(e,sH.create(r,s),"pointer")}return!0}}(e,n,r)})(e,l.pos,l.inside,t)?t.preventDefault():aL(e,"pointer"))};class aU{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[aH],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 sH&&l.from<=s&&l.to>s)&&(this.mightDrag={node:i,pos:s,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&om&&!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)),aL(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(()=>ae(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(a$(e))),this.updateAllowDefault(e),this.allowDefault||!t)aL(this.view,"pointer");else{var n,r,i,s;(n=this.view,r=t.pos,i=t.inside,s=this.selectNode,aB(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 sH&&(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(sH.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&&(aF(e,sH.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&&sH.isSelectable(r))&&(aF(e,new sH(n),"pointer"),!0)}(n,i)))?e.preventDefault():0==e.button&&(this.flushed||oy&&this.mightDrag&&!this.mightDrag.node.isAtom||ob&&!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)))?(aF(this.view,sL.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):aL(this.view,"pointer")}}move(e){this.updateAllowDefault(e),aL(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 aV(e,t){return!!e.composing||!!(oy&&500>Math.abs(t.timeStamp-e.input.compositionEndedAt))&&(e.input.compositionEndedAt=-2e8,!0)}a_.touchstart=e=>{e.input.lastTouch=Date.now(),aG(e),aL(e,"pointer")},a_.touchmove=e=>{e.input.lastTouch=Date.now(),aL(e,"pointer")},a_.contextmenu=e=>aG(e);let aW=oN?5e3:-1;function aq(e,t){clearTimeout(e.input.composingTimeout),t>-1&&(e.input.composingTimeout=setTimeout(()=>aG(e),t))}function aK(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 aG(e,t=!1){if(!oN||!(e.domObserver.flushingSoon>=0)){if(e.domObserver.forceFlush(),aK(e),t||e.docView&&e.docView.dirty){let n=o7(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}}aD.compositionstart=aD.compositionupdate=e=>{if(!e.composing){e.domObserver.flush();let{state:t}=e,n=t.selection.$to;if(t.selection instanceof sB&&(t.storedMarks||!n.textOffset&&n.parentOffset&&n.nodeBefore.marks.some(e=>!1===e.type.spec.inclusive)||ob&&ok&&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(),aG(e,!0),e.markCursor=null;else if(aG(e,!t.selection.empty),om&&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}aq(e,aW)},aD.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++,aq(e,20))};let aJ=oh&&of<15||ov&&oC<604;function aZ(e,t,n,r,i){let s=aN(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 aX(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," "):""}a_.copy=aD.cut=(e,t)=>{let n=e.state.selection,r="cut"==t.type;if(n.empty)return;let i=aJ?null:t.clipboardData,{dom:s,text:o}=ak(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"))},aD.paste=(e,t)=>{if(e.composing&&!oN)return;let n=aJ?null:t.clipboardData,r=e.input.shiftKey&&45!=e.input.lastKeyCode;n&&aZ(e,aX(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?aZ(e,r.value,null,i,t):aZ(e,r.textContent,r.innerHTML,i,t)},50)}(e,t)};class aY{constructor(e,t,n){this.slice=e,this.move=t,this.node=n}}let aQ=ow?"altKey":"ctrlKey";function a0(e,t){let n;return e.someProp("dragCopies",e=>{n=n||e(t)}),null!=n?!n:!t[aQ]}for(let e in a_.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(a$(t));if(s&&s.pos>=i.from&&s.pos<=(i instanceof sH?i.to-1:i.to));else if(r&&r.mightDrag)n=sH.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=sH.create(e.state.doc,r.posBefore))}let o=(n||e.state.selection).content(),{dom:a,text:l,slice:c}=ak(e,o);t.dataTransfer.files.length&&ob&&!(ox>120)||t.dataTransfer.clearData(),t.dataTransfer.setData(aJ?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",aJ||t.dataTransfer.setData("text/plain",l),e.dragging=new aY(c,a0(e,t),n)},a_.dragend=e=>{let t=e.dragging;window.setTimeout(()=>{e.dragging==t&&(e.dragging=null)},50)},aD.dragover=aD.dragenter=(e,t)=>t.preventDefault(),aD.drop=(e,t)=>{try{!function(e,t,n){if(!t.dataTransfer)return;let r=e.posAtCoords(a$(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=aN(e,aX(t.dataTransfer),aJ?null:t.dataTransfer.getData("text/html"),!1,i);let o=!!(n&&a0(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?sk(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&&sH.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))l.setSelection(new sH(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(aa(e,p,l.doc.resolve(t)))}e.focus(),e.dispatch(l.setMeta("uiEvent","drop"))}(e,t,e.dragging)}finally{e.dragging=null}},a_.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())&&ae(e)},20))},a_.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)},a_.beforeinput=(e,t)=>{if(ob&&oN&&"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,oo(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)}},aD)a_[e]=aD[e];function a1(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 a2{constructor(e,t){this.toDOM=e,this.spec=t||a9,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 a4(i-n,i-n,this)}valid(){return!0}eq(e){return this==e||e instanceof a2&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&a1(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class a3{constructor(e,t){this.attrs=e,this.spec=t||a9}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 a4(i,s,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof a3&&a1(this.attrs,e.attrs)&&a1(this.spec,e.spec)}static is(e){return e.type instanceof a3}destroy(){}}class a5{constructor(e,t){this.attrs=e,this.spec=t||a9}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 a4(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 a5&&a1(this.attrs,e.attrs)&&a1(this.spec,e.spec)}destroy(){}}class a4{constructor(e,t,n){this.from=e,this.to=t,this.type=n}copy(e,t){return new a4(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 a4(e,e,new a2(t,n))}static inline(e,t,n,r){return new a4(e,t,new a3(n,r))}static node(e,t,n,r){return new a4(e,t,new a5(n,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof a3}get widget(){return this.type instanceof a2}}let a6=[],a9={};class a7{constructor(e,t){this.local=e.length?e:a6,this.children=t.length?t:a6}static create(e,t){return t.length?li(t,e,0,a9):a8}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==a8||0==e.maps.length?this:this.mapInner(e,t,0,0,n||a9)}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),f=r.maybeChild(p);if(f&&h==d&&h+f.nodeSize==u){let r=a[t+2].mapInner(n,f,c+1,e[t]+s+1,o);r!=a8?(a[t]=d,a[t+1]=u,a[t+2]=r):(a[t+1]=-2,l=!0)}else l=!0}if(l){let l=li(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 a7(t.sort(ls),a)}(this.children,s||[],e,t,n,r,i):s?new a7(s.sort(ls),a6):a8}add(e,t){return t.length?this==a8?a7.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=ln(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,li(a,e,o+1,a9)),i+=3}});let s=lt(i?lr(t):t,-n);for(let t=0;t<s.length;t++)s[t].type.valid(e,s[t])||s.splice(t--,1);return new a7(s.length?this.local.concat(s).sort(ls):this.local,r||this.children)}remove(e){return 0==e.length||this==a8?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!=a8?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 a7(r,n):a8}forChild(e,t){let n,r;if(this==a8)return this;if(t.isLeaf)return a7.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 a3){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 a7(r.sort(ls),a6);return n?new le([e,n]):e}return n||a8}eq(e){if(this==e)return!0;if(!(e instanceof a7)||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 lo(this.localsInner(e))}localsInner(e){if(this==a8)return a6;if(e.inlineContent||!this.local.some(a3.is))return this.local;let t=[];for(let e=0;e<this.local.length;e++)this.local[e].type instanceof a3||t.push(this.local[e]);return t}forEachSet(e){e(this)}}a7.empty=new a7([],[]),a7.removeOverlap=lo;let a8=a7.empty;class le{constructor(e){this.members=e}map(e,t){let n=this.members.map(n=>n.map(e,t,a9));return le.from(n)}forChild(e,t){if(t.isLeaf)return a7.empty;let n=[];for(let r=0;r<this.members.length;r++){let i=this.members[r].forChild(e,t);i!=a8&&(i instanceof le?n=n.concat(i.members):n.push(i))}return le.from(n)}eq(e){if(!(e instanceof le)||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?lo(n?t:t.sort(ls)):a6}static from(e){switch(e.length){case 0:return a8;case 1:return e[0];default:return new le(e.every(e=>e instanceof a7)?e:e.reduce((e,t)=>e.concat(t instanceof a7?t:t.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function lt(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 a4(i.from+t,i.to+t,i.type))}return n}function ln(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 lr(e){let t=[];for(let n=0;n<e.length;n++)null!=e[n]&&t.push(e[n]);return t}function li(e,t,n,r){let i=[],s=!1;t.forEach((t,o)=>{let a=ln(e,t,o+n);if(a){s=!0;let e=li(a,t,n+o+1,r);e!=a8&&i.push(o,o+t.nodeSize,e)}});let o=lt(s?lr(e):e,-n).sort(ls);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 a7(o,i):a8}function ls(e,t){return e.from-t.from||e.to-t.to}function lo(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),la(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),la(t,i,r.copy(s.from,r.to)));break}}return t}function la(e,t,n){for(;t<e.length&&ls(n,e[t])>0;)t++;e.splice(t,0,n)}function ll(e){let t=[];return e.someProp("decorations",n=>{let r=n(e.state);r&&r!=a8&&t.push(r)}),e.cursorWrapper&&t.push(a7.create(e.state.doc,[e.cursorWrapper.deco])),le.from(t)}let lc={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},ld=oh&&of<=11;class lu{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 lp{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new lu,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]);oh&&of<=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()}),ld&&(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,lc)),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(al(this.view)){if(this.suppressingSelectionUpdates)return ae(this.view);if(oh&&of<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&s8(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=s4(n))t.add(n);for(let r=e.anchorNode;r;r=s4(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)&&al(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(om&&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&&oi(r)&&(c=o7(t))&&c.eq(sL.near(t.state.doc.resolve(0),1))?(t.input.lastFocus=0,ae(t),this.currentSelection.set(r),t.scrollToSelection()):(s>-1||i)&&(s>-1&&(t.docView.markDirty(s,o),e=t,!lh.has(e)&&(lh.set(e,null),-1!==["normal","nowrap","pre-line"].indexOf(getComputedStyle(e.dom).whiteSpace))&&(e.requiresGeckoHackNode=om,lf||(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."),lf=!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)||ae(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(oh&&of<=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?s5(r)+1:0,o=n.localPosFromDOM(e.target,s,-1),a=i&&i.parentNode==e.target?s5(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 lh=new WeakMap,lf=!1;function lm(e,t){let n=t.startContainer,r=t.startOffset,i=t.endContainer,s=t.endOffset,o=e.domAtPos(e.state.selection.anchor);return s8(o.node,o.offset,i,s)&&([n,r,i,s]=[i,s,n,r]),{anchorNode:n,anchorOffset:r,focusNode:i,focusOffset:s}}function lg(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 lb=/^(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:aa(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 lv(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 lw{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 aI,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(lj),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=lS(this),lN(this),this.nodeViews=lC(this),this.docView=oG(this.state.doc,lk(this),ll(this),this.dom,this),this.domObserver=new lp(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=o7(e,t);if(n&&!e.state.selection.eq(n)){if(ob&&oN&&13===e.input.lastKeyCode&&Date.now()-100<e.input.lastKeyCodeTime&&e.someProp("handleKeyDown",t=>t(e,oo(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}],oi(c)||r.push({node:c.focusNode,offset:c.focusOffset})),ob&&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")||iG.fromSchema(e.state.schema),h=u.resolve(a),f=null,m=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:lg,context:h});if(r&&null!=r[0].pos){let e=r[0].pos,t=r[1]&&r[1].pos;null==t&&(t=e),f={anchor:e+a,head:t+a}}return{doc:m,sel:f,from:a,to:l}}(e,t,n),h=e.state.doc,f=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 m=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&&lv(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&&lv(e.textBetween(s-1,s+1))&&(s+=t?1:-1),o=s+(o-a),a=s}return{start:s,endA:o,endB:a}}(f.content,p.doc.content,p.from,s,o);if(m&&e.input.domChangeCount++,(ov&&e.input.lastIOSEnter>Date.now()-225||oN)&&i.some(e=>1==e.nodeType&&!lb.test(e.nodeName))&&(!m||m.endA>=m.endB)&&e.someProp("handleKeyDown",t=>t(e,oo(13,"Enter")))){e.input.lastIOSEnter=0;return}if(!m)if(r&&u instanceof sB&&!u.empty&&u.$head.sameParent(u.$anchor)&&!e.composing&&!(p.sel&&p.sel.anchor!=p.sel.head))m={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&&m.start==m.endB&&e.state.selection instanceof sB&&(m.start>e.state.selection.from&&m.start<=e.state.selection.from+2&&e.state.selection.from>=p.from?m.start=e.state.selection.from:m.endA<e.state.selection.to&&m.endA>=e.state.selection.to-2&&e.state.selection.to<=p.to&&(m.endB+=e.state.selection.to-m.endA,m.endA=e.state.selection.to)),oh&&of<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>p.from&&"  "==p.doc.textBetween(m.start-p.from-1,m.start-p.from+1)&&(m.start--,m.endA--,m.endB--);let g=p.doc.resolveNoCache(m.start-p.from),b=p.doc.resolveNoCache(m.endB-p.from),x=h.resolve(m.start),y=g.sameParent(b)&&g.parent.inlineContent&&x.end()>=m.endA;if((ov&&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(b)||!g.parent.inlineContent)&&g.pos<b.pos&&!/\S/.test(p.doc.textBetween(g.pos,b.pos,"","")))&&e.someProp("handleKeyDown",t=>t(e,oo(13,"Enter")))){e.input.lastIOSEnter=0;return}if(e.state.selection.anchor>m.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,m.start,m.endA,g,b)&&e.someProp("handleKeyDown",t=>t(e,oo(8,"Backspace")))){oN&&ob&&e.domObserver.suppressSelectionUpdates();return}ob&&m.endB==m.start&&(e.input.lastChromeDelete=Date.now()),oN&&!y&&g.start()!=b.start()&&0==b.parentOffset&&g.depth==b.depth&&p.sel&&p.sel.anchor==p.sel.head&&p.sel.head==m.endA&&(m.endB-=2,b=p.doc.resolveNoCache(m.endB-p.from),setTimeout(()=>{e.someProp("handleKeyDown",function(t){return t(e,oo(13,"Enter"))})},20));let v=m.start,w=m.endA,k=t=>{let n=t||e.state.tr.replace(v,w,p.doc.slice(m.start-p.from,m.endB-p.from));if(p.sel){let t=lx(e,n.doc,p.sel);t&&!(ob&&e.composing&&t.empty&&(m.start!=m.endB||e.input.lastChromeDelete<Date.now()-100)&&(t.head==v||t.head==n.mapping.map(w)-1)||oh&&t.empty&&t.head==v)&&n.setSelection(t)}return l&&n.setMeta("composition",l),n.scrollIntoView()};if(y)if(g.pos==b.pos){oh&&of<=11&&0==g.parentOffset&&(e.domObserver.suppressSelectionUpdates(),setTimeout(()=>ae(e),20));let t=k(e.state.tr.delete(v,w)),n=h.resolve(m.start).marksAcross(h.resolve(m.endA));n&&t.ensureMarks(n),e.dispatch(t)}else if(m.endA==m.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(iu.from(c).eq(e))return{mark:a,type:o}}(g.parent.content.cut(g.parentOffset,b.parentOffset),x.parent.content.cut(x.parentOffset,m.endA-x.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()==b.index()-!b.textOffset){let t=g.parent.textBetween(g.parentOffset,b.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 a_){let n=a_[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)||az(e,t)||!e.editable&&t.type in aD||n(e,t)},aR[t]?{passive:!0}:void 0)}oy&&e.dom.addEventListener("input",()=>null),aP(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&&aP(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(lj),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&&(aK(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=lC(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)&&aP(this),this.editable=lS(this),lN(this);let c=ll(this),d=lk(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:oM(e.dom)}}(this);if(a){let t,n,a;this.domObserver.stop();let l=p&&(oh||ob)&&!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=ob?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=on(e=e.childNodes[t-1])}else{if(!e.parentNode||or(e))return null;t=s5(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||or(e))return null;t=s5(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=oG(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(),s8(t.node,t.offset,n.anchorNode,n.anchorOffset)))?ae(this,l):(as(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;oA(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 sH){let t=this.docView.domAfterPos(this.state.selection.from);1==t.nodeType&&oE(this,t.getBoundingClientRect(),e)}else oE(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 aY(e.slice,e.move,r<0?void 0:sH.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(oh){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(oT)return e.focus(oT);let t=oM(e);e.focus(null==oT?{get preventScroll(){return oT={preventScroll:!0},!0}}:void 0),oT||(oT=!1,oA(t,0))}(this.dom),ae(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(on(r.offsetNode),r.offset)}}catch(e){}if(e.caretRangeFromPoint){let r=e.caretRangeFromPoint(t,n);if(r)return{node:r.startContainer,offset:Math.min(on(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(!oO(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(oO(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=s4(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(om&&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++}oS&&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=s9(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=oD(r,1);if(n.top!=n.bottom&&oO(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 oI(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 oB==t&&oF==n?oH:(oB=t,oF=n,oH="up"==n||"down"==n?(r=t.selection,i="up"==n?r.$from:r.$to,oz(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=oI(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=s9(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?o$.test(r.parent.textContent)&&o.modify?oz(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 aZ(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return aZ(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return ak(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,[],ll(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,s7()}}get isDestroyed(){return null==this.docView}dispatchEvent(e){!az(this,e)&&a_[e.type]&&(this.editable||!(e.type in aD))&&a_[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 lm(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?lm(e,n):null}(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}function lk(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"),[a4.node(0,e.state.doc.content.size,t)]}function lN(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:a4.widget(e.state.selection.from,t,{raw:!0,marks:e.markCursor})}}else e.cursorWrapper=null}function lS(e){return!e.someProp("editable",t=>!1===t(e.state))}function lC(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 lj(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")}lw.prototype.dispatch=function(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))};for(var lE={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:"'"},lM={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},lA="u">typeof navigator&&/Mac/.test(navigator.platform),lT="u">typeof navigator&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),lO=0;lO<10;lO++)lE[48+lO]=lE[96+lO]=String(lO);for(var lO=1;lO<=24;lO++)lE[lO+111]="F"+lO;for(var lO=65;lO<=90;lO++)lE[lO]=String.fromCharCode(lO+32),lM[lO]=String.fromCharCode(lO);for(var l_ in lE)lM.hasOwnProperty(l_)||(lM[l_]=lE[l_]);let lD="u">typeof navigator&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),lR="u">typeof navigator&&/Win/.test(navigator.platform);function lI(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 lL(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))lD?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=!(lA&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||lT&&n.shiftKey&&n.key&&1==n.key.length||"Unidentified"==n.key)&&n.key||(n.shiftKey?lM:lE)[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[lI(i,n)];if(o&&o(e.state,e.dispatch,e))return!0;if(1==i.length&&" "!=i){if(n.shiftKey){let r=t[lI(i,n,!1)];if(r&&r(e.state,e.dispatch,e))return!0}if((n.altKey||n.metaKey||n.ctrlKey)&&!(lR&&n.ctrlKey&&n.altKey)&&(s=lE[n.keyCode])&&s!=i){let r=t[lI(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 lP=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 lP(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 lz(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 l$=new s3("selectingCells");function lB(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 lF(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 lH(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=lB(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 lU(e){return"row"==e.parent.type.spec.tableRole&&!!e.nodeAfter}function lV(e,t){return e.depth==t.depth&&e.pos>=t.start(-1)&&e.pos<=t.end(-1)}function lW(e,t,n){let r=e.node(-1),i=lP.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 lq(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 lK(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 lG=class e extends sL{constructor(e,t=e){const n=e.node(-1),r=lP.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 sP(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(lU(r)&&lU(i)&&lV(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 sB.between(r,i)}content(){let e=this.$anchorCell.node(-1),t=lP.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=lq(e,0,c)),d>0&&(e=lq(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(iu.from(o)))}let o=this.isColSelection()&&this.isRowSelection()?e:s;return new ix(iu.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=sL.findFrom(e.doc.resolve(e.mapping.slice(n).map(this.to)),-1);i&&e.setSelection(i)}replaceWith(e,t){this.replace(e,new ix(iu.from(t),0,0))}forEachCell(e){let t=this.$anchorCell.node(-1),n=lP.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=lP.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=lP.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=lP.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 lJ(this.$anchorCell.pos,this.$headCell.pos)}};lG.prototype.visible=!1,sL.jsonID("cell",lG);var lJ=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&&lV(t,n)?new lG(t,n):sL.near(n,1)}};function lZ(e){if(!(e.selection instanceof lG))return null;let t=[];return e.selection.forEachCell((e,n)=>{t.push(a4.node(n,n+e.nodeSize,{class:"selectedCell"}))}),a7.create(e.doc,t)}let lX=new s3("fix-tables");function lY(e,t){let n,r=(t,r)=>{"table"==t.type.spec.tableRole&&(n=function(e,t,n,r){let i,s,o=lP.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,lq(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=lz(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(lX,{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 lQ(e){let t=lP.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 l0(e,t){let n=[],r=lP.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 l1(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 l2(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 l3(e,t){let n=l2(t.$from);if(!n)return;let r=lP.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 l5(e,t){let n=l2(t.$from);if(!n)return;let r=lP.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 l4(e,t,n=t){let r,i=t,s=n;for(let n=t;n>=0;n--){let t=l3(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=l3(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=l3(t,e.selection);n&&n.length>0&&o.push(t)}i=o[0],s=o[o.length-1];let a=l3(i,e.selection),l=l5(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=l3(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 l6(e,t,n=t){let r,i=t,s=n;for(let n=t;n>=0;n--){let t=l5(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=l5(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=l5(t,e.selection);n&&n.length>0&&o.push(t)}i=o[0],s=o[o.length-1];let a=l5(i,e.selection),l=l3(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=l5(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 l9(e){return e[0].map((t,n)=>e.map(e=>e[n]))}function l7(e){let t=e.selection,n=lH(e),r=n.node(-1),i=n.start(-1),s=lP.get(r);return{...t instanceof lG?s.rectBetween(t.$anchorCell.pos-i,t.$headCell.pos-i):s.findCell(n.pos-i),tableStart:i,map:s,table:r}}function l8(e,{map:t,tableStart:n,table:r},i){let s=i>0?-1:0;(function(e,t,n){let r=lz(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,lK(l.attrs,i-t.colCount(s))),o+=l.attrs.rowspan-1}else{let l=null==s?lz(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 ce(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=lz(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?lz(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,lz(r.type.schema).row.create(null,o)),e}function ct(e){let t=e.content;return 1==t.childCount&&t.child(0).isTextblock&&0==t.child(0).childCount}function cn(e,t){let n=e.selection;if(!(n instanceof lG)||n.$anchorCell.pos==n.$headCell.pos)return!1;let r=l7(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=iu.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{ct(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,{...lK(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=ct(s)?n+1:e;o.replaceWith(t+r.tableStart,e+r.tableStart,l)}o.setSelection(new lG(o.doc.resolve(n+r.tableStart))),t(o)}return!0}function cr(e,t){var n;let r=lz(e.schema);return(n=({node:e})=>r[e.type.spec.tableRole],(e,t)=>{let r,i,s=e.selection;if(s instanceof lG){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=lB(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=l7(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 lG&&u.setSelection(new lG(u.doc.resolve(s.$anchorCell.pos),o?u.doc.resolve(o):void 0)),t(u)}return!0})(e,t)}function ci(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 cs(e,t){if((t=t||{useDeprecatedLogic:!1}).useDeprecatedLogic)return function(t,n){if(!lF(t))return!1;if(n){let r=lz(t.schema),i=l7(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(!lF(t))return!1;if(n){let r=lz(t.schema),i=l7(t),s=t.tr,o=ci("row",i,r),a=ci("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}}cs("row",{useDeprecatedLogic:!0}),cs("column",{useDeprecatedLogic:!0});let co=cs("cell",{useDeprecatedLogic:!0});function ca(e){return function(t,n){if(!lF(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}(lH(t),e);if(null==r)return!1;if(n){let e=t.doc.resolve(r);n(t.tr.setSelection(sB.between(e,e.node(0).resolve(e.pos+e.nodeAfter.nodeSize))).scrollIntoView())}return!0}}function cl(e,t){let n=e.selection;if(!(n instanceof lG))return!1;if(t){let r=e.tr,i=lz(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 cc(e,t){let n=e.createAndFill();return new sR(n).replace(0,n.content.size,t).doc}function cd(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 cu(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,lq(i.attrs,o-d,i.attrs.colspan-(o-d))),e.insert(u+i.nodeSize,i.type.createAndFill(lq(i.attrs,0,o-d))),c+=i.attrs.rowspan-1}}return l}function cp(e,t,n,r,i){let s=n?e.doc.nodeAt(n-1):e.doc;if(!s)throw Error("No table found");let o=lP.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=lP.get(s),p=u.mapping.maps.length}(function(e,t,n,r,i,s){let o,a,l=lz(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,iu.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(),cd(u,o,s,n,l,c,a,p)&&h(),cd(u,o,s,n,l,c,d,p)&&h(),cu(u,o,s,n,a,d,l,p)&&h(),cu(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 lG(u.doc.resolve(n+o.positionAt(a,l,s)),u.doc.resolve(n+o.positionAt(d-1,c-1,s)))),t(u)}let ch=lL({ArrowLeft:cm("horiz",-1),ArrowRight:cm("horiz",1),ArrowUp:cm("vert",-1),ArrowDown:cm("vert",1),"Shift-ArrowLeft":cg("horiz",-1),"Shift-ArrowRight":cg("horiz",1),"Shift-ArrowUp":cg("vert",-1),"Shift-ArrowDown":cg("vert",1),Backspace:cl,"Mod-Backspace":cl,Delete:cl,"Mod-Delete":cl});function cf(e,t,n){return!n.eq(e.selection)&&(t&&t(e.tr.setSelection(n).scrollIntoView()),!0)}function cm(e,t){return(n,r,i)=>{if(!i)return!1;let s=n.selection;if(s instanceof lG)return cf(n,r,sL.near(s.$headCell,t));if("horiz"!=e&&!s.empty)return!1;let o=cv(i,e,t);if(null==o)return!1;if("horiz"==e)return cf(n,r,sL.near(n.doc.resolve(s.head+t),t));{let i,s=n.doc.resolve(o),a=lW(s,e,t);return i=a?sL.near(a,1):t<0?sL.near(n.doc.resolve(s.before(-1)),-1):sL.near(n.doc.resolve(s.after(-1)),1),cf(n,r,i)}}}function cg(e,t){return(n,r,i)=>{let s;if(!i)return!1;let o=n.selection;if(o instanceof lG)s=o;else{let r=cv(i,e,t);if(null==r)return!1;s=new lG(n.doc.resolve(r))}let a=lW(s.$headCell,e,t);return!!a&&cf(n,r,new lG(s.$anchorCell,a))}}function cb(e,t){let n=lB(e.state.doc.resolve(t));return!!n&&(e.dispatch(e.state.tr.setSelection(new lG(n))),!0)}function cx(e,t,n){if(!lF(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=cc(lz(o).row,new ix(i,s,l)).content),a.push(i)}else{if("cell"!=s&&"header_cell"!=s)return null;a.push(n||r?cc(lz(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(iu.empty),n[i]<r){let s=lz(e).cell.createAndFill(),o=[];for(let e=n[i];e<r;e++)o.push(s);t[i]=t[i].append(iu.from(o))}return{height:t.length,width:r,rows:t}}(o,a)}(n),i=e.state.selection;if(i instanceof lG){r||(r={width:1,height:1,rows:[iu.from(cc(lz(e.state.schema).cell,n))]});let t=i.$anchorCell.node(-1),s=i.$anchorCell.start(-1),o=lP.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(lq(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(iu.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(iu.from(o))}n=e,t=i}return{width:e,height:t,rows:n}}(r,o.right-o.left,o.bottom-o.top),cp(e.state,e.dispatch,s,o,r),!0}if(!r)return!1;{let t=lH(e.state),n=t.start(-1);return cp(e.state,e.dispatch,n,lP.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=cw(e,t.target);if(t.shiftKey&&e.state.selection instanceof lG)s(e.state.selection.$anchorCell,t),t.preventDefault();else if(t.shiftKey&&i&&null!=(r=lB(e.state.selection.$anchor))&&(null==(n=ck(e,t))?void 0:n.pos)!=r.pos)s(r,t),t.preventDefault();else if(!i)return;function s(t,n){let r=ck(e,n),i=null==l$.getState(e.state);if(!r||!lV(t,r))if(!i)return;else r=t;let s=new lG(t,r);if(i||!e.state.selection.eq(s)){let n=e.state.tr.setSelection(s);i&&n.setMeta(l$,t.pos),e.dispatch(n)}}function o(){e.root.removeEventListener("mouseup",o),e.root.removeEventListener("dragstart",o),e.root.removeEventListener("mousemove",a),null!=l$.getState(e.state)&&e.dispatch(e.state.tr.setMeta(l$,-1))}function a(n){let r,a=l$.getState(e.state);if(null!=a)r=e.state.doc.resolve(a);else if(cw(e,n.target)!=i&&!(r=ck(e,t)))return o();r&&s(r,n)}e.root.addEventListener("mouseup",o),e.root.addEventListener("dragstart",o),e.root.addEventListener("mousemove",a)}function cv(e,t,n){if(!(e.state.selection instanceof sB))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 cw(e,t){for(;t&&t!=e.dom;t=t.parentNode)if("TD"==t.nodeName||"TH"==t.nodeName)return t;return null}function ck(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&&lB(e.state.doc.resolve(r))||lB(e.state.doc.resolve(i))}var cN=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")),cS(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,cS(e,this.colgroup,this.table,this.defaultCellMinWidth),!0)}ignoreMutation(e){return"attributes"==e.type&&(e.target==this.table||this.colgroup.contains(e.target))}};function cS(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 cC=new s3("tableColumnResizing");var cj=class e{constructor(e,t){this.activeHandle=e,this.dragging=t}apply(t){let n=t.getMeta(cC);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 lU(t.doc.resolve(n))||(n=-1),new e(n,this.dragging)}return this}};function cE(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=lB(e.state.doc.resolve(s));if(!o)return -1;if("right"==n)return o.pos;let a=lP.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 cM(e,t,n){let r=t.clientX-e.startX;return Math.max(n,e.startWidth+r)}function cA(e,t){e.dispatch(e.state.tr.setMeta(cC,{setHandle:t}))}function cT(e,t,n,r){let i=e.state.doc.resolve(t),s=i.node(-1),o=i.start(-1),a=lP.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&&cS(s,l.firstChild,l,r,a,n)}var cO=f,c_=e.i(3909);let cD=(e,t)=>!e.selection.empty&&(t&&t(e.tr.deleteSelection().scrollIntoView()),!0);function cR(e,t){let{$cursor:n}=e.selection;return n&&(t?t.endOfTextblock("backward",e):!(n.parentOffset>0))?n:null}let cI=(e,t,n)=>{let r=cR(e,n);if(!r)return!1;let i=c$(r);if(!i){let n=r.blockRange(),i=n&&sh(n);return null!=i&&(t&&t(e.tr.lift(n,i).scrollIntoView()),!0)}let s=i.nodeBefore;if(cJ(e,i,t,-1))return!0;if(0==r.parent.content.size&&(cP(s,"end")||sH.isSelectable(s)))for(let n=r.depth;;n--){let o=sN(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(cP(s,"end")?sL.findFrom(n.doc.resolve(n.mapping.map(i.pos,-1)),-1):sH.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 cL(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=sN(e.doc,i,o,ix.empty);if(!a||a.from!=i||a instanceof sc&&a.slice.size>=o-i)return!1;if(n){let t=e.tr.step(a);t.setSelection(sB.create(t.doc,i)),n(t.scrollIntoView())}return!0}function cP(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 cz=(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=c$(r)}let o=s&&s.nodeBefore;return!!o&&!!sH.isSelectable(o)&&(t&&t(e.tr.setSelection(sH.create(e.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function c$(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 cB(e,t){let{$cursor:n}=e.selection;return n&&(t?t.endOfTextblock("forward",e):!(n.parentOffset<n.parent.content.size))?n:null}let cF=(e,t,n)=>{let r=cB(e,n);if(!r)return!1;let i=cU(r);if(!i)return!1;let s=i.nodeAfter;if(cJ(e,i,t,1))return!0;if(0==r.parent.content.size&&(cP(s,"start")||sH.isSelectable(s))){let n=sN(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(cP(s,"start")?sL.findFrom(r.doc.resolve(r.mapping.map(i.pos)),1):sH.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)},cH=(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=cU(r)}let o=s&&s.nodeAfter;return!!o&&!!sH.isSelectable(o)&&(t&&t(e.tr.setSelection(sH.create(e.doc,s.pos)).scrollIntoView()),!0)};function cU(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 cV=(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 cW(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 cq=(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=cW(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(sL.near(i.doc.resolve(r),1)),t(i.scrollIntoView())}return!0},cK=(e,t)=>{let n=e.selection,{$from:r,$to:i}=n;if(n instanceof sV||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=cW(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(sB.create(o.doc,n+1)),t(o.scrollIntoView())}return!0},cG=(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&&sh(r);return null!=i&&(t&&t(e.tr.lift(r,i).scrollIntoView()),!0)};function cJ(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=iu.empty;for(let e=c.length-1;e>=0;e--)i=iu.from(c[e].create(null,i));i=iu.from(a.copy(i));let s=e.tr.step(new sd(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:sL.findFrom(t,1),f=h&&h.$from.blockRange(h.$to),m=f&&sh(f);if(null!=m&&m>=t.depth)return n&&n(e.tr.lift(f,m).scrollIntoView()),!0;if(p&&cP(l,"start",!0)&&cP(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=iu.empty;for(let e=i.length-1;e>=0;e--)r=iu.from(i[e].copy(r));n(e.tr.step(new sd(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 cZ(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(sB.create(t.doc,e<0?i.start(s):i.end(s)))),!0)}}let cX=cZ(-1),cY=cZ(1);function cQ(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 c0(...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 c1=c0(cD,cI,cz),c2=c0(cD,cF,cH),c3={Enter:c0(cV,cK,cG,(e,t)=>{let{$from:n,$to:r}=e.selection;if(e.selection instanceof sH&&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=cW(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 sB||e.selection instanceof sV)&&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":cq,Backspace:c1,"Mod-Backspace":c1,"Shift-Backspace":c1,Delete:c2,"Mod-Delete":c2,"Mod-a":(e,t)=>(t&&t(e.tr.setSelection(new sV(e.doc))),!0)},c5={"Ctrl-h":c3.Backspace,"Alt-Backspace":c3["Mod-Backspace"],"Ctrl-d":c3.Delete,"Ctrl-Alt-Backspace":c3["Mod-Delete"],"Alt-Delete":c3["Mod-Delete"],"Alt-d":c3["Mod-Delete"],"Ctrl-a":cX,"Ctrl-e":cY};for(let e in c3)c5[e]=c3[e];"u">typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):"u">typeof os&&os.platform&&os.platform();var c4=Object.defineProperty,c6=(e,t)=>{for(var n in t)c4(e,n,{get:t[n],enumerable:!0})};function c9(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 c7=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:c9({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}},c8={};c6(c8,{blur:()=>de,clearContent:()=>dt,clearNodes:()=>dn,command:()=>dr,createParagraphNear:()=>di,cut:()=>ds,deleteCurrentNode:()=>da,deleteNode:()=>dc,deleteRange:()=>dd,deleteSelection:()=>dp,enter:()=>dh,exitCode:()=>df,extendMarkRange:()=>dw,first:()=>dk,focus:()=>dM,forEach:()=>dA,insertContent:()=>dT,insertContentAt:()=>dR,joinBackward:()=>dP,joinDown:()=>dL,joinForward:()=>dz,joinItemBackward:()=>d$,joinItemForward:()=>dB,joinTextblockBackward:()=>dF,joinTextblockForward:()=>dH,joinUp:()=>dI,keyboardShortcut:()=>dV,lift:()=>dq,liftEmptyBlock:()=>dK,liftListItem:()=>dG,newlineInCode:()=>dJ,resetAttributes:()=>dY,scrollIntoView:()=>dQ,selectAll:()=>d0,selectNodeBackward:()=>d1,selectNodeForward:()=>d2,selectParentNode:()=>d3,selectTextblockEnd:()=>d5,selectTextblockStart:()=>d4,setContent:()=>d9,setMark:()=>uI,setMeta:()=>uL,setNode:()=>uP,setNodeSelection:()=>uz,setTextDirection:()=>u$,setTextSelection:()=>uB,sinkListItem:()=>uF,splitBlock:()=>uU,splitListItem:()=>uV,toggleList:()=>uK,toggleMark:()=>uG,toggleNode:()=>uJ,toggleWrap:()=>uZ,undoInputRule:()=>uX,unsetAllMarks:()=>uY,unsetMark:()=>uQ,unsetTextDirection:()=>u0,updateAttributes:()=>u1,wrapIn:()=>u2,wrapInList:()=>u3});var de=()=>({editor:e,view:t})=>(requestAnimationFrame(()=>{var n;e.isDestroyed||(t.dom.blur(),null==(n=null==window?void 0:window.getSelection())||n.removeAllRanges())}),!0),dt=(e=!0)=>({commands:t})=>t.setContent("",{emitUpdate:e}),dn=()=>({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=sh(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)},dr=e=>t=>e(t),di=()=>({state:e,dispatch:t})=>cK(e,t),ds=(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 sB(r.doc.resolve(Math.max(o-1,0)))),!0},da=()=>({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 dl(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 dc=e=>({tr:t,state:n,dispatch:r})=>{let i=dl(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},dd=e=>({tr:t,dispatch:n})=>{let{from:r,to:i}=e;return n&&t.delete(r,i),!0},du=(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},dp=()=>({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:du(r,n=e.schema,"left"),to:du(i,n,"right")};return t&&(e.tr.deleteRange(s,o).scrollIntoView(),t(e.tr)),!0},dh=()=>({commands:e})=>e.keyboardShortcut("Enter"),df=()=>({state:e,dispatch:t})=>cq(e,t);function dm(e){return"[object RegExp]"===Object.prototype.toString.call(e)}function dg(e,t,n={strict:!0}){let r=Object.keys(t);return!r.length||r.every(r=>n.strict?t[r]===e[r]:dm(t[r])?t[r].test(e[r]):t[r]===e[r])}function db(e,t,n={}){return e.find(e=>e.type===t&&dg(Object.fromEntries(Object.keys(n).map(t=>[t,e.attrs[t]])),n))}function dx(e,t,n={}){return!!db(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(!db([...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 dv(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 dw=(e,t)=>({tr:n,state:r,dispatch:i})=>{let s=dv(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=sB.create(o,e.from,e.to);n.setSelection(t)}}return!0},dk=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 dN(e){return e instanceof sB}function dS(e=0,t=0,n=0){return Math.min(Math.max(e,t),n)}function dC(e,t=null){if(!t)return null;let n=sL.atStart(e),r=sL.atEnd(e);if("start"===t||!0===t)return n;if("end"===t)return r;let i=n.from,s=r.to;return"all"===t?sB.create(e,dS(0,i,s),dS(e.content.size,i,s)):sB.create(e,dS(t,i,s),dS(t,i,s))}function dj(){return"Android"===navigator.platform||/android/i.test(navigator.userAgent)}function dE(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}var dM=(e=null,t={})=>({editor:n,view:r,tr:i,dispatch:s})=>{t={scrollIntoView:!0,...t};let o=()=>{(dE()||dj())&&r.dom.focus(),"u">typeof navigator&&/^((?!chrome|android).)*safari/i.test(navigator.userAgent)&&!dE()&&!dj()&&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&&!dN(n.state.selection))return o(),!0;let a=dC(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},dA=(e,t)=>n=>e.every((e,r)=>t(e,{...n,index:r})),dT=(e,t)=>({tr:n,commands:r})=>r.insertContentAt({from:n.selection.from,to:n.selection.to},e,t),dO=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&&dO(r)}return e};function d_(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 dO(new window.DOMParser().parseFromString(t,"text/html").body)}function dD(e,t,n){if(e instanceof iO||e instanceof iu)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 iu.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),dD("",t,n)}if(i){if(n.errorOnInvalidContent){let r=!1,i="",s=new iq({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?iG.fromSchema(s).parseSlice(d_(e),n.parseOptions):iG.fromSchema(s).parse(d_(e),n.parseOptions),n.errorOnInvalidContent&&r)throw Error("[tiptap error]: Invalid HTML content",{cause:Error(`Invalid element found: ${i}`)})}let r=iG.fromSchema(t);return n.slice?r.parseSlice(d_(e),n.parseOptions).content:r.parse(d_(e),n.parseOptions)}return dD("",t,n)}var dR=(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{dD(t,s.schema,{parseOptions:c,errorOnInvalidContent:!0})}catch(e){l(e)}try{i=dD(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 iu){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 sc||r instanceof sd))return;let i=e.mapping.maps[n],s=0;i.forEach((e,t,n,r)=>{0===s&&(s=r)}),e.setSelection(sL.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},dI=()=>({state:e,dispatch:t})=>((e,t)=>{let n=e.selection,r=n instanceof sH,i;if(r){if(n.node.isTextblock||!sy(e.doc,n.from))return!1;i=n.from}else if(null==(i=sw(e.doc,n.from,-1)))return!1;if(t){let n=e.tr.join(i);r&&n.setSelection(sH.create(n.doc,i-e.doc.resolve(i).nodeBefore.nodeSize)),t(n.scrollIntoView())}return!0})(e,t),dL=()=>({state:e,dispatch:t})=>((e,t)=>{let n=e.selection,r;if(n instanceof sH){if(n.node.isTextblock||!sy(e.doc,n.to))return!1;r=n.to}else if(null==(r=sw(e.doc,n.to,1)))return!1;return t&&t(e.tr.join(r).scrollIntoView()),!0})(e,t),dP=()=>({state:e,dispatch:t})=>cI(e,t),dz=()=>({state:e,dispatch:t})=>cF(e,t),d$=()=>({state:e,dispatch:t,tr:n})=>{try{let r=sw(e.doc,e.selection.$from.pos,-1);if(null==r)return!1;return n.join(r,2),t&&t(n),!0}catch{return!1}},dB=()=>({state:e,dispatch:t,tr:n})=>{try{let r=sw(e.doc,e.selection.$from.pos,1);if(null==r)return!1;return n.join(r,2),t&&t(n),!0}catch{return!1}},dF=()=>({state:e,dispatch:t})=>((e,t,n)=>{let r=cR(e,n);if(!r)return!1;let i=c$(r);return!!i&&cL(e,i,t)})(e,t),dH=()=>({state:e,dispatch:t})=>((e,t,n)=>{let r=cB(e,n);if(!r)return!1;let i=cU(r);return!!i&&cL(e,i,t)})(e,t);function dU(){return"u">typeof navigator&&/Mac/.test(navigator.platform)}var dV=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))dE()||dU()?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 dW(e,t,n={}){let{from:r,to:i,empty:s}=e.selection,o=t?dl(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=>dg(e.node.attrs,n,{strict:!1}));return s?!!c.length:c.reduce((e,t)=>e+t.to-t.from,0)>=l}var dq=(e,t={})=>({state:n,dispatch:r})=>{let i=dl(e,n.schema);return!!dW(n,i,t)&&((e,t)=>{let{$from:n,$to:r}=e.selection,i=n.blockRange(r),s=i&&sh(i);return null!=s&&(t&&t(e.tr.lift(i,s).scrollIntoView()),!0)})(n,r)},dK=()=>({state:e,dispatch:t})=>cG(e,t),dG=e=>({state:t,dispatch:n})=>{var r;return(r=dl(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 sd(s-1,o,s,o,new ix(iu.from(n.create(null,r.parent.copy())),1,0),1,!0)),r=new iA(i.doc.resolve(r.$from.pos),i.doc.resolve(o),r.depth));let a=sh(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?iu.empty:iu.from(i))))return!1;let u=s.pos,p=u+o.nodeSize;return r.step(new sd(u-!!a,p+ +!!l,u+1,p-1,new ix((a?iu.empty:iu.from(i.copy(iu.empty))).append(l?iu.empty:iu.from(i.copy(iu.empty))),+!a,+!l),+!a)),t(r.scrollIntoView()),!0}(e,t,s)))})(t,n)},dJ=()=>({state:e,dispatch:t})=>cV(e,t);function dZ(e,t){return t.nodes[e]?"node":t.marks[e]?"mark":null}function dX(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 dY=(e,t)=>({tr:n,state:r,dispatch:i})=>{let s=null,o=null,a=dZ("string"==typeof e?e:e.name,r.schema);if(!a)return!1;"node"===a&&(s=dl(e,r.schema)),"mark"===a&&(o=dv(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,dX(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(dX(s.attrs,t))))})})}),l},dQ=()=>({tr:e,dispatch:t})=>(t&&e.scrollIntoView(),!0),d0=()=>({tr:e,dispatch:t})=>{if(t){let t=new sV(e.doc);e.setSelection(t)}return!0},d1=()=>({state:e,dispatch:t})=>cz(e,t),d2=()=>({state:e,dispatch:t})=>cH(e,t),d3=()=>({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(sH.create(e.doc,i))),!0)})(e,t),d5=()=>({state:e,dispatch:t})=>cY(e,t),d4=()=>({state:e,dispatch:t})=>cX(e,t);function d6(e,t,n={},r={}){return dD(e,t,{slice:!1,parseOptions:n,errorOnInvalidContent:r.errorOnInvalidContent})}var d9=(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=d6(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 d7(e,t){let n=dv(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 d8(e,t){let n=new sR(e);return t.forEach(e=>{e.steps.forEach(e=>{n.step(e)})}),n}function ue(e,t){let n=[];return e.descendants((e,r)=>{t(e)&&n.push({node:e,pos:r})}),n}function ut(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 un(e){return t=>ut(t.$from,e)}function ur(e,t,n){return void 0===e.config[t]&&e.parent?ur(e.parent,t,n):"function"==typeof e.config[t]?e.config[t].bind({...n,parent:e.parent?ur(e.parent,t,n):null}):e.config[t]}function ui(e){return e.map(e=>{let t={name:e.name,options:e.options,storage:e.storage},n=ur(e,"addExtensions",t);return n?[e,...ui(n())]:e}).flat(10)}function us(e,t){let n=i3.fromSchema(t).serializeFragment(e),r=document.implementation.createHTMLDocument().createElement("div");return r.appendChild(n),r.innerHTML}function uo(e){return"function"==typeof e}function ua(e,t,...n){return uo(e)?t?e.bind(t)(...n):e(...n):e}function ul(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 uc(e){let t=[],{nodeExtensions:n,markExtensions:r}=ul(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=ur(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=ur(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 ud(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 uu(...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([...ud(n[e]),...ud(t)]);n[e]=Array.from(r.entries()).map(([e,t])=>`${e}: ${t}`).join("; ")}else n[e]=t}),n},{})}function up(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)=>uu(e,t),{})}function uh(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 uf(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 um(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 ug(e){return e.sort((e,t)=>{let n=ur(e,"priority")||100,r=ur(t,"priority")||100;return n>r?-1:+(n<r)})}function ub(e){var t;let n=ug(ui(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 uv(e){return Object.fromEntries(Object.entries(e.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function uw(e,t){let n=dZ("string"==typeof t?t:t.name,e.schema);return"node"===n?function(e,t){let n=dl(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?d7(e,t):{}}function uk(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 uN(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 uS(e,t){return t.nodes[e]||t.marks[e]||null}function uC(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 uj(e,t,n={}){let{empty:r,ranges:i}=e.selection,s=t?dv(t,e.schema):null;if(r)return!!(e.storedMarks||e.selection.$from.marks()).filter(e=>!s||s.name===e.type.name).find(e=>dg(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=>dg(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 uE(e,t){return Array.isArray(t)?t.some(t=>("string"==typeof t?t:t.name)===e.name):t}function uM(e,t){let{nodeExtensions:n}=ul(t),r=n.find(t=>t.name===e);if(!r)return!1;let i={name:r.name,options:r.options,storage:r.storage},s=ua(ur(r,"group",i));return"string"==typeof s&&s.split(" ").includes("list")}function uA(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&&(uA(e,{ignoreWhitespace:n,checkChildren:t})||(r=!1))}),r}return!1}function uT(e){return e instanceof sH}var uO=class e{constructor(e){this.position=e}static fromJSON(t){return new e(t.position)}toJSON(){return{position:this.position}}};function u_(e,t){let n=t.mapping.mapResult(e.position);return{position:new uO(n.pos),mapResult:n}}function uD(e){return new uO(e)}function uR(e,t,n){let r=e.state.doc.content.size,i=dS(t,0,r),s=dS(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 uI=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let{selection:s}=n,{empty:o,ranges:a}=s,l=dv(e,r.schema);if(i)if(o){let e=d7(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(dN(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)},uL=(e,t)=>({tr:n})=>(n.setMeta(e,t),!0),uP=(e,t={})=>({state:n,dispatch:r,chain:i})=>{let s,o=dl(e,n.schema);return(n.selection.$anchor.sameParent(n.selection.$head)&&(s=n.selection.$anchor.parent.attrs),o.isTextblock)?i().command(({commands:e})=>!!cQ(o,{...s,...t})(n)||e.clearNodes()).command(({state:e})=>cQ(o,{...s,...t})(e,r)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},uz=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,r=dS(e,0,n.content.size),i=sH.create(n,r);t.setSelection(i)}return!0},u$=(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},uB=e=>({tr:t,dispatch:n})=>{if(n){let{doc:n}=t,{from:r,to:i}="number"==typeof e?{from:e,to:e}:e,s=sB.atStart(n).from,o=sB.atEnd(n).to,a=dS(r,s,o),l=dS(i,s,o),c=sB.create(n,a,l);t.setSelection(c)}return!0},uF=e=>({state:t,dispatch:n})=>{var r;return(r=dl(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=iu.from(n?r.create():null),o=new ix(iu.from(r.create(null,iu.from(a.type.create(null,i)))),n?3:1,0),c=s.start,d=s.end;t(e.tr.step(new sd(c-(n?3:1),d,c,d,o,1,!0)).scrollIntoView())}return!0})(t,n)};function uH(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 uU=({keepMarks:e=!0}={})=>({tr:t,state:n,dispatch:r,editor:i})=>{let{selection:s,doc:o}=t,{$from:a,$to:l}=s,c=uC(i.extensionManager.attributes,a.node().type.name,a.node().attrs);if(s instanceof sH&&s.node.isBlock)return!!a.parentOffset&&!!sx(o,a.pos)&&(r&&(e&&uH(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 sB&&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&&uH(n,i.extensionManager.splittableMarks),t.scrollIntoView()}return h},uV=(e,t={})=>({tr:n,state:r,dispatch:i,editor:s})=>{var o;let a=dl(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=iu.empty,r=l.index(-1)?1:l.index(-2)?2:3;for(let t=l.depth-r;t>=l.depth-3;t-=1)e=iu.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={...uC(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(iu.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(sB.near(n.doc.resolve(u))),n.scrollIntoView()}return!0}let h=c.pos===l.end()?u.contentMatchAt(0).defaultType:null,f={...uC(p,u.type.name,u.attrs),...t},m={...uC(p,l.node().type.name,l.node().attrs),...t};n.delete(l.pos,c.pos);let g=h?[{type:a,attrs:f},{type:h,attrs:m}]:[{type:a,attrs:f}];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},uW=(e,t)=>{let n=un(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)},uq=(e,t)=>{let n=un(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)},uK=(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=dl(e,o.schema),f=dl(t,o.schema),{selection:m,storedMarks:g}=o,{$from:b,$to:x}=m,y=b.blockRange(x),v=g||m.$to.parentOffset&&m.$from.marks();if(!y)return!1;let w=un(e=>uM(e.type.name,u))(m),k=0===m.from&&m.to===o.doc.content.size,N=o.doc.content.content,S=1===N.length?N[0]:null,C=k&&S&&uM(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 sB.between(r,i)}(e);return!!n&&(e.setSelection(n),t&&t(e),!0)}).liftListItem(f).run():c.liftListItem(f);if(uM(j.node.type.name,u)&&h.validContent(j.node.content))return l().command(()=>(s.setNodeMarkup(j.pos,h),!0)).command(()=>uW(s,h)).command(()=>uq(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(()=>uW(s,h)).command(()=>uq(s,h)).run():l().command(()=>!!d().wrapInList(h,r)||c.clearNodes()).wrapInList(h,r).command(()=>uW(s,h)).command(()=>uq(s,h)).run()},uG=(e,t={},n={})=>({state:r,commands:i})=>{let{extendEmptyMarkRange:s=!1}=n,o=dv(e,r.schema);return uj(r,o,t)?i.unsetMark(o,{extendEmptyMarkRange:s}):i.setMark(o,t)},uJ=(e,t,n={})=>({state:r,commands:i})=>{let s,o=dl(e,r.schema),a=dl(t,r.schema),l=dW(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})},uZ=(e,t={})=>({state:n,commands:r})=>{let i=dl(e,n.schema);return dW(n,i,t)?r.lift(i):r.wrapIn(i,t)},uX=()=>({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},uY=()=>({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)},uQ=(e,t={})=>({tr:n,state:r,dispatch:i})=>{var s;let{extendEmptyMarkRange:o=!1}=t,{selection:a}=n,l=dv(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},u0=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},u1=(e,t={})=>({tr:n,state:r,dispatch:i})=>{let s=null,o=null,a=dZ("string"==typeof e?e:e.name,r.schema);if(!a)return!1;"node"===a&&(s=dl(e,r.schema)),"mark"===a&&(o=dv(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},u2=(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&&sf(o,e,t);return!!a&&(r&&r(n.tr.wrap(o,a).scrollIntoView()),!0)}})(dl(e,n.schema),t)(n,r),u3=(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 iA(e,e,t.depth),t.endIndex<t.parent.childCount&&(t=new iA(t.$from,o.resolve(t.$to.end(t.depth)),t.depth)),i=!0}let a=sf(s,n,r,t);return!!a&&(e&&function(e,t,n,r,i){let s=iu.empty;for(let e=n.length-1;e>=0;e--)s=iu.from(n[e].type.create(n[e].attrs,s));e.step(new sd(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)}})(dl(e,n.schema),t)(n,r),u5=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={}}},u4=class{constructor(e){var t;this.find=e.find,this.handler=e.handler,this.undoable=null==(t=e.undoable)||t}};function u6(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(dm(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=c9({state:l.state,transaction:o}),p={from:r-(t[0].length-s.length),to:i},{commands:h,chain:f,can:m}=new c7({editor:n,state:c});null!==e.handler({state:c,range:p,match:t,commands:h,chain:f,can:m})&&o.steps.length&&(e.undoable&&o.setMeta(a,{transform:o,from:r,to:i,text:s}),l.dispatch(o),d=!0)}),d}function u9(e){return"Object"===Object.prototype.toString.call(e).slice(8,-1)&&e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype}var u7=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{...ua(ur(this,"addOptions",{name:this.name}))}}get storage(){return{...ua(ur(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 u9(t)&&u9(n)&&Object.keys(n).forEach(i=>{u9(n[i])&&u9(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}},u8=class e extends u7{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)}},pe=class{constructor(e){this.find=e.find,this.handler=e.handler}},pt=null,pn=class{constructor(e,t){this.splittableMarks=[],this.editor=t,this.baseExtensions=e,this.extensions=ub(e),this.schema=function(e,t){var n;let r=uc(e),{nodeExtensions:i,markExtensions:s}=ul(e),o=null==(n=i.find(e=>ur(e,"topNode")))?void 0:n.name;return new iq({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=uf({...e.reduce((e,t)=>{let r=ur(t,"extendNodeSchema",s);return{...e,...r?r(n):{}}},{}),content:ua(ur(n,"content",s)),marks:ua(ur(n,"marks",s)),group:ua(ur(n,"group",s)),inline:ua(ur(n,"inline",s)),atom:ua(ur(n,"atom",s)),selectable:ua(ur(n,"selectable",s)),draggable:ua(ur(n,"draggable",s)),code:ua(ur(n,"code",s)),whitespace:ua(ur(n,"whitespace",s)),linebreakReplacement:ua(ur(n,"linebreakReplacement",s)),defining:ua(ur(n,"defining",s)),isolating:ua(ur(n,"isolating",s)),attrs:Object.fromEntries(i.map(um))}),a=ua(ur(n,"parseHTML",s));a&&(o.parseDOM=a.map(e=>uh(e,i)));let l=ur(n,"renderHTML",s);l&&(o.toDOM=e=>l({node:e,HTMLAttributes:up(e,i)}));let c=ur(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=uf({...e.reduce((e,t)=>{let r=ur(t,"extendMarkSchema",s);return{...e,...r?r(n):{}}},{}),inclusive:ua(ur(n,"inclusive",s)),excludes:ua(ur(n,"excludes",s)),group:ua(ur(n,"group",s)),spanning:ua(ur(n,"spanning",s)),code:ua(ur(n,"code",s)),attrs:Object.fromEntries(i.map(um))}),a=ua(ur(n,"parseHTML",s));a&&(o.parseDOM=a.map(e=>uh(e,i)));let l=ur(n,"renderHTML",s);return l&&(o.toDOM=e=>l({mark:e,HTMLAttributes:up(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:uS(t.name,this.schema)},r=ur(t,"addCommands",n);return r?{...e,...r()}:e},{})}get plugins(){let{editor:e}=this;return ug([...this.extensions].reverse()).flatMap(t=>{let n={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:e,type:uS(t.name,this.schema)},r=[],i=ur(t,"addKeyboardShortcuts",n),s={};if("mark"===t.type&&ur(t,"exitable",n)&&(s.ArrowRight=()=>u8.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 s0({props:{handleKeyDown:lL(s)}});r.push(o);let a=ur(t,"addInputRules",n);if(uE(t,e.options.enableInputRules)&&a){let t=a();if(t&&t.length){let n=function(e){let{editor:t,rules:n}=e,r=new s0({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=us(iu.from(e),s.schema));let{from:i}=a,o=i+e.length;u6({editor:t,from:i,to:o,text:e,rules:n,plugin:r})}),e.selectionSet||e.docChanged?null:i}},props:{handleTextInput:(e,i,s,o)=>u6({editor:t,from:i,to:s,text:o,rules:n,plugin:r}),handleDOMEvents:{compositionend:e=>(setTimeout(()=>{let{$cursor:i}=e.state.selection;i&&u6({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&&u6({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=ur(t,"addPasteRules",n);if(uE(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 c7({editor:t,state:n}),u=[];return n.doc.nodesBetween(r,i,(e,t)=>{var p,h,f,m,g;if((null==(h=null==(p=e.type)?void 0:p.spec)?void 0:h.code)||!(e.isText||e.isTextblock||e.isInline))return;let b=null!=(g=null!=(m=null==(f=e.content)?void 0:f.size)?m:e.nodeSize)?g:0,x=Math.max(r,t),y=Math.min(i,t+b);x>=y||((e,t,n)=>{if(dm(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(x-t,y-t,void 0,""),s.find,o).forEach(e=>{if(void 0===e.index)return;let t=x+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:c9({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 s0({view(e){let t=t=>{var r;(i=(null==(r=e.dom.parentElement)?void 0:r.contains(t.target))?e.dom.parentElement:null)&&(pt=n)},r=()=>{pt&&(pt=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=pt;(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,f;let t,{text:n}=u;"string"==typeof n||(n=us(iu.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==(f=(t=new ClipboardEvent("paste",{clipboardData:new DataTransfer})).clipboardData)||f.setData("text/html",h),t)})}let m=n.doc.content.findDiffStart(r.doc.content),g=n.doc.content.findDiffEnd(r.doc.content);if("number"==typeof m&&g&&m!==g.b)return l({rule:e,state:r,from:m,to:g,pasteEvt:a})}}))}({editor:e,rules:t});r.push(...n)}}let c=ur(t,"addProseMirrorPlugins",n);if(c){let e=c();r.push(...e)}return r})}get attributes(){return uc(this.extensions)}get nodeViews(){let{editor:e}=this,{nodeExtensions:t}=ul(this.extensions);return Object.fromEntries(t.filter(e=>!!ur(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:dl(t.name,this.schema)},i=ur(t,"addNodeView",r);if(!i)return[];let s=i();return s?[t.name,(r,i,o,a,l)=>{let c=up(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 ug([...this.extensions].reverse()).reduceRight((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:uS(n.name,this.schema)},i=ur(n,"dispatchTransaction",r);return i?t=>{i.call(r,{transaction:t,next:e})}:e},e)}transformPastedHTML(e){let{editor:t}=this;return ug([...this.extensions]).reduce((e,n)=>{let r={name:n.name,options:n.options,storage:this.editor.extensionStorage[n.name],editor:t,type:uS(n.name,this.schema)},i=ur(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}=ul(this.extensions);return Object.fromEntries(t.filter(e=>!!ur(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:dv(t.name,this.schema)},i=ur(t,"addMarkView",r);return i?[t.name,(r,s,o)=>{let a=up(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:uS(e.name,this.schema)};"mark"===e.type&&(null==(t=ua(ur(e,"keepOnSplit",n)))||t)&&this.splittableMarks.push(e.name);let r=ur(e,"onBeforeCreate",n),i=ur(e,"onCreate",n),s=ur(e,"onUpdate",n),o=ur(e,"onSelectionUpdate",n),a=ur(e,"onTransaction",n),l=ur(e,"onFocus",n),c=ur(e,"onBlur",n),d=ur(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)})}};pn.resolve=ub,pn.sort=ug,pn.flatten=ui,c6({},{ClipboardTextSerializer:()=>pi,Commands:()=>ps,Delete:()=>po,Drop:()=>pa,Editable:()=>pl,FocusEvents:()=>pd,Keymap:()=>pu,Paste:()=>pp,Tabindex:()=>ph,TextDirection:()=>pf,focusEventsPluginKey:()=>pc});var pr=class e extends u7{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)}},pi=pr.create({name:"clipboardTextSerializer",addOptions:()=>({blockSeparator:void 0}),addProseMirrorPlugins(){return[new s0({key:new s3("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=uv(n);return ux(r,{from:o,to:a},{...void 0!==this.options.blockSeparator?{blockSeparator:this.options.blockSeparator}:{},textSerializers:l})}}})]}}),ps=pr.create({name:"commands",addCommands:()=>({...c8})}),po=pr.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=d8(e.before,[e,...t]);uk(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 so){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()}}),pa=pr.create({name:"drop",addProseMirrorPlugins(){return[new s0({key:new s3("tiptapDrop"),props:{handleDrop:(e,t,n,r)=>{this.editor.emit("drop",{editor:this.editor,event:t,slice:n,moved:r})}}})]}}),pl=pr.create({name:"editable",addProseMirrorPlugins(){return[new s0({key:new s3("editable"),props:{editable:()=>this.editor.options.editable}})]}}),pc=new s3("focusEvents"),pd=pr.create({name:"focusEvents",addProseMirrorPlugins(){let{editor:e}=this;return[new s0({key:pc,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}}}})]}}),pu=pr.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:sL.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 dE()||dU()?i:r},addProseMirrorPlugins(){return[new s0({key:new s3("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=sL.atStart(t.doc).from,c=sL.atEnd(t.doc).to;if(s||o!==l||a!==c||!uA(n.doc))return;let d=n.tr,u=c9({state:n,transaction:d}),{commands:p}=new c7({editor:this.editor,state:u});if(p.clearNodes(),d.steps.length)return d}})]}}),pp=pr.create({name:"paste",addProseMirrorPlugins(){return[new s0({key:new s3("tiptapPaste"),props:{handlePaste:(e,t,n)=>{this.editor.emit("paste",{editor:this.editor,event:t,slice:n})}}})]}}),ph=pr.create({name:"tabindex",addOptions:()=>({value:void 0}),addProseMirrorPlugins(){return[new s0({key:new s3("tabindex"),props:{attributes:()=>{var e;return this.editor.isEditable||void 0!==this.options.value?{tabindex:null!=(e=this.options.value)?e:"0"}:{}}}})]}}),pf=pr.create({name:"textDirection",addOptions:()=>({direction:void 0}),addGlobalAttributes(){if(!this.options.direction)return[];let{nodeExtensions:e}=ul(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 s0({key:new s3("textDirection"),props:{attributes:()=>{let e=this.options.direction;return e?{dir:e}:{}}}})]}}),pm=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)}},pg=`.ProseMirror {
22
22
  position: relative;
23
23
  }
24
24