@motifx-community/ui 0.1.0-beta.14 → 0.1.0-beta.16

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 (330) hide show
  1. package/CHANGELOG.md +113 -0
  2. package/README.md +2 -2
  3. package/dist/components/diagram/Diagram.d.ts +607 -0
  4. package/dist/components/diagram/DiagramAutoPan.d.ts +17 -0
  5. package/dist/components/diagram/DiagramBends.d.ts +70 -0
  6. package/dist/components/diagram/DiagramDragging.d.ts +66 -0
  7. package/dist/components/diagram/DiagramEdgeView.d.ts +78 -0
  8. package/dist/components/diagram/DiagramGrid.d.ts +13 -0
  9. package/dist/components/diagram/DiagramHistory.d.ts +16 -0
  10. package/dist/components/diagram/DiagramLinks.d.ts +177 -0
  11. package/dist/components/diagram/DiagramMap.d.ts +62 -0
  12. package/dist/components/diagram/DiagramNodeView.d.ts +143 -0
  13. package/dist/components/diagram/DiagramOverview.d.ts +20 -0
  14. package/dist/components/diagram/DiagramPanning.d.ts +34 -0
  15. package/dist/components/diagram/diagram-alignment.d.ts +2 -0
  16. package/dist/components/diagram/diagram-auto-pan-host.d.ts +8 -0
  17. package/dist/components/diagram/diagram-background.d.ts +2 -0
  18. package/dist/components/diagram/diagram-bends-host.d.ts +17 -0
  19. package/dist/components/diagram/diagram-card-kind.d.ts +42 -0
  20. package/dist/components/diagram/diagram-card-node.d.ts +11 -0
  21. package/dist/components/diagram/diagram-center-options.d.ts +6 -0
  22. package/dist/components/diagram/diagram-change.d.ts +11 -0
  23. package/dist/components/diagram/diagram-class-member.d.ts +13 -0
  24. package/dist/components/diagram/diagram-class-node.d.ts +12 -0
  25. package/dist/components/diagram/diagram-column-checked-event-args.d.ts +9 -0
  26. package/dist/components/diagram/diagram-connected-event-args.d.ts +6 -0
  27. package/dist/components/diagram/diagram-connecting-event-args.d.ts +9 -0
  28. package/dist/components/diagram/diagram-connection.d.ts +7 -0
  29. package/dist/components/diagram/diagram-data.d.ts +12 -0
  30. package/dist/components/diagram/diagram-deleted-event-args.d.ts +8 -0
  31. package/dist/components/diagram/diagram-deleting-event-args.d.ts +9 -0
  32. package/dist/components/diagram/diagram-dragging-host.d.ts +47 -0
  33. package/dist/components/diagram/diagram-drawn-node.d.ts +10 -0
  34. package/dist/components/diagram/diagram-edge-end.d.ts +2 -0
  35. package/dist/components/diagram/diagram-edge-path.d.ts +5 -0
  36. package/dist/components/diagram/diagram-edge-reshaped-event-args.d.ts +8 -0
  37. package/dist/components/diagram/diagram-edge-reshaping-event-args.d.ts +6 -0
  38. package/dist/components/diagram/diagram-edge.d.ts +49 -0
  39. package/dist/components/diagram/diagram-edit.d.ts +10 -0
  40. package/dist/components/diagram/diagram-export-options.d.ts +14 -0
  41. package/dist/components/diagram/diagram-export.d.ts +28 -0
  42. package/dist/components/diagram/diagram-fit-options.d.ts +12 -0
  43. package/dist/components/diagram/diagram-history-changed-event-args.d.ts +14 -0
  44. package/dist/components/diagram/diagram-history-step.d.ts +9 -0
  45. package/dist/components/diagram/diagram-kinds.d.ts +9 -0
  46. package/dist/components/diagram/diagram-layered.d.ts +39 -0
  47. package/dist/components/diagram/diagram-layout-direction.d.ts +2 -0
  48. package/dist/components/diagram/diagram-layout-options.d.ts +24 -0
  49. package/dist/components/diagram/diagram-layout-type.d.ts +5 -0
  50. package/dist/components/diagram/diagram-layout.d.ts +33 -0
  51. package/dist/components/diagram/diagram-line-look.d.ts +6 -0
  52. package/dist/components/diagram/diagram-line.d.ts +11 -0
  53. package/dist/components/diagram/diagram-links-host.d.ts +45 -0
  54. package/dist/components/diagram/diagram-links-options.d.ts +7 -0
  55. package/dist/components/diagram/diagram-map-props.d.ts +10 -0
  56. package/dist/components/diagram/diagram-map-target.d.ts +27 -0
  57. package/dist/components/diagram/diagram-marker.d.ts +6 -0
  58. package/dist/components/diagram/diagram-mini-map-options.d.ts +13 -0
  59. package/dist/components/diagram/diagram-mini-map-position.d.ts +2 -0
  60. package/dist/components/diagram/diagram-node-context.d.ts +26 -0
  61. package/dist/components/diagram/diagram-node-host.d.ts +23 -0
  62. package/dist/components/diagram/diagram-node-kind.d.ts +43 -0
  63. package/dist/components/diagram/diagram-node-move.d.ts +11 -0
  64. package/dist/components/diagram/diagram-node-resized-event-args.d.ts +8 -0
  65. package/dist/components/diagram/diagram-node-resizing-event-args.d.ts +6 -0
  66. package/dist/components/diagram/diagram-node-size.d.ts +8 -0
  67. package/dist/components/diagram/diagram-node-status.d.ts +2 -0
  68. package/dist/components/diagram/diagram-node-toggled-event-args.d.ts +7 -0
  69. package/dist/components/diagram/diagram-node.d.ts +56 -0
  70. package/dist/components/diagram/diagram-nodes-moved-event-args.d.ts +6 -0
  71. package/dist/components/diagram/diagram-nodes-moving-event-args.d.ts +6 -0
  72. package/dist/components/diagram/diagram-panning-host.d.ts +19 -0
  73. package/dist/components/diagram/diagram-pasted-event-args.d.ts +7 -0
  74. package/dist/components/diagram/diagram-pasting-event-args.d.ts +11 -0
  75. package/dist/components/diagram/diagram-path-ends.d.ts +11 -0
  76. package/dist/components/diagram/diagram-path-result.d.ts +6 -0
  77. package/dist/components/diagram/diagram-paths.d.ts +35 -0
  78. package/dist/components/diagram/diagram-point.d.ts +5 -0
  79. package/dist/components/diagram/diagram-port-place.d.ts +9 -0
  80. package/dist/components/diagram/diagram-port.d.ts +27 -0
  81. package/dist/components/diagram/diagram-props.d.ts +159 -0
  82. package/dist/components/diagram/diagram-reconnected-event-args.d.ts +10 -0
  83. package/dist/components/diagram/diagram-reconnecting-event-args.d.ts +11 -0
  84. package/dist/components/diagram/diagram-rect.d.ts +7 -0
  85. package/dist/components/diagram/diagram-resize-side.d.ts +2 -0
  86. package/dist/components/diagram/diagram-route.d.ts +10 -0
  87. package/dist/components/diagram/diagram-selection-changed-event-args.d.ts +9 -0
  88. package/dist/components/diagram/diagram-selection.d.ts +5 -0
  89. package/dist/components/diagram/diagram-side.d.ts +2 -0
  90. package/dist/components/diagram/diagram-table-column.d.ts +13 -0
  91. package/dist/components/diagram/diagram-table-node.d.ts +12 -0
  92. package/dist/components/diagram/diagram-tree.d.ts +14 -0
  93. package/dist/components/diagram/diagram-viewport-changed-event-args.d.ts +8 -0
  94. package/dist/components/diagram/diagram-viewport-options.d.ts +5 -0
  95. package/dist/components/diagram/diagram-viewport.d.ts +6 -0
  96. package/dist/components/diagram/index.d.ts +65 -0
  97. package/dist/components/diagram/swallow-next-click.d.ts +5 -0
  98. package/dist/components/expressioneditor/ExpressionEditor.d.ts +111 -0
  99. package/dist/components/expressioneditor/expression-editor-props.d.ts +24 -0
  100. package/dist/components/expressioneditor/index.d.ts +2 -0
  101. package/dist/components/formlayout/FormLayout.d.ts +10 -3
  102. package/dist/components/formlayout/form-editor-type.d.ts +1 -1
  103. package/dist/components/formlayout/form-item.d.ts +4 -1
  104. package/dist/components/formlayout/form-layout-props.d.ts +1 -1
  105. package/dist/components/formlayout/index.d.ts +1 -0
  106. package/dist/components/formlayout/schema-items.d.ts +26 -0
  107. package/dist/components/pivotgrid/model/PivotAxisWindow.d.ts +53 -1
  108. package/dist/components/pivotgrid/model/PivotCellWindow.d.ts +2 -0
  109. package/dist/components/pivotgrid/model/PivotWindows.d.ts +3 -6
  110. package/dist/components/toolbar/Toolbar.d.ts +5 -3
  111. package/dist/core/control.d.ts +2 -0
  112. package/dist/core/keyboard.d.ts +5 -0
  113. package/dist/core/measure/index.d.ts +2 -0
  114. package/dist/core/measure/picture.d.ts +27 -0
  115. package/dist/core/shortcut-options.d.ts +5 -2
  116. package/dist/core/ui-strings.d.ts +191 -0
  117. package/dist/generated/tokens.d.ts +1615 -0
  118. package/dist/index.d.ts +2 -0
  119. package/dist/index.js +11501 -705
  120. package/dist/index.js.map +1 -1
  121. package/dist/locales/en.json +180 -1
  122. package/dist/locales/tr.json +180 -1
  123. package/dist/styles.css +2262 -3
  124. package/dist/tokens/index.d.ts +1615 -0
  125. package/dist/tokens/index.js +1615 -0
  126. package/dist/tokens/index.js.map +1 -1
  127. package/dist/{tr-BGbF9uCs.js → tr-4GNbFdQh.js} +361 -3
  128. package/dist/{tr-BGbF9uCs.js.map → tr-4GNbFdQh.js.map} +1 -1
  129. package/docs/accordion.md +1 -1
  130. package/docs/actionsheet.md +1 -1
  131. package/docs/appbar.md +1 -1
  132. package/docs/appmenu-api.md +1 -1
  133. package/docs/appmenu-programmatic.md +1 -1
  134. package/docs/appmenu-search.md +1 -1
  135. package/docs/appmenu.md +1 -1
  136. package/docs/avatar.md +1 -1
  137. package/docs/badge.md +1 -1
  138. package/docs/bar-gauge-angles.md +1 -1
  139. package/docs/bar-gauge-data.md +1 -1
  140. package/docs/bar-gauge-labels.md +1 -1
  141. package/docs/bar-gauge.md +1 -1
  142. package/docs/barcode.md +1 -1
  143. package/docs/bottomnavigation.md +1 -1
  144. package/docs/bottomsheet.md +1 -1
  145. package/docs/breadcrumb.md +1 -1
  146. package/docs/button.md +1 -1
  147. package/docs/buttongroup.md +1 -1
  148. package/docs/buttons.md +1 -1
  149. package/docs/calendar.md +1 -1
  150. package/docs/card.md +1 -1
  151. package/docs/chart-bars.md +1 -1
  152. package/docs/chart-candles.md +1 -1
  153. package/docs/chart-funnel.md +1 -1
  154. package/docs/chart-heatmap.md +1 -1
  155. package/docs/chart-lines.md +1 -1
  156. package/docs/chart-live.md +1 -1
  157. package/docs/chart-pie.md +1 -1
  158. package/docs/chart-radar.md +1 -1
  159. package/docs/chart-ranges.md +1 -1
  160. package/docs/chart-references.md +1 -1
  161. package/docs/chart-scatter.md +1 -1
  162. package/docs/chart-waterfall.md +1 -1
  163. package/docs/chart-zoom.md +1 -1
  164. package/docs/chart.md +1 -1
  165. package/docs/chat.md +1 -1
  166. package/docs/checkbox.md +1 -1
  167. package/docs/chip.md +1 -1
  168. package/docs/choice.md +1 -1
  169. package/docs/colorbox.md +1 -1
  170. package/docs/combobox.md +1 -1
  171. package/docs/commands.md +1 -1
  172. package/docs/control.md +1 -1
  173. package/docs/data.md +2 -2
  174. package/docs/datagrid-api.md +1 -1
  175. package/docs/datagrid-bands.md +1 -1
  176. package/docs/datagrid-drag-select.md +1 -1
  177. package/docs/datagrid-drag.md +1 -1
  178. package/docs/datagrid-editing.md +1 -1
  179. package/docs/datagrid-filtering.md +1 -1
  180. package/docs/datagrid-forms.md +1 -1
  181. package/docs/datagrid-grouping.md +1 -1
  182. package/docs/datagrid-layout.md +1 -1
  183. package/docs/datagrid-lookups.md +1 -1
  184. package/docs/datagrid-master-detail.md +1 -1
  185. package/docs/datagrid-scrolling.md +1 -1
  186. package/docs/datagrid-selection.md +1 -1
  187. package/docs/datagrid.md +1 -1
  188. package/docs/datalayer-api.md +491 -0
  189. package/docs/datalayer-changes.md +501 -0
  190. package/docs/datalayer-odata.md +998 -0
  191. package/docs/datalayer-pivot.md +850 -0
  192. package/docs/datalayer-queries.md +516 -0
  193. package/docs/datalayer-rest.md +529 -0
  194. package/docs/datalayer-soap.md +576 -0
  195. package/docs/datalayer-source.md +464 -0
  196. package/docs/datalayer.md +264 -0
  197. package/docs/datebox.md +1 -1
  198. package/docs/daterangebox.md +1 -1
  199. package/docs/diagram-api.md +200 -0
  200. package/docs/diagram-commands.md +79 -0
  201. package/docs/diagram-connections.md +157 -0
  202. package/docs/diagram-custom-nodes.md +325 -0
  203. package/docs/diagram-designer.md +816 -0
  204. package/docs/diagram-editing.md +62 -0
  205. package/docs/diagram-flow.md +157 -0
  206. package/docs/diagram-keyboard.md +58 -0
  207. package/docs/diagram-layout.md +354 -0
  208. package/docs/diagram-nodes.md +206 -0
  209. package/docs/diagram-tables.md +212 -0
  210. package/docs/diagram.md +217 -0
  211. package/docs/display.md +1 -1
  212. package/docs/draggable.md +1 -1
  213. package/docs/drawer.md +1 -1
  214. package/docs/dropdown.md +1 -1
  215. package/docs/editors.md +1 -1
  216. package/docs/expressioneditor.md +469 -0
  217. package/docs/expressions.md +431 -0
  218. package/docs/feedback.md +1 -1
  219. package/docs/fileuploader.md +1 -1
  220. package/docs/filterbuilder.md +1 -1
  221. package/docs/formlayout-schema.md +143 -0
  222. package/docs/formlayout.md +16 -4
  223. package/docs/foundations.md +1 -1
  224. package/docs/gallery.md +1 -1
  225. package/docs/gauge-base.md +1 -1
  226. package/docs/gauge-circular.md +1 -1
  227. package/docs/gauge-dashboards.md +1 -1
  228. package/docs/gauge-linear.md +1 -1
  229. package/docs/gauge-markers.md +1 -1
  230. package/docs/gauge-marks.md +1 -1
  231. package/docs/gauge-ranges.md +1 -1
  232. package/docs/gauge-scales.md +1 -1
  233. package/docs/gauge.md +1 -1
  234. package/docs/home.md +1 -1
  235. package/docs/keyboard.md +2 -2
  236. package/docs/language.md +1 -1
  237. package/docs/layout.md +1 -1
  238. package/docs/listbox.md +1 -1
  239. package/docs/loadpanel.md +1 -1
  240. package/docs/lookup.md +1 -1
  241. package/docs/markdown.md +1 -1
  242. package/docs/menus-api.md +1 -1
  243. package/docs/menus-context.md +1 -1
  244. package/docs/menus-customization.md +1 -1
  245. package/docs/menus-merging.md +1 -1
  246. package/docs/menus-programmatic.md +1 -1
  247. package/docs/menus.md +1 -1
  248. package/docs/multiview.md +1 -1
  249. package/docs/navigation.md +1 -1
  250. package/docs/numberbox.md +1 -1
  251. package/docs/otpinput.md +1 -1
  252. package/docs/pagination.md +1 -1
  253. package/docs/pivotgrid-api.md +1 -1
  254. package/docs/pivotgrid-chart.md +1 -1
  255. package/docs/pivotgrid-drilldown.md +1 -1
  256. package/docs/pivotgrid-export.md +1 -1
  257. package/docs/pivotgrid-fields.md +1 -1
  258. package/docs/pivotgrid-keyboard.md +1 -1
  259. package/docs/pivotgrid-layout.md +1 -1
  260. package/docs/pivotgrid-panel.md +1 -1
  261. package/docs/pivotgrid-remote.md +122 -44
  262. package/docs/pivotgrid-sorting.md +3 -3
  263. package/docs/pivotgrid-state.md +1 -1
  264. package/docs/pivotgrid-summaries.md +1 -1
  265. package/docs/pivotgrid.md +1 -1
  266. package/docs/popover.md +1 -1
  267. package/docs/progress.md +1 -1
  268. package/docs/qrcode.md +1 -1
  269. package/docs/radiogroup.md +1 -1
  270. package/docs/rating.md +1 -1
  271. package/docs/resizable.md +1 -1
  272. package/docs/ribbonmenu-api.md +1 -1
  273. package/docs/ribbonmenu-commands.md +1 -1
  274. package/docs/ribbonmenu-customization.md +1 -1
  275. package/docs/ribbonmenu-display.md +1 -1
  276. package/docs/ribbonmenu-layouts.md +1 -1
  277. package/docs/ribbonmenu-programmatic.md +1 -1
  278. package/docs/ribbonmenu.md +1 -1
  279. package/docs/scheduler-agenda.md +1 -1
  280. package/docs/scheduler-big-data.md +1 -1
  281. package/docs/scheduler-editing.md +1 -1
  282. package/docs/scheduler-form.md +1 -1
  283. package/docs/scheduler-icalendar.md +1 -1
  284. package/docs/scheduler-mobile.md +1 -1
  285. package/docs/scheduler-recurrence.md +1 -1
  286. package/docs/scheduler-resources.md +1 -1
  287. package/docs/scheduler-timeline.md +1 -1
  288. package/docs/scheduler.md +1 -1
  289. package/docs/scrollview.md +1 -1
  290. package/docs/shortcuteditor.md +1 -1
  291. package/docs/showcase-flowstudio.md +61 -0
  292. package/docs/showcase-home.md +1 -1
  293. package/docs/showcase-mail.md +1 -1
  294. package/docs/showcase.md +1 -1
  295. package/docs/signature.md +1 -1
  296. package/docs/skeleton.md +1 -1
  297. package/docs/slider.md +1 -1
  298. package/docs/sortable.md +1 -1
  299. package/docs/sparkline.md +1 -1
  300. package/docs/speeddial.md +1 -1
  301. package/docs/splitter.md +1 -1
  302. package/docs/stepper.md +1 -1
  303. package/docs/switch.md +1 -1
  304. package/docs/tabdocs-dock.md +1 -1
  305. package/docs/tabdocs-drag.md +1 -1
  306. package/docs/tabdocs-menus.md +1 -1
  307. package/docs/tabdocs-mobile.md +1 -1
  308. package/docs/tabdocs-tabs.md +1 -1
  309. package/docs/tabdocs-windows.md +1 -1
  310. package/docs/tabdocs-workspace.md +1 -1
  311. package/docs/tabdocs.md +1 -1
  312. package/docs/tabs.md +1 -1
  313. package/docs/tagbox.md +1 -1
  314. package/docs/textarea.md +1 -1
  315. package/docs/textbox.md +1 -1
  316. package/docs/tileview.md +1 -1
  317. package/docs/timeline.md +1 -1
  318. package/docs/toast.md +1 -1
  319. package/docs/tokens.md +324 -1
  320. package/docs/toolbar-api.md +1 -1
  321. package/docs/toolbar-customization.md +1 -1
  322. package/docs/toolbar.md +1 -1
  323. package/docs/tooltip.md +1 -1
  324. package/docs/treeview.md +1 -1
  325. package/docs/validationsummary.md +1 -1
  326. package/docs/window.md +1 -1
  327. package/docs/wizard.md +1 -1
  328. package/llms-full.txt +10142 -462
  329. package/llms.txt +32 -1
  330. package/package.json +2 -2
