fixed some more stuff
This commit is contained in:
@@ -20,8 +20,6 @@
|
||||
$: selectedNodes = $nodes.filter((n) => n.selected);
|
||||
$: bounds = getNodesBounds(selectedNodes);
|
||||
|
||||
$: console.log($nodes);
|
||||
|
||||
function onContextMenu(event: MouseEvent | TouchEvent) {
|
||||
dispatch('selectioncontextmenu', { nodes: selectedNodes, event });
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ export function useNodesData(nodeIds: any): any {
|
||||
const _nodeIds = isArrayOfIds ? nodeIds : [nodeIds];
|
||||
|
||||
for (const nodeId of _nodeIds) {
|
||||
const node = nodeLookup.get(nodeId);
|
||||
const node = nodeLookup.get(nodeId)?.internals.userNode;
|
||||
if (node) {
|
||||
nextNodesData.push({
|
||||
id: node.id,
|
||||
|
||||
@@ -256,17 +256,28 @@ export function useSvelteFlow(): {
|
||||
nodeUpdate: Partial<Node> | ((node: Node) => Partial<Node>),
|
||||
options: { replace: boolean } = { replace: false }
|
||||
) => {
|
||||
nodes.update((nds) =>
|
||||
nds.map((node) => {
|
||||
if (node.id === id) {
|
||||
const nextNode = typeof nodeUpdate === 'function' ? nodeUpdate(node as Node) : nodeUpdate;
|
||||
const node = get(nodeLookup).get(id)?.internals.userNode;
|
||||
|
||||
return options.replace && isNode(nextNode) ? nextNode : { ...node, ...nextNode };
|
||||
}
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
||||
return node;
|
||||
})
|
||||
);
|
||||
const nextNode = typeof nodeUpdate === 'function' ? nodeUpdate(node as Node) : nodeUpdate;
|
||||
|
||||
if (options.replace) {
|
||||
nodes.update((nds) =>
|
||||
nds.map((node) => {
|
||||
if (node.id === id) {
|
||||
return isNode(nextNode) ? nextNode : { ...node, ...nextNode };
|
||||
}
|
||||
|
||||
return node;
|
||||
})
|
||||
);
|
||||
} else {
|
||||
Object.assign(node, nextNode);
|
||||
nodes.update((nds) => nds);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -448,13 +459,21 @@ export function useSvelteFlow(): {
|
||||
},
|
||||
updateNode,
|
||||
updateNodeData: (id, dataUpdate, options) => {
|
||||
updateNode(id, (node) => {
|
||||
const nextData = typeof dataUpdate === 'function' ? dataUpdate(node) : dataUpdate;
|
||||
const node = get(nodeLookup).get(id)?.internals.userNode;
|
||||
|
||||
return options?.replace
|
||||
? { ...node, data: nextData }
|
||||
: { ...node, data: { ...node.data, ...nextData } };
|
||||
});
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
|
||||
const nextData = typeof dataUpdate === 'function' ? dataUpdate(node) : dataUpdate;
|
||||
|
||||
if (options?.replace) {
|
||||
node.data = nextData;
|
||||
} else {
|
||||
node.data = { ...node.data, ...nextData };
|
||||
}
|
||||
|
||||
nodes.update((nds) => nds);
|
||||
},
|
||||
viewport
|
||||
};
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
};
|
||||
},
|
||||
onChange: (change: XYResizerChange, childChanges: XYResizerChildChange[]) => {
|
||||
const node = $nodeLookup.get(id);
|
||||
const node = $nodeLookup.get(id)?.internals.userNode;
|
||||
if (node) {
|
||||
node.height = change.isHeightChange ? change.height : node.height;
|
||||
node.width = change.isWidthChange ? change.width : node.width;
|
||||
@@ -79,7 +79,7 @@
|
||||
: node.position;
|
||||
|
||||
for (const childChange of childChanges) {
|
||||
const childNode = $nodeLookup.get(childChange.id);
|
||||
const childNode = $nodeLookup.get(childChange.id)?.internals.userNode;
|
||||
if (childNode) {
|
||||
childNode.position = childChange.position;
|
||||
}
|
||||
|
||||
@@ -65,20 +65,17 @@ export function createStore({
|
||||
const nodeLookup = get(store.nodeLookup);
|
||||
|
||||
for (const nodeDragItem of nodeDragItems) {
|
||||
const node = nodeLookup.get(nodeDragItem.id);
|
||||
const node = nodeLookup.get(nodeDragItem.id)?.internals.userNode;
|
||||
|
||||
if (!node) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const userNode = node.internals.userNode;
|
||||
userNode.position = nodeDragItem.position;
|
||||
userNode.dragging = dragging;
|
||||
// node.internals.positionAbsolute = nodeDragItem.internals.positionAbsolute;
|
||||
node.position = nodeDragItem.position;
|
||||
node.dragging = dragging;
|
||||
}
|
||||
|
||||
store.nodes.set(get(store.nodes));
|
||||
//$nodes = $nodes
|
||||
};
|
||||
|
||||
function updateNodeDimensions(updates: Map<string, NodeDimensionUpdate>) {
|
||||
@@ -111,11 +108,13 @@ export function createStore({
|
||||
}
|
||||
|
||||
switch (nodeUpdate.type) {
|
||||
case 'dimensions':
|
||||
case 'dimensions': {
|
||||
const measured = { ...node.measured, ...nodeUpdate.dimensions };
|
||||
node.width = nodeUpdate.dimensions?.width ?? node.width;
|
||||
node.height = nodeUpdate.dimensions?.height ?? node.height;
|
||||
// TODO: do we need measured here?
|
||||
node.measured = measured;
|
||||
break;
|
||||
}
|
||||
case 'position':
|
||||
node.position = nodeUpdate.position ?? node.position;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user