refactor(hooks): rename useNodeDimensions to useNodeBounds
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import shallow from 'zustand/shallow';
|
import shallow from 'zustand/shallow';
|
||||||
|
|
||||||
import { Rect } from '../types';
|
import { NodeBounds } from '../types';
|
||||||
import { useStore } from '../store';
|
import { useStore } from '../store';
|
||||||
|
|
||||||
function useNodeDimensions(id: string): Rect | null {
|
function useNodeBounds(id: string): NodeBounds | null {
|
||||||
const nodeDimensions = useStore(
|
const nodeBounds = useStore(
|
||||||
useCallback(
|
useCallback(
|
||||||
(s) => {
|
(s) => {
|
||||||
const nodeItem = s.nodeInternals.get(id);
|
const nodeItem = s.nodeInternals.get(id);
|
||||||
@@ -16,8 +16,8 @@ function useNodeDimensions(id: string): Rect | null {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...nodeItem.positionAbsolute,
|
...nodeItem.positionAbsolute,
|
||||||
width: nodeItem.width ?? 0,
|
width: nodeItem.width ?? null,
|
||||||
height: nodeItem.height ?? 0,
|
height: nodeItem.height ?? null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
[id]
|
[id]
|
||||||
@@ -25,7 +25,7 @@ function useNodeDimensions(id: string): Rect | null {
|
|||||||
shallow
|
shallow
|
||||||
);
|
);
|
||||||
|
|
||||||
return nodeDimensions;
|
return nodeBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default useNodeDimensions;
|
export default useNodeBounds;
|
||||||
@@ -27,6 +27,7 @@ export { applyNodeChanges, applyEdgeChanges } from './utils/changes';
|
|||||||
|
|
||||||
export { default as useZoomPanHelper } from './hooks/useZoomPanHelper';
|
export { default as useZoomPanHelper } from './hooks/useZoomPanHelper';
|
||||||
export { default as useUpdateNodeInternals } from './hooks/useUpdateNodeInternals';
|
export { default as useUpdateNodeInternals } from './hooks/useUpdateNodeInternals';
|
||||||
|
export { default as useNodeBounds } from './hooks/useNodeBounds';
|
||||||
export * from './hooks/useNodesEdgesState';
|
export * from './hooks/useNodesEdgesState';
|
||||||
|
|
||||||
export * from './additional-components';
|
export * from './additional-components';
|
||||||
|
|||||||
@@ -111,3 +111,8 @@ export type NodeInternalsItem = Node & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type NodeInternals = Map<string, NodeInternalsItem>;
|
export type NodeInternals = Map<string, NodeInternalsItem>;
|
||||||
|
|
||||||
|
export type NodeBounds = XYPosition & {
|
||||||
|
width: number | null;
|
||||||
|
height: number | null;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user