feat: add node group breadcrumbs

This commit is contained in:
2026-05-05 12:44:44 +02:00
parent bff140a764
commit 8ad62cfc8e
8 changed files with 318 additions and 159 deletions
@@ -1,4 +1,10 @@
import type { NodeDefinition } from '@nodarium/types';
import type {
Edge,
NodeDefinition,
NodeInstance,
SerializedEdge,
SerializedNode
} from '@nodarium/types';
export function getParameterHeight(node: NodeDefinition, inputKey: string) {
if (node.id === '__internal/group/input') {
@@ -27,6 +33,19 @@ export function getParameterHeight(node: NodeDefinition, inputKey: string) {
return 50;
}
export function serializeNode(node: SerializedNode | NodeInstance): SerializedNode {
return {
id: node.id,
position: [...node.position],
type: node.type,
props: node.props
};
}
export function serializeEdge(edge: Edge): SerializedEdge {
return [edge[0].id, edge[1], edge[2].id, edge[3]];
}
const nodeHeightCache: Record<string, number> = {};
export function getNodeHeight(node: NodeDefinition) {
if (!node || !('inputs' in node)) {
@@ -45,3 +64,34 @@ export function getNodeHeight(node: NodeDefinition) {
nodeHeightCache[node.id] = height;
return height;
}
export function areSocketsCompatible(
output: string | undefined,
inputs: string | (string | undefined)[] | undefined
) {
if (output === '*') return true;
if (Array.isArray(inputs) && output) {
return inputs.includes('*') || inputs.includes(output);
}
return inputs === output;
}
export function areEdgesEqual(firstEdge: Edge, secondEdge: Edge) {
if (firstEdge[0].id !== secondEdge[0].id) {
return false;
}
if (firstEdge[1] !== secondEdge[1]) {
return false;
}
if (firstEdge[2].id !== secondEdge[2].id) {
return false;
}
if (firstEdge[3] !== secondEdge[3]) {
return false;
}
return true;
}