chore(utils): cleanup
This commit is contained in:
@@ -5,13 +5,13 @@
|
||||
import { useRef, useEffect, type MouseEvent, type KeyboardEvent } from 'react';
|
||||
import cc from 'classcat';
|
||||
import { shallow } from 'zustand/shallow';
|
||||
import { getNodesBounds } from '@xyflow/system';
|
||||
import { getInternalNodesBounds } from '@xyflow/system';
|
||||
|
||||
import { useStore, useStoreApi } from '../../hooks/useStore';
|
||||
import { useDrag } from '../../hooks/useDrag';
|
||||
import { useMoveSelectedNodes } from '../../hooks/useMoveSelectedNodes';
|
||||
import { arrowKeyDiffs } from '../NodeWrapper/utils';
|
||||
import type { InternalNode, Node, ReactFlowState } from '../../types';
|
||||
import type { Node, ReactFlowState } from '../../types';
|
||||
|
||||
export type NodesSelectionProps<NodeType> = {
|
||||
onSelectionContextMenu?: (event: MouseEvent, nodes: NodeType[]) => void;
|
||||
@@ -20,14 +20,10 @@ export type NodesSelectionProps<NodeType> = {
|
||||
};
|
||||
|
||||
const selector = (s: ReactFlowState) => {
|
||||
const selectedNodes: InternalNode[] = [];
|
||||
for (const [, node] of s.nodeLookup) {
|
||||
if (node.selected) {
|
||||
selectedNodes.push(node);
|
||||
}
|
||||
}
|
||||
|
||||
const { width, height, x, y } = getNodesBounds(selectedNodes, { nodeOrigin: s.nodeOrigin });
|
||||
const { width, height, x, y } = getInternalNodesBounds(s.nodeLookup, {
|
||||
nodeOrigin: s.nodeOrigin,
|
||||
filter: (node) => !!node.selected,
|
||||
});
|
||||
|
||||
return {
|
||||
width,
|
||||
|
||||
@@ -2,14 +2,14 @@ import {
|
||||
infiniteExtent,
|
||||
ConnectionMode,
|
||||
adoptUserNodes,
|
||||
getNodesBounds,
|
||||
getViewportForBounds,
|
||||
Transform,
|
||||
updateConnectionLookup,
|
||||
devWarn,
|
||||
getInternalNodesBounds,
|
||||
} from '@xyflow/system';
|
||||
|
||||
import type { Edge, Node, ReactFlowStore } from '../types';
|
||||
import type { Edge, InternalNode, Node, ReactFlowStore } from '../types';
|
||||
|
||||
const getInitialState = ({
|
||||
nodes,
|
||||
@@ -28,7 +28,7 @@ const getInitialState = ({
|
||||
height?: number;
|
||||
fitView?: boolean;
|
||||
} = {}): ReactFlowStore => {
|
||||
const nodeLookup = new Map();
|
||||
const nodeLookup = new Map<string, InternalNode>();
|
||||
const parentLookup = new Map();
|
||||
const connectionLookup = new Map();
|
||||
const edgeLookup = new Map();
|
||||
@@ -44,11 +44,11 @@ const getInitialState = ({
|
||||
let transform: Transform = [0, 0, 1];
|
||||
|
||||
if (fitView && width && height) {
|
||||
const nodesWithDimensions = storeNodes.filter(
|
||||
(node) => (node.width || node.initialWidth) && (node.height || node.initialHeight)
|
||||
);
|
||||
// @todo users nodeOrigin should be used here
|
||||
const bounds = getNodesBounds(nodesWithDimensions, { nodeOrigin: [0, 0] });
|
||||
const bounds = getInternalNodesBounds(nodeLookup, {
|
||||
nodeOrigin: [0, 0],
|
||||
filter: (node) => !!((node.width || node.initialWidth) && (node.height || node.initialHeight)),
|
||||
});
|
||||
const { x, y, zoom } = getViewportForBounds(bounds, width, height, 0.5, 2, 0.1);
|
||||
transform = [x, y, zoom];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user