@theclearsky/react-blender-nodes 0.0.1 → 0.0.2

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
@@ -3,171 +3,334 @@
3
3
  A React component library inspired by Blender's node editor interface, providing
4
4
  a flexible and customizable node-based graph editor for web applications.
5
5
 
6
+ ![React Blender Nodes Banner](./docs/screenshots/banner.png)
7
+
6
8
  ## 🎯 Overview
7
9
 
8
- React Blender Nodes is a React library that recreates the iconic Blender node
9
- editor experience on the web. Built with modern React patterns and TypeScript,
10
- it offers a complete solution for creating interactive node-based interfaces
11
- with support for custom nodes, connections, and real-time manipulation.
10
+ React Blender Nodes recreates the iconic Blender node editor experience on the
11
+ web. Built with modern React patterns and TypeScript, it offers a complete
12
+ solution for creating interactive node-based interfaces with support for custom
13
+ nodes, connections, and real-time manipulation.
12
14
 
13
15
  ## ✨ Features
14
16
 
15
- - **Blender-inspired UI**: Authentic node editor experience with dark theme and
16
- familiar interactions
17
- - **Fully Customizable Nodes**: Create nodes with custom inputs, outputs, and
18
- styling
19
- - **Interactive Graph Editor**: Pan, zoom, select, and manipulate nodes with
20
- intuitive controls
21
- - **TypeScript Support**: Full type safety with comprehensive type definitions
22
- - **Storybook Integration**: Interactive component documentation and testing
23
- - **Modular Architecture**: Atomic design pattern with reusable components
24
- - **Modern React**: Built with React 19+ and modern hooks patterns
17
+ ### 🎨 Blender-Inspired Interface
18
+
19
+ ![Blender Interface](./docs/screenshots/blender-interface.png)
20
+
21
+ - Authentic dark theme matching Blender's node editor
22
+ - Familiar interactions and visual design
23
+ - Smooth animations and transitions
24
+
25
+ ### 🔧 Customizable Nodes
26
+
27
+ ![Customizable Nodes](./docs/screenshots/customizable-nodes.png)
28
+
29
+ - Dynamic inputs and outputs with custom shapes
30
+ - Collapsible input panels for complex configurations
31
+ - Interactive input components (text, number sliders)
32
+ - Custom handle shapes (circle, square, diamond, star, etc.)
33
+
34
+ ### 🎮 Interactive Graph Editor
35
+
36
+ ![Interactive Graph](./docs/screenshots/interactive-graph.png)
37
+
38
+ - Pan, zoom, and select nodes with intuitive controls
39
+ - Drag and drop node connections
40
+ - Context menu for adding new nodes
41
+ - Real-time node manipulation
42
+
43
+ ### 🎯 Advanced Features
44
+
45
+ ![Advanced Features](./docs/screenshots/advanced-features.png)
46
+
47
+ - **Handle Shapes**: 13+ custom handle shapes including geometric and artistic
48
+ designs
49
+ - **Input Components**: Built-in text and number inputs with validation
50
+ - **Panel System**: Collapsible panels for organizing complex node inputs
51
+ - **State Management**: Integrated reducer for managing graph state
52
+ - **TypeScript Support**: Full type safety with comprehensive definitions
25
53
 
26
54
  ## 🚀 Quick Start
27
55
 
56
+ ### Installation
57
+
28
58
  ```bash
29
- npm install react-blender-nodes
59
+ npm install @theclearsky/react-blender-nodes
30
60
  ```
31
61
 
