@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,233 +1,282 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* createTreeItem - Provides accessibility for a tree item.
|
|
3
|
-
* Based on @react-aria/tree/useTreeItem.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { createMemo, createSignal, type Accessor } from 'solid-js';
|
|
7
|
-
import type { JSX } from 'solid-js';
|
|
8
|
-
import
|
|
9
|
-
import type {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
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
|
-
if (
|
|
83
|
-
p.
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
p.
|
|
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
|
-
const
|
|
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
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
'aria-
|
|
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
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* createTreeItem - Provides accessibility for a tree item.
|
|
3
|
+
* Based on @react-aria/tree/useTreeItem.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { createMemo, createSignal, type Accessor } from 'solid-js';
|
|
7
|
+
import type { JSX } from 'solid-js';
|
|
8
|
+
import { createId } from '@proyecto-viviana/solid-stately';
|
|
9
|
+
import type { TreeState, TreeCollection } from '@proyecto-viviana/solid-stately';
|
|
10
|
+
import type { AriaTreeItemProps, TreeItemAria } from './types';
|
|
11
|
+
import { getTreeData } from './createTree';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Creates accessibility props for a tree item.
|
|
15
|
+
*/
|
|
16
|
+
export function createTreeItem<T extends object, C extends TreeCollection<T> = TreeCollection<T>>(
|
|
17
|
+
props: Accessor<AriaTreeItemProps<T>>,
|
|
18
|
+
state: Accessor<TreeState<T, C>>,
|
|
19
|
+
_ref: Accessor<HTMLDivElement | null>
|
|
20
|
+
): TreeItemAria {
|
|
21
|
+
const [isPressed, setIsPressed] = createSignal(false);
|
|
22
|
+
const rowId = createId();
|
|
23
|
+
const expandButtonId = createId();
|
|
24
|
+
|
|
25
|
+
const isSelected = createMemo(() => {
|
|
26
|
+
const s = state();
|
|
27
|
+
const p = props();
|
|
28
|
+
return s.isSelected(p.node.key);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const isDisabled = createMemo(() => {
|
|
32
|
+
const s = state();
|
|
33
|
+
const p = props();
|
|
34
|
+
return s.isDisabled(p.node.key);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const isFocused = createMemo(() => {
|
|
38
|
+
const s = state();
|
|
39
|
+
const p = props();
|
|
40
|
+
return s.focusedKey === p.node.key;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const isExpanded = createMemo(() => {
|
|
44
|
+
const s = state();
|
|
45
|
+
const p = props();
|
|
46
|
+
return s.isExpanded(p.node.key);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const isExpandable = createMemo(() => {
|
|
50
|
+
const p = props();
|
|
51
|
+
return p.node.isExpandable ?? false;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const level = createMemo(() => {
|
|
55
|
+
const p = props();
|
|
56
|
+
return p.node.level;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Handle click/press for selection and actions
|
|
60
|
+
const onClick = (e: MouseEvent) => {
|
|
61
|
+
const s = state();
|
|
62
|
+
const p = props();
|
|
63
|
+
|
|
64
|
+
if (isDisabled()) return;
|
|
65
|
+
|
|
66
|
+
// Get tree metadata for actions
|
|
67
|
+
const treeData = getTreeData(s);
|
|
68
|
+
const onAction = treeData?.actions.onAction;
|
|
69
|
+
|
|
70
|
+
// Handle selection
|
|
71
|
+
if (s.selectionMode !== 'none') {
|
|
72
|
+
if (e.shiftKey && s.selectionMode === 'multiple') {
|
|
73
|
+
s.extendSelection(p.node.key);
|
|
74
|
+
} else if (e.ctrlKey || e.metaKey) {
|
|
75
|
+
s.toggleSelection(p.node.key);
|
|
76
|
+
} else {
|
|
77
|
+
// Replace selection or toggle if already selected
|
|
78
|
+
if (isSelected() && s.selectedKeys !== 'all') {
|
|
79
|
+
const selectedKeys = s.selectedKeys as Set<unknown>;
|
|
80
|
+
if (selectedKeys.size === 1) {
|
|
81
|
+
// Single selection, trigger action
|
|
82
|
+
if (onAction) {
|
|
83
|
+
onAction(p.node.key);
|
|
84
|
+
}
|
|
85
|
+
if (p.onAction) {
|
|
86
|
+
p.onAction();
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
s.replaceSelection(p.node.key);
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
s.replaceSelection(p.node.key);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
// No selection mode, just trigger action
|
|
97
|
+
if (onAction) {
|
|
98
|
+
onAction(p.node.key);
|
|
99
|
+
}
|
|
100
|
+
if (p.onAction) {
|
|
101
|
+
p.onAction();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
107
|
+
const s = state();
|
|
108
|
+
const p = props();
|
|
109
|
+
|
|
110
|
+
if (isDisabled()) return;
|
|
111
|
+
|
|
112
|
+
if (e.key === 'Enter') {
|
|
113
|
+
// Get tree metadata for actions
|
|
114
|
+
const treeData = getTreeData(s);
|
|
115
|
+
const onAction = treeData?.actions.onAction;
|
|
116
|
+
|
|
117
|
+
if (onAction || p.onAction) {
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
|
|
120
|
+
if (onAction) {
|
|
121
|
+
onAction(p.node.key);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (p.onAction) {
|
|
125
|
+
p.onAction();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
} else if (e.key === ' ' || e.key === 'Space' || e.key === 'Spacebar') {
|
|
129
|
+
// Space toggles selection
|
|
130
|
+
if (s.selectionMode !== 'none') {
|
|
131
|
+
e.preventDefault();
|
|
132
|
+
s.toggleSelection(p.node.key);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const onFocus = () => {
|
|
138
|
+
const s = state();
|
|
139
|
+
const p = props();
|
|
140
|
+
s.setFocusedKey(p.node.key);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const onPointerDown = () => {
|
|
144
|
+
setIsPressed(true);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const onPointerUp = () => {
|
|
148
|
+
setIsPressed(false);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// Compute sibling position (aria-posinset/aria-setsize)
|
|
152
|
+
const siblingInfo = createMemo(() => {
|
|
153
|
+
const s = state();
|
|
154
|
+
const p = props();
|
|
155
|
+
const node = p.node;
|
|
156
|
+
const parentKey = node.parentKey;
|
|
157
|
+
|
|
158
|
+
if (parentKey != null) {
|
|
159
|
+
const parentNode = s.collection.getItem(parentKey);
|
|
160
|
+
if (parentNode) {
|
|
161
|
+
return {
|
|
162
|
+
posinset: node.index + 1, // 1-based
|
|
163
|
+
setsize: parentNode.childNodes.length,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Root-level: count root nodes
|
|
169
|
+
const rootNodes = s.collection.rows.filter((n) => n.level === 0);
|
|
170
|
+
const rootIndex = rootNodes.findIndex((n) => n.key === node.key);
|
|
171
|
+
return {
|
|
172
|
+
posinset: rootIndex >= 0 ? rootIndex + 1 : node.index + 1,
|
|
173
|
+
setsize: rootNodes.length,
|
|
174
|
+
};
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
const rowProps = createMemo(() => {
|
|
178
|
+
const s = state();
|
|
179
|
+
const p = props();
|
|
180
|
+
const node = p.node;
|
|
181
|
+
const { posinset, setsize } = siblingInfo();
|
|
182
|
+
|
|
183
|
+
// Use textValue for aria-label (if available), or explicit textValue prop
|
|
184
|
+
const textValue = p.textValue ?? node.textValue;
|
|
185
|
+
|
|
186
|
+
const baseProps: Record<string, unknown> = {
|
|
187
|
+
role: 'row',
|
|
188
|
+
id: rowId,
|
|
189
|
+
'aria-label': textValue || undefined,
|
|
190
|
+
'aria-selected': s.selectionMode !== 'none' ? isSelected() : undefined,
|
|
191
|
+
'aria-disabled': isDisabled() || undefined,
|
|
192
|
+
'aria-expanded': isExpandable() ? isExpanded() : undefined,
|
|
193
|
+
'aria-level': node.level + 1, // 1-based for ARIA
|
|
194
|
+
'aria-posinset': posinset,
|
|
195
|
+
'aria-setsize': setsize,
|
|
196
|
+
tabIndex: isFocused() ? 0 : -1,
|
|
197
|
+
onClick,
|
|
198
|
+
onKeyDown,
|
|
199
|
+
onFocus,
|
|
200
|
+
onPointerDown,
|
|
201
|
+
onPointerUp,
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
// Add aria-rowindex for virtualized trees
|
|
205
|
+
if (p.isVirtualized && node.rowIndex != null) {
|
|
206
|
+
baseProps['aria-rowindex'] = node.rowIndex + 1; // 1-based
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return baseProps as JSX.HTMLAttributes<HTMLDivElement>;
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const gridCellProps = createMemo(() => {
|
|
213
|
+
return {
|
|
214
|
+
role: 'gridcell',
|
|
215
|
+
} as JSX.HTMLAttributes<HTMLDivElement>;
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
// Expand button handler
|
|
219
|
+
const onExpandClick = (e: MouseEvent) => {
|
|
220
|
+
e.stopPropagation(); // Don't trigger row click
|
|
221
|
+
const s = state();
|
|
222
|
+
const p = props();
|
|
223
|
+
|
|
224
|
+
if (isDisabled()) return;
|
|
225
|
+
|
|
226
|
+
s.toggleKey(p.node.key);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const stopPointerPropagation = (e: Event) => {
|
|
230
|
+
// Prevent row pointer handlers from flipping pressed state and re-rendering
|
|
231
|
+
// before the button click handler can run.
|
|
232
|
+
e.stopPropagation();
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const expandButtonProps = createMemo(() => {
|
|
236
|
+
const baseProps: Record<string, unknown> = {
|
|
237
|
+
type: 'button',
|
|
238
|
+
id: expandButtonId,
|
|
239
|
+
'aria-label': isExpanded() ? 'Collapse' : 'Expand',
|
|
240
|
+
'aria-labelledby': isExpandable() ? `${expandButtonId} ${rowId}` : undefined,
|
|
241
|
+
onClick: onExpandClick,
|
|
242
|
+
onPointerDown: stopPointerPropagation,
|
|
243
|
+
onPointerUp: stopPointerPropagation,
|
|
244
|
+
onMouseDown: stopPointerPropagation,
|
|
245
|
+
onMouseUp: stopPointerPropagation,
|
|
246
|
+
tabIndex: -1, // Not in tab order, use arrow keys
|
|
247
|
+
'aria-hidden': !isExpandable() ? true : undefined,
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
return baseProps as JSX.ButtonHTMLAttributes<HTMLButtonElement>;
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
get rowProps() {
|
|
255
|
+
return rowProps();
|
|
256
|
+
},
|
|
257
|
+
get gridCellProps() {
|
|
258
|
+
return gridCellProps();
|
|
259
|
+
},
|
|
260
|
+
get expandButtonProps() {
|
|
261
|
+
return expandButtonProps();
|
|
262
|
+
},
|
|
263
|
+
get isSelected() {
|
|
264
|
+
return isSelected();
|
|
265
|
+
},
|
|
266
|
+
get isDisabled() {
|
|
267
|
+
return isDisabled();
|
|
268
|
+
},
|
|
269
|
+
get isPressed() {
|
|
270
|
+
return isPressed();
|
|
271
|
+
},
|
|
272
|
+
get isExpanded() {
|
|
273
|
+
return isExpanded();
|
|
274
|
+
},
|
|
275
|
+
get isExpandable() {
|
|
276
|
+
return isExpandable();
|
|
277
|
+
},
|
|
278
|
+
get level() {
|
|
279
|
+
return level();
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
}
|
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* createTreeSelectionCheckbox - Provides accessibility for a tree item's selection checkbox.
|
|
3
|
-
* Based on @react-aria/gridlist/useGridListSelectionCheckbox.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { createMemo, type Accessor } from 'solid-js';
|
|
7
|
-
import type { JSX } from 'solid-js';
|
|
8
|
-
import type { TreeState, TreeCollection } from '@proyecto-viviana/solid-stately';
|
|
9
|
-
import type { AriaTreeSelectionCheckboxProps, TreeSelectionCheckboxAria } from './types';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Creates accessibility props for a tree selection checkbox.
|
|
13
|
-
*/
|
|
14
|
-
export function createTreeSelectionCheckbox<T extends object, C extends TreeCollection<T> = TreeCollection<T>>(
|
|
15
|
-
props: Accessor<AriaTreeSelectionCheckboxProps>,
|
|
16
|
-
state: Accessor<TreeState<T, C>>
|
|
17
|
-
): TreeSelectionCheckboxAria {
|
|
18
|
-
const isSelected = createMemo(() => {
|
|
19
|
-
const s = state();
|
|
20
|
-
const p = props();
|
|
21
|
-
return s.isSelected(p.key);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const isDisabled = createMemo(() => {
|
|
25
|
-
const s = state();
|
|
26
|
-
const p = props();
|
|
27
|
-
return s.isDisabled(p.key);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const onChange = (e: Event) => {
|
|
31
|
-
const s = state();
|
|
32
|
-
const p = props();
|
|
33
|
-
const target = e.target as HTMLInputElement;
|
|
34
|
-
|
|
35
|
-
if (isDisabled()) return;
|
|
36
|
-
|
|
37
|
-
if (target.checked) {
|
|
38
|
-
s.toggleSelection(p.key);
|
|
39
|
-
} else {
|
|
40
|
-
s.toggleSelection(p.key);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const onClick = (e: MouseEvent) => {
|
|
45
|
-
// Stop propagation to prevent row click from also firing
|
|
46
|
-
e.stopPropagation();
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const checkboxProps = createMemo(() => {
|
|
50
|
-
const baseProps: Record<string, unknown> = {
|
|
51
|
-
type: 'checkbox',
|
|
52
|
-
'aria-label': 'Select',
|
|
53
|
-
checked: isSelected(),
|
|
54
|
-
disabled: isDisabled(),
|
|
55
|
-
onChange,
|
|
56
|
-
onClick,
|
|
57
|
-
tabIndex: -1, // Use arrow keys to navigate, not tab
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
return baseProps as JSX.InputHTMLAttributes<HTMLInputElement>;
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
get checkboxProps() {
|
|
65
|
-
return checkboxProps();
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* createTreeSelectionCheckbox - Provides accessibility for a tree item's selection checkbox.
|
|
3
|
+
* Based on @react-aria/gridlist/useGridListSelectionCheckbox.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { createMemo, type Accessor } from 'solid-js';
|
|
7
|
+
import type { JSX } from 'solid-js';
|
|
8
|
+
import type { TreeState, TreeCollection } from '@proyecto-viviana/solid-stately';
|
|
9
|
+
import type { AriaTreeSelectionCheckboxProps, TreeSelectionCheckboxAria } from './types';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates accessibility props for a tree selection checkbox.
|
|
13
|
+
*/
|
|
14
|
+
export function createTreeSelectionCheckbox<T extends object, C extends TreeCollection<T> = TreeCollection<T>>(
|
|
15
|
+
props: Accessor<AriaTreeSelectionCheckboxProps>,
|
|
16
|
+
state: Accessor<TreeState<T, C>>
|
|
17
|
+
): TreeSelectionCheckboxAria {
|
|
18
|
+
const isSelected = createMemo(() => {
|
|
19
|
+
const s = state();
|
|
20
|
+
const p = props();
|
|
21
|
+
return s.isSelected(p.key);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const isDisabled = createMemo(() => {
|
|
25
|
+
const s = state();
|
|
26
|
+
const p = props();
|
|
27
|
+
return s.isDisabled(p.key);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const onChange = (e: Event) => {
|
|
31
|
+
const s = state();
|
|
32
|
+
const p = props();
|
|
33
|
+
const target = e.target as HTMLInputElement;
|
|
34
|
+
|
|
35
|
+
if (isDisabled()) return;
|
|
36
|
+
|
|
37
|
+
if (target.checked) {
|
|
38
|
+
s.toggleSelection(p.key);
|
|
39
|
+
} else {
|
|
40
|
+
s.toggleSelection(p.key);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const onClick = (e: MouseEvent) => {
|
|
45
|
+
// Stop propagation to prevent row click from also firing
|
|
46
|
+
e.stopPropagation();
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const checkboxProps = createMemo(() => {
|
|
50
|
+
const baseProps: Record<string, unknown> = {
|
|
51
|
+
type: 'checkbox',
|
|
52
|
+
'aria-label': 'Select',
|
|
53
|
+
checked: isSelected(),
|
|
54
|
+
disabled: isDisabled(),
|
|
55
|
+
onChange,
|
|
56
|
+
onClick,
|
|
57
|
+
tabIndex: -1, // Use arrow keys to navigate, not tab
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return baseProps as JSX.InputHTMLAttributes<HTMLInputElement>;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
get checkboxProps() {
|
|
65
|
+
return checkboxProps();
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|