@proyecto-viviana/solidaria 0.2.1 → 0.2.3

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 (208) hide show
  1. package/dist/autocomplete/createAutocomplete.d.ts +2 -2
  2. package/dist/autocomplete/createAutocomplete.d.ts.map +1 -1
  3. package/dist/index.js +233 -234
  4. package/dist/index.js.map +2 -2
  5. package/dist/index.ssr.js +233 -234
  6. package/dist/index.ssr.js.map +2 -2
  7. package/dist/interactions/PressEvent.d.ts +13 -10
  8. package/dist/interactions/PressEvent.d.ts.map +1 -1
  9. package/dist/interactions/createPress.d.ts.map +1 -1
  10. package/dist/interactions/index.d.ts +1 -1
  11. package/dist/interactions/index.d.ts.map +1 -1
  12. package/dist/select/createHiddenSelect.d.ts.map +1 -1
  13. package/dist/toolbar/createToolbar.d.ts.map +1 -1
  14. package/dist/tooltip/createTooltipTrigger.d.ts.map +1 -1
  15. package/package.json +9 -7
  16. package/src/autocomplete/createAutocomplete.ts +341 -0
  17. package/src/autocomplete/index.ts +9 -0
  18. package/src/breadcrumbs/createBreadcrumbs.ts +196 -0
  19. package/src/breadcrumbs/index.ts +8 -0
  20. package/src/button/createButton.ts +142 -0
  21. package/src/button/createToggleButton.ts +101 -0
  22. package/src/button/index.ts +4 -0
  23. package/src/button/types.ts +78 -0
  24. package/src/calendar/createCalendar.ts +138 -0
  25. package/src/calendar/createCalendarCell.ts +187 -0
  26. package/src/calendar/createCalendarGrid.ts +140 -0
  27. package/src/calendar/createRangeCalendar.ts +136 -0
  28. package/src/calendar/createRangeCalendarCell.ts +186 -0
  29. package/src/calendar/index.ts +34 -0
  30. package/src/checkbox/createCheckbox.ts +135 -0
  31. package/src/checkbox/createCheckboxGroup.ts +137 -0
  32. package/src/checkbox/createCheckboxGroupItem.ts +117 -0
  33. package/src/checkbox/createCheckboxGroupState.ts +193 -0
  34. package/src/checkbox/index.ts +13 -0
  35. package/src/color/createColorArea.ts +314 -0
  36. package/src/color/createColorField.ts +137 -0
  37. package/src/color/createColorSlider.ts +197 -0
  38. package/src/color/createColorSwatch.ts +40 -0
  39. package/src/color/createColorWheel.ts +208 -0
  40. package/src/color/index.ts +24 -0
  41. package/src/color/types.ts +116 -0
  42. package/src/combobox/createComboBox.ts +647 -0
  43. package/src/combobox/index.ts +6 -0
  44. package/src/combobox/intl/en-US.json +7 -0
  45. package/src/combobox/intl/es-ES.json +7 -0
  46. package/src/combobox/intl/index.ts +23 -0
  47. package/src/datepicker/createDateField.ts +154 -0
  48. package/src/datepicker/createDatePicker.ts +206 -0
  49. package/src/datepicker/createDateSegment.ts +229 -0
  50. package/src/datepicker/createTimeField.ts +154 -0
  51. package/src/datepicker/index.ts +28 -0
  52. package/src/dialog/createDialog.ts +120 -0
  53. package/src/dialog/index.ts +2 -0
  54. package/src/dialog/types.ts +19 -0
  55. package/src/disclosure/createDisclosure.ts +131 -0
  56. package/src/disclosure/createDisclosureGroup.ts +62 -0
  57. package/src/disclosure/index.ts +11 -0
  58. package/src/dnd/createDrag.ts +209 -0
  59. package/src/dnd/createDraggableCollection.ts +63 -0
  60. package/src/dnd/createDraggableItem.ts +243 -0
  61. package/src/dnd/createDrop.ts +321 -0
  62. package/src/dnd/createDroppableCollection.ts +293 -0
  63. package/src/dnd/createDroppableItem.ts +213 -0
  64. package/src/dnd/index.ts +47 -0
  65. package/src/dnd/types.ts +89 -0
  66. package/src/dnd/utils.ts +294 -0
  67. package/src/focus/FocusScope.tsx +408 -0
  68. package/src/focus/createAutoFocus.ts +321 -0
  69. package/src/focus/createFocusRestore.ts +313 -0
  70. package/src/focus/createVirtualFocus.ts +396 -0
  71. package/src/focus/index.ts +35 -0
  72. package/src/form/createFormReset.ts +51 -0
  73. package/src/form/createFormValidation.ts +224 -0
  74. package/src/form/index.ts +11 -0
  75. package/src/grid/GridKeyboardDelegate.ts +429 -0
  76. package/src/grid/createGrid.ts +261 -0
  77. package/src/grid/createGridCell.ts +182 -0
  78. package/src/grid/createGridRow.ts +153 -0
  79. package/src/grid/index.ts +18 -0
  80. package/src/grid/types.ts +133 -0
  81. package/src/gridlist/createGridList.ts +185 -0
  82. package/src/gridlist/createGridListItem.ts +180 -0
  83. package/src/gridlist/createGridListSelectionCheckbox.ts +59 -0
  84. package/src/gridlist/index.ts +16 -0
  85. package/src/gridlist/types.ts +81 -0
  86. package/src/i18n/NumberFormatter.ts +266 -0
  87. package/src/i18n/createCollator.ts +79 -0
  88. package/src/i18n/createDateFormatter.ts +83 -0
  89. package/src/i18n/createFilter.ts +131 -0
  90. package/src/i18n/createNumberFormatter.ts +52 -0
  91. package/src/i18n/createStringFormatter.ts +87 -0
  92. package/src/i18n/index.ts +40 -0
  93. package/src/i18n/locale.tsx +188 -0
  94. package/src/i18n/utils.ts +99 -0
  95. package/src/index.ts +670 -0
  96. package/src/interactions/FocusableProvider.tsx +44 -0
  97. package/src/interactions/PressEvent.ts +126 -0
  98. package/src/interactions/createFocus.ts +163 -0
  99. package/src/interactions/createFocusRing.ts +89 -0
  100. package/src/interactions/createFocusWithin.ts +206 -0
  101. package/src/interactions/createFocusable.ts +168 -0
  102. package/src/interactions/createHover.ts +254 -0
  103. package/src/interactions/createInteractionModality.ts +424 -0
  104. package/src/interactions/createKeyboard.ts +82 -0
  105. package/src/interactions/createLongPress.ts +174 -0
  106. package/src/interactions/createMove.ts +289 -0
  107. package/src/interactions/createPress.ts +834 -0
  108. package/src/interactions/index.ts +78 -0
  109. package/src/label/createField.ts +145 -0
  110. package/src/label/createLabel.ts +117 -0
  111. package/src/label/createLabels.ts +50 -0
  112. package/src/label/index.ts +19 -0
  113. package/src/landmark/createLandmark.ts +377 -0
  114. package/src/landmark/index.ts +8 -0
  115. package/src/link/createLink.ts +182 -0
  116. package/src/link/index.ts +1 -0
  117. package/src/listbox/createListBox.ts +269 -0
  118. package/src/listbox/createOption.ts +151 -0
  119. package/src/listbox/index.ts +12 -0
  120. package/src/live-announcer/announce.ts +322 -0
  121. package/src/live-announcer/index.ts +9 -0
  122. package/src/menu/createMenu.ts +396 -0
  123. package/src/menu/createMenuItem.ts +149 -0
  124. package/src/menu/createMenuTrigger.ts +88 -0
  125. package/src/menu/index.ts +18 -0
  126. package/src/meter/createMeter.ts +75 -0
  127. package/src/meter/index.ts +1 -0
  128. package/src/numberfield/createNumberField.ts +268 -0
  129. package/src/numberfield/index.ts +5 -0
  130. package/src/overlays/ariaHideOutside.ts +219 -0
  131. package/src/overlays/createInteractOutside.ts +149 -0
  132. package/src/overlays/createModal.tsx +202 -0
  133. package/src/overlays/createOverlay.ts +155 -0
  134. package/src/overlays/createOverlayTrigger.ts +85 -0
  135. package/src/overlays/createPreventScroll.ts +266 -0
  136. package/src/overlays/index.ts +44 -0
  137. package/src/popover/calculatePosition.ts +766 -0
  138. package/src/popover/createOverlayPosition.ts +356 -0
  139. package/src/popover/createPopover.ts +170 -0
  140. package/src/popover/index.ts +24 -0
  141. package/src/progress/createProgressBar.ts +128 -0
  142. package/src/progress/index.ts +5 -0
  143. package/src/radio/createRadio.ts +287 -0
  144. package/src/radio/createRadioGroup.ts +189 -0
  145. package/src/radio/createRadioGroupState.ts +201 -0
  146. package/src/radio/index.ts +23 -0
  147. package/src/searchfield/createSearchField.ts +186 -0
  148. package/src/searchfield/index.ts +2 -0
  149. package/src/select/createHiddenSelect.tsx +236 -0
  150. package/src/select/createSelect.ts +395 -0
  151. package/src/select/index.ts +14 -0
  152. package/src/selection/createTypeSelect.ts +201 -0
  153. package/src/selection/index.ts +6 -0
  154. package/src/separator/createSeparator.ts +82 -0
  155. package/src/separator/index.ts +6 -0
  156. package/src/slider/createSlider.ts +349 -0
  157. package/src/slider/index.ts +2 -0
  158. package/src/ssr/index.tsx +370 -0
  159. package/src/switch/createSwitch.ts +70 -0
  160. package/src/switch/index.ts +1 -0
  161. package/src/table/createTable.ts +526 -0
  162. package/src/table/createTableCell.ts +147 -0
  163. package/src/table/createTableColumnHeader.ts +115 -0
  164. package/src/table/createTableHeaderRow.ts +40 -0
  165. package/src/table/createTableRow.ts +155 -0
  166. package/src/table/createTableRowGroup.ts +32 -0
  167. package/src/table/createTableSelectAllCheckbox.ts +73 -0
  168. package/src/table/createTableSelectionCheckbox.ts +59 -0
  169. package/src/table/index.ts +30 -0
  170. package/src/table/types.ts +165 -0
  171. package/src/tabs/createTabs.ts +472 -0
  172. package/src/tabs/index.ts +14 -0
  173. package/src/tag/createTag.ts +194 -0
  174. package/src/tag/createTagGroup.ts +154 -0
  175. package/src/tag/index.ts +12 -0
  176. package/src/textfield/createTextField.ts +198 -0
  177. package/src/textfield/index.ts +5 -0
  178. package/src/toast/createToast.ts +118 -0
  179. package/src/toast/createToastRegion.ts +100 -0
  180. package/src/toast/index.ts +11 -0
  181. package/src/toggle/createToggle.ts +223 -0
  182. package/src/toggle/createToggleState.ts +94 -0
  183. package/src/toggle/index.ts +7 -0
  184. package/src/toolbar/createToolbar.ts +369 -0
  185. package/src/toolbar/index.ts +6 -0
  186. package/src/tooltip/createTooltip.ts +79 -0
  187. package/src/tooltip/createTooltipTrigger.ts +222 -0
  188. package/src/tooltip/index.ts +6 -0
  189. package/src/tree/createTree.ts +246 -0
  190. package/src/tree/createTreeItem.ts +233 -0
  191. package/src/tree/createTreeSelectionCheckbox.ts +68 -0
  192. package/src/tree/index.ts +16 -0
  193. package/src/tree/types.ts +87 -0
  194. package/src/utils/createDescription.ts +137 -0
  195. package/src/utils/dom.ts +327 -0
  196. package/src/utils/env.ts +54 -0
  197. package/src/utils/events.ts +106 -0
  198. package/src/utils/filterDOMProps.ts +116 -0
  199. package/src/utils/focus.ts +151 -0
  200. package/src/utils/geometry.ts +115 -0
  201. package/src/utils/globalListeners.ts +142 -0
  202. package/src/utils/index.ts +80 -0
  203. package/src/utils/mergeProps.ts +52 -0
  204. package/src/utils/platform.ts +52 -0
  205. package/src/utils/reactivity.ts +36 -0
  206. package/src/utils/textSelection.ts +114 -0
  207. package/src/visually-hidden/createVisuallyHidden.ts +124 -0
  208. package/src/visually-hidden/index.ts +6 -0
