@theclearsky/react-blender-nodes 0.0.4 → 0.0.5

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 CHANGED
@@ -21,7 +21,10 @@ a flexible and customizable node-based graph editor for web applications.
21
21
  React Blender Nodes recreates the iconic Blender node editor experience on the
22
22
  web. Built with modern React patterns and TypeScript, it offers a complete
23
23
  solution for creating interactive node-based interfaces with support for custom
24
- nodes, connections, and real-time manipulation.
24
+ nodes, connections, and real-time manipulation. Features an intelligent type
25
+ system with automatic inference, complex data validation, and comprehensive
26
+ connection validation to ensure your node graphs are always type-safe and
27
+ error-free.
25
28
 
26
29
  ## Quick Start
27
30
 
@@ -164,19 +167,92 @@ const dataTypes = {
164
167
  - Context menu for adding new nodes
165
168
  - Real-time node manipulation
166
169
 
167
- ### 🎯 Advanced Features
168
-
169
- ![Advanced Features](./docs/screenshots/advanced-features.png)
170
-
171
- - **Handle Shapes**: 13+ custom handle shapes including geometric and artistic
172
- designs
173
- - **Input Components**: Built-in text and number inputs with validation
174
- - **Panel System**: Collapsible panels for organizing complex node inputs
170
+ ### 🧠 Smart Type System & Validation + Advanced Features
171
+
172
+ ![Smart Type System And Advanced Features](./docs/screenshots/smart-type-system-and-advanced-features.mp4)
173
+
174
+ - **Intelligent Type Inference**: Automatically infer node types from
175
+ connections
176
+ - Dynamic type resolution as you build your graph
177
+ - Real-time type updates when connections change
178
+ - Support for `inferFromConnection` data types
179
+ - **Advanced Type Validation**: Comprehensive type checking system
180
+ - **Complex Type Checking**: Zod schema validation for complex data structures
181
+ - **Type Conversion Control**: Fine-grained control over allowed type
182
+ conversions
183
+ - **Cycle Detection**: Prevent infinite loops in your node graphs
184
+ - **Multiple Data Types**: Support for diverse data structures
185
+ - Basic types: `string`, `number`
186
+ - Complex types: Custom objects with Zod schemas
187
+ - Special types: `inferFromConnection`, `noEquivalent`
188
+ - **Runtime Safety**: Catch type errors before they break your application
189
+ - Connection validation with detailed error messages
190
+ - Automatic type propagation across connected nodes
191
+ - Schema compatibility checking for complex types
175
192
  - **State Management**: Integrated reducer for managing graph state
176
193
  - **TypeScript Support**: Full type safety with comprehensive definitions
177
194
 
178
195
  ## Usage Examples
179
196
 
197
+ ### Smart Type System with Validation
198
+
199
+ ```tsx
200
+ import { z } from 'zod';
201
+
202
+ // Define complex data types with Zod schemas
203
+ const userSchema = z.object({
204
+ id: z.string(),
205
+ name: z.string(),
206
+ email: z.string().email(),
207
+ });
208
+
209
+ const dataTypes = {
210
+ stringType: makeDataTypeWithAutoInfer({
211
+ name: 'String',
212
+ underlyingType: 'string',
213
+ color: '#4A90E2',
214
+ }),
215
+ userType: makeDataTypeWithAutoInfer({
216
+ name: 'User',
217
+ underlyingType: 'complex',
218
+ complexSchema: userSchema,
219
+ color: '#7ED321',
220
+ }),
221
+ inferredType: makeDataTypeWithAutoInfer({
222
+ name: 'Inferred',
223
+ underlyingType: 'inferFromConnection',
224
+ color: '#FF6B6B',
225
+ }),
226
+ };
227
+
228
+ // Enable advanced validation features
229
+ const initialState = makeStateWithAutoInfer({
230
+ dataTypes,
231
+ typeOfNodes: {
232
+ userInput: makeTypeOfNodeWithAutoInfer({
233
+ name: 'User Input',
234
+ inputs: [{ name: 'User Data', dataType: 'userType' }],
235
+ outputs: [{ name: 'Output', dataType: 'inferredType' }],
236
+ }),
237
+ stringProcessor: makeTypeOfNodeWithAutoInfer({
238
+ name: 'String Processor',
239
+ inputs: [{ name: 'Input', dataType: 'inferredType' }],
240
+ outputs: [{ name: 'Result', dataType: 'stringType' }],
241
+ }),
242
+ },
243
+ nodeIdToNodeType: makeNodeIdToNodeTypeWithAutoInfer({}),
244
+ nodes: [],
245
+ edges: [],
246
+ // Enable smart validation features
247
+ enableTypeInference: true,
248
+ enableComplexTypeChecking: true,
249
+ enableCycleChecking: true,
250
+ allowedConversionsBetweenDataTypes: {
251
+ userType: { stringType: true }, // Allow user to string conversion
252
+ },
253
+ });
254
+ ```
255
+
180
256
  ### Custom Node with Panels
181
257
 
182
258
  ```tsx
package/dist/index.d.ts CHANGED
@@ -1146,6 +1146,11 @@ export declare type FullGraphProps<DataTypeUniqueId extends string = string, Nod
1146
1146
  ]>;
1147
1147
  };
1148
1148
 
1149
+ export declare function getResultantDataTypeOfHandleConsideringInferredType<DataTypeUniqueId extends string = string, UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never>(handle: ConfigurableNodeInput<UnderlyingType, ComplexSchemaType, DataTypeUniqueId> | ConfigurableNodeOutput<UnderlyingType, ComplexSchemaType, DataTypeUniqueId> | undefined): {
1150
+ dataTypeObject: DataType<UnderlyingType, ComplexSchemaType>;
1151
+ dataTypeUniqueId: DataTypeUniqueId;
1152
+ } | undefined;
1153
+
1149
1154
  declare type HandleIndices = {
1150
1155
  type: 'input';
1151
1156
  index1: number;
@@ -1785,12 +1790,54 @@ export declare type State<DataTypeUniqueId extends string = string, NodeTypeUniq
1785
1790
  nodeIdToNodeType: NodeIdToNodeType<NodeTypeUniqueId>;
1786
1791
  /** Array of edges in the graph */
1787
1792
  edges: Edges;
1788
- /** Optional mapping of allowed conversions between data types */
1793
+ /**
1794
+ * Optional mapping of allowed conversions between data types
1795
+ * - When not provided, all conversions are allowed
1796
+ * - If provided, only the conversions that are explicitly allowed will be allowed (happens even with empty object)
1797
+ * - By default, it will not allow conversion between complex types unless explicitly allowed here (even if complex type checking is enabled)
1798
+ * - If you want to allow conversion between complex types unless disallowed by complex type checking, you can set `allowConversionBetweenComplexTypesUnlessDisallowedByComplexTypeChecking` to true
1799
+ *
1800
+ * @default undefined
1801
+ */
1789
1802
  allowedConversionsBetweenDataTypes?: AllowedConversionsBetweenDataTypes<DataTypeUniqueId>;
1790
- /** Whether to enable type inference */
1803
+ /**
1804
+ * Whether to allow conversion between complex types unless disallowed by complex type checking
1805
+ * - If not provided, is considered disabled
1806
+ * - Only takes effect if complex type checking is enabled (`allowedConversionsBetweenDataTypes` is provided)
1807
+ * - If enabled, it will allow conversion between complex types unless disallowed by complex type checking
1808
+ * - If disabled, it will not allow conversion between complex types unless explicitly allowed by `allowedConversionsBetweenDataTypes`, even if complex type checking is enabled
1809
+ *
1810
+ * @default undefined
1811
+ */
1812
+ allowConversionBetweenComplexTypesUnlessDisallowedByComplexTypeChecking?: boolean;
1813
+ /**
1814
+ * Whether to enable type inference
1815
+ * - If not provided, is considered disabled
1816
+ * - When disabled, the types of the nodes are not inferred from the connections
1817
+ * - When enabled, the types of the nodes are inferred from the connections and reset when edges are removed
1818
+ *
1819
+ * @default undefined
1820
+ */
1791
1821
  enableTypeInference?: boolean;
1792
- /** Whether to enable complex type checking */
1822
+ /**
1823
+ * Whether to enable complex type checking
1824
+ * - If not provided, is considered disabled
1825
+ * - When disabled, the complex types are not checked for compatibility, all connections are allowed
1826
+ * - When enabled, the complex types are checked for compatibility, and connections are not allowed if the complex types are not compatible
1827
+ * - Complex types are compatible if they are the same type or if they have exactly the same schema
1828
+ *
1829
+ * @default undefined
1830
+ */
1793
1831
  enableComplexTypeChecking?: boolean;
1832
+ /**
1833
+ * Whether to enable cycle checking
1834
+ * - If not provided, is considered disabled
1835
+ * - When disabled, the cycles are not checked, all connections are allowed
1836
+ * - When enabled, the cycles are checked, and connections are not allowed if they create a cycle
1837
+ *
1838
+ * @default undefined
1839
+ */
1840
+ enableCycleChecking?: boolean;
1794
1841
  };
1795
1842
 
1796
1843
  /**
@@ -2034,4 +2081,17 @@ export declare function useFullGraph<DataTypeUniqueId extends string = string, N
2034
2081
  dispatch: ActionDispatch<[action: Action<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>]>;
2035
2082
  };
2036
2083
 
2084
+ /**
2085
+ * Checks if adding an edge will create a cycle in the graph
2086
+ *
2087
+ * @template DataTypeUniqueId - Unique identifier type for data types
2088
+ * @template NodeTypeUniqueId - Unique identifier type for node types
2089
+ * @template UnderlyingType - Supported underlying data types
2090
+ * @template ComplexSchemaType - Zod schema type for complex data types
2091
+ * @param state - The current graph state
2092
+ * @param newEdge - The edge to check
2093
+ * @returns Whether the edge will create a cycle
2094
+ */
2095
+ export declare function willAddingEdgeCreateCycle<DataTypeUniqueId extends string = string, NodeTypeUniqueId extends string = string, UnderlyingType extends SupportedUnderlyingTypes = SupportedUnderlyingTypes, ComplexSchemaType extends UnderlyingType extends 'complex' ? z.ZodType : never = never>(state: State<DataTypeUniqueId, NodeTypeUniqueId, UnderlyingType, ComplexSchemaType>, sourceNodeId: string, targetNodeId: string): boolean;
2096
+
2037
2097
  export { }