@luxonis/depthai-pipeline-lib 1.16.0 → 1.16.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.
@@ -11,6 +11,7 @@ const edgeTypes = { generic: BezierEdge, bridge: BridgeEdge };
11
11
  const PipelineCanvasBody = ({ pipeline, pipelineState: pipelineStateParsed, header, isDebugging = false, ...flexProps }) => {
12
12
  const { fitView, setViewport, getViewport } = useReactFlow();
13
13
  const autoArrangeRef = React.useRef(true);
14
+ const moveStartZoomRef = React.useRef(null);
14
15
  const widthSelector = (state) => state.width;
15
16
  const heightSelector = (state) => state.height;
16
17
  const reactFlowWidth = useStore(widthSelector);
@@ -18,6 +19,20 @@ const PipelineCanvasBody = ({ pipeline, pipelineState: pipelineStateParsed, head
18
19
  const [shouldFitAndResize, setShouldFitAndResize] = React.useState(false);
19
20
  const [openLegend, setOpenLegend] = React.useState(false);
20
21
  const pipelineState = React.useMemo(() => pipelineStateParsed, [pipelineStateParsed]);
22
+ const layoutSignature = React.useMemo(() => {
23
+ if (!pipeline) {
24
+ return '';
25
+ }
26
+ const nodeSignature = pipeline.nodes
27
+ .map((node) => `${node.id}:${node.parentId ?? ''}`)
28
+ .sort()
29
+ .join('|');
30
+ const edgeSignature = pipeline.edges
31
+ .map((edge) => `${edge.id}:${edge.source}:${edge.target}:${edge.sourceHandle ?? ''}:${edge.targetHandle ?? ''}:${edge.type ?? ''}`)
32
+ .sort()
33
+ .join('|');
34
+ return `${nodeSignature}__${edgeSignature}`;
35
+ }, [pipeline]);
21
36
  // biome-ignore lint/correctness/useExhaustiveDependencies: Intended
22
37
  React.useEffect(() => {
23
38
  void fitView();
@@ -25,34 +40,22 @@ const PipelineCanvasBody = ({ pipeline, pipelineState: pipelineStateParsed, head
25
40
  }, [reactFlowWidth, reactFlowHeight]);
26
41
  const [nodes, setNodes, onNodesChange] = useNodesState([]);
27
42
  const [edges, setEdges] = useEdgesState([]);
43
+ // biome-ignore lint/correctness/useExhaustiveDependencies: Layout should only rerun when graph structure changes
28
44
  React.useEffect(() => {
29
45
  if (!autoArrangeRef.current) {
30
46
  return;
31
47
  }
32
48
  const layouted = getLayoutedElements(pipeline?.nodes ?? [], pipeline?.edges ?? []);
33
- if (pipelineState) {
34
- const updatedNodes = updateNodesOnPipelineStateChange([...layouted.nodes], pipelineState);
35
- const adjustedNodes = adjustNodes([...updatedNodes], layouted.edges);
36
- setNodes([...adjustedNodes]);
37
- }
38
- else {
39
- const adjustedNodes = adjustNodes([...layouted.nodes], layouted.edges);
40
- setNodes([...adjustedNodes]);
41
- }
49
+ const adjustedNodes = adjustNodes([...layouted.nodes], layouted.edges);
50
+ setNodes([...adjustedNodes]);
42
51
  setEdges([...layouted.edges]);
43
52
  setShouldFitAndResize(true);
44
- }, [pipeline?.edges, pipeline?.nodes, setEdges, setNodes, pipelineState]);
53
+ }, [layoutSignature, setEdges, setNodes]);
45
54
  // biome-ignore lint/correctness/useExhaustiveDependencies: Intended
46
55
  React.useEffect(() => {
47
56
  if (pipelineState && nodes.length > 0) {
48
57
  const updatedNodes = updateNodesOnPipelineStateChange(nodes, pipelineState);
49
58
  setNodes([...updatedNodes]);
50
- if (!autoArrangeRef.current) {
51
- return;
52
- }
53
- else {
54
- setShouldFitAndResize(true);
55
- }
56
59
  }
57
60
  // eslint-disable-next-line react-hooks/exhaustive-deps
58
61
  }, [pipelineState]);
@@ -69,6 +72,16 @@ const PipelineCanvasBody = ({ pipeline, pipelineState: pipelineStateParsed, head
69
72
  }
70
73
  // eslint-disable-next-line react-hooks/exhaustive-deps
71
74
  }, [shouldFitAndResize]);
72
- 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 && (_jsxs(ReactFlow, { nodes: nodes, edges: edges, onNodeDragStart: () => (autoArrangeRef.current = false), onNodesChange: onNodesChange, fitView: true, nodeTypes: nodeTypes, edgeTypes: edgeTypes, minZoom: 0.4, children: [header && _jsx(Panel, { position: "top-center", children: header }), _jsx(Panel, { position: "top-right", children: _jsxs(Flex, { gap: "xs", flexDirection: "column", children: [_jsx(Button, { onClick: () => setOpenLegend(!openLegend), label: openLegend ? 'Collapse' : 'Legend' }), openLegend && _jsx(PipelineLegend, { isDebugging: isDebugging })] }) })] }))] }));
75
+ const handleMoveStart = React.useCallback((_, viewport) => {
76
+ moveStartZoomRef.current = viewport.zoom;
77
+ }, []);
78
+ const handleMoveEnd = React.useCallback((_, viewport) => {
79
+ if (moveStartZoomRef.current !== null &&
80
+ Math.abs(viewport.zoom - moveStartZoomRef.current) > 0.001) {
81
+ autoArrangeRef.current = false;
82
+ }
83
+ moveStartZoomRef.current = null;
84
+ }, []);
85
+ 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 && (_jsxs(ReactFlow, { nodes: nodes, edges: edges, onMoveStart: handleMoveStart, onMoveEnd: handleMoveEnd, onNodeDragStart: () => (autoArrangeRef.current = false), onNodesChange: onNodesChange, fitView: true, nodeTypes: nodeTypes, edgeTypes: edgeTypes, minZoom: 0.4, children: [header && _jsx(Panel, { position: "top-center", children: header }), _jsx(Panel, { position: "top-right", children: _jsxs(Flex, { gap: "xs", flexDirection: "column", children: [_jsx(Button, { onClick: () => setOpenLegend(!openLegend), label: openLegend ? 'Collapse' : 'Legend' }), openLegend && _jsx(PipelineLegend, { isDebugging: isDebugging })] }) })] }))] }));
73
86
  };
