mirror of
https://github.com/Shopify/draggable.git
synced 2025-12-08 20:15:56 +00:00
commit
e6cf325a98
@ -224,6 +224,7 @@ export class DragPressureEvent extends DragEvent {
|
|||||||
*/
|
*/
|
||||||
export class DragStopEvent extends DragEvent {
|
export class DragStopEvent extends DragEvent {
|
||||||
static type = 'drag:stop';
|
static type = 'drag:stop';
|
||||||
|
static cancelable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -157,11 +157,11 @@ Read-only property for pressure applied on a draggable element. Value ranges fro
|
|||||||
`DragStopEvent` gets triggered after `DragStartEvent`, once drag interactions have completed.
|
`DragStopEvent` gets triggered after `DragStartEvent`, once drag interactions have completed.
|
||||||
|
|
||||||
| | |
|
| | |
|
||||||
| ----------------- | --------------- |
|
| ----------------- | -------------------------------------------------- |
|
||||||
| **Specification** | `DragEvent` |
|
| **Specification** | `DragEvent` |
|
||||||
| **Interface** | `DragStopEvent` |
|
| **Interface** | `DragStopEvent` |
|
||||||
| **Cancelable** | false |
|
| **Cancelable** | true |
|
||||||
| **Cancel action** | - |
|
| **Cancel action** | Prevent item from being added where it was dropped |
|
||||||
| **type** | `drag:stop` |
|
| **type** | `drag:stop` |
|
||||||
|
|
||||||
## DragStoppedEvent
|
## DragStoppedEvent
|
||||||
|
|||||||
@ -420,19 +420,19 @@ export default class Draggable {
|
|||||||
this.originalSource.parentNode.insertBefore(this.source, this.originalSource);
|
this.originalSource.parentNode.insertBefore(this.source, this.originalSource);
|
||||||
this.originalSource.style.display = 'none';
|
this.originalSource.style.display = 'none';
|
||||||
|
|
||||||
const dragEvent = new DragStartEvent({
|
const dragStartEvent = new DragStartEvent({
|
||||||
source: this.source,
|
source: this.source,
|
||||||
originalSource: this.originalSource,
|
originalSource: this.originalSource,
|
||||||
sourceContainer: container,
|
sourceContainer: container,
|
||||||
sensorEvent,
|
sensorEvent,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.trigger(dragEvent);
|
this.trigger(dragStartEvent);
|
||||||
|
|
||||||
this.dragging = !dragEvent.canceled();
|
this.dragging = !dragStartEvent.canceled();
|
||||||
|
|
||||||
if (dragEvent.canceled()) {
|
if (dragStartEvent.canceled()) {
|
||||||
this.source.parentNode.removeChild(this.source);
|
this.source.remove();
|
||||||
this.originalSource.style.display = null;
|
this.originalSource.style.display = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -575,8 +575,8 @@ export default class Draggable {
|
|||||||
|
|
||||||
this.trigger(dragStopEvent);
|
this.trigger(dragStopEvent);
|
||||||
|
|
||||||
this.source.parentNode.insertBefore(this.originalSource, this.source);
|
if (!dragStopEvent.canceled()) this.source.parentNode.insertBefore(this.originalSource, this.source);
|
||||||
this.source.parentNode.removeChild(this.source);
|
this.source.remove();
|
||||||
this.originalSource.style.display = '';
|
this.originalSource.style.display = '';
|
||||||
|
|
||||||
this.source.classList.remove(...this.getClassNamesFor('source:dragging'));
|
this.source.classList.remove(...this.getClassNamesFor('source:dragging'));
|
||||||
|
|||||||
@ -27,7 +27,7 @@ describe('Focusable', () => {
|
|||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
draggable.destroy();
|
draggable.destroy();
|
||||||
sandbox.parentNode.removeChild(sandbox);
|
sandbox.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is included by default', () => {
|
it('is included by default', () => {
|
||||||
|
|||||||
@ -258,7 +258,7 @@ export default class Mirror extends AbstractPlugin {
|
|||||||
this.draggable.trigger(mirrorDestroyEvent);
|
this.draggable.trigger(mirrorDestroyEvent);
|
||||||
|
|
||||||
if (!mirrorDestroyEvent.canceled()) {
|
if (!mirrorDestroyEvent.canceled()) {
|
||||||
this.mirror.parentNode.removeChild(this.mirror);
|
this.mirror.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,7 @@ describe('Mirror', () => {
|
|||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
draggable.destroy();
|
draggable.destroy();
|
||||||
sandbox.parentNode.removeChild(sandbox);
|
sandbox.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates mirror element on `drag:start`', async () => {
|
it('creates mirror element on `drag:start`', async () => {
|
||||||
|
|||||||
@ -43,7 +43,7 @@ describe('DragSensor', () => {
|
|||||||
|
|
||||||
function teardown() {
|
function teardown() {
|
||||||
dragSensor.detach();
|
dragSensor.detach();
|
||||||
sandbox.parentNode.removeChild(sandbox);
|
sandbox.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('common', () => {
|
describe('common', () => {
|
||||||
|
|||||||
@ -42,7 +42,7 @@ describe('MouseSensor', () => {
|
|||||||
|
|
||||||
function teardown() {
|
function teardown() {
|
||||||
mouseSensor.detach();
|
mouseSensor.detach();
|
||||||
sandbox.parentNode.removeChild(sandbox);
|
sandbox.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('common', () => {
|
describe('common', () => {
|
||||||
|
|||||||
@ -34,7 +34,7 @@ describe('TouchSensor', () => {
|
|||||||
|
|
||||||
function teardown() {
|
function teardown() {
|
||||||
touchSensor.detach();
|
touchSensor.detach();
|
||||||
sandbox.parentNode.removeChild(sandbox);
|
sandbox.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('common', () => {
|
describe('common', () => {
|
||||||
|
|||||||
@ -37,7 +37,7 @@ describe('Draggable', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
sandbox.parentNode.removeChild(sandbox);
|
sandbox.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('.Plugins', () => {
|
describe('.Plugins', () => {
|
||||||
|
|||||||
@ -47,7 +47,7 @@ describe('Droppable', () => {
|
|||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
droppable.destroy();
|
droppable.destroy();
|
||||||
sandbox.parentNode.removeChild(sandbox);
|
sandbox.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('triggers', () => {
|
describe('triggers', () => {
|
||||||
|
|||||||
@ -62,7 +62,7 @@ describe('ResizeMirror', () => {
|
|||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
draggable.destroy();
|
draggable.destroy();
|
||||||
sandbox.parentNode.removeChild(sandbox);
|
sandbox.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('resizes mirror based on over element', async () => {
|
it('resizes mirror based on over element', async () => {
|
||||||
|
|||||||
@ -58,7 +58,7 @@ describe('Sortable', () => {
|
|||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
sortable.destroy();
|
sortable.destroy();
|
||||||
sandbox.parentNode.removeChild(sandbox);
|
sandbox.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers events', () => {
|
it('triggers events', () => {
|
||||||
|
|||||||
@ -153,7 +153,7 @@ export default class Swappable extends Draggable {
|
|||||||
function withTempElement(callback) {
|
function withTempElement(callback) {
|
||||||
const tmpElement = document.createElement('div');
|
const tmpElement = document.createElement('div');
|
||||||
callback(tmpElement);
|
callback(tmpElement);
|
||||||
tmpElement.parentNode.removeChild(tmpElement);
|
tmpElement.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
function swap(source, over) {
|
function swap(source, over) {
|
||||||
|
|||||||
@ -58,7 +58,7 @@ describe('Swappable', () => {
|
|||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
swappable.destroy();
|
swappable.destroy();
|
||||||
sandbox.parentNode.removeChild(sandbox);
|
sandbox.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('triggers events', () => {
|
it('triggers events', () => {
|
||||||
|
|||||||
@ -19,7 +19,7 @@ describe('utils', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
sandbox.parentNode.removeChild(sandbox);
|
sandbox.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return null when no element specified', () => {
|
it('should return null when no element specified', () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user