@@ -0,0 +1,62 @@
1
+ # Diagram: Moving and selecting
2
+
3
+ > Diagram · @motifx-community/ui 0.1.0-beta.16
4
+
5
+ The user moves, selects and deletes nodes and connections with the pointer and the keys, and the diagram writes every change to the app’s objects.
6
+
7
+ ## Moving, selecting and deleting
8
+
9
+ Drag a node to move it with the other selected nodes; its `x` and `y` are written, and its connections follow. `snapToGrid` snaps the nodes to the grid, and Escape puts them back. Click to select, and use Shift or Ctrl to add. Shift and a drag of the surface selects the nodes inside a rectangle. Delete removes the selection with the connections of its nodes, after `onDeleting`. `draggable`, `selectable`, `connectable` and `deletable` turn each of these off for the diagram or for a single node.
10
+
11
+ ```tsx
12
+ import { reactive } from '@motifx/core';
13
+ import { Button, Diagram, Stack, Switch, type DiagramEdge, type DiagramNode } from '@motifx-community/ui';
14
+
15
+ const NODES: DiagramNode[] = [
16
+ { id: 'start', x: 0, y: 100, text: 'Start' },
17
+ { id: 'review', x: 220, y: 20, text: 'Review the request' },
18
+ { id: 'approve', x: 220, y: 180, text: 'Approve' },
19
+ { id: 'archive', x: 480, y: 100, text: 'Archive (fixed in place)', draggable: false },
20
+ ];
21
+
22
+ const EDGES: DiagramEdge[] = [
23
+ { id: 'e1', source: 'start', target: 'review' },
24
+ { id: 'e2', source: 'review', target: 'approve' },
25
+ { id: 'e3', source: 'approve', target: 'archive' },
26
+ ];
27
+
28
+ /**
29
+ * Drag a node to move it, with the other selected nodes. Click to select, Shift or Ctrl to add, Shift and a drag of the
30
+ * surface to select inside a rectangle, Delete to delete. Ctrl and the arrows move the selection.
31
+ */
32
+ export default function Editing() {
33
+ const s = reactive({ snap: true, told: 'Nothing selected.' });
34
+ let diagram: Diagram | null = null;
35
+ return (
36
+ <Stack gap="md" style="inline-size: 100%">
37
+ <Stack orientation="horizontal" wrap align="center">
38
+ <Switch text="Snap to the grid" x-model={() => s.snap} />
39
+ <Button text="Select all" variant="outline" onclick={() => diagram?.selectAll()} />
40
+ <Button text="Delete the selection" variant="outline" onclick={() => diagram?.deleteSelection()} />
41
+ </Stack>
42
+ <Diagram
43
+ class="diagram-editing"
44
+ ref={(d: Diagram) => (diagram = d)}
45
+ label="Approval flow"
46
+ autoFit
47
+ nodes={NODES}
48
+ edges={EDGES}
49
+ edgePath="rounded-step"
50
+ snapToGrid={() => s.snap}
51
+ onSelectionChanged={(e) => (s.told = e.nodes.length || e.edges.length ? `Selected: ${[...e.nodes.map((n) => n.text), ...e.edges.map((edge) => edge.id)].join(', ')}.` : 'Nothing selected.')}
52
+ onNodesMoved={(e) => (s.told = `Moved ${e.moves.map((m) => `${m.node.text} to ${m.to.x}, ${m.to.y}`).join('; ')}.`)}
53
+ />
54
+ <output class="diagram-editing-told">{() => s.told}</output>
55
+ </Stack>
56
+ );
57
+ }
58
+ ```
59
+
60
+ ## Feedback
61
+
62
+ Loading issues…
@@ -0,0 +1,157 @@
1
+ # Diagram: Flow nodes
2
+
3
+ > Diagram · @motifx-community/ui 0.1.0-beta.16
4
+
5
+ The pieces of a flow designer: the card, a kind of node to start one’s own from, ports with labels, the status a run shows on each node, and the connections of a node and the nodes at their other ends, for an app that walks the flow.
6
+
7
+ ## A run through a flow
8
+
9
+ The steps are cards. Run walks the flow: each step is `running`, then `done`, and the next steps are the nodes its connections go to (`nodesOf`); a decision goes out by the port of its answer, and the way it does not take is `skipped`.
10
+
11
+ ```tsx
12
+ import { reactive } from '@motifx/core';
13
+ import { Button, Diagram, Stack, cardKind, type DiagramCardNode, type DiagramEdge, type DiagramNodeKind } from '@motifx-community/ui';
14
+
15
+ /** A glyph of the kit, drawn by the design language in use. */
16
+ const glyph = (name: string) => <span class="mx-glyph" data-icon={name} aria-hidden="true" />;
17
+
18
+ /** A run through a flow of cards: each step shows its status, and the next steps are the nodes its connections go to. */
19
+ export default function FlowRun() {
20
+ const s = reactive({ said: 'Run the flow to see each step take its status.', running: false, answer: 'yes' as 'yes' | 'no' });
21
+
22
+ // Kinds made from the card: the ports are labeled rows, and a decision goes out by the port of its answer.
23
+ const kinds: Record<string, DiagramNodeKind<DiagramCardNode>> = {
24
+ trigger: cardKind({ ports: [{ id: 'out', side: 'right', direction: 'source', label: 'Then' }] }),
25
+ action: cardKind({
26
+ ports: [
27
+ { id: 'in', side: 'left', direction: 'target' },
28
+ { id: 'out', side: 'right', direction: 'source' },
29
+ ],
30
+ }),
31
+ decision: cardKind({
32
+ ports: [
33
+ { id: 'in', side: 'left', direction: 'target' },
34
+ { id: 'yes', side: 'right', direction: 'source', label: 'Yes' },
35
+ { id: 'no', side: 'right', direction: 'source', label: 'No' },
36
+ ],
37
+ body: () => <em>{() => `Answers ${s.answer}`}</em>,
38
+ }),
39
+ };
40
+ const nodes: DiagramCardNode[] = [
41
+ { id: 'timer', x: 0, y: 60, kind: 'trigger', text: 'Every morning', subtitle: 'At 08:00', icon: glyph('clock') },
42
+ { id: 'query', x: 260, y: 60, kind: 'action', text: 'Read late orders', subtitle: 'Shop database', icon: glyph('table') },
43
+ { id: 'any', x: 520, y: 40, kind: 'decision', text: 'Any rows?', icon: glyph('split') },
44
+ { id: 'mail', x: 800, y: 0, kind: 'action', text: 'Send a reminder', subtitle: 'sales account', icon: glyph('send') },
45
+ { id: 'log', x: 800, y: 150, kind: 'action', text: 'Write to the log', icon: glyph('file') },
46
+ ];
47
+ const edges: DiagramEdge[] = [
48
+ { id: 'a', source: 'timer', sourcePort: 'out', target: 'query', targetPort: 'in' },
49
+ { id: 'b', source: 'query', sourcePort: 'out', target: 'any', targetPort: 'in' },
50
+ { id: 'c', source: 'any', sourcePort: 'yes', target: 'mail', targetPort: 'in' },
51
+ { id: 'd', source: 'any', sourcePort: 'no', target: 'log', targetPort: 'in' },
52
+ ];
53
+ let diagram!: Diagram<DiagramCardNode>;
54
+ const wait = (ms: number) => new Promise((done) => setTimeout(done, ms));
55
+
56
+ const run = async () => {
57
+ s.running = true;
58
+ for (const node of nodes) diagram.setNodeStatus(node.id, 'waiting');
59
+ let at: DiagramCardNode | undefined = nodes[0];
60
+ while (at) {
61
+ diagram.setNodeStatus(at.id, 'running');
62
+ s.said = `${at.text} is running.`;
63
+ await wait(700);
64
+ diagram.setNodeStatus(at.id, 'done', at.id === 'query' ? '3 rows' : undefined);
65
+ // A decision goes out by the port of its answer, and the ways it does not take are skipped.
66
+ const decision = at.kind === 'decision';
67
+ const next = diagram.nodesOf(at.id, { direction: 'out', port: decision ? s.answer : undefined });
68
+ if (decision) for (const other of diagram.nodesOf(at.id, { direction: 'out' })) if (!next.includes(other)) diagram.setNodeStatus(other.id, 'skipped');
69
+ at = next[0];
70
+ }
71
+ s.said = 'The run reached the end.';
72
+ s.running = false;
73
+ };
74
+
75
+ return (
76
+ <Stack gap="md" class="docs-wide">
77
+ <Stack orientation="horizontal" gap="sm" wrap align="center">
78
+ <Button text="Run" tone="accent" disabled={() => s.running} onclick={() => void run()} />
79
+ <Button text={() => `Answer ${s.answer === 'yes' ? 'no' : 'yes'}`} variant="outline" disabled={() => s.running} onclick={() => (s.answer = s.answer === 'yes' ? 'no' : 'yes')} />
80
+ <Button
81
+ text="Clear the statuses"
82
+ variant="outline"
83
+ disabled={() => s.running}
84
+ onclick={() => {
85
+ for (const node of nodes) diagram.setNodeStatus(node.id, null);
86
+ s.said = 'Run the flow to see each step take its status.';
87
+ }}
88
+ />
89
+ </Stack>
90
+ <Diagram ref={(d: Diagram<DiagramCardNode>) => (diagram = d)} label="Late orders" nodes={nodes} edges={edges} kinds={kinds} edgePath="curve" autoFit />
91
+ <output>{() => s.said}</output>
92
+ </Stack>
93
+ );
94
+ }
95
+ ```
96
+
97
+ ## The card
98
+
99
+ A node of the built-in `card` kind has a header with its `icon`, its `text` as the title and its `subtitle` under it. `cardKind(options)` makes a kind of one’s own from it: a body under the header, and the ports of the kind. A port on the left or the right with a `label` gets a row, the port beside it: the ways in on the left, the ways out on the right.
100
+
101
+ | Option | Description |
102
+ | --- | --- |
103
+ | `body(context)` | Makes the body under the header, once per node, as a kind’s `content` does; `context.host` is the body. |
104
+ | `update(context)` | Writes what changed in the body when the node is drawn again. |
105
+ | `icon(node), subtitle(node)` | Where the icon and the line under the title come from. Default: the node’s `icon` and `subtitle`. |
106
+ | `ports, cssClass, resizable, minWidth, minHeight` | As a kind’s own: the ports of a node that names none, more classes, and resizing. |
107
+
108
+ ```tsx
109
+ const kinds = {
110
+ decision: cardKind({
111
+ ports: [
112
+ { id: 'in', side: 'left', direction: 'target' },
113
+ { id: 'yes', side: 'right', direction: 'source', label: 'Yes' },
114
+ { id: 'no', side: 'right', direction: 'source', label: 'No' },
115
+ ],
116
+ body: (context) => <code>{context.node.condition}</code>,
117
+ }),
118
+ };
119
+ ```
120
+
121
+ On any other kind, a port’s `label` is its tip.
122
+
123
+ ## Status
124
+
125
+ A node’s `status` shows as a mark on its corner and a ring around it, in the colors of the design language; `statusText` says more, in the mark’s tip. `setNodeStatus` changes both, draws only that node and says it to a screen reader with the node’s name; a node read again with `refresh()` shows the status it carries.
126
+
127
+ | Status | Meaning |
128
+ | --- | --- |
129
+ | `running` | The step runs now. |
130
+ | `done` | It finished. |
131
+ | `error` | It failed; `statusText` says why. |
132
+ | `waiting` | It waits for something: its turn, an answer, a time. |
133
+ | `skipped` | The run did not take it. |
134
+
135
+ ## The connections of a node
136
+
137
+ `edgesOf` gives the connections of a node and `nodesOf` the nodes at their other ends, by `direction` and by `port`. Read in a getter, they follow the connections as they are drawn, moved and taken away, so a panel that shows what feeds a step stays true.
138
+
139
+ ```tsx
140
+ // The steps before this one, in a getter: they follow the connections.
141
+ const before = () => diagram.nodesOf(step.id, { direction: 'in' }).map((node) => node.text).join(', ');
142
+ // The way out of a decision for its answer.
143
+ const next = diagram.nodesOf('check', { direction: 'out', port: 'yes' });
144
+ ```
145
+
146
+ ## API reference
147
+
148
+ | Member | Returns | Description |
149
+ | --- | --- | --- |
150
+ | `setNodeStatus(id, status, text?)` | `boolean` | Shows what a node is doing; `null` takes the status away. A screen reader hears it with the node’s name. Not a step of the history. Returns whether it changed. |
151
+ | `edgesOf(id, options?)` | `DiagramEdge[]` | The connections of a node: `direction` `'in'`, `'out'` or `'both'`, and `port`, a port of the node. Followed in a getter. |
152
+ | `nodesOf(id, options?)` | `DiagramNode[]` | The nodes at the other ends of those connections, each once. Followed in a getter. |
153
+ | `cardKind(options?)` | `DiagramNodeKind` | A kind of node made from the card: a header with an icon, a title and a line under it, a body of its own, and a row for each labeled port. |
154
+
155
+ ## Feedback
156
+
157
+ Loading issues…
@@ -0,0 +1,58 @@
1
+ # Diagram: Keyboard and accessibility
2
+
3
+ > Diagram · @motifx-community/ui 0.1.0-beta.16
4
+
5
+ Everything can be done with the keys, and a screen reader hears the diagram, its nodes and what the user does.
6
+
7
+ ## Keyboard
8
+
9
+ | Key | Description |
10
+ | --- | --- |
11
+ | `Enter` | Puts the keys on the node nearest the middle of the view. On a node, starts a connection from it: the arrow keys choose the other node and bring it into view, Enter connects on the first ports that allow it, Escape cancels. On a connection chosen with `]` or `[`, takes its end at the other node: the arrow keys choose a node, Enter moves the end there, Escape cancels. |
12
+ | `Period, Comma` | Go through the points of the selected connection along its line, or the runs of a right-angled one. The point under the keys is ringed, and a screen reader hears its place among them. |
13
+ | `], [` | Go through the connections of the node under the keys, clockwise from the top. Each is selected, and a screen reader hears its label, its two nodes and its place among them; Delete deletes it. |
14
+ | `Arrow keys` | Move from node to node once a node is selected, to the nearest node within 45 degrees of the direction of the key, and pan the view otherwise. With Shift, the view pans four times further. |
15
+ | `Ctrl + arrow keys` | Move the selected nodes by one step of the grid, or the point under the keys; a run of a right-angled connection moves sideways. With Shift, by one unit. |
16
+ | `Alt + arrow keys` | Resize the node under the keys, if it can be resized, by one step of the grid. With Shift, by one unit. |
17
+ | `Ctrl + Z, Ctrl + Shift + Z, Ctrl + Y` | Undo and redo. |
18
+ | `Ctrl + C, Ctrl + X, Ctrl + V, Ctrl + D` | Copy, cut, paste and duplicate. |
19
+ | `Ctrl + A` | Selects every node and connection. |
20
+ | `Insert` | Adds a point to the selected connection halfway to the next one, after the point under the keys, and puts the keys on it. A right-angled connection takes no points of its own. |
21
+ | `Delete, Backspace` | Deletes the selection. On a point under the keys, removes the point; on a run of a right-angled connection, gives the line back to its own way. |
22
+ | `Escape` | Clears the selection, or cancels a drag and puts the nodes back. On a point under the keys, goes back to its connection. |
23
+ | `Plus, Minus` | Zoom in and out around the middle of the view. |
24
+ | `Space + drag` | Pans the view from anywhere, also over a node. |
25
+
26
+ ## Pointer and touch
27
+
28
+ | Gesture | Description |
29
+ | --- | --- |
30
+ | `Drag the surface` | Pans the view. |
31
+ | `Middle button + drag` | Pans the view from anywhere. |
32
+ | `Wheel` | Pans the view up and down; with Shift, across. A touchpad pans in both directions. |
33
+ | `Ctrl + wheel, pinch` | Zooms around the pointer. |
34
+ | `One finger, two fingers` | One finger pans. Two fingers zoom and pan together. |
35
+ | `Drag a node` | Moves it, with the other selected nodes. Near an edge of the surface the view pans. |
36
+ | `Click` | Selects a node or a connection. With Shift or Ctrl, adds it to the selection or removes it. A click on the empty surface clears the selection. |
37
+ | `Shift + drag the surface` | Selects the nodes inside the rectangle, in addition to the selection. |
38
+ | `Drag from a port` | Draws a connection. Every port it can end at is shown. It snaps to the nearest port within reach, or to the nearest port of the node under the pointer. Escape cancels it. |
39
+ | `Click or drag on a map` | Takes the view there, or moves it with the pointer. The wheel over the map zooms around the point under the pointer. |
40
+ | `Drag the handle of a selected connection` | Moves that end to another node or port. The other end stays where it is until the drop. A connection can also be taken near its end, outside the port. |
41
+
42
+ ## Accessibility
43
+
44
+ | Topic | Details |
45
+ | --- | --- |
46
+ | `Surface` | The diagram is a focusable group with the role description “diagram”, the name from `label`, and a description of its keys. |
47
+ | `Nodes` | Each node is a group with the role description “node” and the name of its text. The node the keys are on is the active descendant of the diagram, so a screen reader follows it, and the diagram says its name and its number of connections. |
48
+ | `Announcements` | A live region says what the user did: a connection made or moved, a line changed, a point added or removed, nodes moved, deleted or pasted, a step undone or redone. |
49
+ | `Without a pointer` | With the keys the user selects nodes and connections, moves nodes, connects them, moves the ends and the points of connections, deletes, and uses the clipboard and the history. |
50
+ | `Controls in nodes` | The keys typed in a text field inside a node belong to the field: undo, select all, the clipboard and deleting work on its text, and the commands of the diagram wait until focus leaves it. |
51
+ | `Large diagrams` | In the sketch of a far view, Enter and the arrow keys take the view to a node at its actual size, so the node under the keys is always on the page. |
52
+ | `Map` | A map is a focusable group with the role description “map”: the arrow keys pan the diagram and plus and minus zoom it, so the keys do on it all that the pointer does. |
53
+ | `Right to left` | A diagram is a drawing, so its coordinates do not change direction. The text inside nodes follows the direction of the page. |
54
+ | `Touch` | The surface takes every touch while it can be panned or zoomed. When neither is allowed, a finger scrolls the page over it. |
55
+
56
+ ## Feedback
57
+
58
+ Loading issues…
@@ -0,0 +1,354 @@
1
+ # Diagram: Layout, map and export
2
+
3
+ > Diagram · @motifx-community/ui 0.1.0-beta.16
4
+
5
+ Placing the nodes automatically, a map of the whole diagram, saving and loading, and images of the diagram.
6
+
7
+ ## Automatic layout
8
+
9
+ `layout(options)` places the nodes. `layered` puts them in layers that every connection crosses the same way, `down`, `right`, `up` or `left`: a connection that closes a cycle is turned round, the layers keep the connections as short as they can be, and the order in each layer crosses as few of them as it can. `tree` hangs each node under the first node that reaches it, each node over the middle of its children. `grid` puts them in rows, in the order of `nodes`.
10
+
11
+ The nodes keep the top left corner of the place they took; with `animate` they glide there, and `fit` brings them into view. A group takes the nodes in it along, and a node that may not be dragged stays where it is. A long connection of a layered layout passes each layer at a point of its own beside the nodes; a right-angled one finds its own way. The layout is one step of the history, cancelled by `onNodesMoving` and told by `onNodesMoved`. Called before the nodes are laid out, it waits for them. `autoLayout` lays nodes given without places out as `layoutOptions` say once they are first laid out, as a part of showing them: neither a step of the history nor told. The `layout` command makes the layout of `layoutOptions`.
12
+
13
+ ```tsx
14
+ import { reactive } from '@motifx/core';
15
+ import { Button, Diagram, Stack, type DiagramEdge, type DiagramLayoutOptions, type DiagramNode } from '@motifx-community/ui';
16
+
17
+ const LAYOUTS: { text: string; options: DiagramLayoutOptions }[] = [
18
+ { text: 'Layers down', options: { type: 'layered', direction: 'down' } },
19
+ { text: 'Layers right', options: { type: 'layered', direction: 'right' } },
20
+ { text: 'Layers up', options: { type: 'layered', direction: 'up' } },
21
+ { text: 'Layers left', options: { type: 'layered', direction: 'left' } },
22
+ { text: 'Tree', options: { type: 'tree', direction: 'down' } },
23
+ { text: 'Grid', options: { type: 'grid' } },
24
+ ];
25
+
26
+ /** A flow laid out by the diagram: in layers four ways, as a tree, or in rows. The nodes glide to their places. */
27
+ export default function Layout() {
28
+ const s = reactive({ said: 'Pick a layout. Undo puts the nodes back.' });
29
+ // The nodes come without places: the diagram lays them out once they are laid out (`autoLayout`).
30
+ const nodes: DiagramNode[] = [
31
+ ['received', 'Order received'],
32
+ ['stock', 'Check stock'],
33
+ ['charge', 'Charge card'],
34
+ ['supplier', 'Order from supplier'],
35
+ ['wait', 'Wait for delivery'],
36
+ ['pick', 'Pick items'],
37
+ ['notify', 'Tell the customer'],
38
+ ['invoice', 'Send invoice'],
39
+ ['pack', 'Pack'],
40
+ ['cancel', 'Cancel order'],
41
+ ['ship', 'Ship'],
42
+ ['delivered', 'Delivered'],
43
+ ].map(([id, text]) => ({ id, text, x: 0, y: 0 }));
44
+ const edge = (source: string, target: string, label?: string): DiagramEdge => ({ id: `${source}-${target}`, source, target, label });
45
+ const edges: DiagramEdge[] = [
46
+ edge('received', 'stock'),
47
+ edge('received', 'charge'),
48
+ edge('stock', 'pick', 'In stock'),
49
+ edge('stock', 'supplier', 'Out of stock'),
50
+ edge('supplier', 'wait'),
51
+ edge('wait', 'stock'),
52
+ edge('charge', 'pick'),
53
+ edge('charge', 'notify', 'Declined'),
54
+ edge('notify', 'cancel'),
55
+ edge('charge', 'invoice'),
56
+ edge('pick', 'pack'),
57
+ edge('pack', 'ship'),
58
+ edge('ship', 'delivered'),
59
+ edge('invoice', 'delivered'),
60
+ ];
61
+ let diagram!: Diagram;
62
+
63
+ return (
64
+ <Stack gap="md" class="docs-wide">
65
+ <Stack orientation="horizontal" gap="sm" wrap>
66
+ {LAYOUTS.map((layout) => (
67
+ <Button key={layout.text} text={layout.text} variant="outline" onclick={() => diagram.layout({ ...layout.options, animate: true, fit: true })} />
68
+ ))}
69
+ <Button text="Undo" variant="ghost" onclick={() => diagram.undo()} />
70
+ </Stack>
71
+ <Diagram
72
+ ref={(d: Diagram) => (diagram = d)}
73
+ label="Order handling"
74
+ nodes={nodes}
75
+ edges={edges}
76
+ autoLayout
77
+ autoFit
78
+ onNodesMoved={(e) => (s.said = `${e.moves.length} nodes moved.`)}
79
+ />
80
+ <output>{() => s.said}</output>
81
+ </Stack>
82
+ );
83
+ }
84
+ ```
85
+
86
+ Ports count: a connection that leaves a table by a lower row pulls the table it reaches lower, so the lines of a table diagram cross less.
87
+
88
+ ```tsx
89
+ import { Button, Diagram, Stack, type DiagramEdge, type DiagramTableColumn, type DiagramTableNode } from '@motifx-community/ui';
90
+
91
+ /** A database laid out from the left: a relation from a lower row pulls the table it reaches lower, so the lines cross less. */
92
+ export default function LayoutTables() {
93
+ const table = (id: string, columns: DiagramTableColumn[]): DiagramTableNode => ({ id, text: id, kind: 'table', x: 0, y: 0, columns });
94
+ const nodes: DiagramTableNode[] = [
95
+ table('order_items', [
96
+ { name: 'order_id', type: 'int', primaryKey: true, foreignKey: true },
97
+ { name: 'product_id', type: 'int', primaryKey: true, foreignKey: true },
98
+ { name: 'quantity', type: 'int' },
99
+ ]),
100
+ table('orders', [
101
+ { name: 'id', type: 'int', primaryKey: true },
102
+ { name: 'customer_id', type: 'int', foreignKey: true },
103
+ { name: 'address_id', type: 'int', foreignKey: true },
104
+ { name: 'created_at', type: 'timestamp' },
105
+ ]),
106
+ table('payments', [
107
+ { name: 'id', type: 'int', primaryKey: true },
108
+ { name: 'order_id', type: 'int', foreignKey: true },
109
+ { name: 'amount', type: 'decimal' },
110
+ ]),
111
+ table('products', [
112
+ { name: 'id', type: 'int', primaryKey: true },
113
+ { name: 'category_id', type: 'int', foreignKey: true },
114
+ { name: 'supplier_id', type: 'int', foreignKey: true },
115
+ { name: 'price', type: 'decimal' },
116
+ ]),
117
+ table('customers', [
118
+ { name: 'id', type: 'int', primaryKey: true },
119
+ { name: 'name', type: 'text' },
120
+ ]),
121
+ table('addresses', [
122
+ { name: 'id', type: 'int', primaryKey: true },
123
+ { name: 'customer_id', type: 'int', foreignKey: true },
124
+ { name: 'city', type: 'text' },
125
+ ]),
126
+ table('categories', [
127
+ { name: 'id', type: 'int', primaryKey: true },
128
+ { name: 'name', type: 'text' },
129
+ ]),
130
+ table('suppliers', [
131
+ { name: 'id', type: 'int', primaryKey: true },
132
+ { name: 'name', type: 'text' },
133
+ ]),
134
+ ];
135
+ const relation = (source: string, sourcePort: string, target: string): DiagramEdge => ({
136
+ id: `${source}.${sourcePort}`,
137
+ source,
138
+ sourcePort,
139
+ target,
140
+ targetPort: 'id',
141
+ sourceMarker: 'zero-or-many',
142
+ targetMarker: 'one',
143
+ });
144
+ const edges: DiagramEdge[] = [
145
+ relation('order_items', 'order_id', 'orders'),
146
+ relation('order_items', 'product_id', 'products'),
147
+ relation('orders', 'customer_id', 'customers'),
148
+ relation('orders', 'address_id', 'addresses'),
149
+ relation('payments', 'order_id', 'orders'),
150
+ relation('products', 'category_id', 'categories'),
151
+ relation('products', 'supplier_id', 'suppliers'),
152
+ relation('addresses', 'customer_id', 'customers'),
153
+ ];
154
+ let diagram!: Diagram;
155
+
156
+ return (
157
+ <Stack gap="md" class="docs-wide">
158
+ <Stack orientation="horizontal" gap="sm" wrap>
159
+ <Button text="From the left" variant="outline" onclick={() => diagram.layout({ direction: 'right', animate: true, fit: true })} />
160
+ <Button text="From the top" variant="outline" onclick={() => diagram.layout({ direction: 'down', animate: true, fit: true })} />
161
+ </Stack>
162
+ <Diagram
163
+ ref={(d: Diagram) => (diagram = d)}
164
+ label="Shop database"
165
+ nodes={nodes}
166
+ edges={edges}
167
+ edgePath="rounded-orthogonal"
168
+ autoLayout
169
+ layoutOptions={{ direction: 'right' }}
170
+ autoFit
171
+ />
172
+ </Stack>
173
+ );
174
+ }
175
+ ```
176
+
177
+ | Option | Type | Default | Description |
178
+ | --- | --- | --- | --- |
179
+ | `type` | `'layered' \| 'tree' \| 'grid'` | `'layered'` | Layers the connections run across, a tree, or rows. |
180
+ | `direction` | `'down' \| 'right' \| 'up' \| 'left'` | `'down'` | The way the connections of layers and of a tree run. |
181
+ | `nodeGap, layerGap` | `number` | `40`, `80` | The room between two nodes side by side, and between two layers or two levels of a tree, in diagram units. A grid takes `nodeGap` both ways. |
182
+ | `columns` | `number` | About as wide as high | The nodes in a row of a grid. |
183
+ | `nodes` | `readonly string[]` | Every node in no group | The nodes to place; a group takes the nodes in it along. |
184
+ | `animate` | `boolean` | `false` | The nodes glide to their places with the motion of the design language. |
185
+ | `fit` | `boolean` | `false` | Fits the nodes into view once they are placed. |
186
+
187
+ ## Map
188
+
189
+ `miniMap` shows a map of the whole diagram in a corner of it: `true`, or the options below. The map shows the nodes, the part in view outlined and the rest dimmed. A click glides the view there, a drag moves it, and the wheel zooms around the point under the pointer; with the keys, the arrows pan and plus and minus zoom. It has no buttons: the app’s own buttons run the diagram’s `zoomIn`, `zoomOut` and `zoomToFit` commands.
190
+
191
+ ```tsx
192
+ import { reactive } from '@motifx/core';
193
+ import { Button, Diagram, Stack, type DiagramEdge, type DiagramMiniMapPosition, type DiagramNode } from '@motifx-community/ui';
194
+
195
+ const CORNERS: DiagramMiniMapPosition[] = ['bottom-end', 'bottom-start', 'top-start', 'top-end'];
196
+
197
+ /** A large diagram with its map in a corner: a click on the map takes the view there, a drag moves it, the wheel zooms. */
198
+ export default function MapCorner() {
199
+ const s = reactive({ corner: CORNERS[0], shown: true });
200
+ // A process of 64 steps: each step leads on to one or two, and now and then back to an earlier one.
201
+ const nodes: DiagramNode[] = Array.from({ length: 64 }, (_, k) => ({ id: `s${k}`, text: `Step ${k + 1}`, x: 0, y: 0 }));
202
+ const edges: DiagramEdge[] = [];
203
+ for (let k = 1; k < nodes.length; k++) {
204
+ edges.push({ id: `e${k}`, source: `s${Math.floor((k - 1) / 2)}`, target: `s${k}` });
205
+ if (k % 9 === 0) edges.push({ id: `back${k}`, source: `s${k}`, target: `s${k - 5}`, dashed: true });
206
+ }
207
+ let diagram!: Diagram;
208
+ let started = false;
209
+
210
+ return (
211
+ <Stack gap="md" class="docs-wide">
212
+ <Stack orientation="horizontal" gap="sm" wrap align="center">
213
+ <Button text="Zoom in" variant="outline" onclick={() => diagram.zoomIn({ animate: true })} />
214
+ <Button text="Zoom out" variant="outline" onclick={() => diagram.zoomOut({ animate: true })} />
215
+ <Button text="Fit" variant="outline" onclick={() => diagram.fit({ animate: true })} />
216
+ <Button text="Next corner" variant="outline" onclick={() => (s.corner = CORNERS[(CORNERS.indexOf(s.corner) + 1) % CORNERS.length])} />
217
+ <Button text="Show or hide the map" variant="outline" onclick={() => (s.shown = !s.shown)} />
218
+ <output>{() => `miniMap: { visible: ${s.shown}, position: '${s.corner}' }`}</output>
219
+ </Stack>
220
+ <Diagram
221
+ ref={(d: Diagram) => (diagram = d)}
222
+ label="Process"
223
+ nodes={nodes}
224
+ edges={edges}
225
+ edgePath="rounded-step"
226
+ autoLayout
227
+ layoutOptions={{ direction: 'right' }}
228
+ miniMap={() => ({ visible: s.shown, position: s.corner })}
229
+ // Once the steps are laid out, the view starts at the first one.
230
+ onContentChanged={() => {
231
+ if (started || diagram.drawnNodes().length < nodes.length) return;
232
+ started = true;
233
+ diagram.centerOn('s0');
234
+ }}
235
+ />
236
+ </Stack>
237
+ );
238
+ }
239
+ ```
240
+
241
+ | Option | Type | Default | Description |
242
+ | --- | --- | --- | --- |
243
+ | `visible` | `boolean` | `true` | Shows the map. |
244
+ | `position` | `'top-start' \| 'top-end' \| 'bottom-start' \| 'bottom-end'` | `'bottom-end'` | The corner it stands in; `start` and `end` follow the direction of the page. |
245
+ | `width, height` | `number` | The design language’s | Its size in pixels. |
246
+ | `label` | `string` | The kit string “Diagram map” | Its accessible name. |
247
+
248
+ `DiagramMap` is the same map as a component of its own, for a place outside the diagram, such as a side panel: give it the diagram in `diagram`, and it follows the nodes, the view and the selection.
249
+
250
+ | Prop | Type | Default | Description |
251
+ | --- | --- | --- | --- |
252
+ | `diagram` | `Bind<Diagram \| null>` | `null` | The diagram the map shows and moves the view of. |
253
+ | `label` | `Bind<string>` | The kit string “Diagram map” | The accessible name of the map. |
254
+
255
+ ## Saving and loading as JSON
256
+
257
+ `save()` gives copies of the nodes, the connections and the view as plain data, which `JSON.stringify` writes as a JSON text to keep in a file, in storage or on a server. `load(data)` shows such data again, or its JSON text: copies of its nodes and connections fill the same arrays, the view moves to the one saved (the nodes are fitted into view when none was), and the selection and the history are cleared. Data that cannot be read is reported and changes nothing.
258
+
259
+ ```tsx
260
+ import { reactive } from '@motifx/core';
261
+ import { Button, Diagram, Stack, type DiagramEdge, type DiagramNode } from '@motifx-community/ui';
262
+
263
+ /** The diagram saved as JSON and loaded back. */
264
+ export default function SaveLoad() {
265
+ const s = reactive({ saved: '' });
266
+ const nodes: DiagramNode[] = [
267
+ { id: 'new', x: 0, y: 60, text: 'New ticket' },
268
+ { id: 'triage', x: 200, y: 60, text: 'Triage' },
269
+ { id: 'work', x: 400, y: 0, text: 'In progress' },
270
+ { id: 'wait', x: 400, y: 130, text: 'Waiting for reply' },
271
+ { id: 'done', x: 620, y: 60, text: 'Resolved' },
272
+ ];
273
+ const edges: DiagramEdge[] = [
274
+ { id: 'a', source: 'new', target: 'triage' },
275
+ { id: 'b', source: 'triage', target: 'work', label: 'Clear' },
276
+ { id: 'c', source: 'triage', target: 'wait', label: 'Needs more', dashed: true },
277
+ { id: 'd', source: 'wait', target: 'work' },
278
+ { id: 'e', source: 'work', target: 'done' },
279
+ ];
280
+ let diagram!: Diagram;
281
+
282
+ return (
283
+ <Stack gap="md" class="docs-wide">
284
+ <Stack orientation="horizontal" gap="sm" wrap>
285
+ <Button text="Save" variant="outline" onclick={() => (s.saved = JSON.stringify(diagram.save(), null, 2))} />
286
+ <Button text="Load what was saved" variant="outline" disabled={() => !s.saved} onclick={() => diagram.load(s.saved)} />
287
+ </Stack>
288
+ <Diagram ref={(d: Diagram) => (diagram = d)} label="Ticket flow" nodes={nodes} edges={edges} autoFit />
289
+ <p x-wait={() => !s.saved}>Move or delete some nodes, then load what was saved.</p>
290
+ <pre x-wait={() => !s.saved} style={{ maxHeight: '220px', overflow: 'auto' }}>
291
+ {() => s.saved}
292
+ </pre>
293
+ </Stack>
294
+ );
295
+ }
296
+ ```
297
+
298
+ ## Images
299
+
300
+ `toSVG()` gives the diagram as an SVG document that stands alone, and `toDataURL()` and `toBlob()` give it as a PNG. The image is made of shapes and texts: the lines and their marks, the boxes, borders and texts of the nodes and labels in the colors of the design language, glyphs and pictures; not the selection, the ports or the handles. Shadows and gradients are not drawn, and a PNG has only the fonts installed on the system: a font the page loads from the web is replaced by one of them, kept as wide as on the page.
301
+
302
+ ```tsx
303
+ import { reactive } from '@motifx/core';
304
+ import { Button, Diagram, Stack, type DiagramEdge, type DiagramNode } from '@motifx-community/ui';
305
+
306
+ /** The diagram drawn as an SVG document and as a PNG. */
307
+ export default function Images() {
308
+ const s = reactive({ svg: '', png: '' });
309
+ const nodes: DiagramNode[] = [
310
+ { id: 'new', x: 0, y: 60, text: 'New ticket' },
311
+ { id: 'triage', x: 200, y: 60, text: 'Triage' },
312
+ { id: 'work', x: 400, y: 0, text: 'In progress' },
313
+ { id: 'wait', x: 400, y: 130, text: 'Waiting for reply' },
314
+ { id: 'done', x: 620, y: 60, text: 'Resolved' },
315
+ ];
316
+ const edges: DiagramEdge[] = [
317
+ { id: 'a', source: 'new', target: 'triage' },
318
+ { id: 'b', source: 'triage', target: 'work', label: 'Clear' },
319
+ { id: 'c', source: 'triage', target: 'wait', label: 'Needs more', dashed: true },
320
+ { id: 'd', source: 'wait', target: 'work' },
321
+ { id: 'e', source: 'work', target: 'done' },
322
+ ];
323
+ let diagram!: Diagram;
324
+
325
+ return (
326
+ <Stack gap="md" class="docs-wide">
327
+ <Stack orientation="horizontal" gap="sm" wrap>
328
+ <Button text="Make an SVG" variant="outline" onclick={() => (s.svg = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(diagram.toSVG())}`)} />
329
+ <Button text="Make a PNG" variant="outline" onclick={() => diagram.toDataURL().then((url) => (s.png = url))} />
330
+ </Stack>
331
+ <Diagram ref={(d: Diagram) => (diagram = d)} label="Ticket flow to draw" nodes={nodes} edges={edges} autoFit />
332
+ <Stack x-wait={() => !s.svg && !s.png} orientation="horizontal" gap="md" wrap>
333
+ <a x-wait={() => !s.svg} href={() => s.svg} download="ticket-flow.svg">
334
+ <img alt="The diagram as an SVG document" src={() => s.svg} style={{ maxWidth: '360px' }} />
335
+ </a>
336
+ <a x-wait={() => !s.png} href={() => s.png} download="ticket-flow.png">
337
+ <img alt="The diagram as a PNG" src={() => s.png} style={{ maxWidth: '360px' }} />
338
+ </a>
339
+ </Stack>
340
+ </Stack>
341
+ );
342
+ }
343
+ ```
344
+
345
+ | Option | Type | Default | Description |
346
+ | --- | --- | --- | --- |
347
+ | `nodes` | `readonly string[]` | Every node | The nodes to draw, with the connections between them. |
348
+ | `padding` | `number` | `16` | The room around the drawing, in diagram units. |
349
+ | `background` | `string` | The color behind the diagram | The background, or `'transparent'` for none. |
350
+ | `scale` | `number` | `2` | The pixels of a PNG for a unit of the diagram. A drawing too large for the browser to hold as one image is drawn at a smaller scale. |
351
+
352
+ ## Feedback
353
+
354
+ Loading issues…