@redsift/design-system 11.6.0-muiv5-alpha.5 → 11.6.0-muiv5-alpha.7

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 (150) hide show
  1. package/_internal/Alert2.js +182 -39
  2. package/_internal/AppBar.js +240 -29
  3. package/_internal/AppContainer.js +132 -86
  4. package/_internal/AppContent.js +84 -17
  5. package/_internal/Badge2.js +137 -4
  6. package/_internal/BreadcrumbItem.js +85 -3
  7. package/_internal/Breadcrumbs2.js +86 -21
  8. package/_internal/Button2.js +81 -20
  9. package/_internal/ButtonGroup.js +165 -25
  10. package/_internal/ButtonLink.js +74 -18
  11. package/_internal/Card2.js +151 -29
  12. package/_internal/CardActions.js +38 -3
  13. package/_internal/CardBody.js +36 -3
  14. package/_internal/CardHeader.js +77 -3
  15. package/_internal/Checkbox2.js +234 -58
  16. package/_internal/CheckboxGroup.js +182 -4
  17. package/_internal/ConditionalWrapper.js +11 -12
  18. package/_internal/DetailedCard.js +6912 -48
  19. package/_internal/DetailedCardCollapsibleSectionItems.js +58 -3
  20. package/_internal/DetailedCardHeader.js +61 -3
  21. package/_internal/DetailedCardSection.js +166 -3
  22. package/_internal/DetailedCardSectionItem.js +88 -3
  23. package/_internal/Flexbox2.js +85 -22
  24. package/_internal/Grid2.js +87 -24
  25. package/_internal/GridItem.js +34 -3
  26. package/_internal/Heading2.js +107 -3
  27. package/_internal/Icon2.js +206 -5
  28. package/_internal/IconButton.js +71 -3
  29. package/_internal/IconButtonLink.js +65 -18
  30. package/_internal/Item2.js +390 -73
  31. package/_internal/Link2.js +56 -15
  32. package/_internal/LinkButton.js +56 -13
  33. package/_internal/Number2.js +103 -61
  34. package/_internal/NumberField.js +3959 -65
  35. package/_internal/Pill2.js +400 -4
  36. package/_internal/ProgressBar.js +61 -18
  37. package/_internal/Radio2.js +227 -56
  38. package/_internal/RadioGroup.js +170 -4
  39. package/_internal/Shield2.js +220 -4
  40. package/_internal/SideNavigationMenu.js +586 -4
  41. package/_internal/SideNavigationMenuItem.js +299 -4
  42. package/_internal/Skeleton2.js +36 -9
  43. package/_internal/SkeletonCircle.js +52 -3
  44. package/_internal/SkeletonText.js +71 -3
  45. package/_internal/Spinner2.js +319 -29
  46. package/_internal/Switch2.js +310 -56
  47. package/_internal/SwitchGroup.js +182 -4
  48. package/_internal/Text2.js +45 -3
  49. package/_internal/TextArea.js +430 -20
  50. package/_internal/TextField.js +463 -19
  51. package/_internal/alert.js +2 -5
  52. package/_internal/app-bar.js +2 -8
  53. package/_internal/app-container.js +3 -9
  54. package/_internal/app-content.js +2 -5
  55. package/_internal/app-side-panel.js +3 -11
  56. package/_internal/badge.js +2 -6
  57. package/_internal/breadcrumb-item.js +1 -4
  58. package/_internal/breadcrumbs.js +2 -6
  59. package/_internal/button-group.js +2 -5
  60. package/_internal/button-link.js +2 -8
  61. package/_internal/button.js +3 -8
  62. package/_internal/card-actions.js +1 -4
  63. package/_internal/card-body.js +1 -4
  64. package/_internal/card-header.js +1 -8
  65. package/_internal/card.js +2 -11
  66. package/_internal/checkbox-group.js +2 -6
  67. package/_internal/checkbox.js +2 -6
  68. package/_internal/colors.js +87 -91
  69. package/_internal/conditional-wrapper.js +2 -2
  70. package/_internal/detailed-card-collapsible-section-items.js +1 -3
  71. package/_internal/detailed-card-header.js +1 -7
  72. package/_internal/detailed-card-section-item.js +1 -10
  73. package/_internal/detailed-card-section.js +1 -6
  74. package/_internal/detailed-card.js +2 -16
  75. package/_internal/flexbox.js +2 -5
  76. package/_internal/focus-within-group.js +3 -3
  77. package/_internal/fonts.js +4 -6
  78. package/_internal/gradient-border.js +35 -16
  79. package/_internal/grid-item.js +1 -4
  80. package/_internal/grid.js +2 -6
  81. package/_internal/heading.js +2 -6
  82. package/_internal/icon-button-link.js +2 -8
  83. package/_internal/icon-button.js +2 -6
  84. package/_internal/icon.js +2 -6
  85. package/_internal/item.js +2 -8
  86. package/_internal/link-button.js +2 -8
  87. package/_internal/link.js +3 -8
  88. package/_internal/listbox.js +3 -6
  89. package/_internal/number-field.js +2 -9
  90. package/_internal/number.js +2 -7
  91. package/_internal/pill.js +2 -6
  92. package/_internal/progress-bar.js +2 -5
  93. package/_internal/radio-group.js +2 -6
  94. package/_internal/radio.js +2 -6
  95. package/_internal/shared.js +2 -5
  96. package/_internal/shield.js +2 -6
  97. package/_internal/side-navigation-menu-bar.js +3 -9
  98. package/_internal/side-navigation-menu-item.js +2 -8
  99. package/_internal/side-navigation-menu.js +2 -8
  100. package/_internal/skeleton-circle.js +1 -6
  101. package/_internal/skeleton-text.js +2 -6
  102. package/_internal/skeleton.js +1 -7
  103. package/_internal/spinner.js +2 -5
  104. package/_internal/styles.js +235 -17
  105. package/_internal/styles2.js +44 -280
  106. package/_internal/switch-group.js +2 -6
  107. package/_internal/switch.js +2 -6
  108. package/_internal/text-area.js +2 -9
  109. package/_internal/text-field.js +2 -10
  110. package/_internal/text.js +2 -6
  111. package/_internal/theme.js +1 -3
  112. package/_internal/types.js +7 -31
  113. package/_internal/types2.js +18 -29
  114. package/_internal/types3.js +15 -18
  115. package/_internal/useAppSidePanel.js +331 -6
  116. package/_internal/useFocusOnList.js +502 -44
  117. package/_internal/useListboxItem.js +120 -23
  118. package/_internal/useSideNavigationMenuBar.js +371 -7
  119. package/_internal/useTheme.js +10 -8
  120. package/index.d.ts +4667 -0
  121. package/index.js +523 -1674
  122. package/package.json +2 -2
  123. package/_internal/SideNavigationMenuBar.js +0 -9
  124. package/_internal/helpers.js +0 -23
  125. package/_internal/types10.js +0 -20
  126. package/_internal/types11.js +0 -27
  127. package/_internal/types12.js +0 -35
  128. package/_internal/types13.js +0 -143
  129. package/_internal/types14.js +0 -11
  130. package/_internal/types15.js +0 -62
  131. package/_internal/types16.js +0 -56
  132. package/_internal/types17.js +0 -57
  133. package/_internal/types18.js +0 -40
  134. package/_internal/types19.js +0 -101
  135. package/_internal/types20.js +0 -47
  136. package/_internal/types21.js +0 -68
  137. package/_internal/types22.js +0 -52
  138. package/_internal/types23.js +0 -174
  139. package/_internal/types24.js +0 -18
  140. package/_internal/types25.js +0 -12
  141. package/_internal/types26.js +0 -36
  142. package/_internal/types27.js +0 -72
  143. package/_internal/types28.js +0 -73
  144. package/_internal/types29.js +0 -99
  145. package/_internal/types4.js +0 -67
  146. package/_internal/types5.js +0 -11
  147. package/_internal/types6.js +0 -11
  148. package/_internal/types7.js +0 -28
  149. package/_internal/types8.js +0 -72
  150. package/_internal/types9.js +0 -16
