@redvars/peacock 4.0.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (467) hide show
  1. package/dist/{BaseField-CAog9TIc.js → BaseField-_unSNU5x.js} +43 -4
  2. package/dist/BaseField-_unSNU5x.js.map +1 -0
  3. package/dist/{BaseInput-CcMfg1Y2.js → BaseInput-DtZH0fPJ.js} +7 -4
  4. package/dist/BaseInput-DtZH0fPJ.js.map +1 -0
  5. package/dist/accordion.js.map +1 -1
  6. package/dist/ai-badge.js +32 -6
  7. package/dist/ai-badge.js.map +1 -1
  8. package/dist/ai-summary.js +2 -2
  9. package/dist/alert.js +2 -2
  10. package/dist/anchor-nav.js +2 -2
  11. package/dist/app-shell.js +2 -2
  12. package/dist/assistant-panel.js +2 -2
  13. package/dist/assistant-step.js +2 -2
  14. package/dist/assistant-steps.js +2 -2
  15. package/dist/avatar-group.js +2 -2
  16. package/dist/banner.js +2 -2
  17. package/dist/{base-button-Do2TUy8M.js → base-button-BJMGMcMv.js} +3 -1
  18. package/dist/base-button-BJMGMcMv.js.map +1 -0
  19. package/dist/{base-progress-BiLlZVHJ.js → base-progress-D7Nmfh1s.js} +4 -2
  20. package/dist/base-progress-D7Nmfh1s.js.map +1 -0
  21. package/dist/bottom-sheet.js +2 -2
  22. package/dist/breadcrumb.js +2 -2
  23. package/dist/button-group.js +4 -4
  24. package/dist/button.js +14 -8
  25. package/dist/button.js.map +1 -1
  26. package/dist/calendar.js +2 -2
  27. package/dist/canvas-base-CWQ4rQ2s.js +788 -0
  28. package/dist/canvas-base-CWQ4rQ2s.js.map +1 -0
  29. package/dist/canvas-link-CtgsALq4.js +54 -0
  30. package/dist/canvas-link-CtgsALq4.js.map +1 -0
  31. package/dist/{cartesian-chart-C-f1frt0.js → cartesian-chart-CS5yRLfE.js} +3 -2
  32. package/dist/cartesian-chart-CS5yRLfE.js.map +1 -0
  33. package/dist/{cb-group-base-DeuCVx3a.js → cb-group-base-CO30uFQZ.js} +2 -2
  34. package/dist/{cb-group-base-DeuCVx3a.js.map → cb-group-base-CO30uFQZ.js.map} +1 -1
  35. package/dist/cb-group.js +3 -3
  36. package/dist/cb-rule.js +3 -3
  37. package/dist/chart-area.js +5 -4
  38. package/dist/chart-area.js.map +1 -1
  39. package/dist/chart-bar.js +5 -4
  40. package/dist/chart-bar.js.map +1 -1
  41. package/dist/chart-base-C_XKVyhf.js +833 -0
  42. package/dist/chart-base-C_XKVyhf.js.map +1 -0
  43. package/dist/chart-doughnut.js +4 -3
  44. package/dist/chart-doughnut.js.map +1 -1
  45. package/dist/chart-line.js +5 -4
  46. package/dist/chart-line.js.map +1 -1
  47. package/dist/chart-pie.js +4 -3
  48. package/dist/chart-pie.js.map +1 -1
  49. package/dist/chat-event.js +152 -0
  50. package/dist/chat-event.js.map +1 -0
  51. package/dist/chat-message.js +195 -19
  52. package/dist/chat-message.js.map +1 -1
  53. package/dist/chat-thread.js +26 -9
  54. package/dist/chat-thread.js.map +1 -1
  55. package/dist/checkbox-group.js +5 -5
  56. package/dist/checkbox.js +5 -5
  57. package/dist/chip-set.js +4 -4
  58. package/dist/chip.js +4 -4
  59. package/dist/circular-progress.js +3 -3
  60. package/dist/citation.js +2 -2
  61. package/dist/code-editor.js +6 -5
  62. package/dist/code-editor.js.map +1 -1
  63. package/dist/code-highlighter.js +2 -2
  64. package/dist/color-field.js +6 -6
  65. package/dist/color-picker.js +2 -2
  66. package/dist/command-palette.js +2 -2
  67. package/dist/comment-composer.js +6 -6
  68. package/dist/condition-builder.js +3 -3
  69. package/dist/confirm-dialog.js +2 -2
  70. package/dist/copy-button.js +2 -2
  71. package/dist/currency-field.js +6 -6
  72. package/dist/custom-elements-jsdocs.json +2330 -397
  73. package/dist/custom-elements.json +20464 -542
  74. package/dist/date-field.js +7 -7
  75. package/dist/date-picker.js +4 -2
  76. package/dist/date-picker.js.map +1 -1
  77. package/dist/date-range-field.js +7 -7
  78. package/dist/datetime-field.js +7 -7
  79. package/dist/dependency-map-layout-5KUueabk.js +1390 -0
  80. package/dist/dependency-map-layout-5KUueabk.js.map +1 -0
  81. package/dist/dependency-map.js +1605 -0
  82. package/dist/dependency-map.js.map +1 -0
  83. package/dist/description-item.js +2 -2
  84. package/dist/description-list.js +2 -2
  85. package/dist/diagram-Va096vj9.js +2029 -0
  86. package/dist/diagram-Va096vj9.js.map +1 -0
  87. package/dist/diagram-controls.js +345 -0
  88. package/dist/diagram-controls.js.map +1 -0
  89. package/dist/diagram-minimap.js +216 -0
  90. package/dist/diagram-minimap.js.map +1 -0
  91. package/dist/diagram.js +20 -0
  92. package/dist/diagram.js.map +1 -0
  93. package/dist/diff-viewer.js +2 -2
  94. package/dist/discussion-activity.js +4 -4
  95. package/dist/discussion-comment.js +4 -4
  96. package/dist/{discussion-time-BegaYfhf.js → discussion-time-DqykqvNy.js} +2 -2
  97. package/dist/{discussion-time-BegaYfhf.js.map → discussion-time-DqykqvNy.js.map} +1 -1
  98. package/dist/discussion.js +8 -8
  99. package/dist/{document-editor-BO7QPbO5.js → document-editor-Dc8JeFVB.js} +2 -2
  100. package/dist/{document-editor-BO7QPbO5.js.map → document-editor-Dc8JeFVB.js.map} +1 -1
  101. package/dist/document-editor.js +3 -3
  102. package/dist/draft-card.js +14 -4
  103. package/dist/draft-card.js.map +1 -1
  104. package/dist/dropdown-button.js +3 -2
  105. package/dist/dropdown-button.js.map +1 -1
  106. package/dist/erd.js +2021 -0
  107. package/dist/erd.js.map +1 -0
  108. package/dist/fab.js +4 -4
  109. package/dist/field.js +257 -43
  110. package/dist/field.js.map +1 -1
  111. package/dist/file-upload.js +38 -16
  112. package/dist/file-upload.js.map +1 -1
  113. package/dist/filter-bar.js +2 -2
  114. package/dist/flow.js +27 -970
  115. package/dist/flow.js.map +1 -1
  116. package/dist/focus-ring.js +2 -0
  117. package/dist/focus-ring.js.map +1 -1
  118. package/dist/{form-associated-D3Tn33s_.js → form-associated-BHbg72PG.js} +3 -1
  119. package/dist/{form-associated-D3Tn33s_.js.map → form-associated-BHbg72PG.js.map} +1 -1
  120. package/dist/{form-submitter-DWwv6K9-.js → form-submitter-beG1CXAn.js} +7 -1
  121. package/dist/{form-submitter-DWwv6K9-.js.map → form-submitter-beG1CXAn.js.map} +1 -1
  122. package/dist/form.js +3 -3
  123. package/dist/{generative-view-DmtpDobn.js → generative-view-BKlcuujw.js} +13 -13
  124. package/dist/generative-view-BKlcuujw.js.map +1 -0
  125. package/dist/generative-view.js +3 -3
  126. package/dist/geometry-INg82Lxq.js +305 -0
  127. package/dist/geometry-INg82Lxq.js.map +1 -0
  128. package/dist/history-YbTSQZHj.js +45 -0
  129. package/dist/history-YbTSQZHj.js.map +1 -0
  130. package/dist/host-CZK7xhzh.js +40 -0
  131. package/dist/host-CZK7xhzh.js.map +1 -0
  132. package/dist/html-editor.js +6 -6
  133. package/dist/{hyperlink-DhE9RlVS.js → hyperlink-DycWPKwU.js} +10 -1
  134. package/dist/hyperlink-DycWPKwU.js.map +1 -0
  135. package/dist/{i18n-controller-urcQKYGe.js → i18n-controller-DJHsE1YH.js} +2 -2
  136. package/dist/{i18n-controller-urcQKYGe.js.map → i18n-controller-DJHsE1YH.js.map} +1 -1
  137. package/dist/icon-button.js +11 -9
  138. package/dist/icon-button.js.map +1 -1
  139. package/dist/image.js +2 -2
  140. package/dist/index.js +42 -22
  141. package/dist/index.js.map +1 -1
  142. package/dist/inline-edit.js +2 -2
  143. package/dist/input.js +5 -5
  144. package/dist/json-viewer.js +2 -2
  145. package/dist/kanban.js +2 -2
  146. package/dist/kbd.js +2 -2
  147. package/dist/linear-progress.js +3 -3
  148. package/dist/link-button.js +9 -7
  149. package/dist/link-button.js.map +1 -1
  150. package/dist/list-item.js +2 -2
  151. package/dist/list.js +2 -2
  152. package/dist/listbox.js +4 -4
  153. package/dist/loader-full.js +17 -16
  154. package/dist/loader-full.js.map +1 -1
  155. package/dist/loader.js +51 -18
  156. package/dist/loader.js.map +1 -1
  157. package/dist/markdown-editor.js +6 -6
  158. package/dist/markers-BFmh1OCz.js +46 -0
  159. package/dist/markers-BFmh1OCz.js.map +1 -0
  160. package/dist/measure-controller-Dmc5hZKg.js +89 -0
  161. package/dist/measure-controller-Dmc5hZKg.js.map +1 -0
  162. package/dist/mention-input.js +7 -6
  163. package/dist/mention-input.js.map +1 -1
  164. package/dist/menu-item.js +3 -2
  165. package/dist/menu-item.js.map +1 -1
  166. package/dist/{menu-trigger-controller-DyLpTxM7.js → menu-trigger-controller-CEJq1ugC.js} +11 -14
  167. package/dist/menu-trigger-controller-CEJq1ugC.js.map +1 -0
  168. package/dist/menu.js +2 -2
  169. package/dist/modal.js +2 -2
  170. package/dist/navigation-bar.js +2 -2
  171. package/dist/navigation-drawer.js +2 -2
  172. package/dist/navigation-rail.js +2 -2
  173. package/dist/notification-center.js +3 -3
  174. package/dist/number-field.js +7 -6
  175. package/dist/number-field.js.map +1 -1
  176. package/dist/option.js +2 -2
  177. package/dist/page-header.js +2 -2
  178. package/dist/pagination.js +2 -2
  179. package/dist/password-field.js +6 -6
  180. package/dist/password-rules.js +2 -2
  181. package/dist/phone-field.js +6 -6
  182. package/dist/{picker-field-B4DtcJfL.js → picker-field-CUI05sWc.js} +3 -3
  183. package/dist/{picker-field-B4DtcJfL.js.map → picker-field-CUI05sWc.js.map} +1 -1
  184. package/dist/pin-input.js +6 -6
  185. package/dist/presence-indicator.js +2 -2
  186. package/dist/prompt-input.js +6 -6
  187. package/dist/radio-group.js +2 -1
  188. package/dist/radio-group.js.map +1 -1
  189. package/dist/radio.js +6 -6
  190. package/dist/radio.js.map +1 -1
  191. package/dist/rating.js +6 -5
  192. package/dist/rating.js.map +1 -1
  193. package/dist/redvars-loader.js +2 -2
  194. package/dist/{relative-time-BVQXLuHm.js → relative-time-BNxqvEbg.js} +13 -2
  195. package/dist/relative-time-BNxqvEbg.js.map +1 -0
  196. package/dist/relative-time.js +3 -3
  197. package/dist/resizable-panels.js +2 -2
  198. package/dist/{rich-text-input-DLICqof1.js → rich-text-input-N_hqnXej.js} +3 -3
  199. package/dist/{rich-text-input-DLICqof1.js.map → rich-text-input-N_hqnXej.js.map} +1 -1
  200. package/dist/ripple.js +2 -0
  201. package/dist/ripple.js.map +1 -1
  202. package/dist/{schema-hMt-NRLk.js → schema-Dy0z-80u.js} +2 -2
  203. package/dist/{schema-hMt-NRLk.js.map → schema-Dy0z-80u.js.map} +1 -1
  204. package/dist/search.js +5 -5
  205. package/dist/segmented-button-group.js +1 -1
  206. package/dist/select.js +8 -8
  207. package/dist/side-sheet.js +2 -2
  208. package/dist/signature-pad.js +6 -5
  209. package/dist/signature-pad.js.map +1 -1
  210. package/dist/slider.js +6 -5
  211. package/dist/slider.js.map +1 -1
  212. package/dist/snackbar.js +2 -2
  213. package/dist/sparkline.js +2 -2
  214. package/dist/split-button.js +109 -21
  215. package/dist/split-button.js.map +1 -1
  216. package/dist/src/__internal/ai/suggestion-controller.d.ts +2 -0
  217. package/dist/src/__internal/diagram/canvas-base.d.ts +105 -0
  218. package/dist/src/__internal/diagram/canvas-link.d.ts +21 -0
  219. package/dist/src/__internal/diagram/geometry.d.ts +49 -0
  220. package/dist/src/__internal/diagram/history.d.ts +17 -0
  221. package/dist/src/__internal/diagram/host.d.ts +45 -0
  222. package/dist/src/__internal/diagram/markers.d.ts +16 -0
  223. package/dist/src/__internal/diagram/measure-controller.d.ts +32 -0
  224. package/dist/src/__internal/diagram/motion.d.ts +22 -0
  225. package/dist/src/__internal/diagram/selection.d.ts +20 -0
  226. package/dist/src/__internal/diagram/types.d.ts +39 -0
  227. package/dist/src/__internal/diagram/viewport-controller.d.ts +89 -0
  228. package/dist/src/__internal/i18n/strings.d.ts +155 -0
  229. package/dist/src/__internal/menu-trigger-controller.d.ts +11 -8
  230. package/dist/src/__internal/toggle-base.d.ts +8 -0
  231. package/dist/src/__internal/utils/deprecate.d.ts +3 -3
  232. package/dist/src/__internal/utils/relative-time.d.ts +5 -0
  233. package/dist/src/accordion/accordion.d.ts +1 -0
  234. package/dist/src/ai-badge/ai-badge.d.ts +8 -0
  235. package/dist/src/button/button/button.d.ts +4 -0
  236. package/dist/src/chat-message/chat-message.d.ts +51 -10
  237. package/dist/src/chat-message/index.d.ts +1 -1
  238. package/dist/src/chat-thread/chat-event.d.ts +37 -0
  239. package/dist/src/chat-thread/chat-thread.d.ts +7 -4
  240. package/dist/src/chat-thread/index.d.ts +1 -0
  241. package/dist/src/code-editor/code-editor.d.ts +1 -0
  242. package/dist/src/date-picker/date-picker.d.ts +2 -0
  243. package/dist/src/dependency-map/dependency-map-layout.d.ts +48 -0
  244. package/dist/src/dependency-map/dependency-map.d.ts +241 -0
  245. package/dist/src/dependency-map/index.d.ts +2 -0
  246. package/dist/src/diagram/diagram.d.ts +300 -0
  247. package/dist/src/diagram/flow.d.ts +53 -0
  248. package/dist/src/diagram/index.d.ts +4 -0
  249. package/dist/src/diagram-controls/diagram-controls.d.ts +46 -0
  250. package/dist/src/diagram-controls/index.d.ts +1 -0
  251. package/dist/src/diagram-minimap/diagram-minimap.d.ts +39 -0
  252. package/dist/src/diagram-minimap/index.d.ts +1 -0
  253. package/dist/src/erd/erd-layout.d.ts +27 -0
  254. package/dist/src/erd/erd.d.ts +266 -0
  255. package/dist/src/erd/index.d.ts +2 -0
  256. package/dist/src/field/field.d.ts +38 -1
  257. package/dist/src/file-upload/file-upload.d.ts +3 -1
  258. package/dist/src/focus-ring/focus-ring.d.ts +2 -0
  259. package/dist/src/index.d.ts +17 -4
  260. package/dist/src/input/BaseField.d.ts +15 -1
  261. package/dist/src/input/BaseInput.d.ts +4 -0
  262. package/dist/src/menu/menu-item/menu-item.d.ts +1 -0
  263. package/dist/src/number-field/number-field.d.ts +4 -0
  264. package/dist/src/progress/base-progress.d.ts +3 -0
  265. package/dist/src/radio/radio-group.d.ts +1 -0
  266. package/dist/src/rating/rating.d.ts +1 -0
  267. package/dist/src/ripple/ripple.d.ts +2 -0
  268. package/dist/src/signature-pad/signature-pad.d.ts +1 -0
  269. package/dist/src/slider/slider.d.ts +1 -0
  270. package/dist/src/split-button/split-button.d.ts +7 -2
  271. package/dist/src/switch/switch.d.ts +1 -0
  272. package/dist/src/tabs/tab.d.ts +2 -0
  273. package/dist/src/tabs/tabs.d.ts +1 -0
  274. package/dist/src/textarea/textarea.d.ts +3 -0
  275. package/dist/src/time-picker/time-picker.d.ts +2 -0
  276. package/dist/src/transfer-list/transfer-list.d.ts +1 -0
  277. package/dist/src/tree-chart/index.d.ts +2 -0
  278. package/dist/src/tree-chart/tree-chart-layout.d.ts +49 -0
  279. package/dist/src/tree-chart/tree-chart.d.ts +221 -0
  280. package/dist/src/workflow/index.d.ts +2 -0
  281. package/dist/src/workflow/workflow-format.d.ts +5 -0
  282. package/dist/src/workflow/workflow-model.d.ts +194 -0
  283. package/dist/src/workflow/workflow.d.ts +313 -0
  284. package/dist/src/workflow-timeline/index.d.ts +1 -0
  285. package/dist/src/workflow-timeline/workflow-timeline.d.ts +41 -0
  286. package/dist/stat.js +2 -2
  287. package/dist/status-indicator.js +2 -2
  288. package/dist/step.js +2 -2
  289. package/dist/stepper.js +2 -2
  290. package/dist/{strings-DmbqMTfs.js → strings-DnYjGbbc.js} +169 -1
  291. package/dist/{strings-DmbqMTfs.js.map → strings-DnYjGbbc.js.map} +1 -1
  292. package/dist/sub-menu.js +2 -2
  293. package/dist/{suggestion-controller-CW17adxd.js → suggestion-controller-7YRQqkaI.js} +3 -1
  294. package/dist/{suggestion-controller-CW17adxd.js.map → suggestion-controller-7YRQqkaI.js.map} +1 -1
  295. package/dist/svg.js +2 -2
  296. package/dist/switch.js +6 -5
  297. package/dist/switch.js.map +1 -1
  298. package/dist/tab.js +1 -0
  299. package/dist/tab.js.map +1 -1
  300. package/dist/table.js +50 -11
  301. package/dist/table.js.map +1 -1
  302. package/dist/tabs.js +1 -0
  303. package/dist/tabs.js.map +1 -1
  304. package/dist/test/diagram-controls.test.d.ts +1 -0
  305. package/dist/test/diagram-geometry.test.d.ts +1 -0
  306. package/dist/test/diagram.test.d.ts +1 -0
  307. package/dist/test/erd.test.d.ts +1 -0
  308. package/dist/test/toggle-label.test.d.ts +1 -0
  309. package/dist/test/tree-chart.test.d.ts +1 -0
  310. package/dist/test/workflow-debug.test.d.ts +1 -0
  311. package/dist/test/workflow.test.d.ts +1 -0
  312. package/dist/textarea.js +13 -6
  313. package/dist/textarea.js.map +1 -1
  314. package/dist/time-field.js +7 -7
  315. package/dist/time-picker.js +4 -2
  316. package/dist/time-picker.js.map +1 -1
  317. package/dist/timeline-item.js +2 -2
  318. package/dist/timeline.js +2 -2
  319. package/dist/{toggle-base-BQO5pjrU.js → toggle-base-CXmFSp3b.js} +19 -3
  320. package/dist/toggle-base-CXmFSp3b.js.map +1 -0
  321. package/dist/tour.js +2 -2
  322. package/dist/transfer-list.js +6 -5
  323. package/dist/transfer-list.js.map +1 -1
  324. package/dist/{chart-base-B-gOg2Di.js → transform-CxeQFXXB.js} +9 -839
  325. package/dist/transform-CxeQFXXB.js.map +1 -0
  326. package/dist/tree-chart.js +1986 -0
  327. package/dist/tree-chart.js.map +1 -0
  328. package/dist/tree-item.js +2 -2
  329. package/dist/tree.js +2 -2
  330. package/dist/tsconfig.tsbuildinfo +1 -1
  331. package/dist/typing-indicator.js +2 -2
  332. package/dist/url-field.js +6 -6
  333. package/dist/user-menu.js +3 -3
  334. package/dist/virtual-list.js +2 -2
  335. package/dist/workflow-format-BsyveyeC.js +34 -0
  336. package/dist/workflow-format-BsyveyeC.js.map +1 -0
  337. package/dist/workflow-model-CauduOG2.js +330 -0
  338. package/dist/workflow-model-CauduOG2.js.map +1 -0
  339. package/dist/workflow-timeline.js +354 -0
  340. package/dist/workflow-timeline.js.map +1 -0
  341. package/dist/workflow.js +3337 -0
  342. package/dist/workflow.js.map +1 -0
  343. package/dist/workspace-switcher.js +3 -3
  344. package/package.json +1 -1
  345. package/readme.md +44 -2
  346. package/src/LoaderUtils.ts +9 -2
  347. package/src/__internal/ai/suggestion-controller.ts +3 -1
  348. package/src/__internal/diagram/canvas-base.ts +410 -0
  349. package/src/__internal/diagram/canvas-link.ts +66 -0
  350. package/src/__internal/diagram/geometry.ts +372 -0
  351. package/src/__internal/diagram/history.ts +49 -0
  352. package/src/__internal/diagram/host.ts +76 -0
  353. package/src/__internal/diagram/markers.ts +56 -0
  354. package/src/__internal/diagram/measure-controller.ts +104 -0
  355. package/src/__internal/diagram/motion.ts +89 -0
  356. package/src/__internal/diagram/selection.ts +69 -0
  357. package/src/__internal/diagram/types.ts +56 -0
  358. package/src/__internal/diagram/viewport-controller.ts +494 -0
  359. package/src/__internal/i18n/strings.ts +207 -0
  360. package/src/__internal/menu-trigger-controller.ts +11 -15
  361. package/src/__internal/mixins/field.ts +3 -0
  362. package/src/__internal/mixins/form-associated.ts +2 -0
  363. package/src/__internal/mixins/form-submitter.ts +6 -0
  364. package/src/__internal/mixins/hyperlink.ts +10 -0
  365. package/src/__internal/toggle-base.ts +16 -0
  366. package/src/__internal/utils/deprecate.ts +5 -4
  367. package/src/__internal/utils/relative-time.ts +20 -0
  368. package/src/accordion/accordion.ts +1 -0
  369. package/src/ai-badge/ai-badge.scss +8 -0
  370. package/src/ai-badge/ai-badge.ts +21 -4
  371. package/src/button/base-button/base-button.ts +2 -0
  372. package/src/button/button/button-base.scss +9 -2
  373. package/src/button/button/button-layers.scss +3 -1
  374. package/src/button/button/button.ts +4 -0
  375. package/src/chat-message/chat-message.scss +72 -0
  376. package/src/chat-message/chat-message.ts +137 -18
  377. package/src/chat-message/index.ts +1 -0
  378. package/src/chat-thread/chat-event.scss +36 -0
  379. package/src/chat-thread/chat-event.ts +79 -0
  380. package/src/chat-thread/chat-thread.scss +4 -1
  381. package/src/chat-thread/chat-thread.ts +22 -6
  382. package/src/chat-thread/index.ts +1 -0
  383. package/src/code-editor/code-editor.ts +1 -0
  384. package/src/date-picker/date-picker.ts +2 -0
  385. package/src/dependency-map/dependency-map-layout.ts +505 -0
  386. package/src/dependency-map/dependency-map.scss +626 -0
  387. package/src/dependency-map/dependency-map.ts +1280 -0
  388. package/src/dependency-map/index.ts +16 -0
  389. package/src/diagram/diagram.scss +513 -0
  390. package/src/diagram/diagram.ts +1852 -0
  391. package/src/diagram/flow.ts +81 -0
  392. package/src/diagram/index.ts +44 -0
  393. package/src/diagram-controls/diagram-controls.scss +68 -0
  394. package/src/diagram-controls/diagram-controls.ts +255 -0
  395. package/src/diagram-controls/index.ts +1 -0
  396. package/src/diagram-minimap/diagram-minimap.scss +41 -0
  397. package/src/diagram-minimap/diagram-minimap.ts +149 -0
  398. package/src/diagram-minimap/index.ts +1 -0
  399. package/src/draft-card/draft-card.scss +16 -2
  400. package/src/dropdown-button/dropdown-button.ts +2 -1
  401. package/src/erd/erd-layout.ts +92 -0
  402. package/src/erd/erd.scss +636 -0
  403. package/src/erd/erd.ts +1728 -0
  404. package/src/erd/index.ts +17 -0
  405. package/src/field/field.scss +197 -23
  406. package/src/field/field.ts +109 -16
  407. package/src/file-upload/file-upload.scss +37 -10
  408. package/src/file-upload/file-upload.ts +3 -1
  409. package/src/focus-ring/focus-ring.ts +2 -0
  410. package/src/generative-view/catalog.generated.ts +12 -11
  411. package/src/index.ts +123 -3
  412. package/src/input/BaseField.ts +45 -2
  413. package/src/input/BaseInput.ts +4 -1
  414. package/src/loader.ts +29 -0
  415. package/src/mention-input/mention-input.scss +2 -0
  416. package/src/menu/menu-item/menu-item.ts +1 -0
  417. package/src/number-field/number-field.ts +4 -0
  418. package/src/progress/base-progress.ts +3 -0
  419. package/src/radio/radio-group.ts +1 -0
  420. package/src/radio/radio.ts +1 -1
  421. package/src/rating/rating.ts +1 -0
  422. package/src/ripple/ripple.ts +2 -0
  423. package/src/signature-pad/signature-pad.ts +1 -0
  424. package/src/slider/slider.ts +1 -0
  425. package/src/split-button/split-button-colors.scss +9 -0
  426. package/src/split-button/split-button-sizes.scss +32 -5
  427. package/src/split-button/split-button.scss +61 -8
  428. package/src/split-button/split-button.ts +15 -8
  429. package/src/switch/switch.ts +1 -0
  430. package/src/table/table.scss +57 -9
  431. package/src/table/table.ts +3 -1
  432. package/src/tabs/tab.ts +2 -0
  433. package/src/tabs/tabs.ts +1 -0
  434. package/src/textarea/textarea.scss +2 -0
  435. package/src/textarea/textarea.ts +8 -0
  436. package/src/time-picker/time-picker.ts +2 -0
  437. package/src/transfer-list/transfer-list.ts +1 -0
  438. package/src/tree-chart/index.ts +13 -0
  439. package/src/tree-chart/tree-chart-layout.ts +185 -0
  440. package/src/tree-chart/tree-chart.scss +377 -0
  441. package/src/tree-chart/tree-chart.ts +1170 -0
  442. package/src/workflow/index.ts +35 -0
  443. package/src/workflow/workflow-format.ts +29 -0
  444. package/src/workflow/workflow-model.ts +583 -0
  445. package/src/workflow/workflow.scss +1164 -0
  446. package/src/workflow/workflow.ts +2674 -0
  447. package/src/workflow-timeline/index.ts +1 -0
  448. package/src/workflow-timeline/workflow-timeline.scss +128 -0
  449. package/src/workflow-timeline/workflow-timeline.ts +238 -0
  450. package/dist/BaseField-CAog9TIc.js.map +0 -1
  451. package/dist/BaseInput-CcMfg1Y2.js.map +0 -1
  452. package/dist/base-button-Do2TUy8M.js.map +0 -1
  453. package/dist/base-progress-BiLlZVHJ.js.map +0 -1
  454. package/dist/cartesian-chart-C-f1frt0.js.map +0 -1
  455. package/dist/chart-base-B-gOg2Di.js.map +0 -1
  456. package/dist/generative-view-DmtpDobn.js.map +0 -1
  457. package/dist/hyperlink-DhE9RlVS.js.map +0 -1
  458. package/dist/menu-trigger-controller-DyLpTxM7.js.map +0 -1
  459. package/dist/relative-time-BVQXLuHm.js.map +0 -1
  460. package/dist/src/flow/flow.d.ts +0 -178
  461. package/dist/src/flow/index.d.ts +0 -2
  462. package/dist/toggle-base-BQO5pjrU.js.map +0 -1
  463. package/src/button/button-group/readme.md +0 -23
  464. package/src/flow/flow.scss +0 -215
  465. package/src/flow/flow.ts +0 -958
  466. package/src/flow/index.ts +0 -10
  467. /package/dist/test/{flow.test.d.ts → dependency-map.test.d.ts} +0 -0
