wiki-viewer 2.0.1 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/standalone/.next/BUILD_ID +1 -1
- package/.next/standalone/.next/build-manifest.json +3 -3
- package/.next/standalone/.next/server/app/_global-error.html +1 -1
- package/.next/standalone/.next/server/app/_global-error.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found.html +1 -1
- package/.next/standalone/.next/server/app/_not-found.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found.segments/_full.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found.segments/_index.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/_not-found.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/api/agent/activity/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/agent/events/[...path]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/agent/files/[...path]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/agent/fs/file/[...path]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/agent/fs/ls/[[...path]]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/agent/fs/move/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/agent/fs/search/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/agent/internal/span/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/agent/settings/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/agent/sidecar/[...path]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/assets/[...path]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/share/[token]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/share/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/system/reveal/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/system/set-root/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/system/workspaces/[id]/open/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/system/workspaces/[id]/refresh/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/system/workspaces/[id]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/system/workspaces/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/upload/[...path]/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/app/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/backlinks/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/content/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/download/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/file/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/folder/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/git-branches/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/git-checkout/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/git-diff/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/git-file-info/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/git-history/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/git-pull/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/move/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/new-file/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/outlinks/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/page/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/presence/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/search/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/slugs/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/upload/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/api/wiki/watch/route.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/index.html +1 -1
- package/.next/standalone/.next/server/app/index.rsc +2 -2
- package/.next/standalone/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/index.segments/_full.segment.rsc +2 -2
- package/.next/standalone/.next/server/app/index.segments/_head.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/index.segments/_index.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/index.segments/_tree.segment.rsc +1 -1
- package/.next/standalone/.next/server/app/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/app/s/[token]/page.js.nft.json +1 -1
- package/.next/standalone/.next/server/app/s/[token]/page_client-reference-manifest.js +1 -1
- package/.next/standalone/.next/server/chunks/[root-of-the-server]__0w~__xz._.js +1 -1
- package/.next/standalone/.next/server/chunks/ssr/{[root-of-the-server]__10m6c40._.js → [root-of-the-server]__0g2q.m9._.js} +1 -1
- package/.next/standalone/.next/server/chunks/ssr/{_0yevh-d._.js → _026lnd.._.js} +7 -7
- package/.next/standalone/.next/server/chunks/ssr/_06rf50_._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/{_0~a9dyk._.js → _0hpi._s._.js} +6 -6
- package/.next/standalone/.next/server/chunks/ssr/_0jdop6l._.js +3 -0
- package/.next/standalone/.next/server/chunks/ssr/src_app_page_tsx_0ss2.w7._.js +1 -1
- package/.next/standalone/.next/server/middleware-build-manifest.js +3 -3
- package/.next/standalone/.next/server/middleware-manifest.json +1 -1
- package/.next/standalone/.next/server/pages/404.html +1 -1
- package/.next/standalone/.next/server/pages/500.html +1 -1
- package/.next/standalone/.next/static/chunks/0_p-~rp2hak3c.js +113 -0
- package/.next/standalone/.next/static/chunks/0lrkdb9w.6kl1.js +1 -0
- package/.next/standalone/.next/static/chunks/{0ey6h_rkpuzxs.js → 0oy4xayqkedl5.js} +5 -5
- package/.next/standalone/.next/static/chunks/{0.69aou29w6ma.js → 0r0fa52s8puxv.js} +1 -1
- package/.next/standalone/.next/static/chunks/14_efa7172tp-.js +1 -0
- package/.next/standalone/package.json +1 -1
- package/package.json +1 -1
- package/.next/standalone/.next/server/chunks/ssr/_0wmhtx3._.js +0 -3
- package/.next/standalone/.next/static/chunks/0jt1z17mjmjde.js +0 -113
- package/.next/standalone/.next/static/chunks/0wxju9pxda4c2.js +0 -1
- /package/.next/standalone/.next/static/{nbWvTsOgKt53BB3Gl0swc → XIglKqX0BlS2ovM_Stm9Z}/_buildManifest.js +0 -0
- /package/.next/standalone/.next/static/{nbWvTsOgKt53BB3Gl0swc → XIglKqX0BlS2ovM_Stm9Z}/_clientMiddlewareManifest.js +0 -0
- /package/.next/standalone/.next/static/{nbWvTsOgKt53BB3Gl0swc → XIglKqX0BlS2ovM_Stm9Z}/_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,z.useState)(""),h=(0,z.useRef)(null),x=window.location.origin,f=(0,z.useCallback)(()=>a6,[]),g=(0,z.useCallback)(()=>m.replace(/\$WIKI_URL/g,x),[m,x]),b=(0,z.useCallback)(()=>`npx wiki-viewer-mcp register --url ${x} --id ai:myagent --name "My Agent"`,[x]),w=(0,z.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=a8(f),v=a8(g),N=a8(b),k=a8(w);return((0,z.useEffect)(()=>{if(a)return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e);function e(e){"Escape"===e.key&&n()}},[a,n]),(0,z.useEffect)(()=>{a&&h.current?.focus()},[a]),(0,z.useEffect)(()=>{if(!a)return;c();let e=setInterval(()=>void c(),1e4);return()=>clearInterval(e)},[a,c]),(0,z.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)(s,{className:"h-4 w-4 text-muted-foreground"}),(0,t.jsx)("span",{className:"text-sm font-semibold",children:"AI Agent"})]}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:n,title:"Close panel (Esc)",children:(0,t.jsx)(B.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)(U.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)(r.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:a6}),(0,t.jsx)(U.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)(r.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)(U.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)(r.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)(U.Button,{size:"sm",variant:"outline",className:"h-7 w-full text-xs gap-1.5",onClick:()=>void k.copy(),children:k.copied?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(r.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)(r.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)(et.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)(et.ExternalLink,{className:"h-3 w-3"})," install JSON"]})]})]}),(0,t.jsx)(a1,{}),(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)(aW,{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)(a9,{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 nt=e.i(580330),na=e.i(409082),nn=e.i(877031),ns=e.i(847463),nr=e.i(917356),ni=/[\\\/_+.#"@\[\(\{&]/,nl=/[\\\/_+.#"@\[\(\{&]/g,no=/[\s-]/,nc=/[\s-]/g;function nd(e){return e.toLowerCase().replace(nc," ")}var nu=e.i(750110),nm=e.i(433616),np='[cmdk-group=""]',nh='[cmdk-group-items=""]',nx='[cmdk-item=""]',nf=`${nx}:not([aria-disabled="true"])`,ng="cmdk-item-select",nb="data-value",nw=(e,t,a)=>{var n;return n=e,function e(t,a,n,s,r,i,l){if(i===a.length)return r===t.length?1:.99;var o=`${r},${i}`;if(void 0!==l[o])return l[o];for(var c,d,u,m,p=s.charAt(i),h=n.indexOf(p,r),x=0;h>=0;)(c=e(t,a,n,s,h+1,i+1,l))>x&&(h===r?c*=1:ni.test(t.charAt(h-1))?(c*=.8,(u=t.slice(r,h-1).match(nl))&&r>0&&(c*=Math.pow(.999,u.length))):no.test(t.charAt(h-1))?(c*=.9,(m=t.slice(r,h-1).match(nc))&&r>0&&(c*=Math.pow(.999,m.length))):(c*=.17,r>0&&(c*=Math.pow(.999,h-r))),t.charAt(h)!==a.charAt(i)&&(c*=.9999)),(c<.1&&n.charAt(h-1)===s.charAt(i+1)||s.charAt(i+1)===s.charAt(i)&&n.charAt(h-1)!==s.charAt(i))&&.1*(d=e(t,a,n,s,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,nd(n),nd(t),0,0,{})},ny=z.createContext(void 0),nv=z.createContext(void 0),nN=z.createContext(void 0),nk=z.forwardRef((e,t)=>{let a=nT(()=>{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=nT(()=>new Set),s=nT(()=>new Map),r=nT(()=>new Map),i=nT(()=>new Set),l=nD(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,nm.useId)(),w=(0,nm.useId)(),y=(0,nm.useId)(),v=z.useRef(null),N=nF();nO(()=>{if(void 0!==d){let e=d.trim();a.current.value=e,k.emit()}},[d]),nO(()=>{N(6,M)},[]);let k=z.useMemo(()=>({subscribe:e=>(i.current.add(e),()=>i.current.delete(e)),snapshot:()=>a.current,setState:(e,t,n)=>{var s,r,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==(s=document.getElementById(b))||s.focus()}if(N(7,()=>{var e;a.current.selectedItemId=null==(e=A())?void 0:e.id,k.emit()}),n||N(5,M),(null==(r=l.current)?void 0:r.value)!==void 0){null==(o=(i=l.current).onValueChange)||o.call(i,null!=t?t:"");return}}k.emit()}},emit:()=>{i.current.forEach(e=>e())}}),[]),j=z.useMemo(()=>({value:(e,t,n)=>{var s;t!==(null==(s=r.current.get(e))?void 0:s.value)&&(r.current.set(e,{value:t,keywords:n}),a.current.filtered.items.set(e,_(t,n)),N(2,()=>{C(),k.emit()}))},item:(e,t)=>(n.current.add(e),t&&(s.current.has(t)?s.current.get(t).add(e):s.current.set(t,new Set([e]))),N(3,()=>{S(),C(),a.current.value||E(),k.emit()}),()=>{r.current.delete(e),n.current.delete(e),a.current.filtered.items.delete(e);let t=A();N(4,()=>{S(),(null==t?void 0:t.getAttribute("id"))===e&&E(),k.emit()})}),group:e=>(s.current.has(e)||s.current.set(e,new Set),()=>{r.current.delete(e),s.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,s;let r=null!=(s=null==(n=l.current)?void 0:n.filter)?s:nw;return e?r(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=s.current.get(a),r=0;n.forEach(t=>{r=Math.max(e.get(t),r)}),t.push([a,r])});let n=v.current;D().sort((t,a)=>{var n,s;let r=t.getAttribute("id"),i=a.getAttribute("id");return(null!=(n=e.get(i))?n:0)-(null!=(s=e.get(r))?s:0)}).forEach(e=>{let t=e.closest(nh);t?t.appendChild(e.parentElement===t?e:e.closest(`${nh} > *`)):n.appendChild(e.parentElement===n?e:e.closest(`${nh} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{var t;let a=null==(t=v.current)?void 0:t.querySelector(`${np}[${nb}="${encodeURIComponent(e[0])}"]`);null==a||a.parentElement.appendChild(a)})}function E(){let e=D().find(e=>"true"!==e.getAttribute("aria-disabled")),t=null==e?void 0:e.getAttribute(nb);k.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 s of n.current){let n=_(null!=(t=null==(e=r.current.get(s))?void 0:e.value)?t:"",null!=(o=null==(i=r.current.get(s))?void 0:i.keywords)?o:[]);a.current.filtered.items.set(s,n),n>0&&c++}for(let[e,t]of s.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=A();n&&((null==(e=n.parentElement)?void 0:e.firstChild)===n&&(null==(a=null==(t=n.closest(np))?void 0:t.querySelector('[cmdk-group-heading=""]'))||a.scrollIntoView({block:"nearest"})),n.scrollIntoView({block:"nearest"}))}function A(){var e;return null==(e=v.current)?void 0:e.querySelector(`${nx}[aria-selected="true"]`)}function D(){var e;return Array.from((null==(e=v.current)?void 0:e.querySelectorAll(nf))||[])}function O(e){let t=D()[e];t&&k.setState("value",t.getAttribute(nb))}function T(e){var t;let a=A(),n=D(),s=n.findIndex(e=>e===a),r=n[s+e];null!=(t=l.current)&&t.loop&&(r=s+e<0?n[n.length-1]:s+e===n.length?n[0]:n[s+e]),r&&k.setState("value",r.getAttribute(nb))}function I(e){let t=A(),a=null==t?void 0:t.closest(np),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,np):function(e,t){let a=e.previousElementSibling;for(;a;){if(a.matches(t))return a;a=a.previousElementSibling}}(a,np))?void 0:a.querySelector(nf);n?k.setState("value",n.getAttribute(nb)):T(e)}let R=()=>O(D().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 z.createElement(nu.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=A();if(t){let e=new Event(ng);t.dispatchEvent(e)}}}}},z.createElement("label",{"cmdk-label":"",htmlFor:j.inputId,id:j.labelId,style:nP},o),nL(e,e=>z.createElement(nv.Provider,{value:k},z.createElement(ny.Provider,{value:j},e))))}),nj=z.forwardRef((e,t)=>{var a,n;let s=(0,nm.useId)(),r=z.useRef(null),i=z.useContext(nN),l=z.useContext(ny),o=nD(e),c=null!=(n=null==(a=o.current)?void 0:a.forceMount)?n:null==i?void 0:i.forceMount;nO(()=>{if(!c)return l.item(s,null==i?void 0:i.id)},[c]);let d=nR(s,r,[e.value,e.children,r],e.keywords),u=z.useContext(nv),m=nI(e=>e.value&&e.value===d.current),p=nI(e=>!!c||!1===l.filter()||!e.search||e.filtered.items.get(s)>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(z.useEffect(()=>{let t=r.current;if(!(!t||e.disabled))return t.addEventListener(ng,h),()=>t.removeEventListener(ng,h)},[p,e.onSelect,e.disabled]),!p)return null;let{disabled:f,value:g,onSelect:b,forceMount:w,keywords:y,...v}=e;return z.createElement(nu.Primitive.div,{ref:(0,t3.composeRefs)(r,t),...v,id:s,"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)}),n_=z.forwardRef((e,t)=>{let{heading:a,children:n,forceMount:s,...r}=e,i=(0,nm.useId)(),l=z.useRef(null),o=z.useRef(null),c=(0,nm.useId)(),d=z.useContext(ny),u=nI(e=>!!s||!1===d.filter()||!e.search||e.filtered.groups.has(i));nO(()=>d.group(i),[]),nR(i,l,[e.value,e.heading,o]);let m=z.useMemo(()=>({id:i,forceMount:s}),[s]);return z.createElement(nu.Primitive.div,{ref:(0,t3.composeRefs)(l,t),...r,"cmdk-group":"",role:"presentation",hidden:!u||void 0},a&&z.createElement("div",{ref:o,"cmdk-group-heading":"","aria-hidden":!0,id:c},a),nL(e,e=>z.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":a?c:void 0},z.createElement(nN.Provider,{value:m},e))))}),nC=z.forwardRef((e,t)=>{let{alwaysRender:a,...n}=e,s=z.useRef(null),r=nI(e=>!e.search);return a||r?z.createElement(nu.Primitive.div,{ref:(0,t3.composeRefs)(s,t),...n,"cmdk-separator":"",role:"separator"}):null}),nE=z.forwardRef((e,t)=>{let{onValueChange:a,...n}=e,s=null!=e.value,r=z.useContext(nv),i=nI(e=>e.search),l=nI(e=>e.selectedItemId),o=z.useContext(ny);return z.useEffect(()=>{null!=e.value&&r.setState("search",e.value)},[e.value]),z.createElement(nu.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:s?e.value:i,onChange:e=>{s||r.setState("search",e.target.value),null==a||a(e.target.value)}})}),nS=z.forwardRef((e,t)=>{let{children:a,label:n="Suggestions",...s}=e,r=z.useRef(null),i=z.useRef(null),l=nI(e=>e.selectedItemId),o=z.useContext(ny);return z.useEffect(()=>{if(i.current&&r.current){let e=i.current,t=r.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)}}},[]),z.createElement(nu.Primitive.div,{ref:(0,t3.composeRefs)(r,t),...s,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":l,"aria-label":n,id:o.listId},nL(e,e=>z.createElement("div",{ref:(0,t3.composeRefs)(i,o.listInnerRef),"cmdk-list-sizer":""},e)))}),nM=z.forwardRef((e,t)=>{let{open:a,onOpenChange:n,overlayClassName:s,contentClassName:r,container:i,...l}=e;return z.createElement(tL.Root,{open:a,onOpenChange:n},z.createElement(tL.Portal,{container:i},z.createElement(tL.Overlay,{"cmdk-overlay":"",className:s}),z.createElement(tL.Content,{"aria-label":e.label,"cmdk-dialog":"",className:r},z.createElement(nk,{ref:t,...l}))))}),nA=Object.assign(nk,{List:nS,Item:nj,Input:nE,Group:n_,Separator:nC,Dialog:nM,Empty:z.forwardRef((e,t)=>nI(e=>0===e.filtered.count)?z.createElement(nu.Primitive.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),Loading:z.forwardRef((e,t)=>{let{progress:a,children:n,label:s="Loading...",...r}=e;return z.createElement(nu.Primitive.div,{ref:t,...r,"cmdk-loading":"",role:"progressbar","aria-valuenow":a,"aria-valuemin":0,"aria-valuemax":100,"aria-label":s},nL(e,e=>z.createElement("div",{"aria-hidden":!0},e)))})});function nD(e){let t=z.useRef(e);return nO(()=>{t.current=e}),t}var nO="u"<typeof window?z.useEffect:z.useLayoutEffect;function nT(e){let t=z.useRef();return void 0===t.current&&(t.current=e()),t}function nI(e){let t=z.useContext(nv),a=()=>e(t.snapshot());return z.useSyncExternalStore(t.subscribe,a,a)}function nR(e,t,a,n=[]){let s=z.useRef(),r=z.useContext(ny);return nO(()=>{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():s.current}})(),o=n.map(e=>e.trim());r.value(e,l,o),null==(i=t.current)||i.setAttribute(nb,l),s.current=l}),s}var nF=()=>{let[e,t]=z.useState(),a=nT(()=>new Map);return nO(()=>{a.current.forEach(e=>e()),a.current=new Map},[e]),(e,n)=>{a.current.set(e,n),t({})}};function nL({asChild:e,children:t},a){let n;return e&&z.isValidElement(t)?z.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 nP={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};let nB=(0,n.default)("search",[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]),nz=z.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nA,{ref:n,className:(0,V.cn)("flex h-full w-full flex-col overflow-hidden rounded-sm bg-popover text-popover-foreground",e),...a}));function n$({children:e,shouldFilter:a,...n}){return(0,t.jsx)(q.Dialog,{...n,children:(0,t.jsxs)(q.DialogContent,{className:"overflow-hidden p-0 shadow-golden max-w-lg",children:[(0,t.jsx)(q.DialogTitle,{className:"sr-only",children:"Search"}),(0,t.jsx)(nz,{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})]})})}nz.displayName=nA.displayName;let nU=z.forwardRef(({className:e,...a},n)=>(0,t.jsxs)("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[(0,t.jsx)(nB,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),(0,t.jsx)(nA.Input,{ref:n,className:(0,V.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})]}));nU.displayName=nA.Input.displayName;let nq=z.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nA.List,{ref:n,className:(0,V.cn)("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...a}));nq.displayName=nA.List.displayName;let nK=z.forwardRef((e,a)=>(0,t.jsx)(nA.Empty,{ref:a,className:"py-6 text-center text-sm text-muted-foreground",...e}));nK.displayName=nA.Empty.displayName;let nH=z.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nA.Group,{ref:n,className:(0,V.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}));nH.displayName=nA.Group.displayName;let nW=z.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nA.Separator,{ref:n,className:(0,V.cn)("-mx-1 h-px bg-border",e),...a}));nW.displayName=nA.Separator.displayName;let nG=z.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nA.Item,{ref:n,className:(0,V.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}));nG.displayName=nA.Item.displayName;let nV=null,nZ=null,nX=(0,tW.create)(e=>({query:"",results:[],loading:!1,truncated:!1,open:!1,setQuery:t=>e({query:t}),setOpen:t=>e({open:t}),clear:()=>{nZ&&clearTimeout(nZ),nV?.abort(),e({query:"",results:[],loading:!1,truncated:!1})},search:t=>(nZ&&clearTimeout(nZ),t.trim())?(e({loading:!0}),new Promise(a=>{nZ=setTimeout(()=>{nJ(e,t).finally(a)},150)})):(nV?.abort(),e({results:[],loading:!1,truncated:!1}),Promise.resolve())}));async function nJ(e,t){nV?.abort();let a=new AbortController;nV=a;try{let n=await (0,G.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 s=await n.json();if(a.signal.aborted)return;e({results:s.matches??[],truncated:!!s.truncated,loading:!1})}catch(t){"AbortError"!==t.name&&e({loading:!1})}}var nQ=e.i(395624);function nY({html:e}){let a=function(e){let t,a=[],n=/<mark>([\s\S]*?)<\/mark>/g,s=0;for(;null!==(t=n.exec(e));)t.index>s&&a.push({text:e.slice(s,t.index),mark:!1}),a.push({text:t[1]??"",mark:!0}),s=t.index+t[0].length;return s<e.length&&a.push({text:e.slice(s),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 n0({onOpenFile:e,onToggleSidebar:a=()=>void 0,onNewFile:n=()=>void 0,onCopyPath:r=()=>void 0}){let i=nX(e=>e.open),l=nX(e=>e.setOpen),c=nX(e=>e.query),d=nX(e=>e.setQuery),m=nX(e=>e.results),p=nX(e=>e.loading),h=nX(e=>e.truncated),x=nX(e=>e.search),{resolvedTheme:f,setTheme:g}=(0,nr.useTheme)(),b=(0,aG.useAIPanelStore)(e=>e.toggle),w=(0,nQ.useViewWidthStore)(e=>e.width),y=(0,nQ.useViewWidthStore)(e=>e.cycle),v=c.trimStart(),N=""===v||v.startsWith(">"),k=N?"":c;function j(e){e(),l(!1),d("")}(0,z.useEffect)(()=>{function e(e){(e.metaKey||e.ctrlKey)&&"k"===e.key.toLowerCase()&&(e.preventDefault(),l(!i))}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[i,l]),(0,z.useEffect)(()=>{if(!i||N)return;let e=setTimeout(()=>{x(k)},120);return()=>clearTimeout(e)},[k,N,i,x]);let _=(nQ.VIEW_WIDTH_ORDER.indexOf(w)+1)%nQ.VIEW_WIDTH_ORDER.length,C=nQ.VIEW_WIDTH_LABEL[nQ.VIEW_WIDTH_ORDER[_]];return(0,t.jsxs)(n$,{open:i,onOpenChange:e=>{l(e),e||d("")},shouldFilter:!1,children:[(0,t.jsx)(nU,{placeholder:"Search files… ( > for actions )",value:c,onValueChange:d}),(0,t.jsxs)(nq,{children:[N&&(0,t.jsxs)(nH,{heading:"Actions",children:[(0,t.jsxs)(nG,{value:"toggle-dark-mode",onSelect:()=>j(()=>g("dark"===f?"light":"dark")),children:["dark"===f?(0,t.jsx)(ns.Sun,{className:"mr-2 h-4 w-4"}):(0,t.jsx)(na.Moon,{className:"mr-2 h-4 w-4"}),"dark"===f?"Switch to light mode":"Switch to dark mode"]}),(0,t.jsxs)(nG,{value:"toggle-ai-panel",onSelect:()=>j(b),children:[(0,t.jsx)(s,{className:"mr-2 h-4 w-4"}),"Toggle AI panel"]}),(0,t.jsxs)(nG,{value:"toggle-sidebar",onSelect:()=>j(a),children:[(0,t.jsx)(nn.PanelLeft,{className:"mr-2 h-4 w-4"}),"Toggle sidebar"]}),(0,t.jsxs)(nG,{value:"new-file",onSelect:()=>j(n),children:[(0,t.jsx)(u.FilePlus,{className:"mr-2 h-4 w-4"}),"New file"]}),(0,t.jsxs)(nG,{value:"copy-path",onSelect:()=>j(r),children:[(0,t.jsx)(o.Copy,{className:"mr-2 h-4 w-4"}),"Copy current file path"]}),(0,t.jsxs)(nG,{value:"cycle-view-width",onSelect:()=>j(y),children:[(0,t.jsx)(nt.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:["(",nQ.VIEW_WIDTH_LABEL[w]," → ",C,")"]})]})]})]}),!N&&(0,t.jsxs)(t.Fragment,{children:[p&&(0,t.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:"Searching…"}),!p&&""!==k.trim()&&0===m.length&&(0,t.jsx)(nK,{children:"No matches."}),m.length>0&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(nW,{}),(0,t.jsx)(nH,{heading:h?"Top results (refine query for more)":"Results",children:m.map(a=>(0,t.jsx)(nG,{value:a.path,onSelect:()=>{e(a.path),l(!1),d("")},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)(nY,{html:a.snippet})})]})},a.path))})]})]})]})]})}function n1({onOpenFile:e}){let a=nX(e=>e.query),n=nX(e=>e.setQuery),s=nX(e=>e.results),r=nX(e=>e.loading),i=nX(e=>e.search),l=nX(e=>e.clear),[o,c]=(0,z.useState)(0),d=(0,z.useRef)(null);function u(t){let a=s[t];a&&(e(a.path),l())}return(0,z.useEffect)(()=>{c(0)},[s]),(0,z.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)(nB,{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!==s.length&&("ArrowDown"===e.key?(e.preventDefault(),c(e=>(e+1)%s.length)):"ArrowUp"===e.key?(e.preventDefault(),c(e=>(e-1+s.length)%s.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:[r&&(0,t.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"Searching…"}),!r&&0===s.length&&(0,t.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"No matches"}),s.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)(nY,{html:e.snippet})})]},e.path))]})]})}let n2="wiki-sidebar-width";function n5(e){return Number.isNaN(e)?288:Math.min(600,Math.max(200,Math.round(e)))}let n3=(0,tW.create)(e=>({width:function(){let e=localStorage.getItem(n2);if(e){let t=Number.parseInt(e,10);if(!Number.isNaN(t))return n5(t)}return 288}(),setWidth:t=>{let a=n5(t);localStorage.setItem(n2,String(a)),e({width:a})}}));var n4=e.i(780569),n7=e.i(246542);let n9="wiki-show-hidden",n6=(0,tW.create)((e,t)=>({showHidden:"1"===localStorage.getItem(n9),toggle:()=>{let a=!t().showHidden;a?localStorage.setItem(n9,"1"):localStorage.removeItem(n9),e({showHidden:a})}}));function n8(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 s=Math.floor(n/60);return s<24?`${s}h ago`:`${Math.floor(s/24)}d ago`}let se=new Set(["image","media","pdf","fallback","app","node-app","html"]);function st(e){return e.split(".").pop()?.toLowerCase()??""}function sa(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=st(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 sn=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 ss(e){let t=sa(e,"file");return"editor"===t||"text"===t||sn.has(st(e))}function sr(e){return["md","markdown"].includes(st(e))}function si(e){return"image"===sa(e,"file")}async function sl(e){let t=await (0,G.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 so=new Map,sc=new Map;async function sd(e){let t=so.get(e);if(t)return so.delete(e),t;let a=sc.get(e);if(a){let t=await a;return so.delete(e),t}return null}function su(e,t,a){return e.map(e=>e.path===t?a(e):e.children?{...e,children:su(e.children,t,a)}:e)}let sm={contentVisibility:"auto",containIntrinsicSize:"auto 32px"},sp=(0,z.memo)(function({node:e,depth:a,ctx:n,isMobile:s,activeWorkspaceId:i,sidebarScrollRef:b,isActive:w,isDragOver:k,isPinned:_,isAgentActive:C,isPulling:E,branchOpen:S,branchPos:M,branches:A,branchLoading:D,checkingOut:T,onHoverEnter:I,onHoverLeave:B}){return(0,t.jsxs)(av,{children:[(0,t.jsx)(ak,{asChild:!0,children:(0,t.jsxs)("div",{role:"treeitem",tabIndex:0,draggable:!s,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=b.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=b.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=b.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=b.current;if(!e)return;let a=Array.from(e.querySelectorAll('[role="treeitem"]')),n=t.currentTarget,s=a.indexOf(n),r=Number.parseInt(n.style.paddingLeft??"0",10);for(let e=s-1;e>=0;e--)if(Number.parseInt(a[e].style.paddingLeft??"0",10)<r){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:()=>I(e),onMouseLeave:B,className:(0,V.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",w?"bg-accent-soft text-foreground font-medium":"hover:bg-muted",k&&"ring-2 ring-primary bg-primary-soft",e.name.startsWith(".")&&"opacity-40"),style:{paddingLeft:`${14*a+8}px`,...sm},onClick:()=>{"dir"===e.type?n.toggleFolder(e):("app"===e.type||"node-app"===e.type?(n.openViewer(e),n.toggleFolder(e)):n.openViewer(e),s&&n.setSidebarCollapsed(!0))},children:["dir"===e.type||"app"===e.type||"node-app"===e.type?e.loading?(0,t.jsx)(N.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)(h,{className:(0,V.cn)("h-4 w-4 shrink-0",!w&&"text-warning")}):(0,t.jsx)(p.Folder,{className:(0,V.cn)("h-4 w-4 shrink-0",!w&&"text-warning")}):"app"===e.type?(0,t.jsx)(g.Globe,{className:(0,V.cn)("h-4 w-4 shrink-0",!w&&"text-foreground/70")}):"node-app"===e.type?(0,t.jsx)(F,{className:(0,V.cn)("h-4 w-4 shrink-0",!w&&"text-emerald-500")}):"html"===sa(e.name,"file")?(0,t.jsx)(g.Globe,{className:(0,V.cn)("h-4 w-4 shrink-0",!w&&"text-foreground/60")}):si(e.name)?(0,t.jsx)(y.default,{className:(0,V.cn)("h-4 w-4 shrink-0",!w&&"text-sunshine-700")}):ss(e.name)?(0,t.jsx)(m.FileText,{className:(0,V.cn)("h-4 w-4 shrink-0",!w&&"text-foreground/70")}):(0,t.jsx)(d.File,{className:(0,V.cn)("h-4 w-4 shrink-0",!w&&"text-foreground/60")})}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children: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",{type:"button",className:"flex items-center gap-0.5 hover:text-foreground",title:"Switch branch",onClick:t=>{if(t.stopPropagation(),S){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)(f,{className:"h-2.5 w-2.5"}),e.git.branch,e.git.dirty&&(0,t.jsx)("span",{className:"ml-0.5 text-warning",children:"*"})]}),E?(0,t.jsx)(N.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)(O,{className:"h-2.5 w-2.5"})}),S&&M&&"u">typeof document&&(0,$.createPortal)((0,t.jsx)("div",{style:{position:"fixed",top:M.top,left:M.left},className:"z-[9999] min-w-[120px] rounded-md border bg-popover p-1 shadow-md",onKeyDown:e=>{"Escape"===e.key&&(n.setBranchDropdownNode(null),n.setBranchDropdownPos(null))},onClick:e=>e.stopPropagation(),children:D?(0,t.jsx)("div",{className:"flex justify-center py-2",children:(0,t.jsx)(N.Loader2,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"})}):0===A.length?(0,t.jsx)("p",{className:"px-2 py-1 text-[10px] text-muted-foreground",children:"No branches"}):A.map(a=>{let s=e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")):"";return(0,t.jsxs)("button",{type:"button",disabled:null!==T||a.current,className:(0,V.cn)("flex w-full items-center gap-1.5 rounded px-2 py-1 text-left text-[11px] hover:bg-muted",a.current&&"font-semibold text-foreground",!a.current&&"text-muted-foreground"),onClick:t=>{t.stopPropagation(),a.current||n.handleCheckout(e.path,a.name,s)},children:[a.current?(0,t.jsx)(r.Check,{className:"h-3 w-3 shrink-0"}):(0,t.jsx)("span",{className:"w-3 shrink-0"}),T===a.name?(0,t.jsx)(N.Loader2,{className:"h-3 w-3 animate-spin"}):a.name]},a.name)})}),document.body)]}),C&&(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)(tE.DropdownMenu,{children:[(0,t.jsx)(tE.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsx)(U.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)(j,{className:"h-3.5 w-3.5"})})}),(0,t.jsxs)(tE.DropdownMenuContent,{align:"end",className:"w-48",children:[(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>n.copyPath(e.path),children:[(0,t.jsx)(o.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),sr(e.name)&&(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>n.copyWikiLink(e.name),children:[(0,t.jsx)(m.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>n.copyUrl(e.path),children:[(0,t.jsx)(v.Link,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),"file"===e.type&&ss(e.name)&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>n.copyRawContent(e.path),children:[(0,t.jsx)(m.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>n.copyFormattedContent(e.path,e.name),children:[(0,t.jsx)(m.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),(0,t.jsx)(tE.DropdownMenuSeparator,{}),"dir"===e.type&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(tE.DropdownMenuItem,{onClick:async()=>{e.expanded||n.toggleFolder(e),n.setNewFileParent(e.path),n.setNewFileName(""),n.setFileCreateError(null)},children:[(0,t.jsx)(u.FilePlus,{className:"mr-2 h-3.5 w-3.5"}),"New file here"]}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>n.triggerUpload(e.path),children:[(0,t.jsx)(P.Upload,{className:"mr-2 h-3.5 w-3.5"}),"Upload here"]}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>{n.setNewFolderParent(e.path),n.setNewFolderName(""),n.setFolderError(null)},children:[(0,t.jsx)(x,{className:"mr-2 h-3.5 w-3.5"}),"New subfolder"]}),(0,t.jsx)(tE.DropdownMenuSeparator,{})]}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>n.handleDownload(e),children:[(0,t.jsx)(c,{className:"mr-2 h-3.5 w-3.5"}),"file"===e.type?"Download":"Download as zip"]}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>n.togglePin(e,i),children:[(0,t.jsx)(R,{className:(0,V.cn)("mr-2 h-3.5 w-3.5",_&&"fill-current text-amber-400")}),_?"Unpin":"Pin to top"]}),(0,t.jsx)(tE.DropdownMenuSeparator,{}),(0,t.jsxs)(tE.DropdownMenuItem,{className:"text-destructive focus:text-destructive",onClick:()=>{n.setDeletingPath(e.path),n.setDeletingIsDir("file"!==e.type)},children:[(0,t.jsx)(L.Trash2,{className:"mr-2 h-3.5 w-3.5"}),"Delete"]})]})]})})]})}),(0,t.jsxs)(aL,{children:[(0,t.jsx)(aP,{onSelect:()=>n.copyPath(e.path),children:"Copy path"}),sr(e.name)&&(0,t.jsx)(aP,{onSelect:()=>n.copyWikiLink(e.name),children:"Copy wiki link"}),(0,t.jsx)(aB,{}),(0,t.jsx)(aP,{onSelect:()=>n.copyUrl(e.path),children:"Copy URL"}),"file"===e.type&&ss(e.name)&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(aB,{}),(0,t.jsx)(aP,{onSelect:()=>n.copyRawContent(e.path),children:"Copy raw content"}),(0,t.jsx)(aP,{onSelect:()=>n.copyFormattedContent(e.path,e.name),children:"Copy formatted content"})]})]})]})}),sh=(0,z.memo)(function(e){let{ctx:a,openPath:n,dragOverPath:s,branchDropdownNode:i,branchDropdownPos:l,nodeBranches:o,branchesLoading:c,checkingOutBranch:d,pullingRepo:u,activePaths:h,pins:x,isMobile:f,activeWorkspaceId:g,newFileParent:b,newFileName:w,fileCreateError:y,newFolderParent:v,newFolderName:N,folderError:k,sidebarScrollRef:j}=e,_=n6(e=>e.showHidden),C=(0,z.useRef)(null),E=(0,z.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,z.useCallback)(()=>{C.current&&(clearTimeout(C.current),C.current=null)},[]),M=(0,z.useMemo)(()=>{let t=[],a=(e,n)=>{for(let s of e)!(!_&&s.name.startsWith("."))&&(t.push({kind:"row",node:s,depth:n}),"dir"===s.type&&(v===s.path&&t.push({kind:"newfolder",node:s,depth:n}),b===s.path&&t.push({kind:"newfile",node:s,depth:n})),("dir"===s.type||"app"===s.type||"node-app"===s.type)&&s.expanded&&(s.children&&s.children.length>0?a(s.children,n+1):s.children?.length===0&&t.push({kind:"empty",node:s,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)(sp,{node:b,depth:v,ctx:a,isMobile:f,activeWorkspaceId:g,sidebarScrollRef:j,isActive:n===b.path,isDragOver:s===b.path,isPinned:x.some(e=>e.path===b.path),isAgentActive:h.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`,...sm},children:[(0,t.jsx)("span",{className:"w-3.5 shrink-0"}),(0,t.jsx)(p.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(""))}}),k&&(0,t.jsx)("span",{className:"text-xs text-destructive",children:k}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:a.handleCreateFolder,children:(0,t.jsx)(r.Check,{className:"h-3 w-3"})}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{a.setNewFolderParent(null),a.setNewFolderName("")},children:(0,t.jsx)(B.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`,...sm},children:[(0,t.jsx)("span",{className:"w-3.5 shrink-0"}),(0,t.jsx)(m.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)(U.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:a.handleCreateFile,children:(0,t.jsx)(r.Check,{className:"h-3 w-3"})}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{a.setNewFileParent(null),a.setNewFileName("")},children:(0,t.jsx)(B.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`,...sm},children:"Empty"},`empty-${b.path}`)})})});e.s(["default",0,function(){let e;(0,n7.useWikiSlugsStore)(e=>e.loadedAt),(0,z.useEffect)(()=>{n7.useWikiSlugsStore.getState().load()},[]);let[n,c]=(0,z.useState)(null),[h,j]=(0,z.useState)(null),[F,$]=(0,z.useState)(()=>(0,G.getActiveWorkspaceId)()),[q,H]=(0,z.useState)([]),[W,Z]=(0,z.useState)(!1),[X,J]=(0,z.useState)(!1),[et,ea]=(0,z.useState)(null),[ei,el]=(0,z.useState)(null),eo=(0,z.useCallback)(async()=>{try{let e=await fetch("/api/system/workspaces");if(!e.ok)throw Error("Failed");let t=await e.json();if(H(t.workspaces),Z(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($(n.id),j(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,z.useEffect)(()=>{eo()},[eo]);let ed=(0,a2.useEditorStore)(e=>e.currentPath),eu=aU(e=>e.recents),[em,ep]=(0,z.useState)(!1),[eh,ex]=(0,z.useState)(!0),ef=aH(e=>e.pins),eg=(0,z.useRef)(null),eb=(0,aG.useAIPanelStore)(e=>e.activity),ew=(0,z.useMemo)(()=>{let e=new Date(Date.now()-6e4).toISOString(),t=new Set;for(let a of eb)a.at>=e&&a.path&&a.by?.startsWith("ai:")&&t.add(a.path);return t},[eb]);(0,z.useEffect)(()=>{let e=()=>{aG.useAIPanelStore.getState().loadActivity()};e();let t=setInterval(e,1e4);return()=>clearInterval(t)},[]),(0,z.useEffect)(()=>{aU.getState().loadForWorkspace(F),aH.getState().loadForWorkspace(F)},[F]),(0,z.useEffect)(()=>{let e=[...ef.map(e=>e.path),...eu.slice(0,8).map(e=>e.path)].filter((e,t,a)=>sr(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,a2.prefetchPage)(t)});return()=>{"cancelIdleCallback"in window?window.cancelIdleCallback(t):clearTimeout(t)}},[ef,eu]);let ey=(0,z.useRef)(new URLSearchParams(window.location.search).get("path")),ev=(0,z.useRef)(!1),[eN,ek]=(0,z.useState)([]),[ej,e_]=(0,z.useState)(!1),[eC,eE]=(0,z.useState)(!1),eS=(0,z.useRef)(!1),[eM,eA]=(0,z.useState)(!1),[eD,eO]=(0,z.useState)(!1),[eT,eI]=(0,z.useState)(null),eR=(0,z.useRef)(null),eF=(0,z.useRef)(""),[eL,eP]=(0,z.useState)(null),[eB,ez]=(0,z.useState)(""),[e$,eU]=(0,z.useState)(null),[eq,eK]=(0,z.useState)(null),[eH,eW]=(0,z.useState)(""),[eG,eV]=(0,z.useState)(null),[eZ,eX]=(0,z.useState)(null),[eJ,eQ]=(0,z.useState)(!1),[eY,e0]=(0,z.useState)(null),[e1,e2]=(0,z.useState)(null),[e5,e3]=(0,z.useState)(!1),[e4,e7]=(0,z.useState)(0),e9=function(e="(max-width: 767px)"){let[t,a]=(0,z.useState)(!1);return(0,z.useEffect)(()=>{let t=window.matchMedia(e),n=()=>a(t.matches);return n(),t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[e]),t}(),[e6,e8]=(0,z.useState)(!1),te=n3(e=>e.width),tt=n6(e=>e.showHidden),ta=n3(e=>e.setWidth);(0,z.useEffect)(()=>{e9&&e8(!0)},[e9]);let[ts,tr]=(0,z.useState)(!1),[ti,tl]=(0,z.useState)(!1),[to,tc]=(0,z.useState)(!1),[td,tu]=(0,z.useState)(null),[tp,tb]=(0,z.useState)(0),[tw,ty]=(0,z.useState)(!1),[tv,tk]=(0,z.useState)(!1),[t_,tC]=(0,z.useState)(""),[tS,tA]=(0,z.useState)(!1),[tD,tO]=(0,z.useState)(null),tT=(0,z.useRef)(null),[tI,tL]=(0,z.useState)(null),tP=(0,z.useRef)(null),tB=(0,z.useRef)(!1),tz=(0,z.useRef)(async()=>{});(0,z.useEffect)(()=>{ej||eS.current||(eS.current=!0,eE(!0),sl("").then(e=>{ek(e),e_(!0),eE(!1)}).catch(()=>{eS.current=!1,eE(!1)}))},[ej]);let t$=(0,z.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 sl(n)});ek(e=>{let t=e;for(let{prefix:e,children:n}of a)t=su(t,e,e=>({...e,children:n,expanded:!0}));return t})},[]),tU=(0,z.useCallback)(async e=>{let t=await sl(e);""===e?ek(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})}):ek(a=>su(a,e,e=>({...e,children:t,expanded:!0})))},[]),[tq,tH]=(0,z.useState)(null),[tW,tG]=(0,z.useState)(null),[tV,tZ]=(0,z.useState)(!1),[tX,tJ]=(0,z.useState)([]),[tQ,t0]=(0,z.useState)(!1),[t1,t2]=(0,z.useState)(null),[t5,t3]=(0,z.useState)(null),[t4,t7]=(0,z.useState)(!1),[t9,t6]=(0,z.useState)({}),[t8,ae]=(0,z.useState)({}),[at,aa]=(0,z.useState)(null),[an,as]=(0,z.useState)(null),[ar,ai]=(0,z.useState)(null),al=(0,z.useCallback)(async(e,t)=>{if(!tq){tH(e);try{let a=await (0,G.wsFetch)("/api/wiki/git-pull",{method:"POST",body:JSON.stringify({path:e})});if(!a.ok){let e=await a.json();(0,tK.showError)(e.message??e.error??"Pull failed");return}let n=await a.json();(0,tK.showSuccess)(`Pulled ${e} (${n.branch} @ ${n.sha.slice(0,7)})`),await tU(t)}catch{(0,tK.showError)("Pull failed")}finally{tH(null)}}},[tq,tU]);(0,z.useEffect)(()=>{tZ(!1),tJ([]),t2(null),t3(null)},[eY?.path]);let ao=eY?.path;(0,z.useEffect)(()=>{if(!ao)return void tG(null);let e=!1,t=setTimeout(()=>{(async()=>{try{let t=await (0,G.wsFetch)(`/api/wiki/git-file-info?path=${encodeURIComponent(ao)}`);if(e)return;if(!t.ok)return void tG(null);let a=await t.json();e||tG(a.info)}catch{e||tG(null)}})()},200);return()=>{e=!0,clearTimeout(t)}},[ao]);let ac=(0,z.useCallback)(async()=>{if(!eY)return;let e=eY.path;tZ(!0),t0(!0),tJ([]),t2(null),t3(null);try{let t=await (0,G.wsFetch)(`/api/wiki/git-history?path=${encodeURIComponent(e)}`);if(!t.ok)return void(0,tK.showError)("Could not load history");let a=await t.json();eY.path===e&&tJ(a.commits)}catch{(0,tK.showError)("Could not load history")}finally{t0(!1)}},[eY]),ad=(0,z.useCallback)(async e=>{if(!eY)return;if(t1===e){t2(null),t3(null);return}let t=eY.path;t2(e),t7(!0),t3(null);try{let a=await (0,G.wsFetch)(`/api/wiki/git-diff?path=${encodeURIComponent(t)}&sha=${encodeURIComponent(e)}`);if(!a.ok)return void(0,tK.showError)("Could not load diff");let n=await a.json();eY.path===t&&t1===e&&t3(n.diff)}catch{(0,tK.showError)("Could not load diff")}finally{t7(!1)}},[eY,t1]),ap=(0,z.useCallback)(async e=>{if(t9[e]||t8[e])return;let t=!1;ae(t=>({...t,[e]:!0}));try{let a=await (0,G.wsFetch)(`/api/wiki/git-branches?path=${encodeURIComponent(e)}`);if(t)return;if(!a.ok)return void(0,tK.showError)("Could not load branches");let n=await a.json();t||t6(t=>({...t,[e]:n.branches}))}catch{t||(0,tK.showError)("Could not load branches")}finally{t||ae(t=>({...t,[e]:!1}))}return()=>{t=!0}},[t9,t8]),ah=(0,z.useCallback)(async(e,t,a)=>{if(!at){aa(t);try{let n=await (0,G.wsFetch)("/api/wiki/git-checkout",{method:"POST",body:JSON.stringify({path:e,branch:t})});if(409===n.status)return void(0,tK.showError)("Repository has uncommitted changes");if(!n.ok){let e=await n.json();(0,tK.showError)(e.error??"Checkout failed");return}let s=await n.json();(0,tK.showSuccess)(`Switched to ${s.branch}`),t6(t=>{let a={...t};return delete a[e],a}),as(null),ai(null),await tU(a)}catch{(0,tK.showError)("Checkout failed")}finally{aa(null)}}},[at,tU]);(0,z.useEffect)(()=>{if(!an)return;let e=()=>{as(null),ai(null)},t=e=>{"Escape"===e.key&&(as(null),ai(null))};return document.addEventListener("click",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("click",e),document.removeEventListener("keydown",t)}},[an]);let ax=(0,z.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(...ax(a.children)));return t},[]),af=(0,z.useCallback)(async()=>{eA(!0);try{let e=ax(eN),t=await sl("");for(let a of(ek(t),e)){let e=await sl(a);ek(t=>su(t,a,t=>({...t,children:e,expanded:!0})))}}finally{eA(!1)}},[eN,ax]),ag=(0,z.useCallback)(async()=>{if(eY){if(sr(eY.name)){ty(!0);try{await a2.useEditorStore.getState().loadPage(eY.path)}finally{ty(!1)}return}if(["editor","text"].includes(sa(eY.name,eY.nodeType))||ss(eY.name)){ty(!0);try{let e=await (0,G.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(eY.path)}`);if(e.ok){let t=await e.json();tu(t.content),tb(Number(e.headers.get("X-Wiki-Revision")??0))}}catch{}ty(!1)}}},[eY]);async function ab(e){if("dir"===e.type||"app"===e.type||"node-app"===e.type)if(e.expanded)ek(t=>su(t,e.path,e=>({...e,expanded:!1})));else if(void 0===e.children){let t=await sd(e.path);if(t)return void ek(a=>su(a,e.path,e=>({...e,loading:!1,children:t,expanded:!0})));ek(t=>su(t,e.path,e=>({...e,loading:!0})));let a=await sl(e.path);ek(t=>su(t,e.path,e=>({...e,loading:!1,children:a,expanded:!0})))}else ek(t=>su(t,e.path,e=>({...e,expanded:!0})))}async function aw(e){if("file"===e.type&&aU.getState().push({path:e.path,name:e.name},F),e0({path:e.path,name:e.name,size:e.size,nodeType:"app"===e.type?"app":"node-app"===e.type?"node-app":"file"}),tk(!1),tO(null),tu(null),tb(0),"file"===e.type&&sr(e.name)){ty(!0);try{await a2.useEditorStore.getState().loadPage(e.path)}finally{ty(!1)}return}if(["editor","text"].includes(sa(e.name,e.type))||ss(e.name)){ty(!0);try{let t=await (0,G.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(e.path)}`);if(t.ok){let e=await t.json();tu(e.content),tb(Number(t.headers.get("X-Wiki-Revision")??0))}}catch{}ty(!1)}}(0,z.useEffect)(()=>{eY&&sr(eY.name)&&a2.useEditorStore.getState().currentPath!==eY.path&&a2.useEditorStore.getState().loadPage(eY.path)},[eY]),(0,z.useEffect)(()=>{tP.current=eY},[eY]),(0,z.useEffect)(()=>{tB.current=tv},[tv]),(0,z.useEffect)(()=>{tz.current=ag},[ag]),(0,z.useEffect)(()=>{if(!n)return;let e=new Map,t=new EventSource((0,G.withWs)("/api/wiki/watch"));return t.onmessage=t=>{var a;let n;try{n=JSON.parse(t.data)}catch{return}let{type:s,path:r}=n,i=r.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),tU(a)},300)),"change"===s&&tP.current?.path===r&&!tB.current){let t=`__file__${r}`;e.has(t)&&clearTimeout(e.get(t)),e.set(t,setTimeout(()=>{e.delete(t),tz.current()},400))}},()=>{for(let a of(t.close(),e.values()))clearTimeout(a)}},[n,tU]),(0,z.useEffect)(()=>{e3(!1)},[]);let ay=(0,z.useCallback)(e=>{let t=e.split("/").pop()??e;t$(e),aw({path:e,name:t,type:"file"})},[t$]);(0,z.useEffect)(()=>{if(!ed||eY&&eY.path===ed)return;let e=ed.split("/").pop()??ed;aw({path:ed,name:e,type:"file"})},[ed]);let av=(0,z.useCallback)(async e=>{if(!e)return void e0(null);let t=e.split("/"),a=t[t.length-1],n=t.slice(0,-1).join("/"),s=(await sl(n)).find(t=>t.path===e);s&&(await t$(e),aw({path:e,name:a,type:s.type,modifiedAt:s.modifiedAt}))},[t$]);(0,z.useEffect)(()=>{let e=new URL(window.location.href);eY?e.searchParams.set("path",eY.path):e.searchParams.delete("path");let t=e.toString();t!==window.location.href&&window.history.pushState(null,"",t)},[eY]),(0,z.useEffect)(()=>{let e=()=>{av(new URLSearchParams(window.location.search).get("path"))};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[av]),(0,z.useEffect)(()=>{ev.current||ej&&(ev.current=!0,av(ey.current))},[ej,av]);let aN=(0,z.useCallback)(async e=>{if(e===F)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()),e0(null),tu(null),tk(!1),ek([]),e_(!1),eS.current=!1,n7.useWikiSlugsStore.getState().invalidate();let a=q.find(t=>t.id===e);a&&j(a.rootDir),$(e)},[F,q]),ak=(0,z.useCallback)(async()=>{if(et)try{if(!(await fetch(`/api/system/workspaces/${et}`,{method:"DELETE"})).ok)throw Error("Failed");if(et===F){let e=q.filter(e=>e.id!==et);if(e.length>0){let t=[...e].sort((e,t)=>(t.lastOpenedAt??t.createdAt).localeCompare(e.lastOpenedAt??e.createdAt))[0];await aN(t.id)}else c(!1)}await eo()}catch{}finally{ea(null)}},[et,F,q,aN,eo]),aj=(0,z.useCallback)(async e=>{if(!ei){el(e);try{let t=await fetch(`/api/system/workspaces/${e}/refresh`,{method:"POST"});if(!t.ok){let e=await t.json();(0,tK.showError)(e.error??"Refresh failed")}await eo()}catch{(0,tK.showError)("Refresh failed")}finally{el(null)}}},[ei,eo]);async function a_(){if(!eY)return;tA(!0),tO(null);let e=await (0,G.wsFetch)("/api/wiki/content",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:eY.path,content:t_,baseRevision:tp})});if(e.ok){let t=await e.json();"number"==typeof t.revision&&tb(t.revision),tu(t_),tk(!1)}else tO((await e.json()).error??"Save failed");tA(!1)}let aC=(0,z.useCallback)(async(e,t)=>{let a=Array.from(e);if(a.length){eO(!0),eI(null);try{for(let e of a){let a=new FormData;a.append("file",e),a.append("dir",t);let n=await (0,G.wsFetch)("/api/wiki/upload",{method:"POST",body:a});if(!n.ok){let e=await n.json();eI(e.error??"Upload failed"),(0,tK.showError)(e.error??"Upload failed");break}}await tU(t)}catch{eI("Upload failed.")}finally{eO(!1),eR.current&&(eR.current.value="")}}},[tU]);function aE(e){eF.current=e,eR.current?.click()}async function aS(){let e=eB.trim();if(!e||null===eL)return;eU(null);let t=eL?`${eL}/${e}`:e,a=await (0,G.wsFetch)("/api/wiki/folder",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});a.ok?(eP(null),ez(""),await tU(eL),""!==eL&&ek(e=>su(e,eL,e=>({...e,expanded:!0})))):eU((await a.json()).error??"Failed")}async function aM(){let e=eH.trim();if(!e||null===eq)return;eV(null);let t=e.includes(".")?e:`${e}.md`,a=eq?`${eq}/${t}`:t,n=await (0,G.wsFetch)("/api/wiki/new-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a})});n.ok?(eK(null),eW(""),await tU(eq),""!==eq&&ek(e=>su(e,eq,e=>({...e,expanded:!0}))),aw({path:a,name:t,type:"file",modifiedAt:new Date().toISOString()})):eV((await n.json()).error??"Failed")}function aA(e){navigator.clipboard.writeText(e),(0,tK.showSuccess)("Path copied")}function aD(e){let t=e.replace(/\.(md|markdown)$/i,"");navigator.clipboard.writeText(`[[${t}]]`),(0,tK.showSuccess)("Wiki link copied")}function aO(e){let t=new URL(location.href);t.searchParams.set("path",e),F&&t.searchParams.set("ws",F),navigator.clipboard.writeText(t.toString()),(0,tK.showSuccess)("URL copied")}async function aT(e){if(eY?.path===e&&null!==td)return td;if(a2.useEditorStore.getState().currentPath===e)return a2.useEditorStore.getState().content;let t=await (0,G.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(e)}`);if(!t.ok)throw Error("Cannot copy content");return(await t.json()).content}async function aI(e){try{let t=await aT(e);await navigator.clipboard.writeText(t),(0,tK.showSuccess)("Raw content copied")}catch{(0,tK.showError)("Could not copy file content")}}async function aR(e,t){try{let a=await aT(e);if(!sr(t)){await navigator.clipboard.writeText(a),(0,tK.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,tK.showSuccess)("Formatted content copied")}catch{(0,tK.showError)("Could not copy formatted content")}}function aF(e){return(0,t.jsxs)(tE.DropdownMenu,{children:[(0,t.jsx)(tE.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsxs)(U.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1.5 px-2 text-xs",title:"Copy path, wiki link, or URL",children:[(0,t.jsx)(o.Copy,{className:"h-3.5 w-3.5"}),"Copy",(0,t.jsx)(i.ChevronDown,{className:"h-3 w-3 opacity-60"})]})}),(0,t.jsxs)(tE.DropdownMenuContent,{align:"end",className:"w-44",children:[(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>aA(e.path),children:[(0,t.jsx)(o.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),sr(e.name)&&(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>aD(e.name),children:[(0,t.jsx)(m.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,t.jsx)(tE.DropdownMenuSeparator,{}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>aO(e.path),children:[(0,t.jsx)(v.Link,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),ss(e.name)&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tE.DropdownMenuSeparator,{}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>void aI(e.path),children:[(0,t.jsx)(m.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>void aR(e.path,e.name),children:[(0,t.jsx)(m.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]})]})]})}async function aL(){eZ&&(await (0,G.wsFetch)("/api/wiki",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:eZ})}),(eY?.path===eZ||eY?.path.startsWith(`${eZ}/`))&&(e0(null),tu(null)),ek(e=>(function e(t,a){return t.filter(e=>e.path!==a).map(t=>t.children?{...t,children:e(t.children,a)}:t)})(e,eZ)),eX(null))}function aP(e,t,a){e.preventDefault(),e.stopPropagation();let n=tT.current;!n||n.path===t||t.startsWith(`${n.path}/`)||(e.dataTransfer.dropEffect="move",tL("root"===a?"":t))}async function aB(e,t){e.preventDefault(),e.stopPropagation(),tL(null);let a=tT.current;if(tT.current=null,!a||a.path===t||t.startsWith(`${a.path}/`))return;let n=t?`${t}/${a.name}`:a.name;if(n!==a.path&&(await (0,G.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 tU(e),t!==e&&await tU(t),eY?.path===a.path&&e0({path:n,name:a.name,nodeType:eY.nodeType,size:eY.size})}}let az=eY?sa(eY.name,eY.nodeType):null,a$=!!eY&&null!==az&&!se.has(az)&&(eY.size??0)>5242880&&e1!==eY.path,aq=(0,nQ.useViewWidthStore)(e=>e.width),aK=(0,nQ.useViewWidthStore)(e=>e.align),aW=null===az||"editor"===az||"text"===az||"source"===az||"notebook"===az||"fallback"===az,aV=aW?nQ.VIEW_WIDTH_CLASS[aq]:"",aZ=aW?nQ.VIEW_ALIGN_CLASS[aK]:"",aX=(0,z.useRef)(null);aX.current={toggleFolder:e=>void ab(e),openViewer:e=>void aw(e),copyPath:aA,copyWikiLink:aD,copyUrl:aO,copyRawContent:e=>void aI(e),copyFormattedContent:(e,t)=>void aR(e,t),handleDownload:function(e){let t=(0,G.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:aE,handleCreateFile:()=>void aM(),handleCreateFolder:()=>void aS(),handleDragStart:function(e,t){tT.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t.path)},handleDragOver:aP,handleDropOnFolder:(e,t)=>void aB(e,t),handleGitPull:(e,t)=>void al(e,t),handleCheckout:(e,t,a)=>void ah(e,t,a),loadBranches:e=>void ap(e),prefetch:e=>{"file"===e.type?sr(e.name)&&(0,a2.prefetchPage)(e.path):function(e){if(so.has(e)||sc.has(e))return;let t=sl(e).then(t=>(so.set(e,t),t)).finally(()=>sc.delete(e));sc.set(e,t),t.catch(()=>{})}(e.path)},togglePin:(e,t)=>aH.getState().toggle({path:e.path,name:e.name,type:"dir"===e.type?"file":e.type},t),setDragOverPath:tL,setSidebarCollapsed:e8,setBranchDropdownNode:as,setBranchDropdownPos:ai,setNewFileParent:eK,setNewFileName:eW,setFileCreateError:eV,setNewFolderParent:eP,setNewFolderName:ez,setFolderError:eU,setDeletingPath:eX,setDeletingIsDir:eQ};let aJ=(0,z.useMemo)(()=>({toggleFolder:e=>aX.current.toggleFolder(e),openViewer:e=>aX.current.openViewer(e),copyPath:e=>aX.current.copyPath(e),copyWikiLink:e=>aX.current.copyWikiLink(e),copyUrl:e=>aX.current.copyUrl(e),copyRawContent:e=>aX.current.copyRawContent(e),copyFormattedContent:(e,t)=>aX.current.copyFormattedContent(e,t),handleDownload:e=>aX.current.handleDownload(e),triggerUpload:e=>aX.current.triggerUpload(e),handleCreateFile:()=>aX.current.handleCreateFile(),handleCreateFolder:()=>aX.current.handleCreateFolder(),handleDragStart:(e,t)=>aX.current.handleDragStart(e,t),handleDragOver:(e,t,a)=>aX.current.handleDragOver(e,t,a),handleDropOnFolder:(e,t)=>aX.current.handleDropOnFolder(e,t),handleGitPull:(e,t)=>aX.current.handleGitPull(e,t),handleCheckout:(e,t,a)=>aX.current.handleCheckout(e,t,a),loadBranches:e=>aX.current.loadBranches(e),prefetch:e=>aX.current.prefetch(e),togglePin:(e,t)=>aX.current.togglePin(e,t),setDragOverPath:e=>aX.current.setDragOverPath(e),setSidebarCollapsed:e=>aX.current.setSidebarCollapsed(e),setBranchDropdownNode:e=>aX.current.setBranchDropdownNode(e),setBranchDropdownPos:e=>aX.current.setBranchDropdownPos(e),setNewFileParent:e=>aX.current.setNewFileParent(e),setNewFileName:e=>aX.current.setNewFileName(e),setFileCreateError:e=>aX.current.setFileCreateError(e),setNewFolderParent:e=>aX.current.setNewFolderParent(e),setNewFolderName:e=>aX.current.setNewFolderName(e),setFolderError:e=>aX.current.setFolderError(e),setDeletingPath:e=>aX.current.setDeletingPath(e),setDeletingIsDir:e=>aX.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)(N.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),!1===n&&(0,t.jsx)(tR,{onSelect:e=>{let t=new URL(location.href);t.searchParams.set("ws",e),t.searchParams.delete("path"),history.replaceState(null,"",t.toString()),e_(!1),eS.current=!1,$(e),c(!0),eo()}}),!0===n&&X&&(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)(U.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1.5 text-xs",onClick:()=>J(!1),children:[(0,t.jsx)(B.X,{className:"h-3.5 w-3.5"})," Cancel"]})}),(0,t.jsx)(tR,{onSelect:e=>{J(!1),eo(),aN(e)}})]}),!0===n&&!X&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n0,{onOpenFile:ay,onToggleSidebar:()=>e8(e=>{let t=!e;return e9&&!1===t&&aG.useAIPanelStore.getState().close(),t}),onNewFile:()=>eK(""),onCopyPath:()=>{eY&&navigator.clipboard.writeText(eY.path)}}),!e6&&e9&&(0,t.jsx)("div",{className:"fixed inset-0 z-40 bg-overlay backdrop-blur-[1px] md:hidden",onClick:()=>e8(!0),"aria-hidden":!0}),!e6&&(0,t.jsxs)(am.Card,{style:e9?void 0:{width:te},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)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 shrink-0",title:"Collapse sidebar",onClick:()=>e8(!0),children:(0,t.jsx)(_,{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)(tE.DropdownMenu,{children:[(0,t.jsx)(tE.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsxs)(U.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1 px-2 text-xs",disabled:eD,children:[eD?(0,t.jsx)(N.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(D,{className:"h-3.5 w-3.5"}),"New",(0,t.jsx)(i.ChevronDown,{className:"h-3 w-3 opacity-60"})]})}),(0,t.jsxs)(tE.DropdownMenuContent,{align:"start",className:"w-44",children:[(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>{eK(""),eW(""),eV(null)},children:[(0,t.jsx)(u.FilePlus,{className:"mr-2 h-3.5 w-3.5"}),"New file"]}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>{eP(""),ez(""),eU(null)},children:[(0,t.jsx)(x,{className:"mr-2 h-3.5 w-3.5"}),"New folder"]}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>aE(""),disabled:eD,children:[(0,t.jsx)(P.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)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Refresh tree",onClick:af,disabled:eM,children:eM?(0,t.jsx)(N.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(O,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:tt?"Hide hidden files":"Show hidden files",onClick:()=>n6.getState().toggle(),children:tt?(0,t.jsx)(S.Eye,{className:"h-3.5 w-3.5"}):(0,t.jsx)(M,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(tF.ThemeToggle,{}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"AI Agent panel",onClick:()=>{aG.useAIPanelStore.getState().toggle(),e9&&e8(!0)},children:(0,t.jsx)(s,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Settings",onClick:()=>tl(!0),children:(0,t.jsx)(T,{className:"h-3.5 w-3.5"})})]})]}),eT&&(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"}),eT]}),""===eL&&(0,t.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,t.jsx)(p.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:eB,onChange:e=>ez(e.target.value),onKeyDown:e=>{"Enter"===e.key&&aS(),"Escape"===e.key&&(eP(null),ez(""))}}),e$&&(0,t.jsx)("span",{className:"text-xs text-destructive",children:e$}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:aS,children:(0,t.jsx)(r.Check,{className:"h-3 w-3"})}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{eP(null),ez("")},children:(0,t.jsx)(B.X,{className:"h-3 w-3"})})]}),""===eq&&(0,t.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,t.jsx)(m.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:eH,onChange:e=>eW(e.target.value),onKeyDown:e=>{"Enter"===e.key&&aM(),"Escape"===e.key&&(eK(null),eW(""))}}),eG&&(0,t.jsx)("span",{className:"text-xs text-destructive",children:eG}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:aM,children:(0,t.jsx)(r.Check,{className:"h-3 w-3"})}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{eK(null),eW("")},children:(0,t.jsx)(B.X,{className:"h-3 w-3"})})]}),(0,t.jsx)("div",{className:"border-b",children:(0,t.jsx)(n1,{onOpenFile:ay})}),(0,t.jsxs)("div",{ref:eg,className:(0,V.cn)("flex-1 overflow-auto py-1 editorial-file-tree",""===tI&&"ring-2 ring-inset ring-primary bg-primary/5"),onDragOver:e=>aP(e,"","root"),onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||tL(null)},onDrop:e=>aB(e,""),children:[ef.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:()=>ep(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)(A,{className:"h-3 w-3"}),"Pinned",(0,t.jsx)("span",{className:"ml-auto text-[9px] tabular-nums opacity-60",children:ef.length})]}),!em&&ef.map(e=>(0,t.jsxs)("div",{role:"button",tabIndex:0,className:(0,V.cn)("group flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer transition-colors select-none",eY?.path===e.path?"bg-accent-soft text-foreground font-medium":"hover:bg-muted"),onClick:()=>{aw({path:e.path,name:e.name,type:e.type??"file",modifiedAt:""}),e9&&e8(!0)},onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),aw({path:e.path,name:e.name,type:e.type??"file",modifiedAt:""}))},children:[(0,t.jsx)(R,{className:"h-3 w-3 shrink-0 fill-current text-amber-400"}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate text-xs",children: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(),aH.getState().toggle({path:e.path,name:e.name},F)},children:(0,t.jsx)(B.X,{className:"h-3 w-3"})})]},e.path))]}),eu.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:()=>ex(e=>!e),children:[eh?(0,t.jsx)(l.ChevronRight,{className:"h-3 w-3"}):(0,t.jsx)(i.ChevronDown,{className:"h-3 w-3"}),"Recent",(0,t.jsx)("span",{className:"ml-auto text-[9px] tabular-nums opacity-60",children:eu.length})]}),!eh&&eu.slice(0,8).map(e=>(0,t.jsxs)("div",{role:"button",tabIndex:0,className:(0,V.cn)("flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer transition-colors select-none",eY?.path===e.path?"bg-accent-soft text-foreground font-medium":"hover:bg-muted"),onClick:()=>{aw({path:e.path,name:e.name,type:e.type??"file",modifiedAt:""}),e9&&e8(!0)},onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),aw({path:e.path,name:e.name,type:e.type??"file",modifiedAt:""}))},children:[(0,t.jsx)(m.FileText,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,t.jsx)("span",{className:"flex-1 truncate text-xs",children: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("/")})]},e.path))]}),eC?(0,t.jsx)("div",{className:"flex justify-center py-6",children:(0,t.jsx)(N.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):0===eN.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)(m.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)(U.Button,{size:"sm",variant:"outline",className:"w-full gap-1.5 max-w-[180px]",onClick:()=>aE(""),disabled:eD,children:[eD?(0,t.jsx)(N.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(P.Upload,{className:"h-3.5 w-3.5"}),"Upload Files"]})]}):(0,t.jsx)(sh,{ctx:aJ,nodes:eN,openPath:eY?.path??null,dragOverPath:tI,branchDropdownNode:an,branchDropdownPos:ar,nodeBranches:t9,branchesLoading:t8,checkingOutBranch:at,pullingRepo:tq,activePaths:ew,pins:ef,isMobile:e9,activeWorkspaceId:F,newFileParent:eq,newFileName:eH,fileCreateError:eG,newFolderParent:eL,newFolderName:eB,folderError:e$,sidebarScrollRef:eg})]}),(0,t.jsx)("div",{className:"border-t px-2 py-2 bg-muted shrink-0",children:(0,t.jsxs)(tE.DropdownMenu,{children:[(0,t.jsx)(tE.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsxs)(U.Button,{size:"sm",variant:"ghost",className:"w-full h-auto justify-between gap-2 px-2 py-1.5 text-left",title:h??"",children:[(0,t.jsxs)("span",{className:"flex flex-col min-w-0",children:[(0,t.jsx)("span",{className:"truncate text-xs font-medium",children:q.find(e=>e.id===F)?.name??"Workspace"}),(0,t.jsx)("span",{className:"truncate text-[10px] text-muted-foreground font-mono",children:h??""})]}),(0,t.jsx)(i.ChevronDown,{className:"h-3.5 w-3.5 shrink-0 opacity-60"})]})}),(0,t.jsxs)(tE.DropdownMenuContent,{align:"start",className:"w-60",children:[q.map(e=>(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>void aN(e.id),className:(0,V.cn)("gap-2",e.id===F&&"font-medium"),children:[e.id===F?(0,t.jsx)(r.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.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)(f,{className:"h-2.5 w-2.5"})," read-only"]})]}),(0,t.jsx)("span",{className:"truncate text-[10px] text-muted-foreground font-mono",children:e.rootDir}),e.git?.lastPulledAt&&n8(e.git.lastPulledAt)&&(0,t.jsxs)("span",{className:"text-[10px] text-muted-foreground/70",children:["synced ",n8(e.git.lastPulledAt)]})]}),W&&e.git&&(0,t.jsx)("button",{className:(0,V.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:ei===e.id,onClick:t=>{t.stopPropagation(),t.preventDefault(),aj(e.id)},children:(0,t.jsx)(O,{className:(0,V.cn)("h-3.5 w-3.5",ei===e.id&&"animate-spin")})}),W&&(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(),ea(e.id)},children:(0,t.jsx)(L.Trash2,{className:"h-3.5 w-3.5"})})]},e.id)),W&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tE.DropdownMenuSeparator,{}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>J(!0),children:[(0,t.jsx)(x,{className:"mr-2 h-3.5 w-3.5"}),"Add workspace…"]})]})]})]})}),(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;tr(!0);let a=document.body.style.cursor,n=document.body.style.userSelect;document.body.style.cursor="col-resize",document.body.style.userSelect="none";let s=e=>{ta(te+(e.clientX-t))},r=()=>{tr(!1),document.body.style.cursor=a,document.body.style.userSelect=n,window.removeEventListener("mousemove",s),window.removeEventListener("mouseup",r)};window.addEventListener("mousemove",s),window.addEventListener("mouseup",r)},onDoubleClick:()=>ta(288),onKeyDown:e=>{"ArrowLeft"===e.key?(e.preventDefault(),ta(te-16)):"ArrowRight"===e.key&&(e.preventDefault(),ta(te+16))},tabIndex:0,"aria-valuemin":200,"aria-valuemax":600,"aria-valuenow":te,className:(0,V.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",ts&&"bg-primary/60")})]}),(0,t.jsxs)("div",{className:"flex-1 flex flex-col min-w-0 relative",children:[e6&&(0,t.jsx)(U.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:()=>e8(!1),children:(0,t.jsx)(C,{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)(U.Button,{size:"sm",variant:"ghost",className:"h-9 w-9 p-0",title:"Show sidebar",onClick:()=>{e8(!1),aG.useAIPanelStore.getState().close()},children:(0,t.jsx)(C,{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:eY?.path,children:[eY&&(0,t.jsx)("span",{className:"editorial-tree-typeicon shrink-0",children:"app"===az||"html"===az?(0,t.jsx)(g.Globe,{className:"h-4 w-4 text-foreground/70"}):si(eY.name)?(0,t.jsx)(y.default,{className:"h-4 w-4 text-sunshine-700"}):ss(eY.name)?(0,t.jsx)(m.FileText,{className:"h-4 w-4 text-foreground/70"}):(0,t.jsx)(d.File,{className:"h-4 w-4 text-foreground/60"})}),(0,t.jsx)("span",{className:"truncate",children:eY?eY.name:"Wiki Viewer"})]}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-9 w-9 p-0",title:"AI Agent panel",onClick:()=>{aG.useAIPanelStore.getState().open(),e8(!0)},children:(0,t.jsx)(s,{className:"h-4 w-4"})})]}),eY?"node-app"===az?(0,t.jsx)(tM,{path:eY.path,title:eY.name}):"app"===az||"html"===az?(e="html"===az?`/api/assets/${eY.path}`:void 0,e5?(0,t.jsx)(tj,{path:eY.path,title:eY.name,src:e,fullscreen:!0,onExit:()=>e3(!1)}):(0,t.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,t.jsxs)("div",{className:(0,V.cn)("flex items-center justify-between px-4 py-2 border-b bg-muted shrink-0 editorial-doc-header",!e9&&e6&&"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)(g.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:eY.path,children:eY.path})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[aF(eY),"html"===az&&!tv&&null!==td&&(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Edit source",onClick:()=>{tk(!0),tC(td),tO(null)},children:(0,t.jsx)(E,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Refresh",onClick:()=>e7(e=>e+1),children:(0,t.jsx)(O,{className:"h-3.5 w-3.5"})}),(0,t.jsxs)(U.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1.5 text-xs",onClick:()=>e3(!0),children:[(0,t.jsx)(k,{className:"h-3.5 w-3.5"}),"Open fullscreen"]}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{e0(null),tk(!1)},children:(0,t.jsx)(B.X,{className:"h-3.5 w-3.5"})})]})]}),tv&&"html"===az?(0,t.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:[(0,t.jsx)("textarea",{value:t_,onChange:e=>tC(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:[tD&&(0,t.jsx)("span",{className:"text-xs text-destructive mr-auto",children:tD}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",onClick:()=>{tk(!1),tO(null)},children:"Cancel"}),(0,t.jsxs)(U.Button,{size:"sm",className:"gap-1",onClick:a_,disabled:tS,children:[tS&&(0,t.jsx)(N.Loader2,{className:"h-3 w-3 animate-spin"}),"Save"]})]})]}):(0,t.jsx)(tj,{path:eY.path,title:eY.name,src:e},e4)]})):(0,t.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,t.jsxs)("div",{className:(0,V.cn)("flex items-center justify-between px-4 py-2 border-b bg-muted shrink-0 editorial-doc-header",!e9&&e6&&"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:si(eY.name)?(0,t.jsx)(y.default,{className:"h-4 w-4 shrink-0 text-sunshine-700"}):ss(eY.name)?(0,t.jsx)(m.FileText,{className:"h-4 w-4 shrink-0 text-foreground/70"}):(0,t.jsx)(d.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:eY.path,children:eY.path}),tW&&(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)(w,{className:"h-3 w-3 shrink-0"}),(0,t.jsx)("span",{className:"truncate max-w-[100px]",children:tW.author}),(0,t.jsx)("span",{title:new Date(tW.date).toLocaleString(),className:"shrink-0",children:n8(tW.date)})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[aF(eY),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"File history",onClick:()=>{tV?tZ(!1):ac()},children:(0,t.jsx)(b,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Share",onClick:()=>tc(!0),children:(0,t.jsx)(I,{className:"h-3.5 w-3.5"})}),ss(eY.name)&&!tv&&(null!==td||sr(eY.name))&&(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{tk(!0),tC(td??""),tO(null),sr(eY.name)&&a2.useEditorStore.getState().loadPage(eY.path)},children:(0,t.jsx)(E,{className:"h-3.5 w-3.5"})}),ss(eY.name)&&tv&&sr(eY.name)&&(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Done editing",onClick:()=>{tk(!1),tO(null)},children:(0,t.jsx)(S.Eye,{className:"h-3.5 w-3.5"})}),ss(eY.name)&&!tv&&(null!==td||sr(eY.name))&&(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Refresh",onClick:ag,disabled:tw,children:tw?(0,t.jsx)(N.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(O,{className:"h-3.5 w-3.5"})}),aW&&(0,t.jsx)(n4.ViewWidthToggle,{}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{e0(null),tu(null),tk(!1)},children:(0,t.jsx)(B.X,{className:"h-3.5 w-3.5"})})]})]}),tV&&(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:()=>tZ(!1),children:(0,t.jsx)(B.X,{className:"h-3.5 w-3.5"})})]}),tQ?(0,t.jsx)("div",{className:"flex justify-center py-4",children:(0,t.jsx)(N.Loader2,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):0===tX.length?(0,t.jsx)("p",{className:"px-4 py-3 text-xs text-muted-foreground",children:"No history found."}):(0,t.jsx)("div",{children:tX.map(e=>(0,t.jsxs)("div",{children:[(0,t.jsx)("button",{type:"button",className:(0,V.cn)("w-full text-left px-4 py-2 hover:bg-muted transition-colors",t1===e.sha&&"bg-muted"),onClick:()=>void ad(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:n8(e.date)})]})}),t1===e.sha&&(0,t.jsx)("div",{className:"border-t",children:t4?(0,t.jsx)("div",{className:"flex justify-center py-3",children:(0,t.jsx)(N.Loader2,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):null!==t5?(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:t5}):null})]},e.sha))})]}),a$?(0,t.jsx)(en,{path:eY.path,size:eY.size??0,onOpen:()=>e2(eY.path)}):tv?(0,t.jsx)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:sr(eY.name)?(0,t.jsx)(Y.KBEditor,{}):(0,t.jsx)("textarea",{value:t_,onChange:e=>tC(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"})}):sr(eY.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)(N.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):(0,t.jsx)(Y.KBEditor,{mode:"viewing"})}):(0,t.jsx)("div",{className:"flex-1 overflow-auto p-4 min-h-0",children:(0,t.jsx)("div",{className:(0,V.cn)("w-full",aZ,aV),children:tw?(0,t.jsx)("div",{className:"flex justify-center py-8",children:(0,t.jsx)(N.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):"csv"===az?(0,t.jsx)(Q,{path:eY.path,title:eY.name}):"pdf"===az?(0,t.jsx)(tg,{path:eY.path,title:eY.name}):"mermaid"===az?(0,t.jsx)(ec,{path:eY.path,title:eY.name}):"notebook"===az?(0,t.jsx)(tm,{path:eY.path,title:eY.name}):"image"===az?(0,t.jsx)(es,{path:eY.path,title:eY.name}):"media"===az?(0,t.jsx)(er,{path:eY.path,title:eY.name,type:["mp4","webm","mov","m4v"].includes(st(eY.name))?"video":"audio"}):"docx"===az?(0,t.jsx)(th,{path:eY.path,title:eY.name}):"xlsx"===az?(0,t.jsx)(tf,{path:eY.path,title:eY.name}):"pptx"===az?(0,t.jsx)(tx,{path:eY.path,title:eY.name}):"source"===az?(0,t.jsx)(tN,{path:eY.path,title:eY.name}):"fallback"===az?(0,t.jsx)(ee,{path:eY.path,title:eY.name}):null!==td?(0,t.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-words leading-relaxed",children:td}):ss(eY.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&&!sr(eY.name)&&(0,t.jsxs)("div",{className:"border-t px-4 py-2 flex items-center justify-end gap-2 bg-muted shrink-0",children:[tD&&(0,t.jsx)("span",{className:"text-xs text-destructive mr-auto",children:tD}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",onClick:()=>{tk(!1),tO(null)},children:"Cancel"}),(0,t.jsxs)(U.Button,{size:"sm",className:"gap-1",onClick:a_,disabled:tS,children:[tS&&(0,t.jsx)(N.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)(m.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)(au,{open:to,onOpenChange:tc,filePath:eY?.path??""}),(0,t.jsx)(tY,{open:ti,onOpenChange:tl}),(0,t.jsx)(ne,{currentPath:eY?.path}),(0,t.jsx)("input",{ref:eR,type:"file",multiple:!0,className:"hidden",onChange:e=>{e.target.files&&aC(e.target.files,eF.current)}}),(0,t.jsx)(K,{open:!!eZ,onOpenChange:e=>{e||eX(null)},title:eJ?"Delete folder?":"Delete file?",description:eJ?`"${eZ?.split("/").pop()}" and all its contents will be permanently deleted.`:`"${eZ?.split("/").pop()}" will be permanently removed.`,onConfirm:aL}),(0,t.jsx)(K,{open:!!et,onOpenChange:e=>{e||ea(null)},title:"Delete workspace?",description:`"${q.find(e=>e.id===et)?.name??""}" will be removed from the workspace list. Files on disk are NOT deleted.`,onConfirm:ak})]})]},F??"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,z.useState)(""),h=(0,z.useRef)(null),x=window.location.origin,f=(0,z.useCallback)(()=>a6,[]),g=(0,z.useCallback)(()=>m.replace(/\$WIKI_URL/g,x),[m,x]),b=(0,z.useCallback)(()=>`npx wiki-viewer-mcp register --url ${x} --id ai:myagent --name "My Agent"`,[x]),w=(0,z.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=a8(f),v=a8(g),N=a8(b),k=a8(w);return((0,z.useEffect)(()=>{if(a)return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e);function e(e){"Escape"===e.key&&n()}},[a,n]),(0,z.useEffect)(()=>{a&&h.current?.focus()},[a]),(0,z.useEffect)(()=>{if(!a)return;c();let e=setInterval(()=>void c(),1e4);return()=>clearInterval(e)},[a,c]),(0,z.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)(s,{className:"h-4 w-4 text-muted-foreground"}),(0,t.jsx)("span",{className:"text-sm font-semibold",children:"AI Agent"})]}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:n,title:"Close panel (Esc)",children:(0,t.jsx)(B.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)(U.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)(r.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:a6}),(0,t.jsx)(U.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)(r.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)(U.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)(r.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)(U.Button,{size:"sm",variant:"outline",className:"h-7 w-full text-xs gap-1.5",onClick:()=>void k.copy(),children:k.copied?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(r.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)(r.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)(et.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)(et.ExternalLink,{className:"h-3 w-3"})," install JSON"]})]})]}),(0,t.jsx)(a1,{}),(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)(aW,{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)(a9,{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 nt=e.i(580330),na=e.i(409082),nn=e.i(877031),ns=e.i(847463),nr=e.i(917356),ni=/[\\\/_+.#"@\[\(\{&]/,nl=/[\\\/_+.#"@\[\(\{&]/g,no=/[\s-]/,nc=/[\s-]/g;function nd(e){return e.toLowerCase().replace(nc," ")}var nu=e.i(750110),nm=e.i(433616),np='[cmdk-group=""]',nh='[cmdk-group-items=""]',nx='[cmdk-item=""]',nf=`${nx}:not([aria-disabled="true"])`,ng="cmdk-item-select",nb="data-value",nw=(e,t,a)=>{var n;return n=e,function e(t,a,n,s,r,i,l){if(i===a.length)return r===t.length?1:.99;var o=`${r},${i}`;if(void 0!==l[o])return l[o];for(var c,d,u,m,p=s.charAt(i),h=n.indexOf(p,r),x=0;h>=0;)(c=e(t,a,n,s,h+1,i+1,l))>x&&(h===r?c*=1:ni.test(t.charAt(h-1))?(c*=.8,(u=t.slice(r,h-1).match(nl))&&r>0&&(c*=Math.pow(.999,u.length))):no.test(t.charAt(h-1))?(c*=.9,(m=t.slice(r,h-1).match(nc))&&r>0&&(c*=Math.pow(.999,m.length))):(c*=.17,r>0&&(c*=Math.pow(.999,h-r))),t.charAt(h)!==a.charAt(i)&&(c*=.9999)),(c<.1&&n.charAt(h-1)===s.charAt(i+1)||s.charAt(i+1)===s.charAt(i)&&n.charAt(h-1)!==s.charAt(i))&&.1*(d=e(t,a,n,s,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,nd(n),nd(t),0,0,{})},ny=z.createContext(void 0),nv=z.createContext(void 0),nN=z.createContext(void 0),nk=z.forwardRef((e,t)=>{let a=nT(()=>{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=nT(()=>new Set),s=nT(()=>new Map),r=nT(()=>new Map),i=nT(()=>new Set),l=nD(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,nm.useId)(),w=(0,nm.useId)(),y=(0,nm.useId)(),v=z.useRef(null),N=nF();nO(()=>{if(void 0!==d){let e=d.trim();a.current.value=e,k.emit()}},[d]),nO(()=>{N(6,M)},[]);let k=z.useMemo(()=>({subscribe:e=>(i.current.add(e),()=>i.current.delete(e)),snapshot:()=>a.current,setState:(e,t,n)=>{var s,r,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==(s=document.getElementById(b))||s.focus()}if(N(7,()=>{var e;a.current.selectedItemId=null==(e=A())?void 0:e.id,k.emit()}),n||N(5,M),(null==(r=l.current)?void 0:r.value)!==void 0){null==(o=(i=l.current).onValueChange)||o.call(i,null!=t?t:"");return}}k.emit()}},emit:()=>{i.current.forEach(e=>e())}}),[]),j=z.useMemo(()=>({value:(e,t,n)=>{var s;t!==(null==(s=r.current.get(e))?void 0:s.value)&&(r.current.set(e,{value:t,keywords:n}),a.current.filtered.items.set(e,_(t,n)),N(2,()=>{C(),k.emit()}))},item:(e,t)=>(n.current.add(e),t&&(s.current.has(t)?s.current.get(t).add(e):s.current.set(t,new Set([e]))),N(3,()=>{S(),C(),a.current.value||E(),k.emit()}),()=>{r.current.delete(e),n.current.delete(e),a.current.filtered.items.delete(e);let t=A();N(4,()=>{S(),(null==t?void 0:t.getAttribute("id"))===e&&E(),k.emit()})}),group:e=>(s.current.has(e)||s.current.set(e,new Set),()=>{r.current.delete(e),s.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,s;let r=null!=(s=null==(n=l.current)?void 0:n.filter)?s:nw;return e?r(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=s.current.get(a),r=0;n.forEach(t=>{r=Math.max(e.get(t),r)}),t.push([a,r])});let n=v.current;D().sort((t,a)=>{var n,s;let r=t.getAttribute("id"),i=a.getAttribute("id");return(null!=(n=e.get(i))?n:0)-(null!=(s=e.get(r))?s:0)}).forEach(e=>{let t=e.closest(nh);t?t.appendChild(e.parentElement===t?e:e.closest(`${nh} > *`)):n.appendChild(e.parentElement===n?e:e.closest(`${nh} > *`))}),t.sort((e,t)=>t[1]-e[1]).forEach(e=>{var t;let a=null==(t=v.current)?void 0:t.querySelector(`${np}[${nb}="${encodeURIComponent(e[0])}"]`);null==a||a.parentElement.appendChild(a)})}function E(){let e=D().find(e=>"true"!==e.getAttribute("aria-disabled")),t=null==e?void 0:e.getAttribute(nb);k.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 s of n.current){let n=_(null!=(t=null==(e=r.current.get(s))?void 0:e.value)?t:"",null!=(o=null==(i=r.current.get(s))?void 0:i.keywords)?o:[]);a.current.filtered.items.set(s,n),n>0&&c++}for(let[e,t]of s.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=A();n&&((null==(e=n.parentElement)?void 0:e.firstChild)===n&&(null==(a=null==(t=n.closest(np))?void 0:t.querySelector('[cmdk-group-heading=""]'))||a.scrollIntoView({block:"nearest"})),n.scrollIntoView({block:"nearest"}))}function A(){var e;return null==(e=v.current)?void 0:e.querySelector(`${nx}[aria-selected="true"]`)}function D(){var e;return Array.from((null==(e=v.current)?void 0:e.querySelectorAll(nf))||[])}function O(e){let t=D()[e];t&&k.setState("value",t.getAttribute(nb))}function T(e){var t;let a=A(),n=D(),s=n.findIndex(e=>e===a),r=n[s+e];null!=(t=l.current)&&t.loop&&(r=s+e<0?n[n.length-1]:s+e===n.length?n[0]:n[s+e]),r&&k.setState("value",r.getAttribute(nb))}function I(e){let t=A(),a=null==t?void 0:t.closest(np),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,np):function(e,t){let a=e.previousElementSibling;for(;a;){if(a.matches(t))return a;a=a.previousElementSibling}}(a,np))?void 0:a.querySelector(nf);n?k.setState("value",n.getAttribute(nb)):T(e)}let R=()=>O(D().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 z.createElement(nu.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=A();if(t){let e=new Event(ng);t.dispatchEvent(e)}}}}},z.createElement("label",{"cmdk-label":"",htmlFor:j.inputId,id:j.labelId,style:nP},o),nL(e,e=>z.createElement(nv.Provider,{value:k},z.createElement(ny.Provider,{value:j},e))))}),nj=z.forwardRef((e,t)=>{var a,n;let s=(0,nm.useId)(),r=z.useRef(null),i=z.useContext(nN),l=z.useContext(ny),o=nD(e),c=null!=(n=null==(a=o.current)?void 0:a.forceMount)?n:null==i?void 0:i.forceMount;nO(()=>{if(!c)return l.item(s,null==i?void 0:i.id)},[c]);let d=nR(s,r,[e.value,e.children,r],e.keywords),u=z.useContext(nv),m=nI(e=>e.value&&e.value===d.current),p=nI(e=>!!c||!1===l.filter()||!e.search||e.filtered.items.get(s)>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(z.useEffect(()=>{let t=r.current;if(!(!t||e.disabled))return t.addEventListener(ng,h),()=>t.removeEventListener(ng,h)},[p,e.onSelect,e.disabled]),!p)return null;let{disabled:f,value:g,onSelect:b,forceMount:w,keywords:y,...v}=e;return z.createElement(nu.Primitive.div,{ref:(0,t3.composeRefs)(r,t),...v,id:s,"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)}),n_=z.forwardRef((e,t)=>{let{heading:a,children:n,forceMount:s,...r}=e,i=(0,nm.useId)(),l=z.useRef(null),o=z.useRef(null),c=(0,nm.useId)(),d=z.useContext(ny),u=nI(e=>!!s||!1===d.filter()||!e.search||e.filtered.groups.has(i));nO(()=>d.group(i),[]),nR(i,l,[e.value,e.heading,o]);let m=z.useMemo(()=>({id:i,forceMount:s}),[s]);return z.createElement(nu.Primitive.div,{ref:(0,t3.composeRefs)(l,t),...r,"cmdk-group":"",role:"presentation",hidden:!u||void 0},a&&z.createElement("div",{ref:o,"cmdk-group-heading":"","aria-hidden":!0,id:c},a),nL(e,e=>z.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":a?c:void 0},z.createElement(nN.Provider,{value:m},e))))}),nC=z.forwardRef((e,t)=>{let{alwaysRender:a,...n}=e,s=z.useRef(null),r=nI(e=>!e.search);return a||r?z.createElement(nu.Primitive.div,{ref:(0,t3.composeRefs)(s,t),...n,"cmdk-separator":"",role:"separator"}):null}),nE=z.forwardRef((e,t)=>{let{onValueChange:a,...n}=e,s=null!=e.value,r=z.useContext(nv),i=nI(e=>e.search),l=nI(e=>e.selectedItemId),o=z.useContext(ny);return z.useEffect(()=>{null!=e.value&&r.setState("search",e.value)},[e.value]),z.createElement(nu.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:s?e.value:i,onChange:e=>{s||r.setState("search",e.target.value),null==a||a(e.target.value)}})}),nS=z.forwardRef((e,t)=>{let{children:a,label:n="Suggestions",...s}=e,r=z.useRef(null),i=z.useRef(null),l=nI(e=>e.selectedItemId),o=z.useContext(ny);return z.useEffect(()=>{if(i.current&&r.current){let e=i.current,t=r.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)}}},[]),z.createElement(nu.Primitive.div,{ref:(0,t3.composeRefs)(r,t),...s,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":l,"aria-label":n,id:o.listId},nL(e,e=>z.createElement("div",{ref:(0,t3.composeRefs)(i,o.listInnerRef),"cmdk-list-sizer":""},e)))}),nM=z.forwardRef((e,t)=>{let{open:a,onOpenChange:n,overlayClassName:s,contentClassName:r,container:i,...l}=e;return z.createElement(tL.Root,{open:a,onOpenChange:n},z.createElement(tL.Portal,{container:i},z.createElement(tL.Overlay,{"cmdk-overlay":"",className:s}),z.createElement(tL.Content,{"aria-label":e.label,"cmdk-dialog":"",className:r},z.createElement(nk,{ref:t,...l}))))}),nA=Object.assign(nk,{List:nS,Item:nj,Input:nE,Group:n_,Separator:nC,Dialog:nM,Empty:z.forwardRef((e,t)=>nI(e=>0===e.filtered.count)?z.createElement(nu.Primitive.div,{ref:t,...e,"cmdk-empty":"",role:"presentation"}):null),Loading:z.forwardRef((e,t)=>{let{progress:a,children:n,label:s="Loading...",...r}=e;return z.createElement(nu.Primitive.div,{ref:t,...r,"cmdk-loading":"",role:"progressbar","aria-valuenow":a,"aria-valuemin":0,"aria-valuemax":100,"aria-label":s},nL(e,e=>z.createElement("div",{"aria-hidden":!0},e)))})});function nD(e){let t=z.useRef(e);return nO(()=>{t.current=e}),t}var nO="u"<typeof window?z.useEffect:z.useLayoutEffect;function nT(e){let t=z.useRef();return void 0===t.current&&(t.current=e()),t}function nI(e){let t=z.useContext(nv),a=()=>e(t.snapshot());return z.useSyncExternalStore(t.subscribe,a,a)}function nR(e,t,a,n=[]){let s=z.useRef(),r=z.useContext(ny);return nO(()=>{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():s.current}})(),o=n.map(e=>e.trim());r.value(e,l,o),null==(i=t.current)||i.setAttribute(nb,l),s.current=l}),s}var nF=()=>{let[e,t]=z.useState(),a=nT(()=>new Map);return nO(()=>{a.current.forEach(e=>e()),a.current=new Map},[e]),(e,n)=>{a.current.set(e,n),t({})}};function nL({asChild:e,children:t},a){let n;return e&&z.isValidElement(t)?z.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 nP={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};let nB=(0,n.default)("search",[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]),nz=z.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nA,{ref:n,className:(0,V.cn)("flex h-full w-full flex-col overflow-hidden rounded-sm bg-popover text-popover-foreground",e),...a}));function n$({children:e,shouldFilter:a,...n}){return(0,t.jsx)(q.Dialog,{...n,children:(0,t.jsxs)(q.DialogContent,{className:"overflow-hidden p-0 shadow-golden max-w-lg",children:[(0,t.jsx)(q.DialogTitle,{className:"sr-only",children:"Search"}),(0,t.jsx)(nz,{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})]})})}nz.displayName=nA.displayName;let nU=z.forwardRef(({className:e,...a},n)=>(0,t.jsxs)("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[(0,t.jsx)(nB,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),(0,t.jsx)(nA.Input,{ref:n,className:(0,V.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})]}));nU.displayName=nA.Input.displayName;let nq=z.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nA.List,{ref:n,className:(0,V.cn)("max-h-[300px] overflow-y-auto overflow-x-hidden",e),...a}));nq.displayName=nA.List.displayName;let nK=z.forwardRef((e,a)=>(0,t.jsx)(nA.Empty,{ref:a,className:"py-6 text-center text-sm text-muted-foreground",...e}));nK.displayName=nA.Empty.displayName;let nH=z.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nA.Group,{ref:n,className:(0,V.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}));nH.displayName=nA.Group.displayName;let nW=z.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nA.Separator,{ref:n,className:(0,V.cn)("-mx-1 h-px bg-border",e),...a}));nW.displayName=nA.Separator.displayName;let nG=z.forwardRef(({className:e,...a},n)=>(0,t.jsx)(nA.Item,{ref:n,className:(0,V.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}));nG.displayName=nA.Item.displayName;let nV=null,nZ=null,nX=(0,tW.create)(e=>({query:"",results:[],loading:!1,truncated:!1,open:!1,setQuery:t=>e({query:t}),setOpen:t=>e({open:t}),clear:()=>{nZ&&clearTimeout(nZ),nV?.abort(),e({query:"",results:[],loading:!1,truncated:!1})},search:t=>(nZ&&clearTimeout(nZ),t.trim())?(e({loading:!0}),new Promise(a=>{nZ=setTimeout(()=>{nJ(e,t).finally(a)},150)})):(nV?.abort(),e({results:[],loading:!1,truncated:!1}),Promise.resolve())}));async function nJ(e,t){nV?.abort();let a=new AbortController;nV=a;try{let n=await (0,G.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 s=await n.json();if(a.signal.aborted)return;e({results:s.matches??[],truncated:!!s.truncated,loading:!1})}catch(t){"AbortError"!==t.name&&e({loading:!1})}}var nQ=e.i(395624);function nY({html:e}){let a=function(e){let t,a=[],n=/<mark>([\s\S]*?)<\/mark>/g,s=0;for(;null!==(t=n.exec(e));)t.index>s&&a.push({text:e.slice(s,t.index),mark:!1}),a.push({text:t[1]??"",mark:!0}),s=t.index+t[0].length;return s<e.length&&a.push({text:e.slice(s),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 n0({onOpenFile:e,onToggleSidebar:a=()=>void 0,onNewFile:n=()=>void 0,onCopyPath:r=()=>void 0}){let i=nX(e=>e.open),l=nX(e=>e.setOpen),c=nX(e=>e.query),d=nX(e=>e.setQuery),m=nX(e=>e.results),p=nX(e=>e.loading),h=nX(e=>e.truncated),x=nX(e=>e.search),{resolvedTheme:f,setTheme:g}=(0,nr.useTheme)(),b=(0,aG.useAIPanelStore)(e=>e.toggle),w=(0,nQ.useViewWidthStore)(e=>e.width),y=(0,nQ.useViewWidthStore)(e=>e.cycle),v=c.trimStart(),N=""===v||v.startsWith(">"),k=N?"":c;function j(e){e(),l(!1),d("")}(0,z.useEffect)(()=>{function e(e){(e.metaKey||e.ctrlKey)&&"k"===e.key.toLowerCase()&&(e.preventDefault(),l(!i))}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[i,l]),(0,z.useEffect)(()=>{if(!i||N)return;let e=setTimeout(()=>{x(k)},120);return()=>clearTimeout(e)},[k,N,i,x]);let _=(nQ.VIEW_WIDTH_ORDER.indexOf(w)+1)%nQ.VIEW_WIDTH_ORDER.length,C=nQ.VIEW_WIDTH_LABEL[nQ.VIEW_WIDTH_ORDER[_]];return(0,t.jsxs)(n$,{open:i,onOpenChange:e=>{l(e),e||d("")},shouldFilter:!1,children:[(0,t.jsx)(nU,{placeholder:"Search files… ( > for actions )",value:c,onValueChange:d}),(0,t.jsxs)(nq,{children:[N&&(0,t.jsxs)(nH,{heading:"Actions",children:[(0,t.jsxs)(nG,{value:"toggle-dark-mode",onSelect:()=>j(()=>g("dark"===f?"light":"dark")),children:["dark"===f?(0,t.jsx)(ns.Sun,{className:"mr-2 h-4 w-4"}):(0,t.jsx)(na.Moon,{className:"mr-2 h-4 w-4"}),"dark"===f?"Switch to light mode":"Switch to dark mode"]}),(0,t.jsxs)(nG,{value:"toggle-ai-panel",onSelect:()=>j(b),children:[(0,t.jsx)(s,{className:"mr-2 h-4 w-4"}),"Toggle AI panel"]}),(0,t.jsxs)(nG,{value:"toggle-sidebar",onSelect:()=>j(a),children:[(0,t.jsx)(nn.PanelLeft,{className:"mr-2 h-4 w-4"}),"Toggle sidebar"]}),(0,t.jsxs)(nG,{value:"new-file",onSelect:()=>j(n),children:[(0,t.jsx)(u.FilePlus,{className:"mr-2 h-4 w-4"}),"New file"]}),(0,t.jsxs)(nG,{value:"copy-path",onSelect:()=>j(r),children:[(0,t.jsx)(o.Copy,{className:"mr-2 h-4 w-4"}),"Copy current file path"]}),(0,t.jsxs)(nG,{value:"cycle-view-width",onSelect:()=>j(y),children:[(0,t.jsx)(nt.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:["(",nQ.VIEW_WIDTH_LABEL[w]," → ",C,")"]})]})]})]}),!N&&(0,t.jsxs)(t.Fragment,{children:[p&&(0,t.jsx)("div",{className:"px-3 py-2 text-xs text-muted-foreground",children:"Searching…"}),!p&&""!==k.trim()&&0===m.length&&(0,t.jsx)(nK,{children:"No matches."}),m.length>0&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(nW,{}),(0,t.jsx)(nH,{heading:h?"Top results (refine query for more)":"Results",children:m.map(a=>(0,t.jsx)(nG,{value:a.path,onSelect:()=>{e(a.path),l(!1),d("")},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)(nY,{html:a.snippet})})]})},a.path))})]})]})]})]})}function n1({onOpenFile:e}){let a=nX(e=>e.query),n=nX(e=>e.setQuery),s=nX(e=>e.results),r=nX(e=>e.loading),i=nX(e=>e.search),l=nX(e=>e.clear),[o,c]=(0,z.useState)(0),d=(0,z.useRef)(null);function u(t){let a=s[t];a&&(e(a.path),l())}return(0,z.useEffect)(()=>{c(0)},[s]),(0,z.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)(nB,{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!==s.length&&("ArrowDown"===e.key?(e.preventDefault(),c(e=>(e+1)%s.length)):"ArrowUp"===e.key?(e.preventDefault(),c(e=>(e-1+s.length)%s.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:[r&&(0,t.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"Searching…"}),!r&&0===s.length&&(0,t.jsx)("div",{className:"px-2 py-1 text-xs text-muted-foreground",children:"No matches"}),s.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)(nY,{html:e.snippet})})]},e.path))]})]})}let n2="wiki-sidebar-width";function n5(e){return Number.isNaN(e)?288:Math.min(600,Math.max(200,Math.round(e)))}let n3=(0,tW.create)(e=>({width:function(){let e=localStorage.getItem(n2);if(e){let t=Number.parseInt(e,10);if(!Number.isNaN(t))return n5(t)}return 288}(),setWidth:t=>{let a=n5(t);localStorage.setItem(n2,String(a)),e({width:a})}}));var n4=e.i(780569),n7=e.i(246542);let n9="wiki-show-hidden",n6=(0,tW.create)((e,t)=>({showHidden:"1"===localStorage.getItem(n9),toggle:()=>{let a=!t().showHidden;a?localStorage.setItem(n9,"1"):localStorage.removeItem(n9),e({showHidden:a})}}));function n8(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 s=Math.floor(n/60);return s<24?`${s}h ago`:`${Math.floor(s/24)}d ago`}let se=new Set(["image","media","pdf","fallback","app","node-app","html"]);function st(e){return e.split(".").pop()?.toLowerCase()??""}function sa(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=st(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 sn=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 ss(e){let t=sa(e,"file");return"editor"===t||"text"===t||sn.has(st(e))}function sr(e){return["md","markdown"].includes(st(e))}function si(e){return"image"===sa(e,"file")}async function sl(e){let t=await (0,G.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 so=new Map,sc=new Map;async function sd(e){let t=so.get(e);if(t)return so.delete(e),t;let a=sc.get(e);if(a){let t=await a;return so.delete(e),t}return null}function su(e,t,a){return e.map(e=>e.path===t?a(e):e.children?{...e,children:su(e.children,t,a)}:e)}let sm={contentVisibility:"auto",containIntrinsicSize:"auto 32px"},sp=(0,z.memo)(function({node:e,depth:a,ctx:n,isMobile:s,activeWorkspaceId:i,sidebarScrollRef:b,isActive:w,isDragOver:k,isPinned:_,isAgentActive:C,isPulling:E,branchOpen:S,branchPos:M,branches:A,branchLoading:D,checkingOut:T,onHoverEnter:I,onHoverLeave:B}){return(0,t.jsxs)(av,{children:[(0,t.jsx)(ak,{asChild:!0,children:(0,t.jsxs)("div",{role:"treeitem",tabIndex:0,draggable:!s,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=b.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=b.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=b.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=b.current;if(!e)return;let a=Array.from(e.querySelectorAll('[role="treeitem"]')),n=t.currentTarget,s=a.indexOf(n),r=Number.parseInt(n.style.paddingLeft??"0",10);for(let e=s-1;e>=0;e--)if(Number.parseInt(a[e].style.paddingLeft??"0",10)<r){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:()=>I(e),onMouseLeave:B,className:(0,V.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",w?"bg-accent-soft text-foreground font-medium":"hover:bg-muted",k&&"ring-2 ring-primary bg-primary-soft",e.name.startsWith(".")&&"opacity-40"),style:{paddingLeft:`${14*a+8}px`,...sm},onClick:()=>{"dir"===e.type?n.toggleFolder(e):("app"===e.type||"node-app"===e.type?(n.openViewer(e),n.toggleFolder(e)):n.openViewer(e),s&&n.setSidebarCollapsed(!0))},children:["dir"===e.type||"app"===e.type||"node-app"===e.type?e.loading?(0,t.jsx)(N.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)(h,{className:(0,V.cn)("h-4 w-4 shrink-0",!w&&"text-warning")}):(0,t.jsx)(p.Folder,{className:(0,V.cn)("h-4 w-4 shrink-0",!w&&"text-warning")}):"app"===e.type?(0,t.jsx)(g.Globe,{className:(0,V.cn)("h-4 w-4 shrink-0",!w&&"text-foreground/70")}):"node-app"===e.type?(0,t.jsx)(F,{className:(0,V.cn)("h-4 w-4 shrink-0",!w&&"text-emerald-500")}):"html"===sa(e.name,"file")?(0,t.jsx)(g.Globe,{className:(0,V.cn)("h-4 w-4 shrink-0",!w&&"text-foreground/60")}):si(e.name)?(0,t.jsx)(y.default,{className:(0,V.cn)("h-4 w-4 shrink-0",!w&&"text-sunshine-700")}):ss(e.name)?(0,t.jsx)(m.FileText,{className:(0,V.cn)("h-4 w-4 shrink-0",!w&&"text-foreground/70")}):(0,t.jsx)(d.File,{className:(0,V.cn)("h-4 w-4 shrink-0",!w&&"text-foreground/60")})}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate",children: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",{type:"button",className:"flex items-center gap-0.5 hover:text-foreground",title:"Switch branch",onClick:t=>{if(t.stopPropagation(),S){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)(f,{className:"h-2.5 w-2.5"}),e.git.branch,e.git.dirty&&(0,t.jsx)("span",{className:"ml-0.5 text-warning",children:"*"})]}),E?(0,t.jsx)(N.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)(O,{className:"h-2.5 w-2.5"})}),S&&M&&"u">typeof document&&(0,$.createPortal)((0,t.jsx)("div",{style:{position:"fixed",top:M.top,left:M.left},className:"z-[9999] min-w-[120px] rounded-md border bg-popover p-1 shadow-md",onKeyDown:e=>{"Escape"===e.key&&(n.setBranchDropdownNode(null),n.setBranchDropdownPos(null))},onClick:e=>e.stopPropagation(),children:D?(0,t.jsx)("div",{className:"flex justify-center py-2",children:(0,t.jsx)(N.Loader2,{className:"h-3.5 w-3.5 animate-spin text-muted-foreground"})}):0===A.length?(0,t.jsx)("p",{className:"px-2 py-1 text-[10px] text-muted-foreground",children:"No branches"}):A.map(a=>{let s=e.path.includes("/")?e.path.substring(0,e.path.lastIndexOf("/")):"";return(0,t.jsxs)("button",{type:"button",disabled:null!==T||a.current,className:(0,V.cn)("flex w-full items-center gap-1.5 rounded px-2 py-1 text-left text-[11px] hover:bg-muted",a.current&&"font-semibold text-foreground",!a.current&&"text-muted-foreground"),onClick:t=>{t.stopPropagation(),a.current||n.handleCheckout(e.path,a.name,s)},children:[a.current?(0,t.jsx)(r.Check,{className:"h-3 w-3 shrink-0"}):(0,t.jsx)("span",{className:"w-3 shrink-0"}),T===a.name?(0,t.jsx)(N.Loader2,{className:"h-3 w-3 animate-spin"}):a.name]},a.name)})}),document.body)]}),C&&(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)(tE.DropdownMenu,{children:[(0,t.jsx)(tE.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsx)(U.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)(j,{className:"h-3.5 w-3.5"})})}),(0,t.jsxs)(tE.DropdownMenuContent,{align:"end",className:"w-48",children:[(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>n.copyPath(e.path),children:[(0,t.jsx)(o.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),sr(e.name)&&(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>n.copyWikiLink(e.name),children:[(0,t.jsx)(m.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>n.copyUrl(e.path),children:[(0,t.jsx)(v.Link,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),"file"===e.type&&ss(e.name)&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>n.copyRawContent(e.path),children:[(0,t.jsx)(m.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>n.copyFormattedContent(e.path,e.name),children:[(0,t.jsx)(m.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]}),(0,t.jsx)(tE.DropdownMenuSeparator,{}),"dir"===e.type&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(tE.DropdownMenuItem,{onClick:async()=>{e.expanded||n.toggleFolder(e),n.setNewFileParent(e.path),n.setNewFileName(""),n.setFileCreateError(null)},children:[(0,t.jsx)(u.FilePlus,{className:"mr-2 h-3.5 w-3.5"}),"New file here"]}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>n.triggerUpload(e.path),children:[(0,t.jsx)(P.Upload,{className:"mr-2 h-3.5 w-3.5"}),"Upload here"]}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>{n.setNewFolderParent(e.path),n.setNewFolderName(""),n.setFolderError(null)},children:[(0,t.jsx)(x,{className:"mr-2 h-3.5 w-3.5"}),"New subfolder"]}),(0,t.jsx)(tE.DropdownMenuSeparator,{})]}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>n.handleDownload(e),children:[(0,t.jsx)(c,{className:"mr-2 h-3.5 w-3.5"}),"file"===e.type?"Download":"Download as zip"]}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>n.togglePin(e,i),children:[(0,t.jsx)(R,{className:(0,V.cn)("mr-2 h-3.5 w-3.5",_&&"fill-current text-amber-400")}),_?"Unpin":"Pin to top"]}),(0,t.jsx)(tE.DropdownMenuSeparator,{}),(0,t.jsxs)(tE.DropdownMenuItem,{className:"text-destructive focus:text-destructive",onClick:()=>{n.setDeletingPath(e.path),n.setDeletingIsDir("file"!==e.type)},children:[(0,t.jsx)(L.Trash2,{className:"mr-2 h-3.5 w-3.5"}),"Delete"]})]})]})})]})}),(0,t.jsxs)(aL,{children:[(0,t.jsx)(aP,{onSelect:()=>n.copyPath(e.path),children:"Copy path"}),sr(e.name)&&(0,t.jsx)(aP,{onSelect:()=>n.copyWikiLink(e.name),children:"Copy wiki link"}),(0,t.jsx)(aB,{}),(0,t.jsx)(aP,{onSelect:()=>n.copyUrl(e.path),children:"Copy URL"}),"file"===e.type&&ss(e.name)&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(aB,{}),(0,t.jsx)(aP,{onSelect:()=>n.copyRawContent(e.path),children:"Copy raw content"}),(0,t.jsx)(aP,{onSelect:()=>n.copyFormattedContent(e.path,e.name),children:"Copy formatted content"})]})]})]})}),sh=(0,z.memo)(function(e){let{ctx:a,openPath:n,dragOverPath:s,branchDropdownNode:i,branchDropdownPos:l,nodeBranches:o,branchesLoading:c,checkingOutBranch:d,pullingRepo:u,activePaths:h,pins:x,isMobile:f,activeWorkspaceId:g,newFileParent:b,newFileName:w,fileCreateError:y,newFolderParent:v,newFolderName:N,folderError:k,sidebarScrollRef:j}=e,_=n6(e=>e.showHidden),C=(0,z.useRef)(null),E=(0,z.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,z.useCallback)(()=>{C.current&&(clearTimeout(C.current),C.current=null)},[]),M=(0,z.useMemo)(()=>{let t=[],a=(e,n)=>{for(let s of e)!(!_&&s.name.startsWith("."))&&(t.push({kind:"row",node:s,depth:n}),"dir"===s.type&&(v===s.path&&t.push({kind:"newfolder",node:s,depth:n}),b===s.path&&t.push({kind:"newfile",node:s,depth:n})),("dir"===s.type||"app"===s.type||"node-app"===s.type)&&s.expanded&&(s.children&&s.children.length>0?a(s.children,n+1):s.children?.length===0&&t.push({kind:"empty",node:s,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)(sp,{node:b,depth:v,ctx:a,isMobile:f,activeWorkspaceId:g,sidebarScrollRef:j,isActive:n===b.path,isDragOver:s===b.path,isPinned:x.some(e=>e.path===b.path),isAgentActive:h.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`,...sm},children:[(0,t.jsx)("span",{className:"w-3.5 shrink-0"}),(0,t.jsx)(p.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(""))}}),k&&(0,t.jsx)("span",{className:"text-xs text-destructive",children:k}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:a.handleCreateFolder,children:(0,t.jsx)(r.Check,{className:"h-3 w-3"})}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{a.setNewFolderParent(null),a.setNewFolderName("")},children:(0,t.jsx)(B.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`,...sm},children:[(0,t.jsx)("span",{className:"w-3.5 shrink-0"}),(0,t.jsx)(m.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)(U.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:a.handleCreateFile,children:(0,t.jsx)(r.Check,{className:"h-3 w-3"})}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{a.setNewFileParent(null),a.setNewFileName("")},children:(0,t.jsx)(B.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`,...sm},children:"Empty"},`empty-${b.path}`)})})});e.s(["default",0,function(){let e;(0,n7.useWikiSlugsStore)(e=>e.loadedAt),(0,z.useEffect)(()=>{n7.useWikiSlugsStore.getState().load()},[]);let[n,c]=(0,z.useState)(null),[h,j]=(0,z.useState)(null),[F,$]=(0,z.useState)(()=>(0,G.getActiveWorkspaceId)()),[q,H]=(0,z.useState)([]),[W,Z]=(0,z.useState)(!1),[X,J]=(0,z.useState)(!1),[et,ea]=(0,z.useState)(null),[ei,el]=(0,z.useState)(null),eo=(0,z.useCallback)(async()=>{try{let e=await fetch("/api/system/workspaces");if(!e.ok)throw Error("Failed");let t=await e.json();if(H(t.workspaces),Z(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($(n.id),j(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,z.useEffect)(()=>{eo()},[eo]);let ed=(0,a2.useEditorStore)(e=>e.currentPath),eu=aU(e=>e.recents),[em,ep]=(0,z.useState)(!1),[eh,ex]=(0,z.useState)(!0),ef=aH(e=>e.pins),eg=(0,z.useRef)(null),eb=(0,aG.useAIPanelStore)(e=>e.activity),ew=(0,z.useMemo)(()=>{let e=new Date(Date.now()-6e4).toISOString(),t=new Set;for(let a of eb)a.at>=e&&a.path&&a.by?.startsWith("ai:")&&t.add(a.path);return t},[eb]);(0,z.useEffect)(()=>{let e=()=>{aG.useAIPanelStore.getState().loadActivity()};e();let t=setInterval(e,1e4);return()=>clearInterval(t)},[]),(0,z.useEffect)(()=>{aU.getState().loadForWorkspace(F),aH.getState().loadForWorkspace(F)},[F]),(0,z.useEffect)(()=>{let e=[...ef.map(e=>e.path),...eu.slice(0,8).map(e=>e.path)].filter((e,t,a)=>sr(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,a2.prefetchPage)(t)});return()=>{"cancelIdleCallback"in window?window.cancelIdleCallback(t):clearTimeout(t)}},[ef,eu]);let ey=(0,z.useRef)(new URLSearchParams(window.location.search).get("path")),ev=(0,z.useRef)(!1),[eN,ek]=(0,z.useState)([]),[ej,e_]=(0,z.useState)(!1),[eC,eE]=(0,z.useState)(!1),eS=(0,z.useRef)(!1),[eM,eA]=(0,z.useState)(!1),[eD,eO]=(0,z.useState)(!1),[eT,eI]=(0,z.useState)(null),eR=(0,z.useRef)(null),eF=(0,z.useRef)(""),[eL,eP]=(0,z.useState)(null),[eB,ez]=(0,z.useState)(""),[e$,eU]=(0,z.useState)(null),[eq,eK]=(0,z.useState)(null),[eH,eW]=(0,z.useState)(""),[eG,eV]=(0,z.useState)(null),[eZ,eX]=(0,z.useState)(null),[eJ,eQ]=(0,z.useState)(!1),[eY,e0]=(0,z.useState)(null),[e1,e2]=(0,z.useState)(null),[e5,e3]=(0,z.useState)(!1),[e4,e7]=(0,z.useState)(0),e9=function(e="(max-width: 767px)"){let[t,a]=(0,z.useState)(!1);return(0,z.useEffect)(()=>{let t=window.matchMedia(e),n=()=>a(t.matches);return n(),t.addEventListener("change",n),()=>t.removeEventListener("change",n)},[e]),t}(),[e6,e8]=(0,z.useState)(!1),te=n3(e=>e.width),tt=n6(e=>e.showHidden),ta=n3(e=>e.setWidth);(0,z.useEffect)(()=>{e9&&e8(!0)},[e9]);let[ts,tr]=(0,z.useState)(!1),[ti,tl]=(0,z.useState)(!1),[to,tc]=(0,z.useState)(!1),[td,tu]=(0,z.useState)(null),[tp,tb]=(0,z.useState)(0),[tw,ty]=(0,z.useState)(!1),[tv,tk]=(0,z.useState)(!1),[t_,tC]=(0,z.useState)(""),[tS,tA]=(0,z.useState)(!1),[tD,tO]=(0,z.useState)(null),tT=(0,z.useRef)(null),[tI,tL]=(0,z.useState)(null),tP=(0,z.useRef)(null),tB=(0,z.useRef)(!1),tz=(0,z.useRef)(async()=>{});(0,z.useEffect)(()=>{ej||eS.current||(eS.current=!0,eE(!0),sl("").then(e=>{ek(e),e_(!0),eE(!1)}).catch(()=>{eS.current=!1,eE(!1)}))},[ej]);let t$=(0,z.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 sl(n)});ek(e=>{let t=e;for(let{prefix:e,children:n}of a)t=su(t,e,e=>({...e,children:n,expanded:!0}));return t})},[]),tU=(0,z.useCallback)(async e=>{let t=await sl(e);""===e?ek(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})}):ek(a=>su(a,e,e=>({...e,children:t,expanded:!0})))},[]),[tq,tH]=(0,z.useState)(null),[tW,tG]=(0,z.useState)(null),[tV,tZ]=(0,z.useState)(!1),[tX,tJ]=(0,z.useState)([]),[tQ,t0]=(0,z.useState)(!1),[t1,t2]=(0,z.useState)(null),[t5,t3]=(0,z.useState)(null),[t4,t7]=(0,z.useState)(!1),[t9,t6]=(0,z.useState)({}),[t8,ae]=(0,z.useState)({}),[at,aa]=(0,z.useState)(null),[an,as]=(0,z.useState)(null),[ar,ai]=(0,z.useState)(null),al=(0,z.useCallback)(async(e,t)=>{if(!tq){tH(e);try{let a=await (0,G.wsFetch)("/api/wiki/git-pull",{method:"POST",body:JSON.stringify({path:e})});if(!a.ok){let e=await a.json();(0,tK.showError)(e.message??e.error??"Pull failed");return}let n=await a.json();(0,tK.showSuccess)(`Pulled ${e} (${n.branch} @ ${n.sha.slice(0,7)})`),await tU(t)}catch{(0,tK.showError)("Pull failed")}finally{tH(null)}}},[tq,tU]);(0,z.useEffect)(()=>{tZ(!1),tJ([]),t2(null),t3(null)},[eY?.path]);let ao=eY?.path;(0,z.useEffect)(()=>{if(!ao)return void tG(null);let e=!1,t=setTimeout(()=>{(async()=>{try{let t=await (0,G.wsFetch)(`/api/wiki/git-file-info?path=${encodeURIComponent(ao)}`);if(e)return;if(!t.ok)return void tG(null);let a=await t.json();e||tG(a.info)}catch{e||tG(null)}})()},200);return()=>{e=!0,clearTimeout(t)}},[ao]);let ac=(0,z.useCallback)(async()=>{if(!eY)return;let e=eY.path;tZ(!0),t0(!0),tJ([]),t2(null),t3(null);try{let t=await (0,G.wsFetch)(`/api/wiki/git-history?path=${encodeURIComponent(e)}`);if(!t.ok)return void(0,tK.showError)("Could not load history");let a=await t.json();eY.path===e&&tJ(a.commits)}catch{(0,tK.showError)("Could not load history")}finally{t0(!1)}},[eY]),ad=(0,z.useCallback)(async e=>{if(!eY)return;if(t1===e){t2(null),t3(null);return}let t=eY.path;t2(e),t7(!0),t3(null);try{let a=await (0,G.wsFetch)(`/api/wiki/git-diff?path=${encodeURIComponent(t)}&sha=${encodeURIComponent(e)}`);if(!a.ok)return void(0,tK.showError)("Could not load diff");let n=await a.json();eY.path===t&&t1===e&&t3(n.diff)}catch{(0,tK.showError)("Could not load diff")}finally{t7(!1)}},[eY,t1]),ap=(0,z.useCallback)(async e=>{if(t9[e]||t8[e])return;let t=!1;ae(t=>({...t,[e]:!0}));try{let a=await (0,G.wsFetch)(`/api/wiki/git-branches?path=${encodeURIComponent(e)}`);if(t)return;if(!a.ok)return void(0,tK.showError)("Could not load branches");let n=await a.json();t||t6(t=>({...t,[e]:n.branches}))}catch{t||(0,tK.showError)("Could not load branches")}finally{t||ae(t=>({...t,[e]:!1}))}return()=>{t=!0}},[t9,t8]),ah=(0,z.useCallback)(async(e,t,a)=>{if(!at){aa(t);try{let n=await (0,G.wsFetch)("/api/wiki/git-checkout",{method:"POST",body:JSON.stringify({path:e,branch:t})});if(409===n.status)return void(0,tK.showError)("Repository has uncommitted changes");if(!n.ok){let e=await n.json();(0,tK.showError)(e.error??"Checkout failed");return}let s=await n.json();(0,tK.showSuccess)(`Switched to ${s.branch}`),t6(t=>{let a={...t};return delete a[e],a}),as(null),ai(null),await tU(a)}catch{(0,tK.showError)("Checkout failed")}finally{aa(null)}}},[at,tU]);(0,z.useEffect)(()=>{if(!an)return;let e=()=>{as(null),ai(null)},t=e=>{"Escape"===e.key&&(as(null),ai(null))};return document.addEventListener("click",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("click",e),document.removeEventListener("keydown",t)}},[an]);let ax=(0,z.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(...ax(a.children)));return t},[]),af=(0,z.useCallback)(async()=>{eA(!0);try{let e=ax(eN),t=await sl("");for(let a of(ek(t),e)){let e=await sl(a);ek(t=>su(t,a,t=>({...t,children:e,expanded:!0})))}}finally{eA(!1)}},[eN,ax]),ag=(0,z.useCallback)(async()=>{if(eY){if(sr(eY.name)){ty(!0);try{await a2.useEditorStore.getState().loadPage(eY.path)}finally{ty(!1)}return}if(["editor","text"].includes(sa(eY.name,eY.nodeType))||ss(eY.name)){ty(!0);try{let e=await (0,G.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(eY.path)}`);if(e.ok){let t=await e.json();tu(t.content),tb(Number(e.headers.get("X-Wiki-Revision")??0))}}catch{}ty(!1)}}},[eY]);async function ab(e){if("dir"===e.type||"app"===e.type||"node-app"===e.type)if(e.expanded)ek(t=>su(t,e.path,e=>({...e,expanded:!1})));else if(void 0===e.children){let t=await sd(e.path);if(t)return void ek(a=>su(a,e.path,e=>({...e,loading:!1,children:t,expanded:!0})));ek(t=>su(t,e.path,e=>({...e,loading:!0})));let a=await sl(e.path);ek(t=>su(t,e.path,e=>({...e,loading:!1,children:a,expanded:!0})))}else ek(t=>su(t,e.path,e=>({...e,expanded:!0})))}async function aw(e){if("file"===e.type&&aU.getState().push({path:e.path,name:e.name},F),e0({path:e.path,name:e.name,size:e.size,nodeType:"app"===e.type?"app":"node-app"===e.type?"node-app":"file"}),tk(!1),tO(null),tu(null),tb(0),"file"===e.type&&sr(e.name)){ty(!0);try{await a2.useEditorStore.getState().loadPage(e.path)}finally{ty(!1)}return}if(["editor","text"].includes(sa(e.name,e.type))||ss(e.name)){ty(!0);try{let t=await (0,G.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(e.path)}`);if(t.ok){let e=await t.json();tu(e.content),tb(Number(t.headers.get("X-Wiki-Revision")??0))}}catch{}ty(!1)}}(0,z.useEffect)(()=>{eY&&sr(eY.name)&&a2.useEditorStore.getState().currentPath!==eY.path&&a2.useEditorStore.getState().loadPage(eY.path)},[eY]),(0,z.useEffect)(()=>{tP.current=eY},[eY]),(0,z.useEffect)(()=>{tB.current=tv},[tv]),(0,z.useEffect)(()=>{tz.current=ag},[ag]),(0,z.useEffect)(()=>{if(!n)return;let e=new Map,t=new EventSource((0,G.withWs)("/api/wiki/watch"));return t.onmessage=t=>{var a;let n;try{n=JSON.parse(t.data)}catch{return}let{type:s,path:r}=n,i=r.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),tU(a)},300)),"change"===s&&tP.current?.path===r&&!tB.current){let t=`__file__${r}`;e.has(t)&&clearTimeout(e.get(t)),e.set(t,setTimeout(()=>{e.delete(t),tz.current()},400))}},()=>{for(let a of(t.close(),e.values()))clearTimeout(a)}},[n,tU]),(0,z.useEffect)(()=>{e3(!1)},[]);let ay=(0,z.useCallback)(e=>{let t=e.split("/").pop()??e;t$(e),aw({path:e,name:t,type:"file"})},[t$]);(0,z.useEffect)(()=>{if(!ed||eY&&eY.path===ed)return;let e=ed.split("/").pop()??ed;aw({path:ed,name:e,type:"file"})},[ed]);let av=(0,z.useCallback)(async e=>{if(!e)return void e0(null);let t=e.split("/"),a=t[t.length-1],n=t.slice(0,-1).join("/"),s=(await sl(n)).find(t=>t.path===e);s&&(await t$(e),aw({path:e,name:a,type:s.type,modifiedAt:s.modifiedAt}))},[t$]);(0,z.useEffect)(()=>{let e=new URL(window.location.href);eY?e.searchParams.set("path",eY.path):e.searchParams.delete("path");let t=e.toString();t!==window.location.href&&window.history.pushState(null,"",t)},[eY]),(0,z.useEffect)(()=>{let e=()=>{av(new URLSearchParams(window.location.search).get("path"))};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[av]),(0,z.useEffect)(()=>{ev.current||ej&&(ev.current=!0,av(ey.current))},[ej,av]);let aN=(0,z.useCallback)(async e=>{if(e===F)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()),e0(null),tu(null),tk(!1),ek([]),e_(!1),eS.current=!1,n7.useWikiSlugsStore.getState().invalidate();let a=q.find(t=>t.id===e);a&&j(a.rootDir),$(e)},[F,q]),ak=(0,z.useCallback)(async()=>{if(et)try{if(!(await fetch(`/api/system/workspaces/${et}`,{method:"DELETE"})).ok)throw Error("Failed");if(et===F){let e=q.filter(e=>e.id!==et);if(e.length>0){let t=[...e].sort((e,t)=>(t.lastOpenedAt??t.createdAt).localeCompare(e.lastOpenedAt??e.createdAt))[0];await aN(t.id)}else c(!1)}await eo()}catch{}finally{ea(null)}},[et,F,q,aN,eo]),aj=(0,z.useCallback)(async e=>{if(!ei){el(e);try{let t=await fetch(`/api/system/workspaces/${e}/refresh`,{method:"POST"});if(!t.ok){let e=await t.json();(0,tK.showError)(e.error??"Refresh failed")}await eo()}catch{(0,tK.showError)("Refresh failed")}finally{el(null)}}},[ei,eo]);async function a_(){if(!eY)return;tA(!0),tO(null);let e=await (0,G.wsFetch)("/api/wiki/content",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:eY.path,content:t_,baseRevision:tp})});if(e.ok){let t=await e.json();"number"==typeof t.revision&&tb(t.revision),tu(t_),tk(!1)}else tO((await e.json()).error??"Save failed");tA(!1)}let aC=(0,z.useCallback)(async(e,t)=>{let a=Array.from(e);if(a.length){eO(!0),eI(null);try{for(let e of a){let a=new FormData;a.append("file",e),a.append("dir",t);let n=await (0,G.wsFetch)("/api/wiki/upload",{method:"POST",body:a});if(!n.ok){let e=await n.json();eI(e.error??"Upload failed"),(0,tK.showError)(e.error??"Upload failed");break}}await tU(t)}catch{eI("Upload failed.")}finally{eO(!1),eR.current&&(eR.current.value="")}}},[tU]);function aE(e){eF.current=e,eR.current?.click()}async function aS(){let e=eB.trim();if(!e||null===eL)return;eU(null);let t=eL?`${eL}/${e}`:e,a=await (0,G.wsFetch)("/api/wiki/folder",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});a.ok?(eP(null),ez(""),await tU(eL),""!==eL&&ek(e=>su(e,eL,e=>({...e,expanded:!0})))):eU((await a.json()).error??"Failed")}async function aM(){let e=eH.trim();if(!e||null===eq)return;eV(null);let t=e.includes(".")?e:`${e}.md`,a=eq?`${eq}/${t}`:t,n=await (0,G.wsFetch)("/api/wiki/new-file",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:a})});n.ok?(eK(null),eW(""),await tU(eq),""!==eq&&ek(e=>su(e,eq,e=>({...e,expanded:!0}))),aw({path:a,name:t,type:"file",modifiedAt:new Date().toISOString()})):eV((await n.json()).error??"Failed")}function aA(e){navigator.clipboard.writeText(e),(0,tK.showSuccess)("Path copied")}function aD(e){let t=e.replace(/\.(md|markdown)$/i,"");navigator.clipboard.writeText(`[[${t}]]`),(0,tK.showSuccess)("Wiki link copied")}function aO(e){let t=new URL(location.href);t.searchParams.set("path",e),F&&t.searchParams.set("ws",F),navigator.clipboard.writeText(t.toString()),(0,tK.showSuccess)("URL copied")}async function aT(e){if(eY?.path===e&&null!==td)return td;if(a2.useEditorStore.getState().currentPath===e)return a2.useEditorStore.getState().content;let t=await (0,G.wsFetch)(`/api/wiki/content?path=${encodeURIComponent(e)}`);if(!t.ok)throw Error("Cannot copy content");return(await t.json()).content}async function aI(e){try{let t=await aT(e);await navigator.clipboard.writeText(t),(0,tK.showSuccess)("Raw content copied")}catch{(0,tK.showError)("Could not copy file content")}}async function aR(e,t){try{let a=await aT(e);if(!sr(t)){await navigator.clipboard.writeText(a),(0,tK.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,tK.showSuccess)("Formatted content copied")}catch{(0,tK.showError)("Could not copy formatted content")}}function aF(e){return(0,t.jsxs)(tE.DropdownMenu,{children:[(0,t.jsx)(tE.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsxs)(U.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1.5 px-2 text-xs",title:"Copy path, wiki link, or URL",children:[(0,t.jsx)(o.Copy,{className:"h-3.5 w-3.5"}),"Copy",(0,t.jsx)(i.ChevronDown,{className:"h-3 w-3 opacity-60"})]})}),(0,t.jsxs)(tE.DropdownMenuContent,{align:"end",className:"w-44",children:[(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>aA(e.path),children:[(0,t.jsx)(o.Copy,{className:"mr-2 h-3.5 w-3.5"}),"Copy path"]}),sr(e.name)&&(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>aD(e.name),children:[(0,t.jsx)(m.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy wiki link"]}),(0,t.jsx)(tE.DropdownMenuSeparator,{}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>aO(e.path),children:[(0,t.jsx)(v.Link,{className:"mr-2 h-3.5 w-3.5"}),"Copy URL"]}),ss(e.name)&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tE.DropdownMenuSeparator,{}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>void aI(e.path),children:[(0,t.jsx)(m.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy raw content"]}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>void aR(e.path,e.name),children:[(0,t.jsx)(m.FileText,{className:"mr-2 h-3.5 w-3.5"}),"Copy formatted content"]})]})]})]})}async function aL(){eZ&&(await (0,G.wsFetch)("/api/wiki",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:eZ})}),(eY?.path===eZ||eY?.path.startsWith(`${eZ}/`))&&(e0(null),tu(null)),ek(e=>(function e(t,a){return t.filter(e=>e.path!==a).map(t=>t.children?{...t,children:e(t.children,a)}:t)})(e,eZ)),eX(null))}function aP(e,t,a){e.preventDefault(),e.stopPropagation();let n=tT.current;if(!n){Array.from(e.dataTransfer.types).includes("Files")&&(e.dataTransfer.dropEffect="copy",tL("root"===a?"":t));return}n.path===t||t.startsWith(`${n.path}/`)||(e.dataTransfer.dropEffect="move",tL("root"===a?"":t))}async function aB(e,t){e.preventDefault(),e.stopPropagation(),tL(null);let a=tT.current;if(tT.current=null,!a){e.dataTransfer.files.length>0&&await aC(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,G.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 tU(e),t!==e&&await tU(t),eY?.path===a.path&&e0({path:n,name:a.name,nodeType:eY.nodeType,size:eY.size})}}let az=eY?sa(eY.name,eY.nodeType):null,a$=!!eY&&null!==az&&!se.has(az)&&(eY.size??0)>5242880&&e1!==eY.path,aq=(0,nQ.useViewWidthStore)(e=>e.width),aK=(0,nQ.useViewWidthStore)(e=>e.align),aW=null===az||"editor"===az||"text"===az||"source"===az||"notebook"===az||"fallback"===az,aV=aW?nQ.VIEW_WIDTH_CLASS[aq]:"",aZ=aW?nQ.VIEW_ALIGN_CLASS[aK]:"",aX=(0,z.useRef)(null);aX.current={toggleFolder:e=>void ab(e),openViewer:e=>void aw(e),copyPath:aA,copyWikiLink:aD,copyUrl:aO,copyRawContent:e=>void aI(e),copyFormattedContent:(e,t)=>void aR(e,t),handleDownload:function(e){let t=(0,G.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:aE,handleCreateFile:()=>void aM(),handleCreateFolder:()=>void aS(),handleDragStart:function(e,t){tT.current=t,e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",t.path)},handleDragOver:aP,handleDropOnFolder:(e,t)=>void aB(e,t),handleGitPull:(e,t)=>void al(e,t),handleCheckout:(e,t,a)=>void ah(e,t,a),loadBranches:e=>void ap(e),prefetch:e=>{"file"===e.type?sr(e.name)&&(0,a2.prefetchPage)(e.path):function(e){if(so.has(e)||sc.has(e))return;let t=sl(e).then(t=>(so.set(e,t),t)).finally(()=>sc.delete(e));sc.set(e,t),t.catch(()=>{})}(e.path)},togglePin:(e,t)=>aH.getState().toggle({path:e.path,name:e.name,type:"dir"===e.type?"file":e.type},t),setDragOverPath:tL,setSidebarCollapsed:e8,setBranchDropdownNode:as,setBranchDropdownPos:ai,setNewFileParent:eK,setNewFileName:eW,setFileCreateError:eV,setNewFolderParent:eP,setNewFolderName:ez,setFolderError:eU,setDeletingPath:eX,setDeletingIsDir:eQ};let aJ=(0,z.useMemo)(()=>({toggleFolder:e=>aX.current.toggleFolder(e),openViewer:e=>aX.current.openViewer(e),copyPath:e=>aX.current.copyPath(e),copyWikiLink:e=>aX.current.copyWikiLink(e),copyUrl:e=>aX.current.copyUrl(e),copyRawContent:e=>aX.current.copyRawContent(e),copyFormattedContent:(e,t)=>aX.current.copyFormattedContent(e,t),handleDownload:e=>aX.current.handleDownload(e),triggerUpload:e=>aX.current.triggerUpload(e),handleCreateFile:()=>aX.current.handleCreateFile(),handleCreateFolder:()=>aX.current.handleCreateFolder(),handleDragStart:(e,t)=>aX.current.handleDragStart(e,t),handleDragOver:(e,t,a)=>aX.current.handleDragOver(e,t,a),handleDropOnFolder:(e,t)=>aX.current.handleDropOnFolder(e,t),handleGitPull:(e,t)=>aX.current.handleGitPull(e,t),handleCheckout:(e,t,a)=>aX.current.handleCheckout(e,t,a),loadBranches:e=>aX.current.loadBranches(e),prefetch:e=>aX.current.prefetch(e),togglePin:(e,t)=>aX.current.togglePin(e,t),setDragOverPath:e=>aX.current.setDragOverPath(e),setSidebarCollapsed:e=>aX.current.setSidebarCollapsed(e),setBranchDropdownNode:e=>aX.current.setBranchDropdownNode(e),setBranchDropdownPos:e=>aX.current.setBranchDropdownPos(e),setNewFileParent:e=>aX.current.setNewFileParent(e),setNewFileName:e=>aX.current.setNewFileName(e),setFileCreateError:e=>aX.current.setFileCreateError(e),setNewFolderParent:e=>aX.current.setNewFolderParent(e),setNewFolderName:e=>aX.current.setNewFolderName(e),setFolderError:e=>aX.current.setFolderError(e),setDeletingPath:e=>aX.current.setDeletingPath(e),setDeletingIsDir:e=>aX.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)(N.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}),!1===n&&(0,t.jsx)(tR,{onSelect:e=>{let t=new URL(location.href);t.searchParams.set("ws",e),t.searchParams.delete("path"),history.replaceState(null,"",t.toString()),e_(!1),eS.current=!1,$(e),c(!0),eo()}}),!0===n&&X&&(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)(U.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1.5 text-xs",onClick:()=>J(!1),children:[(0,t.jsx)(B.X,{className:"h-3.5 w-3.5"})," Cancel"]})}),(0,t.jsx)(tR,{onSelect:e=>{J(!1),eo(),aN(e)}})]}),!0===n&&!X&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(n0,{onOpenFile:ay,onToggleSidebar:()=>e8(e=>{let t=!e;return e9&&!1===t&&aG.useAIPanelStore.getState().close(),t}),onNewFile:()=>eK(""),onCopyPath:()=>{eY&&navigator.clipboard.writeText(eY.path)}}),!e6&&e9&&(0,t.jsx)("div",{className:"fixed inset-0 z-40 bg-overlay backdrop-blur-[1px] md:hidden",onClick:()=>e8(!0),"aria-hidden":!0}),!e6&&(0,t.jsxs)(am.Card,{style:e9?void 0:{width:te},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)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 shrink-0",title:"Collapse sidebar",onClick:()=>e8(!0),children:(0,t.jsx)(_,{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)(tE.DropdownMenu,{children:[(0,t.jsx)(tE.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsxs)(U.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1 px-2 text-xs",disabled:eD,children:[eD?(0,t.jsx)(N.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(D,{className:"h-3.5 w-3.5"}),"New",(0,t.jsx)(i.ChevronDown,{className:"h-3 w-3 opacity-60"})]})}),(0,t.jsxs)(tE.DropdownMenuContent,{align:"start",className:"w-44",children:[(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>{eK(""),eW(""),eV(null)},children:[(0,t.jsx)(u.FilePlus,{className:"mr-2 h-3.5 w-3.5"}),"New file"]}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>{eP(""),ez(""),eU(null)},children:[(0,t.jsx)(x,{className:"mr-2 h-3.5 w-3.5"}),"New folder"]}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>aE(""),disabled:eD,children:[(0,t.jsx)(P.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)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Refresh tree",onClick:af,disabled:eM,children:eM?(0,t.jsx)(N.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(O,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:tt?"Hide hidden files":"Show hidden files",onClick:()=>n6.getState().toggle(),children:tt?(0,t.jsx)(S.Eye,{className:"h-3.5 w-3.5"}):(0,t.jsx)(M,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(tF.ThemeToggle,{}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"AI Agent panel",onClick:()=>{aG.useAIPanelStore.getState().toggle(),e9&&e8(!0)},children:(0,t.jsx)(s,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Settings",onClick:()=>tl(!0),children:(0,t.jsx)(T,{className:"h-3.5 w-3.5"})})]})]}),eT&&(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"}),eT]}),""===eL&&(0,t.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,t.jsx)(p.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:eB,onChange:e=>ez(e.target.value),onKeyDown:e=>{"Enter"===e.key&&aS(),"Escape"===e.key&&(eP(null),ez(""))}}),e$&&(0,t.jsx)("span",{className:"text-xs text-destructive",children:e$}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:aS,children:(0,t.jsx)(r.Check,{className:"h-3 w-3"})}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{eP(null),ez("")},children:(0,t.jsx)(B.X,{className:"h-3 w-3"})})]}),""===eq&&(0,t.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 border-b shrink-0",children:[(0,t.jsx)(m.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:eH,onChange:e=>eW(e.target.value),onKeyDown:e=>{"Enter"===e.key&&aM(),"Escape"===e.key&&(eK(null),eW(""))}}),eG&&(0,t.jsx)("span",{className:"text-xs text-destructive",children:eG}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:aM,children:(0,t.jsx)(r.Check,{className:"h-3 w-3"})}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>{eK(null),eW("")},children:(0,t.jsx)(B.X,{className:"h-3 w-3"})})]}),(0,t.jsx)("div",{className:"border-b",children:(0,t.jsx)(n1,{onOpenFile:ay})}),(0,t.jsxs)("div",{ref:eg,className:(0,V.cn)("flex-1 overflow-auto py-1 editorial-file-tree",""===tI&&"ring-2 ring-inset ring-primary bg-primary/5"),onDragOver:e=>aP(e,"","root"),onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||tL(null)},onDrop:e=>aB(e,""),children:[ef.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:()=>ep(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)(A,{className:"h-3 w-3"}),"Pinned",(0,t.jsx)("span",{className:"ml-auto text-[9px] tabular-nums opacity-60",children:ef.length})]}),!em&&ef.map(e=>(0,t.jsxs)("div",{role:"button",tabIndex:0,className:(0,V.cn)("group flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer transition-colors select-none",eY?.path===e.path?"bg-accent-soft text-foreground font-medium":"hover:bg-muted"),onClick:()=>{aw({path:e.path,name:e.name,type:e.type??"file",modifiedAt:""}),e9&&e8(!0)},onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),aw({path:e.path,name:e.name,type:e.type??"file",modifiedAt:""}))},children:[(0,t.jsx)(R,{className:"h-3 w-3 shrink-0 fill-current text-amber-400"}),(0,t.jsx)("span",{className:"min-w-0 flex-1 truncate text-xs",children: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(),aH.getState().toggle({path:e.path,name:e.name},F)},children:(0,t.jsx)(B.X,{className:"h-3 w-3"})})]},e.path))]}),eu.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:()=>ex(e=>!e),children:[eh?(0,t.jsx)(l.ChevronRight,{className:"h-3 w-3"}):(0,t.jsx)(i.ChevronDown,{className:"h-3 w-3"}),"Recent",(0,t.jsx)("span",{className:"ml-auto text-[9px] tabular-nums opacity-60",children:eu.length})]}),!eh&&eu.slice(0,8).map(e=>(0,t.jsxs)("div",{role:"button",tabIndex:0,className:(0,V.cn)("flex items-center gap-1.5 rounded-sm px-2 py-1 text-sm cursor-pointer transition-colors select-none",eY?.path===e.path?"bg-accent-soft text-foreground font-medium":"hover:bg-muted"),onClick:()=>{aw({path:e.path,name:e.name,type:e.type??"file",modifiedAt:""}),e9&&e8(!0)},onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),aw({path:e.path,name:e.name,type:e.type??"file",modifiedAt:""}))},children:[(0,t.jsx)(m.FileText,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),(0,t.jsx)("span",{className:"flex-1 truncate text-xs",children: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("/")})]},e.path))]}),eC?(0,t.jsx)("div",{className:"flex justify-center py-6",children:(0,t.jsx)(N.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):0===eN.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)(m.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)(U.Button,{size:"sm",variant:"outline",className:"w-full gap-1.5 max-w-[180px]",onClick:()=>aE(""),disabled:eD,children:[eD?(0,t.jsx)(N.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(P.Upload,{className:"h-3.5 w-3.5"}),"Upload Files"]})]}):(0,t.jsx)(sh,{ctx:aJ,nodes:eN,openPath:eY?.path??null,dragOverPath:tI,branchDropdownNode:an,branchDropdownPos:ar,nodeBranches:t9,branchesLoading:t8,checkingOutBranch:at,pullingRepo:tq,activePaths:ew,pins:ef,isMobile:e9,activeWorkspaceId:F,newFileParent:eq,newFileName:eH,fileCreateError:eG,newFolderParent:eL,newFolderName:eB,folderError:e$,sidebarScrollRef:eg})]}),(0,t.jsx)("div",{className:"border-t px-2 py-2 bg-muted shrink-0",children:(0,t.jsxs)(tE.DropdownMenu,{children:[(0,t.jsx)(tE.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsxs)(U.Button,{size:"sm",variant:"ghost",className:"w-full h-auto justify-between gap-2 px-2 py-1.5 text-left",title:h??"",children:[(0,t.jsxs)("span",{className:"flex flex-col min-w-0",children:[(0,t.jsx)("span",{className:"truncate text-xs font-medium",children:q.find(e=>e.id===F)?.name??"Workspace"}),(0,t.jsx)("span",{className:"truncate text-[10px] text-muted-foreground font-mono",children:h??""})]}),(0,t.jsx)(i.ChevronDown,{className:"h-3.5 w-3.5 shrink-0 opacity-60"})]})}),(0,t.jsxs)(tE.DropdownMenuContent,{align:"start",className:"w-60",children:[q.map(e=>(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>void aN(e.id),className:(0,V.cn)("gap-2",e.id===F&&"font-medium"),children:[e.id===F?(0,t.jsx)(r.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.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)(f,{className:"h-2.5 w-2.5"})," read-only"]})]}),(0,t.jsx)("span",{className:"truncate text-[10px] text-muted-foreground font-mono",children:e.rootDir}),e.git?.lastPulledAt&&n8(e.git.lastPulledAt)&&(0,t.jsxs)("span",{className:"text-[10px] text-muted-foreground/70",children:["synced ",n8(e.git.lastPulledAt)]})]}),W&&e.git&&(0,t.jsx)("button",{className:(0,V.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:ei===e.id,onClick:t=>{t.stopPropagation(),t.preventDefault(),aj(e.id)},children:(0,t.jsx)(O,{className:(0,V.cn)("h-3.5 w-3.5",ei===e.id&&"animate-spin")})}),W&&(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(),ea(e.id)},children:(0,t.jsx)(L.Trash2,{className:"h-3.5 w-3.5"})})]},e.id)),W&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(tE.DropdownMenuSeparator,{}),(0,t.jsxs)(tE.DropdownMenuItem,{onClick:()=>J(!0),children:[(0,t.jsx)(x,{className:"mr-2 h-3.5 w-3.5"}),"Add workspace…"]})]})]})]})}),(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;tr(!0);let a=document.body.style.cursor,n=document.body.style.userSelect;document.body.style.cursor="col-resize",document.body.style.userSelect="none";let s=e=>{ta(te+(e.clientX-t))},r=()=>{tr(!1),document.body.style.cursor=a,document.body.style.userSelect=n,window.removeEventListener("mousemove",s),window.removeEventListener("mouseup",r)};window.addEventListener("mousemove",s),window.addEventListener("mouseup",r)},onDoubleClick:()=>ta(288),onKeyDown:e=>{"ArrowLeft"===e.key?(e.preventDefault(),ta(te-16)):"ArrowRight"===e.key&&(e.preventDefault(),ta(te+16))},tabIndex:0,"aria-valuemin":200,"aria-valuemax":600,"aria-valuenow":te,className:(0,V.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",ts&&"bg-primary/60")})]}),(0,t.jsxs)("div",{className:"flex-1 flex flex-col min-w-0 relative",children:[e6&&(0,t.jsx)(U.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:()=>e8(!1),children:(0,t.jsx)(C,{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)(U.Button,{size:"sm",variant:"ghost",className:"h-9 w-9 p-0",title:"Show sidebar",onClick:()=>{e8(!1),aG.useAIPanelStore.getState().close()},children:(0,t.jsx)(C,{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:eY?.path,children:[eY&&(0,t.jsx)("span",{className:"editorial-tree-typeicon shrink-0",children:"app"===az||"html"===az?(0,t.jsx)(g.Globe,{className:"h-4 w-4 text-foreground/70"}):si(eY.name)?(0,t.jsx)(y.default,{className:"h-4 w-4 text-sunshine-700"}):ss(eY.name)?(0,t.jsx)(m.FileText,{className:"h-4 w-4 text-foreground/70"}):(0,t.jsx)(d.File,{className:"h-4 w-4 text-foreground/60"})}),(0,t.jsx)("span",{className:"truncate",children:eY?eY.name:"Wiki Viewer"})]}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-9 w-9 p-0",title:"AI Agent panel",onClick:()=>{aG.useAIPanelStore.getState().open(),e8(!0)},children:(0,t.jsx)(s,{className:"h-4 w-4"})})]}),eY?"node-app"===az?(0,t.jsx)(tM,{path:eY.path,title:eY.name}):"app"===az||"html"===az?(e="html"===az?`/api/assets/${eY.path}`:void 0,e5?(0,t.jsx)(tj,{path:eY.path,title:eY.name,src:e,fullscreen:!0,onExit:()=>e3(!1)}):(0,t.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,t.jsxs)("div",{className:(0,V.cn)("flex items-center justify-between px-4 py-2 border-b bg-muted shrink-0 editorial-doc-header",!e9&&e6&&"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)(g.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:eY.path,children:eY.path})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[aF(eY),"html"===az&&!tv&&null!==td&&(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Edit source",onClick:()=>{tk(!0),tC(td),tO(null)},children:(0,t.jsx)(E,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Refresh",onClick:()=>e7(e=>e+1),children:(0,t.jsx)(O,{className:"h-3.5 w-3.5"})}),(0,t.jsxs)(U.Button,{size:"sm",variant:"ghost",className:"h-7 gap-1.5 text-xs",onClick:()=>e3(!0),children:[(0,t.jsx)(k,{className:"h-3.5 w-3.5"}),"Open fullscreen"]}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{e0(null),tk(!1)},children:(0,t.jsx)(B.X,{className:"h-3.5 w-3.5"})})]})]}),tv&&"html"===az?(0,t.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:[(0,t.jsx)("textarea",{value:t_,onChange:e=>tC(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:[tD&&(0,t.jsx)("span",{className:"text-xs text-destructive mr-auto",children:tD}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",onClick:()=>{tk(!1),tO(null)},children:"Cancel"}),(0,t.jsxs)(U.Button,{size:"sm",className:"gap-1",onClick:a_,disabled:tS,children:[tS&&(0,t.jsx)(N.Loader2,{className:"h-3 w-3 animate-spin"}),"Save"]})]})]}):(0,t.jsx)(tj,{path:eY.path,title:eY.name,src:e},e4)]})):(0,t.jsxs)("div",{className:"flex-1 flex flex-col overflow-hidden min-w-0",children:[(0,t.jsxs)("div",{className:(0,V.cn)("flex items-center justify-between px-4 py-2 border-b bg-muted shrink-0 editorial-doc-header",!e9&&e6&&"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:si(eY.name)?(0,t.jsx)(y.default,{className:"h-4 w-4 shrink-0 text-sunshine-700"}):ss(eY.name)?(0,t.jsx)(m.FileText,{className:"h-4 w-4 shrink-0 text-foreground/70"}):(0,t.jsx)(d.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:eY.path,children:eY.path}),tW&&(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)(w,{className:"h-3 w-3 shrink-0"}),(0,t.jsx)("span",{className:"truncate max-w-[100px]",children:tW.author}),(0,t.jsx)("span",{title:new Date(tW.date).toLocaleString(),className:"shrink-0",children:n8(tW.date)})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1 shrink-0",children:[aF(eY),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"File history",onClick:()=>{tV?tZ(!1):ac()},children:(0,t.jsx)(b,{className:"h-3.5 w-3.5"})}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Share",onClick:()=>tc(!0),children:(0,t.jsx)(I,{className:"h-3.5 w-3.5"})}),ss(eY.name)&&!tv&&(null!==td||sr(eY.name))&&(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{tk(!0),tC(td??""),tO(null),sr(eY.name)&&a2.useEditorStore.getState().loadPage(eY.path)},children:(0,t.jsx)(E,{className:"h-3.5 w-3.5"})}),ss(eY.name)&&tv&&sr(eY.name)&&(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Done editing",onClick:()=>{tk(!1),tO(null)},children:(0,t.jsx)(S.Eye,{className:"h-3.5 w-3.5"})}),ss(eY.name)&&!tv&&(null!==td||sr(eY.name))&&(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",title:"Refresh",onClick:ag,disabled:tw,children:tw?(0,t.jsx)(N.Loader2,{className:"h-3.5 w-3.5 animate-spin"}):(0,t.jsx)(O,{className:"h-3.5 w-3.5"})}),aW&&(0,t.jsx)(n4.ViewWidthToggle,{}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>{e0(null),tu(null),tk(!1)},children:(0,t.jsx)(B.X,{className:"h-3.5 w-3.5"})})]})]}),tV&&(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:()=>tZ(!1),children:(0,t.jsx)(B.X,{className:"h-3.5 w-3.5"})})]}),tQ?(0,t.jsx)("div",{className:"flex justify-center py-4",children:(0,t.jsx)(N.Loader2,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):0===tX.length?(0,t.jsx)("p",{className:"px-4 py-3 text-xs text-muted-foreground",children:"No history found."}):(0,t.jsx)("div",{children:tX.map(e=>(0,t.jsxs)("div",{children:[(0,t.jsx)("button",{type:"button",className:(0,V.cn)("w-full text-left px-4 py-2 hover:bg-muted transition-colors",t1===e.sha&&"bg-muted"),onClick:()=>void ad(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:n8(e.date)})]})}),t1===e.sha&&(0,t.jsx)("div",{className:"border-t",children:t4?(0,t.jsx)("div",{className:"flex justify-center py-3",children:(0,t.jsx)(N.Loader2,{className:"h-4 w-4 animate-spin text-muted-foreground"})}):null!==t5?(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:t5}):null})]},e.sha))})]}),a$?(0,t.jsx)(en,{path:eY.path,size:eY.size??0,onOpen:()=>e2(eY.path)}):tv?(0,t.jsx)("div",{className:"flex-1 flex flex-col overflow-hidden min-h-0",children:sr(eY.name)?(0,t.jsx)(Y.KBEditor,{}):(0,t.jsx)("textarea",{value:t_,onChange:e=>tC(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"})}):sr(eY.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)(N.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):(0,t.jsx)(Y.KBEditor,{mode:"viewing"})}):"csv"===az||"pdf"===az||"mermaid"===az||"notebook"===az||"image"===az||"media"===az||"docx"===az||"xlsx"===az||"pptx"===az||"source"===az||"fallback"===az?(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)(N.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):"csv"===az?(0,t.jsx)(Q,{path:eY.path,title:eY.name}):"pdf"===az?(0,t.jsx)(tg,{path:eY.path,title:eY.name}):"mermaid"===az?(0,t.jsx)(ec,{path:eY.path,title:eY.name}):"notebook"===az?(0,t.jsx)(tm,{path:eY.path,title:eY.name}):"image"===az?(0,t.jsx)(es,{path:eY.path,title:eY.name}):"media"===az?(0,t.jsx)(er,{path:eY.path,title:eY.name,type:["mp4","webm","mov","m4v"].includes(st(eY.name))?"video":"audio"}):"docx"===az?(0,t.jsx)(th,{path:eY.path,title:eY.name}):"xlsx"===az?(0,t.jsx)(tf,{path:eY.path,title:eY.name}):"pptx"===az?(0,t.jsx)(tx,{path:eY.path,title:eY.name}):"source"===az?(0,t.jsx)(tN,{path:eY.path,title:eY.name}):(0,t.jsx)(ee,{path:eY.path,title:eY.name})}):(0,t.jsx)("div",{className:"flex-1 overflow-auto p-4 min-h-0",children:(0,t.jsx)("div",{className:(0,V.cn)("w-full",aZ,aV),children:tw?(0,t.jsx)("div",{className:"flex justify-center py-8",children:(0,t.jsx)(N.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):null!==td?(0,t.jsx)("pre",{className:"text-xs font-mono whitespace-pre-wrap break-words leading-relaxed",children:td}):ss(eY.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&&!sr(eY.name)&&(0,t.jsxs)("div",{className:"border-t px-4 py-2 flex items-center justify-end gap-2 bg-muted shrink-0",children:[tD&&(0,t.jsx)("span",{className:"text-xs text-destructive mr-auto",children:tD}),(0,t.jsx)(U.Button,{size:"sm",variant:"ghost",onClick:()=>{tk(!1),tO(null)},children:"Cancel"}),(0,t.jsxs)(U.Button,{size:"sm",className:"gap-1",onClick:a_,disabled:tS,children:[tS&&(0,t.jsx)(N.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)(m.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)(au,{open:to,onOpenChange:tc,filePath:eY?.path??""}),(0,t.jsx)(tY,{open:ti,onOpenChange:tl}),(0,t.jsx)(ne,{currentPath:eY?.path}),(0,t.jsx)("input",{ref:eR,type:"file",multiple:!0,className:"hidden",onChange:e=>{e.target.files&&aC(e.target.files,eF.current)}}),(0,t.jsx)(K,{open:!!eZ,onOpenChange:e=>{e||eX(null)},title:eJ?"Delete folder?":"Delete file?",description:eJ?`"${eZ?.split("/").pop()}" and all its contents will be permanently deleted.`:`"${eZ?.split("/").pop()}" will be permanently removed.`,onConfirm:aL}),(0,t.jsx)(K,{open:!!et,onOpenChange:e=>{e||ea(null)},title:"Delete workspace?",description:`"${q.find(e=>e.id===et)?.name??""}" will be removed from the workspace list. Files on disk are NOT deleted.`,onConfirm:ak})]})]},F??"none")}],952683)}]);
|