@jxsuite/studio 4.1.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (607) hide show
  1. package/README.md +1 -1
  2. package/data/elements-meta.json +5 -15
  3. package/data/html-meta.json +51 -6
  4. package/dist/chunks/{2020-n6tfwnda.js → 2020-g79n01v9.js} +14 -14
  5. package/dist/chunks/action-group-sp6tna8v.js +118 -0
  6. package/dist/chunks/adapter-nj7tnjfn.js +13 -0
  7. package/dist/chunks/cf-account-picker-fyf63pmy.js +495 -0
  8. package/dist/chunks/cf-settings-71bv5zn9.js +20 -0
  9. package/dist/chunks/color-area-v17df7b8.js +154 -0
  10. package/dist/chunks/color-field-anwybnkn.js +208 -0
  11. package/dist/chunks/color-slider-44ez96fc.js +79 -0
  12. package/dist/chunks/color-xgg3kfw7.js +35 -0
  13. package/dist/chunks/combobox-5e7jev23.js +236 -0
  14. package/dist/chunks/components-2w1f35qs.js +18 -0
  15. package/dist/chunks/content-source-3wqeas45.js +46 -0
  16. package/dist/chunks/convert-to-repeater-d0cgnb6d.js +639 -0
  17. package/dist/chunks/dialog-s890b918.js +85 -0
  18. package/dist/chunks/editor-3qhbg51x.js +35 -0
  19. package/dist/chunks/entry-commands-d6g50j7s.js +42 -0
  20. package/dist/chunks/extension-sections-fy7q4fe9.js +651 -0
  21. package/dist/chunks/file-ops-3btj6st0.js +47 -0
  22. package/dist/chunks/files-ef8fgs3w.js +72 -0
  23. package/dist/chunks/format-host-3c33nwr8.js +40 -0
  24. package/dist/chunks/fs-events-13tj6sex.js +18 -0
  25. package/dist/chunks/git-panel-4wp2rn9b.js +49 -0
  26. package/dist/chunks/icons-yy10wk9r.js +402 -0
  27. package/dist/chunks/iframe-entry-15g3n6xv.js +114 -0
  28. package/dist/chunks/iframe-entry-b27vq81n.js +203 -0
  29. package/dist/chunks/iframe-entry-nbyxee1y.js +154 -0
  30. package/dist/chunks/iframe-host-jgesd924.js +115 -0
  31. package/dist/chunks/{index-wcnt3r9g.js → index-mdmyx6s2.js} +11 -11
  32. package/dist/chunks/index-n4j7qxyr.js +109 -0
  33. package/dist/chunks/{javascript-q8kpmfah.js → javascript-xvrfrpkb.js} +8 -9
  34. package/dist/chunks/{jsonMode-dkr040ga.js → jsonMode-tyx2kj6p.js} +526 -527
  35. package/dist/chunks/jx-validate-j0wxk72w.js +15 -0
  36. package/dist/chunks/layers-1nq5evsh.js +29 -0
  37. package/dist/chunks/layers-panel-ar2gh90g.js +40 -0
  38. package/dist/chunks/listbox-6v2ac08j.js +44 -0
  39. package/dist/chunks/lit-html-m244w9nh.js +17 -0
  40. package/dist/chunks/media-picker-2qbetq73.js +33 -0
  41. package/dist/chunks/menu-q99sy9rf.js +285 -0
  42. package/dist/chunks/menu-rf7n72mf.js +14 -0
  43. package/dist/chunks/{monaco-binding-rj6xpx9y.js → monaco-binding-sw6en4dw.js} +12 -15
  44. package/dist/chunks/monaco-buffer-bhy3hb6m.js +24 -0
  45. package/dist/chunks/{monaco-setup-vx9bhp1d.js → monaco-setup-8r62fj6y.js} +27 -37
  46. package/dist/chunks/notify-628t0anh.js +21 -0
  47. package/dist/chunks/number-field-5cndyft8.js +72 -0
  48. package/dist/chunks/parse-0zx14y15.js +10 -0
  49. package/dist/chunks/platform-ts9cg1a4.js +15 -0
  50. package/dist/chunks/popover-47z3ytva.js +25 -0
  51. package/dist/chunks/publish-panel-98f7sr3g.js +27 -0
  52. package/dist/chunks/quick-search-srzz83k2.js +45 -0
  53. package/dist/chunks/references-n553f0e1.js +26 -0
  54. package/dist/chunks/right-panel-rrgx2dn3.js +45 -0
  55. package/dist/chunks/section-registry-5pq32t0q.js +25 -0
  56. package/dist/chunks/select-2r16ez41.js +49 -0
  57. package/dist/chunks/split-g7nm1rgb.js +191 -0
  58. package/dist/chunks/studio-0hqbpbd0.js +62 -0
  59. package/dist/chunks/studio-18avnhjp.js +2430 -0
  60. package/dist/chunks/{studio-kryvsw6j.js → studio-1k325pwf.js} +48 -48
  61. package/dist/chunks/{studio-msd847zn.js → studio-25hkdrkw.js} +357 -86
  62. package/dist/chunks/studio-26d7myd1.js +258 -0
  63. package/dist/chunks/{studio-4r1pv6zf.js → studio-38emantv.js} +22 -5
  64. package/dist/chunks/studio-3gxv60tn.js +422 -0
  65. package/dist/chunks/{studio-fbf92ckf.js → studio-3hxkd92t.js} +275 -163
  66. package/dist/chunks/studio-4m0haseg.js +185 -0
  67. package/dist/chunks/{studio-ynxwkrzd.js → studio-4wbb9ct0.js} +1953 -1785
  68. package/dist/chunks/{studio-1wagb550.js → studio-5523bpzt.js} +11 -11
  69. package/dist/chunks/{studio-x4qkdat5.js → studio-57mf66w2.js} +1749 -2481
  70. package/dist/chunks/studio-5jy81t3s.js +17463 -0
  71. package/dist/chunks/studio-5rt7sqa0.js +1168 -0
  72. package/dist/chunks/studio-5te5tqng.js +81 -0
  73. package/dist/chunks/{studio-p4ngc046.js → studio-6ewqv390.js} +9 -9
  74. package/dist/chunks/{studio-9ab8gqsm.js → studio-6nzaktvy.js} +7 -7
  75. package/dist/chunks/studio-6xa21ej9.js +28 -0
  76. package/dist/chunks/{studio-5ehhackm.js → studio-727xh0e3.js} +19 -19
  77. package/dist/chunks/{studio-ahn3pdgx.js → studio-79y5sz51.js} +52 -38
  78. package/dist/chunks/{studio-gcye7qka.js → studio-7e11jpa9.js} +21 -21
  79. package/dist/chunks/{studio-q7v10cg2.js → studio-7r42c6ca.js} +17 -7
  80. package/dist/chunks/studio-7xptrg0j.js +954 -0
  81. package/dist/chunks/{studio-cft9r4r7.js → studio-81390n6f.js} +22 -22
  82. package/dist/chunks/{studio-q43a5y9h.js → studio-8jn5yhyn.js} +16 -16
  83. package/dist/chunks/studio-8qtrpzr3.js +839 -0
  84. package/dist/chunks/{studio-dg7zyt5x.js → studio-98b3z07n.js} +1 -1
  85. package/dist/chunks/studio-9xxz1q69.js +1356 -0
  86. package/dist/chunks/studio-akbww0j5.js +13615 -0
  87. package/dist/chunks/{studio-x813zp48.js → studio-arfpe389.js} +30 -30
  88. package/dist/chunks/{studio-trxrabqf.js → studio-az3zd49t.js} +475 -283
  89. package/dist/chunks/studio-cpvb2ed1.js +1171 -0
  90. package/dist/chunks/{studio-f3wqjtk5.js → studio-d0300636.js} +5076 -18
  91. package/dist/chunks/{studio-bgxt93ga.js → studio-d055c37e.js} +13 -13
  92. package/dist/chunks/studio-d1ja2x9r.js +362 -0
  93. package/dist/chunks/{studio-b9b6t1dg.js → studio-e1f24eff.js} +5664 -5666
  94. package/dist/chunks/{studio-3bqpr0zh.js → studio-em9nw8eh.js} +299 -110
  95. package/dist/chunks/studio-erdatzvp.js +1190 -0
  96. package/dist/chunks/{studio-g1wdche0.js → studio-esrxgwh6.js} +80 -80
  97. package/dist/chunks/studio-fabxk6r9.js +2811 -0
  98. package/dist/chunks/{studio-3n4ndrzh.js → studio-h4nvnjvz.js} +303 -303
  99. package/dist/chunks/{studio-dm19q43r.js → studio-hhvs4sdg.js} +10 -10
  100. package/dist/chunks/{studio-q9jd1a60.js → studio-kcgff4r0.js} +15 -18
  101. package/dist/chunks/{studio-685s0ytq.js → studio-nqgawfks.js} +572 -572
  102. package/dist/chunks/{studio-xrapxwwc.js → studio-p1dw8wfw.js} +55 -29
  103. package/dist/chunks/studio-pm6hgy7r.js +4763 -0
  104. package/dist/chunks/studio-q0a3yk4n.js +33 -0
  105. package/dist/chunks/{studio-wcy8trfx.js → studio-q3x06vmj.js} +23 -22
  106. package/dist/chunks/studio-qahxvnan.js +111 -0
  107. package/dist/chunks/{studio-53n8bp04.js → studio-r6xmmtfh.js} +1 -1
  108. package/dist/chunks/{studio-2b946z26.js → studio-rkstz940.js} +3658 -6134
  109. package/dist/chunks/{studio-tvgyw9xw.js → studio-rnyf3f8e.js} +83 -250
  110. package/dist/chunks/studio-rpyah2ew.js +2805 -0
  111. package/dist/chunks/studio-rs76k67r.js +12 -0
  112. package/dist/chunks/{studio-jkftxyvz.js → studio-s6z853aq.js} +5858 -2152
  113. package/dist/chunks/{studio-6yw4y3my.js → studio-sgdc5pfc.js} +8 -8
  114. package/dist/chunks/studio-tb3ev01j.js +763 -0
  115. package/dist/chunks/{studio-t5wqwzdh.js → studio-tjjk7jvk.js} +1 -1
  116. package/dist/chunks/studio-vhv5tgxm.js +51 -0
  117. package/dist/chunks/{studio-qjy2z9bv.js → studio-vz68yn9e.js} +32 -137
  118. package/dist/chunks/studio-wqpngpsk.js +174 -0
  119. package/dist/chunks/{studio-b55y6ewx.js → studio-x3rty6tr.js} +58 -58
  120. package/dist/chunks/studio-xsykpvsh.js +8448 -0
  121. package/dist/chunks/{studio-92ab2jqe.js → studio-y9zedyjn.js} +14 -14
  122. package/dist/chunks/studio-yxa81f45.js +12 -0
  123. package/dist/chunks/swatch-group-t0n6h2rn.js +139 -0
  124. package/dist/chunks/tabs-wbp1cdws.js +156 -0
  125. package/dist/chunks/textfield-abk6qyee.js +73 -0
  126. package/dist/chunks/toast-780pvfbv.js +27 -0
  127. package/dist/chunks/toast-host-3sqv46sn.js +116 -0
  128. package/dist/chunks/toolbar-xbh5bhtr.js +194 -0
  129. package/dist/chunks/tooltip-eptb614w.js +369 -0
  130. package/dist/chunks/tree-a73p0pqm.js +367 -0
  131. package/dist/chunks/{tsMode-76kr53q0.js → tsMode-jy4m86rv.js} +83 -85
  132. package/dist/chunks/workspace-wrew8zk4.js +69 -0
  133. package/dist/chunks/{ws-client-6shc5rze.js → ws-client-ny4zc51r.js} +20 -22
  134. package/dist/iframe-entry.js +1780 -667
  135. package/dist/studio.js +52819 -36480
  136. package/dist/workers/editor.worker.js +1040 -1085
  137. package/dist/workers/json.worker.js +1946 -1991
  138. package/dist/workers/ts.worker.js +4960 -5005
  139. package/index.html +1 -0
  140. package/package.json +18 -52
  141. package/src/about/about-modal.ts +72 -123
  142. package/src/browse/library-commands.ts +20 -49
  143. package/src/browse/library-layouts.ts +87 -218
  144. package/src/browse/library-pane.ts +406 -438
  145. package/src/canvas/canvas-helpers.ts +0 -49
  146. package/src/canvas/canvas-live-render.ts +25 -2
  147. package/src/canvas/canvas-render.ts +666 -231
  148. package/src/canvas/canvas-surface.ts +0 -1
  149. package/src/canvas/canvas-utils.ts +310 -117
  150. package/src/canvas/dialog-path.ts +76 -0
  151. package/src/canvas/dialog-state.ts +67 -0
  152. package/src/canvas/diff-marks.ts +252 -0
  153. package/src/canvas/diff-toolbar.ts +349 -0
  154. package/src/canvas/diff-view.ts +123 -0
  155. package/src/canvas/edit-width-drag.ts +187 -0
  156. package/src/canvas/edit-width.ts +150 -0
  157. package/src/canvas/iframe-entry.ts +125 -8
  158. package/src/canvas/iframe-host.ts +271 -15
  159. package/src/canvas/iframe-interaction.ts +133 -13
  160. package/src/canvas/iframe-patch.ts +7 -1
  161. package/src/canvas/iframe-position.ts +5 -6
  162. package/src/canvas/iframe-protocol.ts +106 -5
  163. package/src/canvas/iframe-render.ts +373 -5
  164. package/src/canvas/iframe-slash.ts +2 -2
  165. package/src/canvas/iframe-subtree.ts +5 -8
  166. package/src/canvas/path-mapping.ts +25 -3
  167. package/src/canvas/popover-path.ts +106 -0
  168. package/src/canvas/popover-state.ts +155 -0
  169. package/src/canvas/surface-registry.ts +21 -10
  170. package/src/collab/presence-chips.ts +51 -73
  171. package/src/commands/app-commands.ts +10 -0
  172. package/src/commands/budget.ts +12 -0
  173. package/src/commands/command-args.ts +369 -6
  174. package/src/commands/defaults.ts +44 -14
  175. package/src/commands/live-context.ts +11 -5
  176. package/src/commands/reference.ts +12 -2
  177. package/src/commands/registry.ts +165 -8
  178. package/src/content/entry-commands.ts +16 -23
  179. package/src/content/entry-editor.ts +144 -101
  180. package/src/editor/canvas-slash-bridge.ts +2 -2
  181. package/src/editor/context-menu.ts +49 -200
  182. package/src/editor/convert-to-component.ts +42 -82
  183. package/src/editor/convert-to-repeater.ts +132 -173
  184. package/src/editor/inline-edit.ts +11 -0
  185. package/src/editor/shortcuts.ts +65 -26
  186. package/src/editor/slash-menu.ts +150 -157
  187. package/src/files/file-ops.ts +117 -11
  188. package/src/files/files.ts +943 -660
  189. package/src/files/json-layout.ts +474 -0
  190. package/src/files/serialize-document.ts +8 -1
  191. package/src/format/convert-file.ts +16 -10
  192. package/src/format/format-host.ts +50 -1
  193. package/src/github/github-auth.ts +71 -29
  194. package/src/github/github-publish.ts +57 -65
  195. package/src/grid/cell-editors.ts +46 -4
  196. package/src/grid/cell-popovers.ts +65 -62
  197. package/src/grid/grid-open.ts +86 -64
  198. package/src/grid/grid-panel.ts +390 -469
  199. package/src/grid/redirects-grid.ts +40 -44
  200. package/src/hosting/layout.ts +2 -0
  201. package/src/i18n/i18n-commands.ts +127 -62
  202. package/src/media/media-pane.ts +83 -133
  203. package/src/new-project/add-repo-modal.ts +125 -176
  204. package/src/new-project/import-tab.ts +181 -252
  205. package/src/new-project/location-fields.ts +93 -160
  206. package/src/new-project/new-project-modal.ts +376 -367
  207. package/src/packages/jxsuite-update.ts +76 -18
  208. package/src/panels/activity-panel.ts +137 -104
  209. package/src/panels/ai-chat/chat-markdown.ts +15 -13
  210. package/src/panels/ai-chat/chat-view.ts +307 -472
  211. package/src/panels/ai-chat/composer.ts +175 -163
  212. package/src/panels/ai-chat/sessions-view.ts +31 -62
  213. package/src/panels/ai-panel.ts +210 -185
  214. package/src/panels/block-action-bar.ts +437 -643
  215. package/src/panels/bottom-dock.ts +112 -47
  216. package/src/panels/chat-panel.ts +19 -14
  217. package/src/panels/data-explorer.ts +141 -102
  218. package/src/panels/data-grid.ts +183 -150
  219. package/src/panels/dnd.ts +75 -20
  220. package/src/panels/editors.ts +26 -19
  221. package/src/panels/elements-panel.ts +243 -186
  222. package/src/panels/empty-state.ts +26 -42
  223. package/src/panels/events-panel.ts +950 -729
  224. package/src/panels/formula-workspace.ts +434 -207
  225. package/src/panels/frontmatter-fields.ts +185 -153
  226. package/src/panels/frontmatter-panel.ts +411 -187
  227. package/src/panels/git-diff-open.ts +148 -0
  228. package/src/panels/git-panel.ts +679 -605
  229. package/src/panels/head-panel.ts +617 -435
  230. package/src/panels/i18n-panel.ts +153 -133
  231. package/src/panels/imports-panel.ts +388 -414
  232. package/src/panels/jump-bar.ts +174 -147
  233. package/src/panels/layers-panel.ts +785 -671
  234. package/src/panels/left-panel.ts +166 -94
  235. package/src/panels/navigator-panels.ts +1 -1
  236. package/src/panels/pane-context.ts +529 -677
  237. package/src/panels/pane-grid.ts +265 -241
  238. package/src/panels/panel-registry.ts +15 -4
  239. package/src/panels/problems-panel.ts +177 -99
  240. package/src/panels/properties-panel.ts +1525 -966
  241. package/src/panels/provenance.ts +31 -113
  242. package/src/panels/quick-search.ts +217 -172
  243. package/src/panels/right-panel.ts +135 -169
  244. package/src/panels/seo-modal.ts +346 -167
  245. package/src/panels/settings-menu.ts +109 -646
  246. package/src/panels/settings-pane.ts +102 -86
  247. package/src/panels/signals-panel.ts +1318 -1172
  248. package/src/panels/statement-editor.ts +556 -428
  249. package/src/panels/style-panel.ts +1367 -630
  250. package/src/panels/style-utils.ts +36 -32
  251. package/src/panels/stylebook-doc.ts +30 -73
  252. package/src/panels/stylebook-layers-panel.ts +202 -109
  253. package/src/panels/stylebook-panel.ts +124 -88
  254. package/src/panels/tab-strip.ts +385 -287
  255. package/src/platforms/cloud.ts +106 -16
  256. package/src/platforms/devserver.ts +13 -0
  257. package/src/publish/deploy-checklist.ts +124 -78
  258. package/src/publish/publish-commands.ts +4 -12
  259. package/src/publish/publish-panel.ts +134 -328
  260. package/src/services/a11y-report.ts +100 -43
  261. package/src/services/ai-command-tools.ts +468 -0
  262. package/src/services/ai-session-store.ts +6 -0
  263. package/src/services/ai-system-prompt.ts +110 -18
  264. package/src/services/ai-tools.ts +28 -143
  265. package/src/services/ai-write-report.ts +174 -0
  266. package/src/services/document-assistant.ts +50 -2
  267. package/src/services/idle.ts +16 -14
  268. package/src/services/live-surfaces.ts +237 -0
  269. package/src/services/model-uri.ts +75 -0
  270. package/src/services/notify.ts +63 -6
  271. package/src/services/popover-report.ts +325 -0
  272. package/src/services/surface-registry.ts +56 -0
  273. package/src/services/tool-executor.ts +6 -0
  274. package/src/settings/contexts-section.ts +301 -299
  275. package/src/settings/contributed-section.ts +361 -222
  276. package/src/settings/css-vars-editor.ts +320 -325
  277. package/src/settings/defs-editor.ts +572 -535
  278. package/src/settings/dependencies-editor.ts +79 -107
  279. package/src/settings/extension-commands.ts +379 -0
  280. package/src/settings/extension-rows.ts +113 -0
  281. package/src/settings/extensions-section.ts +287 -0
  282. package/src/settings/general-settings.ts +130 -181
  283. package/src/settings/head-editor.ts +10 -305
  284. package/src/settings/locales-section.ts +146 -196
  285. package/src/settings/preferences-accounts.ts +1 -1
  286. package/src/settings/preferences-dialog.ts +350 -330
  287. package/src/settings/project-sections.ts +108 -181
  288. package/src/settings/schema-field-ui.ts +11 -399
  289. package/src/settings/section-registry.ts +8 -1
  290. package/src/settings/settings-document.ts +31 -29
  291. package/src/shell/tree.ts +42 -87
  292. package/src/shell.ts +48 -36
  293. package/src/studio.ts +90 -67
  294. package/src/style/token-ref.ts +0 -39
  295. package/src/surfaces/about.json +263 -0
  296. package/src/surfaces/about.ts +163 -0
  297. package/src/surfaces/add-repo.json +486 -0
  298. package/src/surfaces/add-repo.ts +236 -0
  299. package/src/surfaces/ai-chat.json +2185 -0
  300. package/src/surfaces/ai-chat.ts +549 -0
  301. package/src/surfaces/ai-credentials-form.json +332 -0
  302. package/src/surfaces/ai-credentials-form.ts +151 -0
  303. package/src/surfaces/ai-managed-connect.json +108 -0
  304. package/src/surfaces/ai-managed-connect.ts +123 -0
  305. package/src/surfaces/ai-model-picker.json +114 -0
  306. package/src/surfaces/ai-model-picker.ts +139 -0
  307. package/src/surfaces/block-action-bar.json +640 -0
  308. package/src/surfaces/block-action-bar.ts +368 -0
  309. package/src/surfaces/bottom-dock.json +154 -0
  310. package/src/surfaces/bottom-dock.ts +125 -0
  311. package/src/surfaces/canvas-stage.json +444 -0
  312. package/src/surfaces/canvas-stage.ts +253 -0
  313. package/src/surfaces/cf-account-picker.json +300 -0
  314. package/src/surfaces/cf-account-picker.ts +214 -0
  315. package/src/surfaces/commandbar.json +984 -0
  316. package/src/{panels/toolbar.ts → surfaces/commandbar.ts} +414 -389
  317. package/src/surfaces/convert-repeater.json +309 -0
  318. package/src/surfaces/convert-repeater.ts +276 -0
  319. package/src/surfaces/data-actions.json +157 -0
  320. package/src/surfaces/data-actions.ts +115 -0
  321. package/src/surfaces/dialog.json +289 -0
  322. package/src/surfaces/dialog.ts +343 -0
  323. package/src/surfaces/diff-toolbar.json +266 -0
  324. package/src/surfaces/diff-toolbar.ts +139 -0
  325. package/src/surfaces/doc-header.json +739 -0
  326. package/src/surfaces/doc-header.ts +223 -0
  327. package/src/surfaces/empty-state.json +152 -0
  328. package/src/surfaces/empty-state.ts +173 -0
  329. package/src/surfaces/entry-editor.json +281 -0
  330. package/src/surfaces/entry-editor.ts +191 -0
  331. package/src/surfaces/expression-editor.json +977 -0
  332. package/src/surfaces/expression-editor.ts +266 -0
  333. package/src/surfaces/files-panel.json +592 -0
  334. package/src/surfaces/files-panel.ts +301 -0
  335. package/src/surfaces/formula-palette.json +364 -0
  336. package/src/surfaces/formula-palette.ts +340 -0
  337. package/src/surfaces/git-panel.json +1822 -0
  338. package/src/surfaces/git-panel.ts +272 -0
  339. package/src/surfaces/github-auth.json +112 -0
  340. package/src/surfaces/github-auth.ts +139 -0
  341. package/src/surfaces/github-publish.json +206 -0
  342. package/src/surfaces/github-publish.ts +169 -0
  343. package/src/surfaces/grid-cell.json +218 -0
  344. package/src/surfaces/grid-cell.ts +120 -0
  345. package/src/surfaces/grid-open.json +147 -0
  346. package/src/surfaces/grid-open.ts +87 -0
  347. package/src/surfaces/grid-panel.json +706 -0
  348. package/src/surfaces/grid-panel.ts +206 -0
  349. package/src/surfaces/grid-replace.json +179 -0
  350. package/src/surfaces/grid-replace.ts +89 -0
  351. package/src/surfaces/grid-views.json +446 -0
  352. package/src/surfaces/grid-views.ts +172 -0
  353. package/src/surfaces/inspector-dock.json +187 -0
  354. package/src/surfaces/inspector-dock.ts +161 -0
  355. package/src/surfaces/jump-bar.json +243 -0
  356. package/src/surfaces/jump-bar.ts +129 -0
  357. package/src/surfaces/jxsuite-update.json +146 -0
  358. package/src/surfaces/jxsuite-update.ts +149 -0
  359. package/src/surfaces/library-pane.json +1509 -0
  360. package/src/surfaces/library-pane.ts +363 -0
  361. package/src/surfaces/logic-panel.json +1949 -0
  362. package/src/surfaces/logic-panel.ts +369 -0
  363. package/src/surfaces/logic-workspace.json +685 -0
  364. package/src/surfaces/logic-workspace.ts +238 -0
  365. package/src/surfaces/media-browser.json +303 -0
  366. package/src/surfaces/media-browser.ts +145 -0
  367. package/src/surfaces/media-field.json +163 -0
  368. package/src/surfaces/media-field.ts +116 -0
  369. package/src/surfaces/media-pane.json +513 -0
  370. package/src/surfaces/media-pane.ts +197 -0
  371. package/src/surfaces/menu.json +232 -0
  372. package/src/surfaces/menu.ts +375 -0
  373. package/src/surfaces/navigator-dock.json +113 -0
  374. package/src/surfaces/navigator-dock.ts +130 -0
  375. package/src/surfaces/new-project.json +1654 -0
  376. package/src/surfaces/new-project.ts +411 -0
  377. package/src/surfaces/palette.json +535 -0
  378. package/src/surfaces/pane-context.json +1497 -0
  379. package/src/surfaces/pane-context.ts +513 -0
  380. package/src/surfaces/pane-grid.json +188 -0
  381. package/src/surfaces/pane-grid.ts +250 -0
  382. package/src/surfaces/panel-activity.json +563 -0
  383. package/src/surfaces/panel-activity.ts +187 -0
  384. package/src/surfaces/panel-data.json +141 -0
  385. package/src/surfaces/panel-data.ts +156 -0
  386. package/src/surfaces/panel-deploy-checklist.json +283 -0
  387. package/src/surfaces/panel-deploy-checklist.ts +175 -0
  388. package/src/surfaces/panel-elements.json +367 -0
  389. package/src/surfaces/panel-elements.ts +175 -0
  390. package/src/surfaces/panel-i18n.json +569 -0
  391. package/src/surfaces/panel-i18n.ts +212 -0
  392. package/src/surfaces/panel-imports.json +780 -0
  393. package/src/surfaces/panel-imports.ts +209 -0
  394. package/src/surfaces/panel-outline.json +734 -0
  395. package/src/surfaces/panel-outline.ts +326 -0
  396. package/src/surfaces/panel-page.json +1017 -0
  397. package/src/surfaces/panel-page.ts +240 -0
  398. package/src/surfaces/panel-problems.json +497 -0
  399. package/src/surfaces/panel-problems.ts +157 -0
  400. package/src/surfaces/panel-signals.json +1973 -0
  401. package/src/surfaces/panel-signals.ts +436 -0
  402. package/src/surfaces/panel-stylebook-layers.json +317 -0
  403. package/src/surfaces/panel-stylebook-layers.ts +155 -0
  404. package/src/surfaces/preferences.json +850 -0
  405. package/src/surfaces/preferences.ts +332 -0
  406. package/src/surfaces/progress-modal.json +110 -0
  407. package/src/surfaces/progress-modal.ts +150 -0
  408. package/src/surfaces/properties-panel.json +1578 -0
  409. package/src/surfaces/properties-panel.ts +337 -0
  410. package/src/surfaces/publish.json +945 -0
  411. package/src/surfaces/publish.ts +392 -0
  412. package/src/surfaces/push-plan.json +110 -0
  413. package/src/surfaces/push-plan.ts +87 -0
  414. package/src/surfaces/rail.json +255 -0
  415. package/src/surfaces/rail.ts +206 -0
  416. package/src/surfaces/reference-field.json +191 -0
  417. package/src/surfaces/reference-field.ts +168 -0
  418. package/src/surfaces/schema-builder.json +1011 -0
  419. package/src/surfaces/schema-builder.ts +181 -0
  420. package/src/surfaces/schema-form.json +1013 -0
  421. package/src/surfaces/schema-form.ts +287 -0
  422. package/src/surfaces/secret-field.json +60 -0
  423. package/src/surfaces/secret-field.ts +146 -0
  424. package/src/surfaces/seo.json +932 -0
  425. package/src/surfaces/seo.ts +334 -0
  426. package/src/surfaces/settings-contexts.json +538 -0
  427. package/src/surfaces/settings-contexts.ts +196 -0
  428. package/src/surfaces/settings-contributed.json +489 -0
  429. package/src/surfaces/settings-contributed.ts +199 -0
  430. package/src/surfaces/settings-css-vars.json +820 -0
  431. package/src/surfaces/settings-css-vars.ts +199 -0
  432. package/src/surfaces/settings-defs.json +1363 -0
  433. package/src/surfaces/settings-defs.ts +232 -0
  434. package/src/surfaces/settings-deploy.json +108 -0
  435. package/src/surfaces/settings-deploy.ts +135 -0
  436. package/src/surfaces/settings-extensions.json +486 -0
  437. package/src/surfaces/settings-extensions.ts +201 -0
  438. package/src/surfaces/settings-head.json +779 -0
  439. package/src/surfaces/settings-head.ts +397 -0
  440. package/src/surfaces/settings-locales.json +420 -0
  441. package/src/surfaces/settings-locales.ts +137 -0
  442. package/src/surfaces/settings-overview.json +423 -0
  443. package/src/surfaces/settings-overview.ts +218 -0
  444. package/src/surfaces/settings-packages.json +549 -0
  445. package/src/surfaces/settings-packages.ts +158 -0
  446. package/src/surfaces/settings-pane.json +147 -0
  447. package/src/surfaces/settings-pane.ts +150 -0
  448. package/src/surfaces/settings-rawjson.json +104 -0
  449. package/src/surfaces/settings-rawjson.ts +107 -0
  450. package/src/surfaces/shell.json +99 -0
  451. package/src/surfaces/shell.ts +30 -0
  452. package/src/surfaces/slash-menu.json +180 -0
  453. package/src/surfaces/slash-menu.ts +272 -0
  454. package/src/surfaces/statements.json +607 -0
  455. package/src/surfaces/statements.ts +238 -0
  456. package/src/surfaces/statusbar.json +94 -0
  457. package/src/{panels → surfaces}/statusbar.ts +163 -90
  458. package/src/surfaces/style-panel.json +1643 -0
  459. package/src/surfaces/style-panel.ts +338 -0
  460. package/src/surfaces/stylebook-chrome.json +122 -0
  461. package/src/surfaces/stylebook-chrome.ts +122 -0
  462. package/src/surfaces/tab-strip.json +448 -0
  463. package/src/surfaces/tab-strip.ts +200 -0
  464. package/src/surfaces/target-line.json +419 -0
  465. package/src/surfaces/target-line.ts +349 -0
  466. package/src/surfaces/toasts.json +189 -0
  467. package/src/surfaces/welcome.json +571 -0
  468. package/src/surfaces/welcome.ts +338 -0
  469. package/src/tabs/project-config.ts +71 -15
  470. package/src/tabs/tab.ts +52 -1
  471. package/src/types.ts +22 -0
  472. package/src/ui/ai-credentials-form.ts +104 -100
  473. package/src/ui/ai-managed-connect.ts +54 -36
  474. package/src/ui/ai-model-picker.ts +75 -47
  475. package/src/ui/cf-account-picker.ts +76 -141
  476. package/src/ui/color-selector.ts +80 -301
  477. package/src/ui/dynamic-slot.ts +43 -283
  478. package/src/ui/expression-editor.ts +797 -576
  479. package/src/ui/field-input.ts +8 -181
  480. package/src/ui/form-controls.ts +838 -366
  481. package/src/ui/formula-chips.ts +80 -85
  482. package/src/ui/kit.ts +33 -0
  483. package/src/ui/layers.ts +293 -593
  484. package/src/ui/media-picker.ts +203 -284
  485. package/src/ui/panel-resize.ts +251 -64
  486. package/src/ui/popover-surface.ts +153 -0
  487. package/src/ui/progress-modal.ts +22 -60
  488. package/src/ui/regions.ts +13 -7
  489. package/src/ui/schema-form.ts +906 -440
  490. package/src/ui/surface.ts +122 -0
  491. package/src/ui/unit-selector.ts +15 -131
  492. package/src/ui/value-source.ts +14 -0
  493. package/src/ui/virtual-window.ts +88 -9
  494. package/src/utils/canvas-media.ts +72 -0
  495. package/src/utils/edit-display.ts +7 -2
  496. package/src/utils/element-selectors.ts +69 -0
  497. package/src/utils/link-target.ts +2 -2
  498. package/src/utils/studio-utils.ts +0 -10
  499. package/src/view.ts +15 -0
  500. package/src/workspace/pane-derive.ts +36 -14
  501. package/src/workspace/workspace.ts +15 -6
  502. package/styles/canvas.css +72 -467
  503. package/styles/forced-colors.css +48 -82
  504. package/styles/forced-colors.json +41 -0
  505. package/styles/inspector.css +2 -1301
  506. package/styles/overlays.css +96 -2823
  507. package/styles/panels.css +6 -1423
  508. package/styles/shell-frame.css +272 -0
  509. package/styles/shell-frame.json +227 -0
  510. package/styles/shell.css +0 -1568
  511. package/styles/tokens.css +65 -136
  512. package/styles/tokens.json +84 -0
  513. package/dist/chunks/Overlay.dev-etqjwyf9.js +0 -23
  514. package/dist/chunks/adapter-jkcyhgtr.js +0 -14
  515. package/dist/chunks/cf-account-picker-en86v7x7.js +0 -163
  516. package/dist/chunks/cf-settings-45fgyx8y.js +0 -21
  517. package/dist/chunks/components-zmx10t62.js +0 -21
  518. package/dist/chunks/content-source-48xg86wj.js +0 -49
  519. package/dist/chunks/convert-to-repeater-43tfn7cs.js +0 -268
  520. package/dist/chunks/editor-cptq5jp1.js +0 -37
  521. package/dist/chunks/entry-commands-e63f1xc0.js +0 -46
  522. package/dist/chunks/extension-sections-txv08xxg.js +0 -311
  523. package/dist/chunks/file-ops-wbh4hhsx.js +0 -48
  524. package/dist/chunks/files-3kfkwhk4.js +0 -93
  525. package/dist/chunks/flow-qbfgrpeh.js +0 -634
  526. package/dist/chunks/focus-trap.esm-9t2drp0g.js +0 -1025
  527. package/dist/chunks/focus-visible-6eg70z18.js +0 -167
  528. package/dist/chunks/format-host-w16q81tf.js +0 -43
  529. package/dist/chunks/fs-events-hrrg328g.js +0 -21
  530. package/dist/chunks/git-panel-532whr1y.js +0 -59
  531. package/dist/chunks/index-zqxmqxmh.js +0 -109
  532. package/dist/chunks/jx-validate-8er6gbxy.js +0 -19
  533. package/dist/chunks/layers-panel-07hm7g5j.js +0 -67
  534. package/dist/chunks/layers-q75tj2mf.js +0 -45
  535. package/dist/chunks/lit-html-j055mkh8.js +0 -22
  536. package/dist/chunks/monaco-buffer-dqw0xxpx.js +0 -25
  537. package/dist/chunks/notify-yjm79n4s.js +0 -30
  538. package/dist/chunks/parse-24d0gay3.js +0 -19
  539. package/dist/chunks/platform-ba1j1gbh.js +0 -16
  540. package/dist/chunks/publish-panel-v9st96ja.js +0 -29
  541. package/dist/chunks/quick-search-zccjp6gv.js +0 -66
  542. package/dist/chunks/references-3qx8fkyp.js +0 -29
  543. package/dist/chunks/right-panel-vm3b6kwy.js +0 -46
  544. package/dist/chunks/section-registry-sx1ykvkw.js +0 -30
  545. package/dist/chunks/sp-overlay.dev-qgvhnxf4.js +0 -18
  546. package/dist/chunks/sp-popover.dev-n2etmqdp.js +0 -9
  547. package/dist/chunks/sp-progress-circle.dev-hryhj0es.js +0 -15
  548. package/dist/chunks/sp-tooltip.dev-4sastdnw.js +0 -15
  549. package/dist/chunks/sp-tray.dev-tkbscm06.js +0 -199
  550. package/dist/chunks/studio-0a5qrh01.js +0 -3
  551. package/dist/chunks/studio-0bq6eh7v.js +0 -12
  552. package/dist/chunks/studio-18j3bmcz.js +0 -14
  553. package/dist/chunks/studio-1ngbejft.js +0 -181
  554. package/dist/chunks/studio-4b5z1x43.js +0 -424
  555. package/dist/chunks/studio-4n2b5gzb.js +0 -357
  556. package/dist/chunks/studio-4rzyrtjz.js +0 -426
  557. package/dist/chunks/studio-5fx3g9jg.js +0 -4325
  558. package/dist/chunks/studio-5myknm0a.js +0 -1903
  559. package/dist/chunks/studio-7afd21nw.js +0 -67
  560. package/dist/chunks/studio-7nte2hj4.js +0 -613
  561. package/dist/chunks/studio-8jpzqk5s.js +0 -128
  562. package/dist/chunks/studio-8q517dfr.js +0 -24
  563. package/dist/chunks/studio-950k0dx6.js +0 -6939
  564. package/dist/chunks/studio-9n4mrmnb.js +0 -184
  565. package/dist/chunks/studio-a0tswy0w.js +0 -58
  566. package/dist/chunks/studio-ahnzd9rg.js +0 -23
  567. package/dist/chunks/studio-cmb03bg5.js +0 -13890
  568. package/dist/chunks/studio-d1ks410h.js +0 -175
  569. package/dist/chunks/studio-ef49pnzx.js +0 -387
  570. package/dist/chunks/studio-eqq1w638.js +0 -113
  571. package/dist/chunks/studio-ew0djmhg.js +0 -341
  572. package/dist/chunks/studio-gfgb8pe6.js +0 -1652
  573. package/dist/chunks/studio-h4rxscfc.js +0 -10
  574. package/dist/chunks/studio-jc994dnr.js +0 -1066
  575. package/dist/chunks/studio-kyh9avvv.js +0 -28
  576. package/dist/chunks/studio-m3hwn7y1.js +0 -120
  577. package/dist/chunks/studio-mtfnaqs9.js +0 -659
  578. package/dist/chunks/studio-n6j9t10q.js +0 -318
  579. package/dist/chunks/studio-n8b9wqwy.js +0 -291
  580. package/dist/chunks/studio-qcy05dp8.js +0 -1743
  581. package/dist/chunks/studio-qq6jym04.js +0 -53
  582. package/dist/chunks/studio-rdx8jcxy.js +0 -83
  583. package/dist/chunks/studio-rn9ta2mz.js +0 -111
  584. package/dist/chunks/studio-t7qb9db8.js +0 -665
  585. package/dist/chunks/studio-tmc5emrw.js +0 -8
  586. package/dist/chunks/studio-z6nw2ek2.js +0 -18
  587. package/dist/chunks/studio-zczps70q.js +0 -378
  588. package/dist/chunks/studio-zqazsct2.js +0 -1823
  589. package/dist/chunks/workspace-fjx52ryv.js +0 -89
  590. package/src/panels/activity-bar.ts +0 -251
  591. package/src/panels/panel-scheduler.ts +0 -219
  592. package/src/panels/style-inputs.ts +0 -237
  593. package/src/panels/target-line.ts +0 -274
  594. package/src/panels/welcome-screen.ts +0 -346
  595. package/src/ui/button-group.ts +0 -102
  596. package/src/ui/choice-field.ts +0 -72
  597. package/src/ui/field-row.ts +0 -249
  598. package/src/ui/formula-palette.ts +0 -213
  599. package/src/ui/icons.ts +0 -52
  600. package/src/ui/jx-theme.ts +0 -130
  601. package/src/ui/spectrum.ts +0 -340
  602. package/src/ui/value-selector.ts +0 -174
  603. package/src/ui/widgets.ts +0 -172
  604. /package/dist/chunks/{javascript-s56a8dpk.css → javascript-4abzjcy9.css} +0 -0
  605. /package/dist/chunks/{jsonMode-zr9sw0c7.css → jsonMode-vvmpmk34.css} +0 -0
  606. /package/dist/chunks/{monaco-setup-pav68602.css → monaco-setup-8vbyqnhr.css} +0 -0
  607. /package/dist/chunks/{tsMode-ef187txx.css → tsMode-hnxxb73h.css} +0 -0
