@flanksource/clicky-ui 0.2.18 → 0.2.20

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 (445) hide show
  1. package/dist/ai.cjs +26 -0
  2. package/dist/ai.cjs.map +1 -0
  3. package/dist/ai.d.ts +2 -0
  4. package/dist/ai.d.ts.map +1 -0
  5. package/dist/ai.js +26 -0
  6. package/dist/ai.js.map +1 -0
  7. package/dist/chat.cjs +7 -0
  8. package/dist/chat.cjs.map +1 -1
  9. package/dist/chat.js +7 -0
  10. package/dist/chat.js.map +1 -1
  11. package/dist/components/FilterBar.cjs +49 -18
  12. package/dist/components/FilterBar.cjs.map +1 -1
  13. package/dist/components/FilterBar.d.ts +0 -2
  14. package/dist/components/FilterBar.d.ts.map +1 -1
  15. package/dist/components/FilterBar.js +50 -19
  16. package/dist/components/FilterBar.js.map +1 -1
  17. package/dist/components/SearchInput.cjs +63 -0
  18. package/dist/components/SearchInput.cjs.map +1 -0
  19. package/dist/components/SearchInput.d.ts +31 -0
  20. package/dist/components/SearchInput.d.ts.map +1 -0
  21. package/dist/components/SearchInput.js +63 -0
  22. package/dist/components/SearchInput.js.map +1 -0
  23. package/dist/components/SegmentedControl.cjs +88 -0
  24. package/dist/components/SegmentedControl.cjs.map +1 -0
  25. package/dist/components/SegmentedControl.d.ts +38 -0
  26. package/dist/components/SegmentedControl.d.ts.map +1 -0
  27. package/dist/components/SegmentedControl.js +88 -0
  28. package/dist/components/SegmentedControl.js.map +1 -0
  29. package/dist/components/Switch.cjs +51 -0
  30. package/dist/components/Switch.cjs.map +1 -0
  31. package/dist/components/Switch.d.ts +23 -0
  32. package/dist/components/Switch.d.ts.map +1 -0
  33. package/dist/components/Switch.js +51 -0
  34. package/dist/components/Switch.js.map +1 -0
  35. package/dist/components/TimeRange.cjs +53 -45
  36. package/dist/components/TimeRange.cjs.map +1 -1
  37. package/dist/components/TimeRange.d.ts.map +1 -1
  38. package/dist/components/TimeRange.js +53 -45
  39. package/dist/components/TimeRange.js.map +1 -1
  40. package/dist/components/TreePickerField.cjs +5 -1
  41. package/dist/components/TreePickerField.cjs.map +1 -1
  42. package/dist/components/TreePickerField.d.ts.map +1 -1
  43. package/dist/components/TreePickerField.js +5 -1
  44. package/dist/components/TreePickerField.js.map +1 -1
  45. package/dist/components/filter-bar-utils.cjs +5 -0
  46. package/dist/components/filter-bar-utils.cjs.map +1 -1
  47. package/dist/components/filter-bar-utils.d.ts +2 -0
  48. package/dist/components/filter-bar-utils.d.ts.map +1 -1
  49. package/dist/components/filter-bar-utils.js +5 -0
  50. package/dist/components/filter-bar-utils.js.map +1 -1
  51. package/dist/components/json-schema-form-fields.cjs +8 -2
  52. package/dist/components/json-schema-form-fields.cjs.map +1 -1
  53. package/dist/components/json-schema-form-fields.d.ts.map +1 -1
  54. package/dist/components/json-schema-form-fields.js +8 -2
  55. package/dist/components/json-schema-form-fields.js.map +1 -1
  56. package/dist/components/json-schema-form-resolve.cjs +1 -1
  57. package/dist/components/json-schema-form-resolve.cjs.map +1 -1
  58. package/dist/components/json-schema-form-resolve.js +1 -1
  59. package/dist/components/json-schema-form-resolve.js.map +1 -1
  60. package/dist/components.cjs +21 -1
  61. package/dist/components.cjs.map +1 -1
  62. package/dist/components.d.ts +11 -1
  63. package/dist/components.d.ts.map +1 -1
  64. package/dist/components.js +21 -1
  65. package/dist/components.js.map +1 -1
  66. package/dist/data/Clicky.cjs +33 -44
  67. package/dist/data/Clicky.cjs.map +1 -1
  68. package/dist/data/Clicky.d.ts +0 -9
  69. package/dist/data/Clicky.d.ts.map +1 -1
  70. package/dist/data/Clicky.js +31 -42
  71. package/dist/data/Clicky.js.map +1 -1
  72. package/dist/data/DataTable.cjs +73 -50
  73. package/dist/data/DataTable.cjs.map +1 -1
  74. package/dist/data/DataTable.d.ts +4 -0
  75. package/dist/data/DataTable.d.ts.map +1 -1
  76. package/dist/data/DataTable.js +73 -50
  77. package/dist/data/DataTable.js.map +1 -1
  78. package/dist/data/Icon.cjs +2 -5
  79. package/dist/data/Icon.cjs.map +1 -1
  80. package/dist/data/Icon.d.ts +1 -21
  81. package/dist/data/Icon.d.ts.map +1 -1
  82. package/dist/data/Icon.js +3 -6
  83. package/dist/data/Icon.js.map +1 -1
  84. package/dist/data/MatrixTable.cjs +4 -4
  85. package/dist/data/MatrixTable.cjs.map +1 -1
  86. package/dist/data/MatrixTable.js +4 -4
  87. package/dist/data/MatrixTable.js.map +1 -1
  88. package/dist/data/RadialGauge.cjs +76 -0
  89. package/dist/data/RadialGauge.cjs.map +1 -0
  90. package/dist/data/RadialGauge.d.ts +24 -0
  91. package/dist/data/RadialGauge.d.ts.map +1 -0
  92. package/dist/data/RadialGauge.js +76 -0
  93. package/dist/data/RadialGauge.js.map +1 -0
  94. package/dist/data/StatusBreakdown.cjs +0 -4
  95. package/dist/data/StatusBreakdown.cjs.map +1 -1
  96. package/dist/data/StatusBreakdown.d.ts +0 -2
  97. package/dist/data/StatusBreakdown.d.ts.map +1 -1
  98. package/dist/data/StatusBreakdown.js +1 -5
  99. package/dist/data/StatusBreakdown.js.map +1 -1
  100. package/dist/data/TabButton.cjs +17 -2
  101. package/dist/data/TabButton.cjs.map +1 -1
  102. package/dist/data/TabButton.d.ts +5 -1
  103. package/dist/data/TabButton.d.ts.map +1 -1
  104. package/dist/data/TabButton.js +17 -2
  105. package/dist/data/TabButton.js.map +1 -1
  106. package/dist/data/Timeline.cjs +61 -0
  107. package/dist/data/Timeline.cjs.map +1 -0
  108. package/dist/data/Timeline.d.ts +36 -0
  109. package/dist/data/Timeline.d.ts.map +1 -0
  110. package/dist/data/Timeline.js +61 -0
  111. package/dist/data/Timeline.js.map +1 -0
  112. package/dist/data/TimeseriesCoreBars.cjs +2 -25
  113. package/dist/data/TimeseriesCoreBars.cjs.map +1 -1
  114. package/dist/data/TimeseriesCoreBars.d.ts +0 -19
  115. package/dist/data/TimeseriesCoreBars.d.ts.map +1 -1
  116. package/dist/data/TimeseriesCoreBars.js +2 -25
  117. package/dist/data/TimeseriesCoreBars.js.map +1 -1
  118. package/dist/data/TimeseriesCoreBars.model.cjs +27 -0
  119. package/dist/data/TimeseriesCoreBars.model.cjs.map +1 -0
  120. package/dist/data/TimeseriesCoreBars.model.d.ts +20 -0
  121. package/dist/data/TimeseriesCoreBars.model.d.ts.map +1 -0
  122. package/dist/data/TimeseriesCoreBars.model.js +27 -0
  123. package/dist/data/TimeseriesCoreBars.model.js.map +1 -0
  124. package/dist/data/TimeseriesPanel.axes.cjs.map +1 -1
  125. package/dist/data/TimeseriesPanel.axes.d.ts +1 -1
  126. package/dist/data/TimeseriesPanel.axes.d.ts.map +1 -1
  127. package/dist/data/TimeseriesPanel.axes.js.map +1 -1
  128. package/dist/data/TimeseriesPanel.cjs +4 -54
  129. package/dist/data/TimeseriesPanel.cjs.map +1 -1
  130. package/dist/data/TimeseriesPanel.d.ts +2 -138
  131. package/dist/data/TimeseriesPanel.d.ts.map +1 -1
  132. package/dist/data/TimeseriesPanel.js +2 -52
  133. package/dist/data/TimeseriesPanel.js.map +1 -1
  134. package/dist/data/TimeseriesPanel.model.cjs +53 -0
  135. package/dist/data/TimeseriesPanel.model.cjs.map +1 -0
  136. package/dist/data/TimeseriesPanel.model.d.ts +88 -0
  137. package/dist/data/TimeseriesPanel.model.d.ts.map +1 -0
  138. package/dist/data/TimeseriesPanel.model.js +53 -0
  139. package/dist/data/TimeseriesPanel.model.js.map +1 -0
  140. package/dist/data/Tree.cjs +1 -1
  141. package/dist/data/Tree.cjs.map +1 -1
  142. package/dist/data/Tree.js +1 -1
  143. package/dist/data/Tree.js.map +1 -1
  144. package/dist/data/ai/ChatFab.cjs +29 -0
  145. package/dist/data/ai/ChatFab.cjs.map +1 -0
  146. package/dist/data/ai/ChatFab.d.ts +12 -0
  147. package/dist/data/ai/ChatFab.d.ts.map +1 -0
  148. package/dist/data/ai/ChatFab.js +29 -0
  149. package/dist/data/ai/ChatFab.js.map +1 -0
  150. package/dist/data/ai/ChatWindow.cjs +178 -0
  151. package/dist/data/ai/ChatWindow.cjs.map +1 -0
  152. package/dist/data/ai/ChatWindow.d.ts +38 -0
  153. package/dist/data/ai/ChatWindow.d.ts.map +1 -0
  154. package/dist/data/ai/ChatWindow.js +156 -0
  155. package/dist/data/ai/ChatWindow.js.map +1 -0
  156. package/dist/data/ai/ChatWindowManager.cjs +139 -0
  157. package/dist/data/ai/ChatWindowManager.cjs.map +1 -0
  158. package/dist/data/ai/ChatWindowManager.d.ts +12 -0
  159. package/dist/data/ai/ChatWindowManager.d.ts.map +1 -0
  160. package/dist/data/ai/ChatWindowManager.js +139 -0
  161. package/dist/data/ai/ChatWindowManager.js.map +1 -0
  162. package/dist/data/ai/ContextBadges.cjs +74 -0
  163. package/dist/data/ai/ContextBadges.cjs.map +1 -0
  164. package/dist/data/ai/ContextBadges.d.ts +16 -0
  165. package/dist/data/ai/ContextBadges.d.ts.map +1 -0
  166. package/dist/data/ai/ContextBadges.js +74 -0
  167. package/dist/data/ai/ContextBadges.js.map +1 -0
  168. package/dist/data/ai/ThreadPicker.cjs +148 -0
  169. package/dist/data/ai/ThreadPicker.cjs.map +1 -0
  170. package/dist/data/ai/ThreadPicker.d.ts +37 -0
  171. package/dist/data/ai/ThreadPicker.d.ts.map +1 -0
  172. package/dist/data/ai/ThreadPicker.js +148 -0
  173. package/dist/data/ai/ThreadPicker.js.map +1 -0
  174. package/dist/data/ai/ToolPreferences.cjs +80 -0
  175. package/dist/data/ai/ToolPreferences.cjs.map +1 -0
  176. package/dist/data/ai/ToolPreferences.d.ts +19 -0
  177. package/dist/data/ai/ToolPreferences.d.ts.map +1 -0
  178. package/dist/data/ai/ToolPreferences.js +80 -0
  179. package/dist/data/ai/ToolPreferences.js.map +1 -0
  180. package/dist/data/ai/chat-window-context.cjs +78 -0
  181. package/dist/data/ai/chat-window-context.cjs.map +1 -0
  182. package/dist/data/ai/chat-window-context.d.ts +57 -0
  183. package/dist/data/ai/chat-window-context.d.ts.map +1 -0
  184. package/dist/data/ai/chat-window-context.js +78 -0
  185. package/dist/data/ai/chat-window-context.js.map +1 -0
  186. package/dist/data/ai/context.cjs +43 -0
  187. package/dist/data/ai/context.cjs.map +1 -0
  188. package/dist/data/ai/context.d.ts +35 -0
  189. package/dist/data/ai/context.d.ts.map +1 -0
  190. package/dist/data/ai/context.js +43 -0
  191. package/dist/data/ai/context.js.map +1 -0
  192. package/dist/data/ai/index.d.ts +10 -0
  193. package/dist/data/ai/index.d.ts.map +1 -0
  194. package/dist/data/cache-browser/CacheDetailPanel.cjs +15 -0
  195. package/dist/data/cache-browser/CacheDetailPanel.cjs.map +1 -1
  196. package/dist/data/cache-browser/CacheDetailPanel.d.ts.map +1 -1
  197. package/dist/data/cache-browser/CacheDetailPanel.js +15 -0
  198. package/dist/data/cache-browser/CacheDetailPanel.js.map +1 -1
  199. package/dist/data/cache-browser/cache-browser.fixtures.d.ts +10 -0
  200. package/dist/data/cache-browser/cache-browser.fixtures.d.ts.map +1 -0
  201. package/dist/data/cache-browser/download.cjs +13 -0
  202. package/dist/data/cache-browser/download.cjs.map +1 -0
  203. package/dist/data/cache-browser/download.d.ts +3 -0
  204. package/dist/data/cache-browser/download.d.ts.map +1 -0
  205. package/dist/data/cache-browser/download.js +13 -0
  206. package/dist/data/cache-browser/download.js.map +1 -0
  207. package/dist/data/chat/Chat.cjs +40 -2
  208. package/dist/data/chat/Chat.cjs.map +1 -1
  209. package/dist/data/chat/Chat.d.ts +5 -2
  210. package/dist/data/chat/Chat.d.ts.map +1 -1
  211. package/dist/data/chat/Chat.fixtures.cjs +86 -0
  212. package/dist/data/chat/Chat.fixtures.cjs.map +1 -0
  213. package/dist/data/chat/Chat.fixtures.d.ts +4 -0
  214. package/dist/data/chat/Chat.fixtures.d.ts.map +1 -1
  215. package/dist/data/chat/Chat.fixtures.js +86 -0
  216. package/dist/data/chat/Chat.fixtures.js.map +1 -0
  217. package/dist/data/chat/Chat.js +41 -3
  218. package/dist/data/chat/Chat.js.map +1 -1
  219. package/dist/data/chat/ContextUsage.cjs +99 -0
  220. package/dist/data/chat/ContextUsage.cjs.map +1 -0
  221. package/dist/data/chat/ContextUsage.d.ts +19 -0
  222. package/dist/data/chat/ContextUsage.d.ts.map +1 -0
  223. package/dist/data/chat/ContextUsage.js +99 -0
  224. package/dist/data/chat/ContextUsage.js.map +1 -0
  225. package/dist/data/chat/ModelSelector.cjs +28 -14
  226. package/dist/data/chat/ModelSelector.cjs.map +1 -1
  227. package/dist/data/chat/ModelSelector.d.ts +5 -4
  228. package/dist/data/chat/ModelSelector.d.ts.map +1 -1
  229. package/dist/data/chat/ModelSelector.js +28 -14
  230. package/dist/data/chat/ModelSelector.js.map +1 -1
  231. package/dist/data/chat/clickyOperationsToTools.cjs +21 -1
  232. package/dist/data/chat/clickyOperationsToTools.cjs.map +1 -1
  233. package/dist/data/chat/clickyOperationsToTools.d.ts +5 -4
  234. package/dist/data/chat/clickyOperationsToTools.d.ts.map +1 -1
  235. package/dist/data/chat/clickyOperationsToTools.js +21 -1
  236. package/dist/data/chat/clickyOperationsToTools.js.map +1 -1
  237. package/dist/data/chat/index.d.ts +4 -1
  238. package/dist/data/chat/index.d.ts.map +1 -1
  239. package/dist/data/chat/provider-icons.cjs +15 -0
  240. package/dist/data/chat/provider-icons.cjs.map +1 -0
  241. package/dist/data/chat/provider-icons.d.ts +7 -0
  242. package/dist/data/chat/provider-icons.d.ts.map +1 -0
  243. package/dist/data/chat/provider-icons.js +15 -0
  244. package/dist/data/chat/provider-icons.js.map +1 -0
  245. package/dist/data/chat/types.cjs.map +1 -1
  246. package/dist/data/chat/types.d.ts +41 -9
  247. package/dist/data/chat/types.d.ts.map +1 -1
  248. package/dist/data/chat/types.js.map +1 -1
  249. package/dist/data/clicky-parse.cjs +42 -0
  250. package/dist/data/clicky-parse.cjs.map +1 -0
  251. package/dist/data/clicky-parse.d.ts +11 -0
  252. package/dist/data/clicky-parse.d.ts.map +1 -0
  253. package/dist/data/clicky-parse.js +42 -0
  254. package/dist/data/clicky-parse.js.map +1 -0
  255. package/dist/data/diagnostics/FrameSourceWindow.cjs +0 -4
  256. package/dist/data/diagnostics/FrameSourceWindow.cjs.map +1 -1
  257. package/dist/data/diagnostics/FrameSourceWindow.d.ts +1 -11
  258. package/dist/data/diagnostics/FrameSourceWindow.d.ts.map +1 -1
  259. package/dist/data/diagnostics/FrameSourceWindow.js +1 -5
  260. package/dist/data/diagnostics/FrameSourceWindow.js.map +1 -1
  261. package/dist/data/diagnostics/FrameSourceWindow.utils.cjs +7 -0
  262. package/dist/data/diagnostics/FrameSourceWindow.utils.cjs.map +1 -0
  263. package/dist/data/diagnostics/FrameSourceWindow.utils.d.ts +12 -0
  264. package/dist/data/diagnostics/FrameSourceWindow.utils.d.ts.map +1 -0
  265. package/dist/data/diagnostics/FrameSourceWindow.utils.js +7 -0
  266. package/dist/data/diagnostics/FrameSourceWindow.utils.js.map +1 -0
  267. package/dist/data/diagnostics/JvmStackTrace.cjs +2 -1
  268. package/dist/data/diagnostics/JvmStackTrace.cjs.map +1 -1
  269. package/dist/data/diagnostics/JvmStackTrace.d.ts.map +1 -1
  270. package/dist/data/diagnostics/JvmStackTrace.js +2 -1
  271. package/dist/data/diagnostics/JvmStackTrace.js.map +1 -1
  272. package/dist/data/icon-fallback.cjs +12 -0
  273. package/dist/data/icon-fallback.cjs.map +1 -0
  274. package/dist/data/icon-fallback.d.ts +19 -0
  275. package/dist/data/icon-fallback.d.ts.map +1 -0
  276. package/dist/data/icon-fallback.js +12 -0
  277. package/dist/data/icon-fallback.js.map +1 -0
  278. package/dist/data/status-breakdown-utils.cjs +7 -0
  279. package/dist/data/status-breakdown-utils.cjs.map +1 -0
  280. package/dist/data/status-breakdown-utils.d.ts +4 -0
  281. package/dist/data/status-breakdown-utils.d.ts.map +1 -0
  282. package/dist/data/status-breakdown-utils.js +7 -0
  283. package/dist/data/status-breakdown-utils.js.map +1 -0
  284. package/dist/data/test-runner/TestRunSummary.cjs +36 -0
  285. package/dist/data/test-runner/TestRunSummary.cjs.map +1 -1
  286. package/dist/data/test-runner/TestRunSummary.d.ts +7 -1
  287. package/dist/data/test-runner/TestRunSummary.d.ts.map +1 -1
  288. package/dist/data/test-runner/TestRunSummary.js +36 -0
  289. package/dist/data/test-runner/TestRunSummary.js.map +1 -1
  290. package/dist/data/test-runner/TestRunner.cjs +5 -3
  291. package/dist/data/test-runner/TestRunner.cjs.map +1 -1
  292. package/dist/data/test-runner/TestRunner.d.ts +13 -1
  293. package/dist/data/test-runner/TestRunner.d.ts.map +1 -1
  294. package/dist/data/test-runner/TestRunner.js +5 -3
  295. package/dist/data/test-runner/TestRunner.js.map +1 -1
  296. package/dist/data/version-info.cjs +3 -3
  297. package/dist/data/version-info.js +3 -3
  298. package/dist/data.cjs +19 -6
  299. package/dist/data.cjs.map +1 -1
  300. package/dist/data.d.ts +14 -6
  301. package/dist/data.d.ts.map +1 -1
  302. package/dist/data.js +18 -5
  303. package/dist/data.js.map +1 -1
  304. package/dist/index.cjs +57 -7
  305. package/dist/index.cjs.map +1 -1
  306. package/dist/index.js +56 -6
  307. package/dist/index.js.map +1 -1
  308. package/dist/layout/AppShell.cjs +332 -0
  309. package/dist/layout/AppShell.cjs.map +1 -0
  310. package/dist/layout/AppShell.d.ts +75 -0
  311. package/dist/layout/AppShell.d.ts.map +1 -0
  312. package/dist/layout/AppShell.js +332 -0
  313. package/dist/layout/AppShell.js.map +1 -0
  314. package/dist/layout/AppSidebar.cjs +239 -0
  315. package/dist/layout/AppSidebar.cjs.map +1 -0
  316. package/dist/layout/AppSidebar.d.ts +62 -0
  317. package/dist/layout/AppSidebar.d.ts.map +1 -0
  318. package/dist/layout/AppSidebar.js +239 -0
  319. package/dist/layout/AppSidebar.js.map +1 -0
  320. package/dist/layout/Panel.cjs +66 -0
  321. package/dist/layout/Panel.cjs.map +1 -0
  322. package/dist/layout/Panel.d.ts +34 -0
  323. package/dist/layout/Panel.d.ts.map +1 -0
  324. package/dist/layout/Panel.js +66 -0
  325. package/dist/layout/Panel.js.map +1 -0
  326. package/dist/layout/Tabs.cjs +36 -0
  327. package/dist/layout/Tabs.cjs.map +1 -0
  328. package/dist/layout/Tabs.d.ts +36 -0
  329. package/dist/layout/Tabs.d.ts.map +1 -0
  330. package/dist/layout/Tabs.js +36 -0
  331. package/dist/layout/Tabs.js.map +1 -0
  332. package/dist/overlay/DropdownMenu.cjs.map +1 -1
  333. package/dist/overlay/DropdownMenu.d.ts.map +1 -1
  334. package/dist/overlay/DropdownMenu.js.map +1 -1
  335. package/dist/overlay/Modal.cjs +4 -2
  336. package/dist/overlay/Modal.cjs.map +1 -1
  337. package/dist/overlay/Modal.d.ts +1 -1
  338. package/dist/overlay/Modal.d.ts.map +1 -1
  339. package/dist/overlay/Modal.js +4 -2
  340. package/dist/overlay/Modal.js.map +1 -1
  341. package/dist/overlay/Toast.cjs +89 -0
  342. package/dist/overlay/Toast.cjs.map +1 -0
  343. package/dist/overlay/Toast.d.ts +14 -0
  344. package/dist/overlay/Toast.d.ts.map +1 -0
  345. package/dist/overlay/Toast.js +89 -0
  346. package/dist/overlay/Toast.js.map +1 -0
  347. package/dist/overlay/toast-context.cjs +12 -0
  348. package/dist/overlay/toast-context.cjs.map +1 -0
  349. package/dist/overlay/toast-context.d.ts +24 -0
  350. package/dist/overlay/toast-context.d.ts.map +1 -0
  351. package/dist/overlay/toast-context.js +12 -0
  352. package/dist/overlay/toast-context.js.map +1 -0
  353. package/dist/rpc/AcceptPicker.cjs +81 -58
  354. package/dist/rpc/AcceptPicker.cjs.map +1 -1
  355. package/dist/rpc/AcceptPicker.d.ts.map +1 -1
  356. package/dist/rpc/AcceptPicker.js +81 -58
  357. package/dist/rpc/AcceptPicker.js.map +1 -1
  358. package/dist/rpc/CommandForm.cjs +5 -35
  359. package/dist/rpc/CommandForm.cjs.map +1 -1
  360. package/dist/rpc/CommandForm.d.ts +0 -3
  361. package/dist/rpc/CommandForm.d.ts.map +1 -1
  362. package/dist/rpc/CommandForm.js +2 -32
  363. package/dist/rpc/CommandForm.js.map +1 -1
  364. package/dist/rpc/CommandOutput.cjs +2 -1
  365. package/dist/rpc/CommandOutput.cjs.map +1 -1
  366. package/dist/rpc/CommandOutput.d.ts.map +1 -1
  367. package/dist/rpc/CommandOutput.js +2 -1
  368. package/dist/rpc/CommandOutput.js.map +1 -1
  369. package/dist/rpc/EntityExplorerApp.cjs +28 -83
  370. package/dist/rpc/EntityExplorerApp.cjs.map +1 -1
  371. package/dist/rpc/EntityExplorerApp.d.ts +1 -4
  372. package/dist/rpc/EntityExplorerApp.d.ts.map +1 -1
  373. package/dist/rpc/EntityExplorerApp.js +13 -68
  374. package/dist/rpc/EntityExplorerApp.js.map +1 -1
  375. package/dist/rpc/OperationCatalog.cjs +2 -2
  376. package/dist/rpc/OperationCatalog.cjs.map +1 -1
  377. package/dist/rpc/OperationCatalog.d.ts +1 -1
  378. package/dist/rpc/OperationCatalog.d.ts.map +1 -1
  379. package/dist/rpc/OperationCatalog.js +1 -1
  380. package/dist/rpc/OperationCatalog.js.map +1 -1
  381. package/dist/rpc/OperationCommandPage.cjs +6 -4
  382. package/dist/rpc/OperationCommandPage.cjs.map +1 -1
  383. package/dist/rpc/OperationCommandPage.d.ts.map +1 -1
  384. package/dist/rpc/OperationCommandPage.js +3 -1
  385. package/dist/rpc/OperationCommandPage.js.map +1 -1
  386. package/dist/rpc/RouterProvider.cjs +10 -0
  387. package/dist/rpc/RouterProvider.cjs.map +1 -0
  388. package/dist/rpc/RouterProvider.d.ts +10 -0
  389. package/dist/rpc/RouterProvider.d.ts.map +1 -0
  390. package/dist/rpc/RouterProvider.js +10 -0
  391. package/dist/rpc/RouterProvider.js.map +1 -0
  392. package/dist/rpc/apiClient.cjs +4 -4
  393. package/dist/rpc/apiClient.cjs.map +1 -1
  394. package/dist/rpc/apiClient.js +4 -4
  395. package/dist/rpc/apiClient.js.map +1 -1
  396. package/dist/rpc/command-form-utils.cjs +43 -0
  397. package/dist/rpc/command-form-utils.cjs.map +1 -0
  398. package/dist/rpc/command-form-utils.d.ts +5 -0
  399. package/dist/rpc/command-form-utils.d.ts.map +1 -0
  400. package/dist/rpc/command-form-utils.js +43 -0
  401. package/dist/rpc/command-form-utils.js.map +1 -0
  402. package/dist/rpc/commandHref.cjs +62 -0
  403. package/dist/rpc/commandHref.cjs.map +1 -0
  404. package/dist/rpc/commandHref.d.ts +7 -0
  405. package/dist/rpc/commandHref.d.ts.map +1 -0
  406. package/dist/rpc/commandHref.js +62 -0
  407. package/dist/rpc/commandHref.js.map +1 -0
  408. package/dist/rpc/formMetadata.cjs +1 -1
  409. package/dist/rpc/formMetadata.cjs.map +1 -1
  410. package/dist/rpc/formMetadata.js +1 -1
  411. package/dist/rpc/formMetadata.js.map +1 -1
  412. package/dist/rpc/router.cjs +83 -0
  413. package/dist/rpc/router.cjs.map +1 -0
  414. package/dist/rpc/router.d.ts +24 -0
  415. package/dist/rpc/router.d.ts.map +1 -0
  416. package/dist/rpc/router.js +83 -0
  417. package/dist/rpc/router.js.map +1 -0
  418. package/dist/rpc/rpc-story-fixtures/orders.fixture.d.ts +3 -0
  419. package/dist/rpc/rpc-story-fixtures/orders.fixture.d.ts.map +1 -0
  420. package/dist/rpc/rpc-story-fixtures/services.fixture.d.ts +3 -0
  421. package/dist/rpc/rpc-story-fixtures/services.fixture.d.ts.map +1 -0
  422. package/dist/rpc/rpc-story-fixtures/surface-fixture.d.ts +24 -0
  423. package/dist/rpc/rpc-story-fixtures/surface-fixture.d.ts.map +1 -0
  424. package/dist/rpc/rpc-story-fixtures/widgets.fixture.d.ts +3 -0
  425. package/dist/rpc/rpc-story-fixtures/widgets.fixture.d.ts.map +1 -0
  426. package/dist/rpc/rpc-story.fixtures.d.ts +16 -0
  427. package/dist/rpc/rpc-story.fixtures.d.ts.map +1 -0
  428. package/dist/rpc.cjs +17 -0
  429. package/dist/rpc.cjs.map +1 -1
  430. package/dist/rpc.d.ts +5 -0
  431. package/dist/rpc.d.ts.map +1 -1
  432. package/dist/rpc.js +18 -1
  433. package/dist/rpc.js.map +1 -1
  434. package/dist/styles.cjs +1 -0
  435. package/dist/styles.cjs.map +1 -1
  436. package/dist/styles.css +1 -1
  437. package/dist/styles.d.ts.map +1 -1
  438. package/dist/styles.js +1 -0
  439. package/dist/styles.js.map +1 -1
  440. package/dist/tailwind-preset.cjs +36 -19
  441. package/dist/tailwind-preset.cjs.map +1 -1
  442. package/dist/tailwind-preset.d.ts.map +1 -1
  443. package/dist/tailwind-preset.js +36 -19
  444. package/dist/tailwind-preset.js.map +1 -1
  445. package/package.json +11 -1