@@ -1,5 +1,420 @@
1
- import React, { RefObject } from 'react';
2
- import { f as FocusWithinGroupProps, F as FocusWithinGroupState, e as FocusWithinGroupContextProps, c as FocusWithinGroupAction, U as UseFocusWithinGroupProps, d as UseFocusGroupProps } from './types13.js';
1
+ import { _ as _objectSpread2 } from './_rollupPluginBabelHelpers.js';
2
+ import React__default, { useReducer, useEffect, useMemo, useContext, useCallback } from 'react';
3
+ import { F as FocusWithinGroupActionType, N as Navigation, E as EventKey, a as FOCUS_WITHING_GROUP_INITIAL_STATE, b as FocusWithinGroupContext } from './useFocusOnListItem.js';
4
+
5
+ const DOCUMENT_POSITION_FOLLOWING = 4;
6
+ const FocusWithinGroupReducer = (state, action) => {
7
+ switch (action.type) {
8
+ case FocusWithinGroupActionType.REGISTER_TAB_STOP:
9
+ {
10
+ const newTabStop = action.payload;
11
+ if (!newTabStop.domElementRef.current) {
12
+ return state;
13
+ }
14
+
15
+ // Iterate backwards through state.tabStops since it is
16
+ // most likely that the tab stop will need to be inserted
17
+ // at the end of that array.
18
+ let indexToInsertAt = -1;
19
+ for (let i = state.tabStops.length - 1; i >= 0; --i) {
20
+ const loopTabStop = state.tabStops[i];
21
+ if (loopTabStop.id === newTabStop.id) {
22
+ // console.warn(false, `'${newTabStop.id}' tab stop already registered`);
23
+ return state;
24
+ }
25
+ // The compareDocumentPosition condition is true
26
+ // if newTabStop follows loopTabStop:
27
+ if (indexToInsertAt === -1 && loopTabStop.domElementRef.current && !!(loopTabStop.domElementRef.current.compareDocumentPosition(newTabStop.domElementRef.current) & DOCUMENT_POSITION_FOLLOWING)) {
28
+ indexToInsertAt = i + 1;
29
+ break;
30
+ }
31
+ }
32
+
33
+ // The indexToInsertAt is -1 when newTabStop should be inserted
34
+ // at the start of tabStops (the compareDocumentPosition condition
35
+ // always returns false in that case).
36
+ if (indexToInsertAt === -1) {
37
+ indexToInsertAt = 0;
38
+ }
39
+ const newTabStops = state.tabStops.slice();
40
+ newTabStops.splice(indexToInsertAt, 0, newTabStop);
41
+ return _objectSpread2(_objectSpread2({}, state), {}, {
42
+ selectedId: state.focusOnInit ? getUpdatedSelectedId(newTabStops, state.selectedId) : null,
43
+ tabStops: newTabStops,
44
+ rowStartMap: null
45
+ });
46
+ }
47
+ case FocusWithinGroupActionType.UNREGISTER_TAB_STOP:
48
+ {
49
+ const id = action.payload.id;
50
+ const newTabStops = state.tabStops.filter(tabStop => tabStop.id !== id);
51
+ if (newTabStops.length === state.tabStops.length) {
52
+ // console.warn(false, `'${id}' tab stop already unregistered`);
53
+ return state;
54
+ }
55
+ return _objectSpread2(_objectSpread2({}, state), {}, {
56
+ selectedId: state.focusOnInit ? getUpdatedSelectedId(newTabStops, state.selectedId) : null,
57
+ tabStops: newTabStops,
58
+ rowStartMap: null
59
+ });
60
+ }
61
+ case FocusWithinGroupActionType.TAB_STOP_UPDATED:
62
+ {
63
+ const {
64
+ id,
65
+ rowIndex,
66
+ isDisabled,
67
+ value
68
+ } = action.payload;
69
+ const index = state.tabStops.findIndex(tabStop => tabStop.id === id);
70
+ if (index === -1) {
71
+ console.warn(false, `'${id}' tab stop not registered`);
72
+ return state;
73
+ }
74
+ const tabStop = state.tabStops[index];
75
+ if (tabStop.isDisabled === isDisabled && tabStop.rowIndex === rowIndex && tabStop.value === value) {
76
+ // Nothing to do so short-circuit.
77
+ return state;
78
+ }
79
+ const newTabStop = _objectSpread2(_objectSpread2({}, tabStop), {}, {
80
+ rowIndex,
81
+ isDisabled,
82
+ value
83
+ });
84
+ const newTabStops = state.tabStops.slice();
85
+ newTabStops.splice(index, 1, newTabStop);
86
+ return _objectSpread2(_objectSpread2({}, state), {}, {
87
+ selectedId: state.focusOnInit ? getUpdatedSelectedId(newTabStops, state.selectedId) : null,
88
+ tabStops: newTabStops,
89
+ rowStartMap: null
90
+ });
91
+ }
92
+ case FocusWithinGroupActionType.KEY_DOWN_ON_ITEM:
93
+ {
94
+ const {
95
+ id,
96
+ key,
97
+ ctrlKey
98
+ } = action.payload;
99
+ const index = state.tabStops.findIndex(tabStop => tabStop.id === id);
100
+ if (index === -1) {
101
+ console.warn(false, `'${id}' tab stop not registered`);
102
+ return state;
103
+ }
104
+ return moveSelectionFromKey(state, index, key, ctrlKey);
105
+ }
106
+ case FocusWithinGroupActionType.CLICK_ON_ITEM:
107
+ {
108
+ const id = action.payload.id;
109
+ const index = state.tabStops.findIndex(tabStop => tabStop.id === id);
110
+ if (index === -1) {
111
+ console.warn(false, `'${id}' tab stop not registered`);
112
+ return state;
113
+ }
114
+ const currentTabStop = state.tabStops[index];
115
+ return currentTabStop.isDisabled ? state : selectTabStop(state, currentTabStop, undefined, state.focusOnClick);
116
+ }
117
+ case FocusWithinGroupActionType.FOCUS_ON_LIST:
118
+ {
119
+ var _action$payload$id, _state$tabStops$;
120
+ const id = (_action$payload$id = action.payload.id) !== null && _action$payload$id !== void 0 ? _action$payload$id : (_state$tabStops$ = state.tabStops[0]) === null || _state$tabStops$ === void 0 ? void 0 : _state$tabStops$.id;
121
+ const index = state.tabStops.findIndex(tabStop => tabStop.id === id);
122
+ if (index === -1) {
123
+ return state;
124
+ }
125
+ const currentTabStop = state.tabStops[index];
126
+ return currentTabStop.isDisabled ? _objectSpread2(_objectSpread2({}, state), {}, {
127
+ delayedAction: undefined
128
+ }, action.payload) : selectTabStop(_objectSpread2(_objectSpread2({}, state), {}, {
129
+ delayedAction: undefined
130
+ }, action.payload), currentTabStop, undefined, state.focusOnClick);
131
+ }
132
+ case FocusWithinGroupActionType.BLUR_ON_LIST:
133
+ {
134
+ return _objectSpread2(_objectSpread2({}, state), {}, {
135
+ activedescendant: ['', '']
136
+ });
137
+ }
138
+ case FocusWithinGroupActionType.KEY_DOWN_ON_LIST:
139
+ {
140
+ const {
141
+ key,
142
+ ctrlKey
143
+ } = action.payload;
144
+ let index = state.tabStops.findIndex(tabStop => tabStop.id === state.selectedId);
145
+ if (index === -1) {
146
+ if (state.focusOnInit) {
147
+ console.warn(false, `'${state.selectedId}' tab stop not registered`);
148
+ return _objectSpread2(_objectSpread2({}, state), {}, {
149
+ delayedAction: undefined
150
+ });
151
+ } else {
152
+ index = 0;
153
+ }
154
+ }
155
+ return moveSelectionFromKey(_objectSpread2(_objectSpread2({}, state), {}, {
156
+ delayedAction: undefined
157
+ }), index, key, ctrlKey);
158
+ }
159
+ case FocusWithinGroupActionType.OPTIONS_UPDATED:
160
+ return _objectSpread2(_objectSpread2({}, state), action.payload);
161
+ case FocusWithinGroupActionType.FILTER_LIST:
162
+ return _objectSpread2(_objectSpread2({}, state), {}, {
163
+ selectedId: null
164
+ }, action.payload);
165
+ case FocusWithinGroupActionType.DELAY_ACTION:
166
+ return _objectSpread2(_objectSpread2({}, state), {}, {
167
+ delayedAction: action.payload
168
+ });
169
+ /* istanbul ignore next */
170
+ default:
171
+ return state;
172
+ }
173
+ };
174
+ function findIndexOfVeryFirstActiveTabStop(tabStops) {
175
+ return tabStops.findIndex(tabStop => !tabStop.isDisabled);
176
+ }
177
+ function findIndexOfVeryLastActiveTabStop(tabStops) {
178
+ for (let i = tabStops.length - 1; i >= 0; --i) {
179
+ const tabStop = tabStops[i];
180
+ if (!tabStop.isDisabled) {
181
+ return i;
182
+ }
183
+ }
184
+ return -1;
185
+ }
186
+
187
+ // Determine the updated value for selectedId:
188
+ function getUpdatedSelectedId(tabStops, currentSelectedId) {
189
+ if (currentSelectedId === null) {
190
+ // There is not currently selected tab stop, so find
191
+ // the first tab stop that is not isDisabled and return
192
+ // its id, otherwise return null.
193
+ const index = tabStops.findIndex(tabStop => !tabStop.isDisabled);
194
+ return index === -1 ? null : tabStops[index].id;
195
+ }
196
+ let index = tabStops.findIndex(tabStop => tabStop.id === currentSelectedId);
197
+ if (index !== -1 && !tabStops[index].isDisabled) {
198
+ // The current selected id is still valid, so return it.
199
+ return currentSelectedId;
200
+ }
201
+
202
+ // Finds the first tab stop that is not isDisabled and return
203
+ // its id, otherwise return null.
204
+ index = tabStops.findIndex(tabStop => !tabStop.isDisabled);
205
+ return index === -1 ? null : tabStops[index].id;
206
+ }
207
+
208
+ // Translates the user key down event info into a navigation instruction.
209
+ function getNavigationValue(key, ctrlKey, isGrid, direction, loopAround, isFirst, isLast) {
210
+ switch (key) {
211
+ case EventKey.ArrowLeft:
212
+ if (isGrid || direction === 'horizontal' || direction === 'both') {
213
+ return !isGrid && loopAround && isFirst ? Navigation.VERY_LAST : Navigation.PREVIOUS;
214
+ }
215
+ return null;
216
+ case EventKey.ArrowRight:
217
+ if (isGrid || direction === 'horizontal' || direction === 'both') {
218
+ return !isGrid && loopAround && isLast ? Navigation.VERY_FIRST : Navigation.NEXT;
219
+ }
220
+ return null;
221
+ case EventKey.ArrowUp:
222
+ if (isGrid) {
223
+ return Navigation.PREVIOUS_ROW;
224
+ } else if (direction === 'vertical' || direction === 'both') {
225
+ return loopAround && isFirst ? Navigation.VERY_LAST : Navigation.PREVIOUS;
226
+ }
227
+ return null;
228
+ case EventKey.ArrowDown:
229
+ if (isGrid) {
230
+ return Navigation.NEXT_ROW;
231
+ } else if (direction === 'vertical' || direction === 'both') {
232
+ return loopAround && isLast ? Navigation.VERY_FIRST : Navigation.NEXT;
233
+ }
234
+ return null;
235
+ case EventKey.Home:
236
+ return !isGrid || ctrlKey ? Navigation.VERY_FIRST : Navigation.FIRST_IN_ROW;
237
+ case EventKey.End:
238
+ return !isGrid || ctrlKey ? Navigation.VERY_LAST : Navigation.LAST_IN_ROW;
239
+ /* istanbul ignore next */
240
+ default:
241
+ return null;
242
+ }
243
+ }
244
+
245
+ // Creates the new state for a tab stop when it becomes the selected one.
246
+ function selectTabStop(state, tabStop, rowStartMap) {
247
+ let allowFocusing = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
248
+ return _objectSpread2(_objectSpread2({}, state), {}, {
249
+ allowFocusing,
250
+ selectedId: tabStop.id,
251
+ rowStartMap: rowStartMap || state.rowStartMap,
252
+ activedescendant: state.focusType === 'virtual-focus' ? [tabStop.id, tabStop.value] : undefined
253
+ });
254
+ }
255
+
256
+ // Creates the row start index lookup map
257
+ // for the currently registered tab stops.
258
+ function createRowStartMap(state) {
259
+ const map = new Map();
260
+ for (let i = 0; i < state.tabStops.length; ++i) {
261
+ const {
262
+ rowIndex
263
+ } = state.tabStops[i];
264
+ if (rowIndex !== null && !map.has(rowIndex)) {
265
+ map.set(rowIndex, i);
266
+ }
267
+ }
268
+ return map;
269
+ }
270
+ function moveSelectionFromKey(state, index, key, ctrlKey) {
271
+ const currentTabStop = state.tabStops[index];
272
+ if (currentTabStop.isDisabled) {
273
+ return state;
274
+ }
275
+ const isGrid = currentTabStop.rowIndex !== null;
276
+ const isFirst = index === findIndexOfVeryFirstActiveTabStop(state.tabStops);
277
+ const isLast = index === findIndexOfVeryLastActiveTabStop(state.tabStops);
278
+ const navigation = getNavigationValue(key, ctrlKey, isGrid, state.direction, state.loopAround, isFirst, isLast);
279
+ if (!navigation) {
280
+ return state;
281
+ }
282
+ switch (navigation) {
283
+ case Navigation.NEXT:
284
+ {
285
+ for (let i = index + 1; i < state.tabStops.length; ++i) {
286
+ const tabStop = state.tabStops[i];
287
+ if (isGrid && tabStop.rowIndex !== currentTabStop.rowIndex) {
288
+ break;
289
+ }
290
+ if (!tabStop.isDisabled) {
291
+ return selectTabStop(state, tabStop);
292
+ }
293
+ }
294
+ }
295
+ break;
296
+ case Navigation.PREVIOUS:
297
+ {
298
+ for (let i = index - 1; i >= 0; --i) {
299
+ const tabStop = state.tabStops[i];
300
+ if (isGrid && tabStop.rowIndex !== currentTabStop.rowIndex) {
301
+ break;
302
+ }
303
+ if (!tabStop.isDisabled) {
304
+ return selectTabStop(state, tabStop);
305
+ }
306
+ }
307
+ }
308
+ break;
309
+ case Navigation.VERY_FIRST:
310
+ {
311
+ const index = findIndexOfVeryFirstActiveTabStop(state.tabStops);
312
+ if (index > -1) {
313
+ return selectTabStop(state, state.tabStops[index]);
314
+ }
315
+ }
316
+ break;
317
+ case Navigation.VERY_LAST:
318
+ {
319
+ const index = findIndexOfVeryLastActiveTabStop(state.tabStops);
320
+ if (index > -1) {
321
+ return selectTabStop(state, state.tabStops[index]);
322
+ }
323
+ }
324
+ break;
325
+ case Navigation.PREVIOUS_ROW:
326
+ {
327
+ if (currentTabStop.rowIndex === null || currentTabStop.rowIndex === 0) {
328
+ return state;
329
+ }
330
+ const rowStartMap = state.rowStartMap || createRowStartMap(state);
331
+ const rowStartIndex = rowStartMap.get(currentTabStop.rowIndex);
332
+ if (rowStartIndex === undefined) {
333
+ return state;
334
+ }
335
+ const columnOffset = index - rowStartIndex;
336
+ for (let i = currentTabStop.rowIndex - 1; i >= 0; --i) {
337
+ const rowStartIndex = rowStartMap.get(i);
338
+ if (rowStartIndex === undefined) {
339
+ return state;
340
+ }
341
+ const rowTabStop = state.tabStops[rowStartIndex + columnOffset];
342
+ if (rowTabStop && !rowTabStop.isDisabled) {
343
+ return selectTabStop(state, rowTabStop, rowStartMap);
344
+ }
345
+ }
346
+ return _objectSpread2(_objectSpread2({}, state), {}, {
347
+ allowFocusing: true,
348
+ rowStartMap
349
+ });
350
+ }
351
+ case Navigation.NEXT_ROW:
352
+ {
353
+ const maxRowIndex = state.tabStops[state.tabStops.length - 1].rowIndex;
354
+ if (currentTabStop.rowIndex === null || maxRowIndex === null || currentTabStop.rowIndex === maxRowIndex) {
355
+ return state;
356
+ }
357
+ const rowStartMap = state.rowStartMap || createRowStartMap(state);
358
+ const rowStartIndex = rowStartMap.get(currentTabStop.rowIndex);
359
+ if (rowStartIndex === undefined) {
360
+ return state;
361
+ }
362
+ const columnOffset = index - rowStartIndex;
363
+ for (let i = currentTabStop.rowIndex + 1; i <= maxRowIndex; ++i) {
364
+ const rowStartIndex = rowStartMap.get(i);
365
+ if (rowStartIndex === undefined) {
366
+ return state;
367
+ }
368
+ const rowTabStop = state.tabStops[rowStartIndex + columnOffset];
369
+ if (rowTabStop && !rowTabStop.isDisabled) {
370
+ return selectTabStop(state, rowTabStop, rowStartMap);
371
+ }
372
+ }
373
+ return _objectSpread2(_objectSpread2({}, state), {}, {
374
+ allowFocusing: true,
375
+ rowStartMap
376
+ });
377
+ }
378
+ case Navigation.FIRST_IN_ROW:
379
+ {
380
+ if (currentTabStop.rowIndex === null) {
381
+ return state;
382
+ }
383
+ const rowStartMap = state.rowStartMap || createRowStartMap(state);
384
+ const rowStartIndex = rowStartMap.get(currentTabStop.rowIndex);
385
+ if (rowStartIndex === undefined) {
386
+ return state;
387
+ }
388
+ for (let i = rowStartIndex; i < state.tabStops.length; ++i) {
389
+ const tabStop = state.tabStops[i];
390
+ if (tabStop.rowIndex !== currentTabStop.rowIndex) {
391
+ break;
392
+ } else if (!tabStop.isDisabled) {
393
+ return selectTabStop(state, state.tabStops[i], rowStartMap);
394
+ }
395
+ }
396
+ }
397
+ break;
398
+ case Navigation.LAST_IN_ROW:
399
+ {
400
+ if (currentTabStop.rowIndex === null) {
401
+ return state;
402
+ }
403
+ const rowStartMap = state.rowStartMap || createRowStartMap(state);
404
+ const rowEndIndex = rowStartMap.has(currentTabStop.rowIndex + 1) ? (rowStartMap.get(currentTabStop.rowIndex + 1) || 0) - 1 : state.tabStops.length - 1;
405
+ for (let i = rowEndIndex; i >= 0; --i) {
406
+ const tabStop = state.tabStops[i];
407
+ if (tabStop.rowIndex !== currentTabStop.rowIndex) {
408
+ break;
409
+ } else if (!tabStop.isDisabled) {
410
+ return selectTabStop(state, state.tabStops[i], rowStartMap);
411
+ }
412
+ }
413
+ }
414
+ break;
415
+ }
416
+ return state;
417
+ }
3
418
 
