Skip to content

Commit

Permalink
fixed drag start event
Browse files Browse the repository at this point in the history
  • Loading branch information
ishubin committed Dec 1, 2024
1 parent 3a7df46 commit 45a4c55
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/ui/components/editor/states/interact/DragItemState.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ export class DragItemState extends SubState {
* @param {Item} item
* @param {Number} x
* @param {Number} y
* @param {UserEventBus}
* @param {Item|undefined} componentItem
*/
constructor(parentState, listener, item, x, y, componentItem) {
constructor(parentState, listener, item, x, y, userEventBus, componentItem) {
super(parentState, 'drag-item');
this.listener = listener;
this.userEventBus = userEventBus;
this.initialClickPoint = {x, y};
this.originalItemPosition = {x: item.area.x, y: item.area.y};
this.item = item;
Expand All @@ -104,11 +106,11 @@ export class DragItemState extends SubState {
this.looper.stop();
}

emit(element, eventName, ...args) {
emit(item, eventName, ...args) {
if (this.componentItem) {
this.componentItem.meta.componentUserEventBus.emitItemEvent(this.item.id, eventName, ...args);
} else {
this.parentState.emit(element, eventName, ...args);
this.userEventBus.emitItemEvent(item.id, eventName, ...args);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/ui/components/editor/states/interact/IdleInteractState.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ export class IdleInteractState extends SubState {
this.initialClickPoint = {x: mx, y: my};
if (!isEventMiddleClick(event) && object && object.type === 'item') {
if (object.item.behavior.dragging !== 'none') {
this.migrateSubState(new DragItemState(this, this.listener, object.item, x, y, componentItem));
this.migrateSubState(new DragItemState(this, this.listener, object.item, x, y, this.userEventBus, componentItem));
return;
} else if (object.item.meta.ancestorDraggableId) {
const schemeContainer = componentItem ? componentItem.meta.componentSchemeContainer : this.schemeContainer;
const ancestorItem = schemeContainer.findItemById(object.item.meta.ancestorDraggableId);
if (ancestorItem) {
this.migrateSubState(new DragItemState(this, this.listener, ancestorItem, x, y, componentItem));
this.migrateSubState(new DragItemState(this, this.listener, ancestorItem, x, y, this.userEventBus, componentItem));
return;
}
}
Expand Down Expand Up @@ -254,7 +254,7 @@ export class IdleInteractState extends SubState {
if (componentItem && componentItem.meta.componentUserEventBus && item && item.id) {
componentItem.meta.componentUserEventBus.emitItemEvent(item.id, eventName, ...args);
} else {
this.parentState.emit(item, eventName, ...args);
this.userEventBus.emitItemEvent(item.id, eventName, ...args);
}
}

Expand Down

0 comments on commit 45a4c55

Please sign in to comment.