@vuer-ai/vuer-uikit 0.0.96 → 0.0.98

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 (341) hide show
  1. package/README.md +106 -7
  2. package/cli/dial-cli.js +49 -7
  3. package/dist/SyncScroll/SyncScroll.cjs +10 -10
  4. package/dist/SyncScroll/SyncScroll.mjs +3 -3
  5. package/dist/SyncScroll/index.cjs +10 -10
  6. package/dist/SyncScroll/index.mjs +3 -3
  7. package/dist/chunk-3HEZVWRW.mjs +62 -0
  8. package/dist/chunk-4KWGGESI.cjs +494 -0
  9. package/dist/{chunk-CCMKL2OA.cjs → chunk-7GWDO25E.cjs} +2 -2
  10. package/dist/chunk-A5LCX2UQ.cjs +208 -0
  11. package/dist/chunk-BEJIZ56L.mjs +300 -0
  12. package/dist/chunk-C7VGRU3O.mjs +283 -0
  13. package/dist/{chunk-LONOMMFA.cjs → chunk-LJMNHTTG.cjs} +21 -21
  14. package/dist/chunk-O66RESRR.cjs +285 -0
  15. package/dist/{chunk-RINTUFYQ.cjs → chunk-RMK6W774.cjs} +24 -19
  16. package/dist/{chunk-BFQ2WL5U.mjs → chunk-TTYSYGVE.mjs} +2 -2
  17. package/dist/chunk-VA3PEYFM.mjs +489 -0
  18. package/dist/chunk-VBBJSIY7.cjs +308 -0
  19. package/dist/{chunk-AIINOWEH.mjs → chunk-W4JCKCW7.mjs} +5 -5
  20. package/dist/chunk-WWGF6TBZ.mjs +206 -0
  21. package/dist/chunk-ZGN4UEJR.cjs +679 -0
  22. package/dist/chunk-ZQLRMOUW.mjs +661 -0
  23. package/dist/dial/DialPanel.cjs +24 -24
  24. package/dist/dial/DialPanel.mjs +23 -23
  25. package/dist/dial/DialProvider.cjs +3 -3
  26. package/dist/dial/DialProvider.d.cts +1 -0
  27. package/dist/dial/DialProvider.d.ts +1 -0
  28. package/dist/dial/DialProvider.example.cjs +72 -0
  29. package/dist/dial/DialProvider.example.d.cts +7 -0
  30. package/dist/dial/DialProvider.example.d.ts +7 -0
  31. package/dist/dial/DialProvider.example.mjs +68 -0
  32. package/dist/dial/DialProvider.mjs +1 -1
  33. package/dist/dial/index.cjs +42 -42
  34. package/dist/dial/index.mjs +23 -23
  35. package/dist/dial/wrapped-inputs/ControlledInputs.cjs +27 -27
  36. package/dist/dial/wrapped-inputs/ControlledInputs.mjs +23 -23
  37. package/dist/dial/wrapped-inputs/DialInputs.cjs +34 -34
  38. package/dist/dial/wrapped-inputs/DialInputs.mjs +23 -23
  39. package/dist/dial/wrapped-inputs/DialVectorInput.cjs +24 -24
  40. package/dist/dial/wrapped-inputs/DialVectorInput.mjs +23 -23
  41. package/dist/dial/wrapped-inputs/index.cjs +39 -39
  42. package/dist/dial/wrapped-inputs/index.mjs +23 -23
  43. package/dist/highlight-cursor/cursor-provider.cjs +3 -3
  44. package/dist/highlight-cursor/cursor-provider.mjs +2 -2
  45. package/dist/highlight-cursor/enhanced-components.cjs +10 -10
  46. package/dist/highlight-cursor/enhanced-components.mjs +5 -5
  47. package/dist/highlight-cursor/index.cjs +16 -16
  48. package/dist/highlight-cursor/index.mjs +6 -6
  49. package/dist/hooks/index.cjs +5 -5
  50. package/dist/hooks/index.mjs +1 -1
  51. package/dist/index.cjs +190 -190
  52. package/dist/index.mjs +23 -23
  53. package/dist/ui/UIKitBadge.cjs +6 -6
  54. package/dist/ui/UIKitBadge.mjs +2 -2
  55. package/dist/ui/avatar.cjs +1 -1
  56. package/dist/ui/avatar.mjs +1 -1
  57. package/dist/ui/badge.cjs +1 -1
  58. package/dist/ui/badge.d.cts +1 -1
  59. package/dist/ui/badge.d.ts +1 -1
  60. package/dist/ui/badge.mjs +1 -1
  61. package/dist/ui/button.cjs +1 -1
  62. package/dist/ui/button.mjs +1 -1
  63. package/dist/ui/card.cjs +1 -1
  64. package/dist/ui/card.mjs +1 -1
  65. package/dist/ui/checkbox.cjs +1 -1
  66. package/dist/ui/checkbox.mjs +1 -1
  67. package/dist/ui/collapsible.cjs +1 -1
  68. package/dist/ui/collapsible.mjs +1 -1
  69. package/dist/ui/drawer.cjs +1 -1
  70. package/dist/ui/drawer.mjs +1 -1
  71. package/dist/ui/dropdown.cjs +1 -1
  72. package/dist/ui/dropdown.mjs +1 -1
  73. package/dist/ui/index.cjs +107 -107
  74. package/dist/ui/index.mjs +17 -17
  75. package/dist/ui/inputs/color-input.cjs +1 -1
  76. package/dist/ui/inputs/color-input.mjs +1 -1
  77. package/dist/ui/inputs/index.cjs +11 -11
  78. package/dist/ui/inputs/index.mjs +3 -3
  79. package/dist/ui/inputs/input-numbers.cjs +1 -1
  80. package/dist/ui/inputs/input-numbers.mjs +1 -1
  81. package/dist/ui/inputs/input.cjs +1 -1
  82. package/dist/ui/inputs/input.d.cts +1 -1
  83. package/dist/ui/inputs/input.d.ts +1 -1
  84. package/dist/ui/inputs/input.mjs +1 -1
  85. package/dist/ui/inputs/number-inputs/CmInput.cjs +1 -1
  86. package/dist/ui/inputs/number-inputs/CmInput.mjs +1 -1
  87. package/dist/ui/inputs/number-inputs/DegInput.cjs +1 -1
  88. package/dist/ui/inputs/number-inputs/DegInput.mjs +1 -1
  89. package/dist/ui/inputs/number-inputs/EulerDegInput.cjs +1 -1
  90. package/dist/ui/inputs/number-inputs/EulerDegInput.mjs +1 -1
  91. package/dist/ui/inputs/number-inputs/EulerInput.cjs +1 -1
  92. package/dist/ui/inputs/number-inputs/EulerInput.mjs +1 -1
  93. package/dist/ui/inputs/number-inputs/EulerRadInput.cjs +1 -1
  94. package/dist/ui/inputs/number-inputs/EulerRadInput.mjs +1 -1
  95. package/dist/ui/inputs/number-inputs/InchInput.cjs +1 -1
  96. package/dist/ui/inputs/number-inputs/InchInput.mjs +1 -1
  97. package/dist/ui/inputs/number-inputs/IntInput.cjs +1 -1
  98. package/dist/ui/inputs/number-inputs/IntInput.mjs +1 -1
  99. package/dist/ui/inputs/number-inputs/KVectorInput.cjs +1 -1
  100. package/dist/ui/inputs/number-inputs/KVectorInput.mjs +1 -1
  101. package/dist/ui/inputs/number-inputs/QuaternionInput.cjs +1 -1
  102. package/dist/ui/inputs/number-inputs/QuaternionInput.mjs +1 -1
  103. package/dist/ui/inputs/number-inputs/RadInput.cjs +1 -1
  104. package/dist/ui/inputs/number-inputs/RadInput.mjs +1 -1
  105. package/dist/ui/inputs/number-inputs/TimeInput.cjs +1 -1
  106. package/dist/ui/inputs/number-inputs/TimeInput.mjs +1 -1
  107. package/dist/ui/inputs/number-inputs/Vec3Input.cjs +1 -1
  108. package/dist/ui/inputs/number-inputs/Vec3Input.mjs +1 -1
  109. package/dist/ui/inputs/number-inputs/VectorInput.cjs +1 -1
  110. package/dist/ui/inputs/number-inputs/VectorInput.mjs +1 -1
  111. package/dist/ui/inputs/number-inputs/index.cjs +11 -11
  112. package/dist/ui/inputs/number-inputs/index.mjs +3 -3
  113. package/dist/ui/inputs/presets-input.cjs +1 -1
  114. package/dist/ui/inputs/presets-input.mjs +1 -1
  115. package/dist/ui/label.cjs +1 -1
  116. package/dist/ui/label.mjs +1 -1
  117. package/dist/ui/layout.cjs +1 -1
  118. package/dist/ui/layout.mjs +1 -1
  119. package/dist/ui/layouts/dock-layout/DockLayoutView.cjs +1 -1
  120. package/dist/ui/layouts/dock-layout/DockLayoutView.mjs +1 -1
  121. package/dist/ui/layouts/dock-layout/LayoutSlots.cjs +1 -1
  122. package/dist/ui/layouts/dock-layout/LayoutSlots.mjs +1 -1
  123. package/dist/ui/layouts/dock-layout/index.cjs +1 -1
  124. package/dist/ui/layouts/dock-layout/index.mjs +1 -1
  125. package/dist/ui/layouts/index.cjs +2 -2
  126. package/dist/ui/layouts/index.mjs +2 -2
  127. package/dist/ui/layouts/liquid-layout/LayoutSlots.cjs +1 -1
  128. package/dist/ui/layouts/liquid-layout/LayoutSlots.mjs +1 -1
  129. package/dist/ui/layouts/liquid-layout/LiquidLayoutView.cjs +1 -1
  130. package/dist/ui/layouts/liquid-layout/LiquidLayoutView.mjs +1 -1
  131. package/dist/ui/layouts/liquid-layout/index.cjs +1 -1
  132. package/dist/ui/layouts/liquid-layout/index.mjs +1 -1
  133. package/dist/ui/modal.cjs +1 -1
  134. package/dist/ui/modal.mjs +1 -1
  135. package/dist/ui/navigation.cjs +1 -1
  136. package/dist/ui/navigation.mjs +1 -1
  137. package/dist/ui/pagination.cjs +1 -1
  138. package/dist/ui/pagination.mjs +1 -1
  139. package/dist/ui/panel.cjs +1 -1
  140. package/dist/ui/panel.mjs +1 -1
  141. package/dist/ui/popover.cjs +1 -1
  142. package/dist/ui/popover.mjs +1 -1
  143. package/dist/ui/radio-group.cjs +1 -1
  144. package/dist/ui/radio-group.mjs +1 -1
  145. package/dist/ui/resizable.cjs +1 -1
  146. package/dist/ui/resizable.mjs +1 -1
  147. package/dist/ui/select.cjs +1 -1
  148. package/dist/ui/select.d.cts +1 -1
  149. package/dist/ui/select.d.ts +1 -1
  150. package/dist/ui/select.mjs +1 -1
  151. package/dist/ui/separator.cjs +1 -1
  152. package/dist/ui/separator.mjs +1 -1
  153. package/dist/ui/sheet.cjs +1 -1
  154. package/dist/ui/sheet.mjs +1 -1
  155. package/dist/ui/sidebar.cjs +26 -26
  156. package/dist/ui/sidebar.mjs +2 -2
  157. package/dist/ui/simple-tree-view.cjs +1 -1
  158. package/dist/ui/simple-tree-view.mjs +1 -1
  159. package/dist/ui/skeleton.cjs +1 -1
  160. package/dist/ui/skeleton.mjs +1 -1
  161. package/dist/ui/slider.cjs +1 -1
  162. package/dist/ui/slider.mjs +1 -1
  163. package/dist/ui/switch.cjs +1 -1
  164. package/dist/ui/switch.mjs +1 -1
  165. package/dist/ui/table.cjs +1 -1
  166. package/dist/ui/table.mjs +1 -1
  167. package/dist/ui/tabs.cjs +1 -1
  168. package/dist/ui/tabs.mjs +1 -1
  169. package/dist/ui/textarea.cjs +1 -1
  170. package/dist/ui/textarea.d.cts +1 -1
  171. package/dist/ui/textarea.d.ts +1 -1
  172. package/dist/ui/textarea.mjs +1 -1
  173. package/dist/ui/theme/ThemeToggles.cjs +1 -1
  174. package/dist/ui/theme/ThemeToggles.mjs +1 -1
  175. package/dist/ui/theme/index.cjs +1 -1
  176. package/dist/ui/theme/index.mjs +1 -1
  177. package/dist/ui/toggle-buttons.cjs +1 -1
  178. package/dist/ui/toggle-buttons.mjs +1 -1
  179. package/dist/ui/toggle-group.cjs +1 -1
  180. package/dist/ui/toggle-group.mjs +1 -1
  181. package/dist/ui/toggle.cjs +1 -1
  182. package/dist/ui/toggle.mjs +1 -1
  183. package/dist/ui/toolbar.cjs +1 -1
  184. package/dist/ui/toolbar.mjs +1 -1
  185. package/dist/ui/tooltip.cjs +1 -1
  186. package/dist/ui/tooltip.mjs +1 -1
  187. package/dist/ui/tree-view/TreeSearchBar.cjs +1 -1
  188. package/dist/ui/tree-view/TreeSearchBar.mjs +1 -1
  189. package/dist/ui/tree-view/TreeView.cjs +1 -1
  190. package/dist/ui/tree-view/TreeView.mjs +1 -1
  191. package/dist/ui/tree-view/index.cjs +6 -6
  192. package/dist/ui/tree-view/index.mjs +2 -2
  193. package/dist/ui/tree-view-legacy.cjs +9 -9
  194. package/dist/ui/tree-view-legacy.mjs +5 -5
  195. package/dist/ui/waterfall/CursorOverlay.cjs +1 -1
  196. package/dist/ui/waterfall/CursorOverlay.mjs +1 -1
  197. package/dist/ui/waterfall/TimelineEvent.cjs +1 -1
  198. package/dist/ui/waterfall/TimelineEvent.mjs +1 -1
  199. package/dist/ui/waterfall/TimelineProcessBar.cjs +1 -1
  200. package/dist/ui/waterfall/TimelineProcessBar.mjs +1 -1
  201. package/dist/ui/waterfall/Wedges.cjs +1 -1
  202. package/dist/ui/waterfall/Wedges.mjs +1 -1
  203. package/dist/ui/waterfall/index.cjs +8 -8
  204. package/dist/ui/waterfall/index.mjs +7 -7
  205. package/package.json +28 -2
  206. package/src/SyncScroll/README.md +283 -0
  207. package/src/SyncScroll/SyncScroll.tsx +361 -0
  208. package/src/SyncScroll/index.ts +22 -0
  209. package/src/SyncScroll/useSyncScroll.tsx +226 -0
  210. package/src/cli/dial-cli.ts +1133 -0
  211. package/src/dial/DialPanel.tsx +208 -0
  212. package/src/dial/DialProvider.example.tsx +80 -0
  213. package/src/dial/DialProvider.tsx +138 -0
  214. package/src/dial/index.ts +26 -0
  215. package/src/dial/wrapped-inputs/ControlledInputs.tsx +176 -0
  216. package/src/dial/wrapped-inputs/DialInputs.tsx +401 -0
  217. package/src/dial/wrapped-inputs/DialVectorInput.tsx +125 -0
  218. package/src/dial/wrapped-inputs/index.ts +25 -0
  219. package/src/highlight-cursor/cursor-context.tsx +23 -0
  220. package/src/highlight-cursor/cursor-provider.tsx +264 -0
  221. package/src/highlight-cursor/enhanced-components.tsx +16 -0
  222. package/src/highlight-cursor/index.ts +21 -0
  223. package/src/highlight-cursor/tabs-cursor-context.tsx +121 -0
  224. package/src/highlight-cursor/types.ts +40 -0
  225. package/src/highlight-cursor/with-cursor.tsx +144 -0
  226. package/src/hooks/clientOnly.tsx +54 -0
  227. package/src/hooks/cn.ts +33 -0
  228. package/src/hooks/index.ts +9 -0
  229. package/src/hooks/useDocument.tsx +18 -0
  230. package/src/hooks/useDragSelect.ts +116 -0
  231. package/src/hooks/useIsMobile.ts +35 -0
  232. package/src/hooks/useLocalStorage.ts +122 -0
  233. package/src/hooks/useLocation.tsx +95 -0
  234. package/src/hooks/useQueryParams.tsx +31 -0
  235. package/src/hooks/useWindow.tsx +18 -0
  236. package/src/index.css +5 -0
  237. package/src/index.ts +5 -0
  238. package/src/styles/.editorconfig +0 -0
  239. package/src/styles/theme.css +152 -0
  240. package/src/styles/toast.css +67 -0
  241. package/src/styles/variables.css +229 -0
  242. package/src/ui/UIKitBadge.tsx +171 -0
  243. package/src/ui/avatar.tsx +221 -0
  244. package/src/ui/badge.tsx +74 -0
  245. package/src/ui/button.tsx +143 -0
  246. package/src/ui/card.tsx +146 -0
  247. package/src/ui/checkbox.tsx +78 -0
  248. package/src/ui/collapsible.tsx +43 -0
  249. package/src/ui/drag-selectable/DragSelectProvider.tsx +178 -0
  250. package/src/ui/drag-selectable/createSelectable.tsx +43 -0
  251. package/src/ui/drag-selectable/index.ts +2 -0
  252. package/src/ui/drawer.tsx +137 -0
  253. package/src/ui/dropdown.tsx +707 -0
  254. package/src/ui/icons/MouseCursorIcons.tsx +39 -0
  255. package/src/ui/icons/cursor.tsx +38 -0
  256. package/src/ui/icons/index.ts +2 -0
  257. package/src/ui/index.ts +45 -0
  258. package/src/ui/inputs/color-input.tsx +61 -0
  259. package/src/ui/inputs/index.tsx +5 -0
  260. package/src/ui/inputs/input-numbers.tsx +394 -0
  261. package/src/ui/inputs/input.tsx +155 -0
  262. package/src/ui/inputs/number-inputs/CmInput.tsx +26 -0
  263. package/src/ui/inputs/number-inputs/DegInput.tsx +26 -0
  264. package/src/ui/inputs/number-inputs/EulerDegInput.tsx +14 -0
  265. package/src/ui/inputs/number-inputs/EulerInput.tsx +30 -0
  266. package/src/ui/inputs/number-inputs/EulerRadInput.tsx +14 -0
  267. package/src/ui/inputs/number-inputs/InchInput.tsx +26 -0
  268. package/src/ui/inputs/number-inputs/IntInput.tsx +46 -0
  269. package/src/ui/inputs/number-inputs/KVectorInput.tsx +20 -0
  270. package/src/ui/inputs/number-inputs/QuaternionInput.tsx +27 -0
  271. package/src/ui/inputs/number-inputs/RadInput.tsx +26 -0
  272. package/src/ui/inputs/number-inputs/TimeInput.tsx +26 -0
  273. package/src/ui/inputs/number-inputs/Vec3Input.tsx +26 -0
  274. package/src/ui/inputs/number-inputs/VectorInput.tsx +38 -0
  275. package/src/ui/inputs/number-inputs/index.ts +38 -0
  276. package/src/ui/inputs/presets-input.tsx +59 -0
  277. package/src/ui/label.tsx +35 -0
  278. package/src/ui/layout.tsx +43 -0
  279. package/src/ui/layouts/dock-layout/DockLayoutView.tsx +128 -0
  280. package/src/ui/layouts/dock-layout/LayoutSlots.tsx +85 -0
  281. package/src/ui/layouts/dock-layout/index.tsx +2 -0
  282. package/src/ui/layouts/index.ts +2 -0
  283. package/src/ui/layouts/liquid-layout/LayoutSlots.tsx +82 -0
  284. package/src/ui/layouts/liquid-layout/LiquidLayoutView.tsx +76 -0
  285. package/src/ui/layouts/liquid-layout/index.ts +1 -0
  286. package/src/ui/modal.tsx +211 -0
  287. package/src/ui/navigation.tsx +86 -0
  288. package/src/ui/pagination.tsx +129 -0
  289. package/src/ui/panel.tsx +146 -0
  290. package/src/ui/popover.tsx +112 -0
  291. package/src/ui/radio-group.tsx +63 -0
  292. package/src/ui/resizable.tsx +52 -0
  293. package/src/ui/select.tsx +365 -0
  294. package/src/ui/separator.tsx +26 -0
  295. package/src/ui/sheet.tsx +257 -0
  296. package/src/ui/sidebar.tsx +695 -0
  297. package/src/ui/simple-tree-view.tsx +604 -0
  298. package/src/ui/skeleton.tsx +15 -0
  299. package/src/ui/slider.tsx +204 -0
  300. package/src/ui/switch.tsx +45 -0
  301. package/src/ui/table.tsx +99 -0
  302. package/src/ui/tabs.tsx +192 -0
  303. package/src/ui/textarea.tsx +55 -0
  304. package/src/ui/theme/ThemeProvider.tsx +319 -0
  305. package/src/ui/theme/ThemeToggles.tsx +84 -0
  306. package/src/ui/theme/index.ts +21 -0
  307. package/src/ui/theme/themeScript.tsx +179 -0
  308. package/src/ui/theme/types.ts +61 -0
  309. package/src/ui/toast.tsx +30 -0
  310. package/src/ui/toggle-buttons.tsx +290 -0
  311. package/src/ui/toggle-group.tsx +236 -0
  312. package/src/ui/toggle.tsx +94 -0
  313. package/src/ui/toolbar.tsx +54 -0
  314. package/src/ui/tooltip.tsx +171 -0
  315. package/src/ui/tree-view/TreeSearchBar.tsx +88 -0
  316. package/src/ui/tree-view/TreeView.tsx +232 -0
  317. package/src/ui/tree-view/hooks.tsx +289 -0
  318. package/src/ui/tree-view/index.ts +4 -0
  319. package/src/ui/tree-view/types.ts +23 -0
  320. package/src/ui/tree-view-legacy.tsx +644 -0
  321. package/src/ui/version-badge.tsx +0 -0
  322. package/src/ui/waterfall/CursorOverlay.tsx +96 -0
  323. package/src/ui/waterfall/NavigationControls.tsx +42 -0
  324. package/src/ui/waterfall/Tick.tsx +51 -0
  325. package/src/ui/waterfall/TimeRuleEventDot.tsx +19 -0
  326. package/src/ui/waterfall/TimelineEvent.tsx +60 -0
  327. package/src/ui/waterfall/TimelineProcessBar.tsx +207 -0
  328. package/src/ui/waterfall/Wedges.tsx +67 -0
  329. package/src/ui/waterfall/WheelZoomContext.tsx +128 -0
  330. package/src/ui/waterfall/hooks/useTimelineState.tsx +134 -0
  331. package/src/ui/waterfall/hooks/useViewport.tsx +293 -0
  332. package/src/ui/waterfall/index.tsx +326 -0
  333. package/src/ui/waterfall/types.ts +20 -0
  334. package/src/ui/waterfall/utils.ts +91 -0
  335. package/dist/chunk-W2YAQV5N.mjs +0 -57
  336. package/dist/{chunk-QLCEHV4Q.mjs → chunk-2OZK5DY5.mjs} +2 -2
  337. package/dist/{chunk-Z35DNFRZ.cjs → chunk-7IS37C3P.cjs} +2 -2
  338. package/dist/{chunk-4AOAH77D.mjs → chunk-A2PCEL5S.mjs} +2 -2
  339. package/dist/{chunk-K4VD5PPY.mjs → chunk-BIUDC66P.mjs} +1 -1
  340. package/dist/{chunk-RKJR6RZU.cjs → chunk-OYNLQTHW.cjs} +1 -1
  341. package/dist/{chunk-VE3XLQLO.cjs → chunk-QUFZWF4E.cjs} +2 -2
