port more updates

This commit is contained in:
peterkogo
2024-12-17 17:37:26 +01:00
parent 72d3e014b7
commit 39930e705d
14 changed files with 68 additions and 57 deletions
@@ -11,7 +11,7 @@
type XYResizerChildChange
} from '@xyflow/system';
import type { ResizeControlProps } from './types';
import { get } from 'svelte/store';
import { useSvelteFlow } from '$lib/hooks/useSvelteFlow.svelte';
let {
nodeId,
@@ -34,6 +34,8 @@
const store = useStore();
const { updateNode } = useSvelteFlow();
let id = $derived(
typeof nodeId === 'string' ? nodeId : getContext<string>('svelteflow__node_id')
);
@@ -72,28 +74,20 @@
};
},
onChange: (change: XYResizerChange, childChanges: XYResizerChildChange[]) => {
const node = store.nodeLookup.get(id)?.internals.userNode;
if (!node) {
return;
}
if (change.x !== undefined && change.y !== undefined) {
node.position = { x: change.x, y: change.y };
}
if (change.width !== undefined && change.height !== undefined) {
node.width = change.width;
node.height = change.height;
}
updateNode(id, (node) => ({
...node,
position: { x: change.x ?? node.position.x, y: change.y ?? node.position.y },
width: change.width ?? node.width,
height: change.height ?? node.height
}));
// TODO: performance?
for (const childChange of childChanges) {
const childNode = store.nodeLookup.get(childChange.id)?.internals.userNode;
if (childNode) {
childNode.position = childChange.position;
}
updateNode(childChange.id, (node) => ({
...node,
position: childChange.position
}));
}
// store.nodes.set(get(store.nodes));
}
});
}