@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.
Files changed (219) hide show
  1. package/LICENSE +21 -0
  2. package/dist/actiongroup/createActionGroup.d.ts +29 -0
  3. package/dist/actiongroup/createActionGroup.d.ts.map +1 -0
  4. package/dist/actiongroup/index.d.ts +2 -0
  5. package/dist/actiongroup/index.d.ts.map +1 -0
  6. package/dist/autocomplete/createAutocomplete.d.ts +6 -2
  7. package/dist/autocomplete/createAutocomplete.d.ts.map +1 -1
  8. package/dist/breadcrumbs/createBreadcrumbs.d.ts +2 -0
  9. package/dist/breadcrumbs/createBreadcrumbs.d.ts.map +1 -1
  10. package/dist/button/createToggleButtonGroup.d.ts +32 -0
  11. package/dist/button/createToggleButtonGroup.d.ts.map +1 -0
  12. package/dist/button/index.d.ts +2 -0
  13. package/dist/button/index.d.ts.map +1 -1
  14. package/dist/calendar/createCalendarCell.d.ts +2 -0
  15. package/dist/calendar/createCalendarCell.d.ts.map +1 -1
  16. package/dist/calendar/createCalendarGrid.d.ts.map +1 -1
  17. package/dist/calendar/createRangeCalendarCell.d.ts +3 -1
  18. package/dist/calendar/createRangeCalendarCell.d.ts.map +1 -1
  19. package/dist/checkbox/createCheckboxGroup.d.ts +5 -1
  20. package/dist/checkbox/createCheckboxGroup.d.ts.map +1 -1
  21. package/dist/collections/index.d.ts +56 -0
  22. package/dist/collections/index.d.ts.map +1 -0
  23. package/dist/color/createColorArea.d.ts.map +1 -1
  24. package/dist/color/createColorSlider.d.ts.map +1 -1
  25. package/dist/color/createColorWheel.d.ts.map +1 -1
  26. package/dist/combobox/createComboBox.d.ts +6 -0
  27. package/dist/combobox/createComboBox.d.ts.map +1 -1
  28. package/dist/datepicker/createDatePicker.d.ts +6 -0
  29. package/dist/datepicker/createDatePicker.d.ts.map +1 -1
  30. package/dist/datepicker/createDateRangePicker.d.ts +40 -0
  31. package/dist/datepicker/createDateRangePicker.d.ts.map +1 -0
  32. package/dist/datepicker/createDateSegment.d.ts +1 -1
  33. package/dist/datepicker/createDateSegment.d.ts.map +1 -1
  34. package/dist/datepicker/createTimeSegment.d.ts +29 -0
  35. package/dist/datepicker/createTimeSegment.d.ts.map +1 -0
  36. package/dist/datepicker/index.d.ts +2 -0
  37. package/dist/datepicker/index.d.ts.map +1 -1
  38. package/dist/disclosure/createDisclosureGroup.d.ts +2 -1
  39. package/dist/disclosure/createDisclosureGroup.d.ts.map +1 -1
  40. package/dist/dnd/createDrag.d.ts.map +1 -1
  41. package/dist/dnd/createDraggableCollection.d.ts +4 -0
  42. package/dist/dnd/createDraggableCollection.d.ts.map +1 -1
  43. package/dist/dnd/createDraggableItem.d.ts.map +1 -1
  44. package/dist/dnd/createDrop.d.ts.map +1 -1
  45. package/dist/dnd/createDroppableCollection.d.ts +32 -1
  46. package/dist/dnd/createDroppableCollection.d.ts.map +1 -1
  47. package/dist/dnd/createDroppableItem.d.ts.map +1 -1
  48. package/dist/dnd/index.d.ts +1 -1
  49. package/dist/dnd/index.d.ts.map +1 -1
  50. package/dist/grid/createGrid.d.ts.map +1 -1
  51. package/dist/gridlist/createGridList.d.ts.map +1 -1
  52. package/dist/index.d.ts +6 -4
  53. package/dist/index.d.ts.map +1 -1
  54. package/dist/index.js +4659 -3452
  55. package/dist/index.js.map +1 -7
  56. package/dist/index.ssr.js +4659 -3452
  57. package/dist/index.ssr.js.map +1 -7
  58. package/dist/interactions/createFocus.d.ts.map +1 -1
  59. package/dist/interactions/createFocusWithin.d.ts.map +1 -1
  60. package/dist/link/createLink.d.ts +10 -0
  61. package/dist/link/createLink.d.ts.map +1 -1
  62. package/dist/listbox/createListBox.d.ts +1 -0
  63. package/dist/listbox/createListBox.d.ts.map +1 -1
  64. package/dist/listbox/createOption.d.ts.map +1 -1
  65. package/dist/menu/createMenu.d.ts +1 -0
  66. package/dist/menu/createMenu.d.ts.map +1 -1
  67. package/dist/meter/createMeter.d.ts.map +1 -1
  68. package/dist/numberfield/createNumberField.d.ts +18 -0
  69. package/dist/numberfield/createNumberField.d.ts.map +1 -1
  70. package/dist/overlays/createModal.d.ts +16 -0
  71. package/dist/overlays/createModal.d.ts.map +1 -1
  72. package/dist/overlays/createOverlay.d.ts.map +1 -1
  73. package/dist/overlays/index.d.ts +1 -1
  74. package/dist/overlays/index.d.ts.map +1 -1
  75. package/dist/popover/createOverlayPosition.d.ts.map +1 -1
  76. package/dist/popover/createPopover.d.ts.map +1 -1
  77. package/dist/progress/createProgressBar.d.ts.map +1 -1
  78. package/dist/radio/createRadioGroup.d.ts +2 -2
  79. package/dist/radio/createRadioGroup.d.ts.map +1 -1
  80. package/dist/searchfield/createSearchField.d.ts.map +1 -1
  81. package/dist/select/createHiddenSelect.d.ts.map +1 -1
  82. package/dist/select/createSelect.d.ts.map +1 -1
  83. package/dist/slider/createSlider.d.ts.map +1 -1
  84. package/dist/table/createTable.d.ts.map +1 -1
  85. package/dist/tabs/createTabs.d.ts +1 -1
  86. package/dist/tabs/createTabs.d.ts.map +1 -1
  87. package/dist/tag/createTag.d.ts.map +1 -1
  88. package/dist/tag/createTagGroup.d.ts.map +1 -1
  89. package/dist/toast/createToast.d.ts +4 -0
  90. package/dist/toast/createToast.d.ts.map +1 -1
  91. package/dist/toast/createToastRegion.d.ts.map +1 -1
  92. package/dist/toolbar/createToolbar.d.ts.map +1 -1
  93. package/dist/tooltip/createTooltipTrigger.d.ts.map +1 -1
  94. package/dist/tree/createTree.d.ts.map +1 -1
  95. package/dist/tree/createTreeItem.d.ts.map +1 -1
  96. package/dist/tree/types.d.ts +4 -0
  97. package/dist/tree/types.d.ts.map +1 -1
  98. package/dist/utils/env.d.ts +1 -1
  99. package/dist/utils/env.d.ts.map +1 -1
  100. package/dist/utils/platform.d.ts.map +1 -1
  101. package/dist/visually-hidden/createVisuallyHidden.d.ts.map +1 -1
  102. package/package.json +8 -6
  103. package/src/actiongroup/createActionGroup.ts +324 -0
  104. package/src/actiongroup/index.ts +8 -0
  105. package/src/autocomplete/createAutocomplete.ts +32 -9
  106. package/src/breadcrumbs/createBreadcrumbs.ts +10 -15
  107. package/src/button/createButton.ts +1 -1
  108. package/src/button/createToggleButtonGroup.ts +128 -0
  109. package/src/button/index.ts +9 -0
  110. package/src/calendar/createCalendarCell.ts +6 -4
  111. package/src/calendar/createCalendarGrid.ts +27 -18
  112. package/src/calendar/createRangeCalendarCell.ts +26 -9
  113. package/src/checkbox/createCheckboxGroup.ts +21 -4
  114. package/src/collections/index.ts +242 -0
  115. package/src/color/createColorArea.ts +380 -314
  116. package/src/color/createColorField.ts +137 -137
  117. package/src/color/createColorSlider.ts +286 -197
  118. package/src/color/createColorSwatch.ts +40 -40
  119. package/src/color/createColorWheel.ts +218 -208
  120. package/src/color/index.ts +24 -24
  121. package/src/color/types.ts +116 -116
  122. package/src/combobox/createComboBox.ts +670 -647
  123. package/src/combobox/index.ts +6 -6
  124. package/src/datepicker/createDatePicker.ts +54 -16
  125. package/src/datepicker/createDateRangePicker.ts +246 -0
  126. package/src/datepicker/createDateSegment.ts +185 -31
  127. package/src/datepicker/createTimeSegment.ts +370 -0
  128. package/src/datepicker/index.ts +14 -0
  129. package/src/dialog/createDialog.ts +120 -120
  130. package/src/dialog/index.ts +2 -2
  131. package/src/dialog/types.ts +19 -19
  132. package/src/disclosure/createDisclosureGroup.ts +5 -2
  133. package/src/dnd/createDrag.ts +224 -209
  134. package/src/dnd/createDraggableCollection.ts +96 -63
  135. package/src/dnd/createDraggableItem.ts +259 -243
  136. package/src/dnd/createDrop.ts +322 -321
  137. package/src/dnd/createDroppableCollection.ts +682 -293
  138. package/src/dnd/createDroppableItem.ts +215 -213
  139. package/src/dnd/index.ts +55 -47
  140. package/src/dnd/types.ts +89 -89
  141. package/src/dnd/utils.ts +294 -294
  142. package/src/focus/createAutoFocus.ts +321 -321
  143. package/src/focus/createFocusRestore.ts +313 -313
  144. package/src/focus/createVirtualFocus.ts +396 -396
  145. package/src/form/createFormValidation.ts +224 -224
  146. package/src/form/index.ts +11 -11
  147. package/src/grid/createGrid.ts +3 -1
  148. package/src/gridlist/createGridList.ts +16 -0
  149. package/src/gridlist/createGridListItem.ts +1 -1
  150. package/src/i18n/NumberFormatter.ts +266 -266
  151. package/src/i18n/createCollator.ts +79 -79
  152. package/src/i18n/createDateFormatter.ts +83 -83
  153. package/src/i18n/createFilter.ts +131 -131
  154. package/src/i18n/createNumberFormatter.ts +52 -52
  155. package/src/i18n/index.ts +40 -40
  156. package/src/i18n/locale.tsx +188 -188
  157. package/src/i18n/utils.ts +99 -99
  158. package/src/index.ts +51 -0
  159. package/src/interactions/createFocus.ts +6 -5
  160. package/src/interactions/createFocusWithin.ts +6 -5
  161. package/src/interactions/createLongPress.ts +174 -174
  162. package/src/interactions/createMove.ts +289 -289
  163. package/src/interactions/createPress.ts +5 -5
  164. package/src/landmark/createLandmark.ts +377 -377
  165. package/src/landmark/index.ts +8 -8
  166. package/src/link/createLink.ts +23 -8
  167. package/src/listbox/createListBox.ts +308 -269
  168. package/src/listbox/createOption.ts +162 -151
  169. package/src/listbox/index.ts +12 -12
  170. package/src/live-announcer/announce.ts +322 -322
  171. package/src/live-announcer/index.ts +9 -9
  172. package/src/menu/createMenu.ts +405 -396
  173. package/src/menu/createMenuItem.ts +149 -149
  174. package/src/menu/createMenuTrigger.ts +88 -88
  175. package/src/menu/index.ts +18 -18
  176. package/src/meter/createMeter.ts +1 -6
  177. package/src/numberfield/createNumberField.ts +311 -268
  178. package/src/numberfield/index.ts +5 -5
  179. package/src/overlays/ariaHideOutside.ts +219 -219
  180. package/src/overlays/createInteractOutside.ts +149 -149
  181. package/src/overlays/createModal.tsx +238 -202
  182. package/src/overlays/createOverlay.ts +165 -155
  183. package/src/overlays/createOverlayTrigger.ts +85 -85
  184. package/src/overlays/createPreventScroll.ts +266 -266
  185. package/src/overlays/index.ts +48 -44
  186. package/src/popover/calculatePosition.ts +6 -6
  187. package/src/popover/createOverlayPosition.ts +7 -4
  188. package/src/popover/createPopover.ts +21 -7
  189. package/src/progress/createProgressBar.ts +6 -1
  190. package/src/radio/createRadioGroup.ts +88 -14
  191. package/src/searchfield/createSearchField.ts +241 -186
  192. package/src/searchfield/index.ts +2 -2
  193. package/src/select/createHiddenSelect.tsx +263 -236
  194. package/src/select/createSelect.ts +373 -395
  195. package/src/select/index.ts +14 -14
  196. package/src/slider/createSlider.ts +364 -349
  197. package/src/slider/index.ts +2 -2
  198. package/src/ssr/index.tsx +370 -370
  199. package/src/table/createTable.ts +3 -1
  200. package/src/table/createTableColumnHeader.ts +1 -1
  201. package/src/table/createTableRow.ts +1 -1
  202. package/src/tabs/createTabs.ts +80 -51
  203. package/src/tag/createTag.ts +135 -6
  204. package/src/tag/createTagGroup.ts +7 -2
  205. package/src/toast/createToast.ts +8 -2
  206. package/src/toast/createToastRegion.ts +0 -1
  207. package/src/toolbar/createToolbar.ts +75 -1
  208. package/src/tooltip/createTooltip.ts +79 -79
  209. package/src/tooltip/createTooltipTrigger.ts +226 -222
  210. package/src/tooltip/index.ts +6 -6
  211. package/src/tree/createTree.ts +261 -246
  212. package/src/tree/createTreeItem.ts +282 -233
  213. package/src/tree/createTreeSelectionCheckbox.ts +68 -68
  214. package/src/tree/index.ts +16 -16
  215. package/src/tree/types.ts +91 -87
  216. package/src/utils/env.ts +55 -54
  217. package/src/utils/platform.ts +16 -6
  218. package/src/visually-hidden/createVisuallyHidden.ts +139 -124
  219. 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': props.isDisabled || state.isDisabled || undefined,
