@thaut/claude-ide 0.0.0-stage → 1.0.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/bin/claude-ide.js +23 -0
- package/package.json +75 -4
- package/server/add-dirs.ts +126 -0
- package/server/auth.test.ts +148 -0
- package/server/auth.ts +235 -0
- package/server/bang.ts +54 -0
- package/server/btw-instructions.ts +19 -0
- package/server/btw-policy.ts +17 -0
- package/server/btw.ts +143 -0
- package/server/child-env.ts +29 -0
- package/server/cli-control.ts +255 -0
- package/server/cli-files.ts +55 -0
- package/server/cli-info.ts +73 -0
- package/server/config/account.ts +65 -0
- package/server/config/agents.ts +186 -0
- package/server/config/mcp.ts +86 -0
- package/server/config/memory.ts +193 -0
- package/server/config/paths.ts +156 -0
- package/server/config/plugins.ts +204 -0
- package/server/config/routes.ts +95 -0
- package/server/config/settings.ts +246 -0
- package/server/config.ts +46 -0
- package/server/db.ts +121 -0
- package/server/directories.test.ts +180 -0
- package/server/directories.ts +87 -0
- package/server/dist-version.ts +69 -0
- package/server/durable-tasks.ts +61 -0
- package/server/file-transfers.ts +79 -0
- package/server/files.test.ts +127 -0
- package/server/files.ts +386 -0
- package/server/fs-queue.ts +14 -0
- package/server/fsutil.ts +144 -0
- package/server/git.ts +86 -0
- package/server/goal-state.test.ts +64 -0
- package/server/goal-state.ts +78 -0
- package/server/history-pages.test.ts +619 -0
- package/server/history-pages.ts +513 -0
- package/server/http-channel-manager.ts +468 -0
- package/server/http-channel-pull.test.ts +314 -0
- package/server/http-channel-push.test.ts +364 -0
- package/server/http-channel-registration.test.ts +291 -0
- package/server/http-channel-routes.ts +73 -0
- package/server/http-channel-store.ts +142 -0
- package/server/http-channel-test-fixture.ts +103 -0
- package/server/ide-messages-mcp.test.ts +82 -0
- package/server/ide-messages-mcp.ts +47 -0
- package/server/idecron-mcp.ts +65 -0
- package/server/idecron.test.ts +79 -0
- package/server/idecron.ts +271 -0
- package/server/index.ts +336 -0
- package/server/live-session.test.ts +1126 -0
- package/server/live-session.ts +1165 -0
- package/server/project-routes.ts +46 -0
- package/server/projects.test.ts +28 -0
- package/server/push.ts +315 -0
- package/server/report-cache.ts +28 -0
- package/server/session-aliases.test.ts +57 -0
- package/server/session-aliases.ts +50 -0
- package/server/session-branch.ts +71 -0
- package/server/session-dirs.ts +189 -0
- package/server/session-file.test.ts +134 -0
- package/server/session-file.ts +113 -0
- package/server/session-messaging.test.ts +297 -0
- package/server/session-messaging.ts +165 -0
- package/server/sessions.ts +638 -0
- package/server/subagents.test.ts +43 -0
- package/server/subagents.ts +58 -0
- package/server/tool-images.test.ts +76 -0
- package/server/tool-images.ts +45 -0
- package/server/turn-changes.ts +308 -0
- package/server/worktree-git.ts +87 -0
- package/server/worktrees.ts +138 -0
- package/server/ws.test.ts +195 -0
- package/server/ws.ts +197 -0
- package/shared/agent-model.ts +15 -0
- package/shared/agent-tasks.ts +12 -0
- package/shared/config.ts +175 -0
- package/shared/directories.ts +12 -0
- package/shared/files.ts +51 -0
- package/shared/http-channels.ts +63 -0
- package/shared/message-window.ts +189 -0
- package/shared/project.ts +77 -0
- package/shared/protocol.ts +203 -0
- package/shared/task-types.ts +4 -0
- package/shared/todos.ts +40 -0
- package/shared/write-policy.ts +9 -0
- package/web/dist/assets/AgentView-wrTKgcJ3.js +1 -0
- package/web/dist/assets/AnnotationSelection-BZmNmwVW.js +7 -0
- package/web/dist/assets/ChangesView-G1WTzh4q.js +2 -0
- package/web/dist/assets/FilesView-DPgAbYt_.js +6 -0
- package/web/dist/assets/Form-BKTwiYyw.js +1 -0
- package/web/dist/assets/HomePage-Dq2apjBe.js +1 -0
- package/web/dist/assets/Markdown-IwP-xF29.js +67 -0
- package/web/dist/assets/MessageList-DD9GypSy.js +15 -0
- package/web/dist/assets/Modal-g2rv8I_n.js +1 -0
- package/web/dist/assets/NotificationSettings-DpuLO_Bv.js +1 -0
- package/web/dist/assets/OverviewPage-Dx6miabE.js +1 -0
- package/web/dist/assets/ProjectHome-CousyTLL.js +1 -0
- package/web/dist/assets/SessionView-CPVL7_HO.js +2 -0
- package/web/dist/assets/SettingsPage-D_oYSnW2.js +7 -0
- package/web/dist/assets/WorktreesView-C7e0HV__.js +1 -0
- package/web/dist/assets/abap-CLvhMVsD.js +1 -0
- package/web/dist/assets/actionscript-3-Cs6JJXT5.js +1 -0
- package/web/dist/assets/ada-X3Y2mlq2.js +1 -0
- package/web/dist/assets/ahk-DwADkxyd.js +1 -0
- package/web/dist/assets/ahk2-_6rzW9BS.js +1 -0
- package/web/dist/assets/andromeeda-vGVdxbeo.js +1 -0
- package/web/dist/assets/angular-html-Cw29lun8.js +1 -0
- package/web/dist/assets/angular-ts-BXz-O3SJ.js +1 -0
- package/web/dist/assets/apache-U0d_L8uA.js +1 -0
- package/web/dist/assets/apex-KFGFyKwG.js +1 -0
- package/web/dist/assets/apl-xBchdRhy.js +1 -0
- package/web/dist/assets/applescript-CCn79oCD.js +1 -0
- package/web/dist/assets/ara-4CJ0cIlV.js +1 -0
- package/web/dist/assets/asciidoc-SCjQUq34.js +1 -0
- package/web/dist/assets/asm-Cmm7eHzH.js +1 -0
- package/web/dist/assets/astro-1q6DGuN3.js +1 -0
- package/web/dist/assets/aurora-x-CDeNXAV0.js +1 -0
- package/web/dist/assets/awk-BWXHIvNe.js +1 -0
- package/web/dist/assets/ayu-dark-DluEY0Gj.js +1 -0
- package/web/dist/assets/ayu-light-C3h-C4tm.js +1 -0
- package/web/dist/assets/ayu-mirage-Bqwy1Gya.js +1 -0
- package/web/dist/assets/ballerina-B7ZEbQpA.js +1 -0
- package/web/dist/assets/bat-qdxAdBWQ.js +1 -0
- package/web/dist/assets/beancount-C2IN4Vk8.js +1 -0
- package/web/dist/assets/berry-DKpUyyne.js +1 -0
- package/web/dist/assets/bibtex-Ci_nEsc7.js +1 -0
- package/web/dist/assets/bicep-CUHmPFLl.js +1 -0
- package/web/dist/assets/bird2-CYIUgYqB.js +1 -0
- package/web/dist/assets/blade-Cqdv4oZN.js +1 -0
- package/web/dist/assets/bsl-CVED6lJ1.js +1 -0
- package/web/dist/assets/c-D9gIxSfx.js +1 -0
- package/web/dist/assets/c3-D0apG41V.js +1 -0
- package/web/dist/assets/cadence-CQ2zXKGN.js +1 -0
- package/web/dist/assets/cairo-DRAZz75c.js +1 -0
- package/web/dist/assets/catppuccin-frappe-C9Q5zVZY.js +1 -0
- package/web/dist/assets/catppuccin-latte-CtsyrtPq.js +1 -0
- package/web/dist/assets/catppuccin-macchiato-R8nAf1vR.js +1 -0
- package/web/dist/assets/catppuccin-mocha-DjuaAJKi.js +1 -0
- package/web/dist/assets/chapel-CuseGurG.js +1 -0
- package/web/dist/assets/clarity-CtfBBspg.js +1 -0
- package/web/dist/assets/clojure-DqKBuwfJ.js +1 -0
- package/web/dist/assets/cmake-Bj61d0ZC.js +1 -0
- package/web/dist/assets/cobol-Bdpj3Qoh.js +1 -0
- package/web/dist/assets/codeowners-C8r90Shi.js +1 -0
- package/web/dist/assets/codeql-oeQT6MSM.js +1 -0
- package/web/dist/assets/coffee-Sk8pHFjs.js +1 -0
- package/web/dist/assets/common-lisp-Cv5bFMCO.js +1 -0
- package/web/dist/assets/coq-CGaSfhwR.js +1 -0
- package/web/dist/assets/core-BxI4V4-T.js +12 -0
- package/web/dist/assets/cpp-BQfBYKx3.js +1 -0
- package/web/dist/assets/crystal-B3j7DoOZ.js +1 -0
- package/web/dist/assets/csharp-dmMxLVLW.js +1 -0
- package/web/dist/assets/css-DpFbYmRh.js +1 -0
- package/web/dist/assets/csv-Dx-8-gkx.js +1 -0
- package/web/dist/assets/cue-CE9AQfxI.js +1 -0
- package/web/dist/assets/cypher-ClKdZ_lG.js +1 -0
- package/web/dist/assets/d-qD-0Kul2.js +1 -0
- package/web/dist/assets/dark-plus-Cs2F2srj.js +1 -0
- package/web/dist/assets/dart-CHZY9Xhz.js +1 -0
- package/web/dist/assets/dax-BkyTk9wS.js +1 -0
- package/web/dist/assets/desktop-Dlh5hvp9.js +1 -0
- package/web/dist/assets/diff-woXpYk--.js +1 -0
- package/web/dist/assets/docker-IyjqRm3v.js +1 -0
- package/web/dist/assets/dotenv-CuH5my32.js +1 -0
- package/web/dist/assets/dracula-BHWKrbxM.js +1 -0
- package/web/dist/assets/dracula-soft-5eyTD99u.js +1 -0
- package/web/dist/assets/dream-maker-DW3nJb8Q.js +1 -0
- package/web/dist/assets/edge-DXQWmXTB.js +1 -0
- package/web/dist/assets/elixir-CrDIY2Vo.js +1 -0
- package/web/dist/assets/elm-BslFEg8K.js +1 -0
- package/web/dist/assets/emacs-lisp-DR2vtWaj.js +1 -0
- package/web/dist/assets/engine-javascript-DJg3-Vu2.js +141 -0
- package/web/dist/assets/erb-CUYhg0Ws.js +1 -0
- package/web/dist/assets/erlang-BXdgHVfi.js +1 -0
- package/web/dist/assets/everforest-dark-sB-x3p7T.js +1 -0
- package/web/dist/assets/everforest-light-Df2xbC6M.js +1 -0
- package/web/dist/assets/fennel-DQxkIbk2.js +1 -0
- package/web/dist/assets/fish-BJitypiv.js +1 -0
- package/web/dist/assets/fluent-C03EYrpw.js +1 -0
- package/web/dist/assets/format-DrBC7w0A.js +1 -0
- package/web/dist/assets/fortran-fixed-form-D6mN0kjy.js +1 -0
- package/web/dist/assets/fortran-free-form-CYNrtFtB.js +1 -0
- package/web/dist/assets/fsharp-CwoEF39o.js +1 -0
- package/web/dist/assets/gdresource-CZkFGo3B.js +1 -0
- package/web/dist/assets/gdscript-DYvRD3hg.js +1 -0
- package/web/dist/assets/gdshader-CBce3t8t.js +1 -0
- package/web/dist/assets/genie-CV2tkWYe.js +1 -0
- package/web/dist/assets/gherkin-DExj1W_8.js +1 -0
- package/web/dist/assets/git-commit-dUGrvm6Q.js +1 -0
- package/web/dist/assets/git-rebase-4zCRqF28.js +1 -0
- package/web/dist/assets/github-dark-C-LZuMrd.js +1 -0
- package/web/dist/assets/github-dark-default-DXG-b-1a.js +1 -0
- package/web/dist/assets/github-dark-dimmed-Bx1FflLF.js +1 -0
- package/web/dist/assets/github-dark-high-contrast-B_tTalzw.js +1 -0
- package/web/dist/assets/github-light-EUqPIrTm.js +1 -0
- package/web/dist/assets/github-light-default-BXViO-2h.js +1 -0
- package/web/dist/assets/github-light-high-contrast-B68TUdTA.js +1 -0
- package/web/dist/assets/gleam-CSRkHgEL.js +1 -0
- package/web/dist/assets/glimmer-js-7adTRvH4.js +1 -0
- package/web/dist/assets/glimmer-ts-IdSskDYw.js +1 -0
- package/web/dist/assets/glsl-Qzy53KDt.js +1 -0
- package/web/dist/assets/gn-CAXYAgV-.js +1 -0
- package/web/dist/assets/gnuplot-7GGW24-e.js +1 -0
- package/web/dist/assets/go-rLFTqkRN.js +1 -0
- package/web/dist/assets/graphql-CV_puxbB.js +1 -0
- package/web/dist/assets/groovy-CacY0gHj.js +1 -0
- package/web/dist/assets/gruvbox-dark-hard-C820rvS2.js +1 -0
- package/web/dist/assets/gruvbox-dark-medium-BPjhmG05.js +1 -0
- package/web/dist/assets/gruvbox-dark-soft-MrdJrrXF.js +1 -0
- package/web/dist/assets/gruvbox-light-hard-BC_s9l72.js +1 -0
- package/web/dist/assets/gruvbox-light-medium-BAWPOn9u.js +1 -0
- package/web/dist/assets/gruvbox-light-soft-BSMLrYjP.js +1 -0
- package/web/dist/assets/hack-C5GPjiLV.js +1 -0
- package/web/dist/assets/haml-BQ5YR1DQ.js +1 -0
- package/web/dist/assets/handlebars-DnhRK9A1.js +1 -0
- package/web/dist/assets/haskell-D8IpX4py.js +1 -0
- package/web/dist/assets/haxe-C8oCnwJJ.js +1 -0
- package/web/dist/assets/hcl-Dh228itO.js +1 -0
- package/web/dist/assets/highlight.worker-CY-ZeDAl.js +1 -0
- package/web/dist/assets/hjson-CxZEssPk.js +1 -0
- package/web/dist/assets/hlsl-Cvrh5tZx.js +1 -0
- package/web/dist/assets/horizon-CE9ld1lL.js +1 -0
- package/web/dist/assets/horizon-bright-DSNQnXHK.js +1 -0
- package/web/dist/assets/houston-CsvMBhTu.js +1 -0
- package/web/dist/assets/html-CmHiEKV9.js +1 -0
- package/web/dist/assets/html-derivative-BXE-rYIK.js +1 -0
- package/web/dist/assets/http-DPjjqtcL.js +1 -0
- package/web/dist/assets/hurl-AMBpSloO.js +1 -0
- package/web/dist/assets/hxml-D7Y24wKF.js +1 -0
- package/web/dist/assets/hy-CZbG8q4J.js +1 -0
- package/web/dist/assets/imba-DsUTQ-LC.js +1 -0
- package/web/dist/assets/index-DNPnl4sh.css +2 -0
- package/web/dist/assets/index-DQh72lEx.js +14 -0
- package/web/dist/assets/ini-B5eOa1yu.js +1 -0
- package/web/dist/assets/java-CEM7Tdw_.js +1 -0
- package/web/dist/assets/javascript-CU3PLowd.js +1 -0
- package/web/dist/assets/jinja-fR0x_9Xy.js +1 -0
- package/web/dist/assets/jison-BoKsxs5M.js +1 -0
- package/web/dist/assets/json-BM2FWsRB.js +1 -0
- package/web/dist/assets/json5-BR5RXkoi.js +1 -0
- package/web/dist/assets/jsonc-CYpm1nAK.js +1 -0
- package/web/dist/assets/jsonl-CmCQp5Yx.js +1 -0
- package/web/dist/assets/jsonnet-CJTPZ8u_.js +1 -0
- package/web/dist/assets/jssm-DXw9l8Rf.js +1 -0
- package/web/dist/assets/jsx-B5fTecQP.js +1 -0
- package/web/dist/assets/julia-DGyDG39_.js +1 -0
- package/web/dist/assets/just-B-RyLcSR.js +1 -0
- package/web/dist/assets/kanagawa-dragon-Bozd7klA.js +1 -0
- package/web/dist/assets/kanagawa-lotus-BmuOG9ZW.js +1 -0
- package/web/dist/assets/kanagawa-wave-BML5mF2J.js +1 -0
- package/web/dist/assets/kdl-CsD5j6eV.js +1 -0
- package/web/dist/assets/kotlin-DhhofPvG.js +1 -0
- package/web/dist/assets/kusto-C7mF5XQf.js +1 -0
- package/web/dist/assets/langs-CciPKqaF.js +1 -0
- package/web/dist/assets/laserwave-C_8bwKvT.js +1 -0
- package/web/dist/assets/latex-CV1pQelm.js +1 -0
- package/web/dist/assets/lean-CewbzKMR.js +1 -0
- package/web/dist/assets/less-DVTAwKKz.js +1 -0
- package/web/dist/assets/lib-DlcVMUqT.js +1 -0
- package/web/dist/assets/light-plus-DVQuIRkW.js +1 -0
- package/web/dist/assets/liquid-9p05RSzQ.js +1 -0
- package/web/dist/assets/llvm-DqHOMS-s.js +1 -0
- package/web/dist/assets/log-BNLmms1o.js +1 -0
- package/web/dist/assets/logo-Cluzi2Zq.js +1 -0
- package/web/dist/assets/lua-CIPVh0S-.js +1 -0
- package/web/dist/assets/luau-VGWVLoqX.js +1 -0
- package/web/dist/assets/make-Dixweg8N.js +1 -0
- package/web/dist/assets/markdown-BYOwaDjH.js +1 -0
- package/web/dist/assets/marko-h2h6YUMS.js +1 -0
- package/web/dist/assets/material-theme-Bm3Qr25_.js +1 -0
- package/web/dist/assets/material-theme-darker-2IIEA8gg.js +1 -0
- package/web/dist/assets/material-theme-lighter-uhdI0v04.js +1 -0
- package/web/dist/assets/material-theme-ocean-CHQ94UKr.js +1 -0
- package/web/dist/assets/material-theme-palenight-B5W6OYN7.js +1 -0
- package/web/dist/assets/matlab-D7qyCx1q.js +1 -0
- package/web/dist/assets/mdc-yAyZMdoC.js +1 -0
- package/web/dist/assets/mdx-DQZ5AkYe.js +1 -0
- package/web/dist/assets/mermaid-BxpfTIzt.js +1 -0
- package/web/dist/assets/message-font-size-DoaZfwkT.js +1 -0
- package/web/dist/assets/min-dark-BSWPekZh.js +1 -0
- package/web/dist/assets/min-light-DDpmG2fV.js +1 -0
- package/web/dist/assets/mipsasm-BMqwQI7S.js +1 -0
- package/web/dist/assets/mojo-fg40_ntQ.js +1 -0
- package/web/dist/assets/monokai-BscAjiQZ.js +1 -0
- package/web/dist/assets/moonbit-D9W784E_.js +1 -0
- package/web/dist/assets/move-BYnGhZoM.js +1 -0
- package/web/dist/assets/narrat-_X_XdTYD.js +1 -0
- package/web/dist/assets/nextflow-BoTnSBQ_.js +1 -0
- package/web/dist/assets/nextflow-groovy-D7IRt6Pp.js +1 -0
- package/web/dist/assets/nginx-jWINucNT.js +1 -0
- package/web/dist/assets/night-owl-DhmEMT88.js +1 -0
- package/web/dist/assets/night-owl-light-eJ-hLW7d.js +1 -0
- package/web/dist/assets/nim-Dtt9DZ0t.js +1 -0
- package/web/dist/assets/nix-Cl_7024t.js +1 -0
- package/web/dist/assets/nord-Cb4Vim4T.js +1 -0
- package/web/dist/assets/nsis-CjNLYCLg.js +1 -0
- package/web/dist/assets/nushell--0fT3PI1.js +1 -0
- package/web/dist/assets/objective-c-D1A_Heim.js +1 -0
- package/web/dist/assets/objective-cpp-BsSzOQcm.js +1 -0
- package/web/dist/assets/ocaml-O90oeIOV.js +1 -0
- package/web/dist/assets/odin-B1RWQWA5.js +1 -0
- package/web/dist/assets/one-dark-pro-C6YyR8OD.js +1 -0
- package/web/dist/assets/one-light-D7Lr4KcI.js +1 -0
- package/web/dist/assets/openscad-BUDT5pXO.js +1 -0
- package/web/dist/assets/org-ClD5huOa.js +1 -0
- package/web/dist/assets/pascal-4ZHwLPI5.js +1 -0
- package/web/dist/assets/perl-BFegxyeJ.js +1 -0
- package/web/dist/assets/php-B-qOA3Y4.js +1 -0
- package/web/dist/assets/pkl-ot-7Btpt.js +1 -0
- package/web/dist/assets/plastic-DQwYfKfQ.js +1 -0
- package/web/dist/assets/plsql-DGHpHOYJ.js +1 -0
- package/web/dist/assets/po-BiJDBrnU.js +1 -0
- package/web/dist/assets/poimandres-DRFjx7u4.js +1 -0
- package/web/dist/assets/polar-C7UOKdEL.js +1 -0
- package/web/dist/assets/postcss-BXeXVLqQ.js +1 -0
- package/web/dist/assets/powerquery-DNMTfnFr.js +1 -0
- package/web/dist/assets/powershell-QtSnmXcu.js +1 -0
- package/web/dist/assets/prisma-DMgNhnYS.js +1 -0
- package/web/dist/assets/prolog-iXnhIJG7.js +1 -0
- package/web/dist/assets/proto-DB4EqR-F.js +1 -0
- package/web/dist/assets/pug-Cq0NBPu-.js +1 -0
- package/web/dist/assets/puppet-CDv2pdJW.js +1 -0
- package/web/dist/assets/purescript-9MfHhQsQ.js +1 -0
- package/web/dist/assets/python-gzcpVVnB.js +1 -0
- package/web/dist/assets/qml-CYUsa87k.js +1 -0
- package/web/dist/assets/qmldir-DCQb3MpD.js +1 -0
- package/web/dist/assets/qss-Fe1Jh2GI.js +1 -0
- package/web/dist/assets/r-4xJhgbOf.js +1 -0
- package/web/dist/assets/racket-DcIDlBhZ.js +1 -0
- package/web/dist/assets/raku-B3gFvitq.js +1 -0
- package/web/dist/assets/razor-BlHaOHx8.js +1 -0
- package/web/dist/assets/rbs-C0MpOrj4.js +1 -0
- package/web/dist/assets/react-B4UGpcWC.js +1 -0
- package/web/dist/assets/red-CYlAq2b0.js +1 -0
- package/web/dist/assets/reg-CRGYupPL.js +1 -0
- package/web/dist/assets/regexp-BUSxjv2o.js +1 -0
- package/web/dist/assets/rel-BtDbiS_P.js +1 -0
- package/web/dist/assets/riscv-Ckw8ddFX.js +1 -0
- package/web/dist/assets/ron-VUp2lXgN.js +1 -0
- package/web/dist/assets/rose-pine-aMsaMD1D.js +1 -0
- package/web/dist/assets/rose-pine-dawn-8PwUyIlP.js +1 -0
- package/web/dist/assets/rose-pine-moon-DO-qXg-I.js +1 -0
- package/web/dist/assets/rosmsg-CAekHB0j.js +1 -0
- package/web/dist/assets/rst-zjfguEh7.js +1 -0
- package/web/dist/assets/ruby-4oR9waBK.js +1 -0
- package/web/dist/assets/rust-DpiIf5JO.js +1 -0
- package/web/dist/assets/sas-Do4V_2i9.js +1 -0
- package/web/dist/assets/sass-DXrisJhu.js +1 -0
- package/web/dist/assets/scala-BiFt_7mu.js +1 -0
- package/web/dist/assets/scheme-DQCgrYNe.js +1 -0
- package/web/dist/assets/scss-CW6JPtag.js +1 -0
- package/web/dist/assets/sdbl-bTVj8UrX.js +1 -0
- package/web/dist/assets/shaderlab-C4rnI7x0.js +1 -0
- package/web/dist/assets/shellscript-zBmOMFJh.js +1 -0
- package/web/dist/assets/shellsession-DxGUTWaf.js +1 -0
- package/web/dist/assets/slack-dark-DnToyrRv.js +1 -0
- package/web/dist/assets/slack-ochin-B2OO5cIa.js +1 -0
- package/web/dist/assets/smalltalk-BHpQb5nM.js +1 -0
- package/web/dist/assets/smithy-Dgaz7aur.js +1 -0
- package/web/dist/assets/snazzy-light-4G7pJPwS.js +1 -0
- package/web/dist/assets/solarized-dark-b97czJOk.js +1 -0
- package/web/dist/assets/solarized-light-DFPxpIYQ.js +1 -0
- package/web/dist/assets/solidity-Bj7E1mRn.js +1 -0
- package/web/dist/assets/soy-DVtw20Yn.js +1 -0
- package/web/dist/assets/sparql-C0ia5K60.js +1 -0
- package/web/dist/assets/splunk-BC2Px7Mm.js +1 -0
- package/web/dist/assets/sql-DGCM-jag.js +1 -0
- package/web/dist/assets/ssh-config-BgfXC-Er.js +1 -0
- package/web/dist/assets/stata-DfuMOXna.js +1 -0
- package/web/dist/assets/stylus-B6D30XZt.js +1 -0
- package/web/dist/assets/surrealql-CBoRWxfR.js +1 -0
- package/web/dist/assets/svelte-g_uCUem5.js +1 -0
- package/web/dist/assets/swift-CyEgAFGc.js +1 -0
- package/web/dist/assets/synthwave-84-nFMaYfgc.js +1 -0
- package/web/dist/assets/system-verilog-Dh5ihWbf.js +1 -0
- package/web/dist/assets/systemd-BxMlprV5.js +1 -0
- package/web/dist/assets/talonscript-CohzipZa.js +1 -0
- package/web/dist/assets/tasl-DMoTqEGO.js +1 -0
- package/web/dist/assets/tcl-CZd0xW_V.js +1 -0
- package/web/dist/assets/templ-N5C1hJ4Y.js +1 -0
- package/web/dist/assets/terraform-DswuEJGm.js +1 -0
- package/web/dist/assets/tex-mx6xDwuK.js +1 -0
- package/web/dist/assets/themes-CNElGaXw.js +1 -0
- package/web/dist/assets/tokyo-night-oM2G3aXe.js +1 -0
- package/web/dist/assets/toml-CcmNWLt0.js +1 -0
- package/web/dist/assets/ts-tags-C-j71FRb.js +1 -0
- package/web/dist/assets/tsv-sltzmVWM.js +1 -0
- package/web/dist/assets/tsx-z04y7qR9.js +1 -0
- package/web/dist/assets/turtle-ByJddavk.js +1 -0
- package/web/dist/assets/twig-Bz57G_nl.js +1 -0
- package/web/dist/assets/typescript-RMqVTmzR.js +1 -0
- package/web/dist/assets/typespec-BGhR2SqG.js +1 -0
- package/web/dist/assets/typst-BgkqA2Pg.js +1 -0
- package/web/dist/assets/v-DBj4K9d_.js +1 -0
- package/web/dist/assets/vala-zf12oZj6.js +1 -0
- package/web/dist/assets/vb-DOwzaHZ0.js +1 -0
- package/web/dist/assets/verilog-B2gwz-sJ.js +1 -0
- package/web/dist/assets/vesper-DdrHHSXu.js +1 -0
- package/web/dist/assets/vhdl-BroJfC0k.js +1 -0
- package/web/dist/assets/viml-DvXPmvsu.js +1 -0
- package/web/dist/assets/vitesse-black-fwtXNY1n.js +1 -0
- package/web/dist/assets/vitesse-dark-BZCL-v6S.js +1 -0
- package/web/dist/assets/vitesse-light-VbXTXTou.js +1 -0
- package/web/dist/assets/vue-CQgvQytb.js +1 -0
- package/web/dist/assets/vue-html-Dhl6fh9l.js +1 -0
- package/web/dist/assets/vue-vine-Dw_uU59K.js +1 -0
- package/web/dist/assets/vyper-CgoNMtux.js +1 -0
- package/web/dist/assets/wasm-ByWQv1Qj.js +1 -0
- package/web/dist/assets/wenyan-C8pVoKbM.js +1 -0
- package/web/dist/assets/wgsl-BsKzXJz4.js +1 -0
- package/web/dist/assets/wikitext-ClFFjSW2.js +1 -0
- package/web/dist/assets/wit-DdvCle-K.js +1 -0
- package/web/dist/assets/wolfram-DLL8P-h_.js +1 -0
- package/web/dist/assets/xml-B49klYQ3.js +1 -0
- package/web/dist/assets/xsl-D7tnD3qq.js +1 -0
- package/web/dist/assets/yaml-DNQ5_xkL.js +1 -0
- package/web/dist/assets/zenscript-BnlCZFoB.js +1 -0
- package/web/dist/assets/zig-CMLA9XwU.js +1 -0
- package/web/dist/icons/apple-touch-icon.png +0 -0
- package/web/dist/icons/badge-96.png +0 -0
- package/web/dist/icons/icon-192.png +0 -0
- package/web/dist/icons/icon-512.png +0 -0
- package/web/dist/icons/icon.svg +4 -0
- package/web/dist/icons/maskable-192.png +0 -0
- package/web/dist/icons/maskable-512.png +0 -0
- package/web/dist/index.html +30 -0
- package/web/dist/manifest.webmanifest +20 -0
- package/web/dist/sw.js +176 -0
- package/web/dist/version.json +1 -0
- package/web/src/App.tsx +97 -0
- package/web/src/agent-history-flow.test.ts +191 -0
- package/web/src/agent-history-flow.ts +58 -0
- package/web/src/agent-owners.ts +30 -0
- package/web/src/annotation-selection.test.ts +36 -0
- package/web/src/annotation-selection.ts +123 -0
- package/web/src/annotations.test.ts +279 -0
- package/web/src/annotations.ts +191 -0
- package/web/src/api.ts +27 -0
- package/web/src/auth-events.ts +11 -0
- package/web/src/auth-lifecycle.test.ts +105 -0
- package/web/src/clipboard.ts +32 -0
- package/web/src/components/ActivityNotifier.tsx +22 -0
- package/web/src/components/AnnotationEditor.tsx +135 -0
- package/web/src/components/AnnotationSelection.tsx +122 -0
- package/web/src/components/Automation.tsx +390 -0
- package/web/src/components/CodeView.tsx +121 -0
- package/web/src/components/Composer.tsx +552 -0
- package/web/src/components/ComposerAnnotations.tsx +45 -0
- package/web/src/components/Confirmation.tsx +91 -0
- package/web/src/components/CopyButton.tsx +23 -0
- package/web/src/components/DiffView.tsx +94 -0
- package/web/src/components/DirectoryPicker.tsx +230 -0
- package/web/src/components/FileCopyMenu.tsx +58 -0
- package/web/src/components/FileEntryActions.tsx +95 -0
- package/web/src/components/ImagePreview.tsx +68 -0
- package/web/src/components/Items.tsx +608 -0
- package/web/src/components/Markdown.tsx +73 -0
- package/web/src/components/MessageList.tsx +458 -0
- package/web/src/components/Modal.tsx +72 -0
- package/web/src/components/NotificationEntry.tsx +31 -0
- package/web/src/components/NotificationSettings.tsx +226 -0
- package/web/src/components/NotificationToasts.tsx +59 -0
- package/web/src/components/OpenTabs.tsx +112 -0
- package/web/src/components/Pending.tsx +175 -0
- package/web/src/components/ProjectExtras.tsx +299 -0
- package/web/src/components/ProjectNav.tsx +47 -0
- package/web/src/components/SessionActions.tsx +271 -0
- package/web/src/components/SessionChannels.tsx +288 -0
- package/web/src/components/SessionExtras.tsx +263 -0
- package/web/src/components/SettingsLink.tsx +21 -0
- package/web/src/components/Shell.tsx +320 -0
- package/web/src/components/SvgPreview.tsx +18 -0
- package/web/src/components/TodoPanel.tsx +37 -0
- package/web/src/components/VersionNotice.tsx +40 -0
- package/web/src/components/icons.tsx +43 -0
- package/web/src/diff.ts +62 -0
- package/web/src/drafts.test.ts +80 -0
- package/web/src/drafts.ts +64 -0
- package/web/src/format.ts +5 -0
- package/web/src/highlight.worker.ts +49 -0
- package/web/src/hooks.ts +59 -0
- package/web/src/item-view-state.test.ts +51 -0
- package/web/src/item-view-state.ts +43 -0
- package/web/src/live-history-flow.test.ts +77 -0
- package/web/src/live-merge.test.ts +64 -0
- package/web/src/live-merge.ts +50 -0
- package/web/src/live-message-hydration.test.ts +253 -0
- package/web/src/live.ts +404 -0
- package/web/src/main.tsx +27 -0
- package/web/src/markdown-assets.test.ts +70 -0
- package/web/src/markdown-assets.ts +78 -0
- package/web/src/markdown-html.test.ts +84 -0
- package/web/src/markdown-html.ts +60 -0
- package/web/src/markdown-svg.test.ts +37 -0
- package/web/src/markdown-svg.ts +42 -0
- package/web/src/markdown-tables.test.ts +34 -0
- package/web/src/markdown-tables.ts +17 -0
- package/web/src/message-bodies.ts +117 -0
- package/web/src/message-cache.test.ts +208 -0
- package/web/src/message-cache.ts +158 -0
- package/web/src/message-font-size.test.ts +41 -0
- package/web/src/message-font-size.ts +57 -0
- package/web/src/message-time.test.ts +32 -0
- package/web/src/message-time.ts +26 -0
- package/web/src/notify.ts +132 -0
- package/web/src/open-tabs.test.ts +69 -0
- package/web/src/open-tabs.ts +110 -0
- package/web/src/pages/AgentView.tsx +138 -0
- package/web/src/pages/ChangesView.tsx +193 -0
- package/web/src/pages/FilesView.tsx +406 -0
- package/web/src/pages/HomePage.tsx +96 -0
- package/web/src/pages/LoginPage.tsx +56 -0
- package/web/src/pages/OverviewPage.tsx +124 -0
- package/web/src/pages/ProjectHome.tsx +136 -0
- package/web/src/pages/SessionView.tsx +238 -0
- package/web/src/pages/WorktreesView.tsx +197 -0
- package/web/src/pages/settings/AccountPage.tsx +149 -0
- package/web/src/pages/settings/AgentsPage.tsx +182 -0
- package/web/src/pages/settings/ConfigPage.tsx +181 -0
- package/web/src/pages/settings/GeneralPage.tsx +27 -0
- package/web/src/pages/settings/HooksPage.tsx +244 -0
- package/web/src/pages/settings/McpPage.tsx +310 -0
- package/web/src/pages/settings/MemoryPage.tsx +309 -0
- package/web/src/pages/settings/PermissionsPage.tsx +160 -0
- package/web/src/pages/settings/PluginsPage.tsx +251 -0
- package/web/src/pages/settings/SettingsPage.tsx +141 -0
- package/web/src/pages/settings/SkillsPage.tsx +142 -0
- package/web/src/pages/settings/ui.tsx +165 -0
- package/web/src/preference-document.ts +133 -0
- package/web/src/project-actions.ts +18 -0
- package/web/src/project-files-state.test.ts +49 -0
- package/web/src/project-files-state.ts +64 -0
- package/web/src/project-images.ts +13 -0
- package/web/src/pwa.ts +33 -0
- package/web/src/queryClient.ts +5 -0
- package/web/src/reasoning-preference.test.ts +39 -0
- package/web/src/reasoning-preference.ts +42 -0
- package/web/src/session-confirmations.ts +36 -0
- package/web/src/stream-replay.test.ts +163 -0
- package/web/src/styles.css +231 -0
- package/web/src/tool-result-body.test.ts +115 -0
- package/web/src/transcript.test.ts +186 -0
- package/web/src/transcript.ts +583 -0
- package/web/src/turns.test.ts +338 -0
- package/web/src/turns.ts +178 -0
- package/web/src/ui/Button.tsx +60 -0
- package/web/src/ui/Controls.tsx +227 -0
- package/web/src/ui/Form.tsx +203 -0
- package/web/src/ui/MenuPopover.tsx +144 -0
- package/web/src/ui/Popover.tsx +147 -0
- package/web/src/ui/ResizablePane.tsx +110 -0
- package/web/src/ui/Select.tsx +150 -0
- package/web/src/ui/icons.tsx +270 -0
- package/web/src/unsaved.tsx +99 -0
- package/web/src/user-text.test.ts +60 -0
- package/web/src/user-text.ts +35 -0
- package/web/src/uuid.ts +12 -0
- package/README.md +0 -3
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { copyText } from "../clipboard.ts";
|
|
3
|
+
import { Button } from "../ui/Button.tsx";
|
|
4
|
+
import { AlertIcon, CheckIcon, CopyIcon } from "../ui/icons.tsx";
|
|
5
|
+
|
|
6
|
+
export function CopyButton({ text, label, className }: { text: string; label: string; className?: string }) {
|
|
7
|
+
const [copied, setCopied] = useState<string>();
|
|
8
|
+
const [error, setError] = useState<string>();
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (copied === undefined) return;
|
|
11
|
+
const timer = setTimeout(() => setCopied(undefined), 1500);
|
|
12
|
+
return () => clearTimeout(timer);
|
|
13
|
+
}, [copied]);
|
|
14
|
+
const done = copied === text;
|
|
15
|
+
return <Button variant="ghost" size="sm" iconOnly className={`${className ?? ""} ${done ? "bg-ok/10! text-ok! ring-1 ring-ok/25" : ""}`} data-copied={done || undefined} aria-label={label} title={error ?? (done ? "已复制" : label)} onClick={async () => {
|
|
16
|
+
setError(undefined);
|
|
17
|
+
try { await copyText(text); setCopied(text); }
|
|
18
|
+
catch (error) { setError(error instanceof Error ? error.message : "复制失败"); }
|
|
19
|
+
}}>
|
|
20
|
+
{error ? <AlertIcon className="text-danger" /> : done ? <CheckIcon className="text-ok" /> : <CopyIcon />}
|
|
21
|
+
<span className="sr-only" role="status">{error ?? (done ? "已复制" : "")}</span>
|
|
22
|
+
</Button>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
|
|
3
|
+
type Row =
|
|
4
|
+
| { kind: "hunk"; text: string }
|
|
5
|
+
| { kind: "meta"; text: string }
|
|
6
|
+
| { kind: "ctx" | "add" | "del"; text: string; old?: number; new?: number };
|
|
7
|
+
|
|
8
|
+
/** Parse one or more unified diffs (as produced by `git diff`) into display rows. */
|
|
9
|
+
export function parseUnifiedDiff(diff: string): Row[] {
|
|
10
|
+
const rows: Row[] = [];
|
|
11
|
+
let oldNo = 0;
|
|
12
|
+
let newNo = 0;
|
|
13
|
+
let inHunk = false;
|
|
14
|
+
const lines = diff.split("\n");
|
|
15
|
+
if (lines[lines.length - 1] === "") lines.pop();
|
|
16
|
+
for (const l of lines) {
|
|
17
|
+
if (l.startsWith("diff --git ")) {
|
|
18
|
+
inHunk = false;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const h = /^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@(.*)$/.exec(l);
|
|
22
|
+
if (h) {
|
|
23
|
+
oldNo = Number(h[1]);
|
|
24
|
+
newNo = Number(h[2]);
|
|
25
|
+
inHunk = true;
|
|
26
|
+
rows.push({ kind: "hunk", text: l });
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (!inHunk) {
|
|
30
|
+
// File header: only keep the human-relevant bits.
|
|
31
|
+
if (/^(Binary files|new file mode|deleted file mode|old mode|new mode|similarity|rename )/.test(l)) rows.push({ kind: "meta", text: l });
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (l.startsWith("+")) rows.push({ kind: "add", text: l.slice(1), new: newNo++ });
|
|
35
|
+
else if (l.startsWith("-")) rows.push({ kind: "del", text: l.slice(1), old: oldNo++ });
|
|
36
|
+
else if (l.startsWith("\\")) rows.push({ kind: "meta", text: l });
|
|
37
|
+
else rows.push({ kind: "ctx", text: l.slice(1), old: oldNo++, new: newNo++ });
|
|
38
|
+
}
|
|
39
|
+
return rows;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const ROW_CLASS: Record<Row["kind"], string> = {
|
|
43
|
+
add: "bg-ok/15",
|
|
44
|
+
del: "bg-danger/15",
|
|
45
|
+
ctx: "",
|
|
46
|
+
hunk: "bg-accent/5 text-muted border-y border-border",
|
|
47
|
+
meta: "text-muted italic",
|
|
48
|
+
};
|
|
49
|
+
const SIGN: Record<Row["kind"], string> = { add: "+", del: "-", ctx: " ", hunk: "", meta: "" };
|
|
50
|
+
|
|
51
|
+
/** Added / removed line counts of a unified diff. */
|
|
52
|
+
export function diffStats(diff: string) {
|
|
53
|
+
let add = 0;
|
|
54
|
+
let del = 0;
|
|
55
|
+
for (const r of parseUnifiedDiff(diff)) {
|
|
56
|
+
if (r.kind === "add") add++;
|
|
57
|
+
else if (r.kind === "del") del++;
|
|
58
|
+
}
|
|
59
|
+
return { add, del };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function DiffView({ diff }: { diff: string }) {
|
|
63
|
+
const rows = useMemo(() => parseUnifiedDiff(diff), [diff]);
|
|
64
|
+
if (rows.length === 0)
|
|
65
|
+
return (
|
|
66
|
+
<p className="m-4 rounded-xl border border-dashed border-border px-6 py-8 text-center text-sm text-muted">
|
|
67
|
+
没有可显示的差异。文件可能只改了权限,或者改动已经还原。
|
|
68
|
+
</p>
|
|
69
|
+
);
|
|
70
|
+
return (
|
|
71
|
+
<div className="overflow-x-auto" data-testid="diff-view">
|
|
72
|
+
<table className="diff-table min-w-full border-collapse font-mono text-[12.5px] leading-5">
|
|
73
|
+
<tbody>
|
|
74
|
+
{rows.map((r, i) =>
|
|
75
|
+
r.kind === "hunk" || r.kind === "meta" ? (
|
|
76
|
+
<tr key={i} className={ROW_CLASS[r.kind]}>
|
|
77
|
+
<td colSpan={4} className="whitespace-pre px-3 py-1">
|
|
78
|
+
{r.text}
|
|
79
|
+
</td>
|
|
80
|
+
</tr>
|
|
81
|
+
) : (
|
|
82
|
+
<tr key={i} className={ROW_CLASS[r.kind]} data-kind={r.kind}>
|
|
83
|
+
<td className="diff-ln">{r.old ?? ""}</td>
|
|
84
|
+
<td className="diff-ln">{r.new ?? ""}</td>
|
|
85
|
+
<td className={`w-4 select-none pl-1 text-center ${r.kind === "add" ? "text-ok" : r.kind === "del" ? "text-danger" : "text-muted"}`}>{SIGN[r.kind]}</td>
|
|
86
|
+
<td className="whitespace-pre pr-4">{r.text}</td>
|
|
87
|
+
</tr>
|
|
88
|
+
),
|
|
89
|
+
)}
|
|
90
|
+
</tbody>
|
|
91
|
+
</table>
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import { createPortal } from "react-dom";
|
|
3
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
4
|
+
import type { DirectoryListing } from "@shared/directories.ts";
|
|
5
|
+
import { api, ApiError } from "../api.ts";
|
|
6
|
+
import { Button } from "../ui/Button.tsx";
|
|
7
|
+
import { monoInputCls, inputCls } from "../ui/Form.tsx";
|
|
8
|
+
import { FileIcon, FolderIcon } from "../ui/icons.tsx";
|
|
9
|
+
import { Switch } from "../ui/Controls.tsx";
|
|
10
|
+
import { ChevronIcon } from "./icons.tsx";
|
|
11
|
+
import { Modal } from "./Modal.tsx";
|
|
12
|
+
|
|
13
|
+
export function DirectoryPicker({ initialPath, onSelect, onClose }: { initialPath?: string; onSelect: (path: string) => void | Promise<void>; onClose: () => void }) {
|
|
14
|
+
const qc = useQueryClient();
|
|
15
|
+
const [directory, setDirectory] = useState(initialPath ?? "");
|
|
16
|
+
const [completion, setCompletion] = useState(false);
|
|
17
|
+
const [address, setAddress] = useState(initialPath ?? "");
|
|
18
|
+
const [filter, setFilter] = useState("");
|
|
19
|
+
const [hidden, setHidden] = useState(false);
|
|
20
|
+
const [navigation, setNavigation] = useState<string | null>(initialPath ?? "");
|
|
21
|
+
const [newFolder, setNewFolder] = useState<{ parent: string; hidden: boolean } | null>(null);
|
|
22
|
+
const [folderName, setFolderName] = useState("");
|
|
23
|
+
const addressRef = useRef<HTMLInputElement>(null);
|
|
24
|
+
const newFolderButtonRef = useRef<HTMLButtonElement>(null);
|
|
25
|
+
const hadNewFolder = useRef(false);
|
|
26
|
+
const listing = useQuery({
|
|
27
|
+
queryKey: ["directory-picker", directory, hidden, completion],
|
|
28
|
+
queryFn: ({ signal }) => api<DirectoryListing>(`/api/directories?path=${encodeURIComponent(directory)}&hidden=${hidden ? "1" : "0"}${completion ? "&complete=1" : ""}`, { signal }),
|
|
29
|
+
placeholderData: (previous) => previous,
|
|
30
|
+
staleTime: 0,
|
|
31
|
+
retry: false,
|
|
32
|
+
});
|
|
33
|
+
const confirm = useMutation({
|
|
34
|
+
mutationFn: async ({ path, create }: { path: string; create: boolean }) => {
|
|
35
|
+
let selected = path;
|
|
36
|
+
if (create) {
|
|
37
|
+
const created = await api<DirectoryListing>(`/api/directories?hidden=${hidden ? "1" : "0"}`, { method: "POST", json: { path } });
|
|
38
|
+
qc.setQueryData(["directory-picker", created.path, hidden, false], created);
|
|
39
|
+
setCompletion(false);
|
|
40
|
+
setNavigation(null);
|
|
41
|
+
setAddress(created.path);
|
|
42
|
+
setDirectory(created.path);
|
|
43
|
+
selected = created.path;
|
|
44
|
+
}
|
|
45
|
+
await onSelect(selected);
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
const createFolder = useMutation({
|
|
49
|
+
mutationFn: async ({ parent, name, hidden: showHidden }: { parent: string; name: string; hidden: boolean }) => {
|
|
50
|
+
const path = `${parent.replace(/\/$/, "")}/${name}`;
|
|
51
|
+
return api<DirectoryListing>(`/api/directories?hidden=${showHidden ? "1" : "0"}`, { method: "POST", json: { path } });
|
|
52
|
+
},
|
|
53
|
+
onSuccess: (created, { parent, hidden: showHidden }) => {
|
|
54
|
+
// Invalidate canonical and typed aliases of the parent, including hidden views.
|
|
55
|
+
void qc.invalidateQueries({
|
|
56
|
+
queryKey: ["directory-picker"],
|
|
57
|
+
predicate: (query) => query.queryKey[1] === parent || (query.state.data as DirectoryListing | undefined)?.path === parent,
|
|
58
|
+
});
|
|
59
|
+
qc.setQueryData(["directory-picker", created.path, showHidden, false], created);
|
|
60
|
+
setNewFolder(null);
|
|
61
|
+
navigate(created.path);
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
const busy = confirm.isPending || createFolder.isPending;
|
|
65
|
+
const blocked = busy || newFolder !== null;
|
|
66
|
+
const current = listing.data;
|
|
67
|
+
const ready = !!current && !listing.isFetching && !listing.isError && !listing.isPlaceholderData;
|
|
68
|
+
const entries = current?.entries.filter((entry) => entry.name.toLocaleLowerCase().includes(filter.toLocaleLowerCase())) ?? [];
|
|
69
|
+
const canCreate = !!directory && address === directory && (ready && current.requestedType === "missing"
|
|
70
|
+
|| listing.error instanceof ApiError && listing.error.status === 404);
|
|
71
|
+
const selectedPath = listing.isError ? directory : current?.requestedPath ?? current?.path ?? directory;
|
|
72
|
+
const isFile = current?.requestedType === "file";
|
|
73
|
+
const checking = address !== directory && (completion || address !== current?.path);
|
|
74
|
+
const folderNameError = !folderName ? "请填写文件夹名称" : folderName === "." || folderName === ".." || /[/\\\0]/.test(folderName) ? "名称不能包含 /、\\ 或空字符,也不能是 . 或 .." : null;
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
// Only explicit navigation may replace the address with its canonical path.
|
|
78
|
+
// Typing clears navigation, so a late response cannot change the text/caret.
|
|
79
|
+
if (current && !listing.isError && !listing.isFetching && !listing.isPlaceholderData && navigation === directory) {
|
|
80
|
+
if (completion) {
|
|
81
|
+
setNavigation(null);
|
|
82
|
+
// Completion lists siblings even for an existing directory. Only an
|
|
83
|
+
// explicit Enter/Go follows the resolved target into its own listing.
|
|
84
|
+
if (current.requestedType === "dir") {
|
|
85
|
+
const target = current.requestedPath ?? directory;
|
|
86
|
+
setCompletion(false);
|
|
87
|
+
setNavigation(target);
|
|
88
|
+
setAddress(target);
|
|
89
|
+
setDirectory(target);
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
setAddress(current.path);
|
|
94
|
+
setNavigation(null);
|
|
95
|
+
}
|
|
96
|
+
}, [current, directory, navigation, completion, listing.isError, listing.isFetching, listing.isPlaceholderData]);
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
if (address === directory || !completion && address === current?.path || blocked) return;
|
|
99
|
+
const timer = setTimeout(() => { setCompletion(true); setDirectory(address); setFilter(""); }, 250);
|
|
100
|
+
return () => clearTimeout(timer);
|
|
101
|
+
}, [address, directory, current?.path, blocked, completion]);
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (!newFolder && hadNewFolder.current) newFolderButtonRef.current?.focus();
|
|
104
|
+
hadNewFolder.current = newFolder !== null;
|
|
105
|
+
}, [newFolder]);
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
const previous = document.activeElement;
|
|
108
|
+
if (window.matchMedia("(pointer: fine)").matches) addressRef.current?.focus();
|
|
109
|
+
return () => { if (previous instanceof HTMLElement && previous.isConnected) previous.focus(); };
|
|
110
|
+
}, []);
|
|
111
|
+
|
|
112
|
+
function navigate(path: string, complete = false) {
|
|
113
|
+
confirm.reset();
|
|
114
|
+
setCompletion(complete);
|
|
115
|
+
setNavigation(path);
|
|
116
|
+
setAddress(path);
|
|
117
|
+
setDirectory(path);
|
|
118
|
+
setFilter("");
|
|
119
|
+
if (path === directory) void listing.refetch();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function enter(path: string, complete = false) {
|
|
123
|
+
if (!blocked) navigate(path, complete);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function openNewFolder() {
|
|
127
|
+
if (blocked || !ready || checking) return;
|
|
128
|
+
confirm.reset();
|
|
129
|
+
createFolder.reset();
|
|
130
|
+
setFolderName("");
|
|
131
|
+
// Capture the successful canonical listing before opening the nested dialog.
|
|
132
|
+
setNewFolder({ parent: current.path, hidden });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function closeNewFolder() {
|
|
136
|
+
if (!createFolder.isPending) setNewFolder(null);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return createPortal(
|
|
140
|
+
<>
|
|
141
|
+
<div inert={newFolder !== null}>
|
|
142
|
+
<Modal title="添加项目" onClose={() => { if (!blocked) onClose(); }} testId="directory-picker" scrollBody={false}>
|
|
143
|
+
<div className="directory-picker-body flex min-h-0 flex-1 flex-col gap-3">
|
|
144
|
+
<p className="shrink-0 text-xs text-muted">浏览服务所在机器上的文件夹。</p>
|
|
145
|
+
<div className="flex shrink-0 gap-2">
|
|
146
|
+
<input
|
|
147
|
+
ref={addressRef}
|
|
148
|
+
aria-label="浏览目录路径"
|
|
149
|
+
className={monoInputCls}
|
|
150
|
+
value={address}
|
|
151
|
+
disabled={blocked}
|
|
152
|
+
placeholder="绝对路径或 ~/"
|
|
153
|
+
onChange={(e) => { setNavigation(null); setAddress(e.target.value); confirm.reset(); }}
|
|
154
|
+
onKeyDown={(e) => {
|
|
155
|
+
if (e.key === "Enter") { e.preventDefault(); e.stopPropagation(); enter(address, true); }
|
|
156
|
+
}}
|
|
157
|
+
/>
|
|
158
|
+
<Button disabled={blocked} onClick={() => enter(address, true)}>前往</Button>
|
|
159
|
+
</div>
|
|
160
|
+
<div className="flex shrink-0 flex-wrap items-center gap-2">
|
|
161
|
+
<Button size="sm" disabled={blocked || !ready || !current?.parent} onClick={() => current?.parent && enter(current.parent)}>↑ 上级</Button>
|
|
162
|
+
<Button size="sm" disabled={blocked} onClick={() => enter("")}>主目录</Button>
|
|
163
|
+
<Button ref={newFolderButtonRef} size="sm" disabled={blocked || !ready || checking} onClick={openNewFolder}>新建文件夹</Button>
|
|
164
|
+
<Switch label="隐藏目录" checked={hidden} onChange={(next) => { if (!blocked) setHidden(next); }} />
|
|
165
|
+
</div>
|
|
166
|
+
<input aria-label="筛选文件夹" disabled={blocked} className={`${inputCls} shrink-0`} placeholder="筛选文件夹…" value={filter} onChange={(e) => setFilter(e.target.value)} />
|
|
167
|
+
{current && <p className="shrink-0 break-all text-xs text-muted">浏览:{current.path}{current.prefix ? ` · 前缀:${current.prefix}` : ""}</p>}
|
|
168
|
+
{canCreate && <p role="status" className="shrink-0 text-xs text-muted">路径尚不存在。可选择下方候选目录,或确定创建输入的目录。</p>}
|
|
169
|
+
{isFile && ready && <p role="status" className="shrink-0 text-xs text-muted">这是文件,请选择文件夹作为项目目录。</p>}
|
|
170
|
+
<div className="directory-picker-list h-[min(40dvh,20rem)] min-h-0 flex-auto overflow-y-auto overscroll-contain rounded-lg border border-border bg-surface" aria-label="文件夹列表" aria-busy={listing.isFetching || checking}>
|
|
171
|
+
{(listing.isFetching || checking) && <p className="px-4 py-2 text-xs text-muted" role="status">正在查找目录…</p>}
|
|
172
|
+
{!current && (listing.isFetching || checking) ? (
|
|
173
|
+
<p className="px-4 py-8 text-center text-sm text-muted" role="status">正在读取目录…</p>
|
|
174
|
+
) : listing.isError ? (
|
|
175
|
+
<div className="space-y-2 px-4 py-6 text-center">
|
|
176
|
+
<p role={canCreate ? "status" : "alert"} className={`text-sm ${canCreate ? "text-muted" : "text-danger"}`}>{canCreate ? "目录不存在,确定后将创建并添加项目。" : listing.error.message}</p>
|
|
177
|
+
{canCreate && <>
|
|
178
|
+
<p className="break-all font-mono text-xs text-muted">{directory}</p>
|
|
179
|
+
</>}
|
|
180
|
+
{!canCreate && <Button size="sm" disabled={blocked} onClick={() => { confirm.reset(); void listing.refetch(); }}>重试</Button>}
|
|
181
|
+
</div>
|
|
182
|
+
) : entries.length === 0 ? (
|
|
183
|
+
<p className="px-4 py-8 text-center text-sm text-muted">{filter ? "没有匹配的文件夹" : "没有子文件夹,可直接确定添加"}</p>
|
|
184
|
+
) : (
|
|
185
|
+
<ul>
|
|
186
|
+
{entries.map((entry) => (
|
|
187
|
+
<li key={entry.path}>
|
|
188
|
+
<button type="button" disabled={blocked || checking || listing.isFetching || entry.type === "file"} onClick={() => enter(entry.path)} className="flex w-full items-center gap-2.5 px-4 py-3 text-left text-sm hover:bg-surface-2 focus-visible:outline-none focus-visible:bg-surface-2 disabled:opacity-50 sm:py-2">
|
|
189
|
+
{entry.type === "file" ? <FileIcon className="shrink-0 text-muted" /> : <FolderIcon className="shrink-0 text-muted" />}
|
|
190
|
+
<span className="min-w-0 flex-1 truncate">{entry.name}</span>
|
|
191
|
+
{entry.type === "file" ? <span className="text-xs text-muted">文件</span> : <ChevronIcon />}
|
|
192
|
+
</button>
|
|
193
|
+
</li>
|
|
194
|
+
))}
|
|
195
|
+
</ul>
|
|
196
|
+
)}
|
|
197
|
+
</div>
|
|
198
|
+
{current?.truncated && <p className="shrink-0 text-xs text-muted">目录较多,仅显示前 5000 项。可在上方输入路径直接进入。</p>}
|
|
199
|
+
{confirm.error && <p role="alert" className="shrink-0 break-words text-sm text-danger">{confirm.error.message}</p>}
|
|
200
|
+
<div className="flex shrink-0 items-center gap-2 border-t border-border pt-3">
|
|
201
|
+
<Button variant="ghost" disabled={blocked} onClick={onClose}>取消</Button>
|
|
202
|
+
<Button variant="primary" className="ml-auto" loading={confirm.isPending} disabled={blocked || checking || listing.isFetching || isFile || (!canCreate && !ready)} onClick={() => confirm.mutate({ path: selectedPath, create: canCreate })}>{canCreate ? "确定并创建目录" : "确定"}</Button>
|
|
203
|
+
</div>
|
|
204
|
+
</div>
|
|
205
|
+
</Modal>
|
|
206
|
+
</div>
|
|
207
|
+
{newFolder && (
|
|
208
|
+
<Modal title="新建文件夹" onClose={closeNewFolder} testId="directory-create-dialog">
|
|
209
|
+
<form className="flex flex-col gap-3" onSubmit={(event) => {
|
|
210
|
+
event.preventDefault();
|
|
211
|
+
if (!folderNameError && !createFolder.isPending) createFolder.mutate({ parent: newFolder.parent, name: folderName, hidden: newFolder.hidden });
|
|
212
|
+
}}>
|
|
213
|
+
<p className="break-all text-xs text-muted">创建位置:{newFolder.parent}</p>
|
|
214
|
+
<label className="flex flex-col gap-1.5 text-sm">
|
|
215
|
+
文件夹名称
|
|
216
|
+
<input autoFocus aria-label="文件夹名称" className={inputCls} value={folderName} disabled={createFolder.isPending} aria-invalid={!!folderName && !!folderNameError} onChange={(event) => { setFolderName(event.target.value); createFolder.reset(); }} />
|
|
217
|
+
</label>
|
|
218
|
+
{folderName && folderNameError && <p role="alert" className="text-sm text-danger">{folderNameError}</p>}
|
|
219
|
+
{createFolder.error && <p role="alert" className="break-words text-sm text-danger">{createFolder.error.message}</p>}
|
|
220
|
+
<div className="flex items-center gap-2 border-t border-border pt-3">
|
|
221
|
+
<Button variant="ghost" disabled={createFolder.isPending} onClick={closeNewFolder}>取消</Button>
|
|
222
|
+
<Button type="submit" variant="primary" className="ml-auto" loading={createFolder.isPending} disabled={!!folderNameError}>确定</Button>
|
|
223
|
+
</div>
|
|
224
|
+
</form>
|
|
225
|
+
</Modal>
|
|
226
|
+
)}
|
|
227
|
+
</>,
|
|
228
|
+
document.body,
|
|
229
|
+
);
|
|
230
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
|
+
import type { FileContent } from "@shared/files.ts";
|
|
3
|
+
import { api } from "../api.ts";
|
|
4
|
+
import { copyText } from "../clipboard.ts";
|
|
5
|
+
import { Button, Spinner } from "../ui/Button.tsx";
|
|
6
|
+
import { MenuItem } from "../ui/Controls.tsx";
|
|
7
|
+
import { MenuPopover } from "../ui/MenuPopover.tsx";
|
|
8
|
+
import { AlertIcon, CheckIcon, ChevronDownIcon, CopyIcon } from "../ui/icons.tsx";
|
|
9
|
+
import { fileApi } from "./ProjectNav.tsx";
|
|
10
|
+
|
|
11
|
+
export function FileCopyMenu({ pid, path, root, file }: { pid: string; path: string; root?: string; file?: FileContent }) {
|
|
12
|
+
const request = useRef<AbortController | null>(null);
|
|
13
|
+
const [selected, setSelected] = useState("");
|
|
14
|
+
const [busy, setBusy] = useState(false);
|
|
15
|
+
const [copied, setCopied] = useState(false);
|
|
16
|
+
const [error, setError] = useState<string>();
|
|
17
|
+
useEffect(() => () => request.current?.abort(), []);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!copied) return;
|
|
20
|
+
const timer = setTimeout(() => setCopied(false), 1500);
|
|
21
|
+
return () => clearTimeout(timer);
|
|
22
|
+
}, [copied]);
|
|
23
|
+
const absolute = root ? `${root.replace(/[\\/]+$/, "")}/${path}` : undefined;
|
|
24
|
+
const canCopyFile = file?.content !== undefined && !file.binary;
|
|
25
|
+
const copy = async (kind: "absolute" | "relative" | "file" | "selection") => {
|
|
26
|
+
request.current?.abort();
|
|
27
|
+
const controller = new AbortController();
|
|
28
|
+
request.current = controller;
|
|
29
|
+
setBusy(true); setCopied(false); setError(undefined);
|
|
30
|
+
try {
|
|
31
|
+
let text = kind === "absolute" ? absolute : kind === "relative" ? path : kind === "selection" ? selected : file?.content;
|
|
32
|
+
if (kind === "file" && file?.truncated) {
|
|
33
|
+
const full = await api<FileContent>(fileApi(pid, "file", { path, full: "1" }), { signal: controller.signal });
|
|
34
|
+
if (full.binary || full.truncated || full.content === undefined) throw new Error("无法复制这个文件的全文。");
|
|
35
|
+
text = full.content;
|
|
36
|
+
}
|
|
37
|
+
if (controller.signal.aborted) return;
|
|
38
|
+
if (text === undefined) throw new Error("没有可复制的内容。");
|
|
39
|
+
await copyText(text);
|
|
40
|
+
if (!controller.signal.aborted) setCopied(true);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
if (!controller.signal.aborted) setError(error instanceof Error ? error.message : "复制失败");
|
|
43
|
+
} finally { if (!controller.signal.aborted) setBusy(false); }
|
|
44
|
+
};
|
|
45
|
+
return <>
|
|
46
|
+
<MenuPopover label="文件复制选项" beforeOpen={() => setSelected(window.getSelection()?.toString() ?? "")} width={240} testId="file-copy-menu"
|
|
47
|
+
trigger={(props) => <Button {...props} variant="ghost" size="sm" aria-busy={busy} icon={busy ? <Spinner /> : error ? <AlertIcon className="text-danger" /> : copied ? <CheckIcon className="text-ok" /> : <CopyIcon />} title={error}>
|
|
48
|
+
{busy ? "复制中…" : error ? "复制失败" : copied ? "已复制" : "复制"}<ChevronDownIcon size={12} />
|
|
49
|
+
</Button>}>
|
|
50
|
+
{error && <p className="px-3 py-2 text-xs text-danger">{error}</p>}
|
|
51
|
+
<MenuItem disabled={!absolute} onClick={() => void copy("absolute")}>复制完整路径</MenuItem>
|
|
52
|
+
<MenuItem onClick={() => void copy("relative")}>复制相对路径</MenuItem>
|
|
53
|
+
<MenuItem disabled={!canCopyFile} onClick={() => void copy("file")}>复制全文</MenuItem>
|
|
54
|
+
<MenuItem disabled={!selected} onClick={() => void copy("selection")} hint={!selected ? "请先选择文字" : undefined}>复制页面选中文本</MenuItem>
|
|
55
|
+
</MenuPopover>
|
|
56
|
+
{error && <span className="sr-only" role="alert">{error}</span>}
|
|
57
|
+
</>;
|
|
58
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { createContext, useContext, useEffect, useRef, useState, type ReactNode } from "react";
|
|
2
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
import { MAX_UPLOAD_BYTES, MAX_UPLOAD_FILES, type UploadResult } from "@shared/files.ts";
|
|
4
|
+
import { ApiError, authFetch } from "../api.ts";
|
|
5
|
+
import { copyText } from "../clipboard.ts";
|
|
6
|
+
import { useProjects } from "../hooks.ts";
|
|
7
|
+
import { Button } from "../ui/Button.tsx";
|
|
8
|
+
import { MenuItem, MenuSeparator } from "../ui/Controls.tsx";
|
|
9
|
+
import { MenuPopover } from "../ui/MenuPopover.tsx";
|
|
10
|
+
import { AlertIcon, CheckIcon, CopyIcon, DownloadIcon, MoreIcon, UploadIcon } from "../ui/icons.tsx";
|
|
11
|
+
import { useConfirm } from "./Confirmation.tsx";
|
|
12
|
+
import { fileApi } from "./ProjectNav.tsx";
|
|
13
|
+
import { refreshProjectImages } from "../project-images.ts";
|
|
14
|
+
|
|
15
|
+
const UploadContext = createContext<{ choose: (directory: string) => void; busy: boolean; root?: string } | null>(null);
|
|
16
|
+
|
|
17
|
+
export function FileUploadProvider({ pid, children }: { pid: string; children: ReactNode }) {
|
|
18
|
+
const input = useRef<HTMLInputElement>(null), directory = useRef("");
|
|
19
|
+
const confirm = useConfirm(), qc = useQueryClient();
|
|
20
|
+
const project = useProjects().data?.find((item) => item.id === pid);
|
|
21
|
+
const [notice, setNotice] = useState("");
|
|
22
|
+
const upload = useMutation({ mutationFn: async ({ selected, target }: { selected: File[]; target: string }) => {
|
|
23
|
+
if (selected.length > MAX_UPLOAD_FILES || selected.reduce((bytes, file) => bytes + file.size, 0) > MAX_UPLOAD_BYTES) throw new Error("单次最多上传 100 个文件,总大小不超过 50 MiB。");
|
|
24
|
+
const approved = new Set<string>(), written: string[] = [];
|
|
25
|
+
let files = selected;
|
|
26
|
+
while (files.length) {
|
|
27
|
+
const form = new FormData();
|
|
28
|
+
files.forEach((file) => form.append("files", file));
|
|
29
|
+
approved.forEach((name) => form.append("overwrite", name));
|
|
30
|
+
const response = await authFetch(fileApi(pid, "files/upload", { path: target }), { method: "POST", body: form });
|
|
31
|
+
const result = await response.json() as UploadResult & { error?: string };
|
|
32
|
+
if (!response.ok && (response.status !== 409 || !result.conflicts?.length)) throw new ApiError(response.status, result.error ?? "上传失败");
|
|
33
|
+
written.push(...result.files);
|
|
34
|
+
const completed = new Set(result.files.map((file) => file.split("/").at(-1)));
|
|
35
|
+
files = files.filter((file) => !completed.has(file.name));
|
|
36
|
+
if (!result.conflicts.length) break;
|
|
37
|
+
if (!(await confirm({ title: "覆盖同名文件?", description: `目标:${project?.path ?? pid}${target ? `/${target}` : ""}\n\n${result.conflicts.join("\n")}`, confirmLabel: "覆盖并上传", danger: true })).confirmed) break;
|
|
38
|
+
result.conflicts.forEach((name) => approved.add(name));
|
|
39
|
+
}
|
|
40
|
+
return written.length;
|
|
41
|
+
}, onMutate: () => setNotice(""), onSuccess: (count) => setNotice(count ? `已上传 ${count} 个文件` : "已取消上传"),
|
|
42
|
+
onSettled: () => {
|
|
43
|
+
refreshProjectImages(pid);
|
|
44
|
+
for (const key of ["files", "file", "search-files", "search-content", "git-status", "git-diff"]) void qc.invalidateQueries({ queryKey: [key, pid] });
|
|
45
|
+
} });
|
|
46
|
+
return <UploadContext.Provider value={{ root: project?.path, busy: upload.isPending, choose: (target) => { directory.current = target; input.current?.click(); } }}>
|
|
47
|
+
<input ref={input} type="file" multiple hidden aria-label="选择上传文件" disabled={upload.isPending} onChange={(event) => {
|
|
48
|
+
const files = Array.from(event.currentTarget.files ?? []);
|
|
49
|
+
event.currentTarget.value = "";
|
|
50
|
+
if (files.length) upload.mutate({ selected: files, target: directory.current });
|
|
51
|
+
}} />
|
|
52
|
+
{children}
|
|
53
|
+
{(upload.isPending || upload.error || notice) && <div role={upload.error ? "alert" : "status"} className={`shrink-0 border-t border-border px-3 py-2 text-xs ${upload.error ? "text-danger" : "text-muted"}`}>
|
|
54
|
+
{upload.isPending ? "正在上传…" : upload.error?.message ?? notice}
|
|
55
|
+
</div>}
|
|
56
|
+
</UploadContext.Provider>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function UploadButton({ directory = "", primary = false }: { directory?: string; primary?: boolean }) {
|
|
60
|
+
const upload = useContext(UploadContext);
|
|
61
|
+
return <Button size="sm" variant={primary ? "primary" : "secondary"} icon={<UploadIcon />} disabled={!upload || upload.busy} onClick={() => upload?.choose(directory)}>上传文件</Button>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function FileEntryActions({ pid, path, directory }: { pid: string; path: string; directory?: boolean }) {
|
|
65
|
+
const upload = useContext(UploadContext);
|
|
66
|
+
const [copied, setCopied] = useState(false), [error, setError] = useState<string>();
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (!copied) return;
|
|
69
|
+
const timer = setTimeout(() => setCopied(false), 1500);
|
|
70
|
+
return () => clearTimeout(timer);
|
|
71
|
+
}, [copied]);
|
|
72
|
+
const absolute = upload?.root ? path ? `${upload.root.replace(/[\\/]+$/, "")}/${path}` : upload.root : undefined;
|
|
73
|
+
const copy = async (text: string) => {
|
|
74
|
+
setCopied(false); setError(undefined);
|
|
75
|
+
try { await copyText(text); setCopied(true); }
|
|
76
|
+
catch (error) { setError(error instanceof Error ? error.message : "复制失败"); }
|
|
77
|
+
};
|
|
78
|
+
const name = path.split("/").at(-1) || "项目根目录";
|
|
79
|
+
return <>
|
|
80
|
+
<MenuPopover label={`${name} 更多操作`} trigger={(props) => <Button {...props} variant="ghost" size="sm" iconOnly title={error ?? (copied ? "已复制" : `${name} 更多操作`)} data-copied={copied || undefined}>
|
|
81
|
+
{error ? <AlertIcon className="text-danger" /> : copied ? <CheckIcon className="text-ok" /> : <MoreIcon />}
|
|
82
|
+
</Button>}>
|
|
83
|
+
<MenuItem icon={<CopyIcon />} disabled={!absolute} onClick={() => absolute && void copy(absolute)}>复制绝对路径</MenuItem>
|
|
84
|
+
<MenuItem icon={<CopyIcon />} onClick={() => void copy(path || ".")}>复制相对路径</MenuItem>
|
|
85
|
+
<MenuSeparator />
|
|
86
|
+
{directory ? <MenuItem icon={<UploadIcon />} disabled={!upload || upload.busy} onClick={() => upload?.choose(path)}>上传文件</MenuItem>
|
|
87
|
+
: <MenuItem icon={<DownloadIcon />} onClick={() => {
|
|
88
|
+
const link = document.createElement("a");
|
|
89
|
+
link.href = fileApi(pid, "file/download", { path }); link.download = name;
|
|
90
|
+
document.body.appendChild(link); link.click(); link.remove();
|
|
91
|
+
}}>下载文件</MenuItem>}
|
|
92
|
+
</MenuPopover>
|
|
93
|
+
<span className="sr-only" role={error ? "alert" : "status"}>{error ?? (copied ? "已复制" : "")}</span>
|
|
94
|
+
</>;
|
|
95
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
2
|
+
import { createPortal } from "react-dom";
|
|
3
|
+
import { useLocation } from "react-router";
|
|
4
|
+
import { Button } from "../ui/Button.tsx";
|
|
5
|
+
import { Modal } from "./Modal.tsx";
|
|
6
|
+
|
|
7
|
+
type Preview = { id: number; src: string; alt: string; bestEffort?: boolean };
|
|
8
|
+
let preview: Preview | null = null;
|
|
9
|
+
let nextId = 0;
|
|
10
|
+
const listeners = new Set<() => void>();
|
|
11
|
+
const subscribe = (listener: () => void) => { listeners.add(listener); return () => { listeners.delete(listener); }; };
|
|
12
|
+
const getPreview = () => preview;
|
|
13
|
+
|
|
14
|
+
export function openImagePreview(src: string, alt: string, bestEffort = false) {
|
|
15
|
+
preview = { id: ++nextId, src, alt, bestEffort };
|
|
16
|
+
for (const listener of listeners) listener();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function closeImagePreview() {
|
|
20
|
+
if (!preview) return;
|
|
21
|
+
preview = null;
|
|
22
|
+
for (const listener of listeners) listener();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Lives outside transcript rows so virtualization cannot close an open image. */
|
|
26
|
+
export function ImagePreview() {
|
|
27
|
+
const current = useSyncExternalStore(subscribe, getPreview);
|
|
28
|
+
const { pathname } = useLocation();
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
closeImagePreview();
|
|
31
|
+
return closeImagePreview;
|
|
32
|
+
}, [pathname]);
|
|
33
|
+
return current ? createPortal(<PreviewDialog key={current.id} preview={current} />, document.body) : null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function PreviewDialog({ preview }: { preview: Preview }) {
|
|
37
|
+
const [original, setOriginal] = useState(false);
|
|
38
|
+
const toggle = useRef<HTMLButtonElement>(null);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
const previous = document.activeElement;
|
|
41
|
+
const overflow = document.body.style.overflow;
|
|
42
|
+
document.body.style.overflow = "hidden";
|
|
43
|
+
toggle.current?.focus();
|
|
44
|
+
return () => {
|
|
45
|
+
document.body.style.overflow = overflow;
|
|
46
|
+
if (previous instanceof HTMLElement && previous.isConnected) previous.focus({ preventScroll: true });
|
|
47
|
+
};
|
|
48
|
+
}, []);
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<Modal title="图片预览" onClose={closeImagePreview} testId="image-preview" scrollBody={false} panelClassName="max-w-6xl!">
|
|
52
|
+
<div className="mb-3 flex shrink-0 justify-end">
|
|
53
|
+
<Button ref={toggle} size="sm" onClick={() => setOriginal(!original)} aria-pressed={original}>
|
|
54
|
+
{original ? "适应屏幕" : "原尺寸"}
|
|
55
|
+
</Button>
|
|
56
|
+
</div>
|
|
57
|
+
<div className="min-h-0 overflow-auto overscroll-contain rounded-lg bg-surface-2/50">
|
|
58
|
+
<img
|
|
59
|
+
src={preview.src}
|
|
60
|
+
alt={preview.alt}
|
|
61
|
+
onError={preview.bestEffort ? closeImagePreview : undefined}
|
|
62
|
+
className={`mx-auto block ${original ? "max-w-none" : "max-w-full object-contain"}`}
|
|
63
|
+
style={original ? undefined : { maxHeight: "calc(100dvh - var(--overlay-top) - var(--overlay-bottom) - 8rem)" }}
|
|
64
|
+
/>
|
|
65
|
+
</div>
|
|
66
|
+
</Modal>
|
|
67
|
+
);
|
|
68
|
+
}
|