wiki-viewer 2.7.3 → 2.7.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 (85) 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/server/app/_global-error.html +1 -1
  5. package/.next/standalone/.next/server/app/_global-error.rsc +1 -1
  6. package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  7. package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  8. package/.next/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  9. package/.next/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  10. package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  11. package/.next/standalone/.next/server/app/_not-found.html +1 -1
  12. package/.next/standalone/.next/server/app/_not-found.rsc +1 -1
  13. package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
  14. package/.next/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  15. package/.next/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
  16. package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  17. package/.next/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  18. package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
  19. package/.next/standalone/.next/server/app/api/agent/activity/route.js.nft.json +1 -1
  20. package/.next/standalone/.next/server/app/api/agent/events/[...path]/route.js.nft.json +1 -1
  21. package/.next/standalone/.next/server/app/api/agent/files/[...path]/route.js.nft.json +1 -1
  22. package/.next/standalone/.next/server/app/api/agent/fs/file/[...path]/route.js.nft.json +1 -1
  23. package/.next/standalone/.next/server/app/api/agent/fs/ls/[[...path]]/route.js.nft.json +1 -1
  24. package/.next/standalone/.next/server/app/api/agent/fs/move/route.js.nft.json +1 -1
  25. package/.next/standalone/.next/server/app/api/agent/fs/search/route.js.nft.json +1 -1
  26. package/.next/standalone/.next/server/app/api/agent/internal/span/route.js.nft.json +1 -1
  27. package/.next/standalone/.next/server/app/api/agent/settings/route.js.nft.json +1 -1
  28. package/.next/standalone/.next/server/app/api/agent/sidecar/[...path]/route.js.nft.json +1 -1
  29. package/.next/standalone/.next/server/app/api/assets/[...path]/route.js.nft.json +1 -1
  30. package/.next/standalone/.next/server/app/api/pdf/save/route.js.nft.json +1 -1
  31. package/.next/standalone/.next/server/app/api/share/[token]/asset/route.js.nft.json +1 -1
  32. package/.next/standalone/.next/server/app/api/share/[token]/route.js.nft.json +1 -1
  33. package/.next/standalone/.next/server/app/api/share/route.js.nft.json +1 -1
  34. package/.next/standalone/.next/server/app/api/system/reveal/route.js.nft.json +1 -1
  35. package/.next/standalone/.next/server/app/api/system/set-root/route.js.nft.json +1 -1
  36. package/.next/standalone/.next/server/app/api/system/workspaces/[id]/branch/route.js.nft.json +1 -1
  37. package/.next/standalone/.next/server/app/api/system/workspaces/[id]/open/route.js.nft.json +1 -1
  38. package/.next/standalone/.next/server/app/api/system/workspaces/[id]/refresh/route.js.nft.json +1 -1
  39. package/.next/standalone/.next/server/app/api/system/workspaces/[id]/route.js.nft.json +1 -1
  40. package/.next/standalone/.next/server/app/api/system/workspaces/route.js.nft.json +1 -1
  41. package/.next/standalone/.next/server/app/api/upload/[...path]/route.js.nft.json +1 -1
  42. package/.next/standalone/.next/server/app/api/wiki/app/route.js.nft.json +1 -1
  43. package/.next/standalone/.next/server/app/api/wiki/backlinks/route.js.nft.json +1 -1
  44. package/.next/standalone/.next/server/app/api/wiki/content/route.js.nft.json +1 -1
  45. package/.next/standalone/.next/server/app/api/wiki/download/route.js.nft.json +1 -1
  46. package/.next/standalone/.next/server/app/api/wiki/file/route.js.nft.json +1 -1
  47. package/.next/standalone/.next/server/app/api/wiki/folder/route.js.nft.json +1 -1
  48. package/.next/standalone/.next/server/app/api/wiki/git-branches/route.js.nft.json +1 -1
  49. package/.next/standalone/.next/server/app/api/wiki/git-checkout/route.js.nft.json +1 -1
  50. package/.next/standalone/.next/server/app/api/wiki/git-diff/route.js.nft.json +1 -1
  51. package/.next/standalone/.next/server/app/api/wiki/git-file-info/route.js.nft.json +1 -1
  52. package/.next/standalone/.next/server/app/api/wiki/git-history/route.js.nft.json +1 -1
  53. package/.next/standalone/.next/server/app/api/wiki/git-pull/route.js.nft.json +1 -1
  54. package/.next/standalone/.next/server/app/api/wiki/move/route.js.nft.json +1 -1
  55. package/.next/standalone/.next/server/app/api/wiki/new-file/route.js.nft.json +1 -1
  56. package/.next/standalone/.next/server/app/api/wiki/outlinks/route.js.nft.json +1 -1
  57. package/.next/standalone/.next/server/app/api/wiki/page/route.js.nft.json +1 -1
  58. package/.next/standalone/.next/server/app/api/wiki/presence/route.js.nft.json +1 -1
  59. package/.next/standalone/.next/server/app/api/wiki/route.js.nft.json +1 -1
  60. package/.next/standalone/.next/server/app/api/wiki/search/route.js.nft.json +1 -1
  61. package/.next/standalone/.next/server/app/api/wiki/slugs/route.js.nft.json +1 -1
  62. package/.next/standalone/.next/server/app/api/wiki/upload/route.js.nft.json +1 -1
  63. package/.next/standalone/.next/server/app/api/wiki/watch/route.js.nft.json +1 -1
  64. package/.next/standalone/.next/server/app/index.html +1 -1
  65. package/.next/standalone/.next/server/app/index.rsc +2 -2
  66. package/.next/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
  67. package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +2 -2
  68. package/.next/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
  69. package/.next/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
  70. package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
  71. package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
  72. package/.next/standalone/.next/server/chunks/[root-of-the-server]__0gurz9a._.js +1 -1
  73. package/.next/standalone/.next/server/chunks/ssr/_0v4uz-4._.js +1 -1
  74. package/.next/standalone/.next/server/middleware-build-manifest.js +3 -3
  75. package/.next/standalone/.next/server/middleware-manifest.json +5 -5
  76. package/.next/standalone/.next/server/pages/404.html +1 -1
  77. package/.next/standalone/.next/server/pages/500.html +1 -1
  78. package/.next/standalone/.next/server/server-reference-manifest.js +1 -1
  79. package/.next/standalone/.next/server/server-reference-manifest.json +1 -1
  80. package/.next/standalone/.next/static/chunks/{0pd5k_eu2n6lx.js → 0p1blx45umac6.js} +1 -1
  81. package/.next/standalone/package.json +1 -1
  82. package/package.json +1 -1
  83. /package/.next/standalone/.next/static/{xsJTB5dwbN66j_C416RPY → FGEHouLkusE6SPcSxOC3u}/_buildManifest.js +0 -0
  84. /package/.next/standalone/.next/static/{xsJTB5dwbN66j_C416RPY → FGEHouLkusE6SPcSxOC3u}/_clientMiddlewareManifest.js +0 -0
  85. /package/.next/standalone/.next/static/{xsJTB5dwbN66j_C416RPY → FGEHouLkusE6SPcSxOC3u}/_ssgManifest.js +0 -0
@@ -14,4 +14,4 @@ TOKEN=<paste token here>
14
14
  # 3. Read snapshot
15
15
  curl -s -H "Authorization: Bearer $TOKEN" \\
16
16
  -H "X-Agent-Id: ai:claude" \\
