@theclearsky/react-blender-nodes 0.0.2 → 0.0.3
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/dist/index.d.ts +404 -10
- package/dist/react-blender-nodes.es.js +2532 -2492
- 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: {
|
|
@@ -79,7 +79,7 @@ declare type Action<DataTypeUniqueId extends string = string, NodeTypeUniqueId e
|
|
|
79
79
|
};
|
|
80
80
|
|
|
81
81
|
/** Map of action types for type-safe action dispatching */
|
|
82
|
-
declare const actionTypesMap: {
|
|
82
|
+
export declare const actionTypesMap: {
|
|
83
83
|
readonly ADD_NODE: "ADD_NODE";
|
|
84
84
|
readonly UPDATE_NODE_BY_REACT_FLOW: "UPDATE_NODE_BY_REACT_FLOW";
|
|
85
85
|
readonly UPDATE_EDGES_BY_REACT_FLOW: "UPDATE_EDGES_BY_REACT_FLOW";
|
|
@@ -227,7 +227,7 @@ export declare function cn(...inputs: ClassValue[]): string;
|
|
|
227
227
|
* />
|
|
228
228
|
* ```
|
|
229
229
|
*/
|
|
230
|
-
export declare const ConfigurableEdge: ForwardRefExoticComponent<Pick<ConfigurableEdgeState, "data" | "source" | "style" | "id" | "
|
|
230
|
+
export declare const ConfigurableEdge: ForwardRefExoticComponent<Pick<ConfigurableEdgeState, "data" | "source" | "style" | "id" | "selectable" | "deletable" | "selected" | "target" | "animated"> & EdgePosition & EdgeLabelOptions & {
|
|
231
231
|
sourceHandleId?: string | null;
|
|
232
232
|
targetHandleId?: string | null;
|
|
233
233
|
markerStart?: string;
|
|
@@ -476,6 +476,157 @@ export declare type ConfigurableNodeReactFlowWrapperProps = NodeProps<Configurab
|
|
|
476
476
|
/** State type for configurable nodes in ReactFlow */
|
|
477
477
|
export declare type ConfigurableNodeState = Node_2<Omit<ConfigurableNodeProps, 'isCurrentlyInsideReactFlow'>, 'configurableNode'>;
|
|
478
478
|
|
|
479
|
+
/**
|
|
480
|
+
* Constructs a ConfigurableNodeInput or ConfigurableNodeOutput from a type definition
|
|
481
|
+
*
|
|
482
|
+
* This function creates the appropriate input or output instance based on the data type's
|
|
483
|
+
* underlying type (string or number). It generates a unique ID and applies the correct
|
|
484
|
+
* configuration including handle color and input allowance.
|
|
485
|
+
*
|
|
486
|
+
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
487
|
+
* @template NodeTypeUniqueId - Unique identifier type for node types
|
|
488
|
+
* @template UnderlyingType - Supported underlying data types ('string' | 'number' | 'complex')
|
|
489
|
+
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
490
|
+
* @param typeOfDataType - The type definition for the input or output
|
|
491
|
+
* @param dataTypes - Map of data type definitions
|
|
492
|
+
* @returns Constructed input or output instance
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* ```tsx
|
|
496
|
+
* import {
|
|
497
|
+
* constructInputOrOutputOfType,
|
|
498
|
+
* makeDataTypeWithAutoInfer
|
|
499
|
+
* } from 'react-blender-nodes';
|
|
500
|
+
*
|
|
501
|
+
* // Define data types with auto-infer for type safety
|
|
502
|
+
* const dataTypes = {
|
|
503
|
+
* stringType: makeDataTypeWithAutoInfer({
|
|
504
|
+
* name: 'String',
|
|
505
|
+
* underlyingType: 'string',
|
|
506
|
+
* color: '#4A90E2',
|
|
507
|
+
* }),
|
|
508
|
+
* };
|
|
509
|
+
*
|
|
510
|
+
* // Construct input with type safety
|
|
511
|
+
* const input = constructInputOrOutputOfType(
|
|
512
|
+
* { name: 'Value', dataType: 'stringType', allowInput: true },
|
|
513
|
+
* dataTypes
|
|
514
|
+
* );
|
|
515
|
+
* ```
|
|
516
|
+
*/
|
|
517
|
+
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>(typeOfDataType: TypeOfInput<DataTypeUniqueId> | TypeOfNode<DataTypeUniqueId>['outputs'][number], dataTypes: State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>['dataTypes']): ConfigurableNodeInput | ConfigurableNodeOutput;
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Constructs a ConfigurableNodeInputPanel from a type definition
|
|
521
|
+
*
|
|
522
|
+
* This function creates an input panel with multiple inputs based on the panel type
|
|
523
|
+
* definition. It generates a unique panel ID and constructs all the inputs within
|
|
524
|
+
* the panel using the constructInputOrOutputOfType function.
|
|
525
|
+
*
|
|
526
|
+
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
527
|
+
* @template NodeTypeUniqueId - Unique identifier type for node types
|
|
528
|
+
* @template UnderlyingType - Supported underlying data types ('string' | 'number' | 'complex')
|
|
529
|
+
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
530
|
+
* @param typeOfPanel - The type definition for the input panel
|
|
531
|
+
* @param dataTypes - Map of data type definitions
|
|
532
|
+
* @returns Constructed input panel instance
|
|
533
|
+
*
|
|
534
|
+
* @example
|
|
535
|
+
* ```tsx
|
|
536
|
+
* import {
|
|
537
|
+
* constructInputPanelOfType,
|
|
538
|
+
* makeDataTypeWithAutoInfer
|
|
539
|
+
* } from 'react-blender-nodes';
|
|
540
|
+
*
|
|
541
|
+
* // Define data types with auto-infer for type safety
|
|
542
|
+
* const dataTypes = {
|
|
543
|
+
* numberType: makeDataTypeWithAutoInfer({
|
|
544
|
+
* name: 'Number',
|
|
545
|
+
* underlyingType: 'number',
|
|
546
|
+
* color: '#E74C3C',
|
|
547
|
+
* }),
|
|
548
|
+
* };
|
|
549
|
+
*
|
|
550
|
+
* // Construct panel with type safety
|
|
551
|
+
* const panel = constructInputPanelOfType(
|
|
552
|
+
* {
|
|
553
|
+
* name: 'Settings',
|
|
554
|
+
* inputs: [
|
|
555
|
+
* { name: 'Width', dataType: 'numberType' },
|
|
556
|
+
* { name: 'Height', dataType: 'numberType' }
|
|
557
|
+
* ]
|
|
558
|
+
* },
|
|
559
|
+
* dataTypes
|
|
560
|
+
* );
|
|
561
|
+
* ```
|
|
562
|
+
*/
|
|
563
|
+
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>(typeOfPanel: {
|
|
564
|
+
name: string;
|
|
565
|
+
inputs: {
|
|
566
|
+
name: string;
|
|
567
|
+
dataType: DataTypeUniqueId;
|
|
568
|
+
}[];
|
|
569
|
+
}, dataTypes: State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>['dataTypes']): ConfigurableNodeInputPanel;
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Constructs a complete node from a node type definition
|
|
573
|
+
*
|
|
574
|
+
* This function creates a fully configured ReactFlow node based on the node type
|
|
575
|
+
* definition. It processes all inputs (including panels) and outputs, generates
|
|
576
|
+
* unique IDs, and sets up the node with the correct position and configuration.
|
|
577
|
+
*
|
|
578
|
+
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
579
|
+
* @template NodeTypeUniqueId - Unique identifier type for node types
|
|
580
|
+
* @template UnderlyingType - Supported underlying data types ('string' | 'number' | 'complex')
|
|
581
|
+
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
582
|
+
* @param dataTypes - Map of data type definitions
|
|
583
|
+
* @param nodeType - The unique identifier of the node type
|
|
584
|
+
* @param typeOfNodes - Map of node type definitions
|
|
585
|
+
* @param nodeId - Unique identifier for the new node instance
|
|
586
|
+
* @param position - Position where the node should be placed
|
|
587
|
+
* @returns Complete ReactFlow node instance
|
|
588
|
+
*
|
|
589
|
+
* @example
|
|
590
|
+
* ```tsx
|
|
591
|
+
* import {
|
|
592
|
+
* constructNodeOfType,
|
|
593
|
+
* makeStateWithAutoInfer,
|
|
594
|
+
* makeNodeIdToNodeTypeWithAutoInfer,
|
|
595
|
+
* makeTypeOfNodeWithAutoInfer,
|
|
596
|
+
* makeDataTypeWithAutoInfer
|
|
597
|
+
* } from 'react-blender-nodes';
|
|
598
|
+
*
|
|
599
|
+
* // Define data types with auto-infer for type safety
|
|
600
|
+
* const dataTypes = {
|
|
601
|
+
* stringType: makeDataTypeWithAutoInfer({
|
|
602
|
+
* name: 'String',
|
|
603
|
+
* underlyingType: 'string',
|
|
604
|
+
* color: '#4A90E2',
|
|
605
|
+
* }),
|
|
606
|
+
* };
|
|
607
|
+
*
|
|
608
|
+
* // Define node types with auto-infer for type safety
|
|
609
|
+
* const typeOfNodes = {
|
|
610
|
+
* inputNode: makeTypeOfNodeWithAutoInfer({
|
|
611
|
+
* name: 'Input Node',
|
|
612
|
+
* headerColor: '#C44536',
|
|
613
|
+
* inputs: [{ name: 'Input', dataType: 'stringType', allowInput: true }],
|
|
614
|
+
* outputs: [{ name: 'Output', dataType: 'stringType' }]
|
|
615
|
+
* }),
|
|
616
|
+
* };
|
|
617
|
+
*
|
|
618
|
+
* // Construct node with type safety
|
|
619
|
+
* const node = constructNodeOfType(
|
|
620
|
+
* dataTypes,
|
|
621
|
+
* 'inputNode',
|
|
622
|
+
* typeOfNodes,
|
|
623
|
+
* 'node-123',
|
|
624
|
+
* { x: 100, y: 100 }
|
|
625
|
+
* );
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
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>(dataTypes: 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];
|
|
629
|
+
|
|
479
630
|
/**
|
|
480
631
|
* A context-aware handle component for node inputs and outputs
|
|
481
632
|
*
|
|
@@ -759,7 +910,7 @@ export declare type CreateNodeContextMenuProps<DataTypeUniqueId extends string =
|
|
|
759
910
|
* @template UnderlyingType - The underlying type of the data
|
|
760
911
|
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
761
912
|
*/
|
|
762
|
-
declare type DataType<UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never> = UnderlyingType extends 'complex' ? {
|
|
913
|
+
export declare type DataType<UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never> = UnderlyingType extends 'complex' ? {
|
|
763
914
|
/** Display name of the data type */
|
|
764
915
|
name: string;
|
|
765
916
|
/** The underlying type of the data */
|
|
@@ -1026,6 +1177,238 @@ export declare function isCoordinateInBox(coordinate: Coordinate, box: Box, xAxi
|
|
|
1026
1177
|
*/
|
|
1027
1178
|
export declare function isNumberInRange(number: number, min: number, max: number, minInclusive?: boolean, maxInclusive?: boolean): boolean;
|
|
1028
1179
|
|
|
1180
|
+
/**
|
|
1181
|
+
* Type guard to check if a string is a supported underlying type
|
|
1182
|
+
*
|
|
1183
|
+
* @param type - The string to check
|
|
1184
|
+
* @returns True if the string is a supported underlying type
|
|
1185
|
+
*
|
|
1186
|
+
* @example
|
|
1187
|
+
* ```tsx
|
|
1188
|
+
* if (isSupportedUnderlyingType('string')) {
|
|
1189
|
+
* // type is now 'string'
|
|
1190
|
+
* }
|
|
1191
|
+
* ```
|
|
1192
|
+
*/
|
|
1193
|
+
export declare function isSupportedUnderlyingType(type: string): type is SupportedUnderlyingTypes;
|
|
1194
|
+
|
|
1195
|
+
/**
|
|
1196
|
+
* Main reducer function for managing graph state
|
|
1197
|
+
*
|
|
1198
|
+
* This reducer handles all state updates for the graph including nodes, edges,
|
|
1199
|
+
* and input values. It uses Immer for immutable state updates and integrates
|
|
1200
|
+
* with ReactFlow for node and edge management.
|
|
1201
|
+
*
|
|
1202
|
+
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
1203
|
+
* @template NodeTypeUniqueId - Unique identifier type for node types
|
|
1204
|
+
* @template UnderlyingType - Supported underlying data types ('string' | 'number' | 'complex')
|
|
1205
|
+
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
1206
|
+
* @param oldState - The current state of the graph
|
|
1207
|
+
* @param action - The action to apply to the state
|
|
1208
|
+
* @returns New state after applying the action
|
|
1209
|
+
*
|
|
1210
|
+
* @example
|
|
1211
|
+
* ```tsx
|
|
1212
|
+
* import {
|
|
1213
|
+
* mainReducer,
|
|
1214
|
+
* makeStateWithAutoInfer,
|
|
1215
|
+
* makeNodeIdToNodeTypeWithAutoInfer,
|
|
1216
|
+
* makeTypeOfNodeWithAutoInfer,
|
|
1217
|
+
* makeDataTypeWithAutoInfer
|
|
1218
|
+
* } from 'react-blender-nodes';
|
|
1219
|
+
*
|
|
1220
|
+
* // Create type-safe state with auto-infer helpers
|
|
1221
|
+
* const dataTypes = {
|
|
1222
|
+
* stringType: makeDataTypeWithAutoInfer({
|
|
1223
|
+
* name: 'String',
|
|
1224
|
+
* underlyingType: 'string',
|
|
1225
|
+
* color: '#4A90E2',
|
|
1226
|
+
* }),
|
|
1227
|
+
* };
|
|
1228
|
+
*
|
|
1229
|
+
* const typeOfNodes = {
|
|
1230
|
+
* inputNode: makeTypeOfNodeWithAutoInfer({
|
|
1231
|
+
* name: 'Input Node',
|
|
1232
|
+
* headerColor: '#C44536',
|
|
1233
|
+
* inputs: [{ name: 'Input', dataType: 'stringType', allowInput: true }],
|
|
1234
|
+
* outputs: [{ name: 'Output', dataType: 'stringType' }],
|
|
1235
|
+
* }),
|
|
1236
|
+
* };
|
|
1237
|
+
*
|
|
1238
|
+
* const nodeIdToNodeType = makeNodeIdToNodeTypeWithAutoInfer({
|
|
1239
|
+
* 'node-1': 'inputNode',
|
|
1240
|
+
* });
|
|
1241
|
+
*
|
|
1242
|
+
* const state = makeStateWithAutoInfer({
|
|
1243
|
+
* dataTypes,
|
|
1244
|
+
* typeOfNodes,
|
|
1245
|
+
* nodeIdToNodeType,
|
|
1246
|
+
* nodes: [],
|
|
1247
|
+
* edges: [],
|
|
1248
|
+
* });
|
|
1249
|
+
*
|
|
1250
|
+
* // Add a new node (type-safe!)
|
|
1251
|
+
* const newState = mainReducer(state, {
|
|
1252
|
+
* type: 'ADD_NODE',
|
|
1253
|
+
* payload: {
|
|
1254
|
+
* type: 'inputNode',
|
|
1255
|
+
* position: { x: 100, y: 100 },
|
|
1256
|
+
* },
|
|
1257
|
+
* });
|
|
1258
|
+
*
|
|
1259
|
+
* // Update input value (type-safe!)
|
|
1260
|
+
* const updatedState = mainReducer(newState, {
|
|
1261
|
+
* type: 'UPDATE_INPUT_VALUE',
|
|
1262
|
+
* payload: {
|
|
1263
|
+
* nodeId: 'node1',
|
|
1264
|
+
* inputId: 'input1',
|
|
1265
|
+
* value: 'new value',
|
|
1266
|
+
* },
|
|
1267
|
+
* });
|
|
1268
|
+
* ```
|
|
1269
|
+
*/
|
|
1270
|
+
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>;
|
|
1271
|
+
|
|
1272
|
+
/**
|
|
1273
|
+
* Helper function to create a data type with automatic type inference
|
|
1274
|
+
*
|
|
1275
|
+
* This function is essential for type safety when defining data types. It ensures
|
|
1276
|
+
* that TypeScript can properly infer and validate the types throughout your graph
|
|
1277
|
+
* system, preventing runtime errors and providing better IDE support.
|
|
1278
|
+
*
|
|
1279
|
+
* @template UnderlyingType - The underlying type of the data
|
|
1280
|
+
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
1281
|
+
* @param input - The data type definition
|
|
1282
|
+
* @returns The data type definition with proper typing
|
|
1283
|
+
*
|
|
1284
|
+
* @example
|
|
1285
|
+
* ```tsx
|
|
1286
|
+
* // ✅ Type-safe - TypeScript will validate dataType references
|
|
1287
|
+
* const stringType = makeDataTypeWithAutoInfer({
|
|
1288
|
+
* name: 'String',
|
|
1289
|
+
* underlyingType: 'string',
|
|
1290
|
+
* color: '#4A90E2',
|
|
1291
|
+
* });
|
|
1292
|
+
*
|
|
1293
|
+
* // ❌ Without auto-infer - TypeScript can't validate references
|
|
1294
|
+
* const stringType = {
|
|
1295
|
+
* name: 'String',
|
|
1296
|
+
* underlyingType: 'string',
|
|
1297
|
+
* color: '#4A90E2',
|
|
1298
|
+
* };
|
|
1299
|
+
* ```
|
|
1300
|
+
*/
|
|
1301
|
+
export declare function makeDataTypeWithAutoInfer<UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never>(input: DataType<UnderlyingType, ComplexSchemaType>): DataType<UnderlyingType, ComplexSchemaType>;
|
|
1302
|
+
|
|
1303
|
+
/**
|
|
1304
|
+
* Helper function to create a node ID to node type mapping with automatic type inference
|
|
1305
|
+
*
|
|
1306
|
+
* This function is essential for type safety when mapping node IDs to their types.
|
|
1307
|
+
* It ensures that TypeScript can validate that all node type references are valid,
|
|
1308
|
+
* preventing runtime errors when dispatching actions and providing better IDE support.
|
|
1309
|
+
*
|
|
1310
|
+
* @template NodeTypeUniqueId - Unique identifier type for node types
|
|
1311
|
+
* @param input - The node ID to node type mapping
|
|
1312
|
+
* @returns The mapping with proper typing
|
|
1313
|
+
*
|
|
1314
|
+
* @example
|
|
1315
|
+
* ```tsx
|
|
1316
|
+
* // ✅ Type-safe - TypeScript will validate node type references
|
|
1317
|
+
* const nodeIdToNodeType = makeNodeIdToNodeTypeWithAutoInfer({
|
|
1318
|
+
* 'node-1': 'inputNode',
|
|
1319
|
+
* 'node-2': 'outputNode',
|
|
1320
|
+
* });
|
|
1321
|
+
*
|
|
1322
|
+
* // ❌ Without auto-infer - TypeScript can't validate node type references
|
|
1323
|
+
* const nodeIdToNodeType = {
|
|
1324
|
+
* 'node-1': 'inputNode',
|
|
1325
|
+
* 'node-2': 'outputNode',
|
|
1326
|
+
* };
|
|
1327
|
+
* ```
|
|
1328
|
+
*/
|
|
1329
|
+
export declare function makeNodeIdToNodeTypeWithAutoInfer<NodeTypeUniqueId extends string = string>(input: NodeIdToNodeType<NodeTypeUniqueId>): NodeIdToNodeType<NodeTypeUniqueId>;
|
|
1330
|
+
|
|
1331
|
+
/**
|
|
1332
|
+
* Helper function to create a state with automatic type inference
|
|
1333
|
+
*
|
|
1334
|
+
* This function is essential for complete type safety when creating the graph state.
|
|
1335
|
+
* It ensures that TypeScript can properly infer and validate all type relationships
|
|
1336
|
+
* throughout your graph system, providing compile-time type checking and better IDE support.
|
|
1337
|
+
*
|
|
1338
|
+
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
1339
|
+
* @template NodeTypeUniqueId - Unique identifier type for node types
|
|
1340
|
+
* @template UnderlyingType - Supported underlying data types ('string' | 'number' | 'complex')
|
|
1341
|
+
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
1342
|
+
* @param input - The state definition
|
|
1343
|
+
* @returns The state with proper typing
|
|
1344
|
+
*
|
|
1345
|
+
* @example
|
|
1346
|
+
* ```tsx
|
|
1347
|
+
* // ✅ Type-safe - Complete type inference and validation
|
|
1348
|
+
* const state = makeStateWithAutoInfer({
|
|
1349
|
+
* dataTypes: {
|
|
1350
|
+
* stringType: makeDataTypeWithAutoInfer({
|
|
1351
|
+
* name: 'String',
|
|
1352
|
+
* underlyingType: 'string',
|
|
1353
|
+
* color: '#4A90E2'
|
|
1354
|
+
* })
|
|
1355
|
+
* },
|
|
1356
|
+
* typeOfNodes: {
|
|
1357
|
+
* inputNode: makeTypeOfNodeWithAutoInfer({
|
|
1358
|
+
* name: 'Input',
|
|
1359
|
+
* inputs: [],
|
|
1360
|
+
* outputs: []
|
|
1361
|
+
* })
|
|
1362
|
+
* },
|
|
1363
|
+
* nodeIdToNodeType: makeNodeIdToNodeTypeWithAutoInfer({}),
|
|
1364
|
+
* nodes: [],
|
|
1365
|
+
* edges: [],
|
|
1366
|
+
* });
|
|
1367
|
+
*
|
|
1368
|
+
* // ❌ Without auto-infer - No type validation
|
|
1369
|
+
* const state = {
|
|
1370
|
+
* dataTypes: { stringType: { name: 'String', underlyingType: 'string', color: '#4A90E2' } },
|
|
1371
|
+
* typeOfNodes: { inputNode: { name: 'Input', inputs: [], outputs: [] } },
|
|
1372
|
+
* nodes: [],
|
|
1373
|
+
* nodeIdToNodeType: {},
|
|
1374
|
+
* edges: [],
|
|
1375
|
+
* };
|
|
1376
|
+
* ```
|
|
1377
|
+
*/
|
|
1378
|
+
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>;
|
|
1379
|
+
|
|
1380
|
+
/**
|
|
1381
|
+
* Helper function to create a node type with automatic type inference
|
|
1382
|
+
*
|
|
1383
|
+
* This function is essential for type safety when defining node types. It ensures
|
|
1384
|
+
* that TypeScript can properly validate dataType references in inputs and outputs,
|
|
1385
|
+
* preventing runtime errors when creating nodes and providing better IDE support.
|
|
1386
|
+
*
|
|
1387
|
+
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
1388
|
+
* @param input - The node type definition
|
|
1389
|
+
* @returns The node type definition with proper typing
|
|
1390
|
+
*
|
|
1391
|
+
* @example
|
|
1392
|
+
* ```tsx
|
|
1393
|
+
* // ✅ Type-safe - TypeScript will validate dataType references
|
|
1394
|
+
* const inputNodeType = makeTypeOfNodeWithAutoInfer({
|
|
1395
|
+
* name: 'Input Node',
|
|
1396
|
+
* headerColor: '#C44536',
|
|
1397
|
+
* inputs: [{ name: 'Input', dataType: 'stringType', allowInput: true }],
|
|
1398
|
+
* outputs: [{ name: 'Output', dataType: 'stringType' }],
|
|
1399
|
+
* });
|
|
1400
|
+
*
|
|
1401
|
+
* // ❌ Without auto-infer - TypeScript can't validate dataType references
|
|
1402
|
+
* const inputNodeType = {
|
|
1403
|
+
* name: 'Input Node',
|
|
1404
|
+
* headerColor: '#C44536',
|
|
1405
|
+
* inputs: [{ name: 'Input', dataType: 'stringType', allowInput: true }],
|
|
1406
|
+
* outputs: [{ name: 'Output', dataType: 'stringType' }],
|
|
1407
|
+
* };
|
|
1408
|
+
* ```
|
|
1409
|
+
*/
|
|
1410
|
+
export declare function makeTypeOfNodeWithAutoInfer<DataTypeUniqueId extends string = string>(input: TypeOfNode<DataTypeUniqueId>): TypeOfNode<DataTypeUniqueId>;
|
|
1411
|
+
|
|
1029
1412
|
/**
|
|
1030
1413
|
* Array of node changes for ReactFlow
|
|
1031
1414
|
*/
|
|
@@ -1036,7 +1419,7 @@ export declare type NodeChanges = NodeChange<ConfigurableNodeState>[];
|
|
|
1036
1419
|
*
|
|
1037
1420
|
* @template NodeTypeUniqueId - Unique identifier type for node types
|
|
1038
1421
|
*/
|
|
1039
|
-
declare type NodeIdToNodeType<NodeTypeUniqueId extends string = string> = Record<string, NodeTypeUniqueId>;
|
|
1422
|
+
export declare type NodeIdToNodeType<NodeTypeUniqueId extends string = string> = Record<string, NodeTypeUniqueId>;
|
|
1040
1423
|
|
|
1041
1424
|
/**
|
|
1042
1425
|
* Enhanced node resizer component with customizable controls
|
|
@@ -1215,7 +1598,7 @@ export declare type SliderNumberInputProps = {
|
|
|
1215
1598
|
* @template UnderlyingType - Supported underlying data types ('string' | 'number' | 'complex')
|
|
1216
1599
|
* @template ComplexSchemaType - Zod schema type for complex data types
|
|
1217
1600
|
*/
|
|
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> = {
|
|
1601
|
+
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
1602
|
/** Map of data type definitions */
|
|
1220
1603
|
dataTypes: Record<DataTypeUniqueId, DataType<UnderlyingType, ComplexSchemaType>>;
|
|
1221
1604
|
/** Map of node type definitions */
|
|
@@ -1231,19 +1614,30 @@ declare type State<DataTypeUniqueId extends string = string, NodeTypeUniqueId ex
|
|
|
1231
1614
|
/**
|
|
1232
1615
|
* Union type of all supported underlying data types
|
|
1233
1616
|
*/
|
|
1234
|
-
declare type SupportedUnderlyingTypes = (typeof supportedUnderlyingTypes)[number];
|
|
1617
|
+
export declare type SupportedUnderlyingTypes = (typeof supportedUnderlyingTypes)[number];
|
|
1235
1618
|
|
|
1236
1619
|
/**
|
|
1237
1620
|
* Array of supported underlying data types
|
|
1238
1621
|
*/
|
|
1239
1622
|
declare const supportedUnderlyingTypes: readonly ["string", "number", "complex", "noEquivalent", "inferFromConnection"];
|
|
1240
1623
|
|
|
1624
|
+
/**
|
|
1625
|
+
* Map of supported underlying types for type checking
|
|
1626
|
+
*/
|
|
1627
|
+
export declare const supportedUnderlyingTypesMap: {
|
|
1628
|
+
readonly string: "string";
|
|
1629
|
+
readonly number: "number";
|
|
1630
|
+
readonly complex: "complex";
|
|
1631
|
+
readonly noEquivalent: "noEquivalent";
|
|
1632
|
+
readonly inferFromConnection: "inferFromConnection";
|
|
1633
|
+
};
|
|
1634
|
+
|
|
1241
1635
|
/**
|
|
1242
1636
|
* Definition of an input type in a node
|
|
1243
1637
|
*
|
|
1244
1638
|
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
1245
1639
|
*/
|
|
1246
|
-
declare type TypeOfInput<DataTypeUniqueId extends string = string> = {
|
|
1640
|
+
export declare type TypeOfInput<DataTypeUniqueId extends string = string> = {
|
|
1247
1641
|
/** Display name of the input */
|
|
1248
1642
|
name: string;
|
|
1249
1643
|
/** The data type identifier this input uses */
|
|
@@ -1257,7 +1651,7 @@ declare type TypeOfInput<DataTypeUniqueId extends string = string> = {
|
|
|
1257
1651
|
*
|
|
1258
1652
|
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
1259
1653
|
*/
|
|
1260
|
-
declare type TypeOfInputPanel<DataTypeUniqueId extends string = string> = {
|
|
1654
|
+
export declare type TypeOfInputPanel<DataTypeUniqueId extends string = string> = {
|
|
1261
1655
|
/** Display name of the input panel */
|
|
1262
1656
|
name: string;
|
|
1263
1657
|
/** Array of inputs within this panel */
|
|
@@ -1269,7 +1663,7 @@ declare type TypeOfInputPanel<DataTypeUniqueId extends string = string> = {
|
|
|
1269
1663
|
*
|
|
1270
1664
|
* @template DataTypeUniqueId - Unique identifier type for data types
|
|
1271
1665
|
*/
|
|
1272
|
-
declare type TypeOfNode<DataTypeUniqueId extends string = string> = {
|
|
1666
|
+
export declare type TypeOfNode<DataTypeUniqueId extends string = string> = {
|
|
1273
1667
|
/** Display name of the node type */
|
|
1274
1668
|
name: string;
|
|
1275
1669
|
/** Color used for the node header */
|