@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
|
@@ -1,213 +1,215 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* createDroppableItem - ARIA hook for droppable items within a collection.
|
|
3
|
-
*
|
|
4
|
-
* Provides accessibility props for items that can receive drops.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { createMemo, type Accessor } from 'solid-js';
|
|
8
|
-
import type { JSX } from 'solid-js';
|
|
9
|
-
import type {
|
|
10
|
-
DroppableCollectionState,
|
|
11
|
-
DropTarget,
|
|
12
|
-
DropOperation,
|
|
13
|
-
} from '@proyecto-viviana/solid-stately';
|
|
14
|
-
import {
|
|
15
|
-
DragTypesImpl,
|
|
16
|
-
DROP_OPERATION,
|
|
17
|
-
DROP_OPERATION_ALLOWED,
|
|
18
|
-
DROP_OPERATION_TO_DROP_EFFECT,
|
|
19
|
-
getGlobalAllowedDropOperations,
|
|
20
|
-
} from './utils';
|
|
21
|
-
|
|
22
|
-
export interface DroppableItemOptions {
|
|
23
|
-
/** The unique key of the item. */
|
|
24
|
-
key: string | number;
|
|
25
|
-
/** Reference to the item element. */
|
|
26
|
-
ref: Accessor<HTMLElement | null>;
|
|
27
|
-
/** Whether this item is disabled for dropping. */
|
|
28
|
-
isDisabled?: boolean;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface DroppableItemAria {
|
|
32
|
-
/** Props for the droppable item element. */
|
|
33
|
-
dropProps: JSX.HTMLAttributes<HTMLElement>;
|
|
34
|
-
/** Whether the item is currently a drop target. */
|
|
35
|
-
isDropTarget: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Creates ARIA props for a droppable item within a collection.
|
|
40
|
-
*
|
|
41
|
-
* @param options - Accessor returning item options
|
|
42
|
-
* @param state - Droppable collection state
|
|
43
|
-
* @returns Droppable item ARIA props
|
|
44
|
-
*/
|
|
45
|
-
export function createDroppableItem(
|
|
46
|
-
options: Accessor<DroppableItemOptions>,
|
|
47
|
-
state: DroppableCollectionState
|
|
48
|
-
): DroppableItemAria {
|
|
49
|
-
const getOptions = createMemo(() => options());
|
|
50
|
-
|
|
51
|
-
const isDropTarget = createMemo(() => {
|
|
52
|
-
const { key } = getOptions();
|
|
53
|
-
const target = state.target;
|
|
54
|
-
return target?.type === 'item' && target.key === key;
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const getTarget = (dropPosition: 'before' | 'on' | 'after'): DropTarget => {
|
|
58
|
-
const { key } = getOptions();
|
|
59
|
-
return {
|
|
60
|
-
type: 'item',
|
|
61
|
-
key,
|
|
62
|
-
dropPosition,
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const getDropOperation = (
|
|
67
|
-
e: DragEvent,
|
|
68
|
-
target: DropTarget
|
|
69
|
-
): DropOperation => {
|
|
70
|
-
if (!e.dataTransfer) return 'cancel';
|
|
71
|
-
|
|
72
|
-
const types = new DragTypesImpl(e.dataTransfer);
|
|
73
|
-
let allowedBits =
|
|
74
|
-
DROP_OPERATION_ALLOWED[e.dataTransfer.effectAllowed] || DROP_OPERATION.all;
|
|
75
|
-
|
|
76
|
-
// Use global allowed operations for internal drags
|
|
77
|
-
const globalAllowed = getGlobalAllowedDropOperations();
|
|
78
|
-
if (globalAllowed) {
|
|
79
|
-
allowedBits &= globalAllowed;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const allowedOperations: DropOperation[] = [];
|
|
83
|
-
if (allowedBits & DROP_OPERATION.move) allowedOperations.push('move');
|
|
84
|
-
if (allowedBits & DROP_OPERATION.copy) allowedOperations.push('copy');
|
|
85
|
-
if (allowedBits & DROP_OPERATION.link) allowedOperations.push('link');
|
|
86
|
-
|
|
87
|
-
return state.getDropOperation(target, types, allowedOperations);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
let dropActivateTimer: ReturnType<typeof setTimeout> | undefined;
|
|
91
|
-
const DROP_ACTIVATE_TIMEOUT = 800;
|
|
92
|
-
|
|
93
|
-
const onDragEnter = (e: DragEvent) => {
|
|
94
|
-
e.preventDefault();
|
|
95
|
-
e.stopPropagation();
|
|
96
|
-
|
|
97
|
-
const opts = getOptions();
|
|
98
|
-
if (opts.isDisabled) return;
|
|
99
|
-
|
|
100
|
-
// Determine drop position based on cursor position
|
|
101
|
-
const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
e.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
dropPosition = '
|
|
140
|
-
} else {
|
|
141
|
-
dropPosition = '
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* createDroppableItem - ARIA hook for droppable items within a collection.
|
|
3
|
+
*
|
|
4
|
+
* Provides accessibility props for items that can receive drops.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { createMemo, type Accessor } from 'solid-js';
|
|
8
|
+
import type { JSX } from 'solid-js';
|
|
9
|
+
import type {
|
|
10
|
+
DroppableCollectionState,
|
|
11
|
+
DropTarget,
|
|
12
|
+
DropOperation,
|
|
13
|
+
} from '@proyecto-viviana/solid-stately';
|
|
14
|
+
import {
|
|
15
|
+
DragTypesImpl,
|
|
16
|
+
DROP_OPERATION,
|
|
17
|
+
DROP_OPERATION_ALLOWED,
|
|
18
|
+
DROP_OPERATION_TO_DROP_EFFECT,
|
|
19
|
+
getGlobalAllowedDropOperations,
|
|
20
|
+
} from './utils';
|
|
21
|
+
|
|
22
|
+
export interface DroppableItemOptions {
|
|
23
|
+
/** The unique key of the item. */
|
|
24
|
+
key: string | number;
|
|
25
|
+
/** Reference to the item element. */
|
|
26
|
+
ref: Accessor<HTMLElement | null>;
|
|
27
|
+
/** Whether this item is disabled for dropping. */
|
|
28
|
+
isDisabled?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface DroppableItemAria {
|
|
32
|
+
/** Props for the droppable item element. */
|
|
33
|
+
dropProps: JSX.HTMLAttributes<HTMLElement>;
|
|
34
|
+
/** Whether the item is currently a drop target. */
|
|
35
|
+
isDropTarget: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Creates ARIA props for a droppable item within a collection.
|
|
40
|
+
*
|
|
41
|
+
* @param options - Accessor returning item options
|
|
42
|
+
* @param state - Droppable collection state
|
|
43
|
+
* @returns Droppable item ARIA props
|
|
44
|
+
*/
|
|
45
|
+
export function createDroppableItem(
|
|
46
|
+
options: Accessor<DroppableItemOptions>,
|
|
47
|
+
state: DroppableCollectionState
|
|
48
|
+
): DroppableItemAria {
|
|
49
|
+
const getOptions = createMemo(() => options());
|
|
50
|
+
|
|
51
|
+
const isDropTarget = createMemo(() => {
|
|
52
|
+
const { key } = getOptions();
|
|
53
|
+
const target = state.target;
|
|
54
|
+
return target?.type === 'item' && target.key === key;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const getTarget = (dropPosition: 'before' | 'on' | 'after'): DropTarget => {
|
|
58
|
+
const { key } = getOptions();
|
|
59
|
+
return {
|
|
60
|
+
type: 'item',
|
|
61
|
+
key,
|
|
62
|
+
dropPosition,
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const getDropOperation = (
|
|
67
|
+
e: DragEvent,
|
|
68
|
+
target: DropTarget
|
|
69
|
+
): DropOperation => {
|
|
70
|
+
if (!e.dataTransfer) return 'cancel';
|
|
71
|
+
|
|
72
|
+
const types = new DragTypesImpl(e.dataTransfer);
|
|
73
|
+
let allowedBits =
|
|
74
|
+
DROP_OPERATION_ALLOWED[e.dataTransfer.effectAllowed] || DROP_OPERATION.all;
|
|
75
|
+
|
|
76
|
+
// Use global allowed operations for internal drags
|
|
77
|
+
const globalAllowed = getGlobalAllowedDropOperations();
|
|
78
|
+
if (globalAllowed) {
|
|
79
|
+
allowedBits &= globalAllowed;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const allowedOperations: DropOperation[] = [];
|
|
83
|
+
if (allowedBits & DROP_OPERATION.move) allowedOperations.push('move');
|
|
84
|
+
if (allowedBits & DROP_OPERATION.copy) allowedOperations.push('copy');
|
|
85
|
+
if (allowedBits & DROP_OPERATION.link) allowedOperations.push('link');
|
|
86
|
+
|
|
87
|
+
return state.getDropOperation(target, types, allowedOperations);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
let dropActivateTimer: ReturnType<typeof setTimeout> | undefined;
|
|
91
|
+
const DROP_ACTIVATE_TIMEOUT = 800;
|
|
92
|
+
|
|
93
|
+
const onDragEnter = (e: DragEvent) => {
|
|
94
|
+
e.preventDefault();
|
|
95
|
+
e.stopPropagation();
|
|
96
|
+
|
|
97
|
+
const opts = getOptions();
|
|
98
|
+
if (opts.isDisabled) return;
|
|
99
|
+
|
|
100
|
+
// Determine drop position based on cursor position
|
|
101
|
+
const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
|
|
102
|
+
const x = e.clientX - rect.x;
|
|
103
|
+
const y = e.clientY - rect.y;
|
|
104
|
+
const height = rect.height;
|
|
105
|
+
|
|
106
|
+
let dropPosition: 'before' | 'on' | 'after';
|
|
107
|
+
if (y < height * 0.25) {
|
|
108
|
+
dropPosition = 'before';
|
|
109
|
+
} else if (y > height * 0.75) {
|
|
110
|
+
dropPosition = 'after';
|
|
111
|
+
} else {
|
|
112
|
+
dropPosition = 'on';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const target = getTarget(dropPosition);
|
|
116
|
+
const operation = getDropOperation(e, target);
|
|
117
|
+
|
|
118
|
+
if (operation !== 'cancel') {
|
|
119
|
+
state.setTarget(target);
|
|
120
|
+
e.dataTransfer!.dropEffect = DROP_OPERATION_TO_DROP_EFFECT[operation] as DataTransfer['dropEffect'];
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const onDragOver = (e: DragEvent) => {
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
e.stopPropagation();
|
|
127
|
+
|
|
128
|
+
const opts = getOptions();
|
|
129
|
+
if (opts.isDisabled) return;
|
|
130
|
+
|
|
131
|
+
// Update drop position based on cursor
|
|
132
|
+
const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
|
|
133
|
+
const x = e.clientX - rect.x;
|
|
134
|
+
const y = e.clientY - rect.y;
|
|
135
|
+
const height = rect.height;
|
|
136
|
+
|
|
137
|
+
let dropPosition: 'before' | 'on' | 'after';
|
|
138
|
+
if (y < height * 0.25) {
|
|
139
|
+
dropPosition = 'before';
|
|
140
|
+
} else if (y > height * 0.75) {
|
|
141
|
+
dropPosition = 'after';
|
|
142
|
+
} else {
|
|
143
|
+
dropPosition = 'on';
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const target = getTarget(dropPosition);
|
|
147
|
+
const operation = getDropOperation(e, target);
|
|
148
|
+
|
|
149
|
+
if (operation !== 'cancel') {
|
|
150
|
+
state.setTarget(target);
|
|
151
|
+
e.dataTransfer!.dropEffect = DROP_OPERATION_TO_DROP_EFFECT[operation] as DataTransfer['dropEffect'];
|
|
152
|
+
|
|
153
|
+
// Handle drop activate for 'on' position
|
|
154
|
+
clearTimeout(dropActivateTimer);
|
|
155
|
+
if (dropPosition === 'on') {
|
|
156
|
+
dropActivateTimer = setTimeout(() => {
|
|
157
|
+
state.activateTarget(x, y);
|
|
158
|
+
}, DROP_ACTIVATE_TIMEOUT);
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
e.dataTransfer!.dropEffect = 'none';
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const onDragLeave = (e: DragEvent) => {
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
e.stopPropagation();
|
|
168
|
+
|
|
169
|
+
clearTimeout(dropActivateTimer);
|
|
170
|
+
|
|
171
|
+
// Only clear target if leaving this item
|
|
172
|
+
const relatedTarget = e.relatedTarget as HTMLElement | null;
|
|
173
|
+
const currentTarget = e.currentTarget as HTMLElement;
|
|
174
|
+
if (!relatedTarget || !currentTarget.contains(relatedTarget)) {
|
|
175
|
+
// Clear if no longer over this item
|
|
176
|
+
const { key } = getOptions();
|
|
177
|
+
if (state.target?.type === 'item' && state.target.key === key) {
|
|
178
|
+
// State clearing handled by parent collection
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const onDrop = (e: DragEvent) => {
|
|
184
|
+
e.preventDefault();
|
|
185
|
+
e.stopPropagation();
|
|
186
|
+
|
|
187
|
+
clearTimeout(dropActivateTimer);
|
|
188
|
+
|
|
189
|
+
// Drop handling is done by the parent collection
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const dropProps = createMemo(() => {
|
|
193
|
+
const opts = getOptions();
|
|
194
|
+
|
|
195
|
+
if (opts.isDisabled) {
|
|
196
|
+
return {};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
onDragEnter,
|
|
201
|
+
onDragOver,
|
|
202
|
+
onDragLeave,
|
|
203
|
+
onDrop,
|
|
204
|
+
};
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
return {
|
|
208
|
+
get dropProps() {
|
|
209
|
+
return dropProps() as DroppableItemAria['dropProps'];
|
|
210
|
+
},
|
|
211
|
+
get isDropTarget() {
|
|
212
|
+
return isDropTarget();
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
}
|
package/src/dnd/index.ts
CHANGED
|
@@ -1,47 +1,55 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Drag and Drop module for solidaria.
|
|
3
|
-
*
|
|
4
|
-
* Provides ARIA hooks for drag and drop interactions.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// Basic drag/drop hooks
|
|
8
|
-
export { createDrag } from './createDrag';
|
|
9
|
-
export { createDrop } from './createDrop';
|
|
10
|
-
|
|
11
|
-
// Collection hooks
|
|
12
|
-
export {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
export
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Drag and Drop module for solidaria.
|
|
3
|
+
*
|
|
4
|
+
* Provides ARIA hooks for drag and drop interactions.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// Basic drag/drop hooks
|
|
8
|
+
export { createDrag } from './createDrag';
|
|
9
|
+
export { createDrop } from './createDrop';
|
|
10
|
+
|
|
11
|
+
// Collection hooks
|
|
12
|
+
export {
|
|
13
|
+
createDraggableCollection,
|
|
14
|
+
setGlobalDraggingCollectionRef,
|
|
15
|
+
getGlobalDraggingCollectionRef,
|
|
16
|
+
setGlobalDraggingKeys,
|
|
17
|
+
getGlobalDraggingKeys,
|
|
18
|
+
setGlobalDraggingTypes,
|
|
19
|
+
getGlobalDraggingTypes,
|
|
20
|
+
} from './createDraggableCollection';
|
|
21
|
+
export { createDroppableCollection, setGlobalDropCollectionRef, getGlobalDropCollectionRef } from './createDroppableCollection';
|
|
22
|
+
|
|
23
|
+
// Item hooks
|
|
24
|
+
export { createDraggableItem } from './createDraggableItem';
|
|
25
|
+
export { createDroppableItem } from './createDroppableItem';
|
|
26
|
+
|
|
27
|
+
// Types
|
|
28
|
+
export type { AriaDragOptions, DragAria, AriaDropOptions, DropAria } from './types';
|
|
29
|
+
export type { DraggableCollectionOptions, DraggableCollectionAria } from './createDraggableCollection';
|
|
30
|
+
export type { DroppableCollectionOptions, DroppableCollectionAria, DropTargetDelegate } from './createDroppableCollection';
|
|
31
|
+
export type { DraggableItemOptions, DraggableItemAria } from './createDraggableItem';
|
|
32
|
+
export type { DroppableItemOptions, DroppableItemAria } from './createDroppableItem';
|
|
33
|
+
|
|
34
|
+
// Utilities
|
|
35
|
+
export {
|
|
36
|
+
CUSTOM_DRAG_TYPE,
|
|
37
|
+
NATIVE_DRAG_TYPES,
|
|
38
|
+
GENERIC_TYPE,
|
|
39
|
+
DROP_OPERATION,
|
|
40
|
+
DROP_OPERATION_ALLOWED,
|
|
41
|
+
EFFECT_ALLOWED,
|
|
42
|
+
DROP_EFFECT_TO_DROP_OPERATION,
|
|
43
|
+
DROP_OPERATION_TO_DROP_EFFECT,
|
|
44
|
+
getTypes,
|
|
45
|
+
writeToDataTransfer,
|
|
46
|
+
readFromDataTransfer,
|
|
47
|
+
DragTypesImpl,
|
|
48
|
+
isTextDropItem,
|
|
49
|
+
isFileDropItem,
|
|
50
|
+
isDirectoryDropItem,
|
|
51
|
+
setGlobalDropEffect,
|
|
52
|
+
getGlobalDropEffect,
|
|
53
|
+
setGlobalAllowedDropOperations,
|
|
54
|
+
getGlobalAllowedDropOperations,
|
|
55
|
+
} from './utils';
|