@zonsh/ui 0.0.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (388) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +75 -1
  3. package/assets/illustrations/drawing/bracket-construction-dark.svg +77 -0
  4. package/assets/illustrations/drawing/bracket-construction-filled-dark.svg +50 -0
  5. package/assets/illustrations/drawing/bracket-construction-filled.svg +50 -0
  6. package/assets/illustrations/drawing/bracket-construction.svg +77 -0
  7. package/assets/illustrations/drawing/crescent-dark.svg +28 -0
  8. package/assets/illustrations/drawing/crescent-guides-dark.svg +33 -0
  9. package/assets/illustrations/drawing/crescent-guides.svg +33 -0
  10. package/assets/illustrations/drawing/crescent.svg +28 -0
  11. package/assets/illustrations/drawing/eclipse-dark.svg +187 -0
  12. package/assets/illustrations/drawing/eclipse-guides-dark.svg +191 -0
  13. package/assets/illustrations/drawing/eclipse-guides.svg +191 -0
  14. package/assets/illustrations/drawing/eclipse.svg +187 -0
  15. package/assets/illustrations/drawing/elevation-guides-dark.svg +31 -0
  16. package/assets/illustrations/drawing/elevation-guides-plain-dark.svg +9 -0
  17. package/assets/illustrations/drawing/elevation-guides-plain.svg +9 -0
  18. package/assets/illustrations/drawing/elevation-guides.svg +31 -0
  19. package/assets/illustrations/drawing/horizon-dark.svg +30 -0
  20. package/assets/illustrations/drawing/horizon.svg +30 -0
  21. package/assets/illustrations/drawing/nib-study-dark.svg +107 -0
  22. package/assets/illustrations/drawing/nib-study-plain-dark.svg +93 -0
  23. package/assets/illustrations/drawing/nib-study-plain.svg +93 -0
  24. package/assets/illustrations/drawing/nib-study.svg +107 -0
  25. package/assets/illustrations/editorial/assistant-640.webp +0 -0
  26. package/assets/illustrations/editorial/assistant.webp +0 -0
  27. package/assets/illustrations/editorial/automation-640.webp +0 -0
  28. package/assets/illustrations/editorial/automation.webp +0 -0
  29. package/assets/illustrations/editorial/bracket-left-640.webp +0 -0
  30. package/assets/illustrations/editorial/bracket-left.webp +0 -0
  31. package/assets/illustrations/editorial/bracket-right-640.webp +0 -0
  32. package/assets/illustrations/editorial/bracket-right.webp +0 -0
  33. package/assets/illustrations/editorial/custom-software-640.webp +0 -0
  34. package/assets/illustrations/editorial/custom-software.webp +0 -0
  35. package/assets/illustrations/editorial/digitalization-640.webp +0 -0
  36. package/assets/illustrations/editorial/digitalization.webp +0 -0
  37. package/assets/illustrations/editorial/integration-640.webp +0 -0
  38. package/assets/illustrations/editorial/integration.webp +0 -0
  39. package/assets/illustrations/editorial/problem-640.webp +0 -0
  40. package/assets/illustrations/editorial/problem.webp +0 -0
  41. package/assets/illustrations/editorial/process-analysis-640.webp +0 -0
  42. package/assets/illustrations/editorial/process-analysis.webp +0 -0
  43. package/assets/illustrations/editorial/process-concept-640.webp +0 -0
  44. package/assets/illustrations/editorial/process-concept.webp +0 -0
  45. package/assets/illustrations/editorial/process-development-640.webp +0 -0
  46. package/assets/illustrations/editorial/process-development.webp +0 -0
  47. package/assets/illustrations/editorial/process-discovery-640.webp +0 -0
  48. package/assets/illustrations/editorial/process-discovery.webp +0 -0
  49. package/assets/illustrations/editorial/process-maintenance-640.webp +0 -0
  50. package/assets/illustrations/editorial/process-maintenance.webp +0 -0
  51. package/assets/illustrations/editorial/process-prototype-640.webp +0 -0
  52. package/assets/illustrations/editorial/process-prototype.webp +0 -0
  53. package/assets/illustrations/editorial/process-testing-640.webp +0 -0
  54. package/assets/illustrations/editorial/process-testing.webp +0 -0
  55. package/assets/illustrations/iso/automation-dark.svg +6 -0
  56. package/assets/illustrations/iso/automation.svg +6 -0
  57. package/assets/illustrations/iso/bar-chart-dark.svg +6 -0
  58. package/assets/illustrations/iso/bar-chart.svg +6 -0
  59. package/assets/illustrations/iso/brackets-classic-dark.svg +6 -0
  60. package/assets/illustrations/iso/brackets-classic.svg +6 -0
  61. package/assets/illustrations/iso/brackets-dark.svg +6 -0
  62. package/assets/illustrations/iso/brackets.svg +6 -0
  63. package/assets/illustrations/iso/city-dark.svg +6 -0
  64. package/assets/illustrations/iso/city.svg +6 -0
  65. package/assets/illustrations/iso/conveyor-dark.svg +6 -0
  66. package/assets/illustrations/iso/conveyor.svg +6 -0
  67. package/assets/illustrations/iso/database-dark.svg +6 -0
  68. package/assets/illustrations/iso/database.svg +6 -0
  69. package/assets/illustrations/iso/documents-dark.svg +6 -0
  70. package/assets/illustrations/iso/documents.svg +6 -0
  71. package/assets/illustrations/iso/inbox-dark.svg +6 -0
  72. package/assets/illustrations/iso/inbox.svg +6 -0
  73. package/assets/illustrations/iso/laptop-dark.svg +6 -0
  74. package/assets/illustrations/iso/laptop.svg +6 -0
  75. package/assets/illustrations/iso/monitor-dark.svg +6 -0
  76. package/assets/illustrations/iso/monitor.svg +6 -0
  77. package/assets/illustrations/iso/pipeline-dark.svg +6 -0
  78. package/assets/illustrations/iso/pipeline.svg +6 -0
  79. package/assets/illustrations/iso/platform-dark.svg +6 -0
  80. package/assets/illustrations/iso/platform.svg +6 -0
  81. package/assets/illustrations/iso/server-dark.svg +6 -0
  82. package/assets/illustrations/iso/server.svg +6 -0
  83. package/assets/illustrations/iso/spreadsheet-dark.svg +6 -0
  84. package/assets/illustrations/iso/spreadsheet.svg +6 -0
  85. package/assets/illustrations/iso/timeline-dark.svg +6 -0
  86. package/assets/illustrations/iso/timeline.svg +6 -0
  87. package/assets/illustrations/sheet/construction.svg +115 -0
  88. package/assets/illustrations/sheet/crescent.svg +40 -0
  89. package/assets/illustrations/sheet/limb.svg +42 -0
  90. package/assets/illustrations/sheet/stress-axis.svg +119 -0
  91. package/assets/illustrations/sheet/totality.svg +215 -0
  92. package/assets/illustrations/sheet/vertical-metrics.svg +43 -0
  93. package/assets/logo-left.svg +1 -0
  94. package/assets/logo-right.svg +1 -0
  95. package/assets/logo.svg +1 -0
  96. package/dist/components/_overlay.d.ts +47 -0
  97. package/dist/components/_overlay.js +59 -0
  98. package/dist/components/accordion.d.ts +32 -0
  99. package/dist/components/accordion.js +39 -0
  100. package/dist/components/alert-dialog.d.ts +45 -0
  101. package/dist/components/alert-dialog.js +56 -0
  102. package/dist/components/alert.d.ts +35 -0
  103. package/dist/components/alert.js +42 -0
  104. package/dist/components/ascii-field.d.ts +34 -0
  105. package/dist/components/ascii-field.js +410 -0
  106. package/dist/components/aspect-ratio.d.ts +14 -0
  107. package/dist/components/aspect-ratio.js +17 -0
  108. package/dist/components/avatar.d.ts +42 -0
  109. package/dist/components/avatar.js +55 -0
  110. package/dist/components/badge.d.ts +70 -0
  111. package/dist/components/badge.js +62 -0
  112. package/dist/components/breadcrumb.d.ts +22 -0
  113. package/dist/components/breadcrumb.js +32 -0
  114. package/dist/components/button-group.d.ts +30 -0
  115. package/dist/components/button-group.js +47 -0
  116. package/dist/components/button.d.ts +53 -0
  117. package/dist/components/button.js +130 -0
  118. package/dist/components/calendar.d.ts +26 -0
  119. package/dist/components/calendar.js +164 -0
  120. package/dist/components/card.d.ts +42 -0
  121. package/dist/components/card.js +76 -0
  122. package/dist/components/carousel.d.ts +90 -0
  123. package/dist/components/carousel.js +213 -0
  124. package/dist/components/chart.d.ts +180 -0
  125. package/dist/components/chart.js +286 -0
  126. package/dist/components/checkbox.d.ts +23 -0
  127. package/dist/components/checkbox.js +43 -0
  128. package/dist/components/code-block.d.ts +45 -0
  129. package/dist/components/code-block.js +58 -0
  130. package/dist/components/code-highlight.d.ts +13 -0
  131. package/dist/components/code-highlight.js +107 -0
  132. package/dist/components/collapsible.d.ts +20 -0
  133. package/dist/components/collapsible.js +32 -0
  134. package/dist/components/color-picker.d.ts +85 -0
  135. package/dist/components/color-picker.js +407 -0
  136. package/dist/components/combobox.d.ts +81 -0
  137. package/dist/components/combobox.js +100 -0
  138. package/dist/components/command.d.ts +112 -0
  139. package/dist/components/command.js +212 -0
  140. package/dist/components/context-menu.d.ts +29 -0
  141. package/dist/components/context-menu.js +35 -0
  142. package/dist/components/conversation.d.ts +27 -0
  143. package/dist/components/conversation.js +293 -0
  144. package/dist/components/copy-button.d.ts +46 -0
  145. package/dist/components/copy-button.js +118 -0
  146. package/dist/components/data-table.d.ts +175 -0
  147. package/dist/components/data-table.js +302 -0
  148. package/dist/components/date-picker.d.ts +91 -0
  149. package/dist/components/date-picker.js +207 -0
  150. package/dist/components/dialog.d.ts +48 -0
  151. package/dist/components/dialog.js +92 -0
  152. package/dist/components/direction.d.ts +16 -0
  153. package/dist/components/direction.js +18 -0
  154. package/dist/components/drawer.d.ts +60 -0
  155. package/dist/components/drawer.js +76 -0
  156. package/dist/components/empty.d.ts +31 -0
  157. package/dist/components/empty.js +50 -0
  158. package/dist/components/feature-list.d.ts +54 -0
  159. package/dist/components/feature-list.js +43 -0
  160. package/dist/components/field.d.ts +15 -0
  161. package/dist/components/field.js +36 -0
  162. package/dist/components/file-drop.d.ts +55 -0
  163. package/dist/components/file-drop.js +197 -0
  164. package/dist/components/filter-bar.d.ts +106 -0
  165. package/dist/components/filter-bar.js +296 -0
  166. package/dist/components/form.d.ts +33 -0
  167. package/dist/components/form.js +34 -0
  168. package/dist/components/graph.d.ts +105 -0
  169. package/dist/components/graph.js +786 -0
  170. package/dist/components/illustration.d.ts +85 -0
  171. package/dist/components/illustration.js +165 -0
  172. package/dist/components/input-group.d.ts +127 -0
  173. package/dist/components/input-group.js +292 -0
  174. package/dist/components/input.d.ts +16 -0
  175. package/dist/components/input.js +25 -0
  176. package/dist/components/item.d.ts +64 -0
  177. package/dist/components/item.js +116 -0
  178. package/dist/components/kbd.d.ts +33 -0
  179. package/dist/components/kbd.js +38 -0
  180. package/dist/components/label.d.ts +12 -0
  181. package/dist/components/label.js +24 -0
  182. package/dist/components/layout.d.ts +136 -0
  183. package/dist/components/layout.js +162 -0
  184. package/dist/components/logo.d.ts +54 -0
  185. package/dist/components/logo.js +96 -0
  186. package/dist/components/menu.d.ts +60 -0
  187. package/dist/components/menu.js +138 -0
  188. package/dist/components/menubar.d.ts +62 -0
  189. package/dist/components/menubar.js +223 -0
  190. package/dist/components/message.d.ts +42 -0
  191. package/dist/components/message.js +56 -0
  192. package/dist/components/meter.d.ts +31 -0
  193. package/dist/components/meter.js +25 -0
  194. package/dist/components/native-select.d.ts +26 -0
  195. package/dist/components/native-select.js +35 -0
  196. package/dist/components/navigation-menu.d.ts +42 -0
  197. package/dist/components/navigation-menu.js +97 -0
  198. package/dist/components/number-field.d.ts +36 -0
  199. package/dist/components/number-field.js +153 -0
  200. package/dist/components/otp-field.d.ts +35 -0
  201. package/dist/components/otp-field.js +94 -0
  202. package/dist/components/pagination.d.ts +31 -0
  203. package/dist/components/pagination.js +70 -0
  204. package/dist/components/pdf-viewer.d.ts +69 -0
  205. package/dist/components/pdf-viewer.js +929 -0
  206. package/dist/components/popover.d.ts +33 -0
  207. package/dist/components/popover.js +48 -0
  208. package/dist/components/preview-card.d.ts +25 -0
  209. package/dist/components/preview-card.js +22 -0
  210. package/dist/components/progress.d.ts +27 -0
  211. package/dist/components/progress.js +23 -0
  212. package/dist/components/prompt-input.d.ts +131 -0
  213. package/dist/components/prompt-input.js +403 -0
  214. package/dist/components/quote.d.ts +22 -0
  215. package/dist/components/quote.js +15 -0
  216. package/dist/components/radio-group.d.ts +18 -0
  217. package/dist/components/radio-group.js +34 -0
  218. package/dist/components/reasoning.d.ts +31 -0
  219. package/dist/components/reasoning.js +70 -0
  220. package/dist/components/resizable.d.ts +38 -0
  221. package/dist/components/resizable.js +41 -0
  222. package/dist/components/response.d.ts +30 -0
  223. package/dist/components/response.js +538 -0
  224. package/dist/components/scroll-area.d.ts +33 -0
  225. package/dist/components/scroll-area.js +31 -0
  226. package/dist/components/select.d.ts +35 -0
  227. package/dist/components/select.js +60 -0
  228. package/dist/components/separator.d.ts +14 -0
  229. package/dist/components/separator.js +17 -0
  230. package/dist/components/sidebar.d.ts +147 -0
  231. package/dist/components/sidebar.js +489 -0
  232. package/dist/components/site-header.d.ts +59 -0
  233. package/dist/components/site-header.js +67 -0
  234. package/dist/components/skeleton.d.ts +31 -0
  235. package/dist/components/skeleton.js +29 -0
  236. package/dist/components/slider.d.ts +24 -0
  237. package/dist/components/slider.js +129 -0
  238. package/dist/components/sources.d.ts +25 -0
  239. package/dist/components/sources.js +35 -0
  240. package/dist/components/spinner.d.ts +36 -0
  241. package/dist/components/spinner.js +72 -0
  242. package/dist/components/suggestions.d.ts +20 -0
  243. package/dist/components/suggestions.js +18 -0
  244. package/dist/components/switch.d.ts +14 -0
  245. package/dist/components/switch.js +26 -0
  246. package/dist/components/table.d.ts +162 -0
  247. package/dist/components/table.js +758 -0
  248. package/dist/components/tabs.d.ts +25 -0
  249. package/dist/components/tabs.js +162 -0
  250. package/dist/components/tag.d.ts +41 -0
  251. package/dist/components/tag.js +88 -0
  252. package/dist/components/tags-input.d.ts +40 -0
  253. package/dist/components/tags-input.js +239 -0
  254. package/dist/components/textarea.d.ts +13 -0
  255. package/dist/components/textarea.js +16 -0
  256. package/dist/components/theme.d.ts +41 -0
  257. package/dist/components/theme.js +112 -0
  258. package/dist/components/time-field.d.ts +51 -0
  259. package/dist/components/time-field.js +437 -0
  260. package/dist/components/timeline.d.ts +76 -0
  261. package/dist/components/timeline.js +99 -0
  262. package/dist/components/toast.d.ts +72 -0
  263. package/dist/components/toast.js +196 -0
  264. package/dist/components/toggle-group.d.ts +41 -0
  265. package/dist/components/toggle-group.js +140 -0
  266. package/dist/components/toggle.d.ts +23 -0
  267. package/dist/components/toggle.js +35 -0
  268. package/dist/components/tool-call.d.ts +52 -0
  269. package/dist/components/tool-call.js +57 -0
  270. package/dist/components/toolbar.d.ts +17 -0
  271. package/dist/components/toolbar.js +34 -0
  272. package/dist/components/tooltip.d.ts +42 -0
  273. package/dist/components/tooltip.js +47 -0
  274. package/dist/components/tree.d.ts +75 -0
  275. package/dist/components/tree.js +636 -0
  276. package/dist/components/typography.d.ts +134 -0
  277. package/dist/components/typography.js +176 -0
  278. package/dist/components/video-player.d.ts +276 -0
  279. package/dist/components/video-player.js +1352 -0
  280. package/dist/components/whiteboard.d.ts +80 -0
  281. package/dist/components/whiteboard.js +389 -0
  282. package/dist/index.d.ts +85 -0
  283. package/dist/index.js +86 -0
  284. package/dist/lib/cn.d.ts +20 -0
  285. package/dist/lib/cn.js +38 -0
  286. package/dist/lib/code-highlight.d.ts +31 -0
  287. package/dist/lib/code-highlight.js +24 -0
  288. package/dist/lib/code-theme.d.ts +19 -0
  289. package/dist/lib/code-theme.js +140 -0
  290. package/dist/lib/collapse-row.d.ts +9 -0
  291. package/dist/lib/collapse-row.js +129 -0
  292. package/dist/lib/digit-roll.d.ts +21 -0
  293. package/dist/lib/digit-roll.js +31 -0
  294. package/dist/lib/editorial-assets.d.ts +16 -0
  295. package/dist/lib/editorial-assets.js +56 -0
  296. package/dist/lib/figure/catalog.d.ts +127 -0
  297. package/dist/lib/figure/catalog.js +130 -0
  298. package/dist/lib/figure/figures/automation.d.ts +7 -0
  299. package/dist/lib/figure/figures/automation.js +143 -0
  300. package/dist/lib/figure/figures/bar-chart.d.ts +7 -0
  301. package/dist/lib/figure/figures/bar-chart.js +99 -0
  302. package/dist/lib/figure/figures/brackets-classic.d.ts +11 -0
  303. package/dist/lib/figure/figures/brackets-classic.js +170 -0
  304. package/dist/lib/figure/figures/brackets.d.ts +8 -0
  305. package/dist/lib/figure/figures/brackets.js +84 -0
  306. package/dist/lib/figure/figures/city.d.ts +7 -0
  307. package/dist/lib/figure/figures/city.js +93 -0
  308. package/dist/lib/figure/figures/conveyor.d.ts +7 -0
  309. package/dist/lib/figure/figures/conveyor.js +97 -0
  310. package/dist/lib/figure/figures/database.d.ts +7 -0
  311. package/dist/lib/figure/figures/database.js +65 -0
  312. package/dist/lib/figure/figures/documents.d.ts +7 -0
  313. package/dist/lib/figure/figures/documents.js +83 -0
  314. package/dist/lib/figure/figures/inbox.d.ts +7 -0
  315. package/dist/lib/figure/figures/inbox.js +92 -0
  316. package/dist/lib/figure/figures/laptop.d.ts +7 -0
  317. package/dist/lib/figure/figures/laptop.js +67 -0
  318. package/dist/lib/figure/figures/monitor.d.ts +7 -0
  319. package/dist/lib/figure/figures/monitor.js +59 -0
  320. package/dist/lib/figure/figures/pipeline.d.ts +8 -0
  321. package/dist/lib/figure/figures/pipeline.js +117 -0
  322. package/dist/lib/figure/figures/platform.d.ts +7 -0
  323. package/dist/lib/figure/figures/platform.js +117 -0
  324. package/dist/lib/figure/figures/server.d.ts +7 -0
  325. package/dist/lib/figure/figures/server.js +115 -0
  326. package/dist/lib/figure/figures/spreadsheet.d.ts +7 -0
  327. package/dist/lib/figure/figures/spreadsheet.js +87 -0
  328. package/dist/lib/figure/figures/timeline.d.ts +7 -0
  329. package/dist/lib/figure/figures/timeline.js +65 -0
  330. package/dist/lib/figure/kernel.d.ts +152 -0
  331. package/dist/lib/figure/kernel.js +576 -0
  332. package/dist/lib/figure/parts.d.ts +42 -0
  333. package/dist/lib/figure/parts.js +126 -0
  334. package/dist/lib/form-reset.d.ts +11 -0
  335. package/dist/lib/form-reset.js +22 -0
  336. package/dist/lib/glide.d.ts +53 -0
  337. package/dist/lib/glide.js +138 -0
  338. package/dist/lib/graph-layout.d.ts +58 -0
  339. package/dist/lib/graph-layout.js +200 -0
  340. package/dist/lib/illustration-drawings.d.ts +89 -0
  341. package/dist/lib/illustration-drawings.js +539 -0
  342. package/dist/lib/illustration-info.d.ts +37 -0
  343. package/dist/lib/illustration-info.js +22 -0
  344. package/dist/lib/illustration-library.d.ts +87 -0
  345. package/dist/lib/illustration-library.js +352 -0
  346. package/dist/lib/logo-geometry.d.ts +29 -0
  347. package/dist/lib/logo-geometry.js +67 -0
  348. package/dist/lib/markdown-guard.d.ts +16 -0
  349. package/dist/lib/markdown-guard.js +123 -0
  350. package/dist/lib/merge-refs.d.ts +10 -0
  351. package/dist/lib/merge-refs.js +26 -0
  352. package/dist/lib/motion.d.ts +6 -0
  353. package/dist/lib/motion.js +12 -0
  354. package/dist/lib/pdf-worker.d.ts +1 -0
  355. package/dist/lib/pdf-worker.js +6 -0
  356. package/dist/lib/pdf.d.ts +19 -0
  357. package/dist/lib/pdf.js +58 -0
  358. package/dist/lib/platform.d.ts +33 -0
  359. package/dist/lib/platform.js +68 -0
  360. package/dist/lib/room.d.ts +25 -0
  361. package/dist/lib/room.js +46 -0
  362. package/dist/lib/table-fit.d.ts +143 -0
  363. package/dist/lib/table-fit.js +577 -0
  364. package/dist/lib/theme-script.d.ts +18 -0
  365. package/dist/lib/theme-script.js +29 -0
  366. package/dist/styles/expressive.css +188 -0
  367. package/dist/styles/fonts.css +145 -0
  368. package/dist/styles/index.css +206 -0
  369. package/dist/styles/material.css +313 -0
  370. package/dist/styles/parts/ai.css +360 -0
  371. package/dist/styles/parts/brand.css +75 -0
  372. package/dist/styles/parts/controls.css +725 -0
  373. package/dist/styles/parts/data.css +222 -0
  374. package/dist/styles/parts/editorial.css +120 -0
  375. package/dist/styles/parts/feedback.css +273 -0
  376. package/dist/styles/parts/foundations.css +166 -0
  377. package/dist/styles/parts/graph.css +214 -0
  378. package/dist/styles/parts/inputs.css +261 -0
  379. package/dist/styles/parts/isometric.css +124 -0
  380. package/dist/styles/parts/navigation.css +232 -0
  381. package/dist/styles/parts/overlays.css +250 -0
  382. package/dist/styles/parts/pdf.css +154 -0
  383. package/dist/styles/parts/react-flow.css +519 -0
  384. package/dist/styles/parts/whiteboard.css +855 -0
  385. package/dist/styles/tokens.css +290 -0
  386. package/dist/vite.d.ts +116 -0
  387. package/dist/vite.js +129 -0
  388. package/package.json +188 -5