62
+ ### Basic Usage
63
+
32
64
  ```tsx
33
- import { FullGraph } from 'react-blender-nodes';
65
+ import {
66
+ FullGraph,
67
+ useFullGraph,
68
+ makeStateWithAutoInfer,
69
+ makeNodeIdToNodeTypeWithAutoInfer,
70
+ makeTypeOfNodeWithAutoInfer,
71
+ makeDataTypeWithAutoInfer,
72
+ } from 'react-blender-nodes';
34
73
  import 'react-blender-nodes/style.css';
35
74
 
36
- function App() {
37
- const nodes = [
38
- {
39
- id: '1',
40
- type: 'configurableNode',
41
- position: { x: 100, y: 100 },
42
- data: {
43
- name: 'Input Node',
44
- outputs: [{ id: 'output-1', name: 'Value', type: 'number' }],
45
- },
46
- },
47
- ];
75
+ function MyNodeEditor() {
76
+ // Define data types with auto-infer for type safety
77
+ const dataTypes = {
78
+ stringType: makeDataTypeWithAutoInfer({
79
+ name: 'String',
80
+ underlyingType: 'string',
81
+ color: '#4A90E2',
82
+ }),
83
+ numberType: makeDataTypeWithAutoInfer({
84
+ name: 'Number',
85
+ underlyingType: 'number',
86
+ color: '#7ED321',
87
+ }),
88
+ };
89
+
90
+ // Define node types with auto-infer for type safety
91
+ const typeOfNodes = {
92
+ inputNode: makeTypeOfNodeWithAutoInfer({
93
+ name: 'Input Node',
94
+ headerColor: '#C44536',
95
+ inputs: [
96
+ { name: 'Text Input', dataType: 'stringType', allowInput: true },
97
+ { name: 'Number Input', dataType: 'numberType', allowInput: true },
98
+ ],
99
+ outputs: [{ name: 'Output', dataType: 'stringType' }],
100
+ }),
101
+ };
102
+
103
+ // Define node ID to type mapping with auto-infer
104
+ const nodeIdToNodeType = makeNodeIdToNodeTypeWithAutoInfer({});
105
+
106
+ // Create state with auto-infer for complete type safety
107
+ const initialState = makeStateWithAutoInfer({
108
+ dataTypes,
109
+ typeOfNodes,
110
+ nodeIdToNodeType,
111
+ nodes: [],
112
+ edges: [],
113
+ });
114
+
115
+ const { state, dispatch } = useFullGraph(initialState);
48
116
 
49
117
  return (
50
- <div style={{ height: '500px' }}>
51
- <FullGraph nodes={nodes} edges={[]} />
118
+ <div style={{ height: '600px', width: '100%' }}>
119
+ <FullGraph state={state} dispatch={dispatch} />
52
120
  </div>
53
121
  );
54
122
  }
55
123
  ```
56
124
 
57
- ## 📁 Project Structure
125
+ ### 🔒 Type Safety with Auto-Infer Helpers
58
126
 
