tmex-cli 0.12.4 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -6
- package/dist/runtime/server.js +1639 -102
- package/package.json +1 -1
- package/resources/fe-dist/assets/DevicePage-Cj9jwadE.js +19 -0
- package/resources/fe-dist/assets/DevicesPage-BbypaGC7.js +1 -0
- package/resources/fe-dist/assets/{FilePage-D1t8_zlX.js → FilePage-CbHZVJbn.js} +3 -4
- package/resources/fe-dist/assets/SettingsPage-CCV0NSQF.js +39 -0
- package/resources/fe-dist/assets/agent-tab-DPwxh08T.js +38 -0
- package/resources/fe-dist/assets/api-DlcFE5in.js +10 -0
- package/resources/fe-dist/assets/{arc-Cv0H1Phu.js → arc-Bzmm6y8F.js} +1 -2
- package/resources/fe-dist/assets/{architectureDiagram-3BPJPVTR-DG7npZeK.js → architectureDiagram-3BPJPVTR-BdsN6XRe.js} +1 -2
- package/resources/fe-dist/assets/{blockDiagram-GPEHLZMM-weB7PKUK.js → blockDiagram-GPEHLZMM-CXdQhkqo.js} +1 -2
- package/resources/fe-dist/assets/{c4Diagram-AAUBKEIU-C0sEabtp.js → c4Diagram-AAUBKEIU-CE_W2_pV.js} +1 -2
- package/resources/fe-dist/assets/{card-Spfb5xRZ.js → card-B_sl9KIo.js} +1 -2
- package/resources/fe-dist/assets/channel-CuapxAWT.js +1 -0
- package/resources/fe-dist/assets/{chunk-2J33WTMH-BxOp2sIC.js → chunk-2J33WTMH-BAdEIJQO.js} +1 -2
- package/resources/fe-dist/assets/{chunk-4BX2VUAB-bhg4hxVT.js → chunk-4BX2VUAB-BZ0yj21c.js} +1 -2
- package/resources/fe-dist/assets/{chunk-55IACEB6-v6jayOak.js → chunk-55IACEB6-BknLtkSo.js} +1 -2
- package/resources/fe-dist/assets/{chunk-727SXJPM-IY0KVws8.js → chunk-727SXJPM-CxVON9n5.js} +1 -2
- package/resources/fe-dist/assets/{chunk-AQP2D5EJ-CgwymoWa.js → chunk-AQP2D5EJ-CLqOK2pR.js} +1 -2
- package/resources/fe-dist/assets/{chunk-FMBD7UC4-DN35690f.js → chunk-FMBD7UC4-Dt5Vot-R.js} +1 -2
- package/resources/fe-dist/assets/{chunk-ND2GUHAM-lJmtxdhS.js → chunk-ND2GUHAM-t9HYlb8C.js} +1 -2
- package/resources/fe-dist/assets/{chunk-QZHKN3VN-DFeaB8rn.js → chunk-QZHKN3VN-DZReNtLB.js} +1 -2
- package/resources/fe-dist/assets/classDiagram-4FO5ZUOK-C0k136Ud.js +1 -0
- package/resources/fe-dist/assets/classDiagram-v2-Q7XG4LA2-C0k136Ud.js +1 -0
- package/resources/fe-dist/assets/copy-Z9Fsj1r-.js +6 -0
- package/resources/fe-dist/assets/{cose-bilkent-S5V4N54A-Dw2yYQz4.js → cose-bilkent-S5V4N54A-BCTtGF2n.js} +1 -2
- package/resources/fe-dist/assets/cytoscape.esm-DTSO7Bv0.js +0 -1
- package/resources/fe-dist/assets/{dagre-BM42HDAG-BeMjJ7ln.js → dagre-BM42HDAG-BQ48EqSj.js} +1 -2
- package/resources/fe-dist/assets/defaultLocale-DX6XiGOO.js +0 -1
- package/resources/fe-dist/assets/{diagram-2AECGRRQ-Dur8_CuN.js → diagram-2AECGRRQ-BXjt2moR.js} +1 -2
- package/resources/fe-dist/assets/{diagram-5GNKFQAL-GJc7gVa_.js → diagram-5GNKFQAL-B2bvNTQO.js} +1 -2
- package/resources/fe-dist/assets/{diagram-KO2AKTUF-pxckXfjw.js → diagram-KO2AKTUF-DLHWfbBH.js} +1 -2
- package/resources/fe-dist/assets/{diagram-LMA3HP47-B9E8-X7C.js → diagram-LMA3HP47-BCFT3Bur.js} +1 -2
- package/resources/fe-dist/assets/{diagram-OG6HWLK6-DrhHw5wy.js → diagram-OG6HWLK6-bNZtxUJ2.js} +1 -2
- package/resources/fe-dist/assets/en_US-B07wSHDj.js +1 -0
- package/resources/fe-dist/assets/{erDiagram-TEJ5UH35-DY9Wg1A1.js → erDiagram-TEJ5UH35-KoAzrx4j.js} +1 -2
- package/resources/fe-dist/assets/files-tab-DdBDTjfs.js +70 -0
- package/resources/fe-dist/assets/{flowDiagram-I6XJVG4X-eq3WE9d6.js → flowDiagram-I6XJVG4X-C6wGExWt.js} +1 -2
- package/resources/fe-dist/assets/{ganttDiagram-6RSMTGT7-BlXISXe1.js → ganttDiagram-6RSMTGT7-BIWybjes.js} +1 -2
- package/resources/fe-dist/assets/{gitGraphDiagram-PVQCEYII-Bg-xHeIY.js → gitGraphDiagram-PVQCEYII-CD6tz24l.js} +1 -2
- package/resources/fe-dist/assets/graph-CAnANduQ.js +0 -1
- package/resources/fe-dist/assets/index-CUCrFB_J.js +29 -0
- package/resources/fe-dist/assets/index-CwH-l50P.js +299 -0
- package/resources/fe-dist/assets/index-D-q7dOhH.css +1 -0
- package/resources/fe-dist/assets/{infoDiagram-5YYISTIA-CW2drAHG.js → infoDiagram-5YYISTIA-CrI-qlYw.js} +1 -2
- package/resources/fe-dist/assets/init-Gi6I4Gst.js +0 -1
- package/resources/fe-dist/assets/{ishikawaDiagram-YF4QCWOH-Qchz0nqR.js → ishikawaDiagram-YF4QCWOH-D9v5anxN.js} +1 -2
- package/resources/fe-dist/assets/ja_JP-DjF6Lrmx.js +1 -0
- package/resources/fe-dist/assets/{journeyDiagram-JHISSGLW-Dk-UsexE.js → journeyDiagram-JHISSGLW-BH38CiJ0.js} +1 -2
- package/resources/fe-dist/assets/{kanban-definition-UN3LZRKU-DKeGp7b5.js → kanban-definition-UN3LZRKU-CKZ3_oXD.js} +1 -2
- package/resources/fe-dist/assets/layout-DGIYPm2g.js +0 -1
- package/resources/fe-dist/assets/{linear-Bt4f_qDW.js → linear-C_oE01xA.js} +1 -2
- package/resources/fe-dist/assets/{markdown-preview-DXv9GzaA.js → markdown-preview-BtNbNwlP.js} +6 -7
- package/resources/fe-dist/assets/{mermaid.core-B-wSkmMd.js → mermaid.core-4dbvlhht.js} +5 -6
- package/resources/fe-dist/assets/{mindmap-definition-RKZ34NQL-DXBwCMXu.js → mindmap-definition-RKZ34NQL-C5o4mnnX.js} +1 -2
- package/resources/fe-dist/assets/ordinal-BENe2yWM.js +0 -1
- package/resources/fe-dist/assets/{pieDiagram-4H26LBE5--KxRgbWG.js → pieDiagram-4H26LBE5-2ss3HotB.js} +1 -2
- package/resources/fe-dist/assets/{quadrantDiagram-W4KKPZXB-DqXsCI9E.js → quadrantDiagram-W4KKPZXB-Bolcfx55.js} +1 -2
- package/resources/fe-dist/assets/{requirementDiagram-4Y6WPE33-C2KeTWqB.js → requirementDiagram-4Y6WPE33-B-atSHRR.js} +1 -2
- package/resources/fe-dist/assets/{sankeyDiagram-5OEKKPKP-CC5tcr7d.js → sankeyDiagram-5OEKKPKP-ByynRcAV.js} +1 -2
- package/resources/fe-dist/assets/selection-clipboard-Dq6Zemfd.js +1 -0
- package/resources/fe-dist/assets/send-D0P5wgcD.js +11 -0
- package/resources/fe-dist/assets/{sequenceDiagram-3UESZ5HK-CqlMDtOG.js → sequenceDiagram-3UESZ5HK-CNC9IxV4.js} +1 -2
- package/resources/fe-dist/assets/{stateDiagram-AJRCARHV-CVcrlBiw.js → stateDiagram-AJRCARHV-CqzYDImp.js} +1 -2
- package/resources/fe-dist/assets/stateDiagram-v2-BHNVJYJU-C3azxyWE.js +1 -0
- package/resources/fe-dist/assets/{terminal-settings-panel-CYV9svzz.js → terminal-settings-panel-cjw9P_wY.js} +6 -7
- package/resources/fe-dist/assets/{timeline-definition-PNZ67QCA-CEBskfkL.js → timeline-definition-PNZ67QCA-C38KIECs.js} +1 -2
- package/resources/fe-dist/assets/transfer-toast-5tb-zYhi.js +6 -0
- package/resources/fe-dist/assets/triangle-alert-CQzql6mY.js +6 -0
- package/resources/fe-dist/assets/{vennDiagram-CIIHVFJN-CrxyVTtu.js → vennDiagram-CIIHVFJN-BJudKfzJ.js} +1 -2
- package/resources/fe-dist/assets/{wardley-L42UT6IY-CSmsRb8z.js → wardley-L42UT6IY-B6p_luMy.js} +1 -2
- package/resources/fe-dist/assets/{wardleyDiagram-YWT4CUSO-DoDzNeOA.js → wardleyDiagram-YWT4CUSO-DZJeOiWQ.js} +1 -2
- package/resources/fe-dist/assets/{xychartDiagram-2RQKCTM6-Dbq_OKsv.js → xychartDiagram-2RQKCTM6-DOMCute2.js} +1 -2
- package/resources/fe-dist/assets/zap-DWNtdoic.js +6 -0
- package/resources/fe-dist/assets/zh_CN-D10j4J8Y.js +1 -0
- package/resources/fe-dist/index.html +2 -2
- package/resources/gateway-drizzle/0010_lucky_kabuki.sql +32 -0
- package/resources/gateway-drizzle/meta/_journal.json +7 -0
- package/resources/fe-dist/assets/DevicePage-C4JS6baR.js +0 -15
- package/resources/fe-dist/assets/DevicesPage-p0CfWP1T.js +0 -2
- package/resources/fe-dist/assets/SettingsPage-Cq6n8Xjc.js +0 -27
- package/resources/fe-dist/assets/channel-DDiDKfY0.js +0 -2
- package/resources/fe-dist/assets/classDiagram-4FO5ZUOK-CXFjdzka.js +0 -2
- package/resources/fe-dist/assets/classDiagram-v2-Q7XG4LA2-CXFjdzka.js +0 -2
- package/resources/fe-dist/assets/index-CXIj7HZi.css +0 -1
- package/resources/fe-dist/assets/index-CYmVLCAD.js +0 -488
- package/resources/fe-dist/assets/stateDiagram-v2-BHNVJYJU-B0BDuZBM.js +0 -2
package/package.json
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import{Y as Fe,u as je,j as o,$ as tt,a0 as nt,a1 as rt,a2 as st,a3 as ot,a4 as it,r,d as H,a5 as J,a6 as Xe,a7 as Ke,a8 as ct,a9 as at,aa as lt,ab as Oe,o as xe,ac as ut,ad as Be,ae as dt,b as Ge,af as We,ag as ft,c as $e,ah as Ve,ai as Ee,aj as mt,ak as ht,al as ze,y as wt,am as pt,B as me,T as xt,an as vt,ao as gt,ap as St,aq as bt,A as Et,f as Rt,g as Tt,i as yt,k as jt,l as It,m as Ct,n as Nt}from"./index-CwH-l50P.js";import{T as kt,C as Mt,c as Pt,F as At,a as Qe,R as Lt,A as _t,f as zt,t as Dt,S as Ft}from"./terminal-settings-panel-cjw9P_wY.js";import{w as Bt}from"./selection-clipboard-Dq6Zemfd.js";import{C as Wt}from"./copy-Z9Fsj1r-.js";import{S as qe,K as $t}from"./send-D0P5wgcD.js";/**
|
|
2
|
+
* @license lucide-react v0.564.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const Ht=[["path",{d:"m13.5 8.5-5 5",key:"1cs55j"}],["path",{d:"m8.5 8.5 5 5",key:"a8mexj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]],Ot=Fe("search-x",Ht);/**
|
|
7
|
+
* @license lucide-react v0.564.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const qt=[["path",{d:"M14 17H5",key:"gfn3mx"}],["path",{d:"M19 7h-9",key:"6i9tg"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]],Ut=Fe("settings-2",qt);/**
|
|
12
|
+
* @license lucide-react v0.564.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const Yt=[["rect",{width:"14",height:"20",x:"5",y:"2",rx:"2",ry:"2",key:"1yt0o3"}],["path",{d:"M12 18h.01",key:"mhygvu"}]],Xt=Fe("smartphone",Yt);function Kt({open:n,onOpenChange:e}){const{t:i}=je();return o.jsx(tt,{open:n,onOpenChange:e,children:o.jsxs(nt,{side:"bottom",className:"max-h-[88dvh] overflow-y-auto pb-[var(--tmex-safe-area-bottom)] sm:mx-auto sm:max-w-md sm:rounded-t-2xl sm:border sm:border-b-0","data-testid":"keyboard-behavior-sheet",children:[o.jsxs(rt,{children:[o.jsx(st,{children:i("settings.terminal.title")}),o.jsx(ot,{children:i("settings.terminal.savedInBrowser")})]}),o.jsx("div",{className:"px-4 pb-4",children:o.jsx(kt,{})})]})})}function Gt({visible:n,canPaste:e,onCopy:i,onPaste:a,onDismiss:w}){const{t:y}=je();if(!n)return null;const k=v=>{v.preventDefault()};return o.jsxs("div",{className:"absolute top-2 left-1/2 z-20 flex -translate-x-1/2 items-center gap-1 rounded-lg border bg-background/95 p-1 shadow-md backdrop-blur","data-testid":"terminal-selection-toolbar",children:[o.jsxs("button",{type:"button",className:"flex h-9 items-center gap-1.5 rounded-md px-3 text-sm font-medium hover:bg-accent hover:text-accent-foreground",onMouseDown:k,onClick:i,"data-testid":"terminal-selection-copy",children:[o.jsx(Wt,{className:"h-4 w-4"}),y("terminal.copy")]}),e&&o.jsxs("button",{type:"button",className:"flex h-9 items-center gap-1.5 rounded-md px-3 text-sm font-medium hover:bg-accent hover:text-accent-foreground",onMouseDown:k,onClick:a,"data-testid":"terminal-selection-paste",children:[o.jsx(Mt,{className:"h-4 w-4"}),y("terminal.paste")]}),o.jsx("button",{type:"button",className:"flex h-9 w-9 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground",onMouseDown:k,onClick:w,"aria-label":y("terminal.clearSelection"),"data-testid":"terminal-selection-dismiss",children:o.jsx(it,{className:"h-4 w-4"})})]})}function Je(n){if(!n)return n;const e=n.replace(/\r\n/g,`
|
|
17
|
+
`);return(e.endsWith(`
|
|
18
|
+
`)?e.slice(0,-1):e).replace(/\n/g,`\r
|
|
19
|
+
`)}const Vt="\x1B[?1049h\x1B[H\x1B[2J";function Qt(n){return Vt+Je(n)}function Ue(n,e){let i=e,a=0;for(const v of n)v===10&&!i&&(a+=1),i=v===13;const w=i;if(a===0)return{normalized:n,endedWithCR:w};const y=new Uint8Array(n.length+a);let k=0;i=e;for(const v of n)v===10&&!i&&(y[k]=13,k+=1),y[k]=v,k+=1,i=v===13;return{normalized:y,endedWithCR:w}}const Jt=1.3,Zt=36,en=500,tn=12;function nn(n,e){const i=r.useRef(!1);return r.useEffect(()=>{const a=n.current;if(!a||!(window.innerWidth<768||navigator.maxTouchPoints>0||"ontouchstart"in window))return;i.current=!0;let y=0,k=null,v=!1,R=0,X=0,s=0,C=null,L=!1;const K=()=>{C!==null&&(clearTimeout(C),C=null)},W=m=>m?!!(m.closest(".scrollbar")||m.closest(".slider")||m.closest(".xterm-scroll-area")):!1,b=(m,h,g)=>{const N=g instanceof Element?g:null;if(W(N))return!0;const O=document.elementFromPoint(m,h);if(W(O))return!0;const x=a.querySelector(".xterm");if(!(x instanceof HTMLElement))return!1;const S=x.getBoundingClientRect(),P=m>=S.left&&m<=S.right,T=h>=S.top&&h<=S.bottom;return!P||!T?!1:m>=S.right-Zt},Z=()=>[a.querySelector(".xterm-viewport"),a.querySelector(".xterm-scrollable-element")].filter(h=>h instanceof HTMLElement),ee=m=>{if(k===null)return null;for(let h=0;h<m.length;h+=1){const g=m.item(h);if(g&&g.identifier===k)return g}return null},te=m=>{if(K(),m.touches.length!==1)return;const h=m.touches.item(0);h&&(k=h.identifier,y=h.clientY,R=0,v=b(h.clientX,h.clientY,m.target),X=h.clientX,s=h.clientY,L=!1,v||(C=setTimeout(()=>{var N;C=null;const g=(e==null?void 0:e())??null;(N=g==null?void 0:g.startTouchSelection)!=null&&N.call(g,X,s,"word")&&(L=!0)},en)))},q=m=>{var P,T,j,D,V,$,le,Q,oe;const h=ee(m.touches)??m.touches.item(0);if(!h)return;if(L){const _=(e==null?void 0:e())??null;(P=_==null?void 0:_.updateTouchSelection)==null||P.call(_,h.clientX,h.clientY),m.cancelable&&m.preventDefault();return}if(C!==null&&Math.hypot(h.clientX-X,h.clientY-s)>tn&&K(),v||(v=b(h.clientX,h.clientY,m.target),v&&(R=0)),v)return;const g=h.clientY,N=y-g;if(y=g,N===0)return;let O=!1,x=!1;const S=(e==null?void 0:e())??null;if(S){const _=S==null?void 0:S._core,p=((V=(D=(j=(T=_==null?void 0:_._renderService)==null?void 0:T.dimensions)==null?void 0:j.css)==null?void 0:D.cell)==null?void 0:V.height)??18;R+=N*Jt;const F=R>0?Math.floor(R/p):Math.ceil(R/p);if(typeof S.handleViewportGesture=="function")F!==0&&(O=S.handleViewportGesture({source:"touch",deltaY:F*p,clientX:h.clientX,clientY:h.clientY}),R-=F*p);else if(F!==0){const B=((le=($=S.buffer)==null?void 0:$.active)==null?void 0:le.viewportY)??0;S.scrollLines(F);const ne=((oe=(Q=S.buffer)==null?void 0:Q.active)==null?void 0:oe.viewportY)??0;O=B!==ne,x=F<0&&B<=0&&ne<=0,R-=F*p}}else{const _=Z();if(_.length===0)return;for(const p of _){const F=p.scrollTop;p.scrollTop+=N;const B=p.scrollTop;Math.abs(B-F)>0&&(O=!0),N<0&&B<=0&&(x=!0)}if(!O){const p=a.querySelector(".xterm");if(p instanceof HTMLElement){const F=new WheelEvent("wheel",{bubbles:!0,cancelable:!0,deltaMode:WheelEvent.DOM_DELTA_PIXEL,deltaY:N}),B=p.dispatchEvent(F);O=F.defaultPrevented||!B}}}m.cancelable&&(O||x)&&m.preventDefault()},c=m=>{var g;if(K(),!(k===null||!ee(m.changedTouches))&&(k=null,R=0,v=!1,L)){L=!1;const N=(e==null?void 0:e())??null;(g=N==null?void 0:N.endTouchSelection)==null||g.call(N)}},A=m=>{L&&m.preventDefault()};return a.addEventListener("touchstart",te,{passive:!0}),a.addEventListener("touchmove",q,{passive:!1}),a.addEventListener("touchend",c,{passive:!0}),a.addEventListener("touchcancel",c,{passive:!0}),a.addEventListener("contextmenu",A),()=>{i.current=!1,K(),a.removeEventListener("touchstart",te),a.removeEventListener("touchmove",q),a.removeEventListener("touchend",c),a.removeEventListener("touchcancel",c),a.removeEventListener("contextmenu",A)}},[n,e]),i}function rn({now:n,remoteSize:e,pendingLocalSize:i,ttlMs:a=2e3}){return!i||n-i.at>a?!0:i.cols===e.cols&&i.rows===e.rows}function sn({currentSize:n,containerSize:e,force:i=!1}){return i?!0:n.cols!==e.cols||n.rows!==e.rows}function on({deviceId:n,paneId:e,deviceConnected:i,isSelectionInvalid:a,onResize:w,onSync:y,getContainerRect:k}){const v=r.useRef(null),R=r.useRef(null),X=r.useRef(null),s=r.useRef(null),C=r.useRef(0),L=r.useRef([]),K=r.useRef(null),W=r.useRef(null),b=r.useRef(k),Z=r.useRef(!1),ee=r.useRef(w),te=r.useRef(y);r.useEffect(()=>{ee.current=w},[w]),r.useEffect(()=>{te.current=y},[y]),r.useEffect(()=>{b.current=k},[k]);const q=r.useCallback(()=>{var $,le,Q,oe,_,p,F,B,ne,re;const x=W.current,S=K.current;if(!x||!S||!x.element)return null;let P;try{const U=S.proposeDimensions();if(!U)throw new Error("fitAddon.proposeDimensions() returned null");P=Math.max(2,U.cols)}catch{const U=x._core,ve=((oe=(Q=(le=($=U==null?void 0:U._renderService)==null?void 0:$.dimensions)==null?void 0:le.css)==null?void 0:Q.cell)==null?void 0:oe.width)??9,l=(_=b.current)==null?void 0:_.call(b);if(!l||l.width===0)return null;P=Math.max(2,Math.floor(l.width/ve))}const T=(p=b.current)==null?void 0:p.call(b);if(!T||T.height===0)return null;const j=x._core,D=((re=(ne=(B=(F=j==null?void 0:j._renderService)==null?void 0:F.dimensions)==null?void 0:B.css)==null?void 0:ne.cell)==null?void 0:re.height)??17,V=Math.max(2,Math.floor(T.height/D));return{cols:P,rows:V}},[]),c=r.useCallback((x,S)=>{const P=W.current;P&&(P.cols===x&&P.rows===S||P.resize(x,S))},[]),A=r.useCallback((x,S=!1)=>{if(!n||!e||!i||a&&x!=="sync"||!S&&Date.now()<C.current||!W.current)return!1;const T=q();if(!T)return!1;const{cols:j,rows:D}=T,V=X.current;return!S&&V&&V.cols===j&&V.rows===D?(c(j,D),!0):(c(j,D),x==="sync"?te.current(j,D):ee.current(j,D),X.current={cols:j,rows:D},s.current={cols:j,rows:D,at:Date.now()},!0)},[c,i,n,a,q,e]),m=r.useCallback((x="resize",S={})=>{const{immediate:P=!1,force:T=!1}=S;R.current!==null&&(window.clearTimeout(R.current),R.current=null),v.current!==null&&(cancelAnimationFrame(v.current),v.current=null);const j=()=>{v.current=requestAnimationFrame(()=>{v.current=null,A(x,T)})};if(P){j();return}R.current=window.setTimeout(()=>{R.current=null,j()},150)},[A]),h=r.useCallback(()=>{for(const x of L.current)window.clearTimeout(x);L.current=[]},[]),g=r.useCallback(()=>{var S;h(),m("sync",{immediate:!0,force:!0});const x=window.setTimeout(()=>{m("sync",{immediate:!0,force:!0})},60);L.current.push(x),typeof document<"u"&&"fonts"in document&&((S=document.fonts)!=null&&S.ready)&&document.fonts.ready.then(()=>{m("sync",{immediate:!0,force:!0})}).catch(()=>{})},[h,m]);r.useEffect(()=>{let x=null;const S=()=>{x!==null&&cancelAnimationFrame(x),x=requestAnimationFrame(()=>{x=null,m("resize")})};return window.addEventListener("resize",S),()=>{window.removeEventListener("resize",S),x!==null&&cancelAnimationFrame(x)}},[m]),r.useEffect(()=>{const x=()=>{var $;const j=W.current,D=q();if(!j||!D)return;if(!sn({currentSize:{cols:Math.max(2,j.cols),rows:Math.max(2,j.rows)},containerSize:D})){($=j.refresh)==null||$.call(j);return}m("sync",{force:!0})},S=()=>{if(document.visibilityState!=="visible"){Z.current=!0;return}Z.current&&(Z.current=!1,x())},P=()=>{Z.current=!0},T=()=>{Z.current&&(Z.current=!1,x())};return document.addEventListener("visibilitychange",S),window.addEventListener("blur",P),window.addEventListener("focus",T),()=>{document.removeEventListener("visibilitychange",S),window.removeEventListener("blur",P),window.removeEventListener("focus",T)}},[q,m]),r.useEffect(()=>()=>{h(),R.current!==null&&window.clearTimeout(R.current),v.current!==null&&cancelAnimationFrame(v.current)},[h]);const N=r.useCallback(x=>{K.current=x},[]),O=r.useCallback(x=>{W.current=x},[]);return{scheduleResize:m,runPostSelectResize:g,clearPostSelectResizeTimers:h,setFitAddon:N,setTerminal:O,lastReportedSize:X,pendingLocalSize:s,suppressLocalResizeUntil:C}}const cn=1e4,De="tmex:terminal-mode-cache";function an(n,e){try{const i=sessionStorage.getItem(De);return i?JSON.parse(i)[`${n}:${e}`]??null:null}catch{return null}}function ln(n,e,i){try{const a=sessionStorage.getItem(De),w=a?JSON.parse(a):{},y=`${n}:${e}`;i?w[y]=i:delete w[y],sessionStorage.setItem(De,JSON.stringify(w))}catch{}}function un(){return{mouseX10:!1,mouseNormal:!0,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!1}}function dn(n,e){if(!e)return n?{...n,mouseX10:!1,mouseNormal:!1,mouseButton:!1,mouseAny:!1,mouseUtf8:!1,mouseSgrPixels:!1,mouseUrxvt:!1,altScreen1047:!1,altScreen1049:!1}:null;const i=un();if(!n)return i;const a=n.mouseNormal||n.mouseButton||n.mouseAny;return{...n,mouseX10:!1,mouseUtf8:!1,mouseSgr:!0,mouseSgrPixels:!1,mouseUrxvt:!1,altScroll:!0,altScreen1047:!1,altScreen1049:!1,mouseNormal:a?n.mouseNormal:i.mouseNormal}}function fn(n){var i;const e=globalThis;e.__tmexE2eXterm=n,e.__tmexE2eTerminal=n,e.__tmexE2eTerminalEngine=Qe,e.__tmexE2eTerminalRenderer=((i=n.getRendererKind)==null?void 0:i.call(n))??null}function mn(n){if(!n)return;const e=globalThis;e.__tmexE2eTerminal!==n&&e.__tmexE2eXterm!==n||(e.__tmexE2eXterm=null,e.__tmexE2eTerminal=null,e.__tmexE2eTerminalEngine=null,e.__tmexE2eTerminalRenderer=null,e.__tmexE2eTerminalSelectionText=null)}const Ze=r.forwardRef(({deviceId:n,paneId:e,theme:i,inputMode:a,deviceConnected:w,isSelectionInvalid:y,onResize:k,onSync:v,children:R},X)=>{const[s,C]=r.useState(null),[L,K]=r.useState(!1),W=H(l=>l.sendInput),b=J(l=>l.terminalFontId),Z=J(l=>l.terminalFontSize),ee=J(l=>l.terminalLineHeight),{t:te}=je(),q=r.useMemo(()=>{switch(i){case"light":return Ke;default:return Xe}},[i]),c=r.useRef(null),A=r.useRef(null),m=r.useRef(null),h=r.useRef(n),g=r.useRef(e),N=r.useRef(n),O=r.useRef(e),x=r.useRef(w&&!y),S=r.useRef(a),P=r.useRef(q),T=r.useRef(!1),j=r.useRef(!1),D=r.useRef(null),V=r.useRef(!1),$=r.useCallback((l,f,I)=>{!(l!=null&&l.exportModeSnapshot)||!f||!I||ln(f,I,l.exportModeSnapshot())},[]),le=r.useCallback(()=>s,[s]);nn(c,le),r.useEffect(()=>{h.current=n,g.current=e,j.current=!1},[n,e]),r.useEffect(()=>{x.current=w&&!y},[w,y]),r.useEffect(()=>{S.current=a},[a]),r.useEffect(()=>{P.current=q},[q]);const Q=r.useCallback(l=>{if(!l||a!=="direct"||!x.current)return;const f=h.current,I=g.current;!f||!I||W(f,I,l,!1)},[a,W]),{pendingLocalSize:oe,scheduleResize:_,runPostSelectResize:p,setFitAddon:F,setTerminal:B}=on({deviceId:n,paneId:e,deviceConnected:w,isSelectionInvalid:y,onResize:k,onSync:v,getContainerRect:()=>{const l=c.current;if(!l)return null;const f=l.getBoundingClientRect();return{width:f.width,height:f.height}}});r.useEffect(()=>{let l=!1,f=null;return(async()=>{if(await ct(b,Z),l)return;const I=await Pt({fontFamily:at(b),fontSize:Z,lineHeight:ee,scrollback:cn,theme:P.current,disableStdin:S.current==="editor"});if(l){I.dispose();return}f=I,A.current&&I.open(A.current),fn(I),C(I)})(),()=>{l=!0,C(null),mn(f),f==null||f.dispose()}},[b,Z,ee]),r.useEffect(()=>{!s||!("setTheme"in s)||s.setTheme(q)},[s,q]),r.useEffect(()=>{!s||!("setDisableStdin"in s)||s.setDisableStdin(a==="editor")},[s,a]),r.useEffect(()=>{if(!(s!=null&&s.getCursorViewportRect))return;const l=()=>{var f;return((f=s.getCursorViewportRect)==null?void 0:f.call(s))??null};return ut(l),()=>lt(l)},[s]),r.useEffect(()=>{!s||a!=="direct"||window.innerWidth<768||"ontouchstart"in window||s.focus()},[s,a]);const ne=r.useMemo(()=>s?{onResetTerminal:l=>{h.current===l&&($(s,N.current,O.current),V.current=!0,s.reset(),T.current=!1,p())},onApplyHistory:(l,f,I)=>{var ie;if(h.current!==l)return;const z=dn(an(h.current,g.current),I);z&&((ie=s.restoreModeSnapshot)==null||ie.call(s,z));const M=I?Qt(f):Je(f);j.current=!0,s.write(M),V.current=!1,N.current=h.current,O.current=g.current,$(s,h.current,g.current)},onFlushBuffer:(l,f)=>{if(h.current===l){for(const I of f){const z=Ue(I,T.current);T.current=z.endedWithCR,s.write(z.normalized)}j.current&&(s.buffer.active.baseY<=1&&s.scrollToTop(),j.current=!1),N.current=h.current,O.current=g.current,$(s,h.current,g.current)}},onOutput:(l,f,I)=>{if(h.current!==l||g.current!==f)return;const z=Ue(I,T.current);T.current=z.endedWithCR,s.write(z.normalized),j.current&&(s.buffer.active.baseY<=1&&s.scrollToTop(),j.current=!1),N.current=h.current,O.current=g.current,$(s,h.current,g.current)}}:{},[s,$,p]);r.useEffect(()=>{s?D.current!==s&&(T.current=!1,N.current=h.current,O.current=g.current,D.current=s):D.current=null},[s]),r.useEffect(()=>{if(!(!s||!n||!e))return()=>{if(V.current){V.current=!1;return}$(s,N.current,O.current)}},[n,s,e,$]),r.useEffect(()=>{Oe(ne)},[ne]),r.useEffect(()=>()=>{Oe({})},[]),r.useEffect(()=>{if(!s){m.current=null,F(null),B(null);return}const l=new At;return s.loadAddon(l),m.current=l,F(l),B(s),p(),()=>{try{l.dispose()}finally{m.current=null,F(null),B(null)}}},[s,p,F,B]),r.useEffect(()=>{const l=c.current;if(!l)return;let f=null;const I=new ResizeObserver(()=>{f!==null&&cancelAnimationFrame(f),f=requestAnimationFrame(()=>{f=null,_("resize")})});return I.observe(l),()=>{I.disconnect(),f!==null&&cancelAnimationFrame(f)}},[_]),r.useEffect(()=>{if(!s||!n||!e)return;const l=s.onData(f=>{!w||y||Q(f)});return s.attachCustomKeyEventHandler(f=>!w||y||f.type!=="keydown"||a!=="direct"?!0:f.shiftKey&&f.key==="Enter"?(f.preventDefault(),Q("\x1B[13;2u"),!1):!0),()=>{l.dispose(),s.attachCustomKeyEventHandler(()=>!0)}},[s,w,y,a,Q,n,e]),r.useEffect(()=>{if(!(s!=null&&s.onLinkActivated))return;const l=s.onLinkActivated(f=>{window.open(f,"_blank","noopener,noreferrer")});return()=>l.dispose()},[s]),r.useEffect(()=>{if(!(s!=null&&s.onSelectionChange)){K(!1);return}const l=s.onSelectionChange(f=>{K(!!f)});return()=>{l.dispose(),K(!1)}},[s]);const re=r.useCallback(()=>{var f;if(!s)return;const l=((f=s.getSelection)==null?void 0:f.call(s))??"";l&&Bt(l).then(()=>{xe.success(te("terminal.copied"))}).catch(()=>{xe.error(te("terminal.copyFailed"))}).finally(()=>{var I;(I=s.clearSelection)==null||I.call(s),s.focus()})},[s,te]),U=r.useCallback(()=>{var f;if(!s)return;((f=navigator.clipboard)!=null&&f.readText?navigator.clipboard.readText():Promise.reject(new Error("clipboard unavailable"))).then(I=>{var z;I&&s.paste(I),(z=s.clearSelection)==null||z.call(s),s.focus()}).catch(()=>{xe.error(te("terminal.pasteFailed"))})},[s,te]),ve=r.useCallback(()=>{var l;(l=s==null?void 0:s.clearSelection)==null||l.call(s),s==null||s.focus()},[s]);return r.useImperativeHandle(X,()=>({write:l=>s==null?void 0:s.write(l),reset:()=>{s==null||s.reset(),T.current=!1},scrollToBottom:()=>s==null?void 0:s.scrollToBottom(),resize:(l,f)=>s==null?void 0:s.resize(l,f),getTerminal:()=>s??null,getSize:()=>s?{cols:Math.max(2,s.cols),rows:Math.max(2,s.rows)}:null,runPostSelectResize:()=>p(),scheduleResize:(l,f)=>_(l,f),calculateSizeFromContainer:()=>{var Ie,ce,ge,ue,ae,G,Se,de,be,Re,Te,Ce,Ne,ke,Me,Pe;const l=c.current,f=s,I=m.current;if(!l||!f)return null;const z=l.getBoundingClientRect();if(z.width===0||z.height===0)return null;const M=f._core;let ie;if(I)try{const fe=I.proposeDimensions();if(fe)ie=Math.max(2,fe.cols);else{const Ae=((ue=(ge=(ce=(Ie=M==null?void 0:M._renderService)==null?void 0:Ie.dimensions)==null?void 0:ce.css)==null?void 0:ge.cell)==null?void 0:ue.width)??9;ie=Math.max(2,Math.floor(z.width/Ae))}}catch{const fe=((de=(Se=(G=(ae=M==null?void 0:M._renderService)==null?void 0:ae.dimensions)==null?void 0:G.css)==null?void 0:Se.cell)==null?void 0:de.width)??9;ie=Math.max(2,Math.floor(z.width/fe))}else{const fe=((Ce=(Te=(Re=(be=M==null?void 0:M._renderService)==null?void 0:be.dimensions)==null?void 0:Re.css)==null?void 0:Te.cell)==null?void 0:Ce.width)??9;ie=Math.max(2,Math.floor(z.width/fe))}const we=((Pe=(Me=(ke=(Ne=M==null?void 0:M._renderService)==null?void 0:Ne.dimensions)==null?void 0:ke.css)==null?void 0:Me.cell)==null?void 0:Pe.height)??17,Le=Math.max(2,Math.floor(z.height/we));return{cols:ie,rows:Le}},getPendingLocalSize:()=>oe.current}),[s,oe,p,_]),o.jsxs("div",{className:"flex h-full w-full flex-col",style:{backgroundColor:q.background},"data-terminal-engine":Qe,children:[o.jsxs("div",{ref:c,className:"relative min-h-0 w-full flex-1",children:[o.jsx("div",{ref:A,className:"absolute inset-0"}),o.jsx(Gt,{visible:L,canPaste:a==="direct"&&w&&!y,onCopy:re,onPaste:U,onDismiss:ve})]}),R]})});Ze.displayName="Terminal";const hn=1200,wn=2e3;function he(n,e){return!n||!e?!1:n.windowId===e.windowId&&n.paneId===e.paneId}function et(n,e){const i=n.filter(a=>e-a.at<hn);return i.length===0?null:i.reduce((a,w)=>w.at>a.at?w:a)}function ye(n,e=Date.now()){return!n||e-n.at>wn?null:n}function pn(n){const e=n.now??Date.now(),i=et(n.recentSelectRequests,e);if(i&&!he(i,n.activePaneFromEvent)||he(n.currentRoute,n.activePaneFromEvent)||he(n.lastHandledActive,n.activePaneFromEvent))return!0;const a=ye(n.pendingUserSelection,e);return!!(a&&!he(a,n.activePaneFromEvent))}function xn(n){const e=n.now??Date.now(),i=et(n.recentSelectRequests,e),a=ye(n.pendingUserSelection,e);return!!(a&&!he(a,n.snapshotActive)||i&&!he(i,n.snapshotActive))}function vn(n){const e=n.now??Date.now(),i=ye(n.pendingUserSelection,e);return!(i&&he(i,n.routeTarget)||n.snapshotActive&&he(n.snapshotActive,n.routeTarget))}const Ye=r.memo(function({onActivate:e,disabled:i}){const{data:a}=$e({queryKey:Dt,queryFn:zt,staleTime:6e4}),w=(a==null?void 0:a.items)??[];return w.length===0?null:o.jsx("div",{className:"terminal-shortcuts-strip","data-testid":"terminal-shortcuts-strip",children:o.jsx(Ft,{items:w,useIcons:(a==null?void 0:a.useIcons)??!1,onActivate:e,disabled:i,preventFocusSteal:!0,rowTestId:"terminal-shortcuts-row",idPrefix:"terminal-shortcut"})})});function Tn(){var He;const{t:n}=je(),{deviceId:e,windowId:i,paneId:a}=Be(),w=dt(),y=r.useRef(null),k=r.useRef(null),v=r.useRef(null),R=r.useRef(null),X=r.useRef(!1),s=r.useRef(!1),C=r.useRef(null),L=H(t=>t.selectPane),K=H(t=>e?t.snapshots[e]:void 0),W=H(t=>{var u;return e?(u=t.deviceErrors)==null?void 0:u[e]:void 0}),b=H(t=>{var u;return e?((u=t.deviceConnected)==null?void 0:u[e])??!1:!1}),ee=!!H(t=>{var u;return e?(u=t.deviceReconnecting)==null?void 0:u[e]:void 0}),te=H(t=>e?t.connectedDevices.has(e):!1),q=Ge(t=>{var u;return((u=t.settings)==null?void 0:u.siteName)??"tmex"}),c=r.useMemo(()=>We(a),[a]),A=r.useMemo(()=>e&&c?`${e}:${c}`:null,[e,c]),[m,h]=r.useState(!1),[g,N]=r.useState(""),O=r.useRef(!1),x=!b||!c,[S,P]=r.useState(!1),T=J(t=>t.inputMode),j=J(t=>t.theme),D=J(t=>t.editorSendWithEnter),V=J(t=>t.setEditorSendWithEnter),$=J(t=>t.addEditorHistory),le=J(t=>t.setEditorDraft),Q=J(t=>t.removeEditorDraft),oe=J(t=>A?t.editorDrafts[A]??"":""),_=r.useMemo(()=>ft(),[]),p=(He=K==null?void 0:K.session)==null?void 0:He.windows,F=j==="light"?Ke:Xe,{data:B}=$e({queryKey:["devices"],queryFn:async()=>{const t=await fetch("/api/devices");if(!t.ok)throw new Error("Failed to fetch devices");return t.json()},throwOnError:!1}),ne=r.useMemo(()=>{if(e)return B==null?void 0:B.devices.find(t=>t.id===e)},[e,B==null?void 0:B.devices]),re=r.useMemo(()=>{if(!(!i||!p))return p.find(t=>t.id===i)},[i,p]),U=r.useMemo(()=>{if(!(!c||!re))return re.panes.find(t=>t.id===c)},[c,re]),ve=!!p,I=ve&&!!i&&!re?n("terminal.windowClosed"):ve&&!!i&&!!c&&!!re&&!U?n("terminal.paneClosed"):null,z=!!I,M=!!(b&&c&&!z),ie=r.useMemo(()=>{if(!re||!U)return null;const t=(ne==null?void 0:ne.name)??e;return Ve({paneIdx:U.index,windowIdx:re.index,paneTitle:U.title,windowName:re.name,windowCustomName:re.customName,deviceName:t})},[ne==null?void 0:ne.name,e,U,re]),we=r.useMemo(()=>{if(!p||p.length===0)return null;const t=p.find(d=>d.active),u=t==null?void 0:t.panes.find(d=>d.active);return!t||!u?null:{windowId:t.id,paneId:u.id}},[p]),Le=r.useCallback((t,u)=>{!e||!c||H.getState().resizePane(e,c,t,u)},[e,c]),Ie=r.useCallback((t,u)=>{!e||!c||H.getState().syncPaneSize(e,c,t,u)},[e,c]),ce=r.useCallback((t,u)=>{const d=R.current,E=(d==null?void 0:d.calculateSizeFromContainer())??(d==null?void 0:d.getSize())??void 0;if(E)return E;if(!t||!u||!p)return;const Y=p.find(pe=>pe.id===t),se=Y==null?void 0:Y.panes.find(pe=>pe.id===u);if(!(!se||se.width<=1||se.height<=1))return{cols:se.width,rows:se.height}},[p]);r.useEffect(()=>{const t=()=>{h(window.innerWidth<768||"ontouchstart"in window)};return t(),window.addEventListener("resize",t),()=>window.removeEventListener("resize",t)},[]),r.useEffect(()=>{if(!m||!_||s.current)return;s.current=!0;const t=()=>{window.scrollTo(0,1)},u=window.requestAnimationFrame(t),d=window.setTimeout(t,120),E=window.setTimeout(t,420);return()=>{window.cancelAnimationFrame(u),window.clearTimeout(d),window.clearTimeout(E)}},[_,m]),r.useEffect(()=>{e&&(X.current=!1,Se.current=null,de.current=null,C.current=null,ue.current=[])},[e]),r.useEffect(()=>{b||(X.current=!1)},[b]),r.useEffect(()=>{if(!e||!b||!i||!p)return;if(p.length===0){w("/devices",{replace:!0});return}const t=p.find(d=>d.id===i);if(!t)return;if(!c){const d=t.panes.find(E=>E.active)??t.panes[0];d&&w(`/devices/${e}/windows/${i}/panes/${Ee(d.id)}`,{replace:!0});return}if(!t.panes.find(d=>d.id===c)){const d=t.panes.find(E=>E.active)??t.panes[0];d&&w(`/devices/${e}/windows/${i}/panes/${Ee(d.id)}`,{replace:!0});return}},[e,b,p,i,c,w]),r.useEffect(()=>{if(!e||!b||!p||p.length===0||i&&c||X.current)return;const t=p.find(d=>d.active)??p[0],u=t.panes.find(d=>d.active)??t.panes[0];u&&(X.current=!0,w(`/devices/${e}/windows/${t.id}/panes/${Ee(u.id)}`,{replace:!0}))},[b,e,w,c,i,p]);const ge=r.useRef(null);r.useEffect(()=>{ge.current=null},[e,c]),r.useEffect(()=>{if(!e||!i||!c||x||!b)return;const t=`${e}:${i}:${c}`;if(ge.current===t)return;ge.current=t;const u=ce(i,c);ae(i,c),L(e,i,c,u)},[b,e,ce,x,c,L,i]),r.useEffect(()=>{if(!e||!b||!i||!c)return;const t={windowId:i,paneId:c};vn({routeTarget:t,snapshotActive:we,pendingUserSelection:C.current})&&(C.current={windowId:t.windowId,paneId:t.paneId,at:Date.now()})},[b,e,c,we,i]);const ue=r.useRef([]),ae=r.useCallback((t,u)=>{const d=Date.now(),E=[...ue.current.filter(Y=>d-Y.at<2e3),{windowId:t,paneId:u,at:d}];ue.current=E.slice(-8)},[]),G=H(t=>e?t.activePaneFromEvent[e]:void 0),Se=r.useRef(null);r.useEffect(()=>{if(!e||!b||!i||!c||!G)return;const t=Date.now(),u=ye(C.current,t);if(C.current=u,pn({now:t,pendingUserSelection:u,activePaneFromEvent:G,currentRoute:{windowId:i,paneId:c},recentSelectRequests:ue.current,lastHandledActive:Se.current}))return;Se.current={...G},u&&u.windowId===G.windowId&&u.paneId===G.paneId&&(C.current=null);const d=ce(G.windowId,G.paneId);ae(G.windowId,G.paneId),L(e,G.windowId,G.paneId,d),w(`/devices/${e}/windows/${G.windowId}/panes/${Ee(G.paneId)}`,{replace:!0})},[e,b,i,c,G,ae,ce,L,w]);const de=r.useRef(null);r.useEffect(()=>{if(!e||!b||!p||p.length===0)return;const t=ue.current,u=p.find(_e=>_e.active);if(!u)return;const d=u.panes.find(_e=>_e.active);if(!d)return;const E={windowId:u.id,paneId:d.id},Y=Date.now(),se=ye(C.current,Y);if(C.current=se,xn({now:Y,pendingUserSelection:se,snapshotActive:E,recentSelectRequests:t})||de.current&&de.current.windowId===E.windowId&&de.current.paneId===E.paneId||(de.current={...E},se&&se.windowId===E.windowId&&se.paneId===E.paneId&&(C.current=null),i===E.windowId&&c===E.paneId))return;const pe=ce(E.windowId,E.paneId);ae(E.windowId,E.paneId),L(e,E.windowId,E.paneId,pe),w(`/devices/${e}/windows/${E.windowId}/panes/${Ee(E.paneId)}`,{replace:!0})},[e,b,p,i,c,ae,ce,L,w]);const be=H(t=>e?t.pendingCreateWindowAt[e]:void 0);r.useEffect(()=>{if(!e||!b||!be)return;const t=5e3,u=Date.now()-be;if(u>t){H.getState().clearPendingCreateWindow(e);return}if(!we){const Y=window.setTimeout(()=>{H.getState().clearPendingCreateWindow(e)},t-u);return()=>window.clearTimeout(Y)}const d=we;if(i===d.windowId&&c===d.paneId){const Y=window.setTimeout(()=>{H.getState().clearPendingCreateWindow(e)},t-u);return()=>window.clearTimeout(Y)}C.current={windowId:d.windowId,paneId:d.paneId,at:Date.now()};const E=ce(d.windowId,d.paneId);ae(d.windowId,d.paneId),L(e,d.windowId,d.paneId,E),w(`/devices/${e}/windows/${d.windowId}/panes/${Ee(d.paneId)}`,{replace:!0}),H.getState().clearPendingCreateWindow(e)},[e,b,be,we,i,c,ae,ce,L,w]),r.useEffect(()=>{if(!M||!U||x)return;const t=R.current,u=t==null?void 0:t.getTerminal();if(!u)return;const d=Math.max(2,Math.floor(U.width||0)),E=Math.max(2,Math.floor(U.height||0));if(!d||!E)return;const Y=Date.now(),se={cols:d,rows:E},pe=(t==null?void 0:t.getPendingLocalSize())??null;rn({now:Y,remoteSize:se,pendingLocalSize:pe})&&(u.cols===d&&u.rows===E||u.resize(d,E))},[M,x,U]),r.useEffect(()=>{const t=window.requestAnimationFrame(()=>{var d;(d=R.current)==null||d.scrollToBottom()}),u=window.setTimeout(()=>{var d;(d=R.current)==null||d.scrollToBottom()},120);return()=>{window.cancelAnimationFrame(t),window.clearTimeout(u)}},[T]),r.useEffect(()=>{W!=null&&W.message&&xe.error(W.message)},[W==null?void 0:W.message]),r.useEffect(()=>(document.title=mt(ie),()=>{document.title=q}),[q,ie]),r.useEffect(()=>{const t=()=>{var u;(u=R.current)==null||u.scrollToBottom()};return window.addEventListener("tmex:jump-to-latest",t),()=>{window.removeEventListener("tmex:jump-to-latest",t)}},[]),r.useEffect(()=>{const t=u=>{const{deviceId:d,windowId:E,paneId:Y}=u.detail;d===e&&(C.current={windowId:E,paneId:Y,at:Date.now()})};return window.addEventListener("tmex:user-initiated-selection",t),()=>{window.removeEventListener("tmex:user-initiated-selection",t)}},[e]),r.useEffect(()=>{N(oe)},[oe]);const Re=r.useCallback(t=>{if(!e||!c||!M)return;H.getState().sendInput(e,c,t,!1)},[M,e,c]),Te=r.useCallback(t=>{var u,d;if(t.type==="action"){if(t.action==="toggleKeyboard"){J.getState().setInputMode(T==="direct"?"editor":"direct");return}if(t.action==="scrollToBottom"){(u=R.current)==null||u.scrollToBottom();return}}if(t.type==="send"){t.payload&&Re(t.payload);return}if(!(!e||!c||!M))switch(t.action){case"paste":{((d=navigator.clipboard)!=null&&d.readText?navigator.clipboard.readText():Promise.reject(new Error("clipboard unavailable"))).then(Y=>{Y&&H.getState().paste(e,c,Y)}).catch(()=>xe.error(n("terminal.pasteFailed")));break}case"newAgentSession":ht.getState().startDraft(e,c,null),J.getState().setSidebarCollapsed(!1),J.getState().setSidebarTab("agent");break}},[M,e,Re,T,c,n]),Ce=r.useCallback(()=>{if(!M){xe.error(n("wsError.checkGateway"));return}if(!e||!c||!g.trim())return;P(!0),window.setTimeout(()=>P(!1),150);const t=D?`${g}\r`:g;H.getState().sendInput(e,c,t,!1),$(g),A&&Q(A),N("")},[$,M,e,A,D,g,Q,c,n]),Ne=r.useCallback(()=>{if(!M){xe.error(n("wsError.checkGateway"));return}if(!e||!c||!g.trim())return;P(!0),window.setTimeout(()=>P(!1),150);const t=g.split(/\r?\n/),u=H.getState();for(const d of t)d.trim()&&u.sendInput(e,c,`${d}\r`,!1);$(g),A&&Q(A),N("")},[$,M,e,A,g,Q,c,n]),ke=r.useCallback(()=>{var t;(t=v.current)==null||t.focus({preventScroll:!0})},[]);if(!e)return o.jsx("div",{className:"flex h-full items-center justify-center p-4",children:o.jsx("div",{className:"rounded-lg border border-dashed border-border px-4 py-3 text-sm text-muted-foreground",children:n("device.noDevices")})});const Me=!!c&&!z&&(b||ee),Pe=b&&!!c&&!z&&!U,fe=te&&!b&&!W&&!ee,Ae=o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:o.jsx(ze,{className:"h-6 w-6 text-muted-foreground animate-spin"})}),o.jsx("h3",{className:"text-lg font-medium",children:n("terminal.connecting")})]});return o.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background","data-testid":"device-page",children:[o.jsx("div",{className:`flex-1 relative overflow-hidden min-h-0 min-w-0 ${m&&T==="editor"?"pb-1":""}`,children:o.jsxs("div",{className:"h-full px-3 py-1 min-h-0 min-w-0 w-full relative flex rounded-xl",style:{backgroundColor:F.background},children:[z?o.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-8 text-center",children:o.jsxs("div",{className:"max-w-sm space-y-4",children:[o.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:o.jsx(Ot,{className:"h-6 w-6 text-muted-foreground"})}),o.jsx("p",{className:"text-sm text-muted-foreground","data-testid":"terminal-selection-invalid",children:I})]})}):Me&&c?o.jsx("div",{ref:y,className:"flex-1 h-full min-h-0 w-full","data-virtual-keyboard-avoid":!0,children:o.jsx(Ze,{ref:R,deviceId:e,paneId:c,theme:j,inputMode:T,deviceConnected:b,isSelectionInvalid:z,onResize:Le,onSync:Ie,children:T==="direct"&&o.jsx("div",{className:"kb-floating-shortcuts",style:{backgroundColor:F.background},children:o.jsx(Ye,{onActivate:Te,disabled:!M})})},`${e}:${c}`)}):o.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-8 text-center",children:o.jsx("div",{className:"max-w-sm space-y-4",children:fe?Ae:!b&&!ee?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:o.jsx("span",{className:"text-2xl text-muted-foreground",children:"🔌"})}),o.jsx("h3",{className:"text-lg font-medium",children:n("device.disconnected")}),o.jsx("p",{className:"text-sm text-muted-foreground",children:n("device.connectToStart")})]}):i?Ae:o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:o.jsx("span",{className:"text-2xl text-muted-foreground",children:"📋"})}),o.jsx("h3",{className:"text-lg font-medium",children:n("window.noWindowSelected")}),o.jsx("p",{className:"text-sm text-muted-foreground",children:n("window.selectWindowToStart")})]})})}),ee&&o.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-2 z-10 flex justify-center","data-testid":"terminal-reconnecting-indicator",children:o.jsx(wt,{deviceId:e,className:"shadow-sm"})}),Pe&&o.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/85 backdrop-blur-sm","data-testid":"terminal-status-overlay",children:o.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border bg-card/90 px-4 py-3 shadow-sm",children:[o.jsx("div",{className:"h-7 w-7 rounded-full border-2 border-primary border-t-transparent animate-spin"}),o.jsx("span",{className:"text-xs text-muted-foreground","data-testid":"terminal-status-text",children:n("terminal.connecting")})]})})]})}),T==="editor"&&o.jsxs("div",{ref:k,"data-virtual-keyboard-avoid":!0,className:"editor-mode-input bg-card/85 backdrop-blur-sm",children:[m&&o.jsx(Ye,{onActivate:t=>{Te(t),t.type==="send"&&ke()},disabled:!M}),o.jsx("textarea",{ref:v,"data-testid":"editor-input",className:"min-h-[88px] max-h-[28vh] w-full resize-y rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground shadow-xs outline-none transition-colors focus:border-ring",value:g,onChange:t=>{const u=t.target.value;if(N(u),!!A){if(u){le(A,u);return}Q(A)}},placeholder:n("terminal.inputPlaceholder"),onCompositionStart:()=>{O.current=!0},onCompositionEnd:()=>{O.current=!1}}),o.jsx("div",{className:"actions mt-2",children:o.jsxs("div",{className:"send-row flex flex-wrap items-center justify-end gap-2","data-testid":"editor-send-row",children:[o.jsxs("div",{className:"send-with-enter-toggle mr-auto flex items-center gap-2 text-xs text-muted-foreground","data-testid":"editor-send-with-enter-toggle",children:[o.jsx(pt,{size:"sm",checked:D,onCheckedChange:t=>V(!!t)}),o.jsx("span",{children:n("terminal.editorSendWithEnter")})]}),o.jsxs(me,{variant:"outline",size:"sm","data-testid":"editor-clear",onMouseDown:t=>t.preventDefault(),onClick:()=>{var t;N(""),A&&Q(A),m&&T==="editor"&&((t=v.current)==null||t.focus({preventScroll:!0}))},title:n("terminal.clear"),children:[o.jsx(xt,{className:"h-4 w-4"}),n("terminal.clear")]}),o.jsxs(me,{variant:"secondary",size:"sm","data-testid":"editor-send-line-by-line",onMouseDown:t=>t.preventDefault(),onClick:()=>{var t;Ne(),m&&T==="editor"&&((t=v.current)==null||t.focus({preventScroll:!0}))},disabled:!M||S,children:[S?o.jsx(ze,{className:"h-4 w-4 animate-spin"}):o.jsx(qe,{className:"h-4 w-4"}),n("terminal.editorSendLineByLine")]}),o.jsxs(me,{variant:"default",size:"sm","data-testid":"editor-send",onMouseDown:t=>t.preventDefault(),onClick:()=>{var t;Ce(),m&&T==="editor"&&((t=v.current)==null||t.focus({preventScroll:!0}))},disabled:!M||S,children:[S?o.jsx(ze,{className:"h-4 w-4 animate-spin"}):o.jsx(qe,{className:"h-4 w-4"}),n("common.send")]})]})})]})]})}function yn(){const{deviceId:n,windowId:e,paneId:i}=Be(),a=i?We(i):void 0,w=H(s=>s.snapshots),y=Ge(s=>{var C;return((C=s.settings)==null?void 0:C.siteName)??"tmex"}),k=n?w[n]:void 0,v=r.useMemo(()=>{var s;if(!(!e||!((s=k==null?void 0:k.session)!=null&&s.windows)))return k.session.windows.find(C=>C.id===e)},[e,k]),R=r.useMemo(()=>{if(!(!a||!v))return v.panes.find(s=>s.id===a)},[a,v]),X=r.useMemo(()=>v&&R?Ve({paneIdx:R.index,windowIdx:v.index,paneTitle:R.title,windowName:v.name,windowCustomName:v.customName,deviceName:y}):n??"",[v,R,y,n]);return o.jsx(o.Fragment,{children:X})}function jn(){const{t:n}=je(),{deviceId:e,paneId:i}=Be(),a=i?We(i):void 0,w=J(c=>c.inputMode),y=J(c=>c.setInputMode),k=H(c=>{var A;return e?((A=c.deviceConnected)==null?void 0:A[e])??!1:!1}),[v,R]=r.useState(!1),[X,s]=r.useState(!1),[C,L]=r.useState(!1),K=!!(a&&k),b=($e({queryKey:gt(e??"",a??""),queryFn:()=>vt(e??"",a??""),enabled:!!(e&&a),throwOnError:!1}).data??[]).some(c=>c.enabled),Z=()=>{y(w==="direct"?"editor":"direct")},ee=()=>{window.dispatchEvent(new CustomEvent("tmex:jump-to-latest"))},te=()=>{R(!0)},q=()=>{window.location.reload()};return o.jsxs(o.Fragment,{children:[o.jsx(me,{variant:"ghost",size:"icon-sm",onClick:te,"aria-label":n("nav.refreshPage"),title:n("nav.refreshPage"),children:o.jsx(Lt,{className:"h-4 w-4"})}),o.jsx(me,{variant:"ghost",size:"icon-sm",onClick:Z,disabled:!K,"data-testid":"terminal-input-mode-toggle","aria-label":n(w==="direct"?"nav.switchToEditor":"nav.switchToDirect"),title:n(w==="direct"?"nav.switchToEditor":"nav.switchToDirect"),children:w==="direct"?o.jsx($t,{className:"h-4 w-4"}):o.jsx(Xt,{className:"h-4 w-4"})}),o.jsx(me,{variant:"ghost",size:"icon-sm",onClick:ee,disabled:!K,"aria-label":n("nav.jumpToLatest"),title:n("nav.jumpToLatest"),children:o.jsx(_t,{className:"h-4 w-4"})}),o.jsxs(me,{variant:"ghost",size:"icon-sm",className:"relative",onClick:()=>s(!0),disabled:!a,"data-testid":"watch-open-button","aria-label":n("watch.title"),title:n("watch.title"),children:[o.jsx(St,{className:"h-4 w-4"}),b&&o.jsx("span",{className:"absolute right-1 top-1 h-1.5 w-1.5 rounded-full bg-primary","data-testid":"watch-active-indicator"})]}),o.jsx(me,{variant:"ghost",size:"icon-sm",onClick:()=>L(!0),"data-testid":"keyboard-behavior-open-button","aria-label":n("settings.terminal.title"),title:n("settings.terminal.title"),children:o.jsx(Ut,{className:"h-4 w-4"})}),o.jsx(Kt,{open:C,onOpenChange:L}),e&&a&&o.jsx(bt,{open:X,onOpenChange:s,deviceId:e,paneId:a}),o.jsx(Et,{open:v,onOpenChange:R,children:o.jsxs(Rt,{children:[o.jsxs(Tt,{children:[o.jsx(yt,{children:n("nav.refreshPage")}),o.jsx(jt,{children:n("nav.refreshPageConfirm")})]}),o.jsxs(It,{children:[o.jsx(Ct,{onClick:()=>R(!1),children:n("common.cancel")}),o.jsx(Nt,{onClick:q,children:n("common.confirm")})]})]})})]})}export{jn as PageActions,yn as PageTitle,Tn as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as D,r as x,a as W,b as ae,c as ie,d as re,e as K,t as ne,j as e,M as _,B as C,P as X,A as oe,f as ce,g as de,h as le,T as Y,i as me,k as he,l as ue,m as pe,n as xe,G as ve,o as v,D as fe,p as ye,E as ge,q as je,s as A,v as we,w as Ne,x as Q,y as Ce,S as De,L as be,z as Se,C as Ee,F as Me,H as Pe,I as Ke,J as Re,K as f,N as z,O as V,Q as U,R as J,U as j,V as Ie,W as ke}from"./index-CwH-l50P.js";import{C as M,a as P,b as Ae,c as $e,d as Te}from"./card-B_sl9KIo.js";import{Z as Fe}from"./zap-DWNtdoic.js";function R(s){const o=s.trim();return o||void 0}function qe(s){return s?{name:s.name,type:s.type,host:s.host??"",port:s.port??22,username:s.username??"",sshConfigRef:s.sshConfigRef??"",session:s.session??"tmex",authMode:s.type==="local"?"auto":s.authMode,password:"",privateKey:"",privateKeyPassphrase:""}:{name:"",type:"local",host:"",port:22,username:"root",sshConfigRef:"",session:"tmex",authMode:"auto",password:"",privateKey:"",privateKeyPassphrase:""}}function Le(s){if(s.type==="local")return{name:s.name.trim(),type:"local",session:R(s.session)??"tmex",authMode:"auto"};const o={name:s.name.trim(),type:"ssh",host:s.host.trim(),port:s.port,username:s.username.trim(),session:R(s.session)??"tmex",authMode:s.authMode};return s.authMode==="configRef"&&(o.sshConfigRef=s.sshConfigRef.trim()),s.authMode==="password"&&(o.password=s.password),s.authMode==="key"&&(o.privateKey=s.privateKey,o.privateKeyPassphrase=s.privateKeyPassphrase||void 0),o}function He(s){if(s.type==="local")return{name:s.name.trim(),session:R(s.session)??"tmex",authMode:"auto"};const o={name:s.name.trim(),host:s.host.trim(),port:s.port,username:s.username.trim(),sshConfigRef:s.authMode==="configRef"?s.sshConfigRef.trim():"",session:R(s.session)??"tmex",authMode:s.authMode};return s.authMode==="password"&&s.password&&(o.password=s.password),s.authMode==="key"&&s.privateKey&&(o.privateKey=s.privateKey,o.privateKeyPassphrase=s.privateKeyPassphrase||void 0),o}function ee(s){return Number.isInteger(s)&&s>=1&&s<=65535}function Oe(s){return s.type!=="ssh"?null:s.host.trim()?ee(s.port)?s.username.trim()?s.authMode==="configRef"&&!s.sshConfigRef.trim()?"validation.sshConfigRequired":null:"validation.usernameRequired":"validation.portRequired":"validation.hostRequired"}async function G(s,o){try{return(await s.json()).error??o}catch{return o}}function Ue(){const{t:s}=D(),[o,m]=x.useState(!1),[t,y]=x.useState(null),[r,d]=x.useState(null),l=W(),u=ae(n=>{var p;return((p=n.settings)==null?void 0:p.language)??"en_US"});x.useEffect(()=>{const n=()=>m(!0);return window.addEventListener("tmex:open-add-device",n),()=>window.removeEventListener("tmex:open-add-device",n)},[]);const{data:c,isLoading:I,isError:w}=ie({queryKey:["devices"],queryFn:async()=>{const n=await fetch("/api/devices");if(!n.ok)throw new Error(s("device.loadFailed"));return n.json()},throwOnError:!1}),b=re(n=>n.hydrateDeviceErrors);x.useEffect(()=>{c!=null&&c.devices&&b(c.devices.map(n=>({deviceId:n.id,lastError:n.lastError??null,lastErrorType:n.lastErrorType??null})))},[c,b]);const S=K({mutationFn:async n=>{if(!(await fetch(`/api/devices/${n}`,{method:"DELETE"})).ok)throw new Error(s("device.deleteFailed"))},onSuccess:()=>{l.invalidateQueries({queryKey:["devices"]}),v.success(s("common.success"))},onError:n=>{v.error(n instanceof Error?n.message:s("common.error"))}}),E=x.useMemo(()=>[...(c==null?void 0:c.devices)??[]].sort((p,N)=>p.sortOrder-N.sortOrder||p.name.localeCompare(N.name,ne(u),{numeric:!0,sensitivity:"base"})),[c==null?void 0:c.devices,u]);return e.jsxs("div",{className:"mx-auto flex w-full max-w-6xl flex-col gap-3 p-3 pb-[calc(1rem+env(safe-area-inset-bottom))] sm:gap-4 sm:p-5","data-testid":"devices-page",children:[I?e.jsx(M,{children:e.jsx(P,{className:"py-16 text-center text-sm text-muted-foreground",children:s("common.loading")})}):w?e.jsx(M,{children:e.jsx(P,{className:"py-16 text-center text-sm text-destructive",children:s("device.loadFailed")})}):E.length===0?e.jsx(M,{children:e.jsxs(P,{className:"space-y-4 py-14 text-center",children:[e.jsx("div",{className:"mx-auto flex h-12 w-12 items-center justify-center rounded-xl border border-border bg-muted",children:e.jsx(_,{className:"h-6 w-6 text-muted-foreground"})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-lg font-medium",children:s("device.noDevices")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("device.addDevice")})]}),e.jsxs(C,{variant:"default","data-testid":"devices-add-empty",onClick:()=>m(!0),children:[e.jsx(X,{className:"h-4 w-4"}),s("device.addDevice")]})]})}):e.jsx("div",{className:"grid gap-3 lg:grid-cols-2",children:E.map(n=>e.jsx(Be,{device:n,onEdit:()=>y(n),onDelete:()=>d(n)},n.id))}),o&&e.jsx(Z,{mode:"create",onClose:()=>m(!1)}),t&&e.jsx(Z,{mode:"edit",device:t,onClose:()=>y(null)}),e.jsx(oe,{open:r!==null,onOpenChange:n=>!n&&d(null),children:e.jsxs(ce,{children:[e.jsxs(de,{children:[e.jsx(le,{className:"bg-destructive/10",children:e.jsx(Y,{className:"h-5 w-5 text-destructive"})}),e.jsx(me,{children:s("device.deleteConfirm")}),e.jsx(he,{children:s("device.deleteDescription",{name:(r==null?void 0:r.name)??""})})]}),e.jsxs(ue,{children:[e.jsx(pe,{children:s("common.cancel")}),e.jsx(xe,{variant:"destructive",disabled:!r||S.isPending,onClick:()=>{r&&(S.mutate(r.id),d(null))},children:s("common.delete")})]})]})})]})}function Be({device:s,onEdit:o,onDelete:m}){const{t}=D(),y=s.type==="local"?e.jsx(_,{className:"h-4 w-4"}):e.jsx(ve,{className:"h-4 w-4"}),r=s.type==="local"?t("device.typeLocal"):`${s.username??"-"}@${s.host??"-"}:${s.port??22}`,d=K({mutationFn:async()=>{const l=await fetch(`/api/devices/${s.id}/test-connection`,{method:"POST"});let u=null;try{u=await l.json()}catch{u=null}if(!l.ok){const c=u;throw new Error((c==null?void 0:c.error)??t("common.error"))}return u},onSuccess:l=>{v.success(l.message??t("common.success"))},onError:l=>{v.error(l instanceof Error?l.message:t("common.error"))}});return e.jsxs(M,{"data-testid":"device-card","data-device-id":s.id,"data-device-name":s.name,className:"overflow-hidden border-border/50",children:[e.jsxs(Ae,{className:"space-y-2 pb-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[e.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-border bg-muted text-muted-foreground",children:y}),e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsx($e,{className:"line-clamp-1 text-sm",title:s.name,children:s.name}),e.jsx(Te,{className:"line-clamp-1 text-xs",children:r})]})]}),e.jsx("div",{className:"flex shrink-0 items-center gap-1",children:e.jsxs(fe,{children:[e.jsx(ye,{render:e.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":`device-card-actions-${s.id}`,"aria-label":t("common.edit"),title:t("common.edit")}),children:e.jsx(ge,{className:"h-4 w-4"})}),e.jsxs(je,{align:"end",children:[e.jsxs(A,{"data-testid":`device-card-edit-${s.id}`,onClick:o,children:[e.jsx(we,{className:"h-4 w-4"}),t("common.edit")]}),s.type==="ssh"&&e.jsxs(A,{"data-testid":`device-card-test-${s.id}`,onClick:()=>d.mutate(),disabled:d.isPending,children:[e.jsx(Fe,{className:"h-4 w-4"}),t("common.test")]}),e.jsx(Ne,{}),e.jsxs(A,{"data-testid":`device-card-delete-${s.id}`,variant:"destructive",onClick:m,children:[e.jsx(Y,{className:"h-4 w-4"}),t("common.delete")]})]})]})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:s.type==="local"?t("device.typeLocal"):t("device.typeSSHBadge")}),s.session&&e.jsx(Q,{variant:"outline",className:"text-[11px] font-normal",children:s.session}),e.jsx(Ce,{deviceId:s.id})]})]}),e.jsxs(P,{className:"pt-0",children:[e.jsx(De,{className:"mb-2"}),e.jsx("div",{className:"flex items-center justify-end",children:e.jsx(be,{to:`/devices/${s.id}`,"data-testid":`device-card-connect-${s.id}`,className:Se({variant:"outline",size:"sm"}),children:t("device.connect")})})]})]})}function Z({mode:s,device:o,onClose:m}){const{t}=D(),y=W(),[r,d]=x.useState(qe(o)),[l,u]=x.useState(!1),[c,I]=x.useState(!1),w=s==="edit",b=r.type==="ssh",S=K({mutationFn:async a=>{const i=await fetch("/api/devices",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(await G(i,t("device.createFailed")));return i.json()},onSuccess:()=>{y.invalidateQueries({queryKey:["devices"]}),v.success(t("common.success")),m()},onError:a=>{v.error(a instanceof Error?a.message:t("common.error"))}}),E=K({mutationFn:async a=>{if(!o)throw new Error(t("apiError.deviceNotFound"));const i=await fetch(`/api/devices/${o.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)});if(!i.ok)throw new Error(await G(i,t("device.updateFailed")));return i.json()},onSuccess:()=>{y.invalidateQueries({queryKey:["devices"]}),v.success(t("common.success")),m()},onError:a=>{v.error(a instanceof Error?a.message:t("common.error"))}}),n=async a=>{a.preventDefault(),I(!0);const i=Oe(r);if(i){v.error(t(i));return}u(!0);try{s==="create"?await S.mutateAsync(Le(r)):await E.mutateAsync(He(r))}catch{}finally{u(!1)}},p=`${s}-device-name`,N=`${s}-device-type`,$=`${s}-device-host`,T=`${s}-device-port`,F=`${s}-device-username`,q=`${s}-device-session`,L=`${s}-device-auth-mode`,H=`${s}-device-password`,O=`${s}-device-private-key`,B=`${s}-device-private-key-passphrase`,se={local:t("device.typeLocal"),ssh:t("device.typeSSH")},te={password:t("device.authPassword"),key:t("device.authKey"),agent:t("device.authAgent"),configRef:t("device.authConfigRef")},k=a=>e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-wider text-muted-foreground",children:a}),h=(a,i,g)=>e.jsxs("label",{className:"block text-xs font-medium text-foreground",htmlFor:a,children:[i,g&&e.jsx("span",{className:"ml-0.5 text-destructive",children:"*"})]});return e.jsx(Ee,{open:!0,onOpenChange:a=>!a&&m(),children:e.jsxs(Me,{"data-testid":"device-dialog",className:"w-full max-w-2xl",children:[e.jsxs(Pe,{children:[e.jsx(Ke,{children:t(w?"device.editDevice":"device.addDevice")}),e.jsx(Re,{children:t(w?"device.editDeviceDescription":"device.addDeviceDescription")})]}),e.jsxs("form",{onSubmit:n,className:"space-y-4",children:[e.jsxs("div",{className:"-mr-2 max-h-[min(70dvh,720px)] space-y-5 overflow-y-auto pr-2",children:[e.jsxs("section",{className:"space-y-2.5",children:[k(t("device.sectionBasic")),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[h(p,t("device.name"),!0),e.jsx(f,{id:p,"data-testid":"device-name-input",type:"text",value:r.name,onChange:a=>d(i=>({...i,name:a.target.value})),placeholder:t("device.namePlaceholder"),required:!0})]}),e.jsxs("div",{className:"space-y-1.5",children:[h(N,t("device.type")),e.jsxs(z,{value:r.type,onValueChange:a=>{if(!a)return;const i=a;d(g=>({...g,type:i,authMode:i==="local"?"auto":g.authMode==="auto"?"agent":g.authMode}))},disabled:w,children:[e.jsx(V,{id:N,"data-testid":"device-type-select",className:"w-full",children:e.jsx(U,{placeholder:t("device.type"),children:a=>se[a]??""})}),e.jsxs(J,{children:[e.jsx(j,{value:"local",children:t("device.typeLocal")}),e.jsx(j,{value:"ssh",children:t("device.typeSSH")})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[h(q,t("device.session")),e.jsx(f,{id:q,"data-testid":"device-session-input",type:"text",value:r.session,onChange:a=>d(i=>({...i,session:a.target.value})),placeholder:t("device.sessionPlaceholder")})]})]})]}),b&&e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"space-y-2.5",children:[k(t("device.sectionConnection")),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[h($,t("device.host"),!0),e.jsx(f,{id:$,type:"text",value:r.host,onChange:a=>d(i=>({...i,host:a.target.value})),placeholder:t("device.hostPlaceholder"),"aria-invalid":c&&!r.host.trim()})]}),e.jsxs("div",{className:"space-y-1.5",children:[h(T,t("device.port"),!0),e.jsx(f,{id:T,type:"number",value:Number.isNaN(r.port)?"":r.port,onChange:a=>{const i=a.target.value;d(g=>({...g,port:i===""?Number.NaN:Number.parseInt(i,10)}))},min:1,max:65535,"aria-invalid":c&&!ee(r.port)})]}),e.jsxs("div",{className:"space-y-1.5 sm:col-span-2",children:[h(F,t("device.username"),!0),e.jsx(f,{id:F,type:"text",value:r.username,onChange:a=>d(i=>({...i,username:a.target.value})),placeholder:t("device.usernamePlaceholder"),"aria-invalid":c&&!r.username.trim()})]})]})]}),e.jsxs("section",{className:"space-y-2.5",children:[k(t("device.sectionAuth")),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[h(L,t("device.authMode")),e.jsxs(z,{value:r.authMode,onValueChange:a=>{a&&d(i=>({...i,authMode:a}))},children:[e.jsx(V,{id:L,"data-testid":"device-auth-mode-select",className:"w-full",children:e.jsx(U,{placeholder:t("device.authMode"),children:a=>te[a]??""})}),e.jsxs(J,{children:[e.jsx(j,{value:"password",children:t("device.authPassword")}),e.jsx(j,{value:"key",children:t("device.authKey")}),e.jsx(j,{value:"agent",children:t("device.authAgent")}),e.jsx(j,{value:"configRef",children:t("device.authConfigRef")})]})]})]}),r.authMode==="password"&&e.jsxs("div",{className:"space-y-1.5",children:[h(H,t("device.password")),e.jsx(f,{id:H,type:"password",value:r.password,onChange:a=>d(i=>({...i,password:a.target.value}))})]}),r.authMode==="key"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[h(O,t("device.privateKey")),e.jsx(Ie,{id:O,value:r.privateKey,onChange:a=>d(i=>({...i,privateKey:a.target.value})),className:"h-28 font-mono text-xs",placeholder:t("device.privateKeyPlaceholder")})]}),e.jsxs("div",{className:"space-y-1.5",children:[h(B,t("device.passphrase")),e.jsx(f,{id:B,type:"password",value:r.privateKeyPassphrase,onChange:a=>d(i=>({...i,privateKeyPassphrase:a.target.value}))})]})]}),r.authMode==="configRef"&&e.jsxs("div",{className:"space-y-1.5",children:[h(`${s}-device-ssh-config-ref`,t("device.authConfigRef"),!0),e.jsx(f,{id:`${s}-device-ssh-config-ref`,"data-testid":"device-ssh-config-ref-input",type:"text",value:r.sshConfigRef,onChange:a=>d(i=>({...i,sshConfigRef:a.target.value})),placeholder:t("device.sshConfigRefPlaceholder"),"aria-invalid":c&&!r.sshConfigRef.trim()}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:t("device.sshConfigRefHint")})]})]})]})]})]}),e.jsxs(ke,{children:[e.jsx(C,{type:"button",variant:"outline",onClick:m,children:t("common.cancel")}),e.jsx(C,{type:"submit",variant:"default","data-testid":"device-dialog-save",disabled:l,children:t(l?"common.saving":"common.save")})]})]})]})})}function Je(){const{t:s}=D();return e.jsx(e.Fragment,{children:s("sidebar.manageDevices")})}function Ge(){const{t:s}=D(),o=()=>{window.dispatchEvent(new CustomEvent("tmex:open-add-device"))};return e.jsx(C,{variant:"ghost",size:"icon-sm","data-testid":"devices-add",onClick:o,"aria-label":s("sidebar.addDevice"),title:s("sidebar.addDevice"),children:e.jsx(X,{className:"h-4 w-4"})})}export{Ge as PageActions,Je as PageTitle,Ue as default};
|