| 1 | "use client"; |
| 2 | |
| 3 | import { useState, useEffect |
| 4 | import { use } |
| 5 | import { useRouter } |
| 6 | import { useQuery } |
| 7 | import Editor from "@monaco-editor/react |
| 8 | import { |
| 9 | ChevronRight, |
| 10 | Folder, |
| 11 | FolderOpen, |
| 12 | File, |
| 13 | FileCode2, |
| 14 | FileImage, |
| 15 | Save, |
| 16 | ChevronLeft, |
| 17 | Plus, |
| 18 | Upload, |
| 19 | X, |
| 20 | Pencil, |
| 21 | Trash2, |
| 22 | MoreHorizontal, |
| 23 | Archive, |
| 24 | PackageOpen, |
| 25 | Download, |
| 26 | Loader2, |
| 27 | } from "lucide-react"; |
| 28 | import type { Monaco |
| 29 | import { useTranslations } |
| 30 | import { orpc } |
| 31 | import { authClient } |
| 32 | import Loader from "@/components/loader |
| 33 | import { ConfirmDialog } |
| 34 | import { |
| 35 | DropdownMenu, |
| 36 | DropdownMenuTrigger, |
| 37 | DropdownMenuContent, |
| 38 | DropdownMenuItem, |
| 39 | } from "@struxa/ui/components/dropdown-menu"; |
| 40 | import { Checkbox } |
| 41 | import { Button } |
| 42 | import { Input } |
| 43 | import { Label } |
| 44 | import { |
| 45 | Select, |
| 46 | SelectTrigger, |
| 47 | SelectValue, |
| 48 | SelectContent, |
| 49 | SelectItem, |
| 50 | } from "@struxa/ui/components/select"; |
| 51 | import { |
| 52 | Dialog, |
| 53 | DialogClose, |
| 54 | DialogPopup, |
| 55 | DialogHeader, |
| 56 | DialogFooter, |
| 57 | DialogTitle, |
| 58 | DialogDescription, |
| 59 | } from "@struxa/ui/components/dialog"; |
| 60 | |
| 61 | interface WingsFile { |
| 62 | name: string; |
| 63 | size: number; |
| 64 | file: boolean; |
| 65 | directory: boolean; |
| 66 | symlink: boolean; |
| 67 | mime?: string |
| 68 | editable?: boolean |
| 69 | } |
| 70 | |
| 71 | function defineTheme(monaco: |
| 72 | monaco.editor.defineTheme |
| 73 | base: "vs-dark", |
| 74 | inherit: true, |
| 75 | rules: [ |
| 76 | { token: "", foreground |
| 77 | { token: "comment", |
| 78 | { token: "string", |
| 79 | { token: "keyword", |
| 80 | { token: "number", |
| 81 | { token: "type", |
| 82 | { token: "variable", |
| 83 | ], |
| 84 | colors: { |
| 85 | "editor.background": "#0a0a0a", |
| 86 | "editor.foreground": "#aaaaaa", |
| 87 | "editorLineNumber.foreground": "#333333", |
| 88 | "editorLineNumber.activeForeground": "#555555", |
| 89 | "editor.selectionBackground": "#3b82f622", |
| 90 | "editor.lineHighlightBackground": "#171717", |
| 91 | "editorCursor.foreground": "#3b82f6", |
| 92 | "editorGutter.background": "#0a0a0a", |
| 93 | "editor.inactiveSelectionBackground": "#171717", |
| 94 | "editorWidget.background": "#171717", |
| 95 | "editorWidget.border": "#262626", |
| 96 | "input.background": "#171717", |
| 97 | "input.border": "#262626", |
| 98 | "scrollbarSlider.background": "#262626", |
| 99 | "scrollbarSlider.hoverBackground": "#333333", |
| 100 | "editorBracketMatch.background": "#3b82f622", |
| 101 | "editorBracketMatch.border": "#3b82f644", |
| 102 | }, |
| 103 | }); |
| 104 | } |
| 105 | |
| 106 | function getLanguage(filename: |
| 107 | const ext = |
| 108 | const map: |
| 109 | json: "json", yml |
| 110 | js: "javascript", ts |
| 111 | java: "java", sh |
| 112 | xml: "xml", html |
| 113 | sql: "sql", properties |
| 114 | toml: "ini", log |
| 115 | }; |
| 116 | return map[ext |
| 117 | } |
| 118 | |
| 119 | function fmtBytes(bytes: |
| 120 | if (bytes < |
| 121 | if (bytes < |
| 122 | return `${(bytes |
| 123 | } |
| 124 | |
| 125 | function isText(file: |
| 126 | const mime = |
| 127 | if (mime.startsWith |
| 128 | const ext = |
| 129 | return ["txt", |
| 130 | } |
| 131 | |
| 132 | function isImage(file: |
| 133 | return (file.mime |
| 134 | } |
| 135 | |
| 136 | function isArchiveFile(name: |
| 137 | return /\.(tar |
| 138 | } |
| 139 | |
| 140 | function stripArchiveExt(name: |
| 141 | return name.replace |
| 142 | } |
| 143 | |
| 144 | const ARCHIVE_FORMATS = [ |
| 145 | { value: "tar_gz", |
| 146 | { value: "zip", |
| 147 | { value: "tar_xz", |
| 148 | { value: "tar_bz2", |
| 149 | { value: "tar_zstd", |
| 150 | { value: "seven_zip", |
| 151 | { value: "tar", |
| 152 | ] as const; |
| 153 | |
| 154 | const ARCHIVE_FORMAT_ITEMS = ARCHIVE_FORMATS |
| 155 | |
| 156 | function FileIcon({ file |
| 157 | if (file.directory |
| 158 | if (isImage(file |
| 159 | if (isText(file |
| 160 | return <File className |
| 161 | } |
| 162 | |
| 163 | export default function FilesPage |
| 164 | const t = |
| 165 | const router = |
| 166 | const { data: |
| 167 | const { id |
| 168 | |
| 169 | useEffect(() => |
| 170 | if (!isPending && |
| 171 | }, [isPending, |
| 172 | |
| 173 | const [dirPath, |
| 174 | const [entries, |
| 175 | const [loadingDir, |
| 176 | const [selectedFile, |
| 177 | const [openFilePath, |
| 178 | const [editContent, |
| 179 | const [unsaved, |
| 180 | const [saving, |
| 181 | const [showNewFile, |
| 182 | const [newFileName, |
| 183 | const [uploading, |
| 184 | const [isDragging, |
| 185 | const [renamingPath, |
| 186 | const [renameValue, |
| 187 | const [selected, |
| 188 | const [busyAction, |
| 189 | const [archiveDialog, |
| 190 | const [deleteTarget, |
| 191 | const [deleting, |
| 192 | const uploadInputRef = |
| 193 | const newFileInputRef = |
| 194 | const handleSaveRef = |
| 195 | |
| 196 | const filesBase = |
| 197 | |
| 198 | const fetchDir = |
| 199 | setLoadingDir(true); |
| 200 | try { |
| 201 | const res = |
| 202 | `${filesBase}/list-directory?directory=${encodeURIComponent |
| 203 | ); |
| 204 | if (!res.ok |
| 205 | const raw = |
| 206 | const data = |
| 207 | const sorted = |
| 208 | if (a.file |
| 209 | return a.name |
| 210 | }); |
| 211 | setEntries(sorted); |
| 212 | setDirPath(dir); |
| 213 | setSelected(new Set |
| 214 | return sorted; |
| 215 | } finally { |
| 216 | setLoadingDir(false); |
| 217 | } |
| 218 | }, [filesBase]); |
| 219 | |
| 220 | useEffect(() => |
| 221 | void fetchDir("/" |
| 222 | }, [fetchDir]); |
| 223 | |
| 224 | async function openFile |
| 225 | const filePath = |
| 226 | if (!file.file |
| 227 | setSelectedFile(file); |
| 228 | setOpenFilePath(filePath); |
| 229 | setEditContent(""); |
| 230 | setUnsaved(false); |
| 231 | return; |
| 232 | } |
| 233 | const res = |
| 234 | `${filesBase}/contents?file=${encodeURIComponent |
| 235 | ); |
| 236 | const text = |
| 237 | setSelectedFile(file); |
| 238 | setOpenFilePath(filePath); |
| 239 | setEditContent(text); |
| 240 | setUnsaved(false); |
| 241 | } |
| 242 | |
| 243 | async function handleSave |
| 244 | if (!selectedFile || |
| 245 | const filePath = |
| 246 | setSaving(true); |
| 247 | try { |
| 248 | await fetch( |
| 249 | `${filesBase}/write?file=${encodeURIComponent |
| 250 | { |
| 251 | method: "POST", |
| 252 | headers: { "Content-Type": |
| 253 | body: editContent, |
| 254 | }, |
| 255 | ); |
| 256 | setUnsaved(false); |
| 257 | } finally { |
| 258 | setSaving(false); |
| 259 | } |
| 260 | } |
| 261 | handleSaveRef.current = |
| 262 | |
| 263 | async function createFile |
| 264 | const name = |
| 265 | if (!name) |
| 266 | const filePath = |
| 267 | await fetch( |
| 268 | `${filesBase}/write?file=${encodeURIComponent |
| 269 | { |
| 270 | method: "POST", |
| 271 | headers: { "Content-Type": |
| 272 | body: "", |
| 273 | }, |
| 274 | ); |
| 275 | setShowNewFile(false); |
| 276 | setNewFileName(""); |
| 277 | const refreshed = |
| 278 | const entry = |
| 279 | if (entry?.file |
| 280 | await openFile(entry |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | async function handleUpload |
| 285 | if (!files || |
| 286 | setUploading(true); |
| 287 | try { |
| 288 | await Promise.all |
| 289 | Array.from(files |
| 290 | const filePath = |
| 291 | const buffer = |
| 292 | await fetch( |
| 293 | `${filesBase}/write?file=${encodeURIComponent |
| 294 | { |
| 295 | method: "POST", |
| 296 | headers: { "Content-Type": |
| 297 | body: buffer, |
| 298 | }, |
| 299 | ); |
| 300 | }), |
| 301 | ); |
| 302 | await fetchDir(dirPath |
| 303 | } finally { |
| 304 | setUploading(false); |
| 305 | if (uploadInputRef.current |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | async function handleRename |
| 310 | const newName = |
| 311 | const oldName = |
| 312 | setRenamingPath(null); |
| 313 | if (!newName || |
| 314 | const parent = |
| 315 | const newPath = |
| 316 | const res = |
| 317 | `${filesBase}/rename`, |
| 318 | { |
| 319 | method: "PUT", |
| 320 | headers: { "Content-Type": |
| 321 | body: JSON.stringify |
| 322 | }, |
| 323 | ); |
| 324 | if (!res.ok |
| 325 | if (openFilePath === |
| 326 | setOpenFilePath(newPath); |
| 327 | setSelectedFile((f) |
| 328 | } |
| 329 | await fetchDir(dirPath |
| 330 | } |
| 331 | |
| 332 | async function handleDelete |
| 333 | setDeleting(true); |
| 334 | try { |
| 335 | const res = |
| 336 | `${filesBase}/delete`, |
| 337 | { |
| 338 | method: "POST", |
| 339 | headers: { "Content-Type": |
| 340 | body: JSON.stringify |
| 341 | }, |
| 342 | ); |
| 343 | if (!res.ok |
| 344 | if (openFilePath && |
| 345 | setSelectedFile(null); |
| 346 | setOpenFilePath(null); |
| 347 | setEditContent(""); |
| 348 | setUnsaved(false); |
| 349 | } |
| 350 | setSelected(new Set |
| 351 | await fetchDir(dirPath |
| 352 | } finally { |
| 353 | setDeleting(false); |
| 354 | setDeleteTarget(null); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | function toggleSelect(itemPath |
| 359 | setSelected((prev) |
| 360 | const next = |
| 361 | if (next.has |
| 362 | next.delete(itemPath |
| 363 | } else { |
| 364 | next.add(itemPath |
| 365 | } |
| 366 | return next; |
| 367 | }); |
| 368 | } |
| 369 | |
| 370 | function openArchiveDialog(paths |
| 371 | const single = |
| 372 | setArchiveDialog({ |
| 373 | paths, |
| 374 | name: single ? |
| 375 | format: "tar_gz", |
| 376 | }); |
| 377 | } |
| 378 | |
| 379 | function setArchiveFormat(format |
| 380 | setArchiveDialog((d) |
| 381 | if (!d) |
| 382 | const newExt = |
| 383 | const oldExt = |
| 384 | const name = |
| 385 | ? `${d.name |
| 386 | : d.name; |
| 387 | return { ...d |
| 388 | }); |
| 389 | } |
| 390 | |
| 391 | async function handleArchive |
| 392 | setBusyAction("archive"); |
| 393 | try { |
| 394 | const res = |
| 395 | `${filesBase}/compress`, |
| 396 | { |
| 397 | method: "POST", |
| 398 | headers: { "Content-Type": |
| 399 | body: JSON.stringify |
| 400 | root: dirPath, |
| 401 | files: paths.map |
| 402 | format, |
| 403 | ...(name?.trim |
| 404 | }), |
| 405 | }, |
| 406 | ); |
| 407 | if (!res.ok |
| 408 | setArchiveDialog(null); |
| 409 | setSelected(new Set |
| 410 | await fetchDir(dirPath |
| 411 | } finally { |
| 412 | setBusyAction(null); |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | async function handleUnarchive |
| 417 | const base = |
| 418 | const folder = |
| 419 | const parent = |
| 420 | const folderPath = |
| 421 | setBusyAction("unarchive"); |
| 422 | try { |
| 423 | const mk = |
| 424 | `${filesBase}/create-directory`, |
| 425 | { |
| 426 | method: "POST", |
| 427 | headers: { "Content-Type": |
| 428 | body: JSON.stringify |
| 429 | }, |
| 430 | ); |
| 431 | if (!mk.ok |
| 432 | const un = |
| 433 | `${filesBase}/decompress`, |
| 434 | { |
| 435 | method: "POST", |
| 436 | headers: { "Content-Type": |
| 437 | body: JSON.stringify |
| 438 | }, |
| 439 | ); |
| 440 | if (!un.ok |
| 441 | await fetch( |
| 442 | `${filesBase}/delete`, |
| 443 | { |
| 444 | method: "POST", |
| 445 | headers: { "Content-Type": |
| 446 | body: JSON.stringify |
| 447 | }, |
| 448 | ); |
| 449 | return; |
| 450 | } |
| 451 | await fetchDir(dirPath |
| 452 | } finally { |
| 453 | setBusyAction(null); |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | useEffect(() => |
| 458 | function onKeyDown(e |
| 459 | if ((e.ctrlKey |
| 460 | e.preventDefault(); |
| 461 | void handleSaveRef.current() |
| 462 | } |
| 463 | } |
| 464 | document.addEventListener("keydown |
| 465 | return () => |
| 466 | }, []); |
| 467 | |
| 468 | const { data: |
| 469 | |
| 470 | if (isPending || |
| 471 | |
| 472 | const pathSegments = |
| 473 | |
| 474 | function navigateUp() { |
| 475 | if (pathSegments.length |
| 476 | const parent = |
| 477 | void fetchDir(parent) |
| 478 | } |
| 479 | |
| 480 | function navigateInto(name |
| 481 | const next = |
| 482 | void fetchDir(next) |
| 483 | } |
| 484 | |
| 485 | return ( |
| 486 | <> |
| 487 | <div |
| 488 | className={`relative flex flex-1 flex-col gap-3 overflow-auto px-4 py-4 md:flex-row md:overflow-hidden${isDragging |
| 489 | onDragOver={(e) |
| 490 | onDragEnter={(e) |
| 491 | onDragLeave={(e) |
| 492 | onDrop={(e) |
| 493 | > |
| 494 | {isDragging && ( |
| 495 | <div className="pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-xl bg-background/80 backdrop-blur-sm |
| 496 | <div className="flex flex-col items-center gap-2 text-blue-500 |
| 497 | <Upload className=" |
| 498 | <span className="text-sm font-medium |
| 499 | </div> |
| 500 | </div> |
| 501 | )} |
| 502 | <div className="flex w-full shrink-0 flex-col overflow-hidden rounded-xl border border-border bg-card max-h-64 md:max-h-none md:w-60 |
| 503 | <div className="flex h-10 shrink-0 items-center justify-between border-b border-border px-3 |
| 504 | <span className="truncate font-mono text-[11px] text-muted-foreground |
| 505 | <div className="flex shrink-0 items-center gap-1 |
| 506 | <button |
| 507 | type="button" |
| 508 | title={t(" |
| 509 | onClick={() => |
| 510 | setShowNewFile(true); |
| 511 | setTimeout(() => |
| 512 | }} |
| 513 | className="rounded-md p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground" |
| 514 | > |
| 515 | <Plus className=" |
| 516 | </button> |
| 517 | <button |
| 518 | type="button" |
| 519 | title={t(" |
| 520 | disabled={uploading} |
| 521 | onClick={() => |
| 522 | className="rounded-md p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground disabled:opacity-40" |
| 523 | > |
| 524 | <Upload className=" |
| 525 | </button> |
| 526 | </div> |
| 527 | </div> |
| 528 | <input |
| 529 | ref={uploadInputRef} |
| 530 | type="file" |
| 531 | multiple |
| 532 | className="hidden" |
| 533 | onChange={(e) |
| 534 | /> |
| 535 | {showNewFile && ( |
| 536 | <div className="flex items-center gap-1 border-b border-border px-2 py-1.5 |
| 537 | <Plus className=" |
| 538 | <input |
| 539 | ref={newFileInputRef} |
| 540 | type="text" |
| 541 | value={newFileName} |
| 542 | onChange={(e) |
| 543 | onKeyDown={(e) |
| 544 | if (e.key |
| 545 | if (e.key |
| 546 | }} |
| 547 | placeholder="filename.ext" |
| 548 | className="flex-1 bg-transparent font-mono text-xs text-foreground placeholder:text-muted-foreground outline-none" |
| 549 | /> |
| 550 | <button |
| 551 | type="button" |
| 552 | onClick={() => |
| 553 | className="text-muted-foreground hover:text-foreground" |
| 554 | > |
| 555 | <X className=" |
| 556 | </button> |
| 557 | </div> |
| 558 | )} |
| 559 | {selected.size > |
| 560 | <div className="flex items-center justify-between border-b border-border bg-muted/40 px-2 py-1.5 |
| 561 | <span className="text-[11px] font-medium text-foreground |
| 562 | <div className="flex shrink-0 items-center gap-0.5 |
| 563 | <button |
| 564 | type="button" |
| 565 | title={t(" |
| 566 | disabled={busyAction !== |
| 567 | onClick={() => |
| 568 | className="rounded-md p-1 text-muted-foreground transition-colors hover:bg-background hover:text-foreground disabled:opacity-40" |
| 569 | > |
| 570 | {busyAction === "archive |
| 571 | </button> |
| 572 | <button |
| 573 | type="button" |
| 574 | title={t(" |
| 575 | disabled={deleting} |
| 576 | onClick={() => |
| 577 | className="rounded-md p-1 text-muted-foreground transition-colors hover:bg-background hover:text-destructive disabled:opacity-40" |
| 578 | > |
| 579 | <Trash2 className=" |
| 580 | </button> |
| 581 | <button |
| 582 | type="button" |
| 583 | title={t(" |
| 584 | onClick={() => |
| 585 | className="rounded-md p-1 text-muted-foreground transition-colors hover:bg-background hover:text-foreground" |
| 586 | > |
| 587 | <X className=" |
| 588 | </button> |
| 589 | </div> |
| 590 | </div> |
| 591 | )} |
| 592 | <div className="flex-1 overflow-y-auto py-1 |
| 593 | {pathSegments.length > |
| 594 | <button |
| 595 | type="button" |
| 596 | onClick={navigateUp} |
| 597 | className="flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-muted-foreground transition-colors hover:bg-muted hover:text-foreground" |
| 598 | > |
| 599 | <ChevronLeft className=" |
| 600 | <span className="font-mono |
| 601 | </button> |
| 602 | )} |
| 603 | {loadingDir ? ( |
| 604 | <div className="px-3 py-4 text-xs text-muted-foreground |
| 605 | ) : ( |
| 606 | entries.map((file |
| 607 | const itemPath = |
| 608 | if (renamingPath === itemPath |
| 609 | return ( |
| 610 | <div key={file |
| 611 | <FileIcon file={ |
| 612 | <input |
| 613 | autoFocus |
| 614 | type="text" |
| 615 | value={renameValue} |
| 616 | onChange={(e) |
| 617 | onKeyDown={(e) |
| 618 | if (e.key |
| 619 | if (e.key |
| 620 | }} |
| 621 | onBlur={() => |
| 622 | className="flex-1 bg-transparent font-mono text-xs text-foreground outline-none" |
| 623 | /> |
| 624 | </div> |
| 625 | ); |
| 626 | } |
| 627 | return ( |
| 628 | <div |
| 629 | key={file.name |
| 630 | role="button" |
| 631 | tabIndex={0} |
| 632 | onClick={() => |
| 633 | if (file.directory) |
| 634 | navigateInto(file.name |
| 635 | } else { |
| 636 | void openFile(file) |
| 637 | } |
| 638 | }} |
| 639 | onKeyDown={(e) |
| 640 | if (e.key |
| 641 | e.preventDefault(); |
| 642 | if (file.directory) |
| 643 | navigateInto(file.name |
| 644 | } else { |
| 645 | void openFile(file) |
| 646 | } |
| 647 | } |
| 648 | }} |
| 649 | className={`group flex w-full cursor-pointer items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors hover:bg-muted ${ |
| 650 | openFilePath === itemPath |
| 651 | }`} |
| 652 | > |
| 653 | <Checkbox |
| 654 | className={`size-3.5 shrink-0 rounded-sm [&>svg]:size-3 ${selected |
| 655 | checked={selected.has |
| 656 | onClick={(e) |
| 657 | onCheckedChange={() => |
| 658 | /> |
| 659 | <FileIcon file={ |
| 660 | <span className="flex-1 truncate font-mono |
| 661 | {file.directory && |
| 662 | <ChevronRight className=" |
| 663 | )} |
| 664 | {file.file && |
| 665 | <span className="shrink-0 text-[10px] text-muted-foreground/60 |
| 666 | )} |
| 667 | <DropdownMenu> |
| 668 | <DropdownMenuTrigger |
| 669 | title={t(" |
| 670 | onClick={(e) |
| 671 | className="shrink-0 rounded-md p-0.5 text-muted-foreground opacity-0 transition-opacity hover:bg-background hover:text-foreground group-hover:opacity-100 group-focus-within:opacity-100 data-[state=open]:opacity-100" |
| 672 | > |
| 673 | <MoreHorizontal className=" |
| 674 | </DropdownMenuTrigger> |
| 675 | <DropdownMenuContent align=" |
| 676 | {file.file && |
| 677 | <DropdownMenuItem |
| 678 | className="cursor-pointer" |
| 679 | onClick={() => |
| 680 | const a = |
| 681 | a.href = |
| 682 | a.click(); |
| 683 | }} |
| 684 | > |
| 685 | <Download /> |
| 686 | {t("download") |
| 687 | </DropdownMenuItem> |
| 688 | )} |
| 689 | <DropdownMenuItem |
| 690 | className="cursor-pointer" |
| 691 | onClick={() => |
| 692 | setRenamingPath(itemPath); |
| 693 | setRenameValue(file.name |
| 694 | }} |
| 695 | > |
| 696 | <Pencil /> |
| 697 | {t("rename") |
| 698 | </DropdownMenuItem> |
| 699 | <DropdownMenuItem |
| 700 | className="cursor-pointer" |
| 701 | disabled={busyAction !== |
| 702 | onClick={() => |
| 703 | > |
| 704 | {busyAction === "archive |
| 705 | {t("archive") |
| 706 | </DropdownMenuItem> |
| 707 | {isArchiveFile(file.name |
| 708 | <DropdownMenuItem |
| 709 | className="cursor-pointer" |
| 710 | disabled={busyAction !== |
| 711 | onClick={() => |
| 712 | > |
| 713 | {busyAction === "unarchive |
| 714 | {t("unarchive") |
| 715 | </DropdownMenuItem> |
| 716 | )} |
| 717 | <DropdownMenuItem |
| 718 | variant="destructive" |
| 719 | className="cursor-pointer" |
| 720 | onClick={() => |
| 721 | > |
| 722 | <Trash2 /> |
| 723 | {t("delete") |
| 724 | </DropdownMenuItem> |
| 725 | </DropdownMenuContent> |
| 726 | </DropdownMenu> |
| 727 | </div> |
| 728 | ); |
| 729 | }) |
| 730 | )} |
| 731 | </div> |
| 732 | </div> |
| 733 | |
| 734 | <div className="flex flex-1 flex-col overflow-hidden rounded-xl border border-border bg-card |
| 735 | {selectedFile ? ( |
| 736 | <> |
| 737 | <div className="flex h-10 shrink-0 items-center justify-between border-b border-border px-4 |
| 738 | <div className="flex items-center gap-2 |
| 739 | <FileIcon file={ |
| 740 | <span className="font-mono text-xs text-foreground |
| 741 | {unsaved && <span |
| 742 | </div> |
| 743 | {isText(selectedFile) |
| 744 | <button |
| 745 | type="button" |
| 746 | onClick={() => |
| 747 | disabled={saving} |
| 748 | className={`flex items-center gap-1.5 rounded-lg px-3 py-1 text-xs font-medium transition-all ${ |
| 749 | unsaved && !saving |
| 750 | ? "bg-blue-500 text-white hover:bg-blue-600" |
| 751 | : "bg-muted text-muted-foreground cursor-default" |
| 752 | }`} |
| 753 | > |
| 754 | <Save className=" |
| 755 | {saving ? t |
| 756 | </button> |
| 757 | )} |
| 758 | </div> |
| 759 | |
| 760 | <div className="flex-1 overflow-hidden |
| 761 | {isImage(selectedFile) |
| 762 | <div className="flex h-full items-center justify-center bg-muted/30 |
| 763 | <div className="flex flex-col items-center gap-3 rounded-xl border border-border bg-card px-8 py-6 |
| 764 | <FileImage className=" |
| 765 | <span className="font-mono text-sm text-foreground |
| 766 | <span className="text-xs text-muted-foreground |
| 767 | </div> |
| 768 | </div> |
| 769 | ) : isText(selectedFile |
| 770 | <Editor |
| 771 | height="100%" |
| 772 | language={getLanguage(selectedFile |
| 773 | value={editContent} |
| 774 | theme="struxa-dark" |
| 775 | onChange={(v) |
| 776 | beforeMount={defineTheme} |
| 777 | options={{ |
| 778 | fontSize: 13, |
| 779 | fontFamily: "var(--font-geist-mono), 'JetBrains Mono', 'Fira Code', monospace", |
| 780 | lineHeight: 20, |
| 781 | minimap: { enabled: false |
| 782 | scrollBeyondLastLine: false, |
| 783 | renderLineHighlight: "line", |
| 784 | overviewRulerBorder: false, |
| 785 | hideCursorInOverviewRuler: true, |
| 786 | padding: { top: 16 |
| 787 | scrollbar: { verticalScrollbarSize: 6 |
| 788 | lineNumbersMinChars: 3, |
| 789 | folding: false, |
| 790 | contextmenu: false, |
| 791 | }} |
| 792 | /> |
| 793 | ) : ( |
| 794 | <div className="flex h-full flex-col items-center justify-center gap-3 |
| 795 | <File className=" |
| 796 | <p className="text-sm font-medium text-foreground |
| 797 | <span className="text-xs text-muted-foreground |
| 798 | <span className="font-mono text-xs text-muted-foreground/60 |
| 799 | </div> |
| 800 | )} |
| 801 | </div> |
| 802 | </> |
| 803 | ) : ( |
| 804 | <div className="flex h-full flex-col items-center justify-center gap-3 |
| 805 | <FolderOpen className=" |
| 806 | <p className="text-sm font-medium text-foreground |
| 807 | <span className="text-xs text-muted-foreground |
| 808 | </div> |
| 809 | )} |
| 810 | </div> |
| 811 | </div> |
| 812 | <Dialog open={ |
| 813 | <DialogPopup showCloseButton={ |
| 814 | <DialogHeader> |
| 815 | <DialogTitle>{t( |
| 816 | <DialogDescription>{t( |
| 817 | </DialogHeader> |
| 818 | <div className="flex flex-col gap-4 px-5 py-4 |
| 819 | <div className="flex flex-col gap-1.5 |
| 820 | <Label className=" |
| 821 | <Input |
| 822 | autoFocus |
| 823 | className="font-mono text-xs" |
| 824 | placeholder={t(" |
| 825 | value={archiveDialog?.name |
| 826 | onChange={(e) |
| 827 | /> |
| 828 | </div> |
| 829 | <div className="flex flex-col gap-1.5 |
| 830 | <Label className=" |
| 831 | <Select |
| 832 | value={archiveDialog?.format |
| 833 | items={ARCHIVE_FORMAT_ITEMS} |
| 834 | onValueChange={(v) |
| 835 | > |
| 836 | <SelectTrigger className=" |
| 837 | <SelectValue /> |
| 838 | </SelectTrigger> |
| 839 | <SelectContent> |
| 840 | {ARCHIVE_FORMATS.map(( |
| 841 | <SelectItem key={ |
| 842 | ))} |
| 843 | </SelectContent> |
| 844 | </Select> |
| 845 | </div> |
| 846 | </div> |
| 847 | <DialogFooter> |
| 848 | <DialogClose className=" |
| 849 | {t("cancel") |
| 850 | </DialogClose> |
| 851 | <Button |
| 852 | size="sm" |
| 853 | disabled={busyAction === |
| 854 | onClick={() => |
| 855 | > |
| 856 | {busyAction === "archive |
| 857 | {t("createArchive") |
| 858 | </Button> |
| 859 | </DialogFooter> |
| 860 | </DialogPopup> |
| 861 | </Dialog> |
| 862 | |
| 863 | <ConfirmDialog |
| 864 | open={deleteTarget !== |
| 865 | onOpenChange={(open) |
| 866 | title={t(" |
| 867 | description={ |
| 868 | deleteTarget |
| 869 | ? deleteTarget.bulk |
| 870 | ? t("deleteSelectedDescription" |
| 871 | : t("deleteFileDescription" |
| 872 | : undefined |
| 873 | } |
| 874 | confirmLabel={t(" |
| 875 | destructive |
| 876 | loading={deleting} |
| 877 | onConfirm={() => |
| 878 | /> |
| 879 | </> |
| 880 | ); |
| 881 | } |