@chromvoid/headless-ui 0.1.0

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 (191) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +99 -0
  3. package/dist/a11y-contracts/index.d.ts +23 -0
  4. package/dist/a11y-contracts/index.js +1 -0
  5. package/dist/accordion/index.d.ts +78 -0
  6. package/dist/accordion/index.js +264 -0
  7. package/dist/adapters/index.d.ts +9 -0
  8. package/dist/adapters/index.js +1 -0
  9. package/dist/alert/index.d.ts +33 -0
  10. package/dist/alert/index.js +54 -0
  11. package/dist/alert-dialog/index.d.ts +69 -0
  12. package/dist/alert-dialog/index.js +94 -0
  13. package/dist/badge/index.d.ts +48 -0
  14. package/dist/badge/index.js +89 -0
  15. package/dist/breadcrumb/index.d.ts +55 -0
  16. package/dist/breadcrumb/index.js +77 -0
  17. package/dist/button/index.d.ts +46 -0
  18. package/dist/button/index.js +86 -0
  19. package/dist/callout/index.d.ts +41 -0
  20. package/dist/callout/index.js +63 -0
  21. package/dist/card/index.d.ts +54 -0
  22. package/dist/card/index.js +103 -0
  23. package/dist/carousel/index.d.ts +98 -0
  24. package/dist/carousel/index.js +243 -0
  25. package/dist/checkbox/index.d.ts +50 -0
  26. package/dist/checkbox/index.js +87 -0
  27. package/dist/combobox/index.d.ts +114 -0
  28. package/dist/combobox/index.js +431 -0
  29. package/dist/command-palette/index.d.ts +73 -0
  30. package/dist/command-palette/index.js +147 -0
  31. package/dist/context-menu/index.d.ts +111 -0
  32. package/dist/context-menu/index.js +372 -0
  33. package/dist/copy-button/index.d.ts +62 -0
  34. package/dist/copy-button/index.js +183 -0
  35. package/dist/core/index.d.ts +20 -0
  36. package/dist/core/index.js +2 -0
  37. package/dist/core/selection.d.ts +5 -0
  38. package/dist/core/selection.js +39 -0
  39. package/dist/core/value-range.d.ts +49 -0
  40. package/dist/core/value-range.js +134 -0
  41. package/dist/date-picker/index.d.ts +210 -0
  42. package/dist/date-picker/index.js +895 -0
  43. package/dist/dialog/index.d.ts +95 -0
  44. package/dist/dialog/index.js +153 -0
  45. package/dist/disclosure/index.d.ts +52 -0
  46. package/dist/disclosure/index.js +159 -0
  47. package/dist/drawer/index.d.ts +30 -0
  48. package/dist/drawer/index.js +39 -0
  49. package/dist/feed/index.d.ts +77 -0
  50. package/dist/feed/index.js +260 -0
  51. package/dist/grid/index.d.ts +103 -0
  52. package/dist/grid/index.js +415 -0
  53. package/dist/index.d.ts +51 -0
  54. package/dist/index.js +51 -0
  55. package/dist/input/index.d.ts +86 -0
  56. package/dist/input/index.js +156 -0
  57. package/dist/interactions/composite-navigation.d.ts +69 -0
  58. package/dist/interactions/composite-navigation.js +169 -0
  59. package/dist/interactions/index.d.ts +15 -0
  60. package/dist/interactions/index.js +4 -0
  61. package/dist/interactions/keyboard-intents.d.ts +16 -0
  62. package/dist/interactions/keyboard-intents.js +33 -0
  63. package/dist/interactions/overlay-focus.d.ts +40 -0
  64. package/dist/interactions/overlay-focus.js +93 -0
  65. package/dist/interactions/typeahead.d.ts +20 -0
  66. package/dist/interactions/typeahead.js +41 -0
  67. package/dist/landmarks/index.d.ts +39 -0
  68. package/dist/landmarks/index.js +58 -0
  69. package/dist/link/index.d.ts +34 -0
  70. package/dist/link/index.js +39 -0
  71. package/dist/listbox/index.d.ts +92 -0
  72. package/dist/listbox/index.js +337 -0
  73. package/dist/menu/index.d.ts +132 -0
  74. package/dist/menu/index.js +541 -0
  75. package/dist/menu-button/index.d.ts +71 -0
  76. package/dist/menu-button/index.js +121 -0
  77. package/dist/meter/index.d.ts +45 -0
  78. package/dist/meter/index.js +106 -0
  79. package/dist/number/index.d.ts +113 -0
  80. package/dist/number/index.js +252 -0
  81. package/dist/popover/index.d.ts +70 -0
  82. package/dist/popover/index.js +126 -0
  83. package/dist/progress/index.d.ts +49 -0
  84. package/dist/progress/index.js +79 -0
  85. package/dist/radio-group/index.d.ts +61 -0
  86. package/dist/radio-group/index.js +150 -0
  87. package/dist/select/index.d.ts +92 -0
  88. package/dist/select/index.js +239 -0
  89. package/dist/sidebar/index.d.ts +74 -0
  90. package/dist/sidebar/index.js +186 -0
  91. package/dist/slider/index.d.ts +61 -0
  92. package/dist/slider/index.js +150 -0
  93. package/dist/slider-multi-thumb/index.d.ts +70 -0
  94. package/dist/slider-multi-thumb/index.js +222 -0
  95. package/dist/spinbutton/index.d.ts +75 -0
  96. package/dist/spinbutton/index.js +214 -0
  97. package/dist/spinner/index.d.ts +1 -0
  98. package/dist/spinner/index.js +1 -0
  99. package/dist/spinner/spinner.d.ts +23 -0
  100. package/dist/spinner/spinner.js +25 -0
  101. package/dist/switch/index.d.ts +40 -0
  102. package/dist/switch/index.js +61 -0
  103. package/dist/table/index.d.ts +117 -0
  104. package/dist/table/index.js +377 -0
  105. package/dist/tabs/index.d.ts +63 -0
  106. package/dist/tabs/index.js +174 -0
  107. package/dist/textarea/index.d.ts +68 -0
  108. package/dist/textarea/index.js +137 -0
  109. package/dist/toast/index.d.ts +67 -0
  110. package/dist/toast/index.js +145 -0
  111. package/dist/toolbar/index.d.ts +59 -0
  112. package/dist/toolbar/index.js +139 -0
  113. package/dist/tooltip/index.d.ts +52 -0
  114. package/dist/tooltip/index.js +169 -0
  115. package/dist/treegrid/index.d.ts +101 -0
  116. package/dist/treegrid/index.js +463 -0
  117. package/dist/treeview/index.d.ts +68 -0
  118. package/dist/treeview/index.js +370 -0
  119. package/dist/window-splitter/index.d.ts +65 -0
  120. package/dist/window-splitter/index.js +204 -0
  121. package/package.json +92 -0
  122. package/specs/ADR-001-headless-architecture.md +461 -0
  123. package/specs/ADR-002-repo-release-model.md +108 -0
  124. package/specs/ADR-003-public-api-versioning.md +136 -0
  125. package/specs/ADR-004-focus-selection-policy.md +117 -0
  126. package/specs/IMPLEMENTATION-ROADMAP.md +237 -0
  127. package/specs/ISSUE-BACKLOG.md +681 -0
  128. package/specs/RELEASE-CANDIDATE.md +30 -0
  129. package/specs/components/accordion.md +130 -0
  130. package/specs/components/alert-dialog.md +72 -0
  131. package/specs/components/alert.md +65 -0
  132. package/specs/components/badge.md +220 -0
  133. package/specs/components/breadcrumb.md +74 -0
  134. package/specs/components/button.md +115 -0
  135. package/specs/components/callout.md +195 -0
  136. package/specs/components/card.md +280 -0
  137. package/specs/components/carousel.md +140 -0
  138. package/specs/components/checkbox.md +172 -0
  139. package/specs/components/combobox.md +423 -0
  140. package/specs/components/command-palette.md +92 -0
  141. package/specs/components/context-menu.md +556 -0
  142. package/specs/components/copy-button.md +293 -0
  143. package/specs/components/date-picker.md +400 -0
  144. package/specs/components/dialog.md +298 -0
  145. package/specs/components/disclosure.md +257 -0
  146. package/specs/components/drawer.md +353 -0
  147. package/specs/components/feed.md +265 -0
  148. package/specs/components/grid.md +186 -0
  149. package/specs/components/input.md +254 -0
  150. package/specs/components/landmarks.md +136 -0
  151. package/specs/components/link.md +134 -0
  152. package/specs/components/listbox.md +351 -0
  153. package/specs/components/menu-button.md +76 -0
  154. package/specs/components/menu.md +623 -0
  155. package/specs/components/meter.md +149 -0
  156. package/specs/components/number.md +393 -0
  157. package/specs/components/popover.md +252 -0
  158. package/specs/components/progress.md +188 -0
  159. package/specs/components/radio-group.md +151 -0
  160. package/specs/components/select.md +144 -0
  161. package/specs/components/sidebar.md +321 -0
  162. package/specs/components/slider-multi-thumb.md +78 -0
  163. package/specs/components/slider.md +84 -0
  164. package/specs/components/spinbutton.md +140 -0
  165. package/specs/components/spinner.md +132 -0
  166. package/specs/components/switch.md +175 -0
  167. package/specs/components/table.md +403 -0
  168. package/specs/components/tabs.md +265 -0
  169. package/specs/components/textarea.md +185 -0
  170. package/specs/components/toast.md +198 -0
  171. package/specs/components/toolbar.md +278 -0
  172. package/specs/components/tooltip.md +252 -0
  173. package/specs/components/treegrid.md +281 -0
  174. package/specs/components/treeview.md +91 -0
  175. package/specs/components/window-splitter.md +297 -0
  176. package/specs/ops/git-shard-sync.md +107 -0
  177. package/specs/ops/release-checklist.md +76 -0
  178. package/specs/release/GAP-TO-GREEN-ISSUES.md +88 -0
  179. package/specs/release/api-freeze-candidate.md +54 -0
  180. package/specs/release/changelog-automation.md +76 -0
  181. package/specs/release/changelog.generated.md +53 -0
  182. package/specs/release/changelog.patch.generated.md +46 -0
  183. package/specs/release/consumer-integration.md +53 -0
  184. package/specs/release/migration-notes-pre-v1.md +40 -0
  185. package/specs/release/mvp-changelog.md +57 -0
  186. package/specs/release/release-notes-template.md +61 -0
  187. package/specs/release/release-rehearsal.md +113 -0
  188. package/specs/release/semver-deprecation-dry-run.md +89 -0
  189. package/specs/release/shard-release-drill-report.md +50 -0
  190. package/specs/release/shard-release-follow-ups.md +31 -0
  191. package/specs/signals.md +208 -0
