@omega-flow/editor 0.1.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.
@@ -0,0 +1,552 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import React$1, { ReactNode, ComponentType } from 'react';
3
+ import * as _omega_flow_types from '@omega-flow/types';
4
+ import { Workflow, Node, Edge, WorkflowOptions } from '@omega-flow/types';
5
+ import * as _xyflow_react from '@xyflow/react';
6
+ import { NodeProps, NodeTypes } from '@xyflow/react';
7
+
8
+ /**
9
+ * Definition for a handle (connection point) on a node
10
+ */
11
+ interface HandleDefinition {
12
+ id: string;
13
+ label?: string;
14
+ }
15
+ /**
16
+ * Props passed to node view components (rendered on canvas)
17
+ * This extends ReactFlow's NodeProps for full compatibility
18
+ */
19
+ type NodeViewProps = NodeProps;
20
+ /**
21
+ * Props passed to node detail components (rendered in detail panel)
22
+ */
23
+ interface NodeDetailProps {
24
+ node: Node;
25
+ onChange: (data: Record<string, unknown>) => void;
26
+ }
27
+ /**
28
+ * Complete definition of a node type including visual components
29
+ */
30
+ interface NodeTypeDefinition {
31
+ /** Node type identifier (e.g., "Trigger", "Action") */
32
+ type: string;
33
+ /** Display name shown in UI */
34
+ label: string;
35
+ /** Description/tooltip text */
36
+ description?: string;
37
+ /** Node background color */
38
+ color?: string;
39
+ /** Initial data when node is created */
40
+ defaultData: Record<string, unknown>;
41
+ /** Output connection handles */
42
+ sourceHandles: HandleDefinition[];
43
+ /** Input connection handles */
44
+ targetHandles: HandleDefinition[];
45
+ /** Component to render on the canvas */
46
+ ViewComponent: ComponentType<NodeViewProps>;
47
+ /** Component to render in the detail panel */
48
+ DetailComponent: ComponentType<NodeDetailProps>;
49
+ }
50
+ /**
51
+ * State managed by the workflow editor context
52
+ */
53
+ interface WorkflowEditorState {
54
+ /** The original workflow being edited (null if creating new) */
55
+ workflow: Workflow | null;
56
+ /** Current nodes in the flow */
57
+ nodes: Node[];
58
+ /** Current edges in the flow */
59
+ edges: Edge[];
60
+ /** Workflow options (frequency, etc.) */
61
+ options: WorkflowOptions;
62
+ /** Workflow name */
63
+ name: string;
64
+ /** Currently selected node ID */
65
+ selectedNodeId: string | null;
66
+ /** Whether there are unsaved changes */
67
+ isDirty: boolean;
68
+ /** Registered node types */
69
+ nodeTypes: Map<string, NodeTypeDefinition>;
70
+ }
71
+ /**
72
+ * Actions available in the workflow editor context
73
+ */
74
+ interface WorkflowEditorActions {
75
+ /** Load a workflow into the editor */
76
+ loadWorkflow: (workflow: Workflow) => void;
77
+ /** Reset to initial state */
78
+ resetWorkflow: () => void;
79
+ /** Add a new node at position */
80
+ addNode: (type: string, position: {
81
+ x: number;
82
+ y: number;
83
+ }) => void;
84
+ /** Update a node's data */
85
+ updateNode: (nodeId: string, data: Record<string, unknown>) => void;
86
+ /** Update a node's position */
87
+ updateNodePosition: (nodeId: string, position: {
88
+ x: number;
89
+ y: number;
90
+ }) => void;
91
+ /** Remove a node */
92
+ removeNode: (nodeId: string) => void;
93
+ /** Select a node (or null to deselect) */
94
+ selectNode: (nodeId: string | null) => void;
95
+ /** Add a new edge */
96
+ addEdge: (connection: {
97
+ source: string;
98
+ target: string;
99
+ sourceHandle?: string;
100
+ targetHandle?: string;
101
+ }) => void;
102
+ /** Remove an edge */
103
+ removeEdge: (edgeId: string) => void;
104
+ /** Set workflow name */
105
+ setName: (name: string) => void;
106
+ /** Set workflow options */
107
+ setOptions: (options: WorkflowOptions) => void;
108
+ /** Register a custom node type */
109
+ registerNodeType: (definition: NodeTypeDefinition) => void;
110
+ /** Get the current workflow state */
111
+ getWorkflow: () => Workflow;
112
+ /** Mark the workflow as clean (saved) */
113
+ markClean: () => void;
114
+ /** Handle ReactFlow node changes */
115
+ onNodesChange: (changes: unknown[]) => void;
116
+ /** Handle ReactFlow edge changes */
117
+ onEdgesChange: (changes: unknown[]) => void;
118
+ /** Handle ReactFlow connections */
119
+ onConnect: (connection: unknown) => void;
120
+ }
121
+ /**
122
+ * Complete context value combining state and actions
123
+ */
124
+ interface WorkflowEditorContextValue extends WorkflowEditorState, WorkflowEditorActions {
125
+ }
126
+ /**
127
+ * Props for the WorkflowEditor component
128
+ */
129
+ interface WorkflowEditorProps {
130
+ children: ReactNode;
131
+ /** Initial workflow to load */
132
+ workflow?: Workflow;
133
+ /** Custom node types to register */
134
+ nodeTypes?: NodeTypeDefinition[];
135
+ /** Callback when workflow changes */
136
+ onWorkflowChange?: (workflow: Workflow) => void;
137
+ /** Callback when dirty state changes */
138
+ onDirtyChange?: (isDirty: boolean) => void;
139
+ }
140
+ /**
141
+ * Props for NodesPanel component
142
+ */
143
+ interface NodesPanelProps {
144
+ className?: string;
145
+ /** Whether to show descriptions */
146
+ showDescriptions?: boolean;
147
+ /** Filter which node types to show */
148
+ filter?: (nodeType: NodeTypeDefinition) => boolean;
149
+ /** Custom render function for items */
150
+ renderItem?: (nodeType: NodeTypeDefinition) => ReactNode;
151
+ }
152
+ /**
153
+ * Props for DetailPanel component
154
+ */
155
+ interface DetailPanelProps {
156
+ className?: string;
157
+ /** Message when no node is selected */
158
+ emptyMessage?: ReactNode;
159
+ /** Whether to show node type label */
160
+ showNodeType?: boolean;
161
+ /** Whether to show node ID */
162
+ showNodeId?: boolean;
163
+ }
164
+ /**
165
+ * Props for OptionsPanel component
166
+ */
167
+ interface OptionsPanelProps {
168
+ className?: string;
169
+ /** Whether to show frequency options */
170
+ showFrequency?: boolean;
171
+ /** Custom options to render */
172
+ customOptions?: ReactNode;
173
+ }
174
+ /**
175
+ * Props for ControlPanel component
176
+ */
177
+ interface ControlPanelProps {
178
+ className?: string;
179
+ /** Whether to show name input */
180
+ showName?: boolean;
181
+ /** Whether to show save button */
182
+ showSaveButton?: boolean;
183
+ /** Label for save button */
184
+ saveButtonLabel?: string;
185
+ /** Save callback */
186
+ onSave?: () => Promise<void>;
187
+ /** Custom actions to render */
188
+ renderActions?: (context: {
189
+ isDirty: boolean;
190
+ workflow: Workflow;
191
+ }) => ReactNode;
192
+ }
193
+
194
+ /**
195
+ * Main wrapper component for the workflow editor.
196
+ * Provides context and state management for all child components.
197
+ *
198
+ * @example
199
+ * ```tsx
200
+ * <WorkflowEditor workflow={workflow} onWorkflowChange={handleChange}>
201
+ * <ReactFlow nodes={nodes} edges={edges} ...>
202
+ * <Panel position="top-left"><NodesPanel /></Panel>
203
+ * </ReactFlow>
204
+ * </WorkflowEditor>
205
+ * ```
206
+ */
207
+ declare function WorkflowEditor({ children, workflow, nodeTypes, onWorkflowChange, onDirtyChange, }: WorkflowEditorProps): react_jsx_runtime.JSX.Element;
208
+
209
+ /**
210
+ * Panel showing available node types that can be dragged onto the canvas.
211
+ */
212
+ declare function NodesPanel({ className, showDescriptions, filter, renderItem, }: NodesPanelProps): react_jsx_runtime.JSX.Element;
213
+
214
+ /**
215
+ * Panel for editing the properties of the selected node.
216
+ * Renders the appropriate DetailComponent based on node type.
217
+ */
218
+ declare function DetailPanel({ className, emptyMessage, showNodeType, showNodeId, }: DetailPanelProps): react_jsx_runtime.JSX.Element;
219
+
220
+ /**
221
+ * Panel for editing workflow options like frequency.
222
+ */
223
+ declare function OptionsPanel({ className, showFrequency, customOptions, }: OptionsPanelProps): react_jsx_runtime.JSX.Element;
224
+
225
+ /**
226
+ * Panel for editing workflow name and saving.
227
+ */
228
+ declare function ControlPanel({ className, showName, showSaveButton, saveButtonLabel, onSave, renderActions, }: ControlPanelProps): react_jsx_runtime.JSX.Element;
229
+
230
+ /**
231
+ * Provider component for workflow editor context
232
+ */
233
+ declare function WorkflowEditorProvider({ children, workflow, nodeTypes: customNodeTypes, onWorkflowChange, onDirtyChange, }: WorkflowEditorProps): react_jsx_runtime.JSX.Element;
234
+ /**
235
+ * Hook to access the workflow editor context
236
+ * @throws Error if used outside of WorkflowEditorProvider
237
+ */
238
+ declare function useWorkflowEditorContext(): WorkflowEditorContextValue;
239
+
240
+ /**
241
+ * Main hook for accessing workflow editor state and actions.
242
+ * Provides a convenient interface to the most commonly used functionality.
243
+ */
244
+ declare function useWorkflowEditor(): {
245
+ workflow: _omega_flow_types.Workflow;
246
+ nodes: _xyflow_react.Node[];
247
+ edges: _xyflow_react.Edge[];
248
+ options: _omega_flow_types.WorkflowOptions;
249
+ name: string;
250
+ isDirty: boolean;
251
+ selectedNode: _xyflow_react.Node | null;
252
+ selectedNodeId: string | null;
253
+ loadWorkflow: (workflow: _omega_flow_types.Workflow) => void;
254
+ resetWorkflow: () => void;
255
+ addNode: (type: string, position: {
256
+ x: number;
257
+ y: number;
258
+ }) => void;
259
+ updateNode: (nodeId: string, data: Record<string, unknown>) => void;
260
+ removeNode: (nodeId: string) => void;
261
+ selectNode: (nodeId: string | null) => void;
262
+ addEdge: (connection: {
263
+ source: string;
264
+ target: string;
265
+ sourceHandle?: string;
266
+ targetHandle?: string;
267
+ }) => void;
268
+ removeEdge: (edgeId: string) => void;
269
+ setName: (name: string) => void;
270
+ setOptions: (options: _omega_flow_types.WorkflowOptions) => void;
271
+ getWorkflow: () => _omega_flow_types.Workflow;
272
+ markClean: () => void;
273
+ };
274
+
275
+ /**
276
+ * Hook for working with nodes in the workflow.
277
+ * Returns nodes and handlers compatible with ReactFlow.
278
+ */
279
+ declare function useNodes(): {
280
+ nodes: _xyflow_react.Node[];
281
+ onNodesChange: (changes: unknown[]) => void;
282
+ addNode: (type: string, position: {
283
+ x: number;
284
+ y: number;
285
+ }) => void;
286
+ updateNode: (nodeId: string, data: Record<string, unknown>) => void;
287
+ removeNode: (nodeId: string) => void;
288
+ };
289
+
290
+ /**
291
+ * Hook for working with edges in the workflow.
292
+ * Returns edges and handlers compatible with ReactFlow.
293
+ */
294
+ declare function useEdges(): {
295
+ edges: _xyflow_react.Edge[];
296
+ onEdgesChange: (changes: unknown[]) => void;
297
+ onConnect: (connection: unknown) => void;
298
+ addEdge: (connection: {
299
+ source: string;
300
+ target: string;
301
+ sourceHandle?: string;
302
+ targetHandle?: string;
303
+ }) => void;
304
+ removeEdge: (edgeId: string) => void;
305
+ };
306
+
307
+ /**
308
+ * Hook for accessing the node type registry.
309
+ * Returns node types and ReactFlow-compatible nodeTypes object.
310
+ */
311
+ declare function useNodeRegistry(): {
312
+ /** Map of node type definitions */
313
+ nodeTypes: Map<string, NodeTypeDefinition>;
314
+ /** Array of node type definitions */
315
+ nodeTypesList: NodeTypeDefinition[];
316
+ /** ReactFlow-compatible nodeTypes object */
317
+ reactFlowNodeTypes: NodeTypes;
318
+ /** Register a new node type */
319
+ registerNodeType: (definition: NodeTypeDefinition) => void;
320
+ /** Get a specific node type definition */
321
+ getNodeType: (type: string) => NodeTypeDefinition | undefined;
322
+ };
323
+
324
+ /**
325
+ * Hook for handling drag-and-drop from the nodes panel to the canvas.
326
+ * Provides event handlers for drag start, drag over, and drop events.
327
+ */
328
+ declare function useDragAndDrop(): {
329
+ onDragStart: (event: React.DragEvent, nodeType: string) => void;
330
+ onDragOver: (event: React.DragEvent) => void;
331
+ onDrop: (event: React.DragEvent) => void;
332
+ };
333
+
334
+ /**
335
+ * Hook for working with the currently selected node.
336
+ */
337
+ declare function useSelectedNode(): {
338
+ /** The currently selected node, or null if none */
339
+ selectedNode: _xyflow_react.Node | null;
340
+ /** The ID of the selected node */
341
+ selectedNodeId: string | null;
342
+ /** The node type definition for the selected node */
343
+ nodeType: NodeTypeDefinition | undefined;
344
+ /** Select a node by ID */
345
+ selectNode: (nodeId: string | null) => void;
346
+ /** Update the selected node's data */
347
+ updateSelectedNode: (data: Record<string, unknown>) => void;
348
+ /** Remove the selected node */
349
+ removeSelectedNode: () => void;
350
+ };
351
+
352
+ interface BaseNodeViewProps {
353
+ id: string;
354
+ data: Record<string, unknown>;
355
+ selected?: boolean;
356
+ label: string;
357
+ color?: string;
358
+ icon?: React$1.ReactNode;
359
+ sourceHandles?: HandleDefinition[];
360
+ targetHandles?: HandleDefinition[];
361
+ children?: React$1.ReactNode;
362
+ }
363
+ /**
364
+ * Base component for rendering nodes on the canvas.
365
+ * Provides consistent styling and handle rendering.
366
+ */
367
+ declare function BaseNodeView({ label, color, icon, sourceHandles, targetHandles, selected, children, }: BaseNodeViewProps): react_jsx_runtime.JSX.Element;
368
+
369
+ declare function TriggerNodeView({ id, data, selected }: NodeProps): react_jsx_runtime.JSX.Element;
370
+
371
+ declare function ActionNodeView({ id, data, selected }: NodeProps): react_jsx_runtime.JSX.Element;
372
+
373
+ declare function ConditionNodeView({ id, data, selected }: NodeProps): react_jsx_runtime.JSX.Element;
374
+
375
+ declare function ExitNodeView({ id, data, selected }: NodeProps): react_jsx_runtime.JSX.Element;
376
+
377
+ declare function WaitNodeView({ id, data, selected }: NodeProps): react_jsx_runtime.JSX.Element;
378
+
379
+ declare function TriggerOrTimeoutNodeView({ id, data, selected }: NodeProps): react_jsx_runtime.JSX.Element;
380
+
381
+ /**
382
+ * Detail editor for Trigger nodes.
383
+ * Allows setting the event type that triggers this node.
384
+ */
385
+ declare function TriggerNodeDetail({ node, onChange }: NodeDetailProps): react_jsx_runtime.JSX.Element;
386
+
387
+ /**
388
+ * Detail editor for Action nodes.
389
+ * Allows setting the action name and parameters.
390
+ */
391
+ declare function ActionNodeDetail({ node, onChange }: NodeDetailProps): react_jsx_runtime.JSX.Element;
392
+
393
+ /**
394
+ * Detail editor for Condition nodes.
395
+ * Allows editing json-rules-engine conditions.
396
+ */
397
+ declare function ConditionNodeDetail({ node, onChange }: NodeDetailProps): react_jsx_runtime.JSX.Element;
398
+
399
+ /**
400
+ * Detail editor for Exit nodes.
401
+ * Exit nodes have no configurable properties.
402
+ */
403
+ declare function ExitNodeDetail(_props: NodeDetailProps): react_jsx_runtime.JSX.Element;
404
+
405
+ /**
406
+ * Detail editor for Wait nodes.
407
+ * Allows setting the wait duration.
408
+ */
409
+ declare function WaitNodeDetail({ node, onChange }: NodeDetailProps): react_jsx_runtime.JSX.Element;
410
+
411
+ /**
412
+ * Detail editor for TriggerOrTimeout nodes.
413
+ * Allows setting both the event type and timeout duration.
414
+ */
415
+ declare function TriggerOrTimeoutNodeDetail({ node, onChange }: NodeDetailProps): react_jsx_runtime.JSX.Element;
416
+
417
+ /**
418
+ * Default node type definitions for the workflow editor.
419
+ * These correspond to the node models in @omega-flow/engine.
420
+ */
421
+ declare const defaultNodeTypes: NodeTypeDefinition[];
422
+
423
+ interface FieldProps {
424
+ label: string;
425
+ children: React$1.ReactNode;
426
+ error?: string;
427
+ hint?: string;
428
+ }
429
+ /**
430
+ * Base field wrapper component that provides label, error, and hint display.
431
+ * Use this to wrap custom inputs.
432
+ */
433
+ declare function Field({ label, children, error, hint }: FieldProps): react_jsx_runtime.JSX.Element;
434
+
435
+ interface TextFieldProps {
436
+ label: string;
437
+ value: string;
438
+ onChange: (value: string) => void;
439
+ placeholder?: string;
440
+ disabled?: boolean;
441
+ error?: string;
442
+ hint?: string;
443
+ }
444
+ /**
445
+ * Text input field with label.
446
+ */
447
+ declare function TextField({ label, value, onChange, placeholder, disabled, error, hint, }: TextFieldProps): react_jsx_runtime.JSX.Element;
448
+
449
+ interface NumberFieldProps {
450
+ label: string;
451
+ value: number;
452
+ onChange: (value: number) => void;
453
+ min?: number;
454
+ max?: number;
455
+ step?: number;
456
+ disabled?: boolean;
457
+ error?: string;
458
+ hint?: string;
459
+ }
460
+ /**
461
+ * Number input field with label.
462
+ */
463
+ declare function NumberField({ label, value, onChange, min, max, step, disabled, error, hint, }: NumberFieldProps): react_jsx_runtime.JSX.Element;
464
+
465
+ interface SelectOption {
466
+ value: string;
467
+ label: string;
468
+ }
469
+ interface SelectFieldProps {
470
+ label: string;
471
+ value: string;
472
+ options: SelectOption[];
473
+ onChange: (value: string) => void;
474
+ placeholder?: string;
475
+ disabled?: boolean;
476
+ error?: string;
477
+ hint?: string;
478
+ }
479
+ /**
480
+ * Select dropdown field with label.
481
+ */
482
+ declare function SelectField({ label, value, options, onChange, placeholder, disabled, error, hint, }: SelectFieldProps): react_jsx_runtime.JSX.Element;
483
+
484
+ interface CheckboxFieldProps {
485
+ label: string;
486
+ checked: boolean;
487
+ onChange: (checked: boolean) => void;
488
+ disabled?: boolean;
489
+ }
490
+ /**
491
+ * Checkbox field with label.
492
+ */
493
+ declare function CheckboxField({ label, checked, onChange, disabled, }: CheckboxFieldProps): react_jsx_runtime.JSX.Element;
494
+
495
+ interface TextAreaFieldProps {
496
+ label: string;
497
+ value: string;
498
+ onChange: (value: string) => void;
499
+ rows?: number;
500
+ placeholder?: string;
501
+ disabled?: boolean;
502
+ error?: string;
503
+ hint?: string;
504
+ }
505
+ /**
506
+ * Multi-line text input field with label.
507
+ */
508
+ declare function TextAreaField({ label, value, onChange, rows, placeholder, disabled, error, hint, }: TextAreaFieldProps): react_jsx_runtime.JSX.Element;
509
+
510
+ interface DurationFieldProps {
511
+ label: string;
512
+ /** Value in milliseconds */
513
+ value: number;
514
+ onChange: (value: number) => void;
515
+ disabled?: boolean;
516
+ error?: string;
517
+ hint?: string;
518
+ }
519
+ /**
520
+ * Duration input field with unit selector (ms, s, min, h).
521
+ * Value is stored in milliseconds but displayed in a user-friendly unit.
522
+ */
523
+ declare function DurationField({ label, value, onChange, disabled, error, hint, }: DurationFieldProps): react_jsx_runtime.JSX.Element;
524
+
525
+ interface JsonFieldProps {
526
+ label: string;
527
+ value: unknown;
528
+ onChange: (value: unknown) => void;
529
+ rows?: number;
530
+ disabled?: boolean;
531
+ error?: string;
532
+ hint?: string;
533
+ }
534
+ /**
535
+ * JSON input field with validation.
536
+ * Displays JSON in a formatted textarea and validates on change.
537
+ */
538
+ declare function JsonField({ label, value, onChange, rows, disabled, error: externalError, hint, }: JsonFieldProps): react_jsx_runtime.JSX.Element;
539
+
540
+ interface FieldGroupProps {
541
+ label?: string;
542
+ children: React$1.ReactNode;
543
+ collapsible?: boolean;
544
+ defaultCollapsed?: boolean;
545
+ }
546
+ /**
547
+ * Groups related fields together with an optional label.
548
+ * Can be made collapsible for better organization.
549
+ */
550
+ declare function FieldGroup({ label, children, collapsible, defaultCollapsed, }: FieldGroupProps): react_jsx_runtime.JSX.Element;
551
+
552
+ export { ActionNodeDetail, ActionNodeView, BaseNodeView, type BaseNodeViewProps, CheckboxField, type CheckboxFieldProps, ConditionNodeDetail, ConditionNodeView, ControlPanel, type ControlPanelProps, DetailPanel, type DetailPanelProps, DurationField, type DurationFieldProps, ExitNodeDetail, ExitNodeView, Field, FieldGroup, type FieldGroupProps, type FieldProps, type HandleDefinition, JsonField, type JsonFieldProps, type NodeDetailProps, type NodeTypeDefinition, type NodeViewProps, NodesPanel, type NodesPanelProps, NumberField, type NumberFieldProps, OptionsPanel, type OptionsPanelProps, SelectField, type SelectFieldProps, type SelectOption, TextAreaField, type TextAreaFieldProps, TextField, type TextFieldProps, TriggerNodeDetail, TriggerNodeView, TriggerOrTimeoutNodeDetail, TriggerOrTimeoutNodeView, WaitNodeDetail, WaitNodeView, WorkflowEditor, type WorkflowEditorActions, type WorkflowEditorContextValue, type WorkflowEditorProps, WorkflowEditorProvider, type WorkflowEditorState, defaultNodeTypes, useDragAndDrop, useEdges, useNodeRegistry, useNodes, useSelectedNode, useWorkflowEditor, useWorkflowEditorContext };