@redvars/peacock 4.0.0 → 4.1.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 (408) hide show
  1. package/dist/{BaseField-CAog9TIc.js → BaseField-BMumJpkW.js} +6 -3
  2. package/dist/BaseField-BMumJpkW.js.map +1 -0
  3. package/dist/{BaseInput-CcMfg1Y2.js → BaseInput-mWdyYv27.js} +6 -3
  4. package/dist/BaseInput-mWdyYv27.js.map +1 -0
  5. package/dist/accordion.js.map +1 -1
  6. package/dist/ai-badge.js +2 -2
  7. package/dist/ai-summary.js +2 -2
  8. package/dist/alert.js +2 -2
  9. package/dist/anchor-nav.js +2 -2
  10. package/dist/app-shell.js +2 -2
  11. package/dist/assistant-panel.js +2 -2
  12. package/dist/assistant-step.js +2 -2
  13. package/dist/assistant-steps.js +2 -2
  14. package/dist/avatar-group.js +2 -2
  15. package/dist/banner.js +2 -2
  16. package/dist/{base-button-Do2TUy8M.js → base-button-BJMGMcMv.js} +3 -1
  17. package/dist/base-button-BJMGMcMv.js.map +1 -0
  18. package/dist/{base-progress-BiLlZVHJ.js → base-progress-CvLVSjuy.js} +4 -2
  19. package/dist/base-progress-CvLVSjuy.js.map +1 -0
  20. package/dist/bottom-sheet.js +2 -2
  21. package/dist/breadcrumb.js +2 -2
  22. package/dist/button-group.js +4 -4
  23. package/dist/button.js +3 -3
  24. package/dist/calendar.js +2 -2
  25. package/dist/canvas-base-BTQMEVn_.js +788 -0
  26. package/dist/canvas-base-BTQMEVn_.js.map +1 -0
  27. package/dist/canvas-link-CtgsALq4.js +54 -0
  28. package/dist/canvas-link-CtgsALq4.js.map +1 -0
  29. package/dist/{cartesian-chart-C-f1frt0.js → cartesian-chart-DM1FC_XT.js} +3 -2
  30. package/dist/cartesian-chart-DM1FC_XT.js.map +1 -0
  31. package/dist/{cb-group-base-DeuCVx3a.js → cb-group-base-B6fa4Lll.js} +2 -2
  32. package/dist/{cb-group-base-DeuCVx3a.js.map → cb-group-base-B6fa4Lll.js.map} +1 -1
  33. package/dist/cb-group.js +3 -3
  34. package/dist/cb-rule.js +3 -3
  35. package/dist/chart-area.js +5 -4
  36. package/dist/chart-area.js.map +1 -1
  37. package/dist/chart-bar.js +5 -4
  38. package/dist/chart-bar.js.map +1 -1
  39. package/dist/chart-base-Dhxuw_Mw.js +833 -0
  40. package/dist/chart-base-Dhxuw_Mw.js.map +1 -0
  41. package/dist/chart-doughnut.js +4 -3
  42. package/dist/chart-doughnut.js.map +1 -1
  43. package/dist/chart-line.js +5 -4
  44. package/dist/chart-line.js.map +1 -1
  45. package/dist/chart-pie.js +4 -3
  46. package/dist/chart-pie.js.map +1 -1
  47. package/dist/chat-message.js +2 -2
  48. package/dist/chat-thread.js +2 -2
  49. package/dist/checkbox-group.js +4 -4
  50. package/dist/checkbox.js +4 -4
  51. package/dist/chip-set.js +3 -3
  52. package/dist/chip.js +4 -4
  53. package/dist/circular-progress.js +3 -3
  54. package/dist/citation.js +2 -2
  55. package/dist/code-editor.js +5 -4
  56. package/dist/code-editor.js.map +1 -1
  57. package/dist/code-highlighter.js +2 -2
  58. package/dist/color-field.js +5 -5
  59. package/dist/color-picker.js +2 -2
  60. package/dist/command-palette.js +2 -2
  61. package/dist/comment-composer.js +5 -5
  62. package/dist/condition-builder.js +3 -3
  63. package/dist/confirm-dialog.js +2 -2
  64. package/dist/copy-button.js +2 -2
  65. package/dist/currency-field.js +5 -5
  66. package/dist/custom-elements-jsdocs.json +2115 -336
  67. package/dist/custom-elements.json +19483 -615
  68. package/dist/date-field.js +6 -6
  69. package/dist/date-picker.js +4 -2
  70. package/dist/date-picker.js.map +1 -1
  71. package/dist/date-range-field.js +6 -6
  72. package/dist/datetime-field.js +6 -6
  73. package/dist/dependency-map-layout-5KUueabk.js +1390 -0
  74. package/dist/dependency-map-layout-5KUueabk.js.map +1 -0
  75. package/dist/dependency-map.js +1605 -0
  76. package/dist/dependency-map.js.map +1 -0
  77. package/dist/description-item.js +2 -2
  78. package/dist/description-list.js +2 -2
  79. package/dist/diagram-2r11KySs.js +2029 -0
  80. package/dist/diagram-2r11KySs.js.map +1 -0
  81. package/dist/diagram-controls.js +345 -0
  82. package/dist/diagram-controls.js.map +1 -0
  83. package/dist/diagram-minimap.js +216 -0
  84. package/dist/diagram-minimap.js.map +1 -0
  85. package/dist/diagram.js +20 -0
  86. package/dist/diagram.js.map +1 -0
  87. package/dist/diff-viewer.js +2 -2
  88. package/dist/discussion-activity.js +2 -2
  89. package/dist/discussion-comment.js +2 -2
  90. package/dist/discussion.js +5 -5
  91. package/dist/{document-editor-BO7QPbO5.js → document-editor-BnEugM3E.js} +2 -2
  92. package/dist/{document-editor-BO7QPbO5.js.map → document-editor-BnEugM3E.js.map} +1 -1
  93. package/dist/document-editor.js +3 -3
  94. package/dist/draft-card.js +2 -2
  95. package/dist/erd.js +2021 -0
  96. package/dist/erd.js.map +1 -0
  97. package/dist/fab.js +4 -4
  98. package/dist/field.js +257 -43
  99. package/dist/field.js.map +1 -1
  100. package/dist/file-upload.js +37 -15
  101. package/dist/file-upload.js.map +1 -1
  102. package/dist/filter-bar.js +2 -2
  103. package/dist/flow.js +27 -970
  104. package/dist/flow.js.map +1 -1
  105. package/dist/focus-ring.js +2 -0
  106. package/dist/focus-ring.js.map +1 -1
  107. package/dist/{form-associated-D3Tn33s_.js → form-associated-BHbg72PG.js} +3 -1
  108. package/dist/{form-associated-D3Tn33s_.js.map → form-associated-BHbg72PG.js.map} +1 -1
  109. package/dist/{form-submitter-DWwv6K9-.js → form-submitter-beG1CXAn.js} +7 -1
  110. package/dist/{form-submitter-DWwv6K9-.js.map → form-submitter-beG1CXAn.js.map} +1 -1
  111. package/dist/form.js +2 -2
  112. package/dist/{generative-view-DmtpDobn.js → generative-view-BgOcLRXr.js} +13 -13
  113. package/dist/generative-view-BgOcLRXr.js.map +1 -0
  114. package/dist/generative-view.js +3 -3
  115. package/dist/geometry-INg82Lxq.js +305 -0
  116. package/dist/geometry-INg82Lxq.js.map +1 -0
  117. package/dist/history-YbTSQZHj.js +45 -0
  118. package/dist/history-YbTSQZHj.js.map +1 -0
  119. package/dist/host-CZK7xhzh.js +40 -0
  120. package/dist/host-CZK7xhzh.js.map +1 -0
  121. package/dist/html-editor.js +5 -5
  122. package/dist/{hyperlink-DhE9RlVS.js → hyperlink-DycWPKwU.js} +10 -1
  123. package/dist/hyperlink-DycWPKwU.js.map +1 -0
  124. package/dist/{i18n-controller-urcQKYGe.js → i18n-controller-Cp43HjJl.js} +2 -2
  125. package/dist/{i18n-controller-urcQKYGe.js.map → i18n-controller-Cp43HjJl.js.map} +1 -1
  126. package/dist/icon-button.js +4 -4
  127. package/dist/image.js +2 -2
  128. package/dist/index.js +37 -18
  129. package/dist/index.js.map +1 -1
  130. package/dist/inline-edit.js +2 -2
  131. package/dist/input.js +4 -4
  132. package/dist/json-viewer.js +2 -2
  133. package/dist/kanban.js +2 -2
  134. package/dist/kbd.js +2 -2
  135. package/dist/linear-progress.js +3 -3
  136. package/dist/link-button.js +2 -2
  137. package/dist/list-item.js +2 -2
  138. package/dist/list.js +2 -2
  139. package/dist/listbox.js +3 -3
  140. package/dist/loader-full.js +13 -13
  141. package/dist/loader.js +44 -15
  142. package/dist/loader.js.map +1 -1
  143. package/dist/markdown-editor.js +5 -5
  144. package/dist/markers-BFmh1OCz.js +46 -0
  145. package/dist/markers-BFmh1OCz.js.map +1 -0
  146. package/dist/measure-controller-Dmc5hZKg.js +89 -0
  147. package/dist/measure-controller-Dmc5hZKg.js.map +1 -0
  148. package/dist/mention-input.js +6 -5
  149. package/dist/mention-input.js.map +1 -1
  150. package/dist/menu-item.js +3 -2
  151. package/dist/menu-item.js.map +1 -1
  152. package/dist/menu.js +2 -2
  153. package/dist/modal.js +2 -2
  154. package/dist/navigation-bar.js +2 -2
  155. package/dist/navigation-drawer.js +2 -2
  156. package/dist/navigation-rail.js +2 -2
  157. package/dist/notification-center.js +2 -2
  158. package/dist/number-field.js +6 -5
  159. package/dist/number-field.js.map +1 -1
  160. package/dist/option.js +2 -2
  161. package/dist/page-header.js +2 -2
  162. package/dist/pagination.js +2 -2
  163. package/dist/password-field.js +5 -5
  164. package/dist/password-rules.js +2 -2
  165. package/dist/phone-field.js +5 -5
  166. package/dist/{picker-field-B4DtcJfL.js → picker-field-dTlIMAQn.js} +3 -3
  167. package/dist/{picker-field-B4DtcJfL.js.map → picker-field-dTlIMAQn.js.map} +1 -1
  168. package/dist/pin-input.js +5 -5
  169. package/dist/presence-indicator.js +2 -2
  170. package/dist/prompt-input.js +5 -5
  171. package/dist/radio-group.js +1 -0
  172. package/dist/radio-group.js.map +1 -1
  173. package/dist/radio.js +5 -5
  174. package/dist/radio.js.map +1 -1
  175. package/dist/rating.js +5 -4
  176. package/dist/rating.js.map +1 -1
  177. package/dist/redvars-loader.js +2 -2
  178. package/dist/relative-time.js +2 -2
  179. package/dist/resizable-panels.js +2 -2
  180. package/dist/{rich-text-input-DLICqof1.js → rich-text-input-DM_BOzgk.js} +3 -3
  181. package/dist/{rich-text-input-DLICqof1.js.map → rich-text-input-DM_BOzgk.js.map} +1 -1
  182. package/dist/ripple.js +2 -0
  183. package/dist/ripple.js.map +1 -1
  184. package/dist/{schema-hMt-NRLk.js → schema-B8g30A_n.js} +2 -2
  185. package/dist/{schema-hMt-NRLk.js.map → schema-B8g30A_n.js.map} +1 -1
  186. package/dist/search.js +4 -4
  187. package/dist/segmented-button-group.js +1 -1
  188. package/dist/select.js +7 -7
  189. package/dist/side-sheet.js +2 -2
  190. package/dist/signature-pad.js +5 -4
  191. package/dist/signature-pad.js.map +1 -1
  192. package/dist/slider.js +5 -4
  193. package/dist/slider.js.map +1 -1
  194. package/dist/snackbar.js +2 -2
  195. package/dist/sparkline.js +2 -2
  196. package/dist/split-button.js +2 -2
  197. package/dist/src/__internal/diagram/canvas-base.d.ts +105 -0
  198. package/dist/src/__internal/diagram/canvas-link.d.ts +21 -0
  199. package/dist/src/__internal/diagram/geometry.d.ts +49 -0
  200. package/dist/src/__internal/diagram/history.d.ts +17 -0
  201. package/dist/src/__internal/diagram/host.d.ts +45 -0
  202. package/dist/src/__internal/diagram/markers.d.ts +16 -0
  203. package/dist/src/__internal/diagram/measure-controller.d.ts +32 -0
  204. package/dist/src/__internal/diagram/motion.d.ts +22 -0
  205. package/dist/src/__internal/diagram/selection.d.ts +20 -0
  206. package/dist/src/__internal/diagram/types.d.ts +39 -0
  207. package/dist/src/__internal/diagram/viewport-controller.d.ts +89 -0
  208. package/dist/src/__internal/i18n/strings.d.ts +149 -0
  209. package/dist/src/__internal/toggle-base.d.ts +8 -0
  210. package/dist/src/__internal/utils/deprecate.d.ts +3 -3
  211. package/dist/src/accordion/accordion.d.ts +1 -0
  212. package/dist/src/code-editor/code-editor.d.ts +1 -0
  213. package/dist/src/date-picker/date-picker.d.ts +2 -0
  214. package/dist/src/dependency-map/dependency-map-layout.d.ts +48 -0
  215. package/dist/src/dependency-map/dependency-map.d.ts +241 -0
  216. package/dist/src/dependency-map/index.d.ts +2 -0
  217. package/dist/src/diagram/diagram.d.ts +300 -0
  218. package/dist/src/diagram/flow.d.ts +53 -0
  219. package/dist/src/diagram/index.d.ts +4 -0
  220. package/dist/src/diagram-controls/diagram-controls.d.ts +46 -0
  221. package/dist/src/diagram-controls/index.d.ts +1 -0
  222. package/dist/src/diagram-minimap/diagram-minimap.d.ts +39 -0
  223. package/dist/src/diagram-minimap/index.d.ts +1 -0
  224. package/dist/src/erd/erd-layout.d.ts +27 -0
  225. package/dist/src/erd/erd.d.ts +266 -0
  226. package/dist/src/erd/index.d.ts +2 -0
  227. package/dist/src/field/field.d.ts +38 -1
  228. package/dist/src/file-upload/file-upload.d.ts +3 -1
  229. package/dist/src/focus-ring/focus-ring.d.ts +2 -0
  230. package/dist/src/index.d.ts +15 -2
  231. package/dist/src/input/BaseField.d.ts +3 -0
  232. package/dist/src/input/BaseInput.d.ts +3 -0
  233. package/dist/src/menu/menu-item/menu-item.d.ts +1 -0
  234. package/dist/src/number-field/number-field.d.ts +4 -0
  235. package/dist/src/progress/base-progress.d.ts +3 -0
  236. package/dist/src/radio/radio-group.d.ts +1 -0
  237. package/dist/src/rating/rating.d.ts +1 -0
  238. package/dist/src/ripple/ripple.d.ts +2 -0
  239. package/dist/src/signature-pad/signature-pad.d.ts +1 -0
  240. package/dist/src/slider/slider.d.ts +1 -0
  241. package/dist/src/switch/switch.d.ts +1 -0
  242. package/dist/src/tabs/tab.d.ts +2 -0
  243. package/dist/src/tabs/tabs.d.ts +1 -0
  244. package/dist/src/textarea/textarea.d.ts +1 -0
  245. package/dist/src/time-picker/time-picker.d.ts +2 -0
  246. package/dist/src/transfer-list/transfer-list.d.ts +1 -0
  247. package/dist/src/tree-chart/index.d.ts +2 -0
  248. package/dist/src/tree-chart/tree-chart-layout.d.ts +49 -0
  249. package/dist/src/tree-chart/tree-chart.d.ts +221 -0
  250. package/dist/src/workflow/index.d.ts +2 -0
  251. package/dist/src/workflow/workflow-format.d.ts +5 -0
  252. package/dist/src/workflow/workflow-model.d.ts +194 -0
  253. package/dist/src/workflow/workflow.d.ts +313 -0
  254. package/dist/src/workflow-timeline/index.d.ts +1 -0
  255. package/dist/src/workflow-timeline/workflow-timeline.d.ts +41 -0
  256. package/dist/stat.js +2 -2
  257. package/dist/status-indicator.js +2 -2
  258. package/dist/step.js +2 -2
  259. package/dist/stepper.js +2 -2
  260. package/dist/{strings-DmbqMTfs.js → strings-BJPuhKJk.js} +163 -1
  261. package/dist/{strings-DmbqMTfs.js.map → strings-BJPuhKJk.js.map} +1 -1
  262. package/dist/sub-menu.js +2 -2
  263. package/dist/svg.js +2 -2
  264. package/dist/switch.js +5 -4
  265. package/dist/switch.js.map +1 -1
  266. package/dist/tab.js +1 -0
  267. package/dist/tab.js.map +1 -1
  268. package/dist/table.js +2 -2
  269. package/dist/tabs.js +1 -0
  270. package/dist/tabs.js.map +1 -1
  271. package/dist/test/diagram-controls.test.d.ts +1 -0
  272. package/dist/test/diagram-geometry.test.d.ts +1 -0
  273. package/dist/test/diagram.test.d.ts +1 -0
  274. package/dist/test/erd.test.d.ts +1 -0
  275. package/dist/test/toggle-label.test.d.ts +1 -0
  276. package/dist/test/tree-chart.test.d.ts +1 -0
  277. package/dist/test/workflow-debug.test.d.ts +1 -0
  278. package/dist/test/workflow.test.d.ts +1 -0
  279. package/dist/textarea.js +7 -5
  280. package/dist/textarea.js.map +1 -1
  281. package/dist/time-field.js +6 -6
  282. package/dist/time-picker.js +4 -2
  283. package/dist/time-picker.js.map +1 -1
  284. package/dist/timeline-item.js +2 -2
  285. package/dist/timeline.js +2 -2
  286. package/dist/{toggle-base-BQO5pjrU.js → toggle-base-BlaHalfS.js} +19 -3
  287. package/dist/toggle-base-BlaHalfS.js.map +1 -0
  288. package/dist/tour.js +2 -2
  289. package/dist/transfer-list.js +5 -4
  290. package/dist/transfer-list.js.map +1 -1
  291. package/dist/{chart-base-B-gOg2Di.js → transform-CxeQFXXB.js} +9 -839
  292. package/dist/transform-CxeQFXXB.js.map +1 -0
  293. package/dist/tree-chart.js +1986 -0
  294. package/dist/tree-chart.js.map +1 -0
  295. package/dist/tree-item.js +2 -2
  296. package/dist/tree.js +2 -2
  297. package/dist/tsconfig.tsbuildinfo +1 -1
  298. package/dist/typing-indicator.js +2 -2
  299. package/dist/url-field.js +5 -5
  300. package/dist/user-menu.js +2 -2
  301. package/dist/virtual-list.js +2 -2
  302. package/dist/workflow-format-BsyveyeC.js +34 -0
  303. package/dist/workflow-format-BsyveyeC.js.map +1 -0
  304. package/dist/workflow-model-CauduOG2.js +330 -0
  305. package/dist/workflow-model-CauduOG2.js.map +1 -0
  306. package/dist/workflow-timeline.js +354 -0
  307. package/dist/workflow-timeline.js.map +1 -0
  308. package/dist/workflow.js +3337 -0
  309. package/dist/workflow.js.map +1 -0
  310. package/dist/workspace-switcher.js +2 -2
  311. package/package.json +1 -1
  312. package/readme.md +44 -2
  313. package/src/LoaderUtils.ts +9 -2
  314. package/src/__internal/diagram/canvas-base.ts +410 -0
  315. package/src/__internal/diagram/canvas-link.ts +66 -0
  316. package/src/__internal/diagram/geometry.ts +372 -0
  317. package/src/__internal/diagram/history.ts +49 -0
  318. package/src/__internal/diagram/host.ts +76 -0
  319. package/src/__internal/diagram/markers.ts +56 -0
  320. package/src/__internal/diagram/measure-controller.ts +104 -0
  321. package/src/__internal/diagram/motion.ts +89 -0
  322. package/src/__internal/diagram/selection.ts +69 -0
  323. package/src/__internal/diagram/types.ts +56 -0
  324. package/src/__internal/diagram/viewport-controller.ts +494 -0
  325. package/src/__internal/i18n/strings.ts +201 -0
  326. package/src/__internal/mixins/field.ts +3 -0
  327. package/src/__internal/mixins/form-associated.ts +2 -0
  328. package/src/__internal/mixins/form-submitter.ts +6 -0
  329. package/src/__internal/mixins/hyperlink.ts +10 -0
  330. package/src/__internal/toggle-base.ts +16 -0
  331. package/src/__internal/utils/deprecate.ts +5 -4
  332. package/src/accordion/accordion.ts +1 -0
  333. package/src/button/base-button/base-button.ts +2 -0
  334. package/src/code-editor/code-editor.ts +1 -0
  335. package/src/date-picker/date-picker.ts +2 -0
  336. package/src/dependency-map/dependency-map-layout.ts +505 -0
  337. package/src/dependency-map/dependency-map.scss +626 -0
  338. package/src/dependency-map/dependency-map.ts +1280 -0
  339. package/src/dependency-map/index.ts +16 -0
  340. package/src/diagram/diagram.scss +513 -0
  341. package/src/diagram/diagram.ts +1852 -0
  342. package/src/diagram/flow.ts +81 -0
  343. package/src/diagram/index.ts +44 -0
  344. package/src/diagram-controls/diagram-controls.scss +68 -0
  345. package/src/diagram-controls/diagram-controls.ts +255 -0
  346. package/src/diagram-controls/index.ts +1 -0
  347. package/src/diagram-minimap/diagram-minimap.scss +41 -0
  348. package/src/diagram-minimap/diagram-minimap.ts +149 -0
  349. package/src/diagram-minimap/index.ts +1 -0
  350. package/src/erd/erd-layout.ts +92 -0
  351. package/src/erd/erd.scss +636 -0
  352. package/src/erd/erd.ts +1728 -0
  353. package/src/erd/index.ts +17 -0
  354. package/src/field/field.scss +197 -23
  355. package/src/field/field.ts +109 -16
  356. package/src/file-upload/file-upload.scss +37 -10
  357. package/src/file-upload/file-upload.ts +3 -1
  358. package/src/focus-ring/focus-ring.ts +2 -0
  359. package/src/generative-view/catalog.generated.ts +12 -11
  360. package/src/index.ts +121 -2
  361. package/src/input/BaseField.ts +3 -0
  362. package/src/input/BaseInput.ts +3 -0
  363. package/src/loader.ts +25 -0
  364. package/src/mention-input/mention-input.scss +2 -0
  365. package/src/menu/menu-item/menu-item.ts +1 -0
  366. package/src/number-field/number-field.ts +4 -0
  367. package/src/progress/base-progress.ts +3 -0
  368. package/src/radio/radio-group.ts +1 -0
  369. package/src/radio/radio.ts +1 -1
  370. package/src/rating/rating.ts +1 -0
  371. package/src/ripple/ripple.ts +2 -0
  372. package/src/signature-pad/signature-pad.ts +1 -0
  373. package/src/slider/slider.ts +1 -0
  374. package/src/switch/switch.ts +1 -0
  375. package/src/tabs/tab.ts +2 -0
  376. package/src/tabs/tabs.ts +1 -0
  377. package/src/textarea/textarea.scss +2 -0
  378. package/src/textarea/textarea.ts +1 -0
  379. package/src/time-picker/time-picker.ts +2 -0
  380. package/src/transfer-list/transfer-list.ts +1 -0
  381. package/src/tree-chart/index.ts +13 -0
  382. package/src/tree-chart/tree-chart-layout.ts +185 -0
  383. package/src/tree-chart/tree-chart.scss +377 -0
  384. package/src/tree-chart/tree-chart.ts +1170 -0
  385. package/src/workflow/index.ts +35 -0
  386. package/src/workflow/workflow-format.ts +29 -0
  387. package/src/workflow/workflow-model.ts +583 -0
  388. package/src/workflow/workflow.scss +1164 -0
  389. package/src/workflow/workflow.ts +2674 -0
  390. package/src/workflow-timeline/index.ts +1 -0
  391. package/src/workflow-timeline/workflow-timeline.scss +128 -0
  392. package/src/workflow-timeline/workflow-timeline.ts +238 -0
  393. package/dist/BaseField-CAog9TIc.js.map +0 -1
  394. package/dist/BaseInput-CcMfg1Y2.js.map +0 -1
  395. package/dist/base-button-Do2TUy8M.js.map +0 -1
  396. package/dist/base-progress-BiLlZVHJ.js.map +0 -1
  397. package/dist/cartesian-chart-C-f1frt0.js.map +0 -1
  398. package/dist/chart-base-B-gOg2Di.js.map +0 -1
  399. package/dist/generative-view-DmtpDobn.js.map +0 -1
  400. package/dist/hyperlink-DhE9RlVS.js.map +0 -1
  401. package/dist/src/flow/flow.d.ts +0 -178
  402. package/dist/src/flow/index.d.ts +0 -2
  403. package/dist/toggle-base-BQO5pjrU.js.map +0 -1
  404. package/src/button/button-group/readme.md +0 -23
  405. package/src/flow/flow.scss +0 -215
  406. package/src/flow/flow.ts +0 -958
  407. package/src/flow/index.ts +0 -10
  408. /package/dist/test/{flow.test.d.ts → dependency-map.test.d.ts} +0 -0