17
- ${t}/api/agent/files/${e??"<path/to/file.md>"}`;await navigator.clipboard.writeText(n),a(!0),setTimeout(()=>a(!1),1500)},[e])}}(e??null),[m,p]=(0,H.useState)(""),h=(0,H.useRef)(null),x=window.location.origin,f=(0,H.useCallback)(()=>nc,[]),g=(0,H.useCallback)(()=>m.replace(/\$WIKI_URL/g,x),[m,x]),b=(0,H.useCallback)(()=>`npx wiki-viewer-mcp register --url ${x} --id ai:myagent --name "My Agent"`,[x]),w=(0,H.useCallback)(()=>JSON.stringify({servers:{"wiki-viewer":{command:"npx",args:["wiki-viewer-mcp"],env:{WIKI_VIEWER_URL:x,WIKI_VIEWER_TOKEN:"<token from register>",WIKI_VIEWER_AGENT_ID:"ai:myagent"}}}},null,2),[x]),y=nd(f),v=nd(g),N=nd(b),j=nd(w);return((0,H.useEffect)(()=>{if(a)return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e);function e(e){"Escape"===e.key&&n()}},[a,n]),(0,H.useEffect)(()=>{a&&h.current?.focus()},[a]),(0,H.useEffect)(()=>{if(!a)return;c();let e=setInterval(()=>void c(),1e4);return()=>clearInterval(e)},[a,c]),(0,H.useEffect)(()=>{a&&fetch("/api/agents/install").then(e=>e.json()).then(e=>{e.bootstrapPrompt&&p(e.bootstrapPrompt)}).catch(()=>void 0)},[a]),a)?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"fixed inset-0 z-40 bg-overlay backdrop-blur-[1px]",onClick:n,"aria-hidden":!0}),(0,t.jsxs)("aside",{ref:h,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,t.jsxs)("div",{className:"flex items-center justify-between border-b border-border px-4 py-3 shrink-0",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(r,{className:"h-4 w-4 text-muted-foreground"}),(0,t.jsx)("span",{className:"text-sm font-semibold",children:"AI Agent"})]}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:n,title:"Close panel (Esc)",children:(0,t.jsx)(K.X,{className:"h-3.5 w-3.5"})})]}),(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto space-y-5 px-4 py-4",children:[(0,t.jsxs)("section",{className:"rounded-md border border-border bg-muted/30 p-3",children:[(0,t.jsx)("p",{className:"text-sm font-medium text-foreground",children:"Work with this wiki using AI"}),(0,t.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,t.jsx)("span",{className:"font-medium text-foreground/80",children:"Agents"})," below before it gets access."]})]}),(0,t.jsxs)("section",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,t.jsx)("p",{className:"text-xs font-semibold text-foreground",children:"Co-write docs with you"}),(0,t.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Edits arrive as suggestions with comments you accept or revert. No MCP needed."}),(0,t.jsx)(W.Button,{size:"sm",variant:"outline",className:"h-7 w-full text-xs gap-1.5",onClick:()=>void v.copy(),disabled:!m,children:v.copied?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(s.Check,{className:"h-3.5 w-3.5 text-green-500"})," Copied!"]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(o.Copy,{className:"h-3.5 w-3.5"})," Paste into any chatbot"]})}),(0,t.jsxs)("p",{className:"text-[10px] text-muted-foreground/50 pt-1",children:["Or install once so it sticks"," ",(0,t.jsx)("span",{className:"text-muted-foreground/40",children:"· Claude, OpenCode"}),":"]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("code",{className:"flex-1 text-[10px] font-mono text-foreground/80 truncate bg-muted rounded px-1 py-0.5",children:nc}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0",title:"Copy this command",onClick:()=>void y.copy(),children:y.copied?(0,t.jsx)(s.Check,{className:"h-3.5 w-3.5 text-green-500"}):(0,t.jsx)(o.Copy,{className:"h-3.5 w-3.5"})})]})]}),(0,t.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,t.jsxs)("p",{className:"text-xs font-semibold text-foreground",children:["Edit files directly"," ",(0,t.jsx)("span",{className:"font-normal text-muted-foreground/60",children:"· Claude Code, Cursor, Codex"})]}),(0,t.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Native read / search / edit tools over MCP. Run to request access:"}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("code",{className:"flex-1 text-[10px] font-mono text-foreground/80 truncate bg-muted rounded px-1 py-0.5",children:b()}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0",title:"Copy this command",onClick:()=>void N.copy(),children:N.copied?(0,t.jsx)(s.Check,{className:"h-3.5 w-3.5 text-green-500"}):(0,t.jsx)(o.Copy,{className:"h-3.5 w-3.5"})})]}),(0,t.jsxs)("p",{className:"text-[10px] text-muted-foreground/50",children:["Approve in ",(0,t.jsx)("span",{className:"font-medium text-foreground/70",children:"Agents"}),", then add to your tool:"]}),(0,t.jsx)(W.Button,{size:"sm",variant:"outline",className:"h-7 w-full text-xs gap-1.5",onClick:()=>void j.copy(),children:j.copied?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(s.Check,{className:"h-3.5 w-3.5 text-green-500"})," Copied!"]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(o.Copy,{className:"h-3.5 w-3.5"})," Copy config (mcp.json)"]})})]}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[(0,t.jsx)("span",{className:"text-[10px] text-muted-foreground/50",children:"For developers:"}),(0,t.jsxs)("button",{type:"button",onClick:()=>void u(),className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[d?(0,t.jsx)(s.Check,{className:"h-3 w-3 text-green-500"}):(0,t.jsx)(o.Copy,{className:"h-3 w-3"})," curl example"]}),(0,t.jsxs)("a",{href:"/api/agents/skill",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[(0,t.jsx)(en.ExternalLink,{className:"h-3 w-3"})," skill"]}),(0,t.jsxs)("a",{href:"/api/agents/install",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[(0,t.jsx)(en.ExternalLink,{className:"h-3 w-3"})," install JSON"]})]})]}),(0,t.jsx)(na,{}),(0,t.jsxs)("section",{className:"space-y-2",children:[(0,t.jsxs)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:["Active Connections"," ",(0,t.jsx)("span",{className:"normal-case font-normal text-muted-foreground/50",children:"(last 5 min)"})]}),(0,t.jsx)("div",{className:"rounded-md border border-border bg-muted/40 p-3",children:0===l.length?(0,t.jsxs)("p",{className:"text-xs text-muted-foreground/60 flex items-center gap-1.5",children:[(0,t.jsx)(a5,{className:"h-3.5 w-3.5"}),"No recent activity"]}):(0,t.jsx)("ul",{className:"space-y-1.5",children:l.map(e=>(0,t.jsxs)("li",{className:"flex items-center justify-between text-xs",children:[(0,t.jsx)("span",{className:"font-mono text-foreground/80 truncate",children:e.by}),(0,t.jsxs)("span",{className:"text-muted-foreground shrink-0",children:[e.opCount," op",1!==e.opCount?"s":""]})]},e.by))})})]}),(0,t.jsxs)("section",{className:"space-y-2",children:[(0,t.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Recent Activity"}),(0,t.jsx)("div",{className:"rounded-md border border-border bg-muted/40 px-3 py-2 max-h-72 overflow-y-auto",children:(0,t.jsx)(no,{activity:i})})]}),(0,t.jsx)("section",{children:(0,t.jsx)("a",{href:"/docs/agent-collab-plan.md",target:"_blank",rel:"noreferrer",className:"text-xs text-primary underline hover:no-underline",children:"Agent collaboration docs →"})})]})]})]}):null}var nm=e.i(580330),np=e.i(877031),nh=/[\\\/_+.#"@\[\(\{&]/,nx=/[\\\/_+.#"@\[\(\{&]/g,nf=/[\s-]/,ng=/[\s-]/g;function nb(e){return e.toLowerCase().replace(ng," ")}var nw=e.i(750110),ny=e.i(433616),nv='[cmdk-group=""]',nN='[cmdk-group-items=""]',nj='[cmdk-item=""]',nk=`${nj}:not([aria-disabled="true"])`,n_="cmdk-item-select",nC="data-value",nE=(e,t,a)=>{var n;return n=e,function e(t,a,n,r,s,i,l){if(i===a.length)return s===t.length?1:.99;var o=`${s},${i}`;if(void 0!==l[o])return l[o];for(var c,d,u,m,p=r.charAt(i),h=n.indexOf(p,s),x=0;h>=0;)(c=e(t,a,n,r,h+1,i+1,l))>x&&(h===s?c*=1:nh.test(t.charAt(h-1))?(c*=.8,(u=t.slice(s,h-1).match(nx))&&s>0&&(c*=Math.pow(.999,u.length))):nf.test(t.charAt(h-1))?(c*=.9,(m=t.slice(s,h-1).match(ng))&&s>0&&(c*=Math.pow(.999,m.length))):(c*=.17,s>0&&(c*=Math.pow(.999,h-s))),t.charAt(h)!==a.charAt(i)&&(c*=.9999)),(c<.1&&n.charAt(h-1)===r.charAt(i+1)||r.charAt(i+1)===r.charAt(i)&&n.charAt(h-1)!==r.charAt(i))&&.1*(d=e(t,a,n,r,h+1,i+2,l))>c&&(c=.1*d),c>x&&(x=c),h=n.indexOf(p,h+1);return l[o]=x,x}(n=a&&a.length>0?`${n+" "+a.join(" ")}`:n,t,nb(n),nb(t),0,0,{})},nS=H.createContext(void 0),nM=H.createContext(void 0),nD=H.createContext(void 0),nA=H.forwardRef((e,t)=>{let a=n$(()=>{var t,a;return{search:"",value:null!=(a=null!=(t=e.value)?t:e.defaultValue)?a:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),n=n$(()=>new Set),r=n$(()=>new Map),s=n$(()=>new Map),i=n$(()=>new Set),l=nB(e),{label:o,children:c,value:d,onValueChange:u,filter:m,shouldFilter:p,loop:h,disablePointerSelection:x=!1,vimBindings:f=!0,...g}=e,b=(0,ny.useId)(),w=(0,ny.useId)(),y=(0,ny.useId)(),v=H.useRef(null),N=nK();nz(()=>{if(void 0!==d){let e=d.trim();a.current.value=e,j.emit()}},[d]),nz(()=>{N(6,M)},[]);let j=H.useMemo(()=>({subscribe:e=>(i.current.add(e),()=>i.current.delete(e)),snapshot:()=>a.current,setState:(e,t,n)=>{var r,s,i,o;if(!Object.is(a.current[e],t)){if(a.current[e]=t,"search"===e)S(),C(),N(1,E);else if("value"===e){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let e=document.getElementById(y);e?e.focus():null==(r=document.getElementById(b))||r.focus()}if(N(7,()=>{var e;a.current.selectedItemId=null==(e=D())?void 0:e.id,j.emit()}),n||N(5,M),(null==(s=l.current)?void 0:s.value)!==void 0){null==(o=(i=l.current).onValueChange)||o.call(i,null!=t?t:"");return}}j.emit()}},emit:()=>{i.current.forEach(e=>e())}}),[]),k=H.useMemo(()=>({value:(e,t,n)=>{var r;t!==(null==(r=s.current.get(e))?void 0:r.value)&&(s.current.set(e,{value:t,keywords:n}),a.current.filtered.items.set(e,_(t,n)),N(2,()=>{C(),j.emit()}))},item:(e,t)=>(n.current.add(e),t&&(r.current.has(t)?r.current.get(t).add(e):r.current.set(t,new Set([e]))),N(3,()=>{S(),C(),a.current.value||E(),j.emit()}),()=>{s.current.delete(e),n.current.delete(e),a.current.filtered.items.delete(e);let t=D();N(4,()=>{S(),(null==t?void 0:t.getAttribute("id"))===e&&E(),j.emit()})}),group:e=>(r.current.has(e)||r.current.set(e,new Set),()=>{s.current.delete(e),r.current.delete(e)}),filter:()=>l.current.shouldFilter,label:o||e["aria-label"],getDisablePointerSelection:()=>l.current.disablePointerSelection,listId:b,inputId:y,labelId:w,listInnerRef:v}),[]);function _(e,t){var n,r;let s=null!=(r=null==(n=l.current)?void 0:n.filter)?r:nE;return e?s(e,a.current.search,t):0}function C(){if(!a.current.search||!1===l.current.shouldFilter)return;let e=a.current.filtered.items,t=[];a.current.filtered.groups.forEach(a=>{let n=r.current.get(a),s=0;n.forEach(t=>{s=Math.max(e.get(t),s)}),t.push([a,s])});let n=v.current;A().sort((t,a)=>{var n,r;let s=t.getAttribute("id"),i=a.getAttribute("id");return(null!=(n=e.get(i))?n:0)-(null!=(r=e.get(s))?r:0)}).forEach(e=>{let t=e.closest(nN);t?t.appendChild(e.parentElement===t?e:e.closest(`${nN} > *`)):n.appendChild(e.parentElement===n?e:e.closest(`${nN} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{var t;let a=null==(t=v.current)?void 0:t.querySelector(`${nv}[${nC}="${encodeURIComponent(e[0])}"]`);null==a||a.parentElement.appendChild(a)})}function E(){let e=A().find(e=>"true"!==e.getAttribute("aria-disabled")),t=null==e?void 0:e.getAttribute(nC);j.setState("value",t||void 0)}function S(){var e,t,i,o;if(!a.current.search||!1===l.current.shouldFilter){a.current.filtered.count=n.current.size;return}a.current.filtered.groups=new Set;let c=0;for(let r of n.current){let n=_(null!=(t=null==(e=s.current.get(r))?void 0:e.value)?t:"",null!=(o=null==(i=s.current.get(r))?void 0:i.keywords)?o:[]);a.current.filtered.items.set(r,n),n>0&&c++}for(let[e,t]of r.current)for(let n of t)if(a.current.filtered.items.get(n)>0){a.current.filtered.groups.add(e);break}a.current.filtered.count=c}function M(){var e,t,a;let n=D();n&&((null==(e=n.parentElement)?void 0:e.firstChild)===n&&(null==(a=null==(t=n.closest(nv))?void 0:t.querySelector('[cmdk-group-heading=""]'))||a.scrollIntoView({block:"nearest"})),n.scrollIntoView({block:"nearest"}))}function D(){var e;return null==(e=v.current)?void 0:e.querySelector(`${nj}[aria-selected="true"]`)}function A(){var e;return Array.from((null==(e=v.current)?void 0:e.querySelectorAll(nk))||[])}function O(e){let t=A()[e];t&&j.setState("value",t.getAttribute(nC))}function T(e){var t;let a=D(),n=A(),r=n.findIndex(e=>e===a),s=n[r+e];null!=(t=l.current)&&t.loop&&(s=r+e<0?n[n.length-1]:r+e===n.length?n[0]:n[r+e]),s&&j.setState("value",s.getAttribute(nC))}function I(e){let t=D(),a=null==t?void 0:t.closest(nv),n;for(;a&&!n;)n=null==(a=e>0?function(e,t){let a=e.nextElementSibling;for(;a;){if(a.matches(t))return a;a=a.nextElementSibling}}(a,nv):function(e,t){let a=e.previousElementSibling;for(;a;){if(a.matches(t))return a;a=a.previousElementSibling}}(a,nv))?void 0:a.querySelector(nk);n?j.setState("value",n.getAttribute(nC)):T(e)}let R=()=>O(A().length-1),F=e=>{e.preventDefault(),e.metaKey?R():e.altKey?I(1):T(1)},L=e=>{e.preventDefault(),e.metaKey?O(0):e.altKey?I(-1):T(-1)};return H.createElement(nw.Primitive.div,{ref:t,tabIndex:-1,...g,"cmdk-root":"",onKeyDown:e=>{var t;null==(t=g.onKeyDown)||t.call(g,e);let a=e.nativeEvent.isComposing||229===e.keyCode;if(!(e.defaultPrevented||a))switch(e.key){case"n":case"j":f&&e.ctrlKey&&F(e);break;case"ArrowDown":F(e);break;case"p":case"k":f&&e.ctrlKey&&L(e);break;case"ArrowUp":L(e);break;case"Home":e.preventDefault(),O(0);break;case"End":e.preventDefault(),R();break;case"Enter":{e.preventDefault();let t=D();if(t){let e=new Event(n_);t.dispatchEvent(e)}}}}},H.createElement("label",{"cmdk-label":"",htmlFor:k.inputId,id:k.labelId,style:nW},o),nH(e,e=>H.createElement(nM.Provider,{value:j},H.createElement(nS.Provider,{value:k},e))))}),nO=H.forwardRef((e,t)=>{var a,n;let r=(0,ny.useId)(),s=H.useRef(null),i=H.useContext(nD),l=H.useContext(nS),o=nB(e),c=null!=(n=null==(a=o.current)?void 0:a.forceMount)?n:null==i?void 0:i.forceMount;nz(()=>{if(!c)return l.item(r,null==i?void 0:i.id)},[c]);let d=nq(r,s,[e.value,e.children,s],e.keywords),u=H.useContext(nM),m=nU(e=>e.value&&e.value===d.current),p=nU(e=>!!c||!1===l.filter()||!e.search||e.filtered.items.get(r)>0);function h(){var e,t;x(),null==(t=(e=o.current).onSelect)||t.call(e,d.current)}function x(){u.setState("value",d.current,!0)}if(H.useEffect(()=>{let t=s.current;if(!(!t||e.disabled))return t.addEventListener(n_,h),()=>t.removeEventListener(n_,h)},[p,e.onSelect,e.disabled]),!p)return null;let{disabled:f,value:g,onSelect:b,forceMount:w,keywords:y,...v}=e;return H.createElement(nw.Primitive.div,{ref:(0,as.composeRefs)(s,t),...v,id:r,"cmdk-item":"",role:"option","aria-disabled":!!f,"aria-selected":!!m,"data-disabled":!!f,"data-selected":!!m,onPointerMove:f||l.getDisablePointerSelection()?void 0:x,onClick:f?void 0:h},e.children)}),nT=H.forwardRef((e,t)=>{let{heading:a,children:n,forceMount:r,...s}=e,i=(0,ny.useId)(),l=H.useRef(null),o=H.useRef(null),c=(0,ny.useId)(),d=H.useContext(nS),u=nU(e=>!!r||!1===d.filter()||!e.search||e.filtered.groups.has(i));nz(()=>d.group(i),[]),nq(i,l,[e.value,e.heading,o]);let m=H.useMemo(()=>({id:i,forceMount:r}),[r]);return H.createElement(nw.Primitive.div,{ref:(0,as.composeRefs)(l,t),...s,"cmdk-group":"",role:"presentation",hidden:!u||void 0},a&&H.createElement("div",{ref:o,"cmdk-group-heading":"","aria-hidden":!0,id:c},a),nH(e,e=>H.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":a?c:void 0},H.createElement(nD.Provider,{value:m},e))))}),nI=H.forwardRef((e,t)=>{let{alwaysRender:a,...n}=e,r=H.useRef(null),s=nU(e=>!e.search);return a||s?H.createElement(nw.Primitive.div,{ref:(0,as.composeRefs)(r,t),...n,"cmdk-separator":"",role:"separator"}):null}),nR=H.forwardRef((e,t)=>{let{onValueChange:a,...n}=e,r=null!=e.value,s=H.useContext(nM),i=nU(e=>e.search),l=nU(e=>e.selectedItemId),o=H.useContext(nS);return H.useEffect(()=>{null!=e.value&&s.setState("search",e.value)},[e.value]),H.createElement(nw.Primitive.input,{ref:t,...n,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":o.listId,"aria-labelledby":o.labelId,"aria-activedescendant":l,id:o.inputId,type:"text",value:r?e.value:i,onChange:e=>{r||s.setState("search",e.target.value),null==a||a(e.target.value)}})}),nF=H.forwardRef((e,t)=>{let{children:a,label:n="Suggestions",...r}=e,s=H.useRef(null),i=H.useRef(null),l=nU(e=>e.selectedItemId),o=H.useContext(nS);return H.useEffect(()=>{if(i.current&&s.current){let e=i.current,t=s.current,a,n=new ResizeObserver(()=>{a=requestAnimationFrame(()=>{let a=e.offsetHeight;t.style.setProperty("--cmdk-list-height",a.toFixed(1)+"px")})});return n.observe(e),()=>{cancelAnimationFrame(a),n.unobserve(e)}}},[]),H.createElement(nw.Primitive.div,{ref:(0,as.composeRefs)(s,t),...r,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":l,"aria-label":n,id:o.listId},nH(e,e=>H.createElement("div",{ref:(0,as.composeRefs)(i,o.listInnerRef),"cmdk-list-sizer":""},e)))}),nL=H.forwardRef((e,t)=>{let{open:a,onOpenChange:n,overlayClassName:r,contentClassName:s,container:i,...l}=e;return H.createElement(tW.Root,{open:a,onOpenChange:n},H.createElement(tW.Portal,{container:i},H.createElement(tW.Overlay,{"cmdk-overlay":"",className:r}),H.createElement(tW.Content,{"aria-label":e.label,"cmdk-dialog":"",className:s},H.createElement(nA,{ref:t,...l}))))}),nP=Object.assign(nA,{List:nF,Item:nO,Input:nR,Group:nT,Separator:nI,Dialog:nL,Empty:H.forwardRef((e,t)=>nU(e=>0===e.filtered.count)?H.createElement(nw.Primitive.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),Loading:H.forwardRef((e,t)=>{let{progress:a,children:n,label:r="Loading...",...s}=e;return H.createElement(nw.Primitive.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":a,"aria-valuemin":0,"aria-valuemax":100,"aria-label":r},nH(e,e=>H.createElement("div",{"aria-hidden":!0},e)))})});function nB(e){let t=H.useRef(e);return nz(()=>{t.current=e}),t}var nz="u"<typeof window?H.useEffect:H.useLayoutEffect;function n$(e){let t=H.useRef();return void 0===t.current&&(t.current=e()),t}function nU(e){let t=H.useContext(nM),a=()=>e(t.snapshot());return H.useSyncExternalStore(t.subscribe,a,a)}function nq(e,t,a,n=[]){let r=H.useRef(),s=H.useContext(nS);return nz(()=>{var i;let l=(()=>{var e;for(let t of a){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():r.current}})(),o=n.map(e=>e.trim());s.value(e,l,o),null==(i=t.current)||i.setAttribute(nC,l),r.current=l}),r}var nK=()=>{let[e,t]=H.useState(),a=n$(()=>new Map);return nz(()=>{a.current.forEach(e=>e()),a.current=new Map},[e]),(e,n)=>{a.current.set(e,n),t({})}};function nH({asChild:e,children:t},a){let n;return e&&H.isValidElement(t)?H.cloneElement("function"==typeof(n=t.type)?n(t.props):"render"in n?n.render(t.props):t,{ref:t.ref},a(t.props.children)):a(t)}var nW={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};let nG=(0,n.default)("search",[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]),nV=H.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nP,{ref:n,className:(0,tf.cn)("flex h-full w-full flex-col overflow-hidden rounded-sm bg-popover text-popover-foreground",e),...a}));function nZ({children:e,shouldFilter:a,...n}){return(0,t.jsx)(G.Dialog,{...n,children:(0,t.jsxs)(G.DialogContent,{className:"overflow-hidden p-0 shadow-golden max-w-lg",children:[(0,t.jsx)(G.DialogTitle,{className:"sr-only",children:"Search"}),(0,t.jsx)(nV,{shouldFilter:a,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})]})})}nV.displayName=nP.displayName;let nX=H.forwardRef(({className:e,...a},n)=>(0,t.jsxs)("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[(0,t.jsx)(nG,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),(0,t.jsx)(nP.Input,{ref:n,className:(0,tf.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),...a})]}));nX.displayName=nP.Input.displayName;let nJ=H.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nP.List,{ref:n,className:(0,tf.cn)("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...a}));nJ.displayName=nP.List.displayName;let nQ=H.forwardRef((e,a)=>(0,t.jsx)(nP.Empty,{ref:a,className:"py-6 text-center text-sm text-muted-foreground",...e}));nQ.displayName=nP.Empty.displayName;let nY=H.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nP.Group,{ref:n,className:(0,tf.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),...a}));nY.displayName=nP.Group.displayName;let n0=H.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nP.Separator,{ref:n,className:(0,tf.cn)("-mx-1 h-px bg-border",e),...a}));n0.displayName=nP.Separator.displayName;let n1=H.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nP.Item,{ref:n,className:(0,tf.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),...a}));n1.displayName=nP.Item.displayName;let n2=null,n5=null,n3=(0,t1.create)(e=>({query:"",results:[],loading:!1,truncated:!1,open:!1,setQuery:t=>e({query:t}),setOpen:t=>e({open:t}),clear:()=>{n5&&clearTimeout(n5),n2?.abort(),e({query:"",results:[],loading:!1,truncated:!1})},search:t=>(n5&&clearTimeout(n5),t.trim())?(e({loading:!0}),new Promise(a=>{n5=setTimeout(()=>{n4(e,t).finally(a)},150)})):(n2?.abort(),e({results:[],loading:!1,truncated:!1}),Promise.resolve())}));async function n4(e,t){n2?.abort();let a=new AbortController;n2=a;try{let n=await (0,X.wsFetch)("/api/wiki/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t,limit:30}),signal:a.signal});if(!n.ok)return void e({results:[],loading:!1,truncated:!1});let r=await n.json();if(a.signal.aborted)return;e({results:r.matches??[],truncated:!!r.truncated,loading:!1})}catch(t){"AbortError"!==t.name&&e({loading:!1})}}var n9=e.i(395624);function n7({html:e}){let a=function(e){let t,a=[],n=/<mark>([\s\S]*?)<\/mark>/g,r=0;for(;null!==(t=n.exec(e));)t.index>r&&a.push({text:e.slice(r,t.index),mark:!1}),a.push({text:t[1]??"",mark:!0}),r=t.index+t[0].length;return r<e.length&&a.push({text:e.slice(r),mark:!1}),a}(e);return(0,t.jsx)(t.Fragment,{children:a.map((e,a)=>e.mark?(0,t.jsx)("mark",{className:"bg-yellow-200 dark:bg-yellow-700 rounded-[2px] px-[1px]",children:e.text},a):(0,t.jsx)("span",{children:e.text},a))})}function n6({onOpenFile:e,recents:a=[],onToggleSidebar:n=()=>void 0,onNewFile:s=()=>void 0,onCopyPath:i=()=>void 0}){let l=n3(e=>e.open),c=n3(e=>e.setOpen),d=n3(e=>e.query),u=n3(e=>e.setQuery),p=n3(e=>e.results),h=n3(e=>e.loading),x=n3(e=>e.truncated),f=n3(e=>e.search),{resolvedTheme:g,setTheme:b}=(0,tH.useTheme)(),w=(0,a3.useAIPanelStore)(e=>e.toggle),y=(0,n9.useViewWidthStore)(e=>e.width),v=(0,n9.useViewWidthStore)(e=>e.cycle),N=d.trimStart(),j=""===N||N.startsWith(">"),k=""===N&&a.length>0,_=j?"":d;function C(e){e(),c(!1),u("")}(0,H.useEffect)(()=>{function e(e){(e.metaKey||e.ctrlKey)&&"k"===e.key.toLowerCase()&&(e.preventDefault(),c(!l))}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[l,c]),(0,H.useEffect)(()=>{if(!l||j)return;let e=setTimeout(()=>{f(_)},120);return()=>clearTimeout(e)},[_,j,l,f]);let E=(n9.VIEW_WIDTH_ORDER.indexOf(y)+1)%n9.VIEW_WIDTH_ORDER.length,M=n9.VIEW_WIDTH_LABEL[n9.VIEW_WIDTH_ORDER[E]];return(0,t.jsxs)(nZ,{open:l,onOpenChange:e=>{c(e),e||u("")},shouldFilter:!1,children:[(0,t.jsx)(nX,{placeholder:"Search files… ( > for actions )",value:d,onValueChange:u}),(0,t.jsxs)(nJ,{children:[k&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(nY,{heading:"Recent",children:a.map(a=>(0,t.jsxs)(n1,{value:`recent:${a.path}`,onSelect:()=>{e(a.path),c(!1),u("")},children:[(0,t.jsx)(aa,{className:"mr-2 h-4 w-4"}),(0,t.jsxs)("div",{className:"flex min-w-0 flex-col gap-0.5",children:[(0,t.jsx)("span",{className:"truncate font-medium",children:a.name}),(0,t.jsx)("span",{className:"truncate text-xs text-muted-foreground",children:a.path})]})]},a.path))}),(0,t.jsx)(n0,{})]}),j&&(0,t.jsxs)(nY,{heading:"Actions",children:[(0,t.jsxs)(n1,{value:"toggle-dark-mode",onSelect:()=>C(()=>b("dark"===g?"light":"dark")),children:["dark"===g?(0,t.jsx)(B.Sun,{className:"mr-2 h-4 w-4"}):(0,t.jsx)(S.Moon,{className:"mr-2 h-4 w-4"}),"dark"===g?"Switch to light mode":"Switch to dark mode"]}),(0,t.jsxs)(n1,{value:"toggle-ai-panel",onSelect:()=>C(w),children:[(0,t.jsx)(r,{className:"mr-2 h-4 w-4"}),"Toggle AI panel"]}),(0,t.jsxs)(n1,{value:"toggle-sidebar",onSelect:()=>C(n),children:[(0,t.jsx)(np.PanelLeft,{className:"mr-2 h-4 w-4"}),"Toggle sidebar"]}),(0,t.jsxs)(n1,{value:"new-file",onSelect:()=>C(s),children:[(0,t.jsx)(m.FilePlus,{className:"mr-2 h-4 w-4"}),"New file"]}),(0,t.jsxs)(n1,{value:"copy-path",onSelect:()=>C(i),children:[(0,t.jsx)(o.Copy,{className:"mr-2 h-4 w-4"}),"Copy current file path"]}),(0,t.jsxs)(n1,{value:"cycle-view-width",onSelect:()=>C(v),children:[(0,t.jsx)(nm.AlignCenter,{className:"mr-2 h-4 w-4"}),(0,t.jsxs)("span",{children:["Change view width"," ",(0,t.jsxs)("span",{className:"text-muted-foreground",children:["(",n9.VIEW_WIDTH_LABEL[y]," → ",M,")"]})]})]})]}),!j&&(0,t.jsxs)(t.Fragment,{children:[h&&(0,t.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:"Searching…"}),!h&&""!==_.trim()&&0===p.length&&(0,t.jsx)(nQ,{children:"No matches."}),p.length>0&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n0,{}),(0,t.jsx)(nY,{heading:x?"Top results (refine query for more)":"Results",children:p.map(a=>(0,t.jsx)(n1,{value:a.path,onSelect:()=>{e(a.path),c(!1),u("")},children:(0,t.jsxs)("div",{className:"flex min-w-0 flex-col gap-0.5",children:[(0,t.jsx)("span",{className:"truncate font-mono text-xs",children:a.path}),a.snippet&&(0,t.jsx)("span",{className:"truncate text-xs text-muted-foreground",children:(0,t.jsx)(n7,{html:a.snippet})})]})},a.path))})]})]})]})]})}function n8({onOpenFile:e}){let a=n3(e=>e.query),n=n3(e=>e.setQuery),r=n3(e=>e.results),s=n3(e=>e.loading),i=n3(e=>e.search),l=n3(e=>e.clear),[o,c]=(0,H.useState)(0),d=(0,H.useRef)(null);function u(t){let a=r[t];a&&(e(a.path),l())}return(0,H.useEffect)(()=>{c(0)},[r]),(0,H.useEffect)(()=>{let e=d.current?.querySelector(`[data-idx="${o}"]`);e?.scrollIntoView({block:"nearest"})},[o]),(0,t.jsxs)("div",{className:"flex flex-col gap-1 px-2 py-1.5",children:[(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)(nG,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 opacity-50"}),(0,t.jsx)("input",{type:"text",className:"w-full rounded-sm border bg-transparent py-1 pl-7 pr-2 text-xs outline-none focus:ring-1 focus:ring-ring",placeholder:"Search… (⌘K)",value:a,onChange:e=>{n(e.target.value),i(e.target.value)},onKeyDown:e=>{"Escape"===e.key?l():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(o)))}})]}),""!==a.trim()&&(0,t.jsxs)("div",{ref:d,className:"max-h-64 overflow-y-auto rounded-sm border bg-popover",children:[s&&(0,t.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"Searching…"}),!s&&0===r.length&&(0,t.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"No matches"}),r.map((e,a)=>(0,t.jsxs)("button",{type:"button","data-idx":a,onClick:()=>u(a),onMouseEnter:()=>c(a),className:`block w-full px-2 py-1 text-left ${a===o?"bg-accent":"hover:bg-accent"}`,children:[(0,t.jsx)("div",{className:"truncate font-mono text-xs",children:e.path}),e.snippet&&(0,t.jsx)("div",{className:"truncate text-[10px] text-muted-foreground",children:(0,t.jsx)(n7,{html:e.snippet})})]},e.path))]})]})}let re="wiki-sidebar-width";function rt(e){return Number.isNaN(e)?288:Math.min(600,Math.max(200,Math.round(e)))}let ra=(0,t1.create)(e=>({width:function(){let e=localStorage.getItem(re);if(e){let t=Number.parseInt(e,10);if(!Number.isNaN(t))return rt(t)}return 288}(),setWidth:t=>{let a=rt(t);localStorage.setItem(re,String(a)),e({width:a})}}));var rn=e.i(246542);let rr="wiki-show-hidden",rs=(0,t1.create)((e,t)=>({showHidden:"1"===localStorage.getItem(rr),toggle:()=>{let a=!t().showHidden;a?localStorage.setItem(rr,"1"):localStorage.removeItem(rr),e({showHidden:a})}})),ri="wiki-humanize-names",rl=(0,t1.create)((e,t)=>({humanize:"1"===localStorage.getItem(ri),toggle:()=>{let a=!t().humanize;a?localStorage.setItem(ri,"1"):localStorage.removeItem(ri),e({humanize:a})}}));function ro(e){let t=e.lastIndexOf("."),a=t>0&&t<e.length-1,n=a?e.slice(0,t):e,r=a?e.slice(t):"",s=n.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));return s.length?s.join(" ")+r:e}let rc=(0,tb.default)(()=>e.A(810497).then(e=>e.PdfViewer),{loadableGenerated:{modules:[904378]},ssr:!1});function rd(e){let t=new Date(e).getTime();if(!Number.isFinite(t))return"";let a=Math.floor(Math.max(0,Date.now()-t)/1e3);if(a<60)return"just now";let n=Math.floor(a/60);if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}let ru=new Set(["image","media","pdf","fallback","app","node-app","html"]);function rm(e){return e.split(".").pop()?.toLowerCase()??""}function rp(e,t){if("node-app"===t)return"node-app";if("app"===t)return"app";if("dir"===t)return"fallback";let a=e.split("/").pop()??e;if(a.startsWith(".")&&-1===a.indexOf(".",1))return"source";let n=rm(e);return n?["md","markdown"].includes(n)?"editor":"txt"===n?"text":["csv","tsv"].includes(n)?"csv":"pdf"===n?"pdf":["mmd","mermaid"].includes(n)?"mermaid":"ipynb"===n?"notebook":["png","jpg","jpeg","gif","webp","svg","avif","ico","bmp"].includes(n)?"image":["mp4","webm","mov","m4v","mp3","wav","ogg","m4a","aac"].includes(n)?"media":"docx"===n?"docx":["xlsx","xlsm"].includes(n)?"xlsx":"pptx"===n?"pptx":"html"===n?"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(n),"source"):"source"}let rh=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 rx(e){let t=rp(e,"file");return"editor"===t||"text"===t||rh.has(rm(e))}function rf(e){return["md","markdown"].includes(rm(e))}function rg(e){return"image"===rp(e,"file")}function rb(e){return"html"===rp(e,"file")}async function rw(e){let t=await (0,X.wsFetch)(`/api/wiki?dir=${encodeURIComponent(e)}`);return t.ok?(await t.json()).entries.map(t=>({name:t.name,path:e?`${e}/${t.name}`:t.name,type:t.type,size:t.size,modifiedAt:t.modifiedAt,expanded:!1,git:t.git})):[]}let ry=new Map,rv=new Map;async function rN(e){let t=ry.get(e);if(t)return ry.delete(e),t;let a=rv.get(e);if(a){let t=await a;return ry.delete(e),t}return null}function rj(e,t,a){return e.map(e=>e.path===t?a(e):e.children?{...e,children:rj(e.children,t,a)}:e)}let rk={contentVisibility:"auto",containIntrinsicSize:"auto 32px"};function r_({node:e,ctx:a,isPinned:n,activeWorkspaceId:r}){return(0,t.jsxs)(aV,{className:"w-48",children:[(0,t.jsxs)(aZ,{onSelect:()=>a.copyPath(e.path),children:[(0,t.jsx)(o.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),rf(e.name)&&(0,t.jsxs)(aZ,{onSelect:()=>a.copyWikiLink(e.name),children:[(0,t.jsx)(p.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,t.jsxs)(aZ,{onSelect:()=>a.copyUrl(e.path),children:[(0,t.jsx)(k.Link,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),"file"===e.type&&rx(e.name)&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(aZ,{onSelect:()=>a.copyRawContent(e.path),children:[(0,t.jsx)(p.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,t.jsxs)(aZ,{onSelect:()=>a.copyFormattedContent(e.path,e.name),children:[(0,t.jsx)(p.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),(0,t.jsx)(aX,{}),"dir"===e.type&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(aZ,{onSelect:()=>{e.expanded||a.toggleFolder(e),a.setNewFileParent(e.path),a.setNewFileName(""),a.setFileCreateError(null)},children:[(0,t.jsx)(m.FilePlus,{className:"mr-2 h-3.5 w-3.5"}),"New file here"]}),(0,t.jsxs)(aZ,{onSelect:()=>a.triggerUpload(e.path),children:[(0,t.jsx)(q.Upload,{className:"mr-2 h-3.5 w-3.5"}),"Upload here"]}),(0,t.jsxs)(aZ,{onSelect:()=>{a.setNewFolderParent(e.path),a.setNewFolderName(""),a.setFolderError(null)},children:[(0,t.jsx)(f,{className:"mr-2 h-3.5 w-3.5"}),"New subfolder"]}),(0,t.jsx)(aX,{})]}),(0,t.jsxs)(aZ,{onSelect:()=>a.handleDownload(e),children:[(0,t.jsx)(c.Download,{className:"mr-2 h-3.5 w-3.5"}),"file"===e.type?"Download":"Download as zip"]}),(0,t.jsxs)(aZ,{onSelect:()=>a.togglePin(e,r),children:[(0,t.jsx)(I,{className:(0,tf.cn)("mr-2 h-3.5 w-3.5",n&&"fill-current text-amber-400")}),n?"Unpin":"Pin to top"]}),(0,t.jsx)(aX,{}),(0,t.jsxs)(aZ,{className:"text-destructive focus:text-destructive",onSelect:()=>{a.setDeletingPath(e.path),a.setDeletingIsDir("file"!==e.type)},children:[(0,t.jsx)(U.Trash2,{className:"mr-2 h-3.5 w-3.5"}),"Delete"]})]})}function rC({name:e,type:a}){let n="h-3.5 w-3.5 shrink-0";return"dir"===a?(0,t.jsx)(h.Folder,{className:(0,tf.cn)(n,"text-warning")}):"app"===a?(0,t.jsx)(y.Globe,{className:(0,tf.cn)(n,"text-foreground/70")}):"node-app"===a?(0,t.jsx)(z,{className:(0,tf.cn)(n,"text-emerald-500")}):rb(e)?(0,t.jsx)(y.Globe,{className:(0,tf.cn)(n,"text-foreground/60")}):rg(e)?(0,t.jsx)(j.Image,{className:(0,tf.cn)(n,"text-sunshine-700")}):rx(e)?(0,t.jsx)(p.FileText,{className:(0,tf.cn)(n,"text-foreground/70")}):(0,t.jsx)(u.File,{className:(0,tf.cn)(n,"text-foreground/60")})}let rE=(0,H.memo)(function({node:e,depth:a,ctx:n,isMobile:r,activeWorkspaceId:s,sidebarScrollRef:i,isActive:d,isDragOver:b,isPinned:w,isAgentActive:v,isPulling:N,branchOpen:C,branchPos:S,branches:M,branchLoading:D,checkingOut:A,onHoverEnter:O,onHoverLeave:T}){let R=rl(e=>e.humanize);return(0,t.jsxs)(aO,{children:[(0,t.jsx)(aI,{asChild:!0,children:(0,t.jsxs)("div",{role:"treeitem",tabIndex:0,draggable:!r,onKeyDown:t=>{if("Enter"===t.key||" "===t.key)t.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"===t.key){t.preventDefault();let e=i.current;if(!e)return;let a=Array.from(e.querySelectorAll('[role="treeitem"]')),n=a.indexOf(t.currentTarget);a[n+1]?.focus()}else if("ArrowUp"===t.key){t.preventDefault();let e=i.current;if(!e)return;let a=Array.from(e.querySelectorAll('[role="treeitem"]')),n=a.indexOf(t.currentTarget);a[n-1]?.focus()}else if("ArrowRight"===t.key){if(t.preventDefault(),"dir"===e.type||"app"===e.type||"node-app"===e.type)if(e.expanded){let e=i.current;if(!e)return;let a=Array.from(e.querySelectorAll('[role="treeitem"]')),n=a.indexOf(t.currentTarget);a[n+1]?.focus()}else n.toggleFolder(e)}else if("ArrowLeft"===t.key){if(t.preventDefault(),("dir"===e.type||"app"===e.type||"node-app"===e.type)&&e.expanded)n.toggleFolder(e);else if(a>0){let e=i.current;if(!e)return;let a=Array.from(e.querySelectorAll('[role="treeitem"]')),n=t.currentTarget,r=a.indexOf(n),s=Number.parseInt(n.style.paddingLeft??"0",10);for(let e=r-1;e>=0;e--)if(Number.parseInt(a[e].style.paddingLeft??"0",10)<s){a[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:()=>O(e),onMouseLeave:T,className:(0,tf.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",d?"bg-accent-soft text-foreground font-medium":"hover:bg-muted",b&&"ring-2 ring-primary bg-primary-soft",e.name.startsWith(".")&&"opacity-40"),style:{paddingLeft:`${14*a+8}px`,...rk},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,t.jsx)(_.Loader2,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground"}):(0,t.jsx)(l.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,t.jsx)("span",{className:"w-3.5 shrink-0"}),(0,t.jsx)("span",{className:"editorial-tree-typeicon",children:"dir"===e.type?e.expanded?(0,t.jsx)(x,{className:(0,tf.cn)("h-4 w-4 shrink-0",!d&&"text-warning")}):(0,t.jsx)(h.Folder,{className:(0,tf.cn)("h-4 w-4 shrink-0",!d&&"text-warning")}):"app"===e.type?(0,t.jsx)(y.Globe,{className:(0,tf.cn)("h-4 w-4 shrink-0",!d&&"text-foreground/70")}):"node-app"===e.type?(0,t.jsx)(z,{className:(0,tf.cn)("h-4 w-4 shrink-0",!d&&"text-emerald-500")}):rb(e.name)?(0,t.jsx)(y.Globe,{className:(0,tf.cn)("h-4 w-4 shrink-0",!d&&"text-foreground/60")}):rg(e.name)?(0,t.jsx)(j.Image,{className:(0,tf.cn)("h-4 w-4 shrink-0",!d&&"text-sunshine-700")}):rx(e.name)?(0,t.jsx)(p.FileText,{className:(0,tf.cn)("h-4 w-4 shrink-0",!d&&"text-foreground/70")}):(0,t.jsx)(u.File,{className:(0,tf.cn)("h-4 w-4 shrink-0",!d&&"text-foreground/60")})}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",title:R?e.name:void 0,children:R?ro(e.name):e.name}),e.git&&(0,t.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,t.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(),C){n.setBranchDropdownNode(null),n.setBranchDropdownPos(null);return}let a=t.currentTarget.getBoundingClientRect();n.setBranchDropdownPos({top:a.bottom+4,left:a.left}),n.setBranchDropdownNode(e.path),n.loadBranches(e.path)},children:[(0,t.jsx)(g,{className:"h-2.5 w-2.5"}),e.git.branch,e.git.dirty&&(0,t.jsx)("span",{className:"ml-0.5 text-warning",children:"*"})]}),N?(0,t.jsx)(_.Loader2,{className:"ml-0.5 h-2.5 w-2.5 animate-spin"}):(0,t.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation();let a=e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")):"";n.handleGitPull(e.path,a)},className:"ml-0.5 text-muted-foreground hover:text-foreground",title:"Pull latest",children:(0,t.jsx)(F,{className:"h-2.5 w-2.5"})}),C&&S&&(0,t.jsx)(tK,{pos:S,branches:M,loading:D,busyName:A,disabled:null!==A,onPick:t=>{let a=e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")):"";n.handleCheckout(e.path,t,a)},onClose:()=>{n.setBranchDropdownNode(null),n.setBranchDropdownPos(null)}})]}),v&&(0,t.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,t.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,t.jsxs)(tR.DropdownMenu,{children:[(0,t.jsx)(tR.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-muted-foreground hover:text-foreground",title:"File actions",children:(0,t.jsx)(E,{className:"h-3.5 w-3.5"})})}),(0,t.jsxs)(tR.DropdownMenuContent,{align:"end",className:"w-48",children:[(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>n.copyPath(e.path),children:[(0,t.jsx)(o.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),rf(e.name)&&(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>n.copyWikiLink(e.name),children:[(0,t.jsx)(p.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>n.copyUrl(e.path),children:[(0,t.jsx)(k.Link,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),"file"===e.type&&rx(e.name)&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>n.copyRawContent(e.path),children:[(0,t.jsx)(p.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>n.copyFormattedContent(e.path,e.name),children:[(0,t.jsx)(p.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),(0,t.jsx)(tR.DropdownMenuSeparator,{}),"dir"===e.type&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(tR.DropdownMenuItem,{onClick:async()=>{e.expanded||n.toggleFolder(e),n.setNewFileParent(e.path),n.setNewFileName(""),n.setFileCreateError(null)},children:[(0,t.jsx)(m.FilePlus,{className:"mr-2 h-3.5 w-3.5"}),"New file here"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>n.triggerUpload(e.path),children:[(0,t.jsx)(q.Upload,{className:"mr-2 h-3.5 w-3.5"}),"Upload here"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>{n.setNewFolderParent(e.path),n.setNewFolderName(""),n.setFolderError(null)},children:[(0,t.jsx)(f,{className:"mr-2 h-3.5 w-3.5"}),"New subfolder"]}),(0,t.jsx)(tR.DropdownMenuSeparator,{})]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>n.handleDownload(e),children:[(0,t.jsx)(c.Download,{className:"mr-2 h-3.5 w-3.5"}),"file"===e.type?"Download":"Download as zip"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>n.togglePin(e,s),children:[(0,t.jsx)(I,{className:(0,tf.cn)("mr-2 h-3.5 w-3.5",w&&"fill-current text-amber-400")}),w?"Unpin":"Pin to top"]}),(0,t.jsx)(tR.DropdownMenuSeparator,{}),(0,t.jsxs)(tR.DropdownMenuItem,{className:"text-destructive focus:text-destructive",onClick:()=>{n.setDeletingPath(e.path),n.setDeletingIsDir("file"!==e.type)},children:[(0,t.jsx)(U.Trash2,{className:"mr-2 h-3.5 w-3.5"}),"Delete"]})]})]})})]})}),(0,t.jsx)(r_,{node:e,ctx:n,isPinned:w,activeWorkspaceId:s})]})}),rS=(0,H.memo)(function(e){let{ctx:a,openPath:n,dragOverPath:r,branchDropdownNode:i,branchDropdownPos:l,nodeBranches:o,branchesLoading:c,checkingOutBranch:d,pullingRepo:u,activePaths:m,pins:x,isMobile:f,activeWorkspaceId:g,newFileParent:b,newFileName:w,fileCreateError:y,newFolderParent:v,newFolderName:N,folderError:j,sidebarScrollRef:k}=e,_=rs(e=>e.showHidden),C=(0,H.useRef)(null),E=(0,H.useCallback)(e=>{let t=("dir"===e.type||"app"===e.type||"node-app"===e.type)&&!e.expanded&&void 0===e.children;("file"===e.type||t)&&(C.current&&clearTimeout(C.current),C.current=setTimeout(()=>a.prefetch(e),120))},[a]),S=(0,H.useCallback)(()=>{C.current&&(clearTimeout(C.current),C.current=null)},[]),M=(0,H.useMemo)(()=>{let t=[],a=(e,n)=>{for(let r of e)!(!_&&r.name.startsWith("."))&&(t.push({kind:"row",node:r,depth:n}),"dir"===r.type&&(v===r.path&&t.push({kind:"newfolder",node:r,depth:n}),b===r.path&&t.push({kind:"newfile",node:r,depth:n})),("dir"===r.type||"app"===r.type||"node-app"===r.type)&&r.expanded&&(r.children&&r.children.length>0?a(r.children,n+1):r.children?.length===0&&t.push({kind:"empty",node:r,depth:n})))};return a(e.nodes,0),t},[e.nodes,b,v,_]);return(0,t.jsx)(t.Fragment,{children:M.map(e=>{let{node:b,depth:v}=e;if("row"===e.kind){let e=i===b.path;return(0,t.jsx)(rE,{node:b,depth:v,ctx:a,isMobile:f,activeWorkspaceId:g,sidebarScrollRef:k,isActive:n===b.path,isDragOver:r===b.path,isPinned:x.some(e=>e.path===b.path),isAgentActive:m.has(b.path),isPulling:u===b.path,branchOpen:e,branchPos:e?l:null,branches:b.git?o[b.path]??[]:[],branchLoading:!!b.git&&!!c[b.path],checkingOut:e?d:null,onHoverEnter:E,onHoverLeave:S},b.path)}return"newfolder"===e.kind?(0,t.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1",style:{paddingLeft:`${(v+1)*14+8}px`,...rk},children:[(0,t.jsx)("span",{className:"w-3.5 shrink-0"}),(0,t.jsx)(h.Folder,{className:"h-4 w-4 shrink-0 text-warning"}),(0,t.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"Folder name",value:N,onChange:e=>a.setNewFolderName(e.target.value),onKeyDown:e=>{"Enter"===e.key&&a.handleCreateFolder(),"Escape"===e.key&&(a.setNewFolderParent(null),a.setNewFolderName(""))}}),j&&(0,t.jsx)("span",{className:"text-xs text-destructive",children:j}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:a.handleCreateFolder,children:(0,t.jsx)(s.Check,{className:"h-3 w-3"})}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{a.setNewFolderParent(null),a.setNewFolderName("")},children:(0,t.jsx)(K.X,{className:"h-3 w-3"})})]},`nf-${b.path}`):"newfile"===e.kind?(0,t.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1",style:{paddingLeft:`${(v+1)*14+8}px`,...rk},children:[(0,t.jsx)("span",{className:"w-3.5 shrink-0"}),(0,t.jsx)(p.FileText,{className:"h-4 w-4 shrink-0 text-accent"}),(0,t.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=>a.setNewFileName(e.target.value),onKeyDown:e=>{"Enter"===e.key&&a.handleCreateFile(),"Escape"===e.key&&(a.setNewFileParent(null),a.setNewFileName(""))}}),y&&(0,t.jsx)("span",{className:"text-xs text-destructive",children:y}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:a.handleCreateFile,children:(0,t.jsx)(s.Check,{className:"h-3 w-3"})}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{a.setNewFileParent(null),a.setNewFileName("")},children:(0,t.jsx)(K.X,{className:"h-3 w-3"})})]},`ff-${b.path}`):(0,t.jsx)("div",{className:"text-xs text-muted-foreground/50 py-0.5",style:{paddingLeft:`${(v+1)*14+8+14+6+16+6}px`,...rk},children:"Empty"},`empty-${b.path}`)})})});e.s(["default",0,function(){let e;(0,rn.useWikiSlugsStore)(e=>e.loadedAt),(0,H.useEffect)(()=>{rn.useWikiSlugsStore.getState().load()},[]);let[n,c]=(0,H.useState)(null),[x,z]=(0,H.useState)(null),[G,Z]=(0,H.useState)(()=>(0,X.getActiveWorkspaceId)()),[J,Q]=(0,H.useState)([]),[Y,en]=(0,H.useState)(!1),[er,eo]=(0,H.useState)(!1),[ed,eu]=(0,H.useState)(null),[em,ep]=(0,H.useState)(null),[eh,ex]=(0,H.useState)({}),[ef,eg]=(0,H.useState)(null),[eb,ew]=(0,H.useState)(null),[ey,ev]=(0,H.useState)(null),[eN,ej]=(0,H.useState)(null),ek=(0,H.useCallback)(async()=>{try{let e=await fetch("/api/system/workspaces");if(!e.ok)throw Error("Failed");let t=await e.json();if(Q(t.workspaces),en(t.isAdmin),t.workspaces.length>0){c(!0);let e=new URLSearchParams(window.location.search).get("ws"),a=e?t.workspaces.find(t=>t.id===e):null,n=a??[...t.workspaces].sort((e,t)=>(t.lastOpenedAt??t.createdAt).localeCompare(e.lastOpenedAt??e.createdAt))[0];if(Z(n.id),z(n.rootDir),!a){let e=new URL(location.href);e.searchParams.set("ws",n.id),history.replaceState(null,"",e.toString())}}else c(!1)}catch{c(!1)}},[]);(0,H.useEffect)(()=>{ek()},[ek]);let e_=(0,nn.useEditorStore)(e=>e.currentPath),eC=aY(e=>e.recents),[eE,eS]=(0,H.useState)(!1),[eM,eD]=(0,H.useState)(!0),eA=a2(e=>e.pins),eO=(0,H.useRef)(null),eT=(0,a3.useAIPanelStore)(e=>e.activity),eI=(0,H.useMemo)(()=>{let e=new Date(Date.now()-6e4).toISOString(),t=new Set;for(let a of eT)a.at>=e&&a.path&&a.by?.startsWith("ai:")&&t.add(a.path);return t},[eT]);(0,H.useEffect)(()=>{let e=()=>{a3.useAIPanelStore.getState().loadActivity()};e();let t=setInterval(e,1e4);return()=>clearInterval(t)},[]),(0,H.useEffect)(()=>{aY.getState().loadForWorkspace(G),a2.getState().loadForWorkspace(G)},[G]),(0,H.useEffect)(()=>{let e=[...eA.map(e=>e.path),...eC.slice(0,8).map(e=>e.path)].filter((e,t,a)=>rf(e)&&a.indexOf(e)===t).slice(0,12);if(0===e.length)return;let t=("requestIdleCallback"in window?e=>window.requestIdleCallback(e):e=>window.setTimeout(e,400))(()=>{for(let t of e)(0,nn.prefetchPage)(t)});return()=>{"cancelIdleCallback"in window?window.cancelIdleCallback(t):clearTimeout(t)}},[eA,eC]);let eR=(0,H.useRef)(new URLSearchParams(window.location.search).get("path")),eF=(0,H.useRef)(!1),[eL,eP]=(0,H.useState)([]),[eB,ez]=(0,H.useState)(!1),[e$,eU]=(0,H.useState)(!1),eq=(0,H.useRef)(!1),[eK,eH]=(0,H.useState)(!1),[eW,eG]=(0,H.useState)(!1),[eV,eZ]=(0,H.useState)(null),eX=(0,H.useRef)(null),eJ=(0,H.useRef)(""),[eQ,eY]=(0,H.useState)(null),[e0,e1]=(0,H.useState)(""),[e2,e5]=(0,H.useState)(null),[e3,e4]=(0,H.useState)(null),[e9,e7]=(0,H.useState)(""),[e6,e8]=(0,H.useState)(null),[te,tt]=(0,H.useState)(null),[ta,tr]=(0,H.useState)(!1),[ts,ti]=(0,H.useState)(null),[tl,to]=(0,H.useState)(null),[tc,td]=(0,H.useState)(!1),[tu,tp]=(0,H.useState)(0),[tb,tw]=(0,H.useState)(0),ty=function(e="(max-width: 767px)"){let[t,a]=(0,H.useState)(!1);return(0,H.useEffect)(()=>{let t=window.matchMedia(e),n=()=>a(t.matches);return n(),t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[e]),t}(),[tv,tN]=(0,H.useState)(!1),tj=ra(e=>e.width),tk=rs(e=>e.showHidden),t_=rl(e=>e.humanize),{resolvedTheme:tC,setTheme:tE}=(0,tH.useTheme)(),tS=ra(e=>e.setWidth);(0,H.useEffect)(()=>{ty&&tN(!0)},[ty]);let[tM,tA]=(0,H.useState)(!1),[tT,tI]=(0,H.useState)(!1),[tF,tP]=(0,H.useState)(!1),[tB,tz]=(0,H.useState)(null),[t$,tq]=(0,H.useState)(0),[tW,tG]=(0,H.useState)(!1),[tV,tZ]=(0,H.useState)(!1),[tX,tJ]=(0,H.useState)(""),[tQ,t0]=(0,H.useState)(!1),[t1,t2]=(0,H.useState)(!1),[t5,t3]=(0,H.useState)(null),t4=(0,H.useRef)(null),[t9,t7]=(0,H.useState)(null),t6=(0,H.useRef)(null),t8=(0,H.useRef)(!1),at=(0,H.useRef)(async()=>{});(0,H.useEffect)(()=>{eB||eq.current||(eq.current=!0,eU(!0),rw("").then(e=>{eP(e),ez(!0),eU(!1)}).catch(()=>{eq.current=!1,eU(!1)}))},[eB]);let aa=(0,H.useCallback)(async e=>{let t=e.split("/");if(t.length<=1)return;let a=[],n="";for(let e=0;e<t.length-1;e++)n=n?`${n}/${t[e]}`:t[e],a.push({prefix:n,children:await rw(n)});eP(e=>{let t=e;for(let{prefix:e,children:n}of a)t=rj(t,e,e=>({...e,children:n,expanded:!0}));return t})},[]),an=(0,H.useCallback)(async e=>{let t=await rw(e);""===e?eP(e=>{let a=new Map(e.map(e=>[e.path,e]));return t.map(e=>{let t=a.get(e.path);return t&&("dir"===t.type||"app"===t.type)?{...e,expanded:t.expanded,children:t.children}:e})}):eP(a=>rj(a,e,e=>({...e,children:t,expanded:!0})))},[]),[ar,as]=(0,H.useState)(null),[ai,al]=(0,H.useState)(null),[ao,ac]=(0,H.useState)(!1),[ad,au]=(0,H.useState)([]),[am,ap]=(0,H.useState)(!1),[ah,ax]=(0,H.useState)(null),[af,ag]=(0,H.useState)(null),[ab,aw]=(0,H.useState)(!1),[ay,av]=(0,H.useState)({}),[ak,a_]=(0,H.useState)({}),[aC,aE]=(0,H.useState)(null),[aS,aM]=(0,H.useState)(null),[aD,aA]=(0,H.useState)(null),aT=(0,H.useCallback)(async(e,t)=>{if(!ar){as(e);try{let a=await (0,X.wsFetch)("/api/wiki/git-pull",{method:"POST",body:JSON.stringify({path:e})});if(!a.ok){let e=await a.json();(0,tY.showError)(e.message??e.error??"Pull failed");return}let n=await a.json();(0,tY.showSuccess)(`Pulled ${e} (${n.branch} @ ${n.sha.slice(0,7)})`),await an(t)}catch{(0,tY.showError)("Pull failed")}finally{as(null)}}},[ar,an]);(0,H.useEffect)(()=>{ac(!1),au([]),ax(null),ag(null)},[ts?.path]);let aR=ts?.path;(0,H.useEffect)(()=>{if(!aR)return void al(null);let e=!1,t=setTimeout(()=>{(async()=>{try{let t=await (0,X.wsFetch)(`/api/wiki/git-file-info?path=${encodeURIComponent(aR)}`);if(e)return;if(!t.ok)return void al(null);let a=await t.json();e||al(a.info)}catch{e||al(null)}})()},200);return()=>{e=!0,clearTimeout(t)}},[aR]);let aF=(0,H.useCallback)(async()=>{if(!ts)return;let e=ts.path;ac(!0),ap(!0),au([]),ax(null),ag(null);try{let t=await (0,X.wsFetch)(`/api/wiki/git-history?path=${encodeURIComponent(e)}`);if(!t.ok)return void(0,tY.showError)("Could not load history");let a=await t.json();ts.path===e&&au(a.commits)}catch{(0,tY.showError)("Could not load history")}finally{ap(!1)}},[ts]),aL=(0,H.useCallback)(async e=>{if(!ts)return;if(ah===e){ax(null),ag(null);return}let t=ts.path;ax(e),aw(!0),ag(null);try{let a=await (0,X.wsFetch)(`/api/wiki/git-diff?path=${encodeURIComponent(t)}&sha=${encodeURIComponent(e)}`);if(!a.ok)return void(0,tY.showError)("Could not load diff");let n=await a.json();ts.path===t&&ah===e&&ag(n.diff)}catch{(0,tY.showError)("Could not load diff")}finally{aw(!1)}},[ts,ah]),aP=(0,H.useCallback)(async e=>{if(ay[e]||ak[e])return;let t=!1;a_(t=>({...t,[e]:!0}));try{let a=await (0,X.wsFetch)(`/api/wiki/git-branches?path=${encodeURIComponent(e)}`);if(t)return;if(!a.ok)return void(0,tY.showError)("Could not load branches");let n=await a.json();t||av(t=>({...t,[e]:n.branches}))}catch{t||(0,tY.showError)("Could not load branches")}finally{t||a_(t=>({...t,[e]:!1}))}return()=>{t=!0}},[ay,ak]),aB=(0,H.useCallback)(async(e,t,a)=>{if(!aC){aE(t);try{let n=await (0,X.wsFetch)("/api/wiki/git-checkout",{method:"POST",body:JSON.stringify({path:e,branch:t})});if(409===n.status)return void(0,tY.showError)("Repository has uncommitted changes");if(!n.ok){let e=await n.json();(0,tY.showError)(e.error??"Checkout failed");return}let r=await n.json();(0,tY.showSuccess)(`Switched to ${r.branch}`),av(t=>{let a={...t};return delete a[e],a}),aM(null),aA(null),await an(a)}catch{(0,tY.showError)("Checkout failed")}finally{aE(null)}}},[aC,an]),az=(0,H.useCallback)(e=>{let t=[];for(let a of e)("dir"===a.type||"app"===a.type||"node-app"===a.type)&&a.expanded&&a.children&&(t.push(a.path),t.push(...az(a.children)));return t},[]),a$=(0,H.useCallback)(async()=>{eH(!0);try{let e=az(eL),t=await rw("");for(let a of(eP(t),e)){let e=await rw(a);eP(t=>rj(t,a,t=>({...t,children:e,expanded:!0})))}}finally{eH(!1)}},[eL,az]),aU=(0,H.useCallback)(async()=>{if(ts){if(rf(ts.name)){tG(!0);try{await nn.useEditorStore.getState().loadPage(ts.path)}finally{tG(!1)}return}if(["editor","text"].includes(rp(ts.name,ts.nodeType))||rx(ts.name)){tG(!0);try{let e=await (0,X.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(ts.path)}`);if(e.ok){let t=await e.json();tz(t.content),tq(Number(e.headers.get("X-Wiki-Revision")??0))}}catch{}tG(!1)}}},[ts]),aq=(0,H.useCallback)(()=>{tw(e=>e+1),aU()},[aU]);async function aK(e){if("dir"===e.type||"app"===e.type||"node-app"===e.type)if(e.expanded)eP(t=>rj(t,e.path,e=>({...e,expanded:!1})));else if(void 0===e.children){let t=await rN(e.path);if(t)return void eP(a=>rj(a,e.path,e=>({...e,loading:!1,children:t,expanded:!0})));eP(t=>rj(t,e.path,e=>({...e,loading:!0})));let a=await rw(e.path);eP(t=>rj(t,e.path,e=>({...e,loading:!1,children:a,expanded:!0})))}else eP(t=>rj(t,e.path,e=>({...e,expanded:!0})))}async function aH(e){if("file"===e.type&&aY.getState().push({path:e.path,name:e.name},G),ti({path:e.path,name:e.name,size:e.size,nodeType:"app"===e.type?"app":"node-app"===e.type?"node-app":"file"}),tZ(!1),t0(!1),t3(null),tz(null),tq(0),"file"===e.type&&rf(e.name)){tG(!0);try{await nn.useEditorStore.getState().loadPage(e.path)}finally{tG(!1)}return}if(["editor","text"].includes(rp(e.name,e.type))||rx(e.name)){tG(!0);try{let t=await (0,X.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(e.path)}`);if(t.ok){let e=await t.json();tz(e.content),tq(Number(t.headers.get("X-Wiki-Revision")??0))}}catch{}tG(!1)}}(0,H.useEffect)(()=>{ts&&rf(ts.name)&&nn.useEditorStore.getState().currentPath!==ts.path&&nn.useEditorStore.getState().loadPage(ts.path)},[ts]),(0,H.useEffect)(()=>{t6.current=ts},[ts]),(0,H.useEffect)(()=>{t8.current=tV},[tV]),(0,H.useEffect)(()=>{at.current=aU},[aU]),(0,H.useEffect)(()=>{if(!n)return;let e=new Map,t=new EventSource((0,X.withWs)("/api/wiki/watch"));return t.onmessage=t=>{var a;let n;try{n=JSON.parse(t.data)}catch{return}let{type:r,path:s}=n,i=s.split("/");if(a=i.length>1?i.slice(0,-1).join("/"):"",e.has(a)&&clearTimeout(e.get(a)),e.set(a,setTimeout(()=>{e.delete(a),an(a)},300)),"change"===r&&t6.current?.path===s&&!t8.current){let t=`__file__${s}`;e.has(t)&&clearTimeout(e.get(t)),e.set(t,setTimeout(()=>{e.delete(t),at.current()},400))}},()=>{for(let a of(t.close(),e.values()))clearTimeout(a)}},[n,an]),(0,H.useEffect)(()=>{td(!1)},[]);let aW=(0,H.useCallback)(e=>{let t=e.split("/").pop()??e;aa(e),aH({path:e,name:t,type:"file"})},[aa]),aG=(0,H.useCallback)(async e=>{let t=e.path.split("/").slice(0,-1).join("/"),a=(await rw(t)).find(t=>t.path===e.path);if(a){if("dir"===a.type){await aa(e.path),await aK(a);return}if("app"===a.type||"node-app"===a.type){await aa(a.path),aH({path:a.path,name:a.name,type:a.type,modifiedAt:a.modifiedAt}),await aK(a),ty&&tN(!0);return}aH({path:a.path,name:a.name,type:a.type,modifiedAt:a.modifiedAt}),ty&&tN(!0)}},[ty,aH,aa,aK]);(0,H.useEffect)(()=>{if(!e_||ts&&ts.path===e_)return;let e=e_.split("/").pop()??e_;aH({path:e_,name:e,type:"file"})},[e_]);let aV=(0,H.useCallback)(async e=>{if(!e)return void ti(null);let t=e.split("/"),a=t[t.length-1],n=t.slice(0,-1).join("/"),r=(await rw(n)).find(t=>t.path===e);r&&(await aa(e),aH({path:e,name:a,type:r.type,modifiedAt:r.modifiedAt}))},[aa]);(0,H.useEffect)(()=>{let e=new URL(window.location.href);ts?e.searchParams.set("path",ts.path):e.searchParams.delete("path");let t=e.toString();t!==window.location.href&&window.history.pushState(null,"",t)},[ts]),(0,H.useEffect)(()=>{let e=()=>{aV(new URLSearchParams(window.location.search).get("path"))};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[aV]),(0,H.useEffect)(()=>{eF.current||eB&&(eF.current=!0,aV(eR.current))},[eB,aV]);let aZ=(0,H.useCallback)(async e=>{if(e===G)return;try{await fetch(`/api/system/workspaces/${e}/open`,{method:"POST"})}catch{}let t=new URL(location.href);t.searchParams.set("ws",e),t.searchParams.delete("path"),history.pushState(null,"",t.toString()),ti(null),tz(null),tZ(!1),eP([]),ez(!1),eq.current=!1,rn.useWikiSlugsStore.getState().invalidate();let a=J.find(t=>t.id===e);a&&z(a.rootDir),Z(e)},[G,J]),aX=(0,H.useCallback)(async()=>{if(ed)try{if(!(await fetch(`/api/system/workspaces/${ed}`,{method:"DELETE"})).ok)throw Error("Failed");if(ed===G){let e=J.filter(e=>e.id!==ed);if(e.length>0){let t=[...e].sort((e,t)=>(t.lastOpenedAt??t.createdAt).localeCompare(e.lastOpenedAt??e.createdAt))[0];await aZ(t.id)}else c(!1)}await ek()}catch{}finally{eu(null)}},[ed,G,J,aZ,ek]),aJ=(0,H.useCallback)(async e=>{if(!em){ep(e);try{let t=await fetch(`/api/system/workspaces/${e}/refresh`,{method:"POST"});if(!t.ok){let e=await t.json();(0,tY.showError)(e.error??"Refresh failed")}await ek()}catch{(0,tY.showError)("Refresh failed")}finally{ep(null)}}},[em,ek]),aQ=(0,H.useCallback)(async e=>{if(!eh[e])try{let t=await fetch(`/api/system/workspaces/${e}/branch`);if(!t.ok)return;let a=await t.json();ex(t=>({...t,[e]:a.branches??[]}))}catch{}},[eh]),a0=(0,H.useCallback)(async(e,t)=>{if(!ef){eg(e),ew(t);try{let a=await fetch(`/api/system/workspaces/${e}/branch`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({branch:t})});if(!a.ok){let e=await a.json();(0,tY.showError)(e.error??"Branch switch failed");return}(0,tY.showSuccess)(`Switched to ${t}`),ev(null),ej(null),await ek()}catch{(0,tY.showError)("Branch switch failed")}finally{eg(null),ew(null)}}},[ef,ek]);async function a1(){if(!ts)return;t2(!0),t3(null);let e=await (0,X.wsFetch)("/api/wiki/content",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:ts.path,content:tX,baseRevision:t$})});if(e.ok){let t=await e.json();"number"==typeof t.revision&&tq(t.revision),tz(tX),tZ(!1)}else t3((await e.json()).error??"Save failed");t2(!1)}let a5=(0,H.useCallback)(async(e,t)=>{let a=Array.from(e);if(a.length){eG(!0),eZ(null);try{for(let e of a){let a=new FormData;a.append("file",e),a.append("dir",t);let n=await (0,X.wsFetch)("/api/wiki/upload",{method:"POST",body:a});if(!n.ok){let e=await n.json();eZ(e.error??"Upload failed"),(0,tY.showError)(e.error??"Upload failed");break}}await an(t)}catch{eZ("Upload failed.")}finally{eG(!1),eX.current&&(eX.current.value="")}}},[an]);function a4(e){eJ.current=e,eX.current?.click()}async function a9(){let e=e0.trim();if(!e||null===eQ)return;e5(null);let t=eQ?`${eQ}/${e}`:e,a=await (0,X.wsFetch)("/api/wiki/folder",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});a.ok?(eY(null),e1(""),await an(eQ),""!==eQ&&eP(e=>rj(e,eQ,e=>({...e,expanded:!0})))):e5((await a.json()).error??"Failed")}async function a7(){let e=e9.trim();if(!e||null===e3)return;e8(null);let t=e.includes(".")?e:`${e}.md`,a=e3?`${e3}/${t}`:t,n=await (0,X.wsFetch)("/api/wiki/new-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a})});n.ok?(e4(null),e7(""),await an(e3),""!==e3&&eP(e=>rj(e,e3,e=>({...e,expanded:!0}))),aH({path:a,name:t,type:"file",modifiedAt:new Date().toISOString()})):e8((await n.json()).error??"Failed")}function a6(e){navigator.clipboard.writeText(e),(0,tY.showSuccess)("Path copied")}function a8(e){let t=e.replace(/\.(md|markdown)$/i,"");navigator.clipboard.writeText(`[[${t}]]`),(0,tY.showSuccess)("Wiki link copied")}function ne(e){let t=new URL(location.href);t.searchParams.set("path",e),G&&t.searchParams.set("ws",G),navigator.clipboard.writeText(t.toString()),(0,tY.showSuccess)("URL copied")}async function nt(e){if(ts?.path===e&&null!==tB)return tB;if(nn.useEditorStore.getState().currentPath===e)return nn.useEditorStore.getState().content;let t=await (0,X.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(e)}`);if(!t.ok)throw Error("Cannot copy content");return(await t.json()).content}async function na(e){try{let t=await nt(e);await navigator.clipboard.writeText(t),(0,tY.showSuccess)("Raw content copied")}catch{(0,tY.showError)("Could not copy file content")}}async function nr(e,t){try{let a=await nt(e);if(!rf(t)){await navigator.clipboard.writeText(a),(0,tY.showSuccess)("Content copied");return}let n=await (0,tn.markdownToHtml)(a,{pagePath:e,sanitize:!0});"ClipboardItem"in window&&navigator.clipboard.write?await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([n],{type:"text/html"}),"text/plain":new Blob([a],{type:"text/plain"})})]):await navigator.clipboard.writeText(a),(0,tY.showSuccess)("Formatted content copied")}catch{(0,tY.showError)("Could not copy formatted content")}}function ns(e,a){return(0,t.jsxs)(tR.DropdownMenu,{children:[(0,t.jsx)(tR.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"File actions",children:(0,t.jsx)(E,{className:"h-3.5 w-3.5"})})}),(0,t.jsxs)(tR.DropdownMenuContent,{align:"end",className:"w-52",children:[(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>a6(e.path),children:[(0,t.jsx)(o.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),rf(e.name)&&(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>a8(e.name),children:[(0,t.jsx)(p.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,t.jsx)(tR.DropdownMenuSeparator,{}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>ne(e.path),children:[(0,t.jsx)(k.Link,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),rx(e.name)&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tR.DropdownMenuSeparator,{}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>void na(e.path),children:[(0,t.jsx)(p.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>void nr(e.path,e.name),children:[(0,t.jsx)(p.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),a&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tR.DropdownMenuSeparator,{}),a]})]})]})}async function ni(){te&&(await (0,X.wsFetch)("/api/wiki",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:te})}),(ts?.path===te||ts?.path.startsWith(`${te}/`))&&(ti(null),tz(null)),eP(e=>(function e(t,a){return t.filter(e=>e.path!==a).map(t=>t.children?{...t,children:e(t.children,a)}:t)})(e,te)),tt(null))}function nl(e,t,a){e.preventDefault(),e.stopPropagation();let n=t4.current;if(!n){Array.from(e.dataTransfer.types).includes("Files")&&(e.dataTransfer.dropEffect="copy",t7("root"===a?"":t));return}n.path===t||t.startsWith(`${n.path}/`)||(e.dataTransfer.dropEffect="move",t7("root"===a?"":t))}async function no(e,t){e.preventDefault(),e.stopPropagation(),t7(null);let a=t4.current;if(t4.current=null,!a){e.dataTransfer.files.length>0&&await a5(e.dataTransfer.files,t);return}if(a.path===t||t.startsWith(`${a.path}/`))return;let n=t?`${t}/${a.name}`:a.name;if(n!==a.path&&(await (0,X.wsFetch)("/api/wiki/move",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({from:a.path,to:n})})).ok){let e=a.path.includes("/")?a.path.split("/").slice(0,-1).join("/"):"";await an(e),t!==e&&await an(t),ts?.path===a.path&&ti({path:n,name:a.name,nodeType:ts.nodeType,size:ts.size})}}let nc=ts?rp(ts.name,ts.nodeType):null,nd=!!ts&&null!==nc&&!ru.has(nc)&&(ts.size??0)>5242880&&tl!==ts.path,nm=(0,n9.useViewWidthStore)(e=>e.width),np=(0,n9.useViewWidthStore)(e=>e.align),nh=(0,n9.useViewWidthStore)(e=>e.setWidth),nx=(0,n9.useViewWidthStore)(e=>e.setAlign),nf=null===nc||"editor"===nc||"text"===nc||"source"===nc||"notebook"===nc||"fallback"===nc,ng=nf?n9.VIEW_WIDTH_CLASS[nm]:"",nb=nf?n9.VIEW_ALIGN_CLASS[np]:"",nw=(0,H.useRef)(null);nw.current={toggleFolder:e=>void aK(e),openViewer:e=>void aH(e),copyPath:a6,copyWikiLink:a8,copyUrl:ne,copyRawContent:e=>void na(e),copyFormattedContent:(e,t)=>void nr(e,t),handleDownload:function(e){let t=(0,X.withWs)(`/api/wiki/download?path=${encodeURIComponent(e.path)}`),a=document.createElement("a");a.href=t,a.download="file"===e.type?e.name:`${e.name}.zip`,document.body.appendChild(a),a.click(),a.remove()},triggerUpload:a4,handleCreateFile:()=>void a7(),handleCreateFolder:()=>void a9(),handleDragStart:function(e,t){t4.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t.path)},handleDragOver:nl,handleDropOnFolder:(e,t)=>void no(e,t),handleGitPull:(e,t)=>void aT(e,t),handleCheckout:(e,t,a)=>void aB(e,t,a),loadBranches:e=>void aP(e),prefetch:e=>{"file"===e.type?rf(e.name)&&(0,nn.prefetchPage)(e.path):function(e){if(ry.has(e)||rv.has(e))return;let t=rw(e).then(t=>(ry.set(e,t),t)).finally(()=>rv.delete(e));rv.set(e,t),t.catch(()=>{})}(e.path)},togglePin:(e,t)=>a2.getState().toggle({path:e.path,name:e.name,type:e.type},t),setDragOverPath:t7,setSidebarCollapsed:tN,setBranchDropdownNode:aM,setBranchDropdownPos:aA,setNewFileParent:e4,setNewFileName:e7,setFileCreateError:e8,setNewFolderParent:eY,setNewFolderName:e1,setFolderError:e5,setDeletingPath:tt,setDeletingIsDir:tr};let ny=(0,H.useMemo)(()=>({toggleFolder:e=>nw.current.toggleFolder(e),openViewer:e=>nw.current.openViewer(e),copyPath:e=>nw.current.copyPath(e),copyWikiLink:e=>nw.current.copyWikiLink(e),copyUrl:e=>nw.current.copyUrl(e),copyRawContent:e=>nw.current.copyRawContent(e),copyFormattedContent:(e,t)=>nw.current.copyFormattedContent(e,t),handleDownload:e=>nw.current.handleDownload(e),triggerUpload:e=>nw.current.triggerUpload(e),handleCreateFile:()=>nw.current.handleCreateFile(),handleCreateFolder:()=>nw.current.handleCreateFolder(),handleDragStart:(e,t)=>nw.current.handleDragStart(e,t),handleDragOver:(e,t,a)=>nw.current.handleDragOver(e,t,a),handleDropOnFolder:(e,t)=>nw.current.handleDropOnFolder(e,t),handleGitPull:(e,t)=>nw.current.handleGitPull(e,t),handleCheckout:(e,t,a)=>nw.current.handleCheckout(e,t,a),loadBranches:e=>nw.current.loadBranches(e),prefetch:e=>nw.current.prefetch(e),togglePin:(e,t)=>nw.current.togglePin(e,t),setDragOverPath:e=>nw.current.setDragOverPath(e),setSidebarCollapsed:e=>nw.current.setSidebarCollapsed(e),setBranchDropdownNode:e=>nw.current.setBranchDropdownNode(e),setBranchDropdownPos:e=>nw.current.setBranchDropdownPos(e),setNewFileParent:e=>nw.current.setNewFileParent(e),setNewFileName:e=>nw.current.setNewFileName(e),setFileCreateError:e=>nw.current.setFileCreateError(e),setNewFolderParent:e=>nw.current.setNewFolderParent(e),setNewFolderName:e=>nw.current.setNewFolderName(e),setFolderError:e=>nw.current.setFolderError(e),setDeletingPath:e=>nw.current.setDeletingPath(e),setDeletingIsDir:e=>nw.current.setDeletingIsDir(e)}),[]);return(0,t.jsxs)("div",{className:"flex h-screen gap-0 overflow-hidden bg-background",children:[null===n&&(0,t.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,t.jsx)(_.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),!1===n&&(0,t.jsx)(tU,{onSelect:e=>{let t=new URL(location.href);t.searchParams.set("ws",e),t.searchParams.delete("path"),history.replaceState(null,"",t.toString()),ez(!1),eq.current=!1,Z(e),c(!0),ek()}}),!0===n&&er&&(0,t.jsxs)("div",{className:"flex-1 flex flex-col",children:[(0,t.jsx)("div",{className:"flex items-center justify-end border-b px-3 py-2 bg-muted shrink-0",children:(0,t.jsxs)(W.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1.5 text-xs",onClick:()=>eo(!1),children:[(0,t.jsx)(K.X,{className:"h-3.5 w-3.5"})," Cancel"]})}),(0,t.jsx)(tU,{onSelect:e=>{eo(!1),ek(),aZ(e)}})]}),!0===n&&!er&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n6,{onOpenFile:aW,recents:eC,onToggleSidebar:()=>tN(e=>{let t=!e;return ty&&!1===t&&a3.useAIPanelStore.getState().close(),t}),onNewFile:()=>e4(""),onCopyPath:()=>{ts&&navigator.clipboard.writeText(ts.path)}}),!tv&&ty&&(0,t.jsx)("div",{className:"fixed inset-0 z-40 bg-overlay backdrop-blur-[1px] md:hidden",onClick:()=>tN(!0),"aria-hidden":!0}),!tv&&(0,t.jsxs)(aj.Card,{style:ty?void 0:{width:tj},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",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2 px-3 py-2 border-b bg-muted shrink-0",children:[(0,t.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",children:[(0,t.jsx)("img",{src:"/logo.svg",alt:"Wiki Viewer",className:"h-5 w-5 shrink-0"}),(0,t.jsx)("span",{className:"truncate text-xs font-semibold leading-5 tracking-tight translate-y-[0.5px]",children:"Wiki Viewer"})]}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 shrink-0",title:"Collapse sidebar",onClick:()=>tN(!0),children:(0,t.jsx)(M,{className:"h-3.5 w-3.5"})})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-1 px-3 py-1.5 border-b bg-muted/50 shrink-0",children:[(0,t.jsxs)(tR.DropdownMenu,{children:[(0,t.jsx)(tR.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsxs)(W.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1 px-2 text-xs",disabled:eW,children:[eW?(0,t.jsx)(_.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(R,{className:"h-3.5 w-3.5"}),"New",(0,t.jsx)(i.ChevronDown,{className:"h-3 w-3 opacity-60"})]})}),(0,t.jsxs)(tR.DropdownMenuContent,{align:"start",className:"w-44",children:[(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>{e4(""),e7(""),e8(null)},children:[(0,t.jsx)(m.FilePlus,{className:"mr-2 h-3.5 w-3.5"}),"New file"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>{eY(""),e1(""),e5(null)},children:[(0,t.jsx)(f,{className:"mr-2 h-3.5 w-3.5"}),"New folder"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>a4(""),disabled:eW,children:[(0,t.jsx)(q.Upload,{className:"mr-2 h-3.5 w-3.5"}),"Upload"]})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Refresh tree",onClick:a$,disabled:eK,children:eK?(0,t.jsx)(_.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(F,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"AI Agent panel",onClick:()=>{a3.useAIPanelStore.getState().toggle(),ty&&tN(!0)},children:(0,t.jsx)(r,{className:"h-3.5 w-3.5"})}),(0,t.jsxs)(tR.DropdownMenu,{children:[(0,t.jsx)(tR.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"More actions",children:(0,t.jsx)(E,{className:"h-3.5 w-3.5"})})}),(0,t.jsxs)(tR.DropdownMenuContent,{align:"end",className:"w-48",children:[Y&&J.find(e=>e.id===G)?.git&&(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>{G&&aJ(G)},disabled:em===G,children:[em===G?(0,t.jsx)(_.Loader2,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(d,{className:"mr-2 h-3.5 w-3.5"}),"Pull latest"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>rs.getState().toggle(),children:[tk?(0,t.jsx)(T,{className:"mr-2 h-3.5 w-3.5"}):(0,t.jsx)(O.Eye,{className:"mr-2 h-3.5 w-3.5"}),tk?"Hide hidden files":"Show hidden files"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>rl.getState().toggle(),children:[(0,t.jsx)($.Type,{className:"mr-2 h-3.5 w-3.5"}),t_?"Raw file names":"Humanize names"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>tE("dark"===tC?"light":"dark"),children:["dark"===tC?(0,t.jsx)(B.Sun,{className:"mr-2 h-3.5 w-3.5"}):(0,t.jsx)(S.Moon,{className:"mr-2 h-3.5 w-3.5"}),"dark"===tC?"Light mode":"Dark mode"]}),(0,t.jsx)(tR.DropdownMenuSeparator,{}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>tI(!0),children:[(0,t.jsx)(L,{className:"mr-2 h-3.5 w-3.5"}),"Settings"]})]})]})]})]}),eV&&(0,t.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,t.jsx)(a.AlertCircle,{className:"h-3.5 w-3.5 shrink-0"}),eV]}),""===eQ&&(0,t.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,t.jsx)(h.Folder,{className:"h-4 w-4 shrink-0 text-warning"}),(0,t.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"Folder name",value:e0,onChange:e=>e1(e.target.value),onKeyDown:e=>{"Enter"===e.key&&a9(),"Escape"===e.key&&(eY(null),e1(""))}}),e2&&(0,t.jsx)("span",{className:"text-xs text-destructive",children:e2}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:a9,children:(0,t.jsx)(s.Check,{className:"h-3 w-3"})}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{eY(null),e1("")},children:(0,t.jsx)(K.X,{className:"h-3 w-3"})})]}),""===e3&&(0,t.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,t.jsx)(p.FileText,{className:"h-4 w-4 shrink-0 text-accent"}),(0,t.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:e9,onChange:e=>e7(e.target.value),onKeyDown:e=>{"Enter"===e.key&&a7(),"Escape"===e.key&&(e4(null),e7(""))}}),e6&&(0,t.jsx)("span",{className:"text-xs text-destructive",children:e6}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:a7,children:(0,t.jsx)(s.Check,{className:"h-3 w-3"})}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{e4(null),e7("")},children:(0,t.jsx)(K.X,{className:"h-3 w-3"})})]}),(0,t.jsx)("div",{className:"border-b",children:(0,t.jsx)(n8,{onOpenFile:aW})}),(0,t.jsxs)("div",{ref:eO,className:(0,tf.cn)("flex-1 overflow-auto py-1 editorial-file-tree",""===t9&&"ring-2 ring-inset ring-primary bg-primary/5"),onDragOver:e=>nl(e,"","root"),onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||t7(null)},onDrop:e=>no(e,""),children:[eA.length>0&&(0,t.jsxs)("div",{className:"border-b mb-1",children:[(0,t.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:()=>eS(e=>!e),children:[eE?(0,t.jsx)(l.ChevronRight,{className:"h-3 w-3"}):(0,t.jsx)(i.ChevronDown,{className:"h-3 w-3"}),(0,t.jsx)(I,{className:"h-3 w-3"}),"Pinned",(0,t.jsx)("span",{className:"ml-auto text-[9px] tabular-nums opacity-60",children:eA.length})]}),!eE&&eA.map(e=>(0,t.jsxs)(aO,{children:[(0,t.jsx)(aI,{asChild:!0,children:(0,t.jsxs)("div",{role:"button",tabIndex:0,className:(0,tf.cn)("group flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer transition-colors select-none",ts?.path===e.path?"bg-accent-soft text-foreground font-medium":"hover:bg-muted"),onClick:()=>{aG(e)},onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),aG(e))},children:[(0,t.jsx)(rC,{name:e.name,type:e.type??"file"}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate text-xs",title:t_?e.name:void 0,children:t_?ro(e.name):e.name}),(0,t.jsx)("span",{className:"max-w-[80px] truncate text-[10px] text-muted-foreground/60",children:e.path.split("/").slice(0,-1).join("/")}),(0,t.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 pinned",onClick:t=>{t.stopPropagation(),a2.getState().toggle({path:e.path,name:e.name},G)},children:(0,t.jsx)(K.X,{className:"h-3 w-3"})})]})}),(0,t.jsx)(r_,{node:{path:e.path,name:e.name,type:e.type??"file"},ctx:ny,isPinned:!0,activeWorkspaceId:G})]},e.path))]}),eC.length>0&&(0,t.jsxs)("div",{className:"border-b mb-1",children:[(0,t.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:()=>eD(e=>!e),children:[eM?(0,t.jsx)(l.ChevronRight,{className:"h-3 w-3"}):(0,t.jsx)(i.ChevronDown,{className:"h-3 w-3"}),(0,t.jsx)(v,{className:"h-3 w-3"}),"Recent",(0,t.jsx)("span",{className:"ml-auto text-[9px] tabular-nums opacity-60",children:eC.length})]}),!eM&&eC.slice(0,8).map(e=>(0,t.jsxs)(aO,{children:[(0,t.jsx)(aI,{asChild:!0,children:(0,t.jsxs)("div",{role:"button",tabIndex:0,className:(0,tf.cn)("flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer transition-colors select-none",ts?.path===e.path?"bg-accent-soft text-foreground font-medium":"hover:bg-muted"),onClick:()=>{aH({path:e.path,name:e.name,type:e.type??"file",modifiedAt:""}),ty&&tN(!0)},onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),aH({path:e.path,name:e.name,type:e.type??"file",modifiedAt:""}))},children:[(0,t.jsx)(rC,{name:e.name,type:e.type??"file"}),(0,t.jsx)("span",{className:"flex-1 truncate text-xs",title:t_?e.name:void 0,children:t_?ro(e.name):e.name}),(0,t.jsx)("span",{className:"text-[10px] text-muted-foreground/60 truncate max-w-[80px]",children:e.path.split("/").slice(0,-1).join("/")})]})}),(0,t.jsx)(r_,{node:{path:e.path,name:e.name,type:e.type??"file"},ctx:ny,isPinned:eA.some(t=>t.path===e.path),activeWorkspaceId:G})]},e.path))]}),e$?(0,t.jsx)("div",{className:"flex justify-center py-6",children:(0,t.jsx)(_.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):0===eL.length?(0,t.jsxs)("div",{className:"flex flex-col items-center gap-3 px-4 py-8 text-center",children:[(0,t.jsx)("div",{className:"rounded-full bg-muted p-3",children:(0,t.jsx)(p.FileText,{className:"h-6 w-6 text-muted-foreground"})}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)("p",{className:"text-sm font-medium",children:"No files yet"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Upload files or add them to the configured directory"})]}),(0,t.jsxs)(W.Button,{size:"sm",variant:"outline",className:"w-full gap-1.5 max-w-[180px]",onClick:()=>a4(""),disabled:eW,children:[eW?(0,t.jsx)(_.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(q.Upload,{className:"h-3.5 w-3.5"}),"Upload Files"]})]}):(0,t.jsx)(rS,{ctx:ny,nodes:eL,openPath:ts?.path??null,dragOverPath:t9,branchDropdownNode:aS,branchDropdownPos:aD,nodeBranches:ay,branchesLoading:ak,checkingOutBranch:aC,pullingRepo:ar,activePaths:eI,pins:eA,isMobile:ty,activeWorkspaceId:G,newFileParent:e3,newFileName:e9,fileCreateError:e6,newFolderParent:eQ,newFolderName:e0,folderError:e2,sidebarScrollRef:eO})]}),(0,t.jsxs)("div",{className:"border-t px-2 py-2 bg-muted shrink-0",children:[(0,t.jsxs)(tR.DropdownMenu,{modal:!1,onOpenChange:e=>{e||(ev(null),ej(null))},children:[(0,t.jsx)(tR.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsxs)(W.Button,{size:"sm",variant:"ghost",className:"w-full h-auto justify-between gap-2 px-2 py-1.5 text-left",title:x??"",children:[(0,t.jsxs)("span",{className:"flex flex-col min-w-0",children:[(0,t.jsx)("span",{className:"truncate text-xs font-medium",children:J.find(e=>e.id===G)?.name??"Workspace"}),(0,t.jsx)("span",{className:"truncate text-[10px] text-muted-foreground font-mono",children:x??""})]}),(0,t.jsx)(i.ChevronDown,{className:"h-3.5 w-3.5 shrink-0 opacity-60"})]})}),(0,t.jsxs)(tR.DropdownMenuContent,{align:"start",className:"w-[var(--radix-dropdown-menu-trigger-width)]",onInteractOutside:e=>{e.target?.closest?.("[data-branch-portal]")&&e.preventDefault()},children:[J.map(e=>(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>void aZ(e.id),onPointerMove:e=>e.preventDefault(),onPointerLeave:e=>e.preventDefault(),className:(0,tf.cn)("gap-2",e.id===G&&"font-medium"),children:[e.id===G?(0,t.jsx)(s.Check,{className:"h-3.5 w-3.5 shrink-0"}):(0,t.jsx)("span",{className:"w-3.5 shrink-0"}),(0,t.jsxs)("span",{className:"flex flex-col min-w-0 flex-1",children:[(0,t.jsxs)("span",{className:"flex items-center gap-1.5 truncate",children:[(0,t.jsx)("span",{className:"truncate",children:e.name}),e.git?Y?(0,t.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:ef===e.id,onClick:t=>{if(t.stopPropagation(),t.preventDefault(),ey===e.id){ev(null),ej(null);return}let a=t.currentTarget.getBoundingClientRect();ej({top:a.bottom+4,left:a.left}),ev(e.id),aQ(e.id)},children:[(0,t.jsx)(g,{className:"h-2.5 w-2.5"})," ",e.git.branch??"branch"]}):(0,t.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,t.jsx)(g,{className:"h-2.5 w-2.5"})," ",e.git.branch??"read-only"]}):e.ssh?(0,t.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,t.jsx)(b,{className:"h-2.5 w-2.5"})," ",e.ssh.host]}):e.readOnly?(0,t.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,t.jsx)(g,{className:"h-2.5 w-2.5"})," read-only"]}):null]}),(0,t.jsx)("span",{className:"truncate text-[10px] text-muted-foreground font-mono",children:e.rootDir}),e.git?.lastPulledAt&&rd(e.git.lastPulledAt)&&(0,t.jsxs)("span",{className:"text-[10px] text-muted-foreground/70",children:["synced ",rd(e.git.lastPulledAt)]})]}),Y&&e.git&&(0,t.jsx)("button",{className:(0,tf.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:em===e.id,onClick:t=>{t.stopPropagation(),t.preventDefault(),aJ(e.id)},children:(0,t.jsx)(F,{className:(0,tf.cn)("h-3.5 w-3.5",em===e.id&&"animate-spin")})}),Y&&(0,t.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(),eu(e.id)},children:(0,t.jsx)(U.Trash2,{className:"h-3.5 w-3.5"})})]},e.id)),Y&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tR.DropdownMenuSeparator,{}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>eo(!0),children:[(0,t.jsx)(f,{className:"mr-2 h-3.5 w-3.5"}),"Add workspace…"]})]})]})]}),(()=>{if(!ey||!eN)return null;let e=J.find(e=>e.id===ey);return e?(0,t.jsx)(tK,{pos:eN,branches:(eh[e.id]??[]).map(t=>({name:t,current:t===e.git?.branch})),loading:!eh[e.id],busyName:ef===e.id?eb:null,disabled:ef===e.id,onPick:t=>{a0(e.id,t)},onClose:()=>{ev(null),ej(null)}}):null})()]}),(0,t.jsx)("div",{role:"separator","aria-orientation":"vertical","aria-label":"Resize sidebar",title:"Drag to resize",onMouseDown:e=>{e.preventDefault();let t=e.clientX;tA(!0);let a=document.body.style.cursor,n=document.body.style.userSelect;document.body.style.cursor="col-resize",document.body.style.userSelect="none";let r=e=>{tS(tj+(e.clientX-t))},s=()=>{tA(!1),document.body.style.cursor=a,document.body.style.userSelect=n,window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",r),window.addEventListener("mouseup",s)},onDoubleClick:()=>tS(288),onKeyDown:e=>{"ArrowLeft"===e.key?(e.preventDefault(),tS(tj-16)):"ArrowRight"===e.key&&(e.preventDefault(),tS(tj+16))},tabIndex:0,"aria-valuemin":200,"aria-valuemax":600,"aria-valuenow":tj,className:(0,tf.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",tM&&"bg-primary/60")})]}),(0,t.jsxs)("div",{className:"flex-1 flex flex-col min-w-0 relative",children:[tv&&(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"hidden md:flex absolute left-2 top-2 z-10 h-7 w-7 p-0",title:"Show sidebar",onClick:()=>tN(!1),children:(0,t.jsx)(D,{className:"h-3.5 w-3.5"})}),(0,t.jsxs)("div",{className:"md:hidden flex h-11 shrink-0 items-center justify-between gap-2 border-b bg-muted px-1",children:[(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-9 w-9 p-0",title:"Show sidebar",onClick:()=>{tN(!1),a3.useAIPanelStore.getState().close()},children:(0,t.jsx)(D,{className:"h-4 w-4"})}),(0,t.jsxs)("span",{className:"flex min-w-0 items-center gap-1.5 text-xs font-semibold tracking-tight text-muted-foreground",title:ts?.path,children:[ts&&(0,t.jsx)("span",{className:"editorial-tree-typeicon shrink-0",children:"app"===nc||"html"===nc?(0,t.jsx)(y.Globe,{className:"h-4 w-4 text-foreground/70"}):rg(ts.name)?(0,t.jsx)(j.Image,{className:"h-4 w-4 text-sunshine-700"}):rx(ts.name)?(0,t.jsx)(p.FileText,{className:"h-4 w-4 text-foreground/70"}):(0,t.jsx)(u.File,{className:"h-4 w-4 text-foreground/60"})}),(0,t.jsx)("span",{className:"truncate",children:ts?ts.name:"Wiki Viewer"})]}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-9 w-9 p-0",title:"AI Agent panel",onClick:()=>{a3.useAIPanelStore.getState().open(),tN(!0)},children:(0,t.jsx)(r,{className:"h-4 w-4"})})]}),ts?"node-app"===nc?(0,t.jsx)(tL,{path:ts.path,title:ts.name}):"app"===nc||"html"===nc?(e="html"===nc?`/api/assets/${ts.path}`:void 0,tc?(0,t.jsx)(tO,{path:ts.path,title:ts.name,src:e,fullscreen:!0,onExit:()=>td(!1)}):(0,t.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,t.jsxs)("div",{className:(0,tf.cn)("flex items-center justify-between px-4 py-2 border-b bg-muted shrink-0 editorial-doc-header",!ty&&tv&&"pl-11"),children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,t.jsx)("span",{className:"hidden md:inline-flex",children:(0,t.jsx)("span",{className:"editorial-tree-typeicon",children:(0,t.jsx)(y.Globe,{className:"h-4 w-4 shrink-0 text-foreground/70"})})}),(0,t.jsx)("span",{className:"hidden md:inline text-sm font-normal truncate",title:ts.path,children:ts.path})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[ns(ts,(0,t.jsxs)(t.Fragment,{children:["html"===nc&&!tV&&(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>t0(e=>!e),children:[tQ?(0,t.jsx)(y.Globe,{className:"mr-2 h-3.5 w-3.5"}):(0,t.jsx)(w.Code2,{className:"mr-2 h-3.5 w-3.5"}),tQ?"Show preview":"Show source"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>tp(e=>e+1),children:[(0,t.jsx)(F,{className:"mr-2 h-3.5 w-3.5"}),"Refresh"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>td(!0),children:[(0,t.jsx)(C,{className:"mr-2 h-3.5 w-3.5"}),"Open fullscreen"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>tP(!0),children:[(0,t.jsx)(P,{className:"mr-2 h-3.5 w-3.5"}),"Share"]})]})),"html"===nc&&!tV&&null!==tB&&(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Edit source",onClick:()=>{tZ(!0),tJ(tB),t3(null)},children:(0,t.jsx)(A,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{ti(null),tZ(!1)},children:(0,t.jsx)(K.X,{className:"h-3.5 w-3.5"})})]})]}),tV&&"html"===nc?(0,t.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:[(0,t.jsx)("textarea",{value:tX,onChange:e=>tJ(e.target.value),spellCheck:!1,className:"flex-1 w-full min-h-0 resize-none bg-background text-foreground px-4 py-3 font-mono text-[13px] leading-relaxed outline-none border-0"}),(0,t.jsxs)("div",{className:"border-t px-4 py-2 flex items-center justify-end gap-2 bg-muted shrink-0",children:[t5&&(0,t.jsx)("span",{className:"text-xs text-destructive mr-auto",children:t5}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",onClick:()=>{tZ(!1),t3(null)},children:"Cancel"}),(0,t.jsxs)(W.Button,{size:"sm",className:"gap-1",onClick:a1,disabled:t1,children:[t1&&(0,t.jsx)(_.Loader2,{className:"h-3 w-3 animate-spin"}),"Save"]})]})]}):tQ&&"html"===nc?(0,t.jsx)(tD,{path:ts.path,title:ts.name}):(0,t.jsx)(tO,{path:ts.path,title:ts.name,src:e},tu)]})):(0,t.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,t.jsxs)("div",{className:(0,tf.cn)("flex items-center justify-between px-4 py-2 border-b bg-muted shrink-0 editorial-doc-header",!ty&&tv&&"pl-11"),children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,t.jsx)("span",{className:"hidden md:inline-flex",children:(0,t.jsx)("span",{className:"editorial-tree-typeicon",children:rg(ts.name)?(0,t.jsx)(j.Image,{className:"h-4 w-4 shrink-0 text-sunshine-700"}):rx(ts.name)?(0,t.jsx)(p.FileText,{className:"h-4 w-4 shrink-0 text-foreground/70"}):(0,t.jsx)(u.File,{className:"h-4 w-4 shrink-0 text-foreground/60"})})}),(0,t.jsx)("span",{className:"hidden md:inline text-sm font-normal truncate",title:ts.path,children:ts.path}),ai&&(0,t.jsxs)("span",{className:"hidden md:flex items-center gap-1 text-[11px] text-muted-foreground shrink-0 ml-1",children:[(0,t.jsx)(N,{className:"h-3 w-3 shrink-0"}),(0,t.jsx)("span",{className:"truncate max-w-[100px]",children:ai.author}),(0,t.jsx)("span",{title:new Date(ai.date).toLocaleString(),className:"shrink-0",children:rd(ai.date)})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[ns(ts,(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>{ao?ac(!1):aF()},children:[(0,t.jsx)(v,{className:"mr-2 h-3.5 w-3.5"}),ao?"Hide history":"File history"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>tP(!0),children:[(0,t.jsx)(P,{className:"mr-2 h-3.5 w-3.5"}),"Share"]}),!tV&&(0,t.jsxs)(tR.DropdownMenuItem,{onClick:aq,disabled:tW,children:[tW?(0,t.jsx)(_.Loader2,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(F,{className:"mr-2 h-3.5 w-3.5"}),"Refresh"]}),nf&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tR.DropdownMenuSeparator,{}),(0,t.jsx)(tR.DropdownMenuLabel,{className:"text-[11px] text-muted-foreground",children:"Width"}),n9.VIEW_WIDTH_ORDER.map(e=>(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>nh(e),className:"flex items-center justify-between text-xs",children:[n9.VIEW_WIDTH_LABEL[e],e===nm&&(0,t.jsx)(s.Check,{className:"h-3.5 w-3.5"})]},e)),(0,t.jsx)(tR.DropdownMenuSeparator,{}),(0,t.jsx)(tR.DropdownMenuLabel,{className:"text-[11px] text-muted-foreground",children:"Alignment"}),n9.VIEW_ALIGN_ORDER.map(e=>(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>nx(e),className:"flex items-center justify-between text-xs",children:[n9.VIEW_ALIGN_LABEL[e],e===np&&(0,t.jsx)(s.Check,{className:"h-3.5 w-3.5"})]},e))]})]})),rx(ts.name)&&!tV&&(null!==tB||rf(ts.name))&&(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{tZ(!0),tJ(tB??""),t3(null),rf(ts.name)&&nn.useEditorStore.getState().loadPage(ts.path)},children:(0,t.jsx)(A,{className:"h-3.5 w-3.5"})}),rx(ts.name)&&tV&&rf(ts.name)&&(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Done editing",onClick:()=>{tZ(!1),t3(null)},children:(0,t.jsx)(O.Eye,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{ti(null),tz(null),tZ(!1)},children:(0,t.jsx)(K.X,{className:"h-3.5 w-3.5"})})]})]}),ao&&(0,t.jsxs)("div",{className:"border-b bg-muted/30 shrink-0 max-h-[40vh] overflow-auto",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between px-4 py-1.5 border-b",children:[(0,t.jsx)("span",{className:"text-xs font-semibold text-muted-foreground",children:"History"}),(0,t.jsx)("button",{type:"button",className:"text-muted-foreground hover:text-foreground",onClick:()=>ac(!1),children:(0,t.jsx)(K.X,{className:"h-3.5 w-3.5"})})]}),am?(0,t.jsx)("div",{className:"flex justify-center py-4",children:(0,t.jsx)(_.Loader2,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):0===ad.length?(0,t.jsx)("p",{className:"px-4 py-3 text-xs text-muted-foreground",children:"No history found."}):(0,t.jsx)("div",{children:ad.map(e=>(0,t.jsxs)("div",{children:[(0,t.jsx)("button",{type:"button",className:(0,tf.cn)("w-full text-left px-4 py-2 hover:bg-muted transition-colors",ah===e.sha&&"bg-muted"),onClick:()=>void aL(e.sha),children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("code",{className:"text-[11px] font-mono text-muted-foreground shrink-0",children:e.shortSha}),(0,t.jsx)("span",{className:"flex-1 truncate text-xs",children:e.message}),(0,t.jsx)("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:e.author}),(0,t.jsx)("span",{className:"shrink-0 text-[11px] text-muted-foreground",title:new Date(e.date).toLocaleString(),children:rd(e.date)})]})}),ah===e.sha&&(0,t.jsx)("div",{className:"border-t",children:ab?(0,t.jsx)("div",{className:"flex justify-center py-3",children:(0,t.jsx)(_.Loader2,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):null!==af?(0,t.jsx)("pre",{className:"overflow-auto px-4 py-2 text-[11px] font-mono leading-relaxed whitespace-pre text-foreground/80 max-h-60",children:af}):null})]},e.sha))})]}),nd?(0,t.jsx)(es,{path:ts.path,size:ts.size??0,onOpen:()=>to(ts.path)}):tV?(0,t.jsx)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:rf(ts.name)?(0,t.jsx)(et.KBEditor,{}):(0,t.jsx)("textarea",{value:tX,onChange:e=>tJ(e.target.value),spellCheck:!1,className:"flex-1 w-full min-h-0 resize-none bg-background text-foreground px-4 py-3 font-mono text-[13px] leading-relaxed outline-none border-0"})}):rf(ts.name)?(0,t.jsx)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:tW?(0,t.jsx)("div",{className:"flex justify-center py-8",children:(0,t.jsx)(_.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):(0,t.jsx)(et.KBEditor,{mode:"viewing"})}):"csv"===nc||"pdf"===nc||"mermaid"===nc||"notebook"===nc||"image"===nc||"media"===nc||"docx"===nc||"xlsx"===nc||"pptx"===nc||"source"===nc||"fallback"===nc?(0,t.jsx)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:tW?(0,t.jsx)("div",{className:"flex justify-center py-8",children:(0,t.jsx)(_.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):"csv"===nc?(0,t.jsx)(ee,{path:ts.path,title:ts.name}):"pdf"===nc?(0,t.jsx)(rc,{path:ts.path,title:ts.name}):"mermaid"===nc?(0,t.jsx)(ec,{path:ts.path,title:ts.name}):"notebook"===nc?(0,t.jsx)(tm,{path:ts.path,title:ts.name}):"image"===nc?(0,t.jsx)(ei,{path:ts.path,title:ts.name}):"media"===nc?(0,t.jsx)(el,{path:ts.path,title:ts.name,type:["mp4","webm","mov","m4v"].includes(rm(ts.name))?"video":"audio"}):"docx"===nc?(0,t.jsx)(th,{path:ts.path,title:ts.name}):"xlsx"===nc?(0,t.jsx)(tg,{path:ts.path,title:ts.name}):"pptx"===nc?(0,t.jsx)(tx,{path:ts.path,title:ts.name}):"source"===nc?(0,t.jsx)(tD,{path:ts.path,title:ts.name}):(0,t.jsx)(ea,{path:ts.path,title:ts.name})},tb):(0,t.jsx)("div",{className:"flex-1 overflow-auto p-4 min-h-0",children:(0,t.jsx)("div",{className:(0,tf.cn)("w-full",nb,ng),children:tW?(0,t.jsx)("div",{className:"flex justify-center py-8",children:(0,t.jsx)(_.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):null!==tB?(0,t.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-words leading-relaxed",children:tB}):rx(ts.name)?(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Could not load file."}):(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Preview not available for this file type."})})}),tV&&!rf(ts.name)&&(0,t.jsxs)("div",{className:"border-t px-4 py-2 flex items-center justify-end gap-2 bg-muted shrink-0",children:[t5&&(0,t.jsx)("span",{className:"text-xs text-destructive mr-auto",children:t5}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",onClick:()=>{tZ(!1),t3(null)},children:"Cancel"}),(0,t.jsxs)(W.Button,{size:"sm",className:"gap-1",onClick:a1,disabled:t1,children:[t1&&(0,t.jsx)(_.Loader2,{className:"h-3 w-3 animate-spin"}),"Save"]})]})]}):(0,t.jsx)("div",{className:"flex-1 flex flex-col items-center justify-center",children:(0,t.jsxs)("div",{className:"flex flex-col items-center gap-2 text-center px-4",children:[(0,t.jsx)(p.FileText,{className:"h-8 w-8 text-muted-foreground"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Select a file to view or edit"})]})})]}),(0,t.jsx)(aN,{open:tF,onOpenChange:tP,filePath:ts?.path??""}),(0,t.jsx)(ae,{open:tT,onOpenChange:tI}),(0,t.jsx)(nu,{currentPath:ts?.path}),(0,t.jsx)("input",{ref:eX,type:"file",multiple:!0,className:"hidden",onChange:e=>{e.target.files&&a5(e.target.files,eJ.current)}}),(0,t.jsx)(V,{open:!!te,onOpenChange:e=>{e||tt(null)},title:ta?"Delete folder?":"Delete file?",description:ta?`"${te?.split("/").pop()}" and all its contents will be permanently deleted.`:`"${te?.split("/").pop()}" will be permanently removed.`,onConfirm:ni}),(0,t.jsx)(V,{open:!!ed,onOpenChange:e=>{e||eu(null)},title:"Delete workspace?",description:`"${J.find(e=>e.id===ed)?.name??""}" will be removed from the workspace list. Files on disk are NOT deleted.`,onConfirm:aX})]})]},G??"none")}],952683)}]);
17
+ ${t}/api/agent/files/${e??"<path/to/file.md>"}`;await navigator.clipboard.writeText(n),a(!0),setTimeout(()=>a(!1),1500)},[e])}}(e??null),[m,p]=(0,H.useState)(""),h=(0,H.useRef)(null),x=window.location.origin,f=(0,H.useCallback)(()=>nc,[]),g=(0,H.useCallback)(()=>m.replace(/\$WIKI_URL/g,x),[m,x]),b=(0,H.useCallback)(()=>`npx wiki-viewer-mcp register --url ${x} --id ai:myagent --name "My Agent"`,[x]),w=(0,H.useCallback)(()=>JSON.stringify({servers:{"wiki-viewer":{command:"npx",args:["wiki-viewer-mcp"],env:{WIKI_VIEWER_URL:x,WIKI_VIEWER_TOKEN:"<token from register>",WIKI_VIEWER_AGENT_ID:"ai:myagent"}}}},null,2),[x]),y=nd(f),v=nd(g),N=nd(b),j=nd(w);return((0,H.useEffect)(()=>{if(a)return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e);function e(e){"Escape"===e.key&&n()}},[a,n]),(0,H.useEffect)(()=>{a&&h.current?.focus()},[a]),(0,H.useEffect)(()=>{if(!a)return;c();let e=setInterval(()=>void c(),1e4);return()=>clearInterval(e)},[a,c]),(0,H.useEffect)(()=>{a&&fetch("/api/agents/install").then(e=>e.json()).then(e=>{e.bootstrapPrompt&&p(e.bootstrapPrompt)}).catch(()=>void 0)},[a]),a)?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"fixed inset-0 z-40 bg-overlay backdrop-blur-[1px]",onClick:n,"aria-hidden":!0}),(0,t.jsxs)("aside",{ref:h,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,t.jsxs)("div",{className:"flex items-center justify-between border-b border-border px-4 py-3 shrink-0",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(r,{className:"h-4 w-4 text-muted-foreground"}),(0,t.jsx)("span",{className:"text-sm font-semibold",children:"AI Agent"})]}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:n,title:"Close panel (Esc)",children:(0,t.jsx)(K.X,{className:"h-3.5 w-3.5"})})]}),(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto space-y-5 px-4 py-4",children:[(0,t.jsxs)("section",{className:"rounded-md border border-border bg-muted/30 p-3",children:[(0,t.jsx)("p",{className:"text-sm font-medium text-foreground",children:"Work with this wiki using AI"}),(0,t.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,t.jsx)("span",{className:"font-medium text-foreground/80",children:"Agents"})," below before it gets access."]})]}),(0,t.jsxs)("section",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,t.jsx)("p",{className:"text-xs font-semibold text-foreground",children:"Co-write docs with you"}),(0,t.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Edits arrive as suggestions with comments you accept or revert. No MCP needed."}),(0,t.jsx)(W.Button,{size:"sm",variant:"outline",className:"h-7 w-full text-xs gap-1.5",onClick:()=>void v.copy(),disabled:!m,children:v.copied?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(s.Check,{className:"h-3.5 w-3.5 text-green-500"})," Copied!"]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(o.Copy,{className:"h-3.5 w-3.5"})," Paste into any chatbot"]})}),(0,t.jsxs)("p",{className:"text-[10px] text-muted-foreground/50 pt-1",children:["Or install once so it sticks"," ",(0,t.jsx)("span",{className:"text-muted-foreground/40",children:"· Claude, OpenCode"}),":"]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("code",{className:"flex-1 text-[10px] font-mono text-foreground/80 truncate bg-muted rounded px-1 py-0.5",children:nc}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0",title:"Copy this command",onClick:()=>void y.copy(),children:y.copied?(0,t.jsx)(s.Check,{className:"h-3.5 w-3.5 text-green-500"}):(0,t.jsx)(o.Copy,{className:"h-3.5 w-3.5"})})]})]}),(0,t.jsxs)("div",{className:"rounded-md border border-border bg-muted/40 p-3 space-y-1.5",children:[(0,t.jsxs)("p",{className:"text-xs font-semibold text-foreground",children:["Edit files directly"," ",(0,t.jsx)("span",{className:"font-normal text-muted-foreground/60",children:"· Claude Code, Cursor, Codex"})]}),(0,t.jsx)("p",{className:"text-[10px] text-muted-foreground/70",children:"Native read / search / edit tools over MCP. Run to request access:"}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("code",{className:"flex-1 text-[10px] font-mono text-foreground/80 truncate bg-muted rounded px-1 py-0.5",children:b()}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 shrink-0",title:"Copy this command",onClick:()=>void N.copy(),children:N.copied?(0,t.jsx)(s.Check,{className:"h-3.5 w-3.5 text-green-500"}):(0,t.jsx)(o.Copy,{className:"h-3.5 w-3.5"})})]}),(0,t.jsxs)("p",{className:"text-[10px] text-muted-foreground/50",children:["Approve in ",(0,t.jsx)("span",{className:"font-medium text-foreground/70",children:"Agents"}),", then add to your tool:"]}),(0,t.jsx)(W.Button,{size:"sm",variant:"outline",className:"h-7 w-full text-xs gap-1.5",onClick:()=>void j.copy(),children:j.copied?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(s.Check,{className:"h-3.5 w-3.5 text-green-500"})," Copied!"]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(o.Copy,{className:"h-3.5 w-3.5"})," Copy config (mcp.json)"]})})]}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[(0,t.jsx)("span",{className:"text-[10px] text-muted-foreground/50",children:"For developers:"}),(0,t.jsxs)("button",{type:"button",onClick:()=>void u(),className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[d?(0,t.jsx)(s.Check,{className:"h-3 w-3 text-green-500"}):(0,t.jsx)(o.Copy,{className:"h-3 w-3"})," curl example"]}),(0,t.jsxs)("a",{href:"/api/agents/skill",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[(0,t.jsx)(en.ExternalLink,{className:"h-3 w-3"})," skill"]}),(0,t.jsxs)("a",{href:"/api/agents/install",target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-[10px] text-primary hover:underline",children:[(0,t.jsx)(en.ExternalLink,{className:"h-3 w-3"})," install JSON"]})]})]}),(0,t.jsx)(na,{}),(0,t.jsxs)("section",{className:"space-y-2",children:[(0,t.jsxs)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:["Active Connections"," ",(0,t.jsx)("span",{className:"normal-case font-normal text-muted-foreground/50",children:"(last 5 min)"})]}),(0,t.jsx)("div",{className:"rounded-md border border-border bg-muted/40 p-3",children:0===l.length?(0,t.jsxs)("p",{className:"text-xs text-muted-foreground/60 flex items-center gap-1.5",children:[(0,t.jsx)(a5,{className:"h-3.5 w-3.5"}),"No recent activity"]}):(0,t.jsx)("ul",{className:"space-y-1.5",children:l.map(e=>(0,t.jsxs)("li",{className:"flex items-center justify-between text-xs",children:[(0,t.jsx)("span",{className:"font-mono text-foreground/80 truncate",children:e.by}),(0,t.jsxs)("span",{className:"text-muted-foreground shrink-0",children:[e.opCount," op",1!==e.opCount?"s":""]})]},e.by))})})]}),(0,t.jsxs)("section",{className:"space-y-2",children:[(0,t.jsx)("h3",{className:"text-xs font-semibold uppercase tracking-widest text-muted-foreground",children:"Recent Activity"}),(0,t.jsx)("div",{className:"rounded-md border border-border bg-muted/40 px-3 py-2 max-h-72 overflow-y-auto",children:(0,t.jsx)(no,{activity:i})})]}),(0,t.jsx)("section",{children:(0,t.jsx)("a",{href:"/docs/agent-collab-plan.md",target:"_blank",rel:"noreferrer",className:"text-xs text-primary underline hover:no-underline",children:"Agent collaboration docs →"})})]})]})]}):null}var nm=e.i(580330),np=e.i(877031),nh=/[\\\/_+.#"@\[\(\{&]/,nx=/[\\\/_+.#"@\[\(\{&]/g,nf=/[\s-]/,ng=/[\s-]/g;function nb(e){return e.toLowerCase().replace(ng," ")}var nw=e.i(750110),ny=e.i(433616),nv='[cmdk-group=""]',nN='[cmdk-group-items=""]',nj='[cmdk-item=""]',nk=`${nj}:not([aria-disabled="true"])`,n_="cmdk-item-select",nC="data-value",nE=(e,t,a)=>{var n;return n=e,function e(t,a,n,r,s,i,l){if(i===a.length)return s===t.length?1:.99;var o=`${s},${i}`;if(void 0!==l[o])return l[o];for(var c,d,u,m,p=r.charAt(i),h=n.indexOf(p,s),x=0;h>=0;)(c=e(t,a,n,r,h+1,i+1,l))>x&&(h===s?c*=1:nh.test(t.charAt(h-1))?(c*=.8,(u=t.slice(s,h-1).match(nx))&&s>0&&(c*=Math.pow(.999,u.length))):nf.test(t.charAt(h-1))?(c*=.9,(m=t.slice(s,h-1).match(ng))&&s>0&&(c*=Math.pow(.999,m.length))):(c*=.17,s>0&&(c*=Math.pow(.999,h-s))),t.charAt(h)!==a.charAt(i)&&(c*=.9999)),(c<.1&&n.charAt(h-1)===r.charAt(i+1)||r.charAt(i+1)===r.charAt(i)&&n.charAt(h-1)!==r.charAt(i))&&.1*(d=e(t,a,n,r,h+1,i+2,l))>c&&(c=.1*d),c>x&&(x=c),h=n.indexOf(p,h+1);return l[o]=x,x}(n=a&&a.length>0?`${n+" "+a.join(" ")}`:n,t,nb(n),nb(t),0,0,{})},nS=H.createContext(void 0),nM=H.createContext(void 0),nD=H.createContext(void 0),nA=H.forwardRef((e,t)=>{let a=n$(()=>{var t,a;return{search:"",value:null!=(a=null!=(t=e.value)?t:e.defaultValue)?a:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),n=n$(()=>new Set),r=n$(()=>new Map),s=n$(()=>new Map),i=n$(()=>new Set),l=nB(e),{label:o,children:c,value:d,onValueChange:u,filter:m,shouldFilter:p,loop:h,disablePointerSelection:x=!1,vimBindings:f=!0,...g}=e,b=(0,ny.useId)(),w=(0,ny.useId)(),y=(0,ny.useId)(),v=H.useRef(null),N=nK();nz(()=>{if(void 0!==d){let e=d.trim();a.current.value=e,j.emit()}},[d]),nz(()=>{N(6,M)},[]);let j=H.useMemo(()=>({subscribe:e=>(i.current.add(e),()=>i.current.delete(e)),snapshot:()=>a.current,setState:(e,t,n)=>{var r,s,i,o;if(!Object.is(a.current[e],t)){if(a.current[e]=t,"search"===e)S(),C(),N(1,E);else if("value"===e){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let e=document.getElementById(y);e?e.focus():null==(r=document.getElementById(b))||r.focus()}if(N(7,()=>{var e;a.current.selectedItemId=null==(e=D())?void 0:e.id,j.emit()}),n||N(5,M),(null==(s=l.current)?void 0:s.value)!==void 0){null==(o=(i=l.current).onValueChange)||o.call(i,null!=t?t:"");return}}j.emit()}},emit:()=>{i.current.forEach(e=>e())}}),[]),k=H.useMemo(()=>({value:(e,t,n)=>{var r;t!==(null==(r=s.current.get(e))?void 0:r.value)&&(s.current.set(e,{value:t,keywords:n}),a.current.filtered.items.set(e,_(t,n)),N(2,()=>{C(),j.emit()}))},item:(e,t)=>(n.current.add(e),t&&(r.current.has(t)?r.current.get(t).add(e):r.current.set(t,new Set([e]))),N(3,()=>{S(),C(),a.current.value||E(),j.emit()}),()=>{s.current.delete(e),n.current.delete(e),a.current.filtered.items.delete(e);let t=D();N(4,()=>{S(),(null==t?void 0:t.getAttribute("id"))===e&&E(),j.emit()})}),group:e=>(r.current.has(e)||r.current.set(e,new Set),()=>{s.current.delete(e),r.current.delete(e)}),filter:()=>l.current.shouldFilter,label:o||e["aria-label"],getDisablePointerSelection:()=>l.current.disablePointerSelection,listId:b,inputId:y,labelId:w,listInnerRef:v}),[]);function _(e,t){var n,r;let s=null!=(r=null==(n=l.current)?void 0:n.filter)?r:nE;return e?s(e,a.current.search,t):0}function C(){if(!a.current.search||!1===l.current.shouldFilter)return;let e=a.current.filtered.items,t=[];a.current.filtered.groups.forEach(a=>{let n=r.current.get(a),s=0;n.forEach(t=>{s=Math.max(e.get(t),s)}),t.push([a,s])});let n=v.current;A().sort((t,a)=>{var n,r;let s=t.getAttribute("id"),i=a.getAttribute("id");return(null!=(n=e.get(i))?n:0)-(null!=(r=e.get(s))?r:0)}).forEach(e=>{let t=e.closest(nN);t?t.appendChild(e.parentElement===t?e:e.closest(`${nN} > *`)):n.appendChild(e.parentElement===n?e:e.closest(`${nN} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{var t;let a=null==(t=v.current)?void 0:t.querySelector(`${nv}[${nC}="${encodeURIComponent(e[0])}"]`);null==a||a.parentElement.appendChild(a)})}function E(){let e=A().find(e=>"true"!==e.getAttribute("aria-disabled")),t=null==e?void 0:e.getAttribute(nC);j.setState("value",t||void 0)}function S(){var e,t,i,o;if(!a.current.search||!1===l.current.shouldFilter){a.current.filtered.count=n.current.size;return}a.current.filtered.groups=new Set;let c=0;for(let r of n.current){let n=_(null!=(t=null==(e=s.current.get(r))?void 0:e.value)?t:"",null!=(o=null==(i=s.current.get(r))?void 0:i.keywords)?o:[]);a.current.filtered.items.set(r,n),n>0&&c++}for(let[e,t]of r.current)for(let n of t)if(a.current.filtered.items.get(n)>0){a.current.filtered.groups.add(e);break}a.current.filtered.count=c}function M(){var e,t,a;let n=D();n&&((null==(e=n.parentElement)?void 0:e.firstChild)===n&&(null==(a=null==(t=n.closest(nv))?void 0:t.querySelector('[cmdk-group-heading=""]'))||a.scrollIntoView({block:"nearest"})),n.scrollIntoView({block:"nearest"}))}function D(){var e;return null==(e=v.current)?void 0:e.querySelector(`${nj}[aria-selected="true"]`)}function A(){var e;return Array.from((null==(e=v.current)?void 0:e.querySelectorAll(nk))||[])}function O(e){let t=A()[e];t&&j.setState("value",t.getAttribute(nC))}function T(e){var t;let a=D(),n=A(),r=n.findIndex(e=>e===a),s=n[r+e];null!=(t=l.current)&&t.loop&&(s=r+e<0?n[n.length-1]:r+e===n.length?n[0]:n[r+e]),s&&j.setState("value",s.getAttribute(nC))}function I(e){let t=D(),a=null==t?void 0:t.closest(nv),n;for(;a&&!n;)n=null==(a=e>0?function(e,t){let a=e.nextElementSibling;for(;a;){if(a.matches(t))return a;a=a.nextElementSibling}}(a,nv):function(e,t){let a=e.previousElementSibling;for(;a;){if(a.matches(t))return a;a=a.previousElementSibling}}(a,nv))?void 0:a.querySelector(nk);n?j.setState("value",n.getAttribute(nC)):T(e)}let R=()=>O(A().length-1),F=e=>{e.preventDefault(),e.metaKey?R():e.altKey?I(1):T(1)},L=e=>{e.preventDefault(),e.metaKey?O(0):e.altKey?I(-1):T(-1)};return H.createElement(nw.Primitive.div,{ref:t,tabIndex:-1,...g,"cmdk-root":"",onKeyDown:e=>{var t;null==(t=g.onKeyDown)||t.call(g,e);let a=e.nativeEvent.isComposing||229===e.keyCode;if(!(e.defaultPrevented||a))switch(e.key){case"n":case"j":f&&e.ctrlKey&&F(e);break;case"ArrowDown":F(e);break;case"p":case"k":f&&e.ctrlKey&&L(e);break;case"ArrowUp":L(e);break;case"Home":e.preventDefault(),O(0);break;case"End":e.preventDefault(),R();break;case"Enter":{e.preventDefault();let t=D();if(t){let e=new Event(n_);t.dispatchEvent(e)}}}}},H.createElement("label",{"cmdk-label":"",htmlFor:k.inputId,id:k.labelId,style:nW},o),nH(e,e=>H.createElement(nM.Provider,{value:j},H.createElement(nS.Provider,{value:k},e))))}),nO=H.forwardRef((e,t)=>{var a,n;let r=(0,ny.useId)(),s=H.useRef(null),i=H.useContext(nD),l=H.useContext(nS),o=nB(e),c=null!=(n=null==(a=o.current)?void 0:a.forceMount)?n:null==i?void 0:i.forceMount;nz(()=>{if(!c)return l.item(r,null==i?void 0:i.id)},[c]);let d=nq(r,s,[e.value,e.children,s],e.keywords),u=H.useContext(nM),m=nU(e=>e.value&&e.value===d.current),p=nU(e=>!!c||!1===l.filter()||!e.search||e.filtered.items.get(r)>0);function h(){var e,t;x(),null==(t=(e=o.current).onSelect)||t.call(e,d.current)}function x(){u.setState("value",d.current,!0)}if(H.useEffect(()=>{let t=s.current;if(!(!t||e.disabled))return t.addEventListener(n_,h),()=>t.removeEventListener(n_,h)},[p,e.onSelect,e.disabled]),!p)return null;let{disabled:f,value:g,onSelect:b,forceMount:w,keywords:y,...v}=e;return H.createElement(nw.Primitive.div,{ref:(0,as.composeRefs)(s,t),...v,id:r,"cmdk-item":"",role:"option","aria-disabled":!!f,"aria-selected":!!m,"data-disabled":!!f,"data-selected":!!m,onPointerMove:f||l.getDisablePointerSelection()?void 0:x,onClick:f?void 0:h},e.children)}),nT=H.forwardRef((e,t)=>{let{heading:a,children:n,forceMount:r,...s}=e,i=(0,ny.useId)(),l=H.useRef(null),o=H.useRef(null),c=(0,ny.useId)(),d=H.useContext(nS),u=nU(e=>!!r||!1===d.filter()||!e.search||e.filtered.groups.has(i));nz(()=>d.group(i),[]),nq(i,l,[e.value,e.heading,o]);let m=H.useMemo(()=>({id:i,forceMount:r}),[r]);return H.createElement(nw.Primitive.div,{ref:(0,as.composeRefs)(l,t),...s,"cmdk-group":"",role:"presentation",hidden:!u||void 0},a&&H.createElement("div",{ref:o,"cmdk-group-heading":"","aria-hidden":!0,id:c},a),nH(e,e=>H.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":a?c:void 0},H.createElement(nD.Provider,{value:m},e))))}),nI=H.forwardRef((e,t)=>{let{alwaysRender:a,...n}=e,r=H.useRef(null),s=nU(e=>!e.search);return a||s?H.createElement(nw.Primitive.div,{ref:(0,as.composeRefs)(r,t),...n,"cmdk-separator":"",role:"separator"}):null}),nR=H.forwardRef((e,t)=>{let{onValueChange:a,...n}=e,r=null!=e.value,s=H.useContext(nM),i=nU(e=>e.search),l=nU(e=>e.selectedItemId),o=H.useContext(nS);return H.useEffect(()=>{null!=e.value&&s.setState("search",e.value)},[e.value]),H.createElement(nw.Primitive.input,{ref:t,...n,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":o.listId,"aria-labelledby":o.labelId,"aria-activedescendant":l,id:o.inputId,type:"text",value:r?e.value:i,onChange:e=>{r||s.setState("search",e.target.value),null==a||a(e.target.value)}})}),nF=H.forwardRef((e,t)=>{let{children:a,label:n="Suggestions",...r}=e,s=H.useRef(null),i=H.useRef(null),l=nU(e=>e.selectedItemId),o=H.useContext(nS);return H.useEffect(()=>{if(i.current&&s.current){let e=i.current,t=s.current,a,n=new ResizeObserver(()=>{a=requestAnimationFrame(()=>{let a=e.offsetHeight;t.style.setProperty("--cmdk-list-height",a.toFixed(1)+"px")})});return n.observe(e),()=>{cancelAnimationFrame(a),n.unobserve(e)}}},[]),H.createElement(nw.Primitive.div,{ref:(0,as.composeRefs)(s,t),...r,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":l,"aria-label":n,id:o.listId},nH(e,e=>H.createElement("div",{ref:(0,as.composeRefs)(i,o.listInnerRef),"cmdk-list-sizer":""},e)))}),nL=H.forwardRef((e,t)=>{let{open:a,onOpenChange:n,overlayClassName:r,contentClassName:s,container:i,...l}=e;return H.createElement(tW.Root,{open:a,onOpenChange:n},H.createElement(tW.Portal,{container:i},H.createElement(tW.Overlay,{"cmdk-overlay":"",className:r}),H.createElement(tW.Content,{"aria-label":e.label,"cmdk-dialog":"",className:s},H.createElement(nA,{ref:t,...l}))))}),nP=Object.assign(nA,{List:nF,Item:nO,Input:nR,Group:nT,Separator:nI,Dialog:nL,Empty:H.forwardRef((e,t)=>nU(e=>0===e.filtered.count)?H.createElement(nw.Primitive.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),Loading:H.forwardRef((e,t)=>{let{progress:a,children:n,label:r="Loading...",...s}=e;return H.createElement(nw.Primitive.div,{ref:t,...s,"cmdk-loading":"",role:"progressbar","aria-valuenow":a,"aria-valuemin":0,"aria-valuemax":100,"aria-label":r},nH(e,e=>H.createElement("div",{"aria-hidden":!0},e)))})});function nB(e){let t=H.useRef(e);return nz(()=>{t.current=e}),t}var nz="u"<typeof window?H.useEffect:H.useLayoutEffect;function n$(e){let t=H.useRef();return void 0===t.current&&(t.current=e()),t}function nU(e){let t=H.useContext(nM),a=()=>e(t.snapshot());return H.useSyncExternalStore(t.subscribe,a,a)}function nq(e,t,a,n=[]){let r=H.useRef(),s=H.useContext(nS);return nz(()=>{var i;let l=(()=>{var e;for(let t of a){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():r.current}})(),o=n.map(e=>e.trim());s.value(e,l,o),null==(i=t.current)||i.setAttribute(nC,l),r.current=l}),r}var nK=()=>{let[e,t]=H.useState(),a=n$(()=>new Map);return nz(()=>{a.current.forEach(e=>e()),a.current=new Map},[e]),(e,n)=>{a.current.set(e,n),t({})}};function nH({asChild:e,children:t},a){let n;return e&&H.isValidElement(t)?H.cloneElement("function"==typeof(n=t.type)?n(t.props):"render"in n?n.render(t.props):t,{ref:t.ref},a(t.props.children)):a(t)}var nW={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};let nG=(0,n.default)("search",[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]),nV=H.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nP,{ref:n,className:(0,tf.cn)("flex h-full w-full flex-col overflow-hidden rounded-sm bg-popover text-popover-foreground",e),...a}));function nZ({children:e,shouldFilter:a,...n}){return(0,t.jsx)(G.Dialog,{...n,children:(0,t.jsxs)(G.DialogContent,{className:"overflow-hidden p-0 shadow-golden max-w-lg",children:[(0,t.jsx)(G.DialogTitle,{className:"sr-only",children:"Search"}),(0,t.jsx)(nV,{shouldFilter:a,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})]})})}nV.displayName=nP.displayName;let nX=H.forwardRef(({className:e,...a},n)=>(0,t.jsxs)("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[(0,t.jsx)(nG,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),(0,t.jsx)(nP.Input,{ref:n,className:(0,tf.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),...a})]}));nX.displayName=nP.Input.displayName;let nJ=H.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nP.List,{ref:n,className:(0,tf.cn)("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...a}));nJ.displayName=nP.List.displayName;let nQ=H.forwardRef((e,a)=>(0,t.jsx)(nP.Empty,{ref:a,className:"py-6 text-center text-sm text-muted-foreground",...e}));nQ.displayName=nP.Empty.displayName;let nY=H.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nP.Group,{ref:n,className:(0,tf.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),...a}));nY.displayName=nP.Group.displayName;let n0=H.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nP.Separator,{ref:n,className:(0,tf.cn)("-mx-1 h-px bg-border",e),...a}));n0.displayName=nP.Separator.displayName;let n1=H.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nP.Item,{ref:n,className:(0,tf.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),...a}));n1.displayName=nP.Item.displayName;let n2=null,n5=null,n3=(0,t1.create)(e=>({query:"",results:[],loading:!1,truncated:!1,open:!1,setQuery:t=>e({query:t}),setOpen:t=>e({open:t}),clear:()=>{n5&&clearTimeout(n5),n2?.abort(),e({query:"",results:[],loading:!1,truncated:!1})},search:t=>(n5&&clearTimeout(n5),t.trim())?(e({loading:!0}),new Promise(a=>{n5=setTimeout(()=>{n4(e,t).finally(a)},150)})):(n2?.abort(),e({results:[],loading:!1,truncated:!1}),Promise.resolve())}));async function n4(e,t){n2?.abort();let a=new AbortController;n2=a;try{let n=await (0,X.wsFetch)("/api/wiki/search",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:t,limit:30}),signal:a.signal});if(!n.ok)return void e({results:[],loading:!1,truncated:!1});let r=await n.json();if(a.signal.aborted)return;e({results:r.matches??[],truncated:!!r.truncated,loading:!1})}catch(t){"AbortError"!==t.name&&e({loading:!1})}}var n9=e.i(395624);function n7({html:e}){let a=function(e){let t,a=[],n=/<mark>([\s\S]*?)<\/mark>/g,r=0;for(;null!==(t=n.exec(e));)t.index>r&&a.push({text:e.slice(r,t.index),mark:!1}),a.push({text:t[1]??"",mark:!0}),r=t.index+t[0].length;return r<e.length&&a.push({text:e.slice(r),mark:!1}),a}(e);return(0,t.jsx)(t.Fragment,{children:a.map((e,a)=>e.mark?(0,t.jsx)("mark",{className:"bg-yellow-200 dark:bg-yellow-700 rounded-[2px] px-[1px]",children:e.text},a):(0,t.jsx)("span",{children:e.text},a))})}function n6({onOpenFile:e,recents:a=[],onToggleSidebar:n=()=>void 0,onNewFile:s=()=>void 0,onCopyPath:i=()=>void 0}){let l=n3(e=>e.open),c=n3(e=>e.setOpen),d=n3(e=>e.query),u=n3(e=>e.setQuery),p=n3(e=>e.results),h=n3(e=>e.loading),x=n3(e=>e.truncated),f=n3(e=>e.search),{resolvedTheme:g,setTheme:b}=(0,tH.useTheme)(),w=(0,a3.useAIPanelStore)(e=>e.toggle),y=(0,n9.useViewWidthStore)(e=>e.width),v=(0,n9.useViewWidthStore)(e=>e.cycle),N=d.trimStart(),j=""===N||N.startsWith(">"),k=""===N&&a.length>0,_=j?"":d;function C(e){e(),c(!1),u("")}(0,H.useEffect)(()=>{function e(e){(e.metaKey||e.ctrlKey)&&"k"===e.key.toLowerCase()&&(e.preventDefault(),c(!l))}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[l,c]),(0,H.useEffect)(()=>{if(!l||j)return;let e=setTimeout(()=>{f(_)},120);return()=>clearTimeout(e)},[_,j,l,f]);let E=(n9.VIEW_WIDTH_ORDER.indexOf(y)+1)%n9.VIEW_WIDTH_ORDER.length,M=n9.VIEW_WIDTH_LABEL[n9.VIEW_WIDTH_ORDER[E]];return(0,t.jsxs)(nZ,{open:l,onOpenChange:e=>{c(e),e||u("")},shouldFilter:!1,children:[(0,t.jsx)(nX,{placeholder:"Search files… ( > for actions )",value:d,onValueChange:u}),(0,t.jsxs)(nJ,{children:[k&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(nY,{heading:"Recent",children:a.map(a=>(0,t.jsxs)(n1,{value:`recent:${a.path}`,onSelect:()=>{e(a.path),c(!1),u("")},children:[(0,t.jsx)(aa,{className:"mr-2 h-4 w-4"}),(0,t.jsxs)("div",{className:"flex min-w-0 flex-col gap-0.5",children:[(0,t.jsx)("span",{className:"truncate font-medium",children:a.name}),(0,t.jsx)("span",{className:"truncate text-xs text-muted-foreground",children:a.path})]})]},a.path))}),(0,t.jsx)(n0,{})]}),j&&(0,t.jsxs)(nY,{heading:"Actions",children:[(0,t.jsxs)(n1,{value:"toggle-dark-mode",onSelect:()=>C(()=>b("dark"===g?"light":"dark")),children:["dark"===g?(0,t.jsx)(B.Sun,{className:"mr-2 h-4 w-4"}):(0,t.jsx)(S.Moon,{className:"mr-2 h-4 w-4"}),"dark"===g?"Switch to light mode":"Switch to dark mode"]}),(0,t.jsxs)(n1,{value:"toggle-ai-panel",onSelect:()=>C(w),children:[(0,t.jsx)(r,{className:"mr-2 h-4 w-4"}),"Toggle AI panel"]}),(0,t.jsxs)(n1,{value:"toggle-sidebar",onSelect:()=>C(n),children:[(0,t.jsx)(np.PanelLeft,{className:"mr-2 h-4 w-4"}),"Toggle sidebar"]}),(0,t.jsxs)(n1,{value:"new-file",onSelect:()=>C(s),children:[(0,t.jsx)(m.FilePlus,{className:"mr-2 h-4 w-4"}),"New file"]}),(0,t.jsxs)(n1,{value:"copy-path",onSelect:()=>C(i),children:[(0,t.jsx)(o.Copy,{className:"mr-2 h-4 w-4"}),"Copy current file path"]}),(0,t.jsxs)(n1,{value:"cycle-view-width",onSelect:()=>C(v),children:[(0,t.jsx)(nm.AlignCenter,{className:"mr-2 h-4 w-4"}),(0,t.jsxs)("span",{children:["Change view width"," ",(0,t.jsxs)("span",{className:"text-muted-foreground",children:["(",n9.VIEW_WIDTH_LABEL[y]," → ",M,")"]})]})]})]}),!j&&(0,t.jsxs)(t.Fragment,{children:[h&&(0,t.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:"Searching…"}),!h&&""!==_.trim()&&0===p.length&&(0,t.jsx)(nQ,{children:"No matches."}),p.length>0&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n0,{}),(0,t.jsx)(nY,{heading:x?"Top results (refine query for more)":"Results",children:p.map(a=>(0,t.jsx)(n1,{value:a.path,onSelect:()=>{e(a.path),c(!1),u("")},children:(0,t.jsxs)("div",{className:"flex min-w-0 flex-col gap-0.5",children:[(0,t.jsx)("span",{className:"truncate font-mono text-xs",children:a.path}),a.snippet&&(0,t.jsx)("span",{className:"truncate text-xs text-muted-foreground",children:(0,t.jsx)(n7,{html:a.snippet})})]})},a.path))})]})]})]})]})}function n8({onOpenFile:e}){let a=n3(e=>e.query),n=n3(e=>e.setQuery),r=n3(e=>e.results),s=n3(e=>e.loading),i=n3(e=>e.search),l=n3(e=>e.clear),[o,c]=(0,H.useState)(0),d=(0,H.useRef)(null);function u(t){let a=r[t];a&&(e(a.path),l())}return(0,H.useEffect)(()=>{c(0)},[r]),(0,H.useEffect)(()=>{let e=d.current?.querySelector(`[data-idx="${o}"]`);e?.scrollIntoView({block:"nearest"})},[o]),(0,t.jsxs)("div",{className:"flex flex-col gap-1 px-2 py-1.5",children:[(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)(nG,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 opacity-50"}),(0,t.jsx)("input",{type:"text",className:"w-full rounded-sm border bg-transparent py-1 pl-7 pr-2 text-xs outline-none focus:ring-1 focus:ring-ring",placeholder:"Search… (⌘K)",value:a,onChange:e=>{n(e.target.value),i(e.target.value)},onKeyDown:e=>{"Escape"===e.key?l():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(o)))}})]}),""!==a.trim()&&(0,t.jsxs)("div",{ref:d,className:"max-h-64 overflow-y-auto rounded-sm border bg-popover",children:[s&&(0,t.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"Searching…"}),!s&&0===r.length&&(0,t.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"No matches"}),r.map((e,a)=>(0,t.jsxs)("button",{type:"button","data-idx":a,onClick:()=>u(a),onMouseEnter:()=>c(a),className:`block w-full px-2 py-1 text-left ${a===o?"bg-accent":"hover:bg-accent"}`,children:[(0,t.jsx)("div",{className:"truncate font-mono text-xs",children:e.path}),e.snippet&&(0,t.jsx)("div",{className:"truncate text-[10px] text-muted-foreground",children:(0,t.jsx)(n7,{html:e.snippet})})]},e.path))]})]})}let re="wiki-sidebar-width";function rt(e){return Number.isNaN(e)?288:Math.min(600,Math.max(200,Math.round(e)))}let ra=(0,t1.create)(e=>({width:function(){let e=localStorage.getItem(re);if(e){let t=Number.parseInt(e,10);if(!Number.isNaN(t))return rt(t)}return 288}(),setWidth:t=>{let a=rt(t);localStorage.setItem(re,String(a)),e({width:a})}}));var rn=e.i(246542);let rr="wiki-show-hidden",rs=(0,t1.create)((e,t)=>({showHidden:"1"===localStorage.getItem(rr),toggle:()=>{let a=!t().showHidden;a?localStorage.setItem(rr,"1"):localStorage.removeItem(rr),e({showHidden:a})}})),ri="wiki-humanize-names",rl=(0,t1.create)((e,t)=>({humanize:"1"===localStorage.getItem(ri),toggle:()=>{let a=!t().humanize;a?localStorage.setItem(ri,"1"):localStorage.removeItem(ri),e({humanize:a})}}));function ro(e){let t=e.lastIndexOf("."),a=t>0&&t<e.length-1,n=a?e.slice(0,t):e,r=a?e.slice(t):"",s=n.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));return s.length?s.join(" ")+r:e}let rc=(0,tb.default)(()=>e.A(810497).then(e=>e.PdfViewer),{loadableGenerated:{modules:[904378]},ssr:!1});function rd(e){let t=new Date(e).getTime();if(!Number.isFinite(t))return"";let a=Math.floor(Math.max(0,Date.now()-t)/1e3);if(a<60)return"just now";let n=Math.floor(a/60);if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}let ru=new Set(["image","media","pdf","fallback","app","node-app","html"]);function rm(e){return e.split(".").pop()?.toLowerCase()??""}function rp(e,t){if("node-app"===t)return"node-app";if("app"===t)return"app";if("dir"===t)return"fallback";let a=e.split("/").pop()??e;if(a.startsWith(".")&&-1===a.indexOf(".",1))return"source";let n=rm(e);return n?["md","markdown"].includes(n)?"editor":"txt"===n?"text":["csv","tsv"].includes(n)?"csv":"pdf"===n?"pdf":["mmd","mermaid"].includes(n)?"mermaid":"ipynb"===n?"notebook":["png","jpg","jpeg","gif","webp","svg","avif","ico","bmp"].includes(n)?"image":["mp4","webm","mov","m4v","mp3","wav","ogg","m4a","aac"].includes(n)?"media":"docx"===n?"docx":["xlsx","xlsm"].includes(n)?"xlsx":"pptx"===n?"pptx":"html"===n?"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(n),"source"):"source"}let rh=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 rx(e){let t=rp(e,"file");return"editor"===t||"text"===t||rh.has(rm(e))}function rf(e){return["md","markdown"].includes(rm(e))}function rg(e){return"image"===rp(e,"file")}function rb(e){return"html"===rp(e,"file")}async function rw(e){let t=await (0,X.wsFetch)(`/api/wiki?dir=${encodeURIComponent(e)}`);return t.ok?(await t.json()).entries.map(t=>({name:t.name,path:e?`${e}/${t.name}`:t.name,type:t.type,size:t.size,modifiedAt:t.modifiedAt,expanded:!1,git:t.git})):[]}let ry=new Map,rv=new Map;async function rN(e){let t=ry.get(e);if(t)return ry.delete(e),t;let a=rv.get(e);if(a){let t=await a;return ry.delete(e),t}return null}function rj(e,t,a){return e.map(e=>e.path===t?a(e):e.children?{...e,children:rj(e.children,t,a)}:e)}let rk={contentVisibility:"auto",containIntrinsicSize:"auto 32px"};function r_({node:e,ctx:a,isPinned:n,activeWorkspaceId:r}){return(0,t.jsxs)(aV,{className:"w-48",children:[(0,t.jsxs)(aZ,{onSelect:()=>a.copyPath(e.path),children:[(0,t.jsx)(o.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),rf(e.name)&&(0,t.jsxs)(aZ,{onSelect:()=>a.copyWikiLink(e.name),children:[(0,t.jsx)(p.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,t.jsxs)(aZ,{onSelect:()=>a.copyUrl(e.path),children:[(0,t.jsx)(k.Link,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),"file"===e.type&&rx(e.name)&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(aZ,{onSelect:()=>a.copyRawContent(e.path),children:[(0,t.jsx)(p.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,t.jsxs)(aZ,{onSelect:()=>a.copyFormattedContent(e.path,e.name),children:[(0,t.jsx)(p.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),(0,t.jsx)(aX,{}),"dir"===e.type&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(aZ,{onSelect:()=>{e.expanded||a.toggleFolder(e),a.setNewFileParent(e.path),a.setNewFileName(""),a.setFileCreateError(null)},children:[(0,t.jsx)(m.FilePlus,{className:"mr-2 h-3.5 w-3.5"}),"New file here"]}),(0,t.jsxs)(aZ,{onSelect:()=>a.triggerUpload(e.path),children:[(0,t.jsx)(q.Upload,{className:"mr-2 h-3.5 w-3.5"}),"Upload here"]}),(0,t.jsxs)(aZ,{onSelect:()=>{a.setNewFolderParent(e.path),a.setNewFolderName(""),a.setFolderError(null)},children:[(0,t.jsx)(f,{className:"mr-2 h-3.5 w-3.5"}),"New subfolder"]}),(0,t.jsx)(aX,{})]}),(0,t.jsxs)(aZ,{onSelect:()=>a.handleDownload(e),children:[(0,t.jsx)(c.Download,{className:"mr-2 h-3.5 w-3.5"}),"file"===e.type?"Download":"Download as zip"]}),(0,t.jsxs)(aZ,{onSelect:()=>a.togglePin(e,r),children:[(0,t.jsx)(I,{className:(0,tf.cn)("mr-2 h-3.5 w-3.5",n&&"fill-current text-amber-400")}),n?"Unpin":"Pin to top"]}),(0,t.jsx)(aX,{}),(0,t.jsxs)(aZ,{className:"text-destructive focus:text-destructive",onSelect:()=>{a.setDeletingPath(e.path),a.setDeletingIsDir("file"!==e.type)},children:[(0,t.jsx)(U.Trash2,{className:"mr-2 h-3.5 w-3.5"}),"Delete"]})]})}function rC({name:e,type:a}){let n="h-3.5 w-3.5 shrink-0";return"dir"===a?(0,t.jsx)(h.Folder,{className:(0,tf.cn)(n,"text-warning")}):"app"===a?(0,t.jsx)(y.Globe,{className:(0,tf.cn)(n,"text-foreground/70")}):"node-app"===a?(0,t.jsx)(z,{className:(0,tf.cn)(n,"text-emerald-500")}):rb(e)?(0,t.jsx)(y.Globe,{className:(0,tf.cn)(n,"text-foreground/60")}):rg(e)?(0,t.jsx)(j.Image,{className:(0,tf.cn)(n,"text-sunshine-700")}):rx(e)?(0,t.jsx)(p.FileText,{className:(0,tf.cn)(n,"text-foreground/70")}):(0,t.jsx)(u.File,{className:(0,tf.cn)(n,"text-foreground/60")})}let rE=(0,H.memo)(function({node:e,depth:a,ctx:n,isMobile:r,activeWorkspaceId:s,sidebarScrollRef:i,isActive:d,isDragOver:b,isPinned:w,isAgentActive:v,isPulling:N,branchOpen:C,branchPos:S,branches:M,branchLoading:D,checkingOut:A,onHoverEnter:O,onHoverLeave:T}){let R=rl(e=>e.humanize);return(0,t.jsxs)(aO,{children:[(0,t.jsx)(aI,{asChild:!0,children:(0,t.jsxs)("div",{role:"treeitem",tabIndex:0,draggable:!r,onKeyDown:t=>{if("Enter"===t.key||" "===t.key)t.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"===t.key){t.preventDefault();let e=i.current;if(!e)return;let a=Array.from(e.querySelectorAll('[role="treeitem"]')),n=a.indexOf(t.currentTarget);a[n+1]?.focus()}else if("ArrowUp"===t.key){t.preventDefault();let e=i.current;if(!e)return;let a=Array.from(e.querySelectorAll('[role="treeitem"]')),n=a.indexOf(t.currentTarget);a[n-1]?.focus()}else if("ArrowRight"===t.key){if(t.preventDefault(),"dir"===e.type||"app"===e.type||"node-app"===e.type)if(e.expanded){let e=i.current;if(!e)return;let a=Array.from(e.querySelectorAll('[role="treeitem"]')),n=a.indexOf(t.currentTarget);a[n+1]?.focus()}else n.toggleFolder(e)}else if("ArrowLeft"===t.key){if(t.preventDefault(),("dir"===e.type||"app"===e.type||"node-app"===e.type)&&e.expanded)n.toggleFolder(e);else if(a>0){let e=i.current;if(!e)return;let a=Array.from(e.querySelectorAll('[role="treeitem"]')),n=t.currentTarget,r=a.indexOf(n),s=Number.parseInt(n.style.paddingLeft??"0",10);for(let e=r-1;e>=0;e--)if(Number.parseInt(a[e].style.paddingLeft??"0",10)<s){a[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:()=>O(e),onMouseLeave:T,className:(0,tf.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",d?"bg-accent-soft text-foreground font-medium":"hover:bg-muted",b&&"ring-2 ring-primary bg-primary-soft",e.name.startsWith(".")&&"opacity-40"),style:{paddingLeft:`${14*a+8}px`,...rk},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,t.jsx)(_.Loader2,{className:"h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground"}):(0,t.jsx)(l.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,t.jsx)("span",{className:"w-3.5 shrink-0"}),(0,t.jsx)("span",{className:"editorial-tree-typeicon",children:"dir"===e.type?e.expanded?(0,t.jsx)(x,{className:(0,tf.cn)("h-4 w-4 shrink-0",!d&&"text-warning")}):(0,t.jsx)(h.Folder,{className:(0,tf.cn)("h-4 w-4 shrink-0",!d&&"text-warning")}):"app"===e.type?(0,t.jsx)(y.Globe,{className:(0,tf.cn)("h-4 w-4 shrink-0",!d&&"text-foreground/70")}):"node-app"===e.type?(0,t.jsx)(z,{className:(0,tf.cn)("h-4 w-4 shrink-0",!d&&"text-emerald-500")}):rb(e.name)?(0,t.jsx)(y.Globe,{className:(0,tf.cn)("h-4 w-4 shrink-0",!d&&"text-foreground/60")}):rg(e.name)?(0,t.jsx)(j.Image,{className:(0,tf.cn)("h-4 w-4 shrink-0",!d&&"text-sunshine-700")}):rx(e.name)?(0,t.jsx)(p.FileText,{className:(0,tf.cn)("h-4 w-4 shrink-0",!d&&"text-foreground/70")}):(0,t.jsx)(u.File,{className:(0,tf.cn)("h-4 w-4 shrink-0",!d&&"text-foreground/60")})}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",title:R?e.name:void 0,children:R?ro(e.name):e.name}),e.git&&(0,t.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,t.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(),C){n.setBranchDropdownNode(null),n.setBranchDropdownPos(null);return}let a=t.currentTarget.getBoundingClientRect();n.setBranchDropdownPos({top:a.bottom+4,left:a.left}),n.setBranchDropdownNode(e.path),n.loadBranches(e.path)},children:[(0,t.jsx)(g,{className:"h-2.5 w-2.5"}),e.git.branch,e.git.dirty&&(0,t.jsx)("span",{className:"ml-0.5 text-warning",children:"*"})]}),N?(0,t.jsx)(_.Loader2,{className:"ml-0.5 h-2.5 w-2.5 animate-spin"}):(0,t.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation();let a=e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")):"";n.handleGitPull(e.path,a)},className:"ml-0.5 text-muted-foreground hover:text-foreground",title:"Pull latest",children:(0,t.jsx)(F,{className:"h-2.5 w-2.5"})}),C&&S&&(0,t.jsx)(tK,{pos:S,branches:M,loading:D,busyName:A,disabled:null!==A,onPick:t=>{let a=e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")):"";n.handleCheckout(e.path,t,a)},onClose:()=>{n.setBranchDropdownNode(null),n.setBranchDropdownPos(null)}})]}),v&&(0,t.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,t.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,t.jsxs)(tR.DropdownMenu,{children:[(0,t.jsx)(tR.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-muted-foreground hover:text-foreground",title:"File actions",children:(0,t.jsx)(E,{className:"h-3.5 w-3.5"})})}),(0,t.jsxs)(tR.DropdownMenuContent,{align:"end",className:"w-48",children:[(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>n.copyPath(e.path),children:[(0,t.jsx)(o.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),rf(e.name)&&(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>n.copyWikiLink(e.name),children:[(0,t.jsx)(p.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>n.copyUrl(e.path),children:[(0,t.jsx)(k.Link,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),"file"===e.type&&rx(e.name)&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>n.copyRawContent(e.path),children:[(0,t.jsx)(p.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>n.copyFormattedContent(e.path,e.name),children:[(0,t.jsx)(p.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),(0,t.jsx)(tR.DropdownMenuSeparator,{}),"dir"===e.type&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(tR.DropdownMenuItem,{onClick:async()=>{e.expanded||n.toggleFolder(e),n.setNewFileParent(e.path),n.setNewFileName(""),n.setFileCreateError(null)},children:[(0,t.jsx)(m.FilePlus,{className:"mr-2 h-3.5 w-3.5"}),"New file here"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>n.triggerUpload(e.path),children:[(0,t.jsx)(q.Upload,{className:"mr-2 h-3.5 w-3.5"}),"Upload here"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>{n.setNewFolderParent(e.path),n.setNewFolderName(""),n.setFolderError(null)},children:[(0,t.jsx)(f,{className:"mr-2 h-3.5 w-3.5"}),"New subfolder"]}),(0,t.jsx)(tR.DropdownMenuSeparator,{})]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>n.handleDownload(e),children:[(0,t.jsx)(c.Download,{className:"mr-2 h-3.5 w-3.5"}),"file"===e.type?"Download":"Download as zip"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>n.togglePin(e,s),children:[(0,t.jsx)(I,{className:(0,tf.cn)("mr-2 h-3.5 w-3.5",w&&"fill-current text-amber-400")}),w?"Unpin":"Pin to top"]}),(0,t.jsx)(tR.DropdownMenuSeparator,{}),(0,t.jsxs)(tR.DropdownMenuItem,{className:"text-destructive focus:text-destructive",onClick:()=>{n.setDeletingPath(e.path),n.setDeletingIsDir("file"!==e.type)},children:[(0,t.jsx)(U.Trash2,{className:"mr-2 h-3.5 w-3.5"}),"Delete"]})]})]})})]})}),(0,t.jsx)(r_,{node:e,ctx:n,isPinned:w,activeWorkspaceId:s})]})}),rS=(0,H.memo)(function(e){let{ctx:a,openPath:n,dragOverPath:r,branchDropdownNode:i,branchDropdownPos:l,nodeBranches:o,branchesLoading:c,checkingOutBranch:d,pullingRepo:u,activePaths:m,pins:x,isMobile:f,activeWorkspaceId:g,newFileParent:b,newFileName:w,fileCreateError:y,newFolderParent:v,newFolderName:N,folderError:j,sidebarScrollRef:k}=e,_=rs(e=>e.showHidden),C=(0,H.useRef)(null),E=(0,H.useCallback)(e=>{let t=("dir"===e.type||"app"===e.type||"node-app"===e.type)&&!e.expanded&&void 0===e.children;("file"===e.type||t)&&(C.current&&clearTimeout(C.current),C.current=setTimeout(()=>a.prefetch(e),120))},[a]),S=(0,H.useCallback)(()=>{C.current&&(clearTimeout(C.current),C.current=null)},[]),M=(0,H.useMemo)(()=>{let t=[],a=(e,n)=>{for(let r of e)!(!_&&r.name.startsWith("."))&&(t.push({kind:"row",node:r,depth:n}),"dir"===r.type&&(v===r.path&&t.push({kind:"newfolder",node:r,depth:n}),b===r.path&&t.push({kind:"newfile",node:r,depth:n})),("dir"===r.type||"app"===r.type||"node-app"===r.type)&&r.expanded&&(r.children&&r.children.length>0?a(r.children,n+1):r.children?.length===0&&t.push({kind:"empty",node:r,depth:n})))};return a(e.nodes,0),t},[e.nodes,b,v,_]);return(0,t.jsx)(t.Fragment,{children:M.map(e=>{let{node:b,depth:v}=e;if("row"===e.kind){let e=i===b.path;return(0,t.jsx)(rE,{node:b,depth:v,ctx:a,isMobile:f,activeWorkspaceId:g,sidebarScrollRef:k,isActive:n===b.path,isDragOver:r===b.path,isPinned:x.some(e=>e.path===b.path),isAgentActive:m.has(b.path),isPulling:u===b.path,branchOpen:e,branchPos:e?l:null,branches:b.git?o[b.path]??[]:[],branchLoading:!!b.git&&!!c[b.path],checkingOut:e?d:null,onHoverEnter:E,onHoverLeave:S},b.path)}return"newfolder"===e.kind?(0,t.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1",style:{paddingLeft:`${(v+1)*14+8}px`,...rk},children:[(0,t.jsx)("span",{className:"w-3.5 shrink-0"}),(0,t.jsx)(h.Folder,{className:"h-4 w-4 shrink-0 text-warning"}),(0,t.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"Folder name",value:N,onChange:e=>a.setNewFolderName(e.target.value),onKeyDown:e=>{"Enter"===e.key&&a.handleCreateFolder(),"Escape"===e.key&&(a.setNewFolderParent(null),a.setNewFolderName(""))}}),j&&(0,t.jsx)("span",{className:"text-xs text-destructive",children:j}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:a.handleCreateFolder,children:(0,t.jsx)(s.Check,{className:"h-3 w-3"})}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{a.setNewFolderParent(null),a.setNewFolderName("")},children:(0,t.jsx)(K.X,{className:"h-3 w-3"})})]},`nf-${b.path}`):"newfile"===e.kind?(0,t.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1",style:{paddingLeft:`${(v+1)*14+8}px`,...rk},children:[(0,t.jsx)("span",{className:"w-3.5 shrink-0"}),(0,t.jsx)(p.FileText,{className:"h-4 w-4 shrink-0 text-accent"}),(0,t.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=>a.setNewFileName(e.target.value),onKeyDown:e=>{"Enter"===e.key&&a.handleCreateFile(),"Escape"===e.key&&(a.setNewFileParent(null),a.setNewFileName(""))}}),y&&(0,t.jsx)("span",{className:"text-xs text-destructive",children:y}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:a.handleCreateFile,children:(0,t.jsx)(s.Check,{className:"h-3 w-3"})}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{a.setNewFileParent(null),a.setNewFileName("")},children:(0,t.jsx)(K.X,{className:"h-3 w-3"})})]},`ff-${b.path}`):(0,t.jsx)("div",{className:"text-xs text-muted-foreground/50 py-0.5",style:{paddingLeft:`${(v+1)*14+8+14+6+16+6}px`,...rk},children:"Empty"},`empty-${b.path}`)})})});e.s(["default",0,function(){let e;(0,rn.useWikiSlugsStore)(e=>e.loadedAt),(0,H.useEffect)(()=>{rn.useWikiSlugsStore.getState().load()},[]);let[n,c]=(0,H.useState)(null),[x,z]=(0,H.useState)(null),[G,Z]=(0,H.useState)(()=>(0,X.getActiveWorkspaceId)()),[J,Q]=(0,H.useState)([]),[Y,en]=(0,H.useState)(!1),[er,eo]=(0,H.useState)(!1),[ed,eu]=(0,H.useState)(null),[em,ep]=(0,H.useState)(null),[eh,ex]=(0,H.useState)({}),[ef,eg]=(0,H.useState)(null),[eb,ew]=(0,H.useState)(null),[ey,ev]=(0,H.useState)(null),[eN,ej]=(0,H.useState)(null),ek=(0,H.useCallback)(async()=>{try{let e=await fetch("/api/system/workspaces");if(!e.ok)throw Error("Failed");let t=await e.json();if(Q(t.workspaces),en(t.isAdmin),t.workspaces.length>0){c(!0);let e=new URLSearchParams(window.location.search).get("ws"),a=e?t.workspaces.find(t=>t.id===e):null,n=a??[...t.workspaces].sort((e,t)=>(t.lastOpenedAt??t.createdAt).localeCompare(e.lastOpenedAt??e.createdAt))[0];if(Z(n.id),z(n.rootDir),!a){let e=new URL(location.href);e.searchParams.set("ws",n.id),history.replaceState(null,"",e.toString())}}else c(!1)}catch{c(!1)}},[]);(0,H.useEffect)(()=>{ek()},[ek]);let e_=(0,nn.useEditorStore)(e=>e.currentPath),eC=aY(e=>e.recents),[eE,eS]=(0,H.useState)(!1),[eM,eD]=(0,H.useState)(!0),eA=a2(e=>e.pins),eO=(0,H.useRef)(null),eT=(0,a3.useAIPanelStore)(e=>e.activity),eI=(0,H.useMemo)(()=>{let e=new Date(Date.now()-6e4).toISOString(),t=new Set;for(let a of eT)a.at>=e&&a.path&&a.by?.startsWith("ai:")&&t.add(a.path);return t},[eT]);(0,H.useEffect)(()=>{let e=()=>{a3.useAIPanelStore.getState().loadActivity()};e();let t=setInterval(e,1e4);return()=>clearInterval(t)},[]),(0,H.useEffect)(()=>{aY.getState().loadForWorkspace(G),a2.getState().loadForWorkspace(G)},[G]),(0,H.useEffect)(()=>{let e=[...eA.map(e=>e.path),...eC.slice(0,8).map(e=>e.path)].filter((e,t,a)=>rf(e)&&a.indexOf(e)===t).slice(0,12);if(0===e.length)return;let t=("requestIdleCallback"in window?e=>window.requestIdleCallback(e):e=>window.setTimeout(e,400))(()=>{for(let t of e)(0,nn.prefetchPage)(t)});return()=>{"cancelIdleCallback"in window?window.cancelIdleCallback(t):clearTimeout(t)}},[eA,eC]);let eR=(0,H.useRef)(new URLSearchParams(window.location.search).get("path")),eF=(0,H.useRef)(!1),[eL,eP]=(0,H.useState)([]),[eB,ez]=(0,H.useState)(!1),[e$,eU]=(0,H.useState)(!1),eq=(0,H.useRef)(!1),[eK,eH]=(0,H.useState)(!1),[eW,eG]=(0,H.useState)(!1),[eV,eZ]=(0,H.useState)(null),eX=(0,H.useRef)(null),eJ=(0,H.useRef)(""),[eQ,eY]=(0,H.useState)(null),[e0,e1]=(0,H.useState)(""),[e2,e5]=(0,H.useState)(null),[e3,e4]=(0,H.useState)(null),[e9,e7]=(0,H.useState)(""),[e6,e8]=(0,H.useState)(null),[te,tt]=(0,H.useState)(null),[ta,tr]=(0,H.useState)(!1),[ts,ti]=(0,H.useState)(null),[tl,to]=(0,H.useState)(null),[tc,td]=(0,H.useState)(!1),[tu,tp]=(0,H.useState)(0),[tb,tw]=(0,H.useState)(0),ty=function(e="(max-width: 767px)"){let[t,a]=(0,H.useState)(!1);return(0,H.useEffect)(()=>{let t=window.matchMedia(e),n=()=>a(t.matches);return n(),t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[e]),t}(),[tv,tN]=(0,H.useState)(!1),tj=ra(e=>e.width),tk=rs(e=>e.showHidden),t_=rl(e=>e.humanize),{resolvedTheme:tC,setTheme:tE}=(0,tH.useTheme)(),tS=ra(e=>e.setWidth);(0,H.useEffect)(()=>{ty&&tN(!0)},[ty]);let[tM,tA]=(0,H.useState)(!1),[tT,tI]=(0,H.useState)(!1),[tF,tP]=(0,H.useState)(!1),[tB,tz]=(0,H.useState)(null),[t$,tq]=(0,H.useState)(0),[tW,tG]=(0,H.useState)(!1),[tV,tZ]=(0,H.useState)(!1),[tX,tJ]=(0,H.useState)(""),[tQ,t0]=(0,H.useState)(!1),[t1,t2]=(0,H.useState)(!1),[t5,t3]=(0,H.useState)(null),t4=(0,H.useRef)(null),[t9,t7]=(0,H.useState)(null),t6=(0,H.useRef)(null),t8=(0,H.useRef)(!1),at=(0,H.useRef)(async()=>{});(0,H.useEffect)(()=>{!G||eB||eq.current||(eq.current=!0,eU(!0),rw("").then(e=>{eP(e),ez(!0),eU(!1)}).catch(()=>{eq.current=!1,eU(!1)}))},[eB,G]);let aa=(0,H.useCallback)(async e=>{let t=e.split("/");if(t.length<=1)return;let a=[],n="";for(let e=0;e<t.length-1;e++)n=n?`${n}/${t[e]}`:t[e],a.push({prefix:n,children:await rw(n)});eP(e=>{let t=e;for(let{prefix:e,children:n}of a)t=rj(t,e,e=>({...e,children:n,expanded:!0}));return t})},[]),an=(0,H.useCallback)(async e=>{let t=await rw(e);""===e?eP(e=>{let a=new Map(e.map(e=>[e.path,e]));return t.map(e=>{let t=a.get(e.path);return t&&("dir"===t.type||"app"===t.type)?{...e,expanded:t.expanded,children:t.children}:e})}):eP(a=>rj(a,e,e=>({...e,children:t,expanded:!0})))},[]),[ar,as]=(0,H.useState)(null),[ai,al]=(0,H.useState)(null),[ao,ac]=(0,H.useState)(!1),[ad,au]=(0,H.useState)([]),[am,ap]=(0,H.useState)(!1),[ah,ax]=(0,H.useState)(null),[af,ag]=(0,H.useState)(null),[ab,aw]=(0,H.useState)(!1),[ay,av]=(0,H.useState)({}),[ak,a_]=(0,H.useState)({}),[aC,aE]=(0,H.useState)(null),[aS,aM]=(0,H.useState)(null),[aD,aA]=(0,H.useState)(null),aT=(0,H.useCallback)(async(e,t)=>{if(!ar){as(e);try{let a=await (0,X.wsFetch)("/api/wiki/git-pull",{method:"POST",body:JSON.stringify({path:e})});if(!a.ok){let e=await a.json();(0,tY.showError)(e.message??e.error??"Pull failed");return}let n=await a.json();(0,tY.showSuccess)(`Pulled ${e} (${n.branch} @ ${n.sha.slice(0,7)})`),await an(t)}catch{(0,tY.showError)("Pull failed")}finally{as(null)}}},[ar,an]);(0,H.useEffect)(()=>{ac(!1),au([]),ax(null),ag(null)},[ts?.path]);let aR=ts?.path;(0,H.useEffect)(()=>{if(!aR)return void al(null);let e=!1,t=setTimeout(()=>{(async()=>{try{let t=await (0,X.wsFetch)(`/api/wiki/git-file-info?path=${encodeURIComponent(aR)}`);if(e)return;if(!t.ok)return void al(null);let a=await t.json();e||al(a.info)}catch{e||al(null)}})()},200);return()=>{e=!0,clearTimeout(t)}},[aR]);let aF=(0,H.useCallback)(async()=>{if(!ts)return;let e=ts.path;ac(!0),ap(!0),au([]),ax(null),ag(null);try{let t=await (0,X.wsFetch)(`/api/wiki/git-history?path=${encodeURIComponent(e)}`);if(!t.ok)return void(0,tY.showError)("Could not load history");let a=await t.json();ts.path===e&&au(a.commits)}catch{(0,tY.showError)("Could not load history")}finally{ap(!1)}},[ts]),aL=(0,H.useCallback)(async e=>{if(!ts)return;if(ah===e){ax(null),ag(null);return}let t=ts.path;ax(e),aw(!0),ag(null);try{let a=await (0,X.wsFetch)(`/api/wiki/git-diff?path=${encodeURIComponent(t)}&sha=${encodeURIComponent(e)}`);if(!a.ok)return void(0,tY.showError)("Could not load diff");let n=await a.json();ts.path===t&&ah===e&&ag(n.diff)}catch{(0,tY.showError)("Could not load diff")}finally{aw(!1)}},[ts,ah]),aP=(0,H.useCallback)(async e=>{if(ay[e]||ak[e])return;let t=!1;a_(t=>({...t,[e]:!0}));try{let a=await (0,X.wsFetch)(`/api/wiki/git-branches?path=${encodeURIComponent(e)}`);if(t)return;if(!a.ok)return void(0,tY.showError)("Could not load branches");let n=await a.json();t||av(t=>({...t,[e]:n.branches}))}catch{t||(0,tY.showError)("Could not load branches")}finally{t||a_(t=>({...t,[e]:!1}))}return()=>{t=!0}},[ay,ak]),aB=(0,H.useCallback)(async(e,t,a)=>{if(!aC){aE(t);try{let n=await (0,X.wsFetch)("/api/wiki/git-checkout",{method:"POST",body:JSON.stringify({path:e,branch:t})});if(409===n.status)return void(0,tY.showError)("Repository has uncommitted changes");if(!n.ok){let e=await n.json();(0,tY.showError)(e.error??"Checkout failed");return}let r=await n.json();(0,tY.showSuccess)(`Switched to ${r.branch}`),av(t=>{let a={...t};return delete a[e],a}),aM(null),aA(null),await an(a)}catch{(0,tY.showError)("Checkout failed")}finally{aE(null)}}},[aC,an]),az=(0,H.useCallback)(e=>{let t=[];for(let a of e)("dir"===a.type||"app"===a.type||"node-app"===a.type)&&a.expanded&&a.children&&(t.push(a.path),t.push(...az(a.children)));return t},[]),a$=(0,H.useCallback)(async()=>{eH(!0);try{let e=az(eL),t=await rw("");for(let a of(eP(t),e)){let e=await rw(a);eP(t=>rj(t,a,t=>({...t,children:e,expanded:!0})))}}finally{eH(!1)}},[eL,az]),aU=(0,H.useCallback)(async()=>{if(ts){if(rf(ts.name)){tG(!0);try{await nn.useEditorStore.getState().loadPage(ts.path)}finally{tG(!1)}return}if(["editor","text"].includes(rp(ts.name,ts.nodeType))||rx(ts.name)){tG(!0);try{let e=await (0,X.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(ts.path)}`);if(e.ok){let t=await e.json();tz(t.content),tq(Number(e.headers.get("X-Wiki-Revision")??0))}}catch{}tG(!1)}}},[ts]),aq=(0,H.useCallback)(()=>{tw(e=>e+1),aU()},[aU]);async function aK(e){if("dir"===e.type||"app"===e.type||"node-app"===e.type)if(e.expanded)eP(t=>rj(t,e.path,e=>({...e,expanded:!1})));else if(void 0===e.children){let t=await rN(e.path);if(t)return void eP(a=>rj(a,e.path,e=>({...e,loading:!1,children:t,expanded:!0})));eP(t=>rj(t,e.path,e=>({...e,loading:!0})));let a=await rw(e.path);eP(t=>rj(t,e.path,e=>({...e,loading:!1,children:a,expanded:!0})))}else eP(t=>rj(t,e.path,e=>({...e,expanded:!0})))}async function aH(e){if("file"===e.type&&aY.getState().push({path:e.path,name:e.name},G),ti({path:e.path,name:e.name,size:e.size,nodeType:"app"===e.type?"app":"node-app"===e.type?"node-app":"file"}),tZ(!1),t0(!1),t3(null),tz(null),tq(0),"file"===e.type&&rf(e.name)){tG(!0);try{await nn.useEditorStore.getState().loadPage(e.path)}finally{tG(!1)}return}if(["editor","text"].includes(rp(e.name,e.type))||rx(e.name)){tG(!0);try{let t=await (0,X.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(e.path)}`);if(t.ok){let e=await t.json();tz(e.content),tq(Number(t.headers.get("X-Wiki-Revision")??0))}}catch{}tG(!1)}}(0,H.useEffect)(()=>{ts&&rf(ts.name)&&nn.useEditorStore.getState().currentPath!==ts.path&&nn.useEditorStore.getState().loadPage(ts.path)},[ts]),(0,H.useEffect)(()=>{t6.current=ts},[ts]),(0,H.useEffect)(()=>{t8.current=tV},[tV]),(0,H.useEffect)(()=>{at.current=aU},[aU]),(0,H.useEffect)(()=>{if(!n||!G)return;let e=new Map,t=new EventSource((0,X.withWs)("/api/wiki/watch"));return t.onmessage=t=>{var a;let n;try{n=JSON.parse(t.data)}catch{return}let{type:r,path:s}=n,i=s.split("/");if(a=i.length>1?i.slice(0,-1).join("/"):"",e.has(a)&&clearTimeout(e.get(a)),e.set(a,setTimeout(()=>{e.delete(a),an(a)},300)),"change"===r&&t6.current?.path===s&&!t8.current){let t=`__file__${s}`;e.has(t)&&clearTimeout(e.get(t)),e.set(t,setTimeout(()=>{e.delete(t),at.current()},400))}},()=>{for(let a of(t.close(),e.values()))clearTimeout(a)}},[n,an,G]),(0,H.useEffect)(()=>{td(!1)},[]);let aW=(0,H.useCallback)(e=>{let t=e.split("/").pop()??e;aa(e),aH({path:e,name:t,type:"file"})},[aa]),aG=(0,H.useCallback)(async e=>{let t=e.path.split("/").slice(0,-1).join("/"),a=(await rw(t)).find(t=>t.path===e.path);if(a){if("dir"===a.type){await aa(e.path),await aK(a);return}if("app"===a.type||"node-app"===a.type){await aa(a.path),aH({path:a.path,name:a.name,type:a.type,modifiedAt:a.modifiedAt}),await aK(a),ty&&tN(!0);return}aH({path:a.path,name:a.name,type:a.type,modifiedAt:a.modifiedAt}),ty&&tN(!0)}},[ty,aH,aa,aK]);(0,H.useEffect)(()=>{if(!e_||ts&&ts.path===e_)return;let e=e_.split("/").pop()??e_;aH({path:e_,name:e,type:"file"})},[e_]);let aV=(0,H.useCallback)(async e=>{if(!e)return void ti(null);let t=e.split("/"),a=t[t.length-1],n=t.slice(0,-1).join("/"),r=(await rw(n)).find(t=>t.path===e);r&&(await aa(e),aH({path:e,name:a,type:r.type,modifiedAt:r.modifiedAt}))},[aa]);(0,H.useEffect)(()=>{let e=new URL(window.location.href);ts?e.searchParams.set("path",ts.path):e.searchParams.delete("path");let t=e.toString();t!==window.location.href&&window.history.pushState(null,"",t)},[ts]),(0,H.useEffect)(()=>{let e=()=>{aV(new URLSearchParams(window.location.search).get("path"))};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[aV]),(0,H.useEffect)(()=>{eF.current||eB&&(eF.current=!0,aV(eR.current))},[eB,aV]);let aZ=(0,H.useCallback)(async e=>{if(e===G)return;try{await fetch(`/api/system/workspaces/${e}/open`,{method:"POST"})}catch{}let t=new URL(location.href);t.searchParams.set("ws",e),t.searchParams.delete("path"),history.pushState(null,"",t.toString()),ti(null),tz(null),tZ(!1),eP([]),ez(!1),eq.current=!1,rn.useWikiSlugsStore.getState().invalidate();let a=J.find(t=>t.id===e);a&&z(a.rootDir),Z(e)},[G,J]),aX=(0,H.useCallback)(async()=>{if(ed)try{if(!(await fetch(`/api/system/workspaces/${ed}`,{method:"DELETE"})).ok)throw Error("Failed");if(ed===G){let e=J.filter(e=>e.id!==ed);if(e.length>0){let t=[...e].sort((e,t)=>(t.lastOpenedAt??t.createdAt).localeCompare(e.lastOpenedAt??e.createdAt))[0];await aZ(t.id)}else c(!1)}await ek()}catch{}finally{eu(null)}},[ed,G,J,aZ,ek]),aJ=(0,H.useCallback)(async e=>{if(!em){ep(e);try{let t=await fetch(`/api/system/workspaces/${e}/refresh`,{method:"POST"});if(!t.ok){let e=await t.json();(0,tY.showError)(e.error??"Refresh failed")}await ek()}catch{(0,tY.showError)("Refresh failed")}finally{ep(null)}}},[em,ek]),aQ=(0,H.useCallback)(async e=>{if(!eh[e])try{let t=await fetch(`/api/system/workspaces/${e}/branch`);if(!t.ok)return;let a=await t.json();ex(t=>({...t,[e]:a.branches??[]}))}catch{}},[eh]),a0=(0,H.useCallback)(async(e,t)=>{if(!ef){eg(e),ew(t);try{let a=await fetch(`/api/system/workspaces/${e}/branch`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({branch:t})});if(!a.ok){let e=await a.json();(0,tY.showError)(e.error??"Branch switch failed");return}(0,tY.showSuccess)(`Switched to ${t}`),ev(null),ej(null),await ek()}catch{(0,tY.showError)("Branch switch failed")}finally{eg(null),ew(null)}}},[ef,ek]);async function a1(){if(!ts)return;t2(!0),t3(null);let e=await (0,X.wsFetch)("/api/wiki/content",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:ts.path,content:tX,baseRevision:t$})});if(e.ok){let t=await e.json();"number"==typeof t.revision&&tq(t.revision),tz(tX),tZ(!1)}else t3((await e.json()).error??"Save failed");t2(!1)}let a5=(0,H.useCallback)(async(e,t)=>{let a=Array.from(e);if(a.length){eG(!0),eZ(null);try{for(let e of a){let a=new FormData;a.append("file",e),a.append("dir",t);let n=await (0,X.wsFetch)("/api/wiki/upload",{method:"POST",body:a});if(!n.ok){let e=await n.json();eZ(e.error??"Upload failed"),(0,tY.showError)(e.error??"Upload failed");break}}await an(t)}catch{eZ("Upload failed.")}finally{eG(!1),eX.current&&(eX.current.value="")}}},[an]);function a4(e){eJ.current=e,eX.current?.click()}async function a9(){let e=e0.trim();if(!e||null===eQ)return;e5(null);let t=eQ?`${eQ}/${e}`:e,a=await (0,X.wsFetch)("/api/wiki/folder",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});a.ok?(eY(null),e1(""),await an(eQ),""!==eQ&&eP(e=>rj(e,eQ,e=>({...e,expanded:!0})))):e5((await a.json()).error??"Failed")}async function a7(){let e=e9.trim();if(!e||null===e3)return;e8(null);let t=e.includes(".")?e:`${e}.md`,a=e3?`${e3}/${t}`:t,n=await (0,X.wsFetch)("/api/wiki/new-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a})});n.ok?(e4(null),e7(""),await an(e3),""!==e3&&eP(e=>rj(e,e3,e=>({...e,expanded:!0}))),aH({path:a,name:t,type:"file",modifiedAt:new Date().toISOString()})):e8((await n.json()).error??"Failed")}function a6(e){navigator.clipboard.writeText(e),(0,tY.showSuccess)("Path copied")}function a8(e){let t=e.replace(/\.(md|markdown)$/i,"");navigator.clipboard.writeText(`[[${t}]]`),(0,tY.showSuccess)("Wiki link copied")}function ne(e){let t=new URL(location.href);t.searchParams.set("path",e),G&&t.searchParams.set("ws",G),navigator.clipboard.writeText(t.toString()),(0,tY.showSuccess)("URL copied")}async function nt(e){if(ts?.path===e&&null!==tB)return tB;if(nn.useEditorStore.getState().currentPath===e)return nn.useEditorStore.getState().content;let t=await (0,X.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(e)}`);if(!t.ok)throw Error("Cannot copy content");return(await t.json()).content}async function na(e){try{let t=await nt(e);await navigator.clipboard.writeText(t),(0,tY.showSuccess)("Raw content copied")}catch{(0,tY.showError)("Could not copy file content")}}async function nr(e,t){try{let a=await nt(e);if(!rf(t)){await navigator.clipboard.writeText(a),(0,tY.showSuccess)("Content copied");return}let n=await (0,tn.markdownToHtml)(a,{pagePath:e,sanitize:!0});"ClipboardItem"in window&&navigator.clipboard.write?await navigator.clipboard.write([new ClipboardItem({"text/html":new Blob([n],{type:"text/html"}),"text/plain":new Blob([a],{type:"text/plain"})})]):await navigator.clipboard.writeText(a),(0,tY.showSuccess)("Formatted content copied")}catch{(0,tY.showError)("Could not copy formatted content")}}function ns(e,a){return(0,t.jsxs)(tR.DropdownMenu,{children:[(0,t.jsx)(tR.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"File actions",children:(0,t.jsx)(E,{className:"h-3.5 w-3.5"})})}),(0,t.jsxs)(tR.DropdownMenuContent,{align:"end",className:"w-52",children:[(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>a6(e.path),children:[(0,t.jsx)(o.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),rf(e.name)&&(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>a8(e.name),children:[(0,t.jsx)(p.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,t.jsx)(tR.DropdownMenuSeparator,{}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>ne(e.path),children:[(0,t.jsx)(k.Link,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),rx(e.name)&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tR.DropdownMenuSeparator,{}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>void na(e.path),children:[(0,t.jsx)(p.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>void nr(e.path,e.name),children:[(0,t.jsx)(p.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),a&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tR.DropdownMenuSeparator,{}),a]})]})]})}async function ni(){te&&(await (0,X.wsFetch)("/api/wiki",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:te})}),(ts?.path===te||ts?.path.startsWith(`${te}/`))&&(ti(null),tz(null)),eP(e=>(function e(t,a){return t.filter(e=>e.path!==a).map(t=>t.children?{...t,children:e(t.children,a)}:t)})(e,te)),tt(null))}function nl(e,t,a){e.preventDefault(),e.stopPropagation();let n=t4.current;if(!n){Array.from(e.dataTransfer.types).includes("Files")&&(e.dataTransfer.dropEffect="copy",t7("root"===a?"":t));return}n.path===t||t.startsWith(`${n.path}/`)||(e.dataTransfer.dropEffect="move",t7("root"===a?"":t))}async function no(e,t){e.preventDefault(),e.stopPropagation(),t7(null);let a=t4.current;if(t4.current=null,!a){e.dataTransfer.files.length>0&&await a5(e.dataTransfer.files,t);return}if(a.path===t||t.startsWith(`${a.path}/`))return;let n=t?`${t}/${a.name}`:a.name;if(n!==a.path&&(await (0,X.wsFetch)("/api/wiki/move",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({from:a.path,to:n})})).ok){let e=a.path.includes("/")?a.path.split("/").slice(0,-1).join("/"):"";await an(e),t!==e&&await an(t),ts?.path===a.path&&ti({path:n,name:a.name,nodeType:ts.nodeType,size:ts.size})}}let nc=ts?rp(ts.name,ts.nodeType):null,nd=!!ts&&null!==nc&&!ru.has(nc)&&(ts.size??0)>5242880&&tl!==ts.path,nm=(0,n9.useViewWidthStore)(e=>e.width),np=(0,n9.useViewWidthStore)(e=>e.align),nh=(0,n9.useViewWidthStore)(e=>e.setWidth),nx=(0,n9.useViewWidthStore)(e=>e.setAlign),nf=null===nc||"editor"===nc||"text"===nc||"source"===nc||"notebook"===nc||"fallback"===nc,ng=nf?n9.VIEW_WIDTH_CLASS[nm]:"",nb=nf?n9.VIEW_ALIGN_CLASS[np]:"",nw=(0,H.useRef)(null);nw.current={toggleFolder:e=>void aK(e),openViewer:e=>void aH(e),copyPath:a6,copyWikiLink:a8,copyUrl:ne,copyRawContent:e=>void na(e),copyFormattedContent:(e,t)=>void nr(e,t),handleDownload:function(e){let t=(0,X.withWs)(`/api/wiki/download?path=${encodeURIComponent(e.path)}`),a=document.createElement("a");a.href=t,a.download="file"===e.type?e.name:`${e.name}.zip`,document.body.appendChild(a),a.click(),a.remove()},triggerUpload:a4,handleCreateFile:()=>void a7(),handleCreateFolder:()=>void a9(),handleDragStart:function(e,t){t4.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t.path)},handleDragOver:nl,handleDropOnFolder:(e,t)=>void no(e,t),handleGitPull:(e,t)=>void aT(e,t),handleCheckout:(e,t,a)=>void aB(e,t,a),loadBranches:e=>void aP(e),prefetch:e=>{"file"===e.type?rf(e.name)&&(0,nn.prefetchPage)(e.path):function(e){if(ry.has(e)||rv.has(e))return;let t=rw(e).then(t=>(ry.set(e,t),t)).finally(()=>rv.delete(e));rv.set(e,t),t.catch(()=>{})}(e.path)},togglePin:(e,t)=>a2.getState().toggle({path:e.path,name:e.name,type:e.type},t),setDragOverPath:t7,setSidebarCollapsed:tN,setBranchDropdownNode:aM,setBranchDropdownPos:aA,setNewFileParent:e4,setNewFileName:e7,setFileCreateError:e8,setNewFolderParent:eY,setNewFolderName:e1,setFolderError:e5,setDeletingPath:tt,setDeletingIsDir:tr};let ny=(0,H.useMemo)(()=>({toggleFolder:e=>nw.current.toggleFolder(e),openViewer:e=>nw.current.openViewer(e),copyPath:e=>nw.current.copyPath(e),copyWikiLink:e=>nw.current.copyWikiLink(e),copyUrl:e=>nw.current.copyUrl(e),copyRawContent:e=>nw.current.copyRawContent(e),copyFormattedContent:(e,t)=>nw.current.copyFormattedContent(e,t),handleDownload:e=>nw.current.handleDownload(e),triggerUpload:e=>nw.current.triggerUpload(e),handleCreateFile:()=>nw.current.handleCreateFile(),handleCreateFolder:()=>nw.current.handleCreateFolder(),handleDragStart:(e,t)=>nw.current.handleDragStart(e,t),handleDragOver:(e,t,a)=>nw.current.handleDragOver(e,t,a),handleDropOnFolder:(e,t)=>nw.current.handleDropOnFolder(e,t),handleGitPull:(e,t)=>nw.current.handleGitPull(e,t),handleCheckout:(e,t,a)=>nw.current.handleCheckout(e,t,a),loadBranches:e=>nw.current.loadBranches(e),prefetch:e=>nw.current.prefetch(e),togglePin:(e,t)=>nw.current.togglePin(e,t),setDragOverPath:e=>nw.current.setDragOverPath(e),setSidebarCollapsed:e=>nw.current.setSidebarCollapsed(e),setBranchDropdownNode:e=>nw.current.setBranchDropdownNode(e),setBranchDropdownPos:e=>nw.current.setBranchDropdownPos(e),setNewFileParent:e=>nw.current.setNewFileParent(e),setNewFileName:e=>nw.current.setNewFileName(e),setFileCreateError:e=>nw.current.setFileCreateError(e),setNewFolderParent:e=>nw.current.setNewFolderParent(e),setNewFolderName:e=>nw.current.setNewFolderName(e),setFolderError:e=>nw.current.setFolderError(e),setDeletingPath:e=>nw.current.setDeletingPath(e),setDeletingIsDir:e=>nw.current.setDeletingIsDir(e)}),[]);return(0,t.jsxs)("div",{className:"flex h-screen gap-0 overflow-hidden bg-background",children:[null===n&&(0,t.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,t.jsx)(_.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),!1===n&&(0,t.jsx)(tU,{onSelect:e=>{let t=new URL(location.href);t.searchParams.set("ws",e),t.searchParams.delete("path"),history.replaceState(null,"",t.toString()),ez(!1),eq.current=!1,Z(e),c(!0),ek()}}),!0===n&&er&&(0,t.jsxs)("div",{className:"flex-1 flex flex-col",children:[(0,t.jsx)("div",{className:"flex items-center justify-end border-b px-3 py-2 bg-muted shrink-0",children:(0,t.jsxs)(W.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1.5 text-xs",onClick:()=>eo(!1),children:[(0,t.jsx)(K.X,{className:"h-3.5 w-3.5"})," Cancel"]})}),(0,t.jsx)(tU,{onSelect:e=>{eo(!1),ek(),aZ(e)}})]}),!0===n&&!er&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n6,{onOpenFile:aW,recents:eC,onToggleSidebar:()=>tN(e=>{let t=!e;return ty&&!1===t&&a3.useAIPanelStore.getState().close(),t}),onNewFile:()=>e4(""),onCopyPath:()=>{ts&&navigator.clipboard.writeText(ts.path)}}),!tv&&ty&&(0,t.jsx)("div",{className:"fixed inset-0 z-40 bg-overlay backdrop-blur-[1px] md:hidden",onClick:()=>tN(!0),"aria-hidden":!0}),!tv&&(0,t.jsxs)(aj.Card,{style:ty?void 0:{width:tj},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",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2 px-3 py-2 border-b bg-muted shrink-0",children:[(0,t.jsxs)("div",{className:"flex min-w-0 items-center gap-1.5",children:[(0,t.jsx)("img",{src:"/logo.svg",alt:"Wiki Viewer",className:"h-5 w-5 shrink-0"}),(0,t.jsx)("span",{className:"truncate text-xs font-semibold leading-5 tracking-tight translate-y-[0.5px]",children:"Wiki Viewer"})]}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 shrink-0",title:"Collapse sidebar",onClick:()=>tN(!0),children:(0,t.jsx)(M,{className:"h-3.5 w-3.5"})})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-1 px-3 py-1.5 border-b bg-muted/50 shrink-0",children:[(0,t.jsxs)(tR.DropdownMenu,{children:[(0,t.jsx)(tR.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsxs)(W.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1 px-2 text-xs",disabled:eW,children:[eW?(0,t.jsx)(_.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(R,{className:"h-3.5 w-3.5"}),"New",(0,t.jsx)(i.ChevronDown,{className:"h-3 w-3 opacity-60"})]})}),(0,t.jsxs)(tR.DropdownMenuContent,{align:"start",className:"w-44",children:[(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>{e4(""),e7(""),e8(null)},children:[(0,t.jsx)(m.FilePlus,{className:"mr-2 h-3.5 w-3.5"}),"New file"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>{eY(""),e1(""),e5(null)},children:[(0,t.jsx)(f,{className:"mr-2 h-3.5 w-3.5"}),"New folder"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>a4(""),disabled:eW,children:[(0,t.jsx)(q.Upload,{className:"mr-2 h-3.5 w-3.5"}),"Upload"]})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Refresh tree",onClick:a$,disabled:eK,children:eK?(0,t.jsx)(_.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(F,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"AI Agent panel",onClick:()=>{a3.useAIPanelStore.getState().toggle(),ty&&tN(!0)},children:(0,t.jsx)(r,{className:"h-3.5 w-3.5"})}),(0,t.jsxs)(tR.DropdownMenu,{children:[(0,t.jsx)(tR.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"More actions",children:(0,t.jsx)(E,{className:"h-3.5 w-3.5"})})}),(0,t.jsxs)(tR.DropdownMenuContent,{align:"end",className:"w-48",children:[Y&&J.find(e=>e.id===G)?.git&&(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>{G&&aJ(G)},disabled:em===G,children:[em===G?(0,t.jsx)(_.Loader2,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(d,{className:"mr-2 h-3.5 w-3.5"}),"Pull latest"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>rs.getState().toggle(),children:[tk?(0,t.jsx)(T,{className:"mr-2 h-3.5 w-3.5"}):(0,t.jsx)(O.Eye,{className:"mr-2 h-3.5 w-3.5"}),tk?"Hide hidden files":"Show hidden files"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>rl.getState().toggle(),children:[(0,t.jsx)($.Type,{className:"mr-2 h-3.5 w-3.5"}),t_?"Raw file names":"Humanize names"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>tE("dark"===tC?"light":"dark"),children:["dark"===tC?(0,t.jsx)(B.Sun,{className:"mr-2 h-3.5 w-3.5"}):(0,t.jsx)(S.Moon,{className:"mr-2 h-3.5 w-3.5"}),"dark"===tC?"Light mode":"Dark mode"]}),(0,t.jsx)(tR.DropdownMenuSeparator,{}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>tI(!0),children:[(0,t.jsx)(L,{className:"mr-2 h-3.5 w-3.5"}),"Settings"]})]})]})]})]}),eV&&(0,t.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,t.jsx)(a.AlertCircle,{className:"h-3.5 w-3.5 shrink-0"}),eV]}),""===eQ&&(0,t.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,t.jsx)(h.Folder,{className:"h-4 w-4 shrink-0 text-warning"}),(0,t.jsx)("input",{className:"flex-1 bg-transparent text-sm outline-none border-b border-border min-w-0",placeholder:"Folder name",value:e0,onChange:e=>e1(e.target.value),onKeyDown:e=>{"Enter"===e.key&&a9(),"Escape"===e.key&&(eY(null),e1(""))}}),e2&&(0,t.jsx)("span",{className:"text-xs text-destructive",children:e2}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:a9,children:(0,t.jsx)(s.Check,{className:"h-3 w-3"})}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{eY(null),e1("")},children:(0,t.jsx)(K.X,{className:"h-3 w-3"})})]}),""===e3&&(0,t.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,t.jsx)(p.FileText,{className:"h-4 w-4 shrink-0 text-accent"}),(0,t.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:e9,onChange:e=>e7(e.target.value),onKeyDown:e=>{"Enter"===e.key&&a7(),"Escape"===e.key&&(e4(null),e7(""))}}),e6&&(0,t.jsx)("span",{className:"text-xs text-destructive",children:e6}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:a7,children:(0,t.jsx)(s.Check,{className:"h-3 w-3"})}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{e4(null),e7("")},children:(0,t.jsx)(K.X,{className:"h-3 w-3"})})]}),(0,t.jsx)("div",{className:"border-b",children:(0,t.jsx)(n8,{onOpenFile:aW})}),(0,t.jsxs)("div",{ref:eO,className:(0,tf.cn)("flex-1 overflow-auto py-1 editorial-file-tree",""===t9&&"ring-2 ring-inset ring-primary bg-primary/5"),onDragOver:e=>nl(e,"","root"),onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||t7(null)},onDrop:e=>no(e,""),children:[eA.length>0&&(0,t.jsxs)("div",{className:"border-b mb-1",children:[(0,t.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:()=>eS(e=>!e),children:[eE?(0,t.jsx)(l.ChevronRight,{className:"h-3 w-3"}):(0,t.jsx)(i.ChevronDown,{className:"h-3 w-3"}),(0,t.jsx)(I,{className:"h-3 w-3"}),"Pinned",(0,t.jsx)("span",{className:"ml-auto text-[9px] tabular-nums opacity-60",children:eA.length})]}),!eE&&eA.map(e=>(0,t.jsxs)(aO,{children:[(0,t.jsx)(aI,{asChild:!0,children:(0,t.jsxs)("div",{role:"button",tabIndex:0,className:(0,tf.cn)("group flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer transition-colors select-none",ts?.path===e.path?"bg-accent-soft text-foreground font-medium":"hover:bg-muted"),onClick:()=>{aG(e)},onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),aG(e))},children:[(0,t.jsx)(rC,{name:e.name,type:e.type??"file"}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate text-xs",title:t_?e.name:void 0,children:t_?ro(e.name):e.name}),(0,t.jsx)("span",{className:"max-w-[80px] truncate text-[10px] text-muted-foreground/60",children:e.path.split("/").slice(0,-1).join("/")}),(0,t.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 pinned",onClick:t=>{t.stopPropagation(),a2.getState().toggle({path:e.path,name:e.name},G)},children:(0,t.jsx)(K.X,{className:"h-3 w-3"})})]})}),(0,t.jsx)(r_,{node:{path:e.path,name:e.name,type:e.type??"file"},ctx:ny,isPinned:!0,activeWorkspaceId:G})]},e.path))]}),eC.length>0&&(0,t.jsxs)("div",{className:"border-b mb-1",children:[(0,t.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:()=>eD(e=>!e),children:[eM?(0,t.jsx)(l.ChevronRight,{className:"h-3 w-3"}):(0,t.jsx)(i.ChevronDown,{className:"h-3 w-3"}),(0,t.jsx)(v,{className:"h-3 w-3"}),"Recent",(0,t.jsx)("span",{className:"ml-auto text-[9px] tabular-nums opacity-60",children:eC.length})]}),!eM&&eC.slice(0,8).map(e=>(0,t.jsxs)(aO,{children:[(0,t.jsx)(aI,{asChild:!0,children:(0,t.jsxs)("div",{role:"button",tabIndex:0,className:(0,tf.cn)("flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer transition-colors select-none",ts?.path===e.path?"bg-accent-soft text-foreground font-medium":"hover:bg-muted"),onClick:()=>{aH({path:e.path,name:e.name,type:e.type??"file",modifiedAt:""}),ty&&tN(!0)},onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),aH({path:e.path,name:e.name,type:e.type??"file",modifiedAt:""}))},children:[(0,t.jsx)(rC,{name:e.name,type:e.type??"file"}),(0,t.jsx)("span",{className:"flex-1 truncate text-xs",title:t_?e.name:void 0,children:t_?ro(e.name):e.name}),(0,t.jsx)("span",{className:"text-[10px] text-muted-foreground/60 truncate max-w-[80px]",children:e.path.split("/").slice(0,-1).join("/")})]})}),(0,t.jsx)(r_,{node:{path:e.path,name:e.name,type:e.type??"file"},ctx:ny,isPinned:eA.some(t=>t.path===e.path),activeWorkspaceId:G})]},e.path))]}),e$?(0,t.jsx)("div",{className:"flex justify-center py-6",children:(0,t.jsx)(_.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):0===eL.length?(0,t.jsxs)("div",{className:"flex flex-col items-center gap-3 px-4 py-8 text-center",children:[(0,t.jsx)("div",{className:"rounded-full bg-muted p-3",children:(0,t.jsx)(p.FileText,{className:"h-6 w-6 text-muted-foreground"})}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)("p",{className:"text-sm font-medium",children:"No files yet"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Upload files or add them to the configured directory"})]}),(0,t.jsxs)(W.Button,{size:"sm",variant:"outline",className:"w-full gap-1.5 max-w-[180px]",onClick:()=>a4(""),disabled:eW,children:[eW?(0,t.jsx)(_.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(q.Upload,{className:"h-3.5 w-3.5"}),"Upload Files"]})]}):(0,t.jsx)(rS,{ctx:ny,nodes:eL,openPath:ts?.path??null,dragOverPath:t9,branchDropdownNode:aS,branchDropdownPos:aD,nodeBranches:ay,branchesLoading:ak,checkingOutBranch:aC,pullingRepo:ar,activePaths:eI,pins:eA,isMobile:ty,activeWorkspaceId:G,newFileParent:e3,newFileName:e9,fileCreateError:e6,newFolderParent:eQ,newFolderName:e0,folderError:e2,sidebarScrollRef:eO})]}),(0,t.jsxs)("div",{className:"border-t px-2 py-2 bg-muted shrink-0",children:[(0,t.jsxs)(tR.DropdownMenu,{modal:!1,onOpenChange:e=>{e||(ev(null),ej(null))},children:[(0,t.jsx)(tR.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsxs)(W.Button,{size:"sm",variant:"ghost",className:"w-full h-auto justify-between gap-2 px-2 py-1.5 text-left",title:x??"",children:[(0,t.jsxs)("span",{className:"flex flex-col min-w-0",children:[(0,t.jsx)("span",{className:"truncate text-xs font-medium",children:J.find(e=>e.id===G)?.name??"Workspace"}),(0,t.jsx)("span",{className:"truncate text-[10px] text-muted-foreground font-mono",children:x??""})]}),(0,t.jsx)(i.ChevronDown,{className:"h-3.5 w-3.5 shrink-0 opacity-60"})]})}),(0,t.jsxs)(tR.DropdownMenuContent,{align:"start",className:"w-[var(--radix-dropdown-menu-trigger-width)]",onInteractOutside:e=>{e.target?.closest?.("[data-branch-portal]")&&e.preventDefault()},children:[J.map(e=>(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>void aZ(e.id),onPointerMove:e=>e.preventDefault(),onPointerLeave:e=>e.preventDefault(),className:(0,tf.cn)("gap-2",e.id===G&&"font-medium"),children:[e.id===G?(0,t.jsx)(s.Check,{className:"h-3.5 w-3.5 shrink-0"}):(0,t.jsx)("span",{className:"w-3.5 shrink-0"}),(0,t.jsxs)("span",{className:"flex flex-col min-w-0 flex-1",children:[(0,t.jsxs)("span",{className:"flex items-center gap-1.5 truncate",children:[(0,t.jsx)("span",{className:"truncate",children:e.name}),e.git?Y?(0,t.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:ef===e.id,onClick:t=>{if(t.stopPropagation(),t.preventDefault(),ey===e.id){ev(null),ej(null);return}let a=t.currentTarget.getBoundingClientRect();ej({top:a.bottom+4,left:a.left}),ev(e.id),aQ(e.id)},children:[(0,t.jsx)(g,{className:"h-2.5 w-2.5"})," ",e.git.branch??"branch"]}):(0,t.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,t.jsx)(g,{className:"h-2.5 w-2.5"})," ",e.git.branch??"read-only"]}):e.ssh?(0,t.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,t.jsx)(b,{className:"h-2.5 w-2.5"})," ",e.ssh.host]}):e.readOnly?(0,t.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,t.jsx)(g,{className:"h-2.5 w-2.5"})," read-only"]}):null]}),(0,t.jsx)("span",{className:"truncate text-[10px] text-muted-foreground font-mono",children:e.rootDir}),e.git?.lastPulledAt&&rd(e.git.lastPulledAt)&&(0,t.jsxs)("span",{className:"text-[10px] text-muted-foreground/70",children:["synced ",rd(e.git.lastPulledAt)]})]}),Y&&e.git&&(0,t.jsx)("button",{className:(0,tf.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:em===e.id,onClick:t=>{t.stopPropagation(),t.preventDefault(),aJ(e.id)},children:(0,t.jsx)(F,{className:(0,tf.cn)("h-3.5 w-3.5",em===e.id&&"animate-spin")})}),Y&&(0,t.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(),eu(e.id)},children:(0,t.jsx)(U.Trash2,{className:"h-3.5 w-3.5"})})]},e.id)),Y&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tR.DropdownMenuSeparator,{}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>eo(!0),children:[(0,t.jsx)(f,{className:"mr-2 h-3.5 w-3.5"}),"Add workspace…"]})]})]})]}),(()=>{if(!ey||!eN)return null;let e=J.find(e=>e.id===ey);return e?(0,t.jsx)(tK,{pos:eN,branches:(eh[e.id]??[]).map(t=>({name:t,current:t===e.git?.branch})),loading:!eh[e.id],busyName:ef===e.id?eb:null,disabled:ef===e.id,onPick:t=>{a0(e.id,t)},onClose:()=>{ev(null),ej(null)}}):null})()]}),(0,t.jsx)("div",{role:"separator","aria-orientation":"vertical","aria-label":"Resize sidebar",title:"Drag to resize",onMouseDown:e=>{e.preventDefault();let t=e.clientX;tA(!0);let a=document.body.style.cursor,n=document.body.style.userSelect;document.body.style.cursor="col-resize",document.body.style.userSelect="none";let r=e=>{tS(tj+(e.clientX-t))},s=()=>{tA(!1),document.body.style.cursor=a,document.body.style.userSelect=n,window.removeEventListener("mousemove",r),window.removeEventListener("mouseup",s)};window.addEventListener("mousemove",r),window.addEventListener("mouseup",s)},onDoubleClick:()=>tS(288),onKeyDown:e=>{"ArrowLeft"===e.key?(e.preventDefault(),tS(tj-16)):"ArrowRight"===e.key&&(e.preventDefault(),tS(tj+16))},tabIndex:0,"aria-valuemin":200,"aria-valuemax":600,"aria-valuenow":tj,className:(0,tf.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",tM&&"bg-primary/60")})]}),(0,t.jsxs)("div",{className:"flex-1 flex flex-col min-w-0 relative",children:[tv&&(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"hidden md:flex absolute left-2 top-2 z-10 h-7 w-7 p-0",title:"Show sidebar",onClick:()=>tN(!1),children:(0,t.jsx)(D,{className:"h-3.5 w-3.5"})}),(0,t.jsxs)("div",{className:"md:hidden flex h-11 shrink-0 items-center justify-between gap-2 border-b bg-muted px-1",children:[(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-9 w-9 p-0",title:"Show sidebar",onClick:()=>{tN(!1),a3.useAIPanelStore.getState().close()},children:(0,t.jsx)(D,{className:"h-4 w-4"})}),(0,t.jsxs)("span",{className:"flex min-w-0 items-center gap-1.5 text-xs font-semibold tracking-tight text-muted-foreground",title:ts?.path,children:[ts&&(0,t.jsx)("span",{className:"editorial-tree-typeicon shrink-0",children:"app"===nc||"html"===nc?(0,t.jsx)(y.Globe,{className:"h-4 w-4 text-foreground/70"}):rg(ts.name)?(0,t.jsx)(j.Image,{className:"h-4 w-4 text-sunshine-700"}):rx(ts.name)?(0,t.jsx)(p.FileText,{className:"h-4 w-4 text-foreground/70"}):(0,t.jsx)(u.File,{className:"h-4 w-4 text-foreground/60"})}),(0,t.jsx)("span",{className:"truncate",children:ts?ts.name:"Wiki Viewer"})]}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-9 w-9 p-0",title:"AI Agent panel",onClick:()=>{a3.useAIPanelStore.getState().open(),tN(!0)},children:(0,t.jsx)(r,{className:"h-4 w-4"})})]}),ts?"node-app"===nc?(0,t.jsx)(tL,{path:ts.path,title:ts.name}):"app"===nc||"html"===nc?(e="html"===nc?`/api/assets/${ts.path}`:void 0,tc?(0,t.jsx)(tO,{path:ts.path,title:ts.name,src:e,fullscreen:!0,onExit:()=>td(!1)}):(0,t.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,t.jsxs)("div",{className:(0,tf.cn)("flex items-center justify-between px-4 py-2 border-b bg-muted shrink-0 editorial-doc-header",!ty&&tv&&"pl-11"),children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,t.jsx)("span",{className:"hidden md:inline-flex",children:(0,t.jsx)("span",{className:"editorial-tree-typeicon",children:(0,t.jsx)(y.Globe,{className:"h-4 w-4 shrink-0 text-foreground/70"})})}),(0,t.jsx)("span",{className:"hidden md:inline text-sm font-normal truncate",title:ts.path,children:ts.path})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[ns(ts,(0,t.jsxs)(t.Fragment,{children:["html"===nc&&!tV&&(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>t0(e=>!e),children:[tQ?(0,t.jsx)(y.Globe,{className:"mr-2 h-3.5 w-3.5"}):(0,t.jsx)(w.Code2,{className:"mr-2 h-3.5 w-3.5"}),tQ?"Show preview":"Show source"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>tp(e=>e+1),children:[(0,t.jsx)(F,{className:"mr-2 h-3.5 w-3.5"}),"Refresh"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>td(!0),children:[(0,t.jsx)(C,{className:"mr-2 h-3.5 w-3.5"}),"Open fullscreen"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>tP(!0),children:[(0,t.jsx)(P,{className:"mr-2 h-3.5 w-3.5"}),"Share"]})]})),"html"===nc&&!tV&&null!==tB&&(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Edit source",onClick:()=>{tZ(!0),tJ(tB),t3(null)},children:(0,t.jsx)(A,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{ti(null),tZ(!1)},children:(0,t.jsx)(K.X,{className:"h-3.5 w-3.5"})})]})]}),tV&&"html"===nc?(0,t.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:[(0,t.jsx)("textarea",{value:tX,onChange:e=>tJ(e.target.value),spellCheck:!1,className:"flex-1 w-full min-h-0 resize-none bg-background text-foreground px-4 py-3 font-mono text-[13px] leading-relaxed outline-none border-0"}),(0,t.jsxs)("div",{className:"border-t px-4 py-2 flex items-center justify-end gap-2 bg-muted shrink-0",children:[t5&&(0,t.jsx)("span",{className:"text-xs text-destructive mr-auto",children:t5}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",onClick:()=>{tZ(!1),t3(null)},children:"Cancel"}),(0,t.jsxs)(W.Button,{size:"sm",className:"gap-1",onClick:a1,disabled:t1,children:[t1&&(0,t.jsx)(_.Loader2,{className:"h-3 w-3 animate-spin"}),"Save"]})]})]}):tQ&&"html"===nc?(0,t.jsx)(tD,{path:ts.path,title:ts.name}):(0,t.jsx)(tO,{path:ts.path,title:ts.name,src:e},tu)]})):(0,t.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,t.jsxs)("div",{className:(0,tf.cn)("flex items-center justify-between px-4 py-2 border-b bg-muted shrink-0 editorial-doc-header",!ty&&tv&&"pl-11"),children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,t.jsx)("span",{className:"hidden md:inline-flex",children:(0,t.jsx)("span",{className:"editorial-tree-typeicon",children:rg(ts.name)?(0,t.jsx)(j.Image,{className:"h-4 w-4 shrink-0 text-sunshine-700"}):rx(ts.name)?(0,t.jsx)(p.FileText,{className:"h-4 w-4 shrink-0 text-foreground/70"}):(0,t.jsx)(u.File,{className:"h-4 w-4 shrink-0 text-foreground/60"})})}),(0,t.jsx)("span",{className:"hidden md:inline text-sm font-normal truncate",title:ts.path,children:ts.path}),ai&&(0,t.jsxs)("span",{className:"hidden md:flex items-center gap-1 text-[11px] text-muted-foreground shrink-0 ml-1",children:[(0,t.jsx)(N,{className:"h-3 w-3 shrink-0"}),(0,t.jsx)("span",{className:"truncate max-w-[100px]",children:ai.author}),(0,t.jsx)("span",{title:new Date(ai.date).toLocaleString(),className:"shrink-0",children:rd(ai.date)})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[ns(ts,(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>{ao?ac(!1):aF()},children:[(0,t.jsx)(v,{className:"mr-2 h-3.5 w-3.5"}),ao?"Hide history":"File history"]}),(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>tP(!0),children:[(0,t.jsx)(P,{className:"mr-2 h-3.5 w-3.5"}),"Share"]}),!tV&&(0,t.jsxs)(tR.DropdownMenuItem,{onClick:aq,disabled:tW,children:[tW?(0,t.jsx)(_.Loader2,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(F,{className:"mr-2 h-3.5 w-3.5"}),"Refresh"]}),nf&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tR.DropdownMenuSeparator,{}),(0,t.jsx)(tR.DropdownMenuLabel,{className:"text-[11px] text-muted-foreground",children:"Width"}),n9.VIEW_WIDTH_ORDER.map(e=>(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>nh(e),className:"flex items-center justify-between text-xs",children:[n9.VIEW_WIDTH_LABEL[e],e===nm&&(0,t.jsx)(s.Check,{className:"h-3.5 w-3.5"})]},e)),(0,t.jsx)(tR.DropdownMenuSeparator,{}),(0,t.jsx)(tR.DropdownMenuLabel,{className:"text-[11px] text-muted-foreground",children:"Alignment"}),n9.VIEW_ALIGN_ORDER.map(e=>(0,t.jsxs)(tR.DropdownMenuItem,{onClick:()=>nx(e),className:"flex items-center justify-between text-xs",children:[n9.VIEW_ALIGN_LABEL[e],e===np&&(0,t.jsx)(s.Check,{className:"h-3.5 w-3.5"})]},e))]})]})),rx(ts.name)&&!tV&&(null!==tB||rf(ts.name))&&(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{tZ(!0),tJ(tB??""),t3(null),rf(ts.name)&&nn.useEditorStore.getState().loadPage(ts.path)},children:(0,t.jsx)(A,{className:"h-3.5 w-3.5"})}),rx(ts.name)&&tV&&rf(ts.name)&&(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Done editing",onClick:()=>{tZ(!1),t3(null)},children:(0,t.jsx)(O.Eye,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{ti(null),tz(null),tZ(!1)},children:(0,t.jsx)(K.X,{className:"h-3.5 w-3.5"})})]})]}),ao&&(0,t.jsxs)("div",{className:"border-b bg-muted/30 shrink-0 max-h-[40vh] overflow-auto",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between px-4 py-1.5 border-b",children:[(0,t.jsx)("span",{className:"text-xs font-semibold text-muted-foreground",children:"History"}),(0,t.jsx)("button",{type:"button",className:"text-muted-foreground hover:text-foreground",onClick:()=>ac(!1),children:(0,t.jsx)(K.X,{className:"h-3.5 w-3.5"})})]}),am?(0,t.jsx)("div",{className:"flex justify-center py-4",children:(0,t.jsx)(_.Loader2,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):0===ad.length?(0,t.jsx)("p",{className:"px-4 py-3 text-xs text-muted-foreground",children:"No history found."}):(0,t.jsx)("div",{children:ad.map(e=>(0,t.jsxs)("div",{children:[(0,t.jsx)("button",{type:"button",className:(0,tf.cn)("w-full text-left px-4 py-2 hover:bg-muted transition-colors",ah===e.sha&&"bg-muted"),onClick:()=>void aL(e.sha),children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("code",{className:"text-[11px] font-mono text-muted-foreground shrink-0",children:e.shortSha}),(0,t.jsx)("span",{className:"flex-1 truncate text-xs",children:e.message}),(0,t.jsx)("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:e.author}),(0,t.jsx)("span",{className:"shrink-0 text-[11px] text-muted-foreground",title:new Date(e.date).toLocaleString(),children:rd(e.date)})]})}),ah===e.sha&&(0,t.jsx)("div",{className:"border-t",children:ab?(0,t.jsx)("div",{className:"flex justify-center py-3",children:(0,t.jsx)(_.Loader2,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):null!==af?(0,t.jsx)("pre",{className:"overflow-auto px-4 py-2 text-[11px] font-mono leading-relaxed whitespace-pre text-foreground/80 max-h-60",children:af}):null})]},e.sha))})]}),nd?(0,t.jsx)(es,{path:ts.path,size:ts.size??0,onOpen:()=>to(ts.path)}):tV?(0,t.jsx)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:rf(ts.name)?(0,t.jsx)(et.KBEditor,{}):(0,t.jsx)("textarea",{value:tX,onChange:e=>tJ(e.target.value),spellCheck:!1,className:"flex-1 w-full min-h-0 resize-none bg-background text-foreground px-4 py-3 font-mono text-[13px] leading-relaxed outline-none border-0"})}):rf(ts.name)?(0,t.jsx)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:tW?(0,t.jsx)("div",{className:"flex justify-center py-8",children:(0,t.jsx)(_.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):(0,t.jsx)(et.KBEditor,{mode:"viewing"})}):"csv"===nc||"pdf"===nc||"mermaid"===nc||"notebook"===nc||"image"===nc||"media"===nc||"docx"===nc||"xlsx"===nc||"pptx"===nc||"source"===nc||"fallback"===nc?(0,t.jsx)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:tW?(0,t.jsx)("div",{className:"flex justify-center py-8",children:(0,t.jsx)(_.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):"csv"===nc?(0,t.jsx)(ee,{path:ts.path,title:ts.name}):"pdf"===nc?(0,t.jsx)(rc,{path:ts.path,title:ts.name}):"mermaid"===nc?(0,t.jsx)(ec,{path:ts.path,title:ts.name}):"notebook"===nc?(0,t.jsx)(tm,{path:ts.path,title:ts.name}):"image"===nc?(0,t.jsx)(ei,{path:ts.path,title:ts.name}):"media"===nc?(0,t.jsx)(el,{path:ts.path,title:ts.name,type:["mp4","webm","mov","m4v"].includes(rm(ts.name))?"video":"audio"}):"docx"===nc?(0,t.jsx)(th,{path:ts.path,title:ts.name}):"xlsx"===nc?(0,t.jsx)(tg,{path:ts.path,title:ts.name}):"pptx"===nc?(0,t.jsx)(tx,{path:ts.path,title:ts.name}):"source"===nc?(0,t.jsx)(tD,{path:ts.path,title:ts.name}):(0,t.jsx)(ea,{path:ts.path,title:ts.name})},tb):(0,t.jsx)("div",{className:"flex-1 overflow-auto p-4 min-h-0",children:(0,t.jsx)("div",{className:(0,tf.cn)("w-full",nb,ng),children:tW?(0,t.jsx)("div",{className:"flex justify-center py-8",children:(0,t.jsx)(_.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):null!==tB?(0,t.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-words leading-relaxed",children:tB}):rx(ts.name)?(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Could not load file."}):(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Preview not available for this file type."})})}),tV&&!rf(ts.name)&&(0,t.jsxs)("div",{className:"border-t px-4 py-2 flex items-center justify-end gap-2 bg-muted shrink-0",children:[t5&&(0,t.jsx)("span",{className:"text-xs text-destructive mr-auto",children:t5}),(0,t.jsx)(W.Button,{size:"sm",variant:"ghost",onClick:()=>{tZ(!1),t3(null)},children:"Cancel"}),(0,t.jsxs)(W.Button,{size:"sm",className:"gap-1",onClick:a1,disabled:t1,children:[t1&&(0,t.jsx)(_.Loader2,{className:"h-3 w-3 animate-spin"}),"Save"]})]})]}):(0,t.jsx)("div",{className:"flex-1 flex flex-col items-center justify-center",children:(0,t.jsxs)("div",{className:"flex flex-col items-center gap-2 text-center px-4",children:[(0,t.jsx)(p.FileText,{className:"h-8 w-8 text-muted-foreground"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Select a file to view or edit"})]})})]}),(0,t.jsx)(aN,{open:tF,onOpenChange:tP,filePath:ts?.path??""}),(0,t.jsx)(ae,{open:tT,onOpenChange:tI}),(0,t.jsx)(nu,{currentPath:ts?.path}),(0,t.jsx)("input",{ref:eX,type:"file",multiple:!0,className:"hidden",onChange:e=>{e.target.files&&a5(e.target.files,eJ.current)}}),(0,t.jsx)(V,{open:!!te,onOpenChange:e=>{e||tt(null)},title:ta?"Delete folder?":"Delete file?",description:ta?`"${te?.split("/").pop()}" and all its contents will be permanently deleted.`:`"${te?.split("/").pop()}" will be permanently removed.`,onConfirm:ni}),(0,t.jsx)(V,{open:!!ed,onOpenChange:e=>{e||eu(null)},title:"Delete workspace?",description:`"${J.find(e=>e.id===ed)?.name??""}" will be removed from the workspace list. Files on disk are NOT deleted.`,onConfirm:aX})]})]},G??"none")}],952683)}]);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-viewer",
3
- "version": "2.7.3",
3
+ "version": "2.7.4",
4
4
  "description": "Local file viewer and wiki — view markdown, HTML, PDFs, notebooks, office docs, and more from any directory",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-viewer",
3
- "version": "2.7.3",
3
+ "version": "2.7.4",
4
4
  "description": "Local file viewer and wiki — view markdown, HTML, PDFs, notebooks, office docs, and more from any directory",
5
5
  "license": "MIT",
6
6
  "type": "module",