@pi-chamber/web 1.0.3 → 1.0.4-rc.2
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/dist/assets/DiagramView-GKGxPczP.js +1 -0
- package/dist/assets/{DiffView-D19Jps0i.js → DiffView-Cay8VAqL.js} +6 -6
- package/dist/assets/FileSaveConflictDialog-BRM9TJo0.js +3 -0
- package/dist/assets/FilesView-CEeQzjc6.js +6 -0
- package/dist/assets/GitHubDetailScaffold-q4YP8iyJ.js +11 -0
- package/dist/assets/GitHubLinkPicker-B9xgIW8y.js +1 -0
- package/dist/assets/GitHubListPrimitives-XkALat1v.js +1 -0
- package/dist/assets/GitView-DV3d0oSJ.js +9 -0
- package/dist/assets/IssuesSurface-OTyt9f3A.js +7 -0
- package/dist/assets/JsonTreeView-X2Auiy_q.js +1 -0
- package/dist/assets/MarkdownRendererImpl-1HameF6j.js +12 -0
- package/dist/assets/PatchDiff-GMQAv4en.js +1 -0
- package/dist/assets/PierreDiffViewer-0X__nypk.js +134 -0
- package/dist/assets/PullRequestsSurface-Dec20SIg.js +2 -0
- package/dist/assets/SessionSwitcherContent-DEw4nz7K.js +1 -0
- package/dist/assets/SessionSwitcherDropdown-DmLhbRzE.js +2 -0
- package/dist/assets/SessionUnreadDot-CJFawQpo.js +1 -0
- package/dist/assets/SettingsView-CwSspvq-.js +6 -0
- package/dist/assets/SettingsWindow-DkPv9MaU.js +1 -0
- package/dist/assets/ToolOutputDialog-DDwbOpTO.js +8 -0
- package/dist/assets/ToolPartDiffPreview-DZRP7p-Q.js +1 -0
- package/dist/assets/{VirtualizedFileDiff-CJondRlh.js → VirtualizedFileDiff-CUWx7JVZ.js} +3 -3
- package/dist/assets/Virtualizer-wpC51ZBQ.js +1 -0
- package/dist/assets/collapsible-Ce85nuXX.js +1 -0
- package/dist/assets/computeVirtualFileMetrics-3PpRLd5B.js +3 -0
- package/dist/assets/{contextFileOpenGuard-CsZL8yie.js → contextFileOpenGuard-PoBklHMz.js} +1 -1
- package/dist/assets/gitStatusPredicates-BvzxqidP.js +1 -0
- package/dist/assets/githubLink-iQ51wqRa.js +10 -0
- package/dist/assets/index-CkMnC_GK.js +1 -0
- package/dist/assets/index-Dd2OcIUY.js +10 -0
- package/dist/assets/index-DvN8zlLT.css +1 -0
- package/dist/assets/main-FasHq7Ck.js +2 -0
- package/dist/assets/main-PSCt716b.js +136 -0
- package/dist/assets/markdownCore-BH56o6Wu.js +2 -0
- package/dist/assets/miniChat-BzfobBDq.js +2 -0
- package/dist/assets/mobile-DAzZE2EL.js +2 -0
- package/dist/assets/permissionStore-B9Hkrqny.js +1 -0
- package/dist/assets/pi-session-focus-preference-D2-1HWmY.js +10 -0
- package/dist/assets/renderDiffWithHighlighter-l8hZWWBO.js +1 -0
- package/dist/assets/renderElectronMiniChatApp-DGYSIihR.js +2 -0
- package/dist/assets/renderFileWithHighlighter-BvDoP7ob.js +1 -0
- package/dist/assets/renderMobileApp-CwgWG0lU.js +11 -0
- package/dist/assets/runtimeEndpointReset-CmI6dBKM.js +62 -0
- package/dist/assets/{runtimeSurface-BdndJV2m.js → runtimeSurface-B1GRkkKC.js} +1 -1
- package/dist/assets/shell-CjFT_Tl9.js +1 -0
- package/dist/assets/sprite-HGQGInUp.js +6510 -0
- package/dist/assets/useAppFontEffects--lKKtKVo.js +212 -0
- package/dist/assets/{useFilesViewSearch-DJ3psTKU.js → useFilesViewSearch-D1jsGQrN.js} +3 -3
- package/dist/assets/useGitHubRemoteSearch-zNgy2bSt.js +1 -0
- package/dist/assets/useSwitcherItems-OCRYcHeu.js +1 -0
- package/dist/assets/vendor-base-ui-DIkTOIJS.js +1 -0
- package/dist/assets/{vendor-beautiful-mermaid-D3YCkKz7.js → vendor-beautiful-mermaid-DApbjBp2.js} +1 -1
- package/dist/assets/vendor-boot-DyL2td56.js +69 -0
- package/dist/assets/vendor-codemirror-autocomplete-DsFn4GLp.js +1 -0
- package/dist/assets/vendor-codemirror-lang-angular-B_NMmBbS.js +1 -0
- package/dist/assets/vendor-codemirror-lang-cpp-GOE7Gjd0.js +1 -0
- package/dist/assets/vendor-codemirror-lang-css-Dwf2XpnZ.js +1 -0
- package/dist/assets/vendor-codemirror-lang-go-C2KHbcll.js +7 -0
- package/dist/assets/vendor-codemirror-lang-html-DcKqyeGk.js +1 -0
- package/dist/assets/vendor-codemirror-lang-java-6eGbyB2k.js +1 -0
- package/dist/assets/vendor-codemirror-lang-javascript-DpTUrvx8.js +13 -0
- package/dist/assets/vendor-codemirror-lang-jinja-xSUJjXhr.js +1 -0
- package/dist/assets/vendor-codemirror-lang-json-CLGxdOCz.js +1 -0
- package/dist/assets/vendor-codemirror-lang-less-6nXi1rS9.js +1 -0
- package/dist/assets/vendor-codemirror-lang-liquid-B9hmb9P8.js +1 -0
- package/dist/assets/vendor-codemirror-lang-markdown-DmFP9s6x.js +1 -0
- package/dist/assets/vendor-codemirror-lang-php-DC6To8iX.js +1 -0
- package/dist/assets/vendor-codemirror-lang-python-yuxIkjit.js +3 -0
- package/dist/assets/vendor-codemirror-lang-rust-di1Sjz-0.js +1 -0
- package/dist/assets/vendor-codemirror-lang-sass-BWpV9NPV.js +1 -0
- package/dist/assets/{vendor-codemirror-lang-sql-HpQWHJjv.js → vendor-codemirror-lang-sql-C_RazIaB.js} +2 -2
- package/dist/assets/vendor-codemirror-lang-vue-BYL0r7KR.js +1 -0
- package/dist/assets/vendor-codemirror-lang-wast-BiVarhcz.js +1 -0
- package/dist/assets/vendor-codemirror-lang-xml-Cn1lY1ts.js +1 -0
- package/dist/assets/vendor-codemirror-lang-yaml-BZ6mZw9L.js +1 -0
- package/dist/assets/vendor-codemirror-language-data-DglcKYWT.js +2 -0
- package/dist/assets/vendor-codemirror-search-DaE6R5gH.js +2 -0
- package/dist/assets/{vendor-elkjs-mzfkf0ML.js → vendor-elkjs-D27273Ms.js} +1 -1
- package/dist/assets/{vendor-heic2any-BHsbokcA.js → vendor-heic2any-pq-UTQQR.js} +1 -1
- package/dist/assets/vendor-lezer-cpp-Dt99h3WT.js +1 -0
- package/dist/assets/vendor-lezer-css-DNU_fzPI.js +1 -0
- package/dist/assets/vendor-lezer-go-BEFtcNyS.js +1 -0
- package/dist/assets/vendor-lezer-html-DDGRhRUz.js +1 -0
- package/dist/assets/vendor-lezer-java-DmfZtW09.js +1 -0
- package/dist/assets/vendor-lezer-javascript-oje4tdp_.js +1 -0
- package/dist/assets/vendor-lezer-json-BRXb_bDX.js +1 -0
- package/dist/assets/vendor-lezer-lr-BU2qmu_5.js +1 -0
- package/dist/assets/{vendor-lezer-markdown-C6g-d6P3.js → vendor-lezer-markdown-CicYv7V9.js} +4 -4
- package/dist/assets/vendor-lezer-php-COORrTpE.js +1 -0
- package/dist/assets/vendor-lezer-python-Cuvm9X9Y.js +1 -0
- package/dist/assets/vendor-lezer-rust-C_zOfHbX.js +1 -0
- package/dist/assets/vendor-lezer-sass-DWP4w7O1.js +1 -0
- package/dist/assets/vendor-lezer-xml-Br6nOYeG.js +1 -0
- package/dist/assets/vendor-lezer-yaml-CYQmm6Sb.js +1 -0
- package/dist/assets/{vendor-lru_map-Cy8fTs3_.js → vendor-lru_map-DOPmc7GU.js} +1 -1
- package/dist/assets/{vendor-qrcode-B0KNSajT.js → vendor-qrcode-Dv4uniC1.js} +1 -1
- package/dist/assets/vendor-react-DASdDPIk.js +1 -0
- package/dist/assets/{vendor-react-drawio-BYDptOsj.js → vendor-react-drawio-Duu5LgQA.js} +1 -1
- package/dist/assets/{vendor-replit-codemirror-vim-DaSwPsXt.js → vendor-replit-codemirror-vim-CZy3BUVv.js} +15 -15
- package/dist/assets/vendor-zustand-CUi8eEds.js +6 -0
- package/dist/assets/{web-components-CCKlju0Z.js → web-components-v9fuidaX.js} +4 -4
- package/dist/index.html +7 -9
- package/dist/mini-chat.html +6 -8
- package/dist/mobile.html +6 -8
- package/package.json +2 -2
- package/server/index.js +3 -1
- package/server/lib/fs/DOCUMENTATION.md +1 -1
- package/server/lib/fs/routes.js +1 -50
- package/server/lib/git/DOCUMENTATION.md +18 -11
- package/server/lib/git/index.js +8 -3
- package/server/lib/git/routes.js +0 -129
- package/server/lib/git/service.js +40 -152
- package/server/lib/git/service.test.js +42 -18
- package/server/lib/github/DOCUMENTATION.md +271 -0
- package/server/lib/github/cache.js +164 -0
- package/server/lib/github/checks.js +230 -0
- package/server/lib/github/client.js +305 -0
- package/server/lib/github/context.js +177 -0
- package/server/lib/github/contracts.test.js +235 -0
- package/server/lib/github/correctness.test.js +356 -0
- package/server/lib/github/credential.js +46 -0
- package/server/lib/github/errors.js +151 -0
- package/server/lib/github/gh-cli.js +336 -0
- package/server/lib/github/index.js +27 -0
- package/server/lib/github/issues.js +495 -0
- package/server/lib/github/pulls.js +699 -0
- package/server/lib/github/repo-scope.js +688 -0
- package/server/lib/github/routes.js +599 -0
- package/server/lib/github/security.test.js +275 -0
- package/server/lib/github/templates.js +153 -0
- package/server/lib/package-manager-detect-child.js +12 -0
- package/server/lib/package-manager.js +366 -92
- package/server/lib/package-manager.test.js +109 -0
- package/server/lib/pi/routes-extension-events.test.js +268 -4
- package/server/lib/pi/routes.js +109 -25
- package/server/lib/pi/routes.test.js +118 -0
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +24 -9
- package/server/lib/pi/session-daemon/builtin-extensions.js +37 -0
- package/server/lib/pi/session-daemon/daemon-process.js +6 -0
- package/server/lib/pi/session-daemon/extension-bridge-draft.test.js +222 -0
- package/server/lib/pi/session-daemon/extension-bridge.js +415 -42
- package/server/lib/pi/session-daemon/extension-name.js +87 -0
- package/server/lib/pi/session-daemon/extension-name.test.js +143 -0
- package/server/lib/pi/session-daemon/extension-theme.js +217 -0
- package/server/lib/pi/session-daemon/extension-theme.test.js +164 -0
- package/server/lib/pi/session-daemon/extension-tool-render.js +365 -0
- package/server/lib/pi/session-daemon/extension-tool-render.test.js +607 -0
- package/server/lib/pi/session-daemon/prompt-operations.test.js +3 -3
- package/server/lib/pi/session-daemon/prompt-preflight.test.js +12 -14
- package/server/lib/pi/session-daemon/sdk-upgrade.test.js +118 -2
- package/server/lib/pi/session-daemon/send-operation-dedup.test.js +1 -1
- package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +323 -3
- package/server/lib/pi/session-daemon/session-daemon-list-live.test.js +244 -0
- package/server/lib/pi/session-daemon/session-daemon-mcp.e2e.test.js +638 -0
- package/server/lib/pi/session-daemon/session-daemon-turn.e2e.test.js +437 -0
- package/server/lib/pi/session-daemon/session-daemon.js +265 -75
- package/server/lib/pi/session-daemon/session-daemon.test.js +271 -5
- package/server/lib/pi/session-daemon/session-idle-residency.test.js +1 -1
- package/server/lib/pi/session-daemon/session-replay.test.js +1 -1
- package/server/lib/pi/session-persistence-gap.test.js +2 -3
- package/server/lib/pi/ui-settings-store.js +2 -1
- package/server/lib/pi/ui-settings-store.test.js +27 -0
- package/server/lib/static-cache-control.js +18 -0
- package/server/lib/static-cache-control.test.js +25 -0
- package/server/lib/workspace/host.js +2 -0
- package/dist/assets/DiagramView-Bj1ZrdhI.js +0 -1
- package/dist/assets/FileSaveConflictDialog-2Z4V_gZU.js +0 -3
- package/dist/assets/FilesView-K18gBSws.js +0 -6
- package/dist/assets/GitView-Hm1KBPaD.js +0 -8
- package/dist/assets/JsonTreeView-fNsiZEIo.js +0 -1
- package/dist/assets/MarkdownRendererImpl-DV5Xkj8N.js +0 -12
- package/dist/assets/PatchDiff-DZaJG6jj.js +0 -1
- package/dist/assets/SessionSwitcherContent-RAsmsuYk.js +0 -1
- package/dist/assets/SessionSwitcherDropdown-DuLPlIF_.js +0 -2
- package/dist/assets/SessionUnreadDot-Dm6k5OCd.js +0 -1
- package/dist/assets/SettingsView-Chu4zbWo.js +0 -6
- package/dist/assets/SettingsWindow-CJzFmmfu.js +0 -1
- package/dist/assets/ToolOutputDialog-uYeXsAGc.js +0 -8
- package/dist/assets/ToolPartDiffPreview-DnAHVRs-.js +0 -1
- package/dist/assets/Virtualizer-BSHVMKgK.js +0 -1
- package/dist/assets/collapsible-BH1vXEAI.js +0 -1
- package/dist/assets/computeVirtualFileMetrics-DXkR5jdw.js +0 -3
- package/dist/assets/gitStatusPredicates-BW8heN1a.js +0 -134
- package/dist/assets/index-5fyXnZFi.css +0 -1
- package/dist/assets/index-BrgKwTb0.js +0 -1
- package/dist/assets/index-C-sV_9sb.js +0 -8
- package/dist/assets/isDiffPlainText-DZFr1Tta.js +0 -1
- package/dist/assets/isFilePlainText-KNpEMvb-.js +0 -1
- package/dist/assets/main-BPY2ug1A.js +0 -135
- package/dist/assets/main-BRIjzIRl.js +0 -2
- package/dist/assets/markdownCore-DYizLr1N.js +0 -3
- package/dist/assets/miniChat-Dva4MINl.js +0 -2
- package/dist/assets/mobile-6jNUNv_x.js +0 -2
- package/dist/assets/permissionStore-iKN1K2_x.js +0 -1
- package/dist/assets/renderElectronMiniChatApp-BIeBrZmO.js +0 -2
- package/dist/assets/renderMobileApp-BDCtZpeS.js +0 -11
- package/dist/assets/runtimeEndpointReset-DqdGOWp8.js +0 -53
- package/dist/assets/useAppFontEffects-BABx-DxZ.js +0 -6722
- package/dist/assets/usePushVisibilityBeacon-BciEu3HS.js +0 -10
- package/dist/assets/useSwitcherItems-C7_5TB_n.js +0 -1
- package/dist/assets/vendor-aria-hidden-DvXkyWUv.js +0 -1
- package/dist/assets/vendor-base-ui-DXSHfszQ.js +0 -1
- package/dist/assets/vendor-class-variance-authority-5VPnzWs2.js +0 -1
- package/dist/assets/vendor-cmdk-zXx6sGnS.js +0 -1
- package/dist/assets/vendor-codemirror-autocomplete-wd6iRebq.js +0 -1
- package/dist/assets/vendor-codemirror-commands-CNlncqrr.js +0 -1
- package/dist/assets/vendor-codemirror-lang-angular-DU_4KiiW.js +0 -1
- package/dist/assets/vendor-codemirror-lang-cpp-CmIT9Z5_.js +0 -1
- package/dist/assets/vendor-codemirror-lang-css-djiuoTi8.js +0 -1
- package/dist/assets/vendor-codemirror-lang-go-COZSwZYW.js +0 -7
- package/dist/assets/vendor-codemirror-lang-html-CKHqhW5R.js +0 -1
- package/dist/assets/vendor-codemirror-lang-java-CNMP5hyC.js +0 -1
- package/dist/assets/vendor-codemirror-lang-javascript-DuOEwJ3f.js +0 -13
- package/dist/assets/vendor-codemirror-lang-jinja-DaKn_b1k.js +0 -1
- package/dist/assets/vendor-codemirror-lang-json-CZ07HmNC.js +0 -1
- package/dist/assets/vendor-codemirror-lang-less-wJdQiDBf.js +0 -1
- package/dist/assets/vendor-codemirror-lang-liquid-0z48Roi8.js +0 -1
- package/dist/assets/vendor-codemirror-lang-markdown-DtcZDGqe.js +0 -1
- package/dist/assets/vendor-codemirror-lang-php-W8plS-JQ.js +0 -1
- package/dist/assets/vendor-codemirror-lang-python-DzzokVau.js +0 -3
- package/dist/assets/vendor-codemirror-lang-rust-C4ulBVpf.js +0 -1
- package/dist/assets/vendor-codemirror-lang-sass-BkZJYEwS.js +0 -1
- package/dist/assets/vendor-codemirror-lang-vue-DiBPljCc.js +0 -1
- package/dist/assets/vendor-codemirror-lang-wast-DoABsogh.js +0 -1
- package/dist/assets/vendor-codemirror-lang-xml-BhLJhOCH.js +0 -1
- package/dist/assets/vendor-codemirror-lang-yaml-D95i1Y5R.js +0 -1
- package/dist/assets/vendor-codemirror-language-BByA_dGF.js +0 -3
- package/dist/assets/vendor-codemirror-language-data-BB5mQv-R.js +0 -2
- package/dist/assets/vendor-codemirror-search-BV44140v.js +0 -2
- package/dist/assets/vendor-codemirror-state-CNWM3Q8V.js +0 -5
- package/dist/assets/vendor-codemirror-view-Ct4T37Ue.js +0 -4
- package/dist/assets/vendor-crelt-C8TCjufn.js +0 -1
- package/dist/assets/vendor-detect-node-es-l0sNRNKZ.js +0 -1
- package/dist/assets/vendor-dnd-kit-accessibility-DZKKhs9S.js +0 -1
- package/dist/assets/vendor-dnd-kit-core-C9qcAm_1.js +0 -5
- package/dist/assets/vendor-dnd-kit-sortable-D8ozj8M-.js +0 -1
- package/dist/assets/vendor-dnd-kit-utilities-DTY1C6ST.js +0 -1
- package/dist/assets/vendor-floating-ui-core-CXmKXOXc.js +0 -1
- package/dist/assets/vendor-floating-ui-dom-WyXykhNi.js +0 -1
- package/dist/assets/vendor-floating-ui-react-dom-BZOGXAGe.js +0 -1
- package/dist/assets/vendor-floating-ui-utils-BzXdqYpP.js +0 -1
- package/dist/assets/vendor-framer-motion-CfplGuM0.js +0 -1
- package/dist/assets/vendor-get-nonce-C-Z93AgS.js +0 -1
- package/dist/assets/vendor-lezer-common-B3-cUCR_.js +0 -1
- package/dist/assets/vendor-lezer-cpp-BleAU9o-.js +0 -1
- package/dist/assets/vendor-lezer-css-C5xB6jxd.js +0 -1
- package/dist/assets/vendor-lezer-go-CXK1UKk8.js +0 -1
- package/dist/assets/vendor-lezer-highlight-CDMHUZ74.js +0 -1
- package/dist/assets/vendor-lezer-html-C0I1p52t.js +0 -1
- package/dist/assets/vendor-lezer-java-D_zzj-NV.js +0 -1
- package/dist/assets/vendor-lezer-javascript-D7Tj24ot.js +0 -1
- package/dist/assets/vendor-lezer-json-Iaex0UN-.js +0 -1
- package/dist/assets/vendor-lezer-lr-bhwg1HMg.js +0 -1
- package/dist/assets/vendor-lezer-php-_DHrbsZG.js +0 -1
- package/dist/assets/vendor-lezer-python-CvuFxeZl.js +0 -1
- package/dist/assets/vendor-lezer-rust-Lqgd5SAo.js +0 -1
- package/dist/assets/vendor-lezer-sass-Dnm2lY4t.js +0 -1
- package/dist/assets/vendor-lezer-xml-hUDuAyS5.js +0 -1
- package/dist/assets/vendor-lezer-yaml-BNIl6S_O.js +0 -1
- package/dist/assets/vendor-marijn-find-cluster-break-DXwl3gUT.js +0 -1
- package/dist/assets/vendor-motion-dom-DhJ-sYS5.js +0 -1
- package/dist/assets/vendor-motion-l0sNRNKZ.js +0 -1
- package/dist/assets/vendor-motion-utils-CKEGc_YG.js +0 -1
- package/dist/assets/vendor-radix-ui-primitive-Dc_FVRD7.js +0 -1
- package/dist/assets/vendor-radix-ui-react-compose-refs-8xy6TJML.js +0 -1
- package/dist/assets/vendor-radix-ui-react-context-CFsX-AUC.js +0 -1
- package/dist/assets/vendor-radix-ui-react-dialog-D2yhEu2p.js +0 -5
- package/dist/assets/vendor-radix-ui-react-dismissable-layer-DrorBNg9.js +0 -1
- package/dist/assets/vendor-radix-ui-react-focus-guards-BfdFmL7c.js +0 -1
- package/dist/assets/vendor-radix-ui-react-focus-scope-D2BkImwt.js +0 -1
- package/dist/assets/vendor-radix-ui-react-id-D2kS9K1j.js +0 -1
- package/dist/assets/vendor-radix-ui-react-portal-YgCRIyi7.js +0 -1
- package/dist/assets/vendor-radix-ui-react-presence-D432pCMB.js +0 -1
- package/dist/assets/vendor-radix-ui-react-primitive-DkH8dMOR.js +0 -1
- package/dist/assets/vendor-radix-ui-react-slot-BIDFZX0-.js +0 -1
- package/dist/assets/vendor-radix-ui-react-use-callback-ref-BwDcSoGV.js +0 -1
- package/dist/assets/vendor-radix-ui-react-use-controllable-state-LiqmKSXO.js +0 -1
- package/dist/assets/vendor-radix-ui-react-use-effect-event-D94va83M.js +0 -1
- package/dist/assets/vendor-radix-ui-react-use-escape-keydown-DTkqjenV.js +0 -1
- package/dist/assets/vendor-radix-ui-react-use-layout-effect-C8Yrsaph.js +0 -1
- package/dist/assets/vendor-react-B5Z1Mdn3.js +0 -9
- package/dist/assets/vendor-react-remove-scroll-bar-CSAHp1YF.js +0 -38
- package/dist/assets/vendor-react-remove-scroll-vR1dy1aP.js +0 -4
- package/dist/assets/vendor-react-style-singleton-Ctw6HnYx.js +0 -1
- package/dist/assets/vendor-reselect-l0sNRNKZ.js +0 -1
- package/dist/assets/vendor-scheduler-7OC5HNn7.js +0 -1
- package/dist/assets/vendor-simplewebauthn-browser-VDA66rT_.js +0 -2
- package/dist/assets/vendor-sonner-BDtm25td.js +0 -1
- package/dist/assets/vendor-style-mod-NZ5MEPvj.js +0 -3
- package/dist/assets/vendor-tanstack-react-virtual-2skouoFw.js +0 -1
- package/dist/assets/vendor-tanstack-virtual-core-Dubg10g5.js +0 -1
- package/dist/assets/vendor-tslib-De9GV7Vy.js +0 -1
- package/dist/assets/vendor-use-callback-ref-CVVuCyLj.js +0 -1
- package/dist/assets/vendor-use-sidecar-Vv4V8Nd1.js +0 -1
- package/dist/assets/vendor-use-sync-external-store-D0AXkdQC.js +0 -1
- package/dist/assets/vendor-w3c-keyname-Vcq4gwWv.js +0 -1
- package/dist/assets/vendor-zustand-GVb4H8HE.js +0 -6
- package/server/lib/git/credentials.js +0 -41
- package/server/lib/git/identity-storage.js +0 -122
- /package/dist/assets/{vendor-katex-CNckGUMB.js → vendor-katex-DZG0Ov6p.js} +0 -0
- /package/dist/assets/{vendor-katex-Cp579UoJ.css → vendor-katex-css-Cp579UoJ.css} +0 -0
- /package/dist/assets/{vendor-xterm-xterm-CrXqRur4.js → vendor-xterm-xterm-B-qIQCd3.js} +0 -0
- /package/dist/assets/{vendor-xterm-xterm-DDGTF8rc.css → vendor-xterm-xterm-css-DDGTF8rc.css} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as c}from"./vendor-boot-DyL2td56.js";import{R as t}from"./vendor-react-DASdDPIk.js";import{p as $,t as d,I as A}from"./useAppFontEffects--lKKtKVo.js";import{t as V,a as G,A as ee,bX as W}from"./index-Dd2OcIUY.js";import{b as te,D as re,F as ne}from"./FileSaveConflictDialog-BRM9TJo0.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-zustand-CUi8eEds.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./runtimeSurface-B1GRkkKC.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-react-drawio-Duu5LgQA.js";const se=l=>l.split("/").pop()||l;function ye(){const{files:l}=$(),[x,k]=t.useState(null),[L,R]=t.useState(""),[M,E]=t.useState(!0),[b,h]=t.useState(null),[m,F]=t.useState(!1),[U,p]=t.useState(!1),[j,P]=t.useState(!1),[q,H]=t.useState(0),g=t.useRef(void 0),C=t.useRef(""),v=t.useRef(0),S=t.useRef(0),y=t.useRef(0),D=t.useRef(null),I=t.useRef(!0),w=t.useRef(null),T=V(e=>e.pendingDiagramFile);t.useEffect(()=>(I.current=!0,()=>{I.current=!1}),[]);const i=t.useCallback((e,n,s)=>I.current&&v.current===e&&G()===n&&w.current===s,[]),K=t.useCallback(async e=>{const n=v.current+1;v.current=n;const s=G(),u=l?.readFile;S.current+=1,y.current+=1,E(!0),k(e),w.current=e,h(null),p(!1),P(!1),F(!1);try{const r=await u?.(e);if(!i(n,s,e))return;if(!r){d.error("Failed to read file"),k(null),w.current=null,C.current="",R(""),g.current=void 0,E(!1);return}C.current=r.content,R(r.content),g.current=r.revision}catch(r){if(!i(n,s,e))return;d.error(r instanceof Error?r.message:"Failed to read file"),k(null),w.current=null,C.current="",R(""),g.current=void 0,E(!1);return}finally{i(n,s,e)&&E(!1)}},[l,i]);t.useEffect(()=>ee(()=>{if(v.current+=1,g.current=void 0,S.current+=1,y.current+=1,!I.current)return;h(null),p(!1),P(!1),F(!1);const e=w.current;e&&K(e)}),[K]),t.useEffect(()=>{if(!T)return;const e=V.getState().consumePendingDiagramFile();e&&K(e)},[K,T]);const X=t.useCallback(async(e,n,s,u,r,o)=>{let a=null,f=s,B=u;try{if(B){const N=await l?.readFile?.(e);if(!i(r,o,e))return;N&&(a=N.content??null,typeof N.revision=="string"&&(f=N.revision),B=N.exists!==!1)}}catch{if(!i(r,o,e))return}i(r,o,e)&&(h({path:e,displayPath:se(e),exists:B,currentRevision:f,currentContent:a,dirtyContent:n,runtimeKey:o}),p(!1))},[l,i]),z=t.useCallback(async(e,n,s,u,r)=>{const o=await l?.writeFile?.(e,n,te(g.current,s?!0:void 0));return i(u,r,e)?{stale:!1,success:!!o?.success,revision:o?.revision}:{stale:!0}},[l,i]),O=t.useCallback((e,n)=>{C.current=e,typeof n<"u"&&(g.current=n),D.current?.getXml()===e&&R(e)},[]),J=t.useCallback(async()=>{const e=D.current?.getXml();if(!x||!l?.writeFile||!e||e===C.current||j||m)return;const n=v.current,s=G(),u=x,r=e,o=S.current+1;S.current=o,P(!0);try{const a=await z(u,r,!1,n,s);if(a.stale)return;if(!a.success){d.error("Failed to write file");return}O(r,a.revision)}catch(a){if(!i(n,s,u))return;if(W(a)){await X(u,r,a.currentRevision??null,a.exists,n,s);return}d.error(a instanceof Error?a.message:"Save failed")}finally{S.current===o&&P(!1)}},[O,x,l,i,m,j,X,z]),Q=t.useCallback(async()=>{const e=b;if(!e||m||!i(v.current,e.runtimeKey,e.path))return;const n=v.current,s=e.runtimeKey;if(!e.exists){k(null),w.current=null,C.current="",R(""),g.current=void 0,h(null),p(!1);return}const u=y.current+1;y.current=u,F(!0);try{const r=await l?.readFile?.(e.path);if(!i(n,s,e.path))return;if(!r){d.error("Failed to read file");return}C.current=r.content??"",R(r.content??""),g.current=r.revision,H(o=>o+1),h(null),p(!1)}catch(r){if(!i(n,s,e.path))return;d.error(r instanceof Error?r.message:"Failed to read file")}finally{y.current===u&&F(!1)}},[l,i,m,b]),Y=t.useCallback(async()=>{const e=b;if(!e||m||!i(v.current,e.runtimeKey,e.path))return;const n=v.current,s=e.runtimeKey;if(!l?.writeFile){d.error("Saving not supported");return}const o=D.current?.getXml()??e.dirtyContent;if(!o){d.error("Failed to write file");return}const a=y.current+1;y.current=a,F(!0);try{const f=await z(e.path,o,!0,n,s);if(f.stale)return;if(!f.success){d.error("Failed to write file");return}O(o,f.revision),h(null),p(!1)}catch(f){if(!i(n,s,e.path))return;if(W(f)){await X(e.path,o,f.currentRevision??e.currentRevision,f.exists,n,s);return}d.error(f instanceof Error?f.message:"Save failed")}finally{y.current===a&&F(!1)}},[O,l,i,m,X,z,b]),Z=t.useCallback(()=>{m||j||(h(null),p(!1))},[m,j]),_=x?x.split("/").pop()||x:"";return x?M?c.jsx("div",{className:"flex h-full items-center justify-center p-3",children:c.jsx(A,{name:"loader-4",className:"size-4 animate-spin"})}):c.jsxs("div",{className:"flex h-full flex-col",children:[c.jsxs("div",{className:"flex items-center gap-2 border-b border-border/30 px-3 py-1.5",children:[c.jsx(A,{name:"file",className:"size-4 shrink-0 text-muted-foreground"}),c.jsx("span",{className:"typography-ui text-muted-foreground truncate flex-1",children:_}),c.jsx("button",{type:"button",onClick:()=>{J()},className:"size-6 flex items-center justify-center rounded-md text-foreground hover:bg-interactive-hover/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",title:"Save diagram",children:c.jsx(A,{name:"save-3",className:"size-4"})}),c.jsx("button",{type:"button",onClick:()=>V.getState().setActiveMainTab("chat"),className:"size-6 flex items-center justify-center rounded-md text-muted-foreground hover:bg-interactive-hover/50 hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",title:"Close diagram view",children:c.jsx(A,{name:"close",className:"size-4"})})]}),c.jsx("div",{className:"flex-1 min-h-0",children:c.jsx(re,{ref:D,xml:L,className:"h-full"},q)}),c.jsx(ne,{open:!!b,conflict:b,isResolving:m||j,showCompare:U,onToggleCompare:()=>p(e=>!e),onReload:()=>{Q()},onOverwrite:()=>{Y()},onClose:Z})]}):c.jsx("div",{className:"flex h-full items-center justify-center p-3",children:c.jsx("div",{className:"typography-ui text-muted-foreground",children:"Pick a file from the tree."})})}export{ye as DiagramView};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{j as n,
|
|
1
|
+
import{j as n,aH as St}from"./vendor-boot-DyL2td56.js";import{R as r}from"./vendor-react-DASdDPIk.js";import{o as se,t as Q,a as Ze,C as ze}from"./index-Dd2OcIUY.js";import{dN as vt,dv as Ct,dL as jt,aj as et,a7 as tt,ck as Nt,cl as Ne,B as Le,I as J,p as nt,aD as oe,t as st,dD as it,ce as Lt,dO as Dt,dP as kt,n as Rt,a4 as Et,ay as At,ah as Tt,cF as Mt,f as It,at as $t,aM as Pt,a9 as _t,aa as Wt,ac as Bt}from"./useAppFontEffects--lKKtKVo.js";import{d as rt,i as Ge,a as He,b as Ot,C as zt}from"./gitStatusPredicates-BvzxqidP.js";import{p as Gt}from"./VirtualizedFileDiff-CUWx7JVZ.js";import{P as Ht}from"./PierreDiffViewer-0X__nypk.js";import{v as Ut,g as Vt}from"./contextFileOpenGuard-PoBklHMz.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-zustand-CUi8eEds.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./runtimeSurface-B1GRkkKC.js";import"./web-components-v9fuidaX.js";import"./computeVirtualFileMetrics-3PpRLd5B.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./themeResolver-yJ9XpNMI.js";import"./vendor-pierre-theming-Dgp7B_O4.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./renderDiffWithHighlighter-l8hZWWBO.js";import"./vendor-diff-C3JhlQdm.js";import"./runtimeEndpointReset-CmI6dBKM.js";import"./SessionUnreadDot-CJFawQpo.js";/* empty css */import"./permissionStore-B9Hkrqny.js";import"./appThemeRegistry-gegrE2dq.js";import"./registerCustomTheme-DmolaWWZ.js";function Kt(t,s=10){const e=[];let i;for(const l of t.split(`
|
|
2
2
|
`)){const p=l.match(vt);if(p!=null){i!=null&&(i.hunkLines.length>0&&(Re(i,s,"trailing"),Ie(i,e)),i=void 0);const u=parseInt(p[3]),b=parseInt(p[1]),g=parseInt(p[4]??"1"),c=parseInt(p[2]??"1");isNaN(u)||isNaN(b)||isNaN(g)||isNaN(c)?e.push(l):i={additionStart:u,deletionStart:b,additionCount:0,deletionCount:0,hunkLines:[],contextLines:[]};continue}if(i==null){e.push(l);continue}if(l.startsWith(" "))i.contextLines.push(l);else if(l!==""){if(i.hunkLines.length>0&&i.contextLines.length>s*2){const u=i.contextLines.length-s*2,b=i.contextLines.slice(-s);Re(i,s,"trailing");const{additionCount:g,deletionCount:c}=i;Ie(i,e),i={additionStart:i.additionStart+g+u,deletionStart:i.deletionStart+c+u,deletionCount:0,additionCount:0,contextLines:b,hunkLines:[]}}Re(i,s,i.hunkLines.length===0?"leading":"before-change"),i.hunkLines.push(l),l.startsWith("+")?i.additionCount+=1:l.startsWith("-")&&(i.deletionCount+=1)}}i!=null&&i.hunkLines.length>0&&(Re(i,s,"trailing"),Ie(i,e));const a=e.join(`
|
|
3
3
|
`);return t.endsWith(`
|
|
4
4
|
`)?`${a}
|
|
@@ -6,13 +6,13 @@ import{j as n,R as r,b as St}from"./vendor-react-B5Z1Mdn3.js";import{o as se,t a
|
|
|
6
6
|
===================================================================
|
|
7
7
|
--- ${t}
|
|
8
8
|
+++ ${t}
|
|
9
|
-
${s}`,Qt=t=>{if(!t.startsWith("diff --git ")&&!/^--- [^\n]*\t?\r?\n\+\+\+ [^\n]*\t?(?:\r?\n|$)/m.test(t))return;const s=[...t.matchAll(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@[^\n]*(?:\r?\n|$)/gm)];if(s.length!==1)return;const e=s[0],i=Number.parseInt(e[1]??"",10),a=Number.parseInt(e[2]??"",10);if(i>1||a>1||!Number.isFinite(i)||!Number.isFinite(a))return;const l=(e.index??0)+e[0].length,p=t.slice(l),u=[],b=[];let g;for(const c of p.split(/\r?\n/)){if(c.startsWith("diff --git ")||c.startsWith("@@ "))break;if(c.startsWith("\\")){if(g==="-"||g===" "){const
|
|
10
|
-
`:"")).join(""),Ke=t=>Ht({name:t,contents:""},{name:t,contents:""}),Zt=t=>/^Binary files .+ differ$/m.test(t)||/^GIT binary patch$/m.test(t),Pe=(t,s,e)=>Zt(s)?{original:"",modified:"",isBinary:!0,patch:s,contextMode:e}:{original:"",modified:"",patch:s,fileDiff:Yt(t,s),contextMode:e},ot=(t,s,e)=>{const i=t??0,a=s??0;return!i&&!a?null:n.jsxs("span",{className:se("typography-meta flex items-center gap-1 text-xs whitespace-nowrap","flex-shrink-0",e?.className),children:[i?n.jsxs("span",{style:{color:"var(--status-success)"},children:["+",i]}):null,a?n.jsxs("span",{style:{color:"var(--status-error)"},children:["-",a]}):null]})},en=r.memo(function({changedFiles:s,selectedFile:e,onSelectFile:i}){return s.length===0?null:n.jsx(et,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:n.jsx("ul",{className:"flex flex-col gap-1",children:s.map(a=>{const l=rt(a),p=e===a.path;return n.jsx("li",{children:n.jsxs("button",{type:"button",onClick:()=>i(a.path),className:se("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",p?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[n.jsx(tt,{filePath:a.path,className:"h-3.5 w-3.5 flex-shrink-0"}),n.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:l.color},title:l.description,"aria-label":l.description,children:l.code}),n.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:a.path,children:a.path}),ot(a.insertions,a.deletions)]})},a.path)})})})}),tn=r.memo(function(){return n.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:n.jsx("div",{className:"typography-meta text-muted-foreground",children:"Content of this file cannot be viewed."})})}),nn=r.memo(function({filePath:s,diff:e,renderSideBySide:i}){const a=e.original.length>0,l=e.modified.length>0,p=i?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",u=i?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";return n.jsx("div",{className:"w-full overflow-auto p-4",style:{contain:"layout"},children:n.jsxs("div",{className:p,children:[a&&n.jsxs("div",{className:u,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:"Original"}),n.jsx("img",{src:e.original,alt:`Original: ${s}`,className:i?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),l&&n.jsxs("div",{className:u,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:a?"Modified":"New"}),n.jsx("img",{src:e.modified,alt:`Modified: ${s}`,className:i?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]})]})})}),sn=r.memo(function({filePath:s,diff:e,renderSideBySide:i,wrapLines:a}){const l=r.useMemo(()=>Nt(s)||"text",[s]);return e.isBinary?n.jsx(tn,{}):Ne(s)?n.jsx(nn,{filePath:s,diff:e,renderSideBySide:i}):n.jsx("div",{className:"w-full",style:{contain:"layout"},children:n.jsx(Ot,{original:e.original,modified:e.modified,fileDiff:e.fileDiff,language:l,fileName:s,renderSideBySide:i,wrapLines:a,layout:"inline"})})}),$e=({label:t,icon:s,loading:e,disabled:i,tone:a,onClick:l})=>n.jsx(Le,{variant:"ghost",size:"sm",className:se("h-6 w-6 rounded-none bg-transparent p-0 text-muted-foreground opacity-70 hover:bg-transparent hover:text-foreground hover:opacity-100",a==="failure"&&"text-[var(--status-error)] hover:text-[var(--status-error)]",a==="success"&&"text-[var(--status-success)] hover:text-[var(--status-success)]"),disabled:i,title:t,"aria-label":t,onClick:p=>{p.stopPropagation(),l()},children:e?n.jsx(J,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(J,{name:s,className:s==="add"?"size-4":"size-3.5"})}),rn=r.memo(function({filePath:s,staged:e,busyAction:i,disabled:a,onAction:l}){return n.jsx("div",{className:"flex items-center gap-0.5 rounded-full border border-[var(--interactive-border)]/45 bg-[var(--surface-background)]/95 px-1 py-0.5 shadow-sm backdrop-blur-md",children:e?n.jsx($e,{label:`Unstage ${s}`,icon:"arrow-go-back",loading:i==="unstage",disabled:a,onClick:()=>l("unstage")}):n.jsxs(n.Fragment,{children:[n.jsx($e,{label:`Revert changes in ${s}`,icon:"arrow-go-back",loading:i==="discard",disabled:a,tone:"failure",onClick:()=>l("discard")}),n.jsx($e,{label:`Stage ${s}`,icon:"add",loading:i==="stage",disabled:a,tone:"success",onClick:()=>l("stage")})]})})}),at=3,on=1e6,an=15e3,qe=500,ln=r.memo(function({directory:s,file:e,layout:i,wrapLines:a,isSelected:l,isExpanded:p,isMounted:u,onSelect:b,onExpandedChange:g,registerSectionRef:c,showOpenInEditorAction:m=!1,isOpeningInEditor:w=!1,onOpenInEditor:k,staged:x=!1,showFileActions:C=!0,loadFullFiles:h=!1,initialDiffData:d=null}){const{git:_}=nt(),B=oe(r.useCallback(f=>f.directories.get(s)?.diffCache.get(e.path)??null,[s,e.path])),$=oe(f=>f.setDiff),j=oe(f=>f.fetchStatus),H=Q(f=>f.setDiffFileLayout),[F,y]=r.useState(0),[N,R]=r.useState(null),[A,M]=r.useState(!1),[L,W]=r.useState(null),[U,Z]=r.useState(!1),[ie,fe]=r.useState(null),[E,I]=r.useState(null),V=r.useRef(null),pe=r.useRef(null),O=r.useMemo(()=>rt(e),[e]),ae=i==="side-by-side",Y=h?"full":"patch",q=`${e.index}:${e.working_dir}:${e.insertions}:${e.deletions}`,X=r.useMemo(()=>d||(x?E:ie||(B?{original:B.original,modified:B.modified,isBinary:B.isBinary,contextMode:"full"}:null)),[B,d,ie,x,E]),me=X?.contextMode===Y,ve=r.useCallback(f=>{pe.current=f,c(e.path,f)},[e.path,c]),re=r.useCallback(f=>{g(e.path,f)},[e.path,g]),he=r.useCallback(()=>{b(e.path)},[e.path,b]);r.useEffect(()=>{x?I(null):fe(null),R(null),V.current=null},[q,x]),r.useEffect(()=>{if(!p||!u)return;if(!s||d||X&&me){V.current=null,M(!1);return}const f=`${s}::${e.path}::${x?"staged":"unstaged"}::${q}::${Y}::${F}`;if(V.current===f)return;V.current=f,R(null),M(!0);let P=!1;const ee=Ze(),xe=h?on:at,ce=Ne(e.path)?_.getGitFileDiff(s,{path:e.path,staged:x}):_.getGitDiff(s,{path:e.path,staged:x,contextLines:xe}),te=an,be=new Promise((K,z)=>{setTimeout(()=>z(new Error(`Timed out after ${te}ms`)),te)});return Promise.race([ce,be]).then(K=>{if(!P){if("diff"in K){const z=Pe(e.path,K.diff,Y);x?I(z):fe(z)}else{const z={original:K.original??"",modified:K.modified??"",isBinary:K.isBinary,contextMode:"full"};x?I(z):$(s,e.path,z,ee)}M(!1)}}).catch(K=>{if(P)return;const z=K instanceof Error?K.message:String(K);R(z),M(!1)}),()=>{P=!0,V.current===f&&(V.current=null)}},[Y,X,me,F,s,e.path,q,_,d,p,u,h,$,x]);const ge=r.useCallback(()=>{re(!p),he()},[re,he,p]),le=r.useCallback(async f=>{if(!(!s||L!==null)){W(f);try{f==="stage"?await _.stageGitFile(s,e.path):f==="unstage"?await _.unstageGitFile(s,e.path):await _.revertGitFile(s,e.path,{scope:"working"}),y(P=>P+1),await j(s,_)}catch(P){const ee=f==="unstage"?"Failed to unstage changes":f==="stage"?"Failed to stage changes":"Failed to revert changes";st.error(P instanceof Error?P.message:ee)}finally{W(P=>P===f?null:P)}}},[s,j,e.path,L,_]);return n.jsxs("div",{ref:ve,className:se("scroll-mt-9 border-b border-[var(--interactive-border)]/40 last:border-b-0"),children:[n.jsx("div",{className:se("z-30 border-b border-[var(--interactive-border)]/35 bg-[var(--surface-elevated)]/90 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--surface-elevated)]/80","sticky top-0"),children:n.jsxs("div",{role:"button",tabIndex:0,onClick:ge,onKeyDown:f=>{f.target===f.currentTarget&&(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),ge())},className:se("cursor-pointer","group/header relative grid min-h-9 w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2 overflow-hidden px-3 py-2","bg-transparent","text-muted-foreground hover:text-foreground",l?"bg-[var(--interactive-selection)]/35":null),children:[n.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-[var(--interactive-hover)]/50"}),n.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[n.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:p?n.jsx(J,{name:"arrow-down-s",className:"size-4"}):n.jsx(J,{name:"arrow-right-s",className:"size-4"})}),n.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:{color:O.color},title:O.description,"aria-label":O.description,children:O.code}),n.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:e.path,children:n.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(tt,{filePath:e.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),(()=>{const f=e.path.lastIndexOf("/");if(f===-1)return n.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:e.path});const P=e.path.slice(0,f),ee=e.path.slice(f+1);return n.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[n.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:P}),n.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[n.jsx("span",{className:"text-muted-foreground",children:"/"}),n.jsx("span",{className:"text-foreground",children:ee})]})]})})()]})})]}),n.jsxs("div",{className:"relative flex shrink-0 items-center justify-self-end gap-2",children:[ot(e.insertions,e.deletions),m&&k?n.jsx(Le,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:"Open this file in editor at change",onClick:f=>{f.stopPropagation(),k(e.path,X)},disabled:w,children:w?n.jsx(J,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(J,{name:"edit",className:"size-3.5"})}):null,n.jsx(it,{mode:ae?"side-by-side":"unified",onModeChange:f=>{const P=f==="side-by-side"?"side-by-side":"inline";H(e.path,P)},className:"opacity-70"})]})]})}),p&&n.jsxs("div",{className:"relative overflow-hidden bg-background",children:[!u&&!N?n.jsx("div",{className:"h-40 border border-border/40 bg-background/40"}):null,N?n.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:"Failed to load diff"}),n.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:N}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>y(f=>f+1),children:"Retry"})]}):null,u&&A&&!X&&!N?n.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx(J,{name:"loader-4",className:"size-4 animate-spin"}),"Loading diff..."]}):null,u&&X&&!U&&e.insertions+e.deletions>qe?n.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:`Large diff (${e.insertions+e.deletions} changed lines)`}),n.jsx("div",{className:"typography-meta text-muted-foreground",children:"Rendering may be slow. You can still view the diff by clicking below."}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>Z(!0),children:"Render anyway"})]}):null,u&&X&&(U||e.insertions+e.deletions<=qe)?n.jsxs(n.Fragment,{children:[n.jsx(sn,{filePath:e.path,diff:X,renderSideBySide:ae,wrapLines:a}),C?n.jsx("div",{className:"pointer-events-none absolute bottom-3 right-3 z-20",children:n.jsx("div",{className:"pointer-events-auto",children:n.jsx(rn,{filePath:e.path,staged:x,busyAction:L,disabled:L!==null,onAction:le})})}):null]}):null]})]})}),cn=1100,Xe=300,un=t=>t<=6?t:t<=12?6:t<=25?4:2,dn=(t,s)=>Lt(t,s),Ye=(t,s)=>{const e=t.split(`
|
|
9
|
+
${s}`,Qt=t=>{if(!t.startsWith("diff --git ")&&!/^--- [^\n]*\t?\r?\n\+\+\+ [^\n]*\t?(?:\r?\n|$)/m.test(t))return;const s=[...t.matchAll(/^@@\s+-(\d+)(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s+@@[^\n]*(?:\r?\n|$)/gm)];if(s.length!==1)return;const e=s[0],i=Number.parseInt(e[1]??"",10),a=Number.parseInt(e[2]??"",10);if(i>1||a>1||!Number.isFinite(i)||!Number.isFinite(a))return;const l=(e.index??0)+e[0].length,p=t.slice(l),u=[],b=[];let g;for(const c of p.split(/\r?\n/)){if(c.startsWith("diff --git ")||c.startsWith("@@ "))break;if(c.startsWith("\\")){if(g==="-"||g===" "){const h=u.at(-1);h&&(h.newline=!1)}if(g==="+"||g===" "){const h=b.at(-1);h&&(h.newline=!1)}continue}if(c.startsWith("-")){u.push({text:c.slice(1),newline:!0}),g="-";continue}if(c.startsWith("+")){b.push({text:c.slice(1),newline:!0}),g="+";continue}c.startsWith(" ")&&(u.push({text:c.slice(1),newline:!0}),b.push({text:c.slice(1),newline:!0}),g=" ")}return{before:Ve(u),after:Ve(b)}},Ve=t=>t.map(s=>s.text+(s.newline?`
|
|
10
|
+
`:"")).join(""),Ke=t=>Gt({name:t,contents:""},{name:t,contents:""}),Zt=t=>/^Binary files .+ differ$/m.test(t)||/^GIT binary patch$/m.test(t),Pe=(t,s,e)=>Zt(s)?{original:"",modified:"",isBinary:!0,patch:s,contextMode:e}:{original:"",modified:"",patch:s,fileDiff:Yt(t,s),contextMode:e},ot=(t,s,e)=>{const i=t??0,a=s??0;return!i&&!a?null:n.jsxs("span",{className:se("typography-meta flex items-center gap-1 text-xs whitespace-nowrap","flex-shrink-0",e?.className),children:[i?n.jsxs("span",{style:{color:"var(--status-success)"},children:["+",i]}):null,a?n.jsxs("span",{style:{color:"var(--status-error)"},children:["-",a]}):null]})},en=r.memo(function({changedFiles:s,selectedFile:e,onSelectFile:i}){return s.length===0?null:n.jsx(et,{outerClassName:"flex-1 min-h-0",className:"px-1 py-2",children:n.jsx("ul",{className:"flex flex-col gap-1",children:s.map(a=>{const l=rt(a),p=e===a.path;return n.jsx("li",{children:n.jsxs("button",{type:"button",onClick:()=>i(a.path),className:se("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",p?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[n.jsx(tt,{filePath:a.path,className:"h-3.5 w-3.5 flex-shrink-0"}),n.jsx("span",{className:"typography-micro font-semibold w-4 text-center uppercase",style:{color:l.color},title:l.description,"aria-label":l.description,children:l.code}),n.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:a.path,children:a.path}),ot(a.insertions,a.deletions)]})},a.path)})})})}),tn=r.memo(function(){return n.jsx("div",{className:"rounded-lg border border-border/60 bg-background px-3 py-2",children:n.jsx("div",{className:"typography-meta text-muted-foreground",children:"Content of this file cannot be viewed."})})}),nn=r.memo(function({filePath:s,diff:e,renderSideBySide:i}){const a=e.original.length>0,l=e.modified.length>0,p=i?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",u=i?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";return n.jsx("div",{className:"w-full overflow-auto p-4",style:{contain:"layout"},children:n.jsxs("div",{className:p,children:[a&&n.jsxs("div",{className:u,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:"Original"}),n.jsx("img",{src:e.original,alt:`Original: ${s}`,className:i?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),l&&n.jsxs("div",{className:u,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:a?"Modified":"New"}),n.jsx("img",{src:e.modified,alt:`Modified: ${s}`,className:i?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]})]})})}),sn=r.memo(function({filePath:s,diff:e,renderSideBySide:i,wrapLines:a}){const l=r.useMemo(()=>Nt(s)||"text",[s]);return e.isBinary?n.jsx(tn,{}):Ne(s)?n.jsx(nn,{filePath:s,diff:e,renderSideBySide:i}):n.jsx("div",{className:"w-full",style:{contain:"layout"},children:n.jsx(Ht,{original:e.original,modified:e.modified,fileDiff:e.fileDiff,language:l,fileName:s,renderSideBySide:i,wrapLines:a,layout:"inline"})})}),$e=({label:t,icon:s,loading:e,disabled:i,tone:a,onClick:l})=>n.jsx(Le,{variant:"ghost",size:"sm",className:se("h-6 w-6 rounded-none bg-transparent p-0 text-muted-foreground opacity-70 hover:bg-transparent hover:text-foreground hover:opacity-100",a==="failure"&&"text-[var(--status-error)] hover:text-[var(--status-error)]",a==="success"&&"text-[var(--status-success)] hover:text-[var(--status-success)]"),disabled:i,title:t,"aria-label":t,onClick:p=>{p.stopPropagation(),l()},children:e?n.jsx(J,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(J,{name:s,className:s==="add"?"size-4":"size-3.5"})}),rn=r.memo(function({filePath:s,staged:e,busyAction:i,disabled:a,onAction:l}){return n.jsx("div",{className:"flex items-center gap-0.5 rounded-full border border-[var(--interactive-border)]/45 bg-[var(--surface-background)]/95 px-1 py-0.5 shadow-sm backdrop-blur-md",children:e?n.jsx($e,{label:`Unstage ${s}`,icon:"arrow-go-back",loading:i==="unstage",disabled:a,onClick:()=>l("unstage")}):n.jsxs(n.Fragment,{children:[n.jsx($e,{label:`Revert changes in ${s}`,icon:"arrow-go-back",loading:i==="discard",disabled:a,tone:"failure",onClick:()=>l("discard")}),n.jsx($e,{label:`Stage ${s}`,icon:"add",loading:i==="stage",disabled:a,tone:"success",onClick:()=>l("stage")})]})})}),at=3,on=1e6,an=15e3,qe=500,ln=r.memo(function({directory:s,file:e,layout:i,wrapLines:a,isSelected:l,isExpanded:p,isMounted:u,onSelect:b,onExpandedChange:g,registerSectionRef:c,showOpenInEditorAction:h=!1,isOpeningInEditor:w=!1,onOpenInEditor:k,staged:x=!1,showFileActions:C=!0,loadFullFiles:m=!1,initialDiffData:d=null}){const{git:_}=nt(),W=oe(r.useCallback(f=>f.directories.get(s)?.diffCache.get(e.path)??null,[s,e.path])),$=oe(f=>f.setDiff),j=oe(f=>f.fetchStatus),H=Q(f=>f.setDiffFileLayout),[F,y]=r.useState(0),[N,R]=r.useState(null),[A,M]=r.useState(!1),[L,B]=r.useState(null),[U,Z]=r.useState(!1),[ie,fe]=r.useState(null),[E,I]=r.useState(null),V=r.useRef(null),pe=r.useRef(null),O=r.useMemo(()=>rt(e),[e]),ae=i==="side-by-side",Y=m?"full":"patch",q=`${e.index}:${e.working_dir}:${e.insertions}:${e.deletions}`,X=r.useMemo(()=>d||(x?E:ie||(W?{original:W.original,modified:W.modified,isBinary:W.isBinary,contextMode:"full"}:null)),[W,d,ie,x,E]),he=X?.contextMode===Y,ve=r.useCallback(f=>{pe.current=f,c(e.path,f)},[e.path,c]),re=r.useCallback(f=>{g(e.path,f)},[e.path,g]),me=r.useCallback(()=>{b(e.path)},[e.path,b]);r.useEffect(()=>{x?I(null):fe(null),R(null),V.current=null},[q,x]),r.useEffect(()=>{if(!p||!u)return;if(!s||d||X&&he){V.current=null,M(!1);return}const f=`${s}::${e.path}::${x?"staged":"unstaged"}::${q}::${Y}::${F}`;if(V.current===f)return;V.current=f,R(null),M(!0);let P=!1;const ee=Ze(),xe=m?on:at,ce=Ne(e.path)?_.getGitFileDiff(s,{path:e.path,staged:x}):_.getGitDiff(s,{path:e.path,staged:x,contextLines:xe}),te=an,be=new Promise((K,z)=>{setTimeout(()=>z(new Error(`Timed out after ${te}ms`)),te)});return Promise.race([ce,be]).then(K=>{if(!P){if("diff"in K){const z=Pe(e.path,K.diff,Y);x?I(z):fe(z)}else{const z={original:K.original??"",modified:K.modified??"",isBinary:K.isBinary,contextMode:"full"};x?I(z):$(s,e.path,z,ee)}M(!1)}}).catch(K=>{if(P)return;const z=K instanceof Error?K.message:String(K);R(z),M(!1)}),()=>{P=!0,V.current===f&&(V.current=null)}},[Y,X,he,F,s,e.path,q,_,d,p,u,m,$,x]);const ge=r.useCallback(()=>{re(!p),me()},[re,me,p]),le=r.useCallback(async f=>{if(!(!s||L!==null)){B(f);try{f==="stage"?await _.stageGitFile(s,e.path):f==="unstage"?await _.unstageGitFile(s,e.path):await _.revertGitFile(s,e.path,{scope:"working"}),y(P=>P+1),await j(s,_)}catch(P){const ee=f==="unstage"?"Failed to unstage changes":f==="stage"?"Failed to stage changes":"Failed to revert changes";st.error(P instanceof Error?P.message:ee)}finally{B(P=>P===f?null:P)}}},[s,j,e.path,L,_]);return n.jsxs("div",{ref:ve,className:se("scroll-mt-9 border-b border-[var(--interactive-border)]/40 last:border-b-0"),children:[n.jsx("div",{className:se("z-30 border-b border-[var(--interactive-border)]/35 bg-[var(--surface-elevated)]/90 backdrop-blur-md supports-[backdrop-filter]:bg-[var(--surface-elevated)]/80","sticky top-0"),children:n.jsxs("div",{role:"button",tabIndex:0,onClick:ge,onKeyDown:f=>{f.target===f.currentTarget&&(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),ge())},className:se("cursor-pointer","group/header relative grid min-h-9 w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2 overflow-hidden px-3 py-2","bg-transparent","text-muted-foreground hover:text-foreground",l?"bg-[var(--interactive-selection)]/35":null),children:[n.jsx("div",{className:"absolute inset-0 pointer-events-none group-hover/header:bg-[var(--interactive-hover)]/50"}),n.jsxs("div",{className:"relative flex min-w-0 flex-1 items-center gap-2",children:[n.jsx("span",{className:"flex size-5 items-center justify-center opacity-70 group-hover/header:opacity-100",children:p?n.jsx(J,{name:"arrow-down-s",className:"size-4"}):n.jsx(J,{name:"arrow-right-s",className:"size-4"})}),n.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:{color:O.color},title:O.description,"aria-label":O.description,children:O.code}),n.jsx("span",{className:"min-w-0 flex-1 overflow-hidden typography-ui-label",title:e.path,children:n.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[n.jsx(tt,{filePath:e.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),(()=>{const f=e.path.lastIndexOf("/");if(f===-1)return n.jsx("span",{className:"block min-w-0 truncate typography-ui-label text-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:e.path});const P=e.path.slice(0,f),ee=e.path.slice(f+1);return n.jsxs("span",{className:"flex min-w-0 items-baseline overflow-hidden",children:[n.jsx("span",{className:"min-w-0 truncate typography-ui-label text-muted-foreground",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},children:P}),n.jsxs("span",{className:"flex-shrink-0 typography-ui-label",children:[n.jsx("span",{className:"text-muted-foreground",children:"/"}),n.jsx("span",{className:"text-foreground",children:ee})]})]})})()]})})]}),n.jsxs("div",{className:"relative flex shrink-0 items-center justify-self-end gap-2",children:[ot(e.insertions,e.deletions),h&&k?n.jsx(Le,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:"Open this file in editor at change",onClick:f=>{f.stopPropagation(),k(e.path,X)},disabled:w,children:w?n.jsx(J,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(J,{name:"edit",className:"size-3.5"})}):null,n.jsx(it,{mode:ae?"side-by-side":"unified",onModeChange:f=>{const P=f==="side-by-side"?"side-by-side":"inline";H(e.path,P)},className:"opacity-70"})]})]})}),p&&n.jsxs("div",{className:"relative overflow-hidden bg-background",children:[!u&&!N?n.jsx("div",{className:"h-40 border border-border/40 bg-background/40"}):null,N?n.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:"Failed to load diff"}),n.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:N}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>y(f=>f+1),children:"Retry"})]}):null,u&&A&&!X&&!N?n.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx(J,{name:"loader-4",className:"size-4 animate-spin"}),"Loading diff..."]}):null,u&&X&&!U&&e.insertions+e.deletions>qe?n.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:`Large diff (${e.insertions+e.deletions} changed lines)`}),n.jsx("div",{className:"typography-meta text-muted-foreground",children:"Rendering may be slow. You can still view the diff by clicking below."}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>Z(!0),children:"Render anyway"})]}):null,u&&X&&(U||e.insertions+e.deletions<=qe)?n.jsxs(n.Fragment,{children:[n.jsx(sn,{filePath:e.path,diff:X,renderSideBySide:ae,wrapLines:a}),C?n.jsx("div",{className:"pointer-events-none absolute bottom-3 right-3 z-20",children:n.jsx("div",{className:"pointer-events-auto",children:n.jsx(rn,{filePath:e.path,staged:x,busyAction:L,disabled:L!==null,onAction:le})})}):null]}):null]})]})}),cn=1100,Xe=300,un=t=>t<=6?t:t<=12?6:t<=25?4:2,dn=(t,s)=>Lt(t,s),Ye=(t,s)=>{const e=t.split(`
|
|
11
11
|
`),i=s.split(`
|
|
12
12
|
`),a=Math.min(e.length,i.length);for(let l=0;l<a;l+=1)if(e[l]!==i[l])return l+1;return i.length>e.length?e.length+1:e.length>i.length?Math.max(1,i.length):1},fn=t=>Array.isArray(t)?t.filter(s=>!s||typeof s!="object"?!1:typeof s.file=="string"):[],pn=t=>t.split(/^diff --git /m).slice(1).flatMap(e=>{const[i=""]=e.split(`
|
|
13
13
|
`,1),a=i.lastIndexOf(" b/");if(a<=2)return[];const l=i.slice(2,a),p=i.slice(a+3).trim(),u=`diff --git ${e}`,b=u.includes(`
|
|
14
14
|
new file mode `)?"added":u.includes(`
|
|
15
15
|
deleted file mode `)?"deleted":u.includes(`
|
|
16
|
-
rename from `)?"renamed":"modified";let g=0,c=0;for(const
|
|
17
|
-
`))
|
|
18
|
-
`);let e=null;for(const i of s){const a=i.match(/^@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/);if(a){const l=Number.parseInt(a[1]??"",10);e=Number.isFinite(l)&&l>=1?l:null;continue}if(e!==null){if(i.startsWith(" ")){e+=1;continue}if(i.startsWith("+"))return e;if(i.startsWith("-"))return Math.max(1,e)}}return null};function bn({effectiveDirectory:t,activeDiffStaged:s,git:e,files:i,setDiff:a,openContextFileAtLine:l}){const[p,u]=r.useState(null),b=r.useCallback(async(g,c)=>{if(!t||!g)return;u(g);const m=Ze();try{let w=null;if(c?.patch&&!c.isBinary&&!Ne(g)?w=Qe(c.patch):c&&c.contextMode==="full"&&!c.isBinary&&!Ne(g)&&(w=Ye(c.original,c.modified)),w===null)try{const d=await e.getGitDiff(t,{path:g,staged:s,contextLines:3});w=Qe(d.diff)}catch{w=null}let k=c;if(w===null||!k){const d=await e.getGitFileDiff(t,{path:g,staged:s});k={original:d.original??"",modified:d.modified??"",isBinary:d.isBinary},s||a(t,g,k,m??void 0)}const x=w??(k.isBinary||Ne(g)?1:Ye(k.original,k.modified)),C=dn(t,g),h=await Ut(i,C,{directory:t});if(!h.ok){st.error(Vt(h.reason));return}l(t,C,x,1)}finally{u(w=>w===g?null:w)}},[s,t,i,e,l,a]);return{openingEditorFilePath:p,openFileInEditorAtChange:b}}function yn(t){const{hideStackedFileSidebar:s=!1,stackedDefaultCollapsedAll:e=!1,pinSelectedFileHeaderToTopOnNavigate:i=!1,diffScope:a="all",branchBase:l=null,branchHead:p=null,targetFilePath:u=null}=t,{git:b,files:g}=nt(),c=Rt(),{screenWidth:m,isMobile:w}=Et(),k=At(c??null),x=Tt(c??null),C=Mt(c??null),h=oe(o=>o.setActiveDirectory),d=oe(o=>o.ensureStatus),_=oe(o=>o.fetchStatus),B=oe(o=>o.clearDiffCache),$=oe(o=>o.setDiff),[j,H]=r.useState(null),[F,y]=r.useState(!1),[N,R]=r.useState(()=>new Set),[A,M]=r.useState(()=>new Set),[L,W]=r.useState(!1),[U,Z]=r.useState(0),[ie,fe]=r.useState(()=>new Map),[E,I]=r.useState(a);r.useEffect(()=>{I(a)},[a]);const V=Q(o=>o.pendingDiffFile),pe=Q(o=>o.pendingDiffStaged),O=Q(o=>o.pendingDiffScope),ae=Q(o=>o.setPendingDiffFile),Y=Q(o=>o.diffLayoutPreference),q=Q(o=>o.diffFileLayout),X=Q(o=>o.setDiffFileLayout),me=Q(o=>o.diffWrapLines),ve=Q(o=>o.setDiffWrapLines),re=Q(o=>o.openContextFileAtLine),he=It(o=>o.currentSessionId),ge=$t(he??""),le=me,f=E==="staged"?!0:E==="working"?!1:null,P=f??F,ee=w||m<=768,xe=!s&&!ee&&m>=1024,ce=r.useRef(null),{branchDiffs:te,branchDiffError:be,branchDiffLoading:K,lastTurnDiffs:z,lastTurnDiffData:De,branchDiffData:ne}=hn({activeDiffScope:E,effectiveDirectory:c,branchBase:l,branchHead:p,git:b,sessionMessageRecords:ge}),D=r.useMemo(()=>{if(E==="turn"||E==="branch")return(E==="branch"?te:z).map(T=>({path:T.file??"",index:"",working_dir:mn(T.status),insertions:T.additions??0,deletions:T.deletions??0,isNew:T.status==="added"})).filter(T=>T.path).sort((T,G)=>T.path.localeCompare(G.path));if(!x?.files)return[];const o=x.diffStats??{},v=E==="staged"?Ge:E==="working"?He:()=>!0;return x.files.filter(v).map(S=>({...S,insertions:o[S.path]?.insertions??0,deletions:o[S.path]?.deletions??0,isNew:zt(S)})).sort((S,T)=>S.path.localeCompare(T.path))},[E,te,z,x]),Ee=r.useMemo(()=>x?.files?x.files.filter(He).length:0,[x]),Ae=r.useMemo(()=>x?.files?x.files.filter(Ge).length:0,[x]),lt=z.length,ct=x?.files?.length??0,ut=te.length,{diffScrollRef:dt,pinnedStackedTarget:ft,pendingScrollTargetRef:ye,shouldPinAfterAlignRef:we,pendingScrollAnchorRestoreRef:_e,lastScrollAnchorRef:Be,captureScrollAnchor:We,cancelPendingScrollAlignment:Fe,queueVisibleStackedFilesSync:ke,registerSectionRef:pt,scrollToFile:Oe}=xn({pinSelectedFileHeaderToTopOnNavigate:i,scrollRequestNonce:U,changedFiles:D,expandedFiles:N,setMountedStackedFiles:M,fileDiffRefreshNonce:ie}),Se=r.useCallback(o=>{R(v=>{if(v.has(o))return v;const S=new Set(v);return S.add(o),S})},[]),Te=r.useMemo(()=>D.map(o=>o.path).join("\0"),[D]);r.useEffect(()=>{const o=Te?Te.split("\0"):[],v=new Set(o),S=`${c??""}:${E}:${e?"collapsed":"default"}`,T=ce.current!==S;ce.current=S,R(G=>{if(T){const ue=e?0:un(o.length);return new Set(o.slice(0,ue))}let Ce=!1;const je=new Set;for(const ue of G){if(!v.has(ue)){Ce=!0;continue}je.add(ue)}return Ce?je:G}),M(G=>{if(T)return new Set;let Ce=!1;const je=new Set;for(const ue of G){if(!v.has(ue)){Ce=!0;continue}je.add(ue)}return Ce?je:G})},[E,Te,c,M,e]);const Me=r.useCallback(o=>{const v=q[o.path];if(v)return v;if(Y==="inline")return"inline";if(Y==="side-by-side")return"side-by-side";const S=m<cn;return o.isNew||S?"inline":"side-by-side"},[q,Y,m]),mt=r.useMemo(()=>D.length===0?null:D.every(o=>Me(o)==="side-by-side")?"side-by-side":"inline",[D,Me]);r.useEffect(()=>{c&&(h(c),d(c,b))},[c,h,d,b]),r.useEffect(()=>{if(c)return Pt.onGitRefreshHint(o=>{ze(o.directory)===ze(c)&&(o.paths?.length&&(_e.current=We()??Be.current,B(c,o.paths),fe(v=>{const S=new Map(v);for(const T of o.paths??[])S.set(T,(S.get(T)??0)+1);return S})),_(c,b,{silent:!0}))})},[We,B,c,_,b,Be,_e]),r.useEffect(()=>{E!=="all"&&!O||V&&(O&&I(O),H(V),y(O==="staged"||!O&&pe),ae(null),we.current=!0,ye.current=V,Se(V),Z(o=>o+1))},[E,Se,V,O,pe,ye,ae,we]),r.useEffect(()=>{if(E==="all")return;const o=u?.trim();o&&(H(o),y(E==="staged"),we.current=!0,ye.current=o,Se(o),Z(v=>v+1))},[E,Se,ye,we,u]),r.useEffect(()=>{if(!j)return;D.some(v=>v.path===j)||(H(null),y(!1))},[D,j]);const ht=r.useCallback((o,v)=>{Fe(),R(S=>{const T=S.has(o);if(v===T)return S;const G=new Set(S);return v?G.add(o):G.delete(o),G}),M(S=>{const T=S.has(o);if(v===T)return S;const G=new Set(S);return v?G.add(o):G.delete(o),G}),ke()},[Fe,ke,M]),gt=r.useCallback(()=>{Fe(),R(o=>o.size>0?new Set:new Set(D.map(v=>v.path))),M(new Set),ke()},[Fe,D,ke,M]),xt=r.useCallback(o=>{},[]),bt=r.useCallback(o=>{Fe(),H(o),y(!1),we.current=!0,ye.current=o,Se(o),Z(v=>v+1),Oe(o)},[Fe,Se,ye,Oe,we]),yt=r.useCallback(o=>{const v=o==="side-by-side"?"side-by-side":"inline";D.forEach(S=>{X(S.path,v)})},[D,X]),{openingEditorFilePath:wt,openFileInEditorAtChange:Ft}=bn({effectiveDirectory:c,activeDiffStaged:P,git:b,files:g,setDiff:$,openContextFileAtLine:re});return{git:b,files:g,effectiveDirectory:c,screenWidth:m,isMobile:w,isGitRepo:k,status:x,isLoadingStatus:C,activeDiffScope:E,setActiveDiffScope:I,branchDiffs:te,branchDiffError:be,branchDiffLoading:K,diffWrapLines:le,setDiffWrapLines:ve,forcedStaged:f,displayFileStaged:F,displayFile:j,pinnedStackedTarget:ft,expandedFiles:N,mountedStackedFiles:A,loadFullFiles:L,setLoadFullFiles:W,fileDiffRefreshNonce:ie,showFileSidebar:xe,diffScrollRef:dt,lastTurnDiffData:De,branchDiffData:ne,changedFiles:D,workingFileCount:Ee,stagedFileCount:Ae,turnFileCount:lt,allFileCount:ct,branchFileCount:ut,currentLayoutForAllFiles:mt,openingEditorFilePath:wt,registerSectionRef:pt,handleStackedEntryExpandedChange:ht,handleExpandOrCollapseAll:gt,handleSelectFile:xt,handleSelectFileAndScroll:bt,handleHeaderLayoutChange:yt,openFileInEditorAtChange:Ft,getLayoutForFile:Me}}const Di=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:s=!1,pinSelectedFileHeaderToTopOnNavigate:e=!1,showOpenInEditorAction:i=!1,diffScope:a="all",onDiffScopeChange:l,branchBase:p=null,branchHead:u=null,targetFilePath:b=null,flushContent:g=!1,hideToolbar:c=!1,onHeaderControlsStateChange:m,toolbarSlot:w=null})=>{const{effectiveDirectory:k,isGitRepo:x,status:C,isLoadingStatus:h,activeDiffScope:d,setActiveDiffScope:_,branchDiffError:B,branchDiffLoading:$,diffWrapLines:j,setDiffWrapLines:H,forcedStaged:F,displayFileStaged:y,displayFile:N,pinnedStackedTarget:R,expandedFiles:A,mountedStackedFiles:M,loadFullFiles:L,setLoadFullFiles:W,fileDiffRefreshNonce:U,showFileSidebar:Z,diffScrollRef:ie,lastTurnDiffData:fe,branchDiffData:E,changedFiles:I,workingFileCount:V,stagedFileCount:pe,turnFileCount:O,allFileCount:ae,branchFileCount:Y,currentLayoutForAllFiles:q,openingEditorFilePath:X,registerSectionRef:me,handleStackedEntryExpandedChange:ve,handleExpandOrCollapseAll:re,handleSelectFile:he,handleSelectFileAndScroll:ge,handleHeaderLayoutChange:le,openFileInEditorAtChange:f,getLayoutForFile:P}=yn({hideStackedFileSidebar:t,stackedDefaultCollapsedAll:s,pinSelectedFileHeaderToTopOnNavigate:e,diffScope:a,branchBase:p,branchHead:u,targetFilePath:b});r.useEffect(()=>{c&&l?.(d)},[d,c,l]);const ee=r.useCallback(()=>{W(ne=>!ne)},[W]),xe=r.useCallback(()=>{H(!j)},[j,H]),ce=r.useCallback(()=>{le(q==="side-by-side"?"unified":"side-by-side")},[q,le]),te=A.size,be=r.useMemo(()=>({turnCount:O,branchCount:Y,expandedCount:te,totalCount:I.length,loadFullFiles:L,wrapLines:j,layoutMode:q,onExpandOrCollapseAll:re,onToggleLoadFullFiles:ee,onToggleWrapLines:xe,onToggleLayout:ce}),[O,Y,te,I.length,L,j,q,re,ee,xe,ce]);r.useEffect(()=>{c&&m?.(be)},[c,be,m]);const K=()=>{if(!k)return null;const ne=D=>F!==null?F:y&&D===N;return n.jsxs("div",{className:se("flex min-w-0 flex-1 min-h-0 h-full",g?"gap-0":"gap-3 px-3 pb-3 pt-2"),children:[Z&&n.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[n.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[n.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:"Files"}),n.jsx("span",{className:"typography-meta text-muted-foreground",children:I.length})]}),n.jsx(en,{changedFiles:I,selectedFile:null,onSelectFile:ge})]}),n.jsx("div",{className:"relative flex-1 min-w-0 min-h-0 h-full",children:n.jsx(et,{ref:ie,outerClassName:"min-h-0 h-full",className:"[overflow-anchor:none] pb-16",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,children:n.jsx("div",{className:"flex flex-col [overflow-anchor:none]","data-diff-virtual-content":!0,children:I.map(D=>n.jsx(ln,{directory:k,file:D,layout:P(D),wrapLines:j,isSelected:!1,isExpanded:A.has(D.path),isMounted:M.has(D.path)||D.path===R,onSelect:he,onExpandedChange:ve,registerSectionRef:me,showOpenInEditorAction:i&&d!=="turn"&&d!=="branch",isOpeningInEditor:X===D.path,onOpenInEditor:(Ee,Ae)=>{f(Ee,Ae)},staged:ne(D.path),showFileActions:d!=="turn"&&d!=="branch",loadFullFiles:L,initialDiffData:d==="turn"?fe.get(D.path)??null:d==="branch"?E.get(D.path)??null:null},`${D.path}:${U.get(D.path)??0}`))})})})]})},z=()=>k?d!=="turn"&&h&&!C?n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(J,{name:"loader-4",className:"size-4 animate-spin"}),"Loading repository status..."]}):d!=="turn"&&d!=="branch"&&x===!1?n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:"Not a git repository. Use the Git tab to initialize or change directories."}):d==="branch"&&$?n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(J,{name:"loader-4",className:"size-4 animate-spin"}),"Loading branch changes..."]}):d==="branch"&&B?n.jsx("div",{className:"flex flex-1 items-center justify-center px-4 text-center text-sm text-muted-foreground",children:`Failed to load branch changes: ${B}`}):I.length===0?n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:d==="turn"?"No last turn changes to display":"Working tree clean, no changes to display"}):K():n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:"Select a session directory to view diffs"}),De=n.jsxs("div",{className:w?"flex min-w-0 flex-1 items-center gap-1.5":"@container/diff-toolbar flex min-w-0 items-center gap-2 px-3 py-2 bg-background",children:[(x!==!1||d==="turn")&&(d==="all"||d==="working"||d==="staged"||d==="turn"||d==="branch")?n.jsx(Gt,{scope:d,isGitRepo:x,branchAvailable:!!(p&&u),allCount:ae,workingCount:V,stagedCount:pe,turnCount:O,branchCount:Y,onScopeChange:ne=>{_(ne),l?.(ne)}}):n.jsx("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:n.jsx("span",{className:"typography-ui-label font-semibold text-foreground",children:h&&!C?"Loading changes...":I.length===1?`${I.length} file changed`:`${I.length} files changed`})}),I.length>0&&n.jsxs(Le,{variant:"ghost",size:"sm",onClick:re,className:se("diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground","ml-auto"),title:A.size>0?"Collapse all":"Expand all",children:[n.jsx(J,{name:"expand-up-down",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__expand-label typography-ui-label",children:A.size>0?"Collapse all":"Expand all"})]}),I.length>0&&d!=="turn"&&d!=="branch"&&n.jsxs(_t,{children:[n.jsx(Bt,{asChild:!0,children:n.jsx(Le,{variant:"ghost",size:"sm",onClick:()=>W(ne=>!ne),"aria-pressed":L,"aria-label":L?"Unload full files":"Load full files",className:se("h-7 w-7 flex-shrink-0 p-0 text-muted-foreground hover:text-foreground",L&&"bg-interactive-selection text-interactive-selection-foreground"),children:n.jsx(J,{name:"file-download",className:"size-4"})})}),n.jsx(Wt,{children:n.jsx("p",{children:L?"Unload full files":"Load full files"})})]}),I.length>0&&n.jsx(Le,{variant:"ghost",size:"sm",onClick:()=>H(!j),className:se("h-5 w-5 p-0 transition-opacity",j?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:j?"Disable line wrap":"Enable line wrap",children:n.jsx(J,{name:"text-wrap",className:"size-4"})}),q&&n.jsx(it,{mode:q==="side-by-side"?"side-by-side":"unified",onModeChange:le})]});return n.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[w?St.createPortal(De,w):c?null:De,z()]})};export{Di as DiffView};
|
|
16
|
+
rename from `)?"renamed":"modified";let g=0,c=0;for(const h of u.split(`
|
|
17
|
+
`))h.startsWith("+")&&!h.startsWith("+++")&&(g+=1),h.startsWith("-")&&!h.startsWith("---")&&(c+=1);return[{file:b==="deleted"?l:p,status:b,additions:g,deletions:c,patch:u}]}),hn=t=>t==="added"?"A":t==="deleted"?"D":"M";function mn({activeDiffScope:t,effectiveDirectory:s,branchBase:e,branchHead:i,git:a,sessionMessageRecords:l}){const[p,u]=r.useState([]),[b,g]=r.useState(null),[c,h]=r.useState(!1),w=r.useMemo(()=>{const C=Dt(l,{showTextJustificationActivity:!1,mergeHiddenUserTurns:!0});for(let m=C.turns.length-1;m>=0;m-=1){const d=C.turns[m];if(!d)continue;const _=d.activityParts.map(j=>j.part).filter(j=>j.type==="tool"),W=kt(_);if(W.length>0)return W.map(j=>({file:j.path,status:"modified",additions:j.additions,deletions:j.deletions,patch:j.patch}));const $=fn(d.userMessage.info?.summary?.diffs);if($.length>0)return $}return[]},[l]);r.useEffect(()=>{if(t!=="branch"||!s||!e||!i||!a.getGitRangeDiff){u([]),g(null),h(!1);return}let C=!1;return h(!0),g(null),a.getGitRangeDiff(s,{base:e,head:i,contextLines:at}).then(m=>{C||(u(pn(m.diff??"")),h(!1))}).catch(m=>{C||(u([]),h(!1),g(m instanceof Error?m.message:String(m)))}),()=>{C=!0}},[t,e,i,s,a]);const k=r.useMemo(()=>{const C=new Map;for(const m of w)if(m.file){if(typeof m.patch=="string"){C.set(m.file,Pe(m.file,m.patch,"patch"));continue}typeof m.before!="string"&&typeof m.after!="string"||C.set(m.file,{original:m.before??"",modified:m.after??"",contextMode:"full"})}return C},[w]),x=r.useMemo(()=>{const C=new Map;for(const m of p)!m.file||typeof m.patch!="string"||C.set(m.file,Pe(m.file,m.patch,"patch"));return C},[p]);return{branchDiffs:p,branchDiffError:b,branchDiffLoading:c,lastTurnDiffs:w,lastTurnDiffData:k,branchDiffData:x}}const Je=(t,s)=>{if(s.length===0)return null;let e=null,i=null;for(const l of s)l.top<=t?(!e||l.top>e.top)&&(e=l):(!i||l.top<i.top)&&(i=l);const a=e??i;return a?{path:a.path,topOffset:a.top-t}:null},gn=(t,s,e,i)=>Math.min(Math.max(0,i),Math.max(0,t+e-s));function xn({pinSelectedFileHeaderToTopOnNavigate:t,scrollRequestNonce:s,changedFiles:e,expandedFiles:i,setMountedStackedFiles:a,fileDiffRefreshNonce:l}){const p=r.useRef(null),u=r.useRef(new Map),[b,g]=r.useState(null),c=r.useRef(null),h=r.useRef(null),w=r.useRef(!1),k=r.useRef(null),x=r.useRef(i),C=r.useRef(null);r.useLayoutEffect(()=>{x.current=i},[i]);const m=r.useRef(null),d=r.useCallback(()=>{const F=p.current;if(!F)return null;const y=F.getBoundingClientRect().top,N=[];for(const[R,A]of u.current)A&&N.push({path:R,top:A.getBoundingClientRect().top});return Je(y,N)},[]),_=r.useCallback(()=>{c.current=null,w.current=!1,g(null),h.current!==null&&(window.cancelAnimationFrame(h.current),h.current=null)},[]),W=r.useCallback(()=>{k.current=null;const F=p.current;if(!F)return;const y=F.getBoundingClientRect(),N=y.top-Xe,R=y.bottom+Xe,A={},M=[];for(const[L,B]of u.current){if(!B)continue;const U=B.getBoundingClientRect();M.push({path:L,top:U.top}),x.current.has(L)&&(U.bottom<N||U.top>R||(A[L]=!0))}C.current=Je(y.top,M),a(L=>{let B=!1;const U=new Set(L);for(const Z of Object.keys(A))U.has(Z)||(U.add(Z),B=!0);return B?U:L})},[a]),$=r.useCallback(()=>{typeof window>"u"||k.current===null&&(k.current=window.requestAnimationFrame(W))},[W]);r.useEffect(()=>{const F=p.current;if(F)return $(),F.addEventListener("scroll",$,{passive:!0}),window.addEventListener("resize",$),()=>{F.removeEventListener("scroll",$),window.removeEventListener("resize",$),k.current!==null&&(window.cancelAnimationFrame(k.current),k.current=null)}},[e,i,$]),r.useLayoutEffect(()=>{const F=m.current;if(!F)return;m.current=null;const y=p.current,N=u.current.get(F.path);if(!y||!N)return;const R=y.getBoundingClientRect().top,A=N.getBoundingClientRect().top-R;y.scrollTop=gn(y.scrollTop,F.topOffset,A,y.scrollHeight-y.clientHeight),C.current=F},[l]);const j=r.useCallback((F,y)=>{const N=u.current;y?N.set(F,y):N.delete(F),$()},[$]),H=r.useCallback(F=>{const y=u.current.get(F),N=p.current;if(!y||!N)return!1;const R=y.getBoundingClientRect().top-N.getBoundingClientRect().top;return N.scrollTo({top:N.scrollTop+R,behavior:"auto"}),!0},[]);return r.useEffect(()=>{if(!c.current)return;let y=0;const N=20;let R=!1;const A=(L=!0)=>{R||(R=!0,c.current=null,w.current=!1,L&&g(null),h.current!==null&&(window.cancelAnimationFrame(h.current),h.current=null))},M=()=>{if(R){h.current=null;return}const L=c.current;if(!L){A(),h.current=null;return}if(!H(L)){y+=1,y<N?h.current=window.requestAnimationFrame(M):(A(),h.current=null);return}if(t&&w.current){g(L),A(!1);return}A()};return h.current=window.requestAnimationFrame(M),()=>{R=!0,h.current!==null&&(window.cancelAnimationFrame(h.current),h.current=null)}},[t,s,H]),{diffScrollRef:p,fileSectionRefs:u,pinnedStackedTarget:b,pendingScrollTargetRef:c,shouldPinAfterAlignRef:w,pendingScrollAnchorRestoreRef:m,lastScrollAnchorRef:C,captureScrollAnchor:d,cancelPendingScrollAlignment:_,queueVisibleStackedFilesSync:$,registerSectionRef:j,scrollToFile:H}}const Qe=t=>{if(!t)return null;const s=t.split(`
|
|
18
|
+
`);let e=null;for(const i of s){const a=i.match(/^@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/);if(a){const l=Number.parseInt(a[1]??"",10);e=Number.isFinite(l)&&l>=1?l:null;continue}if(e!==null){if(i.startsWith(" ")){e+=1;continue}if(i.startsWith("+"))return e;if(i.startsWith("-"))return Math.max(1,e)}}return null};function bn({effectiveDirectory:t,activeDiffStaged:s,git:e,files:i,setDiff:a,openContextFileAtLine:l}){const[p,u]=r.useState(null),b=r.useCallback(async(g,c)=>{if(!t||!g)return;u(g);const h=Ze();try{let w=null;if(c?.patch&&!c.isBinary&&!Ne(g)?w=Qe(c.patch):c&&c.contextMode==="full"&&!c.isBinary&&!Ne(g)&&(w=Ye(c.original,c.modified)),w===null)try{const d=await e.getGitDiff(t,{path:g,staged:s,contextLines:3});w=Qe(d.diff)}catch{w=null}let k=c;if(w===null||!k){const d=await e.getGitFileDiff(t,{path:g,staged:s});k={original:d.original??"",modified:d.modified??"",isBinary:d.isBinary},s||a(t,g,k,h??void 0)}const x=w??(k.isBinary||Ne(g)?1:Ye(k.original,k.modified)),C=dn(t,g),m=await Ut(i,C,{directory:t});if(!m.ok){st.error(Vt(m.reason));return}l(t,C,x,1)}finally{u(w=>w===g?null:w)}},[s,t,i,e,l,a]);return{openingEditorFilePath:p,openFileInEditorAtChange:b}}function yn(t){const{hideStackedFileSidebar:s=!1,stackedDefaultCollapsedAll:e=!1,pinSelectedFileHeaderToTopOnNavigate:i=!1,diffScope:a="all",branchBase:l=null,branchHead:p=null,targetFilePath:u=null}=t,{git:b,files:g}=nt(),c=Rt(),{screenWidth:h,isMobile:w}=Et(),k=At(c??null),x=Tt(c??null),C=Mt(c??null),m=oe(o=>o.setActiveDirectory),d=oe(o=>o.ensureStatus),_=oe(o=>o.fetchStatus),W=oe(o=>o.clearDiffCache),$=oe(o=>o.setDiff),[j,H]=r.useState(null),[F,y]=r.useState(!1),[N,R]=r.useState(()=>new Set),[A,M]=r.useState(()=>new Set),[L,B]=r.useState(!1),[U,Z]=r.useState(0),[ie,fe]=r.useState(()=>new Map),[E,I]=r.useState(a);r.useEffect(()=>{I(a)},[a]);const V=Q(o=>o.pendingDiffFile),pe=Q(o=>o.pendingDiffStaged),O=Q(o=>o.pendingDiffScope),ae=Q(o=>o.setPendingDiffFile),Y=Q(o=>o.diffLayoutPreference),q=Q(o=>o.diffFileLayout),X=Q(o=>o.setDiffFileLayout),he=Q(o=>o.diffWrapLines),ve=Q(o=>o.setDiffWrapLines),re=Q(o=>o.openContextFileAtLine),me=It(o=>o.currentSessionId),ge=$t(me??""),le=he,f=E==="staged"?!0:E==="working"?!1:null,P=f??F,ee=w||h<=768,xe=!s&&!ee&&h>=1024,ce=r.useRef(null),{branchDiffs:te,branchDiffError:be,branchDiffLoading:K,lastTurnDiffs:z,lastTurnDiffData:De,branchDiffData:ne}=mn({activeDiffScope:E,effectiveDirectory:c,branchBase:l,branchHead:p,git:b,sessionMessageRecords:ge}),D=r.useMemo(()=>{if(E==="turn"||E==="branch")return(E==="branch"?te:z).map(T=>({path:T.file??"",index:"",working_dir:hn(T.status),insertions:T.additions??0,deletions:T.deletions??0,isNew:T.status==="added"})).filter(T=>T.path).sort((T,G)=>T.path.localeCompare(G.path));if(!x?.files)return[];const o=x.diffStats??{},v=E==="staged"?Ge:E==="working"?He:()=>!0;return x.files.filter(v).map(S=>({...S,insertions:o[S.path]?.insertions??0,deletions:o[S.path]?.deletions??0,isNew:Ot(S)})).sort((S,T)=>S.path.localeCompare(T.path))},[E,te,z,x]),Ee=r.useMemo(()=>x?.files?x.files.filter(He).length:0,[x]),Ae=r.useMemo(()=>x?.files?x.files.filter(Ge).length:0,[x]),lt=z.length,ct=x?.files?.length??0,ut=te.length,{diffScrollRef:dt,pinnedStackedTarget:ft,pendingScrollTargetRef:ye,shouldPinAfterAlignRef:we,pendingScrollAnchorRestoreRef:_e,lastScrollAnchorRef:We,captureScrollAnchor:Be,cancelPendingScrollAlignment:Fe,queueVisibleStackedFilesSync:ke,registerSectionRef:pt,scrollToFile:Oe}=xn({pinSelectedFileHeaderToTopOnNavigate:i,scrollRequestNonce:U,changedFiles:D,expandedFiles:N,setMountedStackedFiles:M,fileDiffRefreshNonce:ie}),Se=r.useCallback(o=>{R(v=>{if(v.has(o))return v;const S=new Set(v);return S.add(o),S})},[]),Te=r.useMemo(()=>D.map(o=>o.path).join("\0"),[D]);r.useEffect(()=>{const o=Te?Te.split("\0"):[],v=new Set(o),S=`${c??""}:${E}:${e?"collapsed":"default"}`,T=ce.current!==S;ce.current=S,R(G=>{if(T){const ue=e?0:un(o.length);return new Set(o.slice(0,ue))}let Ce=!1;const je=new Set;for(const ue of G){if(!v.has(ue)){Ce=!0;continue}je.add(ue)}return Ce?je:G}),M(G=>{if(T)return new Set;let Ce=!1;const je=new Set;for(const ue of G){if(!v.has(ue)){Ce=!0;continue}je.add(ue)}return Ce?je:G})},[E,Te,c,M,e]);const Me=r.useCallback(o=>{const v=q[o.path];if(v)return v;if(Y==="inline")return"inline";if(Y==="side-by-side")return"side-by-side";const S=h<cn;return o.isNew||S?"inline":"side-by-side"},[q,Y,h]),ht=r.useMemo(()=>D.length===0?null:D.every(o=>Me(o)==="side-by-side")?"side-by-side":"inline",[D,Me]);r.useEffect(()=>{c&&(m(c),d(c,b))},[c,m,d,b]),r.useEffect(()=>{if(c)return Pt.onGitRefreshHint(o=>{ze(o.directory)===ze(c)&&(o.paths?.length&&(_e.current=Be()??We.current,W(c,o.paths),fe(v=>{const S=new Map(v);for(const T of o.paths??[])S.set(T,(S.get(T)??0)+1);return S})),_(c,b,{silent:!0}))})},[Be,W,c,_,b,We,_e]),r.useEffect(()=>{E!=="all"&&!O||V&&(O&&I(O),H(V),y(O==="staged"||!O&&pe),ae(null),we.current=!0,ye.current=V,Se(V),Z(o=>o+1))},[E,Se,V,O,pe,ye,ae,we]),r.useEffect(()=>{if(E==="all")return;const o=u?.trim();o&&(H(o),y(E==="staged"),we.current=!0,ye.current=o,Se(o),Z(v=>v+1))},[E,Se,ye,we,u]),r.useEffect(()=>{if(!j)return;D.some(v=>v.path===j)||(H(null),y(!1))},[D,j]);const mt=r.useCallback((o,v)=>{Fe(),R(S=>{const T=S.has(o);if(v===T)return S;const G=new Set(S);return v?G.add(o):G.delete(o),G}),M(S=>{const T=S.has(o);if(v===T)return S;const G=new Set(S);return v?G.add(o):G.delete(o),G}),ke()},[Fe,ke,M]),gt=r.useCallback(()=>{Fe(),R(o=>o.size>0?new Set:new Set(D.map(v=>v.path))),M(new Set),ke()},[Fe,D,ke,M]),xt=r.useCallback(o=>{},[]),bt=r.useCallback(o=>{Fe(),H(o),y(!1),we.current=!0,ye.current=o,Se(o),Z(v=>v+1),Oe(o)},[Fe,Se,ye,Oe,we]),yt=r.useCallback(o=>{const v=o==="side-by-side"?"side-by-side":"inline";D.forEach(S=>{X(S.path,v)})},[D,X]),{openingEditorFilePath:wt,openFileInEditorAtChange:Ft}=bn({effectiveDirectory:c,activeDiffStaged:P,git:b,files:g,setDiff:$,openContextFileAtLine:re});return{git:b,files:g,effectiveDirectory:c,screenWidth:h,isMobile:w,isGitRepo:k,status:x,isLoadingStatus:C,activeDiffScope:E,setActiveDiffScope:I,branchDiffs:te,branchDiffError:be,branchDiffLoading:K,diffWrapLines:le,setDiffWrapLines:ve,forcedStaged:f,displayFileStaged:F,displayFile:j,pinnedStackedTarget:ft,expandedFiles:N,mountedStackedFiles:A,loadFullFiles:L,setLoadFullFiles:B,fileDiffRefreshNonce:ie,showFileSidebar:xe,diffScrollRef:dt,lastTurnDiffData:De,branchDiffData:ne,changedFiles:D,workingFileCount:Ee,stagedFileCount:Ae,turnFileCount:lt,allFileCount:ct,branchFileCount:ut,currentLayoutForAllFiles:ht,openingEditorFilePath:wt,registerSectionRef:pt,handleStackedEntryExpandedChange:mt,handleExpandOrCollapseAll:gt,handleSelectFile:xt,handleSelectFileAndScroll:bt,handleHeaderLayoutChange:yt,openFileInEditorAtChange:Ft,getLayoutForFile:Me}}const ms=({hideStackedFileSidebar:t=!1,stackedDefaultCollapsedAll:s=!1,pinSelectedFileHeaderToTopOnNavigate:e=!1,showOpenInEditorAction:i=!1,diffScope:a="all",onDiffScopeChange:l,branchBase:p=null,branchHead:u=null,targetFilePath:b=null,flushContent:g=!1,hideToolbar:c=!1,onHeaderControlsStateChange:h,toolbarSlot:w=null})=>{const{effectiveDirectory:k,isGitRepo:x,status:C,isLoadingStatus:m,activeDiffScope:d,setActiveDiffScope:_,branchDiffError:W,branchDiffLoading:$,diffWrapLines:j,setDiffWrapLines:H,forcedStaged:F,displayFileStaged:y,displayFile:N,pinnedStackedTarget:R,expandedFiles:A,mountedStackedFiles:M,loadFullFiles:L,setLoadFullFiles:B,fileDiffRefreshNonce:U,showFileSidebar:Z,diffScrollRef:ie,lastTurnDiffData:fe,branchDiffData:E,changedFiles:I,workingFileCount:V,stagedFileCount:pe,turnFileCount:O,allFileCount:ae,branchFileCount:Y,currentLayoutForAllFiles:q,openingEditorFilePath:X,registerSectionRef:he,handleStackedEntryExpandedChange:ve,handleExpandOrCollapseAll:re,handleSelectFile:me,handleSelectFileAndScroll:ge,handleHeaderLayoutChange:le,openFileInEditorAtChange:f,getLayoutForFile:P}=yn({hideStackedFileSidebar:t,stackedDefaultCollapsedAll:s,pinSelectedFileHeaderToTopOnNavigate:e,diffScope:a,branchBase:p,branchHead:u,targetFilePath:b});r.useEffect(()=>{c&&l?.(d)},[d,c,l]);const ee=r.useCallback(()=>{B(ne=>!ne)},[B]),xe=r.useCallback(()=>{H(!j)},[j,H]),ce=r.useCallback(()=>{le(q==="side-by-side"?"unified":"side-by-side")},[q,le]),te=A.size,be=r.useMemo(()=>({turnCount:O,branchCount:Y,expandedCount:te,totalCount:I.length,loadFullFiles:L,wrapLines:j,layoutMode:q,onExpandOrCollapseAll:re,onToggleLoadFullFiles:ee,onToggleWrapLines:xe,onToggleLayout:ce}),[O,Y,te,I.length,L,j,q,re,ee,xe,ce]);r.useEffect(()=>{c&&h?.(be)},[c,be,h]);const K=()=>{if(!k)return null;const ne=D=>F!==null?F:y&&D===N;return n.jsxs("div",{className:se("flex min-w-0 flex-1 min-h-0 h-full",g?"gap-0":"gap-3 px-3 pb-3 pt-2"),children:[Z&&n.jsxs("section",{className:"hidden lg:flex w-72 flex-col rounded-xl border border-border/60 bg-background/70 overflow-hidden",children:[n.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-border/40",children:[n.jsx("span",{className:"typography-ui-header font-semibold text-foreground",children:"Files"}),n.jsx("span",{className:"typography-meta text-muted-foreground",children:I.length})]}),n.jsx(en,{changedFiles:I,selectedFile:null,onSelectFile:ge})]}),n.jsx("div",{className:"relative flex-1 min-w-0 min-h-0 h-full",children:n.jsx(et,{ref:ie,outerClassName:"min-h-0 h-full",className:"[overflow-anchor:none] pb-16",disableHorizontal:!0,observeMutations:!1,preventOverscroll:!0,"data-diff-virtual-root":!0,children:n.jsx("div",{className:"flex flex-col [overflow-anchor:none]","data-diff-virtual-content":!0,children:I.map(D=>n.jsx(ln,{directory:k,file:D,layout:P(D),wrapLines:j,isSelected:!1,isExpanded:A.has(D.path),isMounted:M.has(D.path)||D.path===R,onSelect:me,onExpandedChange:ve,registerSectionRef:he,showOpenInEditorAction:i&&d!=="turn"&&d!=="branch",isOpeningInEditor:X===D.path,onOpenInEditor:(Ee,Ae)=>{f(Ee,Ae)},staged:ne(D.path),showFileActions:d!=="turn"&&d!=="branch",loadFullFiles:L,initialDiffData:d==="turn"?fe.get(D.path)??null:d==="branch"?E.get(D.path)??null:null},`${D.path}:${U.get(D.path)??0}`))})})})]})},z=()=>k?d!=="turn"&&m&&!C?n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(J,{name:"loader-4",className:"size-4 animate-spin"}),"Loading repository status..."]}):d!=="turn"&&d!=="branch"&&x===!1?n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:"Not a git repository. Use the Git tab to initialize or change directories."}):d==="branch"&&$?n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(J,{name:"loader-4",className:"size-4 animate-spin"}),"Loading branch changes..."]}):d==="branch"&&W?n.jsx("div",{className:"flex flex-1 items-center justify-center px-4 text-center text-sm text-muted-foreground",children:`Failed to load branch changes: ${W}`}):I.length===0?n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:d==="turn"?"No last turn changes to display":"Working tree clean, no changes to display"}):K():n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:"Select a session directory to view diffs"}),De=n.jsxs("div",{className:w?"flex min-w-0 flex-1 items-center gap-1.5":"@container/diff-toolbar flex min-w-0 items-center gap-2 px-3 py-2 bg-background",children:[(x!==!1||d==="turn")&&(d==="all"||d==="working"||d==="staged"||d==="turn"||d==="branch")?n.jsx(zt,{scope:d,isGitRepo:x,branchAvailable:!!(p&&u),allCount:ae,workingCount:V,stagedCount:pe,turnCount:O,branchCount:Y,onScopeChange:ne=>{_(ne),l?.(ne)}}):n.jsx("div",{className:"flex items-center gap-1 rounded-md px-2 py-1 text-muted-foreground shrink-0",children:n.jsx("span",{className:"typography-ui-label font-medium text-foreground",children:m&&!C?"Loading changes...":I.length===1?`${I.length} file changed`:`${I.length} files changed`})}),I.length>0&&n.jsxs(Le,{variant:"ghost",size:"sm",onClick:re,className:se("diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground","ml-auto"),title:A.size>0?"Collapse all":"Expand all",children:[n.jsx(J,{name:"expand-up-down",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__expand-label typography-ui-label",children:A.size>0?"Collapse all":"Expand all"})]}),I.length>0&&d!=="turn"&&d!=="branch"&&n.jsxs(_t,{children:[n.jsx(Wt,{asChild:!0,children:n.jsx(Le,{variant:"ghost",size:"sm",onClick:()=>B(ne=>!ne),"aria-pressed":L,"aria-label":L?"Unload full files":"Load full files",className:se("h-7 w-7 flex-shrink-0 p-0 text-muted-foreground hover:text-foreground",L&&"bg-interactive-selection text-interactive-selection-foreground"),children:n.jsx(J,{name:"file-download",className:"size-4"})})}),n.jsx(Bt,{children:n.jsx("p",{children:L?"Unload full files":"Load full files"})})]}),I.length>0&&n.jsx(Le,{variant:"ghost",size:"sm",onClick:()=>H(!j),className:se("h-5 w-5 p-0 transition-opacity",j?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:j?"Disable line wrap":"Enable line wrap",children:n.jsx(J,{name:"text-wrap",className:"size-4"})}),q&&n.jsx(it,{mode:q==="side-by-side"?"side-by-side":"unified",onModeChange:le})]});return n.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[w?St.createPortal(De,w):c?null:De,z()]})};export{ms as DiffView};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{j as r}from"./vendor-boot-DyL2td56.js";import{R as a}from"./vendor-react-DASdDPIk.js";import{D}from"./vendor-react-drawio-Duu5LgQA.js";import{o as C}from"./index-Dd2OcIUY.js";import{ak as E,al as S,am as N,an as B,ao as F,ap as H,B as p}from"./useAppFontEffects--lKKtKVo.js";const A='<mxfile><diagram id="new" name="Page-1"><mxGraphModel dx="0" dy="0" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="1169" math="0" shadow="0"><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>';function w(){if(typeof document>"u")return!1;const t=document.documentElement.getAttribute("data-theme");return t==="dark"||!t&&window.matchMedia("(prefers-color-scheme: dark)").matches}const T=a.forwardRef(function({xml:e,readOnly:o,className:d,onChange:u},m){const l=a.useRef(e),c=a.useRef(null),i=a.useRef(!1),[s,y]=a.useState(w),f=a.useRef(e),h=a.useRef(e);h.current!==e&&(h.current=e,f.current=e,l.current=e);const v=a.useRef(s);v.current!==s&&(v.current=s,f.current=l.current);const g=a.useRef(null);a.useEffect(()=>{const n=()=>y(w());n();const x=new MutationObserver(n);return x.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>x.disconnect()},[]),a.useEffect(()=>{const n=setTimeout(()=>{g.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(n)},[]),a.useImperativeHandle(m,()=>({getXml:()=>l.current}));const R=a.useCallback(()=>{!e&&!i.current&&(i.current=!0,setTimeout(()=>{c.current?.template({})},500))},[e]),j=a.useCallback(n=>{l.current=n.xml,u?.(n.xml)},[u]);return r.jsx("div",{ref:g,className:C("h-full w-full",d),children:r.jsx(D,{ref:c,xml:f.current||A,autosave:!0,urlParameters:{ui:o?"simple":s?"dark":"kennedy",spin:!0,libraries:!o,chrome:o,nav:o,layers:o,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:R,onAutoSave:j},s?"dark":"light")})}),X=(t,e)=>!t||t.runtimeKey!==e.runtimeKey||t.root!==e.root||t.path!==e.path||t.generation!==e.generation,b=t=>{if(typeof t=="string")return t;if(t===null)return null},G=(t,e)=>{if(e===!0)return t!==void 0?{expectedRevision:b(t),overwrite:!0}:{overwrite:!0};if(t!==void 0)return{expectedRevision:b(t)}},W=(t,e)=>!!(t&&e&&t.runtimeKey===e.runtimeKey&&t.root===e.root&&t.path===e.path&&t.generation===e.generation),k=(t,e=4e3)=>t.length>e?`${t.slice(0,e)}
|
|
2
|
+
|
|
3
|
+
… truncated …`:t,Y=({open:t,conflict:e,isResolving:o,showCompare:d,onToggleCompare:u,onReload:m,onOverwrite:l,onClose:c})=>{if(!e)return null;const i=!e.exists;return r.jsx(E,{open:t,onOpenChange:s=>{s||c()},children:r.jsxs(S,{showCloseButton:!1,className:"max-w-lg",children:[r.jsxs(N,{children:[r.jsx(B,{children:i?"File deleted on disk":"File changed on disk"}),r.jsx(F,{children:i?`“${e.displayPath}” was deleted since you opened it. Your edits are preserved. Reload to discard them, or overwrite to recreate the file.`:`“${e.displayPath}” changed since you opened it. Your edits are preserved. Reload to discard them and load the current version, or overwrite to keep your edits.`})]}),d&&!i?r.jsxs("div",{className:"grid max-h-64 grid-cols-1 gap-2 overflow-auto py-2",children:[r.jsxs("div",{children:[r.jsx("div",{className:"typography-meta text-muted-foreground",children:"Current version on disk"}),r.jsx("pre",{className:"mt-1 max-h-28 overflow-auto rounded-md bg-[var(--surface-subtle)] p-2 text-xs whitespace-pre-wrap break-words",children:k(e.currentContent??"")})]}),r.jsxs("div",{children:[r.jsx("div",{className:"typography-meta text-muted-foreground",children:"Your edits"}),r.jsx("pre",{className:"mt-1 max-h-28 overflow-auto rounded-md bg-[var(--surface-subtle)] p-2 text-xs whitespace-pre-wrap break-words",children:k(e.dirtyContent)})]})]}):null,r.jsxs(H,{className:"flex flex-wrap gap-2",children:[i?null:r.jsx(p,{variant:"outline",onClick:u,disabled:o,"aria-label":d?"Hide version comparison":"Compare versions",title:d?"Hide version comparison":"Compare versions",children:d?"Hide compare":"Compare"}),r.jsx(p,{variant:"outline",onClick:m,disabled:o,"aria-label":i?"Discard edits and close":"Reload current version",title:i?"Discard edits and close":"Reload current version",children:i?"Discard edits":"Reload"}),r.jsx(p,{variant:"destructive",onClick:l,disabled:o,"aria-label":i?"Recreate file with my edits":"Overwrite with my edits",title:i?"Recreate file with my edits":"Overwrite with my edits",children:o?"Working…":"Overwrite"})]})]})})};export{T as D,Y as F,G as b,W as i,X as s};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{ad as bo,c6 as Nt,c7 as Mn,x as c,ab as pa,J as me,c8 as wo,c9 as yo,H as ha,G as nn,ai as ga,S as ko,aj as Pn,j as t,ae as jo,c0 as Co,a9 as No,ca as So,c3 as st,cb as Er,b$ as Ro,C as Fo,L as kn,cc as Eo,cd as zo,c2 as Mo,aH as To,ce as Do,W as Ao,F as Oo}from"./vendor-boot-DyL2td56.js";import{R as s,a as y}from"./vendor-react-DASdDPIk.js";import{o as J,H as Po,h as Lo,bV as Io,F as Bo,bW as $o,t as Fe,bX as xa,K as Re,a as Vo,A as Wo,L as _o,bY as Ct,I as Ko,J as qo,_ as zr,bZ as Ho,ae as Mr,m as Tr,G as jn,aA as Go}from"./index-Dd2OcIUY.js";import{ch as Uo,a7 as xt,B as q,I as F,ai as Et,ci as Jo,ak as va,al as ba,am as wa,an as ya,ao as ka,ap as ja,a8 as Ln,ab as In,ad as Bn,ae as Zt,t as pe,af as Qt,ag as Xo,cj as en,aj as Ca,E as Dr,b2 as Yo,ck as Na,cl as Sa,cm as Ra,cn as Fa,co as Tn,cp as Zo,a9 as Xe,aa as Ye,ac as Ze,p as Qo,aq as ei,a4 as ti,n as ni,ah as ri,cq as Ar,ar as Or,aM as ai,cr as Pr}from"./useAppFontEffects--lKKtKVo.js";import{javascript as ht}from"./vendor-codemirror-lang-javascript-DpTUrvx8.js";import{json as Ea}from"./vendor-codemirror-lang-json-CLGxdOCz.js";import{css as za}from"./vendor-codemirror-lang-css-Dwf2XpnZ.js";import{html as Dn}from"./vendor-codemirror-lang-html-DcKqyeGk.js";import{markdown as Ma}from"./vendor-codemirror-lang-markdown-DmFP9s6x.js";import{l as Ta}from"./vendor-codemirror-language-data-DglcKYWT.js";import{python as Da}from"./vendor-codemirror-lang-python-yuxIkjit.js";import{shell as si}from"./shell-CjFT_Tl9.js";import{ensurePierreThemeRegistered as Lr,getResolvedShikiTheme as oi}from"./appThemeRegistry-gegrE2dq.js";import{D as ii,i as Aa,b as Oa,s as ci,F as li}from"./FileSaveConflictDialog-BRM9TJo0.js";import{h as Ir,y as ui,z as di,B as fi,E as mi,G as pi,P as Xt}from"./runtimeEndpointReset-CmI6dBKM.js";import{h as An,i as Pa,j as La}from"./SessionUnreadDot-CJFawQpo.js";import{g as St,c as Ia,d as Ba,e as $n,n as hi,f as gi,M as Rt,h as oe,j as xi,s as vi,i as bi,a as wi,t as Yt,k as Cn,b as yi,l as ki,u as ji,m as Br,o as Ci,p as $r}from"./useFilesViewSearch-D1jsGQrN.js";import{J as Ni,F as Si}from"./JsonTreeView-X2Auiy_q.js";import{a as Vr,g as tn,b as Wr,c as _r,o as Ri,d as Fi}from"./vendor-codemirror-search-DaE6R5gH.js";import{v as Ei,g as zi}from"./vendor-replit-codemirror-vim-CZy3BUVv.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-zustand-CUi8eEds.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./runtimeSurface-B1GRkkKC.js";import"./vendor-lezer-javascript-oje4tdp_.js";import"./vendor-lezer-lr-BU2qmu_5.js";import"./vendor-codemirror-autocomplete-DsFn4GLp.js";import"./vendor-lezer-json-BRXb_bDX.js";import"./vendor-lezer-css-DNU_fzPI.js";import"./vendor-lezer-html-DDGRhRUz.js";import"./vendor-lezer-markdown-CicYv7V9.js";import"./vendor-lezer-python-Cuvm9X9Y.js";import"./registerCustomTheme-DmolaWWZ.js";import"./themeResolver-yJ9XpNMI.js";import"./vendor-pierre-theming-Dgp7B_O4.js";import"./vendor-shikijs-core-CGM_jqPK.js";import"./vendor-shikijs-types-CPSbSeK6.js";import"./vendor-shikijs-vscode-textmate-BgLrS_2D.js";import"./vendor-hast-util-to-html-BKBhbTDb.js";import"./vendor-html-void-elements-CkdplsNl.js";import"./vendor-property-information-rJCbAzvX.js";import"./vendor-zwitch-C2o2j-tx.js";import"./vendor-stringify-entities-CsH1VEn9.js";import"./vendor-character-entities-legacy-BpoLgcEt.js";import"./vendor-character-entities-html4-D7taRCQ7.js";import"./vendor-ccount-c2V3InAJ.js";import"./vendor-comma-separated-tokens-D8TqSuIK.js";import"./vendor-space-separated-tokens-DD3iYX1K.js";import"./vendor-hast-util-whitespace-D4Wp6AEg.js";import"./vendor-react-drawio-Duu5LgQA.js";/* empty css */import"./permissionStore-B9Hkrqny.js";import"./web-components-v9fuidaX.js";import"./computeVirtualFileMetrics-3PpRLd5B.js";import"./vendor-shiki-Bbf2GEcE.js";import"./vendor-shikijs-engine-oniguruma-DPWuIF1G.js";import"./vendor-shikijs-engine-javascript-Cme4830A.js";import"./vendor-oniguruma-to-es-DLBnFDCE.js";import"./vendor-oniguruma-parser-C0D4_9rT.js";import"./vendor-regex-BBWcyTkg.js";import"./vendor-regex-utilities-2BQyy0xI.js";import"./vendor-regex-recursion-JU4mF-dD.js";import"./vendor-shikijs-transformers-CZWsLLKm.js";import"./Virtualizer-wpC51ZBQ.js";import"./renderFileWithHighlighter-BvDoP7ob.js";const On=bo.define(si);function Mi(e){const n=e.trim().toLowerCase();switch(n){case"bash":case"sh":case"zsh":case"shell":case"shellsession":case"console":return On;case"json":case"jsonc":case"json5":return Ea().language;case"js":case"javascript":return ht().language;case"jsx":return ht({jsx:!0}).language;case"ts":case"typescript":return ht({typescript:!0}).language;case"tsx":return ht({typescript:!0,jsx:!0}).language;case"html":return Dn().language;case"css":return za().language;case"py":case"python":return Da().language;case"md":case"markdown":case"mdown":case"mkd":return Ma().language;case"heex":case"eex":case"leex":return Dn().language;default:return pa.matchLanguageName(Ta,n,!0)}}const $a=e=>e.split("/").pop()?.toLowerCase()??"",Ti=e=>{const n=$a(e);return n?pa.matchFilename(Ta,n):null},Di=()=>Nt(Mn.define([{tag:[c.heading1,c.heading2,c.heading3,c.heading4,c.heading5,c.heading6],fontWeight:"600"},{tag:c.strong,fontWeight:"600"},{tag:c.emphasis,fontStyle:"italic"},{tag:c.strikethrough,textDecoration:"line-through"},{tag:[c.link,c.url],color:"var(--markdown-link, currentColor)",textDecoration:"underline"},{tag:c.monospace,color:"var(--markdown-inline-code, currentColor)",backgroundColor:"var(--markdown-inline-code-bg, transparent)"},{tag:c.quote,color:"var(--markdown-blockquote, currentColor)",fontStyle:"italic"},{tag:c.list,color:"color-mix(in srgb, var(--muted-foreground) 40%, var(--foreground) 60%)"},{tag:c.heading,color:"var(--markdown-heading1, currentColor)"}]));function Ai(e){const n=e.toLowerCase();switch($a(n)){case"makefile":case"gnumakefile":return On}const i=n.lastIndexOf("."),o=i>=0?n.slice(i+1):"";switch(o){case"ts":case"tsx":case"mts":case"cts":return ht({typescript:!0,jsx:o==="tsx"});case"js":case"jsx":case"mjs":case"cjs":return ht({typescript:!1,jsx:o==="jsx"});case"json":case"jsonc":case"json5":case"jsonl":case"ndjson":case"geojson":return Ea();case"css":case"scss":case"sass":case"less":return za();case"html":case"htm":case"xml":case"drawio":case"dio":return Dn();case"md":case"mdx":case"markdown":case"mdown":case"mkd":return[Ma({codeLanguages:Mi}),Di()];case"sh":case"bash":case"zsh":case"fish":case"env":return On;case"py":case"pyw":case"pyi":return Da();default:return null}}async function Oi(e){const n=Ti(e);if(!n)return null;if(n.support)return n.support;try{return await n.load()}catch{return null}}function Kr(e,n){const a=e.metadata.variant==="dark",i=e.config?.fonts?.mono||"monospace",o=e.colors.syntax.highlights||{},u=e.colors.syntax.tokens||{},f=n?.fontSize?`${n.fontSize}px`:"var(--text-code)",m=me.theme({"&":{backgroundColor:"var(--background)",color:e.colors.syntax.base.foreground,fontSize:f,lineHeight:"1.5",position:"relative"},".cm-scroller":{fontFamily:i,backgroundColor:"var(--background)"},".cm-comment":{color:e.colors.syntax.base.comment},".cm-keyword":{color:e.colors.syntax.base.keyword},".cm-string":{color:e.colors.syntax.base.string},".cm-string-2":{color:u.stringEscape||e.colors.syntax.base.string},".cm-number":{color:e.colors.syntax.base.number},".cm-operator":{color:e.colors.syntax.base.operator},".cm-punctuation":{color:u.punctuation||e.colors.syntax.base.comment},".cm-atom":{color:u.boolean||e.colors.syntax.base.number},".cm-builtin":{color:u.functionCall||e.colors.syntax.base.function},".cm-def":{color:u.variableGlobal||e.colors.syntax.base.variable},".cm-attribute":{color:u.variableOther||u.variableProperty||e.colors.syntax.base.operator},".cm-meta":{color:e.colors.syntax.base.comment},".cm-property":{color:u.variableProperty||e.colors.syntax.base.keyword},".cm-variable":{color:e.colors.syntax.base.variable},".cm-variable-2":{color:u.variableOther||e.colors.syntax.base.function},".cm-variable-3":{color:u.variableGlobal||e.colors.syntax.base.type},".cm-tag":{color:u.tag||e.colors.syntax.base.keyword},".cm-link":{color:u.url||e.colors.syntax.base.keyword,textDecoration:"underline"},".cm-content":{caretColor:e.colors.interactive.cursor},".cm-cursor, .cm-dropCursor":{borderLeftColor:e.colors.interactive.cursor},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, ::selection":{backgroundColor:e.colors.interactive.selection},".cm-gutters":{backgroundColor:"var(--background)",color:o.lineNumber||e.colors.syntax.base.comment,borderRight:`1px solid ${e.colors.interactive.border}`,position:"sticky",paddingRight:"8px",left:0,zIndex:2,boxShadow:"0 0 0 var(--background)"},".cm-gutter":{backgroundColor:"var(--background)"},".cm-gutterElement":{backgroundColor:"var(--background)"},".cm-lineNumbers":{backgroundColor:"var(--background)"},".cm-lineNumbers .cm-gutterElement":{paddingLeft:"8px",paddingRight:"8px",minWidth:"42px"},".cm-activeLineGutter":{color:o.lineNumberActive||e.colors.syntax.base.foreground},".cm-activeLine":{backgroundColor:e.colors.surface.overlay},".cm-panels":{backgroundColor:"transparent",color:e.colors.surface.foreground,position:"absolute",top:"0",right:"0",left:"auto",width:"auto",zIndex:10,pointerEvents:"none"},".cm-panels-top":{borderBottom:"none",position:"absolute",top:"6px",right:"14px",left:"auto",width:"auto"},".cm-panels-bottom":{position:"static",width:"100%",pointerEvents:"auto"},".cm-panels-bottom .cm-vim-panel":{borderTop:`1px solid ${e.colors.interactive.border}`,backgroundColor:e.colors.surface.elevated,color:e.colors.surface.mutedForeground,fontFamily:"var(--font-mono)",fontSize:"12px",minHeight:"22px",padding:"2px 8px"},".cm-panel.cm-search":{pointerEvents:"auto",padding:"4px",backgroundColor:`color-mix(in srgb, ${e.colors.surface.elevated} 85%, transparent)`,border:`1px solid ${e.colors.interactive.border}`,borderRadius:"10px",boxShadow:`0 2px 8px color-mix(in srgb, ${e.colors.surface.background} 60%, transparent)`,width:"auto",minWidth:"360px",maxWidth:"480px"},".cm-search":{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"0",width:"100%",color:e.colors.surface.foreground,fontFamily:"inherit",fontSize:"13px",lineHeight:"1"},".cm-search br":{display:"none"},".cm-search .cm-textfield":{appearance:"none",height:"26px",margin:0,padding:"0 8px",borderRadius:"6px !important",border:`1px solid ${e.colors.interactive.border}`,backgroundColor:e.colors.surface.background,color:e.colors.surface.foreground,fontFamily:"inherit",fontSize:"12px",lineHeight:"1",outline:"none",transition:"border-color 150ms ease"},".cm-search .cm-textfield::placeholder":{color:e.colors.surface.mutedForeground,opacity:1},".cm-search .cm-textfield:focus":{borderColor:e.colors.primary.base},'.cm-search .cm-textfield[name="search"]':{order:1,flex:"1 1 120px",maxWidth:"calc(100% - 142px)",minWidth:"100px"},".cm-search label":{order:2,display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"1px solid transparent",backgroundColor:"transparent",color:"transparent",cursor:"pointer",userSelect:"none",fontSize:"1px",lineHeight:"0",overflow:"hidden",position:"relative",transition:"background-color 120ms ease, border-color 120ms ease"},".cm-search label:hover":{backgroundColor:e.colors.interactive.hover},'.cm-search label:has(input[type="checkbox"]:checked)':{backgroundColor:e.colors.interactive.hover,borderColor:e.colors.interactive.border},'.cm-search [type="checkbox"]':{appearance:"none",WebkitAppearance:"none",width:"0",height:"0",margin:"0",padding:"0",border:"none",position:"absolute",opacity:"0",pointerEvents:"none"},".cm-search label::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"13px",fontWeight:"600",lineHeight:"1",fontFamily:"inherit",color:e.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search label:hover::after":{color:e.colors.surface.foreground},'.cm-search label:has(input[type="checkbox"]:checked)::after':{color:e.colors.surface.foreground},'.cm-search label:has(input[name="case"])::after':{content:'"Aa"',fontSize:"12px",letterSpacing:"-0.5px"},'.cm-search label:has(input[name="re"])::after':{content:'".*"',fontSize:"13px",fontFamily:"monospace"},'.cm-search label:has(input[name="word"])::after':{content:'"ab"',fontSize:"12px",textDecoration:"underline",textUnderlineOffset:"2px"},".cm-search .cm-search-message":{order:3,color:e.colors.surface.mutedForeground,backgroundColor:"transparent",border:"none",borderRadius:"0",padding:"0 6px",fontSize:"11px",whiteSpace:"nowrap",lineHeight:"26px"},".cm-search .cm-button":{appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:0,marginLeft:"1px",padding:0,borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:"transparent",cursor:"pointer",fontSize:"1px",fontWeight:"400",lineHeight:"0",overflow:"hidden",position:"relative",boxShadow:"none",transition:"background-color 120ms ease"},".cm-search .cm-button::after":{position:"absolute",top:"50%",left:"50%",transform:"translate(-50%, -50%)",fontSize:"15px",lineHeight:"1",color:e.colors.surface.mutedForeground,pointerEvents:"none"},".cm-search .cm-button:hover":{backgroundColor:e.colors.interactive.hover},".cm-search .cm-button:hover::after":{color:e.colors.surface.foreground},".cm-search .cm-button:active":{backgroundColor:e.colors.interactive.active},".cm-search .cm-button:focus-visible":{outline:"none",boxShadow:`0 0 0 1px ${e.colors.interactive.focusRing}`},".cm-search .cm-button:disabled":{opacity:.4,cursor:"default",pointerEvents:"none"},'.cm-search .cm-button[name="prev"]':{order:21,marginTop:"2px"},'.cm-search .cm-button[name="prev"]::after':{content:'"↑"'},'.cm-search .cm-button[name="next"]':{order:22,marginTop:"2px"},'.cm-search .cm-button[name="next"]::after':{content:'"↓"'},'.cm-search .cm-button[name="select"]':{order:23,marginTop:"2px"},'.cm-search .cm-button[name="select"]::after':{content:'"≡"',fontSize:"17px"},'.cm-panel.cm-search button[name="close"]':{order:5,appearance:"none",WebkitAppearance:"none",display:"inline-flex",alignItems:"center",justifyContent:"center",width:"26px",height:"26px",minWidth:"26px",flexShrink:"0",margin:"0 0 0 auto",padding:"0",borderRadius:"4px",border:"none",backgroundColor:"transparent",backgroundImage:"none",color:e.colors.surface.mutedForeground,cursor:"pointer",fontSize:"16px",lineHeight:"1",boxShadow:"none",position:"relative",overflow:"visible",transition:"background-color 120ms ease, color 120ms ease"},'.cm-panel.cm-search button[name="close"]:hover':{backgroundColor:e.colors.interactive.hover,color:e.colors.surface.foreground},'.cm-search .cm-button[name="replace"]':{order:24,marginTop:"2px"},'.cm-search .cm-button[name="replace"]::after':{content:'"⇄"'},'.cm-search .cm-button[name="replaceAll"], .cm-search .cm-button[name="replace-all"]':{order:25,marginTop:"2px"},'.cm-search .cm-button[name="replaceAll"]::after, .cm-search .cm-button[name="replace-all"]::after':{content:'"⇉"'},'.cm-search .cm-textfield[name="replace"]':{order:20,flex:"1 1 100%",maxWidth:"calc(100% - 142px)",minWidth:"80px",marginTop:"2px"},".cm-searchMatch":{backgroundColor:e.colors.status.infoBackground,boxShadow:`inset 0 0 0 1px ${e.colors.status.infoBorder}`,borderRadius:"2px"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:e.colors.interactive.selection,color:e.colors.interactive.selectionForeground,boxShadow:`inset 0 0 0 1px ${e.colors.interactive.borderFocus}`},"&.cm-focused":{outline:"none"}},{dark:a}),g=Mn.define([{tag:[c.comment,c.docComment,c.meta,c.documentMeta],class:"cm-comment"},{tag:[c.keyword,c.controlKeyword,c.moduleKeyword,c.definitionKeyword,c.modifier],class:"cm-keyword"},{tag:[c.operatorKeyword,c.operator,c.derefOperator,c.updateOperator,c.definitionOperator,c.typeOperator,c.controlOperator,c.logicOperator,c.bitwiseOperator,c.arithmeticOperator,c.compareOperator],class:"cm-operator"},{tag:[c.punctuation,c.separator,c.bracket,c.paren,c.brace,c.squareBracket,c.angleBracket],class:"cm-punctuation"},{tag:[c.string,c.regexp,c.attributeValue,c.special(c.string),c.monospace],class:"cm-string"},{tag:c.escape,class:"cm-string-2"},{tag:[c.number,c.bool,c.atom,c.null,c.self],class:"cm-number"},{tag:[c.function(c.variableName),c.function(c.definition(c.variableName)),c.function(c.propertyName),c.standard(c.variableName),c.special(c.variableName)],class:"cm-builtin"},{tag:c.definition(c.variableName),class:"cm-def"},{tag:[c.variableName,c.local(c.variableName),c.constant(c.variableName),c.literal],class:"cm-variable"},{tag:c.propertyName,class:"cm-property"},{tag:c.attributeName,class:"cm-attribute"},{tag:[c.className,c.typeName,c.namespace],class:"cm-variable-3"},{tag:[c.tagName,c.labelName,c.annotation,c.macroName],class:"cm-tag"},{tag:c.link,class:"cm-link"},{tag:[c.heading,c.heading1,c.heading2,c.heading3,c.heading4,c.heading5,c.heading6],class:"cm-keyword"}]),w=Mn.define([{tag:[c.comment,c.docComment,c.meta,c.documentMeta],color:e.colors.syntax.base.comment},{tag:[c.keyword,c.controlKeyword,c.moduleKeyword,c.definitionKeyword,c.modifier],color:e.colors.syntax.base.keyword},{tag:[c.operatorKeyword,c.operator,c.derefOperator,c.updateOperator,c.definitionOperator,c.typeOperator,c.controlOperator,c.logicOperator,c.bitwiseOperator,c.arithmeticOperator,c.compareOperator],color:e.colors.syntax.base.operator},{tag:[c.string,c.regexp,c.attributeValue,c.special(c.string),c.monospace],color:e.colors.syntax.base.string},{tag:c.escape,color:u.stringEscape||e.colors.syntax.base.string},{tag:[c.number,c.bool,c.atom,c.null,c.self],color:e.colors.syntax.base.number},{tag:[c.function(c.variableName),c.function(c.definition(c.variableName)),c.function(c.propertyName),c.standard(c.variableName),c.special(c.variableName)],color:e.colors.syntax.base.function},{tag:c.definition(c.variableName),color:u.variableGlobal||e.colors.syntax.base.variable},{tag:[c.variableName,c.local(c.variableName),c.constant(c.variableName),c.literal],color:e.colors.syntax.base.variable},{tag:c.propertyName,color:u.variableProperty||e.colors.syntax.base.variable},{tag:c.attributeName,color:u.variableOther||e.colors.syntax.base.variable},{tag:[c.className,c.typeName,c.namespace],color:e.colors.syntax.base.type},{tag:[c.tagName,c.labelName,c.annotation,c.macroName],color:u.tag||e.colors.syntax.base.keyword},{tag:c.link,color:u.url||e.colors.syntax.base.function,textDecoration:"underline"},{tag:[c.punctuation,c.separator,c.bracket,c.paren,c.brace,c.squareBracket,c.angleBracket],color:u.punctuation||e.colors.syntax.base.comment}]);return n?.syntaxColors===!1?[m]:[m,Nt(wo,{fallback:!0}),Nt(yo),Nt(g),Nt(w)]}const Pi=180,Va=ko.define(),Li=1,Ii=2,Bi=4,qr=new Map,$i=(e,n)=>{const a=`${e}|${n}`,i=qr.get(a);if(i)return i;let o="";e&&(o+=`color:${e};`),n&Li&&(o+="font-style:italic;"),n&Ii&&(o+="font-weight:bold;"),n&Bi&&(o+="text-decoration:underline;");const u=nn.mark({attributes:{style:o}});return qr.set(a,u),u},Vi=(e,n)=>{const a=new Pn,i=e.state.doc,o=Math.min(n.length,i.lines);for(let u=0;u<o;u+=1){const f=n[u];if(!f||f.length===0)continue;const m=i.line(u+1);let g=m.from;for(const[w,N,x]of f){if(w<=0)continue;const b=g,j=Math.min(g+w,m.to);g+=w,!(j<=b)&&(!N&&!x||a.add(b,j,$i(N,x)))}}return a.finish()},Wi=ha.define({create(){return nn.none},update(e,n){let a=e.map(n.changes);for(const i of n.effects)i.is(Va)&&(a=i.value);return a},provide:e=>me.decorations.from(e)}),_i=e=>ga.fromClass(class{timer;generation=0;constructor(n){this.tokenize(n)}update(n){n.docChanged&&this.schedule(n.view)}schedule(n){this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0,this.tokenize(n)},Pi)}async tokenize(n){const a=++this.generation,i=n.state.doc.toString(),o=await Uo(i,e.language,e.themeName,e.theme);o&&a===this.generation&&n.state.doc.length===i.length&&n.dispatch({effects:Va.of(Vi(n,o))})}destroy(){this.timer&&clearTimeout(this.timer)}}),Ki=e=>[Wi,_i(e)],Ke=e=>(e||"").replace(/\\/g,"/").replace(/\/+$/g,""),gt=e=>{const n=Ke(e);return!n||n==="/"?n||"/":n.split("/").filter(Boolean).at(-1)??n},Wa=e=>{const n=Ke(e);if(!n||n==="/")return null;const a=n.lastIndexOf("/");if(a<0)return null;if(a===0)return"/";const i=n.slice(0,a);return/^[A-Za-z]:$/.test(i)?`${i}/`:i},Hr=(e,n)=>{const a=Ke(e),i=Ke(n);return!a||!i?!1:a===i||a.startsWith(`${i}/`)},Gr=(e,n)=>{const a=Ke(e);if(!a)return Ke(n);if(a.startsWith("/")||/^[A-Za-z]:(\/|$)/.test(a))return a;const i=Ke(n);return i?`${i}/${a}`:a},qi=(e,n)=>{const a=Ke(e),i=Ke(n);if(!a||a===i)return!1;const o=Wa(a);return o?i&&Hr(a,i)?Hr(o,i):!0:!1},Hi=e=>{if(typeof e!="number"||!Number.isFinite(e)||e<0)return"";if(e<1024)return`${e} B`;const n=["KB","MB","GB"];let a=e/1024;for(const i of n){if(a<1024||i===n[n.length-1])return`${a.toFixed(a>=10?0:1)} ${i}`;a/=1024}return""},Gi=(e,n)=>!n||e===n?gt(e):e.startsWith(`${n}/`)?e.slice(n.length+1):e,Ui=({root:e,directory:n,entries:a,query:i,searchResults:o,isSearching:u,directoryError:f,refreshing:m,editorPath:g,editor:w,onClose:N,onQueryChange:x,onOpenDirectory:b,onOpenFile:j,onBackFromEditor:C,onRefresh:v})=>{if(!e)return t.jsx(Ft,{message:"Select a project to browse files."});if(g)return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsx(Ir,{leading:t.jsx(q,{type:"button",variant:"ghost",size:"icon","aria-label":"Back",onClick:C,style:{touchAction:"manipulation"},children:t.jsx(F,{name:"arrow-left",className:"size-4"})}),icon:t.jsx(xt,{filePath:g,className:"size-4 shrink-0"}),title:gt(g)}),t.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:w})]});const L=n===e?"Project files":gt(n),I=qi(n,e)?Wa(n):null,l=!!I&&!i.trim(),B=I===e?"Project files":gt(I??""),H=N||l&&I?t.jsxs(t.Fragment,{children:[N?t.jsx(q,{type:"button",variant:"ghost",size:"icon","aria-label":"Close",onClick:N,style:{touchAction:"manipulation"},children:t.jsx(F,{name:"close",className:"size-4"})}):null,l&&I?t.jsx(q,{type:"button",variant:"ghost",size:"icon","aria-label":`Back to ${gt(I)}`,onClick:()=>b(I),style:{touchAction:"manipulation"},children:t.jsx(F,{name:"arrow-left",className:"size-4"})}):null]}):void 0;return t.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background text-foreground",children:[t.jsx(Ir,{leading:H,icon:n===e?"file-text":"folder",title:L,actions:t.jsx(q,{type:"button",variant:"ghost",size:"icon","aria-label":"Refresh files",onClick:v,style:{touchAction:"manipulation"},children:t.jsx(F,{name:"refresh",className:J("size-4",m&&"animate-spin")})})}),t.jsx("div",{className:"shrink-0 px-3 py-2",children:t.jsxs("div",{className:"relative",children:[t.jsx(F,{name:"search",className:"pointer-events-none absolute left-2 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground"}),t.jsx(Et,{value:i,onChange:D=>x(D.target.value),placeholder:"Search files",className:"h-8 pl-7"})]})}),t.jsx(Jo,{className:"min-h-0 w-full flex-1 overflow-y-auto pb-3",children:f?t.jsx(Ft,{message:f}):i.trim()?t.jsx(Ji,{root:e,results:o,isSearching:u,onOpenFile:j}):a===void 0?t.jsx(Ft,{loading:!0,message:"Loading..."}):t.jsxs("div",{className:"flex w-full min-w-0 flex-col px-1",children:[l&&I?t.jsxs("button",{type:"button",className:J(La,"px-2"),"aria-label":`Up one level to ${B}`,onClick:()=>b(I),style:{touchAction:"manipulation"},children:[t.jsx(F,{name:"arrow-left",className:J(An(!0),"text-muted-foreground")}),t.jsx("span",{className:J(Pa(!0),"flex-1 text-muted-foreground"),children:"Up one level"})]}):null,a.length===0?t.jsx("div",{className:"px-3 py-8 text-center typography-ui-label text-muted-foreground",children:"This directory is empty."}):null,a.map(D=>t.jsx(_a,{name:D.name,path:D.path,directory:D.type==="directory",meta:D.type==="directory"?void 0:Hi(D.size),onClick:()=>D.type==="directory"?b(Gr(D.path,n||e)):j(Gr(D.path,n||e))},D.path))]})})]})},_a=({name:e,path:n,directory:a,meta:i,onClick:o})=>t.jsxs("button",{type:"button",className:J(La,"px-2"),onClick:o,style:{touchAction:"manipulation"},children:[a?t.jsx(F,{name:"folder-3-fill",className:J(An(!0),"text-primary/80")}):t.jsx(xt,{filePath:n,className:An(!0)}),t.jsx("span",{className:J(Pa(!0),"flex-1 text-foreground"),children:e}),i?t.jsx("span",{className:"shrink-0 typography-micro text-muted-foreground",children:i}):null,a?t.jsx(F,{name:"arrow-right-s",className:"size-4 shrink-0 text-muted-foreground/60"}):null]}),Ji=({root:e,results:n,isSearching:a,onOpenFile:i})=>a?t.jsx(Ft,{loading:!0,message:"Loading..."}):n.length===0?t.jsx(Ft,{message:"No files found."}):t.jsx("div",{className:"flex w-full min-w-0 flex-col px-1",children:n.map(o=>t.jsx(_a,{name:gt(o.path),path:o.path,directory:!1,meta:o.relativePath??Gi(o.path,e),onClick:()=>i(o.path)},o.path))}),Ft=({message:e,loading:n=!1})=>t.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center",children:t.jsxs("div",{className:"flex max-w-sm flex-col items-center gap-2",children:[n?t.jsx(F,{name:"loader-4",className:"size-5 animate-spin text-muted-foreground"}):t.jsx(F,{name:"folder-open-fill",className:"size-6 text-muted-foreground"}),t.jsx("p",{className:"typography-ui-label font-semibold text-foreground",children:e})]})}),Xi=({activeDialog:e,dialogData:n,dialogInputValue:a,onDialogInputChange:i,isDialogSubmitting:o,onDialogSubmit:u,onClose:f,inputRef:m})=>t.jsx(va,{open:!!e,onOpenChange:g=>!g&&f(),children:t.jsxs(ba,{initialFocus:m,children:[t.jsxs(wa,{children:[t.jsxs(ya,{children:[e==="createFile"&&"Create File",e==="createFolder"&&"Create Folder",e==="rename"&&"Rename",e==="delete"&&"Delete"]}),t.jsxs(ka,{children:[e==="createFile"&&`Create a new file in ${n?.path??"root"}`,e==="createFolder"&&`Create a new folder in ${n?.path??"root"}`,e==="rename"&&`Rename ${n?.name??""}`,e==="delete"&&`Are you sure you want to delete ${n?.name??""}? This action cannot be undone.`]})]}),e!=="delete"&&t.jsx("div",{className:"py-4",children:t.jsx(Et,{value:a,onChange:g=>i(g.target.value),placeholder:e==="rename"?"New name":"Name",onKeyDown:g=>{g.key==="Enter"&&u()},ref:m})}),t.jsxs(ja,{children:[t.jsx(q,{variant:"outline",onClick:f,disabled:o,children:"Cancel"}),t.jsx(q,{variant:e==="delete"?"destructive":"default",onClick:()=>{u()},disabled:o||e!=="delete"&&!a.trim(),children:o?t.jsx(F,{name:"loader-4",className:"size-4 animate-spin"}):e==="delete"?"Delete":"Confirm"})]})]})}),Yi=({label:e,iconDataUrl:n})=>{const[a,i]=s.useState(!1),o=e.trim().slice(0,1).toUpperCase()||"?";return n&&!a?t.jsx("img",{src:n,alt:"",className:"size-4 rounded-sm",onError:()=>i(!0)}):t.jsx("span",{className:J("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),children:o})},Ka=({filePath:e,extension:n})=>t.jsx(xt,{filePath:e,extension:n}),Zi=({status:e})=>{const n={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"}[e];return t.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:n}})},Ur=({name:e})=>{const n=s.useRef(null),a=s.useRef(null),[i,o]=s.useState(!1);return s.useLayoutEffect(()=>{const u=n.current,f=a.current;if(!u||!f)return;const m=()=>{o(f.scrollWidth>u.clientWidth+1)};m();const g=new ResizeObserver(m);return g.observe(u),g.observe(f),()=>{g.disconnect()}},[e]),t.jsxs("span",{ref:n,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[t.jsx("span",{ref:a,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:e}),i?t.jsxs("span",{className:"open-file-name-marquee-track",children:[t.jsx("span",{className:"open-file-name-marquee-item",children:e}),t.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:e})]}):t.jsx("span",{className:"block min-w-0 truncate",children:e})]})},Qi=({node:e,root:n,isExpanded:a,isActive:i,isMobile:o,isBrowserClient:u,alwaysShowActions:f,status:m,badge:g,permissions:w,downloadFile:N,contextMenuPath:x,setContextMenuPath:b,rightClickMenuPath:j,setRightClickMenuPath:C,onSelect:v,onToggle:L,onRevealPath:I,onOpenDialog:l})=>{const B=e.type==="directory",{canRename:H,canCreateFile:D,canCreateFolder:$,canDelete:G,canReveal:_}=w,X=!B&&!!N,A=_&&!u,T=H||D||$||G||X||A,k=s.useCallback(d=>{T&&(d?.preventDefault(),C(e.path))},[T,e.path,C]),V=s.useCallback(()=>{B?L(e.path):v(e)},[B,e,v,L]),E=s.useCallback(d=>{d.stopPropagation(),C(null),b(e.path)},[e.path,b,C]),R=({Item:d,Separator:O})=>t.jsxs(t.Fragment,{children:[H&&t.jsxs(d,{onClick:S=>{S.stopPropagation(),l("rename",e)},children:[t.jsx(F,{name:"edit",className:"mr-2 size-4"})," ","Rename"]}),t.jsxs(d,{onClick:S=>{S.stopPropagation(),Zt(e.path).then(P=>{if(P.ok){pe.success("Path copied");return}pe.error("Copy failed")})},children:[t.jsx(F,{name:"file-copy",className:"mr-2 size-4"})," ","Copy Path"]}),t.jsxs(d,{onClick:S=>{S.stopPropagation();const P=St(n,e.path)||e.path;Zt(P).then(Y=>{if(Y.ok){pe.success("Relative path copied");return}pe.error("Copy failed")})},children:[t.jsx(F,{name:"file-copy-2",className:"mr-2 size-4"})," ","Copy Relative Path"]}),!B&&N&&t.jsxs(d,{onClick:S=>{S.stopPropagation(),N(e.path).catch(P=>{console.error("Download failed:",P),pe.error("Operation failed")})},children:[t.jsx(F,{name:"download",className:"mr-2 size-4"})," ",u?"Download":"Save"]}),A&&t.jsxs(d,{onClick:S=>{S.stopPropagation(),I(e.path)},children:[t.jsx(F,{name:"folder-received",className:"mr-2 size-4"})," ",Po()]}),B&&(D||$)&&t.jsxs(t.Fragment,{children:[t.jsx(O,{}),D&&t.jsxs(d,{onClick:S=>{S.stopPropagation(),l("createFile",e)},children:[t.jsx(F,{name:"file-add",className:"mr-2 size-4"})," ","New File"]}),$&&t.jsxs(d,{onClick:S=>{S.stopPropagation(),l("createFolder",e)},children:[t.jsx(F,{name:"folder-add",className:"mr-2 size-4"})," ","New Folder"]})]}),G&&t.jsxs(t.Fragment,{children:[t.jsx(O,{}),t.jsxs(d,{onClick:S=>{S.stopPropagation(),l("delete",e)},className:"text-destructive focus:text-destructive",children:[t.jsx(F,{name:"delete-bin",className:"mr-2 size-4"})," ","Delete"]})]})]});return t.jsxs(ui,{open:j===e.path,onOpenChange:d=>C(d?e.path:null),children:[t.jsxs(di,{render:t.jsx("div",{className:"group relative flex items-center",onContextMenu:o?void 0:k}),children:[t.jsxs("button",{type:"button",onClick:V,onContextMenu:o?void 0:k,className:J("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[B?a?t.jsx(F,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):t.jsx(F,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):t.jsx(Ka,{filePath:e.path,extension:e.extension}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:e.path,children:e.name}),!B&&m&&t.jsx(Zi,{status:m}),B&&g&&t.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[g.modified>0&&t.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",g.modified]}),g.added>0&&t.jsxs("span",{className:"text-[var(--status-success)]",children:["+",g.added]})]})]}),T&&t.jsx("div",{className:J("absolute right-1 top-1/2 -translate-y-1/2",f?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:t.jsxs(Ln,{open:x===e.path,onOpenChange:d=>b(d?e.path:null),children:[t.jsx(In,{asChild:!0,children:t.jsx(q,{variant:"ghost",size:"icon",className:"size-6",onClick:E,children:t.jsx(F,{name:"more-2-fill",className:"size-4"})})}),t.jsx(Bn,{align:"end",side:"bottom",onCloseAutoFocus:()=>b(null),children:R({Item:Qt,Separator:Xo})})]})})]}),t.jsx(fi,{className:"min-w-[180px]",children:R({Item:mi,Separator:pi})})]})},Nn=(e,n,a)=>{const[i,o]=s.useState(""),[u,f]=s.useState(0);return s.useEffect(()=>{if(!e){o("");return}let m=!1;o("");const g=Lo(),w=Io(g);Bo(g).then(x=>{m||!x||(o(e),n(null))}).catch(x=>{m||(n(x instanceof Error?x.message:a),o(e))});const N=$o(()=>{m||(o(e),f(x=>x+1),n(null))});return()=>{m=!0,w(),N()}},[e,n,a]),{readyKey:i,nonce:u}},ec=e=>e!==null&&typeof e=="object"&&"updateStatus"in e&&typeof e.updateStatus=="function",tc=e=>{const n=document.createElement("div");n.className="cm-vim-panel";const a=zi(e);if(!a)return{top:!1,dom:n};a.state.statusbar=n;const i=a.state.vimPlugin;return ec(i)&&i.updateStatus(),{top:!1,dom:n,destroy(){a.state.statusbar===n&&(a.state.statusbar=null)}}};function Jr(e){return e?[Ei(),jo.of(tc),Co()]:[]}const nc={next:"Next match",prev:"Previous match",select:"Select all matches",replace:"Replace",replaceAll:"Replace all",close:"Close"},rc={case:"Match case",re:"Regular expression",word:"Match whole word"};function ac(e){const n=e.querySelector(".cm-search");if(n){for(const[a,i]of Object.entries(nc)){const o=n.querySelector(`button[name="${a}"]`);o&&!o.title&&(o.title=i)}for(const[a,i]of Object.entries(rc)){const u=n.querySelector(`input[name="${a}"]`)?.parentElement;u&&!u.title&&(u.title=i)}}}const Sn=new WeakMap;function sc(e,n){const a=tn(e.state);if(!a.valid)return Sn.delete(e),0;const i=Sn.get(e);if(!n&&i?.doc===e.state.doc&&i.query.eq(a))return i.total;const o=a.getCursor(e.state);let u=0;for(let f=o.next();!f.done;f=o.next())u+=1;return Sn.set(e,{query:a,doc:e.state.doc,total:u}),u}function oc(e){const n=tn(e.state);if(!n.valid)return 0;const a=e.state.selection.main,i=n.getCursor(e.state);let o=0,u=0;for(let f=i.next();!f.done;f=i.next()){const m=f.value;if(o+=1,u===0&&(u=o),a.from===m.from&&a.to===m.to||a.from<m.to&&a.to>m.from||m.from>=a.head)return o}return u}function Xr(e,n,a=!1){const i=e.querySelector(".cm-search");if(!i)return;let o=i.querySelector(".cm-search-message");if(!o){o=document.createElement("span"),o.className="cm-search-message",o.setAttribute("aria-live","polite");const m=i.querySelector('button[name="next"]'),g=m?.parentNode===i?m:i.firstChild;i.insertBefore(o,g)}const u=sc(n,a),f=u===0?0:oc(n);o.textContent=u===0?"":`${f}/${u}`}const Yr=new st,Zr=new st,Qr=new st,ea=new st,ta=new st,na=new st,ra=new st,aa=e=>e,Rn=Do,ic=Ri,cc=Fi;class lc extends Ao{constructor(n,a){super(),this.id=n,this.containerMap=a}toDOM(){let n=this.containerMap.get(this.id);return n||(n=document.createElement("div"),n.className="oc-block-widget",n.dataset.widgetId=this.id,this.containerMap.set(this.id,n)),n}eq(n){return n.id===this.id}destroy(){}}const sa=(e,n)=>!e||e.length===0?[]:ha.define({create(a){const i=new Pn,o=[...e].sort((u,f)=>u.afterLine-f.afterLine);for(const u of o){const f=a.doc.lines;if(u.afterLine>f)continue;const m=a.doc.line(u.afterLine);i.add(m.to,m.to,nn.widget({widget:new lc(u.id,n),block:!0,side:1}))}return i.finish()},update(a,i){return a.map(i.changes)},provide:a=>me.decorations.from(a)}),oa=e=>{if(!e)return[];const n=Math.max(1,e.start),a=Math.max(n,e.end);return ga.fromClass(class{decorations;constructor(i){this.decorations=this.build(i)}update(i){(i.docChanged||i.viewportChanged)&&(this.decorations=this.build(i.view))}build(i){const o=new Pn;for(let u=n;u<=a&&u<=i.state.doc.lines;u+=1){const f=i.state.doc.line(u);o.add(f.from,f.from,nn.line({class:"oc-cm-selected-line"}))}return o.finish()}},{decorations:i=>i.decorations})};function uc({value:e,onChange:n,extensions:a,className:i,readOnly:o,lineNumbersConfig:u,highlightLines:f,onViewReady:m,onViewDestroy:g,blockWidgets:w,enableSearch:N,searchOpen:x,onSearchOpenChange:b,vimMode:j}){const C=s.useRef(null),v=s.useRef(null),L=s.useRef(e),I=s.useRef(n),l=s.useRef(m),B=s.useRef(g),H=s.useRef(b),D=s.useRef(w),$=s.useRef(j),G=s.useRef(new Map),[_,X]=s.useState([]),A=s.useCallback(k=>{const V=(k??[]).map(E=>{const R=G.current.get(E.id);return R?{id:E.id,content:E.content,container:R}:null}).filter(E=>E!==null);X(E=>E.length===V.length&&E.every((R,d)=>{const O=V[d];return R.id===O.id&&R.content===O.content&&R.container===O.container})?E:V)},[]),T=s.useCallback(k=>{const V=C.current,E=k??v.current;if(!V||!E)return;const R=E.dom.querySelector(".cm-gutters"),d=R instanceof HTMLElement?R.getBoundingClientRect().width:0;V.style.setProperty("--oc-editor-gutter-width",`${d}px`)},[]);return s.useEffect(()=>{L.current=e},[e]),s.useEffect(()=>{I.current=n},[n]),s.useEffect(()=>{l.current=m,B.current=g},[m,g]),s.useEffect(()=>{H.current=b},[b]),s.useEffect(()=>{D.current=w,A(w)},[w,A]),s.useEffect(()=>{if(!C.current)return;const k=(()=>{if(typeof document>"u")return null;const E=document.querySelector('meta[name="csp-nonce"]')?.getAttribute("content");if(E)return E;const R=window.__PICHAMBER_CSP_NONCE__;return typeof R=="string"&&R.length>0?R:null})(),V=No.create({doc:L.current,extensions:[...k?[me.cspNonce.of(k)]:[],So({fixed:!0}),Yr.of(Er(u)),Ro(),Fo.of(" "),ra.of(Jr(j)),kn.of([Eo,...zo,...Mo]),me.updateListener.of(E=>{T(E.view),(E.viewportChanged||E.geometryChanged)&&A(D.current);const R=Vr(E.startState),d=Vr(E.state);R!==d&&H.current?.(d);const O=!tn(E.startState).eq(tn(E.state));if(d&&(R!==d||O||E.docChanged||E.selectionSet)&&Xr(E.view.dom,E.view,R!==d||O||E.docChanged),!E.docChanged)return;const S=E.state.doc.toString();L.current=S,I.current(S),A(D.current)}),Zr.of(me.editable.of(!o)),Qr.of(a??[]),ea.of(oa(f)),ta.of(sa(w,G.current)),na.of(N?[Wr({top:!0}),kn.of(aa(_r))]:[])]});return v.current=new me({state:V,parent:C.current}),Rn(v.current,v.current.state.doc.length,200),v.current.requestMeasure(),requestAnimationFrame(()=>{T(v.current),A(D.current)}),v.current&&l.current?.(v.current),()=>{B.current?.(),v.current?.destroy(),v.current=null,X([])}},[D,T,A]),s.useEffect(()=>{const k=v.current;k&&(k.dispatch({effects:[Yr.reconfigure(Er(u)),Zr.reconfigure(me.editable.of(!o)),Qr.reconfigure(a??[]),ea.reconfigure(oa(f)),ta.reconfigure(sa(w,G.current)),na.reconfigure(N?[Wr({top:!0}),kn.of(aa(_r))]:[])]}),Rn(k,k.state.doc.length,200),k.requestMeasure(),requestAnimationFrame(()=>{T(k),A(D.current)}))},[a,f,u,o,w,N,T,A]),s.useEffect(()=>{const k=v.current;if(!k){$.current=j;return}$.current!==j&&($.current=j,k.dispatch({effects:ra.reconfigure(Jr(j))}))},[j]),s.useEffect(()=>{const k=v.current;!k||N===!1||(x?(ic(k),requestAnimationFrame(()=>{ac(k.dom),Xr(k.dom,k,!0)})):cc(k))},[x,N]),s.useEffect(()=>{const k=v.current;if(!k)return;const V=k.state.doc.toString();V!==e&&(k.dispatch({changes:{from:0,to:V.length,insert:e}}),Rn(k,k.state.doc.length,300),k.requestMeasure(),requestAnimationFrame(()=>T(k)))},[e,T]),t.jsxs(t.Fragment,{children:[t.jsx("div",{ref:C,className:J("h-full w-full","[&_.cm-editor]:h-full [&_.cm-editor]:w-full","[&_.cm-scroller]:font-mono [&_.cm-scroller]:text-[var(--text-code)] [&_.cm-scroller]:leading-6","[&_.cm-lineNumbers]:text-[var(--tools-edit-line-number)]",i)}),_.map(k=>To.createPortal(k.content,k.container,k.id))]})}const ia=({variant:e,selectedFile:n,loading:a,suppressLoadingIndicator:i,fileError:o,isSelectedImage:u,imageSrc:f,imagePreviewNonce:m,isSelectedPdf:g,pdfSrc:w,pdfPreviewNonce:N,isUnsupportedBinary:x,onDownload:b,enableRichPreviews:j,drawioViewMode:C,drawioRemountNonce:v,diagramEditorRef:L,diagramEditorXml:I,onDiagramChange:l,jsonViewMode:B,markdownViewMode:H,htmlViewMode:D,htmlLoading:$,htmlPreviewNonce:G,htmlPreviewSrc:_,fileContent:X,canUseShikiFileView:A,textViewMode:T,draftContent:k,onDraftChange:V,canEdit:E,vimMode:R,editorExtensions:d,editorWrapperRef:O,shouldMaskEditorForPendingNavigation:S,onEditorViewReady:P,onEditorViewDestroy:Y,enableSearch:ee=!1,searchOpen:re,onSearchOpenChange:te,pierreTheme:K,shikiThemeType:Q,wrapLines:Qe})=>{const Oe=e==="fullscreen",le=Oe?"p-4":"p-3",Pe=!!(n?.path&&en(n.path)),Le=!!(n?.path&&Ia(n.path)),ae=!!(n?.path&&Ba(n.path)),ue=!!(n?.path&&$n(n.path)),ye=()=>n?t.jsx("div",{className:"h-full",children:t.jsx(Si,{file:{name:n.name,contents:k,lang:Na(n.path)||void 0},options:{disableFileHeader:!0,overflow:Qe?"wrap":"scroll",theme:K,themeType:Q},className:"block h-full w-full",style:{height:"100%"}})}):null;return t.jsx(Ca,{outerClassName:"h-full min-w-0",className:"h-full min-w-0",children:n?a?i?t.jsx("div",{className:le}):t.jsxs("div",{className:`${le} flex items-center gap-2 typography-ui text-muted-foreground`,children:[t.jsx(F,{name:"loader-4",className:"size-4 animate-spin"}),Oe?"Loading…":"Loading..."]}):o?t.jsx("div",{className:`${le} typography-ui text-[color:var(--status-error)]`,children:o}):u?t.jsx("div",{className:J("flex h-full items-center justify-center",le),children:t.jsx("img",{src:f,alt:n.name||"Image",className:J("max-w-full object-contain rounded-md border border-border/30 bg-primary/10",Oe?"max-h-full":"max-h-[70vh]")},m)}):g?t.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:t.jsx("iframe",{src:w,className:"h-full w-full border-0",title:n.name},N)}):x?t.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[t.jsx("div",{className:"typography-ui-header text-foreground",children:"Cannot preview binary file"}),t.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:"This file is binary and cannot be edited in PiChamber. Download it to open with another app."}),b?t.jsxs(q,{type:"button",variant:"outline",size:"sm",onClick:b,children:[t.jsx(F,{name:"download",className:"mr-2 size-4"}),"Save file"]}):null]}):j&&Pe&&C==="preview"?t.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:t.jsx(ii,{ref:L,xml:I,onChange:l},`${n.path}:${v}`)}):j&&Le&&B==="tree"?t.jsx(Dr,{fallback:t.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[t.jsx("div",{className:"mb-1 font-medium text-destructive",children:"JSON viewer unavailable"}),t.jsx("div",{className:"text-sm text-muted-foreground",children:"Switch to text mode to view raw content."})]}),children:t.jsx("div",{className:"h-full overflow-auto",children:t.jsx(Ni,{jsonString:X,maxHeight:"100%",initiallyExpandedDepth:2})})}):ae&&H==="preview"?t.jsxs("div",{className:J("h-full overflow-auto",le),children:[X.length>500*1024?t.jsx("div",{className:"mb-3 rounded-md border border-status-warning/20 bg-status-warning/10 px-3 py-2 text-sm text-status-warning",children:`This file is large (${Math.round(X.length/1024)}KB). Preview may be limited.`}):null,t.jsx(Dr,{fallback:t.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[t.jsx("div",{className:"mb-1 font-medium text-destructive",children:"Preview unavailable"}),t.jsx("div",{className:"text-sm text-muted-foreground",children:"Switch to edit mode to fix the issue."})]}),children:t.jsx(Yo,{content:X,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}):j&&ue&&D==="preview"?$?t.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:"Loading..."}):t.jsx("div",{className:"h-full overflow-hidden",children:t.jsx("iframe",{src:_,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:"HTML Preview"},G)}):A&&T==="view"?ye():t.jsxs("div",{className:J("relative h-full",S&&"overflow-hidden"),ref:O,children:[t.jsx("div",{className:J("h-full",S&&"invisible"),children:t.jsx(uc,{value:k,onChange:V,readOnly:!E,vimMode:R,extensions:d,className:"h-full",onViewReady:P,onViewDestroy:Y,...ee?{enableSearch:!0,searchOpen:re,onSearchOpenChange:te}:{}})}),S?t.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:t.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[t.jsx(F,{name:"loader-4",className:"size-4 animate-spin"}),"Opening file at change..."]})}):null]}):t.jsx("div",{className:`${le} typography-ui text-muted-foreground`,children:"Pick a file from the tree."})})};async function dc(e,n,a){if(Sa(e)&&!Ra(e))return{kind:n?"desktop-image":"asset-image"};if(Fa(e))return{kind:"pdf"};if(Tn(e))return{kind:"binary",detectedFromContent:!1};const o=await a(e);if(Zo(o))return{kind:"binary",detectedFromContent:!0};const u=hi(o);return{kind:"text",content:u,draft:u.length>Rt?`${u.slice(0,Rt)}
|
|
2
|
+
|
|
3
|
+
… truncated …`:u,lineEnding:gi(o)}}function fc({isDirty:e,saveDraft:n}){const a=Fe(b=>b.setMainTabGuard),[i,o]=y.useState(!1),u=y.useRef(null),f=y.useRef(!1),m=y.useCallback(b=>f.current?(f.current=!1,!1):e?(u.current=b,o(!0),!0):!1,[e]);y.useEffect(()=>{if(!e){a(null);return}const b=j=>!m({kind:"tab",tab:j});return a(b),()=>{Fe.getState().mainTabGuard===b&&a(null)}},[e,m,a]);const g=y.useCallback(()=>{const b=u.current;return u.current=null,f.current=!0,o(!1),b?.kind==="tab"&&a(null),b},[a]),w=y.useCallback(()=>g(),[g]),N=y.useCallback(async()=>await n()?g():(f.current=!1,null),[n,g]),x=y.useCallback(b=>{b||o(!0)},[]);return{confirmOpen:i,discardAndTakeIntent:w,keepModalOpen:x,requestNavigation:m,saveAndTakeIntent:N}}function mc(e,n){if(e.state.doc.length!==n.length)return!1;if(n.length===0)return!0;const a=Math.min(128,n.length);if(e.state.sliceDoc(0,a)!==n.slice(0,a))return!1;const i=Math.max(0,n.length-a);return e.state.sliceDoc(i,n.length)===n.slice(i)}function pc({root:e,selectedPath:n,loadedPath:a,fileLoading:i,fileError:o,isImage:u,isPdf:f,isUnsupportedBinary:m,canEdit:g,textViewMode:w,setTextViewMode:N,draftContent:x,confirmDiscardOpen:b,selectFilePath:j}){const C=Fe(A=>A.pendingFileNavigation),v=Fe(A=>A.setPendingFileNavigation),L=Fe(A=>A.pendingFileFocusPath),I=Fe(A=>A.setPendingFileFocusPath),l=y.useRef(null),[B,H]=y.useState(0),D=y.useRef(null),$=y.useRef({key:"",attempts:0}),G=y.useCallback(()=>{H(A=>A+1)},[]);y.useEffect(()=>()=>{D.current!==null&&window.cancelAnimationFrame(D.current)},[]),y.useEffect(()=>{if(!C||!e)return;const A=()=>{D.current===null&&(D.current=window.requestAnimationFrame(()=>{D.current=null,G()}))},T=()=>{v(null),$.current={key:"",attempts:0}},k=oe(C.path);if(!k){T();return}const V=`${k}:${C.line}:${C.column??1}`;if($.current.key!==V&&($.current={key:V,attempts:0}),n!==k){b||j(k);return}if(i||a!==k)return;if(o||u||f||m){T();return}if(!g)return;if(w!=="edit"){N("edit");return}const E=l.current;if(!E||!mc(E,x)){A();return}const R=Math.max(1,Math.min(C.line,E.state.doc.lines)),d=E.state.doc.line(R),O=Math.max(1,C.column||1),S=d.from+Math.min(Math.max(0,d.to-d.from),O-1);if(!(E.state.selection.main.head===S)||$.current.attempts===0){$.current.attempts+=1,E.dispatch({selection:{anchor:S},effects:me.scrollIntoView(S,{y:"center"})}),E.focus(),A();return}window.requestAnimationFrame(()=>{const Y=l.current;Y&&(Y.dispatch({selection:{anchor:S},effects:me.scrollIntoView(S,{y:"center"})}),Y.focus())}),T()},[g,b,x,B,o,i,u,f,m,a,G,C,e,n,j,v,N,w]),y.useEffect(()=>{if(!L||!e)return;const A=oe(L);if(!A){I(null);return}n!==A||i||a!==A||(!o&&!u&&!f&&!m&&g&&w==="edit"&&l.current?.focus(),I(null))},[g,o,i,u,f,m,a,L,e,n,I,w]);const _=oe(C?.path??"");return{editorViewRef:l,notifyEditorViewChanged:G,shouldMaskEditor:!!(C&&_&&n===_&&!i&&!o&&!u&&!f&&!m)}}function hc(e){return!(!e.autoSaveEnabled||!e.isDirty||!e.canWrite||e.isSaving||e.fileLoading||e.isNonEditableBinary||!e.selectedFilePath||e.loadedFilePath!==e.selectedFilePath)}function gc(e){return e.selectedFilePath?e.isDirty?!(e.fileLoading||e.loadedFilePath!==e.selectedFilePath||e.isNonEditableBinary||e.draftContent===""&&e.fileContent!==""&&e.loadedFilePath!==e.selectedFilePath):!0:!1}const xc=1500,vc=2e3;function bc({autoSaveEnabled:e,selectedPath:n,loadedPath:a,fileLoading:i,isDirty:o,draftContent:u,fileContent:f,lineEnding:m,isNonEditableBinary:g,writeFile:w,expectedRevision:N,onSaved:x,captureSaveScope:b,currentSaveScope:j,onConflict:C}){const[v,L]=y.useState(!1),[I,l]=y.useState("idle"),[B,H]=y.useState(null),D=y.useRef(null),$=y.useRef(null),G=y.useRef(C);G.current=C;const _=y.useRef(b);_.current=b;const X=y.useRef(j);X.current=j;const A=y.useCallback(R=>R?Aa(R,X.current?.()??null):!0,[]),T=y.useCallback(()=>{D.current&&(clearTimeout(D.current),D.current=null)},[]),k=y.useCallback(()=>{l("saved"),$.current&&clearTimeout($.current),$.current=setTimeout(()=>{$.current=null,l("idle")},vc)},[]),V=y.useCallback(async R=>{if(!n||!w)return pe.error("Saving not supported"),!1;if(!gc({selectedFilePath:n,loadedFilePath:a,fileLoading:i,isDirty:o,draftContent:u,fileContent:f,isNonEditableBinary:g}))return g?console.warn(`[saveDraft] refusing to save binary file "${n}".`):u===""&&f!==""&&a!==n&&console.warn(`[saveDraft] refusing to save empty draft for "${n}" (${f.length} bytes were expected). The file may have been read during a concurrent write (O_TRUNC race). Try again after content finishes loading if the save was intentional.`),!1;if(!o)return!0;L(!0);const d=_.current?.()??null;try{const O=xi(u,m),S=Oa(N,R?.overwrite),P=await w(n,O,S);return P?.success?A(d)?(H(null),x(n,u,P?.revision,d),!0):!1:(pe.error("Failed to write file"),!1)}catch(O){if(xa(O)){if(!A(d))return!1;const S={path:n,currentRevision:O.currentRevision??null,exists:O.exists};return H(S),G.current?.(S),!1}return pe.error(O instanceof Error?O.message:"Save failed"),!1}finally{L(!1)}},[u,N,f,i,o,g,A,m,a,x,n,w]),E=y.useCallback(async R=>{if(T(),v)return!1;const d=await V(R);return d&&k(),d},[T,v,V,k]);return y.useEffect(()=>{e||(l("idle"),T())},[e,T]),y.useEffect(()=>{if(hc({autoSaveEnabled:e,isDirty:o,canWrite:!!(n&&w),isSaving:v,fileLoading:i,selectedFilePath:n,loadedFilePath:a,isNonEditableBinary:g}))return D.current=setTimeout(()=>{D.current=null,V().then(R=>{R&&k()})},xc),T},[e,T,u,i,o,g,v,a,V,n,k,w]),y.useEffect(()=>{l("idle"),L(!1),H(null)},[n]),y.useEffect(()=>()=>{T(),$.current&&clearTimeout($.current)},[T]),{autoSaveStatus:I,cancelPendingAutosave:T,isSaving:v,saveConflict:B,clearSaveConflict:()=>H(null),saveDraft:V,saveNow:E}}function wc(e,n){return typeof e.revision=="string"&&typeof n.revision=="string"&&e.revision!==n.revision?!0:n.mtimeMs!==void 0&&e.mtimeMs!==void 0&&n.mtimeMs!==e.mtimeMs||n.size!==e.size}function yc({selectedPath:e,loadedPath:n,isDirty:a,readStat:i,onExternalChange:o,pollIntervalMs:u=2e3}){const f=y.useRef(null),m=y.useRef(a);m.current=a;const g=y.useCallback(w=>{f.current=w},[]);return y.useEffect(()=>{if(!e||n!==e)return;let w=!1;const N=window.setInterval(()=>{if(document.hidden)return;const x=f.current,b=x&&x.path===e&&typeof x.revision=="string"?x.revision:null;i(e,{knownRevision:b}).then(j=>{if(w||!j)return;const C=f.current;if(!C||C.path!==e){f.current=j;return}!wc(C,j)||m.current||(f.current=j,o())}).catch(()=>{})},u);return()=>{w=!0,window.clearInterval(N)}},[n,o,u,i,e]),{recordStat:g}}const ca="pichamber:files:md-viewer-mode",la="pichamber:files:html-viewer-mode",ua="pichamber:files:json-viewer-mode",kc=1500,jc=1500;function Fn(e,n,a){try{const i=localStorage.getItem(e);if(i&&n.includes(i))return i}catch{}return a}function En(e,n){try{localStorage.setItem(e,n)}catch{}}function Cc({root:e,selectedPath:n,fileContent:a,draftContent:i,setDraftContent:o,autoSaveEnabled:u,writeFile:f,expectedRevision:m,captureSaveScope:g,currentSaveScope:w,onSaved:N,onConflict:x}){const[b,j]=y.useState("edit"),[C,v]=y.useState("edit"),[L,I]=y.useState("text"),[l,B]=y.useState("edit"),[H,D]=y.useState("edit"),[$,G]=y.useState(0),[_,X]=y.useState(!1),A=y.useRef({}),T=y.useRef({}),k=y.useRef({}),V=y.useRef({}),E=y.useRef(""),R=y.useRef(""),d=y.useRef(null),O=y.useRef(null),S=y.useRef(null),P=y.useRef(m);P.current=m;const Y=y.useRef(g);Y.current=g;const ee=y.useRef(w);ee.current=w;const re=y.useRef(N);re.current=N;const te=y.useRef(x);te.current=x;const K=y.useCallback(()=>{d.current&&(clearTimeout(d.current),d.current=null),S.current!==null&&(cancelAnimationFrame(S.current),S.current=null)},[]),Q=y.useCallback(W=>{E.current=W,R.current=W},[]),Qe=y.useCallback(()=>Q(""),[Q]);y.useEffect(()=>{n&&(j(A.current[n]??"edit"),v(T.current[n]??Fn(ca,["preview","edit"],"edit")),B(k.current[n]??Fn(la,["preview","edit"],"edit")),D(V.current[n]??"edit"),I(Fn(ua,["tree","text"],"text")))},[n]);const Oe=y.useCallback(W=>{n&&(A.current[n]=W),j(W)},[n]),le=y.useCallback(W=>{n&&(T.current[n]=W),v(W),En(ca,W)},[n]),Pe=y.useCallback(W=>{n&&(k.current[n]=W),B(W),En(la,W)},[n]),Le=y.useCallback(W=>{I(W),En(ua,W)},[]),ae=y.useCallback(W=>{if(n&&(V.current[n]=W),K(),W==="edit"){o(E.current||a),D(W);return}E.current=i;const U=n;D("edit"),S.current=requestAnimationFrame(()=>{S.current=requestAnimationFrame(()=>{S.current=null,!(e&&U&&Re.getState().byRoot[e]?.selectedPath!==U)&&(G(se=>se+1),D("preview"))})})},[K,i,a,e,n,o]),ue=y.useCallback(W=>W?Aa(W,ee.current?.()??null):!0,[]),ye=y.useCallback(async(W,U,se)=>{if(!f||U===R.current)return!1;const ge=Y.current?.()??null;if(ge&&ge.path!==W)return!1;try{const de=await f(W,U,Oa(P.current,se?.overwrite));return de?.success?ue(ge)?(Q(U),o(U),re.current?.(W,U,de?.revision,ge),!0):!1:(pe.error("Failed to write file"),!1)}catch(de){return xa(de)?(ue(ge)&&te.current?.({path:W,currentRevision:de.currentRevision??null,exists:de.exists,xml:U}),!1):(pe.error(de instanceof Error?de.message:"Save failed"),!1)}},[ue,Q,o,f]),he=y.useCallback(()=>{X(!0),O.current&&clearTimeout(O.current),O.current=setTimeout(()=>X(!1),jc)},[]),Ie=y.useCallback(async(W,U,se)=>{d.current&&(clearTimeout(d.current),d.current=null);const ge=await ye(W,U,se);return ge&&he(),ge},[ye,he]),vt=y.useCallback(W=>{E.current=W,!(!u||!n||H!=="preview"||!f)&&(d.current&&clearTimeout(d.current),d.current=setTimeout(()=>{d.current=null,ye(n,W).then(U=>{U&&he()})},kc))},[u,H,ye,n,he,f]);y.useEffect(()=>K,[K,H,n]),y.useEffect(()=>()=>{O.current&&clearTimeout(O.current)},[]);const Ee=en(n??"")&&(E.current||i)||a;return{clearDiagramContent:Qe,diagramEditorXml:Ee,diagramSaved:_,drawioRemountNonce:$,drawioViewMode:H,handleDiagramChange:vt,htmlViewMode:l,jsonViewMode:L,mdViewMode:C,recordDiagramContent:Q,saveDiagramNow:Ie,saveDiagramXml:ye,saveDrawioViewMode:ae,saveHtmlViewMode:Pe,saveJsonViewMode:Le,saveMdViewMode:le,saveTextViewMode:Oe,setTextViewMode:j,textViewMode:b}}function Nc(e,n){return e==="mobile"?!0:n==="full"}function Sc(e,n){if(e===n)return!0;if(e.length!==n.length)return!1;for(let a=0;a<e.length;a+=1){const i=e[a],o=n[a];if(i.name!==o.name||i.path!==o.path||i.type!==o.type||i.extension!==o.extension||i.relativePath!==o.relativePath||i.size!==o.size)return!1}return!0}function Rc({files:e,root:n,activeDirectory:a,expandedPaths:i,chrome:o,showGitignored:u,removeExpandedPathsByPrefix:f,enabled:m=!0,visible:g=!0}){const[w,N]=s.useState({}),[x,b]=s.useState({}),j=s.useRef(new Set),C=s.useRef(new Set),v=s.useRef(new Map),L=s.useRef(new Map),I=s.useRef(0),l=s.useRef(!1),[B,H]=s.useState(()=>Vo());s.useEffect(()=>Wo(R=>{H(R.runtimeKey)}),[]),s.useEffect(()=>(l.current=!1,()=>{l.current=!0,L.current=new Map,C.current=new Set,v.current=new Map}),[]);const D=s.useCallback((R,d)=>{const O=[];for(const S of d){if(!S?.name||o==="desktop"&&!u&&vi(S.name))continue;const P=oe(S.path||""),Y=P?bi(P)?P:oe(`${R}/${P}`):oe(`${R}/${S.name}`),ee=S.isDirectory?"directory":"file";O.push({name:S.name,path:Y,type:ee,extension:ee==="file"&&S.name.includes(".")?S.name.split(".").pop()?.toLowerCase():void 0,size:S.size})}return wi(O)},[o,u]),$=`${B}|${n}|g${u?"1":"0"}|${o}`,G=s.useRef($);G.current=$;const _=s.useCallback(async R=>{if(!m)return;const d=oe(R.trim());if(!d||j.current.has(d))return;const O=v.current.get(d);if(O){await O;return}const S=G.current,P=I.current+1;I.current=P,L.current=new Map(L.current).set(d,P),C.current=new Set(C.current).add(d);const Y=()=>!l.current&&G.current===S&&L.current.get(d)===P,ee=(async()=>{try{const re=e.listDirectory?(await e.listDirectory(d)).entries.map(K=>({name:K.name,path:K.path,isDirectory:K.isDirectory,size:K.size})):(await _o(d)).map(K=>({name:K.name,path:K.path,isDirectory:K.isDirectory}));if(!Y())return;j.current=new Set(j.current).add(d),b(K=>{if(!K[d])return K;const Q={...K};return delete Q[d],Q});const te=D(d,re);N(K=>{const Q=K[d];return Q&&Sc(Q,te)?K:{...K,[d]:te}})}catch(re){if(!Y())return;const te=re instanceof Error?re.message:String(re??"");te==="Directory not found"&&n&&d!==n?(f(n,d),b(K=>{if(!K[d])return K;const Q={...K};return delete Q[d],Q})):(console.error("Failed to load files directory:",re),b(K=>({...K,[d]:te})))}finally{L.current.get(d)===P&&(L.current=new Map(L.current),L.current.delete(d))}})();v.current.set(d,ee);try{await ee}finally{v.current.get(d)===ee&&(v.current.delete(d),C.current=new Set(C.current),C.current.delete(d))}},[m,e,D,f,n]),X=s.useCallback(()=>{j.current=new Set,C.current=new Set,v.current=new Map,L.current=new Map,b({}),N(R=>Object.keys(R).length===0?R:{})},[]),A=s.useCallback(async()=>{!m||!n||(X(),await _(n))},[m,_,X,n]),T=s.useCallback(async R=>{if(!m)return;if(!R){await A();return}const d=oe(R);j.current=new Set(j.current),j.current.delete(d),C.current=new Set(C.current),C.current.delete(d),v.current.delete(d),L.current=new Map(L.current),L.current.delete(d),await _(d)},[m,_,A]),k=s.useRef("");s.useEffect(()=>{k.current!==$&&(k.current=$,X())},[X,$]),s.useEffect(()=>{!m||!g||!n||j.current.has(oe(n))||_(n)},[m,_,n,$,g]),s.useEffect(()=>{!m||!g||!a||_(a)},[a,m,_,g]),s.useEffect(()=>{if(!m||!g||!e.listDirectory)return;const R=P=>{const Y=oe(P);return v.current.has(Y)||C.current.has(Y)},d=()=>{if(!(typeof document<"u"&&document.hidden))for(const P of i)R(P)||T(P)},O=()=>{typeof document<"u"&&document.hidden||d()};typeof document<"u"&&document.addEventListener("visibilitychange",O);const S=i.length>0?window.setInterval(d,8e3):null;return()=>{typeof document<"u"&&document.removeEventListener("visibilitychange",O),S!==null&&window.clearInterval(S)}},[m,i,e.listDirectory,T,g]);const V=s.useRef(m&&g);s.useEffect(()=>{const R=m&&g,d=V.current;if(V.current=R,!(!R||d)){if(!e.listDirectory){n&&!j.current.has(oe(n))&&_(n);return}if(i.length===0){n&&!j.current.has(oe(n))&&_(n);return}for(const O of i){const S=oe(O);v.current.has(S)||C.current.has(S)||T(O)}}},[m,i,e.listDirectory,_,T,n,g]);const E=s.useCallback(R=>j.current.has(oe(R)),[]);return{childrenByDir:w,loadErrorsByDir:x,isLoaded:E,loadDirectory:_,refreshDirectory:T,refreshRoot:A}}const Fc=({showEditorTabsRow:e,isMobile:n,showMobilePageContent:a,onBackMobile:i,selectedFile:o,openFiles:u,root:f,alwaysShowActions:m,editorTabsOverflow:g,editorTabsScrollRef:w,onSelectFile:N,onCloseFile:x})=>e?t.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[n&&a&&t.jsx("button",{type:"button",onClick:i,"aria-label":"Back",className:"inline-flex size-7 flex-shrink-0 items-center justify-center mr-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",children:t.jsx(F,{name:"arrow-left-s",className:"size-5"})}),n?o?t.jsxs(Ln,{children:[t.jsx(In,{asChild:!0,children:t.jsxs("button",{type:"button",className:"inline-flex min-w-0 max-w-full items-center gap-1 text-left typography-ui-label font-medium","aria-label":"Open files",children:[t.jsx(xt,{filePath:o.path,extension:o.extension,className:"size-3.5 flex-shrink-0"}),t.jsx(Ur,{name:o.name}),t.jsx(F,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),t.jsx(Bn,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:u.map(b=>{const j=o?.path===b.path;return t.jsxs(Qt,{onSelect:C=>{if(C.target.closest("[data-close-open-file]")){C.preventDefault();return}j||N(b)},className:J("flex min-w-0 items-center justify-between gap-2 overflow-hidden",j&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[t.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[t.jsx(xt,{filePath:b.path,extension:b.extension,className:"size-3.5 flex-shrink-0"}),t.jsx(Ur,{name:b.name})]}),t.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:C=>{C.preventDefault(),C.stopPropagation()},onClick:C=>{C.preventDefault(),C.stopPropagation(),x(b.path)},className:"inline-flex size-6 shrink-0 items-center justify-center rounded-md text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]","aria-label":`Close ${b.name}`,children:t.jsx(F,{name:"close",className:"size-3.5"})})]},b.path)})})]}):t.jsx("div",{className:"typography-ui-label font-medium truncate",children:"Select a file"}):u.length>0?t.jsxs("div",{className:"relative min-w-0 flex-1",children:[g.left&&t.jsx("div",{className:"pointer-events-none absolute left-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-r from-background to-transparent"}),g.right&&t.jsx("div",{className:"pointer-events-none absolute right-0 top-0 bottom-0 w-6 z-10 bg-gradient-to-l from-background to-transparent"}),t.jsx("div",{ref:w,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},"data-no-drawer-swipe":"true",children:u.map(b=>{const j=o?.path===b.path;return t.jsxs("div",{title:St(f,b.path),className:J("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",j?"bg-[var(--interactive-selection)] border-[var(--primary-muted)] text-[var(--interactive-selection-foreground)]":"bg-transparent border-[var(--interactive-border)] text-[var(--surface-muted-foreground)] hover:bg-[var(--interactive-hover)] hover:text-[var(--surface-foreground)]"),children:[t.jsx(xt,{filePath:b.path,extension:b.extension,className:"size-3.5 flex-shrink-0"}),t.jsx("button",{type:"button",onClick:()=>{j||N(b)},className:"max-w-[12rem] truncate text-left",children:b.name}),t.jsx("button",{type:"button",onClick:C=>{C.stopPropagation(),x(b.path)},className:J("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!j&&!m&&"opacity-0 group-hover:opacity-100"),"aria-label":`Close ${b.name}`,children:t.jsx(F,{name:"close",className:"size-3.5"})})]},b.path)})})]}):t.jsx("div",{className:"typography-ui-label font-medium truncate",children:"Select a file"})]}):null,Ec=(e,n)=>{if(!n)return null;const a=Number.parseInt(e.trim(),10);return!Number.isFinite(a)||a<1?null:Math.min(a,n.state.doc.lines)},da=(e,n)=>{const a=e.state.doc.lineAt(n.main.head);return{lineNumber:a.number,character:n.main.head-a.from+1,selection:n}},fa=(e,n,a)=>{const i=e.state.doc.line(n),o=Math.max(1,Math.min(a,i.length+1)),u=i.from+o-1;e.dispatch({selection:Oo.cursor(u),effects:me.scrollIntoView(u,{y:"center"})})};function zc({open:e,onOpenChange:n,view:a,variant:i="overlay"}){const[o,u]=s.useState(""),f=s.useRef(null),m=s.useRef(!1),g=s.useRef(null),w=s.useRef(null),N=s.useMemo(()=>Ec(o,a),[o,a]);s.useEffect(()=>{!e||!a||(m.current=!1,f.current=da(a,a.state.selection),u(""))},[e,a]),s.useEffect(()=>{e&&window.requestAnimationFrame(()=>{w.current?.focus(),w.current?.select()})},[e]),s.useEffect(()=>{if(!(!e||!a||!f.current)){if(N===null){const{selection:v}=f.current;a.dispatch({selection:v,effects:me.scrollIntoView(v.main.from,{y:"center"})});return}fa(a,N,f.current.character)}},[N,e,a]);const x=s.useCallback(()=>{if(!a||m.current||!f.current)return;const{selection:v}=f.current;a.dispatch({selection:v,effects:me.scrollIntoView(v.main.from,{y:"center"})})},[a]),b=s.useCallback(v=>{v||x(),n(v)},[n,x]),j=s.useCallback(()=>{!a||N===null||!f.current||(m.current=!0,fa(a,N,f.current.character),n(!1),a.focus())},[N,n,a]);s.useEffect(()=>{if(!e)return;const v=I=>{const l=g.current,B=I.target;!l||!(B instanceof Node)||l.contains(B)||b(!1)},L=I=>{I.key==="Escape"&&(I.preventDefault(),b(!1))};return document.addEventListener("pointerdown",v,!0),document.addEventListener("keydown",L,!0),()=>{document.removeEventListener("pointerdown",v,!0),document.removeEventListener("keydown",L,!0)}},[b,e,i]);const C=s.useMemo(()=>a?N===null?`Current Line: ${(f.current??da(a,a.state.selection)).lineNumber}. Type a line number between 1 and ${a.state.doc.lines} to navigate to.`:`Go to line ${N}`:"Editor unavailable.",[N,a]);return i==="inline"?e?t.jsxs("div",{ref:g,className:"ml-1 flex h-6 items-center gap-1",children:[t.jsx(Et,{ref:w,type:"number",min:1,step:1,inputMode:"numeric",value:o,onChange:v=>u(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),j())},placeholder:"Line",className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),t.jsx(q,{variant:"outline",size:"xs",onClick:j,disabled:!a||N===null,className:"h-6 px-2",children:"Go"})]}):null:t.jsx("div",{ref:g,className:J("absolute left-3 top-3 z-40 w-[min(32rem,calc(100%-1.5rem))] rounded-xl border border-[var(--interactive-border)] bg-[color:color-mix(in_srgb,var(--surface-elevated)_94%,transparent)] p-2.5 shadow-lg backdrop-blur-sm transition-all",e?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:t.jsxs("div",{className:"min-w-0",children:[t.jsx(Et,{ref:w,type:"number",min:1,step:1,inputMode:"numeric",value:o,onChange:v=>u(v.target.value),onKeyDown:v=>{v.key==="Enter"&&(v.preventDefault(),j())},placeholder:"Line number",className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),t.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:C})]})})}const zn=({currentMode:e,onToggle:n})=>{const a=e==="preview",i=a?"Switch to edit mode":"Switch to preview mode",o=a?"Edit":"Preview";return t.jsxs(Xe,{children:[t.jsx(Ye,{asChild:!0,children:t.jsx(q,{variant:"ghost",size:"sm",onClick:n,"aria-label":i,className:"h-5 w-5 p-0",children:a?t.jsx(F,{name:"eye",className:"size-4","aria-hidden":"true"}):t.jsx(F,{name:"eye-off",className:"size-4","aria-hidden":"true"})})}),t.jsx(Ze,{sideOffset:8,children:o})]})},Mc=({selectedFile:e,displaySelectedPath:n,layout:a="floating",exitFullscreenOnly:i=!1,canEdit:o,isEditingFile:u,isSaving:f,autoSaveEnabled:m,autoSaveStatus:g,isDirty:w,onSaveDraft:N,onToggleAutoSave:x,openInApps:b,openInCacheStale:j,onOpenInApp:C,onRefreshOpenInApps:v,onToolbarDropdownOpenChange:L,isSelectedImage:I,isSelectedPdf:l,isUnsupportedBinary:B,wrapLines:H,onToggleWrapLines:D,textViewMode:$,onToggleSearch:G,isGoToLineOpen:_,onOpenGoToLineChange:X,editorView:A,canUseShikiFileView:T,isJson:k,isHtml:V,onToggleTextViewMode:E,isMarkdown:R,mdViewMode:d,onToggleMdViewMode:O,isDrawio:S,drawioViewMode:P,onToggleDrawioViewMode:Y,diagramSaved:ee,onSaveDiagram:re,jsonViewMode:te,onToggleJsonViewMode:K,canCopy:Q,copiedContent:Qe,onCopyContent:Oe,canCopyPath:le,copiedPath:Pe,onCopyPath:Le,onDownloadFile:ae,isMobile:ue,mode:ye,isFullscreen:he,onToggleFullscreen:Ie,onExitFullscreen:vt})=>{if(!e)return null;const W=a==="docked"?"pointer-events-auto flex flex-wrap items-center gap-1":"pointer-events-auto flex items-center gap-1 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-1 shadow-sm",U=(se,ge)=>t.jsxs(Xe,{children:[t.jsx(Ye,{asChild:!0,children:t.jsx("span",{className:"inline-flex",children:ge})}),t.jsx(Ze,{side:"bottom",sideOffset:6,children:se})]});return t.jsxs("div",{className:W,children:[o&&u&&t.jsxs(t.Fragment,{children:[f?t.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[t.jsx(F,{name:"loader-4",className:"size-3.5 animate-spin"}),"Saving..."]}):m&&g==="saved"&&!w?t.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[t.jsx(F,{name:"check",className:"size-3.5"}),"Saved"]}):w?U(m?`Save now (${Ct()}+S) - auto-saves after 1.5s`:`Save now (${Ct()}+S)`,t.jsx(q,{variant:"ghost",size:"sm",onClick:()=>{N()},className:"h-6 gap-1 px-1 text-muted-foreground opacity-80 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:m?`Save now (${Ct()}+S) - auto-saves after 1.5s`:`Save now (${Ct()}+S)`,"aria-label":`Save (${Ct()}+S)`,children:t.jsx(F,{name:"save-3",className:"size-4"})})):null,U(m?"Auto-save on":"Manual save",t.jsx(q,{variant:"ghost",size:"sm",onClick:x,className:J("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",m?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:m?"Auto-save on":"Manual save","aria-label":m?"Auto-save on":"Manual save",children:m?t.jsx(F,{name:"file-check-fill",className:"size-4"}):t.jsx(F,{name:"file-check",className:"size-4"})}))]}),t.jsxs(Ln,{onOpenChange:L,children:[t.jsxs(Xe,{children:[t.jsx(Ye,{asChild:!0,children:t.jsx("span",{className:"inline-flex",children:t.jsx(In,{asChild:!0,children:t.jsx(q,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Open in desktop app","aria-label":"Open in desktop app",children:t.jsx(F,{name:"file-transfer",className:"size-4"})})})})}),t.jsx(Ze,{side:"bottom",sideOffset:6,children:"Open in desktop app"})]}),t.jsxs(Bn,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[b.map(se=>t.jsxs(Qt,{className:"flex items-center gap-2",onClick:()=>{C(se)},children:[t.jsx(Yi,{label:se.label,iconDataUrl:se.iconDataUrl}),t.jsx("span",{className:"typography-ui-label text-foreground",children:se.label})]},se.id)),j?t.jsxs(Qt,{className:"flex items-center gap-2",onClick:()=>{v()},children:[t.jsx(F,{name:"refresh",className:"size-4"}),t.jsx("span",{className:"typography-ui-label text-foreground",children:"Refresh Apps"})]}):null]})]}),!I&&!l&&!B&&t.jsxs(t.Fragment,{children:[U(H?"Disable line wrap":"Enable line wrap",t.jsx(q,{variant:"ghost",size:"sm",onClick:D,className:J("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",H?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:H?"Disable line wrap":"Enable line wrap",children:t.jsx(F,{name:"text-wrap",className:"size-4"})})),$==="edit"&&t.jsxs(t.Fragment,{children:[U("Find in file",t.jsx(q,{variant:"ghost",size:"sm",onClick:se=>{G(),se.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Find in file",children:t.jsx(F,{name:"search",className:"size-4"})})),U("Go to line",t.jsx(q,{variant:"ghost",size:"sm",onClick:se=>{X(!_),se.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Go to line",children:t.jsx(F,{name:"menu-fold-2",className:"size-4"})})),t.jsx(zc,{open:_,onOpenChange:X,view:A,variant:"inline"})]})]}),T&&o&&!k&&!V&&t.jsx(zn,{currentMode:$==="view"?"preview":"edit",onToggle:E}),R&&U(d==="preview"?"Switch to edit mode":"Switch to preview mode",t.jsx(q,{variant:"ghost",size:"sm",onClick:O,className:J("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",d==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)] focus-visible:bg-[var(--interactive-selection)] active:bg-[var(--interactive-selection)]":"text-muted-foreground opacity-65 hover:opacity-100"),title:d==="preview"?"Switch to edit mode":"Switch to preview mode","aria-label":d==="preview"?"Switch to edit mode":"Switch to preview mode",children:t.jsx(F,{name:d==="preview"?"eye":"eye-off",className:"size-4"})})),$n(e?.path??"")&&t.jsx(zn,{currentMode:V?"preview":"edit",onToggle:E}),S&&t.jsxs(t.Fragment,{children:[t.jsx(zn,{currentMode:P,onToggle:Y}),P==="preview"&&t.jsx(q,{variant:"ghost",size:"sm",onClick:()=>{re()},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Save diagram",children:ee?t.jsx(F,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):t.jsx(F,{name:"save-3",className:"size-4"})})]}),k&&U(te==="tree"?"Switch to Text View":"Switch to Tree View",t.jsx(q,{variant:"ghost",size:"sm",onClick:K,className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:te==="tree"?"Switch to Text View":"Switch to Tree View",children:te==="tree"?t.jsx(F,{name:"code-sslash",className:"size-4"}):t.jsx(F,{name:"node-tree",className:"size-4"})})),Q&&U("Copy file contents",t.jsx(q,{variant:"ghost",size:"sm",onClick:()=>{Oe()},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Copy file contents","aria-label":"Copy file contents",children:Qe?t.jsx(F,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):t.jsx(F,{name:"clipboard",className:"size-4"})})),le&&U(`Copy file path (${n})`,t.jsx(q,{variant:"ghost",size:"sm",onClick:()=>{Le()},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:`Copy file path (${n})`,"aria-label":`Copy file path (${n})`,children:Pe?t.jsx(F,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):t.jsx(F,{name:"file-copy-2",className:"size-4"})})),ae&&U("Save file",t.jsx(q,{variant:"ghost",size:"sm",onClick:ae,className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Save file","aria-label":"Save file",children:t.jsx(F,{name:"download",className:"size-4"})})),i?U("Exit fullscreen",t.jsx(q,{variant:"ghost",size:"sm",onClick:vt,className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:"Exit fullscreen","aria-label":"Exit fullscreen",children:t.jsx(F,{name:"fullscreen-exit",className:"size-4"})})):!ue&&ye==="full"&&U(he?"Exit fullscreen":"Fullscreen",t.jsx(q,{variant:"ghost",size:"sm",onClick:Ie,className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:he?"Exit fullscreen":"Fullscreen","aria-label":he?"Exit fullscreen":"Fullscreen",children:he?t.jsx(F,{name:"fullscreen-exit",className:"size-4"}):t.jsx(F,{name:"fullscreen",className:"size-4"})}))]})},Tc=({open:e,onOpenChange:n,isSaving:a,onSaveAndContinue:i,onDiscardAndContinue:o})=>t.jsx(va,{open:e,onOpenChange:n,children:t.jsxs(ba,{showCloseButton:!1,className:"max-w-md",children:[t.jsxs(wa,{children:[t.jsx(ya,{children:"Unsaved changes"}),t.jsx(ka,{children:"Save your edits before continuing?"})]}),t.jsxs(ja,{children:[t.jsx(q,{variant:"outline",onClick:i,disabled:a,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:"Save changes"}),t.jsx(q,{variant:"destructive",onClick:o,children:"Discard"})]})]})}),ma=(e,n)=>e.startsWith(`${n}/`)?e.slice(n.length+1):e,Dc=e=>e.index==="A"||e.working_dir==="?"?"git-added":e.index==="D"?"git-deleted":e.index==="M"||e.working_dir==="M"?"git-modified":null,Ac=({root:e,openPaths:n,gitFiles:a})=>{const i=new Set(n),o=new Map,u=new Map,f={modified:0,added:0};for(const w of a??[]){o.has(w.path)||o.set(w.path,w);const N=+(w.index==="M"||w.working_dir==="M"),x=+(w.index==="A"||w.working_dir==="?");if(N===0&&x===0)continue;f.modified+=N,f.added+=x;const b=w.path.split("/");for(let j=1;j<b.length;j+=1){const C=b.slice(0,j).join("/");if(!C)continue;let v=u.get(C);v||(v={modified:0,added:0},u.set(C,v)),v.modified+=N,v.added+=x}}return{getFileStatus:w=>{if(i.has(w))return"open";if(o.size===0)return null;const N=ma(w,e),x=o.get(N);return x?Dc(x):null},getFolderBadge:w=>{if(!a)return null;const N=ma(w,e);if(!N)return f.modified+f.added>0?{...f}:null;const x=u.get(N);return x?{...x}:null}}},Oc=e=>new Set(e),Pc=({root:e,isMobile:n,searchQuery:a,onSearchQueryChange:i,searchInputRef:o,searching:u,searchResults:f,selectedFile:m,onSelectFile:g,onOpenDialog:w,currentDirectory:N,refreshRoot:x,childrenByDir:b,loadErrorsByDir:j,expandedPaths:C,isBrowserClient:v,alwaysShowActions:L,getFileStatus:I,getFolderBadge:l,fileRowPermissions:B,downloadFile:H,contextMenuPath:D,setContextMenuPath:$,rightClickMenuPath:G,setRightClickMenuPath:_,toggleDirectory:X,handleRevealPath:A,refreshDirectory:T})=>{const k=!!(e&&b[e]),V=e?j[e]:null,E=s.useMemo(()=>Oc(C),[C]);function R(d,O){const S=b[d]??[];return S.map((P,Y)=>{const ee=P.type==="directory",re=ee&&E.has(P.path),te=m?.path===P.path,K=Y===S.length-1;return t.jsxs("li",{className:"relative",children:[O>0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),K&&t.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),t.jsx(Qi,{node:P,root:e,isExpanded:re,isActive:te,isMobile:n,isBrowserClient:v,alwaysShowActions:L,status:ee?void 0:I(P.path),badge:ee?l(P.path):void 0,permissions:B,downloadFile:H,contextMenuPath:D,setContextMenuPath:$,rightClickMenuPath:G,setRightClickMenuPath:_,onSelect:g,onToggle:X,onRevealPath:A,onOpenDialog:w}),ee&&re&&t.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[j[P.path]?t.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[t.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:j[P.path],children:j[P.path]}),t.jsxs(q,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{T(P.path)},children:[t.jsx(F,{name:"refresh",className:"size-3.5"}),"Refresh"]})]}):null,R(P.path,O+1)]})]},P.path)})}return t.jsxs("section",{className:J("flex min-h-0 flex-col overflow-hidden",n?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[t.jsx("div",{className:J("flex flex-col gap-2 py-2",n?"px-3":"px-2"),children:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("div",{className:"relative flex-1 min-w-0",children:[t.jsx(F,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),t.jsx(Et,{ref:o,value:a,onChange:d=>i(d.target.value),placeholder:"Search files...",className:"h-8 pl-8 pr-8 typography-meta"}),a.trim().length>0&&t.jsx("button",{type:"button","aria-label":"Clear search",className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{i(""),o.current?.focus()},children:t.jsx(F,{name:"close",className:"size-4"})})]}),t.jsxs(Xe,{children:[t.jsx(Ye,{asChild:!0,children:t.jsx("span",{className:"inline-flex flex-shrink-0",children:t.jsx(q,{variant:"ghost",size:"sm",onClick:()=>w("createFile",{path:N,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:"New File","aria-label":"New File",children:t.jsx(F,{name:"file-add",className:"size-4"})})})}),t.jsx(Ze,{side:"bottom",sideOffset:6,children:"New File"})]}),t.jsxs(Xe,{children:[t.jsx(Ye,{asChild:!0,children:t.jsx("span",{className:"inline-flex flex-shrink-0",children:t.jsx(q,{variant:"ghost",size:"sm",onClick:()=>w("createFolder",{path:N,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:"New Folder","aria-label":"New Folder",children:t.jsx(F,{name:"folder-add",className:"size-4"})})})}),t.jsx(Ze,{side:"bottom",sideOffset:6,children:"New Folder"})]}),t.jsxs(Xe,{children:[t.jsx(Ye,{asChild:!0,children:t.jsx("span",{className:"inline-flex flex-shrink-0",children:t.jsx(q,{variant:"ghost",size:"sm",onClick:()=>{x()},className:"size-8 p-0 flex-shrink-0",title:"Refresh","aria-label":"Refresh",children:t.jsx(F,{name:"refresh",className:"size-4"})})})}),t.jsx(Ze,{side:"bottom",sideOffset:6,children:"Refresh"})]})]})}),t.jsx(Ca,{outerClassName:"flex-1 min-h-0",className:J("py-2",n?"px-3":"px-2"),children:t.jsx("ul",{className:"flex flex-col",children:u?t.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[t.jsx(F,{name:"loader-4",className:"size-4 animate-spin"}),"Searching..."]}):f.length>0?f.map(d=>{const O=m?.path===d.path;return t.jsx("li",{children:t.jsxs("button",{type:"button",onClick:()=>{g(d)},className:J("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",O?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[t.jsx(Ka,{filePath:d.path,extension:d.extension}),t.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:d.path,children:d.relativePath??d.path})]})},d.path)}):V?t.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[t.jsx("span",{className:"text-[var(--status-error)]",children:V}),t.jsxs(q,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{x()},children:[t.jsx(F,{name:"refresh",className:"size-3.5"}),"Refresh"]})]}):k?R(e,0):t.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:"Loading..."})})})]})},Xl=({mode:e="full",chrome:n="desktop",onClose:a,isVisible:i=!0})=>{const{files:o,runtime:u}=Qo(),f=n==="mobile",{currentTheme:m,availableThemes:g,lightThemeId:w,darkThemeId:N}=ei(),{isMobile:x,isTablet:b,screenWidth:j}=ti(),C=Ko(u.platform),v=x||b,L=qo(),I=ni()??"",l=oe(I.trim()),B=Nc(n,e),H=e!=="editor-only",D=e==="editor-only"&&!x,$=ri(I),[G,_]=s.useState(""),X=s.useRef(null),[A,T]=s.useState(!1),[k,V]=s.useState(l),[E,R]=s.useState(!1),[d,O]=s.useState(!0),[S,P]=s.useState(!1),[Y,ee]=s.useState(!1),[re,te]=s.useState(!1),K=s.useRef(null);s.useEffect(()=>{f&&(V(l),_(""),T(!1))},[f,l]);const Q=s.useRef(0),Qe=s.useCallback(r=>{Q.current=Math.max(0,Q.current+(r?1:-1))},[]),Oe=s.useCallback(r=>r instanceof Element?r.closest('[data-slot="dropdown-menu-content"], [data-slot="dropdown-menu-item"]')!==null:!1,[]);s.useEffect(()=>{if(!re)return;const r=h=>{Q.current>0||Oe(h.target)||K.current&&!K.current.contains(h.target)&&te(!1)};return document.addEventListener("mousedown",r),()=>document.removeEventListener("mousedown",r)},[Oe,re]);const le=s.useMemo(()=>g.find(r=>r.metadata.id===w)??zr(!1),[g,w]),Pe=s.useMemo(()=>g.find(r=>r.metadata.id===N)??zr(!0),[g,N]);s.useEffect(()=>{Lr(le),Lr(Pe)},[le,Pe]);const Le=s.useMemo(()=>[],[]),ae=Re(r=>l?r.byRoot[l]?.openPaths??Le:Le),ue=Re(r=>l?r.byRoot[l]?.selectedPath??null:null),ye=Re(r=>l?r.byRoot[l]?.expandedPaths??Le:Le),he=Re(r=>r.removeOpenPath),Ie=Re(r=>r.removeOpenPathsByPrefix),vt=Re(r=>r.removeExpandedPathsByPrefix),Ee=Re(r=>r.setSelectedPath),W=Re(r=>r.toggleExpandedPath),U=Re(r=>r.expandPaths),{childrenByDir:se,loadErrorsByDir:ge,isLoaded:de,loadDirectory:ot,refreshDirectory:zt,refreshRoot:qa}=Rc({files:o,root:l,activeDirectory:f?k:void 0,expandedPaths:ye,chrome:n,showGitignored:L,removeExpandedPathsByPrefix:vt,enabled:B,visible:i}),qe=s.useCallback(r=>{const h=oe(r),z=h.split("/"),M=z[z.length-1]||h,ne=M.includes(".")?M.split(".").pop()?.toLowerCase():void 0;return{name:M,path:h,type:"file",extension:ne}},[]),Mt=s.useMemo(()=>ae.map(qe),[ae,qe]),rn=s.useMemo(()=>{if(ue){const r=Yt(ue);if(ae.some(h=>Yt(h)===r))return ue}return ae[0]??null},[ae,ue]),p=s.useMemo(()=>rn?qe(rn):null,[rn,qe]),Ve=p?.path??"";s.useEffect(()=>{if(!l||!ue)return;const r=Yt(ue);ae.some(z=>Yt(z)===r)||Ee(l,ae[0]??null)},[ae,l,ue,Ee]);const Tt=!!(l&&Ve&&!Cn(Ve,l)),Vn=Tt?Ar(Ve):void 0,ce=s.useMemo(()=>({allowOutsideWorkspace:e==="editor-only"&&Tt,outsideFileGrant:Vn,directory:l||void 0}),[e,Tt,Vn,l]),an=s.useRef(null),[Ha,Ga]=s.useState({left:!1,right:!1}),Wn=s.useCallback(()=>{const r=an.current;r&&Ga({left:r.scrollLeft>2,right:r.scrollLeft+r.clientWidth<r.scrollWidth-2})},[]),_n=s.useRef(Wn);_n.current=Wn,s.useEffect(()=>{const r=an.current;if(!r)return;const h=()=>_n.current();h(),r.addEventListener("scroll",h,{passive:!0});const z=new ResizeObserver(h);return z.observe(r),()=>{r.removeEventListener("scroll",h),z.disconnect()}},[Mt.length]);const[ke,Be]=s.useState(""),[sn,it]=s.useState(!1),[Kn,xe]=s.useState(null),[Ua,He]=s.useState(""),ve=s.useRef(""),[et,je]=s.useState(null),[ct,Ce]=s.useState(void 0),[qn,Ne]=s.useState(null),be=Re(r=>r.activeRuntimeKey),[fe,$e]=s.useState(null),[on,Hn]=s.useState(!1),[Ja,ze]=s.useState(!1),[lt,Se]=s.useState(""),[Xa,Ya]=s.useState(`
|
|
4
|
+
`),Gn=s.useRef(null),Me=s.useRef(0),ut=s.useRef(null),[Un,cn]=s.useState(!1),Dt=Fe(r=>r.autoSaveEnabled),Za=Fe(r=>r.setAutoSaveEnabled),Qa=s.useRef(null),[es,ts]=s.useState(null),[ns,rs]=s.useState(null),{value:as,show:ss}=Or(!1,1200),{value:os,show:is}=Or(!1,1200),[cs,ls]=s.useState(!1),bt=s.useCallback(()=>{l&&Ee(l,null),Be(""),xe(null),He(""),je(null),Ce(void 0),Ne(null),$e(null),ze(!1),x&&T(!1)},[x,l,Ee]),{operation:us,target:ds,inputValue:fs,setInputValue:ms,submitting:ps,inputRef:hs,open:gs,close:xs,submit:vs,capabilities:{canCreateFile:Jn,canCreateFolder:Xn,canRename:Yn,canDelete:Zn}}=yi({files:o,root:l,selectedPath:p?.path??"",refreshDirectory:zt,removeOpenPathsByPrefix:Ie,clearSelectedPath:bt}),Qn=!!o.revealPath,bs=Xt(r=>r.availableApps),ws=Xt(r=>r.isCacheStale),er=Xt(r=>r.initialize),ys=Xt(r=>r.loadInstalledApps);s.useEffect(()=>{er()},[er]);const ks=s.useCallback(r=>{o.revealPath&&o.revealPath(r).catch(()=>{pe.error("Failed to reveal path")})},[o]),js=s.useCallback(async r=>{if(!p?.path||await Ho(p.path,r.id,r.appName)||await Mr(p.path,r.appName))return;const M=ki(p.path)||l;M&&await Mr(M,r.appName)||pe.error(`Failed to open in ${r.appName}`)},[l,p?.path]),Cs=Fe(r=>r.fileEditorKeymap),tr=Fe(r=>r.expandedEditorToolbar);s.useEffect(()=>{Se("")},[p?.path]);const nr=s.useRef("");s.useEffect(()=>{!l||nr.current===l||(nr.current=l,Be(""),xe(null),He(""),je(null),Ce(void 0),Ne(null),$e(null),ze(!1),T(!1))},[l]);const rr=s.useRef(be);s.useEffect(()=>{rr.current!==be&&(rr.current=be,Me.current+=1,ut.current=null,Be(""),Se(""),xe(null),it(!1),He(""),je(null),Ce(void 0),Ne(null),$e(null),ze(!1),cn(!1))},[be]);const Ns=f?k:I,{results:ar,searching:sr}=ji({directory:Ns,query:G,chrome:n,showGitignored:L}),At=s.useCallback(async(r,h)=>{if(o.readFile){const Ae=await o.readFile(r,{...h??{},directory:l||void 0});return{content:Ae.content??"",revision:Ae.revision,exists:Ae.exists}}const z=new URLSearchParams({path:r});h?.allowOutsideWorkspace&&z.set("allowOutsideWorkspace","true"),h?.outsideFileGrant&&z.set("outsideFileGrant",h.outsideFileGrant),h?.optional&&z.set("optional","true"),l&&z.set("directory",l);const M=await Tr(`/api/fs/read?${z.toString()}`,{cache:h?.optional?"no-store":"default"});if(!M.ok){const Ae=await M.json().catch(()=>({error:M.statusText}));throw new Error(Ae.error||"Failed to read file")}const ne=await M.text(),Z=M.headers?.get?.("x-pichamber-file-revision"),De=M.headers?.get?.("x-pichamber-file-exists")!=="false";return{content:ne,revision:typeof Z=="string"&&Z.length>0?Z:De?void 0:null,exists:De}},[o,l]),dt=s.useCallback(async(r,h)=>{if(o.statFile){const z=await o.statFile(r,{...h??{},directory:l||void 0});return{path:z.path,size:z.size,mtimeMs:z.mtimeMs,revision:z.revision}}return null},[o,l]);s.useEffect(()=>{if(!l||!o.statFile||ae.length===0)return;let r=!1;const h=[...ae];return Promise.all(h.map(async z=>{try{const M=await o.statFile?.(z,{directory:l||void 0});!r&&M&&!M.isFile&&Ie(l,z)}catch(M){!r&&Br(M)&&Ie(l,z)}})),()=>{r=!0}},[o,ae,Ie,l]);const ln=s.useMemo(()=>ke.length>Rt?`${ke.slice(0,Rt)}
|
|
5
|
+
|
|
6
|
+
… truncated …`:ke,[ke]),Ot=lt!==ln,Ss=s.useCallback((r,h)=>dt(r,{...ce,...h}),[dt,ce]),Rs=s.useCallback(()=>{je(null),Ce(void 0),Ne(null)},[]),{recordStat:tt}=yc({selectedPath:p?.path??null,loadedPath:et,isDirty:Ot,readStat:Ss,onExternalChange:Rs}),or=s.useRef(null),ir=s.useCallback((r,h,z,M)=>{Be(h);const ne=M?.generation??Me.current;if(typeof z<"u"&&(Ce(z),Ne({runtimeKey:M?.runtimeKey??be,root:M?.root??l,path:r,generation:ne})),l&&Cn(r,l)){const Z=St(l,r);Z&&ai.requestGitRefresh({directory:l,paths:[Z]})}en(r)&&or.current?.(h),dt(r).then(Z=>{Z&&Me.current===ne&&tt(Z)}).catch(()=>{})},[be,dt,tt,l]),un=s.useCallback(()=>p?.path?{runtimeKey:be,root:l,path:p.path,generation:Me.current}:null,[be,l,p?.path]),cr=un,lr=s.useCallback(async(r,h=null)=>{const z=Me.current,M=r.path;let ne=null,Z=r.currentRevision,_e=r.exists;try{if(_e){const De=await At(M,ce);ne=De.content,typeof De.revision=="string"&&(Z=De.revision),_e=De.exists!==!1}}catch{}Me.current===z&&($e({path:M,displayPath:St(l,M)||M,exists:_e,currentRevision:Z,currentContent:ne,diagramXml:h}),ze(!1))},[At,l,ce]),ur=s.useMemo(()=>{if(!p?.path||et!==p.path)return;const r=qn;if(r){if(ci({...r},{runtimeKey:be,root:l,path:p.path,generation:Me.current}))return typeof ct=="string"||ct===null?"__stale__":void 0;if(typeof ct=="string"||ct===null)return ct}},[be,et,ct,qn,l,p?.path]),{clearDiagramContent:dr,diagramEditorXml:Fs,diagramSaved:Es,drawioRemountNonce:zs,drawioViewMode:dn,handleDiagramChange:Ms,htmlViewMode:Pt,jsonViewMode:Lt,mdViewMode:It,recordDiagramContent:fn,saveDiagramNow:mn,saveDrawioViewMode:Ts,saveJsonViewMode:Ds,saveMdViewMode:fr,saveTextViewMode:As,setTextViewMode:pn,textViewMode:nt}=Cc({root:l,selectedPath:p?.path??null,fileContent:ke,draftContent:lt,setDraftContent:Se,autoSaveEnabled:Dt,writeFile:o.writeFile,expectedRevision:ur,captureSaveScope:un,currentSaveScope:cr,onSaved:ir,onConflict:r=>{lr(r,r.xml)}});or.current=fn;const Ge=s.useCallback(()=>It,[It]),{autoSaveStatus:Os,isSaving:hn,clearSaveConflict:rt,saveDraft:mr,saveNow:Bt}=bc({autoSaveEnabled:Dt,selectedPath:p?.path??null,loadedPath:et,fileLoading:sn,isDirty:Ot,draftContent:lt,fileContent:ke,lineEnding:Xa,isNonEditableBinary:!!(p?.path&&(Tn(p.path)||Un)),writeFile:o.writeFile,expectedRevision:ur,onSaved:ir,captureSaveScope:un,currentSaveScope:cr,onConflict:r=>{lr(r)}}),{confirmOpen:pr,discardAndTakeIntent:hr,keepModalOpen:Ps,requestNavigation:$t,saveAndTakeIntent:gr}=fc({isDirty:Ot,saveDraft:mr});s.useEffect(()=>{const r=h=>{Go(h)&&(h.key.toLowerCase()==="s"?(h.preventDefault(),Bt()):h.key.toLowerCase()==="f"&&(h.preventDefault(),ee(!0)))};return window.addEventListener("keydown",r),()=>window.removeEventListener("keydown",r)},[Bt]);const xr=s.useCallback(async r=>{const h=Me.current+1;Me.current=h;const z=be,M=l,ne=()=>{if(!l||z!==be||M!==l)return!1;const ie=Re.getState().byRoot[l],Je=ie?.selectedPath??ie?.openPaths[0]??null;return Me.current===h&&Je===r.path};xe(null),He(""),je(null),Ce(void 0),Ne(null),$e(null),ze(!1),rt(),cn(!1),x&&T(!0);const Z=Ar(r.path),_e={allowOutsideWorkspace:e==="editor-only"&&!!l&&!Cn(r.path,l),outsideFileGrant:Z};let De=!1;it(!0);let Ae;await dc(r.path,u.isDesktop,ie=>At(ie,_e).then(Je=>(Ae=Je.revision,Je.content))).then(ie=>{if(ne()){if(ie.kind!=="text"){if(Be(""),Se(""),ie.kind==="desktop-image"){De=!0;return}ie.kind==="binary"&&cn(ie.detectedFromContent),je(r.path);return}Ya(ie.lineEnding),Be(ie.content),fn(ie.content),Se(ie.draft),je(r.path),Ce(Ae),Ne({runtimeKey:z,root:M,path:r.path,generation:h}),dt(r.path,_e).then(Je=>{Je&&ne()&&tt(Je)}).catch(()=>{})}}).catch(ie=>{if(ne()){if(Ci(ie)){if(it(!1),l&&Ee(l,null),xe(null),Be(""),Se(""),je(null),Ce(void 0),Ne(null),tt(null),G.trim().length>0&&_(""),x&&T(!1),l){const yn=[...$r(r.path,l),r.path];yn.length>0&&U(l,yn);for(const Fr of yn)de(Fr)||ot(Fr)}return}if(Br(ie)){l&&Ie(l,r.path),Be(""),Se(""),xe(null),Ce(void 0),Ne(null),tt(null),x&&T(!1);return}Be(""),Se(""),xe(ie instanceof Error?ie.message:"Failed to read file"),Ce(void 0),Ne(null),tt(null)}}).finally(()=>{ne()&&!De&&it(!1)})},[be,rt,U,de,x,ot,e,At,dt,fn,tt,Ie,l,u.isDesktop,G,Ee]),Vt=s.useCallback(async(r,h)=>{if(!l||!B)return;const z=$r(r,l),M=h?[...z,r]:z;M.length>0&&U(l,M);const ne=M.map(Z=>{if(!de(Z))return ot(Z)}).filter(Boolean);await Promise.all(ne)},[U,de,ot,B,l]),vr=s.useCallback((r,h)=>{const z=h.findIndex(M=>M.path===r);return z===-1||h.length<=1?null:h[z+1]??h[z-1]??null},[]),We=s.useCallback(async r=>{$t({kind:"select",file:r})||(l&&(Ee(l,r.path),Vt(r.path,!1)),xe(null),He(""),Be(""),dr(),Se(""),je(null),Ce(void 0),Ne(null),$e(null),ze(!1),rt(),x&&T(!0))},[dr,rt,Vt,x,$t,l,Ee]),Ls=s.useCallback(r=>{We(qe(r))},[We,qe]),Is=s.useCallback(r=>{const h=oe(r);h&&(_(""),V(h),T(!1))},[]),Bs=s.useCallback(r=>{const h=oe(r);h&&(T(!0),We(qe(h)))},[We,qe]),$s=s.useCallback(async()=>{if(!(!k||E)){R(!0);try{await zt(k)}finally{R(!1)}}},[k,E,zt]),Vs=s.useCallback(()=>{const r=fe;if(r){if(!r.exists){l&&he(l,r.path),bt(),$e(null),ze(!1),rt();return}Se(""),je(null),Ce(void 0),Ne(null),$e(null),ze(!1),rt()}},[rt,bt,he,l,fe]),Ws=s.useCallback(async()=>{if(!(!fe||on)){Hn(!0);try{(fe.diagramXml!==null?await mn(fe.path,fe.diagramXml,{overwrite:!0}):await Bt({overwrite:!0}))&&($e(null),ze(!1))}finally{Hn(!1)}}},[on,fe,mn,Bt]),_s=s.useCallback(()=>{$e(null),ze(!1)},[]);s.useEffect(()=>{!p?.path||!B||!i||Vt(p.path,!1)},[Vt,i,B,p?.path]),s.useEffect(()=>{if(!p){Me.current+=1,ut.current=null,it(!1);return}if(et===p.path||ut.current===p.path)return;const r=p.path;ut.current=r,xr(p).finally(()=>{ut.current===r&&(ut.current=null)})},[xr,et,p]);const ft=s.useCallback(async r=>{if(r.kind==="select"){await We(r.file);return}if(r.kind==="tab"){Fe.getState().setActiveMainTab(r.tab);return}l&&he(l,r.path),p?.path===r.path&&(r.nextFile?await We(r.nextFile):bt())},[bt,We,he,l,p?.path]),Ks=s.useCallback(()=>{const r=hr();Se(ln),r&&ft(r)},[ft,hr,ln]),qs=s.useCallback(async()=>{const r=await gr();r&&await ft(r)},[ft,gr]),Hs=s.useCallback(r=>{const h=p?.path===r,z={kind:"close",path:r,nextFile:vr(r,Mt)};h&&$t(z)||ft(z)},[ft,vr,Mt,$t,p?.path]),Wt=s.useMemo(()=>Ac({root:l,openPaths:ae,gitFiles:$?.files}),[l,ae,$]),Gs=s.useCallback(r=>Wt.getFileStatus(r),[Wt]),Us=s.useCallback(r=>Wt.getFolderBadge(r),[Wt]),Js=s.useCallback(async r=>{const h=oe(r);!l||!B||(W(l,h),de(h)||await ot(h))},[de,ot,B,l,W]),Xs=s.useMemo(()=>({canRename:Yn,canCreateFile:Jn,canCreateFolder:Xn,canDelete:Zn,canReveal:Qn}),[Yn,Jn,Xn,Zn,Qn]),Te=!!(p?.path&&Sa(p.path)),mt=!!(p?.path&&Ra(p.path)),at=!!(p?.path&&Fa(p.path)),gn=!!(p?.path&&(Tn(p.path)||Un)),_t=gn&&!Te&&!at,pt=s.useMemo(()=>St(l,Ve),[Ve,l]),Ys=!!(p&&(!Te||mt)&&!at&&!_t&&ke.length>0),Zs=!!(p&&pt.length>0),wt=!!(p&&!Tt&&!gn&&!Te&&o.writeFile&&ke.length<=Rt),yt=!!(p?.path&&Ba(p.path)),xn=!!(p?.path&&Ia(p.path)),kt=!!(p?.path&&$n(p.path)),br=!!(p?.path&&en(p.path)),Qs=!!(p&&!gn&&!Te),{editorViewRef:we,notifyEditorViewChanged:Kt,shouldMaskEditor:eo}=pc({root:l,selectedPath:Ve||null,loadedPath:et,fileLoading:sn,fileError:Kn,isImage:Te,isPdf:at,isUnsupportedBinary:_t,canEdit:wt,textViewMode:nt,setTextViewMode:pn,draftContent:lt,confirmDiscardOpen:pr,selectFilePath:Ls}),wr=Qs&&!yt&&!br&&!(kt&&Pt==="preview"),to=yt&&It==="edit"||kt&&Pt==="edit"||xn&&Lt==="text"||!yt&&!kt&&!xn&&nt==="edit",qt=s.useMemo(()=>Ve?Ai(Ve):null,[Ve]),[yr,vn]=s.useState(null);s.useEffect(()=>{let r=!1;const h=p?.path;if(!h||qt){vn(null);return}return vn(null),Oi(h).then(z=>{r||vn(z)}),()=>{r=!0}},[p?.path,qt]),s.useEffect(()=>{!wt&&nt==="edit"&&pn("view")},[wt,pn,nt]);const Ue=s.useCallback(r=>{if(!x||!r||!r.hasFocus||typeof window>"u")return;const h=window.visualViewport;if(!h)return;const z=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,z-(h.offsetTop+h.height))<=0)return;const ne=r.state.selection.main.head,Z=r.coordsAtPos(ne);if(!Z)return;const _e=Math.round(h.offsetTop+h.height),Ae=Z.bottom+20-_e;Ae<=0||(r.scrollDOM.scrollTop+=Ae)},[x]);s.useEffect(()=>{if(!x||typeof window>"u")return;const r=()=>{window.requestAnimationFrame(()=>{Ue(we.current)})},h=window.visualViewport;return h?.addEventListener("resize",r),h?.addEventListener("scroll",r,{passive:!0}),document.addEventListener("selectionchange",r),()=>{h?.removeEventListener("resize",r),h?.removeEventListener("scroll",r),document.removeEventListener("selectionchange",r)}},[we,x,Ue]);const Ht=Fe(r=>r.editorFontSize),no=s.useMemo(()=>{if(!p?.path)return[Kr(m,{fontSize:Ht})];const r=Na(p.path),h=[Kr(m,r?{syntaxColors:!1,fontSize:Ht}:{fontSize:Ht})],z=qt??yr;return z&&h.push(z),r&&h.push(Ki({language:r,themeName:m.metadata.id,theme:oi(m)})),d&&h.push(me.lineWrapping),x&&h.push(me.updateListener.of(M=>{M.view.hasFocus&&(M.selectionSet||M.focusChanged||M.viewportChanged||M.geometryChanged)&&window.requestAnimationFrame(()=>{Ue(M.view)})})),h},[m,p?.path,qt,yr,d,x,Ue,Ht]),ro=s.useMemo(()=>({light:le.metadata.id,dark:Pe.metadata.id}),[le.metadata.id,Pe.metadata.id]),Gt=p?.path&&Te&&!u.isDesktop&&!mt?`${p.path}|${ce.allowOutsideWorkspace?"outside":"workspace"}|${ce.outsideFileGrant??""}`:"",Ut=p?.path&&at?`${p.path}|${ce.allowOutsideWorkspace?"outside":"workspace"}|${ce.outsideFileGrant??""}`:"",jt=p?.path&&kt&&Pt==="preview"?p.path:"",bn="Failed to read file",{readyKey:kr,nonce:ao}=Nn(Gt,xe,bn),{readyKey:jr,nonce:so}=Nn(jt,xe,bn),{readyKey:Cr,nonce:oo}=Nn(Ut,xe,bn),io=!!(Gt&&kr!==Gt),co=!!(jt&&jr!==jt),lo=!!(Ut&&Cr!==Ut),uo=p?.path&&Te?u.isDesktop?mt?`data:${Pr(p.path)};utf8,${encodeURIComponent(ke)}`:Ua:mt?`data:${Pr(p.path)};utf8,${encodeURIComponent(ke)}`:kr===Gt?jn().authenticatedAsset("/api/fs/raw",{path:p.path,allowOutsideWorkspace:ce.allowOutsideWorkspace?"true":void 0,outsideFileGrant:ce.outsideFileGrant,directory:l||void 0}):"":"",fo=p?.path&&at&&Cr===Ut?jn().authenticatedAsset("/api/fs/raw",{path:p.path,allowOutsideWorkspace:ce.allowOutsideWorkspace?"true":void 0,outsideFileGrant:ce.outsideFileGrant,directory:l||void 0}):"",mo=jt&&jr===jt&&p?.path?(()=>{const r=p.path.split("/").map(h=>encodeURIComponent(h)).join("/");return jn().authenticatedAsset(`/api/fs/serve${r.startsWith("/")?r:`/${r}`}`)})():void 0;s.useEffect(()=>{let r=!1;return(async()=>{if(!u.isDesktop||!p?.path||!Te||mt){ve.current&&(URL.revokeObjectURL(ve.current),ve.current=""),He("");return}xe(null),ve.current&&(URL.revokeObjectURL(ve.current),ve.current=""),await(o.readFileBinary?o.readFileBinary(p.path,ce).then(M=>M.dataUrl):(async()=>{const M=await Tr("/api/fs/raw",{query:{path:p.path,allowOutsideWorkspace:ce.allowOutsideWorkspace?"true":void 0,outsideFileGrant:ce.outsideFileGrant,directory:l||void 0}});if(!M.ok)throw new Error("Failed to read file");const ne=await M.blob(),Z=URL.createObjectURL(ne);return r?(URL.revokeObjectURL(Z),""):(ve.current=Z,Z)})()).then(M=>{r||(He(M),je(p.path))}).catch(M=>{ve.current&&(URL.revokeObjectURL(ve.current),ve.current=""),r||(He(""),xe(M instanceof Error?M.message:"Failed to read file"),je(null))}).finally(()=>{r||it(!1)})})(),()=>{r=!0}},[o,Te,mt,l,u.isDesktop,p?.path,ce]),s.useEffect(()=>()=>{ve.current&&(URL.revokeObjectURL(ve.current),ve.current="")},[]);const Nr=s.useCallback(()=>{const r=o.downloadFile,h=p?.path;!r||!h||r(h).catch(z=>{console.error("Download failed:",z),pe.error("Operation failed")})},[o.downloadFile,p?.path]),wn=({exitFullscreenOnly:r=!1,layout:h="floating"}={})=>t.jsx(Mc,{selectedFile:p,displaySelectedPath:pt,layout:h,exitFullscreenOnly:r,canEdit:wt,isEditingFile:to,isSaving:hn,autoSaveEnabled:Dt,autoSaveStatus:Os,isDirty:Ot,onSaveDraft:mr,onToggleAutoSave:()=>Za(!Dt),openInApps:bs,openInCacheStale:ws,onOpenInApp:js,onRefreshOpenInApps:()=>ys(!0),onToolbarDropdownOpenChange:Qe,isSelectedImage:Te,isSelectedPdf:at,isUnsupportedBinary:_t,wrapLines:d,onToggleWrapLines:()=>O(!d),textViewMode:nt,onToggleSearch:()=>ee(!Y),isGoToLineOpen:cs,onOpenGoToLineChange:ls,editorView:we.current,canUseShikiFileView:wr,isJson:xn,isHtml:kt,onToggleTextViewMode:()=>{As(nt==="view"?"edit":"view")},isMarkdown:yt,mdViewMode:Ge(),onToggleMdViewMode:()=>fr(Ge()==="preview"?"edit":"preview"),isDrawio:br,drawioViewMode:dn,onToggleDrawioViewMode:()=>Ts(dn==="preview"?"edit":"preview"),diagramSaved:Es,onSaveDiagram:async()=>{const z=Gn.current?.getXml();p?.path&&z&&await mn(p.path,z)},jsonViewMode:Lt,onToggleJsonViewMode:()=>Ds(Lt==="tree"?"text":"tree"),canCopy:Ys,copiedContent:as,onCopyContent:async()=>{(await Zt(ke)).ok?ss(!0):pe.error("Copy failed")},canCopyPath:Zs,copiedPath:os,onCopyPath:async()=>{(await Zt(pt)).ok?is(!0):pe.error("Copy failed")},onDownloadFile:o.downloadFile&&p?Nr:void 0,isMobile:x,mode:e,isFullscreen:S,onToggleFullscreen:()=>P(!S),onExitFullscreen:()=>P(!1)}),po=s.useCallback(r=>{we.current=r,Kt(),window.requestAnimationFrame(()=>{Ue(r)})},[we,Kt,Ue]),ho=s.useCallback(()=>{we.current&&(we.current=null),Kt()},[we,Kt]),go=s.useCallback(r=>{we.current=r,window.requestAnimationFrame(()=>{Ue(r)})},[we,Ue]),xo=s.useCallback(()=>{we.current&&(we.current=null)},[we]),Sr={selectedFile:p,loading:sn||io||lo,suppressLoadingIndicator:D,fileError:Kn,isSelectedImage:Te,imageSrc:uo,imagePreviewNonce:ao,isSelectedPdf:at,pdfSrc:fo,pdfPreviewNonce:oo,isUnsupportedBinary:_t,onDownload:o.downloadFile&&p?Nr:void 0,drawioViewMode:dn,drawioRemountNonce:zs,diagramEditorRef:Gn,diagramEditorXml:Fs,onDiagramChange:Ms,jsonViewMode:Lt,markdownViewMode:It,htmlViewMode:Pt,htmlLoading:co,htmlPreviewNonce:so,htmlPreviewSrc:mo,fileContent:ke,canUseShikiFileView:wr,textViewMode:nt,draftContent:lt,onDraftChange:Se,canEdit:wt,vimMode:Cs==="vim",editorExtensions:no,shouldMaskEditorForPendingNavigation:eo,pierreTheme:ro,shikiThemeType:m.metadata.variant==="dark"?"dark":"light",wrapLines:d},Jt=t.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[t.jsx(Tc,{open:pr,onOpenChange:Ps,isSaving:hn,onSaveAndContinue:()=>{qs()},onDiscardAndContinue:Ks}),t.jsx(li,{open:!!fe,conflict:fe?{path:fe.path,displayPath:fe.displayPath,exists:fe.exists,currentRevision:fe.currentRevision,currentContent:fe.currentContent,dirtyContent:fe.diagramXml??lt}:null,isResolving:on||hn,showCompare:Ja,onToggleCompare:()=>ze(r=>!r),onReload:Vs,onOverwrite:()=>{Ws()},onClose:_s}),t.jsxs("div",{className:J("flex flex-col flex-shrink-0",H&&"border-b border-border/40"),children:[t.jsx(Fc,{showEditorTabsRow:H,isMobile:x,showMobilePageContent:A,onBackMobile:()=>T(!1),selectedFile:p,openFiles:Mt,root:l,alwaysShowActions:v,editorTabsOverflow:Ha,editorTabsScrollRef:an,onSelectFile:We,onCloseFile:Hs}),(tr||x)&&p?t.jsxs("div",{className:"flex min-w-0 items-center gap-3 border-t border-border/40 bg-[var(--surface-subtle)] px-3 py-1",children:[pt&&!x?t.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:pt,children:pt}):null,t.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:wn({layout:"docked"})})]}):null]}),t.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[p&&!Y&&!(tr||x)&&t.jsx("div",{ref:K,className:"absolute right-3 top-3 z-30",onMouseLeave:()=>{Q.current>0||te(!1)},children:re?wn():t.jsxs("div",{className:"flex items-center gap-1",children:[yt?t.jsxs(Xe,{children:[t.jsx(Ye,{asChild:!0,children:t.jsx("span",{className:"inline-flex",children:t.jsx(q,{variant:"ghost",size:"sm",onClick:()=>fr(Ge()==="preview"?"edit":"preview"),className:J("size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 shadow-sm transition-colors",Ge()==="preview"?"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)] hover:bg-[var(--interactive-selection)]":"text-muted-foreground hover:text-foreground"),"aria-label":Ge()==="preview"?"Switch to edit mode":"Switch to preview mode",title:Ge()==="preview"?"Switch to edit mode":"Switch to preview mode",children:t.jsx(F,{name:Ge()==="preview"?"eye":"eye-off",className:"size-4"})})})}),t.jsx(Ze,{side:"bottom",sideOffset:6,children:Ge()==="preview"?"Switch to edit mode":"Switch to preview mode"})]}):null,t.jsxs(Xe,{children:[t.jsx(Ye,{asChild:!0,children:t.jsx("span",{className:"inline-flex",onMouseEnter:()=>te(!0),children:t.jsx(q,{variant:"ghost",size:"sm",onClick:()=>te(!0),className:"size-8 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-0 text-muted-foreground shadow-sm hover:text-foreground","aria-label":"Show editor controls",title:"Editor controls",children:t.jsx(F,{name:"more-2-fill",className:"size-4"})})})}),t.jsx(Ze,{side:"bottom",sideOffset:6,children:"Editor controls"})]})]})}),t.jsx(ia,{variant:"embedded",...Sr,enableRichPreviews:!0,editorWrapperRef:Qa,onEditorViewReady:po,onEditorViewDestroy:ho,enableSearch:!0,searchOpen:Y,onSearchOpenChange:ee})]})]}),Rr=t.jsx(Pc,{root:l,isMobile:x,searchQuery:G,onSearchQueryChange:_,searchInputRef:X,searching:sr,searchResults:ar,selectedFile:p,onSelectFile:We,onOpenDialog:gs,currentDirectory:I,refreshRoot:qa,childrenByDir:se,loadErrorsByDir:ge,expandedPaths:ye,isBrowserClient:C,alwaysShowActions:v,getFileStatus:Gs,getFolderBadge:Us,fileRowPermissions:Xs,downloadFile:o.downloadFile,contextMenuPath:es,setContextMenuPath:ts,rightClickMenuPath:ns,setRightClickMenuPath:rs,toggleDirectory:Js,handleRevealPath:ks,refreshDirectory:zt}),vo=e==="full"&&S&&p&&t.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:t.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[t.jsx("div",{className:"absolute right-4 top-4 z-30",children:wn({exitFullscreenOnly:!0})}),t.jsx(ia,{variant:"fullscreen",...Sr,enableRichPreviews:!1,onEditorViewReady:go,onEditorViewDestroy:xo})]})});return f?t.jsx(Ui,{root:l,directory:k||l,entries:k||l?se[k||l]:void 0,query:G,searchResults:ar,isSearching:sr,directoryError:k||l?ge[k||l]??null:null,refreshing:E,editorPath:A?p?.path??null:null,editor:Jt,onClose:a,onQueryChange:_,onOpenDirectory:Is,onOpenFile:Bs,onBackFromEditor:()=>T(!1),onRefresh:()=>{$s()}}):t.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[t.jsx(Xi,{activeDialog:us,dialogData:ds,dialogInputValue:fs,onDialogInputChange:ms,isDialogSubmitting:ps,onDialogSubmit:vs,onClose:xs,inputRef:hs}),vo,x?A?Jt:Rr:e==="editor-only"?t.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:t.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:Jt})}):t.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[j>=700&&t.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:Rr}),t.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:Jt})]})]})};export{Xl as FilesView};
|