@workbench-kit/shell-react 0.0.2-prototype.0.2.6 → 0.0.2-prototype.0.2.8
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/README.md +41 -0
- package/package.json +9 -9
- package/src/{chat-ai-mock-proposals.ts → chat/ai-mock-proposals.ts} +39 -39
- package/src/{chat-command-input.ts → chat/command-input.ts} +52 -52
- package/src/{chat-command-policy.ts → chat/command-policy.ts} +54 -54
- package/src/{chat-command-surface.tsx → chat/command-surface.tsx} +155 -155
- package/src/{use-workbench-chat-command-proposals.ts → chat/use-chat-command-proposals.ts} +194 -194
- package/src/{chat-view-data.ts → chat/view-data.ts} +20 -20
- package/src/{chat-view.tsx → chat/view.tsx} +220 -220
- package/src/{command-inspector-surface.tsx → commands/inspector-surface.tsx} +46 -46
- package/src/{use-workbench-command-descriptors.ts → commands/use-command-descriptors.ts} +41 -41
- package/src/{use-context-key-revision.ts → commands/use-context-key-revision.ts} +18 -18
- package/src/{commands-view-data.ts → commands/view-data.ts} +17 -17
- package/src/{commands-view.tsx → commands/view.tsx} +43 -43
- package/src/devtools/WorkbenchDevtoolsPanel.tsx +124 -124
- package/src/devtools/WorkbenchDevtoolsShell.tsx +17 -17
- package/src/devtools/index.ts +11 -11
- package/src/devtools/use-workbench-devtools-snapshot.ts +84 -84
- package/src/devtools/workbench-devtools-snapshot.ts +140 -140
- package/src/devtools/workbench-devtools.css +82 -82
- package/src/{editor-area-dnd.ts → editor/area-dnd.ts} +69 -69
- package/src/{editor-area-model.ts → editor/area-model.ts} +71 -71
- package/src/{editor-area.css → editor/area.css} +454 -454
- package/src/{editor-area.tsx → editor/area.tsx} +676 -676
- package/src/{editor-host-surface.tsx → editor/host-surface.tsx} +631 -634
- package/src/{editor-pane-visibility.ts → editor/pane-visibility.ts} +130 -130
- package/src/{editor-resource.ts → editor/resource.ts} +36 -36
- package/src/{editor-state-storage.ts → editor/state-storage.ts} +182 -193
- package/src/{editor-tab-context-menu.ts → editor/tab-context-menu.ts} +118 -118
- package/src/{use-editor.ts → editor/use-editor.ts} +114 -107
- package/src/{editor-view-providers.tsx → editor/view-providers.tsx} +552 -552
- package/src/{editor-workspace-file-availability.ts → editor/workspace-file-availability.ts} +15 -15
- package/src/{editor-workspace-reconcile.tsx → editor/workspace-reconcile.tsx} +31 -28
- package/src/{explorer-context-menu.ts → explorer/context-menu.ts} +114 -114
- package/src/{createCommandWorkspaceExplorerPort.ts → explorer/create-command-workspace-explorer-port.ts} +86 -86
- package/src/{explorer-reveal.ts → explorer/reveal.ts} +112 -112
- package/src/{search-view-data.ts → explorer/search-view-data.ts} +15 -15
- package/src/{search-view.tsx → explorer/search-view.tsx} +65 -62
- package/src/{use-active-workspace-path.ts → explorer/use-active-workspace-path.ts} +15 -15
- package/src/{explorer-view-data.ts → explorer/view-data.ts} +58 -58
- package/src/{explorer-view.tsx → explorer/view.tsx} +227 -224
- package/src/{extension-context-menu.ts → extensions/context-menu.ts} +52 -52
- package/src/{extension-management-model.ts → extensions/management-model.ts} +313 -313
- package/src/{use-extension-management.ts → extensions/use-extension-management.ts} +241 -193
- package/src/{extensions-view-data.ts → extensions/view-data.ts} +19 -19
- package/src/{extensions-view.tsx → extensions/view.tsx} +63 -38
- package/src/{field-remap-demo.tsx → field-remap/demo.tsx} +18 -18
- package/src/{field-remap-editor-surface.tsx → field-remap/editor-surface.tsx} +36 -36
- package/src/{field-remap-flow-adapter.ts → field-remap/flow-adapter.ts} +240 -240
- package/src/{field-remap-flow.tsx → field-remap/flow.tsx} +369 -369
- package/src/{field-remap-graph.tsx → field-remap/graph.tsx} +559 -559
- package/src/field-remap/jsonata-transform.ts +166 -0
- package/src/{field-remap-panel.tsx → field-remap/panel.tsx} +193 -175
- package/src/{field-remap-samples.ts → field-remap/samples.ts} +352 -352
- package/src/{table-mapping-adapter.ts → field-remap/table-mapping-adapter.ts} +59 -59
- package/src/{field-remap-tree.tsx → field-remap/tree.tsx} +404 -404
- package/src/{field-remap-view-data.ts → field-remap/view-data.ts} +16 -16
- package/src/{field-remap-view.css → field-remap/view.css} +676 -676
- package/src/{field-remap-view.tsx → field-remap/view.tsx} +86 -86
- package/src/index.ts +212 -199
- package/src/{json-form-source-patch.ts → jdw/json-form-source-patch.ts} +323 -323
- package/src/{jdw-lab-view-data.ts → jdw/lab-view-data.ts} +25 -25
- package/src/{jdw-lab-view.css → jdw/lab-view.css} +21 -21
- package/src/{jdw-lab-view.tsx → jdw/lab-view.tsx} +79 -79
- package/src/{jdw-widget-form-view.tsx → jdw/widget-form-view.tsx} +68 -65
- package/src/{jdw-widget-preview-view.tsx → jdw/widget-preview-view.tsx} +54 -51
- package/src/{keybinding-overrides-storage.ts → management/keybinding-overrides-storage.ts} +49 -57
- package/src/{keybinding-management-settings.tsx → management/keybinding-settings.tsx} +16 -16
- package/src/{management-palette-commands.ts → management/palette-commands.ts} +38 -38
- package/src/{preference-settings-storage.ts → management/preference-settings-storage.ts} +50 -58
- package/src/{management-settings-ids.ts → management/settings-ids.ts} +12 -12
- package/src/{management-settings.tsx → management/settings.tsx} +96 -75
- package/src/{use-command-management.ts → management/use-command-management.ts} +191 -191
- package/src/{use-keybinding-management.ts → management/use-keybinding-management.ts} +130 -130
- package/src/{shell-model.tsx → shell/model.tsx} +149 -149
- package/src/{provider.tsx → shell/provider.tsx} +603 -573
- package/src/{shell-secondary-actions.tsx → shell/secondary-actions.tsx} +59 -59
- package/src/{shell-settings-constants.ts → shell/settings-constants.ts} +9 -9
- package/src/{shell-settings.tsx → shell/settings.tsx} +599 -599
- package/src/{shell.tsx → shell/shell.tsx} +680 -649
- package/src/{shell-titlebar-layout-controls.tsx → shell/titlebar-layout-controls.tsx} +4 -4
- package/src/{shell-view-host.tsx → shell/view-host.tsx} +212 -199
- package/src/{workbench-appearance-storage.ts → workbench/appearance-storage.ts} +107 -115
- package/src/{workbench-command-host.tsx → workbench/command-host.tsx} +243 -243
- package/src/{workbench-command-palette.ts → workbench/command-palette.ts} +208 -208
- package/src/{workbench-keybinding-bridge.ts → workbench/keybinding-bridge.ts} +54 -54
- package/src/{workbench-layout-storage.ts → workbench/layout-storage.ts} +134 -145
- package/src/{workbench-profile-modal.tsx → workbench/profile-modal.tsx} +118 -118
- package/src/{workbench-shell-command-registration.ts → workbench/shell-command-registration.ts} +58 -58
- package/src/{workbench-startup-gate.tsx → workbench/startup-gate.tsx} +136 -136
- package/src/{workbench-status-sections.ts → workbench/status-sections.ts} +43 -43
- package/src/{use-persisted-workbench-appearance.ts → workbench/use-persisted-appearance.ts} +33 -33
- package/src/{workbench-user-commands.ts → workbench/user-commands.ts} +46 -46
- package/src/{workspace-view-state.ts → workbench/workspace-view-state.ts} +35 -35
- package/src/jsonata-transform.ts +0 -36
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import type { JSX } from 'react';
|
|
2
|
-
import { ScrollArea } from '@workbench-kit/react/primitives';
|
|
3
|
-
|
|
4
|
-
import { SampleFieldRemapDemo } from './
|
|
5
|
-
import { resolveFieldRemapSampleId } from './
|
|
6
|
-
import './
|
|
7
|
-
|
|
8
|
-
export type FieldRemapEditorSurfaceId = string;
|
|
9
|
-
|
|
10
|
-
export interface FieldRemapEditorSurfaceProps {
|
|
11
|
-
readonly resourceUri: string;
|
|
12
|
-
readonly surfaceId: FieldRemapEditorSurfaceId;
|
|
13
|
-
readonly tabId: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function FieldRemapEditorSurface({
|
|
17
|
-
resourceUri,
|
|
18
|
-
surfaceId,
|
|
19
|
-
tabId,
|
|
20
|
-
}: FieldRemapEditorSurfaceProps): JSX.Element {
|
|
21
|
-
const sampleId = resolveFieldRemapSampleId(surfaceId);
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<ScrollArea
|
|
25
|
-
aria-label={`${sampleId} field remap`}
|
|
26
|
-
className="workbench-field-remap-editor-surface"
|
|
27
|
-
data-editor-host-id={tabId}
|
|
28
|
-
data-resource-uri={resourceUri}
|
|
29
|
-
data-sample-id={sampleId}
|
|
30
|
-
data-testid="field-remap-editor-surface"
|
|
31
|
-
orientation="vertical"
|
|
32
|
-
>
|
|
33
|
-
<SampleFieldRemapDemo sampleId={sampleId} />
|
|
34
|
-
</ScrollArea>
|
|
35
|
-
);
|
|
36
|
-
}
|
|
1
|
+
import type { JSX } from 'react';
|
|
2
|
+
import { ScrollArea } from '@workbench-kit/react/primitives';
|
|
3
|
+
|
|
4
|
+
import { SampleFieldRemapDemo } from './demo.js';
|
|
5
|
+
import { resolveFieldRemapSampleId } from './samples.js';
|
|
6
|
+
import './view.css';
|
|
7
|
+
|
|
8
|
+
export type FieldRemapEditorSurfaceId = string;
|
|
9
|
+
|
|
10
|
+
export interface FieldRemapEditorSurfaceProps {
|
|
11
|
+
readonly resourceUri: string;
|
|
12
|
+
readonly surfaceId: FieldRemapEditorSurfaceId;
|
|
13
|
+
readonly tabId: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function FieldRemapEditorSurface({
|
|
17
|
+
resourceUri,
|
|
18
|
+
surfaceId,
|
|
19
|
+
tabId,
|
|
20
|
+
}: FieldRemapEditorSurfaceProps): JSX.Element {
|
|
21
|
+
const sampleId = resolveFieldRemapSampleId(surfaceId);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<ScrollArea
|
|
25
|
+
aria-label={`${sampleId} field remap`}
|
|
26
|
+
className="workbench-field-remap-editor-surface"
|
|
27
|
+
data-editor-host-id={tabId}
|
|
28
|
+
data-resource-uri={resourceUri}
|
|
29
|
+
data-sample-id={sampleId}
|
|
30
|
+
data-testid="field-remap-editor-surface"
|
|
31
|
+
orientation="vertical"
|
|
32
|
+
>
|
|
33
|
+
<SampleFieldRemapDemo sampleId={sampleId} />
|
|
34
|
+
</ScrollArea>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -1,240 +1,240 @@
|
|
|
1
|
-
import type { Edge, Node } from '@xyflow/react';
|
|
2
|
-
import {
|
|
3
|
-
flattenSourceFields,
|
|
4
|
-
flattenTargetSlots,
|
|
5
|
-
type MappingEdge,
|
|
6
|
-
type SourceField,
|
|
7
|
-
type TargetSlot,
|
|
8
|
-
type ValueTransformRegistry,
|
|
9
|
-
} from '@workbench-kit/field-remap';
|
|
10
|
-
|
|
11
|
-
export type FieldRemapFlowNodeKind = 'source-object' | 'target-object' | 'transform';
|
|
12
|
-
|
|
13
|
-
export type FieldRemapPort = {
|
|
14
|
-
fieldId: string;
|
|
15
|
-
label: string;
|
|
16
|
-
dataType?: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/** XYFlow requires node/edge `data` to extend `Record<string, unknown>`. */
|
|
20
|
-
export type FieldRemapSourceObjectNodeData = {
|
|
21
|
-
kind: 'source-object';
|
|
22
|
-
title: string;
|
|
23
|
-
ports: FieldRemapPort[];
|
|
24
|
-
} & Record<string, unknown>;
|
|
25
|
-
|
|
26
|
-
export type FieldRemapTargetObjectNodeData = {
|
|
27
|
-
kind: 'target-object';
|
|
28
|
-
title: string;
|
|
29
|
-
ports: FieldRemapPort[];
|
|
30
|
-
} & Record<string, unknown>;
|
|
31
|
-
|
|
32
|
-
export type FieldRemapTransformNodeData = {
|
|
33
|
-
kind: 'transform';
|
|
34
|
-
mappingEdgeId: string;
|
|
35
|
-
stepIndex: number;
|
|
36
|
-
transformId: string;
|
|
37
|
-
label: string;
|
|
38
|
-
} & Record<string, unknown>;
|
|
39
|
-
|
|
40
|
-
export type FieldRemapFlowNodeData =
|
|
41
|
-
FieldRemapSourceObjectNodeData | FieldRemapTargetObjectNodeData | FieldRemapTransformNodeData;
|
|
42
|
-
|
|
43
|
-
export type FieldRemapFlowEdgeData = {
|
|
44
|
-
mappingEdgeId: string;
|
|
45
|
-
segment: 'in' | 'mid' | 'out' | 'direct';
|
|
46
|
-
} & Record<string, unknown>;
|
|
47
|
-
|
|
48
|
-
export const SOURCE_OBJECT_NODE_ID = 'obj:source' as const;
|
|
49
|
-
export const TARGET_OBJECT_NODE_ID = 'obj:target' as const;
|
|
50
|
-
|
|
51
|
-
const SOURCE_X = 24;
|
|
52
|
-
const TRANSFORM_X = 320;
|
|
53
|
-
const TARGET_X = 620;
|
|
54
|
-
const TRANSFORM_ROW_GAP = 72;
|
|
55
|
-
|
|
56
|
-
export function sourceObjectNodeId(): string {
|
|
57
|
-
return SOURCE_OBJECT_NODE_ID;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function targetObjectNodeId(): string {
|
|
61
|
-
return TARGET_OBJECT_NODE_ID;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Handle id for a field/slot port on an object node. */
|
|
65
|
-
export function portHandleId(fieldOrSlotId: string): string {
|
|
66
|
-
return fieldOrSlotId;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function transformNodeId(mappingEdgeId: string, stepIndex: number): string {
|
|
70
|
-
return `xf:${mappingEdgeId}:${stepIndex}`;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function fieldLabel(field: SourceField | TargetSlot): string {
|
|
74
|
-
return field.path ?? field.label;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function toPorts(fields: readonly (SourceField | TargetSlot)[]): FieldRemapPort[] {
|
|
78
|
-
return fields.map((field) => ({
|
|
79
|
-
fieldId: field.id,
|
|
80
|
-
label: fieldLabel(field),
|
|
81
|
-
dataType: field.dataType,
|
|
82
|
-
}));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Build React Flow nodes/edges from kit shapes + MappingEdge[].
|
|
87
|
-
* Layout: one multi-port source object, transform chain, one multi-port target object.
|
|
88
|
-
*/
|
|
89
|
-
export function mappingToFlowGraph(input: {
|
|
90
|
-
readonly sources: readonly SourceField[];
|
|
91
|
-
readonly targets: readonly TargetSlot[];
|
|
92
|
-
readonly edges: readonly MappingEdge[];
|
|
93
|
-
readonly transforms: ValueTransformRegistry;
|
|
94
|
-
readonly sourceTitle?: string;
|
|
95
|
-
readonly targetTitle?: string;
|
|
96
|
-
}): { nodes: Node<FieldRemapFlowNodeData>[]; edges: Edge<FieldRemapFlowEdgeData>[] } {
|
|
97
|
-
const sourcePorts = toPorts(flattenSourceFields(input.sources));
|
|
98
|
-
const targetPorts = toPorts(flattenTargetSlots(input.targets));
|
|
99
|
-
|
|
100
|
-
const nodes: Node<FieldRemapFlowNodeData>[] = [
|
|
101
|
-
{
|
|
102
|
-
id: SOURCE_OBJECT_NODE_ID,
|
|
103
|
-
type: 'fieldRemapSourceObject',
|
|
104
|
-
position: { x: SOURCE_X, y: 24 },
|
|
105
|
-
data: {
|
|
106
|
-
kind: 'source-object',
|
|
107
|
-
title: input.sourceTitle?.trim() || 'Source',
|
|
108
|
-
ports: sourcePorts,
|
|
109
|
-
},
|
|
110
|
-
draggable: true,
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
id: TARGET_OBJECT_NODE_ID,
|
|
114
|
-
type: 'fieldRemapTargetObject',
|
|
115
|
-
position: { x: TARGET_X, y: 24 },
|
|
116
|
-
data: {
|
|
117
|
-
kind: 'target-object',
|
|
118
|
-
title: input.targetTitle?.trim() || 'Target',
|
|
119
|
-
ports: targetPorts,
|
|
120
|
-
},
|
|
121
|
-
draggable: true,
|
|
122
|
-
},
|
|
123
|
-
];
|
|
124
|
-
|
|
125
|
-
const flowEdges: Edge<FieldRemapFlowEdgeData>[] = [];
|
|
126
|
-
|
|
127
|
-
input.edges.forEach((edge, edgeIndex) => {
|
|
128
|
-
const chain = edge.transformIds ?? [];
|
|
129
|
-
const baseY = 40 + edgeIndex * TRANSFORM_ROW_GAP;
|
|
130
|
-
|
|
131
|
-
if (chain.length === 0) {
|
|
132
|
-
flowEdges.push({
|
|
133
|
-
id: `fe:${edge.id}:direct`,
|
|
134
|
-
source: SOURCE_OBJECT_NODE_ID,
|
|
135
|
-
sourceHandle: portHandleId(edge.sourceFieldId),
|
|
136
|
-
target: TARGET_OBJECT_NODE_ID,
|
|
137
|
-
targetHandle: portHandleId(edge.targetSlotId),
|
|
138
|
-
type: 'smoothstep',
|
|
139
|
-
data: { mappingEdgeId: edge.id, segment: 'direct' },
|
|
140
|
-
});
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
chain.forEach((transformId, stepIndex) => {
|
|
145
|
-
const definition = input.transforms.get(transformId);
|
|
146
|
-
nodes.push({
|
|
147
|
-
id: transformNodeId(edge.id, stepIndex),
|
|
148
|
-
type: 'fieldRemapTransform',
|
|
149
|
-
position: {
|
|
150
|
-
x: TRANSFORM_X + stepIndex * 36,
|
|
151
|
-
y: baseY + stepIndex * 48,
|
|
152
|
-
},
|
|
153
|
-
data: {
|
|
154
|
-
kind: 'transform',
|
|
155
|
-
mappingEdgeId: edge.id,
|
|
156
|
-
stepIndex,
|
|
157
|
-
transformId,
|
|
158
|
-
label: definition?.label ?? transformId,
|
|
159
|
-
},
|
|
160
|
-
draggable: true,
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
flowEdges.push({
|
|
165
|
-
id: `fe:${edge.id}:in`,
|
|
166
|
-
source: SOURCE_OBJECT_NODE_ID,
|
|
167
|
-
sourceHandle: portHandleId(edge.sourceFieldId),
|
|
168
|
-
target: transformNodeId(edge.id, 0),
|
|
169
|
-
targetHandle: 'in',
|
|
170
|
-
type: 'smoothstep',
|
|
171
|
-
data: { mappingEdgeId: edge.id, segment: 'in' },
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
for (let stepIndex = 0; stepIndex < chain.length - 1; stepIndex += 1) {
|
|
175
|
-
flowEdges.push({
|
|
176
|
-
id: `fe:${edge.id}:mid:${stepIndex}`,
|
|
177
|
-
source: transformNodeId(edge.id, stepIndex),
|
|
178
|
-
sourceHandle: 'out',
|
|
179
|
-
target: transformNodeId(edge.id, stepIndex + 1),
|
|
180
|
-
targetHandle: 'in',
|
|
181
|
-
type: 'smoothstep',
|
|
182
|
-
data: { mappingEdgeId: edge.id, segment: 'mid' },
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
flowEdges.push({
|
|
187
|
-
id: `fe:${edge.id}:out`,
|
|
188
|
-
source: transformNodeId(edge.id, chain.length - 1),
|
|
189
|
-
sourceHandle: 'out',
|
|
190
|
-
target: TARGET_OBJECT_NODE_ID,
|
|
191
|
-
targetHandle: portHandleId(edge.targetSlotId),
|
|
192
|
-
type: 'smoothstep',
|
|
193
|
-
data: { mappingEdgeId: edge.id, segment: 'out' },
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
return { nodes, edges: flowEdges };
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/** Parse React Flow connection (object ports or legacy) into a kit MappingEdge. */
|
|
201
|
-
export function connectionToMappingEdge(input: {
|
|
202
|
-
readonly sourceNodeId: string;
|
|
203
|
-
readonly targetNodeId: string;
|
|
204
|
-
readonly sourceHandle?: string | null;
|
|
205
|
-
readonly targetHandle?: string | null;
|
|
206
|
-
readonly existing: readonly MappingEdge[];
|
|
207
|
-
}): MappingEdge | null {
|
|
208
|
-
let sourceFieldId: string | undefined;
|
|
209
|
-
let targetSlotId: string | undefined;
|
|
210
|
-
|
|
211
|
-
if (input.sourceNodeId === SOURCE_OBJECT_NODE_ID && input.sourceHandle) {
|
|
212
|
-
sourceFieldId = input.sourceHandle;
|
|
213
|
-
} else if (input.sourceNodeId.startsWith('src:')) {
|
|
214
|
-
// Legacy single-field node ids (older graphs / tests).
|
|
215
|
-
sourceFieldId = input.sourceNodeId.slice('src:'.length);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (input.targetNodeId === TARGET_OBJECT_NODE_ID && input.targetHandle) {
|
|
219
|
-
targetSlotId = input.targetHandle;
|
|
220
|
-
} else if (input.targetNodeId.startsWith('tgt:')) {
|
|
221
|
-
targetSlotId = input.targetNodeId.slice('tgt:'.length);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (!sourceFieldId || !targetSlotId) {
|
|
225
|
-
return null;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const existing = input.existing.find((edge) => edge.targetSlotId === targetSlotId);
|
|
229
|
-
return {
|
|
230
|
-
id: existing?.id ?? `e-${sourceFieldId}-${targetSlotId}-${Date.now()}`,
|
|
231
|
-
sourceFieldId,
|
|
232
|
-
targetSlotId,
|
|
233
|
-
...(existing?.transformIds ? { transformIds: existing.transformIds } : {}),
|
|
234
|
-
...(existing?.transformOptionSteps
|
|
235
|
-
? { transformOptionSteps: existing.transformOptionSteps }
|
|
236
|
-
: {}),
|
|
237
|
-
...(existing?.itemSourcePath ? { itemSourcePath: existing.itemSourcePath } : {}),
|
|
238
|
-
...(existing?.itemEdges ? { itemEdges: existing.itemEdges } : {}),
|
|
239
|
-
};
|
|
240
|
-
}
|
|
1
|
+
import type { Edge, Node } from '@xyflow/react';
|
|
2
|
+
import {
|
|
3
|
+
flattenSourceFields,
|
|
4
|
+
flattenTargetSlots,
|
|
5
|
+
type MappingEdge,
|
|
6
|
+
type SourceField,
|
|
7
|
+
type TargetSlot,
|
|
8
|
+
type ValueTransformRegistry,
|
|
9
|
+
} from '@workbench-kit/field-remap';
|
|
10
|
+
|
|
11
|
+
export type FieldRemapFlowNodeKind = 'source-object' | 'target-object' | 'transform';
|
|
12
|
+
|
|
13
|
+
export type FieldRemapPort = {
|
|
14
|
+
fieldId: string;
|
|
15
|
+
label: string;
|
|
16
|
+
dataType?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** XYFlow requires node/edge `data` to extend `Record<string, unknown>`. */
|
|
20
|
+
export type FieldRemapSourceObjectNodeData = {
|
|
21
|
+
kind: 'source-object';
|
|
22
|
+
title: string;
|
|
23
|
+
ports: FieldRemapPort[];
|
|
24
|
+
} & Record<string, unknown>;
|
|
25
|
+
|
|
26
|
+
export type FieldRemapTargetObjectNodeData = {
|
|
27
|
+
kind: 'target-object';
|
|
28
|
+
title: string;
|
|
29
|
+
ports: FieldRemapPort[];
|
|
30
|
+
} & Record<string, unknown>;
|
|
31
|
+
|
|
32
|
+
export type FieldRemapTransformNodeData = {
|
|
33
|
+
kind: 'transform';
|
|
34
|
+
mappingEdgeId: string;
|
|
35
|
+
stepIndex: number;
|
|
36
|
+
transformId: string;
|
|
37
|
+
label: string;
|
|
38
|
+
} & Record<string, unknown>;
|
|
39
|
+
|
|
40
|
+
export type FieldRemapFlowNodeData =
|
|
41
|
+
FieldRemapSourceObjectNodeData | FieldRemapTargetObjectNodeData | FieldRemapTransformNodeData;
|
|
42
|
+
|
|
43
|
+
export type FieldRemapFlowEdgeData = {
|
|
44
|
+
mappingEdgeId: string;
|
|
45
|
+
segment: 'in' | 'mid' | 'out' | 'direct';
|
|
46
|
+
} & Record<string, unknown>;
|
|
47
|
+
|
|
48
|
+
export const SOURCE_OBJECT_NODE_ID = 'obj:source' as const;
|
|
49
|
+
export const TARGET_OBJECT_NODE_ID = 'obj:target' as const;
|
|
50
|
+
|
|
51
|
+
const SOURCE_X = 24;
|
|
52
|
+
const TRANSFORM_X = 320;
|
|
53
|
+
const TARGET_X = 620;
|
|
54
|
+
const TRANSFORM_ROW_GAP = 72;
|
|
55
|
+
|
|
56
|
+
export function sourceObjectNodeId(): string {
|
|
57
|
+
return SOURCE_OBJECT_NODE_ID;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function targetObjectNodeId(): string {
|
|
61
|
+
return TARGET_OBJECT_NODE_ID;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Handle id for a field/slot port on an object node. */
|
|
65
|
+
export function portHandleId(fieldOrSlotId: string): string {
|
|
66
|
+
return fieldOrSlotId;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function transformNodeId(mappingEdgeId: string, stepIndex: number): string {
|
|
70
|
+
return `xf:${mappingEdgeId}:${stepIndex}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function fieldLabel(field: SourceField | TargetSlot): string {
|
|
74
|
+
return field.path ?? field.label;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function toPorts(fields: readonly (SourceField | TargetSlot)[]): FieldRemapPort[] {
|
|
78
|
+
return fields.map((field) => ({
|
|
79
|
+
fieldId: field.id,
|
|
80
|
+
label: fieldLabel(field),
|
|
81
|
+
dataType: field.dataType,
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Build React Flow nodes/edges from kit shapes + MappingEdge[].
|
|
87
|
+
* Layout: one multi-port source object, transform chain, one multi-port target object.
|
|
88
|
+
*/
|
|
89
|
+
export function mappingToFlowGraph(input: {
|
|
90
|
+
readonly sources: readonly SourceField[];
|
|
91
|
+
readonly targets: readonly TargetSlot[];
|
|
92
|
+
readonly edges: readonly MappingEdge[];
|
|
93
|
+
readonly transforms: ValueTransformRegistry;
|
|
94
|
+
readonly sourceTitle?: string;
|
|
95
|
+
readonly targetTitle?: string;
|
|
96
|
+
}): { nodes: Node<FieldRemapFlowNodeData>[]; edges: Edge<FieldRemapFlowEdgeData>[] } {
|
|
97
|
+
const sourcePorts = toPorts(flattenSourceFields(input.sources));
|
|
98
|
+
const targetPorts = toPorts(flattenTargetSlots(input.targets));
|
|
99
|
+
|
|
100
|
+
const nodes: Node<FieldRemapFlowNodeData>[] = [
|
|
101
|
+
{
|
|
102
|
+
id: SOURCE_OBJECT_NODE_ID,
|
|
103
|
+
type: 'fieldRemapSourceObject',
|
|
104
|
+
position: { x: SOURCE_X, y: 24 },
|
|
105
|
+
data: {
|
|
106
|
+
kind: 'source-object',
|
|
107
|
+
title: input.sourceTitle?.trim() || 'Source',
|
|
108
|
+
ports: sourcePorts,
|
|
109
|
+
},
|
|
110
|
+
draggable: true,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
id: TARGET_OBJECT_NODE_ID,
|
|
114
|
+
type: 'fieldRemapTargetObject',
|
|
115
|
+
position: { x: TARGET_X, y: 24 },
|
|
116
|
+
data: {
|
|
117
|
+
kind: 'target-object',
|
|
118
|
+
title: input.targetTitle?.trim() || 'Target',
|
|
119
|
+
ports: targetPorts,
|
|
120
|
+
},
|
|
121
|
+
draggable: true,
|
|
122
|
+
},
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
const flowEdges: Edge<FieldRemapFlowEdgeData>[] = [];
|
|
126
|
+
|
|
127
|
+
input.edges.forEach((edge, edgeIndex) => {
|
|
128
|
+
const chain = edge.transformIds ?? [];
|
|
129
|
+
const baseY = 40 + edgeIndex * TRANSFORM_ROW_GAP;
|
|
130
|
+
|
|
131
|
+
if (chain.length === 0) {
|
|
132
|
+
flowEdges.push({
|
|
133
|
+
id: `fe:${edge.id}:direct`,
|
|
134
|
+
source: SOURCE_OBJECT_NODE_ID,
|
|
135
|
+
sourceHandle: portHandleId(edge.sourceFieldId),
|
|
136
|
+
target: TARGET_OBJECT_NODE_ID,
|
|
137
|
+
targetHandle: portHandleId(edge.targetSlotId),
|
|
138
|
+
type: 'smoothstep',
|
|
139
|
+
data: { mappingEdgeId: edge.id, segment: 'direct' },
|
|
140
|
+
});
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
chain.forEach((transformId, stepIndex) => {
|
|
145
|
+
const definition = input.transforms.get(transformId);
|
|
146
|
+
nodes.push({
|
|
147
|
+
id: transformNodeId(edge.id, stepIndex),
|
|
148
|
+
type: 'fieldRemapTransform',
|
|
149
|
+
position: {
|
|
150
|
+
x: TRANSFORM_X + stepIndex * 36,
|
|
151
|
+
y: baseY + stepIndex * 48,
|
|
152
|
+
},
|
|
153
|
+
data: {
|
|
154
|
+
kind: 'transform',
|
|
155
|
+
mappingEdgeId: edge.id,
|
|
156
|
+
stepIndex,
|
|
157
|
+
transformId,
|
|
158
|
+
label: definition?.label ?? transformId,
|
|
159
|
+
},
|
|
160
|
+
draggable: true,
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
flowEdges.push({
|
|
165
|
+
id: `fe:${edge.id}:in`,
|
|
166
|
+
source: SOURCE_OBJECT_NODE_ID,
|
|
167
|
+
sourceHandle: portHandleId(edge.sourceFieldId),
|
|
168
|
+
target: transformNodeId(edge.id, 0),
|
|
169
|
+
targetHandle: 'in',
|
|
170
|
+
type: 'smoothstep',
|
|
171
|
+
data: { mappingEdgeId: edge.id, segment: 'in' },
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
for (let stepIndex = 0; stepIndex < chain.length - 1; stepIndex += 1) {
|
|
175
|
+
flowEdges.push({
|
|
176
|
+
id: `fe:${edge.id}:mid:${stepIndex}`,
|
|
177
|
+
source: transformNodeId(edge.id, stepIndex),
|
|
178
|
+
sourceHandle: 'out',
|
|
179
|
+
target: transformNodeId(edge.id, stepIndex + 1),
|
|
180
|
+
targetHandle: 'in',
|
|
181
|
+
type: 'smoothstep',
|
|
182
|
+
data: { mappingEdgeId: edge.id, segment: 'mid' },
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
flowEdges.push({
|
|
187
|
+
id: `fe:${edge.id}:out`,
|
|
188
|
+
source: transformNodeId(edge.id, chain.length - 1),
|
|
189
|
+
sourceHandle: 'out',
|
|
190
|
+
target: TARGET_OBJECT_NODE_ID,
|
|
191
|
+
targetHandle: portHandleId(edge.targetSlotId),
|
|
192
|
+
type: 'smoothstep',
|
|
193
|
+
data: { mappingEdgeId: edge.id, segment: 'out' },
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
return { nodes, edges: flowEdges };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Parse React Flow connection (object ports or legacy) into a kit MappingEdge. */
|
|
201
|
+
export function connectionToMappingEdge(input: {
|
|
202
|
+
readonly sourceNodeId: string;
|
|
203
|
+
readonly targetNodeId: string;
|
|
204
|
+
readonly sourceHandle?: string | null;
|
|
205
|
+
readonly targetHandle?: string | null;
|
|
206
|
+
readonly existing: readonly MappingEdge[];
|
|
207
|
+
}): MappingEdge | null {
|
|
208
|
+
let sourceFieldId: string | undefined;
|
|
209
|
+
let targetSlotId: string | undefined;
|
|
210
|
+
|
|
211
|
+
if (input.sourceNodeId === SOURCE_OBJECT_NODE_ID && input.sourceHandle) {
|
|
212
|
+
sourceFieldId = input.sourceHandle;
|
|
213
|
+
} else if (input.sourceNodeId.startsWith('src:')) {
|
|
214
|
+
// Legacy single-field node ids (older graphs / tests).
|
|
215
|
+
sourceFieldId = input.sourceNodeId.slice('src:'.length);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (input.targetNodeId === TARGET_OBJECT_NODE_ID && input.targetHandle) {
|
|
219
|
+
targetSlotId = input.targetHandle;
|
|
220
|
+
} else if (input.targetNodeId.startsWith('tgt:')) {
|
|
221
|
+
targetSlotId = input.targetNodeId.slice('tgt:'.length);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (!sourceFieldId || !targetSlotId) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const existing = input.existing.find((edge) => edge.targetSlotId === targetSlotId);
|
|
229
|
+
return {
|
|
230
|
+
id: existing?.id ?? `e-${sourceFieldId}-${targetSlotId}-${Date.now()}`,
|
|
231
|
+
sourceFieldId,
|
|
232
|
+
targetSlotId,
|
|
233
|
+
...(existing?.transformIds ? { transformIds: existing.transformIds } : {}),
|
|
234
|
+
...(existing?.transformOptionSteps
|
|
235
|
+
? { transformOptionSteps: existing.transformOptionSteps }
|
|
236
|
+
: {}),
|
|
237
|
+
...(existing?.itemSourcePath ? { itemSourcePath: existing.itemSourcePath } : {}),
|
|
238
|
+
...(existing?.itemEdges ? { itemEdges: existing.itemEdges } : {}),
|
|
239
|
+
};
|
|
240
|
+
}
|