tide-commander 1.111.2 → 1.113.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/dist/assets/{BossLogsModal-DLTh_jKZ.js → BossLogsModal-Bc0DqA9X.js} +1 -1
- package/dist/assets/{BossSpawnModal-DzivoRl1.js → BossSpawnModal-D-HI5-Rm.js} +1 -1
- package/dist/assets/{ControlsModal-B8j6My0t.js → ControlsModal-CTIbjWJQ.js} +1 -1
- package/dist/assets/{DockerLogsModal-BNwx7lVp.js → DockerLogsModal-CZrAeIrY.js} +1 -1
- package/dist/assets/{EmbeddedEditor-CBoOoGL8.js → EmbeddedEditor-DeNPLdlN.js} +1 -1
- package/dist/assets/{GmailOAuthSetup-BACIjX54.js → GmailOAuthSetup-CVE2MUNk.js} +1 -1
- package/dist/assets/{GoogleOAuthSetup-BuASGyWh.js → GoogleOAuthSetup-DPVaJm-J.js} +1 -1
- package/dist/assets/{IframeModal-ckpeQpQB.js → IframeModal-D0Njx7nV.js} +1 -1
- package/dist/assets/{IntegrationsPanel-Dh7UOnTC.js → IntegrationsPanel-N8GC9dFw.js} +2 -2
- package/dist/assets/{LogViewerModal-Cj7Hv-mD.js → LogViewerModal-DXfAOI0h.js} +1 -1
- package/dist/assets/{MonitoringModal-Bx4vcjBr.js → MonitoringModal-uCFkCztW.js} +1 -1
- package/dist/assets/{PM2LogsModal-RBIjfi4J.js → PM2LogsModal-DGW_92OG.js} +1 -1
- package/dist/assets/{RestoreArchivedAreaModal-BBYlYIso.js → RestoreArchivedAreaModal-DWyz3iM2.js} +1 -1
- package/dist/assets/{Scene2DCanvas-CYB1Y5Wa.js → Scene2DCanvas-CNpWfkXW.js} +1 -1
- package/dist/assets/{SceneManager-6vk047Kd.js → SceneManager-EwY3yHEm.js} +1 -1
- package/dist/assets/{SkillsPanel-CRRypqdy.js → SkillsPanel-YTLlXzWr.js} +1 -1
- package/dist/assets/{SlackMultiInstanceSetup-DisMBGxX.js → SlackMultiInstanceSetup-bAWpygC_.js} +1 -1
- package/dist/assets/{SpawnModal-qiu5nT-F.js → SpawnModal-BWuxUbwF.js} +1 -1
- package/dist/assets/StatisticsModal-fsomOWqv.js +1 -0
- package/dist/assets/{SubordinateAssignmentModal-AUCAiGkE.js → SubordinateAssignmentModal-Cyhy71yX.js} +1 -1
- package/dist/assets/{TriggerManagerPanel-56SuYzNh.js → TriggerManagerPanel-BCDVqT8Q.js} +1 -1
- package/dist/assets/{WorkflowEditorPanel-H0IGkyMd.js → WorkflowEditorPanel-Btq2XPt5.js} +1 -1
- package/dist/assets/{index-94AqwQn0.js → index-BEm8Kg82.js} +1 -1
- package/dist/assets/{index-9NugNkE4.js → index-BPAwPCsE.js} +1 -1
- package/dist/assets/{index-DY395tVJ.js → index-C1Y50w20.js} +2 -2
- package/dist/assets/{index--3sQ1gHE.js → index-CMa6Bc5_.js} +3 -3
- package/dist/assets/{index-C-kx99MP.js → index-Cn-EYfAP.js} +1 -1
- package/dist/assets/{index-DFWA70Lq.js → index-DvzFVxNn.js} +1 -1
- package/dist/assets/{index-DZP3fZ3b.js → index-Glbq4ytE.js} +1 -1
- package/dist/assets/{index-pRI5GcXd.js → index-aMq5H0fp.js} +1 -1
- package/dist/assets/{index-Dv0tQnLX.js → index-qAdi3D_H.js} +1 -1
- package/dist/assets/main-BEfBoz8e.css +1 -0
- package/dist/assets/main-vfMoYhg1.js +214 -0
- package/dist/assets/{web-CccJFC0m.js → web-CMiQoHZs.js} +1 -1
- package/dist/assets/{web-CdhZGenV.js → web-DN5Nx28H.js} +1 -1
- package/dist/assets/{web-RZLwjKCT.js → web-ZMOcyRHy.js} +1 -1
- package/dist/index.html +2 -2
- package/dist/locales/de/terminal.json +1 -0
- package/dist/locales/en/terminal.json +1 -0
- package/dist/locales/es/terminal.json +1 -0
- package/dist/locales/fr/terminal.json +1 -0
- package/dist/locales/hi/terminal.json +1 -0
- package/dist/locales/it/terminal.json +1 -0
- package/dist/locales/ja/terminal.json +1 -0
- package/dist/locales/pt/terminal.json +1 -0
- package/dist/locales/ru/terminal.json +1 -0
- package/dist/locales/zh-CN/terminal.json +1 -0
- package/dist/src/packages/server/claude/backend.js +2 -0
- package/dist/src/packages/server/data/builtin-skills/boss-instructions.js +1 -1
- package/dist/src/packages/server/routes/agents.js +17 -1
- package/dist/src/packages/server/services/claude-usage-service.js +164 -9
- package/dist/src/packages/server/services/llm-matcher-service.js +5 -0
- package/dist/src/packages/shared/agent-types.js +2 -0
- package/package.json +1 -1
- package/dist/assets/StatisticsModal-Bzk7qqOd.js +0 -1
- package/dist/assets/main-BUSv52j9.css +0 -1
- package/dist/assets/main-Bon1sZAi.js +0 -214
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ad as as,u as ts,au as vs,av as bs,aw as zs,j as s,I as F,_ as Is,ax as Es,ay as $s,az as Ds,aA as Ms,r as c,a3 as Ls,ak as Ss,W as Xs,U as Ps,H as Rs,aB as Ys,aC as Gs,aD as Us,aE as ms,aF as _s,s as M,aG as Fs,n as U}from"./main-Bon1sZAi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const fs=as.memo(({agent:a,isSelected:A,isKeyboardFocused:L=!1,onSelect:S,onDoubleClick:n,onChat:g,onFocus:h,onKill:w,onDragStart:X})=>{const{t:x}=ts(["dashboard","common"]),P=vs().has(a.id),N=bs(a.status),H=zs(a),j=Ms(H),I=a.taskLabel?s.jsxs(s.Fragment,{children:[s.jsx(F,{name:"task",size:12})," ",a.taskLabel]}):a.currentTask||a.lastAssignedTask,m=a.status==="idle"&&a.lastActivity>0,[,B]=as.useState(0);return as.useEffect(()=>{if(!m)return;const b=window.setInterval(()=>B(T=>T+1),15e3);return()=>window.clearInterval(b)},[m]),s.jsxs("div",{className:`dash-card dash-card--${N} ${A?"dash-card--selected":""} ${L?"dash-card--keyboard-focused":""}`,"data-agent-id":a.id,onClick:S,onDoubleClick:b=>{b.stopPropagation(),n()},onDragStart:b=>{X==null||X(a),b.dataTransfer.effectAllowed="move"},draggable:!0,title:x("cards.doubleClickHint"),children:[s.jsxs("div",{className:"dash-card__row1",children:[s.jsx("span",{className:`dash-card__status-dot dash-card__status-dot--${N}`}),s.jsx("span",{className:"dash-card__name",children:a.name}),s.jsxs("span",{className:"dash-card__class",children:[s.jsx(Is,{agent:a,size:14})," ",a.class]}),s.jsxs("span",{className:`dash-card__provider dash-card__provider--${a.provider}`,children:[s.jsx(F,{name:a.provider==="codex"||a.provider==="opencode"?"status-pending":"robot",size:11,weight:a.provider==="codex"||a.provider==="opencode"?"fill":"regular",color:a.provider==="codex"?"#a16207":a.provider==="opencode"?"#4ade80":void 0})," ",a.provider]}),P&&s.jsx("span",{className:"dash-card__unseen-badge",title:"New output available - click to view",children:"!"})]}),s.jsxs("div",{className:"dash-card__row2",children:[s.jsx("span",{className:`dash-card__status dash-card__status--${N}`,children:P?"Unseen":a.status}),s.jsxs("div",{className:"dash-card__context",children:[s.jsx("div",{className:"dash-card__context-bar",children:s.jsx("div",{className:`dash-card__context-fill dash-card__context-fill--${j}`,style:{width:`${H}%`}})}),s.jsxs("span",{className:`dash-card__context-pct dash-card__context-pct--${j}`,children:[H,"%"]})]})]}),s.jsxs("div",{className:"dash-card__row3",children:[s.jsxs("span",{className:"dash-card__workdir",title:a.cwd,children:[s.jsx(F,{name:"folder",size:11})," ",a.cwd.split("/").pop()||a.cwd]}),m&&s.jsxs("span",{className:"dash-card__idle-time",style:{color:Ds(a.lastActivity)},title:$s(a.lastActivity),children:[s.jsx(F,{name:"status-waiting-input",size:10})," ",Es(a.lastActivity)]})]}),I&&s.jsx("div",{className:"dash-card__row4",children:s.jsx("span",{className:"dash-card__task",children:I})}),s.jsxs("div",{className:"dash-card__actions",children:[g&&s.jsx("button",{className:"dash-card__action-btn dash-card__action-btn--chat",onClick:b=>{b.stopPropagation(),g()},title:x("cards.openTerminal"),children:x("cards.chat")}),w&&s.jsx("button",{className:"dash-card__action-btn dash-card__action-btn--danger",onClick:b=>{b.stopPropagation(),w()},title:x("cards.killAgent"),children:x("cards.stop")})]})]})});fs.displayName="AgentCard";const ws=({buildings:a,onSelectBuilding:A})=>{const{t:L}=ts(["dashboard"]),S=c.useMemo(()=>Array.from(a.values()).sort((n,g)=>n.name.localeCompare(g.name)),[a]);return s.jsxs("div",{className:"dashboard-view__buildings",children:[s.jsxs("div",{className:"dashboard-view__buildings-header",children:[s.jsx("span",{className:"dashboard-view__buildings-title",children:L("buildings.title")}),s.jsx("span",{className:"dashboard-view__buildings-count",children:S.length})]}),s.jsx("div",{className:"dashboard-view__buildings-row",children:S.map(n=>{const g=bs(n.status),h=Ls(n.type);return s.jsxs("button",{className:`dash-pill dash-pill--${g}`,onClick:()=>A==null?void 0:A(n.id),title:`${n.name} (${n.type}) - ${n.status}`,children:[s.jsx("span",{className:"dash-pill__icon",children:s.jsx(F,{name:h,size:14})}),s.jsx("span",{className:"dash-pill__name",children:n.name}),s.jsx("span",{className:`dash-pill__dot dash-pill__dot--${g}`})]},n.id)})})]})};ws.displayName="BuildingPills";function Zs({onSelectAgent:a,onFocusAgent:A,onKillAgent:L,onSelectBuilding:S,onOpenTerminal:n,onFocusZone:g}){const{t:h}=ts(["dashboard","common"]),w=Ss(),X=Xs(),x=Ps(),rs=Rs(),P=vs(),[N,H]=c.useState(""),[j,I]=c.useState("all"),[m,B]=c.useState("zone"),[b,T]=c.useState(new Set),[k,J]=c.useState(null),[ps,Z]=c.useState(null),[R,Q]=c.useState(!1),[p,W]=c.useState(null),K=c.useMemo(()=>{const e=Array.from(w.values());return{total:e.length,working:e.filter(i=>i.status==="working"||i.status==="waiting"||i.status==="waiting_permission").length,idle:e.filter(i=>i.status==="idle").length,error:e.filter(i=>i.status==="error"||i.status==="offline"||i.status==="orphaned").length}},[w]),ns=c.useMemo(()=>m==="zone"?Ys(w,x):m==="status"?Gs(w,P):Us(w),[w,x,m,P]),V=c.useMemo(()=>{const e=N.toLowerCase().trim(),i=ns.map(l=>({...l,agents:l.agents.filter(_=>{if(j==="working"){if(_.status!=="working"&&_.status!=="waiting"&&_.status!=="waiting_permission")return!1}else if(j==="error"&&_.status!=="error"&&_.status!=="offline"&&_.status!=="orphaned")return!1;return!(e&&!_.name.toLowerCase().includes(e)&&!_.class.toLowerCase().includes(e))})}));return m==="zone"?i:i.filter(l=>l.agents.length>0)},[ns,j,N,m]),O=c.useCallback(e=>e.area?`area:${e.area.id}`:`${m}:${e.label}`,[m]),C=c.useMemo(()=>{const e=[];return V.forEach(i=>{const l=O(i);if(b.has(l))return;const _=m==="status"?ms(i.agents,{prioritizeRecentlyIdle:!0}):_s(i.agents);e.push(..._)}),e},[V,b,m,O]),gs=c.useCallback(e=>{T(i=>{const l=new Set(i);return l.has(e)?l.delete(e):l.add(e),l})},[]),xs=c.useCallback(e=>{n==null||n(e)},[n]),js=c.useCallback(e=>{J(e)},[]),Ns=c.useCallback((e,i)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",Z(i)},[]),ks=c.useCallback(()=>{Z(null)},[]),Cs=c.useCallback(e=>{if(!k)return;if(e===null){const E=M.getState(),t=Array.from(E.areas.values()).find(r=>r.assignedAgentIds.includes(k.id));t&&M.unassignAgentFromArea(k.id,t.id),J(null),Z(null);return}const i=x.get(e);if(!i)return;const l=Array.from(w.values()),_=Fs(i,l,k.position);M.updateAgent({...k,position:{...k.position,x:_.x,z:_.z}}),M.assignAgentToArea(k.id,e),J(null),Z(null)},[k,x,w]);return c.useEffect(()=>{if(C.length===0){Q(!1),W(null);return}R&&(!p||!C.some(e=>e.id===p))&&(W(C[0].id),a==null||a(C[0].id))},[C,R,p,a]),c.useEffect(()=>{const e=t=>t instanceof HTMLElement?t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT"||t.isContentEditable:!1,i=t=>t instanceof HTMLElement?!!t.closest(".guake-terminal")||t.classList.contains("guake-input")||t.classList.contains("agent-panel-input"):!1,l=t=>{const r=Array.from(document.querySelectorAll(".dash-card[data-agent-id]")).find(z=>z.dataset.agentId===t);r==null||r.scrollIntoView({block:"nearest",inline:"nearest"})},_=(t,r)=>{var ds,os,cs,ls,us,hs;const z=Array.from(document.querySelectorAll(".dash-card[data-agent-id]")).map(d=>{const u=d.dataset.agentId;if(!u)return null;const y=d.getBoundingClientRect();return{id:u,centerX:y.left+y.width/2,centerY:y.top+y.height/2,height:y.height}}).filter(d=>d!==null).sort((d,u)=>d.centerY-u.centerY||d.centerX-u.centerX);if(z.length===0)return t;const ss=z.reduce((d,u)=>d+u.height,0)/z.length,es=Math.max(18,ss*.6),f=[];for(const d of z){const u=f[f.length-1];if(!u){f.push([{id:d.id,centerX:d.centerX,centerY:d.centerY}]);continue}const y=u.reduce((ys,As)=>ys+As.centerY,0)/u.length;Math.abs(d.centerY-y)<=es?u.push({id:d.id,centerX:d.centerX,centerY:d.centerY}):f.push([{id:d.id,centerX:d.centerX,centerY:d.centerY}])}f.forEach(d=>d.sort((u,y)=>u.centerX-y.centerX));const Y=f.findIndex(d=>d.some(u=>u.id===t));if(Y===-1)return((os=(ds=f[0])==null?void 0:ds[0])==null?void 0:os.id)??t;const $=f[Y],v=$.findIndex(d=>d.id===t);if(v===-1)return((ls=(cs=f[0])==null?void 0:cs[0])==null?void 0:ls.id)??t;if(r==="left")return((us=$[Math.max(0,v-1)])==null?void 0:us.id)??t;if(r==="right")return((hs=$[Math.min($.length-1,v+1)])==null?void 0:hs.id)??t;const q=r==="up"?Math.max(0,Y-1):Math.min(f.length-1,Y+1),o=f[q],G=$[v].centerX;let D=o[0],is=Math.abs(D.centerX-G);for(const d of o){const u=Math.abs(d.centerX-G);u<is&&(D=d,is=u)}return(D==null?void 0:D.id)??t},E=t=>{const r=M.getShortcuts(),z=r.find(o=>o.id==="dashboard-selector-toggle"),ss=r.find(o=>o.id==="dashboard-vim-left"),es=r.find(o=>o.id==="dashboard-vim-down"),f=r.find(o=>o.id==="dashboard-vim-up"),Y=r.find(o=>o.id==="dashboard-vim-right"),$=r.find(o=>o.id==="open-terminal"),v=M.getState();if(e(t.target))if(!v.terminalOpen&&i(t.target)&&document.activeElement instanceof HTMLElement)document.activeElement.blur();else return;if(U(t,z)){if(C.length===0)return;t.preventDefault(),t.stopPropagation(),Q(!0),W(o=>{const G=o&&C.some(D=>D.id===o)?o:C[0].id;return a==null||a(G),window.setTimeout(()=>l(G),0),G});return}const q=U(t,ss)||t.key==="ArrowLeft"?"left":U(t,es)||t.key==="ArrowDown"?"down":U(t,f)||t.key==="ArrowUp"?"up":U(t,Y)||t.key==="ArrowRight"?"right":null;if(q&&R&&p){t.preventDefault(),t.stopPropagation();const o=_(p,q);o!==p&&(W(o),a==null||a(o),window.setTimeout(()=>l(o),0));return}if(U(t,$)){if(v.terminalOpen)return;if(R&&p&&v.agents.has(p)){t.preventDefault(),n==null||n(p);return}if(v.selectedAgentIds.size===1){t.preventDefault();const o=Array.from(v.selectedAgentIds)[0];n==null||n(o);return}if(v.lastSelectedAgentId&&v.agents.has(v.lastSelectedAgentId)){t.preventDefault(),n==null||n(v.lastSelectedAgentId);return}}};return document.addEventListener("keydown",E,!0),()=>document.removeEventListener("keydown",E,!0)},[C,R,p,n,a]),c.useEffect(()=>{const e=document.activeElement;e instanceof HTMLElement&&e.closest(".guake-terminal")&&!M.getState().terminalOpen&&e.blur()},[]),s.jsxs("div",{className:"dashboard-view",children:[s.jsxs("div",{className:"dashboard-view__topbar",children:[s.jsxs("div",{className:"dashboard-view__metrics",children:[s.jsxs("button",{className:`dashboard-view__metric-btn ${j==="all"?"dashboard-view__metric-btn--active":""}`,onClick:()=>I("all"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.total}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:labels.agents")})]}),s.jsxs("button",{className:`dashboard-view__metric-btn dashboard-view__metric-btn--working ${j==="working"?"dashboard-view__metric-btn--active":""}`,onClick:()=>I("working"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.working}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:status.working")})]}),s.jsxs("button",{className:"dashboard-view__metric-btn dashboard-view__metric-btn--idle ",onClick:()=>I("all"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.idle}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:status.idle")})]}),s.jsxs("button",{className:`dashboard-view__metric-btn dashboard-view__metric-btn--error ${j==="error"?"dashboard-view__metric-btn--active":""}`,onClick:()=>I("error"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.error}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:status.error")})]})]}),s.jsx("input",{className:"dashboard-view__search",type:"text",placeholder:h("searchPlaceholder"),value:N,onChange:e=>H(e.target.value)})]}),s.jsxs("div",{className:"dashboard-view__grouping",children:[s.jsx("button",{className:`dashboard-view__grouping-btn ${m==="zone"?"dashboard-view__grouping-btn--active":""}`,onClick:()=>B("zone"),children:h("grouping.byZone")}),s.jsx("button",{className:`dashboard-view__grouping-btn ${m==="status"?"dashboard-view__grouping-btn--active":""}`,onClick:()=>B("status"),children:h("grouping.byStatus")}),s.jsx("button",{className:`dashboard-view__grouping-btn ${m==="activity"?"dashboard-view__grouping-btn--active":""}`,onClick:()=>B("activity"),children:h("grouping.byActivity")})]}),s.jsxs("div",{className:"dashboard-view__content",children:[V.map(e=>{const i=O(e),l=b.has(i),_=m==="status"?ms(e.agents,{prioritizeRecentlyIdle:!0}):_s(e.agents),E=e.agents.filter(r=>r.status==="working"||r.status==="waiting"||r.status==="waiting_permission").length,t=e.agents.filter(r=>P.has(r.id)).length;return s.jsxs("div",{className:`dashboard-view__zone ${ps===(e.area?e.area.id:null)&&k?"dashboard-view__zone--drag-over":""}`,onDragOver:r=>Ns(r,e.area?e.area.id:null),onDragLeave:ks,onDrop:()=>Cs(e.area?e.area.id:null),children:[s.jsxs("div",{className:"dashboard-view__zone-header",onClick:()=>gs(i),children:[s.jsxs("div",{className:"dashboard-view__zone-left",children:[s.jsx("span",{className:`dashboard-view__zone-chevron ${l?"dashboard-view__zone-chevron--collapsed":""}`,children:s.jsx(F,{name:"caret-down",size:12})}),s.jsx("span",{className:"dashboard-view__zone-dot",style:{backgroundColor:e.color}}),s.jsx("span",{className:"dashboard-view__zone-name",children:e.label}),s.jsxs("span",{className:"dashboard-view__zone-count",children:[h("agentCount",{count:e.agents.length}),E>0&&s.jsxs("span",{className:"dashboard-view__zone-working",children:[" · ",E," ",h("working")]}),t>0&&s.jsxs("span",{className:"dashboard-view__zone-unseen",children:[" · ",t," Unseen"]})]})]}),e.area&&g&&s.jsx("button",{className:"dashboard-view__zone-focus",onClick:r=>{r.stopPropagation(),g(e.area.id)},title:h("focusZone"),children:h("focusZone")})]}),!l&&s.jsx("div",{className:"dashboard-view__zone-grid",children:_.map(r=>s.jsx(fs,{agent:r,isSelected:rs.has(r.id),isKeyboardFocused:R&&p===r.id,onSelect:()=>{a==null||a(r.id),Q(!0),W(r.id)},onDoubleClick:()=>xs(r.id),onChat:()=>n==null?void 0:n(r.id),onFocus:A?()=>A(r.id):void 0,onKill:L?()=>L(r.id):void 0,onDragStart:js},r.id))})]},i)}),V.length===0&&s.jsx("div",{className:"dashboard-view__empty",children:N?h("noAgentsMatching",{search:N}):h("noAgentsSpawned")}),X.size>0&&s.jsx(ws,{buildings:X,onSelectBuilding:S})]})]})}export{Zs as DashboardView};
|
|
1
|
+
import{ad as as,u as ts,au as vs,av as bs,aw as zs,j as s,I as F,_ as Is,ax as Es,ay as $s,az as Ds,aA as Ms,r as c,a3 as Ls,ak as Ss,W as Xs,U as Ps,H as Rs,aB as Ys,aC as Gs,aD as Us,aE as ms,aF as _s,s as M,aG as Fs,n as U}from"./main-vfMoYhg1.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const fs=as.memo(({agent:a,isSelected:A,isKeyboardFocused:L=!1,onSelect:S,onDoubleClick:n,onChat:g,onFocus:h,onKill:w,onDragStart:X})=>{const{t:x}=ts(["dashboard","common"]),P=vs().has(a.id),N=bs(a.status),H=zs(a),j=Ms(H),I=a.taskLabel?s.jsxs(s.Fragment,{children:[s.jsx(F,{name:"task",size:12})," ",a.taskLabel]}):a.currentTask||a.lastAssignedTask,m=a.status==="idle"&&a.lastActivity>0,[,B]=as.useState(0);return as.useEffect(()=>{if(!m)return;const b=window.setInterval(()=>B(T=>T+1),15e3);return()=>window.clearInterval(b)},[m]),s.jsxs("div",{className:`dash-card dash-card--${N} ${A?"dash-card--selected":""} ${L?"dash-card--keyboard-focused":""}`,"data-agent-id":a.id,onClick:S,onDoubleClick:b=>{b.stopPropagation(),n()},onDragStart:b=>{X==null||X(a),b.dataTransfer.effectAllowed="move"},draggable:!0,title:x("cards.doubleClickHint"),children:[s.jsxs("div",{className:"dash-card__row1",children:[s.jsx("span",{className:`dash-card__status-dot dash-card__status-dot--${N}`}),s.jsx("span",{className:"dash-card__name",children:a.name}),s.jsxs("span",{className:"dash-card__class",children:[s.jsx(Is,{agent:a,size:14})," ",a.class]}),s.jsxs("span",{className:`dash-card__provider dash-card__provider--${a.provider}`,children:[s.jsx(F,{name:a.provider==="codex"||a.provider==="opencode"?"status-pending":"robot",size:11,weight:a.provider==="codex"||a.provider==="opencode"?"fill":"regular",color:a.provider==="codex"?"#a16207":a.provider==="opencode"?"#4ade80":void 0})," ",a.provider]}),P&&s.jsx("span",{className:"dash-card__unseen-badge",title:"New output available - click to view",children:"!"})]}),s.jsxs("div",{className:"dash-card__row2",children:[s.jsx("span",{className:`dash-card__status dash-card__status--${N}`,children:P?"Unseen":a.status}),s.jsxs("div",{className:"dash-card__context",children:[s.jsx("div",{className:"dash-card__context-bar",children:s.jsx("div",{className:`dash-card__context-fill dash-card__context-fill--${j}`,style:{width:`${H}%`}})}),s.jsxs("span",{className:`dash-card__context-pct dash-card__context-pct--${j}`,children:[H,"%"]})]})]}),s.jsxs("div",{className:"dash-card__row3",children:[s.jsxs("span",{className:"dash-card__workdir",title:a.cwd,children:[s.jsx(F,{name:"folder",size:11})," ",a.cwd.split("/").pop()||a.cwd]}),m&&s.jsxs("span",{className:"dash-card__idle-time",style:{color:Ds(a.lastActivity)},title:$s(a.lastActivity),children:[s.jsx(F,{name:"status-waiting-input",size:10})," ",Es(a.lastActivity)]})]}),I&&s.jsx("div",{className:"dash-card__row4",children:s.jsx("span",{className:"dash-card__task",children:I})}),s.jsxs("div",{className:"dash-card__actions",children:[g&&s.jsx("button",{className:"dash-card__action-btn dash-card__action-btn--chat",onClick:b=>{b.stopPropagation(),g()},title:x("cards.openTerminal"),children:x("cards.chat")}),w&&s.jsx("button",{className:"dash-card__action-btn dash-card__action-btn--danger",onClick:b=>{b.stopPropagation(),w()},title:x("cards.killAgent"),children:x("cards.stop")})]})]})});fs.displayName="AgentCard";const ws=({buildings:a,onSelectBuilding:A})=>{const{t:L}=ts(["dashboard"]),S=c.useMemo(()=>Array.from(a.values()).sort((n,g)=>n.name.localeCompare(g.name)),[a]);return s.jsxs("div",{className:"dashboard-view__buildings",children:[s.jsxs("div",{className:"dashboard-view__buildings-header",children:[s.jsx("span",{className:"dashboard-view__buildings-title",children:L("buildings.title")}),s.jsx("span",{className:"dashboard-view__buildings-count",children:S.length})]}),s.jsx("div",{className:"dashboard-view__buildings-row",children:S.map(n=>{const g=bs(n.status),h=Ls(n.type);return s.jsxs("button",{className:`dash-pill dash-pill--${g}`,onClick:()=>A==null?void 0:A(n.id),title:`${n.name} (${n.type}) - ${n.status}`,children:[s.jsx("span",{className:"dash-pill__icon",children:s.jsx(F,{name:h,size:14})}),s.jsx("span",{className:"dash-pill__name",children:n.name}),s.jsx("span",{className:`dash-pill__dot dash-pill__dot--${g}`})]},n.id)})})]})};ws.displayName="BuildingPills";function Zs({onSelectAgent:a,onFocusAgent:A,onKillAgent:L,onSelectBuilding:S,onOpenTerminal:n,onFocusZone:g}){const{t:h}=ts(["dashboard","common"]),w=Ss(),X=Xs(),x=Ps(),rs=Rs(),P=vs(),[N,H]=c.useState(""),[j,I]=c.useState("all"),[m,B]=c.useState("zone"),[b,T]=c.useState(new Set),[k,J]=c.useState(null),[ps,Z]=c.useState(null),[R,Q]=c.useState(!1),[p,W]=c.useState(null),K=c.useMemo(()=>{const e=Array.from(w.values());return{total:e.length,working:e.filter(i=>i.status==="working"||i.status==="waiting"||i.status==="waiting_permission").length,idle:e.filter(i=>i.status==="idle").length,error:e.filter(i=>i.status==="error"||i.status==="offline"||i.status==="orphaned").length}},[w]),ns=c.useMemo(()=>m==="zone"?Ys(w,x):m==="status"?Gs(w,P):Us(w),[w,x,m,P]),V=c.useMemo(()=>{const e=N.toLowerCase().trim(),i=ns.map(l=>({...l,agents:l.agents.filter(_=>{if(j==="working"){if(_.status!=="working"&&_.status!=="waiting"&&_.status!=="waiting_permission")return!1}else if(j==="error"&&_.status!=="error"&&_.status!=="offline"&&_.status!=="orphaned")return!1;return!(e&&!_.name.toLowerCase().includes(e)&&!_.class.toLowerCase().includes(e))})}));return m==="zone"?i:i.filter(l=>l.agents.length>0)},[ns,j,N,m]),O=c.useCallback(e=>e.area?`area:${e.area.id}`:`${m}:${e.label}`,[m]),C=c.useMemo(()=>{const e=[];return V.forEach(i=>{const l=O(i);if(b.has(l))return;const _=m==="status"?ms(i.agents,{prioritizeRecentlyIdle:!0}):_s(i.agents);e.push(..._)}),e},[V,b,m,O]),gs=c.useCallback(e=>{T(i=>{const l=new Set(i);return l.has(e)?l.delete(e):l.add(e),l})},[]),xs=c.useCallback(e=>{n==null||n(e)},[n]),js=c.useCallback(e=>{J(e)},[]),Ns=c.useCallback((e,i)=>{e.preventDefault(),e.dataTransfer.dropEffect="move",Z(i)},[]),ks=c.useCallback(()=>{Z(null)},[]),Cs=c.useCallback(e=>{if(!k)return;if(e===null){const E=M.getState(),t=Array.from(E.areas.values()).find(r=>r.assignedAgentIds.includes(k.id));t&&M.unassignAgentFromArea(k.id,t.id),J(null),Z(null);return}const i=x.get(e);if(!i)return;const l=Array.from(w.values()),_=Fs(i,l,k.position);M.updateAgent({...k,position:{...k.position,x:_.x,z:_.z}}),M.assignAgentToArea(k.id,e),J(null),Z(null)},[k,x,w]);return c.useEffect(()=>{if(C.length===0){Q(!1),W(null);return}R&&(!p||!C.some(e=>e.id===p))&&(W(C[0].id),a==null||a(C[0].id))},[C,R,p,a]),c.useEffect(()=>{const e=t=>t instanceof HTMLElement?t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT"||t.isContentEditable:!1,i=t=>t instanceof HTMLElement?!!t.closest(".guake-terminal")||t.classList.contains("guake-input")||t.classList.contains("agent-panel-input"):!1,l=t=>{const r=Array.from(document.querySelectorAll(".dash-card[data-agent-id]")).find(z=>z.dataset.agentId===t);r==null||r.scrollIntoView({block:"nearest",inline:"nearest"})},_=(t,r)=>{var ds,os,cs,ls,us,hs;const z=Array.from(document.querySelectorAll(".dash-card[data-agent-id]")).map(d=>{const u=d.dataset.agentId;if(!u)return null;const y=d.getBoundingClientRect();return{id:u,centerX:y.left+y.width/2,centerY:y.top+y.height/2,height:y.height}}).filter(d=>d!==null).sort((d,u)=>d.centerY-u.centerY||d.centerX-u.centerX);if(z.length===0)return t;const ss=z.reduce((d,u)=>d+u.height,0)/z.length,es=Math.max(18,ss*.6),f=[];for(const d of z){const u=f[f.length-1];if(!u){f.push([{id:d.id,centerX:d.centerX,centerY:d.centerY}]);continue}const y=u.reduce((ys,As)=>ys+As.centerY,0)/u.length;Math.abs(d.centerY-y)<=es?u.push({id:d.id,centerX:d.centerX,centerY:d.centerY}):f.push([{id:d.id,centerX:d.centerX,centerY:d.centerY}])}f.forEach(d=>d.sort((u,y)=>u.centerX-y.centerX));const Y=f.findIndex(d=>d.some(u=>u.id===t));if(Y===-1)return((os=(ds=f[0])==null?void 0:ds[0])==null?void 0:os.id)??t;const $=f[Y],v=$.findIndex(d=>d.id===t);if(v===-1)return((ls=(cs=f[0])==null?void 0:cs[0])==null?void 0:ls.id)??t;if(r==="left")return((us=$[Math.max(0,v-1)])==null?void 0:us.id)??t;if(r==="right")return((hs=$[Math.min($.length-1,v+1)])==null?void 0:hs.id)??t;const q=r==="up"?Math.max(0,Y-1):Math.min(f.length-1,Y+1),o=f[q],G=$[v].centerX;let D=o[0],is=Math.abs(D.centerX-G);for(const d of o){const u=Math.abs(d.centerX-G);u<is&&(D=d,is=u)}return(D==null?void 0:D.id)??t},E=t=>{const r=M.getShortcuts(),z=r.find(o=>o.id==="dashboard-selector-toggle"),ss=r.find(o=>o.id==="dashboard-vim-left"),es=r.find(o=>o.id==="dashboard-vim-down"),f=r.find(o=>o.id==="dashboard-vim-up"),Y=r.find(o=>o.id==="dashboard-vim-right"),$=r.find(o=>o.id==="open-terminal"),v=M.getState();if(e(t.target))if(!v.terminalOpen&&i(t.target)&&document.activeElement instanceof HTMLElement)document.activeElement.blur();else return;if(U(t,z)){if(C.length===0)return;t.preventDefault(),t.stopPropagation(),Q(!0),W(o=>{const G=o&&C.some(D=>D.id===o)?o:C[0].id;return a==null||a(G),window.setTimeout(()=>l(G),0),G});return}const q=U(t,ss)||t.key==="ArrowLeft"?"left":U(t,es)||t.key==="ArrowDown"?"down":U(t,f)||t.key==="ArrowUp"?"up":U(t,Y)||t.key==="ArrowRight"?"right":null;if(q&&R&&p){t.preventDefault(),t.stopPropagation();const o=_(p,q);o!==p&&(W(o),a==null||a(o),window.setTimeout(()=>l(o),0));return}if(U(t,$)){if(v.terminalOpen)return;if(R&&p&&v.agents.has(p)){t.preventDefault(),n==null||n(p);return}if(v.selectedAgentIds.size===1){t.preventDefault();const o=Array.from(v.selectedAgentIds)[0];n==null||n(o);return}if(v.lastSelectedAgentId&&v.agents.has(v.lastSelectedAgentId)){t.preventDefault(),n==null||n(v.lastSelectedAgentId);return}}};return document.addEventListener("keydown",E,!0),()=>document.removeEventListener("keydown",E,!0)},[C,R,p,n,a]),c.useEffect(()=>{const e=document.activeElement;e instanceof HTMLElement&&e.closest(".guake-terminal")&&!M.getState().terminalOpen&&e.blur()},[]),s.jsxs("div",{className:"dashboard-view",children:[s.jsxs("div",{className:"dashboard-view__topbar",children:[s.jsxs("div",{className:"dashboard-view__metrics",children:[s.jsxs("button",{className:`dashboard-view__metric-btn ${j==="all"?"dashboard-view__metric-btn--active":""}`,onClick:()=>I("all"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.total}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:labels.agents")})]}),s.jsxs("button",{className:`dashboard-view__metric-btn dashboard-view__metric-btn--working ${j==="working"?"dashboard-view__metric-btn--active":""}`,onClick:()=>I("working"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.working}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:status.working")})]}),s.jsxs("button",{className:"dashboard-view__metric-btn dashboard-view__metric-btn--idle ",onClick:()=>I("all"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.idle}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:status.idle")})]}),s.jsxs("button",{className:`dashboard-view__metric-btn dashboard-view__metric-btn--error ${j==="error"?"dashboard-view__metric-btn--active":""}`,onClick:()=>I("error"),children:[s.jsx("span",{className:"dashboard-view__metric-value",children:K.error}),s.jsx("span",{className:"dashboard-view__metric-label",children:h("common:status.error")})]})]}),s.jsx("input",{className:"dashboard-view__search",type:"text",placeholder:h("searchPlaceholder"),value:N,onChange:e=>H(e.target.value)})]}),s.jsxs("div",{className:"dashboard-view__grouping",children:[s.jsx("button",{className:`dashboard-view__grouping-btn ${m==="zone"?"dashboard-view__grouping-btn--active":""}`,onClick:()=>B("zone"),children:h("grouping.byZone")}),s.jsx("button",{className:`dashboard-view__grouping-btn ${m==="status"?"dashboard-view__grouping-btn--active":""}`,onClick:()=>B("status"),children:h("grouping.byStatus")}),s.jsx("button",{className:`dashboard-view__grouping-btn ${m==="activity"?"dashboard-view__grouping-btn--active":""}`,onClick:()=>B("activity"),children:h("grouping.byActivity")})]}),s.jsxs("div",{className:"dashboard-view__content",children:[V.map(e=>{const i=O(e),l=b.has(i),_=m==="status"?ms(e.agents,{prioritizeRecentlyIdle:!0}):_s(e.agents),E=e.agents.filter(r=>r.status==="working"||r.status==="waiting"||r.status==="waiting_permission").length,t=e.agents.filter(r=>P.has(r.id)).length;return s.jsxs("div",{className:`dashboard-view__zone ${ps===(e.area?e.area.id:null)&&k?"dashboard-view__zone--drag-over":""}`,onDragOver:r=>Ns(r,e.area?e.area.id:null),onDragLeave:ks,onDrop:()=>Cs(e.area?e.area.id:null),children:[s.jsxs("div",{className:"dashboard-view__zone-header",onClick:()=>gs(i),children:[s.jsxs("div",{className:"dashboard-view__zone-left",children:[s.jsx("span",{className:`dashboard-view__zone-chevron ${l?"dashboard-view__zone-chevron--collapsed":""}`,children:s.jsx(F,{name:"caret-down",size:12})}),s.jsx("span",{className:"dashboard-view__zone-dot",style:{backgroundColor:e.color}}),s.jsx("span",{className:"dashboard-view__zone-name",children:e.label}),s.jsxs("span",{className:"dashboard-view__zone-count",children:[h("agentCount",{count:e.agents.length}),E>0&&s.jsxs("span",{className:"dashboard-view__zone-working",children:[" · ",E," ",h("working")]}),t>0&&s.jsxs("span",{className:"dashboard-view__zone-unseen",children:[" · ",t," Unseen"]})]})]}),e.area&&g&&s.jsx("button",{className:"dashboard-view__zone-focus",onClick:r=>{r.stopPropagation(),g(e.area.id)},title:h("focusZone"),children:h("focusZone")})]}),!l&&s.jsx("div",{className:"dashboard-view__zone-grid",children:_.map(r=>s.jsx(fs,{agent:r,isSelected:rs.has(r.id),isKeyboardFocused:R&&p===r.id,onSelect:()=>{a==null||a(r.id),Q(!0),W(r.id)},onDoubleClick:()=>xs(r.id),onChat:()=>n==null?void 0:n(r.id),onFocus:A?()=>A(r.id):void 0,onKill:L?()=>L(r.id):void 0,onDragStart:js},r.id))})]},i)}),V.length===0&&s.jsx("div",{className:"dashboard-view__empty",children:N?h("noAgentsMatching",{search:N}):h("noAgentsSpawned")}),X.size>0&&s.jsx(ws,{buildings:X,onSelectBuilding:S})]})]})}export{Zs as DashboardView};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/web-
|
|
2
|
-
import{
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/web-ZMOcyRHy.js","assets/main-vfMoYhg1.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-Chj50gSY.js","assets/main-BEfBoz8e.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{cd as e,bD as o}from"./main-vfMoYhg1.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-ZMOcyRHy.js"),__vite__mapDeps([0,1,2,3,4])).then(r=>new r.HapticsWeb)});export{c as Haptics,i as ImpactStyle,t as NotificationType};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/EmbeddedEditor-
|
|
2
|
-
import{r as s,aM as Y,l as K,a_ as Kt,M as $s,S as Rt,N as Hs,s as mt,u as le,j as e,I as M,bB as Ft,f as zs,bC as As,bD as Rn,bE as Os,bF as Gs,bG as Fn,bH as In,bI as Tt,bJ as Pn,bK as Ln,bL as $n,bM as Xt,bN as Hn,bO as Us,bP as Mt,bQ as Dt,ac as it,bR as ft,bS as pt,bT as Es,bU as zn,b6 as An,bV as Jt,bW as On,bX as Gn,bY as Ss,C as Un,n as Bn}from"./main-Bon1sZAi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function _n(t){const[n,o]=s.useState(null),[c,r]=s.useState(!1),i=s.useCallback(async()=>{if(t){r(!0);try{const f=await Y(K(`/api/files/git-status?path=${encodeURIComponent(t)}`)),l=await f.json();f.ok?o(l):o({isGitRepo:!1,files:[]})}catch(f){console.error("[FileExplorer] Failed to load git status:",f),o({isGitRepo:!1,files:[]})}finally{r(!1)}}},[t]);return{gitStatus:n,loading:c,loadGitStatus:i}}async function Vn(t){try{const n=await Y(K(`/api/files/git-original?path=${encodeURIComponent(t)}`)),o=await n.json();return n.ok&&!o.isNew?{content:o.content,isNew:!1}:{content:null,isNew:!0}}catch(n){return console.error("[FileExplorer] Failed to load original file:",n),{content:null,isNew:!0}}}const Kn=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",""]),Wn=new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".ico",".svg"]),Yn=new Set([".pdf"]),qn=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 Jn(t){const n=t.toLowerCase();return Wn.has(n)?"image":Yn.has(n)?"pdf":qn.has(n)?"binary":(Kn.has(n),"text")}function Xn(){const[t,n]=s.useState(null),[o,c]=s.useState(!1),[r,i]=s.useState(null),f=s.useCallback(async u=>{var g,j;c(!0),i(null);try{const p=u.substring(u.lastIndexOf(".")).toLowerCase(),y=Jn(p),C=u.substring(u.lastIndexOf("/")+1);if(y==="image"){const N=await Y(K(`/api/files/binary?path=${encodeURIComponent(u)}`));if(!N.ok){const w=await N.json().catch(()=>({error:"Failed to load image"}));i(w.error||"Failed to load image"),n(null);return}const d=await N.blob(),v=URL.createObjectURL(d);n({path:u,filename:C,extension:p,content:"",size:d.size,modified:new Date().toISOString(),fileType:"image",dataUrl:v});return}if(y==="pdf"){const N=await Y(K(`/api/files/info?path=${encodeURIComponent(u)}`)),d=await N.json();if(!N.ok){i(d.error||"Failed to load PDF info"),n(null);return}n({path:u,filename:C,extension:p,content:"",size:d.size,modified:d.modified,fileType:"pdf",dataUrl:K(`/api/files/binary?path=${encodeURIComponent(u)}&token=${encodeURIComponent(Kt())}`)});return}if(y==="binary"){const N=await Y(K(`/api/files/info?path=${encodeURIComponent(u)}`)),d=await N.json();if(!N.ok){i(d.error||"Failed to load file info"),n(null);return}n({path:u,filename:C,extension:p,content:"",size:d.size,modified:d.modified,fileType:"binary",dataUrl:K(`/api/files/binary?path=${encodeURIComponent(u)}&download=true&token=${encodeURIComponent(Kt())}`)});return}const R=await Y(K(`/api/files/read?path=${encodeURIComponent(u)}`)),x=await R.json();if(!R.ok){if((g=x.error)!=null&&g.includes("too large")||(j=x.error)!=null&&j.includes("binary")){const N=await Y(K(`/api/files/info?path=${encodeURIComponent(u)}`)),d=await N.json();if(N.ok){n({path:u,filename:C,extension:p,content:"",size:d.size,modified:d.modified,fileType:"binary",dataUrl:K(`/api/files/binary?path=${encodeURIComponent(u)}&download=true&token=${encodeURIComponent(Kt())}`)});return}}i(x.error||"Failed to load file"),n(null);return}n({...x,fileType:"text"})}catch(p){const y=p instanceof Error?p.message:"Failed to load file";i(y),n(null)}finally{c(!1)}},[]),l=s.useCallback(()=>{n(u=>(u!=null&&u.dataUrl&&u.dataUrl.startsWith("blob:")&&URL.revokeObjectURL(u.dataUrl),null)),i(null)},[]);return{file:t,loading:o,error:r,loadFile:f,clearFile:l,setFile:n}}const Wt="file-explorer-state",Qn=10080*60*1e3;function Zn(t,n){return n?`${Wt}-folder-${n}`:t?`${Wt}-area-${t}`:`${Wt}-default`}async function ea(t){try{const n=await Y(K(`/api/files/exists?path=${encodeURIComponent(t)}`));return n.ok?(await n.json()).exists===!0:!1}catch{return!1}}function ta({areaId:t,folderPath:n,isOpen:o}){const c=Zn(t,n),r=s.useRef(!1);s.useEffect(()=>{r.current=!1},[t,n]);const i=s.useCallback(async()=>{if(r.current)return null;r.current=!0;try{const l=localStorage.getItem(c);if(!l)return null;const u=JSON.parse(l);if(Date.now()-u.timestamp>Qn)return localStorage.removeItem(c),null;const j=(await Promise.all(u.tabs.map(async y=>({tab:y,exists:await ea(y.path)})))).filter(({exists:y})=>y).map(({tab:y})=>y);let p=u.activeTabPath;return p&&!j.some(y=>y.path===p)&&(p=j.length>0?j[0].path:null),{tabs:j,activeTabPath:p,viewMode:u.viewMode||"files",selectedFolderIndex:u.selectedFolderIndex||0,expandedPaths:new Set(u.expandedPaths||[])}}catch(l){return console.error("[FileExplorerStorage] Failed to load state:",l),null}},[c]),f=s.useCallback(l=>{if(o)try{const u={tabs:l.tabs,activeTabPath:l.activeTabPath,viewMode:l.viewMode,selectedFolderIndex:l.selectedFolderIndex,expandedPaths:Array.from(l.expandedPaths),timestamp:Date.now()};localStorage.setItem(c,JSON.stringify(u))}catch(u){console.error("[FileExplorerStorage] Failed to save state:",u)}},[c,o]);return{loadStoredState:i,saveState:f}}const Ts=280,Ms=150,Ds=1200;function sa(){const[t,n]=s.useState(()=>{const g=$s(Rt.TREE_PANEL_WIDTH,Ts);return g>=Ms&&g<=Ds?g:Ts}),o=s.useRef(!1),[c,r]=s.useState(!1),i=s.useRef(0),f=s.useRef(0),l=s.useRef(t);l.current=t;const u=s.useCallback(g=>{g.preventDefault(),o.current=!0,r(!0),i.current=g.clientX,f.current=t,document.body.style.cursor="ew-resize",document.body.style.userSelect="none"},[t]);return s.useEffect(()=>{const g=p=>{if(!o.current)return;const y=p.clientX-i.current,C=Math.min(Ds,Math.max(Ms,f.current+y));n(C)},j=()=>{o.current&&(o.current=!1,r(!1),document.body.style.cursor="",document.body.style.userSelect="",Hs(Rt.TREE_PANEL_WIDTH,l.current))};return document.addEventListener("mousemove",g),document.addEventListener("mouseup",j),()=>{document.removeEventListener("mousemove",g),document.removeEventListener("mouseup",j)}},[]),{treePanelWidth:t,handleResizeStart:u,isResizing:c}}const na=100,aa=.65,ra=36;function ia(){const[t,n]=s.useState(()=>$s(Rt.MOBILE_TREE_PANEL_HEIGHT,0)),o=s.useRef(t);o.current=t;const c=s.useRef(0),r=s.useRef(0),i=()=>Math.floor((window.innerHeight-ra)*aa),f=p=>Math.min(i(),Math.max(na,p)),l=s.useCallback(p=>{n(p);const y=document.querySelector(".file-explorer-main");y&&y.style.setProperty("--fe-mobile-tree-height",`${p}px`)},[]),u=s.useCallback(()=>{document.body.style.cursor="",document.body.style.userSelect="",Hs(Rt.MOBILE_TREE_PANEL_HEIGHT,o.current),mt.setTerminalResizing(!1)},[]),g=s.useCallback(p=>{p.preventDefault();const y=document.querySelector(".file-explorer-tree-panel"),C=o.current>0?o.current:(y==null?void 0:y.getBoundingClientRect().height)??240;c.current=p.clientY,r.current=C,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",mt.setTerminalResizing(!0);const R=N=>{const d=N.clientY-c.current;l(f(r.current+d))},x=()=>{document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",x),u()};document.addEventListener("mousemove",R),document.addEventListener("mouseup",x)},[l,u]),j=s.useCallback(p=>{if(p.touches.length!==1)return;const y=document.querySelector(".file-explorer-tree-panel"),C=o.current>0?o.current:(y==null?void 0:y.getBoundingClientRect().height)??240;c.current=p.touches[0].clientY,r.current=C,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",mt.setTerminalResizing(!0);const R=N=>{if(N.touches.length!==1)return;N.preventDefault();const d=N.touches[0].clientY-c.current;l(f(r.current+d))},x=()=>{document.removeEventListener("touchmove",R),document.removeEventListener("touchend",x),document.removeEventListener("touchcancel",x),u()};document.addEventListener("touchmove",R,{passive:!1}),document.addEventListener("touchend",x),document.addEventListener("touchcancel",x)},[l,u]);return{mobileTreeHeight:t,handleResizeMouseDown:g,handleResizeTouchStart:j}}function Qt(){const[t,n]=s.useState([]),[o,c]=s.useState(!1),[r,i]=s.useState(null),[f,l]=s.useState(null),u=s.useCallback(async N=>{c(!0),i(null);try{const d=await Y(K(`/api/files/git-branches?path=${encodeURIComponent(N)}`)),v=await d.json();d.ok?n(v.branches||[]):(i(v.error||"Failed to load branches"),n([]))}catch(d){console.error("[GitBranches] Failed to load branches:",d),i("Failed to load branches"),n([])}finally{c(!1)}},[]),g=s.useCallback(async(N,d)=>{l("checkout"),i(null);try{const v=await Y(K("/api/files/git-checkout"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N,branch:d})}),w=await v.json();return v.ok||i(w.error||"Checkout failed"),w}catch(v){console.error("[GitBranches] Checkout failed:",v);const w={success:!1,error:"Checkout failed"};return i(w.error),w}finally{l(null)}},[]),j=s.useCallback(async(N,d,v)=>{l("create"),i(null);try{const w=await Y(K("/api/files/git-branch-create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N,name:d,startPoint:v})}),S=await w.json();return w.ok||i(S.error||"Failed to create branch"),S}catch(w){console.error("[GitBranches] Create branch failed:",w);const S={success:!1,error:"Failed to create branch"};return i(S.error),S}finally{l(null)}},[]),p=s.useCallback(async N=>{l("pull"),i(null);try{const d=await Y(K("/api/files/git-pull"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N})}),v=await d.json();return!d.ok&&!v.conflicts&&i(v.error||"Pull failed"),v}catch(d){console.error("[GitBranches] Pull failed:",d);const v={success:!1,error:"Pull failed"};return i(v.error),v}finally{l(null)}},[]),y=s.useCallback(async N=>{l("push"),i(null);try{const d=await Y(K("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N})}),v=await d.json();return d.ok||i(v.error||"Push failed"),v}catch(d){console.error("[GitBranches] Push failed:",d);const v={success:!1,error:"Push failed"};return i(v.error),v}finally{l(null)}},[]),C=s.useCallback(async(N,d)=>{l("merge"),i(null);try{const v=await Y(K("/api/files/git-merge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N,branch:d})}),w=await v.json();return!v.ok&&!w.conflicts&&i(w.error||"Merge failed"),w}catch(v){console.error("[GitBranches] Merge failed:",v);const w={success:!1,error:"Merge failed"};return i(w.error),w}finally{l(null)}},[]),R=s.useCallback(async N=>{l("merge-abort"),i(null);try{const d=await Y(K("/api/files/git-merge-abort"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N})}),v=await d.json();return d.ok||i(v.error||"Merge abort failed"),v}catch(d){console.error("[GitBranches] Merge abort failed:",d);const v={success:!1,error:"Merge abort failed"};return i(v.error),v}finally{l(null)}},[]),x=s.useCallback(async N=>{l("merge-continue"),i(null);try{const d=await Y(K("/api/files/git-merge-continue"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N})}),v=await d.json();return d.ok||i(v.error||"Merge continue failed"),v}catch(d){console.error("[GitBranches] Merge continue failed:",d);const v={success:!1,error:"Merge continue failed"};return i(v.error),v}finally{l(null)}},[]);return{branches:t,loading:o,error:r,operationInProgress:f,loadBranches:u,checkoutBranch:g,createBranch:j,pullFromRemote:p,pushToRemote:y,mergeBranch:C,mergeAbort:R,mergeContinue:x}}const la=50,oa=400,Rs={branch:"",author:"",since:"",until:"",searchPath:"",search:""};function ca(){const[t,n]=s.useState([]),[o,c]=s.useState(!1),[r,i]=s.useState(!1),[f,l]=s.useState(null),[u,g]=s.useState(!1),[j,p]=s.useState(0),[y,C]=s.useState({...Rs}),[R,x]=s.useState(null),[N,d]=s.useState([]),[v,w]=s.useState(!1),[S,A]=s.useState([]),[H,G]=s.useState(!1),z=s.useRef(null),ae=s.useRef(""),ee=s.useCallback((O,Z,L)=>{const T=L||y,W=new URLSearchParams;return W.set("path",O),W.set("limit",String(la)),W.set("offset",String(Z)),T.branch&&W.set("branch",T.branch),T.author&&W.set("author",T.author),T.since&&W.set("since",T.since),T.until&&W.set("until",T.until),T.searchPath&&W.set("searchPath",T.searchPath),T.search&&W.set("search",T.search),W.toString()},[y]),D=s.useCallback(async O=>{ae.current=O,c(!0),l(null),x(null),d([]);try{const Z=ee(O,0),L=await Y(K(`/api/files/git-log?${Z}`)),T=await L.json();L.ok?(n(T.commits||[]),p(T.total||0),g(T.hasMore||!1)):(l(T.error||"Failed to load git history"),n([]))}catch(Z){console.error("[useGitHistory] loadHistory error:",Z),l("Failed to load git history"),n([])}finally{c(!1)}},[ee]),F=s.useCallback(async O=>{if(!(r||!u)){i(!0);try{const Z=ee(O,t.length),L=await Y(K(`/api/files/git-log?${Z}`)),T=await L.json();L.ok&&(n(W=>[...W,...T.commits||[]]),p(T.total||0),g(T.hasMore||!1))}catch(Z){console.error("[useGitHistory] loadMore error:",Z)}finally{i(!1)}}},[ee,t.length,u,r]),I=s.useCallback(async O=>{if(x(O),!O){d([]);return}w(!0);try{const Z=ae.current,L=new URLSearchParams({path:Z,hash:O.hash}),T=await Y(K(`/api/files/git-commit-files?${L}`)),W=await T.json();T.ok?d(W.files||[]):d([])}catch(Z){console.error("[useGitHistory] selectCommit files error:",Z),d([])}finally{w(!1)}},[]),re=s.useCallback((O,Z)=>{C(L=>({...L,[O]:Z}))},[]),_=s.useCallback(()=>{C({...Rs})},[]);s.useEffect(()=>{const O=ae.current;if(O)return z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{D(O)},oa),()=>{z.current&&clearTimeout(z.current)}},[y]);const ge=s.useCallback(async O=>{G(!0);try{const Z=new URLSearchParams({path:O}),L=await Y(K(`/api/files/git-authors?${Z}`)),T=await L.json();L.ok&&A(T.authors||[])}catch(Z){console.error("[useGitHistory] loadAuthors error:",Z)}finally{G(!1)}},[]);return{commits:t,loading:o,loadingMore:r,error:f,hasMore:u,total:j,filters:y,setFilter:re,resetFilters:_,selectedCommit:R,selectCommit:I,commitFiles:N,commitFilesLoading:v,loadHistory:D,loadMore:F,authors:S,authorsLoading:H,loadAuthors:ge}}function da(t){if(!t.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 o of n){const c=t.current.querySelector(o);if(c&&Fs(c))return c}return Fs(t.current)?t.current:null}function Fs(t){const n=["auto","scroll"].includes(getComputedStyle(t).overflowY),o=t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth;return n&&o}function Bs(t){if(!t)return 19.5;const n=parseFloat(getComputedStyle(t).lineHeight);return isNaN(n)?19.5:n}function Yt(t,n=!0){const o=n?t.scrollHeight:0;t.scrollTo({top:o,behavior:"smooth"})}function ua(t){const{scrollTop:n,scrollHeight:o,clientHeight:c}=t;return o<=c?100:Math.round(n/(o-c)*100)}function ha(t,n){const o=Bs(t),c=t.scrollTop,r=Math.floor(c/o)+1,i=n.split(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/EmbeddedEditor-DeNPLdlN.js","assets/main-vfMoYhg1.js","assets/vendor-react--Eh9ivFN.js","assets/vendor-three-Chj50gSY.js","assets/main-BEfBoz8e.css","assets/EmbeddedEditor-O_u2UVA4.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{r as s,aM as Y,l as K,a_ as Kt,M as $s,S as Rt,N as Hs,s as mt,u as le,j as e,I as M,bB as Ft,f as zs,bC as As,bD as Rn,bE as Os,bF as Gs,bG as Fn,bH as In,bI as Tt,bJ as Pn,bK as Ln,bL as $n,bM as Xt,bN as Hn,bO as Us,bP as Mt,bQ as Dt,ac as it,bR as ft,bS as pt,bT as Es,bU as zn,b6 as An,bV as Jt,bW as On,bX as Gn,bY as Ss,C as Un,n as Bn}from"./main-vfMoYhg1.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";function _n(t){const[n,o]=s.useState(null),[c,r]=s.useState(!1),i=s.useCallback(async()=>{if(t){r(!0);try{const f=await Y(K(`/api/files/git-status?path=${encodeURIComponent(t)}`)),l=await f.json();f.ok?o(l):o({isGitRepo:!1,files:[]})}catch(f){console.error("[FileExplorer] Failed to load git status:",f),o({isGitRepo:!1,files:[]})}finally{r(!1)}}},[t]);return{gitStatus:n,loading:c,loadGitStatus:i}}async function Vn(t){try{const n=await Y(K(`/api/files/git-original?path=${encodeURIComponent(t)}`)),o=await n.json();return n.ok&&!o.isNew?{content:o.content,isNew:!1}:{content:null,isNew:!0}}catch(n){return console.error("[FileExplorer] Failed to load original file:",n),{content:null,isNew:!0}}}const Kn=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",""]),Wn=new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".ico",".svg"]),Yn=new Set([".pdf"]),qn=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 Jn(t){const n=t.toLowerCase();return Wn.has(n)?"image":Yn.has(n)?"pdf":qn.has(n)?"binary":(Kn.has(n),"text")}function Xn(){const[t,n]=s.useState(null),[o,c]=s.useState(!1),[r,i]=s.useState(null),f=s.useCallback(async u=>{var g,j;c(!0),i(null);try{const p=u.substring(u.lastIndexOf(".")).toLowerCase(),y=Jn(p),C=u.substring(u.lastIndexOf("/")+1);if(y==="image"){const N=await Y(K(`/api/files/binary?path=${encodeURIComponent(u)}`));if(!N.ok){const w=await N.json().catch(()=>({error:"Failed to load image"}));i(w.error||"Failed to load image"),n(null);return}const d=await N.blob(),v=URL.createObjectURL(d);n({path:u,filename:C,extension:p,content:"",size:d.size,modified:new Date().toISOString(),fileType:"image",dataUrl:v});return}if(y==="pdf"){const N=await Y(K(`/api/files/info?path=${encodeURIComponent(u)}`)),d=await N.json();if(!N.ok){i(d.error||"Failed to load PDF info"),n(null);return}n({path:u,filename:C,extension:p,content:"",size:d.size,modified:d.modified,fileType:"pdf",dataUrl:K(`/api/files/binary?path=${encodeURIComponent(u)}&token=${encodeURIComponent(Kt())}`)});return}if(y==="binary"){const N=await Y(K(`/api/files/info?path=${encodeURIComponent(u)}`)),d=await N.json();if(!N.ok){i(d.error||"Failed to load file info"),n(null);return}n({path:u,filename:C,extension:p,content:"",size:d.size,modified:d.modified,fileType:"binary",dataUrl:K(`/api/files/binary?path=${encodeURIComponent(u)}&download=true&token=${encodeURIComponent(Kt())}`)});return}const R=await Y(K(`/api/files/read?path=${encodeURIComponent(u)}`)),x=await R.json();if(!R.ok){if((g=x.error)!=null&&g.includes("too large")||(j=x.error)!=null&&j.includes("binary")){const N=await Y(K(`/api/files/info?path=${encodeURIComponent(u)}`)),d=await N.json();if(N.ok){n({path:u,filename:C,extension:p,content:"",size:d.size,modified:d.modified,fileType:"binary",dataUrl:K(`/api/files/binary?path=${encodeURIComponent(u)}&download=true&token=${encodeURIComponent(Kt())}`)});return}}i(x.error||"Failed to load file"),n(null);return}n({...x,fileType:"text"})}catch(p){const y=p instanceof Error?p.message:"Failed to load file";i(y),n(null)}finally{c(!1)}},[]),l=s.useCallback(()=>{n(u=>(u!=null&&u.dataUrl&&u.dataUrl.startsWith("blob:")&&URL.revokeObjectURL(u.dataUrl),null)),i(null)},[]);return{file:t,loading:o,error:r,loadFile:f,clearFile:l,setFile:n}}const Wt="file-explorer-state",Qn=10080*60*1e3;function Zn(t,n){return n?`${Wt}-folder-${n}`:t?`${Wt}-area-${t}`:`${Wt}-default`}async function ea(t){try{const n=await Y(K(`/api/files/exists?path=${encodeURIComponent(t)}`));return n.ok?(await n.json()).exists===!0:!1}catch{return!1}}function ta({areaId:t,folderPath:n,isOpen:o}){const c=Zn(t,n),r=s.useRef(!1);s.useEffect(()=>{r.current=!1},[t,n]);const i=s.useCallback(async()=>{if(r.current)return null;r.current=!0;try{const l=localStorage.getItem(c);if(!l)return null;const u=JSON.parse(l);if(Date.now()-u.timestamp>Qn)return localStorage.removeItem(c),null;const j=(await Promise.all(u.tabs.map(async y=>({tab:y,exists:await ea(y.path)})))).filter(({exists:y})=>y).map(({tab:y})=>y);let p=u.activeTabPath;return p&&!j.some(y=>y.path===p)&&(p=j.length>0?j[0].path:null),{tabs:j,activeTabPath:p,viewMode:u.viewMode||"files",selectedFolderIndex:u.selectedFolderIndex||0,expandedPaths:new Set(u.expandedPaths||[])}}catch(l){return console.error("[FileExplorerStorage] Failed to load state:",l),null}},[c]),f=s.useCallback(l=>{if(o)try{const u={tabs:l.tabs,activeTabPath:l.activeTabPath,viewMode:l.viewMode,selectedFolderIndex:l.selectedFolderIndex,expandedPaths:Array.from(l.expandedPaths),timestamp:Date.now()};localStorage.setItem(c,JSON.stringify(u))}catch(u){console.error("[FileExplorerStorage] Failed to save state:",u)}},[c,o]);return{loadStoredState:i,saveState:f}}const Ts=280,Ms=150,Ds=1200;function sa(){const[t,n]=s.useState(()=>{const g=$s(Rt.TREE_PANEL_WIDTH,Ts);return g>=Ms&&g<=Ds?g:Ts}),o=s.useRef(!1),[c,r]=s.useState(!1),i=s.useRef(0),f=s.useRef(0),l=s.useRef(t);l.current=t;const u=s.useCallback(g=>{g.preventDefault(),o.current=!0,r(!0),i.current=g.clientX,f.current=t,document.body.style.cursor="ew-resize",document.body.style.userSelect="none"},[t]);return s.useEffect(()=>{const g=p=>{if(!o.current)return;const y=p.clientX-i.current,C=Math.min(Ds,Math.max(Ms,f.current+y));n(C)},j=()=>{o.current&&(o.current=!1,r(!1),document.body.style.cursor="",document.body.style.userSelect="",Hs(Rt.TREE_PANEL_WIDTH,l.current))};return document.addEventListener("mousemove",g),document.addEventListener("mouseup",j),()=>{document.removeEventListener("mousemove",g),document.removeEventListener("mouseup",j)}},[]),{treePanelWidth:t,handleResizeStart:u,isResizing:c}}const na=100,aa=.65,ra=36;function ia(){const[t,n]=s.useState(()=>$s(Rt.MOBILE_TREE_PANEL_HEIGHT,0)),o=s.useRef(t);o.current=t;const c=s.useRef(0),r=s.useRef(0),i=()=>Math.floor((window.innerHeight-ra)*aa),f=p=>Math.min(i(),Math.max(na,p)),l=s.useCallback(p=>{n(p);const y=document.querySelector(".file-explorer-main");y&&y.style.setProperty("--fe-mobile-tree-height",`${p}px`)},[]),u=s.useCallback(()=>{document.body.style.cursor="",document.body.style.userSelect="",Hs(Rt.MOBILE_TREE_PANEL_HEIGHT,o.current),mt.setTerminalResizing(!1)},[]),g=s.useCallback(p=>{p.preventDefault();const y=document.querySelector(".file-explorer-tree-panel"),C=o.current>0?o.current:(y==null?void 0:y.getBoundingClientRect().height)??240;c.current=p.clientY,r.current=C,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",mt.setTerminalResizing(!0);const R=N=>{const d=N.clientY-c.current;l(f(r.current+d))},x=()=>{document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",x),u()};document.addEventListener("mousemove",R),document.addEventListener("mouseup",x)},[l,u]),j=s.useCallback(p=>{if(p.touches.length!==1)return;const y=document.querySelector(".file-explorer-tree-panel"),C=o.current>0?o.current:(y==null?void 0:y.getBoundingClientRect().height)??240;c.current=p.touches[0].clientY,r.current=C,document.body.style.cursor="ns-resize",document.body.style.userSelect="none",mt.setTerminalResizing(!0);const R=N=>{if(N.touches.length!==1)return;N.preventDefault();const d=N.touches[0].clientY-c.current;l(f(r.current+d))},x=()=>{document.removeEventListener("touchmove",R),document.removeEventListener("touchend",x),document.removeEventListener("touchcancel",x),u()};document.addEventListener("touchmove",R,{passive:!1}),document.addEventListener("touchend",x),document.addEventListener("touchcancel",x)},[l,u]);return{mobileTreeHeight:t,handleResizeMouseDown:g,handleResizeTouchStart:j}}function Qt(){const[t,n]=s.useState([]),[o,c]=s.useState(!1),[r,i]=s.useState(null),[f,l]=s.useState(null),u=s.useCallback(async N=>{c(!0),i(null);try{const d=await Y(K(`/api/files/git-branches?path=${encodeURIComponent(N)}`)),v=await d.json();d.ok?n(v.branches||[]):(i(v.error||"Failed to load branches"),n([]))}catch(d){console.error("[GitBranches] Failed to load branches:",d),i("Failed to load branches"),n([])}finally{c(!1)}},[]),g=s.useCallback(async(N,d)=>{l("checkout"),i(null);try{const v=await Y(K("/api/files/git-checkout"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N,branch:d})}),w=await v.json();return v.ok||i(w.error||"Checkout failed"),w}catch(v){console.error("[GitBranches] Checkout failed:",v);const w={success:!1,error:"Checkout failed"};return i(w.error),w}finally{l(null)}},[]),j=s.useCallback(async(N,d,v)=>{l("create"),i(null);try{const w=await Y(K("/api/files/git-branch-create"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N,name:d,startPoint:v})}),S=await w.json();return w.ok||i(S.error||"Failed to create branch"),S}catch(w){console.error("[GitBranches] Create branch failed:",w);const S={success:!1,error:"Failed to create branch"};return i(S.error),S}finally{l(null)}},[]),p=s.useCallback(async N=>{l("pull"),i(null);try{const d=await Y(K("/api/files/git-pull"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N})}),v=await d.json();return!d.ok&&!v.conflicts&&i(v.error||"Pull failed"),v}catch(d){console.error("[GitBranches] Pull failed:",d);const v={success:!1,error:"Pull failed"};return i(v.error),v}finally{l(null)}},[]),y=s.useCallback(async N=>{l("push"),i(null);try{const d=await Y(K("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N})}),v=await d.json();return d.ok||i(v.error||"Push failed"),v}catch(d){console.error("[GitBranches] Push failed:",d);const v={success:!1,error:"Push failed"};return i(v.error),v}finally{l(null)}},[]),C=s.useCallback(async(N,d)=>{l("merge"),i(null);try{const v=await Y(K("/api/files/git-merge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N,branch:d})}),w=await v.json();return!v.ok&&!w.conflicts&&i(w.error||"Merge failed"),w}catch(v){console.error("[GitBranches] Merge failed:",v);const w={success:!1,error:"Merge failed"};return i(w.error),w}finally{l(null)}},[]),R=s.useCallback(async N=>{l("merge-abort"),i(null);try{const d=await Y(K("/api/files/git-merge-abort"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N})}),v=await d.json();return d.ok||i(v.error||"Merge abort failed"),v}catch(d){console.error("[GitBranches] Merge abort failed:",d);const v={success:!1,error:"Merge abort failed"};return i(v.error),v}finally{l(null)}},[]),x=s.useCallback(async N=>{l("merge-continue"),i(null);try{const d=await Y(K("/api/files/git-merge-continue"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:N})}),v=await d.json();return d.ok||i(v.error||"Merge continue failed"),v}catch(d){console.error("[GitBranches] Merge continue failed:",d);const v={success:!1,error:"Merge continue failed"};return i(v.error),v}finally{l(null)}},[]);return{branches:t,loading:o,error:r,operationInProgress:f,loadBranches:u,checkoutBranch:g,createBranch:j,pullFromRemote:p,pushToRemote:y,mergeBranch:C,mergeAbort:R,mergeContinue:x}}const la=50,oa=400,Rs={branch:"",author:"",since:"",until:"",searchPath:"",search:""};function ca(){const[t,n]=s.useState([]),[o,c]=s.useState(!1),[r,i]=s.useState(!1),[f,l]=s.useState(null),[u,g]=s.useState(!1),[j,p]=s.useState(0),[y,C]=s.useState({...Rs}),[R,x]=s.useState(null),[N,d]=s.useState([]),[v,w]=s.useState(!1),[S,A]=s.useState([]),[H,G]=s.useState(!1),z=s.useRef(null),ae=s.useRef(""),ee=s.useCallback((O,Z,L)=>{const T=L||y,W=new URLSearchParams;return W.set("path",O),W.set("limit",String(la)),W.set("offset",String(Z)),T.branch&&W.set("branch",T.branch),T.author&&W.set("author",T.author),T.since&&W.set("since",T.since),T.until&&W.set("until",T.until),T.searchPath&&W.set("searchPath",T.searchPath),T.search&&W.set("search",T.search),W.toString()},[y]),D=s.useCallback(async O=>{ae.current=O,c(!0),l(null),x(null),d([]);try{const Z=ee(O,0),L=await Y(K(`/api/files/git-log?${Z}`)),T=await L.json();L.ok?(n(T.commits||[]),p(T.total||0),g(T.hasMore||!1)):(l(T.error||"Failed to load git history"),n([]))}catch(Z){console.error("[useGitHistory] loadHistory error:",Z),l("Failed to load git history"),n([])}finally{c(!1)}},[ee]),F=s.useCallback(async O=>{if(!(r||!u)){i(!0);try{const Z=ee(O,t.length),L=await Y(K(`/api/files/git-log?${Z}`)),T=await L.json();L.ok&&(n(W=>[...W,...T.commits||[]]),p(T.total||0),g(T.hasMore||!1))}catch(Z){console.error("[useGitHistory] loadMore error:",Z)}finally{i(!1)}}},[ee,t.length,u,r]),I=s.useCallback(async O=>{if(x(O),!O){d([]);return}w(!0);try{const Z=ae.current,L=new URLSearchParams({path:Z,hash:O.hash}),T=await Y(K(`/api/files/git-commit-files?${L}`)),W=await T.json();T.ok?d(W.files||[]):d([])}catch(Z){console.error("[useGitHistory] selectCommit files error:",Z),d([])}finally{w(!1)}},[]),re=s.useCallback((O,Z)=>{C(L=>({...L,[O]:Z}))},[]),_=s.useCallback(()=>{C({...Rs})},[]);s.useEffect(()=>{const O=ae.current;if(O)return z.current&&clearTimeout(z.current),z.current=setTimeout(()=>{D(O)},oa),()=>{z.current&&clearTimeout(z.current)}},[y]);const ge=s.useCallback(async O=>{G(!0);try{const Z=new URLSearchParams({path:O}),L=await Y(K(`/api/files/git-authors?${Z}`)),T=await L.json();L.ok&&A(T.authors||[])}catch(Z){console.error("[useGitHistory] loadAuthors error:",Z)}finally{G(!1)}},[]);return{commits:t,loading:o,loadingMore:r,error:f,hasMore:u,total:j,filters:y,setFilter:re,resetFilters:_,selectedCommit:R,selectCommit:I,commitFiles:N,commitFilesLoading:v,loadHistory:D,loadMore:F,authors:S,authorsLoading:H,loadAuthors:ge}}function da(t){if(!t.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 o of n){const c=t.current.querySelector(o);if(c&&Fs(c))return c}return Fs(t.current)?t.current:null}function Fs(t){const n=["auto","scroll"].includes(getComputedStyle(t).overflowY),o=t.scrollHeight>t.clientHeight||t.scrollWidth>t.clientWidth;return n&&o}function Bs(t){if(!t)return 19.5;const n=parseFloat(getComputedStyle(t).lineHeight);return isNaN(n)?19.5:n}function Yt(t,n=!0){const o=n?t.scrollHeight:0;t.scrollTo({top:o,behavior:"smooth"})}function ua(t){const{scrollTop:n,scrollHeight:o,clientHeight:c}=t;return o<=c?100:Math.round(n/(o-c)*100)}function ha(t,n){const o=Bs(t),c=t.scrollTop,r=Math.floor(c/o)+1,i=n.split(`
|
|
3
3
|
`).length;return Math.min(r,i)}function ma(t,n,o=!1){if(!n)return[];o||t.toLowerCase();const c=o?n:n.toLowerCase(),r=[];let i=0;const f=t.split(`
|
|
4
4
|
`);let l=0;for(let u=0;u<f.length;u++){const g=f[u],j=o?g:g.toLowerCase();let p=0,y=j.indexOf(c);for(;y!==-1;){const C=l+y;r.push({index:i++,line:u+1,column:y,length:c.length,charIndex:C}),p=y+c.length,y=j.indexOf(c,p)}l+=g.length+1}return r}function lt(t){return/[\w]/.test(t)}function Ge(t){return/\s/.test(t)}function fa(t,n,o){let c=n-1,r=o;const i=t.length,f=t[c]||"";if(r<f.length){const g=lt(f[r]);if(!Ge(f[r]))for(;r<f.length&&!Ge(f[r])&<(f[r])===g;)r++}for(;c<i;){const g=t[c]||"";for(;r<g.length&&Ge(g[r]);)r++;if(r<g.length)return{line:c+1,col:r};c++,r=0}const l=i,u=Math.max(0,(t[i-1]||"").length-1);return{line:l,col:u}}function pa(t,n,o){let c=n-1,r=o+1;const i=t.length;for(;c<i;){const u=t[c]||"";for(;r<u.length&&Ge(u[r]);)r++;if(r<u.length)break;c++,r=0}if(c>=i)return{line:i,col:Math.max(0,(t[i-1]||"").length-1)};const f=t[c]||"",l=lt(f[r]);for(;r+1<f.length&&!Ge(f[r+1])&<(f[r+1])===l;)r++;return{line:c+1,col:r}}function ga(t,n,o){let c=n-1,r=o-1;for(;c>=0;){const l=t[c]||"";for(;r>=0&&Ge(l[r]);)r--;if(r>=0)break;c--,c>=0&&(r=(t[c]||"").length-1)}if(c<0)return{line:1,col:0};const i=t[c]||"",f=lt(i[r]);for(;r>0&&!Ge(i[r-1])&<(i[r-1])===f;)r--;return{line:c+1,col:r}}function xa(t,n,o,c){if(c==="none")return"";const{anchorLine:r,anchorCol:i,headLine:f,headCol:l}=o;if(c==="line"){const C=Math.min(r,f),R=Math.max(r,f);return n.slice(C-1,R).join(`
|
|
5
5
|
`)}let u,g,j,p;if(r<f||r===f&&i<=l?(u=r,g=i,j=f,p=l):(u=f,g=l,j=r,p=i),u===j)return(n[u-1]||"").substring(g,p+1);const y=[];y.push((n[u-1]||"").substring(g));for(let C=u;C<j-1;C++)y.push(n[C]||"");return y.push((n[j-1]||"").substring(0,p+1)),y.join(`
|
|
6
6
|
`)}function _s(t){const{containerRef:n,isEnabled:o=!0,content:c="",onClose:r,onSearchOpen:i}=t,f=s.useRef({percentage:0,line:1,column:1}),l=s.useRef(null),u=s.useRef(19.5),g=s.useMemo(()=>c.split(`
|
|
7
|
-
`),[c]),j=g.length,[p,y]=s.useState(1),[C,R]=s.useState(0),[x,N]=s.useState(!1),[d,v]=s.useState("none"),[w,S]=s.useState(null),[A,H]=s.useState(!1),[G,z]=s.useState(""),[ae,ee]=s.useState(0),[D,F]=s.useState(!1),I=s.useMemo(()=>ma(c,G,!1),[c,G]),re=s.useCallback(()=>{const m=l.current;if(!m)return;const q=ua(m),ie=ha(m,c),V=Math.max(1,Math.round(m.scrollLeft/7.8)+1);f.current={percentage:q,line:ie,column:V}},[c]),_=s.useCallback(()=>{H(!0),z(""),ee(0),i==null||i()},[i]),ge=s.useCallback(()=>{H(!1),z(""),ee(0)},[]),O=s.useCallback(()=>{F(m=>!m)},[]),Z=s.useCallback(m=>{const q=l.current;if(!q)return;const ie=q.querySelector(".file-viewer-pre"),ue=ie&&parseFloat(getComputedStyle(ie).lineHeight)||u.current,V=ie&&parseFloat(getComputedStyle(ie).paddingTop)||0,Q=(ie?ie.offsetTop:0)+V+(m-1)*ue,te=ue*3;q.scrollTo({top:Math.max(0,Q-te),behavior:"smooth"})},[]);s.useEffect(()=>{!A||I.length===0||ee(0)},[I,A]),s.useEffect(()=>{if(!A||I.length===0)return;const m=I[ae];m&&(y(m.line),R(m.column),Z(m.line))},[A,I,ae,Z]);const L=s.useCallback(()=>{I.length!==0&&ee(m=>(m+1)%I.length)},[I]),T=s.useCallback(()=>{I.length!==0&&ee(m=>(m-1+I.length)%I.length)},[I]),W=s.useCallback(m=>{const q=l.current;if(!q)return;const ie=q.querySelector(".file-viewer-pre");if(!ie)return;const ue=parseFloat(getComputedStyle(ie).lineHeight),V=isNaN(ue)?u.current:ue,E=parseFloat(getComputedStyle(ie).paddingTop)||0,te=ie.offsetTop+E+(m-1)*V,Ne=te+V,xe=q.scrollTop,U=xe+q.clientHeight;te<xe?q.scrollTo({top:Math.max(0,te),behavior:"auto"}):Ne>U&&q.scrollTo({top:Ne-q.clientHeight,behavior:"auto"})},[]),ne=s.useCallback((m,q)=>{y(m),R(q),W(m),d!=="none"&&S(ie=>ie?{...ie,headLine:m,headCol:q}:null)},[d,W]),be=s.useCallback(()=>{if(d==="none"||!w)return;const m=xa(c,g,w,d);m&&navigator.clipboard.writeText(m).catch(()=>{const q=document.createElement("textarea");q.value=m,q.style.position="fixed",q.style.left="-9999px",document.body.appendChild(q),q.select(),document.execCommand("copy"),document.body.removeChild(q)}),v("none"),S(null)},[d,w,c,g]),de=s.useCallback(m=>{const q=m.target;if((q.tagName==="INPUT"||q.tagName==="TEXTAREA")&&m.key!=="Escape")return;const ue=l.current;if(!ue)return;let V=!1;const E=u.current,Q=Math.max(1,Math.floor(ue.clientHeight/E)),te=Math.max(1,Math.floor(Q/2)),Ne=(U,se)=>{const pe=Math.max(0,(g[U-1]||"").length-1);return Math.min(se,Math.max(0,pe))},xe=(U,se)=>{const pe=Ne(U,se);ne(U,pe)};if(m.key==="v"&&!m.shiftKey&&!m.ctrlKey&&!A)m.preventDefault(),m.stopPropagation(),d==="char"?(v("none"),S(null)):(v("char"),S({anchorLine:p,anchorCol:C,headLine:p,headCol:C})),V=!0;else if(m.key==="V"&&m.shiftKey&&!m.ctrlKey&&!A)m.preventDefault(),m.stopPropagation(),d==="line"?(v("none"),S(null)):(v("line"),S({anchorLine:p,anchorCol:0,headLine:p,headCol:0})),V=!0;else if(m.key==="y"&&!m.ctrlKey&&d!=="none")m.preventDefault(),m.stopPropagation(),be(),V=!0;else if(m.key==="j"||m.key==="ArrowDown"){m.preventDefault(),m.stopPropagation();const U=Math.min(p+1,j);xe(U,C),V=!0}else if(m.key==="k"||m.key==="ArrowUp"){m.preventDefault(),m.stopPropagation();const U=Math.max(p-1,1);xe(U,C),V=!0}else if(m.key==="d"&&m.ctrlKey||m.key==="d"&&d==="none"&&!A){m.preventDefault(),m.stopPropagation();const U=Math.min(p+te,j);xe(U,C),V=!0}else if(m.key==="u"&&m.ctrlKey||m.key==="u"&&d==="none"&&!A){m.preventDefault(),m.stopPropagation();const U=Math.max(p-te,1);xe(U,C),V=!0}else if((m.ctrlKey||m.metaKey)&&m.key==="f")m.preventDefault(),m.stopPropagation(),_(),V=!0;else if(m.key==="f"&&!m.ctrlKey&&!m.metaKey&&d==="none"&&!A){m.preventDefault(),m.stopPropagation();const U=Math.min(p+Q,j);xe(U,C),V=!0}else if(m.key===" "||m.key==="PageDown"){m.preventDefault(),m.stopPropagation();const U=Math.min(p+Q,j);xe(U,C),V=!0}else if(m.key==="b"&&!x&&d==="none"&&!A||m.key==="PageUp"){m.preventDefault(),m.stopPropagation();const U=Math.max(p-Q,1);xe(U,C),V=!0}else if(m.key==="g"&&!m.shiftKey&&d==="none"&&!A)m.preventDefault(),m.stopPropagation(),ne(1,0),Yt(ue,!1),V=!0;else if(m.key==="Home")m.preventDefault(),m.stopPropagation(),ne(1,0),Yt(ue,!1),V=!0;else if(m.key==="G"&&m.shiftKey||m.key==="End")m.preventDefault(),m.stopPropagation(),ne(j,0),Yt(ue,!0),V=!0;else if(m.key==="h"||m.key==="ArrowLeft")m.preventDefault(),m.stopPropagation(),ne(p,Math.max(0,C-1)),V=!0;else if(m.key==="l"||m.key==="ArrowRight"){m.preventDefault(),m.stopPropagation();const U=(g[p-1]||"").length;ne(p,Math.min(C+1,Math.max(0,U-1))),V=!0}else if(m.key==="w"&&!m.ctrlKey&&!A){m.preventDefault(),m.stopPropagation();const U=fa(g,p,C);ne(U.line,U.col),V=!0}else if(m.key==="e"&&!m.ctrlKey&&!A){m.preventDefault(),m.stopPropagation();const U=pa(g,p,C);ne(U.line,U.col),V=!0}else if(m.key==="b"&&!A){m.preventDefault(),m.stopPropagation();const U=ga(g,p,C);ne(U.line,U.col),V=!0}else if(m.key==="0")m.preventDefault(),m.stopPropagation(),ne(p,0),V=!0;else if(m.key==="$")m.preventDefault(),m.stopPropagation(),ne(p,Math.max(0,(g[p-1]||"").length-1)),V=!0;else if(m.key==="^"){m.preventDefault(),m.stopPropagation();const se=(g[p-1]||"").search(/\S/);ne(p,se>=0?se:0),V=!0}else m.key==="/"?(m.preventDefault(),m.stopPropagation(),_(),V=!0):m.key==="n"&&!A?(m.preventDefault(),m.stopPropagation(),L(),V=!0):m.key==="N"&&m.shiftKey&&!A?(m.preventDefault(),m.stopPropagation(),T(),V=!0):m.key==="?"&&d==="none"?(m.preventDefault(),m.stopPropagation(),O(),V=!0):m.key==="q"&&d==="none"?(m.preventDefault(),m.stopPropagation(),r==null||r(),V=!0):m.key==="Escape"&&(d!=="none"?(m.preventDefault(),m.stopPropagation(),v("none"),S(null),V=!0):A?(m.preventDefault(),m.stopPropagation(),ge(),V=!0):x&&(m.preventDefault(),m.stopPropagation(),N(!1),V=!0));V&&(m.key!=="Escape"&&!x&&N(!0),requestAnimationFrame(re))},[r,re,j,g,p,C,W,A,ge,d,x,ne,be,_,L,T,O]);return s.useEffect(()=>{if(!o)return;const m=da(n);if(l.current=m,!m){console.warn("[useLessNavigation] Could not find scrollable container");return}u.current=Bs(m);const q=()=>{re()};return window.addEventListener("keydown",de,{capture:!0}),m.addEventListener("scroll",q,{passive:!0}),re(),()=>{window.removeEventListener("keydown",de,{capture:!0}),m.removeEventListener("scroll",q)}},[o,de,re]),{scrollPercentage:f.current.percentage,currentLine:f.current.line,currentColumn:f.current.column,totalLines:j,cursorLine:p,cursorCol:C,cursorModeActive:x,visualMode:d,selection:w,searchActive:A,searchQuery:G,searchMatches:I,currentMatchIndex:ae,startSearch:_,setSearchQuery:z,nextMatch:L,prevMatch:T,clearSearch:ge,helpActive:D,toggleHelp:O}}const Zt=({query:t,onQueryChange:n,matchCount:o,currentIndex:c,onNext:r,onPrev:i,onClose:f})=>{const{t:l}=le(["terminal"]),u=s.useRef(null);s.useEffect(()=>{var p;(p=u.current)==null||p.focus()},[]);const g=s.useCallback(p=>{p.stopPropagation(),p.key==="Enter"||p.key==="ArrowDown"?(p.preventDefault(),r()):p.key==="ArrowUp"&&(p.preventDefault(),i())},[r,i]),j=o===0&&t?l("terminal:fileExplorer.noMatches"):o>0?`${c+1}/${o}`:"";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:u,type:"text",className:"file-viewer-search-input",placeholder:l("terminal:fileExplorer.searchInFile"),value:t,onChange:p=>n(p.target.value),onKeyDown:g,autoComplete:"off",spellCheck:"false"})]}),t&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"file-viewer-search-counter",children:j}),e.jsxs("div",{className:"file-viewer-search-nav",children:[e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-prev",onClick:i,disabled:o===0,title:l("terminal:fileExplorer.previousMatch"),"aria-label":l("terminal:fileExplorer.previousMatch"),children:e.jsx(M,{name:"caret-up",size:10})}),e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-next",onClick:r,disabled:o===0,title:l("terminal:fileExplorer.nextMatch"),"aria-label":l("terminal:fileExplorer.nextMatch"),children:e.jsx(M,{name:"caret-down",size:10})})]})]}),e.jsx("button",{className:"file-viewer-search-close",onClick:f,title:l("terminal:fileExplorer.closeSearch"),"aria-label":l("terminal:fileExplorer.closeSearch"),children:e.jsx(M,{name:"close",size:12})})]})};Zt.displayName="SearchBar";const ya=[{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"}],es=({onClose:t})=>{const{t:n}=le(["terminal"]),o=s.useCallback(i=>{i.target===i.currentTarget&&t()},[t]),c=s.useCallback(i=>{(i.key==="Escape"||i.key==="?")&&(i.preventDefault(),i.stopPropagation(),t())},[t]),r=ya.reduce((i,f)=>(i[f.category]||(i[f.category]=[]),i[f.category].push(f),i),{});return e.jsx("div",{className:"keybindings-help-overlay",onClick:o,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:t,"aria-label":n("terminal:fileExplorer.closeHelp"),title:n("terminal:fileExplorer.pressEscapeToClose"),children:e.jsx(M,{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,f])=>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:f.map((l,u)=>e.jsxs("div",{className:"keybindings-help-item",children:[e.jsx("div",{className:"keybindings-help-keys",children:l.keys.map((g,j)=>e.jsx("kbd",{className:"keybindings-help-key",children:g},j))}),e.jsx("div",{className:"keybindings-help-description",children:l.description})]},u))})]},i))}),e.jsx("p",{className:"keybindings-help-footer",children:n("terminal:fileExplorer.keybindingsFooter")})]})})};es.displayName="KeybindingsHelp";const Is=s.lazy(()=>Rn(()=>import("./EmbeddedEditor-CBoOoGL8.js"),__vite__mapDeps([0,1,2,3,4,5])).then(t=>({default:t.EmbeddedEditor}))),ba=[".md",".mdx",".markdown"],Ps="file-viewer-markdown-render",ja=[".puml",".plantuml",".iuml",".pu"],Ls="file-viewer-plantuml-render",va="https://kroki.io/plantuml/svg";function wa(t){return ba.includes(t.toLowerCase())}function Ca(t){return ja.includes(t.toLowerCase())}function Na(){const[t,n]=s.useState(()=>{try{const c=localStorage.getItem(Ps);return c===null?!0:c==="true"}catch{return!0}}),o=s.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(Ps,String(r))}catch{}return r})},[]);return[t,o]}function ka(){const[t,n]=s.useState(()=>{try{const c=localStorage.getItem(Ls);return c===null?!0:c==="true"}catch{return!0}}),o=s.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(Ls,String(r))}catch{}return r})},[]);return[t,o]}function Ea(t){const n=new TextEncoder().encode(t);let o="";for(const c of n)o+=String.fromCharCode(c);return`data:image/svg+xml;base64,${window.btoa(o)}`}function Ue({file:t,rightContent:n,onRevealInTree:o,editMode:c,onToggleEdit:r}){const{t:i}=le(["terminal","common"]),[f,l]=s.useState("idle"),[u,g]=s.useState("idle"),[j,p]=s.useState("idle"),y=t.fileType==="text"?Ft(t.extension):t.extension.slice(1).toUpperCase(),C=t.fileType==="text"&&t.content!=null,{settings:R}=zs(),x=async()=>{try{await Tt(t.content),p("copied"),setTimeout(()=>p("idle"),2e3)}catch{p("error"),setTimeout(()=>p("idle"),2e3)}},N=()=>{const S=new Blob([t.content],{type:"text/plain;charset=utf-8"}),A=URL.createObjectURL(S),H=document.createElement("a");H.href=A,H.download=t.filename,document.body.appendChild(H),H.click(),H.remove(),setTimeout(()=>URL.revokeObjectURL(A),1e3)},d=async()=>{l("loading");try{const S=await Y(K("/api/files/open-in-editor"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t.path,...R.externalEditorCommand&&{editorCommand:R.externalEditorCommand}})});if(!S.ok){const A=await S.json().catch(()=>({error:"Unknown error"}));console.error("Failed to open in editor:",A),l("error"),setTimeout(()=>l("idle"),2e3);return}l("success"),setTimeout(()=>l("idle"),2e3)}catch(S){console.error("Error opening file in editor:",S),l("error"),setTimeout(()=>l("idle"),2e3)}},v=async()=>{if(t.path)try{await $n(t.path),g("success"),setTimeout(()=>g("idle"),2e3)}catch(S){console.error("Error opening file explorer:",S),g("error"),setTimeout(()=>g("idle"),2e3)}},w=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:t.filename}),e.jsxs("span",{className:"file-viewer-meta",children:[As(t.size)," • ",y,t.content&&` • ${t.content.split(`
|
|
7
|
+
`),[c]),j=g.length,[p,y]=s.useState(1),[C,R]=s.useState(0),[x,N]=s.useState(!1),[d,v]=s.useState("none"),[w,S]=s.useState(null),[A,H]=s.useState(!1),[G,z]=s.useState(""),[ae,ee]=s.useState(0),[D,F]=s.useState(!1),I=s.useMemo(()=>ma(c,G,!1),[c,G]),re=s.useCallback(()=>{const m=l.current;if(!m)return;const q=ua(m),ie=ha(m,c),V=Math.max(1,Math.round(m.scrollLeft/7.8)+1);f.current={percentage:q,line:ie,column:V}},[c]),_=s.useCallback(()=>{H(!0),z(""),ee(0),i==null||i()},[i]),ge=s.useCallback(()=>{H(!1),z(""),ee(0)},[]),O=s.useCallback(()=>{F(m=>!m)},[]),Z=s.useCallback(m=>{const q=l.current;if(!q)return;const ie=q.querySelector(".file-viewer-pre"),ue=ie&&parseFloat(getComputedStyle(ie).lineHeight)||u.current,V=ie&&parseFloat(getComputedStyle(ie).paddingTop)||0,Q=(ie?ie.offsetTop:0)+V+(m-1)*ue,te=ue*3;q.scrollTo({top:Math.max(0,Q-te),behavior:"smooth"})},[]);s.useEffect(()=>{!A||I.length===0||ee(0)},[I,A]),s.useEffect(()=>{if(!A||I.length===0)return;const m=I[ae];m&&(y(m.line),R(m.column),Z(m.line))},[A,I,ae,Z]);const L=s.useCallback(()=>{I.length!==0&&ee(m=>(m+1)%I.length)},[I]),T=s.useCallback(()=>{I.length!==0&&ee(m=>(m-1+I.length)%I.length)},[I]),W=s.useCallback(m=>{const q=l.current;if(!q)return;const ie=q.querySelector(".file-viewer-pre");if(!ie)return;const ue=parseFloat(getComputedStyle(ie).lineHeight),V=isNaN(ue)?u.current:ue,E=parseFloat(getComputedStyle(ie).paddingTop)||0,te=ie.offsetTop+E+(m-1)*V,Ne=te+V,xe=q.scrollTop,U=xe+q.clientHeight;te<xe?q.scrollTo({top:Math.max(0,te),behavior:"auto"}):Ne>U&&q.scrollTo({top:Ne-q.clientHeight,behavior:"auto"})},[]),ne=s.useCallback((m,q)=>{y(m),R(q),W(m),d!=="none"&&S(ie=>ie?{...ie,headLine:m,headCol:q}:null)},[d,W]),be=s.useCallback(()=>{if(d==="none"||!w)return;const m=xa(c,g,w,d);m&&navigator.clipboard.writeText(m).catch(()=>{const q=document.createElement("textarea");q.value=m,q.style.position="fixed",q.style.left="-9999px",document.body.appendChild(q),q.select(),document.execCommand("copy"),document.body.removeChild(q)}),v("none"),S(null)},[d,w,c,g]),de=s.useCallback(m=>{const q=m.target;if((q.tagName==="INPUT"||q.tagName==="TEXTAREA")&&m.key!=="Escape")return;const ue=l.current;if(!ue)return;let V=!1;const E=u.current,Q=Math.max(1,Math.floor(ue.clientHeight/E)),te=Math.max(1,Math.floor(Q/2)),Ne=(U,se)=>{const pe=Math.max(0,(g[U-1]||"").length-1);return Math.min(se,Math.max(0,pe))},xe=(U,se)=>{const pe=Ne(U,se);ne(U,pe)};if(m.key==="v"&&!m.shiftKey&&!m.ctrlKey&&!A)m.preventDefault(),m.stopPropagation(),d==="char"?(v("none"),S(null)):(v("char"),S({anchorLine:p,anchorCol:C,headLine:p,headCol:C})),V=!0;else if(m.key==="V"&&m.shiftKey&&!m.ctrlKey&&!A)m.preventDefault(),m.stopPropagation(),d==="line"?(v("none"),S(null)):(v("line"),S({anchorLine:p,anchorCol:0,headLine:p,headCol:0})),V=!0;else if(m.key==="y"&&!m.ctrlKey&&d!=="none")m.preventDefault(),m.stopPropagation(),be(),V=!0;else if(m.key==="j"||m.key==="ArrowDown"){m.preventDefault(),m.stopPropagation();const U=Math.min(p+1,j);xe(U,C),V=!0}else if(m.key==="k"||m.key==="ArrowUp"){m.preventDefault(),m.stopPropagation();const U=Math.max(p-1,1);xe(U,C),V=!0}else if(m.key==="d"&&m.ctrlKey||m.key==="d"&&d==="none"&&!A){m.preventDefault(),m.stopPropagation();const U=Math.min(p+te,j);xe(U,C),V=!0}else if(m.key==="u"&&m.ctrlKey||m.key==="u"&&d==="none"&&!A){m.preventDefault(),m.stopPropagation();const U=Math.max(p-te,1);xe(U,C),V=!0}else if((m.ctrlKey||m.metaKey)&&m.key==="f")m.preventDefault(),m.stopPropagation(),_(),V=!0;else if(m.key==="f"&&!m.ctrlKey&&!m.metaKey&&d==="none"&&!A){m.preventDefault(),m.stopPropagation();const U=Math.min(p+Q,j);xe(U,C),V=!0}else if(m.key===" "||m.key==="PageDown"){m.preventDefault(),m.stopPropagation();const U=Math.min(p+Q,j);xe(U,C),V=!0}else if(m.key==="b"&&!x&&d==="none"&&!A||m.key==="PageUp"){m.preventDefault(),m.stopPropagation();const U=Math.max(p-Q,1);xe(U,C),V=!0}else if(m.key==="g"&&!m.shiftKey&&d==="none"&&!A)m.preventDefault(),m.stopPropagation(),ne(1,0),Yt(ue,!1),V=!0;else if(m.key==="Home")m.preventDefault(),m.stopPropagation(),ne(1,0),Yt(ue,!1),V=!0;else if(m.key==="G"&&m.shiftKey||m.key==="End")m.preventDefault(),m.stopPropagation(),ne(j,0),Yt(ue,!0),V=!0;else if(m.key==="h"||m.key==="ArrowLeft")m.preventDefault(),m.stopPropagation(),ne(p,Math.max(0,C-1)),V=!0;else if(m.key==="l"||m.key==="ArrowRight"){m.preventDefault(),m.stopPropagation();const U=(g[p-1]||"").length;ne(p,Math.min(C+1,Math.max(0,U-1))),V=!0}else if(m.key==="w"&&!m.ctrlKey&&!A){m.preventDefault(),m.stopPropagation();const U=fa(g,p,C);ne(U.line,U.col),V=!0}else if(m.key==="e"&&!m.ctrlKey&&!A){m.preventDefault(),m.stopPropagation();const U=pa(g,p,C);ne(U.line,U.col),V=!0}else if(m.key==="b"&&!A){m.preventDefault(),m.stopPropagation();const U=ga(g,p,C);ne(U.line,U.col),V=!0}else if(m.key==="0")m.preventDefault(),m.stopPropagation(),ne(p,0),V=!0;else if(m.key==="$")m.preventDefault(),m.stopPropagation(),ne(p,Math.max(0,(g[p-1]||"").length-1)),V=!0;else if(m.key==="^"){m.preventDefault(),m.stopPropagation();const se=(g[p-1]||"").search(/\S/);ne(p,se>=0?se:0),V=!0}else m.key==="/"?(m.preventDefault(),m.stopPropagation(),_(),V=!0):m.key==="n"&&!A?(m.preventDefault(),m.stopPropagation(),L(),V=!0):m.key==="N"&&m.shiftKey&&!A?(m.preventDefault(),m.stopPropagation(),T(),V=!0):m.key==="?"&&d==="none"?(m.preventDefault(),m.stopPropagation(),O(),V=!0):m.key==="q"&&d==="none"?(m.preventDefault(),m.stopPropagation(),r==null||r(),V=!0):m.key==="Escape"&&(d!=="none"?(m.preventDefault(),m.stopPropagation(),v("none"),S(null),V=!0):A?(m.preventDefault(),m.stopPropagation(),ge(),V=!0):x&&(m.preventDefault(),m.stopPropagation(),N(!1),V=!0));V&&(m.key!=="Escape"&&!x&&N(!0),requestAnimationFrame(re))},[r,re,j,g,p,C,W,A,ge,d,x,ne,be,_,L,T,O]);return s.useEffect(()=>{if(!o)return;const m=da(n);if(l.current=m,!m){console.warn("[useLessNavigation] Could not find scrollable container");return}u.current=Bs(m);const q=()=>{re()};return window.addEventListener("keydown",de,{capture:!0}),m.addEventListener("scroll",q,{passive:!0}),re(),()=>{window.removeEventListener("keydown",de,{capture:!0}),m.removeEventListener("scroll",q)}},[o,de,re]),{scrollPercentage:f.current.percentage,currentLine:f.current.line,currentColumn:f.current.column,totalLines:j,cursorLine:p,cursorCol:C,cursorModeActive:x,visualMode:d,selection:w,searchActive:A,searchQuery:G,searchMatches:I,currentMatchIndex:ae,startSearch:_,setSearchQuery:z,nextMatch:L,prevMatch:T,clearSearch:ge,helpActive:D,toggleHelp:O}}const Zt=({query:t,onQueryChange:n,matchCount:o,currentIndex:c,onNext:r,onPrev:i,onClose:f})=>{const{t:l}=le(["terminal"]),u=s.useRef(null);s.useEffect(()=>{var p;(p=u.current)==null||p.focus()},[]);const g=s.useCallback(p=>{p.stopPropagation(),p.key==="Enter"||p.key==="ArrowDown"?(p.preventDefault(),r()):p.key==="ArrowUp"&&(p.preventDefault(),i())},[r,i]),j=o===0&&t?l("terminal:fileExplorer.noMatches"):o>0?`${c+1}/${o}`:"";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:u,type:"text",className:"file-viewer-search-input",placeholder:l("terminal:fileExplorer.searchInFile"),value:t,onChange:p=>n(p.target.value),onKeyDown:g,autoComplete:"off",spellCheck:"false"})]}),t&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"file-viewer-search-counter",children:j}),e.jsxs("div",{className:"file-viewer-search-nav",children:[e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-prev",onClick:i,disabled:o===0,title:l("terminal:fileExplorer.previousMatch"),"aria-label":l("terminal:fileExplorer.previousMatch"),children:e.jsx(M,{name:"caret-up",size:10})}),e.jsx("button",{className:"file-viewer-search-btn file-viewer-search-next",onClick:r,disabled:o===0,title:l("terminal:fileExplorer.nextMatch"),"aria-label":l("terminal:fileExplorer.nextMatch"),children:e.jsx(M,{name:"caret-down",size:10})})]})]}),e.jsx("button",{className:"file-viewer-search-close",onClick:f,title:l("terminal:fileExplorer.closeSearch"),"aria-label":l("terminal:fileExplorer.closeSearch"),children:e.jsx(M,{name:"close",size:12})})]})};Zt.displayName="SearchBar";const ya=[{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"}],es=({onClose:t})=>{const{t:n}=le(["terminal"]),o=s.useCallback(i=>{i.target===i.currentTarget&&t()},[t]),c=s.useCallback(i=>{(i.key==="Escape"||i.key==="?")&&(i.preventDefault(),i.stopPropagation(),t())},[t]),r=ya.reduce((i,f)=>(i[f.category]||(i[f.category]=[]),i[f.category].push(f),i),{});return e.jsx("div",{className:"keybindings-help-overlay",onClick:o,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:t,"aria-label":n("terminal:fileExplorer.closeHelp"),title:n("terminal:fileExplorer.pressEscapeToClose"),children:e.jsx(M,{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,f])=>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:f.map((l,u)=>e.jsxs("div",{className:"keybindings-help-item",children:[e.jsx("div",{className:"keybindings-help-keys",children:l.keys.map((g,j)=>e.jsx("kbd",{className:"keybindings-help-key",children:g},j))}),e.jsx("div",{className:"keybindings-help-description",children:l.description})]},u))})]},i))}),e.jsx("p",{className:"keybindings-help-footer",children:n("terminal:fileExplorer.keybindingsFooter")})]})})};es.displayName="KeybindingsHelp";const Is=s.lazy(()=>Rn(()=>import("./EmbeddedEditor-DeNPLdlN.js"),__vite__mapDeps([0,1,2,3,4,5])).then(t=>({default:t.EmbeddedEditor}))),ba=[".md",".mdx",".markdown"],Ps="file-viewer-markdown-render",ja=[".puml",".plantuml",".iuml",".pu"],Ls="file-viewer-plantuml-render",va="https://kroki.io/plantuml/svg";function wa(t){return ba.includes(t.toLowerCase())}function Ca(t){return ja.includes(t.toLowerCase())}function Na(){const[t,n]=s.useState(()=>{try{const c=localStorage.getItem(Ps);return c===null?!0:c==="true"}catch{return!0}}),o=s.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(Ps,String(r))}catch{}return r})},[]);return[t,o]}function ka(){const[t,n]=s.useState(()=>{try{const c=localStorage.getItem(Ls);return c===null?!0:c==="true"}catch{return!0}}),o=s.useCallback(()=>{n(c=>{const r=!c;try{localStorage.setItem(Ls,String(r))}catch{}return r})},[]);return[t,o]}function Ea(t){const n=new TextEncoder().encode(t);let o="";for(const c of n)o+=String.fromCharCode(c);return`data:image/svg+xml;base64,${window.btoa(o)}`}function Ue({file:t,rightContent:n,onRevealInTree:o,editMode:c,onToggleEdit:r}){const{t:i}=le(["terminal","common"]),[f,l]=s.useState("idle"),[u,g]=s.useState("idle"),[j,p]=s.useState("idle"),y=t.fileType==="text"?Ft(t.extension):t.extension.slice(1).toUpperCase(),C=t.fileType==="text"&&t.content!=null,{settings:R}=zs(),x=async()=>{try{await Tt(t.content),p("copied"),setTimeout(()=>p("idle"),2e3)}catch{p("error"),setTimeout(()=>p("idle"),2e3)}},N=()=>{const S=new Blob([t.content],{type:"text/plain;charset=utf-8"}),A=URL.createObjectURL(S),H=document.createElement("a");H.href=A,H.download=t.filename,document.body.appendChild(H),H.click(),H.remove(),setTimeout(()=>URL.revokeObjectURL(A),1e3)},d=async()=>{l("loading");try{const S=await Y(K("/api/files/open-in-editor"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t.path,...R.externalEditorCommand&&{editorCommand:R.externalEditorCommand}})});if(!S.ok){const A=await S.json().catch(()=>({error:"Unknown error"}));console.error("Failed to open in editor:",A),l("error"),setTimeout(()=>l("idle"),2e3);return}l("success"),setTimeout(()=>l("idle"),2e3)}catch(S){console.error("Error opening file in editor:",S),l("error"),setTimeout(()=>l("idle"),2e3)}},v=async()=>{if(t.path)try{await $n(t.path),g("success"),setTimeout(()=>g("idle"),2e3)}catch(S){console.error("Error opening file explorer:",S),g("error"),setTimeout(()=>g("idle"),2e3)}},w=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:t.filename}),e.jsxs("span",{className:"file-viewer-meta",children:[As(t.size)," • ",y,t.content&&` • ${t.content.split(`
|
|
8
8
|
`).length} lines`]})]}),e.jsxs("div",{className:"file-viewer-header-right",children:[r&&t.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 ${j}`,onClick:x,title:i("terminal:fileExplorer.copyAllTitle"),children:i(j==="copied"?"terminal:fileExplorer.copied":j==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyAll")}),e.jsx("button",{className:"file-viewer-download-btn",onClick:N,title:i("terminal:fileExplorer.downloadFileTitle"),children:i("common:buttons.download")})]}),e.jsx("button",{className:`file-viewer-reveal-explorer-btn ${u}`,onClick:v,disabled:!t.path,title:w,"aria-label":w,children:u==="success"?e.jsx(M,{name:"check",size:14}):u==="error"?e.jsx(M,{name:"cross",size:14}):e.jsx(M,{name:"folder-open",size:14})}),e.jsx("button",{className:`file-viewer-open-editor-btn ${f}`,onClick:d,disabled:f==="loading",title:i(f==="error"?"terminal:fileExplorer.failedToOpenEditor":f==="success"?"terminal:fileExplorer.openingInEditor":"terminal:fileExplorer.openInEditor"),children:f==="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"})}):f==="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"})})}),o&&e.jsx("button",{className:"file-viewer-locate-btn",onClick:()=>o(t.path),title:i("terminal:fileExplorer.locateInTree"),children:e.jsx(M,{name:"target",size:14})}),n]})]})}function Sa({file:t,onRevealInTree:n,renderMarkdown:o,onToggleRender:c,editMode:r,onToggleEdit:i}){const f=s.useRef(null),l=s.useRef(null),u=s.useRef(null),{t:g}=le(["terminal","common"]),[j,p]=s.useState("idle"),[y,C]=s.useState("idle"),[R,x]=s.useState("idle"),[N,d]=s.useState("idle"),v=_s({containerRef:u,isEnabled:!0,content:t.content});s.useEffect(()=>{if(!o&&f.current){const z=Ft(t.extension);Os(z).then(()=>{f.current&&Gs(f.current)})}},[t,o]);const w=s.useCallback(async()=>{if(!l.current){p("error"),setTimeout(()=>p("idle"),2e3);return}try{const z=l.current.innerHTML,ae=Fn(z),ee=l.current.innerText;await In(ae,ee),p("copied"),setTimeout(()=>p("idle"),2e3)}catch{p("error"),setTimeout(()=>p("idle"),2e3)}},[]),S=s.useCallback(async()=>{if(!l.current){C("error"),setTimeout(()=>C("idle"),2e3);return}try{const z=l.current.innerHTML;await Tt(z),C("copied"),setTimeout(()=>C("idle"),2e3)}catch{C("error"),setTimeout(()=>C("idle"),2e3)}},[]),A=s.useCallback(async()=>{try{await Tt(t.content),x("copied"),setTimeout(()=>x("idle"),2e3)}catch{x("error"),setTimeout(()=>x("idle"),2e3)}},[t.content]),H=s.useCallback(async()=>{try{await Tt(t.content),d("copied"),setTimeout(()=>d("idle"),2e3)}catch{d("error"),setTimeout(()=>d("idle"),2e3)}},[t.content]),G=e.jsxs("div",{className:"file-viewer-header-buttons",children:[o&&e.jsxs(e.Fragment,{children:[e.jsx("button",{className:`file-viewer-copy-html-btn ${j}`,onClick:w,title:g("terminal:fileExplorer.copyRichTextTitle"),children:g(j==="copied"?"terminal:fileExplorer.copied":j==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyRichText")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${y}`,onClick:S,title:g("terminal:fileExplorer.copyHtmlTitle"),children:g(y==="copied"?"terminal:fileExplorer.copied":y==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyHtml")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${R}`,onClick:A,title:g("terminal:fileExplorer.copyMarkdownTitle"),children:g(R==="copied"?"terminal:fileExplorer.copied":R==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyMarkdown")}),e.jsx("button",{className:`file-viewer-copy-html-btn ${N}`,onClick:H,title:g("terminal:fileExplorer.copyOriginalTitle"),children:g(N==="copied"?"terminal:fileExplorer.copied":N==="error"?"terminal:fileExplorer.copyError":"terminal:fileExplorer.copyOriginal")})]}),e.jsx("button",{className:`file-viewer-render-toggle ${o?"active":""}`,onClick:c,title:g(o?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderMarkdown"),children:o?"</>":"Aa"})]});return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{file:t,onRevealInTree:n,rightContent:G,editMode:r,onToggleEdit:i}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:u,children:[o?e.jsx("div",{className:"file-viewer-markdown-wrapper",children:e.jsx("div",{className:"markdown-content",ref:l,children:e.jsx(Pn,{remarkPlugins:[Ln],children:t.content})})}):e.jsx("div",{className:"file-viewer-code-wrapper",children:e.jsx("pre",{className:"file-viewer-pre",children:e.jsx("code",{ref:f,className:"language-markdown",children:t.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(Zt,{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(es,{onClose:v.toggleHelp})]})}function Ta({file:t,onRevealInTree:n,renderPlantUml:o,onToggleRender:c,editMode:r,onToggleEdit:i}){const{t:f}=le(["terminal"]),l=s.useRef(null),u=s.useRef(null),[g,j]=s.useState(null),[p,y]=s.useState(!1),[C,R]=s.useState(null),x=_s({containerRef:u,isEnabled:!0,content:t.content});s.useEffect(()=>{if(!o&&l.current){const d=Ft(t.extension);Os(d).then(()=>{l.current&&Gs(l.current)})}},[t,o]),s.useEffect(()=>{if(!o)return;if(!t.content.trim()){j(null),R("Diagram is empty");return}const d=new AbortController;return y(!0),R(null),(async()=>{try{const w=await fetch(va,{method:"POST",headers:{"Content-Type":"text/plain; charset=utf-8",Accept:"image/svg+xml"},body:t.content,signal:d.signal});if(!w.ok)throw new Error(`Render failed (${w.status})`);const S=await w.text();if(!S.includes("<svg"))throw new Error("Invalid SVG output");j(Ea(S))}catch(w){if(d.signal.aborted)return;const S=w instanceof Error?w.message:"Failed to render diagram";R(S),j(null)}finally{d.signal.aborted||y(!1)}})(),()=>d.abort()},[t.path,t.content,o]);const N=e.jsx("div",{className:"file-viewer-header-buttons",children:e.jsx("button",{className:`file-viewer-render-toggle ${o?"active":""}`,onClick:c,title:f(o?"terminal:fileExplorer.showSource":"terminal:fileExplorer.renderDiagram"),children:o?"</>":f("terminal:fileExplorer.diagram")})});return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{file:t,onRevealInTree:n,rightContent:N,editMode:r,onToggleEdit:i}),e.jsxs("div",{className:"file-viewer-content-wrapper",ref:u,children:[o?e.jsxs("div",{className:"file-viewer-diagram-wrapper",children:[p&&e.jsx("div",{className:"file-viewer-placeholder",children:f("terminal:fileExplorer.renderingDiagram")}),!p&&g&&e.jsx("img",{src:g,alt:t.filename,className:"file-viewer-diagram-image"}),!p&&C&&e.jsxs("div",{className:"file-viewer-diagram-error",children:[e.jsxs("div",{children:[f("terminal:fileExplorer.couldNotRender"),": ",C]}),e.jsx("button",{className:"file-viewer-render-toggle",onClick:c,children:f("terminal:fileExplorer.showSource")})]})]}):e.jsx("div",{className:"file-viewer-code-wrapper",children:e.jsx("pre",{className:"file-viewer-pre",children:e.jsx("code",{ref:l,className:"language-plaintext",children:t.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(Zt,{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(es,{onClose:x.toggleHelp})]})}function Ma({file:t,onRevealInTree:n}){const{t:o}=le(["common","terminal"]),c=()=>{if(t.dataUrl){const r=document.createElement("a");r.href=t.dataUrl,r.download=t.filename,r.click()}};return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{file:t,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:c,title:o("common:buttons.download"),children:o("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-image-wrapper",children:t.dataUrl?e.jsx("img",{src:t.dataUrl,alt:t.filename,className:"file-viewer-image"}):e.jsx("div",{className:"file-viewer-placeholder",children:o("terminal:fileExplorer.failedToLoadImage")})})]})}function Da({file:t,onRevealInTree:n}){const{t:o}=le(["common","terminal"]),c=()=>{if(t.dataUrl){const r=document.createElement("a");r.href=t.dataUrl,r.download=t.filename,r.click()}};return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{file:t,onRevealInTree:n,rightContent:e.jsx("button",{className:"file-viewer-download-btn",onClick:c,title:o("common:buttons.download"),children:o("common:buttons.download")})}),e.jsx("div",{className:"file-viewer-pdf-wrapper",children:t.dataUrl?e.jsx("iframe",{src:t.dataUrl,title:t.filename,className:"file-viewer-pdf"}):e.jsx("div",{className:"file-viewer-placeholder",children:o("terminal:fileExplorer.failedToLoadPdf")})})]})}function Ra({file:t,onRevealInTree:n}){const{t:o}=le(["terminal","common"]),c=()=>{if(t.dataUrl){const i=document.createElement("a");i.href=t.dataUrl,i.download=t.filename,i.click()}},r=()=>{const i=t.extension.toLowerCase();return[".xlsx",".xls"].includes(i)?e.jsx(M,{name:"dashboard",size:48}):[".docx",".doc"].includes(i)?e.jsx(M,{name:"edit",size:48}):[".pptx",".ppt"].includes(i)?e.jsx(M,{name:"film",size:48}):[".zip",".tar",".gz",".rar",".7z"].includes(i)?e.jsx(M,{name:"file-zip",size:48}):[".mp3",".wav",".flac",".ogg"].includes(i)?e.jsx(M,{name:"music-note",size:48}):[".mp4",".avi",".mov",".mkv",".webm"].includes(i)?e.jsx(M,{name:"film",size:48}):[".exe",".dmg",".app",".msi"].includes(i)?e.jsx(M,{name:"gear",size:48}):[".apk",".aab",".ipa"].includes(i)?e.jsx(M,{name:"mobile",size:48}):[".jar",".war",".ear"].includes(i)?e.jsx(M,{name:"coffee",size:48}):[".iso",".img"].includes(i)?e.jsx(M,{name:"disc",size:48}):[".so",".dll",".dylib"].includes(i)?e.jsx(M,{name:"wrench",size:48}):e.jsx(M,{name:"folder",size:48})};return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{file:t,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:t.filename}),e.jsx("div",{className:"file-viewer-binary-size",children:As(t.size)}),e.jsx("div",{className:"file-viewer-binary-message",children:o("terminal:fileExplorer.cannotPreview")}),e.jsx("button",{className:"file-viewer-download-btn large",onClick:c,children:o("terminal:fileExplorer.downloadFile")})]})]})}function Fa({file:t,loading:n,error:o,onRevealInTree:c,onFileEdited:r}){const{t:i}=le(["terminal","common"]),[f,l]=Na(),[u,g]=ka(),[j,p]=s.useState(!1);s.useEffect(()=>{p(!1)},[t==null?void 0:t.path]);const y=s.useCallback(async w=>{if(!t)return;const S=await Y(K("/api/files/write"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t.path,content:w})});if(!S.ok){const A=await S.json().catch(()=>({error:"Save failed"}));throw new Error(A.error||"Save failed")}},[t]),C=s.useCallback(()=>{p(w=>(w&&t&&(r==null||r(t.path)),!w))},[t,r]),R=s.useCallback(()=>{t&&(r==null||r(t.path))},[t,r]);if(n)return e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")});if(o)return e.jsx("div",{className:"file-viewer-placeholder error",children:o});if(!t)return e.jsxs("div",{className:"file-viewer-placeholder",children:[e.jsx("div",{className:"placeholder-icon",children:e.jsx(M,{name:"folder-open",size:32})}),e.jsx("div",{className:"placeholder-text",children:i("terminal:fileExplorer.selectFileToView")})]});const x=t.fileType||"text",N=x==="text"&&wa(t.extension),d=x==="text"&&Ca(t.extension),v=N||d;return v&&j&&t.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(Ue,{file:t,onRevealInTree:c,editMode:!0,onToggleEdit:C}),e.jsx(s.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")}),children:e.jsx(Is,{content:t.content,extension:t.extension,onSave:y,onCancel:C},t.path)})]}):x==="text"&&!v&&t.content!=null?e.jsxs("div",{className:"file-viewer-content",children:[e.jsx(Ue,{file:t,onRevealInTree:c}),e.jsx(s.Suspense,{fallback:e.jsx("div",{className:"file-viewer-placeholder",children:i("common:status.loading")}),children:e.jsx(Is,{content:t.content,extension:t.extension,onSave:y,onCancel:R},t.path)})]}):e.jsxs("div",{className:"file-viewer-content",children:[N&&e.jsx(Sa,{file:t,onRevealInTree:c,renderMarkdown:f,onToggleRender:l,editMode:j,onToggleEdit:C}),d&&!N&&e.jsx(Ta,{file:t,onRevealInTree:c,renderPlantUml:u,onToggleRender:g,editMode:j,onToggleEdit:C}),x==="image"&&e.jsx(Ma,{file:t,onRevealInTree:c}),x==="pdf"&&e.jsx(Da,{file:t,onRevealInTree:c}),x==="binary"&&e.jsx(Ra,{file:t,onRevealInTree:c})]})}const Vs=s.memo(Fa,(t,n)=>t.loading!==n.loading||t.error!==n.error?!1:t.file===null&&n.file===null?!0:t.file===null||n.file===null?!1:t.file.path===n.file.path&&t.file.content===n.file.content&&t.file.modified===n.file.modified);Vs.displayName="FileViewer";function Ks({text:t,query:n}){if(!n)return e.jsx(e.Fragment,{children:t});const o=Hn(t,n);if(o)return e.jsxs(e.Fragment,{children:[t.slice(0,o.start),e.jsx("mark",{className:"search-highlight",children:t.slice(o.start,o.end)}),t.slice(o.end)]});const c=n.toLowerCase(),i=t.toLowerCase().indexOf(c);return i===-1?e.jsx(e.Fragment,{children:t}):e.jsxs(e.Fragment,{children:[t.slice(0,i),e.jsx("mark",{className:"search-highlight",children:t.slice(i,i+n.length)}),t.slice(i+n.length)]})}const Ia=s.memo(function({node:n,query:o,isSelected:c,onSelect:r,lineNumber:i}){const f=n.isDirectory?null:Xt(n),l=n.path.split("/");l[l.length-1];const u=l.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(M,{name:"folder",size:14})}):f?e.jsx("span",{className:"search-result-icon",style:{backgroundImage:`url('${f}')`},role:"img","aria-label":"file icon"}):e.jsx("span",{className:"search-result-icon",children:e.jsx(M,{name:"file-text",size:14})}),e.jsxs("div",{className:"search-result-info",children:[e.jsxs("span",{className:"search-result-name",children:[e.jsx(Ks,{text:n.name,query:o}),i&&e.jsxs("span",{className:"search-result-line-badge",children:[":",i]})]}),e.jsx("span",{className:"search-result-path",children:u})]})]})}),Pa=s.memo(function({match:n,query:o,isSelected:c,onSelect:r}){const{t:i}=le(["terminal"]),f={name:n.name,path:n.path,isDirectory:!1,extension:n.extension},l=Xt(f),u=n.path.split("/"),g=u[u.length-1],j=u.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:[l?e.jsx("span",{className:"content-search-icon",style:{backgroundImage:`url('${l}')`},role:"img","aria-label":"file icon"}):e.jsx("span",{className:"content-search-icon",children:e.jsx(M,{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:g}),e.jsx("span",{className:"search-result-path",style:{fontSize:"10px"},children:j})]}),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,y)=>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(Ks,{text:p.content.trim(),query:o})})]},`${n.path}-${p.line}-${y}`)),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 La({filenameResults:t,contentResults:n,onSelectFile:o,onSelectContent:c,selectedPath:r,query:i,lineNumber:f}){const{t:l}=le(["terminal"]),u=t.length>0,g=n.length>0;return!u&&!g?e.jsx("div",{className:"search-no-results",children:l("terminal:fileExplorer.noMatchesFound")}):e.jsxs("div",{className:"unified-search-results",children:[u&&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(M,{name:"file-text",size:14})}),e.jsx("span",{className:"unified-search-section-title",children:l("terminal:fileExplorer.files")}),e.jsx("span",{className:"unified-search-section-count",children:t.length})]}),e.jsx("div",{className:"unified-search-section-content",children:t.map(j=>e.jsx(Ia,{node:j,query:i,isSelected:r===j.path,onSelect:o,lineNumber:f},j.path))})]}),g&&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(M,{name:"edit",size:14})}),e.jsx("span",{className:"unified-search-section-title",children:l("terminal:fileExplorer.content")}),e.jsx("span",{className:"unified-search-section-count",children:l("terminal:fileExplorer.matchesInFiles",{matches:n.reduce((j,p)=>j+p.matches.length,0),files:n.length})})]}),e.jsx("div",{className:"unified-search-section-content",children:n.map(j=>e.jsx(Pa,{match:j,query:i,isSelected:r===j.path,onSelect:c},j.path))})]})]})}const Ws=s.memo(La,(t,n)=>!(t.query!==n.query||t.selectedPath!==n.selectedPath||t.filenameResults.length!==n.filenameResults.length||t.contentResults.length!==n.contentResults.length));Ws.displayName="UnifiedSearchResults";const $a=s.memo(function({file:n,isSelected:o,onSelect:c,onStage:r,isStaging:i,showDirPath:f,isChecked:l,onToggleCheck:u,onContextMenu:g,onDiscard:j}){const{t:p}=le(["terminal"]),y=n.status,C=pt[y],R=y==="deleted",x=y==="untracked"&&r,N=n.name.includes(".")?"."+n.name.split(".").pop():"",d=f&&n.path.includes("/")?n.path.slice(0,n.path.lastIndexOf("/")):"";return e.jsxs("div",{className:`git-file-item ${o?"selected":""}`,onClick:()=>!R&&c(n.path,y),onContextMenu:v=>{v.preventDefault(),g==null||g(v,n,y)},style:{cursor:R?"not-allowed":"pointer"},title:n.path,children:[u&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:l||!1,onChange:v=>{v.stopPropagation(),u(n.path)},onClick:v=>v.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:ft(N),alt:"file"}),e.jsxs("span",{className:"git-file-name",children:[n.name,d&&e.jsx("span",{className:"git-file-dir",children:d})]}),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(M,{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?"...":"+"}),j&&e.jsx("button",{className:"git-discard-btn",onClick:v=>{v.stopPropagation(),j(n,y)},title:y==="untracked"||y==="added"?"Delete file":"Discard changes",children:e.jsx(M,{name:"revert",size:12})})]})}),Ha=16,za=22,Aa=s.memo(function t({node:n,depth:o,expandedDirs:c,onToggleDir:r,selectedPath:i,onSelect:f,onStage:l,stagingPaths:u,checkedFiles:g,onToggleCheck:j,onContextMenu:p,onDirContextMenu:y,onDiscard:C}){const{t:R}=le(["terminal"]),x=o*Ha;if(!n.isDirectory){const d=n.file.status,v=pt[d];return e.jsxs("div",{className:`git-file-item ${i===n.path?"selected":""}`,onClick:()=>d!=="deleted"&&f(n.file.path,d),onContextMenu:w=>{w.preventDefault(),p==null||p(w,n.file,d)},style:{paddingLeft:`${x+za}px`,cursor:d==="deleted"?"not-allowed":"pointer"},title:n.file.path,children:[j&&e.jsx("input",{type:"checkbox",className:"git-file-checkbox",checked:(g==null?void 0:g.has(n.file.path))||!1,onChange:w=>{w.stopPropagation(),j(n.file.path)},onClick:w=>w.stopPropagation()}),e.jsx("img",{className:"tree-icon",src:ft(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(M,{name:"subitem",size:10,style:{transform:"rotate(180deg)"}})," ",n.file.oldPath.split("/").pop()]}),d==="untracked"&&l&&e.jsx("button",{className:`git-stage-btn ${u!=null&&u.has(n.path)?"staging":""}`,onClick:w=>{w.stopPropagation(),u!=null&&u.has(n.path)||l(n.file.path)},title:R("terminal:fileExplorer.stageFile"),disabled:u==null?void 0:u.has(n.path),children:u!=null&&u.has(n.path)?"...":"+"}),C&&e.jsx("button",{className:"git-discard-btn",onClick:w=>{w.stopPropagation(),C(n.file,d)},title:d==="untracked"||d==="added"?"Delete file":"Discard changes",children:e.jsx(M,{name:"revert",size:12})})]})}const N=c.has(n.path);return e.jsxs("div",{className:"tree-node-wrapper",children:[e.jsxs("div",{className:`tree-node directory ${N?"expanded":""}`,style:{paddingLeft:`${x}px`},onClick:()=>r(n.path),onContextMenu:d=>{d.preventDefault(),d.stopPropagation(),y==null||y(d,n)},children:[e.jsx("span",{className:`tree-arrow ${N?"expanded":""}`,children:e.jsx(M,{name:"caret-right",size:10})}),e.jsx("img",{className:"tree-folder-icon",src:N?"/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:R("terminal:fileExplorer.fileCount",{count:n.fileCount})})]}),N&&e.jsx("div",{className:"tree-children",children:n.children.map(d=>e.jsx(t,{node:d,depth:o+1,expandedDirs:c,onToggleDir:r,selectedPath:i,onSelect:f,onStage:l,stagingPaths:u,checkedFiles:g,onToggleCheck:j,onContextMenu:p,onDirContextMenu:y,onDiscard:C},d.path))})]})}),qt=s.memo(function({groupLabel:n,groupIcon:o,groupColor:c,files:r,treeNodes:i,viewMode:f,selectedPath:l,expandedDirs:u,onToggleDir:g,onFileSelect:j,onStageFile:p,onStageAll:y,stagingPaths:C,checkedFiles:R,onToggleCheck:x,onContextMenu:N,onDirContextMenu:d,onDiscardFile:v,onDiscardAll:w}){const{t:S}=le(["terminal"]);if(r.length===0)return null;const A=r.some(z=>z.status==="untracked"),H=A&&y&&r.length>0,G=C?r.every(z=>C.has(z.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:o}),n," (",r.length,")",H&&e.jsx("button",{className:`git-stage-all-btn ${G?"staging":""}`,onClick:z=>{z.stopPropagation(),G||y()},title:S("terminal:fileExplorer.stageAllUntracked"),disabled:G,children:G?"...":S("terminal:fileExplorer.stageAll")}),w&&e.jsxs("button",{className:"git-discard-all-btn",onClick:z=>{z.stopPropagation(),w()},title:A?`Delete all ${r.length} files`:`Discard all ${r.length} changes`,children:[e.jsx(M,{name:"revert",size:12})," All"]})]}),f==="tree"?e.jsx("div",{className:"git-tree-content",children:i.map(z=>e.jsx(Aa,{node:z,depth:0,expandedDirs:u,onToggleDir:g,selectedPath:l,onSelect:j,onStage:p,stagingPaths:C,checkedFiles:R,onToggleCheck:x,onContextMenu:N,onDirContextMenu:d,onDiscard:v},z.path))}):e.jsx("div",{className:"git-flat-content",children:r.map(z=>e.jsx($a,{file:z,isSelected:l===z.path,onSelect:j,onStage:z.status==="untracked"?p:void 0,isStaging:C==null?void 0:C.has(z.path),showDirPath:!0,isChecked:R==null?void 0:R.has(z.path),onToggleCheck:x,onContextMenu:N,onDiscard:v},z.path))})]})});function Oa({gitStatus:t,loading:n,onFileSelect:o,selectedPath:c,onRefresh:r,onStageFiles:i,stagingPaths:f,currentFolder:l,onCommitComplete:u,mergeInProgress:g,mergingBranch:j,onMergeContinue:p,onMergeAbort:y,onConflictOpen:C,onRevealInTree:R}){const{t:x}=le(["terminal","common"]),[N,d]=s.useState("tree"),[v,w]=s.useState(new Set),[S,A]=s.useState(""),[H,G]=s.useState(""),[z,ae]=s.useState(!1),[ee,D]=s.useState(new Set),[F,I]=s.useState(!1),[re,_]=s.useState(null),ge=s.useRef(null),{showToast:O}=Us(),[Z,L]=s.useState(null),[T,W]=s.useState(null),[ne,be]=s.useState(null),de=s.useCallback((k,P)=>{be({files:[k],label:k.name})},[]),m=s.useCallback(async()=>{if(!(!ne||!l))try{const k=await Y(K("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:ne.files.map(B=>({path:B.path,status:B.status})),directory:l})}),P=await k.json();k.ok&&P.success?(O("success","Discarded",`Reverted ${ne.files.length} file(s)`),r()):O("error","Discard Failed",P.error||"Could not discard changes")}catch{O("error","Discard Failed","Network error")}finally{be(null)}},[ne,l,r,O]),q=s.useCallback((k,P,B)=>{k.preventDefault(),k.stopPropagation(),L({isOpen:!0,position:{x:k.clientX,y:k.clientY},file:P,status:B})},[]),ie=s.useCallback(async(k,P)=>{if(l)try{const B=await Y(K("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:[{path:k.path,status:P}],directory:l})}),ke=await B.json();B.ok&&ke.success?(O("success","Discarded",`Restored ${k.name}`),r()):O("error","Discard Failed",ke.error||"Could not discard changes")}catch{O("error","Discard Failed","Network error")}},[l,r,O]),ue=s.useCallback(async k=>{try{await navigator.clipboard.writeText(k),O("success","Copied","Full path copied")}catch{O("error","Copy Failed","Could not copy path")}},[O]),V=s.useCallback(async k=>{const P=l&&k.startsWith(l+"/")?k.slice(l.length+1):k;try{await navigator.clipboard.writeText(P),O("success","Copied","Relative path copied")}catch{O("error","Copy Failed","Could not copy path")}},[l,O]),E=s.useMemo(()=>{if(!Z)return[];const{file:k,status:P}=Z,B=[];return P==="conflict"&&C?B.push({id:"open-conflict",label:x("terminal:fileExplorer.gitContextMenu.openConflictResolver"),icon:e.jsx(M,{name:"warn",size:14}),onClick:()=>C(k.path)}):P!=="deleted"&&B.push({id:"open-file",label:x("terminal:fileExplorer.gitContextMenu.openFile"),icon:e.jsx(M,{name:"file-text",size:14}),onClick:()=>o(k.path,P)}),P!=="conflict"&&B.push({id:"stage-file",label:x("terminal:fileExplorer.gitContextMenu.stageFile"),icon:e.jsx(M,{name:"plus",size:14}),onClick:()=>{i([k.path])}}),B.push({id:"divider-1",label:"",divider:!0,onClick:()=>{}}),(P==="modified"||P==="deleted"||P==="renamed"||P==="conflict")&&B.push({id:"discard-changes",label:x("terminal:fileExplorer.gitContextMenu.discardChanges"),icon:e.jsx(M,{name:"revert",size:14}),danger:!0,onClick:()=>{ie(k,P)}}),(P==="untracked"||P==="added")&&B.push({id:"delete-file",label:x("terminal:fileExplorer.gitContextMenu.deleteFile"),icon:e.jsx(M,{name:"trash",size:14}),danger:!0,onClick:()=>{ie(k,P)}}),B.push({id:"divider-2",label:"",divider:!0,onClick:()=>{}}),B.push({id:"copy-full-path",label:x("terminal:fileExplorer.gitContextMenu.copyFullPath"),icon:e.jsx(M,{name:"pin",size:14}),onClick:()=>{ue(k.path)}}),B.push({id:"copy-relative-path",label:x("terminal:fileExplorer.gitContextMenu.copyRelativePath"),icon:e.jsx(M,{name:"clipboard",size:14}),onClick:()=>{V(k.path)}}),R&&P!=="deleted"&&B.push({id:"reveal-in-tree",label:x("terminal:fileExplorer.gitContextMenu.revealInTree"),icon:e.jsx(M,{name:"target",size:14}),onClick:()=>R(k.path)}),B},[Z,o,i,C,R,ie,ue,V,x]),Q=s.useCallback((k,P)=>{k.preventDefault(),k.stopPropagation(),W({isOpen:!0,position:{x:k.clientX,y:k.clientY},node:P})},[]),te=s.useCallback(k=>!k.isDirectory&&k.file?[k.file]:k.children.flatMap(P=>te(P)),[]),Ne=s.useCallback(async k=>{if(!l)return;const P=te(k);if(P.length!==0)try{const B=await Y(K("/api/files/git-discard"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({files:P.map(Te=>({path:Te.path,status:Te.status})),directory:l})}),ke=await B.json();B.ok&&ke.success?(O("success","Discarded",`Reverted ${P.length} file(s) in ${k.name}`),r()):O("error","Discard Failed",ke.error||"Could not discard changes")}catch{O("error","Discard Failed","Network error")}},[l,te,r,O]),xe=s.useMemo(()=>{if(!T)return[];const{node:k}=T,P=te(k);return[{id:"discard-dir",label:`Discard Changes (${P.length} files)`,icon:e.jsx(M,{name:"revert",size:14}),danger:!0,onClick:()=>{Ne(k)}},{id:"stage-dir",label:`Stage All (${P.length} files)`,icon:e.jsx(M,{name:"plus",size:14}),onClick:()=>{i(P.map(B=>B.path))}}]},[T,te,Ne,i]),U=s.useCallback(k=>{w(P=>{const B=new Set(P);return B.has(k)?B.delete(k):B.add(k),B})},[]),{conflictFiles:se,conflictTree:pe,changesFiles:me,changesTree:Be,untrackedFiles:Se,untrackedTree:It,allDirPaths:He}=s.useMemo(()=>{if(!t||!t.isGitRepo||t.files.length===0)return{conflictFiles:[],conflictTree:[],changesFiles:[],changesTree:[],untrackedFiles:[],untrackedTree:[],allDirPaths:new Set};const k=new Set,P=t.files.filter(Re=>Re.status==="conflict"),B=Mt(P);Dt(B,k);const ke=t.files.filter(Re=>Re.status==="modified"||Re.status==="added"||Re.status==="deleted"||Re.status==="renamed"),Te=Mt(ke);Dt(Te,k);const ot=t.files.filter(Re=>Re.status==="untracked"),We=Mt(ot);return Dt(We,k),{conflictFiles:P,conflictTree:B,changesFiles:ke,changesTree:Te,untrackedFiles:ot,untrackedTree:We,allDirPaths:k}},[t]);s.useEffect(()=>{w(He)},[He]),s.useEffect(()=>{t!=null&&t.files&&D(new Set(t.files.map(k=>k.path)))},[t==null?void 0:t.files]);const Pt=s.useCallback(()=>{me.length!==0&&be({files:me,label:`${me.length} changed files`})},[me]),_e=s.useCallback(()=>{Se.length!==0&&be({files:Se,label:`${Se.length} unversioned files`})},[Se]),Lt=s.useCallback(()=>{se.length!==0&&be({files:se,label:`${se.length} conflicted files`})},[se]),Ve=se.length>0;s.useEffect(()=>{if(re){const k=re.type==="error"?8e3:4e3,P=setTimeout(()=>_(null),k);return()=>clearTimeout(P)}},[re]);const gt=s.useCallback(async()=>{const k=!z;if(ae(k),k&&l){G(S);try{const B=await(await Y(K(`/api/files/git-log-message?path=${encodeURIComponent(l)}`))).json();B.message&&A(B.message)}catch{}}else A(H)},[z,l,S,H]),je=s.useCallback(k=>{D(P=>{const B=new Set(P);return B.has(k)?B.delete(k):B.add(k),B})},[]),$t=s.useCallback(()=>{if(!(t!=null&&t.files))return;const k=t.files.map(B=>B.path),P=k.every(B=>ee.has(B));D(P?new Set:new Set(k))},[t==null?void 0:t.files,ee]),ve=s.useCallback(async k=>{if(!(!l||!S.trim()||ee.size===0||F)){I(!0),_(null);try{const P=await Y(K("/api/files/git-commit"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:l,message:S.trim(),amend:z,paths:Array.from(ee)})}),B=await P.json();if(!P.ok||!B.success){_({type:"error",text:B.error||"Commit failed"}),I(!1);return}if(k)try{const ke=await Y(K("/api/files/git-push"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({directory:l})}),Te=await ke.json();ke.ok&&Te.success?_({type:"success",text:x("terminal:fileExplorer.committedAndPushed")}):_({type:"error",text:x("terminal:fileExplorer.committedButPushFailed",{error:Te.error||"Unknown error"})})}catch{_({type:"error",text:x("terminal:fileExplorer.committedButPushFailed",{error:"Network error"})})}else _({type:"success",text:x("terminal:fileExplorer.committedSuccessfully")});A(""),G(""),ae(!1),r(),u==null||u()}catch(P){_({type:"error",text:P.message||"Commit failed"})}finally{I(!1)}}},[l,S,z,ee,F,r,u]);if(n)return e.jsx("div",{className:"git-changes-loading",children:x("terminal:fileExplorer.loadingGitStatus")});if(!t||!t.isGitRepo)return e.jsxs("div",{className:"git-changes-empty",children:[e.jsx("div",{className:"git-empty-icon",children:e.jsx(M,{name:"package",size:32})}),e.jsx("div",{className:"git-empty-text",children:x("terminal:fileExplorer.notGitRepo")})]});if(t.files.length===0)return e.jsxs("div",{className:"git-changes-empty",children:[e.jsx("div",{className:"git-empty-icon",children:e.jsx(M,{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:t.branch})})]});const xt=k=>{i([k])},Ke=()=>{const k=Se.map(P=>P.path);k.length>0&&i(k)},De=(k,P)=>{P==="conflict"&&C?C(k):o(k,P)};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(M,{name:"git-branch",size:12})}),t.branch]}),t.counts&&e.jsxs("div",{className:"git-changes-summary",children:[(t.counts.conflict??0)>0&&e.jsxs("span",{className:"git-count conflict",children:[t.counts.conflict,"C"]}),t.counts.modified>0&&e.jsxs("span",{className:"git-count modified",children:[t.counts.modified,"M"]}),t.counts.added>0&&e.jsxs("span",{className:"git-count added",children:[t.counts.added,"A"]}),t.counts.deleted>0&&e.jsxs("span",{className:"git-count deleted",children:[t.counts.deleted,"D"]}),t.counts.untracked>0&&e.jsxs("span",{className:"git-count untracked",children:[t.counts.untracked,"?"]})]}),e.jsxs("div",{className:"git-view-toggle",children:[e.jsx("button",{className:`git-view-toggle-btn ${N==="flat"?"active":""}`,onClick:()=>d("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 ${N==="tree"?"active":""}`,onClick:()=>d("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(M,{name:"refresh",size:12})})]}),g&&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:j?` (${j})`:""})}),e.jsxs("div",{className:"git-merge-actions",children:[e.jsx("button",{className:"git-merge-continue-btn",onClick:p,disabled:Ve,title:x(Ve?"terminal:fileExplorer.resolveAllConflictsFirst":"terminal:fileExplorer.continueMerge"),children:x("terminal:fileExplorer.continue")}),e.jsx("button",{className:"git-merge-abort-btn",onClick:y,title:x("terminal:fileExplorer.abortMerge"),children:x("terminal:fileExplorer.abort")})]})]}),e.jsxs("div",{className:"git-changes-list",children:[e.jsx(qt,{groupLabel:x("terminal:fileExplorer.gitGroups.conflicts"),groupIcon:"C",groupColor:"#ff5555",files:se,treeNodes:pe,viewMode:N,selectedPath:c,expandedDirs:v,onToggleDir:U,onFileSelect:De,checkedFiles:ee,onToggleCheck:je,onContextMenu:q,onDirContextMenu:Q,onDiscardFile:de,onDiscardAll:Lt}),e.jsx(qt,{groupLabel:x("terminal:fileExplorer.gitGroups.changes"),groupIcon:"~",groupColor:"#c89a5a",files:me,treeNodes:Be,viewMode:N,selectedPath:c,expandedDirs:v,onToggleDir:U,onFileSelect:De,checkedFiles:ee,onToggleCheck:je,onContextMenu:q,onDirContextMenu:Q,onDiscardFile:de,onDiscardAll:Pt}),e.jsx(qt,{groupLabel:x("terminal:fileExplorer.gitGroups.unversioned"),groupIcon:"?",groupColor:"#6ab8c8",files:Se,treeNodes:It,viewMode:N,selectedPath:c,expandedDirs:v,onToggleDir:U,onFileSelect:De,onStageFile:xt,onStageAll:Ke,stagingPaths:f,checkedFiles:ee,onToggleCheck:je,onContextMenu:q,onDirContextMenu:Q,onDiscardFile:de,onDiscardAll:_e})]}),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:z,onChange:gt}),x("terminal:fileExplorer.amend")]}),e.jsx("span",{className:"git-commit-file-count",children:x("terminal:fileExplorer.fileCount",{count:ee.size})}),e.jsx("button",{className:"git-commit-select-toggle",onClick:$t,title:ee.size===t.files.length?x("terminal:fileExplorer.deselectAll"):x("terminal:fileExplorer.selectAll"),children:ee.size===t.files.length?x("terminal:fileExplorer.deselectAll"):x("terminal:fileExplorer.selectAll")})]}),e.jsx("textarea",{ref:ge,className:"git-commit-message",placeholder:x("terminal:fileExplorer.commitMessagePlaceholder"),value:S,onChange:k=>A(k.target.value),onKeyDown:k=>{(k.metaKey||k.ctrlKey)&&k.key==="Enter"&&(k.preventDefault(),ve(!1)),(k.metaKey||k.ctrlKey)&&k.shiftKey&&k.key==="Enter"&&(k.preventDefault(),ve(!0)),k.stopPropagation()},rows:3,disabled:F}),re&&e.jsx("div",{className:`git-commit-status ${re.type}`,children:re.text}),e.jsxs("div",{className:"git-commit-actions",children:[e.jsx("button",{className:"git-commit-btn",onClick:()=>ve(!1),disabled:!S.trim()||ee.size===0||F,title:x("terminal:fileExplorer.commitCtrlEnter"),children:x(F?"terminal:fileExplorer.committing":"terminal:fileExplorer.commitAction")}),e.jsx("button",{className:"git-commit-push-btn",onClick:()=>ve(!0),disabled:!S.trim()||ee.size===0||F,title:x("terminal:fileExplorer.commitAndPushCtrlShiftEnter"),children:F?"...":x("terminal:fileExplorer.commitAndPush")})]})]}),Z&&e.jsx(it,{isOpen:Z.isOpen,position:Z.position,worldPosition:{x:0,z:0},actions:E,onClose:()=>L(null)}),T&&e.jsx(it,{isOpen:T.isOpen,position:T.position,worldPosition:{x:0,z:0},actions:xe,onClose:()=>W(null)}),ne&&e.jsx("div",{className:"git-discard-confirm-overlay",onClick:()=>be(null),children:e.jsxs("div",{className:"git-discard-confirm",onClick:k=>k.stopPropagation(),children:[e.jsx("p",{children:ne.files.some(k=>k.status==="untracked"||k.status==="added")?e.jsxs(e.Fragment,{children:["Delete ",e.jsx("strong",{children:ne.label}),"?"]}):e.jsxs(e.Fragment,{children:["Discard changes to ",e.jsx("strong",{children:ne.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:()=>be(null),children:"Cancel"}),e.jsx("button",{className:"git-discard-confirm-btn",onClick:m,children:ne.files.some(k=>k.status==="untracked"||k.status==="added")?"Delete":"Discard"})]})]})})]})}const Ys=s.memo(Oa,(t,n)=>t.loading!==n.loading||t.selectedPath!==n.selectedPath||t.stagingPaths!==n.stagingPaths||t.currentFolder!==n.currentFolder||t.mergeInProgress!==n.mergeInProgress||t.mergingBranch!==n.mergingBranch?!1:t.gitStatus===null&&n.gitStatus===null?!0:!(t.gitStatus===null||n.gitStatus===null||t.gitStatus.isGitRepo!==n.gitStatus.isGitRepo||t.gitStatus.branch!==n.gitStatus.branch||t.gitStatus.files.length!==n.gitStatus.files.length||t.gitStatus.mergeInProgress!==n.gitStatus.mergeInProgress));Ys.displayName="GitChanges";const Ga=s.memo(function({tab:n,isActive:o,onSelect:c,onClose:r,onContextMenu:i}){const{t:f}=le(["terminal"]),l={name:n.filename,path:n.path,isDirectory:!1,extension:n.extension},u=s.useCallback(()=>{c(n.path)},[c,n.path]),g=s.useCallback(y=>{y.button===1&&(y.preventDefault(),y.stopPropagation(),r(n.path))},[r,n.path]),j=s.useCallback(y=>{y.preventDefault(),y.stopPropagation(),r(n.path)},[r,n.path]),p=s.useCallback(y=>{y.preventDefault(),y.stopPropagation(),i(y,n)},[i,n]);return e.jsxs("div",{className:`file-tab ${o?"active":""}`,onClick:u,onMouseDown:g,onContextMenu:p,title:n.path,children:[e.jsx("img",{className:"file-tab-icon",src:Xt(l),alt:"file"}),e.jsx("span",{className:"file-tab-name",children:n.filename}),e.jsx("button",{className:"file-tab-close",onClick:j,title:f("terminal:fileExplorer.closeMiddleClick"),children:"×"})]})});function Ua(t){return typeof t.path=="string"&&t.path.startsWith("/")}function Ba({tabs:t,activeTabPath:n,onSelectTab:o,onCloseTab:c,onCloseAllTabs:r,onShowGitHistory:i}){const{t:f}=le(["terminal"]),[l,u]=s.useState(null),g=s.useCallback((y,C)=>{u({isOpen:!0,position:{x:y.clientX,y:y.clientY},tab:C})},[]),j=s.useCallback(()=>u(null),[]),p=s.useMemo(()=>{if(!l)return[];const y=l.tab,C=!!i&&Ua(y),R=[{id:"git-history",label:f("terminal:fileExplorer.showGitHistory")??"Show Git History",icon:e.jsx(M,{name:"git-commit",size:14}),disabled:!C,onClick:()=>{C&&i(y.path)}}];return r&&R.push({id:"divider-close-all",label:"",divider:!0,onClick:()=>{}},{id:"close-all-tabs",label:f("terminal:fileExplorer.closeAllTabs")??"Close all tabs",icon:e.jsx(M,{name:"cross",size:14}),danger:!0,onClick:()=>r()}),R},[l,i,r,f]);return t.length===0?null:e.jsxs("div",{className:"file-tabs-bar",children:[e.jsx("div",{className:"file-tabs-container",children:t.map(y=>e.jsx(Ga,{tab:y,isActive:n===y.path,onSelect:o,onClose:c,onContextMenu:g},y.path))}),l&&e.jsx(it,{isOpen:l.isOpen,position:l.position,worldPosition:{x:0,z:0},actions:p,onClose:j})]})}const qs=s.memo(Ba,(t,n)=>{if(t.activeTabPath!==n.activeTabPath||t.tabs.length!==n.tabs.length||t.onShowGitHistory!==n.onShowGitHistory||t.onCloseAllTabs!==n.onCloseAllTabs)return!1;for(let o=0;o<t.tabs.length;o++)if(t.tabs[o].path!==n.tabs[o].path)return!1;return!0});qs.displayName="FileTabs";const _a=s.memo(function({currentFolder:n,gitStatus:o,onBranchChanged:c,onMerge:r,onCompare:i,onPullConflicts:f}){const{t:l}=le(["terminal","common"]),[u,g]=s.useState(!1),[j,p]=s.useState(""),[y,C]=s.useState(!1),[R,x]=s.useState(""),[N,d]=s.useState(!1),[v,w]=s.useState(null),[S,A]=s.useState(null),H=s.useRef(null),G=s.useRef(null),z=s.useRef(null),{branches:ae,loading:ee,operationInProgress:D,loadBranches:F,checkoutBranch:I,createBranch:re,pullFromRemote:_,pushToRemote:ge}=Qt();s.useEffect(()=>{u&&n&&(F(n),setTimeout(()=>{var E;return(E=G.current)==null?void 0:E.focus()},50)),u||(p(""),C(!1),x(""),w(null))},[u,n,F]),s.useEffect(()=>{if(v){const E=v.type==="error"?8e3:3e3,Q=setTimeout(()=>w(null),E);return()=>clearTimeout(Q)}},[v]),s.useEffect(()=>{y&&setTimeout(()=>{var E;return(E=z.current)==null?void 0:E.focus()},50)},[y]),s.useEffect(()=>{if(!u)return;const E=te=>{const Ne=te.target;!Ne.closest(".branch-widget-selector")&&!Ne.closest(".branch-widget-dropdown")&&g(!1)},Q=te=>{te.key==="Escape"&&(te.preventDefault(),te.stopPropagation(),g(!1))};return document.addEventListener("click",E),document.addEventListener("keydown",Q,!0),()=>{document.removeEventListener("click",E),document.removeEventListener("keydown",Q,!0)}},[u]);const O=s.useCallback(async E=>{if(!n||D||E.isCurrent)return;const Q=await I(n,E.name);Q.success?(w({type:"success",text:l("terminal:fileExplorer.switchedToBranch",{branch:Q.branch||E.name})}),c(),F(n)):w({type:"error",text:Q.error||l("terminal:fileExplorer.checkoutFailed")})},[n,D,I,c,F]),Z=s.useCallback(async()=>{if(!n||!R.trim()||D)return;const E=await re(n,R.trim());E.success?(w({type:"success",text:l("terminal:fileExplorer.createdBranch",{branch:E.branch})}),C(!1),x(""),c(),F(n)):w({type:"error",text:E.error||l("terminal:fileExplorer.createBranchFailed")})},[n,R,D,re,c,F]),L=s.useCallback(async()=>{if(!n||D)return;const E=await _(n);E.success?(E.stashConflicts&&E.stashConflicts.length>0?(w({type:"error",text:`Pull succeeded but stash pop had conflicts: ${E.stashConflicts.length} file(s). Resolve manually.`}),f==null||f(E.stashConflicts),g(!1)):E.stashed?w({type:"success",text:"Pull complete. Local changes were auto-stashed and restored."}):w({type:"success",text:l("terminal:fileExplorer.pullComplete")}),c(),F(n)):E.conflicts&&E.conflicts.length>0?(w({type:"error",text:`Pull conflicts: ${E.conflicts.length} file(s)`}),f==null||f(E.conflicts),g(!1)):w({type:"error",text:E.error||l("terminal:fileExplorer.pullFailed")})},[n,D,_,c,F,f]),T=s.useCallback(async()=>{if(!n||D)return;const E=await ge(n);E.success?w({type:"success",text:l("terminal:fileExplorer.pushComplete")}):w({type:"error",text:E.error||l("terminal:fileExplorer.pushFailed")})},[n,D,ge]),[W,ne]=s.useState(!1),be=s.useCallback(async()=>{if(!(!n||D||W)){ne(!0);try{const E=await Y(K("/api/files/git-fetch"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:n})});if(E.ok)w({type:"success",text:"Fetch complete"}),c(),F(n);else{const Q=await E.json().catch(()=>({error:"Fetch failed"}));w({type:"error",text:Q.error||"Fetch failed"})}}catch{w({type:"error",text:"Fetch failed"})}finally{ne(!1)}}},[n,D,W,c,F]),de=(o==null?void 0:o.branch)||"unknown",m=!!D,q=s.useCallback((E,Q)=>{Q.isCurrent||(E.preventDefault(),E.stopPropagation(),A({isOpen:!0,position:{x:E.clientX,y:E.clientY},branch:Q.name}))},[]),ie=s.useMemo(()=>{if(!S)return[];const E=!!D||(o==null?void 0:o.mergeInProgress);return[{id:"compare",label:l("terminal:fileExplorer.showDiffWith",{branch:S.branch}),icon:e.jsx(M,{name:"arrows-horizontal",size:14}),disabled:!!D,onClick:()=>{i==null||i(S.branch),g(!1)}},{id:"merge",label:l("terminal:fileExplorer.mergeInto",{source:S.branch,target:de}),icon:"⤵",disabled:!!E,onClick:()=>{r&&r(S.branch),g(!1)}},{id:"divider-1",label:"",divider:!0,onClick:()=>{}},{id:"checkout",label:l("terminal:fileExplorer.checkoutBranch",{branch:S.branch}),icon:e.jsx(M,{name:"git-branch",size:14}),disabled:!!D,onClick:()=>{const Q=ae.find(te=>te.name===S.branch);Q&&O(Q)}}]},[S,D,o==null?void 0:o.mergeInProgress,de,r,i,ae,O]),ue=s.useMemo(()=>{const E=ae.filter(te=>!te.isRemote);if(!j)return E;const Q=j.toLowerCase();return E.filter(te=>te.name.toLowerCase().includes(Q))},[ae,j]),V=s.useMemo(()=>{const E=ae.filter(te=>te.isRemote);if(!j)return E;const Q=j.toLowerCase();return E.filter(te=>te.name.toLowerCase().includes(Q))},[ae,j]);return e.jsxs("div",{className:"branch-widget",style:{position:"relative"},children:[e.jsxs("div",{className:"branch-widget-selector",onClick:E=>{E.stopPropagation(),g(!u)},title:`Branch: ${de}`,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:de}),e.jsx("span",{className:"branch-widget-arrow",children:"▼"})]}),u&&e.jsxs("div",{className:"branch-widget-dropdown",ref:H,children:[e.jsx("div",{className:"branch-widget-search",children:e.jsx("input",{ref:G,type:"text",className:"branch-widget-search-input",placeholder:l("terminal:fileExplorer.searchBranches"),value:j,onChange:E=>p(E.target.value),onKeyDown:E=>E.stopPropagation()})}),v&&e.jsx("div",{className:`branch-widget-status ${v.type}`,children:v.text}),e.jsx("div",{className:"branch-widget-section-header",children:l("terminal:fileExplorer.actions")}),e.jsxs("div",{className:"branch-widget-actions",children:[e.jsxs("div",{className:`branch-widget-action-item ${m||W?"disabled":""}`,onClick:be,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:W?"Fetching...":"Fetch"})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:L,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:l(D==="pull"?"terminal:fileExplorer.pulling":"terminal:fileExplorer.pull")})]}),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 4l4 4h-2.5v5h-3V8H4l4-4z"})})}),e.jsx("span",{className:"branch-widget-action-label",children:l(D==="push"?"terminal:fileExplorer.pushing":"terminal:fileExplorer.push")})]}),e.jsxs("div",{className:`branch-widget-action-item ${m?"disabled":""}`,onClick:()=>{m||C(!y)},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:l("terminal:fileExplorer.newBranch")})]})]}),y&&e.jsxs("div",{className:"branch-widget-new-branch",children:[e.jsx("input",{ref:z,type:"text",className:"branch-widget-new-branch-input",placeholder:l("terminal:fileExplorer.branchNamePlaceholder"),value:R,onChange:E=>x(E.target.value),onKeyDown:E=>{E.stopPropagation(),E.key==="Enter"&&Z(),E.key==="Escape"&&(C(!1),x(""))}}),e.jsx("button",{className:"branch-widget-new-branch-confirm",onClick:Z,disabled:!R.trim()||m,children:D==="create"?"...":l("common:buttons.create")})]}),e.jsxs("div",{className:"branch-widget-section-header",children:[l("terminal:fileExplorer.localBranches"),ee&&e.jsxs("span",{className:"branch-widget-loading-hint",children:[" ",l("terminal:fileExplorer.loading")]})]}),e.jsxs("div",{className:"branch-widget-branch-list",children:[ue.length===0&&!ee&&e.jsx("div",{className:"branch-widget-empty",children:l("terminal:fileExplorer.noBranchesFound")}),ue.map(E=>e.jsxs("div",{className:`branch-widget-branch-item ${E.isCurrent?"current":""} ${m?"disabled":""}`,onClick:()=>O(E),onContextMenu:Q=>q(Q,E),title:E.lastMessage||E.name,children:[e.jsxs("span",{className:"branch-widget-branch-name",children:[E.isCurrent&&e.jsx("span",{className:"branch-widget-current-marker",children:"*"}),E.name]}),E.lastCommit&&e.jsx("span",{className:"branch-widget-branch-commit",children:E.lastCommit})]},E.name))]}),V.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"branch-widget-section-header clickable",onClick:()=>d(!N),children:[e.jsx("span",{className:"branch-widget-section-toggle",children:N?"▾":"▸"}),l("terminal:fileExplorer.remoteBranches",{count:V.length})]}),N&&e.jsx("div",{className:"branch-widget-branch-list",children:V.map(E=>e.jsxs("div",{className:`branch-widget-branch-item remote ${m?"disabled":""}`,onClick:()=>O(E),onContextMenu:Q=>q(Q,E),title:E.lastMessage||E.name,children:[e.jsx("span",{className:"branch-widget-branch-name",children:E.name}),E.lastCommit&&e.jsx("span",{className:"branch-widget-branch-commit",children:E.lastCommit})]},E.name))})]})]}),S&&e.jsx(it,{isOpen:S.isOpen,position:S.position,worldPosition:{x:0,z:0},actions:ie,onClose:()=>A(null)})]})});function Va(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function St(t,n){if(!t)return"";const o=Es.languages[n];return o?Es.highlight(t,o,n):Va(t)}function Ka(t){const n=[],o=t.split(`
|
|
9
9
|
`);let c=[],r=!1,i=[],f=[],l=!1;for(const u of o)u.startsWith("<<<<<<<")?(c.length>0&&(n.push({type:"unchanged",content:c.join(`
|
|
10
10
|
`)}),c=[]),r=!0,l=!1,i=[],f=[]):u.startsWith("=======")&&r?l=!0:u.startsWith(">>>>>>>")&&r?(n.push({type:"conflict",ours:i.join(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as J,a as Z,r,s as h,j as e,D as de,I as H,C as oe,b as me,c as be,d as ue,g as he,e as _e,Q as pe,R as xe}from"./main-Bon1sZAi.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const fe=({building:a,connections:x,activeConnectionId:l,activeDatabase:c,collapsed:y,onToggleCollapse:f,onConnectionChange:Q,onDatabaseChange:S,onInsertTable:L,onSelectTableQuery:P})=>{const{t:m}=J(["terminal"]),q=Z(a.id),[I,R]=r.useState(new Set),[k,n]=r.useState(""),[d,g]=r.useState(""),[$,w]=r.useState(!1),[U,F]=r.useState(null),K=r.useRef(null),C=r.useRef(null),O=r.useRef(null),N=l?q.databases.get(l)??[]:[],G=l&&c?`${l}:${c}`:"",j=G?q.tables.get(G)??[]:[],p=l?q.connectionStatus.get(l):void 0,D=r.useMemo(()=>{if(!k.trim())return N;const t=k.toLowerCase();return N.filter(o=>o.toLowerCase().includes(t))},[N,k]),b=r.useMemo(()=>{if(!d.trim())return j;const t=d.toLowerCase();return j.filter(o=>o.name.toLowerCase().includes(t))},[j,d]);r.useEffect(()=>{const t=o=>{C.current&&!C.current.contains(o.target)&&w(!1)};return $&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[$]),r.useEffect(()=>{l&&!p&&h.testDatabaseConnection(a.id,l)},[a.id,l,p]),r.useEffect(()=>{l&&(p!=null&&p.connected)&&N.length===0&&h.listDatabases(a.id,l)},[a.id,l,p==null?void 0:p.connected,N.length]),r.useEffect(()=>{l&&c&&j.length===0&&h.listTables(a.id,l,c)},[a.id,l,c,j.length]),r.useEffect(()=>{F(null),g("")},[l,c]);const _=r.useCallback(t=>{R(o=>{const T=new Set(o);if(T.has(t))T.delete(t);else if(T.add(t),l&&c){const v=`${l}:${c}:${t}`;q.tableSchemas.has(v)||h.getTableSchema(a.id,l,c,t)}return T})},[a.id,l,c,q.tableSchemas]),z=t=>{if(!l||!c)return null;const o=`${l}:${c}:${t}`;return q.tableSchemas.get(o)};return y?e.jsx("div",{className:"database-sidebar database-sidebar--collapsed",children:e.jsx("button",{className:"database-sidebar__toggle",onClick:f,title:m("terminal:database.expandSidebar"),children:"»"})}):e.jsxs("div",{className:"database-sidebar",children:[e.jsxs("div",{className:"database-sidebar__header",children:[e.jsx("span",{children:m("terminal:database.explorer")}),e.jsx("button",{className:"database-sidebar__toggle",onClick:f,title:m("terminal:database.collapseSidebar"),children:"«"})]}),e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:m("terminal:database.connection")}),e.jsx("select",{className:"database-sidebar__select",value:l||"",onChange:t=>Q(t.target.value),children:x.length===0?e.jsx("option",{value:"",children:m("terminal:database.noConnections")}):x.map(t=>{var o;return e.jsxs("option",{value:t.id,children:[((o=de[t.engine])==null?void 0:o.icon)??"🗄️"," ",t.name]},t.id)})}),p&&e.jsx("div",{className:`database-sidebar__status ${p.connected?"database-sidebar__status--connected":"database-sidebar__status--error"}`,children:p.connected?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✓"}),m("terminal:database.connected"),p.serverVersion&&e.jsxs("span",{className:"database-sidebar__version",children:["(",p.serverVersion,")"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✗"}),p.error||m("terminal:database.disconnected")]})})]}),N.length>0&&e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:m("terminal:database.databaseTitle")}),e.jsxs("div",{className:"database-sidebar__searchable-select",ref:C,children:[e.jsx("input",{ref:K,className:"database-sidebar__search-input",type:"text",value:$?k:c||"",placeholder:m("terminal:database.selectDatabase"),onChange:t=>{n(t.target.value),$||w(!0)},onFocus:()=>{w(!0),n("")},onKeyDown:t=>{var o,T;t.key==="Escape"?(w(!1),n(""),(o=K.current)==null||o.blur()):t.key==="Enter"&&D.length===1&&(S(D[0]),w(!1),n(""),(T=K.current)==null||T.blur())}}),$&&e.jsx("div",{className:"database-sidebar__dropdown",children:D.length===0?e.jsx("div",{className:"database-sidebar__dropdown-empty",children:"No matches"}):D.map(t=>e.jsx("div",{className:`database-sidebar__dropdown-item ${t===c?"database-sidebar__dropdown-item--active":""}`,onMouseDown:o=>{o.preventDefault(),S(t),w(!1),n("")},children:t},t))})]})]}),j.length>0&&e.jsxs("div",{className:"database-sidebar__section database-sidebar__section--tables",children:[e.jsx("div",{className:"database-sidebar__section-title",children:d.trim()?m("terminal:database.tablesCount",{count:b.length})+` / ${j.length}`:m("terminal:database.tablesCount",{count:j.length})}),e.jsxs("div",{className:"database-sidebar__table-filter",children:[e.jsx("input",{ref:O,className:"database-sidebar__table-filter-input",type:"text",value:d,placeholder:m("terminal:database.filterTables"),onChange:t=>g(t.target.value),onKeyDown:t=>{var o;t.key==="Escape"&&(d?g(""):(o=O.current)==null||o.blur(),t.stopPropagation())}}),d&&e.jsx("button",{className:"database-sidebar__table-filter-clear",onClick:()=>{var t;g(""),(t=O.current)==null||t.focus()},title:"Clear filter",children:"×"})]}),e.jsxs("div",{className:"database-sidebar__tables",children:[d.trim()&&b.length===0&&e.jsx("div",{className:"database-sidebar__tables-empty",children:m("terminal:database.noTablesMatch")}),b.map(t=>{const o=I.has(t.name),T=o?z(t.name):null;return e.jsxs("div",{className:"database-sidebar__table",children:[e.jsxs("div",{className:"database-sidebar__table-header",children:[e.jsx("button",{className:"database-sidebar__table-expand",onClick:()=>_(t.name),title:o?"Collapse table schema":"Expand table schema",children:e.jsx(H,{name:o?"caret-down":"caret-right",size:10})}),e.jsx("span",{className:"database-sidebar__table-icon",children:e.jsx(H,{name:t.type==="view"?"eye":"clipboard",size:12})}),e.jsx("span",{className:`database-sidebar__table-name ${U===t.name?"database-sidebar__table-name--selected":""}`,onClick:()=>F(t.name),onDoubleClick:()=>{F(t.name),P(t.name)},children:t.name}),e.jsx("button",{className:"database-sidebar__table-insert",onClick:v=>{v.stopPropagation(),L(t.name)},title:m("terminal:database.insertTableName"),children:"+"})]}),o&&T&&e.jsx("div",{className:"database-sidebar__table-columns",children:T.columns.map(v=>e.jsxs("div",{className:"database-sidebar__column",onClick:()=>L(v.name),title:`${v.type}${v.nullable?" NULL":" NOT NULL"}${v.primaryKey?" PK":""}`,children:[e.jsx("span",{className:"database-sidebar__column-icon",children:v.primaryKey?e.jsx(H,{name:"key",size:11}):null}),e.jsx("span",{className:"database-sidebar__column-name",children:v.name}),e.jsx("span",{className:"database-sidebar__column-type",children:v.type})]},v.name))})]},t.name)})]})]})]})},je=({buildingId:a,history:x,onLoadQuery:l})=>{const{t:c}=J(["terminal","common"]),[y,f]=r.useState(""),[Q,S]=r.useState(!1),[L,P]=r.useState(!1),m=r.useMemo(()=>{let n=x;if(Q&&(n=n.filter(d=>d.favorite)),y.trim()){const d=y.toLowerCase();n=n.filter(g=>g.query.toLowerCase().includes(d)||g.database.toLowerCase().includes(d))}return n},[x,Q,y]),q=n=>{const d=new Date(n),$=new Date().getTime()-d.getTime();return $<1440*60*1e3?d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):$<10080*60*1e3?d.toLocaleDateString([],{weekday:"short"})+" "+d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):d.toLocaleDateString([],{month:"short",day:"numeric"})},I=r.useCallback((n,d)=>{d.stopPropagation(),h.toggleQueryFavorite(a,n)},[a]),R=r.useCallback((n,d)=>{d.stopPropagation(),h.deleteQueryFromHistory(a,n)},[a]),k=r.useCallback(()=>{P(!0)},[]);return x.length===0?e.jsxs("div",{className:"query-history query-history--empty",children:[e.jsx("p",{children:c("terminal:database.noHistory")}),e.jsx("p",{children:c("terminal:database.queriesAppearHere")})]}):e.jsxs("div",{className:"query-history",children:[e.jsxs("div",{className:"query-history__toolbar",children:[e.jsx("input",{type:"text",className:"query-history__search",placeholder:c("terminal:database.searchQueries"),value:y,onChange:n=>f(n.target.value)}),e.jsxs("label",{className:"query-history__filter",children:[e.jsx("input",{type:"checkbox",checked:Q,onChange:n=>S(n.target.checked)}),c("terminal:database.favoritesOnly")]}),e.jsx("button",{className:"query-history__clear",onClick:k,title:c("terminal:database.clearAll"),children:c("terminal:database.clearAll")})]}),e.jsxs("div",{className:"query-history__list",children:[m.map(n=>e.jsxs("div",{className:`query-history__item ${n.status==="error"?"query-history__item--error":""}`,onClick:()=>l(n.query),children:[e.jsxs("div",{className:"query-history__item-header",children:[e.jsx("span",{className:`query-history__status ${n.status==="success"?"query-history__status--success":"query-history__status--error"}`,children:e.jsx(H,{name:n.status==="success"?"check":"cross",size:12})}),e.jsx("span",{className:"query-history__database",children:n.database}),e.jsx("span",{className:"query-history__date",children:q(n.executedAt)}),e.jsxs("span",{className:"query-history__duration",children:[n.duration,"ms"]}),n.rowCount!==void 0&&e.jsx("span",{className:"query-history__row-count",children:c("terminal:database.rowCount",{count:n.rowCount})})]}),e.jsx("div",{className:"query-history__query",children:e.jsx("code",{children:n.query.length>200?n.query.substring(0,200)+"...":n.query})}),n.error&&e.jsx("div",{className:"query-history__error",children:n.error}),e.jsxs("div",{className:"query-history__actions",children:[e.jsx("button",{className:`query-history__favorite ${n.favorite?"query-history__favorite--active":""}`,onClick:d=>I(n.id,d),title:n.favorite?c("terminal:database.removeFromFavorites"):c("terminal:database.addToFavorites"),children:e.jsx(H,{name:"star",size:12,weight:n.favorite?"fill":"regular",color:n.favorite?"#facc15":void 0})}),e.jsx("button",{className:"query-history__delete",onClick:d=>R(n.id,d),title:c("terminal:database.deleteFromHistory"),children:e.jsx(H,{name:"trash",size:12})})]})]},n.id)),m.length===0&&e.jsx("div",{className:"query-history__no-results",children:c("terminal:database.noQueriesMatch")})]}),e.jsx(oe,{isOpen:L,title:c("terminal:database.clearAll"),message:c("terminal:database.confirmClearHistory"),confirmLabel:c("terminal:database.clearAll"),cancelLabel:c("common:buttons.cancel"),variant:"danger",onConfirm:()=>h.clearQueryHistory(a),onClose:()=>P(!1)})]})},ye=({tabs:a,activeTabId:x,onTabClick:l,onTabClose:c})=>{const{t:y}=J(["terminal"]);return e.jsx("div",{className:"database-tabs",children:a.map(f=>e.jsxs("div",{className:`database-tabs__tab ${x===f.id?"database-tabs__tab--active":""}`,children:[e.jsxs("button",{className:"database-tabs__tab-label",onClick:()=>l(f),title:`${f.connectionName} / ${f.database}`,children:[f.database,e.jsx("span",{className:"database-tabs__tab-connection",children:f.connectionName})]}),e.jsx("button",{className:"database-tabs__tab-close",onClick:()=>c(f.id),title:y("terminal:database.closeTab"),"aria-label":`Close ${f.database} tab`,children:"×"})]},f.id))})},ee=a=>`db-panel-${a}`;function Ne(a){try{const x=localStorage.getItem(ee(a));return x?JSON.parse(x):{}}catch{return{}}}function ve(a,x){try{localStorage.setItem(ee(a),JSON.stringify(x))}catch{}}const ge=({building:a,onClose:x})=>{var B,W,Y,X;const{t:l}=J(["terminal","common"]),c=Z(a.id),y=me(a.id),f=be(a.id),Q=ue(a.id),S=r.useRef(Ne(a.id)),L=r.useRef(null),P=r.useRef(0),m=((B=a.database)==null?void 0:B.connections)??[],q=(s,i)=>`${s}:${i}`,I=s=>s?(S.current.queries??{})[s]??"":S.current.generalQuery??"",[R,k]=r.useState("results"),[n,d]=r.useState(0),[g,$]=r.useState(!1),[w,U]=r.useState(!1),[F,K]=r.useState(()=>(S.current.openTabs??[]).map(i=>{var u;return{id:`${i.connectionId}:${i.database}`,connectionId:i.connectionId,connectionName:((u=m.find(A=>A.id===i.connectionId))==null?void 0:u.name)??i.connectionId,database:i.database}})),[C,O]=r.useState(S.current.activeTabId??null),[N,G]=r.useState(()=>{const s=S.current.queries??{};return S.current.generalQuery,s}),[j,p]=r.useState(I(C)),D=r.useCallback(s=>{p(i=>{const u=typeof s=="function"?s(i):s;return G(A=>{const E={...A};return C&&(E[C]=u),E}),u})},[C]),b=c.activeConnectionId??S.current.connectionId??((W=a.database)==null?void 0:W.activeConnectionId)??((Y=m[0])==null?void 0:Y.id),_=c.activeDatabase??S.current.database??((X=a.database)==null?void 0:X.activeDatabase),z=m.find(s=>s.id===b),t=b&&_?`${b}:${_}`:"",o=t?c.tables.get(t)??[]:[],T=r.useMemo(()=>{const s=new Map;return!b||!_||o.forEach(i=>{const u=c.tableSchemas.get(`${b}:${_}:${i.name}`);u&&s.set(i.name,{columns:u.columns})}),s},[b,_,o,c.tableSchemas]),v=r.useCallback((s,i)=>{var E;const u=q(s,i),A=((E=m.find(M=>M.id===s))==null?void 0:E.name)??s;K(M=>{if(M.some(ie=>ie.id===u))return M;const ce={id:u,connectionId:s,connectionName:A,database:i};return[...M,ce]}),O(u),p(N[u]??""),h.setActiveConnection(a.id,s),h.setActiveDatabase(a.id,i)},[a.id,m,N]),ae=r.useCallback(s=>{K(i=>i.filter(u=>u.id!==s)),C===s&&K(i=>{if(i.length>0){const u=i[0];O(u.id),p(N[u.id]??""),h.setActiveConnection(a.id,u.connectionId),h.setActiveDatabase(a.id,u.database)}else O(null),p("");return i})},[C,a.id,N]),se=r.useCallback(s=>{O(s.id),p(N[s.id]??""),h.setActiveConnection(a.id,s.connectionId),h.setActiveDatabase(a.id,s.database)},[a.id,N]);r.useEffect(()=>{if(!w&&m.length>0){const s=S.current;s.connectionId&&m.some(i=>i.id===s.connectionId)&&(h.setActiveConnection(a.id,s.connectionId),h.listDatabases(a.id,s.connectionId),s.database&&(h.setActiveDatabase(a.id,s.database),h.listTables(a.id,s.connectionId,s.database))),U(!0)}},[a.id,m,w]),r.useEffect(()=>{h.requestQueryHistory(a.id)},[a.id]),r.useEffect(()=>{const s=i=>{i.key==="Escape"&&(i.preventDefault(),i.stopPropagation(),x())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[x]),r.useEffect(()=>{w&&b&&ve(a.id,{connectionId:b,database:_,lastQuery:j,queries:N,generalQuery:"",openTabs:F.map(s=>({connectionId:s.connectionId,database:s.database})),activeTabId:C??void 0})},[a.id,b,_,j,w,F,C,N]);const te=r.useCallback(s=>{var i;if(!(!b||!_||!j.trim()||Q))if(s==="cursor"){const u=(i=L.current)==null?void 0:i.querySelector(".query-editor__textarea"),A=(u==null?void 0:u.selectionStart)??P.current,E=he(j,A);E&&h.executeQuery(a.id,b,_,E)}else{const u=_e(j);if(u.length<=1)h.executeQuery(a.id,b,_,j.trim());else{const A=b,E=_;(async()=>{for(const M of u)await h.executeQueryAndWait(a.id,A,E,M.sql)})()}}},[a.id,b,_,j,Q]),ne=r.useCallback(s=>{D(s),k("results")},[]),re=r.useCallback(s=>{h.setActiveConnection(a.id,s),h.listDatabases(a.id,s)},[a.id]),le=r.useCallback(s=>{b&&(v(b,s),h.listTables(a.id,b,s))},[a.id,b,v]),V=y[n];return m.length===0?e.jsxs("div",{className:"database-panel",ref:L,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:e.jsx(H,{name:"database",size:16})}),e.jsx("span",{className:"database-panel__name",children:a.name})]}),e.jsx("button",{className:"database-panel__close",onClick:x,children:"×"})]}),e.jsx("div",{className:"database-panel__body",children:e.jsxs("div",{className:"database-panel__no-connections",children:[e.jsx("div",{className:"database-panel__no-connections-icon",children:e.jsx(H,{name:"plug",size:32})}),e.jsx("h3",{children:l("terminal:database.noConnections")}),e.jsx("p",{children:l("terminal:database.noConnectionsDesc")}),e.jsx("p",{children:l("terminal:database.toGetStarted")}),e.jsxs("ol",{children:[e.jsx("li",{children:l("terminal:database.step1Close")}),e.jsx("li",{children:l("terminal:database.step2Settings")}),e.jsx("li",{children:l("terminal:database.step3AddConnection")}),e.jsx("li",{children:l("terminal:database.step4Reopen")})]})]})})]}):e.jsxs("div",{className:"database-panel",ref:L,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:(z==null?void 0:z.engine)==="mysql"?"🐬":"🐘"}),e.jsx("span",{className:"database-panel__name",children:a.name}),z&&e.jsxs("span",{className:"database-panel__connection-info",children:[z.name," / ",_||l("terminal:database.noDatabaseSelected")]})]}),e.jsx("button",{className:"database-panel__close",onClick:x,children:"×"})]}),e.jsxs("div",{className:"database-panel__body",children:[e.jsx(fe,{building:a,connections:m,activeConnectionId:b,activeDatabase:_,collapsed:g,onToggleCollapse:()=>$(!g),onConnectionChange:re,onDatabaseChange:le,onInsertTable:s=>D(i=>i+` ${s}`),onSelectTableQuery:s=>{const i=`SELECT * FROM ${s}`;D(i),b&&_&&h.executeQuery(a.id,b,_,i)}}),e.jsxs("div",{className:"database-panel__main",children:[F.length>0&&e.jsx(ye,{tabs:F,activeTabId:C,onTabClick:se,onTabClose:ae}),e.jsx(pe,{query:j,onChange:D,onExecute:te,isExecuting:Q,disabled:!b||!_,tables:o,tableSchemas:T,onRequestTableSchema:s=>{b&&_&&h.getTableSchema(a.id,b,_,s)}}),e.jsxs("div",{className:"database-panel__tabs",children:[e.jsxs("button",{className:`database-panel__tab ${R==="results"?"database-panel__tab--active":""}`,onClick:()=>k("results"),children:[l("terminal:database.results"),y.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:y.length})]}),e.jsxs("button",{className:`database-panel__tab ${R==="history"?"database-panel__tab--active":""}`,onClick:()=>k("history"),children:[l("terminal:database.history"),f.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:f.length})]}),R==="results"&&y.length>1&&e.jsxs("div",{className:"database-panel__result-nav",children:[e.jsxs("button",{disabled:n>=y.length-1,onClick:()=>d(s=>s+1),children:["← ",l("terminal:database.older")]}),e.jsxs("span",{children:[n+1," / ",y.length]}),e.jsxs("button",{disabled:n<=0,onClick:()=>d(s=>s-1),children:[l("terminal:database.newer")," →"]})]})]}),e.jsx("div",{className:"database-panel__tab-content",children:R==="results"?V?e.jsx(xe,{result:V,buildingId:a.id,building:a}):e.jsxs("div",{className:"database-panel__empty",children:[e.jsx("p",{children:l("terminal:database.noResultsYet")}),e.jsx("p",{children:l("terminal:database.selectDbAndRun")})]}):e.jsx(je,{buildingId:a.id,history:f,onLoadQuery:ne})})]})]})]})};export{ge as DatabasePanel,fe as DatabaseSidebar,ye as DatabaseTabs,pe as QueryEditor,je as QueryHistoryPanel,xe as ResultsTable};
|
|
1
|
+
import{u as J,a as Z,r,s as h,j as e,D as de,I as H,C as oe,b as me,c as be,d as ue,g as he,e as _e,Q as pe,R as xe}from"./main-vfMoYhg1.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-Chj50gSY.js";const fe=({building:a,connections:x,activeConnectionId:l,activeDatabase:c,collapsed:y,onToggleCollapse:f,onConnectionChange:Q,onDatabaseChange:S,onInsertTable:L,onSelectTableQuery:P})=>{const{t:m}=J(["terminal"]),q=Z(a.id),[I,R]=r.useState(new Set),[k,n]=r.useState(""),[d,g]=r.useState(""),[$,w]=r.useState(!1),[U,F]=r.useState(null),K=r.useRef(null),C=r.useRef(null),O=r.useRef(null),N=l?q.databases.get(l)??[]:[],G=l&&c?`${l}:${c}`:"",j=G?q.tables.get(G)??[]:[],p=l?q.connectionStatus.get(l):void 0,D=r.useMemo(()=>{if(!k.trim())return N;const t=k.toLowerCase();return N.filter(o=>o.toLowerCase().includes(t))},[N,k]),b=r.useMemo(()=>{if(!d.trim())return j;const t=d.toLowerCase();return j.filter(o=>o.name.toLowerCase().includes(t))},[j,d]);r.useEffect(()=>{const t=o=>{C.current&&!C.current.contains(o.target)&&w(!1)};return $&&document.addEventListener("mousedown",t),()=>document.removeEventListener("mousedown",t)},[$]),r.useEffect(()=>{l&&!p&&h.testDatabaseConnection(a.id,l)},[a.id,l,p]),r.useEffect(()=>{l&&(p!=null&&p.connected)&&N.length===0&&h.listDatabases(a.id,l)},[a.id,l,p==null?void 0:p.connected,N.length]),r.useEffect(()=>{l&&c&&j.length===0&&h.listTables(a.id,l,c)},[a.id,l,c,j.length]),r.useEffect(()=>{F(null),g("")},[l,c]);const _=r.useCallback(t=>{R(o=>{const T=new Set(o);if(T.has(t))T.delete(t);else if(T.add(t),l&&c){const v=`${l}:${c}:${t}`;q.tableSchemas.has(v)||h.getTableSchema(a.id,l,c,t)}return T})},[a.id,l,c,q.tableSchemas]),z=t=>{if(!l||!c)return null;const o=`${l}:${c}:${t}`;return q.tableSchemas.get(o)};return y?e.jsx("div",{className:"database-sidebar database-sidebar--collapsed",children:e.jsx("button",{className:"database-sidebar__toggle",onClick:f,title:m("terminal:database.expandSidebar"),children:"»"})}):e.jsxs("div",{className:"database-sidebar",children:[e.jsxs("div",{className:"database-sidebar__header",children:[e.jsx("span",{children:m("terminal:database.explorer")}),e.jsx("button",{className:"database-sidebar__toggle",onClick:f,title:m("terminal:database.collapseSidebar"),children:"«"})]}),e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:m("terminal:database.connection")}),e.jsx("select",{className:"database-sidebar__select",value:l||"",onChange:t=>Q(t.target.value),children:x.length===0?e.jsx("option",{value:"",children:m("terminal:database.noConnections")}):x.map(t=>{var o;return e.jsxs("option",{value:t.id,children:[((o=de[t.engine])==null?void 0:o.icon)??"🗄️"," ",t.name]},t.id)})}),p&&e.jsx("div",{className:`database-sidebar__status ${p.connected?"database-sidebar__status--connected":"database-sidebar__status--error"}`,children:p.connected?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✓"}),m("terminal:database.connected"),p.serverVersion&&e.jsxs("span",{className:"database-sidebar__version",children:["(",p.serverVersion,")"]})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"database-sidebar__status-icon",children:"✗"}),p.error||m("terminal:database.disconnected")]})})]}),N.length>0&&e.jsxs("div",{className:"database-sidebar__section",children:[e.jsx("div",{className:"database-sidebar__section-title",children:m("terminal:database.databaseTitle")}),e.jsxs("div",{className:"database-sidebar__searchable-select",ref:C,children:[e.jsx("input",{ref:K,className:"database-sidebar__search-input",type:"text",value:$?k:c||"",placeholder:m("terminal:database.selectDatabase"),onChange:t=>{n(t.target.value),$||w(!0)},onFocus:()=>{w(!0),n("")},onKeyDown:t=>{var o,T;t.key==="Escape"?(w(!1),n(""),(o=K.current)==null||o.blur()):t.key==="Enter"&&D.length===1&&(S(D[0]),w(!1),n(""),(T=K.current)==null||T.blur())}}),$&&e.jsx("div",{className:"database-sidebar__dropdown",children:D.length===0?e.jsx("div",{className:"database-sidebar__dropdown-empty",children:"No matches"}):D.map(t=>e.jsx("div",{className:`database-sidebar__dropdown-item ${t===c?"database-sidebar__dropdown-item--active":""}`,onMouseDown:o=>{o.preventDefault(),S(t),w(!1),n("")},children:t},t))})]})]}),j.length>0&&e.jsxs("div",{className:"database-sidebar__section database-sidebar__section--tables",children:[e.jsx("div",{className:"database-sidebar__section-title",children:d.trim()?m("terminal:database.tablesCount",{count:b.length})+` / ${j.length}`:m("terminal:database.tablesCount",{count:j.length})}),e.jsxs("div",{className:"database-sidebar__table-filter",children:[e.jsx("input",{ref:O,className:"database-sidebar__table-filter-input",type:"text",value:d,placeholder:m("terminal:database.filterTables"),onChange:t=>g(t.target.value),onKeyDown:t=>{var o;t.key==="Escape"&&(d?g(""):(o=O.current)==null||o.blur(),t.stopPropagation())}}),d&&e.jsx("button",{className:"database-sidebar__table-filter-clear",onClick:()=>{var t;g(""),(t=O.current)==null||t.focus()},title:"Clear filter",children:"×"})]}),e.jsxs("div",{className:"database-sidebar__tables",children:[d.trim()&&b.length===0&&e.jsx("div",{className:"database-sidebar__tables-empty",children:m("terminal:database.noTablesMatch")}),b.map(t=>{const o=I.has(t.name),T=o?z(t.name):null;return e.jsxs("div",{className:"database-sidebar__table",children:[e.jsxs("div",{className:"database-sidebar__table-header",children:[e.jsx("button",{className:"database-sidebar__table-expand",onClick:()=>_(t.name),title:o?"Collapse table schema":"Expand table schema",children:e.jsx(H,{name:o?"caret-down":"caret-right",size:10})}),e.jsx("span",{className:"database-sidebar__table-icon",children:e.jsx(H,{name:t.type==="view"?"eye":"clipboard",size:12})}),e.jsx("span",{className:`database-sidebar__table-name ${U===t.name?"database-sidebar__table-name--selected":""}`,onClick:()=>F(t.name),onDoubleClick:()=>{F(t.name),P(t.name)},children:t.name}),e.jsx("button",{className:"database-sidebar__table-insert",onClick:v=>{v.stopPropagation(),L(t.name)},title:m("terminal:database.insertTableName"),children:"+"})]}),o&&T&&e.jsx("div",{className:"database-sidebar__table-columns",children:T.columns.map(v=>e.jsxs("div",{className:"database-sidebar__column",onClick:()=>L(v.name),title:`${v.type}${v.nullable?" NULL":" NOT NULL"}${v.primaryKey?" PK":""}`,children:[e.jsx("span",{className:"database-sidebar__column-icon",children:v.primaryKey?e.jsx(H,{name:"key",size:11}):null}),e.jsx("span",{className:"database-sidebar__column-name",children:v.name}),e.jsx("span",{className:"database-sidebar__column-type",children:v.type})]},v.name))})]},t.name)})]})]})]})},je=({buildingId:a,history:x,onLoadQuery:l})=>{const{t:c}=J(["terminal","common"]),[y,f]=r.useState(""),[Q,S]=r.useState(!1),[L,P]=r.useState(!1),m=r.useMemo(()=>{let n=x;if(Q&&(n=n.filter(d=>d.favorite)),y.trim()){const d=y.toLowerCase();n=n.filter(g=>g.query.toLowerCase().includes(d)||g.database.toLowerCase().includes(d))}return n},[x,Q,y]),q=n=>{const d=new Date(n),$=new Date().getTime()-d.getTime();return $<1440*60*1e3?d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):$<10080*60*1e3?d.toLocaleDateString([],{weekday:"short"})+" "+d.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):d.toLocaleDateString([],{month:"short",day:"numeric"})},I=r.useCallback((n,d)=>{d.stopPropagation(),h.toggleQueryFavorite(a,n)},[a]),R=r.useCallback((n,d)=>{d.stopPropagation(),h.deleteQueryFromHistory(a,n)},[a]),k=r.useCallback(()=>{P(!0)},[]);return x.length===0?e.jsxs("div",{className:"query-history query-history--empty",children:[e.jsx("p",{children:c("terminal:database.noHistory")}),e.jsx("p",{children:c("terminal:database.queriesAppearHere")})]}):e.jsxs("div",{className:"query-history",children:[e.jsxs("div",{className:"query-history__toolbar",children:[e.jsx("input",{type:"text",className:"query-history__search",placeholder:c("terminal:database.searchQueries"),value:y,onChange:n=>f(n.target.value)}),e.jsxs("label",{className:"query-history__filter",children:[e.jsx("input",{type:"checkbox",checked:Q,onChange:n=>S(n.target.checked)}),c("terminal:database.favoritesOnly")]}),e.jsx("button",{className:"query-history__clear",onClick:k,title:c("terminal:database.clearAll"),children:c("terminal:database.clearAll")})]}),e.jsxs("div",{className:"query-history__list",children:[m.map(n=>e.jsxs("div",{className:`query-history__item ${n.status==="error"?"query-history__item--error":""}`,onClick:()=>l(n.query),children:[e.jsxs("div",{className:"query-history__item-header",children:[e.jsx("span",{className:`query-history__status ${n.status==="success"?"query-history__status--success":"query-history__status--error"}`,children:e.jsx(H,{name:n.status==="success"?"check":"cross",size:12})}),e.jsx("span",{className:"query-history__database",children:n.database}),e.jsx("span",{className:"query-history__date",children:q(n.executedAt)}),e.jsxs("span",{className:"query-history__duration",children:[n.duration,"ms"]}),n.rowCount!==void 0&&e.jsx("span",{className:"query-history__row-count",children:c("terminal:database.rowCount",{count:n.rowCount})})]}),e.jsx("div",{className:"query-history__query",children:e.jsx("code",{children:n.query.length>200?n.query.substring(0,200)+"...":n.query})}),n.error&&e.jsx("div",{className:"query-history__error",children:n.error}),e.jsxs("div",{className:"query-history__actions",children:[e.jsx("button",{className:`query-history__favorite ${n.favorite?"query-history__favorite--active":""}`,onClick:d=>I(n.id,d),title:n.favorite?c("terminal:database.removeFromFavorites"):c("terminal:database.addToFavorites"),children:e.jsx(H,{name:"star",size:12,weight:n.favorite?"fill":"regular",color:n.favorite?"#facc15":void 0})}),e.jsx("button",{className:"query-history__delete",onClick:d=>R(n.id,d),title:c("terminal:database.deleteFromHistory"),children:e.jsx(H,{name:"trash",size:12})})]})]},n.id)),m.length===0&&e.jsx("div",{className:"query-history__no-results",children:c("terminal:database.noQueriesMatch")})]}),e.jsx(oe,{isOpen:L,title:c("terminal:database.clearAll"),message:c("terminal:database.confirmClearHistory"),confirmLabel:c("terminal:database.clearAll"),cancelLabel:c("common:buttons.cancel"),variant:"danger",onConfirm:()=>h.clearQueryHistory(a),onClose:()=>P(!1)})]})},ye=({tabs:a,activeTabId:x,onTabClick:l,onTabClose:c})=>{const{t:y}=J(["terminal"]);return e.jsx("div",{className:"database-tabs",children:a.map(f=>e.jsxs("div",{className:`database-tabs__tab ${x===f.id?"database-tabs__tab--active":""}`,children:[e.jsxs("button",{className:"database-tabs__tab-label",onClick:()=>l(f),title:`${f.connectionName} / ${f.database}`,children:[f.database,e.jsx("span",{className:"database-tabs__tab-connection",children:f.connectionName})]}),e.jsx("button",{className:"database-tabs__tab-close",onClick:()=>c(f.id),title:y("terminal:database.closeTab"),"aria-label":`Close ${f.database} tab`,children:"×"})]},f.id))})},ee=a=>`db-panel-${a}`;function Ne(a){try{const x=localStorage.getItem(ee(a));return x?JSON.parse(x):{}}catch{return{}}}function ve(a,x){try{localStorage.setItem(ee(a),JSON.stringify(x))}catch{}}const ge=({building:a,onClose:x})=>{var B,W,Y,X;const{t:l}=J(["terminal","common"]),c=Z(a.id),y=me(a.id),f=be(a.id),Q=ue(a.id),S=r.useRef(Ne(a.id)),L=r.useRef(null),P=r.useRef(0),m=((B=a.database)==null?void 0:B.connections)??[],q=(s,i)=>`${s}:${i}`,I=s=>s?(S.current.queries??{})[s]??"":S.current.generalQuery??"",[R,k]=r.useState("results"),[n,d]=r.useState(0),[g,$]=r.useState(!1),[w,U]=r.useState(!1),[F,K]=r.useState(()=>(S.current.openTabs??[]).map(i=>{var u;return{id:`${i.connectionId}:${i.database}`,connectionId:i.connectionId,connectionName:((u=m.find(A=>A.id===i.connectionId))==null?void 0:u.name)??i.connectionId,database:i.database}})),[C,O]=r.useState(S.current.activeTabId??null),[N,G]=r.useState(()=>{const s=S.current.queries??{};return S.current.generalQuery,s}),[j,p]=r.useState(I(C)),D=r.useCallback(s=>{p(i=>{const u=typeof s=="function"?s(i):s;return G(A=>{const E={...A};return C&&(E[C]=u),E}),u})},[C]),b=c.activeConnectionId??S.current.connectionId??((W=a.database)==null?void 0:W.activeConnectionId)??((Y=m[0])==null?void 0:Y.id),_=c.activeDatabase??S.current.database??((X=a.database)==null?void 0:X.activeDatabase),z=m.find(s=>s.id===b),t=b&&_?`${b}:${_}`:"",o=t?c.tables.get(t)??[]:[],T=r.useMemo(()=>{const s=new Map;return!b||!_||o.forEach(i=>{const u=c.tableSchemas.get(`${b}:${_}:${i.name}`);u&&s.set(i.name,{columns:u.columns})}),s},[b,_,o,c.tableSchemas]),v=r.useCallback((s,i)=>{var E;const u=q(s,i),A=((E=m.find(M=>M.id===s))==null?void 0:E.name)??s;K(M=>{if(M.some(ie=>ie.id===u))return M;const ce={id:u,connectionId:s,connectionName:A,database:i};return[...M,ce]}),O(u),p(N[u]??""),h.setActiveConnection(a.id,s),h.setActiveDatabase(a.id,i)},[a.id,m,N]),ae=r.useCallback(s=>{K(i=>i.filter(u=>u.id!==s)),C===s&&K(i=>{if(i.length>0){const u=i[0];O(u.id),p(N[u.id]??""),h.setActiveConnection(a.id,u.connectionId),h.setActiveDatabase(a.id,u.database)}else O(null),p("");return i})},[C,a.id,N]),se=r.useCallback(s=>{O(s.id),p(N[s.id]??""),h.setActiveConnection(a.id,s.connectionId),h.setActiveDatabase(a.id,s.database)},[a.id,N]);r.useEffect(()=>{if(!w&&m.length>0){const s=S.current;s.connectionId&&m.some(i=>i.id===s.connectionId)&&(h.setActiveConnection(a.id,s.connectionId),h.listDatabases(a.id,s.connectionId),s.database&&(h.setActiveDatabase(a.id,s.database),h.listTables(a.id,s.connectionId,s.database))),U(!0)}},[a.id,m,w]),r.useEffect(()=>{h.requestQueryHistory(a.id)},[a.id]),r.useEffect(()=>{const s=i=>{i.key==="Escape"&&(i.preventDefault(),i.stopPropagation(),x())};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[x]),r.useEffect(()=>{w&&b&&ve(a.id,{connectionId:b,database:_,lastQuery:j,queries:N,generalQuery:"",openTabs:F.map(s=>({connectionId:s.connectionId,database:s.database})),activeTabId:C??void 0})},[a.id,b,_,j,w,F,C,N]);const te=r.useCallback(s=>{var i;if(!(!b||!_||!j.trim()||Q))if(s==="cursor"){const u=(i=L.current)==null?void 0:i.querySelector(".query-editor__textarea"),A=(u==null?void 0:u.selectionStart)??P.current,E=he(j,A);E&&h.executeQuery(a.id,b,_,E)}else{const u=_e(j);if(u.length<=1)h.executeQuery(a.id,b,_,j.trim());else{const A=b,E=_;(async()=>{for(const M of u)await h.executeQueryAndWait(a.id,A,E,M.sql)})()}}},[a.id,b,_,j,Q]),ne=r.useCallback(s=>{D(s),k("results")},[]),re=r.useCallback(s=>{h.setActiveConnection(a.id,s),h.listDatabases(a.id,s)},[a.id]),le=r.useCallback(s=>{b&&(v(b,s),h.listTables(a.id,b,s))},[a.id,b,v]),V=y[n];return m.length===0?e.jsxs("div",{className:"database-panel",ref:L,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:e.jsx(H,{name:"database",size:16})}),e.jsx("span",{className:"database-panel__name",children:a.name})]}),e.jsx("button",{className:"database-panel__close",onClick:x,children:"×"})]}),e.jsx("div",{className:"database-panel__body",children:e.jsxs("div",{className:"database-panel__no-connections",children:[e.jsx("div",{className:"database-panel__no-connections-icon",children:e.jsx(H,{name:"plug",size:32})}),e.jsx("h3",{children:l("terminal:database.noConnections")}),e.jsx("p",{children:l("terminal:database.noConnectionsDesc")}),e.jsx("p",{children:l("terminal:database.toGetStarted")}),e.jsxs("ol",{children:[e.jsx("li",{children:l("terminal:database.step1Close")}),e.jsx("li",{children:l("terminal:database.step2Settings")}),e.jsx("li",{children:l("terminal:database.step3AddConnection")}),e.jsx("li",{children:l("terminal:database.step4Reopen")})]})]})})]}):e.jsxs("div",{className:"database-panel",ref:L,children:[e.jsxs("div",{className:"database-panel__header",children:[e.jsxs("div",{className:"database-panel__title",children:[e.jsx("span",{className:"database-panel__icon",children:(z==null?void 0:z.engine)==="mysql"?"🐬":"🐘"}),e.jsx("span",{className:"database-panel__name",children:a.name}),z&&e.jsxs("span",{className:"database-panel__connection-info",children:[z.name," / ",_||l("terminal:database.noDatabaseSelected")]})]}),e.jsx("button",{className:"database-panel__close",onClick:x,children:"×"})]}),e.jsxs("div",{className:"database-panel__body",children:[e.jsx(fe,{building:a,connections:m,activeConnectionId:b,activeDatabase:_,collapsed:g,onToggleCollapse:()=>$(!g),onConnectionChange:re,onDatabaseChange:le,onInsertTable:s=>D(i=>i+` ${s}`),onSelectTableQuery:s=>{const i=`SELECT * FROM ${s}`;D(i),b&&_&&h.executeQuery(a.id,b,_,i)}}),e.jsxs("div",{className:"database-panel__main",children:[F.length>0&&e.jsx(ye,{tabs:F,activeTabId:C,onTabClick:se,onTabClose:ae}),e.jsx(pe,{query:j,onChange:D,onExecute:te,isExecuting:Q,disabled:!b||!_,tables:o,tableSchemas:T,onRequestTableSchema:s=>{b&&_&&h.getTableSchema(a.id,b,_,s)}}),e.jsxs("div",{className:"database-panel__tabs",children:[e.jsxs("button",{className:`database-panel__tab ${R==="results"?"database-panel__tab--active":""}`,onClick:()=>k("results"),children:[l("terminal:database.results"),y.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:y.length})]}),e.jsxs("button",{className:`database-panel__tab ${R==="history"?"database-panel__tab--active":""}`,onClick:()=>k("history"),children:[l("terminal:database.history"),f.length>0&&e.jsx("span",{className:"database-panel__tab-badge",children:f.length})]}),R==="results"&&y.length>1&&e.jsxs("div",{className:"database-panel__result-nav",children:[e.jsxs("button",{disabled:n>=y.length-1,onClick:()=>d(s=>s+1),children:["← ",l("terminal:database.older")]}),e.jsxs("span",{children:[n+1," / ",y.length]}),e.jsxs("button",{disabled:n<=0,onClick:()=>d(s=>s-1),children:[l("terminal:database.newer")," →"]})]})]}),e.jsx("div",{className:"database-panel__tab-content",children:R==="results"?V?e.jsx(xe,{result:V,buildingId:a.id,building:a}):e.jsxs("div",{className:"database-panel__empty",children:[e.jsx("p",{children:l("terminal:database.noResultsYet")}),e.jsx("p",{children:l("terminal:database.selectDbAndRun")})]}):e.jsx(je,{buildingId:a.id,history:f,onLoadQuery:ne})})]})]})]})};export{ge as DatabasePanel,fe as DatabaseSidebar,ye as DatabaseTabs,pe as QueryEditor,je as QueryHistoryPanel,xe as ResultsTable};
|