@foresthubai/workflow-builder 0.3.0 → 0.4.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 +661 -661
- package/NOTICE +16 -16
- package/README.md +110 -93
- package/dist/components/ui/command.d.ts +2 -2
- package/dist/components/ui/input.d.ts +1 -1
- package/dist/components/ui/resizable.d.ts +1 -1
- package/dist/components/ui/textarea.d.ts +1 -1
- package/dist/graph/BaseNode.js +10 -10
- package/dist/graph/reactFlowRegistry.d.ts.map +1 -1
- package/dist/lib/utils.d.ts +3 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +6 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/toolbars/CanvasTabsToolbar.d.ts +11 -0
- package/dist/toolbars/CanvasTabsToolbar.d.ts.map +1 -0
- package/dist/toolbars/CanvasTabsToolbar.js +101 -0
- package/dist/toolbars/CanvasTabsToolbar.js.map +1 -0
- package/package.json +2 -2
- package/src/BuilderLayout.tsx +345 -345
- package/src/Canvas.tsx +261 -261
- package/src/CanvasEditor.tsx +142 -142
- package/src/CanvasTabsToolbar.tsx +176 -176
- package/src/RightConfigPanel.tsx +266 -266
- package/src/WorkflowBuilder.tsx +412 -412
- package/src/cn.ts +6 -6
- package/src/components/ui/add-button.tsx +39 -39
- package/src/components/ui/alert-dialog.tsx +141 -141
- package/src/components/ui/alert.tsx +59 -59
- package/src/components/ui/badge.tsx +36 -36
- package/src/components/ui/button.tsx +85 -85
- package/src/components/ui/card.tsx +79 -79
- package/src/components/ui/checkbox.tsx +28 -28
- package/src/components/ui/collapsible.tsx +9 -9
- package/src/components/ui/command.tsx +153 -153
- package/src/components/ui/delete-button.tsx +23 -23
- package/src/components/ui/dialog.tsx +125 -125
- package/src/components/ui/dropdown-menu.tsx +198 -198
- package/src/components/ui/input.tsx +55 -55
- package/src/components/ui/label.tsx +24 -24
- package/src/components/ui/readonly-banner.tsx +15 -15
- package/src/components/ui/resizable.tsx +43 -43
- package/src/components/ui/scroll-area.tsx +102 -102
- package/src/components/ui/select.tsx +160 -160
- package/src/components/ui/separator.tsx +29 -29
- package/src/components/ui/switch.tsx +27 -27
- package/src/components/ui/textarea.tsx +51 -51
- package/src/components/ui/toast.tsx +127 -127
- package/src/components/ui/toaster.tsx +33 -33
- package/src/components/ui/toggle-group.tsx +59 -59
- package/src/components/ui/toggle.tsx +43 -43
- package/src/components/ui/tooltip.tsx +32 -32
- package/src/dialogs/NodePickerDialog.tsx +84 -84
- package/src/dialogs/ValidationDialog.tsx +184 -184
- package/src/graph/BaseNode.tsx +557 -557
- package/src/graph/CustomEdge.tsx +185 -185
- package/src/graph/CustomNode.tsx +16 -16
- package/src/graph/FunctionCallNode.tsx +30 -30
- package/src/graph/PortHandle.tsx +189 -189
- package/src/graph/reactFlowRegistry.ts +26 -26
- package/src/hooks/use-toast.ts +125 -125
- package/src/hooks/useAvailableVariables.ts +20 -20
- package/src/hooks/useCanvasHistory.ts +22 -22
- package/src/hooks/useCanvasTabs.ts +168 -168
- package/src/hooks/useFunctionDiagnosticsSync.ts +40 -40
- package/src/hooks/useFunctionRegistry.ts +26 -26
- package/src/hooks/useFunctions.ts +44 -44
- package/src/hooks/useGraph.ts +161 -161
- package/src/hooks/useNodeDefinitions.ts +82 -82
- package/src/hooks/useParamErrors.ts +26 -26
- package/src/hooks/useResolvedTheme.ts +30 -30
- package/src/hooks/useResourceDiagnosticsSync.ts +58 -58
- package/src/hooks/useSuppressThemeTransition.ts +79 -79
- package/src/hooks/useWorkflowSerialization.ts +127 -127
- package/src/i18n/index.ts +53 -53
- package/src/i18n/locales/de.json +501 -501
- package/src/i18n/locales/en.json +557 -557
- package/src/index.ts +27 -27
- package/src/inputs/ExpressionInput.tsx +297 -297
- package/src/inputs/ParameterEditor.tsx +515 -515
- package/src/inputs/PortSection.tsx +144 -144
- package/src/panels/BuilderSidebar.tsx +301 -301
- package/src/panels/ChannelConfigPanel.tsx +49 -49
- package/src/panels/ChannelsPanel.tsx +28 -28
- package/src/panels/DebugConsolePanel.tsx +73 -73
- package/src/panels/DebugContextPanel.tsx +77 -77
- package/src/panels/DebugExternalIOPanel.tsx +180 -180
- package/src/panels/DiagnosticsPanel.tsx +170 -170
- package/src/panels/EdgeConfigPanel.tsx +104 -104
- package/src/panels/FunctionConfigPanel.tsx +179 -179
- package/src/panels/FunctionListPanel.tsx +45 -45
- package/src/panels/MemoryConfigPanel.tsx +55 -55
- package/src/panels/MemoryPanel.tsx +40 -40
- package/src/panels/ModelConfigPanel.tsx +41 -41
- package/src/panels/ModelsPanel.tsx +36 -36
- package/src/panels/NodeConfigPanel.tsx +630 -630
- package/src/panels/NodeLibrary.tsx +288 -288
- package/src/panels/ResourceConfigPanel.tsx +132 -132
- package/src/panels/ResourceListPanel.tsx +113 -113
- package/src/panels/VariableConfigPanel.tsx +161 -161
- package/src/panels/VariablesPanel.tsx +145 -145
- package/src/stores/canvasStore.test.ts +44 -44
- package/src/stores/canvasStore.ts +245 -245
- package/src/stores/debugStore.ts +74 -74
- package/src/stores/diagnosticsStore.ts +130 -130
- package/src/stores/editorStore.ts +202 -202
- package/src/styles/index.css +526 -526
- package/src/utils/categoryConstants.ts +26 -26
- package/src/utils/channelOperations.ts +86 -86
- package/src/utils/connectionRules.ts +137 -137
- package/src/utils/functionOperations.ts +179 -179
- package/src/utils/graphOperations.ts +550 -550
- package/src/utils/history.ts +207 -207
- package/src/utils/memoryOperations.ts +57 -57
- package/src/utils/migrateFunctionNodes.ts +107 -107
- package/src/utils/modelOperations.ts +55 -55
- package/src/utils/paramDisplay.ts +71 -71
- package/src/utils/resourceHelpers.ts +32 -32
- package/src/utils/translation.ts +28 -28
- package/src/utils/variableOperations.ts +75 -75
- package/tailwind-preset.ts +166 -166
|
@@ -1,288 +1,288 @@
|
|
|
1
|
-
import { Badge } from "../components/ui/badge";
|
|
2
|
-
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "../components/ui/collapsible";
|
|
3
|
-
import { Input } from "../components/ui/input";
|
|
4
|
-
import { ScrollArea } from "../components/ui/scroll-area";
|
|
5
|
-
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../components/ui/tooltip";
|
|
6
|
-
import { NodeCategory } from "@foresthubai/workflow-core/node";
|
|
7
|
-
import type { FunctionDeclaration } from "@foresthubai/workflow-core/function";
|
|
8
|
-
import { ChevronDown, ChevronDown as DropdownIcon, Hash, Search, ToggleLeft, Type } from "lucide-react";
|
|
9
|
-
import type { TFunction } from "i18next";
|
|
10
|
-
import React, { useState } from "react";
|
|
11
|
-
import { useTranslation } from "react-i18next";
|
|
12
|
-
|
|
13
|
-
import { NodeDefinition } from "@foresthubai/workflow-core/node";
|
|
14
|
-
import { categoryIcons, categoryColors } from "../utils/categoryConstants";
|
|
15
|
-
import { useEditorStore } from "../stores/editorStore";
|
|
16
|
-
import { isReadOnly } from "../WorkflowBuilder";
|
|
17
|
-
import { FunctionNodeDefinition } from "@foresthubai/workflow-core/node";
|
|
18
|
-
import { Parameter } from "@foresthubai/workflow-core/parameter";
|
|
19
|
-
import { getNodeDescription } from "../utils/translation";
|
|
20
|
-
|
|
21
|
-
const getParameterIcon = (type: string) => {
|
|
22
|
-
switch (type) {
|
|
23
|
-
case "string":
|
|
24
|
-
return Type;
|
|
25
|
-
case "number":
|
|
26
|
-
case "int":
|
|
27
|
-
case "float":
|
|
28
|
-
return Hash;
|
|
29
|
-
case "boolean":
|
|
30
|
-
case "bool":
|
|
31
|
-
return ToggleLeft;
|
|
32
|
-
case "dropdown":
|
|
33
|
-
case "selection":
|
|
34
|
-
return DropdownIcon;
|
|
35
|
-
default:
|
|
36
|
-
return Type;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const getParameterTypeLabel = (type: string, t: TFunction) => {
|
|
41
|
-
switch (type) {
|
|
42
|
-
case "string":
|
|
43
|
-
return t("paramTypeText");
|
|
44
|
-
case "int":
|
|
45
|
-
case "float":
|
|
46
|
-
case "number":
|
|
47
|
-
return t("paramTypeNumber");
|
|
48
|
-
case "boolean":
|
|
49
|
-
case "bool":
|
|
50
|
-
return t("paramTypeBoolean");
|
|
51
|
-
case "dropdown":
|
|
52
|
-
case "selection":
|
|
53
|
-
return t("paramTypeSelection");
|
|
54
|
-
case "expression":
|
|
55
|
-
return t("paramTypeExpression");
|
|
56
|
-
default:
|
|
57
|
-
return type;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const ParameterTooltip: React.FC<{
|
|
62
|
-
parameters: Parameter[];
|
|
63
|
-
t: TFunction;
|
|
64
|
-
}> = ({ parameters, t }) => {
|
|
65
|
-
if (parameters.length === 0) return null;
|
|
66
|
-
|
|
67
|
-
return (
|
|
68
|
-
<div className="space-y-2 max-w-sm">
|
|
69
|
-
<div className="font-medium text-sm">{t("parametersLabel")}</div>
|
|
70
|
-
{parameters.map((param, index) => {
|
|
71
|
-
const IconComponent = getParameterIcon(param.type);
|
|
72
|
-
const isOptional = param.optional === true;
|
|
73
|
-
return (
|
|
74
|
-
<div key={index} className="space-y-1">
|
|
75
|
-
<div className="flex items-center gap-2">
|
|
76
|
-
<IconComponent className="w-3 h-3" />
|
|
77
|
-
<span className="font-medium text-sm">{param.label}</span>
|
|
78
|
-
{!isOptional ? (
|
|
79
|
-
<Badge variant="destructive" className="text-xs">
|
|
80
|
-
{t("required")}
|
|
81
|
-
</Badge>
|
|
82
|
-
) : (
|
|
83
|
-
<Badge variant="secondary" className="text-xs">
|
|
84
|
-
{t("optional")}
|
|
85
|
-
</Badge>
|
|
86
|
-
)}
|
|
87
|
-
</div>
|
|
88
|
-
<div className="text-xs text-muted-foreground pl-5">
|
|
89
|
-
{t("typeLabel")} {getParameterTypeLabel(param.type, t)}
|
|
90
|
-
{param.default !== undefined && (
|
|
91
|
-
<span>
|
|
92
|
-
{" "}
|
|
93
|
-
• {t("defaultLabel")} {String(param.default)}
|
|
94
|
-
</span>
|
|
95
|
-
)}
|
|
96
|
-
{"options" in param && param.options && (
|
|
97
|
-
<span>
|
|
98
|
-
{" "}
|
|
99
|
-
• {t("optionsLabel")} {param.options.map((o) => o.label || o.value).join(", ")}
|
|
100
|
-
</span>
|
|
101
|
-
)}
|
|
102
|
-
</div>
|
|
103
|
-
</div>
|
|
104
|
-
);
|
|
105
|
-
})}
|
|
106
|
-
</div>
|
|
107
|
-
);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
interface NodeLibraryProps {
|
|
111
|
-
onAddNode: (nodeType: NodeDefinition, position?: { x: number; y: number }) => void;
|
|
112
|
-
nodeDefinitions: NodeDefinition[];
|
|
113
|
-
getAllCategories: () => NodeCategory[];
|
|
114
|
-
functions: FunctionDeclaration[];
|
|
115
|
-
isFunctionCanvas: boolean;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const NodeLibrary = ({
|
|
119
|
-
onAddNode,
|
|
120
|
-
nodeDefinitions,
|
|
121
|
-
getAllCategories,
|
|
122
|
-
functions,
|
|
123
|
-
isFunctionCanvas,
|
|
124
|
-
}: NodeLibraryProps) => {
|
|
125
|
-
const { t } = useTranslation();
|
|
126
|
-
const readOnly = useEditorStore((s) => isReadOnly(s.builderMode));
|
|
127
|
-
const [searchTerm, setSearchTerm] = useState("");
|
|
128
|
-
const [expandedCategories, setExpandedCategories] = useState<Set<string>>(new Set());
|
|
129
|
-
|
|
130
|
-
const search = searchTerm.toLowerCase();
|
|
131
|
-
const filteredNodes = nodeDefinitions.filter(
|
|
132
|
-
(node) =>
|
|
133
|
-
!node.isUnremovable &&
|
|
134
|
-
!(isFunctionCanvas && node.category === NodeCategory.Trigger) &&
|
|
135
|
-
// Search filter: label, category, or any tag
|
|
136
|
-
(node.label.toLowerCase().includes(search) ||
|
|
137
|
-
node.category.toLowerCase().includes(search) ||
|
|
138
|
-
(node.tags ?? []).some((tag) => tag.toLowerCase().includes(search))),
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
// Get categories that have matching nodes when searching
|
|
142
|
-
const categoriesWithMatches = new Set(filteredNodes.map((node) => node.category));
|
|
143
|
-
|
|
144
|
-
const toggleCategory = (category: NodeCategory) => {
|
|
145
|
-
const newExpanded = new Set(expandedCategories);
|
|
146
|
-
if (newExpanded.has(category)) {
|
|
147
|
-
newExpanded.delete(category);
|
|
148
|
-
} else {
|
|
149
|
-
newExpanded.add(category);
|
|
150
|
-
}
|
|
151
|
-
setExpandedCategories(newExpanded);
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
// When searching, auto-expand categories with matches
|
|
155
|
-
const isCategoryExpanded = (category: NodeCategory) => {
|
|
156
|
-
if (searchTerm.trim() && categoriesWithMatches.has(category)) {
|
|
157
|
-
return true;
|
|
158
|
-
}
|
|
159
|
-
return expandedCategories.has(category);
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
const hasResults = filteredNodes.length > 0;
|
|
163
|
-
|
|
164
|
-
return (
|
|
165
|
-
<div className="h-full flex flex-col">
|
|
166
|
-
{/* Search */}
|
|
167
|
-
<div className="relative shrink-0">
|
|
168
|
-
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground pointer-events-none" />
|
|
169
|
-
<Input
|
|
170
|
-
placeholder={t("searchBlocks")}
|
|
171
|
-
value={searchTerm}
|
|
172
|
-
onChange={(e) => setSearchTerm(e.target.value)}
|
|
173
|
-
className="pl-10 h-9 rounded-lg"
|
|
174
|
-
/>
|
|
175
|
-
</div>
|
|
176
|
-
|
|
177
|
-
<ScrollArea className="flex-1 mt-3">
|
|
178
|
-
{/* disableHoverableContent: close the tooltip as soon as the cursor
|
|
179
|
-
leaves the tile, instead of keeping it open when the pointer moves
|
|
180
|
-
onto the description itself. */}
|
|
181
|
-
<TooltipProvider disableHoverableContent>
|
|
182
|
-
{/* px-1 keeps tile hover borders off the scroll-clip edge */}
|
|
183
|
-
<div className="flex flex-col gap-0.5 px-1 pb-4">
|
|
184
|
-
{!hasResults && (
|
|
185
|
-
<p className="text-sm text-muted-foreground text-center py-10">{t("noResults", "No matching nodes")}</p>
|
|
186
|
-
)}
|
|
187
|
-
{getAllCategories().map((category) => {
|
|
188
|
-
const categoryNodes = filteredNodes.filter((node) => node.category === category);
|
|
189
|
-
if (categoryNodes.length === 0) return null;
|
|
190
|
-
|
|
191
|
-
const isExpanded = isCategoryExpanded(category);
|
|
192
|
-
const CategoryIcon = categoryIcons[category];
|
|
193
|
-
const iconChipClass = categoryColors[category] ?? "bg-muted text-muted-foreground border-border";
|
|
194
|
-
|
|
195
|
-
return (
|
|
196
|
-
<Collapsible key={category} open={isExpanded} onOpenChange={() => toggleCategory(category)}>
|
|
197
|
-
<CollapsibleTrigger className="flex items-center gap-2 w-full px-2 py-1.5 rounded-md text-left hover:bg-muted/50 transition-colors group">
|
|
198
|
-
<ChevronDown
|
|
199
|
-
className={`w-4 h-4 text-muted-foreground transition-transform duration-200 ${
|
|
200
|
-
isExpanded ? "" : "-rotate-90"
|
|
201
|
-
}`}
|
|
202
|
-
/>
|
|
203
|
-
{CategoryIcon && <CategoryIcon className="w-4 h-4 text-muted-foreground shrink-0" />}
|
|
204
|
-
<span className="flex-1 font-medium text-sm truncate">{category}</span>
|
|
205
|
-
<span className="text-xs text-muted-foreground tabular-nums">{categoryNodes.length}</span>
|
|
206
|
-
</CollapsibleTrigger>
|
|
207
|
-
|
|
208
|
-
<CollapsibleContent>
|
|
209
|
-
<div className="grid grid-cols-2 gap-1.5 px-1 pt-1.5 pb-2">
|
|
210
|
-
{categoryNodes.map((nodedef) => {
|
|
211
|
-
const staticParams = nodedef.parameters;
|
|
212
|
-
const nodeKey = `${nodedef.type}-${"functionInfo" in nodedef ? (nodedef as FunctionNodeDefinition).functionInfo.id : ""}`;
|
|
213
|
-
const hasParams = staticParams.length > 0;
|
|
214
|
-
const description = getNodeDescription(t, nodedef);
|
|
215
|
-
const firstTag = nodedef.tags?.[0];
|
|
216
|
-
|
|
217
|
-
const tile = (
|
|
218
|
-
<button
|
|
219
|
-
type="button"
|
|
220
|
-
draggable={!readOnly}
|
|
221
|
-
onDragStart={
|
|
222
|
-
readOnly
|
|
223
|
-
? undefined
|
|
224
|
-
: (e) => {
|
|
225
|
-
const dragData = { nodeDef: nodedef };
|
|
226
|
-
e.dataTransfer.setData("application/json", JSON.stringify(dragData));
|
|
227
|
-
e.dataTransfer.effectAllowed = "copy";
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
onClick={readOnly ? undefined : () => onAddNode(nodedef)}
|
|
231
|
-
disabled={readOnly}
|
|
232
|
-
className={`relative flex flex-col items-center gap-2 rounded-lg border border-border bg-card p-2.5 text-center transition-colors duration-150 ${
|
|
233
|
-
readOnly
|
|
234
|
-
? "opacity-60 cursor-default"
|
|
235
|
-
: "cursor-grab active:cursor-grabbing hover:border-primary/50 hover:bg-accent/40"
|
|
236
|
-
}`}
|
|
237
|
-
>
|
|
238
|
-
<div
|
|
239
|
-
className={`flex items-center justify-center w-9 h-9 rounded-lg border ${iconChipClass}`}
|
|
240
|
-
>
|
|
241
|
-
{CategoryIcon && <CategoryIcon className="w-4 h-4" />}
|
|
242
|
-
</div>
|
|
243
|
-
<span className="text-[11px] font-medium leading-tight line-clamp-2 w-full">
|
|
244
|
-
{nodedef.label}
|
|
245
|
-
</span>
|
|
246
|
-
{firstTag && (
|
|
247
|
-
<Badge
|
|
248
|
-
variant="secondary"
|
|
249
|
-
className="absolute top-1 right-1 text-[9px] h-3.5 px-1 font-normal leading-none"
|
|
250
|
-
>
|
|
251
|
-
{firstTag}
|
|
252
|
-
</Badge>
|
|
253
|
-
)}
|
|
254
|
-
</button>
|
|
255
|
-
);
|
|
256
|
-
|
|
257
|
-
const hasTooltipContent = description || hasParams;
|
|
258
|
-
if (!hasTooltipContent) {
|
|
259
|
-
return <React.Fragment key={nodeKey}>{tile}</React.Fragment>;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
return (
|
|
263
|
-
<Tooltip key={nodeKey} delayDuration={300}>
|
|
264
|
-
<TooltipTrigger asChild>{tile}</TooltipTrigger>
|
|
265
|
-
<TooltipContent side="right" className="max-w-sm pointer-events-none">
|
|
266
|
-
<div className="space-y-2">
|
|
267
|
-
{description && (
|
|
268
|
-
<p className="text-xs text-muted-foreground leading-relaxed">{description}</p>
|
|
269
|
-
)}
|
|
270
|
-
{hasParams && <ParameterTooltip parameters={staticParams} t={t} />}
|
|
271
|
-
</div>
|
|
272
|
-
</TooltipContent>
|
|
273
|
-
</Tooltip>
|
|
274
|
-
);
|
|
275
|
-
})}
|
|
276
|
-
</div>
|
|
277
|
-
</CollapsibleContent>
|
|
278
|
-
</Collapsible>
|
|
279
|
-
);
|
|
280
|
-
})}
|
|
281
|
-
</div>
|
|
282
|
-
</TooltipProvider>
|
|
283
|
-
</ScrollArea>
|
|
284
|
-
</div>
|
|
285
|
-
);
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
export default NodeLibrary;
|
|
1
|
+
import { Badge } from "../components/ui/badge";
|
|
2
|
+
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "../components/ui/collapsible";
|
|
3
|
+
import { Input } from "../components/ui/input";
|
|
4
|
+
import { ScrollArea } from "../components/ui/scroll-area";
|
|
5
|
+
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../components/ui/tooltip";
|
|
6
|
+
import { NodeCategory } from "@foresthubai/workflow-core/node";
|
|
7
|
+
import type { FunctionDeclaration } from "@foresthubai/workflow-core/function";
|
|
8
|
+
import { ChevronDown, ChevronDown as DropdownIcon, Hash, Search, ToggleLeft, Type } from "lucide-react";
|
|
9
|
+
import type { TFunction } from "i18next";
|
|
10
|
+
import React, { useState } from "react";
|
|
11
|
+
import { useTranslation } from "react-i18next";
|
|
12
|
+
|
|
13
|
+
import { NodeDefinition } from "@foresthubai/workflow-core/node";
|
|
14
|
+
import { categoryIcons, categoryColors } from "../utils/categoryConstants";
|
|
15
|
+
import { useEditorStore } from "../stores/editorStore";
|
|
16
|
+
import { isReadOnly } from "../WorkflowBuilder";
|
|
17
|
+
import { FunctionNodeDefinition } from "@foresthubai/workflow-core/node";
|
|
18
|
+
import { Parameter } from "@foresthubai/workflow-core/parameter";
|
|
19
|
+
import { getNodeDescription } from "../utils/translation";
|
|
20
|
+
|
|
21
|
+
const getParameterIcon = (type: string) => {
|
|
22
|
+
switch (type) {
|
|
23
|
+
case "string":
|
|
24
|
+
return Type;
|
|
25
|
+
case "number":
|
|
26
|
+
case "int":
|
|
27
|
+
case "float":
|
|
28
|
+
return Hash;
|
|
29
|
+
case "boolean":
|
|
30
|
+
case "bool":
|
|
31
|
+
return ToggleLeft;
|
|
32
|
+
case "dropdown":
|
|
33
|
+
case "selection":
|
|
34
|
+
return DropdownIcon;
|
|
35
|
+
default:
|
|
36
|
+
return Type;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const getParameterTypeLabel = (type: string, t: TFunction) => {
|
|
41
|
+
switch (type) {
|
|
42
|
+
case "string":
|
|
43
|
+
return t("paramTypeText");
|
|
44
|
+
case "int":
|
|
45
|
+
case "float":
|
|
46
|
+
case "number":
|
|
47
|
+
return t("paramTypeNumber");
|
|
48
|
+
case "boolean":
|
|
49
|
+
case "bool":
|
|
50
|
+
return t("paramTypeBoolean");
|
|
51
|
+
case "dropdown":
|
|
52
|
+
case "selection":
|
|
53
|
+
return t("paramTypeSelection");
|
|
54
|
+
case "expression":
|
|
55
|
+
return t("paramTypeExpression");
|
|
56
|
+
default:
|
|
57
|
+
return type;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const ParameterTooltip: React.FC<{
|
|
62
|
+
parameters: Parameter[];
|
|
63
|
+
t: TFunction;
|
|
64
|
+
}> = ({ parameters, t }) => {
|
|
65
|
+
if (parameters.length === 0) return null;
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<div className="space-y-2 max-w-sm">
|
|
69
|
+
<div className="font-medium text-sm">{t("parametersLabel")}</div>
|
|
70
|
+
{parameters.map((param, index) => {
|
|
71
|
+
const IconComponent = getParameterIcon(param.type);
|
|
72
|
+
const isOptional = param.optional === true;
|
|
73
|
+
return (
|
|
74
|
+
<div key={index} className="space-y-1">
|
|
75
|
+
<div className="flex items-center gap-2">
|
|
76
|
+
<IconComponent className="w-3 h-3" />
|
|
77
|
+
<span className="font-medium text-sm">{param.label}</span>
|
|
78
|
+
{!isOptional ? (
|
|
79
|
+
<Badge variant="destructive" className="text-xs">
|
|
80
|
+
{t("required")}
|
|
81
|
+
</Badge>
|
|
82
|
+
) : (
|
|
83
|
+
<Badge variant="secondary" className="text-xs">
|
|
84
|
+
{t("optional")}
|
|
85
|
+
</Badge>
|
|
86
|
+
)}
|
|
87
|
+
</div>
|
|
88
|
+
<div className="text-xs text-muted-foreground pl-5">
|
|
89
|
+
{t("typeLabel")} {getParameterTypeLabel(param.type, t)}
|
|
90
|
+
{param.default !== undefined && (
|
|
91
|
+
<span>
|
|
92
|
+
{" "}
|
|
93
|
+
• {t("defaultLabel")} {String(param.default)}
|
|
94
|
+
</span>
|
|
95
|
+
)}
|
|
96
|
+
{"options" in param && param.options && (
|
|
97
|
+
<span>
|
|
98
|
+
{" "}
|
|
99
|
+
• {t("optionsLabel")} {param.options.map((o) => o.label || o.value).join(", ")}
|
|
100
|
+
</span>
|
|
101
|
+
)}
|
|
102
|
+
</div>
|
|
103
|
+
</div>
|
|
104
|
+
);
|
|
105
|
+
})}
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
interface NodeLibraryProps {
|
|
111
|
+
onAddNode: (nodeType: NodeDefinition, position?: { x: number; y: number }) => void;
|
|
112
|
+
nodeDefinitions: NodeDefinition[];
|
|
113
|
+
getAllCategories: () => NodeCategory[];
|
|
114
|
+
functions: FunctionDeclaration[];
|
|
115
|
+
isFunctionCanvas: boolean;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const NodeLibrary = ({
|
|
119
|
+
onAddNode,
|
|
120
|
+
nodeDefinitions,
|
|
121
|
+
getAllCategories,
|
|
122
|
+
functions,
|
|
123
|
+
isFunctionCanvas,
|
|
124
|
+
}: NodeLibraryProps) => {
|
|
125
|
+
const { t } = useTranslation();
|
|
126
|
+
const readOnly = useEditorStore((s) => isReadOnly(s.builderMode));
|
|
127
|
+
const [searchTerm, setSearchTerm] = useState("");
|
|
128
|
+
const [expandedCategories, setExpandedCategories] = useState<Set<string>>(new Set());
|
|
129
|
+
|
|
130
|
+
const search = searchTerm.toLowerCase();
|
|
131
|
+
const filteredNodes = nodeDefinitions.filter(
|
|
132
|
+
(node) =>
|
|
133
|
+
!node.isUnremovable &&
|
|
134
|
+
!(isFunctionCanvas && node.category === NodeCategory.Trigger) &&
|
|
135
|
+
// Search filter: label, category, or any tag
|
|
136
|
+
(node.label.toLowerCase().includes(search) ||
|
|
137
|
+
node.category.toLowerCase().includes(search) ||
|
|
138
|
+
(node.tags ?? []).some((tag) => tag.toLowerCase().includes(search))),
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
// Get categories that have matching nodes when searching
|
|
142
|
+
const categoriesWithMatches = new Set(filteredNodes.map((node) => node.category));
|
|
143
|
+
|
|
144
|
+
const toggleCategory = (category: NodeCategory) => {
|
|
145
|
+
const newExpanded = new Set(expandedCategories);
|
|
146
|
+
if (newExpanded.has(category)) {
|
|
147
|
+
newExpanded.delete(category);
|
|
148
|
+
} else {
|
|
149
|
+
newExpanded.add(category);
|
|
150
|
+
}
|
|
151
|
+
setExpandedCategories(newExpanded);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// When searching, auto-expand categories with matches
|
|
155
|
+
const isCategoryExpanded = (category: NodeCategory) => {
|
|
156
|
+
if (searchTerm.trim() && categoriesWithMatches.has(category)) {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
return expandedCategories.has(category);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const hasResults = filteredNodes.length > 0;
|
|
163
|
+
|
|
164
|
+
return (
|
|
165
|
+
<div className="h-full flex flex-col">
|
|
166
|
+
{/* Search */}
|
|
167
|
+
<div className="relative shrink-0">
|
|
168
|
+
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground pointer-events-none" />
|
|
169
|
+
<Input
|
|
170
|
+
placeholder={t("searchBlocks")}
|
|
171
|
+
value={searchTerm}
|
|
172
|
+
onChange={(e) => setSearchTerm(e.target.value)}
|
|
173
|
+
className="pl-10 h-9 rounded-lg"
|
|
174
|
+
/>
|
|
175
|
+
</div>
|
|
176
|
+
|
|
177
|
+
<ScrollArea className="flex-1 mt-3">
|
|
178
|
+
{/* disableHoverableContent: close the tooltip as soon as the cursor
|
|
179
|
+
leaves the tile, instead of keeping it open when the pointer moves
|
|
180
|
+
onto the description itself. */}
|
|
181
|
+
<TooltipProvider disableHoverableContent>
|
|
182
|
+
{/* px-1 keeps tile hover borders off the scroll-clip edge */}
|
|
183
|
+
<div className="flex flex-col gap-0.5 px-1 pb-4">
|
|
184
|
+
{!hasResults && (
|
|
185
|
+
<p className="text-sm text-muted-foreground text-center py-10">{t("noResults", "No matching nodes")}</p>
|
|
186
|
+
)}
|
|
187
|
+
{getAllCategories().map((category) => {
|
|
188
|
+
const categoryNodes = filteredNodes.filter((node) => node.category === category);
|
|
189
|
+
if (categoryNodes.length === 0) return null;
|
|
190
|
+
|
|
191
|
+
const isExpanded = isCategoryExpanded(category);
|
|
192
|
+
const CategoryIcon = categoryIcons[category];
|
|
193
|
+
const iconChipClass = categoryColors[category] ?? "bg-muted text-muted-foreground border-border";
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
<Collapsible key={category} open={isExpanded} onOpenChange={() => toggleCategory(category)}>
|
|
197
|
+
<CollapsibleTrigger className="flex items-center gap-2 w-full px-2 py-1.5 rounded-md text-left hover:bg-muted/50 transition-colors group">
|
|
198
|
+
<ChevronDown
|
|
199
|
+
className={`w-4 h-4 text-muted-foreground transition-transform duration-200 ${
|
|
200
|
+
isExpanded ? "" : "-rotate-90"
|
|
201
|
+
}`}
|
|
202
|
+
/>
|
|
203
|
+
{CategoryIcon && <CategoryIcon className="w-4 h-4 text-muted-foreground shrink-0" />}
|
|
204
|
+
<span className="flex-1 font-medium text-sm truncate">{category}</span>
|
|
205
|
+
<span className="text-xs text-muted-foreground tabular-nums">{categoryNodes.length}</span>
|
|
206
|
+
</CollapsibleTrigger>
|
|
207
|
+
|
|
208
|
+
<CollapsibleContent>
|
|
209
|
+
<div className="grid grid-cols-2 gap-1.5 px-1 pt-1.5 pb-2">
|
|
210
|
+
{categoryNodes.map((nodedef) => {
|
|
211
|
+
const staticParams = nodedef.parameters;
|
|
212
|
+
const nodeKey = `${nodedef.type}-${"functionInfo" in nodedef ? (nodedef as FunctionNodeDefinition).functionInfo.id : ""}`;
|
|
213
|
+
const hasParams = staticParams.length > 0;
|
|
214
|
+
const description = getNodeDescription(t, nodedef);
|
|
215
|
+
const firstTag = nodedef.tags?.[0];
|
|
216
|
+
|
|
217
|
+
const tile = (
|
|
218
|
+
<button
|
|
219
|
+
type="button"
|
|
220
|
+
draggable={!readOnly}
|
|
221
|
+
onDragStart={
|
|
222
|
+
readOnly
|
|
223
|
+
? undefined
|
|
224
|
+
: (e) => {
|
|
225
|
+
const dragData = { nodeDef: nodedef };
|
|
226
|
+
e.dataTransfer.setData("application/json", JSON.stringify(dragData));
|
|
227
|
+
e.dataTransfer.effectAllowed = "copy";
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
onClick={readOnly ? undefined : () => onAddNode(nodedef)}
|
|
231
|
+
disabled={readOnly}
|
|
232
|
+
className={`relative flex flex-col items-center gap-2 rounded-lg border border-border bg-card p-2.5 text-center transition-colors duration-150 ${
|
|
233
|
+
readOnly
|
|
234
|
+
? "opacity-60 cursor-default"
|
|
235
|
+
: "cursor-grab active:cursor-grabbing hover:border-primary/50 hover:bg-accent/40"
|
|
236
|
+
}`}
|
|
237
|
+
>
|
|
238
|
+
<div
|
|
239
|
+
className={`flex items-center justify-center w-9 h-9 rounded-lg border ${iconChipClass}`}
|
|
240
|
+
>
|
|
241
|
+
{CategoryIcon && <CategoryIcon className="w-4 h-4" />}
|
|
242
|
+
</div>
|
|
243
|
+
<span className="text-[11px] font-medium leading-tight line-clamp-2 w-full">
|
|
244
|
+
{nodedef.label}
|
|
245
|
+
</span>
|
|
246
|
+
{firstTag && (
|
|
247
|
+
<Badge
|
|
248
|
+
variant="secondary"
|
|
249
|
+
className="absolute top-1 right-1 text-[9px] h-3.5 px-1 font-normal leading-none"
|
|
250
|
+
>
|
|
251
|
+
{firstTag}
|
|
252
|
+
</Badge>
|
|
253
|
+
)}
|
|
254
|
+
</button>
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
const hasTooltipContent = description || hasParams;
|
|
258
|
+
if (!hasTooltipContent) {
|
|
259
|
+
return <React.Fragment key={nodeKey}>{tile}</React.Fragment>;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return (
|
|
263
|
+
<Tooltip key={nodeKey} delayDuration={300}>
|
|
264
|
+
<TooltipTrigger asChild>{tile}</TooltipTrigger>
|
|
265
|
+
<TooltipContent side="right" className="max-w-sm pointer-events-none">
|
|
266
|
+
<div className="space-y-2">
|
|
267
|
+
{description && (
|
|
268
|
+
<p className="text-xs text-muted-foreground leading-relaxed">{description}</p>
|
|
269
|
+
)}
|
|
270
|
+
{hasParams && <ParameterTooltip parameters={staticParams} t={t} />}
|
|
271
|
+
</div>
|
|
272
|
+
</TooltipContent>
|
|
273
|
+
</Tooltip>
|
|
274
|
+
);
|
|
275
|
+
})}
|
|
276
|
+
</div>
|
|
277
|
+
</CollapsibleContent>
|
|
278
|
+
</Collapsible>
|
|
279
|
+
);
|
|
280
|
+
})}
|
|
281
|
+
</div>
|
|
282
|
+
</TooltipProvider>
|
|
283
|
+
</ScrollArea>
|
|
284
|
+
</div>
|
|
285
|
+
);
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
export default NodeLibrary;
|