74
87
  export const PipelineCanvas = (props) => (_jsx(ReactFlowProvider, { children: _jsx(PipelineCanvasBody, { ...props }) }));
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Badge, Flex, Label, SubLabel } from '@luxonis/common-fe-components';
3
3
  import React from 'react';
4
+ import { PACKAGE_VERSION } from '../version.js';
4
5
  const debugSections = [
5
6
  {
6
7
  title: 'Nodes',
@@ -211,5 +212,5 @@ export const PipelineLegend = ({ isDebugging, }) => {
211
212
  bridgeSection,
212
213
  ]
213
214
  : sharedSections;
214
- return (_jsxs(Flex, { direction: "column", gap: "xs", width: "full", padding: "sm", rounded: "common", border: "base", backgroundColor: "white", maxWidth: "390px", children: [_jsx(Label, { text: "Legend", color: "black", weight: "medium", align: "center" }), _jsx(Flex, { direction: "column", gap: "xs", width: "full", children: sections.map((section) => (_jsx(LegendSection, { title: section.title, items: section.items }, section.title))) })] }));
215
+ return (_jsxs(Flex, { direction: "column", gap: "xs", width: "full", padding: "sm", rounded: "common", border: "base", backgroundColor: "white", maxWidth: "390px", children: [_jsx(Label, { text: "Legend", color: "black", weight: "medium", align: "center" }), _jsx(Flex, { direction: "column", gap: "xs", width: "full", children: sections.map((section) => (_jsx(LegendSection, { title: section.title, items: section.items }, section.title))) }), _jsx(SubLabel, { text: `v${PACKAGE_VERSION}`, color: "lightGray", align: "right" })] }));
215
216
  };
@@ -4,3 +4,4 @@ export type { Pipeline, RawPipelinePayload } from './services/pipeline.js';
4
4
  export { parsePipeline } from './services/pipeline.js';
5
5
  export type { PipelineState, RawPipelineStatePayload, } from './services/pipeline-state.js';
6
6
  export { parsePipelineState } from './services/pipeline-state.js';
7
+ export { PACKAGE_VERSION } from './version.js';
package/dist/src/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { PipelineCanvas } from './components/PipelineCanvas.js';
2
2
  export { parsePipeline } from './services/pipeline.js';
3
3
  export { parsePipelineState } from './services/pipeline-state.js';
4
+ export { PACKAGE_VERSION } from './version.js';
@@ -0,0 +1 @@
1
+ export declare const PACKAGE_VERSION = "1.16.2";
@@ -0,0 +1,3 @@
1
+ // This file is autogenerated by build-utils.sh.
2
+ // Do not edit it manually.
3
+ export const PACKAGE_VERSION = '1.16.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luxonis/depthai-pipeline-lib",
3
- "version": "1.16.0",
3
+ "version": "1.16.2",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/src/index.js",