@constructive-io/ui 0.4.1 → 0.6.1

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 (415) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +17 -22
  3. package/dist/button-D4vqTxhp.d.cts +20 -0
  4. package/dist/button-D4vqTxhp.d.ts +20 -0
  5. package/dist/components/alert-dialog.cjs +129 -0
  6. package/dist/components/alert-dialog.cjs.map +1 -0
  7. package/dist/components/alert-dialog.d.cts +33 -0
  8. package/dist/components/alert-dialog.d.ts +23 -21
  9. package/dist/components/alert-dialog.js +98 -296
  10. package/dist/components/alert-dialog.js.map +1 -1
  11. package/dist/components/alert.cjs +62 -0
  12. package/dist/components/alert.cjs.map +1 -0
  13. package/dist/components/alert.d.cts +19 -0
  14. package/dist/components/alert.d.ts +18 -13
  15. package/dist/components/alert.js +49 -31
  16. package/dist/components/alert.js.map +1 -1
  17. package/dist/components/app-bar.cjs +81 -0
  18. package/dist/components/app-bar.cjs.map +1 -0
  19. package/dist/components/app-bar.d.cts +27 -0
  20. package/dist/components/app-bar.d.ts +27 -0
  21. package/dist/components/app-bar.js +77 -0
  22. package/dist/components/app-bar.js.map +1 -0
  23. package/dist/components/app-shell.cjs +267 -0
  24. package/dist/components/app-shell.cjs.map +1 -0
  25. package/dist/components/app-shell.d.cts +98 -0
  26. package/dist/components/app-shell.d.ts +98 -0
  27. package/dist/components/app-shell.js +264 -0
  28. package/dist/components/app-shell.js.map +1 -0
  29. package/dist/components/autocomplete.cjs +167 -0
  30. package/dist/components/autocomplete.cjs.map +1 -0
  31. package/dist/components/autocomplete.d.cts +28 -0
  32. package/dist/components/autocomplete.d.ts +24 -24
  33. package/dist/components/autocomplete.js +146 -397
  34. package/dist/components/autocomplete.js.map +1 -1
  35. package/dist/components/avatar.cjs +39 -0
  36. package/dist/components/avatar.cjs.map +1 -0
  37. package/dist/components/avatar.d.cts +13 -0
  38. package/dist/components/avatar.d.ts +11 -11
  39. package/dist/components/avatar.js +24 -27
  40. package/dist/components/avatar.js.map +1 -1
  41. package/dist/components/badge.cjs +48 -0
  42. package/dist/components/badge.cjs.map +1 -0
  43. package/dist/components/badge.d.cts +15 -0
  44. package/dist/components/badge.d.ts +13 -13
  45. package/dist/components/badge.js +39 -38
  46. package/dist/components/badge.js.map +1 -1
  47. package/dist/components/breadcrumb.cjs +89 -0
  48. package/dist/components/breadcrumb.cjs.map +1 -0
  49. package/dist/components/breadcrumb.d.cts +15 -0
  50. package/dist/components/breadcrumb.d.ts +14 -13
  51. package/dist/components/breadcrumb.js +63 -137
  52. package/dist/components/breadcrumb.js.map +1 -1
  53. package/dist/components/button.cjs +75 -0
  54. package/dist/components/button.cjs.map +1 -0
  55. package/dist/components/button.d.cts +2 -0
  56. package/dist/components/button.d.ts +2 -17
  57. package/dist/components/button.js +66 -57
  58. package/dist/components/button.js.map +1 -1
  59. package/dist/components/calendar-rac.cjs +72 -0
  60. package/dist/components/calendar-rac.cjs.map +1 -0
  61. package/dist/components/calendar-rac.d.cts +13 -0
  62. package/dist/components/calendar-rac.d.ts +8 -8
  63. package/dist/components/calendar-rac.js +49 -61
  64. package/dist/components/calendar-rac.js.map +1 -1
  65. package/dist/components/card.cjs +86 -0
  66. package/dist/components/card.cjs.map +1 -0
  67. package/dist/components/card.d.cts +17 -0
  68. package/dist/components/card.d.ts +15 -17
  69. package/dist/components/card.js +58 -57
  70. package/dist/components/card.js.map +1 -1
  71. package/dist/components/checkbox-group.cjs +19 -0
  72. package/dist/components/checkbox-group.cjs.map +1 -0
  73. package/dist/components/checkbox-group.d.cts +7 -0
  74. package/dist/components/checkbox-group.d.ts +5 -5
  75. package/dist/components/checkbox-group.js +12 -10
  76. package/dist/components/checkbox-group.js.map +1 -1
  77. package/dist/components/checkbox.cjs +67 -0
  78. package/dist/components/checkbox.cjs.map +1 -0
  79. package/dist/components/checkbox.d.cts +8 -0
  80. package/dist/components/checkbox.d.ts +6 -6
  81. package/dist/components/checkbox.js +58 -61
  82. package/dist/components/checkbox.js.map +1 -1
  83. package/dist/components/collapsible.cjs +90 -0
  84. package/dist/components/collapsible.cjs.map +1 -0
  85. package/dist/components/collapsible.d.cts +45 -0
  86. package/dist/components/collapsible.d.ts +19 -28
  87. package/dist/components/collapsible.js +74 -112
  88. package/dist/components/collapsible.js.map +1 -1
  89. package/dist/components/combobox.cjs +257 -0
  90. package/dist/components/combobox.cjs.map +1 -0
  91. package/dist/components/combobox.d.cts +44 -0
  92. package/dist/components/combobox.d.ts +36 -36
  93. package/dist/components/combobox.js +229 -515
  94. package/dist/components/combobox.js.map +1 -1
  95. package/dist/components/command.cjs +139 -0
  96. package/dist/components/command.cjs.map +1 -0
  97. package/dist/components/command.d.cts +24 -0
  98. package/dist/components/command.d.ts +22 -22
  99. package/dist/components/command.js +109 -240
  100. package/dist/components/command.js.map +1 -1
  101. package/dist/components/dialog.cjs +139 -0
  102. package/dist/components/dialog.cjs.map +1 -0
  103. package/dist/components/dialog.d.cts +31 -0
  104. package/dist/components/dialog.d.ts +27 -31
  105. package/dist/components/dialog.js +112 -429
  106. package/dist/components/dialog.js.map +1 -1
  107. package/dist/components/dock.cjs +90 -0
  108. package/dist/components/dock.cjs.map +1 -0
  109. package/dist/components/dock.d.cts +30 -0
  110. package/dist/components/dock.d.ts +25 -26
  111. package/dist/components/dock.js +78 -104
  112. package/dist/components/dock.js.map +1 -1
  113. package/dist/components/drawer.cjs +115 -0
  114. package/dist/components/drawer.cjs.map +1 -0
  115. package/dist/components/drawer.d.cts +16 -0
  116. package/dist/components/drawer.d.ts +15 -15
  117. package/dist/components/drawer.js +77 -121
  118. package/dist/components/drawer.js.map +1 -1
  119. package/dist/components/dropdown-menu.cjs +217 -0
  120. package/dist/components/dropdown-menu.cjs.map +1 -0
  121. package/dist/components/dropdown-menu.d.cts +53 -0
  122. package/dist/components/dropdown-menu.d.ts +49 -46
  123. package/dist/components/dropdown-menu.js +177 -357
  124. package/dist/components/dropdown-menu.js.map +1 -1
  125. package/dist/components/empty.cjs +72 -0
  126. package/dist/components/empty.cjs.map +1 -0
  127. package/dist/components/empty.d.cts +15 -0
  128. package/dist/components/empty.d.ts +15 -0
  129. package/dist/components/empty.js +64 -0
  130. package/dist/components/empty.js.map +1 -0
  131. package/dist/components/field.cjs +186 -0
  132. package/dist/components/field.cjs.map +1 -0
  133. package/dist/components/field.d.cts +46 -0
  134. package/dist/components/field.d.ts +44 -49
  135. package/dist/components/field.js +166 -108
  136. package/dist/components/field.js.map +1 -1
  137. package/dist/components/flickering-grid.cjs +153 -0
  138. package/dist/components/flickering-grid.cjs.map +1 -0
  139. package/dist/components/flickering-grid.d.cts +16 -0
  140. package/dist/components/flickering-grid.d.ts +14 -13
  141. package/dist/components/flickering-grid.js +144 -141
  142. package/dist/components/flickering-grid.js.map +1 -1
  143. package/dist/components/flow-zoom-panel.cjs +62 -0
  144. package/dist/components/flow-zoom-panel.cjs.map +1 -0
  145. package/dist/components/flow-zoom-panel.d.cts +12 -0
  146. package/dist/components/flow-zoom-panel.d.ts +12 -0
  147. package/dist/components/flow-zoom-panel.js +61 -0
  148. package/dist/components/flow-zoom-panel.js.map +1 -0
  149. package/dist/components/form-control.cjs +65 -0
  150. package/dist/components/form-control.cjs.map +1 -0
  151. package/dist/components/form-control.d.cts +15 -0
  152. package/dist/components/form-control.d.ts +11 -11
  153. package/dist/components/form-control.js +56 -167
  154. package/dist/components/form-control.js.map +1 -1
  155. package/dist/components/form.cjs +102 -0
  156. package/dist/components/form.cjs.map +1 -0
  157. package/dist/components/form.d.cts +2 -0
  158. package/dist/components/form.d.ts +2 -37
  159. package/dist/components/form.js +76 -163
  160. package/dist/components/form.js.map +1 -1
  161. package/dist/components/input-group.cjs +70 -0
  162. package/dist/components/input-group.cjs.map +1 -0
  163. package/dist/components/input-group.d.cts +16 -0
  164. package/dist/components/input-group.d.ts +14 -16
  165. package/dist/components/input-group.js +51 -163
  166. package/dist/components/input-group.js.map +1 -1
  167. package/dist/components/input.cjs +37 -0
  168. package/dist/components/input.cjs.map +1 -0
  169. package/dist/components/input.d.cts +2 -0
  170. package/dist/components/input.d.ts +2 -11
  171. package/dist/components/input.js +30 -54
  172. package/dist/components/input.js.map +1 -1
  173. package/dist/components/json-input.cjs +147 -0
  174. package/dist/components/json-input.cjs.map +1 -0
  175. package/dist/components/json-input.d.cts +26 -0
  176. package/dist/components/json-input.d.ts +20 -19
  177. package/dist/components/json-input.js +132 -340
  178. package/dist/components/json-input.js.map +1 -1
  179. package/dist/components/label.cjs +27 -0
  180. package/dist/components/label.cjs.map +1 -0
  181. package/dist/components/label.d.cts +11 -0
  182. package/dist/components/label.d.ts +6 -6
  183. package/dist/components/label.js +17 -20
  184. package/dist/components/label.js.map +1 -1
  185. package/dist/components/motion-grid.cjs +68 -0
  186. package/dist/components/motion-grid.cjs.map +1 -0
  187. package/dist/components/motion-grid.d.cts +20 -0
  188. package/dist/components/motion-grid.d.ts +15 -15
  189. package/dist/components/motion-grid.js +59 -75
  190. package/dist/components/motion-grid.js.map +1 -1
  191. package/dist/components/multi-select.cjs +573 -0
  192. package/dist/components/multi-select.cjs.map +1 -0
  193. package/dist/components/multi-select.d.cts +198 -0
  194. package/dist/components/multi-select.d.ts +173 -173
  195. package/dist/components/multi-select.js +562 -874
  196. package/dist/components/multi-select.js.map +1 -1
  197. package/dist/components/page-header.cjs +30 -0
  198. package/dist/components/page-header.cjs.map +1 -0
  199. package/dist/components/page-header.d.cts +17 -0
  200. package/dist/components/page-header.d.ts +11 -11
  201. package/dist/components/page-header.js +23 -11
  202. package/dist/components/page-header.js.map +1 -1
  203. package/dist/components/pagination.cjs +95 -0
  204. package/dist/components/pagination.cjs.map +1 -0
  205. package/dist/components/pagination.d.cts +17 -0
  206. package/dist/components/pagination.d.ts +15 -17
  207. package/dist/components/pagination.js +70 -128
  208. package/dist/components/pagination.js.map +1 -1
  209. package/dist/components/popover.cjs +97 -0
  210. package/dist/components/popover.cjs.map +1 -0
  211. package/dist/components/popover.d.cts +40 -0
  212. package/dist/components/popover.d.ts +33 -28
  213. package/dist/components/popover.js +78 -178
  214. package/dist/components/popover.js.map +1 -1
  215. package/dist/components/portal.cjs +156 -0
  216. package/dist/components/portal.cjs.map +1 -0
  217. package/dist/components/portal.d.cts +118 -0
  218. package/dist/components/portal.d.ts +33 -23
  219. package/dist/components/portal.js +128 -57
  220. package/dist/components/portal.js.map +1 -1
  221. package/dist/components/progress.cjs +30 -0
  222. package/dist/components/progress.cjs.map +1 -0
  223. package/dist/components/progress.d.cts +10 -0
  224. package/dist/components/progress.d.ts +8 -8
  225. package/dist/components/progress.js +21 -24
  226. package/dist/components/progress.js.map +1 -1
  227. package/dist/components/progressive-blur-scroll-container.cjs +76 -0
  228. package/dist/components/progressive-blur-scroll-container.cjs.map +1 -0
  229. package/dist/components/progressive-blur-scroll-container.d.cts +25 -0
  230. package/dist/components/progressive-blur-scroll-container.d.ts +19 -19
  231. package/dist/components/progressive-blur-scroll-container.js +70 -137
  232. package/dist/components/progressive-blur-scroll-container.js.map +1 -1
  233. package/dist/components/progressive-blur.cjs +46 -0
  234. package/dist/components/progressive-blur.cjs.map +1 -0
  235. package/dist/components/progressive-blur.d.cts +17 -0
  236. package/dist/components/progressive-blur.d.ts +15 -14
  237. package/dist/components/progressive-blur.js +38 -63
  238. package/dist/components/progressive-blur.js.map +1 -1
  239. package/dist/components/radio-group.cjs +38 -0
  240. package/dist/components/radio-group.cjs.map +1 -0
  241. package/dist/components/radio-group.d.cts +10 -0
  242. package/dist/components/radio-group.d.ts +8 -8
  243. package/dist/components/radio-group.js +28 -30
  244. package/dist/components/radio-group.js.map +1 -1
  245. package/dist/components/record-picker.cjs +8 -0
  246. package/dist/components/record-picker.d.cts +16 -0
  247. package/dist/components/record-picker.d.ts +13 -13
  248. package/dist/components/record-picker.js +5 -364
  249. package/dist/components/resizable.cjs +50 -0
  250. package/dist/components/resizable.cjs.map +1 -0
  251. package/dist/components/resizable.d.cts +11 -0
  252. package/dist/components/resizable.d.ts +10 -10
  253. package/dist/components/resizable.js +29 -37
  254. package/dist/components/resizable.js.map +1 -1
  255. package/dist/components/responsive-diagram.cjs +56 -0
  256. package/dist/components/responsive-diagram.cjs.map +1 -0
  257. package/dist/components/responsive-diagram.d.cts +10 -0
  258. package/dist/components/responsive-diagram.d.ts +7 -7
  259. package/dist/components/responsive-diagram.js +50 -60
  260. package/dist/components/responsive-diagram.js.map +1 -1
  261. package/dist/components/scroll-area.cjs +46 -0
  262. package/dist/components/scroll-area.cjs.map +1 -0
  263. package/dist/components/scroll-area.d.cts +12 -0
  264. package/dist/components/scroll-area.d.ts +11 -11
  265. package/dist/components/scroll-area.js +35 -62
  266. package/dist/components/scroll-area.js.map +1 -1
  267. package/dist/components/select.cjs +204 -0
  268. package/dist/components/select.cjs.map +1 -0
  269. package/dist/components/select.d.cts +47 -0
  270. package/dist/components/select.d.ts +38 -38
  271. package/dist/components/select.js +172 -269
  272. package/dist/components/select.js.map +1 -1
  273. package/dist/components/separator.cjs +23 -0
  274. package/dist/components/separator.cjs.map +1 -0
  275. package/dist/components/separator.d.cts +2 -0
  276. package/dist/components/separator.d.ts +2 -11
  277. package/dist/components/separator.js +14 -18
  278. package/dist/components/separator.js.map +1 -1
  279. package/dist/components/sheet.cjs +19 -0
  280. package/dist/components/sheet.d.cts +107 -0
  281. package/dist/components/sheet.d.ts +85 -90
  282. package/dist/components/sheet.js +3 -598
  283. package/dist/components/sidebar.cjs +29 -0
  284. package/dist/components/sidebar.d.cts +67 -0
  285. package/dist/components/sidebar.d.ts +63 -73
  286. package/dist/components/sidebar.js +3 -1215
  287. package/dist/components/skeleton.cjs +24 -0
  288. package/dist/components/skeleton.cjs.map +1 -0
  289. package/dist/components/skeleton.d.cts +11 -0
  290. package/dist/components/skeleton.d.ts +10 -6
  291. package/dist/components/skeleton.js +15 -10
  292. package/dist/components/skeleton.js.map +1 -1
  293. package/dist/components/sonner.cjs +23 -0
  294. package/dist/components/sonner.cjs.map +1 -0
  295. package/dist/components/sonner.d.cts +10 -0
  296. package/dist/components/sonner.d.ts +7 -7
  297. package/dist/components/sonner.js +17 -18
  298. package/dist/components/sonner.js.map +1 -1
  299. package/dist/components/stack/index.cjs +44 -0
  300. package/dist/components/stack/index.d.cts +2 -0
  301. package/dist/components/stack/index.d.ts +2 -674
  302. package/dist/components/stack/index.js +3 -1444
  303. package/dist/components/stepper.cjs +160 -0
  304. package/dist/components/stepper.cjs.map +1 -0
  305. package/dist/components/stepper.d.cts +32 -0
  306. package/dist/components/stepper.d.ts +27 -25
  307. package/dist/components/stepper.js +133 -261
  308. package/dist/components/stepper.js.map +1 -1
  309. package/dist/components/switch.cjs +35 -0
  310. package/dist/components/switch.cjs.map +1 -0
  311. package/dist/components/switch.d.cts +8 -0
  312. package/dist/components/switch.d.ts +7 -7
  313. package/dist/components/switch.js +26 -34
  314. package/dist/components/switch.js.map +1 -1
  315. package/dist/components/table.cjs +85 -0
  316. package/dist/components/table.cjs.map +1 -0
  317. package/dist/components/table.d.cts +23 -0
  318. package/dist/components/table.d.ts +23 -15
  319. package/dist/components/table.js +56 -46
  320. package/dist/components/table.js.map +1 -1
  321. package/dist/components/tabs.cjs +49 -0
  322. package/dist/components/tabs.cjs.map +1 -0
  323. package/dist/components/tabs.d.cts +10 -0
  324. package/dist/components/tabs.d.ts +9 -9
  325. package/dist/components/tabs.js +31 -36
  326. package/dist/components/tabs.js.map +1 -1
  327. package/dist/components/tags.cjs +132 -0
  328. package/dist/components/tags.cjs.map +1 -0
  329. package/dist/components/tags.d.cts +36 -0
  330. package/dist/components/tags.d.ts +24 -28
  331. package/dist/components/tags.js +114 -438
  332. package/dist/components/tags.js.map +1 -1
  333. package/dist/components/textarea.cjs +34 -0
  334. package/dist/components/textarea.cjs.map +1 -0
  335. package/dist/components/textarea.d.cts +10 -0
  336. package/dist/components/textarea.d.ts +8 -8
  337. package/dist/components/textarea.js +27 -48
  338. package/dist/components/textarea.js.map +1 -1
  339. package/dist/components/toast/index.cjs +9 -0
  340. package/dist/components/toast/index.d.cts +2 -0
  341. package/dist/components/toast/index.d.ts +2 -52
  342. package/dist/components/toast/index.js +3 -623
  343. package/dist/components/tooltip.cjs +67 -0
  344. package/dist/components/tooltip.cjs.map +1 -0
  345. package/dist/components/tooltip.d.cts +2 -0
  346. package/dist/components/tooltip.d.ts +2 -29
  347. package/dist/components/tooltip.js +53 -166
  348. package/dist/components/tooltip.js.map +1 -1
  349. package/dist/components/unlink-button.cjs +24 -0
  350. package/dist/components/unlink-button.cjs.map +1 -0
  351. package/dist/components/unlink-button.d.cts +14 -0
  352. package/dist/components/unlink-button.d.ts +11 -11
  353. package/dist/components/unlink-button.js +18 -86
  354. package/dist/components/unlink-button.js.map +1 -1
  355. package/dist/form-DgRTv7O7.d.ts +54 -0
  356. package/dist/form-DoZEWSzb.d.cts +54 -0
  357. package/dist/index-CjA4CENl.d.cts +684 -0
  358. package/dist/index-CjA4CENl.d.ts +684 -0
  359. package/dist/index-UnM04j0t.d.cts +58 -0
  360. package/dist/index-UnM04j0t.d.ts +58 -0
  361. package/dist/index.cjs +408 -9346
  362. package/dist/index.d.cts +224 -2548
  363. package/dist/index.d.ts +224 -2548
  364. package/dist/index.js +65 -9022
  365. package/dist/input-CBrCuMH8.d.cts +11 -0
  366. package/dist/input-CBrCuMH8.d.ts +11 -0
  367. package/dist/motion-config-COCFHq1L.cjs +271 -0
  368. package/dist/motion-config-COCFHq1L.cjs.map +1 -0
  369. package/dist/motion-config-COsZ6azM.js +241 -0
  370. package/dist/motion-config-COsZ6azM.js.map +1 -0
  371. package/dist/record-picker-BbxngCeV.js +162 -0
  372. package/dist/record-picker-BbxngCeV.js.map +1 -0
  373. package/dist/record-picker-Bz4FApxD.cjs +167 -0
  374. package/dist/record-picker-Bz4FApxD.cjs.map +1 -0
  375. package/dist/rolldown-runtime-D_qnwXdH.cjs +35 -0
  376. package/dist/separator-BQEsr0Rc.d.cts +11 -0
  377. package/dist/separator-BQEsr0Rc.d.ts +11 -0
  378. package/dist/sheet-BLHnhLRH.js +425 -0
  379. package/dist/sheet-BLHnhLRH.js.map +1 -0
  380. package/dist/sheet-BdA0rfIz.cjs +515 -0
  381. package/dist/sheet-BdA0rfIz.cjs.map +1 -0
  382. package/dist/sidebar-CPy_fibW.cjs +608 -0
  383. package/dist/sidebar-CPy_fibW.cjs.map +1 -0
  384. package/dist/sidebar-Cfax0g0_.js +463 -0
  385. package/dist/sidebar-Cfax0g0_.js.map +1 -0
  386. package/dist/slot-C-jEfihz.cjs +122 -0
  387. package/dist/slot-C-jEfihz.cjs.map +1 -0
  388. package/dist/slot-EL8zfLG0.js +97 -0
  389. package/dist/slot-EL8zfLG0.js.map +1 -0
  390. package/dist/stack-DKdvlOM6.cjs +1771 -0
  391. package/dist/stack-DKdvlOM6.cjs.map +1 -0
  392. package/dist/stack-jMdxDrex.js +1531 -0
  393. package/dist/stack-jMdxDrex.js.map +1 -0
  394. package/dist/toast-D6MqijT2.cjs +316 -0
  395. package/dist/toast-D6MqijT2.cjs.map +1 -0
  396. package/dist/toast-D_BOLzm3.js +287 -0
  397. package/dist/toast-D_BOLzm3.js.map +1 -0
  398. package/dist/tooltip-CTRQoN1A.d.cts +29 -0
  399. package/dist/tooltip-CTRQoN1A.d.ts +29 -0
  400. package/dist/utils-BkMLyah9.js +12 -0
  401. package/dist/utils-BkMLyah9.js.map +1 -0
  402. package/dist/utils-CzTQ3-VI.cjs +17 -0
  403. package/dist/utils-CzTQ3-VI.cjs.map +1 -0
  404. package/package.json +288 -47
  405. package/src/styles/globals.css +155 -203
  406. package/dist/components/org-chart/index.d.ts +0 -54
  407. package/dist/components/org-chart/index.js +0 -861
  408. package/dist/components/org-chart/index.js.map +0 -1
  409. package/dist/components/record-picker.js.map +0 -1
  410. package/dist/components/sheet.js.map +0 -1
  411. package/dist/components/sidebar.js.map +0 -1
  412. package/dist/components/stack/index.js.map +0 -1
  413. package/dist/components/toast/index.js.map +0 -1
  414. package/dist/index.cjs.map +0 -1
  415. package/dist/index.js.map +0 -1
