@react-x11/components 0.1.0 → 0.2.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 (783) hide show
  1. package/README.md +979 -21
  2. package/dist/ansi/cast.d.ts +48 -0
  3. package/dist/ansi/cast.d.ts.map +1 -0
  4. package/dist/ansi/cast.js +135 -0
  5. package/dist/ansi/cast.js.map +1 -0
  6. package/dist/ansi/index.d.ts +10 -0
  7. package/dist/ansi/index.d.ts.map +1 -0
  8. package/dist/ansi/index.js +27 -0
  9. package/dist/ansi/index.js.map +1 -0
  10. package/dist/ansi/palette.d.ts +79 -0
  11. package/dist/ansi/palette.d.ts.map +1 -0
  12. package/dist/ansi/palette.js +155 -0
  13. package/dist/ansi/palette.js.map +1 -0
  14. package/dist/ansi/parse.d.ts +114 -0
  15. package/dist/ansi/parse.d.ts.map +1 -0
  16. package/dist/ansi/parse.js +687 -0
  17. package/dist/ansi/parse.js.map +1 -0
  18. package/dist/ansi/sgr.d.ts +87 -0
  19. package/dist/ansi/sgr.d.ts.map +1 -0
  20. package/dist/ansi/sgr.js +302 -0
  21. package/dist/ansi/sgr.js.map +1 -0
  22. package/dist/ansi/utf8.d.ts +15 -0
  23. package/dist/ansi/utf8.d.ts.map +1 -0
  24. package/dist/ansi/utf8.js +82 -0
  25. package/dist/ansi/utf8.js.map +1 -0
  26. package/dist/calendar/Calendar.d.ts +136 -0
  27. package/dist/calendar/Calendar.d.ts.map +1 -0
  28. package/dist/calendar/Calendar.js +460 -0
  29. package/dist/calendar/Calendar.js.map +1 -0
  30. package/dist/calendar/DatePicker.d.ts +52 -0
  31. package/dist/calendar/DatePicker.d.ts.map +1 -0
  32. package/dist/calendar/DatePicker.js +257 -0
  33. package/dist/calendar/DatePicker.js.map +1 -0
  34. package/dist/calendar/dates.d.ts +90 -0
  35. package/dist/calendar/dates.d.ts.map +1 -0
  36. package/dist/calendar/dates.js +236 -0
  37. package/dist/calendar/dates.js.map +1 -0
  38. package/dist/calendar/index.d.ts +8 -0
  39. package/dist/calendar/index.d.ts.map +1 -0
  40. package/dist/calendar/index.js +15 -0
  41. package/dist/calendar/index.js.map +1 -0
  42. package/dist/charts/components.d.ts +141 -0
  43. package/dist/charts/components.d.ts.map +1 -0
  44. package/dist/charts/components.js +580 -0
  45. package/dist/charts/components.js.map +1 -0
  46. package/dist/charts/data.d.ts +198 -0
  47. package/dist/charts/data.d.ts.map +1 -0
  48. package/dist/charts/data.js +616 -0
  49. package/dist/charts/data.js.map +1 -0
  50. package/dist/charts/hx.d.ts +21 -0
  51. package/dist/charts/hx.d.ts.map +1 -0
  52. package/dist/charts/hx.js +15 -0
  53. package/dist/charts/hx.js.map +1 -0
  54. package/dist/charts/index.d.ts +27 -0
  55. package/dist/charts/index.d.ts.map +1 -0
  56. package/dist/charts/index.js +38 -0
  57. package/dist/charts/index.js.map +1 -0
  58. package/dist/charts/node.d.ts +96 -0
  59. package/dist/charts/node.d.ts.map +1 -0
  60. package/dist/charts/node.js +720 -0
  61. package/dist/charts/node.js.map +1 -0
  62. package/dist/charts/render.d.ts +153 -0
  63. package/dist/charts/render.d.ts.map +1 -0
  64. package/dist/charts/render.js +762 -0
  65. package/dist/charts/render.js.map +1 -0
  66. package/dist/charts/scale.d.ts +42 -0
  67. package/dist/charts/scale.d.ts.map +1 -0
  68. package/dist/charts/scale.js +173 -0
  69. package/dist/charts/scale.js.map +1 -0
  70. package/dist/charts/spec.d.ts +91 -0
  71. package/dist/charts/spec.d.ts.map +1 -0
  72. package/dist/charts/spec.js +33 -0
  73. package/dist/charts/spec.js.map +1 -0
  74. package/dist/charts/timers.d.ts +6 -0
  75. package/dist/charts/timers.d.ts.map +1 -0
  76. package/dist/charts/timers.js +14 -0
  77. package/dist/charts/timers.js.map +1 -0
  78. package/dist/code/hx.d.ts +24 -0
  79. package/dist/code/hx.d.ts.map +1 -0
  80. package/dist/code/hx.js +25 -0
  81. package/dist/code/hx.js.map +1 -0
  82. package/dist/code/index.d.ts +45 -0
  83. package/dist/code/index.d.ts.map +1 -0
  84. package/dist/code/index.js +93 -0
  85. package/dist/code/index.js.map +1 -0
  86. package/dist/code-editor/completion.d.ts +26 -0
  87. package/dist/code-editor/completion.d.ts.map +1 -0
  88. package/dist/code-editor/completion.js +129 -0
  89. package/dist/code-editor/completion.js.map +1 -0
  90. package/dist/code-editor/doc.d.ts +35 -0
  91. package/dist/code-editor/doc.d.ts.map +1 -0
  92. package/dist/code-editor/doc.js +162 -0
  93. package/dist/code-editor/doc.js.map +1 -0
  94. package/dist/code-editor/hx.d.ts +13 -0
  95. package/dist/code-editor/hx.d.ts.map +1 -0
  96. package/dist/code-editor/hx.js +10 -0
  97. package/dist/code-editor/hx.js.map +1 -0
  98. package/dist/code-editor/index.d.ts +88 -0
  99. package/dist/code-editor/index.d.ts.map +1 -0
  100. package/dist/code-editor/index.js +401 -0
  101. package/dist/code-editor/index.js.map +1 -0
  102. package/dist/code-editor/node.d.ts +343 -0
  103. package/dist/code-editor/node.d.ts.map +1 -0
  104. package/dist/code-editor/node.js +1521 -0
  105. package/dist/code-editor/node.js.map +1 -0
  106. package/dist/code-language/hljs.d.ts +47 -0
  107. package/dist/code-language/hljs.d.ts.map +1 -0
  108. package/dist/code-language/hljs.js +211 -0
  109. package/dist/code-language/hljs.js.map +1 -0
  110. package/dist/code-language/index.d.ts +22 -0
  111. package/dist/code-language/index.d.ts.map +1 -0
  112. package/dist/code-language/index.js +20 -0
  113. package/dist/code-language/index.js.map +1 -0
  114. package/dist/code-language/languages/glsl.d.ts +4 -0
  115. package/dist/code-language/languages/glsl.d.ts.map +1 -0
  116. package/dist/code-language/languages/glsl.js +99 -0
  117. package/dist/code-language/languages/glsl.js.map +1 -0
  118. package/dist/code-language/languages/javascript.d.ts +10 -0
  119. package/dist/code-language/languages/javascript.d.ts.map +1 -0
  120. package/dist/code-language/languages/javascript.js +360 -0
  121. package/dist/code-language/languages/javascript.js.map +1 -0
  122. package/dist/code-language/languages/json.d.ts +4 -0
  123. package/dist/code-language/languages/json.d.ts.map +1 -0
  124. package/dist/code-language/languages/json.js +68 -0
  125. package/dist/code-language/languages/json.js.map +1 -0
  126. package/dist/code-language/languages/shell.d.ts +4 -0
  127. package/dist/code-language/languages/shell.d.ts.map +1 -0
  128. package/dist/code-language/languages/shell.js +189 -0
  129. package/dist/code-language/languages/shell.js.map +1 -0
  130. package/dist/code-language/languages/sql.d.ts +11 -0
  131. package/dist/code-language/languages/sql.d.ts.map +1 -0
  132. package/dist/code-language/languages/sql.js +133 -0
  133. package/dist/code-language/languages/sql.js.map +1 -0
  134. package/dist/code-language/lezer.d.ts +24 -0
  135. package/dist/code-language/lezer.d.ts.map +1 -0
  136. package/dist/code-language/lezer.js +148 -0
  137. package/dist/code-language/lezer.js.map +1 -0
  138. package/dist/code-language/registry.d.ts +19 -0
  139. package/dist/code-language/registry.d.ts.map +1 -0
  140. package/dist/code-language/registry.js +56 -0
  141. package/dist/code-language/registry.js.map +1 -0
  142. package/dist/code-language/runs.d.ts +35 -0
  143. package/dist/code-language/runs.d.ts.map +1 -0
  144. package/dist/code-language/runs.js +88 -0
  145. package/dist/code-language/runs.js.map +1 -0
  146. package/dist/code-language/stream.d.ts +70 -0
  147. package/dist/code-language/stream.d.ts.map +1 -0
  148. package/dist/code-language/stream.js +243 -0
  149. package/dist/code-language/stream.js.map +1 -0
  150. package/dist/code-language/textmate.d.ts +27 -0
  151. package/dist/code-language/textmate.d.ts.map +1 -0
  152. package/dist/code-language/textmate.js +86 -0
  153. package/dist/code-language/textmate.js.map +1 -0
  154. package/dist/code-language/theme.d.ts +26 -0
  155. package/dist/code-language/theme.d.ts.map +1 -0
  156. package/dist/code-language/theme.js +108 -0
  157. package/dist/code-language/theme.js.map +1 -0
  158. package/dist/code-language/timers.d.ts +7 -0
  159. package/dist/code-language/timers.d.ts.map +1 -0
  160. package/dist/code-language/timers.js +22 -0
  161. package/dist/code-language/timers.js.map +1 -0
  162. package/dist/code-language/types.d.ts +173 -0
  163. package/dist/code-language/types.d.ts.map +1 -0
  164. package/dist/code-language/types.js +41 -0
  165. package/dist/code-language/types.js.map +1 -0
  166. package/dist/codeblock/index.d.ts +69 -0
  167. package/dist/codeblock/index.d.ts.map +1 -0
  168. package/dist/codeblock/index.js +85 -0
  169. package/dist/codeblock/index.js.map +1 -0
  170. package/dist/color-picker/ColorField.d.ts +39 -0
  171. package/dist/color-picker/ColorField.d.ts.map +1 -0
  172. package/dist/color-picker/ColorField.js +239 -0
  173. package/dist/color-picker/ColorField.js.map +1 -0
  174. package/dist/color-picker/ColorPicker.d.ts +109 -0
  175. package/dist/color-picker/ColorPicker.d.ts.map +1 -0
  176. package/dist/color-picker/ColorPicker.js +757 -0
  177. package/dist/color-picker/ColorPicker.js.map +1 -0
  178. package/dist/color-picker/color.d.ts +105 -0
  179. package/dist/color-picker/color.d.ts.map +1 -0
  180. package/dist/color-picker/color.js +313 -0
  181. package/dist/color-picker/color.js.map +1 -0
  182. package/dist/color-picker/index.d.ts +8 -0
  183. package/dist/color-picker/index.d.ts.map +1 -0
  184. package/dist/color-picker/index.js +19 -0
  185. package/dist/color-picker/index.js.map +1 -0
  186. package/dist/desktop-calendar/eds.d.ts +102 -0
  187. package/dist/desktop-calendar/eds.d.ts.map +1 -0
  188. package/dist/desktop-calendar/eds.js +356 -0
  189. package/dist/desktop-calendar/eds.js.map +1 -0
  190. package/dist/desktop-calendar/ical.d.ts +63 -0
  191. package/dist/desktop-calendar/ical.d.ts.map +1 -0
  192. package/dist/desktop-calendar/ical.js +57 -0
  193. package/dist/desktop-calendar/ical.js.map +1 -0
  194. package/dist/desktop-calendar/index.d.ts +72 -0
  195. package/dist/desktop-calendar/index.d.ts.map +1 -0
  196. package/dist/desktop-calendar/index.js +213 -0
  197. package/dist/desktop-calendar/index.js.map +1 -0
  198. package/dist/embed/client.d.ts +121 -0
  199. package/dist/embed/client.d.ts.map +1 -0
  200. package/dist/embed/client.js +203 -0
  201. package/dist/embed/client.js.map +1 -0
  202. package/dist/embed/host.d.ts +96 -0
  203. package/dist/embed/host.d.ts.map +1 -0
  204. package/dist/embed/host.js +266 -0
  205. package/dist/embed/host.js.map +1 -0
  206. package/dist/embed/index.d.ts +5 -0
  207. package/dist/embed/index.d.ts.map +1 -0
  208. package/dist/embed/index.js +13 -0
  209. package/dist/embed/index.js.map +1 -0
  210. package/dist/embed/timers.d.ts +6 -0
  211. package/dist/embed/timers.d.ts.map +1 -0
  212. package/dist/embed/timers.js +16 -0
  213. package/dist/embed/timers.js.map +1 -0
  214. package/dist/flow/draw.d.ts +45 -0
  215. package/dist/flow/draw.d.ts.map +1 -0
  216. package/dist/flow/draw.js +295 -0
  217. package/dist/flow/draw.js.map +1 -0
  218. package/dist/flow/index.d.ts +64 -0
  219. package/dist/flow/index.d.ts.map +1 -0
  220. package/dist/flow/index.js +306 -0
  221. package/dist/flow/index.js.map +1 -0
  222. package/dist/flow/model.d.ts +158 -0
  223. package/dist/flow/model.d.ts.map +1 -0
  224. package/dist/flow/model.js +566 -0
  225. package/dist/flow/model.js.map +1 -0
  226. package/dist/flow/node.d.ts +429 -0
  227. package/dist/flow/node.d.ts.map +1 -0
  228. package/dist/flow/node.js +3025 -0
  229. package/dist/flow/node.js.map +1 -0
  230. package/dist/flow/paths.d.ts +43 -0
  231. package/dist/flow/paths.d.ts.map +1 -0
  232. package/dist/flow/paths.js +327 -0
  233. package/dist/flow/paths.js.map +1 -0
  234. package/dist/flow/types.d.ts +561 -0
  235. package/dist/flow/types.d.ts.map +1 -0
  236. package/dist/flow/types.js +2 -0
  237. package/dist/flow/types.js.map +1 -0
  238. package/dist/formula/hx.d.ts +24 -0
  239. package/dist/formula/hx.d.ts.map +1 -0
  240. package/dist/formula/hx.js +25 -0
  241. package/dist/formula/hx.js.map +1 -0
  242. package/dist/formula/index.d.ts +74 -0
  243. package/dist/formula/index.d.ts.map +1 -0
  244. package/dist/formula/index.js +155 -0
  245. package/dist/formula/index.js.map +1 -0
  246. package/dist/formula/katex.d.ts +78 -0
  247. package/dist/formula/katex.d.ts.map +1 -0
  248. package/dist/formula/katex.js +130 -0
  249. package/dist/formula/katex.js.map +1 -0
  250. package/dist/formula/layout.d.ts +103 -0
  251. package/dist/formula/layout.d.ts.map +1 -0
  252. package/dist/formula/layout.js +716 -0
  253. package/dist/formula/layout.js.map +1 -0
  254. package/dist/formula/node.d.ts +50 -0
  255. package/dist/formula/node.d.ts.map +1 -0
  256. package/dist/formula/node.js +351 -0
  257. package/dist/formula/node.js.map +1 -0
  258. package/dist/html/controls.d.ts +48 -0
  259. package/dist/html/controls.d.ts.map +1 -0
  260. package/dist/html/controls.js +195 -0
  261. package/dist/html/controls.js.map +1 -0
  262. package/dist/html/css/cascade.d.ts +51 -0
  263. package/dist/html/css/cascade.d.ts.map +1 -0
  264. package/dist/html/css/cascade.js +552 -0
  265. package/dist/html/css/cascade.js.map +1 -0
  266. package/dist/html/css/parse.d.ts +74 -0
  267. package/dist/html/css/parse.d.ts.map +1 -0
  268. package/dist/html/css/parse.js +464 -0
  269. package/dist/html/css/parse.js.map +1 -0
  270. package/dist/html/css/style.d.ts +142 -0
  271. package/dist/html/css/style.d.ts.map +1 -0
  272. package/dist/html/css/style.js +1145 -0
  273. package/dist/html/css/style.js.map +1 -0
  274. package/dist/html/css/ua.d.ts +5 -0
  275. package/dist/html/css/ua.d.ts.map +1 -0
  276. package/dist/html/css/ua.js +171 -0
  277. package/dist/html/css/ua.js.map +1 -0
  278. package/dist/html/css/values.d.ts +78 -0
  279. package/dist/html/css/values.d.ts.map +1 -0
  280. package/dist/html/css/values.js +330 -0
  281. package/dist/html/css/values.js.map +1 -0
  282. package/dist/html/dom.d.ts +112 -0
  283. package/dist/html/dom.d.ts.map +1 -0
  284. package/dist/html/dom.js +374 -0
  285. package/dist/html/dom.js.map +1 -0
  286. package/dist/html/hx.d.ts +24 -0
  287. package/dist/html/hx.d.ts.map +1 -0
  288. package/dist/html/hx.js +29 -0
  289. package/dist/html/hx.js.map +1 -0
  290. package/dist/html/index.d.ts +137 -0
  291. package/dist/html/index.d.ts.map +1 -0
  292. package/dist/html/index.js +339 -0
  293. package/dist/html/index.js.map +1 -0
  294. package/dist/html/layout/block.d.ts +58 -0
  295. package/dist/html/layout/block.d.ts.map +1 -0
  296. package/dist/html/layout/block.js +724 -0
  297. package/dist/html/layout/block.js.map +1 -0
  298. package/dist/html/layout/boxes.d.ts +261 -0
  299. package/dist/html/layout/boxes.d.ts.map +1 -0
  300. package/dist/html/layout/boxes.js +725 -0
  301. package/dist/html/layout/boxes.js.map +1 -0
  302. package/dist/html/layout/flex.d.ts +16 -0
  303. package/dist/html/layout/flex.d.ts.map +1 -0
  304. package/dist/html/layout/flex.js +242 -0
  305. package/dist/html/layout/flex.js.map +1 -0
  306. package/dist/html/layout/floats.d.ts +50 -0
  307. package/dist/html/layout/floats.d.ts.map +1 -0
  308. package/dist/html/layout/floats.js +110 -0
  309. package/dist/html/layout/floats.js.map +1 -0
  310. package/dist/html/layout/inline.d.ts +44 -0
  311. package/dist/html/layout/inline.d.ts.map +1 -0
  312. package/dist/html/layout/inline.js +700 -0
  313. package/dist/html/layout/inline.js.map +1 -0
  314. package/dist/html/layout/table.d.ts +5 -0
  315. package/dist/html/layout/table.d.ts.map +1 -0
  316. package/dist/html/layout/table.js +340 -0
  317. package/dist/html/layout/table.js.map +1 -0
  318. package/dist/html/node.d.ts +149 -0
  319. package/dist/html/node.d.ts.map +1 -0
  320. package/dist/html/node.js +861 -0
  321. package/dist/html/node.js.map +1 -0
  322. package/dist/html/paint.d.ts +48 -0
  323. package/dist/html/paint.d.ts.map +1 -0
  324. package/dist/html/paint.js +495 -0
  325. package/dist/html/paint.js.map +1 -0
  326. package/dist/html/resources.d.ts +48 -0
  327. package/dist/html/resources.d.ts.map +1 -0
  328. package/dist/html/resources.js +156 -0
  329. package/dist/html/resources.js.map +1 -0
  330. package/dist/index.d.ts +48 -0
  331. package/dist/index.d.ts.map +1 -0
  332. package/dist/index.js +92 -0
  333. package/dist/index.js.map +1 -0
  334. package/dist/internal/heights.d.ts +81 -0
  335. package/dist/internal/heights.d.ts.map +1 -0
  336. package/dist/internal/heights.js +193 -0
  337. package/dist/internal/heights.js.map +1 -0
  338. package/dist/internal/hx.d.ts +24 -0
  339. package/dist/internal/hx.d.ts.map +1 -0
  340. package/dist/internal/hx.js +27 -0
  341. package/dist/internal/hx.js.map +1 -0
  342. package/dist/internal/text.d.ts +6 -0
  343. package/dist/internal/text.d.ts.map +1 -0
  344. package/dist/internal/text.js +44 -0
  345. package/dist/internal/text.js.map +1 -0
  346. package/dist/internal/timers.d.ts +8 -0
  347. package/dist/internal/timers.d.ts.map +1 -0
  348. package/dist/internal/timers.js +22 -0
  349. package/dist/internal/timers.js.map +1 -0
  350. package/dist/internal/widget.d.ts +40 -0
  351. package/dist/internal/widget.d.ts.map +1 -0
  352. package/dist/internal/widget.js +44 -0
  353. package/dist/internal/widget.js.map +1 -0
  354. package/dist/markdown/ast.d.ts +126 -0
  355. package/dist/markdown/ast.d.ts.map +1 -0
  356. package/dist/markdown/ast.js +8 -0
  357. package/dist/markdown/ast.js.map +1 -0
  358. package/dist/markdown/hx.d.ts +24 -0
  359. package/dist/markdown/hx.d.ts.map +1 -0
  360. package/dist/markdown/hx.js +25 -0
  361. package/dist/markdown/hx.js.map +1 -0
  362. package/dist/markdown/index.d.ts +90 -0
  363. package/dist/markdown/index.d.ts.map +1 -0
  364. package/dist/markdown/index.js +413 -0
  365. package/dist/markdown/index.js.map +1 -0
  366. package/dist/markdown/parse.d.ts +8 -0
  367. package/dist/markdown/parse.d.ts.map +1 -0
  368. package/dist/markdown/parse.js +911 -0
  369. package/dist/markdown/parse.js.map +1 -0
  370. package/dist/markdown/spans.d.ts +20 -0
  371. package/dist/markdown/spans.d.ts.map +1 -0
  372. package/dist/markdown/spans.js +96 -0
  373. package/dist/markdown/spans.js.map +1 -0
  374. package/dist/media-player/backends.d.ts +64 -0
  375. package/dist/media-player/backends.d.ts.map +1 -0
  376. package/dist/media-player/backends.js +110 -0
  377. package/dist/media-player/backends.js.map +1 -0
  378. package/dist/media-player/control.d.ts +40 -0
  379. package/dist/media-player/control.d.ts.map +1 -0
  380. package/dist/media-player/control.js +44 -0
  381. package/dist/media-player/control.js.map +1 -0
  382. package/dist/media-player/hx.d.ts +24 -0
  383. package/dist/media-player/hx.d.ts.map +1 -0
  384. package/dist/media-player/hx.js +25 -0
  385. package/dist/media-player/hx.js.map +1 -0
  386. package/dist/media-player/index.d.ts +107 -0
  387. package/dist/media-player/index.d.ts.map +1 -0
  388. package/dist/media-player/index.js +219 -0
  389. package/dist/media-player/index.js.map +1 -0
  390. package/dist/media-player/mpv.d.ts +4 -0
  391. package/dist/media-player/mpv.d.ts.map +1 -0
  392. package/dist/media-player/mpv.js +120 -0
  393. package/dist/media-player/mpv.js.map +1 -0
  394. package/dist/media-player/vlc.d.ts +8 -0
  395. package/dist/media-player/vlc.d.ts.map +1 -0
  396. package/dist/media-player/vlc.js +83 -0
  397. package/dist/media-player/vlc.js.map +1 -0
  398. package/dist/richtext/index.d.ts +19 -0
  399. package/dist/richtext/index.d.ts.map +1 -0
  400. package/dist/richtext/index.js +4 -0
  401. package/dist/richtext/index.js.map +1 -0
  402. package/dist/richtext/links.d.ts +12 -0
  403. package/dist/richtext/links.d.ts.map +1 -0
  404. package/dist/richtext/links.js +64 -0
  405. package/dist/richtext/links.js.map +1 -0
  406. package/dist/richtext/menu.d.ts +11 -0
  407. package/dist/richtext/menu.d.ts.map +1 -0
  408. package/dist/richtext/menu.js +43 -0
  409. package/dist/richtext/menu.js.map +1 -0
  410. package/dist/richtext/node.d.ts +151 -0
  411. package/dist/richtext/node.d.ts.map +1 -0
  412. package/dist/richtext/node.js +255 -0
  413. package/dist/richtext/node.js.map +1 -0
  414. package/dist/richtext/runs.d.ts +92 -0
  415. package/dist/richtext/runs.d.ts.map +1 -0
  416. package/dist/richtext/runs.js +158 -0
  417. package/dist/richtext/runs.js.map +1 -0
  418. package/dist/table/hx.d.ts +24 -0
  419. package/dist/table/hx.d.ts.map +1 -0
  420. package/dist/table/hx.js +25 -0
  421. package/dist/table/hx.js.map +1 -0
  422. package/dist/table/index.d.ts +169 -0
  423. package/dist/table/index.d.ts.map +1 -0
  424. package/dist/table/index.js +844 -0
  425. package/dist/table/index.js.map +1 -0
  426. package/dist/table/rows.d.ts +136 -0
  427. package/dist/table/rows.d.ts.map +1 -0
  428. package/dist/table/rows.js +146 -0
  429. package/dist/table/rows.js.map +1 -0
  430. package/dist/terminal/backends.d.ts +105 -0
  431. package/dist/terminal/backends.d.ts.map +1 -0
  432. package/dist/terminal/backends.js +185 -0
  433. package/dist/terminal/backends.js.map +1 -0
  434. package/dist/terminal/hx.d.ts +24 -0
  435. package/dist/terminal/hx.d.ts.map +1 -0
  436. package/dist/terminal/hx.js +25 -0
  437. package/dist/terminal/hx.js.map +1 -0
  438. package/dist/terminal/index.d.ts +160 -0
  439. package/dist/terminal/index.d.ts.map +1 -0
  440. package/dist/terminal/index.js +344 -0
  441. package/dist/terminal/index.js.map +1 -0
  442. package/dist/terminal/title.d.ts +24 -0
  443. package/dist/terminal/title.d.ts.map +1 -0
  444. package/dist/terminal/title.js +129 -0
  445. package/dist/terminal/title.js.map +1 -0
  446. package/dist/terminal/vt/colors.d.ts +63 -0
  447. package/dist/terminal/vt/colors.d.ts.map +1 -0
  448. package/dist/terminal/vt/colors.js +203 -0
  449. package/dist/terminal/vt/colors.js.map +1 -0
  450. package/dist/terminal/vt/diff.d.ts +117 -0
  451. package/dist/terminal/vt/diff.d.ts.map +1 -0
  452. package/dist/terminal/vt/diff.js +358 -0
  453. package/dist/terminal/vt/diff.js.map +1 -0
  454. package/dist/terminal/vt/fonts.d.ts +92 -0
  455. package/dist/terminal/vt/fonts.d.ts.map +1 -0
  456. package/dist/terminal/vt/fonts.js +178 -0
  457. package/dist/terminal/vt/fonts.js.map +1 -0
  458. package/dist/terminal/vt/index.d.ts +78 -0
  459. package/dist/terminal/vt/index.d.ts.map +1 -0
  460. package/dist/terminal/vt/index.js +312 -0
  461. package/dist/terminal/vt/index.js.map +1 -0
  462. package/dist/terminal/vt/keys.d.ts +74 -0
  463. package/dist/terminal/vt/keys.d.ts.map +1 -0
  464. package/dist/terminal/vt/keys.js +309 -0
  465. package/dist/terminal/vt/keys.js.map +1 -0
  466. package/dist/terminal/vt/mouse.d.ts +44 -0
  467. package/dist/terminal/vt/mouse.d.ts.map +1 -0
  468. package/dist/terminal/vt/mouse.js +106 -0
  469. package/dist/terminal/vt/mouse.js.map +1 -0
  470. package/dist/terminal/vt/node.d.ts +246 -0
  471. package/dist/terminal/vt/node.d.ts.map +1 -0
  472. package/dist/terminal/vt/node.js +1068 -0
  473. package/dist/terminal/vt/node.js.map +1 -0
  474. package/dist/terminal/vt/pty.d.ts +81 -0
  475. package/dist/terminal/vt/pty.d.ts.map +1 -0
  476. package/dist/terminal/vt/pty.js +201 -0
  477. package/dist/terminal/vt/pty.js.map +1 -0
  478. package/dist/terminal/vt/renderer.d.ts +179 -0
  479. package/dist/terminal/vt/renderer.d.ts.map +1 -0
  480. package/dist/terminal/vt/renderer.js +357 -0
  481. package/dist/terminal/vt/renderer.js.map +1 -0
  482. package/dist/terminal/vt/timers.d.ts +6 -0
  483. package/dist/terminal/vt/timers.d.ts.map +1 -0
  484. package/dist/terminal/vt/timers.js +16 -0
  485. package/dist/terminal/vt/timers.js.map +1 -0
  486. package/dist/terminal/vt/xterm.d.ts +142 -0
  487. package/dist/terminal/vt/xterm.d.ts.map +1 -0
  488. package/dist/terminal/vt/xterm.js +32 -0
  489. package/dist/terminal/vt/xterm.js.map +1 -0
  490. package/dist/terminal-output/hx.d.ts +24 -0
  491. package/dist/terminal-output/hx.d.ts.map +1 -0
  492. package/dist/terminal-output/hx.js +25 -0
  493. package/dist/terminal-output/hx.js.map +1 -0
  494. package/dist/terminal-output/index.d.ts +92 -0
  495. package/dist/terminal-output/index.d.ts.map +1 -0
  496. package/dist/terminal-output/index.js +179 -0
  497. package/dist/terminal-output/index.js.map +1 -0
  498. package/dist/terminal-output/runs.d.ts +27 -0
  499. package/dist/terminal-output/runs.d.ts.map +1 -0
  500. package/dist/terminal-output/runs.js +66 -0
  501. package/dist/terminal-output/runs.js.map +1 -0
  502. package/dist/three/canvas.d.ts +46 -0
  503. package/dist/three/canvas.d.ts.map +1 -0
  504. package/dist/three/canvas.js +305 -0
  505. package/dist/three/canvas.js.map +1 -0
  506. package/dist/three/events.d.ts +64 -0
  507. package/dist/three/events.d.ts.map +1 -0
  508. package/dist/three/events.js +146 -0
  509. package/dist/three/events.js.map +1 -0
  510. package/dist/three/geometries.d.ts +89 -0
  511. package/dist/three/geometries.d.ts.map +1 -0
  512. package/dist/three/geometries.js +345 -0
  513. package/dist/three/geometries.js.map +1 -0
  514. package/dist/three/globals.d.ts +7 -0
  515. package/dist/three/globals.d.ts.map +1 -0
  516. package/dist/three/globals.js +20 -0
  517. package/dist/three/globals.js.map +1 -0
  518. package/dist/three/hx.d.ts +9 -0
  519. package/dist/three/hx.d.ts.map +1 -0
  520. package/dist/three/hx.js +10 -0
  521. package/dist/three/hx.js.map +1 -0
  522. package/dist/three/index.d.ts +22 -0
  523. package/dist/three/index.d.ts.map +1 -0
  524. package/dist/three/index.js +24 -0
  525. package/dist/three/index.js.map +1 -0
  526. package/dist/three/jsx-dev-runtime.d.ts +19 -0
  527. package/dist/three/jsx-dev-runtime.d.ts.map +1 -0
  528. package/dist/three/jsx-dev-runtime.js +2 -0
  529. package/dist/three/jsx-dev-runtime.js.map +1 -0
  530. package/dist/three/jsx-runtime.d.ts +19 -0
  531. package/dist/three/jsx-runtime.d.ts.map +1 -0
  532. package/dist/three/jsx-runtime.js +2 -0
  533. package/dist/three/jsx-runtime.js.map +1 -0
  534. package/dist/three/jsx.d.ts +198 -0
  535. package/dist/three/jsx.d.ts.map +1 -0
  536. package/dist/three/jsx.js +2 -0
  537. package/dist/three/jsx.js.map +1 -0
  538. package/dist/three/materials.d.ts +125 -0
  539. package/dist/three/materials.d.ts.map +1 -0
  540. package/dist/three/materials.js +229 -0
  541. package/dist/three/materials.js.map +1 -0
  542. package/dist/three/math.d.ts +146 -0
  543. package/dist/three/math.d.ts.map +1 -0
  544. package/dist/three/math.js +464 -0
  545. package/dist/three/math.js.map +1 -0
  546. package/dist/three/objects.d.ts +185 -0
  547. package/dist/three/objects.d.ts.map +1 -0
  548. package/dist/three/objects.js +309 -0
  549. package/dist/three/objects.js.map +1 -0
  550. package/dist/three/passes.d.ts +54 -0
  551. package/dist/three/passes.d.ts.map +1 -0
  552. package/dist/three/passes.js +78 -0
  553. package/dist/three/passes.js.map +1 -0
  554. package/dist/three/postprocess.d.ts +85 -0
  555. package/dist/three/postprocess.d.ts.map +1 -0
  556. package/dist/three/postprocess.js +503 -0
  557. package/dist/three/postprocess.js.map +1 -0
  558. package/dist/three/raycast.d.ts +24 -0
  559. package/dist/three/raycast.d.ts.map +1 -0
  560. package/dist/three/raycast.js +138 -0
  561. package/dist/three/raycast.js.map +1 -0
  562. package/dist/three/reconciler.d.ts +48 -0
  563. package/dist/three/reconciler.d.ts.map +1 -0
  564. package/dist/three/reconciler.js +416 -0
  565. package/dist/three/reconciler.js.map +1 -0
  566. package/dist/three/renderer-direct.d.ts +102 -0
  567. package/dist/three/renderer-direct.d.ts.map +1 -0
  568. package/dist/three/renderer-direct.js +782 -0
  569. package/dist/three/renderer-direct.js.map +1 -0
  570. package/dist/three/renderer-indirect.d.ts +68 -0
  571. package/dist/three/renderer-indirect.d.ts.map +1 -0
  572. package/dist/three/renderer-indirect.js +438 -0
  573. package/dist/three/renderer-indirect.js.map +1 -0
  574. package/dist/three/store.d.ts +81 -0
  575. package/dist/three/store.d.ts.map +1 -0
  576. package/dist/three/store.js +110 -0
  577. package/dist/three/store.js.map +1 -0
  578. package/dist/timeline/hx.d.ts +18 -0
  579. package/dist/timeline/hx.d.ts.map +1 -0
  580. package/dist/timeline/hx.js +10 -0
  581. package/dist/timeline/hx.js.map +1 -0
  582. package/dist/timeline/index.d.ts +152 -0
  583. package/dist/timeline/index.d.ts.map +1 -0
  584. package/dist/timeline/index.js +383 -0
  585. package/dist/timeline/index.js.map +1 -0
  586. package/dist/tray-host/hx.d.ts +24 -0
  587. package/dist/tray-host/hx.d.ts.map +1 -0
  588. package/dist/tray-host/hx.js +25 -0
  589. package/dist/tray-host/hx.js.map +1 -0
  590. package/dist/tray-host/index.d.ts +110 -0
  591. package/dist/tray-host/index.d.ts.map +1 -0
  592. package/dist/tray-host/index.js +191 -0
  593. package/dist/tray-host/index.js.map +1 -0
  594. package/dist/tray-host/manager.d.ts +137 -0
  595. package/dist/tray-host/manager.d.ts.map +1 -0
  596. package/dist/tray-host/manager.js +462 -0
  597. package/dist/tray-host/manager.js.map +1 -0
  598. package/dist/tray-host/notify.d.ts +22 -0
  599. package/dist/tray-host/notify.d.ts.map +1 -0
  600. package/dist/tray-host/notify.js +74 -0
  601. package/dist/tray-host/notify.js.map +1 -0
  602. package/dist/tray-host/protocol.d.ts +106 -0
  603. package/dist/tray-host/protocol.d.ts.map +1 -0
  604. package/dist/tray-host/protocol.js +191 -0
  605. package/dist/tray-host/protocol.js.map +1 -0
  606. package/dist/tree/hx.d.ts +24 -0
  607. package/dist/tree/hx.d.ts.map +1 -0
  608. package/dist/tree/hx.js +25 -0
  609. package/dist/tree/hx.js.map +1 -0
  610. package/dist/tree/index.d.ts +221 -0
  611. package/dist/tree/index.d.ts.map +1 -0
  612. package/dist/tree/index.js +716 -0
  613. package/dist/tree/index.js.map +1 -0
  614. package/dist/tree/internal.d.ts +18 -0
  615. package/dist/tree/internal.d.ts.map +1 -0
  616. package/dist/tree/internal.js +66 -0
  617. package/dist/tree/internal.js.map +1 -0
  618. package/dist/tree/rows.d.ts +177 -0
  619. package/dist/tree/rows.d.ts.map +1 -0
  620. package/dist/tree/rows.js +179 -0
  621. package/dist/tree/rows.js.map +1 -0
  622. package/package.json +166 -12
  623. package/src/ansi/cast.ts +159 -0
  624. package/src/ansi/index.ts +53 -0
  625. package/src/ansi/palette.ts +226 -0
  626. package/src/ansi/parse.ts +780 -0
  627. package/src/ansi/sgr.ts +380 -0
  628. package/src/ansi/utf8.ts +84 -0
  629. package/src/calendar/Calendar.ts +744 -0
  630. package/src/calendar/DatePicker.ts +368 -0
  631. package/src/calendar/dates.ts +307 -0
  632. package/src/calendar/index.ts +51 -0
  633. package/src/charts/components.ts +864 -0
  634. package/src/charts/data.ts +776 -0
  635. package/src/charts/hx.ts +39 -0
  636. package/src/charts/index.ts +99 -0
  637. package/src/charts/node.ts +932 -0
  638. package/src/charts/render.ts +982 -0
  639. package/src/charts/scale.ts +214 -0
  640. package/src/charts/spec.ts +122 -0
  641. package/src/charts/timers.ts +24 -0
  642. package/src/code/hx.ts +51 -0
  643. package/src/code/index.ts +174 -0
  644. package/src/code-editor/completion.ts +161 -0
  645. package/src/code-editor/doc.ts +198 -0
  646. package/src/code-editor/hx.ts +26 -0
  647. package/src/code-editor/index.ts +615 -0
  648. package/src/code-editor/node.ts +1926 -0
  649. package/src/code-language/hljs.ts +302 -0
  650. package/src/code-language/index.ts +51 -0
  651. package/src/code-language/languages/glsl.ts +120 -0
  652. package/src/code-language/languages/javascript.ts +419 -0
  653. package/src/code-language/languages/json.ts +72 -0
  654. package/src/code-language/languages/shell.ts +221 -0
  655. package/src/code-language/languages/sql.ts +165 -0
  656. package/src/code-language/lezer.ts +190 -0
  657. package/src/code-language/registry.ts +66 -0
  658. package/src/code-language/runs.ts +128 -0
  659. package/src/code-language/stream.ts +306 -0
  660. package/src/code-language/textmate.ts +134 -0
  661. package/src/code-language/theme.ts +124 -0
  662. package/src/code-language/timers.ts +36 -0
  663. package/src/code-language/types.ts +252 -0
  664. package/src/codeblock/index.ts +146 -0
  665. package/src/color-picker/ColorField.ts +333 -0
  666. package/src/color-picker/ColorPicker.ts +1069 -0
  667. package/src/color-picker/color.ts +399 -0
  668. package/src/color-picker/index.ts +50 -0
  669. package/src/desktop-calendar/eds.ts +484 -0
  670. package/src/desktop-calendar/ical.ts +119 -0
  671. package/src/desktop-calendar/index.ts +287 -0
  672. package/src/embed/client.ts +311 -0
  673. package/src/embed/host.ts +432 -0
  674. package/src/embed/index.ts +33 -0
  675. package/src/embed/timers.ts +32 -0
  676. package/src/flow/draw.ts +418 -0
  677. package/src/flow/index.ts +473 -0
  678. package/src/flow/model.ts +687 -0
  679. package/src/flow/node.ts +3694 -0
  680. package/src/flow/paths.ts +403 -0
  681. package/src/flow/types.ts +634 -0
  682. package/src/formula/hx.ts +51 -0
  683. package/src/formula/index.ts +243 -0
  684. package/src/formula/katex.ts +209 -0
  685. package/src/formula/layout.ts +876 -0
  686. package/src/formula/node.ts +467 -0
  687. package/src/html/controls.ts +244 -0
  688. package/src/html/css/cascade.ts +606 -0
  689. package/src/html/css/parse.ts +500 -0
  690. package/src/html/css/style.ts +1371 -0
  691. package/src/html/css/ua.ts +174 -0
  692. package/src/html/css/values.ts +358 -0
  693. package/src/html/dom.ts +410 -0
  694. package/src/html/hx.ts +55 -0
  695. package/src/html/index.ts +545 -0
  696. package/src/html/layout/block.ts +876 -0
  697. package/src/html/layout/boxes.ts +981 -0
  698. package/src/html/layout/flex.ts +297 -0
  699. package/src/html/layout/floats.ts +125 -0
  700. package/src/html/layout/inline.ts +870 -0
  701. package/src/html/layout/table.ts +380 -0
  702. package/src/html/node.ts +967 -0
  703. package/src/html/paint.ts +605 -0
  704. package/src/html/resources.ts +214 -0
  705. package/src/index.ts +638 -0
  706. package/src/internal/heights.ts +211 -0
  707. package/src/internal/hx.ts +53 -0
  708. package/src/internal/text.ts +44 -0
  709. package/src/internal/timers.ts +44 -0
  710. package/src/internal/widget.ts +92 -0
  711. package/src/markdown/ast.ts +163 -0
  712. package/src/markdown/hx.ts +51 -0
  713. package/src/markdown/index.ts +686 -0
  714. package/src/markdown/parse.ts +1037 -0
  715. package/src/markdown/spans.ts +143 -0
  716. package/src/media-player/backends.ts +155 -0
  717. package/src/media-player/control.ts +70 -0
  718. package/src/media-player/hx.ts +51 -0
  719. package/src/media-player/index.ts +378 -0
  720. package/src/media-player/mpv.ts +146 -0
  721. package/src/media-player/vlc.ts +97 -0
  722. package/src/richtext/index.ts +42 -0
  723. package/src/richtext/links.ts +78 -0
  724. package/src/richtext/menu.ts +49 -0
  725. package/src/richtext/node.ts +406 -0
  726. package/src/richtext/runs.ts +253 -0
  727. package/src/table/hx.ts +51 -0
  728. package/src/table/index.ts +1219 -0
  729. package/src/table/rows.ts +275 -0
  730. package/src/terminal/backends.ts +242 -0
  731. package/src/terminal/hx.ts +51 -0
  732. package/src/terminal/index.ts +574 -0
  733. package/src/terminal/title.ts +172 -0
  734. package/src/terminal/vt/colors.ts +247 -0
  735. package/src/terminal/vt/diff.ts +467 -0
  736. package/src/terminal/vt/fonts.ts +233 -0
  737. package/src/terminal/vt/index.ts +443 -0
  738. package/src/terminal/vt/keys.ts +369 -0
  739. package/src/terminal/vt/mouse.ts +144 -0
  740. package/src/terminal/vt/node.ts +1242 -0
  741. package/src/terminal/vt/pty.ts +334 -0
  742. package/src/terminal/vt/renderer.ts +555 -0
  743. package/src/terminal/vt/timers.ts +31 -0
  744. package/src/terminal/vt/xterm.ts +193 -0
  745. package/src/terminal-output/hx.ts +51 -0
  746. package/src/terminal-output/index.ts +340 -0
  747. package/src/terminal-output/runs.ts +79 -0
  748. package/src/three/canvas.ts +451 -0
  749. package/src/three/events.ts +197 -0
  750. package/src/three/geometries.ts +429 -0
  751. package/src/three/globals.ts +34 -0
  752. package/src/three/hx.ts +22 -0
  753. package/src/three/index.ts +98 -0
  754. package/src/three/jsx-dev-runtime.ts +27 -0
  755. package/src/three/jsx-runtime.ts +38 -0
  756. package/src/three/jsx.ts +275 -0
  757. package/src/three/materials.ts +270 -0
  758. package/src/three/math.ts +585 -0
  759. package/src/three/objects.ts +397 -0
  760. package/src/three/passes.ts +90 -0
  761. package/src/three/postprocess.ts +677 -0
  762. package/src/three/raycast.ts +189 -0
  763. package/src/three/react-reconciler.d.ts +50 -0
  764. package/src/three/reconciler.ts +624 -0
  765. package/src/three/renderer-direct.ts +1055 -0
  766. package/src/three/renderer-indirect.ts +570 -0
  767. package/src/three/store.ts +207 -0
  768. package/src/timeline/hx.ts +31 -0
  769. package/src/timeline/index.ts +603 -0
  770. package/src/tray-host/hx.ts +51 -0
  771. package/src/tray-host/index.ts +331 -0
  772. package/src/tray-host/manager.ts +639 -0
  773. package/src/tray-host/notify.ts +102 -0
  774. package/src/tray-host/protocol.ts +235 -0
  775. package/src/tree/hx.ts +51 -0
  776. package/src/tree/index.ts +1087 -0
  777. package/src/tree/internal.ts +87 -0
  778. package/src/tree/rows.ts +334 -0
  779. package/src/index.d.ts +0 -2
  780. package/src/index.js +0 -9
  781. package/src/sparkline/index.d.ts +0 -29
  782. package/src/sparkline/index.js +0 -50
  783. package/src/sparkline/node.js +0 -72
