@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.
- package/CHANGELOG.md +113 -0
- package/README.md +2 -2
- package/dist/components/diagram/Diagram.d.ts +607 -0
- package/dist/components/diagram/DiagramAutoPan.d.ts +17 -0
- package/dist/components/diagram/DiagramBends.d.ts +70 -0
- package/dist/components/diagram/DiagramDragging.d.ts +66 -0
- package/dist/components/diagram/DiagramEdgeView.d.ts +78 -0
- package/dist/components/diagram/DiagramGrid.d.ts +13 -0
- package/dist/components/diagram/DiagramHistory.d.ts +16 -0
- package/dist/components/diagram/DiagramLinks.d.ts +177 -0
- package/dist/components/diagram/DiagramMap.d.ts +62 -0
- package/dist/components/diagram/DiagramNodeView.d.ts +143 -0
- package/dist/components/diagram/DiagramOverview.d.ts +20 -0
- package/dist/components/diagram/DiagramPanning.d.ts +34 -0
- package/dist/components/diagram/diagram-alignment.d.ts +2 -0
- package/dist/components/diagram/diagram-auto-pan-host.d.ts +8 -0
- package/dist/components/diagram/diagram-background.d.ts +2 -0
- package/dist/components/diagram/diagram-bends-host.d.ts +17 -0
- package/dist/components/diagram/diagram-card-kind.d.ts +42 -0
- package/dist/components/diagram/diagram-card-node.d.ts +11 -0
- package/dist/components/diagram/diagram-center-options.d.ts +6 -0
- package/dist/components/diagram/diagram-change.d.ts +11 -0
- package/dist/components/diagram/diagram-class-member.d.ts +13 -0
- package/dist/components/diagram/diagram-class-node.d.ts +12 -0
- package/dist/components/diagram/diagram-column-checked-event-args.d.ts +9 -0
- package/dist/components/diagram/diagram-connected-event-args.d.ts +6 -0
- package/dist/components/diagram/diagram-connecting-event-args.d.ts +9 -0
- package/dist/components/diagram/diagram-connection.d.ts +7 -0
- package/dist/components/diagram/diagram-data.d.ts +12 -0
- package/dist/components/diagram/diagram-deleted-event-args.d.ts +8 -0
- package/dist/components/diagram/diagram-deleting-event-args.d.ts +9 -0
- package/dist/components/diagram/diagram-dragging-host.d.ts +47 -0
- package/dist/components/diagram/diagram-drawn-node.d.ts +10 -0
- package/dist/components/diagram/diagram-edge-end.d.ts +2 -0
- package/dist/components/diagram/diagram-edge-path.d.ts +5 -0
- package/dist/components/diagram/diagram-edge-reshaped-event-args.d.ts +8 -0
- package/dist/components/diagram/diagram-edge-reshaping-event-args.d.ts +6 -0
- package/dist/components/diagram/diagram-edge.d.ts +49 -0
- package/dist/components/diagram/diagram-edit.d.ts +10 -0
- package/dist/components/diagram/diagram-export-options.d.ts +14 -0
- package/dist/components/diagram/diagram-export.d.ts +28 -0
- package/dist/components/diagram/diagram-fit-options.d.ts +12 -0
- package/dist/components/diagram/diagram-history-changed-event-args.d.ts +14 -0
- package/dist/components/diagram/diagram-history-step.d.ts +9 -0
- package/dist/components/diagram/diagram-kinds.d.ts +9 -0
- package/dist/components/diagram/diagram-layered.d.ts +39 -0
- package/dist/components/diagram/diagram-layout-direction.d.ts +2 -0
- package/dist/components/diagram/diagram-layout-options.d.ts +24 -0
- package/dist/components/diagram/diagram-layout-type.d.ts +5 -0
- package/dist/components/diagram/diagram-layout.d.ts +33 -0
- package/dist/components/diagram/diagram-line-look.d.ts +6 -0
- package/dist/components/diagram/diagram-line.d.ts +11 -0
- package/dist/components/diagram/diagram-links-host.d.ts +45 -0
- package/dist/components/diagram/diagram-links-options.d.ts +7 -0
- package/dist/components/diagram/diagram-map-props.d.ts +10 -0
- package/dist/components/diagram/diagram-map-target.d.ts +27 -0
- package/dist/components/diagram/diagram-marker.d.ts +6 -0
- package/dist/components/diagram/diagram-mini-map-options.d.ts +13 -0
- package/dist/components/diagram/diagram-mini-map-position.d.ts +2 -0
- package/dist/components/diagram/diagram-node-context.d.ts +26 -0
- package/dist/components/diagram/diagram-node-host.d.ts +23 -0
- package/dist/components/diagram/diagram-node-kind.d.ts +43 -0
- package/dist/components/diagram/diagram-node-move.d.ts +11 -0
- package/dist/components/diagram/diagram-node-resized-event-args.d.ts +8 -0
- package/dist/components/diagram/diagram-node-resizing-event-args.d.ts +6 -0
- package/dist/components/diagram/diagram-node-size.d.ts +8 -0
- package/dist/components/diagram/diagram-node-status.d.ts +2 -0
- package/dist/components/diagram/diagram-node-toggled-event-args.d.ts +7 -0
- package/dist/components/diagram/diagram-node.d.ts +56 -0
- package/dist/components/diagram/diagram-nodes-moved-event-args.d.ts +6 -0
- package/dist/components/diagram/diagram-nodes-moving-event-args.d.ts +6 -0
- package/dist/components/diagram/diagram-panning-host.d.ts +19 -0
- package/dist/components/diagram/diagram-pasted-event-args.d.ts +7 -0
- package/dist/components/diagram/diagram-pasting-event-args.d.ts +11 -0
- package/dist/components/diagram/diagram-path-ends.d.ts +11 -0
- package/dist/components/diagram/diagram-path-result.d.ts +6 -0
- package/dist/components/diagram/diagram-paths.d.ts +35 -0
- package/dist/components/diagram/diagram-point.d.ts +5 -0
- package/dist/components/diagram/diagram-port-place.d.ts +9 -0
- package/dist/components/diagram/diagram-port.d.ts +27 -0
- package/dist/components/diagram/diagram-props.d.ts +159 -0
- package/dist/components/diagram/diagram-reconnected-event-args.d.ts +10 -0
- package/dist/components/diagram/diagram-reconnecting-event-args.d.ts +11 -0
- package/dist/components/diagram/diagram-rect.d.ts +7 -0
- package/dist/components/diagram/diagram-resize-side.d.ts +2 -0
- package/dist/components/diagram/diagram-route.d.ts +10 -0
- package/dist/components/diagram/diagram-selection-changed-event-args.d.ts +9 -0
- package/dist/components/diagram/diagram-selection.d.ts +5 -0
- package/dist/components/diagram/diagram-side.d.ts +2 -0
- package/dist/components/diagram/diagram-table-column.d.ts +13 -0
- package/dist/components/diagram/diagram-table-node.d.ts +12 -0
- package/dist/components/diagram/diagram-tree.d.ts +14 -0
- package/dist/components/diagram/diagram-viewport-changed-event-args.d.ts +8 -0
- package/dist/components/diagram/diagram-viewport-options.d.ts +5 -0
- package/dist/components/diagram/diagram-viewport.d.ts +6 -0
- package/dist/components/diagram/index.d.ts +65 -0
- package/dist/components/diagram/swallow-next-click.d.ts +5 -0
- package/dist/components/expressioneditor/ExpressionEditor.d.ts +111 -0
- package/dist/components/expressioneditor/expression-editor-props.d.ts +24 -0
- package/dist/components/expressioneditor/index.d.ts +2 -0
- package/dist/components/formlayout/FormLayout.d.ts +10 -3
- package/dist/components/formlayout/form-editor-type.d.ts +1 -1
- package/dist/components/formlayout/form-item.d.ts +4 -1
- package/dist/components/formlayout/form-layout-props.d.ts +1 -1
- package/dist/components/formlayout/index.d.ts +1 -0
- package/dist/components/formlayout/schema-items.d.ts +26 -0
- package/dist/components/pivotgrid/model/PivotAxisWindow.d.ts +53 -1
- package/dist/components/pivotgrid/model/PivotCellWindow.d.ts +2 -0
- package/dist/components/pivotgrid/model/PivotWindows.d.ts +3 -6
- package/dist/components/toolbar/Toolbar.d.ts +5 -3
- package/dist/core/control.d.ts +2 -0
- package/dist/core/keyboard.d.ts +5 -0
- package/dist/core/measure/index.d.ts +2 -0
- package/dist/core/measure/picture.d.ts +27 -0
- package/dist/core/shortcut-options.d.ts +5 -2
- package/dist/core/ui-strings.d.ts +191 -0
- package/dist/generated/tokens.d.ts +1615 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +11501 -705
- package/dist/index.js.map +1 -1
- package/dist/locales/en.json +180 -1
- package/dist/locales/tr.json +180 -1
- package/dist/styles.css +2262 -3
- package/dist/tokens/index.d.ts +1615 -0
- package/dist/tokens/index.js +1615 -0
- package/dist/tokens/index.js.map +1 -1
- package/dist/{tr-BGbF9uCs.js → tr-4GNbFdQh.js} +361 -3
- package/dist/{tr-BGbF9uCs.js.map → tr-4GNbFdQh.js.map} +1 -1
- package/docs/accordion.md +1 -1
- package/docs/actionsheet.md +1 -1
- package/docs/appbar.md +1 -1
- package/docs/appmenu-api.md +1 -1
- package/docs/appmenu-programmatic.md +1 -1
- package/docs/appmenu-search.md +1 -1
- package/docs/appmenu.md +1 -1
- package/docs/avatar.md +1 -1
- package/docs/badge.md +1 -1
- package/docs/bar-gauge-angles.md +1 -1
- package/docs/bar-gauge-data.md +1 -1
- package/docs/bar-gauge-labels.md +1 -1
- package/docs/bar-gauge.md +1 -1
- package/docs/barcode.md +1 -1
- package/docs/bottomnavigation.md +1 -1
- package/docs/bottomsheet.md +1 -1
- package/docs/breadcrumb.md +1 -1
- package/docs/button.md +1 -1
- package/docs/buttongroup.md +1 -1
- package/docs/buttons.md +1 -1
- package/docs/calendar.md +1 -1
- package/docs/card.md +1 -1
- package/docs/chart-bars.md +1 -1
- package/docs/chart-candles.md +1 -1
- package/docs/chart-funnel.md +1 -1
- package/docs/chart-heatmap.md +1 -1
- package/docs/chart-lines.md +1 -1
- package/docs/chart-live.md +1 -1
- package/docs/chart-pie.md +1 -1
- package/docs/chart-radar.md +1 -1
- package/docs/chart-ranges.md +1 -1
- package/docs/chart-references.md +1 -1
- package/docs/chart-scatter.md +1 -1
- package/docs/chart-waterfall.md +1 -1
- package/docs/chart-zoom.md +1 -1
- package/docs/chart.md +1 -1
- package/docs/chat.md +1 -1
- package/docs/checkbox.md +1 -1
- package/docs/chip.md +1 -1
- package/docs/choice.md +1 -1
- package/docs/colorbox.md +1 -1
- package/docs/combobox.md +1 -1
- package/docs/commands.md +1 -1
- package/docs/control.md +1 -1
- package/docs/data.md +2 -2
- package/docs/datagrid-api.md +1 -1
- package/docs/datagrid-bands.md +1 -1
- package/docs/datagrid-drag-select.md +1 -1
- package/docs/datagrid-drag.md +1 -1
- package/docs/datagrid-editing.md +1 -1
- package/docs/datagrid-filtering.md +1 -1
- package/docs/datagrid-forms.md +1 -1
- package/docs/datagrid-grouping.md +1 -1
- package/docs/datagrid-layout.md +1 -1
- package/docs/datagrid-lookups.md +1 -1
- package/docs/datagrid-master-detail.md +1 -1
- package/docs/datagrid-scrolling.md +1 -1
- package/docs/datagrid-selection.md +1 -1
- package/docs/datagrid.md +1 -1
- package/docs/datalayer-api.md +491 -0
- package/docs/datalayer-changes.md +501 -0
- package/docs/datalayer-odata.md +998 -0
- package/docs/datalayer-pivot.md +850 -0
- package/docs/datalayer-queries.md +516 -0
- package/docs/datalayer-rest.md +529 -0
- package/docs/datalayer-soap.md +576 -0
- package/docs/datalayer-source.md +464 -0
- package/docs/datalayer.md +264 -0
- package/docs/datebox.md +1 -1
- package/docs/daterangebox.md +1 -1
- package/docs/diagram-api.md +200 -0
- package/docs/diagram-commands.md +79 -0
- package/docs/diagram-connections.md +157 -0
- package/docs/diagram-custom-nodes.md +325 -0
- package/docs/diagram-designer.md +816 -0
- package/docs/diagram-editing.md +62 -0
- package/docs/diagram-flow.md +157 -0
- package/docs/diagram-keyboard.md +58 -0
- package/docs/diagram-layout.md +354 -0
- package/docs/diagram-nodes.md +206 -0
- package/docs/diagram-tables.md +212 -0
- package/docs/diagram.md +217 -0
- package/docs/display.md +1 -1
- package/docs/draggable.md +1 -1
- package/docs/drawer.md +1 -1
- package/docs/dropdown.md +1 -1
- package/docs/editors.md +1 -1
- package/docs/expressioneditor.md +469 -0
- package/docs/expressions.md +431 -0
- package/docs/feedback.md +1 -1
- package/docs/fileuploader.md +1 -1
- package/docs/filterbuilder.md +1 -1
- package/docs/formlayout-schema.md +143 -0
- package/docs/formlayout.md +16 -4
- package/docs/foundations.md +1 -1
- package/docs/gallery.md +1 -1
- package/docs/gauge-base.md +1 -1
- package/docs/gauge-circular.md +1 -1
- package/docs/gauge-dashboards.md +1 -1
- package/docs/gauge-linear.md +1 -1
- package/docs/gauge-markers.md +1 -1
- package/docs/gauge-marks.md +1 -1
- package/docs/gauge-ranges.md +1 -1
- package/docs/gauge-scales.md +1 -1
- package/docs/gauge.md +1 -1
- package/docs/home.md +1 -1
- package/docs/keyboard.md +2 -2
- package/docs/language.md +1 -1
- package/docs/layout.md +1 -1
- package/docs/listbox.md +1 -1
- package/docs/loadpanel.md +1 -1
- package/docs/lookup.md +1 -1
- package/docs/markdown.md +1 -1
- package/docs/menus-api.md +1 -1
- package/docs/menus-context.md +1 -1
- package/docs/menus-customization.md +1 -1
- package/docs/menus-merging.md +1 -1
- package/docs/menus-programmatic.md +1 -1
- package/docs/menus.md +1 -1
- package/docs/multiview.md +1 -1
- package/docs/navigation.md +1 -1
- package/docs/numberbox.md +1 -1
- package/docs/otpinput.md +1 -1
- package/docs/pagination.md +1 -1
- package/docs/pivotgrid-api.md +1 -1
- package/docs/pivotgrid-chart.md +1 -1
- package/docs/pivotgrid-drilldown.md +1 -1
- package/docs/pivotgrid-export.md +1 -1
- package/docs/pivotgrid-fields.md +1 -1
- package/docs/pivotgrid-keyboard.md +1 -1
- package/docs/pivotgrid-layout.md +1 -1
- package/docs/pivotgrid-panel.md +1 -1
- package/docs/pivotgrid-remote.md +122 -44
- package/docs/pivotgrid-sorting.md +3 -3
- package/docs/pivotgrid-state.md +1 -1
- package/docs/pivotgrid-summaries.md +1 -1
- package/docs/pivotgrid.md +1 -1
- package/docs/popover.md +1 -1
- package/docs/progress.md +1 -1
- package/docs/qrcode.md +1 -1
- package/docs/radiogroup.md +1 -1
- package/docs/rating.md +1 -1
- package/docs/resizable.md +1 -1
- package/docs/ribbonmenu-api.md +1 -1
- package/docs/ribbonmenu-commands.md +1 -1
- package/docs/ribbonmenu-customization.md +1 -1
- package/docs/ribbonmenu-display.md +1 -1
- package/docs/ribbonmenu-layouts.md +1 -1
- package/docs/ribbonmenu-programmatic.md +1 -1
- package/docs/ribbonmenu.md +1 -1
- package/docs/scheduler-agenda.md +1 -1
- package/docs/scheduler-big-data.md +1 -1
- package/docs/scheduler-editing.md +1 -1
- package/docs/scheduler-form.md +1 -1
- package/docs/scheduler-icalendar.md +1 -1
- package/docs/scheduler-mobile.md +1 -1
- package/docs/scheduler-recurrence.md +1 -1
- package/docs/scheduler-resources.md +1 -1
- package/docs/scheduler-timeline.md +1 -1
- package/docs/scheduler.md +1 -1
- package/docs/scrollview.md +1 -1
- package/docs/shortcuteditor.md +1 -1
- package/docs/showcase-flowstudio.md +61 -0
- package/docs/showcase-home.md +1 -1
- package/docs/showcase-mail.md +1 -1
- package/docs/showcase.md +1 -1
- package/docs/signature.md +1 -1
- package/docs/skeleton.md +1 -1
- package/docs/slider.md +1 -1
- package/docs/sortable.md +1 -1
- package/docs/sparkline.md +1 -1
- package/docs/speeddial.md +1 -1
- package/docs/splitter.md +1 -1
- package/docs/stepper.md +1 -1
- package/docs/switch.md +1 -1
- package/docs/tabdocs-dock.md +1 -1
- package/docs/tabdocs-drag.md +1 -1
- package/docs/tabdocs-menus.md +1 -1
- package/docs/tabdocs-mobile.md +1 -1
- package/docs/tabdocs-tabs.md +1 -1
- package/docs/tabdocs-windows.md +1 -1
- package/docs/tabdocs-workspace.md +1 -1
- package/docs/tabdocs.md +1 -1
- package/docs/tabs.md +1 -1
- package/docs/tagbox.md +1 -1
- package/docs/textarea.md +1 -1
- package/docs/textbox.md +1 -1
- package/docs/tileview.md +1 -1
- package/docs/timeline.md +1 -1
- package/docs/toast.md +1 -1
- package/docs/tokens.md +324 -1
- package/docs/toolbar-api.md +1 -1
- package/docs/toolbar-customization.md +1 -1
- package/docs/toolbar.md +1 -1
- package/docs/tooltip.md +1 -1
- package/docs/treeview.md +1 -1
- package/docs/validationsummary.md +1 -1
- package/docs/window.md +1 -1
- package/docs/wizard.md +1 -1
- package/llms-full.txt +10142 -462
- package/llms.txt +32 -1
- package/package.json +2 -2
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
# Diagram: Nodes and styles
|
|
2
|
+
|
|
3
|
+
> Diagram · @motifx-community/ui 0.1.0-beta.16
|
|
4
|
+
|
|
5
|
+
What a node holds and how it looks: kinds of node of the app’s own with any control of the kit inside, groups, lanes and notes, resizing, and the app’s own classes and styles on top of the design tokens.
|
|
6
|
+
|
|
7
|
+
## Node kinds and controls
|
|
8
|
+
|
|
9
|
+
A node names its kind in `kind`, and `kinds` gives each kind its content: any control of the kit, made with JSX or in code, once per node. `update` writes what changed when the node is drawn again, after `refresh()`, an undo or a resize; content bound to reactive fields of the app needs none. A kind also gives the ports, classes, size limits and resizing of its nodes. [Custom nodes](diagram-custom-nodes.md) builds kinds step by step.
|
|
10
|
+
|
|
11
|
+
A press on a control inside a node belongs to the control, so the node does not move while the user types, clicks or flips a switch. `context.dragHandle(part)` makes one part, such as a title bar, the only place that drags the node; elsewhere a press only selects it.
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { reactive } from '@motifx/core';
|
|
15
|
+
import { Badge, Button, Diagram, Stack, Switch, TextBox, type DiagramEdge, type DiagramNode, type DiagramNodeKind } from '@motifx-community/ui';
|
|
16
|
+
|
|
17
|
+
/** A step of the app's own: plain data on the node, which the content binds to through a reactive object. */
|
|
18
|
+
interface Step extends DiagramNode {
|
|
19
|
+
data: { name: string; enabled: boolean; runs: number };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Kinds of node of the app's own: kit controls inside the nodes, ports of the kind, and a title bar that drags the node. */
|
|
23
|
+
export default function Kinds() {
|
|
24
|
+
const s = reactive({ said: 'Rename a step, turn it off, or run it. Drag a step by its title.' });
|
|
25
|
+
const step = (id: string, x: number, y: number, name: string, kind = 'step'): Step => ({ id, x, y, kind, width: 240, text: name, data: { name, enabled: true, runs: 0 } });
|
|
26
|
+
const nodes: Step[] = [step('fetch', 0, 0, 'Fetch orders'), step('check', 320, 0, 'Check stock'), step('route', 640, 40, 'In stock?', 'branch')];
|
|
27
|
+
const edges: DiagramEdge[] = [
|
|
28
|
+
{ id: 'a', source: 'fetch', sourcePort: 'out', target: 'check', targetPort: 'in' },
|
|
29
|
+
{ id: 'b', source: 'check', sourcePort: 'out', target: 'route', targetPort: 'in' },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
const kinds: Record<string, DiagramNodeKind<Step>> = {
|
|
33
|
+
step: {
|
|
34
|
+
ports: [
|
|
35
|
+
{ id: 'in', side: 'left', direction: 'target' },
|
|
36
|
+
{ id: 'out', side: 'right', direction: 'source' },
|
|
37
|
+
],
|
|
38
|
+
// Made once per node, with JSX: the controls are the kit's own, bound to the step's fields; what they write goes to `data`.
|
|
39
|
+
content: (context) => {
|
|
40
|
+
const d = reactive(context.node.data);
|
|
41
|
+
// The name a screen reader hears follows the one the user types.
|
|
42
|
+
context.label(() => d.name);
|
|
43
|
+
return (
|
|
44
|
+
<Stack gap="sm">
|
|
45
|
+
<Stack orientation="horizontal" justify="space-between" align="center" ref={(head: Stack) => context.dragHandle(head)}>
|
|
46
|
+
<strong>{() => d.name}</strong>
|
|
47
|
+
<Badge count={() => d.runs} variant="subtle" />
|
|
48
|
+
</Stack>
|
|
49
|
+
<TextBox label="Name" labelMode="hidden" x-model={() => d.name} />
|
|
50
|
+
<Stack orientation="horizontal" justify="space-between" align="center">
|
|
51
|
+
<Switch label="On" x-model={() => d.enabled} />
|
|
52
|
+
<Button
|
|
53
|
+
text="Run"
|
|
54
|
+
size="sm"
|
|
55
|
+
disabled={() => !d.enabled}
|
|
56
|
+
onclick={() => {
|
|
57
|
+
d.runs++;
|
|
58
|
+
s.said = `${d.name} ran ${d.runs === 1 ? 'once' : `${d.runs} times`}.`;
|
|
59
|
+
}}
|
|
60
|
+
/>
|
|
61
|
+
</Stack>
|
|
62
|
+
</Stack>
|
|
63
|
+
);
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
branch: {
|
|
67
|
+
ports: [
|
|
68
|
+
{ id: 'in', side: 'left', direction: 'target' },
|
|
69
|
+
{ id: 'yes', side: 'right', offset: 0.3, direction: 'source' },
|
|
70
|
+
{ id: 'no', side: 'right', offset: 0.75, direction: 'source' },
|
|
71
|
+
],
|
|
72
|
+
content: (context) => (
|
|
73
|
+
<Stack gap="sm">
|
|
74
|
+
<strong>{context.node.text}</strong>
|
|
75
|
+
<Stack orientation="horizontal" justify="end" gap="lg">
|
|
76
|
+
<small>Yes</small>
|
|
77
|
+
</Stack>
|
|
78
|
+
<Stack orientation="horizontal" justify="end" gap="lg">
|
|
79
|
+
<small>No</small>
|
|
80
|
+
</Stack>
|
|
81
|
+
</Stack>
|
|
82
|
+
),
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
<Stack gap="md" class="docs-wide">
|
|
88
|
+
<Diagram
|
|
89
|
+
label="Order steps"
|
|
90
|
+
nodes={nodes}
|
|
91
|
+
edges={edges}
|
|
92
|
+
kinds={kinds}
|
|
93
|
+
autoFit
|
|
94
|
+
/>
|
|
95
|
+
<output>{() => s.said}</output>
|
|
96
|
+
</Stack>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Groups, lanes and notes
|
|
102
|
+
|
|
103
|
+
Three kinds are built in. A `group` holds other nodes under a header, and a `lane` holds them beside a title that runs down its side; a node names the group it is in with `parent`. Its `x` and `y` stay in diagram units. The user drops a node into a group and drags it out again, and a group moves with everything inside it. A `note` is text on the diagram without ports.
|
|
104
|
+
|
|
105
|
+
The button in a header collapses the group: the nodes inside leave the surface and the selection, and their connections end at the group until it opens. `setCollapsed(id, collapsed)` does the same from code, and `onNodeToggled` reports both. Deleting, copying or duplicating a group takes the nodes inside it along.
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
import { reactive } from '@motifx/core';
|
|
109
|
+
import { Button, Diagram, Stack, type DiagramEdge, type DiagramNode } from '@motifx-community/ui';
|
|
110
|
+
|
|
111
|
+
/** Lanes, a group inside a lane, and a note: nodes go into a group and out of it with a drag, and a group collapses. */
|
|
112
|
+
export default function Groups() {
|
|
113
|
+
const s = reactive({ said: 'Drag “Ship” into Payment, or a node out of its group. Select a lane, the group or the note to resize it.' });
|
|
114
|
+
const nodes: DiagramNode[] = [
|
|
115
|
+
{ id: 'customer', x: 0, y: 0, width: 780, height: 140, kind: 'lane', text: 'Customer' },
|
|
116
|
+
{ id: 'shop', x: 0, y: 160, width: 780, height: 260, kind: 'lane', text: 'Shop' },
|
|
117
|
+
{ id: 'order', x: 80, y: 50, text: 'Place order', parent: 'customer' },
|
|
118
|
+
{ id: 'receive', x: 640, y: 50, text: 'Receive parcel', parent: 'customer' },
|
|
119
|
+
{ id: 'payment', x: 80, y: 200, width: 400, height: 190, kind: 'group', text: 'Payment', parent: 'shop' },
|
|
120
|
+
{ id: 'charge', x: 110, y: 280, text: 'Charge card', parent: 'payment' },
|
|
121
|
+
{ id: 'invoice', x: 300, y: 280, text: 'Send invoice', parent: 'payment' },
|
|
122
|
+
{ id: 'ship', x: 520, y: 280, text: 'Ship', parent: 'shop' },
|
|
123
|
+
{ id: 'tip', x: 820, y: 0, width: 200, height: 110, kind: 'note', text: 'A lane collapses to its title, a group to its header. Their connections end at them meanwhile.' },
|
|
124
|
+
];
|
|
125
|
+
const edges: DiagramEdge[] = [
|
|
126
|
+
{ id: 'a', source: 'order', target: 'charge' },
|
|
127
|
+
{ id: 'b', source: 'charge', target: 'invoice' },
|
|
128
|
+
{ id: 'c', source: 'invoice', target: 'ship' },
|
|
129
|
+
{ id: 'd', source: 'ship', target: 'receive' },
|
|
130
|
+
];
|
|
131
|
+
const nameOf = (id: string | undefined) => nodes.find((n) => n.id === id)?.text ?? id;
|
|
132
|
+
let diagram!: Diagram;
|
|
133
|
+
|
|
134
|
+
return (
|
|
135
|
+
<Stack gap="md" class="docs-wide">
|
|
136
|
+
<Stack orientation="horizontal" gap="sm" wrap>
|
|
137
|
+
<Button text="Collapse or open Payment" variant="outline" onclick={() => diagram.setCollapsed('payment', !nodes[4].collapsed)} />
|
|
138
|
+
<Button text="Undo" variant="outline" onclick={() => diagram.undo()} />
|
|
139
|
+
</Stack>
|
|
140
|
+
<Diagram
|
|
141
|
+
ref={(d: Diagram) => (diagram = d)}
|
|
142
|
+
label="Order process"
|
|
143
|
+
nodes={nodes}
|
|
144
|
+
edges={edges}
|
|
145
|
+
autoFit
|
|
146
|
+
onNodesMoved={(e) => {
|
|
147
|
+
const m = e.moves.find((move) => move.fromParent !== move.toParent);
|
|
148
|
+
if (m) s.said = m.toParent ? `${m.node.text} is in ${nameOf(m.toParent)} now.` : `${m.node.text} left ${nameOf(m.fromParent)}.`;
|
|
149
|
+
}}
|
|
150
|
+
onNodeToggled={(e) => (s.said = `${e.node.text} ${e.collapsed ? 'collapsed' : 'opened'}${e.byUser ? '' : ' from code'}.`)}
|
|
151
|
+
onNodeResized={(e) => (s.said = `${e.node.kind === 'note' ? 'The note' : e.node.text}: ${Math.round(e.to.width)} × ${Math.round(e.to.height)}.`)}
|
|
152
|
+
/>
|
|
153
|
+
<output>{() => s.said}</output>
|
|
154
|
+
</Stack>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Resizing
|
|
160
|
+
|
|
161
|
+
A selected node whose kind or own `resizable` allows it has a handle at each corner and takes the pointer along each side. A resize writes `x`, `y`, `width` and `height`, keeps the node at least the size its kind allows, snaps to the grid with `snapToGrid`, and is a step of the history; an undo gives back the size the node had, or none. Alt and an arrow key resize the node under the keys. `onNodeResizing` can cancel a resize, and `onNodeResized` reports it.
|
|
162
|
+
|
|
163
|
+
## Styles
|
|
164
|
+
|
|
165
|
+
`cssClass` and `style` add the app’s own classes and CSS properties to a node or a connection, and a connection also takes a `color` and a `width`. Change them in place and call `refresh()`: only what changed is written. The look of every part is also set by the design tokens below.
|
|
166
|
+
|
|
167
|
+
```tsx
|
|
168
|
+
import { Component } from '@motifx/core';
|
|
169
|
+
import { Button, Diagram, Stack, type DiagramEdge, type DiagramNode } from '@motifx-community/ui';
|
|
170
|
+
|
|
171
|
+
/** Classes and styles of the app's own on nodes and connections; changed in place, they are written on `refresh()`. */
|
|
172
|
+
export default class Styles extends Component<HTMLDivElement> {
|
|
173
|
+
constructor() {
|
|
174
|
+
super('div');
|
|
175
|
+
this.class.add('docs-wide');
|
|
176
|
+
const nodes: DiagramNode[] = [
|
|
177
|
+
{ id: 'ok', x: 0, y: 0, text: 'Healthy', style: { background: 'var(--mx-color-success-subtle)', 'border-color': 'var(--mx-color-success-solid)' } },
|
|
178
|
+
{ id: 'warn', x: 260, y: 0, text: 'Degraded', style: { background: 'var(--mx-color-caution-subtle)', 'border-color': 'var(--mx-color-caution-solid)' } },
|
|
179
|
+
{ id: 'down', x: 520, y: 0, text: 'Down', style: { background: 'var(--mx-color-danger-subtle)', 'border-color': 'var(--mx-color-danger-solid)' } },
|
|
180
|
+
];
|
|
181
|
+
const edges: DiagramEdge[] = [
|
|
182
|
+
{ id: 'a', source: 'ok', target: 'warn', color: 'var(--mx-color-caution-solid)', width: 3 },
|
|
183
|
+
{ id: 'b', source: 'warn', target: 'down', color: 'var(--mx-color-danger-solid)', width: 3, dashed: true },
|
|
184
|
+
];
|
|
185
|
+
const diagram = new Diagram({ label: 'Service health', nodes, edges, autoFit: true });
|
|
186
|
+
const change = new Button({
|
|
187
|
+
text: 'Mark “Down” as recovered',
|
|
188
|
+
variant: 'outline',
|
|
189
|
+
onclick: () => {
|
|
190
|
+
nodes[2].text = 'Recovered';
|
|
191
|
+
nodes[2].style = { background: 'var(--mx-color-success-subtle)', 'border-color': 'var(--mx-color-success-solid)' };
|
|
192
|
+
edges[1].color = 'var(--mx-color-success-solid)';
|
|
193
|
+
edges[1].dashed = false;
|
|
194
|
+
diagram.refresh();
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
const stack = new Stack({ gap: 'md' });
|
|
198
|
+
stack.controls.add(change, diagram);
|
|
199
|
+
this.controls.add(stack);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Feedback
|
|
205
|
+
|
|
206
|
+
Loading issues…
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# Diagram: Tables and classes
|
|
2
|
+
|
|
3
|
+
> Diagram · @motifx-community/ui 0.1.0-beta.16
|
|
4
|
+
|
|
5
|
+
Table (entity relationship) and class diagrams with the built-in `table` and `class` kinds, the marks their connections end with, and texts at the ends of a connection.
|
|
6
|
+
|
|
7
|
+
## Table diagrams
|
|
8
|
+
|
|
9
|
+
A node of the `table` kind shows its name and a row for each of its `columns`, with its type and its key: `primaryKey`, `foreignKey` or `unique`. Each column has a port named by the column beside its row, on the left and on the right; a connection takes the side that faces its other end, and names the column in `sourcePort` or `targetPort`. The user relates two columns by dragging from one to the other.
|
|
10
|
+
|
|
11
|
+
Rows are matched by the column’s name, so changing `columns` in place and calling `refresh()` keeps the rows and connections that stay. The button in the header collapses a table to its name.
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { reactive } from '@motifx/core';
|
|
15
|
+
import { Button, Diagram, Stack, type DiagramEdge, type DiagramTableNode } from '@motifx-community/ui';
|
|
16
|
+
|
|
17
|
+
/** A table diagram: a port beside each column, crow's feet that say how many rows each end takes. */
|
|
18
|
+
export default function Tables() {
|
|
19
|
+
const s = reactive({ said: 'Drag from a column to a column of another table to relate them.' });
|
|
20
|
+
const nodes: DiagramTableNode[] = [
|
|
21
|
+
{
|
|
22
|
+
id: 'customers',
|
|
23
|
+
x: 0,
|
|
24
|
+
y: 0,
|
|
25
|
+
kind: 'table',
|
|
26
|
+
text: 'customers',
|
|
27
|
+
columns: [
|
|
28
|
+
{ name: 'id', type: 'int', primaryKey: true },
|
|
29
|
+
{ name: 'name', type: 'text' },
|
|
30
|
+
{ name: 'email', type: 'text', unique: true },
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: 'orders',
|
|
35
|
+
x: 300,
|
|
36
|
+
y: 40,
|
|
37
|
+
kind: 'table',
|
|
38
|
+
text: 'orders',
|
|
39
|
+
columns: [
|
|
40
|
+
{ name: 'id', type: 'int', primaryKey: true },
|
|
41
|
+
{ name: 'customer_id', type: 'int', foreignKey: true },
|
|
42
|
+
{ name: 'created_at', type: 'timestamp' },
|
|
43
|
+
{ name: 'total', type: 'decimal' },
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: 'order_items',
|
|
48
|
+
x: 600,
|
|
49
|
+
y: 0,
|
|
50
|
+
kind: 'table',
|
|
51
|
+
text: 'order_items',
|
|
52
|
+
columns: [
|
|
53
|
+
{ name: 'order_id', type: 'int', primaryKey: true, foreignKey: true },
|
|
54
|
+
{ name: 'product_id', type: 'int', primaryKey: true, foreignKey: true },
|
|
55
|
+
{ name: 'quantity', type: 'int' },
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: 'products',
|
|
60
|
+
x: 900,
|
|
61
|
+
y: 60,
|
|
62
|
+
kind: 'table',
|
|
63
|
+
text: 'products',
|
|
64
|
+
columns: [
|
|
65
|
+
{ name: 'id', type: 'int', primaryKey: true },
|
|
66
|
+
{ name: 'name', type: 'text' },
|
|
67
|
+
{ name: 'price', type: 'decimal' },
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
const relation = (id: string, source: string, sourcePort: string, target: string, sourceMarker: DiagramEdge['sourceMarker']): DiagramEdge => ({
|
|
72
|
+
id,
|
|
73
|
+
source,
|
|
74
|
+
sourcePort,
|
|
75
|
+
target,
|
|
76
|
+
targetPort: 'id',
|
|
77
|
+
path: 'rounded-step',
|
|
78
|
+
sourceMarker,
|
|
79
|
+
targetMarker: 'one',
|
|
80
|
+
});
|
|
81
|
+
const edges: DiagramEdge[] = [
|
|
82
|
+
relation('orders-customer', 'orders', 'customer_id', 'customers', 'zero-or-many'),
|
|
83
|
+
relation('items-order', 'order_items', 'order_id', 'orders', 'one-or-many'),
|
|
84
|
+
relation('items-product', 'order_items', 'product_id', 'products', 'zero-or-many'),
|
|
85
|
+
];
|
|
86
|
+
let diagram!: Diagram;
|
|
87
|
+
const orders = nodes[1];
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<Stack gap="md" class="docs-wide">
|
|
91
|
+
<Stack orientation="horizontal" gap="sm" wrap>
|
|
92
|
+
<Button
|
|
93
|
+
text="Add a column to orders"
|
|
94
|
+
variant="outline"
|
|
95
|
+
onclick={() => {
|
|
96
|
+
orders.columns.push({ name: `note_${orders.columns.length}`, type: 'text' });
|
|
97
|
+
diagram.refresh();
|
|
98
|
+
}}
|
|
99
|
+
/>
|
|
100
|
+
<Button
|
|
101
|
+
text="Collapse or open the tables"
|
|
102
|
+
variant="outline"
|
|
103
|
+
onclick={() => {
|
|
104
|
+
const collapse = !nodes.every((n) => n.collapsed);
|
|
105
|
+
for (const n of nodes) diagram.setCollapsed(n.id, collapse);
|
|
106
|
+
}}
|
|
107
|
+
/>
|
|
108
|
+
</Stack>
|
|
109
|
+
<Diagram
|
|
110
|
+
ref={(d: Diagram) => (diagram = d)}
|
|
111
|
+
label="Shop database"
|
|
112
|
+
nodes={nodes}
|
|
113
|
+
edges={edges}
|
|
114
|
+
autoFit
|
|
115
|
+
// A relation the user draws: many rows of the table it starts at, one of the table it ends at.
|
|
116
|
+
onConnecting={(e) => {
|
|
117
|
+
e.edge.path = 'rounded-step';
|
|
118
|
+
e.edge.sourceMarker = 'zero-or-many';
|
|
119
|
+
e.edge.targetMarker = 'one';
|
|
120
|
+
}}
|
|
121
|
+
onConnected={(e) => (s.said = `${e.edge.source}.${e.edge.sourcePort} → ${e.edge.target}.${e.edge.targetPort}`)}
|
|
122
|
+
/>
|
|
123
|
+
<output>{() => s.said}</output>
|
|
124
|
+
</Stack>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Class diagrams
|
|
130
|
+
|
|
131
|
+
A node of the `class` kind shows its `stereotype` between guillemets over its name, which slants when the class is `abstract`, and its `attributes` and `methods` in two compartments. Each member shows who sees it (`+` public, `-` private, `#` protected, `~` package), its name and its type; a `static` member is underlined and an `abstract` one slants. A class has a port in the middle of each side that connections start and end at, and the button in its header hides its compartments.
|
|
132
|
+
|
|
133
|
+
`sourceLabel` and `targetLabel` write a text at each end of a connection, beside the line by the node, such as how many objects the end takes.
|
|
134
|
+
|
|
135
|
+
```tsx
|
|
136
|
+
import { Diagram, type DiagramClassNode, type DiagramEdge } from '@motifx-community/ui';
|
|
137
|
+
|
|
138
|
+
/** A class diagram: inheritance, composition with how many objects each end takes, and a dependency. */
|
|
139
|
+
export default function Classes() {
|
|
140
|
+
const nodes: DiagramClassNode[] = [
|
|
141
|
+
{
|
|
142
|
+
id: 'drawing',
|
|
143
|
+
x: 0,
|
|
144
|
+
y: 0,
|
|
145
|
+
kind: 'class',
|
|
146
|
+
text: 'Drawing',
|
|
147
|
+
attributes: [{ name: 'shapes', type: 'Shape[]', visibility: 'private' }],
|
|
148
|
+
methods: [
|
|
149
|
+
{ name: 'add(shape: Shape)', type: 'void', visibility: 'public' },
|
|
150
|
+
{ name: 'render()', type: 'void', visibility: 'public' },
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
id: 'shape',
|
|
155
|
+
x: 380,
|
|
156
|
+
y: 0,
|
|
157
|
+
kind: 'class',
|
|
158
|
+
text: 'Shape',
|
|
159
|
+
abstract: true,
|
|
160
|
+
attributes: [
|
|
161
|
+
{ name: 'name', type: 'string', visibility: 'protected' },
|
|
162
|
+
{ name: 'count', type: 'number', visibility: 'private', static: true },
|
|
163
|
+
],
|
|
164
|
+
methods: [
|
|
165
|
+
{ name: 'area()', type: 'number', visibility: 'public', abstract: true },
|
|
166
|
+
{ name: 'describe()', type: 'string', visibility: 'public' },
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
{ id: 'circle', x: 260, y: 280, kind: 'class', text: 'Circle', attributes: [{ name: 'radius', type: 'number', visibility: 'private' }], methods: [{ name: 'area()', type: 'number', visibility: 'public' }] },
|
|
170
|
+
{
|
|
171
|
+
id: 'rectangle',
|
|
172
|
+
x: 520,
|
|
173
|
+
y: 280,
|
|
174
|
+
kind: 'class',
|
|
175
|
+
text: 'Rectangle',
|
|
176
|
+
attributes: [
|
|
177
|
+
{ name: 'width', type: 'number', visibility: 'private' },
|
|
178
|
+
{ name: 'height', type: 'number', visibility: 'private' },
|
|
179
|
+
],
|
|
180
|
+
methods: [{ name: 'area()', type: 'number', visibility: 'public' }],
|
|
181
|
+
},
|
|
182
|
+
{ id: 'renderer', x: 0, y: 280, kind: 'class', text: 'Renderer', stereotype: 'interface', methods: [{ name: 'draw(shape: Shape)', type: 'void', visibility: 'public', abstract: true }] },
|
|
183
|
+
];
|
|
184
|
+
const edges: DiagramEdge[] = [
|
|
185
|
+
{ id: 'circle-shape', source: 'circle', target: 'shape', path: 'step', targetMarker: 'triangle-open' },
|
|
186
|
+
{ id: 'rectangle-shape', source: 'rectangle', target: 'shape', path: 'step', targetMarker: 'triangle-open' },
|
|
187
|
+
{ id: 'drawing-shape', source: 'drawing', target: 'shape', path: 'straight', sourceMarker: 'diamond', targetMarker: 'arrow-open', sourceLabel: '1', targetLabel: '0..*' },
|
|
188
|
+
{ id: 'drawing-renderer', source: 'drawing', target: 'renderer', path: 'straight', targetMarker: 'arrow-open', dashed: true, label: 'uses' },
|
|
189
|
+
];
|
|
190
|
+
return <Diagram class="docs-wide" label="Shapes" nodes={nodes} edges={edges} autoFit />;
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Marks
|
|
195
|
+
|
|
196
|
+
`sourceMarker` and `targetMarker` take these marks besides those of a flow. The line stops at the back of a shape that is filled over it or open inside; a crow’s foot stands on a line that reaches the node.
|
|
197
|
+
|
|
198
|
+
| Mark | Meaning |
|
|
199
|
+
| --- | --- |
|
|
200
|
+
| ``one`` | Two bars: exactly one row. |
|
|
201
|
+
| ``many`` | A crow’s foot: many rows. |
|
|
202
|
+
| ``zero-or-one`` | A ring and a bar: no row or one. |
|
|
203
|
+
| ``one-or-many`` | A bar and a crow’s foot: one row or more. |
|
|
204
|
+
| ``zero-or-many`` | A ring and a crow’s foot: any number of rows. |
|
|
205
|
+
| ``triangle-open`` | An open triangle at the class inherited from, or the interface realized. |
|
|
206
|
+
| ``diamond`` | A filled diamond at the whole of a composition: its parts go with it. |
|
|
207
|
+
| ``diamond-open`` | An open diamond at the whole of an aggregation: its parts live on their own. |
|
|
208
|
+
| ``arrow`, `arrow-open`, `circle`, `none`` | The marks of a flow, also for the way an association is read. |
|
|
209
|
+
|
|
210
|
+
## Feedback
|
|
211
|
+
|
|
212
|
+
Loading issues…
|
package/docs/diagram.md
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# Diagram
|
|
2
|
+
|
|
3
|
+
> Diagram · @motifx-community/ui 0.1.0-beta.16
|
|
4
|
+
|
|
5
|
+
Nodes and the connections between them on a surface that the user pans and zooms. The user draws connections between the ports of nodes and moves their ends. The diagram is only the surface: toolbars and menus belong to the app, which uses the diagram’s methods.
|
|
6
|
+
|
|
7
|
+
## Import
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import { Diagram } from '@motifx-community/ui';
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Nodes and connections
|
|
14
|
+
|
|
15
|
+
Each node has an `id` and a position in diagram units. A node without a size takes the size of its content. Each connection joins two nodes by their `id`. `autoFit` fits the nodes into view once they are laid out. Drag the surface to pan, and hold Ctrl while turning the wheel to zoom.
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { Diagram, type DiagramEdge, type DiagramNode } from '@motifx-community/ui';
|
|
19
|
+
|
|
20
|
+
const NODES: DiagramNode[] = [
|
|
21
|
+
{ id: 'order', x: 0, y: 90, text: 'Order received' },
|
|
22
|
+
{ id: 'stock', x: 220, y: 0, text: 'Check the stock' },
|
|
23
|
+
{ id: 'payment', x: 220, y: 180, text: 'Take the payment' },
|
|
24
|
+
{ id: 'ship', x: 460, y: 90, text: 'Ship the order' },
|
|
25
|
+
{ id: 'notify', x: 680, y: 70, width: 170, text: 'Send the tracking number to the customer' },
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
const EDGES: DiagramEdge[] = [
|
|
29
|
+
{ id: 'e1', source: 'order', target: 'stock' },
|
|
30
|
+
{ id: 'e2', source: 'order', target: 'payment' },
|
|
31
|
+
{ id: 'e3', source: 'stock', target: 'ship', label: 'In stock' },
|
|
32
|
+
{ id: 'e4', source: 'payment', target: 'ship', label: 'Paid' },
|
|
33
|
+
{ id: 'e5', source: 'ship', target: 'notify' },
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
/** Nodes and the connections between them, fitted into view once they are laid out. */
|
|
37
|
+
export default function Basic() {
|
|
38
|
+
return <Diagram class="diagram-basic" label="Order flow" autoFit nodes={NODES} edges={EDGES} />;
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Moving the view
|
|
43
|
+
|
|
44
|
+
`zoomIn`, `zoomOut`, `fit` and `centerOn` move the view from code, and `animate` glides it with the motion of the design language. `onViewportChanged` reports every move. `background` sets the marks on the surface.
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
import { reactive } from '@motifx/core';
|
|
48
|
+
import { Button, ButtonGroup, Diagram, Stack, type DiagramBackground, type DiagramNode, type DiagramViewport } from '@motifx-community/ui';
|
|
49
|
+
|
|
50
|
+
const NODES: DiagramNode[] = Array.from({ length: 12 }, (_, i) => ({ id: `step-${i + 1}`, x: (i % 4) * 220, y: Math.floor(i / 4) * 140, text: `Step ${i + 1}` }));
|
|
51
|
+
|
|
52
|
+
/** The view moved from code: zoom, fit and center on a node, each gliding there; the marks of the surface. */
|
|
53
|
+
export default function View() {
|
|
54
|
+
const s = reactive({ background: 'dots' as unknown, viewport: { x: 0, y: 0, zoom: 1 } as DiagramViewport });
|
|
55
|
+
let diagram: Diagram | null = null;
|
|
56
|
+
return (
|
|
57
|
+
<Stack gap="md" style="inline-size: 100%">
|
|
58
|
+
<Stack orientation="horizontal" wrap align="center">
|
|
59
|
+
<Button text="Zoom in" variant="outline" onclick={() => diagram?.zoomIn({ animate: true })} />
|
|
60
|
+
<Button text="Zoom out" variant="outline" onclick={() => diagram?.zoomOut({ animate: true })} />
|
|
61
|
+
<Button text="Fit" variant="outline" onclick={() => diagram?.fit({ animate: true })} />
|
|
62
|
+
<Button text="Center on step 6" variant="outline" onclick={() => diagram?.centerOn('step-6', { zoom: 1.5, animate: true })} />
|
|
63
|
+
<ButtonGroup label="Background" items={['dots', 'lines', 'cross', 'none']} x-model={() => s.background} />
|
|
64
|
+
</Stack>
|
|
65
|
+
<Diagram
|
|
66
|
+
class="diagram-view"
|
|
67
|
+
ref={(d: Diagram) => (diagram = d)}
|
|
68
|
+
label="Steps"
|
|
69
|
+
autoFit
|
|
70
|
+
nodes={NODES}
|
|
71
|
+
background={() => s.background as DiagramBackground}
|
|
72
|
+
onViewportChanged={(e) => (s.viewport = e.viewport)}
|
|
73
|
+
/>
|
|
74
|
+
<output class="diagram-view-told">{() => `x ${Math.round(s.viewport.x)}, y ${Math.round(s.viewport.y)}, zoom ${s.viewport.zoom.toFixed(2)}`}</output>
|
|
75
|
+
</Stack>
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Limits
|
|
81
|
+
|
|
82
|
+
`minZoom` and `maxZoom` limit the zoom. `bounds` keeps the view over an area of the diagram, and centers the area when it is smaller than the view.
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
import { Diagram, type DiagramNode } from '@motifx-community/ui';
|
|
86
|
+
|
|
87
|
+
const NODES: DiagramNode[] = [
|
|
88
|
+
{ id: 'north', x: 160, y: 0, text: 'North' },
|
|
89
|
+
{ id: 'west', x: 0, y: 120, text: 'West' },
|
|
90
|
+
{ id: 'east', x: 320, y: 120, text: 'East' },
|
|
91
|
+
{ id: 'south', x: 160, y: 240, text: 'South' },
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
/** The view stays over the nodes' area, between half and twice the actual size. */
|
|
95
|
+
export default function Limits() {
|
|
96
|
+
return <Diagram class="diagram-limits" label="Compass" autoFit nodes={NODES} minZoom={0.5} maxZoom={2} bounds={{ x: -80, y: -80, width: 600, height: 440 }} background="lines" />;
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Large diagrams
|
|
101
|
+
|
|
102
|
+
A diagram of more nodes than `detailLimit` (400 by default) keeps on the page only the nodes and lines in view and near it: a node is made when it first comes into view, a few hundred a frame at most, and leaves the page with its content kept when it goes out of view. A node not laid out yet takes the size of the nodes of its kind laid out so far, and its lines are drawn to it; it takes its own size once it comes into view. With more nodes in view than `detailLimit`, the diagram draws a sketch of them, each node a box and each line a plain line, until fewer are in view.
|
|
103
|
+
|
|
104
|
+
`layout` and the images put every node on the page for a moment, to lay them out. Load ten thousand nodes below: they come at once, and panning, zooming and dragging stay as smooth as in a small diagram.
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
import { reactive } from '@motifx/core';
|
|
108
|
+
import { Button, Diagram, Stack, type DiagramEdge, type DiagramNode } from '@motifx-community/ui';
|
|
109
|
+
|
|
110
|
+
/** Rows of steps, each leading to the next and now and then to the step below: as many as asked for. */
|
|
111
|
+
function steps(count: number): { nodes: DiagramNode[]; edges: DiagramEdge[] } {
|
|
112
|
+
const columns = Math.ceil(Math.sqrt(count * 2));
|
|
113
|
+
const nodes: DiagramNode[] = [];
|
|
114
|
+
const edges: DiagramEdge[] = [];
|
|
115
|
+
for (let k = 0; k < count; k++) {
|
|
116
|
+
nodes.push({ id: `n${k}`, text: `Step ${k + 1}`, x: (k % columns) * 200, y: Math.floor(k / columns) * 110 });
|
|
117
|
+
if (k % columns && k > 0) edges.push({ id: `r${k}`, source: `n${k - 1}`, target: `n${k}` });
|
|
118
|
+
if (k >= columns && k % 3 === 0) edges.push({ id: `d${k}`, source: `n${k - columns}`, target: `n${k}`, sourcePort: 'bottom', targetPort: 'top' });
|
|
119
|
+
}
|
|
120
|
+
return { nodes, edges };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** A large diagram: the time from loading the nodes to their first frame, and a map to find the way. */
|
|
124
|
+
export default function Large() {
|
|
125
|
+
const s = reactive({ said: 'Load a diagram of many nodes.' });
|
|
126
|
+
let diagram!: Diagram;
|
|
127
|
+
let waiting: { count: number; from: number } | null = null;
|
|
128
|
+
let laying = 0;
|
|
129
|
+
const show = (count: number) => {
|
|
130
|
+
waiting = { count, from: performance.now() };
|
|
131
|
+
s.said = `Loading ${count.toLocaleString()} nodes…`;
|
|
132
|
+
diagram.load({ ...steps(count), viewport: { x: 24, y: 24, zoom: 1 } });
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<Stack gap="md" class="docs-wide">
|
|
137
|
+
<Stack orientation="horizontal" gap="sm" wrap align="center">
|
|
138
|
+
<Button text="100 nodes" variant="outline" onclick={() => show(100)} />
|
|
139
|
+
<Button text="1,000 nodes" variant="outline" onclick={() => show(1000)} />
|
|
140
|
+
<Button text="10,000 nodes" variant="outline" onclick={() => show(10000)} />
|
|
141
|
+
<Button
|
|
142
|
+
text="Lay out"
|
|
143
|
+
variant="outline"
|
|
144
|
+
onclick={() => {
|
|
145
|
+
laying = performance.now();
|
|
146
|
+
s.said = 'Laying out…';
|
|
147
|
+
diagram.layout({ direction: 'right', fit: true });
|
|
148
|
+
}}
|
|
149
|
+
/>
|
|
150
|
+
<Button
|
|
151
|
+
text="Make an SVG"
|
|
152
|
+
variant="outline"
|
|
153
|
+
onclick={() => {
|
|
154
|
+
const from = performance.now();
|
|
155
|
+
const svg = diagram.toSVG();
|
|
156
|
+
const nodes = svg.match(/>Step \d+</g)?.length ?? 0;
|
|
157
|
+
s.said = `An SVG of ${nodes.toLocaleString()} nodes, ${Math.round(svg.length / 1024).toLocaleString()} KB, in ${Math.round(performance.now() - from)} ms.`;
|
|
158
|
+
}}
|
|
159
|
+
/>
|
|
160
|
+
<output>{() => s.said}</output>
|
|
161
|
+
</Stack>
|
|
162
|
+
<Diagram
|
|
163
|
+
ref={(d: Diagram) => (diagram = d)}
|
|
164
|
+
label="Many steps"
|
|
165
|
+
miniMap
|
|
166
|
+
onNodesMoved={() => {
|
|
167
|
+
if (!laying) return;
|
|
168
|
+
s.said = `${diagram.nodes.length.toLocaleString()} nodes laid out in ${Math.round(performance.now() - laying)} ms.`;
|
|
169
|
+
laying = 0;
|
|
170
|
+
}}
|
|
171
|
+
// The time it took: the nodes, laid out, on the screen with their lines.
|
|
172
|
+
onContentChanged={() => {
|
|
173
|
+
if (!waiting || diagram.nodes.length !== waiting.count) return;
|
|
174
|
+
const took = Math.round(performance.now() - waiting.from);
|
|
175
|
+
s.said = `${waiting.count.toLocaleString()} nodes in ${took} ms.`;
|
|
176
|
+
waiting = null;
|
|
177
|
+
}}
|
|
178
|
+
/>
|
|
179
|
+
</Stack>
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Programmatic use
|
|
185
|
+
|
|
186
|
+
`new Diagram(props)` creates the diagram without JSX. Each prop is also a property. A change made to the nodes in place is drawn on `refresh()` or on `reState()`.
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
import { Component } from '@motifx/core';
|
|
190
|
+
import { Button, Diagram, Stack } from '@motifx-community/ui';
|
|
191
|
+
|
|
192
|
+
/** A diagram created programmatically. A node added to the array is drawn on `refresh()`. */
|
|
193
|
+
export default class Programmatic extends Component<HTMLDivElement> {
|
|
194
|
+
constructor() {
|
|
195
|
+
super('div');
|
|
196
|
+
this.class.add('docs-wide');
|
|
197
|
+
const nodes = [{ id: 'first', x: 0, y: 0, text: 'First' }];
|
|
198
|
+
const diagram = new Diagram({ label: 'Programmatic diagram', nodes, autoFit: true, background: 'cross' });
|
|
199
|
+
const add = new Button({
|
|
200
|
+
text: 'Add a node',
|
|
201
|
+
variant: 'outline',
|
|
202
|
+
onclick: () => {
|
|
203
|
+
nodes.push({ id: `node-${nodes.length + 1}`, x: nodes.length * 200, y: (nodes.length % 2) * 100, text: `Node ${nodes.length + 1}` });
|
|
204
|
+
diagram.refresh();
|
|
205
|
+
diagram.fit({ animate: true });
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
const stack = new Stack({ gap: 'md' });
|
|
209
|
+
stack.controls.add(add, diagram);
|
|
210
|
+
this.controls.add(stack);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Feedback
|
|
216
|
+
|
|
217
|
+
Loading issues…
|
package/docs/display.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Display
|
|
2
2
|
|
|
3
|
-
> Display · @motifx-community/ui 0.1.0-beta.
|
|
3
|
+
> Display · @motifx-community/ui 0.1.0-beta.16
|
|
4
4
|
|
|
5
5
|
Display components present content: people, counts and labels, cards, pictures, tiles, events in time, codes to scan, and placeholders while content loads.
|
|
6
6
|
|
package/docs/draggable.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Draggable and DropTarget
|
|
2
2
|
|
|
3
|
-
> Navigation · @motifx-community/ui 0.1.0-beta.
|
|
3
|
+
> Navigation · @motifx-community/ui 0.1.0-beta.16
|
|
4
4
|
|
|
5
5
|
Makes any content movable with the pointer, touch or the arrow keys, optionally along one axis, inside a boundary, by a handle or as a copy. `DropTarget` defines areas that accept it. To reorder items in a list, see [Sortable](sortable.md).
|
|
6
6
|
|
package/docs/drawer.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Drawer
|
|
2
2
|
|
|
3
|
-
> Navigation · @motifx-community/ui 0.1.0-beta.
|
|
3
|
+
> Navigation · @motifx-community/ui 0.1.0-beta.16
|
|
4
4
|
|
|
5
5
|
A panel that slides in from an edge of the page or a container, either over the content or pushing it aside. Users can swipe it in from the edge and back out, and Escape, the scrim and the browser's back action close it.
|
|
6
6
|
|