@barqjs/aria 0.0.0-stage → 0.2.0-next.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/LICENSE +21 -0
- package/README.md +304 -2
- package/package.json +437 -4
- package/src/autocomplete.tsx +581 -0
- package/src/breadcrumbs.tsx +297 -0
- package/src/button.tsx +468 -0
- package/src/calendar.tsx +2316 -0
- package/src/checkbox.tsx +732 -0
- package/src/collections.ts +1059 -0
- package/src/color.ts +2119 -0
- package/src/colorpicker.tsx +2023 -0
- package/src/colorswatchpicker.tsx +240 -0
- package/src/combobox.tsx +3003 -0
- package/src/command.tsx +1203 -0
- package/src/date.ts +674 -0
- package/src/datefield.tsx +2066 -0
- package/src/datepicker.tsx +907 -0
- package/src/dialog.tsx +1077 -0
- package/src/disclosure.tsx +711 -0
- package/src/dnd/clipboard.ts +125 -0
- package/src/dnd/collection.ts +1265 -0
- package/src/dnd/data.ts +409 -0
- package/src/dnd/drag-drop.ts +801 -0
- package/src/dnd/index.ts +133 -0
- package/src/dnd/manager.ts +639 -0
- package/src/dnd/strings.ts +1279 -0
- package/src/dnd/targets.ts +726 -0
- package/src/dnd/types.ts +212 -0
- package/src/dom.ts +703 -0
- package/src/drag-and-drop.tsx +669 -0
- package/src/drawer.ts +674 -0
- package/src/dropzone.tsx +208 -0
- package/src/file-trigger.tsx +103 -0
- package/src/focus.ts +1370 -0
- package/src/form.tsx +94 -0
- package/src/gridlist.tsx +1354 -0
- package/src/group.tsx +146 -0
- package/src/i18n.ts +823 -0
- package/src/index.ts +1672 -0
- package/src/interactions/description.ts +73 -0
- package/src/interactions/flags.ts +35 -0
- package/src/interactions/focus-events.ts +226 -0
- package/src/interactions/focusable.ts +86 -0
- package/src/interactions/hover.ts +213 -0
- package/src/interactions/interact-outside.ts +123 -0
- package/src/interactions/keyboard.ts +298 -0
- package/src/interactions/listeners.ts +78 -0
- package/src/interactions/long-press.ts +160 -0
- package/src/interactions/modality.ts +428 -0
- package/src/interactions/move.ts +257 -0
- package/src/interactions/open-link.ts +226 -0
- package/src/interactions/press.ts +915 -0
- package/src/interactions/prevent-focus.ts +102 -0
- package/src/interactions/scroll-wheel.ts +43 -0
- package/src/interactions/text-selection.ts +77 -0
- package/src/interactions.ts +81 -0
- package/src/label.ts +140 -0
- package/src/link.tsx +477 -0
- package/src/listbox.tsx +1247 -0
- package/src/live.ts +208 -0
- package/src/menu.tsx +2383 -0
- package/src/menubar.tsx +579 -0
- package/src/navigation-tree.tsx +357 -0
- package/src/navigation.ts +735 -0
- package/src/numberfield.tsx +942 -0
- package/src/otp.ts +430 -0
- package/src/overlay-arrow.tsx +157 -0
- package/src/overlays.ts +1549 -0
- package/src/platform.ts +75 -0
- package/src/presence.ts +164 -0
- package/src/preview-trigger.tsx +582 -0
- package/src/progress-bar-context.ts +15 -0
- package/src/questionnaire.tsx +1717 -0
- package/src/radio.tsx +641 -0
- package/src/register-dom.ts +12 -0
- package/src/scroller.ts +1165 -0
- package/src/select.tsx +1745 -0
- package/src/selection-indicator.tsx +74 -0
- package/src/selection.ts +1472 -0
- package/src/shared-element-transition.tsx +316 -0
- package/src/sheet.tsx +1461 -0
- package/src/slider.tsx +1137 -0
- package/src/splitter.ts +1152 -0
- package/src/static-collection.ts +211 -0
- package/src/switch.tsx +212 -0
- package/src/table.tsx +2218 -0
- package/src/tabs.tsx +1127 -0
- package/src/tag.tsx +637 -0
- package/src/textarea.tsx +186 -0
- package/src/textfield.tsx +483 -0
- package/src/toast-components.tsx +589 -0
- package/src/toast.ts +658 -0
- package/src/toggle-button-group.tsx +175 -0
- package/src/toggle-input.tsx +86 -0
- package/src/toggle.ts +384 -0
- package/src/togglegroup.ts +365 -0
- package/src/tokenfield.tsx +1673 -0
- package/src/toolbar.tsx +184 -0
- package/src/tooltip.tsx +674 -0
- package/src/tree.tsx +2075 -0
- package/src/utils.ts +787 -0
- package/src/validation.ts +504 -0
- package/src/virtualizer.tsx +837 -0
|
@@ -0,0 +1,1265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drag and drop for a collection: which items a drag carries, where among the
|
|
3
|
+
* items a drop lands, and the indicators that stand for those places.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { type Accessor, createEffect, createSignal, untrack } from "@barqjs/core";
|
|
7
|
+
import { tryCleanup } from "@barqjs/primitives/utils";
|
|
8
|
+
import type { Collection, Key, SelectionManager } from "../collections.ts";
|
|
9
|
+
import { stringFormatter, useLocale } from "../i18n.ts";
|
|
10
|
+
import { description } from "../interactions/description.ts";
|
|
11
|
+
import { setInteractionModality } from "../interactions/modality.ts";
|
|
12
|
+
import type { ElementRef } from "../interactions/press.ts";
|
|
13
|
+
import type { KeyboardDelegate } from "../selection.ts";
|
|
14
|
+
import { access, type DOMProps, id, type MaybeAccessor, mergeProps } from "../utils.ts";
|
|
15
|
+
import {
|
|
16
|
+
clearGlobalDnDState,
|
|
17
|
+
DIRECTORY_DRAG_TYPE,
|
|
18
|
+
dndState,
|
|
19
|
+
getTypes,
|
|
20
|
+
isInternalDropOperation,
|
|
21
|
+
refElement,
|
|
22
|
+
setDraggingCollectionRef,
|
|
23
|
+
setDraggingKeys,
|
|
24
|
+
setDropCollectionRef,
|
|
25
|
+
} from "./data.ts";
|
|
26
|
+
import { autoScroll, dragInteraction, dropBehaviour, virtualDrop } from "./drag-drop.ts";
|
|
27
|
+
import {
|
|
28
|
+
type DragModality,
|
|
29
|
+
dragSession,
|
|
30
|
+
type DragTarget,
|
|
31
|
+
registerDropItem,
|
|
32
|
+
registerDropTarget,
|
|
33
|
+
} from "./manager.ts";
|
|
34
|
+
import { type DndMessage, dndStrings } from "./strings.ts";
|
|
35
|
+
import {
|
|
36
|
+
type DropNavigationDirection,
|
|
37
|
+
navigateDropTarget,
|
|
38
|
+
nextSiblingNode,
|
|
39
|
+
previousSiblingNode,
|
|
40
|
+
} from "./targets.ts";
|
|
41
|
+
import type {
|
|
42
|
+
DragItem,
|
|
43
|
+
DragMoveEvent,
|
|
44
|
+
DragPreviewRenderer,
|
|
45
|
+
DragStartEvent,
|
|
46
|
+
DragType,
|
|
47
|
+
DragTypes,
|
|
48
|
+
DraggableCollectionEndEvent,
|
|
49
|
+
DraggableCollectionProps,
|
|
50
|
+
DropEvent,
|
|
51
|
+
DropOperation,
|
|
52
|
+
DropPosition,
|
|
53
|
+
DroppableCollectionDropEvent,
|
|
54
|
+
DroppableCollectionProps,
|
|
55
|
+
DropTarget,
|
|
56
|
+
DropTargetDelegate,
|
|
57
|
+
ItemDropTarget,
|
|
58
|
+
} from "./types.ts";
|
|
59
|
+
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
// Draggable collection state
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
|
|
64
|
+
export interface DraggableCollectionStateOptions<T = unknown> extends DraggableCollectionProps<T> {
|
|
65
|
+
collection: Accessor<Collection<unknown>>;
|
|
66
|
+
selectionManager: Accessor<SelectionManager>;
|
|
67
|
+
isDisabled?: MaybeAccessor<boolean | undefined>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface DraggableCollectionState {
|
|
71
|
+
collection: Accessor<Collection<unknown>>;
|
|
72
|
+
selectionManager: Accessor<SelectionManager>;
|
|
73
|
+
/** The key the drag started on. */
|
|
74
|
+
draggedKey: Accessor<Key | null>;
|
|
75
|
+
/** Every key being dragged: the one grabbed, and the selection when it was selected. */
|
|
76
|
+
draggingKeys: Accessor<Set<Key>>;
|
|
77
|
+
isDisabled: Accessor<boolean>;
|
|
78
|
+
isDragging(key: Key): boolean;
|
|
79
|
+
getKeysForDrag(key: Key): Set<Key>;
|
|
80
|
+
getItems(key: Key): DragItem[];
|
|
81
|
+
preview?: MaybeAccessor<DragPreviewRenderer | null | undefined>;
|
|
82
|
+
getAllowedDropOperations?: () => DropOperation[];
|
|
83
|
+
startDrag(key: Key, event: DragStartEvent): void;
|
|
84
|
+
moveDrag(event: DragMoveEvent): void;
|
|
85
|
+
endDrag(event: DraggableCollectionEndEvent): void;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Which items a drag carries, and the events for it.
|
|
90
|
+
*
|
|
91
|
+
* Grabbing a selected item drags the whole selection; grabbing an unselected
|
|
92
|
+
* one drags only it, as the macOS Finder does. A selected descendant of a
|
|
93
|
+
* selected item is not dragged twice.
|
|
94
|
+
*/
|
|
95
|
+
export function draggableCollectionState<T = unknown>(
|
|
96
|
+
options: DraggableCollectionStateOptions<T>,
|
|
97
|
+
): DraggableCollectionState {
|
|
98
|
+
// The keys are read back by the same handler that set them, so the value
|
|
99
|
+
// lives beside the signal that tells the view.
|
|
100
|
+
let draggingKeysNow = new Set<Key>();
|
|
101
|
+
let draggedKeyNow: Key | null = null;
|
|
102
|
+
const [version, publish] = createSignal(0, { equals: false, ownedWrite: true });
|
|
103
|
+
|
|
104
|
+
const getKeysForDrag = (key: Key): Set<Key> => {
|
|
105
|
+
const manager = options.selectionManager();
|
|
106
|
+
const collection = options.collection();
|
|
107
|
+
const keys = new Set<Key>();
|
|
108
|
+
if (!manager.isSelected(key)) {
|
|
109
|
+
keys.add(key);
|
|
110
|
+
return keys;
|
|
111
|
+
}
|
|
112
|
+
const selected = manager.selectedKeys;
|
|
113
|
+
for (const current of selected) {
|
|
114
|
+
const node = collection.getItem(current);
|
|
115
|
+
if (node === null) continue;
|
|
116
|
+
let isChild = false;
|
|
117
|
+
let parentKey = node.parentKey;
|
|
118
|
+
while (parentKey !== undefined) {
|
|
119
|
+
if (selected.has(parentKey)) {
|
|
120
|
+
isChild = true;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
parentKey = collection.getItem(parentKey)?.parentKey;
|
|
124
|
+
}
|
|
125
|
+
if (!isChild) keys.add(current);
|
|
126
|
+
}
|
|
127
|
+
return keys;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
collection: options.collection,
|
|
132
|
+
selectionManager: options.selectionManager,
|
|
133
|
+
draggedKey: () => {
|
|
134
|
+
version();
|
|
135
|
+
return draggedKeyNow;
|
|
136
|
+
},
|
|
137
|
+
draggingKeys: () => {
|
|
138
|
+
version();
|
|
139
|
+
return draggingKeysNow;
|
|
140
|
+
},
|
|
141
|
+
isDisabled: () => access(options.isDisabled) === true,
|
|
142
|
+
isDragging(key) {
|
|
143
|
+
version();
|
|
144
|
+
return draggingKeysNow.has(key);
|
|
145
|
+
},
|
|
146
|
+
getKeysForDrag,
|
|
147
|
+
getItems(key) {
|
|
148
|
+
const keys = getKeysForDrag(key);
|
|
149
|
+
const collection = options.collection();
|
|
150
|
+
const items: T[] = [];
|
|
151
|
+
for (const each of keys) {
|
|
152
|
+
const value = collection.getItem(each)?.value;
|
|
153
|
+
if (value !== null && value !== undefined) items.push(value as T);
|
|
154
|
+
}
|
|
155
|
+
return options.getItems(keys, items);
|
|
156
|
+
},
|
|
157
|
+
preview: options.preview,
|
|
158
|
+
getAllowedDropOperations: options.getAllowedDropOperations,
|
|
159
|
+
startDrag(key, event) {
|
|
160
|
+
const keys = getKeysForDrag(key);
|
|
161
|
+
draggingKeysNow = keys;
|
|
162
|
+
draggedKeyNow = key;
|
|
163
|
+
options.selectionManager().setFocused(false);
|
|
164
|
+
publish(0);
|
|
165
|
+
options.onDragStart?.({ ...event, keys });
|
|
166
|
+
},
|
|
167
|
+
moveDrag(event) {
|
|
168
|
+
options.onDragMove?.({ ...event, keys: draggingKeysNow });
|
|
169
|
+
},
|
|
170
|
+
endDrag(event) {
|
|
171
|
+
options.onDragEnd?.({ ...event, keys: draggingKeysNow, isInternal: event.isInternal });
|
|
172
|
+
draggingKeysNow = new Set();
|
|
173
|
+
draggedKeyNow = null;
|
|
174
|
+
publish(0);
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// ---------------------------------------------------------------------------
|
|
180
|
+
// Draggable collection and its items
|
|
181
|
+
// ---------------------------------------------------------------------------
|
|
182
|
+
|
|
183
|
+
const draggableCollectionRefs = new WeakMap<DraggableCollectionState, ElementRef>();
|
|
184
|
+
|
|
185
|
+
export type DraggableCollectionOptions = Record<string, never>;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* The collection a drag of its items starts from.
|
|
189
|
+
*
|
|
190
|
+
* Whether a drop is a reorder or an insert depends on whether it lands where
|
|
191
|
+
* it started, so the collection's element is recorded for the drop to compare.
|
|
192
|
+
*/
|
|
193
|
+
export function draggableCollection(
|
|
194
|
+
_options: DraggableCollectionOptions,
|
|
195
|
+
state: DraggableCollectionState,
|
|
196
|
+
ref: ElementRef,
|
|
197
|
+
): void {
|
|
198
|
+
draggableCollectionRefs.set(state, ref);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export interface DraggableItemOptions {
|
|
202
|
+
key: Key;
|
|
203
|
+
/** Whether keyboard and screen reader drags start from a separate button. */
|
|
204
|
+
hasDragButton?: boolean;
|
|
205
|
+
/**
|
|
206
|
+
* Whether the item has an action of its own on Enter and long press. Starting
|
|
207
|
+
* a drag from the keyboard then takes Alt + Enter.
|
|
208
|
+
*/
|
|
209
|
+
hasAction?: MaybeAccessor<boolean | undefined>;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export interface DraggableItemResult {
|
|
213
|
+
dragProps: DOMProps;
|
|
214
|
+
/** Options for `button()`, for the item's drag button. */
|
|
215
|
+
dragButtonProps: DOMProps;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const ITEM_MESSAGES: Record<DragModality, { selected: DndMessage; notSelected: DndMessage }> = {
|
|
219
|
+
keyboard: { selected: "dragSelectedKeyboard", notSelected: "dragDescriptionKeyboard" },
|
|
220
|
+
touch: { selected: "dragSelectedLongPress", notSelected: "dragDescriptionLongPress" },
|
|
221
|
+
virtual: { selected: "dragDescriptionVirtual", notSelected: "dragDescriptionVirtual" },
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
/** One item of a draggable collection. */
|
|
225
|
+
export function draggableItem(
|
|
226
|
+
options: DraggableItemOptions,
|
|
227
|
+
state: DraggableCollectionState,
|
|
228
|
+
): DraggableItemResult {
|
|
229
|
+
const isDisabled = (): boolean =>
|
|
230
|
+
state.isDisabled() || state.selectionManager().isDisabled(options.key);
|
|
231
|
+
const hasAction = (): boolean => access(options.hasAction) === true;
|
|
232
|
+
const hasDragButton = options.hasDragButton === true;
|
|
233
|
+
|
|
234
|
+
const interaction = dragInteraction({
|
|
235
|
+
getItems: () => state.getItems(options.key),
|
|
236
|
+
preview: () => access(state.preview),
|
|
237
|
+
getAllowedDropOperations: state.getAllowedDropOperations,
|
|
238
|
+
hasDragButton,
|
|
239
|
+
isDisabled,
|
|
240
|
+
onDragStart(event) {
|
|
241
|
+
state.startDrag(options.key, event);
|
|
242
|
+
setDraggingKeys(state.draggingKeys());
|
|
243
|
+
setDraggingCollectionRef(draggableCollectionRefs.get(state));
|
|
244
|
+
},
|
|
245
|
+
onDragMove: (event) => state.moveDrag(event),
|
|
246
|
+
onDragEnd(event) {
|
|
247
|
+
const isInternal = event.dropOperation === "cancel" ? false : isInternalDropOperation();
|
|
248
|
+
state.endDrag({ ...event, keys: state.draggingKeys(), isInternal });
|
|
249
|
+
clearGlobalDnDState();
|
|
250
|
+
},
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
const strings = interaction.strings;
|
|
254
|
+
const count = (): number => state.getKeysForDrag(options.key).size;
|
|
255
|
+
const isSelectedForDrag = (): boolean =>
|
|
256
|
+
count() > 1 && state.selectionManager().isSelected(options.key);
|
|
257
|
+
const describesItem = (): boolean =>
|
|
258
|
+
!hasDragButton && state.selectionManager().selectionMode !== "none";
|
|
259
|
+
|
|
260
|
+
const itemDescription = (): string | undefined => {
|
|
261
|
+
if (isDisabled() || hasDragButton) return undefined;
|
|
262
|
+
const currentModality = interaction.modality();
|
|
263
|
+
// A long press selects an item that has an action, so it is not offered
|
|
264
|
+
// as a drag.
|
|
265
|
+
if (currentModality === "touch" && hasAction()) return undefined;
|
|
266
|
+
if (!describesItem()) return interaction.message();
|
|
267
|
+
const selected = isSelectedForDrag();
|
|
268
|
+
let message = ITEM_MESSAGES[currentModality][selected ? "selected" : "notSelected"];
|
|
269
|
+
if (hasAction() && currentModality === "keyboard") message = `${message}Alt` as DndMessage;
|
|
270
|
+
return selected ? strings().format(message, { count: count() }) : strings().format(message);
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const buttonLabel = (): string | undefined => {
|
|
274
|
+
if (describesItem()) return undefined;
|
|
275
|
+
if (isSelectedForDrag()) return strings().format("dragSelectedItems", { count: count() });
|
|
276
|
+
const node = state.collection().getItem(options.key);
|
|
277
|
+
return strings().format("dragItem", { itemText: node?.textValue ?? "" });
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
const accessible = interaction.accessibleProps as {
|
|
281
|
+
onPointerDown: (event: PointerEvent) => void;
|
|
282
|
+
onKeyDownCapture: (event: KeyboardEvent) => void;
|
|
283
|
+
onKeyUpCapture: (event: KeyboardEvent) => void;
|
|
284
|
+
onClick: (event: MouseEvent) => void;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
const gated = <E extends Event>(handler: (event: E) => void) => {
|
|
288
|
+
return (event: E): void => {
|
|
289
|
+
if (!isDisabled()) handler(event);
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// An action of its own on Enter means a drag starts on Alt + Enter.
|
|
294
|
+
const withAlt = (handler: (event: KeyboardEvent) => void) => (event: KeyboardEvent) => {
|
|
295
|
+
if (!hasAction() || event.altKey) handler(event);
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
const dragProps = mergeProps(
|
|
299
|
+
hasDragButton
|
|
300
|
+
? {}
|
|
301
|
+
: {
|
|
302
|
+
onPointerDown: accessible.onPointerDown,
|
|
303
|
+
onKeyDownCapture: withAlt(accessible.onKeyDownCapture),
|
|
304
|
+
onKeyUpCapture: withAlt(accessible.onKeyUpCapture),
|
|
305
|
+
// With selection, a click selects: touch drags on a long press, and
|
|
306
|
+
// NVDA and JAWS are in forms mode inside a collection anyway.
|
|
307
|
+
onClick: (event: MouseEvent) => {
|
|
308
|
+
if (!describesItem()) accessible.onClick(event);
|
|
309
|
+
},
|
|
310
|
+
},
|
|
311
|
+
description(itemDescription),
|
|
312
|
+
{
|
|
313
|
+
draggable: () => (isDisabled() ? undefined : "true"),
|
|
314
|
+
onDragStart: gated(interaction.nativeProps.onDragStart as (event: DragEvent) => void),
|
|
315
|
+
onDrag: gated(interaction.nativeProps.onDrag as (event: DragEvent) => void),
|
|
316
|
+
onDragEnd: interaction.nativeProps.onDragEnd,
|
|
317
|
+
},
|
|
318
|
+
);
|
|
319
|
+
|
|
320
|
+
const buttonDescription = description(() =>
|
|
321
|
+
hasDragButton && !isDisabled() ? interaction.message() : undefined,
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
return {
|
|
325
|
+
dragProps,
|
|
326
|
+
dragButtonProps: {
|
|
327
|
+
...buttonDescription,
|
|
328
|
+
onPress: interaction.onPress,
|
|
329
|
+
isDisabled,
|
|
330
|
+
"aria-label": buttonLabel,
|
|
331
|
+
},
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// ---------------------------------------------------------------------------
|
|
336
|
+
// Droppable collection state
|
|
337
|
+
// ---------------------------------------------------------------------------
|
|
338
|
+
|
|
339
|
+
export interface DropOperationEvent {
|
|
340
|
+
target: DropTarget;
|
|
341
|
+
types: DragTypes;
|
|
342
|
+
allowedOperations: DropOperation[];
|
|
343
|
+
isInternal: boolean;
|
|
344
|
+
draggingKeys: Set<Key>;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export interface DroppableCollectionStateOptions extends DroppableCollectionProps {
|
|
348
|
+
collection: Accessor<Collection<unknown>>;
|
|
349
|
+
selectionManager: Accessor<SelectionManager>;
|
|
350
|
+
isDisabled?: MaybeAccessor<boolean | undefined>;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export interface DroppableCollectionState {
|
|
354
|
+
collection: Accessor<Collection<unknown>>;
|
|
355
|
+
selectionManager: Accessor<SelectionManager>;
|
|
356
|
+
/** Where a drop would land right now. */
|
|
357
|
+
target: Accessor<DropTarget | null>;
|
|
358
|
+
isDisabled: Accessor<boolean>;
|
|
359
|
+
setTarget(target: DropTarget | null): void;
|
|
360
|
+
/** Whether `target` is where a drop would land, counting "after A" and "before B" as one. */
|
|
361
|
+
isDropTarget(target: DropTarget | null): boolean;
|
|
362
|
+
getDropOperation(event: DropOperationEvent): DropOperation;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export function isEqualDropTarget(
|
|
366
|
+
a: DropTarget | null | undefined,
|
|
367
|
+
b: DropTarget | null | undefined,
|
|
368
|
+
): boolean {
|
|
369
|
+
if (a === null || a === undefined) return b === null || b === undefined;
|
|
370
|
+
if (a.type === "root") return b?.type === "root";
|
|
371
|
+
return b?.type === "item" && b.key === a.key && b.dropPosition === a.dropPosition;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function isDraggingWithinParent(
|
|
375
|
+
collection: Collection<unknown>,
|
|
376
|
+
target: ItemDropTarget,
|
|
377
|
+
draggingKeys: Set<Key>,
|
|
378
|
+
): boolean {
|
|
379
|
+
const targetNode = collection.getItem(target.key);
|
|
380
|
+
for (const key of draggingKeys) {
|
|
381
|
+
if (collection.getItem(key)?.parentKey !== targetNode?.parentKey) return false;
|
|
382
|
+
}
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Where a drop on a collection would land, and whether it is accepted there.
|
|
388
|
+
*
|
|
389
|
+
* Without `getDropOperation`, a target is valid when some handler would act on
|
|
390
|
+
* it: `onReorder` for between items of this collection, `onInsert` for between
|
|
391
|
+
* items from elsewhere, `onItemDrop` for on an item, `onRootDrop` for on the
|
|
392
|
+
* collection from elsewhere, `onMove` for anywhere from here, and `onDrop` for
|
|
393
|
+
* anything at all.
|
|
394
|
+
*/
|
|
395
|
+
export function droppableCollectionState(
|
|
396
|
+
options: DroppableCollectionStateOptions,
|
|
397
|
+
): DroppableCollectionState {
|
|
398
|
+
let targetNow: DropTarget | null = null;
|
|
399
|
+
const [version, publish] = createSignal(0, { equals: false, ownedWrite: true });
|
|
400
|
+
const isDisabled = (): boolean => access(options.isDisabled) === true;
|
|
401
|
+
|
|
402
|
+
const oppositeTarget = (target: ItemDropTarget): ItemDropTarget | null => {
|
|
403
|
+
const collection = options.collection();
|
|
404
|
+
const node = collection.getItem(target.key);
|
|
405
|
+
if (node === null) return null;
|
|
406
|
+
if (target.dropPosition === "before") {
|
|
407
|
+
const previous = previousSiblingNode(collection, node);
|
|
408
|
+
return previous === null ? null : { type: "item", key: previous.key, dropPosition: "after" };
|
|
409
|
+
}
|
|
410
|
+
if (target.dropPosition === "after") {
|
|
411
|
+
const next = nextSiblingNode(collection, node);
|
|
412
|
+
return next === null ? null : { type: "item", key: next.key, dropPosition: "before" };
|
|
413
|
+
}
|
|
414
|
+
return null;
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
const defaultGetDropOperation = (event: DropOperationEvent): DropOperation => {
|
|
418
|
+
const { target, types, allowedOperations, isInternal, draggingKeys } = event;
|
|
419
|
+
if (isDisabled()) return "cancel";
|
|
420
|
+
|
|
421
|
+
const accepted = options.acceptedDragTypes ?? "all";
|
|
422
|
+
if (accepted !== "all" && !accepted.some((type) => types.has(type))) return "cancel";
|
|
423
|
+
|
|
424
|
+
const isBetween =
|
|
425
|
+
target.type === "item" &&
|
|
426
|
+
(target.dropPosition === "before" || target.dropPosition === "after");
|
|
427
|
+
const isValidInsert = options.onInsert !== undefined && isBetween && !isInternal;
|
|
428
|
+
const isValidReorder =
|
|
429
|
+
options.onReorder !== undefined &&
|
|
430
|
+
isBetween &&
|
|
431
|
+
isInternal &&
|
|
432
|
+
isDraggingWithinParent(options.collection(), target, draggingKeys);
|
|
433
|
+
const isItemDropAllowed =
|
|
434
|
+
target.type !== "item" ||
|
|
435
|
+
target.dropPosition !== "on" ||
|
|
436
|
+
options.shouldAcceptItemDrop === undefined ||
|
|
437
|
+
options.shouldAcceptItemDrop(target, types);
|
|
438
|
+
const isValidMove = options.onMove !== undefined && target.type === "item" && isInternal;
|
|
439
|
+
// A drop of a collection's own items on itself read as nothing happening.
|
|
440
|
+
const isValidRootDrop =
|
|
441
|
+
options.onRootDrop !== undefined && target.type === "root" && !isInternal;
|
|
442
|
+
// A folder cannot be dropped into itself.
|
|
443
|
+
const isValidOnItemDrop =
|
|
444
|
+
options.onItemDrop !== undefined &&
|
|
445
|
+
target.type === "item" &&
|
|
446
|
+
target.dropPosition === "on" &&
|
|
447
|
+
!(isInternal && draggingKeys.has(target.key)) &&
|
|
448
|
+
isItemDropAllowed;
|
|
449
|
+
|
|
450
|
+
if (
|
|
451
|
+
options.onDrop !== undefined ||
|
|
452
|
+
isValidInsert ||
|
|
453
|
+
isValidReorder ||
|
|
454
|
+
(isValidMove && isItemDropAllowed) ||
|
|
455
|
+
isValidRootDrop ||
|
|
456
|
+
isValidOnItemDrop
|
|
457
|
+
) {
|
|
458
|
+
return options.getDropOperation !== undefined
|
|
459
|
+
? options.getDropOperation(target, types, allowedOperations)
|
|
460
|
+
: (allowedOperations[0] ?? "cancel");
|
|
461
|
+
}
|
|
462
|
+
return "cancel";
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
const state: DroppableCollectionState = {
|
|
466
|
+
collection: options.collection,
|
|
467
|
+
selectionManager: options.selectionManager,
|
|
468
|
+
isDisabled,
|
|
469
|
+
target: () => {
|
|
470
|
+
version();
|
|
471
|
+
return targetNow;
|
|
472
|
+
},
|
|
473
|
+
setTarget(next) {
|
|
474
|
+
if (state.isDropTarget(next)) return;
|
|
475
|
+
const previous = targetNow;
|
|
476
|
+
if (previous !== null) {
|
|
477
|
+
options.onDropExit?.({ type: "dropexit", x: 0, y: 0, target: previous });
|
|
478
|
+
}
|
|
479
|
+
if (next !== null) {
|
|
480
|
+
options.onDropEnter?.({ type: "dropenter", x: 0, y: 0, target: next });
|
|
481
|
+
}
|
|
482
|
+
targetNow = next;
|
|
483
|
+
publish(0);
|
|
484
|
+
},
|
|
485
|
+
isDropTarget(dropTarget) {
|
|
486
|
+
version();
|
|
487
|
+
const target = targetNow;
|
|
488
|
+
if (target === null || dropTarget === null) return false;
|
|
489
|
+
if (isEqualDropTarget(dropTarget, target)) return true;
|
|
490
|
+
// "After A" and "before B" are one place when B follows A.
|
|
491
|
+
if (
|
|
492
|
+
dropTarget.type === "item" &&
|
|
493
|
+
target.type === "item" &&
|
|
494
|
+
dropTarget.key !== target.key &&
|
|
495
|
+
dropTarget.dropPosition !== target.dropPosition &&
|
|
496
|
+
dropTarget.dropPosition !== "on" &&
|
|
497
|
+
target.dropPosition !== "on"
|
|
498
|
+
) {
|
|
499
|
+
return (
|
|
500
|
+
isEqualDropTarget(oppositeTarget(dropTarget), target) ||
|
|
501
|
+
isEqualDropTarget(dropTarget, oppositeTarget(target))
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
return false;
|
|
505
|
+
},
|
|
506
|
+
getDropOperation(event) {
|
|
507
|
+
const { target, isInternal, draggingKeys } = event;
|
|
508
|
+
// Never onto itself, or into its own descendants.
|
|
509
|
+
if (isInternal && target.type === "item" && draggingKeys.size > 0) {
|
|
510
|
+
if (draggingKeys.has(target.key) && target.dropPosition === "on") return "cancel";
|
|
511
|
+
const collection = options.collection();
|
|
512
|
+
let current: Key | undefined = target.key;
|
|
513
|
+
while (current !== undefined) {
|
|
514
|
+
const parentKey: Key | undefined = collection.getItem(current)?.parentKey;
|
|
515
|
+
if (parentKey !== undefined && draggingKeys.has(parentKey)) return "cancel";
|
|
516
|
+
current = parentKey;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
return defaultGetDropOperation(event);
|
|
520
|
+
},
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
return state;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// ---------------------------------------------------------------------------
|
|
527
|
+
// Droppable collection
|
|
528
|
+
// ---------------------------------------------------------------------------
|
|
529
|
+
|
|
530
|
+
const droppableCollections = new WeakMap<
|
|
531
|
+
DroppableCollectionState,
|
|
532
|
+
{ id: Accessor<string>; ref: ElementRef }
|
|
533
|
+
>();
|
|
534
|
+
|
|
535
|
+
function droppableCollectionOf(state: DroppableCollectionState): {
|
|
536
|
+
id: Accessor<string>;
|
|
537
|
+
ref: ElementRef;
|
|
538
|
+
} {
|
|
539
|
+
const entry = droppableCollections.get(state);
|
|
540
|
+
if (entry === undefined)
|
|
541
|
+
throw new Error("A droppable item must be inside a droppable collection.");
|
|
542
|
+
return entry;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export interface DroppableCollectionOptions extends DroppableCollectionProps {
|
|
546
|
+
/** Moves between drop targets with the arrow keys. */
|
|
547
|
+
keyboardDelegate: KeyboardDelegate;
|
|
548
|
+
/** Finds the drop target under the pointer. */
|
|
549
|
+
dropTargetDelegate: DropTargetDelegate;
|
|
550
|
+
/** Called for every key during a keyboard drag over the collection. */
|
|
551
|
+
onKeyDown?: (event: KeyboardEvent) => void;
|
|
552
|
+
/**
|
|
553
|
+
* The key that takes focus for an item after a drop. A collection whose
|
|
554
|
+
* items are not themselves focusable (a table, where focus is on cells)
|
|
555
|
+
* names what is. @default the item's own key
|
|
556
|
+
*/
|
|
557
|
+
focusKeyFor?: (key: Key) => Key;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
export interface DroppableCollectionResult {
|
|
561
|
+
collectionProps: DOMProps;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
interface DroppingState {
|
|
565
|
+
collection: Collection<unknown>;
|
|
566
|
+
focusedKey: Key | null;
|
|
567
|
+
selectedKeys: Set<Key>;
|
|
568
|
+
target: DropTarget;
|
|
569
|
+
draggingKeys: Set<Key>;
|
|
570
|
+
isInternal: boolean;
|
|
571
|
+
timeout: ReturnType<typeof setTimeout> | undefined;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
/**
|
|
575
|
+
* The element of a droppable collection.
|
|
576
|
+
*
|
|
577
|
+
* After a drop, focus and selection follow what happened: inserted items are
|
|
578
|
+
* selected and the first one focused, a reordered item keeps focus, and an
|
|
579
|
+
* item dropped on is focused, each only when the user or the application has
|
|
580
|
+
* not already moved them.
|
|
581
|
+
*/
|
|
582
|
+
export function droppableCollection(
|
|
583
|
+
options: DroppableCollectionOptions,
|
|
584
|
+
state: DroppableCollectionState,
|
|
585
|
+
ref: ElementRef<HTMLElement>,
|
|
586
|
+
): DroppableCollectionResult {
|
|
587
|
+
const locale = useLocale();
|
|
588
|
+
const scroller = autoScroll(ref);
|
|
589
|
+
let nextTarget: DropTarget | null = null;
|
|
590
|
+
let dropOperation: DropOperation | null = null;
|
|
591
|
+
|
|
592
|
+
const defaultOnDrop = async (event: DroppableCollectionDropEvent): Promise<void> => {
|
|
593
|
+
const accepted = options.acceptedDragTypes ?? "all";
|
|
594
|
+
const { draggingKeys } = dndState();
|
|
595
|
+
const isInternal = isInternalDropOperation(ref);
|
|
596
|
+
const { target, dropOperation: operation, items } = event;
|
|
597
|
+
|
|
598
|
+
let filtered = items;
|
|
599
|
+
if (accepted !== "all" || options.shouldAcceptItemDrop !== undefined) {
|
|
600
|
+
filtered = items.filter((item) => {
|
|
601
|
+
let itemTypes: Set<DragType>;
|
|
602
|
+
if (item.kind === "directory") itemTypes = new Set<DragType>([DIRECTORY_DRAG_TYPE]);
|
|
603
|
+
else itemTypes = item.kind === "file" ? new Set([item.type]) : item.types;
|
|
604
|
+
|
|
605
|
+
const types: DragTypes = { has: (type) => hasAnyType(itemTypes, type) };
|
|
606
|
+
if (accepted === "all" || accepted.some((type) => itemTypes.has(type))) {
|
|
607
|
+
// An item may be stricter than the collection about what lands on it.
|
|
608
|
+
if (
|
|
609
|
+
target.type === "item" &&
|
|
610
|
+
target.dropPosition === "on" &&
|
|
611
|
+
options.shouldAcceptItemDrop !== undefined
|
|
612
|
+
) {
|
|
613
|
+
return options.shouldAcceptItemDrop(target, types);
|
|
614
|
+
}
|
|
615
|
+
return true;
|
|
616
|
+
}
|
|
617
|
+
return false;
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
if (filtered.length === 0) return;
|
|
622
|
+
|
|
623
|
+
if (target.type === "root" && options.onRootDrop !== undefined) {
|
|
624
|
+
await options.onRootDrop({ items: filtered, dropOperation: operation });
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
if (target.type === "item") {
|
|
628
|
+
if (target.dropPosition === "on" && options.onItemDrop !== undefined) {
|
|
629
|
+
await options.onItemDrop({ items: filtered, dropOperation: operation, isInternal, target });
|
|
630
|
+
}
|
|
631
|
+
if (options.onMove !== undefined && isInternal) {
|
|
632
|
+
await options.onMove({ keys: draggingKeys, dropOperation: operation, target });
|
|
633
|
+
}
|
|
634
|
+
if (target.dropPosition !== "on") {
|
|
635
|
+
if (!isInternal && options.onInsert !== undefined) {
|
|
636
|
+
await options.onInsert({ items: filtered, dropOperation: operation, target });
|
|
637
|
+
}
|
|
638
|
+
if (isInternal && options.onReorder !== undefined) {
|
|
639
|
+
await options.onReorder({ keys: draggingKeys, dropOperation: operation, target });
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
let dropping: DroppingState | null = null;
|
|
646
|
+
const focusKey = (key: Key): Key => options.focusKeyFor?.(key) ?? key;
|
|
647
|
+
|
|
648
|
+
const updateFocusAfterDrop = (): void => {
|
|
649
|
+
if (dropping === null) return;
|
|
650
|
+
const manager = state.selectionManager();
|
|
651
|
+
const collection = state.collection();
|
|
652
|
+
const {
|
|
653
|
+
target,
|
|
654
|
+
collection: previousCollection,
|
|
655
|
+
selectedKeys: previousSelectedKeys,
|
|
656
|
+
focusedKey: previousFocusedKey,
|
|
657
|
+
isInternal,
|
|
658
|
+
draggingKeys,
|
|
659
|
+
} = dropping;
|
|
660
|
+
const focusedParent =
|
|
661
|
+
previousFocusedKey === null ? undefined : collection.getItem(previousFocusedKey)?.parentKey;
|
|
662
|
+
|
|
663
|
+
if (
|
|
664
|
+
collection.size > previousCollection.size &&
|
|
665
|
+
manager.isSelectionEqual(previousSelectedKeys)
|
|
666
|
+
) {
|
|
667
|
+
// Select what the drop inserted, so the user can see what happened.
|
|
668
|
+
const newKeys = new Set<Key>();
|
|
669
|
+
for (const key of collection.getKeys()) {
|
|
670
|
+
const item = collection.getItem(key);
|
|
671
|
+
if (item?.type === "item" && previousCollection.getItem(item.key) === null) {
|
|
672
|
+
newKeys.add(item.key);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
manager.setSelectedKeys(newKeys);
|
|
676
|
+
|
|
677
|
+
if (manager.focusedKey === previousFocusedKey) {
|
|
678
|
+
let first: Key | null | undefined = newKeys.values().next().value;
|
|
679
|
+
if (first !== undefined && first !== null) {
|
|
680
|
+
const item = collection.getItem(first);
|
|
681
|
+
const expanded = (collection as { expandedKeys?: Set<Key> }).expandedKeys;
|
|
682
|
+
const isParentRowExpanded =
|
|
683
|
+
expanded !== undefined && item?.parentKey !== undefined
|
|
684
|
+
? expanded.has(item.parentKey)
|
|
685
|
+
: false;
|
|
686
|
+
if (
|
|
687
|
+
item !== null &&
|
|
688
|
+
(item.type !== "item" ||
|
|
689
|
+
(target.type === "item" && target.dropPosition === "on" && !isParentRowExpanded))
|
|
690
|
+
) {
|
|
691
|
+
first = item.parentKey;
|
|
692
|
+
}
|
|
693
|
+
if (first !== undefined && first !== null) manager.setFocusedKey(focusKey(first));
|
|
694
|
+
// With nothing selectable, the focus ring is the only sign of the drop.
|
|
695
|
+
if (manager.selectionMode === "none") setInteractionModality("keyboard");
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
} else if (
|
|
699
|
+
previousFocusedKey !== null &&
|
|
700
|
+
manager.focusedKey === previousFocusedKey &&
|
|
701
|
+
isInternal &&
|
|
702
|
+
target.type === "item" &&
|
|
703
|
+
target.dropPosition !== "on" &&
|
|
704
|
+
focusedParent !== undefined &&
|
|
705
|
+
draggingKeys.has(focusedParent)
|
|
706
|
+
) {
|
|
707
|
+
// A reordered row keeps focus on the row, not on a cell of it.
|
|
708
|
+
manager.setFocusedKey(focusKey(focusedParent));
|
|
709
|
+
setInteractionModality("keyboard");
|
|
710
|
+
} else if (
|
|
711
|
+
manager.focusedKey === previousFocusedKey &&
|
|
712
|
+
target.type === "item" &&
|
|
713
|
+
target.dropPosition === "on" &&
|
|
714
|
+
collection.getItem(target.key) !== null
|
|
715
|
+
) {
|
|
716
|
+
manager.setFocusedKey(focusKey(target.key));
|
|
717
|
+
setInteractionModality("keyboard");
|
|
718
|
+
} else if (manager.focusedKey !== null && !manager.isSelected(manager.focusedKey)) {
|
|
719
|
+
setInteractionModality("keyboard");
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
manager.setFocused(true);
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
const onDrop = (event: DropEvent, target: DropTarget): void => {
|
|
726
|
+
const manager = state.selectionManager();
|
|
727
|
+
dropping = {
|
|
728
|
+
timeout: undefined,
|
|
729
|
+
focusedKey: manager.focusedKey,
|
|
730
|
+
collection: state.collection(),
|
|
731
|
+
selectedKeys: manager.selectedKeys,
|
|
732
|
+
draggingKeys: dndState().draggingKeys,
|
|
733
|
+
isInternal: isInternalDropOperation(ref),
|
|
734
|
+
target,
|
|
735
|
+
};
|
|
736
|
+
|
|
737
|
+
const handler = options.onDrop ?? defaultOnDrop;
|
|
738
|
+
void handler({
|
|
739
|
+
type: "drop",
|
|
740
|
+
x: event.x,
|
|
741
|
+
y: event.y,
|
|
742
|
+
target,
|
|
743
|
+
items: event.items,
|
|
744
|
+
dropOperation: event.dropOperation,
|
|
745
|
+
});
|
|
746
|
+
|
|
747
|
+
// Long enough for the data to be read and the collection to change; if it
|
|
748
|
+
// changes sooner, the effect below gets there first.
|
|
749
|
+
const current = dropping;
|
|
750
|
+
current.timeout = setTimeout(() => {
|
|
751
|
+
if (dropping !== current) return;
|
|
752
|
+
updateFocusAfterDrop();
|
|
753
|
+
dropping = null;
|
|
754
|
+
}, 50);
|
|
755
|
+
};
|
|
756
|
+
|
|
757
|
+
tryCleanup(() => {
|
|
758
|
+
if (dropping !== null) clearTimeout(dropping.timeout);
|
|
759
|
+
});
|
|
760
|
+
|
|
761
|
+
// Focus and selection are repaired once the change has landed. The repair
|
|
762
|
+
// reads the selection, which is no dependency of this effect.
|
|
763
|
+
createEffect(
|
|
764
|
+
() => {
|
|
765
|
+
const collection = state.collection();
|
|
766
|
+
return dropping !== null && collection !== dropping.collection ? dropping : null;
|
|
767
|
+
},
|
|
768
|
+
(pending) => {
|
|
769
|
+
if (pending === null) return;
|
|
770
|
+
untrack(updateFocusAfterDrop);
|
|
771
|
+
},
|
|
772
|
+
);
|
|
773
|
+
|
|
774
|
+
const { dropProps } = dropBehaviour(
|
|
775
|
+
{
|
|
776
|
+
ref,
|
|
777
|
+
onDropEnter() {
|
|
778
|
+
if (nextTarget !== null) state.setTarget(nextTarget);
|
|
779
|
+
},
|
|
780
|
+
onDropMove(event) {
|
|
781
|
+
if (nextTarget !== null) state.setTarget(nextTarget);
|
|
782
|
+
scroller.move(event.x, event.y);
|
|
783
|
+
},
|
|
784
|
+
getDropOperationForPoint(types, allowedOperations, x, y) {
|
|
785
|
+
const { draggingKeys, dropCollectionRef } = dndState();
|
|
786
|
+
const isInternal = isInternalDropOperation(ref);
|
|
787
|
+
const isValid = (target: DropTarget): boolean =>
|
|
788
|
+
state.getDropOperation({ target, types, allowedOperations, isInternal, draggingKeys }) !==
|
|
789
|
+
"cancel";
|
|
790
|
+
let target = options.dropTargetDelegate.getDropTargetFromPoint(x, y, isValid);
|
|
791
|
+
if (target === null) {
|
|
792
|
+
dropOperation = "cancel";
|
|
793
|
+
nextTarget = null;
|
|
794
|
+
return "cancel";
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
dropOperation = state.getDropOperation({
|
|
798
|
+
target,
|
|
799
|
+
types,
|
|
800
|
+
allowedOperations,
|
|
801
|
+
isInternal,
|
|
802
|
+
draggingKeys,
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
// An item that refuses may sit in a collection that accepts.
|
|
806
|
+
if (dropOperation === "cancel") {
|
|
807
|
+
const root: DropTarget = { type: "root" };
|
|
808
|
+
const rootOperation = state.getDropOperation({
|
|
809
|
+
target: root,
|
|
810
|
+
types,
|
|
811
|
+
allowedOperations,
|
|
812
|
+
isInternal,
|
|
813
|
+
draggingKeys,
|
|
814
|
+
});
|
|
815
|
+
if (rootOperation !== "cancel") {
|
|
816
|
+
target = root;
|
|
817
|
+
dropOperation = rootOperation;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
// Only a valid target records the collection, because leaving one is
|
|
822
|
+
// what clears it.
|
|
823
|
+
if (dropOperation !== "cancel" && refElement(ref) !== refElement(dropCollectionRef)) {
|
|
824
|
+
setDropCollectionRef(ref);
|
|
825
|
+
}
|
|
826
|
+
nextTarget = dropOperation === "cancel" ? null : target;
|
|
827
|
+
return dropOperation;
|
|
828
|
+
},
|
|
829
|
+
onDropExit() {
|
|
830
|
+
setDropCollectionRef(undefined);
|
|
831
|
+
state.setTarget(null);
|
|
832
|
+
scroller.stop();
|
|
833
|
+
},
|
|
834
|
+
onDropActivate(event) {
|
|
835
|
+
const target = state.target();
|
|
836
|
+
if (target?.type === "item") {
|
|
837
|
+
options.onDropActivate?.({ type: "dropactivate", x: event.x, y: event.y, target });
|
|
838
|
+
}
|
|
839
|
+
},
|
|
840
|
+
onDrop(event) {
|
|
841
|
+
setDropCollectionRef(ref);
|
|
842
|
+
const target = state.target();
|
|
843
|
+
if (target !== null) onDrop(event, target);
|
|
844
|
+
// A drag from outside any collection keeps nothing for a `dragend`.
|
|
845
|
+
if (dndState().draggingCollectionRef === undefined) clearGlobalDnDState();
|
|
846
|
+
},
|
|
847
|
+
},
|
|
848
|
+
false,
|
|
849
|
+
);
|
|
850
|
+
|
|
851
|
+
const isRTL = (): boolean => locale().direction === "rtl";
|
|
852
|
+
|
|
853
|
+
const getNextTarget = (
|
|
854
|
+
target: DropTarget | null | undefined,
|
|
855
|
+
wrap = true,
|
|
856
|
+
key: DropNavigationDirection = "down",
|
|
857
|
+
): DropTarget | null =>
|
|
858
|
+
navigateDropTarget(options.keyboardDelegate, state.collection(), target, key, isRTL(), wrap);
|
|
859
|
+
|
|
860
|
+
const getPreviousTarget = (target: DropTarget | null | undefined, wrap = true) =>
|
|
861
|
+
getNextTarget(target, wrap, "up");
|
|
862
|
+
|
|
863
|
+
const nextValidTarget = (
|
|
864
|
+
start: DropTarget | null | undefined,
|
|
865
|
+
types: DragTypes,
|
|
866
|
+
allowedDropOperations: DropOperation[],
|
|
867
|
+
step: (target: DropTarget | null | undefined, wrap: boolean) => DropTarget | null,
|
|
868
|
+
wrap = true,
|
|
869
|
+
): DropTarget | null => {
|
|
870
|
+
let seenRoot = 0;
|
|
871
|
+
let operation: DropOperation;
|
|
872
|
+
let target = start;
|
|
873
|
+
const { draggingKeys } = dndState();
|
|
874
|
+
const isInternal = isInternalDropOperation(ref);
|
|
875
|
+
do {
|
|
876
|
+
const candidate = step(target, wrap);
|
|
877
|
+
if (candidate === null) return null;
|
|
878
|
+
target = candidate;
|
|
879
|
+
operation = state.getDropOperation({
|
|
880
|
+
target: candidate,
|
|
881
|
+
types,
|
|
882
|
+
allowedOperations: allowedDropOperations,
|
|
883
|
+
isInternal,
|
|
884
|
+
draggingKeys,
|
|
885
|
+
});
|
|
886
|
+
if (candidate.type === "root") seenRoot++;
|
|
887
|
+
} while (operation === "cancel" && !state.isDropTarget(target) && seenRoot < 2);
|
|
888
|
+
|
|
889
|
+
return operation === "cancel" ? null : target;
|
|
890
|
+
};
|
|
891
|
+
|
|
892
|
+
const operationFor = (target: DropTarget, types: DragTypes, allowed: DropOperation[]) =>
|
|
893
|
+
state.getDropOperation({
|
|
894
|
+
target,
|
|
895
|
+
types,
|
|
896
|
+
allowedOperations: allowed,
|
|
897
|
+
isInternal: isInternalDropOperation(ref),
|
|
898
|
+
draggingKeys: dndState().draggingKeys,
|
|
899
|
+
});
|
|
900
|
+
|
|
901
|
+
const onKeyDown = (event: KeyboardEvent, dragTarget: DragTarget): void => {
|
|
902
|
+
const delegate = options.keyboardDelegate;
|
|
903
|
+
const types = getTypes(dragTarget.items);
|
|
904
|
+
const allowed = dragTarget.allowedDropOperations;
|
|
905
|
+
const along =
|
|
906
|
+
(key: DropNavigationDirection) =>
|
|
907
|
+
(target: DropTarget | null | undefined, wrap: boolean): DropTarget | null =>
|
|
908
|
+
getNextTarget(target, wrap, key);
|
|
909
|
+
|
|
910
|
+
switch (event.key) {
|
|
911
|
+
case "ArrowDown":
|
|
912
|
+
if (delegate.getKeyBelow !== undefined) {
|
|
913
|
+
state.setTarget(nextValidTarget(state.target(), types, allowed, along("down")));
|
|
914
|
+
}
|
|
915
|
+
break;
|
|
916
|
+
case "ArrowUp":
|
|
917
|
+
if (delegate.getKeyAbove !== undefined) {
|
|
918
|
+
state.setTarget(nextValidTarget(state.target(), types, allowed, along("up")));
|
|
919
|
+
}
|
|
920
|
+
break;
|
|
921
|
+
case "ArrowLeft":
|
|
922
|
+
if (delegate.getKeyLeftOf !== undefined) {
|
|
923
|
+
state.setTarget(nextValidTarget(state.target(), types, allowed, along("left")));
|
|
924
|
+
}
|
|
925
|
+
break;
|
|
926
|
+
case "ArrowRight":
|
|
927
|
+
if (delegate.getKeyRightOf !== undefined) {
|
|
928
|
+
state.setTarget(nextValidTarget(state.target(), types, allowed, along("right")));
|
|
929
|
+
}
|
|
930
|
+
break;
|
|
931
|
+
case "Home":
|
|
932
|
+
if (delegate.getFirstKey !== undefined) {
|
|
933
|
+
state.setTarget(nextValidTarget(null, types, allowed, getNextTarget));
|
|
934
|
+
}
|
|
935
|
+
break;
|
|
936
|
+
case "End":
|
|
937
|
+
if (delegate.getLastKey !== undefined) {
|
|
938
|
+
state.setTarget(nextValidTarget(null, types, allowed, getPreviousTarget));
|
|
939
|
+
}
|
|
940
|
+
break;
|
|
941
|
+
case "PageDown": {
|
|
942
|
+
if (delegate.getKeyPageBelow === undefined) break;
|
|
943
|
+
let target = state.target();
|
|
944
|
+
if (target === null) {
|
|
945
|
+
target = nextValidTarget(null, types, allowed, getNextTarget);
|
|
946
|
+
} else {
|
|
947
|
+
// From the root, a page below the first item.
|
|
948
|
+
let targetKey: Key | null | undefined = delegate.getFirstKey?.();
|
|
949
|
+
if (target.type === "item") targetKey = target.key;
|
|
950
|
+
let nextKey: Key | null = null;
|
|
951
|
+
if (targetKey !== null && targetKey !== undefined) {
|
|
952
|
+
nextKey = delegate.getKeyPageBelow(targetKey);
|
|
953
|
+
}
|
|
954
|
+
let dropPosition: DropPosition = target.type === "item" ? target.dropPosition : "after";
|
|
955
|
+
|
|
956
|
+
// Off the end, or already on the last item: the last position there is.
|
|
957
|
+
if (
|
|
958
|
+
nextKey === null ||
|
|
959
|
+
(target.type === "item" && target.key === delegate.getLastKey?.())
|
|
960
|
+
) {
|
|
961
|
+
nextKey = delegate.getLastKey?.() ?? null;
|
|
962
|
+
dropPosition = "after";
|
|
963
|
+
}
|
|
964
|
+
if (nextKey === null) break;
|
|
965
|
+
target = { type: "item", key: nextKey, dropPosition };
|
|
966
|
+
|
|
967
|
+
if (operationFor(target, types, allowed) === "cancel") {
|
|
968
|
+
target =
|
|
969
|
+
nextValidTarget(target, types, allowed, getNextTarget, false) ??
|
|
970
|
+
nextValidTarget(target, types, allowed, getPreviousTarget, false);
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
state.setTarget(target ?? state.target());
|
|
974
|
+
break;
|
|
975
|
+
}
|
|
976
|
+
case "PageUp": {
|
|
977
|
+
if (delegate.getKeyPageAbove === undefined) break;
|
|
978
|
+
let target = state.target();
|
|
979
|
+
if (target === null) {
|
|
980
|
+
target = nextValidTarget(null, types, allowed, getPreviousTarget);
|
|
981
|
+
} else if (target.type === "item") {
|
|
982
|
+
// From the first item, the root; otherwise a page up.
|
|
983
|
+
if (target.key === delegate.getFirstKey?.()) {
|
|
984
|
+
target = { type: "root" };
|
|
985
|
+
} else {
|
|
986
|
+
let nextKey: Key | null | undefined = delegate.getKeyPageAbove(target.key);
|
|
987
|
+
let dropPosition = target.dropPosition;
|
|
988
|
+
if (nextKey === null) {
|
|
989
|
+
nextKey = delegate.getFirstKey?.();
|
|
990
|
+
dropPosition = "before";
|
|
991
|
+
}
|
|
992
|
+
if (nextKey === null || nextKey === undefined) break;
|
|
993
|
+
target = { type: "item", key: nextKey, dropPosition };
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
if (operationFor(target, types, allowed) === "cancel") {
|
|
997
|
+
target =
|
|
998
|
+
nextValidTarget(target, types, allowed, getPreviousTarget, false) ??
|
|
999
|
+
nextValidTarget(target, types, allowed, getNextTarget, false);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
state.setTarget(target ?? state.target());
|
|
1003
|
+
break;
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
options.onKeyDown?.(event);
|
|
1007
|
+
};
|
|
1008
|
+
|
|
1009
|
+
createEffect(
|
|
1010
|
+
() => refElement(ref) as HTMLElement | null,
|
|
1011
|
+
(element) => {
|
|
1012
|
+
if (element === null) return undefined;
|
|
1013
|
+
return registerDropTarget({
|
|
1014
|
+
element,
|
|
1015
|
+
preventFocusOnDrop: true,
|
|
1016
|
+
getDropOperation(types, allowedOperations) {
|
|
1017
|
+
const target = state.target();
|
|
1018
|
+
if (target !== null) return operationFor(target, types, allowedOperations);
|
|
1019
|
+
// Accepted if anything in it accepts.
|
|
1020
|
+
return nextValidTarget(null, types, allowedOperations, getNextTarget) === null
|
|
1021
|
+
? "cancel"
|
|
1022
|
+
: "move";
|
|
1023
|
+
},
|
|
1024
|
+
onDropEnter(_event, dragTarget) {
|
|
1025
|
+
const types = getTypes(dragTarget.items);
|
|
1026
|
+
const manager = state.selectionManager();
|
|
1027
|
+
// Recorded for a droppable item asking whether the drag is internal.
|
|
1028
|
+
setDropCollectionRef(ref);
|
|
1029
|
+
|
|
1030
|
+
// Entering, the default is after the focused item; with a selection,
|
|
1031
|
+
// after the last selected item, or before the first when the focus is
|
|
1032
|
+
// on the first (selecting upwards suggests moving upwards).
|
|
1033
|
+
let key: Key | null | undefined = manager.focusedKey;
|
|
1034
|
+
let dropPosition: DropPosition = "after";
|
|
1035
|
+
const item = key === null ? null : state.collection().getItem(key);
|
|
1036
|
+
if (item !== null && item.type !== "item" && item.parentKey !== undefined) {
|
|
1037
|
+
key = item.parentKey;
|
|
1038
|
+
}
|
|
1039
|
+
if (key !== null && key !== undefined && manager.isSelected(key)) {
|
|
1040
|
+
if (manager.selectedKeys.size > 1 && manager.firstSelectedKey === key) {
|
|
1041
|
+
dropPosition = "before";
|
|
1042
|
+
} else {
|
|
1043
|
+
key = manager.lastSelectedKey;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
let target: DropTarget | null = null;
|
|
1048
|
+
if (key !== null && key !== undefined) {
|
|
1049
|
+
target = { type: "item", key, dropPosition };
|
|
1050
|
+
if (operationFor(target, types, dragTarget.allowedDropOperations) === "cancel") {
|
|
1051
|
+
target =
|
|
1052
|
+
nextValidTarget(
|
|
1053
|
+
target,
|
|
1054
|
+
types,
|
|
1055
|
+
dragTarget.allowedDropOperations,
|
|
1056
|
+
getNextTarget,
|
|
1057
|
+
false,
|
|
1058
|
+
) ??
|
|
1059
|
+
nextValidTarget(
|
|
1060
|
+
target,
|
|
1061
|
+
types,
|
|
1062
|
+
dragTarget.allowedDropOperations,
|
|
1063
|
+
getPreviousTarget,
|
|
1064
|
+
false,
|
|
1065
|
+
);
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
target ??= nextValidTarget(null, types, dragTarget.allowedDropOperations, getNextTarget);
|
|
1069
|
+
state.setTarget(target);
|
|
1070
|
+
},
|
|
1071
|
+
onDropExit() {
|
|
1072
|
+
setDropCollectionRef(undefined);
|
|
1073
|
+
state.setTarget(null);
|
|
1074
|
+
},
|
|
1075
|
+
onDropTargetEnter(target) {
|
|
1076
|
+
state.setTarget(target);
|
|
1077
|
+
},
|
|
1078
|
+
onDropActivate(event, target) {
|
|
1079
|
+
if (target?.type === "item" && target.dropPosition === "on") {
|
|
1080
|
+
options.onDropActivate?.({ type: "dropactivate", x: event.x, y: event.y, target });
|
|
1081
|
+
}
|
|
1082
|
+
},
|
|
1083
|
+
onDrop(event, target) {
|
|
1084
|
+
setDropCollectionRef(ref);
|
|
1085
|
+
const current = state.target();
|
|
1086
|
+
if (current !== null) onDrop(event, target ?? current);
|
|
1087
|
+
},
|
|
1088
|
+
onKeyDown,
|
|
1089
|
+
});
|
|
1090
|
+
},
|
|
1091
|
+
);
|
|
1092
|
+
|
|
1093
|
+
const collectionId = id();
|
|
1094
|
+
droppableCollections.set(state, { id: collectionId, ref });
|
|
1095
|
+
|
|
1096
|
+
return {
|
|
1097
|
+
// No drop description on the collection itself: a drop on the whole
|
|
1098
|
+
// collection has an indicator that carries it.
|
|
1099
|
+
collectionProps: mergeProps(dropProps, { id: collectionId }),
|
|
1100
|
+
};
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
function hasAnyType(types: Set<DragType>, type: DragType | DragType[]): boolean {
|
|
1104
|
+
if (Array.isArray(type)) return type.some((one) => types.has(one));
|
|
1105
|
+
return types.has(type);
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1108
|
+
// ---------------------------------------------------------------------------
|
|
1109
|
+
// Droppable items and drop indicators
|
|
1110
|
+
// ---------------------------------------------------------------------------
|
|
1111
|
+
|
|
1112
|
+
export interface DroppableItemOptions {
|
|
1113
|
+
target: DropTarget;
|
|
1114
|
+
/** A button inside the target that opens it, for a tree's folders. */
|
|
1115
|
+
activateButtonRef?: ElementRef<HTMLElement>;
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
export interface DroppableItemResult {
|
|
1119
|
+
dropProps: DOMProps;
|
|
1120
|
+
isDropTarget: Accessor<boolean>;
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
/** One drop target inside a droppable collection: an item, or a position between two. */
|
|
1124
|
+
export function droppableItem(
|
|
1125
|
+
options: DroppableItemOptions,
|
|
1126
|
+
state: DroppableCollectionState,
|
|
1127
|
+
ref: ElementRef<HTMLElement>,
|
|
1128
|
+
): DroppableItemResult {
|
|
1129
|
+
const { ref: collectionRef } = droppableCollectionOf(state);
|
|
1130
|
+
const virtual = virtualDrop(true);
|
|
1131
|
+
|
|
1132
|
+
createEffect(
|
|
1133
|
+
() => refElement(ref) as HTMLElement | null,
|
|
1134
|
+
(element) => {
|
|
1135
|
+
if (element === null) return undefined;
|
|
1136
|
+
return registerDropItem({
|
|
1137
|
+
element,
|
|
1138
|
+
target: options.target,
|
|
1139
|
+
getDropOperation: (types, allowedOperations) =>
|
|
1140
|
+
state.getDropOperation({
|
|
1141
|
+
target: options.target,
|
|
1142
|
+
types,
|
|
1143
|
+
allowedOperations,
|
|
1144
|
+
isInternal: isInternalDropOperation(collectionRef),
|
|
1145
|
+
draggingKeys: dndState().draggingKeys,
|
|
1146
|
+
}),
|
|
1147
|
+
activateButtonRef: options.activateButtonRef,
|
|
1148
|
+
});
|
|
1149
|
+
},
|
|
1150
|
+
);
|
|
1151
|
+
|
|
1152
|
+
const isValidForSession = (): boolean => {
|
|
1153
|
+
const session = dragSession();
|
|
1154
|
+
if (session === null) return false;
|
|
1155
|
+
return (
|
|
1156
|
+
state.getDropOperation({
|
|
1157
|
+
target: options.target,
|
|
1158
|
+
types: getTypes(session.dragTarget.items),
|
|
1159
|
+
allowedOperations: session.dragTarget.allowedDropOperations,
|
|
1160
|
+
isInternal: isInternalDropOperation(collectionRef),
|
|
1161
|
+
draggingKeys: dndState().draggingKeys,
|
|
1162
|
+
}) !== "cancel"
|
|
1163
|
+
);
|
|
1164
|
+
};
|
|
1165
|
+
|
|
1166
|
+
const isDropTarget = (): boolean => state.isDropTarget(options.target);
|
|
1167
|
+
|
|
1168
|
+
createEffect(
|
|
1169
|
+
() => (dragSession() !== null && isDropTarget() ? refElement(ref) : null),
|
|
1170
|
+
(element) => {
|
|
1171
|
+
if (element instanceof HTMLElement) element.focus();
|
|
1172
|
+
},
|
|
1173
|
+
);
|
|
1174
|
+
|
|
1175
|
+
return {
|
|
1176
|
+
dropProps: {
|
|
1177
|
+
...virtual,
|
|
1178
|
+
"aria-hidden": () => (dragSession() === null || isValidForSession() ? undefined : "true"),
|
|
1179
|
+
},
|
|
1180
|
+
isDropTarget,
|
|
1181
|
+
};
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
export interface DropIndicatorOptions {
|
|
1185
|
+
target: DropTarget;
|
|
1186
|
+
activateButtonRef?: ElementRef<HTMLElement>;
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
export interface DropIndicatorResult {
|
|
1190
|
+
dropIndicatorProps: DOMProps;
|
|
1191
|
+
isDropTarget: Accessor<boolean>;
|
|
1192
|
+
/**
|
|
1193
|
+
* Whether the indicator is hidden from sight and from assistive technology:
|
|
1194
|
+
* outside a drag, or not a valid target for this one. Leave it out of the
|
|
1195
|
+
* DOM entirely then, unless a pointer drag is over it.
|
|
1196
|
+
*/
|
|
1197
|
+
isHidden: Accessor<boolean>;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
/** A position between items (or the whole collection) as a drop target with a name. */
|
|
1201
|
+
export function dropIndicator(
|
|
1202
|
+
options: DropIndicatorOptions,
|
|
1203
|
+
state: DroppableCollectionState,
|
|
1204
|
+
ref: ElementRef<HTMLElement>,
|
|
1205
|
+
): DropIndicatorResult {
|
|
1206
|
+
const { target } = options;
|
|
1207
|
+
const strings = stringFormatter(dndStrings);
|
|
1208
|
+
const { dropProps } = droppableItem(options, state, ref);
|
|
1209
|
+
const indicatorId = id();
|
|
1210
|
+
const collection = droppableCollectionOf(state);
|
|
1211
|
+
|
|
1212
|
+
const textOf = (key: Key | null | undefined): string =>
|
|
1213
|
+
key === null || key === undefined ? "" : (state.collection().getItem(key)?.textValue ?? "");
|
|
1214
|
+
|
|
1215
|
+
const label = (): string => {
|
|
1216
|
+
const format = strings();
|
|
1217
|
+
if (target.type === "root") return format.format("dropOnRoot");
|
|
1218
|
+
if (target.dropPosition === "on") {
|
|
1219
|
+
return format.format("dropOnItem", { itemText: textOf(target.key) });
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
const current = state.collection();
|
|
1223
|
+
const node = current.getItem(target.key);
|
|
1224
|
+
let before: Key | null = null;
|
|
1225
|
+
let after: Key | null = null;
|
|
1226
|
+
if (target.dropPosition === "before") {
|
|
1227
|
+
const previous = node === null ? null : previousSiblingNode(current, node);
|
|
1228
|
+
before = previous?.type === "item" ? previous.key : null;
|
|
1229
|
+
after = target.key;
|
|
1230
|
+
} else {
|
|
1231
|
+
before = target.key;
|
|
1232
|
+
const next = node === null ? null : nextSiblingNode(current, node);
|
|
1233
|
+
after = next?.type === "item" ? next.key : null;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
if (before !== null && after !== null) {
|
|
1237
|
+
return format.format("insertBetween", {
|
|
1238
|
+
beforeItemText: textOf(before),
|
|
1239
|
+
afterItemText: textOf(after),
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
if (before !== null) return format.format("insertAfter", { itemText: textOf(before) });
|
|
1243
|
+
if (after !== null) return format.format("insertBefore", { itemText: textOf(after) });
|
|
1244
|
+
return "";
|
|
1245
|
+
};
|
|
1246
|
+
|
|
1247
|
+
const itemHidden = dropProps["aria-hidden"] as Accessor<string | undefined>;
|
|
1248
|
+
const ariaHidden = (): string | undefined => (dragSession() === null ? "true" : itemHidden());
|
|
1249
|
+
const isDropTarget = (): boolean => state.isDropTarget(target);
|
|
1250
|
+
|
|
1251
|
+
return {
|
|
1252
|
+
dropIndicatorProps: {
|
|
1253
|
+
...dropProps,
|
|
1254
|
+
id: indicatorId,
|
|
1255
|
+
"aria-roledescription": () => strings().format("dropIndicator"),
|
|
1256
|
+
"aria-label": label,
|
|
1257
|
+
"aria-labelledby": () =>
|
|
1258
|
+
target.type === "root" ? `${indicatorId()} ${collection.id()}` : undefined,
|
|
1259
|
+
"aria-hidden": ariaHidden,
|
|
1260
|
+
tabIndex: -1,
|
|
1261
|
+
},
|
|
1262
|
+
isDropTarget,
|
|
1263
|
+
isHidden: () => !isDropTarget() && ariaHidden() !== undefined,
|
|
1264
|
+
};
|
|
1265
|
+
}
|