ember-sortable 5.1.2 → 5.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{addon-main.js → addon-main.cjs} +2 -0
- package/declarations/modifiers/sortable-group.d.ts +326 -0
- package/declarations/modifiers/sortable-group.d.ts.map +1 -0
- package/declarations/modifiers/sortable-handle.d.ts +24 -0
- package/declarations/modifiers/sortable-handle.d.ts.map +1 -0
- package/declarations/modifiers/sortable-item.d.ts +346 -0
- package/declarations/modifiers/sortable-item.d.ts.map +1 -0
- package/declarations/services/ember-sortable-internal-state.d.ts +58 -0
- package/declarations/services/ember-sortable-internal-state.d.ts.map +1 -0
- package/declarations/system/scroll-container.d.ts +18 -0
- package/declarations/system/scroll-container.d.ts.map +1 -0
- package/declarations/system/scroll-parent.d.ts +2 -0
- package/declarations/system/scroll-parent.d.ts.map +1 -0
- package/declarations/template-registry.d.ts +9 -0
- package/declarations/template-registry.d.ts.map +1 -0
- package/declarations/test-support/helpers/drag.d.ts +37 -0
- package/declarations/test-support/helpers/drag.d.ts.map +1 -0
- package/declarations/test-support/helpers/reorder.d.ts +25 -0
- package/declarations/test-support/helpers/reorder.d.ts.map +1 -0
- package/declarations/test-support/index.d.ts +5 -0
- package/declarations/test-support/index.d.ts.map +1 -0
- package/declarations/test-support/utils/keyboard.d.ts +17 -0
- package/declarations/test-support/utils/keyboard.d.ts.map +1 -0
- package/declarations/test-support/utils/offset.d.ts +11 -0
- package/declarations/test-support/utils/offset.d.ts.map +1 -0
- package/declarations/utils/constant.d.ts +11 -0
- package/declarations/utils/constant.d.ts.map +1 -0
- package/declarations/utils/coordinate.d.ts +17 -0
- package/declarations/utils/coordinate.d.ts.map +1 -0
- package/declarations/utils/css-calculation.d.ts +13 -0
- package/declarations/utils/css-calculation.d.ts.map +1 -0
- package/declarations/utils/defaults.d.ts +23 -0
- package/declarations/utils/defaults.d.ts.map +1 -0
- package/declarations/utils/keyboard.d.ts +17 -0
- package/declarations/utils/keyboard.d.ts.map +1 -0
- package/dist/{_rollupPluginBabelHelpers-543b1c36.js → _rollupPluginBabelHelpers-a7bede49.js} +2 -2
- package/dist/_rollupPluginBabelHelpers-a7bede49.js.map +1 -0
- package/dist/modifiers/sortable-group.js +63 -30
- package/dist/modifiers/sortable-group.js.map +1 -1
- package/dist/modifiers/sortable-handle.js +4 -4
- package/dist/modifiers/sortable-handle.js.map +1 -1
- package/dist/modifiers/sortable-item.js +187 -80
- package/dist/modifiers/sortable-item.js.map +1 -1
- package/dist/services/ember-sortable-internal-state.js +11 -5
- package/dist/services/ember-sortable-internal-state.js.map +1 -1
- package/dist/test-support/helpers/drag.js +4 -1
- package/dist/test-support/helpers/drag.js.map +1 -1
- package/dist/test-support/helpers/reorder.js +12 -2
- package/dist/test-support/helpers/reorder.js.map +1 -1
- package/dist/test-support/utils/keyboard.js.map +1 -1
- package/dist/test-support/utils/offset.js.map +1 -1
- package/dist/utils/constant.js.map +1 -1
- package/dist/utils/coordinate.js +4 -4
- package/dist/utils/coordinate.js.map +1 -1
- package/dist/utils/css-calculation.js +4 -4
- package/dist/utils/css-calculation.js.map +1 -1
- package/dist/utils/defaults.js.map +1 -1
- package/dist/utils/keyboard.js.map +1 -1
- package/package.json +103 -29
- package/dist/_rollupPluginBabelHelpers-543b1c36.js.map +0 -1
- package/dist/system/scroll-container.js +0 -54
- package/dist/system/scroll-container.js.map +0 -1
- package/dist/system/scroll-parent.js +0 -35
- package/dist/system/scroll-parent.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sortable-handle.js","sources":["../../src/modifiers/sortable-handle.
|
|
1
|
+
{"version":3,"file":"sortable-handle.js","sources":["../../src/modifiers/sortable-handle.ts"],"sourcesContent":["import Modifier from 'ember-modifier';\n\ninterface SortableHandleModifierSignature {\n Element: HTMLElement;\n}\n\n/**\n * Modifier to to mark the handle of an item. If this is not supplied the item will be the handle\n *\n * @module drag-drop/draggable-group\n * @example*\n * <ol {{sortable-group onChange=this.update a11yAnnouncementConfig=this.myA11yConfig}}>\n * {{#each model.items as |item|}}\n * <li {{sortable-item model=item}}>\n * {{item.name}}\n * <span class=\"handle\" {{sortable-handle}}>↕</span>\n * </li>\n * {{/each}}\n * </ol>\n */\nexport default class SortableHandleModifier extends Modifier<SortableHandleModifierSignature> {\n didSetup = false;\n\n override modify(element: HTMLElement /*, positional, named*/) {\n if (!this.didSetup) {\n // take the model and look up the registered element, the tell that element you are the handle\n element.dataset['sortableHandle'] = 'true';\n element.setAttribute('tabIndex', '0');\n element.setAttribute('role', 'button');\n this.didSetup = true;\n }\n }\n}\n"],"names":["SortableHandleModifier","Modifier","constructor","args","_defineProperty","modify","element","didSetup","dataset","setAttribute"],"mappings":";;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,MAAMA,sBAAsB,SAASC,QAAQ,CAAkC;AAAAC,EAAAA,WAAAA,CAAA,GAAAC,IAAA,EAAA;AAAA,IAAA,KAAA,CAAA,GAAAA,IAAA,CAAA,CAAA;AAAAC,IAAAA,eAAA,mBACjF,KAAK,CAAA,CAAA;AAAA,GAAA;EAEPC,MAAMA,CAACC,OAAoB,EAA0B;AAC5D,IAAA,IAAI,CAAC,IAAI,CAACC,QAAQ,EAAE;AAClB;AACAD,MAAAA,OAAO,CAACE,OAAO,CAAC,gBAAgB,CAAC,GAAG,MAAM,CAAA;AAC1CF,MAAAA,OAAO,CAACG,YAAY,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;AACrCH,MAAAA,OAAO,CAACG,YAAY,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;MACtC,IAAI,CAACF,QAAQ,GAAG,IAAI,CAAA;AACtB,KAAA;AACF,GAAA;AACF;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as _defineProperty, _ as _applyDecoratedDescriptor, b as _initializerDefineProperty } from '../_rollupPluginBabelHelpers-a7bede49.js';
|
|
2
2
|
import Modifier from 'ember-modifier';
|
|
3
3
|
import { Promise as Promise$1, defer } from 'rsvp';
|
|
4
4
|
import { action, set } from '@ember/object';
|
|
@@ -6,8 +6,6 @@ import { DRAG_ACTIONS, END_ACTIONS, ELEMENT_CLICK_ACTION } from '../utils/consta
|
|
|
6
6
|
import { bind, scheduleOnce, throttle, later, run } from '@ember/runloop';
|
|
7
7
|
import { DEBUG } from '@glimmer/env';
|
|
8
8
|
import { getX, getY } from '../utils/coordinate.js';
|
|
9
|
-
import ScrollContainer from '../system/scroll-container.js';
|
|
10
|
-
import scrollParent from '../system/scroll-parent.js';
|
|
11
9
|
import { getBorderSpacing } from '../utils/css-calculation.js';
|
|
12
10
|
import { buildWaiter } from '@ember/test-waiters';
|
|
13
11
|
import { inject } from '@ember/service';
|
|
@@ -15,9 +13,103 @@ import { assert, deprecate } from '@ember/debug';
|
|
|
15
13
|
import { registerDestructor } from '@ember/destroyable';
|
|
16
14
|
import { isTesting } from '@embroider/macros';
|
|
17
15
|
|
|
16
|
+
class ScrollContainer {
|
|
17
|
+
constructor(element) {
|
|
18
|
+
_defineProperty(this, "element", void 0);
|
|
19
|
+
_defineProperty(this, "isWindow", void 0);
|
|
20
|
+
_defineProperty(this, "top", void 0);
|
|
21
|
+
_defineProperty(this, "left", void 0);
|
|
22
|
+
_defineProperty(this, "width", void 0);
|
|
23
|
+
_defineProperty(this, "height", void 0);
|
|
24
|
+
_defineProperty(this, "scrollWidth", void 0);
|
|
25
|
+
_defineProperty(this, "scrollHeight", void 0);
|
|
26
|
+
_defineProperty(this, "maxScrollTop", void 0);
|
|
27
|
+
_defineProperty(this, "maxScrollLeft", void 0);
|
|
28
|
+
this.isWindow = element === document;
|
|
29
|
+
this.element = this.isWindow ? document.documentElement : element;
|
|
30
|
+
if (this.isWindow) {
|
|
31
|
+
this.top = 0;
|
|
32
|
+
this.left = 0;
|
|
33
|
+
this.width = document.documentElement.clientWidth;
|
|
34
|
+
this.height = document.documentElement.clientHeight;
|
|
35
|
+
} else {
|
|
36
|
+
// Absolute position in document
|
|
37
|
+
const {
|
|
38
|
+
top,
|
|
39
|
+
left
|
|
40
|
+
} = this.element.getBoundingClientRect();
|
|
41
|
+
this.top = top;
|
|
42
|
+
this.left = left;
|
|
43
|
+
// Viewport size of the container element
|
|
44
|
+
this.width = parseFloat(getComputedStyle(this.element).width);
|
|
45
|
+
this.height = parseFloat(getComputedStyle(this.element).height);
|
|
46
|
+
}
|
|
47
|
+
// Total size of the container element (including scrollable part)
|
|
48
|
+
this.scrollWidth = this.element.scrollWidth;
|
|
49
|
+
this.scrollHeight = this.element.scrollHeight;
|
|
50
|
+
// Max scroll pos
|
|
51
|
+
this.maxScrollTop = this.scrollHeight - this.height;
|
|
52
|
+
this.maxScrollLeft = this.scrollWidth - this.width;
|
|
53
|
+
}
|
|
54
|
+
get bottom() {
|
|
55
|
+
return this.top + this.height;
|
|
56
|
+
}
|
|
57
|
+
get right() {
|
|
58
|
+
return this.left + this.width;
|
|
59
|
+
}
|
|
60
|
+
scrollTop(value) {
|
|
61
|
+
if (value) {
|
|
62
|
+
value = Math.max(0, Math.min(this.maxScrollTop, value));
|
|
63
|
+
this.element.scrollTop = value;
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
return this.element.scrollTop;
|
|
67
|
+
}
|
|
68
|
+
scrollLeft(value) {
|
|
69
|
+
if (value) {
|
|
70
|
+
value = Math.max(0, Math.min(this.maxScrollLeft, value));
|
|
71
|
+
this.element.scrollLeft = value;
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
return this.element.scrollLeft;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function getParentElements(element) {
|
|
79
|
+
const parentsArray = [];
|
|
80
|
+
if (!element) {
|
|
81
|
+
return parentsArray;
|
|
82
|
+
}
|
|
83
|
+
let currentParent = element.parentElement;
|
|
84
|
+
while (currentParent !== null) {
|
|
85
|
+
parentsArray.push(currentParent);
|
|
86
|
+
currentParent = currentParent.parentElement;
|
|
87
|
+
}
|
|
88
|
+
return parentsArray;
|
|
89
|
+
}
|
|
90
|
+
function scrollParent (element) {
|
|
91
|
+
const position = getComputedStyle(element).position;
|
|
92
|
+
const excludeStaticParent = position === 'absolute';
|
|
93
|
+
let scrollParent = getParentElements(element).filter(function (parent) {
|
|
94
|
+
const parentElemStyles = getComputedStyle(parent);
|
|
95
|
+
if (excludeStaticParent && parentElemStyles.position === 'static') {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
const {
|
|
99
|
+
overflow,
|
|
100
|
+
overflowX,
|
|
101
|
+
overflowY
|
|
102
|
+
} = parentElemStyles;
|
|
103
|
+
return /(auto|scroll)/.test(overflow + overflowX + overflowY);
|
|
104
|
+
})[0];
|
|
105
|
+
if (!scrollParent || scrollParent === document.body) {
|
|
106
|
+
scrollParent = document;
|
|
107
|
+
}
|
|
108
|
+
return scrollParent;
|
|
109
|
+
}
|
|
110
|
+
|
|
18
111
|
var _dec, _class, _descriptor;
|
|
19
112
|
const sortableItemWaiter = buildWaiter('sortable-item-waiter');
|
|
20
|
-
|
|
21
113
|
/**
|
|
22
114
|
* Modifier to mark an element as an item to be reordered
|
|
23
115
|
*
|
|
@@ -37,7 +129,7 @@ const sortableItemWaiter = buildWaiter('sortable-item-waiter');
|
|
|
37
129
|
* {{/each}}
|
|
38
130
|
* </ol>
|
|
39
131
|
*/
|
|
40
|
-
let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'),
|
|
132
|
+
let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), _class = class SortableItemModifier extends Modifier {
|
|
41
133
|
/**
|
|
42
134
|
* The SortableGroupModifier this item belongs to. Assigned by the group
|
|
43
135
|
* when it inspects all the items in the list
|
|
@@ -66,7 +158,7 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
66
158
|
* If no group is assigned a default is used
|
|
67
159
|
*
|
|
68
160
|
* @default "_EmberSortableGroup"
|
|
69
|
-
* @returns {
|
|
161
|
+
* @returns {string}
|
|
70
162
|
*/
|
|
71
163
|
get groupName() {
|
|
72
164
|
return this.named.groupName || '_EmberSortableGroup';
|
|
@@ -180,16 +272,16 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
180
272
|
}
|
|
181
273
|
const dragOriginX = this._dragOriginX;
|
|
182
274
|
const dragOriginY = this._dragOriginY;
|
|
183
|
-
if (dragOriginX > this._pageX) {
|
|
275
|
+
if (dragOriginX && this._pageX && dragOriginX > this._pageX) {
|
|
184
276
|
moveDirection.left = true;
|
|
185
277
|
}
|
|
186
|
-
if (dragOriginX < this._pageX) {
|
|
278
|
+
if (dragOriginX && this._pageX && dragOriginX < this._pageX) {
|
|
187
279
|
moveDirection.right = true;
|
|
188
280
|
}
|
|
189
|
-
if (dragOriginY > this._pageY) {
|
|
281
|
+
if (dragOriginY && this._pageY && dragOriginY > this._pageY) {
|
|
190
282
|
moveDirection.top = true;
|
|
191
283
|
}
|
|
192
|
-
if (dragOriginY < this._pageY) {
|
|
284
|
+
if (dragOriginY && this._pageY && dragOriginY < this._pageY) {
|
|
193
285
|
moveDirection.bottom = true;
|
|
194
286
|
}
|
|
195
287
|
return moveDirection;
|
|
@@ -255,7 +347,7 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
255
347
|
@property disableCheckScrollBounds
|
|
256
348
|
*/
|
|
257
349
|
get disableCheckScrollBounds() {
|
|
258
|
-
return this.named.disableCheckScrollBounds
|
|
350
|
+
return this.named.disableCheckScrollBounds !== undefined ? this.named.disableCheckScrollBounds : isTesting();
|
|
259
351
|
}
|
|
260
352
|
|
|
261
353
|
/**
|
|
@@ -295,7 +387,7 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
295
387
|
@method freeze
|
|
296
388
|
*/
|
|
297
389
|
freeze() {
|
|
298
|
-
|
|
390
|
+
const el = this.element;
|
|
299
391
|
if (!el) {
|
|
300
392
|
return;
|
|
301
393
|
}
|
|
@@ -306,7 +398,7 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
306
398
|
@method reset
|
|
307
399
|
*/
|
|
308
400
|
reset() {
|
|
309
|
-
|
|
401
|
+
const el = this.element;
|
|
310
402
|
if (!el) {
|
|
311
403
|
return;
|
|
312
404
|
}
|
|
@@ -319,13 +411,12 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
319
411
|
@method thaw
|
|
320
412
|
*/
|
|
321
413
|
thaw() {
|
|
322
|
-
|
|
414
|
+
const el = this.element;
|
|
323
415
|
if (!el) {
|
|
324
416
|
return;
|
|
325
417
|
}
|
|
326
418
|
el.style.transition = '';
|
|
327
419
|
}
|
|
328
|
-
|
|
329
420
|
/**
|
|
330
421
|
* Setup event listeners for drag and drop
|
|
331
422
|
*
|
|
@@ -337,7 +428,7 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
337
428
|
if (this.isDisabled) {
|
|
338
429
|
return;
|
|
339
430
|
}
|
|
340
|
-
if (this.handleElement && !startEvent.target
|
|
431
|
+
if (this.handleElement && !startEvent.target?.closest(this.handle)) {
|
|
341
432
|
return;
|
|
342
433
|
}
|
|
343
434
|
startEvent.preventDefault();
|
|
@@ -367,9 +458,9 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
367
458
|
if (this.sortableGroup.sortedItems.some(x => x.isBusy)) {
|
|
368
459
|
return;
|
|
369
460
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
461
|
+
const distance = this.distance;
|
|
462
|
+
const dx = Math.abs(getX(startEvent) - getX(event));
|
|
463
|
+
const dy = Math.abs(getY(startEvent) - getY(event));
|
|
373
464
|
if (distance <= dx || distance <= dy) {
|
|
374
465
|
DRAG_ACTIONS.forEach(event => window.removeEventListener(event, this._prepareDragListener));
|
|
375
466
|
this._startDrag(startEvent);
|
|
@@ -387,9 +478,9 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
387
478
|
if (this.isBusy) {
|
|
388
479
|
return;
|
|
389
480
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
481
|
+
const drag = this._makeDragHandler(event);
|
|
482
|
+
const dragThrottled = ev => throttle(this, drag, ev, 16, false);
|
|
483
|
+
const drop = () => {
|
|
393
484
|
DRAG_ACTIONS.forEach(event => window.removeEventListener(event, dragThrottled));
|
|
394
485
|
END_ACTIONS.forEach(event => window.removeEventListener(event, drop));
|
|
395
486
|
run(() => {
|
|
@@ -411,10 +502,10 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
411
502
|
*/
|
|
412
503
|
|
|
413
504
|
_scrollOnEdges(drag) {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
505
|
+
const groupDirection = this.direction;
|
|
506
|
+
const element = this.element;
|
|
507
|
+
const scrollContainer = new ScrollContainer(scrollParent(element));
|
|
508
|
+
const itemContainer = {
|
|
418
509
|
width: parseInt(getComputedStyle(element).width, 10),
|
|
419
510
|
get height() {
|
|
420
511
|
return parseInt(getComputedStyle(element).height, 10);
|
|
@@ -444,25 +535,25 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
444
535
|
scrollKey = 'scrollTop';
|
|
445
536
|
pageKey = 'pageY';
|
|
446
537
|
}
|
|
447
|
-
|
|
538
|
+
const createFakeEvent = () => {
|
|
448
539
|
if (this._pageX == null && this._pageY == null) {
|
|
449
540
|
return;
|
|
450
541
|
}
|
|
451
542
|
return {
|
|
452
|
-
pageX: this._pageX,
|
|
453
|
-
pageY: this._pageY,
|
|
454
|
-
clientX: this._pageX,
|
|
455
|
-
clientY: this._pageY
|
|
543
|
+
pageX: this._pageX ?? 0,
|
|
544
|
+
pageY: this._pageY ?? 0,
|
|
545
|
+
clientX: this._pageX ?? 0,
|
|
546
|
+
clientY: this._pageY ?? 0
|
|
456
547
|
};
|
|
457
548
|
};
|
|
458
549
|
|
|
459
550
|
// Set a trigger padding that will start scrolling
|
|
460
551
|
// the box when the item reaches within padding pixels
|
|
461
552
|
// of the edge of the scroll container.
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
553
|
+
const checkScrollBounds = () => {
|
|
554
|
+
const leadingEdge = itemContainer[leadingEdgeKey];
|
|
555
|
+
const trailingEdge = itemContainer[trailingEdgeKey];
|
|
556
|
+
const scroll = scrollContainer[scrollKey]();
|
|
466
557
|
let delta = 0;
|
|
467
558
|
if (trailingEdge >= scrollContainer[trailingEdgeKey]) {
|
|
468
559
|
delta = trailingEdge - scrollContainer[trailingEdgeKey];
|
|
@@ -470,10 +561,10 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
470
561
|
delta = leadingEdge - scrollContainer[leadingEdgeKey];
|
|
471
562
|
}
|
|
472
563
|
if (delta !== 0) {
|
|
473
|
-
|
|
564
|
+
const speed = this.maxScrollSpeed;
|
|
474
565
|
delta = Math.min(Math.max(delta, -1 * speed), speed);
|
|
475
566
|
delta = scrollContainer[scrollKey](scroll + delta) - scroll;
|
|
476
|
-
|
|
567
|
+
const event = createFakeEvent();
|
|
477
568
|
if (event) {
|
|
478
569
|
if (scrollContainer.isWindow) {
|
|
479
570
|
event[pageKey] += delta;
|
|
@@ -501,7 +592,10 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
501
592
|
let dragOrigin;
|
|
502
593
|
let elementOrigin;
|
|
503
594
|
let scrollOrigin;
|
|
504
|
-
|
|
595
|
+
const parentElement = this.element.parentNode;
|
|
596
|
+
if (!parentElement) {
|
|
597
|
+
return () => {};
|
|
598
|
+
}
|
|
505
599
|
if (groupDirection === 'grid') {
|
|
506
600
|
this.startEvent = startEvent;
|
|
507
601
|
const dragOriginX = getX(startEvent);
|
|
@@ -514,13 +608,13 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
514
608
|
const scrollOriginY = parentElement.getBoundingClientRect().top;
|
|
515
609
|
return event => {
|
|
516
610
|
this._pageX = getX(event);
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
611
|
+
const dx = this._pageX - dragOriginX;
|
|
612
|
+
const scrollX = parentElement.getBoundingClientRect().left;
|
|
613
|
+
const x = elementOriginX + dx + (scrollOriginX - scrollX);
|
|
520
614
|
this._pageY = getY(event);
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
615
|
+
const dy = this._pageY - dragOriginY;
|
|
616
|
+
const scrollY = parentElement.getBoundingClientRect().top;
|
|
617
|
+
const y = elementOriginY + dy + (scrollOriginY - scrollY);
|
|
524
618
|
this._drag(x, y);
|
|
525
619
|
};
|
|
526
620
|
}
|
|
@@ -530,9 +624,9 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
530
624
|
scrollOrigin = parentElement.getBoundingClientRect().left;
|
|
531
625
|
return event => {
|
|
532
626
|
this._pageX = getX(event);
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
627
|
+
const dx = this._pageX - dragOrigin;
|
|
628
|
+
const scrollX = parentElement.getBoundingClientRect().left;
|
|
629
|
+
const x = elementOrigin + dx + (scrollOrigin - scrollX);
|
|
536
630
|
this._drag(x, 0);
|
|
537
631
|
};
|
|
538
632
|
}
|
|
@@ -542,12 +636,13 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
542
636
|
scrollOrigin = parentElement.getBoundingClientRect().top;
|
|
543
637
|
return event => {
|
|
544
638
|
this._pageY = getY(event);
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
639
|
+
const dy = this._pageY - dragOrigin;
|
|
640
|
+
const scrollY = parentElement.getBoundingClientRect().top;
|
|
641
|
+
const y = elementOrigin + dy + (scrollOrigin - scrollY);
|
|
548
642
|
this._drag(0, y);
|
|
549
643
|
};
|
|
550
644
|
}
|
|
645
|
+
return () => {};
|
|
551
646
|
}
|
|
552
647
|
|
|
553
648
|
/**
|
|
@@ -555,7 +650,7 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
555
650
|
@private
|
|
556
651
|
*/
|
|
557
652
|
_scheduleApplyPosition() {
|
|
558
|
-
scheduleOnce('render', this,
|
|
653
|
+
scheduleOnce('render', this, this._applyPosition);
|
|
559
654
|
}
|
|
560
655
|
|
|
561
656
|
/**
|
|
@@ -568,20 +663,20 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
568
663
|
}
|
|
569
664
|
const groupDirection = this.direction;
|
|
570
665
|
if (groupDirection === 'grid') {
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
666
|
+
const x = this.x;
|
|
667
|
+
const dx = x - this.element.offsetLeft + parseFloat(getComputedStyle(this.element).marginLeft);
|
|
668
|
+
const y = this.y;
|
|
669
|
+
const dy = y - this.element.offsetTop;
|
|
575
670
|
this.element.style.transform = `translate(${dx}px, ${dy}px)`;
|
|
576
671
|
}
|
|
577
672
|
if (groupDirection === 'x') {
|
|
578
|
-
|
|
579
|
-
|
|
673
|
+
const x = this.x;
|
|
674
|
+
const dx = x - this.element.offsetLeft + parseFloat(getComputedStyle(this.element).marginLeft);
|
|
580
675
|
this.element.style.transform = `translateX(${dx}px)`;
|
|
581
676
|
}
|
|
582
677
|
if (groupDirection === 'y') {
|
|
583
|
-
|
|
584
|
-
|
|
678
|
+
const y = this.y;
|
|
679
|
+
const dy = y - this.element.offsetTop;
|
|
585
680
|
this.element.style.transform = `translateY(${dy}px)`;
|
|
586
681
|
}
|
|
587
682
|
}
|
|
@@ -594,9 +689,11 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
594
689
|
if (!this.isDragging) {
|
|
595
690
|
return;
|
|
596
691
|
}
|
|
597
|
-
|
|
692
|
+
const updateInterval = this.updateInterval;
|
|
598
693
|
this.x = dimensionX;
|
|
599
694
|
this.y = dimensionY;
|
|
695
|
+
|
|
696
|
+
// @ts-expect-error Argument of type 'this' is not assignable to parameter of type 'AnyFn'.
|
|
600
697
|
throttle(this, this.sortableGroup.update, updateInterval);
|
|
601
698
|
}
|
|
602
699
|
|
|
@@ -608,7 +705,7 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
608
705
|
if (!this.element) {
|
|
609
706
|
return;
|
|
610
707
|
}
|
|
611
|
-
|
|
708
|
+
const transitionPromise = this._waitForTransition();
|
|
612
709
|
this._preventClick();
|
|
613
710
|
|
|
614
711
|
// Get sortableItems before making drop end and pass it to update function
|
|
@@ -618,7 +715,7 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
618
715
|
set(this, 'isDragging', false);
|
|
619
716
|
set(this, 'isDropping', true);
|
|
620
717
|
this.sortableGroup.update(sortedItems);
|
|
621
|
-
|
|
718
|
+
const allTransitionPromise = this._waitForAllTransitions();
|
|
622
719
|
Promise$1.all([transitionPromise, allTransitionPromise]).then(() => this._complete());
|
|
623
720
|
}
|
|
624
721
|
|
|
@@ -687,7 +784,7 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
687
784
|
if (this.isAnimated) {
|
|
688
785
|
const animations = this.sortableGroup.sortedItems.map(x => x.element.getAnimations());
|
|
689
786
|
const animationPromises = animations.map(animation => {
|
|
690
|
-
return animation.finished;
|
|
787
|
+
return animation.every(x => x.finished);
|
|
691
788
|
});
|
|
692
789
|
transitionPromise = Promise$1.all(animationPromises);
|
|
693
790
|
} else {
|
|
@@ -716,8 +813,8 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
716
813
|
if (!this.element) {
|
|
717
814
|
return undefined;
|
|
718
815
|
}
|
|
719
|
-
|
|
720
|
-
|
|
816
|
+
const el = this.element;
|
|
817
|
+
const transitionProperty = getComputedStyle(el).transitionProperty;
|
|
721
818
|
return /all|transform/.test(transitionProperty) && this.transitionDuration > 0;
|
|
722
819
|
}
|
|
723
820
|
|
|
@@ -728,12 +825,12 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
728
825
|
*/
|
|
729
826
|
get transitionDuration() {
|
|
730
827
|
const items = this.sortableGroup.sortedItems.filter(x => !x.isDragging && !x.isDropping);
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
828
|
+
const el = items[0]?.element ?? this.element; // Fallback when only one element is present in list
|
|
829
|
+
const rule = getComputedStyle(el).transitionDuration;
|
|
830
|
+
const match = rule.match(/([\d.]+)([ms]*)/);
|
|
734
831
|
if (match) {
|
|
735
|
-
let value = parseFloat(match[1]);
|
|
736
|
-
|
|
832
|
+
let value = parseFloat(match[1] ?? '');
|
|
833
|
+
const unit = match[2];
|
|
737
834
|
if (unit === 's') {
|
|
738
835
|
value = value * 1000;
|
|
739
836
|
}
|
|
@@ -749,7 +846,7 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
749
846
|
*/
|
|
750
847
|
get x() {
|
|
751
848
|
if (this._x === undefined) {
|
|
752
|
-
|
|
849
|
+
const marginLeft = parseFloat(getComputedStyle(this.element).marginLeft);
|
|
753
850
|
this._x = this.element.scrollLeft + this.element.offsetLeft - marginLeft;
|
|
754
851
|
}
|
|
755
852
|
return this._x;
|
|
@@ -785,9 +882,9 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
785
882
|
@type Number
|
|
786
883
|
*/
|
|
787
884
|
get width() {
|
|
788
|
-
|
|
885
|
+
const el = this.element;
|
|
789
886
|
let width = el.offsetWidth;
|
|
790
|
-
|
|
887
|
+
const elStyles = getComputedStyle(el);
|
|
791
888
|
width += parseInt(elStyles.marginLeft) + parseInt(elStyles.marginRight); // equal to jQuery.outerWidth(true)
|
|
792
889
|
|
|
793
890
|
width += getBorderSpacing(el).horizontal;
|
|
@@ -800,9 +897,9 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
800
897
|
@type Number
|
|
801
898
|
*/
|
|
802
899
|
get height() {
|
|
803
|
-
|
|
900
|
+
const el = this.element;
|
|
804
901
|
let height = el.offsetHeight;
|
|
805
|
-
|
|
902
|
+
const elStyles = getComputedStyle(el);
|
|
806
903
|
|
|
807
904
|
// This is needed atm only for grid, to fix jumping on drag-start.
|
|
808
905
|
// In test-app it looks like there is a side-effect when we activate also for direction vertical.
|
|
@@ -830,23 +927,33 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
830
927
|
this.handleElement = this.element.querySelector(this.handle);
|
|
831
928
|
const touchAction = disabled ? 'initial' : 'none';
|
|
832
929
|
if (this.handleElement) {
|
|
833
|
-
this.handleElement.style['
|
|
930
|
+
this.handleElement.style['touchAction'] = touchAction;
|
|
834
931
|
} else {
|
|
835
|
-
this.element.style['
|
|
932
|
+
this.element.style['touchAction'] = touchAction;
|
|
836
933
|
}
|
|
837
934
|
}
|
|
838
935
|
constructor(owner, args) {
|
|
839
936
|
super(owner, args);
|
|
840
937
|
_defineProperty(this, "className", 'sortable-item');
|
|
841
938
|
_initializerDefineProperty(this, "sortableService", _descriptor, this);
|
|
939
|
+
_defineProperty(this, "startEvent", void 0);
|
|
842
940
|
_defineProperty(this, "_sortableGroup", void 0);
|
|
941
|
+
_defineProperty(this, "_x", void 0);
|
|
942
|
+
_defineProperty(this, "_y", void 0);
|
|
943
|
+
_defineProperty(this, "_dragOriginX", void 0);
|
|
944
|
+
_defineProperty(this, "_dragOriginY", void 0);
|
|
945
|
+
_defineProperty(this, "_pageX", void 0);
|
|
946
|
+
_defineProperty(this, "_pageY", void 0);
|
|
843
947
|
_defineProperty(this, "handleElement", void 0);
|
|
844
948
|
_defineProperty(this, "_isDragging", false);
|
|
845
949
|
_defineProperty(this, "_isDropping", false);
|
|
846
950
|
_defineProperty(this, "wasDropped", false);
|
|
951
|
+
_defineProperty(this, "_prepareDragListener", void 0);
|
|
952
|
+
_defineProperty(this, "_cancelStartDragListener", void 0);
|
|
847
953
|
_defineProperty(this, "maxScrollSpeed", 20);
|
|
848
954
|
_defineProperty(this, "element", void 0);
|
|
849
955
|
_defineProperty(this, "didSetup", false);
|
|
956
|
+
_defineProperty(this, "named", void 0);
|
|
850
957
|
/**
|
|
851
958
|
* tracks if event listeners have been registered. Registering event handlers is unnecessary if item is disabled.
|
|
852
959
|
*/
|
|
@@ -862,7 +969,7 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
862
969
|
// (doesn't work in Chrome 56), we set touch-action: none as a workaround.
|
|
863
970
|
this.setupHandleElement(this.named.disabled);
|
|
864
971
|
if (!this.didSetup) {
|
|
865
|
-
this.element.dataset
|
|
972
|
+
this.element.dataset['sortableItem'] = 'true';
|
|
866
973
|
this.sortableService.registerItem(this.groupName, this);
|
|
867
974
|
this.didSetup = true;
|
|
868
975
|
}
|
|
@@ -872,12 +979,12 @@ let SortableItemModifier = (_dec = inject('ember-sortable-internal-state'), (_cl
|
|
|
872
979
|
this.addEventListener();
|
|
873
980
|
}
|
|
874
981
|
}
|
|
875
|
-
},
|
|
982
|
+
}, _descriptor = _applyDecoratedDescriptor(_class.prototype, "sortableService", [_dec], {
|
|
876
983
|
configurable: true,
|
|
877
984
|
enumerable: true,
|
|
878
985
|
writable: true,
|
|
879
986
|
initializer: null
|
|
880
|
-
}), _applyDecoratedDescriptor(_class.prototype, "mouseDown", [action], Object.getOwnPropertyDescriptor(_class.prototype, "mouseDown"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "keyDown", [action], Object.getOwnPropertyDescriptor(_class.prototype, "keyDown"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "touchStart", [action], Object.getOwnPropertyDescriptor(_class.prototype, "touchStart"), _class.prototype)
|
|
987
|
+
}), _applyDecoratedDescriptor(_class.prototype, "mouseDown", [action], Object.getOwnPropertyDescriptor(_class.prototype, "mouseDown"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "keyDown", [action], Object.getOwnPropertyDescriptor(_class.prototype, "keyDown"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "touchStart", [action], Object.getOwnPropertyDescriptor(_class.prototype, "touchStart"), _class.prototype), _class);
|
|
881
988
|
/**
|
|
882
989
|
*
|
|
883
990
|
* @param {SortableItemModifier} instance
|