@vantran-se/openchamber-web 2.0.3 → 2.0.5

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 (265) hide show
  1. package/README.md +20 -28
  2. package/bin/cli.js +3 -1
  3. package/bin/cli.test.js +13 -4
  4. package/bin/lib/DOCUMENTATION.md +4 -1
  5. package/bin/lib/commands-serve.js +9 -0
  6. package/dist/assets/{CodeMirrorCommentWidgets-CWhdh0wf.js → CodeMirrorCommentWidgets-DCAQTLMM.js} +1 -1
  7. package/dist/assets/DiffView-uzNpHBlV.js +4 -0
  8. package/dist/assets/FilesView-Bkq0sjNx.js +17 -0
  9. package/dist/assets/{GitView-DKIjpnu4.js → GitView-BmibZC7n.js} +4 -4
  10. package/dist/assets/{GuestAttachDialog-BIa9jCfL.js → GuestAttachDialog-D7TJG1rt.js} +1 -1
  11. package/dist/assets/GuestSurfacePane-PAcYaFzP.js +1 -0
  12. package/dist/assets/{JsonTreeView-CtI1Mqwo.js → JsonTreeView-BNT2yUVu.js} +1 -1
  13. package/dist/assets/{LinearIssuesView-BD2zLu-r.js → LinearIssuesView-D3Azksju.js} +1 -1
  14. package/dist/assets/MarkdownImageGallery-BGY6tuiK.js +1 -0
  15. package/dist/assets/MarkdownRendererImpl-DJmhQ37f.js +12 -0
  16. package/dist/assets/{OnboardingScreen-B8TxloXZ.js → OnboardingScreen-D_41H2qC.js} +1 -1
  17. package/dist/assets/{PatchDiff--Civs1xY.js → PatchDiff-C0RSqa9W.js} +1 -1
  18. package/dist/assets/{PierreDiffViewer-BlDmw3-A.js → PierreDiffViewer-BBE7tTY2.js} +3 -3
  19. package/dist/assets/{PlanView-DyH2SyCP.js → PlanView-Bqc-xuDe.js} +4 -4
  20. package/dist/assets/PluginPane-DQ0k41Q-.js +3 -0
  21. package/dist/assets/SettingsView-BAiJU5hJ.js +30 -0
  22. package/dist/assets/{SettingsWindow-y9WpZqK6.js → SettingsWindow-DuC4ecLw.js} +1 -1
  23. package/dist/assets/{SubmoduleDiffSummary-DeFmhPFZ.js → SubmoduleDiffSummary-0HgmcMXz.js} +1 -1
  24. package/dist/assets/{ToolOutputDialog-8DmF7_PZ.js → ToolOutputDialog-DdHkQJEE.js} +6 -6
  25. package/dist/assets/{ToolPartDiffPreview-Ca15DKE1.js → ToolPartDiffPreview-DWdN0r5K.js} +2 -2
  26. package/dist/assets/{VirtualizedFileDiff-BfEBad09.js → VirtualizedFileDiff-ClDezf2d.js} +1 -1
  27. package/dist/assets/{WalkthroughView-Cj3K8Xz6.js → WalkthroughView-BJicp0RC.js} +2 -2
  28. package/dist/assets/{appThemeRegistry-DAdawJZn.js → appThemeRegistry-CiuyzfSW.js} +1 -1
  29. package/dist/assets/changesTree-CePHbFcj.js +1 -0
  30. package/dist/assets/commitAndPush-DTKb6IwT.js +1 -0
  31. package/dist/assets/{computeVirtualFileMetrics-RF-KjfUH.js → computeVirtualFileMetrics-kM_zJNMt.js} +2 -2
  32. package/dist/assets/de-BMnfXm-G.js +10 -0
  33. package/dist/assets/es-DKEvCCL6.js +16 -0
  34. package/dist/assets/fr-D9fgE2xE.js +14 -0
  35. package/dist/assets/index-DUke1nme.css +1 -0
  36. package/dist/assets/{index-CL7ZQ94-.js → index-DWB8bR_g.js} +1 -1
  37. package/dist/assets/index-Di6zUe5h.js +41 -0
  38. package/dist/assets/{isDiffPlainText-D2yJ9fO6.js → isDiffPlainText-DOoIsGqs.js} +1 -1
  39. package/dist/assets/{isFilePlainText-BwMEq1Ey.js → isFilePlainText-bt5VHvcd.js} +1 -1
  40. package/dist/assets/ja-BEXad-KW.js +16 -0
  41. package/dist/assets/ko-DGrQ0lEe.js +16 -0
  42. package/dist/assets/{main-quLSA7jc.js → main-BpLQbZC2.js} +2 -2
  43. package/dist/assets/main-CI9DtHJv.js +896 -0
  44. package/dist/assets/{markdown-shiki.worker-CahLvHIq.js → markdown-shiki.worker-Bg8SoAJJ.js} +8 -5
  45. package/dist/assets/markdownCore-DK2KK5RW.js +7 -0
  46. package/dist/assets/{miniChat-D-lJJibr.js → miniChat-CIWaR8wG.js} +2 -2
  47. package/dist/assets/{mobile-VTtphbW6.js → mobile-CnWKEYIP.js} +2 -2
  48. package/dist/assets/patchFileDiff-Cqn0C0az.js +13 -0
  49. package/dist/assets/pl-BlhkmR5b.js +16 -0
  50. package/dist/assets/pt-BR-Bs96Ew9I.js +16 -0
  51. package/dist/assets/{renderElectronMiniChatApp-DF7ch5eM.js → renderElectronMiniChatApp-D9t0-9nV.js} +2 -2
  52. package/dist/assets/renderMobileApp-CW7fVs_s.js +25 -0
  53. package/dist/assets/runtimeEndpointReset-D0PcCb3K.js +27 -0
  54. package/dist/assets/scheduledTasksApi-Dahv3ws0.js +1 -0
  55. package/dist/assets/{shikiHighlight-_HeCCHx1.js → shikiHighlight-l-MbaNS4.js} +1 -1
  56. package/dist/assets/{textMateThemeFromAppTheme-C95XdFGj.js → textMateThemeFromAppTheme-C-kGcOpD.js} +1 -1
  57. package/dist/assets/tr-CehUK1M9.js +7 -0
  58. package/dist/assets/uk-Bno5WGNz.js +16 -0
  59. package/dist/assets/{useAppFontEffects-ZM9ij19-.js → useAppFontEffects-DDjuwVqi.js} +160 -156
  60. package/dist/assets/{useInlineCommentController-CkfxMJPy.js → useInlineCommentController-Clg8EO3A.js} +2 -2
  61. package/dist/assets/{useRootScrollLock-BtiAC1fj.js → useRootScrollLock-nDcRrgJ1.js} +2 -2
  62. package/dist/assets/{vendor-codemirror-language-data-U-lXzXNK.js → vendor-codemirror-language-data-oKF0MAwd.js} +2 -2
  63. package/dist/assets/vendor-opencode-client-DSZl7jSi.js +12 -0
  64. package/dist/assets/vendor-zod-BSoePkpP.js +39 -0
  65. package/dist/assets/{web-components-C583Pmfm.js → web-components-Bc1WPd4i.js} +1 -1
  66. package/dist/assets/zh-CN-DnAweIWo.js +16 -0
  67. package/dist/assets/zh-TW-BbBBK25p.js +16 -0
  68. package/dist/index.html +5 -5
  69. package/dist/mini-chat.html +5 -5
  70. package/dist/mobile.html +5 -5
  71. package/package.json +3 -3
  72. package/server/index.d.ts +2 -0
  73. package/server/index.js +196 -52
  74. package/server/lib/agent-tool/DOCUMENTATION.md +5 -0
  75. package/server/lib/agent-tool/runtime.js +89 -51
  76. package/server/lib/agent-tool/runtime.test.js +17 -0
  77. package/server/lib/browser-control/DOCUMENTATION.md +14 -2
  78. package/server/lib/event-stream/DOCUMENTATION.md +2 -2
  79. package/server/lib/event-stream/global-hub.js +45 -7
  80. package/server/lib/event-stream/global-hub.test.js +128 -2
  81. package/server/lib/event-stream/global-ws-bridge.js +3 -1
  82. package/server/lib/event-stream/rebind.test.js +1 -0
  83. package/server/lib/event-stream/runtime.js +1 -2
  84. package/server/lib/event-stream/upstream-reader.js +3 -2
  85. package/server/lib/git/DOCUMENTATION.md +1 -1
  86. package/server/lib/git/service.js +22 -0
  87. package/server/lib/git/service.test.js +8 -0
  88. package/server/lib/guests/DOCUMENTATION.md +4 -3
  89. package/server/lib/guests/catalog.js +19 -1
  90. package/server/lib/guests/catalog.test.js +22 -0
  91. package/server/lib/guests/html-styles.js +5 -3
  92. package/server/lib/guests/html-styles.test.js +3 -1
  93. package/server/lib/guests/routes.js +11 -3
  94. package/server/lib/guests/service.js +5 -0
  95. package/server/lib/guests/surface.js +55 -9
  96. package/server/lib/guests/surface.test.js +56 -6
  97. package/server/lib/notifications/DOCUMENTATION.md +10 -0
  98. package/server/lib/notifications/emit-route.js +118 -0
  99. package/server/lib/notifications/emit-route.test.js +112 -0
  100. package/server/lib/openchamber-control/actions.js +16 -2
  101. package/server/lib/openchamber-control/service.js +23 -0
  102. package/server/lib/openchamber-control/service.test.js +31 -0
  103. package/server/lib/openchamber-sessions/fork-inheritance.js +103 -0
  104. package/server/lib/openchamber-sessions/fork-inheritance.test.js +69 -0
  105. package/server/lib/openchamber-sessions/routes.js +11 -0
  106. package/server/lib/openchamber-sessions/routes.test.js +18 -0
  107. package/server/lib/opencode/DOCUMENTATION.md +23 -23
  108. package/server/lib/opencode/bootstrap-runtime.js +14 -1
  109. package/server/lib/opencode/compatibility.js +6 -3
  110. package/server/lib/opencode/compatibility.test.js +8 -0
  111. package/server/lib/opencode/config-entity-v2.test.js +27 -0
  112. package/server/lib/opencode/config-paths.test.js +12 -0
  113. package/server/lib/opencode/config-v2.d.ts +2 -0
  114. package/server/lib/opencode/config-v2.js +42 -0
  115. package/server/lib/opencode/config-v2.test.js +17 -0
  116. package/server/lib/opencode/core-routes.js +20 -4
  117. package/server/lib/opencode/core-routes.test.js +41 -0
  118. package/server/lib/opencode/env-runtime.js +1 -8
  119. package/server/lib/opencode/feature-routes-runtime.js +2 -1
  120. package/server/lib/opencode/lifecycle.js +156 -2
  121. package/server/lib/opencode/lifecycle.test.js +255 -1
  122. package/server/lib/opencode/managed-config-file.js +18 -6
  123. package/server/lib/opencode/managed-config-file.test.js +23 -7
  124. package/server/lib/opencode/mcp.js +7 -2
  125. package/server/lib/opencode/network-runtime.js +16 -7
  126. package/server/lib/opencode/network-runtime.test.js +29 -1
  127. package/server/lib/opencode/npm-registry-config.d.ts +1 -0
  128. package/server/lib/opencode/npm-registry-config.js +123 -0
  129. package/server/lib/opencode/npm-registry-config.test.js +167 -0
  130. package/server/lib/opencode/npm-registry.js +5 -6
  131. package/server/lib/opencode/npm-registry.test.js +30 -0
  132. package/server/lib/opencode/openchamber-routes.js +29 -11
  133. package/server/lib/opencode/openchamber-routes.test.js +18 -0
  134. package/server/lib/opencode/project-directory-runtime.js +8 -0
  135. package/server/lib/opencode/project-directory-runtime.test.js +13 -0
  136. package/server/lib/opencode/provider-source-route.test.js +59 -0
  137. package/server/lib/opencode/providers.js +3 -0
  138. package/server/lib/opencode/providers.test.js +62 -0
  139. package/server/lib/opencode/proxy.js +53 -16
  140. package/server/lib/opencode/routes-upgrade.test.js +1 -1
  141. package/server/lib/opencode/routes.js +36 -1
  142. package/server/lib/opencode/server-startup-runtime.js +25 -0
  143. package/server/lib/opencode/server-startup-runtime.test.js +67 -1
  144. package/server/lib/opencode/server-utils-runtime.js +5 -0
  145. package/server/lib/opencode/settings-helpers.js +10 -0
  146. package/server/lib/opencode/settings-helpers.test.js +2 -2
  147. package/server/lib/opencode/settings-registry.json +17 -0
  148. package/server/lib/opencode/settings-runtime.js +1 -0
  149. package/server/lib/opencode/shared-service-runtime.js +155 -0
  150. package/server/lib/opencode/shared-service-runtime.test.js +180 -0
  151. package/server/lib/opencode/shared.js +49 -4
  152. package/server/lib/opencode/shared.test.js +78 -1
  153. package/server/lib/opencode/shutdown-runtime.js +14 -5
  154. package/server/lib/opencode/shutdown-runtime.test.js +77 -2
  155. package/server/lib/opencode/skill-routes.js +28 -12
  156. package/server/lib/opencode/skill-routes.test.js +121 -1
  157. package/server/lib/opencode/startup-pipeline-runtime.js +5 -4
  158. package/server/lib/opencode/startup-pipeline-runtime.test.js +18 -7
  159. package/server/lib/opencode/upgrade-capability.js +0 -14
  160. package/server/lib/opencode/v1-migration-topup.js +21 -15
  161. package/server/lib/opencode/v1-migration-topup.test.js +14 -6
  162. package/server/lib/opencode/v2-install.d.ts +1 -0
  163. package/server/lib/opencode/v2-install.js +8 -7
  164. package/server/lib/opencode/v2-install.test.js +13 -4
  165. package/server/lib/opencode/watcher.js +3 -1
  166. package/server/lib/opencode/watcher.test.js +54 -0
  167. package/server/lib/opencode/websearch-config.js +13 -1
  168. package/server/lib/quota/providers/kimi.js +1 -1
  169. package/server/lib/realtime-proxy.js +5 -1
  170. package/server/lib/realtime-proxy.test.js +29 -0
  171. package/server/lib/relay/tunnel-host.js +4 -1
  172. package/server/lib/relay/tunnel-host.test.js +11 -0
  173. package/server/lib/session-assist/DOCUMENTATION.md +17 -5
  174. package/server/lib/session-assist/runtime.js +19 -2
  175. package/server/lib/session-assist/runtime.test.js +8 -0
  176. package/server/lib/session-goal/DOCUMENTATION.md +11 -0
  177. package/server/lib/small-model/DOCUMENTATION.md +11 -10
  178. package/server/lib/small-model/index.js +27 -32
  179. package/server/lib/small-model/index.test.js +28 -16
  180. package/server/lib/spaces/DOCUMENTATION.md +404 -32
  181. package/server/lib/spaces/code-in-bait.js +145 -6
  182. package/server/lib/spaces/code-in.js +10 -150
  183. package/server/lib/spaces/code-in.test.js +7 -83
  184. package/server/lib/spaces/code-out.js +1819 -0
  185. package/server/lib/spaces/code-out.test.js +3945 -0
  186. package/server/lib/spaces/code-transfer.js +173 -0
  187. package/server/lib/spaces/command-stream.test.js +181 -0
  188. package/server/lib/spaces/dispatcher.js +670 -0
  189. package/server/lib/spaces/dispatcher.test.js +582 -0
  190. package/server/lib/spaces/gatekeeper-channel.js +61 -7
  191. package/server/lib/spaces/gatekeeper-channel.test.js +43 -7
  192. package/server/lib/spaces/gatekeeper-program.cjs +68 -14
  193. package/server/lib/spaces/gatekeeper-program.test.js +118 -3
  194. package/server/lib/spaces/hardening.js +20 -4
  195. package/server/lib/spaces/hardening.test.js +18 -3
  196. package/server/lib/spaces/host-git.js +7 -4
  197. package/server/lib/spaces/host-git.test.js +6 -2
  198. package/server/lib/spaces/host.js +310 -0
  199. package/server/lib/spaces/host.test.js +273 -0
  200. package/server/lib/spaces/journey.js +552 -0
  201. package/server/lib/spaces/journey.test.js +589 -0
  202. package/server/lib/spaces/layout.js +42 -8
  203. package/server/lib/spaces/manager.js +4 -3
  204. package/server/lib/spaces/manager.test.js +6 -0
  205. package/server/lib/spaces/places/code-out.docker.live.test.js +412 -0
  206. package/server/lib/spaces/places/contract-suite.js +36 -0
  207. package/server/lib/spaces/places/dispatcher.docker.live.test.js +296 -0
  208. package/server/lib/spaces/places/docker-live-support.js +27 -4
  209. package/server/lib/spaces/places/docker.js +33 -5
  210. package/server/lib/spaces/places/docker.test.js +42 -3
  211. package/server/lib/spaces/places/escape-suite.js +118 -14
  212. package/server/lib/spaces/places/fake-docker.js +3 -1
  213. package/server/lib/spaces/places/grants.docker.live.test.js +197 -0
  214. package/server/lib/spaces/places/memory-place.js +24 -1
  215. package/server/lib/spaces/places/registry.js +1 -1
  216. package/server/lib/spaces/places/server.docker.live.test.js +69 -33
  217. package/server/lib/spaces/places/sessions.docker.live.test.js +222 -0
  218. package/server/lib/spaces/routes.js +216 -0
  219. package/server/lib/spaces/routes.test.js +213 -0
  220. package/server/lib/spaces/run-command.js +261 -8
  221. package/server/lib/spaces/run-command.test.js +193 -3
  222. package/server/lib/spaces/space-events.js +153 -0
  223. package/server/lib/spaces/space-events.test.js +160 -0
  224. package/server/lib/spaces/space-opencode.js +52 -0
  225. package/server/lib/spaces/space-opencode.test.js +41 -0
  226. package/server/lib/spaces/space-records.js +150 -0
  227. package/server/lib/spaces/space-records.test.js +113 -0
  228. package/server/lib/spaces/space-sessions.js +210 -0
  229. package/server/lib/spaces/space-sessions.test.js +161 -0
  230. package/server/lib/spaces/websocket.js +329 -0
  231. package/server/lib/spaces/websocket.test.js +345 -0
  232. package/server/lib/ui-auth/ui-auth.js +8 -2
  233. package/server/lib/ui-auth/ui-auth.test.js +29 -0
  234. package/server/opencode-proxy.test.js +271 -0
  235. package/server/proxy-headers.js +8 -2
  236. package/server/proxy-headers.test.js +20 -0
  237. package/dist/assets/DiffView-CX3wAX2S.js +0 -4
  238. package/dist/assets/FilesView-OL3CON3r.js +0 -17
  239. package/dist/assets/GuestSurfacePane-B_cqX5I5.js +0 -1
  240. package/dist/assets/MarkdownImageGallery-DFiTFZgj.js +0 -1
  241. package/dist/assets/MarkdownRendererImpl-DZm5sf1W.js +0 -12
  242. package/dist/assets/PluginPane-BibJit86.js +0 -3
  243. package/dist/assets/SettingsView-h-VpVO47.js +0 -29
  244. package/dist/assets/commitAndPush-BIPfOMXY.js +0 -1
  245. package/dist/assets/de-BqCNGROu.js +0 -10
  246. package/dist/assets/es-BTPpTRgN.js +0 -16
  247. package/dist/assets/fr-hxbzMdAg.js +0 -14
  248. package/dist/assets/index-CLcM8HKx.css +0 -1
  249. package/dist/assets/index-CvLgnuNI.js +0 -41
  250. package/dist/assets/ja-_zLwwYiy.js +0 -16
  251. package/dist/assets/ko-CFn3Dzhc.js +0 -16
  252. package/dist/assets/main-BLJaug9I.js +0 -896
  253. package/dist/assets/markdownCore-DS9FdwrI.js +0 -5
  254. package/dist/assets/patchFileDiff-D9iBcTEi.js +0 -13
  255. package/dist/assets/pl-DFHE7xac.js +0 -16
  256. package/dist/assets/pt-BR-CUjZF179.js +0 -16
  257. package/dist/assets/renderMobileApp-CNQhdXsi.js +0 -25
  258. package/dist/assets/runtimeEndpointReset-DeaERc0M.js +0 -27
  259. package/dist/assets/scheduledTasksApi-BD6Vx9pu.js +0 -1
  260. package/dist/assets/tr-BB6sA_zH.js +0 -7
  261. package/dist/assets/uk-CB4o8g-o.js +0 -16
  262. package/dist/assets/vendor-opencode-client-_BAHQo4R.js +0 -12
  263. package/dist/assets/vendor-zod-Gea9uBlY.js +0 -39
  264. package/dist/assets/zh-CN-BRyDuWhc.js +0 -16
  265. package/dist/assets/zh-TW-BDGbWA1Q.js +0 -16
