tmex-cli 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tmex-cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "tmex": "./bin/tmex.js",
@@ -1,4 +1,4 @@
1
- import{c as fi,bw as qn,bx as jn,by as Vn,r as w,bz as Ae,bA as Os,j as B,b as Ss,u as Fr,bB as ws,bC as Yn,bD as bs,d as Ve,e as Xn,bE as Dt,f as wi,B as _t}from"./index-CY8_MxKm.js";import{T as Gn,A as Jn,a as Zn,b as Qn,c as eo,d as to,e as io,f as so,g as ro}from"./useValueChanged-B_Zh3mEN.js";import{L as bi,S as no,a as Ns}from"./switch-e1eUCkao.js";/**
1
+ import{c as fi,bw as qn,bx as jn,by as Vn,r as w,bz as Ae,bA as Os,j as B,b as Ss,u as Fr,bB as ws,bC as Yn,bD as bs,d as Ve,e as Xn,bE as Dt,f as wi,B as _t}from"./index-35UZ83ei.js";import{T as Gn,A as Jn,a as Zn,b as Qn,c as eo,d as to,e as io,f as so,g as ro}from"./useValueChanged-ia5UgAxm.js";import{L as bi,S as no,a as Ns}from"./switch-MW4hLOq6.js";/**
2
2
  * @license lucide-react v0.564.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -263,5 +263,5 @@ WARNING: This link could potentially be dangerous`)){let i=window.open();if(i){t
263
263
  position: relative;
264
264
  }
265
265
  `;function s({options:n,addons:o,listeners:l}={}){const h=i.useRef(null),a=i.useRef(l),[d,c]=i.useState(null);return i.useEffect(()=>{a.current=l},[l]),i.useEffect(()=>{const _=new t.Terminal({fontFamily:"operator mono,SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace",fontSize:14,theme:{background:"#101420"},cursorStyle:"underline",cursorBlink:!1,...n});o==null||o.forEach(f=>_.loadAddon(f));const u=a.current;return u!=null&&u.onBinary&&_.onBinary(u.onBinary),u!=null&&u.onCursorMove&&_.onCursorMove(u.onCursorMove),u!=null&&u.onLineFeed&&_.onLineFeed(u.onLineFeed),u!=null&&u.onScroll&&_.onScroll(u.onScroll),u!=null&&u.onSelectionChange&&_.onSelectionChange(u.onSelectionChange),u!=null&&u.onRender&&_.onRender(u.onRender),u!=null&&u.onResize&&_.onResize(u.onResize),u!=null&&u.onTitleChange&&_.onTitleChange(u.onTitleChange),u!=null&&u.onKey&&_.onKey(u.onKey),u!=null&&u.onData&&_.onData(u.onData),u!=null&&u.customKeyEventHandler&&_.attachCustomKeyEventHandler(u.customKeyEventHandler),h.current&&(_.open(h.current),_.focus()),c(_),()=>{_.dispose(),c(null)}},[n,o]),{ref:h,instance:d}}function r({className:n="",options:o,addons:l,listeners:h,...a}){const{ref:d}=s({options:o,addons:l,listeners:h});return e.jsx("div",{className:n,ref:d,...a})}return Xt.XTerm=r,Xt.useXTerm=s,Xt}var Rh=Eh();const Tn={background:"#e1e1e1",foreground:"#616161",cursor:"#616161",selectionBackground:"rgba(97, 97, 97, 0.25)",black:"#171717",red:"#bf2172",green:"#009799",yellow:"#9a7200",blue:"#007299",magenta:"#9b1d72",cyan:"#007173",white:"#d9d9d9",brightBlack:"#4e4e4e",brightRed:"#e12672",brightGreen:"#00bddf",brightYellow:"#ffdd00",brightBlue:"#7299bc",brightMagenta:"#e17899",brightCyan:"#6fbcbd",brightWhite:"#f1f1f1"},Pn={background:"#262626",foreground:"#d0d0d0",cursor:"#c5c5c5",selectionBackground:"rgba(197, 197, 197, 0.25)",black:"#000000",red:"#ba3c3c",green:"#5d876d",yellow:"#d5a54e",blue:"#887c8d",magenta:"#cd6d6d",cyan:"#618484",white:"#cfcdc3",brightBlack:"#000000",brightRed:"#ea7171",brightGreen:"#7aab7a",brightYellow:"#d1d194",brightBlue:"#afa3b5",brightMagenta:"#e29f9f",brightCyan:"#a0aea3",brightWhite:"#d0d0d0"},Bh='"JetBrains Mono", "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", "Noto Sans Mono CJK SC", "Source Han Mono SC", "Sarasa Mono SC", "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", monospace';var Ii={exports:{}},Pr;function Dh(){return Pr||(Pr=1,(function(e,t){(function(i,s){e.exports=s()})(self,(()=>(()=>{var i={};return(()=>{var s=i;Object.defineProperty(s,"__esModule",{value:!0}),s.FitAddon=void 0,s.FitAddon=class{activate(r){this._terminal=r}dispose(){}fit(){const r=this.proposeDimensions();if(!r||!this._terminal||isNaN(r.cols)||isNaN(r.rows))return;const n=this._terminal._core;this._terminal.rows===r.rows&&this._terminal.cols===r.cols||(n._renderService.clear(),this._terminal.resize(r.cols,r.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;const r=this._terminal._core,n=r._renderService.dimensions;if(n.css.cell.width===0||n.css.cell.height===0)return;const o=this._terminal.options.scrollback===0?0:r.viewport.scrollBarWidth,l=window.getComputedStyle(this._terminal.element.parentElement),h=parseInt(l.getPropertyValue("height")),a=Math.max(0,parseInt(l.getPropertyValue("width"))),d=window.getComputedStyle(this._terminal.element),c=h-(parseInt(d.getPropertyValue("padding-top"))+parseInt(d.getPropertyValue("padding-bottom"))),_=a-(parseInt(d.getPropertyValue("padding-right"))+parseInt(d.getPropertyValue("padding-left")))-o;return{cols:Math.max(2,Math.floor(_/n.css.cell.width)),rows:Math.max(1,Math.floor(c/n.css.cell.height))}}}})(),i})()))})(Ii)),Ii.exports}var Mh=Dh();function Lh({deviceId:e,paneId:t,deviceConnected:i,isSelectionInvalid:s,onResize:r,onSync:n,getContainerRect:o}){const l=w.useRef(null),h=w.useRef(null),a=w.useRef(null),d=w.useRef(null),c=w.useRef(0),_=w.useRef([]),u=w.useRef(null),f=w.useRef(null),p=w.useRef(r),y=w.useRef(n);w.useEffect(()=>{p.current=r},[r]),w.useEffect(()=>{y.current=n},[n]);const v=w.useCallback((H,V=!1)=>{var M,x,j,G,le,Ee,J,ie;if(!e||!t||!i||s&&H!=="sync"||!V&&Date.now()<c.current)return!1;const I=f.current,$=u.current;if(!I||!$||!I.element)return!1;let F,C;try{$.fit(),F=Math.max(2,I.cols)}catch{const Z=I._core,ee=((G=(j=(x=(M=Z==null?void 0:Z._renderService)==null?void 0:M.dimensions)==null?void 0:x.css)==null?void 0:j.cell)==null?void 0:G.width)??9,Y=o==null?void 0:o();if(!Y||Y.width===0)return!1;F=Math.max(2,Math.floor(Y.width/ee))}const m=o==null?void 0:o();if(!m||m.height===0)return!1;const k=I._core,E=((ie=(J=(Ee=(le=k==null?void 0:k._renderService)==null?void 0:le.dimensions)==null?void 0:Ee.css)==null?void 0:J.cell)==null?void 0:ie.height)??17;C=Math.max(2,Math.floor(m.height/E));const R=a.current;return!V&&R&&R.cols===F&&R.rows===C||(H==="sync"?y.current(F,C):p.current(F,C),a.current={cols:F,rows:C},d.current={cols:F,rows:C,at:Date.now()}),!0},[e,t,i,s]),A=w.useCallback((H="resize",V={})=>{const{immediate:I=!1,force:$=!1}=V;h.current!==null&&(window.clearTimeout(h.current),h.current=null),l.current!==null&&(cancelAnimationFrame(l.current),l.current=null);const F=()=>{l.current=requestAnimationFrame(()=>{l.current=null,v(H,$)})};if(I){F();return}h.current=window.setTimeout(()=>{h.current=null,F()},150)},[v]),T=w.useCallback(()=>{_.current.forEach(H=>window.clearTimeout(H)),_.current=[]},[]),L=w.useCallback(()=>{var V;T(),A("sync",{immediate:!0,force:!0});const H=window.setTimeout(()=>{A("sync",{immediate:!0,force:!0})},60);_.current.push(H),typeof document<"u"&&"fonts"in document&&((V=document.fonts)!=null&&V.ready)&&document.fonts.ready.then(()=>{A("sync",{immediate:!0,force:!0})}).catch(()=>{})},[T,A]);w.useEffect(()=>{let H=null;const V=()=>{H!==null&&cancelAnimationFrame(H),H=requestAnimationFrame(()=>{H=null,A("resize")})};return window.addEventListener("resize",V),()=>{window.removeEventListener("resize",V),H!==null&&cancelAnimationFrame(H)}},[A]),w.useEffect(()=>{const H=()=>{document.visibilityState==="visible"&&A("sync",{force:!0})},V=()=>{A("sync",{force:!0})};return document.addEventListener("visibilitychange",H),window.addEventListener("focus",V),()=>{document.removeEventListener("visibilitychange",H),window.removeEventListener("focus",V)}},[A]),w.useEffect(()=>()=>{T(),h.current!==null&&window.clearTimeout(h.current),l.current!==null&&cancelAnimationFrame(l.current)},[T]);const O=w.useCallback(H=>{u.current=H},[]),W=w.useCallback(H=>{f.current=H},[]);return{scheduleResize:A,runPostSelectResize:L,clearPostSelectResizeTimers:T,setFitAddon:O,setTerminal:W,lastReportedSize:a,pendingLocalSize:d,suppressLocalResizeUntil:c}}function Th(e){return e&&e.replace(/\r?\n/g,`\r
266
- `)}function Ar(e,t){let i=t,s=0;for(const l of e)l===10&&!i&&(s+=1),i=l===13;const r=i;if(s===0)return{normalized:e,endedWithCR:r};const n=new Uint8Array(e.length+s);let o=0;i=t;for(const l of e)l===10&&!i&&(n[o]=13,o+=1),n[o]=l,o+=1,i=l===13;return{normalized:n,endedWithCR:r}}const Ph={fontFamily:Bh,fontSize:13,convertEol:!0,scrollSensitivity:2,smoothScrollDuration:120,letterSpacing:0,cursorBlink:!0,allowProposedApi:!0,scrollback:1e4},An=w.forwardRef(({deviceId:e,paneId:t,theme:i,inputMode:s,deviceConnected:r,isSelectionInvalid:n,onResize:o,onSync:l},h)=>{const{instance:a,ref:d}=Rh.useXTerm({options:Ph}),c=w.useMemo(()=>{switch(i){case"light":return Tn;case"dark":default:return Pn}},[i]),_=Ae(I=>I.sendInput),u=w.useRef(null),f=w.useRef(e),p=w.useRef(t),y=w.useRef(r&&!n),v=w.useRef(!1),A=w.useRef(null),T=w.useRef(null);w.useEffect(()=>{f.current=e,p.current=t},[e,t]),w.useEffect(()=>{y.current=r&&!n},[r,n]);const{scheduleResize:L,runPostSelectResize:O,setFitAddon:W,setTerminal:H}=Lh({deviceId:e,paneId:t,deviceConnected:r,isSelectionInvalid:n,onResize:o,onSync:l,getContainerRect:()=>{const I=u.current;if(!I)return null;const $=I.getBoundingClientRect();return{width:$.width,height:$.height}}});w.useEffect(()=>{a&&(a.options.theme=c)},[a,c]),w.useEffect(()=>{a&&(a.options.disableStdin=s==="editor")},[a,s]);const V=w.useMemo(()=>a?{onResetTerminal:I=>{f.current===I&&(a.reset(),v.current=!1,O())},onApplyHistory:(I,$)=>{f.current===I&&a.write(Th($))},onFlushBuffer:(I,$)=>{if(f.current===I)for(const F of $){const C=Ar(F,v.current);v.current=C.endedWithCR,a.write(C.normalized)}},onOutput:(I,$,F)=>{if(f.current!==I||p.current!==$||!y.current)return;const C=Ar(F,v.current);v.current=C.endedWithCR,a.write(C.normalized)}}:{},[a,O]);return w.useEffect(()=>{a?A.current!==a&&(v.current=!1,a.reset(),A.current=a):A.current=null},[a]),w.useEffect(()=>{},[a]),w.useEffect(()=>{Os(V)},[V]),w.useEffect(()=>()=>{Os({})},[]),w.useEffect(()=>{if(!a){T.current=null,W(null),H(null);return}const I=new Mh.FitAddon;return a.loadAddon(I),T.current=I,W(I),H(a),L("sync",{immediate:!0,force:!0}),()=>{try{I.dispose()}finally{T.current=null,W(null),H(null)}}},[a,L,W,H]),w.useEffect(()=>{const I=u.current;if(!I)return;let $=null;const F=new ResizeObserver(()=>{$!==null&&cancelAnimationFrame($),$=requestAnimationFrame(()=>{$=null,L("resize")})});return F.observe(I),()=>{F.disconnect(),$!==null&&cancelAnimationFrame($)}},[L]),w.useEffect(()=>{if(!a||!e||!t)return;const I=a.onData($=>{!r||n||_(e,t,$,!1)});return a.attachCustomKeyEventHandler($=>!r||n||$.type!=="keydown"||s!=="direct"?!0:$.shiftKey&&$.key==="Enter"?($.preventDefault(),_(e,t,"\x1B[13;2u",!1),!1):!0),()=>{I.dispose(),a.attachCustomKeyEventHandler(()=>!0)}},[a,e,t,r,n,s,_]),w.useImperativeHandle(h,()=>({write:I=>a==null?void 0:a.write(I),reset:()=>{a==null||a.reset(),v.current=!1},scrollToBottom:()=>a==null?void 0:a.scrollToBottom(),resize:(I,$)=>a==null?void 0:a.resize(I,$),getTerminal:()=>a??null,getSize:()=>a?{cols:Math.max(2,a.cols),rows:Math.max(2,a.rows)}:null,runPostSelectResize:()=>O(),scheduleResize:(I,$)=>L(I,$),calculateSizeFromContainer:()=>{var M,x,j,G,le,Ee,J,ie,Z,ee,Y,tt,me,Te,ve,he;const I=u.current,$=a,F=T.current;if(!I||!$)return null;const C=I.getBoundingClientRect();if(C.width===0||C.height===0)return null;const m=$._core;let k;if(F)try{const K=F.proposeDimensions();if(K)k=Math.max(2,K.cols);else{const vt=((G=(j=(x=(M=m==null?void 0:m._renderService)==null?void 0:M.dimensions)==null?void 0:x.css)==null?void 0:j.cell)==null?void 0:G.width)??9;k=Math.max(2,Math.floor(C.width/vt))}}catch{const K=((ie=(J=(Ee=(le=m==null?void 0:m._renderService)==null?void 0:le.dimensions)==null?void 0:Ee.css)==null?void 0:J.cell)==null?void 0:ie.width)??9;k=Math.max(2,Math.floor(C.width/K))}else{const K=((tt=(Y=(ee=(Z=m==null?void 0:m._renderService)==null?void 0:Z.dimensions)==null?void 0:ee.css)==null?void 0:Y.cell)==null?void 0:tt.width)??9;k=Math.max(2,Math.floor(C.width/K))}const E=((he=(ve=(Te=(me=m==null?void 0:m._renderService)==null?void 0:me.dimensions)==null?void 0:Te.css)==null?void 0:ve.cell)==null?void 0:he.height)??17,R=Math.max(2,Math.floor(C.height/E));return{cols:k,rows:R}}}),[a,O,L]),B.jsx("div",{ref:u,className:"h-full w-full relative",style:{backgroundColor:c.background},children:B.jsx("div",{ref:d,className:"absolute inset-0"})})});An.displayName="Terminal";function Ah(){const e=Ss.getState().settings;return(e==null?void 0:e.siteName)||"tmex"}function Ir(e){const t=e==null?void 0:e.trim();return t&&t.length>0?t:"?"}function In({paneIdx:e,windowIdx:t,paneTitle:i,windowName:s,deviceName:r}){const n=t??"?",o=e??"?",l=Ir(i??s),h=Ir(r);return`${n}/${o}: ${l}@${h}`}function Ih(e){const t=Ah();return e!=null&&e.trim()?`[${t}]${e}`:t}function Oh(){if(typeof navigator>"u")return!1;const e=navigator.userAgent,t=/iPad|iPhone|iPod/.test(e),i=navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1;return t||i}const Nh=[{key:"enter",label:"ENTER",payload:"\r"},{key:"ctrl-c",label:"CTRL-C",payload:""},{key:"ctrl-d",label:"CTRL-D",payload:""},{key:"up",label:"↑",payload:"\x1B[A"},{key:"down",label:"↓",payload:"\x1B[B"},{key:"left",label:"←",payload:"\x1B[D"},{key:"right",label:"→",payload:"\x1B[C"},{key:"shift-enter",label:"SHIFT+ENTER",payload:"\x1B[13;2u"},{key:"tab",label:"TAB",payload:" "},{key:"backspace",label:"BACKSPACE",payload:"\b"},{key:"esc",label:"ESC",payload:"\x1B"},{key:"delete",label:"DELETE",payload:""},{key:":",label:":",payload:":"},{key:"/",label:"/",payload:"/"},{key:"'",label:"'",payload:"'"},{key:'"',label:'"',payload:'"'},{key:"`",label:"`",payload:"`"}],Or=w.memo(function({onSend:t,onFocusEditor:i,disabled:s,isMobile:r,inputMode:n}){return B.jsx("div",{className:"terminal-shortcuts-strip my-2 bg-muted rounded-xl","data-testid":"terminal-shortcuts-strip",children:B.jsx("div",{className:"shortcut-row flex items-center gap-1.5 p-2 overflow-x-auto scrollbar-thin","data-testid":"editor-shortcuts-row",children:Nh.map(o=>B.jsx(_t,{variant:"secondary",size:"sm",className:"h-7 min-w-9 px-2.5 rounded-full text-[11px] font-medium tracking-wide shrink-0 [@media(any-pointer:coarse)]:h-9 [@media(any-pointer:coarse)]:min-w-10 [@media(any-pointer:coarse)]:px-3",title:o.label,"aria-label":o.label,"data-testid":`editor-shortcut-${o.key}`,onPointerDown:l=>l.preventDefault(),onClick:()=>{t(o.payload),r&&n==="editor"&&(i==null||i())},disabled:s,children:o.label},o.key))})})});function qh(){var Is;const{t:e}=Fr(),{deviceId:t,windowId:i,paneId:s}=ws(),r=Yn(),n=w.useRef(null),o=w.useRef(null),l=w.useRef(null),h=w.useRef(null),a=w.useRef(!1),d=w.useRef(!1),c=w.useRef(null),_=Ae(g=>g.selectPane),u=Ae(g=>t?g.snapshots[t]:void 0),f=Ae(g=>{var P;return t?(P=g.deviceErrors)==null?void 0:P[t]:void 0}),p=Ae(g=>{var P;return t?((P=g.deviceConnected)==null?void 0:P[t])??!1:!1}),y=Ss(g=>{var P;return((P=g.settings)==null?void 0:P.siteName)??"tmex"}),v=w.useMemo(()=>bs(s),[s]),A=w.useMemo(()=>t&&v?`${t}:${v}`:null,[t,v]),[T,L]=w.useState(!1),[O,W]=w.useState(""),[H,V]=w.useState(!1),I=w.useRef(!1),$=!p||!v,[F,C]=w.useState(0),[m,k]=w.useState(0),[E,R]=w.useState(!1),M=Ve(g=>g.inputMode),x=Ve(g=>g.theme),j=Ve(g=>g.editorSendWithEnter),G=Ve(g=>g.setEditorSendWithEnter),le=Ve(g=>g.addEditorHistory),Ee=Ve(g=>g.setEditorDraft),J=Ve(g=>g.removeEditorDraft),ie=Ve(g=>A?g.editorDrafts[A]??"":""),Z=w.useMemo(()=>Oh(),[]),ee=T&&M==="editor"&&Z&&H,Y=(Is=u==null?void 0:u.session)==null?void 0:Is.windows,tt=x==="light"?Tn:Pn,{data:me}=Xn({queryKey:["devices"],queryFn:async()=>{const g=await fetch("/api/devices");if(!g.ok)throw new Error("Failed to fetch devices");return g.json()},throwOnError:!1}),Te=w.useMemo(()=>{if(t)return me==null?void 0:me.devices.find(g=>g.id===t)},[t,me==null?void 0:me.devices]),ve=w.useMemo(()=>{if(!(!i||!Y))return Y.find(g=>g.id===i)},[i,Y]),he=w.useMemo(()=>{if(!(!v||!ve))return ve.panes.find(g=>g.id===v)},[v,ve]),K=!!Y,Ts=!!(K&&!!i&&!ve||K&&!!i&&!!v&&!!ve&&!he?e("wsError.checkGateway"):null),Ne=!!(p&&v&&!Ts),Ps=w.useMemo(()=>{if(!ve||!he)return null;const g=(Te==null?void 0:Te.name)??t;return In({paneIdx:he.index,windowIdx:ve.index,paneTitle:he.title,windowName:ve.name,deviceName:g})},[Te==null?void 0:Te.name,t,he,ve]),On=w.useCallback((g,P)=>{!t||!v||Ae.getState().resizePane(t,v,g,P)},[t,v]),Nn=w.useCallback((g,P)=>{!t||!v||Ae.getState().syncPaneSize(t,v,g,P)},[t,v]);w.useEffect(()=>{const g=()=>{L(window.innerWidth<768||"ontouchstart"in window)};return g(),window.addEventListener("resize",g),()=>window.removeEventListener("resize",g)},[]),w.useEffect(()=>{if(!T||!Z||d.current)return;d.current=!0;const g=()=>{window.scrollTo(0,1)},P=window.requestAnimationFrame(g),N=window.setTimeout(g,120),_e=window.setTimeout(g,420);return()=>{window.cancelAnimationFrame(P),window.clearTimeout(N),window.clearTimeout(_e)}},[Z,T]),w.useEffect(()=>{M!=="editor"&&V(!1)},[M]),w.useEffect(()=>{var _e,ne;if(!(T&&Z&&M==="editor"&&H)){C(0);return}let g=null;const P=()=>{const $e=window.visualViewport,lt=($e==null?void 0:$e.height)??window.innerHeight,Bt=($e==null?void 0:$e.offsetTop)??0,Un=Math.max(0,Math.round(window.innerHeight-lt-Bt));C(Un)},N=()=>{g===null&&(g=window.requestAnimationFrame(()=>{g=null,P()}))};return P(),(_e=window.visualViewport)==null||_e.addEventListener("resize",N),(ne=window.visualViewport)==null||ne.addEventListener("scroll",N),window.addEventListener("resize",N),()=>{var $e,lt;($e=window.visualViewport)==null||$e.removeEventListener("resize",N),(lt=window.visualViewport)==null||lt.removeEventListener("scroll",N),window.removeEventListener("resize",N),g!==null&&window.cancelAnimationFrame(g)}},[M,H,Z,T]),w.useEffect(()=>{if(!ee){k(0);return}const g=o.current;if(!g)return;const P=()=>{k(Math.ceil(g.getBoundingClientRect().height))};P();const N=new ResizeObserver(P);return N.observe(g),()=>N.disconnect()},[ee]),w.useEffect(()=>{t&&(a.current=!1,Et.current=null,Rt.current=null,c.current=null,kt.current=[])},[t]),w.useEffect(()=>{p||(a.current=!1)},[p]),w.useEffect(()=>{if(!t||!p||!i||!Y)return;if(Y.length===0){r("/devices",{replace:!0});return}const g=Y.find(N=>N.id===i);if(!g)return;if(!v){const N=g.panes.find(_e=>_e.active)??g.panes[0];N&&r(`/devices/${t}/windows/${i}/panes/${Dt(N.id)}`,{replace:!0});return}if(!g.panes.find(N=>N.id===v)){const N=g.panes.find(_e=>_e.active)??g.panes[0];N&&r(`/devices/${t}/windows/${i}/panes/${Dt(N.id)}`,{replace:!0});return}},[t,p,Y,i,v,r]),w.useEffect(()=>{if(!t||!p||!Y||Y.length===0||i&&v||a.current)return;const g=Y.find(N=>N.active)??Y[0],P=g.panes.find(N=>N.active)??g.panes[0];P&&(a.current=!0,r(`/devices/${t}/windows/${g.id}/panes/${Dt(P.id)}`,{replace:!0}))},[p,t,r,v,i,Y]),w.useEffect(()=>{var N;if(!t||!i||!v||$||!p)return;const g=Ae.getState().selectedPanes[t];if(g&&g.windowId===i&&g.paneId===v)return;const P=((N=h.current)==null?void 0:N.calculateSizeFromContainer())??void 0;Si(i,v),_(t,i,v,P)},[p,t,$,v,_,i]);const kt=w.useRef([]),Si=w.useCallback((g,P)=>{const N=Date.now(),_e=[...kt.current.filter(ne=>N-ne.at<2e3),{windowId:g,paneId:P,at:N}];kt.current=_e.slice(-8)},[]),Be=Ae(g=>t?g.activePaneFromEvent[t]:void 0),Et=w.useRef(null);w.useEffect(()=>{var P;if(!t||!p||!i||!v||!Be)return;{const N=Date.now();if(kt.current.some(ne=>ne.windowId===Be.windowId&&ne.paneId===Be.paneId&&N-ne.at<1200))return}if(Be.windowId===i&&Be.paneId===v||Et.current&&Et.current.windowId===Be.windowId&&Et.current.paneId===Be.paneId)return;Et.current={...Be};const g=((P=h.current)==null?void 0:P.calculateSizeFromContainer())??void 0;Si(Be.windowId,Be.paneId),_(t,Be.windowId,Be.paneId,g),r(`/devices/${t}/windows/${Be.windowId}/panes/${Dt(Be.paneId)}`,{replace:!0})},[t,p,i,v,Be,_,r]);const Rt=w.useRef(null);w.useEffect(()=>{var lt;if(!t||!p||!Y||Y.length===0||c.current)return;const g=kt.current,P=g.length>0?g[g.length-1]:null;if(P&&Date.now()-P.at<1200)return;const N=Y.find(Bt=>Bt.active);if(!N)return;const _e=N.panes.find(Bt=>Bt.active);if(!_e)return;const ne={windowId:N.id,paneId:_e.id};if(Rt.current&&Rt.current.windowId===ne.windowId&&Rt.current.paneId===ne.paneId||(Rt.current={...ne},i===ne.windowId&&v===ne.paneId))return;const $e=((lt=h.current)==null?void 0:lt.calculateSizeFromContainer())??void 0;Si(ne.windowId,ne.paneId),_(t,ne.windowId,ne.paneId,$e),r(`/devices/${t}/windows/${ne.windowId}/panes/${Dt(ne.paneId)}`,{replace:!0})},[t,p,Y,i,v,_,r]),w.useEffect(()=>{var _e;if(!Ne||!he||$)return;const g=(_e=h.current)==null?void 0:_e.getTerminal();if(!g)return;const P=Math.max(2,Math.floor(he.width||0)),N=Math.max(2,Math.floor(he.height||0));!P||!N||g.cols===P&&g.rows===N||g.resize(P,N)},[Ne,$,he]),w.useEffect(()=>{const g=window.requestAnimationFrame(()=>{var N;(N=h.current)==null||N.scrollToBottom()}),P=window.setTimeout(()=>{var N;(N=h.current)==null||N.scrollToBottom()},120);return()=>{window.cancelAnimationFrame(g),window.clearTimeout(P)}},[M]),w.useEffect(()=>{f!=null&&f.message&&wi.error(f.message)},[f==null?void 0:f.message]),w.useEffect(()=>(document.title=Ih(Ps),()=>{document.title=y}),[y,Ps]),w.useEffect(()=>{const g=()=>{var P;(P=h.current)==null||P.scrollToBottom()};return window.addEventListener("tmex:jump-to-latest",g),()=>{window.removeEventListener("tmex:jump-to-latest",g)}},[]),w.useEffect(()=>{const g=P=>{const{deviceId:N,windowId:_e,paneId:ne}=P.detail;N===t&&(c.current={windowId:_e,paneId:ne})};return window.addEventListener("tmex:user-initiated-selection",g),()=>{window.removeEventListener("tmex:user-initiated-selection",g)}},[t]),w.useEffect(()=>{W(ie)},[ie]);const As=w.useCallback(g=>{if(!t||!v||!Ne)return;Ae.getState().sendInput(t,v,g,!1)},[Ne,t,v]),Hn=w.useCallback(()=>{if(!Ne){wi.error(e("wsError.checkGateway"));return}if(!t||!v||!O.trim())return;R(!0),window.setTimeout(()=>R(!1),150);const g=j?`${O}\r`:O;Ae.getState().sendInput(t,v,g,!1),le(O),A&&J(A),W("")},[le,Ne,t,A,j,O,J,v,e]),zn=w.useCallback(()=>{if(!Ne){wi.error(e("wsError.checkGateway"));return}if(!t||!v||!O.trim())return;R(!0),window.setTimeout(()=>R(!1),150);const g=O.split(/\r?\n/),P=Ae.getState();for(const N of g)N.trim()&&P.sendInput(t,v,`${N}\r`,!1);le(O),A&&J(A),W("")},[le,Ne,t,A,O,J,v,e]),Fn=w.useCallback(g=>{if(V(!0),!(T&&Z))return;const P=g.currentTarget;window.requestAnimationFrame(()=>{P.scrollIntoView({block:"nearest",inline:"nearest"})}),window.setTimeout(()=>{window.scrollTo(0,1)},60)},[Z,T]),Wn=w.useCallback(()=>{V(!1)},[]);if(!t)return B.jsx("div",{className:"flex h-full items-center justify-center p-4",children:B.jsx("div",{className:"rounded-lg border border-dashed border-border px-4 py-3 text-sm text-muted-foreground",children:e("device.noDevices")})});const $n=!p&&!f,Kn=w.useCallback(()=>{var g;(g=l.current)==null||g.focus({preventScroll:!0})},[]);return B.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background","data-testid":"device-page",children:[B.jsxs("div",{className:`flex-1 relative overflow-hidden min-h-0 min-w-0 ${T&&M==="editor"&&!ee?"pb-1":""}`,style:{paddingBottom:ee?`${m+60}px`:void 0},children:[B.jsx("div",{className:"h-full px-3 py-1 min-h-0 min-w-0 w-full relative flex rounded-xl",style:{backgroundColor:tt.background},children:p&&v?B.jsx("div",{ref:n,className:"flex-1 w-full",children:B.jsx(An,{ref:h,deviceId:t,paneId:v,theme:x,inputMode:M,deviceConnected:p,isSelectionInvalid:Ts,onResize:On,onSync:Nn},`${t}:${v}`)}):B.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-8 text-center",children:B.jsx("div",{className:"max-w-sm space-y-4",children:p?i?B.jsxs(B.Fragment,{children:[B.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:B.jsx(bi,{className:"h-6 w-6 text-muted-foreground animate-spin"})}),B.jsx("h3",{className:"text-lg font-medium",children:e("terminal.connecting")})]}):B.jsxs(B.Fragment,{children:[B.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:B.jsx("span",{className:"text-2xl text-muted-foreground",children:"📋"})}),B.jsx("h3",{className:"text-lg font-medium",children:e("window.noWindowSelected")}),B.jsx("p",{className:"text-sm text-muted-foreground",children:e("window.selectWindowToStart")})]}):B.jsxs(B.Fragment,{children:[B.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:B.jsx("span",{className:"text-2xl text-muted-foreground",children:"🔌"})}),B.jsx("h3",{className:"text-lg font-medium",children:e("device.disconnected")}),B.jsx("p",{className:"text-sm text-muted-foreground",children:e("device.connectToStart")})]})})})}),$n&&B.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/85 backdrop-blur-sm","data-testid":"terminal-status-overlay",children:B.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:[B.jsx("div",{className:"h-7 w-7 rounded-full border-2 border-primary border-t-transparent animate-spin"}),B.jsx("span",{className:"text-xs text-muted-foreground","data-testid":"terminal-status-text",children:e("terminal.connecting")})]})})]}),M==="direct"&&B.jsx("div",{className:"",children:B.jsx(Or,{onSend:As,disabled:!Ne,isMobile:T,inputMode:M})}),M==="editor"&&B.jsxs("div",{ref:o,className:`editor-mode-input bg-card/85 backdrop-blur-sm ${ee?"fixed left-0 right-0 z-50":""}`,style:ee?{bottom:`${F}px`}:void 0,children:[T&&B.jsx(Or,{onSend:As,onFocusEditor:Kn,disabled:!Ne,isMobile:T,inputMode:M}),B.jsx("textarea",{ref:l,"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:O,onChange:g=>{const P=g.target.value;if(W(P),!!A){if(P){Ee(A,P);return}J(A)}},placeholder:e("terminal.inputPlaceholder"),onFocus:Fn,onBlur:Wn,onCompositionStart:()=>{I.current=!0},onCompositionEnd:()=>{I.current=!1}}),B.jsx("div",{className:"actions mt-2",children:B.jsxs("div",{className:"send-row flex flex-wrap items-center justify-end gap-2","data-testid":"editor-send-row",children:[B.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:[B.jsx(no,{size:"sm",checked:j,onCheckedChange:g=>G(!!g)}),B.jsx("span",{children:e("terminal.editorSendWithEnter")})]}),B.jsxs(_t,{variant:"outline",size:"sm","data-testid":"editor-clear",onPointerDown:g=>g.preventDefault(),onClick:()=>{var g;W(""),A&&J(A),T&&M==="editor"&&((g=l.current)==null||g.focus({preventScroll:!0}))},title:e("terminal.clear"),children:[B.jsx(Gn,{className:"h-4 w-4"}),e("terminal.clear")]}),B.jsxs(_t,{variant:"secondary",size:"sm","data-testid":"editor-send-line-by-line",onPointerDown:g=>g.preventDefault(),onClick:()=>{var g;zn(),T&&M==="editor"&&((g=l.current)==null||g.focus({preventScroll:!0}))},disabled:!Ne||E,children:[E?B.jsx(bi,{className:"h-4 w-4 animate-spin"}):B.jsx(Ns,{className:"h-4 w-4"}),e("terminal.editorSendLineByLine")]}),B.jsxs(_t,{variant:"default",size:"sm","data-testid":"editor-send",onPointerDown:g=>g.preventDefault(),onClick:()=>{var g;Hn(),T&&M==="editor"&&((g=l.current)==null||g.focus({preventScroll:!0}))},disabled:!Ne||E,children:[E?B.jsx(bi,{className:"h-4 w-4 animate-spin"}):B.jsx(Ns,{className:"h-4 w-4"}),e("common.send")]})]})})]})]})}function jh(){const{deviceId:e,windowId:t,paneId:i}=ws(),s=i?bs(i):void 0,r=Ae(d=>d.snapshots),n=Ss(d=>{var c;return((c=d.settings)==null?void 0:c.siteName)??"tmex"}),o=e?r[e]:void 0,l=w.useMemo(()=>{var d;if(!(!t||!((d=o==null?void 0:o.session)!=null&&d.windows)))return o.session.windows.find(c=>c.id===t)},[t,o]),h=w.useMemo(()=>{if(!(!s||!l))return l.panes.find(d=>d.id===s)},[s,l]),a=w.useMemo(()=>l&&h?In({paneIdx:h.index,windowIdx:l.index,paneTitle:h.title,windowName:l.name,deviceName:n}):e??"",[l,h,n,e]);return B.jsx(B.Fragment,{children:a})}function Vh(){const{t:e}=Fr(),{deviceId:t,paneId:i}=ws(),s=i?bs(i):void 0,r=Ve(f=>f.inputMode),n=Ve(f=>f.setInputMode),o=Ae(f=>{var p;return t?((p=f.deviceConnected)==null?void 0:p[t])??!1:!1}),[l,h]=w.useState(!1),a=!!(s&&o),d=()=>{n(r==="direct"?"editor":"direct")},c=()=>{window.dispatchEvent(new CustomEvent("tmex:jump-to-latest"))},_=()=>{h(!0)},u=()=>{window.location.reload()};return B.jsxs(B.Fragment,{children:[B.jsx(_t,{variant:"ghost",size:"icon-sm",onClick:_,"aria-label":e("nav.refreshPage"),title:e("nav.refreshPage"),children:B.jsx(uo,{className:"h-4 w-4"})}),B.jsx(_t,{variant:"ghost",size:"icon-sm",onClick:d,disabled:!a,"data-testid":"terminal-input-mode-toggle","aria-label":e(r==="direct"?"nav.switchToEditor":"nav.switchToDirect"),title:e(r==="direct"?"nav.switchToEditor":"nav.switchToDirect"),children:r==="direct"?B.jsx(ho,{className:"h-4 w-4"}):B.jsx(fo,{className:"h-4 w-4"})}),B.jsx(_t,{variant:"ghost",size:"icon-sm",onClick:c,disabled:!a,"aria-label":e("nav.jumpToLatest"),title:e("nav.jumpToLatest"),children:B.jsx(ao,{className:"h-4 w-4"})}),B.jsx(Jn,{open:l,onOpenChange:h,children:B.jsxs(Zn,{children:[B.jsxs(Qn,{children:[B.jsx(eo,{children:e("nav.refreshPage")}),B.jsx(to,{children:e("nav.refreshPageConfirm")})]}),B.jsxs(io,{children:[B.jsx(so,{onClick:()=>h(!1),children:e("common.cancel")}),B.jsx(ro,{onClick:u,children:e("common.confirm")})]})]})})]})}export{Vh as PageActions,jh as PageTitle,qh as default};
267
- //# sourceMappingURL=DevicePage-HcbJmTWj.js.map
266
+ `)}function Ar(e,t){let i=t,s=0;for(const l of e)l===10&&!i&&(s+=1),i=l===13;const r=i;if(s===0)return{normalized:e,endedWithCR:r};const n=new Uint8Array(e.length+s);let o=0;i=t;for(const l of e)l===10&&!i&&(n[o]=13,o+=1),n[o]=l,o+=1,i=l===13;return{normalized:n,endedWithCR:r}}const Ph={fontFamily:Bh,fontSize:13,convertEol:!0,scrollSensitivity:2,smoothScrollDuration:120,letterSpacing:0,cursorBlink:!0,allowProposedApi:!0,scrollback:1e4},An=w.forwardRef(({deviceId:e,paneId:t,theme:i,inputMode:s,deviceConnected:r,isSelectionInvalid:n,onResize:o,onSync:l},h)=>{const{instance:a,ref:d}=Rh.useXTerm({options:Ph}),c=w.useMemo(()=>{switch(i){case"light":return Tn;case"dark":default:return Pn}},[i]),_=Ae(I=>I.sendInput),u=w.useRef(null),f=w.useRef(e),p=w.useRef(t),y=w.useRef(r&&!n),v=w.useRef(!1),A=w.useRef(null),T=w.useRef(null);w.useEffect(()=>{f.current=e,p.current=t},[e,t]),w.useEffect(()=>{y.current=r&&!n},[r,n]);const{scheduleResize:L,runPostSelectResize:O,setFitAddon:W,setTerminal:H}=Lh({deviceId:e,paneId:t,deviceConnected:r,isSelectionInvalid:n,onResize:o,onSync:l,getContainerRect:()=>{const I=u.current;if(!I)return null;const $=I.getBoundingClientRect();return{width:$.width,height:$.height}}});w.useEffect(()=>{a&&(a.options.theme=c)},[a,c]),w.useEffect(()=>{a&&(a.options.disableStdin=s==="editor")},[a,s]);const V=w.useMemo(()=>a?{onResetTerminal:I=>{f.current===I&&(a.reset(),v.current=!1,O())},onApplyHistory:(I,$)=>{f.current===I&&a.write(Th($))},onFlushBuffer:(I,$)=>{if(f.current===I)for(const F of $){const C=Ar(F,v.current);v.current=C.endedWithCR,a.write(C.normalized)}},onOutput:(I,$,F)=>{if(f.current!==I||p.current!==$||!y.current)return;const C=Ar(F,v.current);v.current=C.endedWithCR,a.write(C.normalized)}}:{},[a,O]);return w.useEffect(()=>{a?A.current!==a&&(v.current=!1,a.reset(),A.current=a):A.current=null},[a]),w.useEffect(()=>{},[a]),w.useEffect(()=>{Os(V)},[V]),w.useEffect(()=>()=>{Os({})},[]),w.useEffect(()=>{if(!a){T.current=null,W(null),H(null);return}const I=new Mh.FitAddon;return a.loadAddon(I),T.current=I,W(I),H(a),L("sync",{immediate:!0,force:!0}),()=>{try{I.dispose()}finally{T.current=null,W(null),H(null)}}},[a,L,W,H]),w.useEffect(()=>{const I=u.current;if(!I)return;let $=null;const F=new ResizeObserver(()=>{$!==null&&cancelAnimationFrame($),$=requestAnimationFrame(()=>{$=null,L("resize")})});return F.observe(I),()=>{F.disconnect(),$!==null&&cancelAnimationFrame($)}},[L]),w.useEffect(()=>{if(!a||!e||!t)return;const I=a.onData($=>{!r||n||_(e,t,$,!1)});return a.attachCustomKeyEventHandler($=>!r||n||$.type!=="keydown"||s!=="direct"?!0:$.shiftKey&&$.key==="Enter"?($.preventDefault(),_(e,t,"\x1B[13;2u",!1),!1):!0),()=>{I.dispose(),a.attachCustomKeyEventHandler(()=>!0)}},[a,e,t,r,n,s,_]),w.useImperativeHandle(h,()=>({write:I=>a==null?void 0:a.write(I),reset:()=>{a==null||a.reset(),v.current=!1},scrollToBottom:()=>a==null?void 0:a.scrollToBottom(),resize:(I,$)=>a==null?void 0:a.resize(I,$),getTerminal:()=>a??null,getSize:()=>a?{cols:Math.max(2,a.cols),rows:Math.max(2,a.rows)}:null,runPostSelectResize:()=>O(),scheduleResize:(I,$)=>L(I,$),calculateSizeFromContainer:()=>{var M,x,j,G,le,Ee,J,ie,Z,ee,Y,tt,me,Te,ve,he;const I=u.current,$=a,F=T.current;if(!I||!$)return null;const C=I.getBoundingClientRect();if(C.width===0||C.height===0)return null;const m=$._core;let k;if(F)try{const K=F.proposeDimensions();if(K)k=Math.max(2,K.cols);else{const vt=((G=(j=(x=(M=m==null?void 0:m._renderService)==null?void 0:M.dimensions)==null?void 0:x.css)==null?void 0:j.cell)==null?void 0:G.width)??9;k=Math.max(2,Math.floor(C.width/vt))}}catch{const K=((ie=(J=(Ee=(le=m==null?void 0:m._renderService)==null?void 0:le.dimensions)==null?void 0:Ee.css)==null?void 0:J.cell)==null?void 0:ie.width)??9;k=Math.max(2,Math.floor(C.width/K))}else{const K=((tt=(Y=(ee=(Z=m==null?void 0:m._renderService)==null?void 0:Z.dimensions)==null?void 0:ee.css)==null?void 0:Y.cell)==null?void 0:tt.width)??9;k=Math.max(2,Math.floor(C.width/K))}const E=((he=(ve=(Te=(me=m==null?void 0:m._renderService)==null?void 0:me.dimensions)==null?void 0:Te.css)==null?void 0:ve.cell)==null?void 0:he.height)??17,R=Math.max(2,Math.floor(C.height/E));return{cols:k,rows:R}}}),[a,O,L]),B.jsx("div",{ref:u,className:"h-full w-full relative",style:{backgroundColor:c.background},children:B.jsx("div",{ref:d,className:"absolute inset-0"})})});An.displayName="Terminal";function Ah(){const e=Ss.getState().settings;return(e==null?void 0:e.siteName)||"tmex"}function Ir(e){const t=e==null?void 0:e.trim();return t&&t.length>0?t:"?"}function In({paneIdx:e,windowIdx:t,paneTitle:i,windowName:s,deviceName:r}){const n=t??"?",o=e??"?",l=Ir(i??s),h=Ir(r);return`${n}/${o}: ${l}@${h}`}function Ih(e){const t=Ah();return e!=null&&e.trim()?`[${t}]${e}`:t}function Oh(){if(typeof navigator>"u")return!1;const e=navigator.userAgent,t=/iPad|iPhone|iPod/.test(e),i=navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1;return t||i}const Nh=[{key:"enter",label:"ENTER",payload:"\r"},{key:"ctrl-c",label:"CTRL-C",payload:""},{key:"ctrl-d",label:"CTRL-D",payload:""},{key:"up",label:"↑",payload:"\x1B[A"},{key:"down",label:"↓",payload:"\x1B[B"},{key:"left",label:"←",payload:"\x1B[D"},{key:"right",label:"→",payload:"\x1B[C"},{key:"shift-enter",label:"SHIFT+ENTER",payload:"\x1B[13;2u"},{key:"tab",label:"TAB",payload:" "},{key:"backspace",label:"BACKSPACE",payload:"\b"},{key:"esc",label:"ESC",payload:"\x1B"},{key:"delete",label:"DELETE",payload:""},{key:":",label:":",payload:":"},{key:"/",label:"/",payload:"/"},{key:"'",label:"'",payload:"'"},{key:'"',label:'"',payload:'"'},{key:"`",label:"`",payload:"`"}],Or=w.memo(function({onSend:t,onFocusEditor:i,disabled:s,isMobile:r,inputMode:n}){return B.jsx("div",{className:"terminal-shortcuts-strip my-2 bg-muted rounded-xl","data-testid":"terminal-shortcuts-strip",children:B.jsx("div",{className:"shortcut-row flex items-center gap-1.5 p-2 overflow-x-auto scrollbar-thin","data-testid":"editor-shortcuts-row",children:Nh.map(o=>B.jsx(_t,{variant:"secondary",size:"sm",className:"h-7 min-w-9 px-2.5 rounded-full text-[11px] font-medium tracking-wide shrink-0 [@media(any-pointer:coarse)]:h-9 [@media(any-pointer:coarse)]:min-w-10 [@media(any-pointer:coarse)]:px-3",title:o.label,"aria-label":o.label,"data-testid":`editor-shortcut-${o.key}`,onPointerDown:l=>l.preventDefault(),onClick:()=>{t(o.payload),r&&n==="editor"&&(i==null||i())},disabled:s,children:o.label},o.key))})})});function qh(){var Is;const{t:e}=Fr(),{deviceId:t,windowId:i,paneId:s}=ws(),r=Yn(),n=w.useRef(null),o=w.useRef(null),l=w.useRef(null),h=w.useRef(null),a=w.useRef(!1),d=w.useRef(!1),c=w.useRef(null),_=Ae(g=>g.selectPane),u=Ae(g=>t?g.snapshots[t]:void 0),f=Ae(g=>{var P;return t?(P=g.deviceErrors)==null?void 0:P[t]:void 0}),p=Ae(g=>{var P;return t?((P=g.deviceConnected)==null?void 0:P[t])??!1:!1}),y=Ss(g=>{var P;return((P=g.settings)==null?void 0:P.siteName)??"tmex"}),v=w.useMemo(()=>bs(s),[s]),A=w.useMemo(()=>t&&v?`${t}:${v}`:null,[t,v]),[T,L]=w.useState(!1),[O,W]=w.useState(""),[H,V]=w.useState(!1),I=w.useRef(!1),$=!p||!v,[F,C]=w.useState(0),[m,k]=w.useState(0),[E,R]=w.useState(!1),M=Ve(g=>g.inputMode),x=Ve(g=>g.theme),j=Ve(g=>g.editorSendWithEnter),G=Ve(g=>g.setEditorSendWithEnter),le=Ve(g=>g.addEditorHistory),Ee=Ve(g=>g.setEditorDraft),J=Ve(g=>g.removeEditorDraft),ie=Ve(g=>A?g.editorDrafts[A]??"":""),Z=w.useMemo(()=>Oh(),[]),ee=T&&M==="editor"&&Z&&H,Y=(Is=u==null?void 0:u.session)==null?void 0:Is.windows,tt=x==="light"?Tn:Pn,{data:me}=Xn({queryKey:["devices"],queryFn:async()=>{const g=await fetch("/api/devices");if(!g.ok)throw new Error("Failed to fetch devices");return g.json()},throwOnError:!1}),Te=w.useMemo(()=>{if(t)return me==null?void 0:me.devices.find(g=>g.id===t)},[t,me==null?void 0:me.devices]),ve=w.useMemo(()=>{if(!(!i||!Y))return Y.find(g=>g.id===i)},[i,Y]),he=w.useMemo(()=>{if(!(!v||!ve))return ve.panes.find(g=>g.id===v)},[v,ve]),K=!!Y,Ts=!!(K&&!!i&&!ve||K&&!!i&&!!v&&!!ve&&!he?e("wsError.checkGateway"):null),Ne=!!(p&&v&&!Ts),Ps=w.useMemo(()=>{if(!ve||!he)return null;const g=(Te==null?void 0:Te.name)??t;return In({paneIdx:he.index,windowIdx:ve.index,paneTitle:he.title,windowName:ve.name,deviceName:g})},[Te==null?void 0:Te.name,t,he,ve]),On=w.useCallback((g,P)=>{!t||!v||Ae.getState().resizePane(t,v,g,P)},[t,v]),Nn=w.useCallback((g,P)=>{!t||!v||Ae.getState().syncPaneSize(t,v,g,P)},[t,v]);w.useEffect(()=>{const g=()=>{L(window.innerWidth<768||"ontouchstart"in window)};return g(),window.addEventListener("resize",g),()=>window.removeEventListener("resize",g)},[]),w.useEffect(()=>{if(!T||!Z||d.current)return;d.current=!0;const g=()=>{window.scrollTo(0,1)},P=window.requestAnimationFrame(g),N=window.setTimeout(g,120),_e=window.setTimeout(g,420);return()=>{window.cancelAnimationFrame(P),window.clearTimeout(N),window.clearTimeout(_e)}},[Z,T]),w.useEffect(()=>{M!=="editor"&&V(!1)},[M]),w.useEffect(()=>{var _e,ne;if(!(T&&Z&&M==="editor"&&H)){C(0);return}let g=null;const P=()=>{const $e=window.visualViewport,lt=($e==null?void 0:$e.height)??window.innerHeight,Bt=($e==null?void 0:$e.offsetTop)??0,Un=Math.max(0,Math.round(window.innerHeight-lt-Bt));C(Un)},N=()=>{g===null&&(g=window.requestAnimationFrame(()=>{g=null,P()}))};return P(),(_e=window.visualViewport)==null||_e.addEventListener("resize",N),(ne=window.visualViewport)==null||ne.addEventListener("scroll",N),window.addEventListener("resize",N),()=>{var $e,lt;($e=window.visualViewport)==null||$e.removeEventListener("resize",N),(lt=window.visualViewport)==null||lt.removeEventListener("scroll",N),window.removeEventListener("resize",N),g!==null&&window.cancelAnimationFrame(g)}},[M,H,Z,T]),w.useEffect(()=>{if(!ee){k(0);return}const g=o.current;if(!g)return;const P=()=>{k(Math.ceil(g.getBoundingClientRect().height))};P();const N=new ResizeObserver(P);return N.observe(g),()=>N.disconnect()},[ee]),w.useEffect(()=>{t&&(a.current=!1,Et.current=null,Rt.current=null,c.current=null,kt.current=[])},[t]),w.useEffect(()=>{p||(a.current=!1)},[p]),w.useEffect(()=>{if(!t||!p||!i||!Y)return;if(Y.length===0){r("/devices",{replace:!0});return}const g=Y.find(N=>N.id===i);if(!g)return;if(!v){const N=g.panes.find(_e=>_e.active)??g.panes[0];N&&r(`/devices/${t}/windows/${i}/panes/${Dt(N.id)}`,{replace:!0});return}if(!g.panes.find(N=>N.id===v)){const N=g.panes.find(_e=>_e.active)??g.panes[0];N&&r(`/devices/${t}/windows/${i}/panes/${Dt(N.id)}`,{replace:!0});return}},[t,p,Y,i,v,r]),w.useEffect(()=>{if(!t||!p||!Y||Y.length===0||i&&v||a.current)return;const g=Y.find(N=>N.active)??Y[0],P=g.panes.find(N=>N.active)??g.panes[0];P&&(a.current=!0,r(`/devices/${t}/windows/${g.id}/panes/${Dt(P.id)}`,{replace:!0}))},[p,t,r,v,i,Y]),w.useEffect(()=>{var N;if(!t||!i||!v||$||!p)return;const g=Ae.getState().selectedPanes[t];if(g&&g.windowId===i&&g.paneId===v)return;const P=((N=h.current)==null?void 0:N.calculateSizeFromContainer())??void 0;Si(i,v),_(t,i,v,P)},[p,t,$,v,_,i]);const kt=w.useRef([]),Si=w.useCallback((g,P)=>{const N=Date.now(),_e=[...kt.current.filter(ne=>N-ne.at<2e3),{windowId:g,paneId:P,at:N}];kt.current=_e.slice(-8)},[]),Be=Ae(g=>t?g.activePaneFromEvent[t]:void 0),Et=w.useRef(null);w.useEffect(()=>{var P;if(!t||!p||!i||!v||!Be)return;{const N=Date.now();if(kt.current.some(ne=>ne.windowId===Be.windowId&&ne.paneId===Be.paneId&&N-ne.at<1200))return}if(Be.windowId===i&&Be.paneId===v||Et.current&&Et.current.windowId===Be.windowId&&Et.current.paneId===Be.paneId)return;Et.current={...Be};const g=((P=h.current)==null?void 0:P.calculateSizeFromContainer())??void 0;Si(Be.windowId,Be.paneId),_(t,Be.windowId,Be.paneId,g),r(`/devices/${t}/windows/${Be.windowId}/panes/${Dt(Be.paneId)}`,{replace:!0})},[t,p,i,v,Be,_,r]);const Rt=w.useRef(null);w.useEffect(()=>{var lt;if(!t||!p||!Y||Y.length===0||c.current)return;const g=kt.current,P=g.length>0?g[g.length-1]:null;if(P&&Date.now()-P.at<1200)return;const N=Y.find(Bt=>Bt.active);if(!N)return;const _e=N.panes.find(Bt=>Bt.active);if(!_e)return;const ne={windowId:N.id,paneId:_e.id};if(Rt.current&&Rt.current.windowId===ne.windowId&&Rt.current.paneId===ne.paneId||(Rt.current={...ne},i===ne.windowId&&v===ne.paneId))return;const $e=((lt=h.current)==null?void 0:lt.calculateSizeFromContainer())??void 0;Si(ne.windowId,ne.paneId),_(t,ne.windowId,ne.paneId,$e),r(`/devices/${t}/windows/${ne.windowId}/panes/${Dt(ne.paneId)}`,{replace:!0})},[t,p,Y,i,v,_,r]),w.useEffect(()=>{var _e;if(!Ne||!he||$)return;const g=(_e=h.current)==null?void 0:_e.getTerminal();if(!g)return;const P=Math.max(2,Math.floor(he.width||0)),N=Math.max(2,Math.floor(he.height||0));!P||!N||g.cols===P&&g.rows===N||g.resize(P,N)},[Ne,$,he]),w.useEffect(()=>{const g=window.requestAnimationFrame(()=>{var N;(N=h.current)==null||N.scrollToBottom()}),P=window.setTimeout(()=>{var N;(N=h.current)==null||N.scrollToBottom()},120);return()=>{window.cancelAnimationFrame(g),window.clearTimeout(P)}},[M]),w.useEffect(()=>{f!=null&&f.message&&wi.error(f.message)},[f==null?void 0:f.message]),w.useEffect(()=>(document.title=Ih(Ps),()=>{document.title=y}),[y,Ps]),w.useEffect(()=>{const g=()=>{var P;(P=h.current)==null||P.scrollToBottom()};return window.addEventListener("tmex:jump-to-latest",g),()=>{window.removeEventListener("tmex:jump-to-latest",g)}},[]),w.useEffect(()=>{const g=P=>{const{deviceId:N,windowId:_e,paneId:ne}=P.detail;N===t&&(c.current={windowId:_e,paneId:ne})};return window.addEventListener("tmex:user-initiated-selection",g),()=>{window.removeEventListener("tmex:user-initiated-selection",g)}},[t]),w.useEffect(()=>{W(ie)},[ie]);const As=w.useCallback(g=>{if(!t||!v||!Ne)return;Ae.getState().sendInput(t,v,g,!1)},[Ne,t,v]),Hn=w.useCallback(()=>{if(!Ne){wi.error(e("wsError.checkGateway"));return}if(!t||!v||!O.trim())return;R(!0),window.setTimeout(()=>R(!1),150);const g=j?`${O}\r`:O;Ae.getState().sendInput(t,v,g,!1),le(O),A&&J(A),W("")},[le,Ne,t,A,j,O,J,v,e]),zn=w.useCallback(()=>{if(!Ne){wi.error(e("wsError.checkGateway"));return}if(!t||!v||!O.trim())return;R(!0),window.setTimeout(()=>R(!1),150);const g=O.split(/\r?\n/),P=Ae.getState();for(const N of g)N.trim()&&P.sendInput(t,v,`${N}\r`,!1);le(O),A&&J(A),W("")},[le,Ne,t,A,O,J,v,e]),Fn=w.useCallback(g=>{if(V(!0),!(T&&Z))return;const P=g.currentTarget;window.requestAnimationFrame(()=>{P.scrollIntoView({block:"nearest",inline:"nearest"})}),window.setTimeout(()=>{window.scrollTo(0,1)},60)},[Z,T]),Wn=w.useCallback(()=>{V(!1)},[]),$n=w.useCallback(()=>{var g;(g=l.current)==null||g.focus({preventScroll:!0})},[]);if(!t)return B.jsx("div",{className:"flex h-full items-center justify-center p-4",children:B.jsx("div",{className:"rounded-lg border border-dashed border-border px-4 py-3 text-sm text-muted-foreground",children:e("device.noDevices")})});const Kn=!p&&!f;return B.jsxs("div",{className:"flex h-full min-h-0 flex-col bg-background","data-testid":"device-page",children:[B.jsxs("div",{className:`flex-1 relative overflow-hidden min-h-0 min-w-0 ${T&&M==="editor"&&!ee?"pb-1":""}`,style:{paddingBottom:ee?`${m+60}px`:void 0},children:[B.jsx("div",{className:"h-full px-3 py-1 min-h-0 min-w-0 w-full relative flex rounded-xl",style:{backgroundColor:tt.background},children:p&&v?B.jsx("div",{ref:n,className:"flex-1 w-full",children:B.jsx(An,{ref:h,deviceId:t,paneId:v,theme:x,inputMode:M,deviceConnected:p,isSelectionInvalid:Ts,onResize:On,onSync:Nn},`${t}:${v}`)}):B.jsx("div",{className:"absolute inset-0 flex flex-col items-center justify-center p-8 text-center",children:B.jsx("div",{className:"max-w-sm space-y-4",children:p?i?B.jsxs(B.Fragment,{children:[B.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:B.jsx(bi,{className:"h-6 w-6 text-muted-foreground animate-spin"})}),B.jsx("h3",{className:"text-lg font-medium",children:e("terminal.connecting")})]}):B.jsxs(B.Fragment,{children:[B.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:B.jsx("span",{className:"text-2xl text-muted-foreground",children:"📋"})}),B.jsx("h3",{className:"text-lg font-medium",children:e("window.noWindowSelected")}),B.jsx("p",{className:"text-sm text-muted-foreground",children:e("window.selectWindowToStart")})]}):B.jsxs(B.Fragment,{children:[B.jsx("div",{className:"h-12 w-12 rounded-full bg-muted flex items-center justify-center mx-auto",children:B.jsx("span",{className:"text-2xl text-muted-foreground",children:"🔌"})}),B.jsx("h3",{className:"text-lg font-medium",children:e("device.disconnected")}),B.jsx("p",{className:"text-sm text-muted-foreground",children:e("device.connectToStart")})]})})})}),Kn&&B.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-background/85 backdrop-blur-sm","data-testid":"terminal-status-overlay",children:B.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:[B.jsx("div",{className:"h-7 w-7 rounded-full border-2 border-primary border-t-transparent animate-spin"}),B.jsx("span",{className:"text-xs text-muted-foreground","data-testid":"terminal-status-text",children:e("terminal.connecting")})]})})]}),M==="direct"&&B.jsx("div",{className:"",children:B.jsx(Or,{onSend:As,disabled:!Ne,isMobile:T,inputMode:M})}),M==="editor"&&B.jsxs("div",{ref:o,className:`editor-mode-input bg-card/85 backdrop-blur-sm ${ee?"fixed left-0 right-0 z-50":""}`,style:ee?{bottom:`${F}px`}:void 0,children:[T&&B.jsx(Or,{onSend:As,onFocusEditor:$n,disabled:!Ne,isMobile:T,inputMode:M}),B.jsx("textarea",{ref:l,"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:O,onChange:g=>{const P=g.target.value;if(W(P),!!A){if(P){Ee(A,P);return}J(A)}},placeholder:e("terminal.inputPlaceholder"),onFocus:Fn,onBlur:Wn,onCompositionStart:()=>{I.current=!0},onCompositionEnd:()=>{I.current=!1}}),B.jsx("div",{className:"actions mt-2",children:B.jsxs("div",{className:"send-row flex flex-wrap items-center justify-end gap-2","data-testid":"editor-send-row",children:[B.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:[B.jsx(no,{size:"sm",checked:j,onCheckedChange:g=>G(!!g)}),B.jsx("span",{children:e("terminal.editorSendWithEnter")})]}),B.jsxs(_t,{variant:"outline",size:"sm","data-testid":"editor-clear",onPointerDown:g=>g.preventDefault(),onClick:()=>{var g;W(""),A&&J(A),T&&M==="editor"&&((g=l.current)==null||g.focus({preventScroll:!0}))},title:e("terminal.clear"),children:[B.jsx(Gn,{className:"h-4 w-4"}),e("terminal.clear")]}),B.jsxs(_t,{variant:"secondary",size:"sm","data-testid":"editor-send-line-by-line",onPointerDown:g=>g.preventDefault(),onClick:()=>{var g;zn(),T&&M==="editor"&&((g=l.current)==null||g.focus({preventScroll:!0}))},disabled:!Ne||E,children:[E?B.jsx(bi,{className:"h-4 w-4 animate-spin"}):B.jsx(Ns,{className:"h-4 w-4"}),e("terminal.editorSendLineByLine")]}),B.jsxs(_t,{variant:"default",size:"sm","data-testid":"editor-send",onPointerDown:g=>g.preventDefault(),onClick:()=>{var g;Hn(),T&&M==="editor"&&((g=l.current)==null||g.focus({preventScroll:!0}))},disabled:!Ne||E,children:[E?B.jsx(bi,{className:"h-4 w-4 animate-spin"}):B.jsx(Ns,{className:"h-4 w-4"}),e("common.send")]})]})})]})]})}function jh(){const{deviceId:e,windowId:t,paneId:i}=ws(),s=i?bs(i):void 0,r=Ae(d=>d.snapshots),n=Ss(d=>{var c;return((c=d.settings)==null?void 0:c.siteName)??"tmex"}),o=e?r[e]:void 0,l=w.useMemo(()=>{var d;if(!(!t||!((d=o==null?void 0:o.session)!=null&&d.windows)))return o.session.windows.find(c=>c.id===t)},[t,o]),h=w.useMemo(()=>{if(!(!s||!l))return l.panes.find(d=>d.id===s)},[s,l]),a=w.useMemo(()=>l&&h?In({paneIdx:h.index,windowIdx:l.index,paneTitle:h.title,windowName:l.name,deviceName:n}):e??"",[l,h,n,e]);return B.jsx(B.Fragment,{children:a})}function Vh(){const{t:e}=Fr(),{deviceId:t,paneId:i}=ws(),s=i?bs(i):void 0,r=Ve(f=>f.inputMode),n=Ve(f=>f.setInputMode),o=Ae(f=>{var p;return t?((p=f.deviceConnected)==null?void 0:p[t])??!1:!1}),[l,h]=w.useState(!1),a=!!(s&&o),d=()=>{n(r==="direct"?"editor":"direct")},c=()=>{window.dispatchEvent(new CustomEvent("tmex:jump-to-latest"))},_=()=>{h(!0)},u=()=>{window.location.reload()};return B.jsxs(B.Fragment,{children:[B.jsx(_t,{variant:"ghost",size:"icon-sm",onClick:_,"aria-label":e("nav.refreshPage"),title:e("nav.refreshPage"),children:B.jsx(uo,{className:"h-4 w-4"})}),B.jsx(_t,{variant:"ghost",size:"icon-sm",onClick:d,disabled:!a,"data-testid":"terminal-input-mode-toggle","aria-label":e(r==="direct"?"nav.switchToEditor":"nav.switchToDirect"),title:e(r==="direct"?"nav.switchToEditor":"nav.switchToDirect"),children:r==="direct"?B.jsx(ho,{className:"h-4 w-4"}):B.jsx(fo,{className:"h-4 w-4"})}),B.jsx(_t,{variant:"ghost",size:"icon-sm",onClick:c,disabled:!a,"aria-label":e("nav.jumpToLatest"),title:e("nav.jumpToLatest"),children:B.jsx(ao,{className:"h-4 w-4"})}),B.jsx(Jn,{open:l,onOpenChange:h,children:B.jsxs(Zn,{children:[B.jsxs(Qn,{children:[B.jsx(eo,{children:e("nav.refreshPage")}),B.jsx(to,{children:e("nav.refreshPageConfirm")})]}),B.jsxs(io,{children:[B.jsx(so,{onClick:()=>h(!1),children:e("common.cancel")}),B.jsx(ro,{onClick:u,children:e("common.confirm")})]})]})})]})}export{Vh as PageActions,jh as PageTitle,qh as default};
267
+ //# sourceMappingURL=DevicePage-DDl0kHG5.js.map