feat(core): allow array of ids as updateNodeInternals arg

This commit is contained in:
braks
2023-05-10 12:31:56 +02:00
parent 22da0df68e
commit 70102b701b
@@ -6,12 +6,16 @@ import type { UpdateNodeInternals } from '../types';
function useUpdateNodeInternals(): UpdateNodeInternals {
const store = useStoreApi();
return useCallback<UpdateNodeInternals>((id: string) => {
return useCallback<UpdateNodeInternals>((id: string | string[]) => {
const { domNode, updateNodeDimensions } = store.getState();
const nodeElement = domNode?.querySelector(`.react-flow__node[data-id="${id}"]`) as HTMLDivElement;
if (nodeElement) {
requestAnimationFrame(() => updateNodeDimensions([{ id, nodeElement, forceUpdate: true }]));
const updateIds = Array.isArray(id) ? id : [id];
updateIds.forEach((id) => {
requestAnimationFrame(() => updateNodeDimensions([{ id, nodeElement, forceUpdate: true }]));
});
}
}, []);
}