@@ -1 +1 @@
1
- {"version":3,"file":"Tree.cjs","sources":["../../src/data/Tree.tsx"],"sourcesContent":["import { useMemo, useState, type ReactNode } from \"react\";\nimport { cn } from \"../lib/utils\";\nimport { Icon } from \"./Icon\";\nimport { UiClose, UiCollapseAll, UiExpandAll, UiSearch } from \"../icons\";\nimport { TreeNode, type TreeNodeProps } from \"./TreeNode\";\n\nexport type TreeProps<T> = Omit<\n TreeNodeProps<T>,\n \"node\" | \"depth\" | \"expandAll\" | \"forcedOpenKeys\"\n> & {\n /** Root nodes to render. */\n roots: T[];\n /** Empty-state content when no roots are provided. */\n empty?: ReactNode;\n /** Classes applied to the tree root. */\n className?: string;\n /**\n * Render the Expand all / Collapse all toolbar above the tree. Enabled by\n * default. Set to false to suppress when the tree is tiny or the controls\n * are owned externally.\n */\n showControls?: boolean;\n /**\n * Externally controlled expand-all state. When provided together with\n * `onExpandAllChange`, the tree is controlled; otherwise it manages the\n * toolbar state internally.\n */\n expandAll?: boolean | null;\n /** Called when the toolbar expand-all state changes. */\n onExpandAllChange?: (next: boolean | null) => void;\n /** Classes applied to the search/control toolbar. */\n toolbarClassName?: string;\n /**\n * Override the text the filter matches against for a given node.\n * Defaults to a recursive walk of the node's own fields (excluding\n * its `children` and any secondary children), which works for\n * plain-shape trees but leaks text from nested domain objects —\n * e.g. a SQL Table's Field rows are marked secondary, yet the\n * parent record still carries `record.fields[].field` strings that\n * the default walker would collect. Callers that need precise\n * control over search behaviour should return only the text they\n * want surfaced (the node's own display label / id / type).\n */\n getSearchText?: (node: T) => string;\n /**\n * Force-open the ancestors of the `selected` node so it is always revealed,\n * even when its branch was collapsed (a deep-link, a programmatic selection\n * from outside the tree, or simply a folder the user never opened). While a\n * node is selected its ancestors cannot be collapsed. Off by default; other\n * nodes keep their normal expand state. Requires `selected` to be set.\n */\n revealSelected?: boolean;\n};\n\n// ancestorPathKeys returns the keys of every ancestor on the path from a root\n// down to `target` (excluding target itself — opening the ancestors is what\n// makes target render). Matches by getKey so it is robust to object identity\n// across roots rebuilds. Returns null when target is not found.\nfunction ancestorPathKeys<T>(\n roots: T[],\n getChildren: TreeProps<T>[\"getChildren\"],\n getKey: TreeProps<T>[\"getKey\"],\n target: T,\n): Set<string | number> | null {\n const targetKey = getKey(target);\n const path: (string | number)[] = [];\n const visit = (node: T): boolean => {\n if (getKey(node) === targetKey) return true;\n for (const child of getChildren(node) ?? []) {\n if (visit(child)) {\n path.push(getKey(node));\n return true;\n }\n }\n return false;\n };\n for (const root of roots) {\n if (visit(root)) return path.length ? new Set(path) : null;\n }\n return null;\n}\n\n// mergeKeySets unions two optional key sets, preserving the null fast-path when\n// both are empty so consumers without a filter or reveal pass null downstream.\nfunction mergeKeySets(\n a: Set<string | number> | null,\n b: Set<string | number> | null,\n): Set<string | number> | null {\n if (!a) return b;\n if (!b) return a;\n return new Set([...a, ...b]);\n}\n\n// Edge counting, search-text collection and filtering all walk the tree through\n// the synchronous `getChildren` only. A lazy node (one declared via\n// `hasMoreChildren` whose children have not been fetched yet) therefore\n// contributes no edges and no search text until the operator expands it — so it\n// is invisible to \"expand all\" and to the filter while still collapsed. This is\n// intentional: we never trigger network loads from bulk/search operations.\nfunction countTreeEdges<T>(roots: T[], getChildren: TreeProps<T>[\"getChildren\"]) {\n let total = 0;\n const stack = [...roots];\n\n while (stack.length > 0) {\n const node = stack.pop()!;\n const children = getChildren(node) ?? [];\n total += children.length;\n stack.push(...children);\n }\n\n return total;\n}\n\nfunction collectTreeSearchText(\n value: unknown,\n excluded = new Set<unknown>(),\n seen = new Set<unknown>(),\n): string {\n if (value == null || excluded.has(value)) return \"\";\n\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n typeof value === \"bigint\"\n ) {\n return String(value);\n }\n\n if (typeof value !== \"object\") return \"\";\n if (seen.has(value)) return \"\";\n seen.add(value);\n\n if (Array.isArray(value)) {\n return value\n .map((entry) => collectTreeSearchText(entry, excluded, seen))\n .filter(Boolean)\n .join(\" \");\n }\n\n const preferredKeys = [\"label\", \"name\", \"title\", \"text\", \"plain\", \"id\", \"content\"];\n const record = value as Record<string, unknown>;\n const chunks: string[] = [];\n\n for (const key of preferredKeys) {\n if (!(key in record)) continue;\n const text = collectTreeSearchText(record[key], excluded, seen);\n if (text) chunks.push(text);\n }\n\n for (const [key, entry] of Object.entries(record)) {\n if (key === \"children\" || preferredKeys.includes(key)) continue;\n const text = collectTreeSearchText(entry, excluded, seen);\n if (text) chunks.push(text);\n }\n\n return chunks.join(\" \");\n}\n\nfunction nodeSearchText<T>(node: T, children: ReturnType<TreeProps<T>[\"getChildren\"]>) {\n const excluded = new Set<unknown>();\n if (children) excluded.add(children);\n return collectTreeSearchText(node, excluded).trim().toLowerCase();\n}\n\nfunction filterTreeRoots<T>(\n roots: T[],\n getChildren: TreeProps<T>[\"getChildren\"],\n getKey: TreeProps<T>[\"getKey\"],\n query: string,\n isSecondary?: (node: T) => boolean,\n getSearchText?: (node: T) => string,\n) {\n const normalizedQuery = query.trim().toLowerCase();\n if (!normalizedQuery) {\n return {\n roots,\n filteredChildren: null as Map<string | number, T[]> | null,\n forcedOpenKeys: null as Set<string | number> | null,\n };\n }\n\n const filteredChildren = new Map<string | number, T[]>();\n const forcedOpenKeys = new Set<string | number>();\n\n function matchText(node: T, children: T[]): string {\n // Honour the caller-supplied text extractor first — it's the\n // only way to get precise control over what the filter sees when\n // the node carries domain data whose fields would otherwise leak\n // into the default walker.\n if (getSearchText) return getSearchText(node).trim().toLowerCase();\n // Match-text skips secondary children so e.g. a Table's search\n // text only draws from the Table itself, not from its Field\n // rows. The Table is primary, so its own text still counts.\n const searchChildren = children.filter((c) => !isSecondary?.(c));\n return nodeSearchText(node, searchChildren);\n }\n\n function visit(node: T): boolean {\n // A secondary node never drives a filter match — it's\n // effectively invisible to search. Still rendered when the\n // caller opens the parent manually. This is what lets a 28k-row\n // field tree stay searchable at the record level without \"field\n // name contains 'x'\" matches spamming the results.\n if (isSecondary?.(node)) return false;\n\n const key = getKey(node);\n const children = getChildren(node) ?? [];\n const childrenAllSecondary =\n children.length > 0 && children.every((child) => isSecondary?.(child));\n const matches = matchText(node, children).includes(normalizedQuery);\n const visibleChildren: T[] = [];\n\n for (const child of children) {\n if (visit(child)) visibleChildren.push(child);\n }\n\n if (matches) {\n if (children.length > 0) {\n filteredChildren.set(key, children);\n if (!childrenAllSecondary) forcedOpenKeys.add(key);\n }\n return true;\n }\n\n if (visibleChildren.length > 0) {\n filteredChildren.set(key, visibleChildren);\n forcedOpenKeys.add(key);\n return true;\n }\n\n return false;\n }\n\n return {\n roots: roots.filter((root) => visit(root)),\n filteredChildren,\n forcedOpenKeys,\n };\n}\n\nexport function Tree<T>({\n roots,\n empty,\n className,\n showControls = true,\n expandAll: controlledExpandAll,\n onExpandAllChange,\n toolbarClassName,\n getSearchText,\n revealSelected = false,\n ...nodeProps\n}: TreeProps<T>) {\n const [internalExpandAll, setInternalExpandAll] = useState<boolean | null>(null);\n const [filterQuery, setFilterQuery] = useState(\"\");\n const basePaddingPx = nodeProps.basePaddingPx ?? 8;\n const isControlled = onExpandAllChange !== undefined;\n const expandAll = isControlled ? (controlledExpandAll ?? null) : internalExpandAll;\n const totalEdges = useMemo(\n () => countTreeEdges(roots, nodeProps.getChildren),\n [roots, nodeProps.getChildren],\n );\n const showFilter = totalEdges > 20;\n const activeFilter = showFilter ? filterQuery : \"\";\n const filteredTree = useMemo(\n () =>\n filterTreeRoots(\n roots,\n nodeProps.getChildren,\n nodeProps.getKey,\n activeFilter,\n nodeProps.isSecondary,\n getSearchText,\n ),\n [\n roots,\n nodeProps.getChildren,\n nodeProps.getKey,\n activeFilter,\n nodeProps.isSecondary,\n getSearchText,\n ],\n );\n const treeRoots = filteredTree.roots;\n const filteredChildren = filteredTree.filteredChildren;\n // Force-open the selected node's ancestors when revealSelected is set, unioned\n // with the filter's own forced-open keys. Recomputed when the selection moves\n // so the tree follows it without a remount.\n const revealKeys = useMemo(\n () =>\n revealSelected && nodeProps.selected\n ? ancestorPathKeys(roots, nodeProps.getChildren, nodeProps.getKey, nodeProps.selected)\n : null,\n [revealSelected, roots, nodeProps.getChildren, nodeProps.getKey, nodeProps.selected],\n );\n const forcedOpenKeys = useMemo(\n () => mergeKeySets(filteredTree.forcedOpenKeys, revealKeys),\n [filteredTree.forcedOpenKeys, revealKeys],\n );\n const effectiveGetChildren = filteredChildren\n ? (node: T) => filteredChildren.get(nodeProps.getKey(node)) ?? []\n : nodeProps.getChildren;\n const effectiveExpandAll = expandAll;\n const effectiveEmpty = activeFilter.trim() ? (\n <div className=\"px-3 py-4 text-sm text-muted-foreground\">No matching tree nodes.</div>\n ) : (\n empty\n );\n const showControlButtons = showControls && roots.length > 0;\n const showVirtualRow = showFilter || showControlButtons;\n const setExpandAll = (next: boolean | null) => {\n if (isControlled) onExpandAllChange?.(next);\n else setInternalExpandAll(next);\n };\n\n if (treeRoots.length === 0 && !showVirtualRow) return <>{effectiveEmpty ?? null}</>;\n\n return (\n <div className={cn(\"flex flex-col min-h-0\", className)}>\n <div role=\"tree\" className=\"min-h-0 flex-1 overflow-auto\">\n {showVirtualRow && (\n <div\n role=\"presentation\"\n className={cn(\n \"sticky top-0 z-10 flex items-center gap-1.5 border-b border-border/70 bg-background/95 py-1 pr-2 text-sm backdrop-blur supports-[backdrop-filter]:bg-background/80\",\n toolbarClassName,\n )}\n style={{ paddingLeft: `${basePaddingPx}px` }}\n >\n {showFilter ? (\n <Icon icon={UiSearch} className=\"w-3 shrink-0 text-xs text-muted-foreground\" />\n ) : (\n <span className=\"w-3 shrink-0\" aria-hidden />\n )}\n\n {showFilter ? (\n <label className=\"flex min-w-0 flex-1 items-center gap-2 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground shadow-sm\">\n <input\n type=\"search\"\n value={filterQuery}\n onChange={(event) => setFilterQuery(event.target.value)}\n placeholder=\"Filter tree\"\n className=\"h-5 w-full border-0 bg-transparent p-0 text-xs outline-none placeholder:text-muted-foreground\"\n aria-label=\"Filter tree nodes\"\n />\n {filterQuery && (\n <button\n type=\"button\"\n onClick={() => setFilterQuery(\"\")}\n className=\"inline-flex items-center rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-accent-foreground\"\n aria-label=\"Clear tree filter\"\n title=\"Clear tree filter\"\n >\n <Icon icon={UiClose} className=\"text-xs\" />\n </button>\n )}\n </label>\n ) : (\n <span className=\"flex-1\" />\n )}\n\n {showControlButtons && (\n <div className=\"ml-auto flex items-center gap-1\">\n <button\n type=\"button\"\n onClick={() => setExpandAll(true)}\n aria-pressed={effectiveExpandAll === true}\n aria-label=\"Expand all\"\n title=\"Expand all\"\n disabled={activeFilter.trim().length > 0}\n className={cn(\n \"inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n effectiveExpandAll === true && \"bg-accent text-accent-foreground\",\n )}\n >\n <Icon icon={UiExpandAll} className=\"text-sm\" />\n </button>\n <button\n type=\"button\"\n onClick={() => setExpandAll(false)}\n aria-pressed={effectiveExpandAll === false}\n aria-label=\"Collapse all\"\n title=\"Collapse all\"\n disabled={activeFilter.trim().length > 0}\n className={cn(\n \"inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n effectiveExpandAll === false && \"bg-accent text-accent-foreground\",\n )}\n >\n <Icon icon={UiCollapseAll} className=\"text-sm\" />\n </button>\n </div>\n )}\n </div>\n )}\n\n {treeRoots.length === 0 ? (\n (effectiveEmpty ?? null)\n ) : (\n <>\n {treeRoots.map((root) => (\n <TreeNode<T>\n {...nodeProps}\n key={nodeProps.getKey(root)}\n node={root}\n expandAll={effectiveExpandAll}\n forcedOpenKeys={forcedOpenKeys}\n getChildren={effectiveGetChildren}\n />\n ))}\n </>\n )}\n </div>\n </div>\n );\n}\n"],"names":["useState","useMemo","jsx","Fragment","cn","jsxs","Icon","UiSearch","UiClose","UiExpandAll","UiCollapseAll","createElement","TreeNode"],"mappings":";;;;;;;;;;;AA0DA,SAAS,iBACP,OACA,aACA,QACA,QAC6B;AAC7B,QAAM,YAAY,OAAO,MAAM;AAC/B,QAAM,OAA4B,CAAA;AAClC,QAAM,QAAQ,CAAC,SAAqB;AAClC,QAAI,OAAO,IAAI,MAAM,UAAW,QAAO;AACvC,eAAW,SAAS,YAAY,IAAI,KAAK,CAAA,GAAI;AAC3C,UAAI,MAAM,KAAK,GAAG;AAChB,aAAK,KAAK,OAAO,IAAI,CAAC;AACtB,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACA,aAAW,QAAQ,OAAO;AACxB,QAAI,MAAM,IAAI,EAAG,QAAO,KAAK,SAAS,IAAI,IAAI,IAAI,IAAI;AAAA,EACxD;AACA,SAAO;AACT;AAIA,SAAS,aACP,GACA,GAC6B;AAC7B,MAAI,CAAC,EAAG,QAAO;AACf,MAAI,CAAC,EAAG,QAAO;AACf,6BAAW,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;AAC7B;AAQA,SAAS,eAAkB,OAAY,aAA0C;AAC/E,MAAI,QAAQ;AACZ,QAAM,QAAQ,CAAC,GAAG,KAAK;AAEvB,SAAO,MAAM,SAAS,GAAG;AACvB,UAAM,OAAO,MAAM,IAAA;AACnB,UAAM,WAAW,YAAY,IAAI,KAAK,CAAA;AACtC,aAAS,SAAS;AAClB,UAAM,KAAK,GAAG,QAAQ;AAAA,EAC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AA;AAAA,IAKL,UAAU,WAAW,IACnB,kBAAkB,OAEnBR,2BAAAA,IAAAC,qBAAA,EACG,UAAA,UAAU,IAAI,CAAC,SACdQ,sBAAAA;AAAAA,MAACC,SAAAA;AAAAA,MAAA;AAAA,QACE,GAAG;AAAA,QACJ,KAAK,UAAU,OAAO,IAAI;AAAA,QAC1B,MAAM;AAAA,QACN,WAAW;AAAA,QACX;AAAA,QACA,aAAa;AAAA,MAAA;AAAA,IAAA,CAEhB,EAAA,CACH;AAAA,EAAA,EAAA,CAEJ,EAAA,CACF;AAEJ;;"}
1
+ {"version":3,"file":"Tree.cjs","sources":["../../src/data/Tree.tsx"],"sourcesContent":["import { useMemo, useState, type ReactNode } from \"react\";\nimport { cn } from \"../lib/utils\";\nimport { Icon } from \"./Icon\";\nimport { UiClose, UiCollapseAll, UiExpandAll, UiSearch } from \"../icons\";\nimport { TreeNode, type TreeNodeProps } from \"./TreeNode\";\n\nexport type TreeProps<T> = Omit<\n TreeNodeProps<T>,\n \"node\" | \"depth\" | \"expandAll\" | \"forcedOpenKeys\"\n> & {\n /** Root nodes to render. */\n roots: T[];\n /** Empty-state content when no roots are provided. */\n empty?: ReactNode;\n /** Classes applied to the tree root. */\n className?: string;\n /**\n * Render the Expand all / Collapse all toolbar above the tree. Enabled by\n * default. Set to false to suppress when the tree is tiny or the controls\n * are owned externally.\n */\n showControls?: boolean;\n /**\n * Externally controlled expand-all state. When provided together with\n * `onExpandAllChange`, the tree is controlled; otherwise it manages the\n * toolbar state internally.\n */\n expandAll?: boolean | null;\n /** Called when the toolbar expand-all state changes. */\n onExpandAllChange?: (next: boolean | null) => void;\n /** Classes applied to the search/control toolbar. */\n toolbarClassName?: string;\n /**\n * Override the text the filter matches against for a given node.\n * Defaults to a recursive walk of the node's own fields (excluding\n * its `children` and any secondary children), which works for\n * plain-shape trees but leaks text from nested domain objects —\n * e.g. a SQL Table's Field rows are marked secondary, yet the\n * parent record still carries `record.fields[].field` strings that\n * the default walker would collect. Callers that need precise\n * control over search behaviour should return only the text they\n * want surfaced (the node's own display label / id / type).\n */\n getSearchText?: (node: T) => string;\n /**\n * Force-open the ancestors of the `selected` node so it is always revealed,\n * even when its branch was collapsed (a deep-link, a programmatic selection\n * from outside the tree, or simply a folder the user never opened). While a\n * node is selected its ancestors cannot be collapsed. Off by default; other\n * nodes keep their normal expand state. Requires `selected` to be set.\n */\n revealSelected?: boolean;\n};\n\n// ancestorPathKeys returns the keys of every ancestor on the path from a root\n// down to `target` (excluding target itself — opening the ancestors is what\n// makes target render). Matches by getKey so it is robust to object identity\n// across roots rebuilds. Returns null when target is not found.\nfunction ancestorPathKeys<T>(\n roots: T[],\n getChildren: TreeProps<T>[\"getChildren\"],\n getKey: TreeProps<T>[\"getKey\"],\n target: T,\n): Set<string | number> | null {\n const targetKey = getKey(target);\n const path: (string | number)[] = [];\n const visit = (node: T): boolean => {\n if (getKey(node) === targetKey) return true;\n for (const child of getChildren(node) ?? []) {\n if (visit(child)) {\n path.push(getKey(node));\n return true;\n }\n }\n return false;\n };\n for (const root of roots) {\n if (visit(root)) return path.length ? new Set(path) : null;\n }\n return null;\n}\n\n// mergeKeySets unions two optional key sets, preserving the null fast-path when\n// both are empty so consumers without a filter or reveal pass null downstream.\nfunction mergeKeySets(\n a: Set<string | number> | null,\n b: Set<string | number> | null,\n): Set<string | number> | null {\n if (!a) return b;\n if (!b) return a;\n return new Set([...a, ...b]);\n}\n\n// Edge counting, search-text collection and filtering all walk the tree through\n// the synchronous `getChildren` only. A lazy node (one declared via\n// `hasMoreChildren` whose children have not been fetched yet) therefore\n// contributes no edges and no search text until the operator expands it — so it\n// is invisible to \"expand all\" and to the filter while still collapsed. This is\n// intentional: we never trigger network loads from bulk/search operations.\nfunction countTreeEdges<T>(roots: T[], getChildren: TreeProps<T>[\"getChildren\"]) {\n let total = 0;\n const stack = [...roots];\n\n while (stack.length > 0) {\n const node = stack.pop()!;\n const children = getChildren(node) ?? [];\n total += children.length;\n stack.push(...children);\n }\n\n return total;\n}\n\nfunction collectTreeSearchText(\n value: unknown,\n excluded = new Set<unknown>(),\n seen = new Set<unknown>(),\n): string {\n if (value == null || excluded.has(value)) return \"\";\n\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n typeof value === \"bigint\"\n ) {\n return String(value);\n }\n\n if (typeof value !== \"object\") return \"\";\n if (seen.has(value)) return \"\";\n seen.add(value);\n\n if (Array.isArray(value)) {\n return value\n .map((entry) => collectTreeSearchText(entry, excluded, seen))\n .filter(Boolean)\n .join(\" \");\n }\n\n const preferredKeys = [\"label\", \"name\", \"title\", \"text\", \"plain\", \"id\", \"content\"];\n const record = value as Record<string, unknown>;\n const chunks: string[] = [];\n\n for (const key of preferredKeys) {\n if (!(key in record)) continue;\n const text = collectTreeSearchText(record[key], excluded, seen);\n if (text) chunks.push(text);\n }\n\n for (const [key, entry] of Object.entries(record)) {\n if (key === \"children\" || preferredKeys.includes(key)) continue;\n const text = collectTreeSearchText(entry, excluded, seen);\n if (text) chunks.push(text);\n }\n\n return chunks.join(\" \");\n}\n\nfunction nodeSearchText<T>(node: T, children: ReturnType<TreeProps<T>[\"getChildren\"]>) {\n const excluded = new Set<unknown>();\n if (children) excluded.add(children);\n return collectTreeSearchText(node, excluded).trim().toLowerCase();\n}\n\nfunction filterTreeRoots<T>(\n roots: T[],\n getChildren: TreeProps<T>[\"getChildren\"],\n getKey: TreeProps<T>[\"getKey\"],\n query: string,\n isSecondary?: (node: T) => boolean,\n getSearchText?: (node: T) => string,\n) {\n const normalizedQuery = query.trim().toLowerCase();\n if (!normalizedQuery) {\n return {\n roots,\n filteredChildren: null as Map<string | number, T[]> | null,\n forcedOpenKeys: null as Set<string | number> | null,\n };\n }\n\n const filteredChildren = new Map<string | number, T[]>();\n const forcedOpenKeys = new Set<string | number>();\n\n function matchText(node: T, children: T[]): string {\n // Honour the caller-supplied text extractor first — it's the\n // only way to get precise control over what the filter sees when\n // the node carries domain data whose fields would otherwise leak\n // into the default walker.\n if (getSearchText) return getSearchText(node).trim().toLowerCase();\n // Match-text skips secondary children so e.g. a Table's search\n // text only draws from the Table itself, not from its Field\n // rows. The Table is primary, so its own text still counts.\n const searchChildren = children.filter((c) => !isSecondary?.(c));\n return nodeSearchText(node, searchChildren);\n }\n\n function visit(node: T): boolean {\n // A secondary node never drives a filter match — it's\n // effectively invisible to search. Still rendered when the\n // caller opens the parent manually. This is what lets a 28k-row\n // field tree stay searchable at the record level without \"field\n // name contains 'x'\" matches spamming the results.\n if (isSecondary?.(node)) return false;\n\n const key = getKey(node);\n const children = getChildren(node) ?? [];\n const childrenAllSecondary =\n children.length > 0 && children.every((child) => isSecondary?.(child));\n const matches = matchText(node, children).includes(normalizedQuery);\n const visibleChildren: T[] = [];\n\n for (const child of children) {\n if (visit(child)) visibleChildren.push(child);\n }\n\n if (matches) {\n if (children.length > 0) {\n filteredChildren.set(key, children);\n if (!childrenAllSecondary) forcedOpenKeys.add(key);\n }\n return true;\n }\n\n if (visibleChildren.length > 0) {\n filteredChildren.set(key, visibleChildren);\n forcedOpenKeys.add(key);\n return true;\n }\n\n return false;\n }\n\n return {\n roots: roots.filter((root) => visit(root)),\n filteredChildren,\n forcedOpenKeys,\n };\n}\n\nexport function Tree<T>({\n roots,\n empty,\n className,\n showControls = true,\n expandAll: controlledExpandAll,\n onExpandAllChange,\n toolbarClassName,\n getSearchText,\n revealSelected = false,\n ...nodeProps\n}: TreeProps<T>) {\n const [internalExpandAll, setInternalExpandAll] = useState<boolean | null>(null);\n const [filterQuery, setFilterQuery] = useState(\"\");\n const basePaddingPx = nodeProps.basePaddingPx ?? 8;\n const isControlled = onExpandAllChange !== undefined;\n const expandAll = isControlled ? (controlledExpandAll ?? null) : internalExpandAll;\n const totalEdges = useMemo(\n () => countTreeEdges(roots, nodeProps.getChildren),\n [roots, nodeProps.getChildren],\n );\n const showFilter = totalEdges > 20;\n const activeFilter = showFilter ? filterQuery : \"\";\n const filteredTree = useMemo(\n () =>\n filterTreeRoots(\n roots,\n nodeProps.getChildren,\n nodeProps.getKey,\n activeFilter,\n nodeProps.isSecondary,\n getSearchText,\n ),\n [\n roots,\n nodeProps.getChildren,\n nodeProps.getKey,\n activeFilter,\n nodeProps.isSecondary,\n getSearchText,\n ],\n );\n const treeRoots = filteredTree.roots;\n const filteredChildren = filteredTree.filteredChildren;\n // Force-open the selected node's ancestors when revealSelected is set, unioned\n // with the filter's own forced-open keys. Recomputed when the selection moves\n // so the tree follows it without a remount.\n const revealKeys = useMemo(\n () =>\n revealSelected && nodeProps.selected\n ? ancestorPathKeys(roots, nodeProps.getChildren, nodeProps.getKey, nodeProps.selected)\n : null,\n [revealSelected, roots, nodeProps.getChildren, nodeProps.getKey, nodeProps.selected],\n );\n const forcedOpenKeys = useMemo(\n () => mergeKeySets(filteredTree.forcedOpenKeys, revealKeys),\n [filteredTree.forcedOpenKeys, revealKeys],\n );\n const effectiveGetChildren = filteredChildren\n ? (node: T) => filteredChildren.get(nodeProps.getKey(node)) ?? []\n : nodeProps.getChildren;\n const effectiveExpandAll = expandAll;\n const effectiveEmpty = activeFilter.trim() ? (\n <div className=\"px-3 py-4 text-sm text-muted-foreground\">No matching tree nodes.</div>\n ) : (\n empty\n );\n const showControlButtons = showControls && roots.length > 0;\n const showVirtualRow = showFilter || showControlButtons;\n const setExpandAll = (next: boolean | null) => {\n if (isControlled) onExpandAllChange?.(next);\n else setInternalExpandAll(next);\n };\n\n if (treeRoots.length === 0 && !showVirtualRow) return <>{effectiveEmpty ?? null}</>;\n\n return (\n <div className={cn(\"flex flex-col min-h-0\", className)}>\n <div role=\"tree\" className=\"min-h-0 flex-1 overflow-auto\">\n {showVirtualRow && (\n <div\n role=\"presentation\"\n className={cn(\n \"sticky top-0 z-10 flex items-center gap-1.5 border-b border-border/70 bg-background/95 py-1 pr-2 text-sm backdrop-blur supports-[backdrop-filter]:bg-background/80\",\n toolbarClassName,\n )}\n style={{ paddingLeft: `${basePaddingPx}px` }}\n >\n {showFilter ? (\n <Icon icon={UiSearch} className=\"w-3 shrink-0 text-xs text-muted-foreground\" />\n ) : (\n <span className=\"w-3 shrink-0\" aria-hidden />\n )}\n\n {showFilter ? (\n <label className=\"flex min-w-0 flex-1 items-center gap-2 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground shadow-sm\">\n <input\n type=\"search\"\n value={filterQuery}\n onChange={(event) => setFilterQuery(event.target.value)}\n placeholder=\"Filter tree\"\n className=\"h-5 w-full min-w-0 border-0 bg-transparent p-0 text-xs outline-none placeholder:text-muted-foreground\"\n aria-label=\"Filter tree nodes\"\n />\n {filterQuery && (\n <button\n type=\"button\"\n onClick={() => setFilterQuery(\"\")}\n className=\"inline-flex items-center rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-accent-foreground\"\n aria-label=\"Clear tree filter\"\n title=\"Clear tree filter\"\n >\n <Icon icon={UiClose} className=\"text-xs\" />\n </button>\n )}\n </label>\n ) : (\n <span className=\"flex-1\" />\n )}\n\n {showControlButtons && (\n <div className=\"ml-auto flex items-center gap-1\">\n <button\n type=\"button\"\n onClick={() => setExpandAll(true)}\n aria-pressed={effectiveExpandAll === true}\n aria-label=\"Expand all\"\n title=\"Expand all\"\n disabled={activeFilter.trim().length > 0}\n className={cn(\n \"inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n effectiveExpandAll === true && \"bg-accent text-accent-foreground\",\n )}\n >\n <Icon icon={UiExpandAll} className=\"text-sm\" />\n </button>\n <button\n type=\"button\"\n onClick={() => setExpandAll(false)}\n aria-pressed={effectiveExpandAll === false}\n aria-label=\"Collapse all\"\n title=\"Collapse all\"\n disabled={activeFilter.trim().length > 0}\n className={cn(\n \"inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n effectiveExpandAll === false && \"bg-accent text-accent-foreground\",\n )}\n >\n <Icon icon={UiCollapseAll} className=\"text-sm\" />\n </button>\n </div>\n )}\n </div>\n )}\n\n {treeRoots.length === 0 ? (\n (effectiveEmpty ?? null)\n ) : (\n <>\n {treeRoots.map((root) => (\n <TreeNode<T>\n {...nodeProps}\n key={nodeProps.getKey(root)}\n node={root}\n expandAll={effectiveExpandAll}\n forcedOpenKeys={forcedOpenKeys}\n getChildren={effectiveGetChildren}\n />\n ))}\n </>\n )}\n </div>\n </div>\n );\n}\n"],"names":["useState","useMemo","jsx","Fragment","cn","jsxs","Icon","UiSearch","UiClose","UiExpandAll","UiCollapseAll","createElement","TreeNode"],"mappings":";;;;;;;;;;;AA0DA,SAAS,iBACP,OACA,aACA,QACA,QAC6B;AAC7B,QAAM,YAAY,OAAO,MAAM;AAC/B,QAAM,OAA4B,CAAA;AAClC,QAAM,QAAQ,CAAC,SAAqB;AAClC,QAAI,OAAO,IAAI,MAAM,UAAW,QAAO;AACvC,eAAW,SAAS,YAAY,IAAI,KAAK,CAAA,GAAI;AAC3C,UAAI,MAAM,KAAK,GAAG;AAChB,aAAK,KAAK,OAAO,IAAI,CAAC;AACtB,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACA,aAAW,QAAQ,OAAO;AACxB,QAAI,MAAM,IAAI,EAAG,QAAO,KAAK,SAAS,IAAI,IAAI,IAAI,IAAI;AAAA,EACxD;AACA,SAAO;AACT;AAIA,SAAS,aACP,GACA,GAC6B;AAC7B,MAAI,CAAC,EAAG,QAAO;AACf,MAAI,CAAC,EAAG,QAAO;AACf,6BAAW,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;AAC7B;AAQA,SAAS,eAAkB,OAAY,aAA0C;AAC/E,MAAI,QAAQ;AACZ,QAAM,QAAQ,CAAC,GAAG,KAAK;AAEvB,SAAO,MAAM,SAAS,GAAG;AACvB,UAAM,OAAO,MAAM,IAAA;AACnB,UAAM,WAAW,YAAY,IAAI,KAAK,CAAA;AACtC,aAAS,SAAS;AAClB,UAAM,KAAK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A;AAAA,MAAA;AAAA,IAAA;AAAA,IAKL,UAAU,WAAW,IACnB,kBAAkB,OAEnBR,2BAAAA,IAAAC,qBAAA,EACG,UAAA,UAAU,IAAI,CAAC,SACdQ,sBAAAA;AAAAA,MAACC,SAAAA;AAAAA,MAAA;AAAA,QACE,GAAG;AAAA,QACJ,KAAK,UAAU,OAAO,IAAI;AAAA,QAC1B,MAAM;AAAA,QACN,WAAW;AAAA,QACX;AAAA,QACA,aAAa;AAAA,MAAA;AAAA,IAAA,CAEhB,EAAA,CACH;AAAA,EAAA,EAAA,CAEJ,EAAA,CACF;AAEJ;;"}
package/dist/data/Tree.js CHANGED
@@ -199,7 +199,7 @@ function Tree({
199
199
  value: filterQuery,
200
200
  onChange: (event) => setFilterQuery(event.target.value),
201
201
  placeholder: "Filter tree",
202
- className: "h-5 w-full border-0 bg-transparent p-0 text-xs outline-none placeholder:text-muted-foreground",
202
+ className: "h-5 w-full min-w-0 border-0 bg-transparent p-0 text-xs outline-none placeholder:text-muted-foreground",
203
203
  "aria-label": "Filter tree nodes"
204
204
  }
205
205
  ),
