@reeve-iot/workflow-mui 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +68 -2
- package/dist/canvas/BlockNode.d.ts +30 -0
- package/dist/canvas/BlockNode.js +211 -0
- package/dist/canvas/Connection.d.ts +10 -0
- package/dist/canvas/Connection.js +22 -0
- package/dist/canvas/WorkflowCanvas.d.ts +16 -0
- package/dist/canvas/WorkflowCanvas.js +258 -0
- package/dist/canvas/analysedPortTerm.d.ts +6 -0
- package/dist/canvas/analysedPortTerm.js +17 -0
- package/dist/canvas/geometry.d.ts +14 -0
- package/dist/canvas/geometry.js +16 -0
- package/dist/canvas/graphTopology.d.ts +12 -0
- package/dist/canvas/graphTopology.js +32 -0
- package/dist/canvas/highlights.d.ts +12 -0
- package/dist/canvas/highlights.js +1 -0
- package/dist/canvas/nodePorts.d.ts +19 -0
- package/dist/canvas/nodePorts.js +28 -0
- package/dist/canvas/portCustomization.d.ts +21 -0
- package/dist/canvas/portCustomization.js +6 -0
- package/dist/canvas/portGeometry.d.ts +3 -0
- package/dist/canvas/portGeometry.js +3 -0
- package/dist/canvas/portLabelLayout.d.ts +9 -0
- package/dist/canvas/portLabelLayout.js +47 -0
- package/dist/canvas/unavailableBlock.d.ts +15 -0
- package/dist/canvas/unavailableBlock.js +9 -0
- package/dist/config/ErrorHandlingSection.d.ts +12 -0
- package/dist/config/ErrorHandlingSection.js +55 -0
- package/dist/config/NodeConfigPanel.d.ts +19 -0
- package/dist/config/NodeConfigPanel.js +246 -0
- package/dist/config/PassthroughSection.d.ts +18 -0
- package/dist/config/PassthroughSection.js +37 -0
- package/dist/config/ResiliencySection.d.ts +17 -0
- package/dist/config/ResiliencySection.js +156 -0
- package/dist/config/TypeArgumentPicker.d.ts +6 -0
- package/dist/config/TypeArgumentPicker.js +31 -0
- package/dist/config/nodeConfigCustomization.d.ts +100 -0
- package/dist/config/nodeConfigCustomization.js +6 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +26 -0
- package/dist/mapping/MappingDialog.d.ts +10 -0
- package/dist/mapping/MappingDialog.js +282 -0
- package/dist/mapping/mappingCustomization.d.ts +50 -0
- package/dist/mapping/mappingCustomization.js +8 -0
- package/dist/mapping/wireSourceOutputs.d.ts +29 -0
- package/dist/mapping/wireSourceOutputs.js +67 -0
- package/dist/nameDraft.d.ts +23 -0
- package/dist/nameDraft.js +19 -0
- package/dist/navigation/SubCanvasBreadcrumb.d.ts +7 -0
- package/dist/navigation/SubCanvasBreadcrumb.js +30 -0
- package/dist/palette/BlockPalette.d.ts +17 -0
- package/dist/palette/BlockPalette.js +55 -0
- package/dist/ports/KeyValueRowsField.d.ts +34 -0
- package/dist/ports/KeyValueRowsField.js +111 -0
- package/dist/ports/PortDeclarationTable.d.ts +18 -0
- package/dist/ports/PortDeclarationTable.js +111 -0
- package/dist/ports/PortValueEditor.d.ts +69 -0
- package/dist/ports/PortValueEditor.js +168 -0
- package/dist/ports/collectionComposer.d.ts +26 -0
- package/dist/ports/collectionComposer.js +37 -0
- package/dist/ports/refusedLiteral.d.ts +9 -0
- package/dist/ports/refusedLiteral.js +10 -0
- package/dist/ports/writeTerm.d.ts +5 -0
- package/dist/ports/writeTerm.js +10 -0
- package/dist/settings/ConcurrencySection.d.ts +8 -0
- package/dist/settings/ConcurrencySection.js +31 -0
- package/dist/settings/ParameterDeclarationDialog.d.ts +35 -0
- package/dist/settings/ParameterDeclarationDialog.js +81 -0
- package/dist/settings/WorkflowExecutionSection.d.ts +14 -0
- package/dist/settings/WorkflowExecutionSection.js +222 -0
- package/dist/theme/editorColors.d.ts +29 -0
- package/dist/theme/editorColors.js +30 -0
- package/dist/validation/ValidationFindings.d.ts +27 -0
- package/dist/validation/ValidationFindings.js +39 -0
- package/package.json +55 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Reeve Workflow Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,69 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @reeve-iot/workflow-mui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The Material UI editor for Reeve Workflow: canvas, block nodes, palette and configuration panels over
|
|
4
|
+
[`@reeve-iot/workflow-core`](https://github.com/reeve-iot/reeve-workflow/tree/main/packages/core). Part of [Reeve Workflow](https://github.com/reeve-iot/reeve-workflow).
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install @reeve-iot/workflow-mui
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Peer dependencies: `react` and `react-dom` (18 or 19), `@mui/material` and `@mui/icons-material` 9, `@emotion/react`
|
|
13
|
+
and `@emotion/styled` 11.
|
|
14
|
+
|
|
15
|
+
This package depends on `core` and re-exports it, so one dependency is enough. To style the editor yourself, depend
|
|
16
|
+
on `@reeve-iot/workflow-core` directly and MUI never enters your bundle.
|
|
17
|
+
|
|
18
|
+
## What it contains
|
|
19
|
+
|
|
20
|
+
The workflow canvas, block nodes, the block palette, the node configuration panel (with Resiliency, Error Handling,
|
|
21
|
+
Passthrough and Type Arguments sections), `WorkflowExecutionSection` for a workflow's deadline, retry and checkpoint
|
|
22
|
+
policy, `ConcurrencySection` for its concurrency mode and queue, the mapping dialog, port value editors, navigation
|
|
23
|
+
and validation display. Every component reads and writes through the editor store of `core`; none fetches. To load and
|
|
24
|
+
save over HTTP, add
|
|
25
|
+
[`@reeve-iot/workflow-client`](https://github.com/reeve-iot/reeve-workflow/tree/main/packages/client) and
|
|
26
|
+
[`@reeve-iot/workflow-adapters`](https://github.com/reeve-iot/reeve-workflow/tree/main/packages/adapters).
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
Components render inside `WorkflowEditorStoreProvider`:
|
|
31
|
+
|
|
32
|
+
```tsx
|
|
33
|
+
import { WorkflowCanvas, WorkflowEditorStoreProvider, type PortTypeRegistry } from '@reeve-iot/workflow-mui'
|
|
34
|
+
|
|
35
|
+
export function Editor({ portTypes }: { portTypes: PortTypeRegistry }) {
|
|
36
|
+
return (
|
|
37
|
+
<WorkflowEditorStoreProvider options={{ portTypes }}>
|
|
38
|
+
<WorkflowCanvas onCanvasClick={() => undefined} />
|
|
39
|
+
</WorkflowEditorStoreProvider>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Customising
|
|
45
|
+
|
|
46
|
+
A host reaches into the editor through React contexts. Without a provider each one is empty and the editor draws only
|
|
47
|
+
what the block catalogue declares.
|
|
48
|
+
|
|
49
|
+
| Context | What the host supplies |
|
|
50
|
+
|---|---|
|
|
51
|
+
| `NodeConfigCustomizationContext` | Renderers for configuration fields, extra sections in the configuration panel, a type-argument picker and a control for `Json` expressions. |
|
|
52
|
+
| `NodePortCustomizationContext` | Ports to hide, input types that depend on the node's configuration, and ports discovered at runtime. |
|
|
53
|
+
| `MappingCustomizationContext` | The projection control in the mapping dialog. |
|
|
54
|
+
| `EditorColorsContext` | Literal colours for the canvas. By default `deriveEditorColors(theme)` builds them from the active MUI theme; a theme in MUI's CSS-variables mode needs literal colours here, because the canvas paints with SVG attributes that do not resolve `var(--…)`. |
|
|
55
|
+
|
|
56
|
+
### Validation findings
|
|
57
|
+
|
|
58
|
+
The `ValidationFindings` component displays editor findings and warnings, or the diagnostics a publish attempt
|
|
59
|
+
returned. It must be rendered inside `WorkflowEditorStoreProvider`. It renders through `validationMessage` with the
|
|
60
|
+
`validationMessages` catalogue given to the provider; its `catalogue` prop overrides that for one list. A code the
|
|
61
|
+
library has no template for, a host rule's code without a translation, and a publish diagnostic whose code's template
|
|
62
|
+
reads params show the finding's own `message`. Every row carries `data-code`; a row that names a node opens that
|
|
63
|
+
node's canvas and selects it, then calls `onSelectNode`.
|
|
64
|
+
|
|
65
|
+
See the [validation findings guide](https://github.com/reeve-iot/reeve-workflow/blob/main/docs/reference/validation-findings.md) for an end-to-end example.
|
|
66
|
+
|
|
67
|
+
## Licence
|
|
68
|
+
|
|
69
|
+
MIT.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { MouseEvent as ReactMouseEvent } from 'react';
|
|
2
|
+
import type { WorkflowNode } from '@reeve-iot/workflow-core';
|
|
3
|
+
import type { NodeDiffKind, NodeHighlight } from './highlights.js';
|
|
4
|
+
import type { DescribeUnavailableBlock } from './unavailableBlock.js';
|
|
5
|
+
/** The virtual output a node grows under the EmitError policy, core's ERROR_OUTPUT_NAME. */
|
|
6
|
+
export declare const ERROR_PORT_NAME = "_error";
|
|
7
|
+
export interface BlockNodeProps {
|
|
8
|
+
node: WorkflowNode;
|
|
9
|
+
isSelected: boolean;
|
|
10
|
+
isConnecting: boolean;
|
|
11
|
+
/** Every callback names the node, so a canvas can pass one stable handler to all of its nodes. */
|
|
12
|
+
onDragStart: (event: ReactMouseEvent, nodeId: string) => void;
|
|
13
|
+
onConnectionStart: (nodeId: string, x: number, y: number) => void;
|
|
14
|
+
onConnectionEnd: (nodeId: string) => void;
|
|
15
|
+
onSelect: (nodeId: string) => void;
|
|
16
|
+
highlight?: NodeHighlight;
|
|
17
|
+
diffHighlight?: NodeDiffKind;
|
|
18
|
+
readOnly?: boolean;
|
|
19
|
+
isBreakpoint?: boolean;
|
|
20
|
+
isPausedHere?: boolean;
|
|
21
|
+
/** Draws a transient ring, for locating the block a validation finding points at. */
|
|
22
|
+
isFlashing?: boolean;
|
|
23
|
+
/** Bumped per request so the pulse replays when the same node is asked for twice. */
|
|
24
|
+
flashKey?: number;
|
|
25
|
+
entryNodeLabel?: string;
|
|
26
|
+
exitNodeLabel?: string;
|
|
27
|
+
/** The host's wording for a node whose block type is not in the catalogue, drawn as a placeholder in its place. */
|
|
28
|
+
describeUnavailableBlock?: DescribeUnavailableBlock;
|
|
29
|
+
}
|
|
30
|
+
export declare const BlockNode: import("react").MemoExoticComponent<({ node, isSelected, isConnecting, onDragStart, onConnectionStart, onConnectionEnd, onSelect, highlight, diffHighlight, readOnly, isBreakpoint, isPausedHere, isFlashing, flashKey, entryNodeLabel, exitNodeLabel, describeUnavailableBlock, }: BlockNodeProps) => import("react").JSX.Element>;
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { memo, useId, useMemo } from 'react';
|
|
3
|
+
import { ERROR_OUTPUT_NAME, ERROR_OUTPUT_TYPE, WORKFLOW_INPUT_BLOCK_TYPE_ID, WORKFLOW_OUTPUT_BLOCK_TYPE_ID, WORKFLOW_START_ANCHOR_PORT_NAME, declaredOutputTerm, addsErrorOutput, displayPortTerm, draftAnalysisFreshness, indexDraftAnalysis, parseDynamicPorts, readMapping, useWorkflowEditorStore, } from '@reeve-iot/workflow-core';
|
|
4
|
+
import { useEditorColors } from '../theme/editorColors.js';
|
|
5
|
+
import { NODE_HEADER_HEIGHT, NODE_ITEM_HEIGHT, NODE_WIDTH } from './geometry.js';
|
|
6
|
+
import { PORT_RADIUS, PORT_STROKE_WIDTH } from './portGeometry.js';
|
|
7
|
+
import { PORT_LABEL_FONT_SIZE, PORT_LABEL_INSET, layoutPortLabelRow } from './portLabelLayout.js';
|
|
8
|
+
import { useNodePorts } from './nodePorts.js';
|
|
9
|
+
import { useGraphTopology } from './graphTopology.js';
|
|
10
|
+
import { unavailableBlockText } from './unavailableBlock.js';
|
|
11
|
+
const BUTTON_HEIGHT = 28;
|
|
12
|
+
const BUTTON_GAP = 4;
|
|
13
|
+
const BUTTONS_PADDING_TOP = 8;
|
|
14
|
+
const typeSuffix = (display) => (display === undefined ? '' : ` (${display.text})`);
|
|
15
|
+
/** The virtual output a node grows under the EmitError policy, core's ERROR_OUTPUT_NAME. */
|
|
16
|
+
export const ERROR_PORT_NAME = ERROR_OUTPUT_NAME;
|
|
17
|
+
export const BlockNode = memo(function BlockNode({ node, isSelected, isConnecting, onDragStart, onConnectionStart, onConnectionEnd, onSelect, highlight, diffHighlight, readOnly, isBreakpoint, isPausedHere, isFlashing, flashKey, entryNodeLabel = 'Workflow Input', exitNodeLabel = 'Workflow Output', describeUnavailableBlock, }) {
|
|
18
|
+
const c = useEditorColors();
|
|
19
|
+
const clipId = useId().replace(/[^A-Za-z0-9_-]/g, '');
|
|
20
|
+
const { canvasStack, edges } = useGraphTopology();
|
|
21
|
+
const blockTypes = useWorkflowEditorStore((s) => s.blockTypes);
|
|
22
|
+
const workflowInputParams = useWorkflowEditorStore((s) => s.workflowInputParams);
|
|
23
|
+
const workflowOutputParams = useWorkflowEditorStore((s) => s.workflowOutputParams);
|
|
24
|
+
const enterSubCanvas = useWorkflowEditorStore((s) => s.enterSubCanvas);
|
|
25
|
+
const analysis = useWorkflowEditorStore((s) => s.analysis);
|
|
26
|
+
const revision = useWorkflowEditorStore((s) => s.revision);
|
|
27
|
+
const isEntry = node.blockTypeId === WORKFLOW_INPUT_BLOCK_TYPE_ID;
|
|
28
|
+
const isExit = node.blockTypeId === WORKFLOW_OUTPUT_BLOCK_TYPE_ID;
|
|
29
|
+
const isSynthetic = isEntry || isExit;
|
|
30
|
+
const blockType = useMemo(() => (isSynthetic ? undefined : blockTypes.find((bt) => bt.blockTypeId === node.blockTypeId)), [blockTypes, node.blockTypeId, isSynthetic]);
|
|
31
|
+
const hostPorts = useNodePorts(node, blockType);
|
|
32
|
+
const analysisIndex = useMemo(() => indexDraftAnalysis(analysis), [analysis]);
|
|
33
|
+
const freshness = draftAnalysisFreshness(analysis, revision);
|
|
34
|
+
const canvasPath = useMemo(() => canvasStack.map((f) => ({ nodeId: f.parentNodeId, branchName: f.subCanvasName })), [canvasStack]);
|
|
35
|
+
const termOf = (side, port) => {
|
|
36
|
+
const analysed = analysisIndex.port(canvasPath, node.id, side, port.name);
|
|
37
|
+
return displayPortTerm(port.type ?? analysed?.declared, analysed, freshness, analysisIndex.findings(canvasPath, node.id, port.name));
|
|
38
|
+
};
|
|
39
|
+
const termAttributes = (display) => display === undefined ? {} : {
|
|
40
|
+
'data-term-knowledge': display.knowledge,
|
|
41
|
+
'data-analysis': display.knowledge === 'declared' ? 'none' : display.stale ? 'stale' : 'current',
|
|
42
|
+
};
|
|
43
|
+
let inputs = [];
|
|
44
|
+
let outputs = [];
|
|
45
|
+
const unavailable = !isSynthetic && blockType === undefined ? unavailableBlockText(node, describeUnavailableBlock) : undefined;
|
|
46
|
+
if (isSynthetic) {
|
|
47
|
+
const frame = canvasStack[canvasStack.length - 1];
|
|
48
|
+
if (!frame) {
|
|
49
|
+
const params = isEntry ? workflowInputParams : workflowOutputParams;
|
|
50
|
+
const ports = params.map((p) => ({ name: p.name, displayName: p.displayName, isRequired: isEntry ? false : p.isRequired, type: p.type }));
|
|
51
|
+
if (isEntry)
|
|
52
|
+
outputs = ports;
|
|
53
|
+
else
|
|
54
|
+
inputs = ports;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
const parentNode = frame.nodes.find((n) => n.id === frame.parentNodeId);
|
|
58
|
+
const parentBlockType = blockTypes.find((bt) => bt.blockTypeId === parentNode?.blockTypeId);
|
|
59
|
+
if (parentBlockType) {
|
|
60
|
+
if (isEntry) {
|
|
61
|
+
const declared = parentBlockType.subCanvasInputs?.[frame.subCanvasName] ?? [];
|
|
62
|
+
const ownerInputs = parentBlockType.hasDynamicPorts && parentNode
|
|
63
|
+
? parseDynamicPorts(parentNode.configuration['InputPorts'])
|
|
64
|
+
: (parentBlockType.inputs ?? []);
|
|
65
|
+
const forwarded = (parentNode?.passthrough ?? [])
|
|
66
|
+
.filter((name) => !declared.some((p) => p.name === name))
|
|
67
|
+
.map((name) => ({ name, displayName: name, isRequired: false, type: ownerInputs.find((i) => i.name === name)?.type }));
|
|
68
|
+
outputs = [...declared, ...forwarded].map((p) => ({ name: p.name, displayName: p.displayName, isRequired: p.isRequired, type: p.type }));
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const declared = (parentBlockType.subCanvasOutputs?.[frame.subCanvasName] ?? []).map((p) => ({
|
|
72
|
+
name: p.name, displayName: p.displayName, isRequired: p.isRequired, type: p.type,
|
|
73
|
+
}));
|
|
74
|
+
const fromParent = new Map();
|
|
75
|
+
for (const port of parentNode?.outputPorts ?? []) {
|
|
76
|
+
const sourceKey = port.sources?.[frame.subCanvasName];
|
|
77
|
+
if (!sourceKey)
|
|
78
|
+
continue;
|
|
79
|
+
if (declared.some((d) => d.name === sourceKey))
|
|
80
|
+
continue;
|
|
81
|
+
if (!fromParent.has(sourceKey)) {
|
|
82
|
+
fromParent.set(sourceKey, { name: sourceKey, displayName: sourceKey, isRequired: false, type: port.type });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
inputs = [...declared, ...fromParent.values()];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (isEntry && outputs.length === 0) {
|
|
90
|
+
outputs = [{ name: WORKFLOW_START_ANCHOR_PORT_NAME, displayName: 'Start', isRequired: false, type: 'Flow' }];
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else if (blockType) {
|
|
94
|
+
const declaredInputs = (blockType.hasDynamicPorts
|
|
95
|
+
? parseDynamicPorts(node.configuration['InputPorts'])
|
|
96
|
+
: (blockType.inputs ?? []).map((i) => ({ name: i.name, displayName: i.displayName, isRequired: i.isRequired, type: i.type })))
|
|
97
|
+
.filter((i) => !hostPorts.isInputHidden(i.name))
|
|
98
|
+
.map((i) => ({ ...i, type: hostPorts.inputType(i) }));
|
|
99
|
+
const staticOutputs = (blockType.outputs ?? []).map((o) => ({ name: o.name, displayName: o.displayName, isRequired: false, type: o.type }));
|
|
100
|
+
const declaredOutputs = (blockType.supportsDeclaredOutputs ? (node.outputPorts ?? []) : [])
|
|
101
|
+
.filter((p) => !staticOutputs.some((s) => s.name === p.name))
|
|
102
|
+
.map((p) => ({ name: p.name, displayName: p.displayName || p.name, isRequired: false, type: declaredOutputTerm(blockType, p) }));
|
|
103
|
+
const baseOutputs = blockType.hasDynamicPorts
|
|
104
|
+
? parseDynamicPorts(node.configuration['OutputPorts'])
|
|
105
|
+
: [...staticOutputs, ...declaredOutputs];
|
|
106
|
+
const extraInputs = hostPorts.hostInputs.filter((d) => !declaredInputs.some((i) => i.name === d.name));
|
|
107
|
+
const passthroughNames = node.passthrough ?? [];
|
|
108
|
+
const virtualInputs = passthroughNames
|
|
109
|
+
.filter((name) => !declaredInputs.some((i) => i.name === name) && !extraInputs.some((c) => c.name === name))
|
|
110
|
+
.map((name) => ({ name, displayName: name, isRequired: false }));
|
|
111
|
+
inputs = [...declaredInputs, ...extraInputs, ...virtualInputs];
|
|
112
|
+
const extraOutputs = hostPorts.hostOutputs.filter((d) => !baseOutputs.some((o) => o.name === d.name));
|
|
113
|
+
const showErrorPort = addsErrorOutput(node, [...baseOutputs, ...extraOutputs]);
|
|
114
|
+
const virtualOutputs = passthroughNames
|
|
115
|
+
.filter((name) => !baseOutputs.some((o) => o.name === name) && !extraOutputs.some((c) => c.name === name) && !(showErrorPort && name === ERROR_PORT_NAME))
|
|
116
|
+
.map((name) => {
|
|
117
|
+
const matching = inputs.find((i) => i.name === name);
|
|
118
|
+
return { name, displayName: matching?.displayName ?? name, isRequired: false, type: matching?.type };
|
|
119
|
+
});
|
|
120
|
+
const errorPort = showErrorPort ? [{ name: ERROR_PORT_NAME, displayName: 'Error', isRequired: false, type: ERROR_OUTPUT_TYPE }] : [];
|
|
121
|
+
outputs = [...baseOutputs, ...extraOutputs, ...virtualOutputs, ...errorPort];
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
const fed = new Set();
|
|
125
|
+
const offered = new Set();
|
|
126
|
+
for (const edge of edges) {
|
|
127
|
+
if (edge.targetNodeId === node.id)
|
|
128
|
+
for (const name of Object.keys(edge.mappings))
|
|
129
|
+
fed.add(name);
|
|
130
|
+
if (edge.sourceNodeId !== node.id)
|
|
131
|
+
continue;
|
|
132
|
+
for (const mapping of Object.values(edge.mappings)) {
|
|
133
|
+
const read = readMapping(mapping);
|
|
134
|
+
if (!read.literal && read.source !== '')
|
|
135
|
+
offered.add(read.source);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
inputs = [...fed].map((name) => ({ name, displayName: name, isRequired: false }));
|
|
139
|
+
outputs = [...offered].map((name) => ({ name, displayName: name, isRequired: false }));
|
|
140
|
+
}
|
|
141
|
+
const connectable = !readOnly && unavailable === undefined;
|
|
142
|
+
const inputTerms = inputs.map((port) => termOf('inputs', port));
|
|
143
|
+
const outputTerms = outputs.map((port) => termOf('outputs', port));
|
|
144
|
+
const inputLabels = inputs.map((port, index) => `${port.displayName}${port.isRequired ? '*' : ''}${typeSuffix(inputTerms[index])}`);
|
|
145
|
+
const outputLabels = outputs.map((port, index) => `${port.displayName}${typeSuffix(outputTerms[index])}`);
|
|
146
|
+
const labelRows = Array.from({ length: Math.max(inputs.length, outputs.length) }, (_, index) => layoutPortLabelRow(inputLabels[index], outputLabels[index], NODE_WIDTH));
|
|
147
|
+
const displayName = isEntry ? entryNodeLabel : isExit ? exitNodeLabel : (unavailable?.title ?? blockType?.displayName ?? '');
|
|
148
|
+
const subCanvasNames = isSynthetic ? [] : (blockType?.subCanvasNames ?? []);
|
|
149
|
+
const hasSubCanvases = subCanvasNames.length > 0;
|
|
150
|
+
const portsHeight = Math.max(1, Math.max(inputs.length, outputs.length)) * NODE_ITEM_HEIGHT + 8;
|
|
151
|
+
const buttonsHeight = hasSubCanvases
|
|
152
|
+
? BUTTONS_PADDING_TOP + subCanvasNames.length * BUTTON_HEIGHT + (subCanvasNames.length - 1) * BUTTON_GAP + 8
|
|
153
|
+
: 0;
|
|
154
|
+
const reasonHeight = unavailable === undefined ? 0 : NODE_ITEM_HEIGHT;
|
|
155
|
+
const nodeHeight = NODE_HEADER_HEIGHT + portsHeight + buttonsHeight + reasonHeight;
|
|
156
|
+
const portsEndY = NODE_HEADER_HEIGHT + portsHeight;
|
|
157
|
+
const headerColor = isSelected ? c.selected : isEntry ? c.headerInput : isExit ? c.headerOutput : c.nodeHeader;
|
|
158
|
+
const headerTextColor = isSelected || isSynthetic ? c.nodeFill : c.text;
|
|
159
|
+
const diffStroke = diffHighlight === 'added' ? c.ok : diffHighlight === 'removed' ? c.danger : diffHighlight === 'modified' ? c.warn : null;
|
|
160
|
+
const runStroke = highlight?.status === 'running' ? c.warn : highlight?.status === 'success' ? c.ok : highlight?.status === 'error' ? c.danger : null;
|
|
161
|
+
const outlineStroke = (isSelected ? c.selected : null) ?? diffStroke ?? runStroke ?? (unavailable ? c.danger : isEntry ? c.headerInput : isExit ? c.headerOutput : c.nodeStroke);
|
|
162
|
+
const outlineStrokeWidth = isSelected || highlight?.status || diffHighlight ? 2 : isSynthetic || unavailable ? 2 : 1;
|
|
163
|
+
const tooltip = [
|
|
164
|
+
unavailable?.reason ?? null,
|
|
165
|
+
highlight?.inputsJson ? `Inputs:\n${highlight.inputsJson}` : null,
|
|
166
|
+
highlight?.outputsJson ? `Outputs:\n${highlight.outputsJson}` : null,
|
|
167
|
+
]
|
|
168
|
+
.filter(Boolean)
|
|
169
|
+
.join('\n\n');
|
|
170
|
+
const labelHint = (label, display) => [[label, ...(display?.findings ?? [])].join('\n'), tooltip].filter(Boolean).join('\n\n');
|
|
171
|
+
const portY = (index) => NODE_HEADER_HEIGHT + (index + 0.5) * NODE_ITEM_HEIGHT + 4;
|
|
172
|
+
const bodyPointer = {
|
|
173
|
+
onClick: (event) => {
|
|
174
|
+
event.stopPropagation();
|
|
175
|
+
onSelect(node.id);
|
|
176
|
+
},
|
|
177
|
+
onMouseDown: (event) => {
|
|
178
|
+
if (event.button !== 0)
|
|
179
|
+
return;
|
|
180
|
+
event.preventDefault();
|
|
181
|
+
onDragStart(event, node.id);
|
|
182
|
+
},
|
|
183
|
+
onMouseUp: (event) => {
|
|
184
|
+
if (isConnecting && unavailable === undefined) {
|
|
185
|
+
event.stopPropagation();
|
|
186
|
+
onConnectionEnd(node.id);
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
return (_jsxs("g", { transform: `translate(${node.position.x}, ${node.position.y})`, "data-testid": `workflow-node-${node.blockTypeId}`, "data-node-id": node.id, "data-unavailable": unavailable ? 'true' : undefined, children: [tooltip && _jsx("title", { children: tooltip }), _jsxs("defs", { children: [labelRows.slice(0, inputs.length).map((row, index) => (_jsx("clipPath", { id: `port-in-clip-${clipId}-${index}`, children: _jsx("rect", { x: 0, y: 0, width: row.inputEnd, height: nodeHeight }) }, `in-${index}`))), _jsx("clipPath", { id: `node-clip-${clipId}`, children: _jsx("rect", { x: 0, y: 0, width: NODE_WIDTH - 12, height: nodeHeight }) }), labelRows.slice(0, outputs.length).map((row, index) => (_jsx("clipPath", { id: `port-out-clip-${clipId}-${index}`, children: _jsx("rect", { x: row.outputStart, y: 0, width: NODE_WIDTH - row.outputStart, height: nodeHeight }) }, `out-${index}`)))] }), _jsx("rect", { "data-testid": `workflow-node-body-${node.id}`, width: NODE_WIDTH, height: nodeHeight, rx: 8, ry: 8, fill: c.nodeFill, stroke: outlineStroke, strokeWidth: outlineStrokeWidth, strokeDasharray: unavailable ? '6 4' : undefined, ...bodyPointer, style: { cursor: 'grab' } }), isFlashing && (_jsx("rect", { "data-testid": "node-flash-ring", x: -5, y: -5, width: NODE_WIDTH + 10, height: nodeHeight + 10, rx: 12, ry: 12, fill: "none", stroke: c.info, strokeWidth: 3, pointerEvents: "none", children: _jsx("animate", { attributeName: "opacity", values: "0;1;0;1;0;1;0", dur: "1.1s", repeatCount: "1", fill: "freeze" }) }, flashKey)), _jsx("rect", { width: NODE_WIDTH, height: NODE_HEADER_HEIGHT, rx: 8, ry: 8, fill: headerColor, style: { pointerEvents: 'none' } }), _jsx("rect", { y: NODE_HEADER_HEIGHT - 8, width: NODE_WIDTH, height: 8, fill: headerColor, style: { pointerEvents: 'none' } }), _jsx("text", { x: 12, y: 26, fill: headerTextColor, style: { fontSize: 13, fontWeight: 'bold', pointerEvents: 'none' }, children: unavailable ? `⚠ ${displayName}` : displayName }), unavailable && (_jsx("text", { x: 12, y: portsEndY + buttonsHeight + NODE_ITEM_HEIGHT / 2 + 4, clipPath: `url(#node-clip-${clipId})`, "data-testid": `workflow-node-unavailable-${node.id}`, fill: c.danger, style: { fontSize: 11, pointerEvents: 'none' }, children: unavailable.reason })), hasSubCanvases && (_jsxs("g", { style: { pointerEvents: 'none' }, children: [_jsx("circle", { cx: NODE_WIDTH - 14, cy: 14, r: 10, fill: c.warn }), _jsx("text", { x: NODE_WIDTH - 14, y: 18, textAnchor: "middle", fill: c.nodeFill, style: { fontSize: 10, fontWeight: 'bold' }, children: "\u22A1" })] })), (isBreakpoint || isPausedHere) && (_jsx("circle", { cx: -6, cy: 14, r: 6, fill: isPausedHere ? c.warn : c.danger, stroke: c.nodeFill, strokeWidth: 1.5, style: { pointerEvents: 'none' }, "aria-label": isPausedHere ? 'Paused here' : 'Breakpoint' })), inputs.map((input, index) => (_jsxs("g", { children: [_jsx("circle", { cx: 0, cy: portY(index), r: PORT_RADIUS, "data-testid": `workflow-port-${node.id}-input-${input.name}`, "aria-label": `${displayName} input ${input.displayName}`, fill: c.nodeFill, stroke: isExit ? c.headerOutput : c.nodeStroke, strokeWidth: PORT_STROKE_WIDTH, onMouseUp: (event) => {
|
|
191
|
+
if (!connectable || !isConnecting || event.button !== 0)
|
|
192
|
+
return;
|
|
193
|
+
event.stopPropagation();
|
|
194
|
+
onConnectionEnd(node.id);
|
|
195
|
+
}, style: { cursor: 'crosshair' } }), _jsxs("g", { ...bodyPointer, style: { cursor: 'grab' }, children: [_jsx("title", { children: labelHint(inputLabels[index], inputTerms[index]) }), _jsx("text", { x: PORT_LABEL_INSET, y: portY(index) + 5, clipPath: `url(#port-in-clip-${clipId}-${index})`, "data-testid": `workflow-port-label-${node.id}-input-${input.name}`, ...termAttributes(inputTerms[index]), fill: inputTerms[index]?.knowledge === 'refused' ? c.danger : c.textDim, style: { fontSize: PORT_LABEL_FONT_SIZE, ...(inputTerms[index]?.stale === true ? { fontStyle: 'italic', opacity: 0.7 } : {}) }, children: inputLabels[index] })] })] }, input.name))), outputs.map((output, index) => {
|
|
196
|
+
const isErrorPort = output.name === ERROR_PORT_NAME;
|
|
197
|
+
return (_jsxs("g", { children: [_jsx("circle", { cx: NODE_WIDTH, cy: portY(index), r: PORT_RADIUS, "data-testid": `workflow-port-${node.id}-output-${output.name}`, "aria-label": `${displayName} output ${output.displayName}`, fill: c.nodeFill, stroke: isErrorPort ? c.danger : isEntry ? c.headerInput : c.nodeStroke, strokeWidth: PORT_STROKE_WIDTH, onMouseDown: (event) => {
|
|
198
|
+
if (!connectable || event.button !== 0)
|
|
199
|
+
return;
|
|
200
|
+
event.stopPropagation();
|
|
201
|
+
event.preventDefault();
|
|
202
|
+
onConnectionStart(node.id, node.position.x + NODE_WIDTH, node.position.y + portY(index));
|
|
203
|
+
}, style: { cursor: 'crosshair' } }), _jsxs("g", { ...bodyPointer, style: { cursor: 'grab' }, children: [_jsx("title", { children: labelHint(outputLabels[index], outputTerms[index]) }), _jsx("text", { x: NODE_WIDTH - PORT_LABEL_INSET, y: portY(index) + 5, textAnchor: "end", clipPath: `url(#port-out-clip-${clipId}-${index})`, "data-testid": `workflow-port-label-${node.id}-output-${output.name}`, ...termAttributes(outputTerms[index]), fill: isErrorPort || outputTerms[index]?.knowledge === 'refused' ? c.danger : c.textDim, style: { fontSize: PORT_LABEL_FONT_SIZE, ...(outputTerms[index]?.stale === true ? { fontStyle: 'italic', opacity: 0.7 } : {}) }, children: outputLabels[index] })] })] }, output.name));
|
|
204
|
+
}), hasSubCanvases && (_jsxs(_Fragment, { children: [_jsx("line", { x1: 8, y1: portsEndY, x2: NODE_WIDTH - 8, y2: portsEndY, stroke: c.nodeStroke, strokeWidth: 1, style: { pointerEvents: 'none' } }), subCanvasNames.map((canvasName, index) => {
|
|
205
|
+
const buttonY = portsEndY + BUTTONS_PADDING_TOP + index * (BUTTON_HEIGHT + BUTTON_GAP);
|
|
206
|
+
return (_jsxs("g", { style: { cursor: 'pointer' }, children: [_jsx("rect", { x: 8, y: buttonY, width: NODE_WIDTH - 16, height: BUTTON_HEIGHT, rx: 4, ry: 4, fill: c.infoBg, stroke: c.infoBorder, strokeWidth: 1, style: { pointerEvents: 'none' } }), _jsxs("text", { x: NODE_WIDTH / 2, y: buttonY + BUTTON_HEIGHT / 2 + 5, textAnchor: "middle", fill: c.info, style: { fontSize: 11, fontWeight: 500, pointerEvents: 'none' }, children: ["\u25B6 Enter: ", canvasName] }), _jsx("rect", { x: 8, y: buttonY, width: NODE_WIDTH - 16, height: BUTTON_HEIGHT, rx: 4, ry: 4, fill: "transparent", "data-subcanvas-entry": `${node.id}:${canvasName}`, onClick: (event) => {
|
|
207
|
+
event.stopPropagation();
|
|
208
|
+
enterSubCanvas(node.id, canvasName);
|
|
209
|
+
} })] }, canvasName));
|
|
210
|
+
})] }))] }));
|
|
211
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MouseEvent } from 'react';
|
|
2
|
+
import type { WorkflowEdge, WorkflowNode } from '@reeve-iot/workflow-core';
|
|
3
|
+
export interface ConnectionProps {
|
|
4
|
+
edge: WorkflowEdge;
|
|
5
|
+
nodes: WorkflowNode[];
|
|
6
|
+
isSelected: boolean;
|
|
7
|
+
onClick: (event: MouseEvent) => void;
|
|
8
|
+
}
|
|
9
|
+
/** One wire between two nodes, drawn as a horizontal cubic so it leaves and enters sideways. */
|
|
10
|
+
export declare function Connection({ edge, nodes, isSelected, onClick }: ConnectionProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { useEditorColors } from '../theme/editorColors.js';
|
|
4
|
+
import { NODE_WIDTH, portAnchorY } from './geometry.js';
|
|
5
|
+
const WIRE_HIT_WIDTH_PX = 18;
|
|
6
|
+
/** One wire between two nodes, drawn as a horizontal cubic so it leaves and enters sideways. */
|
|
7
|
+
export function Connection({ edge, nodes, isSelected, onClick }) {
|
|
8
|
+
const colors = useEditorColors();
|
|
9
|
+
const source = useMemo(() => nodes.find((n) => n.id === edge.sourceNodeId), [nodes, edge.sourceNodeId]);
|
|
10
|
+
const target = useMemo(() => nodes.find((n) => n.id === edge.targetNodeId), [nodes, edge.targetNodeId]);
|
|
11
|
+
const path = useMemo(() => {
|
|
12
|
+
if (!source || !target)
|
|
13
|
+
return '';
|
|
14
|
+
const sourceX = source.position.x + NODE_WIDTH;
|
|
15
|
+
const sourceY = portAnchorY(source.position.y);
|
|
16
|
+
const targetX = target.position.x;
|
|
17
|
+
const targetY = portAnchorY(target.position.y);
|
|
18
|
+
const dx = Math.abs(targetX - sourceX) * 0.5;
|
|
19
|
+
return `M ${sourceX} ${sourceY} C ${sourceX + dx} ${sourceY}, ${targetX - dx} ${targetY}, ${targetX} ${targetY}`;
|
|
20
|
+
}, [source, target]);
|
|
21
|
+
return (_jsxs("g", { onClick: onClick, "data-testid": `workflow-edge-${edge.sourceNodeId}-${edge.targetNodeId}`, style: { cursor: 'pointer' }, children: [_jsx("path", { d: path, fill: "none", stroke: isSelected ? colors.selected : colors.edge, strokeWidth: isSelected ? 4 : 2, pointerEvents: "visibleStroke" }), _jsx("path", { "data-testid": `workflow-edge-hit-${edge.sourceNodeId}-${edge.targetNodeId}`, d: path, fill: "none", stroke: "transparent", strokeWidth: WIRE_HIT_WIDTH_PX, vectorEffect: "non-scaling-stroke", pointerEvents: "stroke" })] }));
|
|
22
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DescribeUnavailableBlock } from './unavailableBlock.js';
|
|
2
|
+
import type { NodeDiffKind, NodeHighlight } from './highlights.js';
|
|
3
|
+
export interface WorkflowCanvasProps {
|
|
4
|
+
onCanvasClick: () => void;
|
|
5
|
+
highlights?: NodeHighlight[];
|
|
6
|
+
diffHighlights?: Record<string, NodeDiffKind>;
|
|
7
|
+
readOnly?: boolean;
|
|
8
|
+
/** Nodes a host debugger has a breakpoint on. */
|
|
9
|
+
breakpointNodeIds?: string[];
|
|
10
|
+
/** Node a host debugger is currently paused at. */
|
|
11
|
+
pausedNodeId?: string | null;
|
|
12
|
+
/** The host's wording for a node whose block type is not in the catalogue. Such a node is drawn as a placeholder, kept
|
|
13
|
+
* where it stands with its wires; without this the placeholder says the block type is not available on this host. */
|
|
14
|
+
describeUnavailableBlock?: DescribeUnavailableBlock;
|
|
15
|
+
}
|
|
16
|
+
export declare function WorkflowCanvas({ onCanvasClick, highlights, diffHighlights, readOnly, breakpointNodeIds, pausedNodeId, describeUnavailableBlock, }: WorkflowCanvasProps): import("react").JSX.Element;
|