@react-aria/dnd 3.6.1-nightly.4624 → 3.6.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/dist/DragManager.main.js +68 -68
- package/dist/DragManager.mjs +68 -68
- package/dist/DragManager.module.js +68 -68
- package/dist/DragPreview.main.js +1 -1
- package/dist/DragPreview.mjs +1 -1
- package/dist/DragPreview.module.js +1 -1
- package/dist/ListDropTargetDelegate.main.js +31 -31
- package/dist/ListDropTargetDelegate.mjs +31 -31
- package/dist/ListDropTargetDelegate.module.js +31 -31
- package/dist/constants.main.js +10 -10
- package/dist/constants.mjs +10 -10
- package/dist/constants.module.js +10 -10
- package/dist/useClipboard.main.js +1 -1
- package/dist/useClipboard.mjs +1 -1
- package/dist/useClipboard.module.js +1 -1
- package/dist/useDrag.main.js +38 -38
- package/dist/useDrag.mjs +38 -38
- package/dist/useDrag.module.js +38 -38
- package/dist/useDraggableItem.main.js +17 -17
- package/dist/useDraggableItem.mjs +17 -17
- package/dist/useDraggableItem.module.js +17 -17
- package/dist/useDrop.main.js +30 -30
- package/dist/useDrop.mjs +30 -30
- package/dist/useDrop.module.js +30 -30
- package/dist/useDropIndicator.main.js +17 -17
- package/dist/useDropIndicator.mjs +17 -17
- package/dist/useDropIndicator.module.js +17 -17
- package/dist/useDroppableCollection.main.js +83 -83
- package/dist/useDroppableCollection.mjs +83 -83
- package/dist/useDroppableCollection.module.js +83 -83
- package/dist/useDroppableItem.main.js +2 -2
- package/dist/useDroppableItem.mjs +2 -2
- package/dist/useDroppableItem.module.js +2 -2
- package/dist/useVirtualDrop.main.js +5 -5
- package/dist/useVirtualDrop.mjs +5 -5
- package/dist/useVirtualDrop.module.js +5 -5
- package/dist/utils.main.js +20 -20
- package/dist/utils.mjs +20 -20
- package/dist/utils.module.js +20 -20
- package/package.json +11 -11
|
@@ -40,11 +40,11 @@ function $67560de7c78cb232$export$aef80212ac99c003(item) {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
function $67560de7c78cb232$export$549dbcf8649bf3b2(target, stringFormatter) {
|
|
43
|
-
if ($67560de7c78cb232$var$dragSession) throw new Error(
|
|
43
|
+
if ($67560de7c78cb232$var$dragSession) throw new Error('Cannot begin dragging while already dragging');
|
|
44
44
|
$67560de7c78cb232$var$dragSession = new $67560de7c78cb232$var$DragSession(target, stringFormatter);
|
|
45
45
|
requestAnimationFrame(()=>{
|
|
46
46
|
$67560de7c78cb232$var$dragSession.setup();
|
|
47
|
-
if ((0, $7252cd45fc48c07c$export$1fb2158d224b542c)() ===
|
|
47
|
+
if ((0, $7252cd45fc48c07c$export$1fb2158d224b542c)() === 'keyboard') $67560de7c78cb232$var$dragSession.next();
|
|
48
48
|
});
|
|
49
49
|
for (let cb of $67560de7c78cb232$var$subscriptions)cb();
|
|
50
50
|
}
|
|
@@ -73,56 +73,56 @@ function $67560de7c78cb232$export$7454aff2e161f241(element) {
|
|
|
73
73
|
return false;
|
|
74
74
|
}
|
|
75
75
|
const $67560de7c78cb232$var$CANCELED_EVENTS = [
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
76
|
+
'pointerdown',
|
|
77
|
+
'pointermove',
|
|
78
|
+
'pointerenter',
|
|
79
|
+
'pointerleave',
|
|
80
|
+
'pointerover',
|
|
81
|
+
'pointerout',
|
|
82
|
+
'pointerup',
|
|
83
|
+
'mousedown',
|
|
84
|
+
'mousemove',
|
|
85
|
+
'mouseenter',
|
|
86
|
+
'mouseleave',
|
|
87
|
+
'mouseover',
|
|
88
|
+
'mouseout',
|
|
89
|
+
'mouseup',
|
|
90
|
+
'touchstart',
|
|
91
|
+
'touchmove',
|
|
92
|
+
'touchend',
|
|
93
|
+
'focusin',
|
|
94
|
+
'focusout'
|
|
95
95
|
];
|
|
96
96
|
const $67560de7c78cb232$var$CLICK_EVENTS = [
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
'pointerup',
|
|
98
|
+
'mouseup',
|
|
99
|
+
'touchend'
|
|
100
100
|
];
|
|
101
101
|
const $67560de7c78cb232$var$MESSAGES = {
|
|
102
|
-
keyboard:
|
|
103
|
-
touch:
|
|
104
|
-
virtual:
|
|
102
|
+
keyboard: 'dragStartedKeyboard',
|
|
103
|
+
touch: 'dragStartedTouch',
|
|
104
|
+
virtual: 'dragStartedVirtual'
|
|
105
105
|
};
|
|
106
106
|
class $67560de7c78cb232$var$DragSession {
|
|
107
107
|
setup() {
|
|
108
|
-
document.addEventListener(
|
|
109
|
-
document.addEventListener(
|
|
110
|
-
window.addEventListener(
|
|
111
|
-
window.addEventListener(
|
|
112
|
-
document.addEventListener(
|
|
113
|
-
document.addEventListener(
|
|
108
|
+
document.addEventListener('keydown', this.onKeyDown, true);
|
|
109
|
+
document.addEventListener('keyup', this.onKeyUp, true);
|
|
110
|
+
window.addEventListener('focus', this.onFocus, true);
|
|
111
|
+
window.addEventListener('blur', this.onBlur, true);
|
|
112
|
+
document.addEventListener('click', this.onClick, true);
|
|
113
|
+
document.addEventListener('pointerdown', this.onPointerDown, true);
|
|
114
114
|
for (let event of $67560de7c78cb232$var$CANCELED_EVENTS)document.addEventListener(event, this.cancelEvent, true);
|
|
115
115
|
this.mutationObserver = new MutationObserver(()=>this.updateValidDropTargets());
|
|
116
116
|
this.updateValidDropTargets();
|
|
117
117
|
(0, $irqIb$announce)(this.stringFormatter.format($67560de7c78cb232$var$MESSAGES[(0, $7252cd45fc48c07c$export$1fb2158d224b542c)()]));
|
|
118
118
|
}
|
|
119
119
|
teardown() {
|
|
120
|
-
document.removeEventListener(
|
|
121
|
-
document.removeEventListener(
|
|
122
|
-
window.removeEventListener(
|
|
123
|
-
window.removeEventListener(
|
|
124
|
-
document.removeEventListener(
|
|
125
|
-
document.removeEventListener(
|
|
120
|
+
document.removeEventListener('keydown', this.onKeyDown, true);
|
|
121
|
+
document.removeEventListener('keyup', this.onKeyUp, true);
|
|
122
|
+
window.removeEventListener('focus', this.onFocus, true);
|
|
123
|
+
window.removeEventListener('blur', this.onBlur, true);
|
|
124
|
+
document.removeEventListener('click', this.onClick, true);
|
|
125
|
+
document.removeEventListener('pointerdown', this.onPointerDown, true);
|
|
126
126
|
for (let event of $67560de7c78cb232$var$CANCELED_EVENTS)document.removeEventListener(event, this.cancelEvent, true);
|
|
127
127
|
this.mutationObserver.disconnect();
|
|
128
128
|
this.restoreAriaHidden();
|
|
@@ -130,19 +130,19 @@ class $67560de7c78cb232$var$DragSession {
|
|
|
130
130
|
onKeyDown(e) {
|
|
131
131
|
var _this_currentDropTarget;
|
|
132
132
|
this.cancelEvent(e);
|
|
133
|
-
if (e.key ===
|
|
133
|
+
if (e.key === 'Escape') {
|
|
134
134
|
this.cancel();
|
|
135
135
|
return;
|
|
136
136
|
}
|
|
137
|
-
if (e.key ===
|
|
137
|
+
if (e.key === 'Tab' && !(e.metaKey || e.altKey || e.ctrlKey)) {
|
|
138
138
|
if (e.shiftKey) this.previous();
|
|
139
139
|
else this.next();
|
|
140
140
|
}
|
|
141
|
-
if (typeof ((_this_currentDropTarget = this.currentDropTarget) === null || _this_currentDropTarget === void 0 ? void 0 : _this_currentDropTarget.onKeyDown) ===
|
|
141
|
+
if (typeof ((_this_currentDropTarget = this.currentDropTarget) === null || _this_currentDropTarget === void 0 ? void 0 : _this_currentDropTarget.onKeyDown) === 'function') this.currentDropTarget.onKeyDown(e, this.dragTarget);
|
|
142
142
|
}
|
|
143
143
|
onKeyUp(e) {
|
|
144
144
|
this.cancelEvent(e);
|
|
145
|
-
if (e.key ===
|
|
145
|
+
if (e.key === 'Enter') {
|
|
146
146
|
if (e.altKey) this.activate();
|
|
147
147
|
else this.drop();
|
|
148
148
|
}
|
|
@@ -194,7 +194,7 @@ class $67560de7c78cb232$var$DragSession {
|
|
|
194
194
|
cancelEvent(e) {
|
|
195
195
|
var _this_dragTarget;
|
|
196
196
|
// Allow focusin and focusout on the drag target so focus ring works properly.
|
|
197
|
-
if ((e.type ===
|
|
197
|
+
if ((e.type === 'focusin' || e.type === 'focusout') && e.target === ((_this_dragTarget = this.dragTarget) === null || _this_dragTarget === void 0 ? void 0 : _this_dragTarget.element)) return;
|
|
198
198
|
// Allow default for events that might cancel a click event
|
|
199
199
|
if (!$67560de7c78cb232$var$CLICK_EVENTS.includes(e.type)) e.preventDefault();
|
|
200
200
|
e.stopPropagation();
|
|
@@ -219,7 +219,7 @@ class $67560de7c78cb232$var$DragSession {
|
|
|
219
219
|
let validDropItems = [
|
|
220
220
|
...$67560de7c78cb232$var$dropItems.values()
|
|
221
221
|
].filter((item)=>{
|
|
222
|
-
if (typeof item.getDropOperation ===
|
|
222
|
+
if (typeof item.getDropOperation === 'function') return item.getDropOperation(types, this.dragTarget.allowedDropOperations) !== 'cancel';
|
|
223
223
|
return true;
|
|
224
224
|
});
|
|
225
225
|
// Filter out drop targets that contain valid items. We don't want to stop hiding elements
|
|
@@ -234,7 +234,7 @@ class $67560de7c78cb232$var$DragSession {
|
|
|
234
234
|
subtree: true,
|
|
235
235
|
attributes: true,
|
|
236
236
|
attributeFilter: [
|
|
237
|
-
|
|
237
|
+
'aria-hidden'
|
|
238
238
|
]
|
|
239
239
|
});
|
|
240
240
|
}
|
|
@@ -295,20 +295,20 @@ class $67560de7c78cb232$var$DragSession {
|
|
|
295
295
|
}
|
|
296
296
|
setCurrentDropTarget(dropTarget, item) {
|
|
297
297
|
if (dropTarget !== this.currentDropTarget) {
|
|
298
|
-
if (this.currentDropTarget && typeof this.currentDropTarget.onDropExit ===
|
|
298
|
+
if (this.currentDropTarget && typeof this.currentDropTarget.onDropExit === 'function') {
|
|
299
299
|
let rect = this.currentDropTarget.element.getBoundingClientRect();
|
|
300
300
|
this.currentDropTarget.onDropExit({
|
|
301
|
-
type:
|
|
301
|
+
type: 'dropexit',
|
|
302
302
|
x: rect.left + rect.width / 2,
|
|
303
303
|
y: rect.top + rect.height / 2
|
|
304
304
|
});
|
|
305
305
|
}
|
|
306
306
|
this.currentDropTarget = dropTarget;
|
|
307
307
|
if (dropTarget) {
|
|
308
|
-
if (typeof dropTarget.onDropEnter ===
|
|
308
|
+
if (typeof dropTarget.onDropEnter === 'function') {
|
|
309
309
|
let rect = dropTarget.element.getBoundingClientRect();
|
|
310
310
|
dropTarget.onDropEnter({
|
|
311
|
-
type:
|
|
311
|
+
type: 'dropenter',
|
|
312
312
|
x: rect.left + rect.width / 2,
|
|
313
313
|
y: rect.top + rect.height / 2
|
|
314
314
|
}, this.dragTarget);
|
|
@@ -317,13 +317,13 @@ class $67560de7c78cb232$var$DragSession {
|
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
if (item !== this.currentDropItem) {
|
|
320
|
-
if (item && typeof this.currentDropTarget.onDropTargetEnter ===
|
|
320
|
+
if (item && typeof this.currentDropTarget.onDropTargetEnter === 'function') this.currentDropTarget.onDropTargetEnter(item === null || item === void 0 ? void 0 : item.target);
|
|
321
321
|
item === null || item === void 0 ? void 0 : item.element.focus();
|
|
322
322
|
this.currentDropItem = item;
|
|
323
323
|
// Announce first drop target after drag start announcement finishes.
|
|
324
324
|
// Otherwise, it will never get announced because drag start announcement is assertive.
|
|
325
325
|
if (!this.initialFocused) {
|
|
326
|
-
(0, $irqIb$announce)(item === null || item === void 0 ? void 0 : item.element.getAttribute(
|
|
326
|
+
(0, $irqIb$announce)(item === null || item === void 0 ? void 0 : item.element.getAttribute('aria-label'), 'polite');
|
|
327
327
|
this.initialFocused = true;
|
|
328
328
|
}
|
|
329
329
|
}
|
|
@@ -331,14 +331,14 @@ class $67560de7c78cb232$var$DragSession {
|
|
|
331
331
|
end() {
|
|
332
332
|
this.teardown();
|
|
333
333
|
$67560de7c78cb232$var$endDragging();
|
|
334
|
-
if (typeof this.dragTarget.onDragEnd ===
|
|
335
|
-
let target = this.currentDropTarget && this.dropOperation !==
|
|
334
|
+
if (typeof this.dragTarget.onDragEnd === 'function') {
|
|
335
|
+
let target = this.currentDropTarget && this.dropOperation !== 'cancel' ? this.currentDropTarget : this.dragTarget;
|
|
336
336
|
let rect = target.element.getBoundingClientRect();
|
|
337
337
|
this.dragTarget.onDragEnd({
|
|
338
|
-
type:
|
|
338
|
+
type: 'dragend',
|
|
339
339
|
x: rect.x + rect.width / 2,
|
|
340
340
|
y: rect.y + rect.height / 2,
|
|
341
|
-
dropOperation: this.dropOperation ||
|
|
341
|
+
dropOperation: this.dropOperation || 'cancel'
|
|
342
342
|
});
|
|
343
343
|
}
|
|
344
344
|
// Blur and re-focus the drop target so that the focus ring appears.
|
|
@@ -346,8 +346,8 @@ class $67560de7c78cb232$var$DragSession {
|
|
|
346
346
|
// Since we cancel all focus events in drag sessions, refire blur to make sure state gets updated so drag target doesn't think it's still focused
|
|
347
347
|
// i.e. When you from one list to another during a drag session, we need the blur to fire on the first list after the drag.
|
|
348
348
|
if (!this.dragTarget.element.contains(this.currentDropTarget.element)) {
|
|
349
|
-
this.dragTarget.element.dispatchEvent(new FocusEvent(
|
|
350
|
-
this.dragTarget.element.dispatchEvent(new FocusEvent(
|
|
349
|
+
this.dragTarget.element.dispatchEvent(new FocusEvent('blur'));
|
|
350
|
+
this.dragTarget.element.dispatchEvent(new FocusEvent('focusout', {
|
|
351
351
|
bubbles: true
|
|
352
352
|
}));
|
|
353
353
|
}
|
|
@@ -363,30 +363,30 @@ class $67560de7c78cb232$var$DragSession {
|
|
|
363
363
|
this.setCurrentDropTarget(null);
|
|
364
364
|
this.end();
|
|
365
365
|
if (!this.dragTarget.element.closest('[aria-hidden="true"]')) this.dragTarget.element.focus();
|
|
366
|
-
(0, $irqIb$announce)(this.stringFormatter.format(
|
|
366
|
+
(0, $irqIb$announce)(this.stringFormatter.format('dropCanceled'));
|
|
367
367
|
}
|
|
368
368
|
drop(item) {
|
|
369
369
|
if (!this.currentDropTarget) {
|
|
370
370
|
this.cancel();
|
|
371
371
|
return;
|
|
372
372
|
}
|
|
373
|
-
if (typeof (item === null || item === void 0 ? void 0 : item.getDropOperation) ===
|
|
373
|
+
if (typeof (item === null || item === void 0 ? void 0 : item.getDropOperation) === 'function') {
|
|
374
374
|
let types = (0, $7252cd45fc48c07c$export$e1d41611756c6326)(this.dragTarget.items);
|
|
375
375
|
this.dropOperation = item.getDropOperation(types, this.dragTarget.allowedDropOperations);
|
|
376
|
-
} else if (typeof this.currentDropTarget.getDropOperation ===
|
|
376
|
+
} else if (typeof this.currentDropTarget.getDropOperation === 'function') {
|
|
377
377
|
let types = (0, $7252cd45fc48c07c$export$e1d41611756c6326)(this.dragTarget.items);
|
|
378
378
|
this.dropOperation = this.currentDropTarget.getDropOperation(types, this.dragTarget.allowedDropOperations);
|
|
379
379
|
} else // TODO: show menu ??
|
|
380
380
|
this.dropOperation = this.dragTarget.allowedDropOperations[0];
|
|
381
|
-
if (typeof this.currentDropTarget.onDrop ===
|
|
381
|
+
if (typeof this.currentDropTarget.onDrop === 'function') {
|
|
382
382
|
let items = this.dragTarget.items.map((item)=>({
|
|
383
|
-
kind:
|
|
383
|
+
kind: 'text',
|
|
384
384
|
types: new Set(Object.keys(item)),
|
|
385
385
|
getText: (type)=>Promise.resolve(item[type])
|
|
386
386
|
}));
|
|
387
387
|
let rect = this.currentDropTarget.element.getBoundingClientRect();
|
|
388
388
|
this.currentDropTarget.onDrop({
|
|
389
|
-
type:
|
|
389
|
+
type: 'drop',
|
|
390
390
|
x: rect.left + rect.width / 2,
|
|
391
391
|
y: rect.top + rect.height / 2,
|
|
392
392
|
items: items,
|
|
@@ -394,13 +394,13 @@ class $67560de7c78cb232$var$DragSession {
|
|
|
394
394
|
}, item === null || item === void 0 ? void 0 : item.target);
|
|
395
395
|
}
|
|
396
396
|
this.end();
|
|
397
|
-
(0, $irqIb$announce)(this.stringFormatter.format(
|
|
397
|
+
(0, $irqIb$announce)(this.stringFormatter.format('dropComplete'));
|
|
398
398
|
}
|
|
399
399
|
activate() {
|
|
400
|
-
if (this.currentDropTarget && typeof this.currentDropTarget.onDropActivate ===
|
|
400
|
+
if (this.currentDropTarget && typeof this.currentDropTarget.onDropActivate === 'function') {
|
|
401
401
|
let rect = this.currentDropTarget.element.getBoundingClientRect();
|
|
402
402
|
this.currentDropTarget.onDropActivate({
|
|
403
|
-
type:
|
|
403
|
+
type: 'dropactivate',
|
|
404
404
|
x: rect.left + rect.width / 2,
|
|
405
405
|
y: rect.top + rect.height / 2
|
|
406
406
|
});
|
|
@@ -425,7 +425,7 @@ function $67560de7c78cb232$var$findValidDropTargets(options) {
|
|
|
425
425
|
...$67560de7c78cb232$var$dropTargets.values()
|
|
426
426
|
].filter((target)=>{
|
|
427
427
|
if (target.element.closest('[aria-hidden="true"]')) return false;
|
|
428
|
-
if (typeof target.getDropOperation ===
|
|
428
|
+
if (typeof target.getDropOperation === 'function') return target.getDropOperation(types, options.allowedDropOperations) !== 'cancel';
|
|
429
429
|
return true;
|
|
430
430
|
});
|
|
431
431
|
}
|
package/dist/DragPreview.main.js
CHANGED
|
@@ -46,7 +46,7 @@ function $2dccaca1f4baa446$var$DragPreview(props, ref) {
|
|
|
46
46
|
return /*#__PURE__*/ (0, ($parcel$interopDefault($l6JIF$react))).createElement("div", {
|
|
47
47
|
style: {
|
|
48
48
|
zIndex: -100,
|
|
49
|
-
position:
|
|
49
|
+
position: 'absolute',
|
|
50
50
|
top: 0,
|
|
51
51
|
left: -100000
|
|
52
52
|
},
|
package/dist/DragPreview.mjs
CHANGED
|
@@ -6,40 +6,40 @@ function $parcel$export(e, n, v, s) {
|
|
|
6
6
|
$parcel$export(module.exports, "ListDropTargetDelegate", () => $2268795bbb597ecb$export$fbd65d14c79e28cc);
|
|
7
7
|
class $2268795bbb597ecb$export$fbd65d14c79e28cc {
|
|
8
8
|
getPrimaryStart(rect) {
|
|
9
|
-
return this.orientation ===
|
|
9
|
+
return this.orientation === 'horizontal' ? rect.left : rect.top;
|
|
10
10
|
}
|
|
11
11
|
getPrimaryEnd(rect) {
|
|
12
|
-
return this.orientation ===
|
|
12
|
+
return this.orientation === 'horizontal' ? rect.right : rect.bottom;
|
|
13
13
|
}
|
|
14
14
|
getSecondaryStart(rect) {
|
|
15
|
-
return this.orientation ===
|
|
15
|
+
return this.orientation === 'horizontal' ? rect.top : rect.left;
|
|
16
16
|
}
|
|
17
17
|
getSecondaryEnd(rect) {
|
|
18
|
-
return this.orientation ===
|
|
18
|
+
return this.orientation === 'horizontal' ? rect.bottom : rect.right;
|
|
19
19
|
}
|
|
20
20
|
getFlowStart(rect) {
|
|
21
|
-
return this.layout ===
|
|
21
|
+
return this.layout === 'stack' ? this.getPrimaryStart(rect) : this.getSecondaryStart(rect);
|
|
22
22
|
}
|
|
23
23
|
getFlowEnd(rect) {
|
|
24
|
-
return this.layout ===
|
|
24
|
+
return this.layout === 'stack' ? this.getPrimaryEnd(rect) : this.getSecondaryEnd(rect);
|
|
25
25
|
}
|
|
26
26
|
getFlowSize(rect) {
|
|
27
27
|
return this.getFlowEnd(rect) - this.getFlowStart(rect);
|
|
28
28
|
}
|
|
29
29
|
getDropTargetFromPoint(x, y, isValidDropTarget) {
|
|
30
30
|
if (this.collection.size === 0) return {
|
|
31
|
-
type:
|
|
31
|
+
type: 'root'
|
|
32
32
|
};
|
|
33
33
|
let rect = this.ref.current.getBoundingClientRect();
|
|
34
|
-
let primary = this.orientation ===
|
|
35
|
-
let secondary = this.orientation ===
|
|
34
|
+
let primary = this.orientation === 'horizontal' ? x : y;
|
|
35
|
+
let secondary = this.orientation === 'horizontal' ? y : x;
|
|
36
36
|
primary += this.getPrimaryStart(rect);
|
|
37
37
|
secondary += this.getSecondaryStart(rect);
|
|
38
|
-
let flow = this.layout ===
|
|
39
|
-
let isPrimaryRTL = this.orientation ===
|
|
40
|
-
let isSecondaryRTL = this.layout ===
|
|
41
|
-
let isFlowRTL = this.layout ===
|
|
42
|
-
let elements = this.ref.current.querySelectorAll(
|
|
38
|
+
let flow = this.layout === 'stack' ? primary : secondary;
|
|
39
|
+
let isPrimaryRTL = this.orientation === 'horizontal' && this.direction === 'rtl';
|
|
40
|
+
let isSecondaryRTL = this.layout === 'grid' && this.orientation === 'vertical' && this.direction === 'rtl';
|
|
41
|
+
let isFlowRTL = this.layout === 'stack' ? isPrimaryRTL : isSecondaryRTL;
|
|
42
|
+
let elements = this.ref.current.querySelectorAll('[data-key]');
|
|
43
43
|
let elementMap = new Map();
|
|
44
44
|
for (let item of elements)if (item instanceof HTMLElement) elementMap.set(item.dataset.key, item);
|
|
45
45
|
let items = [
|
|
@@ -62,32 +62,32 @@ class $2268795bbb597ecb$export$fbd65d14c79e28cc {
|
|
|
62
62
|
else if (secondary > this.getSecondaryEnd(rect)) update(!isSecondaryRTL);
|
|
63
63
|
else {
|
|
64
64
|
let target = {
|
|
65
|
-
type:
|
|
65
|
+
type: 'item',
|
|
66
66
|
key: item.key,
|
|
67
|
-
dropPosition:
|
|
67
|
+
dropPosition: 'on'
|
|
68
68
|
};
|
|
69
69
|
if (isValidDropTarget(target)) {
|
|
70
70
|
// Otherwise, if dropping on the item is accepted, try the before/after positions if within 5px
|
|
71
71
|
// of the start or end of the item.
|
|
72
72
|
if (flow <= this.getFlowStart(rect) + 5 && isValidDropTarget({
|
|
73
73
|
...target,
|
|
74
|
-
dropPosition:
|
|
75
|
-
})) target.dropPosition = isFlowRTL ?
|
|
74
|
+
dropPosition: 'before'
|
|
75
|
+
})) target.dropPosition = isFlowRTL ? 'after' : 'before';
|
|
76
76
|
else if (flow >= this.getFlowEnd(rect) - 5 && isValidDropTarget({
|
|
77
77
|
...target,
|
|
78
|
-
dropPosition:
|
|
79
|
-
})) target.dropPosition = isFlowRTL ?
|
|
78
|
+
dropPosition: 'after'
|
|
79
|
+
})) target.dropPosition = isFlowRTL ? 'before' : 'after';
|
|
80
80
|
} else {
|
|
81
81
|
// If dropping on the item isn't accepted, try the target before or after depending on the position.
|
|
82
82
|
let mid = this.getFlowStart(rect) + this.getFlowSize(rect) / 2;
|
|
83
83
|
if (flow <= mid && isValidDropTarget({
|
|
84
84
|
...target,
|
|
85
|
-
dropPosition:
|
|
86
|
-
})) target.dropPosition = isFlowRTL ?
|
|
85
|
+
dropPosition: 'before'
|
|
86
|
+
})) target.dropPosition = isFlowRTL ? 'after' : 'before';
|
|
87
87
|
else if (flow >= mid && isValidDropTarget({
|
|
88
88
|
...target,
|
|
89
|
-
dropPosition:
|
|
90
|
-
})) target.dropPosition = isFlowRTL ?
|
|
89
|
+
dropPosition: 'after'
|
|
90
|
+
})) target.dropPosition = isFlowRTL ? 'before' : 'after';
|
|
91
91
|
}
|
|
92
92
|
return target;
|
|
93
93
|
}
|
|
@@ -96,22 +96,22 @@ class $2268795bbb597ecb$export$fbd65d14c79e28cc {
|
|
|
96
96
|
let element = elementMap.get(String(item.key));
|
|
97
97
|
rect = element.getBoundingClientRect();
|
|
98
98
|
if (primary < this.getPrimaryStart(rect) || Math.abs(flow - this.getFlowStart(rect)) < Math.abs(flow - this.getFlowEnd(rect))) return {
|
|
99
|
-
type:
|
|
99
|
+
type: 'item',
|
|
100
100
|
key: item.key,
|
|
101
|
-
dropPosition: isFlowRTL ?
|
|
101
|
+
dropPosition: isFlowRTL ? 'after' : 'before'
|
|
102
102
|
};
|
|
103
103
|
return {
|
|
104
|
-
type:
|
|
104
|
+
type: 'item',
|
|
105
105
|
key: item.key,
|
|
106
|
-
dropPosition: isFlowRTL ?
|
|
106
|
+
dropPosition: isFlowRTL ? 'before' : 'after'
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
109
|
constructor(collection, ref, options){
|
|
110
110
|
this.collection = collection;
|
|
111
111
|
this.ref = ref;
|
|
112
|
-
this.layout = (options === null || options === void 0 ? void 0 : options.layout) ||
|
|
113
|
-
this.orientation = (options === null || options === void 0 ? void 0 : options.orientation) ||
|
|
114
|
-
this.direction = (options === null || options === void 0 ? void 0 : options.direction) ||
|
|
112
|
+
this.layout = (options === null || options === void 0 ? void 0 : options.layout) || 'stack';
|
|
113
|
+
this.orientation = (options === null || options === void 0 ? void 0 : options.orientation) || 'vertical';
|
|
114
|
+
this.direction = (options === null || options === void 0 ? void 0 : options.direction) || 'ltr';
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
|
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
class $3ca85212bf8898e4$export$fbd65d14c79e28cc {
|
|
2
2
|
getPrimaryStart(rect) {
|
|
3
|
-
return this.orientation ===
|
|
3
|
+
return this.orientation === 'horizontal' ? rect.left : rect.top;
|
|
4
4
|
}
|
|
5
5
|
getPrimaryEnd(rect) {
|
|
6
|
-
return this.orientation ===
|
|
6
|
+
return this.orientation === 'horizontal' ? rect.right : rect.bottom;
|
|
7
7
|
}
|
|
8
8
|
getSecondaryStart(rect) {
|
|
9
|
-
return this.orientation ===
|
|
9
|
+
return this.orientation === 'horizontal' ? rect.top : rect.left;
|
|
10
10
|
}
|
|
11
11
|
getSecondaryEnd(rect) {
|
|
12
|
-
return this.orientation ===
|
|
12
|
+
return this.orientation === 'horizontal' ? rect.bottom : rect.right;
|
|
13
13
|
}
|
|
14
14
|
getFlowStart(rect) {
|
|
15
|
-
return this.layout ===
|
|
15
|
+
return this.layout === 'stack' ? this.getPrimaryStart(rect) : this.getSecondaryStart(rect);
|
|
16
16
|
}
|
|
17
17
|
getFlowEnd(rect) {
|
|
18
|
-
return this.layout ===
|
|
18
|
+
return this.layout === 'stack' ? this.getPrimaryEnd(rect) : this.getSecondaryEnd(rect);
|
|
19
19
|
}
|
|
20
20
|
getFlowSize(rect) {
|
|
21
21
|
return this.getFlowEnd(rect) - this.getFlowStart(rect);
|
|
22
22
|
}
|
|
23
23
|
getDropTargetFromPoint(x, y, isValidDropTarget) {
|
|
24
24
|
if (this.collection.size === 0) return {
|
|
25
|
-
type:
|
|
25
|
+
type: 'root'
|
|
26
26
|
};
|
|
27
27
|
let rect = this.ref.current.getBoundingClientRect();
|
|
28
|
-
let primary = this.orientation ===
|
|
29
|
-
let secondary = this.orientation ===
|
|
28
|
+
let primary = this.orientation === 'horizontal' ? x : y;
|
|
29
|
+
let secondary = this.orientation === 'horizontal' ? y : x;
|
|
30
30
|
primary += this.getPrimaryStart(rect);
|
|
31
31
|
secondary += this.getSecondaryStart(rect);
|
|
32
|
-
let flow = this.layout ===
|
|
33
|
-
let isPrimaryRTL = this.orientation ===
|
|
34
|
-
let isSecondaryRTL = this.layout ===
|
|
35
|
-
let isFlowRTL = this.layout ===
|
|
36
|
-
let elements = this.ref.current.querySelectorAll(
|
|
32
|
+
let flow = this.layout === 'stack' ? primary : secondary;
|
|
33
|
+
let isPrimaryRTL = this.orientation === 'horizontal' && this.direction === 'rtl';
|
|
34
|
+
let isSecondaryRTL = this.layout === 'grid' && this.orientation === 'vertical' && this.direction === 'rtl';
|
|
35
|
+
let isFlowRTL = this.layout === 'stack' ? isPrimaryRTL : isSecondaryRTL;
|
|
36
|
+
let elements = this.ref.current.querySelectorAll('[data-key]');
|
|
37
37
|
let elementMap = new Map();
|
|
38
38
|
for (let item of elements)if (item instanceof HTMLElement) elementMap.set(item.dataset.key, item);
|
|
39
39
|
let items = [
|
|
@@ -56,32 +56,32 @@ class $3ca85212bf8898e4$export$fbd65d14c79e28cc {
|
|
|
56
56
|
else if (secondary > this.getSecondaryEnd(rect)) update(!isSecondaryRTL);
|
|
57
57
|
else {
|
|
58
58
|
let target = {
|
|
59
|
-
type:
|
|
59
|
+
type: 'item',
|
|
60
60
|
key: item.key,
|
|
61
|
-
dropPosition:
|
|
61
|
+
dropPosition: 'on'
|
|
62
62
|
};
|
|
63
63
|
if (isValidDropTarget(target)) {
|
|
64
64
|
// Otherwise, if dropping on the item is accepted, try the before/after positions if within 5px
|
|
65
65
|
// of the start or end of the item.
|
|
66
66
|
if (flow <= this.getFlowStart(rect) + 5 && isValidDropTarget({
|
|
67
67
|
...target,
|
|
68
|
-
dropPosition:
|
|
69
|
-
})) target.dropPosition = isFlowRTL ?
|
|
68
|
+
dropPosition: 'before'
|
|
69
|
+
})) target.dropPosition = isFlowRTL ? 'after' : 'before';
|
|
70
70
|
else if (flow >= this.getFlowEnd(rect) - 5 && isValidDropTarget({
|
|
71
71
|
...target,
|
|
72
|
-
dropPosition:
|
|
73
|
-
})) target.dropPosition = isFlowRTL ?
|
|
72
|
+
dropPosition: 'after'
|
|
73
|
+
})) target.dropPosition = isFlowRTL ? 'before' : 'after';
|
|
74
74
|
} else {
|
|
75
75
|
// If dropping on the item isn't accepted, try the target before or after depending on the position.
|
|
76
76
|
let mid = this.getFlowStart(rect) + this.getFlowSize(rect) / 2;
|
|
77
77
|
if (flow <= mid && isValidDropTarget({
|
|
78
78
|
...target,
|
|
79
|
-
dropPosition:
|
|
80
|
-
})) target.dropPosition = isFlowRTL ?
|
|
79
|
+
dropPosition: 'before'
|
|
80
|
+
})) target.dropPosition = isFlowRTL ? 'after' : 'before';
|
|
81
81
|
else if (flow >= mid && isValidDropTarget({
|
|
82
82
|
...target,
|
|
83
|
-
dropPosition:
|
|
84
|
-
})) target.dropPosition = isFlowRTL ?
|
|
83
|
+
dropPosition: 'after'
|
|
84
|
+
})) target.dropPosition = isFlowRTL ? 'before' : 'after';
|
|
85
85
|
}
|
|
86
86
|
return target;
|
|
87
87
|
}
|
|
@@ -90,22 +90,22 @@ class $3ca85212bf8898e4$export$fbd65d14c79e28cc {
|
|
|
90
90
|
let element = elementMap.get(String(item.key));
|
|
91
91
|
rect = element.getBoundingClientRect();
|
|
92
92
|
if (primary < this.getPrimaryStart(rect) || Math.abs(flow - this.getFlowStart(rect)) < Math.abs(flow - this.getFlowEnd(rect))) return {
|
|
93
|
-
type:
|
|
93
|
+
type: 'item',
|
|
94
94
|
key: item.key,
|
|
95
|
-
dropPosition: isFlowRTL ?
|
|
95
|
+
dropPosition: isFlowRTL ? 'after' : 'before'
|
|
96
96
|
};
|
|
97
97
|
return {
|
|
98
|
-
type:
|
|
98
|
+
type: 'item',
|
|
99
99
|
key: item.key,
|
|
100
|
-
dropPosition: isFlowRTL ?
|
|
100
|
+
dropPosition: isFlowRTL ? 'before' : 'after'
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
103
|
constructor(collection, ref, options){
|
|
104
104
|
this.collection = collection;
|
|
105
105
|
this.ref = ref;
|
|
106
|
-
this.layout = (options === null || options === void 0 ? void 0 : options.layout) ||
|
|
107
|
-
this.orientation = (options === null || options === void 0 ? void 0 : options.orientation) ||
|
|
108
|
-
this.direction = (options === null || options === void 0 ? void 0 : options.direction) ||
|
|
106
|
+
this.layout = (options === null || options === void 0 ? void 0 : options.layout) || 'stack';
|
|
107
|
+
this.orientation = (options === null || options === void 0 ? void 0 : options.orientation) || 'vertical';
|
|
108
|
+
this.direction = (options === null || options === void 0 ? void 0 : options.direction) || 'ltr';
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|