tide-commander 1.145.0 → 1.146.0
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/CHANGELOG.md +13 -0
- package/dist/assets/{BossLogsModal-DPXsdZ7u.js → BossLogsModal-BR0IXO2N.js} +1 -1
- package/dist/assets/BossSpawnModal-x75-j2da.js +1 -0
- package/dist/assets/{ControlsModal-J62POwmI.js → ControlsModal-DVil4qEv.js} +1 -1
- package/dist/assets/{DockerLogsModal-DZx8OuLO.js → DockerLogsModal-CFREftxm.js} +1 -1
- package/dist/assets/{EmbeddedEditor-BLZrqHph.js → EmbeddedEditor-BB1dXjgA.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-BD-W3VJ9.js → GmailOAuthSetup-Bt4lYIib.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-miugyyJJ.js → GoogleOAuthSetup-D9WbR8pi.js} +1 -1
- package/dist/assets/{IframeModal-uiyVg9VQ.js → IframeModal-VRxo8uW0.js} +1 -1
- package/dist/assets/{IntegrationsPanel-CAt_jjW7.js → IntegrationsPanel-CPGny7vx.js} +2 -2
- package/dist/assets/{LogViewerModal-DHSPYmTn.js → LogViewerModal-bkAbzlbh.js} +1 -1
- package/dist/assets/{MonitoringModal-DJdIFnXI.js → MonitoringModal-CkpuOazc.js} +1 -1
- package/dist/assets/{PM2LogsModal-CA7IDf-Q.js → PM2LogsModal-Cllh-p5p.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-CrgrnJrN.js → RestoreArchivedAreaModal-DLjiody0.js} +1 -1
- package/dist/assets/{Scene2DCanvas-CCKFfv_Q.js → Scene2DCanvas-UxkEcgli.js} +1 -1
- package/dist/assets/{SceneManager-DPogxokC.js → SceneManager-3z1c1ca8.js} +1 -1
- package/dist/assets/{SkillsPanel-BGH4Jzy2.js → SkillsPanel-Opv6_qsA.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-Cde0PF27.js → SlackMultiInstanceSetup-BRBXqcBK.js} +1 -1
- package/dist/assets/SpawnModal-Cgr2So6H.js +1 -0
- package/dist/assets/{StatisticsModal-BWx5rOYA.js → StatisticsModal-CQ9zX_te.js} +1 -1
- package/dist/assets/{SubordinateAssignmentModal-BcACB1Rb.js → SubordinateAssignmentModal-DYl_KFut.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-BQdBJs9X.js → TriggerManagerPanel-DteLW6l2.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-CzM3DxVG.js → WorkflowEditorPanel-C_OQpYuO.js} +1 -1
- package/dist/assets/{area-logos-BHJ2RYkS.js → area-logos-CcA80suT.js} +1 -1
- package/dist/assets/{index-DxcL_hH1.js → index-BMCNBI0L.js} +1 -1
- package/dist/assets/index-CCFfkD_H.js +2 -0
- package/dist/assets/{index-DtuQeAw2.js → index-CIuAGpI4.js} +1 -1
- package/dist/assets/{index-f23AFZac.js → index-ClQaYJNq.js} +1 -1
- package/dist/assets/{index-D0wHZqkk.js → index-CtzZOKXq.js} +1 -1
- package/dist/assets/{index-D_wa-zns.js → index-DQhrNqbn.js} +3 -3
- package/dist/assets/{index-B20Fn_-l.js → index-DhL1siJA.js} +1 -1
- package/dist/assets/{index-DuPDS7BI.js → index-DtUDyvyC.js} +2 -2
- package/dist/assets/{index-C4Xpdvs6.js → index-k4vAPWgE.js} +1 -1
- package/dist/assets/{main-DBurmQCa.js → main-BhpZ8DMy.js} +107 -107
- package/dist/assets/{web-B-nLiUYo.js → web-5BrjMiIU.js} +1 -1
- package/dist/assets/{web-BkDI_Oul.js → web-Cx4v8f8d.js} +1 -1
- package/dist/assets/{web-XTmM7Spb.js → web-DpsRRzsh.js} +1 -1
- package/dist/index.html +1 -1
- package/dist/src/packages/shared/agent-types.js +12 -32
- package/package.json +1 -1
- package/dist/assets/BossSpawnModal-Bn8bGZyF.js +0 -1
- package/dist/assets/SpawnModal-B_1WTo88.js +0 -1
- package/dist/assets/index-BksOQHtD.js +0 -2
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/EmbeddedEditor-
|
|
2
|
-
import{r as t,h as Y,i as V,G as Xt,_ as Js,S as $t,$ as Ys,s as Ve,u as re,j as e,I as R,bW as Ht,f as qs,bX as Xs,bY as Un,bZ as Qs,b_ as Zs,b$ as Bn,c0 as _n,c1 as Pt,c2 as Vn,c3 as Kn,c4 as Wn,c5 as ss,c6 as Jn,c7 as en,c8 as It,c9 as Lt,al as rt,ca as pt,cb as gt,cc as Hs,cd as Yn,bs as qn,ce as ts,cf as Rt,cg as Xn,ch as Qn,ci as Zn,cj as ea,ck as ta,cl as zs,C as sa,o as na}from"./main-DBurmQCa.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function aa(s){const[n,l]=t.useState(null),[c,r]=t.useState(!1),i=t.useCallback(async()=>{if(s){r(!0);try{const h=await Y(V(`/api/files/git-status?path=${encodeURIComponent(s)}`)),o=await h.json();h.ok?l(o):l({isGitRepo:!1,files:[]})}catch(h){console.error("[FileExplorer] Failed to load git status:",h),l({isGitRepo:!1,files:[]})}finally{r(!1)}}},[s]);return{gitStatus:n,loading:c,loadGitStatus:i}}async function ra(s){try{const n=await Y(V(`/api/files/git-original?path=${encodeURIComponent(s)}`)),l=await n.json();return n.ok&&!l.isNew?{content:l.content,isNew:!1}:{content:null,isNew:!0}}catch(n){return console.error("[FileExplorer] Failed to load original file:",n),{content:null,isNew:!0}}}const ia=new Set([".txt",".md",".markdown",".json",".yaml",".yml",".xml",".html",".htm",".css",".scss",".sass",".less",".js",".jsx",".ts",".tsx",".mjs",".cjs",".py",".rb",".c",".cpp",".h",".hpp",".cs",".go",".rs",".swift",".kt",".scala",".clj",".ex",".exs",".erl",".hs",".ml",".fs",".sql",".sh",".bash",".zsh",".fish",".ps1",".bat",".cmd",".toml",".ini",".cfg",".conf",".env",".gitignore",".dockerignore",".editorconfig",".prettierrc",".eslintrc",".babelrc",".log",".csv",".tsv",".svg",""]),la=new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".ico",".svg"]),oa=new Set([".pdf"]),ca=new Set([".xlsx",".xls",".docx",".doc",".pptx",".ppt",".zip",".tar",".gz",".rar",".7z",".exe",".dmg",".app",".deb",".rpm",".apk",".aab",".ipa",".msi",".mp3",".mp4",".wav",".avi",".mov",".mkv",".flac",".ogg",".webm",".ttf",".otf",".woff",".woff2",".eot",".sqlite",".db",".so",".dll",".dylib",".a",".o",".obj",".bin",".dat",".iso",".img",".jar",".war",".ear",".class"]);function da(s){const n=s.toLowerCase();return la.has(n)?"image":oa.has(n)?"pdf":ca.has(n)?"binary":(ia.has(n),"text")}function ua(){const[s,n]=t.useState(null),[l,c]=t.useState(!1),[r,i]=t.useState(null),h=t.useCallback(async d=>{var f,b;c(!0),i(null);try{const p=d.substring(d.lastIndexOf(".")).toLowerCase(),w=da(p),C=d.substring(d.lastIndexOf("/")+1);if(w==="image"){const k=await Y(V(`/api/files/binary?path=${encodeURIComponent(d)}`));if(!k.ok){const N=await k.json().catch(()=>({error:"Failed to load image"}));i(N.error||"Failed to load image"),n(null);return}const y=await k.blob(),v=URL.createObjectURL(y);n({path:d,filename:C,extension:p,content:"",size:y.size,modified:new Date().toISOString(),fileType:"image",dataUrl:v});return}if(w==="pdf"){const k=await Y(V(`/api/files/info?path=${encodeURIComponent(d)}`)),y=await k.json();if(!k.ok){i(y.error||"Failed to load PDF info"),n(null);return}n({path:d,filename:C,extension:p,content:"",size:y.size,modified:y.modified,fileType:"pdf",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(d)}&token=${encodeURIComponent(Xt())}`)});return}if(w==="binary"){const k=await Y(V(`/api/files/info?path=${encodeURIComponent(d)}`)),y=await k.json();if(!k.ok){i(y.error||"Failed to load file info"),n(null);return}n({path:d,filename:C,extension:p,content:"",size:y.size,modified:y.modified,fileType:"binary",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(d)}&download=true&token=${encodeURIComponent(Xt())}`)});return}const P=await Y(V(`/api/files/read?path=${encodeURIComponent(d)}`)),x=await P.json();if(!P.ok){if((f=x.error)!=null&&f.includes("too large")||(b=x.error)!=null&&b.includes("binary")){const k=await Y(V(`/api/files/info?path=${encodeURIComponent(d)}`)),y=await k.json();if(k.ok){n({path:d,filename:C,extension:p,content:"",size:y.size,modified:y.modified,fileType:"binary",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(d)}&download=true&token=${encodeURIComponent(Xt())}`)});return}}i(x.error||"Failed to load file"),n(null);return}n({...x,fileType:"text"})}catch(p){const w=p instanceof Error?p.message:"Failed to load file";i(w),n(null)}finally{c(!1)}},[]),o=t.useCallback(()=>{n(d=>(d!=null&&d.dataUrl&&d.dataUrl.startsWith("blob:")&&URL.revokeObjectURL(d.dataUrl),null)),i(null)},[]);return{file:s,loading:l,error:r,loadFile:h,clearFile:o,setFile:n}}const ha="file-explorer-state",As="file-explorer-recent-projects",ma=10080*60*1e3,fa=12;function Qt(s){return`${ha}-folder-${s}`}async function pa(s){try{const n=await Y(V(`/api/files/exists?path=${encodeURIComponent(s)}`));return n.ok?(await n.json()).exists===!0:!1}catch{return!1}}function ga(){const s=t.useCallback(async r=>{if(!r)return null;try{const i=localStorage.getItem(Qt(r));if(!i)return null;const h=JSON.parse(i);if(Date.now()-h.timestamp>ma)return localStorage.removeItem(Qt(r)),null;const d=(await Promise.all((h.tabs||[]).map(async b=>({tab:b,exists:await pa(b.path)})))).filter(({exists:b})=>b).map(({tab:b})=>b);let f=h.activeTabPath;return f&&!d.some(b=>b.path===f)&&(f=d.length>0?d[0].path:null),{tabs:d,activeTabPath:f,viewMode:h.viewMode||"files",expandedPaths:new Set(h.expandedPaths||[])}}catch(i){return console.error("[FileExplorerStorage] Failed to load project state:",i),null}},[]),n=t.useCallback((r,i)=>{if(r)try{const h={tabs:i.tabs,activeTabPath:i.activeTabPath,viewMode:i.viewMode,expandedPaths:Array.from(i.expandedPaths),timestamp:Date.now()};localStorage.setItem(Qt(r),JSON.stringify(h))}catch(h){console.error("[FileExplorerStorage] Failed to save project state:",h)}},[]),l=t.useCallback(()=>{try{const r=localStorage.getItem(As);if(!r)return[];const i=JSON.parse(r);return Array.isArray(i)?i.filter(h=>typeof h=="string"):[]}catch{return[]}},[]),c=t.useCallback(r=>{if(!r)return l();const i=[r,...l().filter(h=>h!==r)].slice(0,fa);try{localStorage.setItem(As,JSON.stringify(i))}catch{}return i},[l]);return{loadProjectState:s,saveProjectState:n,loadRecentProjects:l,pushRecentProject:c}}const Os=280,Gs=150,Us=1200;function xa(){const[s,n]=t.useState(()=>{const f=Js($t.TREE_PANEL_WIDTH,Os);return f>=Gs&&f<=Us?f:Os}),l=t.useRef(!1),[c,r]=t.useState(!1),i=t.useRef(0),h=t.useRef(0),o=t.useRef(s);o.current=s;const d=t.useCallback(f=>{f.preventDefault(),l.current=!0,r(!0),i.current=f.clientX,h.current=s,document.body.style.cursor="ew-resize",document.body.style.userSelect="none"},[s]);return t.useEffect(()=>{const f=p=>{if(!l.current)return;const w=p.clientX-i.current,C=Math.min(Us,Math.max(Gs,h.current+w));n(C)},b=()=>{l.current&&(l.current=!1,r(!1),document.body.style.cursor="",document.body.style.userSelect="",Ys($t.TREE_PANEL_WIDTH,o.current))};return document.addEventListener("mousemove",f),document.addEventListener("mouseup",b),()=>{document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",b)}},[]),{treePanelWidth:s,handleResizeStart:d,isResizing:c}}const ya=100,ba=.65,ja=36;function va(){const[s,n]=t.useState(()=>Js($t.MOBILE_TREE_PANEL_HEIGHT,0)),l=t.useRef(s);l.current=s;const c=t.useRef(0),r=t.useRef(0),i=()=>Math.floor((window.innerHeight-ja)*ba),h=p=>Math.min(i(),Math.max(ya,p)),o=t.useCallback(p=>{n(p);const w=document.querySelector(".file-explorer-main");w&&w.style.setProperty("--fe-mobile-tree-height",`${p}px`)},[]),d=t.useCallback(()=>{document.body.style.cursor="",document.body.style.userSelect="",Ys($t.MOBILE_TREE_PANEL_HEIGHT,l.current),Ve.setTerminalResizing(!1)},[]),f=t.useCallback(p=>{p.preventDefault();const w=document.querySelector(".file-explorer-tree-panel"),C=l.current>0?l.current:(w==null?void 0:w.getBoundingClientRect().height)??240;c.current=p.clientY,r.current=C,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",Ve.setTerminalResizing(!0);const P=k=>{const y=k.clientY-c.current;o(h(r.current+y))},x=()=>{document.removeEventListener("mousemove",P),document.removeEventListener("mouseup",x),d()};document.addEventListener("mousemove",P),document.addEventListener("mouseup",x)},[o,d]),b=t.useCallback(p=>{if(p.touches.length!==1)return;const w=document.querySelector(".file-explorer-tree-panel"),C=l.current>0?l.current:(w==null?void 0:w.getBoundingClientRect().height)??240;c.current=p.touches[0].clientY,r.current=C,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",Ve.setTerminalResizing(!0);const P=k=>{if(k.touches.length!==1)return;k.preventDefault();const y=k.touches[0].clientY-c.current;o(h(r.current+y))},x=()=>{document.removeEventListener("touchmove",P),document.removeEventListener("touchend",x),document.removeEventListener("touchcancel",x),d()};document.addEventListener("touchmove",P,{passive:!1}),document.addEventListener("touchend",x),document.addEventListener("touchcancel",x)},[o,d]);return{mobileTreeHeight:s,handleResizeMouseDown:f,handleResizeTouchStart:b}}function ns(){const[s,n]=t.useState([]),[l,c]=t.useState(!1),[r,i]=t.useState(null),[h,o]=t.useState(null),d=t.useCallback(async k=>{c(!0),i(null);try{const y=await Y(V(`/api/files/git-branches?path=${encodeURIComponent(k)}`)),v=await y.json();y.ok?n(v.branches||[]):(i(v.error||"Failed to load branches"),n([]))}catch(y){console.error("[GitBranches] Failed to load branches:",y),i("Failed to load branches"),n([])}finally{c(!1)}},[]),f=t.useCallback(async(k,y)=>{o("checkout"),i(null);try{const v=await Y(V("/api/files/git-checkout"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:y})}),N=await v.json();return v.ok||i(N.error||"Checkout failed"),N}catch(v){console.error("[GitBranches] Checkout failed:",v);const N={success:!1,error:"Checkout failed"};return i(N.error),N}finally{o(null)}},[]),b=t.useCallback(async(k,y,v)=>{o("create"),i(null);try{const N=await Y(V("/api/files/git-branch-create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,name:y,startPoint:v})}),D=await N.json();return N.ok||i(D.error||"Failed to create branch"),D}catch(N){console.error("[GitBranches] Create branch failed:",N);const D={success:!1,error:"Failed to create branch"};return i(D.error),D}finally{o(null)}},[]),p=t.useCallback(async k=>{o("pull"),i(null);try{const y=await Y(V("/api/files/git-pull"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await y.json();return!y.ok&&!v.conflicts&&i(v.error||"Pull failed"),v}catch(y){console.error("[GitBranches] Pull failed:",y);const v={success:!1,error:"Pull failed"};return i(v.error),v}finally{o(null)}},[]),w=t.useCallback(async k=>{o("push"),i(null);try{const y=await Y(V("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await y.json();return y.ok||i(v.error||"Push failed"),v}catch(y){console.error("[GitBranches] Push failed:",y);const v={success:!1,error:"Push failed"};return i(v.error),v}finally{o(null)}},[]),C=t.useCallback(async(k,y)=>{o("merge"),i(null);try{const v=await Y(V("/api/files/git-merge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:y})}),N=await v.json();return!v.ok&&!N.conflicts&&i(N.error||"Merge failed"),N}catch(v){console.error("[GitBranches] Merge failed:",v);const N={success:!1,error:"Merge failed"};return i(N.error),N}finally{o(null)}},[]),P=t.useCallback(async k=>{o("merge-abort"),i(null);try{const y=await Y(V("/api/files/git-merge-abort"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await y.json();return y.ok||i(v.error||"Merge abort failed"),v}catch(y){console.error("[GitBranches] Merge abort failed:",y);const v={success:!1,error:"Merge abort failed"};return i(v.error),v}finally{o(null)}},[]),x=t.useCallback(async k=>{o("merge-continue"),i(null);try{const y=await Y(V("/api/files/git-merge-continue"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await y.json();return y.ok||i(v.error||"Merge continue failed"),v}catch(y){console.error("[GitBranches] Merge continue failed:",y);const v={success:!1,error:"Merge continue failed"};return i(v.error),v}finally{o(null)}},[]);return{branches:s,loading:l,error:r,operationInProgress:h,loadBranches:d,checkoutBranch:f,createBranch:b,pullFromRemote:p,pushToRemote:w,mergeBranch:C,mergeAbort:P,mergeContinue:x}}const wa=50,Ca=400,Bs={branch:"",author:"",since:"",until:"",searchPath:"",search:""};function Na(){const[s,n]=t.useState([]),[l,c]=t.useState(!1),[r,i]=t.useState(!1),[h,o]=t.useState(null),[d,f]=t.useState(!1),[b,p]=t.useState(0),[w,C]=t.useState({...Bs}),[P,x]=t.useState(null),[k,y]=t.useState([]),[v,N]=t.useState(!1),[D,j]=t.useState([]),[A,G]=t.useState(!1),H=t.useRef(null),ne=t.useRef(""),Z=t.useCallback((O,W,T)=>{const J=T||w,z=new URLSearchParams;return z.set("path",O),z.set("limit",String(wa)),z.set("offset",String(W)),J.branch&&z.set("branch",J.branch),J.author&&z.set("author",J.author),J.since&&z.set("since",J.since),J.until&&z.set("until",J.until),J.searchPath&&z.set("searchPath",J.searchPath),J.search&&z.set("search",J.search),z.toString()},[w]),M=t.useCallback(async O=>{ne.current=O,c(!0),o(null),x(null),y([]);try{const W=Z(O,0),T=await Y(V(`/api/files/git-log?${W}`)),J=await T.json();T.ok?(n(J.commits||[]),p(J.total||0),f(J.hasMore||!1)):(o(J.error||"Failed to load git history"),n([]))}catch(W){console.error("[useGitHistory] loadHistory error:",W),o("Failed to load git history"),n([])}finally{c(!1)}},[Z]),I=t.useCallback(async O=>{if(!(r||!d)){i(!0);try{const W=Z(O,s.length),T=await Y(V(`/api/files/git-log?${W}`)),J=await T.json();T.ok&&(n(z=>[...z,...J.commits||[]]),p(J.total||0),f(J.hasMore||!1))}catch(W){console.error("[useGitHistory] loadMore error:",W)}finally{i(!1)}}},[Z,s.length,d,r]),K=t.useCallback(async O=>{if(x(O),!O){y([]);return}N(!0);try{const W=ne.current,T=new URLSearchParams({path:W,hash:O.hash}),J=await Y(V(`/api/files/git-commit-files?${T}`)),z=await J.json();J.ok?y(z.files||[]):y([])}catch(W){console.error("[useGitHistory] selectCommit files error:",W),y([])}finally{N(!1)}},[]),ae=t.useCallback((O,W)=>{C(T=>({...T,[O]:W}))},[]),ie=t.useCallback(()=>{C({...Bs})},[]);t.useEffect(()=>{const O=ne.current;if(O)return H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{M(O)},Ca),()=>{H.current&&clearTimeout(H.current)}},[w]);const fe=t.useCallback(async O=>{G(!0);try{const W=new URLSearchParams({path:O}),T=await Y(V(`/api/files/git-authors?${W}`)),J=await T.json();T.ok&&j(J.authors||[])}catch(W){console.error("[useGitHistory] loadAuthors error:",W)}finally{G(!1)}},[]);return{commits:s,loading:l,loadingMore:r,error:h,hasMore:d,total:b,filters:w,setFilter:ae,resetFilters:ie,selectedCommit:P,selectCommit:K,commitFiles:k,commitFilesLoading:v,loadHistory:M,loadMore:I,authors:D,authorsLoading:A,loadAuthors:fe}}function ka(s){if(!s.current)return null;const n=[".file-viewer-code-with-lines",".file-viewer-markdown-wrapper",".file-viewer-code-wrapper",".file-viewer-diagram-wrapper",".file-viewer-image-wrapper",".file-viewer-pdf-wrapper"];for(const l of n){const c=s.current.querySelector(l);if(c&&_s(c))return c}return _s(s.current)?s.current:null}function _s(s){const n=["auto","scroll"].includes(getComputedStyle(s).overflowY),l=s.scrollHeight>s.clientHeight||s.scrollWidth>s.clientWidth;return n&&l}function tn(s){if(!s)return 19.5;const n=parseFloat(getComputedStyle(s).lineHeight);return isNaN(n)?19.5:n}function Zt(s,n=!0){const l=n?s.scrollHeight:0;s.scrollTo({top:l,behavior:"smooth"})}function Ea(s){const{scrollTop:n,scrollHeight:l,clientHeight:c}=s;return l<=c?100:Math.round(n/(l-c)*100)}function Sa(s,n){const l=tn(s),c=s.scrollTop,r=Math.floor(c/l)+1,i=n.split(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/EmbeddedEditor-BB1dXjgA.js","assets/main-BhpZ8DMy.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-Chj50gSY.js","assets/main-ijcbyjBn.css","assets/EmbeddedEditor-O_u2UVA4.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as t,h as Y,i as V,G as Xt,_ as Js,S as $t,$ as Ys,s as Ve,u as re,j as e,I as R,bW as Ht,f as qs,bX as Xs,bY as Un,bZ as Qs,b_ as Zs,b$ as Bn,c0 as _n,c1 as Pt,c2 as Vn,c3 as Kn,c4 as Wn,c5 as ss,c6 as Jn,c7 as en,c8 as It,c9 as Lt,al as rt,ca as pt,cb as gt,cc as Hs,cd as Yn,bs as qn,ce as ts,cf as Rt,cg as Xn,ch as Qn,ci as Zn,cj as ea,ck as ta,cl as zs,C as sa,o as na}from"./main-BhpZ8DMy.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function aa(s){const[n,l]=t.useState(null),[c,r]=t.useState(!1),i=t.useCallback(async()=>{if(s){r(!0);try{const h=await Y(V(`/api/files/git-status?path=${encodeURIComponent(s)}`)),o=await h.json();h.ok?l(o):l({isGitRepo:!1,files:[]})}catch(h){console.error("[FileExplorer] Failed to load git status:",h),l({isGitRepo:!1,files:[]})}finally{r(!1)}}},[s]);return{gitStatus:n,loading:c,loadGitStatus:i}}async function ra(s){try{const n=await Y(V(`/api/files/git-original?path=${encodeURIComponent(s)}`)),l=await n.json();return n.ok&&!l.isNew?{content:l.content,isNew:!1}:{content:null,isNew:!0}}catch(n){return console.error("[FileExplorer] Failed to load original file:",n),{content:null,isNew:!0}}}const ia=new Set([".txt",".md",".markdown",".json",".yaml",".yml",".xml",".html",".htm",".css",".scss",".sass",".less",".js",".jsx",".ts",".tsx",".mjs",".cjs",".py",".rb",".c",".cpp",".h",".hpp",".cs",".go",".rs",".swift",".kt",".scala",".clj",".ex",".exs",".erl",".hs",".ml",".fs",".sql",".sh",".bash",".zsh",".fish",".ps1",".bat",".cmd",".toml",".ini",".cfg",".conf",".env",".gitignore",".dockerignore",".editorconfig",".prettierrc",".eslintrc",".babelrc",".log",".csv",".tsv",".svg",""]),la=new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".ico",".svg"]),oa=new Set([".pdf"]),ca=new Set([".xlsx",".xls",".docx",".doc",".pptx",".ppt",".zip",".tar",".gz",".rar",".7z",".exe",".dmg",".app",".deb",".rpm",".apk",".aab",".ipa",".msi",".mp3",".mp4",".wav",".avi",".mov",".mkv",".flac",".ogg",".webm",".ttf",".otf",".woff",".woff2",".eot",".sqlite",".db",".so",".dll",".dylib",".a",".o",".obj",".bin",".dat",".iso",".img",".jar",".war",".ear",".class"]);function da(s){const n=s.toLowerCase();return la.has(n)?"image":oa.has(n)?"pdf":ca.has(n)?"binary":(ia.has(n),"text")}function ua(){const[s,n]=t.useState(null),[l,c]=t.useState(!1),[r,i]=t.useState(null),h=t.useCallback(async d=>{var f,b;c(!0),i(null);try{const p=d.substring(d.lastIndexOf(".")).toLowerCase(),w=da(p),C=d.substring(d.lastIndexOf("/")+1);if(w==="image"){const k=await Y(V(`/api/files/binary?path=${encodeURIComponent(d)}`));if(!k.ok){const N=await k.json().catch(()=>({error:"Failed to load image"}));i(N.error||"Failed to load image"),n(null);return}const y=await k.blob(),v=URL.createObjectURL(y);n({path:d,filename:C,extension:p,content:"",size:y.size,modified:new Date().toISOString(),fileType:"image",dataUrl:v});return}if(w==="pdf"){const k=await Y(V(`/api/files/info?path=${encodeURIComponent(d)}`)),y=await k.json();if(!k.ok){i(y.error||"Failed to load PDF info"),n(null);return}n({path:d,filename:C,extension:p,content:"",size:y.size,modified:y.modified,fileType:"pdf",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(d)}&token=${encodeURIComponent(Xt())}`)});return}if(w==="binary"){const k=await Y(V(`/api/files/info?path=${encodeURIComponent(d)}`)),y=await k.json();if(!k.ok){i(y.error||"Failed to load file info"),n(null);return}n({path:d,filename:C,extension:p,content:"",size:y.size,modified:y.modified,fileType:"binary",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(d)}&download=true&token=${encodeURIComponent(Xt())}`)});return}const P=await Y(V(`/api/files/read?path=${encodeURIComponent(d)}`)),x=await P.json();if(!P.ok){if((f=x.error)!=null&&f.includes("too large")||(b=x.error)!=null&&b.includes("binary")){const k=await Y(V(`/api/files/info?path=${encodeURIComponent(d)}`)),y=await k.json();if(k.ok){n({path:d,filename:C,extension:p,content:"",size:y.size,modified:y.modified,fileType:"binary",dataUrl:V(`/api/files/binary?path=${encodeURIComponent(d)}&download=true&token=${encodeURIComponent(Xt())}`)});return}}i(x.error||"Failed to load file"),n(null);return}n({...x,fileType:"text"})}catch(p){const w=p instanceof Error?p.message:"Failed to load file";i(w),n(null)}finally{c(!1)}},[]),o=t.useCallback(()=>{n(d=>(d!=null&&d.dataUrl&&d.dataUrl.startsWith("blob:")&&URL.revokeObjectURL(d.dataUrl),null)),i(null)},[]);return{file:s,loading:l,error:r,loadFile:h,clearFile:o,setFile:n}}const ha="file-explorer-state",As="file-explorer-recent-projects",ma=10080*60*1e3,fa=12;function Qt(s){return`${ha}-folder-${s}`}async function pa(s){try{const n=await Y(V(`/api/files/exists?path=${encodeURIComponent(s)}`));return n.ok?(await n.json()).exists===!0:!1}catch{return!1}}function ga(){const s=t.useCallback(async r=>{if(!r)return null;try{const i=localStorage.getItem(Qt(r));if(!i)return null;const h=JSON.parse(i);if(Date.now()-h.timestamp>ma)return localStorage.removeItem(Qt(r)),null;const d=(await Promise.all((h.tabs||[]).map(async b=>({tab:b,exists:await pa(b.path)})))).filter(({exists:b})=>b).map(({tab:b})=>b);let f=h.activeTabPath;return f&&!d.some(b=>b.path===f)&&(f=d.length>0?d[0].path:null),{tabs:d,activeTabPath:f,viewMode:h.viewMode||"files",expandedPaths:new Set(h.expandedPaths||[])}}catch(i){return console.error("[FileExplorerStorage] Failed to load project state:",i),null}},[]),n=t.useCallback((r,i)=>{if(r)try{const h={tabs:i.tabs,activeTabPath:i.activeTabPath,viewMode:i.viewMode,expandedPaths:Array.from(i.expandedPaths),timestamp:Date.now()};localStorage.setItem(Qt(r),JSON.stringify(h))}catch(h){console.error("[FileExplorerStorage] Failed to save project state:",h)}},[]),l=t.useCallback(()=>{try{const r=localStorage.getItem(As);if(!r)return[];const i=JSON.parse(r);return Array.isArray(i)?i.filter(h=>typeof h=="string"):[]}catch{return[]}},[]),c=t.useCallback(r=>{if(!r)return l();const i=[r,...l().filter(h=>h!==r)].slice(0,fa);try{localStorage.setItem(As,JSON.stringify(i))}catch{}return i},[l]);return{loadProjectState:s,saveProjectState:n,loadRecentProjects:l,pushRecentProject:c}}const Os=280,Gs=150,Us=1200;function xa(){const[s,n]=t.useState(()=>{const f=Js($t.TREE_PANEL_WIDTH,Os);return f>=Gs&&f<=Us?f:Os}),l=t.useRef(!1),[c,r]=t.useState(!1),i=t.useRef(0),h=t.useRef(0),o=t.useRef(s);o.current=s;const d=t.useCallback(f=>{f.preventDefault(),l.current=!0,r(!0),i.current=f.clientX,h.current=s,document.body.style.cursor="ew-resize",document.body.style.userSelect="none"},[s]);return t.useEffect(()=>{const f=p=>{if(!l.current)return;const w=p.clientX-i.current,C=Math.min(Us,Math.max(Gs,h.current+w));n(C)},b=()=>{l.current&&(l.current=!1,r(!1),document.body.style.cursor="",document.body.style.userSelect="",Ys($t.TREE_PANEL_WIDTH,o.current))};return document.addEventListener("mousemove",f),document.addEventListener("mouseup",b),()=>{document.removeEventListener("mousemove",f),document.removeEventListener("mouseup",b)}},[]),{treePanelWidth:s,handleResizeStart:d,isResizing:c}}const ya=100,ba=.65,ja=36;function va(){const[s,n]=t.useState(()=>Js($t.MOBILE_TREE_PANEL_HEIGHT,0)),l=t.useRef(s);l.current=s;const c=t.useRef(0),r=t.useRef(0),i=()=>Math.floor((window.innerHeight-ja)*ba),h=p=>Math.min(i(),Math.max(ya,p)),o=t.useCallback(p=>{n(p);const w=document.querySelector(".file-explorer-main");w&&w.style.setProperty("--fe-mobile-tree-height",`${p}px`)},[]),d=t.useCallback(()=>{document.body.style.cursor="",document.body.style.userSelect="",Ys($t.MOBILE_TREE_PANEL_HEIGHT,l.current),Ve.setTerminalResizing(!1)},[]),f=t.useCallback(p=>{p.preventDefault();const w=document.querySelector(".file-explorer-tree-panel"),C=l.current>0?l.current:(w==null?void 0:w.getBoundingClientRect().height)??240;c.current=p.clientY,r.current=C,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",Ve.setTerminalResizing(!0);const P=k=>{const y=k.clientY-c.current;o(h(r.current+y))},x=()=>{document.removeEventListener("mousemove",P),document.removeEventListener("mouseup",x),d()};document.addEventListener("mousemove",P),document.addEventListener("mouseup",x)},[o,d]),b=t.useCallback(p=>{if(p.touches.length!==1)return;const w=document.querySelector(".file-explorer-tree-panel"),C=l.current>0?l.current:(w==null?void 0:w.getBoundingClientRect().height)??240;c.current=p.touches[0].clientY,r.current=C,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",Ve.setTerminalResizing(!0);const P=k=>{if(k.touches.length!==1)return;k.preventDefault();const y=k.touches[0].clientY-c.current;o(h(r.current+y))},x=()=>{document.removeEventListener("touchmove",P),document.removeEventListener("touchend",x),document.removeEventListener("touchcancel",x),d()};document.addEventListener("touchmove",P,{passive:!1}),document.addEventListener("touchend",x),document.addEventListener("touchcancel",x)},[o,d]);return{mobileTreeHeight:s,handleResizeMouseDown:f,handleResizeTouchStart:b}}function ns(){const[s,n]=t.useState([]),[l,c]=t.useState(!1),[r,i]=t.useState(null),[h,o]=t.useState(null),d=t.useCallback(async k=>{c(!0),i(null);try{const y=await Y(V(`/api/files/git-branches?path=${encodeURIComponent(k)}`)),v=await y.json();y.ok?n(v.branches||[]):(i(v.error||"Failed to load branches"),n([]))}catch(y){console.error("[GitBranches] Failed to load branches:",y),i("Failed to load branches"),n([])}finally{c(!1)}},[]),f=t.useCallback(async(k,y)=>{o("checkout"),i(null);try{const v=await Y(V("/api/files/git-checkout"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:y})}),N=await v.json();return v.ok||i(N.error||"Checkout failed"),N}catch(v){console.error("[GitBranches] Checkout failed:",v);const N={success:!1,error:"Checkout failed"};return i(N.error),N}finally{o(null)}},[]),b=t.useCallback(async(k,y,v)=>{o("create"),i(null);try{const N=await Y(V("/api/files/git-branch-create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,name:y,startPoint:v})}),D=await N.json();return N.ok||i(D.error||"Failed to create branch"),D}catch(N){console.error("[GitBranches] Create branch failed:",N);const D={success:!1,error:"Failed to create branch"};return i(D.error),D}finally{o(null)}},[]),p=t.useCallback(async k=>{o("pull"),i(null);try{const y=await Y(V("/api/files/git-pull"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await y.json();return!y.ok&&!v.conflicts&&i(v.error||"Pull failed"),v}catch(y){console.error("[GitBranches] Pull failed:",y);const v={success:!1,error:"Pull failed"};return i(v.error),v}finally{o(null)}},[]),w=t.useCallback(async k=>{o("push"),i(null);try{const y=await Y(V("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await y.json();return y.ok||i(v.error||"Push failed"),v}catch(y){console.error("[GitBranches] Push failed:",y);const v={success:!1,error:"Push failed"};return i(v.error),v}finally{o(null)}},[]),C=t.useCallback(async(k,y)=>{o("merge"),i(null);try{const v=await Y(V("/api/files/git-merge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k,branch:y})}),N=await v.json();return!v.ok&&!N.conflicts&&i(N.error||"Merge failed"),N}catch(v){console.error("[GitBranches] Merge failed:",v);const N={success:!1,error:"Merge failed"};return i(N.error),N}finally{o(null)}},[]),P=t.useCallback(async k=>{o("merge-abort"),i(null);try{const y=await Y(V("/api/files/git-merge-abort"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await y.json();return y.ok||i(v.error||"Merge abort failed"),v}catch(y){console.error("[GitBranches] Merge abort failed:",y);const v={success:!1,error:"Merge abort failed"};return i(v.error),v}finally{o(null)}},[]),x=t.useCallback(async k=>{o("merge-continue"),i(null);try{const y=await Y(V("/api/files/git-merge-continue"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:k})}),v=await y.json();return y.ok||i(v.error||"Merge continue failed"),v}catch(y){console.error("[GitBranches] Merge continue failed:",y);const v={success:!1,error:"Merge continue failed"};return i(v.error),v}finally{o(null)}},[]);return{branches:s,loading:l,error:r,operationInProgress:h,loadBranches:d,checkoutBranch:f,createBranch:b,pullFromRemote:p,pushToRemote:w,mergeBranch:C,mergeAbort:P,mergeContinue:x}}const wa=50,Ca=400,Bs={branch:"",author:"",since:"",until:"",searchPath:"",search:""};function Na(){const[s,n]=t.useState([]),[l,c]=t.useState(!1),[r,i]=t.useState(!1),[h,o]=t.useState(null),[d,f]=t.useState(!1),[b,p]=t.useState(0),[w,C]=t.useState({...Bs}),[P,x]=t.useState(null),[k,y]=t.useState([]),[v,N]=t.useState(!1),[D,j]=t.useState([]),[A,G]=t.useState(!1),H=t.useRef(null),ne=t.useRef(""),Z=t.useCallback((O,W,T)=>{const J=T||w,z=new URLSearchParams;return z.set("path",O),z.set("limit",String(wa)),z.set("offset",String(W)),J.branch&&z.set("branch",J.branch),J.author&&z.set("author",J.author),J.since&&z.set("since",J.since),J.until&&z.set("until",J.until),J.searchPath&&z.set("searchPath",J.searchPath),J.search&&z.set("search",J.search),z.toString()},[w]),M=t.useCallback(async O=>{ne.current=O,c(!0),o(null),x(null),y([]);try{const W=Z(O,0),T=await Y(V(`/api/files/git-log?${W}`)),J=await T.json();T.ok?(n(J.commits||[]),p(J.total||0),f(J.hasMore||!1)):(o(J.error||"Failed to load git history"),n([]))}catch(W){console.error("[useGitHistory] loadHistory error:",W),o("Failed to load git history"),n([])}finally{c(!1)}},[Z]),I=t.useCallback(async O=>{if(!(r||!d)){i(!0);try{const W=Z(O,s.length),T=await Y(V(`/api/files/git-log?${W}`)),J=await T.json();T.ok&&(n(z=>[...z,...J.commits||[]]),p(J.total||0),f(J.hasMore||!1))}catch(W){console.error("[useGitHistory] loadMore error:",W)}finally{i(!1)}}},[Z,s.length,d,r]),K=t.useCallback(async O=>{if(x(O),!O){y([]);return}N(!0);try{const W=ne.current,T=new URLSearchParams({path:W,hash:O.hash}),J=await Y(V(`/api/files/git-commit-files?${T}`)),z=await J.json();J.ok?y(z.files||[]):y([])}catch(W){console.error("[useGitHistory] selectCommit files error:",W),y([])}finally{N(!1)}},[]),ae=t.useCallback((O,W)=>{C(T=>({...T,[O]:W}))},[]),ie=t.useCallback(()=>{C({...Bs})},[]);t.useEffect(()=>{const O=ne.current;if(O)return H.current&&clearTimeout(H.current),H.current=setTimeout(()=>{M(O)},Ca),()=>{H.current&&clearTimeout(H.current)}},[w]);const fe=t.useCallback(async O=>{G(!0);try{const W=new URLSearchParams({path:O}),T=await Y(V(`/api/files/git-authors?${W}`)),J=await T.json();T.ok&&j(J.authors||[])}catch(W){console.error("[useGitHistory] loadAuthors error:",W)}finally{G(!1)}},[]);return{commits:s,loading:l,loadingMore:r,error:h,hasMore:d,total:b,filters:w,setFilter:ae,resetFilters:ie,selectedCommit:P,selectCommit:K,commitFiles:k,commitFilesLoading:v,loadHistory:M,loadMore:I,authors:D,authorsLoading:A,loadAuthors:fe}}function ka(s){if(!s.current)return null;const n=[".file-viewer-code-with-lines",".file-viewer-markdown-wrapper",".file-viewer-code-wrapper",".file-viewer-diagram-wrapper",".file-viewer-image-wrapper",".file-viewer-pdf-wrapper"];for(const l of n){const c=s.current.querySelector(l);if(c&&_s(c))return c}return _s(s.current)?s.current:null}function _s(s){const n=["auto","scroll"].includes(getComputedStyle(s).overflowY),l=s.scrollHeight>s.clientHeight||s.scrollWidth>s.clientWidth;return n&&l}function tn(s){if(!s)return 19.5;const n=parseFloat(getComputedStyle(s).lineHeight);return isNaN(n)?19.5:n}function Zt(s,n=!0){const l=n?s.scrollHeight:0;s.scrollTo({top:l,behavior:"smooth"})}function Ea(s){const{scrollTop:n,scrollHeight:l,clientHeight:c}=s;return l<=c?100:Math.round(n/(l-c)*100)}function Sa(s,n){const l=tn(s),c=s.scrollTop,r=Math.floor(c/l)+1,i=n.split(`
|
|
3
3
|
`).length;return Math.min(r,i)}function Ta(s,n,l=!1){if(!n)return[];l||s.toLowerCase();const c=l?n:n.toLowerCase(),r=[];let i=0;const h=s.split(`
|
|
4
4
|
`);let o=0;for(let d=0;d<h.length;d++){const f=h[d],b=l?f:f.toLowerCase();let p=0,w=b.indexOf(c);for(;w!==-1;){const C=o+w;r.push({index:i++,line:d+1,column:w,length:c.length,charIndex:C}),p=w+c.length,w=b.indexOf(c,p)}o+=f.length+1}return r}function it(s){return/[\w]/.test(s)}function Ke(s){return/\s/.test(s)}function Ma(s,n,l){let c=n-1,r=l;const i=s.length,h=s[c]||"";if(r<h.length){const f=it(h[r]);if(!Ke(h[r]))for(;r<h.length&&!Ke(h[r])&&it(h[r])===f;)r++}for(;c<i;){const f=s[c]||"";for(;r<f.length&&Ke(f[r]);)r++;if(r<f.length)return{line:c+1,col:r};c++,r=0}const o=i,d=Math.max(0,(s[i-1]||"").length-1);return{line:o,col:d}}function Da(s,n,l){let c=n-1,r=l+1;const i=s.length;for(;c<i;){const d=s[c]||"";for(;r<d.length&&Ke(d[r]);)r++;if(r<d.length)break;c++,r=0}if(c>=i)return{line:i,col:Math.max(0,(s[i-1]||"").length-1)};const h=s[c]||"",o=it(h[r]);for(;r+1<h.length&&!Ke(h[r+1])&&it(h[r+1])===o;)r++;return{line:c+1,col:r}}function Ra(s,n,l){let c=n-1,r=l-1;for(;c>=0;){const o=s[c]||"";for(;r>=0&&Ke(o[r]);)r--;if(r>=0)break;c--,c>=0&&(r=(s[c]||"").length-1)}if(c<0)return{line:1,col:0};const i=s[c]||"",h=it(i[r]);for(;r>0&&!Ke(i[r-1])&&it(i[r-1])===h;)r--;return{line:c+1,col:r}}function Fa(s,n,l,c){if(c==="none")return"";const{anchorLine:r,anchorCol:i,headLine:h,headCol:o}=l;if(c==="line"){const C=Math.min(r,h),P=Math.max(r,h);return n.slice(C-1,P).join(`
|
|
5
5
|
`)}let d,f,b,p;if(r<h||r===h&&i<=o?(d=r,f=i,b=h,p=o):(d=h,f=o,b=r,p=i),d===b)return(n[d-1]||"").substring(f,p+1);const w=[];w.push((n[d-1]||"").substring(f));for(let C=d;C<b-1;C++)w.push(n[C]||"");return w.push((n[b-1]||"").substring(0,p+1)),w.join(`
|
|
6
6
|
`)}function sn(s){const{containerRef:n,isEnabled:l=!0,content:c="",onClose:r,onSearchOpen:i}=s,h=t.useRef({percentage:0,line:1,column:1}),o=t.useRef(null),d=t.useRef(19.5),f=t.useMemo(()=>c.split(`
|
|
7
|
-
`),[c]),b=f.length,[p,w]=t.useState(1),[C,P]=t.useState(0),[x,k]=t.useState(!1),[y,v]=t.useState("none"),[N,D]=t.useState(null),[j,A]=t.useState(!1),[G,H]=t.useState(""),[ne,Z]=t.useState(0),[M,I]=t.useState(!1),K=t.useMemo(()=>Ta(c,G,!1),[c,G]),ae=t.useCallback(()=>{const m=o.current;if(!m)return;const F=Ea(m),Q=Sa(m,c),_=Math.max(1,Math.round(m.scrollLeft/7.8)+1);h.current={percentage:F,line:Q,column:_}},[c]),ie=t.useCallback(()=>{A(!0),H(""),Z(0),i==null||i()},[i]),fe=t.useCallback(()=>{A(!1),H(""),Z(0)},[]),O=t.useCallback(()=>{I(m=>!m)},[]),W=t.useCallback(m=>{const F=o.current;if(!F)return;const Q=F.querySelector(".file-viewer-pre"),de=Q&&parseFloat(getComputedStyle(Q).lineHeight)||d.current,_=Q&&parseFloat(getComputedStyle(Q).paddingTop)||0,U=(Q?Q.offsetTop:0)+_+(m-1)*de,te=de*3;F.scrollTo({top:Math.max(0,U-te),behavior:"smooth"})},[]);t.useEffect(()=>{!j||K.length===0||Z(0)},[K,j]),t.useEffect(()=>{if(!j||K.length===0)return;const m=K[ne];m&&(w(m.line),P(m.column),W(m.line))},[j,K,ne,W]);const T=t.useCallback(()=>{K.length!==0&&Z(m=>(m+1)%K.length)},[K]),J=t.useCallback(()=>{K.length!==0&&Z(m=>(m-1+K.length)%K.length)},[K]),z=t.useCallback(m=>{const F=o.current;if(!F)return;const Q=F.querySelector(".file-viewer-pre");if(!Q)return;const de=parseFloat(getComputedStyle(Q).lineHeight),_=isNaN(de)?d.current:de,S=parseFloat(getComputedStyle(Q).paddingTop)||0,te=Q.offsetTop+S+(m-1)*_,Te=te+_,Ce=F.scrollTop,ee=Ce+F.clientHeight;te<Ce?F.scrollTo({top:Math.max(0,te),behavior:"auto"}):Te>ee&&F.scrollTo({top:Te-F.clientHeight,behavior:"auto"})},[]),se=t.useCallback((m,F)=>{w(m),P(F),z(m),y!=="none"&&D(Q=>Q?{...Q,headLine:m,headCol:F}:null)},[y,z]),xe=t.useCallback(()=>{if(y==="none"||!N)return;const m=Fa(c,f,N,y);m&&navigator.clipboard.writeText(m).catch(()=>{const F=document.createElement("textarea");F.value=m,F.style.position="fixed",F.style.left="-9999px",document.body.appendChild(F),F.select(),document.execCommand("copy"),document.body.removeChild(F)}),v("none"),D(null)},[y,N,c,f]),ye=t.useCallback(m=>{const F=m.target;if((F.tagName==="INPUT"||F.tagName==="TEXTAREA")&&m.key!=="Escape")return;const de=o.current;if(!de)return;let _=!1;const S=d.current,U=Math.max(1,Math.floor(de.clientHeight/S)),te=Math.max(1,Math.floor(U/2)),Te=(ee,pe)=>{const Ge=Math.max(0,(f[ee-1]||"").length-1);return Math.min(pe,Math.max(0,Ge))},Ce=(ee,pe)=>{const Ge=Te(ee,pe);se(ee,Ge)};if(m.key==="v"&&!m.shiftKey&&!m.ctrlKey&&!j)m.preventDefault(),m.stopPropagation(),y==="char"?(v("none"),D(null)):(v("char"),D({anchorLine:p,anchorCol:C,headLine:p,headCol:C})),_=!0;else if(m.key==="V"&&m.shiftKey&&!m.ctrlKey&&!j)m.preventDefault(),m.stopPropagation(),y==="line"?(v("none"),D(null)):(v("line"),D({anchorLine:p,anchorCol:0,headLine:p,headCol:0})),_=!0;else if(m.key==="y"&&!m.ctrlKey&&y!=="none")m.preventDefault(),m.stopPropagation(),xe(),_=!0;else if(m.key==="j"||m.key==="ArrowDown"){m.preventDefault(),m.stopPropagation();const ee=Math.min(p+1,b);Ce(ee,C),_=!0}else if(m.key==="k"||m.key==="ArrowUp"){m.preventDefault(),m.stopPropagation();const ee=Math.max(p-1,1);Ce(ee,C),_=!0}else if(m.key==="d"&&m.ctrlKey||m.key==="d"&&y==="none"&&!j){m.preventDefault(),m.stopPropagation();const ee=Math.min(p+te,b);Ce(ee,C),_=!0}else if(m.key==="u"&&m.ctrlKey||m.key==="u"&&y==="none"&&!j){m.preventDefault(),m.stopPropagation();const ee=Math.max(p-te,1);Ce(ee,C),_=!0}else if((m.ctrlKey||m.metaKey)&&m.key==="f")m.preventDefault(),m.stopPropagation(),ie(),_=!0;else if(m.key==="f"&&!m.ctrlKey&&!m.metaKey&&y==="none"&&!j){m.preventDefault(),m.stopPropagation();const ee=Math.min(p+U,b);Ce(ee,C),_=!0}else if(m.key===" "||m.key==="PageDown"){m.preventDefault(),m.stopPropagation();const ee=Math.min(p+U,b);Ce(ee,C),_=!0}else if(m.key==="b"&&!x&&y==="none"&&!j||m.key==="PageUp"){m.preventDefault(),m.stopPropagation();const ee=Math.max(p-U,1);Ce(ee,C),_=!0}else if(m.key==="g"&&!m.shiftKey&&y==="none"&&!j)m.preventDefault(),m.stopPropagation(),se(1,0),Zt(de,!1),_=!0;else if(m.key==="Home")m.preventDefault(),m.stopPropagation(),se(1,0),Zt(de,!1),_=!0;else if(m.key==="G"&&m.shiftKey||m.key==="End")m.preventDefault(),m.stopPropagation(),se(b,0),Zt(de,!0),_=!0;else if(m.key==="h"||m.key==="ArrowLeft")m.preventDefault(),m.stopPropagation(),se(p,Math.max(0,C-1)),_=!0;else if(m.key==="l"||m.key==="ArrowRight"){m.preventDefault(),m.stopPropagation();const ee=(f[p-1]||"").length;se(p,Math.min(C+1,Math.max(0,ee-1))),_=!0}else if(m.key==="w"&&!m.ctrlKey&&!j){m.preventDefault(),m.stopPropagation();const ee=Ma(f,p,C);se(ee.line,ee.col),_=!0}else if(m.key==="e"&&!m.ctrlKey&&!j){m.preventDefault(),m.stopPropagation();const ee=Da(f,p,C);se(ee.line,ee.col),_=!0}else if(m.key==="b"&&!j){m.preventDefault(),m.stopPropagation();const ee=Ra(f,p,C);se(ee.line,ee.col),_=!0}else if(m.key==="0")m.preventDefault(),m.stopPropagation(),se(p,0),_=!0;else if(m.key==="$")m.preventDefault(),m.stopPropagation(),se(p,Math.max(0,(f[p-1]||"").length-1)),_=!0;else if(m.key==="^"){m.preventDefault(),m.stopPropagation();const pe=(f[p-1]||"").search(/\S/);se(p,pe>=0?pe:0),_=!0}else m.key==="/"?(m.preventDefault(),m.stopPropagation(),ie(),_=!0):m.key==="n"&&!j?(m.preventDefault(),m.stopPropagation(),T(),_=!0):m.key==="N"&&m.shiftKey&&!j?(m.preventDefault(),m.stopPropagation(),J(),_=!0):m.key==="?"&&y==="none"?(m.preventDefault(),m.stopPropagation(),O(),_=!0):m.key==="q"&&y==="none"?(m.preventDefault(),m.stopPropagation(),r==null||r(),_=!0):m.key==="Escape"&&(y!=="none"?(m.preventDefault(),m.stopPropagation(),v("none"),D(null),_=!0):j?(m.preventDefault(),m.stopPropagation(),fe(),_=!0):x&&(m.preventDefault(),m.stopPropagation(),k(!1),_=!0));_&&(m.key!=="Escape"&&!x&&k(!0),requestAnimationFrame(ae))},[r,ae,b,f,p,C,z,j,fe,y,x,se,xe,ie,T,J,O]);return t.useEffect(()=>{if(!l)return;const m=ka(n);if(o.current=m,!m){console.warn("[useLessNavigation] Could not find scrollable container");return}d.current=tn(m);const F=()=>{ae()};return window.addEventListener("keydown",ye,{capture:!0}),m.addEventListener("scroll",F,{passive:!0}),ae(),()=>{window.removeEventListener("keydown",ye,{capture:!0}),m.removeEventListener("scroll",F)}},[l,ye,ae]),{scrollPercentage:h.current.percentage,currentLine:h.current.line,currentColumn:h.current.column,totalLines:b,cursorLine:p,cursorCol:C,cursorModeActive:x,visualMode:y,selection:N,searchActive:j,searchQuery:G,searchMatches:K,currentMatchIndex:ne,startSearch:ie,setSearchQuery:H,nextMatch:T,prevMatch:J,clearSearch:fe,helpActive:M,toggleHelp:O}}const as=({query:s,onQueryChange:n,matchCount:l,currentIndex:c,onNext:r,onPrev:i,onClose:h})=>{const{t:o}=re(["terminal"]),d=t.useRef(null);t.useEffect(()=>{var p;(p=d.current)==null||p.focus()},[]);const f=t.useCallback(p=>{p.stopPropagation(),p.key==="Enter"||p.key==="ArrowDown"?(p.preventDefault(),r()):p.key==="ArrowUp"&&(p.preventDefault(),i())},[r,i]),b=l===0&&s?o("terminal:fileExplorer.noMatches"):l>0?`${c+1}/${l}`:"";return e.jsxs("div",{className:"file-viewer-search-bar",children:[e.jsxs("div",{className:"file-viewer-search-input-wrapper",children:[e.jsx("span",{className:"file-viewer-search-prefix",children:"/"}),e.jsx("input",{ref:d,type:"text",className:"file-viewer-search-input",placeholder:o("terminal:fileExplorer.searchInFile"),value:s,onChange:p=>n(p.target.value),onKeyDown:f,autoComplete:"off",spellCheck:"false"})]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"file-viewer-search-counter",children:b}),e.jsxs("div",{className:"file-viewer-search-nav",children:[e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-prev",onClick:i,disabled:l===0,title:o("terminal:fileExplorer.previousMatch"),"aria-label":o("terminal:fileExplorer.previousMatch"),children:e.jsx(R,{name:"caret-up",size:10})}),e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-next",onClick:r,disabled:l===0,title:o("terminal:fileExplorer.nextMatch"),"aria-label":o("terminal:fileExplorer.nextMatch"),children:e.jsx(R,{name:"caret-down",size:10})})]})]}),e.jsx("button",{className:"file-viewer-search-close",onClick:h,title:o("terminal:fileExplorer.closeSearch"),"aria-label":o("terminal:fileExplorer.closeSearch"),children:e.jsx(R,{name:"close",size:12})})]})};as.displayName="SearchBar";const Pa=[{keys:["j","↓"],description:"Move cursor down one line",category:"Navigation"},{keys:["k","↑"],description:"Move cursor up one line",category:"Navigation"},{keys:["h","←"],description:"Move cursor left",category:"Navigation"},{keys:["l","→"],description:"Move cursor right",category:"Navigation"},{keys:["0"],description:"Jump to start of line",category:"Navigation"},{keys:["$"],description:"Jump to end of line",category:"Navigation"},{keys:["^"],description:"First non-whitespace char",category:"Navigation"},{keys:["d","Ctrl+D"],description:"Half page down",category:"Navigation"},{keys:["u","Ctrl+U"],description:"Half page up",category:"Navigation"},{keys:["f","Space"],description:"Full page down",category:"Navigation"},{keys:["b","Page Up"],description:"Full page up",category:"Navigation"},{keys:["g","Home"],description:"Jump to top of file",category:"Navigation"},{keys:["G","End"],description:"Jump to bottom of file",category:"Navigation"},{keys:["w"],description:"Next word start",category:"Word Motion"},{keys:["e"],description:"Next word end",category:"Word Motion"},{keys:["b"],description:"Previous word start",category:"Word Motion"},{keys:["v"],description:"Character visual mode",category:"Visual Mode"},{keys:["V"],description:"Line visual mode",category:"Visual Mode"},{keys:["y"],description:"Yank (copy) selection",category:"Visual Mode"},{keys:["Escape"],description:"Exit visual mode",category:"Visual Mode"},{keys:["/"],description:"Open search bar",category:"Search"},{keys:["n"],description:"Next match",category:"Search"},{keys:["N"],description:"Previous match",category:"Search"},{keys:["?"],description:"Toggle this help overlay",category:"Help"},{keys:["Escape"],description:"Exit cursor mode (or visual/search)",category:"Help"},{keys:["Alt+E"],description:"Close file viewer",category:"Help"},{keys:["q"],description:"Close file viewer",category:"Help"}],rs=({onClose:s})=>{const{t:n}=re(["terminal"]),l=t.useCallback(i=>{i.target===i.currentTarget&&s()},[s]),c=t.useCallback(i=>{(i.key==="Escape"||i.key==="?")&&(i.preventDefault(),i.stopPropagation(),s())},[s]),r=Pa.reduce((i,h)=>(i[h.category]||(i[h.category]=[]),i[h.category].push(h),i),{});return e.jsx("div",{className:"keybindings-help-overlay",onClick:l,onKeyDown:c,tabIndex:0,role:"dialog","aria-label":n("terminal:fileExplorer.keybindingsHelp"),children:e.jsxs("div",{className:"keybindings-help-content",children:[e.jsx("button",{className:"keybindings-help-close",onClick:s,"aria-label":n("terminal:fileExplorer.closeHelp"),title:n("terminal:fileExplorer.pressEscapeToClose"),children:e.jsx(R,{name:"close",size:14})}),e.jsx("h2",{className:"keybindings-help-title",children:n("terminal:fileExplorer.keybindingsHelp")}),e.jsx("p",{className:"keybindings-help-subtitle",children:n("terminal:fileExplorer.keybindingsSubtitle")}),e.jsx("div",{className:"keybindings-help-categories",children:Object.entries(r).map(([i,h])=>e.jsxs("div",{className:"keybindings-help-category",children:[e.jsx("h3",{className:"keybindings-help-category-title",children:i}),e.jsx("div",{className:"keybindings-help-list",children:h.map((o,d)=>e.jsxs("div",{className:"keybindings-help-item",children:[e.jsx("div",{className:"keybindings-help-keys",children:o.keys.map((f,b)=>e.jsx("kbd",{className:"keybindings-help-key",children:f},b))}),e.jsx("div",{className:"keybindings-help-description",children:o.description})]},d))})]},i))}),e.jsx("p",{className:"keybindings-help-footer",children:n("terminal:fileExplorer.keybindingsFooter")})]})})};rs.displayName="KeybindingsHelp";const Vs=t.lazy(()=>Un(()=>import("./EmbeddedEditor-BLZrqHph.js"),__vite__mapDeps([0,1,2,3,4,5])).then(s=>({default:s.EmbeddedEditor}))),Ia=[".md",".mdx",".markdown"],Ks="file-viewer-markdown-render",La=[".puml",".plantuml",".iuml",".pu"],Ws="file-viewer-plantuml-render",$a="https://kroki.io/plantuml/svg";function Ha(s){return Ia.includes(s.toLowerCase())}function za(s){return La.includes(s.toLowerCase())}function Aa(){const[s,n]=t.useState(()=>{try{const c=localStorage.getItem(Ks);return c===null?!0:c==="true"}catch{return!0}}),l=t.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(Ks,String(r))}catch{}return r})},[]);return[s,l]}function Oa(){const[s,n]=t.useState(()=>{try{const c=localStorage.getItem(Ws);return c===null?!0:c==="true"}catch{return!0}}),l=t.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(Ws,String(r))}catch{}return r})},[]);return[s,l]}function Ga(s){const n=new TextEncoder().encode(s);let l="";for(const c of n)l+=String.fromCharCode(c);return`data:image/svg+xml;base64,${window.btoa(l)}`}function We({file:s,rightContent:n,onRevealInTree:l,editMode:c,onToggleEdit:r}){const{t:i}=re(["terminal","common"]),[h,o]=t.useState("idle"),[d,f]=t.useState("idle"),[b,p]=t.useState("idle"),w=s.fileType==="text"?Ht(s.extension):s.extension.slice(1).toUpperCase(),C=s.fileType==="text"&&s.content!=null,{settings:P}=qs(),x=async()=>{try{await Pt(s.content),p("copied"),setTimeout(()=>p("idle"),2e3)}catch{p("error"),setTimeout(()=>p("idle"),2e3)}},k=()=>{const D=new Blob([s.content],{type:"text/plain;charset=utf-8"}),j=URL.createObjectURL(D),A=document.createElement("a");A.href=j,A.download=s.filename,document.body.appendChild(A),A.click(),A.remove(),setTimeout(()=>URL.revokeObjectURL(j),1e3)},y=async()=>{o("loading");try{const D=await Y(V("/api/files/open-in-editor"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:s.path,...P.externalEditorCommand&&{editorCommand:P.externalEditorCommand}})});if(!D.ok){const j=await D.json().catch(()=>({error:"Unknown error"}));console.error("Failed to open in editor:",j),o("error"),setTimeout(()=>o("idle"),2e3);return}o("success"),setTimeout(()=>o("idle"),2e3)}catch(D){console.error("Error opening file in editor:",D),o("error"),setTimeout(()=>o("idle"),2e3)}},v=async()=>{if(s.path)try{await Wn(s.path),f("success"),setTimeout(()=>f("idle"),2e3)}catch(D){console.error("Error opening file explorer:",D),f("error"),setTimeout(()=>f("idle"),2e3)}},N=i("terminal:fileExplorer.openInFileExplorer");return e.jsxs("div",{className:"file-viewer-header",children:[e.jsxs("div",{className:"file-viewer-header-left",children:[e.jsx("span",{className:"file-viewer-filename",children:s.filename}),e.jsxs("span",{className:"file-viewer-meta",children:[Xs(s.size)," • ",w,s.content&&` • ${s.content.split(`
|
|
7
|
+
`),[c]),b=f.length,[p,w]=t.useState(1),[C,P]=t.useState(0),[x,k]=t.useState(!1),[y,v]=t.useState("none"),[N,D]=t.useState(null),[j,A]=t.useState(!1),[G,H]=t.useState(""),[ne,Z]=t.useState(0),[M,I]=t.useState(!1),K=t.useMemo(()=>Ta(c,G,!1),[c,G]),ae=t.useCallback(()=>{const m=o.current;if(!m)return;const F=Ea(m),Q=Sa(m,c),_=Math.max(1,Math.round(m.scrollLeft/7.8)+1);h.current={percentage:F,line:Q,column:_}},[c]),ie=t.useCallback(()=>{A(!0),H(""),Z(0),i==null||i()},[i]),fe=t.useCallback(()=>{A(!1),H(""),Z(0)},[]),O=t.useCallback(()=>{I(m=>!m)},[]),W=t.useCallback(m=>{const F=o.current;if(!F)return;const Q=F.querySelector(".file-viewer-pre"),de=Q&&parseFloat(getComputedStyle(Q).lineHeight)||d.current,_=Q&&parseFloat(getComputedStyle(Q).paddingTop)||0,U=(Q?Q.offsetTop:0)+_+(m-1)*de,te=de*3;F.scrollTo({top:Math.max(0,U-te),behavior:"smooth"})},[]);t.useEffect(()=>{!j||K.length===0||Z(0)},[K,j]),t.useEffect(()=>{if(!j||K.length===0)return;const m=K[ne];m&&(w(m.line),P(m.column),W(m.line))},[j,K,ne,W]);const T=t.useCallback(()=>{K.length!==0&&Z(m=>(m+1)%K.length)},[K]),J=t.useCallback(()=>{K.length!==0&&Z(m=>(m-1+K.length)%K.length)},[K]),z=t.useCallback(m=>{const F=o.current;if(!F)return;const Q=F.querySelector(".file-viewer-pre");if(!Q)return;const de=parseFloat(getComputedStyle(Q).lineHeight),_=isNaN(de)?d.current:de,S=parseFloat(getComputedStyle(Q).paddingTop)||0,te=Q.offsetTop+S+(m-1)*_,Te=te+_,Ce=F.scrollTop,ee=Ce+F.clientHeight;te<Ce?F.scrollTo({top:Math.max(0,te),behavior:"auto"}):Te>ee&&F.scrollTo({top:Te-F.clientHeight,behavior:"auto"})},[]),se=t.useCallback((m,F)=>{w(m),P(F),z(m),y!=="none"&&D(Q=>Q?{...Q,headLine:m,headCol:F}:null)},[y,z]),xe=t.useCallback(()=>{if(y==="none"||!N)return;const m=Fa(c,f,N,y);m&&navigator.clipboard.writeText(m).catch(()=>{const F=document.createElement("textarea");F.value=m,F.style.position="fixed",F.style.left="-9999px",document.body.appendChild(F),F.select(),document.execCommand("copy"),document.body.removeChild(F)}),v("none"),D(null)},[y,N,c,f]),ye=t.useCallback(m=>{const F=m.target;if((F.tagName==="INPUT"||F.tagName==="TEXTAREA")&&m.key!=="Escape")return;const de=o.current;if(!de)return;let _=!1;const S=d.current,U=Math.max(1,Math.floor(de.clientHeight/S)),te=Math.max(1,Math.floor(U/2)),Te=(ee,pe)=>{const Ge=Math.max(0,(f[ee-1]||"").length-1);return Math.min(pe,Math.max(0,Ge))},Ce=(ee,pe)=>{const Ge=Te(ee,pe);se(ee,Ge)};if(m.key==="v"&&!m.shiftKey&&!m.ctrlKey&&!j)m.preventDefault(),m.stopPropagation(),y==="char"?(v("none"),D(null)):(v("char"),D({anchorLine:p,anchorCol:C,headLine:p,headCol:C})),_=!0;else if(m.key==="V"&&m.shiftKey&&!m.ctrlKey&&!j)m.preventDefault(),m.stopPropagation(),y==="line"?(v("none"),D(null)):(v("line"),D({anchorLine:p,anchorCol:0,headLine:p,headCol:0})),_=!0;else if(m.key==="y"&&!m.ctrlKey&&y!=="none")m.preventDefault(),m.stopPropagation(),xe(),_=!0;else if(m.key==="j"||m.key==="ArrowDown"){m.preventDefault(),m.stopPropagation();const ee=Math.min(p+1,b);Ce(ee,C),_=!0}else if(m.key==="k"||m.key==="ArrowUp"){m.preventDefault(),m.stopPropagation();const ee=Math.max(p-1,1);Ce(ee,C),_=!0}else if(m.key==="d"&&m.ctrlKey||m.key==="d"&&y==="none"&&!j){m.preventDefault(),m.stopPropagation();const ee=Math.min(p+te,b);Ce(ee,C),_=!0}else if(m.key==="u"&&m.ctrlKey||m.key==="u"&&y==="none"&&!j){m.preventDefault(),m.stopPropagation();const ee=Math.max(p-te,1);Ce(ee,C),_=!0}else if((m.ctrlKey||m.metaKey)&&m.key==="f")m.preventDefault(),m.stopPropagation(),ie(),_=!0;else if(m.key==="f"&&!m.ctrlKey&&!m.metaKey&&y==="none"&&!j){m.preventDefault(),m.stopPropagation();const ee=Math.min(p+U,b);Ce(ee,C),_=!0}else if(m.key===" "||m.key==="PageDown"){m.preventDefault(),m.stopPropagation();const ee=Math.min(p+U,b);Ce(ee,C),_=!0}else if(m.key==="b"&&!x&&y==="none"&&!j||m.key==="PageUp"){m.preventDefault(),m.stopPropagation();const ee=Math.max(p-U,1);Ce(ee,C),_=!0}else if(m.key==="g"&&!m.shiftKey&&y==="none"&&!j)m.preventDefault(),m.stopPropagation(),se(1,0),Zt(de,!1),_=!0;else if(m.key==="Home")m.preventDefault(),m.stopPropagation(),se(1,0),Zt(de,!1),_=!0;else if(m.key==="G"&&m.shiftKey||m.key==="End")m.preventDefault(),m.stopPropagation(),se(b,0),Zt(de,!0),_=!0;else if(m.key==="h"||m.key==="ArrowLeft")m.preventDefault(),m.stopPropagation(),se(p,Math.max(0,C-1)),_=!0;else if(m.key==="l"||m.key==="ArrowRight"){m.preventDefault(),m.stopPropagation();const ee=(f[p-1]||"").length;se(p,Math.min(C+1,Math.max(0,ee-1))),_=!0}else if(m.key==="w"&&!m.ctrlKey&&!j){m.preventDefault(),m.stopPropagation();const ee=Ma(f,p,C);se(ee.line,ee.col),_=!0}else if(m.key==="e"&&!m.ctrlKey&&!j){m.preventDefault(),m.stopPropagation();const ee=Da(f,p,C);se(ee.line,ee.col),_=!0}else if(m.key==="b"&&!j){m.preventDefault(),m.stopPropagation();const ee=Ra(f,p,C);se(ee.line,ee.col),_=!0}else if(m.key==="0")m.preventDefault(),m.stopPropagation(),se(p,0),_=!0;else if(m.key==="$")m.preventDefault(),m.stopPropagation(),se(p,Math.max(0,(f[p-1]||"").length-1)),_=!0;else if(m.key==="^"){m.preventDefault(),m.stopPropagation();const pe=(f[p-1]||"").search(/\S/);se(p,pe>=0?pe:0),_=!0}else m.key==="/"?(m.preventDefault(),m.stopPropagation(),ie(),_=!0):m.key==="n"&&!j?(m.preventDefault(),m.stopPropagation(),T(),_=!0):m.key==="N"&&m.shiftKey&&!j?(m.preventDefault(),m.stopPropagation(),J(),_=!0):m.key==="?"&&y==="none"?(m.preventDefault(),m.stopPropagation(),O(),_=!0):m.key==="q"&&y==="none"?(m.preventDefault(),m.stopPropagation(),r==null||r(),_=!0):m.key==="Escape"&&(y!=="none"?(m.preventDefault(),m.stopPropagation(),v("none"),D(null),_=!0):j?(m.preventDefault(),m.stopPropagation(),fe(),_=!0):x&&(m.preventDefault(),m.stopPropagation(),k(!1),_=!0));_&&(m.key!=="Escape"&&!x&&k(!0),requestAnimationFrame(ae))},[r,ae,b,f,p,C,z,j,fe,y,x,se,xe,ie,T,J,O]);return t.useEffect(()=>{if(!l)return;const m=ka(n);if(o.current=m,!m){console.warn("[useLessNavigation] Could not find scrollable container");return}d.current=tn(m);const F=()=>{ae()};return window.addEventListener("keydown",ye,{capture:!0}),m.addEventListener("scroll",F,{passive:!0}),ae(),()=>{window.removeEventListener("keydown",ye,{capture:!0}),m.removeEventListener("scroll",F)}},[l,ye,ae]),{scrollPercentage:h.current.percentage,currentLine:h.current.line,currentColumn:h.current.column,totalLines:b,cursorLine:p,cursorCol:C,cursorModeActive:x,visualMode:y,selection:N,searchActive:j,searchQuery:G,searchMatches:K,currentMatchIndex:ne,startSearch:ie,setSearchQuery:H,nextMatch:T,prevMatch:J,clearSearch:fe,helpActive:M,toggleHelp:O}}const as=({query:s,onQueryChange:n,matchCount:l,currentIndex:c,onNext:r,onPrev:i,onClose:h})=>{const{t:o}=re(["terminal"]),d=t.useRef(null);t.useEffect(()=>{var p;(p=d.current)==null||p.focus()},[]);const f=t.useCallback(p=>{p.stopPropagation(),p.key==="Enter"||p.key==="ArrowDown"?(p.preventDefault(),r()):p.key==="ArrowUp"&&(p.preventDefault(),i())},[r,i]),b=l===0&&s?o("terminal:fileExplorer.noMatches"):l>0?`${c+1}/${l}`:"";return e.jsxs("div",{className:"file-viewer-search-bar",children:[e.jsxs("div",{className:"file-viewer-search-input-wrapper",children:[e.jsx("span",{className:"file-viewer-search-prefix",children:"/"}),e.jsx("input",{ref:d,type:"text",className:"file-viewer-search-input",placeholder:o("terminal:fileExplorer.searchInFile"),value:s,onChange:p=>n(p.target.value),onKeyDown:f,autoComplete:"off",spellCheck:"false"})]}),s&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"file-viewer-search-counter",children:b}),e.jsxs("div",{className:"file-viewer-search-nav",children:[e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-prev",onClick:i,disabled:l===0,title:o("terminal:fileExplorer.previousMatch"),"aria-label":o("terminal:fileExplorer.previousMatch"),children:e.jsx(R,{name:"caret-up",size:10})}),e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-next",onClick:r,disabled:l===0,title:o("terminal:fileExplorer.nextMatch"),"aria-label":o("terminal:fileExplorer.nextMatch"),children:e.jsx(R,{name:"caret-down",size:10})})]})]}),e.jsx("button",{className:"file-viewer-search-close",onClick:h,title:o("terminal:fileExplorer.closeSearch"),"aria-label":o("terminal:fileExplorer.closeSearch"),children:e.jsx(R,{name:"close",size:12})})]})};as.displayName="SearchBar";const Pa=[{keys:["j","↓"],description:"Move cursor down one line",category:"Navigation"},{keys:["k","↑"],description:"Move cursor up one line",category:"Navigation"},{keys:["h","←"],description:"Move cursor left",category:"Navigation"},{keys:["l","→"],description:"Move cursor right",category:"Navigation"},{keys:["0"],description:"Jump to start of line",category:"Navigation"},{keys:["$"],description:"Jump to end of line",category:"Navigation"},{keys:["^"],description:"First non-whitespace char",category:"Navigation"},{keys:["d","Ctrl+D"],description:"Half page down",category:"Navigation"},{keys:["u","Ctrl+U"],description:"Half page up",category:"Navigation"},{keys:["f","Space"],description:"Full page down",category:"Navigation"},{keys:["b","Page Up"],description:"Full page up",category:"Navigation"},{keys:["g","Home"],description:"Jump to top of file",category:"Navigation"},{keys:["G","End"],description:"Jump to bottom of file",category:"Navigation"},{keys:["w"],description:"Next word start",category:"Word Motion"},{keys:["e"],description:"Next word end",category:"Word Motion"},{keys:["b"],description:"Previous word start",category:"Word Motion"},{keys:["v"],description:"Character visual mode",category:"Visual Mode"},{keys:["V"],description:"Line visual mode",category:"Visual Mode"},{keys:["y"],description:"Yank (copy) selection",category:"Visual Mode"},{keys:["Escape"],description:"Exit visual mode",category:"Visual Mode"},{keys:["/"],description:"Open search bar",category:"Search"},{keys:["n"],description:"Next match",category:"Search"},{keys:["N"],description:"Previous match",category:"Search"},{keys:["?"],description:"Toggle this help overlay",category:"Help"},{keys:["Escape"],description:"Exit cursor mode (or visual/search)",category:"Help"},{keys:["Alt+E"],description:"Close file viewer",category:"Help"},{keys:["q"],description:"Close file viewer",category:"Help"}],rs=({onClose:s})=>{const{t:n}=re(["terminal"]),l=t.useCallback(i=>{i.target===i.currentTarget&&s()},[s]),c=t.useCallback(i=>{(i.key==="Escape"||i.key==="?")&&(i.preventDefault(),i.stopPropagation(),s())},[s]),r=Pa.reduce((i,h)=>(i[h.category]||(i[h.category]=[]),i[h.category].push(h),i),{});return e.jsx("div",{className:"keybindings-help-overlay",onClick:l,onKeyDown:c,tabIndex:0,role:"dialog","aria-label":n("terminal:fileExplorer.keybindingsHelp"),children:e.jsxs("div",{className:"keybindings-help-content",children:[e.jsx("button",{className:"keybindings-help-close",onClick:s,"aria-label":n("terminal:fileExplorer.closeHelp"),title:n("terminal:fileExplorer.pressEscapeToClose"),children:e.jsx(R,{name:"close",size:14})}),e.jsx("h2",{className:"keybindings-help-title",children:n("terminal:fileExplorer.keybindingsHelp")}),e.jsx("p",{className:"keybindings-help-subtitle",children:n("terminal:fileExplorer.keybindingsSubtitle")}),e.jsx("div",{className:"keybindings-help-categories",children:Object.entries(r).map(([i,h])=>e.jsxs("div",{className:"keybindings-help-category",children:[e.jsx("h3",{className:"keybindings-help-category-title",children:i}),e.jsx("div",{className:"keybindings-help-list",children:h.map((o,d)=>e.jsxs("div",{className:"keybindings-help-item",children:[e.jsx("div",{className:"keybindings-help-keys",children:o.keys.map((f,b)=>e.jsx("kbd",{className:"keybindings-help-key",children:f},b))}),e.jsx("div",{className:"keybindings-help-description",children:o.description})]},d))})]},i))}),e.jsx("p",{className:"keybindings-help-footer",children:n("terminal:fileExplorer.keybindingsFooter")})]})})};rs.displayName="KeybindingsHelp";const Vs=t.lazy(()=>Un(()=>import("./EmbeddedEditor-BB1dXjgA.js"),__vite__mapDeps([0,1,2,3,4,5])).then(s=>({default:s.EmbeddedEditor}))),Ia=[".md",".mdx",".markdown"],Ks="file-viewer-markdown-render",La=[".puml",".plantuml",".iuml",".pu"],Ws="file-viewer-plantuml-render",$a="https://kroki.io/plantuml/svg";function Ha(s){return Ia.includes(s.toLowerCase())}function za(s){return La.includes(s.toLowerCase())}function Aa(){const[s,n]=t.useState(()=>{try{const c=localStorage.getItem(Ks);return c===null?!0:c==="true"}catch{return!0}}),l=t.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(Ks,String(r))}catch{}return r})},[]);return[s,l]}function Oa(){const[s,n]=t.useState(()=>{try{const c=localStorage.getItem(Ws);return c===null?!0:c==="true"}catch{return!0}}),l=t.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(Ws,String(r))}catch{}return r})},[]);return[s,l]}function Ga(s){const n=new TextEncoder().encode(s);let l="";for(const c of n)l+=String.fromCharCode(c);return`data:image/svg+xml;base64,${window.btoa(l)}`}function We({file:s,rightContent:n,onRevealInTree:l,editMode:c,onToggleEdit:r}){const{t:i}=re(["terminal","common"]),[h,o]=t.useState("idle"),[d,f]=t.useState("idle"),[b,p]=t.useState("idle"),w=s.fileType==="text"?Ht(s.extension):s.extension.slice(1).toUpperCase(),C=s.fileType==="text"&&s.content!=null,{settings:P}=qs(),x=async()=>{try{await Pt(s.content),p("copied"),setTimeout(()=>p("idle"),2e3)}catch{p("error"),setTimeout(()=>p("idle"),2e3)}},k=()=>{const D=new Blob([s.content],{type:"text/plain;charset=utf-8"}),j=URL.createObjectURL(D),A=document.createElement("a");A.href=j,A.download=s.filename,document.body.appendChild(A),A.click(),A.remove(),setTimeout(()=>URL.revokeObjectURL(j),1e3)},y=async()=>{o("loading");try{const D=await Y(V("/api/files/open-in-editor"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:s.path,...P.externalEditorCommand&&{editorCommand:P.externalEditorCommand}})});if(!D.ok){const j=await D.json().catch(()=>({error:"Unknown error"}));console.error("Failed to open in editor:",j),o("error"),setTimeout(()=>o("idle"),2e3);return}o("success"),setTimeout(()=>o("idle"),2e3)}catch(D){console.error("Error opening file in editor:",D),o("error"),setTimeout(()=>o("idle"),2e3)}},v=async()=>{if(s.path)try{await Wn(s.path),f("success"),setTimeout(()=>f("idle"),2e3)}catch(D){console.error("Error opening file explorer:",D),f("error"),setTimeout(()=>f("idle"),2e3)}},N=i("terminal:fileExplorer.openInFileExplorer");return e.jsxs("div",{className:"file-viewer-header",children:[e.jsxs("div",{className:"file-viewer-header-left",children:[e.jsx("span",{className:"file-viewer-filename",children:s.filename}),e.jsxs("span",{className:"file-viewer-meta",children:[Xs(s.size)," • ",w,s.content&&` • ${s.content.split(`
|
|
8
8
|
`).length} lines`]})]}),e.jsxs("div",{className:"file-viewer-header-right",children:[r&&s.fileType==="text"&&e.jsx("button",{className:`file-viewer-edit-btn${c?" active":""}`,onClick:r,title:i(c?"terminal:fileExplorer.exitEdit":"terminal:fileExplorer.editFile"),children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M11.013 1.427a1.75 1.75 0 012.474 0l1.086 1.086a1.75 1.75 0 010 2.474l-8.61 8.61c-.21.21-.47.364-.756.445l-3.251.93a.75.75 0 01-.927-.928l.929-3.25a1.75 1.75 0 01.445-.758l8.61-8.61zm1.414 1.06a.25.25 0 00-.354 0L3.463 11.1a.25.25 0 00-.064.108l-.558 1.953 1.953-.558a.25.25 0 00.108-.064l8.61-8.61a.25.25 0 000-.354l-1.086-1.086z"})})}),C&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`file-viewer-copy-html-btn ${b}`,onClick:x,title:i("terminal:fileExplorer.copyAllTitle"),children:i(b==="copied"?"terminal:fileExplorer.copied":b==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyAll")}),e.jsx("button",{className:"file-viewer-download-btn",onClick:k,title:i("terminal:fileExplorer.downloadFileTitle"),children:i("common:buttons.download")})]}),e.jsx("button",{className:`file-viewer-reveal-explorer-btn ${d}`,onClick:v,disabled:!s.path,title:N,"aria-label":N,children:d==="success"?e.jsx(R,{name:"check",size:14}):d==="error"?e.jsx(R,{name:"cross",size:14}):e.jsx(R,{name:"folder-open",size:14})}),e.jsx("button",{className:`file-viewer-open-editor-btn ${h}`,onClick:y,disabled:h==="loading",title:i(h==="error"?"terminal:fileExplorer.failedToOpenEditor":h==="success"?"terminal:fileExplorer.openingInEditor":"terminal:fileExplorer.openInEditor"),children:h==="success"?e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M13.78 4.22a.75.75 0 010 1.06l-7.25 7.25a.75.75 0 11-1.06-1.06l7.25-7.25a.75.75 0 011.06 0z"})}):h==="error"?e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M3.72 3.72a.75.75 0 011.06 0L8 6.94l3.22-3.22a.75.75 0 111.06 1.06L9.06 8l3.22 3.22a.75.75 0 11-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 01-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 010-1.06z"})}):e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M1.5 1h6v1.5h-5v11h11v-5H15v6.5H0V1h1.5zm8 0H15v5.5h-1.5V3.56L7.28 9.78l-1.06-1.06L12.44 2.5H9.5V1z"})})}),l&&e.jsx("button",{className:"file-viewer-locate-btn",onClick:()=>l(s.path),title:i("terminal:fileExplorer.locateInTree"),children:e.jsx(R,{name:"target",size:14})}),n]})]})}function Ua({file:s,onRevealInTree:n,renderMarkdown:l,onToggleRender:c,editMode:r,onToggleEdit:i}){const h=t.useRef(null),o=t.useRef(null),d=t.useRef(null),{t:f}=re(["terminal","common"]),[b,p]=t.useState("idle"),[w,C]=t.useState("idle"),[P,x]=t.useState("idle"),[k,y]=t.useState("idle"),v=sn({containerRef:d,isEnabled:!0,content:s.content});t.useEffect(()=>{if(!l&&h.current){const H=Ht(s.extension);Qs(H).then(()=>{h.current&&Zs(h.current)})}},[s,l]);const N=t.useCallback(async()=>{if(!o.current){p("error"),setTimeout(()=>p("idle"),2e3);return}try{const H=o.current.innerHTML,ne=Bn(H),Z=o.current.innerText;await _n(ne,Z),p("copied"),setTimeout(()=>p("idle"),2e3)}catch{p("error"),setTimeout(()=>p("idle"),2e3)}},[]),D=t.useCallback(async()=>{if(!o.current){C("error"),setTimeout(()=>C("idle"),2e3);return}try{const H=o.current.innerHTML;await Pt(H),C("copied"),setTimeout(()=>C("idle"),2e3)}catch{C("error"),setTimeout(()=>C("idle"),2e3)}},[]),j=t.useCallback(async()=>{try{await Pt(s.content),x("copied"),setTimeout(()=>x("idle"),2e3)}catch{x("error"),setTimeout(()=>x("idle"),2e3)}},[s.content]),A=t.useCallback(async()=>{try{await Pt(s.content),y("copied"),setTimeout(()=>y("idle"),2e3)}catch{y("error"),setTimeout(()=>y("idle"),2e3)}},[s.content]),G=e.jsxs("div",{className:"file-viewer-header-buttons",children:[l&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`file-viewer-copy-html-btn ${b}`,onClick:N,title:f("terminal:fileExplorer.copyRichTextTitle"),children:f(b==="copied"?"terminal:fileExplorer.copied":b==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyRichText")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${w}`,onClick:D,title:f("terminal:fileExplorer.copyHtmlTitle"),children:f(w==="copied"?"terminal:fileExplorer.copied":w==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyHtml")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${P}`,onClick:j,title:f("terminal:fileExplorer.copyMarkdownTitle"),children:f(P==="copied"?"terminal:fileExplorer.copied":P==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyMarkdown")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${k}`,onClick:A,title:f("terminal:fileExplorer.copyOriginalTitle"),children:f(k==="copied"?"terminal:fileExplorer.copied":k==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyOriginal")})]}),e.jsx("button",{className:`file-viewer-render-toggle ${l?"active":""}`,onClick:c,title:f(l?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderMarkdown"),children:l?"</>":"Aa"})]});return e.jsxs(e.Fragment,{children:[e.jsx(We,{file:s,onRevealInTree:n,rightContent:G,editMode:r,onToggleEdit:i}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:d,children:[l?e.jsx("div",{className:"file-viewer-markdown-wrapper",children:e.jsx("div",{className:"markdown-content",ref:o,children:e.jsx(Vn,{remarkPlugins:[Kn],children:s.content})})}):e.jsx("div",{className:"file-viewer-code-wrapper",children:e.jsx("pre",{className:"file-viewer-pre",children:e.jsx("code",{ref:h,className:"language-markdown",children:s.content})})}),e.jsx("div",{className:"file-viewer-scroll-indicator",title:`Line ${v.currentLine}/${v.totalLines}`,children:v.scrollPercentage===100?"END":v.scrollPercentage===0?"TOP":`${v.scrollPercentage}%`}),v.searchActive&&e.jsx(as,{query:v.searchQuery,onQueryChange:v.setSearchQuery,matchCount:v.searchMatches.length,currentIndex:v.currentMatchIndex,onNext:v.nextMatch,onPrev:v.prevMatch,onClose:v.clearSearch})]}),v.helpActive&&e.jsx(rs,{onClose:v.toggleHelp})]})}function Ba({file:s,onRevealInTree:n,renderPlantUml:l,onToggleRender:c,editMode:r,onToggleEdit:i}){const{t:h}=re(["terminal"]),o=t.useRef(null),d=t.useRef(null),[f,b]=t.useState(null),[p,w]=t.useState(!1),[C,P]=t.useState(null),x=sn({containerRef:d,isEnabled:!0,content:s.content});t.useEffect(()=>{if(!l&&o.current){const y=Ht(s.extension);Qs(y).then(()=>{o.current&&Zs(o.current)})}},[s,l]),t.useEffect(()=>{if(!l)return;if(!s.content.trim()){b(null),P("Diagram is empty");return}const y=new AbortController;return w(!0),P(null),(async()=>{try{const N=await fetch($a,{method:"POST",headers:{"Content-Type":"text/plain; charset=utf-8",Accept:"image/svg+xml"},body:s.content,signal:y.signal});if(!N.ok)throw new Error(`Render failed (${N.status})`);const D=await N.text();if(!D.includes("<svg"))throw new Error("Invalid SVG output");b(Ga(D))}catch(N){if(y.signal.aborted)return;const D=N instanceof Error?N.message:"Failed to render diagram";P(D),b(null)}finally{y.signal.aborted||w(!1)}})(),()=>y.abort()},[s.path,s.content,l]);const k=e.jsx("div",{className:"file-viewer-header-buttons",children:e.jsx("button",{className:`file-viewer-render-toggle ${l?"active":""}`,onClick:c,title:h(l?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderDiagram"),children:l?"</>":h("terminal:fileExplorer.diagram")})});return e.jsxs(e.Fragment,{children:[e.jsx(We,{file:s,onRevealInTree:n,rightContent:k,editMode:r,onToggleEdit:i}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:d,children:[l?e.jsxs("div",{className:"file-viewer-diagram-wrapper",children:[p&&e.jsx("div",{className:"file-viewer-placeholder",children:h("terminal:fileExplorer.renderingDiagram")}),!p&&f&&e.jsx("img",{src:f,alt:s.filename,className:"file-viewer-diagram-image"}),!p&&C&&e.jsxs("div",{className:"file-viewer-diagram-error",children:[e.jsxs("div",{children:[h("terminal:fileExplorer.couldNotRender"),": ",C]}),e.jsx("button",{className:"file-viewer-render-toggle",onClick:c,children:h("terminal:fileExplorer.showSource")})]})]}):e.jsx("div",{className:"file-viewer-code-wrapper",children:e.jsx("pre",{className:"file-viewer-pre",children:e.jsx("code",{ref:o,className:"language-plaintext",children:s.content})})}),e.jsx("div",{className:"file-viewer-scroll-indicator",title:`Line ${x.currentLine}/${x.totalLines}`,children:x.scrollPercentage===100?"END":x.scrollPercentage===0?"TOP":`${x.scrollPercentage}%`}),x.searchActive&&e.jsx(as,{query:x.searchQuery,onQueryChange:x.setSearchQuery,matchCount:x.searchMatches.length,currentIndex:x.currentMatchIndex,onNext:x.nextMatch,onPrev:x.prevMatch,onClose:x.clearSearch})]}),x.helpActive&&e.jsx(rs,{onClose:x.toggleHelp})]})}function _a({file:s,onRevealInTree:n}){const{t:l}=re(["common","terminal"]),c=()=>{if(s.dataUrl){const r=document.createElement("a");r.href=s.dataUrl,r.download=s.filename,r.click()}};return e.jsxs(e.Fragment,{children:[e.jsx(We,{file:s,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:c,title:l("common:buttons.download"),children:l("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-image-wrapper",children:s.dataUrl?e.jsx("img",{src:s.dataUrl,alt:s.filename,className:"file-viewer-image"}):e.jsx("div",{className:"file-viewer-placeholder",children:l("terminal:fileExplorer.failedToLoadImage")})})]})}function Va({file:s,onRevealInTree:n}){const{t:l}=re(["common","terminal"]),c=()=>{if(s.dataUrl){const r=document.createElement("a");r.href=s.dataUrl,r.download=s.filename,r.click()}};return e.jsxs(e.Fragment,{children:[e.jsx(We,{file:s,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:c,title:l("common:buttons.download"),children:l("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-pdf-wrapper",children:s.dataUrl?e.jsx("iframe",{src:s.dataUrl,title:s.filename,className:"file-viewer-pdf"}):e.jsx("div",{className:"file-viewer-placeholder",children:l("terminal:fileExplorer.failedToLoadPdf")})})]})}function Ka({file:s,onRevealInTree:n}){const{t:l}=re(["terminal","common"]),c=()=>{if(s.dataUrl){const i=document.createElement("a");i.href=s.dataUrl,i.download=s.filename,i.click()}},r=()=>{const i=s.extension.toLowerCase();return[".xlsx",".xls"].includes(i)?e.jsx(R,{name:"dashboard",size:48}):[".docx",".doc"].includes(i)?e.jsx(R,{name:"edit",size:48}):[".pptx",".ppt"].includes(i)?e.jsx(R,{name:"film",size:48}):[".zip",".tar",".gz",".rar",".7z"].includes(i)?e.jsx(R,{name:"file-zip",size:48}):[".mp3",".wav",".flac",".ogg"].includes(i)?e.jsx(R,{name:"music-note",size:48}):[".mp4",".avi",".mov",".mkv",".webm"].includes(i)?e.jsx(R,{name:"film",size:48}):[".exe",".dmg",".app",".msi"].includes(i)?e.jsx(R,{name:"gear",size:48}):[".apk",".aab",".ipa"].includes(i)?e.jsx(R,{name:"mobile",size:48}):[".jar",".war",".ear"].includes(i)?e.jsx(R,{name:"coffee",size:48}):[".iso",".img"].includes(i)?e.jsx(R,{name:"disc",size:48}):[".so",".dll",".dylib"].includes(i)?e.jsx(R,{name:"wrench",size:48}):e.jsx(R,{name:"folder",size:48})};return e.jsxs(e.Fragment,{children:[e.jsx(We,{file:s,onRevealInTree:n}),e.jsxs("div",{className:"file-viewer-binary",children:[e.jsx("div",{className:"file-viewer-binary-icon",children:r()}),e.jsx("div",{className:"file-viewer-binary-name",children:s.filename}),e.jsx("div",{className:"file-viewer-binary-size",children:Xs(s.size)}),e.jsx("div",{className:"file-viewer-binary-message",children:l("terminal:fileExplorer.cannotPreview")}),e.jsx("button",{className:"file-viewer-download-btn large",onClick:c,children:l("terminal:fileExplorer.downloadFile")})]})]})}function Wa({file:s,loading:n,error:l,onRevealInTree:c,onFileEdited:r}){const{t:i}=re(["terminal","common"]),[h,o]=Aa(),[d,f]=Oa(),[b,p]=t.useState(!1);t.useEffect(()=>{p(!1)},[s==null?void 0:s.path]);const w=t.useCallback(async N=>{if(!s)return;const D=await Y(V("/api/files/write"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:s.path,content:N})});if(!D.ok){const j=await D.json().catch(()=>({error:"Save failed"}));throw new Error(j.error||"Save failed")}},[s]),C=t.useCallback(()=>{p(N=>(N&&s&&(r==null||r(s.path)),!N))},[s,r]),P=t.useCallback(()=>{s&&(r==null||r(s.path))},[s,r]);if(n)return e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")});if(l)return e.jsx("div",{className:"file-viewer-placeholder error",children:l});if(!s)return e.jsxs("div",{className:"file-viewer-placeholder",children:[e.jsx("div",{className:"placeholder-icon",children:e.jsx(R,{name:"folder-open",size:32})}),e.jsx("div",{className:"placeholder-text",children:i("terminal:fileExplorer.selectFileToView")})]});const x=s.fileType||"text",k=x==="text"&&Ha(s.extension),y=x==="text"&&za(s.extension),v=k||y;return v&&b&&s.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(We,{file:s,onRevealInTree:c,editMode:!0,onToggleEdit:C}),e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")}),children:e.jsx(Vs,{content:s.content,extension:s.extension,onSave:w,onCancel:C},s.path)})]}):x==="text"&&!v&&s.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(We,{file:s,onRevealInTree:c}),e.jsx(t.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")}),children:e.jsx(Vs,{content:s.content,extension:s.extension,onSave:w,onCancel:P},s.path)})]}):e.jsxs("div",{className:"file-viewer-content",children:[k&&e.jsx(Ua,{file:s,onRevealInTree:c,renderMarkdown:h,onToggleRender:o,editMode:b,onToggleEdit:C}),y&&!k&&e.jsx(Ba,{file:s,onRevealInTree:c,renderPlantUml:d,onToggleRender:f,editMode:b,onToggleEdit:C}),x==="image"&&e.jsx(_a,{file:s,onRevealInTree:c}),x==="pdf"&&e.jsx(Va,{file:s,onRevealInTree:c}),x==="binary"&&e.jsx(Ka,{file:s,onRevealInTree:c})]})}const nn=t.memo(Wa,(s,n)=>s.loading!==n.loading||s.error!==n.error?!1:s.file===null&&n.file===null?!0:s.file===null||n.file===null?!1:s.file.path===n.file.path&&s.file.content===n.file.content&&s.file.modified===n.file.modified);nn.displayName="FileViewer";function an({text:s,query:n}){if(!n)return e.jsx(e.Fragment,{children:s});const l=Jn(s,n);if(l)return e.jsxs(e.Fragment,{children:[s.slice(0,l.start),e.jsx("mark",{className:"search-highlight",children:s.slice(l.start,l.end)}),s.slice(l.end)]});const c=n.toLowerCase(),i=s.toLowerCase().indexOf(c);return i===-1?e.jsx(e.Fragment,{children:s}):e.jsxs(e.Fragment,{children:[s.slice(0,i),e.jsx("mark",{className:"search-highlight",children:s.slice(i,i+n.length)}),s.slice(i+n.length)]})}const Ja=t.memo(function({node:n,query:l,isSelected:c,onSelect:r,lineNumber:i}){const h=n.isDirectory?null:ss(n),o=n.path.split("/");o[o.length-1];const d=o.slice(0,-1).join("/");return e.jsxs("div",{className:`search-result-item ${c?"selected":""}`,onClick:()=>r(n),children:[n.isDirectory?e.jsx("span",{className:"search-result-icon",children:e.jsx(R,{name:"folder",size:14})}):h?e.jsx("span",{className:"search-result-icon",style:{backgroundImage:`url('${h}')`},role:"img","aria-label":"file icon"}):e.jsx("span",{className:"search-result-icon",children:e.jsx(R,{name:"file-text",size:14})}),e.jsxs("div",{className:"search-result-info",children:[e.jsxs("span",{className:"search-result-name",children:[e.jsx(an,{text:n.name,query:l}),i&&e.jsxs("span",{className:"search-result-line-badge",children:[":",i]})]}),e.jsx("span",{className:"search-result-path",children:d})]})]})}),Ya=t.memo(function({match:n,query:l,isSelected:c,onSelect:r}){const{t:i}=re(["terminal"]),h={name:n.name,path:n.path,isDirectory:!1,extension:n.extension},o=ss(h),d=n.path.split("/"),f=d[d.length-1],b=d.slice(0,-1).join("/");return e.jsxs("div",{className:`content-search-item ${c?"selected":""}`,children:[e.jsxs("div",{className:`content-search-header ${c?"selected":""}`,onClick:()=>r(n.path),children:[o?e.jsx("span",{className:"content-search-icon",style:{backgroundImage:`url('${o}')`},role:"img","aria-label":"file icon"}):e.jsx("span",{className:"content-search-icon",children:e.jsx(R,{name:"file-text",size:14})}),e.jsxs("div",{style:{flex:1,minWidth:0,display:"flex",flexDirection:"column",gap:"2px"},children:[e.jsx("span",{className:"content-search-name",children:f}),e.jsx("span",{className:"search-result-path",style:{fontSize:"10px"},children:b})]}),e.jsx("span",{className:"content-search-count",children:n.matches.length})]}),e.jsxs("div",{className:"content-search-matches",children:[n.matches.slice(0,5).map((p,w)=>e.jsxs("div",{className:"content-search-match",onClick:()=>r(n.path,p.line),children:[e.jsx("span",{className:"content-search-line-num",children:p.line}),e.jsx("span",{className:"content-search-line-content",children:e.jsx(an,{text:p.content.trim(),query:l})})]},`${n.path}-${p.line}-${w}`)),n.matches.length>5&&e.jsxs("div",{className:"content-search-match",style:{opacity:.6,cursor:"default"},children:[e.jsx("span",{className:"content-search-line-num",children:"..."}),e.jsx("span",{className:"content-search-line-content",children:i("terminal:fileExplorer.moreMatches",{count:n.matches.length-5})})]})]})]})});function qa({filenameResults:s,contentResults:n,onSelectFile:l,onSelectContent:c,selectedPath:r,query:i,lineNumber:h}){const{t:o}=re(["terminal"]),d=s.length>0,f=n.length>0;return!d&&!f?e.jsx("div",{className:"search-no-results",children:o("terminal:fileExplorer.noMatchesFound")}):e.jsxs("div",{className:"unified-search-results",children:[d&&e.jsxs("div",{className:"unified-search-section",children:[e.jsxs("div",{className:"unified-search-section-header",children:[e.jsx("span",{className:"unified-search-section-icon",children:e.jsx(R,{name:"file-text",size:14})}),e.jsx("span",{className:"unified-search-section-title",children:o("terminal:fileExplorer.files")}),e.jsx("span",{className:"unified-search-section-count",children:s.length})]}),e.jsx("div",{className:"unified-search-section-content",children:s.map(b=>e.jsx(Ja,{node:b,query:i,isSelected:r===b.path,onSelect:l,lineNumber:h},b.path))})]}),f&&e.jsxs("div",{className:"unified-search-section",children:[e.jsxs("div",{className:"unified-search-section-header",children:[e.jsx("span",{className:"unified-search-section-icon",children:e.jsx(R,{name:"edit",size:14})}),e.jsx("span",{className:"unified-search-section-title",children:o("terminal:fileExplorer.content")}),e.jsx("span",{className:"unified-search-section-count",children:o("terminal:fileExplorer.matchesInFiles",{matches:n.reduce((b,p)=>b+p.matches.length,0),files:n.length})})]}),e.jsx("div",{className:"unified-search-section-content",children:n.map(b=>e.jsx(Ya,{match:b,query:i,isSelected:r===b.path,onSelect:c},b.path))})]})]})}const rn=t.memo(qa,(s,n)=>!(s.query!==n.query||s.selectedPath!==n.selectedPath||s.filenameResults.length!==n.filenameResults.length||s.contentResults.length!==n.contentResults.length));rn.displayName="UnifiedSearchResults";const Xa=t.memo(function({file:n,isSelected:l,onSelect:c,onStage:r,isStaging:i,showDirPath:h,isChecked:o,onToggleCheck:d,onContextMenu:f,onDiscard:b}){const{t:p}=re(["terminal"]),w=n.status,C=gt[w],P=w==="deleted",x=w==="untracked"&&r,k=n.name.includes(".")?"."+n.name.split(".").pop():"",y=h&&n.path.includes("/")?n.path.slice(0,n.path.lastIndexOf("/")):"";return e.jsxs("div",{className:`git-file-item ${l?"selected":""}`,onClick:()=>!P&&c(n.path,w),onContextMenu:v=>{v.preventDefault(),f==null||f(v,n,w)},style:{cursor:P?"not-allowed":"pointer"},title:n.path,children:[d&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:o||!1,onChange:v=>{v.stopPropagation(),d(n.path)},onClick:v=>v.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:pt(k),alt:"file"}),e.jsxs("span",{className:"git-file-name",children:[n.name,y&&e.jsx("span",{className:"git-file-dir",children:y})]}),e.jsx("span",{className:"git-file-status",style:{color:C.color},children:C.icon}),n.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:[e.jsx(R,{name:"subitem",size:10,style:{transform:"rotate(180deg)"}})," ",n.oldPath.split("/").pop()]}),x&&e.jsx("button",{className:`git-stage-btn ${i?"staging":""}`,onClick:v=>{v.stopPropagation(),i||r(n.path)},title:p("terminal:fileExplorer.stageFile"),disabled:i,children:i?"...":"+"}),b&&e.jsx("button",{className:"git-discard-btn",onClick:v=>{v.stopPropagation(),b(n,w)},title:w==="untracked"||w==="added"?"Delete file":"Discard changes",children:e.jsx(R,{name:"revert",size:12})})]})}),Qa=16,Za=22,er=t.memo(function s({node:n,depth:l,expandedDirs:c,onToggleDir:r,selectedPath:i,onSelect:h,onStage:o,stagingPaths:d,checkedFiles:f,onToggleCheck:b,onContextMenu:p,onDirContextMenu:w,onDiscard:C}){const{t:P}=re(["terminal"]),x=l*Qa;if(!n.isDirectory){const y=n.file.status,v=gt[y];return e.jsxs("div",{className:`git-file-item ${i===n.path?"selected":""}`,onClick:()=>y!=="deleted"&&h(n.file.path,y),onContextMenu:N=>{N.preventDefault(),p==null||p(N,n.file,y)},style:{paddingLeft:`${x+Za}px`,cursor:y==="deleted"?"not-allowed":"pointer"},title:n.file.path,children:[b&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:(f==null?void 0:f.has(n.file.path))||!1,onChange:N=>{N.stopPropagation(),b(n.file.path)},onClick:N=>N.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:pt(n.file.name.includes(".")?"."+n.file.name.split(".").pop():""),alt:"file"}),e.jsx("span",{className:"git-file-name",children:n.file.name}),e.jsx("span",{className:"git-file-status",style:{color:v.color},children:v.icon}),n.file.oldPath&&e.jsxs("span",{className:"git-file-renamed",children:[e.jsx(R,{name:"subitem",size:10,style:{transform:"rotate(180deg)"}})," ",n.file.oldPath.split("/").pop()]}),y==="untracked"&&o&&e.jsx("button",{className:`git-stage-btn ${d!=null&&d.has(n.path)?"staging":""}`,onClick:N=>{N.stopPropagation(),d!=null&&d.has(n.path)||o(n.file.path)},title:P("terminal:fileExplorer.stageFile"),disabled:d==null?void 0:d.has(n.path),children:d!=null&&d.has(n.path)?"...":"+"}),C&&e.jsx("button",{className:"git-discard-btn",onClick:N=>{N.stopPropagation(),C(n.file,y)},title:y==="untracked"||y==="added"?"Delete file":"Discard changes",children:e.jsx(R,{name:"revert",size:12})})]})}const k=c.has(n.path);return e.jsxs("div",{className:"tree-node-wrapper",children:[e.jsxs("div",{className:`tree-node directory ${k?"expanded":""}`,style:{paddingLeft:`${x}px`},onClick:()=>r(n.path),onContextMenu:y=>{y.preventDefault(),y.stopPropagation(),w==null||w(y,n)},children:[e.jsx("span",{className:`tree-arrow ${k?"expanded":""}`,children:e.jsx(R,{name:"caret-right",size:10})}),e.jsx("img",{className:"tree-folder-icon",src:k?"/assets/vscode-icons/default_folder_opened.svg":"/assets/vscode-icons/default_folder.svg",alt:"folder"}),e.jsx("span",{className:"tree-name",children:n.name}),e.jsx("span",{className:"git-tree-file-count",children:P("terminal:fileExplorer.fileCount",{count:n.fileCount})})]}),k&&e.jsx("div",{className:"tree-children",children:n.children.map(y=>e.jsx(s,{node:y,depth:l+1,expandedDirs:c,onToggleDir:r,selectedPath:i,onSelect:h,onStage:o,stagingPaths:d,checkedFiles:f,onToggleCheck:b,onContextMenu:p,onDirContextMenu:w,onDiscard:C},y.path))})]})}),es=t.memo(function({groupLabel:n,groupIcon:l,groupColor:c,files:r,treeNodes:i,viewMode:h,selectedPath:o,expandedDirs:d,onToggleDir:f,onFileSelect:b,onStageFile:p,onStageAll:w,stagingPaths:C,checkedFiles:P,onToggleCheck:x,onContextMenu:k,onDirContextMenu:y,onDiscardFile:v,onDiscardAll:N}){const{t:D}=re(["terminal"]);if(r.length===0)return null;const j=r.some(H=>H.status==="untracked"),A=j&&w&&r.length>0,G=C?r.every(H=>C.has(H.path)):!1;return e.jsxs("div",{className:"git-status-group",children:[e.jsxs("div",{className:"git-status-group-header",style:{color:c},children:[e.jsx("span",{className:"git-status-badge",style:{background:c},children:l}),n," (",r.length,")",A&&e.jsx("button",{className:`git-stage-all-btn ${G?"staging":""}`,onClick:H=>{H.stopPropagation(),G||w()},title:D("terminal:fileExplorer.stageAllUntracked"),disabled:G,children:G?"...":D("terminal:fileExplorer.stageAll")}),N&&e.jsxs("button",{className:"git-discard-all-btn",onClick:H=>{H.stopPropagation(),N()},title:j?`Delete all ${r.length} files`:`Discard all ${r.length} changes`,children:[e.jsx(R,{name:"revert",size:12})," All"]})]}),h==="tree"?e.jsx("div",{className:"git-tree-content",children:i.map(H=>e.jsx(er,{node:H,depth:0,expandedDirs:d,onToggleDir:f,selectedPath:o,onSelect:b,onStage:p,stagingPaths:C,checkedFiles:P,onToggleCheck:x,onContextMenu:k,onDirContextMenu:y,onDiscard:v},H.path))}):e.jsx("div",{className:"git-flat-content",children:r.map(H=>e.jsx(Xa,{file:H,isSelected:o===H.path,onSelect:b,onStage:H.status==="untracked"?p:void 0,isStaging:C==null?void 0:C.has(H.path),showDirPath:!0,isChecked:P==null?void 0:P.has(H.path),onToggleCheck:x,onContextMenu:k,onDiscard:v},H.path))})]})});function tr({gitStatus:s,loading:n,onFileSelect:l,selectedPath:c,onRefresh:r,onStageFiles:i,stagingPaths:h,currentFolder:o,onCommitComplete:d,mergeInProgress:f,mergingBranch:b,onMergeContinue:p,onMergeAbort:w,onConflictOpen:C,onRevealInTree:P}){const{t:x}=re(["terminal","common"]),[k,y]=t.useState("tree"),[v,N]=t.useState(new Set),[D,j]=t.useState(""),[A,G]=t.useState(""),[H,ne]=t.useState(!1),[Z,M]=t.useState(new Set),[I,K]=t.useState(!1),[ae,ie]=t.useState(null),fe=t.useRef(null),{showToast:O}=en(),[W,T]=t.useState(null),[J,z]=t.useState(null),[se,xe]=t.useState(null),ye=t.useCallback((E,L)=>{xe({files:[E],label:E.name})},[]),m=t.useCallback(async()=>{if(!(!se||!o))try{const E=await Y(V("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:se.files.map(B=>({path:B.path,status:B.status})),directory:o})}),L=await E.json();E.ok&&L.success?(O("success","Discarded",`Reverted ${se.files.length} file(s)`),r()):O("error","Discard Failed",L.error||"Could not discard changes")}catch{O("error","Discard Failed","Network error")}finally{xe(null)}},[se,o,r,O]),F=t.useCallback((E,L,B)=>{E.preventDefault(),E.stopPropagation(),T({isOpen:!0,position:{x:E.clientX,y:E.clientY},file:L,status:B})},[]),Q=t.useCallback(async(E,L)=>{if(o)try{const B=await Y(V("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:[{path:E.path,status:L}],directory:o})}),je=await B.json();B.ok&&je.success?(O("success","Discarded",`Restored ${E.name}`),r()):O("error","Discard Failed",je.error||"Could not discard changes")}catch{O("error","Discard Failed","Network error")}},[o,r,O]),de=t.useCallback(async E=>{try{await navigator.clipboard.writeText(E),O("success","Copied","Full path copied")}catch{O("error","Copy Failed","Could not copy path")}},[O]),_=t.useCallback(async E=>{const L=o&&E.startsWith(o+"/")?E.slice(o.length+1):E;try{await navigator.clipboard.writeText(L),O("success","Copied","Relative path copied")}catch{O("error","Copy Failed","Could not copy path")}},[o,O]),S=t.useMemo(()=>{if(!W)return[];const{file:E,status:L}=W,B=[];return L==="conflict"&&C?B.push({id:"open-conflict",label:x("terminal:fileExplorer.gitContextMenu.openConflictResolver"),icon:e.jsx(R,{name:"warn",size:14}),onClick:()=>C(E.path)}):L!=="deleted"&&B.push({id:"open-file",label:x("terminal:fileExplorer.gitContextMenu.openFile"),icon:e.jsx(R,{name:"file-text",size:14}),onClick:()=>l(E.path,L)}),L!=="conflict"&&B.push({id:"stage-file",label:x("terminal:fileExplorer.gitContextMenu.stageFile"),icon:e.jsx(R,{name:"plus",size:14}),onClick:()=>{i([E.path])}}),B.push({id:"divider-1",label:"",divider:!0,onClick:()=>{}}),(L==="modified"||L==="deleted"||L==="renamed"||L==="conflict")&&B.push({id:"discard-changes",label:x("terminal:fileExplorer.gitContextMenu.discardChanges"),icon:e.jsx(R,{name:"revert",size:14}),danger:!0,onClick:()=>{Q(E,L)}}),(L==="untracked"||L==="added")&&B.push({id:"delete-file",label:x("terminal:fileExplorer.gitContextMenu.deleteFile"),icon:e.jsx(R,{name:"trash",size:14}),danger:!0,onClick:()=>{Q(E,L)}}),B.push({id:"divider-2",label:"",divider:!0,onClick:()=>{}}),B.push({id:"copy-full-path",label:x("terminal:fileExplorer.gitContextMenu.copyFullPath"),icon:e.jsx(R,{name:"pin",size:14}),onClick:()=>{de(E.path)}}),B.push({id:"copy-relative-path",label:x("terminal:fileExplorer.gitContextMenu.copyRelativePath"),icon:e.jsx(R,{name:"clipboard",size:14}),onClick:()=>{_(E.path)}}),P&&L!=="deleted"&&B.push({id:"reveal-in-tree",label:x("terminal:fileExplorer.gitContextMenu.revealInTree"),icon:e.jsx(R,{name:"target",size:14}),onClick:()=>P(E.path)}),B},[W,l,i,C,P,Q,de,_,x]),U=t.useCallback((E,L)=>{E.preventDefault(),E.stopPropagation(),z({isOpen:!0,position:{x:E.clientX,y:E.clientY},node:L})},[]),te=t.useCallback(E=>!E.isDirectory&&E.file?[E.file]:E.children.flatMap(L=>te(L)),[]),Te=t.useCallback(async E=>{if(!o)return;const L=te(E);if(L.length!==0)try{const B=await Y(V("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:L.map(De=>({path:De.path,status:De.status})),directory:o})}),je=await B.json();B.ok&&je.success?(O("success","Discarded",`Reverted ${L.length} file(s) in ${E.name}`),r()):O("error","Discard Failed",je.error||"Could not discard changes")}catch{O("error","Discard Failed","Network error")}},[o,te,r,O]),Ce=t.useMemo(()=>{if(!J)return[];const{node:E}=J,L=te(E);return[{id:"discard-dir",label:`Discard Changes (${L.length} files)`,icon:e.jsx(R,{name:"revert",size:14}),danger:!0,onClick:()=>{Te(E)}},{id:"stage-dir",label:`Stage All (${L.length} files)`,icon:e.jsx(R,{name:"plus",size:14}),onClick:()=>{i(L.map(B=>B.path))}}]},[J,te,Te,i]),ee=t.useCallback(E=>{N(L=>{const B=new Set(L);return B.has(E)?B.delete(E):B.add(E),B})},[]),{conflictFiles:pe,conflictTree:Ge,changesFiles:Ue,changesTree:xt,untrackedFiles:Me,untrackedTree:lt,allDirPaths:ot}=t.useMemo(()=>{if(!s||!s.isGitRepo||s.files.length===0)return{conflictFiles:[],conflictTree:[],changesFiles:[],changesTree:[],untrackedFiles:[],untrackedTree:[],allDirPaths:new Set};const E=new Set,L=s.files.filter(he=>he.status==="conflict"),B=It(L);Lt(B,E);const je=s.files.filter(he=>he.status==="modified"||he.status==="added"||he.status==="deleted"||he.status==="renamed"),De=It(je);Lt(De,E);const Ee=s.files.filter(he=>he.status==="untracked"),jt=It(Ee);return Lt(jt,E),{conflictFiles:L,conflictTree:B,changesFiles:je,changesTree:De,untrackedFiles:Ee,untrackedTree:jt,allDirPaths:E}},[s]);t.useEffect(()=>{N(ot)},[ot]),t.useEffect(()=>{s!=null&&s.files&&M(new Set(s.files.map(E=>E.path)))},[s==null?void 0:s.files]);const yt=t.useCallback(()=>{Ue.length!==0&&xe({files:Ue,label:`${Ue.length} changed files`})},[Ue]),zt=t.useCallback(()=>{Me.length!==0&&xe({files:Me,label:`${Me.length} unversioned files`})},[Me]),bt=t.useCallback(()=>{pe.length!==0&&xe({files:pe,label:`${pe.length} conflicted files`})},[pe]),be=pe.length>0;t.useEffect(()=>{if(ae){const E=ae.type==="error"?8e3:4e3,L=setTimeout(()=>ie(null),E);return()=>clearTimeout(L)}},[ae]);const oe=t.useCallback(async()=>{const E=!H;if(ne(E),E&&o){G(D);try{const B=await(await Y(V(`/api/files/git-log-message?path=${encodeURIComponent(o)}`))).json();B.message&&j(B.message)}catch{}}else j(A)},[H,o,D,A]),ge=t.useCallback(E=>{M(L=>{const B=new Set(L);return B.has(E)?B.delete(E):B.add(E),B})},[]),Ne=t.useCallback(()=>{if(!(s!=null&&s.files))return;const E=s.files.map(B=>B.path),L=E.every(B=>Z.has(B));M(L?new Set:new Set(E))},[s==null?void 0:s.files,Z]),Pe=t.useCallback(async E=>{if(!(!o||!D.trim()||Z.size===0||I)){K(!0),ie(null);try{const L=await Y(V("/api/files/git-commit"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:o,message:D.trim(),amend:H,paths:Array.from(Z)})}),B=await L.json();if(!L.ok||!B.success){ie({type:"error",text:B.error||"Commit failed"}),K(!1);return}if(E)try{const je=await Y(V("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:o})}),De=await je.json();je.ok&&De.success?ie({type:"success",text:x("terminal:fileExplorer.committedAndPushed")}):ie({type:"error",text:x("terminal:fileExplorer.committedButPushFailed",{error:De.error||"Unknown error"})})}catch{ie({type:"error",text:x("terminal:fileExplorer.committedButPushFailed",{error:"Network error"})})}else ie({type:"success",text:x("terminal:fileExplorer.committedSuccessfully")});j(""),G(""),ne(!1),r(),d==null||d()}catch(L){ie({type:"error",text:L.message||"Commit failed"})}finally{K(!1)}}},[o,D,H,Z,I,r,d]);if(n)return e.jsx("div",{className:"git-changes-loading",children:x("terminal:fileExplorer.loadingGitStatus")});if(!s||!s.isGitRepo)return e.jsxs("div",{className:"git-changes-empty",children:[e.jsx("div",{className:"git-empty-icon",children:e.jsx(R,{name:"package",size:32})}),e.jsx("div",{className:"git-empty-text",children:x("terminal:fileExplorer.notGitRepo")})]});if(s.files.length===0)return e.jsxs("div",{className:"git-changes-empty",children:[e.jsx("div",{className:"git-empty-icon",children:e.jsx(R,{name:"sparkle",size:32})}),e.jsx("div",{className:"git-empty-text",children:x("terminal:fileExplorer.workingTreeClean")}),e.jsx("div",{className:"git-empty-branch",children:x("terminal:fileExplorer.onBranch",{branch:s.branch})})]});const Be=E=>{i([E])},At=()=>{const E=Me.map(L=>L.path);E.length>0&&i(E)},ze=(E,L)=>{L==="conflict"&&C?C(E):l(E,L)};return e.jsxs("div",{className:"git-changes",children:[e.jsxs("div",{className:"git-changes-header",children:[e.jsxs("span",{className:"git-branch",children:[e.jsx("span",{className:"git-branch-icon",children:e.jsx(R,{name:"git-branch",size:12})}),s.branch]}),s.counts&&e.jsxs("div",{className:"git-changes-summary",children:[(s.counts.conflict??0)>0&&e.jsxs("span",{className:"git-count conflict",children:[s.counts.conflict,"C"]}),s.counts.modified>0&&e.jsxs("span",{className:"git-count modified",children:[s.counts.modified,"M"]}),s.counts.added>0&&e.jsxs("span",{className:"git-count added",children:[s.counts.added,"A"]}),s.counts.deleted>0&&e.jsxs("span",{className:"git-count deleted",children:[s.counts.deleted,"D"]}),s.counts.untracked>0&&e.jsxs("span",{className:"git-count untracked",children:[s.counts.untracked,"?"]})]}),e.jsxs("div",{className:"git-view-toggle",children:[e.jsx("button",{className:`git-view-toggle-btn ${k==="flat"?"active":""}`,onClick:()=>y("flat"),title:x("terminal:fileExplorer.flatList"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("rect",{x:"2",y:"3",width:"12",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"2",y:"7",width:"12",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"2",y:"11",width:"12",height:"1.5",rx:"0.5"})]})}),e.jsx("button",{className:`git-view-toggle-btn ${k==="tree"?"active":""}`,onClick:()=>y("tree"),title:x("terminal:fileExplorer.directoryTree"),children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:[e.jsx("rect",{x:"1",y:"2",width:"6",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"4",y:"5.5",width:"8",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"4",y:"9",width:"8",height:"1.5",rx:"0.5"}),e.jsx("rect",{x:"7",y:"12.5",width:"7",height:"1.5",rx:"0.5"})]})})]}),e.jsx("button",{className:"git-refresh-btn",onClick:r,title:x("common:buttons.refresh"),children:e.jsx(R,{name:"refresh",size:12})})]}),f&&e.jsxs("div",{className:"git-merge-banner",children:[e.jsx("span",{className:"git-merge-banner-icon",children:"⚠"}),e.jsx("span",{className:"git-merge-banner-text",children:x("terminal:fileExplorer.mergeInProgress",{branch:b?` (${b})`:""})}),e.jsxs("div",{className:"git-merge-actions",children:[e.jsx("button",{className:"git-merge-continue-btn",onClick:p,disabled:be,title:x(be?"terminal:fileExplorer.resolveAllConflictsFirst":"terminal:fileExplorer.continueMerge"),children:x("terminal:fileExplorer.continue")}),e.jsx("button",{className:"git-merge-abort-btn",onClick:w,title:x("terminal:fileExplorer.abortMerge"),children:x("terminal:fileExplorer.abort")})]})]}),e.jsxs("div",{className:"git-changes-list",children:[e.jsx(es,{groupLabel:x("terminal:fileExplorer.gitGroups.conflicts"),groupIcon:"C",groupColor:"#ff5555",files:pe,treeNodes:Ge,viewMode:k,selectedPath:c,expandedDirs:v,onToggleDir:ee,onFileSelect:ze,checkedFiles:Z,onToggleCheck:ge,onContextMenu:F,onDirContextMenu:U,onDiscardFile:ye,onDiscardAll:bt}),e.jsx(es,{groupLabel:x("terminal:fileExplorer.gitGroups.changes"),groupIcon:"~",groupColor:"#c89a5a",files:Ue,treeNodes:xt,viewMode:k,selectedPath:c,expandedDirs:v,onToggleDir:ee,onFileSelect:ze,checkedFiles:Z,onToggleCheck:ge,onContextMenu:F,onDirContextMenu:U,onDiscardFile:ye,onDiscardAll:yt}),e.jsx(es,{groupLabel:x("terminal:fileExplorer.gitGroups.unversioned"),groupIcon:"?",groupColor:"#6ab8c8",files:Me,treeNodes:lt,viewMode:k,selectedPath:c,expandedDirs:v,onToggleDir:ee,onFileSelect:ze,onStageFile:Be,onStageAll:At,stagingPaths:h,checkedFiles:Z,onToggleCheck:ge,onContextMenu:F,onDirContextMenu:U,onDiscardFile:ye,onDiscardAll:zt})]}),e.jsxs("div",{className:"git-commit-panel",children:[e.jsxs("div",{className:"git-commit-options",children:[e.jsxs("label",{className:"git-commit-amend-label",children:[e.jsx("input",{type:"checkbox",className:"git-commit-amend-checkbox",checked:H,onChange:oe}),x("terminal:fileExplorer.amend")]}),e.jsx("span",{className:"git-commit-file-count",children:x("terminal:fileExplorer.fileCount",{count:Z.size})}),e.jsx("button",{className:"git-commit-select-toggle",onClick:Ne,title:Z.size===s.files.length?x("terminal:fileExplorer.deselectAll"):x("terminal:fileExplorer.selectAll"),children:Z.size===s.files.length?x("terminal:fileExplorer.deselectAll"):x("terminal:fileExplorer.selectAll")})]}),e.jsx("textarea",{ref:fe,className:"git-commit-message",placeholder:x("terminal:fileExplorer.commitMessagePlaceholder"),value:D,onChange:E=>j(E.target.value),onKeyDown:E=>{(E.metaKey||E.ctrlKey)&&E.key==="Enter"&&(E.preventDefault(),Pe(!1)),(E.metaKey||E.ctrlKey)&&E.shiftKey&&E.key==="Enter"&&(E.preventDefault(),Pe(!0)),E.stopPropagation()},rows:3,disabled:I}),ae&&e.jsx("div",{className:`git-commit-status ${ae.type}`,children:ae.text}),e.jsxs("div",{className:"git-commit-actions",children:[e.jsx("button",{className:"git-commit-btn",onClick:()=>Pe(!1),disabled:!D.trim()||Z.size===0||I,title:x("terminal:fileExplorer.commitCtrlEnter"),children:x(I?"terminal:fileExplorer.committing":"terminal:fileExplorer.commitAction")}),e.jsx("button",{className:"git-commit-push-btn",onClick:()=>Pe(!0),disabled:!D.trim()||Z.size===0||I,title:x("terminal:fileExplorer.commitAndPushCtrlShiftEnter"),children:I?"...":x("terminal:fileExplorer.commitAndPush")})]})]}),W&&e.jsx(rt,{isOpen:W.isOpen,position:W.position,worldPosition:{x:0,z:0},actions:S,onClose:()=>T(null)}),J&&e.jsx(rt,{isOpen:J.isOpen,position:J.position,worldPosition:{x:0,z:0},actions:Ce,onClose:()=>z(null)}),se&&e.jsx("div",{className:"git-discard-confirm-overlay",onClick:()=>xe(null),children:e.jsxs("div",{className:"git-discard-confirm",onClick:E=>E.stopPropagation(),children:[e.jsx("p",{children:se.files.some(E=>E.status==="untracked"||E.status==="added")?e.jsxs(e.Fragment,{children:["Delete ",e.jsx("strong",{children:se.label}),"?"]}):e.jsxs(e.Fragment,{children:["Discard changes to ",e.jsx("strong",{children:se.label}),"?"]})}),e.jsx("p",{className:"git-discard-confirm-hint",children:"This cannot be undone."}),e.jsxs("div",{className:"git-discard-confirm-actions",children:[e.jsx("button",{className:"git-discard-confirm-cancel",onClick:()=>xe(null),children:"Cancel"}),e.jsx("button",{className:"git-discard-confirm-btn",onClick:m,children:se.files.some(E=>E.status==="untracked"||E.status==="added")?"Delete":"Discard"})]})]})})]})}const ln=t.memo(tr,(s,n)=>s.loading!==n.loading||s.selectedPath!==n.selectedPath||s.stagingPaths!==n.stagingPaths||s.currentFolder!==n.currentFolder||s.mergeInProgress!==n.mergeInProgress||s.mergingBranch!==n.mergingBranch?!1:s.gitStatus===null&&n.gitStatus===null?!0:!(s.gitStatus===null||n.gitStatus===null||s.gitStatus.isGitRepo!==n.gitStatus.isGitRepo||s.gitStatus.branch!==n.gitStatus.branch||s.gitStatus.files.length!==n.gitStatus.files.length||s.gitStatus.mergeInProgress!==n.gitStatus.mergeInProgress));ln.displayName="GitChanges";const sr=t.memo(function({tab:n,isActive:l,onSelect:c,onClose:r,onContextMenu:i}){const{t:h}=re(["terminal"]),o={name:n.filename,path:n.path,isDirectory:!1,extension:n.extension},d=t.useCallback(()=>{c(n.path)},[c,n.path]),f=t.useCallback(w=>{w.button===1&&(w.preventDefault(),w.stopPropagation(),r(n.path))},[r,n.path]),b=t.useCallback(w=>{w.preventDefault(),w.stopPropagation(),r(n.path)},[r,n.path]),p=t.useCallback(w=>{w.preventDefault(),w.stopPropagation(),i(w,n)},[i,n]);return e.jsxs("div",{className:`file-tab ${l?"active":""}`,onClick:d,onMouseDown:f,onContextMenu:p,title:n.path,children:[e.jsx("img",{className:"file-tab-icon",src:ss(o),alt:"file"}),e.jsx("span",{className:"file-tab-name",children:n.filename}),e.jsx("button",{className:"file-tab-close",onClick:b,title:h("terminal:fileExplorer.closeMiddleClick"),children:"×"})]})});function nr(s){return typeof s.path=="string"&&s.path.startsWith("/")}function ar({tabs:s,activeTabPath:n,onSelectTab:l,onCloseTab:c,onCloseAllTabs:r,onShowGitHistory:i}){const{t:h}=re(["terminal"]),[o,d]=t.useState(null),f=t.useCallback((w,C)=>{d({isOpen:!0,position:{x:w.clientX,y:w.clientY},tab:C})},[]),b=t.useCallback(()=>d(null),[]),p=t.useMemo(()=>{if(!o)return[];const w=o.tab,C=!!i&&nr(w),P=[{id:"git-history",label:h("terminal:fileExplorer.showGitHistory")??"Show Git History",icon:e.jsx(R,{name:"git-commit",size:14}),disabled:!C,onClick:()=>{C&&i(w.path)}}];return r&&P.push({id:"divider-close-all",label:"",divider:!0,onClick:()=>{}},{id:"close-all-tabs",label:h("terminal:fileExplorer.closeAllTabs")??"Close all tabs",icon:e.jsx(R,{name:"cross",size:14}),danger:!0,onClick:()=>r()}),P},[o,i,r,h]);return s.length===0?null:e.jsxs("div",{className:"file-tabs-bar",children:[e.jsx("div",{className:"file-tabs-container",children:s.map(w=>e.jsx(sr,{tab:w,isActive:n===w.path,onSelect:l,onClose:c,onContextMenu:f},w.path))}),o&&e.jsx(rt,{isOpen:o.isOpen,position:o.position,worldPosition:{x:0,z:0},actions:p,onClose:b})]})}const on=t.memo(ar,(s,n)=>{if(s.activeTabPath!==n.activeTabPath||s.tabs.length!==n.tabs.length||s.onShowGitHistory!==n.onShowGitHistory||s.onCloseAllTabs!==n.onCloseAllTabs)return!1;for(let l=0;l<s.tabs.length;l++)if(s.tabs[l].path!==n.tabs[l].path)return!1;return!0});on.displayName="FileTabs";const rr=t.memo(function({currentFolder:n,gitStatus:l,onBranchChanged:c,onMerge:r,onCompare:i,onPullConflicts:h}){const{t:o}=re(["terminal","common"]),[d,f]=t.useState(!1),[b,p]=t.useState(""),[w,C]=t.useState(!1),[P,x]=t.useState(""),[k,y]=t.useState(!1),[v,N]=t.useState(null),[D,j]=t.useState(null),A=t.useRef(null),G=t.useRef(null),H=t.useRef(null),{branches:ne,loading:Z,operationInProgress:M,loadBranches:I,checkoutBranch:K,createBranch:ae,pullFromRemote:ie,pushToRemote:fe}=ns();t.useEffect(()=>{d&&n&&(I(n),setTimeout(()=>{var S;return(S=G.current)==null?void 0:S.focus()},50)),d||(p(""),C(!1),x(""),N(null))},[d,n,I]),t.useEffect(()=>{if(v){const S=v.type==="error"?8e3:3e3,U=setTimeout(()=>N(null),S);return()=>clearTimeout(U)}},[v]),t.useEffect(()=>{w&&setTimeout(()=>{var S;return(S=H.current)==null?void 0:S.focus()},50)},[w]),t.useEffect(()=>{if(!d)return;const S=te=>{const Te=te.target;!Te.closest(".branch-widget-selector")&&!Te.closest(".branch-widget-dropdown")&&f(!1)},U=te=>{te.key==="Escape"&&(te.preventDefault(),te.stopPropagation(),f(!1))};return document.addEventListener("click",S),document.addEventListener("keydown",U,!0),()=>{document.removeEventListener("click",S),document.removeEventListener("keydown",U,!0)}},[d]);const O=t.useCallback(async S=>{if(!n||M||S.isCurrent)return;const U=await K(n,S.name);U.success?(N({type:"success",text:o("terminal:fileExplorer.switchedToBranch",{branch:U.branch||S.name})}),c(),I(n)):N({type:"error",text:U.error||o("terminal:fileExplorer.checkoutFailed")})},[n,M,K,c,I]),W=t.useCallback(async()=>{if(!n||!P.trim()||M)return;const S=await ae(n,P.trim());S.success?(N({type:"success",text:o("terminal:fileExplorer.createdBranch",{branch:S.branch})}),C(!1),x(""),c(),I(n)):N({type:"error",text:S.error||o("terminal:fileExplorer.createBranchFailed")})},[n,P,M,ae,c,I]),T=t.useCallback(async()=>{if(!n||M)return;const S=await ie(n);S.success?(S.stashConflicts&&S.stashConflicts.length>0?(N({type:"error",text:`Pull succeeded but stash pop had conflicts: ${S.stashConflicts.length} file(s). Resolve manually.`}),h==null||h(S.stashConflicts),f(!1)):S.stashed?N({type:"success",text:"Pull complete. Local changes were auto-stashed and restored."}):N({type:"success",text:o("terminal:fileExplorer.pullComplete")}),c(),I(n)):S.conflicts&&S.conflicts.length>0?(N({type:"error",text:`Pull conflicts: ${S.conflicts.length} file(s)`}),h==null||h(S.conflicts),f(!1)):N({type:"error",text:S.error||o("terminal:fileExplorer.pullFailed")})},[n,M,ie,c,I,h]),J=t.useCallback(async()=>{if(!n||M)return;const S=await fe(n);S.success?N({type:"success",text:o("terminal:fileExplorer.pushComplete")}):N({type:"error",text:S.error||o("terminal:fileExplorer.pushFailed")})},[n,M,fe]),[z,se]=t.useState(!1),xe=t.useCallback(async()=>{if(!(!n||M||z)){se(!0);try{const S=await Y(V("/api/files/git-fetch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n})});if(S.ok)N({type:"success",text:"Fetch complete"}),c(),I(n);else{const U=await S.json().catch(()=>({error:"Fetch failed"}));N({type:"error",text:U.error||"Fetch failed"})}}catch{N({type:"error",text:"Fetch failed"})}finally{se(!1)}}},[n,M,z,c,I]),ye=(l==null?void 0:l.branch)||"unknown",m=!!M,F=t.useCallback((S,U)=>{U.isCurrent||(S.preventDefault(),S.stopPropagation(),j({isOpen:!0,position:{x:S.clientX,y:S.clientY},branch:U.name}))},[]),Q=t.useMemo(()=>{if(!D)return[];const S=!!M||(l==null?void 0:l.mergeInProgress);return[{id:"compare",label:o("terminal:fileExplorer.showDiffWith",{branch:D.branch}),icon:e.jsx(R,{name:"arrows-horizontal",size:14}),disabled:!!M,onClick:()=>{i==null||i(D.branch),f(!1)}},{id:"merge",label:o("terminal:fileExplorer.mergeInto",{source:D.branch,target:ye}),icon:"⤵",disabled:!!S,onClick:()=>{r&&r(D.branch),f(!1)}},{id:"divider-1",label:"",divider:!0,onClick:()=>{}},{id:"checkout",label:o("terminal:fileExplorer.checkoutBranch",{branch:D.branch}),icon:e.jsx(R,{name:"git-branch",size:14}),disabled:!!M,onClick:()=>{const U=ne.find(te=>te.name===D.branch);U&&O(U)}}]},[D,M,l==null?void 0:l.mergeInProgress,ye,r,i,ne,O]),de=t.useMemo(()=>{const S=ne.filter(te=>!te.isRemote);if(!b)return S;const U=b.toLowerCase();return S.filter(te=>te.name.toLowerCase().includes(U))},[ne,b]),_=t.useMemo(()=>{const S=ne.filter(te=>te.isRemote);if(!b)return S;const U=b.toLowerCase();return S.filter(te=>te.name.toLowerCase().includes(U))},[ne,b]);return e.jsxs("div",{className:"branch-widget",style:{position:"relative"},children:[e.jsxs("div",{className:"branch-widget-selector",onClick:S=>{S.stopPropagation(),f(!d)},title:`Branch: ${ye}`,children:[e.jsx("svg",{className:"branch-widget-icon",width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M5 3.25a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0Zm0 2.122a2.25 2.25 0 1 0-1 0v1.836A2.25 2.25 0 0 0 5.75 9.5h1.378a2.251 2.251 0 1 0 0-1H5.75a1.25 1.25 0 0 1-1.25-1.25V5.372Zm7.75 4.878a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3-8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z"})}),e.jsx("span",{className:"branch-widget-name",children:ye}),e.jsx("span",{className:"branch-widget-arrow",children:"▼"})]}),d&&e.jsxs("div",{className:"branch-widget-dropdown",ref:A,children:[e.jsx("div",{className:"branch-widget-search",children:e.jsx("input",{ref:G,type:"text",className:"branch-widget-search-input",placeholder:o("terminal:fileExplorer.searchBranches"),value:b,onChange:S=>p(S.target.value),onKeyDown:S=>S.stopPropagation()})}),v&&e.jsx("div",{className:`branch-widget-status ${v.type}`,children:v.text}),e.jsx("div",{className:"branch-widget-section-header",children:o("terminal:fileExplorer.actions")}),e.jsxs("div",{className:"branch-widget-actions",children:[e.jsxs("div",{className:`branch-widget-action-item ${m||z?"disabled":""}`,onClick:xe,children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 13l-3-3h2V6h2v4h2l-3 3zM8 3l3 3h-2v4H7V6H5l3-3z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:z?"Fetching...":"Fetch"})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:T,children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 12l-4-4h2.5V3h3v5H12L8 12z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o(M==="pull"?"terminal:fileExplorer.pulling":"terminal:fileExplorer.pull")})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:J,children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 4l4 4h-2.5v5h-3V8H4l4-4z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o(M==="push"?"terminal:fileExplorer.pushing":"terminal:fileExplorer.push")})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:()=>{m||C(!w)},children:[e.jsx("span",{className:"branch-widget-action-icon",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"currentColor",children:e.jsx("path",{d:"M8 2v5H3v2h5v5h2V9h5V7H10V2H8z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:o("terminal:fileExplorer.newBranch")})]})]}),w&&e.jsxs("div",{className:"branch-widget-new-branch",children:[e.jsx("input",{ref:H,type:"text",className:"branch-widget-new-branch-input",placeholder:o("terminal:fileExplorer.branchNamePlaceholder"),value:P,onChange:S=>x(S.target.value),onKeyDown:S=>{S.stopPropagation(),S.key==="Enter"&&W(),S.key==="Escape"&&(C(!1),x(""))}}),e.jsx("button",{className:"branch-widget-new-branch-confirm",onClick:W,disabled:!P.trim()||m,children:M==="create"?"...":o("common:buttons.create")})]}),e.jsxs("div",{className:"branch-widget-section-header",children:[o("terminal:fileExplorer.localBranches"),Z&&e.jsxs("span",{className:"branch-widget-loading-hint",children:[" ",o("terminal:fileExplorer.loading")]})]}),e.jsxs("div",{className:"branch-widget-branch-list",children:[de.length===0&&!Z&&e.jsx("div",{className:"branch-widget-empty",children:o("terminal:fileExplorer.noBranchesFound")}),de.map(S=>e.jsxs("div",{className:`branch-widget-branch-item ${S.isCurrent?"current":""} ${m?"disabled":""}`,onClick:()=>O(S),onContextMenu:U=>F(U,S),title:S.lastMessage||S.name,children:[e.jsxs("span",{className:"branch-widget-branch-name",children:[S.isCurrent&&e.jsx("span",{className:"branch-widget-current-marker",children:"*"}),S.name]}),S.lastCommit&&e.jsx("span",{className:"branch-widget-branch-commit",children:S.lastCommit})]},S.name))]}),_.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"branch-widget-section-header clickable",onClick:()=>y(!k),children:[e.jsx("span",{className:"branch-widget-section-toggle",children:k?"▾":"▸"}),o("terminal:fileExplorer.remoteBranches",{count:_.length})]}),k&&e.jsx("div",{className:"branch-widget-branch-list",children:_.map(S=>e.jsxs("div",{className:`branch-widget-branch-item remote ${m?"disabled":""}`,onClick:()=>O(S),onContextMenu:U=>F(U,S),title:S.lastMessage||S.name,children:[e.jsx("span",{className:"branch-widget-branch-name",children:S.name}),S.lastCommit&&e.jsx("span",{className:"branch-widget-branch-commit",children:S.lastCommit})]},S.name))})]})]}),D&&e.jsx(rt,{isOpen:D.isOpen,position:D.position,worldPosition:{x:0,z:0},actions:Q,onClose:()=>j(null)})]})});function ir(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function Ft(s,n){if(!s)return"";const l=Hs.languages[n];return l?Hs.highlight(s,l,n):ir(s)}function lr(s){const n=[],l=s.split(`
|
|
9
9
|
`);let c=[],r=!1,i=[],h=[],o=!1;for(const d of l)d.startsWith("<<<<<<<")?(c.length>0&&(n.push({type:"unchanged",content:c.join(`
|
|
10
10
|
`)}),c=[]),r=!0,o=!1,i=[],h=[]):d.startsWith("=======")&&r?o=!0:d.startsWith(">>>>>>>")&&r?(n.push({type:"conflict",ours:i.join(`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{bM as He,r as t,s as I,i as ye,bN as Ee,h as _e,j as e,I as z,u as fe,bO as ze,W as Te,bP as Ue,bQ as Be,n as We,bR as Ke,bS as De,bT as Ve,ag as Ge,ah as qe,ai as Ye,bd as Je,X as Me,S as oe,b7 as Xe,b4 as Qe,a7 as Ze,Y as Ie,ay as et,a2 as tt,bU as st,o as X,bV as nt}from"./main-
|
|
1
|
+
import{bM as He,r as t,s as I,i as ye,bN as Ee,h as _e,j as e,I as z,u as fe,bO as ze,W as Te,bP as Ue,bQ as Be,n as We,bR as Ke,bS as De,bT as Ve,ag as Ge,ah as qe,ai as Ye,bd as Je,X as Me,S as oe,b7 as Xe,b4 as Qe,a7 as Ze,Y as Ie,ay as et,a2 as tt,bU as st,o as X,bV as nt}from"./main-BhpZ8DMy.js";import{FileExplorerPanel as at}from"./index-DQhrNqbn.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const Ne={status:"all",activity:"all",sort:"activity"},lt={"1h":3600*1e3,"6h":360*60*1e3,"24h":1440*60*1e3},Ae=20,me=3,ot={idle:"#4aff9e",working:"#4a9eff",waiting:"#ff9e4a",waiting_permission:"#ffcc00",error:"#ff4a4a",offline:"#888888",orphaned:"#ff9e4a"},ct=12e4;function rt(s){return s.trim().replace(/\r\n/g,`
|
|
2
2
|
`)}function $e(s,a){return`${s}:${rt(a)}`}function it(s,a,l,f){if(s.uuid&&a.has(s.uuid))return!1;if(s.uuid)return!0;const p=s.isUserPrompt?"user":"assistant",d=$e(p,s.text),M=s.timestamp||0,A=l.get(d);return A!==void 0&&Math.abs(M-A)<=ct?!1:M>f}function dt({isOpen:s,agents:a}){const l=He(),[f,p]=t.useState(new Map),d=t.useRef(new Set);t.useRef(a);const M=t.useMemo(()=>Array.from(a.keys()).sort().join(","),[a]),A=t.useMemo(()=>Array.from(a.values()).map(j=>`${j.id}:${j.sessionId||""}`).sort().join(","),[a]);t.useEffect(()=>{s||(d.current.clear(),p(new Map))},[s]),t.useEffect(()=>{if(!s)return;const j=new Set(Array.from(a.keys()));for(const i of d.current)j.has(i)||d.current.delete(i);let h=null;l>0&&(h=I.preserveOutputs(),d.current.clear());const v=async(i,C,F=0)=>{if(d.current.add(i.id),F>0&&await new Promise(x=>setTimeout(x,F)),p(x=>{const k=new Map(x);return k.set(i.id,{agentId:i.id,messages:[],loading:!0,hasMore:!1,totalCount:0}),k}),!i.sessionId){C&&C.length>0&&I.mergeOutputsWithHistory(i.id,[],C),p(x=>{const k=new Map(x);return k.set(i.id,{agentId:i.id,messages:[],loading:!1,hasMore:!1,totalCount:0}),k});return}try{const k=await(await _e(ye(`/api/agents/${i.id}/history?limit=${Ee}&offset=0`))).json(),P=k.messages||[],K=P.length>0?Math.max(...P.map(w=>w.timestamp?new Date(w.timestamp).getTime():0)):0,Y=new Set(P.map(w=>w.uuid).filter(w=>!!w)),V=new Map;for(const w of P){if(w.type!=="user"&&w.type!=="assistant")continue;const c=$e(w.type,w.content),L=w.timestamp?new Date(w.timestamp).getTime():0,W=V.get(c)??0;L>W&&V.set(c,L)}const G=I.getOutputs(i.id),B=(C&&C.length>0?[...C,...G]:G).filter(w=>it(w,Y,V,K));I.clearOutputs(i.id);for(const w of B)I.addOutput(i.id,w);p(w=>{const c=new Map(w);return c.set(i.id,{agentId:i.id,messages:P,loading:!1,hasMore:k.hasMore||!1,totalCount:k.totalCount||0}),c})}catch(x){if(console.error(`Failed to load history for ${i.name}:`,x),C&&C.length>0){I.clearOutputs(i.id);for(const k of C)I.addOutput(i.id,k)}p(k=>{const P=new Map(k);return P.set(i.id,{agentId:i.id,messages:[],loading:!1,hasMore:!1,totalCount:0}),P})}},u=l>0?500:0,D=Array.from(a.values());for(const i of D)if(!d.current.has(i.id)){const C=h==null?void 0:h.get(i.id);v(i,C,u)}},[s,M,A,l]);const R=t.useRef(a),N=t.useRef(f);R.current=a,N.current=f;const b=t.useCallback(async j=>{const h=R.current.get(j),v=N.current.get(j);if(!(h!=null&&h.sessionId)||!v||!v.hasMore)return;const u=v.messages.length;try{const i=await(await fetch(ye(`/api/agents/${j}/history?limit=${Ee}&offset=${u}`))).json();i.messages&&i.messages.length>0&&p(C=>{const F=new Map(C),x=C.get(j);return x&&F.set(j,{...x,messages:[...i.messages,...x.messages],hasMore:i.hasMore||!1}),F})}catch(D){console.error(`Failed to load more history for agent ${j}:`,D)}},[]),E=t.useCallback(j=>{d.current.delete(j),p(h=>{const v=new Map(h),u=h.get(j);return u&&v.set(j,{...u,messages:[],hasMore:!1,totalCount:0,loading:!1}),v})},[]);return{histories:f,loadMoreHistory:b,clearAgentHistory:E}}function ut({command:s,onCommandChange:a,useTextarea:l,forceTextarea:f,onForceTextarea:p,onSend:d,canSend:M,attachedFiles:A,onAddFile:R,onRemoveFile:N,uploadFile:b,onAddPastedText:E,placeholder:j="Message...",className:h="",compact:v=!1,inputRef:u}){const D=t.useRef(null),i=t.useRef(null),C=t.useRef(l);t.useEffect(()=>{if(l&&!C.current&&i.current){const c=i.current;c.focus(),c.selectionStart=c.selectionEnd=c.value.length}C.current=l},[l]),t.useEffect(()=>{const c=i.current;if(!c||!l)return;c.style.height="auto";const L=v?120:180,W=Math.min(c.scrollHeight,L);c.style.height=`${W}px`},[s,l,v]);const F=t.useCallback(async c=>{const L=c.clipboardData.items;for(const _ of L)if(_.type.startsWith("image/")){c.preventDefault();const $=_.getAsFile();if($){const O=await b($);O&&R(O)}return}const W=c.clipboardData.files;if(W.length>0){c.preventDefault();for(const _ of W){const $=await b(_);$&&R($)}return}const U=c.clipboardData.getData("text"),te=(U.match(/\n/g)||[]).length+1;if(te>5){c.preventDefault();const $=`[Pasted text #${E(U)} +${te} lines]`,O=c.target,se=O.selectionStart||0,ae=O.selectionEnd||0,ne=s.slice(0,se)+$+s.slice(ae);a(ne),l||p(!0)}},[s,a,l,p,b,R,E]),x=t.useCallback(async c=>{const L=c.target.files;if(L){for(const W of L){const U=await b(W);U&&R(U)}D.current&&(D.current.value="")}},[b,R]),k=t.useCallback(c=>{if(c.key==="Enter"&&c.shiftKey){l||(c.preventDefault(),p(!0));return}c.key==="Enter"&&(c.preventDefault(),d())},[l,p,d]),P=t.useCallback(c=>{},[]),K=t.useCallback(c=>{c.button===1&&(c.preventDefault(),c.stopPropagation())},[]),Y=t.useCallback(c=>{i.current=c,u==null||u(c)},[u]),V=v?"agent-panel-input":"guake-input",G=v?"agent-panel-input-container":"guake-input-container",Q=v?"agent-panel-attach-btn":"guake-attach-btn",B=v?"agent-panel-send-btn":"",w=l?v?"agent-panel-input-expanded":"guake-input-expanded":"";return e.jsxs(e.Fragment,{children:[A.length>0&&e.jsx("div",{className:v?"agent-panel-attachments":"guake-attachments",children:A.map(c=>e.jsxs("div",{className:`${v?"agent-panel-attachment":"guake-attachment"} ${c.isImage?"is-image":""}`,children:[e.jsx("span",{className:v?"agent-panel-attachment-icon":"guake-attachment-icon",children:e.jsx(z,{name:c.isImage?"file":"paperclip",size:12})}),e.jsx("span",{className:v?"agent-panel-attachment-name":"guake-attachment-name",title:c.path,children:c.name}),!v&&e.jsxs("span",{className:"guake-attachment-size",children:["(",Math.round(c.size/1024),"KB)"]}),e.jsx("button",{className:v?"agent-panel-attachment-remove":"guake-attachment-remove",onClick:()=>N(c.id),title:"Remove",children:"×"})]},c.id))}),e.jsxs("div",{className:`${V} ${w} ${h}`,children:[e.jsx("input",{ref:D,type:"file",multiple:!0,onChange:x,style:{display:"none"},accept:"*"}),e.jsxs("div",{className:G,onAuxClick:K,children:[e.jsx("button",{className:Q,onClick:()=>{var c;return(c=D.current)==null?void 0:c.click()},title:"Attach file (or paste image)",children:e.jsx(z,{name:"paperclip",size:14})}),l?e.jsx("textarea",{ref:Y,placeholder:j,value:s,onChange:c=>a(c.target.value),onKeyDown:k,onPaste:F,onMouseDown:P}):e.jsx("input",{ref:u,type:"text",placeholder:j,value:s,onChange:c=>a(c.target.value),onKeyDown:k,onPaste:F,onMouseDown:P}),e.jsx("button",{className:B,onClick:d,disabled:!M,title:"Send",children:e.jsx(z,{name:"send",size:14})})]})]})]})}function mt(s){const a=Math.floor(s/1e3),l=Math.floor(a/60),f=a%60;return`${l}:${f.toString().padStart(2,"0")}`}const ft=t.memo(function({agentId:a,isWorking:l,timestamp:f}){const{t:p}=fe(["terminal"]),[d,M]=t.useState(0);return t.useEffect(()=>{if(!l||!f){M(0);return}M(Date.now()-f);const A=setInterval(()=>{M(Date.now()-f)},1e3);return()=>clearInterval(A)},[l,f]),l?e.jsxs("div",{className:"guake-stop-bar",children:[e.jsx("span",{className:"guake-elapsed-timer",children:mt(d)}),e.jsxs("button",{className:"guake-stop-btn",onClick:()=>I.stopAgent(a),title:p("terminal:input.stopOperation"),children:[e.jsx("span",{className:"stop-icon",children:e.jsx(z,{name:"stop",size:12,weight:"fill"})}),e.jsx("span",{className:"stop-label",children:p("terminal:input.stop")})]})]}):null});function pt({agent:s,history:a,outputs:l,isExpanded:f,isFocused:p,advancedView:d,onExpand:M,onFocus:A,inputRef:R,onLoadMore:N,onClearHistory:b}){const{t:E}=fe(["terminal","common"]),j=ze(s.id),h=t.useRef(null),[v,u]=t.useState(!1),D=t.useRef(0),i=t.useRef(!1),[C,F]=t.useState(!0),[x,k]=t.useState(!1),[P,K]=t.useState(null),[Y,V]=t.useState(null),[G,Q]=t.useState(null);Te(`commander-image-modal-${s.id}`,P!==null,()=>K(null));const{command:B,setCommand:w,forceTextarea:c,setForceTextarea:L,useTextarea:W,setPastedTexts:U,incrementPastedCount:te,resetPastedCount:_,attachedFiles:$,setAttachedFiles:O,removeAttachedFile:se,uploadFile:ae,expandPastedTexts:ne}=Ue({selectedAgentId:s.id}),le=B.trim().length>0||$.length>0,n=Be({outputs:l,viewMode:d?"advanced":"simple"}),o=t.useMemo(()=>{const S=We(s);return{usedPercent:S.usedPercent,freePercent:S.freePercent,hasData:!!s.contextStats,totalTokens:S.totalTokens,contextWindow:S.contextWindow}},[s.contextStats,s.contextUsed,s.contextLimit]),g=t.useCallback(()=>{!v&&(a!=null&&a.hasMore)&&N&&(u(!0),D.current=h.current?h.current.scrollHeight-h.current.scrollTop:0,N())},[v,a==null?void 0:a.hasMore,N]);t.useEffect(()=>{v&&a&&!a.loading&&u(!1)},[a,v]);const m=t.useCallback(()=>{i.current=!0,F(!1)},[]),T=t.useRef(f),Z=t.useRef(p);t.useEffect(()=>{(f&&!T.current||p&&!Z.current)&&(i.current=!1,F(!0),k(!0)),T.current=f,Z.current=p},[f,p]);const ee=t.useRef(a==null?void 0:a.loading);t.useEffect(()=>{ee.current&&!(a!=null&&a.loading)&&(i.current=!1,F(!0),k(!0)),ee.current=a==null?void 0:a.loading},[a==null?void 0:a.loading]),t.useEffect(()=>{if(!x)return;const S=h.current;if(!S)return;const y=performance.now();let H=0,ue=-1,ke;const Re=()=>{const{scrollTop:Fe,scrollHeight:Se,clientHeight:Le}=S,Oe=Se-Fe-Le<=2;if(Math.abs(Se-ue)<=1&&Oe?H+=1:H=0,ue=Se,H>=3){k(!1);return}if(performance.now()-y>5e3){k(!1);return}ke=requestAnimationFrame(Re)};return ke=requestAnimationFrame(Re),()=>cancelAnimationFrame(ke)},[x]),t.useEffect(()=>{i.current||F(!0)},[n.length]);const q=t.useCallback(()=>!1,[]),ie=t.useCallback(S=>{const y=te();return U(H=>new Map(H).set(y,S)),y},[te,U]),he=t.useCallback(S=>{O(y=>[...y,S])},[O]),xe=t.useCallback(()=>{if(!le)return;if(B.trim()==="/clear"&&$.length===0){I.clearContext(s.id),b(),w(""),L(!1),U(new Map),O([]),_();return}let S=ne(B.trim());if($.length>0){const y=$.map(H=>H.isImage?`[Image: ${H.path}]`:`[File: ${H.path}]`).join(`
|
|
3
3
|
`);S=S?`${S}
|
|
4
4
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/web-
|
|
2
|
-
import{cQ as e,bY as o}from"./main-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/web-Cx4v8f8d.js","assets/main-BhpZ8DMy.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-Chj50gSY.js","assets/main-ijcbyjBn.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{cQ as e,bY as o}from"./main-BhpZ8DMy.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";var i;(function(r){r.Heavy="HEAVY",r.Medium="MEDIUM",r.Light="LIGHT"})(i||(i={}));var t;(function(r){r.Success="SUCCESS",r.Warning="WARNING",r.Error="ERROR"})(t||(t={}));const c=e("Haptics",{web:()=>o(()=>import("./web-Cx4v8f8d.js"),__vite__mapDeps([0,1,2,3,4])).then(r=>new r.HapticsWeb)});export{c as Haptics,i as ImpactStyle,t as NotificationType};
|