@proyecto-viviana/solidaria 0.2.4 → 0.2.8
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/dist/actiongroup/createActionGroup.d.ts +29 -0
- package/dist/actiongroup/createActionGroup.d.ts.map +1 -0
- package/dist/actiongroup/index.d.ts +2 -0
- package/dist/actiongroup/index.d.ts.map +1 -0
- package/dist/autocomplete/createAutocomplete.d.ts +6 -2
- package/dist/autocomplete/createAutocomplete.d.ts.map +1 -1
- package/dist/breadcrumbs/createBreadcrumbs.d.ts +2 -0
- package/dist/breadcrumbs/createBreadcrumbs.d.ts.map +1 -1
- package/dist/button/createToggleButtonGroup.d.ts +32 -0
- package/dist/button/createToggleButtonGroup.d.ts.map +1 -0
- package/dist/button/index.d.ts +2 -0
- package/dist/button/index.d.ts.map +1 -1
- package/dist/calendar/createCalendarCell.d.ts +2 -0
- package/dist/calendar/createCalendarCell.d.ts.map +1 -1
- package/dist/calendar/createCalendarGrid.d.ts.map +1 -1
- package/dist/calendar/createRangeCalendarCell.d.ts +3 -1
- package/dist/calendar/createRangeCalendarCell.d.ts.map +1 -1
- package/dist/checkbox/createCheckboxGroup.d.ts +5 -1
- package/dist/checkbox/createCheckboxGroup.d.ts.map +1 -1
- package/dist/collections/index.d.ts +56 -0
- package/dist/collections/index.d.ts.map +1 -0
- package/dist/color/createColorArea.d.ts.map +1 -1
- package/dist/color/createColorSlider.d.ts.map +1 -1
- package/dist/color/createColorWheel.d.ts.map +1 -1
- package/dist/combobox/createComboBox.d.ts +6 -0
- package/dist/combobox/createComboBox.d.ts.map +1 -1
- package/dist/datepicker/createDatePicker.d.ts +6 -0
- package/dist/datepicker/createDatePicker.d.ts.map +1 -1
- package/dist/datepicker/createDateRangePicker.d.ts +40 -0
- package/dist/datepicker/createDateRangePicker.d.ts.map +1 -0
- package/dist/datepicker/createDateSegment.d.ts +1 -1
- package/dist/datepicker/createDateSegment.d.ts.map +1 -1
- package/dist/datepicker/createTimeSegment.d.ts +29 -0
- package/dist/datepicker/createTimeSegment.d.ts.map +1 -0
- package/dist/datepicker/index.d.ts +2 -0
- package/dist/datepicker/index.d.ts.map +1 -1
- package/dist/disclosure/createDisclosureGroup.d.ts +2 -1
- package/dist/disclosure/createDisclosureGroup.d.ts.map +1 -1
- package/dist/dnd/createDrag.d.ts.map +1 -1
- package/dist/dnd/createDraggableCollection.d.ts +4 -0
- package/dist/dnd/createDraggableCollection.d.ts.map +1 -1
- package/dist/dnd/createDraggableItem.d.ts.map +1 -1
- package/dist/dnd/createDrop.d.ts.map +1 -1
- package/dist/dnd/createDroppableCollection.d.ts +32 -1
- package/dist/dnd/createDroppableCollection.d.ts.map +1 -1
- package/dist/dnd/createDroppableItem.d.ts.map +1 -1
- package/dist/dnd/index.d.ts +1 -1
- package/dist/dnd/index.d.ts.map +1 -1
- package/dist/grid/createGrid.d.ts.map +1 -1
- package/dist/gridlist/createGridList.d.ts.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4659 -3452
- package/dist/index.js.map +1 -7
- package/dist/index.ssr.js +4659 -3452
- package/dist/index.ssr.js.map +1 -7
- package/dist/interactions/createFocus.d.ts.map +1 -1
- package/dist/interactions/createFocusWithin.d.ts.map +1 -1
- package/dist/link/createLink.d.ts +10 -0
- package/dist/link/createLink.d.ts.map +1 -1
- package/dist/listbox/createListBox.d.ts +1 -0
- package/dist/listbox/createListBox.d.ts.map +1 -1
- package/dist/listbox/createOption.d.ts.map +1 -1
- package/dist/menu/createMenu.d.ts +1 -0
- package/dist/menu/createMenu.d.ts.map +1 -1
- package/dist/meter/createMeter.d.ts.map +1 -1
- package/dist/numberfield/createNumberField.d.ts +18 -0
- package/dist/numberfield/createNumberField.d.ts.map +1 -1
- package/dist/overlays/createModal.d.ts +16 -0
- package/dist/overlays/createModal.d.ts.map +1 -1
- package/dist/overlays/createOverlay.d.ts.map +1 -1
- package/dist/overlays/index.d.ts +1 -1
- package/dist/overlays/index.d.ts.map +1 -1
- package/dist/popover/createOverlayPosition.d.ts.map +1 -1
- package/dist/popover/createPopover.d.ts.map +1 -1
- package/dist/progress/createProgressBar.d.ts.map +1 -1
- package/dist/radio/createRadioGroup.d.ts +2 -2
- package/dist/radio/createRadioGroup.d.ts.map +1 -1
- package/dist/searchfield/createSearchField.d.ts.map +1 -1
- package/dist/select/createHiddenSelect.d.ts.map +1 -1
- package/dist/select/createSelect.d.ts.map +1 -1
- package/dist/slider/createSlider.d.ts.map +1 -1
- package/dist/table/createTable.d.ts.map +1 -1
- package/dist/tabs/createTabs.d.ts +1 -1
- package/dist/tabs/createTabs.d.ts.map +1 -1
- package/dist/tag/createTag.d.ts.map +1 -1
- package/dist/tag/createTagGroup.d.ts.map +1 -1
- package/dist/toast/createToast.d.ts +4 -0
- package/dist/toast/createToast.d.ts.map +1 -1
- package/dist/toast/createToastRegion.d.ts.map +1 -1
- package/dist/toolbar/createToolbar.d.ts.map +1 -1
- package/dist/tooltip/createTooltipTrigger.d.ts.map +1 -1
- package/dist/tree/createTree.d.ts.map +1 -1
- package/dist/tree/createTreeItem.d.ts.map +1 -1
- package/dist/tree/types.d.ts +4 -0
- package/dist/tree/types.d.ts.map +1 -1
- package/dist/utils/env.d.ts +1 -1
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/platform.d.ts.map +1 -1
- package/dist/visually-hidden/createVisuallyHidden.d.ts.map +1 -1
- package/package.json +8 -6
- package/src/actiongroup/createActionGroup.ts +324 -0
- package/src/actiongroup/index.ts +8 -0
- package/src/autocomplete/createAutocomplete.ts +32 -9
- package/src/breadcrumbs/createBreadcrumbs.ts +10 -15
- package/src/button/createButton.ts +1 -1
- package/src/button/createToggleButtonGroup.ts +128 -0
- package/src/button/index.ts +9 -0
- package/src/calendar/createCalendarCell.ts +6 -4
- package/src/calendar/createCalendarGrid.ts +27 -18
- package/src/calendar/createRangeCalendarCell.ts +26 -9
- package/src/checkbox/createCheckboxGroup.ts +21 -4
- package/src/collections/index.ts +242 -0
- package/src/color/createColorArea.ts +380 -314
- package/src/color/createColorField.ts +137 -137
- package/src/color/createColorSlider.ts +286 -197
- package/src/color/createColorSwatch.ts +40 -40
- package/src/color/createColorWheel.ts +218 -208
- package/src/color/index.ts +24 -24
- package/src/color/types.ts +116 -116
- package/src/combobox/createComboBox.ts +670 -647
- package/src/combobox/index.ts +6 -6
- package/src/datepicker/createDatePicker.ts +54 -16
- package/src/datepicker/createDateRangePicker.ts +246 -0
- package/src/datepicker/createDateSegment.ts +185 -31
- package/src/datepicker/createTimeSegment.ts +370 -0
- package/src/datepicker/index.ts +14 -0
- package/src/dialog/createDialog.ts +120 -120
- package/src/dialog/index.ts +2 -2
- package/src/dialog/types.ts +19 -19
- package/src/disclosure/createDisclosureGroup.ts +5 -2
- package/src/dnd/createDrag.ts +224 -209
- package/src/dnd/createDraggableCollection.ts +96 -63
- package/src/dnd/createDraggableItem.ts +259 -243
- package/src/dnd/createDrop.ts +322 -321
- package/src/dnd/createDroppableCollection.ts +682 -293
- package/src/dnd/createDroppableItem.ts +215 -213
- package/src/dnd/index.ts +55 -47
- package/src/dnd/types.ts +89 -89
- package/src/dnd/utils.ts +294 -294
- package/src/focus/createAutoFocus.ts +321 -321
- package/src/focus/createFocusRestore.ts +313 -313
- package/src/focus/createVirtualFocus.ts +396 -396
- package/src/form/createFormValidation.ts +224 -224
- package/src/form/index.ts +11 -11
- package/src/grid/createGrid.ts +3 -1
- package/src/gridlist/createGridList.ts +16 -0
- package/src/gridlist/createGridListItem.ts +1 -1
- package/src/i18n/NumberFormatter.ts +266 -266
- package/src/i18n/createCollator.ts +79 -79
- package/src/i18n/createDateFormatter.ts +83 -83
- package/src/i18n/createFilter.ts +131 -131
- package/src/i18n/createNumberFormatter.ts +52 -52
- package/src/i18n/index.ts +40 -40
- package/src/i18n/locale.tsx +188 -188
- package/src/i18n/utils.ts +99 -99
- package/src/index.ts +51 -0
- package/src/interactions/createFocus.ts +6 -5
- package/src/interactions/createFocusWithin.ts +6 -5
- package/src/interactions/createLongPress.ts +174 -174
- package/src/interactions/createMove.ts +289 -289
- package/src/interactions/createPress.ts +5 -5
- package/src/landmark/createLandmark.ts +377 -377
- package/src/landmark/index.ts +8 -8
- package/src/link/createLink.ts +23 -8
- package/src/listbox/createListBox.ts +308 -269
- package/src/listbox/createOption.ts +162 -151
- package/src/listbox/index.ts +12 -12
- package/src/live-announcer/announce.ts +322 -322
- package/src/live-announcer/index.ts +9 -9
- package/src/menu/createMenu.ts +405 -396
- package/src/menu/createMenuItem.ts +149 -149
- package/src/menu/createMenuTrigger.ts +88 -88
- package/src/menu/index.ts +18 -18
- package/src/meter/createMeter.ts +1 -6
- package/src/numberfield/createNumberField.ts +311 -268
- package/src/numberfield/index.ts +5 -5
- package/src/overlays/ariaHideOutside.ts +219 -219
- package/src/overlays/createInteractOutside.ts +149 -149
- package/src/overlays/createModal.tsx +238 -202
- package/src/overlays/createOverlay.ts +165 -155
- package/src/overlays/createOverlayTrigger.ts +85 -85
- package/src/overlays/createPreventScroll.ts +266 -266
- package/src/overlays/index.ts +48 -44
- package/src/popover/calculatePosition.ts +6 -6
- package/src/popover/createOverlayPosition.ts +7 -4
- package/src/popover/createPopover.ts +21 -7
- package/src/progress/createProgressBar.ts +6 -1
- package/src/radio/createRadioGroup.ts +88 -14
- package/src/searchfield/createSearchField.ts +241 -186
- package/src/searchfield/index.ts +2 -2
- package/src/select/createHiddenSelect.tsx +263 -236
- package/src/select/createSelect.ts +373 -395
- package/src/select/index.ts +14 -14
- package/src/slider/createSlider.ts +364 -349
- package/src/slider/index.ts +2 -2
- package/src/ssr/index.tsx +370 -370
- package/src/table/createTable.ts +3 -1
- package/src/table/createTableColumnHeader.ts +1 -1
- package/src/table/createTableRow.ts +1 -1
- package/src/tabs/createTabs.ts +80 -51
- package/src/tag/createTag.ts +135 -6
- package/src/tag/createTagGroup.ts +7 -2
- package/src/toast/createToast.ts +8 -2
- package/src/toast/createToastRegion.ts +0 -1
- package/src/toolbar/createToolbar.ts +75 -1
- package/src/tooltip/createTooltip.ts +79 -79
- package/src/tooltip/createTooltipTrigger.ts +226 -222
- package/src/tooltip/index.ts +6 -6
- package/src/tree/createTree.ts +261 -246
- package/src/tree/createTreeItem.ts +282 -233
- package/src/tree/createTreeSelectionCheckbox.ts +68 -68
- package/src/tree/index.ts +16 -16
- package/src/tree/types.ts +91 -87
- package/src/utils/env.ts +55 -54
- package/src/utils/platform.ts +16 -6
- package/src/visually-hidden/createVisuallyHidden.ts +139 -124
- package/src/visually-hidden/index.ts +6 -6
package/src/dnd/createDrop.ts
CHANGED
|
@@ -1,321 +1,322 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* createDrop - ARIA hook for drop operations.
|
|
3
|
-
*
|
|
4
|
-
* Provides accessibility props for drop target elements with support for
|
|
5
|
-
* mouse, touch, and keyboard interactions.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { createMemo, type Accessor } from 'solid-js';
|
|
9
|
-
import { createDropState } from '@proyecto-viviana/solid-stately';
|
|
10
|
-
import type { AriaDropOptions, DropAria } from './types';
|
|
11
|
-
import {
|
|
12
|
-
readFromDataTransfer,
|
|
13
|
-
DragTypesImpl,
|
|
14
|
-
DROP_OPERATION,
|
|
15
|
-
DROP_OPERATION_ALLOWED,
|
|
16
|
-
DROP_OPERATION_TO_DROP_EFFECT,
|
|
17
|
-
DROP_EFFECT_TO_DROP_OPERATION,
|
|
18
|
-
setGlobalDropEffect,
|
|
19
|
-
getGlobalAllowedDropOperations,
|
|
20
|
-
} from './utils';
|
|
21
|
-
import type { DropOperation } from '@proyecto-viviana/solid-stately';
|
|
22
|
-
|
|
23
|
-
const DROP_ACTIVATE_TIMEOUT = 800;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Creates ARIA props for a drop target element.
|
|
27
|
-
*
|
|
28
|
-
* @param props - Accessor returning drop options
|
|
29
|
-
* @returns Drop ARIA props and state
|
|
30
|
-
*/
|
|
31
|
-
export function createDrop(props: Accessor<AriaDropOptions>): DropAria {
|
|
32
|
-
const getProps = createMemo(() => props());
|
|
33
|
-
|
|
34
|
-
// Create drop state
|
|
35
|
-
const state = createDropState(() => ({
|
|
36
|
-
getDropOperation: getProps().getDropOperation,
|
|
37
|
-
onDropEnter: getProps().onDropEnter,
|
|
38
|
-
onDropMove: getProps().onDropMove,
|
|
39
|
-
onDropActivate: getProps().onDropActivate,
|
|
40
|
-
onDropExit: getProps().onDropExit,
|
|
41
|
-
onDrop: getProps().onDrop,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
let
|
|
48
|
-
let
|
|
49
|
-
let
|
|
50
|
-
let
|
|
51
|
-
let
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (e.
|
|
82
|
-
if (e.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (e.
|
|
86
|
-
if (e.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (ops & DROP_OPERATION.
|
|
100
|
-
if (ops & DROP_OPERATION.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
e.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
e.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const
|
|
225
|
-
const
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
e.
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
e.
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
const
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* createDrop - ARIA hook for drop operations.
|
|
3
|
+
*
|
|
4
|
+
* Provides accessibility props for drop target elements with support for
|
|
5
|
+
* mouse, touch, and keyboard interactions.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { createMemo, type Accessor } from 'solid-js';
|
|
9
|
+
import { createDropState } from '@proyecto-viviana/solid-stately';
|
|
10
|
+
import type { AriaDropOptions, DropAria } from './types';
|
|
11
|
+
import {
|
|
12
|
+
readFromDataTransfer,
|
|
13
|
+
DragTypesImpl,
|
|
14
|
+
DROP_OPERATION,
|
|
15
|
+
DROP_OPERATION_ALLOWED,
|
|
16
|
+
DROP_OPERATION_TO_DROP_EFFECT,
|
|
17
|
+
DROP_EFFECT_TO_DROP_OPERATION,
|
|
18
|
+
setGlobalDropEffect,
|
|
19
|
+
getGlobalAllowedDropOperations,
|
|
20
|
+
} from './utils';
|
|
21
|
+
import type { DropOperation } from '@proyecto-viviana/solid-stately';
|
|
22
|
+
|
|
23
|
+
const DROP_ACTIVATE_TIMEOUT = 800;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Creates ARIA props for a drop target element.
|
|
27
|
+
*
|
|
28
|
+
* @param props - Accessor returning drop options
|
|
29
|
+
* @returns Drop ARIA props and state
|
|
30
|
+
*/
|
|
31
|
+
export function createDrop(props: Accessor<AriaDropOptions>): DropAria {
|
|
32
|
+
const getProps = createMemo(() => props());
|
|
33
|
+
|
|
34
|
+
// Create drop state
|
|
35
|
+
const state = createDropState(() => ({
|
|
36
|
+
getDropOperation: getProps().getDropOperation,
|
|
37
|
+
onDropEnter: getProps().onDropEnter,
|
|
38
|
+
onDropMove: getProps().onDropMove,
|
|
39
|
+
onDropActivate: getProps().onDropActivate,
|
|
40
|
+
onDropExit: getProps().onDropExit,
|
|
41
|
+
onDrop: getProps().onDrop,
|
|
42
|
+
hasDropButton: getProps().hasDropButton,
|
|
43
|
+
isDisabled: getProps().isDisabled,
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
// Track internal state
|
|
47
|
+
let x = 0;
|
|
48
|
+
let y = 0;
|
|
49
|
+
let dragOverElements = new Set<Element>();
|
|
50
|
+
let dropEffect: DataTransfer['dropEffect'] = 'none';
|
|
51
|
+
let allowedOperations = DROP_OPERATION.all;
|
|
52
|
+
let dropActivateTimer: ReturnType<typeof setTimeout> | undefined;
|
|
53
|
+
|
|
54
|
+
const fireDropEnter = (e: DragEvent) => {
|
|
55
|
+
const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
|
|
56
|
+
state.enterTarget(e.clientX - rect.x, e.clientY - rect.y);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const fireDropExit = (e: DragEvent) => {
|
|
60
|
+
const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
|
|
61
|
+
state.exitTarget(e.clientX - rect.x, e.clientY - rect.y);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const getAllowedOperations = (e: DragEvent): number => {
|
|
65
|
+
let allowed = DROP_OPERATION_ALLOWED[e.dataTransfer?.effectAllowed ?? 'none'] ?? DROP_OPERATION.none;
|
|
66
|
+
|
|
67
|
+
// Use global allowed operations if set (for internal drags)
|
|
68
|
+
const globalAllowed = getGlobalAllowedDropOperations();
|
|
69
|
+
if (globalAllowed) {
|
|
70
|
+
allowed &= globalAllowed;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Handle modifier keys for operation switching
|
|
74
|
+
let modifierAllowed = DROP_OPERATION.none;
|
|
75
|
+
|
|
76
|
+
// macOS: Alt=copy, Ctrl=link, Cmd=move
|
|
77
|
+
// Windows/Linux: Alt=link, Shift=move, Ctrl=copy
|
|
78
|
+
const isMac = typeof navigator !== 'undefined' && /mac/i.test(navigator.platform);
|
|
79
|
+
|
|
80
|
+
if (isMac) {
|
|
81
|
+
if (e.altKey) modifierAllowed |= DROP_OPERATION.copy;
|
|
82
|
+
if (e.ctrlKey) modifierAllowed |= DROP_OPERATION.link;
|
|
83
|
+
if (e.metaKey) modifierAllowed |= DROP_OPERATION.move;
|
|
84
|
+
} else {
|
|
85
|
+
if (e.altKey) modifierAllowed |= DROP_OPERATION.link;
|
|
86
|
+
if (e.shiftKey) modifierAllowed |= DROP_OPERATION.move;
|
|
87
|
+
if (e.ctrlKey) modifierAllowed |= DROP_OPERATION.copy;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (modifierAllowed) {
|
|
91
|
+
return allowed & modifierAllowed;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return allowed;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const allowedOperationsToArray = (ops: number): DropOperation[] => {
|
|
98
|
+
const result: DropOperation[] = [];
|
|
99
|
+
if (ops & DROP_OPERATION.move) result.push('move');
|
|
100
|
+
if (ops & DROP_OPERATION.copy) result.push('copy');
|
|
101
|
+
if (ops & DROP_OPERATION.link) result.push('link');
|
|
102
|
+
return result;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const getDropOperationForAllowed = (allowed: number, operation: DropOperation): DropOperation => {
|
|
106
|
+
const op = DROP_OPERATION[operation];
|
|
107
|
+
return allowed & op ? operation : 'cancel';
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const onDragEnter = (e: DragEvent) => {
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
e.stopPropagation();
|
|
113
|
+
|
|
114
|
+
dragOverElements.add(e.target as Element);
|
|
115
|
+
if (dragOverElements.size > 1) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const p = getProps();
|
|
120
|
+
const allowedOpsBits = getAllowedOperations(e);
|
|
121
|
+
const allowedOps = allowedOperationsToArray(allowedOpsBits);
|
|
122
|
+
let dropOp: DropOperation = allowedOps[0] ?? 'cancel';
|
|
123
|
+
|
|
124
|
+
if (typeof p.getDropOperation === 'function' && e.dataTransfer) {
|
|
125
|
+
const types = new DragTypesImpl(e.dataTransfer);
|
|
126
|
+
dropOp = getDropOperationForAllowed(
|
|
127
|
+
allowedOpsBits,
|
|
128
|
+
p.getDropOperation(types, allowedOps)
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (typeof p.getDropOperationForPoint === 'function' && e.dataTransfer) {
|
|
133
|
+
const types = new DragTypesImpl(e.dataTransfer);
|
|
134
|
+
const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
|
|
135
|
+
dropOp = getDropOperationForAllowed(
|
|
136
|
+
allowedOpsBits,
|
|
137
|
+
p.getDropOperationForPoint(types, allowedOps, e.clientX - rect.x, e.clientY - rect.y)
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
x = e.clientX;
|
|
142
|
+
y = e.clientY;
|
|
143
|
+
allowedOperations = allowedOpsBits;
|
|
144
|
+
dropEffect = (DROP_OPERATION_TO_DROP_EFFECT[dropOp] || 'none') as DataTransfer['dropEffect'];
|
|
145
|
+
|
|
146
|
+
if (e.dataTransfer) {
|
|
147
|
+
e.dataTransfer.dropEffect = dropEffect;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (dropOp !== 'cancel') {
|
|
151
|
+
fireDropEnter(e);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const onDragOver = (e: DragEvent) => {
|
|
156
|
+
e.preventDefault();
|
|
157
|
+
e.stopPropagation();
|
|
158
|
+
|
|
159
|
+
const allowedOpsBits = getAllowedOperations(e);
|
|
160
|
+
|
|
161
|
+
// Skip if position and operations haven't changed
|
|
162
|
+
if (e.clientX === x && e.clientY === y && allowedOpsBits === allowedOperations) {
|
|
163
|
+
if (e.dataTransfer) {
|
|
164
|
+
e.dataTransfer.dropEffect = dropEffect;
|
|
165
|
+
}
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
x = e.clientX;
|
|
170
|
+
y = e.clientY;
|
|
171
|
+
|
|
172
|
+
const prevDropEffect = dropEffect;
|
|
173
|
+
const p = getProps();
|
|
174
|
+
|
|
175
|
+
// Update drop effect if allowed operations changed
|
|
176
|
+
if (allowedOpsBits !== allowedOperations) {
|
|
177
|
+
const allowedOps = allowedOperationsToArray(allowedOpsBits);
|
|
178
|
+
let dropOp: DropOperation = allowedOps[0] ?? 'cancel';
|
|
179
|
+
|
|
180
|
+
if (typeof p.getDropOperation === 'function' && e.dataTransfer) {
|
|
181
|
+
const types = new DragTypesImpl(e.dataTransfer);
|
|
182
|
+
dropOp = getDropOperationForAllowed(
|
|
183
|
+
allowedOpsBits,
|
|
184
|
+
p.getDropOperation(types, allowedOps)
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
dropEffect = (DROP_OPERATION_TO_DROP_EFFECT[dropOp] || 'none') as DataTransfer['dropEffect'];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Check point-specific operation
|
|
191
|
+
if (typeof p.getDropOperationForPoint === 'function' && e.dataTransfer) {
|
|
192
|
+
const types = new DragTypesImpl(e.dataTransfer);
|
|
193
|
+
const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
|
|
194
|
+
const dropOp = getDropOperationForAllowed(
|
|
195
|
+
allowedOpsBits,
|
|
196
|
+
p.getDropOperationForPoint(types, allowedOperationsToArray(allowedOpsBits), x - rect.x, y - rect.y)
|
|
197
|
+
);
|
|
198
|
+
dropEffect = (DROP_OPERATION_TO_DROP_EFFECT[dropOp] || 'none') as DataTransfer['dropEffect'];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
allowedOperations = allowedOpsBits;
|
|
202
|
+
|
|
203
|
+
if (e.dataTransfer) {
|
|
204
|
+
e.dataTransfer.dropEffect = dropEffect;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Fire enter/exit events on drop effect change
|
|
208
|
+
if (dropEffect === 'none' && prevDropEffect !== 'none') {
|
|
209
|
+
fireDropExit(e);
|
|
210
|
+
} else if (dropEffect !== 'none' && prevDropEffect === 'none') {
|
|
211
|
+
fireDropEnter(e);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Fire move event
|
|
215
|
+
if (dropEffect !== 'none') {
|
|
216
|
+
const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
|
|
217
|
+
state.moveInTarget(x - rect.x, y - rect.y);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Handle drop activate timer
|
|
221
|
+
clearTimeout(dropActivateTimer);
|
|
222
|
+
|
|
223
|
+
if (typeof p.onDropActivate === 'function' && dropEffect !== 'none') {
|
|
224
|
+
const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
|
|
225
|
+
const activateX = x - rect.x;
|
|
226
|
+
const activateY = y - rect.y;
|
|
227
|
+
dropActivateTimer = setTimeout(() => {
|
|
228
|
+
state.activateTarget(activateX, activateY);
|
|
229
|
+
}, DROP_ACTIVATE_TIMEOUT);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
const onDragLeave = (e: DragEvent) => {
|
|
234
|
+
e.preventDefault();
|
|
235
|
+
e.stopPropagation();
|
|
236
|
+
|
|
237
|
+
// Track drag over elements (WebKit workaround for relatedTarget being null)
|
|
238
|
+
dragOverElements.delete(e.target as Element);
|
|
239
|
+
|
|
240
|
+
// Remove elements no longer in DOM
|
|
241
|
+
for (const element of dragOverElements) {
|
|
242
|
+
if (!e.currentTarget || !(e.currentTarget as Element).contains(element)) {
|
|
243
|
+
dragOverElements.delete(element);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (dragOverElements.size > 0) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (dropEffect !== 'none') {
|
|
252
|
+
fireDropExit(e);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
clearTimeout(dropActivateTimer);
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
const onDropHandler = (e: DragEvent) => {
|
|
259
|
+
e.preventDefault();
|
|
260
|
+
e.stopPropagation();
|
|
261
|
+
|
|
262
|
+
// Track drop effect globally for Chrome Android
|
|
263
|
+
setGlobalDropEffect(dropEffect);
|
|
264
|
+
|
|
265
|
+
const p = getProps();
|
|
266
|
+
if (typeof p.onDrop === 'function' && e.dataTransfer) {
|
|
267
|
+
const items = readFromDataTransfer(e.dataTransfer);
|
|
268
|
+
const dropOperation = DROP_EFFECT_TO_DROP_OPERATION[dropEffect];
|
|
269
|
+
const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
|
|
270
|
+
|
|
271
|
+
state.drop(e.clientX - rect.x, e.clientY - rect.y, items, dropOperation);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
dragOverElements.clear();
|
|
275
|
+
fireDropExit(e);
|
|
276
|
+
clearTimeout(dropActivateTimer);
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
const dropProps = createMemo(() => {
|
|
280
|
+
const p = getProps();
|
|
281
|
+
|
|
282
|
+
if (p.isDisabled) {
|
|
283
|
+
return {};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const baseProps: Record<string, unknown> = {
|
|
287
|
+
onDragEnter,
|
|
288
|
+
onDragOver,
|
|
289
|
+
onDragLeave,
|
|
290
|
+
onDrop: onDropHandler,
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
return baseProps;
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
const dropButtonProps = createMemo(() => {
|
|
297
|
+
const p = getProps();
|
|
298
|
+
|
|
299
|
+
if (p.isDisabled) {
|
|
300
|
+
return {
|
|
301
|
+
disabled: true,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
return {
|
|
306
|
+
type: 'button' as const,
|
|
307
|
+
'aria-label': 'Drop',
|
|
308
|
+
};
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
return {
|
|
312
|
+
get dropProps() {
|
|
313
|
+
return dropProps() as DropAria['dropProps'];
|
|
314
|
+
},
|
|
315
|
+
get isDropTarget() {
|
|
316
|
+
return state.isDropTarget;
|
|
317
|
+
},
|
|
318
|
+
get dropButtonProps() {
|
|
319
|
+
return dropButtonProps() as DropAria['dropButtonProps'];
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
}
|