package/src/erd/erd.ts ADDED
@@ -0,0 +1,1728 @@
1
+ import { html, nothing, svg, type PropertyValues } from 'lit';
2
+ import { property, query, state } from 'lit/decorators.js';
3
+ import { classMap } from 'lit/directives/class-map.js';
4
+ import { repeat } from 'lit/directives/repeat.js';
5
+ import IndividualComponent from '@/IndividualComponent.js';
6
+ import { DiagramCanvasElement } from '@/__internal/diagram/canvas-base.js';
7
+ import {
8
+ boundsOf,
9
+ edgeGeometry,
10
+ inflateRect,
11
+ nearestInDirection,
12
+ polylineMidpoint,
13
+ roundedPath,
14
+ type EdgeGeometry,
15
+ } from '@/__internal/diagram/geometry.js';
16
+ import { markerShapes, markerTransform } from '@/__internal/diagram/markers.js';
17
+ import { History } from '@/__internal/diagram/history.js';
18
+ import {
19
+ animateOut,
20
+ easeInOutCubic,
21
+ prefersReducedMotion,
22
+ tween,
23
+ } from '@/__internal/diagram/motion.js';
24
+ import type { DiagramOverview } from '@/__internal/diagram/host.js';
25
+ import type {
26
+ DiagramPoint,
27
+ DiagramRect,
28
+ DiagramSide,
29
+ DiagramViewportDetail,
30
+ } from '@/__internal/diagram/types.js';
31
+ import { withinHops } from '@/dependency-map/dependency-map-layout.js';
32
+ import { layoutEntities } from './erd-layout.js';
33
+ import styles from './erd.scss';
34
+
35
+ /** Crow's-foot cardinality at one end of a relation. */
36
+ export type ErdCardinality =
37
+ | 'one'
38
+ | 'zero-or-one'
39
+ | 'many'
40
+ | 'one-or-many'
41
+ | 'zero-or-many';
42
+
43
+ export type ErdAccent =
44
+ | 'primary'
45
+ | 'tertiary'
46
+ | 'blue'
47
+ | 'green'
48
+ | 'orange'
49
+ | 'purple'
50
+ | 'red'
51
+ | 'yellow'
52
+ | 'neutral';
53
+
54
+ export interface ErdColumn {
55
+ name: string;
56
+ /** The data type, for example `uuid` or `varchar(120)`. */
57
+ type?: string;
58
+ /** Part of the primary key. */
59
+ pk?: boolean;
60
+ nullable?: boolean;
61
+ unique?: boolean;
62
+ /** Shown as the row's tooltip. */
63
+ comment?: string;
64
+ }
65
+
66
+ /** A table, view or other entity. */
67
+ export interface ErdEntity {
68
+ id: string;
69
+ name: string;
70
+ /** Shown before the name, and what the `schema` filter matches. */
71
+ schema?: string;
72
+ /** Material Symbols name for the header tile. Defaults to `table`. */
73
+ icon?: string;
74
+ accent?: ErdAccent;
75
+ columns: ErdColumn[];
76
+ /** Starts collapsed to its header. */
77
+ collapsed?: boolean;
78
+ /** A fixed top-left corner, in canvas pixels. Entities without one are laid out automatically. */
79
+ position?: DiagramPoint;
80
+ comment?: string;
81
+ }
82
+
83
+ /**
84
+ * A reference from `source` (the entity holding the foreign key) to `target` (the entity it
85
+ * references). With column names the line joins those rows; without, the headers.
86
+ */
87
+ export interface ErdRelation {
88
+ id: string;
89
+ source: string;
90
+ sourceColumn?: string;
91
+ target: string;
92
+ targetColumn?: string;
93
+ /** How many `source` rows point at one `target` row. Defaults to `many`. */
94
+ sourceCardinality?: ErdCardinality;
95
+ /** How many `target` rows one `source` row points at. Defaults to `one`. */
96
+ targetCardinality?: ErdCardinality;
97
+ label?: string;
98
+ }
99
+
100
+ export type ErdChangeReason =
101
+ | 'move'
102
+ | 'rename'
103
+ | 'entity-add'
104
+ | 'column-add'
105
+ | 'column-remove'
106
+ | 'column-update'
107
+ | 'connect'
108
+ | 'cardinality'
109
+ | 'delete'
110
+ | 'undo'
111
+ | 'redo';
112
+
113
+ /** Detail of `select`. */
114
+ export interface ErdSelectDetail {
115
+ id: string;
116
+ kind: 'entity' | 'relation';
117
+ entity?: ErdEntity;
118
+ relation?: ErdRelation;
119
+ }
120
+
121
+ /** Detail of `entity-move`. */
122
+ export interface ErdMoveDetail {
123
+ id: string;
124
+ position: DiagramPoint;
125
+ }
126
+
127
+ /** Detail of `toggle`. */
128
+ export interface ErdToggleDetail {
129
+ id: string;
130
+ collapsed: boolean;
131
+ }
132
+
133
+ /** Detail of `connect`. Cancel it to keep the relation from being added. */
134
+ export interface ErdConnectDetail {
135
+ relation: ErdRelation;
136
+ }
137
+
138
+ /** Detail of `delete`. Cancel it to keep the items. */
139
+ export interface ErdDeleteDetail {
140
+ entities: string[];
141
+ relations: string[];
142
+ }
143
+
144
+ /** Detail of `change`. */
145
+ export interface ErdChangeDetail {
146
+ entities: ErdEntity[];
147
+ relations: ErdRelation[];
148
+ reason: ErdChangeReason;
149
+ }
150
+
151
+ /** Detail of `focus-change`. */
152
+ export interface ErdFocusDetail {
153
+ id: string | null;
154
+ hops: number;
155
+ }
156
+
157
+ /** Detail of `viewport-change`. */
158
+ export type ErdViewportDetail = DiagramViewportDetail;
159
+
160
+ interface ErdSnapshot {
161
+ entities: ErdEntity[];
162
+ relations: ErdRelation[];
163
+ }
164
+
165
+ interface RowRef {
166
+ entity: string;
167
+ column?: string;
168
+ }
169
+
170
+ /** Fixed sizes, so relations can be routed to rows without measuring. */
171
+ const WIDTH = 264;
172
+ const BORDER = 1;
173
+ const HEADER = 48;
174
+ const ROW = 28;
175
+ /** Space above the first row and below the last. */
176
+ const ROWS_PADDING = 4;
177
+ const ADD_ROW = 32;
178
+
179
+ const DRAG_THRESHOLD = 4;
180
+
181
+ const INTERACTIVE = 'button, a, input, wc-icon-button';
182
+
183
+ /** Below this zoom, rows are drawn as bars. */
184
+ const FAR_ZOOM = 0.4;
185
+
186
+ const CARDINALITY_PRESETS: {
187
+ key:
188
+ | 'erdManyToOne'
189
+ | 'erdZeroOrManyToOne'
190
+ | 'erdOneToOne'
191
+ | 'erdZeroOrOneToOne'
192
+ | 'erdManyToMany';
193
+ source: ErdCardinality;
194
+ target: ErdCardinality;
195
+ }[] = [
196
+ { key: 'erdManyToOne', source: 'many', target: 'one' },
197
+ { key: 'erdZeroOrManyToOne', source: 'zero-or-many', target: 'one' },
198
+ { key: 'erdOneToOne', source: 'one', target: 'one' },
199
+ { key: 'erdZeroOrOneToOne', source: 'zero-or-one', target: 'one' },
200
+ { key: 'erdManyToMany', source: 'many', target: 'many' },
201
+ ];
202
+
203
+ let relationCounter = 0;
204
+
205
+ /**
206
+ * @label ERD
207
+ * @tag wc-erd
208
+ * @rawTag erd
209
+ * @summary An entity-relationship diagram: tables with their columns, joined by crow's-foot relations.
210
+ *
211
+ * @overview
212
+ * <p>Set <code>entities</code> (each with <code>columns</code>) and <code>relations</code>. A relation
213
+ * runs from the entity holding the foreign key (<code>source</code>, <code>sourceColumn</code>) to the
214
+ * one it references (<code>target</code>, <code>targetColumn</code>), and its ends show crow's-foot
215
+ * cardinality (many to one by default). Lines join the column rows and route at right angles. Primary
216
+ * keys show a key, foreign keys a link. Hover an entity or a column to highlight what it is joined to.</p>
217
+ * <p>Entities without a <code>position</code> are laid out automatically: referenced tables to the left
218
+ * of the tables that reference them. Collapse an entity to its header with the chevron (or Shift+Enter);
219
+ * the layout closes the gap. <code>schema</code> shows one schema, and <code>focused-node</code> with
220
+ * <code>hops</code> shows one entity's neighbourhood (press F on an entity). Zoomed far out, rows
221
+ * become bars.</p>
222
+ * <p>With <code>editable</code>: double-click a name or type to rename it (F2 on an entity), add and
223
+ * remove columns, click a row's key to toggle the primary key, drag the ring at a row's end onto
224
+ * another row to add a relation and pick its cardinality, and delete with Delete. Every edit fires
225
+ * <code>change</code> with the new <code>entities</code> and <code>relations</code>; undo with Ctrl+Z.</p>
226
+ * <p>Entities are one tab stop: arrow keys move to the nearest entity in that direction, Enter selects.
227
+ * The canvas is infinite like <code>wc-diagram</code>, with the <code>controls</code> and
228
+ * <code>minimap</code> slots.</p>
229
+ *
230
+ * @example
231
+ * ```html
232
+ * <wc-erd id="schema" style="height: 480px"></wc-erd>
233
+ * <script>
234
+ * const erd = document.getElementById('schema');
235
+ * erd.entities = [
236
+ * { id: 'customers', name: 'customers', columns: [
237
+ * { name: 'id', type: 'uuid', pk: true }, { name: 'email', type: 'text' }] },
238
+ * { id: 'orders', name: 'orders', columns: [
239
+ * { name: 'id', type: 'uuid', pk: true }, { name: 'customer_id', type: 'uuid' }] }
240
+ * ];
241
+ * erd.relations = [
242
+ * { id: 'r1', source: 'orders', sourceColumn: 'customer_id', target: 'customers', targetColumn: 'id' }
243
+ * ];
244
+ * </script>
245
+ * ```
246
+ *
247
+ * @slot controls - A `wc-diagram-controls`, shown at the bottom start corner.
248
+ * @slot minimap - A `wc-diagram-minimap`, shown at the bottom end corner.
249
+ *
250
+ * @fires {CustomEvent<ErdSelectDetail>} select - An entity or relation was chosen. Detail contains `{ id, kind, entity, relation }`.
251
+ * @fires {CustomEvent<ErdMoveDetail>} entity-move - A dragged entity was dropped. Detail contains `{ id, position }`.
252
+ * @fires {CustomEvent<ErdToggleDetail>} toggle - An entity was collapsed or expanded. Detail contains `{ id, collapsed }`.
253
+ * @fires {CustomEvent<ErdConnectDetail>} connect - A relation is about to be added by dragging. Cancelable. Detail contains `{ relation }`.
254
+ * @fires {CustomEvent<ErdDeleteDetail>} delete - Entities or relations are about to be deleted. Cancelable. Detail contains `{ entities, relations }`.
255
+ * @fires {CustomEvent<ErdChangeDetail>} change - An edit was made. Detail contains `{ entities, relations, reason }`.
256
+ * @fires {CustomEvent<ErdFocusDetail>} focus-change - Focus mode was turned on or off with the keyboard. Detail contains `{ id, hops }`.
257
+ * @fires {CustomEvent<ErdViewportDetail>} viewport-change - Once per frame while the camera moves and once when it settles. Detail contains `{ x, y, zoom, settled }`.
258
+ *
259
+ * @cssprop --erd-relation-color - Colour of relations. Defaults to outline.
260
+ * @cssprop --erd-highlight-color - Colour of highlighted relations and rows. Defaults to primary.
261
+ * @cssprop --erd-background - Canvas background. Defaults to surface-container-lowest.
262
+ * @tags data
263
+ */
264
+ @IndividualComponent
265
+ export class Erd extends DiagramCanvasElement {
266
+ // ── Static
267
+
268
+ static styles = [styles];
269
+
270
+ // ── Properties
271
+
272
+ @property({ attribute: false })
273
+ entities: ErdEntity[] = [];
274
+
275
+ @property({ attribute: false })
276
+ relations: ErdRelation[] = [];
277
+
278
+ /** Shows only the entities of this schema. */
279
+ @property({ type: String, reflect: true })
280
+ schema = '';
281
+
282
+ /** Shows only the entities within `hops` relations of this entity. */
283
+ @property({ type: String, reflect: true, attribute: 'focused-node' })
284
+ focusedNode = '';
285
+
286
+ /** How far focus mode reaches. */
287
+ @property({ type: Number, reflect: true })
288
+ hops = 1;
289
+
290
+ /** Id of the selected entity or relation. */
291
+ @property({ type: String, reflect: true })
292
+ selected = '';
293
+
294
+ // ── State
295
+
296
+ @state()
297
+ private _collapsed = new Set<string>();
298
+
299
+ @state()
300
+ private _hover?: RowRef;
301
+
302
+ @state()
303
+ private _focusId = '';
304
+
305
+ @state()
306
+ private _editing?: {
307
+ entity: string;
308
+ column?: number;
309
+ field: 'name' | 'type';
310
+ };
311
+
312
+ @state()
313
+ private _picker?: { id: string; x: number; y: number };
314
+
315
+ @state()
316
+ private _connecting?: {
317
+ from: RowRef;
318
+ start: DiagramPoint;
319
+ side: DiagramSide;
320
+ pointer: DiagramPoint;
321
+ };
322
+
323
+ @state()
324
+ private _announcement = '';
325
+
326
+ @state()
327
+ private _fresh = new Set<string>();
328
+
329
+ // ── Private fields
330
+
331
+ @query('.erd-viewport')
332
+ private readonly _viewportEl?: HTMLElement;
333
+
334
+ private readonly history = new History<ErdSnapshot>();
335
+
336
+ private visible: ErdEntity[] = [];
337
+
338
+ private visibleIds = new Set<string>();
339
+
340
+ private byId = new Map<string, ErdEntity>();
341
+
342
+ private positions = new Map<string, DiagramPoint>();
343
+
344
+ private overrides = new Map<string, DiagramPoint>();
345
+
346
+ private pinned = new Map<string, DiagramPoint>();
347
+
348
+ private layoutKey = '';
349
+
350
+ private seen = new Set<string>();
351
+
352
+ private stopGlide?: () => void;
353
+
354
+ private drag?: {
355
+ pointerId: number;
356
+ startX: number;
357
+ startY: number;
358
+ id: string;
359
+ origin: DiagramPoint;
360
+ element: HTMLElement;
361
+ moved: boolean;
362
+ };
363
+
364
+ // ── Lifecycle
365
+
366
+ disconnectedCallback() {
367
+ super.disconnectedCallback();
368
+ this.stopGlide?.();
369
+ }
370
+
371
+ protected willUpdate(changed: PropertyValues<this>) {
372
+ super.willUpdate(changed);
373
+ if (changed.has('entities')) {
374
+ let next: Set<string> | undefined;
375
+ for (const e of this.entities) {
376
+ if (!this.seen.has(e.id)) {
377
+ this.seen.add(e.id);
378
+ if (e.collapsed) {
379
+ next = next ?? new Set(this._collapsed);
380
+ next.add(e.id);
381
+ }
382
+ }
383
+ if (e.position) this.pinned.set(e.id, e.position);
384
+ }
385
+ if (next) this._collapsed = next;
386
+ this.byId = new Map(this.entities.map(e => [e.id, e]));
387
+ }
388
+ if (
389
+ (
390
+ [
391
+ 'entities',
392
+ 'relations',
393
+ 'schema',
394
+ 'focusedNode',
395
+ 'hops',
396
+ 'editable',
397
+ '_collapsed',
398
+ ] as (keyof Erd)[]
399
+ ).some(k => changed.has(k))
400
+ ) {
401
+ this.computeVisible();
402
+ this.runLayout();
403
+ }
404
+ }
405
+
406
+ protected updated(changed: PropertyValues<this>) {
407
+ super.updated(changed);
408
+ if (changed.has('_editing' as keyof Erd) && this._editing) {
409
+ const input =
410
+ this.renderRoot.querySelector<HTMLInputElement>('.erd-input');
411
+ input?.focus();
412
+ input?.select();
413
+ }
414
+ }
415
+
416
+ // ── Public API
417
+
418
+ get canUndo(): boolean {
419
+ return this.editable && !this.readonly && this.history.canUndo;
420
+ }
421
+
422
+ get canRedo(): boolean {
423
+ return this.editable && !this.readonly && this.history.canRedo;
424
+ }
425
+
426
+ undo() {
427
+ if (!this.canUndo) return;
428
+ const previous = this.history.undo(this.snapshot());
429
+ if (previous) this.restore(previous, 'undo');
430
+ }
431
+
432
+ redo() {
433
+ if (!this.canRedo) return;
434
+ const next = this.history.redo(this.snapshot());
435
+ if (next) this.restore(next, 'redo');
436
+ }
437
+
438
+ /** Lays every entity out again, forgetting dragged and given positions. */
439
+ autoLayout() {
440
+ this.pinned.clear();
441
+ this.layoutKey = '';
442
+ this.runLayout();
443
+ this.requestUpdate();
444
+ }
445
+
446
+ collapse(id: string) {
447
+ this.toggle(id, true);
448
+ }
449
+
450
+ expand(id: string) {
451
+ this.toggle(id, false);
452
+ }
453
+
454
+ collapseAll() {
455
+ this._collapsed = new Set(this.entities.map(e => e.id));
456
+ }
457
+
458
+ expandAll() {
459
+ this._collapsed = new Set();
460
+ }
461
+
462
+ /** Selects an entity as a click would and brings it into view. */
463
+ selectEntity(id: string) {
464
+ const entity = this.byId.get(id);
465
+ if (!entity || !this.visibleIds.has(id)) return;
466
+ this.selectItem(id);
467
+ this.moveFocusTo(id);
468
+ }
469
+
470
+ /** Adds an entity at the centre of the view (or at its `position`) and starts renaming it. */
471
+ addEntity(entity: Partial<ErdEntity> = {}) {
472
+ const view = this.viewport.visibleRect();
473
+ const id = entity.id ?? this.uniqueId('entity');
474
+ const created: ErdEntity = {
475
+ name: this.i18n.t('erdNewEntity'),
476
+ columns: [{ name: 'id', type: 'uuid', pk: true }],
477
+ ...entity,
478
+ id,
479
+ position: entity.position ?? {
480
+ x: Math.round(view.x + view.width / 2 - WIDTH / 2),
481
+ y: Math.round(view.y + view.height / 2 - 60),
482
+ },
483
+ };
484
+ this.markFresh(id);
485
+ this.commit([...this.entities, created], this.relations, 'entity-add');
486
+ if (this.editable) this._editing = { entity: id, field: 'name' };
487
+ this._focusId = id;
488
+ return created;
489
+ }
490
+
491
+ /** Adds a relation as a drag would, firing the cancelable `connect` first. Returns whether it was added. */
492
+ addRelation(relation: Omit<ErdRelation, 'id'> & { id?: string }): boolean {
493
+ const created: ErdRelation = {
494
+ sourceCardinality: 'many',
495
+ targetCardinality: 'one',
496
+ ...relation,
497
+ id: relation.id ?? this.uniqueId('relation'),
498
+ };
499
+ if (!this.emit<ErdConnectDetail>('connect', { relation: created }, true))
500
+ return false;
501
+ this.markFresh(created.id);
502
+ this.commit(this.entities, [...this.relations, created], 'connect');
503
+ const name = (r: RowRef) => {
504
+ const e = this.byId.get(r.entity);
505
+ return r.column ? `${e?.name}.${r.column}` : (e?.name ?? r.entity);
506
+ };
507
+ this.announce(
508
+ this.i18n.t('erdConnected')(
509
+ name({ entity: created.source, column: created.sourceColumn }),
510
+ name({ entity: created.target, column: created.targetColumn }),
511
+ ),
512
+ );
513
+ return true;
514
+ }
515
+
516
+ /** Deletes entities (with their relations) and relations, firing the cancelable `delete` first. */
517
+ deleteItems(ids: string[]) {
518
+ const entityIds = ids.filter(id => this.byId.has(id));
519
+ const relationIds = new Set(
520
+ ids.filter(id => this.relations.some(r => r.id === id)),
521
+ );
522
+ for (const r of this.relations) {
523
+ if (entityIds.includes(r.source) || entityIds.includes(r.target))
524
+ relationIds.add(r.id);
525
+ }
526
+ if (!entityIds.length && !relationIds.size) return;
527
+ const detail = { entities: entityIds, relations: [...relationIds] };
528
+ if (!this.emit<ErdDeleteDetail>('delete', detail, true)) return;
529
+ const apply = () => {
530
+ if (this.selected && ids.includes(this.selected)) this.selected = '';
531
+ this.commit(
532
+ this.entities.filter(e => !entityIds.includes(e.id)),
533
+ this.relations.filter(r => !relationIds.has(r.id)),
534
+ 'delete',
535
+ );
536
+ };
537
+ const elements = entityIds
538
+ .map(id => this.entityElement(id))
539
+ .filter((el): el is HTMLElement => !!el);
540
+ animateOut(elements, apply);
541
+ }
542
+
543
+ // ── Canvas hooks
544
+
545
+ protected viewportElement() {
546
+ return this._viewportEl;
547
+ }
548
+
549
+ protected contentBounds(): DiagramRect | undefined {
550
+ return boundsOf(this.visible.map(e => this.rectOf(e.id)));
551
+ }
552
+
553
+ protected selectionRects(): DiagramRect[] {
554
+ if (this.visibleIds.has(this.selected)) return [this.rectOf(this.selected)];
555
+ const r = this.relations.find(x => x.id === this.selected);
556
+ return r && this.visibleIds.has(r.source) && this.visibleIds.has(r.target)
557
+ ? [this.rectOf(r.source), this.rectOf(r.target)]
558
+ : [];
559
+ }
560
+
561
+ protected itemRect(id: string): DiagramRect | undefined {
562
+ return this.visibleIds.has(id) ? this.rectOf(id) : undefined;
563
+ }
564
+
565
+ protected firstItemRect(): DiagramRect | undefined {
566
+ const first = this.visible[0];
567
+ return first ? this.rectOf(first.id) : undefined;
568
+ }
569
+
570
+ protected overviewItems(): DiagramOverview['items'] {
571
+ return this.visible.map(e => ({
572
+ ...this.rectOf(e.id),
573
+ selected: e.id === this.selected,
574
+ }));
575
+ }
576
+
577
+ protected isBackground(target: EventTarget | null): boolean {
578
+ const el = target as Element | null;
579
+ if (!el) return false;
580
+ return (
581
+ el === this._viewportEl ||
582
+ ['erd-world', 'erd-relations', 'erd-entities'].some(c =>
583
+ el.classList?.contains(c),
584
+ )
585
+ );
586
+ }
587
+
588
+ protected onBackgroundClick() {
589
+ this.selected = '';
590
+ this._picker = undefined;
591
+ }
592
+
593
+ // ── Private methods: model
594
+
595
+ private snapshot(): ErdSnapshot {
596
+ return { entities: this.entities, relations: this.relations };
597
+ }
598
+
599
+ private restore(s: ErdSnapshot, reason: ErdChangeReason) {
600
+ this.entities = s.entities;
601
+ this.relations = s.relations;
602
+ this.emit<ErdChangeDetail>('change', { ...s, reason });
603
+ }
604
+
605
+ private commit(
606
+ entities: ErdEntity[],
607
+ relations: ErdRelation[],
608
+ reason: ErdChangeReason,
609
+ ) {
610
+ this.history.push(this.snapshot());
611
+ this.entities = entities;
612
+ this.relations = relations;
613
+ this.emit<ErdChangeDetail>('change', { entities, relations, reason });
614
+ }
615
+
616
+ private updateEntity(
617
+ id: string,
618
+ update: (e: ErdEntity) => ErdEntity,
619
+ reason: ErdChangeReason,
620
+ ) {
621
+ this.commit(
622
+ this.entities.map(e => (e.id === id ? update(e) : e)),
623
+ this.relations,
624
+ reason,
625
+ );
626
+ }
627
+
628
+ private uniqueId(prefix: string) {
629
+ relationCounter += 1;
630
+ const taken = new Set([
631
+ ...this.entities.map(e => e.id),
632
+ ...this.relations.map(r => r.id),
633
+ ]);
634
+ let id = `${prefix}-${relationCounter}`;
635
+ while (taken.has(id)) {
636
+ relationCounter += 1;
637
+ id = `${prefix}-${relationCounter}`;
638
+ }
639
+ return id;
640
+ }
641
+
642
+ private markFresh(id: string) {
643
+ if (prefersReducedMotion()) return;
644
+ this._fresh = new Set([...this._fresh, id]);
645
+ setTimeout(() => {
646
+ const next = new Set(this._fresh);
647
+ next.delete(id);
648
+ this._fresh = next;
649
+ }, 600);
650
+ }
651
+
652
+ private computeVisible() {
653
+ let shown = this.entities.filter(
654
+ e => !this.schema || e.schema === this.schema,
655
+ );
656
+ const ids = new Set(shown.map(e => e.id));
657
+ if (this.focusedNode && ids.has(this.focusedNode)) {
658
+ const near = withinHops(
659
+ this.focusedNode,
660
+ this.relations.filter(r => ids.has(r.source) && ids.has(r.target)),
661
+ this.hops,
662
+ );
663
+ shown = shown.filter(e => near.has(e.id));
664
+ }
665
+ this.visible = shown;
666
+ this.visibleIds = new Set(shown.map(e => e.id));
667
+ if (this.visibleIds.size && !this.visibleIds.has(this.selected)) {
668
+ if (!this.relations.some(r => r.id === this.selected)) this.selected = '';
669
+ }
670
+ }
671
+
672
+ private heightOf(e: ErdEntity): number {
673
+ const frame = HEADER + BORDER * 2;
674
+ if (this._collapsed.has(e.id)) return frame;
675
+ return (
676
+ frame +
677
+ e.columns.length * ROW +
678
+ ROWS_PADDING * 2 +
679
+ (this.editable && !this.readonly ? ADD_ROW : 0)
680
+ );
681
+ }
682
+
683
+ private runLayout() {
684
+ const relations = this.relations.filter(
685
+ r => this.visibleIds.has(r.source) && this.visibleIds.has(r.target),
686
+ );
687
+ const key = [
688
+ this.visible
689
+ .map(
690
+ e =>
691
+ `${e.id}:${this.heightOf(e)}:${this.pinned.has(e.id) ? 'p' : ''}`,
692
+ )
693
+ .join(','),
694
+ relations.map(r => `${r.source}>${r.target}`).join(','),
695
+ ].join('|');
696
+ if (key === this.layoutKey) return;
697
+ this.layoutKey = key;
698
+ const next = layoutEntities(
699
+ this.visible.map(e => ({
700
+ id: e.id,
701
+ height: this.heightOf(e),
702
+ pinned: this.pinned.get(e.id),
703
+ })),
704
+ relations,
705
+ { width: WIDTH },
706
+ );
707
+ this.glide(this.positions, next);
708
+ this.positions = next;
709
+ }
710
+
711
+ private glide(
712
+ from: Map<string, DiagramPoint>,
713
+ to: Map<string, DiagramPoint>,
714
+ ) {
715
+ this.stopGlide?.();
716
+ this.overrides.clear();
717
+ if (!from.size || prefersReducedMotion() || !this.startApplied) return;
718
+ const moving = [...to].filter(([id, p]) => {
719
+ const f = from.get(id);
720
+ return f && (f.x !== p.x || f.y !== p.y);
721
+ });
722
+ if (!moving.length) return;
723
+ this.stopGlide = tween({
724
+ duration: 400,
725
+ easing: easeInOutCubic,
726
+ onUpdate: t => {
727
+ for (const [id, p] of moving) {
728
+ const f = from.get(id) ?? p;
729
+ this.overrides.set(id, {
730
+ x: f.x + (p.x - f.x) * t,
731
+ y: f.y + (p.y - f.y) * t,
732
+ });
733
+ }
734
+ this.requestUpdate();
735
+ },
736
+ onDone: () => {
737
+ this.overrides.clear();
738
+ this.stopGlide = undefined;
739
+ this.requestUpdate();
740
+ },
741
+ });
742
+ }
743
+
744
+ private topLeft(id: string): DiagramPoint {
745
+ return this.overrides.get(id) ?? this.positions.get(id) ?? { x: 0, y: 0 };
746
+ }
747
+
748
+ private rectOf(id: string): DiagramRect {
749
+ const p = this.topLeft(id);
750
+ const e = this.byId.get(id);
751
+ return {
752
+ x: p.x,
753
+ y: p.y,
754
+ width: WIDTH,
755
+ height: e ? this.heightOf(e) : HEADER,
756
+ };
757
+ }
758
+
759
+ /** The y of a column row's middle, or the header's when the row is hidden or missing. */
760
+ private rowY(entity: ErdEntity, column?: string): number {
761
+ const top = this.topLeft(entity.id).y + BORDER;
762
+ const index = column
763
+ ? entity.columns.findIndex(c => c.name === column)
764
+ : -1;
765
+ if (index < 0 || this._collapsed.has(entity.id)) return top + HEADER / 2;
766
+ return top + HEADER + ROWS_PADDING + index * ROW + ROW / 2;
767
+ }
768
+
769
+ private foreignKeys(entityId: string): Set<string> {
770
+ const out = new Set<string>();
771
+ for (const r of this.relations)
772
+ if (r.source === entityId && r.sourceColumn) out.add(r.sourceColumn);
773
+ return out;
774
+ }
775
+
776
+ private related(id: string): {
777
+ references: string[];
778
+ referencedBy: string[];
779
+ } {
780
+ const name = (x: string) => this.byId.get(x)?.name ?? x;
781
+ return {
782
+ references: [
783
+ ...new Set(
784
+ this.relations.filter(r => r.source === id).map(r => name(r.target)),
785
+ ),
786
+ ],
787
+ referencedBy: [
788
+ ...new Set(
789
+ this.relations.filter(r => r.target === id).map(r => name(r.source)),
790
+ ),
791
+ ],
792
+ };
793
+ }
794
+
795
+ /** Relations and rows lit by the hovered entity or column. */
796
+ private highlight():
797
+ | { relations: Set<string>; entities: Set<string>; rows: Set<string> }
798
+ | undefined {
799
+ const h = this._hover;
800
+ if (!h || this._connecting || this.drag?.moved) return undefined;
801
+ const relations = new Set<string>();
802
+ const entities = new Set<string>([h.entity]);
803
+ const rows = new Set<string>();
804
+ for (const r of this.relations) {
805
+ const fromHere =
806
+ r.source === h.entity && (!h.column || r.sourceColumn === h.column);
807
+ const toHere =
808
+ r.target === h.entity && (!h.column || r.targetColumn === h.column);
809
+ if (fromHere || toHere) {
810
+ relations.add(r.id);
811
+ entities.add(r.source);
812
+ entities.add(r.target);
813
+ if (r.sourceColumn) rows.add(`${r.source}\u0000${r.sourceColumn}`);
814
+ if (r.targetColumn) rows.add(`${r.target}\u0000${r.targetColumn}`);
815
+ }
816
+ }
817
+ return { relations, entities, rows };
818
+ }
819
+
820
+ // ── Private methods: interaction
821
+
822
+ private announce(message: string) {
823
+ this._announcement = '';
824
+ requestAnimationFrame(() => {
825
+ this._announcement = message;
826
+ });
827
+ }
828
+
829
+ private selectItem(id: string) {
830
+ this.selected = id;
831
+ const entity = this.byId.get(id);
832
+ const relation = entity ? undefined : this.relations.find(r => r.id === id);
833
+ this.emit<ErdSelectDetail>('select', {
834
+ id,
835
+ kind: entity ? 'entity' : 'relation',
836
+ entity,
837
+ relation,
838
+ });
839
+ }
840
+
841
+ private moveFocusTo(id: string) {
842
+ this._focusId = id;
843
+ this.updateComplete.then(() => {
844
+ this.entityElement(id)?.focus({ preventScroll: true });
845
+ const r = this.itemRect(id);
846
+ const view = this.viewport.visibleRect();
847
+ if (
848
+ r &&
849
+ (r.x < view.x ||
850
+ r.y < view.y ||
851
+ r.x + r.width > view.x + view.width ||
852
+ r.y + r.height > view.y + view.height)
853
+ ) {
854
+ this.centerOn(r.x + r.width / 2, r.y + Math.min(r.height, 200) / 2);
855
+ }
856
+ });
857
+ }
858
+
859
+ private toggle(id: string, collapsed: boolean) {
860
+ if (this._collapsed.has(id) === collapsed) return;
861
+ const next = new Set(this._collapsed);
862
+ if (collapsed) next.add(id);
863
+ else next.delete(id);
864
+ this._collapsed = next;
865
+ this.emit<ErdToggleDetail>('toggle', { id, collapsed });
866
+ }
867
+
868
+ private get canEdit() {
869
+ return this.editable && !this.readonly;
870
+ }
871
+
872
+ private startEdit(entity: string, field: 'name' | 'type', column?: number) {
873
+ if (!this.canEdit) return;
874
+ this._editing = { entity, column, field };
875
+ }
876
+
877
+ private finishEdit(value: string | undefined) {
878
+ const editing = this._editing;
879
+ this._editing = undefined;
880
+ if (!editing || value === undefined) return;
881
+ const text = value.trim();
882
+ const entity = this.byId.get(editing.entity);
883
+ if (!entity || (!text && editing.field === 'name')) return;
884
+ if (editing.column === undefined) {
885
+ if (text !== entity.name)
886
+ this.updateEntity(entity.id, e => ({ ...e, name: text }), 'rename');
887
+ } else {
888
+ const column = entity.columns[editing.column];
889
+ if (!column) return;
890
+ const field = editing.field === 'name' ? 'name' : 'type';
891
+ if ((column[field] ?? '') === text) return;
892
+ const oldName = column.name;
893
+ this.commit(
894
+ this.entities.map(e =>
895
+ e.id === entity.id
896
+ ? {
897
+ ...e,
898
+ columns: e.columns.map((c, i) =>
899
+ i === editing.column ? { ...c, [field]: text } : c,
900
+ ),
901
+ }
902
+ : e,
903
+ ),
904
+ // Relations follow a renamed column.
905
+ field === 'name'
906
+ ? this.relations.map(r => ({
907
+ ...r,
908
+ sourceColumn:
909
+ r.source === entity.id && r.sourceColumn === oldName
910
+ ? text
911
+ : r.sourceColumn,
912
+ targetColumn:
913
+ r.target === entity.id && r.targetColumn === oldName
914
+ ? text
915
+ : r.targetColumn,
916
+ }))
917
+ : this.relations,
918
+ field === 'name' ? 'rename' : 'column-update',
919
+ );
920
+ }
921
+ this.moveFocusTo(entity.id);
922
+ }
923
+
924
+ private addColumn(entityId: string) {
925
+ const entity = this.byId.get(entityId);
926
+ if (!entity) return;
927
+ const base = this.i18n.t('erdNewColumn');
928
+ const taken = new Set(entity.columns.map(c => c.name));
929
+ let name = base;
930
+ for (let n = 2; taken.has(name); n += 1) name = `${base}_${n}`;
931
+ this.updateEntity(
932
+ entityId,
933
+ e => ({
934
+ ...e,
935
+ columns: [...e.columns, { name, type: 'text', nullable: true }],
936
+ }),
937
+ 'column-add',
938
+ );
939
+ this._editing = {
940
+ entity: entityId,
941
+ column: entity.columns.length,
942
+ field: 'name',
943
+ };
944
+ }
945
+
946
+ private removeColumn(entityId: string, index: number) {
947
+ const entity = this.byId.get(entityId);
948
+ const column = entity?.columns[index];
949
+ if (!entity || !column) return;
950
+ this.commit(
951
+ this.entities.map(e =>
952
+ e.id === entityId
953
+ ? { ...e, columns: e.columns.filter((_, i) => i !== index) }
954
+ : e,
955
+ ),
956
+ this.relations.filter(
957
+ r =>
958
+ !(r.source === entityId && r.sourceColumn === column.name) &&
959
+ !(r.target === entityId && r.targetColumn === column.name),
960
+ ),
961
+ 'column-remove',
962
+ );
963
+ }
964
+
965
+ private togglePrimaryKey(entityId: string, index: number) {
966
+ this.updateEntity(
967
+ entityId,
968
+ e => ({
969
+ ...e,
970
+ columns: e.columns.map((c, i) =>
971
+ i === index ? { ...c, pk: !c.pk } : c,
972
+ ),
973
+ }),
974
+ 'column-update',
975
+ );
976
+ }
977
+
978
+ private setCardinality(
979
+ id: string,
980
+ source: ErdCardinality,
981
+ target: ErdCardinality,
982
+ ) {
983
+ this._picker = undefined;
984
+ this.commit(
985
+ this.entities,
986
+ this.relations.map(r =>
987
+ r.id === id
988
+ ? { ...r, sourceCardinality: source, targetCardinality: target }
989
+ : r,
990
+ ),
991
+ 'cardinality',
992
+ );
993
+ }
994
+
995
+ private toCanvas(event: PointerEvent): DiagramPoint {
996
+ const vr = this._viewportEl?.getBoundingClientRect();
997
+ const { x, y, zoom } = this.viewport.view;
998
+ return {
999
+ x: (event.clientX - (vr?.left ?? 0) - x) / zoom,
1000
+ y: (event.clientY - (vr?.top ?? 0) - y) / zoom,
1001
+ };
1002
+ }
1003
+
1004
+ private onEntityKeyDown(event: KeyboardEvent, entity: ErdEntity) {
1005
+ if (event.target !== event.currentTarget) return;
1006
+ const done = (fn: () => void) => {
1007
+ event.preventDefault();
1008
+ event.stopPropagation();
1009
+ fn();
1010
+ };
1011
+ const { key } = event;
1012
+ const arrows: Record<string, 'up' | 'down' | 'left' | 'right'> = {
1013
+ ArrowUp: 'up',
1014
+ ArrowDown: 'down',
1015
+ ArrowLeft: 'left',
1016
+ ArrowRight: 'right',
1017
+ };
1018
+ if (key === 'Enter' && event.shiftKey) {
1019
+ done(() => this.toggle(entity.id, !this._collapsed.has(entity.id)));
1020
+ } else if (key === 'Enter' || key === ' ') {
1021
+ done(() => this.selectItem(entity.id));
1022
+ } else if (arrows[key]) {
1023
+ const next = nearestInDirection(
1024
+ this.rectOf(entity.id),
1025
+ this.visible
1026
+ .filter(e => e.id !== entity.id)
1027
+ .map(e => ({ id: e.id, rect: this.rectOf(e.id) })),
1028
+ arrows[key],
1029
+ );
1030
+ if (next) done(() => this.moveFocusTo(next.id));
1031
+ } else if (key === 'f' || key === 'F') {
1032
+ done(() => {
1033
+ const id = this.focusedNode === entity.id ? '' : entity.id;
1034
+ this.focusedNode = id;
1035
+ this.emit<ErdFocusDetail>('focus-change', {
1036
+ id: id || null,
1037
+ hops: this.hops,
1038
+ });
1039
+ });
1040
+ } else if (key === 'F2' && this.canEdit) {
1041
+ done(() => this.startEdit(entity.id, 'name'));
1042
+ } else if ((key === 'Delete' || key === 'Backspace') && this.canEdit) {
1043
+ done(() => this.deleteItems([entity.id]));
1044
+ }
1045
+ }
1046
+
1047
+ private onViewportKeyDown = (event: KeyboardEvent) => {
1048
+ if (event.defaultPrevented) return;
1049
+ const mod = event.ctrlKey || event.metaKey;
1050
+ const key = event.key.toLowerCase();
1051
+ if (key === 'escape') {
1052
+ event.preventDefault();
1053
+ if (this._picker) this._picker = undefined;
1054
+ else if (this.focusedNode) {
1055
+ this.focusedNode = '';
1056
+ this.emit<ErdFocusDetail>('focus-change', {
1057
+ id: null,
1058
+ hops: this.hops,
1059
+ });
1060
+ } else this.selected = '';
1061
+ return;
1062
+ }
1063
+ if (mod && key === 'z' && !event.shiftKey) {
1064
+ event.preventDefault();
1065
+ this.undo();
1066
+ return;
1067
+ }
1068
+ if (mod && (key === 'y' || (key === 'z' && event.shiftKey))) {
1069
+ event.preventDefault();
1070
+ this.redo();
1071
+ return;
1072
+ }
1073
+ if (
1074
+ (key === 'delete' || key === 'backspace') &&
1075
+ this.canEdit &&
1076
+ this.relations.some(r => r.id === this.selected)
1077
+ ) {
1078
+ event.preventDefault();
1079
+ this.deleteItems([this.selected]);
1080
+ return;
1081
+ }
1082
+ this.handleCanvasKey(event);
1083
+ };
1084
+
1085
+ private onEntityPointerDown(event: PointerEvent, entity: ErdEntity) {
1086
+ if (event.button !== 0 || this.viewport.spaceHeld) return;
1087
+ const origin = event.composedPath()[0];
1088
+ if (
1089
+ origin instanceof Element &&
1090
+ origin.closest(`${INTERACTIVE}, .erd-port`)
1091
+ )
1092
+ return;
1093
+ event.stopPropagation();
1094
+ this._picker = undefined;
1095
+ const element = event.currentTarget as HTMLElement;
1096
+ element.focus({ preventScroll: true });
1097
+ this._focusId = entity.id;
1098
+ this.drag = {
1099
+ pointerId: event.pointerId,
1100
+ startX: event.clientX,
1101
+ startY: event.clientY,
1102
+ id: entity.id,
1103
+ origin: this.topLeft(entity.id),
1104
+ element,
1105
+ moved: false,
1106
+ };
1107
+ try {
1108
+ element.setPointerCapture(event.pointerId);
1109
+ } catch {
1110
+ // Synthetic pointers cannot be captured.
1111
+ }
1112
+ element.addEventListener('pointermove', this.onDragMove);
1113
+ element.addEventListener('pointerup', this.onDragUp);
1114
+ element.addEventListener('pointercancel', this.onDragUp);
1115
+ }
1116
+
1117
+ private onDragMove = (event: PointerEvent) => {
1118
+ const { drag } = this;
1119
+ if (!drag || event.pointerId !== drag.pointerId || this.readonly) return;
1120
+ const { zoom } = this.viewport.view;
1121
+ const dx = (event.clientX - drag.startX) / zoom;
1122
+ const dy = (event.clientY - drag.startY) / zoom;
1123
+ if (!drag.moved && Math.hypot(dx * zoom, dy * zoom) < DRAG_THRESHOLD)
1124
+ return;
1125
+ drag.moved = true;
1126
+ const position = {
1127
+ x: Math.round(drag.origin.x + dx),
1128
+ y: Math.round(drag.origin.y + dy),
1129
+ };
1130
+ this.positions.set(drag.id, position);
1131
+ this.pinned.set(drag.id, position);
1132
+ this.requestUpdate();
1133
+ };
1134
+
1135
+ private onDragUp = (event: PointerEvent) => {
1136
+ const { drag } = this;
1137
+ if (!drag || event.pointerId !== drag.pointerId) return;
1138
+ this.drag = undefined;
1139
+ drag.element.removeEventListener('pointermove', this.onDragMove);
1140
+ drag.element.removeEventListener('pointerup', this.onDragUp);
1141
+ drag.element.removeEventListener('pointercancel', this.onDragUp);
1142
+ try {
1143
+ if (drag.element.hasPointerCapture(drag.pointerId)) {
1144
+ drag.element.releasePointerCapture(drag.pointerId);
1145
+ }
1146
+ } catch {
1147
+ // The pointer is already gone.
1148
+ }
1149
+ if (!drag.moved) {
1150
+ this.selectItem(drag.id);
1151
+ return;
1152
+ }
1153
+ const position = this.topLeft(drag.id);
1154
+ // The layout key changes now that the entity is pinned; keep everything else where it is.
1155
+ this.layoutKey = '';
1156
+ this.runLayout();
1157
+ this.emit<ErdMoveDetail>('entity-move', { id: drag.id, position });
1158
+ if (this.canEdit) {
1159
+ this.updateEntity(drag.id, e => ({ ...e, position }), 'move');
1160
+ }
1161
+ };
1162
+
1163
+ private onPortPointerDown(
1164
+ event: PointerEvent,
1165
+ entity: ErdEntity,
1166
+ column: ErdColumn,
1167
+ ) {
1168
+ if (event.button !== 0 || !this.canEdit) return;
1169
+ event.preventDefault();
1170
+ event.stopPropagation();
1171
+ const handle = event.currentTarget as HTMLElement;
1172
+ const start = {
1173
+ x: this.topLeft(entity.id).x + WIDTH,
1174
+ y: this.rowY(entity, column.name),
1175
+ };
1176
+ this._connecting = {
1177
+ from: { entity: entity.id, column: column.name },
1178
+ start,
1179
+ side: 'right',
1180
+ pointer: this.toCanvas(event),
1181
+ };
1182
+ try {
1183
+ handle.setPointerCapture(event.pointerId);
1184
+ } catch {
1185
+ // Synthetic pointers cannot be captured.
1186
+ }
1187
+ const move = (e: PointerEvent) => {
1188
+ if (this._connecting)
1189
+ this._connecting = { ...this._connecting, pointer: this.toCanvas(e) };
1190
+ };
1191
+ const up = (e: PointerEvent) => {
1192
+ handle.removeEventListener('pointermove', move);
1193
+ handle.removeEventListener('pointerup', up);
1194
+ handle.removeEventListener('pointercancel', up);
1195
+ const connecting = this._connecting;
1196
+ this._connecting = undefined;
1197
+ if (!connecting || e.type === 'pointercancel') return;
1198
+ const target = this.rowAt(e.clientX, e.clientY);
1199
+ if (!target) return;
1200
+ const { from } = connecting;
1201
+ if (target.entity === from.entity && target.column === from.column)
1202
+ return;
1203
+ if (
1204
+ this.addRelation({
1205
+ source: from.entity,
1206
+ sourceColumn: from.column,
1207
+ target: target.entity,
1208
+ targetColumn: target.column,
1209
+ })
1210
+ ) {
1211
+ const vr = this._viewportEl?.getBoundingClientRect();
1212
+ const created = this.relations[this.relations.length - 1];
1213
+ this._picker = {
1214
+ id: created.id,
1215
+ x: e.clientX - (vr?.left ?? 0),
1216
+ y: e.clientY - (vr?.top ?? 0),
1217
+ };
1218
+ }
1219
+ };
1220
+ handle.addEventListener('pointermove', move);
1221
+ handle.addEventListener('pointerup', up);
1222
+ handle.addEventListener('pointercancel', up);
1223
+ }
1224
+
1225
+ /** The row (or entity header) under a screen point. */
1226
+ private rowAt(clientX: number, clientY: number): RowRef | undefined {
1227
+ const root = this.renderRoot as ShadowRoot;
1228
+ const hits = root.elementsFromPoint?.(clientX, clientY) ?? [];
1229
+ for (const el of hits) {
1230
+ const row = el.closest?.('.erd-row') as HTMLElement | null;
1231
+ const card = el.closest?.('.erd-entity') as HTMLElement | null;
1232
+ if (row?.dataset.column !== undefined && card?.dataset.id) {
1233
+ return { entity: card.dataset.id, column: row.dataset.column };
1234
+ }
1235
+ if (card?.dataset.id) return { entity: card.dataset.id };
1236
+ }
1237
+ return undefined;
1238
+ }
1239
+
1240
+ private entityElement(id: string): HTMLElement | null {
1241
+ return this.renderRoot.querySelector<HTMLElement>(
1242
+ `.erd-entity[data-id="${CSS.escape(id)}"]`,
1243
+ );
1244
+ }
1245
+
1246
+ // ── Render helpers
1247
+
1248
+ private renderMarker(
1249
+ cardinality: ErdCardinality,
1250
+ at: DiagramPoint,
1251
+ angle: number,
1252
+ ) {
1253
+ return markerShapes(cardinality).map(
1254
+ s =>
1255
+ svg`<path class=${`erd-marker fill-${s.fill}`} d=${s.d} transform=${markerTransform(at, angle)}></path>`,
1256
+ );
1257
+ }
1258
+
1259
+ /**
1260
+ * A route between facing sides that avoids the entities in between: when the plain elbow would
1261
+ * cross one, the line turns in the gap next to each end and runs along the nearest free channel.
1262
+ * Returns `undefined` when the plain elbow is clear or no channel is found.
1263
+ */
1264
+ private routeAround(
1265
+ start: DiagramPoint,
1266
+ end: DiagramPoint,
1267
+ sourceId: string,
1268
+ targetId: string,
1269
+ ): EdgeGeometry | undefined {
1270
+ const dir = end.x >= start.x ? 1 : -1;
1271
+ const margin = 14;
1272
+ const obstacles = this.visible
1273
+ .filter(e => e.id !== sourceId && e.id !== targetId)
1274
+ .map(e => inflateRect(this.rectOf(e.id), margin));
1275
+ const hits = (a: DiagramPoint, b: DiagramPoint) => {
1276
+ const x1 = Math.min(a.x, b.x);
1277
+ const x2 = Math.max(a.x, b.x);
1278
+ const y1 = Math.min(a.y, b.y);
1279
+ const y2 = Math.max(a.y, b.y);
1280
+ return obstacles.some(
1281
+ o => x1 < o.x + o.width && x2 > o.x && y1 < o.y + o.height && y2 > o.y,
1282
+ );
1283
+ };
1284
+ const clear = (points: DiagramPoint[]) =>
1285
+ points.every((p, i) => i === 0 || !hits(points[i - 1], p));
1286
+ const xm = (start.x + end.x) / 2;
1287
+ if (clear([start, { x: xm, y: start.y }, { x: xm, y: end.y }, end])) {
1288
+ return undefined;
1289
+ }
1290
+ const gapA = start.x + dir * 28;
1291
+ const gapB = end.x - dir * 28;
1292
+ const candidates = [
1293
+ start.y,
1294
+ end.y,
1295
+ ...obstacles.flatMap(o => [o.y - 1, o.y + o.height + 1]),
1296
+ ];
1297
+ let best: DiagramPoint[] | undefined;
1298
+ let bestCost = Infinity;
1299
+ for (const y of candidates) {
1300
+ const points = [
1301
+ start,
1302
+ { x: gapA, y: start.y },
1303
+ { x: gapA, y },
1304
+ { x: gapB, y },
1305
+ { x: gapB, y: end.y },
1306
+ end,
1307
+ ];
1308
+ const cost = Math.abs(y - start.y) + Math.abs(y - end.y);
1309
+ if (cost < bestCost && clear(points)) {
1310
+ best = points;
1311
+ bestCost = cost;
1312
+ }
1313
+ }
1314
+ if (!best) return undefined;
1315
+ return {
1316
+ d: roundedPath(best, 14),
1317
+ mid: polylineMidpoint(best),
1318
+ startAngle: dir > 0 ? Math.PI : 0,
1319
+ endAngle: dir > 0 ? 0 : Math.PI,
1320
+ };
1321
+ }
1322
+
1323
+ private renderRelations(
1324
+ lit: ReturnType<Erd['highlight']>,
1325
+ shown: Set<string>,
1326
+ ) {
1327
+ return this.relations
1328
+ .filter(
1329
+ r => this.visibleIds.has(r.source) && this.visibleIds.has(r.target),
1330
+ )
1331
+ .filter(r => shown.has(r.source) || shown.has(r.target))
1332
+ .map(r => {
1333
+ const s = this.byId.get(r.source) as ErdEntity;
1334
+ const t = this.byId.get(r.target) as ErdEntity;
1335
+ const sp = this.topLeft(s.id);
1336
+ const tp = this.topLeft(t.id);
1337
+ let sSide: DiagramSide = 'right';
1338
+ let tSide: DiagramSide = 'left';
1339
+ if (tp.x + WIDTH + 40 < sp.x) {
1340
+ sSide = 'left';
1341
+ tSide = 'right';
1342
+ } else if (!(sp.x + WIDTH + 40 < tp.x)) {
1343
+ // Stacked in one column: both lines leave on the right and loop.
1344
+ tSide = 'right';
1345
+ }
1346
+ const start = {
1347
+ x: sSide === 'right' ? sp.x + WIDTH : sp.x,
1348
+ y: this.rowY(s, r.sourceColumn),
1349
+ };
1350
+ const end = {
1351
+ x: tSide === 'right' ? tp.x + WIDTH : tp.x,
1352
+ y: this.rowY(t, r.targetColumn),
1353
+ };
1354
+ const g =
1355
+ (sSide !== tSide && this.routeAround(start, end, s.id, t.id)) ||
1356
+ edgeGeometry('elbow', start, sSide, end, tSide, { radius: 14 });
1357
+ const on = !!lit?.relations.has(r.id);
1358
+ const selected = this.selected === r.id;
1359
+ return svg`<g
1360
+ class=${classMap({
1361
+ 'erd-relation': true,
1362
+ 'is-lit': on,
1363
+ 'is-dim': !!lit && !on,
1364
+ 'is-selected': selected,
1365
+ 'is-fresh': this._fresh.has(r.id),
1366
+ })}
1367
+ data-id=${r.id}
1368
+ >
1369
+ <path class="erd-line" d=${g.d} pathLength="1"></path>
1370
+ ${this.renderMarker(r.sourceCardinality ?? 'many', start, g.startAngle)}
1371
+ ${this.renderMarker(r.targetCardinality ?? 'one', end, g.endAngle)}
1372
+ <path
1373
+ class="erd-hit"
1374
+ d=${g.d}
1375
+ @pointerdown=${(e: PointerEvent) => e.stopPropagation()}
1376
+ @click=${() => this.selectItem(r.id)}
1377
+ ></path>
1378
+ ${
1379
+ r.label
1380
+ ? svg`<text class="erd-relation-label" x=${g.mid.x} y=${g.mid.y - 6}>${r.label}</text>`
1381
+ : nothing
1382
+ }
1383
+ </g>`;
1384
+ });
1385
+ }
1386
+
1387
+ private renderPreview() {
1388
+ const c = this._connecting;
1389
+ if (!c) return nothing;
1390
+ const side: DiagramSide = c.pointer.x >= c.start.x ? 'left' : 'right';
1391
+ const g = edgeGeometry('elbow', c.start, c.side, c.pointer, side, {
1392
+ radius: 14,
1393
+ });
1394
+ return svg`<path class="erd-preview" d=${g.d}></path>`;
1395
+ }
1396
+
1397
+ private renderInput(value: string) {
1398
+ return html`<input
1399
+ class="erd-input"
1400
+ .value=${value}
1401
+ aria-label=${this.i18n.t('erdRename')}
1402
+ @pointerdown=${(e: Event) => e.stopPropagation()}
1403
+ @keydown=${(e: KeyboardEvent) => {
1404
+ e.stopPropagation();
1405
+ if (e.key === 'Enter')
1406
+ this.finishEdit((e.target as HTMLInputElement).value);
1407
+ else if (e.key === 'Escape') this.finishEdit(undefined);
1408
+ }}
1409
+ @blur=${(e: FocusEvent) => {
1410
+ if (this._editing)
1411
+ this.finishEdit((e.target as HTMLInputElement).value);
1412
+ }}
1413
+ />`;
1414
+ }
1415
+
1416
+ private renderRow(
1417
+ entity: ErdEntity,
1418
+ column: ErdColumn,
1419
+ index: number,
1420
+ fks: Set<string>,
1421
+ lit: ReturnType<Erd['highlight']>,
1422
+ ) {
1423
+ const editing = this._editing;
1424
+ const editingName =
1425
+ editing?.entity === entity.id &&
1426
+ editing.column === index &&
1427
+ editing.field === 'name';
1428
+ const editingType =
1429
+ editing?.entity === entity.id &&
1430
+ editing.column === index &&
1431
+ editing.field === 'type';
1432
+ const fk = fks.has(column.name);
1433
+ let keyIcon = '';
1434
+ if (column.pk) keyIcon = 'key';
1435
+ else if (fk) keyIcon = 'link';
1436
+ let keyLabel = '';
1437
+ if (column.pk) keyLabel = this.i18n.t('erdPrimaryKey');
1438
+ else if (fk) keyLabel = this.i18n.t('erdForeignKey');
1439
+ const keyCell = this.canEdit
1440
+ ? html`<button
1441
+ type="button"
1442
+ class=${classMap({
1443
+ 'erd-key': true,
1444
+ 'is-pk': !!column.pk,
1445
+ 'is-fk': fk && !column.pk,
1446
+ })}
1447
+ aria-label=${this.i18n.t('erdTogglePrimaryKey')(column.name)}
1448
+ aria-pressed=${column.pk ? 'true' : 'false'}
1449
+ @click=${() => this.togglePrimaryKey(entity.id, index)}
1450
+ >
1451
+ <wc-icon name=${keyIcon || 'key'}></wc-icon>
1452
+ </button>`
1453
+ : html`<span
1454
+ class=${classMap({
1455
+ 'erd-key': true,
1456
+ 'is-pk': !!column.pk,
1457
+ 'is-fk': fk && !column.pk,
1458
+ })}
1459
+ title=${keyLabel}
1460
+ >${keyIcon
1461
+ ? html`<wc-icon name=${keyIcon}></wc-icon>`
1462
+ : nothing}</span
1463
+ >`;
1464
+ return html`<div
1465
+ class=${classMap({
1466
+ 'erd-row': true,
1467
+ 'is-lit': !!lit?.rows.has(`${entity.id}\u0000${column.name}`),
1468
+ 'is-hover':
1469
+ this._hover?.entity === entity.id &&
1470
+ this._hover.column === column.name,
1471
+ })}
1472
+ data-column=${column.name}
1473
+ title=${column.comment ?? nothing}
1474
+ @pointerenter=${() => {
1475
+ this._hover = { entity: entity.id, column: column.name };
1476
+ }}
1477
+ @pointerleave=${() => {
1478
+ this._hover = { entity: entity.id };
1479
+ }}
1480
+ >
1481
+ ${keyCell}
1482
+ ${editingName
1483
+ ? this.renderInput(column.name)
1484
+ : html`<span
1485
+ class="erd-col-name"
1486
+ @dblclick=${() => this.startEdit(entity.id, 'name', index)}
1487
+ >${column.name}${keyLabel
1488
+ ? html`<span class="sr-only">, ${keyLabel}</span>`
1489
+ : nothing}</span
1490
+ >`}
1491
+ ${editingType
1492
+ ? this.renderInput(column.type ?? '')
1493
+ : html`<span
1494
+ class="erd-col-type"
1495
+ @dblclick=${() => this.startEdit(entity.id, 'type', index)}
1496
+ >${column.type ?? ''}${column.nullable
1497
+ ? html`<span class="erd-null" title=${this.i18n.t('erdNullable')}
1498
+ >?</span
1499
+ >`
1500
+ : nothing}</span
1501
+ >`}
1502
+ ${this.canEdit
1503
+ ? html`<wc-icon-button
1504
+ class="erd-remove"
1505
+ variant="text"
1506
+ shape="round"
1507
+ size="xs"
1508
+ aria-label=${this.i18n.t('erdRemoveColumn')(column.name)}
1509
+ @click=${() => this.removeColumn(entity.id, index)}
1510
+ ><wc-icon name="close"></wc-icon
1511
+ ></wc-icon-button>
1512
+ <span
1513
+ class="erd-port"
1514
+ aria-hidden="true"
1515
+ @pointerdown=${(e: PointerEvent) =>
1516
+ this.onPortPointerDown(e, entity, column)}
1517
+ ></span>`
1518
+ : nothing}
1519
+ </div>`;
1520
+ }
1521
+
1522
+ private renderEntity(
1523
+ entity: ErdEntity,
1524
+ focusId: string,
1525
+ lit: ReturnType<Erd['highlight']>,
1526
+ ) {
1527
+ const p = this.topLeft(entity.id);
1528
+ const collapsed = this._collapsed.has(entity.id);
1529
+ const fks = this.foreignKeys(entity.id);
1530
+ const { references, referencedBy } = this.related(entity.id);
1531
+ const editingName =
1532
+ this._editing?.entity === entity.id && this._editing.column === undefined;
1533
+ const selected = this.selected === entity.id;
1534
+ return html`<div
1535
+ class=${classMap({
1536
+ 'erd-entity': true,
1537
+ [`accent-${entity.accent ?? 'primary'}`]: true,
1538
+ 'is-selected': selected,
1539
+ 'is-collapsed': collapsed,
1540
+ 'is-lit': !!lit?.entities.has(entity.id) && lit.entities.size > 1,
1541
+ 'is-dim': !!lit && !lit.entities.has(entity.id),
1542
+ 'is-fresh': this._fresh.has(entity.id),
1543
+ 'is-focus': this.focusedNode === entity.id,
1544
+ })}
1545
+ data-id=${entity.id}
1546
+ role="button"
1547
+ aria-pressed=${selected ? 'true' : 'false'}
1548
+ aria-expanded=${collapsed ? 'false' : 'true'}
1549
+ aria-label=${this.i18n.t('erdEntity')(
1550
+ entity.schema ? `${entity.schema}.${entity.name}` : entity.name,
1551
+ entity.columns.length,
1552
+ references,
1553
+ referencedBy,
1554
+ )}
1555
+ tabindex=${focusId === entity.id ? '0' : '-1'}
1556
+ style="left: ${p.x}px; top: ${p.y}px; width: ${WIDTH}px;"
1557
+ @pointerdown=${(e: PointerEvent) => this.onEntityPointerDown(e, entity)}
1558
+ @pointerenter=${() => {
1559
+ this._hover = { entity: entity.id };
1560
+ }}
1561
+ @pointerleave=${() => {
1562
+ this._hover = undefined;
1563
+ }}
1564
+ @keydown=${(e: KeyboardEvent) => this.onEntityKeyDown(e, entity)}
1565
+ @focus=${() => {
1566
+ this._focusId = entity.id;
1567
+ }}
1568
+ >
1569
+ <div class="erd-header">
1570
+ <span class="erd-tile"
1571
+ ><wc-icon name=${entity.icon ?? 'table'}></wc-icon
1572
+ ></span>
1573
+ <span class="erd-title" title=${entity.comment ?? nothing}>
1574
+ ${entity.schema
1575
+ ? html`<span class="erd-schema">${entity.schema}.</span>`
1576
+ : nothing}
1577
+ ${editingName
1578
+ ? this.renderInput(entity.name)
1579
+ : html`<span
1580
+ class="erd-name"
1581
+ @dblclick=${() => this.startEdit(entity.id, 'name')}
1582
+ >${entity.name}</span
1583
+ >`}
1584
+ </span>
1585
+ ${collapsed
1586
+ ? html`<span class="erd-count"
1587
+ >${this.i18n.t('erdColumnCount')(entity.columns.length)}</span
1588
+ >`
1589
+ : nothing}
1590
+ <wc-icon-button
1591
+ class="erd-toggle"
1592
+ variant="text"
1593
+ shape="round"
1594
+ size="xs"
1595
+ tabindex="-1"
1596
+ aria-label=${this.i18n.t(collapsed ? 'erdExpand' : 'erdCollapse')(
1597
+ entity.name,
1598
+ )}
1599
+ @click=${() => this.toggle(entity.id, !collapsed)}
1600
+ ><wc-icon
1601
+ name=${collapsed ? 'keyboard_arrow_down' : 'keyboard_arrow_up'}
1602
+ ></wc-icon
1603
+ ></wc-icon-button>
1604
+ </div>
1605
+ ${collapsed
1606
+ ? nothing
1607
+ : html`<div class="erd-rows">
1608
+ ${entity.columns.map((c, i) =>
1609
+ this.renderRow(entity, c, i, fks, lit),
1610
+ )}
1611
+ ${this.canEdit
1612
+ ? html`<button
1613
+ type="button"
1614
+ class="erd-add"
1615
+ @click=${() => this.addColumn(entity.id)}
1616
+ >
1617
+ <wc-icon name="add"></wc-icon>${this.i18n.t('erdAddColumn')}
1618
+ </button>`
1619
+ : nothing}
1620
+ </div>`}
1621
+ </div>`;
1622
+ }
1623
+
1624
+ private renderPicker() {
1625
+ const picker = this._picker;
1626
+ if (!picker) return nothing;
1627
+ const relation = this.relations.find(r => r.id === picker.id);
1628
+ if (!relation) return nothing;
1629
+ return html`<div
1630
+ class="erd-picker"
1631
+ role="menu"
1632
+ aria-label=${this.i18n.t('erdCardinality')}
1633
+ data-diagram-overlay
1634
+ style="left: ${picker.x + 8}px; top: ${picker.y + 8}px;"
1635
+ @pointerdown=${(e: Event) => e.stopPropagation()}
1636
+ >
1637
+ ${CARDINALITY_PRESETS.map(
1638
+ preset =>
1639
+ html`<button
1640
+ type="button"
1641
+ role="menuitemradio"
1642
+ aria-checked=${relation.sourceCardinality === preset.source &&
1643
+ relation.targetCardinality === preset.target
1644
+ ? 'true'
1645
+ : 'false'}
1646
+ @click=${() =>
1647
+ this.setCardinality(relation.id, preset.source, preset.target)}
1648
+ >
1649
+ <svg
1650
+ class="erd-picker-icon"
1651
+ viewBox="-30 -10 60 20"
1652
+ aria-hidden="true"
1653
+ >
1654
+ <path class="erd-line" d="M -26 0 L 26 0"></path>
1655
+ ${this.renderMarker(preset.source, { x: -26, y: 0 }, Math.PI)}
1656
+ ${this.renderMarker(preset.target, { x: 26, y: 0 }, 0)}
1657
+ </svg>
1658
+ ${this.i18n.t(preset.key)}
1659
+ </button>`,
1660
+ )}
1661
+ </div>`;
1662
+ }
1663
+
1664
+ // ── Render
1665
+
1666
+ protected render() {
1667
+ const { x, y, zoom } = this.viewport.view;
1668
+ const lit = this.highlight();
1669
+ const focusId = this.visibleIds.has(this._focusId)
1670
+ ? this._focusId
1671
+ : (this.visible[0]?.id ?? '');
1672
+ const shown = new Set(
1673
+ this.visible
1674
+ .filter(
1675
+ e =>
1676
+ this.nearView(this.rectOf(e.id)) ||
1677
+ e.id === focusId ||
1678
+ e.id === this.selected,
1679
+ )
1680
+ .map(e => e.id),
1681
+ );
1682
+ return html`
1683
+ <div
1684
+ class=${classMap({
1685
+ 'erd-viewport': true,
1686
+ 'lod-far': zoom < FAR_ZOOM,
1687
+ 'is-panning': this.viewport.panning,
1688
+ 'is-space': this.viewport.spaceHeld,
1689
+ 'is-connecting': !!this._connecting,
1690
+ 'is-editable': this.canEdit,
1691
+ })}
1692
+ tabindex="0"
1693
+ role="region"
1694
+ aria-label=${this.label || this.i18n.t('erdLabel')}
1695
+ aria-describedby="instructions"
1696
+ style=${this.gridStyle()}
1697
+ @keydown=${this.onViewportKeyDown}
1698
+ >
1699
+ <div
1700
+ class="erd-world"
1701
+ style="transform: translate(${x}px, ${y}px) scale(${zoom}); --_zoom: ${zoom};"
1702
+ >
1703
+ <svg class="erd-relations" width="1" height="1" aria-hidden="true">
1704
+ ${this.renderRelations(lit, shown)} ${this.renderPreview()}
1705
+ </svg>
1706
+ <div
1707
+ class="erd-entities"
1708
+ role="group"
1709
+ aria-label=${this.label || this.i18n.t('erdLabel')}
1710
+ >
1711
+ ${repeat(
1712
+ this.visible.filter(e => shown.has(e.id)),
1713
+ e => e.id,
1714
+ e => this.renderEntity(e, focusId, lit),
1715
+ )}
1716
+ </div>
1717
+ </div>
1718
+ ${this.renderPicker()} ${this.renderBackToContent()}
1719
+ <div class="slot-controls"><slot name="controls"></slot></div>
1720
+ <div class="slot-minimap"><slot name="minimap"></slot></div>
1721
+ <div id="instructions" hidden>
1722
+ ${this.i18n.t('diagramInstructions')}
1723
+ </div>
1724
+ <div class="sr-only" aria-live="polite">${this._announcement}</div>
1725
+ </div>
1726
+ `;
1727
+ }
1728
+ }