@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
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { type JSX, createMemo } from 'solid-js';
|
|
10
10
|
import { type DisclosureGroupState } from '@proyecto-viviana/solid-stately';
|
|
11
|
+
import { access, type MaybeAccessor } from '../utils/reactivity';
|
|
11
12
|
|
|
12
13
|
// ============================================
|
|
13
14
|
// TYPES
|
|
@@ -48,12 +49,14 @@ export interface DisclosureGroupAria {
|
|
|
48
49
|
* ```
|
|
49
50
|
*/
|
|
50
51
|
export function createDisclosureGroup(
|
|
51
|
-
props: AriaDisclosureGroupProps
|
|
52
|
+
props: MaybeAccessor<AriaDisclosureGroupProps>,
|
|
52
53
|
state: DisclosureGroupState
|
|
53
54
|
): DisclosureGroupAria {
|
|
55
|
+
const getProps = () => access(props);
|
|
56
|
+
|
|
54
57
|
const groupProps = createMemo<JSX.HTMLAttributes<HTMLElement>>(() => ({
|
|
55
58
|
role: 'group',
|
|
56
|
-
'aria-disabled':
|
|
59
|
+
'aria-disabled': getProps().isDisabled || state.isDisabled || undefined,
|
|
57
60
|
}));
|
|
58
61
|
|
|
59
62
|
return {
|
package/src/dnd/createDrag.ts
CHANGED
|
@@ -1,209 +1,224 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* createDrag - ARIA hook for drag operations.
|
|
3
|
-
*
|
|
4
|
-
* Provides accessibility props for draggable elements with support for
|
|
5
|
-
* mouse, touch, and keyboard interactions.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { createMemo, type Accessor } from 'solid-js';
|
|
9
|
-
import { createDragState } from '@proyecto-viviana/solid-stately';
|
|
10
|
-
import type { AriaDragOptions, DragAria } from './types';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
offsetX =
|
|
98
|
-
offsetY =
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
return
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
1
|
+
/**
|
|
2
|
+
* createDrag - ARIA hook for drag operations.
|
|
3
|
+
*
|
|
4
|
+
* Provides accessibility props for draggable elements with support for
|
|
5
|
+
* mouse, touch, and keyboard interactions.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { createMemo, type Accessor } from 'solid-js';
|
|
9
|
+
import { createDragState } from '@proyecto-viviana/solid-stately';
|
|
10
|
+
import type { AriaDragOptions, DragAria } from './types';
|
|
11
|
+
import {
|
|
12
|
+
getTypes,
|
|
13
|
+
writeToDataTransfer,
|
|
14
|
+
DROP_OPERATION,
|
|
15
|
+
EFFECT_ALLOWED,
|
|
16
|
+
DROP_EFFECT_TO_DROP_OPERATION,
|
|
17
|
+
setGlobalAllowedDropOperations,
|
|
18
|
+
setGlobalDropEffect,
|
|
19
|
+
getGlobalDropEffect,
|
|
20
|
+
} from './utils';
|
|
21
|
+
import { setGlobalDraggingTypes } from './createDraggableCollection';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates ARIA props for a draggable element.
|
|
25
|
+
*
|
|
26
|
+
* @param props - Accessor returning drag options
|
|
27
|
+
* @returns Drag ARIA props and state
|
|
28
|
+
*/
|
|
29
|
+
export function createDrag(props: Accessor<AriaDragOptions>): DragAria {
|
|
30
|
+
const getProps = createMemo(() => props());
|
|
31
|
+
|
|
32
|
+
// Create drag state
|
|
33
|
+
const state = createDragState(() => ({
|
|
34
|
+
getItems: getProps().getItems,
|
|
35
|
+
getAllowedDropOperations: getProps().getAllowedDropOperations,
|
|
36
|
+
onDragStart: getProps().onDragStart,
|
|
37
|
+
onDragMove: getProps().onDragMove,
|
|
38
|
+
onDragEnd: getProps().onDragEnd,
|
|
39
|
+
isDisabled: getProps().isDisabled,
|
|
40
|
+
hasDragButton: getProps().hasDragButton,
|
|
41
|
+
preview: getProps().preview,
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
// Track position for drag move
|
|
45
|
+
let lastX = 0;
|
|
46
|
+
let lastY = 0;
|
|
47
|
+
|
|
48
|
+
const onDragStart = (e: DragEvent) => {
|
|
49
|
+
if (e.defaultPrevented) return;
|
|
50
|
+
e.stopPropagation();
|
|
51
|
+
|
|
52
|
+
const p = getProps();
|
|
53
|
+
|
|
54
|
+
// Call state handler
|
|
55
|
+
state.startDrag(e.clientX, e.clientY);
|
|
56
|
+
|
|
57
|
+
// Get items and write to data transfer
|
|
58
|
+
const items = state.getItems();
|
|
59
|
+
setGlobalDraggingTypes(getTypes(items));
|
|
60
|
+
e.dataTransfer?.clearData?.();
|
|
61
|
+
if (e.dataTransfer) {
|
|
62
|
+
writeToDataTransfer(e.dataTransfer, items);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Set allowed drop operations
|
|
66
|
+
let allowed = DROP_OPERATION.all;
|
|
67
|
+
const allowedOps = state.getAllowedDropOperations();
|
|
68
|
+
if (allowedOps.length > 0) {
|
|
69
|
+
allowed = DROP_OPERATION.none;
|
|
70
|
+
for (const op of allowedOps) {
|
|
71
|
+
allowed |= DROP_OPERATION[op] || DROP_OPERATION.none;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
setGlobalAllowedDropOperations(allowed);
|
|
76
|
+
const effectAllowed = EFFECT_ALLOWED[allowed] || 'none';
|
|
77
|
+
if (e.dataTransfer) {
|
|
78
|
+
e.dataTransfer.effectAllowed =
|
|
79
|
+
(effectAllowed === 'cancel' ? 'none' : effectAllowed) as DataTransfer['effectAllowed'];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Handle custom preview
|
|
83
|
+
if (typeof p.preview?.current === 'function' && e.dataTransfer) {
|
|
84
|
+
p.preview.current(items, (node, userX, userY) => {
|
|
85
|
+
if (!node || !e.dataTransfer) return;
|
|
86
|
+
|
|
87
|
+
const size = node.getBoundingClientRect();
|
|
88
|
+
const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
|
|
89
|
+
let defaultX = e.clientX - rect.x;
|
|
90
|
+
let defaultY = e.clientY - rect.y;
|
|
91
|
+
|
|
92
|
+
if (defaultX > size.width || defaultY > size.height) {
|
|
93
|
+
defaultX = size.width / 2;
|
|
94
|
+
defaultY = size.height / 2;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let offsetX = typeof userX === 'number' ? userX : defaultX;
|
|
98
|
+
let offsetY = typeof userY === 'number' ? userY : defaultY;
|
|
99
|
+
|
|
100
|
+
offsetX = Math.max(0, Math.min(offsetX, size.width));
|
|
101
|
+
offsetY = Math.max(0, Math.min(offsetY, size.height));
|
|
102
|
+
|
|
103
|
+
e.dataTransfer.setDragImage(node, offsetX, offsetY);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
lastX = e.clientX;
|
|
108
|
+
lastY = e.clientY;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const onDrag = (e: DragEvent) => {
|
|
112
|
+
e.stopPropagation();
|
|
113
|
+
|
|
114
|
+
if (e.clientX === lastX && e.clientY === lastY) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
state.moveDrag(e.clientX, e.clientY);
|
|
119
|
+
|
|
120
|
+
lastX = e.clientX;
|
|
121
|
+
lastY = e.clientY;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const onDragEnd = (e: DragEvent) => {
|
|
125
|
+
e.stopPropagation();
|
|
126
|
+
|
|
127
|
+
let dropEffect: string = e.dataTransfer?.dropEffect ?? 'none';
|
|
128
|
+
// Chrome Android fix - use global drop effect
|
|
129
|
+
if (getGlobalDropEffect()) {
|
|
130
|
+
dropEffect = getGlobalDropEffect()!;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const dropOperation = DROP_EFFECT_TO_DROP_OPERATION[dropEffect];
|
|
134
|
+
state.endDrag(e.clientX, e.clientY, dropOperation);
|
|
135
|
+
|
|
136
|
+
setGlobalAllowedDropOperations(DROP_OPERATION.none);
|
|
137
|
+
setGlobalDraggingTypes(new Set());
|
|
138
|
+
setGlobalDropEffect(undefined);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// Keyboard/screen reader drag initiation
|
|
142
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
143
|
+
if (e.key === 'Enter' && e.target === e.currentTarget) {
|
|
144
|
+
e.preventDefault();
|
|
145
|
+
e.stopPropagation();
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const onKeyUp = (e: KeyboardEvent) => {
|
|
150
|
+
if (e.key === 'Enter' && e.target === e.currentTarget) {
|
|
151
|
+
e.preventDefault();
|
|
152
|
+
e.stopPropagation();
|
|
153
|
+
// Would initiate keyboard-based drag mode
|
|
154
|
+
// This is a simplified version - full implementation needs DragManager
|
|
155
|
+
const rect = (e.target as HTMLElement).getBoundingClientRect();
|
|
156
|
+
state.startDrag(rect.x + rect.width / 2, rect.y + rect.height / 2);
|
|
157
|
+
const items = state.getItems();
|
|
158
|
+
setGlobalDraggingTypes(getTypes(items));
|
|
159
|
+
let allowed = DROP_OPERATION.all;
|
|
160
|
+
const allowedOps = state.getAllowedDropOperations();
|
|
161
|
+
if (allowedOps.length > 0) {
|
|
162
|
+
allowed = DROP_OPERATION.none;
|
|
163
|
+
for (const op of allowedOps) {
|
|
164
|
+
allowed |= DROP_OPERATION[op] || DROP_OPERATION.none;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
setGlobalAllowedDropOperations(allowed);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const dragProps = createMemo(() => {
|
|
172
|
+
const p = getProps();
|
|
173
|
+
|
|
174
|
+
if (p.isDisabled) {
|
|
175
|
+
return {
|
|
176
|
+
draggable: false as const,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const baseProps: Record<string, unknown> = {
|
|
181
|
+
draggable: true as const,
|
|
182
|
+
onDragStart,
|
|
183
|
+
onDrag,
|
|
184
|
+
onDragEnd,
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// Add keyboard handlers if no separate drag button
|
|
188
|
+
if (!p.hasDragButton) {
|
|
189
|
+
baseProps.onKeyDown = onKeyDown;
|
|
190
|
+
baseProps.onKeyUp = onKeyUp;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return baseProps;
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
const dragButtonProps = createMemo(() => {
|
|
197
|
+
const p = getProps();
|
|
198
|
+
|
|
199
|
+
if (p.isDisabled) {
|
|
200
|
+
return {
|
|
201
|
+
disabled: true,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return {
|
|
206
|
+
type: 'button' as const,
|
|
207
|
+
'aria-label': 'Drag',
|
|
208
|
+
onKeyDown,
|
|
209
|
+
onKeyUp,
|
|
210
|
+
};
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
return {
|
|
214
|
+
get dragProps() {
|
|
215
|
+
return dragProps() as DragAria['dragProps'];
|
|
216
|
+
},
|
|
217
|
+
get dragButtonProps() {
|
|
218
|
+
return dragButtonProps() as DragAria['dragButtonProps'];
|
|
219
|
+
},
|
|
220
|
+
get isDragging() {
|
|
221
|
+
return state.isDragging;
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
}
|
|
@@ -1,63 +1,96 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* createDraggableCollection - ARIA hook for draggable collection items.
|
|
3
|
-
*
|
|
4
|
-
* Provides accessibility support for dragging items from a collection
|
|
5
|
-
* component like ListBox, GridList, or Table.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { createMemo, createEffect, onCleanup, type Accessor } from 'solid-js';
|
|
9
|
-
import type { DraggableCollectionState } from '@proyecto-viviana/solid-stately';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
1
|
+
/**
|
|
2
|
+
* createDraggableCollection - ARIA hook for draggable collection items.
|
|
3
|
+
*
|
|
4
|
+
* Provides accessibility support for dragging items from a collection
|
|
5
|
+
* component like ListBox, GridList, or Table.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { createMemo, createEffect, onCleanup, type Accessor } from 'solid-js';
|
|
9
|
+
import type { DraggableCollectionState } from '@proyecto-viviana/solid-stately';
|
|
10
|
+
import { getTypes } from './utils';
|
|
11
|
+
|
|
12
|
+
// Global state for tracking the dragging collection
|
|
13
|
+
let globalDraggingCollectionRef: HTMLElement | null = null;
|
|
14
|
+
let globalDraggingKeys: Set<string | number> = new Set();
|
|
15
|
+
let globalDraggingTypes: Set<string> = new Set();
|
|
16
|
+
|
|
17
|
+
export function setGlobalDraggingCollectionRef(ref: HTMLElement | null): void {
|
|
18
|
+
globalDraggingCollectionRef = ref;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function getGlobalDraggingCollectionRef(): HTMLElement | null {
|
|
22
|
+
return globalDraggingCollectionRef;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function setGlobalDraggingKeys(keys: Set<string | number>): void {
|
|
26
|
+
globalDraggingKeys = new Set(keys);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getGlobalDraggingKeys(): Set<string | number> {
|
|
30
|
+
return new Set(globalDraggingKeys);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function setGlobalDraggingTypes(types: Set<string>): void {
|
|
34
|
+
globalDraggingTypes = new Set(types);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getGlobalDraggingTypes(): Set<string> {
|
|
38
|
+
return new Set(globalDraggingTypes);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface DraggableCollectionOptions {
|
|
42
|
+
/** Reference to the collection element. */
|
|
43
|
+
ref: Accessor<HTMLElement | null>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface DraggableCollectionAria {
|
|
47
|
+
/** The draggable collection state. */
|
|
48
|
+
state: DraggableCollectionState;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Creates ARIA support for a draggable collection.
|
|
53
|
+
*
|
|
54
|
+
* @param _options - Collection options
|
|
55
|
+
* @param state - Draggable collection state
|
|
56
|
+
* @returns Draggable collection ARIA result
|
|
57
|
+
*/
|
|
58
|
+
export function createDraggableCollection(
|
|
59
|
+
options: DraggableCollectionOptions,
|
|
60
|
+
state: DraggableCollectionState
|
|
61
|
+
): DraggableCollectionAria {
|
|
62
|
+
const ref = createMemo(() => options.ref());
|
|
63
|
+
|
|
64
|
+
// Track dragging state globally
|
|
65
|
+
createEffect(() => {
|
|
66
|
+
const currentRef = ref();
|
|
67
|
+
if (state.draggingKeys.size > 0) {
|
|
68
|
+
if (globalDraggingCollectionRef !== currentRef) {
|
|
69
|
+
setGlobalDraggingCollectionRef(currentRef);
|
|
70
|
+
}
|
|
71
|
+
setGlobalDraggingKeys(state.draggingKeys);
|
|
72
|
+
setGlobalDraggingTypes(getTypes(state.getItems(state.draggingKeys)));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Clear global drag tracking when this collection is no longer dragging.
|
|
77
|
+
if (globalDraggingCollectionRef === currentRef) {
|
|
78
|
+
setGlobalDraggingCollectionRef(null);
|
|
79
|
+
setGlobalDraggingKeys(new Set());
|
|
80
|
+
setGlobalDraggingTypes(new Set());
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Clean up on unmount
|
|
85
|
+
onCleanup(() => {
|
|
86
|
+
if (globalDraggingCollectionRef === ref()) {
|
|
87
|
+
setGlobalDraggingCollectionRef(null);
|
|
88
|
+
setGlobalDraggingKeys(new Set());
|
|
89
|
+
setGlobalDraggingTypes(new Set());
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
state,
|
|
95
|
+
};
|
|
96
|
+
}
|