@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,157 @@
|
|
|
1
|
+
# Diagram: Connections
|
|
2
|
+
|
|
3
|
+
> Diagram · @motifx-community/ui 0.1.0-beta.16
|
|
4
|
+
|
|
5
|
+
Connections run from an output of a node to an input of another. The user draws them from the ports and moves their ends, and the diagram holds every connection to its rules.
|
|
6
|
+
|
|
7
|
+
## Lines and markers
|
|
8
|
+
|
|
9
|
+
`edgePath` sets the shape of every line, and a connection can set its own `path`. `sourceMarker` and `targetMarker` set the marks at its ends, `label` the text in its middle, and `dashed` and `animated` the look of the line. A line between two nodes without ports leaves each node by the side that faces the other, and follows the nodes when they move or change size.
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { reactive } from '@motifx/core';
|
|
13
|
+
import { ButtonGroup, Diagram, Stack, type DiagramEdge, type DiagramEdgePath, type DiagramNode } from '@motifx-community/ui';
|
|
14
|
+
|
|
15
|
+
const NODES: DiagramNode[] = [
|
|
16
|
+
{ id: 'a', x: 0, y: 0, text: 'Arrow' },
|
|
17
|
+
{ id: 'b', x: 260, y: 90, text: 'Open arrow' },
|
|
18
|
+
{ id: 'c', x: 0, y: 200, text: 'Circle' },
|
|
19
|
+
{ id: 'd', x: 260, y: 290, text: 'Dashed' },
|
|
20
|
+
{ id: 'e', x: 520, y: 0, text: 'Animated' },
|
|
21
|
+
{ id: 'f', x: 520, y: 290, text: 'No marks' },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
const EDGES: DiagramEdge[] = [
|
|
25
|
+
{ id: 'ab', source: 'a', target: 'b', label: 'arrow' },
|
|
26
|
+
{ id: 'cb', source: 'c', target: 'b', targetMarker: 'arrow-open', label: 'arrow-open' },
|
|
27
|
+
{ id: 'cd', source: 'c', target: 'd', sourceMarker: 'circle', targetMarker: 'circle', label: 'circle' },
|
|
28
|
+
{ id: 'bd', source: 'b', target: 'd', dashed: true },
|
|
29
|
+
{ id: 'be', source: 'b', target: 'e', animated: true },
|
|
30
|
+
{ id: 'df', source: 'd', target: 'f', targetMarker: 'none' },
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
/** The shapes of a line, the marks at its ends, labels, dashed and moving lines. */
|
|
34
|
+
export default function Connections() {
|
|
35
|
+
const s = reactive({ path: 'curve' as unknown });
|
|
36
|
+
return (
|
|
37
|
+
<Stack gap="md" style="inline-size: 100%">
|
|
38
|
+
<ButtonGroup label="Shape" items={['straight', 'curve', 'step', 'rounded-step']} x-model={() => s.path} />
|
|
39
|
+
<Diagram class="diagram-connections" label="Shapes and marks" autoFit nodes={NODES} edges={EDGES} edgePath={() => s.path as DiagramEdgePath} background="lines" />
|
|
40
|
+
</Stack>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Drawing connections
|
|
46
|
+
|
|
47
|
+
The ports show over a node; outputs are filled and inputs are hollow. Drag from a port to connect it: every port the connection can end at is shown, and dropping on a node takes its nearest one. Select a connection and drag the handle at one of its ends to move that end; the other end stays in place. The diagram refuses a connection that breaks its rules or `canConnect`, and marks the port red while the pointer is over it. A new connection is added to `edges` after `onConnecting`, which can change or cancel it.
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { reactive } from '@motifx/core';
|
|
51
|
+
import { Diagram, Stack, type DiagramConnection, type DiagramEdge, type DiagramNode } from '@motifx-community/ui';
|
|
52
|
+
|
|
53
|
+
const NODES: DiagramNode[] = [
|
|
54
|
+
{ id: 'orders', x: 0, y: 40, text: 'Orders', ports: [{ id: 'out', side: 'right', direction: 'source', type: 'data' }] },
|
|
55
|
+
{ id: 'clicks', x: 0, y: 200, text: 'Clicks', ports: [{ id: 'out', side: 'right', direction: 'source', type: 'event' }] },
|
|
56
|
+
{
|
|
57
|
+
id: 'join',
|
|
58
|
+
x: 260,
|
|
59
|
+
y: 110,
|
|
60
|
+
text: 'Join',
|
|
61
|
+
ports: [
|
|
62
|
+
{ id: 'left', side: 'left', offset: 0.3, direction: 'target', type: 'data', maxConnections: 1 },
|
|
63
|
+
{ id: 'right', side: 'left', offset: 0.7, direction: 'target', type: 'data', maxConnections: 1 },
|
|
64
|
+
{ id: 'out', side: 'right', direction: 'source', type: 'data' },
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
{ id: 'report', x: 520, y: 40, text: 'Report', ports: [{ id: 'in', side: 'left', direction: 'target', type: 'data' }] },
|
|
68
|
+
{ id: 'alerts', x: 520, y: 200, text: 'Alerts', ports: [{ id: 'in', side: 'left', direction: 'target', type: 'event' }] },
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Ports that only start or only end a connection, that join only ports of their type, and that take one connection.
|
|
73
|
+
* Drag from a port to another to connect them; drag an end of a line to move it. A connection into itself is refused.
|
|
74
|
+
*/
|
|
75
|
+
export default function Connecting() {
|
|
76
|
+
const edges: DiagramEdge[] = [{ id: 'first', source: 'orders', sourcePort: 'out', target: 'join', targetPort: 'left' }];
|
|
77
|
+
const s = reactive({ told: 'Drag from a port to connect.', count: edges.length });
|
|
78
|
+
return (
|
|
79
|
+
<Stack gap="md" style="inline-size: 100%">
|
|
80
|
+
<Diagram
|
|
81
|
+
class="diagram-connecting"
|
|
82
|
+
label="Data flow"
|
|
83
|
+
autoFit
|
|
84
|
+
nodes={NODES}
|
|
85
|
+
edges={edges}
|
|
86
|
+
edgePath="rounded-step"
|
|
87
|
+
canConnect={(c: DiagramConnection) => c.source !== c.target}
|
|
88
|
+
onConnected={(e) => {
|
|
89
|
+
s.told = `Connected ${e.edge.source} to ${e.edge.target}.`;
|
|
90
|
+
s.count = edges.length;
|
|
91
|
+
}}
|
|
92
|
+
onReconnected={(e) => (s.told = `Moved the ${e.end} of ${e.edge.id} to ${e.end === 'source' ? e.edge.source : e.edge.target}.`)}
|
|
93
|
+
/>
|
|
94
|
+
<output class="diagram-connecting-told">{() => `${s.told} Connections: ${s.count}.`}</output>
|
|
95
|
+
</Stack>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
| Rule | Description |
|
|
101
|
+
| --- | --- |
|
|
102
|
+
| `Direction` | A connection runs from an output to an input: an input never connects to an input, and an output never to an output. A port with `direction: 'source'` is an output, `'target'` an input, and `'both'` either. On a node without its own ports, the top and left sides are inputs and the right and bottom sides outputs. A drag from an input draws the connection backwards, and a drag from a port that is both takes the direction of the port it ends at. |
|
|
103
|
+
| `Type` | A port with a `type` connects only to a port of the same type. |
|
|
104
|
+
| `Limit` | A port with `maxConnections` takes no more connections than that. |
|
|
105
|
+
| `Duplicates` | Two nodes are not connected twice through the same ports, and a port is not connected to itself. |
|
|
106
|
+
| `App rule` | `canConnect` is asked last, for every connection the user draws, every end the user moves, and every `connect()` call. |
|
|
107
|
+
|
|
108
|
+
## Points and routes
|
|
109
|
+
|
|
110
|
+
`orthogonal` and `rounded-orthogonal` lines turn at right angles around the nodes in their way, with as few turns as they can, and find their way again when a node moves into it or out of it. `step` and `rounded-step` take the shortest right-angled way and do not look at the other nodes.
|
|
111
|
+
|
|
112
|
+
A line passes through the `points` of its own. On a selected line, drag the handle in the middle of a run to add a point, drag a point to move it, and double-click it to take it away. On a right-angled line, drag the handle of a run to move it sideways: the line keeps the turns it has then as points of its own, and a double click gives it back to its own way. Each change is a step of the history, after `onEdgeReshaping`, which can cancel it, and before `onEdgeReshaped`. The points move with the line when both of its nodes move.
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
import { reactive } from '@motifx/core';
|
|
116
|
+
import { Button, Diagram, Stack, type DiagramEdge, type DiagramEdgePath, type DiagramNode } from '@motifx-community/ui';
|
|
117
|
+
|
|
118
|
+
const SHAPES: DiagramEdgePath[] = ['rounded-orthogonal', 'orthogonal', 'rounded-step', 'curve', 'straight'];
|
|
119
|
+
|
|
120
|
+
/** Lines that find their way around the nodes, and points of a line's own that the user adds, moves and takes away. */
|
|
121
|
+
export default function Routes() {
|
|
122
|
+
const s = reactive({ shape: SHAPES[0], said: 'Select a line to change it. Drag the store between the others: the lines go around it.' });
|
|
123
|
+
const nodes: DiagramNode[] = [
|
|
124
|
+
{ id: 'order', x: 0, y: 120, text: 'Order' },
|
|
125
|
+
{ id: 'store', x: 260, y: 60, width: 120, height: 160, text: 'Store' },
|
|
126
|
+
{ id: 'pack', x: 560, y: 0, text: 'Pack' },
|
|
127
|
+
{ id: 'ship', x: 560, y: 240, text: 'Ship' },
|
|
128
|
+
];
|
|
129
|
+
const edges: DiagramEdge[] = [
|
|
130
|
+
{ id: 'order-pack', source: 'order', sourcePort: 'right', target: 'pack', targetPort: 'left' },
|
|
131
|
+
{ id: 'order-ship', source: 'order', sourcePort: 'right', target: 'ship', targetPort: 'left' },
|
|
132
|
+
{ id: 'store-pack', source: 'store', sourcePort: 'right', target: 'pack', targetPort: 'top', dashed: true, points: [{ x: 460, y: 140 }, { x: 460, y: -40 }, { x: 610, y: -40 }] },
|
|
133
|
+
];
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<Stack gap="md" class="docs-wide">
|
|
137
|
+
<Stack orientation="horizontal" gap="sm" wrap align="center">
|
|
138
|
+
<Button text="Next shape" variant="outline" onclick={() => (s.shape = SHAPES[(SHAPES.indexOf(s.shape) + 1) % SHAPES.length])} />
|
|
139
|
+
<output>{() => `edgePath: '${s.shape}'`}</output>
|
|
140
|
+
</Stack>
|
|
141
|
+
<Diagram
|
|
142
|
+
label="Order routes"
|
|
143
|
+
nodes={nodes}
|
|
144
|
+
edges={edges}
|
|
145
|
+
edgePath={() => s.shape}
|
|
146
|
+
autoFit
|
|
147
|
+
onEdgeReshaped={(e) => (s.said = e.edge.points ? `${e.edge.id}: ${e.edge.points.length} points of its own.` : `${e.edge.id} finds its own way again.`)}
|
|
148
|
+
/>
|
|
149
|
+
<output>{() => s.said}</output>
|
|
150
|
+
</Stack>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Feedback
|
|
156
|
+
|
|
157
|
+
Loading issues…
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
# Diagram: Custom nodes
|
|
2
|
+
|
|
3
|
+
> Diagram · @motifx-community/ui 0.1.0-beta.16
|
|
4
|
+
|
|
5
|
+
A node of the app’s own is a node kind: the node names it in `kind`, and the diagram’s `kinds` says what the nodes of that kind hold, which ports they have, how they look and how large they are. These recipes build kinds step by step, from a card that shows data to nodes with controls, ports of their own and content made without JSX.
|
|
6
|
+
|
|
7
|
+
## A first kind
|
|
8
|
+
|
|
9
|
+
A kind takes four steps. Give the node’s data a type that extends `DiagramNode`; name the kind in each node’s `kind`; give `kinds` the kind’s `content`, which makes the content of each node once and returns a component made with JSX or in code, or a text; and give the kind a `cssClass` for its look.
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
interface Person extends DiagramNode {
|
|
13
|
+
data: { role: string };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const kinds: Record<string, DiagramNodeKind<Person>> = {
|
|
17
|
+
person: {
|
|
18
|
+
cssClass: 'org-person',
|
|
19
|
+
content: (context) => (
|
|
20
|
+
<Stack orientation="horizontal" gap="sm" align="center">
|
|
21
|
+
<Avatar name={context.node.text ?? ''} tone="auto" size="sm" />
|
|
22
|
+
<strong>{context.node.text}</strong>
|
|
23
|
+
</Stack>
|
|
24
|
+
),
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const nodes: Person[] = [
|
|
29
|
+
{ id: 'ada', x: 0, y: 0, kind: 'person', text: 'Ada Lovelace', data: { role: 'Head of engineering' } },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
<Diagram label="Team" nodes={nodes} edges={edges} kinds={kinds} />
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The content takes the place of the node’s text on the surface, but `text` is still what a screen reader calls the node: give it the node’s name. A name the user changes inside the content is given with `context.label(() => d.name)`, and the node follows it as the data changes. The node keeps its frame, its ports, its selection and its keys from the diagram; the class adds to them. `[data-selected]` marks a selected node, `[data-active]` the node under the keys.
|
|
36
|
+
|
|
37
|
+
```tsx
|
|
38
|
+
.mx-diagram__node.org-person {
|
|
39
|
+
border-inline-start: 4px solid var(--mx-color-accent-solid);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.mx-diagram__node.org-person[data-selected] {
|
|
43
|
+
background: var(--mx-color-accent-subtle);
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
import { reactive, type ComponentBase } from '@motifx/core';
|
|
49
|
+
import { Avatar, Button, Diagram, Stack, type DiagramEdge, type DiagramNode, type DiagramNodeKind } from '@motifx-community/ui';
|
|
50
|
+
|
|
51
|
+
/** A node of the app's own: `text` is the person's name, on the card and to a screen reader, and `data` the rest. */
|
|
52
|
+
interface Person extends DiagramNode {
|
|
53
|
+
data: { role: string };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** What each card shows, by the node's content area: `update` copies the node's fields into it. */
|
|
57
|
+
const shown = new WeakMap<ComponentBase, { name: string; role: string }>();
|
|
58
|
+
|
|
59
|
+
/** A kind of node: a card made once per node, its look from a class of the app, written again on `refresh()`. */
|
|
60
|
+
const kinds: Record<string, DiagramNodeKind<Person>> = {
|
|
61
|
+
person: {
|
|
62
|
+
cssClass: 'org-person',
|
|
63
|
+
content: (context) => {
|
|
64
|
+
const card = reactive({ name: context.node.text ?? '', role: context.node.data.role });
|
|
65
|
+
shown.set(context.host, card);
|
|
66
|
+
return (
|
|
67
|
+
<Stack orientation="horizontal" gap="sm" align="center">
|
|
68
|
+
<Avatar name={() => card.name} tone="auto" size="sm" />
|
|
69
|
+
<Stack gap="xxs">
|
|
70
|
+
<strong>{() => card.name}</strong>
|
|
71
|
+
<small>{() => card.role}</small>
|
|
72
|
+
</Stack>
|
|
73
|
+
</Stack>
|
|
74
|
+
);
|
|
75
|
+
},
|
|
76
|
+
update: (context) => {
|
|
77
|
+
const card = shown.get(context.host)!;
|
|
78
|
+
card.name = context.node.text ?? '';
|
|
79
|
+
card.role = context.node.data.role;
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export default function CustomFirst() {
|
|
85
|
+
const nodes: Person[] = [
|
|
86
|
+
{ id: 'ada', x: 0, y: 70, kind: 'person', text: 'Ada Lovelace', data: { role: 'Head of engineering' } },
|
|
87
|
+
{ id: 'grace', x: 300, y: 0, kind: 'person', text: 'Grace Hopper', data: { role: 'Compilers' } },
|
|
88
|
+
{ id: 'alan', x: 300, y: 140, kind: 'person', text: 'Alan Turing', data: { role: 'Research' } },
|
|
89
|
+
];
|
|
90
|
+
const edges: DiagramEdge[] = [
|
|
91
|
+
{ id: 'a', source: 'ada', target: 'grace' },
|
|
92
|
+
{ id: 'b', source: 'ada', target: 'alan' },
|
|
93
|
+
];
|
|
94
|
+
let diagram!: Diagram<Person>;
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<Stack gap="md" class="docs-wide">
|
|
98
|
+
<Stack orientation="horizontal" gap="sm" wrap>
|
|
99
|
+
<Button
|
|
100
|
+
text="Promote Alan"
|
|
101
|
+
variant="outline"
|
|
102
|
+
onclick={() => {
|
|
103
|
+
// Plain data changed in code: `refresh()` draws the node again, and `update` writes it.
|
|
104
|
+
nodes[2].data.role = 'Head of research';
|
|
105
|
+
diagram.refresh();
|
|
106
|
+
}}
|
|
107
|
+
/>
|
|
108
|
+
</Stack>
|
|
109
|
+
<Diagram ref={(d: Diagram<Person>) => (diagram = d)} label="Team" nodes={nodes} edges={edges} kinds={kinds} autoFit />
|
|
110
|
+
</Stack>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Data that changes
|
|
116
|
+
|
|
117
|
+
Data the app changes in code, as it comes from a server, is written by the kind’s `update`. The diagram calls it whenever it draws the node again: after `refresh()`, `reState()`, an undo or a resize. Keep what the content shows in a reactive object of its own, and let `update` copy the node’s fields into it; the bindings write only what changed. Promote Alan in the team above works this way.
|
|
118
|
+
|
|
119
|
+
```tsx
|
|
120
|
+
const shown = new WeakMap<ComponentBase, { role: string }>();
|
|
121
|
+
|
|
122
|
+
person: {
|
|
123
|
+
content: (context) => {
|
|
124
|
+
const card = reactive({ role: context.node.data.role });
|
|
125
|
+
shown.set(context.host, card);
|
|
126
|
+
return <small>{() => card.role}</small>;
|
|
127
|
+
},
|
|
128
|
+
update: (context) => {
|
|
129
|
+
shown.get(context.host)!.role = context.node.data.role;
|
|
130
|
+
},
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Elsewhere, when the data comes:
|
|
134
|
+
nodes[2].data.role = 'Head of research';
|
|
135
|
+
diagram.refresh();
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Data the user changes inside the node is simplest as a reactive object: `reactive(context.node.data)` gives the same object for the same data each time, and what it is given is written to the node’s own `data`. The controls bind to it, and neither `update` nor `refresh()` is needed. Another part of the page shares the data the same way, with `reactive(node.data)`.
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
content: (context) => {
|
|
142
|
+
const d = reactive(context.node.data);
|
|
143
|
+
return <NumberBox label="In stock" min={0} x-model={() => d.stock} />;
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Keep `data` plain: numbers, texts, lists and objects. `save()`, the clipboard, duplicating and `load()` copy nodes through JSON, so a copy or a loaded node has plain data of its own, and its content makes its own reactive object. A function, a class instance or a component kept in `data` does not survive the copy.
|
|
148
|
+
|
|
149
|
+
## Controls inside a node
|
|
150
|
+
|
|
151
|
+
Any control of the kit goes inside a node. A press on a control belongs to the control, so the node does not move while the user clicks, types or flips a switch. The keys typed in a text field belong to the field: undo, select all, the clipboard and Delete work on its text, and the commands of the diagram wait until focus leaves it.
|
|
152
|
+
|
|
153
|
+
`context.dragHandle(part)` makes one part, such as a title bar, the only place a press drags the node from; elsewhere a press only selects it. `context.selected` tells whether the node is selected when its content is made or written, and `context.diagram` is the diagram, to call its methods.
|
|
154
|
+
|
|
155
|
+
```tsx
|
|
156
|
+
import { reactive } from '@motifx/core';
|
|
157
|
+
import { Badge, Button, Diagram, NumberBox, Stack, type DiagramEdge, type DiagramNode, type DiagramNodeKind } from '@motifx-community/ui';
|
|
158
|
+
|
|
159
|
+
/** A shelf of a store: plain data on the node, which `save()`, a copy and `load()` carry as it is. */
|
|
160
|
+
interface Shelf extends DiagramNode {
|
|
161
|
+
data: { stock: number; reorderAt: number };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Controls of the kit inside the nodes, bound to the node's own data through a reactive object, and a title bar that drags the node. */
|
|
165
|
+
const kinds: Record<string, DiagramNodeKind<Shelf>> = {
|
|
166
|
+
shelf: {
|
|
167
|
+
ports: [
|
|
168
|
+
{ id: 'in', side: 'left', direction: 'target' },
|
|
169
|
+
{ id: 'out', side: 'right', direction: 'source' },
|
|
170
|
+
],
|
|
171
|
+
content: (context) => {
|
|
172
|
+
// The same object for the same data, wherever it is asked for; what it is given is written to `data`.
|
|
173
|
+
const d = reactive(context.node.data);
|
|
174
|
+
return (
|
|
175
|
+
<Stack gap="sm">
|
|
176
|
+
<Stack orientation="horizontal" justify="space-between" align="center" ref={(head: Stack) => context.dragHandle(head)}>
|
|
177
|
+
<strong>{context.node.text}</strong>
|
|
178
|
+
<Badge count={() => d.stock} showZero variant="subtle" tone={() => (d.stock < d.reorderAt ? 'danger' : 'success')} />
|
|
179
|
+
</Stack>
|
|
180
|
+
<NumberBox label="In stock" min={0} x-model={() => d.stock} />
|
|
181
|
+
<Button text="Sell one" size="sm" disabled={() => d.stock === 0} onclick={() => d.stock--} />
|
|
182
|
+
</Stack>
|
|
183
|
+
);
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
export default function CustomControls() {
|
|
189
|
+
const s = reactive({ saved: '' });
|
|
190
|
+
const shelf = (id: string, x: number, text: string, stock: number): Shelf => ({ id, x, y: 0, kind: 'shelf', text, width: 200, data: { stock, reorderAt: 5 } });
|
|
191
|
+
const nodes: Shelf[] = [shelf('back', 0, 'Back room', 40), shelf('front', 300, 'Front shelf', 6)];
|
|
192
|
+
const edges: DiagramEdge[] = [{ id: 'a', source: 'back', sourcePort: 'out', target: 'front', targetPort: 'in' }];
|
|
193
|
+
let diagram!: Diagram<Shelf>;
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
<Stack gap="md" class="docs-wide">
|
|
197
|
+
<Diagram ref={(d: Diagram<Shelf>) => (diagram = d)} label="Store shelves" nodes={nodes} edges={edges} kinds={kinds} autoFit />
|
|
198
|
+
<Stack orientation="horizontal" gap="sm" wrap align="center">
|
|
199
|
+
<Button text="Show the saved data" variant="outline" onclick={() => (s.saved = JSON.stringify(diagram.save().nodes.map((n) => ({ id: n.id, ...n.data }))))} />
|
|
200
|
+
<small>Sell from a shelf, type a number, or select a shelf and press Ctrl+D: the copy has data of its own.</small>
|
|
201
|
+
</Stack>
|
|
202
|
+
<output x-wait={() => !s.saved}>{() => s.saved}</output>
|
|
203
|
+
</Stack>
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Ports
|
|
209
|
+
|
|
210
|
+
A kind gives its nodes their ports in `ports`: a list for every node of the kind, or a function that makes them from the node, read again whenever the node is drawn. A port has an `id`, a `side` or several, an `offset` along the side, a `direction` (`source` starts connections, `target` ends them, `both` does both), a `type` that joins only ports of the same type, and `maxConnections`. A node’s own `ports` take the place of its kind’s.
|
|
211
|
+
|
|
212
|
+
`context.anchor(id, part)` stands a port beside a part of the content, such as a row of a list, and keeps it there as the content changes; `null` gives the port back to its `offset`. In the switch below each case is a row with a port of its own: Add a case adds a case to the data and calls `refresh()`, which reads the ports again.
|
|
213
|
+
|
|
214
|
+
```tsx
|
|
215
|
+
import { reactive, type ComponentBase } from '@motifx/core';
|
|
216
|
+
import { Button, Diagram, Stack, type DiagramEdge, type DiagramNode, type DiagramNodeKind } from '@motifx-community/ui';
|
|
217
|
+
|
|
218
|
+
/** A node of a flow: a switch carries its cases in `data`, and has a port for each. */
|
|
219
|
+
interface FlowNode extends DiagramNode {
|
|
220
|
+
data?: { cases: { id: string; text: string }[] };
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** Ports a function makes from the node, each standing beside the row of its case. */
|
|
224
|
+
const kinds: Record<string, DiagramNodeKind<FlowNode>> = {
|
|
225
|
+
switch: {
|
|
226
|
+
// Read again whenever the node is drawn: after `refresh()`, a case added has its port.
|
|
227
|
+
ports: (node) => [{ id: 'in', side: 'left', direction: 'target' }, ...(node.data?.cases ?? []).map((c) => ({ id: c.id, side: 'right' as const, direction: 'source' as const }))],
|
|
228
|
+
content: (context) => {
|
|
229
|
+
const d = reactive(context.node.data!);
|
|
230
|
+
return (
|
|
231
|
+
<Stack gap="xs">
|
|
232
|
+
<strong ref={(head: ComponentBase) => context.dragHandle(head)}>{context.node.text}</strong>
|
|
233
|
+
{d.cases.map((c) => (
|
|
234
|
+
<div key={c.id} ref={(row: ComponentBase) => context.anchor(c.id, row)}>
|
|
235
|
+
{c.text}
|
|
236
|
+
</div>
|
|
237
|
+
))}
|
|
238
|
+
</Stack>
|
|
239
|
+
);
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export default function CustomPorts() {
|
|
245
|
+
const nodes: FlowNode[] = [
|
|
246
|
+
{ id: 'pay', x: 0, y: 40, kind: 'switch', text: 'Payment', data: { cases: [{ id: 'card', text: 'Card' }, { id: 'transfer', text: 'Bank transfer' }] } },
|
|
247
|
+
{ id: 'charge', x: 320, y: 0, text: 'Charge the card' },
|
|
248
|
+
{ id: 'wait', x: 320, y: 110, text: 'Wait for the transfer' },
|
|
249
|
+
];
|
|
250
|
+
const edges: DiagramEdge[] = [
|
|
251
|
+
{ id: 'a', source: 'pay', sourcePort: 'card', target: 'charge' },
|
|
252
|
+
{ id: 'b', source: 'pay', sourcePort: 'transfer', target: 'wait' },
|
|
253
|
+
];
|
|
254
|
+
const pay = reactive(nodes[0].data!);
|
|
255
|
+
let diagram!: Diagram<FlowNode>;
|
|
256
|
+
|
|
257
|
+
return (
|
|
258
|
+
<Stack gap="md" class="docs-wide">
|
|
259
|
+
<Stack orientation="horizontal" gap="sm" wrap>
|
|
260
|
+
<Button
|
|
261
|
+
text="Add a case"
|
|
262
|
+
variant="outline"
|
|
263
|
+
disabled={() => pay.cases.length >= 5}
|
|
264
|
+
onclick={() => {
|
|
265
|
+
const n = pay.cases.length + 1;
|
|
266
|
+
pay.cases.push({ id: `case-${n}`, text: `Case ${n}` });
|
|
267
|
+
diagram.refresh();
|
|
268
|
+
}}
|
|
269
|
+
/>
|
|
270
|
+
</Stack>
|
|
271
|
+
<Diagram ref={(d: Diagram<FlowNode>) => (diagram = d)} label="Payment flow" nodes={nodes} edges={edges} kinds={kinds} autoFit />
|
|
272
|
+
</Stack>
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## Size, resizing and groups
|
|
278
|
+
|
|
279
|
+
Without `width` and `height` a node takes the size of its content; with them it keeps that size. A kind with `resizable` lets the user resize its nodes by the handles of a selected node, no smaller than `minWidth` and `minHeight`, and `update` runs after each resize. A kind with `group` holds other nodes, and one with `collapsible` collapses to its header, as the built-in kinds in [Groups, lanes and notes](diagram-nodes.md#groups) do. A kind of the app’s own with the name of a built-in one takes its place.
|
|
280
|
+
|
|
281
|
+
## Content made in code
|
|
282
|
+
|
|
283
|
+
Without JSX, `content` makes the content in code: it returns a control of the kit, or adds controls to `context.host.controls` and returns nothing. A property of a control takes a function, which keeps it bound to reactive data, as in JSX.
|
|
284
|
+
|
|
285
|
+
```tsx
|
|
286
|
+
import { Component, reactive } from '@motifx/core';
|
|
287
|
+
import { Avatar, Badge, Button, Diagram, Stack, type DiagramEdge, type DiagramNode, type DiagramNodeKind } from '@motifx-community/ui';
|
|
288
|
+
|
|
289
|
+
/** A worker of a queue: `text` is its name, `data` how many jobs it ran. */
|
|
290
|
+
interface Worker extends DiagramNode {
|
|
291
|
+
data: { jobs: number };
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** The content of a kind made in code, without JSX: controls of the kit, their properties bound to the node's data with functions. */
|
|
295
|
+
const kinds: Record<string, DiagramNodeKind<Worker>> = {
|
|
296
|
+
worker: {
|
|
297
|
+
content: (context) => {
|
|
298
|
+
const d = reactive(context.node.data);
|
|
299
|
+
const row = new Stack({ orientation: 'horizontal', gap: 'sm', align: 'center' });
|
|
300
|
+
row.controls.add(
|
|
301
|
+
new Avatar({ name: context.node.text ?? '', tone: 'auto', size: 'sm' }),
|
|
302
|
+
new Badge({ count: () => d.jobs, showZero: true, variant: 'subtle' }),
|
|
303
|
+
new Button({ text: 'Run a job', size: 'sm', variant: 'outline', onclick: () => d.jobs++ }),
|
|
304
|
+
);
|
|
305
|
+
// Added to the content area, nothing is returned; returning `row` does the same.
|
|
306
|
+
context.host.controls.add(row);
|
|
307
|
+
},
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
export default class CustomInCode extends Component<HTMLDivElement> {
|
|
312
|
+
constructor() {
|
|
313
|
+
super('div');
|
|
314
|
+
this.class.add('docs-wide');
|
|
315
|
+
const worker = (id: string, x: number, y: number, text: string): Worker => ({ id, x, y, kind: 'worker', text, data: { jobs: 0 } });
|
|
316
|
+
const nodes: Worker[] = [worker('north', 0, 0, 'North worker'), worker('south', 0, 110, 'South worker')];
|
|
317
|
+
const edges: DiagramEdge[] = [{ id: 'a', source: 'north', target: 'south', dashed: true }];
|
|
318
|
+
this.controls.add(new Diagram<Worker>({ label: 'Queue workers', nodes, edges, kinds, autoFit: true }));
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
## Feedback
|
|
324
|
+
|
|
325
|
+
Loading issues…
|