@@ -1,861 +0,0 @@
1
- "use client";
2
- import * as React2 from 'react';
3
- import { createContext, memo, useState, useContext, useCallback, useMemo, useEffect, useRef } from 'react';
4
- import { Handle, Position, ReactFlowProvider, useReactFlow, useNodesState, useEdgesState, ReactFlow, Background, BackgroundVariant, getSmoothStepPath, BaseEdge, Panel } from '@xyflow/react';
5
- import '@xyflow/react/dist/style.css';
6
- import { Ellipsis, Pencil, Trash2, Loader2, Network, UserPlus } from 'lucide-react';
7
- import { clsx } from 'clsx';
8
- import { twMerge } from 'tailwind-merge';
9
- import { Tooltip } from '@base-ui/react/tooltip';
10
- import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
11
- import { RiAddLine, RiSubtractLine, RiFocus3Line } from '@remixicon/react';
12
- import { cva } from 'class-variance-authority';
13
- import { Avatar as Avatar$1 } from '@base-ui/react/avatar';
14
- import { Menu } from '@base-ui/react/menu';
15
-
16
- // src/components/org-chart/org-chart.tsx
17
- function cn(...inputs) {
18
- return twMerge(clsx(inputs));
19
- }
20
- var PORTAL_ROOT_ID = "portal-root";
21
- var PortalContext = React2.createContext({
22
- layer: "base",
23
- depth: 0,
24
- floatingPortalStrategy: "root",
25
- floatingZIndex: "default"
26
- });
27
- function useRootPortalContainer() {
28
- const [container, setContainer] = React2.useState(null);
29
- React2.useLayoutEffect(() => {
30
- const el = document.getElementById(PORTAL_ROOT_ID);
31
- setContainer(el);
32
- }, []);
33
- return container;
34
- }
35
- function useFloatingOverlayPortalProps() {
36
- const rootContainer = useRootPortalContainer();
37
- const { floatingPortalStrategy, floatingZIndex } = React2.useContext(PortalContext);
38
- const container = floatingPortalStrategy === "nested" ? void 0 : rootContainer ?? null;
39
- const zIndexClass = floatingZIndex === "elevated" ? "z-[var(--z-layer-floating-elevated)]" : "z-[var(--z-layer-floating)]";
40
- return { container, zIndexClass };
41
- }
42
- function composeRefs(...refs) {
43
- return (node) => {
44
- refs.forEach((ref) => {
45
- if (typeof ref === "function") {
46
- ref(node);
47
- } else if (ref != null) {
48
- ref.current = node;
49
- }
50
- });
51
- };
52
- }
53
- function mergeProps(slotProps, childProps) {
54
- const overrideProps = { ...childProps };
55
- for (const propName in childProps) {
56
- if (propName === "ref") continue;
57
- const slotPropValue = slotProps[propName];
58
- const childPropValue = childProps[propName];
59
- if (/^on[A-Z]/.test(propName) && typeof slotPropValue === "function" && typeof childPropValue === "function") {
60
- overrideProps[propName] = (...args) => {
61
- childPropValue(...args);
62
- slotPropValue(...args);
63
- };
64
- } else if (propName === "className" && typeof slotPropValue === "string" && typeof childPropValue === "string") {
65
- overrideProps[propName] = `${slotPropValue} ${childPropValue}`.trim();
66
- } else if (propName === "style" && typeof slotPropValue === "object" && typeof childPropValue === "object") {
67
- overrideProps[propName] = { ...slotPropValue, ...childPropValue };
68
- }
69
- }
70
- return { ...slotProps, ...overrideProps };
71
- }
72
- function mergePropsWithRef(parentProps, childElement) {
73
- const childProps = childElement.props;
74
- const parentRef = parentProps.ref;
75
- const childRef = childProps.ref;
76
- const mergedProps = mergeProps(parentProps, childProps);
77
- if (parentRef || childRef) {
78
- mergedProps.ref = composeRefs(parentRef, childRef);
79
- }
80
- return mergedProps;
81
- }
82
- function isSlottable(child) {
83
- return React2.isValidElement(child);
84
- }
85
- var Slot = React2.forwardRef((props, forwardedRef) => {
86
- const { children, ...slotProps } = props;
87
- if (isSlottable(children)) {
88
- const childProps = children.props;
89
- const childRef = childProps.ref;
90
- return React2.cloneElement(children, {
91
- ...mergeProps(slotProps, childProps),
92
- ref: forwardedRef ? composeRefs(forwardedRef, childRef) : childRef
93
- });
94
- }
95
- if (React2.Children.count(children) > 1) {
96
- const childrenArray = React2.Children.toArray(children);
97
- const slottableChild = childrenArray.find(
98
- (child) => React2.isValidElement(child) && child.type === Slottable
99
- );
100
- if (slottableChild) {
101
- const newElement = slottableChild.props.children;
102
- if (isSlottable(newElement)) {
103
- const newElementProps = newElement.props;
104
- const newChildren = childrenArray.map((child) => {
105
- if (child === slottableChild) {
106
- return React2.Children.count(newElementProps.children) > 1 ? React2.Children.only(null) : newElementProps.children;
107
- }
108
- return child;
109
- });
110
- const childRef = newElementProps.ref;
111
- return React2.cloneElement(newElement, {
112
- ...mergeProps(slotProps, newElementProps),
113
- ref: forwardedRef ? composeRefs(forwardedRef, childRef) : childRef,
114
- children: newChildren
115
- });
116
- }
117
- }
118
- }
119
- return /* @__PURE__ */ jsx(Fragment, { children });
120
- });
121
- Slot.displayName = "Slot";
122
- function Slottable({ children }) {
123
- return /* @__PURE__ */ jsx(Fragment, { children });
124
- }
125
- function TooltipProvider({ delay = 0, delayDuration, ...props }) {
126
- return /* @__PURE__ */ jsx(Tooltip.Provider, { "data-slot": "tooltip-provider", delay: delayDuration ?? delay, ...props });
127
- }
128
- var buttonVariants = cva(
129
- "[&_svg]:-mx-0.5 relative inline-flex shrink-0 cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-lg border font-medium text-base outline-none transition-shadow before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-lg)-1px)] pointer-coarse:after:absolute pointer-coarse:after:size-full pointer-coarse:after:min-h-11 pointer-coarse:after:min-w-11 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-64 sm:text-sm [&_svg:not([class*='opacity-'])]:opacity-80 [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
130
- {
131
- defaultVariants: {
132
- size: "default",
133
- variant: "default"
134
- },
135
- variants: {
136
- size: {
137
- default: "h-9 px-[calc(--spacing(3)-1px)] sm:h-8",
138
- icon: "size-9 sm:size-8",
139
- "icon-lg": "size-10 sm:size-9",
140
- "icon-sm": "size-8 sm:size-7",
141
- "icon-xl": 'size-11 sm:size-10 [&_svg:not([class*="size-"])]:size-5 sm:[&_svg:not([class*="size-"])]:size-4.5',
142
- "icon-xs": 'size-7 rounded-md before:rounded-[calc(var(--radius-md)-1px)] sm:size-6 not-in-data-[slot=input-group]:[&_svg:not([class*="size-"])]:size-4 sm:not-in-data-[slot=input-group]:[&_svg:not([class*="size-"])]:size-3.5',
143
- lg: "h-10 px-[calc(--spacing(3.5)-1px)] sm:h-9",
144
- sm: "h-8 gap-1.5 px-[calc(--spacing(2.5)-1px)] sm:h-7",
145
- xl: 'h-11 px-[calc(--spacing(4)-1px)] text-lg sm:h-10 sm:text-base [&_svg:not([class*="size-"])]:size-5 sm:[&_svg:not([class*="size-"])]:size-4.5',
146
- xs: 'h-7 gap-1 rounded-md px-[calc(--spacing(2)-1px)] text-sm before:rounded-[calc(var(--radius-md)-1px)] sm:h-6 sm:text-xs [&_svg:not([class*="size-"])]:size-4 sm:[&_svg:not([class*="size-"])]:size-3.5'
147
- },
148
- variant: {
149
- default: "not-disabled:inset-shadow-[0_1px_--theme(--color-white/16%)] border-primary bg-primary text-primary-foreground shadow-primary/24 shadow-xs hover:bg-primary/90 [:active,[data-pressed]]:inset-shadow-[0_1px_--theme(--color-black/8%)] [:disabled,:active,[data-pressed]]:shadow-none",
150
- destructive: "not-disabled:inset-shadow-[0_1px_--theme(--color-white/16%)] border-destructive bg-destructive text-white shadow-destructive/24 shadow-xs hover:bg-destructive/90 [:active,[data-pressed]]:inset-shadow-[0_1px_--theme(--color-black/8%)] [:disabled,:active,[data-pressed]]:shadow-none",
151
- "destructive-outline": "border-destructive/40 bg-transparent bg-clip-padding text-destructive shadow-xs not-disabled:not-active:not-data-pressed:before:shadow-[0_1px_--theme(--color-black/4%)] dark:bg-input/32 dark:not-in-data-[slot=group]:bg-clip-border dark:not-disabled:before:shadow-[0_-1px_--theme(--color-white/4%)] dark:not-disabled:not-active:not-data-pressed:before:shadow-[0_-1px_--theme(--color-white/8%)] [:disabled,:active,[data-pressed]]:shadow-none [:hover,[data-pressed]]:border-destructive/60 [:hover,[data-pressed]]:bg-destructive/8",
152
- ghost: "border-transparent hover:bg-accent data-pressed:bg-accent",
153
- link: "border-transparent underline-offset-4 hover:underline",
154
- outline: "border-border bg-background bg-clip-padding shadow-xs not-disabled:not-active:not-data-pressed:before:shadow-[0_1px_--theme(--color-black/4%)] dark:bg-input/32 dark:not-in-data-[slot=group]:bg-clip-border dark:not-disabled:before:shadow-[0_-1px_--theme(--color-white/4%)] dark:not-disabled:not-active:not-data-pressed:before:shadow-[0_-1px_--theme(--color-white/8%)] [:disabled,:active,[data-pressed]]:shadow-none [:hover,[data-pressed]]:bg-accent/50 dark:[:hover,[data-pressed]]:bg-input/64",
155
- secondary: "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/90 [:active,[data-pressed]]:bg-secondary/80"
156
- }
157
- }
158
- }
159
- );
160
- var Button = React2.forwardRef(
161
- ({ className, variant, size, asChild, children, type = "button", ...props }, ref) => {
162
- const buttonClasses = cn(buttonVariants({ className, size, variant }));
163
- if (asChild && React2.isValidElement(children)) {
164
- const childProps = children.props;
165
- return React2.cloneElement(children, {
166
- ...props,
167
- className: cn(buttonClasses, childProps.className),
168
- "data-slot": "button"
169
- });
170
- }
171
- return /* @__PURE__ */ jsx("button", { ref, type, className: buttonClasses, "data-slot": "button", ...props, children });
172
- }
173
- );
174
- Button.displayName = "Button";
175
- var BUTTON_CLASS = "text-muted-foreground/80 hover:text-muted-foreground bg-card size-10 rounded-none shadow-none first:rounded-s-lg last:rounded-e-lg focus-visible:z-10";
176
- function FlowZoomPanel({
177
- className,
178
- position = "bottom-right",
179
- fitViewIcon = /* @__PURE__ */ jsx(RiFocus3Line, { className: "size-5", "aria-hidden": "true" }),
180
- fitViewOptions
181
- }) {
182
- const { zoomIn, zoomOut, fitView } = useReactFlow();
183
- const onFitView = useCallback(() => {
184
- fitView(fitViewOptions);
185
- }, [fitView, fitViewOptions]);
186
- return /* @__PURE__ */ jsxs(
187
- Panel,
188
- {
189
- "data-slot": "flow-zoom-panel",
190
- position,
191
- className: cn("inline-flex -space-x-px rounded-md shadow-xs rtl:space-x-reverse", className),
192
- children: [
193
- /* @__PURE__ */ jsx(Button, { variant: "outline", size: "icon", className: BUTTON_CLASS, onClick: () => zoomIn(), "aria-label": "Zoom in", children: /* @__PURE__ */ jsx(RiAddLine, { className: "size-5", "aria-hidden": "true" }) }),
194
- /* @__PURE__ */ jsx(Button, { variant: "outline", size: "icon", className: BUTTON_CLASS, onClick: () => zoomOut(), "aria-label": "Zoom out", children: /* @__PURE__ */ jsx(RiSubtractLine, { className: "size-5", "aria-hidden": "true" }) }),
195
- /* @__PURE__ */ jsx(Button, { variant: "outline", size: "icon", className: BUTTON_CLASS, onClick: onFitView, "aria-label": "Fit view", children: fitViewIcon })
196
- ]
197
- }
198
- );
199
- }
200
-
201
- // src/components/org-chart/layout.ts
202
- var NODE_WIDTH = 260;
203
- var NODE_HEIGHT = 100;
204
- var RANK_SEP = 80;
205
- var NODE_SEP = 40;
206
- var ROOT_KEY = "__root__";
207
- function computeLayout(edges) {
208
- const edgeById = /* @__PURE__ */ new Map();
209
- const childCountMap = /* @__PURE__ */ new Map();
210
- const childrenMap = /* @__PURE__ */ new Map();
211
- for (const e of edges) {
212
- edgeById.set(e.id, e);
213
- if (e.parentId) {
214
- childCountMap.set(e.parentId, (childCountMap.get(e.parentId) ?? 0) + 1);
215
- }
216
- const parent = e.parentId ?? ROOT_KEY;
217
- const bucket = childrenMap.get(parent);
218
- if (bucket) bucket.push(e.id);
219
- else childrenMap.set(parent, [e.id]);
220
- }
221
- for (const children of childrenMap.values()) {
222
- children.sort((a, b) => {
223
- const nameA = edgeById.get(a)?.displayName?.toLowerCase() ?? "";
224
- const nameB = edgeById.get(b)?.displayName?.toLowerCase() ?? "";
225
- return nameA.localeCompare(nameB);
226
- });
227
- }
228
- const widthCache = /* @__PURE__ */ new Map();
229
- const subtreeWidth = (nodeId) => {
230
- if (widthCache.has(nodeId)) return widthCache.get(nodeId);
231
- const children = childrenMap.get(nodeId);
232
- if (!children || children.length === 0) {
233
- widthCache.set(nodeId, NODE_WIDTH);
234
- return NODE_WIDTH;
235
- }
236
- const totalChildWidth = children.reduce((sum, c) => sum + subtreeWidth(c), 0);
237
- const gaps = (children.length - 1) * NODE_SEP;
238
- const w = Math.max(NODE_WIDTH, totalChildWidth + gaps);
239
- widthCache.set(nodeId, w);
240
- return w;
241
- };
242
- const positions = /* @__PURE__ */ new Map();
243
- const positionSubtree = (nodeId, centerX, y) => {
244
- positions.set(nodeId, { x: centerX, y });
245
- const children = childrenMap.get(nodeId);
246
- if (!children || children.length === 0) return;
247
- const totalWidth = children.reduce((sum, c) => sum + subtreeWidth(c), 0) + (children.length - 1) * NODE_SEP;
248
- let currentX = centerX - totalWidth / 2;
249
- for (const childId of children) {
250
- const childW = subtreeWidth(childId);
251
- positionSubtree(childId, currentX + childW / 2, y + NODE_HEIGHT + RANK_SEP);
252
- currentX += childW + NODE_SEP;
253
- }
254
- };
255
- const roots = childrenMap.get(ROOT_KEY) ?? [];
256
- if (roots.length === 1) {
257
- positionSubtree(roots[0], 0, 0);
258
- } else {
259
- const totalWidth = roots.reduce((sum, r) => sum + subtreeWidth(r), 0) + (roots.length - 1) * NODE_SEP;
260
- let currentX = -totalWidth / 2;
261
- for (const rootId of roots) {
262
- const w = subtreeWidth(rootId);
263
- positionSubtree(rootId, currentX + w / 2, 0);
264
- currentX += w + NODE_SEP;
265
- }
266
- }
267
- const nodes = edges.map((e) => {
268
- const pos = positions.get(e.id);
269
- return {
270
- id: e.id,
271
- type: "orgChartNode",
272
- width: NODE_WIDTH,
273
- height: NODE_HEIGHT,
274
- position: {
275
- x: pos.x - NODE_WIDTH / 2,
276
- y: pos.y
277
- },
278
- data: {
279
- id: e.id,
280
- displayName: e.displayName,
281
- avatarUrl: e.avatarUrl,
282
- positionTitle: e.positionTitle,
283
- parentId: e.parentId,
284
- childCount: childCountMap.get(e.id) ?? 0,
285
- isRoot: !e.parentId
286
- }
287
- };
288
- });
289
- const flowEdges = edges.filter((e) => e.parentId).map((e) => ({
290
- id: `edge-${e.parentId}-${e.id}`,
291
- source: e.parentId,
292
- target: e.id,
293
- type: "orgChartEdge"
294
- }));
295
- return { nodes, edges: flowEdges };
296
- }
297
- var NodeActionsContext = createContext(null);
298
- var OrgChartContext = createContext(null);
299
- function OrgChartProvider({ children, editable }) {
300
- const [selectedNodeId, setSelectedNodeId] = useState(null);
301
- const [draggedNodeId, setDraggedNodeId] = useState(null);
302
- const [dropTargetNodeId, setDropTargetNodeId] = useState(null);
303
- const selectNode = useCallback((nodeId) => setSelectedNodeId(nodeId), []);
304
- const clearSelection = useCallback(() => setSelectedNodeId(null), []);
305
- const value = useMemo(
306
- () => ({
307
- selectedNodeId,
308
- selectNode,
309
- clearSelection,
310
- editable,
311
- draggedNodeId,
312
- setDraggedNodeId,
313
- dropTargetNodeId,
314
- setDropTargetNodeId
315
- }),
316
- [selectedNodeId, selectNode, clearSelection, editable, draggedNodeId, dropTargetNodeId]
317
- );
318
- return /* @__PURE__ */ jsx(OrgChartContext.Provider, { value, children });
319
- }
320
- function useOrgChartContext() {
321
- const ctx = useContext(OrgChartContext);
322
- if (!ctx) throw new Error("useOrgChartContext must be used within OrgChartProvider");
323
- return ctx;
324
- }
325
- function NodeActionsProvider({
326
- children,
327
- onEditNode,
328
- onRemoveNode
329
- }) {
330
- const value = useMemo(() => ({ onEditNode, onRemoveNode }), [onEditNode, onRemoveNode]);
331
- return /* @__PURE__ */ jsx(NodeActionsContext.Provider, { value, children });
332
- }
333
- function useNodeActions() {
334
- const ctx = useContext(NodeActionsContext);
335
- if (!ctx) throw new Error("useNodeActions must be used within NodeActionsProvider");
336
- return ctx;
337
- }
338
- function OrgChartEdge({
339
- sourceX,
340
- sourceY,
341
- targetX,
342
- targetY,
343
- sourcePosition,
344
- targetPosition,
345
- style = {}
346
- }) {
347
- const [edgePath] = getSmoothStepPath({
348
- sourceX,
349
- sourceY,
350
- sourcePosition,
351
- targetX,
352
- targetY,
353
- targetPosition,
354
- borderRadius: 12
355
- });
356
- return /* @__PURE__ */ jsx(BaseEdge, { path: edgePath, style });
357
- }
358
- function OrgChartEmpty({ editable, onAddRoot }) {
359
- return /* @__PURE__ */ jsxs("div", { className: "bg-card border-border/60 flex flex-col items-center justify-center rounded-xl border py-16", children: [
360
- /* @__PURE__ */ jsx("div", { className: "bg-muted mb-4 flex size-14 items-center justify-center rounded-2xl", children: /* @__PURE__ */ jsx(Network, { className: "text-muted-foreground size-7" }) }),
361
- /* @__PURE__ */ jsx("h3", { className: "text-foreground text-base font-semibold", children: "No Org Chart Yet" }),
362
- /* @__PURE__ */ jsx("p", { className: "text-muted-foreground mt-1.5 max-w-sm text-center text-sm", children: "Build your organization hierarchy by adding the first person." }),
363
- editable && /* @__PURE__ */ jsxs(Button, { className: "mt-5 gap-1.5", onClick: onAddRoot, children: [
364
- /* @__PURE__ */ jsx(UserPlus, { className: "size-3.5" }),
365
- "Add First Member"
366
- ] })
367
- ] });
368
- }
369
- function Avatar({ className, ...props }) {
370
- return /* @__PURE__ */ jsx(
371
- Avatar$1.Root,
372
- {
373
- "data-slot": "avatar",
374
- className: cn("relative flex size-8 shrink-0 overflow-hidden rounded-full", className),
375
- ...props
376
- }
377
- );
378
- }
379
- function AvatarImage({ className, ...props }) {
380
- return /* @__PURE__ */ jsx(Avatar$1.Image, { "data-slot": "avatar-image", className: cn("aspect-square size-full", className), ...props });
381
- }
382
- function AvatarFallback({ className, delayMs, delay, ...props }) {
383
- return /* @__PURE__ */ jsx(
384
- Avatar$1.Fallback,
385
- {
386
- "data-slot": "avatar-fallback",
387
- delay: delay ?? delayMs,
388
- className: cn("bg-secondary flex size-full items-center justify-center rounded-[inherit] text-xs", className),
389
- ...props
390
- }
391
- );
392
- }
393
- var badgeVariants = cva(
394
- "relative inline-flex shrink-0 items-center justify-center gap-1 whitespace-nowrap rounded-sm border border-transparent font-medium outline-none transition-shadow focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-64 [&_svg:not([class*='size-'])]:size-3 [&_svg]:pointer-events-none [&_svg]:shrink-0 [button,a&]:cursor-pointer [button,a&]:pointer-coarse:after:absolute [button,a&]:pointer-coarse:after:size-full [button,a&]:pointer-coarse:after:min-h-11 [button,a&]:pointer-coarse:after:min-w-11",
395
- {
396
- defaultVariants: {
397
- size: "default",
398
- variant: "default"
399
- },
400
- variants: {
401
- size: {
402
- default: "px-[calc(--spacing(1)-1px)] text-xs",
403
- lg: "px-[calc(--spacing(1.5)-1px)] text-sm",
404
- sm: "rounded-[calc(var(--radius-sm)-2px)] px-[calc(--spacing(1)-1px)] text-[.625rem]"
405
- },
406
- variant: {
407
- default: "bg-primary text-primary-foreground [button,a&]:hover:bg-primary/90",
408
- destructive: "bg-destructive text-white [button,a&]:hover:bg-destructive/90",
409
- error: "bg-destructive/8 text-destructive dark:bg-destructive/16",
410
- info: "bg-info/8 text-info-foreground dark:bg-info/16",
411
- outline: "border-border/60 bg-transparent dark:bg-input/32 [button,a&]:hover:bg-accent/50 dark:[button,a&]:hover:bg-input/48",
412
- secondary: "bg-secondary text-secondary-foreground [button,a&]:hover:bg-secondary/90",
413
- success: "bg-success/8 text-success-foreground dark:bg-success/16",
414
- warning: "bg-warning/8 text-warning-foreground dark:bg-warning/16"
415
- }
416
- }
417
- }
418
- );
419
- var Badge = React2.forwardRef(({ className, variant, size, ...props }, ref) => /* @__PURE__ */ jsx("span", { ref, "data-slot": "badge", className: cn(badgeVariants({ variant, size }), className), ...props }));
420
- Badge.displayName = "Badge";
421
- function DropdownMenu({ ...props }) {
422
- return /* @__PURE__ */ jsx(Menu.Root, { "data-slot": "dropdown-menu", ...props });
423
- }
424
- function DropdownMenuPortal({ ...props }) {
425
- const { container } = useFloatingOverlayPortalProps();
426
- return /* @__PURE__ */ jsx(Menu.Portal, { "data-slot": "dropdown-menu-portal", container, ...props });
427
- }
428
- function DropdownMenuTrigger({ asChild, nativeButton, children, ...props }) {
429
- if (asChild && React2.isValidElement(children)) {
430
- return /* @__PURE__ */ jsx(
431
- Menu.Trigger,
432
- {
433
- "data-slot": "dropdown-menu-trigger",
434
- nativeButton: nativeButton ?? true,
435
- ...props,
436
- render: (triggerProps) => {
437
- const { nativeButton: _, ...rest } = triggerProps;
438
- return React2.cloneElement(
439
- children,
440
- mergePropsWithRef(rest, children)
441
- );
442
- }
443
- }
444
- );
445
- }
446
- return /* @__PURE__ */ jsx(Menu.Trigger, { "data-slot": "dropdown-menu-trigger", nativeButton, ...props, children });
447
- }
448
- function DropdownMenuContent({
449
- className,
450
- sideOffset = 4,
451
- side = "bottom",
452
- align = "start",
453
- onPointerDown: _onPointerDown,
454
- onPointerDownOutside: _onPointerDownOutside,
455
- onCloseAutoFocus: _onCloseAutoFocus,
456
- forceMount: _forceMount,
457
- ...props
458
- }) {
459
- const { zIndexClass } = useFloatingOverlayPortalProps();
460
- return /* @__PURE__ */ jsx(DropdownMenuPortal, { children: /* @__PURE__ */ jsx(Menu.Positioner, { side, align, sideOffset, className: zIndexClass, children: /* @__PURE__ */ jsx(
461
- Menu.Popup,
462
- {
463
- "data-slot": "dropdown-menu-content",
464
- className: cn(
465
- `bg-popover text-popover-foreground data-[open]:animate-in data-[closed]:animate-out
466
- data-[closed]:fade-out-0 data-[open]:fade-in-0 data-[closed]:zoom-out-95
467
- data-[open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2
468
- data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 min-w-40 overflow-hidden
469
- rounded-md border p-1 shadow-lg`,
470
- className
471
- ),
472
- ...props
473
- }
474
- ) }) });
475
- }
476
- function DropdownMenuItem({
477
- className,
478
- inset,
479
- variant = "default",
480
- asChild,
481
- children,
482
- onClick,
483
- ...props
484
- }) {
485
- const itemClassName = cn(
486
- `data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[variant=destructive]:text-destructive
487
- data-[variant=destructive]:data-[highlighted]:bg-destructive/10 dark:data-[variant=destructive]:data-[highlighted]:bg-destructive/40
488
- data-[variant=destructive]:data-[highlighted]:text-destructive
489
- data-[variant=destructive]:*:[svg]:!text-destructive relative flex cursor-default items-center gap-2
490
- rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none
491
- data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0`,
492
- className
493
- );
494
- if (asChild && React2.isValidElement(children)) {
495
- return /* @__PURE__ */ jsx(
496
- Menu.Item,
497
- {
498
- "data-slot": "dropdown-menu-item",
499
- "data-inset": inset,
500
- "data-variant": variant,
501
- ...props,
502
- render: (itemProps) => {
503
- const childProps = children.props;
504
- const itemOnClick = itemProps.onClick;
505
- return React2.cloneElement(children, {
506
- ...itemProps,
507
- className: cn(itemClassName, childProps.className),
508
- onClick: (e) => {
509
- onClick?.(e);
510
- itemOnClick?.(e);
511
- }
512
- });
513
- }
514
- }
515
- );
516
- }
517
- return /* @__PURE__ */ jsx(
518
- Menu.Item,
519
- {
520
- "data-slot": "dropdown-menu-item",
521
- "data-inset": inset,
522
- "data-variant": variant,
523
- ...props,
524
- render: (itemProps) => {
525
- const itemOnClick = itemProps.onClick;
526
- return /* @__PURE__ */ jsx(
527
- "div",
528
- {
529
- ...itemProps,
530
- className: cn(itemClassName, itemProps.className),
531
- onClick: (e) => {
532
- onClick?.(e);
533
- itemOnClick?.(e);
534
- },
535
- children
536
- }
537
- );
538
- }
539
- }
540
- );
541
- }
542
- function DropdownMenuSeparator({ className, ...props }) {
543
- return /* @__PURE__ */ jsx(
544
- Menu.Separator,
545
- {
546
- "data-slot": "dropdown-menu-separator",
547
- className: cn("bg-border -mx-1 my-1 h-px", className),
548
- ...props
549
- }
550
- );
551
- }
552
-
553
- // src/components/org-chart/org-chart-utils.ts
554
- function getInitials(name) {
555
- if (!name) return "--";
556
- const parts = name.trim().split(/\s+/).filter(Boolean);
557
- if (parts.length === 0) return "--";
558
- if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();
559
- return (parts[0][0] + parts[1][0]).toUpperCase();
560
- }
561
- function OrgChartNodeComponent({ id, data }) {
562
- const { selectedNodeId, dropTargetNodeId, editable } = useOrgChartContext();
563
- const { onEditNode, onRemoveNode } = useNodeActions();
564
- const isSelected = selectedNodeId === id;
565
- const isDropTarget = dropTargetNodeId === id;
566
- const [isHovered, setIsHovered] = useState(false);
567
- const [isMenuOpen, setIsMenuOpen] = useState(false);
568
- return /* @__PURE__ */ jsxs(
569
- "div",
570
- {
571
- style: { width: NODE_WIDTH },
572
- className: cn(
573
- "bg-card dark:bg-muted relative rounded-xl border shadow-sm transition-all",
574
- "border-border/60",
575
- isSelected && "ring-primary ring-2 ring-offset-2 dark:ring-offset-zinc-900",
576
- isDropTarget && "ring-primary/50 border-primary scale-105 ring-2"
577
- ),
578
- onMouseEnter: () => setIsHovered(true),
579
- onMouseLeave: () => setIsHovered(false),
580
- children: [
581
- !data.isRoot && /* @__PURE__ */ jsx(Handle, { type: "target", position: Position.Top, className: "!bg-border !size-2 !rounded-full !border-0" }),
582
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3 px-4 py-3", children: [
583
- /* @__PURE__ */ jsxs(Avatar, { className: "size-10 shrink-0", children: [
584
- data.avatarUrl && /* @__PURE__ */ jsx(AvatarImage, { src: data.avatarUrl, alt: data.displayName ?? "" }),
585
- /* @__PURE__ */ jsx(AvatarFallback, { className: "bg-primary/10 text-primary text-xs font-medium", children: getInitials(data.displayName) })
586
- ] }),
587
- /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
588
- /* @__PURE__ */ jsx("p", { className: "text-foreground truncate text-sm font-semibold", children: data.displayName ?? "Unknown" }),
589
- data.positionTitle && /* @__PURE__ */ jsx("p", { className: "text-muted-foreground truncate text-xs", children: data.positionTitle })
590
- ] }),
591
- editable && (isHovered || isMenuOpen) ? /* @__PURE__ */ jsx("div", { className: "nodrag nopan shrink-0", children: /* @__PURE__ */ jsxs(DropdownMenu, { open: isMenuOpen, onOpenChange: setIsMenuOpen, children: [
592
- /* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
593
- Button,
594
- {
595
- variant: "ghost",
596
- size: "icon",
597
- className: "size-7 rounded-full",
598
- onClick: (e) => e.stopPropagation(),
599
- children: /* @__PURE__ */ jsx(Ellipsis, { className: "size-4" })
600
- }
601
- ) }),
602
- /* @__PURE__ */ jsxs(DropdownMenuContent, { align: "start", side: "right", className: "translate-x-1 -translate-y-3.5", children: [
603
- /* @__PURE__ */ jsxs(
604
- DropdownMenuItem,
605
- {
606
- onClick: (e) => {
607
- e.stopPropagation();
608
- setIsMenuOpen(false);
609
- onEditNode(data);
610
- },
611
- children: [
612
- /* @__PURE__ */ jsx(Pencil, { className: "mr-2 size-3.5" }),
613
- "Edit Position"
614
- ]
615
- }
616
- ),
617
- /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
618
- /* @__PURE__ */ jsxs(
619
- DropdownMenuItem,
620
- {
621
- className: "text-destructive hover:bg-destructive/10 focus:bg-destructive/10 hover:text-destructive\n focus:text-destructive data-[highlighted]:bg-destructive/10 data-[highlighted]:text-destructive",
622
- onClick: (e) => {
623
- e.stopPropagation();
624
- setIsMenuOpen(false);
625
- onRemoveNode(data);
626
- },
627
- children: [
628
- /* @__PURE__ */ jsx(Trash2, { className: "mr-2 size-3.5" }),
629
- "Remove from Chart"
630
- ]
631
- }
632
- )
633
- ] })
634
- ] }) }) : data.childCount > 0 && /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: "shrink-0 text-[10px]", children: data.childCount })
635
- ] }),
636
- /* @__PURE__ */ jsx(Handle, { type: "source", position: Position.Bottom, className: "!bg-border !size-2 !rounded-full !border-0" })
637
- ]
638
- }
639
- );
640
- }
641
- var OrgChartNodeMemo = memo(OrgChartNodeComponent);
642
- var FIT_VIEW_OPTIONS = { padding: 0.12 };
643
- function getDescendantIds(nodeId, nodes) {
644
- const descendants = /* @__PURE__ */ new Set();
645
- const queue = [nodeId];
646
- while (queue.length > 0) {
647
- const current = queue.pop();
648
- for (const n of nodes) {
649
- if (n.data.parentId === current && !descendants.has(n.id)) {
650
- descendants.add(n.id);
651
- queue.push(n.id);
652
- }
653
- }
654
- }
655
- return descendants;
656
- }
657
- function mergeWithMeasured(prev, layoutNodes) {
658
- const prevMap = new Map(prev.map((n) => [n.id, n]));
659
- return layoutNodes.map((n) => {
660
- const existing = prevMap.get(n.id);
661
- if (!existing) return n;
662
- return existing.data.isRoot !== n.data.isRoot ? n : { ...n, measured: existing.measured };
663
- });
664
- }
665
- function OrgChartInner({
666
- className,
667
- edges: controlledEdges,
668
- defaultEdges,
669
- isLoading = false,
670
- editable = true,
671
- onReparent,
672
- onAddToChart,
673
- onEditNode,
674
- onRemoveNode,
675
- onReparentSuccess,
676
- onReparentError
677
- }) {
678
- const isControlled = controlledEdges !== void 0;
679
- const {
680
- selectNode,
681
- clearSelection,
682
- setDraggedNodeId,
683
- setDropTargetNodeId
684
- } = useOrgChartContext();
685
- const [internalEdges, setInternalEdges] = useState(defaultEdges ?? []);
686
- const defaultEdgesHash = useMemo(
687
- () => defaultEdges?.map((e) => `${e.id}:${e.parentId}:${e.positionTitle ?? ""}:${e.displayName ?? ""}`).join(",") ?? "",
688
- [defaultEdges]
689
- );
690
- useEffect(() => {
691
- if (!isControlled && defaultEdges) {
692
- setInternalEdges(defaultEdges);
693
- }
694
- }, [defaultEdgesHash]);
695
- const apiEdges = controlledEdges ?? internalEdges;
696
- const layout = useMemo(() => apiEdges.length > 0 ? computeLayout(apiEdges) : null, [apiEdges]);
697
- const layoutNodes = layout?.nodes ?? [];
698
- const layoutEdges = layout?.edges ?? [];
699
- const isEmpty = apiEdges.length === 0 && !isLoading;
700
- const { fitView, getIntersectingNodes } = useReactFlow();
701
- const [nodes, setNodes, onNodesChange] = useNodesState([]);
702
- const [rfEdges, setRfEdges, onEdgesChange] = useEdgesState([]);
703
- const nodesHash = useMemo(
704
- () => layoutNodes.map((n) => `${n.id}:${n.data.parentId ?? ""}:${n.data.positionTitle ?? ""}:${n.data.displayName ?? ""}`).join(","),
705
- [layoutNodes]
706
- );
707
- const edgesHash = useMemo(() => layoutEdges.map((e) => `${e.id}:${e.source}:${e.target}`).join(","), [layoutEdges]);
708
- const fitViewRef = useRef(fitView);
709
- fitViewRef.current = fitView;
710
- useEffect(() => {
711
- setNodes((prev) => mergeWithMeasured(prev, layoutNodes));
712
- setRfEdges(layoutEdges);
713
- const raf = requestAnimationFrame(() => fitViewRef.current(FIT_VIEW_OPTIONS));
714
- return () => cancelAnimationFrame(raf);
715
- }, [nodesHash, edgesHash]);
716
- const draggedNodeRef = useRef(null);
717
- const dropTargetIdRef = useRef(null);
718
- const nodeTypes = useMemo(() => ({ orgChartNode: OrgChartNodeMemo }), []);
719
- const edgeTypes = useMemo(() => ({ orgChartEdge: OrgChartEdge }), []);
720
- const onNodeDragStart = useCallback(
721
- (_, node) => {
722
- if (!editable) return;
723
- draggedNodeRef.current = node.id;
724
- setDraggedNodeId(node.id);
725
- },
726
- [editable, setDraggedNodeId]
727
- );
728
- const onNodeDrag = useCallback(
729
- (_, node) => {
730
- if (!editable || !draggedNodeRef.current) return;
731
- const intersecting = getIntersectingNodes(node);
732
- const target = intersecting.find((n) => n.id !== node.id);
733
- const targetId = target?.id ?? null;
734
- if (targetId === dropTargetIdRef.current) return;
735
- dropTargetIdRef.current = targetId;
736
- setDropTargetNodeId(targetId);
737
- },
738
- [editable, getIntersectingNodes, setDropTargetNodeId]
739
- );
740
- const applyOptimisticReparent = useCallback((childId, newParentId) => {
741
- setInternalEdges(
742
- (prev) => prev.map((e) => e.id === childId ? { ...e, parentId: newParentId } : e)
743
- );
744
- }, []);
745
- const snapBack = useCallback(() => {
746
- setNodes((prev) => mergeWithMeasured(prev, layoutNodes));
747
- }, [layoutNodes, setNodes]);
748
- const onNodeDragStop = useCallback(
749
- async (_, _node) => {
750
- if (!editable || !draggedNodeRef.current) return;
751
- const childId = draggedNodeRef.current;
752
- const newParentId = dropTargetIdRef.current;
753
- draggedNodeRef.current = null;
754
- dropTargetIdRef.current = null;
755
- setDraggedNodeId(null);
756
- setDropTargetNodeId(null);
757
- if (!newParentId || newParentId === childId) {
758
- snapBack();
759
- return;
760
- }
761
- if (getDescendantIds(childId, layoutNodes).has(newParentId)) {
762
- onReparentError?.("Cannot create circular reporting chain");
763
- snapBack();
764
- return;
765
- }
766
- const draggedData = layoutNodes.find((n) => n.id === childId)?.data;
767
- if (!draggedData || newParentId === draggedData.parentId) {
768
- snapBack();
769
- return;
770
- }
771
- const targetName = layoutNodes.find((n) => n.id === newParentId)?.data.displayName;
772
- const preserve = { positionTitle: draggedData.positionTitle };
773
- if (!isControlled) {
774
- const snapshotEdges = internalEdges;
775
- applyOptimisticReparent(childId, newParentId);
776
- try {
777
- await onReparent?.(childId, newParentId, preserve);
778
- onReparentSuccess?.(draggedData.displayName ?? "Member", targetName ?? "new manager");
779
- } catch (err) {
780
- console.error("[OrgChart] reparent failed", err);
781
- setInternalEdges(snapshotEdges);
782
- onReparentError?.("Failed to update reporting line");
783
- }
784
- } else {
785
- snapBack();
786
- try {
787
- await onReparent?.(childId, newParentId, preserve);
788
- onReparentSuccess?.(draggedData.displayName ?? "Member", targetName ?? "new manager");
789
- } catch (err) {
790
- console.error("[OrgChart] reparent failed", err);
791
- onReparentError?.("Failed to update reporting line");
792
- }
793
- }
794
- },
795
- [editable, isControlled, internalEdges, layoutNodes, onReparent, onReparentSuccess, onReparentError, applyOptimisticReparent, snapBack, setDraggedNodeId, setDropTargetNodeId]
796
- );
797
- const onNodeClick = useCallback((_, node) => selectNode(node.id), [selectNode]);
798
- const onPaneClick = useCallback(() => clearSelection(), [clearSelection]);
799
- const handleEditNode = useCallback(
800
- (nodeData) => onEditNode?.(nodeData),
801
- [onEditNode]
802
- );
803
- const handleRemoveNode = useCallback(
804
- (nodeData) => onRemoveNode?.(nodeData),
805
- [onRemoveNode]
806
- );
807
- if (isLoading) {
808
- return /* @__PURE__ */ jsx("div", { className: "bg-card border-border/60 flex items-center justify-center rounded-xl border p-16", children: /* @__PURE__ */ jsx(Loader2, { className: "text-muted-foreground size-6 animate-spin" }) });
809
- }
810
- if (isEmpty) {
811
- return /* @__PURE__ */ jsx(OrgChartEmpty, { editable, onAddRoot: onAddToChart ?? (() => {
812
- }) });
813
- }
814
- return /* @__PURE__ */ jsx(NodeActionsProvider, { onEditNode: handleEditNode, onRemoveNode: handleRemoveNode, children: /* @__PURE__ */ jsx("div", { className: cn("border-border/60 h-[600px] overflow-hidden rounded-xl border", className), children: /* @__PURE__ */ jsxs(
815
- ReactFlow,
816
- {
817
- nodes,
818
- edges: rfEdges,
819
- onNodesChange,
820
- onEdgesChange,
821
- onNodeClick,
822
- proOptions: { hideAttribution: true },
823
- onPaneClick,
824
- onNodeDragStart,
825
- onNodeDrag,
826
- onNodeDragStop,
827
- nodeTypes,
828
- edgeTypes,
829
- fitView: true,
830
- fitViewOptions: FIT_VIEW_OPTIONS,
831
- minZoom: 0.3,
832
- maxZoom: 1.5,
833
- nodesDraggable: editable,
834
- nodesConnectable: false,
835
- elementsSelectable: true,
836
- selectNodesOnDrag: false,
837
- panOnDrag: true,
838
- zoomOnScroll: true,
839
- preventScrolling: true,
840
- style: {
841
- "--xy-background-pattern-dots-color-default": "var(--color-border)",
842
- "--xy-edge-stroke-width-default": 2,
843
- "--xy-edge-stroke-default": "var(--color-border)",
844
- "--xy-edge-stroke-selected-default": "var(--color-foreground)",
845
- "--xy-attribution-background-color-default": "transparent"
846
- },
847
- attributionPosition: "bottom-left",
848
- children: [
849
- /* @__PURE__ */ jsx(Background, { variant: BackgroundVariant.Dots, gap: 20, size: 2 }),
850
- /* @__PURE__ */ jsx(FlowZoomPanel, { fitViewOptions: FIT_VIEW_OPTIONS })
851
- ]
852
- }
853
- ) }) });
854
- }
855
- function OrgChart(props) {
856
- return /* @__PURE__ */ jsx(ReactFlowProvider, { children: /* @__PURE__ */ jsx(OrgChartProvider, { editable: props.editable ?? true, children: /* @__PURE__ */ jsx(TooltipProvider, { children: /* @__PURE__ */ jsx(OrgChartInner, { ...props }) }) }) });
857
- }
858
-
859
- export { OrgChart };
860
- //# sourceMappingURL=index.js.map
861
- //# sourceMappingURL=index.js.map