fixed, parentExpand & simplified updateNodePositions

This commit is contained in:
peterkogo
2024-01-24 13:44:28 +01:00
parent 5d3efa73a8
commit 829c82cfda
5 changed files with 9 additions and 15 deletions

View File

@@ -151,19 +151,16 @@ const createRFStore = ({
onNodesChange?.(changes);
}
},
updateNodePositions: (nodeDragItems, positionChanged = true, dragging = false) => {
updateNodePositions: (nodeDragItems, dragging = false) => {
const changes = nodeDragItems.map((node) => {
const change: NodePositionChange = {
id: node.id,
type: 'position',
position: node.position,
positionAbsolute: node.computed?.positionAbsolute,
dragging,
};
if (positionChanged) {
change.positionAbsolute = node.computed?.positionAbsolute;
change.position = node.position;
}
return change;
});

View File

@@ -3,6 +3,7 @@ import { EdgeLookup, NodeLookup } from '@xyflow/system';
import type { Node, Edge, EdgeChange, NodeChange, NodeSelectionChange, EdgeSelectionChange } from '../types';
export function handleParentExpand(updatedElements: any[], updateItem: any) {
console.log(updatedElements, updateItem);
for (const [index, item] of updatedElements.entries()) {
if (item.id === updateItem.parentNode) {
const parent = { ...item };
@@ -106,7 +107,7 @@ function applyChanges(changes: any[], elements: any[]): any[] {
const updatedElement = { ...element };
for (const change of changes) {
applyChange(change, updatedElement, elements);
applyChange(change, updatedElement, updatedElements);
}
updatedElements.push(updatedElement);

View File

@@ -63,7 +63,7 @@ export function createStore({
store.edges.set(addEdgeUtil(edgeParams, edges));
}
const updateNodePositions: UpdateNodePositions = (nodeDragItems, _, dragging = false) => {
const updateNodePositions: UpdateNodePositions = (nodeDragItems, dragging = false) => {
const nodeLookup = get(store.nodeLookup);
nodeDragItems.forEach((nodeDragItem) => {

View File

@@ -123,11 +123,7 @@ export type SelectionRect = Rect & {
export type OnError = (id: string, message: string) => void;
export type UpdateNodePositions = (
dragItems: NodeDragItem[] | NodeBase[],
positionChanged?: boolean,
dragging?: boolean
) => void;
export type UpdateNodePositions = (dragItems: NodeDragItem[] | NodeBase[], dragging?: boolean) => void;
export type PanBy = (delta: XYPosition) => boolean;
export type UpdateConnection = (params: {

View File

@@ -164,7 +164,7 @@ export function XYDrag<OnNodeDrag extends (e: any, nodes: any, node: any) => voi
return;
}
updateNodePositions(dragItems, true, true);
updateNodePositions(dragItems, true);
const onNodeOrSelectionDrag = nodeId ? onNodeDrag : wrapSelectionDragFunc(onSelectionDrag);
if (dragEvent && (onDrag || onNodeOrSelectionDrag)) {
@@ -296,7 +296,7 @@ export function XYDrag<OnNodeDrag extends (e: any, nodes: any, node: any) => voi
const { nodeLookup, updateNodePositions, onNodeDragStop, onSelectionDragStop } = getStoreItems();
const onNodeOrSelectionDragStop = nodeId ? onNodeDragStop : wrapSelectionDragFunc(onSelectionDragStop);
updateNodePositions(dragItems, false, false);
updateNodePositions(dragItems, false);
if (onDragStop || onNodeOrSelectionDragStop) {
const [currentNode, currentNodes] = getEventHandlerParams({