@theclearsky/react-blender-nodes 0.0.2 → 0.0.4
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/README.md +54 -43
- package/dist/index.d.ts +607 -31
- package/dist/react-blender-nodes.css +1 -1
- package/dist/react-blender-nodes.es.js +4606 -3984
- package/dist/react-blender-nodes.es.js.map +1 -1
- package/dist/react-blender-nodes.umd.js +20 -20
- package/dist/react-blender-nodes.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ import { z } from 'zod';
|
|
|
35
35
|
* @template UnderlyingType - Supported underlying data types ('string' | 'number' | 'complex')
|
|
36
36
|
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
37
37
|
*/
|
|
38
|
-
declare type Action<DataTypeUniqueId extends string = string, NodeTypeUniqueId extends string = string, UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never> = {
|
|
38
|
+
export declare type Action<DataTypeUniqueId extends string = string, NodeTypeUniqueId extends string = string, UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never> = {
|
|
39
39
|
/** Add a new node to the graph */
|
|
40
40
|
type: typeof actionTypesMap.ADD_NODE;
|
|
41
41
|
payload: {
|
|
@@ -44,12 +44,21 @@ declare type Action<DataTypeUniqueId extends string = string, NodeTypeUniqueId e
|
|
|
44
44
|
/** Position where to place the node */
|
|
45
45
|
position: XYPosition;
|
|
46
46
|
};
|
|
47
|
+
} | {
|
|
48
|
+
/** Add a new node to the graph and select it */
|
|
49
|
+
type: typeof actionTypesMap.ADD_NODE_AND_SELECT;
|
|
50
|
+
payload: {
|
|
51
|
+
/** Type of node to add */
|
|
52
|
+
type: State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>['nodeIdToNodeType'][string];
|
|
53
|
+
/** Position where to place the node */
|
|
54
|
+
position: XYPosition;
|
|
55
|
+
};
|
|
47
56
|
} | {
|
|
48
57
|
/** Update nodes based on ReactFlow changes */
|
|
49
58
|
type: typeof actionTypesMap.UPDATE_NODE_BY_REACT_FLOW;
|
|
50
59
|
payload: {
|
|
51
60
|
/** Array of node changes from ReactFlow */
|
|
52
|
-
changes: NodeChanges
|
|
61
|
+
changes: NodeChanges<UnderlyingType, ComplexSchemaType, DataTypeUniqueId>;
|
|
53
62
|
};
|
|
54
63
|
} | {
|
|
55
64
|
/** Update edges based on ReactFlow changes */
|
|
@@ -79,14 +88,51 @@ declare type Action<DataTypeUniqueId extends string = string, NodeTypeUniqueId e
|
|
|
79
88
|
};
|
|
80
89
|
|
|
81
90
|
/** Map of action types for type-safe action dispatching */
|
|
82
|
-
declare const actionTypesMap: {
|
|
91
|
+
export declare const actionTypesMap: {
|
|
83
92
|
readonly ADD_NODE: "ADD_NODE";
|
|
93
|
+
readonly ADD_NODE_AND_SELECT: "ADD_NODE_AND_SELECT";
|
|
84
94
|
readonly UPDATE_NODE_BY_REACT_FLOW: "UPDATE_NODE_BY_REACT_FLOW";
|
|
85
95
|
readonly UPDATE_EDGES_BY_REACT_FLOW: "UPDATE_EDGES_BY_REACT_FLOW";
|
|
86
96
|
readonly ADD_EDGE_BY_REACT_FLOW: "ADD_EDGE_BY_REACT_FLOW";
|
|
87
97
|
readonly UPDATE_INPUT_VALUE: "UPDATE_INPUT_VALUE";
|
|
88
98
|
};
|
|
89
99
|
|
|
100
|
+
/**
|
|
101
|
+
* Adds a new edge between two handles with type checking and inference
|
|
102
|
+
*
|
|
103
|
+
* This function validates that a connection is allowed between two handles based on
|
|
104
|
+
* their data types, handles type inference for 'inferFromConnection' types, and
|
|
105
|
+
* validates Zod schema compatibility for complex types.
|
|
106
|
+
*
|
|
107
|
+
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
108
|
+
* @template NodeTypeUniqueId - Unique identifier type for node types
|
|
109
|
+
* @template UnderlyingType - Supported underlying data types
|
|
110
|
+
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
111
|
+
* @param nodes - Array of nodes in the graph
|
|
112
|
+
* @param edges - Array of edges in the graph
|
|
113
|
+
* @param newEdgeSourceNodeId - ID of the source node
|
|
114
|
+
* @param newEdgeSourceHandleId - ID of the source handle
|
|
115
|
+
* @param newEdgeTargetNodeId - ID of the target node
|
|
116
|
+
* @param newEdgeTargetHandleId - ID of the target handle
|
|
117
|
+
* @param state - The current graph state
|
|
118
|
+
* @param allowedConversionsBetweenDataTypes - Optional mapping of allowed conversions
|
|
119
|
+
* @param enableTypeInference - Whether to enable type inference
|
|
120
|
+
* @param enableComplexTypeChecking - Whether to enable complex type checking
|
|
121
|
+
* @returns Object containing updated nodes, edges, and validation result
|
|
122
|
+
*/
|
|
123
|
+
export declare function addEdgeWithTypeChecking<DataTypeUniqueId extends string = string, NodeTypeUniqueId extends string = string, UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never>(newEdgeSourceNodeId: string, newEdgeSourceHandleId: string, newEdgeTargetNodeId: string, newEdgeTargetHandleId: string, state: State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>): {
|
|
124
|
+
updatedNodes: Nodes<UnderlyingType, ComplexSchemaType, DataTypeUniqueId>;
|
|
125
|
+
updatedEdges: Edges;
|
|
126
|
+
validation: ConnectionValidationResult;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Mapping of allowed conversions between data types
|
|
131
|
+
*
|
|
132
|
+
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
133
|
+
*/
|
|
134
|
+
declare type AllowedConversionsBetweenDataTypes<DataTypeUniqueId extends string = string> = Partial<Record<DataTypeUniqueId, Partial<Record<DataTypeUniqueId, boolean>>>>;
|
|
135
|
+
|
|
90
136
|
/**
|
|
91
137
|
* Represents a rectangular bounding box
|
|
92
138
|
*/
|
|
@@ -322,9 +368,9 @@ name?: string;
|
|
|
322
368
|
/** Background color of the node header */
|
|
323
369
|
headerColor?: string;
|
|
324
370
|
/** Array of inputs and input panels */
|
|
325
|
-
inputs?: (ConfigurableNodeInput | ConfigurableNodeInputPanel)[];
|
|
371
|
+
inputs?: (ConfigurableNodeInput<"string" | "number" | "complex" | "noEquivalent" | "inferFromConnection", never, string> | ConfigurableNodeInputPanel<"string" | "number" | "complex" | "noEquivalent" | "inferFromConnection", never, string>)[] | undefined;
|
|
326
372
|
/** Array of output sockets */
|
|
327
|
-
outputs?: ConfigurableNodeOutput[];
|
|
373
|
+
outputs?: ConfigurableNodeOutput<"string" | "number" | "complex" | "noEquivalent" | "inferFromConnection", never, string>[] | undefined;
|
|
328
374
|
/** Whether the node is currently inside a ReactFlow context */
|
|
329
375
|
isCurrentlyInsideReactFlow?: boolean;
|
|
330
376
|
/** Props for the node resizer component */
|
|
@@ -337,7 +383,7 @@ nodeResizerProps?: NodeResizerWithMoreControlsProps;
|
|
|
337
383
|
* Defines an input socket on a node with optional interactive input component.
|
|
338
384
|
* Supports both string and number types with type-specific onChange handlers.
|
|
339
385
|
*/
|
|
340
|
-
export declare type ConfigurableNodeInput = {
|
|
386
|
+
export declare type ConfigurableNodeInput<UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never, DataTypeUniqueId extends string = string> = {
|
|
341
387
|
/** Unique identifier for the input */
|
|
342
388
|
id: string;
|
|
343
389
|
/** Display name for the input */
|
|
@@ -348,6 +394,16 @@ export declare type ConfigurableNodeInput = {
|
|
|
348
394
|
handleShape?: HandleShape;
|
|
349
395
|
/** Whether to show an interactive input component when not connected */
|
|
350
396
|
allowInput?: boolean;
|
|
397
|
+
/** Data type of the input, used by full graph */
|
|
398
|
+
dataType?: {
|
|
399
|
+
dataTypeObject: DataType<UnderlyingType, ComplexSchemaType>;
|
|
400
|
+
dataTypeUniqueId: DataTypeUniqueId;
|
|
401
|
+
};
|
|
402
|
+
/** Inferred data type of the input (only when type inference is enabled and datatype is inferredFromConnection and connected), used by full graph */
|
|
403
|
+
inferredDataType?: {
|
|
404
|
+
dataTypeObject: DataType<UnderlyingType, ComplexSchemaType>;
|
|
405
|
+
dataTypeUniqueId: DataTypeUniqueId;
|
|
406
|
+
} | null;
|
|
351
407
|
} & ({
|
|
352
408
|
/** String input type */
|
|
353
409
|
type: 'string';
|
|
@@ -369,13 +425,13 @@ export declare type ConfigurableNodeInput = {
|
|
|
369
425
|
*
|
|
370
426
|
* Groups multiple inputs together in a collapsible panel for better organization.
|
|
371
427
|
*/
|
|
372
|
-
export declare type ConfigurableNodeInputPanel = {
|
|
428
|
+
export declare type ConfigurableNodeInputPanel<UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never, DataTypeUniqueId extends string = string> = {
|
|
373
429
|
/** Unique identifier for the panel */
|
|
374
430
|
id: string;
|
|
375
431
|
/** Display name for the panel */
|
|
376
432
|
name: string;
|
|
377
433
|
/** Array of inputs contained in this panel */
|
|
378
|
-
inputs: ConfigurableNodeInput[];
|
|
434
|
+
inputs: ConfigurableNodeInput<UnderlyingType, ComplexSchemaType, DataTypeUniqueId>[];
|
|
379
435
|
};
|
|
380
436
|
|
|
381
437
|
/**
|
|
@@ -383,7 +439,7 @@ export declare type ConfigurableNodeInputPanel = {
|
|
|
383
439
|
*
|
|
384
440
|
* Defines an output socket on a node that can be connected to inputs.
|
|
385
441
|
*/
|
|
386
|
-
export declare type ConfigurableNodeOutput = {
|
|
442
|
+
export declare type ConfigurableNodeOutput<UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never, DataTypeUniqueId extends string = string> = {
|
|
387
443
|
/** Unique identifier for the output */
|
|
388
444
|
id: string;
|
|
389
445
|
/** Display name for the output */
|
|
@@ -392,6 +448,16 @@ export declare type ConfigurableNodeOutput = {
|
|
|
392
448
|
handleColor?: string;
|
|
393
449
|
/** Shape of the output handle (circle, square, diamond, etc.) */
|
|
394
450
|
handleShape?: HandleShape;
|
|
451
|
+
/** Data type of the output, used by full graph */
|
|
452
|
+
dataType?: {
|
|
453
|
+
dataTypeObject: DataType<UnderlyingType, ComplexSchemaType>;
|
|
454
|
+
dataTypeUniqueId: DataTypeUniqueId;
|
|
455
|
+
};
|
|
456
|
+
/** Inferred data type of the output (only when type inference is enabled and datatype is inferredFromConnection and connected), used by full graph */
|
|
457
|
+
inferredDataType?: {
|
|
458
|
+
dataTypeObject: DataType<UnderlyingType, ComplexSchemaType>;
|
|
459
|
+
dataTypeUniqueId: DataTypeUniqueId;
|
|
460
|
+
} | null;
|
|
395
461
|
} & ({
|
|
396
462
|
/** String output type */
|
|
397
463
|
type: 'string';
|
|
@@ -406,15 +472,15 @@ export declare type ConfigurableNodeOutput = {
|
|
|
406
472
|
* Defines the complete configuration for a customizable node with inputs, outputs,
|
|
407
473
|
* and optional panels. Supports both standalone usage and ReactFlow integration.
|
|
408
474
|
*/
|
|
409
|
-
export declare type ConfigurableNodeProps = {
|
|
475
|
+
export declare type ConfigurableNodeProps<UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never, DataTypeUniqueId extends string = string> = {
|
|
410
476
|
/** Display name of the node */
|
|
411
477
|
name?: string;
|
|
412
478
|
/** Background color of the node header */
|
|
413
479
|
headerColor?: string;
|
|
414
480
|
/** Array of inputs and input panels */
|
|
415
|
-
inputs?: (ConfigurableNodeInput | ConfigurableNodeInputPanel)[];
|
|
481
|
+
inputs?: (ConfigurableNodeInput<UnderlyingType, ComplexSchemaType, DataTypeUniqueId> | ConfigurableNodeInputPanel<UnderlyingType, ComplexSchemaType, DataTypeUniqueId>)[];
|
|
416
482
|
/** Array of output sockets */
|
|
417
|
-
outputs?: ConfigurableNodeOutput[];
|
|
483
|
+
outputs?: ConfigurableNodeOutput<UnderlyingType, ComplexSchemaType, DataTypeUniqueId>[];
|
|
418
484
|
/** Whether the node is currently inside a ReactFlow context */
|
|
419
485
|
isCurrentlyInsideReactFlow?: boolean;
|
|
420
486
|
/** Props for the node resizer component */
|
|
@@ -464,17 +530,187 @@ export declare type ConfigurableNodeProps = {
|
|
|
464
530
|
* />
|
|
465
531
|
* ```
|
|
466
532
|
*/
|
|
467
|
-
export declare const ConfigurableNodeReactFlowWrapper: ForwardRefExoticComponent<
|
|
468
|
-
isConnectable: boolean;
|
|
469
|
-
positionAbsoluteX: number;
|
|
470
|
-
positionAbsoluteY: number;
|
|
471
|
-
} & RefAttributes<HTMLDivElement>>;
|
|
533
|
+
export declare const ConfigurableNodeReactFlowWrapper: ForwardRefExoticComponent<Omit<ConfigurableNodeReactFlowWrapperProps<"string" | "number" | "complex" | "noEquivalent" | "inferFromConnection", never, string>, "position"> & RefAttributes<HTMLDivElement>>;
|
|
472
534
|
|
|
473
535
|
/** Props for the ConfigurableNodeReactFlowWrapper component */
|
|
474
|
-
export declare type ConfigurableNodeReactFlowWrapperProps = NodeProps<ConfigurableNodeState
|
|
536
|
+
export declare type ConfigurableNodeReactFlowWrapperProps<UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never, DataTypeUniqueId extends string = string> = NodeProps<ConfigurableNodeState<UnderlyingType, ComplexSchemaType, DataTypeUniqueId>> & {
|
|
537
|
+
position: XYPosition;
|
|
538
|
+
};
|
|
475
539
|
|
|
476
540
|
/** State type for configurable nodes in ReactFlow */
|
|
477
|
-
export declare type ConfigurableNodeState = Node_2<Omit<ConfigurableNodeProps, 'isCurrentlyInsideReactFlow'>, 'configurableNode'>;
|
|
541
|
+
export declare type ConfigurableNodeState<UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never, DataTypeUniqueId extends string = string> = Node_2<Omit<ConfigurableNodeProps<UnderlyingType, ComplexSchemaType, DataTypeUniqueId>, 'isCurrentlyInsideReactFlow'>, 'configurableNode'>;
|
|
542
|
+
|
|
543
|
+
/**
|
|
544
|
+
* Type for connection validation result
|
|
545
|
+
*/
|
|
546
|
+
declare type ConnectionValidationResult = {
|
|
547
|
+
isValid: boolean;
|
|
548
|
+
reason?: string;
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Constructs a ConfigurableNodeInput or ConfigurableNodeOutput from a type definition
|
|
553
|
+
*
|
|
554
|
+
* This function creates the appropriate input or output instance based on the data type's
|
|
555
|
+
* underlying type (string or number). It generates a unique ID and applies the correct
|
|
556
|
+
* configuration including handle color and input allowance.
|
|
557
|
+
*
|
|
558
|
+
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
559
|
+
* @template NodeTypeUniqueId - Unique identifier type for node types
|
|
560
|
+
* @template UnderlyingType - Supported underlying data types ('string' | 'number' | 'complex')
|
|
561
|
+
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
562
|
+
* @param typeOfDataType - The type definition for the input or output
|
|
563
|
+
* @param dataTypes - Map of data type definitions
|
|
564
|
+
* @returns Constructed input or output instance
|
|
565
|
+
*
|
|
566
|
+
* @example
|
|
567
|
+
* ```tsx
|
|
568
|
+
* import {
|
|
569
|
+
* constructInputOrOutputOfType,
|
|
570
|
+
* makeDataTypeWithAutoInfer
|
|
571
|
+
* } from 'react-blender-nodes';
|
|
572
|
+
*
|
|
573
|
+
* // Define data types with auto-infer for type safety
|
|
574
|
+
* const dataTypes = {
|
|
575
|
+
* stringType: makeDataTypeWithAutoInfer({
|
|
576
|
+
* name: 'String',
|
|
577
|
+
* underlyingType: 'string',
|
|
578
|
+
* color: '#4A90E2',
|
|
579
|
+
* }),
|
|
580
|
+
* };
|
|
581
|
+
*
|
|
582
|
+
* // Construct input with type safety
|
|
583
|
+
* const input = constructInputOrOutputOfType(
|
|
584
|
+
* { name: 'Value', dataType: 'stringType', allowInput: true },
|
|
585
|
+
* dataTypes
|
|
586
|
+
* );
|
|
587
|
+
* ```
|
|
588
|
+
*/
|
|
589
|
+
export declare function constructInputOrOutputOfType<DataTypeUniqueId extends string = string, NodeTypeUniqueId extends string = string, UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never>(typeOfDataTypeInNode: TypeOfInput<DataTypeUniqueId> | TypeOfNode<DataTypeUniqueId>['outputs'][number], allDataTypes: State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>['dataTypes']): ConfigurableNodeInput<UnderlyingType, ComplexSchemaType, DataTypeUniqueId> | ConfigurableNodeOutput<UnderlyingType, ComplexSchemaType, DataTypeUniqueId>;
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Constructs a ConfigurableNodeInputPanel from a type definition
|
|
593
|
+
*
|
|
594
|
+
* This function creates an input panel with multiple inputs based on the panel type
|
|
595
|
+
* definition. It generates a unique panel ID and constructs all the inputs within
|
|
596
|
+
* the panel using the constructInputOrOutputOfType function.
|
|
597
|
+
*
|
|
598
|
+
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
599
|
+
* @template NodeTypeUniqueId - Unique identifier type for node types
|
|
600
|
+
* @template UnderlyingType - Supported underlying data types ('string' | 'number' | 'complex')
|
|
601
|
+
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
602
|
+
* @param typeOfPanel - The type definition for the input panel
|
|
603
|
+
* @param dataTypes - Map of data type definitions
|
|
604
|
+
* @returns Constructed input panel instance
|
|
605
|
+
*
|
|
606
|
+
* @example
|
|
607
|
+
* ```tsx
|
|
608
|
+
* import {
|
|
609
|
+
* constructInputPanelOfType,
|
|
610
|
+
* makeDataTypeWithAutoInfer
|
|
611
|
+
* } from 'react-blender-nodes';
|
|
612
|
+
*
|
|
613
|
+
* // Define data types with auto-infer for type safety
|
|
614
|
+
* const dataTypes = {
|
|
615
|
+
* numberType: makeDataTypeWithAutoInfer({
|
|
616
|
+
* name: 'Number',
|
|
617
|
+
* underlyingType: 'number',
|
|
618
|
+
* color: '#E74C3C',
|
|
619
|
+
* }),
|
|
620
|
+
* };
|
|
621
|
+
*
|
|
622
|
+
* // Construct panel with type safety
|
|
623
|
+
* const panel = constructInputPanelOfType(
|
|
624
|
+
* {
|
|
625
|
+
* name: 'Settings',
|
|
626
|
+
* inputs: [
|
|
627
|
+
* { name: 'Width', dataType: 'numberType' },
|
|
628
|
+
* { name: 'Height', dataType: 'numberType' }
|
|
629
|
+
* ]
|
|
630
|
+
* },
|
|
631
|
+
* dataTypes
|
|
632
|
+
* );
|
|
633
|
+
* ```
|
|
634
|
+
*/
|
|
635
|
+
export declare function constructInputPanelOfType<DataTypeUniqueId extends string = string, NodeTypeUniqueId extends string = string, UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never>(typeOfPanelInNode: {
|
|
636
|
+
name: string;
|
|
637
|
+
inputs: {
|
|
638
|
+
name: string;
|
|
639
|
+
dataType: DataTypeUniqueId;
|
|
640
|
+
}[];
|
|
641
|
+
}, allDataTypes: State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>['dataTypes']): ConfigurableNodeInputPanel<UnderlyingType, ComplexSchemaType, DataTypeUniqueId>;
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Constructs a complete node from a node type definition
|
|
645
|
+
*
|
|
646
|
+
* This function creates a fully configured ReactFlow node based on the node type
|
|
647
|
+
* definition. It processes all inputs (including panels) and outputs, generates
|
|
648
|
+
* unique IDs, and sets up the node with the correct position and configuration.
|
|
649
|
+
*
|
|
650
|
+
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
651
|
+
* @template NodeTypeUniqueId - Unique identifier type for node types
|
|
652
|
+
* @template UnderlyingType - Supported underlying data types ('string' | 'number' | 'complex')
|
|
653
|
+
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
654
|
+
* @param dataTypes - Map of data type definitions
|
|
655
|
+
* @param nodeType - The unique identifier of the node type
|
|
656
|
+
* @param typeOfNodes - Map of node type definitions
|
|
657
|
+
* @param nodeId - Unique identifier for the new node instance
|
|
658
|
+
* @param position - Position where the node should be placed
|
|
659
|
+
* @returns Complete ReactFlow node instance
|
|
660
|
+
*
|
|
661
|
+
* @example
|
|
662
|
+
* ```tsx
|
|
663
|
+
* import {
|
|
664
|
+
* constructNodeOfType,
|
|
665
|
+
* makeStateWithAutoInfer,
|
|
666
|
+
* makeNodeIdToNodeTypeWithAutoInfer,
|
|
667
|
+
* makeTypeOfNodeWithAutoInfer,
|
|
668
|
+
* makeDataTypeWithAutoInfer
|
|
669
|
+
* } from 'react-blender-nodes';
|
|
670
|
+
*
|
|
671
|
+
* // Define data types with auto-infer for type safety
|
|
672
|
+
* const dataTypes = {
|
|
673
|
+
* stringType: makeDataTypeWithAutoInfer({
|
|
674
|
+
* name: 'String',
|
|
675
|
+
* underlyingType: 'string',
|
|
676
|
+
* color: '#4A90E2',
|
|
677
|
+
* }),
|
|
678
|
+
* };
|
|
679
|
+
*
|
|
680
|
+
* // Define node types with auto-infer for type safety
|
|
681
|
+
* const typeOfNodes = {
|
|
682
|
+
* inputNode: makeTypeOfNodeWithAutoInfer({
|
|
683
|
+
* name: 'Input Node',
|
|
684
|
+
* headerColor: '#C44536',
|
|
685
|
+
* inputs: [{ name: 'Input', dataType: 'stringType', allowInput: true }],
|
|
686
|
+
* outputs: [{ name: 'Output', dataType: 'stringType' }]
|
|
687
|
+
* }),
|
|
688
|
+
* };
|
|
689
|
+
*
|
|
690
|
+
* // Construct node with type safety
|
|
691
|
+
* const node = constructNodeOfType(
|
|
692
|
+
* dataTypes,
|
|
693
|
+
* 'inputNode',
|
|
694
|
+
* typeOfNodes,
|
|
695
|
+
* 'node-123',
|
|
696
|
+
* { x: 100, y: 100 }
|
|
697
|
+
* );
|
|
698
|
+
* ```
|
|
699
|
+
*/
|
|
700
|
+
export declare function constructNodeOfType<DataTypeUniqueId extends string = string, NodeTypeUniqueId extends string = string, UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never>(allDataTypes: State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>['dataTypes'], nodeType: NodeTypeUniqueId, typeOfNodes: State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>['typeOfNodes'], nodeId: string, position: XYPosition): State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>['nodes'][number];
|
|
701
|
+
|
|
702
|
+
/**
|
|
703
|
+
* Constructs the type of a handle from indices
|
|
704
|
+
*
|
|
705
|
+
* This function constructs the type of a handle from indices, handling both regular inputs and inputs within panels.
|
|
706
|
+
*
|
|
707
|
+
* @param allDataTypes - The all data types
|
|
708
|
+
* @param nodeType - The node type
|
|
709
|
+
* @param typeOfNodes - The type of nodes
|
|
710
|
+
* @param indices - The indices of the handle
|
|
711
|
+
* @returns The type of the handle
|
|
712
|
+
*/
|
|
713
|
+
export declare function constructTypeOfHandleFromIndices<DataTypeUniqueId extends string = string, NodeTypeUniqueId extends string = string, UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never>(allDataTypes: State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>['dataTypes'], nodeType: NodeTypeUniqueId, typeOfNodes: State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>['typeOfNodes'], indices: HandleIndices | undefined): ConfigurableNodeInput<UnderlyingType, ComplexSchemaType, DataTypeUniqueId> | ConfigurableNodeOutput<UnderlyingType, ComplexSchemaType, DataTypeUniqueId> | undefined;
|
|
478
714
|
|
|
479
715
|
/**
|
|
480
716
|
* A context-aware handle component for node inputs and outputs
|
|
@@ -739,9 +975,9 @@ export declare type Coordinate = {
|
|
|
739
975
|
* @param contextMenuPosition - The position where the context menu was opened
|
|
740
976
|
* @returns ContextMenuItem array for the context menu
|
|
741
977
|
*/
|
|
742
|
-
export declare function createNodeContextMenu<DataTypeUniqueId extends string = string, NodeTypeUniqueId extends string = string, UnderlyingType extends
|
|
978
|
+
export declare function createNodeContextMenu<DataTypeUniqueId extends string = string, NodeTypeUniqueId extends string = string, UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never>({ typeOfNodes, dispatch, setContextMenu, contextMenuPosition, }: CreateNodeContextMenuProps<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>): ContextMenuItem[];
|
|
743
979
|
|
|
744
|
-
export declare type CreateNodeContextMenuProps<DataTypeUniqueId extends string = string, NodeTypeUniqueId extends string = string, UnderlyingType extends
|
|
980
|
+
export declare type CreateNodeContextMenuProps<DataTypeUniqueId extends string = string, NodeTypeUniqueId extends string = string, UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? any : never = never> = {
|
|
745
981
|
typeOfNodes: State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>['typeOfNodes'];
|
|
746
982
|
dispatch: ActionDispatch<[
|
|
747
983
|
action: Action<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>
|
|
@@ -759,7 +995,7 @@ export declare type CreateNodeContextMenuProps<DataTypeUniqueId extends string =
|
|
|
759
995
|
* @template UnderlyingType - The underlying type of the data
|
|
760
996
|
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
761
997
|
*/
|
|
762
|
-
declare type DataType<UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never> = UnderlyingType extends 'complex' ? {
|
|
998
|
+
export declare type DataType<UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never> = UnderlyingType extends 'complex' ? {
|
|
763
999
|
/** Display name of the data type */
|
|
764
1000
|
name: string;
|
|
765
1001
|
/** The underlying type of the data */
|
|
@@ -768,6 +1004,10 @@ declare type DataType<UnderlyingType extends SupportedUnderlyingTypes = Supporte
|
|
|
768
1004
|
complexSchema: ComplexSchemaType;
|
|
769
1005
|
/** Color used for visual representation */
|
|
770
1006
|
color: string;
|
|
1007
|
+
/** Shape of the handle */
|
|
1008
|
+
shape?: HandleShape;
|
|
1009
|
+
/** Whether this input allows direct user input */
|
|
1010
|
+
allowInput?: boolean;
|
|
771
1011
|
} : {
|
|
772
1012
|
/** Display name of the data type */
|
|
773
1013
|
name: string;
|
|
@@ -777,6 +1017,10 @@ declare type DataType<UnderlyingType extends SupportedUnderlyingTypes = Supporte
|
|
|
777
1017
|
complexSchema?: undefined;
|
|
778
1018
|
/** Color used for visual representation */
|
|
779
1019
|
color: string;
|
|
1020
|
+
/** Shape of the handle */
|
|
1021
|
+
shape?: HandleShape;
|
|
1022
|
+
/** Whether this input allows direct user input */
|
|
1023
|
+
allowInput?: boolean;
|
|
780
1024
|
};
|
|
781
1025
|
|
|
782
1026
|
/**
|
|
@@ -902,6 +1146,16 @@ export declare type FullGraphProps<DataTypeUniqueId extends string = string, Nod
|
|
|
902
1146
|
]>;
|
|
903
1147
|
};
|
|
904
1148
|
|
|
1149
|
+
declare type HandleIndices = {
|
|
1150
|
+
type: 'input';
|
|
1151
|
+
index1: number;
|
|
1152
|
+
index2: number | undefined;
|
|
1153
|
+
} | {
|
|
1154
|
+
type: 'output';
|
|
1155
|
+
index1: number;
|
|
1156
|
+
index2: undefined;
|
|
1157
|
+
};
|
|
1158
|
+
|
|
905
1159
|
/** Type representing all available handle shapes */
|
|
906
1160
|
export declare type HandleShape = (typeof handleShapesMap)[keyof typeof handleShapesMap];
|
|
907
1161
|
|
|
@@ -1026,17 +1280,291 @@ export declare function isCoordinateInBox(coordinate: Coordinate, box: Box, xAxi
|
|
|
1026
1280
|
*/
|
|
1027
1281
|
export declare function isNumberInRange(number: number, min: number, max: number, minInclusive?: boolean, maxInclusive?: boolean): boolean;
|
|
1028
1282
|
|
|
1283
|
+
/**
|
|
1284
|
+
* Type guard to check if a string is a supported underlying type
|
|
1285
|
+
*
|
|
1286
|
+
* @param type - The string to check
|
|
1287
|
+
* @returns True if the string is a supported underlying type
|
|
1288
|
+
*
|
|
1289
|
+
* @example
|
|
1290
|
+
* ```tsx
|
|
1291
|
+
* if (isSupportedUnderlyingType('string')) {
|
|
1292
|
+
* // type is now 'string'
|
|
1293
|
+
* }
|
|
1294
|
+
* ```
|
|
1295
|
+
*/
|
|
1296
|
+
export declare function isSupportedUnderlyingType(type: string): type is SupportedUnderlyingTypes;
|
|
1297
|
+
|
|
1298
|
+
/**
|
|
1299
|
+
* Type guard to check if a string is a valid DataTypeUniqueId
|
|
1300
|
+
*/
|
|
1301
|
+
export declare function isValidDataTypeId<DataTypeUniqueId extends string, UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never>(id: string, dataTypes: Record<DataTypeUniqueId, DataType<UnderlyingType, ComplexSchemaType>>): id is DataTypeUniqueId;
|
|
1302
|
+
|
|
1303
|
+
/**
|
|
1304
|
+
* Type guard to check if a string is a valid NodeTypeUniqueId
|
|
1305
|
+
*/
|
|
1306
|
+
export declare function isValidNodeTypeUniqueId<NodeTypeUniqueId extends string>(id: string, nodeIdToNodeType: Record<string, NodeTypeUniqueId>): id is NodeTypeUniqueId;
|
|
1307
|
+
|
|
1308
|
+
/**
|
|
1309
|
+
* Main reducer function for managing graph state
|
|
1310
|
+
*
|
|
1311
|
+
* This reducer handles all state updates for the graph including nodes, edges,
|
|
1312
|
+
* and input values. It uses Immer for immutable state updates and integrates
|
|
1313
|
+
* with ReactFlow for node and edge management.
|
|
1314
|
+
*
|
|
1315
|
+
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
1316
|
+
* @template NodeTypeUniqueId - Unique identifier type for node types
|
|
1317
|
+
* @template UnderlyingType - Supported underlying data types ('string' | 'number' | 'complex')
|
|
1318
|
+
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
1319
|
+
* @param oldState - The current state of the graph
|
|
1320
|
+
* @param action - The action to apply to the state
|
|
1321
|
+
* @returns New state after applying the action
|
|
1322
|
+
*
|
|
1323
|
+
* @example
|
|
1324
|
+
* ```tsx
|
|
1325
|
+
* import {
|
|
1326
|
+
* mainReducer,
|
|
1327
|
+
* makeStateWithAutoInfer,
|
|
1328
|
+
* makeNodeIdToNodeTypeWithAutoInfer,
|
|
1329
|
+
* makeTypeOfNodeWithAutoInfer,
|
|
1330
|
+
* makeDataTypeWithAutoInfer
|
|
1331
|
+
* } from 'react-blender-nodes';
|
|
1332
|
+
*
|
|
1333
|
+
* // Create type-safe state with auto-infer helpers
|
|
1334
|
+
* const dataTypes = {
|
|
1335
|
+
* stringType: makeDataTypeWithAutoInfer({
|
|
1336
|
+
* name: 'String',
|
|
1337
|
+
* underlyingType: 'string',
|
|
1338
|
+
* color: '#4A90E2',
|
|
1339
|
+
* }),
|
|
1340
|
+
* };
|
|
1341
|
+
*
|
|
1342
|
+
* const typeOfNodes = {
|
|
1343
|
+
* inputNode: makeTypeOfNodeWithAutoInfer({
|
|
1344
|
+
* name: 'Input Node',
|
|
1345
|
+
* headerColor: '#C44536',
|
|
1346
|
+
* inputs: [{ name: 'Input', dataType: 'stringType', allowInput: true }],
|
|
1347
|
+
* outputs: [{ name: 'Output', dataType: 'stringType' }],
|
|
1348
|
+
* }),
|
|
1349
|
+
* };
|
|
1350
|
+
*
|
|
1351
|
+
* const nodeIdToNodeType = makeNodeIdToNodeTypeWithAutoInfer({
|
|
1352
|
+
* 'node-1': 'inputNode',
|
|
1353
|
+
* });
|
|
1354
|
+
*
|
|
1355
|
+
* const state = makeStateWithAutoInfer({
|
|
1356
|
+
* dataTypes,
|
|
1357
|
+
* typeOfNodes,
|
|
1358
|
+
* nodeIdToNodeType,
|
|
1359
|
+
* nodes: [],
|
|
1360
|
+
* edges: [],
|
|
1361
|
+
* });
|
|
1362
|
+
*
|
|
1363
|
+
* // Add a new node (type-safe!)
|
|
1364
|
+
* const newState = mainReducer(state, {
|
|
1365
|
+
* type: 'ADD_NODE',
|
|
1366
|
+
* payload: {
|
|
1367
|
+
* type: 'inputNode',
|
|
1368
|
+
* position: { x: 100, y: 100 },
|
|
1369
|
+
* },
|
|
1370
|
+
* });
|
|
1371
|
+
*
|
|
1372
|
+
* // Update input value (type-safe!)
|
|
1373
|
+
* const updatedState = mainReducer(newState, {
|
|
1374
|
+
* type: 'UPDATE_INPUT_VALUE',
|
|
1375
|
+
* payload: {
|
|
1376
|
+
* nodeId: 'node1',
|
|
1377
|
+
* inputId: 'input1',
|
|
1378
|
+
* value: 'new value',
|
|
1379
|
+
* },
|
|
1380
|
+
* });
|
|
1381
|
+
* ```
|
|
1382
|
+
*/
|
|
1383
|
+
export declare function mainReducer<DataTypeUniqueId extends string = string, NodeTypeUniqueId extends string = string, UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never>(oldState: State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>, action: Action<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>): State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>;
|
|
1384
|
+
|
|
1385
|
+
/**
|
|
1386
|
+
* Helper function to create a mapping of allowed conversions between data types with automatic type inference
|
|
1387
|
+
*
|
|
1388
|
+
* This function is essential for type safety when creating a mapping of allowed conversions between data types.
|
|
1389
|
+
* It ensures that TypeScript can properly infer and validate the types throughout your graph system,
|
|
1390
|
+
* preventing runtime errors and providing better IDE support.
|
|
1391
|
+
*
|
|
1392
|
+
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
1393
|
+
* @param input - The mapping of allowed conversions between data types
|
|
1394
|
+
* @returns The mapping with proper typing
|
|
1395
|
+
*
|
|
1396
|
+
* @example
|
|
1397
|
+
* ```tsx
|
|
1398
|
+
* // ✅ Type-safe - TypeScript will validate node type references
|
|
1399
|
+
* const allowedConversionsBetweenDataTypes = makeAllowedConversionsBetweenDataTypesWithAutoInfer({
|
|
1400
|
+
* 'inputDataType': {
|
|
1401
|
+
* 'outputDataType': true,
|
|
1402
|
+
* },
|
|
1403
|
+
* });
|
|
1404
|
+
*
|
|
1405
|
+
* // ❌ Without auto-infer - TypeScript can't validate node type references
|
|
1406
|
+
* const allowedConversionsBetweenDataTypes = {
|
|
1407
|
+
* 'inputDataType': {
|
|
1408
|
+
* 'outputDataType': true,
|
|
1409
|
+
* },
|
|
1410
|
+
* };
|
|
1411
|
+
* ```
|
|
1412
|
+
*/
|
|
1413
|
+
export declare function makeAllowedConversionsBetweenDataTypesWithAutoInfer<DataTypeUniqueId extends string = string>(input: AllowedConversionsBetweenDataTypes<DataTypeUniqueId>): Partial<Record<DataTypeUniqueId, Partial<Record<DataTypeUniqueId, boolean>>>>;
|
|
1414
|
+
|
|
1415
|
+
/**
|
|
1416
|
+
* Helper function to create a data type with automatic type inference
|
|
1417
|
+
*
|
|
1418
|
+
* This function is essential for type safety when defining data types. It ensures
|
|
1419
|
+
* that TypeScript can properly infer and validate the types throughout your graph
|
|
1420
|
+
* system, preventing runtime errors and providing better IDE support.
|
|
1421
|
+
*
|
|
1422
|
+
* @template UnderlyingType - The underlying type of the data
|
|
1423
|
+
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
1424
|
+
* @param input - The data type definition
|
|
1425
|
+
* @returns The data type definition with proper typing
|
|
1426
|
+
*
|
|
1427
|
+
* @example
|
|
1428
|
+
* ```tsx
|
|
1429
|
+
* // ✅ Type-safe - TypeScript will validate dataType references
|
|
1430
|
+
* const stringType = makeDataTypeWithAutoInfer({
|
|
1431
|
+
* name: 'String',
|
|
1432
|
+
* underlyingType: 'string',
|
|
1433
|
+
* color: '#4A90E2',
|
|
1434
|
+
* });
|
|
1435
|
+
*
|
|
1436
|
+
* // ❌ Without auto-infer - TypeScript can't validate references
|
|
1437
|
+
* const stringType = {
|
|
1438
|
+
* name: 'String',
|
|
1439
|
+
* underlyingType: 'string',
|
|
1440
|
+
* color: '#4A90E2',
|
|
1441
|
+
* };
|
|
1442
|
+
* ```
|
|
1443
|
+
*/
|
|
1444
|
+
export declare function makeDataTypeWithAutoInfer<UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never>(input: DataType<UnderlyingType, ComplexSchemaType>): DataType<UnderlyingType, ComplexSchemaType>;
|
|
1445
|
+
|
|
1446
|
+
/**
|
|
1447
|
+
* Helper function to create a node ID to node type mapping with automatic type inference
|
|
1448
|
+
*
|
|
1449
|
+
* This function is essential for type safety when mapping node IDs to their types.
|
|
1450
|
+
* It ensures that TypeScript can validate that all node type references are valid,
|
|
1451
|
+
* preventing runtime errors when dispatching actions and providing better IDE support.
|
|
1452
|
+
*
|
|
1453
|
+
* @template NodeTypeUniqueId - Unique identifier type for node types
|
|
1454
|
+
* @param input - The node ID to node type mapping
|
|
1455
|
+
* @returns The mapping with proper typing
|
|
1456
|
+
*
|
|
1457
|
+
* @example
|
|
1458
|
+
* ```tsx
|
|
1459
|
+
* // ✅ Type-safe - TypeScript will validate node type references
|
|
1460
|
+
* const nodeIdToNodeType = makeNodeIdToNodeTypeWithAutoInfer({
|
|
1461
|
+
* 'node-1': 'inputNode',
|
|
1462
|
+
* 'node-2': 'outputNode',
|
|
1463
|
+
* });
|
|
1464
|
+
*
|
|
1465
|
+
* // ❌ Without auto-infer - TypeScript can't validate node type references
|
|
1466
|
+
* const nodeIdToNodeType = {
|
|
1467
|
+
* 'node-1': 'inputNode',
|
|
1468
|
+
* 'node-2': 'outputNode',
|
|
1469
|
+
* };
|
|
1470
|
+
* ```
|
|
1471
|
+
*/
|
|
1472
|
+
export declare function makeNodeIdToNodeTypeWithAutoInfer<NodeTypeUniqueId extends string = string>(input: NodeIdToNodeType<NodeTypeUniqueId>): NodeIdToNodeType<NodeTypeUniqueId>;
|
|
1473
|
+
|
|
1474
|
+
/**
|
|
1475
|
+
* Helper function to create a state with automatic type inference
|
|
1476
|
+
*
|
|
1477
|
+
* This function is essential for complete type safety when creating the graph state.
|
|
1478
|
+
* It ensures that TypeScript can properly infer and validate all type relationships
|
|
1479
|
+
* throughout your graph system, providing compile-time type checking and better IDE support.
|
|
1480
|
+
*
|
|
1481
|
+
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
1482
|
+
* @template NodeTypeUniqueId - Unique identifier type for node types
|
|
1483
|
+
* @template UnderlyingType - Supported underlying data types ('string' | 'number' | 'complex')
|
|
1484
|
+
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
1485
|
+
* @param input - The state definition
|
|
1486
|
+
* @returns The state with proper typing
|
|
1487
|
+
*
|
|
1488
|
+
* @example
|
|
1489
|
+
* ```tsx
|
|
1490
|
+
* // ✅ Type-safe - Complete type inference and validation
|
|
1491
|
+
* const state = makeStateWithAutoInfer({
|
|
1492
|
+
* dataTypes: {
|
|
1493
|
+
* stringType: makeDataTypeWithAutoInfer({
|
|
1494
|
+
* name: 'String',
|
|
1495
|
+
* underlyingType: 'string',
|
|
1496
|
+
* color: '#4A90E2'
|
|
1497
|
+
* })
|
|
1498
|
+
* },
|
|
1499
|
+
* typeOfNodes: {
|
|
1500
|
+
* inputNode: makeTypeOfNodeWithAutoInfer({
|
|
1501
|
+
* name: 'Input',
|
|
1502
|
+
* inputs: [],
|
|
1503
|
+
* outputs: []
|
|
1504
|
+
* })
|
|
1505
|
+
* },
|
|
1506
|
+
* nodeIdToNodeType: makeNodeIdToNodeTypeWithAutoInfer({}),
|
|
1507
|
+
* nodes: [],
|
|
1508
|
+
* edges: [],
|
|
1509
|
+
* });
|
|
1510
|
+
*
|
|
1511
|
+
* // ❌ Without auto-infer - No type validation
|
|
1512
|
+
* const state = {
|
|
1513
|
+
* dataTypes: { stringType: { name: 'String', underlyingType: 'string', color: '#4A90E2' } },
|
|
1514
|
+
* typeOfNodes: { inputNode: { name: 'Input', inputs: [], outputs: [] } },
|
|
1515
|
+
* nodes: [],
|
|
1516
|
+
* nodeIdToNodeType: {},
|
|
1517
|
+
* edges: [],
|
|
1518
|
+
* };
|
|
1519
|
+
* ```
|
|
1520
|
+
*/
|
|
1521
|
+
export declare function makeStateWithAutoInfer<DataTypeUniqueId extends string = string, NodeTypeUniqueId extends string = string, UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never>(input: State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>): State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>;
|
|
1522
|
+
|
|
1523
|
+
/**
|
|
1524
|
+
* Helper function to create a node type with automatic type inference
|
|
1525
|
+
*
|
|
1526
|
+
* This function is essential for type safety when defining node types. It ensures
|
|
1527
|
+
* that TypeScript can properly validate dataType references in inputs and outputs,
|
|
1528
|
+
* preventing runtime errors when creating nodes and providing better IDE support.
|
|
1529
|
+
*
|
|
1530
|
+
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
1531
|
+
* @param input - The node type definition
|
|
1532
|
+
* @returns The node type definition with proper typing
|
|
1533
|
+
*
|
|
1534
|
+
* @example
|
|
1535
|
+
* ```tsx
|
|
1536
|
+
* // ✅ Type-safe - TypeScript will validate dataType references
|
|
1537
|
+
* const inputNodeType = makeTypeOfNodeWithAutoInfer({
|
|
1538
|
+
* name: 'Input Node',
|
|
1539
|
+
* headerColor: '#C44536',
|
|
1540
|
+
* inputs: [{ name: 'Input', dataType: 'stringType', allowInput: true }],
|
|
1541
|
+
* outputs: [{ name: 'Output', dataType: 'stringType' }],
|
|
1542
|
+
* });
|
|
1543
|
+
*
|
|
1544
|
+
* // ❌ Without auto-infer - TypeScript can't validate dataType references
|
|
1545
|
+
* const inputNodeType = {
|
|
1546
|
+
* name: 'Input Node',
|
|
1547
|
+
* headerColor: '#C44536',
|
|
1548
|
+
* inputs: [{ name: 'Input', dataType: 'stringType', allowInput: true }],
|
|
1549
|
+
* outputs: [{ name: 'Output', dataType: 'stringType' }],
|
|
1550
|
+
* };
|
|
1551
|
+
* ```
|
|
1552
|
+
*/
|
|
1553
|
+
export declare function makeTypeOfNodeWithAutoInfer<DataTypeUniqueId extends string = string>(input: TypeOfNode<DataTypeUniqueId>): TypeOfNode<DataTypeUniqueId>;
|
|
1554
|
+
|
|
1029
1555
|
/**
|
|
1030
1556
|
* Array of node changes for ReactFlow
|
|
1031
1557
|
*/
|
|
1032
|
-
export declare type NodeChanges = NodeChange<
|
|
1558
|
+
export declare type NodeChanges<UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never, DataTypeUniqueId extends string = string> = NodeChange<Optional<ConfigurableNodeReactFlowWrapperProps<UnderlyingType, ComplexSchemaType, DataTypeUniqueId>, NodeOptionalKeys>>[];
|
|
1033
1559
|
|
|
1034
1560
|
/**
|
|
1035
1561
|
* Mapping from node IDs to their node types
|
|
1036
1562
|
*
|
|
1037
1563
|
* @template NodeTypeUniqueId - Unique identifier type for node types
|
|
1038
1564
|
*/
|
|
1039
|
-
declare type NodeIdToNodeType<NodeTypeUniqueId extends string = string> = Record<string, NodeTypeUniqueId>;
|
|
1565
|
+
export declare type NodeIdToNodeType<NodeTypeUniqueId extends string = string> = Record<string, NodeTypeUniqueId>;
|
|
1566
|
+
|
|
1567
|
+
declare type NodeOptionalKeys = 'draggable' | 'zIndex' | 'selectable' | 'deletable' | 'dragging' | 'selected' | 'isConnectable' | 'positionAbsoluteX' | 'positionAbsoluteY';
|
|
1040
1568
|
|
|
1041
1569
|
/**
|
|
1042
1570
|
* Enhanced node resizer component with customizable controls
|
|
@@ -1106,7 +1634,9 @@ export declare type NodeResizerWithMoreControlsProps = NodeResizerProps & {
|
|
|
1106
1634
|
/**
|
|
1107
1635
|
* Array of configurable nodes in the graph
|
|
1108
1636
|
*/
|
|
1109
|
-
export declare type Nodes =
|
|
1637
|
+
export declare type Nodes<UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never, DataTypeUniqueId extends string = string> = Optional<ConfigurableNodeReactFlowWrapperProps<UnderlyingType, ComplexSchemaType, DataTypeUniqueId>, NodeOptionalKeys>[];
|
|
1638
|
+
|
|
1639
|
+
declare type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
1110
1640
|
|
|
1111
1641
|
/**
|
|
1112
1642
|
* ReactFlow-aware input component that automatically updates node data
|
|
@@ -1128,6 +1658,35 @@ export declare type ReactFlowAwareInputProps = {
|
|
|
1128
1658
|
input: ConfigurableNodeInput;
|
|
1129
1659
|
};
|
|
1130
1660
|
|
|
1661
|
+
/**
|
|
1662
|
+
* Removes an edge between two handles with type checking and inference
|
|
1663
|
+
*
|
|
1664
|
+
* This function validates that a connection is removed between two handles based on
|
|
1665
|
+
* their data types, handles type inference for 'inferFromConnection' types, and
|
|
1666
|
+
* validates Zod schema compatibility for complex types.
|
|
1667
|
+
*
|
|
1668
|
+
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
1669
|
+
* @template NodeTypeUniqueId - Unique identifier type for node types
|
|
1670
|
+
* @template UnderlyingType - Supported underlying data types
|
|
1671
|
+
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
1672
|
+
* @param nodes - Array of nodes in the graph
|
|
1673
|
+
* @param edges - Array of edges in the graph
|
|
1674
|
+
* @param removedEdgeSourceNodeId - ID of the source node
|
|
1675
|
+
* @param removedEdgeSourceHandleId - ID of the source handle
|
|
1676
|
+
* @param removedEdgeTargetNodeId - ID of the target node
|
|
1677
|
+
* @param removedEdgeTargetHandleId - ID of the target handle
|
|
1678
|
+
* @param state - The current graph state
|
|
1679
|
+
* @param allowedConversionsBetweenDataTypes - Optional mapping of allowed conversions
|
|
1680
|
+
* @param enableTypeInference - Whether to enable type inference
|
|
1681
|
+
* @param enableComplexTypeChecking - Whether to enable complex type checking
|
|
1682
|
+
* @returns Object containing updated nodes, edges, and validation result
|
|
1683
|
+
*/
|
|
1684
|
+
export declare function removeEdgeWithTypeChecking<DataTypeUniqueId extends string = string, NodeTypeUniqueId extends string = string, UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never>(removedEdge: State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>['edges'][number], state: State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>, removedEdgeChange: EdgeChange<ConfigurableEdgeState>): {
|
|
1685
|
+
updatedNodes: Nodes<UnderlyingType, ComplexSchemaType, DataTypeUniqueId>;
|
|
1686
|
+
updatedEdges: Edges;
|
|
1687
|
+
validation: ConnectionValidationResult;
|
|
1688
|
+
};
|
|
1689
|
+
|
|
1131
1690
|
/**
|
|
1132
1691
|
* Sanitizes a number to be shown as a text, removing the trailing zeros after the decimal point if the number is an integer
|
|
1133
1692
|
* @param value - The number to sanitize
|
|
@@ -1215,35 +1774,52 @@ export declare type SliderNumberInputProps = {
|
|
|
1215
1774
|
* @template UnderlyingType - Supported underlying data types ('string' | 'number' | 'complex')
|
|
1216
1775
|
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
1217
1776
|
*/
|
|
1218
|
-
declare type State<DataTypeUniqueId extends string = string, NodeTypeUniqueId extends string = string, UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never> = {
|
|
1777
|
+
export declare type State<DataTypeUniqueId extends string = string, NodeTypeUniqueId extends string = string, UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never> = {
|
|
1219
1778
|
/** Map of data type definitions */
|
|
1220
1779
|
dataTypes: Record<DataTypeUniqueId, DataType<UnderlyingType, ComplexSchemaType>>;
|
|
1221
1780
|
/** Map of node type definitions */
|
|
1222
1781
|
typeOfNodes: Record<NodeTypeUniqueId, TypeOfNode<DataTypeUniqueId>>;
|
|
1223
1782
|
/** Array of nodes in the graph */
|
|
1224
|
-
nodes: Nodes
|
|
1783
|
+
nodes: Nodes<UnderlyingType, ComplexSchemaType, DataTypeUniqueId>;
|
|
1225
1784
|
/** Mapping from node IDs to their types */
|
|
1226
1785
|
nodeIdToNodeType: NodeIdToNodeType<NodeTypeUniqueId>;
|
|
1227
1786
|
/** Array of edges in the graph */
|
|
1228
1787
|
edges: Edges;
|
|
1788
|
+
/** Optional mapping of allowed conversions between data types */
|
|
1789
|
+
allowedConversionsBetweenDataTypes?: AllowedConversionsBetweenDataTypes<DataTypeUniqueId>;
|
|
1790
|
+
/** Whether to enable type inference */
|
|
1791
|
+
enableTypeInference?: boolean;
|
|
1792
|
+
/** Whether to enable complex type checking */
|
|
1793
|
+
enableComplexTypeChecking?: boolean;
|
|
1229
1794
|
};
|
|
1230
1795
|
|
|
1231
1796
|
/**
|
|
1232
1797
|
* Union type of all supported underlying data types
|
|
1233
1798
|
*/
|
|
1234
|
-
declare type SupportedUnderlyingTypes = (typeof supportedUnderlyingTypes)[number];
|
|
1799
|
+
export declare type SupportedUnderlyingTypes = (typeof supportedUnderlyingTypes)[number];
|
|
1235
1800
|
|
|
1236
1801
|
/**
|
|
1237
1802
|
* Array of supported underlying data types
|
|
1238
1803
|
*/
|
|
1239
1804
|
declare const supportedUnderlyingTypes: readonly ["string", "number", "complex", "noEquivalent", "inferFromConnection"];
|
|
1240
1805
|
|
|
1806
|
+
/**
|
|
1807
|
+
* Map of supported underlying types for type checking
|
|
1808
|
+
*/
|
|
1809
|
+
export declare const supportedUnderlyingTypesMap: {
|
|
1810
|
+
readonly string: "string";
|
|
1811
|
+
readonly number: "number";
|
|
1812
|
+
readonly complex: "complex";
|
|
1813
|
+
readonly noEquivalent: "noEquivalent";
|
|
1814
|
+
readonly inferFromConnection: "inferFromConnection";
|
|
1815
|
+
};
|
|
1816
|
+
|
|
1241
1817
|
/**
|
|
1242
1818
|
* Definition of an input type in a node
|
|
1243
1819
|
*
|
|
1244
1820
|
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
1245
1821
|
*/
|
|
1246
|
-
declare type TypeOfInput<DataTypeUniqueId extends string = string> = {
|
|
1822
|
+
export declare type TypeOfInput<DataTypeUniqueId extends string = string> = {
|
|
1247
1823
|
/** Display name of the input */
|
|
1248
1824
|
name: string;
|
|
1249
1825
|
/** The data type identifier this input uses */
|
|
@@ -1257,7 +1833,7 @@ declare type TypeOfInput<DataTypeUniqueId extends string = string> = {
|
|
|
1257
1833
|
*
|
|
1258
1834
|
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
1259
1835
|
*/
|
|
1260
|
-
declare type TypeOfInputPanel<DataTypeUniqueId extends string = string> = {
|
|
1836
|
+
export declare type TypeOfInputPanel<DataTypeUniqueId extends string = string> = {
|
|
1261
1837
|
/** Display name of the input panel */
|
|
1262
1838
|
name: string;
|
|
1263
1839
|
/** Array of inputs within this panel */
|
|
@@ -1269,7 +1845,7 @@ declare type TypeOfInputPanel<DataTypeUniqueId extends string = string> = {
|
|
|
1269
1845
|
*
|
|
1270
1846
|
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
1271
1847
|
*/
|
|
1272
|
-
declare type TypeOfNode<DataTypeUniqueId extends string = string> = {
|
|
1848
|
+
export declare type TypeOfNode<DataTypeUniqueId extends string = string> = {
|
|
1273
1849
|
/** Display name of the node type */
|
|
1274
1850
|
name: string;
|
|
1275
1851
|
/** Color used for the node header */
|