@@ -0,0 +1,17 @@
1
+ import{f as Re,R as i,c as Ei,j as r,r as ht}from"./vendor-react-BUCujlKS.js";import{a as tt,h as en,Z as Mo,_ as Do,$ as zo,a0 as Lo,x as et,u as mt,eb as Ao,J as Vi,C as Io,a4 as Pi,e8 as Oo,e as Bo,e9 as $o,a3 as _o,ea as Wo}from"./index-Di6zUe5h.js";import{f as st,z as Mi,ai as sa,cf as Uo,h as W,kI as Ko,g8 as Ho,X as Cs,B as I,I as E,kJ as qo,aA as Ns,gZ as Go,gX as Xo,_ as Jo,T as Zo,bj as Yo,K as Qo,ak as el,cA as tl,eI as Di,iD as sl,gu as rl,t as re,l as zi,ay as Kr,ct as bs,da as nl,b as il,kK as ys,c1 as al,az as Hr,kL as qr,cu as Li,cv as Ai,kM as Ii,kN as Oi,kO as ol,kP as ll,kQ as cl,hE as ul,kR as dl,kS as fl,kT as ml,c2 as ra,c3 as na,c4 as ia,c5 as aa,c6 as oa,c7 as la,as as tn,at as sn,av as rn,bh as ur,c8 as Gr,aB as ar,cp as Xr,ae as Mt,af as Dt,ag as zt,b$ as hl,c0 as pl,g as fr,bi as gl,cz as xl}from"./useAppFontEffects-DDjuwVqi.js";import{l as vl,az as wl,ay as bl,Z as yl,_ as jl,$ as Nl,a0 as Sl,a1 as Cl}from"./runtimeEndpointReset-D0PcCb3K.js";import{c as Bi,s as Fl,P as js,C as kl}from"./shikiHighlight-l-MbaNS4.js";import{a as Rl}from"./vendor-codemirror-state-C9awkmn-.js";import{E as Lt}from"./vendor-codemirror-view-CiLROUVV.js";import{V as Tl,J as El,F as Vl}from"./JsonTreeView-BNT2yUVu.js";import{ensurePierreThemeRegistered as $i,getResolvedShikiTheme as Pl}from"./appThemeRegistry-CiuyzfSW.js";import{V as Ml,W as Dl}from"./Virtualizer-CZlLSacm.js";import{V as zl}from"./Virtualizer-D_a8gKmg.js";import{D as Ll}from"./vendor-react-drawio-Ct3Q0DsD.js";import{a as Al,u as or,b as Il,g as Ol,h as Bl}from"./scheduledTasksApi-Dahv3ws0.js";import{I as $l,u as _l,n as Wl}from"./useInlineCommentController-Clg8EO3A.js";import{b as Ul}from"./CodeMirrorCommentWidgets-DCAQTLMM.js";import"./vendor-scheduler-7OC5HNn7.js";import"./vendor-zod-BSoePkpP.js";import"./vendor-vite-runtime-DD1OZmLC.js";import"./vendor-zustand-BAGL70zf.js";import"./vendor-opencode-client-DSZl7jSi.js";import"./vendor-simplewebauthn-browser-VDA66rT_.js";import"./vendor-base-ui-CsXYnR5c.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"./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-tanstack-react-virtual-ClYN8CzB.js";import"./vendor-tanstack-virtual-core-BewVQryB.js";import"./vendor-framer-motion-Bq3iTZ6r.js";import"./vendor-motion-dom-DcCgeG69.js";import"./vendor-motion-utils-BGh8QBgx.js";import"./contextPanelEmbeddedChat-CirXEPJq.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-oKF0MAwd.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-BuBPBC3R.js";import"./vendor-tailwind-merge-CPcsbTWB.js";import"./vendor-fuse.js-Dw8P0qyA.js";import"./GuestAttachDialog-D7TJG1rt.js";import"./PluginPane-DQ0k41Q-.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-Bc1WPd4i.js";import"./computeVirtualFileMetrics-kM_zJNMt.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-bt5VHvcd.js";import"./textMateThemeFromAppTheme-C-kGcOpD.js";function _i(n){const e=Re.c(41),{containerRef:s,filePath:a,fileContent:w}=n,{t:f}=st(),v=Mi(Yl),d=Mi(Zl),x=sa(),p=Uo(Jl),[m,b]=i.useState(null),[y,F]=i.useState(""),[N,S]=i.useState(!1),g=i.useRef(!1),l=i.useRef(null),T=i.useRef(null),[R,M]=i.useState(null);let D;e[0]===Symbol.for("react.memo_cache_sentinel")?(D=()=>{b(null),F(""),S(!1),g.current=!1,T.current=null,M(null)},e[0]=D):D=e[0];const A=D;let k,V;e[1]!==s?(k=()=>{const K=s.current;if(!K)return;const ie=()=>{if(g.current)return;const ae=window.getSelection(),fe=ae?.toString().trim()??"";if(!ae||!fe||ae.rangeCount===0){A();return}const me=ae.getRangeAt(0);if(!K.contains(me.commonAncestorContainer)){A();return}const le=me.getBoundingClientRect();T.current=me.cloneRange(),F(fe),b({x:le.left+le.width/2,y:le.top-10})},_=ae=>{l.current?.contains(ae.target)||g.current&&A()};return document.addEventListener("selectionchange",ie),document.addEventListener("pointerdown",_),()=>{document.removeEventListener("selectionchange",ie),document.removeEventListener("pointerdown",_)}},V=[s,A],e[1]=s,e[2]=k,e[3]=V):(k=e[2],V=e[3]),i.useEffect(k,V);let z;e[4]!==w?(z=K=>{const ie=he=>w.slice(0,he).split(`
2
+ `).length,_=Gl,ae=(he,ve)=>{for(const Ee of _(he)){const ye=w.indexOf(Ee,ve);if(ye>=0)return ye}return-1},fe=K.length>=8?w.indexOf(K):-1;if(fe>=0){const he=ie(fe);return{start:he,end:he+K.split(`
3
+ `).length-1}}const me=K.split(`
4
+ `).map(ql).filter(Boolean);if(me.length===0)return null;const le=ae(me[0],0);if(le<0)return null;const be=ie(le);if(me.length===1)return{start:be,end:be};const xe=ae(me[me.length-1],le);return xe<0?null:{start:be,end:Math.max(be,ie(xe))}},e[4]=w,e[5]=z):z=e[5];const B=z;let U;e[6]===Symbol.for("react.memo_cache_sentinel")?(U=()=>{const K=T.current;if(!K){M(null);return}M(Ko(K))},e[6]=U):U=e[6];const Y=U;let te,ee;e[7]!==N?(te=()=>{if(!N)return;let K=null;const ie=()=>{K===null&&(K=window.requestAnimationFrame(()=>{K=null,Y()}))};return document.addEventListener("scroll",ie,{capture:!0,passive:!0}),window.addEventListener("resize",ie),()=>{K!==null&&window.cancelAnimationFrame(K),document.removeEventListener("scroll",ie,{capture:!0}),window.removeEventListener("resize",ie)}},ee=[N,Y],e[7]=N,e[8]=te,e[9]=ee):(te=e[8],ee=e[9]),i.useEffect(te,ee);let G;e[10]!==y?(G=()=>{y&&(S(!0),g.current=!0,Y(),window.getSelection()?.removeAllRanges())},e[10]=y,e[11]=G):G=e[11];const X=G;let J;e[12]!==p||e[13]!==v||e[14]!==x||e[15]!==a||e[16]!==d||e[17]!==B||e[18]!==y?(J=K=>{const ie=v??(d?"draft":null);if(!y||!ie||!x){A();return}const _=B(y);p({directory:x,sessionKey:ie},{source:"file-quote",fileLabel:a,startLine:_?.start??0,endLine:_?.end??0,code:y,language:"",text:K.trim()}),A(),queueMicrotask(Hl)},e[12]=p,e[13]=v,e[14]=x,e[15]=a,e[16]=d,e[17]=B,e[18]=y,e[19]=J):J=e[19];const q=J;if(!m)return null;let Q;e[20]!==N||e[21]!==B||e[22]!==y?(Q=N?B(y):null,e[20]=N,e[21]=B,e[22]=y,e[23]=Q):Q=e[23];const _e=Q;let ne;e[24]!==m.x||e[25]!==m.y?(ne={left:m.x,top:m.y,transform:"translate(-50%, -100%)"},e[24]=m.x,e[25]=m.y,e[26]=ne):ne=e[26];let Te;e[27]!==N||e[28]!==R?(Te=N&&R&&R.length>0?Ei.createPortal(r.jsx("div",{className:"pointer-events-none fixed inset-0 z-40",children:R.map(Kl)}),document.body):null,e[27]=N,e[28]=R,e[29]=Te):Te=e[29];let De;e[30]!==N||e[31]!==a||e[32]!==_e||e[33]!==X||e[34]!==q||e[35]!==f?(De=N?r.jsx("div",{className:"w-[min(420px,80vw)]",children:r.jsx($l,{fileLabel:a,lineRange:_e?{start:_e.start,end:_e.end}:void 0,onSave:q,onCancel:A})}):r.jsx("div",{className:W("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:r.jsx("button",{type:"button",onClick:X,className:W("px-3.5 py-1.5 rounded-full","text-sm font-medium","text-foreground","hover:bg-[var(--interactive-hover)]","transition-colors duration-150"),title:f("chat.textSelection.title.commentOnSelection"),children:f("chat.textSelection.actions.comment")})}),e[30]=N,e[31]=a,e[32]=_e,e[33]=X,e[34]=q,e[35]=f,e[36]=De):De=e[36];let ze;return e[37]!==ne||e[38]!==Te||e[39]!==De?(ze=Ei.createPortal(r.jsxs("div",{ref:l,className:"fixed z-50",style:ne,children:[Te,De]}),document.body),e[37]=ne,e[38]=Te,e[39]=De,e[40]=ze):ze=e[40],ze}function Kl(n,e){return r.jsx("div",{className:"oc-chat-comment-rect absolute",style:{left:n.left,top:n.top,width:n.width,height:n.height}},e)}function Hl(){Ho()}function ql(n){return n.trim()}function Gl(n){const e=n.trim();return[e,e.slice(0,32),e.split(" ").slice(0,4).join(" ")].filter(Xl)}function Xl(n){return n.length>=8}function Jl(n){return n.addDraft}function Zl(n){return n.newSessionDraft?.open}function Yl(n){return n.currentSessionId}const Ql=(n,e)=>{if(!e)return null;const s=Number.parseInt(n.trim(),10);return!Number.isFinite(s)||s<1?null:Math.min(s,e.state.doc.lines)},Wi=(n,e)=>{const s=n.state.doc.lineAt(e.main.head);return{lineNumber:s.number,character:e.main.head-s.from+1,selection:e}},Ui=(n,e,s)=>{const a=n.state.doc.line(e),w=Math.max(1,Math.min(s,a.length+1)),f=a.from+w-1;n.dispatch({selection:Rl.cursor(f),effects:Lt.scrollIntoView(f,{y:"center"})})};function ec({open:n,onOpenChange:e,view:s,variant:a="overlay"}){const{t:w}=st(),[f,v]=i.useState(""),d=i.useRef(null),x=i.useRef(!1),p=i.useRef(null),m=i.useRef(null),b=i.useMemo(()=>Ql(f,s),[f,s]);i.useEffect(()=>{!n||!s||(x.current=!1,d.current=Wi(s,s.state.selection),v(""))},[n,s]),i.useEffect(()=>{n&&window.requestAnimationFrame(()=>{m.current?.focus(),m.current?.select()})},[n]),i.useEffect(()=>{if(!(!n||!s||!d.current)){if(b===null){const{selection:g}=d.current;s.dispatch({selection:g,effects:Lt.scrollIntoView(g.main.from,{y:"center"})});return}Ui(s,b,d.current.character)}},[b,n,s]);const y=i.useCallback(()=>{if(!s||x.current||!d.current)return;const{selection:g}=d.current;s.dispatch({selection:g,effects:Lt.scrollIntoView(g.main.from,{y:"center"})})},[s]),F=i.useCallback(g=>{g||y(),e(g)},[e,y]),N=i.useCallback(()=>{!s||b===null||!d.current||(x.current=!0,Ui(s,b,d.current.character),e(!1),s.focus())},[b,e,s]);i.useEffect(()=>{if(!n)return;const g=T=>{const R=p.current,M=T.target;!R||!(M instanceof Node)||R.contains(M)||F(!1)},l=T=>{T.key==="Escape"&&(T.preventDefault(),F(!1))};return document.addEventListener("pointerdown",g,!0),document.addEventListener("keydown",l,!0),()=>{document.removeEventListener("pointerdown",g,!0),document.removeEventListener("keydown",l,!0)}},[F,n,a]);const S=i.useMemo(()=>{if(!s)return w("goToLineDialog.helper.editorUnavailable");if(b===null){const g=d.current??Wi(s,s.state.selection);return w("goToLineDialog.helper.currentLineRange",{current:g.lineNumber,max:s.state.doc.lines})}return w("goToLineDialog.helper.goToLine",{line:b})},[b,w,s]);return a==="inline"?n?r.jsxs("div",{ref:p,className:"ml-1 flex h-6 items-center gap-1",children:[r.jsx(Cs,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:f,onChange:g=>v(g.target.value),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),N())},placeholder:w("goToLineDialog.field.linePlaceholderShort"),className:"h-6 w-20 rounded-md border-border/70 bg-transparent px-2 typography-meta"}),r.jsx(I,{variant:"outline",size:"xs",onClick:N,disabled:!s||b===null,className:"h-6 px-2",children:w("goToLineDialog.actions.go")})]}):null:r.jsx("div",{ref:p,className:W("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",n?"pointer-events-auto translate-y-0 opacity-100":"pointer-events-none -translate-y-1 opacity-0"),children:r.jsxs("div",{className:"min-w-0",children:[r.jsx(Cs,{ref:m,type:"number",min:1,step:1,inputMode:"numeric",value:f,onChange:g=>v(g.target.value),onKeyDown:g=>{g.key==="Enter"&&(g.preventDefault(),N())},placeholder:w("goToLineDialog.field.linePlaceholder"),className:"h-8 w-full rounded-md border-border/70 bg-surface-elevated/60 typography-ui-label"}),r.jsx("div",{className:"mt-2 rounded-md bg-primary/15 px-3 py-1.5 typography-ui-label text-foreground/95",children:S})]})})}const tc=(n,e)=>{const s=e.trim().toLowerCase(),a=[];if(!s)return a;const w=n.toLowerCase();let f=0;for(;;){const v=w.indexOf(s,f);if(v===-1)break;a.push({start:v,end:v+s.length}),f=v+s.length}return a},mr="data-md-find",Jr="data-md-find-current",ca="rounded-[2px] bg-status-warning/30 text-foreground",sc="rounded-[2px] bg-status-warning/60 text-foreground",rc=120,nc=n=>n instanceof Element&&n.hasAttribute(mr),ic=n=>n.target instanceof Element&&n.target.hasAttribute(mr)?!0:[...n.addedNodes].some(e=>nc(e)),ua=n=>{const e=new Set;n.querySelectorAll(`mark[${mr}]`).forEach(s=>{const a=s.parentNode;a&&(a.replaceChild(document.createTextNode(s.textContent??""),s),e.add(a))}),e.forEach(s=>s.normalize())},ac=(n,e)=>{ua(n);const s=e.trim().toLowerCase();if(!s)return[];const a=[],w=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,{acceptNode(v){const d=v.parentElement;return!d||d.closest("svg, script, style")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),f=[];for(;w.nextNode();){const v=w.currentNode;v instanceof Text&&f.push(v)}for(const v of f){const d=v.nodeValue??"";if(!d)continue;const x=tc(d,s);if(x.length===0)continue;const p=v.parentNode;if(!p)continue;const m=document.createDocumentFragment();let b=0;for(const y of x){y.start>b&&m.appendChild(document.createTextNode(d.slice(b,y.start)));const F=document.createElement("mark");F.setAttribute(mr,""),F.className=ca,F.textContent=d.slice(y.start,y.end),m.appendChild(F),a.push(F),b=y.end}b<d.length&&m.appendChild(document.createTextNode(d.slice(b))),p.replaceChild(m,v)}return a},Ki=({containerRef:n,open:e,onOpenChange:s,focusNonce:a,className:w})=>{const{t:f}=st(),[v,d]=i.useState(""),[x,p]=i.useState(0),[m,b]=i.useState(0),y=i.useRef(null),F=i.useRef([]),N=i.useRef(v);N.current=v;const S=i.useRef(null),g=i.useRef(null),l=i.useCallback((k,V=!1)=>{const z=n.current;if(!z){F.current=[],p(0),b(0);return}F.current=ac(z,k);const B=F.current.length;p(B),b(U=>!V||B===0?0:Math.min(U,B-1))},[n]),T=i.useCallback((k,V=!1)=>{S.current&&clearTimeout(S.current),S.current=setTimeout(()=>{S.current=null,l(k,V)},rc)},[l]);i.useEffect(()=>()=>{S.current&&clearTimeout(S.current)},[]);const R=i.useCallback(()=>{s(!1);const k=g.current;g.current=null,k?.isConnected&&k.focus()},[s]);i.useEffect(()=>{const k=n.current;if(!e||!k)return;const V=new MutationObserver(z=>{!N.current.trim()||!z.some(U=>!ic(U))||T(N.current,!0)});return V.observe(k,{childList:!0,subtree:!0,characterData:!0}),()=>{V.disconnect(),ua(k)}},[n,e,T]),i.useEffect(()=>{if(!e)return;const k=document.activeElement;k instanceof HTMLElement&&!g.current&&(g.current=k),y.current?.focus()},[e]),i.useEffect(()=>{e&&a>0&&(y.current?.focus(),y.current?.select())},[e,a]),i.useEffect(()=>{const k=n.current;if(!k||(k.querySelectorAll(`mark[${Jr}]`).forEach(z=>{z.removeAttribute(Jr),z.className=ca}),x===0))return;const V=F.current[Math.min(Math.max(m,0),x-1)];V&&(V.setAttribute(Jr,""),V.className=sc,V.scrollIntoView({block:"nearest"}))},[n,m,x]);const M=i.useCallback(()=>{b(k=>x===0?0:(k+1)%x)},[x]),D=i.useCallback(()=>{b(k=>x===0?0:(k-1+x)%x)},[x]),A=i.useCallback(k=>{k.key==="Enter"?(k.preventDefault(),k.shiftKey?D():M()):k.key==="Escape"&&(k.preventDefault(),R())},[R,M,D]);return e?r.jsxs("div",{className:W("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",w),children:[r.jsx(E,{name:"search",className:"ml-0.5 size-3.5 text-muted-foreground"}),r.jsx(Cs,{ref:y,value:v,onChange:k=>{d(k.target.value),T(k.target.value)},onKeyDown:A,placeholder:f("filesView.preview.find.placeholder"),"aria-label":f("filesView.preview.find.placeholder"),className:"h-7 w-40 rounded-md px-2 py-0 text-sm md:w-56"}),r.jsx("span",{className:"min-w-12 px-1 text-center typography-micro text-muted-foreground tabular-nums","aria-live":"polite","aria-label":x>0?f("filesView.preview.find.countAria",{current:m+1,total:x}):f("filesView.preview.find.noMatches"),children:v.trim()&&x===0?f("filesView.preview.find.noMatches"):x>0?`${m+1}/${x}`:""}),r.jsx(I,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:D,title:f("filesView.preview.find.previousAria"),"aria-label":f("filesView.preview.find.previousAria"),disabled:x===0,children:r.jsx(E,{name:"arrow-up",className:"size-3.5"})}),r.jsx(I,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:M,title:f("filesView.preview.find.nextAria"),"aria-label":f("filesView.preview.find.nextAria"),disabled:x===0,children:r.jsx(E,{name:"arrow-down",className:"size-3.5"})}),r.jsx(I,{type:"button",variant:"ghost",size:"sm",className:"size-6 p-0 text-muted-foreground",onClick:R,title:f("filesView.preview.find.closeAria"),"aria-label":f("filesView.preview.find.closeAria"),children:r.jsx(E,{name:"close",className:"size-3.5"})})]}):null},oc=n=>{let e=!0;return{poll:async()=>{if(!e||n.isDirty())return!1;const s=n.getLoadedContent(),a=n.getLoadedRevision();try{const w=await n.readContent();if(!e||n.isDirty()||a!==n.getLoadedRevision())return!1;if(w===s)return!0;const f=await n.readContent();return!e||n.isDirty()||f!==w||a!==n.getLoadedRevision()?!1:(n.applyContent(w),!0)}catch{return!1}},dispose:()=>{e=!1}}},lc=1,cc=(n,e)=>e.size!==n.size||e.mtimeMs!==void 0&&n.mtimeMs!==void 0&&Math.abs(e.mtimeMs-n.mtimeMs)>=lc;function Hi(){const n=Re.c(8),[e]=ht.useState(uc),s=ht.useRef(!1);let a;n[0]!==e?(a=x=>{if(x==null){e.cleanUp(),s.current=!1;return}s.current||(s.current=!0,e.setup(x,x.firstElementChild??void 0))},n[0]=e,n[1]=a):a=n[1];const w=a;let f,v;n[2]!==e?(f=()=>()=>{s.current=!1,e.cleanUp()},v=[e],n[2]=e,n[3]=f,n[4]=v):(f=n[3],v=n[4]),ht.useLayoutEffect(f,v);let d;return n[5]!==w||n[6]!==e?(d={virtualizer:e,setScroller:w},n[5]=w,n[6]=e,n[7]=d):d=n[7],d}function uc(){return new zl}const rs=new Map,dc=100;function lr(n){const[e,s]=ht.useState(null),a=ht.useRef(null),w=ht.useRef(null),f=ht.useRef(null),v=ht.useCallback((d,x)=>{d&&x instanceof Tl&&(f.current={key:n,file:x,node:d});const p=a.current,m=w.current,b=()=>{a.current===p&&(p?.(),m?.())};x?queueMicrotask(b):b()},[n]);return ht.useLayoutEffect(()=>{if(!e||!n)return;const d=rs.get(n)??{top:0,left:0};let x=!0;const p=()=>f.current?.key===n?f.current.file:null,m=l=>f.current?.key===n?f.current.node.shadowRoot?.querySelector(`[data-line][data-line-index="${l-1}"]`):null,b=()=>{F.disconnect(),N.disconnect()},y=()=>{if(!x)return;const l=p(),T=d.line&&l?.getLinePosition(d.line.number),R=d.line&&m(d.line.number);let M=d.top;d.line&&T&&(M=(l?.top??0)+T.top-d.line.offset),d.line&&R&&(M=e.scrollTop+R.getBoundingClientRect().top-e.getBoundingClientRect().top-d.line.offset),e.scrollTop=M,e.scrollLeft=d.left,(!d.line||R)&&Math.abs(e.scrollTop-M)<1&&Math.abs(e.scrollLeft-d.left)<1&&(x=!1,b())},F=new ResizeObserver(y),N=new MutationObserver(()=>{if(x){for(const l of e.children)F.observe(l);y()}});F.observe(e);for(const l of e.children)F.observe(l);N.observe(e,{childList:!0,subtree:!0});const S=()=>{if(x)return;const l=p(),T=l?.getNumericScrollAnchor(e.scrollTop-(l.top??0)),R=T&&m(T.lineNumber),M=R?R.getBoundingClientRect().top-e.getBoundingClientRect().top:null;if(rs.delete(n),rs.set(n,{top:e.scrollTop,left:e.scrollLeft,line:T&&M!==null&&M>=0&&M<e.clientHeight?{number:T.lineNumber,offset:M}:void 0}),rs.size>dc){const D=rs.keys().next().value;D!==void 0&&rs.delete(D)}},g=()=>{x=!1,b()};return a.current=y,w.current=S,y(),e.addEventListener("scroll",S,{passive:!0}),e.addEventListener("wheel",g,{passive:!0}),e.addEventListener("touchstart",g,{passive:!0}),e.addEventListener("pointerdown",g,{passive:!0}),e.addEventListener("keydown",g),()=>{a.current=null,w.current=null,f.current?.key===n&&(f.current=null),b(),e.removeEventListener("scroll",S),e.removeEventListener("wheel",g),e.removeEventListener("touchstart",g),e.removeEventListener("pointerdown",g),e.removeEventListener("keydown",g)}},[n,e]),{setScroller:s,restore:v}}function fc(n){return!(!n.autoSaveEnabled||!n.isDirty||!n.canWrite||n.isSaving||n.fileLoading||n.isNonEditableBinary||!n.selectedFilePath||n.loadedFilePath!==n.selectedFilePath)}function mc(n){return n.selectedFilePath?n.isDirty?!(n.fileLoading||n.loadedFilePath!==n.selectedFilePath||n.isNonEditableBinary||n.draftContent===""&&n.fileContent!==""&&n.loadedFilePath!==n.selectedFilePath):!0:!1}const da=2e5,hc=n=>{let e=0,s=0;for(let a=0;a<n.length;a++)n.charCodeAt(a)===10&&(a>0&&n.charCodeAt(a-1)===13?e++:s++);return e>s?`\r
5
+ `:`
6
+ `},fa=n=>n.replace(/\r\n/g,`
7
+ `).replace(/\r/g,`
8
+ `),pc=n=>({content:fa(n),lineEnding:hc(n)}),gc=(n,e)=>{const s=fa(n);return e===`\r
9
+ `?s.replace(/\n/g,`\r
10
+ `):s},xc=(n,e)=>e??(n.length>da?"view":"edit"),vc=n=>{let e=2166136261;for(let s=0;s<n.length;s++)e^=n.charCodeAt(s),e=e+((e<<1)+(e<<4)+(e<<7)+(e<<8)+(e<<24))>>>0;return`${n.length}:${e.toString(16)}`},wc='<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 qi(){if(typeof document>"u")return!1;const n=document.documentElement.getAttribute("data-theme");return n==="dark"||!n&&window.matchMedia("(prefers-color-scheme: dark)").matches}const bc=i.forwardRef(function({xml:e,readOnly:s,className:a,onChange:w},f){const v=i.useRef(e),d=i.useRef(null),x=i.useRef(!1),[p,m]=i.useState(qi),b=i.useRef(e),y=i.useRef(e);y.current!==e&&(y.current=e,b.current=e,v.current=e);const F=i.useRef(p);F.current!==p&&(F.current=p,b.current=v.current);const N=i.useRef(null);i.useEffect(()=>{const l=()=>m(qi());l();const T=new MutationObserver(l);return T.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]}),()=>T.disconnect()},[]),i.useEffect(()=>{const l=setTimeout(()=>{N.current?.querySelector(".diagrams-iframe")?.focus()},600);return()=>clearTimeout(l)},[]),i.useImperativeHandle(f,()=>({getXml:()=>v.current}));const S=i.useCallback(()=>{!e&&!x.current&&(x.current=!0,setTimeout(()=>{d.current?.template({})},500))},[e]),g=i.useCallback(l=>{v.current=l.xml,w?.(l.xml)},[w]);return r.jsx("div",{ref:N,className:W("h-full w-full",a),children:r.jsx(Ll,{ref:d,xml:b.current||wc,autosave:!0,urlParameters:{ui:s?"simple":p?"dark":"kennedy",spin:!0,libraries:!s,chrome:s,nav:s,layers:s,noSaveBtn:!0,noExitBtn:!0,saveAndExit:!1},onLoad:S,onAutoSave:g},p?"dark":"light")})}),Fs=n=>{const e=Re.c(18),{items:s,actions:a,className:w}=n;let f,v,d,x;if(e[0]!==a||e[1]!==w||e[2]!==s){x=Symbol.for("react.early_return_sentinel");e:{const y=s.filter(yc);if(y.length===0&&!a){x=null;break e}e[7]!==w?(d=W("flex min-h-7 items-center gap-2 border-b border-border/40 bg-[var(--surface-subtle)] px-3 py-1",w),e[7]=w,e[8]=d):d=e[8],f="min-w-0 flex-1 truncate typography-meta text-muted-foreground",v=y.join(" · ")}e[0]=a,e[1]=w,e[2]=s,e[3]=f,e[4]=v,e[5]=d,e[6]=x}else f=e[3],v=e[4],d=e[5],x=e[6];if(x!==Symbol.for("react.early_return_sentinel"))return x;let p;e[9]!==f||e[10]!==v?(p=r.jsx("div",{className:f,children:v}),e[9]=f,e[10]=v,e[11]=p):p=e[11];let m;e[12]!==a?(m=a?r.jsx("div",{className:"flex shrink-0 items-center gap-1",children:a}):null,e[12]=a,e[13]=m):m=e[13];let b;return e[14]!==d||e[15]!==p||e[16]!==m?(b=r.jsxs("div",{className:d,children:[p,m]}),e[14]=d,e[15]=p,e[16]=m,e[17]=b):b=e[17],b};function yc(n){return n.length>0}const ks=n=>{if(n===null||!Number.isFinite(n)||n<0)return"";if(n<1024)return`${n} B`;const e=["KB","MB","GB"];let s=n/1024;for(const a of e){if(s<1024||a===e[e.length-1])return`${s.toFixed(s>=10?0:1)} ${a}`;s/=1024}return""},jc=n=>{if(n===null||!Number.isFinite(n)||n<0)return"";const e=Math.round(n),s=Math.floor(e/3600),a=Math.floor(e%3600/60),w=e%60,f=v=>String(v).padStart(2,"0");return s>0?`${s}:${f(a)}:${f(w)}`:`${a}:${f(w)}`},ma=n=>n&&n.width>0&&n.height>0?`${n.width} × ${n.height}`:"",Nc=n=>{const e=Re.c(28),{name:s,path:a,sizeBytes:w,download:f}=n,{t:v}=st();let d,x,p,m,b,y,F;if(e[0]!==s||e[1]!==a||e[2]!==w||e[3]!==v){const l=qo(a).toUpperCase();y="flex h-full min-h-0 flex-col",F=r.jsx(Fs,{items:[l,ks(w)]}),p="flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center",e[11]!==a?(m=r.jsx(Ns,{filePath:a,className:"size-10"}),e[11]=a,e[12]=m):m=e[12],e[13]!==s?(b=r.jsx("div",{className:"max-w-full truncate typography-ui-header text-foreground",children:s}),e[13]=s,e[14]=b):b=e[14],d="max-w-md typography-ui text-muted-foreground",x=l?v("filesView.artifact.binary.descriptionWithType",{extension:l}):v("filesView.artifact.binary.description"),e[0]=s,e[1]=a,e[2]=w,e[3]=v,e[4]=d,e[5]=x,e[6]=p,e[7]=m,e[8]=b,e[9]=y,e[10]=F}else d=e[4],x=e[5],p=e[6],m=e[7],b=e[8],y=e[9],F=e[10];let N;e[15]!==d||e[16]!==x?(N=r.jsx("div",{className:d,children:x}),e[15]=d,e[16]=x,e[17]=N):N=e[17];let S;e[18]!==f||e[19]!==p||e[20]!==m||e[21]!==b||e[22]!==N?(S=r.jsxs("div",{className:p,children:[m,b,N,f]}),e[18]=f,e[19]=p,e[20]=m,e[21]=b,e[22]=N,e[23]=S):S=e[23];let g;return e[24]!==y||e[25]!==F||e[26]!==S?(g=r.jsxs("div",{className:y,children:[F,S]}),e[24]=y,e[25]=F,e[26]=S,e[27]=g):g=e[27],g},Sc=[48,32,24,18,14],Cc=["ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz",`0123456789 .,;:!?&@#%()[]{}<>+-=/\\*"'`];let Zr=0;const Fc=n=>{const e=Re.c(16),{src:s,name:a,sizeBytes:w}=n,{t:f}=st(),[v,d]=i.useState("loading"),[x]=i.useState(kc);let p,m;e[0]!==x||e[1]!==s?(p=()=>{let S=!1;d("loading");const g=new FontFace(x,`url("${s.replace(/"/g,"%22")}")`);return document.fonts.add(g),g.load().then(()=>{S||d("ready")}).catch(()=>{S||d("failed")}),()=>{S=!0,document.fonts.delete(g)}},m=[x,s],e[0]=x,e[1]=s,e[2]=p,e[3]=m):(p=e[2],m=e[3]),i.useEffect(p,m);let b;e[4]!==w?(b=ks(w),e[4]=w,e[5]=b):b=e[5];let y;e[6]!==a||e[7]!==b?(y=r.jsx(Fs,{items:[a,b]}),e[6]=a,e[7]=b,e[8]=y):y=e[8];let F;e[9]!==x||e[10]!==v||e[11]!==f?(F=v==="failed"?r.jsx("div",{className:"flex flex-1 items-center justify-center p-6 text-center typography-ui text-muted-foreground",children:f("filesView.artifact.font.loadFailed")}):v==="loading"?r.jsxs("div",{className:"flex items-center gap-2 p-3 typography-ui text-muted-foreground",children:[r.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}),f("common.loading")]}):r.jsx("div",{className:"min-h-0 flex-1 overflow-auto p-4",style:{fontFamily:`"${x}"`},children:r.jsxs("div",{className:"flex flex-col gap-4",children:[Sc.map(S=>r.jsxs("div",{className:"flex items-baseline gap-3",children:[r.jsx("span",{className:"w-8 shrink-0 text-right font-sans typography-meta text-muted-foreground",children:S}),r.jsx("span",{className:"min-w-0 break-words leading-tight text-foreground",style:{fontSize:`${S}px`},children:f("filesView.artifact.font.sample")})]},S)),r.jsx("div",{className:"mt-2 flex flex-col gap-1 border-t border-border/40 pt-4 text-foreground",style:{fontSize:"20px"},children:Cc.map(Rc)})]})}),e[9]=x,e[10]=v,e[11]=f,e[12]=F):F=e[12];let N;return e[13]!==y||e[14]!==F?(N=r.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[y,F]}),e[13]=y,e[14]=F,e[15]=N):N=e[15],N};function kc(){return Zr=Zr+1,`oc-font-preview-${Zr}`}function Rc(n){return r.jsx("div",{className:"break-all leading-relaxed",children:n},n)}const Tc=n=>{const e=Re.c(46),{src:s,name:a,sizeBytes:w}=n,{t:f}=st(),[v,d]=i.useState("fit"),[x,p]=i.useState(null);let m;e[0]===Symbol.for("react.memo_cache_sentinel")?(m=()=>{p(null),d("fit")},e[0]=m):m=e[0];let b;e[1]!==s?(b=[s],e[1]=s,e[2]=b):b=e[2],i.useEffect(m,b);let y;e[3]!==x?(y=ma(x),e[3]=x,e[4]=y):y=e[4];let F;e[5]!==w?(F=ks(w),e[5]=w,e[6]=F):F=e[6];let N;e[7]!==y||e[8]!==F?(N=[y,F],e[7]=y,e[8]=F,e[9]=N):N=e[9];const S=v==="fit";let g;e[10]!==f?(g=f("filesView.artifact.image.fitTitle"),e[10]=f,e[11]=g):g=e[11];let l;e[12]===Symbol.for("react.memo_cache_sentinel")?(l=()=>d("fit"),e[12]=l):l=e[12];let T;e[13]!==f?(T=f("filesView.artifact.image.fit"),e[13]=f,e[14]=T):T=e[14];let R;e[15]!==S||e[16]!==g||e[17]!==T?(R=r.jsx(I,{variant:"chip",size:"xs","aria-pressed":S,title:g,onClick:l,children:T}),e[15]=S,e[16]=g,e[17]=T,e[18]=R):R=e[18];const M=v==="actual";let D;e[19]!==f?(D=f("filesView.artifact.image.actualTitle"),e[19]=f,e[20]=D):D=e[20];let A;e[21]===Symbol.for("react.memo_cache_sentinel")?(A=()=>d("actual"),e[21]=A):A=e[21];let k;e[22]!==M||e[23]!==D?(k=r.jsx(I,{variant:"chip",size:"xs","aria-pressed":M,title:D,onClick:A,children:"1:1"}),e[22]=M,e[23]=D,e[24]=k):k=e[24];let V;e[25]!==R||e[26]!==k?(V=r.jsxs(r.Fragment,{children:[R,k]}),e[25]=R,e[26]=k,e[27]=V):V=e[27];let z;e[28]!==V||e[29]!==N?(z=r.jsx(Fs,{items:N,actions:V}),e[28]=V,e[29]=N,e[30]=z):z=e[30];const B=v==="fit"&&"flex items-center justify-center";let U;e[31]!==B?(U=W("min-h-0 flex-1 overflow-auto p-3",B),e[31]=B,e[32]=U):U=e[32];let Y;e[33]===Symbol.for("react.memo_cache_sentinel")?(Y=q=>{const Q=q.currentTarget;p({width:Q.naturalWidth,height:Q.naturalHeight})},e[33]=Y):Y=e[33];const te=v==="fit"?"max-h-full max-w-full object-contain":"max-w-none";let ee;e[34]!==te?(ee=W("rounded-md border border-border/30 bg-primary/10",te),e[34]=te,e[35]=ee):ee=e[35];let G;e[36]!==a||e[37]!==s||e[38]!==ee?(G=r.jsx("img",{src:s,alt:a,draggable:!1,onLoad:Y,className:ee},s),e[36]=a,e[37]=s,e[38]=ee,e[39]=G):G=e[39];let X;e[40]!==U||e[41]!==G?(X=r.jsx("div",{className:U,children:G}),e[40]=U,e[41]=G,e[42]=X):X=e[42];let J;return e[43]!==z||e[44]!==X?(J=r.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[z,X]}),e[43]=z,e[44]=X,e[45]=J):J=e[45],J},Ec=n=>{const e=Re.c(24),{kind:s,src:a,name:w,sizeBytes:f,download:v}=n,{t:d}=st(),[x,p]=i.useState(null),[m,b]=i.useState(null),[y,F]=i.useState(!1);let N;e[0]===Symbol.for("react.memo_cache_sentinel")?(N=()=>{p(null),b(null),F(!1)},e[0]=N):N=e[0];let S;e[1]!==a?(S=[a],e[1]=a,e[2]=S):S=e[2],i.useEffect(N,S);let g;e[3]===Symbol.for("react.memo_cache_sentinel")?(g=V=>{const z=V.currentTarget;p(Number.isFinite(z.duration)?z.duration:null),z instanceof HTMLVideoElement&&b({width:z.videoWidth,height:z.videoHeight})},e[3]=g):g=e[3];const l=g;let T;e[4]!==x?(T=jc(x),e[4]=x,e[5]=T):T=e[5];let R;e[6]!==m?(R=ma(m),e[6]=m,e[7]=R):R=e[7];let M;e[8]!==f?(M=ks(f),e[8]=f,e[9]=M):M=e[9];let D;e[10]!==T||e[11]!==R||e[12]!==M?(D=r.jsx(Fs,{items:[T,R,M]}),e[10]=T,e[11]=R,e[12]=M,e[13]=D):D=e[13];let A;e[14]!==v||e[15]!==y||e[16]!==s||e[17]!==w||e[18]!==a||e[19]!==d?(A=y?r.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-3 p-6 text-center",children:[r.jsx("div",{className:"max-w-md typography-ui text-muted-foreground",children:d("filesView.artifact.media.unplayable")}),v]}):s==="video"?r.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center bg-[var(--surface-background)] p-3",children:r.jsx("video",{src:a,controls:!0,playsInline:!0,preload:"metadata",title:w,className:"max-h-full max-w-full rounded-md",onLoadedMetadata:l,onError:()=>F(!0)},a)}):r.jsxs("div",{className:"flex flex-1 flex-col items-center justify-center gap-4 p-6",children:[r.jsx("div",{className:"typography-ui-label truncate text-foreground",children:w}),r.jsx("audio",{src:a,controls:!0,preload:"metadata",title:w,className:"w-full max-w-lg",onLoadedMetadata:l,onError:()=>F(!0)},a)]}),e[14]=v,e[15]=y,e[16]=s,e[17]=w,e[18]=a,e[19]=d,e[20]=A):A=e[20];let k;return e[21]!==D||e[22]!==A?(k=r.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[D,A]}),e[21]=D,e[22]=A,e[23]=k):k=e[23],k},Vc=2e3,Pc=n=>n.toLowerCase().endsWith(".tsv")?" ":",",Mc=(n,e,s=Vc)=>{const a=[];let w=0,f="",v=[],d=!1,x=!1;const p=()=>{v.push(f),f="",v.length===1&&v[0]===""&&!x||((w===0||a.length<=s)&&a.push(v),w+=1),v=[],x=!1},m=n.charCodeAt(0)===65279?n.slice(1):n;for(let S=0;S<m.length;S+=1){const g=m[S];if(d){g==='"'?m[S+1]==='"'?(f+='"',S+=1):d=!1:f+=g;continue}if(g==='"'){d=!0,x=!0;continue}if(g===e){v.push(f),f="",x=!0;continue}if(g===`
11
+ `||g==="\r"){g==="\r"&&m[S+1]===`
12
+ `&&(S+=1),p();continue}f+=g}(f.length>0||v.length>0||d)&&p();const b=a[0]??[],y=a.slice(1),F=a.reduce((S,g)=>Math.max(S,g.length),0),N=Math.max(0,w-1);return{header:b,rows:y,totalRows:N,columnCount:F,truncated:y.length<N}},Dc=n=>{const e=Re.c(29),{path:s,content:a,sizeBytes:w}=n,{t:f}=st();let v;e[0]!==a||e[1]!==s?(v=Mc(a,Pc(s)),e[0]=a,e[1]=s,e[2]=v):v=e[2];const d=v;let x;e[3]!==f||e[4]!==d.columnCount||e[5]!==d.totalRows?(x=d.totalRows===1?f("filesView.artifact.table.rowsSingle",{rows:d.totalRows,columns:d.columnCount}):f("filesView.artifact.table.rowsPlural",{rows:d.totalRows,columns:d.columnCount}),e[3]=f,e[4]=d.columnCount,e[5]=d.totalRows,e[6]=x):x=e[6];const p=x;let m;e[7]!==d.columnCount?(m=Array.from({length:d.columnCount},zc),e[7]=d.columnCount,e[8]=m):m=e[8];const b=m;let y;e[9]!==f||e[10]!==d.rows||e[11]!==d.totalRows||e[12]!==d.truncated?(y=d.truncated?f("filesView.artifact.table.truncated",{shown:d.rows.length,total:d.totalRows}):"",e[9]=f,e[10]=d.rows,e[11]=d.totalRows,e[12]=d.truncated,e[13]=y):y=e[13];let F;e[14]!==w?(F=ks(w),e[14]=w,e[15]=F):F=e[15];let N;e[16]!==p||e[17]!==y||e[18]!==F?(N=r.jsx(Fs,{items:[p,y,F]}),e[16]=p,e[17]=y,e[18]=F,e[19]=N):N=e[19];let S;e[20]!==b||e[21]!==f||e[22]!==d.columnCount||e[23]!==d.header||e[24]!==d.rows?(S=d.columnCount===0?r.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:f("filesView.artifact.table.empty")}):r.jsx("div",{className:"min-h-0 flex-1 overflow-auto",children:r.jsxs("table",{className:"min-w-full border-separate border-spacing-0 font-mono typography-meta",children:[r.jsx("thead",{className:"sticky top-0 z-10 bg-[var(--surface-subtle)]",children:r.jsx("tr",{children:b.map(l=>r.jsx("th",{scope:"col",className:"whitespace-nowrap border-b border-r border-border/40 px-2 py-1 text-left font-medium text-foreground last:border-r-0",children:d.header[l]??""},l))})}),r.jsx("tbody",{children:d.rows.map((l,T)=>r.jsx("tr",{className:"odd:bg-[var(--surface-background)] even:bg-[var(--surface-subtle)]/40",children:b.map(R=>r.jsx("td",{className:"max-w-[32rem] truncate border-b border-r border-border/30 px-2 py-1 align-top text-foreground last:border-r-0",title:l[R]??"",children:l[R]??""},R))},T))})]})}),e[20]=b,e[21]=f,e[22]=d.columnCount,e[23]=d.header,e[24]=d.rows,e[25]=S):S=e[25];let g;return e[26]!==N||e[27]!==S?(g=r.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[N,S]}),e[26]=N,e[27]=S,e[28]=g):g=e[28],g};function zc(n,e){return e}const Yr="data-oc-local-asset",Lc=25*1024*1024,Gi=n=>{const e=n.trim();return!e||e.startsWith("#")||e.startsWith("//")?!1:!/^[a-z][a-z\d+.-]*:/i.test(e)},Ac=n=>n.split(/[?#]/,1)[0]??"",Ic=n=>n.trim().toLowerCase().replace(/[^\p{L}\p{N}\s-]/gu,"").replace(/\s+/g,"-"),Oc=(n,e)=>{const s=ha(e.replace(/^#/,"")).toLowerCase();if(!s)return!1;for(const a of Array.from(n.querySelectorAll("h1, h2, h3, h4, h5, h6")))if(a.id===s||Ic(a.textContent??"")===s)return a.scrollIntoView({block:"start"}),!0;return!1},ha=n=>{try{return decodeURIComponent(n)}catch{return n}},Xi=({container:n,filePath:e,workspaceRoot:s,onOpenFile:a,enabled:w})=>{const f=i.useRef(a);f.current=a,i.useEffect(()=>{if(!w||!n||!e)return;const v=e.slice(0,e.lastIndexOf("/")+1)||"/",d=g=>Go(v,ha(Ac(g))),x=g=>({path:g,allowOutsideWorkspace:s&&Xo(g,s)?void 0:"true",directory:s||void 0});let p=!1;const m=tt(),b=new Map,y=g=>{const l=b.get(g);if(l)return l;const T=(async()=>{const R=await en("/api/fs/raw",{query:x(g),signal:AbortSignal.timeout(3e4)});if(!R.ok)throw new Error(`Image read failed (${R.status})`);const M=await R.blob();if(M.size>Lc)throw new Error("Image too large for preview");if(p||tt()!==m)throw new Error("Preview closed");return URL.createObjectURL(M)})();return b.set(g,T),T.catch(()=>b.delete(g)),T},F=()=>{for(const g of Array.from(n.querySelectorAll("img[src]"))){const l=g.getAttribute("src")??"";if(!Gi(l))continue;const T=d(l);g.setAttribute(Yr,T),y(T).then(R=>{p||g.getAttribute(Yr)!==T||g.getAttribute("src")!==R&&(g.src=R)}).catch(()=>{p||g.removeAttribute(Yr)})}},N=g=>{if(g.defaultPrevented||g.button!==0||g.metaKey||g.ctrlKey||g.shiftKey||g.altKey)return;const l=g.target;if(!(l instanceof Element))return;const T=l.closest("a[href]");if(!(T instanceof HTMLAnchorElement)||!n.contains(T))return;const R=T.getAttribute("href")??"";if(R.startsWith("#")){g.preventDefault(),g.stopPropagation(),Oc(n,R);return}Gi(R)&&(g.preventDefault(),g.stopPropagation(),f.current(d(R)))};F();const S=new MutationObserver(F);return S.observe(n,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src"]}),n.addEventListener("click",N,!0),()=>{p=!0,S.disconnect(),n.removeEventListener("click",N,!0);for(const g of b.values())g.then(l=>URL.revokeObjectURL(l)).catch(()=>{})}},[n,w,e,s])},Bc=n=>{const e=Z(n);if(!e)return"";if(e==="/"||/^[A-Za-z]:\/$/.test(e))return e;const s=e.lastIndexOf("/");if(s<0)return e;if(s===0)return"/";const a=e.slice(0,s);return/^[A-Za-z]:$/.test(a)?`${a}/`:a},$c=n=>{const e=Re.c(8),{label:s,iconDataUrl:a}=n,[w,f]=i.useState(!1);let v;e[0]!==s?(v=s.trim().slice(0,1).toUpperCase()||"?",e[0]=s,e[1]=v):v=e[1];const d=v;if(a&&!w){let m;e[2]===Symbol.for("react.memo_cache_sentinel")?(m=()=>f(!0),e[2]=m):m=e[2];let b;return e[3]!==a?(b=r.jsx("img",{src:a,alt:"",className:"size-4 rounded-sm",onError:m}),e[3]=a,e[4]=b):b=e[4],b}let x;e[5]===Symbol.for("react.memo_cache_sentinel")?(x=W("size-4 rounded-sm flex items-center justify-center","bg-[var(--surface-muted)] text-[9px] font-medium text-muted-foreground"),e[5]=x):x=e[5];let p;return e[6]!==d?(p=r.jsx("span",{className:x,children:d}),e[6]=d,e[7]=p):p=e[7],p},_c=n=>n.slice().sort((e,s)=>e.type!==s.type?e.type==="directory"?-1:1:e.name.localeCompare(s.name)),Z=n=>{if(!n)return"";const e=n.replace(/\\/g,"/"),s=e.startsWith("//");let a=e.replace(/\/+/g,"/");s&&!a.startsWith("//")&&(a=`/${a}`);const w=a==="/",f=/^[A-Za-z]:\/$/.test(a);return!w&&!f&&(a=a.replace(/\/+$/,"")),a},Wc=n=>n.startsWith("/")||n.startsWith("//")||/^[A-Za-z]:\//.test(n),is=n=>/^[A-Za-z]:\//.test(n)?n.toLowerCase():n,Ss=(n,e)=>{const s=Z(e),a=Z(n);if(!s||!a)return!1;const w=is(s),f=is(a);return f===w||f.startsWith(`${w}/`)},Ji=(n,e)=>{const s=Z(e),a=Z(n);if(!Ss(a,s))return[];const f=a.slice(s.length).replace(/^\//,"").split("/"),v=[];let d=s;for(let x=0;x<f.length-1;x++)d=d?`${d}/${f[x]}`:f[x],v.push(d);return v},dr=(n,e)=>{if(!e)return"";const s=Z(e);if(!n||!Ss(s,n))return s;const a=s.slice(n.length);return a.startsWith("/")?a.slice(1):a},Uc=new Set(["node_modules"]),Kc=n=>{const e=Re.c(3),{status:s}=n;let a;e[0]===Symbol.for("react.memo_cache_sentinel")?(a={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]=a):a=e[0];const w=a[s];let f;return e[1]!==w?(f=r.jsx("span",{className:"size-2 rounded-full",style:{backgroundColor:w}}),e[1]=w,e[2]=f):f=e[2],f},Zi=n=>{const e=Re.c(11),{name:s}=n,a=i.useRef(null),w=i.useRef(null),[f,v]=i.useState(!1);let d;e[0]===Symbol.for("react.memo_cache_sentinel")?(d=()=>{const y=a.current,F=w.current;if(!y||!F)return;const N=()=>{v(F.scrollWidth>y.clientWidth+1)};N();const S=new ResizeObserver(N);return S.observe(y),S.observe(F),()=>{S.disconnect()}},e[0]=d):d=e[0];let x;e[1]!==s?(x=[s],e[1]=s,e[2]=x):x=e[2],i.useLayoutEffect(d,x);let p;e[3]!==s?(p=r.jsx("span",{ref:w,"aria-hidden":"true",className:"invisible absolute whitespace-nowrap",children:s}),e[3]=s,e[4]=p):p=e[4];let m;e[5]!==s||e[6]!==f?(m=f?r.jsxs("span",{className:"open-file-name-marquee-track",children:[r.jsx("span",{className:"open-file-name-marquee-item",children:s}),r.jsx("span",{className:"open-file-name-marquee-item","aria-hidden":"true",children:s})]}):r.jsx("span",{className:"block min-w-0 truncate",children:s}),e[5]=s,e[6]=f,e[7]=m):m=e[7];let b;return e[8]!==p||e[9]!==m?(b=r.jsxs("span",{ref:a,className:"relative block min-w-0 flex-1 overflow-hidden whitespace-nowrap",children:[p,m]}),e[8]=p,e[9]=m,e[10]=b):b=e[10],b},Hc=n=>Uc.has(n),qc=n=>{const e=Z(n);return e==="node_modules"||e.endsWith("/node_modules")||e.includes("/node_modules/")},Gc=n=>{const s=(n instanceof Error?n.message:String(n??"")).toLowerCase();return s.includes("is a directory")||s.includes("eisdir")},Yi=n=>{const s=(n instanceof Error?n.message:String(n??"")).toLowerCase();return s.includes("file not found")||s.includes("enoent")||s.includes("no such file")||s.includes("does not exist")},Xc=2e5,pa=(n,e)=>r.jsx(Ns,{filePath:n,extension:e}),Qr=n=>{if(!n)return!1;const e=n.toLowerCase().split(".").pop();return e==="md"||e==="markdown"},Qi=n=>{if(!n)return!1;const e=n.toLowerCase().split(".").pop();return e==="json"||e==="jsonc"||e==="json5"||e==="geojson"},cr=n=>{if(!n)return!1;const e=n.toLowerCase().split(".").pop();return e==="html"||e==="htm"},Jc=n=>{const e=Re.c(78),{node:s,root:a,isExpanded:w,isActive:f,isMobile:v,isBrowserClient:d,alwaysShowActions:x,status:p,badge:m,permissions:b,downloadFile:y,contextMenuPath:F,setContextMenuPath:N,rightClickMenuPath:S,setRightClickMenuPath:g,onSelect:l,onToggle:T,onRevealPath:R,onOpenDialog:M,canUpload:D,onPickFiles:A}=n,{t:k}=st(),V=s.type==="directory",{canRename:z,canCreateFile:B,canCreateFolder:U,canDelete:Y,canReveal:te}=b,ee=!V&&!!y,G=te&&!d,X=V&&D,J=z||B||U||X||Y||ee||G;let q;e[0]!==J||e[1]!==s.path||e[2]!==g?(q=Ue=>{J&&(Ue?.preventDefault(),g(s.path))},e[0]=J,e[1]=s.path,e[2]=g,e[3]=q):q=e[3];const Q=q;let _e;e[4]!==V||e[5]!==s||e[6]!==l||e[7]!==T?(_e=()=>{V?T(s.path):l(s)},e[4]=V,e[5]=s,e[6]=l,e[7]=T,e[8]=_e):_e=e[8];const ne=_e;let Te;e[9]!==s.path||e[10]!==N||e[11]!==g?(Te=Ue=>{Ue.stopPropagation(),g(null),N(s.path)},e[9]=s.path,e[10]=N,e[11]=g,e[12]=Te):Te=e[12];const De=Te;let ze;e[13]!==B||e[14]!==U||e[15]!==Y||e[16]!==z||e[17]!==G||e[18]!==X||e[19]!==y||e[20]!==d||e[21]!==V||e[22]!==s||e[23]!==M||e[24]!==A||e[25]!==R||e[26]!==a||e[27]!==k?(ze=Ue=>{const{Item:je,Separator:as}=Ue;return r.jsxs(r.Fragment,{children:[z&&r.jsxs(je,{onClick:ce=>{ce.stopPropagation(),M("rename",s)},children:[r.jsx(E,{name:"edit",className:"mr-2 size-4"})," ",k("sidebarFilesTree.menu.rename")]}),r.jsxs(je,{onClick:ce=>{ce.stopPropagation(),fr(s.path).then(St=>{if(St.ok){re.success(k("sidebarFilesTree.toast.pathCopied"));return}re.error(k("sidebarFilesTree.toast.copyFailed"))})},children:[r.jsx(E,{name:"file-copy",className:"mr-2 size-4"})," ",k("sidebarFilesTree.menu.copyPath")]}),r.jsxs(je,{onClick:ce=>{ce.stopPropagation();const St=dr(a,s.path)||s.path;fr(St).then(At=>{if(At.ok){re.success(k("filesView.toast.relativePathCopied"));return}re.error(k("sidebarFilesTree.toast.copyFailed"))})},children:[r.jsx(E,{name:"file-copy-2",className:"mr-2 size-4"})," ",k("filesView.tree.menu.copyRelativePath")]}),!V&&y&&r.jsxs(je,{onClick:ce=>{ce.stopPropagation(),y(s.path).catch(St=>{console.error("Download failed:",St),re.error(k("sidebarFilesTree.toast.operationFailed"))})},children:[r.jsx(E,{name:"download",className:"mr-2 size-4"})," ",k(d?"sidebarFilesTree.menu.download":"sidebarFilesTree.menu.save")]}),G&&r.jsxs(je,{onClick:ce=>{ce.stopPropagation(),R(s.path)},children:[r.jsx(E,{name:"folder-received",className:"mr-2 size-4"})," ",k(xl())]}),V&&(B||U||X)&&r.jsxs(r.Fragment,{children:[r.jsx(as,{}),B&&r.jsxs(je,{onClick:ce=>{ce.stopPropagation(),M("createFile",s)},children:[r.jsx(E,{name:"file-add",className:"mr-2 size-4"})," ",k("sidebarFilesTree.menu.newFile")]}),U&&r.jsxs(je,{onClick:ce=>{ce.stopPropagation(),M("createFolder",s)},children:[r.jsx(E,{name:"folder-add",className:"mr-2 size-4"})," ",k("sidebarFilesTree.menu.newFolder")]}),X&&r.jsxs(je,{onClick:ce=>{ce.stopPropagation(),A(s.path)},children:[r.jsx(E,{name:"upload-2",className:"mr-2 size-4"})," ",k("sidebarFilesTree.menu.uploadFiles")]})]}),Y&&r.jsxs(r.Fragment,{children:[r.jsx(as,{}),r.jsxs(je,{onClick:ce=>{ce.stopPropagation(),M("delete",s)},className:"text-destructive focus:text-destructive",children:[r.jsx(E,{name:"delete-bin",className:"mr-2 size-4"})," ",k("sidebarFilesTree.menu.delete")]})]})]})},e[13]=B,e[14]=U,e[15]=Y,e[16]=z,e[17]=G,e[18]=X,e[19]=y,e[20]=d,e[21]=V,e[22]=s,e[23]=M,e[24]=A,e[25]=R,e[26]=a,e[27]=k,e[28]=ze):ze=e[28];const K=ze,ie=S===s.path;let _;e[29]!==s.path||e[30]!==g?(_=Ue=>g(Ue?s.path:null),e[29]=s.path,e[30]=g,e[31]=_):_=e[31];const ae=v?void 0:Q;let fe;e[32]!==ae?(fe=r.jsx("div",{className:"group relative flex items-center",onContextMenu:ae}),e[32]=ae,e[33]=fe):fe=e[33];const me=v?void 0:Q,le=f?"bg-interactive-selection/70":"hover:bg-interactive-hover/40";let be;e[34]!==le?(be=W("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors pr-8 select-none",le),e[34]=le,e[35]=be):be=e[35];let xe;e[36]!==V||e[37]!==w||e[38]!==s.extension||e[39]!==s.path?(xe=V?w?r.jsx(E,{name:"folder-open",className:"size-4 flex-shrink-0 text-muted-foreground"}):r.jsx(E,{name:"folder-3",className:"size-4 flex-shrink-0 text-muted-foreground"}):pa(s.path,s.extension),e[36]=V,e[37]=w,e[38]=s.extension,e[39]=s.path,e[40]=xe):xe=e[40];let he;e[41]!==s.name||e[42]!==s.path?(he=r.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta",title:s.path,children:s.name}),e[41]=s.name,e[42]=s.path,e[43]=he):he=e[43];let ve;e[44]!==V||e[45]!==p?(ve=!V&&p&&r.jsx(Kc,{status:p}),e[44]=V,e[45]=p,e[46]=ve):ve=e[46];let Ee;e[47]!==m||e[48]!==V?(Ee=V&&m&&r.jsxs("span",{className:"text-xs flex items-center gap-1 ml-auto mr-1",children:[m.modified>0&&r.jsxs("span",{className:"text-[var(--status-warning)]",children:["M",m.modified]}),m.added>0&&r.jsxs("span",{className:"text-[var(--status-success)]",children:["+",m.added]})]}),e[47]=m,e[48]=V,e[49]=Ee):Ee=e[49];let ye;e[50]!==ne||e[51]!==be||e[52]!==xe||e[53]!==he||e[54]!==ve||e[55]!==Ee||e[56]!==me?(ye=r.jsxs("button",{type:"button",onClick:ne,onContextMenu:me,className:be,children:[xe,he,ve,Ee]}),e[50]=ne,e[51]=be,e[52]=xe,e[53]=he,e[54]=ve,e[55]=Ee,e[56]=me,e[57]=ye):ye=e[57];let lt;e[58]!==x||e[59]!==F||e[60]!==De||e[61]!==J||e[62]!==v||e[63]!==s.path||e[64]!==K||e[65]!==N?(lt=J&&r.jsx("div",{className:W("absolute right-1 top-1/2 -translate-y-1/2",x?"opacity-100":"opacity-0 focus-within:opacity-100 group-hover:opacity-100"),children:r.jsxs(tn,{open:F===s.path,onOpenChange:Ue=>N(Ue?s.path:null),children:[r.jsx(sn,{asChild:!0,children:r.jsx(I,{variant:"ghost",size:"icon",className:"size-6",onClick:De,children:r.jsx(E,{name:"more-2-fill",className:"size-4"})})}),r.jsx(rn,{align:"end",side:"bottom",onCloseAutoFocus:()=>N(null),children:K({Item:ur,Separator:gl})})]})}),e[58]=x,e[59]=F,e[60]=De,e[61]=J,e[62]=v,e[63]=s.path,e[64]=K,e[65]=N,e[66]=lt):lt=e[66];let We;e[67]!==ye||e[68]!==lt||e[69]!==fe?(We=r.jsxs(Sl,{render:fe,children:[ye,lt]}),e[67]=ye,e[68]=lt,e[69]=fe,e[70]=We):We=e[70];let ct;e[71]!==K?(ct=r.jsx(yl,{className:"min-w-[180px]",children:K({Item:Nl,Separator:jl})}),e[71]=K,e[72]=ct):ct=e[72];let Le;return e[73]!==We||e[74]!==ct||e[75]!==ie||e[76]!==_?(Le=r.jsxs(Cl,{open:ie,onOpenChange:_,children:[We,ct]}),e[73]=We,e[74]=ct,e[75]=ie,e[76]=_,e[77]=Le):Le=e[77],Le},Zc=n=>{const e=Re.c(83),{activeDialog:s,dialogData:a,dialogInputValue:w,onDialogInputChange:f,isDialogSubmitting:v,onDialogSubmit:d,onClose:x,inputRef:p}=n,{t:m}=st(),b=!!s;let y;e[0]!==x?(y=Q=>!Q&&x(),e[0]=x,e[1]=y):y=e[1];let F;e[2]!==s||e[3]!==m?(F=s==="createFile"&&m("filesView.dialog.createFile.title"),e[2]=s,e[3]=m,e[4]=F):F=e[4];let N;e[5]!==s||e[6]!==m?(N=s==="createFolder"&&m("filesView.dialog.createFolder.title"),e[5]=s,e[6]=m,e[7]=N):N=e[7];let S;e[8]!==s||e[9]!==m?(S=s==="rename"&&m("filesView.dialog.rename.title"),e[8]=s,e[9]=m,e[10]=S):S=e[10];let g;e[11]!==s||e[12]!==m?(g=s==="delete"&&m("filesView.dialog.delete.title"),e[11]=s,e[12]=m,e[13]=g):g=e[13];let l;e[14]!==F||e[15]!==N||e[16]!==S||e[17]!==g?(l=r.jsxs(aa,{children:[F,N,S,g]}),e[14]=F,e[15]=N,e[16]=S,e[17]=g,e[18]=l):l=e[18];let T;e[19]!==s||e[20]!==a?.path||e[21]!==m?(T=s==="createFile"&&m("filesView.dialog.createFile.description",{path:a?.path??m("filesView.dialog.rootFallback")}),e[19]=s,e[20]=a?.path,e[21]=m,e[22]=T):T=e[22];let R;e[23]!==s||e[24]!==a?.path||e[25]!==m?(R=s==="createFolder"&&m("filesView.dialog.createFolder.description",{path:a?.path??m("filesView.dialog.rootFallback")}),e[23]=s,e[24]=a?.path,e[25]=m,e[26]=R):R=e[26];let M;e[27]!==s||e[28]!==a?.name||e[29]!==m?(M=s==="rename"&&m("filesView.dialog.rename.description",{name:a?.name??""}),e[27]=s,e[28]=a?.name,e[29]=m,e[30]=M):M=e[30];let D;e[31]!==s||e[32]!==a?.name||e[33]!==m?(D=s==="delete"&&m("filesView.dialog.delete.description",{name:a?.name??""}),e[31]=s,e[32]=a?.name,e[33]=m,e[34]=D):D=e[34];let A;e[35]!==M||e[36]!==D||e[37]!==T||e[38]!==R?(A=r.jsxs(oa,{children:[T,R,M,D]}),e[35]=M,e[36]=D,e[37]=T,e[38]=R,e[39]=A):A=e[39];let k;e[40]!==A||e[41]!==l?(k=r.jsxs(ia,{children:[l,A]}),e[40]=A,e[41]=l,e[42]=k):k=e[42];let V;e[43]!==s||e[44]!==w||e[45]!==p||e[46]!==f||e[47]!==d||e[48]!==m?(V=s!=="delete"&&r.jsx("div",{className:"py-4",children:r.jsx(Cs,{value:w,onChange:Q=>f(Q.target.value),placeholder:m(s==="rename"?"filesView.dialog.rename.placeholder":"filesView.dialog.namePlaceholder"),onKeyDown:Q=>{Q.key==="Enter"&&d()},ref:p})}),e[43]=s,e[44]=w,e[45]=p,e[46]=f,e[47]=d,e[48]=m,e[49]=V):V=e[49];let z;e[50]!==m?(z=m("filesView.dialog.cancel"),e[50]=m,e[51]=z):z=e[51];let B;e[52]!==v||e[53]!==x||e[54]!==z?(B=r.jsx(I,{variant:"outline",onClick:x,disabled:v,children:z}),e[52]=v,e[53]=x,e[54]=z,e[55]=B):B=e[55];const U=s==="delete"?"destructive":"default";let Y;e[56]!==d?(Y=()=>{d()},e[56]=d,e[57]=Y):Y=e[57];let te;e[58]!==s||e[59]!==w||e[60]!==v?(te=v||s!=="delete"&&!w.trim(),e[58]=s,e[59]=w,e[60]=v,e[61]=te):te=e[61];let ee;e[62]!==s||e[63]!==v||e[64]!==m?(ee=v?r.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}):m(s==="delete"?"filesView.dialog.delete.confirm":"filesView.dialog.confirm"),e[62]=s,e[63]=v,e[64]=m,e[65]=ee):ee=e[65];let G;e[66]!==U||e[67]!==Y||e[68]!==te||e[69]!==ee?(G=r.jsx(I,{variant:U,onClick:Y,disabled:te,children:ee}),e[66]=U,e[67]=Y,e[68]=te,e[69]=ee,e[70]=G):G=e[70];let X;e[71]!==B||e[72]!==G?(X=r.jsxs(la,{children:[B,G]}),e[71]=B,e[72]=G,e[73]=X):X=e[73];let J;e[74]!==p||e[75]!==k||e[76]!==V||e[77]!==X?(J=r.jsxs(na,{initialFocus:p,children:[k,V,X]}),e[74]=p,e[75]=k,e[76]=V,e[77]=X,e[78]=J):J=e[78];let q;return e[79]!==b||e[80]!==y||e[81]!==J?(q=r.jsx(ra,{open:b,onOpenChange:y,children:J}),e[79]=b,e[80]=y,e[81]=J,e[82]=q):q=e[82],q},ns=new Map,Yc=100,ea=n=>{const e=Re.c(13);let s,a,w;e[0]!==n?({positionKey:a,onViewReady:s,...w}=n,e[0]=n,e[1]=s,e[2]=a,e[3]=w):(s=e[1],a=e[2],w=e[3]);const f=i.useRef(null);let v,d;e[4]!==a?(v=()=>()=>{const m=f.current;if(!m)return;const{anchor:b,head:y}=m.state.selection.main;if(ns.delete(a),ns.set(a,{scroll:m.scrollSnapshot(),anchor:b,head:y}),ns.size>Yc){const F=ns.keys().next().value;F!==void 0&&ns.delete(F)}},d=[a],e[4]=a,e[5]=v,e[6]=d):(v=e[5],d=e[6]),i.useLayoutEffect(v,d);let x;e[7]!==s||e[8]!==a?(x=m=>{f.current=m;const b=ns.get(a);b&&m.dispatch({selection:{anchor:Math.min(b.anchor,m.state.doc.length),head:Math.min(b.head,m.state.doc.length)},effects:b.scroll}),s?.(m)},e[7]=s,e[8]=a,e[9]=x):x=e[9];let p;return e[10]!==w||e[11]!==x?(p=r.jsx(kl,{...w,onViewReady:x}),e[10]=w,e[11]=x,e[12]=p):p=e[12],p},ta=(n,e,s)=>{const a=Re.c(8),[w,f]=i.useState(""),[v,d]=i.useState(0);let x,p;a[0]!==n||a[1]!==s||a[2]!==e?(x=()=>{if(!n){f("");return}let b=!1;f("");const y=Bo(),F=$o(y);_o(y).then(S=>{b||!S||(f(n),e(null))}).catch(S=>{b||(e(S instanceof Error?S.message:s),f(n))});const N=Wo(()=>{b||(f(n),d(Qc),e(null))});return()=>{b=!0,F(),N()}},p=[n,e,s],a[0]=n,a[1]=s,a[2]=e,a[3]=x,a[4]=p):(x=a[3],p=a[4]),i.useEffect(x,p);let m;return a[5]!==v||a[6]!==w?(m={readyKey:w,nonce:v},a[5]=v,a[6]=w,a[7]=m):m=a[7],m},jf=({mode:n="full",visible:e=!0})=>{const{t:s}=st(),{files:a,runtime:w}=Jo(),{currentTheme:f,availableThemes:v,lightThemeId:d,darkThemeId:x}=Zo(),{isMobile:p,isTablet:m,screenWidth:b}=Yo(),y=Mo(w.platform),F=p||m,N=Do(),S=zo(),g=sa()??"",l=Z(g.trim()),T=p||n==="full",R=T&&e,M=Qo(t=>t.runtimeKey),D=JSON.stringify([M,l]),A=i.useRef(D);A.current=D;const k=JSON.stringify([M,l,N,S]),V=i.useRef(k);V.current=k;const z=n!=="editor-only",B=n==="editor-only"&&!p,U=Lo(t=>t.searchFiles),Y=el(R?g:null),[te,ee]=i.useState(""),G=tl(te,200),X=i.useRef(null),[J,q]=i.useState(!1),[Q,_e]=i.useState(!0),[ne,Te]=i.useState(!1),[De,ze]=i.useState(!1),K=i.useRef(0),ie=i.useCallback(t=>{K.current=Math.max(0,K.current+(t?1:-1))},[]),[_,ae]=i.useState("edit"),[fe,me]=i.useState("edit"),[le,be]=i.useState("tree"),[xe,he]=i.useState("edit"),[ve,Ee]=i.useState("preview"),[ye,lt]=i.useState("preview"),[We,ct]=i.useState("preview"),[Le,Ue]=i.useState("table"),[je,as]=i.useState(null),[ce,St]=i.useState(0),At=i.useRef({}),hr=i.useRef({}),pr=i.useRef({}),nn=i.useRef({}),an=i.useRef({}),on=i.useRef({}),gr=i.useRef({}),Rs=i.useMemo(()=>v.find(t=>t.metadata.id===d)??Di(!1),[v,d]),Ts=i.useMemo(()=>v.find(t=>t.metadata.id===x)??Di(!0),[v,x]);i.useEffect(()=>{$i(Rs),$i(Ts)},[Rs,Ts]);const Es=i.useMemo(()=>[],[]),Ne=et(t=>l?t.byRoot[l]?.openPaths??Es:Es),Ct=et(t=>l?t.byRoot[l]?.selectedPath??null:null),rt=et(t=>l?t.byRoot[l]?.expandedPaths??Es:Es),ga=i.useMemo(()=>new Set(rt),[rt]),It=et(t=>t.removeOpenPath),pt=et(t=>t.removeOpenPathsByPrefix),ln=et(t=>t.removeExpandedPathsByPrefix),Se=et(t=>t.setSelectedPath),cn=et(t=>t.toggleExpandedPath),Vs=et(t=>t.expandPaths),Ot=i.useCallback(t=>{const o=Z(t),u=o.split("/"),h=u[u.length-1]||o,j=h.includes(".")?h.split(".").pop()?.toLowerCase():void 0;return{name:h,path:o,type:"file",extension:j}},[]),Bt=i.useMemo(()=>Ne.map(Ot),[Ne,Ot]),xr=i.useMemo(()=>{if(Ct){const t=is(Ct);if(Ne.some(o=>is(o)===t))return Ct}return Ne[0]??null},[Ne,Ct]),c=i.useMemo(()=>xr?Ot(xr):null,[xr,Ot]),nt=c?.path??"";i.useEffect(()=>{if(!l||!Ct)return;const t=is(Ct);Ne.some(u=>is(u)===t)||Se(l,Ne[0]??null)},[Ne,l,Ct,Se]);const vr=!!(l&&nt&&!Ss(nt,l)),wr=i.useMemo(()=>({allowOutsideWorkspace:vr,directory:l||void 0}),[vr,l]),gt=i.useCallback(t=>({allowOutsideWorkspace:!!(l&&!Ss(t,l))}),[l]),br=i.useRef(null),[un,xa]=i.useState({left:!1,right:!1}),dn=i.useCallback(()=>{const t=br.current;t&&xa({left:t.scrollLeft>2,right:t.scrollLeft+t.clientWidth<t.scrollWidth-2})},[]),fn=i.useRef(dn);fn.current=dn,i.useEffect(()=>{const t=br.current;if(!t)return;const o=()=>fn.current();o(),t.addEventListener("scroll",o,{passive:!0});const u=new ResizeObserver(o);return u.observe(t),()=>{t.removeEventListener("scroll",o),u.disconnect()}},[Bt.length]);const[mn,yr]=i.useState({}),[Ps,os]=i.useState({}),Ke=i.useRef(new Set),Ve=i.useMemo(()=>new Al,[]);i.useEffect(()=>()=>Ve.clear(),[Ve]);const[hn,Ms]=i.useState([]),[va,Ds]=i.useState(!1),[$,pe]=i.useState(""),{isPlaying:zs,play:wa,stop:ba}=sl(),[Ce,xt]=i.useState(!1),[Je,we]=i.useState(null),[ya,He]=i.useState(""),[ge,ue]=i.useState(null),vt=JSON.stringify([tt(),l,ge]),[se,Fe]=i.useState(""),[ls,jr]=i.useState(!1),[pn,ja]=i.useState(`
13
+ `),Na=i.useRef(null),it=i.useRef(null),Ae=i.useRef(null),wt=i.useRef(""),cs=i.useRef(""),ut=i.useRef(null),gn=i.useRef(null),Ze=i.useRef(null),Nr=i.useRef(""),Sr=i.useRef(0),$t=i.useRef(0),Ft=i.useRef(null),[us,Sa]=i.useState(0),[Ca,_t]=i.useState("idle"),[Fa,Ls]=i.useState(!1),[kt,xn]=i.useState(!1),ke=mt(t=>t.autoSaveEnabled),ka=mt(t=>t.setAutoSaveEnabled),[Cr,ds]=i.useState(!1),Wt=i.useRef(null),fs=i.useRef(null),ms=i.useRef(!1),hs=i.useRef(null),ps=i.useRef(null),qe=i.useRef(null),As=i.useRef(null),[Ra,Fr]=i.useState(0),Ut=i.useRef(null),Rt=i.useRef({key:"",attempts:0});i.useEffect(()=>()=>{Ut.current!==null&&typeof window<"u"&&(window.cancelAnimationFrame(Ut.current),Ut.current=null)},[]);const[Tt,kr]=i.useState(null),[Et,Ta]=i.useState(null),[bt,vn]=i.useState(""),[Ea,Rr]=i.useState(!1),[Va,Pa]=i.useState(null),[Ma,Da]=i.useState(null),[za,wn]=i.useState(!1),[La,bn]=i.useState(!1),[Aa,Tr]=i.useState(!1),[yn,Is]=i.useState(!1),[jn,Nn]=i.useState(0),Os=i.useRef(null),Bs=i.useCallback(t=>{const o=t?.currentTarget??Os.current;if(!o)return;const u=document.activeElement;u&&u!==document.body&&u!==o&&(rl(u)||o.contains(u))||o.focus({preventScroll:!0})},[]),$s=i.useRef(null),Sn=!!a.writeFile,Cn=!!a.createDirectory,Fn=!!a.rename,kn=!!a.delete,Rn=!!a.revealPath,Ia=or(t=>t.availableApps),Oa=or(t=>t.isCacheStale),Tn=or(t=>t.initialize),Ba=or(t=>t.loadInstalledApps);i.useEffect(()=>{Tn()},[Tn]);const $a=i.useCallback(t=>{a.revealPath&&a.revealPath(t).catch(()=>{re.error(s("sidebarFilesTree.toast.revealFailed"))})},[a,s]),_a=i.useCallback(async t=>{if(!c?.path||await Ao(c.path,t.id,t.appName)||await Vi(c.path,t.appName))return;const h=Bc(c.path)||l;h&&await Vi(h,t.appName)||re.error(s("filesView.toast.openInAppFailed",{app:t.appName}))},[l,c?.path,s]),Er=i.useCallback((t,o)=>{kr(t),Ta(o),vn(t==="rename"&&o.name||""),Rr(!1)},[]),[H,Ye]=i.useState(null),Kt=i.useRef(!1),yt=i.useRef(null),[En,Ht]=i.useState(!1),at=mt(t=>t.pendingFileNavigation),_s=mt(t=>t.setPendingFileNavigation),Vr=mt(t=>t.pendingFileFocusPath),Pr=mt(t=>t.setPendingFileFocusPath),Vn=mt(t=>t.fileEditorKeymap),gs=zi(t=>t.settingsDefaultFileViewerPreview),Wa=zi(t=>t.showMessageTTSButtons);i.useEffect(()=>{const t=()=>{Kt.current=!1,yt.current=null,Ht(!1)};return document.addEventListener("mouseup",t),()=>document.removeEventListener("mouseup",t)},[]),i.useEffect(()=>()=>{hs.current!==null&&window.clearTimeout(hs.current),ps.current!==null&&window.clearTimeout(ps.current)},[]);const Ua=i.useCallback((t,o)=>{const u=t.split(`
14
+ `),h=Math.max(1,o.start),j=Math.min(u.length,o.end);return h>j?"":u.slice(h-1,j).join(`
15
+ `)},[]),Pn=i.useRef(null),Ka=_l({source:"file",fileLabel:c?.path??null,language:c?.path&&Kr(c.path)||"text",getCodeForRange:t=>Ua($,Wl(t)),toStoreRange:t=>({startLine:t.start,endLine:t.end}),fromDraftRange:t=>({start:t.startLine,end:t.endLine})}),{drafts:Mn,commentText:Ws,setCommentText:Dn,editingDraftId:Us,setSelection:zn,saveComment:Ln,cancel:xs,reset:An,startEdit:In,deleteDraft:On}=Ka;i.useEffect(()=>{Ye(null),An(),Fe(""),jr(!1)},[c?.path,An]),i.useEffect(()=>{zn(H)},[H,zn]),i.useEffect(()=>{if(!H&&!Us)return;const t=u=>{const h=u.target;h.closest('[data-comment-input="true"]')||h.closest('[data-comment-card="true"]')||h.closest(".cm-gutterElement")||h.closest("[data-sonner-toast]")||h.closest("[data-sonner-toaster]")||Ws.trim()||(Ye(null),xs())},o=setTimeout(()=>{document.addEventListener("click",t)},100);return()=>{clearTimeout(o),document.removeEventListener("click",t)}},[xs,Ws,Us,H]),i.useEffect(()=>{if(!p||!H)return;const t=qe.current;if(!t)return;const o=t.state.selection.main;o.empty||t.dispatch({selection:{anchor:o.head}});const u=document.getSelection();u&&!u.isCollapsed&&u.anchorNode&&t.contentDOM.contains(u.anchorNode)&&u.removeAllRanges()},[p,H]);const Bn=i.useCallback((t,o)=>{const u=o??H??void 0;o&&Ye(o),Ln(t,u),Ye(null)},[H,Ln]),$n=i.useCallback((t,o)=>{const u=[];for(const h of o){if(!(h&&typeof h.name=="string"&&h.name.length>0)||!N&&h.name.startsWith(".")||!S&&Hc(h.name))continue;const j=h.name,C=Z(h.path||""),P=C?Wc(C)?C:Z(`${t}/${C}`):Z(`${t}/${j}`),O=h.isDirectory?"directory":"file",de=O==="file"&&j.includes(".")?j.split(".").pop()?.toLowerCase():void 0;u.push({name:j,path:P,type:O,extension:de})}return _c(u)},[S,N]),Pe=i.useCallback(async(t,o=!1)=>{if(!R)return;const u=Z(t.trim());if(!u||!o&&Ke.current.has(u))return;const h=V.current,j=tt();return Ve.run(u,async C=>{const P=()=>C()&&V.current===h&&tt()===j;try{const O=a.listDirectory?(await a.listDirectory(u)).entries:await Io.listLocalDirectory(u);if(!P())return;const de=$n(u,O);Ke.current=new Set(Ke.current),Ke.current.add(u),os(L=>{if(!L[u])return L;const oe={...L};return delete oe[u],oe}),yr(L=>L[u]&&Il(L[u],de)?L:{...L,[u]:de})}catch(O){if(!P())return;const de=O instanceof Error?O.message:String(O??"");if(de==="Directory not found"&&l&&u!==l){ln(l,u),os(L=>{if(!L[u])return L;const oe={...L};return delete oe[u],oe});return}console.error("Failed to load files directory:",O),os(L=>({...L,[u]:de}))}},o)},[Ve,a,$n,ln,l,R]),Ks=i.useCallback(async()=>{l&&(Ke.current=new Set,Ve.clear(),os({}),yr(t=>Object.keys(t).length===0?t:{}),await Pe(l))},[Ve,Pe,l]),Ie=i.useCallback(async t=>{if(!t){await Ks();return}const o=Z(t);Ke.current=new Set(Ke.current),Ke.current.delete(o),await Pe(o,!0)},[Pe,Ks]),{canUpload:_n,uploadingDirectory:Ha,pickFiles:Wn,uploadElements:qa}=vl({root:l,refreshDirectory:Ie}),Hs=Ha!==null,Un=i.useRef(""),Kn=i.useRef("");i.useEffect(()=>{if(!l)return;const t=k,o=Un.current!==D,u=Kn.current!==t;!o&&!u||(o&&(Un.current=D,$t.current+=1,Ft.current=null,pe(""),we(null),He(""),ue(null),q(!1)),u&&(Kn.current=t,Ke.current=new Set,Ve.clear(),os({}),yr(h=>Object.keys(h).length===0?h:{}),Pe(l)))},[Ve,D,Pe,l,k]),i.useEffect(()=>{if(!R||!a.listDirectory)return;const t=()=>{if(!document.hidden&&rt.length>0)for(const o of rt)Ve.has(o)||Ie(o)};return document.addEventListener("visibilitychange",t),()=>document.removeEventListener("visibilitychange",t)},[Ve,rt,a.listDirectory,Ie,R]);const Hn=i.useRef(!1);i.useEffect(()=>{const t=R&&!Hn.current;if(Hn.current=R,!(!R||!l)&&(Pe(l),t))for(const o of rt)Ve.has(o)||Ie(o)},[Ve,rt,Pe,Ie,l,R]),i.useEffect(()=>{if(!R||!a.listDirectory||rt.length===0)return;const t=setInterval(()=>{if(!document.hidden)for(const o of rt)Ve.has(o)||Ie(o)},8e3);return()=>clearInterval(t)},[Ve,rt,a.listDirectory,Ie,R]);const Ga=i.useCallback(async t=>{if(t?.preventDefault(),!Et||!Tt)return;Rr(!0);const o=()=>{kr(null)},u=j=>{re.error(j)},h=()=>{Rr(!1)};if(Tt==="createFile"){if(!bt.trim()){u(s("sidebarFilesTree.toast.filenameRequired")),h();return}if(!a.writeFile){u(s("sidebarFilesTree.toast.writeNotSupported")),h();return}const j=Et.path,C=j?`${j}/`:"",P=Z(`${C}${bt.trim()}`);await a.writeFile(P,"").then(async O=>{O.success&&(re.success(s("sidebarFilesTree.toast.fileCreated")),await Ie(j)),o()}).catch(()=>u(s("sidebarFilesTree.toast.operationFailed"))).finally(h);return}if(Tt==="createFolder"){if(!bt.trim()){u(s("sidebarFilesTree.toast.folderNameRequired")),h();return}const j=Et.path,C=j?`${j}/`:"",P=Z(`${C}${bt.trim()}`);await a.createDirectory(P).then(async O=>{O.success&&(re.success(s("sidebarFilesTree.toast.folderCreated")),await Ie(j)),o()}).catch(()=>u(s("sidebarFilesTree.toast.operationFailed"))).finally(h);return}if(Tt==="rename"){if(!bt.trim()){u(s("sidebarFilesTree.toast.nameRequired")),h();return}if(!a.rename){u(s("sidebarFilesTree.toast.renameNotSupported")),h();return}const j=Et.path,C=j.split("/").slice(0,-1).join("/"),P=C?`${C}/`:"",O=Z(`${P}${bt.trim()}`);await a.rename(j,O).then(async de=>{de.success&&(re.success(s("sidebarFilesTree.toast.renamedSuccessfully")),await Ie(C),l&&pt(l,j),(c?.path===j||c?.path.startsWith(`${j}/`))&&(l&&Se(l,null),pe(""),we(null),He(""),ue(null),p&&q(!1))),o()}).catch(()=>u(s("sidebarFilesTree.toast.operationFailed"))).finally(h);return}if(Tt==="delete"){if(!a.delete){u(s("sidebarFilesTree.toast.deleteNotSupported")),h();return}const j=Et.path,C=j.split("/").slice(0,-1).join("/");await a.delete(j).then(async P=>{P.success&&(re.success(s("sidebarFilesTree.toast.deletedSuccessfully")),await Ie(C),l&&pt(l,j),(c?.path===j||c?.path.startsWith(`${j}/`))&&(l&&Se(l,null),pe(""),we(null),He(""),ue(null),p&&q(!1))),o()}).catch(()=>u(s("sidebarFilesTree.toast.operationFailed"))).finally(h);return}h()},[Tt,Et,bt,a,Ie,p,pt,l,c?.path,Se,s]);i.useEffect(()=>{if(!g){Ms([]),Ds(!1);return}const t=G.trim();if(!t){Ms([]),Ds(!1);return}let o=!1;return Ds(!0),U(g,t,150,{includeHidden:N,respectGitignore:!S,type:"file"}).then(u=>{if(o)return;const j=u.filter(C=>S||!qc(C.path)).map(C=>({name:C.name,path:Z(C.path),type:"file",extension:C.extension,relativePath:C.relativePath}));Ms(j)}).catch(()=>{o||Ms([])}).finally(()=>{o||Ds(!1)}),()=>{o=!0}},[g,G,U,N,S]);const qs=i.useCallback(async(t,o)=>{const u=gt(t);if(a.readFile)return(await a.readFile(t,{...u,directory:l||void 0,...o})).content??"";const h=new URLSearchParams({path:t});u.allowOutsideWorkspace&&h.set("allowOutsideWorkspace","true"),l&&h.set("directory",l);const j=await en(`/api/fs/read?${h.toString()}`,{cache:o?.fresh?"no-store":"default",signal:AbortSignal.timeout(3e4)});if(!j.ok){const C=await j.json().catch(()=>({error:j.statusText}));throw new Error(C.error||s("filesView.error.readFileFailed"))}return j.text()},[a,gt,l,s]),ot=i.useCallback(async t=>{if(a.statFile){const o=gt(t),u=await a.statFile(t,{...o,directory:l||void 0});return{path:u.path,size:u.size,mtimeMs:u.mtimeMs}}return null},[a,gt,l]);i.useEffect(()=>{if(!l||!a.statFile||Ne.length===0)return;let t=!1;const o=[...Ne];return Promise.all(o.map(async u=>{try{const h=gt(u),j=await a.statFile?.(u,{...h,directory:l||void 0});!t&&j&&!j.isFile&&pt(l,u)}catch(h){!t&&Yi(h)&&pt(l,u)}})),()=>{t=!0}},[a,Ne,pt,gt,l]);const Oe=se!==$,qt=i.useCallback(async()=>{if(!c||!a.writeFile)return re.error(s("filesView.toast.savingNotSupported")),!1;const t=bs(c.path)||kt;if(!mc({selectedFilePath:c.path,loadedFilePath:ge,fileLoading:Ce,isDirty:Oe,draftContent:se,fileContent:$,isNonEditableBinary:t}))return t?console.warn(`[saveDraft] refusing to save binary file "${c.path}".`):se===""&&$!==""&&ge!==c.path&&console.warn(`[saveDraft] refusing to save empty draft for "${c.path}" (${$.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(!Oe)return!0;jr(!0);try{const o=gc(se,pn);if(!(await a.writeFile(c.path,o))?.success)return re.error(s("filesView.toast.writeFileFailed")),!1;if(pe(se),Nr.current=o,Sr.current+=1,l&&Ss(c.path,l)){const h=dr(l,c.path);h&&nl.requestGitRefresh({directory:l,paths:[h]})}if(l&&/(?:^|\/)\.agents\/loops\/[^/]+\.md$/i.test(Z(c.path))){const h=il.getState().projects.find(j=>Z(j.path)===Z(l));if(h)try{await Ol(h.id)}catch{re.error(s("sessions.scheduledTasks.dialog.toast.updateFailed"))}}return c?.path&&ys(c.path)&&(wt.current=se,cs.current=se),ot(c.path).then(h=>{h&&(Ze.current=h)}).catch(()=>{}),!0}catch(o){return re.error(o instanceof Error?o.message:s("filesView.toast.saveFailed")),!1}finally{jr(!1)}},[kt,se,$,Ce,a,Oe,pn,ge,ot,l,c,s]);i.useEffect(()=>{ke||(_t("idle"),it.current&&(clearTimeout(it.current),it.current=null))},[ke]);const qn=1500;i.useEffect(()=>{const t=!!(c&&a.writeFile),o=!!(c?.path&&(bs(c.path)||kt));if(fc({autoSaveEnabled:ke,isDirty:Oe,canWrite:t,isSaving:ls,fileLoading:Ce,selectedFilePath:c?.path,loadedFilePath:ge,isNonEditableBinary:o}))return it.current=setTimeout(()=>{qt().then(u=>{u&&(_t("saved"),setTimeout(()=>_t("idle"),2e3))})},qn),()=>{it.current&&(clearTimeout(it.current),it.current=null)}},[ke,kt,se,Ce,Oe,ge,c,a.writeFile,ls,qt]),i.useEffect(()=>{_t("idle")},[c?.path]),al({save_file:t=>{if(!(t.target instanceof Node)||!As.current?.contains(t.target))return!1;it.current&&(clearTimeout(it.current),it.current=null),ls||qt().then(o=>{o&&(_t("saved"),setTimeout(()=>_t("idle"),2e3))})},find_in_file:t=>{if(!(t.target instanceof Node))return!1;if(Xe&&$e()==="preview"){if(p||!(ne?$s.current:Os.current)?.contains(t.target))return!1;Is(!0),Nn(u=>u+1);return}if(!As.current?.contains(t.target))return!1;ze(!0)}});const Gt=i.useCallback(t=>{const{content:o,lineEnding:u}=pc(t);return Nr.current=t,Sr.current+=1,ja(u),pe(o),wt.current=o,cs.current=o,Fe(o),o},[]),Gn=i.useCallback(async t=>{const o=$t.current+1;$t.current=o;const u=tt(),h=A.current,j=()=>{if(!l||tt()!==u||A.current!==h)return!1;const L=et.getState().byRoot[l],oe=L?.selectedPath??L?.openPaths[0]??null;return $t.current===o&&oe===t.path};we(null),He(""),ue(null),xn(!1),xt(!0);const C=Hr(t.path),P=qr(t.path),O=Li(t.path),de=bs(t.path);if(p&&q(!0),w.isDesktop&&C&&!P){pe(""),Fe("");return}if(!w.isDesktop&&C&&!P){pe(""),Fe(""),ue(t.path),xt(!1);return}if(O){pe(""),Fe(""),ue(t.path),xt(!1);return}if(de){pe(""),Fe(""),ue(t.path),xt(!1);return}await qs(t.path).then(L=>{if(!j())return;if(Ai(L)){xn(!0),pe(""),Fe(""),ue(t.path);return}const oe=Gt(L),Vt=Qr(t.path)||cr(t.path)||Qi(t.path)||ys(t.path)||qr(t.path)||Ii(t.path)||Oi(t.path);ae(Vt?"edit":xc(oe,At.current[t.path])),ue(t.path),ot(t.path).then(ss=>{ss&&j()&&(Ze.current=ss)}).catch(()=>{})}).catch(L=>{if(j()){if(Gc(L)){if(xt(!1),l&&Se(l,null),we(null),pe(""),Fe(""),ue(null),Ze.current=null,te.trim().length>0&&ee(""),p&&q(!1),l){const Vt=[...Ji(t.path,l),t.path];Vt.length>0&&Vs(l,Vt);for(const ss of Vt)Ke.current.has(ss)||Pe(ss)}return}if(Yi(L)){l&&pt(l,t.path),pe(""),Fe(""),we(null),Ze.current=null,p&&q(!1);return}pe(""),Fe(""),we(L instanceof Error?L.message:s("filesView.error.readFileFailed")),Ze.current=null}}).finally(()=>{j()&&xt(!1)})},[Gt,Vs,p,Pe,qs,ot,pt,l,w.isDesktop,te,Se,s]),Gs=i.useCallback(async(t,o)=>{if(!e||!l)return;const u=Ji(t,l),h=o?[...u,t]:u;if(h.length>0&&Vs(l,h),!R)return;const j=h.map(C=>{if(!Ke.current.has(C))return Pe(C)}).filter(Boolean);await Promise.all(j)},[Vs,Pe,l,R,e]),Xn=i.useCallback((t,o)=>{const u=o.findIndex(h=>h.path===t);return u===-1||o.length<=1?null:o[u+1]??o[u-1]??null},[]),Me=i.useCallback(async t=>{if(ms.current)ms.current=!1;else if(Oe){ds(!0),Wt.current=t;return}l&&(Se(l,t.path),Gs(t.path,!1)),we(null),He(""),pe(""),wt.current="",cs.current="",Fe(""),ue(null),p&&q(!0)},[Gs,Oe,p,l,Se]);i.useEffect(()=>{c?.path&&Gs(c.path,!1)},[Gs,c?.path]),i.useEffect(()=>{if(!e)return;if(!c){$t.current+=1,Ft.current=null,xt(!1);return}if(ge===c.path||Ft.current===c.path)return;const t=c.path;Ft.current=t,Gn(c).finally(()=>{Ft.current===t&&(Ft.current=null)})},[us,Gn,ge,c,e]);const Xs=i.useRef(Oe);Xs.current=Oe,i.useEffect(()=>wl(({runtimeKey:t,paths:o})=>{const u=c?.path;t!==tt()||!u||Xs.current||!o.includes(Z(u))||($t.current+=1,Ft.current=null,Ze.current=null,He(""),we(null),ue(null),Sa(h=>h+1))}),[c?.path]),i.useEffect(()=>{if(!e||!c?.path||ge!==c.path)return;const t=c.path,o=tt(),u=A.current,h=()=>Xs.current||ys(t)&&wt.current!==cs.current,j=!bs(t)&&!Hr(t)&&!kt?oc({readContent:()=>qs(t,{fresh:!0}),getLoadedContent:()=>Nr.current,getLoadedRevision:()=>Sr.current,isDirty:h,applyContent:L=>{if(!(C||tt()!==o||A.current!==u)){if(Ai(L)){ue(null);return}Gt(L)}}}):null;let C=!1,P=!1;const O=()=>{document.hidden||P||(P=!0,ot(t).then(async L=>{if(C||tt()!==o||A.current!==u||!L)return;const oe=Ze.current;if(!oe||oe.path!==t){Ze.current=L;return}if(cc(oe,L)){if(j&&L.size<=Xc){await j.poll()&&!C&&(Ze.current=L);return}Xs.current||(Ze.current=L,ue(null))}}).catch(()=>{}).finally(()=>{P=!1}))};O();const de=window.setInterval(O,2e3);return()=>{C=!0,j?.dispose(),window.clearInterval(de)}},[Gt,kt,ge,qs,ot,c?.path,e]);const Xa=i.useCallback(()=>{const t=Wt.current,o=fs.current;if(Wt.current=null,fs.current=null,ms.current=!0,ds(!1),Fe($),o){l&&It(l,o),c?.path===o&&(t?Me(t):(l&&Se(l,null),pe(""),we(null),He(""),ue(null),p&&q(!1)));return}if(t){Me(t);return}},[$,Me,p,It,l,c?.path,Se]),Ja=i.useCallback(async()=>{const t=Wt.current,o=fs.current;if(!await qt()){ms.current=!1;return}if(Wt.current=null,fs.current=null,ms.current=!0,ds(!1),o){l&&It(l,o),c?.path===o&&(t?await Me(t):(l&&Se(l,null),pe(""),we(null),He(""),ue(null),p&&q(!1)));return}if(t){await Me(t);return}},[Me,p,It,l,qt,c?.path,Se]),Jn=i.useCallback(t=>{const o=c?.path===t,u=Xn(t,Bt);if(o&&Oe){ds(!0),Wt.current=u,fs.current=t;return}if(l&&It(l,t),!!o){if(u){Me(u);return}l&&Se(l,null),pe(""),we(null),He(""),ue(null),p&&q(!1)}},[Xn,Me,Oe,p,Bt,It,l,c?.path,Se]),Zn=i.useMemo(()=>new Set(Ne),[Ne]),Js=i.useMemo(()=>Bl(T?Y?.files??[]:[]),[Y?.files,T]),Za=i.useCallback(t=>{if(Zn.has(t))return"open";const o=t.startsWith(l+"/")?t.slice(l.length+1):t;return Js.statusByPath.get(o)??null},[Zn,Js,l]),Ya=i.useCallback(t=>{if(!Y?.files)return null;const o=t.startsWith(l+"/")?t.slice(l.length+1):t;return Js.badgeByDir.get(o)??null},[Y,Js,l]),Qa=i.useCallback(async t=>{const o=Z(t);l&&(cn(l,o),Ke.current.has(o)||await Pe(o))},[Pe,l,cn]),eo=i.useMemo(()=>({canRename:Fn,canCreateFile:Sn,canCreateFolder:Cn,canDelete:kn,canReveal:Rn}),[Fn,Sn,Cn,kn,Rn]);function Yn(t,o){const u=mn[t]??[];return u.map((h,j)=>{const C=h.type==="directory",P=C&&ga.has(h.path),O=c?.path===h.path,de=j===u.length-1;return r.jsxs("li",{className:"relative",children:[o>0&&r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"absolute top-3.5 left-[-12px] w-3 h-px bg-border/40"}),de&&r.jsx("span",{className:"absolute top-3.5 bottom-0 left-[-13px] w-[2px] bg-background"})]}),r.jsx(Jc,{node:h,root:l,isExpanded:P,isActive:O,isMobile:p,isBrowserClient:y,alwaysShowActions:F,status:C?void 0:Za(h.path),badge:C?Ya(h.path):void 0,permissions:eo,downloadFile:a.downloadFile,contextMenuPath:Va,setContextMenuPath:Pa,rightClickMenuPath:Ma,setRightClickMenuPath:Da,onSelect:Me,onToggle:Qa,onRevealPath:$a,onOpenDialog:Er,canUpload:_n&&!Hs,onPickFiles:Wn}),C&&P&&r.jsxs("ul",{className:"flex flex-col gap-1 ml-3 pl-3 border-l border-border/40 relative",children:[Ps[h.path]?r.jsxs("li",{className:"flex items-center gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[r.jsx("span",{className:"min-w-0 flex-1 truncate text-[var(--status-error)]",title:Ps[h.path],children:Ps[h.path]}),r.jsxs(I,{variant:"ghost",size:"xs",className:"h-6 gap-1",onClick:()=>{Ie(h.path)},children:[r.jsx(E,{name:"refresh",className:"size-3.5"}),s("filesView.tree.actions.refreshTitle")]})]}):null,Yn(h.path,o+1)]})]},h.path)})}const Be=!!(c?.path&&Hr(c.path)),Ge=!!(c?.path&&qr(c.path)),Qn=Ge&&ye==="edit",jt=!!(c?.path&&Li(c.path)),ei=!!(c?.path&&ol(c.path)),Mr=ei||!!(c?.path&&ll(c.path)),Dr=!!(c?.path&&cl(c.path)),Zs=!!(c?.path&&(bs(c.path)||kt)),Xt=Zs&&!Be&&!jt&&!Mr&&!Dr,ti=Zs||Be&&!Qn,si=i.useMemo(()=>Z(at?.path??""),[at?.path]),Jt=!!(at&&si&&nt&&nt===si&&!Ce&&!Je&&!ti),Nt=i.useMemo(()=>dr(l,nt),[nt,l]),to=!!(c&&(!Be||Ge)&&!jt&&!Xt&&$.length>0),so=!!(c&&Nt.length>0),Qe=!!(c&&!vr&&!Zs&&(!Be||Ge)&&a.writeFile),Xe=!!(c?.path&&Qr(c.path)),Zt=!!(c?.path&&Qi(c.path)),Yt=!!(c?.path&&cr(c.path)),vs=!!(c?.path&&ys(c.path)),Qt=!!(c?.path&&Ii(c.path)),es=!!(c?.path&&Oi(c.path)),Ys=!!(c&&!Zs&&(!Be||Ge))&&!Xe&&!vs&&!(Yt&&xe==="preview")&&!(Ge&&ye==="preview")&&!(Qt&&We==="preview")&&!(es&&Le==="table"),ro=Xe&&fe==="edit"||Yt&&xe==="edit"||Ge&&ye==="edit"||Qt&&We==="edit"||es&&Le==="text"||Zt&&le==="text"||!Xe&&!Yt&&!Zt&&!Ge&&!Qt&&!es&&_==="edit",Qs=i.useMemo(()=>nt?ul(nt):null,[nt]),[ri,zr]=i.useState(null);i.useEffect(()=>{let t=!1;const o=c?.path;if(!o||Qs){zr(null);return}return zr(null),dl(o).then(u=>{t||zr(u)}),()=>{t=!0}},[c?.path,Qs]),i.useEffect(()=>{!Qe&&_==="edit"&&ae("view")},[Qe,_]);const Lr="openchamber:files:md-viewer-mode",Ar="openchamber:files:html-viewer-mode",Ir="openchamber:files:json-viewer-mode";i.useEffect(()=>{const t=c?.path;if(!t)return;ae(At.current[t]??"edit");let o=gs?"preview":"edit";try{const j=localStorage.getItem(Lr);(j==="preview"||j==="edit")&&(o=j)}catch{}me(hr.current[t]??o);let u=gs?"preview":"edit";try{const j=localStorage.getItem(Ar);(j==="preview"||j==="edit")&&(u=j)}catch{}he(pr.current[t]??u),Ee(gr.current[t]??(gs?"preview":"edit")),lt(nn.current[t]??"preview"),ct(an.current[t]??"preview"),Ue(on.current[t]??"table");let h=gs?"tree":"text";try{const j=localStorage.getItem(Ir);(j==="tree"||j==="text")&&(h=j)}catch{}be(h)},[c?.path,gs]);const no=i.useCallback(t=>{const o=c?.path;o&&(At.current[o]=t),ae(t)},[c?.path]),io=i.useCallback(t=>{const o=c?.path;o&&(hr.current[o]=t),me(t);try{localStorage.setItem(Lr,t)}catch{}},[c?.path]),$e=i.useCallback(()=>fe,[fe]),ao=i.useCallback(t=>{const o=c?.path;o&&(nn.current[o]=t),lt(t)},[c?.path]),oo=i.useCallback(t=>{const o=c?.path;o&&(an.current[o]=t),ct(t)},[c?.path]),lo=i.useCallback(t=>{const o=c?.path;o&&(on.current[o]=t),Ue(t)},[c?.path]);i.useEffect(()=>{const t=c?.path;if(as(null),!t||ge!==t)return;let o=!1;return ot(t).then(u=>{!o&&u&&as(u.size)}).catch(()=>{}),()=>{o=!0}},[us,ge,ot,c?.path]);const ni=c&&Xe&&$e()==="preview"&&!Ce?c.path:null;i.useEffect(()=>{!ni||p||Bs()},[Bs,ne,p,ni]);const co=i.useCallback(t=>{be(t);try{localStorage.setItem(Ir,t)}catch{}},[]),uo=i.useCallback(t=>{const o=c?.path;o&&(pr.current[o]=t),he(t);try{localStorage.setItem(Ar,t)}catch{}},[c?.path]),fo=i.useCallback(t=>{const o=c?.path;if(o&&(gr.current[o]=t),Ae.current&&(clearTimeout(Ae.current),Ae.current=null),ut.current!==null&&(cancelAnimationFrame(ut.current),ut.current=null),t==="edit")Fe(wt.current||$),Ee(t);else{wt.current=se;const u=o;Ee("edit"),ut.current=requestAnimationFrame(()=>{ut.current=requestAnimationFrame(()=>{ut.current=null,!(l&&u&&et.getState().byRoot[l]?.selectedPath!==u)&&(St(h=>h+1),Ee("preview"))})});return}},[se,$,l,c?.path]),Or=i.useCallback(async(t,o)=>{if(!a.writeFile||o===cs.current)return!1;if(!(await a.writeFile(t,o))?.success)return re.error(s("filesView.toast.writeFileFailed")),!1;Gt(o);const h=await ot(t).catch(()=>null);return h&&(Ze.current=h),!0},[Gt,a,ot,s]);i.useEffect(()=>()=>{Ae.current&&(clearTimeout(Ae.current),Ae.current=null),ut.current!==null&&(cancelAnimationFrame(ut.current),ut.current=null)},[ve,c?.path]);const mo=i.useCallback(t=>{if(wt.current=t,!ke||!c?.path||ve!=="preview"||!a.writeFile)return;Ae.current&&clearTimeout(Ae.current);const o=c.path;Ae.current=setTimeout(()=>{Ae.current=null,Or(o,t).then(u=>{u&&(Ls(!0),setTimeout(()=>Ls(!1),1500))}).catch(u=>{re.error(u instanceof Error?u.message:s("filesView.toast.saveFailed"))})},qn)},[ke,ve,a.writeFile,Or,c?.path,s]),ho=i.useMemo(()=>vs&&(wt.current||se)||$,[se,$,vs]),ii=i.useCallback(()=>xe,[xe]);i.useEffect(()=>{const t=u=>{const h=u?"preview":"edit",j=u?"tree":"text";for(const C of Ne)At.current[C]="edit",Qr(C)&&(hr.current[C]=h),cr(C)&&(pr.current[C]=h),ys(C)&&(gr.current[C]=h);ae("edit"),me(h),he(h),Ee(h),be(j);try{localStorage.setItem(Lr,h),localStorage.setItem(Ar,h),localStorage.setItem(Ir,j)}catch{}},o=u=>{const h=!!u.detail?.enabled;t(h)};return window.addEventListener("openchamber:file-viewer-preview-mode-changed",o),()=>{window.removeEventListener("openchamber:file-viewer-preview-mode-changed",o)}},[Ne]),i.useEffect(()=>{if(!at||!l)return;const t=()=>{typeof window>"u"||Ut.current===null&&(Ut.current=window.requestAnimationFrame(()=>{Ut.current=null,Fr(ft=>ft+1)}))},o=(ft,Pt)=>{if(ft.state.doc.length!==Pt.length)return!1;if(Pt.length===0)return!0;const Ur=Math.min(128,Pt.length);if(ft.state.sliceDoc(0,Ur)!==Pt.slice(0,Ur))return!1;const Ti=Math.max(0,Pt.length-Ur);return ft.state.sliceDoc(Ti,Pt.length)===Pt.slice(Ti)},u=Z(at.path);if(!u){_s(null),Rt.current={key:"",attempts:0};return}const h=`${u}:${at.line}:${at.column??1}`;if(Rt.current.key!==h&&(Rt.current={key:h,attempts:0}),c?.path!==u){if(Cr)return;Me(Ot(u));return}if(Ce||ge!==u)return;if(Je||Be||jt||Xt){_s(null),Rt.current={key:"",attempts:0};return}if(!Qe)return;if(_!=="edit"){ae("edit");return}const j=qe.current;if(!j){t();return}if(!o(j,se)){t();return}const C=Math.max(1,Math.min(at.line,j.state.doc.lines)),P=j.state.doc.line(C),O=Math.max(1,at.column||1),de=Math.max(0,P.to-P.from),L=Math.min(de,O-1),oe=P.from+L;if(!(j.state.selection.main.head===oe)||Rt.current.attempts===0){Rt.current.attempts+=1,j.dispatch({selection:{anchor:oe},effects:Lt.scrollIntoView(oe,{y:"center"})}),j.focus(),t();return}typeof window<"u"&&window.requestAnimationFrame(()=>{const ft=qe.current;ft&&(ft.dispatch({selection:{anchor:oe},effects:Lt.scrollIntoView(oe,{y:"center"})}),ft.focus())}),_s(null),Rt.current={key:"",attempts:0}},[Qe,Cr,se,Ra,Je,Ce,Be,jt,Xt,ge,Me,at,l,c?.path,_s,_,Ot]),i.useEffect(()=>{if(!Vr||!l)return;const t=Z(Vr);if(!t){Pr(null);return}c?.path===t&&(Ce||ge!==t||(!Je&&!Be&&!jt&&!Xt&&Qe&&_==="edit"&&qe.current?.focus(),Pr(null)))},[Qe,Je,Ce,Be,jt,Xt,ge,Vr,l,c?.path,Pr,_]);const ts=i.useCallback(t=>{if(!p||!t||typeof window>"u")return;const o=document.activeElement,u=!t.hasFocus&&o instanceof HTMLElement&&t.dom.contains(o)?o.closest('[data-comment-input="true"]'):null;if(!t.hasFocus&&!u)return;const h=window.visualViewport;if(!h)return;const j=document.documentElement.clientHeight||window.innerHeight;if(Math.max(0,j-(h.offsetTop+h.height))<=0)return;const P=u?u.getBoundingClientRect():t.coordsAtPos(t.state.selection.main.head);if(!P)return;const O=Math.round(h.offsetTop+h.height),L=P.bottom+20-O;L<=0||(t.scrollDOM.scrollTop+=L)},[p]);i.useEffect(()=>{if(!p||typeof window>"u")return;const t=()=>{window.requestAnimationFrame(()=>{ts(qe.current)})},o=window.visualViewport;return o?.addEventListener("resize",t),o?.addEventListener("scroll",t,{passive:!0}),document.addEventListener("selectionchange",t),()=>{o?.removeEventListener("resize",t),o?.removeEventListener("scroll",t),document.removeEventListener("selectionchange",t)}},[p,ts]),fl("open_go_to_line",t=>{if(!Qe||_!=="edit"||p)return!1;const o=t.target;if(o?.closest('[role="dialog"]')||!(o instanceof Node)||!As.current?.contains(o))return!1;const u=!!o?.closest(".cm-editor");if(!!o?.closest('input, textarea, [contenteditable="true"], [role="textbox"]')&&!u)return!1;Tr(!0)});const er=mt(t=>t.editorFontSize),ai=i.useMemo(()=>{if(!c?.path)return[Bi(f,{fontSize:er})];const t=Kr(c.path),o=[Bi(f,t?{syntaxColors:!1,fontSize:er}:{fontSize:er})],u=Qs??ri;return u&&o.push(u),t&&o.push(Fl({language:t,themeName:f.metadata.id,theme:Pl(f)})),Q&&o.push(Lt.lineWrapping),p&&o.push(Lt.updateListener.of(h=>{h.view.hasFocus&&(h.selectionSet||h.focusChanged||h.viewportChanged||h.geometryChanged)&&window.requestAnimationFrame(()=>{ts(h.view)})})),o},[f,c?.path,Qs,ri,Q,p,ts,er]),oi=i.useMemo(()=>({light:Rs.metadata.id,dark:Ts.metadata.id}),[Rs.metadata.id,Ts.metadata.id]),li=jt||Mr||Dr,ws=c?.path&&li?`${c.path}|${wr.allowOutsideWorkspace?"outside":"workspace"}|${us}`:"",tr=c?.path&&Yt&&xe==="preview"&&!w.isVSCode?`${c.path}|${us}`:"",ci=s("filesView.error.readFileFailed"),{readyKey:ui,nonce:po}=ta(tr,we,ci),{readyKey:di,nonce:sr}=ta(ws,we,ci),go=!!(tr&&ui!==tr),Br=!!(ws&&di!==ws),xo=c?.path&&Be?Ge?`data:${ml(c.path)};utf8,${encodeURIComponent($)}`:ya:"",rr=c?.path&&li&&ws&&di===ws?Pi().authenticatedAsset(Oo("/api/fs/raw",l),{path:c.path,allowOutsideWorkspace:wr.allowOutsideWorkspace?"true":void 0,directory:l||void 0}):"",vo=i.useCallback(t=>r.jsx("div",{className:"h-full overflow-hidden bg-[var(--surface-background)]",children:r.jsx("iframe",{src:rr,className:"h-full w-full border-0",title:t.name},sr)}),[rr,sr]),fi=c&&a.downloadFile?r.jsxs(I,{type:"button",variant:"outline",size:"sm",onClick:()=>{const t=a.downloadFile;!t||!c||t(c.path).catch(o=>{console.error("Download failed:",o),re.error(s("sidebarFilesTree.toast.operationFailed"))})},children:[r.jsx(E,{name:"download",className:"mr-2 size-4"}),s("filesView.editor.saveFile")]}):null,nr=c&&!Ce&&!Br&&!Je?(t=>Be&&!Qn?r.jsx(Tc,{src:xo,name:t.name,sizeBytes:je}):jt?vo(t):Mr?r.jsx(Ec,{kind:ei?"video":"audio",src:rr,name:t.name,sizeBytes:je,download:fi},sr):Dr?r.jsx(Fc,{src:rr,name:t.name,sizeBytes:je},sr):Xt?r.jsx(Nc,{name:t.name,path:t.path,sizeBytes:je,download:fi}):es&&Le==="table"?r.jsx(Dc,{path:t.path,content:$,sizeBytes:je}):Qt&&We==="preview"?r.jsx("div",{className:"h-full min-h-0 overflow-hidden",children:r.jsx(ar,{fallback:r.jsxs("div",{className:"m-3 rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[r.jsx("div",{className:"mb-1 font-medium text-destructive",children:s("filesView.error.previewUnavailable")}),r.jsx("div",{className:"text-sm text-muted-foreground",children:s("filesView.error.switchToEditMode")})]}),children:r.jsx(Xr,{content:`\`\`\`mermaid
16
+ ${$}
17
+ \`\`\``,className:"markdown-mermaid-fullscreen h-full",enableFileReferences:!1,allowMermaidWheelEvents:!0})})}):null)(c):null;i.useEffect(()=>{let t=!1,o="";return(async()=>{if(!c?.path||!Be||Ge){He("");return}we(null);const h=gt(c.path);if(t)return;await(a.readFileBinary?a.readFileBinary(c.path,h).then(C=>C.dataUrl):(async()=>{const C=await en("/api/fs/raw",{signal:AbortSignal.timeout(3e4),query:{path:c.path,allowOutsideWorkspace:h.allowOutsideWorkspace?"true":void 0,directory:l||void 0}});if(!C.ok)throw new Error(s("filesView.error.readFileFailed"));const P=await C.blob();return o=URL.createObjectURL(P),t?(URL.revokeObjectURL(o),o="",""):o})()).then(C=>{t||(He(C),ue(c.path))}).catch(C=>{t||(He(""),we(C instanceof Error?C.message:s("filesView.error.readFileFailed")),ue(null))}).finally(()=>{t||xt(!1)})})(),()=>{t=!0,o&&URL.revokeObjectURL(o)}},[us,a,Be,Ge,gt,l,c?.path,wr,s]);const wo=i.useCallback(()=>kr(null),[]),bo=i.useMemo(()=>Ul({drafts:Mn,editingDraftId:Us,commentText:Ws,onTextChange:Dn,selection:H,isDragging:En,fileLabel:c?.path??"",newWidgetId:"files-new-comment-input",mapDraftToRange:t=>({start:t.startLine,end:t.endLine}),onSave:Bn,onCancel:()=>{Ye(null),xs()},onEdit:t=>{In(t),Ye({start:t.startLine,end:t.endLine})},onDelete:On}),[xs,Ws,On,Us,Mn,Bn,En,H,c?.path,Dn,In]),mi=Hi(),hi=Hi(),pi=!Ce&&!Je&&ge===nt,ir=pi&&Ys&&_==="view"&&!(Zt&&le==="tree"),gi=pi&&Xe&&$e()==="preview",{setScroller:xi,restore:yo}=lr(ir?`${vt}:code`:null),{setScroller:vi,restore:jo}=lr(ir?`${vt}:code:fullscreen`:null),{setScroller:wi}=lr(gi?`${vt}:markdown`:null),{setScroller:bi}=lr(gi?`${vt}:markdown:fullscreen`:null),{setScroller:yi}=mi,{setScroller:ji}=hi,No=i.useCallback(t=>{yi(t),xi(t)},[yi,xi]),So=i.useCallback(t=>{ji(t),vi(t)},[ji,vi]),[Co,Fo]=i.useState(null),[ko,Ro]=i.useState(null),To=i.useCallback(t=>{Pn.current=t,Os.current=t,Fo(t),wi(t)},[wi]),Eo=i.useCallback(t=>{$s.current=t,Ro(t),bi(t)},[bi]),Ni=i.useCallback(t=>{l&&mt.getState().openContextFile(l,t)},[l]),Si=Xe&&fe==="preview"&&!Ce;Xi({container:Co,filePath:c?.path??null,workspaceRoot:l||null,onOpenFile:Ni,enabled:Si}),Xi({container:ko,filePath:c?.path??null,workspaceRoot:l||null,onOpenFile:Ni,enabled:Si});const $r=bl("unified"),dt=se.length>da,_r=i.useMemo(()=>dt&&ir?vc(se):void 0,[ir,se,dt]),Ci=i.useCallback((t,o,u,h)=>{const j={name:t.name,contents:o,lang:Kr(t.path)||void 0},C=P=>r.jsx(Vl,{file:dt&&_r?{...j,cacheKey:`${t.path}:${_r}`}:j,options:{disableFileHeader:!0,overflow:Q?"wrap":"scroll",theme:oi,themeType:f.metadata.variant==="dark"?"dark":"light",onPostRender:h},className:dt?"block w-full":"block h-full w-full",style:dt?void 0:{height:"100%"}},P);return dt?r.jsx("div",{className:"h-full",children:r.jsx(Ml.Provider,{value:u.virtualizer,children:r.jsx(Dl.Provider,{value:$r,children:C(`${t.path}:${$r?"pool":"pending"}`)})})}):r.jsx("div",{className:"h-full",children:C(t.path)})},[f.metadata.variant,dt,_r,oi,$r,Q]),Fi=({exitFullscreenOnly:t=!1,layout:o="floating"}={})=>{if(!c)return null;const u=o==="docked",h=hl(pl("save_file")),j=u?"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",C=(P,O)=>r.jsxs(Mt,{children:[r.jsx(Dt,{asChild:!0,children:r.jsx("span",{className:"inline-flex",children:O})}),r.jsx(zt,{side:"bottom",sideOffset:6,children:P})]});return r.jsxs("div",{className:j,children:[Qe&&ro&&r.jsxs(r.Fragment,{children:[ls?r.jsxs("span",{className:"flex items-center gap-1 px-1 text-muted-foreground typography-meta",children:[r.jsx(E,{name:"loader-4",className:"size-3.5 animate-spin"}),s("filesView.editor.saving")]}):ke&&Ca==="saved"&&!Oe?r.jsxs("span",{className:"flex items-center gap-1 px-1 text-[color:var(--status-success)] typography-meta",children:[r.jsx(E,{name:"check",className:"size-3.5"}),s("filesView.editor.saved")]}):Oe?C(s(ke?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:h}),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{qt()},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:s(ke?"filesView.editor.saveNowTitle":"filesView.editor.saveNowManualTitle",{shortcut:h}),"aria-label":s("filesView.editor.saveAria",{shortcut:h}),children:r.jsx(E,{name:"save-3",className:"size-4"})})):null,C(s(ke?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>ka(!ke),className:W("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",ke?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:s(ke?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),"aria-label":s(ke?"filesView.editor.autoSaveOn":"filesView.editor.manualSave"),children:ke?r.jsx(E,{name:"file-check-fill",className:"size-4"}):r.jsx(E,{name:"file-check",className:"size-4"})}))]}),r.jsxs(tn,{onOpenChange:ie,children:[r.jsxs(Mt,{children:[r.jsx(Dt,{asChild:!0,children:r.jsx("span",{className:"inline-flex",children:r.jsx(sn,{asChild:!0,children:r.jsx(I,{variant:"ghost",size:"sm",className:"size-6 p-0 text-foreground opacity-100 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s("filesView.editor.openInDesktopApp"),"aria-label":s("filesView.editor.openInDesktopApp"),children:r.jsx(E,{name:"file-transfer",className:"size-4"})})})})}),r.jsx(zt,{side:"bottom",sideOffset:6,children:s("filesView.editor.openInDesktopApp")})]}),r.jsxs(rn,{align:"end",className:"w-56 max-h-[70vh] overflow-y-auto",children:[Ia.map(P=>r.jsxs(ur,{className:"flex items-center gap-2",onClick:()=>{_a(P)},children:[r.jsx($c,{label:P.label,iconDataUrl:P.iconDataUrl}),r.jsx("span",{className:"typography-ui-label text-foreground",children:P.label})]},P.id)),Oa?r.jsxs(ur,{className:"flex items-center gap-2",onClick:()=>{Ba(!0)},children:[r.jsx(E,{name:"refresh",className:"size-4"}),r.jsx("span",{className:"typography-ui-label text-foreground",children:s("filesView.editor.refreshApps")})]}):null]})]}),!ti&&r.jsxs(r.Fragment,{children:[C(s(Q?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>_e(!Q),className:W("size-6 p-0 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",Q?"text-foreground opacity-100":"text-muted-foreground opacity-65 hover:opacity-100"),title:s(Q?"filesView.editor.disableLineWrap":"filesView.editor.enableLineWrap"),children:r.jsx(E,{name:"text-wrap",className:"size-4"})})),_==="edit"&&r.jsxs(r.Fragment,{children:[C(s("filesView.editor.findInFile"),r.jsx(I,{variant:"ghost",size:"sm",onClick:P=>{ze(!De),P.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s("filesView.editor.findInFile"),children:r.jsx(E,{name:"search",className:"size-4"})})),C(s("filesView.editor.goToLine"),r.jsx(I,{variant:"ghost",size:"sm",onClick:P=>{Tr(O=>!O),P.currentTarget.blur()},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s("filesView.editor.goToLine"),children:r.jsx(E,{name:"menu-fold-2",className:"size-4"})})),r.jsx(ec,{open:Aa,onOpenChange:Tr,view:qe.current,variant:"inline"})]})]}),Ys&&Qe&&!Zt&&!Yt&&!Ge&&!Qt&&!es&&r.jsx(js,{currentMode:_==="view"?"preview":"edit",onToggle:()=>{no(_==="view"?"edit":"view")}}),Xe&&C(s($e()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>io($e()==="preview"?"edit":"preview"),className:W("size-6 p-0 transition-colors hover:bg-[var(--interactive-hover)] focus-visible:bg-[var(--interactive-hover)] active:bg-[var(--interactive-hover)]",$e()==="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:s($e()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),"aria-label":s($e()==="preview"?"filesView.editor.switchToEditMode":"filesView.editor.switchToPreviewMode"),children:r.jsx(E,{name:$e()==="preview"?"eye":"eye-off",className:"size-4"})})),cr(c?.path??"")&&r.jsx(js,{currentMode:ii(),onToggle:()=>{uo(ii()==="preview"?"edit":"preview")}}),Ge&&r.jsx(js,{currentMode:ye,onToggle:()=>ao(ye==="preview"?"edit":"preview")}),Qt&&r.jsx(js,{currentMode:We,onToggle:()=>oo(We==="preview"?"edit":"preview")}),es&&C(s(Le==="table"?"filesView.artifact.table.showSource":"filesView.artifact.table.showTable"),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>lo(Le==="table"?"text":"table"),className:"size-6 p-0 text-muted-foreground opacity-65 hover:bg-transparent hover:opacity-100 focus-visible:bg-transparent active:bg-transparent",title:s(Le==="table"?"filesView.artifact.table.showSource":"filesView.artifact.table.showTable"),"aria-label":s(Le==="table"?"filesView.artifact.table.showSource":"filesView.artifact.table.showTable"),children:Le==="table"?r.jsx(E,{name:"code-sslash",className:"size-4"}):r.jsx(E,{name:"table-2",className:"size-4"})})),Xe&&$e()==="preview"&&C(s("filesView.editor.findInFile"),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{Is(!0),Nn(P=>P+1)},className:"size-6 p-0 text-foreground opacity-100 transition-opacity hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s("filesView.editor.findInFile"),children:r.jsx(E,{name:"search",className:"size-4"})})),Xe&&$e()==="preview"&&Wa&&r.jsxs(Mt,{children:[r.jsx(Dt,{asChild:!0,children:r.jsx(I,{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":s(zs?"filesView.tts.stopSpeaking":"filesView.tts.readAloud"),onClick:()=>{zs?ba():$.trim()&&wa($)},children:zs?r.jsx(E,{name:"stop",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(E,{name:"volume-up",className:"size-4"})})}),r.jsx(zt,{sideOffset:8,children:s(zs?"filesView.tts.stopSpeaking":"filesView.tts.readAloud")})]}),vs&&r.jsxs(r.Fragment,{children:[r.jsx(js,{currentMode:ve,onToggle:()=>fo(ve==="preview"?"edit":"preview")}),ve==="preview"&&r.jsx(I,{variant:"ghost",size:"sm",onClick:async()=>{const P=gn.current?.getXml();if(Ae.current&&(clearTimeout(Ae.current),Ae.current=null),c?.path&&P){if(!await Or(c.path,P))return;Ls(!0),setTimeout(()=>Ls(!1),1500)}},className:"size-6 p-0 text-foreground hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s("filesView.diagram.saveDiagram"),children:Fa?r.jsx(E,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(E,{name:"save-3",className:"size-4"})})]}),Zt&&C(s(le==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>co(le==="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:s(le==="tree"?"filesView.editor.switchToTextView":"filesView.editor.switchToTreeView"),children:le==="tree"?r.jsx(E,{name:"code-sslash",className:"size-4"}):r.jsx(E,{name:"node-tree",className:"size-4"})})),to&&C(s("filesView.editor.copyFileContents"),r.jsx(I,{variant:"ghost",size:"sm",onClick:async()=>{(await fr($)).ok?(wn(!0),hs.current!==null&&window.clearTimeout(hs.current),hs.current=window.setTimeout(()=>{wn(!1)},1200)):re.error(s("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s("filesView.editor.copyFileContents"),"aria-label":s("filesView.editor.copyFileContents"),children:za?r.jsx(E,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(E,{name:"clipboard",className:"size-4"})})),so&&C(s("filesView.editor.copyFilePathTitle",{path:Nt}),r.jsx(I,{variant:"ghost",size:"sm",onClick:async()=>{(await fr(Nt)).ok?(bn(!0),ps.current!==null&&window.clearTimeout(ps.current),ps.current=window.setTimeout(()=>{bn(!1)},1200)):re.error(s("filesView.toast.copyFailed"))},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s("filesView.editor.copyFilePathTitle",{path:Nt}),"aria-label":s("filesView.editor.copyFilePathTitle",{path:Nt}),children:La?r.jsx(E,{name:"check",className:"size-4 text-[color:var(--status-success)]"}):r.jsx(E,{name:"file-copy-2",className:"size-4"})})),a.downloadFile&&C(s("filesView.editor.saveFile"),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{const P=a.downloadFile;P&&P(c.path).catch(O=>{console.error("Download failed:",O),re.error(s("sidebarFilesTree.toast.operationFailed"))})},className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s("filesView.editor.saveFile"),"aria-label":s("filesView.editor.saveFile"),children:r.jsx(E,{name:"download",className:"size-4"})})),t?C(s("filesView.editor.exitFullscreen"),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>Te(!1),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s("filesView.editor.exitFullscreen"),"aria-label":s("filesView.editor.exitFullscreen"),children:r.jsx(E,{name:"fullscreen-exit",className:"size-4"})})):!p&&n==="full"&&C(s(ne?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>Te(!ne),className:"size-6 p-0 hover:bg-transparent focus-visible:bg-transparent active:bg-transparent",title:s(ne?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),"aria-label":s(ne?"filesView.editor.exitFullscreen":"filesView.editor.fullscreen"),children:ne?r.jsx(E,{name:"fullscreen-exit",className:"size-4"}):r.jsx(E,{name:"fullscreen",className:"size-4"})}))]})},Wr=r.jsxs("div",{className:"relative flex h-full min-h-0 min-w-0 w-full flex-col overflow-hidden",children:[r.jsx(ra,{open:Cr,onOpenChange:t=>{t||ds(!0)},children:r.jsxs(na,{showCloseButton:!1,className:"max-w-md",children:[r.jsxs(ia,{children:[r.jsx(aa,{children:s("filesView.unsaved.title")}),r.jsx(oa,{children:s("filesView.unsaved.description")})]}),r.jsxs(la,{children:[r.jsx(I,{variant:"outline",onClick:()=>{Ja()},disabled:ls,className:"border-[var(--status-success-border)] bg-[var(--status-success-background)] text-[var(--status-success)] hover:bg-[rgb(var(--status-success)/0.2)]",children:s("filesView.unsaved.saveChanges")}),r.jsx(I,{variant:"destructive",onClick:Xa,children:s("filesView.unsaved.discard")})]})]})}),r.jsxs("div",{className:W("flex flex-col flex-shrink-0",z&&"border-b border-border/40"),children:[z?r.jsxs("div",{className:"flex min-w-0 items-center px-3 py-1.5",children:[p&&J&&r.jsx("button",{type:"button",onClick:()=>q(!1),"aria-label":s("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-ring",children:r.jsx(E,{name:"arrow-left-s",className:"size-5"})}),p?c?r.jsxs(tn,{children:[r.jsx(sn,{asChild:!0,children:r.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":s("filesView.editor.openFilesAria"),children:[r.jsx(Ns,{filePath:c.path,extension:c.extension,className:"size-3.5 flex-shrink-0"}),r.jsx(Zi,{name:c.name}),r.jsx(E,{name:"arrow-down-s",className:"size-4 flex-shrink-0 text-muted-foreground"})]})}),r.jsx(rn,{align:"start",className:"w-[min(24rem,calc(100vw-2rem))] max-w-[calc(100vw-2rem)]",children:Bt.map(t=>{const o=c?.path===t.path;return r.jsxs(ur,{onSelect:u=>{if(u.target.closest("[data-close-open-file]")){u.preventDefault();return}o||Me(t)},className:W("flex min-w-0 items-center justify-between gap-2 overflow-hidden",o&&"bg-[var(--interactive-selection)] text-[var(--interactive-selection-foreground)]"),children:[r.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-2 overflow-hidden",children:[r.jsx(Ns,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),r.jsx(Zi,{name:t.name})]}),r.jsx("button",{type:"button","data-close-open-file":!0,onPointerDown:u=>{u.preventDefault(),u.stopPropagation()},onClick:u=>{u.preventDefault(),u.stopPropagation(),Jn(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":s("filesView.editor.closeFileAria",{name:t.name}),children:r.jsx(E,{name:"close",className:"size-3.5"})})]},t.path)})})]}):r.jsx("div",{className:"typography-ui-label font-medium truncate",children:s("filesView.editor.selectFile")}):Bt.length>0?r.jsxs("div",{className:"relative min-w-0 flex-1",children:[un.left&&r.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"}),un.right&&r.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"}),r.jsx("div",{ref:br,className:"flex min-w-0 items-center gap-1 overflow-x-auto scrollbar-none",style:{scrollbarWidth:"none",msOverflowStyle:"none"},children:Bt.map(t=>{const o=c?.path===t.path;return r.jsxs("div",{title:dr(l,t.path),className:W("group inline-flex items-center gap-1 rounded-md border px-2 py-1 typography-ui-label transition-colors whitespace-nowrap",o?"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:[r.jsx(Ns,{filePath:t.path,extension:t.extension,className:"size-3.5 flex-shrink-0"}),r.jsx("button",{type:"button",onClick:()=>{o||Me(t)},className:"max-w-[12rem] truncate text-left",children:t.name}),r.jsx("button",{type:"button",onClick:u=>{u.stopPropagation(),Jn(t.path)},className:W("rounded-sm p-0.5 text-[var(--surface-muted-foreground)] hover:text-[var(--surface-foreground)]",!o&&!F&&"opacity-0 group-hover:opacity-100"),"aria-label":s("filesView.editor.closeFileAria",{name:t.name}),children:r.jsx(E,{name:"close",className:"size-3.5"})})]},t.path)})})]}):r.jsx("div",{className:"typography-ui-label font-medium truncate",children:s("filesView.editor.selectFile")})]}):null,c?r.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:[Nt&&!p?r.jsx("span",{className:"min-w-0 flex-1 truncate typography-meta text-muted-foreground",title:Nt,children:Nt}):null,r.jsx("div",{className:"ml-auto min-w-0 shrink-0 overflow-x-auto",children:Fi({layout:"docked"})})]}):null]}),r.jsx("div",{className:"flex-1 min-h-0 min-w-0 relative",children:r.jsx(Gr,{ref:No,outerClassName:"h-full min-w-0",className:W("h-full min-w-0",dt&&"[overflow-anchor:none]"),children:c?Ce||Br?B?r.jsx("div",{className:"p-3"}):r.jsxs("div",{className:"p-3 flex items-center gap-2 typography-ui text-muted-foreground",children:[r.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}),s("filesView.state.loading")]}):Je?r.jsx("div",{className:"p-3 typography-ui text-[color:var(--status-error)]",children:Je}):nr||(c&&vs&&ve==="preview"?r.jsx("div",{className:"h-full overflow-hidden",style:{minHeight:"400px"},children:r.jsx(bc,{ref:gn,xml:ho,onChange:mo},`${c.path}:${ce}`)}):c&&Zt&&le==="tree"?r.jsx(ar,{fallback:r.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[r.jsx("div",{className:"mb-1 font-medium text-destructive",children:s("filesView.error.jsonViewerUnavailable")}),r.jsx("div",{className:"text-sm text-muted-foreground",children:s("filesView.error.switchToTextMode")})]}),children:r.jsx("div",{className:"h-full overflow-auto",children:r.jsx(El,{jsonString:$,maxHeight:"100%",initiallyExpandedDepth:2})})}):c&&Xe&&$e()==="preview"?r.jsxs("div",{className:"relative h-full min-h-0",children:[r.jsxs("div",{className:"oc-file-preview h-full overflow-auto p-3 outline-none",tabIndex:-1,onMouseDown:Bs,ref:To,children:[r.jsx(_i,{containerRef:Pn,filePath:c.path,fileContent:$}),$.length>500*1024&&r.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:s("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round($.length/1024)})}),r.jsx(ar,{fallback:r.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[r.jsx("div",{className:"mb-1 font-medium text-destructive",children:s("filesView.error.previewUnavailable")}),r.jsx("div",{className:"text-sm text-muted-foreground",children:s("filesView.error.switchToEditMode")})]}),children:r.jsx(Xr,{content:$,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}),!ne&&r.jsx(Ki,{containerRef:Os,open:yn,onOpenChange:Is,focusNonce:jn})]}):c&&Yt&&xe==="preview"?go?r.jsx("div",{className:"flex h-full items-center justify-center text-muted-foreground typography-ui-label",children:s("common.loading")}):r.jsx("div",{className:"h-full overflow-hidden",children:r.jsx("iframe",{src:!w.isVSCode&&ui===tr?(()=>{const t=c.path.split("/").map(o=>encodeURIComponent(o)).join("/");return Pi().authenticatedAsset(`/api/fs/serve${t.startsWith("/")?t:`/${t}`}`)})():void 0,srcDoc:w.isVSCode?(()=>{const t=c.path.substring(0,c.path.lastIndexOf("/")+1);return t?$.replace(/<head([^>]*)>/i,`<head$1><base href="${t}">`):$})():void 0,className:"w-full h-full border-none",sandbox:"allow-scripts allow-same-origin allow-forms",title:s("filesView.editor.htmlPreviewTitle")},po)}):c&&Ys&&_==="view"?Ci(c,se,mi,yo):r.jsxs("div",{className:W("relative h-full",Jt&&"overflow-hidden"),ref:As,children:[r.jsx("div",{className:W("h-full",Jt&&"invisible"),children:r.jsx(ea,{positionKey:vt,value:se,onChange:Fe,readOnly:!Qe,vimMode:Vn==="vim",extensions:ai,className:"h-full",blockWidgets:bo,onViewReady:t=>{qe.current=t,Fr(o=>o+1),window.requestAnimationFrame(()=>{ts(t)})},onViewDestroy:()=>{qe.current&&(qe.current=null),Fr(t=>t+1)},enableSearch:!0,searchOpen:De,onSearchOpenChange:ze,highlightLines:H?{start:Math.min(H.start,H.end),end:Math.max(H.start,H.end)}:void 0,lineNumbersConfig:{domEventHandlers:{mousedown:(t,o,u)=>{if(!(u instanceof MouseEvent)||u.button!==0)return!1;u.preventDefault();const h=t.state.doc.lineAt(o.from).number;if(H&&!u.shiftKey&&Math.min(H.start,H.end)===h&&Math.max(H.start,H.end)===h)return Ye(null),xs(),Kt.current=!1,yt.current=null,Ht(!1),!0;if(p&&H&&!u.shiftKey){const j=Math.min(H.start,H.end,h),C=Math.max(H.start,H.end,h);return Ye({start:j,end:C}),Kt.current=!1,yt.current=null,Ht(!1),!0}if(Kt.current=!0,yt.current=h,Ht(!0),H&&u.shiftKey){const j=Math.min(H.start,h),C=Math.max(H.end,h);Ye({start:j,end:C})}else Ye({start:h,end:h});return!0},mouseover:(t,o,u)=>{if(!(u instanceof MouseEvent)||u.buttons!==1||!Kt.current||yt.current===null)return!1;const h=t.state.doc.lineAt(o.from).number,j=Math.min(yt.current,h),C=Math.max(yt.current,h);return Ye({start:j,end:C}),Ht(!0),!1},mouseup:()=>(Kt.current=!1,yt.current=null,Ht(!1),!1)}}},vt)}),Jt&&r.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:r.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[r.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}),s("filesView.state.openingFileAtChange")]})})]})):r.jsx("div",{className:"p-3 typography-ui text-muted-foreground",children:s("filesView.editor.pickFileFromTree")})})})]}),Vo=!!(l&&mn[l]),ki=l?Ps[l]:null,Ri=T?r.jsxs("section",{className:W("flex min-h-0 flex-col overflow-hidden",p?"h-full w-full bg-background":"h-full rounded-xl border border-border/60 bg-background/70"),children:[r.jsx("div",{className:W("flex flex-col gap-2 py-2",p?"px-3":"px-2"),children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("div",{className:"relative flex-1 min-w-0",children:[r.jsx(E,{name:"search",className:"pointer-events-none absolute left-2 top-2 size-4 text-muted-foreground"}),r.jsx(Cs,{ref:X,value:te,onChange:t=>ee(t.target.value),placeholder:s("filesView.tree.search.placeholder"),className:"h-8 pl-8 pr-8 typography-meta"}),te.trim().length>0&&r.jsx("button",{type:"button","aria-label":s("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:()=>{ee(""),X.current?.focus()},children:r.jsx(E,{name:"close",className:"size-4"})})]}),r.jsxs(Mt,{children:[r.jsx(Dt,{asChild:!0,children:r.jsx("span",{className:"inline-flex flex-shrink-0",children:r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>Er("createFile",{path:g,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:s("filesView.tree.actions.newFileTitle"),"aria-label":s("filesView.tree.actions.newFileTitle"),children:r.jsx(E,{name:"file-add",className:"size-4"})})})}),r.jsx(zt,{side:"bottom",sideOffset:6,children:s("filesView.tree.actions.newFileTitle")})]}),r.jsxs(Mt,{children:[r.jsx(Dt,{asChild:!0,children:r.jsx("span",{className:"inline-flex flex-shrink-0",children:r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>Er("createFolder",{path:g,type:"directory"}),className:"size-8 p-0 flex-shrink-0",title:s("filesView.tree.actions.newFolderTitle"),"aria-label":s("filesView.tree.actions.newFolderTitle"),children:r.jsx(E,{name:"folder-add",className:"size-4"})})})}),r.jsx(zt,{side:"bottom",sideOffset:6,children:s("filesView.tree.actions.newFolderTitle")})]}),_n&&r.jsxs(Mt,{children:[r.jsx(Dt,{asChild:!0,children:r.jsx("span",{className:"inline-flex flex-shrink-0",children:r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>Wn(l),disabled:!l||Hs,className:"size-8 p-0 flex-shrink-0",title:s("sidebarFilesTree.actions.uploadFilesTitle"),"aria-label":s("sidebarFilesTree.actions.uploadFilesTitle"),children:r.jsx(E,{name:Hs?"loader-4":"upload-2",className:W("size-4",Hs&&"animate-spin")})})})}),r.jsx(zt,{side:"bottom",sideOffset:6,children:s("sidebarFilesTree.actions.uploadFilesTitle")})]}),r.jsxs(Mt,{children:[r.jsx(Dt,{asChild:!0,children:r.jsx("span",{className:"inline-flex flex-shrink-0",children:r.jsx(I,{variant:"ghost",size:"sm",onClick:()=>{Ks()},className:"size-8 p-0 flex-shrink-0",title:s("filesView.tree.actions.refreshTitle"),"aria-label":s("filesView.tree.actions.refreshTitle"),children:r.jsx(E,{name:"refresh",className:"size-4"})})})}),r.jsx(zt,{side:"bottom",sideOffset:6,children:s("filesView.tree.actions.refreshTitle")})]})]})}),r.jsx(Gr,{outerClassName:"flex-1 min-h-0",className:W("py-2",p?"px-3":"px-2"),children:r.jsx("ul",{className:"flex flex-col",children:va?r.jsxs("li",{className:"flex items-center gap-1.5 px-2 py-1 typography-meta text-muted-foreground",children:[r.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}),s("filesView.tree.search.searching")]}):hn.length>0?hn.map(t=>{const o=c?.path===t.path;return r.jsx("li",{children:r.jsxs("button",{type:"button",onClick:()=>{Me(t)},className:W("flex w-full items-center gap-1.5 rounded-md px-2 py-1 text-left text-foreground transition-colors",o?"bg-interactive-selection/70":"hover:bg-interactive-hover/40"),children:[pa(t.path,t.extension),r.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)}):ki?r.jsxs("li",{className:"flex flex-col gap-2 px-2 py-1 typography-meta text-muted-foreground",children:[r.jsx("span",{className:"text-[var(--status-error)]",children:ki}),r.jsxs(I,{variant:"outline",size:"xs",className:"w-fit gap-1.5",onClick:()=>{Ks()},children:[r.jsx(E,{name:"refresh",className:"size-3.5"}),s("filesView.tree.actions.refreshTitle")]})]}):Vo?Yn(l,0):r.jsx("li",{className:"px-2 py-1 typography-meta text-muted-foreground",children:s("filesView.state.loading")})})})]}):null,Po=n==="full"&&ne&&c&&r.jsx("div",{className:"absolute inset-0 z-50 flex flex-col bg-background",children:r.jsxs("div",{className:"flex-1 min-h-0 min-w-0 relative",children:[r.jsx("div",{className:"absolute right-4 top-4 z-30",children:Fi({exitFullscreenOnly:!0})}),r.jsx(Gr,{ref:So,outerClassName:"h-full min-w-0",className:W("h-full min-w-0",dt&&"[overflow-anchor:none]"),children:Ce||Br?B?r.jsx("div",{className:"p-4"}):r.jsxs("div",{className:"p-4 flex items-center gap-2 typography-ui text-muted-foreground",children:[r.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}),"Loading…"]}):Je?r.jsx("div",{className:"p-4 typography-ui text-[color:var(--status-error)]",children:Je}):nr||(Xe&&$e()==="preview"?r.jsxs("div",{className:"relative h-full min-h-0",children:[r.jsxs("div",{className:"oc-file-preview h-full overflow-auto p-4 outline-none",tabIndex:-1,onMouseDown:Bs,ref:Eo,children:[c?r.jsx(_i,{containerRef:$s,filePath:c.path,fileContent:$}):null,$.length>500*1024&&r.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:s("filesView.warning.largeFilePreviewLimited",{sizeKb:Math.round($.length/1024)})}),r.jsx(ar,{fallback:r.jsxs("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 px-3 py-2",children:[r.jsx("div",{className:"mb-1 font-medium text-destructive",children:s("filesView.error.previewUnavailable")}),r.jsx("div",{className:"text-sm text-muted-foreground",children:s("filesView.error.switchToEditMode")})]}),children:r.jsx(Xr,{content:$,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})]}),r.jsx(Ki,{containerRef:$s,open:yn,onOpenChange:Is,focusNonce:jn,className:"right-4 top-16"})]}):Ys&&_==="view"?Ci(c,se,hi,jo):r.jsxs("div",{className:W("relative h-full",Jt&&"overflow-hidden"),children:[r.jsx("div",{className:W("h-full",Jt&&"invisible"),children:r.jsx(ea,{positionKey:`${vt}:fullscreen`,value:se,onChange:Fe,readOnly:!Qe,vimMode:Vn==="vim",extensions:ai,className:"h-full",onViewReady:t=>{qe.current=t,window.requestAnimationFrame(()=>{ts(t)})},onViewDestroy:()=>{qe.current&&(qe.current=null)}},`${vt}:fullscreen`)}),Jt&&r.jsx("div",{className:"pointer-events-none absolute inset-0 flex items-center justify-center bg-background",children:r.jsxs("div",{className:"flex items-center gap-2 typography-ui text-muted-foreground",children:[r.jsx(E,{name:"loader-4",className:"size-4 animate-spin"}),s("filesView.state.openingFileAtChange")]})})]}))})]})});return r.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden bg-background relative",children:[r.jsx(Zc,{activeDialog:Tt,dialogData:Et,dialogInputValue:bt,onDialogInputChange:vn,isDialogSubmitting:Ea,onDialogSubmit:Ga,onClose:wo,inputRef:Na}),qa,Po,p?J?Wr:Ri:n==="editor-only"?r.jsx("div",{className:"flex flex-1 min-h-0 min-w-0 overflow-hidden",children:r.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden bg-background",children:Wr})}):r.jsxs("div",{className:"flex flex-1 min-h-0 min-w-0 gap-3 px-3 pb-3 pt-2",children:[b>=700&&r.jsx("div",{className:"w-72 flex-shrink-0 min-h-0 overflow-hidden",children:Ri}),r.jsx("div",{className:"flex-1 min-h-0 min-w-0 overflow-hidden rounded-xl border border-border/60 bg-background",children:Wr})]})]})};function Qc(n){return n+1}export{jf as FilesView};