@luxonis/depthai-pipeline-lib 1.8.0 → 1.9.0

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.
@@ -5,6 +5,7 @@ import type { PipelineState } from '../services/pipeline-state.js';
5
5
  export type PipelineCanvasProps = FlexProps & {
6
6
  pipeline: Pipeline | null;
7
7
  pipelineState: PipelineState[] | null;
8
+ action?: React.ReactNode;
8
9
  };
9
10
  export declare const updateNodesOnPipelineStateChange: (nodes: ParsedNode[], pipelineState: PipelineState[]) => ParsedNode[];
10
11
  export declare const PipelineCanvas: React.FC<PipelineCanvasProps>;
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from 'react';
3
- import { ReactFlow, ReactFlowProvider, useEdgesState, useNodesState, useReactFlow, useStore, } from '@xyflow/react';
3
+ import { Panel, ReactFlow, ReactFlowProvider, useEdgesState, useNodesState, useReactFlow, useStore, } from '@xyflow/react';
4
4
  import { Flex, Header } from '@luxonis/common-fe-components';
5
5
  import Dagre from '@dagrejs/dagre';
6
6
  import { PipelineNode } from './Node.js';
@@ -125,7 +125,7 @@ export const updateNodesOnPipelineStateChange = (nodes, pipelineState) => {
125
125
  }
126
126
  return parsedNodes;
127
127
  };
128
- const PipelineCanvasBody = ({ pipeline, pipelineState, ...flexProps }) => {
128
+ const PipelineCanvasBody = ({ pipeline, pipelineState, action, ...flexProps }) => {
129
129
  const { fitView, setViewport, getViewport } = useReactFlow();
130
130
  const autoArrangeRef = React.useRef(true);
131
131
  const widthSelector = (state) => state.width;
@@ -184,6 +184,6 @@ const PipelineCanvasBody = ({ pipeline, pipelineState, ...flexProps }) => {
184
184
  }
185
185
  // eslint-disable-next-line react-hooks/exhaustive-deps
186
186
  }, [shouldFitAndResize]);
187
- return (_jsxs(Flex, { align: "center", justify: "center", full: true, height: "container.xs", rounded: "common", border: "base", ...flexProps, children: [!pipeline && _jsx(Header, { text: "Loading pipeline..." }), pipeline && (_jsx(ReactFlow, { nodes: nodes, edges: edges, onNodeDragStart: () => (autoArrangeRef.current = false), onNodesChange: onNodesChange, fitView: true, nodeTypes: { generic: PipelineNode }, minZoom: 0.4 }))] }));
187
+ return (_jsxs(Flex, { align: "center", justify: "center", full: true, height: "container.xs", rounded: "common", border: "base", ...flexProps, children: [!pipeline && _jsx(Header, { text: "Loading pipeline..." }), pipeline && (_jsx(ReactFlow, { nodes: nodes, edges: edges, onNodeDragStart: () => (autoArrangeRef.current = false), onNodesChange: onNodesChange, fitView: true, nodeTypes: { generic: PipelineNode }, minZoom: 0.4, children: action && _jsx(Panel, { position: "top-right", children: action }) }))] }));
188
188
  };
189
189
  export const PipelineCanvas = props => (_jsx(ReactFlowProvider, { children: _jsx(PipelineCanvasBody, { ...props }) }));
@@ -19,6 +19,7 @@ function parseHandles(handles) {
19
19
  }
20
20
  export function parsePipeline(rawPayload) {
21
21
  const { pipeline } = rawPayload;
22
+ // Set all nodes as generic nodes
22
23
  const nodes = pipeline.nodes
23
24
  .filter(([_, node]) => pipeline.connections.some(connection => connection.node1Id === node.id || connection.node2Id === node.id))
24
25
  .map(([id, node]) => ({
@@ -33,6 +34,7 @@ export function parsePipeline(rawPayload) {
33
34
  handles: parseHandles(node.ioInfo),
34
35
  },
35
36
  })) ?? [];
37
+ // Set all parent nodes as group nodes
36
38
  const mappedParentNodes = nodes.map(node => node.parentId).filter(id => id !== undefined);
37
39
  const filteredParentNodes = mappedParentNodes.filter(id => id !== '-1');
38
40
  const parentNodes = [...new Set(filteredParentNodes)];
@@ -55,6 +57,39 @@ export function parsePipeline(rawPayload) {
55
57
  background: 'rgba(0,0,0,0.125)',
56
58
  },
57
59
  })) ?? [];
60
+ const parentNodesIds = parentNodes.map(id => id.toString());
61
+ const childrenNodes = nodes
62
+ .map(node => {
63
+ if (node.parentId && parentNodesIds.includes(node.parentId)) {
64
+ return {
65
+ ...node,
66
+ parentId: `${node.parentId}-parent`,
67
+ extent: 'parent',
68
+ };
69
+ }
70
+ else if (parentNodesIds.includes(node.id)) {
71
+ return {
72
+ ...node,
73
+ parentId: `${node.id}-parent`,
74
+ extent: 'parent',
75
+ };
76
+ }
77
+ else {
78
+ return null;
79
+ }
80
+ })
81
+ .filter(node => node !== null);
82
+ const filteredNodes = nodes
83
+ .filter(node => childrenNodes.find(childNode => childNode.id === node.id) !== undefined ? null : node)
84
+ .filter(node => node !== null);
85
+ const newFormattedParentNodes = formattedParentNodes.map(node => ({
86
+ ...node,
87
+ id: `${node.id}-parent`,
88
+ data: {
89
+ ...node.data,
90
+ id: `${node.data.id}-parent`,
91
+ },
92
+ }));
58
93
  const edges = pipeline.connections.map(connection => ({
59
94
  id: `${connection.node1Id}-${connection.node2Id}-${connection.node1Output}-${connection.node2Input}-edge`,
60
95
  source: connection.node1Id.toString(),
@@ -77,8 +112,8 @@ export function parsePipeline(rawPayload) {
77
112
  },
78
113
  type: 'step',
79
114
  })) ?? [];
80
- const groupedNodes = [...formattedParentNodes, ...nodes];
81
115
  // NOTE: Parent nodes should be rendered before child nodes
116
+ const groupedNodes = [...newFormattedParentNodes, ...childrenNodes, ...filteredNodes];
82
117
  return { nodes: [...groupedNodes], edges: [...edges, ...bridges] };
83
118
  }
84
119
  export const DOCS_BASE_URL = `https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luxonis/depthai-pipeline-lib",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/src/index.js",