Browse Source

Fix placeholder (#6197)

* Fix dragging in absolute dragging mode

* Remove caching temp models

* Fix multiple components dropping position

* Fix placeholder position

* Remove spots if no valid target exists

---------

Co-authored-by: Artur Arseniev <artur.catch@hotmail.it>
pull/6204/head
mohamed yahia 1 year ago
committed by GitHub
parent
commit
fc30655002
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 12
      packages/core/src/utils/sorter/ComponentSorter.ts
  2. 1
      packages/core/src/utils/sorter/DropLocationDeterminer.ts
  3. 1
      packages/core/src/utils/sorter/RateLimiter.ts

12
packages/core/src/utils/sorter/ComponentSorter.ts

@ -129,8 +129,9 @@ export default class ComponentSorter<NodeType extends BaseComponentNode> extends
return sourceNodes.reduce((addedNodes, sourceNode) => {
if (!targetNode.canMove(sourceNode, index)) return addedNodes;
if (this.isPositionChanged(targetNode, sourceNode, index)) {
const addedNode = this.moveNode(targetNode, sourceNode, index);
const { index: lastIndex, addedNode } = this.moveNode(targetNode, sourceNode, index);
addedNodes.push(addedNode);
index = lastIndex;
}
index++; // Increment the index
return addedNodes;
@ -165,9 +166,9 @@ export default class ComponentSorter<NodeType extends BaseComponentNode> extends
* @param targetNode - The node where the source node will be moved.
* @param sourceNode - The node being moved.
* @param index - The index at which to move the source node.
* @returns The node that was moved and added, or null if it couldn't be moved.
* @returns An object containing the added node and its new index, or null if it couldn't be moved.
*/
private moveNode(targetNode: NodeType, sourceNode: NodeType, index: number): NodeType {
private moveNode(targetNode: NodeType, sourceNode: NodeType, index: number) {
const parent = sourceNode.getParent();
if (parent) {
const initialSourceIndex = parent.indexOfChild(sourceNode);
@ -180,7 +181,7 @@ export default class ComponentSorter<NodeType extends BaseComponentNode> extends
const addedNode = targetNode.addChildAt(sourceNode, index, { action: 'move-component' }) as NodeType;
this.triggerEndMoveEvent(addedNode);
return addedNode;
return { addedNode, index };
}
/**
@ -212,8 +213,10 @@ export default class ComponentSorter<NodeType extends BaseComponentNode> extends
private onTargetChange = (oldTargetNode: NodeType | undefined, newTargetNode: NodeType | undefined) => {
oldTargetNode?.restNodeState();
const { Canvas } = this.em;
if (!newTargetNode) {
this.placeholder.hide();
Canvas.removeSpots(spotTarget);
return;
}
newTargetNode?.setSelectedParentState();
@ -226,7 +229,6 @@ export default class ComponentSorter<NodeType extends BaseComponentNode> extends
this.placeholder.show();
}
const { Canvas } = this.em;
const { Select, Hover, Spacing } = CanvasSpotBuiltInTypes;
[Select, Hover, Spacing].forEach((type) => Canvas.removeSpots({ type }));
Canvas.addSpot({ ...spotTarget, component: newTargetNode.model });

1
packages/core/src/utils/sorter/DropLocationDeterminer.ts

@ -126,6 +126,7 @@ export class DropLocationDeterminer<T, NodeType extends SortableTreeNode<T>> ext
if (!targetNode) {
this.triggerLegacyOnMoveCallback(mouseEvent, 0);
this.triggerMoveEvent(mouseX, mouseY);
this.restLastMoveData();
return;
}

1
packages/core/src/utils/sorter/RateLimiter.ts

@ -27,5 +27,6 @@ export class RateLimiter<T> {
clearTimeout(this.timeout);
this.timeout = null;
}
delete this.lastArgs;
}
}

Loading…
Cancel
Save