@@ -0,0 +1,1087 @@
1
+ // <Tree> — a disclosure tree: file browsers, outline panes, property
2
+ // inspectors, anything with a twisty.
3
+ //
4
+ // This is a **successor to react-x11's own `<Tree>`, not a wrapper around
5
+ // it**. Core's is being retired, so nothing here imports it and the two share
6
+ // no code. What is kept is the behaviour a user has already learnt — the
7
+ // keyboard map, type-ahead, the twisty being its own hit target — because
8
+ // that is the part it would be rude to change.
9
+ //
10
+ // Three things it has that core's does not, and they are the reason it lives
11
+ // out here rather than in core:
12
+ //
13
+ // 1. **It reads the app's own data.** `getId` / `getChildren` / `isBranch`
14
+ // and friends mean a filesystem listing, an AST or a normalized store is
15
+ // rendered where it lies, instead of being copied into a shape this
16
+ // component preferred. The defaults describe `{ id, label, children }`,
17
+ // so a tree that has that shape configures nothing.
18
+ // 2. **It virtualizes.** Past a couple of hundred visible rows it builds
19
+ // only the slice on screen, the way `Table` does, and the rest of the
20
+ // list is two spacer boxes so the scrollbar still measures the whole
21
+ // tree. That is what "very large number of elements" costs: nothing.
22
+ // 3. **Every visible part is a seam.** The twisty, the branch edge down the
23
+ // indent, the label, the row's contents and — in `layout="nested"` — the
24
+ // subtree container are each a render prop with a style override beside
25
+ // it. The default look is deliberately plain: a chevron, no branch lines,
26
+ // just indentation.
27
+ //
28
+ // Nothing here registers a host element. A tree is `<box>`, `<text>` and
29
+ // core's chevron, so there is no `registerElement` call, no JSX augmentation
30
+ // and no side effect at import time at all.
31
+ import React, {
32
+ useCallback,
33
+ useEffect,
34
+ useImperativeHandle,
35
+ useMemo,
36
+ useRef,
37
+ useState,
38
+ } from 'react';
39
+ import type { ReactElement, ReactNode, Ref } from 'react';
40
+ import { createStyles } from 'react-x11/style';
41
+ import type { StyleProp } from 'react-x11';
42
+ import { Icon, useDirection, useTheme } from 'react-x11';
43
+ import type { DrawnNode, KeyboardEvent, ScrollableNode } from 'react-x11';
44
+ import {
45
+ XK_DOWN,
46
+ XK_END,
47
+ XK_HOME,
48
+ XK_LEFT,
49
+ XK_PAGE_DOWN,
50
+ XK_PAGE_UP,
51
+ XK_RETURN,
52
+ XK_RIGHT,
53
+ XK_UP,
54
+ } from 'react-x11/keysyms';
55
+
56
+ import { hx } from './hx.js';
57
+ import type { Host } from './hx.js';
58
+ // Shared with <Table> — internal, deliberately not a shared *module*; the
59
+ // header of src/internal/heights.ts says why.
60
+ import { RowHeights } from '../internal/heights.js';
61
+ import { afterLayout, cancelAfterLayout } from '../internal/timers.js';
62
+ import { typeAheadChar, useTypeAhead } from './internal.js';
63
+ import {
64
+ branchEdges,
65
+ findItem,
66
+ groupRows,
67
+ isGroup,
68
+ resolveAccessors,
69
+ visibleRows,
70
+ } from './rows.js';
71
+ import type {
72
+ ResolvedAccessors,
73
+ TreeAccessors,
74
+ TreeGroup,
75
+ TreeItem,
76
+ TreeItemId,
77
+ TreeRow,
78
+ } from './rows.js';
79
+
80
+ // The row model comes out too: it is what the seams are handed, and an app
81
+ // that drives a tree from outside — "reveal this path", "how many rows is
82
+ // that" — does the same arithmetic. `resolveAccessors` is part of it rather
83
+ // than an internal, because `visibleRows` takes accessors with every default
84
+ // already filled in and there is no other way to make a set.
85
+ export type {
86
+ ResolvedAccessors,
87
+ TreeAccessors,
88
+ TreeItem,
89
+ TreeItemId,
90
+ TreeRow,
91
+ TreeGroup,
92
+ } from './rows.js';
93
+ export {
94
+ branchEdges,
95
+ findItem,
96
+ resolveAccessors,
97
+ visibleRows,
98
+ } from './rows.js';
99
+
100
+ /** One level of indent. */
101
+ const INDENT = 14;
102
+ /** The twisty's hit box — what a file browser lets you click to peek into a
103
+ * folder without selecting it. It stays this wide whatever the glyph does. */
104
+ const TWISTY = 12;
105
+ /** The chevron inside it. A chevron's long axis is its box and its short one
106
+ * is half of that, so `size` for one reads as its width. */
107
+ const TWISTY_GLYPH = 10;
108
+ const ROW_HEIGHT = 22;
109
+ /** Rows kept either side of the viewport, so a fast scroll does not show a
110
+ * gap before the next frame catches up. */
111
+ const OVERSCAN = 6;
112
+ /**
113
+ * What to build before the viewport has been measured. `onViewport` cannot
114
+ * arrive until layout has run, which is a frame after the first commit, so
115
+ * there is always one render that has to guess — and guessing "all of them"
116
+ * puts a hundred thousand rows in the tree for a frame.
117
+ */
118
+ const ASSUMED_ROWS = 40;
119
+ /**
120
+ * Where `virtual="auto"` starts virtualizing.
121
+ *
122
+ * Well above any viewport, so a tree that is merely long is still built whole
123
+ * and keeps the two things virtualization costs: a row may be any height, and
124
+ * every row is in the accessibility tree. Well below the point where building
125
+ * every row is felt.
126
+ */
127
+ const VIRTUAL_THRESHOLD = 200;
128
+
129
+ const s = createStyles({
130
+ root: { flexGrow: 1, minHeight: 0, overflow: 'scroll' },
131
+ row: {
132
+ flexShrink: 0,
133
+ flexDirection: 'row',
134
+ alignItems: 'center',
135
+ gap: 4,
136
+ paddingEnd: 8,
137
+ paddingTop: 3,
138
+ paddingBottom: 3,
139
+ cursor: 'pointer',
140
+ transition: { backgroundColor: 80 },
141
+ },
142
+ twisty: {
143
+ width: TWISTY,
144
+ height: TWISTY,
145
+ flexShrink: 0,
146
+ alignItems: 'center',
147
+ justifyContent: 'center',
148
+ },
149
+ guide: { flexShrink: 0, alignSelf: 'stretch' },
150
+ /**
151
+ * The label **wraps**, and the row grows to hold it.
152
+ *
153
+ * This is the whole point of rows being measured rather than fixed: a name
154
+ * too long for the pane becomes two lines of a taller row, not two lines
155
+ * drawn over the row below. An app that wants the one-line, clipped look a
156
+ * file browser has says so — `styles={{ label: { textWrap: 'nowrap' } }}` —
157
+ * and gets it for the whole tree.
158
+ *
159
+ * `textBoxTrim` makes the box the letters rather than the font's ascent and
160
+ * descent, so a label centres on what can be seen. That is what core's
161
+ * `labelContent` gives every label in the widget set.
162
+ */
163
+ label: {
164
+ flexShrink: 1,
165
+ minWidth: 0,
166
+ textBoxTrim: 'cap-alphabetic',
167
+ },
168
+ subtree: { flexShrink: 0 },
169
+ spacer: { flexShrink: 0 },
170
+ });
171
+
172
+ // --- what the seams are told -----------------------------------------------
173
+
174
+ /** A row, plus what only the render knows about it. */
175
+ export interface TreeRowState<T> extends TreeRow<T> {
176
+ selected: boolean;
177
+ /**
178
+ * The ink the row is painted in.
179
+ *
180
+ * Handed over by name because **colour does not cascade into a drawing**:
181
+ * an `<Icon>` or a `<canvas mono>` takes its colour from its own style, so
182
+ * a glyph that has to stay legible on a selected row has to be told. The
183
+ * `<text>` in the default label needs nothing — text does inherit.
184
+ */
185
+ color: string;
186
+ /** Open or close this row's branch. Ignored on a leaf. */
187
+ toggle: (open?: boolean) => void;
188
+ /** Make this row the selection, as a click would. */
189
+ select: () => void;
190
+ }
191
+
192
+ /** What `renderToggle` is told. */
193
+ export interface TreeToggleState<T> extends TreeRowState<T> {
194
+ /** The size the default chevron is drawn at. */
195
+ size: number;
196
+ }
197
+
198
+ /**
199
+ * One column of a row's indent, as `renderGuide` sees it — the tree's branch
200
+ * edge.
201
+ *
202
+ * There is one call per level of depth, outermost first. `own` marks the
203
+ * row's own column, where a `├─` or `└─` connector goes; every earlier column
204
+ * belongs to an ancestor and only ever carries a `│`.
205
+ */
206
+ export interface TreeGuideState<T> {
207
+ row: TreeRowState<T>;
208
+ /** 0 is the outermost column. */
209
+ level: number;
210
+ /** A line passes through this column and continues below this row. */
211
+ continues: boolean;
212
+ /** This is the row's own column rather than an ancestor's. */
213
+ own: boolean;
214
+ /** How wide the column is: the `indent` prop. */
215
+ width: number;
216
+ /** The row's **minimum** height — `rowHeight`. The column stretches to
217
+ * whatever the row turned out to be, and a drawing is told that real size
218
+ * in its own `onDraw`, so this is a hint rather than a measurement.
219
+ * A `<canvas cacheKey>` need not name it: the paint cache already keys on
220
+ * the node's laid-out size. */
221
+ height: number;
222
+ }
223
+
224
+ /** What `renderSubtree` is told, in `layout="nested"`. */
225
+ export interface TreeSubtreeState<T> {
226
+ /** The row the subtree hangs off. Never null: the roots are not a
227
+ * subtree, they are the tree. */
228
+ parent: TreeRow<T>;
229
+ /** The depth of the rows inside it — one more than `parent.depth`. */
230
+ depth: number;
231
+ }
232
+
233
+ /** The expansion that just changed, alongside the whole set. */
234
+ export interface TreeExpandChange<T> {
235
+ id: TreeItemId;
236
+ item: T;
237
+ open: boolean;
238
+ }
239
+
240
+ /** The style overrides, one per part the tree draws. */
241
+ export interface TreeStyles<T> {
242
+ /** A function is called per rendered row, so a style can follow the row's
243
+ * own state without a `renderContent` that repaints everything. */
244
+ row?: StyleProp | ((state: TreeRowState<T>) => StyleProp);
245
+ toggle?: StyleProp;
246
+ guide?: StyleProp | ((state: TreeGuideState<T>) => StyleProp);
247
+ label?: StyleProp;
248
+ subtree?: StyleProp;
249
+ }
250
+
251
+ /**
252
+ * A `<Tree>`'s imperative side.
253
+ *
254
+ * `handleKey` is the one worth knowing about: a filter box above a tree holds
255
+ * the keyboard, and forwarding the arrows to this is how the list below it
256
+ * still walks. It reports whether the tree took the key, so the caller keeps
257
+ * whatever it did not.
258
+ */
259
+ export interface TreeHandle<T = TreeItem> {
260
+ focus: () => void;
261
+ select: (id: TreeItemId | null) => void;
262
+ /** Open or close a branch by id, anywhere in the tree — including one no
263
+ * row is showing. `false` when the id names nothing loaded. */
264
+ setExpanded: (id: TreeItemId, open?: boolean) => boolean;
265
+ /** Bring a row into view, expanding nothing — a collapsed ancestor means
266
+ * there is no row to scroll to, and this reports `false`. */
267
+ scrollToItem: (id: TreeItemId) => boolean;
268
+ handleKey: (ev: KeyboardEvent) => boolean;
269
+ /** The rows on screen right now, in draw order. */
270
+ rows: () => readonly TreeRow<T>[];
271
+ }
272
+
273
+ type BoxProps = Host['box'];
274
+
275
+ export interface TreeProps<T = TreeItem>
276
+ extends
277
+ TreeAccessors<T>,
278
+ Omit<BoxProps, 'style' | 'children' | 'ref' | 'onKeyDown'> {
279
+ /** The roots. */
280
+ items?: readonly T[];
281
+
282
+ /** Controlled expansion. */
283
+ expanded?: readonly TreeItemId[];
284
+ defaultExpanded?: readonly TreeItemId[];
285
+ /**
286
+ * The whole open set, plus the one row that changed — which is what lazy
287
+ * loading needs: `change.open && !loaded.has(change.id)` is the fetch.
288
+ */
289
+ onExpandedChange?: (
290
+ expanded: TreeItemId[],
291
+ change: TreeExpandChange<T>,
292
+ ) => void;
293
+
294
+ /** Controlled selection. One row: see the note on multiple selection in
295
+ * the component's doc comment. */
296
+ selected?: TreeItemId | null;
297
+ defaultSelected?: TreeItemId | null;
298
+ onSelect?: (id: TreeItemId, item: T) => void;
299
+ /** The *open* gesture on top of selection — a double click, Enter, or
300
+ * Space. On a branch it also toggles. */
301
+ onActivate?: (id: TreeItemId, item: T) => void;
302
+
303
+ /** One level of indent, in pixels. `0` puts the whole indent in
304
+ * `renderSubtree`'s hands instead. */
305
+ indent?: number;
306
+ /**
307
+ * The **shortest** a row may be, in pixels. Default 22.
308
+ *
309
+ * A row is not this tall, it is at least this tall: it grows to whatever
310
+ * its content needs, so a label that wraps to two lines gets a row of two
311
+ * lines. Virtualization measures rows rather than assuming them, which is
312
+ * what makes that safe — see {@link estimatedRowHeight}.
313
+ */
314
+ rowHeight?: number;
315
+ /**
316
+ * What a row that has not been measured yet is assumed to be, while
317
+ * virtualizing. Defaults to `rowHeight`.
318
+ *
319
+ * Only the rows on screen have ever been laid out, so the scrollbar is
320
+ * this guess for everything else, and it converges as you scroll. Set it
321
+ * when rows are typically much taller than `rowHeight` — a tree of
322
+ * two-line rows with the default guess starts with a scrollbar that thinks
323
+ * the tree is half its real length.
324
+ */
325
+ estimatedRowHeight?: number;
326
+
327
+ /**
328
+ * Build only the rows on screen. `'auto'` (the default) turns it on past
329
+ * {@link VIRTUAL_THRESHOLD} visible rows.
330
+ *
331
+ * Not available in `layout="nested"`, where the rows are not siblings and
332
+ * a slice of them is not a subtree.
333
+ */
334
+ virtual?: boolean | 'auto';
335
+ /** Rows built either side of the viewport. */
336
+ overscan?: number;
337
+
338
+ /**
339
+ * `'flat'` (the default) makes every row a sibling — which is what lets the
340
+ * tree virtualize, and what the branch guides are drawn per row for.
341
+ *
342
+ * `'nested'` puts each expanded branch's rows inside a container of their
343
+ * own, for a `renderSubtree` that wants to draw a background, a rule down
344
+ * the group, or its own indent. Rows carry their own indent in both, so a
345
+ * subtree container that indents as well should pass `indent={0}`.
346
+ */
347
+ layout?: 'flat' | 'nested';
348
+
349
+ /** The open/close control, inside its hit box. */
350
+ renderToggle?: (state: TreeToggleState<T>) => ReactNode;
351
+ /** One column of the indent — the branch edge. Nothing by default. */
352
+ renderGuide?: (state: TreeGuideState<T>) => ReactNode;
353
+ /** The label cell. An icon in front of the text goes here. */
354
+ renderLabel?: (state: TreeRowState<T>) => ReactNode;
355
+ /**
356
+ * Everything inside the row box, given what would have been there.
357
+ *
358
+ * The row *box* stays this component's — it carries the height
359
+ * virtualization counts on, the role and the aria the tree is read through,
360
+ * and the click that selects. Style it with `styles.row`.
361
+ */
362
+ renderContent?: (state: TreeRowState<T>, content: ReactNode[]) => ReactNode;
363
+ /** The subtree container, in `layout="nested"`. */
364
+ renderSubtree?: (state: TreeSubtreeState<T>, rows: ReactNode) => ReactNode;
365
+
366
+ styles?: TreeStyles<T>;
367
+ style?: StyleProp;
368
+ ref?: Ref<TreeHandle<T>>;
369
+ /** react-x11's queries read this off `props` at run time; its element
370
+ * declarations do not carry it, so it is declared here and reaches the
371
+ * root box through the rest spread. */
372
+ 'data-testname'?: string;
373
+ }
374
+
375
+ /** A string or a number becomes a `<text>`; anything else is already a
376
+ * node. */
377
+ function labelNode(label: ReactNode, style: StyleProp): ReactNode {
378
+ return typeof label === 'string' || typeof label === 'number'
379
+ ? hx('text', { key: 'label', style }, String(label))
380
+ : label;
381
+ }
382
+
383
+ /**
384
+ * `<Tree items />` — a disclosure tree.
385
+ *
386
+ * <Tree items={[{ id: 'src', label: 'src', children: [...] }]} />
387
+ *
388
+ * An item with a `children` array is a branch, **even when the array is
389
+ * empty** — that is how a directory shows a twisty before anything has read
390
+ * it. A branch whose children are not loaded at all says `branch: true`, and
391
+ * fills them in from `onExpandedChange`.
392
+ *
393
+ * Expansion and selection are each controlled (`expanded` + `onExpandedChange`,
394
+ * `selected` + `onSelect`) or uncontrolled (`defaultExpanded`,
395
+ * `defaultSelected`).
396
+ *
397
+ * The tree is a single tab stop. Up/Down walk the visible rows, Right expands
398
+ * a branch and then steps into it, Left collapses and then steps out to the
399
+ * parent, PageUp/PageDown move by a viewport, Home/End jump to the ends,
400
+ * Enter and Space activate, and typing letters jumps to a matching row — the
401
+ * same type-ahead core's `Select` and menus use.
402
+ *
403
+ * **The focus is on the tree, not on the row.** Core's tree focused each row
404
+ * node; a virtualized row is unmounted the moment it scrolls out of view and
405
+ * the focus would go with it, so the container is the focusable thing and the
406
+ * selection is the cursor. That is `Table`'s model, and the honest caveat is
407
+ * the one `Table` carries: while virtualizing, only the rendered rows are in
408
+ * the accessibility tree — the same rows a sighted user can see.
409
+ *
410
+ * **Selection is one row.** Multiple selection is not a prop because there is
411
+ * no version of it everybody agrees on (does Shift extend from the anchor or
412
+ * from the cursor? does Ctrl+click on a branch take its children?), and every
413
+ * such policy is expressible on top of what is here: hold the set yourself,
414
+ * pass `selected` for the cursor, and paint the rest from `styles.row`.
415
+ */
416
+ export function Tree<T = TreeItem>({
417
+ items = [],
418
+ expanded,
419
+ defaultExpanded,
420
+ onExpandedChange,
421
+ selected,
422
+ defaultSelected,
423
+ onSelect,
424
+ onActivate,
425
+ indent = INDENT,
426
+ rowHeight = ROW_HEIGHT,
427
+ estimatedRowHeight,
428
+ virtual = 'auto',
429
+ overscan = OVERSCAN,
430
+ layout = 'flat',
431
+ renderToggle,
432
+ renderGuide,
433
+ renderLabel,
434
+ renderContent,
435
+ renderSubtree,
436
+ styles,
437
+ style,
438
+ ref,
439
+ // the accessors, pulled out so the rest can be spread onto the box
440
+ getId,
441
+ getLabel,
442
+ getText,
443
+ getChildren,
444
+ isBranch,
445
+ isDisabled,
446
+ // ours to chain rather than to hand over: virtualization is measured
447
+ // through both of these
448
+ onScroll,
449
+ onViewport,
450
+ ...boxProps
451
+ }: TreeProps<T>): ReactElement {
452
+ const theme = useTheme();
453
+ const rtl = useDirection() === 'rtl';
454
+ const [ownExpanded, setOwnExpanded] = useState<ReadonlySet<TreeItemId>>(
455
+ () => new Set(defaultExpanded),
456
+ );
457
+ const [ownSelected, setOwnSelected] = useState<TreeItemId | null>(
458
+ defaultSelected ?? null,
459
+ );
460
+ const [view, setView] = useState({ top: 0, height: 0 });
461
+ // Bumped by a measurement pass that found a row taller or shorter than the
462
+ // index believed. It is the only reason the component re-renders for a
463
+ // measurement, and a pass that finds nothing new does not bump it, which is
464
+ // what makes measure → render → measure converge instead of spinning.
465
+ const [, setMeasured] = useState(0);
466
+ const typeAhead = useTypeAhead();
467
+ const scroller = useRef<ScrollableNode | null>(null);
468
+ /** The rows on screen, by id — with the index each was drawn at, so a
469
+ * measurement pass does not have to search the row list for it. */
470
+ const rowNodes = useRef(
471
+ new Map<TreeItemId, { node: DrawnNode; at: number }>(),
472
+ );
473
+ const estimate = estimatedRowHeight ?? rowHeight;
474
+ // `useState` for its lazy initializer rather than `useRef`: one index per
475
+ // mounted tree, built once. Nothing ever calls the setter — what it holds
476
+ // is mutable and its changes are announced through `setMeasured`.
477
+ const [heights] = useState(() => new RowHeights(estimate));
478
+
479
+ const accessors: ResolvedAccessors<T> = useMemo(
480
+ () =>
481
+ resolveAccessors<T>({
482
+ getId,
483
+ getLabel,
484
+ getText,
485
+ getChildren,
486
+ isBranch,
487
+ isDisabled,
488
+ }),
489
+ [getId, getLabel, getText, getChildren, isBranch, isDisabled],
490
+ );
491
+
492
+ const openSet = useMemo(
493
+ () => (expanded ? new Set(expanded) : ownExpanded),
494
+ [expanded, ownExpanded],
495
+ );
496
+ const current = selected === undefined ? ownSelected : selected;
497
+ const rows = useMemo(
498
+ () => visibleRows(items, openSet, accessors),
499
+ [items, openSet, accessors],
500
+ );
501
+
502
+ // Held-down or fast keys arrive in a burst, and every handler in that burst
503
+ // sees the render it started from — so what is open and what is selected
504
+ // are mirrored here and updated the moment they change, or three Downs in a
505
+ // row all step off the same starting point.
506
+ const openRef = useRef(openSet);
507
+ openRef.current = openSet;
508
+ const currentRef = useRef(current);
509
+ currentRef.current = current;
510
+ const rowsRef = useRef(rows);
511
+ rowsRef.current = rows;
512
+ const itemsRef = useRef(items);
513
+ itemsRef.current = items;
514
+ const viewRef = useRef(view);
515
+ viewRef.current = view;
516
+
517
+ const virtualizing =
518
+ layout === 'flat' &&
519
+ (virtual === true ||
520
+ (virtual === 'auto' && rows.length > VIRTUAL_THRESHOLD));
521
+
522
+ // The index is re-pointed at the rows about to be drawn before anything
523
+ // asks it where they are. `rows` is memoized, so this is an identity check
524
+ // on every render that did not change the tree.
525
+ const index = heights;
526
+ index.sync(rows, estimate);
527
+
528
+ // The slice worth building: what is on screen, plus a little either side.
529
+ // Which rows those are is a question for the height index now — with rows
530
+ // of different heights there is no division that answers it.
531
+ const first = virtualizing
532
+ ? Math.max(0, index.indexAt(view.top) - overscan)
533
+ : 0;
534
+ let last = rows.length;
535
+ if (virtualizing) {
536
+ if (view.height > 0) {
537
+ last = Math.min(
538
+ rows.length,
539
+ index.indexAt(view.top + view.height) + 1 + overscan,
540
+ );
541
+ } else {
542
+ // Before the first layout there is no viewport to measure against, and
543
+ // guessing "all of them" would put a hundred thousand rows in the tree
544
+ // for a frame.
545
+ last = Math.min(rows.length, first + ASSUMED_ROWS);
546
+ }
547
+ }
548
+ /** Where the slice starts, and how much of the list is below it — the two
549
+ * spacers that keep the scrollbar measuring the whole tree. */
550
+ const above = virtualizing ? index.offsetAt(first) : 0;
551
+ const below = virtualizing ? index.total() - index.offsetAt(last) : 0;
552
+
553
+ const setExpandedSet = useCallback(
554
+ (next: ReadonlySet<TreeItemId>, change: TreeExpandChange<T>): void => {
555
+ openRef.current = next;
556
+ if (expanded === undefined) setOwnExpanded(next);
557
+ onExpandedChange?.([...next], change);
558
+ },
559
+ [expanded, onExpandedChange],
560
+ );
561
+
562
+ const toggleId = useCallback(
563
+ (id: TreeItemId, item: T, open?: boolean): void => {
564
+ const next = new Set(openRef.current);
565
+ const shouldOpen = open ?? !next.has(id);
566
+ if (shouldOpen) next.add(id);
567
+ else next.delete(id);
568
+ setExpandedSet(next, { id, item, open: shouldOpen });
569
+ },
570
+ [setExpandedSet],
571
+ );
572
+
573
+ /**
574
+ * Put a row in view.
575
+ *
576
+ * A mounted row can say where it is, and `scrollIntoView` then works
577
+ * whatever height it turned out to be — which is what a tree that is *not*
578
+ * virtualizing wants, since nothing has measured its rows. A row that is not
579
+ * mounted has no geometry to ask about, and while virtualizing that is the
580
+ * normal case, so the height index answers instead: where the row starts,
581
+ * and how tall it is or is estimated to be.
582
+ */
583
+ const reveal = useCallback((at: number): void => {
584
+ const box = scroller.current;
585
+ const row = rowsRef.current[at];
586
+ if (!box || !row) return;
587
+ const drawn = rowNodes.current.get(row.id);
588
+ if (drawn) {
589
+ box.scrollIntoView(drawn.node);
590
+ return;
591
+ }
592
+ const top = heights.offsetAt(at);
593
+ const rowH = heights.heightAt(at);
594
+ const height = viewRef.current.height;
595
+ if (top < box.scrollY) box.scrollTo({ y: top });
596
+ else if (height > 0 && top + rowH > box.scrollY + height) {
597
+ box.scrollTo({ y: top + rowH - height });
598
+ }
599
+ }, []);
600
+
601
+ /**
602
+ * Read back what the rows on screen actually laid out at.
603
+ *
604
+ * The one thing that makes rows of different heights work, and the reason
605
+ * it is not simply "read the height in an effect": **layout runs after
606
+ * React's effects, on the frame flush**, so a `useEffect` sees the
607
+ * *previous* pass's geometry — zero, on the render that created the row.
608
+ * This runs a tick later, when `abs` is current.
609
+ *
610
+ * Idempotent by construction. A row whose measurement has not changed
611
+ * reports no change, so the second pass over the same rows costs a map walk
612
+ * and re-renders nothing, and measure → render → measure terminates.
613
+ */
614
+ const measureRows = useCallback((): void => {
615
+ if (!virtualizing) return;
616
+ const box = scroller.current;
617
+ const rows = rowsRef.current;
618
+ const idx = heights;
619
+ // Rows above the top of the viewport are the ones that move the content
620
+ // under it, so their total change is what has to come back out of the
621
+ // scroll offset — otherwise measuring a row you have already scrolled
622
+ // past yanks the list under the pointer.
623
+ const anchor = box ? idx.indexAt(box.scrollY) : 0;
624
+ let shift = 0;
625
+ let changed = false;
626
+ for (const [id, { node, at }] of rowNodes.current) {
627
+ if (rows[at]?.id !== id) continue; // drawn against a list that has moved
628
+ const height = node.abs.height;
629
+ const was = idx.heightAt(at);
630
+ if (!idx.measure(id, at, height)) continue;
631
+ changed = true;
632
+ if (at < anchor) shift += height - was;
633
+ }
634
+ if (!changed) return;
635
+ if (shift !== 0 && box) {
636
+ box.scrollTo({ y: Math.max(0, box.scrollY + shift) });
637
+ }
638
+ setMeasured((n) => n + 1);
639
+ }, [virtualizing]);
640
+
641
+ useEffect(() => {
642
+ if (!virtualizing) return undefined;
643
+ const id = afterLayout(measureRows);
644
+ return () => cancelAfterLayout(id);
645
+ });
646
+
647
+ const goTo = useCallback(
648
+ (row: TreeRow<T> | null | undefined): void => {
649
+ if (!row) return;
650
+ currentRef.current = row.id;
651
+ if (selected === undefined) setOwnSelected(row.id);
652
+ onSelect?.(row.id, row.item);
653
+ reveal(row.index);
654
+ },
655
+ [selected, onSelect, reveal],
656
+ );
657
+
658
+ const activate = useCallback(
659
+ (row: TreeRow<T>): void => {
660
+ if (row.branch) toggleId(row.id, row.item);
661
+ onActivate?.(row.id, row.item);
662
+ },
663
+ [toggleId, onActivate],
664
+ );
665
+
666
+ /** Returns whether the key was the tree's, so a control that forwards its
667
+ * keys here keeps the ones it did not use. */
668
+ const handleKey = useCallback(
669
+ (ev: KeyboardEvent): boolean => {
670
+ const rows = rowsRef.current;
671
+ if (!rows.length) return false;
672
+ const index = rows.findIndex((r) => r.id === currentRef.current);
673
+ const row = rows[index];
674
+ const step = (delta: number): TreeRow<T> | null => {
675
+ for (let i = index + delta; i >= 0 && i < rows.length; i += delta) {
676
+ if (!rows[i].disabled) return rows[i];
677
+ }
678
+ return null;
679
+ };
680
+ /** The nearest enabled row at or before `to`, walking `dir` if the
681
+ * landing row is disabled — what a page jump needs. */
682
+ const nearest = (to: number, dir: number): TreeRow<T> | null => {
683
+ const at = Math.max(0, Math.min(rows.length - 1, to));
684
+ for (let i = at; i >= 0 && i < rows.length; i += dir) {
685
+ if (!rows[i].disabled) return rows[i];
686
+ }
687
+ return null;
688
+ };
689
+ // Deeper is the direction the indent grows in, which is the direction
690
+ // the text runs — so it is Left that opens a branch in a mirrored tree,
691
+ // and the two arrows swap wholesale rather than the tree growing a
692
+ // second set of cases.
693
+ const deeper = rtl ? XK_LEFT : XK_RIGHT;
694
+ const shallower = rtl ? XK_RIGHT : XK_LEFT;
695
+ /**
696
+ * How far a page key moves, in rows.
697
+ *
698
+ * A viewport's worth, which with rows of different heights is not a
699
+ * division: it is "where does the row `index` sits at end up if I add a
700
+ * viewport to its offset". One row of overlap is kept, the way every
701
+ * document viewer does, so a page down leaves a line of context.
702
+ */
703
+ const pageFrom = (from: number, dir: number): number => {
704
+ const idx = heights;
705
+ const viewport = viewRef.current.height;
706
+ if (viewport <= 0) return from + dir;
707
+ const at = Math.max(0, Math.min(rows.length - 1, from));
708
+ const target =
709
+ idx.offsetAt(at) + dir * Math.max(1, viewport - rowHeight);
710
+ const landed = idx.indexAt(Math.max(0, target));
711
+ // never stand still: a row taller than the viewport would otherwise
712
+ // make Page Down a no-op
713
+ return landed === at ? at + dir : landed;
714
+ };
715
+
716
+ switch (ev.keysym) {
717
+ case XK_UP:
718
+ goTo(step(-1));
719
+ return true;
720
+ case XK_DOWN:
721
+ goTo(step(1));
722
+ return true;
723
+ case XK_PAGE_UP:
724
+ goTo(nearest(index < 0 ? 0 : pageFrom(index, -1), 1));
725
+ return true;
726
+ case XK_PAGE_DOWN:
727
+ goTo(nearest(index < 0 ? pageFrom(0, 1) : pageFrom(index, 1), -1));
728
+ return true;
729
+ case deeper:
730
+ // open it, then walk into it — one key does both, in order
731
+ if (row?.branch && !row.open) toggleId(row.id, row.item, true);
732
+ else if (row?.branch) goTo(step(1));
733
+ return true;
734
+ case shallower:
735
+ if (row?.branch && row.open) toggleId(row.id, row.item, false);
736
+ else if (row?.parent) goTo(row.parent);
737
+ return true;
738
+ case XK_HOME:
739
+ goTo(rows.find((r) => !r.disabled));
740
+ return true;
741
+ case XK_END:
742
+ goTo([...rows].reverse().find((r) => !r.disabled));
743
+ return true;
744
+ case XK_RETURN:
745
+ if (row) activate(row);
746
+ return true;
747
+ default:
748
+ break;
749
+ }
750
+ if (ev.codepoint === 32) {
751
+ if (row) activate(row);
752
+ return true;
753
+ }
754
+ const char = typeAheadChar(ev);
755
+ if (!char) return false;
756
+ const found = typeAhead(
757
+ char,
758
+ rows,
759
+ index < 0 ? null : index,
760
+ (r: TreeRow<T>) => accessors.getText(r.item),
761
+ (r: TreeRow<T>) => !r.disabled,
762
+ );
763
+ if (found >= 0) goTo(rows[found]);
764
+ return found >= 0;
765
+ },
766
+ [rtl, rowHeight, goTo, toggleId, activate, typeAhead, accessors],
767
+ );
768
+
769
+ useImperativeHandle(
770
+ ref,
771
+ (): TreeHandle<T> => ({
772
+ focus: () => {
773
+ scroller.current?.focus();
774
+ },
775
+ select: (id) => {
776
+ const row = rowsRef.current.find((r) => r.id === id);
777
+ if (row) goTo(row);
778
+ else if (id === null) {
779
+ currentRef.current = null;
780
+ if (selected === undefined) setOwnSelected(null);
781
+ }
782
+ },
783
+ setExpanded: (id, open) => {
784
+ // An id nobody can see is still legitimately expandable — a lazy load
785
+ // finishing under a branch the user collapsed again, say — so the
786
+ // whole tree is searched rather than the rows on screen.
787
+ //
788
+ // An id that is in neither is a no-op, and that is the point: the
789
+ // change this reports carries the item, `TreeExpandChange<T>.item` is
790
+ // `T`, and an id nothing answers to has no item to put there. Doing
791
+ // nothing beats reporting an expansion of `undefined`.
792
+ const item =
793
+ rowsRef.current.find((r) => r.id === id)?.item ??
794
+ findItem(itemsRef.current, id, accessors);
795
+ if (item === undefined) return false;
796
+ toggleId(id, item, open);
797
+ return true;
798
+ },
799
+ scrollToItem: (id) => {
800
+ const row = rowsRef.current.find((r) => r.id === id);
801
+ if (!row) return false;
802
+ reveal(row.index);
803
+ return true;
804
+ },
805
+ handleKey,
806
+ rows: () => rowsRef.current,
807
+ }),
808
+ [goTo, toggleId, reveal, handleKey, selected, accessors],
809
+ );
810
+
811
+ // --- rendering -----------------------------------------------------------
812
+
813
+ const rowStyleProp = styles?.row;
814
+ const guideStyleProp = styles?.guide;
815
+
816
+ const renderOneRow = (row: TreeRow<T>): ReactElement => {
817
+ const isSelected = row.id === current;
818
+ const color = row.disabled
819
+ ? theme.textMuted
820
+ : isSelected
821
+ ? theme.hoverText
822
+ : theme.text;
823
+ const state: TreeRowState<T> = {
824
+ ...row,
825
+ selected: isSelected,
826
+ color,
827
+ toggle: (open?: boolean) => toggleId(row.id, row.item, open),
828
+ select: () => goTo(row),
829
+ };
830
+
831
+ const content: ReactNode[] = [];
832
+
833
+ // The indent. With no guide seam it is one padding value rather than
834
+ // `depth` empty boxes — a tree ten deep would otherwise build ten nodes
835
+ // per row to draw nothing.
836
+ if (renderGuide && row.depth > 0) {
837
+ const edges = branchEdges(row);
838
+ for (let level = 0; level < row.depth; level++) {
839
+ const guide: TreeGuideState<T> = {
840
+ row: state,
841
+ level,
842
+ continues: edges[level],
843
+ own: level === row.depth - 1,
844
+ width: indent,
845
+ height: rowHeight,
846
+ };
847
+ content.push(
848
+ hx(
849
+ 'box',
850
+ {
851
+ key: `guide${level}`,
852
+ style: [
853
+ s.guide,
854
+ { width: indent },
855
+ typeof guideStyleProp === 'function'
856
+ ? guideStyleProp(guide)
857
+ : guideStyleProp,
858
+ ],
859
+ },
860
+ renderGuide(guide),
861
+ ),
862
+ );
863
+ }
864
+ }
865
+
866
+ const toggleState: TreeToggleState<T> = { ...state, size: TWISTY_GLYPH };
867
+ content.push(
868
+ hx(
869
+ 'box',
870
+ {
871
+ key: 'toggle',
872
+ style: [s.twisty, styles?.toggle],
873
+ // The twisty is its own hit target: clicking it opens the branch
874
+ // without moving the selection, the way a file browser lets you
875
+ // peek inside a folder you have not chosen.
876
+ onClick: row.branch
877
+ ? (ev) => {
878
+ ev.stopPropagation();
879
+ toggleId(row.id, row.item);
880
+ }
881
+ : undefined,
882
+ },
883
+ renderToggle
884
+ ? renderToggle(toggleState)
885
+ : row.branch
886
+ ? React.createElement(Icon, {
887
+ name: row.open
888
+ ? 'chevronDown'
889
+ : rtl
890
+ ? 'chevronLeft'
891
+ : 'chevronRight',
892
+ size: TWISTY_GLYPH,
893
+ // dimmer than the label on a resting row, and the row's own
894
+ // ink once it is selected
895
+ style: isSelected ? undefined : { color: theme.textMuted },
896
+ })
897
+ : null,
898
+ ),
899
+ );
900
+
901
+ content.push(
902
+ renderLabel
903
+ ? // Keyed here rather than by the app, for the reason `renderSubtree`
904
+ // is: the label sits in an array beside the guides and the twisty,
905
+ // and "add a key to the box you return" is not something a render
906
+ // prop should have to know.
907
+ React.createElement(
908
+ React.Fragment,
909
+ { key: 'label' },
910
+ renderLabel(state),
911
+ )
912
+ : labelNode(accessors.getLabel(row.item), [s.label, styles?.label]),
913
+ );
914
+
915
+ return hx(
916
+ 'box',
917
+ {
918
+ key: String(row.id),
919
+ role: 'treeitem',
920
+ 'aria-level': row.depth + 1,
921
+ 'aria-selected': isSelected,
922
+ 'aria-expanded': row.branch ? row.open : undefined,
923
+ 'aria-posinset': row.posInSet,
924
+ 'aria-setsize': row.setSize,
925
+ // `disabled` rather than `aria-disabled`: on a react-x11 node it is
926
+ // the real thing — it clears the AT-SPI ENABLED/SENSITIVE states and
927
+ // selects the `:disabled` style block — and there is no aria spelling
928
+ // of it to write instead.
929
+ disabled: row.disabled || undefined,
930
+ // The index the row was drawn at travels with the node, so measuring
931
+ // does not have to search a hundred thousand rows for where it is.
932
+ // It can go stale — the rows may move before the tick that measures —
933
+ // and both this and the height index check it rather than trust it.
934
+ ref: (node: DrawnNode | null) => {
935
+ if (node) rowNodes.current.set(row.id, { node, at: row.index });
936
+ else rowNodes.current.delete(row.id);
937
+ },
938
+ onClick: (ev) => {
939
+ if (row.disabled) return;
940
+ goTo(row);
941
+ // Select on the first click, open on the second — the gesture every
942
+ // file list has. `detail` is the click count the renderer already
943
+ // counts for text selection.
944
+ if (ev.detail === 2) activate(row);
945
+ },
946
+ style: [
947
+ s.row,
948
+ // A floor, not a height. The row grows to whatever its content
949
+ // needs — a wrapped label, two lines, a thumbnail — and the height
950
+ // index reads back what it actually became.
951
+ { minHeight: rowHeight },
952
+ // The indent is what says "inside", so it is measured from the edge
953
+ // the row's label begins at.
954
+ { paddingStart: renderGuide ? 4 : 4 + row.depth * indent },
955
+ {
956
+ backgroundColor: isSelected ? theme.hoverBackground : 'transparent',
957
+ // The row's ink, said once: `color` inherits, so the label takes
958
+ // it without being handed it.
959
+ color,
960
+ },
961
+ !row.disabled && {
962
+ ':hover': {
963
+ backgroundColor: isSelected
964
+ ? theme.hoverBackground
965
+ : theme.surfaceHover,
966
+ },
967
+ // The selection only moves on the release, and `:active` marks
968
+ // the whole press chain, so a press on the label or the twisty
969
+ // still darkens the row it is in.
970
+ ':active': {
971
+ backgroundColor: isSelected
972
+ ? theme.accentActive
973
+ : theme.surfaceActive,
974
+ },
975
+ },
976
+ typeof rowStyleProp === 'function'
977
+ ? rowStyleProp(state)
978
+ : rowStyleProp,
979
+ ],
980
+ },
981
+ renderContent ? renderContent(state, content) : content,
982
+ );
983
+ };
984
+
985
+ /** `layout="nested"`: the same rows, wrapped group by group. */
986
+ const renderGroup = (group: TreeGroup<T>, key: string): ReactNode => {
987
+ const children = group.rows.map((node, i) =>
988
+ isGroup(node) ? renderGroup(node, `${key}.${i}`) : renderOneRow(node),
989
+ );
990
+ if (!group.parent) return children;
991
+ const state: TreeSubtreeState<T> = {
992
+ parent: group.parent,
993
+ depth: group.parent.depth + 1,
994
+ };
995
+ // The key is this component's either way, and a fragment is how a seam
996
+ // gets one without being told to write it. A `renderSubtree` that had to
997
+ // remember a key would get it wrong the obvious way — keying on the
998
+ // parent id, which is already the key of the parent *row* beside it.
999
+ if (renderSubtree) {
1000
+ return React.createElement(
1001
+ React.Fragment,
1002
+ { key: `subtree:${group.parent.id}` },
1003
+ renderSubtree(state, children),
1004
+ );
1005
+ }
1006
+ return hx(
1007
+ 'box',
1008
+ {
1009
+ key: `subtree:${group.parent.id}`,
1010
+ role: 'group',
1011
+ style: [s.subtree, styles?.subtree],
1012
+ },
1013
+ children,
1014
+ );
1015
+ };
1016
+
1017
+ const body: ReactNode[] = [];
1018
+ if (layout === 'nested') {
1019
+ body.push(renderGroup(groupRows(rows), 'root'));
1020
+ } else {
1021
+ if (virtualizing && first > 0) {
1022
+ body.push(
1023
+ hx('box', {
1024
+ key: 'spacer:before',
1025
+ style: [s.spacer, { height: above }],
1026
+ }),
1027
+ );
1028
+ }
1029
+ for (let i = first; i < last; i++) body.push(renderOneRow(rows[i]));
1030
+ if (virtualizing && last < rows.length) {
1031
+ body.push(
1032
+ hx('box', {
1033
+ key: 'spacer:after',
1034
+ style: [s.spacer, { height: below }],
1035
+ }),
1036
+ );
1037
+ }
1038
+ }
1039
+
1040
+ return hx(
1041
+ 'box',
1042
+ {
1043
+ theme,
1044
+ role: 'tree',
1045
+ // The tree takes the focus, not the row — see the doc comment.
1046
+ focusable: true,
1047
+ ...boxProps,
1048
+ ref: scroller,
1049
+ style: [s.root, style],
1050
+ /**
1051
+ * `preventDefault` is the load-bearing half.
1052
+ *
1053
+ * The tree's root is a scroll container **and** the focused node, and a
1054
+ * focused scroller has default key actions of its own: Down and Up
1055
+ * scroll by a wheel notch, the Page keys by a viewport, Home and End to
1056
+ * the ends, Space by a page. Without this, every arrow did both — moved
1057
+ * the selection *and* scrolled the list under it — which reads as the
1058
+ * tree scrolling whenever you use the keyboard rather than only when
1059
+ * the selection would otherwise leave the viewport.
1060
+ *
1061
+ * `handleKey` reports whether the tree took the key, so a key it did
1062
+ * not take (a letter that matched nothing) still gets the default.
1063
+ */
1064
+ onKeyDown: (ev) => {
1065
+ if (handleKey(ev)) ev.preventDefault();
1066
+ },
1067
+ // Layout, not scrolling, is what first tells a list how much of it is
1068
+ // worth building — and it is also where a page key gets its distance,
1069
+ // so this is measured whether or not the tree virtualizes.
1070
+ onViewport: (ev) => {
1071
+ setView((prev) =>
1072
+ prev.height === ev.height ? prev : { ...prev, height: ev.height },
1073
+ );
1074
+ onViewport?.(ev);
1075
+ },
1076
+ onScroll: (ev) => {
1077
+ if (virtualizing) {
1078
+ setView((prev) =>
1079
+ prev.top === ev.scrollY ? prev : { ...prev, top: ev.scrollY },
1080
+ );
1081
+ }
1082
+ onScroll?.(ev);
1083
+ },
1084
+ },
1085
+ body,
1086
+ );
1087
+ }