Files
archy-demo/demo/aiui/assets/BrowsePage-DDnfUhk3.js
2026-03-17 02:14:04 +00:00

3 lines
8.5 KiB
JavaScript

import{a as M,c as o,F as b,g as E,b as s,e,n as F,t as p,L as g,i as y,r as w,P as B,k as D,K as L,o as T,M as H,Q as z,V as S,W as j}from"./index-BzKy-nNf.js";const V={class:"space-y-0.5"},A=["onClick"],O={key:1,class:"w-3 shrink-0"},I=["d"],R={class:"text-sm truncate"},N={key:0,class:"pl-4 ml-[18px] border-l border-white/5"},W="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z",U="M5 19a2 2 0 01-2-2V7a2 2 0 012-2h4l2 2h4a2 2 0 012 2v1M5 19h14a2 2 0 002-2v-5a2 2 0 00-2-2H9a2 2 0 00-2 2v5a2 2 0 01-2 2z",G="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4",K="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z",X="M7 21h10a2 2 0 002-2V9.414a1 1 0 00-.293-.707l-5.414-5.414A1 1 0 0012.586 3H7a2 2 0 00-2 2v14a2 2 0 002 2z",q=M({__name:"FileTree",props:{items:{}},emits:["selectFile"],setup(m,{emit:_}){const h=w(new Set),v=_;function n(l){if(l.isDirectory){const a=new Set(h.value);a.has(l.path)?a.delete(l.path):a.add(l.path),h.value=a}else v("selectFile",l)}const r=new Set(["ts","tsx","js","jsx","vue","svelte","py","rs","go","java","c","cpp","h","hpp","rb","php","swift","kt","cs","css","scss","less","html","xml","yaml","yml","toml","json","sh","bash","zsh","sql","md","mdx"]),c=new Set(["png","jpg","jpeg","gif","svg","webp","ico","bmp","avif"]);function x(l){return l.split(".").pop()?.toLowerCase()??""}function k(l){if(l.isDirectory)return"text-yellow-500/70";const a=x(l.name);return r.has(a)?"text-blue-400/70":c.has(a)?"text-green-400/70":"text-white/40"}function $(l){if(l.isDirectory)return h.value.has(l.path)?U:W;const a=x(l.name);return r.has(a)?G:c.has(a)?K:X}return(l,a)=>{const C=B("FileTree",!0);return s(),o("div",V,[(s(!0),o(b,null,E(m.items,u=>(s(),o("div",{key:u.path},[e("button",{class:F(["w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-left transition-colors min-h-[32px]",u.isDirectory?"hover:bg-white/5 text-white/70 hover:text-white/80":"hover:bg-white/8 text-white/60 hover:text-white/80"]),onClick:i=>n(u)},[u.isDirectory?(s(),o("svg",{key:0,class:F(["w-3 h-3 text-white/30 shrink-0 transition-transform duration-150",{"rotate-90":h.value.has(u.path)}]),fill:"currentColor",viewBox:"0 0 20 20"},[...a[1]||(a[1]=[e("path",{"fill-rule":"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z","clip-rule":"evenodd"},null,-1)])],2)):(s(),o("span",O)),(s(),o("svg",{class:F(["w-4 h-4 shrink-0",k(u)]),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1.5",d:$(u)},null,8,I)],2)),e("span",R,p(u.name),1)],10,A),u.isDirectory&&u.children?.length&&h.value.has(u.path)?(s(),o("div",N,[g(C,{items:u.children,onSelectFile:a[0]||(a[0]=i=>l.$emit("selectFile",i))},null,8,["items"])])):y("",!0)]))),128))])}}}),Q={class:"h-full flex flex-col"},J={class:"flex items-center justify-between px-4 py-3 border-b border-white/5 shrink-0"},Y={class:"min-w-0 flex-1"},Z={class:"text-sm font-medium text-white/80 truncate"},ee={class:"text-xs text-white/30 truncate mt-0.5"},te={class:"flex items-center gap-2 shrink-0 ml-3"},se={class:"text-xs text-white/25 font-mono"},oe={class:"flex-1 overflow-auto"},ne={class:"text-xs font-mono leading-relaxed w-full"},le={class:"text-white/20 text-right pr-4 pl-4 py-0 select-none align-top whitespace-nowrap sticky left-0 bg-[#0a0a0a]"},ae={class:"text-white/70 pr-4 py-0 whitespace-pre"},P=M({__name:"FilePreview",props:{file:{}},emits:["close"],setup(m){const _=m,h=D(()=>_.file.content.split(`
`));function v(n){return n<1024?`${n} B`:n<1024*1024?`${(n/1024).toFixed(1)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}return(n,r)=>(s(),o("div",Q,[e("div",J,[e("div",Y,[e("p",Z,p(m.file.name),1),e("p",ee,p(m.file.path),1)]),e("div",te,[e("span",se,p(v(m.file.size)),1),e("button",{class:"min-w-[32px] min-h-[32px] flex items-center justify-center rounded-md text-white/40 hover:text-white/70 hover:bg-white/10 transition-colors","aria-label":"Close preview",onClick:r[0]||(r[0]=c=>n.$emit("close"))},[...r[1]||(r[1]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)])])])]),e("div",oe,[e("table",ne,[e("tbody",null,[(s(!0),o(b,null,E(h.value,(c,x)=>(s(),o("tr",{key:x,class:"hover:bg-white/3"},[e("td",le,p(x+1),1),e("td",ae,p(c),1)]))),128))])])])]))}}),ie={class:"h-full flex flex-col bg-[#0a0a0a]"},re={class:"glass shrink-0 px-4 py-3 flex items-center gap-3 border-b border-white/5"},ce={class:"px-4 py-2 flex items-center gap-1 text-xs text-white/40 shrink-0"},ue={class:"text-white/60 min-h-[28px] px-1 flex items-center"},he={class:"flex-1 overflow-hidden flex"},de={class:"flex-1 overflow-y-auto px-2 py-2"},pe={key:0,class:"flex items-center justify-center h-32"},ve={key:1,class:"flex items-center justify-center h-32"},fe={class:"text-sm text-red-400/70"},xe={key:2,class:"space-y-1"},we=["onClick"],me={class:"min-w-0 flex-1"},_e={class:"text-sm text-white/80 truncate group-hover:text-white/90"},ke={class:"text-xs text-white/25 truncate"},ge={key:0,class:"w-[400px] xl:w-[500px] border-l border-white/5 overflow-y-auto shrink-0"},ye={key:0,class:"fixed inset-0 z-50 bg-[#0a0a0a] overflow-y-auto"},Ce=M({__name:"BrowsePage",setup(m){const _=w([]),h=w([]),v=w(!0),n=w(""),r=w(null),c=w(null),x=w(window.innerWidth),k=D(()=>x.value<1024);async function $(){v.value=!0,n.value="";try{const i=await j("/api/fs/list");if(!i.ok)throw new Error(`Failed to load: ${i.status}`);const t=await i.json();_.value=t.projects??[]}catch(i){n.value=i instanceof Error?i.message:"Failed to load projects"}finally{v.value=!1}}async function l(i){r.value=i,c.value=null,v.value=!0,n.value="";try{const t=await j(`/api/fs/tree?path=${encodeURIComponent(i.path)}`);if(!t.ok)throw new Error(`Failed to load: ${t.status}`);const d=await t.json();h.value=d.files??[]}catch(t){n.value=t instanceof Error?t.message:"Failed to load files"}finally{v.value=!1}}function a(){r.value=null,c.value=null,h.value=[]}async function C(i){if(!r.value)return;const t=r.value.path+"/"+i.path;try{const d=await j(`/api/fs/read?path=${encodeURIComponent(t)}`);if(!d.ok){if(d.status===413){n.value="File too large to preview (max 1MB)";return}throw new Error(`Failed to read: ${d.status}`)}const f=await d.json();c.value={name:i.name,path:i.path,content:f.content,size:f.size}}catch(d){n.value=d instanceof Error?d.message:"Failed to read file"}}function u(){x.value=window.innerWidth}return L(()=>{$(),window.addEventListener("resize",u)}),T(()=>{window.removeEventListener("resize",u)}),(i,t)=>{const d=B("router-link");return s(),o("div",ie,[e("header",re,[g(d,{to:"/",class:"min-w-[44px] min-h-[44px] flex items-center justify-center rounded-lg text-white/60 hover:text-white/80 hover:bg-white/10 transition-colors","aria-label":"Back to chat"},{default:H(()=>[...t[2]||(t[2]=[e("svg",{class:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M15 19l-7-7 7-7"})],-1)])]),_:1}),t[3]||(t[3]=e("h1",{class:"text-white/90 text-base font-medium truncate"},"Files",-1))]),e("nav",ce,[e("button",{class:"hover:text-white/70 transition-colors min-h-[28px] px-1",onClick:a}," Projects "),r.value?(s(),o(b,{key:0},[t[4]||(t[4]=e("span",{class:"text-white/20"},"/",-1)),e("span",ue,p(r.value.name),1)],64)):y("",!0)]),e("main",he,[e("div",de,[v.value?(s(),o("div",pe,[...t[5]||(t[5]=[e("span",{class:"text-sm text-white/50"},"Loading...",-1)])])):n.value?(s(),o("div",ve,[e("span",fe,p(n.value),1)])):r.value?(s(),z(q,{key:3,items:h.value,onSelectFile:C},null,8,["items"])):(s(),o("div",xe,[(s(!0),o(b,null,E(_.value,f=>(s(),o("button",{key:f.path,class:"w-full flex items-center gap-3 px-3 py-2.5 rounded-lg text-left hover:bg-white/5 transition-colors group",onClick:be=>l(f)},[t[6]||(t[6]=e("svg",{class:"w-5 h-5 text-white/30 shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1.5",d:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"})],-1)),e("div",me,[e("p",_e,p(f.name),1),e("p",ke,p(f.language),1)])],8,we))),128))]))]),c.value&&!k.value?(s(),o("aside",ge,[g(P,{file:c.value,onClose:t[0]||(t[0]=f=>c.value=null)},null,8,["file"])])):y("",!0)]),(s(),z(S,{to:"body"},[c.value&&k.value?(s(),o("div",ye,[g(P,{file:c.value,onClose:t[1]||(t[1]=f=>c.value=null)},null,8,["file"])])):y("",!0)]))])}}});export{Ce as default};