@theclearsky/react-blender-nodes 0.0.9 → 0.0.11
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
|
@@ -7,11 +7,15 @@
|
|
|
7
7
|
a flexible and customizable node-based graph editor for web applications.
|
|
8
8
|
</p>
|
|
9
9
|
|
|
10
|
+
<p align="center">
|
|
11
|
+
<a href="https://bundlejs.com/?q=%40theclearsky%2Freact-blender-nodes"><img src="https://deno.bundlejs.com/?q=%40theclearsky%2Freact-blender-nodes&badge=detailed&badge-style=for-the-badge" alt="spring-easing's badge" /></a>
|
|
12
|
+
</p>
|
|
13
|
+
|
|
10
14
|

|
|
11
15
|
|
|
12
16
|
## Quick Links
|
|
13
17
|
|
|
14
|
-
- [](https://theclearsky.github.io/react-blender-nodes/?path=/story/
|
|
18
|
+
- [](https://theclearsky.github.io/react-blender-nodes/?path=/story/organisms-fullgraph--with-runner) -
|
|
15
19
|
Interactive examples and component playground
|
|
16
20
|
- [](https://www.npmjs.com/package/@theclearsky/react-blender-nodes) -
|
|
17
21
|
Install and use in your project
|
|
@@ -180,7 +184,7 @@ https://github.com/user-attachments/assets/72d9384a-e9ca-4223-906a-dc422fb66f49
|
|
|
180
184
|
conversions
|
|
181
185
|
- **Cycle Detection**: Prevent infinite loops in your node graphs
|
|
182
186
|
- **Multiple Data Types**: Support for diverse data structures
|
|
183
|
-
- Basic types: `string`, `number`
|
|
187
|
+
- Basic types: `string`, `number`, `boolean`
|
|
184
188
|
- Complex types: Custom objects with Zod schemas
|
|
185
189
|
- Special types: `inferFromConnection`, `noEquivalent`
|
|
186
190
|
- **Runtime Safety**: Catch type errors before they break your application
|
|
@@ -247,6 +251,110 @@ const functionImplementations = makeFunctionImplementationsWithAutoInfer({
|
|
|
247
251
|
/>;
|
|
248
252
|
```
|
|
249
253
|
|
|
254
|
+
### useNodeRunner Hook
|
|
255
|
+
|
|
256
|
+
For advanced control over graph execution, use the `useNodeRunner` hook directly
|
|
257
|
+
instead of relying on the built-in runner UI:
|
|
258
|
+
|
|
259
|
+
```tsx
|
|
260
|
+
import { FullGraph, useFullGraph, useNodeRunner } from 'react-blender-nodes';
|
|
261
|
+
|
|
262
|
+
function MyExecutableGraph() {
|
|
263
|
+
const { state, dispatch } = useFullGraph(initialState);
|
|
264
|
+
|
|
265
|
+
const {
|
|
266
|
+
// State
|
|
267
|
+
runnerState, // 'idle' | 'compiling' | 'running' | 'paused' | 'completed' | 'errored'
|
|
268
|
+
nodeVisualStates, // Map<nodeId, 'idle' | 'running' | 'completed' | 'errored' | 'skipped'>
|
|
269
|
+
executionRecord, // Full execution recording with per-step timing and I/O snapshots
|
|
270
|
+
currentStepIndex, // Index of the currently active/viewed step
|
|
271
|
+
|
|
272
|
+
// Actions
|
|
273
|
+
run, // Start execution (mode-aware: instant or step-by-step)
|
|
274
|
+
pause, // Pause during step-by-step execution
|
|
275
|
+
resume, // Resume paused step-by-step execution
|
|
276
|
+
step, // Advance one step (starts a new run if idle)
|
|
277
|
+
stop, // Abort the current execution
|
|
278
|
+
reset, // Clear all execution state back to idle
|
|
279
|
+
replayTo, // Seek to a specific step index in a completed recording
|
|
280
|
+
loadRecord, // Load an imported ExecutionRecord (validates against current graph)
|
|
281
|
+
|
|
282
|
+
// Settings
|
|
283
|
+
mode, // Current execution mode: 'instant' | 'stepByStep'
|
|
284
|
+
setMode, // Switch execution mode
|
|
285
|
+
maxLoopIterations, // Max iterations before a loop is force-stopped
|
|
286
|
+
setMaxLoopIterations,
|
|
287
|
+
} = useNodeRunner({
|
|
288
|
+
state,
|
|
289
|
+
functionImplementations,
|
|
290
|
+
options: { maxLoopIterations: 100 },
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
return (
|
|
294
|
+
<div>
|
|
295
|
+
<button onClick={run}>Run</button>
|
|
296
|
+
<button onClick={step}>Step</button>
|
|
297
|
+
<button onClick={pause}>Pause</button>
|
|
298
|
+
<button onClick={resume}>Resume</button>
|
|
299
|
+
<button onClick={stop}>Stop</button>
|
|
300
|
+
<button onClick={reset}>Reset</button>
|
|
301
|
+
<p>Status: {runnerState}</p>
|
|
302
|
+
<FullGraph state={state} dispatch={dispatch} />
|
|
303
|
+
</div>
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Import/Export & Automatic Repair
|
|
309
|
+
|
|
310
|
+
Graph state and execution recordings can be exported to JSON and re-imported
|
|
311
|
+
later. On import, the library validates the structure and can automatically
|
|
312
|
+
repair common issues via opt-in repair strategies.
|
|
313
|
+
|
|
314
|
+
#### State Import Repair Strategies
|
|
315
|
+
|
|
316
|
+
Pass a `repair` object to `importGraphState` to enable automatic fixes:
|
|
317
|
+
|
|
318
|
+
```tsx
|
|
319
|
+
import { importGraphState } from 'react-blender-nodes';
|
|
320
|
+
|
|
321
|
+
const result = importGraphState(json, {
|
|
322
|
+
dataTypes: myDataTypes,
|
|
323
|
+
typeOfNodes: myTypeOfNodes,
|
|
324
|
+
repair: {
|
|
325
|
+
removeOrphanEdges: true, // Remove edges whose source or target node doesn't exist
|
|
326
|
+
removeDuplicateNodeIds: true, // Deduplicate nodes with the same ID (keep first)
|
|
327
|
+
removeDuplicateEdgeIds: true, // Deduplicate edges with the same ID (keep first)
|
|
328
|
+
fillMissingDefaults: true, // Fill missing optional fields (viewport, etc.) with defaults
|
|
329
|
+
rehydrateDataTypeObjects: true, // Rebuild handle dataType objects from provided dataTypes
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
if (result.success) {
|
|
334
|
+
// result.data is the repaired State
|
|
335
|
+
// result.warnings contains info about what was repaired
|
|
336
|
+
} else {
|
|
337
|
+
// result.errors contains fatal validation issues
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
#### Recording Import Repair Strategies
|
|
342
|
+
|
|
343
|
+
Pass a `repair` object to `importExecutionRecord` for recording-specific fixes:
|
|
344
|
+
|
|
345
|
+
```tsx
|
|
346
|
+
import { importExecutionRecord } from 'react-blender-nodes';
|
|
347
|
+
|
|
348
|
+
const result = importExecutionRecord(json, {
|
|
349
|
+
repair: {
|
|
350
|
+
sanitizeNonSerializableValues: true, // Replace non-serializable values with "[non-serializable]"
|
|
351
|
+
removeOrphanSteps: true, // Remove steps referencing nodes not present in the record
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
All repair strategies default to `false` and must be explicitly enabled.
|
|
357
|
+
|
|
250
358
|
## Usage Examples
|
|
251
359
|
|
|
252
360
|
### Smart Type System with Validation
|
|
@@ -452,8 +560,22 @@ The main graph editor component with full ReactFlow integration.
|
|
|
452
560
|
|
|
453
561
|
```tsx
|
|
454
562
|
interface FullGraphProps {
|
|
563
|
+
/** The current state of the graph including nodes, edges, and type definitions */
|
|
455
564
|
state: State;
|
|
565
|
+
/** Dispatch function for updating the graph state */
|
|
456
566
|
dispatch: Dispatch;
|
|
567
|
+
/** Function implementations for each node type, enables the runner when provided */
|
|
568
|
+
functionImplementations?: FunctionImplementations;
|
|
569
|
+
/** Called when state is successfully imported. Receives the raw parsed state. */
|
|
570
|
+
onStateImported?: (importedState: State) => void;
|
|
571
|
+
/** Called when a recording is successfully imported. Receives the parsed ExecutionRecord. */
|
|
572
|
+
onRecordingImported?: (record: ExecutionRecord) => void;
|
|
573
|
+
/** Called when import validation fails. Receives the error messages. */
|
|
574
|
+
onImportError?: (errors: string[]) => void;
|
|
575
|
+
/** Controlled execution record. When provided, FullGraph uses this instead of internal state. */
|
|
576
|
+
executionRecord?: ExecutionRecord | null;
|
|
577
|
+
/** Called whenever the execution record changes (run completes, reset, load, etc.). */
|
|
578
|
+
onExecutionRecordChange?: (record: ExecutionRecord | null) => void;
|
|
457
579
|
}
|
|
458
580
|
```
|
|
459
581
|
|
|
@@ -463,17 +585,36 @@ Customizable node component with dynamic inputs and outputs.
|
|
|
463
585
|
|
|
464
586
|
```tsx
|
|
465
587
|
interface ConfigurableNodeProps {
|
|
588
|
+
/** Unique identifier for the node (shown when enableDebugMode is true) */
|
|
589
|
+
id?: string;
|
|
590
|
+
/** Display name of the node */
|
|
466
591
|
name?: string;
|
|
592
|
+
/** Background color of the node header */
|
|
467
593
|
headerColor?: string;
|
|
594
|
+
/** Array of inputs and input panels */
|
|
468
595
|
inputs?: (ConfigurableNodeInput | ConfigurableNodeInputPanel)[];
|
|
596
|
+
/** Array of output sockets */
|
|
469
597
|
outputs?: ConfigurableNodeOutput[];
|
|
598
|
+
/** Whether the node is currently inside a ReactFlow context */
|
|
470
599
|
isCurrentlyInsideReactFlow?: boolean;
|
|
600
|
+
/** Props for the node resizer component */
|
|
601
|
+
nodeResizerProps?: NodeResizerWithMoreControlsProps;
|
|
602
|
+
/** Node type unique id */
|
|
603
|
+
nodeTypeUniqueId?: string;
|
|
604
|
+
/** Whether to show the node open button (used by node groups) */
|
|
605
|
+
showNodeOpenButton?: boolean;
|
|
606
|
+
/** Runner visual state for this node (undefined = no runner overlay) */
|
|
607
|
+
runnerVisualState?: NodeVisualState;
|
|
608
|
+
/** Errors from the runner for this node */
|
|
609
|
+
runnerErrors?: ReadonlyArray<GraphError>;
|
|
610
|
+
/** Warnings from the runner for this node */
|
|
611
|
+
runnerWarnings?: ReadonlyArray<string>;
|
|
471
612
|
}
|
|
472
613
|
```
|
|
473
614
|
|
|
474
615
|
## 🔗 Links
|
|
475
616
|
|
|
476
|
-
- [📖 Storybook Documentation](https://theclearsky.github.io/react-blender-nodes/?path=/story/
|
|
617
|
+
- [📖 Storybook Documentation](https://theclearsky.github.io/react-blender-nodes/?path=/story/organisms-fullgraph--with-runner)
|
|
477
618
|
- [📦 NPM Package](https://www.npmjs.com/package/@theclearsky/react-blender-nodes)
|
|
478
619
|
- [🐛 Report Issues](https://github.com/TheClearSky/react-blender-nodes/issues)
|
|
479
620
|
- [💡 Request Features](https://github.com/TheClearSky/react-blender-nodes/discussions)
|
|
@@ -24683,7 +24683,7 @@ function FV({
|
|
|
24683
24683
|
) : /* @__PURE__ */ y.jsx(
|
|
24684
24684
|
"span",
|
|
24685
24685
|
{
|
|
24686
|
-
className: "flex items-center justify-center text-[9px] font-medium text-[#eee] select-none",
|
|
24686
|
+
className: "flex items-center justify-center text-[9px] font-medium text-[#eee] select-none w-full",
|
|
24687
24687
|
style: { lineHeight: `${s}px` },
|
|
24688
24688
|
children: e.iteration
|
|
24689
24689
|
}
|
|
@@ -29914,4 +29914,3 @@ export {
|
|
|
29914
29914
|
Y3 as validateGraphStateStructure,
|
|
29915
29915
|
W3 as willAddingEdgeCreateCycle
|
|
29916
29916
|
};
|
|
29917
|
-
//# sourceMappingURL=react-blender-nodes.es.js.map
|