@foresthubai/workflow-builder 0.3.0 → 0.4.1

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.
Files changed (124) hide show
  1. package/LICENSE +661 -661
  2. package/NOTICE +16 -16
  3. package/README.md +110 -93
  4. package/dist/components/ui/command.d.ts +2 -2
  5. package/dist/components/ui/input.d.ts +1 -1
  6. package/dist/components/ui/resizable.d.ts +1 -1
  7. package/dist/components/ui/textarea.d.ts +1 -1
  8. package/dist/graph/BaseNode.js +10 -10
  9. package/dist/graph/reactFlowRegistry.d.ts.map +1 -1
  10. package/dist/lib/utils.d.ts +3 -0
  11. package/dist/lib/utils.d.ts.map +1 -0
  12. package/dist/lib/utils.js +6 -0
  13. package/dist/lib/utils.js.map +1 -0
  14. package/dist/stores/editorStore.d.ts +0 -1
  15. package/dist/stores/editorStore.d.ts.map +1 -1
  16. package/dist/stores/editorStore.js +1 -11
  17. package/dist/stores/editorStore.js.map +1 -1
  18. package/dist/toolbars/CanvasTabsToolbar.d.ts +11 -0
  19. package/dist/toolbars/CanvasTabsToolbar.d.ts.map +1 -0
  20. package/dist/toolbars/CanvasTabsToolbar.js +101 -0
  21. package/dist/toolbars/CanvasTabsToolbar.js.map +1 -0
  22. package/package.json +2 -2
  23. package/src/BuilderLayout.tsx +345 -345
  24. package/src/Canvas.tsx +261 -261
  25. package/src/CanvasEditor.tsx +142 -142
  26. package/src/CanvasTabsToolbar.tsx +176 -176
  27. package/src/RightConfigPanel.tsx +266 -266
  28. package/src/WorkflowBuilder.tsx +412 -412
  29. package/src/cn.ts +6 -6
  30. package/src/components/ui/add-button.tsx +39 -39
  31. package/src/components/ui/alert-dialog.tsx +141 -141
  32. package/src/components/ui/alert.tsx +59 -59
  33. package/src/components/ui/badge.tsx +36 -36
  34. package/src/components/ui/button.tsx +85 -85
  35. package/src/components/ui/card.tsx +79 -79
  36. package/src/components/ui/checkbox.tsx +28 -28
  37. package/src/components/ui/collapsible.tsx +9 -9
  38. package/src/components/ui/command.tsx +153 -153
  39. package/src/components/ui/delete-button.tsx +23 -23
  40. package/src/components/ui/dialog.tsx +125 -125
  41. package/src/components/ui/dropdown-menu.tsx +198 -198
  42. package/src/components/ui/input.tsx +55 -55
  43. package/src/components/ui/label.tsx +24 -24
  44. package/src/components/ui/readonly-banner.tsx +15 -15
  45. package/src/components/ui/resizable.tsx +43 -43
  46. package/src/components/ui/scroll-area.tsx +102 -102
  47. package/src/components/ui/select.tsx +160 -160
  48. package/src/components/ui/separator.tsx +29 -29
  49. package/src/components/ui/switch.tsx +27 -27
  50. package/src/components/ui/textarea.tsx +51 -51
  51. package/src/components/ui/toast.tsx +127 -127
  52. package/src/components/ui/toaster.tsx +33 -33
  53. package/src/components/ui/toggle-group.tsx +59 -59
  54. package/src/components/ui/toggle.tsx +43 -43
  55. package/src/components/ui/tooltip.tsx +32 -32
  56. package/src/dialogs/NodePickerDialog.tsx +84 -84
  57. package/src/dialogs/ValidationDialog.tsx +184 -184
  58. package/src/graph/BaseNode.tsx +557 -557
  59. package/src/graph/CustomEdge.tsx +185 -185
  60. package/src/graph/CustomNode.tsx +16 -16
  61. package/src/graph/FunctionCallNode.tsx +30 -30
  62. package/src/graph/PortHandle.tsx +189 -189
  63. package/src/graph/reactFlowRegistry.ts +26 -26
  64. package/src/hooks/use-toast.ts +125 -125
  65. package/src/hooks/useAvailableVariables.ts +20 -20
  66. package/src/hooks/useCanvasHistory.ts +22 -22
  67. package/src/hooks/useCanvasTabs.ts +168 -168
  68. package/src/hooks/useFunctionDiagnosticsSync.ts +40 -40
  69. package/src/hooks/useFunctionRegistry.ts +26 -26
  70. package/src/hooks/useFunctions.ts +44 -44
  71. package/src/hooks/useGraph.ts +161 -161
  72. package/src/hooks/useNodeDefinitions.ts +82 -82
  73. package/src/hooks/useParamErrors.ts +26 -26
  74. package/src/hooks/useResolvedTheme.ts +30 -30
  75. package/src/hooks/useResourceDiagnosticsSync.ts +58 -58
  76. package/src/hooks/useSuppressThemeTransition.ts +79 -79
  77. package/src/hooks/useWorkflowSerialization.ts +127 -127
  78. package/src/i18n/index.ts +53 -53
  79. package/src/i18n/locales/de.json +501 -501
  80. package/src/i18n/locales/en.json +557 -557
  81. package/src/index.ts +27 -27
  82. package/src/inputs/ExpressionInput.tsx +297 -297
  83. package/src/inputs/ParameterEditor.tsx +515 -515
  84. package/src/inputs/PortSection.tsx +144 -144
  85. package/src/panels/BuilderSidebar.tsx +301 -301
  86. package/src/panels/ChannelConfigPanel.tsx +49 -49
  87. package/src/panels/ChannelsPanel.tsx +28 -28
  88. package/src/panels/DebugConsolePanel.tsx +73 -73
  89. package/src/panels/DebugContextPanel.tsx +77 -77
  90. package/src/panels/DebugExternalIOPanel.tsx +180 -180
  91. package/src/panels/DiagnosticsPanel.tsx +170 -170
  92. package/src/panels/EdgeConfigPanel.tsx +104 -104
  93. package/src/panels/FunctionConfigPanel.tsx +179 -179
  94. package/src/panels/FunctionListPanel.tsx +45 -45
  95. package/src/panels/MemoryConfigPanel.tsx +55 -55
  96. package/src/panels/MemoryPanel.tsx +40 -40
  97. package/src/panels/ModelConfigPanel.tsx +41 -41
  98. package/src/panels/ModelsPanel.tsx +36 -36
  99. package/src/panels/NodeConfigPanel.tsx +630 -630
  100. package/src/panels/NodeLibrary.tsx +288 -288
  101. package/src/panels/ResourceConfigPanel.tsx +132 -132
  102. package/src/panels/ResourceListPanel.tsx +113 -113
  103. package/src/panels/VariableConfigPanel.tsx +161 -161
  104. package/src/panels/VariablesPanel.tsx +145 -145
  105. package/src/stores/canvasStore.test.ts +44 -44
  106. package/src/stores/canvasStore.ts +245 -245
  107. package/src/stores/debugStore.ts +74 -74
  108. package/src/stores/diagnosticsStore.ts +130 -130
  109. package/src/stores/editorStore.ts +190 -202
  110. package/src/styles/index.css +526 -526
  111. package/src/utils/categoryConstants.ts +26 -26
  112. package/src/utils/channelOperations.ts +86 -86
  113. package/src/utils/connectionRules.ts +137 -137
  114. package/src/utils/functionOperations.ts +179 -179
  115. package/src/utils/graphOperations.ts +550 -550
  116. package/src/utils/history.ts +207 -207
  117. package/src/utils/memoryOperations.ts +57 -57
  118. package/src/utils/migrateFunctionNodes.ts +107 -107
  119. package/src/utils/modelOperations.ts +55 -55
  120. package/src/utils/paramDisplay.ts +71 -71
  121. package/src/utils/resourceHelpers.ts +32 -32
  122. package/src/utils/translation.ts +28 -28
  123. package/src/utils/variableOperations.ts +75 -75
  124. package/tailwind-preset.ts +166 -166