4
419
  /**
5
420
  * The FocusWithinGroup component.
@@ -36,48 +451,91 @@ import { f as FocusWithinGroupProps, F as FocusWithinGroupState, e as FocusWithi
36
451
  * Note that this option does not apply if the roving tabindex
37
452
  * is being used on a grid.
38
453
  */
39
- declare const FocusWithinGroup: React.FC<FocusWithinGroupProps>;
40
-
41
- declare const FOCUS_WITHING_GROUP_INITIAL_STATE: FocusWithinGroupState;
42
- declare const FocusWithinGroupContext: React.Context<FocusWithinGroupContextProps>;
454
+ const FocusWithinGroup = props => {
455
+ const {
456
+ children,
457
+ direction,
458
+ focusOnClick,
459
+ loopAround,
460
+ focusType,
461
+ listRole,
462
+ focusOnInit,
463
+ activedescendant,
464
+ maxOptionsLength
465
+ } = props;
466
+ const [state, dispatch] = useReducer(FocusWithinGroupReducer, _objectSpread2(_objectSpread2({}, FOCUS_WITHING_GROUP_INITIAL_STATE), {}, {
467
+ direction,
468
+ focusOnClick,
469
+ loopAround,
470
+ focusType,
471
+ listRole,
472
+ focusOnInit,
473
+ activedescendant,
474
+ maxOptionsLength
475
+ }));
43
476
 
44
- declare const FocusWithinGroupReducer: (state: FocusWithinGroupState, action: FocusWithinGroupAction) => FocusWithinGroupState;
45
-
46
- declare function uniqueId(): string;
47
- /**
48
- * Includes the given DOM element in the current roving tabindex.
49
- * @param {RefObject<Element>} domElementRef The DOM element to include.
50
- * This must be the same DOM element for the lifetime of the containing
51
- * component.
52
- * @param {boolean} isDisabled Whether or not the DOM element is currently
53
- * enabled. This value can be updated as appropriate throughout the lifetime
54
- * of the containing component.
55
- * @param {number?} rowIndex An optional integer value that must be
56
- * populated if the roving tabindex is being used in a grid. In that case,
57
- * set it to the zero-based index of the row that the given DOM element
58
- * is currently part of. You can update this row index as appropriate
59
- * throughout the lifetime of the containing component, for example if
60
- * the shape of the grid can change dynamically.
61
- * @returns A tuple of values to be applied by the containing
62
- * component for the roving tabindex to work correctly.
63
- * First tuple value: The tabIndex value to apply to the tab stop
64
- * element.
65
- * Second tuple value: Whether or not focus() should be invoked on the
66
- * tab stop element.
67
- * Third tuple value: The onKeyDown callback to apply to the tab
68
- * stop element. If the key press is relevant to the hook then
69
- * event.preventDefault() will be invoked on the event.
70
- * Fourth tuple value: The onClick callback to apply to the tab
71
- * stop element.
72
- */
73
- declare function useFocusOnListItem(props: {
74
- domElementRef: RefObject<Element>;
75
- isDisabled: boolean;
76
- id?: string;
77
- value?: string;
78
- rowIndex?: number | null;
79
- }): UseFocusWithinGroupProps;
477
+ // Update the options whenever they change:
478
+ useEffect(() => {
479
+ dispatch({
480
+ type: FocusWithinGroupActionType.OPTIONS_UPDATED,
481
+ payload: {
482
+ direction: direction !== null && direction !== void 0 ? direction : FOCUS_WITHING_GROUP_INITIAL_STATE.direction,
483
+ focusOnClick: focusOnClick !== null && focusOnClick !== void 0 ? focusOnClick : FOCUS_WITHING_GROUP_INITIAL_STATE.focusOnClick,
484
+ loopAround: loopAround !== null && loopAround !== void 0 ? loopAround : FOCUS_WITHING_GROUP_INITIAL_STATE.loopAround,
485
+ focusType: focusType !== null && focusType !== void 0 ? focusType : FOCUS_WITHING_GROUP_INITIAL_STATE.focusType,
486
+ listRole: listRole !== null && listRole !== void 0 ? listRole : FOCUS_WITHING_GROUP_INITIAL_STATE.listRole,
487
+ focusOnInit: focusOnInit !== null && focusOnInit !== void 0 ? focusOnInit : FOCUS_WITHING_GROUP_INITIAL_STATE.focusOnInit,
488
+ activedescendant: activedescendant !== null && activedescendant !== void 0 ? activedescendant : FOCUS_WITHING_GROUP_INITIAL_STATE.activedescendant,
489
+ maxOptionsLength: maxOptionsLength !== null && maxOptionsLength !== void 0 ? maxOptionsLength : FOCUS_WITHING_GROUP_INITIAL_STATE.maxOptionsLength
490
+ }
491
+ });
492
+ }, [direction, focusOnClick, focusOnInit, loopAround, focusType, listRole, activedescendant, maxOptionsLength]);
493
+ const context = useMemo(() => ({
494
+ state,
495
+ dispatch
496
+ }), [state]);
497
+ return /*#__PURE__*/React__default.createElement(FocusWithinGroupContext.Provider, {
498
+ value: context
499
+ }, children);
500
+ };
80
501
 
