| import { useRef } from "react"; | |
| import { Rnd } from "react-rnd"; | |
| import { useWindowStore } from "../store/windowStore"; | |
| import { X, Minus, Square } from "lucide-react"; | |
| export function DockableWindow({ | |
| window: win, | |
| children, | |
| }: { | |
| window: any; | |
| children: React.ReactNode; | |
| }) { | |
| const { | |
| updateWindow, | |
| bringToFront, | |
| toggleMinimize, | |
| toggleMaximize, | |
| removeWindow, | |
| } = useWindowStore(); | |
| const rndRef = useRef<any>(); | |
| const { windows } = useWindowStore(); | |
| const minimizedWindows = windows.filter((w) => w.minimized); | |
| const displayTitle = | |
| typeof win.title === "string" | |
| ? win.title | |
| : typeof win.type === "string" | |
| ? win.type.charAt(0).toUpperCase() + win.type.slice(1).replace(/-/g, " ") | |
| : "Window"; | |
| const displayIcon = typeof win.icon === "string" ? win.icon : "▣"; | |
| if (win.minimized) { | |
| const minIdx = minimizedWindows.findIndex((w) => w.id === win.id); | |
| const offsetLeft = 16 + minIdx * 160; // 160px spacing for each item | |
| return ( | |
| <div | |
| className="fixed bottom-4 z-50 glass-terminal px-3 py-1.5 rounded cursor-pointer text-sm font-mono flex items-center justify-between gap-2 border border-white/10 hover:border-neon-mint/50 w-[150px] shadow-lg select-none" | |
| onClick={() => toggleMinimize(win.id)} | |
| style={{ left: `${offsetLeft}px` }} | |
| > | |
| <span className="truncate flex items-center gap-1.5"> | |
| <span>{displayIcon}</span> | |
| <span className="truncate">{displayTitle}</span> | |
| </span> | |
| <button | |
| onClick={(e) => { | |
| e.stopPropagation(); | |
| removeWindow(win.id); | |
| }} | |
| className="w-4 h-4 rounded-full flex items-center justify-center hover:bg-red-500/30 text-slate-400 hover:text-red-400 text-[10px]" | |
| title="Close" | |
| > | |
| ✕ | |
| </button> | |
| </div> | |
| ); | |
| } | |
| const rndProps: any = win.maximized | |
| ? { | |
| position: { x: 0, y: 0 }, | |
| size: { width: "100%", height: "100%" }, | |
| disableDragging: true, | |
| enableResizing: false, | |
| style: { position: "fixed", top: 0, left: 0, zIndex: win.zIndex }, | |
| } | |
| : { | |
| position: { x: win.x, y: win.y }, | |
| size: { width: win.width, height: win.height }, | |
| onDragStop: (e, d) => updateWindow(win.id, { x: d.x, y: d.y }), | |
| onResizeStop: (e, dir, ref, delta, pos) => | |
| updateWindow(win.id, { | |
| width: ref.offsetWidth, | |
| height: ref.offsetHeight, | |
| x: pos.x, | |
| y: pos.y, | |
| }), | |
| minWidth: 300, | |
| minHeight: 200, | |
| style: { zIndex: win.zIndex }, | |
| }; | |
| return ( | |
| <Rnd | |
| ref={rndRef} | |
| {...rndProps} | |
| dragHandleClassName="window-drag-handle" | |
| className="glass-terminal flex flex-col overflow-hidden" | |
| onMouseDown={() => bringToFront(win.id)} | |
| > | |
| <div className="window-drag-handle flex items-center justify-between bg-black/40 px-3 py-2 cursor-move border-b border-white/10"> | |
| <div className="flex items-center gap-2 text-sm font-mono text-neon-mint"> | |
| {displayIcon && <span>{displayIcon}</span>} | |
| <span>{displayTitle}</span> | |
| </div> | |
| <div className="flex gap-1"> | |
| <button | |
| onClick={() => toggleMinimize(win.id)} | |
| className="p-1 hover:bg-white/10 rounded" | |
| > | |
| <Minus size={14} /> | |
| </button> | |
| <button | |
| onClick={() => toggleMaximize(win.id)} | |
| className="p-1 hover:bg-white/10 rounded" | |
| > | |
| <Square size={14} /> | |
| </button> | |
| <button | |
| onClick={() => removeWindow(win.id)} | |
| className="p-1 hover:bg-red-500/20 rounded" | |
| > | |
| <X size={14} /> | |
| </button> | |
| </div> | |
| </div> | |
| <div className="flex-1 overflow-auto bg-black/20">{children}</div> | |
| </Rnd> | |
| ); | |
| } | |
Xet Storage Details
- Size:
- 3.91 kB
- Xet hash:
- bb56d7924acb120bbd992ab583ca710100eb4456efc89800042babd72ce63e7e
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.