59
- ```
60
- react-blender-nodes/
61
- ├── src/
62
- │ ├── components/ # Component library organized by atomic design
63
- │ │ ├── atoms/ # Basic building blocks (buttons, handles, etc.)
64
- │ │ │ ├── Button/ # Reusable button component
65
- │ │ │ ├── ConfigurableConnection/ # Node connection line component
66
- │ │ │ ├── ConfigurableEdge/ # Edge/connection rendering component
67
- │ │ │ └── NodeResizerWithMoreControls/ # Node resizing controls
68
- │ │ ├── molecules/ # Composed components (input groups, controls)
69
- │ │ │ └── SliderNumberInput/ # Combined slider and number input
70
- │ │ └── organisms/ # Complex components (full nodes, graph)
71
- │ │ ├── ConfigurableNode/ # Main node component with inputs/outputs
72
- │ │ └── FullGraph/ # Complete graph editor with ReactFlow
73
- │ ├── hooks/ # Custom React hooks
74
- │ │ ├── useClickedOutside.ts # Click outside detection hook
75
- │ │ └── index.ts # Hook exports
76
- │ ├── utils/ # Utility functions and helpers
77
- │ │ ├── nodeStateManagement/ # State management for node operations
78
- │ │ │ ├── mainReducer.ts # Main state reducer
79
- │ │ │ └── types.ts # State management types
80
- │ │ ├── cnHelper.ts # Class name utility (tailwind-merge)
81
- │ │ ├── geometry.ts # Geometric calculations
82
- │ │ └── index.ts # Utility exports
83
- │ ├── @types/ # TypeScript type definitions
84
- │ │ └── globals.d.ts # Global type declarations
85
- │ ├── index.ts # Main library entry point
86
- │ └── index.css # Global styles and CSS variables
87
- ├── dist/ # Built library files (generated)
88
- ├── storybook-static/ # Built Storybook documentation (generated)
89
- ├── .storybook/ # Storybook configuration
90
- ├── .github/ # GitHub workflows and templates
91
- ├── node_modules/ # Dependencies (generated)
92
- ├── package.json # Project configuration and dependencies
93
- ├── vite.config.ts # Vite bundler configuration
94
- ├── tsconfig.json # TypeScript configuration
95
- ├── components.json # Shadcn/ui component configuration
96
- ├── eslint.config.js # ESLint linting rules
97
- └── .prettierrc # Code formatting configuration
127
+ The auto-infer helper functions are **essential** for type safety in React
128
+ Blender Nodes. They ensure TypeScript can properly validate type references
129
+ throughout your graph system:
130
+
131
+ - **`makeDataTypeWithAutoInfer`**: Validates data type definitions
132
+ - **`makeTypeOfNodeWithAutoInfer`**: Validates node type definitions and
133
+ dataType references
134
+ - **`makeNodeIdToNodeTypeWithAutoInfer`**: Validates node ID to type mappings
135
+ - **`makeStateWithAutoInfer`**: Provides complete type inference for the entire
136
+ state
137
+
138
+ **Why use them?**
139
+
140
+ - **Compile-time validation**: Catch errors before runtime
141
+ - **IDE support**: Better autocomplete and IntelliSense
142
+ - **Refactoring safety**: TypeScript ensures consistency when renaming types
143
+ - **Runtime safety**: Prevents invalid type references
144
+
145
+ **Without auto-infer helpers:**
146
+
147
+ ```tsx
148
+ // No type validation - errors only caught at runtime
149
+ const dataTypes = {
150
+ stringType: { name: 'String', underlyingType: 'string', color: '#4A90E2' },
151
+ };
98
152
  ```
99
153
 
100
- ## 🧩 Component Architecture
154
+ **With auto-infer helpers:**
101
155
 
102
- ### Atomic Design Pattern
156
+ ```tsx
157
+ // ✅ Full type validation - errors caught at compile time
158
+ const dataTypes = {
159
+ stringType: makeDataTypeWithAutoInfer({
160
+ name: 'String',
161
+ underlyingType: 'string',
162
+ color: '#4A90E2',
163
+ }),
164
+ };
165
+ ```
103
166
 
104
- This library follows the atomic design methodology:
167
+ ## 📖 Usage Examples
105
168
 
106
- - **Atoms**: Basic UI elements that cannot be broken down further (Button,
107
- Handle, Edge)
108
- - **Molecules**: Simple groups of atoms functioning together (SliderNumberInput)
109
- - **Organisms**: Complex UI components composed of molecules and atoms
110
- (ConfigurableNode, FullGraph)
169
+ ### Custom Node with Panels
111
170
 
112
- ### Key Components
171
+ ```tsx
172
+ const customNode = {
173
+ id: 'advanced-node',
174
+ type: 'configurableNode',
175
+ position: { x: 100, y: 100 },
176
+ data: {
177
+ name: 'Advanced Processor',
178
+ headerColor: '#2D5A87',
179
+ inputs: [
180
+ {
181
+ id: 'direct-input',
182
+ name: 'Direct Input',
183
+ type: 'string',
184
+ handleColor: '#00BFFF',
185
+ allowInput: true,
186
+ },
187
+ {
188
+ id: 'settings-panel',
189
+ name: 'Settings Panel',
190
+ inputs: [
191
+ {
192
+ id: 'threshold',
193
+ name: 'Threshold',
194
+ type: 'number',
195
+ handleColor: '#96CEB4',
196
+ allowInput: true,
197
+ handleShape: 'diamond',
198
+ },
199
+ {
200
+ id: 'config',
201
+ name: 'Configuration',
202
+ type: 'string',
203
+ handleColor: '#00FFFF',
204
+ allowInput: true,
205
+ handleShape: 'star',
206
+ },
207
+ ],
208
+ },
209
+ ],
210
+ outputs: [
211
+ {
212
+ id: 'result',
213
+ name: 'Result',
214
+ type: 'string',
215
+ handleColor: '#FECA57',
216
+ handleShape: 'hexagon',
217
+ },
218
+ ],
219
+ },
220
+ };
221
+ ```
113
222
 
114
- - **FullGraph**: The main graph editor component with pan, zoom, and node
115
- management
116
- - **ConfigurableNode**: Customizable node component with dynamic inputs and
117
- outputs
118
- - **SliderNumberInput**: Combined slider and number input for precise value
119
- control
120
- - **NodeResizerWithMoreControls**: Enhanced node resizing with additional
121
- controls
223
+ ### Handle Shapes Showcase
122
224
 
123
- ## 🛠️ Development
225
+ ```tsx
226
+ // Available handle shapes
227
+ const handleShapes = [
228
+ 'circle', // Default circular handle
229
+ 'square', // Square handle
230
+ 'rectangle', // Tall rectangle
231
+ 'diamond', // 45° rotated square
232
+ 'hexagon', // Regular hexagon
233
+ 'star', // 5-pointed star
234
+ 'cross', // Plus/cross shape
235
+ 'list', // Three horizontal bars
236
+ 'grid', // 2x2 grid of squares
237
+ 'trapezium', // Trapezoid shape
238
+ 'zigzag', // Zigzag pattern
239
+ 'sparkle', // Sparkle effect
240
+ 'parallelogram', // Parallelogram shape
241
+ ];
242
+ ```
124
243
 
125
- ```bash
126
- # Install dependencies
127
- npm install
244
+ ### Context Menu Integration
128
245
 