59
+ 'aria-disabled': getProps().isDisabled || state.isDisabled || undefined,
57
60
  }));
58
61
 
59
62
  return {
@@ -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
- writeToDataTransfer,
13
- DROP_OPERATION,
14
- EFFECT_ALLOWED,
15
- DROP_EFFECT_TO_DROP_OPERATION,
16
- setGlobalAllowedDropOperations,
17
- setGlobalDropEffect,
18
- getGlobalDropEffect,
19
- } from './utils';
20
-
21
- /**
22
- * Creates ARIA props for a draggable element.
23
- *
24
- * @param props - Accessor returning drag options
25
- * @returns Drag ARIA props and state
26
- */
27
- export function createDrag(props: Accessor<AriaDragOptions>): DragAria {
28
- const getProps = createMemo(() => props());
29
-
30
- // Create drag state
31
- const state = createDragState(() => ({
32
- getItems: getProps().getItems,
33
- getAllowedDropOperations: getProps().getAllowedDropOperations,
34
- onDragStart: getProps().onDragStart,
35
- onDragMove: getProps().onDragMove,
36
- onDragEnd: getProps().onDragEnd,
37
- isDisabled: getProps().isDisabled,
38
- hasDragButton: getProps().hasDragButton,
39
- preview: getProps().preview,
40
- }));
41
-
42
- // Track position for drag move
43
- let lastX = 0;
44
- let lastY = 0;
45
-
46
- const onDragStart = (e: DragEvent) => {
47
- if (e.defaultPrevented) return;
48
- e.stopPropagation();
49
-
50
- const p = getProps();
51
-
52
- // Call state handler
53
- state.startDrag(e.clientX, e.clientY);
54
-
55
- // Get items and write to data transfer
56
- const items = state.getItems();
57
- e.dataTransfer?.clearData?.();
58
- if (e.dataTransfer) {
59
- writeToDataTransfer(e.dataTransfer, items);
60
- }
61
-
62
- // Set allowed drop operations
63
- let allowed = DROP_OPERATION.all;
64
- const allowedOps = state.getAllowedDropOperations();
65
- if (allowedOps.length > 0) {
66
- allowed = DROP_OPERATION.none;
67
- for (const op of allowedOps) {
68
- allowed |= DROP_OPERATION[op] || DROP_OPERATION.none;
69
- }
70
- }
71
-
72
- setGlobalAllowedDropOperations(allowed);
73
- const effectAllowed = EFFECT_ALLOWED[allowed] || 'none';
74
- if (e.dataTransfer) {
75
- e.dataTransfer.effectAllowed =
76
- (effectAllowed === 'cancel' ? 'none' : effectAllowed) as DataTransfer['effectAllowed'];
77
- }
78
-
79
- // Handle custom preview
80
- if (typeof p.preview?.current === 'function' && e.dataTransfer) {
81
- p.preview.current(items, (node, userX, userY) => {
82
- if (!node || !e.dataTransfer) return;
83
-
84
- const size = node.getBoundingClientRect();
85
- const rect = (e.currentTarget as HTMLElement).getBoundingClientRect();
86
- let defaultX = e.clientX - rect.x;
87
- let defaultY = e.clientY - rect.y;
88
-
89
- if (defaultX > size.width || defaultY > size.height) {
90
- defaultX = size.width / 2;
91
- defaultY = size.height / 2;
92
- }
93
-
94
- let offsetX = typeof userX === 'number' ? userX : defaultX;
95
- let offsetY = typeof userY === 'number' ? userY : defaultY;
96
-
97
- offsetX = Math.max(0, Math.min(offsetX, size.width));
98
- offsetY = Math.max(0, Math.min(offsetY, size.height));
99
-
100
- e.dataTransfer.setDragImage(node, offsetX, offsetY);
101
- });
102
- }
103
-
104
- lastX = e.clientX;
105
- lastY = e.clientY;
106
- };
107
-
108
- const onDrag = (e: DragEvent) => {
109
- e.stopPropagation();
110
-
111
- if (e.clientX === lastX && e.clientY === lastY) {
112
- return;
113
- }
114
-
115
- state.moveDrag(e.clientX, e.clientY);
116
-
117
- lastX = e.clientX;
118
- lastY = e.clientY;
119
- };
120
-
121
- const onDragEnd = (e: DragEvent) => {
122
- e.stopPropagation();
123
-
124
- let dropEffect: string = e.dataTransfer?.dropEffect ?? 'none';
125
- // Chrome Android fix - use global drop effect
126
- if (getGlobalDropEffect()) {
127
- dropEffect = getGlobalDropEffect()!;
128
- }
129
-
130
- const dropOperation = DROP_EFFECT_TO_DROP_OPERATION[dropEffect];
131
- state.endDrag(e.clientX, e.clientY, dropOperation);
132
-
133
- setGlobalAllowedDropOperations(DROP_OPERATION.none);
134
- setGlobalDropEffect(undefined);
135
- };
136
-
137
- // Keyboard/screen reader drag initiation
138
- const onKeyDown = (e: KeyboardEvent) => {
139
- if (e.key === 'Enter' && e.target === e.currentTarget) {
140
- e.preventDefault();
141
- e.stopPropagation();
142
- }
143
- };
144
-
145
- const onKeyUp = (e: KeyboardEvent) => {
146
- if (e.key === 'Enter' && e.target === e.currentTarget) {
147
- e.preventDefault();
148
- e.stopPropagation();
149
- // Would initiate keyboard-based drag mode
150
- // This is a simplified version - full implementation needs DragManager
151
- const rect = (e.target as HTMLElement).getBoundingClientRect();
152
- state.startDrag(rect.x + rect.width / 2, rect.y + rect.height / 2);
153
- }
154
- };
155
-
156
- const dragProps = createMemo(() => {
157
- const p = getProps();
158
-
159
- if (p.isDisabled) {
160
- return {
161
- draggable: false as const,
162
- };
163
- }
164
-
165
- const baseProps: Record<string, unknown> = {
166
- draggable: true as const,
167
- onDragStart,
168
- onDrag,
169
- onDragEnd,
170
- };
171
-
172
- // Add keyboard handlers if no separate drag button
173
- if (!p.hasDragButton) {
174
- baseProps.onKeyDown = onKeyDown;
175
- baseProps.onKeyUp = onKeyUp;
176
- }
177
-
178
- return baseProps;
179
- });
180
-
181
- const dragButtonProps = createMemo(() => {
182
- const p = getProps();
183
-
184
- if (p.isDisabled) {
185
- return {
186
- disabled: true,
187
- };
188
- }
189
-
190
- return {
191
- type: 'button' as const,
192
- 'aria-label': 'Drag',
193
- onKeyDown,
194
- onKeyUp,
195
- };
196
- });
197
-
198
- return {
199
- get dragProps() {
200
- return dragProps() as DragAria['dragProps'];
201
- },
202
- get dragButtonProps() {
203
- return dragButtonProps() as DragAria['dragButtonProps'];
204
- },
205
- get isDragging() {
206
- return state.isDragging;
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
- // Global state for tracking the dragging collection
12
- let globalDraggingCollectionRef: HTMLElement | null = null;
13
-
14
- export function setGlobalDraggingCollectionRef(ref: HTMLElement | null): void {
15
- globalDraggingCollectionRef = ref;
16
- }
17
-
18
- export function getGlobalDraggingCollectionRef(): HTMLElement | null {
19
- return globalDraggingCollectionRef;
20
- }
21
-
22
- export interface DraggableCollectionOptions {
23
- /** Reference to the collection element. */
24
- ref: Accessor<HTMLElement | null>;
25
- }
26
-
27
- export interface DraggableCollectionAria {
28
- /** The draggable collection state. */
29
- state: DraggableCollectionState;
30
- }
31
-
32
- /**
33
- * Creates ARIA support for a draggable collection.
34
- *
35
- * @param _options - Collection options
36
- * @param state - Draggable collection state
37
- * @returns Draggable collection ARIA result
38
- */
39
- export function createDraggableCollection(
40
- options: DraggableCollectionOptions,
41
- state: DraggableCollectionState
42
- ): DraggableCollectionAria {
43
- const ref = createMemo(() => options.ref());
44
-
45
- // Track dragging state globally
46
- createEffect(() => {
47
- const currentRef = ref();
48
- if (state.draggingKeys.size > 0 && globalDraggingCollectionRef !== currentRef) {
49
- setGlobalDraggingCollectionRef(currentRef);
50
- }
51
- });
52
-
53
- // Clean up on unmount
54
- onCleanup(() => {
55
- if (globalDraggingCollectionRef === ref()) {
56
- setGlobalDraggingCollectionRef(null);
57
- }
58
- });
59
-
60
- return {
61
- state,
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
+ }