Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make drag:stop cancellable #525

Merged
merged 2 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Draggable/DragEvent/DragEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export class DragPressureEvent extends DragEvent {
*/
export class DragStopEvent extends DragEvent {
static type = 'drag:stop';
static cancelable = true;
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/Draggable/DragEvent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ Read-only property for pressure applied on a draggable element. Value ranges fro

`DragStopEvent` gets triggered after `DragStartEvent`, once drag interactions have completed.

| | |
| ----------------- | --------------- |
| **Specification** | `DragEvent` |
| **Interface** | `DragStopEvent` |
| **Cancelable** | false |
| **Cancel action** | - |
| **type** | `drag:stop` |
| | |
| ----------------- | -------------------------------------------------- |
| **Specification** | `DragEvent` |
| **Interface** | `DragStopEvent` |
| **Cancelable** | true |
| **Cancel action** | Prevent item from being added where it was dropped |
| **type** | `drag:stop` |

## DragStoppedEvent

Expand Down
14 changes: 7 additions & 7 deletions src/Draggable/Draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,19 +420,19 @@ export default class Draggable {
this.originalSource.parentNode.insertBefore(this.source, this.originalSource);
this.originalSource.style.display = 'none';

const dragEvent = new DragStartEvent({
const dragStartEvent = new DragStartEvent({
source: this.source,
originalSource: this.originalSource,
sourceContainer: container,
sensorEvent,
});

this.trigger(dragEvent);
this.trigger(dragStartEvent);

this.dragging = !dragEvent.canceled();
this.dragging = !dragStartEvent.canceled();

if (dragEvent.canceled()) {
this.source.parentNode.removeChild(this.source);
if (dragStartEvent.canceled()) {
this.source.remove();
this.originalSource.style.display = null;
return;
}
Expand Down Expand Up @@ -575,8 +575,8 @@ export default class Draggable {

this.trigger(dragStopEvent);

this.source.parentNode.insertBefore(this.originalSource, this.source);
this.source.parentNode.removeChild(this.source);
if (!dragStopEvent.canceled()) this.source.parentNode.insertBefore(this.originalSource, this.source);
this.source.remove();
this.originalSource.style.display = '';

this.source.classList.remove(...this.getClassNamesFor('source:dragging'));
Expand Down
2 changes: 1 addition & 1 deletion src/Draggable/Plugins/Focusable/tests/Focusable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Focusable', () => {

afterEach(() => {
draggable.destroy();
sandbox.parentNode.removeChild(sandbox);
sandbox.remove();
});

it('is included by default', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Draggable/Plugins/Mirror/Mirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export default class Mirror extends AbstractPlugin {
this.draggable.trigger(mirrorDestroyEvent);

if (!mirrorDestroyEvent.canceled()) {
this.mirror.parentNode.removeChild(this.mirror);
this.mirror.remove();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Draggable/Plugins/Mirror/tests/Mirror.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('Mirror', () => {

afterEach(() => {
draggable.destroy();
sandbox.parentNode.removeChild(sandbox);
sandbox.remove();
});

it('creates mirror element on `drag:start`', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Draggable/Sensors/DragSensor/tests/DragSensor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('DragSensor', () => {

function teardown() {
dragSensor.detach();
sandbox.parentNode.removeChild(sandbox);
sandbox.remove();
}

describe('common', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('MouseSensor', () => {

function teardown() {
mouseSensor.detach();
sandbox.parentNode.removeChild(sandbox);
sandbox.remove();
}

describe('common', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('TouchSensor', () => {

function teardown() {
touchSensor.detach();
sandbox.parentNode.removeChild(sandbox);
sandbox.remove();
}

describe('common', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Draggable/tests/Draggable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Draggable', () => {
});

afterEach(() => {
sandbox.parentNode.removeChild(sandbox);
sandbox.remove();
});

describe('.Plugins', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Droppable/tests/Droppable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('Droppable', () => {

afterEach(() => {
droppable.destroy();
sandbox.parentNode.removeChild(sandbox);
sandbox.remove();
});

describe('triggers', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/ResizeMirror/tests/ResizeMirror.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('ResizeMirror', () => {

afterEach(() => {
draggable.destroy();
sandbox.parentNode.removeChild(sandbox);
sandbox.remove();
});

it('resizes mirror based on over element', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Sortable/tests/Sortable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('Sortable', () => {

afterEach(() => {
sortable.destroy();
sandbox.parentNode.removeChild(sandbox);
sandbox.remove();
});

it('triggers events', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Swappable/Swappable.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default class Swappable extends Draggable {
function withTempElement(callback) {
const tmpElement = document.createElement('div');
callback(tmpElement);
tmpElement.parentNode.removeChild(tmpElement);
tmpElement.remove();
}

function swap(source, over) {
Expand Down
2 changes: 1 addition & 1 deletion src/Swappable/tests/Swappable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('Swappable', () => {

afterEach(() => {
swappable.destroy();
sandbox.parentNode.removeChild(sandbox);
sandbox.remove();
});

it('triggers events', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/utils/closest/tests/closest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('utils', () => {
});

afterEach(() => {
sandbox.parentNode.removeChild(sandbox);
sandbox.remove();
});

it('should return null when no element specified', () => {
Expand Down