129
- # Start development server
130
- npm run dev
246
+ ```tsx
247
+ // Right-click anywhere on the graph to open context menu
248
+ // Automatically generates "Add Node" menu with all available node types
249
+ // Clicking a node type adds it at the cursor position
250
+ ```
131
251
 
132
- # Run Storybook
133
- npm run storybook
252
+ ## 🎨 Styling
134
253
 
135
- # Build library
136
- npm run build
254
+ The library uses Tailwind CSS for styling and provides a dark theme that matches
255
+ Blender's aesthetic:
137
256
 
138
- # Run linting
139
- npm run lint
257
+ ```css
258
+ /* Import the default styles */
259
+ @import 'react-blender-nodes/style.css';
140
260
 
141
- # Format code
142
- npm run pretty
261
+ /* Customize colors using CSS variables */
262
+ :root {
263
+ --primary-black: #181818;
264
+ --primary-dark-gray: #272727;
265
+ --primary-gray: #3f3f3f;
266
+ --primary-white: #ffffff;
267
+ }
143
268
  ```
144
269
 
145
270
  ## 📚 Documentation
146
271
 
147
- Interactive component documentation is available via Storybook:
272
+ ### Interactive Documentation
273
+
274
+ Explore all components with live examples:
148
275
 
149
276
  ```bash
150
277
  npm run storybook
151
278
  ```
152
279
 
153
- Visit `http://localhost:6006` to explore all components with live examples and
154
- controls.
280
+ Visit `http://localhost:6006` to see:
155
281
 
156
- ## 🎨 Styling
282
+ - Component playgrounds
283
+ - Interactive controls
284
+ - Usage examples
285
+ - Handle shape demonstrations
157
286
 
158
- The library uses:
287
+ ### Component API
159
288
 
160
- - **Tailwind CSS** for utility-first styling
161
- - **React flow** for nodes base
289
+ #### FullGraph
290
+
291
+ The main graph editor component with full ReactFlow integration.
292
+
293
+ ```tsx
294
+ interface FullGraphProps {
295
+ state: State;
296
+ dispatch: Dispatch;
297
+ }
298
+ ```
299
+
300
+ #### ConfigurableNode
301
+
302
+ Customizable node component with dynamic inputs and outputs.
303
+
304
+ ```tsx
305
+ interface ConfigurableNodeProps {
306
+ name?: string;
307
+ headerColor?: string;
308
+ inputs?: (ConfigurableNodeInput | ConfigurableNodeInputPanel)[];
309
+ outputs?: ConfigurableNodeOutput[];
310
+ isCurrentlyInsideReactFlow?: boolean;
311
+ }
312
+ ```
313
+
314
+ ## 🔗 Links
315
+
316
+ - [📖 Storybook Documentation](https://theclearsky.github.io/react-blender-nodes/?path=/story/components-organisms-fullgraph--playground)
317
+ - [📦 NPM Package](https://www.npmjs.com/package/@theclearsky/react-blender-nodes)
318
+ - [🐛 Report Issues](https://github.com/TheClearSky/react-blender-nodes/issues)
319
+ - [💡 Request Features](https://github.com/TheClearSky/react-blender-nodes/discussions)
162
320
 
163
321
  ## 🤝 Contributing
164
322
 
165
- Contributions are welcome! Please read our contributing guidelines and ensure
166
- all tests pass before submitting a PR.
323
+ We welcome contributions! Please see our [Contributing Guide](./CONTRIBUTING.md)
324
+ for details on:
325
+
326
+ - Setting up the development environment
327
+ - Code style and conventions
328
+ - Submitting pull requests
329
+ - Reporting issues
167
330
 
168
331
  ## 📄 License
169
332
 
170
- MIT License - see [LICENSE](LICENSE) for details.
333
+ MIT License - see [LICENSE](./LICENSE) for details.
171
334
 
172
335
  ## 🙏 Acknowledgments
173
336
 
@@ -180,7 +343,6 @@ MIT License - see [LICENSE](LICENSE) for details.
180
343
  > Blender useful, consider
181
344
  > [donating to support their work](https://fund.blender.org/).
182
345
 
183
- ## 🔗 Links
346
+ ---
184
347
 
185
- - [Blender Official Repository](https://projects.blender.org/blender/blender.git)
186
- - [Support Blender Foundation](https://fund.blender.org/)
348
+ Made with ❤️ for the Blender and React communities