@@ -0,0 +1,2674 @@
1
+ import {
2
+ html,
3
+ nothing,
4
+ render as renderTemplate,
5
+ svg,
6
+ type PropertyValues,
7
+ type SVGTemplateResult,
8
+ type TemplateResult,
9
+ } from 'lit';
10
+ import { property, query, state } from 'lit/decorators.js';
11
+ import { classMap } from 'lit/directives/class-map.js';
12
+ import IndividualComponent from '@/IndividualComponent.js';
13
+ import { DiagramCanvasElement } from '@/__internal/diagram/canvas-base.js';
14
+ import { roundedPath } from '@/__internal/diagram/geometry.js';
15
+ import { History } from '@/__internal/diagram/history.js';
16
+ import {
17
+ animateOut,
18
+ prefersReducedMotion,
19
+ } from '@/__internal/diagram/motion.js';
20
+ import type { DiagramOverview } from '@/__internal/diagram/host.js';
21
+ import type {
22
+ DiagramRect,
23
+ DiagramView,
24
+ DiagramViewportDetail,
25
+ } from '@/__internal/diagram/types.js';
26
+ import type { Menu } from '@/menu/menu/menu.js';
27
+ import {
28
+ WORKFLOW_LOGIC_STEPS,
29
+ allIds,
30
+ cloneWithNewIds,
31
+ contains,
32
+ countInside,
33
+ createStep,
34
+ findStep,
35
+ getList,
36
+ insertStep,
37
+ isReached,
38
+ listKey,
39
+ listTerminates,
40
+ moveStep,
41
+ removeStep,
42
+ replaceStep,
43
+ stepTerminates,
44
+ walk,
45
+ type WorkflowActionStep,
46
+ type WorkflowListRef,
47
+ type WorkflowRun,
48
+ type WorkflowRunStep,
49
+ type WorkflowRunStepStatus,
50
+ type WorkflowStep,
51
+ type WorkflowStepType,
52
+ type WorkflowValue,
53
+ } from './workflow-model.js';
54
+ import { formatDuration } from './workflow-format.js';
55
+ import styles from './workflow.scss';
56
+
57
+ export type {
58
+ WorkflowAccent,
59
+ WorkflowActionStep,
60
+ WorkflowAssignee,
61
+ WorkflowBranchStep,
62
+ WorkflowEndStep,
63
+ WorkflowField,
64
+ WorkflowListRef,
65
+ WorkflowLoopStep,
66
+ WorkflowOutput,
67
+ WorkflowPath,
68
+ WorkflowRun,
69
+ WorkflowRunStep,
70
+ WorkflowRunStepStatus,
71
+ WorkflowStep,
72
+ WorkflowStepType,
73
+ WorkflowTool,
74
+ WorkflowValue,
75
+ WorkflowWaitStep,
76
+ } from './workflow-model.js';
77
+
78
+ export { WORKFLOW_LOGIC_STEPS } from './workflow-model.js';
79
+
80
+ export type WorkflowDirection = 'vertical' | 'horizontal';
81
+
82
+ export type WorkflowMode = 'design' | 'debug' | 'history';
83
+
84
+ export type WorkflowDebugAction =
85
+ | 'continue'
86
+ | 'pause'
87
+ | 'step-over'
88
+ | 'step-into'
89
+ | 'restart'
90
+ | 'stop'
91
+ | 'retry';
92
+
93
+ /** Detail of `debug-action`. `stepId` is set for `retry`. */
94
+ export interface WorkflowDebugActionDetail {
95
+ action: WorkflowDebugAction;
96
+ stepId?: string;
97
+ }
98
+
99
+ /** Detail of `breakpoint-toggle`. */
100
+ export interface WorkflowBreakpointDetail {
101
+ id: string;
102
+ enabled: boolean;
103
+ breakpoints: string[];
104
+ }
105
+
106
+ /** Detail of `iteration-change`. */
107
+ export interface WorkflowIterationDetail {
108
+ loopId: string;
109
+ /** Zero-based. */
110
+ index: number;
111
+ }
112
+
113
+ export type WorkflowDensity = 'compact' | 'standard' | 'expanded';
114
+
115
+ export type WorkflowChangeReason =
116
+ | 'add'
117
+ | 'remove'
118
+ | 'move'
119
+ | 'paste'
120
+ | 'update'
121
+ | 'undo'
122
+ | 'redo';
123
+
124
+ /** Detail of `change`. */
125
+ export interface WorkflowChangeDetail {
126
+ value: WorkflowValue;
127
+ reason: WorkflowChangeReason;
128
+ }
129
+
130
+ /** Detail of `select`. */
131
+ export interface WorkflowSelectDetail {
132
+ id: string;
133
+ step: WorkflowStep;
134
+ }
135
+
136
+ /** Detail of `step-add`. */
137
+ export interface WorkflowStepAddDetail {
138
+ stepType: WorkflowStepType;
139
+ /** The list the step goes into, and where. */
140
+ list: WorkflowListRef;
141
+ index: number;
142
+ /** Whether the step becomes the trigger. */
143
+ trigger: boolean;
144
+ }
145
+
146
+ /** Detail of `delete`. */
147
+ export interface WorkflowDeleteDetail {
148
+ ids: string[];
149
+ }
150
+
151
+ /** Detail of `viewport-change`. */
152
+ export type WorkflowViewportDetail = DiagramViewportDetail;
153
+
154
+ /** A step that needs attention. */
155
+ export interface WorkflowProblem {
156
+ id: string;
157
+ message: string;
158
+ }
159
+
160
+ interface Point {
161
+ m: number;
162
+ c: number;
163
+ }
164
+
165
+ /** Below this zoom a fitted workflow is hard to read, so it starts at its beginning instead. */
166
+ const MIN_FIT_ZOOM = 0.6;
167
+
168
+ /** Pointer travel, in screen pixels, before a press on a step becomes a drag. */
169
+ const DRAG_THRESHOLD = 5;
170
+
171
+ /** Screen pixels within which a dragged step snaps to a gap. */
172
+ const DROP_DISTANCE = 64;
173
+
174
+ const CORNER = 20;
175
+
176
+ const TRIGGER_GAP = '__trigger';
177
+
178
+ const DATA_PILL = /\{\{\s*([^}]+?)\s*\}\}/g;
179
+
180
+ /** Elements inside a card that handle their own pointer input. */
181
+ const INTERACTIVE =
182
+ 'button, a, input, select, textarea, wc-icon-button, wc-button, [contenteditable]';
183
+
184
+ /** Shared between workflows on a page, like the system clipboard. */
185
+ let clipboard: WorkflowStep | undefined;
186
+
187
+ /**
188
+ * @label Workflow
189
+ * @tag wc-workflow
190
+ * @rawTag workflow
191
+ * @summary A structured builder for business rules and processes: steps, branches that merge back, parallel paths, loops, error paths and ends.
192
+ *
193
+ * @overview
194
+ * <p>Set <code>value</code> to a trigger and a list of steps. Steps are <code>action</code>,
195
+ * <code>wait</code> and <code>end</code> cards, <code>branch</code> and <code>parallel</code> blocks whose
196
+ * paths sit side by side and merge back below (a path that ends draws no merge), and
197
+ * <code>loop</code> frames. An action's <code>onError</code> steps run as a side path. The layout is
198
+ * automatic: top to bottom, or left to right with <code>direction="horizontal"</code>, joined by rounded
199
+ * connectors.</p>
200
+ * <p>Cards show a tinted icon, a headline and the kind of step, up to three <code>fields</code>
201
+ * (<code>{{Step.output}}</code> in a value renders as a data pill), and a footer with outputs, tools or
202
+ * an assignee. <code>density</code> shows less (<code>compact</code>) or everything
203
+ * (<code>expanded</code>). Put your own card in <code>slot="step:&lt;id&gt;"</code>.</p>
204
+ * <p>With <code>editable</code>, a "+" on every connector opens a searchable palette built from
205
+ * <code>stepTypes</code>; <code>step-add</code> fires first and can be canceled to show your own dialog.
206
+ * Drag a step to another "+" to move it, delete it with Delete, duplicate with Ctrl+D, copy and paste,
207
+ * and undo with Ctrl+Z. Steps glide to their new places. Every edit fires <code>change</code> with the
208
+ * new <code>value</code>; selecting a step fires <code>select</code>, for your inspector. Apply its edits
209
+ * with <code>updateStep()</code>.</p>
210
+ * <p>The canvas is infinite, like <code>wc-diagram</code>: pan, zoom, <code>start-position</code>,
211
+ * <code>home()</code>, and the <code>controls</code> and <code>minimap</code> slots. Steps are a tree for
212
+ * screen readers. Up and Down move through steps in reading order, Left and Right move between the
213
+ * paths of a branch (in a horizontal workflow the keys swap), Insert opens the palette after the
214
+ * focused step, Alt + Up or Down moves it, and Shift + Enter collapses or expands a block.</p>
215
+ * <p><code>mode="debug"</code> and <code>mode="history"</code> show a <code>run</code> from your engine:
216
+ * each card gets its status and duration, the path taken is drawn solid and paths not taken are
217
+ * dashed, the running step pulses and a dot travels into each step the run reaches
218
+ * (<code>follow</code> keeps it in view). A failed step shows its error with "Retry from here". In
219
+ * debug mode a debug bar fires <code>debug-action</code> (Continue F5, Step over F10, Step into F11,
220
+ * Restart, Stop Shift+F5), and the dot left of each card toggles a breakpoint (F9) and fires
221
+ * <code>breakpoint-toggle</code>. A loop shows an iteration picker; the steps inside show the picked
222
+ * iteration. History mode is read-only. Editing is off outside <code>design</code>. Pair it with
223
+ * <code>wc-workflow-timeline</code> for a timeline of the run.</p>
224
+ *
225
+ * @example
226
+ * ```html
227
+ * <wc-workflow id="rule" editable style="height: 600px">
228
+ * <wc-diagram-controls slot="controls"></wc-diagram-controls>
229
+ * </wc-workflow>
230
+ * <script>
231
+ * document.getElementById('rule').value = {
232
+ * trigger: { id: 'created', type: 'action', headline: 'Expense created', icon: 'bolt' },
233
+ * steps: [
234
+ * {
235
+ * id: 'amount', type: 'branch', headline: 'Amount check',
236
+ * paths: [
237
+ * { id: 'big', label: 'amount > 1,000', steps: [{ id: 'approve', type: 'action', headline: 'Manager approval' }] },
238
+ * { id: 'small', label: 'Otherwise', isDefault: true, steps: [] }
239
+ * ]
240
+ * },
241
+ * { id: 'end', type: 'end' }
242
+ * ]
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
+ * @slot step:<id> - Custom content for the step with that id, in place of the built-in card.
250
+ *
251
+ * @fires {CustomEvent<WorkflowSelectDetail>} select - A step was chosen with a click, Enter or Space. Detail contains `{ id, step }`.
252
+ * @fires {CustomEvent<WorkflowStepAddDetail>} step-add - Before a step from the palette is added. Cancel it to add the step your own way. Detail contains `{ stepType, list, index, trigger }`.
253
+ * @fires {CustomEvent<WorkflowDeleteDetail>} delete - Before steps are removed. Cancel it to keep them. Detail contains `{ ids }`.
254
+ * @fires {CustomEvent<WorkflowChangeDetail>} change - After every edit. Detail contains `{ value, reason }`.
255
+ * @fires {CustomEvent<WorkflowViewportDetail>} viewport-change - Once per frame while the camera moves and once when it settles. Detail contains `{ x, y, zoom, settled }`.
256
+ * @fires {CustomEvent<WorkflowDebugActionDetail>} debug-action - A debug bar button, a debug shortcut or "Retry from here" was used. Detail contains `{ action, stepId }`.
257
+ * @fires {CustomEvent<WorkflowBreakpointDetail>} breakpoint-toggle - A breakpoint was set or cleared in debug mode. Detail contains `{ id, enabled, breakpoints }`.
258
+ * @fires {CustomEvent<WorkflowIterationDetail>} iteration-change - A different loop iteration was picked. Detail contains `{ loopId, index }`.
259
+ *
260
+ * @cssprop --workflow-card-width - Width of a standard card. Defaults to 280px.
261
+ * @cssprop --workflow-connector-color - Colour of connectors. Defaults to a mix of primary and outline-variant.
262
+ * @cssprop --workflow-background - Canvas background. Defaults to surface-container-lowest.
263
+ * @tags data
264
+ */
265
+ @IndividualComponent
266
+ export class Workflow extends DiagramCanvasElement {
267
+ // ── Static
268
+
269
+ static styles = [styles];
270
+
271
+ // ── Properties
272
+
273
+ /** The workflow: a trigger and its steps. Replaced with a new object, never mutated, on every edit. */
274
+ @property({ attribute: false })
275
+ value: WorkflowValue = { steps: [] };
276
+
277
+ /** Entries of the add-step palette. Defaults to the logic steps (branch, parallel, loop, wait, end). */
278
+ @property({ attribute: false })
279
+ stepTypes: WorkflowStepType[] = WORKFLOW_LOGIC_STEPS;
280
+
281
+ /** Lays the workflow out top to bottom or left to right. */
282
+ @property({ type: String, reflect: true })
283
+ direction: WorkflowDirection = 'vertical';
284
+
285
+ /** How much each card shows: the header only, up to three fields, or everything. */
286
+ @property({ type: String, reflect: true })
287
+ density: WorkflowDensity = 'standard';
288
+
289
+ /** Id of the selected step. */
290
+ @property({ type: String, reflect: true })
291
+ selected = '';
292
+
293
+ /**
294
+ * `design` edits the workflow. `debug` shows a live `run` with a debug bar and breakpoints.
295
+ * `history` replays a past `run`, read-only. Editing is off outside `design`.
296
+ */
297
+ @property({ type: String, reflect: true })
298
+ mode: WorkflowMode = 'design';
299
+
300
+ /** The run to show in `debug` and `history` modes. Your engine produces it. */
301
+ @property({ attribute: false })
302
+ run?: WorkflowRun;
303
+
304
+ /** Ids of steps with a breakpoint, shown and toggled in `debug` mode. */
305
+ @property({ attribute: false })
306
+ breakpoints: string[] = [];
307
+
308
+ /** Keeps the step that is running in view as the run moves. */
309
+ @property({ type: Boolean })
310
+ follow = false;
311
+
312
+ // ── State
313
+
314
+ @state()
315
+ private _palette?: {
316
+ ref: WorkflowListRef;
317
+ index: number;
318
+ trigger: boolean;
319
+ x: number;
320
+ y: number;
321
+ query: string;
322
+ active: number;
323
+ };
324
+
325
+ @state()
326
+ private _collapsed = new Set<string>();
327
+
328
+ @state()
329
+ private _focusId = '';
330
+
331
+ @state()
332
+ private _hoverGap = '';
333
+
334
+ @state()
335
+ private _drag?: { id: string; x: number; y: number; target?: string };
336
+
337
+ @state()
338
+ private _menuFor = '';
339
+
340
+ @state()
341
+ private _announcement = '';
342
+
343
+ /** The iteration shown for each loop, when the person picked one. */
344
+ @state()
345
+ private _iterations = new Map<string, number>();
346
+
347
+ // ── Private fields
348
+
349
+ @query('.wf-viewport')
350
+ private readonly _viewportEl?: HTMLElement;
351
+
352
+ @query('.wf-world')
353
+ private readonly _worldEl?: HTMLElement;
354
+
355
+ @query('.wf-root')
356
+ private readonly _rootEl?: HTMLElement;
357
+
358
+ @query('.wf-connectors')
359
+ private readonly _connectorsEl?: SVGSVGElement;
360
+
361
+ @query('wc-menu')
362
+ private readonly _menu?: Menu;
363
+
364
+ @query('.wf-tokens')
365
+ private readonly _tokensEl?: SVGSVGElement;
366
+
367
+ /** For each step, the loops it is inside, outermost first. */
368
+ private loopParents = new Map<string, string[]>();
369
+
370
+ /** Step statuses at the last render, to spot steps the run just reached. */
371
+ private lastStatuses = new Map<string, WorkflowRunStepStatus>();
372
+
373
+ private pendingTokens: string[] = [];
374
+
375
+ private readonly history = new History<WorkflowValue>();
376
+
377
+ private readonly handledKeys = new WeakSet<Event>();
378
+
379
+ /** Gap keys to the list and index they insert at, from the last render. */
380
+ private gaps = new Map<string, { ref: WorkflowListRef; index: number }>();
381
+
382
+ private unreachable = new Set<string>();
383
+
384
+ private seenCollapsed = new Set<string>();
385
+
386
+ private connectorsDirty = true;
387
+
388
+ private flipBefore?: Map<string, DOMRect>;
389
+
390
+ private trackFrame = 0;
391
+
392
+ private rootObserver?: ResizeObserver;
393
+
394
+ private problemIndex = -1;
395
+
396
+ private stepDrag?: {
397
+ pointerId: number;
398
+ startX: number;
399
+ startY: number;
400
+ id: string;
401
+ element: HTMLElement;
402
+ moved: boolean;
403
+ };
404
+
405
+ // ── Lifecycle
406
+
407
+ disconnectedCallback() {
408
+ super.disconnectedCallback();
409
+ this.rootObserver?.disconnect();
410
+ cancelAnimationFrame(this.trackFrame);
411
+ this.endStepDrag(false);
412
+ }
413
+
414
+ protected willUpdate(changed: PropertyValues<this>) {
415
+ super.willUpdate(changed);
416
+ if (changed.has('value')) {
417
+ this.syncCollapsed();
418
+ this.unreachable = this.findUnreachable();
419
+ this.loopParents = this.findLoopParents();
420
+ if (this.selected && !findStep(this.value, this.selected))
421
+ this.selected = '';
422
+ }
423
+ if (changed.has('run') || changed.has('mode')) this.trackRunChanges();
424
+ if (
425
+ changed.has('run') ||
426
+ changed.has('mode') ||
427
+ changed.has('breakpoints') ||
428
+ changed.has('_iterations' as keyof Workflow) ||
429
+ changed.has('value') ||
430
+ changed.has('direction') ||
431
+ changed.has('density') ||
432
+ changed.has('editable') ||
433
+ changed.has('readonly') ||
434
+ changed.has('_collapsed' as keyof Workflow) ||
435
+ changed.has('_hoverGap' as keyof Workflow) ||
436
+ changed.has('_drag' as keyof Workflow) ||
437
+ changed.has('selected')
438
+ ) {
439
+ this.connectorsDirty = true;
440
+ }
441
+ }
442
+
443
+ protected firstUpdated() {
444
+ if (typeof ResizeObserver !== 'undefined' && this._rootEl) {
445
+ this.rootObserver = new ResizeObserver(() => {
446
+ this.layoutConnectors();
447
+ this.requestUpdate();
448
+ });
449
+ this.rootObserver.observe(this._rootEl);
450
+ }
451
+ document.fonts?.ready.then(() => {
452
+ this.connectorsDirty = true;
453
+ this.requestUpdate();
454
+ });
455
+ }
456
+
457
+ protected updated(changed: PropertyValues<this>) {
458
+ if (this.connectorsDirty) {
459
+ this.connectorsDirty = false;
460
+ this.layoutConnectors();
461
+ }
462
+ this.playFlip();
463
+ if (this.pendingTokens.length) {
464
+ this.animateTokens(this.pendingTokens);
465
+ this.pendingTokens = [];
466
+ }
467
+ if (
468
+ changed.has('run') &&
469
+ this.follow &&
470
+ this.mode !== 'design' &&
471
+ this.run?.current
472
+ ) {
473
+ this.keepInView(this.run.current);
474
+ }
475
+ super.updated(changed);
476
+ }
477
+
478
+ // ── Debugging
479
+
480
+ /** Whether editing is on: `editable`, not `readonly`, and in `design` mode. */
481
+ private get editing(): boolean {
482
+ return this.editable && !this.readonly && this.mode === 'design';
483
+ }
484
+
485
+ /** Whether step cards offer a menu (edit actions in design mode, pinning in debug mode). */
486
+ private get hasMenu(): boolean {
487
+ return this.editable && !this.readonly && this.mode !== 'history';
488
+ }
489
+
490
+ private findLoopParents(): Map<string, string[]> {
491
+ const out = new Map<string, string[]>();
492
+ const visitList = (steps: WorkflowStep[], loops: string[]) => {
493
+ for (const step of steps) {
494
+ out.set(step.id, loops);
495
+ if (step.type === 'loop') visitList(step.steps, [...loops, step.id]);
496
+ else if (step.type === 'branch' || step.type === 'parallel') {
497
+ for (const p of step.paths) visitList(p.steps, loops);
498
+ } else if (step.type === 'action' && step.onError) {
499
+ visitList(step.onError, loops);
500
+ }
501
+ }
502
+ };
503
+ visitList(this.value.steps, []);
504
+ return out;
505
+ }
506
+
507
+ /** The iteration a loop shows: the one picked, else the latest. */
508
+ private iterationIndex(loopId: string, total: number): number {
509
+ const picked = this._iterations.get(loopId);
510
+ return picked !== undefined && picked < total ? picked : total - 1;
511
+ }
512
+
513
+ /** What the run did with a step, looking inside the shown iteration of each loop around it. */
514
+ private runStep(id: string): WorkflowRunStep | undefined {
515
+ const { run } = this;
516
+ if (!run || this.mode === 'design') return undefined;
517
+ let record = run.steps;
518
+ for (const loopId of this.loopParents.get(id) ?? []) {
519
+ const iterations = record[loopId]?.iterations;
520
+ if (!iterations?.length) break;
521
+ record =
522
+ iterations[this.iterationIndex(loopId, iterations.length)] ?? record;
523
+ }
524
+ return record[id] ?? run.steps[id];
525
+ }
526
+
527
+ private statusLabel(
528
+ status: WorkflowRunStepStatus | WorkflowRun['status'],
529
+ ): string {
530
+ const key = {
531
+ queued: 'workflowStatusQueued',
532
+ running: 'workflowStatusRunning',
533
+ waiting: 'workflowStatusWaiting',
534
+ paused: 'workflowStatusPaused',
535
+ success: 'workflowStatusSuccess',
536
+ failed: 'workflowStatusFailed',
537
+ skipped: 'workflowStatusSkipped',
538
+ canceled: 'workflowStatusCanceled',
539
+ }[status] as Parameters<typeof this.i18n.t>[0];
540
+ return this.i18n.t(key) as string;
541
+ }
542
+
543
+ /** Notes the steps the run has just reached, for the travelling token and announcements. */
544
+ private trackRunChanges() {
545
+ const next = new Map<string, WorkflowRunStepStatus>();
546
+ const ids: string[] = [];
547
+ if (this.value.trigger) ids.push(this.value.trigger.id);
548
+ walk(this.value, ({ step }) => ids.push(step.id));
549
+ const reached: string[] = [];
550
+ let latest: { id: string; status: WorkflowRunStepStatus } | undefined;
551
+ for (const id of ids) {
552
+ const status = this.runStep(id)?.status;
553
+ if (status) {
554
+ next.set(id, status);
555
+ const before = this.lastStatuses.get(id);
556
+ if (before !== status) latest = { id, status };
557
+ if (isReached(status) && !isReached(before) && this.lastStatuses.size) {
558
+ reached.push(id);
559
+ }
560
+ }
561
+ }
562
+ if (latest && this.lastStatuses.size) {
563
+ const step = findStep(this.value, latest.id)?.step;
564
+ if (step) {
565
+ this.announce(
566
+ this.i18n.t('workflowStepStatus')(
567
+ this.stepLabel(step),
568
+ this.statusLabel(latest.status),
569
+ ),
570
+ );
571
+ }
572
+ }
573
+ this.lastStatuses = next;
574
+ this.pendingTokens = reached;
575
+ }
576
+
577
+ /** Sends a dot along the connector into each step the run just reached. */
578
+ private animateTokens(ids: string[]) {
579
+ const layer = this._tokensEl;
580
+ const lines = this._connectorsEl;
581
+ if (!layer || !lines || prefersReducedMotion()) return;
582
+ for (const id of ids) {
583
+ const path = lines.querySelector<SVGPathElement>(
584
+ `path[data-to="${CSS.escape(id)}"]`,
585
+ );
586
+ if (path && typeof path.getTotalLength === 'function') {
587
+ const length = path.getTotalLength();
588
+ const halo = document.createElementNS(
589
+ 'http://www.w3.org/2000/svg',
590
+ 'circle',
591
+ );
592
+ const dot = document.createElementNS(
593
+ 'http://www.w3.org/2000/svg',
594
+ 'circle',
595
+ );
596
+ halo.setAttribute('class', 'wf-token-halo');
597
+ halo.setAttribute('r', '12');
598
+ dot.setAttribute('class', 'wf-token');
599
+ dot.setAttribute('r', '5');
600
+ layer.append(halo, dot);
601
+ const start = performance.now();
602
+ const duration = 520;
603
+ const step = (now: number) => {
604
+ const p = Math.min(1, (now - start) / duration);
605
+ const eased = p < 0.5 ? 4 * p ** 3 : 1 - (-2 * p + 2) ** 3 / 2;
606
+ const point = path.getPointAtLength(length * eased);
607
+ for (const c of [halo, dot]) {
608
+ c.setAttribute('cx', String(point.x));
609
+ c.setAttribute('cy', String(point.y));
610
+ }
611
+ if (p < 1) requestAnimationFrame(step);
612
+ else {
613
+ halo.remove();
614
+ dot.remove();
615
+ }
616
+ };
617
+ requestAnimationFrame(step);
618
+ }
619
+ }
620
+ }
621
+
622
+ private toggleBreakpoint(id: string) {
623
+ const enabled = !this.breakpoints.includes(id);
624
+ this.breakpoints = enabled
625
+ ? [...this.breakpoints, id]
626
+ : this.breakpoints.filter(b => b !== id);
627
+ this.emit<WorkflowBreakpointDetail>('breakpoint-toggle', {
628
+ id,
629
+ enabled,
630
+ breakpoints: this.breakpoints,
631
+ });
632
+ }
633
+
634
+ private debugAction(action: WorkflowDebugAction, stepId?: string) {
635
+ this.emit<WorkflowDebugActionDetail>('debug-action', { action, stepId });
636
+ }
637
+
638
+ private setIteration(loopId: string, index: number) {
639
+ const next = new Map(this._iterations);
640
+ next.set(loopId, index);
641
+ this._iterations = next;
642
+ this.emit<WorkflowIterationDetail>('iteration-change', { loopId, index });
643
+ }
644
+
645
+ /** How a loop's iteration went overall, for its tick. */
646
+ private static iterationStatus(
647
+ record: Record<string, WorkflowRunStep>,
648
+ ): WorkflowRunStepStatus {
649
+ const statuses = Object.values(record).map(r => r.status);
650
+ if (statuses.includes('failed')) return 'failed';
651
+ if (
652
+ statuses.some(s => s === 'running' || s === 'paused' || s === 'waiting')
653
+ ) {
654
+ return 'running';
655
+ }
656
+ if (
657
+ statuses.length &&
658
+ statuses.every(s => s === 'success' || s === 'skipped')
659
+ ) {
660
+ return 'success';
661
+ }
662
+ return 'queued';
663
+ }
664
+
665
+ // ── Public API
666
+
667
+ /** Whether `undo()` has something to undo. */
668
+ get canUndo(): boolean {
669
+ return this.history.canUndo;
670
+ }
671
+
672
+ /** Whether `redo()` has something to redo. */
673
+ get canRedo(): boolean {
674
+ return this.history.canRedo;
675
+ }
676
+
677
+ /** Steps that need attention: those marked `invalid`, and steps that can never run. */
678
+ get problems(): WorkflowProblem[] {
679
+ const out: WorkflowProblem[] = [];
680
+ const visit = (step: WorkflowStep) => {
681
+ if (step.invalid)
682
+ out.push({ id: step.id, message: step.errorText ?? '' });
683
+ else if (this.unreachable.has(step.id)) {
684
+ out.push({ id: step.id, message: this.i18n.t('workflowUnreachable') });
685
+ }
686
+ };
687
+ if (this.value.trigger) visit(this.value.trigger);
688
+ walk(this.value, ({ step }) => visit(step));
689
+ return out;
690
+ }
691
+
692
+ undo() {
693
+ const previous = this.history.undo(this.value);
694
+ if (previous) this.commit(previous, 'undo', false);
695
+ }
696
+
697
+ redo() {
698
+ const next = this.history.redo(this.value);
699
+ if (next) this.commit(next, 'redo', false);
700
+ }
701
+
702
+ /** Forgets the undo and redo history, for example after saving. */
703
+ clearHistory() {
704
+ this.history.clear();
705
+ this.listeners.notify();
706
+ }
707
+
708
+ /** Changes a step, for example from an inspector. Records an undo step and fires `change`. */
709
+ updateStep(id: string, patch: Partial<WorkflowStep>) {
710
+ if (!findStep(this.value, id)) return;
711
+ this.commit(
712
+ replaceStep(
713
+ this.value,
714
+ id,
715
+ step => ({ ...step, ...patch, id, type: step.type }) as WorkflowStep,
716
+ ),
717
+ 'update',
718
+ );
719
+ }
720
+
721
+ /** Removes a step and everything inside it, after a cancelable `delete` event. */
722
+ removeStep(id: string) {
723
+ const found = findStep(this.value, id);
724
+ if (!found) return;
725
+ if (!this.emit<WorkflowDeleteDetail>('delete', { ids: [id] }, true)) return;
726
+ const neighbour = this.neighbourAfterRemoval(id);
727
+ const el = this.cardElement(id)?.closest('.wf-item');
728
+ animateOut(el ? [el] : [], () => {
729
+ this.commit(removeStep(this.value, id), 'remove');
730
+ this.announce(
731
+ this.i18n.t('workflowStepRemoved')(this.stepLabel(found.step)),
732
+ );
733
+ if (this.selected === id) this.selected = '';
734
+ if (neighbour) this.focusStep(neighbour);
735
+ });
736
+ }
737
+
738
+ /** Moves keyboard focus to a step and pans it into view. */
739
+ focusStep(id: string) {
740
+ this._focusId = id;
741
+ this.updateComplete.then(() => {
742
+ const el = this.cardElement(id);
743
+ el?.focus({ preventScroll: true });
744
+ this.keepInView(id);
745
+ });
746
+ }
747
+
748
+ /** Selects a step as a click would, fires `select`, and brings it into view. */
749
+ selectStep(id: string) {
750
+ const step = findStep(this.value, id)?.step;
751
+ if (!step) return;
752
+ this.select(step);
753
+ this.focusStep(id);
754
+ }
755
+
756
+ collapse(id: string) {
757
+ const next = new Set(this._collapsed);
758
+ next.add(id);
759
+ this._collapsed = next;
760
+ }
761
+
762
+ expand(id: string) {
763
+ const next = new Set(this._collapsed);
764
+ next.delete(id);
765
+ this._collapsed = next;
766
+ }
767
+
768
+ // ── Canvas hooks
769
+
770
+ protected viewportElement() {
771
+ return this._viewportEl;
772
+ }
773
+
774
+ protected contentBounds(): DiagramRect | undefined {
775
+ const root = this._rootEl;
776
+ if (
777
+ !root ||
778
+ (!this.value.trigger && !this.value.steps.length && !this.editing)
779
+ ) {
780
+ return undefined;
781
+ }
782
+ return { x: 0, y: 0, width: root.offsetWidth, height: root.offsetHeight };
783
+ }
784
+
785
+ protected selectionRects(): DiagramRect[] {
786
+ const r = this.selected ? this.itemRect(this.selected) : undefined;
787
+ return r ? [r] : [];
788
+ }
789
+
790
+ protected itemRect(id: string): DiagramRect | undefined {
791
+ const el = this.cardElement(id);
792
+ return el ? this.rectOf(el) : undefined;
793
+ }
794
+
795
+ protected firstItemRect(): DiagramRect | undefined {
796
+ const el = this._rootEl?.querySelector('[data-card-id], .wf-add-trigger');
797
+ return el ? this.rectOf(el) : undefined;
798
+ }
799
+
800
+ protected overviewItems(): DiagramOverview['items'] {
801
+ const root = this._rootEl;
802
+ if (!root || !this._worldEl) return [];
803
+ return Array.from(root.querySelectorAll<HTMLElement>('[data-card-id]')).map(
804
+ el => ({
805
+ ...this.rectOf(el),
806
+ selected: el.dataset.cardId === this.selected,
807
+ }),
808
+ );
809
+ }
810
+
811
+ protected isBackground(target: EventTarget | null): boolean {
812
+ const el = target as Element | null;
813
+ if (!el) return false;
814
+ if (el === this._viewportEl) return true;
815
+ const cls = el.classList;
816
+ return (
817
+ !!cls &&
818
+ [
819
+ 'wf-world',
820
+ 'wf-root',
821
+ 'wf-seq',
822
+ 'wf-paths',
823
+ 'wf-path',
824
+ 'wf-path-tail',
825
+ 'wf-gap',
826
+ 'wf-connectors',
827
+ 'wf-item',
828
+ 'wf-error-col',
829
+ 'wf-error-spacer',
830
+ ].some(c => cls.contains(c))
831
+ );
832
+ }
833
+
834
+ protected onBackgroundClick() {
835
+ this._palette = undefined;
836
+ this.selected = '';
837
+ }
838
+
839
+ /** Fits the workflow, or shows its start at 60% when fitting it all would be too small to read. */
840
+ protected computeStartView(): DiagramView {
841
+ if (this.startView || this.startPosition !== 'fit')
842
+ return super.computeStartView();
843
+ const bounds = this.contentBounds();
844
+ if (!bounds) return super.computeStartView();
845
+ const fitted = this.viewport.viewForRect(bounds, this.padding);
846
+ if (fitted.zoom >= MIN_FIT_ZOOM) return fitted;
847
+ const zoom = MIN_FIT_ZOOM;
848
+ const { width, height } = this.viewport.size();
849
+ return this.direction === 'vertical'
850
+ ? {
851
+ zoom,
852
+ x: width / 2 - (bounds.x + bounds.width / 2) * zoom,
853
+ y: this.padding - bounds.y * zoom,
854
+ }
855
+ : {
856
+ zoom,
857
+ x: this.padding - bounds.x * zoom,
858
+ y: height / 2 - (bounds.y + bounds.height / 2) * zoom,
859
+ };
860
+ }
861
+
862
+ // ── Private methods: data
863
+
864
+ /** Records an undo step (unless restoring one), animates the change and fires `change`. */
865
+ private commit(
866
+ next: WorkflowValue,
867
+ reason: WorkflowChangeReason,
868
+ record = true,
869
+ ) {
870
+ if (record) this.history.push(this.value);
871
+ this.captureFlip();
872
+ this.value = next;
873
+ this.emit<WorkflowChangeDetail>('change', { value: next, reason });
874
+ this.listeners.notify();
875
+ }
876
+
877
+ private announce(message: string) {
878
+ this._announcement = '';
879
+ requestAnimationFrame(() => {
880
+ this._announcement = message;
881
+ });
882
+ }
883
+
884
+ private syncCollapsed() {
885
+ const next = new Set(this._collapsed);
886
+ let changed = false;
887
+ const visit = (step: WorkflowStep) => {
888
+ if (step.collapsed && !this.seenCollapsed.has(step.id)) {
889
+ this.seenCollapsed.add(step.id);
890
+ next.add(step.id);
891
+ changed = true;
892
+ }
893
+ };
894
+ walk(this.value, ({ step }) => visit(step));
895
+ if (changed) this._collapsed = next;
896
+ }
897
+
898
+ /** Steps after a step that always ends the flow, in the same list. */
899
+ private findUnreachable(): Set<string> {
900
+ const out = new Set<string>();
901
+ const visitList = (steps: WorkflowStep[], dead: boolean) => {
902
+ let gone = dead;
903
+ for (const step of steps) {
904
+ if (gone) out.add(step.id);
905
+ if (step.type === 'branch' || step.type === 'parallel') {
906
+ for (const p of step.paths) visitList(p.steps, gone);
907
+ } else if (step.type === 'loop') {
908
+ visitList(step.steps, gone);
909
+ } else if (step.type === 'action' && step.onError) {
910
+ visitList(step.onError, gone);
911
+ }
912
+ if (stepTerminates(step)) gone = true;
913
+ }
914
+ };
915
+ visitList(this.value.steps, false);
916
+ return out;
917
+ }
918
+
919
+ private stepLabel(step: WorkflowStep): string {
920
+ if (step.headline) return step.headline;
921
+ if (step.type === 'end') return this.i18n.t('workflowEnd');
922
+ return step.id;
923
+ }
924
+
925
+ private neighbourAfterRemoval(id: string): string | undefined {
926
+ const found = findStep(this.value, id);
927
+ if (!found || found.index < 0) return this.value.steps[0]?.id;
928
+ const list = getList(this.value, found.ref) ?? [];
929
+ return (
930
+ list[found.index + 1]?.id ??
931
+ list[found.index - 1]?.id ??
932
+ (found.ref.kind === 'root' ? this.value.trigger?.id : found.ref.stepId)
933
+ );
934
+ }
935
+
936
+ /** Steps in reading order, skipping what is inside collapsed blocks. */
937
+ private navOrder(): string[] {
938
+ const ids: string[] = [];
939
+ if (this.value.trigger) ids.push(this.value.trigger.id);
940
+ walk(this.value, ({ step }) => ids.push(step.id), {
941
+ skip: step => this._collapsed.has(step.id),
942
+ });
943
+ return ids;
944
+ }
945
+
946
+ // ── Private methods: geometry
947
+
948
+ private cardElement(id: string): HTMLElement | null {
949
+ return (
950
+ this._rootEl?.querySelector<HTMLElement>(
951
+ `[data-card-id="${CSS.escape(id)}"]`,
952
+ ) ?? null
953
+ );
954
+ }
955
+
956
+ /** An element's box in canvas coordinates. */
957
+ private rectOf(el: Element): DiagramRect {
958
+ const world = this._worldEl;
959
+ const { zoom } = this.viewport.view;
960
+ const r = el.getBoundingClientRect();
961
+ const w = world?.getBoundingClientRect();
962
+ return {
963
+ x: (r.left - (w?.left ?? 0)) / zoom,
964
+ y: (r.top - (w?.top ?? 0)) / zoom,
965
+ width: r.width / zoom,
966
+ height: r.height / zoom,
967
+ };
968
+ }
969
+
970
+ private keepInView(id: string) {
971
+ const r = this.itemRect(id);
972
+ if (!r) return;
973
+ const v = this.viewport.visibleRect();
974
+ const inside =
975
+ r.x >= v.x &&
976
+ r.y >= v.y &&
977
+ r.x + r.width <= v.x + v.width &&
978
+ r.y + r.height <= v.y + v.height;
979
+ if (!inside) this.centerOn(r.x + r.width / 2, r.y + r.height / 2);
980
+ }
981
+
982
+ /** Draws every connector from the measured positions of cards, pills and joins. */
983
+ private layoutConnectors() {
984
+ const root = this._rootEl;
985
+ const target = this._connectorsEl;
986
+ if (!root || !target || !this._worldEl) return;
987
+ const vertical = this.direction === 'vertical';
988
+ const S = (r: DiagramRect) => (vertical ? r.y : r.x);
989
+ const E = (r: DiagramRect) => (vertical ? r.y + r.height : r.x + r.width);
990
+ const C = (r: DiagramRect) =>
991
+ vertical ? r.x + r.width / 2 : r.y + r.height / 2;
992
+ const CS = (r: DiagramRect) => (vertical ? r.x : r.y);
993
+ const CE = (r: DiagramRect) => (vertical ? r.x + r.width : r.y + r.height);
994
+ const MC = (r: DiagramRect) =>
995
+ vertical ? r.y + r.height / 2 : r.x + r.width / 2;
996
+ const P = (m: number, c: number) =>
997
+ vertical ? { x: c, y: m } : { x: m, y: c };
998
+ const q = (selector: string) => root.querySelector<HTMLElement>(selector);
999
+ const rect = (el: Element) => this.rectOf(el);
1000
+ const paths: SVGTemplateResult[] = [];
1001
+ const { run } = this;
1002
+ const showRun = !!run && this.mode !== 'design';
1003
+ const finished =
1004
+ !!run && ['success', 'failed', 'canceled'].includes(run.status);
1005
+ // A connector is taken when the run reached the step it leads to (or, for a merge, when the
1006
+ // step it leaves succeeded), and not taken when that step was skipped or the run is over.
1007
+ const runClass = (to?: string, from?: string): string => {
1008
+ if (!showRun) return '';
1009
+ let status: WorkflowRunStepStatus | undefined;
1010
+ if (to) status = this.runStep(to)?.status;
1011
+ else if (from && this.runStep(from)?.status === 'success')
1012
+ status = 'success';
1013
+ if (isReached(status)) {
1014
+ return status === 'success' || status === 'failed'
1015
+ ? ' is-taken'
1016
+ : ' is-taken is-active';
1017
+ }
1018
+ if (status === 'skipped' || finished) return ' is-untaken';
1019
+ return '';
1020
+ };
1021
+ const line = (
1022
+ points: { x: number; y: number }[],
1023
+ cls: string,
1024
+ to?: string,
1025
+ from?: string,
1026
+ ) => {
1027
+ paths.push(
1028
+ svg`<path class=${cls + runClass(to, from)} data-to=${to ?? nothing} d=${roundedPath(points, CORNER)}></path>`,
1029
+ );
1030
+ };
1031
+ const link = (from: Point, to: Point, cls: string, toId?: string) => {
1032
+ if (Math.abs(from.c - to.c) < 0.5) {
1033
+ line([P(from.m, from.c), P(to.m, from.c)], cls, toId);
1034
+ } else {
1035
+ const mid = (from.m + to.m) / 2;
1036
+ line(
1037
+ [P(from.m, from.c), P(mid, from.c), P(mid, to.c), P(to.m, to.c)],
1038
+ cls,
1039
+ toId,
1040
+ );
1041
+ }
1042
+ };
1043
+ const gapClass = (ref: WorkflowListRef, index: number, extra = '') => {
1044
+ const key = `${listKey(ref)}#${index}`;
1045
+ return `wf-conn${extra}${this._hoverGap === key || this._drag?.target === key ? ' is-hover' : ''}`;
1046
+ };
1047
+
1048
+ const walkList = (
1049
+ steps: WorkflowStep[],
1050
+ ref: WorkflowListRef,
1051
+ entry: Point | null,
1052
+ extra = '',
1053
+ ): Point | null => {
1054
+ let prev = entry;
1055
+ steps.forEach((step, index) => {
1056
+ const inEl = q(`[data-in-for="${CSS.escape(step.id)}"]`);
1057
+ if (!inEl) return;
1058
+ const r = rect(inEl);
1059
+ if (prev) {
1060
+ link(
1061
+ prev,
1062
+ { m: S(r), c: C(r) },
1063
+ gapClass(ref, index, extra),
1064
+ step.id,
1065
+ );
1066
+ }
1067
+ // walkList and layoutStep call each other for nested paths.
1068
+ // eslint-disable-next-line no-use-before-define
1069
+ prev = layoutStep(step, extra);
1070
+ });
1071
+ const trailing = q(
1072
+ `[data-gap="${CSS.escape(`${listKey(ref)}#${steps.length}`)}"] .wf-plus`,
1073
+ );
1074
+ if (prev && trailing) {
1075
+ const r = rect(trailing);
1076
+ link(
1077
+ prev,
1078
+ { m: S(r), c: C(r) },
1079
+ gapClass(ref, steps.length, `${extra} is-stub`),
1080
+ );
1081
+ }
1082
+ return prev;
1083
+ };
1084
+
1085
+ const layoutStep = (step: WorkflowStep, extra: string): Point | null => {
1086
+ const card = q(`[data-card-id="${CSS.escape(step.id)}"]`);
1087
+ if (!card) return null;
1088
+ const cr = rect(card);
1089
+ if (step.type === 'end') return null;
1090
+ const collapsed = this._collapsed.has(step.id);
1091
+ if ((step.type === 'branch' || step.type === 'parallel') && !collapsed) {
1092
+ const rowEl = q(`[data-paths-for="${CSS.escape(step.id)}"]`);
1093
+ const joinEl = q(`[data-join-for="${CSS.escape(step.id)}"]`);
1094
+ const row = rowEl ? rect(rowEl) : cr;
1095
+ const join = joinEl ? rect(joinEl) : undefined;
1096
+ for (const p of step.paths) {
1097
+ const pillEl = q(`[data-pill="${CSS.escape(p.id)}"]`);
1098
+ if (pillEl) {
1099
+ const pr = rect(pillEl);
1100
+ const fork = (E(cr) + S(pr)) / 2;
1101
+ line(
1102
+ [
1103
+ P(E(cr), C(cr)),
1104
+ P(fork, C(cr)),
1105
+ P(fork, C(pr)),
1106
+ P(S(pr), C(pr)),
1107
+ ],
1108
+ `wf-conn${extra}`,
1109
+ p.steps[0]?.id,
1110
+ );
1111
+ const exit = walkList(
1112
+ p.steps,
1113
+ { kind: 'path', stepId: step.id, pathId: p.id },
1114
+ { m: E(pr), c: C(pr) },
1115
+ extra,
1116
+ );
1117
+ if (exit && join) {
1118
+ const merge = (E(row) + S(join)) / 2;
1119
+ line(
1120
+ [
1121
+ P(exit.m, exit.c),
1122
+ P(merge, exit.c),
1123
+ P(merge, C(join)),
1124
+ P(S(join), C(join)),
1125
+ ],
1126
+ `wf-conn${extra}`,
1127
+ undefined,
1128
+ p.steps[p.steps.length - 1]?.id,
1129
+ );
1130
+ }
1131
+ }
1132
+ }
1133
+ return join ? { m: E(join), c: C(join) } : null;
1134
+ }
1135
+ if (step.type === 'loop' && !collapsed) {
1136
+ const frameEl = q(`[data-loop-for="${CSS.escape(step.id)}"]`);
1137
+ if (!frameEl) return null;
1138
+ const fr = rect(frameEl);
1139
+ const exit = walkList(
1140
+ step.steps,
1141
+ { kind: 'loop', stepId: step.id },
1142
+ { m: E(cr), c: C(cr) },
1143
+ extra,
1144
+ );
1145
+ const firstEl = step.steps[0]
1146
+ ? q(`[data-in-for="${CSS.escape(step.steps[0].id)}"]`)
1147
+ : null;
1148
+ if (exit && firstEl) {
1149
+ const first = rect(firstEl);
1150
+ const lane = CS(fr) + 18;
1151
+ const bottom = Math.min(exit.m + 16, E(fr) - 10);
1152
+ const tipC = CS(first) - 2;
1153
+ line(
1154
+ [
1155
+ P(exit.m, exit.c),
1156
+ P(bottom, exit.c),
1157
+ P(bottom, lane),
1158
+ P(MC(first), lane),
1159
+ P(MC(first), tipC),
1160
+ ],
1161
+ `wf-conn wf-loop-back${extra}${
1162
+ showRun && (this.runStep(step.id)?.iterations?.length ?? 0) > 1
1163
+ ? ' is-taken'
1164
+ : ''
1165
+ }`,
1166
+ );
1167
+ const tip = P(MC(first), tipC);
1168
+ const arrow = vertical
1169
+ ? `M ${tip.x} ${tip.y} l -8 -4.5 l 0 9 z`
1170
+ : `M ${tip.x} ${tip.y} l -4.5 -8 l 9 0 z`;
1171
+ paths.push(svg`<path class="wf-arrow" d=${arrow}></path>`);
1172
+ }
1173
+ return { m: E(fr), c: C(fr) };
1174
+ }
1175
+ if (step.type === 'action' && step.onError) {
1176
+ const pillEl = q(`[data-error-pill="${CSS.escape(step.id)}"]`);
1177
+ if (pillEl) {
1178
+ const pr = rect(pillEl);
1179
+ line(
1180
+ [P(MC(cr), CE(cr)), P(MC(cr), C(pr)), P(S(pr), C(pr))],
1181
+ 'wf-conn is-error',
1182
+ step.onError[0]?.id,
1183
+ );
1184
+ walkList(
1185
+ step.onError,
1186
+ { kind: 'error', stepId: step.id },
1187
+ { m: E(pr), c: C(pr) },
1188
+ ' is-error',
1189
+ );
1190
+ }
1191
+ }
1192
+ if (stepTerminates(step)) return null;
1193
+ return { m: E(cr), c: C(cr) };
1194
+ };
1195
+
1196
+ const triggerEl = q('[data-trigger]');
1197
+ const entry = triggerEl
1198
+ ? { m: E(rect(triggerEl)), c: C(rect(triggerEl)) }
1199
+ : null;
1200
+ walkList(this.value.steps, { kind: 'root' }, entry);
1201
+ renderTemplate(svg`${paths}`, target);
1202
+ }
1203
+
1204
+ /** Keeps connectors on their cards while cards glide. */
1205
+ private trackConnectors(duration: number) {
1206
+ cancelAnimationFrame(this.trackFrame);
1207
+ const until = performance.now() + duration;
1208
+ const step = () => {
1209
+ this.layoutConnectors();
1210
+ if (performance.now() < until)
1211
+ this.trackFrame = requestAnimationFrame(step);
1212
+ };
1213
+ this.trackFrame = requestAnimationFrame(step);
1214
+ }
1215
+
1216
+ private captureFlip() {
1217
+ const root = this._rootEl;
1218
+ if (!root || prefersReducedMotion()) return;
1219
+ const before = new Map<string, DOMRect>();
1220
+ root.querySelectorAll<HTMLElement>('[data-flip]').forEach(el => {
1221
+ before.set(el.dataset.flip ?? '', el.getBoundingClientRect());
1222
+ });
1223
+ this.flipBefore = before;
1224
+ }
1225
+
1226
+ /** Slides moved elements from where they were and pops in new ones. */
1227
+ private playFlip() {
1228
+ const before = this.flipBefore;
1229
+ const root = this._rootEl;
1230
+ this.flipBefore = undefined;
1231
+ if (!before || !root) return;
1232
+ const { zoom } = this.viewport.view;
1233
+ const moved = new Map<Element, { x: number; y: number }>();
1234
+ let animated = false;
1235
+ root.querySelectorAll<HTMLElement>('[data-flip]').forEach(el => {
1236
+ if (typeof el.animate !== 'function') return;
1237
+ const was = before.get(el.dataset.flip ?? '');
1238
+ const now = el.getBoundingClientRect();
1239
+ if (!was) {
1240
+ el.animate(
1241
+ [
1242
+ { opacity: 0, transform: 'scale(0.92)' },
1243
+ { opacity: 1, transform: 'none' },
1244
+ ],
1245
+ { duration: 260, easing: 'cubic-bezier(0.2, 0.9, 0.3, 1.2)' },
1246
+ );
1247
+ animated = true;
1248
+ return;
1249
+ }
1250
+ const total = {
1251
+ x: (was.left - now.left) / zoom,
1252
+ y: (was.top - now.top) / zoom,
1253
+ };
1254
+ moved.set(el, total);
1255
+ const parent = el.parentElement?.closest('[data-flip]');
1256
+ const inherited = (parent && moved.get(parent)) || { x: 0, y: 0 };
1257
+ const dx = total.x - inherited.x;
1258
+ const dy = total.y - inherited.y;
1259
+ if (Math.abs(dx) < 0.5 && Math.abs(dy) < 0.5) return;
1260
+ el.animate(
1261
+ [{ transform: `translate(${dx}px, ${dy}px)` }, { transform: 'none' }],
1262
+ {
1263
+ duration: 320,
1264
+ easing: 'cubic-bezier(0.2, 0, 0, 1)',
1265
+ },
1266
+ );
1267
+ animated = true;
1268
+ });
1269
+ if (animated) this.trackConnectors(340);
1270
+ }
1271
+
1272
+ // ── Private methods: palette
1273
+
1274
+ private openPalette(
1275
+ ref: WorkflowListRef,
1276
+ index: number,
1277
+ anchor: Element | null,
1278
+ trigger = false,
1279
+ ) {
1280
+ const vp = this._viewportEl;
1281
+ if (!vp || !this.editing) return;
1282
+ const vr = vp.getBoundingClientRect();
1283
+ const ar = anchor?.getBoundingClientRect() ?? vr;
1284
+ const width = 300;
1285
+ const height = 380;
1286
+ const x = Math.max(
1287
+ 8,
1288
+ Math.min(ar.right - vr.left + 12, vr.width - width - 8),
1289
+ );
1290
+ const y = Math.max(
1291
+ 8,
1292
+ Math.min(ar.top - vr.top - 24, vr.height - height - 8),
1293
+ );
1294
+ this._palette = { ref, index, trigger, x, y, query: '', active: 0 };
1295
+ this.updateComplete.then(() => {
1296
+ this.renderRoot
1297
+ .querySelector<HTMLInputElement>('.wf-palette input')
1298
+ ?.focus();
1299
+ });
1300
+ }
1301
+
1302
+ private closePalette(refocus = true) {
1303
+ const p = this._palette;
1304
+ this._palette = undefined;
1305
+ if (refocus && p) {
1306
+ const prev = getList(this.value, p.ref)?.[p.index - 1];
1307
+ if (prev) this.focusStep(prev.id);
1308
+ else this._viewportEl?.focus({ preventScroll: true });
1309
+ }
1310
+ }
1311
+
1312
+ private paletteEntries(): WorkflowStepType[] {
1313
+ const p = this._palette;
1314
+ if (!p) return [];
1315
+ const needle = p.query.trim().toLowerCase();
1316
+ return this.stepTypes.filter(
1317
+ t =>
1318
+ !!t.trigger === p.trigger &&
1319
+ (!needle ||
1320
+ t.headline.toLowerCase().includes(needle) ||
1321
+ (t.supportingText ?? '').toLowerCase().includes(needle) ||
1322
+ (t.category ?? '').toLowerCase().includes(needle)),
1323
+ );
1324
+ }
1325
+
1326
+ private choose(type: WorkflowStepType) {
1327
+ const p = this._palette;
1328
+ if (!p) return;
1329
+ this._palette = undefined;
1330
+ const allowed = this.emit<WorkflowStepAddDetail>(
1331
+ 'step-add',
1332
+ { stepType: type, list: p.ref, index: p.index, trigger: p.trigger },
1333
+ true,
1334
+ );
1335
+ if (!allowed) return;
1336
+ const step = createStep(type, allIds(this.value));
1337
+ const next = p.trigger
1338
+ ? {
1339
+ ...this.value,
1340
+ trigger: { ...step, type: 'action' } as WorkflowActionStep,
1341
+ }
1342
+ : insertStep(this.value, p.ref, p.index, step);
1343
+ this.commit(next, 'add');
1344
+ this.selected = step.id;
1345
+ this.emit<WorkflowSelectDetail>('select', { id: step.id, step });
1346
+ this.announce(this.i18n.t('workflowStepAdded')(this.stepLabel(step)));
1347
+ this.focusStep(step.id);
1348
+ }
1349
+
1350
+ private onPaletteKeyDown = (event: KeyboardEvent) => {
1351
+ const p = this._palette;
1352
+ if (!p) return;
1353
+ const entries = this.paletteEntries();
1354
+ if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
1355
+ event.preventDefault();
1356
+ const delta = event.key === 'ArrowDown' ? 1 : -1;
1357
+ const count = Math.max(entries.length, 1);
1358
+ this._palette = { ...p, active: (p.active + delta + count) % count };
1359
+ } else if (event.key === 'Enter') {
1360
+ event.preventDefault();
1361
+ const entry = entries[p.active];
1362
+ if (entry) this.choose(entry);
1363
+ } else if (event.key === 'Escape') {
1364
+ event.preventDefault();
1365
+ this.closePalette();
1366
+ }
1367
+ event.stopPropagation();
1368
+ this.handledKeys.add(event);
1369
+ };
1370
+
1371
+ // ── Private methods: keyboard
1372
+
1373
+ private onCardKeyDown(event: KeyboardEvent, step: WorkflowStep) {
1374
+ if (event.target !== event.currentTarget) return;
1375
+ const handled = (fn: () => void) => {
1376
+ event.preventDefault();
1377
+ this.handledKeys.add(event);
1378
+ fn();
1379
+ };
1380
+ const vertical = this.direction === 'vertical';
1381
+ const mainNext = vertical ? 'ArrowDown' : 'ArrowRight';
1382
+ const mainPrev = vertical ? 'ArrowUp' : 'ArrowLeft';
1383
+ const crossNext = vertical ? 'ArrowRight' : 'ArrowDown';
1384
+ const crossPrev = vertical ? 'ArrowLeft' : 'ArrowUp';
1385
+ const order = this.navOrder();
1386
+ const at = order.indexOf(step.id);
1387
+ const isTrigger = this.value.trigger?.id === step.id;
1388
+ const { key } = event;
1389
+ if (key === 'Enter' && event.shiftKey && this.isBlock(step)) {
1390
+ handled(() =>
1391
+ this._collapsed.has(step.id)
1392
+ ? this.expand(step.id)
1393
+ : this.collapse(step.id),
1394
+ );
1395
+ } else if (key === 'Enter' || key === ' ') {
1396
+ handled(() => this.select(step));
1397
+ } else if (
1398
+ event.altKey &&
1399
+ (key === mainNext || key === mainPrev) &&
1400
+ this.editing &&
1401
+ !isTrigger
1402
+ ) {
1403
+ handled(() => this.nudge(step.id, key === mainNext ? 1 : -1));
1404
+ } else if (key === mainNext && order[at + 1]) {
1405
+ handled(() => this.focusStep(order[at + 1]));
1406
+ } else if (key === mainPrev && at > 0) {
1407
+ handled(() => this.focusStep(order[at - 1]));
1408
+ } else if (key === crossNext || key === crossPrev) {
1409
+ const target = this.crossTarget(step, key === crossNext ? 1 : -1);
1410
+ if (target) handled(() => this.focusStep(target));
1411
+ } else if (key === 'Home' && order[0]) {
1412
+ handled(() => this.focusStep(order[0]));
1413
+ } else if (key === 'End' && order.length) {
1414
+ handled(() => this.focusStep(order[order.length - 1]));
1415
+ } else if ((key === 'Delete' || key === 'Backspace') && this.editing) {
1416
+ handled(() => this.removeStep(step.id));
1417
+ } else if (key === 'Insert' && this.editing && !isTrigger) {
1418
+ handled(() => this.openPaletteAfter(step));
1419
+ } else if ((key === 'F10' && event.shiftKey) || key === 'ContextMenu') {
1420
+ if (this.hasMenu) {
1421
+ handled(() =>
1422
+ this.openMenu(step.id, event.currentTarget as HTMLElement),
1423
+ );
1424
+ }
1425
+ } else if (key === 'F9' && this.mode === 'debug' && step.type !== 'end') {
1426
+ handled(() => this.toggleBreakpoint(step.id));
1427
+ }
1428
+ }
1429
+
1430
+ private onViewportKeyDown = (event: KeyboardEvent) => {
1431
+ if (event.defaultPrevented || this.handledKeys.has(event)) return;
1432
+ const origin = event.composedPath()[0];
1433
+ if (
1434
+ origin instanceof HTMLElement &&
1435
+ origin.matches('input, textarea, select, [contenteditable]')
1436
+ ) {
1437
+ return;
1438
+ }
1439
+ const mod = event.ctrlKey || event.metaKey;
1440
+ const key = event.key.toLowerCase();
1441
+ const run = (fn: () => void) => {
1442
+ event.preventDefault();
1443
+ fn();
1444
+ };
1445
+ if (mod && key === 'z' && this.editing)
1446
+ run(() => (event.shiftKey ? this.redo() : this.undo()));
1447
+ else if (mod && key === 'y' && this.editing) run(() => this.redo());
1448
+ else if (mod && key === 'c' && this.selected)
1449
+ run(() => this.copy(this.selected));
1450
+ else if (mod && key === 'v' && this.editing) run(() => this.paste());
1451
+ else if (mod && key === 'd' && this.editing && this.selected) {
1452
+ run(() => {
1453
+ this.copy(this.selected);
1454
+ this.paste();
1455
+ });
1456
+ } else if (key === 'escape') {
1457
+ run(() => {
1458
+ this._palette = undefined;
1459
+ this.selected = '';
1460
+ });
1461
+ } else if (this.mode === 'debug' && this.handleDebugKey(event)) {
1462
+ event.preventDefault();
1463
+ } else this.handleCanvasKey(event);
1464
+ };
1465
+
1466
+ /** F5 continue or pause (Shift: stop, Ctrl+Shift: restart), F10 step over, F11 step into. */
1467
+ private handleDebugKey(event: KeyboardEvent): boolean {
1468
+ const mod = event.ctrlKey || event.metaKey;
1469
+ if (event.key === 'F5') {
1470
+ if (mod && event.shiftKey) this.debugAction('restart');
1471
+ else if (event.shiftKey) this.debugAction('stop');
1472
+ else
1473
+ this.debugAction(this.run?.status === 'running' ? 'pause' : 'continue');
1474
+ return true;
1475
+ }
1476
+ if (event.key === 'F10' && !event.shiftKey) {
1477
+ this.debugAction('step-over');
1478
+ return true;
1479
+ }
1480
+ if (event.key === 'F11') {
1481
+ this.debugAction('step-into');
1482
+ return true;
1483
+ }
1484
+ return false;
1485
+ }
1486
+
1487
+ private crossTarget(step: WorkflowStep, delta: 1 | -1): string | undefined {
1488
+ const found = findStep(this.value, step.id);
1489
+ if (!found) return undefined;
1490
+ if (delta === 1 && step.type === 'action' && step.onError?.[0])
1491
+ return step.onError[0].id;
1492
+ if (found.ref.kind === 'error' && delta === -1) return found.ref.stepId;
1493
+ if (found.ref.kind !== 'path') return undefined;
1494
+ const { stepId, pathId } = found.ref;
1495
+ const owner = findStep(this.value, stepId)?.step;
1496
+ if (!owner || (owner.type !== 'branch' && owner.type !== 'parallel'))
1497
+ return undefined;
1498
+ const i = owner.paths.findIndex(p => p.id === pathId);
1499
+ const path = owner.paths[i + delta];
1500
+ if (!path?.steps.length) return undefined;
1501
+ return path.steps[Math.min(found.index, path.steps.length - 1)].id;
1502
+ }
1503
+
1504
+ private nudge(id: string, delta: 1 | -1) {
1505
+ const found = findStep(this.value, id);
1506
+ if (!found || found.index < 0) return;
1507
+ const list = getList(this.value, found.ref) ?? [];
1508
+ const target = found.index + delta;
1509
+ if (target < 0 || target >= list.length) return;
1510
+ this.commit(
1511
+ moveStep(this.value, id, found.ref, delta === 1 ? target + 1 : target),
1512
+ 'move',
1513
+ );
1514
+ this.announce(this.i18n.t('workflowStepMoved')(this.stepLabel(found.step)));
1515
+ this.focusStep(id);
1516
+ }
1517
+
1518
+ private openPaletteAfter(step: WorkflowStep) {
1519
+ const found = findStep(this.value, step.id);
1520
+ if (!found) return;
1521
+ const ref = found.index < 0 ? { kind: 'root' as const } : found.ref;
1522
+ const index = found.index + 1;
1523
+ const gap = this._rootEl?.querySelector(
1524
+ `[data-gap="${CSS.escape(`${listKey(ref)}#${index}`)}"]`,
1525
+ );
1526
+ this.openPalette(ref, index, gap ?? this.cardElement(step.id));
1527
+ }
1528
+
1529
+ private copy(id: string) {
1530
+ const step = findStep(this.value, id)?.step;
1531
+ if (step && step.id !== this.value.trigger?.id) clipboard = step;
1532
+ }
1533
+
1534
+ private paste() {
1535
+ if (!clipboard) return;
1536
+ const step = cloneWithNewIds(clipboard, allIds(this.value));
1537
+ const found = this.selected
1538
+ ? findStep(this.value, this.selected)
1539
+ : undefined;
1540
+ const ref =
1541
+ found && found.index >= 0 ? found.ref : { kind: 'root' as const };
1542
+ // After the selected step; at the start when the trigger is selected; else at the end.
1543
+ let index = this.value.steps.length;
1544
+ if (found) index = found.index >= 0 ? found.index + 1 : 0;
1545
+ this.commit(insertStep(this.value, ref, index, step), 'paste');
1546
+ this.select(step);
1547
+ this.focusStep(step.id);
1548
+ }
1549
+
1550
+ private select(step: WorkflowStep) {
1551
+ this.selected = step.id;
1552
+ this.emit<WorkflowSelectDetail>('select', { id: step.id, step });
1553
+ }
1554
+
1555
+ private isBlock(step: WorkflowStep) {
1556
+ return (
1557
+ step.type === 'branch' || step.type === 'parallel' || step.type === 'loop'
1558
+ );
1559
+ }
1560
+
1561
+ private nextProblem() {
1562
+ const { problems } = this;
1563
+ if (!problems.length) return;
1564
+ this.problemIndex = (this.problemIndex + 1) % problems.length;
1565
+ const { id } = problems[this.problemIndex];
1566
+ const step = findStep(this.value, id)?.step;
1567
+ if (step) this.select(step);
1568
+ this.zoomTo(id);
1569
+ this.focusStep(id);
1570
+ }
1571
+
1572
+ // ── Private methods: menu
1573
+
1574
+ private openMenu(id: string, anchor: HTMLElement) {
1575
+ const menu = this._menu;
1576
+ if (!menu) return;
1577
+ this._menuFor = id;
1578
+ menu.anchorElement = anchor;
1579
+ this.updateComplete.then(() => menu.show('first'));
1580
+ }
1581
+
1582
+ private onMenuActivate = (event: Event) => {
1583
+ const item = (
1584
+ event as CustomEvent<{ item: HTMLElement & { value: string } }>
1585
+ ).detail?.item;
1586
+ const id = this._menuFor;
1587
+ if (!item || !id) return;
1588
+ if (item.value === 'duplicate') {
1589
+ this.copy(id);
1590
+ this.selected = id;
1591
+ this.paste();
1592
+ } else if (item.value === 'collapse') this.collapse(id);
1593
+ else if (item.value === 'expand') this.expand(id);
1594
+ else if (item.value === 'delete') this.removeStep(id);
1595
+ else if (item.value === 'pin') this.updateStep(id, { pinned: true });
1596
+ else if (item.value === 'unpin') this.updateStep(id, { pinned: false });
1597
+ };
1598
+
1599
+ // ── Private methods: dragging steps
1600
+
1601
+ private onCardPointerDown(event: PointerEvent, step: WorkflowStep) {
1602
+ if (event.button !== 0 || this.viewport.spaceHeld) return;
1603
+ const origin = event.composedPath()[0];
1604
+ if (origin instanceof Element && origin.closest(INTERACTIVE)) return;
1605
+ event.stopPropagation();
1606
+ const element = event.currentTarget as HTMLElement;
1607
+ element.focus({ preventScroll: true });
1608
+ this._focusId = step.id;
1609
+ this.stepDrag = {
1610
+ pointerId: event.pointerId,
1611
+ startX: event.clientX,
1612
+ startY: event.clientY,
1613
+ id: step.id,
1614
+ element,
1615
+ moved: false,
1616
+ };
1617
+ try {
1618
+ element.setPointerCapture(event.pointerId);
1619
+ } catch {
1620
+ // Synthetic pointers cannot be captured.
1621
+ }
1622
+ element.addEventListener('pointermove', this.onStepPointerMove);
1623
+ element.addEventListener('pointerup', this.onStepPointerUp);
1624
+ element.addEventListener('pointercancel', this.onStepPointerCancel);
1625
+ }
1626
+
1627
+ private onStepPointerMove = (event: PointerEvent) => {
1628
+ const drag = this.stepDrag;
1629
+ if (!drag || event.pointerId !== drag.pointerId) return;
1630
+ const canMove = this.editing && drag.id !== this.value.trigger?.id;
1631
+ if (!canMove) return;
1632
+ if (
1633
+ !drag.moved &&
1634
+ Math.hypot(event.clientX - drag.startX, event.clientY - drag.startY) <
1635
+ DRAG_THRESHOLD
1636
+ ) {
1637
+ return;
1638
+ }
1639
+ drag.moved = true;
1640
+ const vr = this._viewportEl?.getBoundingClientRect();
1641
+ this._drag = {
1642
+ id: drag.id,
1643
+ x: event.clientX - (vr?.left ?? 0),
1644
+ y: event.clientY - (vr?.top ?? 0),
1645
+ target: this.dropTarget(drag.id, event.clientX, event.clientY),
1646
+ };
1647
+ };
1648
+
1649
+ private onStepPointerUp = (event: PointerEvent) => {
1650
+ if (!this.stepDrag || event.pointerId !== this.stepDrag.pointerId) return;
1651
+ this.endStepDrag(true);
1652
+ };
1653
+
1654
+ private onStepPointerCancel = () => {
1655
+ this.endStepDrag(false);
1656
+ };
1657
+
1658
+ private endStepDrag(commit: boolean) {
1659
+ const drag = this.stepDrag;
1660
+ if (!drag) return;
1661
+ this.stepDrag = undefined;
1662
+ const target = this._drag?.target;
1663
+ this._drag = undefined;
1664
+ const { element } = drag;
1665
+ element.removeEventListener('pointermove', this.onStepPointerMove);
1666
+ element.removeEventListener('pointerup', this.onStepPointerUp);
1667
+ element.removeEventListener('pointercancel', this.onStepPointerCancel);
1668
+ try {
1669
+ if (element.hasPointerCapture(drag.pointerId))
1670
+ element.releasePointerCapture(drag.pointerId);
1671
+ } catch {
1672
+ // The pointer is already gone.
1673
+ }
1674
+ if (!commit) return;
1675
+ const step = findStep(this.value, drag.id)?.step;
1676
+ if (!step) return;
1677
+ if (!drag.moved) {
1678
+ this.select(step);
1679
+ return;
1680
+ }
1681
+ const gap = target ? this.gaps.get(target) : undefined;
1682
+ if (!gap) return;
1683
+ this.commit(moveStep(this.value, drag.id, gap.ref, gap.index), 'move');
1684
+ this.announce(this.i18n.t('workflowStepMoved')(this.stepLabel(step)));
1685
+ }
1686
+
1687
+ /** The nearest gap the dragged step can drop into. */
1688
+ private dropTarget(
1689
+ id: string,
1690
+ clientX: number,
1691
+ clientY: number,
1692
+ ): string | undefined {
1693
+ const found = findStep(this.value, id);
1694
+ if (!found) return undefined;
1695
+ let best: { key: string; d: number } | undefined;
1696
+ for (const [key, gap] of this.gaps) {
1697
+ const owner =
1698
+ gap.ref.kind === 'root'
1699
+ ? undefined
1700
+ : findStep(this.value, gap.ref.stepId)?.step;
1701
+ const inside = owner ? contains(found.step, owner.id) : false;
1702
+ const same = listKey(gap.ref) === listKey(found.ref);
1703
+ const noOp =
1704
+ same && (gap.index === found.index || gap.index === found.index + 1);
1705
+ const el = this._rootEl?.querySelector(`[data-gap="${CSS.escape(key)}"]`);
1706
+ if (!inside && !noOp && el) {
1707
+ const r = el.getBoundingClientRect();
1708
+ const d = Math.hypot(
1709
+ clientX - (r.left + r.width / 2),
1710
+ clientY - (r.top + r.height / 2),
1711
+ );
1712
+ if (d < DROP_DISTANCE && (!best || d < best.d)) best = { key, d };
1713
+ }
1714
+ }
1715
+ return best?.key;
1716
+ }
1717
+
1718
+ // ── Render helpers
1719
+
1720
+ private renderValue(text: string) {
1721
+ const parts: (string | TemplateResult)[] = [];
1722
+ let last = 0;
1723
+ for (const match of text.matchAll(DATA_PILL)) {
1724
+ const index = match.index ?? 0;
1725
+ if (index > last) parts.push(text.slice(last, index));
1726
+ const ref = match[1];
1727
+ const source = ref.split('.')[0].trim();
1728
+ let icon = 'data_object';
1729
+ const { trigger } = this.value;
1730
+ if (
1731
+ trigger &&
1732
+ (source === 'Trigger' ||
1733
+ source === trigger.headline ||
1734
+ source === trigger.id)
1735
+ ) {
1736
+ icon = trigger.icon ?? 'bolt';
1737
+ } else {
1738
+ walk(this.value, ({ step }) => {
1739
+ if (step.headline === source || step.id === source)
1740
+ icon = step.icon ?? icon;
1741
+ });
1742
+ }
1743
+ parts.push(
1744
+ html`<span class="wf-ref"
1745
+ ><wc-icon name=${icon}></wc-icon>${ref.replace(/\./, ' · ')}</span
1746
+ >`,
1747
+ );
1748
+ last = index + match[0].length;
1749
+ }
1750
+ if (last < text.length) parts.push(text.slice(last));
1751
+ return parts;
1752
+ }
1753
+
1754
+ private renderCardBody(step: WorkflowStep) {
1755
+ if (this.density === 'compact') return nothing;
1756
+ const limit = this.density === 'expanded' ? Infinity : 3;
1757
+ const rows: [string, string][] = [];
1758
+ if (step.type === 'action')
1759
+ rows.push(
1760
+ ...(step.fields ?? []).map(f => [f.label, f.value] as [string, string]),
1761
+ );
1762
+ if (step.type === 'wait' && step.until)
1763
+ rows.push([this.i18n.t('workflowUntil'), step.until]);
1764
+ const collapsed = this._collapsed.has(step.id) && this.isBlock(step);
1765
+ let pathCount = 1;
1766
+ if (step.type === 'branch' || step.type === 'parallel') {
1767
+ pathCount = step.paths.length;
1768
+ }
1769
+ const summary = collapsed
1770
+ ? this.i18n.t('workflowCollapsedSummary')(pathCount, countInside(step))
1771
+ : '';
1772
+ if (!rows.length && !summary) return nothing;
1773
+ return html`<div class="wf-card-body">
1774
+ ${summary ? html`<div class="wf-summary">${summary}</div>` : nothing}
1775
+ ${rows
1776
+ .slice(0, limit)
1777
+ .map(
1778
+ ([label, value]) =>
1779
+ html`<div class="wf-field">
1780
+ <span class="wf-field-label">${label}</span
1781
+ ><span class="wf-field-value">${this.renderValue(value)}</span>
1782
+ </div>`,
1783
+ )}
1784
+ </div>`;
1785
+ }
1786
+
1787
+ private renderStatus(run: WorkflowRunStep) {
1788
+ const icon = {
1789
+ queued: 'schedule',
1790
+ running: 'progress_activity',
1791
+ waiting: 'hourglass_top',
1792
+ paused: 'pause_circle',
1793
+ success: 'check_circle',
1794
+ failed: 'error',
1795
+ skipped: 'block',
1796
+ canceled: 'cancel',
1797
+ }[run.status];
1798
+ const done = run.status === 'success' || run.status === 'failed';
1799
+ const text =
1800
+ done && run.durationMs !== undefined
1801
+ ? formatDuration(run.durationMs, this.i18n.locale)
1802
+ : this.statusLabel(run.status);
1803
+ return html`<span
1804
+ class=${`wf-status st-${run.status}`}
1805
+ title=${this.statusLabel(run.status)}
1806
+ ><wc-icon name=${icon}></wc-icon>${text}${run.attempts && run.attempts > 1
1807
+ ? html`<span class="wf-attempts">×${run.attempts}</span>`
1808
+ : nothing}</span
1809
+ >`;
1810
+ }
1811
+
1812
+ private renderRunError(step: WorkflowStep, run: WorkflowRunStep | undefined) {
1813
+ if (!run || run.status !== 'failed' || !run.error) return nothing;
1814
+ return html`<div class="wf-run-error">
1815
+ <span
1816
+ class="wf-run-error-text"
1817
+ title=${run.error.detail ?? run.error.message}
1818
+ >${run.error.message}</span
1819
+ >
1820
+ ${this.mode === 'debug'
1821
+ ? html`<button
1822
+ class="wf-retry"
1823
+ type="button"
1824
+ tabindex="-1"
1825
+ @click=${() => this.debugAction('retry', step.id)}
1826
+ >
1827
+ <wc-icon name="replay"></wc-icon>${this.i18n.t(
1828
+ 'workflowRetryFromHere',
1829
+ )}
1830
+ </button>`
1831
+ : nothing}
1832
+ </div>`;
1833
+ }
1834
+
1835
+ /** The iteration picker in a loop's header: previous, "3 / 12", next and a tick per iteration. */
1836
+ private renderIterations(loopId: string) {
1837
+ const iterations = this.runStep(loopId)?.iterations;
1838
+ if (!iterations?.length) return nothing;
1839
+ const total = iterations.length;
1840
+ const index = this.iterationIndex(loopId, total);
1841
+ const ticks = total <= 24;
1842
+ return html`<div
1843
+ class="wf-iterations"
1844
+ role="group"
1845
+ aria-label=${this.i18n.t('workflowIteration')(index + 1, total)}
1846
+ >
1847
+ <wc-icon-button
1848
+ variant="text"
1849
+ shape="round"
1850
+ size="xs"
1851
+ aria-label=${this.i18n.t('workflowPreviousIteration')}
1852
+ ?disabled=${index === 0}
1853
+ @click=${() => this.setIteration(loopId, index - 1)}
1854
+ ><wc-icon name="chevron_left"></wc-icon
1855
+ ></wc-icon-button>
1856
+ <span class="wf-iteration-label"
1857
+ >${this.i18n.t('workflowIterationShort')(index + 1, total)}</span
1858
+ >
1859
+ <wc-icon-button
1860
+ variant="text"
1861
+ shape="round"
1862
+ size="xs"
1863
+ aria-label=${this.i18n.t('workflowNextIteration')}
1864
+ ?disabled=${index === total - 1}
1865
+ @click=${() => this.setIteration(loopId, index + 1)}
1866
+ ><wc-icon name="chevron_right"></wc-icon
1867
+ ></wc-icon-button>
1868
+ ${ticks
1869
+ ? html`<span class="wf-ticks">
1870
+ ${iterations.map(
1871
+ (record, i) =>
1872
+ html`<button
1873
+ type="button"
1874
+ tabindex="-1"
1875
+ class=${classMap({
1876
+ 'wf-tick': true,
1877
+ [`st-${Workflow.iterationStatus(record)}`]: true,
1878
+ 'is-current': i === index,
1879
+ })}
1880
+ aria-label=${this.i18n.t('workflowIteration')(i + 1, total)}
1881
+ @click=${() => this.setIteration(loopId, i)}
1882
+ ></button>`,
1883
+ )}
1884
+ </span>`
1885
+ : nothing}
1886
+ </div>`;
1887
+ }
1888
+
1889
+ private renderDebugBar() {
1890
+ const { run } = this;
1891
+ if (this.mode === 'history') {
1892
+ if (!run) return nothing;
1893
+ return html`<div class=${`wf-runbar st-${run.status}`} role="status">
1894
+ ${this.i18n.t('workflowRunSummary')(
1895
+ run.id,
1896
+ this.statusLabel(run.status),
1897
+ formatDuration(run.durationMs, this.i18n.locale),
1898
+ )}
1899
+ </div>`;
1900
+ }
1901
+ if (this.mode !== 'debug') return nothing;
1902
+ const finished =
1903
+ !run ||
1904
+ run.status === 'success' ||
1905
+ run.status === 'failed' ||
1906
+ run.status === 'canceled';
1907
+ const running = run?.status === 'running';
1908
+ const button = (
1909
+ action: WorkflowDebugAction,
1910
+ icon: string,
1911
+ label: string,
1912
+ disabled = false,
1913
+ ) =>
1914
+ html`<wc-icon-button
1915
+ shape="round"
1916
+ variant=${action === 'continue' || action === 'pause'
1917
+ ? 'filled'
1918
+ : 'tonal'}
1919
+ aria-label=${label}
1920
+ tooltip=${label}
1921
+ ?disabled=${disabled}
1922
+ @click=${() => this.debugAction(action)}
1923
+ ><wc-icon name=${icon}></wc-icon
1924
+ ></wc-icon-button>`;
1925
+ return html`<div
1926
+ class="wf-debugbar"
1927
+ role="toolbar"
1928
+ aria-label=${this.i18n.t('workflowDebugBar')}
1929
+ >
1930
+ ${run
1931
+ ? html`<span class=${`wf-run-status st-${run.status}`}
1932
+ >${this.statusLabel(run.status)}</span
1933
+ >`
1934
+ : nothing}
1935
+ ${running
1936
+ ? button('pause', 'pause', `${this.i18n.t('workflowPause')} (F5)`)
1937
+ : button(
1938
+ 'continue',
1939
+ 'play_arrow',
1940
+ `${this.i18n.t('workflowContinue')} (F5)`,
1941
+ finished && !!run,
1942
+ )}
1943
+ ${button(
1944
+ 'step-over',
1945
+ 'step_over',
1946
+ `${this.i18n.t('workflowStepOver')} (F10)`,
1947
+ finished,
1948
+ )}
1949
+ ${button(
1950
+ 'step-into',
1951
+ 'step_into',
1952
+ `${this.i18n.t('workflowStepInto')} (F11)`,
1953
+ finished,
1954
+ )}
1955
+ ${button(
1956
+ 'restart',
1957
+ 'restart_alt',
1958
+ `${this.i18n.t('workflowRestart')} (Ctrl+Shift+F5)`,
1959
+ )}
1960
+ ${button(
1961
+ 'stop',
1962
+ 'stop',
1963
+ `${this.i18n.t('workflowStop')} (Shift+F5)`,
1964
+ finished,
1965
+ )}
1966
+ </div>`;
1967
+ }
1968
+
1969
+ private renderCardFooter(step: WorkflowStep) {
1970
+ if (this.density === 'compact' || step.type !== 'action') return nothing;
1971
+ const { outputs, tools, assignee } = step;
1972
+ if (!outputs?.length && !tools?.length && !assignee) return nothing;
1973
+ return html`<div class="wf-card-foot">
1974
+ ${assignee
1975
+ ? html`<span class="wf-assignee"
1976
+ ><wc-avatar
1977
+ size="sm"
1978
+ name=${assignee.name}
1979
+ src=${assignee.src ?? nothing}
1980
+ ></wc-avatar
1981
+ >${assignee.name}</span
1982
+ >`
1983
+ : nothing}
1984
+ ${outputs?.length
1985
+ ? html`<span class="wf-foot-label"
1986
+ >${this.i18n.t('workflowOutputs')}</span
1987
+ >${outputs.map(
1988
+ o =>
1989
+ html`<span class="wf-chip" title=${o.type ?? nothing}
1990
+ >${o.name}</span
1991
+ >`,
1992
+ )}`
1993
+ : nothing}
1994
+ ${tools?.length
1995
+ ? tools.map(
1996
+ t =>
1997
+ html`<span class="wf-chip tool"
1998
+ ><wc-icon name=${t.icon ?? 'build'}></wc-icon
1999
+ >${t.headline}</span
2000
+ >`,
2001
+ )
2002
+ : nothing}
2003
+ </div>`;
2004
+ }
2005
+
2006
+ private renderCard(
2007
+ step: WorkflowStep,
2008
+ ctx: {
2009
+ depth: number;
2010
+ index: number;
2011
+ size: number;
2012
+ inAnchor?: boolean;
2013
+ outAnchor?: boolean;
2014
+ trigger?: boolean;
2015
+ },
2016
+ ) {
2017
+ const selected = this.selected === step.id;
2018
+ const invalid = !!step.invalid || this.unreachable.has(step.id);
2019
+ const block = this.isBlock(step);
2020
+ const collapsed = block && this._collapsed.has(step.id);
2021
+ const accent = step.accent ?? this.defaultAccent(step, !!ctx.trigger);
2022
+ const focusId = this._focusId || this.navOrder()[0];
2023
+ const problem = invalid
2024
+ ? step.errorText || this.i18n.t('workflowUnreachable')
2025
+ : '';
2026
+ const run = this.runStep(step.id);
2027
+ const statusText = run ? this.statusLabel(run.status) : '';
2028
+ const label = [
2029
+ this.stepLabel(step),
2030
+ step.supportingText,
2031
+ statusText,
2032
+ problem,
2033
+ ]
2034
+ .filter(Boolean)
2035
+ .join(', ');
2036
+ const breakpoint = this.breakpoints.includes(step.id);
2037
+ return html`<div
2038
+ class=${classMap({
2039
+ 'wf-card': true,
2040
+ [`accent-${accent}`]: true,
2041
+ 'is-selected': selected,
2042
+ 'is-invalid': invalid,
2043
+ 'is-trigger': !!ctx.trigger,
2044
+ 'is-dragging': this._drag?.id === step.id,
2045
+ [`st-${run?.status}`]: !!run,
2046
+ 'is-current': !!run && this.run?.current === step.id,
2047
+ })}
2048
+ data-card-id=${step.id}
2049
+ data-flip=${`card:${step.id}`}
2050
+ data-in-for=${ctx.inAnchor === false ? nothing : step.id}
2051
+ data-out-for=${ctx.outAnchor === false ? nothing : step.id}
2052
+ ?data-trigger=${!!ctx.trigger}
2053
+ role="treeitem"
2054
+ aria-level=${ctx.depth}
2055
+ aria-setsize=${ctx.size}
2056
+ aria-posinset=${ctx.index + 1}
2057
+ aria-selected=${selected ? 'true' : 'false'}
2058
+ aria-expanded=${block ? String(!collapsed) : nothing}
2059
+ aria-label=${label}
2060
+ tabindex=${focusId === step.id ? '0' : '-1'}
2061
+ @pointerdown=${(e: PointerEvent) => this.onCardPointerDown(e, step)}
2062
+ @keydown=${(e: KeyboardEvent) => this.onCardKeyDown(e, step)}
2063
+ @focus=${() => {
2064
+ this._focusId = step.id;
2065
+ }}
2066
+ >
2067
+ ${this.mode === 'debug'
2068
+ ? html`<button
2069
+ class=${classMap({ 'wf-bp': true, 'is-on': breakpoint })}
2070
+ type="button"
2071
+ tabindex="-1"
2072
+ aria-pressed=${breakpoint ? 'true' : 'false'}
2073
+ aria-label=${this.i18n.t('workflowToggleBreakpoint')}
2074
+ title=${this.i18n.t('workflowBreakpoint')}
2075
+ @click=${() => this.toggleBreakpoint(step.id)}
2076
+ ></button>`
2077
+ : nothing}
2078
+ <slot name=${`step:${step.id}`}>
2079
+ <div class="wf-card-head">
2080
+ <span class="wf-tile"
2081
+ >${step.icon
2082
+ ? html`<wc-icon name=${step.icon}></wc-icon>`
2083
+ : nothing}</span
2084
+ >
2085
+ <span class="wf-names">
2086
+ <span class="wf-headline">${this.stepLabel(step)}</span>
2087
+ ${step.supportingText
2088
+ ? html`<span class="wf-kind">${step.supportingText}</span>`
2089
+ : nothing}
2090
+ </span>
2091
+ ${step.pinned
2092
+ ? html`<span class="wf-pin" title=${this.i18n.t('workflowPinned')}
2093
+ ><wc-icon name="keep"></wc-icon
2094
+ ></span>`
2095
+ : nothing}
2096
+ ${invalid && !run
2097
+ ? html`<span
2098
+ class="wf-badge"
2099
+ title=${step.errorText || this.i18n.t('workflowUnreachable')}
2100
+ ><wc-icon name="error"></wc-icon
2101
+ ></span>`
2102
+ : nothing}
2103
+ ${run ? this.renderStatus(run) : nothing}
2104
+ ${block
2105
+ ? html`<wc-icon-button
2106
+ class="wf-toggle"
2107
+ variant="text"
2108
+ shape="round"
2109
+ size="xs"
2110
+ tabindex="-1"
2111
+ aria-label=${this.i18n.t(
2112
+ collapsed ? 'workflowExpand' : 'workflowCollapse',
2113
+ )}
2114
+ @click=${() =>
2115
+ collapsed ? this.expand(step.id) : this.collapse(step.id)}
2116
+ ><wc-icon
2117
+ name=${collapsed ? 'unfold_more' : 'unfold_less'}
2118
+ ></wc-icon
2119
+ ></wc-icon-button>`
2120
+ : nothing}
2121
+ ${this.hasMenu
2122
+ ? html`<wc-icon-button
2123
+ class="wf-more"
2124
+ variant="text"
2125
+ shape="round"
2126
+ size="xs"
2127
+ tabindex="-1"
2128
+ aria-label=${this.i18n.t('workflowMoreActions')}
2129
+ @click=${(e: Event) =>
2130
+ this.openMenu(step.id, e.currentTarget as HTMLElement)}
2131
+ ><wc-icon name="more_vert"></wc-icon
2132
+ ></wc-icon-button>`
2133
+ : nothing}
2134
+ </div>
2135
+ ${this.renderCardBody(step)} ${this.renderRunError(step, run)}
2136
+ ${this.renderCardFooter(step)}
2137
+ </slot>
2138
+ </div>`;
2139
+ }
2140
+
2141
+ private defaultAccent(step: WorkflowStep, trigger: boolean) {
2142
+ if (trigger) return 'primary';
2143
+ switch (step.type) {
2144
+ case 'branch':
2145
+ case 'parallel':
2146
+ return 'orange';
2147
+ case 'loop':
2148
+ return 'purple';
2149
+ case 'wait':
2150
+ return 'yellow';
2151
+ case 'end':
2152
+ return 'neutral';
2153
+ default:
2154
+ return 'blue';
2155
+ }
2156
+ }
2157
+
2158
+ private renderGap(
2159
+ ref: WorkflowListRef,
2160
+ index: number,
2161
+ previous: WorkflowStep | undefined,
2162
+ owner?: WorkflowStep,
2163
+ trailing = false,
2164
+ ) {
2165
+ const key = `${listKey(ref)}#${index}`;
2166
+ this.gaps.set(key, { ref, index });
2167
+ const name = previous
2168
+ ? this.i18n.t('workflowAddStepAfter')(this.stepLabel(previous))
2169
+ : this.i18n.t('workflowAddStepIn')(
2170
+ owner ? this.stepLabel(owner) : this.i18n.t('workflowLabel'),
2171
+ );
2172
+ return html`<div
2173
+ class=${classMap({
2174
+ 'wf-gap': true,
2175
+ 'is-trailing': trailing,
2176
+ 'is-drop': this._drag?.target === key,
2177
+ })}
2178
+ data-gap=${key}
2179
+ >
2180
+ ${this.editing
2181
+ ? html`<button
2182
+ class="wf-plus"
2183
+ type="button"
2184
+ tabindex="-1"
2185
+ aria-label=${name}
2186
+ title=${this.i18n.t('workflowAddStep')}
2187
+ @click=${(e: Event) =>
2188
+ this.openPalette(ref, index, e.currentTarget as Element)}
2189
+ @mouseenter=${() => {
2190
+ this._hoverGap = key;
2191
+ }}
2192
+ @mouseleave=${() => {
2193
+ if (this._hoverGap === key) this._hoverGap = '';
2194
+ }}
2195
+ >
2196
+ <wc-icon name="add"></wc-icon>
2197
+ </button>`
2198
+ : nothing}
2199
+ </div>`;
2200
+ }
2201
+
2202
+ private renderList(
2203
+ steps: WorkflowStep[],
2204
+ ref: WorkflowListRef,
2205
+ depth: number,
2206
+ leading: boolean,
2207
+ owner?: WorkflowStep,
2208
+ ) {
2209
+ return html`<div class="wf-seq" role="group">
2210
+ ${this.renderItems(steps, ref, depth, leading, owner)}
2211
+ </div>`;
2212
+ }
2213
+
2214
+ private renderItems(
2215
+ steps: WorkflowStep[],
2216
+ ref: WorkflowListRef,
2217
+ depth: number,
2218
+ leading: boolean,
2219
+ owner?: WorkflowStep,
2220
+ ) {
2221
+ const out: TemplateResult[] = [];
2222
+ steps.forEach((step, i) => {
2223
+ if (i > 0 || leading)
2224
+ out.push(this.renderGap(ref, i, steps[i - 1], owner));
2225
+ out.push(this.renderStep(step, i, steps.length, depth));
2226
+ });
2227
+ if (!listTerminates(steps) && this.editing) {
2228
+ out.push(
2229
+ this.renderGap(ref, steps.length, steps[steps.length - 1], owner, true),
2230
+ );
2231
+ }
2232
+ return out;
2233
+ }
2234
+
2235
+ private renderStep(
2236
+ step: WorkflowStep,
2237
+ index: number,
2238
+ size: number,
2239
+ depth: number,
2240
+ ): TemplateResult {
2241
+ const ctx = { depth, index, size };
2242
+ const collapsed = this._collapsed.has(step.id);
2243
+ if (step.type === 'end') {
2244
+ const selected = this.selected === step.id;
2245
+ const focusId = this._focusId || this.navOrder()[0];
2246
+ const reached = this.runStep(step.id)?.status;
2247
+ return html`<div class="wf-item">
2248
+ <div
2249
+ class=${classMap({
2250
+ 'wf-end': true,
2251
+ 'is-selected': selected,
2252
+ 'is-invalid': this.unreachable.has(step.id),
2253
+ [`st-${reached}`]: !!reached,
2254
+ })}
2255
+ data-card-id=${step.id}
2256
+ data-in-for=${step.id}
2257
+ data-flip=${`card:${step.id}`}
2258
+ role="treeitem"
2259
+ aria-label=${this.stepLabel(step)}
2260
+ aria-level=${depth}
2261
+ aria-setsize=${size}
2262
+ aria-posinset=${index + 1}
2263
+ aria-selected=${selected ? 'true' : 'false'}
2264
+ tabindex=${focusId === step.id ? '0' : '-1'}
2265
+ @pointerdown=${(e: PointerEvent) => this.onCardPointerDown(e, step)}
2266
+ @keydown=${(e: KeyboardEvent) => this.onCardKeyDown(e, step)}
2267
+ @focus=${() => {
2268
+ this._focusId = step.id;
2269
+ }}
2270
+ >
2271
+ <wc-icon name=${step.icon ?? 'stop_circle'}></wc-icon
2272
+ >${this.stepLabel(step)}
2273
+ </div>
2274
+ </div>`;
2275
+ }
2276
+ if ((step.type === 'branch' || step.type === 'parallel') && !collapsed) {
2277
+ const ends = stepTerminates(step);
2278
+ return html`<div
2279
+ class=${classMap({
2280
+ 'wf-item': true,
2281
+ 'wf-block': true,
2282
+ [step.type]: true,
2283
+ })}
2284
+ >
2285
+ ${this.renderCard(step, { ...ctx, outAnchor: false })}
2286
+ <div class="wf-paths" data-paths-for=${step.id}>
2287
+ ${step.paths.map(p => {
2288
+ const ref: WorkflowListRef = {
2289
+ kind: 'path',
2290
+ stepId: step.id,
2291
+ pathId: p.id,
2292
+ };
2293
+ return html`<div class="wf-path" role="group" aria-label=${p.label}>
2294
+ <div
2295
+ class=${classMap({
2296
+ 'wf-pill': true,
2297
+ 'is-default': !!p.isDefault,
2298
+ })}
2299
+ data-pill=${p.id}
2300
+ data-flip=${`pill:${p.id}`}
2301
+ >
2302
+ ${p.label}
2303
+ </div>
2304
+ ${this.renderList(p.steps, ref, depth + 1, true, step)}
2305
+ <div class="wf-path-tail"></div>
2306
+ </div>`;
2307
+ })}
2308
+ </div>
2309
+ ${ends
2310
+ ? nothing
2311
+ : html`<div
2312
+ class=${classMap({
2313
+ 'wf-join': true,
2314
+ 'is-bar': step.type === 'parallel',
2315
+ })}
2316
+ data-join-for=${step.id}
2317
+ data-out-for=${step.id}
2318
+ data-flip=${`join:${step.id}`}
2319
+ >
2320
+ ${step.type === 'parallel'
2321
+ ? html`<span>${this.i18n.t('workflowWaitForAll')}</span>`
2322
+ : nothing}
2323
+ </div>`}
2324
+ </div>`;
2325
+ }
2326
+ if (step.type === 'loop' && !collapsed) {
2327
+ const mode = {
2328
+ 'for-each': this.i18n.t('workflowLoopForEach'),
2329
+ while: this.i18n.t('workflowLoopWhile'),
2330
+ until: this.i18n.t('workflowLoopUntil'),
2331
+ }[step.mode ?? 'for-each'];
2332
+ return html`<div
2333
+ class="wf-item wf-block wf-loop"
2334
+ data-loop-for=${step.id}
2335
+ data-in-for=${step.id}
2336
+ data-out-for=${step.id}
2337
+ data-flip=${`loop:${step.id}`}
2338
+ >
2339
+ <div class="wf-loop-head">
2340
+ ${this.renderCard(
2341
+ { ...step, supportingText: step.supportingText ?? mode },
2342
+ { ...ctx, inAnchor: false, outAnchor: false },
2343
+ )}
2344
+ ${step.over
2345
+ ? html`<span class="wf-loop-over"
2346
+ >${this.renderValue(step.over)}</span
2347
+ >`
2348
+ : nothing}
2349
+ ${this.renderIterations(step.id)}
2350
+ </div>
2351
+ ${this.renderList(
2352
+ step.steps,
2353
+ { kind: 'loop', stepId: step.id },
2354
+ depth + 1,
2355
+ true,
2356
+ step,
2357
+ )}
2358
+ </div>`;
2359
+ }
2360
+ const card = this.renderCard(step, ctx);
2361
+ if (step.type === 'action' && step.onError) {
2362
+ return html`<div class="wf-item wf-has-error">
2363
+ <div class="wf-error-spacer"></div>
2364
+ ${card}
2365
+ <div class="wf-error-col">
2366
+ <div
2367
+ class="wf-pill is-error"
2368
+ data-error-pill=${step.id}
2369
+ data-flip=${`err:${step.id}`}
2370
+ >
2371
+ ${this.i18n.t('workflowOnError')}
2372
+ </div>
2373
+ ${this.renderList(
2374
+ step.onError,
2375
+ { kind: 'error', stepId: step.id },
2376
+ depth + 1,
2377
+ true,
2378
+ step,
2379
+ )}
2380
+ </div>
2381
+ </div>`;
2382
+ }
2383
+ return html`<div class="wf-item">${card}</div>`;
2384
+ }
2385
+
2386
+ private renderPalette() {
2387
+ const p = this._palette;
2388
+ if (!p) return nothing;
2389
+ const entries = this.paletteEntries();
2390
+ const groups = new Map<
2391
+ string,
2392
+ { entry: WorkflowStepType; index: number }[]
2393
+ >();
2394
+ entries.forEach((entry, index) => {
2395
+ const name = entry.category ?? '';
2396
+ if (!groups.has(name)) groups.set(name, []);
2397
+ groups.get(name)?.push({ entry, index });
2398
+ });
2399
+ const activeId = entries[p.active] ? `wf-option-${p.active}` : '';
2400
+ return html`<div
2401
+ class="wf-palette"
2402
+ data-diagram-overlay
2403
+ role="dialog"
2404
+ aria-label=${this.i18n.t(
2405
+ p.trigger ? 'workflowAddTrigger' : 'workflowAddStep',
2406
+ )}
2407
+ style="left: ${p.x}px; top: ${p.y}px;"
2408
+ @pointerdown=${(e: Event) => e.stopPropagation()}
2409
+ >
2410
+ <label class="wf-palette-search">
2411
+ <wc-icon name="search"></wc-icon>
2412
+ <input
2413
+ type="search"
2414
+ role="combobox"
2415
+ aria-expanded="true"
2416
+ aria-controls="wf-palette-list"
2417
+ aria-activedescendant=${activeId || nothing}
2418
+ placeholder=${this.i18n.t('workflowSearchSteps')}
2419
+ aria-label=${this.i18n.t('workflowSearchSteps')}
2420
+ .value=${p.query}
2421
+ @input=${(e: Event) => {
2422
+ this._palette = {
2423
+ ...p,
2424
+ query: (e.target as HTMLInputElement).value,
2425
+ active: 0,
2426
+ };
2427
+ }}
2428
+ @keydown=${this.onPaletteKeyDown}
2429
+ />
2430
+ </label>
2431
+ <div
2432
+ class="wf-palette-list"
2433
+ id="wf-palette-list"
2434
+ role="listbox"
2435
+ aria-label=${this.i18n.t('workflowAddStep')}
2436
+ >
2437
+ ${entries.length
2438
+ ? [...groups].map(
2439
+ ([name, items]) =>
2440
+ html`<div
2441
+ class="wf-palette-group"
2442
+ role="group"
2443
+ aria-label=${name || nothing}
2444
+ >
2445
+ ${name
2446
+ ? html`<div class="wf-palette-heading" aria-hidden="true">
2447
+ ${name}
2448
+ </div>`
2449
+ : nothing}
2450
+ ${items.map(
2451
+ ({ entry, index }) =>
2452
+ html`<div
2453
+ id=${`wf-option-${index}`}
2454
+ class=${classMap({
2455
+ 'wf-option': true,
2456
+ 'is-active': index === p.active,
2457
+ })}
2458
+ role="option"
2459
+ aria-selected=${index === p.active ? 'true' : 'false'}
2460
+ @click=${() => this.choose(entry)}
2461
+ @keydown=${this.onPaletteKeyDown}
2462
+ @pointermove=${() => {
2463
+ if (this._palette && this._palette.active !== index)
2464
+ this._palette = { ...this._palette, active: index };
2465
+ }}
2466
+ >
2467
+ <span
2468
+ class=${`wf-tile accent-${entry.accent ?? this.defaultAccent({ id: '', type: entry.type } as WorkflowStep, !!entry.trigger)}`}
2469
+ >${entry.icon
2470
+ ? html`<wc-icon name=${entry.icon}></wc-icon>`
2471
+ : nothing}</span
2472
+ >
2473
+ <span class="wf-option-text">
2474
+ <span class="wf-option-title">${entry.headline}</span>
2475
+ ${entry.supportingText
2476
+ ? html`<span class="wf-option-sub"
2477
+ >${entry.supportingText}</span
2478
+ >`
2479
+ : nothing}
2480
+ </span>
2481
+ </div>`,
2482
+ )}
2483
+ </div>`,
2484
+ )
2485
+ : html`<div class="wf-palette-empty">
2486
+ ${this.i18n.t('workflowNoSteps')}
2487
+ </div>`}
2488
+ </div>
2489
+ </div>`;
2490
+ }
2491
+
2492
+ private renderMenu() {
2493
+ const step = this._menuFor
2494
+ ? findStep(this.value, this._menuFor)?.step
2495
+ : undefined;
2496
+ const block = step ? this.isBlock(step) : false;
2497
+ const collapsed = step ? this._collapsed.has(step.id) : false;
2498
+ const isTrigger = step?.id === this.value.trigger?.id;
2499
+ const pin = html`<wc-menu-item value=${step?.pinned ? 'unpin' : 'pin'}
2500
+ ><wc-icon slot="start" name="keep"></wc-icon>${this.i18n.t(
2501
+ step?.pinned ? 'workflowUnpinData' : 'workflowPinData',
2502
+ )}</wc-menu-item
2503
+ >`;
2504
+ if (!this.editing) {
2505
+ return html`<wc-menu
2506
+ placement="bottom-end"
2507
+ @menu-item-activate=${this.onMenuActivate}
2508
+ >
2509
+ ${pin}
2510
+ </wc-menu>`;
2511
+ }
2512
+ return html`<wc-menu
2513
+ placement="bottom-end"
2514
+ @menu-item-activate=${this.onMenuActivate}
2515
+ >
2516
+ ${pin}
2517
+ ${isTrigger
2518
+ ? nothing
2519
+ : html`<wc-menu-item value="duplicate"
2520
+ ><wc-icon slot="start" name="content_copy"></wc-icon>${this.i18n.t(
2521
+ 'workflowDuplicate',
2522
+ )}<span slot="trailing-supporting-text">Ctrl+D</span></wc-menu-item
2523
+ >`}
2524
+ ${block
2525
+ ? html`<wc-menu-item value=${collapsed ? 'expand' : 'collapse'}
2526
+ ><wc-icon
2527
+ slot="start"
2528
+ name=${collapsed ? 'unfold_more' : 'unfold_less'}
2529
+ ></wc-icon
2530
+ >${this.i18n.t(
2531
+ collapsed ? 'workflowExpand' : 'workflowCollapse',
2532
+ )}</wc-menu-item
2533
+ >`
2534
+ : nothing}
2535
+ <wc-menu-item value="delete"
2536
+ ><wc-icon slot="start" name="delete"></wc-icon>${this.i18n.t(
2537
+ 'workflowDelete',
2538
+ )}<span slot="trailing-supporting-text">Del</span></wc-menu-item
2539
+ >
2540
+ </wc-menu>`;
2541
+ }
2542
+
2543
+ private renderDragGhost() {
2544
+ const drag = this._drag;
2545
+ if (!drag) return nothing;
2546
+ const step = findStep(this.value, drag.id)?.step;
2547
+ if (!step) return nothing;
2548
+ return html`<div
2549
+ class="wf-ghost"
2550
+ style="left: ${drag.x}px; top: ${drag.y}px;"
2551
+ >
2552
+ ${step.icon
2553
+ ? html`<wc-icon name=${step.icon}></wc-icon>`
2554
+ : nothing}${this.stepLabel(step)}
2555
+ </div>`;
2556
+ }
2557
+
2558
+ /** The trigger card, or a button to add one while editing. */
2559
+ private renderTrigger() {
2560
+ const { trigger } = this.value;
2561
+ if (trigger) {
2562
+ return html`<div class="wf-item">
2563
+ ${this.renderCard(trigger, {
2564
+ depth: 1,
2565
+ index: 0,
2566
+ size: 1,
2567
+ trigger: true,
2568
+ })}
2569
+ </div>`;
2570
+ }
2571
+ if (!this.editing) return nothing;
2572
+ return html`<div class="wf-item">
2573
+ <button
2574
+ class="wf-add-trigger"
2575
+ type="button"
2576
+ data-trigger
2577
+ data-flip=${TRIGGER_GAP}
2578
+ @click=${(e: Event) =>
2579
+ this.openPalette(
2580
+ { kind: 'root' },
2581
+ 0,
2582
+ e.currentTarget as Element,
2583
+ true,
2584
+ )}
2585
+ >
2586
+ <wc-icon name="bolt"></wc-icon>${this.i18n.t('workflowAddTrigger')}
2587
+ </button>
2588
+ </div>`;
2589
+ }
2590
+
2591
+ // ── Render
2592
+
2593
+ protected render() {
2594
+ const { x, y, zoom } = this.viewport.view;
2595
+ this.gaps = new Map();
2596
+ const { trigger } = this.value;
2597
+ const { problems } = this;
2598
+ return html`
2599
+ <div
2600
+ class=${classMap({
2601
+ 'wf-viewport': true,
2602
+ 'is-panning': this.viewport.panning,
2603
+ 'is-space': this.viewport.spaceHeld,
2604
+ 'is-dragging': !!this._drag,
2605
+ })}
2606
+ tabindex="0"
2607
+ role="region"
2608
+ aria-label=${this.label || this.i18n.t('workflowLabel')}
2609
+ aria-describedby="instructions"
2610
+ style=${this.gridStyle()}
2611
+ @keydown=${this.onViewportKeyDown}
2612
+ @pointerdown=${() => {
2613
+ if (this._palette) this._palette = undefined;
2614
+ }}
2615
+ >
2616
+ <div
2617
+ class="wf-world"
2618
+ style="transform: translate(${x}px, ${y}px) scale(${zoom});"
2619
+ >
2620
+ <svg
2621
+ class="wf-connectors"
2622
+ width="1"
2623
+ height="1"
2624
+ aria-hidden="true"
2625
+ ></svg>
2626
+ <div
2627
+ class=${classMap({
2628
+ 'wf-root': true,
2629
+ [this.direction]: true,
2630
+ [`density-${this.density}`]: true,
2631
+ })}
2632
+ role="tree"
2633
+ aria-label=${this.label || this.i18n.t('workflowLabel')}
2634
+ >
2635
+ <div class="wf-seq" role="group">
2636
+ ${this.renderTrigger()}
2637
+ ${this.renderItems(
2638
+ this.value.steps,
2639
+ { kind: 'root' },
2640
+ 1,
2641
+ !!trigger || this.editing,
2642
+ )}
2643
+ </div>
2644
+ </div>
2645
+ <svg class="wf-tokens" width="1" height="1" aria-hidden="true"></svg>
2646
+ </div>
2647
+ ${this.renderDebugBar()}
2648
+ ${problems.length && this.mode === 'design'
2649
+ ? html`<button
2650
+ class="wf-problems"
2651
+ type="button"
2652
+ @click=${() => this.nextProblem()}
2653
+ >
2654
+ <wc-icon name="error"></wc-icon>${this.i18n.t('workflowProblems')(
2655
+ problems.length,
2656
+ )}
2657
+ </button>`
2658
+ : nothing}
2659
+ ${this.renderPalette()} ${this.renderDragGhost()}
2660
+ ${this.renderBackToContent()}
2661
+ <div class="slot-controls"><slot name="controls"></slot></div>
2662
+ <div class="slot-minimap"><slot name="minimap"></slot></div>
2663
+ <div id="instructions" hidden>
2664
+ ${this.i18n.t('diagramInstructions')}
2665
+ </div>
2666
+ <div class="sr-only" aria-live="polite">${this._announcement}</div>
2667
+ ${this.renderMenu()}
2668
+ </div>
2669
+ `;
2670
+ }
2671
+ }
2672
+
2673
+ // The connector layer is measured after each render, so a second update is expected.
2674
+ Workflow.disableWarning?.('change-in-update');