@@ -1,32 +1,43 @@
1
1
  /// <reference lib="dom" />
2
2
  /// <reference lib="dom.iterable" />
3
3
  /**
4
- * File tree management — project loading, file tree rendering, and file CRUD.
4
+ * File tree management — project loading, file CRUD, and the flow behind the Navigator's Files
5
+ * panel.
5
6
  *
6
- * Functions that mutate state accept a context object with callbacks, following the same pattern as
7
- * file-ops.js. Every name the user supplies (new file, rename) is collected with the Spectrum
8
- * prompt dialog from ui/layers.ts — never a native browser prompt (studio-ui-guidelines.md §8.7).
7
+ * **The body is a Jx document** (`surfaces/files-panel.json`, mounted by
8
+ * `surfaces/files-panel.ts`), so this module draws no markup: it projects. What stays here is
9
+ * everything that is a DECISION — which directories are listed, which entries `.gitignore` masks,
10
+ * how the flat row model is built and where the window falls on it, what a click and a key MEAN,
11
+ * what the per-row menu offers, and what each verb does to the filesystem. The surface reads
12
+ * values.
13
+ *
14
+ * Every name the user supplies (new file, rename) is collected with the prompt dialog from
15
+ * ui/layers.ts — never a native browser prompt (studio-ui-guidelines.md §8.7).
9
16
  *
10
17
  * **The tree is a flat list of rows, and the DOM holds a window onto it** ({@link FileRow},
11
18
  * `ui/virtual-window.ts`). It used to recurse a template per directory level, which is why it drew
12
19
  * every expanded row of every expanded directory — a `node_modules` expanded by accident is tens of
13
- * thousands of `sp-icon` custom elements, built synchronously, on every repaint. A recursion has no
14
- * row list to window, so the recursion moved into {@link collectFileRows}, which produces the rows
15
- * in display order and nothing else; the render is then a window over that array.
20
+ * thousands of icon custom elements, built synchronously, on every repaint. A recursion has no row
21
+ * list to window, so the recursion moved into {@link collectFileRows}, which produces the rows in
22
+ * display order and nothing else; the projection is then a window over that array.
16
23
  *
17
24
  * Flattening costs the `role="group"` wrappers, and pays for them with `aria-level` +
18
25
  * `aria-posinset` / `aria-setsize` on every row — the same shape the Outline has always had, and
19
26
  * the only shape that stays TRUE when the tree draws eleven rows out of ten thousand.
20
27
  *
28
+ * **Four facts about a row are ONE scope field each**, not fields of the row: the selected path,
29
+ * the dragged path, the drop target and the roving tab stop. The document compares each against
30
+ * `$map.item.path`, so moving the selection or dragging a file re-evaluates one attribute per drawn
31
+ * row instead of rebuilding the list — which is what lets a drag-over highlight cost nothing, and
32
+ * what stops a window sliding out from under the drag sources pragmatic-dnd is holding.
33
+ *
21
34
  * @docs studio/interface
22
35
  */