@@ -0,0 +1,377 @@
1
+ /**
2
+ * createLandmark - SolidJS implementation of React Aria's useLandmark
3
+ *
4
+ * Provides landmark navigation in an application. Call this with a role and label
5
+ * to register a landmark navigable with the F6 key.
6
+ *
7
+ * ARIA landmarks help screen reader users navigate between major sections of a page.
8
+ * The F6 key (or Shift+F6) cycles through all registered landmarks.
9
+ */
10
+
11
+ import type { JSX, Accessor } from 'solid-js';
12
+ import { createEffect, onCleanup } from 'solid-js';
13
+ import { access, type MaybeAccessor } from '../utils';
14
+ import { filterDOMProps } from '../utils';
15
+
16
+ // ============================================
17
+ // TYPES
18
+ // ============================================
19
+
20
+ /** ARIA landmark roles */
21
+ export type AriaLandmarkRole =
22
+ | 'main'
23
+ | 'region'
24
+ | 'search'
25
+ | 'navigation'
26
+ | 'form'
27
+ | 'banner'
28
+ | 'contentinfo'
29
+ | 'complementary';
30
+
31
+ export interface AriaLandmarkProps {
32
+ /** The ARIA landmark role. */
33
+ role: AriaLandmarkRole;
34
+ /**
35
+ * A human-readable label for the landmark.
36
+ * Required when multiple landmarks with the same role exist on a page.
37
+ */
38
+ 'aria-label'?: string;
39
+ /** Identifies the element(s) that labels the landmark. */
40
+ 'aria-labelledby'?: string;
41
+ /** The element's unique identifier. */
42
+ id?: string;
43
+ /**
44
+ * A custom focus handler called when this landmark receives focus via F6 navigation.
45
+ * Use this to focus a specific element within the landmark instead of the container.
46
+ */
47
+ focus?: () => void;
48
+ }
49
+
50
+ export interface LandmarkAria<T extends HTMLElement = HTMLElement> {
51
+ /** Props to spread on the landmark element. */
52
+ landmarkProps: JSX.HTMLAttributes<T>;
53
+ }
54
+
55
+ export interface LandmarkController {
56
+ /** Focus the next landmark in DOM order. */
57
+ focusNext: () => void;
58
+ /** Focus the previous landmark in DOM order. */
59
+ focusPrevious: () => void;
60
+ /** Focus the main landmark. */
61
+ focusMain: () => void;
62
+ /** Navigate to a specific landmark by role. If multiple exist, the first one is focused. */
63
+ navigate: (role: AriaLandmarkRole) => void;
64
+ }
65
+
66
+ // ============================================
67
+ // INTERNAL: Landmark Entry
68
+ // ============================================
69
+
70
+ interface LandmarkEntry {
71
+ ref: HTMLElement;
72
+ role: AriaLandmarkRole;
73
+ label?: string;
74
+ focus?: () => void;
75
+ lastFocused?: HTMLElement;
76
+ }
77
+
78
+ // ============================================
79
+ // LANDMARK MANAGER (Singleton)
80
+ // ============================================
81
+
82
+ /**
83
+ * Manages all registered landmarks and handles F6 keyboard navigation.
84
+ */
85
+ class LandmarkManager {
86
+ private landmarks: LandmarkEntry[] = [];
87
+ private currentIndex = -1;
88
+ private listening = false;
89
+
90
+ constructor() {
91
+ if (typeof window !== 'undefined') {
92
+ this.startListening();
93
+ }
94
+ }
95
+
96
+ private startListening() {
97
+ if (this.listening) return;
98
+ this.listening = true;
99
+
100
+ window.addEventListener('keydown', this.handleKeyDown.bind(this), true);
101
+ }
102
+
103
+ private handleKeyDown(event: KeyboardEvent) {
104
+ // F6 to navigate landmarks
105
+ if (event.key === 'F6') {
106
+ event.preventDefault();
107
+ if (event.shiftKey) {
108
+ this.focusPrevious();
109
+ } else {
110
+ this.focusNext();
111
+ }
112
+ }
113
+ }
114
+
115
+ register(entry: LandmarkEntry): void {
116
+ // Insert in DOM order using compareDocumentPosition
117
+ const index = this.findInsertionIndex(entry.ref);
118
+ this.landmarks.splice(index, 0, entry);
119
+
120
+ // Validate: if multiple landmarks have the same role, they should have different labels
121
+ this.validateLabels();
122
+ }
123
+
124
+ unregister(ref: HTMLElement): void {
125
+ const index = this.landmarks.findIndex((l) => l.ref === ref);
126
+ if (index !== -1) {
127
+ this.landmarks.splice(index, 1);
128
+ // Adjust currentIndex if needed
129
+ if (this.currentIndex >= this.landmarks.length) {
130
+ this.currentIndex = this.landmarks.length - 1;
131
+ }
132
+ }
133
+ }
134
+
135
+ private findInsertionIndex(ref: HTMLElement): number {
136
+ // Binary search for insertion point based on DOM order
137
+ let low = 0;
138
+ let high = this.landmarks.length;
139
+
140
+ while (low < high) {
141
+ const mid = Math.floor((low + high) / 2);
142
+ const comparison = this.landmarks[mid].ref.compareDocumentPosition(ref);
143
+
144
+ // Node.DOCUMENT_POSITION_FOLLOWING = 4
145
+ if (comparison & Node.DOCUMENT_POSITION_FOLLOWING) {
146
+ low = mid + 1;
147
+ } else {
148
+ high = mid;
149
+ }
150
+ }
151
+
152
+ return low;
153
+ }
154
+
155
+ private validateLabels(): void {
156
+ // Group landmarks by role
157
+ const roleGroups = new Map<AriaLandmarkRole, LandmarkEntry[]>();
158
+ for (const landmark of this.landmarks) {
159
+ const group = roleGroups.get(landmark.role) || [];
160
+ group.push(landmark);
161
+ roleGroups.set(landmark.role, group);
162
+ }
163
+
164
+ // Warn if multiple landmarks with the same role lack unique labels
165
+ for (const [role, group] of roleGroups) {
166
+ if (group.length > 1) {
167
+ const labels = group.map((l) => l.label);
168
+ const uniqueLabels = new Set(labels.filter(Boolean));
169
+ if (uniqueLabels.size < group.length) {
170
+ console.warn(
171
+ `Multiple landmarks with role "${role}" exist. Each should have a unique aria-label or aria-labelledby.`
172
+ );
173
+ }
174
+ }
175
+ }
176
+ }
177
+
178
+ focusNext(): void {
179
+ if (this.landmarks.length === 0) return;
180
+
181
+ // Find the currently focused landmark
182
+ const activeElement = document.activeElement;
183
+ this.currentIndex = this.findCurrentLandmarkIndex(activeElement);
184
+
185
+ // Move to next
186
+ this.currentIndex = (this.currentIndex + 1) % this.landmarks.length;
187
+ this.focusLandmark(this.landmarks[this.currentIndex]);
188
+ }
189
+
190
+ focusPrevious(): void {
191
+ if (this.landmarks.length === 0) return;
192
+
193
+ // Find the currently focused landmark
194
+ const activeElement = document.activeElement;
195
+ this.currentIndex = this.findCurrentLandmarkIndex(activeElement);
196
+
197
+ // Move to previous
198
+ this.currentIndex =
199
+ (this.currentIndex - 1 + this.landmarks.length) % this.landmarks.length;
200
+ this.focusLandmark(this.landmarks[this.currentIndex]);
201
+ }
202
+
203
+ focusMain(): void {
204
+ const main = this.landmarks.find((l) => l.role === 'main');
205
+ if (main) {
206
+ this.focusLandmark(main);
207
+ }
208
+ }
209
+
210
+ navigate(role: AriaLandmarkRole): void {
211
+ const landmark = this.landmarks.find((l) => l.role === role);
212
+ if (landmark) {
213
+ this.focusLandmark(landmark);
214
+ }
215
+ }
216
+
217
+ private findCurrentLandmarkIndex(activeElement: Element | null): number {
218
+ if (!activeElement) return -1;
219
+
220
+ // Check if active element is within any landmark
221
+ for (let i = 0; i < this.landmarks.length; i++) {
222
+ if (this.landmarks[i].ref.contains(activeElement)) {
223
+ // Store the last focused element for this landmark
224
+ if (activeElement instanceof HTMLElement) {
225
+ this.landmarks[i].lastFocused = activeElement;
226
+ }
227
+ return i;
228
+ }
229
+ }
230
+
231
+ return -1;
232
+ }
233
+
234
+ private focusLandmark(landmark: LandmarkEntry): void {
235
+ // If a custom focus handler is provided, use it
236
+ if (landmark.focus) {
237
+ landmark.focus();
238
+ return;
239
+ }
240
+
241
+ // If we previously focused an element in this landmark, try to restore it
242
+ if (landmark.lastFocused && landmark.ref.contains(landmark.lastFocused)) {
243
+ landmark.lastFocused.focus();
244
+ return;
245
+ }
246
+
247
+ // Try to find the first focusable element
248
+ const focusable = this.findFirstFocusable(landmark.ref);
249
+ if (focusable) {
250
+ focusable.focus();
251
+ return;
252
+ }
253
+
254
+ // Fallback: make the landmark itself focusable and focus it
255
+ if (!landmark.ref.hasAttribute('tabindex')) {
256
+ landmark.ref.setAttribute('tabindex', '-1');
257
+ }
258
+ landmark.ref.focus();
259
+ }
260
+
261
+ private findFirstFocusable(container: HTMLElement): HTMLElement | null {
262
+ const focusableSelectors = [
263
+ 'a[href]',
264
+ 'button:not([disabled])',
265
+ 'input:not([disabled])',
266
+ 'select:not([disabled])',
267
+ 'textarea:not([disabled])',
268
+ '[tabindex]:not([tabindex="-1"])',
269
+ ].join(', ');
270
+
271
+ return container.querySelector<HTMLElement>(focusableSelectors);
272
+ }
273
+
274
+ getController(): LandmarkController {
275
+ return {
276
+ focusNext: () => this.focusNext(),
277
+ focusPrevious: () => this.focusPrevious(),
278
+ focusMain: () => this.focusMain(),
279
+ navigate: (role) => this.navigate(role),
280
+ };
281
+ }
282
+ }
283
+
284
+ // Global singleton instance
285
+ let landmarkManager: LandmarkManager | null = null;
286
+
287
+ function getLandmarkManager(): LandmarkManager {
288
+ if (!landmarkManager) {
289
+ landmarkManager = new LandmarkManager();
290
+ }
291
+ return landmarkManager;
292
+ }
293
+
294
+ // ============================================
295
+ // CREATE LANDMARK
296
+ // ============================================
297
+
298
+ /**
299
+ * Provides landmark navigation in an application.
300
+ * Call this with a role and label to register a landmark navigable with F6.
301
+ *
302
+ * @example
303
+ * ```tsx
304
+ * function Navigation(props) {
305
+ * let ref: HTMLElement;
306
+ * const { landmarkProps } = createLandmark({
307
+ * role: 'navigation',
308
+ * 'aria-label': 'Main navigation'
309
+ * });
310
+ *
311
+ * return (
312
+ * <nav {...landmarkProps} ref={ref}>
313
+ * {props.children}
314
+ * </nav>
315
+ * );
316
+ * }
317
+ * ```
318
+ */
319
+ export function createLandmark<T extends HTMLElement = HTMLElement>(
320
+ props: MaybeAccessor<AriaLandmarkProps>,
321
+ ref: Accessor<T | undefined>
322
+ ): LandmarkAria<T> {
323
+ // Register with the landmark manager
324
+ createEffect(() => {
325
+ const element = ref();
326
+ if (!element) return;
327
+
328
+ const p = access(props);
329
+ const entry: LandmarkEntry = {
330
+ ref: element,
331
+ role: p.role,
332
+ label: p['aria-label'],
333
+ focus: p.focus,
334
+ };
335
+
336
+ const manager = getLandmarkManager();
337
+ manager.register(entry);
338
+
339
+ onCleanup(() => {
340
+ manager.unregister(element);
341
+ });
342
+ });
343
+
344
+ const getLandmarkProps = (): JSX.HTMLAttributes<T> => {
345
+ const p = access(props);
346
+ const domProps = filterDOMProps(p as unknown as Record<string, unknown>, { labelable: true });
347
+
348
+ return {
349
+ ...domProps,
350
+ role: p.role,
351
+ };
352
+ };
353
+
354
+ return {
355
+ get landmarkProps() {
356
+ return getLandmarkProps();
357
+ },
358
+ };
359
+ }
360
+
361
+ // ============================================
362
+ // LANDMARK CONTROLLER
363
+ // ============================================
364
+
365
+ /**
366
+ * Returns a controller for programmatic landmark navigation.
367
+ *
368
+ * @example
369
+ * ```tsx
370
+ * const controller = getLandmarkController();
371
+ * controller.focusMain(); // Focus the main landmark
372
+ * controller.focusNext(); // Focus the next landmark
373
+ * ```
374
+ */
375
+ export function getLandmarkController(): LandmarkController {
376
+ return getLandmarkManager().getController();
377
+ }
@@ -0,0 +1,8 @@
1
+ export {
2
+ createLandmark,
3
+ getLandmarkController,
4
+ type AriaLandmarkRole,
5
+ type AriaLandmarkProps,
6
+ type LandmarkAria,
7
+ type LandmarkController,
8
+ } from './createLandmark';
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Link hook for Solidaria
3
+ *
4
+ * Provides the behavior and accessibility implementation for a link component.
5
+ * A link allows a user to navigate to another page or resource within a web page
6
+ * or application.
7
+ *
8
+ * This is a 1:1 port of @react-aria/link's useLink hook.
9
+ */
10
+
11
+ import { type Accessor } from 'solid-js';
12
+ import { createPress } from '../interactions/createPress';
13
+ import { createFocusable } from '../interactions/createFocusable';
14
+ import { mergeProps } from '../utils/mergeProps';
15
+ import { filterDOMProps } from '../utils/filterDOMProps';
16
+ import { type MaybeAccessor, access } from '../utils/reactivity';
17
+ import { type PressEvent } from '../interactions/PressEvent';
18
+
19
+ // ============================================
20
+ // TYPES
21
+ // ============================================
22
+
23
+ export interface AriaLinkProps {
24
+ /** Whether the link is disabled. */
25
+ isDisabled?: boolean;
26
+ /** The HTML element used to render the link, e.g. 'a', or 'span'. @default 'a' */
27
+ elementType?: string;
28
+ /** The URL to link to. */
29
+ href?: string;
30
+ /** The target window for the link. */
31
+ target?: string;
32
+ /** The relationship between the linked resource and the current page. */
33
+ rel?: string;
34
+ /** Handler that is called when the press is released over the target. */
35
+ onPress?: (e: PressEvent) => void;
36
+ /** Handler that is called when a press interaction starts. */
37
+ onPressStart?: (e: PressEvent) => void;
38
+ /** Handler that is called when a press interaction ends. */
39
+ onPressEnd?: (e: PressEvent) => void;
40
+ /** Handler that is called when the element is clicked. */
41
+ onClick?: (e: MouseEvent) => void;
42
+ /** Handler that is called when the element receives focus. */
43
+ onFocus?: (e: FocusEvent) => void;
44
+ /** Handler that is called when the element loses focus. */
45
+ onBlur?: (e: FocusEvent) => void;
46
+ /** Handler that is called when the element's focus status changes. */
47
+ onFocusChange?: (isFocused: boolean) => void;
48
+ /** Handler that is called when a key is pressed. */
49
+ onKeyDown?: (e: KeyboardEvent) => void;
50
+ /** Handler that is called when a key is released. */
51
+ onKeyUp?: (e: KeyboardEvent) => void;
52
+ /** Whether to autofocus the element. */
53
+ autoFocus?: boolean;
54
+ /** Indicates the current "page" or state within a set of related elements. */
55
+ 'aria-current'?: 'page' | 'step' | 'location' | 'date' | 'time' | 'true' | 'false' | boolean;
56
+ /** Defines a string value that labels the current element. */
57
+ 'aria-label'?: string;
58
+ /** Identifies the element (or elements) that labels the current element. */
59
+ 'aria-labelledby'?: string;
60
+ /** Identifies the element (or elements) that describes the object. */
61
+ 'aria-describedby'?: string;
62
+ }
63
+
64
+ export interface LinkAria {
65
+ /** Props for the link element. */
66
+ linkProps: Record<string, unknown>;
67
+ /** Whether the link is currently pressed. */
68
+ isPressed: Accessor<boolean>;
69
+ }
70
+
71
+ // ============================================
72
+ // IMPLEMENTATION
73
+ // ============================================
74
+
75
+ /**
76
+ * Provides the behavior and accessibility implementation for a link component.
77
+ * A link allows a user to navigate to another page or resource within a web page
78
+ * or application.
79
+ */
80
+ export function createLink(
81
+ props: MaybeAccessor<AriaLinkProps> = {}
82
+ ): LinkAria {
83
+ const getProps = () => access(props);
84
+
85
+ const isDisabled = () => getProps().isDisabled ?? false;
86
+ const elementType = () => getProps().elementType ?? 'a';
87
+
88
+ // Create press handling
89
+ const { pressProps, isPressed } = createPress({
90
+ get isDisabled() { return isDisabled(); },
91
+ get onPress() { return getProps().onPress; },
92
+ get onPressStart() { return getProps().onPressStart; },
93
+ get onPressEnd() { return getProps().onPressEnd; },
94
+ });
95
+
96
+ // Create focusable handling
97
+ const { focusableProps } = createFocusable({
98
+ get isDisabled() { return isDisabled(); },
99
+ get autoFocus() { return getProps().autoFocus; },
100
+ get onFocus() { return getProps().onFocus; },
101
+ get onBlur() { return getProps().onBlur; },
102
+ get onFocusChange() { return getProps().onFocusChange; },
103
+ get onKeyDown() { return getProps().onKeyDown; },
104
+ get onKeyUp() { return getProps().onKeyUp; },
105
+ });
106
+
107
+ // Build link props
108
+ const getLinkProps = (): Record<string, unknown> => {
109
+ const p = getProps();
110
+ const elType = elementType();
111
+ const disabled = isDisabled();
112
+
113
+ let baseProps: Record<string, unknown> = {};
114
+
115
+ // If not an <a>, add role and tabIndex
116
+ if (elType !== 'a') {
117
+ baseProps = {
118
+ role: 'link',
119
+ tabIndex: disabled ? undefined : 0,
120
+ };
121
+ }
122
+
123
+ // Add link-specific props
124
+ if (elType === 'a') {
125
+ if (p.href) baseProps.href = p.href;
126
+ if (p.target) baseProps.target = p.target;
127
+ if (p.rel) baseProps.rel = p.rel;
128
+ }
129
+
130
+ // ARIA attributes
131
+ const ariaProps: Record<string, unknown> = {
132
+ 'aria-disabled': disabled || undefined,
133
+ };
134
+
135
+ if (p['aria-current'] !== undefined) {
136
+ ariaProps['aria-current'] = p['aria-current'];
137
+ }
138
+ if (p['aria-label']) {
139
+ ariaProps['aria-label'] = p['aria-label'];
140
+ }
141
+ if (p['aria-labelledby']) {
142
+ ariaProps['aria-labelledby'] = p['aria-labelledby'];
143
+ }
144
+ if (p['aria-describedby']) {
145
+ ariaProps['aria-describedby'] = p['aria-describedby'];
146
+ }
147
+
148
+ // Handle onClick - prevent default navigation when appropriate
149
+ const onClick = (e: MouseEvent) => {
150
+ // If disabled, prevent navigation and don't call user's onClick
151
+ if (disabled) {
152
+ e.preventDefault();
153
+ return;
154
+ }
155
+
156
+ // If onPress is provided, prevent default navigation
157
+ // This allows onPress to handle the action (e.g., client-side routing)
158
+ if (p.onPress) {
159
+ e.preventDefault();
160
+ }
161
+
162
+ // Call user's onClick if provided
163
+ p.onClick?.(e);
164
+ };
165
+
166
+ return mergeProps(
167
+ filterDOMProps(p as Record<string, unknown>, { labelable: true }),
168
+ baseProps,
169
+ ariaProps,
170
+ focusableProps as Record<string, unknown>,
171
+ pressProps as Record<string, unknown>,
172
+ { onClick }
173
+ );
174
+ };
175
+
176
+ return {
177
+ get linkProps() {
178
+ return getLinkProps();
179
+ },
180
+ isPressed,
181
+ };
182
+ }
@@ -0,0 +1 @@
1
+ export { createLink, type AriaLinkProps, type LinkAria } from './createLink';