@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
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { BlockConfigField, BlockPort, BlockTypeDescriptor, BlockTypeParameter, PortTypeName, VariableMapping, WorkflowNode } from '@reeve-iot/workflow-core';
|
|
3
|
+
/** One entry of a node's configuration map. */
|
|
4
|
+
export type NodeConfigurationValue = WorkflowNode['configuration'][string];
|
|
5
|
+
/** What a host renderer is told about the configuration field it is being offered. */
|
|
6
|
+
export interface ConfigFieldContext {
|
|
7
|
+
node: WorkflowNode;
|
|
8
|
+
blockType: BlockTypeDescriptor;
|
|
9
|
+
field: BlockConfigField;
|
|
10
|
+
/** The value stored on the node, exactly. A field's declared default is a hint the engine never applies,
|
|
11
|
+
* so no default is folded in here and `field.defaultValue` is the only place to read one. */
|
|
12
|
+
value: unknown;
|
|
13
|
+
/** Type of the block input sharing this field's name, when there is one. Hosts key their own editors
|
|
14
|
+
* off this — a `Device` field wants a device picker, not a text box. */
|
|
15
|
+
portType: PortTypeName | undefined;
|
|
16
|
+
/** What an incoming wire binds this field to, already rendered for display, or undefined when nothing
|
|
17
|
+
* is wired. An edge mapping beats node configuration at run time, so a host that ignores this offers
|
|
18
|
+
* an editable field whose value the engine discards. */
|
|
19
|
+
edgeBinding: string | undefined;
|
|
20
|
+
/** Writes one field. */
|
|
21
|
+
onChange: (value: NodeConfigurationValue) => void;
|
|
22
|
+
/** Writes the whole configuration, for a picker that sets several fields at once. */
|
|
23
|
+
onConfigurationChange: (configuration: WorkflowNode['configuration']) => void;
|
|
24
|
+
}
|
|
25
|
+
/** An input of the selected node fed by a literal on an incoming wire's mapping, which the panel draws with a value editor. */
|
|
26
|
+
export interface WireLiteralContext {
|
|
27
|
+
node: WorkflowNode;
|
|
28
|
+
blockType: BlockTypeDescriptor;
|
|
29
|
+
input: BlockPort;
|
|
30
|
+
/** The wire whose mapping holds the literal. */
|
|
31
|
+
edgeId: string;
|
|
32
|
+
/** The literal as stored on the mapping, or undefined when the mapping holds none. */
|
|
33
|
+
value: unknown;
|
|
34
|
+
/** The term the literal is written in: the input's closed term, or its declared term while a type parameter is unbound. */
|
|
35
|
+
portType: PortTypeName;
|
|
36
|
+
/** Writes the literal on the wire's mapping through the store's `updateEdgeMappings`; undefined removes the value. */
|
|
37
|
+
onChange: (value: VariableMapping['literalValue'] | undefined) => void;
|
|
38
|
+
}
|
|
39
|
+
export interface NodeSectionContext {
|
|
40
|
+
node: WorkflowNode;
|
|
41
|
+
blockType: BlockTypeDescriptor;
|
|
42
|
+
onConfigurationChange: (configuration: WorkflowNode['configuration']) => void;
|
|
43
|
+
}
|
|
44
|
+
/** What a host's type-argument picker is told about a node whose block declares type parameters. */
|
|
45
|
+
export interface TypeArgumentPickerContext {
|
|
46
|
+
node: WorkflowNode;
|
|
47
|
+
blockType: BlockTypeDescriptor;
|
|
48
|
+
/** The parameters the block declares, each with the capability names a bound term must implement. */
|
|
49
|
+
typeParameters: readonly BlockTypeParameter[];
|
|
50
|
+
/** The node's `typeArguments` as stored: parameter name to term. Empty when it stores none. */
|
|
51
|
+
typeArguments: Readonly<Record<string, string>>;
|
|
52
|
+
/** Writes the node's whole `typeArguments` through the store's `setNodeTypeArguments`; null, or a record with no entry,
|
|
53
|
+
* removes the key. Whether a term fits its parameter is the server's to say. */
|
|
54
|
+
onChange: (typeArguments: Record<string, string> | null) => void;
|
|
55
|
+
}
|
|
56
|
+
/** A configuration value in Expression mode on a node whose wires offer `Json` outputs: where a host
|
|
57
|
+
* draws its path field or type assist beside an expression such as `${previous.parse.Value}`. */
|
|
58
|
+
export interface ConfigProjectionControlContext {
|
|
59
|
+
placement: 'configuration';
|
|
60
|
+
node: WorkflowNode;
|
|
61
|
+
blockType: BlockTypeDescriptor;
|
|
62
|
+
/** The configuration field holding the expression. */
|
|
63
|
+
fieldName: string;
|
|
64
|
+
/** The field's term: the input sharing its name, else the field's own type. */
|
|
65
|
+
targetType: PortTypeName;
|
|
66
|
+
/** The `Json` and `Json?` outputs of the nodes wired into this one, host-answered ones included, as the mapping
|
|
67
|
+
* dialog lists each wire's sources. */
|
|
68
|
+
jsonOutputs: readonly {
|
|
69
|
+
sourceNodeId: string;
|
|
70
|
+
name: string;
|
|
71
|
+
type: PortTypeName;
|
|
72
|
+
}[];
|
|
73
|
+
/** The expression as stored, without its expression prefix. */
|
|
74
|
+
expressionBody: string;
|
|
75
|
+
/** Replaces the expression body; the panel stores it as the field's value. */
|
|
76
|
+
onExpressionChange: (body: string) => void;
|
|
77
|
+
}
|
|
78
|
+
/** How a host reaches into the generated configuration form. Everything here is optional; without any of
|
|
79
|
+
* it the panel renders exactly what the block type's schema declares. */
|
|
80
|
+
export interface NodeConfigCustomization {
|
|
81
|
+
/** Called for each schema field before the panel renders it. Return a node to render that instead,
|
|
82
|
+
* `null` to render nothing (a field the host owns elsewhere), or undefined to fall through. */
|
|
83
|
+
renderConfigField?: (context: ConfigFieldContext) => ReactNode | null | undefined;
|
|
84
|
+
/** Called, while `NodeConfigPanel`'s `showWireLiterals` is on, for each input that an incoming wire feeds with a literal,
|
|
85
|
+
* a schema field of the same name included. Return a node to render that instead of the panel's value editor, `null` to
|
|
86
|
+
* render nothing (an input the host draws in its own section), or undefined to fall through. */
|
|
87
|
+
renderWireLiteral?: (context: WireLiteralContext) => ReactNode | null | undefined;
|
|
88
|
+
/** Rendered after the generated fields — where a host puts pickers spanning several fields, or its own
|
|
89
|
+
* per-block guidance. */
|
|
90
|
+
renderNodeSections?: (context: NodeSectionContext) => ReactNode;
|
|
91
|
+
/** Called for a node whose block declares type parameters, after the generated fields. Return the host's picker
|
|
92
|
+
* (it offers the terms the vocabulary registers for each parameter's constraints), or null for none. Without it the
|
|
93
|
+
* panel draws no picker; `TypeArgumentPicker` is the library's, for a host to return here. */
|
|
94
|
+
renderTypeArgumentPicker?: (context: TypeArgumentPickerContext) => ReactNode | null;
|
|
95
|
+
/** Called under a configuration field whose value is an expression, when the node's wires offer `Json` outputs.
|
|
96
|
+
* Return the host's projection control, or null for none. Without it the panel draws no control. */
|
|
97
|
+
renderProjectionControl?: (context: ConfigProjectionControlContext) => ReactNode | null;
|
|
98
|
+
}
|
|
99
|
+
export declare const NodeConfigCustomizationContext: import("react").Context<NodeConfigCustomization>;
|
|
100
|
+
export declare function useNodeConfigCustomization(): NodeConfigCustomization;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export * from '@reeve-iot/workflow-core';
|
|
2
|
+
export * from './theme/editorColors.js';
|
|
3
|
+
export * from './canvas/geometry.js';
|
|
4
|
+
export * from './canvas/highlights.js';
|
|
5
|
+
export * from './canvas/portCustomization.js';
|
|
6
|
+
export * from './canvas/nodePorts.js';
|
|
7
|
+
export * from './canvas/Connection.js';
|
|
8
|
+
export * from './canvas/BlockNode.js';
|
|
9
|
+
export * from './canvas/unavailableBlock.js';
|
|
10
|
+
export * from './canvas/WorkflowCanvas.js';
|
|
11
|
+
export * from './config/nodeConfigCustomization.js';
|
|
12
|
+
export * from './config/NodeConfigPanel.js';
|
|
13
|
+
export * from './config/TypeArgumentPicker.js';
|
|
14
|
+
export * from './config/ResiliencySection.js';
|
|
15
|
+
export * from './config/ErrorHandlingSection.js';
|
|
16
|
+
export * from './config/PassthroughSection.js';
|
|
17
|
+
export * from './mapping/mappingCustomization.js';
|
|
18
|
+
export * from './mapping/MappingDialog.js';
|
|
19
|
+
export * from './navigation/SubCanvasBreadcrumb.js';
|
|
20
|
+
export * from './palette/BlockPalette.js';
|
|
21
|
+
export * from './ports/PortDeclarationTable.js';
|
|
22
|
+
export * from './ports/PortValueEditor.js';
|
|
23
|
+
export * from './settings/ConcurrencySection.js';
|
|
24
|
+
export * from './settings/ParameterDeclarationDialog.js';
|
|
25
|
+
export * from './settings/WorkflowExecutionSection.js';
|
|
26
|
+
export * from './validation/ValidationFindings.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export * from '@reeve-iot/workflow-core';
|
|
2
|
+
export * from './theme/editorColors.js';
|
|
3
|
+
export * from './canvas/geometry.js';
|
|
4
|
+
export * from './canvas/highlights.js';
|
|
5
|
+
export * from './canvas/portCustomization.js';
|
|
6
|
+
export * from './canvas/nodePorts.js';
|
|
7
|
+
export * from './canvas/Connection.js';
|
|
8
|
+
export * from './canvas/BlockNode.js';
|
|
9
|
+
export * from './canvas/unavailableBlock.js';
|
|
10
|
+
export * from './canvas/WorkflowCanvas.js';
|
|
11
|
+
export * from './config/nodeConfigCustomization.js';
|
|
12
|
+
export * from './config/NodeConfigPanel.js';
|
|
13
|
+
export * from './config/TypeArgumentPicker.js';
|
|
14
|
+
export * from './config/ResiliencySection.js';
|
|
15
|
+
export * from './config/ErrorHandlingSection.js';
|
|
16
|
+
export * from './config/PassthroughSection.js';
|
|
17
|
+
export * from './mapping/mappingCustomization.js';
|
|
18
|
+
export * from './mapping/MappingDialog.js';
|
|
19
|
+
export * from './navigation/SubCanvasBreadcrumb.js';
|
|
20
|
+
export * from './palette/BlockPalette.js';
|
|
21
|
+
export * from './ports/PortDeclarationTable.js';
|
|
22
|
+
export * from './ports/PortValueEditor.js';
|
|
23
|
+
export * from './settings/ConcurrencySection.js';
|
|
24
|
+
export * from './settings/ParameterDeclarationDialog.js';
|
|
25
|
+
export * from './settings/WorkflowExecutionSection.js';
|
|
26
|
+
export * from './validation/ValidationFindings.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface MappingDialogProps {
|
|
2
|
+
edgeId: string;
|
|
3
|
+
onClose: () => void;
|
|
4
|
+
entryNodeLabel?: string;
|
|
5
|
+
exitNodeLabel?: string;
|
|
6
|
+
}
|
|
7
|
+
/** Edits what one wire carries: which source output feeds each input of the target, or what literal does.
|
|
8
|
+
* The port lists come from the same customization seam the canvas uses, so the dialog cannot drift from
|
|
9
|
+
* what the node draws. */
|
|
10
|
+
export declare function MappingDialog({ edgeId, onClose, entryNodeLabel, exitNodeLabel }: MappingDialogProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useState } from 'react';
|
|
3
|
+
import { Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, FormControl, MenuItem, Paper, Select, Switch, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TextField, ToggleButton, ToggleButtonGroup, Typography, } from '@mui/material';
|
|
4
|
+
import DeleteIcon from '@mui/icons-material/Delete';
|
|
5
|
+
import { WORKFLOW_INPUT_BLOCK_TYPE_ID, WORKFLOW_OUTPUT_BLOCK_TYPE_ID, describeRepeatedMember, findRepeatedMember, indexDraftAnalysis, literalFormOfType, namesTypeParameter, openTermLiteralType, parseDynamicPorts, readMapping, usePortTypes, useWorkflowEditorStore, } from '@reeve-iot/workflow-core';
|
|
6
|
+
import { termText, useAnalysedPortTerm } from '../canvas/analysedPortTerm.js';
|
|
7
|
+
import { useNodePorts } from '../canvas/nodePorts.js';
|
|
8
|
+
import { readExactNumber } from '../ports/PortValueEditor.js';
|
|
9
|
+
import { RefusedLiteral } from '../ports/refusedLiteral.js';
|
|
10
|
+
import { inputWriteTerm } from '../ports/writeTerm.js';
|
|
11
|
+
import { useMappingCustomization } from './mappingCustomization.js';
|
|
12
|
+
import { isJsonTerm, useWireSourceOutputs } from './wireSourceOutputs.js';
|
|
13
|
+
const EXPRESSION_PREFIX = 'expr:';
|
|
14
|
+
function isExpressionLiteral(value) {
|
|
15
|
+
return typeof value === 'string' && value.startsWith(EXPRESSION_PREFIX);
|
|
16
|
+
}
|
|
17
|
+
function literalCellKind(input, form) {
|
|
18
|
+
if (input.allowedValues && input.allowedValues.length > 0)
|
|
19
|
+
return 'allowed';
|
|
20
|
+
if (form === null)
|
|
21
|
+
return 'none';
|
|
22
|
+
if (form !== undefined) {
|
|
23
|
+
return form.gradedAs === 'Int' || form.gradedAs === 'Number' ? 'number'
|
|
24
|
+
: form.gradedAs === 'Boolean' ? 'boolean' : form.gradedAs === 'Json' ? 'json' : 'text';
|
|
25
|
+
}
|
|
26
|
+
if (input.type === 'Number' || input.type === 'Int')
|
|
27
|
+
return 'number';
|
|
28
|
+
if (input.type === 'Boolean')
|
|
29
|
+
return 'boolean';
|
|
30
|
+
return input.type === 'Json' || (input.type !== undefined && openTermLiteralType(input.type) === 'Json') ? 'json' : 'text';
|
|
31
|
+
}
|
|
32
|
+
const LITERAL_JSON_ERROR = 'Must be valid JSON';
|
|
33
|
+
const LITERAL_NULL_ERROR = 'null is not a literal value; use an expression instead';
|
|
34
|
+
function readJsonLiteral(text) {
|
|
35
|
+
if (text.trim() === '')
|
|
36
|
+
return { value: undefined, error: '' };
|
|
37
|
+
let parsed;
|
|
38
|
+
try {
|
|
39
|
+
parsed = JSON.parse(text);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return { value: undefined, error: LITERAL_JSON_ERROR };
|
|
43
|
+
}
|
|
44
|
+
if (parsed === null)
|
|
45
|
+
return { value: undefined, error: LITERAL_NULL_ERROR };
|
|
46
|
+
const repeat = findRepeatedMember(text);
|
|
47
|
+
if (repeat !== undefined)
|
|
48
|
+
return { value: undefined, error: `Ambiguous JSON: ${describeRepeatedMember(repeat)}` };
|
|
49
|
+
return { value: parsed, error: '' };
|
|
50
|
+
}
|
|
51
|
+
function literalJsonText(value) {
|
|
52
|
+
return value === undefined || value === null ? '' : JSON.stringify(value, null, 2);
|
|
53
|
+
}
|
|
54
|
+
/** Edits what one wire carries: which source output feeds each input of the target, or what literal does.
|
|
55
|
+
* The port lists come from the same customization seam the canvas uses, so the dialog cannot drift from
|
|
56
|
+
* what the node draws. */
|
|
57
|
+
export function MappingDialog({ edgeId, onClose, entryNodeLabel = 'Workflow Input', exitNodeLabel = 'Workflow Output' }) {
|
|
58
|
+
const edges = useWorkflowEditorStore((s) => s.edges);
|
|
59
|
+
const nodes = useWorkflowEditorStore((s) => s.nodes);
|
|
60
|
+
const canvasStack = useWorkflowEditorStore((s) => s.canvasStack);
|
|
61
|
+
const blockTypes = useWorkflowEditorStore((s) => s.blockTypes);
|
|
62
|
+
const workflowOutputParams = useWorkflowEditorStore((s) => s.workflowOutputParams);
|
|
63
|
+
const portTypes = usePortTypes();
|
|
64
|
+
const analysis = useWorkflowEditorStore((s) => s.analysis);
|
|
65
|
+
const custom = useMappingCustomization();
|
|
66
|
+
const updateEdgeMappings = useWorkflowEditorStore((s) => s.updateEdgeMappings);
|
|
67
|
+
const removeEdge = useWorkflowEditorStore((s) => s.removeEdge);
|
|
68
|
+
const edge = edges.find((e) => e.id === edgeId);
|
|
69
|
+
const sourceNode = nodes.find((n) => n.id === edge?.sourceNodeId);
|
|
70
|
+
const targetNode = nodes.find((n) => n.id === edge?.targetNodeId);
|
|
71
|
+
const sourceBlockType = blockTypes.find((bt) => bt.blockTypeId === sourceNode?.blockTypeId);
|
|
72
|
+
const targetBlockType = blockTypes.find((bt) => bt.blockTypeId === targetNode?.blockTypeId);
|
|
73
|
+
const hostPorts = useNodePorts(targetNode ?? null, targetBlockType);
|
|
74
|
+
const frame = canvasStack[canvasStack.length - 1];
|
|
75
|
+
const analysisIndex = useMemo(() => indexDraftAnalysis(analysis), [analysis]);
|
|
76
|
+
const analysedTerm = useAnalysedPortTerm();
|
|
77
|
+
const canvasPath = useMemo(() => canvasStack.map((f) => ({ nodeId: f.parentNodeId, branchName: f.subCanvasName })), [canvasStack]);
|
|
78
|
+
const isSourceEntry = sourceNode?.blockTypeId === WORKFLOW_INPUT_BLOCK_TYPE_ID;
|
|
79
|
+
const isTargetExit = targetNode?.blockTypeId === WORKFLOW_OUTPUT_BLOCK_TYPE_ID;
|
|
80
|
+
const isSourceExit = sourceNode?.blockTypeId === WORKFLOW_OUTPUT_BLOCK_TYPE_ID;
|
|
81
|
+
const isTargetEntry = targetNode?.blockTypeId === WORKFLOW_INPUT_BLOCK_TYPE_ID;
|
|
82
|
+
const availableOutputs = useWireSourceOutputs(edge?.sourceNodeId);
|
|
83
|
+
const jsonOutputs = useMemo(() => availableOutputs.flatMap((out) => (out.type !== undefined && isJsonTerm(out.type) ? [{ name: out.name, type: out.type }] : [])), [availableOutputs]);
|
|
84
|
+
const targetInputs = useMemo(() => {
|
|
85
|
+
if (isTargetExit) {
|
|
86
|
+
if (!frame) {
|
|
87
|
+
return workflowOutputParams.map((p) => ({ name: p.name, displayName: p.displayName, isRequired: p.isRequired, type: p.type }));
|
|
88
|
+
}
|
|
89
|
+
const parentNode = frame.nodes.find((n) => n.id === frame.parentNodeId);
|
|
90
|
+
const parentBlockType = blockTypes.find((bt) => bt.blockTypeId === parentNode?.blockTypeId);
|
|
91
|
+
const declared = (parentBlockType?.subCanvasOutputs?.[frame.subCanvasName] ?? []).map((p) => ({
|
|
92
|
+
name: p.name, displayName: p.displayName, isRequired: p.isRequired, type: p.type, allowedValues: p.allowedValues ?? undefined,
|
|
93
|
+
}));
|
|
94
|
+
const bySourceKey = new Map();
|
|
95
|
+
for (const p of parentNode?.outputPorts ?? []) {
|
|
96
|
+
const sourceKey = p.sources?.[frame.subCanvasName];
|
|
97
|
+
if (!sourceKey || declared.some((d) => d.name === sourceKey) || bySourceKey.has(sourceKey))
|
|
98
|
+
continue;
|
|
99
|
+
bySourceKey.set(sourceKey, { name: sourceKey, displayName: sourceKey, isRequired: false, type: p.type });
|
|
100
|
+
}
|
|
101
|
+
return [...declared, ...bySourceKey.values()];
|
|
102
|
+
}
|
|
103
|
+
if (targetBlockType?.hasDynamicPorts) {
|
|
104
|
+
return parseDynamicPorts(targetNode?.configuration['InputPorts']);
|
|
105
|
+
}
|
|
106
|
+
const base = (targetBlockType?.inputs ?? [])
|
|
107
|
+
.filter((i) => !hostPorts.isInputHidden(i.name))
|
|
108
|
+
.map((i) => {
|
|
109
|
+
const port = { name: i.name, displayName: i.displayName, isRequired: i.isRequired, type: i.type };
|
|
110
|
+
const declared = hostPorts.inputType(port);
|
|
111
|
+
const bound = declared === undefined || targetNode === undefined ? undefined
|
|
112
|
+
: inputWriteTerm(declared, targetNode, i.name, analysisIndex, canvasPath);
|
|
113
|
+
return { ...port, type: (bound ?? declared), allowedValues: i.allowedValues ?? undefined };
|
|
114
|
+
});
|
|
115
|
+
const extra = hostPorts.hostInputs.filter((c) => !base.some((i) => i.name === c.name));
|
|
116
|
+
const forwarded = (targetNode?.passthrough ?? [])
|
|
117
|
+
.filter((name) => !base.some((i) => i.name === name) && !extra.some((c) => c.name === name))
|
|
118
|
+
.map((name) => ({ name, displayName: name, isRequired: false, shown: analysedTerm(targetNode?.id ?? '', 'inputs', name) }));
|
|
119
|
+
return [...base, ...extra, ...forwarded];
|
|
120
|
+
}, [isTargetExit, frame, workflowOutputParams, blockTypes, targetBlockType, targetNode, hostPorts, analysisIndex, canvasPath, analysedTerm]);
|
|
121
|
+
const [mappings, setMappings] = useState(edge?.mappings ?? {});
|
|
122
|
+
const [literalText, setLiteralText] = useState({});
|
|
123
|
+
const [literalMode, setLiteralMode] = useState({});
|
|
124
|
+
const [writtenAs, setWrittenAs] = useState({});
|
|
125
|
+
if (!edge || !sourceNode || !targetNode)
|
|
126
|
+
return null;
|
|
127
|
+
if (isSourceExit || isTargetEntry)
|
|
128
|
+
return null;
|
|
129
|
+
if ((!isSourceEntry && !sourceBlockType) || (!isTargetExit && !targetBlockType)) {
|
|
130
|
+
return (_jsxs(Dialog, { open: true, onClose: onClose, maxWidth: "sm", fullWidth: true, children: [_jsx(DialogTitle, { children: "Stored mappings" }), _jsxs(DialogContent, { dividers: true, "data-testid": "mapping-dialog-unavailable", children: [_jsx(Typography, { variant: "body2", color: "textSecondary", gutterBottom: true, children: "A block on this connection is not available on this host, so its mappings are shown as stored and cannot be edited." }), _jsx(Box, { component: "ul", sx: { m: 0, pl: 2, fontFamily: 'monospace', fontSize: 12 }, children: Object.entries(edge.mappings).map(([input, mapping]) => {
|
|
131
|
+
const read = readMapping(mapping);
|
|
132
|
+
return (_jsxs("li", { children: [input, " ", read.literal ? `= ${read.value === undefined ? 'nothing' : JSON.stringify(read.value)}` : `↳ ${read.source}`] }, input));
|
|
133
|
+
}) })] }), _jsxs(DialogActions, { sx: { justifyContent: 'space-between', px: 3 }, children: [_jsx(Button, { color: "error", startIcon: _jsx(DeleteIcon, {}), onClick: () => { removeEdge(edgeId); onClose(); }, children: "Remove Connection" }), _jsx(Button, { onClick: onClose, children: "Close" })] })] }));
|
|
134
|
+
}
|
|
135
|
+
const sourceDisplayName = isSourceEntry ? entryNodeLabel : (sourceBlockType?.displayName ?? '');
|
|
136
|
+
const targetDisplayName = isTargetExit ? exitNodeLabel : (targetBlockType?.displayName ?? '');
|
|
137
|
+
const written = (inputName) => {
|
|
138
|
+
setWrittenAs((prev) => ({ ...prev, [inputName]: targetInputs.find((input) => input.name === inputName)?.type }));
|
|
139
|
+
};
|
|
140
|
+
const change = (inputName, field, value) => {
|
|
141
|
+
if (field === 'literalValue')
|
|
142
|
+
written(inputName);
|
|
143
|
+
setMappings((prev) => {
|
|
144
|
+
const next = { ...(prev[inputName] ?? { type: 'direct' }), [field]: value };
|
|
145
|
+
if (field === 'type' && value === 'literal')
|
|
146
|
+
delete next.projection;
|
|
147
|
+
if (field === 'sourceOutputName' && !readMapping(next).literal && value === '') {
|
|
148
|
+
const rest = { ...prev };
|
|
149
|
+
delete rest[inputName];
|
|
150
|
+
return rest;
|
|
151
|
+
}
|
|
152
|
+
return { ...prev, [inputName]: next };
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
const changeProjection = (inputName, projection) => {
|
|
156
|
+
setMappings((prev) => {
|
|
157
|
+
const entry = prev[inputName];
|
|
158
|
+
if (!entry || readMapping(entry).literal)
|
|
159
|
+
return prev;
|
|
160
|
+
const next = { ...entry };
|
|
161
|
+
delete next.projection;
|
|
162
|
+
if (projection !== null)
|
|
163
|
+
next.projection = projection;
|
|
164
|
+
return { ...prev, [inputName]: next };
|
|
165
|
+
});
|
|
166
|
+
};
|
|
167
|
+
const changeLiteral = (inputName, value) => {
|
|
168
|
+
written(inputName);
|
|
169
|
+
const literalValue = value;
|
|
170
|
+
setMappings((prev) => {
|
|
171
|
+
const entry = prev[inputName] ?? { type: 'literal' };
|
|
172
|
+
return { ...prev, [inputName]: { ...entry, literalValue } };
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
const changeNumber = (inputName, shape, raw) => {
|
|
176
|
+
setLiteralText((prev) => ({ ...prev, [inputName]: raw }));
|
|
177
|
+
const number = readExactNumber(raw, shape);
|
|
178
|
+
if (number !== undefined)
|
|
179
|
+
changeLiteral(inputName, number);
|
|
180
|
+
};
|
|
181
|
+
const changeJson = (input, text) => {
|
|
182
|
+
const inputName = input.name;
|
|
183
|
+
setLiteralText((prev) => ({ ...prev, [inputName]: text }));
|
|
184
|
+
const parsed = readJsonLiteral(text);
|
|
185
|
+
if (parsed.error === '' && parsed.value !== undefined)
|
|
186
|
+
changeLiteral(inputName, parsed.value);
|
|
187
|
+
};
|
|
188
|
+
const literalStored = (input) => {
|
|
189
|
+
const read = readMapping(mappings[input.name] ?? { type: 'direct' });
|
|
190
|
+
return read.literal ? read.value : undefined;
|
|
191
|
+
};
|
|
192
|
+
const valueStored = (input) => {
|
|
193
|
+
const stored = literalStored(input);
|
|
194
|
+
return isExpressionLiteral(stored) ? undefined : stored;
|
|
195
|
+
};
|
|
196
|
+
const numberInvalid = (input) => {
|
|
197
|
+
const typed = literalText[input.name];
|
|
198
|
+
return typed !== undefined && typed !== '' && readExactNumber(typed, formOf(input)?.gradedAs ?? input.type) === undefined;
|
|
199
|
+
};
|
|
200
|
+
const formOf = (input) => (input.type === undefined ? undefined : literalFormOfType(input.type, portTypes));
|
|
201
|
+
const kindOf = (input) => literalCellKind(input, formOf(input));
|
|
202
|
+
const modeOf = (input) => literalMode[input.name] ?? (isExpressionLiteral(literalStored(input)) ? 'expression' : 'value');
|
|
203
|
+
const valueTextOf = (input) => {
|
|
204
|
+
const stored = valueStored(input);
|
|
205
|
+
return literalText[input.name] ?? (stored === undefined || stored === null ? '' : String(stored));
|
|
206
|
+
};
|
|
207
|
+
const jsonTextOf = (input) => literalText[input.name] ?? literalJsonText(valueStored(input));
|
|
208
|
+
const expressionTextOf = (input) => {
|
|
209
|
+
const stored = literalStored(input);
|
|
210
|
+
if (isExpressionLiteral(stored))
|
|
211
|
+
return stored.slice(EXPRESSION_PREFIX.length);
|
|
212
|
+
return kindOf(input) === 'number' ? valueTextOf(input) : '';
|
|
213
|
+
};
|
|
214
|
+
const refusalOf = (input) => {
|
|
215
|
+
if (kindOf(input) !== 'json' || !readMapping(mappings[input.name] ?? { type: 'direct' }).literal)
|
|
216
|
+
return '';
|
|
217
|
+
return readJsonLiteral(modeOf(input) === 'value' ? jsonTextOf(input) : literalJsonText(valueStored(input))).error;
|
|
218
|
+
};
|
|
219
|
+
const switchMode = (input, next) => {
|
|
220
|
+
if (!next || next === modeOf(input))
|
|
221
|
+
return;
|
|
222
|
+
setLiteralMode((prev) => ({ ...prev, [input.name]: next }));
|
|
223
|
+
const body = expressionTextOf(input);
|
|
224
|
+
if (next === 'expression' && body !== '')
|
|
225
|
+
changeLiteral(input.name, `${EXPRESSION_PREFIX}${body}`);
|
|
226
|
+
};
|
|
227
|
+
const storedRefusalOf = (input) => {
|
|
228
|
+
const kind = kindOf(input);
|
|
229
|
+
if (input.type === undefined || kind === 'allowed' || (formOf(input) === undefined && kind !== 'json'))
|
|
230
|
+
return undefined;
|
|
231
|
+
if (Object.hasOwn(writtenAs, input.name) && writtenAs[input.name] === input.type)
|
|
232
|
+
return undefined;
|
|
233
|
+
const stored = valueStored(input);
|
|
234
|
+
return stored === undefined || portTypes.isLiteralOf(stored, input.type) ? undefined : input.type;
|
|
235
|
+
};
|
|
236
|
+
const replaceStored = (input) => {
|
|
237
|
+
setLiteralText((prev) => {
|
|
238
|
+
const rest = { ...prev };
|
|
239
|
+
delete rest[input.name];
|
|
240
|
+
return rest;
|
|
241
|
+
});
|
|
242
|
+
if (kindOf(input) === 'boolean') {
|
|
243
|
+
changeLiteral(input.name, false);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
setMappings((prev) => {
|
|
247
|
+
const entry = prev[input.name];
|
|
248
|
+
if (entry === undefined)
|
|
249
|
+
return prev;
|
|
250
|
+
const next = { ...entry };
|
|
251
|
+
delete next.literalValue;
|
|
252
|
+
return { ...prev, [input.name]: next };
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
const refused = targetInputs.some((input) => refusalOf(input) !== '');
|
|
256
|
+
const save = () => {
|
|
257
|
+
updateEdgeMappings(edgeId, Object.fromEntries(Object.entries(mappings).filter(([, m]) => { const read = readMapping(m); return read.literal || read.source !== ''; })));
|
|
258
|
+
onClose();
|
|
259
|
+
};
|
|
260
|
+
return (_jsxs(Dialog, { open: true, onClose: onClose, maxWidth: "md", fullWidth: true, children: [_jsxs(DialogTitle, { children: ["Map Variables: ", sourceDisplayName, " \u2192 ", targetDisplayName] }), _jsxs(DialogContent, { dividers: true, children: [_jsxs(Typography, { variant: "body2", color: "textSecondary", gutterBottom: true, children: ["Map the outputs from '", sourceDisplayName, "' to the inputs of '", targetDisplayName, "'. All required inputs (*) must be mapped."] }), targetInputs.length === 0 ? (_jsxs(Box, { sx: { py: 4, textAlign: 'center' }, children: [_jsxs(Typography, { variant: "body1", color: "textSecondary", children: ["This connection is for ", _jsx("strong", { children: "execution ordering only" }), "."] }), _jsx(Typography, { variant: "caption", color: "textSecondary", children: "Target block has no input ports to map." })] })) : (_jsx(TableContainer, { component: Paper, variant: "outlined", children: _jsxs(Table, { size: "small", children: [_jsx(TableHead, { children: _jsxs(TableRow, { children: [_jsx(TableCell, { children: "Target Input" }), _jsx(TableCell, { children: "Mapping Type" }), _jsx(TableCell, { children: "Source Output / Value" })] }) }), _jsx(TableBody, { children: targetInputs.map((input) => {
|
|
261
|
+
const read = readMapping(mappings[input.name] ?? { type: 'direct' });
|
|
262
|
+
const kind = kindOf(input);
|
|
263
|
+
return (_jsxs(TableRow, { children: [_jsxs(TableCell, { children: [_jsxs(Typography, { variant: "body2", sx: { fontWeight: input.isRequired ? 'bold' : 'normal' }, children: [input.displayName, " ", input.isRequired && '*'] }), input.type !== undefined && _jsxs(Typography, { variant: "caption", color: "textSecondary", children: ["(", input.type, ")"] }), input.type === undefined && input.shown !== undefined && (_jsxs(Typography, { variant: "caption", color: input.shown.knowledge === 'refused' ? 'error' : 'textSecondary', "data-testid": `mapping-term-${input.name}`, "data-term-knowledge": input.shown.knowledge, "data-analysis": input.shown.stale ? 'stale' : 'current', sx: input.shown.stale ? { fontStyle: 'italic' } : undefined, children: ["(", input.shown.text, ")"] }))] }), _jsx(TableCell, { children: _jsx(FormControl, { fullWidth: true, size: "small", children: _jsxs(Select, { value: read.literal ? 'literal' : 'direct', inputProps: { 'aria-label': `${input.displayName} mapping type` }, onChange: (e) => { change(input.name, 'type', e.target.value); }, children: [_jsx(MenuItem, { value: "direct", children: "Direct" }), _jsx(MenuItem, { value: "literal", children: "Literal" })] }) }) }), _jsxs(TableCell, { children: [!read.literal && (_jsx(FormControl, { fullWidth: true, size: "small", children: _jsxs(Select, { value: read.source, inputProps: { 'aria-label': `${input.displayName} source` }, onChange: (e) => { change(input.name, 'sourceOutputName', e.target.value); }, children: [_jsx(MenuItem, { value: "", children: _jsx("em", { children: "None" }) }), availableOutputs.map((out) => (_jsxs(MenuItem, { value: out.name, children: [out.displayName, out.type === undefined && out.shown === undefined ? '' : ` (${out.type ?? (out.shown === undefined ? '' : termText(out.shown))})`] }, out.name)))] }) })), !read.literal && read.source !== '' && (() => {
|
|
264
|
+
const sourceType = availableOutputs.find((out) => out.name === read.source)?.type;
|
|
265
|
+
const stored = mappings[input.name]?.projection;
|
|
266
|
+
if (!custom.renderProjectionControl || (stored === undefined && !(sourceType && isJsonTerm(sourceType))))
|
|
267
|
+
return null;
|
|
268
|
+
return custom.renderProjectionControl({
|
|
269
|
+
placement: 'wire', edgeId, targetNodeId: edge.targetNodeId, inputName: input.name,
|
|
270
|
+
sourceNodeId: edge.sourceNodeId, sourceOutputName: read.source, sourceType,
|
|
271
|
+
targetType: input.type, projection: stored,
|
|
272
|
+
onChange: (projection) => { changeProjection(input.name, projection); },
|
|
273
|
+
});
|
|
274
|
+
})(), read.literal && kind === 'allowed' && (_jsx(FormControl, { fullWidth: true, size: "small", children: _jsxs(Select, { value: String(read.value ?? ''), inputProps: { 'aria-label': `${input.displayName} literal` }, onChange: (e) => { change(input.name, 'literalValue', e.target.value); }, children: [_jsx(MenuItem, { value: "", children: _jsx("em", { children: "None" }) }), (input.allowedValues ?? []).map((val) => _jsx(MenuItem, { value: val, children: val }, val))] }) })), read.literal && kind === 'text' && formOf(input) === undefined && (_jsx(TextField, { fullWidth: true, size: "small", multiline: true, rows: 4, placeholder: "Literal value", value: String(read.value ?? ''), helperText: input.type !== undefined && namesTypeParameter(input.type)
|
|
275
|
+
? 'The type of this input is not chosen yet; the value is checked once it is.' : undefined, slotProps: { htmlInput: { 'aria-label': `${input.displayName} literal` } }, onChange: (e) => { change(input.name, 'literalValue', e.target.value); } })), read.literal && (kind === 'number' || kind === 'boolean' || kind === 'json' || (kind === 'text' && formOf(input) !== undefined) || kind === 'none') && (_jsxs(Box, { sx: { display: 'flex', flexDirection: 'column', gap: 0.5, minWidth: 220 }, children: [_jsxs(ToggleButtonGroup, { size: "small", exclusive: true, value: modeOf(input), "aria-label": `${input.displayName} literal mode`, onChange: (_, next) => { switchMode(input, next); }, children: [_jsx(ToggleButton, { value: "value", "data-testid": `literal-value-${input.name}`, children: "Value" }), _jsx(ToggleButton, { value: "expression", "data-testid": `literal-expression-${input.name}`, children: "Expression" })] }), modeOf(input) === 'expression' ? (_jsxs(_Fragment, { children: [_jsx(TextField, { fullWidth: true, size: "small", placeholder: "Expression", value: expressionTextOf(input), error: refusalOf(input) !== '', helperText: refusalOf(input) || undefined, slotProps: { htmlInput: { 'aria-label': `${input.displayName} expression`, style: { fontFamily: 'monospace', fontSize: 11 } } }, onChange: (e) => { changeLiteral(input.name, `${EXPRESSION_PREFIX}${e.target.value}`); } }), jsonOutputs.length > 0 && custom.renderProjectionControl?.({
|
|
276
|
+
placement: 'expression', edgeId, targetNodeId: edge.targetNodeId, inputName: input.name,
|
|
277
|
+
sourceNodeId: edge.sourceNodeId, jsonOutputs, targetType: input.type,
|
|
278
|
+
expressionBody: expressionTextOf(input),
|
|
279
|
+
onExpressionChange: (body) => { changeLiteral(input.name, `${EXPRESSION_PREFIX}${body}`); },
|
|
280
|
+
})] })) : storedRefusalOf(input) !== undefined ? (_jsx(RefusedLiteral, { testId: `literal-refused-${input.name}`, value: valueStored(input), expected: storedRefusalOf(input) ?? '', onReplace: () => { replaceStored(input); } })) : kind === 'number' ? (_jsx(TextField, { fullWidth: true, size: "small", type: "text", placeholder: "Literal value", value: valueTextOf(input), error: numberInvalid(input), helperText: numberInvalid(input) ? (_jsxs("span", { "data-testid": `literal-error-${input.name}`, "data-rule-id": "literal-port-value-invalid", children: ["This value cannot be read as ", formOf(input)?.gradedAs ?? input.type, "."] })) : undefined, slotProps: { htmlInput: { inputMode: 'decimal', 'aria-label': `${input.displayName} literal` } }, onChange: (e) => { changeNumber(input.name, formOf(input)?.gradedAs ?? input.type, e.target.value); } })) : kind === 'text' ? (_jsx(TextField, { fullWidth: true, size: "small", multiline: true, rows: 4, placeholder: "Literal value", value: String(valueStored(input) ?? ''), slotProps: { htmlInput: { 'aria-label': `${input.displayName} literal` } }, onChange: (e) => { change(input.name, 'literalValue', e.target.value); } })) : kind === 'none' ? (_jsx(Typography, { variant: "caption", color: "textSecondary", "data-testid": `literal-none-${input.name}`, children: "This type takes no literal value. Connect a wire or write an expression." })) : kind === 'boolean' ? (_jsx(Switch, { size: "small", checked: valueStored(input) === true, slotProps: { input: { 'aria-label': `${input.displayName} literal` } }, onChange: (e) => { changeLiteral(input.name, e.target.checked); } })) : (_jsx(TextField, { fullWidth: true, size: "small", multiline: true, rows: 4, placeholder: "[1, 2, 3]", value: jsonTextOf(input), error: refusalOf(input) !== '', helperText: refusalOf(input) || undefined, slotProps: { htmlInput: { 'aria-label': `${input.displayName} literal`, style: { fontFamily: 'monospace', fontSize: 11 } } }, onChange: (e) => { changeJson(input, e.target.value); } }))] }))] })] }, input.name));
|
|
281
|
+
}) })] }) }))] }), _jsxs(DialogActions, { sx: { justifyContent: 'space-between', px: 3 }, children: [_jsx(Button, { color: "error", startIcon: _jsx(DeleteIcon, {}), onClick: () => { removeEdge(edgeId); onClose(); }, children: "Remove Connection" }), _jsxs(Box, { children: [_jsx(Button, { onClick: onClose, sx: { mr: 1 }, children: "Cancel" }), _jsx(Button, { variant: "contained", color: "primary", disabled: refused, onClick: save, children: "Save Mappings" })] })] })] }));
|
|
282
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { MappingProjection, PortTypeName } from '@reeve-iot/workflow-core';
|
|
3
|
+
interface ProjectionControlBase {
|
|
4
|
+
edgeId: string;
|
|
5
|
+
targetNodeId: string;
|
|
6
|
+
inputName: string;
|
|
7
|
+
sourceNodeId: string;
|
|
8
|
+
targetType?: PortTypeName;
|
|
9
|
+
}
|
|
10
|
+
/** A direct mapping that reads a `Json` or `Json?` output: the wire is a projection wire. */
|
|
11
|
+
export interface WireProjectionControlContext extends ProjectionControlBase {
|
|
12
|
+
placement: 'wire';
|
|
13
|
+
sourceOutputName: string;
|
|
14
|
+
/** The source port's declared term, `Json` or `Json?`. A stored projection on another source also opens the control so it
|
|
15
|
+
* can be cleared; the term is then that source's, or undefined where the source declares no such output. */
|
|
16
|
+
sourceType?: PortTypeName;
|
|
17
|
+
/** The projection the mapping stores, or undefined. */
|
|
18
|
+
projection: MappingProjection | undefined;
|
|
19
|
+
/** Sets the projection, or clears it with null. The mapping dialog holds it until the author saves, through the rules of
|
|
20
|
+
* the store's `setMappingProjection`; only the server's draft analysis grades the path and the type. */
|
|
21
|
+
onChange: (projection: MappingProjection | null) => void;
|
|
22
|
+
}
|
|
23
|
+
/** An input whose mapping is an expression, on a wire whose source offers `Json` outputs. */
|
|
24
|
+
export interface ExpressionProjectionControlContext extends ProjectionControlBase {
|
|
25
|
+
placement: 'expression';
|
|
26
|
+
/** The source's outputs declared `Json` or `Json?`. */
|
|
27
|
+
jsonOutputs: readonly {
|
|
28
|
+
name: string;
|
|
29
|
+
type: PortTypeName;
|
|
30
|
+
}[];
|
|
31
|
+
/** The expression as stored, without its `expr:` prefix. */
|
|
32
|
+
expressionBody: string;
|
|
33
|
+
/** Replaces the expression body; the mapping dialog stores it as the literal. */
|
|
34
|
+
onExpressionChange: (body: string) => void;
|
|
35
|
+
}
|
|
36
|
+
/** What a host's projection control is handed. */
|
|
37
|
+
export type ProjectionControlContext = WireProjectionControlContext | ExpressionProjectionControlContext;
|
|
38
|
+
/** How a host reaches into the mapping dialog. Without it the dialog draws no projection control: the control is the
|
|
39
|
+
* host's to build. */
|
|
40
|
+
export interface MappingCustomization {
|
|
41
|
+
/** Called inside the mapping dialog on a direct mapping from a `Json` output (placement `wire`) and on an
|
|
42
|
+
* expression mapping whose wire has `Json` outputs (placement `expression`). Return the host's control (a path field,
|
|
43
|
+
* a type picker, a paste-sample assist), or null for none. */
|
|
44
|
+
renderProjectionControl?: (context: ProjectionControlContext) => ReactNode | null;
|
|
45
|
+
}
|
|
46
|
+
/** Provide a `MappingCustomization` above the mapping dialog to place the host's projection control in it. */
|
|
47
|
+
export declare const MappingCustomizationContext: import("react").Context<MappingCustomization>;
|
|
48
|
+
/** The `MappingCustomization` in effect; an empty one where no provider is mounted. */
|
|
49
|
+
export declare function useMappingCustomization(): MappingCustomization;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
const NONE = {};
|
|
3
|
+
/** Provide a `MappingCustomization` above the mapping dialog to place the host's projection control in it. */
|
|
4
|
+
export const MappingCustomizationContext = createContext(NONE);
|
|
5
|
+
/** The `MappingCustomization` in effect; an empty one where no provider is mounted. */
|
|
6
|
+
export function useMappingCustomization() {
|
|
7
|
+
return useContext(MappingCustomizationContext);
|
|
8
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { PortTermDisplay, PortTypeName, WorkflowEdge } from '@reeve-iot/workflow-core';
|
|
3
|
+
/** True for the two terms a projection reads. */
|
|
4
|
+
export declare const isJsonTerm: (type: string) => boolean;
|
|
5
|
+
/** An output a wire can read, as the dialog lists it: `type` is absent where the editor does not know the term, as for a
|
|
6
|
+
* passthrough name, whose `shown` term is the server's. */
|
|
7
|
+
export interface WireSourceOutput {
|
|
8
|
+
name: string;
|
|
9
|
+
displayName: string;
|
|
10
|
+
isRequired: boolean;
|
|
11
|
+
type?: PortTypeName;
|
|
12
|
+
shown?: PortTermDisplay;
|
|
13
|
+
}
|
|
14
|
+
/** The outputs a wire from `sourceNodeId` can read on the open canvas: the one list the mapping dialog offers and the
|
|
15
|
+
* node panel's projection slot reads, so the two cannot disagree. */
|
|
16
|
+
export declare function useWireSourceOutputs(sourceNodeId: string | undefined): WireSourceOutput[];
|
|
17
|
+
/** A `Json` or `Json?` output a wire into a node offers, and the node it leaves. */
|
|
18
|
+
export interface WiredJsonOutput {
|
|
19
|
+
sourceNodeId: string;
|
|
20
|
+
name: string;
|
|
21
|
+
type: PortTypeName;
|
|
22
|
+
}
|
|
23
|
+
/** Renders `children` with the `Json` outputs every wire in `edges` offers, each read through `useWireSourceOutputs`:
|
|
24
|
+
* one component per wire, so the hook order holds whatever the number of wires. */
|
|
25
|
+
export declare function WiredJsonOutputs({ edges, children, found }: {
|
|
26
|
+
edges: readonly WorkflowEdge[];
|
|
27
|
+
children: (outputs: readonly WiredJsonOutput[]) => ReactNode;
|
|
28
|
+
found?: readonly WiredJsonOutput[];
|
|
29
|
+
}): ReactNode;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { ERROR_OUTPUT_NAME, ERROR_OUTPUT_TYPE, WORKFLOW_INPUT_BLOCK_TYPE_ID, addsErrorOutput, parseDynamicPorts, useWorkflowEditorStore } from '@reeve-iot/workflow-core';
|
|
4
|
+
import { useAnalysedPortTerm } from '../canvas/analysedPortTerm.js';
|
|
5
|
+
import { useNodePorts } from '../canvas/nodePorts.js';
|
|
6
|
+
/** True for the two terms a projection reads. */
|
|
7
|
+
export const isJsonTerm = (type) => type === 'Json' || type === 'Json?';
|
|
8
|
+
/** The outputs a wire from `sourceNodeId` can read on the open canvas: the one list the mapping dialog offers and the
|
|
9
|
+
* node panel's projection slot reads, so the two cannot disagree. */
|
|
10
|
+
export function useWireSourceOutputs(sourceNodeId) {
|
|
11
|
+
const nodes = useWorkflowEditorStore((s) => s.nodes);
|
|
12
|
+
const blockTypes = useWorkflowEditorStore((s) => s.blockTypes);
|
|
13
|
+
const canvasStack = useWorkflowEditorStore((s) => s.canvasStack);
|
|
14
|
+
const workflowInputParams = useWorkflowEditorStore((s) => s.workflowInputParams);
|
|
15
|
+
const sourceNode = nodes.find((n) => n.id === sourceNodeId);
|
|
16
|
+
const sourceBlockType = blockTypes.find((bt) => bt.blockTypeId === sourceNode?.blockTypeId);
|
|
17
|
+
const sourceHostPorts = useNodePorts(sourceNode ?? null, sourceBlockType);
|
|
18
|
+
const frame = canvasStack[canvasStack.length - 1];
|
|
19
|
+
const isSourceEntry = sourceNode?.blockTypeId === WORKFLOW_INPUT_BLOCK_TYPE_ID;
|
|
20
|
+
const analysedTerm = useAnalysedPortTerm();
|
|
21
|
+
return useMemo(() => {
|
|
22
|
+
if (isSourceEntry) {
|
|
23
|
+
if (!frame) {
|
|
24
|
+
return workflowInputParams.map((p) => ({ name: p.name, displayName: p.displayName, isRequired: false, type: p.type }));
|
|
25
|
+
}
|
|
26
|
+
const parentNode = frame.nodes.find((n) => n.id === frame.parentNodeId);
|
|
27
|
+
const parentBlockType = blockTypes.find((bt) => bt.blockTypeId === parentNode?.blockTypeId);
|
|
28
|
+
const declared = parentBlockType?.subCanvasInputs?.[frame.subCanvasName] ?? [];
|
|
29
|
+
const forwarded = (parentNode?.passthrough ?? [])
|
|
30
|
+
.filter((name) => !declared.some((p) => p.name === name))
|
|
31
|
+
.map((name) => ({ name, displayName: name, isRequired: false, shown: analysedTerm(sourceNode?.id ?? '', 'outputs', name) }));
|
|
32
|
+
return [...declared.map((p) => ({ name: p.name, displayName: p.displayName, isRequired: p.isRequired, type: p.type })), ...forwarded];
|
|
33
|
+
}
|
|
34
|
+
const base = sourceBlockType?.hasDynamicPorts
|
|
35
|
+
? parseDynamicPorts(sourceNode?.configuration['OutputPorts'])
|
|
36
|
+
: (sourceBlockType?.outputs ?? []).map((o) => ({ name: o.name, displayName: o.displayName, isRequired: false, type: o.type }));
|
|
37
|
+
for (const output of sourceHostPorts.hostOutputs) {
|
|
38
|
+
if (!base.some((existing) => existing.name === output.name)) {
|
|
39
|
+
base.push({ name: output.name, displayName: output.displayName, isRequired: false, type: output.type });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (sourceNode && addsErrorOutput(sourceNode, base)) {
|
|
43
|
+
base.push({ name: ERROR_OUTPUT_NAME, displayName: 'Error', isRequired: false, type: ERROR_OUTPUT_TYPE });
|
|
44
|
+
}
|
|
45
|
+
const forwarded = (sourceNode?.passthrough ?? [])
|
|
46
|
+
.filter((name) => !base.some((o) => o.name === name))
|
|
47
|
+
.map((name) => ({ name, displayName: name, isRequired: false, shown: analysedTerm(sourceNode?.id ?? '', 'outputs', name) }));
|
|
48
|
+
return [...base, ...forwarded];
|
|
49
|
+
}, [isSourceEntry, frame, workflowInputParams, blockTypes, sourceBlockType, sourceNode, sourceHostPorts, analysedTerm]);
|
|
50
|
+
}
|
|
51
|
+
/** Renders `children` with the `Json` outputs every wire in `edges` offers, each read through `useWireSourceOutputs`:
|
|
52
|
+
* one component per wire, so the hook order holds whatever the number of wires. */
|
|
53
|
+
export function WiredJsonOutputs({ edges, children, found = [] }) {
|
|
54
|
+
const [first, ...rest] = edges;
|
|
55
|
+
if (first === undefined)
|
|
56
|
+
return children(found);
|
|
57
|
+
return _jsx(WireJsonOutputs, { edge: first, rest: rest, found: found, children: children });
|
|
58
|
+
}
|
|
59
|
+
function WireJsonOutputs({ edge, rest, found, children }) {
|
|
60
|
+
const outputs = useWireSourceOutputs(edge.sourceNodeId);
|
|
61
|
+
const json = useMemo(() => [
|
|
62
|
+
...found,
|
|
63
|
+
...outputs.flatMap((o) => o.type !== undefined && isJsonTerm(o.type) && !found.some((f) => f.sourceNodeId === edge.sourceNodeId && f.name === o.name)
|
|
64
|
+
? [{ sourceNodeId: edge.sourceNodeId, name: o.name, type: o.type }] : []),
|
|
65
|
+
], [found, outputs, edge.sourceNodeId]);
|
|
66
|
+
return _jsx(WiredJsonOutputs, { edges: rest, found: json, children: children });
|
|
67
|
+
}
|