
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
@nodl/react
Advanced tools
A React-implementation of the Nodl framework.
This library is powered by MobX under the hood; and may be observed by an external MobX-instance for UI reactivity.
# Using NPM
npm install @nodl/core @nodl/react
# Using Yarn
yarn add @nodl/core @nodl/react
# Using Bun
bun install @nodl/core @nodl/react
Make sure to also install the following packages:
# Using NPM
npm install react react-dom rxjs zod
# Using Yarn
yarn add react react-dom rxjs zod
# Using Bun
bun install react react-dom rxjs zod
The fundamental piece which renders a surface with fully interactive Nodes & Connections.
Supports the following props:
store: CircuitStore
A Circuit store which holds the internal circuit state along with associated nodes.className?: string
An optional className to assign the Circuit.onConnection?(connection: Connection<unknown>)
An optional callback which fires when new connections are made.onConnectionRemoval?(connection: Connection<unknown>)
An optional callback which fires when connections are removed.onNodeRemoval?(node: Node)
An optional callback which fires when nodes are removed.onSelectionChanged?(nodes: Node[])
An optional callback which fires when selected nodes changes.export const App = () => {
const store = new CircuitStore();
React.useEffect(() => {
store.setNodes([
[additionNode1, { x: -220, y: 100 }],
[additionNode2, { x: -220, y: -100 }],
[additionNode3, { x: 220, y: 0 }]
]);
return () => {
store.dispose();
};
}, []);
return (
<Circuit
store={store}
onConnection={connection => console.log('NEW CONNECTION', connection)}
onConnectionRemoval={connection => console.log('REMOVED CONNECTION', connection)}
onNodeRemoval={node => console.log('REMOVED NODE', node)}
onSelectionChanged={nodes => console.log('SELECTION CHANGED', nodes)}
/>
);
};
The manager which is responsible for the circuit state.
nodes: Node[]
The associated nodes.selectedNodes: Node[]
The currently selected nodes.selectionBounds: Bounds | null
The current selected area's bounds.mousePosition: MousePosition
Current mouse position within the Circuit surface.setNodes(nodesWithPosition: [Node, {x: number, y: number}][])
Used to initialize the store with nodes along with their position.removeNode(nodeId: Node['id'])
Removes a node from the store.selectNodes(nodes: Node[])
Selects the given nodes.dispose()
Disposes the store and its internal reactions.import { Node, Input, Output } from '@nodl/core';
import { Circuit, CircuitStore } from '@nodl/react';
import * as React from 'react';
import { combineLatest, map } from 'rxjs';
import { z } from 'zod';
/** Declare a zod schema for value validation */
const NumberSchema = z.number();
class Addition extends Node {
inputs = {
a: new Input({ name: 'A', type: NumberSchema, defaultValue: 0 }),
b: new Input({ name: 'B', type: NumberSchema, defaultValue: 0 })
};
outputs = {
output: new Output({
name: 'Output',
type: NumberSchema,
observable: combineLatest([this.inputs.a, this.inputs.b]).pipe(
map(inputs => inputs.reduce((sum, value) => sum + value), 0)
)
})
};
}
/** Declare 3 addition nodes */
const additionNode1 = new Addition();
const additionNode2 = new Addition();
const additionNode3 = new Addition();
/** Connect them together */
additionNode1.outputs.output.connect(additionNode3.inputs.a);
additionNode2.outputs.output.connect(additionNode3.inputs.b);
export const App = () => {
const store = new CircuitStore();
React.useEffect(() => {
store.setNodes([
[additionNode1, { x: -220, y: 100 }],
[additionNode2, { x: -220, y: -100 }],
[additionNode3, { x: 220, y: 0 }]
]);
return () => {
store.dispose();
};
}, []);
return (
<Circuit
store={store}
onConnection={c => console.log('NEW CONNECTION', c)}
onConnectionRemoval={c => console.log('REMOVED CONNECTION', c)}
onNodeRemoval={n => console.log('REMOVED NODE', n)}
onSelectionChanged={s => console.log('SELECTION CHANGED', s)}
/>
);
};
FAQs
React implementation of the Nodl framework
We found that @nodl/react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.