@@ -0,0 +1,644 @@
1
+ import { CaseSensitive, ChevronDown, Regex, Search } from "lucide-react";
2
+ import { type ReactNode, useEffect, useMemo, useState } from "react";
3
+
4
+ import { cn } from "../hooks";
5
+ import { SyncScroll } from "../SyncScroll";
6
+ import { InputRoot, InputSlot } from "./inputs/input";
7
+ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./tooltip";
8
+
9
+ /**
10
+ * Minimal tree node shape used by `TreeViewV2`.
11
+ */
12
+ export type TreeDataItem = {
13
+ id: string;
14
+ parentId: string | null;
15
+ label: string;
16
+ isCollapsible?: boolean;
17
+ actions?: ReactNode;
18
+ disable?: boolean;
19
+ [key: string]: unknown;
20
+ };
21
+
22
+ export type TreeDataItemWithMeta<T extends TreeDataItem> = T & {
23
+ indent: number;
24
+ isLast: boolean;
25
+ ancestors: T[];
26
+ };
27
+
28
+ /**
29
+ * Props for the virtualized filterable tree view.
30
+ */
31
+ export type TreeViewProps<T extends TreeDataItem> = {
32
+ data: T[];
33
+ getIcon: (item: T) => ReactNode;
34
+ onVisibleDataChange?: (data: (T & { indent: number; isLast: boolean; ancestors: T[] })[]) => void;
35
+ onItemHover?: (id: string | null) => void;
36
+ className?: string;
37
+ hoveredId?: string | null;
38
+ isSelectable?: boolean;
39
+ selectedItemId?: string | null;
40
+ onSelectChange?: (id: string | null) => void;
41
+ isSearchable?: boolean;
42
+ alwaysShowExpand?: boolean;
43
+ useSyncScroll?: boolean;
44
+ // External search state props (optional - will use internal state if not provided)
45
+ searchQuery?: string;
46
+ onSearchQueryChange?: (query: string) => void;
47
+ isCaseSensitive?: boolean;
48
+ onIsCaseSensitiveChange?: (value: boolean | ((prev: boolean) => boolean)) => void;
49
+ isRegex?: boolean;
50
+ onIsRegexChange?: (value: boolean | ((prev: boolean) => boolean)) => void;
51
+ };
52
+
53
+ /**
54
+ * Filterable and highlightable tree view with keyboardless interactions.
55
+ * Supports search (plain or regex), hover highlights, and collapsible nodes.
56
+ */
57
+ export function TreeView<T extends TreeDataItem>({
58
+ data,
59
+ getIcon,
60
+ onVisibleDataChange,
61
+ onItemHover,
62
+ className,
63
+ hoveredId,
64
+ isSelectable = false,
65
+ selectedItemId,
66
+ onSelectChange,
67
+ isSearchable = true,
68
+ alwaysShowExpand = false,
69
+ useSyncScroll = false,
70
+ // External search state props
71
+ searchQuery: externalSearchQuery,
72
+ onSearchQueryChange: externalOnSearchQueryChange,
73
+ isCaseSensitive: externalIsCaseSensitive,
74
+ onIsCaseSensitiveChange: externalOnIsCaseSensitiveChange,
75
+ isRegex: externalIsRegex,
76
+ onIsRegexChange: externalOnIsRegexChange,
77
+ }: TreeViewProps<T>) {
78
+ const [expandedItems, setExpandedItems] = useState(() => {
79
+ const initial = new Set<string>();
80
+ data.forEach((item) => {
81
+ if (item.isCollapsible) initial.add(item.id);
82
+ });
83
+ return initial;
84
+ });
85
+
86
+ // Use external search state if provided, otherwise use internal state
87
+ const [internalSearchQuery, setInternalSearchQuery] = useState("");
88
+ const [internalIsCaseSensitive, setInternalIsCaseSensitive] = useState(false);
89
+ const [internalIsRegex, setInternalIsRegex] = useState(false);
90
+ const [isRegexValid, setIsRegexValid] = useState(true);
91
+
92
+ const searchQuery = externalSearchQuery ?? internalSearchQuery;
93
+ const setSearchQuery = externalOnSearchQueryChange ?? setInternalSearchQuery;
94
+ const isCaseSensitive = externalIsCaseSensitive ?? internalIsCaseSensitive;
95
+ const isRegex = externalIsRegex ?? internalIsRegex;
96
+
97
+ // Create wrapper functions to handle both function and value setters
98
+ const setIsCaseSensitive = (value: boolean | ((prev: boolean) => boolean)) => {
99
+ if (externalOnIsCaseSensitiveChange) {
100
+ externalOnIsCaseSensitiveChange(value);
101
+ } else {
102
+ setInternalIsCaseSensitive(value);
103
+ }
104
+ };
105
+
106
+ const setIsRegex = (value: boolean | ((prev: boolean) => boolean)) => {
107
+ if (externalOnIsRegexChange) {
108
+ externalOnIsRegexChange(value);
109
+ } else {
110
+ setInternalIsRegex(value);
111
+ }
112
+ };
113
+
114
+ const toggleItem = (id: string) => {
115
+ setExpandedItems((prev) => {
116
+ const newSet = new Set(prev);
117
+ if (newSet.has(id)) {
118
+ newSet.delete(id);
119
+ } else {
120
+ newSet.add(id);
121
+ }
122
+ return newSet;
123
+ });
124
+ };
125
+
126
+ const handleItemSelect = (id: string) => {
127
+ if (isSelectable && onSelectChange) {
128
+ onSelectChange(selectedItemId === id ? null : id);
129
+ }
130
+ };
131
+
132
+ const hasDescendants = (itemId: string): boolean => {
133
+ return (childrenMap.get(itemId) || []).length > 0;
134
+ };
135
+
136
+ const childrenMap = useMemo(() => {
137
+ const map = new Map<string | null, T[]>();
138
+ data.forEach((item) => {
139
+ if (!map.has(item.parentId)) {
140
+ map.set(item.parentId, []);
141
+ }
142
+ map.get(item.parentId)!.push(item);
143
+ });
144
+ return map;
145
+ }, [data]);
146
+
147
+ const dataWithMeta = useMemo((): TreeDataItemWithMeta<T>[] => {
148
+ const dataMap = new Map(data.map((item) => [item.id, item]));
149
+
150
+ const getAncestors = (item: T) => {
151
+ const ancestors: T[] = [];
152
+ let current = item.parentId;
153
+ while (current) {
154
+ const parent = dataMap.get(current);
155
+ if (parent) {
156
+ ancestors.unshift(parent);
157
+ current = parent.parentId;
158
+ } else {
159
+ break;
160
+ }
161
+ }
162
+ return ancestors;
163
+ };
164
+
165
+ const sortedData: T[] = [];
166
+ const visited = new Set<string>();
167
+
168
+ const traverseNode = (nodeId: string | null, depth: number = 0) => {
169
+ const children = childrenMap.get(nodeId) || [];
170
+ children.forEach((child) => {
171
+ if (!visited.has(child.id)) {
172
+ visited.add(child.id);
173
+ sortedData.push(child);
174
+ traverseNode(child.id, depth + 1);
175
+ }
176
+ });
177
+ };
178
+
179
+ traverseNode(null);
180
+
181
+ return sortedData.map((item) => {
182
+ const siblings = childrenMap.get(item.parentId) || [];
183
+ const isLast = siblings.length > 0 && siblings[siblings.length - 1].id === item.id;
184
+ const ancestors = getAncestors(item);
185
+ const indent = ancestors.length;
186
+ return { ...item, indent, isLast, ancestors };
187
+ });
188
+ }, [data, childrenMap]);
189
+
190
+ const visibleData = useMemo((): TreeDataItemWithMeta<T>[] => {
191
+ const dataMap = new Map(data.map((item) => [item.id, item]));
192
+
193
+ if (!searchQuery) {
194
+ const isVisible = (item: { ancestors: T[] }) => {
195
+ return item.ancestors.every((ancestor) => expandedItems.has(ancestor.id));
196
+ };
197
+ return dataWithMeta.filter(isVisible);
198
+ }
199
+
200
+ const matchingAndAncestorIds = new Set<string>();
201
+ let regex: RegExp | null = null;
202
+
203
+ if (isRegex) {
204
+ try {
205
+ regex = new RegExp(searchQuery, isCaseSensitive ? "" : "i");
206
+ if (!isRegexValid) setIsRegexValid(true);
207
+ } catch {
208
+ if (isRegexValid) setIsRegexValid(false);
209
+ return [];
210
+ }
211
+ }
212
+
213
+ data.forEach((item) => {
214
+ let labelMatches = false;
215
+ if (regex) {
216
+ labelMatches = regex.test(item.label);
217
+ } else {
218
+ const source = isCaseSensitive ? item.label : item.label.toLowerCase();
219
+ const query = isCaseSensitive ? searchQuery : searchQuery.toLowerCase();
220
+ labelMatches = source.includes(query);
221
+ }
222
+
223
+ if (labelMatches) {
224
+ matchingAndAncestorIds.add(item.id);
225
+ let current = item.parentId;
226
+ while (current) {
227
+ const parent = dataMap.get(current);
228
+ if (parent) {
229
+ matchingAndAncestorIds.add(parent.id);
230
+ current = parent.parentId;
231
+ } else {
232
+ break;
233
+ }
234
+ }
235
+ }
236
+ });
237
+
238
+ return dataWithMeta.filter((item) => matchingAndAncestorIds.has(item.id));
239
+ }, [searchQuery, dataWithMeta, expandedItems, isCaseSensitive, isRegex, isRegexValid, data]);
240
+
241
+ const searchResultsCount = useMemo(() => {
242
+ if (!searchQuery || !isRegexValid) return 0;
243
+
244
+ let count = 0;
245
+ let regex: RegExp | null = null;
246
+
247
+ if (isRegex) {
248
+ try {
249
+ regex = new RegExp(searchQuery, isCaseSensitive ? "" : "i");
250
+ } catch {
251
+ return 0;
252
+ }
253
+ }
254
+
255
+ data.forEach((item) => {
256
+ let labelMatches = false;
257
+ if (regex) {
258
+ labelMatches = regex.test(item.label);
259
+ } else {
260
+ const source = isCaseSensitive ? item.label : item.label.toLowerCase();
261
+ const query = isCaseSensitive ? searchQuery : searchQuery.toLowerCase();
262
+ labelMatches = source.includes(query);
263
+ }
264
+
265
+ if (labelMatches) {
266
+ count++;
267
+ }
268
+ });
269
+
270
+ return count;
271
+ }, [searchQuery, data, isCaseSensitive, isRegex, isRegexValid]);
272
+
273
+ useEffect(() => {
274
+ onVisibleDataChange?.(visibleData);
275
+ }, [visibleData, onVisibleDataChange]);
276
+
277
+ const renderLabel = (label: string) => {
278
+ if (!searchQuery || !isRegexValid) {
279
+ return label;
280
+ }
281
+
282
+ let regex;
283
+ try {
284
+ regex = new RegExp(`(${searchQuery})`, isCaseSensitive ? "g" : "gi");
285
+ } catch {
286
+ return label;
287
+ }
288
+
289
+ const parts = label.split(regex);
290
+
291
+ return (
292
+ <>
293
+ {parts.map((part, i) =>
294
+ i % 2 === 1 ? (
295
+ <span key={i} className="rounded-uk-xs bg-accent-warning">
296
+ {part}
297
+ </span>
298
+ ) : (
299
+ part
300
+ ),
301
+ )}
302
+ </>
303
+ );
304
+ };
305
+
306
+ return (
307
+ <div className={cn("flex flex-col", className)}>
308
+ {isSearchable && (
309
+ <TreeSearchBar
310
+ searchQuery={searchQuery}
311
+ setSearchQuery={setSearchQuery}
312
+ isCaseSensitive={isCaseSensitive}
313
+ setIsCaseSensitive={setIsCaseSensitive}
314
+ isRegex={isRegex}
315
+ setIsRegex={setIsRegex}
316
+ isRegexValid={isRegexValid}
317
+ searchResultsCount={searchResultsCount}
318
+ />
319
+ )}
320
+ <TreeEntries
321
+ visibleData={visibleData}
322
+ hoveredId={hoveredId}
323
+ onItemHover={onItemHover}
324
+ isSelectable={isSelectable}
325
+ selectedItemId={selectedItemId}
326
+ handleItemSelect={handleItemSelect}
327
+ expandedItems={expandedItems}
328
+ toggleItem={toggleItem}
329
+ alwaysShowExpand={alwaysShowExpand}
330
+ hasDescendants={hasDescendants}
331
+ getIcon={getIcon}
332
+ renderLabel={renderLabel}
333
+ dataWithMeta={dataWithMeta}
334
+ useSyncScroll={useSyncScroll}
335
+ />
336
+ </div>
337
+ );
338
+ }
339
+
340
+ /**
341
+ * Search bar component for the TreeView
342
+ */
343
+ export type TreeSearchBarProps = {
344
+ searchQuery: string;
345
+ setSearchQuery: (query: string) => void;
346
+ isCaseSensitive: boolean;
347
+ setIsCaseSensitive: (value: boolean | ((prev: boolean) => boolean)) => void;
348
+ isRegex: boolean;
349
+ setIsRegex: (value: boolean | ((prev: boolean) => boolean)) => void;
350
+ isRegexValid: boolean;
351
+ searchResultsCount: number;
352
+ };
353
+
354
+ export function TreeSearchBar({
355
+ searchQuery,
356
+ setSearchQuery,
357
+ isCaseSensitive,
358
+ setIsCaseSensitive,
359
+ isRegex,
360
+ setIsRegex,
361
+ isRegexValid,
362
+ searchResultsCount,
363
+ }: TreeSearchBarProps) {
364
+ return (
365
+ <div className="shrink-0">
366
+ <div className="flex items-center gap-1 py-1">
367
+ <InputRoot
368
+ type="text"
369
+ placeholder="Search..."
370
+ size="md"
371
+ className="flex-1"
372
+ inputClassName={cn(!isRegexValid && "text-red-500")}
373
+ value={searchQuery}
374
+ onChange={(e: React.ChangeEvent<HTMLInputElement>) => setSearchQuery(e.target.value)}
375
+ >
376
+ <InputSlot side="left">
377
+ <Search className="text-text-secondary size-4 stroke-1" />
378
+ </InputSlot>
379
+ <InputSlot side="right">
380
+ <TooltipProvider delayDuration={200}>
381
+ <Tooltip>
382
+ <TooltipTrigger asChild>
383
+ <button
384
+ onClick={() => setIsCaseSensitive((prev) => !prev)}
385
+ className={cn(
386
+ "rounded-uk-sm mr-1 p-1",
387
+ isCaseSensitive ? "bg-shadow-secondary" : "",
388
+ )}
389
+ >
390
+ <CaseSensitive className="size-4" />
391
+ </button>
392
+ </TooltipTrigger>
393
+ <TooltipContent>
394
+ <p>Case Sensitive</p>
395
+ </TooltipContent>
396
+ </Tooltip>
397
+ <Tooltip>
398
+ <TooltipTrigger asChild>
399
+ <button
400
+ onClick={() => setIsRegex((prev) => !prev)}
401
+ className={cn("rounded-uk-sm p-1", isRegex && "bg-shadow-secondary")}
402
+ >
403
+ <Regex className="size-4" />
404
+ </button>
405
+ </TooltipTrigger>
406
+ <TooltipContent>
407
+ <p>Use Regular Expression</p>
408
+ </TooltipContent>
409
+ </Tooltip>
410
+ </TooltipProvider>
411
+ </InputSlot>
412
+ </InputRoot>
413
+ </div>
414
+ {searchQuery && isRegexValid && (
415
+ <div className="flex justify-end px-2 pb-1">
416
+ <span className="text-uk-xs text-text-secondary">
417
+ {searchResultsCount} result{searchResultsCount !== 1 ? "s" : ""}
418
+ </span>
419
+ </div>
420
+ )}
421
+ </div>
422
+ );
423
+ }
424
+
425
+ /**
426
+ * Individual tree entry item component
427
+ */
428
+ export type TreeEntryItemProps<T extends TreeDataItem> = {
429
+ item: TreeDataItemWithMeta<T>;
430
+ hoveredId?: string | null;
431
+ onItemHover?: (id: string | null) => void;
432
+ isSelectable?: boolean;
433
+ selectedItemId?: string | null;
434
+ handleItemSelect: (id: string) => void;
435
+ expandedItems: Set<string>;
436
+ toggleItem: (id: string) => void;
437
+ alwaysShowExpand?: boolean;
438
+ hasDescendants: (id: string) => boolean;
439
+ getIcon: (item: T) => ReactNode;
440
+ renderLabel: (label: string) => ReactNode;
441
+ dataWithMeta: TreeDataItemWithMeta<T>[];
442
+ };
443
+
444
+ export function TreeEntryItem<T extends TreeDataItem>({
445
+ item,
446
+ hoveredId,
447
+ onItemHover,
448
+ isSelectable,
449
+ selectedItemId,
450
+ handleItemSelect,
451
+ expandedItems,
452
+ toggleItem,
453
+ alwaysShowExpand,
454
+ hasDescendants,
455
+ getIcon,
456
+ renderLabel,
457
+ dataWithMeta,
458
+ }: TreeEntryItemProps<T>) {
459
+ return (
460
+ <div
461
+ key={item.id}
462
+ className={cn(
463
+ "group relative flex h-[32px] items-center",
464
+ isSelectable && "rounded-uk-md",
465
+ !item.disable && "cursor-pointer",
466
+ hoveredId === item.id && !item.disable && "bg-bg-secondary",
467
+ isSelectable && selectedItemId === item.id && "bg-brand-primary text-text-withbg",
468
+ )}
469
+ onMouseEnter={() => onItemHover?.(item.id)}
470
+ onMouseLeave={() => onItemHover?.(null)}
471
+ onClick={() => !item.disable && handleItemSelect(item.id)}
472
+ >
473
+ {/* Guide Lines */}
474
+ <div className="absolute top-0 left-[-0.28rem] z-0 flex h-full items-center">
475
+ {item.ancestors.map((ancestor, index) => {
476
+ const parentIsLast = dataWithMeta.find((d) => d.id === ancestor.id)?.isLast;
477
+ return (
478
+ <div
479
+ key={index}
480
+ className={cn(
481
+ "h-full w-[1.25rem]",
482
+ parentIsLast ? "" : "border-l",
483
+ "border-line-primary",
484
+ )}
485
+ />
486
+ );
487
+ })}
488
+ {item.indent > 0 && (
489
+ <div className="relative h-full w-[1.24rem]">
490
+ <div
491
+ className={cn(
492
+ "absolute top-0 left-0 h-1/2 w-1/2 border-b border-l",
493
+ item.isLast ? "rounded-bl-md" : "",
494
+ "border-line-primary",
495
+ )}
496
+ />
497
+ {!item.isLast && (
498
+ <div className="border-line-primary absolute top-1/2 left-0 h-1/2 w-1/2 border-l" />
499
+ )}
500
+ </div>
501
+ )}
502
+ </div>
503
+
504
+ <div
505
+ className="text-uk-md z-10 flex w-full items-center justify-between gap-2 px-2 whitespace-nowrap"
506
+ style={{ paddingLeft: `${item.indent * 1.25 + 0.5}rem` }}
507
+ >
508
+ <div className="flex min-w-0 flex-1 items-center gap-2">
509
+ {alwaysShowExpand && hasDescendants(item.id) && !expandedItems.has(item.id) ? (
510
+ <>
511
+ <button
512
+ onClick={(e) => {
513
+ e.stopPropagation();
514
+ toggleItem(item.id);
515
+ }}
516
+ className="flex size-4 cursor-pointer items-center justify-center"
517
+ >
518
+ <ChevronDown
519
+ className={cn(
520
+ "size-4 -rotate-90 transition-transform",
521
+ item.disable && "text-icon-tertiary",
522
+ )}
523
+ />
524
+ </button>
525
+ <div
526
+ className={cn(
527
+ "flex size-4 items-center justify-center",
528
+ item.disable && "text-icon-tertiary",
529
+ )}
530
+ >
531
+ {getIcon(item)}
532
+ </div>
533
+ </>
534
+ ) : (
535
+ <div className="relative flex size-4 items-center justify-center">
536
+ {item.isCollapsible && (
537
+ <button
538
+ onClick={(e) => {
539
+ e.stopPropagation();
540
+ toggleItem(item.id);
541
+ }}
542
+ className="absolute z-20 flex cursor-pointer items-center justify-center opacity-0 transition-opacity group-hover:opacity-100"
543
+ >
544
+ <ChevronDown
545
+ className={cn(
546
+ "size-4 transition-transform",
547
+ !expandedItems.has(item.id) && "-rotate-90",
548
+ item.disable && "text-icon-tertiary",
549
+ )}
550
+ />
551
+ </button>
552
+ )}
553
+ <div
554
+ className={cn(
555
+ "cursor-pointer transition-opacity",
556
+ item.isCollapsible && "group-hover:opacity-0",
557
+ item.disable && "text-icon-tertiary",
558
+ )}
559
+ >
560
+ {getIcon(item)}
561
+ </div>
562
+ </div>
563
+ )}
564
+ <span className={cn("truncate", item.disable && "text-text-tertiary")}>
565
+ {renderLabel(item.label)}
566
+ </span>
567
+ </div>
568
+ {item.actions && (
569
+ <div className="flex items-center gap-1" onClick={(e) => e.stopPropagation()}>
570
+ {item.actions}
571
+ </div>
572
+ )}
573
+ </div>
574
+ </div>
575
+ );
576
+ }
577
+
578
+ /**
579
+ * Tree entries wrapper component
580
+ */
581
+ export type TreeEntriesProps<T extends TreeDataItem> = {
582
+ visibleData: TreeDataItemWithMeta<T>[];
583
+ hoveredId?: string | null;
584
+ onItemHover?: (id: string | null) => void;
585
+ isSelectable?: boolean;
586
+ selectedItemId?: string | null;
587
+ handleItemSelect: (id: string) => void;
588
+ expandedItems: Set<string>;
589
+ toggleItem: (id: string) => void;
590
+ alwaysShowExpand?: boolean;
591
+ hasDescendants: (id: string) => boolean;
592
+ getIcon: (item: T) => ReactNode;
593
+ renderLabel: (label: string) => ReactNode;
594
+ dataWithMeta: TreeDataItemWithMeta<T>[];
595
+ useSyncScroll?: boolean;
596
+ className?: string;
597
+ };
598
+
599
+ export function TreeEntries<T extends TreeDataItem>({
600
+ visibleData,
601
+ hoveredId,
602
+ onItemHover,
603
+ isSelectable,
604
+ selectedItemId,
605
+ handleItemSelect,
606
+ expandedItems,
607
+ toggleItem,
608
+ alwaysShowExpand,
609
+ hasDescendants,
610
+ getIcon,
611
+ renderLabel,
612
+ dataWithMeta,
613
+ useSyncScroll = false,
614
+ className,
615
+ }: TreeEntriesProps<T>) {
616
+ const content = visibleData.map((item) => (
617
+ <TreeEntryItem
618
+ key={item.id}
619
+ item={item}
620
+ hoveredId={hoveredId}
621
+ onItemHover={onItemHover}
622
+ isSelectable={isSelectable}
623
+ selectedItemId={selectedItemId}
624
+ handleItemSelect={handleItemSelect}
625
+ expandedItems={expandedItems}
626
+ toggleItem={toggleItem}
627
+ alwaysShowExpand={alwaysShowExpand}
628
+ hasDescendants={hasDescendants}
629
+ getIcon={getIcon}
630
+ renderLabel={renderLabel}
631
+ dataWithMeta={dataWithMeta}
632
+ />
633
+ ));
634
+
635
+ if (useSyncScroll) {
636
+ return (
637
+ <SyncScroll className={cn("scrollbar-track-transparent flex-1", className)}>
638
+ {content}
639
+ </SyncScroll>
640
+ );
641
+ }
642
+
643
+ return <div className={cn("flex-1 overflow-y-auto", className)}>{content}</div>;
644
+ }
File without changes