@@ -1,132 +1,132 @@
1
- import { useEffect, useState, type ReactNode } from "react";
2
- import { Button } from "../components/ui/button";
3
- import { Separator } from "../components/ui/separator";
4
- import { ChevronRight } from "lucide-react";
5
- import type { Parameter } from "@foresthubai/workflow-core/parameter";
6
- import type { Diagnostic } from "@foresthubai/workflow-core/diagnostics";
7
- import ParameterEditor from "../inputs/ParameterEditor";
8
- import { MAIN_CANVAS_ID } from "../stores/canvasStore";
9
- import { useEditorStore } from "../stores/editorStore";
10
- import { isReadOnly } from "../WorkflowBuilder";
11
- import { useParamErrors } from "../hooks/useParamErrors";
12
- import { ReadOnlyBanner } from "../components/ui/readonly-banner";
13
- import { DeleteButton } from "../components/ui/delete-button";
14
-
15
- interface ResourceConfigPanelProps {
16
- /** Stable id of the open resource — resets the local label field when it changes. */
17
- resetKey: string;
18
- label: string;
19
- /** `title`/aria text for the label input. */
20
- labelTitle: string;
21
- onLabelChange: (label: string) => void;
22
- description: string;
23
- /** Optional validation messages rendered under the title (e.g. empty/duplicate label). */
24
- belowLabel?: ReactNode;
25
- parameters: Parameter[];
26
- /** Read the current value for a parameter (channels map `type` to a top-level field). */
27
- getValue: (param: Parameter) => unknown;
28
- allArguments: Record<string, unknown>;
29
- onParamChange: (paramId: string, value: unknown) => void;
30
- diagnostics: Diagnostic[] | undefined;
31
- translationPrefix: string;
32
- deleteLabel: string;
33
- onDelete: () => void;
34
- onClose: () => void;
35
- /** Canvas used for variable resolution in ParameterEditor. Project-scoped resources use MAIN. */
36
- canvasId?: string;
37
- }
38
-
39
- /**
40
- * Shared editor shell for the project-scoped "primitive" resources that all
41
- * render a `{type, arguments}` bag through `ParameterEditor` — channels, memory,
42
- * declared models. Owns the chrome (editable title, readOnly banner, parameter
43
- * list, delete/close buttons); each wrapper supplies the parameter source, the
44
- * value accessor, and the mutation callbacks. Nodes/edges are too divergent to
45
- * use this and keep their own bodies (sharing only {@link useParamErrors}).
46
- */
47
- export const ResourceConfigPanel = ({
48
- resetKey,
49
- label,
50
- labelTitle,
51
- onLabelChange,
52
- description,
53
- belowLabel,
54
- parameters,
55
- getValue,
56
- allArguments,
57
- onParamChange,
58
- diagnostics,
59
- translationPrefix,
60
- deleteLabel,
61
- onDelete,
62
- onClose,
63
- canvasId = MAIN_CANVAS_ID,
64
- }: ResourceConfigPanelProps) => {
65
- const readOnly = useEditorStore((s) => isReadOnly(s.builderMode));
66
- const paramErrors = useParamErrors(diagnostics);
67
-
68
- // Local label state preserves cursor position on edit; resets when a different
69
- // resource is opened.
70
- const [localLabel, setLocalLabel] = useState(label);
71
- useEffect(() => {
72
- setLocalLabel(label);
73
- }, [resetKey, label]);
74
-
75
- return (
76
- <div className="p-4">
77
- <div className="space-y-4">
78
- <div className="flex items-center justify-between gap-2">
79
- <div className="flex-1 min-w-0">
80
- <div className="group flex items-center gap-1.5 rounded-md border border-transparent px-1.5 -mx-1.5 hover:border-input focus-within:border-input transition-colors">
81
- <input
82
- type="text"
83
- title={labelTitle}
84
- className="font-semibold text-lg bg-transparent w-full outline-none cursor-text py-0.5"
85
- value={localLabel}
86
- readOnly={readOnly}
87
- onChange={(e) => {
88
- setLocalLabel(e.target.value);
89
- onLabelChange(e.target.value);
90
- }}
91
- />
92
- </div>
93
- <p className="text-sm text-muted-foreground">{description}</p>
94
- {belowLabel}
95
- </div>
96
- <Button variant="ghost" size="icon" className="shrink-0" onClick={onClose}>
97
- <ChevronRight className="h-4 w-4" />
98
- </Button>
99
- </div>
100
-
101
- {readOnly && <ReadOnlyBanner />}
102
-
103
- {parameters.length > 0 && (
104
- <>
105
- <Separator />
106
- <div className={`space-y-3 ${readOnly ? "pointer-events-none opacity-60" : ""}`}>
107
- {parameters.map((param) => (
108
- <ParameterEditor
109
- key={param.id}
110
- canvasId={canvasId}
111
- parameter={param}
112
- value={getValue(param)}
113
- allArguments={allArguments}
114
- onChange={(value) => onParamChange(param.id, value)}
115
- errors={paramErrors.get(param.id)}
116
- translationPrefix={translationPrefix}
117
- />
118
- ))}
119
- </div>
120
- </>
121
- )}
122
-
123
- {!readOnly && (
124
- <>
125
- <Separator />
126
- <DeleteButton onClick={onDelete}>{deleteLabel}</DeleteButton>
127
- </>
128
- )}
129
- </div>
130
- </div>
131
- );
132
- };
1
+ import { useEffect, useState, type ReactNode } from "react";
2
+ import { Button } from "../components/ui/button";
3
+ import { Separator } from "../components/ui/separator";
4
+ import { ChevronRight } from "lucide-react";
5
+ import type { Parameter } from "@foresthubai/workflow-core/parameter";
6
+ import type { Diagnostic } from "@foresthubai/workflow-core/diagnostics";
7
+ import ParameterEditor from "../inputs/ParameterEditor";
8
+ import { MAIN_CANVAS_ID } from "../stores/canvasStore";
9
+ import { useEditorStore } from "../stores/editorStore";
10
+ import { isReadOnly } from "../WorkflowBuilder";
11
+ import { useParamErrors } from "../hooks/useParamErrors";
12
+ import { ReadOnlyBanner } from "../components/ui/readonly-banner";
13
+ import { DeleteButton } from "../components/ui/delete-button";
14
+
15
+ interface ResourceConfigPanelProps {
16
+ /** Stable id of the open resource — resets the local label field when it changes. */
17
+ resetKey: string;
18
+ label: string;
19
+ /** `title`/aria text for the label input. */
20
+ labelTitle: string;
21
+ onLabelChange: (label: string) => void;
22
+ description: string;
23
+ /** Optional validation messages rendered under the title (e.g. empty/duplicate label). */
24
+ belowLabel?: ReactNode;
25
+ parameters: Parameter[];
26
+ /** Read the current value for a parameter (channels map `type` to a top-level field). */
27
+ getValue: (param: Parameter) => unknown;
28
+ allArguments: Record<string, unknown>;
29
+ onParamChange: (paramId: string, value: unknown) => void;
30
+ diagnostics: Diagnostic[] | undefined;
31
+ translationPrefix: string;
32
+ deleteLabel: string;
33
+ onDelete: () => void;
34
+ onClose: () => void;
35
+ /** Canvas used for variable resolution in ParameterEditor. Project-scoped resources use MAIN. */
36
+ canvasId?: string;
37
+ }
38
+
39
+ /**
40
+ * Shared editor shell for the project-scoped "primitive" resources that all
41
+ * render a `{type, arguments}` bag through `ParameterEditor` — channels, memory,
42
+ * declared models. Owns the chrome (editable title, readOnly banner, parameter
43
+ * list, delete/close buttons); each wrapper supplies the parameter source, the
44
+ * value accessor, and the mutation callbacks. Nodes/edges are too divergent to
45
+ * use this and keep their own bodies (sharing only {@link useParamErrors}).
46
+ */
47
+ export const ResourceConfigPanel = ({
48
+ resetKey,
49
+ label,
50
+ labelTitle,
51
+ onLabelChange,
52
+ description,
53
+ belowLabel,
54
+ parameters,
55
+ getValue,
56
+ allArguments,
57
+ onParamChange,
58
+ diagnostics,
59
+ translationPrefix,
60
+ deleteLabel,
61
+ onDelete,
62
+ onClose,
63
+ canvasId = MAIN_CANVAS_ID,
64
+ }: ResourceConfigPanelProps) => {
65
+ const readOnly = useEditorStore((s) => isReadOnly(s.builderMode));
66
+ const paramErrors = useParamErrors(diagnostics);
67
+
68
+ // Local label state preserves cursor position on edit; resets when a different
69
+ // resource is opened.
70
+ const [localLabel, setLocalLabel] = useState(label);
71
+ useEffect(() => {
72
+ setLocalLabel(label);
73
+ }, [resetKey, label]);
74
+
75
+ return (
76
+ <div className="p-4">
77
+ <div className="space-y-4">
78
+ <div className="flex items-center justify-between gap-2">
79
+ <div className="flex-1 min-w-0">
80
+ <div className="group flex items-center gap-1.5 rounded-md border border-transparent px-1.5 -mx-1.5 hover:border-input focus-within:border-input transition-colors">
81
+ <input
82
+ type="text"
83
+ title={labelTitle}
84
+ className="font-semibold text-lg bg-transparent w-full outline-none cursor-text py-0.5"
85
+ value={localLabel}
86
+ readOnly={readOnly}
87
+ onChange={(e) => {
88
+ setLocalLabel(e.target.value);
89
+ onLabelChange(e.target.value);
90
+ }}
91
+ />
92
+ </div>
93
+ <p className="text-sm text-muted-foreground">{description}</p>
94
+ {belowLabel}
95
+ </div>
96
+ <Button variant="ghost" size="icon" className="shrink-0" onClick={onClose}>
97
+ <ChevronRight className="h-4 w-4" />
98
+ </Button>
99
+ </div>
100
+
101
+ {readOnly && <ReadOnlyBanner />}
102
+
103
+ {parameters.length > 0 && (
104
+ <>
105
+ <Separator />
106
+ <div className={`space-y-3 ${readOnly ? "pointer-events-none opacity-60" : ""}`}>
107
+ {parameters.map((param) => (
108
+ <ParameterEditor
109
+ key={param.id}
110
+ canvasId={canvasId}
111
+ parameter={param}
112
+ value={getValue(param)}
113
+ allArguments={allArguments}
114
+ onChange={(value) => onParamChange(param.id, value)}
115
+ errors={paramErrors.get(param.id)}
116
+ translationPrefix={translationPrefix}
117
+ />
118
+ ))}
119
+ </div>
120
+ </>
121
+ )}
122
+
123
+ {!readOnly && (
124
+ <>
125
+ <Separator />
126
+ <DeleteButton onClick={onDelete}>{deleteLabel}</DeleteButton>
127
+ </>
128
+ )}
129
+ </div>
130
+ </div>
131
+ );
132
+ };
@@ -1,113 +1,113 @@
1
- import { AlertTriangle, type LucideIcon } from "lucide-react";
2
- import { AddButton } from "../components/ui/add-button";
3
- import { cn } from "../cn";
4
- import { useEditorStore } from "../stores/editorStore";
5
- import { isReadOnly } from "../WorkflowBuilder";
6
- import type { Diagnostic } from "@foresthubai/workflow-core/diagnostics";
7
-
8
- interface ResourceListItem {
9
- id: string;
10
- label: string;
11
- }
12
-
13
- interface AddAction {
14
- label: string;
15
- icon: LucideIcon;
16
- onAdd: () => void;
17
- }
18
-
19
- interface ResourceListPanelProps<I extends ResourceListItem> {
20
- items: I[];
21
- selectedId: string | null;
22
- onSelect: (id: string) => void;
23
- /** The matching diagnostics slot (byChannelId / byMemoryId / byModelId). */
24
- diagnosticsSlot: Record<string, Diagnostic[]>;
25
- /** Short type-badge text shown on the right of each row. */
26
- badge: (item: I) => string;
27
- emptyIcon: LucideIcon;
28
- emptyText: string;
29
- emptyHint: string;
30
- /** One add button (channels/models) or several (memory: File + Vector). */
31
- addActions: AddAction[];
32
- }
33
-
34
- /**
35
- * Shared sidebar list for the project-scoped primitive resources (channels,
36
- * memory, declared models): a selectable row per item with an error ring +
37
- * warning icon driven by the diagnostics slot, a type badge, and add button(s).
38
- * Variables are not listed here — they're canvas-scoped, sectioned, and don't
39
- * use this error-badge model.
40
- */
41
- export function ResourceListPanel<I extends ResourceListItem>({
42
- items,
43
- selectedId,
44
- onSelect,
45
- diagnosticsSlot,
46
- badge,
47
- emptyIcon: EmptyIcon,
48
- emptyText,
49
- emptyHint,
50
- addActions,
51
- }: ResourceListPanelProps<I>) {
52
- const readOnly = useEditorStore((s) => isReadOnly(s.builderMode));
53
-
54
- const addButtons = (
55
- <div className="flex flex-col gap-1.5">
56
- {addActions.map(({ label, icon, onAdd }) => (
57
- <AddButton key={label} icon={icon} onClick={onAdd}>
58
- {label}
59
- </AddButton>
60
- ))}
61
- </div>
62
- );
63
-
64
- if (items.length === 0) {
65
- return (
66
- <div className="flex flex-col items-center justify-center py-8 text-center">
67
- <EmptyIcon className="w-10 h-10 text-muted-foreground/50 mb-3" />
68
- <p className="text-sm text-muted-foreground">{emptyText}</p>
69
- <p className="text-xs text-muted-foreground/70 mt-1">{emptyHint}</p>
70
- {!readOnly && <div className="mt-3 w-full px-2">{addButtons}</div>}
71
- </div>
72
- );
73
- }
74
-
75
- return (
76
- <div className="space-y-1.5">
77
- {items.map((item) => {
78
- const isSelected = selectedId === item.id;
79
- const hasError = (diagnosticsSlot[item.id] ?? []).some((d) => d.severity === "error");
80
- return (
81
- <div
82
- key={item.id}
83
- onClick={() => onSelect(item.id)}
84
- className={cn(
85
- // Background/shadow come from selection; border/ring come from error
86
- // status. Layered, not exclusive — so a selected row with an error
87
- // keeps its red outline against the green selection tint instead of
88
- // hiding the very signal the user is acting on.
89
- "p-3 rounded-lg transition-all cursor-pointer border ring-1",
90
- isSelected ? "bg-accent shadow-md" : "bg-card shadow-sm hover:shadow-md",
91
- hasError
92
- ? "border-destructive ring-destructive"
93
- : isSelected
94
- ? "border-primary/40 ring-primary/40"
95
- : "border-border ring-transparent",
96
- )}
97
- >
98
- <div className="flex items-center justify-between gap-2">
99
- <span className="font-mono text-sm text-foreground truncate flex items-center gap-1.5">
100
- {hasError && <AlertTriangle className="w-3.5 h-3.5 text-destructive shrink-0" />}
101
- {item.label}
102
- </span>
103
- <span className="text-[10px] font-medium px-1.5 py-0.5 rounded border border-border/50 text-muted-foreground shrink-0">
104
- {badge(item)}
105
- </span>
106
- </div>
107
- </div>
108
- );
109
- })}
110
- {!readOnly && <div className="pt-1">{addButtons}</div>}
111
- </div>
112
- );
113
- }
1
+ import { AlertTriangle, type LucideIcon } from "lucide-react";
2
+ import { AddButton } from "../components/ui/add-button";
3
+ import { cn } from "../cn";
4
+ import { useEditorStore } from "../stores/editorStore";
5
+ import { isReadOnly } from "../WorkflowBuilder";
6
+ import type { Diagnostic } from "@foresthubai/workflow-core/diagnostics";
7
+
8
+ interface ResourceListItem {
9
+ id: string;
10
+ label: string;
11
+ }
12
+
13
+ interface AddAction {
14
+ label: string;
15
+ icon: LucideIcon;
16
+ onAdd: () => void;
17
+ }
18
+
19
+ interface ResourceListPanelProps<I extends ResourceListItem> {
20
+ items: I[];
21
+ selectedId: string | null;
22
+ onSelect: (id: string) => void;
23
+ /** The matching diagnostics slot (byChannelId / byMemoryId / byModelId). */
24
+ diagnosticsSlot: Record<string, Diagnostic[]>;
25
+ /** Short type-badge text shown on the right of each row. */
26
+ badge: (item: I) => string;
27
+ emptyIcon: LucideIcon;
28
+ emptyText: string;
29
+ emptyHint: string;
30
+ /** One add button (channels/models) or several (memory: File + Vector). */
31
+ addActions: AddAction[];
32
+ }
33
+
34
+ /**
35
+ * Shared sidebar list for the project-scoped primitive resources (channels,
36
+ * memory, declared models): a selectable row per item with an error ring +
37
+ * warning icon driven by the diagnostics slot, a type badge, and add button(s).
38
+ * Variables are not listed here — they're canvas-scoped, sectioned, and don't
39
+ * use this error-badge model.
40
+ */
41
+ export function ResourceListPanel<I extends ResourceListItem>({
42
+ items,
43
+ selectedId,
44
+ onSelect,
45
+ diagnosticsSlot,
46
+ badge,
47
+ emptyIcon: EmptyIcon,
48
+ emptyText,
49
+ emptyHint,
50
+ addActions,
51
+ }: ResourceListPanelProps<I>) {
52
+ const readOnly = useEditorStore((s) => isReadOnly(s.builderMode));
53
+
54
+ const addButtons = (
55
+ <div className="flex flex-col gap-1.5">
56
+ {addActions.map(({ label, icon, onAdd }) => (
57
+ <AddButton key={label} icon={icon} onClick={onAdd}>
58
+ {label}
59
+ </AddButton>
60
+ ))}
61
+ </div>
62
+ );
63
+
64
+ if (items.length === 0) {
65
+ return (
66
+ <div className="flex flex-col items-center justify-center py-8 text-center">
67
+ <EmptyIcon className="w-10 h-10 text-muted-foreground/50 mb-3" />
68
+ <p className="text-sm text-muted-foreground">{emptyText}</p>
69
+ <p className="text-xs text-muted-foreground/70 mt-1">{emptyHint}</p>
70
+ {!readOnly && <div className="mt-3 w-full px-2">{addButtons}</div>}
71
+ </div>
72
+ );
73
+ }
74
+
75
+ return (
76
+ <div className="space-y-1.5">
77
+ {items.map((item) => {
78
+ const isSelected = selectedId === item.id;
79
+ const hasError = (diagnosticsSlot[item.id] ?? []).some((d) => d.severity === "error");
80
+ return (
81
+ <div
82
+ key={item.id}
83
+ onClick={() => onSelect(item.id)}
84
+ className={cn(
85
+ // Background/shadow come from selection; border/ring come from error
86
+ // status. Layered, not exclusive — so a selected row with an error
87
+ // keeps its red outline against the green selection tint instead of
88
+ // hiding the very signal the user is acting on.
89
+ "p-3 rounded-lg transition-all cursor-pointer border ring-1",
90
+ isSelected ? "bg-accent shadow-md" : "bg-card shadow-sm hover:shadow-md",
91
+ hasError
92
+ ? "border-destructive ring-destructive"
93
+ : isSelected
94
+ ? "border-primary/40 ring-primary/40"
95
+ : "border-border ring-transparent",
96
+ )}
97
+ >
98
+ <div className="flex items-center justify-between gap-2">
99
+ <span className="font-mono text-sm text-foreground truncate flex items-center gap-1.5">
100
+ {hasError && <AlertTriangle className="w-3.5 h-3.5 text-destructive shrink-0" />}
101
+ {item.label}
102
+ </span>
103
+ <span className="text-[10px] font-medium px-1.5 py-0.5 rounded border border-border/50 text-muted-foreground shrink-0">
104
+ {badge(item)}
105
+ </span>
106
+ </div>
107
+ </div>
108
+ );
109
+ })}
110
+ {!readOnly && <div className="pt-1">{addButtons}</div>}
111
+ </div>
112
+ );
113
+ }