@react-aria/dnd 3.11.5 → 3.12.0
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/import.mjs +8 -18
- package/dist/main.js +22 -32
- package/dist/main.js.map +1 -1
- package/dist/module.js +8 -18
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +13 -0
- package/package.json +16 -21
- package/src/index.ts +13 -56
- package/dist/DragManager.main.js +0 -519
- package/dist/DragManager.main.js.map +0 -1
- package/dist/DragManager.mjs +0 -510
- package/dist/DragManager.module.js +0 -510
- package/dist/DragManager.module.js.map +0 -1
- package/dist/DragPreview.main.js +0 -73
- package/dist/DragPreview.main.js.map +0 -1
- package/dist/DragPreview.mjs +0 -64
- package/dist/DragPreview.module.js +0 -64
- package/dist/DragPreview.module.js.map +0 -1
- package/dist/DropTargetKeyboardNavigation.main.js +0 -205
- package/dist/DropTargetKeyboardNavigation.main.js.map +0 -1
- package/dist/DropTargetKeyboardNavigation.mjs +0 -200
- package/dist/DropTargetKeyboardNavigation.module.js +0 -200
- package/dist/DropTargetKeyboardNavigation.module.js.map +0 -1
- package/dist/ListDropTargetDelegate.main.js +0 -129
- package/dist/ListDropTargetDelegate.main.js.map +0 -1
- package/dist/ListDropTargetDelegate.mjs +0 -124
- package/dist/ListDropTargetDelegate.module.js +0 -124
- package/dist/ListDropTargetDelegate.module.js.map +0 -1
- package/dist/ar-AE.main.js +0 -44
- package/dist/ar-AE.main.js.map +0 -1
- package/dist/ar-AE.mjs +0 -46
- package/dist/ar-AE.module.js +0 -46
- package/dist/ar-AE.module.js.map +0 -1
- package/dist/bg-BG.main.js +0 -44
- package/dist/bg-BG.main.js.map +0 -1
- package/dist/bg-BG.mjs +0 -46
- package/dist/bg-BG.module.js +0 -46
- package/dist/bg-BG.module.js.map +0 -1
- package/dist/constants.main.js +0 -64
- package/dist/constants.main.js.map +0 -1
- package/dist/constants.mjs +0 -52
- package/dist/constants.module.js +0 -52
- package/dist/constants.module.js.map +0 -1
- package/dist/cs-CZ.main.js +0 -45
- package/dist/cs-CZ.main.js.map +0 -1
- package/dist/cs-CZ.mjs +0 -47
- package/dist/cs-CZ.module.js +0 -47
- package/dist/cs-CZ.module.js.map +0 -1
- package/dist/da-DK.main.js +0 -44
- package/dist/da-DK.main.js.map +0 -1
- package/dist/da-DK.mjs +0 -46
- package/dist/da-DK.module.js +0 -46
- package/dist/da-DK.module.js.map +0 -1
- package/dist/de-DE.main.js +0 -44
- package/dist/de-DE.main.js.map +0 -1
- package/dist/de-DE.mjs +0 -46
- package/dist/de-DE.module.js +0 -46
- package/dist/de-DE.module.js.map +0 -1
- package/dist/el-GR.main.js +0 -44
- package/dist/el-GR.main.js.map +0 -1
- package/dist/el-GR.mjs +0 -46
- package/dist/el-GR.module.js +0 -46
- package/dist/el-GR.module.js.map +0 -1
- package/dist/en-US.main.js +0 -44
- package/dist/en-US.main.js.map +0 -1
- package/dist/en-US.mjs +0 -46
- package/dist/en-US.module.js +0 -46
- package/dist/en-US.module.js.map +0 -1
- package/dist/es-ES.main.js +0 -44
- package/dist/es-ES.main.js.map +0 -1
- package/dist/es-ES.mjs +0 -46
- package/dist/es-ES.module.js +0 -46
- package/dist/es-ES.module.js.map +0 -1
- package/dist/et-EE.main.js +0 -44
- package/dist/et-EE.main.js.map +0 -1
- package/dist/et-EE.mjs +0 -46
- package/dist/et-EE.module.js +0 -46
- package/dist/et-EE.module.js.map +0 -1
- package/dist/fi-FI.main.js +0 -44
- package/dist/fi-FI.main.js.map +0 -1
- package/dist/fi-FI.mjs +0 -46
- package/dist/fi-FI.module.js +0 -46
- package/dist/fi-FI.module.js.map +0 -1
- package/dist/fr-FR.main.js +0 -44
- package/dist/fr-FR.main.js.map +0 -1
- package/dist/fr-FR.mjs +0 -46
- package/dist/fr-FR.module.js +0 -46
- package/dist/fr-FR.module.js.map +0 -1
- package/dist/he-IL.main.js +0 -44
- package/dist/he-IL.main.js.map +0 -1
- package/dist/he-IL.mjs +0 -46
- package/dist/he-IL.module.js +0 -46
- package/dist/he-IL.module.js.map +0 -1
- package/dist/hr-HR.main.js +0 -44
- package/dist/hr-HR.main.js.map +0 -1
- package/dist/hr-HR.mjs +0 -46
- package/dist/hr-HR.module.js +0 -46
- package/dist/hr-HR.module.js.map +0 -1
- package/dist/hu-HU.main.js +0 -44
- package/dist/hu-HU.main.js.map +0 -1
- package/dist/hu-HU.mjs +0 -46
- package/dist/hu-HU.module.js +0 -46
- package/dist/hu-HU.module.js.map +0 -1
- package/dist/intlStrings.main.js +0 -108
- package/dist/intlStrings.main.js.map +0 -1
- package/dist/intlStrings.mjs +0 -110
- package/dist/intlStrings.module.js +0 -110
- package/dist/intlStrings.module.js.map +0 -1
- package/dist/it-IT.main.js +0 -44
- package/dist/it-IT.main.js.map +0 -1
- package/dist/it-IT.mjs +0 -46
- package/dist/it-IT.module.js +0 -46
- package/dist/it-IT.module.js.map +0 -1
- package/dist/ja-JP.main.js +0 -44
- package/dist/ja-JP.main.js.map +0 -1
- package/dist/ja-JP.mjs +0 -46
- package/dist/ja-JP.module.js +0 -46
- package/dist/ja-JP.module.js.map +0 -1
- package/dist/ko-KR.main.js +0 -44
- package/dist/ko-KR.main.js.map +0 -1
- package/dist/ko-KR.mjs +0 -46
- package/dist/ko-KR.module.js +0 -46
- package/dist/ko-KR.module.js.map +0 -1
- package/dist/lt-LT.main.js +0 -44
- package/dist/lt-LT.main.js.map +0 -1
- package/dist/lt-LT.mjs +0 -46
- package/dist/lt-LT.module.js +0 -46
- package/dist/lt-LT.module.js.map +0 -1
- package/dist/lv-LV.main.js +0 -44
- package/dist/lv-LV.main.js.map +0 -1
- package/dist/lv-LV.mjs +0 -46
- package/dist/lv-LV.module.js +0 -46
- package/dist/lv-LV.module.js.map +0 -1
- package/dist/nb-NO.main.js +0 -44
- package/dist/nb-NO.main.js.map +0 -1
- package/dist/nb-NO.mjs +0 -46
- package/dist/nb-NO.module.js +0 -46
- package/dist/nb-NO.module.js.map +0 -1
- package/dist/nl-NL.main.js +0 -44
- package/dist/nl-NL.main.js.map +0 -1
- package/dist/nl-NL.mjs +0 -46
- package/dist/nl-NL.module.js +0 -46
- package/dist/nl-NL.module.js.map +0 -1
- package/dist/pl-PL.main.js +0 -44
- package/dist/pl-PL.main.js.map +0 -1
- package/dist/pl-PL.mjs +0 -46
- package/dist/pl-PL.module.js +0 -46
- package/dist/pl-PL.module.js.map +0 -1
- package/dist/pt-BR.main.js +0 -44
- package/dist/pt-BR.main.js.map +0 -1
- package/dist/pt-BR.mjs +0 -46
- package/dist/pt-BR.module.js +0 -46
- package/dist/pt-BR.module.js.map +0 -1
- package/dist/pt-PT.main.js +0 -44
- package/dist/pt-PT.main.js.map +0 -1
- package/dist/pt-PT.mjs +0 -46
- package/dist/pt-PT.module.js +0 -46
- package/dist/pt-PT.module.js.map +0 -1
- package/dist/ro-RO.main.js +0 -44
- package/dist/ro-RO.main.js.map +0 -1
- package/dist/ro-RO.mjs +0 -46
- package/dist/ro-RO.module.js +0 -46
- package/dist/ro-RO.module.js.map +0 -1
- package/dist/ru-RU.main.js +0 -44
- package/dist/ru-RU.main.js.map +0 -1
- package/dist/ru-RU.mjs +0 -46
- package/dist/ru-RU.module.js +0 -46
- package/dist/ru-RU.module.js.map +0 -1
- package/dist/sk-SK.main.js +0 -44
- package/dist/sk-SK.main.js.map +0 -1
- package/dist/sk-SK.mjs +0 -46
- package/dist/sk-SK.module.js +0 -46
- package/dist/sk-SK.module.js.map +0 -1
- package/dist/sl-SI.main.js +0 -44
- package/dist/sl-SI.main.js.map +0 -1
- package/dist/sl-SI.mjs +0 -46
- package/dist/sl-SI.module.js +0 -46
- package/dist/sl-SI.module.js.map +0 -1
- package/dist/sr-SP.main.js +0 -44
- package/dist/sr-SP.main.js.map +0 -1
- package/dist/sr-SP.mjs +0 -46
- package/dist/sr-SP.module.js +0 -46
- package/dist/sr-SP.module.js.map +0 -1
- package/dist/sv-SE.main.js +0 -44
- package/dist/sv-SE.main.js.map +0 -1
- package/dist/sv-SE.mjs +0 -46
- package/dist/sv-SE.module.js +0 -46
- package/dist/sv-SE.module.js.map +0 -1
- package/dist/tr-TR.main.js +0 -44
- package/dist/tr-TR.main.js.map +0 -1
- package/dist/tr-TR.mjs +0 -46
- package/dist/tr-TR.module.js +0 -46
- package/dist/tr-TR.module.js.map +0 -1
- package/dist/types.d.ts +0 -244
- package/dist/types.d.ts.map +0 -1
- package/dist/uk-UA.main.js +0 -44
- package/dist/uk-UA.main.js.map +0 -1
- package/dist/uk-UA.mjs +0 -46
- package/dist/uk-UA.module.js +0 -46
- package/dist/uk-UA.module.js.map +0 -1
- package/dist/useAutoScroll.main.js +0 -89
- package/dist/useAutoScroll.main.js.map +0 -1
- package/dist/useAutoScroll.mjs +0 -84
- package/dist/useAutoScroll.module.js +0 -84
- package/dist/useAutoScroll.module.js.map +0 -1
- package/dist/useClipboard.main.js +0 -111
- package/dist/useClipboard.main.js.map +0 -1
- package/dist/useClipboard.mjs +0 -106
- package/dist/useClipboard.module.js +0 -106
- package/dist/useClipboard.module.js.map +0 -1
- package/dist/useDrag.main.js +0 -307
- package/dist/useDrag.main.js.map +0 -1
- package/dist/useDrag.mjs +0 -302
- package/dist/useDrag.module.js +0 -302
- package/dist/useDrag.module.js.map +0 -1
- package/dist/useDraggableCollection.main.js +0 -27
- package/dist/useDraggableCollection.main.js.map +0 -1
- package/dist/useDraggableCollection.mjs +0 -22
- package/dist/useDraggableCollection.module.js +0 -22
- package/dist/useDraggableCollection.module.js.map +0 -1
- package/dist/useDraggableItem.main.js +0 -128
- package/dist/useDraggableItem.main.js.map +0 -1
- package/dist/useDraggableItem.mjs +0 -123
- package/dist/useDraggableItem.module.js +0 -123
- package/dist/useDraggableItem.module.js.map +0 -1
- package/dist/useDrop.main.js +0 -295
- package/dist/useDrop.main.js.map +0 -1
- package/dist/useDrop.mjs +0 -290
- package/dist/useDrop.module.js +0 -290
- package/dist/useDrop.module.js.map +0 -1
- package/dist/useDropIndicator.main.js +0 -102
- package/dist/useDropIndicator.main.js.map +0 -1
- package/dist/useDropIndicator.mjs +0 -97
- package/dist/useDropIndicator.module.js +0 -97
- package/dist/useDropIndicator.module.js.map +0 -1
- package/dist/useDroppableCollection.main.js +0 -536
- package/dist/useDroppableCollection.main.js.map +0 -1
- package/dist/useDroppableCollection.mjs +0 -531
- package/dist/useDroppableCollection.module.js +0 -531
- package/dist/useDroppableCollection.module.js.map +0 -1
- package/dist/useDroppableItem.main.js +0 -81
- package/dist/useDroppableItem.main.js.map +0 -1
- package/dist/useDroppableItem.mjs +0 -76
- package/dist/useDroppableItem.module.js +0 -76
- package/dist/useDroppableItem.module.js.map +0 -1
- package/dist/useVirtualDrop.main.js +0 -56
- package/dist/useVirtualDrop.main.js.map +0 -1
- package/dist/useVirtualDrop.mjs +0 -51
- package/dist/useVirtualDrop.module.js +0 -51
- package/dist/useVirtualDrop.module.js.map +0 -1
- package/dist/utils.main.js +0 -285
- package/dist/utils.main.js.map +0 -1
- package/dist/utils.mjs +0 -257
- package/dist/utils.module.js +0 -257
- package/dist/utils.module.js.map +0 -1
- package/dist/zh-CN.main.js +0 -44
- package/dist/zh-CN.main.js.map +0 -1
- package/dist/zh-CN.mjs +0 -46
- package/dist/zh-CN.module.js +0 -46
- package/dist/zh-CN.module.js.map +0 -1
- package/dist/zh-TW.main.js +0 -44
- package/dist/zh-TW.main.js.map +0 -1
- package/dist/zh-TW.mjs +0 -46
- package/dist/zh-TW.module.js +0 -46
- package/dist/zh-TW.module.js.map +0 -1
- package/src/DragManager.ts +0 -656
- package/src/DragPreview.tsx +0 -81
- package/src/DropTargetKeyboardNavigation.ts +0 -282
- package/src/ListDropTargetDelegate.ts +0 -182
- package/src/constants.ts +0 -85
- package/src/useAutoScroll.ts +0 -105
- package/src/useClipboard.ts +0 -151
- package/src/useDrag.ts +0 -390
- package/src/useDraggableCollection.ts +0 -29
- package/src/useDraggableItem.ts +0 -158
- package/src/useDrop.ts +0 -444
- package/src/useDropIndicator.ts +0 -124
- package/src/useDroppableCollection.ts +0 -665
- package/src/useDroppableItem.ts +0 -86
- package/src/useVirtualDrop.ts +0 -49
- package/src/utils.ts +0 -385
package/src/DragManager.ts
DELETED
|
@@ -1,656 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {announce} from '@react-aria/live-announcer';
|
|
14
|
-
import {ariaHideOutside} from '@react-aria/overlays';
|
|
15
|
-
import {DragEndEvent, DragItem, DropActivateEvent, DropEnterEvent, DropEvent, DropExitEvent, DropItem, DropOperation, DropTarget as DroppableCollectionTarget, FocusableElement} from '@react-types/shared';
|
|
16
|
-
import {getDragModality, getTypes} from './utils';
|
|
17
|
-
import {isVirtualClick, isVirtualPointerEvent, nodeContains} from '@react-aria/utils';
|
|
18
|
-
import type {LocalizedStringFormatter} from '@internationalized/string';
|
|
19
|
-
import {RefObject, useEffect, useState} from 'react';
|
|
20
|
-
|
|
21
|
-
let dropTargets = new Map<Element, DropTarget>();
|
|
22
|
-
let dropItems = new Map<Element, DroppableItem>();
|
|
23
|
-
let dragSession: DragSession | null = null;
|
|
24
|
-
let subscriptions = new Set<() => void>();
|
|
25
|
-
|
|
26
|
-
interface DropTarget {
|
|
27
|
-
element: FocusableElement,
|
|
28
|
-
preventFocusOnDrop?: boolean,
|
|
29
|
-
getDropOperation?: (types: Set<string>, allowedOperations: DropOperation[]) => DropOperation,
|
|
30
|
-
onDropEnter?: (e: DropEnterEvent, dragTarget: DragTarget) => void,
|
|
31
|
-
onDropExit?: (e: DropExitEvent) => void,
|
|
32
|
-
onDropTargetEnter?: (target: DroppableCollectionTarget | null) => void,
|
|
33
|
-
onDropActivate?: (e: DropActivateEvent, target: DroppableCollectionTarget | null) => void,
|
|
34
|
-
onDrop?: (e: DropEvent, target: DroppableCollectionTarget | null) => void,
|
|
35
|
-
onKeyDown?: (e: KeyboardEvent, dragTarget: DragTarget) => void,
|
|
36
|
-
activateButtonRef?: RefObject<FocusableElement | null>
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function registerDropTarget(target: DropTarget) {
|
|
40
|
-
dropTargets.set(target.element, target);
|
|
41
|
-
dragSession?.updateValidDropTargets();
|
|
42
|
-
return (): void => {
|
|
43
|
-
dropTargets.delete(target.element);
|
|
44
|
-
dragSession?.updateValidDropTargets();
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
interface DroppableItem {
|
|
49
|
-
element: FocusableElement,
|
|
50
|
-
target: DroppableCollectionTarget,
|
|
51
|
-
getDropOperation?: (types: Set<string>, allowedOperations: DropOperation[]) => DropOperation,
|
|
52
|
-
activateButtonRef?: RefObject<FocusableElement | null>
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function registerDropItem(item: DroppableItem) {
|
|
56
|
-
dropItems.set(item.element, item);
|
|
57
|
-
return (): void => {
|
|
58
|
-
dropItems.delete(item.element);
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
interface DragTarget {
|
|
63
|
-
element: FocusableElement,
|
|
64
|
-
items: DragItem[],
|
|
65
|
-
allowedDropOperations: DropOperation[],
|
|
66
|
-
onDragEnd?: (e: DragEndEvent) => void
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function beginDragging(target: DragTarget, stringFormatter: LocalizedStringFormatter): void {
|
|
70
|
-
if (dragSession) {
|
|
71
|
-
throw new Error('Cannot begin dragging while already dragging');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
dragSession = new DragSession(target, stringFormatter);
|
|
75
|
-
requestAnimationFrame(() => {
|
|
76
|
-
if (dragSession) {
|
|
77
|
-
dragSession.setup();
|
|
78
|
-
if (getDragModality() === 'keyboard') {
|
|
79
|
-
dragSession.next();
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
for (let cb of subscriptions) {
|
|
85
|
-
cb();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function useDragSession(): DragSession | null {
|
|
90
|
-
let [session, setSession] = useState(dragSession);
|
|
91
|
-
|
|
92
|
-
useEffect(() => {
|
|
93
|
-
let cb = () => setSession(dragSession);
|
|
94
|
-
subscriptions.add(cb);
|
|
95
|
-
return () => {
|
|
96
|
-
subscriptions.delete(cb);
|
|
97
|
-
};
|
|
98
|
-
}, []);
|
|
99
|
-
|
|
100
|
-
return session;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** @private */
|
|
104
|
-
export function isVirtualDragging(): boolean {
|
|
105
|
-
return !!dragSession;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function endDragging() {
|
|
109
|
-
dragSession = null;
|
|
110
|
-
for (let cb of subscriptions) {
|
|
111
|
-
cb();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export function isValidDropTarget(element: Element): boolean {
|
|
116
|
-
for (let target of dropTargets.keys()) {
|
|
117
|
-
if (nodeContains(target, element)) {
|
|
118
|
-
return true;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return false;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const CANCELED_EVENTS = [
|
|
126
|
-
'pointerdown',
|
|
127
|
-
'pointermove',
|
|
128
|
-
'pointerenter',
|
|
129
|
-
'pointerleave',
|
|
130
|
-
'pointerover',
|
|
131
|
-
'pointerout',
|
|
132
|
-
'pointerup',
|
|
133
|
-
'mousedown',
|
|
134
|
-
'mousemove',
|
|
135
|
-
'mouseenter',
|
|
136
|
-
'mouseleave',
|
|
137
|
-
'mouseover',
|
|
138
|
-
'mouseout',
|
|
139
|
-
'mouseup',
|
|
140
|
-
'touchstart',
|
|
141
|
-
'touchmove',
|
|
142
|
-
'touchend',
|
|
143
|
-
'focusin',
|
|
144
|
-
'focusout'
|
|
145
|
-
];
|
|
146
|
-
|
|
147
|
-
const CLICK_EVENTS = [
|
|
148
|
-
'pointerup',
|
|
149
|
-
'mouseup',
|
|
150
|
-
'touchend'
|
|
151
|
-
];
|
|
152
|
-
|
|
153
|
-
const MESSAGES = {
|
|
154
|
-
keyboard: 'dragStartedKeyboard',
|
|
155
|
-
touch: 'dragStartedTouch',
|
|
156
|
-
virtual: 'dragStartedVirtual'
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
class DragSession {
|
|
160
|
-
dragTarget: DragTarget;
|
|
161
|
-
validDropTargets: DropTarget[] = [];
|
|
162
|
-
currentDropTarget: DropTarget | null = null;
|
|
163
|
-
currentDropItem: DroppableItem | null = null;
|
|
164
|
-
dropOperation: DropOperation | null = null;
|
|
165
|
-
private mutationObserver: MutationObserver | null = null;
|
|
166
|
-
private restoreAriaHidden: (() => void) | null = null;
|
|
167
|
-
private stringFormatter: LocalizedStringFormatter;
|
|
168
|
-
private isVirtualClick: boolean = false;
|
|
169
|
-
private initialFocused: boolean;
|
|
170
|
-
|
|
171
|
-
constructor(target: DragTarget, stringFormatter: LocalizedStringFormatter) {
|
|
172
|
-
this.dragTarget = target;
|
|
173
|
-
this.stringFormatter = stringFormatter;
|
|
174
|
-
|
|
175
|
-
this.onKeyDown = this.onKeyDown.bind(this);
|
|
176
|
-
this.onKeyUp = this.onKeyUp.bind(this);
|
|
177
|
-
this.onFocus = this.onFocus.bind(this);
|
|
178
|
-
this.onBlur = this.onBlur.bind(this);
|
|
179
|
-
this.onClick = this.onClick.bind(this);
|
|
180
|
-
this.onPointerDown = this.onPointerDown.bind(this);
|
|
181
|
-
this.cancelEvent = this.cancelEvent.bind(this);
|
|
182
|
-
this.initialFocused = false;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
setup(): void {
|
|
186
|
-
document.addEventListener('keydown', this.onKeyDown, true);
|
|
187
|
-
document.addEventListener('keyup', this.onKeyUp, true);
|
|
188
|
-
window.addEventListener('focus', this.onFocus, true);
|
|
189
|
-
window.addEventListener('blur', this.onBlur, true);
|
|
190
|
-
document.addEventListener('click', this.onClick, true);
|
|
191
|
-
document.addEventListener('pointerdown', this.onPointerDown, true);
|
|
192
|
-
|
|
193
|
-
for (let event of CANCELED_EVENTS) {
|
|
194
|
-
document.addEventListener(event, this.cancelEvent, true);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
this.mutationObserver = new MutationObserver(() =>
|
|
198
|
-
this.updateValidDropTargets()
|
|
199
|
-
);
|
|
200
|
-
this.updateValidDropTargets();
|
|
201
|
-
|
|
202
|
-
announce(this.stringFormatter.format(MESSAGES[getDragModality()]));
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
teardown(): void {
|
|
206
|
-
document.removeEventListener('keydown', this.onKeyDown, true);
|
|
207
|
-
document.removeEventListener('keyup', this.onKeyUp, true);
|
|
208
|
-
window.removeEventListener('focus', this.onFocus, true);
|
|
209
|
-
window.removeEventListener('blur', this.onBlur, true);
|
|
210
|
-
document.removeEventListener('click', this.onClick, true);
|
|
211
|
-
document.removeEventListener('pointerdown', this.onPointerDown, true);
|
|
212
|
-
|
|
213
|
-
for (let event of CANCELED_EVENTS) {
|
|
214
|
-
document.removeEventListener(event, this.cancelEvent, true);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
this.mutationObserver?.disconnect();
|
|
218
|
-
this.restoreAriaHidden?.();
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
onKeyDown(e: KeyboardEvent): void {
|
|
222
|
-
this.cancelEvent(e);
|
|
223
|
-
|
|
224
|
-
if (e.key === 'Escape') {
|
|
225
|
-
this.cancel();
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
if (e.key === 'Tab' && !(e.metaKey || e.altKey || e.ctrlKey)) {
|
|
230
|
-
if (e.shiftKey) {
|
|
231
|
-
this.previous();
|
|
232
|
-
} else {
|
|
233
|
-
this.next();
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
if (typeof this.currentDropTarget?.onKeyDown === 'function') {
|
|
238
|
-
this.currentDropTarget.onKeyDown(e, this.dragTarget);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
onKeyUp(e: KeyboardEvent): void {
|
|
243
|
-
this.cancelEvent(e);
|
|
244
|
-
|
|
245
|
-
if (e.key === 'Enter') {
|
|
246
|
-
if (e.altKey || nodeContains(this.getCurrentActivateButton(), e.target as Node)) {
|
|
247
|
-
this.activate(this.currentDropTarget, this.currentDropItem);
|
|
248
|
-
} else {
|
|
249
|
-
this.drop();
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
getCurrentActivateButton(): FocusableElement | null {
|
|
255
|
-
return this.currentDropItem?.activateButtonRef?.current ?? this.currentDropTarget?.activateButtonRef?.current ?? null;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
onFocus(e: FocusEvent): void {
|
|
259
|
-
let activateButton = this.getCurrentActivateButton();
|
|
260
|
-
if (e.target === activateButton) {
|
|
261
|
-
// TODO: canceling this breaks the focus ring. Revisit when we support tabbing.
|
|
262
|
-
this.cancelEvent(e);
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// Prevent focus events, except to the original drag target.
|
|
267
|
-
if (e.target !== this.dragTarget.element) {
|
|
268
|
-
this.cancelEvent(e);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// Ignore focus events on the window/document (JSDOM). Will be handled in onBlur, below.
|
|
272
|
-
if (!(e.target instanceof HTMLElement) || e.target === this.dragTarget.element) {
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
let dropTarget =
|
|
277
|
-
this.validDropTargets.find(target => target.element === e.target as HTMLElement) ||
|
|
278
|
-
this.validDropTargets.find(target => nodeContains(target.element, e.target as HTMLElement));
|
|
279
|
-
|
|
280
|
-
if (!dropTarget) {
|
|
281
|
-
// if (e.target === activateButton) {
|
|
282
|
-
// activateButton.focus();
|
|
283
|
-
// }
|
|
284
|
-
if (this.currentDropTarget) {
|
|
285
|
-
this.currentDropTarget.element.focus();
|
|
286
|
-
} else {
|
|
287
|
-
this.dragTarget.element.focus();
|
|
288
|
-
}
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
let item = dropItems.get(e.target as HTMLElement);
|
|
293
|
-
if (dropTarget) {
|
|
294
|
-
this.setCurrentDropTarget(dropTarget, item);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
onBlur(e: FocusEvent): void {
|
|
299
|
-
let activateButton = this.getCurrentActivateButton();
|
|
300
|
-
if (e.relatedTarget === activateButton) {
|
|
301
|
-
this.cancelEvent(e);
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (e.target !== this.dragTarget.element) {
|
|
306
|
-
this.cancelEvent(e);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// If nothing is gaining focus, or e.relatedTarget is the window/document (JSDOM),
|
|
310
|
-
// restore focus back to the current drop target if any, or the original drag target.
|
|
311
|
-
if (!e.relatedTarget || !(e.relatedTarget instanceof HTMLElement)) {
|
|
312
|
-
if (this.currentDropTarget) {
|
|
313
|
-
this.currentDropTarget.element.focus();
|
|
314
|
-
} else {
|
|
315
|
-
this.dragTarget.element.focus();
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
onClick(e: MouseEvent): void {
|
|
321
|
-
this.cancelEvent(e);
|
|
322
|
-
if (isVirtualClick(e) || this.isVirtualClick) {
|
|
323
|
-
let dropElements = dropItems.values();
|
|
324
|
-
let item = [...dropElements].find(item => item.element === e.target as HTMLElement || nodeContains(item.activateButtonRef?.current, e.target as HTMLElement));
|
|
325
|
-
let dropTarget = this.validDropTargets.find(target => nodeContains(target.element, e.target as HTMLElement));
|
|
326
|
-
let activateButton = item?.activateButtonRef?.current ?? dropTarget?.activateButtonRef?.current;
|
|
327
|
-
if (nodeContains(activateButton, e.target as HTMLElement) && dropTarget) {
|
|
328
|
-
this.activate(dropTarget, item);
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
if (e.target === this.dragTarget.element) {
|
|
333
|
-
this.cancel();
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
if (dropTarget) {
|
|
338
|
-
this.setCurrentDropTarget(dropTarget, item);
|
|
339
|
-
this.drop(item);
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
onPointerDown(e: PointerEvent): void {
|
|
345
|
-
// Android Talkback double tap has e.detail = 1 for onClick. Detect the virtual click in onPointerDown before onClick fires
|
|
346
|
-
// so we can properly perform cancel and drop operations.
|
|
347
|
-
this.cancelEvent(e);
|
|
348
|
-
this.isVirtualClick = isVirtualPointerEvent(e);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
cancelEvent(e: Event): void {
|
|
352
|
-
// Allow focusin and focusout on the drag target so focus ring works properly.
|
|
353
|
-
if ((e.type === 'focusin' || e.type === 'focusout') && (e.target === this.dragTarget?.element || e.target === this.getCurrentActivateButton())) {
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
// Allow default for events that might cancel a click event
|
|
358
|
-
if (!CLICK_EVENTS.includes(e.type)) {
|
|
359
|
-
e.preventDefault();
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
e.stopPropagation();
|
|
363
|
-
e.stopImmediatePropagation();
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
updateValidDropTargets(): void {
|
|
367
|
-
if (!this.mutationObserver) {
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
this.mutationObserver.disconnect();
|
|
372
|
-
if (this.restoreAriaHidden) {
|
|
373
|
-
this.restoreAriaHidden();
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
this.validDropTargets = findValidDropTargets(this.dragTarget);
|
|
377
|
-
|
|
378
|
-
// Shuffle drop target order based on starting drag target.
|
|
379
|
-
if (this.validDropTargets.length > 0) {
|
|
380
|
-
let nearestIndex = this.findNearestDropTarget();
|
|
381
|
-
this.validDropTargets = [
|
|
382
|
-
...this.validDropTargets.slice(nearestIndex),
|
|
383
|
-
...this.validDropTargets.slice(0, nearestIndex)
|
|
384
|
-
];
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
if (this.currentDropTarget && !this.validDropTargets.includes(this.currentDropTarget)) {
|
|
388
|
-
this.setCurrentDropTarget(this.validDropTargets[0]);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
// Find valid drop items within collections
|
|
392
|
-
let types = getTypes(this.dragTarget.items);
|
|
393
|
-
let validDropItems = [...dropItems.values()].filter(item => {
|
|
394
|
-
if (typeof item.getDropOperation === 'function') {
|
|
395
|
-
return item.getDropOperation(types, this.dragTarget.allowedDropOperations) !== 'cancel';
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
return true;
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
// Filter out drop targets that contain valid items. We don't want to stop hiding elements
|
|
402
|
-
// other than the drop items that exist inside the collection.
|
|
403
|
-
let visibleDropTargets = this.validDropTargets.filter(target =>
|
|
404
|
-
!validDropItems.some(item => nodeContains(target.element, item.element))
|
|
405
|
-
);
|
|
406
|
-
|
|
407
|
-
this.restoreAriaHidden = ariaHideOutside([
|
|
408
|
-
this.dragTarget.element,
|
|
409
|
-
...validDropItems.flatMap(item => item.activateButtonRef?.current ? [item.element, item.activateButtonRef?.current] : [item.element]),
|
|
410
|
-
...visibleDropTargets.flatMap(target => target.activateButtonRef?.current ? [target.element, target.activateButtonRef?.current] : [target.element])
|
|
411
|
-
], {shouldUseInert: true});
|
|
412
|
-
|
|
413
|
-
this.mutationObserver.observe(document.body, {subtree: true, attributes: true, attributeFilter: ['aria-hidden', 'inert']});
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
next(): void {
|
|
417
|
-
// TODO: Allow tabbing to the activate button. Revisit once we fix the focus ring.
|
|
418
|
-
// For now, the activate button is reachable by screen readers and ArrowLeft/ArrowRight
|
|
419
|
-
// is usable specifically by Tree. Will need tabbing for other components.
|
|
420
|
-
// let activateButton = this.getCurrentActivateButton();
|
|
421
|
-
// if (activateButton && document.activeElement !== activateButton) {
|
|
422
|
-
// activateButton.focus();
|
|
423
|
-
// return;
|
|
424
|
-
// }
|
|
425
|
-
|
|
426
|
-
if (!this.currentDropTarget) {
|
|
427
|
-
this.setCurrentDropTarget(this.validDropTargets[0]);
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
let index = this.validDropTargets.indexOf(this.currentDropTarget);
|
|
432
|
-
if (index < 0) {
|
|
433
|
-
this.setCurrentDropTarget(this.validDropTargets[0]);
|
|
434
|
-
return;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
// If we've reached the end of the valid drop targets, cycle back to the original drag target.
|
|
438
|
-
// This lets the user cancel the drag in case they don't have an Escape key (e.g. iPad keyboard case).
|
|
439
|
-
if (index === this.validDropTargets.length - 1) {
|
|
440
|
-
if (!this.dragTarget.element.closest('[aria-hidden="true"], [inert]')) {
|
|
441
|
-
this.setCurrentDropTarget(null);
|
|
442
|
-
this.dragTarget.element.focus();
|
|
443
|
-
} else {
|
|
444
|
-
this.setCurrentDropTarget(this.validDropTargets[0]);
|
|
445
|
-
}
|
|
446
|
-
} else {
|
|
447
|
-
this.setCurrentDropTarget(this.validDropTargets[index + 1]);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
previous(): void {
|
|
452
|
-
// let activateButton = this.getCurrentActivateButton();
|
|
453
|
-
// if (activateButton && document.activeElement === activateButton) {
|
|
454
|
-
// let target = this.currentDropItem ?? this.currentDropTarget;
|
|
455
|
-
// if (target) {
|
|
456
|
-
// target.element.focus();
|
|
457
|
-
// return;
|
|
458
|
-
// }
|
|
459
|
-
// }
|
|
460
|
-
|
|
461
|
-
if (!this.currentDropTarget) {
|
|
462
|
-
this.setCurrentDropTarget(this.validDropTargets[this.validDropTargets.length - 1]);
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
let index = this.validDropTargets.indexOf(this.currentDropTarget);
|
|
467
|
-
if (index < 0) {
|
|
468
|
-
this.setCurrentDropTarget(this.validDropTargets[this.validDropTargets.length - 1]);
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// If we've reached the start of the valid drop targets, cycle back to the original drag target.
|
|
473
|
-
// This lets the user cancel the drag in case they don't have an Escape key (e.g. iPad keyboard case).
|
|
474
|
-
if (index === 0) {
|
|
475
|
-
if (!this.dragTarget.element.closest('[aria-hidden="true"], [inert]')) {
|
|
476
|
-
this.setCurrentDropTarget(null);
|
|
477
|
-
this.dragTarget.element.focus();
|
|
478
|
-
} else {
|
|
479
|
-
this.setCurrentDropTarget(this.validDropTargets[this.validDropTargets.length - 1]);
|
|
480
|
-
}
|
|
481
|
-
} else {
|
|
482
|
-
this.setCurrentDropTarget(this.validDropTargets[index - 1]);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
findNearestDropTarget(): number {
|
|
487
|
-
let dragTargetRect = this.dragTarget.element.getBoundingClientRect();
|
|
488
|
-
|
|
489
|
-
let minDistance = Infinity;
|
|
490
|
-
let nearest = -1;
|
|
491
|
-
for (let i = 0; i < this.validDropTargets.length; i++) {
|
|
492
|
-
let dropTarget = this.validDropTargets[i];
|
|
493
|
-
let rect = dropTarget.element.getBoundingClientRect();
|
|
494
|
-
let dx = rect.left - dragTargetRect.left;
|
|
495
|
-
let dy = rect.top - dragTargetRect.top;
|
|
496
|
-
let dist = (dx * dx) + (dy * dy);
|
|
497
|
-
if (dist < minDistance) {
|
|
498
|
-
minDistance = dist;
|
|
499
|
-
nearest = i;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
return nearest;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
setCurrentDropTarget(dropTarget: DropTarget | null, item?: DroppableItem): void {
|
|
507
|
-
if (dropTarget !== this.currentDropTarget) {
|
|
508
|
-
if (this.currentDropTarget && typeof this.currentDropTarget.onDropExit === 'function') {
|
|
509
|
-
let rect = this.currentDropTarget.element.getBoundingClientRect();
|
|
510
|
-
this.currentDropTarget.onDropExit({
|
|
511
|
-
type: 'dropexit',
|
|
512
|
-
x: rect.left + (rect.width / 2),
|
|
513
|
-
y: rect.top + (rect.height / 2)
|
|
514
|
-
});
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
this.currentDropTarget = dropTarget;
|
|
518
|
-
|
|
519
|
-
if (dropTarget) {
|
|
520
|
-
if (typeof dropTarget.onDropEnter === 'function') {
|
|
521
|
-
let rect = dropTarget.element.getBoundingClientRect();
|
|
522
|
-
dropTarget.onDropEnter({
|
|
523
|
-
type: 'dropenter',
|
|
524
|
-
x: rect.left + (rect.width / 2),
|
|
525
|
-
y: rect.top + (rect.height / 2)
|
|
526
|
-
}, this.dragTarget);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
if (!item) {
|
|
530
|
-
dropTarget?.element.focus();
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
if (item != null && item !== this.currentDropItem) {
|
|
536
|
-
if (this.currentDropTarget && typeof this.currentDropTarget.onDropTargetEnter === 'function') {
|
|
537
|
-
this.currentDropTarget.onDropTargetEnter(item.target);
|
|
538
|
-
}
|
|
539
|
-
item.element.focus();
|
|
540
|
-
this.currentDropItem = item;
|
|
541
|
-
|
|
542
|
-
// Announce first drop target after drag start announcement finishes.
|
|
543
|
-
// Otherwise, it will never get announced because drag start announcement is assertive.
|
|
544
|
-
if (!this.initialFocused) {
|
|
545
|
-
let label = item?.element.getAttribute('aria-label');
|
|
546
|
-
if (label) {
|
|
547
|
-
announce(label, 'polite');
|
|
548
|
-
}
|
|
549
|
-
this.initialFocused = true;
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
end(): void {
|
|
555
|
-
this.teardown();
|
|
556
|
-
endDragging();
|
|
557
|
-
|
|
558
|
-
if (typeof this.dragTarget.onDragEnd === 'function') {
|
|
559
|
-
let target = this.currentDropTarget && this.dropOperation !== 'cancel' ? this.currentDropTarget : this.dragTarget;
|
|
560
|
-
let rect = target.element.getBoundingClientRect();
|
|
561
|
-
this.dragTarget.onDragEnd({
|
|
562
|
-
type: 'dragend',
|
|
563
|
-
x: rect.x + (rect.width / 2),
|
|
564
|
-
y: rect.y + (rect.height / 2),
|
|
565
|
-
dropOperation: this.dropOperation || 'cancel'
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
if (this.currentDropTarget && !this.currentDropTarget.preventFocusOnDrop) {
|
|
570
|
-
// Re-trigger focus event on active element, since it will not have received it during dragging (see cancelEvent).
|
|
571
|
-
// This corrects state such as whether focus ring should appear.
|
|
572
|
-
// useDroppableCollection handles this itself, so this is only for standalone drop zones.
|
|
573
|
-
document.activeElement?.dispatchEvent(new FocusEvent('focusin', {bubbles: true}));
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
this.setCurrentDropTarget(null);
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
cancel(): void {
|
|
580
|
-
this.setCurrentDropTarget(null);
|
|
581
|
-
this.end();
|
|
582
|
-
if (!this.dragTarget.element.closest('[aria-hidden="true"], [inert]')) {
|
|
583
|
-
this.dragTarget.element.focus();
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
// Re-trigger focus event on active element, since it will not have received it during dragging (see cancelEvent).
|
|
587
|
-
document.activeElement?.dispatchEvent(new FocusEvent('focusin', {bubbles: true}));
|
|
588
|
-
|
|
589
|
-
announce(this.stringFormatter.format('dropCanceled'));
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
drop(item?: DroppableItem): void {
|
|
593
|
-
if (!this.currentDropTarget) {
|
|
594
|
-
this.cancel();
|
|
595
|
-
return;
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
if (typeof item?.getDropOperation === 'function') {
|
|
599
|
-
let types = getTypes(this.dragTarget.items);
|
|
600
|
-
this.dropOperation = item.getDropOperation(types, this.dragTarget.allowedDropOperations);
|
|
601
|
-
} else if (typeof this.currentDropTarget.getDropOperation === 'function') {
|
|
602
|
-
let types = getTypes(this.dragTarget.items);
|
|
603
|
-
this.dropOperation = this.currentDropTarget.getDropOperation(types, this.dragTarget.allowedDropOperations);
|
|
604
|
-
} else {
|
|
605
|
-
// TODO: show menu ??
|
|
606
|
-
this.dropOperation = this.dragTarget.allowedDropOperations[0];
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
if (typeof this.currentDropTarget.onDrop === 'function') {
|
|
610
|
-
let items: DropItem[] = this.dragTarget.items.map(item => ({
|
|
611
|
-
kind: 'text',
|
|
612
|
-
types: new Set(Object.keys(item)),
|
|
613
|
-
getText: (type: string) => Promise.resolve(item[type])
|
|
614
|
-
}));
|
|
615
|
-
|
|
616
|
-
let rect = this.currentDropTarget.element.getBoundingClientRect();
|
|
617
|
-
this.currentDropTarget.onDrop({
|
|
618
|
-
type: 'drop',
|
|
619
|
-
x: rect.left + (rect.width / 2),
|
|
620
|
-
y: rect.top + (rect.height / 2),
|
|
621
|
-
items,
|
|
622
|
-
dropOperation: this.dropOperation
|
|
623
|
-
}, item?.target ?? null);
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
this.end();
|
|
627
|
-
announce(this.stringFormatter.format('dropComplete'));
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
activate(dropTarget: DropTarget | null, dropItem: DroppableItem | null | undefined): void {
|
|
631
|
-
if (dropTarget && typeof dropTarget.onDropActivate === 'function') {
|
|
632
|
-
let target = dropItem?.target ?? null;
|
|
633
|
-
let rect = dropTarget.element.getBoundingClientRect();
|
|
634
|
-
dropTarget.onDropActivate({
|
|
635
|
-
type: 'dropactivate',
|
|
636
|
-
x: rect.left + (rect.width / 2),
|
|
637
|
-
y: rect.top + (rect.height / 2)
|
|
638
|
-
}, target);
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
function findValidDropTargets(options: DragTarget) {
|
|
644
|
-
let types = getTypes(options.items);
|
|
645
|
-
return [...dropTargets.values()].filter(target => {
|
|
646
|
-
if (target.element.closest('[aria-hidden="true"], [inert]')) {
|
|
647
|
-
return false;
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
if (typeof target.getDropOperation === 'function') {
|
|
651
|
-
return target.getDropOperation(types, options.allowedDropOperations) !== 'cancel';
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
return true;
|
|
655
|
-
});
|
|
656
|
-
}
|