@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/dist/erd.js ADDED
@@ -0,0 +1,2021 @@
1
+ import { i, _ as __decorate, I as IndividualComponent, w, A, b } from './IndividualComponent-BK7XZjE2.js';
2
+ import { n } from './property-B2TG3KEE.js';
3
+ import { r } from './state-BCeDVCI9.js';
4
+ import { e } from './query-CHb9Ft_d.js';
5
+ import { e as e$1 } from './class-map-NDIkZErE.js';
6
+ import { c } from './repeat-D_ERDRYT.js';
7
+ import { D as DiagramCanvasElement, a as animateOut, p as prefersReducedMotion, t as tween, e as easeInOutCubic } from './canvas-base-BTQMEVn_.js';
8
+ import { b as boundsOf, n as nearestInDirection, i as inflateRect, p as polylineMidpoint, r as roundedPath, e as edgeGeometry } from './geometry-INg82Lxq.js';
9
+ import { m as markerShapes, a as markerTransform } from './markers-BFmh1OCz.js';
10
+ import { H as History } from './history-YbTSQZHj.js';
11
+ import { l as layeredLayout, w as withinHops } from './dependency-map-layout-5KUueabk.js';
12
+ import './base-Cl6v8-BZ.js';
13
+ import './directive-ZPhl09Yt.js';
14
+ import './directive-helpers-Bx3mu42O.js';
15
+ import './i18n-controller-Cp43HjJl.js';
16
+ import './strings-BJPuhKJk.js';
17
+ import './locale-DEsJZCQG.js';
18
+ import './host-CZK7xhzh.js';
19
+ import './transform-CxeQFXXB.js';
20
+
21
+ /**
22
+ * Places entities in columns, referenced tables to the left of the tables that reference them,
23
+ * ordered to keep relations short. Columns are stacked with each entity's real height and centred
24
+ * on one line. Entities with no relations go in a grid after the last column. Returns top-left
25
+ * corners.
26
+ */
27
+ function layoutEntities(entities, relations, options) {
28
+ const { width, columnGap = 120, rowGap = 48 } = options;
29
+ const ids = new Set(entities.map(e => e.id));
30
+ const linked = new Set();
31
+ const edges = [];
32
+ for (const r of relations) {
33
+ if (ids.has(r.source) && ids.has(r.target) && r.source !== r.target) {
34
+ linked.add(r.source);
35
+ linked.add(r.target);
36
+ // Referenced tables first: edges run from the parent to the child.
37
+ edges.push({ source: r.target, target: r.source });
38
+ }
39
+ }
40
+ const heights = new Map(entities.map(e => [e.id, e.height]));
41
+ const connected = entities.filter(e => linked.has(e.id));
42
+ const loose = entities.filter(e => !linked.has(e.id));
43
+ // Ranks and order from the layered layout: x gives the column, y the order within it.
44
+ const ranked = layeredLayout(connected.map(e => ({ id: e.id })), edges, { nodeWidth: width, nodeHeight: 100 });
45
+ const step = width + 120;
46
+ const columns = [];
47
+ for (const [id, p] of ranked) {
48
+ const c = Math.round(p.x / step);
49
+ (columns[c] = columns[c] ?? []).push(id);
50
+ }
51
+ for (const col of columns) {
52
+ col?.sort((a, b) => (ranked.get(a)?.y ?? 0) - (ranked.get(b)?.y ?? 0));
53
+ }
54
+ // Loose entities: a grid of roughly square shape after the connected part.
55
+ if (loose.length) {
56
+ const perColumn = Math.max(2, Math.ceil(Math.sqrt(loose.length)));
57
+ for (let i = 0; i < loose.length; i += perColumn) {
58
+ columns.push(loose.slice(i, i + perColumn).map(e => e.id));
59
+ }
60
+ }
61
+ const result = new Map();
62
+ columns
63
+ .filter(col => col?.length)
64
+ .forEach((col, c) => {
65
+ const total = col.reduce((s, id) => s + (heights.get(id) ?? 0), 0) +
66
+ rowGap * (col.length - 1);
67
+ let y = -total / 2;
68
+ for (const id of col) {
69
+ result.set(id, { x: c * (width + columnGap), y });
70
+ y += (heights.get(id) ?? 0) + rowGap;
71
+ }
72
+ });
73
+ for (const e of entities)
74
+ if (e.pinned)
75
+ result.set(e.id, e.pinned);
76
+ return result;
77
+ }
78
+
79
+ var css_248z = i`* {
80
+ box-sizing: border-box;
81
+ -webkit-tap-highlight-color: transparent;
82
+ }
83
+
84
+ .screen-reader-only {
85
+ position: absolute !important;
86
+ inline-size: 1px !important;
87
+ block-size: 1px !important;
88
+ padding: 0 !important;
89
+ margin: -1px !important;
90
+ overflow: hidden !important;
91
+ clip-path: inset(50%) !important;
92
+ white-space: nowrap !important;
93
+ border: 0 !important;
94
+ }
95
+
96
+ [hidden] {
97
+ display: none !important;
98
+ }
99
+
100
+ @media (forced-colors: active) {
101
+ .selected,
102
+ [aria-selected=true],
103
+ [aria-pressed=true],
104
+ [aria-checked=true],
105
+ [aria-current]:not([aria-current=false]) {
106
+ outline: 2px solid Highlight;
107
+ outline-offset: -2px;
108
+ }
109
+ .disabled,
110
+ [aria-disabled=true] {
111
+ color: GrayText;
112
+ }
113
+ }
114
+ :host {
115
+ display: block;
116
+ position: relative;
117
+ inline-size: 100%;
118
+ block-size: 100%;
119
+ min-block-size: 240px;
120
+ overflow: hidden;
121
+ --erd-background: var(--color-surface-container-lowest, #fbfbfd);
122
+ --erd-relation-color: color-mix(
123
+ in srgb,
124
+ var(--color-outline, #74777f) 80%,
125
+ transparent
126
+ );
127
+ --erd-highlight-color: var(--color-primary, #005faf);
128
+ --_dot-color: var(--color-outline-variant, #c5c6cb);
129
+ }
130
+
131
+ /* Canvas coordinates are physical x/y and do not mirror in right-to-left layouts. */
132
+ /* stylelint-disable property-disallowed-list */
133
+ .erd-viewport {
134
+ position: absolute;
135
+ inset: 0;
136
+ overflow: hidden;
137
+ background-color: var(--erd-background);
138
+ background-image: radial-gradient(var(--_dot-color) 1px, transparent 1.2px);
139
+ border: 1px solid var(--color-outline-variant);
140
+ border-radius: var(--shape-corner-large);
141
+ touch-action: none;
142
+ outline: none;
143
+ container-type: inline-size;
144
+ container-name: diagram;
145
+ }
146
+ .erd-viewport:focus-visible {
147
+ box-shadow: inset 0 0 0 2px var(--color-primary);
148
+ }
149
+ .erd-viewport.is-space {
150
+ cursor: grab;
151
+ }
152
+ .erd-viewport.is-panning {
153
+ cursor: grabbing;
154
+ }
155
+ .erd-viewport.is-connecting {
156
+ cursor: crosshair;
157
+ }
158
+
159
+ .erd-world {
160
+ position: absolute;
161
+ left: 0;
162
+ top: 0;
163
+ transform-origin: 0 0;
164
+ }
165
+
166
+ .erd-entities {
167
+ position: absolute;
168
+ left: 0;
169
+ top: 0;
170
+ }
171
+
172
+ .erd-relations {
173
+ position: absolute;
174
+ left: 0;
175
+ top: 0;
176
+ overflow: visible;
177
+ }
178
+
179
+ .erd-relation {
180
+ --_line: var(--erd-relation-color);
181
+ transition: opacity 150ms ease;
182
+ }
183
+ .erd-relation.is-lit, .erd-relation.is-selected {
184
+ --_line: var(--erd-highlight-color);
185
+ }
186
+ .erd-relation.is-lit .erd-line, .erd-relation.is-selected .erd-line {
187
+ stroke-width: 2.5;
188
+ }
189
+ .erd-relation.is-dim {
190
+ opacity: 0.25;
191
+ }
192
+ .erd-relation.is-fresh .erd-line {
193
+ stroke-dasharray: 1;
194
+ animation: erd-draw 450ms ease-out both;
195
+ }
196
+
197
+ .erd-line {
198
+ fill: none;
199
+ stroke: var(--_line, var(--erd-relation-color));
200
+ stroke-width: 1.5;
201
+ stroke-linejoin: round;
202
+ }
203
+
204
+ .erd-marker {
205
+ stroke: var(--_line, var(--erd-relation-color));
206
+ stroke-width: 1.5;
207
+ stroke-linecap: round;
208
+ }
209
+ .erd-marker.fill-none {
210
+ fill: none;
211
+ }
212
+ .erd-marker.fill-solid {
213
+ fill: var(--_line, var(--erd-relation-color));
214
+ }
215
+ .erd-marker.fill-surface {
216
+ fill: var(--erd-background);
217
+ }
218
+
219
+ .erd-hit {
220
+ fill: none;
221
+ stroke: transparent;
222
+ stroke-width: 12;
223
+ pointer-events: stroke;
224
+ cursor: pointer;
225
+ }
226
+ .erd-hit:hover {
227
+ stroke: color-mix(in srgb, var(--erd-highlight-color) 12%, transparent);
228
+ }
229
+
230
+ .erd-relation-label {
231
+ font-size: 11px;
232
+ text-anchor: middle;
233
+ fill: var(--color-on-surface-variant);
234
+ paint-order: stroke;
235
+ stroke: var(--erd-background);
236
+ stroke-width: 4px;
237
+ pointer-events: none;
238
+ }
239
+
240
+ .erd-preview {
241
+ fill: none;
242
+ stroke: var(--erd-highlight-color);
243
+ stroke-width: 2;
244
+ stroke-dasharray: 6 4;
245
+ pointer-events: none;
246
+ }
247
+
248
+ .erd-entity {
249
+ position: absolute;
250
+ box-sizing: border-box;
251
+ background: var(--color-surface-container-lowest);
252
+ border: 1px solid var(--color-outline-variant);
253
+ border-radius: var(--shape-corner-medium);
254
+ box-shadow: var(--elevation-level1);
255
+ outline: none;
256
+ touch-action: none;
257
+ overflow: visible;
258
+ transition: box-shadow 150ms ease, border-color 150ms ease, opacity 150ms ease;
259
+ }
260
+ .erd-entity:hover {
261
+ border-color: var(--color-outline);
262
+ }
263
+ .erd-entity:focus-visible {
264
+ outline: 2px solid var(--color-primary);
265
+ outline-offset: 3px;
266
+ }
267
+ .erd-entity.is-selected {
268
+ border-color: var(--color-primary);
269
+ box-shadow: 0 0 0 2px var(--color-primary), var(--elevation-level2);
270
+ z-index: 2;
271
+ }
272
+ .erd-entity.is-lit {
273
+ border-color: var(--erd-highlight-color);
274
+ }
275
+ .erd-entity.is-dim {
276
+ opacity: 0.45;
277
+ }
278
+ .erd-entity.is-focus {
279
+ box-shadow: 0 0 0 4px color-mix(in srgb, var(--color-primary) 30%, transparent), var(--elevation-level2);
280
+ }
281
+ .erd-entity.is-fresh {
282
+ animation: erd-pop 320ms cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
283
+ }
284
+
285
+ /* stylelint-enable property-disallowed-list */
286
+ .erd-header {
287
+ display: flex;
288
+ align-items: center;
289
+ gap: 10px;
290
+ block-size: 48px;
291
+ box-sizing: border-box;
292
+ padding: 0 6px 0 10px;
293
+ border-block-end: 1px solid var(--color-outline-variant);
294
+ cursor: grab;
295
+ }
296
+ .is-collapsed .erd-header {
297
+ border-block-end: 0;
298
+ }
299
+
300
+ .erd-tile {
301
+ display: inline-flex;
302
+ align-items: center;
303
+ justify-content: center;
304
+ flex: none;
305
+ inline-size: 28px;
306
+ block-size: 28px;
307
+ border-radius: var(--shape-corner-small);
308
+ background: var(--_tile-bg, var(--color-primary-container));
309
+ --icon-color: var(--_tile-fg, var(--color-on-primary-container));
310
+ --icon-size: 1.05rem;
311
+ }
312
+
313
+ .accent-tertiary {
314
+ --_tile-bg: var(--color-tertiary-container);
315
+ --_tile-fg: var(--color-on-tertiary-container);
316
+ }
317
+
318
+ .accent-blue {
319
+ --_tile-bg: var(--color-blue-container);
320
+ --_tile-fg: var(--color-on-blue-container);
321
+ }
322
+
323
+ .accent-green {
324
+ --_tile-bg: var(--color-green-container);
325
+ --_tile-fg: var(--color-on-green-container);
326
+ }
327
+
328
+ .accent-orange {
329
+ --_tile-bg: var(--color-orange-container);
330
+ --_tile-fg: var(--color-on-orange-container);
331
+ }
332
+
333
+ .accent-purple {
334
+ --_tile-bg: var(--color-purple-container);
335
+ --_tile-fg: var(--color-on-purple-container);
336
+ }
337
+
338
+ .accent-red {
339
+ --_tile-bg: var(--color-error-container);
340
+ --_tile-fg: var(--color-on-error-container);
341
+ }
342
+
343
+ .accent-yellow {
344
+ --_tile-bg: var(--color-yellow-container);
345
+ --_tile-fg: var(--color-on-yellow-container);
346
+ }
347
+
348
+ .accent-neutral {
349
+ --_tile-bg: var(--color-surface-container-high);
350
+ --_tile-fg: var(--color-on-surface-variant);
351
+ }
352
+
353
+ .erd-title {
354
+ display: flex;
355
+ align-items: baseline;
356
+ flex: 1;
357
+ min-inline-size: 0;
358
+ font-size: 14px;
359
+ font-weight: 600;
360
+ color: var(--color-on-surface);
361
+ white-space: nowrap;
362
+ overflow: hidden;
363
+ }
364
+
365
+ .erd-schema {
366
+ font-weight: 400;
367
+ color: var(--color-on-surface-variant);
368
+ }
369
+
370
+ .erd-name {
371
+ overflow: hidden;
372
+ text-overflow: ellipsis;
373
+ }
374
+
375
+ .erd-count {
376
+ flex: none;
377
+ font-size: 11px;
378
+ color: var(--color-on-surface-variant);
379
+ }
380
+
381
+ .erd-rows {
382
+ padding-block: 4px;
383
+ }
384
+
385
+ .erd-row {
386
+ position: relative;
387
+ display: flex;
388
+ align-items: center;
389
+ gap: 6px;
390
+ block-size: 28px;
391
+ box-sizing: border-box;
392
+ padding: 0 10px 0 8px;
393
+ font-size: 13px;
394
+ }
395
+ .erd-row.is-hover {
396
+ background: color-mix(in srgb, var(--color-on-surface) 5%, transparent);
397
+ }
398
+ .erd-row.is-lit {
399
+ background: color-mix(in srgb, var(--erd-highlight-color) 10%, transparent);
400
+ }
401
+ .erd-row.is-lit .erd-col-name {
402
+ color: var(--erd-highlight-color);
403
+ font-weight: 600;
404
+ }
405
+
406
+ .erd-key {
407
+ background: transparent;
408
+ border: none;
409
+ appearance: none;
410
+ margin: 0;
411
+ outline: none;
412
+ padding: 0;
413
+ display: inline-flex;
414
+ align-items: center;
415
+ justify-content: center;
416
+ flex: none;
417
+ inline-size: 18px;
418
+ block-size: 18px;
419
+ border-radius: var(--shape-corner-extra-small);
420
+ --icon-size: 0.85rem;
421
+ --icon-color: var(--color-on-surface-variant);
422
+ }
423
+ .erd-key.is-pk {
424
+ --icon-color: var(--color-yellow, #b58a00);
425
+ }
426
+ .erd-key.is-fk {
427
+ --icon-color: var(--color-primary);
428
+ }
429
+ .erd-key:is(button) {
430
+ cursor: pointer;
431
+ }
432
+ .erd-key:is(button):not(.is-pk, .is-fk) {
433
+ opacity: 0;
434
+ }
435
+ .erd-key:is(button):hover, .erd-key:is(button):focus-visible {
436
+ opacity: 1;
437
+ background: color-mix(in srgb, var(--color-on-surface) 8%, transparent);
438
+ }
439
+ .erd-row:hover .erd-key:is(button) {
440
+ opacity: 1;
441
+ }
442
+
443
+ .erd-col-name {
444
+ flex: 1;
445
+ min-inline-size: 0;
446
+ overflow: hidden;
447
+ text-overflow: ellipsis;
448
+ white-space: nowrap;
449
+ color: var(--color-on-surface);
450
+ }
451
+
452
+ .erd-col-type {
453
+ flex: none;
454
+ max-inline-size: 45%;
455
+ overflow: hidden;
456
+ text-overflow: ellipsis;
457
+ white-space: nowrap;
458
+ font-family: var(--typography-code-font-family, ui-monospace, monospace);
459
+ font-size: 12px;
460
+ color: var(--color-on-surface-variant);
461
+ }
462
+
463
+ .erd-null {
464
+ margin-inline-start: 2px;
465
+ color: var(--color-outline);
466
+ }
467
+
468
+ .erd-input {
469
+ flex: 1;
470
+ min-inline-size: 0;
471
+ block-size: 24px;
472
+ padding: 0 6px;
473
+ font: inherit;
474
+ color: var(--color-on-surface);
475
+ background: var(--color-surface-container-lowest);
476
+ border: 1px solid var(--color-primary);
477
+ border-radius: var(--shape-corner-extra-small);
478
+ outline: none;
479
+ }
480
+
481
+ .erd-remove {
482
+ opacity: 0;
483
+ transition: opacity 120ms ease;
484
+ }
485
+ .erd-row:hover .erd-remove, .erd-remove:focus-within {
486
+ opacity: 1;
487
+ }
488
+
489
+ /* stylelint-disable property-disallowed-list */
490
+ .erd-port {
491
+ position: absolute;
492
+ right: -7px;
493
+ top: 50%;
494
+ inline-size: 12px;
495
+ block-size: 12px;
496
+ margin-block-start: -6px;
497
+ box-sizing: border-box;
498
+ border: 2px solid var(--color-primary);
499
+ border-radius: 50%;
500
+ background: var(--color-surface-container-lowest);
501
+ cursor: crosshair;
502
+ opacity: 0;
503
+ transition: opacity 120ms ease, transform 120ms ease;
504
+ }
505
+ .erd-row:hover .erd-port, .is-connecting .erd-port {
506
+ opacity: 1;
507
+ }
508
+ .erd-port:hover {
509
+ transform: scale(1.3);
510
+ }
511
+
512
+ /* stylelint-enable property-disallowed-list */
513
+ .erd-add {
514
+ background: transparent;
515
+ border: none;
516
+ appearance: none;
517
+ margin: 0;
518
+ outline: none;
519
+ padding: 0;
520
+ display: flex;
521
+ align-items: center;
522
+ gap: 6px;
523
+ inline-size: 100%;
524
+ block-size: 32px;
525
+ padding: 0 10px;
526
+ font-size: 12px;
527
+ font-weight: 500;
528
+ color: var(--color-primary);
529
+ cursor: pointer;
530
+ --icon-size: 1rem;
531
+ --icon-color: var(--color-primary);
532
+ }
533
+ .erd-add:hover {
534
+ background: color-mix(in srgb, var(--color-primary) 8%, transparent);
535
+ }
536
+ .erd-add:focus-visible {
537
+ outline: 2px solid var(--color-primary);
538
+ outline-offset: -2px;
539
+ }
540
+
541
+ .lod-far .erd-row > * {
542
+ visibility: hidden;
543
+ }
544
+ .lod-far .erd-row::after {
545
+ content: "";
546
+ position: absolute;
547
+ inset-inline: 12px 40%;
548
+ inset-block: 10px;
549
+ border-radius: var(--shape-corner-full);
550
+ background: var(--color-surface-container-high);
551
+ }
552
+ .lod-far .erd-title {
553
+ font-size: min(13px / var(--_zoom, 1), 32px);
554
+ }
555
+ .lod-far .erd-schema,
556
+ .lod-far .erd-count,
557
+ .lod-far .erd-toggle {
558
+ display: none;
559
+ }
560
+
561
+ /* stylelint-disable property-disallowed-list */
562
+ .erd-picker {
563
+ position: absolute;
564
+ z-index: 30;
565
+ display: flex;
566
+ flex-direction: column;
567
+ min-inline-size: 200px;
568
+ padding: 4px 0;
569
+ background: var(--color-surface-container);
570
+ border-radius: var(--shape-corner-small);
571
+ box-shadow: var(--elevation-level2);
572
+ }
573
+ .erd-picker button {
574
+ background: transparent;
575
+ border: none;
576
+ appearance: none;
577
+ margin: 0;
578
+ outline: none;
579
+ padding: 0;
580
+ display: flex;
581
+ align-items: center;
582
+ gap: 10px;
583
+ block-size: 36px;
584
+ padding: 0 12px;
585
+ font-size: 13px;
586
+ color: var(--color-on-surface);
587
+ cursor: pointer;
588
+ }
589
+ .erd-picker button:hover, .erd-picker button:focus-visible {
590
+ background: color-mix(in srgb, var(--color-on-surface) 8%, transparent);
591
+ outline: none;
592
+ }
593
+ .erd-picker button[aria-checked=true] {
594
+ background: var(--color-secondary-container);
595
+ color: var(--color-on-secondary-container);
596
+ }
597
+
598
+ /* stylelint-enable property-disallowed-list */
599
+ .erd-picker-icon {
600
+ inline-size: 48px;
601
+ block-size: 16px;
602
+ overflow: visible;
603
+ --_line: currentcolor;
604
+ }
605
+
606
+ .back-to-content {
607
+ position: absolute;
608
+ inset-inline-start: 50%;
609
+ inset-block-end: 24px;
610
+ transform: translateX(-50%);
611
+ box-shadow: var(--elevation-level2);
612
+ border-radius: var(--shape-corner-full);
613
+ z-index: 20;
614
+ }
615
+
616
+ .slot-controls,
617
+ .slot-minimap {
618
+ position: absolute;
619
+ inset-block-end: 16px;
620
+ z-index: 20;
621
+ }
622
+
623
+ .slot-controls {
624
+ inset-inline-start: 16px;
625
+ }
626
+
627
+ .slot-minimap {
628
+ inset-inline-end: 16px;
629
+ }
630
+
631
+ @container diagram (max-width: 480px) {
632
+ .slot-minimap {
633
+ display: none;
634
+ }
635
+ .slot-controls {
636
+ inset-inline-start: 8px;
637
+ inset-block-end: 8px;
638
+ }
639
+ }
640
+ .sr-only {
641
+ position: absolute;
642
+ inline-size: 1px;
643
+ block-size: 1px;
644
+ padding: 0;
645
+ margin: -1px;
646
+ overflow: hidden;
647
+ clip-path: inset(50%);
648
+ white-space: nowrap;
649
+ border: 0;
650
+ }
651
+
652
+ @keyframes erd-draw {
653
+ from {
654
+ stroke-dashoffset: 1;
655
+ }
656
+ to {
657
+ stroke-dashoffset: 0;
658
+ }
659
+ }
660
+ @keyframes erd-pop {
661
+ from {
662
+ opacity: 0;
663
+ transform: scale(0.92);
664
+ }
665
+ to {
666
+ opacity: 1;
667
+ transform: scale(1);
668
+ }
669
+ }
670
+ @media (prefers-reduced-motion: reduce) {
671
+ .erd-entity,
672
+ .erd-relation,
673
+ .erd-port,
674
+ .erd-remove {
675
+ transition: none;
676
+ }
677
+ .erd-entity.is-fresh,
678
+ .erd-relation.is-fresh .erd-line {
679
+ animation: none;
680
+ }
681
+ }`;
682
+
683
+ /** Fixed sizes, so relations can be routed to rows without measuring. */
684
+ const WIDTH = 264;
685
+ const BORDER = 1;
686
+ const HEADER = 48;
687
+ const ROW = 28;
688
+ /** Space above the first row and below the last. */
689
+ const ROWS_PADDING = 4;
690
+ const ADD_ROW = 32;
691
+ const DRAG_THRESHOLD = 4;
692
+ const INTERACTIVE = 'button, a, input, wc-icon-button';
693
+ /** Below this zoom, rows are drawn as bars. */
694
+ const FAR_ZOOM = 0.4;
695
+ const CARDINALITY_PRESETS = [
696
+ { key: 'erdManyToOne', source: 'many', target: 'one' },
697
+ { key: 'erdZeroOrManyToOne', source: 'zero-or-many', target: 'one' },
698
+ { key: 'erdOneToOne', source: 'one', target: 'one' },
699
+ { key: 'erdZeroOrOneToOne', source: 'zero-or-one', target: 'one' },
700
+ { key: 'erdManyToMany', source: 'many', target: 'many' },
701
+ ];
702
+ let relationCounter = 0;
703
+ /**
704
+ * @label ERD
705
+ * @tag wc-erd
706
+ * @rawTag erd
707
+ * @summary An entity-relationship diagram: tables with their columns, joined by crow's-foot relations.
708
+ *
709
+ * @overview
710
+ * <p>Set <code>entities</code> (each with <code>columns</code>) and <code>relations</code>. A relation
711
+ * runs from the entity holding the foreign key (<code>source</code>, <code>sourceColumn</code>) to the
712
+ * one it references (<code>target</code>, <code>targetColumn</code>), and its ends show crow's-foot
713
+ * cardinality (many to one by default). Lines join the column rows and route at right angles. Primary
714
+ * keys show a key, foreign keys a link. Hover an entity or a column to highlight what it is joined to.</p>
715
+ * <p>Entities without a <code>position</code> are laid out automatically: referenced tables to the left
716
+ * of the tables that reference them. Collapse an entity to its header with the chevron (or Shift+Enter);
717
+ * the layout closes the gap. <code>schema</code> shows one schema, and <code>focused-node</code> with
718
+ * <code>hops</code> shows one entity's neighbourhood (press F on an entity). Zoomed far out, rows
719
+ * become bars.</p>
720
+ * <p>With <code>editable</code>: double-click a name or type to rename it (F2 on an entity), add and
721
+ * remove columns, click a row's key to toggle the primary key, drag the ring at a row's end onto
722
+ * another row to add a relation and pick its cardinality, and delete with Delete. Every edit fires
723
+ * <code>change</code> with the new <code>entities</code> and <code>relations</code>; undo with Ctrl+Z.</p>
724
+ * <p>Entities are one tab stop: arrow keys move to the nearest entity in that direction, Enter selects.
725
+ * The canvas is infinite like <code>wc-diagram</code>, with the <code>controls</code> and
726
+ * <code>minimap</code> slots.</p>
727
+ *
728
+ * @example
729
+ * ```html
730
+ * <wc-erd id="schema" style="height: 480px"></wc-erd>
731
+ * <script>
732
+ * const erd = document.getElementById('schema');
733
+ * erd.entities = [
734
+ * { id: 'customers', name: 'customers', columns: [
735
+ * { name: 'id', type: 'uuid', pk: true }, { name: 'email', type: 'text' }] },
736
+ * { id: 'orders', name: 'orders', columns: [
737
+ * { name: 'id', type: 'uuid', pk: true }, { name: 'customer_id', type: 'uuid' }] }
738
+ * ];
739
+ * erd.relations = [
740
+ * { id: 'r1', source: 'orders', sourceColumn: 'customer_id', target: 'customers', targetColumn: 'id' }
741
+ * ];
742
+ * </script>
743
+ * ```
744
+ *
745
+ * @slot controls - A `wc-diagram-controls`, shown at the bottom start corner.
746
+ * @slot minimap - A `wc-diagram-minimap`, shown at the bottom end corner.
747
+ *
748
+ * @fires {CustomEvent<ErdSelectDetail>} select - An entity or relation was chosen. Detail contains `{ id, kind, entity, relation }`.
749
+ * @fires {CustomEvent<ErdMoveDetail>} entity-move - A dragged entity was dropped. Detail contains `{ id, position }`.
750
+ * @fires {CustomEvent<ErdToggleDetail>} toggle - An entity was collapsed or expanded. Detail contains `{ id, collapsed }`.
751
+ * @fires {CustomEvent<ErdConnectDetail>} connect - A relation is about to be added by dragging. Cancelable. Detail contains `{ relation }`.
752
+ * @fires {CustomEvent<ErdDeleteDetail>} delete - Entities or relations are about to be deleted. Cancelable. Detail contains `{ entities, relations }`.
753
+ * @fires {CustomEvent<ErdChangeDetail>} change - An edit was made. Detail contains `{ entities, relations, reason }`.
754
+ * @fires {CustomEvent<ErdFocusDetail>} focus-change - Focus mode was turned on or off with the keyboard. Detail contains `{ id, hops }`.
755
+ * @fires {CustomEvent<ErdViewportDetail>} viewport-change - Once per frame while the camera moves and once when it settles. Detail contains `{ x, y, zoom, settled }`.
756
+ *
757
+ * @cssprop --erd-relation-color - Colour of relations. Defaults to outline.
758
+ * @cssprop --erd-highlight-color - Colour of highlighted relations and rows. Defaults to primary.
759
+ * @cssprop --erd-background - Canvas background. Defaults to surface-container-lowest.
760
+ * @tags data
761
+ */
762
+ let Erd = class Erd extends DiagramCanvasElement {
763
+ constructor() {
764
+ // ── Static
765
+ super(...arguments);
766
+ // ── Properties
767
+ this.entities = [];
768
+ this.relations = [];
769
+ /** Shows only the entities of this schema. */
770
+ this.schema = '';
771
+ /** Shows only the entities within `hops` relations of this entity. */
772
+ this.focusedNode = '';
773
+ /** How far focus mode reaches. */
774
+ this.hops = 1;
775
+ /** Id of the selected entity or relation. */
776
+ this.selected = '';
777
+ // ── State
778
+ this._collapsed = new Set();
779
+ this._focusId = '';
780
+ this._announcement = '';
781
+ this._fresh = new Set();
782
+ this.history = new History();
783
+ this.visible = [];
784
+ this.visibleIds = new Set();
785
+ this.byId = new Map();
786
+ this.positions = new Map();
787
+ this.overrides = new Map();
788
+ this.pinned = new Map();
789
+ this.layoutKey = '';
790
+ this.seen = new Set();
791
+ this.onViewportKeyDown = (event) => {
792
+ if (event.defaultPrevented)
793
+ return;
794
+ const mod = event.ctrlKey || event.metaKey;
795
+ const key = event.key.toLowerCase();
796
+ if (key === 'escape') {
797
+ event.preventDefault();
798
+ if (this._picker)
799
+ this._picker = undefined;
800
+ else if (this.focusedNode) {
801
+ this.focusedNode = '';
802
+ this.emit('focus-change', {
803
+ id: null,
804
+ hops: this.hops,
805
+ });
806
+ }
807
+ else
808
+ this.selected = '';
809
+ return;
810
+ }
811
+ if (mod && key === 'z' && !event.shiftKey) {
812
+ event.preventDefault();
813
+ this.undo();
814
+ return;
815
+ }
816
+ if (mod && (key === 'y' || (key === 'z' && event.shiftKey))) {
817
+ event.preventDefault();
818
+ this.redo();
819
+ return;
820
+ }
821
+ if ((key === 'delete' || key === 'backspace') &&
822
+ this.canEdit &&
823
+ this.relations.some(r => r.id === this.selected)) {
824
+ event.preventDefault();
825
+ this.deleteItems([this.selected]);
826
+ return;
827
+ }
828
+ this.handleCanvasKey(event);
829
+ };
830
+ this.onDragMove = (event) => {
831
+ const { drag } = this;
832
+ if (!drag || event.pointerId !== drag.pointerId || this.readonly)
833
+ return;
834
+ const { zoom } = this.viewport.view;
835
+ const dx = (event.clientX - drag.startX) / zoom;
836
+ const dy = (event.clientY - drag.startY) / zoom;
837
+ if (!drag.moved && Math.hypot(dx * zoom, dy * zoom) < DRAG_THRESHOLD)
838
+ return;
839
+ drag.moved = true;
840
+ const position = {
841
+ x: Math.round(drag.origin.x + dx),
842
+ y: Math.round(drag.origin.y + dy),
843
+ };
844
+ this.positions.set(drag.id, position);
845
+ this.pinned.set(drag.id, position);
846
+ this.requestUpdate();
847
+ };
848
+ this.onDragUp = (event) => {
849
+ const { drag } = this;
850
+ if (!drag || event.pointerId !== drag.pointerId)
851
+ return;
852
+ this.drag = undefined;
853
+ drag.element.removeEventListener('pointermove', this.onDragMove);
854
+ drag.element.removeEventListener('pointerup', this.onDragUp);
855
+ drag.element.removeEventListener('pointercancel', this.onDragUp);
856
+ try {
857
+ if (drag.element.hasPointerCapture(drag.pointerId)) {
858
+ drag.element.releasePointerCapture(drag.pointerId);
859
+ }
860
+ }
861
+ catch {
862
+ // The pointer is already gone.
863
+ }
864
+ if (!drag.moved) {
865
+ this.selectItem(drag.id);
866
+ return;
867
+ }
868
+ const position = this.topLeft(drag.id);
869
+ // The layout key changes now that the entity is pinned; keep everything else where it is.
870
+ this.layoutKey = '';
871
+ this.runLayout();
872
+ this.emit('entity-move', { id: drag.id, position });
873
+ if (this.canEdit) {
874
+ this.updateEntity(drag.id, e => ({ ...e, position }), 'move');
875
+ }
876
+ };
877
+ }
878
+ // ── Lifecycle
879
+ disconnectedCallback() {
880
+ super.disconnectedCallback();
881
+ this.stopGlide?.();
882
+ }
883
+ willUpdate(changed) {
884
+ super.willUpdate(changed);
885
+ if (changed.has('entities')) {
886
+ let next;
887
+ for (const e of this.entities) {
888
+ if (!this.seen.has(e.id)) {
889
+ this.seen.add(e.id);
890
+ if (e.collapsed) {
891
+ next = next ?? new Set(this._collapsed);
892
+ next.add(e.id);
893
+ }
894
+ }
895
+ if (e.position)
896
+ this.pinned.set(e.id, e.position);
897
+ }
898
+ if (next)
899
+ this._collapsed = next;
900
+ this.byId = new Map(this.entities.map(e => [e.id, e]));
901
+ }
902
+ if ([
903
+ 'entities',
904
+ 'relations',
905
+ 'schema',
906
+ 'focusedNode',
907
+ 'hops',
908
+ 'editable',
909
+ '_collapsed',
910
+ ].some(k => changed.has(k))) {
911
+ this.computeVisible();
912
+ this.runLayout();
913
+ }
914
+ }
915
+ updated(changed) {
916
+ super.updated(changed);
917
+ if (changed.has('_editing') && this._editing) {
918
+ const input = this.renderRoot.querySelector('.erd-input');
919
+ input?.focus();
920
+ input?.select();
921
+ }
922
+ }
923
+ // ── Public API
924
+ get canUndo() {
925
+ return this.editable && !this.readonly && this.history.canUndo;
926
+ }
927
+ get canRedo() {
928
+ return this.editable && !this.readonly && this.history.canRedo;
929
+ }
930
+ undo() {
931
+ if (!this.canUndo)
932
+ return;
933
+ const previous = this.history.undo(this.snapshot());
934
+ if (previous)
935
+ this.restore(previous, 'undo');
936
+ }
937
+ redo() {
938
+ if (!this.canRedo)
939
+ return;
940
+ const next = this.history.redo(this.snapshot());
941
+ if (next)
942
+ this.restore(next, 'redo');
943
+ }
944
+ /** Lays every entity out again, forgetting dragged and given positions. */
945
+ autoLayout() {
946
+ this.pinned.clear();
947
+ this.layoutKey = '';
948
+ this.runLayout();
949
+ this.requestUpdate();
950
+ }
951
+ collapse(id) {
952
+ this.toggle(id, true);
953
+ }
954
+ expand(id) {
955
+ this.toggle(id, false);
956
+ }
957
+ collapseAll() {
958
+ this._collapsed = new Set(this.entities.map(e => e.id));
959
+ }
960
+ expandAll() {
961
+ this._collapsed = new Set();
962
+ }
963
+ /** Selects an entity as a click would and brings it into view. */
964
+ selectEntity(id) {
965
+ const entity = this.byId.get(id);
966
+ if (!entity || !this.visibleIds.has(id))
967
+ return;
968
+ this.selectItem(id);
969
+ this.moveFocusTo(id);
970
+ }
971
+ /** Adds an entity at the centre of the view (or at its `position`) and starts renaming it. */
972
+ addEntity(entity = {}) {
973
+ const view = this.viewport.visibleRect();
974
+ const id = entity.id ?? this.uniqueId('entity');
975
+ const created = {
976
+ name: this.i18n.t('erdNewEntity'),
977
+ columns: [{ name: 'id', type: 'uuid', pk: true }],
978
+ ...entity,
979
+ id,
980
+ position: entity.position ?? {
981
+ x: Math.round(view.x + view.width / 2 - WIDTH / 2),
982
+ y: Math.round(view.y + view.height / 2 - 60),
983
+ },
984
+ };
985
+ this.markFresh(id);
986
+ this.commit([...this.entities, created], this.relations, 'entity-add');
987
+ if (this.editable)
988
+ this._editing = { entity: id, field: 'name' };
989
+ this._focusId = id;
990
+ return created;
991
+ }
992
+ /** Adds a relation as a drag would, firing the cancelable `connect` first. Returns whether it was added. */
993
+ addRelation(relation) {
994
+ const created = {
995
+ sourceCardinality: 'many',
996
+ targetCardinality: 'one',
997
+ ...relation,
998
+ id: relation.id ?? this.uniqueId('relation'),
999
+ };
1000
+ if (!this.emit('connect', { relation: created }, true))
1001
+ return false;
1002
+ this.markFresh(created.id);
1003
+ this.commit(this.entities, [...this.relations, created], 'connect');
1004
+ const name = (r) => {
1005
+ const e = this.byId.get(r.entity);
1006
+ return r.column ? `${e?.name}.${r.column}` : (e?.name ?? r.entity);
1007
+ };
1008
+ this.announce(this.i18n.t('erdConnected')(name({ entity: created.source, column: created.sourceColumn }), name({ entity: created.target, column: created.targetColumn })));
1009
+ return true;
1010
+ }
1011
+ /** Deletes entities (with their relations) and relations, firing the cancelable `delete` first. */
1012
+ deleteItems(ids) {
1013
+ const entityIds = ids.filter(id => this.byId.has(id));
1014
+ const relationIds = new Set(ids.filter(id => this.relations.some(r => r.id === id)));
1015
+ for (const r of this.relations) {
1016
+ if (entityIds.includes(r.source) || entityIds.includes(r.target))
1017
+ relationIds.add(r.id);
1018
+ }
1019
+ if (!entityIds.length && !relationIds.size)
1020
+ return;
1021
+ const detail = { entities: entityIds, relations: [...relationIds] };
1022
+ if (!this.emit('delete', detail, true))
1023
+ return;
1024
+ const apply = () => {
1025
+ if (this.selected && ids.includes(this.selected))
1026
+ this.selected = '';
1027
+ this.commit(this.entities.filter(e => !entityIds.includes(e.id)), this.relations.filter(r => !relationIds.has(r.id)), 'delete');
1028
+ };
1029
+ const elements = entityIds
1030
+ .map(id => this.entityElement(id))
1031
+ .filter((el) => !!el);
1032
+ animateOut(elements, apply);
1033
+ }
1034
+ // ── Canvas hooks
1035
+ viewportElement() {
1036
+ return this._viewportEl;
1037
+ }
1038
+ contentBounds() {
1039
+ return boundsOf(this.visible.map(e => this.rectOf(e.id)));
1040
+ }
1041
+ selectionRects() {
1042
+ if (this.visibleIds.has(this.selected))
1043
+ return [this.rectOf(this.selected)];
1044
+ const r = this.relations.find(x => x.id === this.selected);
1045
+ return r && this.visibleIds.has(r.source) && this.visibleIds.has(r.target)
1046
+ ? [this.rectOf(r.source), this.rectOf(r.target)]
1047
+ : [];
1048
+ }
1049
+ itemRect(id) {
1050
+ return this.visibleIds.has(id) ? this.rectOf(id) : undefined;
1051
+ }
1052
+ firstItemRect() {
1053
+ const first = this.visible[0];
1054
+ return first ? this.rectOf(first.id) : undefined;
1055
+ }
1056
+ overviewItems() {
1057
+ return this.visible.map(e => ({
1058
+ ...this.rectOf(e.id),
1059
+ selected: e.id === this.selected,
1060
+ }));
1061
+ }
1062
+ isBackground(target) {
1063
+ const el = target;
1064
+ if (!el)
1065
+ return false;
1066
+ return (el === this._viewportEl ||
1067
+ ['erd-world', 'erd-relations', 'erd-entities'].some(c => el.classList?.contains(c)));
1068
+ }
1069
+ onBackgroundClick() {
1070
+ this.selected = '';
1071
+ this._picker = undefined;
1072
+ }
1073
+ // ── Private methods: model
1074
+ snapshot() {
1075
+ return { entities: this.entities, relations: this.relations };
1076
+ }
1077
+ restore(s, reason) {
1078
+ this.entities = s.entities;
1079
+ this.relations = s.relations;
1080
+ this.emit('change', { ...s, reason });
1081
+ }
1082
+ commit(entities, relations, reason) {
1083
+ this.history.push(this.snapshot());
1084
+ this.entities = entities;
1085
+ this.relations = relations;
1086
+ this.emit('change', { entities, relations, reason });
1087
+ }
1088
+ updateEntity(id, update, reason) {
1089
+ this.commit(this.entities.map(e => (e.id === id ? update(e) : e)), this.relations, reason);
1090
+ }
1091
+ uniqueId(prefix) {
1092
+ relationCounter += 1;
1093
+ const taken = new Set([
1094
+ ...this.entities.map(e => e.id),
1095
+ ...this.relations.map(r => r.id),
1096
+ ]);
1097
+ let id = `${prefix}-${relationCounter}`;
1098
+ while (taken.has(id)) {
1099
+ relationCounter += 1;
1100
+ id = `${prefix}-${relationCounter}`;
1101
+ }
1102
+ return id;
1103
+ }
1104
+ markFresh(id) {
1105
+ if (prefersReducedMotion())
1106
+ return;
1107
+ this._fresh = new Set([...this._fresh, id]);
1108
+ setTimeout(() => {
1109
+ const next = new Set(this._fresh);
1110
+ next.delete(id);
1111
+ this._fresh = next;
1112
+ }, 600);
1113
+ }
1114
+ computeVisible() {
1115
+ let shown = this.entities.filter(e => !this.schema || e.schema === this.schema);
1116
+ const ids = new Set(shown.map(e => e.id));
1117
+ if (this.focusedNode && ids.has(this.focusedNode)) {
1118
+ const near = withinHops(this.focusedNode, this.relations.filter(r => ids.has(r.source) && ids.has(r.target)), this.hops);
1119
+ shown = shown.filter(e => near.has(e.id));
1120
+ }
1121
+ this.visible = shown;
1122
+ this.visibleIds = new Set(shown.map(e => e.id));
1123
+ if (this.visibleIds.size && !this.visibleIds.has(this.selected)) {
1124
+ if (!this.relations.some(r => r.id === this.selected))
1125
+ this.selected = '';
1126
+ }
1127
+ }
1128
+ heightOf(e) {
1129
+ const frame = HEADER + BORDER * 2;
1130
+ if (this._collapsed.has(e.id))
1131
+ return frame;
1132
+ return (frame +
1133
+ e.columns.length * ROW +
1134
+ ROWS_PADDING * 2 +
1135
+ (this.editable && !this.readonly ? ADD_ROW : 0));
1136
+ }
1137
+ runLayout() {
1138
+ const relations = this.relations.filter(r => this.visibleIds.has(r.source) && this.visibleIds.has(r.target));
1139
+ const key = [
1140
+ this.visible
1141
+ .map(e => `${e.id}:${this.heightOf(e)}:${this.pinned.has(e.id) ? 'p' : ''}`)
1142
+ .join(','),
1143
+ relations.map(r => `${r.source}>${r.target}`).join(','),
1144
+ ].join('|');
1145
+ if (key === this.layoutKey)
1146
+ return;
1147
+ this.layoutKey = key;
1148
+ const next = layoutEntities(this.visible.map(e => ({
1149
+ id: e.id,
1150
+ height: this.heightOf(e),
1151
+ pinned: this.pinned.get(e.id),
1152
+ })), relations, { width: WIDTH });
1153
+ this.glide(this.positions, next);
1154
+ this.positions = next;
1155
+ }
1156
+ glide(from, to) {
1157
+ this.stopGlide?.();
1158
+ this.overrides.clear();
1159
+ if (!from.size || prefersReducedMotion() || !this.startApplied)
1160
+ return;
1161
+ const moving = [...to].filter(([id, p]) => {
1162
+ const f = from.get(id);
1163
+ return f && (f.x !== p.x || f.y !== p.y);
1164
+ });
1165
+ if (!moving.length)
1166
+ return;
1167
+ this.stopGlide = tween({
1168
+ duration: 400,
1169
+ easing: easeInOutCubic,
1170
+ onUpdate: t => {
1171
+ for (const [id, p] of moving) {
1172
+ const f = from.get(id) ?? p;
1173
+ this.overrides.set(id, {
1174
+ x: f.x + (p.x - f.x) * t,
1175
+ y: f.y + (p.y - f.y) * t,
1176
+ });
1177
+ }
1178
+ this.requestUpdate();
1179
+ },
1180
+ onDone: () => {
1181
+ this.overrides.clear();
1182
+ this.stopGlide = undefined;
1183
+ this.requestUpdate();
1184
+ },
1185
+ });
1186
+ }
1187
+ topLeft(id) {
1188
+ return this.overrides.get(id) ?? this.positions.get(id) ?? { x: 0, y: 0 };
1189
+ }
1190
+ rectOf(id) {
1191
+ const p = this.topLeft(id);
1192
+ const e = this.byId.get(id);
1193
+ return {
1194
+ x: p.x,
1195
+ y: p.y,
1196
+ width: WIDTH,
1197
+ height: e ? this.heightOf(e) : HEADER,
1198
+ };
1199
+ }
1200
+ /** The y of a column row's middle, or the header's when the row is hidden or missing. */
1201
+ rowY(entity, column) {
1202
+ const top = this.topLeft(entity.id).y + BORDER;
1203
+ const index = column
1204
+ ? entity.columns.findIndex(c => c.name === column)
1205
+ : -1;
1206
+ if (index < 0 || this._collapsed.has(entity.id))
1207
+ return top + HEADER / 2;
1208
+ return top + HEADER + ROWS_PADDING + index * ROW + ROW / 2;
1209
+ }
1210
+ foreignKeys(entityId) {
1211
+ const out = new Set();
1212
+ for (const r of this.relations)
1213
+ if (r.source === entityId && r.sourceColumn)
1214
+ out.add(r.sourceColumn);
1215
+ return out;
1216
+ }
1217
+ related(id) {
1218
+ const name = (x) => this.byId.get(x)?.name ?? x;
1219
+ return {
1220
+ references: [
1221
+ ...new Set(this.relations.filter(r => r.source === id).map(r => name(r.target))),
1222
+ ],
1223
+ referencedBy: [
1224
+ ...new Set(this.relations.filter(r => r.target === id).map(r => name(r.source))),
1225
+ ],
1226
+ };
1227
+ }
1228
+ /** Relations and rows lit by the hovered entity or column. */
1229
+ highlight() {
1230
+ const h = this._hover;
1231
+ if (!h || this._connecting || this.drag?.moved)
1232
+ return undefined;
1233
+ const relations = new Set();
1234
+ const entities = new Set([h.entity]);
1235
+ const rows = new Set();
1236
+ for (const r of this.relations) {
1237
+ const fromHere = r.source === h.entity && (!h.column || r.sourceColumn === h.column);
1238
+ const toHere = r.target === h.entity && (!h.column || r.targetColumn === h.column);
1239
+ if (fromHere || toHere) {
1240
+ relations.add(r.id);
1241
+ entities.add(r.source);
1242
+ entities.add(r.target);
1243
+ if (r.sourceColumn)
1244
+ rows.add(`${r.source}\u0000${r.sourceColumn}`);
1245
+ if (r.targetColumn)
1246
+ rows.add(`${r.target}\u0000${r.targetColumn}`);
1247
+ }
1248
+ }
1249
+ return { relations, entities, rows };
1250
+ }
1251
+ // ── Private methods: interaction
1252
+ announce(message) {
1253
+ this._announcement = '';
1254
+ requestAnimationFrame(() => {
1255
+ this._announcement = message;
1256
+ });
1257
+ }
1258
+ selectItem(id) {
1259
+ this.selected = id;
1260
+ const entity = this.byId.get(id);
1261
+ const relation = entity ? undefined : this.relations.find(r => r.id === id);
1262
+ this.emit('select', {
1263
+ id,
1264
+ kind: entity ? 'entity' : 'relation',
1265
+ entity,
1266
+ relation,
1267
+ });
1268
+ }
1269
+ moveFocusTo(id) {
1270
+ this._focusId = id;
1271
+ this.updateComplete.then(() => {
1272
+ this.entityElement(id)?.focus({ preventScroll: true });
1273
+ const r = this.itemRect(id);
1274
+ const view = this.viewport.visibleRect();
1275
+ if (r &&
1276
+ (r.x < view.x ||
1277
+ r.y < view.y ||
1278
+ r.x + r.width > view.x + view.width ||
1279
+ r.y + r.height > view.y + view.height)) {
1280
+ this.centerOn(r.x + r.width / 2, r.y + Math.min(r.height, 200) / 2);
1281
+ }
1282
+ });
1283
+ }
1284
+ toggle(id, collapsed) {
1285
+ if (this._collapsed.has(id) === collapsed)
1286
+ return;
1287
+ const next = new Set(this._collapsed);
1288
+ if (collapsed)
1289
+ next.add(id);
1290
+ else
1291
+ next.delete(id);
1292
+ this._collapsed = next;
1293
+ this.emit('toggle', { id, collapsed });
1294
+ }
1295
+ get canEdit() {
1296
+ return this.editable && !this.readonly;
1297
+ }
1298
+ startEdit(entity, field, column) {
1299
+ if (!this.canEdit)
1300
+ return;
1301
+ this._editing = { entity, column, field };
1302
+ }
1303
+ finishEdit(value) {
1304
+ const editing = this._editing;
1305
+ this._editing = undefined;
1306
+ if (!editing || value === undefined)
1307
+ return;
1308
+ const text = value.trim();
1309
+ const entity = this.byId.get(editing.entity);
1310
+ if (!entity || (!text && editing.field === 'name'))
1311
+ return;
1312
+ if (editing.column === undefined) {
1313
+ if (text !== entity.name)
1314
+ this.updateEntity(entity.id, e => ({ ...e, name: text }), 'rename');
1315
+ }
1316
+ else {
1317
+ const column = entity.columns[editing.column];
1318
+ if (!column)
1319
+ return;
1320
+ const field = editing.field === 'name' ? 'name' : 'type';
1321
+ if ((column[field] ?? '') === text)
1322
+ return;
1323
+ const oldName = column.name;
1324
+ this.commit(this.entities.map(e => e.id === entity.id
1325
+ ? {
1326
+ ...e,
1327
+ columns: e.columns.map((c, i) => i === editing.column ? { ...c, [field]: text } : c),
1328
+ }
1329
+ : e),
1330
+ // Relations follow a renamed column.
1331
+ field === 'name'
1332
+ ? this.relations.map(r => ({
1333
+ ...r,
1334
+ sourceColumn: r.source === entity.id && r.sourceColumn === oldName
1335
+ ? text
1336
+ : r.sourceColumn,
1337
+ targetColumn: r.target === entity.id && r.targetColumn === oldName
1338
+ ? text
1339
+ : r.targetColumn,
1340
+ }))
1341
+ : this.relations, field === 'name' ? 'rename' : 'column-update');
1342
+ }
1343
+ this.moveFocusTo(entity.id);
1344
+ }
1345
+ addColumn(entityId) {
1346
+ const entity = this.byId.get(entityId);
1347
+ if (!entity)
1348
+ return;
1349
+ const base = this.i18n.t('erdNewColumn');
1350
+ const taken = new Set(entity.columns.map(c => c.name));
1351
+ let name = base;
1352
+ for (let n = 2; taken.has(name); n += 1)
1353
+ name = `${base}_${n}`;
1354
+ this.updateEntity(entityId, e => ({
1355
+ ...e,
1356
+ columns: [...e.columns, { name, type: 'text', nullable: true }],
1357
+ }), 'column-add');
1358
+ this._editing = {
1359
+ entity: entityId,
1360
+ column: entity.columns.length,
1361
+ field: 'name',
1362
+ };
1363
+ }
1364
+ removeColumn(entityId, index) {
1365
+ const entity = this.byId.get(entityId);
1366
+ const column = entity?.columns[index];
1367
+ if (!entity || !column)
1368
+ return;
1369
+ this.commit(this.entities.map(e => e.id === entityId
1370
+ ? { ...e, columns: e.columns.filter((_, i) => i !== index) }
1371
+ : e), this.relations.filter(r => !(r.source === entityId && r.sourceColumn === column.name) &&
1372
+ !(r.target === entityId && r.targetColumn === column.name)), 'column-remove');
1373
+ }
1374
+ togglePrimaryKey(entityId, index) {
1375
+ this.updateEntity(entityId, e => ({
1376
+ ...e,
1377
+ columns: e.columns.map((c, i) => i === index ? { ...c, pk: !c.pk } : c),
1378
+ }), 'column-update');
1379
+ }
1380
+ setCardinality(id, source, target) {
1381
+ this._picker = undefined;
1382
+ this.commit(this.entities, this.relations.map(r => r.id === id
1383
+ ? { ...r, sourceCardinality: source, targetCardinality: target }
1384
+ : r), 'cardinality');
1385
+ }
1386
+ toCanvas(event) {
1387
+ const vr = this._viewportEl?.getBoundingClientRect();
1388
+ const { x, y, zoom } = this.viewport.view;
1389
+ return {
1390
+ x: (event.clientX - (vr?.left ?? 0) - x) / zoom,
1391
+ y: (event.clientY - (vr?.top ?? 0) - y) / zoom,
1392
+ };
1393
+ }
1394
+ onEntityKeyDown(event, entity) {
1395
+ if (event.target !== event.currentTarget)
1396
+ return;
1397
+ const done = (fn) => {
1398
+ event.preventDefault();
1399
+ event.stopPropagation();
1400
+ fn();
1401
+ };
1402
+ const { key } = event;
1403
+ const arrows = {
1404
+ ArrowUp: 'up',
1405
+ ArrowDown: 'down',
1406
+ ArrowLeft: 'left',
1407
+ ArrowRight: 'right',
1408
+ };
1409
+ if (key === 'Enter' && event.shiftKey) {
1410
+ done(() => this.toggle(entity.id, !this._collapsed.has(entity.id)));
1411
+ }
1412
+ else if (key === 'Enter' || key === ' ') {
1413
+ done(() => this.selectItem(entity.id));
1414
+ }
1415
+ else if (arrows[key]) {
1416
+ const next = nearestInDirection(this.rectOf(entity.id), this.visible
1417
+ .filter(e => e.id !== entity.id)
1418
+ .map(e => ({ id: e.id, rect: this.rectOf(e.id) })), arrows[key]);
1419
+ if (next)
1420
+ done(() => this.moveFocusTo(next.id));
1421
+ }
1422
+ else if (key === 'f' || key === 'F') {
1423
+ done(() => {
1424
+ const id = this.focusedNode === entity.id ? '' : entity.id;
1425
+ this.focusedNode = id;
1426
+ this.emit('focus-change', {
1427
+ id: id || null,
1428
+ hops: this.hops,
1429
+ });
1430
+ });
1431
+ }
1432
+ else if (key === 'F2' && this.canEdit) {
1433
+ done(() => this.startEdit(entity.id, 'name'));
1434
+ }
1435
+ else if ((key === 'Delete' || key === 'Backspace') && this.canEdit) {
1436
+ done(() => this.deleteItems([entity.id]));
1437
+ }
1438
+ }
1439
+ onEntityPointerDown(event, entity) {
1440
+ if (event.button !== 0 || this.viewport.spaceHeld)
1441
+ return;
1442
+ const origin = event.composedPath()[0];
1443
+ if (origin instanceof Element &&
1444
+ origin.closest(`${INTERACTIVE}, .erd-port`))
1445
+ return;
1446
+ event.stopPropagation();
1447
+ this._picker = undefined;
1448
+ const element = event.currentTarget;
1449
+ element.focus({ preventScroll: true });
1450
+ this._focusId = entity.id;
1451
+ this.drag = {
1452
+ pointerId: event.pointerId,
1453
+ startX: event.clientX,
1454
+ startY: event.clientY,
1455
+ id: entity.id,
1456
+ origin: this.topLeft(entity.id),
1457
+ element,
1458
+ moved: false,
1459
+ };
1460
+ try {
1461
+ element.setPointerCapture(event.pointerId);
1462
+ }
1463
+ catch {
1464
+ // Synthetic pointers cannot be captured.
1465
+ }
1466
+ element.addEventListener('pointermove', this.onDragMove);
1467
+ element.addEventListener('pointerup', this.onDragUp);
1468
+ element.addEventListener('pointercancel', this.onDragUp);
1469
+ }
1470
+ onPortPointerDown(event, entity, column) {
1471
+ if (event.button !== 0 || !this.canEdit)
1472
+ return;
1473
+ event.preventDefault();
1474
+ event.stopPropagation();
1475
+ const handle = event.currentTarget;
1476
+ const start = {
1477
+ x: this.topLeft(entity.id).x + WIDTH,
1478
+ y: this.rowY(entity, column.name),
1479
+ };
1480
+ this._connecting = {
1481
+ from: { entity: entity.id, column: column.name },
1482
+ start,
1483
+ side: 'right',
1484
+ pointer: this.toCanvas(event),
1485
+ };
1486
+ try {
1487
+ handle.setPointerCapture(event.pointerId);
1488
+ }
1489
+ catch {
1490
+ // Synthetic pointers cannot be captured.
1491
+ }
1492
+ const move = (e) => {
1493
+ if (this._connecting)
1494
+ this._connecting = { ...this._connecting, pointer: this.toCanvas(e) };
1495
+ };
1496
+ const up = (e) => {
1497
+ handle.removeEventListener('pointermove', move);
1498
+ handle.removeEventListener('pointerup', up);
1499
+ handle.removeEventListener('pointercancel', up);
1500
+ const connecting = this._connecting;
1501
+ this._connecting = undefined;
1502
+ if (!connecting || e.type === 'pointercancel')
1503
+ return;
1504
+ const target = this.rowAt(e.clientX, e.clientY);
1505
+ if (!target)
1506
+ return;
1507
+ const { from } = connecting;
1508
+ if (target.entity === from.entity && target.column === from.column)
1509
+ return;
1510
+ if (this.addRelation({
1511
+ source: from.entity,
1512
+ sourceColumn: from.column,
1513
+ target: target.entity,
1514
+ targetColumn: target.column,
1515
+ })) {
1516
+ const vr = this._viewportEl?.getBoundingClientRect();
1517
+ const created = this.relations[this.relations.length - 1];
1518
+ this._picker = {
1519
+ id: created.id,
1520
+ x: e.clientX - (vr?.left ?? 0),
1521
+ y: e.clientY - (vr?.top ?? 0),
1522
+ };
1523
+ }
1524
+ };
1525
+ handle.addEventListener('pointermove', move);
1526
+ handle.addEventListener('pointerup', up);
1527
+ handle.addEventListener('pointercancel', up);
1528
+ }
1529
+ /** The row (or entity header) under a screen point. */
1530
+ rowAt(clientX, clientY) {
1531
+ const root = this.renderRoot;
1532
+ const hits = root.elementsFromPoint?.(clientX, clientY) ?? [];
1533
+ for (const el of hits) {
1534
+ const row = el.closest?.('.erd-row');
1535
+ const card = el.closest?.('.erd-entity');
1536
+ if (row?.dataset.column !== undefined && card?.dataset.id) {
1537
+ return { entity: card.dataset.id, column: row.dataset.column };
1538
+ }
1539
+ if (card?.dataset.id)
1540
+ return { entity: card.dataset.id };
1541
+ }
1542
+ return undefined;
1543
+ }
1544
+ entityElement(id) {
1545
+ return this.renderRoot.querySelector(`.erd-entity[data-id="${CSS.escape(id)}"]`);
1546
+ }
1547
+ // ── Render helpers
1548
+ renderMarker(cardinality, at, angle) {
1549
+ return markerShapes(cardinality).map(s => w `<path class=${`erd-marker fill-${s.fill}`} d=${s.d} transform=${markerTransform(at, angle)}></path>`);
1550
+ }
1551
+ /**
1552
+ * A route between facing sides that avoids the entities in between: when the plain elbow would
1553
+ * cross one, the line turns in the gap next to each end and runs along the nearest free channel.
1554
+ * Returns `undefined` when the plain elbow is clear or no channel is found.
1555
+ */
1556
+ routeAround(start, end, sourceId, targetId) {
1557
+ const dir = end.x >= start.x ? 1 : -1;
1558
+ const margin = 14;
1559
+ const obstacles = this.visible
1560
+ .filter(e => e.id !== sourceId && e.id !== targetId)
1561
+ .map(e => inflateRect(this.rectOf(e.id), margin));
1562
+ const hits = (a, b) => {
1563
+ const x1 = Math.min(a.x, b.x);
1564
+ const x2 = Math.max(a.x, b.x);
1565
+ const y1 = Math.min(a.y, b.y);
1566
+ const y2 = Math.max(a.y, b.y);
1567
+ return obstacles.some(o => x1 < o.x + o.width && x2 > o.x && y1 < o.y + o.height && y2 > o.y);
1568
+ };
1569
+ const clear = (points) => points.every((p, i) => i === 0 || !hits(points[i - 1], p));
1570
+ const xm = (start.x + end.x) / 2;
1571
+ if (clear([start, { x: xm, y: start.y }, { x: xm, y: end.y }, end])) {
1572
+ return undefined;
1573
+ }
1574
+ const gapA = start.x + dir * 28;
1575
+ const gapB = end.x - dir * 28;
1576
+ const candidates = [
1577
+ start.y,
1578
+ end.y,
1579
+ ...obstacles.flatMap(o => [o.y - 1, o.y + o.height + 1]),
1580
+ ];
1581
+ let best;
1582
+ let bestCost = Infinity;
1583
+ for (const y of candidates) {
1584
+ const points = [
1585
+ start,
1586
+ { x: gapA, y: start.y },
1587
+ { x: gapA, y },
1588
+ { x: gapB, y },
1589
+ { x: gapB, y: end.y },
1590
+ end,
1591
+ ];
1592
+ const cost = Math.abs(y - start.y) + Math.abs(y - end.y);
1593
+ if (cost < bestCost && clear(points)) {
1594
+ best = points;
1595
+ bestCost = cost;
1596
+ }
1597
+ }
1598
+ if (!best)
1599
+ return undefined;
1600
+ return {
1601
+ d: roundedPath(best, 14),
1602
+ mid: polylineMidpoint(best),
1603
+ startAngle: dir > 0 ? Math.PI : 0,
1604
+ endAngle: dir > 0 ? 0 : Math.PI,
1605
+ };
1606
+ }
1607
+ renderRelations(lit, shown) {
1608
+ return this.relations
1609
+ .filter(r => this.visibleIds.has(r.source) && this.visibleIds.has(r.target))
1610
+ .filter(r => shown.has(r.source) || shown.has(r.target))
1611
+ .map(r => {
1612
+ const s = this.byId.get(r.source);
1613
+ const t = this.byId.get(r.target);
1614
+ const sp = this.topLeft(s.id);
1615
+ const tp = this.topLeft(t.id);
1616
+ let sSide = 'right';
1617
+ let tSide = 'left';
1618
+ if (tp.x + WIDTH + 40 < sp.x) {
1619
+ sSide = 'left';
1620
+ tSide = 'right';
1621
+ }
1622
+ else if (!(sp.x + WIDTH + 40 < tp.x)) {
1623
+ // Stacked in one column: both lines leave on the right and loop.
1624
+ tSide = 'right';
1625
+ }
1626
+ const start = {
1627
+ x: sSide === 'right' ? sp.x + WIDTH : sp.x,
1628
+ y: this.rowY(s, r.sourceColumn),
1629
+ };
1630
+ const end = {
1631
+ x: tSide === 'right' ? tp.x + WIDTH : tp.x,
1632
+ y: this.rowY(t, r.targetColumn),
1633
+ };
1634
+ const g = (sSide !== tSide && this.routeAround(start, end, s.id, t.id)) ||
1635
+ edgeGeometry('elbow', start, sSide, end, tSide, { radius: 14 });
1636
+ const on = !!lit?.relations.has(r.id);
1637
+ const selected = this.selected === r.id;
1638
+ return w `<g
1639
+ class=${e$1({
1640
+ 'erd-relation': true,
1641
+ 'is-lit': on,
1642
+ 'is-dim': !!lit && !on,
1643
+ 'is-selected': selected,
1644
+ 'is-fresh': this._fresh.has(r.id),
1645
+ })}
1646
+ data-id=${r.id}
1647
+ >
1648
+ <path class="erd-line" d=${g.d} pathLength="1"></path>
1649
+ ${this.renderMarker(r.sourceCardinality ?? 'many', start, g.startAngle)}
1650
+ ${this.renderMarker(r.targetCardinality ?? 'one', end, g.endAngle)}
1651
+ <path
1652
+ class="erd-hit"
1653
+ d=${g.d}
1654
+ @pointerdown=${(e) => e.stopPropagation()}
1655
+ @click=${() => this.selectItem(r.id)}
1656
+ ></path>
1657
+ ${r.label
1658
+ ? w `<text class="erd-relation-label" x=${g.mid.x} y=${g.mid.y - 6}>${r.label}</text>`
1659
+ : A}
1660
+ </g>`;
1661
+ });
1662
+ }
1663
+ renderPreview() {
1664
+ const c = this._connecting;
1665
+ if (!c)
1666
+ return A;
1667
+ const side = c.pointer.x >= c.start.x ? 'left' : 'right';
1668
+ const g = edgeGeometry('elbow', c.start, c.side, c.pointer, side, {
1669
+ radius: 14,
1670
+ });
1671
+ return w `<path class="erd-preview" d=${g.d}></path>`;
1672
+ }
1673
+ renderInput(value) {
1674
+ return b `<input
1675
+ class="erd-input"
1676
+ .value=${value}
1677
+ aria-label=${this.i18n.t('erdRename')}
1678
+ @pointerdown=${(e) => e.stopPropagation()}
1679
+ @keydown=${(e) => {
1680
+ e.stopPropagation();
1681
+ if (e.key === 'Enter')
1682
+ this.finishEdit(e.target.value);
1683
+ else if (e.key === 'Escape')
1684
+ this.finishEdit(undefined);
1685
+ }}
1686
+ @blur=${(e) => {
1687
+ if (this._editing)
1688
+ this.finishEdit(e.target.value);
1689
+ }}
1690
+ />`;
1691
+ }
1692
+ renderRow(entity, column, index, fks, lit) {
1693
+ const editing = this._editing;
1694
+ const editingName = editing?.entity === entity.id &&
1695
+ editing.column === index &&
1696
+ editing.field === 'name';
1697
+ const editingType = editing?.entity === entity.id &&
1698
+ editing.column === index &&
1699
+ editing.field === 'type';
1700
+ const fk = fks.has(column.name);
1701
+ let keyIcon = '';
1702
+ if (column.pk)
1703
+ keyIcon = 'key';
1704
+ else if (fk)
1705
+ keyIcon = 'link';
1706
+ let keyLabel = '';
1707
+ if (column.pk)
1708
+ keyLabel = this.i18n.t('erdPrimaryKey');
1709
+ else if (fk)
1710
+ keyLabel = this.i18n.t('erdForeignKey');
1711
+ const keyCell = this.canEdit
1712
+ ? b `<button
1713
+ type="button"
1714
+ class=${e$1({
1715
+ 'erd-key': true,
1716
+ 'is-pk': !!column.pk,
1717
+ 'is-fk': fk && !column.pk,
1718
+ })}
1719
+ aria-label=${this.i18n.t('erdTogglePrimaryKey')(column.name)}
1720
+ aria-pressed=${column.pk ? 'true' : 'false'}
1721
+ @click=${() => this.togglePrimaryKey(entity.id, index)}
1722
+ >
1723
+ <wc-icon name=${keyIcon || 'key'}></wc-icon>
1724
+ </button>`
1725
+ : b `<span
1726
+ class=${e$1({
1727
+ 'erd-key': true,
1728
+ 'is-pk': !!column.pk,
1729
+ 'is-fk': fk && !column.pk,
1730
+ })}
1731
+ title=${keyLabel}
1732
+ >${keyIcon
1733
+ ? b `<wc-icon name=${keyIcon}></wc-icon>`
1734
+ : A}</span
1735
+ >`;
1736
+ return b `<div
1737
+ class=${e$1({
1738
+ 'erd-row': true,
1739
+ 'is-lit': !!lit?.rows.has(`${entity.id}\u0000${column.name}`),
1740
+ 'is-hover': this._hover?.entity === entity.id &&
1741
+ this._hover.column === column.name,
1742
+ })}
1743
+ data-column=${column.name}
1744
+ title=${column.comment ?? A}
1745
+ @pointerenter=${() => {
1746
+ this._hover = { entity: entity.id, column: column.name };
1747
+ }}
1748
+ @pointerleave=${() => {
1749
+ this._hover = { entity: entity.id };
1750
+ }}
1751
+ >
1752
+ ${keyCell}
1753
+ ${editingName
1754
+ ? this.renderInput(column.name)
1755
+ : b `<span
1756
+ class="erd-col-name"
1757
+ @dblclick=${() => this.startEdit(entity.id, 'name', index)}
1758
+ >${column.name}${keyLabel
1759
+ ? b `<span class="sr-only">, ${keyLabel}</span>`
1760
+ : A}</span
1761
+ >`}
1762
+ ${editingType
1763
+ ? this.renderInput(column.type ?? '')
1764
+ : b `<span
1765
+ class="erd-col-type"
1766
+ @dblclick=${() => this.startEdit(entity.id, 'type', index)}
1767
+ >${column.type ?? ''}${column.nullable
1768
+ ? b `<span class="erd-null" title=${this.i18n.t('erdNullable')}
1769
+ >?</span
1770
+ >`
1771
+ : A}</span
1772
+ >`}
1773
+ ${this.canEdit
1774
+ ? b `<wc-icon-button
1775
+ class="erd-remove"
1776
+ variant="text"
1777
+ shape="round"
1778
+ size="xs"
1779
+ aria-label=${this.i18n.t('erdRemoveColumn')(column.name)}
1780
+ @click=${() => this.removeColumn(entity.id, index)}
1781
+ ><wc-icon name="close"></wc-icon
1782
+ ></wc-icon-button>
1783
+ <span
1784
+ class="erd-port"
1785
+ aria-hidden="true"
1786
+ @pointerdown=${(e) => this.onPortPointerDown(e, entity, column)}
1787
+ ></span>`
1788
+ : A}
1789
+ </div>`;
1790
+ }
1791
+ renderEntity(entity, focusId, lit) {
1792
+ const p = this.topLeft(entity.id);
1793
+ const collapsed = this._collapsed.has(entity.id);
1794
+ const fks = this.foreignKeys(entity.id);
1795
+ const { references, referencedBy } = this.related(entity.id);
1796
+ const editingName = this._editing?.entity === entity.id && this._editing.column === undefined;
1797
+ const selected = this.selected === entity.id;
1798
+ return b `<div
1799
+ class=${e$1({
1800
+ 'erd-entity': true,
1801
+ [`accent-${entity.accent ?? 'primary'}`]: true,
1802
+ 'is-selected': selected,
1803
+ 'is-collapsed': collapsed,
1804
+ 'is-lit': !!lit?.entities.has(entity.id) && lit.entities.size > 1,
1805
+ 'is-dim': !!lit && !lit.entities.has(entity.id),
1806
+ 'is-fresh': this._fresh.has(entity.id),
1807
+ 'is-focus': this.focusedNode === entity.id,
1808
+ })}
1809
+ data-id=${entity.id}
1810
+ role="button"
1811
+ aria-pressed=${selected ? 'true' : 'false'}
1812
+ aria-expanded=${collapsed ? 'false' : 'true'}
1813
+ aria-label=${this.i18n.t('erdEntity')(entity.schema ? `${entity.schema}.${entity.name}` : entity.name, entity.columns.length, references, referencedBy)}
1814
+ tabindex=${focusId === entity.id ? '0' : '-1'}
1815
+ style="left: ${p.x}px; top: ${p.y}px; width: ${WIDTH}px;"
1816
+ @pointerdown=${(e) => this.onEntityPointerDown(e, entity)}
1817
+ @pointerenter=${() => {
1818
+ this._hover = { entity: entity.id };
1819
+ }}
1820
+ @pointerleave=${() => {
1821
+ this._hover = undefined;
1822
+ }}
1823
+ @keydown=${(e) => this.onEntityKeyDown(e, entity)}
1824
+ @focus=${() => {
1825
+ this._focusId = entity.id;
1826
+ }}
1827
+ >
1828
+ <div class="erd-header">
1829
+ <span class="erd-tile"
1830
+ ><wc-icon name=${entity.icon ?? 'table'}></wc-icon
1831
+ ></span>
1832
+ <span class="erd-title" title=${entity.comment ?? A}>
1833
+ ${entity.schema
1834
+ ? b `<span class="erd-schema">${entity.schema}.</span>`
1835
+ : A}
1836
+ ${editingName
1837
+ ? this.renderInput(entity.name)
1838
+ : b `<span
1839
+ class="erd-name"
1840
+ @dblclick=${() => this.startEdit(entity.id, 'name')}
1841
+ >${entity.name}</span
1842
+ >`}
1843
+ </span>
1844
+ ${collapsed
1845
+ ? b `<span class="erd-count"
1846
+ >${this.i18n.t('erdColumnCount')(entity.columns.length)}</span
1847
+ >`
1848
+ : A}
1849
+ <wc-icon-button
1850
+ class="erd-toggle"
1851
+ variant="text"
1852
+ shape="round"
1853
+ size="xs"
1854
+ tabindex="-1"
1855
+ aria-label=${this.i18n.t(collapsed ? 'erdExpand' : 'erdCollapse')(entity.name)}
1856
+ @click=${() => this.toggle(entity.id, !collapsed)}
1857
+ ><wc-icon
1858
+ name=${collapsed ? 'keyboard_arrow_down' : 'keyboard_arrow_up'}
1859
+ ></wc-icon
1860
+ ></wc-icon-button>
1861
+ </div>
1862
+ ${collapsed
1863
+ ? A
1864
+ : b `<div class="erd-rows">
1865
+ ${entity.columns.map((c, i) => this.renderRow(entity, c, i, fks, lit))}
1866
+ ${this.canEdit
1867
+ ? b `<button
1868
+ type="button"
1869
+ class="erd-add"
1870
+ @click=${() => this.addColumn(entity.id)}
1871
+ >
1872
+ <wc-icon name="add"></wc-icon>${this.i18n.t('erdAddColumn')}
1873
+ </button>`
1874
+ : A}
1875
+ </div>`}
1876
+ </div>`;
1877
+ }
1878
+ renderPicker() {
1879
+ const picker = this._picker;
1880
+ if (!picker)
1881
+ return A;
1882
+ const relation = this.relations.find(r => r.id === picker.id);
1883
+ if (!relation)
1884
+ return A;
1885
+ return b `<div
1886
+ class="erd-picker"
1887
+ role="menu"
1888
+ aria-label=${this.i18n.t('erdCardinality')}
1889
+ data-diagram-overlay
1890
+ style="left: ${picker.x + 8}px; top: ${picker.y + 8}px;"
1891
+ @pointerdown=${(e) => e.stopPropagation()}
1892
+ >
1893
+ ${CARDINALITY_PRESETS.map(preset => b `<button
1894
+ type="button"
1895
+ role="menuitemradio"
1896
+ aria-checked=${relation.sourceCardinality === preset.source &&
1897
+ relation.targetCardinality === preset.target
1898
+ ? 'true'
1899
+ : 'false'}
1900
+ @click=${() => this.setCardinality(relation.id, preset.source, preset.target)}
1901
+ >
1902
+ <svg
1903
+ class="erd-picker-icon"
1904
+ viewBox="-30 -10 60 20"
1905
+ aria-hidden="true"
1906
+ >
1907
+ <path class="erd-line" d="M -26 0 L 26 0"></path>
1908
+ ${this.renderMarker(preset.source, { x: -26, y: 0 }, Math.PI)}
1909
+ ${this.renderMarker(preset.target, { x: 26, y: 0 }, 0)}
1910
+ </svg>
1911
+ ${this.i18n.t(preset.key)}
1912
+ </button>`)}
1913
+ </div>`;
1914
+ }
1915
+ // ── Render
1916
+ render() {
1917
+ const { x, y, zoom } = this.viewport.view;
1918
+ const lit = this.highlight();
1919
+ const focusId = this.visibleIds.has(this._focusId)
1920
+ ? this._focusId
1921
+ : (this.visible[0]?.id ?? '');
1922
+ const shown = new Set(this.visible
1923
+ .filter(e => this.nearView(this.rectOf(e.id)) ||
1924
+ e.id === focusId ||
1925
+ e.id === this.selected)
1926
+ .map(e => e.id));
1927
+ return b `
1928
+ <div
1929
+ class=${e$1({
1930
+ 'erd-viewport': true,
1931
+ 'lod-far': zoom < FAR_ZOOM,
1932
+ 'is-panning': this.viewport.panning,
1933
+ 'is-space': this.viewport.spaceHeld,
1934
+ 'is-connecting': !!this._connecting,
1935
+ 'is-editable': this.canEdit,
1936
+ })}
1937
+ tabindex="0"
1938
+ role="region"
1939
+ aria-label=${this.label || this.i18n.t('erdLabel')}
1940
+ aria-describedby="instructions"
1941
+ style=${this.gridStyle()}
1942
+ @keydown=${this.onViewportKeyDown}
1943
+ >
1944
+ <div
1945
+ class="erd-world"
1946
+ style="transform: translate(${x}px, ${y}px) scale(${zoom}); --_zoom: ${zoom};"
1947
+ >
1948
+ <svg class="erd-relations" width="1" height="1" aria-hidden="true">
1949
+ ${this.renderRelations(lit, shown)} ${this.renderPreview()}
1950
+ </svg>
1951
+ <div
1952
+ class="erd-entities"
1953
+ role="group"
1954
+ aria-label=${this.label || this.i18n.t('erdLabel')}
1955
+ >
1956
+ ${c(this.visible.filter(e => shown.has(e.id)), e => e.id, e => this.renderEntity(e, focusId, lit))}
1957
+ </div>
1958
+ </div>
1959
+ ${this.renderPicker()} ${this.renderBackToContent()}
1960
+ <div class="slot-controls"><slot name="controls"></slot></div>
1961
+ <div class="slot-minimap"><slot name="minimap"></slot></div>
1962
+ <div id="instructions" hidden>
1963
+ ${this.i18n.t('diagramInstructions')}
1964
+ </div>
1965
+ <div class="sr-only" aria-live="polite">${this._announcement}</div>
1966
+ </div>
1967
+ `;
1968
+ }
1969
+ };
1970
+ Erd.styles = [css_248z];
1971
+ __decorate([
1972
+ n({ attribute: false })
1973
+ ], Erd.prototype, "entities", void 0);
1974
+ __decorate([
1975
+ n({ attribute: false })
1976
+ ], Erd.prototype, "relations", void 0);
1977
+ __decorate([
1978
+ n({ type: String, reflect: true })
1979
+ ], Erd.prototype, "schema", void 0);
1980
+ __decorate([
1981
+ n({ type: String, reflect: true, attribute: 'focused-node' })
1982
+ ], Erd.prototype, "focusedNode", void 0);
1983
+ __decorate([
1984
+ n({ type: Number, reflect: true })
1985
+ ], Erd.prototype, "hops", void 0);
1986
+ __decorate([
1987
+ n({ type: String, reflect: true })
1988
+ ], Erd.prototype, "selected", void 0);
1989
+ __decorate([
1990
+ r()
1991
+ ], Erd.prototype, "_collapsed", void 0);
1992
+ __decorate([
1993
+ r()
1994
+ ], Erd.prototype, "_hover", void 0);
1995
+ __decorate([
1996
+ r()
1997
+ ], Erd.prototype, "_focusId", void 0);
1998
+ __decorate([
1999
+ r()
2000
+ ], Erd.prototype, "_editing", void 0);
2001
+ __decorate([
2002
+ r()
2003
+ ], Erd.prototype, "_picker", void 0);
2004
+ __decorate([
2005
+ r()
2006
+ ], Erd.prototype, "_connecting", void 0);
2007
+ __decorate([
2008
+ r()
2009
+ ], Erd.prototype, "_announcement", void 0);
2010
+ __decorate([
2011
+ r()
2012
+ ], Erd.prototype, "_fresh", void 0);
2013
+ __decorate([
2014
+ e('.erd-viewport')
2015
+ ], Erd.prototype, "_viewportEl", void 0);
2016
+ Erd = __decorate([
2017
+ IndividualComponent
2018
+ ], Erd);
2019
+
2020
+ export { Erd };
2021
+ //# sourceMappingURL=erd.js.map