Skip to content

Commit 819b1ac

Browse files
authored
feat(thumbnail): add condition node (#100)
1 parent 7214ae8 commit 819b1ac

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
// Disable the default formatter, use eslint instead
3+
"eslint.enable": true,
34
"prettier.enable": false,
45
"editor.formatOnSave": false,
56

src/utils/thumbnail.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ interface NodeThumbnail {
4747
outputHandleDefs?: (OutputHandleDef | GroupDividerDef)[];
4848
additionalOutputs?: boolean;
4949
additionalOutputDefs?: OutputHandleDef[];
50+
conditionHandleDefs?: ConditionHandleDef[];
51+
defaultConditionHandleDef?: DefaultConditionHandleDef;
5052
slots?: SlotProvider[];
5153
slotNodeDefs?: SlotNodeDef[];
5254
handleInputsFrom?: HandleInputFrom[];
@@ -88,6 +90,22 @@ interface InputHandleDef extends OutputHandleDef {
8890

8991
interface ValueHandleDef extends InputHandleDef { }
9092

93+
interface ConditionExpression {
94+
input_handle: string;
95+
operator: string;
96+
value?: any;
97+
}
98+
99+
interface DefaultConditionHandleDef {
100+
handle: string;
101+
description?: string;
102+
}
103+
104+
interface ConditionHandleDef extends DefaultConditionHandleDef {
105+
logical?: string;
106+
expressions?: ConditionExpression[];
107+
}
108+
91109
interface HandleInputFrom {
92110
handle: string;
93111
value?: any;
@@ -150,6 +168,13 @@ interface Node {
150168
slots?: SlotProvider[];
151169

152170
slot?: InlineSlotBlock;
171+
172+
conditions?: InlineConditionBlock;
173+
}
174+
175+
interface InlineConditionBlock {
176+
cases?: ConditionHandleDef[];
177+
default?: DefaultConditionHandleDef;
153178
}
154179

155180
interface InlineSlotBlock {
@@ -182,6 +207,7 @@ enum NODE_TYPE {
182207
SubflowNode = "subflow_node",
183208
SlotNode = "slot_node",
184209
ValueNode = "value_node",
210+
ConditionNode = "condition_node",
185211
}
186212

187213
const isFile = async (path: string): Promise<boolean> => {
@@ -377,6 +403,13 @@ export class Thumbnail implements ThumbnailProvider {
377403
node.slots = raw.slots;
378404
node.handleInputsFrom = raw.inputs_from;
379405
}
406+
else if (typeof raw.conditions === "object" && raw.conditions) {
407+
node.type = NODE_TYPE.ConditionNode;
408+
node.inputHandleDefs = raw.inputs_def;
409+
node.conditionHandleDefs = raw.conditions.cases;
410+
node.defaultConditionHandleDef = raw.conditions.default;
411+
node.handleInputsFrom = raw.inputs_from;
412+
}
380413
else {
381414
// Not implemented.
382415
node.type = NODE_TYPE.ErrorNode;

0 commit comments

Comments
 (0)