@@ -0,0 +1,786 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { applyEdgeChanges, applyNodeChanges, Background, BackgroundVariant, BaseEdge, ConnectionLineType, EdgeLabelRenderer, getSmoothStepPath, getStraightPath, getViewportForBounds, Handle, MiniMap, Panel, Position, ReactFlow, ReactFlowProvider, useInternalNode, useReactFlow, } from "@xyflow/react";
4
+ import { ArrowLeftRightIcon, CircleDotIcon, MaximizeIcon, MinusIcon, PencilIcon, PlusIcon, Trash2Icon, WandSparklesIcon, } from "lucide-react";
5
+ import * as React from "react";
6
+ import { cn } from "../lib/cn.js";
7
+ import { cssDuration } from "../lib/motion.js";
8
+ import { LANE_HEADER, lanes, layered, network, dragSimulation, } from "../lib/graph-layout.js";
9
+ import { Avatar } from "./avatar.js";
10
+ import { ContextMenu, ContextMenuContent, ContextMenuGroup, ContextMenuGroupLabel, ContextMenuItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuTrigger, } from "./context-menu.js";
11
+ import { Toolbar, ToolbarButton, ToolbarGroup, ToolbarSeparator } from "./toolbar.js";
12
+ import { Tooltip, TooltipContent, TooltipTrigger } from "./tooltip.js";
13
+ const GraphContext = React.createContext(null);
14
+ const useGraph = () => React.useContext(GraphContext);
15
+ const clamp = (v, min, max) => Math.min(max, Math.max(min, v));
16
+ const kindOf = (n, layout) => n.kind ?? (layout === "network" ? "entity" : "task");
17
+ const edgeKindOf = (e, layout) => e.kind ?? (layout === "network" ? "relation" : "flow");
18
+ const isDirected = (e, layout) => {
19
+ if (e.directed != null)
20
+ return e.directed;
21
+ const kind = edgeKindOf(e, layout);
22
+ return layout !== "tree" && (kind === "flow" || kind === "message");
23
+ };
24
+ /** The box each kind is drawn in. Labels of events and gateways sit below it, outside. */
25
+ function sizeOf(n, layout) {
26
+ switch (kindOf(n, layout)) {
27
+ case "start":
28
+ case "end":
29
+ case "event":
30
+ return { width: 40, height: 40 };
31
+ case "gateway":
32
+ return { width: 44, height: 44 };
33
+ case "person":
34
+ return { width: 136, height: 96 };
35
+ case "entity":
36
+ return { width: Math.round(clamp(n.label.length * 7.4 + (n.icon ? 58 : 34), 84, 240)), height: 36 };
37
+ case "note":
38
+ return { width: 184, height: 52 };
39
+ case "group":
40
+ return { width: n.size?.width ?? 0, height: n.size?.height ?? 0 };
41
+ default:
42
+ return {
43
+ width: Math.round(clamp(n.label.length * 7.6 + (n.icon ? 66 : 40), 148, 264)),
44
+ height: n.meta ? 60 : 46,
45
+ };
46
+ }
47
+ }
48
+ /** Places every node: kept where positioned, else laid out. Groups come first, as React Flow needs. */
49
+ function build(value, layout, direction) {
50
+ const { nodes, edges } = value;
51
+ const kept = layout === "none" || nodes.every((n) => n.position);
52
+ const groupIds = nodes.filter((n) => kindOf(n, layout) === "group").map((n) => n.id);
53
+ // Swimlanes: a flow whose every step sits in a top-level group.
54
+ const laneMode = layout === "flow" &&
55
+ groupIds.length > 0 &&
56
+ nodes.every((n) => (groupIds.includes(n.id) ? !n.parent : n.parent && groupIds.includes(n.parent)));
57
+ const groups = new Set(nodes.filter((n) => kindOf(n, layout) === "group").map((n) => n.id));
58
+ const boxes = nodes
59
+ .filter((n) => !(layout === "network" && groups.has(n.id)))
60
+ .map((n) => ({
61
+ id: n.id,
62
+ ...sizeOf(n, layout),
63
+ ...(n.parent && groups.has(n.parent) && layout !== "network" ? { parent: n.parent } : {}),
64
+ ...(n.position && layout === "network" ? { fixed: n.position } : {}),
65
+ }));
66
+ let placed;
67
+ if (kept) {
68
+ placed = new Map();
69
+ for (const n of nodes)
70
+ placed.set(n.id, { ...(n.position ?? { x: 0, y: 0 }), ...(n.size ?? {}) });
71
+ // A group positioned by hand without a size wraps its children.
72
+ for (const g of groups) {
73
+ if (nodes.find((n) => n.id === g)?.size)
74
+ continue;
75
+ const children = nodes.filter((n) => n.parent === g);
76
+ let w = 160;
77
+ let h = 96;
78
+ for (const c of children) {
79
+ const s = sizeOf(c, layout);
80
+ w = Math.max(w, (c.position?.x ?? 0) + s.width + 20);
81
+ h = Math.max(h, (c.position?.y ?? 0) + s.height + 20);
82
+ }
83
+ placed.set(g, { ...placed.get(g), width: w, height: h });
84
+ }
85
+ }
86
+ else if (laneMode) {
87
+ placed = lanes(boxes, [...groups], edges, direction);
88
+ }
89
+ else if (layout === "network") {
90
+ placed = network(boxes, edges);
91
+ }
92
+ else {
93
+ placed = layered(boxes, edges, layout === "tree" ? "tree" : "flow", direction);
94
+ }
95
+ const absolute = (id) => placed.get(id) ?? { x: 0, y: 0 };
96
+ const flowNodes = [];
97
+ const ordered = [...nodes].sort((a, b) => Number(groups.has(b.id)) - Number(groups.has(a.id)));
98
+ for (const n of ordered) {
99
+ if (layout === "network" && groups.has(n.id))
100
+ continue;
101
+ const p = absolute(n.id);
102
+ const parent = n.parent && groups.has(n.parent) && layout !== "network" ? n.parent : undefined;
103
+ const size = groups.has(n.id) ? { width: p.width ?? 0, height: p.height ?? 0 } : sizeOf(n, layout);
104
+ // Laid out, positions are absolute: make a child's relative to its group.
105
+ const position = parent && !kept ? { x: p.x - absolute(parent).x, y: p.y - absolute(parent).y } : { x: p.x, y: p.y };
106
+ flowNodes.push({
107
+ id: n.id,
108
+ type: groups.has(n.id) ? "zon-group" : "zon",
109
+ position,
110
+ data: groups.has(n.id) && laneMode ? { node: n, lane: direction } : { node: n },
111
+ width: size.width,
112
+ height: size.height,
113
+ ...(parent ? { parentId: parent, extent: "parent" } : {}),
114
+ ...(groups.has(n.id) ? { selectable: true, zIndex: -1 } : {}),
115
+ ariaLabel: describeNode(n, layout),
116
+ });
117
+ }
118
+ const ids = new Set(flowNodes.map((n) => n.id));
119
+ const flowEdges = edges
120
+ .filter((e) => ids.has(e.source) && ids.has(e.target))
121
+ .map((e, i) => ({
122
+ id: e.id ?? `${e.source}->${e.target}#${i}`,
123
+ source: e.source,
124
+ target: e.target,
125
+ type: "zon",
126
+ data: { edge: e },
127
+ animated: e.animated,
128
+ ariaLabel: `${e.label ? `${e.label}: ` : ""}${labelOf(nodes, e.source)} to ${labelOf(nodes, e.target)}`,
129
+ }));
130
+ return { nodes: flowNodes, edges: flowEdges };
131
+ }
132
+ const labelOf = (nodes, id) => nodes.find((n) => n.id === id)?.label ?? id;
133
+ function describeNode(n, layout) {
134
+ const kind = kindOf(n, layout);
135
+ const what = kind === "start"
136
+ ? "start"
137
+ : kind === "end"
138
+ ? "end"
139
+ : kind === "gateway"
140
+ ? `${n.gateway ?? "exclusive"} gateway`
141
+ : kind === "event"
142
+ ? "event"
143
+ : kind === "group"
144
+ ? "group"
145
+ : "";
146
+ return [n.label, what, n.meta].filter(Boolean).join(", ");
147
+ }
148
+ /** The value a consumer sees: their nodes and edges, with positions (and sizes for groups). */
149
+ function toValue(nodes, edges) {
150
+ return {
151
+ nodes: nodes.map((n) => {
152
+ const out = {
153
+ ...n.data.node,
154
+ position: { x: Math.round(n.position.x), y: Math.round(n.position.y) },
155
+ };
156
+ if (n.type === "zon-group")
157
+ out.size = { width: Math.round(n.width ?? 0), height: Math.round(n.height ?? 0) };
158
+ return out;
159
+ }),
160
+ edges: edges.map((e) => ({ ...e.data.edge, id: e.id })),
161
+ };
162
+ }
163
+ /* ── Nodes ─────────────────────────────────────────────────────────────────── */
164
+ /** The handles a node is connected by: before and after it, in the direction of the flow. */
165
+ function Handles() {
166
+ const { direction } = useGraph();
167
+ const down = direction === "down";
168
+ return (_jsxs(_Fragment, { children: [_jsx(Handle, { type: "target", position: down ? Position.Top : Position.Left }), _jsx(Handle, { type: "source", position: down ? Position.Bottom : Position.Right })] }));
169
+ }
170
+ /** A label that turns into a field while it is being renamed. */
171
+ function Label({ kind, id, value, className, }) {
172
+ const { editing, setEditing, rename } = useGraph();
173
+ const active = editing?.kind === kind && editing.id === id;
174
+ const [draft, setDraft] = React.useState(value);
175
+ React.useEffect(() => setDraft(value), [value, active]);
176
+ if (!active)
177
+ return (_jsx("span", { "data-slot": "graph-label", className: cn("min-w-0 truncate", className), title: value, children: value }));
178
+ const done = (commit) => {
179
+ if (commit && draft.trim() && draft !== value)
180
+ rename(kind, id, draft.trim());
181
+ setEditing(null);
182
+ };
183
+ return (_jsx("input", {
184
+ // nodrag / nopan: typing and selecting text never moves the canvas.
185
+ className: cn("nodrag nopan min-w-0 border-0 bg-transparent p-0 text-inherit outline-none", className), "aria-label": kind === "node" ? "Node label" : "Edge label", autoFocus: true, value: draft, size: Math.max(4, draft.length), onChange: (event) => setDraft(event.currentTarget.value), onFocus: (event) => event.currentTarget.select(), onBlur: () => done(true), onKeyDown: (event) => {
186
+ event.stopPropagation();
187
+ if (event.key === "Enter")
188
+ done(true);
189
+ if (event.key === "Escape")
190
+ done(false);
191
+ } }));
192
+ }
193
+ const glyph = { exclusive: "×", parallel: "+", inclusive: "○" };
194
+ function NodeView({ id, data }) {
195
+ const { layout } = useGraph();
196
+ const n = data.node;
197
+ const kind = kindOf(n, layout);
198
+ const state = { "data-dim": data.dim ? "" : undefined, "data-lit": data.lit ? "" : undefined };
199
+ // Shapes whose name sits under them: events and gateways.
200
+ if (kind === "start" || kind === "end" || kind === "event" || kind === "gateway") {
201
+ return (_jsxs("div", { "data-slot": "graph-node", "data-kind": kind, ...state, className: "relative size-full", children: [_jsx(Handles, {}), _jsx("div", { "data-slot": "graph-shape", className: "grid size-full place-items-center", children: kind === "gateway" && (_jsx("span", { className: "font-mono text-[18px] leading-none text-foreground", children: glyph[n.gateway ?? "exclusive"] })) }), _jsx("div", { className: "pointer-events-none absolute top-full left-1/2 mt-2 w-max max-w-40 -translate-x-1/2 text-center font-mono text-[11px] leading-tight text-muted-foreground", children: _jsx(Label, { kind: "node", id: id, value: n.label, className: "pointer-events-auto" }) })] }));
202
+ }
203
+ if (kind === "note") {
204
+ return (_jsxs("div", { "data-slot": "graph-node", "data-kind": "note", ...state, className: "flex size-full items-center ps-3 text-[13px] leading-snug text-muted-foreground", children: [_jsx(Handles, {}), _jsx(Label, { kind: "node", id: id, value: n.label, className: "line-clamp-2 whitespace-normal" })] }));
205
+ }
206
+ if (kind === "person") {
207
+ return (_jsxs("div", { "data-slot": "graph-node", "data-kind": "person", ...state, className: "flex size-full flex-col items-center gap-1.5 pt-1 text-center", children: [_jsx(Handles, {}), _jsx(Avatar, { "data-slot": "graph-avatar", src: n.image, name: n.label, size: "lg" }), _jsxs("div", { className: "flex w-full min-w-0 flex-col items-center gap-0.5", children: [_jsx(Label, { kind: "node", id: id, value: n.label, className: "max-w-full text-[13px] font-medium text-foreground" }), n.meta && (_jsx("span", { className: "max-w-full truncate font-mono text-[11px] text-muted-foreground", children: n.meta }))] })] }));
208
+ }
209
+ return (_jsxs("div", { "data-slot": "graph-node", "data-kind": kind, ...state, className: cn("flex size-full min-w-0 items-center gap-2.5 material-raised text-foreground [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:text-muted-foreground", kind === "entity" ? "rounded-full px-3.5 text-[13px]" : "rounded-button px-3.5 text-[14px]"), children: [_jsx(Handles, {}), n.icon, _jsxs("div", { className: "flex min-w-0 flex-col", children: [_jsx(Label, { kind: "node", id: id, value: n.label, className: "leading-tight" }), n.meta && kind === "task" && (_jsx("span", { className: "mt-1 truncate font-mono text-[11px] leading-none text-muted-foreground", children: n.meta }))] })] }));
210
+ }
211
+ function GroupView({ id, data }) {
212
+ // A swimlane: a band with its name in a strip at the start, set along the flow.
213
+ if (data.lane) {
214
+ const down = data.lane === "down";
215
+ return (_jsx("div", { "data-slot": "graph-group", "data-lane": data.lane, className: cn("flex size-full border border-field-edge", down ? "flex-col" : "flex-row"), children: _jsx("div", { className: cn("flex shrink-0 items-center justify-center border-field-edge eyebrow text-[10px]", down ? "w-full border-b" : "h-full border-e"), style: down ? { height: LANE_HEADER } : { width: LANE_HEADER }, children: _jsx("span", { className: down ? "" : "rotate-180 [writing-mode:vertical-rl]", children: _jsx(Label, { kind: "node", id: id, value: data.node.label }) }) }) }));
216
+ }
217
+ return (_jsx("div", { "data-slot": "graph-group", "data-dim": data.dim ? "" : undefined, className: "size-full border border-dashed border-field-edge", children: _jsx("div", { className: "px-3 pt-2.5 eyebrow text-[10px]", children: _jsx(Label, { kind: "node", id: id, value: data.node.label }) }) }));
218
+ }
219
+ /** A path through points with each corner rounded: the route of an edge that goes back. */
220
+ function roundedPath(points, radius = 12) {
221
+ let d = `M${points[0].x},${points[0].y}`;
222
+ for (let i = 1; i < points.length - 1; i++) {
223
+ const prev = points[i - 1];
224
+ const at = points[i];
225
+ const next = points[i + 1];
226
+ const inLen = Math.hypot(at.x - prev.x, at.y - prev.y);
227
+ const outLen = Math.hypot(next.x - at.x, next.y - at.y);
228
+ const r = Math.min(radius, inLen / 2, outLen / 2);
229
+ const a = {
230
+ x: at.x - ((at.x - prev.x) / (inLen || 1)) * r,
231
+ y: at.y - ((at.y - prev.y) / (inLen || 1)) * r,
232
+ };
233
+ const b = {
234
+ x: at.x + ((next.x - at.x) / (outLen || 1)) * r,
235
+ y: at.y + ((next.y - at.y) / (outLen || 1)) * r,
236
+ };
237
+ d += ` L${a.x},${a.y} Q${at.x},${at.y} ${b.x},${b.y}`;
238
+ }
239
+ const last = points.at(-1);
240
+ return `${d} L${last.x},${last.y}`;
241
+ }
242
+ /** The box a node is drawn in, in flow coordinates. */
243
+ function boundsOf(node) {
244
+ const { x, y } = node.internals.positionAbsolute;
245
+ return { x, y, w: node.measured.width ?? node.width ?? 0, h: node.measured.height ?? node.height ?? 0 };
246
+ }
247
+ /**
248
+ * The box around top-level nodes, from their own positions and sizes: what React Flow's
249
+ * `getNodesBounds` gives without its node lookup, without the warning it logs (in development)
250
+ * on every such call.
251
+ */
252
+ function boxAround(nodes) {
253
+ if (!nodes.length)
254
+ return { x: 0, y: 0, width: 0, height: 0 };
255
+ const x = Math.min(...nodes.map((n) => n.position.x));
256
+ const y = Math.min(...nodes.map((n) => n.position.y));
257
+ const right = Math.max(...nodes.map((n) => n.position.x + (n.width ?? 0)));
258
+ const bottom = Math.max(...nodes.map((n) => n.position.y + (n.height ?? 0)));
259
+ return { x, y, width: right - x, height: bottom - y };
260
+ }
261
+ /* ── Edges ─────────────────────────────────────────────────────────────────── */
262
+ /** Where the line from a node's centre towards a point leaves the node: a circle or a box. */
263
+ function exit(node, toward, layout) {
264
+ const w = node.measured.width ?? node.width ?? 0;
265
+ const h = node.measured.height ?? node.height ?? 0;
266
+ const { x, y } = node.internals.positionAbsolute;
267
+ const kind = kindOf(node.data.node, layout);
268
+ // A person is joined at their avatar, the circle at the top of the node.
269
+ const cx = x + w / 2;
270
+ const cy = kind === "person" ? y + 24 : y + h / 2;
271
+ const dx = toward.x - cx;
272
+ const dy = toward.y - cy;
273
+ const len = Math.hypot(dx, dy) || 1;
274
+ const round = kind === "person" || kind === "start" || kind === "end" || kind === "event";
275
+ const reach = round
276
+ ? kind === "person"
277
+ ? 20
278
+ : w / 2
279
+ : Math.min(w / 2 / (Math.abs(dx) / len || 1e-6), h / 2 / (Math.abs(dy) / len || 1e-6));
280
+ const gap = 5;
281
+ return { x: cx + (dx / len) * (reach + gap), y: cy + (dy / len) * (reach + gap), cx, cy };
282
+ }
283
+ function EdgeView(props) {
284
+ const { layout, markers, direction, editing } = useGraph();
285
+ const { id, source, target, data } = props;
286
+ const s = useInternalNode(source);
287
+ const t = useInternalNode(target);
288
+ const edge = data.edge;
289
+ const kind = edgeKindOf(edge, layout);
290
+ const floating = layout === "network" || layout === "none";
291
+ let path;
292
+ let labelX;
293
+ let labelY;
294
+ if (floating && s && t) {
295
+ const sc = exit(s, { x: 0, y: 0 }, layout);
296
+ const tc = exit(t, { x: 0, y: 0 }, layout);
297
+ const a = exit(s, { x: tc.cx, y: tc.cy }, layout);
298
+ const b = exit(t, { x: sc.cx, y: sc.cy }, layout);
299
+ [path, labelX, labelY] = getStraightPath({ sourceX: a.x, sourceY: a.y, targetX: b.x, targetY: b.y });
300
+ }
301
+ else if (s &&
302
+ t &&
303
+ (direction === "down" ? props.targetY < props.sourceY + 8 : props.targetX < props.sourceX + 8)) {
304
+ // An edge that goes back against the flow: around the outside of both nodes, not through
305
+ // the ones between them — below a flow that runs right, beside one that runs down.
306
+ const a = boundsOf(s);
307
+ const b = boundsOf(t);
308
+ const out = 18;
309
+ if (direction === "down") {
310
+ const side = Math.max(a.x + a.w, b.x + b.w) + 32;
311
+ const points = [
312
+ { x: props.sourceX, y: props.sourceY },
313
+ { x: props.sourceX, y: props.sourceY + out },
314
+ { x: side, y: props.sourceY + out },
315
+ { x: side, y: props.targetY - out },
316
+ { x: props.targetX, y: props.targetY - out },
317
+ { x: props.targetX, y: props.targetY },
318
+ ];
319
+ path = roundedPath(points);
320
+ labelX = side;
321
+ labelY = (props.sourceY + props.targetY) / 2;
322
+ }
323
+ else {
324
+ const below = Math.max(a.y + a.h, b.y + b.h) + 32;
325
+ const points = [
326
+ { x: props.sourceX, y: props.sourceY },
327
+ { x: props.sourceX + out, y: props.sourceY },
328
+ { x: props.sourceX + out, y: below },
329
+ { x: props.targetX - out, y: below },
330
+ { x: props.targetX - out, y: props.targetY },
331
+ { x: props.targetX, y: props.targetY },
332
+ ];
333
+ path = roundedPath(points);
334
+ labelX = (props.sourceX + props.targetX) / 2;
335
+ labelY = below;
336
+ }
337
+ }
338
+ else {
339
+ [path, labelX, labelY] = getSmoothStepPath({
340
+ sourceX: props.sourceX,
341
+ sourceY: props.sourceY,
342
+ sourcePosition: props.sourcePosition,
343
+ targetX: props.targetX,
344
+ targetY: props.targetY,
345
+ targetPosition: props.targetPosition,
346
+ borderRadius: 12,
347
+ offset: 16,
348
+ });
349
+ }
350
+ const directed = isDirected(edge, layout);
351
+ const marker = directed ? `url(#${markers}-${data?.lit || props.selected ? "lit" : "rest"})` : undefined;
352
+ return (_jsxs(_Fragment, { children: [_jsx(BaseEdge, { id: id, path: path, markerEnd: marker, interactionWidth: 18, "data-kind": kind, className: "zon-graph-edge", "data-dim": data?.dim ? "" : undefined,
353
+ "data-lit": data?.lit || props.selected ? "" : undefined }), (edge.label || (editing?.kind === "edge" && editing.id === id)) && (_jsx(EdgeLabelRenderer, { children: _jsx("div", { "data-slot": "graph-edge-label", "data-edge": id, "data-dim": data?.dim ? "" : undefined, "data-lit": data?.lit || props.selected ? "" : undefined, className: "nodrag nopan pointer-events-auto absolute", style: { transform: `translate(-50%, -50%) translate(${labelX}px, ${labelY}px)` }, children: _jsx(Label, { kind: "edge", id: id, value: edge.label ?? "" }) }) }))] }));
354
+ }
355
+ /** What a new node of each kind is called until it is renamed. */
356
+ const fresh = {
357
+ task: "New step",
358
+ start: "Start",
359
+ end: "End",
360
+ event: "Event",
361
+ gateway: "Decide?",
362
+ note: "A note",
363
+ person: "New person",
364
+ entity: "New node",
365
+ group: "Group",
366
+ };
367
+ /** What the canvas menu offers to add, by layout. */
368
+ const addable = {
369
+ flow: [
370
+ { kind: "task", label: "Step" },
371
+ { kind: "gateway", label: "Decision" },
372
+ { kind: "event", label: "Event" },
373
+ { kind: "start", label: "Start" },
374
+ { kind: "end", label: "End" },
375
+ { kind: "note", label: "Note" },
376
+ ],
377
+ tree: [
378
+ { kind: "person", label: "Person" },
379
+ { kind: "task", label: "Step" },
380
+ ],
381
+ network: [
382
+ { kind: "entity", label: "Node" },
383
+ { kind: "person", label: "Person" },
384
+ ],
385
+ none: [
386
+ { kind: "task", label: "Step" },
387
+ { kind: "entity", label: "Node" },
388
+ { kind: "person", label: "Person" },
389
+ { kind: "note", label: "Note" },
390
+ ],
391
+ };
392
+ const nodeTypes = { zon: NodeView, "zon-group": GroupView };
393
+ const edgeTypes = { zon: EdgeView };
394
+ /**
395
+ * Graph — things and how they connect, on a canvas that pans and zooms: a flow of steps (BPMN
396
+ * tasks, events and gateways), an org chart or tree, or a network of relations (people, shows,
397
+ * systems). Pass `nodes` and `edges`; the layout places them — layered for flows and trees, by
398
+ * forces for networks — or keeps the positions you give.
399
+ *
400
+ * Hover or select a node to light up its connections. In a network, drag a node and its
401
+ * neighbours follow. With `editable`, it is a small diagram editor that reports every change
402
+ * through `onChange`. It needs `@xyflow/react`, `@dagrejs/dagre` and `d3-force`, and is
403
+ * imported from `@zonsh/ui/graph`. The rule people break: a hairball. Past a few dozen nodes,
404
+ * show a part of the graph, or group it.
405
+ */
406
+ export function Graph(props) {
407
+ return (_jsx(ReactFlowProvider, { children: _jsx(GraphCanvas, { ...props }) }));
408
+ }
409
+ function GraphCanvas({ nodes: nodesProp, edges: edgesProp, layout = "flow", direction: directionProp, editable = false, onChange, onSelect, newNodeKind, minimap = false, controls = true, background = "dots", variant = "region", className, ...props }) {
410
+ const direction = directionProp ?? (layout === "tree" ? "down" : "right");
411
+ const flow = useReactFlow();
412
+ const markers = React.useId().replace(/[^a-zA-Z0-9]/g, "");
413
+ const frame = React.useRef(null);
414
+ const describedBy = `${markers}-connections`;
415
+ const [state, setState] = React.useState(() => build({ nodes: nodesProp, edges: edgesProp }, layout, direction));
416
+ const latest = React.useRef(state);
417
+ latest.current = state;
418
+ // The value last sent out: when it comes back as props, it is not laid out again.
419
+ const sent = React.useRef(null);
420
+ React.useEffect(() => {
421
+ if (sent.current && sent.current.nodes === nodesProp && sent.current.edges === edgesProp)
422
+ return;
423
+ setState(build({ nodes: nodesProp, edges: edgesProp }, layout, direction));
424
+ requestAnimationFrame(() => void flow.fitView({ padding: 0.18, maxZoom: 1.15, duration: 0 }));
425
+ }, [nodesProp, edgesProp, layout, direction, flow]);
426
+ const emit = React.useCallback((next) => {
427
+ if (!onChange)
428
+ return;
429
+ const value = toValue(next.nodes, next.edges);
430
+ sent.current = value;
431
+ onChange(value);
432
+ }, [onChange]);
433
+ /* Light up what the pointer or the selection is on, and its neighbours. */
434
+ const [hovered, setHovered] = React.useState(null);
435
+ const [selected, setSelected] = React.useState([]);
436
+ const focus = hovered ? [hovered] : selected;
437
+ const shown = React.useMemo(() => {
438
+ if (!focus.length)
439
+ return state;
440
+ const lit = new Set(focus);
441
+ const litEdges = new Set();
442
+ for (const e of state.edges) {
443
+ if (lit.has(e.source) || lit.has(e.target)) {
444
+ litEdges.add(e.id);
445
+ }
446
+ }
447
+ const near = new Set(focus);
448
+ for (const e of state.edges)
449
+ if (litEdges.has(e.id))
450
+ near.add(e.source).add(e.target);
451
+ return {
452
+ nodes: state.nodes.map((n) => n.type === "zon-group" ? n : { ...n, data: { ...n.data, dim: !near.has(n.id), lit: lit.has(n.id) } }),
453
+ edges: state.edges.map((e) => ({
454
+ ...e,
455
+ data: { ...e.data, dim: !litEdges.has(e.id), lit: litEdges.has(e.id) },
456
+ })),
457
+ };
458
+ }, [state, focus.join("|")]); // eslint-disable-line react-hooks/exhaustive-deps
459
+ /* Editing. */
460
+ const [editing, setEditing] = React.useState(null);
461
+ const rename = React.useCallback((kind, id, label) => {
462
+ const s = latest.current;
463
+ const next = kind === "node"
464
+ ? {
465
+ ...s,
466
+ nodes: s.nodes.map((n) => n.id === id ? { ...n, data: { ...n.data, node: { ...n.data.node, label } } } : n),
467
+ }
468
+ : {
469
+ ...s,
470
+ edges: s.edges.map((e) => e.id === id ? { ...e, data: { ...e.data, edge: { ...e.data.edge, label } } } : e),
471
+ };
472
+ setState(next);
473
+ emit(next);
474
+ }, [emit]);
475
+ const onNodesChange = React.useCallback((changes) => {
476
+ // Removing a node removes its edges with it.
477
+ const gone = new Set(changes.filter((c) => c.type === "remove").map((c) => c.id));
478
+ if (gone.size) {
479
+ const s = latest.current;
480
+ const next = {
481
+ nodes: applyNodeChanges(changes, s.nodes),
482
+ edges: s.edges.filter((e) => !gone.has(e.source) && !gone.has(e.target)),
483
+ };
484
+ setState(next);
485
+ emit(next);
486
+ return;
487
+ }
488
+ // Moves, sizes and selection apply to the newest state: while a network settles, the
489
+ // simulation moves the other nodes in the same frames as the drag.
490
+ setState((prev) => {
491
+ const next = { ...prev, nodes: applyNodeChanges(changes, prev.nodes) };
492
+ latest.current = next;
493
+ return next;
494
+ });
495
+ }, [emit]);
496
+ const onEdgesChange = React.useCallback((changes) => {
497
+ const s = latest.current;
498
+ const next = { ...s, edges: applyEdgeChanges(changes, s.edges) };
499
+ setState(next);
500
+ if (changes.some((c) => c.type === "remove"))
501
+ emit(next);
502
+ }, [emit]);
503
+ const onConnect = React.useCallback((c) => {
504
+ if (!c.source || !c.target || c.source === c.target)
505
+ return;
506
+ const s = latest.current;
507
+ const edge = { source: c.source, target: c.target };
508
+ const id = `${c.source}->${c.target}#${Date.now().toString(36)}`;
509
+ const next = {
510
+ ...s,
511
+ edges: [...s.edges, { id, source: c.source, target: c.target, type: "zon", data: { edge } }],
512
+ };
513
+ setState(next);
514
+ emit(next);
515
+ }, [emit]);
516
+ // A connection let go anywhere on another node — not only on its handle — connects to it.
517
+ const onConnectEnd = React.useCallback((event, state) => {
518
+ if (state.isValid || !state.fromNode)
519
+ return;
520
+ const point = "changedTouches" in event ? event.changedTouches[0] : event;
521
+ if (!point)
522
+ return;
523
+ const target = document
524
+ .elementFromPoint(point.clientX, point.clientY)
525
+ ?.closest(".react-flow__node");
526
+ const id = target?.dataset.id;
527
+ if (!id || id === state.fromNode.id)
528
+ return;
529
+ const from = state.fromNode.id;
530
+ onConnect(state.fromHandle?.type === "target"
531
+ ? { source: id, target: from, sourceHandle: null, targetHandle: null }
532
+ : { source: from, target: id, sourceHandle: null, targetHandle: null });
533
+ }, [onConnect]);
534
+ const addNode = React.useCallback((at, as) => {
535
+ const s = latest.current;
536
+ const kind = as ?? newNodeKind ?? (layout === "network" ? "entity" : "task");
537
+ const node = { id: `n${Date.now().toString(36)}`, label: fresh[kind], kind };
538
+ const size = sizeOf(node, layout);
539
+ // Without a point, the middle of what is in view.
540
+ const box = frame.current?.getBoundingClientRect();
541
+ const center = at ??
542
+ flow.screenToFlowPosition({
543
+ x: box ? box.left + box.width / 2 : window.innerWidth / 2,
544
+ y: box ? box.top + box.height / 2 : window.innerHeight / 2,
545
+ });
546
+ const flowNode = {
547
+ id: node.id,
548
+ type: "zon",
549
+ position: { x: center.x - size.width / 2, y: center.y - size.height / 2 },
550
+ data: { node },
551
+ width: size.width,
552
+ height: size.height,
553
+ selected: true,
554
+ ariaLabel: node.label,
555
+ };
556
+ const next = { ...s, nodes: [...s.nodes.map((n) => ({ ...n, selected: false })), flowNode] };
557
+ setState(next);
558
+ emit(next);
559
+ setEditing({ kind: "node", id: node.id });
560
+ }, [emit, flow, layout, newNodeKind]);
561
+ /*
562
+ * Tidying moves the nodes to their new places, so you can follow where each one goes: they
563
+ * glide from where they stand, the connections following every frame, and the camera moves on
564
+ * the same clock to where it will frame the result — one movement, not a move and then a zoom. A Web Animation keeps the time and the eased progress, so slow motion slows it and
565
+ * reduced motion (a 0 --duration) jumps. Tidying again, or grabbing a node, stops it where it is.
566
+ */
567
+ const tidying = React.useRef(null);
568
+ React.useEffect(() => () => tidying.current?.stop(), []);
569
+ const tidy = React.useCallback(() => {
570
+ tidying.current?.stop();
571
+ const from = latest.current;
572
+ const value = toValue(from.nodes, from.edges);
573
+ const next = build({ nodes: value.nodes.map(({ position: _p, size: _s, ...n }) => n), edges: value.edges }, layout, direction);
574
+ const el = frame.current;
575
+ const duration = el ? cssDuration(el) * 3 : 0;
576
+ // Without motion (reduced motion) the camera jumps too.
577
+ const fit = () => requestAnimationFrame(() => void flow.fitView({ padding: 0.18, maxZoom: 1.15, duration: duration ? 280 : 0 }));
578
+ if (!el || !duration) {
579
+ setState(next);
580
+ emit(next);
581
+ fit();
582
+ return;
583
+ }
584
+ const start = new Map(from.nodes.map((n) => [n.id, n.position]));
585
+ // Where the camera will frame the tidied graph (top-level nodes: lanes hold their own).
586
+ const pane = el.querySelector(".react-flow");
587
+ const camera0 = flow.getViewport();
588
+ const camera1 = pane
589
+ ? getViewportForBounds(boxAround(next.nodes.filter((n) => !n.parentId)), pane.clientWidth, pane.clientHeight, 0.2, 1.15, 0.18)
590
+ : null;
591
+ const ease = getComputedStyle(el).getPropertyValue("--ease").trim() || "ease-out";
592
+ // No keyframes: the animation only keeps the clock; its progress places the nodes.
593
+ const clock = el.animate([], { duration, easing: ease });
594
+ let raf = 0;
595
+ const place = (progress) => {
596
+ if (camera1)
597
+ void flow.setViewport({
598
+ x: camera0.x + (camera1.x - camera0.x) * progress,
599
+ y: camera0.y + (camera1.y - camera0.y) * progress,
600
+ zoom: camera0.zoom + (camera1.zoom - camera0.zoom) * progress,
601
+ });
602
+ setState({
603
+ ...next,
604
+ nodes: next.nodes.map((n) => {
605
+ const a = start.get(n.id) ?? n.position;
606
+ return {
607
+ ...n,
608
+ position: { x: a.x + (n.position.x - a.x) * progress, y: a.y + (n.position.y - a.y) * progress },
609
+ };
610
+ }),
611
+ });
612
+ };
613
+ const step = () => {
614
+ place(clock.effect?.getComputedTiming().progress ?? 1);
615
+ raf = requestAnimationFrame(step);
616
+ };
617
+ raf = requestAnimationFrame(step);
618
+ const end = () => {
619
+ cancelAnimationFrame(raf);
620
+ tidying.current = null;
621
+ };
622
+ clock.onfinish = () => {
623
+ end();
624
+ place(1);
625
+ setState(next);
626
+ emit(next);
627
+ if (!camera1)
628
+ fit();
629
+ };
630
+ tidying.current = {
631
+ stop: () => {
632
+ clock.onfinish = null;
633
+ clock.cancel();
634
+ end();
635
+ emit(latest.current);
636
+ },
637
+ };
638
+ }, [direction, emit, flow, layout]);
639
+ /* Networks: a dragged node pulls its neighbours along, and the rest settles around it. */
640
+ const physics = React.useRef(null);
641
+ const reduce = () => typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
642
+ const onNodeDragStart = React.useCallback((_, node) => {
643
+ tidying.current?.stop();
644
+ if (layout !== "network" || reduce())
645
+ return;
646
+ // A drag that starts while the last one settles takes over from it: one simulation at a time.
647
+ physics.current?.stop();
648
+ physics.current = null;
649
+ const s = latest.current;
650
+ const boxes = s.nodes.map((n) => ({
651
+ id: n.id,
652
+ width: n.width ?? 0,
653
+ height: n.height ?? 0,
654
+ fixed: n.position,
655
+ }));
656
+ const { simulation, sim } = dragSimulation(boxes, s.edges.map((e) => ({ source: e.source, target: e.target })), node.id);
657
+ // Held, the graph stays warm so the neighbours keep up with the pointer.
658
+ simulation.alpha(0.3).alphaTarget(0.3);
659
+ let frame = 0;
660
+ const sizes = new Map(s.nodes.map((n) => [n.id, { w: n.width ?? 0, h: n.height ?? 0 }]));
661
+ const byId = new Map(sim.map((d) => [d.id, d]));
662
+ const held = new Set([node.id]);
663
+ const step = () => {
664
+ simulation.tick();
665
+ setState((prev) => {
666
+ const next = {
667
+ ...prev,
668
+ nodes: prev.nodes.map((n) => {
669
+ const d = byId.get(n.id);
670
+ if (!d || held.has(n.id))
671
+ return n;
672
+ const box = sizes.get(n.id);
673
+ return { ...n, position: { x: (d.x ?? 0) - box.w / 2, y: (d.y ?? 0) - box.h / 2 } };
674
+ }),
675
+ };
676
+ latest.current = next;
677
+ return next;
678
+ });
679
+ if (simulation.alpha() > simulation.alphaMin())
680
+ frame = requestAnimationFrame(step);
681
+ else
682
+ physics.current = null;
683
+ };
684
+ frame = requestAnimationFrame(step);
685
+ physics.current = {
686
+ stop: () => {
687
+ cancelAnimationFrame(frame);
688
+ simulation.stop();
689
+ },
690
+ fix: (id, x, y) => {
691
+ const d = byId.get(id);
692
+ const box = sizes.get(id);
693
+ if (d) {
694
+ d.fx = x + box.w / 2;
695
+ d.fy = y + box.h / 2;
696
+ }
697
+ },
698
+ release: () => {
699
+ // Let go, the node stays where it was dropped and the rest settles around it.
700
+ held.clear();
701
+ simulation.alphaTarget(0);
702
+ },
703
+ };
704
+ }, [layout]);
705
+ const onNodeDrag = React.useCallback((_, node) => {
706
+ physics.current?.fix(node.id, node.position.x, node.position.y);
707
+ }, []);
708
+ const onNodeDragStop = React.useCallback(() => {
709
+ physics.current?.release();
710
+ // Report once the graph has come to rest (or at once, without the physics).
711
+ const wait = () => {
712
+ if (physics.current)
713
+ requestAnimationFrame(wait);
714
+ else
715
+ emit(latest.current);
716
+ };
717
+ wait();
718
+ }, [emit]);
719
+ React.useEffect(() => () => physics.current?.stop(), []);
720
+ const onSelectionChange = React.useCallback(({ nodes, edges }) => {
721
+ setSelected(nodes.filter((n) => n.type !== "zon-group").map((n) => n.id));
722
+ onSelect?.({ nodes: nodes.map((n) => n.id), edges: edges.map((e) => e.id) });
723
+ }, [onSelect]);
724
+ const context = React.useMemo(() => ({ layout, direction, editable, markers, editing, setEditing, rename }), [layout, direction, editable, markers, editing, rename]);
725
+ /* The context menu: what was right-clicked. */
726
+ const [target, setTarget] = React.useState(null);
727
+ const pick = (event) => {
728
+ const el = event.target;
729
+ // Fields, the controls and the map keep the browser's own menu.
730
+ if (el.closest("input, textarea, .react-flow__panel, .react-flow__minimap")) {
731
+ event.stopPropagation();
732
+ return;
733
+ }
734
+ const node = el.closest(".react-flow__node");
735
+ const edge = el.closest(".react-flow__edge, [data-slot='graph-edge-label']");
736
+ if (node?.dataset.id)
737
+ setTarget({
738
+ type: node.classList.contains("react-flow__node-zon-group") ? "group" : "node",
739
+ id: node.dataset.id,
740
+ });
741
+ else if (edge) {
742
+ const id = edge.dataset.id ?? edge.dataset.edge;
743
+ if (id)
744
+ setTarget({ type: "edge", id });
745
+ }
746
+ else
747
+ setTarget({ type: "pane", at: flow.screenToFlowPosition({ x: event.clientX, y: event.clientY }) });
748
+ };
749
+ const removeNode = (id) => onNodesChange([{ type: "remove", id }]);
750
+ const removeEdge = (id) => onEdgesChange([{ type: "remove", id }]);
751
+ const reverse = (id) => {
752
+ const s = latest.current;
753
+ const next = {
754
+ ...s,
755
+ edges: s.edges.map((e) => e.id === id
756
+ ? {
757
+ ...e,
758
+ source: e.target,
759
+ target: e.source,
760
+ data: { ...e.data, edge: { ...e.data.edge, source: e.target, target: e.source } },
761
+ }
762
+ : e),
763
+ };
764
+ setState(next);
765
+ emit(next);
766
+ };
767
+ const targetEdge = target?.type === "edge" ? state.edges.find((e) => e.id === target.id) : undefined;
768
+ const stepped = layout === "flow" || layout === "tree";
769
+ const labels = React.useMemo(() => new Map(state.nodes.map((n) => [n.id, n.data.node.label])), [state.nodes]);
770
+ const canvas = (_jsxs(ReactFlow, { nodes: shown.nodes, edges: shown.edges, nodeTypes: nodeTypes, edgeTypes: edgeTypes, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onConnect: editable ? onConnect : undefined, onConnectEnd: editable ? onConnectEnd : undefined, onNodeMouseEnter: (_, n) => n.type !== "zon-group" && setHovered(n.id), onNodeMouseLeave: () => setHovered(null), onNodeDragStart: onNodeDragStart, onNodeDrag: onNodeDrag, onNodeDragStop: onNodeDragStop, onSelectionChange: onSelectionChange, nodesConnectable: editable, edgesReconnectable: false, deleteKeyCode: editable ? ["Backspace", "Delete"] : null, connectionLineType: stepped ? ConnectionLineType.SmoothStep : ConnectionLineType.Straight, fitView: true, fitViewOptions: { padding: 0.18, maxZoom: 1.15 }, minZoom: 0.2, maxZoom: 2, proOptions: { hideAttribution: true }, "aria-describedby": describedBy, children: [background !== "none" && (_jsx(Background, { variant: background === "lines" ? BackgroundVariant.Lines : BackgroundVariant.Dots, gap: background === "lines" ? 32 : 20, size: 1 })), minimap && (_jsx(MiniMap, { position: "bottom-right", style: { width: 152, height: 100 }, pannable: true, zoomable: true, nodeBorderRadius: 4, ariaLabel: "Map of the graph" })), controls && (_jsx(Panel, { position: "bottom-left", children: _jsx(GraphControls, { editable: editable, tidy: layout === "none" ? undefined : tidy, add: () => addNode() }) }))] }));
771
+ return (_jsx(GraphContext.Provider, { value: context, children: _jsxs("div", { ref: frame, "data-slot": "graph", "data-layout": layout, "data-editable": editable ? "" : undefined, className: cn("relative h-[min(40rem,80svh)] w-full overflow-hidden", variant === "card" ? "surface-card [--card-padding:0]" : "surface-container", className), onKeyDown: (event) => {
772
+ // Editable: Enter on a focused node opens its label.
773
+ const node = event.target.closest(".react-flow__node");
774
+ if (!editable || event.key !== "Enter" || !node?.dataset.id || editing)
775
+ return;
776
+ event.preventDefault();
777
+ setEditing({ kind: "node", id: node.dataset.id });
778
+ }, ...props, children: [_jsx("svg", { "aria-hidden": true, className: "absolute size-0", children: _jsx("defs", { children: ["rest", "lit"].map((tone) => (_jsx("marker", { id: `${markers}-${tone}`, viewBox: "0 0 10 10", refX: "9", refY: "5", markerWidth: "7", markerHeight: "7", orient: "auto-start-reverse", children: _jsx("path", { d: "M1 1.5 L9 5 L1 8.5 Z", "data-tone": tone, className: "zon-graph-arrow" }) }, tone))) }) }), editable ? (_jsxs(ContextMenu, { children: [_jsx(ContextMenuTrigger, { className: "absolute inset-0", onContextMenuCapture: pick, children: canvas }), _jsxs(ContextMenuContent, { children: [target?.type === "pane" && (_jsxs(_Fragment, { children: [_jsxs(ContextMenuGroup, { children: [_jsx(ContextMenuGroupLabel, { children: "Add here" }), addable[layout].map((a) => (_jsxs(ContextMenuItem, { onClick: () => addNode(target.at, a.kind), children: [_jsx(PlusIcon, {}), a.label] }, a.kind)))] }), _jsx(ContextMenuSeparator, {}), layout !== "none" && (_jsxs(ContextMenuItem, { onClick: tidy, children: [_jsx(WandSparklesIcon, {}), "Tidy up"] })), _jsxs(ContextMenuItem, { onClick: () => void flow.fitView({ padding: 0.18, maxZoom: 1.15, duration: 280 }), children: [_jsx(MaximizeIcon, {}), "Fit to view"] })] })), (target?.type === "node" || target?.type === "group") && (_jsxs(_Fragment, { children: [_jsxs(ContextMenuItem, { onClick: () => setEditing({ kind: "node", id: target.id }), children: [_jsx(PencilIcon, {}), "Rename", _jsx(ContextMenuShortcut, { children: "Enter" })] }), target.type === "node" && (_jsxs(_Fragment, { children: [_jsx(ContextMenuSeparator, {}), _jsxs(ContextMenuItem, { variant: "destructive", onClick: () => removeNode(target.id), children: [_jsx(Trash2Icon, {}), "Delete", _jsx(ContextMenuShortcut, { children: "Del" })] })] }))] })), target?.type === "edge" && (_jsxs(_Fragment, { children: [_jsxs(ContextMenuItem, { onClick: () => setEditing({ kind: "edge", id: target.id }), children: [_jsx(PencilIcon, {}), targetEdge?.data?.edge.label ? "Rename label" : "Add a label"] }), targetEdge && isDirected(targetEdge.data.edge, layout) && (_jsxs(ContextMenuItem, { onClick: () => reverse(target.id), children: [_jsx(ArrowLeftRightIcon, {}), "Reverse direction"] })), _jsx(ContextMenuSeparator, {}), _jsxs(ContextMenuItem, { variant: "destructive", onClick: () => removeEdge(target.id), children: [_jsx(Trash2Icon, {}), "Remove connection", _jsx(ContextMenuShortcut, { children: "Del" })] })] }))] })] })) : (canvas), _jsx("ul", { id: describedBy, className: "sr-only", children: state.edges.map((e) => (_jsxs("li", { children: [labels.get(e.source), " ", isDirected(e.data.edge, layout) ? "to" : "and", " ", labels.get(e.target), e.data.edge.label ? `: ${e.data.edge.label}` : ""] }, e.id))) })] }) }));
779
+ }
780
+ function ControlButton({ label, onClick, children, }) {
781
+ return (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(ToolbarButton, { "aria-label": label, onClick: onClick }), children: children }), _jsx(TooltipContent, { side: "top", children: label })] }));
782
+ }
783
+ function GraphControls({ editable, tidy, add }) {
784
+ const flow = useReactFlow();
785
+ return (_jsxs(Toolbar, { "aria-label": "Graph", "data-slot": "graph-controls", children: [_jsxs(ToolbarGroup, { children: [_jsx(ControlButton, { label: "Zoom in", onClick: () => void flow.zoomIn({ duration: 200 }), children: _jsx(PlusIcon, {}) }), _jsx(ControlButton, { label: "Zoom out", onClick: () => void flow.zoomOut({ duration: 200 }), children: _jsx(MinusIcon, {}) }), _jsx(ControlButton, { label: "Fit to view", onClick: () => void flow.fitView({ padding: 0.18, maxZoom: 1.15, duration: 280 }), children: _jsx(MaximizeIcon, {}) })] }), (editable || tidy) && _jsx(ToolbarSeparator, {}), _jsxs(ToolbarGroup, { children: [editable && (_jsx(ControlButton, { label: "Add a node", onClick: add, children: _jsx(CircleDotIcon, {}) })), tidy && (_jsx(ControlButton, { label: "Tidy up", onClick: tidy, children: _jsx(WandSparklesIcon, {}) }))] })] }));
786
+ }