Skip to content

Commit

Permalink
fix: text selection wasn't working for non draggable, sortable or res…
Browse files Browse the repository at this point in the history
…izable elements
  • Loading branch information
marcospont committed Apr 7, 2022
1 parent 586cb85 commit 2fba742
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 20 deletions.
13 changes: 10 additions & 3 deletions src/draggable/draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export default class Draggable {
this.addPlugin(new AutoScroll(this));
this.addPlugin(new ConnectToSortable(this));
this.addSensor(new MouseSensor(this));
document.addEventListener('mouse:down', this.onMouseDown);
document.addEventListener('mouse:start', this.onDragStart);
document.addEventListener('mouse:move', this.onDragMove);
document.addEventListener('mouse:stop', this.onDragStop);
Expand All @@ -272,22 +273,28 @@ export default class Draggable {
);
};

onDragStart = event => {
onMouseDown = event => {
const sensorEvent = event.detail;

if (sensorEvent.caller !== this) {
return;
}

if (this.disabled || this.reverting) {
sensorEvent.cancel();
return;
}

if (!this.isInsideHandle(sensorEvent)) {
sensorEvent.cancel();
return;
}
};

onDragStart = event => {
const sensorEvent = event.detail;

if (sensorEvent.caller !== this) {
return;
}

blurActiveElement(sensorEvent);

Expand Down
21 changes: 13 additions & 8 deletions src/resizable/resizable.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ export default class Resizable extends Draggable {
this.addPlugin(new ResizeAnimate(this));
this.addPlugin(new ResizeGhost(this));
this.addSensor(new MouseSensor(this));
document.addEventListener('mouse:down', () => {
this.pressing = true;
});
document.addEventListener('mouse:down', this.onMouseDown);
document.addEventListener('mouse:stop', () => {
this.pressing = false;
});
Expand Down Expand Up @@ -231,24 +229,31 @@ export default class Resizable extends Draggable {
);
};

onDragStart = event => {
let handleCursor = null;
const { aspectRatio } = this.options;
onMouseDown = event => {
const sensorEvent = event.detail;

if (sensorEvent.caller !== this || !this.currentHandle || !this.currentDirection) {
return;
}

if (this.disabled) {
sensorEvent.cancel();
return;
}

if (!this.isInsideHandle(sensorEvent)) {
sensorEvent.cancel();
return;
}
this.pressing = true;
};

onDragStart = event => {
let handleCursor = null;
const { aspectRatio } = this.options;
const sensorEvent = event.detail;

if (sensorEvent.caller !== this || !this.currentHandle || !this.currentDirection) {
return;
}

this.resizing = true;
this.helper = this.createHelper(sensorEvent);
Expand Down
2 changes: 2 additions & 0 deletions src/sensor/mouse-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import SensorEvent from './sensor-event';

export class MouseDownEvent extends SensorEvent {
static type = 'mouse:down';

static cancelable = true;
}

export class MouseStartEvent extends SensorEvent {
Expand Down
21 changes: 12 additions & 9 deletions src/sensor/mouse-sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,21 @@ export default class MouseSensor extends Sensor {
this.onMouseUp(event);
}

const mouseDown = new MouseDownEvent({
pageX: event.pageX,
pageY: event.pageY,
target: event.target,
caller: this.caller,
originalEvent: event
});

this.pageX = event.pageX;
this.pageY = event.pageY;
this.startEvent = event;
this.trigger(
new MouseDownEvent({
pageX: event.pageX,
pageY: event.pageY,
target: event.target,
caller: this.caller,
originalEvent: event
})
);
this.trigger(mouseDown);
if (mouseDown.canceled) {
return;
}

document.addEventListener('dragstart', preventDefault);
document.addEventListener('mousemove', this.checkThresholds);
Expand Down
18 changes: 18 additions & 0 deletions src/sortable/sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export default class Sortable extends Draggable {
this.addPlugin(new StyleDecorator(this, 'zIndex'));
this.addPlugin(new AutoScroll(this));
this.addSensor(new MouseSensor(this));
document.addEventListener('mouse:down', this.onMouseDown);
document.addEventListener('mouse:start', this.onDragStart);
document.addEventListener('mouse:move', this.onDragMove);
document.addEventListener('mouse:stop', this.onDragStop);
Expand All @@ -187,6 +188,23 @@ export default class Sortable extends Draggable {
);
};

onMouseDown = event => {
const sensorEvent = event.detail;

if (sensorEvent.caller !== this) {
return;
}

if (this.disabled || this.reverting) {
sensorEvent.cancel();
return;
}

if (!this.findItem(sensorEvent)) {
sensorEvent.cancel();
}
};

onDragStart = (event, noActivation = false, forceOwnership = false) => {
const sensorEvent = event.detail;

Expand Down

0 comments on commit 2fba742

Please sign in to comment.