81
- declare function useFocusOnList(): UseFocusGroupProps;
502
+ function useFocusOnList() {
503
+ const context = useContext(FocusWithinGroupContext);
504
+ const handleKeyDown = useCallback(event => {
505
+ const key = EventKey[event.key];
506
+ if (!key) {
507
+ return;
508
+ }
509
+ context.dispatch({
510
+ type: FocusWithinGroupActionType.KEY_DOWN_ON_LIST,
511
+ payload: {
512
+ key,
513
+ ctrlKey: event.ctrlKey
514
+ }
515
+ });
516
+ event.preventDefault();
517
+ }, []);
518
+ const handleFocus = useCallback(() => {
519
+ context.dispatch({
520
+ type: FocusWithinGroupActionType.FOCUS_ON_LIST,
521
+ payload: {
522
+ id: context.state.selectedId
523
+ }
524
+ });
525
+ }, [context.state.selectedId]);
526
+ const handleBlur = useCallback(() => {
527
+ context.dispatch({
528
+ type: FocusWithinGroupActionType.BLUR_ON_LIST,
529
+ payload: {}
530
+ });
531
+ }, []);
532
+ return {
533
+ activedescendant: context.state.activedescendant,
534
+ handleKeyDown,
535
+ handleFocus,
536
+ handleBlur
537
+ };
538
+ }
82
539
 
83
- export { FocusWithinGroup as F, FOCUS_WITHING_GROUP_INITIAL_STATE as a, FocusWithinGroupContext as b, FocusWithinGroupReducer as c, useFocusOnListItem as d, useFocusOnList as e, uniqueId as u };
540
+ export { FocusWithinGroup as F, FocusWithinGroupReducer as a, useFocusOnList as u };
541
+ //# sourceMappingURL=useFocusOnList.js.map