otomato-sdk 2.0.241 → 2.0.242
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/dist/src/models/Node.js
CHANGED
|
@@ -5,6 +5,7 @@ const generatedRefs = new Set();
|
|
|
5
5
|
export class Node {
|
|
6
6
|
constructor(node) {
|
|
7
7
|
this.id = null;
|
|
8
|
+
this.isOptional = null;
|
|
8
9
|
this.id = null;
|
|
9
10
|
this.blockId = node.blockId;
|
|
10
11
|
this.name = node.name;
|
|
@@ -16,6 +17,7 @@ export class Node {
|
|
|
16
17
|
this.class = node.class;
|
|
17
18
|
this.parentInfo = node.parentInfo;
|
|
18
19
|
this.state = node.state || 'inactive';
|
|
20
|
+
this.isOptional = node.isOptional || null;
|
|
19
21
|
this.frontendHelpers = node.frontendHelpers || {};
|
|
20
22
|
if (node.ref) {
|
|
21
23
|
this.ref = node.ref;
|
|
@@ -58,6 +60,9 @@ export class Node {
|
|
|
58
60
|
setRef(ref) {
|
|
59
61
|
this.ref = ref;
|
|
60
62
|
}
|
|
63
|
+
setIsOptional(isOptional) {
|
|
64
|
+
this.isOptional = isOptional;
|
|
65
|
+
}
|
|
61
66
|
getParentInfo() {
|
|
62
67
|
return this.parentInfo;
|
|
63
68
|
}
|
|
@@ -176,6 +181,7 @@ export class Node {
|
|
|
176
181
|
blockId: this.blockId,
|
|
177
182
|
type: this.class,
|
|
178
183
|
state: this.state,
|
|
184
|
+
isOptional: this.isOptional,
|
|
179
185
|
parameters: {
|
|
180
186
|
...this.getParameters(),
|
|
181
187
|
},
|
|
@@ -232,32 +232,6 @@ export function positionWorkflowNodes(workflow) {
|
|
|
232
232
|
}
|
|
233
233
|
});
|
|
234
234
|
});
|
|
235
|
-
// Additional step: Ensure common children of multiple layer 0 triggers are centered at ROOT_X.
|
|
236
|
-
// This runs after initial layer placement and before final overlap resolution specific to children groups might occur,
|
|
237
|
-
// and crucially before parent centering which might pull triggers away.
|
|
238
|
-
for (const node of workflow.nodes) {
|
|
239
|
-
const nodeLayer = node.layer;
|
|
240
|
-
if (nodeLayer === 1) { // Check nodes in the layer immediately following triggers
|
|
241
|
-
const parents = getParents(node, workflow.edges);
|
|
242
|
-
if (parents.length > 1) { // Only if it has multiple parents
|
|
243
|
-
const allParentsAreLayer0Triggers = parents.every(p => {
|
|
244
|
-
const parentLayer = p.layer;
|
|
245
|
-
const parentIsStartingNode = getParents(p, workflow.edges).length === 0;
|
|
246
|
-
return parentLayer === 0 && parentIsStartingNode;
|
|
247
|
-
});
|
|
248
|
-
if (allParentsAreLayer0Triggers) {
|
|
249
|
-
if (node.position) { // Ensure node.position exists before trying to read node.position.y
|
|
250
|
-
node.setPosition(ROOT_X, node.position.y);
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
// This case should ideally not happen if nodes in layer 1 are already positioned by the main loop.
|
|
254
|
-
// If it does, assign a default Y based on its layer.
|
|
255
|
-
node.setPosition(ROOT_X, (nodeLayer * ySpacing) + ROOT_Y);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
235
|
// Step 4: Bottom-up Parent Centering.
|
|
262
236
|
// Now, we simply set each parent's x to the exact average of its children.
|
|
263
237
|
centerParentXPositions(workflow);
|
|
@@ -271,6 +245,42 @@ export function positionWorkflowNodes(workflow) {
|
|
|
271
245
|
return Number(a.getRef()) - Number(b.getRef());
|
|
272
246
|
});
|
|
273
247
|
});
|
|
248
|
+
// FINAL STEP: Center nodes in the main action stack only when there are multiple triggers
|
|
249
|
+
const triggers = workflow.nodes.filter(n => n.layer === 0 && getParents(n, workflow.edges).length === 0);
|
|
250
|
+
// Only apply centering if there are multiple triggers
|
|
251
|
+
if (triggers.length > 1) {
|
|
252
|
+
const triggerRefs = new Set(triggers.map(t => t.getRef()));
|
|
253
|
+
const triggerXs = triggers.map(t => t.position.x);
|
|
254
|
+
const triggerCenter = triggerXs.reduce((a, b) => a + b, 0) / triggerXs.length;
|
|
255
|
+
function getAllAncestors(node, edges, visited = new Set()) {
|
|
256
|
+
const parents = getParents(node, edges);
|
|
257
|
+
for (const parent of parents) {
|
|
258
|
+
if (!visited.has(parent.getRef())) {
|
|
259
|
+
visited.add(parent.getRef());
|
|
260
|
+
getAllAncestors(parent, edges, visited);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return visited;
|
|
264
|
+
}
|
|
265
|
+
// Helper: is a node a descendant of all triggers?
|
|
266
|
+
function isDescendantOfAllTriggers(node) {
|
|
267
|
+
const ancestors = getAllAncestors(node, workflow.edges);
|
|
268
|
+
return Array.from(triggerRefs).every(ref => ancestors.has(ref));
|
|
269
|
+
}
|
|
270
|
+
for (const node of workflow.nodes) {
|
|
271
|
+
if (node.layer === 0)
|
|
272
|
+
continue; // skip triggers
|
|
273
|
+
if (!isDescendantOfAllTriggers(node))
|
|
274
|
+
continue;
|
|
275
|
+
// Check all non-trigger ancestors
|
|
276
|
+
const ancestors = Array.from(getAllAncestors(node, workflow.edges))
|
|
277
|
+
.map(ref => workflow.nodes.find(n => n.getRef() === ref))
|
|
278
|
+
.filter(n => n && n.layer !== 0);
|
|
279
|
+
if (ancestors.every(isDescendantOfAllTriggers)) {
|
|
280
|
+
node.setPosition(triggerCenter, node.position?.y ?? 0);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
274
284
|
}
|
|
275
285
|
catch (e) {
|
|
276
286
|
console.error(e);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.0.
|
|
1
|
+
export declare const SDK_VERSION = "2.0.242";
|
|
2
2
|
export declare function compareVersions(v1: string, v2: string): number;
|
|
@@ -30,6 +30,7 @@ export declare abstract class Node {
|
|
|
30
30
|
image: string;
|
|
31
31
|
parentInfo?: ParentInfo;
|
|
32
32
|
state: NodeState;
|
|
33
|
+
isOptional: boolean | null;
|
|
33
34
|
frontendHelpers: Record<string, any>;
|
|
34
35
|
constructor(node: {
|
|
35
36
|
blockId: number;
|
|
@@ -46,6 +47,7 @@ export declare abstract class Node {
|
|
|
46
47
|
parentInfo?: ParentInfo;
|
|
47
48
|
state?: NodeState;
|
|
48
49
|
frontendHelpers?: Record<string, any>;
|
|
50
|
+
isOptional?: boolean;
|
|
49
51
|
});
|
|
50
52
|
setId(id: string): void;
|
|
51
53
|
setChainId(value: number): void;
|
|
@@ -54,6 +56,7 @@ export declare abstract class Node {
|
|
|
54
56
|
setPosition(x: number, y: number): void;
|
|
55
57
|
getRef(): string;
|
|
56
58
|
setRef(ref: string): void;
|
|
59
|
+
setIsOptional(isOptional: boolean): void;
|
|
57
60
|
getParentInfo(): ParentInfo | undefined;
|
|
58
61
|
getState(): NodeState;
|
|
59
62
|
protected setParameter(key: string, value: any): void;
|