@openchamber/web 1.20.0 → 1.21.1

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.
Files changed (174) hide show
  1. package/bin/cli.test.js +35 -0
  2. package/bin/lib/DOCUMENTATION.md +12 -0
  3. package/bin/lib/cli-settings-accessors.js +111 -0
  4. package/bin/lib/cli-settings-accessors.test.js +189 -0
  5. package/bin/lib/cli-startup.js +29 -9
  6. package/bin/lib/commands-connect-url.js +12 -14
  7. package/dist/assets/{CodeMirrorCommentWidgets-C36E738Y.js → CodeMirrorCommentWidgets-BGj8TJxW.js} +1 -1
  8. package/dist/assets/CommitSection-DwGiXyjf.js +1 -0
  9. package/dist/assets/DiffView-Db6bjVv1.js +4 -0
  10. package/dist/assets/FilesView-DQOa7Lgz.js +17 -0
  11. package/dist/assets/GitView-CHzJxTi0.js +6 -0
  12. package/dist/assets/{JsonTreeView-KnXFN2A-.js → JsonTreeView-CggOsLot.js} +1 -1
  13. package/dist/assets/MarkdownImageGallery-DoZpaHev.js +1 -0
  14. package/dist/assets/MarkdownRendererImpl-B5Y5xCOz.js +12 -0
  15. package/dist/assets/OnboardingScreen-C98d69Fp.js +1 -0
  16. package/dist/assets/{PatchDiff-BzVOVog8.js → PatchDiff-DJYMUiXA.js} +1 -1
  17. package/dist/assets/PierreDiffViewer-CY2bx_SB.js +157 -0
  18. package/dist/assets/PlanView-PkiOY_9H.js +5 -0
  19. package/dist/assets/SettingsView-D-K3ELCM.js +28 -0
  20. package/dist/assets/SettingsWindow-oyOm2fHR.js +1 -0
  21. package/dist/assets/{ToolOutputDialog-BB1c--Zr.js → ToolOutputDialog-lKyeQTPL.js} +6 -6
  22. package/dist/assets/{ToolPartDiffPreview-DaOIDISD.js → ToolPartDiffPreview-C7kBQNAA.js} +2 -2
  23. package/dist/assets/{VirtualizedFileDiff-lESMT-2b.js → VirtualizedFileDiff-BP7ebDFF.js} +4 -4
  24. package/dist/assets/{Virtualizer-X_7XPoTH.js → Virtualizer-CZlLSacm.js} +1 -1
  25. package/dist/assets/Virtualizer-D_a8gKmg.js +1 -0
  26. package/dist/assets/{WalkthroughView-CaSYE0lw.js → WalkthroughView-MuJodAHD.js} +2 -2
  27. package/dist/assets/{computeVirtualFileMetrics-DkRR5b75.js → computeVirtualFileMetrics-CZ0xPeaT.js} +2 -2
  28. package/dist/assets/contextPanelEmbeddedChat-C9abMBTb.js +1 -0
  29. package/dist/assets/de-CEoCz3j6.js +9 -0
  30. package/dist/assets/es-DwyXCqaL.js +15 -0
  31. package/dist/assets/fr-CS7Csln9.js +13 -0
  32. package/dist/assets/index-CUKcHnUA.css +1 -0
  33. package/dist/assets/index-CaPAjwXQ.js +1 -0
  34. package/dist/assets/index-DIvDEKE-.js +7 -0
  35. package/dist/assets/{isDiffPlainText-BG53Ixxy.js → isDiffPlainText-ZBvDxhVB.js} +1 -1
  36. package/dist/assets/{isFilePlainText-BbV-39jl.js → isFilePlainText-DiLRrkJr.js} +1 -1
  37. package/dist/assets/ja-vnwqLcx6.js +15 -0
  38. package/dist/assets/ko-CXuSfZv5.js +15 -0
  39. package/dist/assets/main-D5RWr6sJ.js +2 -0
  40. package/dist/assets/main-DLlfDjQ_.js +926 -0
  41. package/dist/assets/{markdown-shiki.worker-CKGJ1J33.js → markdown-shiki.worker-D5fBU-lw.js} +5 -5
  42. package/dist/assets/markdownCore-CcTcLsQF.js +3 -0
  43. package/dist/assets/{miniChat-ldEghBLB.js → miniChat-CqR3icsk.js} +2 -2
  44. package/dist/assets/mobile-RN_UTTlB.js +2 -0
  45. package/dist/assets/{patchFileDiff-BcFaMtMu.js → patchFileDiff-CjRR5ESs.js} +1 -1
  46. package/dist/assets/pl-BJxry0Mi.js +15 -0
  47. package/dist/assets/pt-BR-DxLmkhdv.js +15 -0
  48. package/dist/assets/renderElectronMiniChatApp-1wC94fQK.js +2 -0
  49. package/dist/assets/renderMobileApp-ltva2Plg.js +25 -0
  50. package/dist/assets/runtimeEndpointReset-D6SmNZaP.js +15 -0
  51. package/dist/assets/scheduledTasksApi-mjMDet_H.js +1 -0
  52. package/dist/assets/{shikiHighlight-DCT2Sq_z.js → shikiHighlight-fGmFkxAM.js} +1 -1
  53. package/dist/assets/tr-5Mk_hQ2Q.js +6 -0
  54. package/dist/assets/uk-ClgQjmlw.js +15 -0
  55. package/dist/assets/{useAppFontEffects-B53Rb6m7.js → useAppFontEffects-KP8_yiGW.js} +176 -184
  56. package/dist/assets/useInlineCommentController-HIjtuhxD.js +2 -0
  57. package/dist/assets/useRootScrollLock-BSiQ5F75.js +1 -0
  58. package/dist/assets/{vendor-base-ui-DsHmyMwp.js → vendor-base-ui-BeMD8X_w.js} +1 -1
  59. package/dist/assets/{vendor-codemirror-language-data-vch3tJ4c.js → vendor-codemirror-language-data-DrTPkHl4.js} +2 -2
  60. package/dist/assets/{vendor-floating-ui-core-CXmKXOXc.js → vendor-floating-ui-core-PuGzNPnN.js} +1 -1
  61. package/dist/assets/{vendor-floating-ui-dom-WyXykhNi.js → vendor-floating-ui-dom-BTvzWks8.js} +1 -1
  62. package/dist/assets/{vendor-floating-ui-react-dom-DKpLs02S.js → vendor-floating-ui-react-dom-DxYCWdHj.js} +1 -1
  63. package/dist/assets/{vendor-floating-ui-utils-BzXdqYpP.js → vendor-floating-ui-utils-D6FqdtJt.js} +1 -1
  64. package/dist/assets/{vendor-framer-motion-CRSgBxjL.js → vendor-framer-motion-livSKyyV.js} +1 -1
  65. package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +1 -0
  66. package/dist/assets/vendor-linkify-it-DZCzzDkK.js +1 -0
  67. package/dist/assets/vendor-marked-linkify-it-CXI_LHIE.js +1 -0
  68. package/dist/assets/{vendor-motion-dom-DJLgZh4Q.js → vendor-motion-dom-D_o3BTI3.js} +1 -1
  69. package/dist/assets/vendor-uc.micro-BAd0H0z4.js +1 -0
  70. package/dist/assets/vendor-zod-BLfBSgBh.js +39 -0
  71. package/dist/assets/{web-components-pcwCTWjC.js → web-components-DOXvU-tB.js} +4 -4
  72. package/dist/assets/zh-CN-Ba6y8H-i.js +15 -0
  73. package/dist/assets/zh-TW-Dv8yyhN1.js +15 -0
  74. package/dist/index.html +7 -7
  75. package/dist/mini-chat.html +5 -5
  76. package/dist/mobile.html +5 -5
  77. package/dist/site.webmanifest +1 -1
  78. package/dist/sw.js +1 -1
  79. package/package.json +4 -4
  80. package/public/site.webmanifest +1 -1
  81. package/server/index.js +10 -2
  82. package/server/lib/client-auth/pairing.js +8 -7
  83. package/server/lib/client-auth/pairing.test.js +5 -1
  84. package/server/lib/client-auth/remote-clients.js +9 -1
  85. package/server/lib/client-auth/remote-clients.test.js +17 -0
  86. package/server/lib/cloudflare-tunnel.js +1 -1
  87. package/server/lib/fs/DOCUMENTATION.md +1 -0
  88. package/server/lib/fs/routes.js +21 -0
  89. package/server/lib/fs/routes.test.js +89 -3
  90. package/server/lib/git/DOCUMENTATION.md +4 -3
  91. package/server/lib/git/service.js +128 -6
  92. package/server/lib/git/service.test.js +191 -1
  93. package/server/lib/github/pr-status.js +10 -1
  94. package/server/lib/markdown-image-grants/DOCUMENTATION.md +4 -0
  95. package/server/lib/markdown-image-grants/routes.js +3 -1
  96. package/server/lib/markdown-image-grants/routes.test.js +14 -0
  97. package/server/lib/openchamber-sessions/routes.js +4 -1
  98. package/server/lib/openchamber-sessions/routes.test.js +23 -0
  99. package/server/lib/opencode/env-runtime.js +17 -1
  100. package/server/lib/opencode/env-runtime.test.js +56 -0
  101. package/server/lib/opencode/lifecycle.js +48 -9
  102. package/server/lib/opencode/lifecycle.test.js +125 -1
  103. package/server/lib/opencode/managed-process-registry.d.ts +13 -0
  104. package/server/lib/opencode/managed-process-registry.js +213 -163
  105. package/server/lib/opencode/managed-process-registry.test.mjs +285 -0
  106. package/server/lib/opencode/project-directory-runtime.js +16 -11
  107. package/server/lib/opencode/project-directory-runtime.test.js +32 -12
  108. package/server/lib/opencode/pwa-manifest-routes.js +1 -1
  109. package/server/lib/opencode/routes-upgrade.test.js +96 -12
  110. package/server/lib/opencode/routes.js +53 -5
  111. package/server/lib/opencode/settings-helpers.js +3 -0
  112. package/server/lib/opencode/settings-helpers.test.js +10 -0
  113. package/server/lib/opencode/theme-runtime.js +1 -1
  114. package/server/lib/opencode/theme-runtime.test.js +129 -0
  115. package/server/lib/quota/DOCUMENTATION.md +19 -0
  116. package/server/lib/quota/providers/copilot.js +26 -10
  117. package/server/lib/quota/providers/copilot.test.js +78 -0
  118. package/server/lib/quota/providers/index.js +4 -18
  119. package/server/lib/relay/DOCUMENTATION.md +1 -1
  120. package/server/lib/relay/service.js +34 -2
  121. package/server/lib/relay/service.test.js +69 -0
  122. package/server/lib/session-goal/runtime.js +2 -1
  123. package/server/lib/session-goal/runtime.test.js +4 -2
  124. package/server/lib/small-model/DOCUMENTATION.md +11 -5
  125. package/server/lib/small-model/call.js +64 -20
  126. package/server/lib/small-model/call.test.js +184 -2
  127. package/server/lib/terminal/DOCUMENTATION.md +2 -0
  128. package/server/lib/terminal/runtime.js +29 -1
  129. package/server/lib/terminal/runtime.test.js +26 -0
  130. package/server/lib/tunnels/install-help.js +2 -2
  131. package/server/lib/tunnels/install-help.test.js +9 -0
  132. package/server/lib/ui-auth/ui-auth.js +2 -2
  133. package/server/lib/ui-auth/ui-auth.test.js +2 -2
  134. package/server/lib/walkthrough/languages.js +1 -0
  135. package/dist/assets/CommitSection-C-F3AX6D.js +0 -1
  136. package/dist/assets/DiagramEditor-BPECg1jS.js +0 -1
  137. package/dist/assets/DiagramView-D0YNMix8.js +0 -1
  138. package/dist/assets/DiffView-BHWaMYCC.js +0 -4
  139. package/dist/assets/FilesView-NMBCW2Tm.js +0 -14
  140. package/dist/assets/GitView-Rp8P1KEI.js +0 -6
  141. package/dist/assets/MarkdownImageGallery-BMn3mtor.js +0 -1
  142. package/dist/assets/MarkdownRendererImpl-kD6N03pH.js +0 -12
  143. package/dist/assets/OnboardingScreen-CenIeD4v.js +0 -1
  144. package/dist/assets/PierreDiffViewer-Dlby4XqT.js +0 -136
  145. package/dist/assets/PlanView-Czu1KMJa.js +0 -4
  146. package/dist/assets/SessionSwitcherDropdown-IETz58DB.js +0 -1
  147. package/dist/assets/SettingsView-B6vmuf-c.js +0 -28
  148. package/dist/assets/SettingsWindow-CauZpdD3.js +0 -1
  149. package/dist/assets/contextPanelEmbeddedChat-BEARQjgn.js +0 -1
  150. package/dist/assets/de-DFdX3ABv.js +0 -9
  151. package/dist/assets/es-iC-FKvV9.js +0 -15
  152. package/dist/assets/fr-BBbi_1AL.js +0 -13
  153. package/dist/assets/index-BiEgzzkg.js +0 -1
  154. package/dist/assets/index-Cwmuwk3V.js +0 -7
  155. package/dist/assets/index-GNm1wgUH.css +0 -1
  156. package/dist/assets/ja-DQLQJL2J.js +0 -15
  157. package/dist/assets/ko-BeElEB4Y.js +0 -15
  158. package/dist/assets/main-Dpzo18z7.js +0 -2
  159. package/dist/assets/main-WMjtYzJs.js +0 -921
  160. package/dist/assets/markdownCore--tDmyI_v.js +0 -2
  161. package/dist/assets/mobile-Dk-VGreF.js +0 -2
  162. package/dist/assets/pl-CLHt2_vV.js +0 -15
  163. package/dist/assets/pt-BR-C_MPUq7e.js +0 -15
  164. package/dist/assets/renderElectronMiniChatApp-DIgCOmXY.js +0 -2
  165. package/dist/assets/renderMobileApp-CDfHS5rr.js +0 -25
  166. package/dist/assets/runtimeEndpointReset-ovNbaZ-x.js +0 -15
  167. package/dist/assets/scheduledTasksApi-BFSlqgnG.js +0 -1
  168. package/dist/assets/uk-PhsC-c4-.js +0 -15
  169. package/dist/assets/useInlineCommentController-DSfrIBKT.js +0 -2
  170. package/dist/assets/vendor-zod-C9ioTTSo.js +0 -39
  171. package/dist/assets/zh-CN-wF-NOFHM.js +0 -15
  172. package/dist/assets/zh-TW-4m4-A7rT.js +0 -15
  173. package/server/lib/quota/providers/command-code.js +0 -90
  174. package/server/lib/quota/providers/command-code.test.js +0 -85
