Merge pull request #3007 from bcakmakoglu/feat/update-node-internals-arr-arg
feat(core): allow array of ids as updateNodeInternals arg
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'@reactflow/core': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Add `edgesUpdatable` prop to store state. Allows enabling/disabling edge updating globally.
|
||||||
@@ -6,13 +6,20 @@ import type { UpdateNodeInternals } from '../types';
|
|||||||
function useUpdateNodeInternals(): UpdateNodeInternals {
|
function useUpdateNodeInternals(): UpdateNodeInternals {
|
||||||
const store = useStoreApi();
|
const store = useStoreApi();
|
||||||
|
|
||||||
return useCallback<UpdateNodeInternals>((id: string) => {
|
return useCallback<UpdateNodeInternals>((id: string | string[]) => {
|
||||||
const { domNode, updateNodeDimensions } = store.getState();
|
const { domNode, updateNodeDimensions } = store.getState();
|
||||||
const nodeElement = domNode?.querySelector(`.react-flow__node[data-id="${id}"]`) as HTMLDivElement;
|
|
||||||
|
|
||||||
if (nodeElement) {
|
const updateIds = Array.isArray(id) ? id : [id];
|
||||||
requestAnimationFrame(() => updateNodeDimensions([{ id, nodeElement, forceUpdate: true }]));
|
|
||||||
}
|
requestAnimationFrame(() => {
|
||||||
|
updateIds.forEach((updateId) => {
|
||||||
|
const nodeElement = domNode?.querySelector(`.react-flow__node[data-id="${updateId}"]`) as HTMLDivElement;
|
||||||
|
|
||||||
|
if (nodeElement) {
|
||||||
|
updateNodeDimensions([{ id: updateId, nodeElement, forceUpdate: true }]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}, []);
|
}, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user