mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-12-14 08:06:22 +00:00
Update script-terminal-modal.tsx
This commit is contained in:
@@ -6,7 +6,16 @@ import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog"
|
|||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { Input } from "@/components/ui/input"
|
import { Input } from "@/components/ui/input"
|
||||||
import { Label } from "@/components/ui/label"
|
import { Label } from "@/components/ui/label"
|
||||||
import { Loader2, Activity, GripHorizontal } from "lucide-react"
|
import {
|
||||||
|
Loader2,
|
||||||
|
Activity,
|
||||||
|
GripHorizontal,
|
||||||
|
ArrowUp,
|
||||||
|
ArrowDown,
|
||||||
|
ArrowLeft,
|
||||||
|
ArrowRight,
|
||||||
|
CornerDownLeft,
|
||||||
|
} from "lucide-react"
|
||||||
import "xterm/css/xterm.css"
|
import "xterm/css/xterm.css"
|
||||||
import { API_PORT } from "@/lib/api-config"
|
import { API_PORT } from "@/lib/api-config"
|
||||||
|
|
||||||
@@ -407,13 +416,11 @@ export function ScriptTerminalModal({
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
|
||||||
setIsResizing(true)
|
const startY = "touches" in e ? e.touches[0].clientY : e.clientY
|
||||||
const startY = "clientY" in e ? e.clientY : e.touches[0].clientY
|
|
||||||
const startHeight = modalHeight
|
const startHeight = modalHeight
|
||||||
|
|
||||||
const handleMove = (moveEvent: MouseEvent | TouchEvent) => {
|
const handleMove = (moveEvent: MouseEvent | TouchEvent) => {
|
||||||
moveEvent.preventDefault()
|
const currentY = "touches" in moveEvent ? moveEvent.touches[0].clientY : moveEvent.clientY
|
||||||
const currentY = moveEvent instanceof MouseEvent ? moveEvent.clientY : moveEvent.touches[0].clientY
|
|
||||||
const deltaY = currentY - startY
|
const deltaY = currentY - startY
|
||||||
const newHeight = Math.max(300, Math.min(2400, startHeight + deltaY))
|
const newHeight = Math.max(300, Math.min(2400, startHeight + deltaY))
|
||||||
|
|
||||||
@@ -436,51 +443,26 @@ export function ScriptTerminalModal({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleEnd = () => {
|
const handleEnd = () => {
|
||||||
setIsResizing(false)
|
document.removeEventListener("mousemove", handleMove as any)
|
||||||
|
|
||||||
localStorage.setItem("scriptModalHeight", modalHeight.toString())
|
|
||||||
|
|
||||||
if (fitAddonRef.current && termRef.current && wsRef.current?.readyState === WebSocket.OPEN) {
|
|
||||||
setTimeout(() => {
|
|
||||||
if (fitAddonRef.current && termRef.current) {
|
|
||||||
fitAddonRef.current.fit()
|
|
||||||
wsRef.current?.send(
|
|
||||||
JSON.stringify({
|
|
||||||
type: "resize",
|
|
||||||
cols: termRef.current.cols,
|
|
||||||
rows: termRef.current.rows,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}, 50)
|
|
||||||
}
|
|
||||||
|
|
||||||
document.removeEventListener("mousemove", handleMove)
|
|
||||||
document.removeEventListener("touchmove", handleMove)
|
|
||||||
document.removeEventListener("mouseup", handleEnd)
|
document.removeEventListener("mouseup", handleEnd)
|
||||||
|
document.removeEventListener("touchmove", handleMove as any)
|
||||||
document.removeEventListener("touchend", handleEnd)
|
document.removeEventListener("touchend", handleEnd)
|
||||||
|
|
||||||
resizeHandlersRef.current = {
|
localStorage.setItem("scriptModalHeight", modalHeight.toString())
|
||||||
handleMouseMove: null,
|
|
||||||
handleMouseUp: null,
|
|
||||||
handleTouchMove: null,
|
|
||||||
handleTouchEnd: null,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resizeHandlersRef.current = {
|
|
||||||
handleMouseMove: handleMove as any,
|
|
||||||
handleMouseUp: handleEnd,
|
|
||||||
handleTouchMove: handleMove as any,
|
|
||||||
handleTouchEnd: handleEnd,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("mousemove", handleMove as any)
|
document.addEventListener("mousemove", handleMove as any)
|
||||||
document.addEventListener("touchmove", handleMove as any, { passive: false })
|
|
||||||
document.addEventListener("mouseup", handleEnd)
|
document.addEventListener("mouseup", handleEnd)
|
||||||
|
document.addEventListener("touchmove", handleMove as any, { passive: false })
|
||||||
document.addEventListener("touchend", handleEnd)
|
document.addEventListener("touchend", handleEnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sendCommand = (command: string) => {
|
||||||
|
if (wsRef.current?.readyState === WebSocket.OPEN) {
|
||||||
|
wsRef.current.send(JSON.stringify({ type: "input", data: command }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Dialog open={isOpen} onOpenChange={onClose}>
|
<Dialog open={isOpen} onOpenChange={onClose}>
|
||||||
@@ -512,90 +494,118 @@ export function ScriptTerminalModal({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{(isTablet || (!isMobile && !isTablet)) && (
|
|
||||||
<div
|
|
||||||
className={`h-2 cursor-ns-resize flex items-center justify-center transition-all duration-150 ${
|
|
||||||
isResizing ? "bg-blue-500 h-3" : "bg-zinc-800 hover:bg-blue-500/50"
|
|
||||||
}`}
|
|
||||||
onMouseDown={handleResizeStart}
|
|
||||||
onTouchStart={handleResizeStart}
|
|
||||||
style={{ touchAction: "none" }}
|
|
||||||
>
|
|
||||||
<GripHorizontal
|
|
||||||
className={`h-4 w-4 transition-all duration-150 ${isResizing ? "text-white scale-110" : "text-zinc-500"}`}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{(isMobile || isTablet) && (
|
{(isMobile || isTablet) && (
|
||||||
<div className="flex flex-wrap gap-1.5 justify-center items-center px-1 bg-zinc-900 text-sm rounded-b-md border-t border-zinc-700 py-1.5">
|
<div className="flex flex-wrap gap-1.5 justify-center items-center px-1 bg-zinc-900 text-sm rounded-b-md border-t border-zinc-700 py-1.5">
|
||||||
<Button
|
<Button
|
||||||
onClick={() => sendKey("escape")}
|
onPointerDown={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
sendCommand("\x1b")
|
||||||
|
}}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="px-2.5 py-2 text-xs h-9 bg-zinc-800 hover:bg-zinc-700 border-zinc-700"
|
className="h-8 px-2.5 text-xs bg-zinc-800 hover:bg-zinc-700 border-zinc-700 text-white min-w-[60px]"
|
||||||
>
|
>
|
||||||
ESC
|
ESC
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => sendKey("tab")}
|
onPointerDown={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
sendCommand("\t")
|
||||||
|
}}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="px-2.5 py-2 text-xs h-9 bg-zinc-800 hover:bg-zinc-700 border-zinc-700"
|
className="h-8 px-2.5 text-xs bg-zinc-800 hover:bg-zinc-700 border-zinc-700 text-white min-w-[60px]"
|
||||||
>
|
>
|
||||||
TAB
|
TAB
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => sendKey("up")}
|
onPointerDown={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
sendCommand("\x1b[A")
|
||||||
|
}}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="px-3 py-2 text-base h-9 bg-zinc-800 hover:bg-zinc-700 border-zinc-700"
|
className="h-8 px-2.5 text-xs bg-zinc-800 hover:bg-zinc-700 border-zinc-700 text-white"
|
||||||
>
|
>
|
||||||
↑
|
<ArrowUp className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => sendKey("down")}
|
onPointerDown={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
sendCommand("\x1b[B")
|
||||||
|
}}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="px-3 py-2 text-base h-9 bg-zinc-800 hover:bg-zinc-700 border-zinc-700"
|
className="h-8 px-2.5 text-xs bg-zinc-800 hover:bg-zinc-700 border-zinc-700 text-white"
|
||||||
>
|
>
|
||||||
↓
|
<ArrowDown className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => sendKey("left")}
|
onPointerDown={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
sendCommand("\x1b[D")
|
||||||
|
}}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="px-3 py-2 text-base h-9 bg-zinc-800 hover:bg-zinc-700 border-zinc-700"
|
className="h-8 px-2.5 text-xs bg-zinc-800 hover:bg-zinc-700 border-zinc-700 text-white"
|
||||||
>
|
>
|
||||||
←
|
<ArrowLeft className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => sendKey("right")}
|
onPointerDown={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
sendCommand("\x1b[C")
|
||||||
|
}}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="px-3 py-2 text-base h-9 bg-zinc-800 hover:bg-zinc-700 border-zinc-700"
|
className="h-8 px-2.5 text-xs bg-zinc-800 hover:bg-zinc-700 border-zinc-700 text-white"
|
||||||
>
|
>
|
||||||
→
|
<ArrowRight className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => sendKey("enter")}
|
onPointerDown={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
sendCommand("\r")
|
||||||
|
}}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="px-3 py-2 text-base h-9 bg-zinc-800 hover:bg-zinc-700 border-zinc-700"
|
className="h-8 px-2.5 text-xs bg-zinc-800 hover:bg-zinc-700 border-zinc-700 text-white"
|
||||||
>
|
>
|
||||||
↵
|
<CornerDownLeft className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
onClick={() => sendKey("ctrlc")}
|
onPointerDown={(e) => {
|
||||||
|
e.preventDefault()
|
||||||
|
e.stopPropagation()
|
||||||
|
sendCommand("\x03")
|
||||||
|
}}
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="px-2 py-2 text-xs h-9 bg-zinc-800 hover:bg-zinc-700 border-zinc-700"
|
className="h-8 px-2.5 text-xs bg-zinc-800 hover:bg-zinc-700 border-zinc-700 text-white min-w-[75px]"
|
||||||
>
|
>
|
||||||
CTRL+C
|
CTRL+C
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{(isTablet || (!isMobile && !isTablet)) && (
|
||||||
|
<div
|
||||||
|
onMouseDown={handleResizeStart}
|
||||||
|
onTouchStart={handleResizeStart}
|
||||||
|
className="h-2 w-full cursor-row-resize bg-zinc-800 hover:bg-blue-600 transition-colors flex items-center justify-center group relative"
|
||||||
|
style={{ touchAction: "none" }}
|
||||||
|
>
|
||||||
|
<GripHorizontal className="h-4 w-4 text-zinc-600 group-hover:text-white pointer-events-none" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="flex items-center justify-between p-4 border-t">
|
<div className="flex items-center justify-between p-4 border-t">
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<Activity className="h-5 w-5 text-blue-500" />
|
<Activity className="h-5 w-5 text-blue-500" />
|
||||||
|
|||||||
Reference in New Issue
Block a user