@@ -0,0 +1,4 @@
1
+ import{R as o,j as n,f as be}from"./vendor-react-BUCujlKS.js";import{W as pn,a as at,u as te,F as Ge}from"./index-DIvDEKE-.js";import{f as we,V as Et,ab as hn,bo as gn,ad as xn,ac as bn,ae as wn,af as ae,y as vt,k as yn,hF as vn,hG as jn,hH as Sn,cB as Nn,t as Ke,hI as Fn,am as Be,B as me,I as A,h as le,a6 as kn,a7 as Cn,a8 as Dn,hs as Bt,hJ as Rn,fs as An,fx as $e,a0 as En,c0 as it,ao as Vt,al as Bn,a$ as Vn,b1 as Ln,fy as Tn,b2 as Mn}from"./useAppFontEffects-KP8_yiGW.js";import{c as _n,p as In}from"./vendor-zustand-BAGL70zf.js";import{P as On}from"./PierreDiffViewer-CY2bx_SB.js";import{u as zn,v as Pn,g as Gn,W as $n}from"./main-DLlfDjQ_.js";import{f as Kn}from"./patchFileDiff-CjRR5ESs.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zod-BLfBSgBh.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-C9abMBTb.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-codemirror-state-C9awkmn-.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-codemirror-view-CiLROUVV.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-DrTPkHl4.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./web-components-DOXvU-tB.js";import"./computeVirtualFileMetrics-CZ0xPeaT.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-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.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"./VirtualizedFileDiff-BP7ebDFF.js";import"./isDiffPlainText-ZBvDxhVB.js";import"./vendor-diff-C3JhlQdm.js";import"./Virtualizer-D_a8gKmg.js";import"./useInlineCommentController-HIjtuhxD.js";import"./runtimeEndpointReset-D6SmNZaP.js";import"./appThemeRegistry-BK0dHKa6.js";import"./registerCustomTheme-BBXUCRnG.js";import"./useRootScrollLock-BSiQ5F75.js";import"./scheduledTasksApi-mjMDet_H.js";import"./vendor-cron-parser-CUcP7OfX.js";import"./vendor-luxon-BZ0puJYg.js";const Hn="openchamber.git-base-branch",Wn=100,He=(s,e)=>JSON.stringify([at(),s,e]),jt=_n()(In((s,e)=>({overrides:{},getOverride:(i,a)=>!i||!a?null:e().overrides[He(i,a)]??null,setOverride:(i,a,d)=>{!i||!a||!d||s(u=>{const p=He(i,a),g=Object.entries({...u.overrides,[p]:d});for(;g.length>Wn;)g.shift();return{overrides:Object.fromEntries(g)}})},clearOverride:(i,a)=>{!i||!a||s(d=>{const u=He(i,a);if(!(u in d.overrides))return d;const p={...d.overrides};return delete p[u],{overrides:p}})}}),{name:Hn,storage:pn(),partialize:s=>({overrides:s.overrides})})),Un=(s,e)=>!!s&&e!==null&&s!==e,qn=(s,e,i,a)=>i?s===null||a&&e===null?!0:e!==null&&s===e:!1,Xn=(s,e)=>s==="branch"&&!e?"working":s,Jn=(s,e,i)=>JSON.stringify([s,e,i]),Yn=(s,e,i,a,d,u)=>{const p=o.useRef({directory:"",attempts:0}),[g,f]=o.useState(()=>({directory:"",exhausted:!1})),m=o.useRef(d);m.current=d;const x=!!s&&g.directory===s&&g.exhausted;return o.useEffect(()=>{if(!s||!e||a||i)return;const c=p.current.directory===s?p.current.attempts:0;if(c>=u){g.directory===s&&g.exhausted||f({directory:s,exhausted:!0});return}p.current={directory:s,attempts:c+1},m.current()},[s,g,a,e,i,u]),x},Qn=(s,e,i,a)=>{const[d,u]=o.useState(()=>new Map),p=o.useRef(d);p.current=d;const g=o.useRef(i);g.current=i;const f=o.useCallback((m,x)=>{const c=new Map(p.current);if(x===null){if(!c.delete(m))return}else c.set(m,x);p.current=c,u(c)},[]);return o.useEffect(()=>{s&&(p.current=new Map,u(p.current))},[s]),o.useEffect(()=>{const m=g.current;if(!s||!m||!e)return;let x=!1;const c=new Set;for(const v of e.split("\0"))p.current.has(v)||(c.add(v),f(v,a),m(v).then(S=>{x||(c.delete(v),f(v,S))}).catch(()=>{x||(c.delete(v),f(v,null))}));return()=>{x=!0;for(const v of c)f(v,null)}},[e,a,s,f]),d},St=(s,e)=>{if(e.length===0)return null;let i=null,a=null;for(const u of e)u.top<=s?(!i||u.top>i.top)&&(i=u):(!a||u.top<a.top)&&(a=u);const d=i??a;return d?{path:d.path,topOffset:d.top-s}:null},Zn=(s,e,i,a)=>Math.min(Math.max(0,a),Math.max(0,s+i-e)),Nt=s=>{if(!s)return null;const e=s.split(`
2
+ `);let i=null;for(const a of e){const d=a.match(/^@@\s*-\d+(?:,\d+)?\s+\+(\d+)(?:,\d+)?\s*@@/);if(d){const u=Number.parseInt(d[1]??"",10);i=Number.isFinite(u)&&u>=1?u:null;continue}if(i!==null){if(a.startsWith(" ")){i+=1;continue}if(a.startsWith("+"))return i;if(a.startsWith("-"))return Math.max(1,i)}}return null},es=1100,ts=15e3,Ft=500,kt=300,ns=1e6,ss=3,rs=s=>s<=6?s:s<=12?6:s<=25?4:2,is={original:"",modified:"",isBinary:!1,contextMode:"patch"},os=3,as=o.memo(()=>{const s=be.c(4),{t:e}=we();let i;s[0]!==e?(i=e("diffView.binary.unavailable"),s[0]=e,s[1]=i):i=s[1];let a;return s[2]!==i?(a=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:i})}),s[2]=i,s[3]=a):a=s[3],a}),Lt={"?":{code:"?",color:"var(--status-info)",descriptionKey:"diffView.change.untracked"},A:{code:"A",color:"var(--status-success)",descriptionKey:"diffView.change.new"},D:{code:"D",color:"var(--status-error)",descriptionKey:"diffView.change.deleted"},R:{code:"R",color:"var(--status-info)",descriptionKey:"diffView.change.renamed"},C:{code:"C",color:"var(--status-info)",descriptionKey:"diffView.change.copied"},M:{code:"M",color:"var(--status-warning)",descriptionKey:"diffView.change.modified"}},ls=Lt.M,cs=s=>{const e=s.index?.trim(),i=s.working_dir?.trim();return e&&e!=="?"?e.charAt(0):i?i.charAt(0):e?.charAt(0)||i?.charAt(0)||"M"},Tt=s=>{const e=cs(s);return Lt[e]??ls},fs=s=>{const{index:e,working_dir:i}=s;return e==="A"||i==="A"||e==="?"||i==="?"},Ct=s=>{const e=s.index?.trim();return!!(e&&e!=="?")},Dt=s=>!!s.working_dir?.trim()||s.index==="?",us=(s,e)=>An(s,e),Rt=s=>(s||"").replace(/\\/g,"/").replace(/\/+$/,""),At=(s,e)=>{const i=s.split(`
3
+ `),a=e.split(`
4
+ `),d=Math.min(i.length,a.length);for(let u=0;u<d;u+=1)if(i[u]!==a[u])return u+1;return a.length>i.length?i.length+1:i.length>a.length?Math.max(1,a.length):1},ds=s=>/^Binary files .+ differ$/m.test(s)||/^GIT binary patch$/m.test(s),ms=s=>Array.isArray(s)?s.filter(e=>!e||typeof e!="object"?!1:typeof e.file=="string"):[],ps=s=>s==="added"?"A":s==="deleted"?"D":"M",ot=(s,e,i)=>ds(e)?{original:"",modified:"",isBinary:!0,patch:e,contextMode:i}:{original:"",modified:"",patch:e,fileDiff:Kn(s,e),contextMode:i},Mt=(s,e,i)=>{const a=s??0,d=e??0;return!a&&!d?null:n.jsxs("span",{className:le("typography-meta flex items-center gap-1 text-xs whitespace-nowrap","flex-shrink-0",i?.className),children:[a?n.jsxs("span",{style:{color:"var(--status-success)"},children:["+",a]}):null,d?n.jsxs("span",{style:{color:"var(--status-error)"},children:["-",d]}):null]})},hs=o.memo(s=>{const e=be.c(58),{scope:i,workingCount:a,stagedCount:d,turnCount:u,branchCount:p,showBranchOption:g,onScopeChange:f}=s,{t:m}=we(),[x,c]=o.useState(!1),v=i==="staged"?d:i==="turn"?u:i==="branch"?p??0:a;let S;e[0]!==i||e[1]!==m?(S=m(i==="staged"?"diffView.scope.staged":i==="turn"?"diffView.scope.lastTurn":i==="branch"?"diffView.scope.branch":"diffView.scope.changed"),e[0]=i,e[1]=m,e[2]=S):S=e[2];const O=S;let T;e[3]!==m?(T=m("diffView.scope.selectorAria"),e[3]=m,e[4]=T):T=e[4];let ne;e[5]!==v?(ne=n.jsxs("span",{className:"diff-toolbar__scope-count",children:[": ",v]}),e[5]=v,e[6]=ne):ne=e[6];let y;e[7]!==O||e[8]!==ne?(y=n.jsxs("span",{className:"whitespace-nowrap",children:[O,ne]}),e[7]=O,e[8]=ne,e[9]=y):y=e[9];let V;e[10]===Symbol.for("react.memo_cache_sentinel")?(V=n.jsx(A,{name:"arrow-down-s",className:"size-4 flex-shrink-0 opacity-60"}),e[10]=V):V=e[10];let M;e[11]!==T||e[12]!==y?(M=n.jsx(Vn,{asChild:!0,children:n.jsxs("button",{type:"button",className:"flex h-7 flex-shrink-0 items-center gap-1.5 rounded-md px-2 typography-ui-label font-semibold text-foreground outline-none hover:bg-interactive-hover focus-visible:ring-2 focus-visible:ring-ring","aria-label":T,children:[y,V]})}),e[11]=T,e[12]=y,e[13]=M):M=e[13];let q;e[14]!==f?(q=ie=>{(ie==="working"||ie==="staged"||ie==="turn"||ie==="branch")&&(f?.(ie),c(!1))},e[14]=f,e[15]=q):q=e[15];let X;e[16]!==m?(X=m("diffView.scope.changed"),e[16]=m,e[17]=X):X=e[17];let se;e[18]!==X?(se=n.jsx("span",{children:X}),e[18]=X,e[19]=se):se=e[19];let J;e[20]!==a?(J=n.jsx("span",{className:"typography-meta text-muted-foreground",children:a}),e[20]=a,e[21]=J):J=e[21];let Y;e[22]!==J||e[23]!==se?(Y=n.jsx($e,{value:"working",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[se,J]})}),e[22]=J,e[23]=se,e[24]=Y):Y=e[24];let C;e[25]!==m?(C=m("diffView.scope.staged"),e[25]=m,e[26]=C):C=e[26];let _;e[27]!==C?(_=n.jsx("span",{children:C}),e[27]=C,e[28]=_):_=e[28];let re;e[29]!==d?(re=n.jsx("span",{className:"typography-meta text-muted-foreground",children:d}),e[29]=d,e[30]=re):re=e[30];let L;e[31]!==_||e[32]!==re?(L=n.jsx($e,{value:"staged",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[_,re]})}),e[31]=_,e[32]=re,e[33]=L):L=e[33];let G;e[34]!==m?(G=m("diffView.scope.lastTurn"),e[34]=m,e[35]=G):G=e[35];let $;e[36]!==G?($=n.jsx("span",{children:G}),e[36]=G,e[37]=$):$=e[37];let E;e[38]!==u?(E=n.jsx("span",{className:"typography-meta text-muted-foreground",children:u}),e[38]=u,e[39]=E):E=e[39];let K;e[40]!==$||e[41]!==E?(K=n.jsx($e,{value:"turn",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[$,E]})}),e[40]=$,e[41]=E,e[42]=K):K=e[42];let Q;e[43]!==p||e[44]!==g||e[45]!==m?(Q=g?n.jsx($e,{value:"branch",children:n.jsxs("span",{className:"flex min-w-0 flex-1 items-center justify-between gap-3",children:[n.jsx("span",{children:m("diffView.scope.branch")}),n.jsx("span",{className:"typography-meta text-muted-foreground",children:p??"…"})]})}):null,e[43]=p,e[44]=g,e[45]=m,e[46]=Q):Q=e[46];let z;e[47]!==i||e[48]!==Y||e[49]!==L||e[50]!==K||e[51]!==Q||e[52]!==q?(z=n.jsx(Ln,{align:"start",className:"w-40",children:n.jsxs(Tn,{value:i,onValueChange:q,children:[Y,L,K,Q]})}),e[47]=i,e[48]=Y,e[49]=L,e[50]=K,e[51]=Q,e[52]=q,e[53]=z):z=e[53];let H;return e[54]!==x||e[55]!==z||e[56]!==M?(H=n.jsxs(Mn,{open:x,onOpenChange:c,children:[M,z]}),e[54]=x,e[55]=z,e[56]=M,e[57]=H):H=e[57],H}),gs=o.memo(s=>{const e=be.c(11),{changedFiles:i,selectedFile:a,onSelectFile:d}=s,{t:u}=we();if(i.length===0)return null;let p;if(e[0]!==i||e[1]!==d||e[2]!==a||e[3]!==u){let f;e[5]!==d||e[6]!==a||e[7]!==u?(f=m=>{const x=Tt(m),c=a===m.path;return n.jsx("li",{children:n.jsxs("button",{type:"button",onClick:()=>d(m.path),className:le("flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left transition-colors",c?"bg-interactive-selection text-interactive-selection-foreground":"text-muted-foreground hover:bg-interactive-hover hover:text-foreground"),children:[n.jsx(Vt,{filePath:m.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:x.color},title:u(x.descriptionKey),"aria-label":u(x.descriptionKey),children:x.code}),n.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left",unicodeBidi:"plaintext"},title:m.path,children:m.path}),Mt(m.insertions,m.deletions)]})},m.path)},e[5]=d,e[6]=a,e[7]=u,e[8]=f):f=e[8],p=i.map(f),e[0]=i,e[1]=d,e[2]=a,e[3]=u,e[4]=p}else p=e[4];let g;return e[9]!==p?(g=n.jsx(it,{outerClassName:"flex-1 min-h-0",className:"px-2 py-2",children:n.jsx("ul",{className:"flex flex-col gap-1",children:p})}),e[9]=p,e[10]=g):g=e[10],g}),xs=o.memo(s=>{const e=be.c(20),{filePath:i,diff:a,renderSideBySide:d}=s,{t:u}=we(),p=a.original.length>0,g=a.modified.length>0,f=d?"flex flex-row gap-6 items-start justify-center":"flex flex-col gap-4 items-center",m=d?"flex flex-col items-center gap-2 flex-1 min-w-0":"flex flex-col items-center gap-2";let x;e[0]===Symbol.for("react.memo_cache_sentinel")?(x={contain:"layout"},e[0]=x):x=e[0];let c;e[1]!==a.original||e[2]!==i||e[3]!==p||e[4]!==m||e[5]!==d||e[6]!==u?(c=p&&n.jsxs("div",{className:m,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:u("diffView.image.original")}),n.jsx("img",{src:a.original,alt:u("diffView.image.originalAlt",{path:i}),className:d?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[1]=a.original,e[2]=i,e[3]=p,e[4]=m,e[5]=d,e[6]=u,e[7]=c):c=e[7];let v;e[8]!==a.modified||e[9]!==i||e[10]!==g||e[11]!==p||e[12]!==m||e[13]!==d||e[14]!==u?(v=g&&n.jsxs("div",{className:m,children:[n.jsx("span",{className:"typography-meta text-muted-foreground font-medium",children:u(p?"diffView.image.modified":"diffView.image.new")}),n.jsx("img",{src:a.modified,alt:u("diffView.image.modifiedAlt",{path:i}),className:d?"max-w-full max-h-[70vh] object-contain":"max-w-full object-contain",style:{imageRendering:"auto"}})]}),e[8]=a.modified,e[9]=i,e[10]=g,e[11]=p,e[12]=m,e[13]=d,e[14]=u,e[15]=v):v=e[15];let S;return e[16]!==f||e[17]!==c||e[18]!==v?(S=n.jsx("div",{className:"w-full overflow-auto p-4",style:x,children:n.jsxs("div",{className:f,children:[c,v]})}),e[16]=f,e[17]=c,e[18]=v,e[19]=S):S=e[19],S}),bs=o.memo(s=>{const e=be.c(16),{filePath:i,diff:a,renderSideBySide:d,wrapLines:u}=s;let p;e[0]!==i?(p=Bn(i)||"text",e[0]=i,e[1]=p):p=e[1];const g=p;if(a.isBinary){let x;return e[2]===Symbol.for("react.memo_cache_sentinel")?(x=n.jsx(as,{}),e[2]=x):x=e[2],x}if(Be(i)){let x;return e[3]!==a||e[4]!==i||e[5]!==d?(x=n.jsx(xs,{filePath:i,diff:a,renderSideBySide:d}),e[3]=a,e[4]=i,e[5]=d,e[6]=x):x=e[6],x}let f;e[7]===Symbol.for("react.memo_cache_sentinel")?(f={contain:"layout"},e[7]=f):f=e[7];let m;return e[8]!==a.fileDiff||e[9]!==a.modified||e[10]!==a.original||e[11]!==i||e[12]!==g||e[13]!==d||e[14]!==u?(m=n.jsx("div",{className:"w-full",style:f,children:n.jsx(On,{original:a.original,modified:a.modified,fileDiff:a.fileDiff,language:g,fileName:i,renderSideBySide:d,wrapLines:u,layout:"inline"})}),e[8]=a.fileDiff,e[9]=a.modified,e[10]=a.original,e[11]=i,e[12]=g,e[13]=d,e[14]=u,e[15]=m):m=e[15],m}),ws=o.memo(s=>{const e=be.c(7),{filePath:i,staged:a,busyAction:d,disabled:u,onAction:p}=s,{t:g}=we();let f;return e[0]!==d||e[1]!==u||e[2]!==i||e[3]!==p||e[4]!==a||e[5]!==g?(f=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:a?n.jsx(rt,{label:g("gitView.changes.unstageFileAria",{path:i}),icon:"arrow-go-back",loading:d==="unstage",disabled:u,onClick:()=>p("unstage")}):n.jsxs(n.Fragment,{children:[n.jsx(rt,{label:g("gitView.changes.revertFileAria",{path:i}),icon:"arrow-go-back",loading:d==="discard",disabled:u,tone:"failure",onClick:()=>p("discard")}),n.jsx(rt,{label:g("gitView.changes.stageFileAria",{path:i}),icon:"add",loading:d==="stage",disabled:u,tone:"success",onClick:()=>p("stage")})]})}),e[0]=d,e[1]=u,e[2]=i,e[3]=p,e[4]=a,e[5]=g,e[6]=f):f=e[6],f}),rt=s=>{const e=be.c(14),{label:i,icon:a,loading:d,disabled:u,tone:p,onClick:g}=s,f=p==="failure"&&"text-[var(--status-error)] hover:text-[var(--status-error)]",m=p==="success"&&"text-[var(--status-success)] hover:text-[var(--status-success)]";let x;e[0]!==f||e[1]!==m?(x=le("h-6 w-6 rounded-none bg-transparent p-0 text-muted-foreground opacity-70 hover:bg-transparent hover:text-foreground hover:opacity-100",f,m),e[0]=f,e[1]=m,e[2]=x):x=e[2];let c;e[3]!==g?(c=O=>{O.stopPropagation(),g()},e[3]=g,e[4]=c):c=e[4];let v;e[5]!==a||e[6]!==d?(v=d?n.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(A,{name:a,className:a==="add"?"size-4":"size-3.5"}),e[5]=a,e[6]=d,e[7]=v):v=e[7];let S;return e[8]!==u||e[9]!==i||e[10]!==x||e[11]!==c||e[12]!==v?(S=n.jsx(me,{variant:"ghost",size:"sm",className:x,disabled:u,title:i,"aria-label":i,onClick:c,children:v}),e[8]=u,e[9]=i,e[10]=x,e[11]=c,e[12]=v,e[13]=S):S=e[13],S},ys=o.memo(({directory:s,file:e,layout:i,wrapLines:a,isSelected:d,isExpanded:u,isMounted:p,onSelect:g,onExpandedChange:f,registerSectionRef:m,showOpenInEditorAction:x=!1,isOpeningInEditor:c=!1,onOpenInEditor:v,staged:S=!1,loadFullFiles:O=!1,initialDiffData:T=null,readOnlyActions:ne=!1})=>{const{t:y}=we(),{git:V}=Et(),M=ae(o.useCallback(w=>w.directories.get(s)?.diffCache.get(e.path)??null,[s,e.path])),q=ae(w=>w.setDiff),X=ae(w=>w.fetchStatus),se=te(w=>w.setDiffFileLayout),[J,Y]=o.useState(0),[C,_]=o.useState(null),[re,L]=o.useState(!1),[G,$]=o.useState(null),[E,K]=o.useState(!1),[Q,z]=o.useState(null),[H,ie]=o.useState(null),ce=o.useRef(null),Ce=o.useRef(null),pe=o.useMemo(()=>Tt(e),[e]),Ve=i==="side-by-side",ye=O?"full":"patch",he=`${e.index}:${e.working_dir}:${e.insertions}:${e.deletions}`,Z=o.useMemo(()=>T||(S?H:Q||(M?{original:M.original,modified:M.modified,isBinary:M.isBinary,contextMode:"full"}:null)),[M,T,Q,S,H]),De=Z?.contextMode===ye,b=o.useCallback(w=>{Ce.current=w,m(e.path,w)},[e.path,m]),ge=o.useCallback(w=>{f(e.path,w)},[e.path,f]),fe=o.useCallback(()=>{g(e.path)},[e.path,g]);o.useEffect(()=>{S?ie(null):z(null),_(null),ce.current=null},[he,S]),o.useEffect(()=>{if(!u||!p)return;if(!s||T||Z&&De){ce.current=null,L(!1);return}const w=`${s}::${e.path}::${S?"staged":"unstaged"}::${he}::${ye}::${J}`;if(ce.current===w)return;ce.current=w,_(null),L(!0);let D=!1;const de=at(),Le=O?ns:ss,Te=Be(e.path)?V.getGitFileDiff(s,{path:e.path,staged:S}):V.getGitDiff(s,{path:e.path,staged:S,contextLines:Le}),Me=ts,_e=new Promise((B,W)=>{setTimeout(()=>W(new Error(`Timed out after ${Me}ms`)),Me)});return Promise.race([Te,_e]).then(B=>{if(!D){if("diff"in B){const W=ot(e.path,B.diff,ye);S?ie(W):z(W)}else{const W={original:B.original??"",modified:B.modified??"",isBinary:B.isBinary,contextMode:"full"};S?ie(W):q(s,e.path,W,de)}L(!1)}}).catch(B=>{if(D)return;const W=B instanceof Error?B.message:String(B);_(W),L(!1)}),()=>{D=!0,ce.current===w&&(ce.current=null)}},[ye,Z,De,J,s,e.path,he,V,T,u,p,O,q,S]);const Re=o.useCallback(()=>{ge(!u),fe()},[ge,fe,u]),ue=o.useCallback(async w=>{if(!(!s||G!==null)){$(w);try{w==="stage"?await V.stageGitFile(s,e.path):w==="unstage"?await V.unstageGitFile(s,e.path):await V.revertGitFile(s,e.path,{scope:"working"}),Y(D=>D+1),await X(s,V)}catch(D){const de=w==="unstage"?"gitView.toast.unstageFileFailed":w==="stage"?"gitView.toast.stageFileFailed":"gitView.toast.revertFailed";Ke.error(D instanceof Error?D.message:y(de))}finally{$(D=>D===w?null:D)}}},[s,X,e.path,G,V,y]);return n.jsxs("div",{ref:b,className:"scroll-mt-9 border-b border-[var(--interactive-border)]/40 last:border-b-0",children:[n.jsx("div",{className:"sticky top-0 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",children:n.jsxs("div",{role:"button",tabIndex:0,onClick:Re,onKeyDown:w=>{w.target===w.currentTarget&&(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),Re())},className:le("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",d?"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:u?n.jsx(A,{name:"arrow-down-s",className:"size-4"}):n.jsx(A,{name:"arrow-right-s",className:"size-4"})}),n.jsx("span",{className:"typography-micro font-semibold leading-none w-4 text-center uppercase",style:{color:pe.color},title:y(pe.descriptionKey),"aria-label":y(pe.descriptionKey),children:pe.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(Vt,{filePath:e.path,className:"h-3.5 w-3.5 flex-shrink-0 align-middle"}),(()=>{const w=e.path.lastIndexOf("/");if(w===-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 D=e.path.slice(0,w),de=e.path.slice(w+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:D}),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:de})]})]})})()]})})]}),n.jsxs("div",{className:"relative flex shrink-0 items-center justify-self-end gap-2",children:[Mt(e.insertions,e.deletions),x&&v?n.jsx(me,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0 opacity-70 hover:opacity-100",title:y("diffView.actions.openFileInEditorAtChange"),onClick:w=>{w.stopPropagation(),v(e.path,Z)},disabled:c,children:c?n.jsx(A,{name:"loader-4",className:"size-3.5 animate-spin"}):n.jsx(A,{name:"edit",className:"size-3.5"})}):null,n.jsx(Bt,{mode:Ve?"side-by-side":"unified",onModeChange:w=>{const D=w==="side-by-side"?"side-by-side":"inline";se(e.path,D)},className:"opacity-70"})]})]})}),u&&n.jsxs("div",{className:"relative bg-background overflow-hidden",children:[!p&&!C?n.jsx("div",{className:"h-40 border border-border/40 bg-background/40"}):null,C?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:y("diffView.state.failedToLoadDiff")}),n.jsx("div",{className:"typography-meta text-muted-foreground max-w-[32rem] text-center",children:C}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>Y(w=>w+1),children:y("diffView.actions.retry")})]}):null,p&&re&&!Z&&!C?n.jsxs("div",{className:"flex items-center justify-center gap-2 px-4 py-8 text-sm text-muted-foreground",children:[n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),y("diffView.state.loadingDiff")]}):null,p&&Z&&!E&&e.insertions+e.deletions>Ft?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:y("diffView.state.largeDiff",{count:e.insertions+e.deletions})}),n.jsx("div",{className:"typography-meta text-muted-foreground",children:y("diffView.state.largeDiffDescription")}),n.jsx("button",{type:"button",className:"typography-ui-label text-primary hover:underline",onClick:()=>K(!0),children:y("diffView.actions.renderAnyway")})]}):null,p&&Z&&(E||e.insertions+e.deletions<=Ft)?n.jsxs(n.Fragment,{children:[n.jsx(bs,{filePath:e.path,diff:Z,renderSideBySide:Ve,wrapLines:a}),n.jsx("div",{className:"pointer-events-none absolute bottom-3 right-3 z-20",children:n.jsx("div",{className:"pointer-events-auto",children:ne?null:n.jsx(ws,{filePath:e.path,staged:S,busyAction:G,disabled:G!==null,onAction:ue})})})]}):null]})]})}),Mi=({hideStackedFileSidebar:s=!1,stackedDefaultCollapsedAll:e=!1,pinSelectedFileHeaderToTopOnNavigate:i=!1,showOpenInEditorAction:a=!1,diffScope:d="all",onDiffScopeChange:u,targetFilePath:p=null,flushContent:g=!1})=>{const{t:f}=we(),{git:m,files:x}=Et(),c=hn(),v=te(t=>t.openContextSurface),S=zn(t=>t.requestSource),{screenWidth:O,isMobile:T}=gn(),ne=xn(c??null),y=bn(c??null),V=wn(c??null),M=ae(t=>t.setActiveDirectory),q=ae(t=>t.ensureStatus),X=ae(t=>t.fetchStatus),se=ae(t=>t.fetchBranches),J=ae(t=>t.clearDiffCache),Y=ae(t=>t.setDiff),[C,_]=o.useState(null),[re,L]=o.useState(!1),[G,$]=o.useState(null),[E,K]=o.useState(()=>new Set),[Q,z]=o.useState(()=>new Set),[H,ie]=o.useState(!1),[ce,Ce]=o.useState(0),[pe,Ve]=o.useState(()=>new Map),[ye,he]=o.useState(!1),[Z,De]=o.useState(!1),[b,ge]=o.useState(d);o.useEffect(()=>{ge(d)},[d]);const fe=te(t=>t.pendingDiffFile),Re=te(t=>t.pendingDiffStaged),ue=te(t=>t.pendingDiffScope),w=te(t=>t.setPendingDiffFile),D=te(t=>t.diffLayoutPreference),de=te(t=>t.diffFileLayout),Le=te(t=>t.setDiffFileLayout),Te=te(t=>t.diffWrapLines),Me=te(t=>t.setDiffWrapLines),_e=te(t=>t.openContextFileAtLine),B=vt(t=>t.currentSessionId),W=yn(B??"",c??void 0),We=Te,Ue=b==="staged"?!0:b==="working"?!1:null,Ie=Ue??re,qe=T||O<=768,_t=!!B&&b!=="turn"&&!qe&&!Ge(),It=b!=="turn"&&!qe&&!Ge(),Ot=!s&&!qe&&O>=1024,ve=o.useRef(null),Ae=o.useRef(new Map),xe=o.useRef(null),P=o.useRef(null),je=o.useRef(!1),Se=o.useRef(null),lt=o.useRef(null),Xe=o.useRef(null),Je=o.useRef(null),ct=o.useCallback(()=>{const t=ve.current;if(!t)return null;const r=t.getBoundingClientRect().top,l=[];for(const[h,j]of Ae.current)j&&l.push({path:h,top:j.getBoundingClientRect().top});return St(r,l)},[]),Ne=o.useCallback(()=>{xe.current=null,je.current=!1,$(null),P.current!==null&&(window.cancelAnimationFrame(P.current),P.current=null)},[]),Fe=o.useCallback(t=>{K(r=>{if(r.has(t))return r;const l=new Set(r);return l.add(t),l})},[]),Ee=o.useMemo(()=>{for(let t=W.length-1;t>=0;t-=1){const r=W[t];if(r.role==="user")return ms(r.summary?.diffs)}return[]},[W]),zt=o.useMemo(()=>{const t=new Map;for(const r of Ee)if(r.file){if(typeof r.patch=="string"){t.set(r.file,ot(r.file,r.patch,"patch"));continue}t.set(r.file,{original:r.before??"",modified:r.after??"",contextMode:"full"})}return t},[Ee]),Pt=o.useMemo(()=>y?.files?y.files.filter(Dt).length:0,[y]),Gt=o.useMemo(()=>y?.files?y.files.filter(Ct).length:0,[y]),$t=Ee.length,k=y?.current??null,ke=ae(t=>c?t.directories.get(c)?.branches??null:null),Kt=ae(t=>c?t.directories.get(c)?.isLoadingBranches??!1:!1),Ht=o.useCallback(()=>{c&&se(c,m)},[c,se,m]),Wt=Yn(c??null,ne!==!1,Kt,!!ke,Ht,os),ft=o.useMemo(()=>{const t=y?.tracking?.trim().split("/")[0];return(t&&ke?.defaultBranches?.[t])??ke?.defaultBranches?.origin??null},[ke,y?.tracking]),Ye=!Ge()&&Un(k,ft),Ut=y!==null,ut=Ge()||Wt||qn(k,ft,Ut,ke!==null),qt=jt(t=>t.setOverride),Xt=jt(o.useCallback(t=>c&&k?t.overrides[He(c,k)]??null:null,[k,c])),[Jt,Qe]=o.useState(null),[Yt,Ze]=o.useState(!1),[dt,Qt]=o.useState("");o.useEffect(()=>{const t=Xn(b,!ut);t!==b&&(ge(t),t==="working"&&u?.("working"))},[b,ut,u]),o.useEffect(()=>{if(!Ye||!c||!k){Qe(null),Ze(!1);return}let t=!1;return Ze(!1),vn(c,k).then(r=>{t||Qe(r.base)}).catch(()=>{t||Qe(null)}).finally(()=>{t||Ze(!0)}),()=>{t=!0}},[k,c,Ye]);const oe=Xt??Jt,[Oe,mt]=o.useState(null),[pt,ht]=o.useState(null),ze=o.useRef(0),et=o.useCallback(()=>{if(!c||!k||!oe)return;const t=ze.current+1;ze.current=t,mt(null),ht(null),jn(c,{base:oe,head:k}).then(r=>{ze.current===t&&mt(r)}).catch(r=>{ze.current===t&&ht(r instanceof Error?r.message:f("diffView.branch.loadError"))})},[oe,k,c,f]);o.useEffect(()=>{b==="branch"&&et()},[b,et]);const gt=b==="branch"&&c&&k&&oe?Jn(c,oe,k):null,Zt=o.useMemo(()=>b==="branch"?Array.from(E).sort().join("\0"):"",[b,E]),en=o.useCallback(t=>!c||!oe||!k?Promise.reject(new Error("branch range is unavailable")):Sn(c,{base:oe,head:k,path:t}).then(r=>ot(t,r.diff,"patch")),[oe,k,c]),tn=Qn(gt,Zt,gt?en:null,is),nn=Oe?.length??null,N=o.useMemo(()=>{if(b==="branch")return(Oe??[]).map(l=>({path:l.path,index:"",working_dir:l.status,insertions:0,deletions:0,isNew:l.status==="A"})).sort((l,h)=>l.path.localeCompare(h.path));if(b==="turn")return Ee.map(l=>({path:l.file??"",index:"",working_dir:ps(l.status),insertions:l.additions??0,deletions:l.deletions??0,isNew:l.status==="added"})).filter(l=>l.path).sort((l,h)=>l.path.localeCompare(h.path));if(!y?.files)return[];const t=y.diffStats??{},r=b==="staged"?Ct:b==="working"?Dt:()=>!0;return y.files.filter(r).map(l=>({...l,insertions:t[l.path]?.insertions??0,deletions:t[l.path]?.deletions??0,isNew:fs(l)})).sort((l,h)=>l.path.localeCompare(h.path))},[b,Oe,Ee,y]),tt=o.useMemo(()=>N.map(t=>t.path).join("\0"),[N]);o.useEffect(()=>{const t=tt?tt.split("\0"):[],r=new Set(t),l=`${c??""}:${b}:${e?"collapsed":"default"}`,h=lt.current!==l;lt.current=l,K(j=>{if(h){const R=e?0:rs(t.length);return new Set(t.slice(0,R))}let I=!1;const F=new Set;for(const R of j){if(!r.has(R)){I=!0;continue}F.add(R)}return I?F:j}),z(j=>{if(h)return new Set;let I=!1;const F=new Set;for(const R of j){if(!r.has(R)){I=!0;continue}F.add(R)}return I?F:j})},[b,tt,c,e]);const xt=o.useCallback(()=>{Se.current=null;const t=ve.current;if(!t)return;const r=t.getBoundingClientRect(),l=r.top-kt,h=r.bottom+kt,j={},I=[];for(const[F,R]of Ae.current){if(!R)continue;const U=R.getBoundingClientRect();I.push({path:F,top:U.top}),E.has(F)&&(U.bottom<l||U.top>h||(j[F]=!0))}Xe.current=St(r.top,I),z(F=>{let R=!1;const U=new Set(F);for(const yt of Object.keys(j))U.has(yt)||(U.add(yt),R=!0);return R?U:F})},[E]),ee=o.useCallback(()=>{typeof window>"u"||Se.current===null&&(Se.current=window.requestAnimationFrame(xt))},[xt]);o.useEffect(()=>{const t=ve.current;if(t)return ee(),t.addEventListener("scroll",ee,{passive:!0}),window.addEventListener("resize",ee),()=>{t.removeEventListener("scroll",ee),window.removeEventListener("resize",ee),Se.current!==null&&(window.cancelAnimationFrame(Se.current),Se.current=null)}},[N,E,ee]);const nt=o.useCallback(t=>{const r=de[t.path];if(r)return r;if(D==="inline")return"inline";if(D==="side-by-side")return"side-by-side";const l=O<es;return t.isNew||l?"inline":"side-by-side"},[de,D,O]),bt=o.useMemo(()=>N.length===0?null:N.every(t=>nt(t)==="side-by-side")?"side-by-side":"inline",[N,nt]);o.useEffect(()=>{c&&(M(c),q(c,m))},[c,M,q,m]),o.useEffect(()=>{if(c)return Nn.onGitRefreshHint(t=>{Rt(t.directory)===Rt(c)&&(t.paths?.length&&(Je.current=ct()??Xe.current,J(c,t.paths),Ve(r=>{const l=new Map(r);for(const h of t.paths??[])l.set(h,(l.get(h)??0)+1);return l})),X(c,m,{silent:!0}))})},[ct,J,c,X,m]),o.useLayoutEffect(()=>{const t=Je.current;if(!t)return;Je.current=null;const r=ve.current,l=Ae.current.get(t.path);if(!r||!l)return;const h=r.getBoundingClientRect().top,j=l.getBoundingClientRect().top-h;r.scrollTop=Zn(r.scrollTop,t.topOffset,j,r.scrollHeight-r.clientHeight),Xe.current=t},[pe]),o.useEffect(()=>{b!=="all"&&!ue||fe&&(ue&&ge(ue),_(fe),L(ue==="staged"||!ue&&Re),w(null),je.current=!0,xe.current=fe,Fe(fe),Ce(t=>t+1))},[b,Fe,fe,ue,Re,w]),o.useEffect(()=>{if(b==="all")return;const t=p?.trim();t&&(_(t),L(b==="staged"),je.current=!0,xe.current=t,Fe(t),Ce(r=>r+1))},[b,Fe,p]),o.useEffect(()=>{if(!C)return;N.some(r=>r.path===C)||(_(null),L(!1))},[N,C]);const sn=o.useCallback((t,r)=>{const l=Ae.current;r?l.set(t,r):l.delete(t),ee()},[ee]),rn=o.useCallback((t,r)=>{Ne(),K(l=>{const h=l.has(t);if(r===h)return l;const j=new Set(l);return r?j.add(t):j.delete(t),j}),r||z(l=>{if(!l.has(t))return l;const h=new Set(l);return h.delete(t),h}),ee()},[Ne,ee]),on=o.useCallback(()=>{Ne(),K(t=>t.size>0?new Set:new Set(N.map(r=>r.path))),z(new Set),ee()},[Ne,N,ee]),an=o.useCallback(async t=>{if(!B)return;const r=vt.getState().getDirectoryForSession(B)||c||"";if(!r){Ke.error(f("diffView.reviewDialog.toast.noSessionDirectory"));return}De(!0);try{await Fn({originalSessionID:B,directory:r,providerID:t.providerID,modelID:t.modelID,agent:t.agent||void 0,variant:t.variant||void 0,generateHandoff:t.generateHandoff,returnAfterHandoffRequest:t.generateHandoff,autoReview:t.autoReview}),he(!1)}catch(l){console.error("[review-flow] failed to start review flow",l),Ke.error(l instanceof Error?l.message:f("diffView.reviewDialog.toast.startFailed"))}finally{De(!1)}},[B,c,f]),Pe=o.useCallback(t=>{const r=Ae.current.get(t),l=ve.current;if(!r||!l)return!1;const h=r.getBoundingClientRect().top-l.getBoundingClientRect().top;return l.scrollTo({top:l.scrollTop+h,behavior:"auto"}),!0},[]);o.useEffect(()=>{if(!xe.current)return;let r=0;const l=20;let h=!1;const j=(F=!0)=>{h||(h=!0,xe.current=null,je.current=!1,F&&$(null),P.current!==null&&(window.cancelAnimationFrame(P.current),P.current=null))},I=()=>{if(h){P.current=null;return}const F=xe.current;if(!F){j(),P.current=null;return}if(!Pe(F)){r+=1,r<l?P.current=window.requestAnimationFrame(I):(j(),P.current=null);return}if(i&&je.current){$(F),j(!1);return}j()};return P.current=window.requestAnimationFrame(I),()=>{h=!0,P.current!==null&&(window.cancelAnimationFrame(P.current),P.current=null)}},[i,ce,Pe]);const ln=o.useCallback(t=>{},[]),st=o.useCallback(t=>{Ne(),_(t),L(!1),je.current=!0,xe.current=t,Fe(t),Ce(r=>r+1),Pe(t)},[Ne,Fe,Pe]);o.useEffect(()=>{const t=r=>{if(!r.altKey||r.metaKey||r.ctrlKey||r.shiftKey||r.key!=="ArrowDown"&&r.key!=="ArrowUp")return;const l=r.target;if(l instanceof HTMLElement&&(l.isContentEditable||l.tagName==="INPUT"||l.tagName==="TEXTAREA"||l.closest('[role="dialog"]'))||N.length===0)return;const h=r.key==="ArrowDown"?1:-1,j=C?N.findIndex(R=>R.path===C):-1,I=j===-1?h>0?0:N.length-1:j+h,F=N[I];F&&(r.preventDefault(),st(F.path))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[N,C,st]);const cn=o.useCallback(t=>{const r=t==="side-by-side"?"side-by-side":"inline";N.forEach(l=>{Le(l.path,r)})},[N,Le]),[fn,wt]=o.useState(null),un=o.useCallback(async(t,r)=>{if(!c||!t)return;wt(t);const l=at();try{let h=null;if(r?.patch&&!r.isBinary&&!Be(t)?h=Nt(r.patch):r&&r.contextMode==="full"&&!r.isBinary&&!Be(t)&&(h=At(r.original,r.modified)),h===null)try{const U=await m.getGitDiff(c,{path:t,staged:Ie,contextLines:3});h=Nt(U.diff)}catch{h=null}let j=r;if(h===null||!j){const U=await m.getGitFileDiff(c,{path:t,staged:Ie});j={original:U.original??"",modified:U.modified??"",isBinary:U.isBinary},Ie||Y(c,t,j,l)}const I=h??(j.isBinary||Be(t)?1:At(j.original,j.modified)),F=us(c,t),R=await Pn(x,F,{directory:c});if(!R.ok){Ke.error(Gn(R.reason));return}_e(c,F,I,1)}finally{wt(h=>h===t?null:h)}},[Ie,c,x,m,_e,Y]),dn=()=>{if(!c)return null;const t=r=>Ue!==null?Ue:re&&r===C;return n.jsxs("div",{className:le("flex min-w-0 flex-1 min-h-0 h-full",g?"gap-0":"gap-3 px-3 pb-3 pt-2"),children:[Ot&&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:f("diffView.section.files")}),n.jsx("span",{className:"typography-meta text-muted-foreground",children:N.length})]}),n.jsx(gs,{changedFiles:N,selectedFile:null,onSelectFile:st})]}),n.jsx("div",{className:"relative flex-1 min-w-0 min-h-0 h-full",children:n.jsx(it,{ref:ve,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:N.map(r=>n.jsx(ys,{directory:c,file:r,layout:nt(r),wrapLines:We,isSelected:!1,isExpanded:E.has(r.path),isMounted:Q.has(r.path)||r.path===G,onSelect:ln,onExpandedChange:rn,registerSectionRef:sn,showOpenInEditorAction:a&&b!=="turn",isOpeningInEditor:fn===r.path,onOpenInEditor:(l,h)=>{un(l,h)},staged:t(r.path),loadFullFiles:H,readOnlyActions:b==="branch",initialDiffData:b==="turn"?zt.get(r.path)??null:b==="branch"?tn.get(r.path)??null:null},`${r.path}:${pe.get(r.path)??0}`))})})})]})},mn=()=>{if(!c)return n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:f("diffView.state.selectSessionDirectory")});if(b!=="turn"&&V&&!y)return n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),f("diffView.state.loadingRepositoryStatus")]});if(b!=="turn"&&ne===!1)return n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:f("diffView.state.notGitRepository")});if(b==="branch"){if(!Yt)return n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),f("diffView.branch.resolvingBase")]});if(!oe){const t=(ke?.all??[]).map(l=>l.replace(/^remotes\//,"")).filter(l=>l!==k&&!l.endsWith(`/${k}`)).sort(),r=En(t,dt,l=>[l]);return n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[n.jsx(A,{name:"git-branch",className:"size-6 text-muted-foreground"}),n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:f("diffView.branch.noBaseTitle")}),n.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:f("diffView.branch.noBaseDescription")}),n.jsx("input",{type:"text",value:dt,onChange:l=>Qt(l.target.value),placeholder:f("gitView.branch.searchPlaceholder"),"aria-label":f("gitView.branch.searchPlaceholder"),className:"w-full max-w-sm rounded-md border border-border/60 bg-[var(--surface-elevated)] px-2.5 py-1.5 typography-meta text-foreground outline-none placeholder:text-muted-foreground focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]"}),n.jsx(it,{outerClassName:"max-h-48 w-full max-w-sm min-h-0",className:"px-1 py-1",children:r.length===0?n.jsx("div",{className:"px-2 py-3 typography-meta text-muted-foreground",children:f("gitView.branch.empty")}):n.jsx("div",{className:"flex flex-col gap-0.5",children:r.map(l=>n.jsxs("button",{type:"button",onClick:()=>c&&k&&qt(c,k,l),className:"flex items-center gap-2 rounded-md px-2 py-1.5 text-left hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--interactive-focus-ring)]",children:[n.jsx(A,{name:"git-branch",className:"size-3.5 text-primary"}),n.jsx("span",{className:"truncate typography-ui-label text-foreground",title:l,children:l})]},l))})})]})}if(pt)return n.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[n.jsx("div",{className:"typography-ui-label font-semibold text-foreground",children:f("diffView.branch.loadError")}),n.jsx("div",{className:"max-w-sm typography-micro text-muted-foreground",children:pt}),n.jsx(me,{variant:"outline",size:"sm",onClick:()=>et(),children:f("diffView.actions.retry")})]});if(Oe===null)return n.jsxs("div",{className:"flex flex-1 items-center justify-center gap-2 text-sm text-muted-foreground",children:[n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}),f("diffView.branch.loadingFiles")]})}return N.length===0?n.jsx("div",{className:"flex flex-1 items-center justify-center text-sm text-muted-foreground",children:b==="turn"?f("diffView.state.noLastTurnChanges"):b==="branch"&&oe?f("diffView.branch.empty",{base:oe}):f("diffView.state.cleanWorkingTree")}):dn()};return n.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-background",children:[n.jsxs("div",{className:"@container/diff-toolbar flex min-w-0 items-center gap-2 px-3 py-2 bg-background",children:[!T&&(b==="working"||b==="staged"||b==="turn"||b==="branch"?n.jsx(hs,{scope:b,workingCount:Pt,stagedCount:Gt,turnCount:$t,branchCount:nn,showBranchOption:Ye,onScopeChange:t=>{ge(t),u?.(t)}}):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:V&&!y?f("diffView.state.loadingChanges"):N.length===1?f("diffView.summary.changedFilesSingle",{count:N.length}):f("diffView.summary.changedFilesPlural",{count:N.length})})})),N.length>0&&n.jsxs(me,{variant:"ghost",size:"sm",onClick:on,className:le("diff-toolbar__expand-button h-7 flex-shrink-0 gap-1 px-1.5 text-muted-foreground hover:text-foreground","ml-auto"),title:E.size>0?f("diffView.actions.collapseAll"):f("diffView.actions.expandAll"),children:[n.jsx(A,{name:"expand-up-down",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__expand-label typography-ui-label",children:E.size>0?f("diffView.actions.collapseAll"):f("diffView.actions.expandAll")})]}),N.length>0&&_t&&n.jsxs(me,{variant:"default",size:"sm",onClick:()=>he(!0),disabled:Z,className:"diff-toolbar__review-button h-7 flex-shrink-0 gap-1.5 px-2","aria-label":f("diffView.actions.reviewAria"),children:[Z?n.jsx(A,{name:"loader-4",className:"size-4 animate-spin"}):n.jsx(A,{name:"search-eye",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__review-label typography-ui-label",children:f("diffView.actions.review")})]}),N.length>0&&It&&n.jsxs(me,{variant:"outline",size:"sm",onClick:()=>{const t=c??"";S(t,{kind:"working-tree",scope:b==="staged"||b==="working"?b:"all"}),v(t,"walkthrough")},className:le("diff-toolbar__walkthrough-button h-7 flex-shrink-0 gap-1.5 px-2",$n),"aria-label":f("walkthrough.action.open"),children:[n.jsx(A,{name:"route",className:"size-4"}),n.jsx("span",{className:"diff-toolbar__walkthrough-label typography-ui-label",children:f("walkthrough.action.open")})]}),N.length>0&&n.jsxs(kn,{children:[n.jsx(Cn,{asChild:!0,children:n.jsx(me,{variant:"ghost",size:"sm",onClick:()=>ie(t=>!t),"aria-pressed":H,"aria-label":f(H?"diffView.actions.disableFullFiles":"diffView.actions.loadFullFiles"),className:le("h-7 w-7 flex-shrink-0 p-0 text-muted-foreground hover:text-foreground",H&&"bg-interactive-selection text-interactive-selection-foreground"),children:n.jsx(A,{name:"file-download",className:"size-4"})})}),n.jsx(Dn,{children:n.jsx("p",{children:f(H?"diffView.actions.disableFullFiles":"diffView.actions.loadFullFiles")})})]}),N.length>0&&n.jsx(me,{variant:"ghost",size:"sm",onClick:()=>Me(!Te),className:le("h-5 w-5 p-0 transition-opacity",We?"text-foreground opacity-100":"text-muted-foreground opacity-60 hover:opacity-100"),title:f(We?"diffView.actions.disableLineWrap":"diffView.actions.enableLineWrap"),children:n.jsx(A,{name:"text-wrap",className:"size-4"})}),bt&&n.jsx(Bt,{mode:bt==="side-by-side"?"side-by-side":"unified",onModeChange:cn})]}),n.jsx(Rn,{open:ye,onOpenChange:he,projectDirectory:c??null,submitting:Z,onConfirm:an}),mn()]})};export{Mi as DiffView};
@@ -0,0 +1,17 @@
1
+ import{f as gt,R as n,c as Nn,j as s,r as nr}from"./vendor-react-BUCujlKS.js";import{Q as aa,R as oa,S as la,T as ca,ak as Cn,n as He,u as ht,d1 as ua,C as Sn,w as da,r as kn,V as Rn,e as fa,c$ as ma,aN as pa,d0 as ha,a as ga}from"./index-DIvDEKE-.js";import{f as Bt,y as Tn,ab as Jn,bQ as xa,h as q,hi as va,fc as wa,S as ss,B as z,I as b,V as ba,L as ya,bo as ja,ac as Fa,c6 as Na,hj as Vn,hk as Ca,gP as Sa,t as Q,l as En,al as ir,c1 as Fs,cB as ka,b as Ra,hl as ar,bD as Ta,am as Dn,hm as Pn,c2 as Mn,c3 as Va,g2 as Ea,hn as Da,ho as Pa,hp as Ma,bE as Qn,bF as Yn,bG as Zn,bH as ei,bI as ti,bJ as si,b2 as fr,a$ as mr,ao as Cs,b1 as pr,a_ as Ss,c0 as or,an as lr,bY as zn,a6 as zt,a7 as At,a8 as Lt,bB as za,bC as Aa,g as Rs,b0 as La,b8 as Ia}from"./useAppFontEffects-KP8_yiGW.js";import{Z as Oa,w as Ba,x as $a,y as Wa,z as _a,A as Ua}from"./runtimeEndpointReset-D6SmNZaP.js";import{c as An,s as Ka,C as Ln,P as cr}from"./shikiHighlight-fGmFkxAM.js";import{a as Ha}from"./vendor-codemirror-state-C9awkmn-.js";import{E as jt}from"./vendor-codemirror-view-CiLROUVV.js";import{J as Ga,F as qa}from"./JsonTreeView-CggOsLot.js";import{ensurePierreThemeRegistered as In,getResolvedShikiTheme as Xa}from"./appThemeRegistry-BK0dHKa6.js";import{V as Ja,W as Qa}from"./Virtualizer-CZlLSacm.js";import{V as Ya}from"./Virtualizer-D_a8gKmg.js";import{u as Ns,c as Za,e as eo}from"./scheduledTasksApi-mjMDet_H.js";import{D as to}from"./vendor-react-drawio-Ct3Q0DsD.js";import{I as so,u as ro,n as no}from"./useInlineCommentController-HIjtuhxD.js";import{b as io}from"./CodeMirrorCommentWidgets-BGj8TJxW.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-zod-BLfBSgBh.js";import"./vendor-opencode-sdk-BJ73u-bH.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-BeMD8X_w.js";import"./vendor-floating-ui-utils-D6FqdtJt.js";import"./vendor-floating-ui-react-dom-DxYCWdHj.js";import"./vendor-floating-ui-dom-BTvzWks8.js";import"./vendor-floating-ui-core-PuGzNPnN.js";import"./vendor-use-sync-external-store-D6wYuSt-.js";import"./contextPanelEmbeddedChat-C9abMBTb.js";import"./vendor-class-variance-authority-5VPnzWs2.js";import"./vendor-clsx-B-dksMZM.js";import"./vendor-dnd-kit-core-BZknOX2w.js";import"./vendor-dnd-kit-utilities-B_MdXhJC.js";import"./vendor-dnd-kit-accessibility-BHxJPORy.js";import"./vendor-dnd-kit-sortable-CsEagZ81.js";import"./vendor-framer-motion-livSKyyV.js";import"./vendor-motion-dom-D_o3BTI3.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./vendor-tanstack-react-virtual-g05Cx3z9.js";import"./vendor-tanstack-virtual-core-Dubg10g5.js";import"./vendor-sonner-DFyL3AvE.js";import"./vendor-cmdk-DgLInKvT.js";import"./vendor-radix-ui-react-dialog-B94Bt2qq.js";import"./vendor-radix-ui-primitive-Dc_FVRD7.js";import"./vendor-radix-ui-react-compose-refs-DcAh5WdT.js";import"./vendor-radix-ui-react-context-Czxm7Z62.js";import"./vendor-radix-ui-react-id-f5BLKEVw.js";import"./vendor-radix-ui-react-use-layout-effect-D_3IhJdJ.js";import"./vendor-radix-ui-react-use-controllable-state-BFT5YmkA.js";import"./vendor-radix-ui-react-dismissable-layer-D7kXcwgJ.js";import"./vendor-radix-ui-react-primitive-DhVoX9SD.js";import"./vendor-radix-ui-react-slot-BQgQOasS.js";import"./vendor-radix-ui-react-use-callback-ref-BZPnuXAC.js";import"./vendor-radix-ui-react-use-escape-keydown-oph88g-F.js";import"./vendor-radix-ui-react-focus-scope-CiaxW4dD.js";import"./vendor-radix-ui-react-portal-BMJYHWck.js";import"./vendor-radix-ui-react-presence-CNxf-uq4.js";import"./vendor-radix-ui-react-focus-guards-B6qJXYua.js";import"./vendor-react-remove-scroll-DO7dCTnK.js";import"./vendor-tslib-De9GV7Vy.js";import"./vendor-react-remove-scroll-bar-BcFYyj3E.js";import"./vendor-react-style-singleton-q6EMHnwf.js";import"./vendor-get-nonce-C-Z93AgS.js";import"./vendor-use-sidecar-zDC0RhA3.js";import"./vendor-use-callback-ref-D3RC8gqK.js";import"./vendor-aria-hidden-DvXkyWUv.js";import"./vendor-codemirror-language-BgPj_McA.js";import"./vendor-lezer-common-B3-cUCR_.js";import"./vendor-lezer-highlight-CDMHUZ74.js";import"./vendor-style-mod-NZ5MEPvj.js";import"./vendor-codemirror-lang-javascript-Cc2ZYbgX.js";import"./vendor-lezer-javascript-D7Tj24ot.js";import"./vendor-lezer-lr-bhwg1HMg.js";import"./vendor-codemirror-autocomplete-DzPz9Wgq.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";import"./vendor-codemirror-lang-json-CMBS2tG9.js";import"./vendor-lezer-json-Iaex0UN-.js";import"./vendor-codemirror-lang-css-O0cZX78y.js";import"./vendor-lezer-css-C5xB6jxd.js";import"./vendor-codemirror-lang-html-CfgK872x.js";import"./vendor-lezer-html-C0I1p52t.js";import"./vendor-codemirror-lang-markdown-BPGOH9ye.js";import"./vendor-lezer-markdown-C6g-d6P3.js";import"./vendor-codemirror-language-data-DrTPkHl4.js";import"./vendor-codemirror-lang-python-HahnQaAS.js";import"./vendor-lezer-python-CvuFxeZl.js";import"./vendor-codemirror-commands-B7H_j0iU.js";import"./vendor-legendapp-list-gg7YLRW7.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./vendor-codemirror-search-BmS-GmcX.js";import"./vendor-replit-codemirror-vim-B2DJlAhT.js";import"./vendor-replit-codemirror-vim-core-FHzKdNUS.js";import"./web-components-DOXvU-tB.js";import"./computeVirtualFileMetrics-CZ0xPeaT.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-BmJyTmjJ.js";import"./vendor-pierre-theming-C6Z4M5_u.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"./isFilePlainText-DiLRrkJr.js";import"./registerCustomTheme-BBXUCRnG.js";function On(a){const e=gt.c(41),{containerRef:r,filePath:d,fileContent:v}=a,{t:g}=Bt(),x=Tn(po),w=Tn(mo),f=Jn(),C=xa(fo),[h,F]=n.useState(null),[N,k]=n.useState(""),[j,T]=n.useState(!1),o=n.useRef(!1),L=n.useRef(null),I=n.useRef(null),[W,A]=n.useState(null);let E;e[0]===Symbol.for("react.memo_cache_sentinel")?(E=()=>{F(null),k(""),T(!1),o.current=!1,I.current=null,A(null)},e[0]=E):E=e[0];const V=E;let S,M;e[1]!==r?(S=()=>{const B=r.current;if(!B)return;const G=()=>{if(o.current)return;const re=window.getSelection(),Se=re?.toString().trim()??"";if(!re||!Se||re.rangeCount===0){V();return}const ie=re.getRangeAt(0);if(!B.contains(ie.commonAncestorContainer)){V();return}const ae=ie.getBoundingClientRect();I.current=ie.cloneRange(),k(Se),F({x:ae.left+ae.width/2,y:ae.top-10})},se=re=>{L.current?.contains(re.target)||o.current&&V()};return document.addEventListener("selectionchange",G),document.addEventListener("pointerdown",se),()=>{document.removeEventListener("selectionchange",G),document.removeEventListener("pointerdown",se)}},M=[r,V],e[1]=r,e[2]=S,e[3]=M):(S=e[2],M=e[3]),n.useEffect(S,M);let $;e[4]!==v?($=B=>{const G=de=>v.slice(0,de).split(`
2
+ `).length,se=co,re=(de,Ve)=>{for(const Ee of se(de)){const ke=v.indexOf(Ee,Ve);if(ke>=0)return ke}return-1},Se=B.length>=8?v.indexOf(B):-1;if(Se>=0){const de=G(Se);return{start:de,end:de+B.split(`
3
+ `).length-1}}const ie=B.split(`
4
+ `).map(lo).filter(Boolean);if(ie.length===0)return null;const ae=re(ie[0],0);if(ae<0)return null;const ye=G(ae);if(ie.length===1)return{start:ye,end:ye};const Te=re(ie[ie.length-1],ae);return Te<0?null:{start:ye,end:Math.max(ye,G(Te))}},e[4]=v,e[5]=$):$=e[5];const P=$;let J;e[6]===Symbol.for("react.memo_cache_sentinel")?(J=()=>{const B=I.current;if(!B){A(null);return}A(va(B))},e[6]=J):J=e[6];const Ne=J;let H,Y;e[7]!==j?(H=()=>{if(!j)return;let B=null;const G=()=>{B===null&&(B=window.requestAnimationFrame(()=>{B=null,Ne()}))};return document.addEventListener("scroll",G,{capture:!0,passive:!0}),window.addEventListener("resize",G),()=>{B!==null&&window.cancelAnimationFrame(B),document.removeEventListener("scroll",G,{capture:!0}),window.removeEventListener("resize",G)}},Y=[j,Ne],e[7]=j,e[8]=H,e[9]=Y):(H=e[8],Y=e[9]),n.useEffect(H,Y);let ee;e[10]!==N?(ee=()=>{N&&(T(!0),o.current=!0,Ne(),window.getSelection()?.removeAllRanges())},e[10]=N,e[11]=ee):ee=e[11];const le=ee;let te;e[12]!==C||e[13]!==x||e[14]!==f||e[15]!==d||e[16]!==w||e[17]!==P||e[18]!==N?(te=B=>{const G=x??(w?"draft":null);if(!N||!G||!f){V();return}const se=P(N);C({directory:f,sessionKey:G},{source:"file-quote",fileLabel:d,startLine:se?.start??0,endLine:se?.end??0,code:N,language:"",text:B.trim()}),V(),queueMicrotask(oo)},e[12]=C,e[13]=x,e[14]=f,e[15]=d,e[16]=w,e[17]=P,e[18]=N,e[19]=te):te=e[19];const Ce=te;if(!h)return null;let O;e[20]!==j||e[21]!==P||e[22]!==N?(O=j?P(N):null,e[20]=j,e[21]=P,e[22]=N,e[23]=O):O=e[23];const ve=O;let we;e[24]!==h.x||e[25]!==h.y?(we={left:h.x,top:h.y,transform:"translate(-50%, -100%)"},e[24]=h.x,e[25]=h.y,e[26]=we):we=e[26];let ce;e[27]!==j||e[28]!==W?(ce=j&&W&&W.length>0?Nn.createPortal(s.jsx("div",{className:"pointer-events-none fixed inset-0 z-40",children:W.map(ao)}),document.body):null,e[27]=j,e[28]=W,e[29]=ce):ce=e[29];let ue;e[30]!==j||e[31]!==d||e[32]!==ve||e[33]!==le||e[34]!==Ce||e[35]!==g?(ue=j?s.jsx("div",{className:"w-[min(420px,80vw)]",children:s.jsx(so,{fileLabel:d,lineRange:ve?{start:ve.start,end:ve.end}:void 0,onSave:Ce,onCancel:V})}):s.jsx("div",{className:q("flex items-center whitespace-nowrap","oc-glass-popover rounded-full border border-[var(--interactive-border)]","shadow-[0_4px_16px_-4px_rgb(0_0_0_/_0.12)]","p-1"),children:s.jsx("button",{type:"button",onClick:le,className:q("px-3.5 py-1.5 rounded-full","text-sm font-medium","text-[var(--surface-foreground)]","hover:bg-[var(--interactive-hover)]","transition-colors duration-150"),title:g("chat.textSelection.title.commentOnSelection"),children:g("chat.textSelection.actions.comment")})}),e[30]=j,e[31]=d,e[32]=ve,e[33]=le,e[34]=Ce,e[35]=g,e[36]=ue):ue=e[36];let be;return e[37]!==we||e[38]!==ce||e[39]!==ue?(be=Nn.createPortal(s.jsxs("div",{ref:L,className:"fixed z-50",style:we,children:[ce,ue]}),document.body),e[37]=we,e[38]=ce,e[39]=ue,e[40]=be):be=e[40],be}function ao(a,e){return s.jsx("div",{className:"oc-chat-comment-rect absolute",style:{left:a.left,top:a.top,width:a.width,height:a.height}},e)}function oo(){wa()}function lo(a){return a.trim()}function co(a){const e=a.trim();return[e,e.slice(0,32),e.split(" ").slice(0,4).join(" ")].filter(uo)}function uo(a){return a.length>=8}function fo(a){return a.addDraft}function mo(a){return a.newSessionDraft?.open}function po(a){return a.currentSessionId}const ho=(a,e)=>{if(!e)return null;const r=Number.parseInt(a.trim(),10);return!Number.isFinite(r)||r<1?null:Math.min(r,e.state.doc.lines)},Bn=(a,e)=>{const r=a.state.doc.lineAt(e.main.head);return{lineNumber:r.number,character:e.main.head-r.from+1,selection:e}},$n=(a,e,r)=>{const d=a.state.doc.line(e),v=Math.max(1,Math.min(r,d.length+1)),g=d.from+v-1;a.dispatch({selection:Ha.cursor(g),effects:jt.scrollIntoView(g,{y:"center"})})};function go({open:a,onOpenChange:e,view:r,variant:d="overlay"}){const{t:v}=Bt(),[g,x]=n.useState(""),w=n.useRef(null),f=n.useRef(!1),C=n.useRef(null),h=n.useRef(null),F=n.useMemo(()=>ho(g,r),[g,r]);n.useEffect(()=>{!a||!r||(f.current=!1,w.current=Bn(r,r.state.selection),x(""))},[a,r]),n.useEffect(()=>{a&&window.requestAnimationFrame(()=>{h.current?.focus(),h.current?.select()})},[a]),n.useEffect(()=>{if(!(!a||!r||!w.current)){if(F===null){const{selection:o}=w.current;r.dispatch({selection:o,effects:jt.scrollIntoView(o.main.from,{y:"center"})});return}$n(r,F,w.current.character)}},[F,a,r]);const N=n.useCallback(()=>{if(!r||f.current||!w.current)return;const{selection:o}=w.current;r.dispatch({selection:o,effects:jt.scrollIntoView(o.main.from,{y:"center"})})},[r]),k=n.useCallback(o=>{o||N(),e(o)},[e,N]),j=n.useCallback(()=>{!r||F===null||!w.current||(f.current=!0,$n(r,F,w.current.character),e(!1),r.focus())},[F,e,r]);n.useEffect(()=>{if(!a)return;const o=I=>{const W=C.current,A=I.target;!W||!(A instanceof Node)||W.contains(A)||k(!1)},L=I=>{I.key==="Escape"&&(I.preventDefault(),k(!1))};return document.addEventListener("pointerdown",o,!0),document.addEventListener("keydown",L,!0),()=>{document.removeEventListener("pointerdown",o,!0),document.removeEventListener("keydown",L,!0)}},[k,a,d]);const T=n.useMemo(()=>{if(!r)return v("goToLineDialog.helper.editorUnavailable");if(F===null){const o=w.current??Bn(r,r.state.selection);return v("goToLineDialog.helper.currentLineRange",{current:o.lineNumber,max:r.state.doc.lines})}return v("goToLineDialog.helper.goToLine",{line:F})},[F,v,r]);return d==="inline"?a?s.jsxs("div",{ref:C,className:"ml-1 flex h-6 items-center gap-1",children:[s.jsx(ss,{ref:h,type:"number",min:1,step:1,inputMode:"numeric",value:g,onChange:o=>x(o.target.value),onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),j())},placeholder:v("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),s.jsx(z,{variant:"outline",size:"xs",onClick:j,disabled:!r||F===null,className:"h-6 px-2",children:v("goToLineDialog.actions.go")})]}):null:s.jsx("div",{ref:C,className:q("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",a?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:s.jsxs("div",{className:"min-w-0",children:[s.jsx(ss,{ref:h,type:"number",min:1,step:1,inputMode:"numeric",value:g,onChange:o=>x(o.target.value),onKeyDown:o=>{o.key==="Enter"&&(o.preventDefault(),j())},placeholder:v("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-background/60 typography-ui-label"}),s.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:T})]})})}const xo=(a,e)=>{const r=e.trim().toLowerCase(),d=[];if(!r)return d;const v=a.toLowerCase();let g=0;for(;;){const x=v.indexOf(r,g);if(x===-1)break;d.push({start:x,end:x+r.length}),g=x+r.length}return d},Vs="data-md-find",ur="data-md-find-current",ri="rounded-[2px] bg-status-warning/30 text-foreground",vo="rounded-[2px] bg-status-warning/60 text-foreground",wo=120,bo=a=>a instanceof Element&&a.hasAttribute(Vs),yo=a=>a.target instanceof Element&&a.target.hasAttribute(Vs)?!0:[...a.addedNodes].some(e=>bo(e)),ni=a=>{const e=new Set;a.querySelectorAll(`mark[${Vs}]`).forEach(r=>{const d=r.parentNode;d&&(d.replaceChild(document.createTextNode(r.textContent??""),r),e.add(d))}),e.forEach(r=>r.normalize())},jo=(a,e)=>{ni(a);const r=e.trim().toLowerCase();if(!r)return[];const d=[],v=document.createTreeWalker(a,NodeFilter.SHOW_TEXT,{acceptNode(x){const w=x.parentElement;return!w||w.closest("svg, script, style")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),g=[];for(;v.nextNode();){const x=v.currentNode;x instanceof Text&&g.push(x)}for(const x of g){const w=x.nodeValue??"";if(!w)continue;const f=xo(w,r);if(f.length===0)continue;const C=x.parentNode;if(!C)continue;const h=document.createDocumentFragment();let F=0;for(const N of f){N.start>F&&h.appendChild(document.createTextNode(w.slice(F,N.start)));const k=document.createElement("mark");k.setAttribute(Vs,""),k.className=ri,k.textContent=w.slice(N.start,N.end),h.appendChild(k),d.push(k),F=N.end}F<w.length&&h.appendChild(document.createTextNode(w.slice(F))),C.replaceChild(h,x)}return d},Wn=({containerRef:a,open:e,onOpenChange:r,focusNonce:d,className:v})=>{const{t:g}=Bt(),[x,w]=n.useState(""),[f,C]=n.useState(0),[h,F]=n.useState(0),N=n.useRef(null),k=n.useRef([]),j=n.useRef(x);j.current=x;const T=n.useRef(null),o=n.useRef(null),L=n.useCallback((S,M=!1)=>{const $=a.current;if(!$){k.current=[],C(0),F(0);return}k.current=jo($,S);const P=k.current.length;C(P),F(J=>!M||P===0?0:Math.min(J,P-1))},[a]),I=n.useCallback((S,M=!1)=>{T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{T.current=null,L(S,M)},wo)},[L]);n.useEffect(()=>()=>{T.current&&clearTimeout(T.current)},[]);const W=n.useCallback(()=>{r(!1);const S=o.current;o.current=null,S?.isConnected&&S.focus()},[r]);n.useEffect(()=>{const S=a.current;if(!e||!S)return;const M=new MutationObserver($=>{!j.current.trim()||!$.some(J=>!yo(J))||I(j.current,!0)});return M.observe(S,{childList:!0,subtree:!0,characterData:!0}),()=>{M.disconnect(),ni(S)}},[a,e,I]),n.useEffect(()=>{if(!e)return;const S=document.activeElement;S instanceof HTMLElement&&!o.current&&(o.current=S),N.current?.focus()},[e]),n.useEffect(()=>{e&&d>0&&(N.current?.focus(),N.current?.select())},[e,d]),n.useEffect(()=>{const S=a.current;if(!S||(S.querySelectorAll(`mark[${ur}]`).forEach($=>{$.removeAttribute(ur),$.className=ri}),f===0))return;const M=k.current[Math.min(Math.max(h,0),f-1)];M&&(M.setAttribute(ur,""),M.className=vo,M.scrollIntoView({block:"nearest"}))},[a,h,f]);const A=n.useCallback(()=>{F(S=>f===0?0:(S+1)%f)},[f]),E=n.useCallback(()=>{F(S=>f===0?0:(S-1+f)%f)},[f]),V=n.useCallback(S=>{S.key==="Enter"?(S.preventDefault(),S.shiftKey?E():A()):S.key==="Escape"&&(S.preventDefault(),W())},[W,A,E]);return e?s.jsxs("div",{className:q("absolute right-3 top-3 z-10 flex items-center gap-1 rounded-lg border border-border/60 bg-[var(--surface-elevated)] px-1.5 py-1 shadow-lg",v),children:[s.jsx(b,{name:"search",className:"ml-0.5 size-3.5 text-muted-foreground"}),s.jsx(ss,{ref:N,value:x,onChange:S=>{w(S.target.value),I(S.target.value)},onKeyDown:V,placeholder:g("filesView.preview.find.placeholder"),"aria-label":g("filesView.preview.find.placeholder"),className:"h-7 w-40 rounded-md px-2 py-0 text-sm md:w-56"}),s.jsx("span",{className:"min-w-12 px-1 text-center typography-micro text-muted-foreground tabular-nums","aria-live":"polite","aria-label":f>0?g("filesView.preview.find.countAria",{current:h+1,total:f}):g("filesView.preview.find.noMatches"),children:x.trim()&&f===0?g("filesView.preview.find.noMatches"):f>0?`${h+1}/${f}`:""}),s.jsx(z,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:E,title:g("filesView.preview.find.previousAria"),"aria-label":g("filesView.preview.find.previousAria"),disabled:f===0,children:s.jsx(b,{name:"arrow-up",className:"size-3.5"})}),s.jsx(z,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:A,title:g("filesView.preview.find.nextAria"),"aria-label":g("filesView.preview.find.nextAria"),disabled:f===0,children:s.jsx(b,{name:"arrow-down",className:"size-3.5"})}),s.jsx(z,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:W,title:g("filesView.preview.find.closeAria"),"aria-label":g("filesView.preview.find.closeAria"),children:s.jsx(b,{name:"close",className:"size-3.5"})})]}):null};function _n(){const a=gt.c(8),[e]=nr.useState(Fo),r=nr.useRef(!1);let d;a[0]!==e?(d=f=>{if(f==null){e.cleanUp(),r.current=!1;return}r.current||(r.current=!0,e.setup(f,f.firstElementChild??void 0))},a[0]=e,a[1]=d):d=a[1];const v=d;let g,x;a[2]!==e?(g=()=>()=>{r.current=!1,e.cleanUp()},x=[e],a[2]=e,a[3]=g,a[4]=x):(g=a[3],x=a[4]),nr.useLayoutEffect(g,x);let w;return a[5]!==v||a[6]!==e?(w={virtualizer:e,setScroller:v},a[5]=v,a[6]=e,a[7]=w):w=a[7],w}function Fo(){return new Ya}function No(a){return!(!a.autoSaveEnabled||!a.isDirty||!a.canWrite||a.isSaving||a.fileLoading||a.isNonEditableBinary||!a.selectedFilePath||a.loadedFilePath!==a.selectedFilePath)}function Co(a){return a.selectedFilePath?a.isDirty?!(a.fileLoading||a.loadedFilePath!==a.selectedFilePath||a.isNonEditableBinary||a.draftContent===""&&a.fileContent!==""&&a.loadedFilePath!==a.selectedFilePath):!0:!1}const So='<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 Un(){if(typeof document>"u")return!1;const a=document.documentElement.getAttribute("data-theme");return a==="dark"||!a&&window.matchMedia("(prefers-color-scheme: dark)").matches}const ko=n.forwardRef(function({xml:e,readOnly:r,className:d,onChange:v},g){const x=n.useRef(e),w=n.useRef(null),f=n.useRef(!1),[C,h]=n.useState(Un),F=n.useRef(e),N=n.useRef(e);N.current!==e&&(N.current=e,F.current=e,x.current=e);const k=n.useRef(C);k.current!==C&&(k.current=C,F.current=x.current);const j=n.useRef(null);n.useEffect(()=>{const L=()=>h(Un());L();const I=new MutationObserver(L);return I.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>I.disconnect()},[]),n.useEffect(()=>{const L=setTimeout(()=>{j.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(L)},[]),n.useImperativeHandle(g,()=>({getXml:()=>x.current}));const T=n.useCallback(()=>{!e&&!f.current&&(f.current=!0,setTimeout(()=>{w.current?.template({})},500))},[e]),o=n.useCallback(L=>{x.current=L.xml,v?.(L.xml)},[v]);return s.jsx("div",{ref:j,className:q("h-full w-full",d),children:s.jsx(to,{ref:w,xml:F.current||So,autosave:!0,urlParameters:{ui:r?"simple":C?"dark":"kennedy",spin:!0,libraries:!r,chrome:r,nav:r,layers:r,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:T,onAutoSave:o},C?"dark":"light")})}),Ro=a=>{const e=K(a);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const r=e.lastIndexOf("/");if(r<0)return e;if(r===0)return"/";const d=e.slice(0,r);return/^[A-Za-z]:$/.test(d)?`${d}/`:d},To=a=>{const e=gt.c(8),{label:r,iconDataUrl:d}=a,[v,g]=n.useState(!1);let x;e[0]!==r?(x=r.trim().slice(0,1).toUpperCase()||"?",e[0]=r,e[1]=x):x=e[1];const w=x;if(d&&!v){let h;e[2]===Symbol.for("react.memo_cache_sentinel")?(h=()=>g(!0),e[2]=h):h=e[2];let F;return e[3]!==d?(F=s.jsx("img",{src:d,alt:"",className:"size-4 rounded-sm",onError:h}),e[3]=d,e[4]=F):F=e[4],F}let f;e[5]===Symbol.for("react.memo_cache_sentinel")?(f=q("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=f):f=e[5];let C;return e[6]!==w?(C=s.jsx("span",{className:f,children:w}),e[6]=w,e[7]=C):C=e[7],C},Vo=a=>a.slice().sort((e,r)=>e.type!==r.type?e.type==="directory"?-1:1:e.name.localeCompare(r.name)),K=a=>{if(!a)return"";const e=a.replace(/\\/g,"/"),r=e.startsWith("//");let d=e.replace(/\/+/g,"/");r&&!d.startsWith("//")&&(d=`/${d}`);const v=d==="/",g=/^[A-Za-z]:\/$/.test(d);return!v&&!g&&(d=d.replace(/\/+$/,"")),d},Eo=a=>a.startsWith("/")||a.startsWith("//")||/^[A-Za-z]:\//.test(a),Ot=a=>/^[A-Za-z]:\//.test(a)?a.toLowerCase():a,Ts=(a,e)=>{const r=K(e),d=K(a);if(!r||!d)return!1;const v=Ot(r),g=Ot(d);return g===v||g.startsWith(`${v}/`)},Kn=(a,e)=>{const r=K(e),d=K(a);if(!Ts(d,r))return[];const g=d.slice(r.length).replace(/^\//,"").split("/"),x=[];let w=r;for(let f=0;f<g.length-1;f++)w=w?`${w}/${g[f]}`:g[f],x.push(w);return x},ks=(a,e)=>{if(!e)return"";const r=K(e);if(!a||!Ts(r,a))return r;const d=r.slice(a.length);return d.startsWith("/")?d.slice(1):d},Do=new Set(["node_modules"]),Po=a=>{const e=gt.c(3),{status:r}=a;let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={open:"var(--status-info)",modified:"var(--status-warning)","git-modified":"var(--status-warning)","git-added":"var(--status-success)","git-deleted":"var(--status-error)"},e[0]=d):d=e[0];const v=d[r];let g;return e[1]!==v?(g=s.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:v}}),e[1]=v,e[2]=g):g=e[2],g},Hn=a=>{const e=gt.c(11),{name:r}=a,d=n.useRef(null),v=n.useRef(null),[g,x]=n.useState(!1);let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w=()=>{const N=d.current,k=v.current;if(!N||!k)return;const j=()=>{x(k.scrollWidth>N.clientWidth+1)};j();const T=new ResizeObserver(j);return T.observe(N),T.observe(k),()=>{T.disconnect()}},e[0]=w):w=e[0];let f;e[1]!==r?(f=[r],e[1]=r,e[2]=f):f=e[2],n.useLayoutEffect(w,f);let C;e[3]!==r?(C=s.jsx("span",{ref:v,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:r}),e[3]=r,e[4]=C):C=e[4];let h;e[5]!==r||e[6]!==g?(h=g?s.jsxs("span",{className:"open-file-name-marquee-track",children:[s.jsx("span",{className:"open-file-name-marquee-item",children:r}),s.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:r})]}):s.jsx("span",{className:"block min-w-0 truncate",children:r}),e[5]=r,e[6]=g,e[7]=h):h=e[7];let F;return e[8]!==C||e[9]!==h?(F=s.jsxs("span",{ref:d,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[C,h]}),e[8]=C,e[9]=h,e[10]=F):F=e[10],F},Mo=a=>Do.has(a),zo=a=>{const e=K(a);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Ao=a=>{const r=(a instanceof Error?a.message:String(a??"")).toLowerCase();return r.includes("is a directory")||r.includes("eisdir")},Gn=a=>{const r=(a instanceof Error?a.message:String(a??"")).toLowerCase();return r.includes("file not found")||r.includes("enoent")||r.includes("no such file")||r.includes("does not exist")},It=2e5;function Lo(a){const e=a.length>400?`${a.slice(0,200)}${a.slice(-200)}`:a;let r=2166136261;for(let d=0;d<e.length;d+=1)r^=e.charCodeAt(d),r=r+((r<<1)+(r<<4)+(r<<7)+(r<<8)+(r<<24))>>>0;return`${a.length}:${r.toString(16)}`}const Io=a=>{let e=0,r=0;for(let d=0;d<a.length;d+=1)a.charCodeAt(d)===10&&(d>0&&a.charCodeAt(d-1)===13?e+=1:r+=1);return e>r?`\r
5
+ `:`
6
+ `},ii=a=>a.replace(/\r\n/g,`
7
+ `).replace(/\r/g,`
8
+ `),Oo=(a,e)=>{const r=ii(a);return e===`\r
9
+ `?r.replace(/\n/g,`\r
10
+ `):r},ai=(a,e)=>s.jsx(Cs,{filePath:a,extension:e}),qn=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},Bo=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},dr=a=>{if(!a)return!1;const e=a.toLowerCase().split(".").pop();return e==="html"||e==="htm"},$o=a=>{const e=gt.c(76),{node:r,root:d,isExpanded:v,isActive:g,isMobile:x,isBrowserClient:w,alwaysShowActions:f,status:C,badge:h,permissions:F,downloadFile:N,contextMenuPath:k,setContextMenuPath:j,rightClickMenuPath:T,setRightClickMenuPath:o,onSelect:L,onToggle:I,onRevealPath:W,onOpenDialog:A}=a,{t:E}=Bt(),V=r.type==="directory",{canRename:S,canCreateFile:M,canCreateFolder:$,canDelete:P,canReveal:J}=F,Ne=!V&&!!N,H=J&&!w,Y=S||M||$||P||Ne||H;let ee;e[0]!==Y||e[1]!==r.path||e[2]!==o?(ee=fe=>{Y&&(fe?.preventDefault(),o(r.path))},e[0]=Y,e[1]=r.path,e[2]=o,e[3]=ee):ee=e[3];const le=ee;let te;e[4]!==V||e[5]!==r||e[6]!==L||e[7]!==I?(te=()=>{V?I(r.path):L(r)},e[4]=V,e[5]=r,e[6]=L,e[7]=I,e[8]=te):te=e[8];const Ce=te;let O;e[9]!==r.path||e[10]!==j||e[11]!==o?(O=fe=>{fe.stopPropagation(),o(null),j(r.path)},e[9]=r.path,e[10]=j,e[11]=o,e[12]=O):O=e[12];const ve=O;let we;e[13]!==M||e[14]!==$||e[15]!==P||e[16]!==S||e[17]!==H||e[18]!==N||e[19]!==w||e[20]!==V||e[21]!==r||e[22]!==A||e[23]!==W||e[24]!==d||e[25]!==E?(we=fe=>{const{Item:he,Separator:Ze}=fe;return s.jsxs(s.Fragment,{children:[S&&s.jsxs(he,{onClick:X=>{X.stopPropagation(),A("rename",r)},children:[s.jsx(b,{name:"edit",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.rename")]}),s.jsxs(he,{onClick:X=>{X.stopPropagation(),Rs(r.path).then(at=>{if(at.ok){Q.success(E("sidebarFilesTree.toast.pathCopied"));return}Q.error(E("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(b,{name:"file-copy",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.copyPath")]}),s.jsxs(he,{onClick:X=>{X.stopPropagation();const at=ks(d,r.path)||r.path;Rs(at).then(me=>{if(me.ok){Q.success(E("filesView.toast.relativePathCopied"));return}Q.error(E("sidebarFilesTree.toast.copyFailed"))})},children:[s.jsx(b,{name:"file-copy-2",className:"mr-2 size-4"})," ",E("filesView.tree.menu.copyRelativePath")]}),!V&&N&&s.jsxs(he,{onClick:X=>{X.stopPropagation(),N(r.path).catch(at=>{console.error("Download failed:",at),Q.error(E("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(b,{name:"download",className:"mr-2 size-4"})," ",E(w?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),H&&s.jsxs(he,{onClick:X=>{X.stopPropagation(),W(r.path)},children:[s.jsx(b,{name:"folder-received",className:"mr-2 size-4"})," ",E(Ia())]}),V&&(M||$)&&s.jsxs(s.Fragment,{children:[s.jsx(Ze,{}),M&&s.jsxs(he,{onClick:X=>{X.stopPropagation(),A("createFile",r)},children:[s.jsx(b,{name:"file-add",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.newFile")]}),$&&s.jsxs(he,{onClick:X=>{X.stopPropagation(),A("createFolder",r)},children:[s.jsx(b,{name:"folder-add",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.newFolder")]})]}),P&&s.jsxs(s.Fragment,{children:[s.jsx(Ze,{}),s.jsxs(he,{onClick:X=>{X.stopPropagation(),A("delete",r)},className:"text-destructive focus:text-destructive",children:[s.jsx(b,{name:"delete-bin",className:"mr-2 size-4"})," ",E("sidebarFilesTree.menu.delete")]})]})]})},e[13]=M,e[14]=$,e[15]=P,e[16]=S,e[17]=H,e[18]=N,e[19]=w,e[20]=V,e[21]=r,e[22]=A,e[23]=W,e[24]=d,e[25]=E,e[26]=we):we=e[26];const ce=we,ue=T===r.path;let be;e[27]!==r.path||e[28]!==o?(be=fe=>o(fe?r.path:null),e[27]=r.path,e[28]=o,e[29]=be):be=e[29];const B=x?void 0:le;let G;e[30]!==B?(G=s.jsx("div",{className:"group relative flex items-center",onContextMenu:B}),e[30]=B,e[31]=G):G=e[31];const se=x?void 0:le,re=g?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let Se;e[32]!==re?(Se=q("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",re),e[32]=re,e[33]=Se):Se=e[33];let ie;e[34]!==V||e[35]!==v||e[36]!==r.extension||e[37]!==r.path?(ie=V?v?s.jsx(b,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):s.jsx(b,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):ai(r.path,r.extension),e[34]=V,e[35]=v,e[36]=r.extension,e[37]=r.path,e[38]=ie):ie=e[38];let ae;e[39]!==r.name||e[40]!==r.path?(ae=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:r.path,children:r.name}),e[39]=r.name,e[40]=r.path,e[41]=ae):ae=e[41];let ye;e[42]!==V||e[43]!==C?(ye=!V&&C&&s.jsx(Po,{status:C}),e[42]=V,e[43]=C,e[44]=ye):ye=e[44];let Te;e[45]!==h||e[46]!==V?(Te=V&&h&&s.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[h.modified>0&&s.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",h.modified]}),h.added>0&&s.jsxs("span",{className:"text-[var(--status-success)]",children:["+",h.added]})]}),e[45]=h,e[46]=V,e[47]=Te):Te=e[47];let de;e[48]!==Ce||e[49]!==Se||e[50]!==ie||e[51]!==ae||e[52]!==ye||e[53]!==Te||e[54]!==se?(de=s.jsxs("button",{type:"button",onClick:Ce,onContextMenu:se,className:Se,children:[ie,ae,ye,Te]}),e[48]=Ce,e[49]=Se,e[50]=ie,e[51]=ae,e[52]=ye,e[53]=Te,e[54]=se,e[55]=de):de=e[55];let Ve;e[56]!==f||e[57]!==k||e[58]!==ve||e[59]!==Y||e[60]!==x||e[61]!==r.path||e[62]!==ce||e[63]!==j?(Ve=Y&&s.jsx("div",{className:q("absolute right-1 top-1/2 -translate-y-1/2",f?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:s.jsxs(fr,{open:k===r.path,onOpenChange:fe=>j(fe?r.path:null),children:[s.jsx(mr,{asChild:!0,children:s.jsx(z,{variant:"ghost",size:"icon",className:"size-6",onClick:ve,children:s.jsx(b,{name:"more-2-fill",className:"size-4"})})}),s.jsx(pr,{align:"end",side:"bottom",onCloseAutoFocus:()=>j(null),children:ce({Item:Ss,Separator:La})})]})}),e[56]=f,e[57]=k,e[58]=ve,e[59]=Y,e[60]=x,e[61]=r.path,e[62]=ce,e[63]=j,e[64]=Ve):Ve=e[64];let Ee;e[65]!==de||e[66]!==Ve||e[67]!==G?(Ee=s.jsxs(_a,{render:G,children:[de,Ve]}),e[65]=de,e[66]=Ve,e[67]=G,e[68]=Ee):Ee=e[68];let ke;e[69]!==ce?(ke=s.jsx(Ba,{className:"min-w-[180px]",children:ce({Item:Wa,Separator:$a})}),e[69]=ce,e[70]=ke):ke=e[70];let Z;return e[71]!==Ee||e[72]!==ke||e[73]!==ue||e[74]!==be?(Z=s.jsxs(Ua,{open:ue,onOpenChange:be,children:[Ee,ke]}),e[71]=Ee,e[72]=ke,e[73]=ue,e[74]=be,e[75]=Z):Z=e[75],Z},Wo=a=>{const e=gt.c(83),{activeDialog:r,dialogData:d,dialogInputValue:v,onDialogInputChange:g,isDialogSubmitting:x,onDialogSubmit:w,onClose:f,inputRef:C}=a,{t:h}=Bt(),F=!!r;let N;e[0]!==f?(N=O=>!O&&f(),e[0]=f,e[1]=N):N=e[1];let k;e[2]!==r||e[3]!==h?(k=r==="createFile"&&h("filesView.dialog.createFile.title"),e[2]=r,e[3]=h,e[4]=k):k=e[4];let j;e[5]!==r||e[6]!==h?(j=r==="createFolder"&&h("filesView.dialog.createFolder.title"),e[5]=r,e[6]=h,e[7]=j):j=e[7];let T;e[8]!==r||e[9]!==h?(T=r==="rename"&&h("filesView.dialog.rename.title"),e[8]=r,e[9]=h,e[10]=T):T=e[10];let o;e[11]!==r||e[12]!==h?(o=r==="delete"&&h("filesView.dialog.delete.title"),e[11]=r,e[12]=h,e[13]=o):o=e[13];let L;e[14]!==k||e[15]!==j||e[16]!==T||e[17]!==o?(L=s.jsxs(ei,{children:[k,j,T,o]}),e[14]=k,e[15]=j,e[16]=T,e[17]=o,e[18]=L):L=e[18];let I;e[19]!==r||e[20]!==d?.path||e[21]!==h?(I=r==="createFile"&&h("filesView.dialog.createFile.description",{path:d?.path??h("filesView.dialog.rootFallback")}),e[19]=r,e[20]=d?.path,e[21]=h,e[22]=I):I=e[22];let W;e[23]!==r||e[24]!==d?.path||e[25]!==h?(W=r==="createFolder"&&h("filesView.dialog.createFolder.description",{path:d?.path??h("filesView.dialog.rootFallback")}),e[23]=r,e[24]=d?.path,e[25]=h,e[26]=W):W=e[26];let A;e[27]!==r||e[28]!==d?.name||e[29]!==h?(A=r==="rename"&&h("filesView.dialog.rename.description",{name:d?.name??""}),e[27]=r,e[28]=d?.name,e[29]=h,e[30]=A):A=e[30];let E;e[31]!==r||e[32]!==d?.name||e[33]!==h?(E=r==="delete"&&h("filesView.dialog.delete.description",{name:d?.name??""}),e[31]=r,e[32]=d?.name,e[33]=h,e[34]=E):E=e[34];let V;e[35]!==A||e[36]!==E||e[37]!==I||e[38]!==W?(V=s.jsxs(ti,{children:[I,W,A,E]}),e[35]=A,e[36]=E,e[37]=I,e[38]=W,e[39]=V):V=e[39];let S;e[40]!==V||e[41]!==L?(S=s.jsxs(Zn,{children:[L,V]}),e[40]=V,e[41]=L,e[42]=S):S=e[42];let M;e[43]!==r||e[44]!==v||e[45]!==C||e[46]!==g||e[47]!==w||e[48]!==h?(M=r!=="delete"&&s.jsx("div",{className:"py-4",children:s.jsx(ss,{value:v,onChange:O=>g(O.target.value),placeholder:h(r==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:O=>{O.key==="Enter"&&w()},ref:C})}),e[43]=r,e[44]=v,e[45]=C,e[46]=g,e[47]=w,e[48]=h,e[49]=M):M=e[49];let $;e[50]!==h?($=h("filesView.dialog.cancel"),e[50]=h,e[51]=$):$=e[51];let P;e[52]!==x||e[53]!==f||e[54]!==$?(P=s.jsx(z,{variant:"outline",onClick:f,disabled:x,children:$}),e[52]=x,e[53]=f,e[54]=$,e[55]=P):P=e[55];const J=r==="delete"?"destructive":"default";let Ne;e[56]!==w?(Ne=()=>{w()},e[56]=w,e[57]=Ne):Ne=e[57];let H;e[58]!==r||e[59]!==v||e[60]!==x?(H=x||r!=="delete"&&!v.trim(),e[58]=r,e[59]=v,e[60]=x,e[61]=H):H=e[61];let Y;e[62]!==r||e[63]!==x||e[64]!==h?(Y=x?s.jsx(b,{name:"loader-4",className:"size-4 animate-spin"}):h(r==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=r,e[63]=x,e[64]=h,e[65]=Y):Y=e[65];let ee;e[66]!==J||e[67]!==Ne||e[68]!==H||e[69]!==Y?(ee=s.jsx(z,{variant:J,onClick:Ne,disabled:H,children:Y}),e[66]=J,e[67]=Ne,e[68]=H,e[69]=Y,e[70]=ee):ee=e[70];let le;e[71]!==P||e[72]!==ee?(le=s.jsxs(si,{children:[P,ee]}),e[71]=P,e[72]=ee,e[73]=le):le=e[73];let te;e[74]!==C||e[75]!==S||e[76]!==M||e[77]!==le?(te=s.jsxs(Yn,{initialFocus:C,children:[S,M,le]}),e[74]=C,e[75]=S,e[76]=M,e[77]=le,e[78]=te):te=e[78];let Ce;return e[79]!==F||e[80]!==N||e[81]!==te?(Ce=s.jsx(Qn,{open:F,onOpenChange:N,children:te}),e[79]=F,e[80]=N,e[81]=te,e[82]=Ce):Ce=e[82],Ce},Xn=(a,e,r)=>{const d=gt.c(8),[v,g]=n.useState(""),[x,w]=n.useState(0);let f,C;d[0]!==a||d[1]!==r||d[2]!==e?(f=()=>{if(!a){g("");return}let F=!1;g("");const N=fa(),k=ma(N);pa(N).then(T=>{F||!T||(g(a),e(null))}).catch(T=>{F||(e(T instanceof Error?T.message:r),g(a))});const j=ha(()=>{F||(g(a),w(_o),e(null))});return()=>{F=!0,k(),j()}},C=[a,e,r],d[0]=a,d[1]=r,d[2]=e,d[3]=f,d[4]=C):(f=d[3],C=d[4]),n.useEffect(f,C);let h;return d[5]!==x||d[6]!==v?(h={readyKey:v,nonce:x},d[5]=x,d[6]=v,d[7]=h):h=d[7],h},uu=({mode:a="full"})=>{const{t:e}=Bt(),{files:r,runtime:d}=ba(),{currentTheme:v,availableThemes:g,lightThemeId:x,darkThemeId:w}=ya(),{isMobile:f,isTablet:C,screenWidth:h}=ja(),F=aa(d.platform),N=f||C,k=oa(),j=la(),T=Jn()??"",o=K(T.trim()),L=a!=="editor-only",I=a==="editor-only"&&!f,W=ca(t=>t.searchFiles),A=Fa(T),[E,V]=n.useState(""),S=Na(E,200),M=n.useRef(null),[$,P]=n.useState(!1),[J,Ne]=n.useState(!0),[H,Y]=n.useState(!1),[ee,le]=n.useState(!1),te=n.useRef(0),Ce=n.useCallback(t=>{te.current=Math.max(0,te.current+(t?1:-1))},[]),[O,ve]=n.useState("edit"),[we,ce]=n.useState("edit"),[ue,be]=n.useState("tree"),[B,G]=n.useState("edit"),[se,re]=n.useState("preview"),[Se,ie]=n.useState(0),ae=n.useRef({}),ye=n.useRef({}),Te=n.useRef({}),de=n.useRef({}),Ve=n.useMemo(()=>g.find(t=>t.metadata.id===x)??Cn(!1),[g,x]),Ee=n.useMemo(()=>g.find(t=>t.metadata.id===w)??Cn(!0),[g,w]);n.useEffect(()=>{In(Ve),In(Ee)},[Ve,Ee]);const ke=n.useMemo(()=>[],[]),Z=He(t=>o?t.byRoot[o]?.openPaths??ke:ke),fe=He(t=>o?t.byRoot[o]?.selectedPath??null:null),he=He(t=>o?t.byRoot[o]?.expandedPaths??ke:ke),Ze=He(t=>t.removeOpenPath),X=He(t=>t.removeOpenPathsByPrefix),at=He(t=>t.removeExpandedPathsByPrefix),me=He(t=>t.setSelectedPath),hr=He(t=>t.toggleExpandedPath),rs=He(t=>t.expandPaths),Ft=n.useCallback(t=>{const i=K(t),l=i.split("/"),u=l[l.length-1]||i,p=u.includes(".")?u.split(".").pop()?.toLowerCase():void 0;return{name:u,path:i,type:"file",extension:p}},[]),Nt=n.useMemo(()=>Z.map(Ft),[Z,Ft]),Es=n.useMemo(()=>{if(fe){const t=Ot(fe);if(Z.some(i=>Ot(i)===t))return fe}return Z[0]??null},[Z,fe]),c=n.useMemo(()=>Es?Ft(Es):null,[Es,Ft]),Ge=c?.path??"",[,oi]=n.useState(0);n.useEffect(()=>{if(!o||!fe)return;const t=Ot(fe);Z.some(l=>Ot(l)===t)||me(o,Z[0]??null)},[Z,o,fe,me]);const ns=!!(o&&Ge&&!Ts(Ge,o)),gr=ns?Vn(Ge):void 0,xt=n.useMemo(()=>({allowOutsideWorkspace:a==="editor-only"&&ns,outsideFileGrant:gr,directory:o||void 0}),[a,ns,gr,o]),qe=n.useCallback(async t=>{const i=Vn(t),l=await Ca(t,o,a==="editor-only");return l.outsideFileGrant&&l.outsideFileGrant!==i&&oi(u=>u+1),l},[a,o]),Ds=n.useRef(null),[xr,li]=n.useState({left:!1,right:!1}),vr=n.useCallback(()=>{const t=Ds.current;t&&li({left:t.scrollLeft>2,right:t.scrollLeft+t.clientWidth<t.scrollWidth-2})},[]),wr=n.useRef(vr);wr.current=vr,n.useEffect(()=>{const t=Ds.current;if(!t)return;const i=()=>wr.current();i(),t.addEventListener("scroll",i,{passive:!0});const l=new ResizeObserver(i);return l.observe(t),()=>{t.removeEventListener("scroll",i),l.disconnect()}},[Nt.length]);const[br,Ps]=n.useState({}),[is,$t]=n.useState({}),ze=n.useRef(new Set),Ae=n.useRef(new Set),et=n.useRef(new Map),yr=n.useRef(0),[jr,as]=n.useState([]),[ci,os]=n.useState(!1),[D,pe]=n.useState(""),{isPlaying:ls,play:ui,stop:di}=Sa(),[Be,ot]=n.useState(!1),[tt,ge]=n.useState(null),[fi,Le]=n.useState(""),[De,oe]=n.useState(null),[ne,xe]=n.useState(""),[Wt,Ms]=n.useState(!1),[Fr,mi]=n.useState(`
11
+ `),pi=n.useRef(null),Xe=n.useRef(null),Pe=n.useRef(null),lt=n.useRef(""),_t=n.useRef(""),st=n.useRef(null),Nr=n.useRef(null),Je=n.useRef(null),Ut=n.useRef(0),Ct=n.useRef(null),[cs,hi]=n.useState(0),[gi,St]=n.useState("idle"),[xi,us]=n.useState(!1),[Kt,Cr]=n.useState(!1),je=ht(t=>t.autoSaveEnabled),vi=ht(t=>t.setAutoSaveEnabled),[zs,Ht]=n.useState(!1),kt=n.useRef(null),Gt=n.useRef(null),qt=n.useRef(!1),Xt=n.useRef(null),Jt=n.useRef(null),$e=n.useRef(null),ds=n.useRef(null),[wi,As]=n.useState(0),Rt=n.useRef(null),vt=n.useRef({key:"",attempts:0});n.useEffect(()=>()=>{Rt.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Rt.current),Rt.current=null)},[]);const[wt,Ls]=n.useState(null),[bt,bi]=n.useState(null),[ct,Sr]=n.useState(""),[yi,Is]=n.useState(!1),[ji,Fi]=n.useState(null),[Ni,Ci]=n.useState(null),[Si,kr]=n.useState(!1),[ki,Rr]=n.useState(!1),[Ri,Os]=n.useState(!1),[Tr,fs]=n.useState(!1),[Vr,Er]=n.useState(0),Bs=n.useRef(null),$s=n.useRef(null),Dr=!!r.writeFile,Pr=!!r.createDirectory,Mr=!!r.rename,zr=!!r.delete,Ar=!!r.revealPath,Ti=Ns(t=>t.availableApps),Vi=Ns(t=>t.isCacheStale),Lr=Ns(t=>t.initialize),Ei=Ns(t=>t.loadInstalledApps);n.useEffect(()=>{Lr()},[Lr]);const Di=n.useCallback(t=>{r.revealPath&&r.revealPath(t).catch(()=>{Q.error(e("sidebarFilesTree.toast.revealFailed"))})},[r,e]),Pi=n.useCallback(async t=>{if(!c?.path||await ua(c.path,t.id,t.appName)||await Sn(c.path,t.appName))return;const u=Ro(c.path)||o;u&&await Sn(u,t.appName)||Q.error(e("filesView.toast.openInAppFailed",{app:t.appName}))},[o,c?.path,e]),Ws=n.useCallback((t,i)=>{Ls(t),bi(i),Sr(t==="rename"&&i.name||""),Is(!1)},[]),[_,We]=n.useState(null),Tt=n.useRef(!1),ut=n.useRef(null),[Ir,Vt]=n.useState(!1),Qe=ht(t=>t.pendingFileNavigation),ms=ht(t=>t.setPendingFileNavigation),_s=ht(t=>t.pendingFileFocusPath),Us=ht(t=>t.setPendingFileFocusPath),Or=ht(t=>t.fileEditorKeymap),Qt=En(t=>t.settingsDefaultFileViewerPreview),Mi=En(t=>t.showMessageTTSButtons);n.useEffect(()=>{const t=()=>{Tt.current=!1,ut.current=null,Vt(!1)};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]),n.useEffect(()=>()=>{Xt.current!==null&&window.clearTimeout(Xt.current),Jt.current!==null&&window.clearTimeout(Jt.current)},[]);const zi=n.useCallback((t,i)=>{const l=t.split(`
12
+ `),u=Math.max(1,i.start),p=Math.min(l.length,i.end);return u>p?"":l.slice(u-1,p).join(`
13
+ `)},[]),ps=n.useRef(null),Ai=ro({source:"file",fileLabel:c?.path??null,language:c?.path&&ir(c.path)||"text",getCodeForRange:t=>zi(D,no(t)),toStoreRange:t=>({startLine:t.start,endLine:t.end}),fromDraftRange:t=>({start:t.startLine,end:t.endLine})}),{drafts:Br,commentText:hs,setCommentText:$r,editingDraftId:gs,setSelection:Wr,saveComment:_r,cancel:Yt,reset:Ur,startEdit:Kr,deleteDraft:Hr}=Ai;n.useEffect(()=>{We(null),Ur(),xe(""),Ms(!1)},[c?.path,Ur]),n.useEffect(()=>{Wr(_)},[_,Wr]),n.useEffect(()=>{if(!_&&!gs)return;const t=l=>{const u=l.target;u.closest('[data-comment-input="true"]')||u.closest('[data-comment-card="true"]')||u.closest(".cm-gutterElement")||u.closest("[data-sonner-toast]")||u.closest("[data-sonner-toaster]")||hs.trim()||(We(null),Yt())},i=setTimeout(()=>{document.addEventListener("click",t)},100);return()=>{clearTimeout(i),document.removeEventListener("click",t)}},[Yt,hs,gs,_]);const Gr=n.useCallback((t,i)=>{const l=i??_??void 0;i&&We(i),_r(t,l),We(null)},[_,_r]),qr=n.useCallback((t,i)=>{const l=[];for(const u of i){if(!(u&&typeof u.name=="string"&&u.name.length>0)||!k&&u.name.startsWith(".")||!j&&Mo(u.name))continue;const p=u.name,m=K(u.path||""),y=m?Eo(m)?m:K(`${t}/${m}`):K(`${t}/${p}`),R=u.isDirectory?"directory":"file",U=R==="file"&&p.includes(".")?p.split(".").pop()?.toLowerCase():void 0;l.push({name:p,path:y,type:R,extension:U})}return Vo(l)},[j,k]),Ie=n.useCallback(async t=>{const i=K(t.trim());if(!i||ze.current.has(i)||Ae.current.has(i))return;Ae.current=new Set(Ae.current),Ae.current.add(i);const l=yr.current+1;yr.current=l,et.current=new Map(et.current),et.current.set(i,l);const u=()=>et.current.get(i)===l;await(r.listDirectory?r.listDirectory(i).then(m=>m.entries.map(y=>({name:y.name,path:y.path,isDirectory:y.isDirectory}))):da.listLocalDirectory(i).then(m=>m.map(y=>({name:y.name,path:y.path,isDirectory:y.isDirectory})))).then(m=>{if(!u())return;const y=qr(i,m);ze.current=new Set(ze.current),ze.current.add(i),$t(R=>{if(!R[i])return R;const U={...R};return delete U[i],U}),Ps(R=>({...R,[i]:y}))}).catch(m=>{if(!u())return;const y=m instanceof Error?m.message:String(m??"");if(y==="Directory not found"&&o&&i!==o){at(o,i),$t(R=>{if(!R[i])return R;const U={...R};return delete U[i],U});return}console.error("Failed to load files directory:",m),$t(R=>({...R,[i]:y}))}).finally(()=>{u()&&(et.current=new Map(et.current),et.current.delete(i),Ae.current=new Set(Ae.current),Ae.current.delete(i))})},[r,qr,at,o]),xs=n.useCallback(async()=>{o&&(ze.current=new Set,Ae.current=new Set,et.current=new Map,$t({}),Ps(t=>Object.keys(t).length===0?t:{}),await Ie(o))},[Ie,o]),Ye=n.useCallback(async t=>{if(!t){await xs();return}const i=K(t);ze.current=new Set(ze.current),ze.current.delete(i),Ae.current=new Set(Ae.current),Ae.current.delete(i),await Ie(i)},[Ie,xs]),Xr=n.useRef(""),Jr=n.useRef("");n.useEffect(()=>{if(!o)return;const t=`${o}|h${k?"1":"0"}|g${j?"1":"0"}`,i=Xr.current!==o,l=Jr.current!==t;!i&&!l||(i&&(Xr.current=o,pe(""),ge(null),Le(""),oe(null),P(!1)),l&&(Jr.current=t,ze.current=new Set,Ae.current=new Set,et.current=new Map,$t({}),Ps(u=>Object.keys(u).length===0?u:{}),Ie(o)))},[Ie,o,j,k]),n.useEffect(()=>{if(!r.listDirectory)return;const t=()=>{if(!document.hidden&&he.length>0)for(const i of he)Ye(i)};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[he,r.listDirectory,Ye]),n.useEffect(()=>{if(!r.listDirectory||he.length===0)return;const t=setInterval(()=>{if(!document.hidden)for(const i of he)Ye(i)},8e3);return()=>clearInterval(t)},[he,r.listDirectory,Ye]);const Li=n.useCallback(async t=>{if(t?.preventDefault(),!bt||!wt)return;Is(!0);const i=()=>{Ls(null)},l=p=>{Q.error(p)},u=()=>{Is(!1)};if(wt==="createFile"){if(!ct.trim()){l(e("sidebarFilesTree.toast.filenameRequired")),u();return}if(!r.writeFile){l(e("sidebarFilesTree.toast.writeNotSupported")),u();return}const p=bt.path,m=p?`${p}/`:"",y=K(`${m}${ct.trim()}`);await r.writeFile(y,"").then(async R=>{R.success&&(Q.success(e("sidebarFilesTree.toast.fileCreated")),await Ye(p)),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(wt==="createFolder"){if(!ct.trim()){l(e("sidebarFilesTree.toast.folderNameRequired")),u();return}const p=bt.path,m=p?`${p}/`:"",y=K(`${m}${ct.trim()}`);await r.createDirectory(y).then(async R=>{R.success&&(Q.success(e("sidebarFilesTree.toast.folderCreated")),await Ye(p)),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(wt==="rename"){if(!ct.trim()){l(e("sidebarFilesTree.toast.nameRequired")),u();return}if(!r.rename){l(e("sidebarFilesTree.toast.renameNotSupported")),u();return}const p=bt.path,m=p.split("/").slice(0,-1).join("/"),y=m?`${m}/`:"",R=K(`${y}${ct.trim()}`);await r.rename(p,R).then(async U=>{U.success&&(Q.success(e("sidebarFilesTree.toast.renamedSuccessfully")),await Ye(m),o&&X(o,p),(c?.path===p||c?.path.startsWith(`${p}/`))&&(o&&me(o,null),pe(""),ge(null),Le(""),oe(null),f&&P(!1))),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}if(wt==="delete"){if(!r.delete){l(e("sidebarFilesTree.toast.deleteNotSupported")),u();return}const p=bt.path,m=p.split("/").slice(0,-1).join("/");await r.delete(p).then(async y=>{y.success&&(Q.success(e("sidebarFilesTree.toast.deletedSuccessfully")),await Ye(m),o&&X(o,p),(c?.path===p||c?.path.startsWith(`${p}/`))&&(o&&me(o,null),pe(""),ge(null),Le(""),oe(null),f&&P(!1))),i()}).catch(()=>l(e("sidebarFilesTree.toast.operationFailed"))).finally(u);return}u()},[wt,bt,ct,r,Ye,f,X,o,c?.path,me,e]);n.useEffect(()=>{if(!T){as([]),os(!1);return}const t=S.trim();if(!t){as([]),os(!1);return}let i=!1;return os(!0),W(T,t,150,{includeHidden:k,respectGitignore:!j,type:"file"}).then(l=>{if(i)return;const p=l.filter(m=>j||!zo(m.path)).map(m=>({name:m.name,path:K(m.path),type:"file",extension:m.extension,relativePath:m.relativePath}));as(p)}).catch(()=>{i||as([])}).finally(()=>{i||os(!1)}),()=>{i=!0}},[T,S,W,k,j]);const Qr=n.useCallback(async t=>{const i=await qe(t);if(r.readFile)return(await r.readFile(t,{...i,directory:o||void 0})).content??"";const l=new URLSearchParams({path:t});i.allowOutsideWorkspace&&l.set("allowOutsideWorkspace","true"),i.outsideFileGrant&&l.set("outsideFileGrant",i.outsideFileGrant),o&&l.set("directory",o);const u=await kn(`/api/fs/read?${l.toString()}`);if(!u.ok){const p=await u.json().catch(()=>({error:u.statusText}));throw new Error(p.error||e("filesView.error.readFileFailed"))}return u.text()},[r,qe,o,e]),dt=n.useCallback(async t=>{if(r.statFile){const i=await qe(t),l=await r.statFile(t,{...i,directory:o||void 0});return{path:l.path,size:l.size,mtimeMs:l.mtimeMs}}return null},[r,qe,o]);n.useEffect(()=>{if(!o||!r.statFile||Z.length===0)return;let t=!1;const i=[...Z];return Promise.all(i.map(async l=>{try{const u=await qe(l),p=await r.statFile?.(l,{...u,directory:o||void 0});!t&&p&&!p.isFile&&X(o,l)}catch(u){!t&&Gn(u)&&X(o,l)}})),()=>{t=!0}},[r,Z,X,qe,o]);const Ks=n.useMemo(()=>D.length>It?`${D.slice(0,It)}
14
+
15
+ … truncated …`:D,[D]),Me=ne!==Ks,Et=n.useCallback(async()=>{if(!c||!r.writeFile)return Q.error(e("filesView.toast.savingNotSupported")),!1;const t=Fs(c.path)||Kt;if(!Co({selectedFilePath:c.path,loadedFilePath:De,fileLoading:Be,isDirty:Me,draftContent:ne,fileContent:D,isNonEditableBinary:t}))return t?console.warn(`[saveDraft] refusing to save binary file "${c.path}".`):ne===""&&D!==""&&De!==c.path&&console.warn(`[saveDraft] refusing to save empty draft for "${c.path}" (${D.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(!Me)return!0;Ms(!0);try{const i=Oo(ne,Fr);if(!(await r.writeFile(c.path,i))?.success)return Q.error(e("filesView.toast.writeFileFailed")),!1;if(pe(ne),o&&Ts(c.path,o)){const u=ks(o,c.path);u&&ka.requestGitRefresh({directory:o,paths:[u]})}if(o&&/(?:^|\/)\.agents\/loops\/[^/]+\.md$/i.test(K(c.path))){const u=Ra.getState().projects.find(p=>K(p.path)===K(o));if(u)try{await Za(u.id)}catch{Q.error(e("sessions.scheduledTasks.dialog.toast.updateFailed"))}}return c?.path&&ar(c.path)&&(lt.current=ne,_t.current=ne),dt(c.path).then(u=>{u&&(Je.current=u)}).catch(()=>{}),!0}catch(i){return Q.error(i instanceof Error?i.message:e("filesView.toast.saveFailed")),!1}finally{Ms(!1)}},[Kt,ne,D,Be,r,Me,Fr,De,dt,o,c,e]);n.useEffect(()=>{je||(St("idle"),Xe.current&&(clearTimeout(Xe.current),Xe.current=null))},[je]);const Yr=1500;n.useEffect(()=>{const t=!!(c&&r.writeFile),i=!!(c?.path&&(Fs(c.path)||Kt));if(No({autoSaveEnabled:je,isDirty:Me,canWrite:t,isSaving:Wt,fileLoading:Be,selectedFilePath:c?.path,loadedFilePath:De,isNonEditableBinary:i}))return Xe.current=setTimeout(()=>{Et().then(l=>{l&&(St("saved"),setTimeout(()=>St("idle"),2e3))})},Yr),()=>{Xe.current&&(clearTimeout(Xe.current),Xe.current=null)}},[je,Kt,ne,Be,Me,De,c,r.writeFile,Wt,Et]),n.useEffect(()=>{St("idle")},[c?.path]),Ta({save_file:t=>{if(!(t.target instanceof Node)||!ds.current?.contains(t.target))return!1;Xe.current&&(clearTimeout(Xe.current),Xe.current=null),Wt||Et().then(i=>{i&&(St("saved"),setTimeout(()=>St("idle"),2e3))})},find_in_file:t=>{if(!(t.target instanceof Node))return!1;if(nt&&Ue()==="preview"){if(f||!(H?$s.current:Bs.current)?.contains(t.target))return!1;fs(!0),Er(l=>l+1);return}if(!ds.current?.contains(t.target))return!1;le(!0)}});const Zr=n.useCallback(async t=>{const i=Ut.current+1;Ut.current=i;const l=()=>{if(!o)return!1;const R=He.getState().byRoot[o],U=R?.selectedPath??R?.openPaths[0]??null;return Ut.current===i&&U===t.path};if(ge(null),Le(""),oe(null),Cr(!1),ot(!0),await qe(t.path),!l())return;const u=Dn(t.path),p=Pn(t.path),m=Mn(t.path),y=Fs(t.path);if(f&&P(!0),d.isDesktop&&u&&!p){pe(""),xe("");return}if(!d.isDesktop&&u&&!p){pe(""),xe(""),oe(t.path),ot(!1);return}if(m){pe(""),xe(""),oe(t.path),ot(!1);return}if(y){pe(""),xe(""),oe(t.path),ot(!1);return}await Qr(t.path).then(R=>{if(!l())return;if(Va(R)){Cr(!0),pe(""),xe(""),oe(t.path);return}const U=ii(R);mi(Io(R)),pe(U),lt.current=U,_t.current=U,xe(U.length>It?`${U.slice(0,It)}
16
+
17
+ … truncated …`:U),oe(t.path),dt(t.path).then(mt=>{mt&&l()&&(Je.current=mt)}).catch(()=>{})}).catch(R=>{if(l()){if(Ao(R)){if(ot(!1),o&&me(o,null),ge(null),pe(""),xe(""),oe(null),Je.current=null,E.trim().length>0&&V(""),f&&P(!1),o){const mt=[...Kn(t.path,o),t.path];mt.length>0&&rs(o,mt);for(const pt of mt)ze.current.has(pt)||Ie(pt)}return}if(Gn(R)){o&&X(o,t.path),pe(""),xe(""),ge(null),Je.current=null,f&&P(!1);return}pe(""),xe(""),ge(R instanceof Error?R.message:e("filesView.error.readFileFailed")),Je.current=null}}).finally(()=>{l()&&ot(!1)})},[rs,f,Ie,Qr,dt,X,qe,o,d.isDesktop,E,me,e]),vs=n.useCallback(async(t,i)=>{if(!o)return;const l=Kn(t,o),u=i?[...l,t]:l;u.length>0&&rs(o,u);const p=u.map(m=>{if(!ze.current.has(m))return Ie(m)}).filter(Boolean);await Promise.all(p)},[rs,Ie,o]),en=n.useCallback((t,i)=>{const l=i.findIndex(u=>u.path===t);return l===-1||i.length<=1?null:i[l+1]??i[l-1]??null},[]),Re=n.useCallback(async t=>{if(qt.current)qt.current=!1;else if(Me){Ht(!0),kt.current=t;return}o&&(me(o,t.path),vs(t.path,!1)),ge(null),Le(""),pe(""),lt.current="",_t.current="",xe(""),oe(null),f&&P(!0)},[vs,Me,f,o,me]);n.useEffect(()=>{c?.path&&vs(c.path,!1)},[vs,c?.path]),n.useEffect(()=>{if(!c){Ut.current+=1,Ct.current=null,ot(!1);return}if(De===c.path||Ct.current===c.path)return;const t=c.path;Ct.current=t,Zr(c).finally(()=>{Ct.current===t&&(Ct.current=null)})},[cs,Zr,De,c]);const Hs=n.useRef(Me);Hs.current=Me,n.useEffect(()=>eo(({runtimeKey:t,paths:i})=>{const l=c?.path;t!==ga()||!l||Hs.current||!i.includes(K(l))||(Ut.current+=1,Ct.current=null,Je.current=null,Le(""),ge(null),oe(null),hi(u=>u+1))}),[c?.path]),n.useEffect(()=>{if(!c?.path||De!==c.path)return;let t=!1;const i=window.setInterval(()=>{document.hidden||dt(c.path).then(l=>{if(t||!l)return;const u=Je.current;if(!u||u.path!==c.path){Je.current=l;return}const p=l.mtimeMs!==void 0&&u.mtimeMs!==void 0&&l.mtimeMs!==u.mtimeMs,m=l.size!==u.size;!p&&!m||Hs.current||(Je.current=l,oe(null))}).catch(()=>{})},2e3);return()=>{t=!0,window.clearInterval(i)}},[De,dt,c?.path]);const Ii=n.useCallback(()=>{const t=kt.current,i=Gt.current;if(kt.current=null,Gt.current=null,qt.current=!0,Ht(!1),xe(Ks),i){o&&Ze(o,i),c?.path===i&&(t?Re(t):(o&&me(o,null),pe(""),ge(null),Le(""),oe(null),f&&P(!1)));return}if(t){Re(t);return}},[Ks,Re,f,Ze,o,c?.path,me]),Oi=n.useCallback(async()=>{const t=kt.current,i=Gt.current;if(!await Et()){qt.current=!1;return}if(kt.current=null,Gt.current=null,qt.current=!0,Ht(!1),i){o&&Ze(o,i),c?.path===i&&(t?await Re(t):(o&&me(o,null),pe(""),ge(null),Le(""),oe(null),f&&P(!1)));return}if(t){await Re(t);return}},[Re,f,Ze,o,Et,c?.path,me]),tn=n.useCallback(t=>{const i=c?.path===t,l=en(t,Nt);if(i&&Me){Ht(!0),kt.current=l,Gt.current=t;return}if(o&&Ze(o,t),!!i){if(l){Re(l);return}o&&me(o,null),pe(""),ge(null),Le(""),oe(null),f&&P(!1)}},[en,Re,Me,f,Nt,Ze,o,c?.path,me]),Bi=n.useCallback(t=>{if(Z.includes(t))return"open";if(A?.files){const i=t.startsWith(o+"/")?t.slice(o.length+1):t,l=A.files.find(u=>u.path===i);if(l){if(l.index==="A"||l.working_dir==="?")return"git-added";if(l.index==="D")return"git-deleted";if(l.index==="M"||l.working_dir==="M")return"git-modified"}}return null},[Z,A,o]),$i=n.useCallback(t=>{if(!A?.files)return null;const i=t.startsWith(o+"/")?t.slice(o.length+1):t,l=i?`${i}/`:"";let u=0,p=0;for(const m of A.files)m.path.startsWith(l)&&((m.index==="M"||m.working_dir==="M")&&u++,(m.index==="A"||m.working_dir==="?")&&p++);return u+p>0?{modified:u,added:p}:null},[A,o]),Wi=n.useCallback(async t=>{const i=K(t);o&&(hr(o,i),ze.current.has(i)||await Ie(i))},[Ie,o,hr]),_i=n.useMemo(()=>({canRename:Mr,canCreateFile:Dr,canCreateFolder:Pr,canDelete:zr,canReveal:Ar}),[Mr,Dr,Pr,zr,Ar]);function sn(t,i){const l=br[t]??[];return l.map((u,p)=>{const m=u.type==="directory",y=m&&he.includes(u.path),R=c?.path===u.path,U=p===l.length-1;return s.jsxs("li",{className:"relative",children:[i>0&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),U&&s.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),s.jsx($o,{node:u,root:o,isExpanded:y,isActive:R,isMobile:f,isBrowserClient:F,alwaysShowActions:N,status:m?void 0:Bi(u.path),badge:m?$i(u.path):void 0,permissions:_i,downloadFile:r.downloadFile,contextMenuPath:ji,setContextMenuPath:Fi,rightClickMenuPath:Ni,setRightClickMenuPath:Ci,onSelect:Re,onToggle:Wi,onRevealPath:Di,onOpenDialog:Ws}),m&&y&&s.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[is[u.path]?s.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:is[u.path],children:is[u.path]}),s.jsxs(z,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{Ye(u.path)},children:[s.jsx(b,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):null,sn(u.path,i+1)]})]},u.path)})}const Fe=!!(c?.path&&Dn(c.path)),ws=!!(c?.path&&Pn(c.path)),Oe=!!(c?.path&&Mn(c.path)),Gs=!!(c?.path&&(Fs(c.path)||Kt)),rt=Gs&&!Fe&&!Oe,rn=n.useMemo(()=>K(Qe?.path??""),[Qe?.path]),Dt=!!(Qe&&rn&&Ge&&Ge===rn&&!Be&&!tt&&!Fe&&!Oe&&!rt),ft=n.useMemo(()=>ks(o,Ge),[Ge,o]),Ui=!!(c&&(!Fe||ws)&&!Oe&&!rt&&D.length>0),Ki=!!(c&&ft.length>0),_e=!!(c&&!ns&&!Gs&&!Fe&&r.writeFile&&D.length<=It),nt=!!(c?.path&&qn(c.path)),Zt=!!(c?.path&&Bo(c.path)),Pt=!!(c?.path&&dr(c.path)),es=!!(c?.path&&ar(c.path)),qs=!!(c&&!Gs&&!Fe)&&!nt&&!es&&!(Pt&&B==="preview"),Hi=nt&&we==="edit"||Pt&&B==="edit"||Zt&&ue==="text"||!nt&&!Pt&&!Zt&&O==="edit",bs=n.useMemo(()=>Ge?Ea(Ge):null,[Ge]),[nn,Xs]=n.useState(null);n.useEffect(()=>{let t=!1;const i=c?.path;if(!i||bs){Xs(null);return}return Xs(null),Da(i).then(l=>{t||Xs(l)}),()=>{t=!0}},[c?.path,bs]),n.useEffect(()=>{!_e&&O==="edit"&&ve("view")},[_e,O]);const Js="openchamber:files:md-viewer-mode",Qs="openchamber:files:html-viewer-mode",Ys="openchamber:files:json-viewer-mode";n.useEffect(()=>{const t=c?.path;if(!t)return;ve(ae.current[t]??"edit");let i=Qt?"preview":"edit";try{const p=localStorage.getItem(Js);(p==="preview"||p==="edit")&&(i=p)}catch{}ce(ye.current[t]??i);let l=Qt?"preview":"edit";try{const p=localStorage.getItem(Qs);(p==="preview"||p==="edit")&&(l=p)}catch{}G(Te.current[t]??l),re(de.current[t]??(Qt?"preview":"edit"));let u=Qt?"tree":"text";try{const p=localStorage.getItem(Ys);(p==="tree"||p==="text")&&(u=p)}catch{}be(u)},[c?.path,Qt]);const Gi=n.useCallback(t=>{const i=c?.path;i&&(ae.current[i]=t),ve(t)},[c?.path]),qi=n.useCallback(t=>{const i=c?.path;i&&(ye.current[i]=t),ce(t);try{localStorage.setItem(Js,t)}catch{}},[c?.path]),Ue=n.useCallback(()=>we,[we]),Xi=n.useCallback(t=>{be(t);try{localStorage.setItem(Ys,t)}catch{}},[]),Ji=n.useCallback(t=>{const i=c?.path;i&&(Te.current[i]=t),G(t);try{localStorage.setItem(Qs,t)}catch{}},[c?.path]),Qi=n.useCallback(t=>{const i=c?.path;if(i&&(de.current[i]=t),Pe.current&&(clearTimeout(Pe.current),Pe.current=null),st.current!==null&&(cancelAnimationFrame(st.current),st.current=null),t==="edit")xe(lt.current||D),re(t);else{lt.current=ne;const l=i;re("edit"),st.current=requestAnimationFrame(()=>{st.current=requestAnimationFrame(()=>{st.current=null,!(o&&l&&He.getState().byRoot[o]?.selectedPath!==l)&&(ie(u=>u+1),re("preview"))})});return}},[ne,D,o,c?.path]),Zs=n.useCallback(async(t,i)=>{if(!r.writeFile||i===_t.current)return!1;if(!(await r.writeFile(t,i))?.success)return Q.error(e("filesView.toast.writeFileFailed")),!1;lt.current=i,_t.current=i,xe(i);const u=await dt(t).catch(()=>null);return u&&(Je.current=u),!0},[r,dt,e]);n.useEffect(()=>()=>{Pe.current&&(clearTimeout(Pe.current),Pe.current=null),st.current!==null&&(cancelAnimationFrame(st.current),st.current=null)},[se,c?.path]);const Yi=n.useCallback(t=>{if(lt.current=t,!je||!c?.path||se!=="preview"||!r.writeFile)return;Pe.current&&clearTimeout(Pe.current);const i=c.path;Pe.current=setTimeout(()=>{Pe.current=null,Zs(i,t).then(l=>{l&&(us(!0),setTimeout(()=>us(!1),1500))}).catch(l=>{Q.error(l instanceof Error?l.message:e("filesView.toast.saveFailed"))})},Yr)},[je,se,r.writeFile,Zs,c?.path,e]),Zi=n.useMemo(()=>es&&(lt.current||ne)||D,[ne,D,es]),an=n.useCallback(()=>B,[B]);n.useEffect(()=>{const t=l=>{const u=l?"preview":"edit",p=l?"tree":"text";for(const m of Z)ae.current[m]="edit",qn(m)&&(ye.current[m]=u),dr(m)&&(Te.current[m]=u),ar(m)&&(de.current[m]=u);ve("edit"),ce(u),G(u),re(u),be(p);try{localStorage.setItem(Js,u),localStorage.setItem(Qs,u),localStorage.setItem(Ys,p)}catch{}},i=l=>{const u=!!l.detail?.enabled;t(u)};return window.addEventListener("openchamber:file-viewer-preview-mode-changed",i),()=>{window.removeEventListener("openchamber:file-viewer-preview-mode-changed",i)}},[Z]),n.useEffect(()=>{if(!Qe||!o)return;const t=()=>{typeof window>"u"||Rt.current===null&&(Rt.current=window.requestAnimationFrame(()=>{Rt.current=null,As(it=>it+1)}))},i=(it,yt)=>{if(it.state.doc.length!==yt.length)return!1;if(yt.length===0)return!0;const rr=Math.min(128,yt.length);if(it.state.sliceDoc(0,rr)!==yt.slice(0,rr))return!1;const Fn=Math.max(0,yt.length-rr);return it.state.sliceDoc(Fn,yt.length)===yt.slice(Fn)},l=K(Qe.path);if(!l){ms(null),vt.current={key:"",attempts:0};return}const u=`${l}:${Qe.line}:${Qe.column??1}`;if(vt.current.key!==u&&(vt.current={key:u,attempts:0}),c?.path!==l){if(zs)return;Re(Ft(l));return}if(Be||De!==l)return;if(tt||Fe||Oe||rt){ms(null),vt.current={key:"",attempts:0};return}if(!_e)return;if(O!=="edit"){ve("edit");return}const p=$e.current;if(!p){t();return}if(!i(p,ne)){t();return}const m=Math.max(1,Math.min(Qe.line,p.state.doc.lines)),y=p.state.doc.line(m),R=Math.max(1,Qe.column||1),U=Math.max(0,y.to-y.from),mt=Math.min(U,R-1),pt=y.from+mt;if(!(p.state.selection.main.head===pt)||vt.current.attempts===0){vt.current.attempts+=1,p.dispatch({selection:{anchor:pt},effects:jt.scrollIntoView(pt,{y:"center"})}),p.focus(),t();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const it=$e.current;it&&(it.dispatch({selection:{anchor:pt},effects:jt.scrollIntoView(pt,{y:"center"})}),it.focus())}),ms(null),vt.current={key:"",attempts:0}},[_e,zs,ne,wi,tt,Be,Fe,Oe,rt,De,Re,Qe,o,c?.path,ms,O,Ft]),n.useEffect(()=>{if(!_s||!o)return;const t=K(_s);if(!t){Us(null);return}c?.path===t&&(Be||De!==t||(!tt&&!Fe&&!Oe&&!rt&&_e&&O==="edit"&&$e.current?.focus(),Us(null)))},[_e,tt,Be,Fe,Oe,rt,De,_s,o,c?.path,Us,O]);const Mt=n.useCallback(t=>{if(!f||!t||!t.hasFocus||typeof window>"u")return;const i=window.visualViewport;if(!i)return;const l=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,l-(i.offsetTop+i.height))<=0)return;const p=t.state.selection.main.head,m=t.coordsAtPos(p);if(!m)return;const y=Math.round(i.offsetTop+i.height),U=m.bottom+20-y;U<=0||(t.scrollDOM.scrollTop+=U)},[f]);n.useEffect(()=>{if(!f||typeof window>"u")return;const t=()=>{window.requestAnimationFrame(()=>{Mt($e.current)})},i=window.visualViewport;return i?.addEventListener("resize",t),i?.addEventListener("scroll",t,{passive:!0}),document.addEventListener("selectionchange",t),()=>{i?.removeEventListener("resize",t),i?.removeEventListener("scroll",t),document.removeEventListener("selectionchange",t)}},[f,Mt]),Pa("open_go_to_line",t=>{if(!_e||O!=="edit"||f)return!1;const i=t.target;if(i?.closest('[role="dialog"]')||!(i instanceof Node)||!ds.current?.contains(i))return!1;const l=!!i?.closest(".cm-editor");if(!!i?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!l)return!1;Os(!0)});const ys=ht(t=>t.editorFontSize),on=n.useMemo(()=>{if(!c?.path)return[An(v,{fontSize:ys})];const t=ir(c.path),i=[An(v,t?{syntaxColors:!1,fontSize:ys}:{fontSize:ys})],l=bs??nn;return l&&i.push(l),t&&i.push(Ka({language:t,themeName:v.metadata.id,theme:Xa(v)})),J&&i.push(jt.lineWrapping),f&&i.push(jt.updateListener.of(u=>{u.view.hasFocus&&(u.selectionSet||u.focusChanged||u.viewportChanged||u.geometryChanged)&&window.requestAnimationFrame(()=>{Mt(u.view)})})),i},[v,c?.path,bs,nn,J,f,Mt,ys]),ln=n.useMemo(()=>({light:Ve.metadata.id,dark:Ee.metadata.id}),[Ve.metadata.id,Ee.metadata.id]),ts=c?.path&&Oe&&(!xt.allowOutsideWorkspace||xt.outsideFileGrant)?`${c.path}|${xt.allowOutsideWorkspace?"outside":"workspace"}|${xt.outsideFileGrant??""}|${cs}`:"",js=c?.path&&Pt&&B==="preview"&&!d.isVSCode?`${c.path}|${cs}`:"",cn=e("filesView.error.readFileFailed"),{readyKey:un,nonce:ea}=Xn(js,ge,cn),{readyKey:dn,nonce:fn}=Xn(ts,ge,cn),ta=!!(js&&un!==js),mn=!!(ts&&dn!==ts),pn=c?.path&&Fe?ws?`data:${Ma(c.path)};utf8,${encodeURIComponent(D)}`:fi:"",hn=c?.path&&Oe&&ts&&dn===ts?Rn().authenticatedAsset("/api/fs/raw",{path:c.path,allowOutsideWorkspace:xt.allowOutsideWorkspace?"true":void 0,outsideFileGrant:xt.outsideFileGrant,directory:o||void 0}):"",gn=n.useCallback(t=>s.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:s.jsx("iframe",{src:hn,className:"h-full w-full border-0",title:t.name},fn)}),[hn,fn]);n.useEffect(()=>{let t=!1,i="";return(async()=>{if(!c?.path||!Fe||ws){Le("");return}ge(null);const u=await qe(c.path);if(t)return;await(r.readFileBinary?r.readFileBinary(c.path,u).then(m=>m.dataUrl):(async()=>{const m=await kn("/api/fs/raw",{query:{path:c.path,allowOutsideWorkspace:u.allowOutsideWorkspace?"true":void 0,outsideFileGrant:u.outsideFileGrant,directory:o||void 0}});if(!m.ok)throw new Error(e("filesView.error.readFileFailed"));const y=await m.blob();return i=URL.createObjectURL(y),t?(URL.revokeObjectURL(i),i="",""):i})()).then(m=>{t||(Le(m),oe(c.path))}).catch(m=>{t||(Le(""),ge(m instanceof Error?m.message:e("filesView.error.readFileFailed")),oe(null))}).finally(()=>{t||ot(!1)})})(),()=>{t=!0,i&&URL.revokeObjectURL(i)}},[cs,r,Fe,ws,qe,o,c?.path,xt,e]);const sa=n.useCallback(()=>Ls(null),[]),ra=n.useMemo(()=>io({drafts:Br,editingDraftId:gs,commentText:hs,onTextChange:$r,selection:_,isDragging:Ir,fileLabel:c?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:t=>({start:t.startLine,end:t.endLine}),onSave:Gr,onCancel:()=>{We(null),Yt()},onEdit:t=>{Kr(t),We({start:t.startLine,end:t.endLine})},onDelete:Hr}),[Yt,hs,Hr,gs,Br,Gr,Ir,_,c?.path,$r,Kr]),xn=_n(),vn=_n(),er=Oa("unified"),Ke=D.length>It,tr=n.useMemo(()=>Ke?Lo(D):void 0,[D,Ke]),wn=n.useCallback((t,i,l)=>{const u={name:t.name,contents:i,lang:ir(t.path)||void 0},p=m=>s.jsx(qa,{file:Ke&&tr?{...u,cacheKey:`${t.path}:${tr}`}:u,options:{disableFileHeader:!0,overflow:J?"wrap":"scroll",theme:ln,themeType:v.metadata.variant==="dark"?"dark":"light"},className:Ke?"block w-full":"block h-full w-full",style:Ke?void 0:{height:"100%"}},m);return Ke?s.jsx("div",{className:"h-full",children:s.jsx(Ja.Provider,{value:l.virtualizer,children:s.jsx(Qa.Provider,{value:er,children:p(`${t.path}:${er?"pool":"pending"}`)})})}):s.jsx("div",{className:"h-full",children:p(t.path)})},[v.metadata.variant,Ke,tr,ln,er,J]),bn=({exitFullscreenOnly:t=!1,layout:i="floating"}={})=>{if(!c)return null;const l=i==="docked",u=za(Aa("save_file")),p=l?"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",m=(y,R)=>s.jsxs(zt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:R})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:y})]});return s.jsxs("div",{className:p,children:[_e&&Hi&&s.jsxs(s.Fragment,{children:[Wt?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[s.jsx(b,{name:"loader-4",className:"size-3.5 animate-spin"}),e("filesView.editor.saving")]}):je&&gi==="saved"&&!Me?s.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[s.jsx(b,{name:"check",className:"size-3.5"}),e("filesView.editor.saved")]}):Me?m(e(je?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:u}),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{Et()},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:e(je?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:u}),"aria-label":e("filesView.editor.saveAria",{shortcut:u}),children:s.jsx(b,{name:"save-3",className:"size-4"})})):null,m(e(je?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>vi(!je),className:q("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",je?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(je?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":e(je?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:je?s.jsx(b,{name:"file-check-fill",className:"size-4"}):s.jsx(b,{name:"file-check",className:"size-4"})}))]}),s.jsxs(fr,{onOpenChange:Ce,children:[s.jsxs(zt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:"inline-flex",children:s.jsx(mr,{asChild:!0,children:s.jsx(z,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.openInDesktopApp"),"aria-label":e("filesView.editor.openInDesktopApp"),children:s.jsx(b,{name:"file-transfer",className:"size-4"})})})})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:e("filesView.editor.openInDesktopApp")})]}),s.jsxs(pr,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Ti.map(y=>s.jsxs(Ss,{className:"flex items-center gap-2",onClick:()=>{Pi(y)},children:[s.jsx(To,{label:y.label,iconDataUrl:y.iconDataUrl}),s.jsx("span",{className:"typography-ui-label text-foreground",children:y.label})]},y.id)),Vi?s.jsxs(Ss,{className:"flex items-center gap-2",onClick:()=>{Ei(!0)},children:[s.jsx(b,{name:"refresh",className:"size-4"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:e("filesView.editor.refreshApps")})]}):null]})]}),!Fe&&!Oe&&!rt&&s.jsxs(s.Fragment,{children:[m(e(J?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Ne(!J),className:q("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",J?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:e(J?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:s.jsx(b,{name:"text-wrap",className:"size-4"})})),O==="edit"&&s.jsxs(s.Fragment,{children:[m(e("filesView.editor.findInFile"),s.jsx(z,{variant:"ghost",size:"sm",onClick:y=>{le(!ee),y.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(b,{name:"search",className:"size-4"})})),m(e("filesView.editor.goToLine"),s.jsx(z,{variant:"ghost",size:"sm",onClick:y=>{Os(R=>!R),y.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.goToLine"),children:s.jsx(b,{name:"menu-fold-2",className:"size-4"})})),s.jsx(go,{open:Ri,onOpenChange:Os,view:$e.current,variant:"inline"})]})]}),qs&&_e&&!Zt&&!Pt&&s.jsx(cr,{currentMode:O==="view"?"preview":"edit",onToggle:()=>{Gi(O==="view"?"edit":"view")}}),nt&&m(e(Ue()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>qi(Ue()==="preview"?"edit":"preview"),className:q("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",Ue()==="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:e(Ue()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),"aria-label":e(Ue()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:s.jsx(b,{name:Ue()==="preview"?"eye":"eye-off",className:"size-4"})})),dr(c?.path??"")&&s.jsx(cr,{currentMode:an(),onToggle:()=>{Ji(an()==="preview"?"edit":"preview")}}),nt&&Ue()==="preview"&&m(e("filesView.editor.findInFile"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{fs(!0),Er(y=>y+1)},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.findInFile"),children:s.jsx(b,{name:"search",className:"size-4"})})),nt&&Ue()==="preview"&&Mi&&s.jsxs(zt,{children:[s.jsx(At,{asChild:!0,children:s.jsx(z,{variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent","aria-label":e(ls?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{ls?di():D.trim()&&ui(D)},children:ls?s.jsx(b,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(b,{name:"volume-up",className:"size-4"})})}),s.jsx(Lt,{sideOffset:8,children:e(ls?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),es&&s.jsxs(s.Fragment,{children:[s.jsx(cr,{currentMode:se,onToggle:()=>Qi(se==="preview"?"edit":"preview")}),se==="preview"&&s.jsx(z,{variant:"ghost",size:"sm",onClick:async()=>{const y=Nr.current?.getXml();if(Pe.current&&(clearTimeout(Pe.current),Pe.current=null),c?.path&&y){if(!await Zs(c.path,y))return;us(!0),setTimeout(()=>us(!1),1500)}},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.diagram.saveDiagram"),children:xi?s.jsx(b,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(b,{name:"save-3",className:"size-4"})})]}),Zt&&m(e(ue==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Xi(ue==="tree"?"text":"tree"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:e(ue==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:ue==="tree"?s.jsx(b,{name:"code-sslash",className:"size-4"}):s.jsx(b,{name:"node-tree",className:"size-4"})})),Ui&&m(e("filesView.editor.copyFileContents"),s.jsx(z,{variant:"ghost",size:"sm",onClick:async()=>{(await Rs(D)).ok?(kr(!0),Xt.current!==null&&window.clearTimeout(Xt.current),Xt.current=window.setTimeout(()=>{kr(!1)},1200)):Q.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFileContents"),"aria-label":e("filesView.editor.copyFileContents"),children:Si?s.jsx(b,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(b,{name:"clipboard",className:"size-4"})})),Ki&&m(e("filesView.editor.copyFilePathTitle",{path:ft}),s.jsx(z,{variant:"ghost",size:"sm",onClick:async()=>{(await Rs(ft)).ok?(Rr(!0),Jt.current!==null&&window.clearTimeout(Jt.current),Jt.current=window.setTimeout(()=>{Rr(!1)},1200)):Q.error(e("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.copyFilePathTitle",{path:ft}),"aria-label":e("filesView.editor.copyFilePathTitle",{path:ft}),children:ki?s.jsx(b,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):s.jsx(b,{name:"file-copy-2",className:"size-4"})})),r.downloadFile&&m(e("filesView.editor.saveFile"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{const y=r.downloadFile;y&&y(c.path).catch(R=>{console.error("Download failed:",R),Q.error(e("sidebarFilesTree.toast.operationFailed"))})},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.saveFile"),"aria-label":e("filesView.editor.saveFile"),children:s.jsx(b,{name:"download",className:"size-4"})})),t?m(e("filesView.editor.exitFullscreen"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Y(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e("filesView.editor.exitFullscreen"),"aria-label":e("filesView.editor.exitFullscreen"),children:s.jsx(b,{name:"fullscreen-exit",className:"size-4"})})):!f&&a==="full"&&m(e(H?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Y(!H),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:e(H?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":e(H?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:H?s.jsx(b,{name:"fullscreen-exit",className:"size-4"}):s.jsx(b,{name:"fullscreen",className:"size-4"})}))]})},sr=s.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[s.jsx(Qn,{open:zs,onOpenChange:t=>{t||Ht(!0)},children:s.jsxs(Yn,{showCloseButton:!1,className:"max-w-md",children:[s.jsxs(Zn,{children:[s.jsx(ei,{children:e("filesView.unsaved.title")}),s.jsx(ti,{children:e("filesView.unsaved.description")})]}),s.jsxs(si,{children:[s.jsx(z,{variant:"outline",onClick:()=>{Oi()},disabled:Wt,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:e("filesView.unsaved.saveChanges")}),s.jsx(z,{variant:"destructive",onClick:Ii,children:e("filesView.unsaved.discard")})]})]})}),s.jsxs("div",{className:q("flex flex-col flex-shrink-0",L&&"border-b border-border/40"),children:[L?s.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[f&&$&&s.jsx("button",{type:"button",onClick:()=>P(!1),"aria-label":e("filesView.editor.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:s.jsx(b,{name:"arrow-left-s",className:"size-5"})}),f?c?s.jsxs(fr,{children:[s.jsx(mr,{asChild:!0,children:s.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":e("filesView.editor.openFilesAria"),children:[s.jsx(Cs,{filePath:c.path,extension:c.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Hn,{name:c.name}),s.jsx(b,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),s.jsx(pr,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:Nt.map(t=>{const i=c?.path===t.path;return s.jsxs(Ss,{onSelect:l=>{if(l.target.closest("[data-close-open-file]")){l.preventDefault();return}i||Re(t)},className:q("flex min-w-0 items-center justify-between gap-2 overflow-hidden",i&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[s.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[s.jsx(Cs,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx(Hn,{name:t.name})]}),s.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:l=>{l.preventDefault(),l.stopPropagation()},onClick:l=>{l.preventDefault(),l.stopPropagation(),tn(t.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":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(b,{name:"close",className:"size-3.5"})})]},t.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")}):Nt.length>0?s.jsxs("div",{className:"relative min-w-0 flex-1",children:[xr.left&&s.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"}),xr.right&&s.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"}),s.jsx("div",{ref:Ds,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Nt.map(t=>{const i=c?.path===t.path;return s.jsxs("div",{title:ks(o,t.path),className:q("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",i?"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:[s.jsx(Cs,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),s.jsx("button",{type:"button",onClick:()=>{i||Re(t)},className:"max-w-[12rem] truncate text-left",children:t.name}),s.jsx("button",{type:"button",onClick:l=>{l.stopPropagation(),tn(t.path)},className:q("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!i&&!N&&"opacity-0 group-hover:opacity-100"),"aria-label":e("filesView.editor.closeFileAria",{name:t.name}),children:s.jsx(b,{name:"close",className:"size-3.5"})})]},t.path)})})]}):s.jsx("div",{className:"typography-ui-label font-medium truncate",children:e("filesView.editor.selectFile")})]}):null,c?s.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:[ft&&!f?s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:ft,children:ft}):null,s.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:bn({layout:"docked"})})]}):null]}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:s.jsx(or,{ref:xn.setScroller,outerClassName:"h-full min-w-0",className:q("h-full min-w-0",Ke&&"[overflow-anchor:none]"),children:c?Be||mn?I?s.jsx("div",{className:"p-3"}):s.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(b,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.loading")]}):tt?s.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:tt}):Fe?s.jsx("div",{className:"flex h-full items-center justify-center p-3",children:s.jsx("img",{src:pn,alt:c?.name??e("filesView.editor.imageAltFallback"),className:"max-w-full max-h-[70vh] object-contain rounded-md border border-border/30 bg-primary/10"},c.path)}):Oe?gn(c):rt?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),r.downloadFile?s.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=r.downloadFile;!t||!c||t(c.path).catch(i=>{console.error("Download failed:",i),Q.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(b,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):c&&es&&se==="preview"?s.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:s.jsx(ko,{ref:Nr,xml:Zi,onChange:Yi},`${c.path}:${Se}`)}):c&&Zt&&ue==="tree"?s.jsx(lr,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.jsonViewerUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToTextMode")})]}),children:s.jsx("div",{className:"h-full overflow-auto",children:s.jsx(Ga,{jsonString:D,maxHeight:"100%",initiallyExpandedDepth:2})})}):c&&nt&&Ue()==="preview"?s.jsxs("div",{className:"relative h-full min-h-0",children:[s.jsxs("div",{className:"oc-file-preview h-full overflow-auto p-3",ref:t=>{ps.current=t,Bs.current=t},children:[s.jsx(On,{containerRef:ps,filePath:c.path,fileContent:D}),D.length>500*1024&&s.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:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(D.length/1024)})}),s.jsx(lr,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(zn,{content:D,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}),!H&&s.jsx(Wn,{containerRef:Bs,open:Tr,onOpenChange:fs,focusNonce:Vr})]}):c&&Pt&&B==="preview"?ta?s.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:e("common.loading")}):s.jsx("div",{className:"h-full overflow-hidden",children:s.jsx("iframe",{src:!d.isVSCode&&un===js?(()=>{const t=c.path.split("/").map(i=>encodeURIComponent(i)).join("/");return Rn().authenticatedAsset(`/api/fs/serve${t.startsWith("/")?t:`/${t}`}`)})():void 0,srcDoc:d.isVSCode?(()=>{const t=c.path.substring(0,c.path.lastIndexOf("/")+1);return t?D.replace(/<head([^>]*)>/i,`<head$1><base href="${t}">`):D})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:e("filesView.editor.htmlPreviewTitle")},ea)}):c&&qs&&O==="view"?wn(c,Ke?D:ne,xn):s.jsxs("div",{className:q("relative h-full",Dt&&"overflow-hidden"),ref:ds,children:[s.jsx("div",{className:q("h-full",Dt&&"invisible"),children:s.jsx(Ln,{value:ne,onChange:xe,readOnly:!_e,vimMode:Or==="vim",extensions:on,className:"h-full",blockWidgets:ra,onViewReady:t=>{$e.current=t,As(i=>i+1),window.requestAnimationFrame(()=>{Mt(t)})},onViewDestroy:()=>{$e.current&&($e.current=null),As(t=>t+1)},enableSearch:!0,searchOpen:ee,onSearchOpenChange:le,highlightLines:_?{start:Math.min(_.start,_.end),end:Math.max(_.start,_.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(t,i,l)=>{if(!(l instanceof MouseEvent)||l.button!==0)return!1;l.preventDefault();const u=t.state.doc.lineAt(i.from).number;if(_&&!l.shiftKey&&Math.min(_.start,_.end)===u&&Math.max(_.start,_.end)===u)return We(null),Yt(),Tt.current=!1,ut.current=null,Vt(!1),!0;if(f&&_&&!l.shiftKey){const p=Math.min(_.start,_.end,u),m=Math.max(_.start,_.end,u);return We({start:p,end:m}),Tt.current=!1,ut.current=null,Vt(!1),!0}if(Tt.current=!0,ut.current=u,Vt(!0),_&&l.shiftKey){const p=Math.min(_.start,u),m=Math.max(_.end,u);We({start:p,end:m})}else We({start:u,end:u});return!0},mouseover:(t,i,l)=>{if(!(l instanceof MouseEvent)||l.buttons!==1||!Tt.current||ut.current===null)return!1;const u=t.state.doc.lineAt(i.from).number,p=Math.min(ut.current,u),m=Math.max(ut.current,u);return We({start:p,end:m}),Vt(!0),!1},mouseup:()=>(Tt.current=!1,ut.current=null,Vt(!1),!1)}}})}),Dt&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(b,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]}):s.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:e("filesView.editor.pickFileFromTree")})})})]}),na=!!(o&&br[o]),yn=o?is[o]:null,jn=s.jsxs("section",{className:q("flex min-h-0 flex-col overflow-hidden",f?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[s.jsx("div",{className:q("flex flex-col gap-2 py-2",f?"px-3":"px-2"),children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("div",{className:"relative flex-1 min-w-0",children:[s.jsx(b,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),s.jsx(ss,{ref:M,value:E,onChange:t=>V(t.target.value),placeholder:e("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),E.trim().length>0&&s.jsx("button",{type:"button","aria-label":e("filesView.tree.search.clearAria"),className:"absolute right-2 top-2 inline-flex size-4 items-center justify-center text-muted-foreground hover:text-foreground",onClick:()=>{V(""),M.current?.focus()},children:s.jsx(b,{name:"close",className:"size-4"})})]}),s.jsxs(zt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Ws("createFile",{path:T,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFileTitle"),"aria-label":e("filesView.tree.actions.newFileTitle"),children:s.jsx(b,{name:"file-add",className:"size-4"})})})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFileTitle")})]}),s.jsxs(zt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>Ws("createFolder",{path:T,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.newFolderTitle"),"aria-label":e("filesView.tree.actions.newFolderTitle"),children:s.jsx(b,{name:"folder-add",className:"size-4"})})})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.newFolderTitle")})]}),s.jsxs(zt,{children:[s.jsx(At,{asChild:!0,children:s.jsx("span",{className:"inline-flex flex-shrink-0",children:s.jsx(z,{variant:"ghost",size:"sm",onClick:()=>{xs()},className:"size-8 p-0 flex-shrink-0",title:e("filesView.tree.actions.refreshTitle"),"aria-label":e("filesView.tree.actions.refreshTitle"),children:s.jsx(b,{name:"refresh",className:"size-4"})})})}),s.jsx(Lt,{side:"bottom",sideOffset:6,children:e("filesView.tree.actions.refreshTitle")})]})]})}),s.jsx(or,{outerClassName:"flex-1 min-h-0",className:q("py-2",f?"px-3":"px-2"),children:s.jsx("ul",{className:"flex flex-col",children:ci?s.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx(b,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.tree.search.searching")]}):jr.length>0?jr.map(t=>{const i=c?.path===t.path;return s.jsx("li",{children:s.jsxs("button",{type:"button",onClick:()=>{Re(t)},className:q("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",i?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[ai(t.path,t.extension),s.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",style:{direction:"rtl",textAlign:"left"},title:t.path,children:t.relativePath??t.path})]})},t.path)}):yn?s.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[s.jsx("span",{className:"text-[var(--status-error)]",children:yn}),s.jsxs(z,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{xs()},children:[s.jsx(b,{name:"refresh",className:"size-3.5"}),e("filesView.tree.actions.refreshTitle")]})]}):na?sn(o,0):s.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:e("filesView.state.loading")})})})]}),ia=a==="full"&&H&&c&&s.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:s.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[s.jsx("div",{className:"absolute right-4 top-4 z-30",children:bn({exitFullscreenOnly:!0})}),s.jsx(or,{ref:vn.setScroller,outerClassName:"h-full min-w-0",className:q("h-full min-w-0",Ke&&"[overflow-anchor:none]"),children:Be||mn?I?s.jsx("div",{className:"p-4"}):s.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(b,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):tt?s.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:tt}):Fe?s.jsx("div",{className:"flex h-full items-center justify-center p-4",children:s.jsx("img",{src:pn,alt:c.name,className:"max-w-full max-h-full object-contain rounded-md border border-border/30 bg-primary/10"},c.path)}):Oe?gn(c):rt?s.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-3 p-6 text-center",children:[s.jsx("div",{className:"typography-ui-header text-foreground",children:e("filesView.editor.cannotPreviewBinary")}),s.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:e("filesView.editor.binaryFileDescription")}),r.downloadFile?s.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=r.downloadFile;!t||!c||t(c.path).catch(i=>{console.error("Download failed:",i),Q.error(e("sidebarFilesTree.toast.operationFailed"))})},children:[s.jsx(b,{name:"download",className:"mr-2 size-4"}),e("filesView.editor.saveFile")]}):null]}):nt&&Ue()==="preview"?s.jsxs("div",{className:"relative h-full min-h-0",children:[s.jsxs("div",{className:"oc-file-preview h-full overflow-auto p-4",ref:t=>{ps.current=t,$s.current=t},children:[c?s.jsx(On,{containerRef:ps,filePath:c.path,fileContent:D}):null,D.length>500*1024&&s.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:e("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round(D.length/1024)})}),s.jsx(lr,{fallback:s.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[s.jsx("div",{className:"mb-1 font-medium text-destructive",children:e("filesView.error.previewUnavailable")}),s.jsx("div",{className:"text-sm text-muted-foreground",children:e("filesView.error.switchToEditMode")})]}),children:s.jsx(zn,{content:D,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}),s.jsx(Wn,{containerRef:$s,open:Tr,onOpenChange:fs,focusNonce:Vr,className:"right-4 top-16"})]}):qs&&O==="view"?wn(c,Ke?D:ne,vn):s.jsxs("div",{className:q("relative h-full",Dt&&"overflow-hidden"),children:[s.jsx("div",{className:q("h-full",Dt&&"invisible"),children:s.jsx(Ln,{value:ne,onChange:xe,readOnly:!_e,vimMode:Or==="vim",extensions:on,className:"h-full",onViewReady:t=>{$e.current=t,window.requestAnimationFrame(()=>{Mt(t)})},onViewDestroy:()=>{$e.current&&($e.current=null)}})}),Dt&&s.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:s.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[s.jsx(b,{name:"loader-4",className:"size-4 animate-spin"}),e("filesView.state.openingFileAtChange")]})})]})})]})});return s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[s.jsx(Wo,{activeDialog:wt,dialogData:bt,dialogInputValue:ct,onDialogInputChange:Sr,isDialogSubmitting:yi,onDialogSubmit:Li,onClose:sa,inputRef:pi}),ia,f?$?sr:jn:a==="editor-only"?s.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:sr})}):s.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[h>=700&&s.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:jn}),s.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:sr})]})]})};function _o(a){return a+1}export{uu as FilesView};