@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 +276 -114
- package/dist/index.d.ts +980 -20
- package/dist/react-blender-nodes.css +1 -1
- package/dist/react-blender-nodes.es.js.map +1 -1
- package/dist/react-blender-nodes.umd.js.map +1 -1
- package/package.json +6 -1
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
|
+

|
|
7
|
+
|
|
6
8
|
## 🎯 Overview
|
|
7
9
|
|
|
8
|
-
React Blender Nodes
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
-
|
|
20
|
-
|
|
21
|
-
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
### 🎨 Blender-Inspired Interface
|
|
18
|
+
|
|
19
|
+

|
|
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
|
+

|
|
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
|
+

|
|
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
|
+

|
|
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 {
|
|
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
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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: '
|
|
51
|
-
<FullGraph
|
|
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
|
-
|
|
125
|
+
### 🔒 Type Safety with Auto-Infer Helpers
|
|
58
126
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
154
|
+
**With auto-infer helpers:**
|
|
101
155
|
|
|
102
|
-
|
|
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
|
-
|
|
167
|
+
## 📖 Usage Examples
|
|
105
168
|
|
|
106
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
126
|
-
# Install dependencies
|
|
127
|
-
npm install
|
|
244
|
+
### Context Menu Integration
|
|
128
245
|
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
133
|
-
npm run storybook
|
|
252
|
+
## 🎨 Styling
|
|
134
253
|
|
|
135
|
-
|
|
136
|
-
|
|
254
|
+
The library uses Tailwind CSS for styling and provides a dark theme that matches
|
|
255
|
+
Blender's aesthetic:
|
|
137
256
|
|
|
138
|
-
|
|
139
|
-
|
|
257
|
+
```css
|
|
258
|
+
/* Import the default styles */
|
|
259
|
+
@import 'react-blender-nodes/style.css';
|
|
140
260
|
|
|
141
|
-
|
|
142
|
-
|
|
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
|
|
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
|
|
154
|
-
controls.
|
|
280
|
+
Visit `http://localhost:6006` to see:
|
|
155
281
|
|
|
156
|
-
|
|
282
|
+
- Component playgrounds
|
|
283
|
+
- Interactive controls
|
|
284
|
+
- Usage examples
|
|
285
|
+
- Handle shape demonstrations
|
|
157
286
|
|
|
158
|
-
|
|
287
|
+
### Component API
|
|
159
288
|
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
166
|
-
|
|
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
|
-
|
|
346
|
+
---
|
|
184
347
|
|
|
185
|
-
|
|
186
|
-
- [Support Blender Foundation](https://fund.blender.org/)
|
|
348
|
+
Made with ❤️ for the Blender and React communities
|