@@ -1 +1 @@
1
- {"version":3,"file":"Tree.js","sources":["../../src/data/Tree.tsx"],"sourcesContent":["import { useMemo, useState, type ReactNode } from \"react\";\nimport { cn } from \"../lib/utils\";\nimport { Icon } from \"./Icon\";\nimport { UiClose, UiCollapseAll, UiExpandAll, UiSearch } from \"../icons\";\nimport { TreeNode, type TreeNodeProps } from \"./TreeNode\";\n\nexport type TreeProps<T> = Omit<\n TreeNodeProps<T>,\n \"node\" | \"depth\" | \"expandAll\" | \"forcedOpenKeys\"\n> & {\n /** Root nodes to render. */\n roots: T[];\n /** Empty-state content when no roots are provided. */\n empty?: ReactNode;\n /** Classes applied to the tree root. */\n className?: string;\n /**\n * Render the Expand all / Collapse all toolbar above the tree. Enabled by\n * default. Set to false to suppress when the tree is tiny or the controls\n * are owned externally.\n */\n showControls?: boolean;\n /**\n * Externally controlled expand-all state. When provided together with\n * `onExpandAllChange`, the tree is controlled; otherwise it manages the\n * toolbar state internally.\n */\n expandAll?: boolean | null;\n /** Called when the toolbar expand-all state changes. */\n onExpandAllChange?: (next: boolean | null) => void;\n /** Classes applied to the search/control toolbar. */\n toolbarClassName?: string;\n /**\n * Override the text the filter matches against for a given node.\n * Defaults to a recursive walk of the node's own fields (excluding\n * its `children` and any secondary children), which works for\n * plain-shape trees but leaks text from nested domain objects —\n * e.g. a SQL Table's Field rows are marked secondary, yet the\n * parent record still carries `record.fields[].field` strings that\n * the default walker would collect. Callers that need precise\n * control over search behaviour should return only the text they\n * want surfaced (the node's own display label / id / type).\n */\n getSearchText?: (node: T) => string;\n /**\n * Force-open the ancestors of the `selected` node so it is always revealed,\n * even when its branch was collapsed (a deep-link, a programmatic selection\n * from outside the tree, or simply a folder the user never opened). While a\n * node is selected its ancestors cannot be collapsed. Off by default; other\n * nodes keep their normal expand state. Requires `selected` to be set.\n */\n revealSelected?: boolean;\n};\n\n// ancestorPathKeys returns the keys of every ancestor on the path from a root\n// down to `target` (excluding target itself — opening the ancestors is what\n// makes target render). Matches by getKey so it is robust to object identity\n// across roots rebuilds. Returns null when target is not found.\nfunction ancestorPathKeys<T>(\n roots: T[],\n getChildren: TreeProps<T>[\"getChildren\"],\n getKey: TreeProps<T>[\"getKey\"],\n target: T,\n): Set<string | number> | null {\n const targetKey = getKey(target);\n const path: (string | number)[] = [];\n const visit = (node: T): boolean => {\n if (getKey(node) === targetKey) return true;\n for (const child of getChildren(node) ?? []) {\n if (visit(child)) {\n path.push(getKey(node));\n return true;\n }\n }\n return false;\n };\n for (const root of roots) {\n if (visit(root)) return path.length ? new Set(path) : null;\n }\n return null;\n}\n\n// mergeKeySets unions two optional key sets, preserving the null fast-path when\n// both are empty so consumers without a filter or reveal pass null downstream.\nfunction mergeKeySets(\n a: Set<string | number> | null,\n b: Set<string | number> | null,\n): Set<string | number> | null {\n if (!a) return b;\n if (!b) return a;\n return new Set([...a, ...b]);\n}\n\n// Edge counting, search-text collection and filtering all walk the tree through\n// the synchronous `getChildren` only. A lazy node (one declared via\n// `hasMoreChildren` whose children have not been fetched yet) therefore\n// contributes no edges and no search text until the operator expands it — so it\n// is invisible to \"expand all\" and to the filter while still collapsed. This is\n// intentional: we never trigger network loads from bulk/search operations.\nfunction countTreeEdges<T>(roots: T[], getChildren: TreeProps<T>[\"getChildren\"]) {\n let total = 0;\n const stack = [...roots];\n\n while (stack.length > 0) {\n const node = stack.pop()!;\n const children = getChildren(node) ?? [];\n total += children.length;\n stack.push(...children);\n }\n\n return total;\n}\n\nfunction collectTreeSearchText(\n value: unknown,\n excluded = new Set<unknown>(),\n seen = new Set<unknown>(),\n): string {\n if (value == null || excluded.has(value)) return \"\";\n\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n typeof value === \"bigint\"\n ) {\n return String(value);\n }\n\n if (typeof value !== \"object\") return \"\";\n if (seen.has(value)) return \"\";\n seen.add(value);\n\n if (Array.isArray(value)) {\n return value\n .map((entry) => collectTreeSearchText(entry, excluded, seen))\n .filter(Boolean)\n .join(\" \");\n }\n\n const preferredKeys = [\"label\", \"name\", \"title\", \"text\", \"plain\", \"id\", \"content\"];\n const record = value as Record<string, unknown>;\n const chunks: string[] = [];\n\n for (const key of preferredKeys) {\n if (!(key in record)) continue;\n const text = collectTreeSearchText(record[key], excluded, seen);\n if (text) chunks.push(text);\n }\n\n for (const [key, entry] of Object.entries(record)) {\n if (key === \"children\" || preferredKeys.includes(key)) continue;\n const text = collectTreeSearchText(entry, excluded, seen);\n if (text) chunks.push(text);\n }\n\n return chunks.join(\" \");\n}\n\nfunction nodeSearchText<T>(node: T, children: ReturnType<TreeProps<T>[\"getChildren\"]>) {\n const excluded = new Set<unknown>();\n if (children) excluded.add(children);\n return collectTreeSearchText(node, excluded).trim().toLowerCase();\n}\n\nfunction filterTreeRoots<T>(\n roots: T[],\n getChildren: TreeProps<T>[\"getChildren\"],\n getKey: TreeProps<T>[\"getKey\"],\n query: string,\n isSecondary?: (node: T) => boolean,\n getSearchText?: (node: T) => string,\n) {\n const normalizedQuery = query.trim().toLowerCase();\n if (!normalizedQuery) {\n return {\n roots,\n filteredChildren: null as Map<string | number, T[]> | null,\n forcedOpenKeys: null as Set<string | number> | null,\n };\n }\n\n const filteredChildren = new Map<string | number, T[]>();\n const forcedOpenKeys = new Set<string | number>();\n\n function matchText(node: T, children: T[]): string {\n // Honour the caller-supplied text extractor first — it's the\n // only way to get precise control over what the filter sees when\n // the node carries domain data whose fields would otherwise leak\n // into the default walker.\n if (getSearchText) return getSearchText(node).trim().toLowerCase();\n // Match-text skips secondary children so e.g. a Table's search\n // text only draws from the Table itself, not from its Field\n // rows. The Table is primary, so its own text still counts.\n const searchChildren = children.filter((c) => !isSecondary?.(c));\n return nodeSearchText(node, searchChildren);\n }\n\n function visit(node: T): boolean {\n // A secondary node never drives a filter match — it's\n // effectively invisible to search. Still rendered when the\n // caller opens the parent manually. This is what lets a 28k-row\n // field tree stay searchable at the record level without \"field\n // name contains 'x'\" matches spamming the results.\n if (isSecondary?.(node)) return false;\n\n const key = getKey(node);\n const children = getChildren(node) ?? [];\n const childrenAllSecondary =\n children.length > 0 && children.every((child) => isSecondary?.(child));\n const matches = matchText(node, children).includes(normalizedQuery);\n const visibleChildren: T[] = [];\n\n for (const child of children) {\n if (visit(child)) visibleChildren.push(child);\n }\n\n if (matches) {\n if (children.length > 0) {\n filteredChildren.set(key, children);\n if (!childrenAllSecondary) forcedOpenKeys.add(key);\n }\n return true;\n }\n\n if (visibleChildren.length > 0) {\n filteredChildren.set(key, visibleChildren);\n forcedOpenKeys.add(key);\n return true;\n }\n\n return false;\n }\n\n return {\n roots: roots.filter((root) => visit(root)),\n filteredChildren,\n forcedOpenKeys,\n };\n}\n\nexport function Tree<T>({\n roots,\n empty,\n className,\n showControls = true,\n expandAll: controlledExpandAll,\n onExpandAllChange,\n toolbarClassName,\n getSearchText,\n revealSelected = false,\n ...nodeProps\n}: TreeProps<T>) {\n const [internalExpandAll, setInternalExpandAll] = useState<boolean | null>(null);\n const [filterQuery, setFilterQuery] = useState(\"\");\n const basePaddingPx = nodeProps.basePaddingPx ?? 8;\n const isControlled = onExpandAllChange !== undefined;\n const expandAll = isControlled ? (controlledExpandAll ?? null) : internalExpandAll;\n const totalEdges = useMemo(\n () => countTreeEdges(roots, nodeProps.getChildren),\n [roots, nodeProps.getChildren],\n );\n const showFilter = totalEdges > 20;\n const activeFilter = showFilter ? filterQuery : \"\";\n const filteredTree = useMemo(\n () =>\n filterTreeRoots(\n roots,\n nodeProps.getChildren,\n nodeProps.getKey,\n activeFilter,\n nodeProps.isSecondary,\n getSearchText,\n ),\n [\n roots,\n nodeProps.getChildren,\n nodeProps.getKey,\n activeFilter,\n nodeProps.isSecondary,\n getSearchText,\n ],\n );\n const treeRoots = filteredTree.roots;\n const filteredChildren = filteredTree.filteredChildren;\n // Force-open the selected node's ancestors when revealSelected is set, unioned\n // with the filter's own forced-open keys. Recomputed when the selection moves\n // so the tree follows it without a remount.\n const revealKeys = useMemo(\n () =>\n revealSelected && nodeProps.selected\n ? ancestorPathKeys(roots, nodeProps.getChildren, nodeProps.getKey, nodeProps.selected)\n : null,\n [revealSelected, roots, nodeProps.getChildren, nodeProps.getKey, nodeProps.selected],\n );\n const forcedOpenKeys = useMemo(\n () => mergeKeySets(filteredTree.forcedOpenKeys, revealKeys),\n [filteredTree.forcedOpenKeys, revealKeys],\n );\n const effectiveGetChildren = filteredChildren\n ? (node: T) => filteredChildren.get(nodeProps.getKey(node)) ?? []\n : nodeProps.getChildren;\n const effectiveExpandAll = expandAll;\n const effectiveEmpty = activeFilter.trim() ? (\n <div className=\"px-3 py-4 text-sm text-muted-foreground\">No matching tree nodes.</div>\n ) : (\n empty\n );\n const showControlButtons = showControls && roots.length > 0;\n const showVirtualRow = showFilter || showControlButtons;\n const setExpandAll = (next: boolean | null) => {\n if (isControlled) onExpandAllChange?.(next);\n else setInternalExpandAll(next);\n };\n\n if (treeRoots.length === 0 && !showVirtualRow) return <>{effectiveEmpty ?? null}</>;\n\n return (\n <div className={cn(\"flex flex-col min-h-0\", className)}>\n <div role=\"tree\" className=\"min-h-0 flex-1 overflow-auto\">\n {showVirtualRow && (\n <div\n role=\"presentation\"\n className={cn(\n \"sticky top-0 z-10 flex items-center gap-1.5 border-b border-border/70 bg-background/95 py-1 pr-2 text-sm backdrop-blur supports-[backdrop-filter]:bg-background/80\",\n toolbarClassName,\n )}\n style={{ paddingLeft: `${basePaddingPx}px` }}\n >\n {showFilter ? (\n <Icon icon={UiSearch} className=\"w-3 shrink-0 text-xs text-muted-foreground\" />\n ) : (\n <span className=\"w-3 shrink-0\" aria-hidden />\n )}\n\n {showFilter ? (\n <label className=\"flex min-w-0 flex-1 items-center gap-2 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground shadow-sm\">\n <input\n type=\"search\"\n value={filterQuery}\n onChange={(event) => setFilterQuery(event.target.value)}\n placeholder=\"Filter tree\"\n className=\"h-5 w-full border-0 bg-transparent p-0 text-xs outline-none placeholder:text-muted-foreground\"\n aria-label=\"Filter tree nodes\"\n />\n {filterQuery && (\n <button\n type=\"button\"\n onClick={() => setFilterQuery(\"\")}\n className=\"inline-flex items-center rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-accent-foreground\"\n aria-label=\"Clear tree filter\"\n title=\"Clear tree filter\"\n >\n <Icon icon={UiClose} className=\"text-xs\" />\n </button>\n )}\n </label>\n ) : (\n <span className=\"flex-1\" />\n )}\n\n {showControlButtons && (\n <div className=\"ml-auto flex items-center gap-1\">\n <button\n type=\"button\"\n onClick={() => setExpandAll(true)}\n aria-pressed={effectiveExpandAll === true}\n aria-label=\"Expand all\"\n title=\"Expand all\"\n disabled={activeFilter.trim().length > 0}\n className={cn(\n \"inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n effectiveExpandAll === true && \"bg-accent text-accent-foreground\",\n )}\n >\n <Icon icon={UiExpandAll} className=\"text-sm\" />\n </button>\n <button\n type=\"button\"\n onClick={() => setExpandAll(false)}\n aria-pressed={effectiveExpandAll === false}\n aria-label=\"Collapse all\"\n title=\"Collapse all\"\n disabled={activeFilter.trim().length > 0}\n className={cn(\n \"inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n effectiveExpandAll === false && \"bg-accent text-accent-foreground\",\n )}\n >\n <Icon icon={UiCollapseAll} className=\"text-sm\" />\n </button>\n </div>\n )}\n </div>\n )}\n\n {treeRoots.length === 0 ? (\n (effectiveEmpty ?? null)\n ) : (\n <>\n {treeRoots.map((root) => (\n <TreeNode<T>\n {...nodeProps}\n key={nodeProps.getKey(root)}\n node={root}\n expandAll={effectiveExpandAll}\n forcedOpenKeys={forcedOpenKeys}\n getChildren={effectiveGetChildren}\n />\n ))}\n </>\n )}\n </div>\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;AA0DA,SAAS,iBACP,OACA,aACA,QACA,QAC6B;AAC7B,QAAM,YAAY,OAAO,MAAM;AAC/B,QAAM,OAA4B,CAAA;AAClC,QAAM,QAAQ,CAAC,SAAqB;AAClC,QAAI,OAAO,IAAI,MAAM,UAAW,QAAO;AACvC,eAAW,SAAS,YAAY,IAAI,KAAK,CAAA,GAAI;AAC3C,UAAI,MAAM,KAAK,GAAG;AAChB,aAAK,KAAK,OAAO,IAAI,CAAC;AACtB,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACA,aAAW,QAAQ,OAAO;AACxB,QAAI,MAAM,IAAI,EAAG,QAAO,KAAK,SAAS,IAAI,IAAI,IAAI,IAAI;AAAA,EACxD;AACA,SAAO;AACT;AAIA,SAAS,aACP,GACA,GAC6B;AAC7B,MAAI,CAAC,EAAG,QAAO;AACf,MAAI,CAAC,EAAG,QAAO;AACf,6BAAW,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC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U,WAAW,IACnB,kBAAkB,OAEnB,oBAAA,UAAA,EACG,UAAA,UAAU,IAAI,CAAC,SACd;AAAA,MAAC;AAAA,MAAA;AAAA,QACE,GAAG;AAAA,QACJ,KAAK,UAAU,OAAO,IAAI;AAAA,QAC1B,MAAM;AAAA,QACN,WAAW;AAAA,QACX;AAAA,QACA,aAAa;AAAA,MAAA;AAAA,IAAA,CAEhB,EAAA,CACH;AAAA,EAAA,EAAA,CAEJ,EAAA,CACF;AAEJ;"}
1
+ {"version":3,"file":"Tree.js","sources":["../../src/data/Tree.tsx"],"sourcesContent":["import { useMemo, useState, type ReactNode } from \"react\";\nimport { cn } from \"../lib/utils\";\nimport { Icon } from \"./Icon\";\nimport { UiClose, UiCollapseAll, UiExpandAll, UiSearch } from \"../icons\";\nimport { TreeNode, type TreeNodeProps } from \"./TreeNode\";\n\nexport type TreeProps<T> = Omit<\n TreeNodeProps<T>,\n \"node\" | \"depth\" | \"expandAll\" | \"forcedOpenKeys\"\n> & {\n /** Root nodes to render. */\n roots: T[];\n /** Empty-state content when no roots are provided. */\n empty?: ReactNode;\n /** Classes applied to the tree root. */\n className?: string;\n /**\n * Render the Expand all / Collapse all toolbar above the tree. Enabled by\n * default. Set to false to suppress when the tree is tiny or the controls\n * are owned externally.\n */\n showControls?: boolean;\n /**\n * Externally controlled expand-all state. When provided together with\n * `onExpandAllChange`, the tree is controlled; otherwise it manages the\n * toolbar state internally.\n */\n expandAll?: boolean | null;\n /** Called when the toolbar expand-all state changes. */\n onExpandAllChange?: (next: boolean | null) => void;\n /** Classes applied to the search/control toolbar. */\n toolbarClassName?: string;\n /**\n * Override the text the filter matches against for a given node.\n * Defaults to a recursive walk of the node's own fields (excluding\n * its `children` and any secondary children), which works for\n * plain-shape trees but leaks text from nested domain objects —\n * e.g. a SQL Table's Field rows are marked secondary, yet the\n * parent record still carries `record.fields[].field` strings that\n * the default walker would collect. Callers that need precise\n * control over search behaviour should return only the text they\n * want surfaced (the node's own display label / id / type).\n */\n getSearchText?: (node: T) => string;\n /**\n * Force-open the ancestors of the `selected` node so it is always revealed,\n * even when its branch was collapsed (a deep-link, a programmatic selection\n * from outside the tree, or simply a folder the user never opened). While a\n * node is selected its ancestors cannot be collapsed. Off by default; other\n * nodes keep their normal expand state. Requires `selected` to be set.\n */\n revealSelected?: boolean;\n};\n\n// ancestorPathKeys returns the keys of every ancestor on the path from a root\n// down to `target` (excluding target itself — opening the ancestors is what\n// makes target render). Matches by getKey so it is robust to object identity\n// across roots rebuilds. Returns null when target is not found.\nfunction ancestorPathKeys<T>(\n roots: T[],\n getChildren: TreeProps<T>[\"getChildren\"],\n getKey: TreeProps<T>[\"getKey\"],\n target: T,\n): Set<string | number> | null {\n const targetKey = getKey(target);\n const path: (string | number)[] = [];\n const visit = (node: T): boolean => {\n if (getKey(node) === targetKey) return true;\n for (const child of getChildren(node) ?? []) {\n if (visit(child)) {\n path.push(getKey(node));\n return true;\n }\n }\n return false;\n };\n for (const root of roots) {\n if (visit(root)) return path.length ? new Set(path) : null;\n }\n return null;\n}\n\n// mergeKeySets unions two optional key sets, preserving the null fast-path when\n// both are empty so consumers without a filter or reveal pass null downstream.\nfunction mergeKeySets(\n a: Set<string | number> | null,\n b: Set<string | number> | null,\n): Set<string | number> | null {\n if (!a) return b;\n if (!b) return a;\n return new Set([...a, ...b]);\n}\n\n// Edge counting, search-text collection and filtering all walk the tree through\n// the synchronous `getChildren` only. A lazy node (one declared via\n// `hasMoreChildren` whose children have not been fetched yet) therefore\n// contributes no edges and no search text until the operator expands it — so it\n// is invisible to \"expand all\" and to the filter while still collapsed. This is\n// intentional: we never trigger network loads from bulk/search operations.\nfunction countTreeEdges<T>(roots: T[], getChildren: TreeProps<T>[\"getChildren\"]) {\n let total = 0;\n const stack = [...roots];\n\n while (stack.length > 0) {\n const node = stack.pop()!;\n const children = getChildren(node) ?? [];\n total += children.length;\n stack.push(...children);\n }\n\n return total;\n}\n\nfunction collectTreeSearchText(\n value: unknown,\n excluded = new Set<unknown>(),\n seen = new Set<unknown>(),\n): string {\n if (value == null || excluded.has(value)) return \"\";\n\n if (\n typeof value === \"string\" ||\n typeof value === \"number\" ||\n typeof value === \"boolean\" ||\n typeof value === \"bigint\"\n ) {\n return String(value);\n }\n\n if (typeof value !== \"object\") return \"\";\n if (seen.has(value)) return \"\";\n seen.add(value);\n\n if (Array.isArray(value)) {\n return value\n .map((entry) => collectTreeSearchText(entry, excluded, seen))\n .filter(Boolean)\n .join(\" \");\n }\n\n const preferredKeys = [\"label\", \"name\", \"title\", \"text\", \"plain\", \"id\", \"content\"];\n const record = value as Record<string, unknown>;\n const chunks: string[] = [];\n\n for (const key of preferredKeys) {\n if (!(key in record)) continue;\n const text = collectTreeSearchText(record[key], excluded, seen);\n if (text) chunks.push(text);\n }\n\n for (const [key, entry] of Object.entries(record)) {\n if (key === \"children\" || preferredKeys.includes(key)) continue;\n const text = collectTreeSearchText(entry, excluded, seen);\n if (text) chunks.push(text);\n }\n\n return chunks.join(\" \");\n}\n\nfunction nodeSearchText<T>(node: T, children: ReturnType<TreeProps<T>[\"getChildren\"]>) {\n const excluded = new Set<unknown>();\n if (children) excluded.add(children);\n return collectTreeSearchText(node, excluded).trim().toLowerCase();\n}\n\nfunction filterTreeRoots<T>(\n roots: T[],\n getChildren: TreeProps<T>[\"getChildren\"],\n getKey: TreeProps<T>[\"getKey\"],\n query: string,\n isSecondary?: (node: T) => boolean,\n getSearchText?: (node: T) => string,\n) {\n const normalizedQuery = query.trim().toLowerCase();\n if (!normalizedQuery) {\n return {\n roots,\n filteredChildren: null as Map<string | number, T[]> | null,\n forcedOpenKeys: null as Set<string | number> | null,\n };\n }\n\n const filteredChildren = new Map<string | number, T[]>();\n const forcedOpenKeys = new Set<string | number>();\n\n function matchText(node: T, children: T[]): string {\n // Honour the caller-supplied text extractor first — it's the\n // only way to get precise control over what the filter sees when\n // the node carries domain data whose fields would otherwise leak\n // into the default walker.\n if (getSearchText) return getSearchText(node).trim().toLowerCase();\n // Match-text skips secondary children so e.g. a Table's search\n // text only draws from the Table itself, not from its Field\n // rows. The Table is primary, so its own text still counts.\n const searchChildren = children.filter((c) => !isSecondary?.(c));\n return nodeSearchText(node, searchChildren);\n }\n\n function visit(node: T): boolean {\n // A secondary node never drives a filter match — it's\n // effectively invisible to search. Still rendered when the\n // caller opens the parent manually. This is what lets a 28k-row\n // field tree stay searchable at the record level without \"field\n // name contains 'x'\" matches spamming the results.\n if (isSecondary?.(node)) return false;\n\n const key = getKey(node);\n const children = getChildren(node) ?? [];\n const childrenAllSecondary =\n children.length > 0 && children.every((child) => isSecondary?.(child));\n const matches = matchText(node, children).includes(normalizedQuery);\n const visibleChildren: T[] = [];\n\n for (const child of children) {\n if (visit(child)) visibleChildren.push(child);\n }\n\n if (matches) {\n if (children.length > 0) {\n filteredChildren.set(key, children);\n if (!childrenAllSecondary) forcedOpenKeys.add(key);\n }\n return true;\n }\n\n if (visibleChildren.length > 0) {\n filteredChildren.set(key, visibleChildren);\n forcedOpenKeys.add(key);\n return true;\n }\n\n return false;\n }\n\n return {\n roots: roots.filter((root) => visit(root)),\n filteredChildren,\n forcedOpenKeys,\n };\n}\n\nexport function Tree<T>({\n roots,\n empty,\n className,\n showControls = true,\n expandAll: controlledExpandAll,\n onExpandAllChange,\n toolbarClassName,\n getSearchText,\n revealSelected = false,\n ...nodeProps\n}: TreeProps<T>) {\n const [internalExpandAll, setInternalExpandAll] = useState<boolean | null>(null);\n const [filterQuery, setFilterQuery] = useState(\"\");\n const basePaddingPx = nodeProps.basePaddingPx ?? 8;\n const isControlled = onExpandAllChange !== undefined;\n const expandAll = isControlled ? (controlledExpandAll ?? null) : internalExpandAll;\n const totalEdges = useMemo(\n () => countTreeEdges(roots, nodeProps.getChildren),\n [roots, nodeProps.getChildren],\n );\n const showFilter = totalEdges > 20;\n const activeFilter = showFilter ? filterQuery : \"\";\n const filteredTree = useMemo(\n () =>\n filterTreeRoots(\n roots,\n nodeProps.getChildren,\n nodeProps.getKey,\n activeFilter,\n nodeProps.isSecondary,\n getSearchText,\n ),\n [\n roots,\n nodeProps.getChildren,\n nodeProps.getKey,\n activeFilter,\n nodeProps.isSecondary,\n getSearchText,\n ],\n );\n const treeRoots = filteredTree.roots;\n const filteredChildren = filteredTree.filteredChildren;\n // Force-open the selected node's ancestors when revealSelected is set, unioned\n // with the filter's own forced-open keys. Recomputed when the selection moves\n // so the tree follows it without a remount.\n const revealKeys = useMemo(\n () =>\n revealSelected && nodeProps.selected\n ? ancestorPathKeys(roots, nodeProps.getChildren, nodeProps.getKey, nodeProps.selected)\n : null,\n [revealSelected, roots, nodeProps.getChildren, nodeProps.getKey, nodeProps.selected],\n );\n const forcedOpenKeys = useMemo(\n () => mergeKeySets(filteredTree.forcedOpenKeys, revealKeys),\n [filteredTree.forcedOpenKeys, revealKeys],\n );\n const effectiveGetChildren = filteredChildren\n ? (node: T) => filteredChildren.get(nodeProps.getKey(node)) ?? []\n : nodeProps.getChildren;\n const effectiveExpandAll = expandAll;\n const effectiveEmpty = activeFilter.trim() ? (\n <div className=\"px-3 py-4 text-sm text-muted-foreground\">No matching tree nodes.</div>\n ) : (\n empty\n );\n const showControlButtons = showControls && roots.length > 0;\n const showVirtualRow = showFilter || showControlButtons;\n const setExpandAll = (next: boolean | null) => {\n if (isControlled) onExpandAllChange?.(next);\n else setInternalExpandAll(next);\n };\n\n if (treeRoots.length === 0 && !showVirtualRow) return <>{effectiveEmpty ?? null}</>;\n\n return (\n <div className={cn(\"flex flex-col min-h-0\", className)}>\n <div role=\"tree\" className=\"min-h-0 flex-1 overflow-auto\">\n {showVirtualRow && (\n <div\n role=\"presentation\"\n className={cn(\n \"sticky top-0 z-10 flex items-center gap-1.5 border-b border-border/70 bg-background/95 py-1 pr-2 text-sm backdrop-blur supports-[backdrop-filter]:bg-background/80\",\n toolbarClassName,\n )}\n style={{ paddingLeft: `${basePaddingPx}px` }}\n >\n {showFilter ? (\n <Icon icon={UiSearch} className=\"w-3 shrink-0 text-xs text-muted-foreground\" />\n ) : (\n <span className=\"w-3 shrink-0\" aria-hidden />\n )}\n\n {showFilter ? (\n <label className=\"flex min-w-0 flex-1 items-center gap-2 rounded-md border border-border bg-background px-2 py-1 text-xs text-foreground shadow-sm\">\n <input\n type=\"search\"\n value={filterQuery}\n onChange={(event) => setFilterQuery(event.target.value)}\n placeholder=\"Filter tree\"\n className=\"h-5 w-full min-w-0 border-0 bg-transparent p-0 text-xs outline-none placeholder:text-muted-foreground\"\n aria-label=\"Filter tree nodes\"\n />\n {filterQuery && (\n <button\n type=\"button\"\n onClick={() => setFilterQuery(\"\")}\n className=\"inline-flex items-center rounded p-0.5 text-muted-foreground hover:bg-accent hover:text-accent-foreground\"\n aria-label=\"Clear tree filter\"\n title=\"Clear tree filter\"\n >\n <Icon icon={UiClose} className=\"text-xs\" />\n </button>\n )}\n </label>\n ) : (\n <span className=\"flex-1\" />\n )}\n\n {showControlButtons && (\n <div className=\"ml-auto flex items-center gap-1\">\n <button\n type=\"button\"\n onClick={() => setExpandAll(true)}\n aria-pressed={effectiveExpandAll === true}\n aria-label=\"Expand all\"\n title=\"Expand all\"\n disabled={activeFilter.trim().length > 0}\n className={cn(\n \"inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n effectiveExpandAll === true && \"bg-accent text-accent-foreground\",\n )}\n >\n <Icon icon={UiExpandAll} className=\"text-sm\" />\n </button>\n <button\n type=\"button\"\n onClick={() => setExpandAll(false)}\n aria-pressed={effectiveExpandAll === false}\n aria-label=\"Collapse all\"\n title=\"Collapse all\"\n disabled={activeFilter.trim().length > 0}\n className={cn(\n \"inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:cursor-not-allowed disabled:opacity-50\",\n effectiveExpandAll === false && \"bg-accent text-accent-foreground\",\n )}\n >\n <Icon icon={UiCollapseAll} className=\"text-sm\" />\n </button>\n </div>\n )}\n </div>\n )}\n\n {treeRoots.length === 0 ? (\n (effectiveEmpty ?? null)\n ) : (\n <>\n {treeRoots.map((root) => (\n <TreeNode<T>\n {...nodeProps}\n key={nodeProps.getKey(root)}\n node={root}\n expandAll={effectiveExpandAll}\n forcedOpenKeys={forcedOpenKeys}\n getChildren={effectiveGetChildren}\n />\n ))}\n </>\n )}\n </div>\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;AA0DA,SAAS,iBACP,OACA,aACA,QACA,QAC6B;AAC7B,QAAM,YAAY,OAAO,MAAM;AAC/B,QAAM,OAA4B,CAAA;AAClC,QAAM,QAAQ,CAAC,SAAqB;AAClC,QAAI,OAAO,IAAI,MAAM,UAAW,QAAO;AACvC,eAAW,SAAS,YAAY,IAAI,KAAK,CAAA,GAAI;AAC3C,UAAI,MAAM,KAAK,GAAG;AAChB,aAAK,KAAK,OAAO,IAAI,CAAC;AACtB,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACA,aAAW,QAAQ,OAAO;AACxB,QAAI,MAAM,IAAI,EAAG,QAAO,KAAK,SAAS,IAAI,IAAI,IAAI,IAAI;AAAA,EACxD;AACA,SAAO;AACT;AAIA,SAAS,aACP,GACA,GAC6B;AAC7B,MAAI,CAAC,EAAG,QAAO;AACf,MAAI,CAAC,EAAG,QAAO;AACf,6BAAW,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;AAC7B;AAQA,SAAS,eAAkB,OAAY,aAA0C;AAC/E,MAAI,QAAQ;AACZ,QAAM,QAAQ,CAAC,GAAG,KAAK;AAEvB,SAAO,MAAM,SAAS,GAAG;AACvB,UAAM,OAAO,MAAM,IAAA;AACnB,UAAM,WAAW,YAAY,IAAI,KAAK,CAAA;AACtC,aAAS,SAAS;AAClB,UAAM,KAAK,GAAG,QAAQ;AAAA,EACxB;AAEA,SAAO;AACT;AAEA,SAAS,sBACP,OACA,WAAW,oBAAI,OACf,OAAO,oBAAI,OACH;AACR,MAAI,SAAS,QAAQ,SAAS,IAAI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"Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const utils = require("../../lib/utils.cjs");
5
+ const Icon = require("../Icon.cjs");
6
+ const chatWindowContext = require("./chat-window-context.cjs");
7
+ const UiComment = require("../../icons/components/UiComment.cjs");
8
+ function ChatFab({ icon = UiComment.UiComment, label = "Open chat", className }) {
9
+ const { panels, openPanel } = chatWindowContext.useChatWindowManager();
10
+ if (panels.length > 0) return null;
11
+ return /* @__PURE__ */ jsxRuntime.jsx(
12
+ "button",
13
+ {
14
+ type: "button",
15
+ "data-testid": "chat-fab",
16
+ title: label,
17
+ "aria-label": label,
18
+ onClick: () => openPanel(),
19
+ className: utils.cn(
20
+ "fixed bottom-4 right-4 z-[60] flex h-12 w-12 items-center justify-center",
21
+ "rounded-full bg-primary text-primary-foreground shadow-lg transition-colors hover:bg-primary/90",
22
+ className
23
+ ),
24
+ children: /* @__PURE__ */ jsxRuntime.jsx(Icon.Icon, { ...typeof icon === "string" ? { name: icon } : { icon }, className: "size-5" })
25
+ }
26
+ );
27
+ }
28
+ exports.ChatFab = ChatFab;
29
+ //# sourceMappingURL=ChatFab.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatFab.cjs","sources":["../../../src/data/ai/ChatFab.tsx"],"sourcesContent":["import { cn } from \"../../lib/utils\";\nimport { Icon, type StaticIconComponent } from \"../Icon\";\nimport { UiComment } from \"../../icons\";\nimport { useChatWindowManager } from \"./chat-window-context\";\n\nexport type ChatFabProps = {\n /** Iconify name or imported icon component shown in the button. */\n icon?: string | StaticIconComponent;\n /** Accessible label / tooltip. */\n label?: string;\n className?: string;\n};\n\n/** A fixed bottom-right launch button that opens the first chat window. It\n * hides itself once any window is open (the windows carry their own controls). */\nexport function ChatFab({ icon = UiComment, label = \"Open chat\", className }: ChatFabProps) {\n const { panels, openPanel } = useChatWindowManager();\n if (panels.length > 0) return null;\n\n return (\n <button\n type=\"button\"\n data-testid=\"chat-fab\"\n title={label}\n aria-label={label}\n onClick={() => openPanel()}\n className={cn(\n \"fixed bottom-4 right-4 z-[60] flex h-12 w-12 items-center justify-center\",\n \"rounded-full bg-primary text-primary-foreground shadow-lg transition-colors hover:bg-primary/90\",\n className,\n )}\n >\n <Icon {...(typeof icon === \"string\" ? { name: icon } : { icon })} className=\"size-5\" />\n </button>\n );\n}\n"],"names":["UiComment","useChatWindowManager","jsx","cn","Icon"],"mappings":";;;;;;;AAeO,SAAS,QAAQ,EAAE,OAAOA,UAAAA,WAAW,QAAQ,aAAa,aAA2B;AAC1F,QAAM,EAAE,QAAQ,UAAA,IAAcC,uCAAA;AAC9B,MAAI,OAAO,SAAS,EAAG,QAAO;AAE9B,SACEC,2BAAAA;AAAAA,IAAC;AAAA,IAAA;AAAA,MACC,MAAK;AAAA,MACL,eAAY;AAAA,MACZ,OAAO;AAAA,MACP,cAAY;AAAA,MACZ,SAAS,MAAM,UAAA;AAAA,MACf,WAAWC,MAAAA;AAAAA,QACT;AAAA,QACA;AAAA,QACA;AAAA,MAAA;AAAA,MAGF,UAAAD,2BAAAA,IAACE,KAAAA,MAAA,EAAM,GAAI,OAAO,SAAS,WAAW,EAAE,MAAM,KAAA,IAAS,EAAE,KAAA,GAAS,WAAU,SAAA,CAAS;AAAA,IAAA;AAAA,EAAA;AAG3F;;"}
@@ -0,0 +1,12 @@
1
+ import { StaticIconComponent } from '../Icon';
2
+ export type ChatFabProps = {
3
+ /** Iconify name or imported icon component shown in the button. */
4
+ icon?: string | StaticIconComponent;
5
+ /** Accessible label / tooltip. */
6
+ label?: string;
7
+ className?: string;
8
+ };
9
+ /** A fixed bottom-right launch button that opens the first chat window. It
10
+ * hides itself once any window is open (the windows carry their own controls). */
11
+ export declare function ChatFab({ icon, label, className }: ChatFabProps): import("react/jsx-runtime").JSX.Element | null;
12
+ //# sourceMappingURL=ChatFab.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatFab.d.ts","sourceRoot":"","sources":["../../../src/data/ai/ChatFab.tsx"],"names":[],"mappings":"AACA,OAAO,EAAQ,KAAK,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAIzD,MAAM,MAAM,YAAY,GAAG;IACzB,mEAAmE;IACnE,IAAI,CAAC,EAAE,MAAM,GAAG,mBAAmB,CAAC;IACpC,kCAAkC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;mFACmF;AACnF,wBAAgB,OAAO,CAAC,EAAE,IAAgB,EAAE,KAAmB,EAAE,SAAS,EAAE,EAAE,YAAY,kDAoBzF"}
@@ -0,0 +1,29 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { cn } from "../../lib/utils.js";
3
+ import { Icon } from "../Icon.js";
4
+ import { useChatWindowManager } from "./chat-window-context.js";
5
+ import { UiComment } from "../../icons/components/UiComment.js";
6
+ function ChatFab({ icon = UiComment, label = "Open chat", className }) {
7
+ const { panels, openPanel } = useChatWindowManager();
8
+ if (panels.length > 0) return null;
9
+ return /* @__PURE__ */ jsx(
10
+ "button",
11
+ {
12
+ type: "button",
13
+ "data-testid": "chat-fab",
14
+ title: label,
15
+ "aria-label": label,
16
+ onClick: () => openPanel(),
17
+ className: cn(
18
+ "fixed bottom-4 right-4 z-[60] flex h-12 w-12 items-center justify-center",
19
+ "rounded-full bg-primary text-primary-foreground shadow-lg transition-colors hover:bg-primary/90",
20
+ className
21
+ ),
22
+ children: /* @__PURE__ */ jsx(Icon, { ...typeof icon === "string" ? { name: icon } : { icon }, className: "size-5" })
23
+ }
24
+ );
25
+ }
26
+ export {
27
+ ChatFab
28
+ };
29
+ //# sourceMappingURL=ChatFab.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatFab.js","sources":["../../../src/data/ai/ChatFab.tsx"],"sourcesContent":["import { cn } from \"../../lib/utils\";\nimport { Icon, type StaticIconComponent } from \"../Icon\";\nimport { UiComment } from \"../../icons\";\nimport { useChatWindowManager } from \"./chat-window-context\";\n\nexport type ChatFabProps = {\n /** Iconify name or imported icon component shown in the button. */\n icon?: string | StaticIconComponent;\n /** Accessible label / tooltip. */\n label?: string;\n className?: string;\n};\n\n/** A fixed bottom-right launch button that opens the first chat window. It\n * hides itself once any window is open (the windows carry their own controls). */\nexport function ChatFab({ icon = UiComment, label = \"Open chat\", className }: ChatFabProps) {\n const { panels, openPanel } = useChatWindowManager();\n if (panels.length > 0) return null;\n\n return (\n <button\n type=\"button\"\n data-testid=\"chat-fab\"\n title={label}\n aria-label={label}\n onClick={() => openPanel()}\n className={cn(\n \"fixed bottom-4 right-4 z-[60] flex h-12 w-12 items-center justify-center\",\n \"rounded-full bg-primary text-primary-foreground shadow-lg transition-colors hover:bg-primary/90\",\n className,\n )}\n >\n <Icon {...(typeof icon === \"string\" ? { name: icon } : { icon })} className=\"size-5\" />\n </button>\n );\n}\n"],"names":[],"mappings":";;;;;AAeO,SAAS,QAAQ,EAAE,OAAO,WAAW,QAAQ,aAAa,aAA2B;AAC1F,QAAM,EAAE,QAAQ,UAAA,IAAc,qBAAA;AAC9B,MAAI,OAAO,SAAS,EAAG,QAAO;AAE9B,SACE;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,MAAK;AAAA,MACL,eAAY;AAAA,MACZ,OAAO;AAAA,MACP,cAAY;AAAA,MACZ,SAAS,MAAM,UAAA;AAAA,MACf,WAAW;AAAA,QACT;AAAA,QACA;AAAA,QACA;AAAA,MAAA;AAAA,MAGF,UAAA,oBAAC,MAAA,EAAM,GAAI,OAAO,SAAS,WAAW,EAAE,MAAM,KAAA,IAAS,EAAE,KAAA,GAAS,WAAU,SAAA,CAAS;AAAA,IAAA;AAAA,EAAA;AAG3F;"}
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
25
+ const jsxRuntime = require("react/jsx-runtime");
26
+ const react = require("react");
27
+ const utils = require("../../lib/utils.cjs");
28
+ const button = require("../../components/button.cjs");
29
+ const Icon = require("../Icon.cjs");
30
+ const Chat = require("../chat/Chat.cjs");
31
+ const chatWindowContext = require("./chat-window-context.cjs");
32
+ const ThreadPicker = require("./ThreadPicker.cjs");
33
+ const ContextBadges = require("./ContextBadges.cjs");
34
+ const ToolPreferences = require("./ToolPreferences.cjs");
35
+ const context = require("./context.cjs");
36
+ const UiAdd = require("../../icons/components/UiAdd.cjs");
37
+ const UiFullscreen = require("../../icons/components/UiFullscreen.cjs");
38
+ const UiClose = require("../../icons/components/UiClose.cjs");
39
+ const MAXIMIZE_CSS = `
40
+ .chat-maximized .react-draggable {
41
+ transform: none !important;
42
+ width: auto !important;
43
+ height: auto !important;
44
+ inset: 0 !important;
45
+ position: absolute !important;
46
+ }`;
47
+ function ChatWindow({
48
+ panel,
49
+ chat,
50
+ title = "Assistant",
51
+ threadsApi = "/api/chat/threads",
52
+ threadsSource,
53
+ contextTypeConfig,
54
+ tools,
55
+ headerExtras
56
+ }) {
57
+ const { updatePanel, closePanel, bringToFront, maximizePanel, openPanel } = chatWindowContext.useChatWindowManager();
58
+ const [Rnd, setRnd] = react.useState(null);
59
+ const [toolPrefs, setToolPrefs] = react.useState({});
60
+ react.useEffect(() => {
61
+ if (!(tools == null ? void 0 : tools.length)) return;
62
+ setToolPrefs((prev) => {
63
+ const next = { ...prev };
64
+ let changed = false;
65
+ for (const t of tools) {
66
+ if (next[t.name] === void 0) {
67
+ next[t.name] = "ask";
68
+ changed = true;
69
+ }
70
+ }
71
+ return changed ? next : prev;
72
+ });
73
+ }, [tools]);
74
+ react.useEffect(() => {
75
+ let active = true;
76
+ import("react-rnd").then((m) => {
77
+ if (active) setRnd(() => m.Rnd);
78
+ });
79
+ return () => {
80
+ active = false;
81
+ };
82
+ }, []);
83
+ const removeContext = react.useCallback(
84
+ (id) => updatePanel(panel.id, { contextItems: panel.contextItems.filter((c) => c.id !== id) }),
85
+ [updatePanel, panel.id, panel.contextItems]
86
+ );
87
+ const mergedBody = {
88
+ ...chat == null ? void 0 : chat.body,
89
+ ...panel.contextItems.length ? { context: context.serializeContext(panel.contextItems) } : {},
90
+ ...tools ? { toolPreferences: toolPrefs } : {}
91
+ };
92
+ const header = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "chat-drag-handle flex cursor-move items-center gap-1 border-b border-border bg-muted/40 px-2 py-1.5", children: [
93
+ threadsSource != null || threadsApi !== null ? /* @__PURE__ */ jsxRuntime.jsx(
94
+ ThreadPicker.ThreadPicker,
95
+ {
96
+ threadId: panel.threadId,
97
+ onSelect: (tid) => updatePanel(panel.id, { threadId: tid }),
98
+ onNew: () => updatePanel(panel.id, { threadId: null }),
99
+ ...threadsSource ? { source: threadsSource } : threadsApi !== null ? { api: threadsApi } : {}
100
+ }
101
+ ) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "px-1 text-sm font-medium", children: title }),
102
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1" }),
103
+ headerExtras,
104
+ tools && /* @__PURE__ */ jsxRuntime.jsx(ToolPreferences.ToolPreferences, { tools, value: toolPrefs, onChange: setToolPrefs }),
105
+ /* @__PURE__ */ jsxRuntime.jsx(button.Button, { variant: "ghost", size: "icon", title: "New window", onClick: () => openPanel(), children: /* @__PURE__ */ jsxRuntime.jsx(Icon.Icon, { icon: UiAdd.UiAdd, className: "size-4" }) }),
106
+ /* @__PURE__ */ jsxRuntime.jsx(
107
+ button.Button,
108
+ {
109
+ variant: "ghost",
110
+ size: "icon",
111
+ title: panel.maximized ? "Restore" : "Maximize",
112
+ onClick: () => maximizePanel(panel.id),
113
+ children: /* @__PURE__ */ jsxRuntime.jsx(Icon.Icon, { icon: UiFullscreen.UiFullscreen, className: "size-4" })
114
+ }
115
+ ),
116
+ /* @__PURE__ */ jsxRuntime.jsx(button.Button, { variant: "ghost", size: "icon", title: "Close", onClick: () => closePanel(panel.id), children: /* @__PURE__ */ jsxRuntime.jsx(Icon.Icon, { icon: UiClose.UiClose, className: "size-4" }) })
117
+ ] });
118
+ const frame = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden rounded-lg border border-border bg-background shadow-xl", children: [
119
+ header,
120
+ /* @__PURE__ */ jsxRuntime.jsx(
121
+ ContextBadges.ContextBadges,
122
+ {
123
+ items: panel.contextItems,
124
+ onRemove: removeContext,
125
+ ...contextTypeConfig ? { typeConfig: contextTypeConfig } : {}
126
+ }
127
+ ),
128
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-h-0 flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
129
+ Chat.Chat,
130
+ {
131
+ ...chat,
132
+ ...panel.threadId ? { threadId: panel.threadId } : {},
133
+ body: mergedBody
134
+ }
135
+ ) })
136
+ ] });
137
+ const outerClass = utils.cn(
138
+ "fixed pointer-events-none",
139
+ panel.maximized ? "inset-4 chat-maximized" : "inset-0"
140
+ );
141
+ if (!Rnd) {
142
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: outerClass, style: { zIndex: panel.zIndex }, children: /* @__PURE__ */ jsxRuntime.jsx(
143
+ "div",
144
+ {
145
+ className: "pointer-events-auto h-full",
146
+ style: panel.maximized ? { position: "relative", width: "100%", height: "100%" } : { position: "absolute", left: panel.x, top: panel.y, width: panel.width, height: panel.height },
147
+ children: frame
148
+ }
149
+ ) });
150
+ }
151
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: outerClass, style: { zIndex: panel.zIndex }, children: [
152
+ /* @__PURE__ */ jsxRuntime.jsx("style", { children: MAXIMIZE_CSS }),
153
+ /* @__PURE__ */ jsxRuntime.jsx(
154
+ Rnd,
155
+ {
156
+ default: { x: panel.x, y: panel.y, width: panel.width, height: panel.height },
157
+ style: { pointerEvents: "auto" },
158
+ minWidth: 360,
159
+ minHeight: 400,
160
+ bounds: "parent",
161
+ dragHandleClassName: "chat-drag-handle",
162
+ disableDragging: panel.maximized,
163
+ enableResizing: !panel.maximized,
164
+ onDragStart: () => bringToFront(panel.id),
165
+ onDragStop: (_e, d) => updatePanel(panel.id, { x: d.x, y: d.y }),
166
+ onResizeStop: (_e, _dir, ref, _delta, pos) => updatePanel(panel.id, { width: ref.offsetWidth, height: ref.offsetHeight, x: pos.x, y: pos.y }),
167
+ children: frame
168
+ }
169
+ )
170
+ ] });
171
+ }
172
+ function ChatWindowLayer(props) {
173
+ const { panels } = chatWindowContext.useChatWindowManager();
174
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: panels.map((panel) => /* @__PURE__ */ jsxRuntime.jsx(ChatWindow, { panel, ...props }, panel.id)) });
175
+ }
176
+ exports.ChatWindow = ChatWindow;
177
+ exports.ChatWindowLayer = ChatWindowLayer;
178
+ //# sourceMappingURL=ChatWindow.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatWindow.cjs","sources":["../../../src/data/ai/ChatWindow.tsx"],"sourcesContent":["import { useCallback, useEffect, useState, type ReactNode } from \"react\";\nimport { cn } from \"../../lib/utils\";\nimport { Button } from \"../../components/button\";\nimport { Icon } from \"../Icon\";\nimport { UiAdd, UiClose, UiFullscreen } from \"../../icons\";\nimport { Chat, type ChatProps } from \"../chat/Chat\";\nimport { useChatWindowManager, type ChatWindowState } from \"./chat-window-context\";\nimport { ThreadPicker, type ThreadSource } from \"./ThreadPicker\";\nimport { ContextBadges } from \"./ContextBadges\";\nimport { ToolPreferences, type ToolMeta, type ToolMode } from \"./ToolPreferences\";\nimport { serializeContext, type ContextTypeConfig } from \"./context\";\n\nexport type ChatWindowProps = {\n panel: ChatWindowState;\n /** Props forwarded to the inner <Chat>. The window manages `threadId` and\n * merges attached context / tool preferences into `body` on top of these. */\n chat?: Partial<ChatProps>;\n /** Header title shown when the thread picker is disabled. */\n title?: ReactNode;\n /** Thread switcher endpoint, or null to hide the picker. Defaults to\n * \"/api/chat/threads\". Ignored when `threadsSource` is set. */\n threadsApi?: string | null;\n /** Inject the thread list/delete directly instead of fetching `threadsApi`\n * (e.g. an app that loads conversations via its own client). Shows the\n * picker regardless of `threadsApi`. */\n threadsSource?: ThreadSource;\n /** Maps context item `type` to an icon/colour for the badge row. */\n contextTypeConfig?: ContextTypeConfig;\n /** When provided, a tool-preferences popover is shown and forwarded as\n * `body.toolPreferences`. Tools default to \"ask\" (approval required); the\n * user can switch any tool to Auto/Off from the popover. */\n tools?: ToolMeta[];\n /** Extra controls rendered in the header, e.g. a <ContextUsage/> gauge. */\n headerExtras?: ReactNode;\n};\n\nconst MAXIMIZE_CSS = `\n.chat-maximized .react-draggable {\n transform: none !important;\n width: auto !important;\n height: auto !important;\n inset: 0 !important;\n position: absolute !important;\n}`;\n\n/** A draggable, resizable floating chat window. It lazy-loads `react-rnd` (an\n * optional dependency, so consumers of just the inner <Chat> never pull it)\n * and renders the existing <Chat> beneath a drag-handle header with thread\n * switching, a context-badge row and optional tool preferences. */\nexport function ChatWindow({\n panel,\n chat,\n title = \"Assistant\",\n threadsApi = \"/api/chat/threads\",\n threadsSource,\n contextTypeConfig,\n tools,\n headerExtras,\n}: ChatWindowProps) {\n const { updatePanel, closePanel, bringToFront, maximizePanel, openPanel } = useChatWindowManager();\n const [Rnd, setRnd] = useState<typeof import(\"react-rnd\").Rnd | null>(null);\n const [toolPrefs, setToolPrefs] = useState<Record<string, ToolMode>>({});\n\n // Tools default to \"ask\" (human-in-the-loop approval) on chat windows. Seed\n // any tool the user hasn't configured yet; existing choices are preserved.\n // Handles tools that load asynchronously after mount.\n useEffect(() => {\n if (!tools?.length) return;\n setToolPrefs((prev) => {\n const next = { ...prev };\n let changed = false;\n for (const t of tools) {\n if (next[t.name] === undefined) {\n next[t.name] = \"ask\";\n changed = true;\n }\n }\n return changed ? next : prev;\n });\n }, [tools]);\n\n useEffect(() => {\n let active = true;\n import(\"react-rnd\").then((m) => {\n if (active) setRnd(() => m.Rnd);\n });\n return () => {\n active = false;\n };\n }, []);\n\n const removeContext = useCallback(\n (id: string) =>\n updatePanel(panel.id, { contextItems: panel.contextItems.filter((c) => c.id !== id) }),\n [updatePanel, panel.id, panel.contextItems],\n );\n\n const mergedBody: Record<string, unknown> = {\n ...chat?.body,\n ...(panel.contextItems.length ? { context: serializeContext(panel.contextItems) } : {}),\n ...(tools ? { toolPreferences: toolPrefs } : {}),\n };\n\n const header = (\n <div className=\"chat-drag-handle flex cursor-move items-center gap-1 border-b border-border bg-muted/40 px-2 py-1.5\">\n {threadsSource != null || threadsApi !== null ? (\n <ThreadPicker\n threadId={panel.threadId}\n onSelect={(tid) => updatePanel(panel.id, { threadId: tid })}\n onNew={() => updatePanel(panel.id, { threadId: null })}\n {...(threadsSource\n ? { source: threadsSource }\n : threadsApi !== null\n ? { api: threadsApi }\n : {})}\n />\n ) : (\n <span className=\"px-1 text-sm font-medium\">{title}</span>\n )}\n <div className=\"flex-1\" />\n {headerExtras}\n {tools && <ToolPreferences tools={tools} value={toolPrefs} onChange={setToolPrefs} />}\n <Button variant=\"ghost\" size=\"icon\" title=\"New window\" onClick={() => openPanel()}>\n <Icon icon={UiAdd} className=\"size-4\" />\n </Button>\n <Button\n variant=\"ghost\"\n size=\"icon\"\n title={panel.maximized ? \"Restore\" : \"Maximize\"}\n onClick={() => maximizePanel(panel.id)}\n >\n <Icon icon={UiFullscreen} className=\"size-4\" />\n </Button>\n <Button variant=\"ghost\" size=\"icon\" title=\"Close\" onClick={() => closePanel(panel.id)}>\n <Icon icon={UiClose} className=\"size-4\" />\n </Button>\n </div>\n );\n\n const frame = (\n <div className=\"flex h-full flex-col overflow-hidden rounded-lg border border-border bg-background shadow-xl\">\n {header}\n <ContextBadges\n items={panel.contextItems}\n onRemove={removeContext}\n {...(contextTypeConfig ? { typeConfig: contextTypeConfig } : {})}\n />\n <div className=\"min-h-0 flex-1\">\n <Chat\n {...chat}\n {...(panel.threadId ? { threadId: panel.threadId } : {})}\n body={mergedBody}\n />\n </div>\n </div>\n );\n\n const outerClass = cn(\n \"fixed pointer-events-none\",\n panel.maximized ? \"inset-4 chat-maximized\" : \"inset-0\",\n );\n\n // Until react-rnd loads (and as a graceful fallback if it never does) the\n // window is statically positioned — still usable, just not draggable.\n if (!Rnd) {\n return (\n <div className={outerClass} style={{ zIndex: panel.zIndex }}>\n <div\n className=\"pointer-events-auto h-full\"\n style={\n panel.maximized\n ? { position: \"relative\", width: \"100%\", height: \"100%\" }\n : { position: \"absolute\", left: panel.x, top: panel.y, width: panel.width, height: panel.height }\n }\n >\n {frame}\n </div>\n </div>\n );\n }\n\n return (\n <div className={outerClass} style={{ zIndex: panel.zIndex }}>\n <style>{MAXIMIZE_CSS}</style>\n <Rnd\n default={{ x: panel.x, y: panel.y, width: panel.width, height: panel.height }}\n style={{ pointerEvents: \"auto\" }}\n minWidth={360}\n minHeight={400}\n bounds=\"parent\"\n dragHandleClassName=\"chat-drag-handle\"\n disableDragging={panel.maximized}\n enableResizing={!panel.maximized}\n onDragStart={() => bringToFront(panel.id)}\n onDragStop={(_e, d) => updatePanel(panel.id, { x: d.x, y: d.y })}\n onResizeStop={(_e, _dir, ref, _delta, pos) =>\n updatePanel(panel.id, { width: ref.offsetWidth, height: ref.offsetHeight, x: pos.x, y: pos.y })\n }\n >\n {frame}\n </Rnd>\n </div>\n );\n}\n\n/** Renders every open window for the current {@link useChatWindowManager}.\n * Drop one of these near the root alongside a <ChatFab/>. */\nexport function ChatWindowLayer(props: Omit<ChatWindowProps, \"panel\">) {\n const { panels } = useChatWindowManager();\n return (\n <>\n {panels.map((panel) => (\n <ChatWindow key={panel.id} panel={panel} {...props} />\n ))}\n </>\n );\n}\n"],"names":["useChatWindowManager","useState","useEffect","useCallback","serializeContext","jsxs","jsx","ThreadPicker","ToolPreferences","Button","Icon","UiAdd","UiFullscreen","UiClose","ContextBadges","Chat","cn","Fragment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAM,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAad,SAAS,WAAW;AAAA,EACzB;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR,aAAa;AAAA,EACb;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAoB;AAClB,QAAM,EAAE,aAAa,YAAY,cAAc,eAAe,UAAA,IAAcA,uCAAA;AAC5E,QAAM,CAAC,KAAK,MAAM,IAAIC,MAAAA,SAAgD,IAAI;AAC1E,QAAM,CAAC,WAAW,YAAY,IAAIA,MAAAA,SAAmC,CAAA,CAAE;AAKvEC,QAAAA,UAAU,MAAM;AACd,QAAI,EAAC,+BAAO,QAAQ;AACpB,iBAAa,CAAC,SAAS;AACrB,YAAM,OAAO,EAAE,GAAG,KAAA;AAClB,UAAI,UAAU;AACd,iBAAW,KAAK,OAAO;AACrB,YAAI,KAAK,EAAE,IAAI,MAAM,QAAW;AAC9B,eAAK,EAAE,IAAI,IAAI;AACf,oBAAU;AAAA,QACZ;AAAA,MACF;AACA,aAAO,UAAU,OAAO;AAAA,IAC1B,CAAC;AAAA,EACH,GAAG,CAA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AACrE,QAAM,EAAE,OAAA,IAAWN,uCAAA;AACnB,SACEM,2BAAAA,IAAAW,WAAAA,UAAA,EACG,UAAA,OAAO,IAAI,CAAC,UACXX,2BAAAA,IAAC,YAAA,EAA0B,OAAe,GAAG,MAAA,GAA5B,MAAM,EAA6B,CACrD,GACH;AAEJ;;;"}
@@ -0,0 +1,38 @@
1
+ import { ReactNode } from 'react';
2
+ import { ChatProps } from '../chat/Chat';
3
+ import { ChatWindowState } from './chat-window-context';
4
+ import { ThreadSource } from './ThreadPicker';
5
+ import { ToolMeta } from './ToolPreferences';
6
+ import { ContextTypeConfig } from './context';
7
+ export type ChatWindowProps = {
8
+ panel: ChatWindowState;
9
+ /** Props forwarded to the inner <Chat>. The window manages `threadId` and
10
+ * merges attached context / tool preferences into `body` on top of these. */
11
+ chat?: Partial<ChatProps>;
12
+ /** Header title shown when the thread picker is disabled. */
13
+ title?: ReactNode;
14
+ /** Thread switcher endpoint, or null to hide the picker. Defaults to
15
+ * "/api/chat/threads". Ignored when `threadsSource` is set. */
16
+ threadsApi?: string | null;
17
+ /** Inject the thread list/delete directly instead of fetching `threadsApi`
18
+ * (e.g. an app that loads conversations via its own client). Shows the
19
+ * picker regardless of `threadsApi`. */
20
+ threadsSource?: ThreadSource;
21
+ /** Maps context item `type` to an icon/colour for the badge row. */
22
+ contextTypeConfig?: ContextTypeConfig;
23
+ /** When provided, a tool-preferences popover is shown and forwarded as
24
+ * `body.toolPreferences`. Tools default to "ask" (approval required); the
25
+ * user can switch any tool to Auto/Off from the popover. */
26
+ tools?: ToolMeta[];
27
+ /** Extra controls rendered in the header, e.g. a <ContextUsage/> gauge. */
28
+ headerExtras?: ReactNode;
29
+ };
30
+ /** A draggable, resizable floating chat window. It lazy-loads `react-rnd` (an
31
+ * optional dependency, so consumers of just the inner <Chat> never pull it)
32
+ * and renders the existing <Chat> beneath a drag-handle header with thread
33
+ * switching, a context-badge row and optional tool preferences. */
34
+ export declare function ChatWindow({ panel, chat, title, threadsApi, threadsSource, contextTypeConfig, tools, headerExtras, }: ChatWindowProps): import("react/jsx-runtime").JSX.Element;
35
+ /** Renders every open window for the current {@link useChatWindowManager}.
36
+ * Drop one of these near the root alongside a <ChatFab/>. */
37
+ export declare function ChatWindowLayer(props: Omit<ChatWindowProps, "panel">): import("react/jsx-runtime").JSX.Element;
38
+ //# sourceMappingURL=ChatWindow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatWindow.d.ts","sourceRoot":"","sources":["../../../src/data/ai/ChatWindow.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAKzE,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAwB,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACnF,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAmB,KAAK,QAAQ,EAAiB,MAAM,mBAAmB,CAAC;AAClF,OAAO,EAAoB,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAErE,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,eAAe,CAAC;IACvB;kFAC8E;IAC9E,IAAI,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAC1B,6DAA6D;IAC7D,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB;oEACgE;IAChE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B;;6CAEyC;IACzC,aAAa,CAAC,EAAE,YAAY,CAAC;IAC7B,oEAAoE;IACpE,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC;;iEAE6D;IAC7D,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;IACnB,2EAA2E;IAC3E,YAAY,CAAC,EAAE,SAAS,CAAC;CAC1B,CAAC;AAWF;;;oEAGoE;AACpE,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,I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