23
36
 
24
- import { html, nothing } from "lit-html";
37
+ import { nothing } from "lit-html";
25
38
  import { errorMessage } from "@jxsuite/schema/parse";
26
39
  import { localeLabel, localeOfPath, resolveI18n } from "@jxsuite/schema/locale";
27
- import { classMap } from "lit-html/directives/class-map.js";
28
- import { ref } from "lit-html/directives/ref.js";
29
- import { renderPopover, showPromptDialog } from "../ui/layers";
40
+ import { showPromptDialog } from "../ui/layers";
30
41
  import { projectState, requireProjectState, setProjectState } from "../store";
31
42
  import { getPlatform } from "../platform";
32
43
  import { disarmPreviewOverlay } from "../preview/preview-overlay";
@@ -64,6 +75,8 @@ import { isViewableMedia, openMediaTab } from "../media/media-open";
64
75
  import { activeRegistry } from "../commands/active-registry";
65
76
  import { collectionOfPath } from "../content/entry-model";
66
77
  import { confirmFileDelete, parseSourceForPath, renamePromptMessage } from "./file-ops";
78
+ import { parseJsonDocument } from "./json-layout";
79
+ import type { JsonLayout } from "./json-layout";
67
80
  import { invalidateUsages } from "../services/references";
68
81
  import {
69
82
  documentExtensions,
@@ -80,31 +93,21 @@ import { markSessionRestored, persistedSession, resetProjectShell, setActivityTa
80
93
  import { restoreSession } from "../workspace/session";
81
94
  import { cleanupGitPanel } from "../panels/git-panel";
82
95
  import { addRecentProject, trackRecentFile } from "../recent-projects";
83
- import {
84
- listWindow,
85
- measuredRowHeight,
86
- revealListRow,
87
- watchListWindow,
88
- } from "../ui/virtual-window";
89
- import type { TemplateResult } from "lit-html";
96
+ import { listWindow, revealListRow, watchListWindow } from "../ui/virtual-window";
90
97
  import type { JxMutableNode } from "@jxsuite/schema/types";
91
98
  import type { ResolvedI18n } from "@jxsuite/schema/locale";
92
- import type { ChoiceOption } from "../ui/choice-field";
99
+ import type { ChoiceOption } from "../ui/layers";
100
+ import { emptyFilesPanelValues, mountFilesPanelSurface } from "../surfaces/files-panel";
101
+ import { openMenu } from "../surfaces/menu";
102
+ import type {
103
+ FileRowView,
104
+ FilesPanelActions,
105
+ FilesPanelSurfaceHandle,
106
+ FilesPanelValues,
107
+ } from "../surfaces/files-panel";
108
+ import type { MenuHandle, MenuRowProjection } from "../surfaces/menu";
93
109
  import type { DirEntry, RenameResult } from "../types";
94
110
  import type { ListWindowWatch } from "../ui/virtual-window";
95
- import { rectOf } from "../utils/geometry";
96
- import { repeat } from "lit-html/directives/repeat.js";
97
-
98
- // ─── File icon map ────────────────────────────────────────────────────────────
99
-
100
- const fileIconMap = {
101
- "sp-icon-document": html`<sp-icon-document></sp-icon-document>`,
102
- "sp-icon-file-code": html`<sp-icon-file-code></sp-icon-file-code>`,
103
- "sp-icon-file-txt": html`<sp-icon-file-txt></sp-icon-file-txt>`,
104
- "sp-icon-folder": html`<sp-icon-folder></sp-icon-folder>`,
105
- "sp-icon-folder-open": html`<sp-icon-folder-open></sp-icon-folder-open>`,
106
- "sp-icon-image": html`<sp-icon-image></sp-icon-image>`,
107
- } as Record<string, TemplateResult>;
108
111
 
109
112
  // ─── File management ──────────────────────────────────────────────────────────
110
113
 
@@ -416,160 +419,66 @@ export async function openLastSessionOrHome(): Promise<boolean> {
416
419
  return false;
417
420
  }
418
421
 
419
- // ─── File tree templates ──────────────────────────────────────────────────────
422
+ // ─── Row icons ────────────────────────────────────────────────────────────────
420
423
 
421
- function fileTypeIconTpl(name: string, type: string) {
422
- let tag;
424
+ /**
425
+ * The kit glyph one row draws, by NAME rather than by tag.
426
+ *
427
+ * It used to be a map of six `sp-icon-*` templates built once at module load, which is a
428
+ * `TemplateResult` per icon whether or not the tree was ever opened. A name is a string the
429
+ * document hands `jx-icon`, and the manifest is what resolves it — so a row costs nothing until it
430
+ * is drawn, and `scripts/check-icons.ts` checks the key against the same manifest the rail's does.
431
+ */
432
+ function fileIconName(name: string, type: string, expanded: boolean): string {
423
433
  if (type === "directory") {
424
- tag = projectState?.expanded?.has(name) ? "sp-icon-folder-open" : "sp-icon-folder";
425
- } else {
426
- const ext = name.split(".").pop()?.toLowerCase();
427
- switch (ext) {
428
- case "json": {
429
- tag = "sp-icon-file-code";
430
- break;
431
- }
432
- case "md": {
433
- tag = "sp-icon-file-txt";
434
- break;
435
- }
436
- case "js":
437
- case "ts": {
438
- tag = "sp-icon-file-code";
439
- break;
440
- }
441
- case "css": {
442
- tag = "sp-icon-file-code";
443
- break;
444
- }
445
- default: {
446
- // Every image extension the media layer knows about, so an uploaded .avif/.ico gets the
447
- // Same icon as a .png instead of falling through to the generic document glyph.
448
- tag = ext && isImage(ext) ? "sp-icon-image" : "sp-icon-document";
449
- break;
450
- }
434
+ return expanded ? "folder-open" : "folder";
435
+ }
436
+ const ext = name.split(".").pop()?.toLowerCase();
437
+ switch (ext) {
438
+ case "css":
439
+ case "js":
440
+ case "json":
441
+ case "ts": {
442
+ return "file-code";
443
+ }
444
+ case "md": {
445
+ return "file-text";
446
+ }
447
+ default: {
448
+ // Every image extension the media layer knows about, so an uploaded .avif/.ico gets the
449
+ // Same icon as a .png instead of falling through to the generic document glyph.
450
+ return ext !== undefined && isImage(ext) ? "image" : "file";
451
451
  }
452
452
  }
453
- return fileIconMap[tag] || fileIconMap["sp-icon-document"];
454
453
  }
455
454
 
456
455
  /**
457
- * Render the file tree template for the left panel.
456
+ * The Navigator no longer draws this panel with lit.
457
+ *
458
+ * The record below returns `nothing` and mounts `surfaces/files-panel.json` in `afterRender`, so
459
+ * this is a stub: it survives only because `NavigatorPanelDeps` still declares the injection and
460
+ * `studio.ts` still passes it. Both go in the change that deletes this.
458
461
  *
459
- * @param {{
460
- * openProject: () => void;
461
- * openFileFromTree: (path: string) => void;
462
- * renderLeftPanel: () => void;
463
- * }} ctx
462
+ * @deprecated The panel is `surfaces/files-panel.json`; call {@link mountFilesPanel}.
464
463
  */
465
- export function renderFilesTemplate({
466
- openProject: openProjectFn,
467
- openFileFromTree: openFileFn,
468
- renderLeftPanel,
469
- }: {
470
- openProject: () => void;
471
- openFileFromTree: (path: string) => void;
472
- renderLeftPanel: () => void;
473
- }) {
474
- if (!projectState) {
475
- return html`<div class="file-tree-empty">No project loaded</div>`;
476
- }
477
-
478
- // No project selected in a monorepo — show welcome prompt
479
- if (!projectState.isSiteProject && projectState.projectRoot === ".") {
480
- return html`<div class="file-tree-empty">
481
- <p style="margin:0 0 12px">Open a project folder to get started.</p>
482
- <sp-button variant="accent" size="s" @click=${openProjectFn}>Open Project</sp-button>
483
- </div>`;
484
- }
485
-
486
- const showingIgnored = showIgnoredFiles();
464
+ export function renderFilesTemplate(): typeof nothing {
465
+ return nothing;
466
+ }
487
467
 
488
- return html`
489
- ${
490
- projectState.isSiteProject
491
- ? html`
492
- <div class="project-header">
493
- <span class="project-name"
494
- >${projectState.projectConfig?.name || projectState.name}</span
495
- >
496
- </div>
497
- `
498
- : nothing
499
- }
500
- <div class="files-toolbar">
501
- <sp-action-group size="xs" compact quiet>
502
- <sp-action-button
503
- size="xs"
504
- label="New File"
505
- @click=${() => createNewFile(".", renderLeftPanel)}
506
- >
507
- <sp-icon-add slot="icon"></sp-icon-add>
508
- </sp-action-button>
509
- <sp-action-button
510
- size="xs"
511
- label="Refresh"
512
- @click=${async () => {
513
- requireProjectState().dirs.clear();
514
- /* The rules go with the listings. Refresh is what an author reaches for after editing a
515
- `.gitignore` by hand, and a tree that came back still hiding by the old rules would
516
- read as the button not having worked. */
517
- resetIgnoreCache();
518
- await loadDirectory(".");
519
- for (const dir of requireProjectState().expanded) {
520
- await loadDirectory(dir);
521
- }
522
- renderLeftPanel();
523
- }}
524
- >
525
- <sp-icon-refresh slot="icon"></sp-icon-refresh>
526
- </sp-action-button>
527
- <sp-action-button
528
- size="xs"
529
- label=${showingIgnored ? "Hide ignored files" : "Show ignored files"}
530
- ?selected=${showingIgnored}
531
- @click=${() => {
532
- /* A repaint and nothing else: the ignored entries were never dropped from
533
- `projectState.dirs`, only from the rows built out of it. */
534
- setShowIgnoredFiles(!showingIgnored);
535
- renderLeftPanel();
536
- }}
537
- >
538
- ${
539
- showingIgnored
540
- ? html`<sp-icon-visibility slot="icon"></sp-icon-visibility>`
541
- : html`<sp-icon-visibility-off slot="icon"></sp-icon-visibility-off>`
542
- }
543
- </sp-action-button>
544
- </sp-action-group>
545
- <sp-search
546
- size="s"
547
- quiet
548
- placeholder="Filter files…"
549
- value=${requireProjectState().searchQuery}
550
- @input=${(e: Event) => {
551
- requireProjectState().searchQuery = (e.target as HTMLInputElement).value;
552
- renderLeftPanel();
553
- }}
554
- @submit=${(e: Event) => e.preventDefault()}
555
- ></sp-search>
556
- </div>
557
- <div
558
- class="file-tree"
559
- role="tree"
560
- aria-label="Project files"
561
- @keydown=${(e: KeyboardEvent) => {
562
- onFileTreeKeydown(e, e.currentTarget as HTMLElement);
563
- }}
564
- ${ref((el) => {
565
- if (el) {
566
- afterFileTreeRender(el as HTMLElement);
567
- }
568
- })}
569
- >
570
- ${fileTreeBodyTemplate({ openFileFn, renderLeftPanel })}
571
- </div>
572
- `;
468
+ /**
469
+ * Drag-and-drop is registered against the row elements the DOCUMENT creates, as they are created.
470
+ *
471
+ * The pass this replaced ran on a `requestAnimationFrame` after every repaint, found the tree and
472
+ * its rows by class, and re-registered every one of them — which is exactly the acquisition
473
+ * `studio-ui-guidelines.md` §9.4 objects to, and which a WINDOWED list makes wrong rather than
474
+ * merely wasteful: the rows are re-used for different files as the window slides, so a pass that
475
+ * arrives one frame late hands a file's drag source to whichever file is standing in its place.
476
+ * {@link mountFilesPanel} adopts each row through `onNodeCreated` instead.
477
+ *
478
+ * @deprecated Registration is `onNodeCreated`; this exists for the deps entry alone.
479
+ */
480
+ export function registerFileTreeDnD(_ctx: { renderLeftPanel: () => void }): void {
481
+ // Intentionally nothing: see the note above.
573
482
  }
574
483
 
575
484
  // ─── The row model, and the window onto it ───────────────────────────────────
@@ -583,7 +492,7 @@ export function renderFilesTemplate({
583
492
  */
584
493
  interface FileRow {
585
494
  /**
586
- * Lit's `repeat` key.
495
+ * The `$map` key the document reconciles by.
587
496
  *
588
497
  * Keyed, where the recursive form was positional: a windowed list re-uses its DOM nodes for
589
498
  * DIFFERENT rows as the window slides, so positional reuse would leave the keyboard focused on an
@@ -613,7 +522,7 @@ interface FileRow {
613
522
  }
614
523
 
615
524
  /**
616
- * The declared height of one row — `styles/panels.css` `.file-tree-item { block-size: 24px }`.
525
+ * The declared height of one row — the `--jx-control-h` the document gives `[part="row"]`.
617
526
  *
618
527
  * The first paint of a session windows by this constant, because nothing has been laid out yet to
619
528
  * measure; {@link fileRowHeight} measures a real row from then on and believes the measurement.
@@ -622,18 +531,58 @@ export const FILE_ROW_HEIGHT = 24;
622
531
 
623
532
  /** The rows the tree last built, in display order. */
624
533
  let _fileRows: FileRow[] = [];
625
- /** The `.file-tree` element, kept between renders so the next one can be windowed. */
534
+ /** The tree element, adopted through the document's `onNodeCreated` so it is never re-found. */
626
535
  let _fileList: HTMLElement | null = null;
536
+ /**
537
+ * Every DRAWN row's element, by path.
538
+ *
539
+ * Held rather than queried, which is the §9.4 rule and, for a windowed list, the only correct
540
+ * answer: the nodes are re-used for different files as the window slides, so a selector run a frame
541
+ * later resolves to whichever file is standing there now. Entries whose element has left the
542
+ * document are swept on the next projection.
543
+ */
544
+ const _fileRowEls = new Map<string, HTMLElement>();
627
545
  /** The scroll watch that repaints the tree as its scroller moves. */
628
546
  let _fileWatch: ListWindowWatch | null = null;
629
547
  /** The Navigator repaint, captured per render so the scroll watch never holds a stale one. */
630
548
  let _filesRerender: (() => void) | null = null;
631
- /** A keyboard jump that had to scroll first, spent by the repaint it provoked. */
632
- let _pendingFocusPath: string | null = null;
633
549
 
634
- /** The height one row actually has; the declared constant until a row has been laid out. */
550
+ /**
551
+ * The height one row actually has; the declared constant until a row has been laid out.
552
+ *
553
+ * Measured off a row this module already holds. The DECLARED height is what lets the FIRST render
554
+ * window anything at all, before any row exists; the MEASUREMENT is what stops that constant
555
+ * becoming a lie the day the density setting changes it, a user zooms, or a locale's font raises
556
+ * the line box.
557
+ */
635
558
  function fileRowHeight(): number {
636
- return measuredRowHeight(_fileList, ".file-tree-item", FILE_ROW_HEIGHT);
559
+ for (const el of _fileRowEls.values()) {
560
+ if (el.isConnected && el.offsetHeight > 0) {
561
+ return el.offsetHeight;
562
+ }
563
+ }
564
+ return FILE_ROW_HEIGHT;
565
+ }
566
+
567
+ /** Forget the rows the window has taken away, and release what was registered against them. */
568
+ function sweepRowElements(): void {
569
+ for (const [path, el] of _fileRowEls) {
570
+ if (!el.isConnected) {
571
+ _fileRowEls.delete(path);
572
+ releaseRowDnD(el);
573
+ }
574
+ }
575
+ }
576
+
577
+ /** The rendered row for a path, or null when the window does not currently hold it. */
578
+ function fileRowElement(path: string): HTMLElement | null {
579
+ const el = _fileRowEls.get(path);
580
+ return el?.isConnected === true ? el : null;
581
+ }
582
+
583
+ /** The model row for a path, or undefined. A "Loading…" row is keyed apart and never matches. */
584
+ function fileRowAt(path: string): FileRow | undefined {
585
+ return _fileRows.find((row) => !row.loading && row.path === path);
637
586
  }
638
587
 
639
588
  /**
@@ -646,12 +595,11 @@ function collectFileRows(
646
595
  dirPath: string,
647
596
  depth: number,
648
597
  rows: FileRow[],
649
- ctx: { renderLeftPanel: () => void },
650
598
  i18n: ResolvedI18n | null,
651
599
  ): void {
652
600
  const entries = requireProjectState().dirs.get(dirPath);
653
601
  if (!entries) {
654
- void loadDirectory(dirPath).then(() => ctx.renderLeftPanel());
602
+ void loadDirectory(dirPath).then(() => repaintFiles());
655
603
  rows.push({
656
604
  depth,
657
605
  expanded: false,
@@ -705,7 +653,7 @@ function collectFileRows(
705
653
  type: entry.type,
706
654
  });
707
655
  if (isExpanded) {
708
- collectFileRows(entry.path, depth + 1, rows, ctx, i18n);
656
+ collectFileRows(entry.path, depth + 1, rows, i18n);
709
657
  }
710
658
  }
711
659
  }
@@ -725,277 +673,428 @@ function fileStep(index: number, step: 1 | -1): number {
725
673
  return -1;
726
674
  }
727
675
 
676
+ /**
677
+ * The row at `index`'s parent: the nearest row above it at a shallower depth; -1 at the top level.
678
+ *
679
+ * Over the MODEL, which is the whole reason `jx-tree` asks rather than answering. The element's own
680
+ * `ArrowLeft` climbs to the nearest DRAWN row at a shallower level, and a directory whose contents
681
+ * fill the viewport is precisely the case where its own row is the one scrolled off the top.
682
+ */
683
+ function fileParentIndex(index: number): number {
684
+ const row = _fileRows[index];
685
+ if (!row) {
686
+ return -1;
687
+ }
688
+ for (let i = index - 1; i >= 0; i--) {
689
+ const above = _fileRows[i]!;
690
+ if (!above.loading && above.depth < row.depth) {
691
+ return i;
692
+ }
693
+ }
694
+ return -1;
695
+ }
696
+
728
697
  /**
729
698
  * Repaint the tree because its window changed.
730
699
  *
731
- * Deferred to a microtask so a scroll arriving mid-commit cannot re-enter the render producing the
732
- * rows, and skipped during a drag: `registerFileTreeDnD` holds pragmatic-dnd registrations on the
733
- * rows it can see, and re-rendering under an active drag would drop every one of them.
700
+ * Deferred to a microtask so a scroll arriving mid-commit cannot re-enter the projection producing
701
+ * the rows, and skipped during a drag: a window that slid under pragmatic-dnd would hand its
702
+ * registrations to a different set of rows halfway through the gesture. `_dragPath` is what says a
703
+ * drag is in flight — a state this module holds, where it used to be a class on a node it then had
704
+ * to go and look for.
734
705
  */
735
706
  function fileWindowChanged(): void {
736
- if (_fileList?.isConnected !== true || _fileList.querySelector(".file-tree-item.dragging")) {
707
+ if (_fileList?.isConnected !== true || _dragPath !== "") {
737
708
  return;
738
709
  }
739
- queueMicrotask(() => _filesRerender?.());
710
+ queueMicrotask(repaintFiles);
740
711
  }
741
712
 
742
713
  /**
743
- * Adopt the rendered tree: remember it, keep it watching whatever scrolls it, and hand the keyboard
744
- * the row a jump asked for once that row exists.
714
+ * Adopt the tree: keep it watching whatever scrolls it.
745
715
  *
746
- * The first paint of a session draws every row, because nothing can be measured before it exists;
747
- * the watch's opening measurement is what asks for the second, windowed pass. Idempotent by
748
- * construction — `watchListWindow` hands back the same watch for the same element and scroller — so
749
- * calling it after every render costs a comparison.
716
+ * Called after every projection rather than once at mount, and that is not belt-and-braces. The
717
+ * tree element is created ONE time — the document re-uses it for the life of the panel — and at
718
+ * that instant it holds no rows, so it does not yet overflow and `watchListWindow` correctly
719
+ * resolves no scroller at all. The first paint draws every row, because nothing can be measured
720
+ * before it exists; the watch's opening measurement is what asks for the second, windowed pass.
721
+ * Idempotent by construction — `watchListWindow` hands back the same watch for the same element and
722
+ * scroller — so calling it again costs a comparison.
750
723
  */
751
- function adoptFileTree(tree: HTMLElement): void {
752
- _fileList = tree;
724
+ function adoptFileTree(): void {
725
+ const tree = _fileList;
726
+ if (tree === null) {
727
+ return;
728
+ }
753
729
  _fileWatch = watchListWindow(_fileWatch, tree, {
754
730
  count: () => _fileRows.length,
755
731
  onChange: fileWindowChanged,
756
732
  rowHeight: fileRowHeight,
757
733
  });
758
- const wanted = _pendingFocusPath;
759
- if (wanted !== null) {
760
- // One shot: a focus request that outlived its own repaint is stale, and moving the keyboard
761
- // Later is worse than never having moved it.
762
- _pendingFocusPath = null;
763
- fileRowElement(tree, wanted)?.focus();
764
- }
765
734
  }
766
735
 
767
- /**
768
- * Adopt the tree once its rows are in the document.
769
- *
770
- * Deferred by a microtask on purpose, exactly as the Outline's `afterTreeRender` is: a `ref` on the
771
- * tree element commits BEFORE the child part holding the rows, so on a first render the callback
772
- * would otherwise measure an empty tree.
773
- */
774
- function afterFileTreeRender(tree: HTMLElement): void {
775
- queueMicrotask(() => adoptFileTree(tree));
776
- }
736
+ // ─── What the document draws ─────────────────────────────────────────────────
777
737
 
778
- /** The rendered row for a path, or null when the window does not currently hold it. */
779
- function fileRowElement(tree: HTMLElement, path: string): HTMLElement | null {
780
- return tree.querySelector<HTMLElement>(`.file-tree-item[data-path="${CSS.escape(path)}"]`);
738
+ /** One model row, as the document reads it: every field a string, and nothing left to decide. */
739
+ function fileRowView(row: FileRow): FileRowView {
740
+ const level = String(row.depth + 1);
741
+ if (row.loading) {
742
+ return {
743
+ ariaExpanded: "",
744
+ depth: String(row.depth),
745
+ icon: "",
746
+ key: row.key,
747
+ kind: "loading",
748
+ level,
749
+ locale: "",
750
+ localeState: "hidden",
751
+ name: row.name,
752
+ path: row.path,
753
+ posInSet: "",
754
+ setSize: "",
755
+ type: row.type,
756
+ };
757
+ }
758
+ /* `""` for a file, and it is not "no answer": an empty `expanded` is what tells `jx-tree-item` the
759
+ row is a LEAF, so it draws no twisty, writes no `aria-expanded`, and `ArrowRight` on it does
760
+ nothing rather than stepping into a directory the row does not have. */
761
+ const isDir = row.type === "directory";
762
+ return {
763
+ ariaExpanded: isDir ? String(row.expanded) : "",
764
+ depth: String(row.depth),
765
+ icon: fileIconName(row.path, row.type, row.expanded),
766
+ key: row.key,
767
+ kind: "item",
768
+ level,
769
+ locale: row.locale === undefined ? "" : localeLabel(row.locale),
770
+ localeState: row.locale === undefined ? "hidden" : "shown",
771
+ name: row.name,
772
+ path: row.path,
773
+ posInSet: String(row.posInSet),
774
+ setSize: String(row.setSize),
775
+ type: row.type,
776
+ };
781
777
  }
782
778
 
783
779
  /**
784
- * The tree's rows, windowed, with the scroll height of the rows it left out reserved either side.
780
+ * Everything the Files document draws right now.
785
781
  *
786
- * The two spacers are `aria-hidden` because a `role="tree"` owns `treeitem`s, and an empty div that
787
- * exists to be 4 000 pixels tall is not one.
782
+ * Three shapes, discriminated by one word, because "there is no project", "this is a monorepo root
783
+ * that has not been pointed at a site" and "here is a tree" are three different things to say and
784
+ * the first two have different offers. The rows are the WINDOW, and the scroll of everything either
785
+ * side of it is reserved by the two spacers — so the array this hands over is a dozen rows whether
786
+ * the project holds twelve files or ten thousand.
788
787
  */
789
- function fileTreeBodyTemplate(ctx: {
790
- openFileFn: (path: string) => void;
791
- renderLeftPanel: () => void;
792
- }): TemplateResult {
793
- // The scroll watch outlives this call and must never repaint through a closure from an earlier
794
- // One — the Navigator's scheduler is the only thing that knows how to draw this panel.
795
- _filesRerender = ctx.renderLeftPanel;
788
+ function filesPanelValues(): FilesPanelValues {
789
+ sweepRowElements();
790
+ if (!projectState) {
791
+ _fileRows = [];
792
+ const values: FilesPanelValues = { ...emptyFilesPanelValues(), view: "none" };
793
+ _lastValues = values;
794
+ return values;
795
+ }
796
+ if (!projectState.isSiteProject && projectState.projectRoot === ".") {
797
+ _fileRows = [];
798
+ const values: FilesPanelValues = { ...emptyFilesPanelValues(), view: "welcome" };
799
+ _lastValues = values;
800
+ return values;
801
+ }
802
+
803
+ const state = requireProjectState();
796
804
  _fileRows = [];
797
- // Resolved once for the whole tree, not once per row: this function runs on EVERY repaint of the
805
+ // Resolved once for the whole tree, not once per row: this runs on EVERY repaint of the
798
806
  // Navigator, and `resolveI18n` canonicalizes every declared tag through `Intl.Locale`.
799
- const { i18n } = resolveI18n(projectState?.projectConfig ?? {});
800
- collectFileRows(".", 0, _fileRows, ctx, i18n);
801
- // Windowed against the PREVIOUS render's element, the only one that exists while this template is
802
- // Being built. There is none on the first paint, and `listWindow` then answers "all of them".
807
+ const { i18n } = resolveI18n(state.projectConfig ?? {});
808
+ collectFileRows(".", 0, _fileRows, i18n);
809
+ // Windowed against the element the document holds, which is the only one that exists while this
810
+ // Is being built. There is none before the first mount, and `listWindow` then answers "all of
811
+ // Them".
803
812
  const range = listWindow(_fileList, { count: _fileRows.length, rowHeight: fileRowHeight() });
804
- // The roving tab stop is decided from the MODEL — the first DRAWN row of a windowed tree is
805
- // Usually not the first row of the tree — and then clamped INTO the window, because a tab stop
806
- // That is not in the document is not a tab stop: a tree whose selected row has scrolled away
807
- // Would otherwise have no tabbable row at all, and Tab would skip the whole panel.
808
- const wanted = Math.max(0, fileIndexOfPath(requireProjectState().selectedPath ?? undefined));
809
- const tabStop = Math.min(Math.max(wanted, range.start), Math.max(range.start, range.end - 1));
810
- const slice = _fileRows
811
- .slice(range.start, range.end)
812
- .map((row, offset) => ({ row, tabStop: range.start + offset === tabStop }));
813
- return html`
814
- <div style="height:${range.padTop}px" aria-hidden="true"></div>
815
- ${repeat(
816
- slice,
817
- (entry) => entry.row.key,
818
- (entry) => fileRowTemplate(entry.row, entry.tabStop, ctx),
819
- )}
820
- <div style="height:${range.padBottom}px" aria-hidden="true"></div>
821
- `;
822
- }
823
-
824
- /** One row, drawn. */
825
- function fileRowTemplate(
826
- row: FileRow,
827
- tabStop: boolean,
828
- ctx: { openFileFn: (path: string) => void; renderLeftPanel: () => void },
829
- ): TemplateResult {
830
- if (row.loading) {
831
- return html`<div
832
- class="file-tree-item"
833
- style="padding-left:${8 + row.depth * 16}px;color:var(--fg-dim);font-style:italic"
834
- >
835
- Loading…
836
- </div>`;
813
+ const drawn = _fileRows.slice(range.start, range.end);
814
+ /* The caret is a SEED, not a clamp. `jx-tree` owns it, keeps it across every repaint that does
815
+ not change `current`, and falls back to the first drawn row for the TAB STOP on its own — so a
816
+ reader whose row has scrolled three hundred rows away keeps their place and still has a way
817
+ back in with Tab. What this replaced recomputed the stop from the selection on every paint and
818
+ clamped it into the window, which moved the reader on a wheel.
819
+
820
+ It must still NAME a row, and the fallback is what guarantees it rather than tidiness: `move`
821
+ reports the caret's own row as `from`, and a tree nobody has touched would report `""` and send
822
+ every ↓ off the bottom of the window back to the first row of the project. */
823
+ const caret =
824
+ (state.selectedPath !== null && fileRowAt(state.selectedPath) ? state.selectedPath : "") ||
825
+ drawn.find((row) => !row.loading)?.path ||
826
+ "";
827
+ const showingIgnored = showIgnoredFiles();
828
+
829
+ const values: FilesPanelValues = {
830
+ currentPath: caret,
831
+ dragPath: _dragPath,
832
+ dropPath: _dropPath,
833
+ headerState: state.isSiteProject ? "shown" : "hidden",
834
+ ignoredIcon: showingIgnored ? "eye" : "eye-slash",
835
+ ignoredLabel: showingIgnored ? "Hide ignored files" : "Show ignored files",
836
+ ignoredSelected: showingIgnored,
837
+ padBottom: range.padBottom,
838
+ padTop: range.padTop,
839
+ projectName: state.projectConfig?.name || state.name,
840
+ query: state.searchQuery,
841
+ rootDrop: _rootDrop,
842
+ rows: drawn.map((row) => fileRowView(row)),
843
+ selectedPath: state.selectedPath ?? "",
844
+ view: "tree",
845
+ };
846
+ _lastValues = values;
847
+ return values;
848
+ }
849
+
850
+ /**
851
+ * Say only what a DRAG changed, without rebuilding the row model.
852
+ *
853
+ * `onDrag` fires per pointer move. Re-projecting from scratch would re-walk every listed directory,
854
+ * re-resolve the locales and re-slice the window on each of them, so the three fields a drag
855
+ * actually moves are written over the last projection instead — and because the document compares
856
+ * each of them against `$map.item.path`, what reaches the DOM is one attribute per drawn row.
857
+ */
858
+ function syncFilesDragState(): void {
859
+ if (!_standingFiles || !_lastValues) {
860
+ return;
837
861
  }
838
- const isDir = row.type === "directory";
839
- return html`
840
- <div
841
- class=${classMap({
842
- "file-tree-item": true,
843
- selected: requireProjectState().selectedPath === row.path,
844
- })}
845
- style="padding-left:${8 + row.depth * 16}px"
846
- role="treeitem"
847
- aria-level=${row.depth + 1}
848
- aria-posinset=${row.posInSet}
849
- aria-setsize=${row.setSize}
850
- tabindex=${tabStop ? "0" : "-1"}
851
- data-path=${row.path}
852
- data-type=${row.type}
853
- aria-expanded=${isDir ? String(row.expanded) : nothing}
854
- @click=${async (e: MouseEvent) => {
855
- e.stopPropagation();
856
- if (isDir) {
857
- await toggleTreeDirectory(row.path);
858
- ctx.renderLeftPanel();
859
- } else {
860
- ctx.openFileFn(row.path);
861
- }
862
- }}
863
- @contextmenu=${(e: MouseEvent) => {
864
- e.preventDefault();
865
- e.stopPropagation();
866
- showFileContextMenu(e, { name: row.name, path: row.path, type: row.type }, ctx);
867
- }}
868
- >
869
- ${
870
- isDir
871
- ? html`<span class="file-tree-toggle">${row.expanded ? "▼" : "▶"}</span>`
872
- : html`<span class="file-tree-toggle empty"> </span>`
873
- }
874
- <span class="file-tree-icon">${fileTypeIconTpl(row.path, row.type)}</span>
875
- <span class="file-tree-name">${row.name}</span>
876
- ${
877
- row.locale === undefined
878
- ? nothing
879
- : html`<span class="file-tree-locale">${localeLabel(row.locale)}</span>`
880
- }
881
- </div>
882
- `;
862
+ _lastValues = {
863
+ ..._lastValues,
864
+ dragPath: _dragPath,
865
+ dropPath: _dropPath,
866
+ rootDrop: _rootDrop,
867
+ };
868
+ _standingFiles.handle.update(_lastValues);
883
869
  }
884
870
 
885
- /** Expand or collapse one directory, listing it the first time it is opened. */
886
- async function toggleTreeDirectory(path: string): Promise<void> {
871
+ /** Repaint the Navigator, which is what brings a new projection to the mounted document. */
872
+ function repaintFiles(): void {
873
+ _filesRerender?.();
874
+ }
875
+
876
+ // ─── The panel's own verbs ───────────────────────────────────────────────────
877
+
878
+ /** Re-read every listed directory, and the `.gitignore` rules with them. */
879
+ async function refreshFileTree(): Promise<void> {
887
880
  const state = requireProjectState();
888
- if (state.expanded.has(path)) {
889
- state.expanded.delete(path);
881
+ state.dirs.clear();
882
+ /* The rules go with the listings. Refresh is what an author reaches for after editing a
883
+ `.gitignore` by hand, and a tree that came back still hiding by the old rules would read as
884
+ the button not having worked. */
885
+ resetIgnoreCache();
886
+ await loadDirectory(".");
887
+ for (const dir of state.expanded) {
888
+ await loadDirectory(dir);
889
+ }
890
+ repaintFiles();
891
+ }
892
+
893
+ /**
894
+ * What a click or Enter on a row MEANS.
895
+ *
896
+ * One verb for both kinds of row, decided here rather than in the document: a directory opens, a
897
+ * file opens in a tab, and a row whose model has since gone does nothing at all.
898
+ */
899
+ function activateFileRow(path: string): void {
900
+ const row = fileRowAt(path);
901
+ if (!row) {
890
902
  return;
891
903
  }
892
- state.expanded.add(path);
893
- if (!state.dirs.has(path)) {
894
- await loadDirectory(path);
904
+ if (row.type === "directory") {
905
+ void toggleTreeDirectory(path).then(() => repaintFiles());
906
+ return;
895
907
  }
908
+ void openFileInTab(path);
896
909
  }
897
910
 
898
- /*
899
- * There is no setupTreeKeyboard here any more, and no WeakSet of trees that already have one.
911
+ /**
912
+ * `jx-tree` says a row should be OPENED or CLOSED; this is what that means to a directory.
900
913
  *
901
- * The panel's afterRender called it after every repaint and lit re-uses the `.file-tree` element
902
- * across all of them, so the unguarded `addEventListener` it replaced accumulated one listener per
903
- * render — after ten repaints a single Down keystroke walked ten rows. The WeakSet made that safe;
904
- * `@keydown` on the element the template already renders makes it impossible, because lit owns the
905
- * binding and swaps it rather than stacking it.
914
+ * One entry point for the twisty, `ArrowRight` and `ArrowLeft` alike, because the element resolves
915
+ * all three into the state the row should be PUT INTO before it asks. The guard is still load
916
+ * bearing: a leaf's twisty box is drawn empty and still answers a click, so a file can arrive here
917
+ * asking to be expanded and must be told nothing happens.
906
918
  */
919
+ function expandFileRow(path: string, expanded: boolean): void {
920
+ const state = requireProjectState();
921
+ if (fileRowAt(path)?.type !== "directory" || state.expanded.has(path) === expanded) {
922
+ return;
923
+ }
924
+ if (!expanded) {
925
+ state.expanded.delete(path);
926
+ // It used to leave the repaint to "the caller who sets up keyboard", and there was no such
927
+ // Caller: ← changed the state and left the children on screen until something else happened to
928
+ // Redraw the panel.
929
+ repaintFiles();
930
+ return;
931
+ }
932
+ // The expansion repaints THROUGH the panel. It used to synthesise a click on the focused row to
933
+ // Get a repaint, which ran that row's own toggle a second time and only did the right thing
934
+ // Because the handler's captured `isExpanded` was already stale.
935
+ void toggleTreeDirectory(path).then(() => repaintFiles());
936
+ }
907
937
 
908
938
  /**
909
- * The tree's keyboard model: ↑↓ walk the rows, → expands, ← collapses, Enter opens.
939
+ * The reader meant that row.
910
940
  *
911
- * ↑ and ↓ step through the MODEL, not through the rendered rows. A DOM-indexed walk stopped dead at
912
- * the last row of the window — three rows past the bottom of the viewport, with thousands of files
913
- * still below it — because there was simply no next element to focus. When the step lands outside
914
- * the window the scroller moves instead, and the focus follows on the repaint ({@link
915
- * adoptFileTree}).
941
+ * The tree is single-select, so `jx-tree` has already resolved every modifier to one replace before
942
+ * this is reached. Selection follows the caret here where it used to lag behind it: the tab stop
943
+ * was computed FROM `selectedPath`, so an arrow key moved the focus and left the highlight on the
944
+ * row the reader had left.
945
+ *
946
+ * The selection is also the only thing this module remembers about where the caret IS. It does not
947
+ * need a second variable: `jx-tree` owns the caret and keeps it across every repaint that does not
948
+ * change `current`, so what the projection owes it is a SEED — a row to start on, and a row to come
949
+ * back to when the one it was on has gone.
916
950
  */
917
- function onFileTreeKeydown(e: KeyboardEvent, tree: HTMLElement): void {
918
- const focused = tree.querySelector(".file-tree-item:focus") as HTMLElement | null;
919
- if (!focused) {
951
+ function selectFileRow(path: string): void {
952
+ if (!projectState || requireProjectState().selectedPath === path) {
920
953
  return;
921
954
  }
922
- let handled = true;
955
+ requireProjectState().selectedPath = path;
956
+ repaintFiles();
957
+ }
923
958
 
924
- switch (e.key) {
925
- case "ArrowDown":
926
- case "ArrowUp": {
927
- const from = fileIndexOfPath(focused.dataset.path);
928
- focusFileRow(tree, fileStep(from, e.key === "ArrowDown" ? 1 : -1));
959
+ /**
960
+ * The caret has to reach a row the window did not draw.
961
+ *
962
+ * `jx-tree` walks the DRAWN rows and stops at the ends of the slice; when a pad says the model
963
+ * continues that way it dispatches this instead of performing anything, because where the row is
964
+ * and how far to scroll are facts about the model. Each key is answered here exactly as the element
965
+ * would have answered it over a slice that held everything.
966
+ */
967
+ function moveFileCaret(from: string, key: string): void {
968
+ const index = fileIndexOfPath(from);
969
+ let target: number;
970
+ switch (key) {
971
+ case "Home": {
972
+ target = fileStep(-1, 1);
929
973
  break;
930
974
  }
931
- case "ArrowRight": {
932
- const path = collapsedDirectoryAt(focused);
933
- if (path !== null) {
934
- // The expansion repaints THROUGH the panel. It used to synthesise a click on the focused
935
- // Row to get a repaint, which ran that row's own toggle a second time and only did the
936
- // Right thing because the handler's captured `isExpanded` was already stale.
937
- void toggleTreeDirectory(path).then(() => _filesRerender?.());
938
- }
975
+ case "End": {
976
+ target = fileStep(_fileRows.length, -1);
977
+ break;
978
+ }
979
+ case "ArrowUp": {
980
+ target = fileStep(index, -1);
939
981
  break;
940
982
  }
941
983
  case "ArrowLeft": {
942
- const path = expandedDirectoryAt(focused);
943
- if (path !== null) {
944
- requireProjectState().expanded.delete(path);
945
- // It used to leave the repaint to "the caller who sets up keyboard", and there was no such
946
- // Caller: ← changed the state and left the children on screen until something else
947
- // Happened to redraw the panel.
948
- _filesRerender?.();
949
- }
984
+ target = fileParentIndex(index);
950
985
  break;
951
986
  }
952
- case "Enter": {
953
- focused.click();
987
+ // ↓ and → both ask for the next drawn row; over the model they are the same step.
988
+ case "ArrowDown":
989
+ case "ArrowRight": {
990
+ target = fileStep(index, 1);
954
991
  break;
955
992
  }
956
993
  default: {
957
- handled = false;
994
+ return;
958
995
  }
959
996
  }
960
- if (handled) {
961
- e.preventDefault();
962
- }
997
+ focusFileRow(target);
963
998
  }
964
999
 
965
- /** The row's directory path when it is a COLLAPSED directory — what → acts on, and nothing else. */
966
- function collapsedDirectoryAt(row: HTMLElement): string | null {
967
- const { path, type } = row.dataset;
968
- return type === "directory" && path !== undefined && !requireProjectState().expanded.has(path)
969
- ? path
970
- : null;
971
- }
972
-
973
- /** The row's directory path when it is an EXPANDED directory — what ← acts on, and nothing else. */
974
- function expandedDirectoryAt(row: HTMLElement): string | null {
975
- const { path, type } = row.dataset;
976
- return type === "directory" && path !== undefined && requireProjectState().expanded.has(path)
977
- ? path
978
- : null;
1000
+ /**
1001
+ * A printable character on a windowed tree: find the model row it names, and go there.
1002
+ *
1003
+ * `jx-tree` resolves typeahead itself only when the drawn rows ARE the model; past that it
1004
+ * dispatches, and the reason is sharper than the one behind `move`. A move off the end of the slice
1005
+ * announces itself — there is nothing to land on. A letter never does: the element's search over
1006
+ * the drawn rows always answers, and over `node_modules` the answer is whichever of the eleven
1007
+ * painted rows happened to start with that letter.
1008
+ *
1009
+ * The search is the element's own, moved onto the full list: forward from the caret, wrapping once,
1010
+ * matching the row's NAME — which is the string the row draws and announces, so the caret can never
1011
+ * land somewhere the reader was not told about — and skipping the "Loading…" placeholders, which
1012
+ * are not tree items and which the arrows already step over.
1013
+ *
1014
+ * @param {string} from The row the caret is on
1015
+ * @param {string} char The character typed, lowercased
1016
+ */
1017
+ function typeaheadFileCaret(from: string, char: string): void {
1018
+ const start = fileIndexOfPath(from);
1019
+ const total = _fileRows.length;
1020
+ for (let step = 1; step <= total; step++) {
1021
+ const at = (start + step + total) % total;
1022
+ const row = _fileRows[at];
1023
+ if (row && !row.loading && row.name.trim().toLowerCase().startsWith(char)) {
1024
+ focusFileRow(at);
1025
+ return;
1026
+ }
1027
+ }
979
1028
  }
980
1029
 
981
- /** Move the keyboard to the model row at `index`, bringing it into the window if it is outside. */
982
- function focusFileRow(tree: HTMLElement, index: number): void {
1030
+ /**
1031
+ * Reveal the model row at `index` and put the caret on it.
1032
+ *
1033
+ * The SELECTION moves with it, and that is not a flourish: `jx-tree` raises `select` alongside
1034
+ * `change` on every arrow it can perform itself, so a step the window could not satisfy must not be
1035
+ * the one step that silently does not. It is also what moves the CARET, because the projection
1036
+ * seeds `currentPath` from the selection — and that write is the whole of this panel's side of the
1037
+ * handoff.
1038
+ *
1039
+ * **The keyboard is deliberately not touched here.** This is the answer to a `move` or a
1040
+ * `typeahead` the tree could not perform, and `jx-tree` keeps the keyboard across both: it focuses
1041
+ * the caret row once its own sync has written the roving `tabindex` onto the revealed element,
1042
+ * which is the only moment focusing it does anything. What this function used to do instead was
1043
+ * pend the path and spend the request from `onNodeCreated` — one reconcile step before the row had
1044
+ * a `tabindex` at all — so the `focus()` was a silent no-op and the caret jump never landed.
1045
+ */
1046
+ function focusFileRow(index: number): void {
983
1047
  const row = _fileRows[index];
984
1048
  if (!row) {
985
1049
  return;
986
1050
  }
987
- const el = fileRowElement(tree, row.path);
988
- if (el) {
989
- el.focus();
1051
+ selectFileRow(row.path);
1052
+ if (fileRowElement(row.path)) {
1053
+ return;
1054
+ }
1055
+ revealListRow(_fileList, index, fileRowHeight());
1056
+ repaintFiles();
1057
+ }
1058
+
1059
+ /** Expand or collapse one directory, listing it the first time it is opened. */
1060
+ async function toggleTreeDirectory(path: string): Promise<void> {
1061
+ const state = requireProjectState();
1062
+ if (state.expanded.has(path)) {
1063
+ state.expanded.delete(path);
990
1064
  return;
991
1065
  }
992
- if (revealListRow(_fileList, index, fileRowHeight())) {
993
- _pendingFocusPath = row.path;
994
- _filesRerender?.();
1066
+ state.expanded.add(path);
1067
+ if (!state.dirs.has(path)) {
1068
+ await loadDirectory(path);
995
1069
  }
996
1070
  }
997
1071
 
998
- let _fileTreeDndCleanups: (() => void)[] = [];
1072
+ // ─── Drag and drop: the island the document draws a home for ─────────────────
1073
+
1074
+ /**
1075
+ * What is registered against each drawn row, so it can be released when the row leaves the window.
1076
+ *
1077
+ * Keyed by the ELEMENT rather than by the path: a windowed list re-uses nodes, and the question
1078
+ * this map answers is "has this node's registration already been taken back", which is about the
1079
+ * node.
1080
+ */
1081
+ const _rowDnd = new Map<HTMLElement, () => void>();
1082
+ /** What is registered against the tree itself: the project root's two drop targets, and the monitor. */
1083
+ let _treeDnd: { element: HTMLElement; cleanup: () => void } | null = null;
1084
+ /** The row being dragged, the row a drag is over, and whether the background is. */
1085
+ let _dragPath = "";
1086
+ /**
1087
+ * The row the pointer is over, whether or not it will take the drop.
1088
+ *
1089
+ * Two facts, not one, because the tree background is a drop target that CONTAINS every row: a
1090
+ * refused row still has to occlude it, or a drop the row said no to lands in the project root.
1091
+ * {@link _dropPath} is the row that will take the drop; this is the row that is in the way.
1092
+ */
1093
+ let _overRow = "";
1094
+ let _dropPath = "";
1095
+ /** Whether the tree background is under the drag; {@link _rootDrop} is what that projects to. */
1096
+ let _overRoot = false;
1097
+ let _rootDrop = "";
999
1098
 
1000
1099
  /** Whether a drag carries OS files (as opposed to a pragmatic in-app drag). */
1001
1100
  export function isFileDrag(e: DragEvent): boolean {
@@ -1003,15 +1102,19 @@ export function isFileDrag(e: DragEvent): boolean {
1003
1102
  }
1004
1103
 
1005
1104
  /**
1006
- * Attach external-file drop handling to one tree row. Pragmatic-dnd only sees pragmatic sources, so
1105
+ * Attach external-file drop handling to one element. Pragmatic-dnd only sees pragmatic sources, so
1007
1106
  * an OS file drag needs the native listeners; `dir` is where a drop lands (the row itself for a
1008
1107
  * directory, its parent for a file, `.` for the tree background).
1108
+ *
1109
+ * The affordance is reported rather than drawn: `setActive` writes the state the document renders
1110
+ * from, where this used to add and remove a class. That is the same correction the Library made — a
1111
+ * highlight a handler adds is a highlight another handler has to remember to take away, and a drag
1112
+ * that left the window never fired the handler that would have.
1009
1113
  */
1010
1114
  function registerFileDropTarget(
1011
1115
  element: HTMLElement,
1012
1116
  dir: string,
1013
- activeClass: string,
1014
- renderLeftPanel: () => void,
1117
+ setActive: (active: boolean) => void,
1015
1118
  ): () => void {
1016
1119
  const onDragOver = (e: DragEvent) => {
1017
1120
  if (!isFileDrag(e)) {
@@ -1022,18 +1125,18 @@ function registerFileDropTarget(
1022
1125
  if (e.dataTransfer) {
1023
1126
  e.dataTransfer.dropEffect = "copy";
1024
1127
  }
1025
- element.classList.add(activeClass);
1128
+ setActive(true);
1026
1129
  };
1027
- const onDragLeave = () => element.classList.remove(activeClass);
1130
+ const onDragLeave = () => setActive(false);
1028
1131
  const onDrop = (e: DragEvent) => {
1029
- element.classList.remove(activeClass);
1132
+ setActive(false);
1030
1133
  const files = e.dataTransfer?.files;
1031
1134
  if (!files?.length) {
1032
1135
  return;
1033
1136
  }
1034
1137
  e.preventDefault();
1035
1138
  e.stopPropagation();
1036
- void uploadFilesToDir(files, dir, renderLeftPanel);
1139
+ void uploadFilesToDir(files, dir, repaintFiles);
1037
1140
  };
1038
1141
  element.addEventListener("dragover", onDragOver);
1039
1142
  element.addEventListener("dragleave", onDragLeave);
@@ -1045,6 +1148,72 @@ function registerFileDropTarget(
1045
1148
  };
1046
1149
  }
1047
1150
 
1151
+ /**
1152
+ * Whether the tree will move `srcPath` into `targetDir` — the ONE predicate behind every answer the
1153
+ * drag gives: which rows light up, which drops the monitor performs, and whether the background
1154
+ * offers the project root.
1155
+ *
1156
+ * Four refusals, and the third is the one nothing used to say. A directory is not a place inside
1157
+ * itself; an entry already in a directory (at any depth) has nowhere to go by being dropped on it;
1158
+ * a directory may not be moved into its own descendant, which is a rename onto a path underneath
1159
+ * the thing being renamed and which the tree happily offered until the server answered 500; and an
1160
+ * entry already directly in the target is a no-op — the case that spelled `.` for the root.
1161
+ *
1162
+ * Both sides are normalised first: `assets\logo.png` and `assets/logo.png` name one entry, and a
1163
+ * predicate that agreed with itself only on one of the two spellings is a predicate with a hole.
1164
+ */
1165
+ export function canMoveInto(srcPath: string, targetDir: string): boolean {
1166
+ const src = srcPath.replaceAll("\\", "/");
1167
+ const dir = targetDir.replaceAll("\\", "/");
1168
+ if (!src || src === dir) {
1169
+ return false;
1170
+ }
1171
+ if (src.startsWith(`${dir}/`) || dir.startsWith(`${src}/`)) {
1172
+ return false;
1173
+ }
1174
+ return parentDir(src) !== dir;
1175
+ }
1176
+
1177
+ /** {@link canMoveInto} for a ROW: only a directory has an inside to move something into. */
1178
+ function acceptsDrop(srcPath: unknown, targetPath: string, targetType: string): boolean {
1179
+ return (
1180
+ targetType === "directory" && typeof srcPath === "string" && canMoveInto(srcPath, targetPath)
1181
+ );
1182
+ }
1183
+
1184
+ /**
1185
+ * Say which row the drag is over and whether that row will take it, and let the document redraw.
1186
+ *
1187
+ * The root affordance is DERIVED here rather than set alongside: a drag over a row is never also a
1188
+ * drag over the background, and the two flags used to be written independently — so a row that
1189
+ * refused the drop left the tree lit up saying the project root would take it, which after the
1190
+ * refusal became final is no longer true either.
1191
+ */
1192
+ function setRowUnderDrag(row: string, accepted: boolean): void {
1193
+ const dropPath = accepted ? row : "";
1194
+ if (_overRow === row && _dropPath === dropPath) {
1195
+ return;
1196
+ }
1197
+ _overRow = row;
1198
+ _dropPath = dropPath;
1199
+ syncRootDrop();
1200
+ }
1201
+
1202
+ /** Say whether a drag is over the tree background, which is the project root. */
1203
+ function setRootUnderDrag(active: boolean): void {
1204
+ if (_overRoot === active) {
1205
+ return;
1206
+ }
1207
+ _overRoot = active;
1208
+ syncRootDrop();
1209
+ }
1210
+
1211
+ /** Recompute the background's affordance from the two facts, and project both. */
1212
+ function syncRootDrop(): void {
1213
+ _rootDrop = _overRoot && _overRow === "" ? "true" : "";
1214
+ syncFilesDragState();
1215
+ }
1216
+
1048
1217
  /**
1049
1218
  * Upload files into `dir` and reveal them: expand the target directory so the new entries are
1050
1219
  * visible. The listing refresh itself runs in the shared post-upload handler.
@@ -1066,7 +1235,7 @@ export async function uploadFilesToDir(
1066
1235
 
1067
1236
  /**
1068
1237
  * Open the OS file picker and upload the choice into `dir` (the tree's "Upload Files…" item). The
1069
- * input is created per invocation and discarded after — the tree template is re-rendered often.
1238
+ * input is created per invocation and discarded after — the tree is re-rendered often.
1070
1239
  */
1071
1240
  export function pickAndUploadTo(dir: string, renderLeftPanel: () => void): void {
1072
1241
  const input = document.createElement("input");
@@ -1082,158 +1251,181 @@ export function pickAndUploadTo(dir: string, renderLeftPanel: () => void): void
1082
1251
  }
1083
1252
 
1084
1253
  /**
1085
- * Register drag-and-drop on file tree items. Called after each file tree render.
1254
+ * Adopt one row element the document has just created: remember it, make it a drag source, and give
1255
+ * it the two drop behaviours its KIND earns.
1086
1256
  *
1087
- * @param {{ renderLeftPanel: () => void }} ctx
1257
+ * Every row is a source, an external-file target and an in-app target. Only a DIRECTORY accepts an
1258
+ * in-app drop, because a file has no inside to move something into — but a file row registers the
1259
+ * target anyway and refuses in its data, because a row that is not a target at all is a row the
1260
+ * drop falls straight through, onto the tree, which is the project root. The registration happens
1261
+ * as the node is created, which is the one moment at which "this element is that path" is certainly
1262
+ * true.
1088
1263
  */
1089
- export function registerFileTreeDnD({ renderLeftPanel }: { renderLeftPanel: () => void }) {
1090
- // Clean up previous registrations
1091
- for (const fn of _fileTreeDndCleanups) {
1092
- fn();
1093
- }
1094
- _fileTreeDndCleanups = [];
1095
-
1096
- requestAnimationFrame(() => {
1097
- const tree = document.querySelector(".file-tree") as HTMLElement | null;
1098
- if (!tree) {
1099
- return;
1100
- }
1101
-
1102
- const items = tree.querySelectorAll(".file-tree-item") as NodeListOf<HTMLElement>;
1103
-
1104
- for (const row of items) {
1105
- const { path } = row.dataset;
1106
- const { type } = row.dataset;
1107
- if (!path) {
1108
- continue;
1109
- }
1110
-
1111
- const cleanups = [
1112
- draggable({
1113
- element: row,
1114
- getInitialData() {
1115
- return { entryType: type, path, type: "file-tree" };
1116
- },
1117
- onDragStart() {
1118
- row.classList.add("dragging");
1119
- },
1120
- onDrop() {
1121
- row.classList.remove("dragging");
1122
- },
1123
- }),
1124
- // Files dropped from the OS land in the row's own directory; a file row targets its parent
1125
- // So dropping next to a sibling puts the upload beside it.
1126
- registerFileDropTarget(
1127
- row,
1128
- type === "directory" ? path : parentDir(path),
1129
- "drag-over",
1130
- renderLeftPanel,
1131
- ),
1132
- ];
1133
-
1134
- if (type === "directory") {
1135
- cleanups.push(
1136
- dropTargetForElements({
1137
- canDrop({ source }) {
1138
- if (source.data.type !== "file-tree") {
1139
- return false;
1140
- }
1141
- const srcPath = source.data.path as string;
1142
- if (srcPath === path) {
1143
- return false;
1144
- }
1145
- if (srcPath.startsWith(`${path}/`)) {
1146
- return false;
1147
- }
1148
- const srcParent = parentDir(srcPath);
1149
- if (srcParent === path) {
1150
- return false;
1151
- }
1152
- return true;
1153
- },
1154
- element: row,
1155
- getData() {
1156
- return { targetDir: path, type: "file-tree-target" };
1157
- },
1158
- onDrag() {
1159
- if (!row.classList.contains("drag-over")) {
1160
- row.classList.add("drag-over");
1161
- }
1162
- },
1163
- onDragEnter() {
1164
- row.classList.add("drag-over");
1165
- },
1166
- onDragLeave() {
1167
- row.classList.remove("drag-over");
1168
- },
1169
- onDrop() {
1170
- row.classList.remove("drag-over");
1171
- },
1172
- }),
1173
- );
1174
- }
1175
-
1176
- _fileTreeDndCleanups.push(combine(...cleanups));
1177
- }
1178
-
1179
- // Root-level drop target (move to project root)
1180
- const rootCleanup = dropTargetForElements({
1264
+ function adoptFileRow(element: HTMLElement, path: string, type: string): void {
1265
+ releaseRowDnD(element);
1266
+ _fileRowEls.set(path, element);
1267
+
1268
+ const cleanups = [
1269
+ draggable({
1270
+ element,
1271
+ getInitialData() {
1272
+ return { entryType: type, path, type: "file-tree" };
1273
+ },
1274
+ onDragStart() {
1275
+ _dragPath = path;
1276
+ syncFilesDragState();
1277
+ },
1278
+ onDrop() {
1279
+ _dragPath = "";
1280
+ setRowUnderDrag("", false);
1281
+ syncFilesDragState();
1282
+ },
1283
+ }),
1284
+ // Files dropped from the OS land in the row's own directory; a file row targets its parent so
1285
+ // Dropping next to a sibling puts the upload beside it.
1286
+ registerFileDropTarget(element, type === "directory" ? path : parentDir(path), (active) => {
1287
+ setRowUnderDrag(active ? path : "", active);
1288
+ }),
1289
+ /**
1290
+ * The in-app target — on EVERY row, accepting or not.
1291
+ *
1292
+ * A row that answered `canDrop: false` was not a drop target at all, and pragmatic-dnd
1293
+ * documents what happens next: "blocking dropping on a drop target will not block dropping on
1294
+ * child or parent drop targets". The next target up is the tree element, whose target IS the
1295
+ * project root — so a refused drop became a move to the root, silently, with no affordance
1296
+ * anywhere on screen to warn the reader it would. Answering `true` and carrying the verdict in
1297
+ * the DATA keeps the innermost target innermost, which is what makes a refusal final.
1298
+ */
1299
+ dropTargetForElements({
1181
1300
  canDrop({ source }) {
1182
- if (source.data.type !== "file-tree") {
1183
- return false;
1184
- }
1185
- const srcPath = source.data.path as string;
1186
- return parentDir(srcPath) !== ".";
1301
+ return source.data.type === "file-tree";
1187
1302
  },
1188
- element: tree,
1189
- getData() {
1190
- return { targetDir: ".", type: "file-tree-target" };
1303
+ element,
1304
+ getData({ source }) {
1305
+ return acceptsDrop(source.data.path, path, type)
1306
+ ? { targetDir: path, type: "file-tree-target" }
1307
+ : { type: "file-tree-refused" };
1191
1308
  },
1192
- onDragEnter() {
1193
- tree.classList.add("drag-over-root");
1309
+ onDrag({ source }) {
1310
+ setRowUnderDrag(path, acceptsDrop(source.data.path, path, type));
1311
+ },
1312
+ onDragEnter({ source }) {
1313
+ setRowUnderDrag(path, acceptsDrop(source.data.path, path, type));
1194
1314
  },
1195
1315
  onDragLeave() {
1196
- tree.classList.remove("drag-over-root");
1316
+ setRowUnderDrag("", false);
1197
1317
  },
1198
1318
  onDrop() {
1199
- tree.classList.remove("drag-over-root");
1319
+ setRowUnderDrag("", false);
1200
1320
  },
1201
- });
1202
- // The tree background is the project root's drop target for OS files. Row handlers
1203
- // StopPropagation, so a drop on a row never also fires here.
1204
- _fileTreeDndCleanups.push(
1205
- rootCleanup,
1206
- registerFileDropTarget(tree, ".", "drag-over-root", renderLeftPanel),
1207
- );
1321
+ }),
1322
+ ];
1208
1323
 
1209
- // Monitor for drop events
1210
- const monitorCleanup = monitorForElements({
1211
- onDrop({ source, location }) {
1212
- const [target] = location.current.dropTargets;
1213
- if (!target) {
1214
- return;
1215
- }
1216
- if (source.data.type !== "file-tree") {
1217
- return;
1218
- }
1219
- if (target.data.type !== "file-tree-target") {
1220
- return;
1221
- }
1324
+ _rowDnd.set(element, combine(...cleanups));
1325
+ }
1222
1326
 
1223
- const srcPath = source.data.path as string;
1224
- const targetDirPath = target.data.targetDir as string;
1225
- const fileName = srcPath.split("/").pop();
1226
- const newPath = targetDirPath === "." ? fileName : `${targetDirPath}/${fileName}`;
1327
+ /** Take back everything registered against one row element. */
1328
+ function releaseRowDnD(element: HTMLElement): void {
1329
+ const cleanup = _rowDnd.get(element);
1330
+ if (cleanup) {
1331
+ cleanup();
1332
+ _rowDnd.delete(element);
1333
+ }
1334
+ }
1227
1335
 
1228
- if (newPath === srcPath) {
1229
- return;
1230
- }
1336
+ /**
1337
+ * Adopt the tree element: the window's scroller, the project root's drop target, and the monitor
1338
+ * that turns a completed drag into a move.
1339
+ *
1340
+ * Registered once, against the element the document created. The pass this replaced ran on every
1341
+ * repaint and re-registered every row from scratch, which is what made a drag mid-scroll drop its
1342
+ * own sources.
1343
+ */
1344
+ function adoptFileTreeElement(element: HTMLElement): void {
1345
+ if (_treeDnd?.element === element) {
1346
+ return;
1347
+ }
1348
+ releaseFileTreeDnD();
1349
+ _fileList = element;
1231
1350
 
1232
- void moveFileEntry(srcPath, newPath!, renderLeftPanel);
1233
- },
1234
- });
1235
- _fileTreeDndCleanups.push(monitorCleanup);
1351
+ /* The background keeps an honest `canDrop`: it is the OUTERMOST target, so there is nothing
1352
+ inside it for a refusal here to leak to. Its affordance is suppressed while a row is under the
1353
+ pointer — {@link syncRootDrop} — because the row is what the drop will reach. */
1354
+ const rootCleanup = dropTargetForElements({
1355
+ canDrop({ source }) {
1356
+ return source.data.type === "file-tree" && canMoveInto(source.data.path as string, ".");
1357
+ },
1358
+ element,
1359
+ getData() {
1360
+ return { targetDir: ".", type: "file-tree-target" };
1361
+ },
1362
+ onDragEnter() {
1363
+ setRootUnderDrag(true);
1364
+ },
1365
+ onDragLeave() {
1366
+ setRootUnderDrag(false);
1367
+ },
1368
+ onDrop() {
1369
+ setRootUnderDrag(false);
1370
+ },
1236
1371
  });
1372
+
1373
+ const monitorCleanup = monitorForElements({
1374
+ onDrop({ source, location }) {
1375
+ const [target] = location.current.dropTargets;
1376
+ if (!target) {
1377
+ return;
1378
+ }
1379
+ if (source.data.type !== "file-tree") {
1380
+ return;
1381
+ }
1382
+ /* The INNERMOST target and no other. `dropTargets` is bubble-ordered, so reading [0] and
1383
+ then refusing what it says is what keeps a row's "no" from becoming the tree's "yes". */
1384
+ if (target.data.type !== "file-tree-target") {
1385
+ return;
1386
+ }
1387
+
1388
+ const srcPath = source.data.path as string;
1389
+ const targetDirPath = target.data.targetDir as string;
1390
+ if (!canMoveInto(srcPath, targetDirPath)) {
1391
+ return;
1392
+ }
1393
+ const fileName = srcPath.split("/").pop();
1394
+ const newPath = targetDirPath === "." ? fileName : `${targetDirPath}/${fileName}`;
1395
+
1396
+ void moveFileEntry(srcPath, newPath!, repaintFiles);
1397
+ },
1398
+ });
1399
+
1400
+ _treeDnd = {
1401
+ cleanup: combine(
1402
+ rootCleanup,
1403
+ monitorCleanup,
1404
+ // The tree background is the project root's drop target for OS files. Row handlers
1405
+ // StopPropagation, so a drop on a row never also fires here.
1406
+ registerFileDropTarget(element, ".", setRootUnderDrag),
1407
+ ),
1408
+ element,
1409
+ };
1410
+ adoptFileTree();
1411
+ }
1412
+
1413
+ /** Take back the tree's own registrations and its scroll watch. */
1414
+ function releaseFileTreeDnD(): void {
1415
+ _treeDnd?.cleanup();
1416
+ _treeDnd = null;
1417
+ for (const cleanup of _rowDnd.values()) {
1418
+ cleanup();
1419
+ }
1420
+ _rowDnd.clear();
1421
+ _fileWatch?.window.destroy();
1422
+ _fileWatch = null;
1423
+ _fileList = null;
1424
+ _dragPath = "";
1425
+ _overRow = "";
1426
+ _dropPath = "";
1427
+ _overRoot = false;
1428
+ _rootDrop = "";
1237
1429
  }
1238
1430
 
1239
1431
  /**
@@ -1297,23 +1489,11 @@ function parentDir(path: string) {
1297
1489
 
1298
1490
  // ─── Context menu ─────────────────────────────────────────────────────────────
1299
1491
 
1300
- let _fileCtxHandle: ReturnType<typeof renderPopover> | null = null;
1492
+ let _fileMenu: MenuHandle | null = null;
1301
1493
 
1302
- function dismissFileContextMenu() {
1303
- if (_fileCtxHandle) {
1304
- _fileCtxHandle.dismiss();
1305
- _fileCtxHandle = null;
1306
- }
1307
- }
1308
-
1309
- /** One row of the file menu. The divider is the em-dash label; `disabled` rows explain themselves. */
1310
- interface FileMenuItem {
1311
- label: string;
1312
- action?: () => void;
1313
- danger?: boolean;
1314
- disabled?: boolean;
1315
- /** The `requires` sentence, printed under a disabled row. */
1316
- reason?: string;
1494
+ function dismissFileContextMenu(): void {
1495
+ _fileMenu?.close();
1496
+ _fileMenu = null;
1317
1497
  }
1318
1498
 
1319
1499
  /**
@@ -1361,6 +1541,16 @@ function fileRowFacts(entry: { path: string; type: string }): Record<string, unk
1361
1541
  return facts;
1362
1542
  }
1363
1543
 
1544
+ /** One of the tree's OWN verbs, as the kit menu reads a row. */
1545
+ function treeMenuRow(
1546
+ id: string,
1547
+ title: string,
1548
+ run: () => void,
1549
+ extra: Partial<MenuRowProjection> = {},
1550
+ ): MenuRowProjection {
1551
+ return { destructive: false, disabled: false, dividerAbove: false, id, run, title, ...extra };
1552
+ }
1553
+
1364
1554
  /**
1365
1555
  * The declared `context/file` commands this row can offer.
1366
1556
  *
@@ -1368,13 +1558,13 @@ function fileRowFacts(entry: { path: string; type: string }): Record<string, unk
1368
1558
  * `group`), whether it is enabled and the sentence saying why not. Nothing here names a command, so
1369
1559
  * a new `context/file` record appears in the tree with no edit to this file.
1370
1560
  */
1371
- function placedFileItems(entry: { path: string; type: string }): FileMenuItem[] {
1561
+ function placedFileRows(entry: { path: string; type: string }): MenuRowProjection[] {
1372
1562
  const registry = activeRegistry();
1373
1563
  if (!registry) {
1374
1564
  return [];
1375
1565
  }
1376
1566
  const facts = fileRowFacts(entry);
1377
- const items: FileMenuItem[] = [];
1567
+ const rows: MenuRowProjection[] = [];
1378
1568
  for (const command of registry.forPlacement("context/file")) {
1379
1569
  const schema = command.args as
1380
1570
  | { properties?: Record<string, unknown>; required?: readonly string[] }
@@ -1389,128 +1579,111 @@ function placedFileItems(entry: { path: string; type: string }): FileMenuItem[]
1389
1579
  }
1390
1580
  }
1391
1581
  const reason = registry.disabledReason(command.id);
1392
- items.push(
1582
+ rows.push(
1393
1583
  reason === undefined
1394
- ? {
1395
- action: () => {
1396
- void registry.run(command.id, args);
1397
- },
1398
- label: command.title,
1399
- }
1400
- : { disabled: true, label: command.title, reason },
1584
+ ? treeMenuRow(command.id, command.title, () => {
1585
+ void registry.run(command.id, args);
1586
+ })
1587
+ : {
1588
+ destructive: false,
1589
+ disabled: true,
1590
+ dividerAbove: false,
1591
+ id: command.id,
1592
+ // A disabled row says what it needs, the same sentence the palette and the agent
1593
+ // Print — `requires`, off the record, never re-worded here.
1594
+ requires: reason,
1595
+ title: command.title,
1596
+ },
1401
1597
  );
1402
1598
  }
1403
- return items;
1599
+ return rows;
1404
1600
  }
1405
1601
 
1406
- function showFileContextMenu(
1407
- e: MouseEvent,
1408
- entry: { name: string; path: string; type: string },
1409
- ctx: { openFileFn: (path: string) => void; renderLeftPanel: () => void },
1410
- ) {
1411
- e.preventDefault();
1412
- dismissFileContextMenu();
1602
+ /**
1603
+ * Everything one row can be asked to do, in the order it is offered.
1604
+ *
1605
+ * The declared rows sit between what the TREE does to a file (open it, create in it, upload to it)
1606
+ * and what it does to the file's existence (rename, delete) — and the boundary between the last two
1607
+ * groups is the `dividerAbove` on Rename, which is what the `"—"` sentinel row used to stand for.
1608
+ */
1609
+ function fileMenuRows(entry: { name: string; path: string; type: string }): MenuRowProjection[] {
1413
1610
  const isDir = entry.type === "directory";
1414
-
1415
- const items: FileMenuItem[] = [];
1416
-
1417
- if (!isDir) {
1418
- items.push({ action: () => ctx.openFileFn(entry.path), label: "Open" });
1419
- }
1611
+ const rows: MenuRowProjection[] = [];
1420
1612
  if (isDir) {
1421
- items.push(
1422
- {
1423
- action: () => createNewFile(entry.path, ctx.renderLeftPanel),
1424
- label: "New File\u2026",
1425
- },
1426
- {
1427
- action: () => pickAndUploadTo(entry.path, ctx.renderLeftPanel),
1428
- label: "Upload Files\u2026",
1429
- },
1613
+ rows.push(
1614
+ treeMenuRow("files.newFile", "New File\u2026", () => {
1615
+ void createNewFile(entry.path, repaintFiles);
1616
+ }),
1617
+ treeMenuRow("files.upload", "Upload Files\u2026", () => {
1618
+ pickAndUploadTo(entry.path, repaintFiles);
1619
+ }),
1430
1620
  );
1431
1621
  if (entry.path === "pages" || entry.path.endsWith("/pages")) {
1432
1622
  // The one hand-built row left: no command declares "open the pages grid". `grid-open.ts`'s
1433
1623
  // `collection.editInGrid` has no pages sibling, so there is nothing here to render yet.
1434
- items.push({
1435
- action: () => {
1624
+ rows.push(
1625
+ treeMenuRow("files.pagesGrid", "Edit Pages in Grid", () => {
1436
1626
  openPagesGrid();
1437
- },
1438
- label: "Edit Pages in Grid",
1439
- });
1627
+ }),
1628
+ );
1440
1629
  }
1630
+ } else {
1631
+ rows.push(
1632
+ treeMenuRow("files.open", "Open", () => {
1633
+ void openFileInTab(entry.path);
1634
+ }),
1635
+ );
1441
1636
  }
1442
- items.push(
1443
- // The declared rows sit between what the TREE does to a file (open it, create in it, upload to
1444
- // It) and what it does to the file's existence (rename, delete).
1445
- ...placedFileItems(entry),
1446
- { label: "\u2014" },
1447
- {
1448
- action: () => renameFile(entry, ctx.renderLeftPanel),
1449
- label: "Rename\u2026",
1450
- },
1451
- {
1452
- action: () => deleteFile(entry, ctx.renderLeftPanel),
1453
- danger: true,
1454
- label: "Delete",
1455
- },
1637
+ rows.push(
1638
+ ...placedFileRows(entry),
1639
+ treeMenuRow(
1640
+ "files.rename",
1641
+ "Rename\u2026",
1642
+ () => {
1643
+ void renameFile(entry, repaintFiles);
1644
+ },
1645
+ { dividerAbove: true },
1646
+ ),
1647
+ treeMenuRow(
1648
+ "files.delete",
1649
+ "Delete",
1650
+ () => {
1651
+ void deleteFile(entry, repaintFiles);
1652
+ },
1653
+ { destructive: true },
1654
+ ),
1456
1655
  );
1656
+ return rows;
1657
+ }
1457
1658
 
1458
- let x = e.clientX;
1459
- let y = e.clientY;
1460
-
1461
- _fileCtxHandle = renderPopover(
1462
- html`<sp-popover
1463
- open
1464
- style="position:fixed;z-index:10000;left:${x}px;top:${y}px"
1465
- ${ref((el) => {
1466
- if (!el) {
1467
- return;
1468
- }
1469
- requestAnimationFrame(() => {
1470
- const popover = el as HTMLElement;
1471
- const menuRect = rectOf(popover);
1472
- if (x + menuRect.width > window.innerWidth) {
1473
- x = window.innerWidth - menuRect.width - 4;
1474
- }
1475
- if (y + menuRect.height > window.innerHeight) {
1476
- y = window.innerHeight - menuRect.height - 4;
1477
- }
1478
- popover.style.left = `${x}px`;
1479
- popover.style.top = `${y}px`;
1480
- });
1481
- })}
1482
- >
1483
- <sp-menu>
1484
- ${items.map((item) =>
1485
- item.label === "\u2014"
1486
- ? html`<sp-menu-divider></sp-menu-divider>`
1487
- : html`<sp-menu-item
1488
- style=${item.danger ? "color: var(--danger)" : ""}
1489
- ?disabled=${item.disabled === true}
1490
- aria-disabled=${item.disabled === true ? "true" : "false"}
1491
- @click=${() => {
1492
- if (item.disabled === true) {
1493
- return;
1494
- }
1495
- dismissFileContextMenu();
1496
- void item.action?.();
1497
- }}
1498
- >${item.label}${
1499
- // A disabled row says what it needs, the same sentence the palette and the agent
1500
- // Print — `requires`, off the record, never re-worded here.
1501
- item.reason ? html`<span slot="description">Needs ${item.reason}</span>` : nothing
1502
- }</sp-menu-item
1503
- >`,
1504
- )}
1505
- </sp-menu>
1506
- </sp-popover>`,
1507
- {
1508
- dismissOnOutsideClick: true,
1509
- onDismiss: () => {
1510
- _fileCtxHandle = null;
1511
- },
1659
+ /**
1660
+ * Open the file menu at the pointer.
1661
+ *
1662
+ * The KIT menu, not a popover of this module's own: `openMenu()` owns the panel, the roving focus,
1663
+ * the typeahead, the light dismissal and Escape, and it is the answer this shell already settled on
1664
+ * (§8.4). What went with the `sp-popover` it replaces is the hand-written clamp — a `ref` that
1665
+ * measured the panel a frame after it opened and moved it back inside the viewport — because the
1666
+ * kit does that for every menu instead of this one doing it for itself.
1667
+ */
1668
+ function showFileContextMenu(path: string, x: number, y: number): void {
1669
+ const row = fileRowAt(path);
1670
+ if (!row) {
1671
+ return;
1672
+ }
1673
+ dismissFileContextMenu();
1674
+ const opener = fileRowElement(path);
1675
+ _fileMenu = openMenu({
1676
+ label: "File actions",
1677
+ onClosed: (handle) => {
1678
+ if (_fileMenu === handle) {
1679
+ _fileMenu = null;
1680
+ }
1512
1681
  },
1513
- );
1682
+ opener,
1683
+ origin: { x, y },
1684
+ region: "files",
1685
+ rows: fileMenuRows({ name: row.name, path: row.path, type: row.type }),
1686
+ });
1514
1687
  }
1515
1688
 
1516
1689
  // ─── File CRUD ────────────────────────────────────────────────────────────────
@@ -2174,13 +2347,16 @@ export async function openFileInTab(path: string, opts: OpenFileOpts = {}) {
2174
2347
  await loadFormats();
2175
2348
  let document: Record<string, unknown>;
2176
2349
  let frontmatter: Record<string, unknown> | undefined;
2350
+ // The layout the JSON was written in, so a save reproduces it (`json-layout.ts`, issue 308). A
2351
+ // Format-class file has none: its serializer owns its layout.
2352
+ let layout: JsonLayout | null = null;
2177
2353
  const format = formatForPath(path);
2178
2354
  if (format) {
2179
2355
  const result = await parseSourceForPath(path, content);
2180
2356
  ({ document } = result);
2181
2357
  ({ frontmatter } = result);
2182
2358
  } else if (path.endsWith(".json")) {
2183
- document = JSON.parse(content) as Record<string, unknown>;
2359
+ ({ document, layout } = parseJsonDocument(content));
2184
2360
  } else {
2185
2361
  throw noFormatError(path);
2186
2362
  }
@@ -2191,6 +2367,7 @@ export async function openFileInTab(path: string, opts: OpenFileOpts = {}) {
2191
2367
  documentPath: path,
2192
2368
  document,
2193
2369
  ...(frontmatter != null && { frontmatter }),
2370
+ layout,
2194
2371
  sourceFormat: format?.name ?? null,
2195
2372
  ...(opts.paneId !== undefined && { paneId: opts.paneId }),
2196
2373
  ...(opts.preview === true && { preview: true }),
@@ -2263,7 +2440,10 @@ export async function reloadFileInTab(path: string) {
2263
2440
  tab.doc.document = document;
2264
2441
  tab.doc.content.frontmatter = frontmatter;
2265
2442
  } else if (path.endsWith(".json")) {
2266
- tab.doc.document = JSON.parse(content) as JxMutableNode;
2443
+ // The file changed under the tab, so its layout is whatever the new text says.
2444
+ const parsed = parseJsonDocument(content);
2445
+ tab.doc.document = parsed.document as JxMutableNode;
2446
+ tab.doc.layout = parsed.layout;
2267
2447
  }
2268
2448
  tab.doc.dirty = false;
2269
2449
  } catch (error) {
@@ -2293,10 +2473,113 @@ export function registerFilesPanel(): void {
2293
2473
  title: "Files",
2294
2474
  level: "project",
2295
2475
  dock: "navigator",
2296
- icon: "sp-icon-folder",
2297
- render: (ctx) => ctx.deps.renderFilesTemplate(),
2298
- afterRender: (ctx) => {
2299
- ctx.deps.registerFileTreeDnD({ renderLeftPanel: ctx.rerender });
2476
+ icon: "folder",
2477
+ // The body is a document, so lit draws nothing and the mount happens against the painted DOM.
2478
+ // `afterRender` runs on every repaint; {@link mountFilesPanel} is idempotent.
2479
+ render: () => nothing,
2480
+ afterRender: (ctx, host) => {
2481
+ mountFilesPanel(host, ctx.rerender);
2300
2482
  },
2301
2483
  });
2302
2484
  }
2485
+
2486
+ // ─── The mount ───────────────────────────────────────────────────────────────
2487
+
2488
+ /** Everything a control on the surface can ask for, defined once. */
2489
+ const FILE_ACTIONS: FilesPanelActions = {
2490
+ activate: activateFileRow,
2491
+ contextMenu: showFileContextMenu,
2492
+ expand: expandFileRow,
2493
+ move: moveFileCaret,
2494
+ newFile: () => {
2495
+ void createNewFile(".", repaintFiles);
2496
+ },
2497
+ openProject: () => {
2498
+ /* The DECLARED command, run through the registry — never a second opener of this surface's own
2499
+ (§12.5). It is the one the ⌘O chord, the palette and the status bar's PROJECT field already
2500
+ run, and it is the only one that knows about the picker modal and the "new window" target. */
2501
+ void activeRegistry()?.run("project.open");
2502
+ },
2503
+ refresh: () => {
2504
+ void refreshFileTree();
2505
+ },
2506
+ rowHost: adoptFileRow,
2507
+ search: (value) => {
2508
+ requireProjectState().searchQuery = value;
2509
+ repaintFiles();
2510
+ },
2511
+ select: selectFileRow,
2512
+ toggleIgnored: () => {
2513
+ /* A repaint and nothing else: the ignored entries were never dropped from `projectState.dirs`,
2514
+ only from the rows built out of it. */
2515
+ setShowIgnoredFiles(!showIgnoredFiles());
2516
+ repaintFiles();
2517
+ },
2518
+ treeHost: adoptFileTreeElement,
2519
+ typeahead: typeaheadFileCaret,
2520
+ };
2521
+
2522
+ /** The mounted document, and the node it was mounted into. */
2523
+ let _standingFiles: { handle: FilesPanelSurfaceHandle; host: HTMLElement } | null = null;
2524
+ /** The last projection, so a drag can move three fields without rebuilding the row model. */
2525
+ let _lastValues: FilesPanelValues | null = null;
2526
+
2527
+ /**
2528
+ * Draw the panel — mounting the document the first time, and re-projecting into it every time
2529
+ * after.
2530
+ *
2531
+ * The document goes into `.panel-content`, not into the `.panel-body` this is handed, for the
2532
+ * reason `panels/git-panel.ts` states: only one of them is the node lit renders this panel's body
2533
+ * into, and appending to the other would leave the panel drawn under whatever the Navigator paints
2534
+ * next.
2535
+ *
2536
+ * The repaint stays the NAVIGATOR'S. Source Control owns an `effect()` because its inputs are the
2537
+ * reactive `shell.git` record; the tree's inputs are a `Map` of directory listings, a `Set` of
2538
+ * expanded paths and a roaming setting, none of which is reactive — so `ctx.rerender` is what this
2539
+ * surface has always been redrawn by, and it stays that way rather than growing a second scheduler
2540
+ * that could disagree with it.
2541
+ *
2542
+ * @param host - The painted `.panel-body`
2543
+ * @param rerender - The Navigator's repaint
2544
+ */
2545
+ export function mountFilesPanel(host: HTMLElement, rerender: () => void): void {
2546
+ const container = host.querySelector<HTMLElement>(".panel-content") ?? host;
2547
+ // Captured per paint, so the scroll watch and every awaited flow repaint through the CURRENT
2548
+ // Navigator scheduler rather than through a closure from an earlier one.
2549
+ _filesRerender = rerender;
2550
+ if (_standingFiles && (_standingFiles.host !== container || !_standingFiles.handle.connected())) {
2551
+ unmountFilesPanel();
2552
+ }
2553
+ const values = filesPanelValues();
2554
+ if (_standingFiles) {
2555
+ _standingFiles.handle.update(values);
2556
+ } else {
2557
+ const handle = mountFilesPanelSurface(container, values, FILE_ACTIONS);
2558
+ _standingFiles = { handle, host: container };
2559
+ /* The FIRST paint is the one nothing else follows, and the tree element it announces through
2560
+ `onNodeCreated` is still detached — the document is appended when its mount resolves. A watch
2561
+ armed against a detached element resolves no scroller, so the window would answer "all of
2562
+ them" for the life of the panel. This is where the tree is finally in the document. */
2563
+ void handle.ready.then(adoptFileTree);
2564
+ }
2565
+ /* One microtask later, because the projection above has only just been written: the rows reach
2566
+ the DOM as the scope's effects run, and a watch armed before they exist measures a tree that
2567
+ does not overflow yet. */
2568
+ queueMicrotask(adoptFileTree);
2569
+ }
2570
+
2571
+ /**
2572
+ * Take the panel down: the document, the drag registrations, the scroll watch and the row handles.
2573
+ *
2574
+ * Exported because a project close has to reach it — the tree it is showing belongs to the project
2575
+ * being left behind, exactly as `cleanupGitPanel` is for the working tree.
2576
+ */
2577
+ export function unmountFilesPanel(): void {
2578
+ dismissFileContextMenu();
2579
+ _standingFiles?.handle.dispose();
2580
+ _standingFiles = null;
2581
+ _lastValues = null;
2582
+ releaseFileTreeDnD();
2583
+ _fileRowEls.clear();
2584
+ _fileRows = [];
2585
+ }