@@ -0,0 +1,415 @@
1
+ import { action, atom, computed } from '@reatom/core';
2
+ const cellKey = (rowId, colId) => `${rowId}::${colId}`;
3
+ const cellKeyFrom = (cell) => cellKey(cell.rowId, cell.colId);
4
+ const clamp = (value, min, max) => Math.min(Math.max(value, min), max);
5
+ export function createGrid(options) {
6
+ const idBase = options.idBase ?? 'grid';
7
+ const focusStrategy = options.focusStrategy ?? 'roving-tabindex';
8
+ const selectionMode = options.selectionMode ?? 'single';
9
+ const selectionFollowsFocus = options.selectionFollowsFocus ?? false;
10
+ const pageSize = Math.max(options.pageSize ?? 10, 1);
11
+ const rows = [...options.rows];
12
+ const columns = [...options.columns];
13
+ const rowById = new Map(rows.map((row, index) => [row.id, { row, index }]));
14
+ const columnById = new Map(columns.map((column, index) => [column.id, { column, index }]));
15
+ const disabledCellSet = new Set((options.disabledCells ?? []).map((cell) => cellKeyFrom(cell)));
16
+ const rowCountAtom = computed(() => Math.max(options.totalRowCount ?? rows.length, rows.length), `${idBase}.rowCount`);
17
+ const columnCountAtom = computed(() => Math.max(options.totalColumnCount ?? columns.length, columns.length), `${idBase}.columnCount`);
18
+ const getRowIndex = (rowId) => rowById.get(rowId)?.index ?? -1;
19
+ const getColumnIndex = (colId) => columnById.get(colId)?.index ?? -1;
20
+ const rowAriaIndex = (rowId) => {
21
+ const info = rowById.get(rowId);
22
+ if (!info)
23
+ return 1;
24
+ return info.row.index ?? info.index + 1;
25
+ };
26
+ const colAriaIndex = (colId) => {
27
+ const info = columnById.get(colId);
28
+ if (!info)
29
+ return 1;
30
+ return info.column.index ?? info.index + 1;
31
+ };
32
+ const isCellDisabled = (rowId, colId) => {
33
+ const rowInfo = rowById.get(rowId);
34
+ const columnInfo = columnById.get(colId);
35
+ if (!rowInfo || !columnInfo)
36
+ return true;
37
+ if (rowInfo.row.disabled)
38
+ return true;
39
+ if (columnInfo.column.disabled)
40
+ return true;
41
+ if (disabledCellSet.has(cellKey(rowId, colId)))
42
+ return true;
43
+ return false;
44
+ };
45
+ const hasCell = (rowId, colId) => rowById.has(rowId) && columnById.has(colId);
46
+ const firstEnabledCellInRow = (rowIndex) => {
47
+ const rowId = rows[rowIndex]?.id;
48
+ if (!rowId)
49
+ return null;
50
+ for (const column of columns) {
51
+ if (!isCellDisabled(rowId, column.id)) {
52
+ return { rowId, colId: column.id };
53
+ }
54
+ }
55
+ return null;
56
+ };
57
+ const lastEnabledCellInRow = (rowIndex) => {
58
+ const rowId = rows[rowIndex]?.id;
59
+ if (!rowId)
60
+ return null;
61
+ for (let index = columns.length - 1; index >= 0; index -= 1) {
62
+ const columnId = columns[index]?.id;
63
+ if (columnId != null && !isCellDisabled(rowId, columnId)) {
64
+ return { rowId, colId: columnId };
65
+ }
66
+ }
67
+ return null;
68
+ };
69
+ const firstEnabledCellInGrid = () => {
70
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex += 1) {
71
+ const cell = firstEnabledCellInRow(rowIndex);
72
+ if (cell)
73
+ return cell;
74
+ }
75
+ return null;
76
+ };
77
+ const lastEnabledCellInGrid = () => {
78
+ for (let rowIndex = rows.length - 1; rowIndex >= 0; rowIndex -= 1) {
79
+ const cell = lastEnabledCellInRow(rowIndex);
80
+ if (cell)
81
+ return cell;
82
+ }
83
+ return null;
84
+ };
85
+ const normalizeCell = (cell) => {
86
+ if (cell == null)
87
+ return firstEnabledCellInGrid();
88
+ if (!hasCell(cell.rowId, cell.colId))
89
+ return firstEnabledCellInGrid();
90
+ if (isCellDisabled(cell.rowId, cell.colId))
91
+ return firstEnabledCellInGrid();
92
+ return cell;
93
+ };
94
+ const activeCellIdAtom = atom(normalizeCell(options.initialActiveCellId ?? null), `${idBase}.activeCellId`);
95
+ const selectedCellIdsAtom = atom(new Set((options.initialSelectedCellIds ?? [])
96
+ .filter((cell) => hasCell(cell.rowId, cell.colId) && !isCellDisabled(cell.rowId, cell.colId))
97
+ .map((cell) => cellKeyFrom(cell))), `${idBase}.selectedCellIds`);
98
+ const setSelection = (keys) => {
99
+ selectedCellIdsAtom.set(new Set(keys));
100
+ };
101
+ const setActiveCell = action((cell) => {
102
+ const normalized = normalizeCell(cell);
103
+ if (!normalized) {
104
+ activeCellIdAtom.set(null);
105
+ return;
106
+ }
107
+ activeCellIdAtom.set(normalized);
108
+ if (selectionFollowsFocus) {
109
+ setSelection([cellKeyFrom(normalized)]);
110
+ }
111
+ }, `${idBase}.setActiveCell`);
112
+ const tryMoveHorizontal = (direction) => {
113
+ const current = normalizeCell(activeCellIdAtom());
114
+ if (!current)
115
+ return;
116
+ const rowIndex = getRowIndex(current.rowId);
117
+ const colIndex = getColumnIndex(current.colId);
118
+ if (rowIndex < 0 || colIndex < 0)
119
+ return;
120
+ for (let nextCol = colIndex + direction; nextCol >= 0 && nextCol < columns.length; nextCol += direction) {
121
+ const colId = columns[nextCol]?.id;
122
+ if (colId != null && !isCellDisabled(current.rowId, colId)) {
123
+ setActiveCell({ rowId: current.rowId, colId });
124
+ return;
125
+ }
126
+ }
127
+ };
128
+ const tryMoveVertical = (direction) => {
129
+ const current = normalizeCell(activeCellIdAtom());
130
+ if (!current)
131
+ return;
132
+ const rowIndex = getRowIndex(current.rowId);
133
+ if (rowIndex < 0)
134
+ return;
135
+ for (let nextRow = rowIndex + direction; nextRow >= 0 && nextRow < rows.length; nextRow += direction) {
136
+ const rowId = rows[nextRow]?.id;
137
+ if (rowId != null && !isCellDisabled(rowId, current.colId)) {
138
+ setActiveCell({ rowId, colId: current.colId });
139
+ return;
140
+ }
141
+ }
142
+ };
143
+ const moveUp = action(() => {
144
+ tryMoveVertical(-1);
145
+ }, `${idBase}.moveUp`);
146
+ const moveDown = action(() => {
147
+ tryMoveVertical(1);
148
+ }, `${idBase}.moveDown`);
149
+ const moveLeft = action(() => {
150
+ tryMoveHorizontal(-1);
151
+ }, `${idBase}.moveLeft`);
152
+ const moveRight = action(() => {
153
+ tryMoveHorizontal(1);
154
+ }, `${idBase}.moveRight`);
155
+ const moveRowStart = action(() => {
156
+ const current = normalizeCell(activeCellIdAtom());
157
+ if (!current)
158
+ return;
159
+ const rowIndex = getRowIndex(current.rowId);
160
+ if (rowIndex < 0)
161
+ return;
162
+ const cell = firstEnabledCellInRow(rowIndex);
163
+ if (cell) {
164
+ setActiveCell(cell);
165
+ }
166
+ }, `${idBase}.moveRowStart`);
167
+ const moveRowEnd = action(() => {
168
+ const current = normalizeCell(activeCellIdAtom());
169
+ if (!current)
170
+ return;
171
+ const rowIndex = getRowIndex(current.rowId);
172
+ if (rowIndex < 0)
173
+ return;
174
+ const cell = lastEnabledCellInRow(rowIndex);
175
+ if (cell) {
176
+ setActiveCell(cell);
177
+ }
178
+ }, `${idBase}.moveRowEnd`);
179
+ const moveGridStart = action(() => {
180
+ const cell = firstEnabledCellInGrid();
181
+ if (cell) {
182
+ setActiveCell(cell);
183
+ }
184
+ }, `${idBase}.moveGridStart`);
185
+ const moveGridEnd = action(() => {
186
+ const cell = lastEnabledCellInGrid();
187
+ if (cell) {
188
+ setActiveCell(cell);
189
+ }
190
+ }, `${idBase}.moveGridEnd`);
191
+ const moveByPage = (direction) => {
192
+ const current = normalizeCell(activeCellIdAtom());
193
+ if (!current)
194
+ return;
195
+ const rowIndex = getRowIndex(current.rowId);
196
+ if (rowIndex < 0)
197
+ return;
198
+ const targetRowIndex = clamp(rowIndex + direction * pageSize, 0, rows.length - 1);
199
+ for (let nextRow = targetRowIndex; nextRow >= 0 && nextRow < rows.length; nextRow += direction) {
200
+ const rowId = rows[nextRow]?.id;
201
+ if (rowId != null && !isCellDisabled(rowId, current.colId)) {
202
+ setActiveCell({ rowId, colId: current.colId });
203
+ return;
204
+ }
205
+ }
206
+ };
207
+ const pageUp = action(() => {
208
+ moveByPage(-1);
209
+ }, `${idBase}.pageUp`);
210
+ const pageDown = action(() => {
211
+ moveByPage(1);
212
+ }, `${idBase}.pageDown`);
213
+ const selectCell = action((cell) => {
214
+ if (!hasCell(cell.rowId, cell.colId) || isCellDisabled(cell.rowId, cell.colId)) {
215
+ return;
216
+ }
217
+ const key = cellKeyFrom(cell);
218
+ if (selectionMode === 'multiple') {
219
+ setSelection([key]);
220
+ return;
221
+ }
222
+ setSelection([key]);
223
+ }, `${idBase}.selectCell`);
224
+ const toggleCellSelection = action((cell) => {
225
+ if (!hasCell(cell.rowId, cell.colId) || isCellDisabled(cell.rowId, cell.colId)) {
226
+ return;
227
+ }
228
+ if (selectionMode !== 'multiple') {
229
+ selectCell(cell);
230
+ return;
231
+ }
232
+ const key = cellKeyFrom(cell);
233
+ const next = new Set(selectedCellIdsAtom());
234
+ if (next.has(key)) {
235
+ next.delete(key);
236
+ }
237
+ else {
238
+ next.add(key);
239
+ }
240
+ selectedCellIdsAtom.set(next);
241
+ }, `${idBase}.toggleCellSelection`);
242
+ const selectRow = action((rowId) => {
243
+ const rowIndex = getRowIndex(rowId);
244
+ if (rowIndex < 0)
245
+ return;
246
+ const keys = columns
247
+ .map((column) => ({ rowId, colId: column.id }))
248
+ .filter((cell) => !isCellDisabled(cell.rowId, cell.colId))
249
+ .map((cell) => cellKeyFrom(cell));
250
+ if (keys.length === 0)
251
+ return;
252
+ if (selectionMode === 'multiple') {
253
+ setSelection(keys);
254
+ return;
255
+ }
256
+ const firstKey = keys[0];
257
+ if (firstKey != null) {
258
+ setSelection([firstKey]);
259
+ }
260
+ }, `${idBase}.selectRow`);
261
+ const selectColumn = action((colId) => {
262
+ const colIndex = getColumnIndex(colId);
263
+ if (colIndex < 0)
264
+ return;
265
+ const keys = rows
266
+ .map((row) => ({ rowId: row.id, colId }))
267
+ .filter((cell) => !isCellDisabled(cell.rowId, cell.colId))
268
+ .map((cell) => cellKeyFrom(cell));
269
+ if (keys.length === 0)
270
+ return;
271
+ if (selectionMode === 'multiple') {
272
+ setSelection(keys);
273
+ return;
274
+ }
275
+ const firstKey = keys[0];
276
+ if (firstKey != null) {
277
+ setSelection([firstKey]);
278
+ }
279
+ }, `${idBase}.selectColumn`);
280
+ const handleKeyDown = action((event) => {
281
+ const ctrlOrMeta = event.ctrlKey === true || event.metaKey === true;
282
+ switch (event.key) {
283
+ case 'ArrowUp':
284
+ moveUp();
285
+ return;
286
+ case 'ArrowDown':
287
+ moveDown();
288
+ return;
289
+ case 'ArrowLeft':
290
+ moveLeft();
291
+ return;
292
+ case 'ArrowRight':
293
+ moveRight();
294
+ return;
295
+ case 'Home':
296
+ if (ctrlOrMeta) {
297
+ moveGridStart();
298
+ }
299
+ else {
300
+ moveRowStart();
301
+ }
302
+ return;
303
+ case 'End':
304
+ if (ctrlOrMeta) {
305
+ moveGridEnd();
306
+ }
307
+ else {
308
+ moveRowEnd();
309
+ }
310
+ return;
311
+ case 'PageUp':
312
+ pageUp();
313
+ return;
314
+ case 'PageDown':
315
+ pageDown();
316
+ return;
317
+ case 'Enter':
318
+ moveDown();
319
+ return;
320
+ case ' ':
321
+ {
322
+ const current = activeCellIdAtom();
323
+ if (current) {
324
+ if (selectionMode === 'multiple') {
325
+ toggleCellSelection(current);
326
+ }
327
+ else {
328
+ selectCell(current);
329
+ }
330
+ }
331
+ }
332
+ return;
333
+ default:
334
+ return;
335
+ }
336
+ }, `${idBase}.handleKeyDown`);
337
+ const actions = {
338
+ setActiveCell,
339
+ moveUp,
340
+ moveDown,
341
+ moveLeft,
342
+ moveRight,
343
+ moveRowStart,
344
+ moveRowEnd,
345
+ moveGridStart,
346
+ moveGridEnd,
347
+ pageUp,
348
+ pageDown,
349
+ selectCell,
350
+ toggleCellSelection,
351
+ selectRow,
352
+ selectColumn,
353
+ handleKeyDown,
354
+ };
355
+ const cellDomId = (rowId, colId) => `${idBase}-cell-${rowId}-${colId}`;
356
+ const contracts = {
357
+ getGridProps() {
358
+ const activeCell = activeCellIdAtom();
359
+ return {
360
+ id: `${idBase}-root`,
361
+ role: 'grid',
362
+ tabindex: focusStrategy === 'aria-activedescendant' ? '0' : '-1',
363
+ 'aria-label': options.ariaLabel,
364
+ 'aria-labelledby': options.ariaLabelledBy,
365
+ 'aria-multiselectable': selectionMode === 'multiple' ? 'true' : 'false',
366
+ 'aria-colcount': columnCountAtom(),
367
+ 'aria-rowcount': rowCountAtom(),
368
+ 'aria-activedescendant': focusStrategy === 'aria-activedescendant' && activeCell != null
369
+ ? cellDomId(activeCell.rowId, activeCell.colId)
370
+ : undefined,
371
+ };
372
+ },
373
+ getRowProps(rowId) {
374
+ if (!rowById.has(rowId)) {
375
+ throw new Error(`Unknown grid row id: ${rowId}`);
376
+ }
377
+ return {
378
+ id: `${idBase}-row-${rowId}`,
379
+ role: 'row',
380
+ 'aria-rowindex': rowAriaIndex(rowId),
381
+ };
382
+ },
383
+ getCellProps(rowId, colId) {
384
+ if (!hasCell(rowId, colId)) {
385
+ throw new Error(`Unknown grid cell id: ${rowId}:${colId}`);
386
+ }
387
+ const key = cellKey(rowId, colId);
388
+ const activeCell = activeCellIdAtom();
389
+ const isActive = activeCell?.rowId === rowId && activeCell?.colId === colId;
390
+ const isDisabled = isCellDisabled(rowId, colId);
391
+ return {
392
+ id: cellDomId(rowId, colId),
393
+ role: 'gridcell',
394
+ tabindex: focusStrategy === 'roving-tabindex' && isActive && !isDisabled ? '0' : '-1',
395
+ 'aria-colindex': colAriaIndex(colId),
396
+ 'aria-selected': selectedCellIdsAtom().has(key) ? 'true' : 'false',
397
+ 'aria-readonly': options.isReadOnly ? 'true' : undefined,
398
+ 'aria-disabled': isDisabled ? 'true' : undefined,
399
+ 'data-active': isActive ? 'true' : 'false',
400
+ onFocus: () => setActiveCell({ rowId, colId }),
401
+ };
402
+ },
403
+ };
404
+ const state = {
405
+ activeCellId: activeCellIdAtom,
406
+ selectedCellIds: selectedCellIdsAtom,
407
+ rowCount: rowCountAtom,
408
+ columnCount: columnCountAtom,
409
+ };
410
+ return {
411
+ state,
412
+ actions,
413
+ contracts,
414
+ };
415
+ }
@@ -0,0 +1,51 @@
1
+ export * from './core/index.js';
2
+ export * from './interactions/index.js';
3
+ export * from './a11y-contracts/index.js';
4
+ export * from './adapters/index.js';
5
+ export * from './listbox/index.js';
6
+ export * from './combobox/index.js';
7
+ export * from './date-picker/index.js';
8
+ export * from './menu/index.js';
9
+ export * from './tabs/index.js';
10
+ export * from './treeview/index.js';
11
+ export * from './alert/index.js';
12
+ export * from './breadcrumb/index.js';
13
+ export * from './landmarks/index.js';
14
+ export * from './meter/index.js';
15
+ export * from './link/index.js';
16
+ export * from './table/index.js';
17
+ export * from './button/index.js';
18
+ export * from './checkbox/index.js';
19
+ export * from './switch/index.js';
20
+ export * from './radio-group/index.js';
21
+ export * from './slider/index.js';
22
+ export * from './spinbutton/index.js';
23
+ export * from './slider-multi-thumb/index.js';
24
+ export * from './disclosure/index.js';
25
+ export * from './accordion/index.js';
26
+ export * from './dialog/index.js';
27
+ export * from './alert-dialog/index.js';
28
+ export * from './tooltip/index.js';
29
+ export * from './menu-button/index.js';
30
+ export * from './toolbar/index.js';
31
+ export * from './grid/index.js';
32
+ export * from './treegrid/index.js';
33
+ export * from './feed/index.js';
34
+ export * from './carousel/index.js';
35
+ export * from './window-splitter/index.js';
36
+ export * from './popover/index.js';
37
+ export * from './select/index.js';
38
+ export * from './context-menu/index.js';
39
+ export * from './command-palette/index.js';
40
+ export * from './toast/index.js';
41
+ export * from './progress/index.js';
42
+ export * from './input/index.js';
43
+ export * from './badge/index.js';
44
+ export * from './card/index.js';
45
+ export * from './copy-button/index.js';
46
+ export * from './number/index.js';
47
+ export * from './textarea/index.js';
48
+ export * from './spinner/index.js';
49
+ export * from './drawer/index.js';
50
+ export * from './callout/index.js';
51
+ export * from './sidebar/index.js';
package/dist/index.js ADDED
@@ -0,0 +1,51 @@
1
+ export * from './core/index.js';
2
+ export * from './interactions/index.js';
3
+ export * from './a11y-contracts/index.js';
4
+ export * from './adapters/index.js';
5
+ export * from './listbox/index.js';
6
+ export * from './combobox/index.js';
7
+ export * from './date-picker/index.js';
8
+ export * from './menu/index.js';
9
+ export * from './tabs/index.js';
10
+ export * from './treeview/index.js';
11
+ export * from './alert/index.js';
12
+ export * from './breadcrumb/index.js';
13
+ export * from './landmarks/index.js';
14
+ export * from './meter/index.js';
15
+ export * from './link/index.js';
16
+ export * from './table/index.js';
17
+ export * from './button/index.js';
18
+ export * from './checkbox/index.js';
19
+ export * from './switch/index.js';
20
+ export * from './radio-group/index.js';
21
+ export * from './slider/index.js';
22
+ export * from './spinbutton/index.js';
23
+ export * from './slider-multi-thumb/index.js';
24
+ export * from './disclosure/index.js';
25
+ export * from './accordion/index.js';
26
+ export * from './dialog/index.js';
27
+ export * from './alert-dialog/index.js';
28
+ export * from './tooltip/index.js';
29
+ export * from './menu-button/index.js';
30
+ export * from './toolbar/index.js';
31
+ export * from './grid/index.js';
32
+ export * from './treegrid/index.js';
33
+ export * from './feed/index.js';
34
+ export * from './carousel/index.js';
35
+ export * from './window-splitter/index.js';
36
+ export * from './popover/index.js';
37
+ export * from './select/index.js';
38
+ export * from './context-menu/index.js';
39
+ export * from './command-palette/index.js';
40
+ export * from './toast/index.js';
41
+ export * from './progress/index.js';
42
+ export * from './input/index.js';
43
+ export * from './badge/index.js';
44
+ export * from './card/index.js';
45
+ export * from './copy-button/index.js';
46
+ export * from './number/index.js';
47
+ export * from './textarea/index.js';
48
+ export * from './spinner/index.js';
49
+ export * from './drawer/index.js';
50
+ export * from './callout/index.js';
51
+ export * from './sidebar/index.js';
@@ -0,0 +1,86 @@
1
+ import { type Atom } from '@reatom/core';
2
+ export type InputType = 'text' | 'password' | 'email' | 'url' | 'tel' | 'search';
3
+ export interface CreateInputOptions {
4
+ idBase?: string;
5
+ value?: string;
6
+ type?: InputType;
7
+ disabled?: boolean;
8
+ readonly?: boolean;
9
+ required?: boolean;
10
+ placeholder?: string;
11
+ clearable?: boolean;
12
+ passwordToggle?: boolean;
13
+ onInput?: (value: string) => void;
14
+ onClear?: () => void;
15
+ }
16
+ export interface InputState {
17
+ value: Atom<string>;
18
+ type: Atom<InputType>;
19
+ disabled: Atom<boolean>;
20
+ readonly: Atom<boolean>;
21
+ required: Atom<boolean>;
22
+ placeholder: Atom<string>;
23
+ clearable: Atom<boolean>;
24
+ passwordToggle: Atom<boolean>;
25
+ passwordVisible: Atom<boolean>;
26
+ focused: Atom<boolean>;
27
+ filled(): boolean;
28
+ resolvedType(): string;
29
+ showClearButton(): boolean;
30
+ showPasswordToggle(): boolean;
31
+ }
32
+ export interface InputActions {
33
+ setValue(value: string): void;
34
+ setType(type: InputType): void;
35
+ setDisabled(disabled: boolean): void;
36
+ setReadonly(readonly: boolean): void;
37
+ setRequired(required: boolean): void;
38
+ setPlaceholder(placeholder: string): void;
39
+ setClearable(clearable: boolean): void;
40
+ setPasswordToggle(toggle: boolean): void;
41
+ togglePasswordVisibility(): void;
42
+ setFocused(focused: boolean): void;
43
+ clear(): void;
44
+ handleInput(value: string): void;
45
+ handleKeyDown(event: Pick<KeyboardEvent, 'key'> & {
46
+ preventDefault?: () => void;
47
+ }): void;
48
+ }
49
+ export interface InputProps {
50
+ id: string;
51
+ type: string;
52
+ 'aria-disabled'?: 'true';
53
+ 'aria-readonly'?: 'true';
54
+ 'aria-required'?: 'true';
55
+ placeholder?: string;
56
+ disabled?: boolean;
57
+ readonly?: boolean;
58
+ tabindex: '0' | '-1';
59
+ autocomplete?: 'off';
60
+ }
61
+ export interface ClearButtonProps {
62
+ role: 'button';
63
+ 'aria-label': string;
64
+ tabindex: '-1';
65
+ hidden?: true;
66
+ 'aria-hidden'?: 'true';
67
+ }
68
+ export interface PasswordToggleProps {
69
+ role: 'button';
70
+ 'aria-label': string;
71
+ 'aria-pressed': 'true' | 'false';
72
+ tabindex: '0' | '-1';
73
+ hidden?: true;
74
+ 'aria-hidden'?: 'true';
75
+ }
76
+ export interface InputContracts {
77
+ getInputProps(): InputProps;
78
+ getClearButtonProps(): ClearButtonProps;
79
+ getPasswordToggleProps(): PasswordToggleProps;
80
+ }
81
+ export interface InputModel {
82
+ readonly state: InputState;
83
+ readonly actions: InputActions;
84
+ readonly contracts: InputContracts;
85
+ }
86
+ export declare function createInput(options?: CreateInputOptions): InputModel;