@bian-womp/spark-workbench 0.2.18 → 0.2.19
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/lib/cjs/index.cjs +126 -71
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/cjs/src/misc/context/WorkbenchContext.provider.d.ts.map +1 -1
- package/lib/cjs/src/misc/layout.d.ts +53 -0
- package/lib/cjs/src/misc/layout.d.ts.map +1 -0
- package/lib/cjs/src/misc/mapping.d.ts +1 -1
- package/lib/cjs/src/misc/mapping.d.ts.map +1 -1
- package/lib/esm/index.js +126 -71
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/src/misc/context/WorkbenchContext.provider.d.ts.map +1 -1
- package/lib/esm/src/misc/layout.d.ts +53 -0
- package/lib/esm/src/misc/layout.d.ts.map +1 -0
- package/lib/esm/src/misc/mapping.d.ts +1 -1
- package/lib/esm/src/misc/mapping.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkbenchContext.provider.d.ts","sourceRoot":"","sources":["../../../../../src/misc/context/WorkbenchContext.provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAMN,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,KAAK,QAAQ,EAAwB,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAmB,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"WorkbenchContext.provider.d.ts","sourceRoot":"","sources":["../../../../../src/misc/context/WorkbenchContext.provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAMN,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,KAAK,QAAQ,EAAwB,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,YAAY,EAAmB,MAAM,4BAA4B,CAAC;AAiB3E,wBAAgB,iBAAiB,CAAC,EAChC,EAAE,EACF,MAAM,EACN,QAAQ,EACR,WAAW,EACX,QAAQ,GACT,EAAE;IACD,EAAE,EAAE,iBAAiB,CAAC;IACtB,MAAM,EAAE,YAAY,CAAC;IACrB,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,EAAE,CAAC,CAAC,EAAE,QAAQ,KAAK,IAAI,CAAC;IACnC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,2CA6jBA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ResolvedHandles } from "@bian-womp/spark-protocol";
|
|
2
|
+
import type { GraphDefinition, Registry } from "@bian-womp/spark-graph";
|
|
3
|
+
import { Position } from "@xyflow/react";
|
|
4
|
+
export declare function computeEffectiveHandles(node: GraphDefinition["nodes"][number], registry: Registry): ResolvedHandles;
|
|
5
|
+
export declare function countVisibleHandles(handles: Omit<ResolvedHandles, "inputDefaults">): {
|
|
6
|
+
inputsCount: number;
|
|
7
|
+
outputsCount: number;
|
|
8
|
+
};
|
|
9
|
+
export declare function estimateNodeSize(args: {
|
|
10
|
+
node: GraphDefinition["nodes"][number];
|
|
11
|
+
registry: Registry;
|
|
12
|
+
showValues?: boolean;
|
|
13
|
+
overrides?: {
|
|
14
|
+
width?: number;
|
|
15
|
+
height?: number;
|
|
16
|
+
};
|
|
17
|
+
}): {
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
inputsCount: number;
|
|
21
|
+
outputsCount: number;
|
|
22
|
+
rowCount: number;
|
|
23
|
+
};
|
|
24
|
+
export declare function layoutNode(args: {
|
|
25
|
+
node: GraphDefinition["nodes"][number];
|
|
26
|
+
registry: Registry;
|
|
27
|
+
showValues?: boolean;
|
|
28
|
+
overrides?: {
|
|
29
|
+
width?: number;
|
|
30
|
+
height?: number;
|
|
31
|
+
};
|
|
32
|
+
}): {
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
inputOrder: string[];
|
|
36
|
+
outputOrder: string[];
|
|
37
|
+
handles: Array<{
|
|
38
|
+
id: string;
|
|
39
|
+
type: "source" | "target";
|
|
40
|
+
position: Position;
|
|
41
|
+
x: number;
|
|
42
|
+
y: number;
|
|
43
|
+
width?: number;
|
|
44
|
+
height?: number;
|
|
45
|
+
}>;
|
|
46
|
+
handleLayout: Array<{
|
|
47
|
+
id: string;
|
|
48
|
+
type: "source" | "target";
|
|
49
|
+
position: Position;
|
|
50
|
+
y: number;
|
|
51
|
+
}>;
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../../../src/misc/layout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAGxE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,EACtC,QAAQ,EAAE,QAAQ,GACjB,eAAe,CAOjB;AAED,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,eAAe,CAAC,GAC9C;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB,CAMA;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE;IACrC,IAAI,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;IACvC,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD,GAAG;IACF,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAcA;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE;IAC/B,IAAI,EAAE,eAAe,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;IACvC,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD,GAAG;IACF,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,EAAE,KAAK,CAAC;QACb,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;QAC1B,QAAQ,EAAE,QAAQ,CAAC;QACnB,CAAC,EAAE,MAAM,CAAC;QACV,CAAC,EAAE,MAAM,CAAC;QACV,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;IACH,YAAY,EAAE,KAAK,CAAC;QAClB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;QAC1B,QAAQ,EAAE,QAAQ,CAAC;QACnB,CAAC,EAAE,MAAM,CAAC;KACX,CAAC,CAAC;CACJ,CAkDA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type GraphDefinition, type Registry, type ValidationIssue } from "@bian-womp/spark-graph";
|
|
2
|
+
import { Position } from "@xyflow/react";
|
|
2
3
|
import type { EdgeRunStatus, NodeRunStatus } from "../core/contracts";
|
|
3
4
|
import type { HandleIssue } from "../core/contracts";
|
|
4
|
-
import { Position } from "@xyflow/react";
|
|
5
5
|
export interface RFNode {
|
|
6
6
|
id: string;
|
|
7
7
|
position: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../../../../src/misc/mapping.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,KAAK,eAAe,
|
|
1
|
+
{"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../../../../src/misc/mapping.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,QAAQ,EACb,KAAK,eAAe,EAErB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIrD,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACnC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAAS,UAAU,GAC5C,UAAU,GACV,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,OAAO,CAAC,EAAE,KAAK,CAAC;QACd,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAAC;QAC1B,QAAQ,EAAE,QAAQ,CAAC;QACn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
1183
|
|
|
1184
|
+
function computeEffectiveHandles(node, registry) {
|
|
1185
|
+
const desc = registry.nodes.get(node.typeId);
|
|
1186
|
+
const resolved = node.resolvedHandles || {};
|
|
1187
|
+
const inputs = { ...desc?.inputs, ...resolved.inputs };
|
|
1188
|
+
const outputs = { ...desc?.outputs, ...resolved.outputs };
|
|
1189
|
+
const inputDefaults = { ...desc?.inputDefaults, ...resolved.inputDefaults };
|
|
1190
|
+
return { inputs, outputs, inputDefaults };
|
|
1191
|
+
}
|
|
1192
|
+
function countVisibleHandles(handles) {
|
|
1193
|
+
const inputIds = Object.keys(handles.inputs).filter((k) => !isInputPrivate(handles.inputs, k));
|
|
1194
|
+
const outputIds = Object.keys(handles.outputs);
|
|
1195
|
+
return { inputsCount: inputIds.length, outputsCount: outputIds.length };
|
|
1196
|
+
}
|
|
1197
|
+
function estimateNodeSize(args) {
|
|
1198
|
+
const { node, registry, showValues, overrides } = args;
|
|
1199
|
+
const { inputs, outputs } = computeEffectiveHandles(node, registry);
|
|
1200
|
+
// Count only non-private inputs for rows on left
|
|
1201
|
+
const { inputsCount, outputsCount } = countVisibleHandles({
|
|
1202
|
+
inputs,
|
|
1203
|
+
outputs,
|
|
1204
|
+
});
|
|
1205
|
+
const rows = Math.max(inputsCount, outputsCount);
|
|
1206
|
+
const baseWidth = showValues ? 320 : 240;
|
|
1207
|
+
const width = overrides?.width ?? baseWidth;
|
|
1208
|
+
const height = overrides?.height ?? NODE_HEADER_HEIGHT_PX + rows * NODE_ROW_HEIGHT_PX;
|
|
1209
|
+
return { width, height, inputsCount, outputsCount, rowCount: rows };
|
|
1210
|
+
}
|
|
1211
|
+
function layoutNode(args) {
|
|
1212
|
+
const { node, registry, showValues, overrides } = args;
|
|
1213
|
+
const { inputs, outputs } = computeEffectiveHandles(node, registry);
|
|
1214
|
+
const inputOrder = Object.keys(inputs).filter((k) => !isInputPrivate(inputs, k));
|
|
1215
|
+
const outputOrder = Object.keys(outputs);
|
|
1216
|
+
const { width, height } = estimateNodeSize({
|
|
1217
|
+
node,
|
|
1218
|
+
registry,
|
|
1219
|
+
showValues,
|
|
1220
|
+
overrides,
|
|
1221
|
+
});
|
|
1222
|
+
const HEADER = NODE_HEADER_HEIGHT_PX;
|
|
1223
|
+
const ROW = NODE_ROW_HEIGHT_PX;
|
|
1224
|
+
const handles = [
|
|
1225
|
+
...inputOrder.map((id, i) => ({
|
|
1226
|
+
id,
|
|
1227
|
+
type: "target",
|
|
1228
|
+
position: Position.Left,
|
|
1229
|
+
x: 0,
|
|
1230
|
+
y: HEADER + i * ROW,
|
|
1231
|
+
width: 1,
|
|
1232
|
+
height: ROW + 2,
|
|
1233
|
+
})),
|
|
1234
|
+
...outputOrder.map((id, i) => ({
|
|
1235
|
+
id,
|
|
1236
|
+
type: "source",
|
|
1237
|
+
position: Position.Right,
|
|
1238
|
+
x: width - 1,
|
|
1239
|
+
y: HEADER + i * ROW,
|
|
1240
|
+
width: 1,
|
|
1241
|
+
height: ROW + 2,
|
|
1242
|
+
})),
|
|
1243
|
+
];
|
|
1244
|
+
const handleLayout = [
|
|
1245
|
+
...inputOrder.map((id, i) => ({
|
|
1246
|
+
id,
|
|
1247
|
+
type: "target",
|
|
1248
|
+
position: Position.Left,
|
|
1249
|
+
y: HEADER + i * ROW + ROW / 2,
|
|
1250
|
+
})),
|
|
1251
|
+
...outputOrder.map((id, i) => ({
|
|
1252
|
+
id,
|
|
1253
|
+
type: "source",
|
|
1254
|
+
position: Position.Right,
|
|
1255
|
+
y: HEADER + i * ROW + ROW / 2,
|
|
1256
|
+
})),
|
|
1257
|
+
];
|
|
1258
|
+
return { width, height, inputOrder, outputOrder, handles, handleLayout };
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1184
1261
|
function toReactFlow(def, positions, registry, opts) {
|
|
1185
1262
|
const EDGE_STYLE_ERROR = { stroke: "#ef4444", strokeWidth: 2 };
|
|
1186
1263
|
const EDGE_STYLE_RUNNING = { stroke: "#3b82f6" };
|
|
@@ -1195,54 +1272,31 @@ function toReactFlow(def, positions, registry, opts) {
|
|
|
1195
1272
|
connectedInputs[nid].add(hid);
|
|
1196
1273
|
}
|
|
1197
1274
|
const nodes = def.nodes.map((n) => {
|
|
1198
|
-
const
|
|
1199
|
-
|
|
1200
|
-
const
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1275
|
+
const { inputs: inputSource, outputs: outputSource } = computeEffectiveHandles(n, registry);
|
|
1276
|
+
const overrideSize = opts.getDefaultNodeSize?.(n.typeId);
|
|
1277
|
+
const geom = layoutNode({
|
|
1278
|
+
node: n,
|
|
1279
|
+
registry,
|
|
1280
|
+
showValues: opts.showValues,
|
|
1281
|
+
overrides: overrideSize,
|
|
1282
|
+
});
|
|
1283
|
+
const inputHandles = geom.inputOrder.map((id) => ({
|
|
1284
|
+
id,
|
|
1285
|
+
typeId: getInputTypeId(inputSource, id),
|
|
1286
|
+
}));
|
|
1287
|
+
const outputHandles = geom.outputOrder.map((id) => ({
|
|
1208
1288
|
id,
|
|
1209
|
-
typeId: formatDeclaredTypeSignature(
|
|
1289
|
+
typeId: formatDeclaredTypeSignature(outputSource[id]),
|
|
1210
1290
|
}));
|
|
1211
1291
|
nodeHandleMap[n.nodeId] = {
|
|
1212
1292
|
inputs: new Set(inputHandles.map((h) => h.id)),
|
|
1213
1293
|
outputs: new Set(outputHandles.map((h) => h.id)),
|
|
1214
1294
|
};
|
|
1215
|
-
//
|
|
1216
|
-
const
|
|
1217
|
-
const
|
|
1218
|
-
const maxRows = Math.max(inputHandles.length, outputHandles.length);
|
|
1219
|
-
// Allow external override to dictate initial size
|
|
1220
|
-
const overrideSize = opts.getDefaultNodeSize?.(n.typeId);
|
|
1221
|
-
const initialWidth = overrideSize?.width ?? (opts.showValues ? 320 : 240);
|
|
1222
|
-
const initialHeight = overrideSize?.height ?? HEADER_SIZE + maxRows * ROW_SIZE;
|
|
1295
|
+
// Shared sizing
|
|
1296
|
+
const initialWidth = geom.width;
|
|
1297
|
+
const initialHeight = geom.height;
|
|
1223
1298
|
// Precompute handle bounds so edges can render immediately without waiting for measurement
|
|
1224
|
-
const handles =
|
|
1225
|
-
// Inputs on the left as targets
|
|
1226
|
-
...inputHandles.map((h, i) => ({
|
|
1227
|
-
id: h.id,
|
|
1228
|
-
type: "target",
|
|
1229
|
-
position: Position.Left,
|
|
1230
|
-
x: 0,
|
|
1231
|
-
y: HEADER_SIZE + i * ROW_SIZE,
|
|
1232
|
-
width: 1,
|
|
1233
|
-
height: ROW_SIZE + 2,
|
|
1234
|
-
})),
|
|
1235
|
-
// Outputs on the right as sources
|
|
1236
|
-
...outputHandles.map((h, i) => ({
|
|
1237
|
-
id: h.id,
|
|
1238
|
-
type: "source",
|
|
1239
|
-
position: Position.Right,
|
|
1240
|
-
x: initialWidth - 1,
|
|
1241
|
-
y: HEADER_SIZE + i * ROW_SIZE,
|
|
1242
|
-
width: 1,
|
|
1243
|
-
height: ROW_SIZE + 2,
|
|
1244
|
-
})),
|
|
1245
|
-
];
|
|
1299
|
+
const handles = geom.handles;
|
|
1246
1300
|
return {
|
|
1247
1301
|
id: n.nodeId,
|
|
1248
1302
|
data: {
|
|
@@ -1254,20 +1308,7 @@ function toReactFlow(def, positions, registry, opts) {
|
|
|
1254
1308
|
h.id,
|
|
1255
1309
|
!!connectedInputs[n.nodeId]?.has(h.id),
|
|
1256
1310
|
])),
|
|
1257
|
-
handleLayout:
|
|
1258
|
-
...inputHandles.map((h, i) => ({
|
|
1259
|
-
id: h.id,
|
|
1260
|
-
type: "target",
|
|
1261
|
-
position: Position.Left,
|
|
1262
|
-
y: HEADER_SIZE + i * ROW_SIZE + ROW_SIZE / 2,
|
|
1263
|
-
})),
|
|
1264
|
-
...outputHandles.map((h, i) => ({
|
|
1265
|
-
id: h.id,
|
|
1266
|
-
type: "source",
|
|
1267
|
-
position: Position.Right,
|
|
1268
|
-
y: HEADER_SIZE + i * ROW_SIZE + ROW_SIZE / 2,
|
|
1269
|
-
})),
|
|
1270
|
-
],
|
|
1311
|
+
handleLayout: geom.handleLayout,
|
|
1271
1312
|
showValues: opts.showValues,
|
|
1272
1313
|
renderWidth: initialWidth,
|
|
1273
1314
|
renderHeight: initialHeight,
|
|
@@ -1466,6 +1507,7 @@ function WorkbenchProvider({ wb, runner, registry, setRegistry, children, }) {
|
|
|
1466
1507
|
// Auto layout (simple layered layout)
|
|
1467
1508
|
const runAutoLayout = useCallback(() => {
|
|
1468
1509
|
const cur = wb.export();
|
|
1510
|
+
// Build DAG layers by indegree
|
|
1469
1511
|
const indegree = {};
|
|
1470
1512
|
const adj = {};
|
|
1471
1513
|
for (const n of cur.nodes) {
|
|
@@ -1492,14 +1534,36 @@ function WorkbenchProvider({ wb, runner, registry, setRegistry, children, }) {
|
|
|
1492
1534
|
layers.push(layer);
|
|
1493
1535
|
q.splice(0, q.length, ...next);
|
|
1494
1536
|
}
|
|
1495
|
-
|
|
1496
|
-
|
|
1537
|
+
// Size-aware placement: columns by layer, stacking nodes vertically in each column
|
|
1538
|
+
// Use the same sizing heuristic as mapping via estimateNodeSize
|
|
1539
|
+
const H_GAP = 160;
|
|
1540
|
+
const V_GAP = 24;
|
|
1497
1541
|
const pos = {};
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1542
|
+
let curX = 0;
|
|
1543
|
+
for (const layer of layers) {
|
|
1544
|
+
// Compute max width in this layer and individual heights
|
|
1545
|
+
let maxWidth = 0;
|
|
1546
|
+
const heights = {};
|
|
1547
|
+
for (const id of layer) {
|
|
1548
|
+
const node = cur.nodes.find((n) => n.nodeId === id);
|
|
1549
|
+
if (!node)
|
|
1550
|
+
continue;
|
|
1551
|
+
// Prefer showValues sizing similar to node rendering
|
|
1552
|
+
// Lazy import to avoid circular deps at module top
|
|
1553
|
+
const size = estimateNodeSize({ node, registry, showValues: true });
|
|
1554
|
+
heights[id] = size.height;
|
|
1555
|
+
if (size.width > maxWidth)
|
|
1556
|
+
maxWidth = size.width;
|
|
1557
|
+
}
|
|
1558
|
+
// Place nodes in this column
|
|
1559
|
+
let curY = 0;
|
|
1560
|
+
for (const id of layer) {
|
|
1561
|
+
const h = heights[id] ?? 0;
|
|
1562
|
+
pos[id] = { x: curX, y: curY };
|
|
1563
|
+
curY += h + V_GAP;
|
|
1564
|
+
}
|
|
1565
|
+
curX += maxWidth + H_GAP;
|
|
1566
|
+
}
|
|
1503
1567
|
wb.setPositions(pos);
|
|
1504
1568
|
}, [wb]);
|
|
1505
1569
|
const updateEdgeType = useCallback((edgeId, typeId) => wb.updateEdgeType(edgeId, typeId), [wb]);
|
|
@@ -1595,15 +1659,6 @@ function WorkbenchProvider({ wb, runner, registry, setRegistry, children, }) {
|
|
|
1595
1659
|
return add("runner", "error")(e);
|
|
1596
1660
|
});
|
|
1597
1661
|
const off3 = runner.on("invalidate", (e) => {
|
|
1598
|
-
if (e?.reason === "graph-updated") {
|
|
1599
|
-
setNodeStatus((s) => {
|
|
1600
|
-
const next = {};
|
|
1601
|
-
for (const n of wb.export().nodes) {
|
|
1602
|
-
next[n.nodeId] = { ...s[n.nodeId], invalidated: true };
|
|
1603
|
-
}
|
|
1604
|
-
return next;
|
|
1605
|
-
});
|
|
1606
|
-
}
|
|
1607
1662
|
// After build/update, pull resolved handles and merge in-place (no graphChanged)
|
|
1608
1663
|
if (e?.reason === "graph-updated" || e?.reason === "graph-built") {
|
|
1609
1664
|
refreshResolvedHandles();
|