@instructure/ui-drilldown 11.7.2-snapshot-18 → 11.7.2-snapshot-19

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 (64) hide show
  1. package/CHANGELOG.md +12 -2
  2. package/es/Drilldown/v2/DrilldownGroup/index.js +55 -0
  3. package/es/Drilldown/v2/DrilldownGroup/props.js +26 -0
  4. package/es/Drilldown/v2/DrilldownOption/index.js +54 -0
  5. package/es/Drilldown/v2/DrilldownOption/props.js +26 -0
  6. package/es/Drilldown/v2/DrilldownPage/index.js +50 -0
  7. package/es/Drilldown/v2/DrilldownPage/props.js +26 -0
  8. package/es/Drilldown/v2/DrilldownSeparator/index.js +47 -0
  9. package/es/Drilldown/v2/DrilldownSeparator/props.js +26 -0
  10. package/es/Drilldown/v2/index.js +1358 -0
  11. package/es/Drilldown/v2/props.js +28 -0
  12. package/es/Drilldown/v2/styles.js +84 -0
  13. package/es/exports/b.js +28 -0
  14. package/lib/Drilldown/v2/DrilldownGroup/index.js +58 -0
  15. package/lib/Drilldown/v2/DrilldownGroup/props.js +31 -0
  16. package/lib/Drilldown/v2/DrilldownOption/index.js +58 -0
  17. package/lib/Drilldown/v2/DrilldownOption/props.js +31 -0
  18. package/lib/Drilldown/v2/DrilldownPage/index.js +56 -0
  19. package/lib/Drilldown/v2/DrilldownPage/props.js +31 -0
  20. package/lib/Drilldown/v2/DrilldownSeparator/index.js +51 -0
  21. package/lib/Drilldown/v2/DrilldownSeparator/props.js +31 -0
  22. package/lib/Drilldown/v2/index.js +1369 -0
  23. package/lib/Drilldown/v2/props.js +33 -0
  24. package/lib/Drilldown/v2/styles.js +90 -0
  25. package/lib/exports/b.js +40 -0
  26. package/package.json +28 -28
  27. package/src/Drilldown/v2/DrilldownGroup/index.tsx +64 -0
  28. package/src/Drilldown/v2/DrilldownGroup/props.ts +134 -0
  29. package/src/Drilldown/v2/DrilldownOption/index.tsx +65 -0
  30. package/src/Drilldown/v2/DrilldownOption/props.ts +211 -0
  31. package/src/Drilldown/v2/DrilldownPage/index.tsx +55 -0
  32. package/src/Drilldown/v2/DrilldownPage/props.ts +102 -0
  33. package/src/Drilldown/v2/DrilldownSeparator/index.tsx +57 -0
  34. package/src/Drilldown/v2/DrilldownSeparator/props.ts +56 -0
  35. package/src/Drilldown/v2/README.md +1445 -0
  36. package/src/Drilldown/v2/index.tsx +1681 -0
  37. package/src/Drilldown/v2/props.ts +361 -0
  38. package/src/Drilldown/v2/styles.ts +97 -0
  39. package/src/exports/b.ts +44 -0
  40. package/tsconfig.build.tsbuildinfo +1 -1
  41. package/types/Drilldown/v2/DrilldownGroup/index.d.ts +41 -0
  42. package/types/Drilldown/v2/DrilldownGroup/index.d.ts.map +1 -0
  43. package/types/Drilldown/v2/DrilldownGroup/props.d.ts +69 -0
  44. package/types/Drilldown/v2/DrilldownGroup/props.d.ts.map +1 -0
  45. package/types/Drilldown/v2/DrilldownOption/index.d.ts +69 -0
  46. package/types/Drilldown/v2/DrilldownOption/index.d.ts.map +1 -0
  47. package/types/Drilldown/v2/DrilldownOption/props.d.ts +125 -0
  48. package/types/Drilldown/v2/DrilldownOption/props.d.ts.map +1 -0
  49. package/types/Drilldown/v2/DrilldownPage/index.d.ts +32 -0
  50. package/types/Drilldown/v2/DrilldownPage/index.d.ts.map +1 -0
  51. package/types/Drilldown/v2/DrilldownPage/props.d.ts +51 -0
  52. package/types/Drilldown/v2/DrilldownPage/props.d.ts.map +1 -0
  53. package/types/Drilldown/v2/DrilldownSeparator/index.d.ts +22 -0
  54. package/types/Drilldown/v2/DrilldownSeparator/index.d.ts.map +1 -0
  55. package/types/Drilldown/v2/DrilldownSeparator/props.d.ts +17 -0
  56. package/types/Drilldown/v2/DrilldownSeparator/props.d.ts.map +1 -0
  57. package/types/Drilldown/v2/index.d.ts +212 -0
  58. package/types/Drilldown/v2/index.d.ts.map +1 -0
  59. package/types/Drilldown/v2/props.d.ts +210 -0
  60. package/types/Drilldown/v2/props.d.ts.map +1 -0
  61. package/types/Drilldown/v2/styles.d.ts +15 -0
  62. package/types/Drilldown/v2/styles.d.ts.map +1 -0
  63. package/types/exports/b.d.ts +11 -0
  64. package/types/exports/b.d.ts.map +1 -0
@@ -0,0 +1,1369 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.Drilldown = void 0;
8
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
+ var _react = require("react");
10
+ var _console = require("@instructure/console");
11
+ var _contains = require("@instructure/ui-dom-utils/lib/contains.js");
12
+ var _containsActiveElement = require("@instructure/ui-dom-utils/lib/containsActiveElement.js");
13
+ var _deepEqual = require("@instructure/ui-utils/lib/deepEqual.js");
14
+ var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
15
+ var _matchComponentTypes = require("@instructure/ui-react-utils/lib/matchComponentTypes.js");
16
+ var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
17
+ var _safeCloneElement = require("@instructure/ui-react-utils/lib/safeCloneElement.js");
18
+ var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
19
+ var _latest = require("@instructure/ui-view/latest");
20
+ var _latest2 = require("@instructure/ui-options/latest");
21
+ var _latest3 = require("@instructure/ui-popover/latest");
22
+ var _Selectable = require("@instructure/ui-selectable/lib/Selectable");
23
+ var _uiIcons = require("@instructure/ui-icons");
24
+ var _emotion = require("@instructure/emotion");
25
+ var _DrilldownSeparator = require("./DrilldownSeparator");
26
+ var _DrilldownOption = require("./DrilldownOption");
27
+ var _DrilldownGroup = require("./DrilldownGroup");
28
+ var _DrilldownPage = require("./DrilldownPage");
29
+ var _styles = _interopRequireDefault(require("./styles"));
30
+ var _props = require("./props");
31
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
32
+ var _react2 = require("@emotion/react");
33
+ const _excluded = ["groupProps"],
34
+ _excluded2 = ["groupProps"],
35
+ _excluded3 = ["id", "themeOverride"];
36
+ var _dec, _dec2, _class, _Drilldown, _ChevronRightInstUIIc, _ChevronLeftInstUIIco, _CheckInstUIIcon, _Options$Separator, _Options$Separator2;
37
+ /*
38
+ * The MIT License (MIT)
39
+ *
40
+ * Copyright (c) 2015 - present Instructure, Inc.
41
+ *
42
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
43
+ * of this software and associated documentation files (the "Software"), to deal
44
+ * in the Software without restriction, including without limitation the rights
45
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
46
+ * copies of the Software, and to permit persons to whom the Software is
47
+ * furnished to do so, subject to the following conditions:
48
+ *
49
+ * The above copyright notice and this permission notice shall be included in all
50
+ * copies or substantial portions of the Software.
51
+ *
52
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
53
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
54
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
55
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
56
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
57
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
58
+ * SOFTWARE.
59
+ */
60
+ // Additional data we need to track on the Options,
61
+ // but shouldn't be settable via props
62
+ // Contains the Option ComponentElement and the extra data we need track on it,
63
+ // but don't want to expose as props
64
+ // Contains the props object of the Page
65
+ // with the `children` transformed into an array
66
+ // An object with the mapped Pages with their id as keys
67
+ /**
68
+ ---
69
+ category: components
70
+ ---
71
+ **/
72
+ let Drilldown = exports.Drilldown = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default), _dec(_class = _dec2(_class = (_Drilldown = class Drilldown extends _react.Component {
73
+ constructor(props) {
74
+ super(props);
75
+ this._drilldownRef = null;
76
+ this._popover = null;
77
+ this._trigger = null;
78
+ this._containerElement = null;
79
+ this._id = void 0;
80
+ this._triggerId = void 0;
81
+ this._headerBackId = void 0;
82
+ this._headerTitleId = void 0;
83
+ this._headerTitleLabelId = void 0;
84
+ this._headerActionId = void 0;
85
+ // Array of visited page ids in "breadcrumbs" fashion
86
+ this._pageHistory = void 0;
87
+ // Map of the active options on the page (includes header options too)
88
+ this._activeOptionsMap = {};
89
+ this.ref = null;
90
+ this.handleRef = el => {
91
+ // ref and elementRef have to be set together for the same element
92
+ const elementRef = this.props.elementRef;
93
+ this.ref = el;
94
+ if (typeof elementRef === 'function') {
95
+ elementRef(el);
96
+ }
97
+ };
98
+ this.handleDrilldownRef = el => {
99
+ const drilldownRef = this.props.drilldownRef;
100
+ this._drilldownRef = el;
101
+ if (typeof drilldownRef === 'function') {
102
+ drilldownRef(el);
103
+ }
104
+
105
+ // setting ref for "non-popover" version, the drilldown itself
106
+ // (if a trigger is provided, the Popover sets the ref)
107
+ if (!this.props.trigger) {
108
+ this.handleRef(el);
109
+ }
110
+ };
111
+ this.show = event => {
112
+ if (this._popover) {
113
+ this._popover.show(event);
114
+ this.setState({
115
+ isShowingPopover: true
116
+ });
117
+ }
118
+ };
119
+ this.hide = event => {
120
+ if (this._popover) {
121
+ this._popover.hide(event);
122
+ this.setState({
123
+ isShowingPopover: false
124
+ });
125
+ this.reset();
126
+ }
127
+ };
128
+ this.handleOptionHighlight = (_event, {
129
+ id,
130
+ direction
131
+ }) => {
132
+ const rotateFocus = this.props.rotateFocus;
133
+ const highlightedOptionId = this.state.highlightedOptionId;
134
+
135
+ // if id exists, use that, or calculate from direction
136
+ let highlightId = this.getPageChildById(id) ? id : void 0;
137
+ if (!highlightId) {
138
+ if (!highlightedOptionId) {
139
+ // nothing highlighted yet, highlight first option
140
+ highlightId = this.activeOptionIds[0];
141
+ } else if (direction) {
142
+ // if it has direction, find next id based on it
143
+ const index = this.activeOptionIds.indexOf(highlightedOptionId);
144
+ const newIndex = index + direction;
145
+ highlightId = index > -1 ? this.activeOptionIds[newIndex] : void 0;
146
+ if (rotateFocus) {
147
+ const lastOptionsIndex = this.activeOptionIds.length - 1;
148
+ if (newIndex < 0) {
149
+ highlightId = this.activeOptionIds[lastOptionsIndex];
150
+ }
151
+ if (newIndex > lastOptionsIndex) {
152
+ highlightId = this.activeOptionIds[0];
153
+ }
154
+ }
155
+ }
156
+ }
157
+ if (highlightId) {
158
+ // only highlight if id exists as a valid option
159
+ this.setState({
160
+ highlightedOptionId: highlightId
161
+ }, () => {
162
+ this.focusOption(highlightId);
163
+ });
164
+ }
165
+ };
166
+ // Navigates to the page and also returns the new and old pageIds
167
+ this.goToPage = newPageId => {
168
+ var _this$pageMap;
169
+ if (!newPageId) {
170
+ (0, _console.warn)(false, `Cannot go to page because there was no page id provided.`);
171
+ return void 0;
172
+ }
173
+
174
+ // TS complains that it cannot be true, but since it is an exposed method,
175
+ // it is better if we provide a warning for this case too
176
+ if (typeof newPageId !== 'string') {
177
+ (0, _console.warn)(false, `Cannot go to page because parameter newPageId has to be string (valid page id). Current newPageId is "${typeof newPageId}".`);
178
+ return void 0;
179
+ }
180
+ if (!((_this$pageMap = this.pageMap) !== null && _this$pageMap !== void 0 && _this$pageMap[newPageId])) {
181
+ (0, _console.warn)(false, `Cannot go to page because page with id: "${newPageId}" doesn't exist.`);
182
+ return void 0;
183
+ }
184
+
185
+ // the last page id in the history is the current one,
186
+ // it will become the "prevPage"
187
+ const prevPageId = this._pageHistory[this._pageHistory.length - 1];
188
+ const idxInHistory = this._pageHistory.indexOf(newPageId);
189
+ if (idxInHistory < 0) {
190
+ // if it is not in the page history, we have to add it
191
+ this._pageHistory.push(newPageId);
192
+ } else {
193
+ // if it was already in the history, we go back to that page,
194
+ // and clear the rest from the history
195
+ this._pageHistory.splice(idxInHistory + 1, this._pageHistory.length - 1);
196
+ }
197
+ this.setState({
198
+ activePageId: newPageId,
199
+ highlightedOptionId: void 0
200
+ });
201
+ return {
202
+ prevPageId,
203
+ newPageId
204
+ };
205
+ };
206
+ this.goToPreviousPage = () => {
207
+ if (!this.previousPage) {
208
+ (0, _console.warn)(false, `There is no previous page to go to. The current page history is: [${this._pageHistory.join(', ')}].`);
209
+ return void 0;
210
+ }
211
+
212
+ // If there is a previous page, goToPage will succeed and return the data
213
+ const _ref = this.goToPage(this.previousPage.id),
214
+ newPageId = _ref.newPageId,
215
+ prevPageId = _ref.prevPageId;
216
+ return {
217
+ newPageId,
218
+ prevPageId
219
+ };
220
+ };
221
+ this.handleBackButtonClick = () => {
222
+ const _ref2 = this.currentPage,
223
+ onBackButtonClicked = _ref2.onBackButtonClicked;
224
+
225
+ // we only display the back button when there is a page to go back to
226
+ const _ref3 = this.goToPreviousPage(),
227
+ newPageId = _ref3.newPageId,
228
+ prevPageId = _ref3.prevPageId;
229
+ if (typeof onBackButtonClicked === 'function') {
230
+ onBackButtonClicked(newPageId, prevPageId);
231
+ }
232
+ };
233
+ this.handleOptionSelect = (event, {
234
+ id
235
+ }) => {
236
+ var _this$currentPage, _selectedOption$group;
237
+ const selectedOption = this.getPageChildById(id);
238
+ if (!id || !selectedOption) {
239
+ event.preventDefault();
240
+ event.stopPropagation();
241
+ return;
242
+ }
243
+ const isOptionDisabled = id !== this._headerBackId && (this.props.disabled || ((_this$currentPage = this.currentPage) === null || _this$currentPage === void 0 ? void 0 : _this$currentPage.disabled) || ((_selectedOption$group = selectedOption.groupProps) === null || _selectedOption$group === void 0 ? void 0 : _selectedOption$group.disabled) || selectedOption.props.disabled);
244
+ if (isOptionDisabled) {
245
+ event.preventDefault();
246
+ event.stopPropagation();
247
+ return;
248
+ }
249
+ const _this$props = this.props,
250
+ shouldHideOnSelect = _this$props.shouldHideOnSelect,
251
+ onSelect = _this$props.onSelect;
252
+ const groupProps = selectedOption.groupProps,
253
+ selectedOptionChild = (0, _objectWithoutProperties2.default)(selectedOption, _excluded);
254
+ const _selectedOptionChild$ = selectedOptionChild.props,
255
+ subPageId = _selectedOptionChild$.subPageId,
256
+ href = _selectedOptionChild$.href,
257
+ value = _selectedOptionChild$.value,
258
+ onOptionClick = _selectedOptionChild$.onOptionClick;
259
+ if (typeof onOptionClick === 'function') {
260
+ onOptionClick(event, {
261
+ optionId: id,
262
+ drilldown: this,
263
+ ...this.exposedNavigationProps
264
+ });
265
+ }
266
+ if (subPageId) {
267
+ this.goToPage(subPageId);
268
+ }
269
+ if (event.type === 'keydown' && href) {
270
+ var _this$_drilldownRef;
271
+ const optionEl = (_this$_drilldownRef = this._drilldownRef) === null || _this$_drilldownRef === void 0 ? void 0 : _this$_drilldownRef.querySelector(`#${CSS.escape(id)}`);
272
+ const isLink = optionEl.tagName.toLowerCase() === 'a';
273
+
274
+ // we need this check because in some cases
275
+ // we ignore href prop in renderOption()
276
+ if (isLink && optionEl !== null && optionEl !== void 0 && optionEl.href) {
277
+ optionEl.click();
278
+ }
279
+ }
280
+ if (groupProps !== null && groupProps !== void 0 && groupProps.selectableType) {
281
+ this.handleGroupOptionSelected(event, selectedOption);
282
+ } else {
283
+ // TODO workaround for react 19 default props
284
+ const optionWithDefaultProps = {
285
+ ...selectedOptionChild,
286
+ props: {
287
+ ...selectedOptionChild.props,
288
+ role: 'menuitem'
289
+ }
290
+ };
291
+ if (typeof onSelect === 'function') {
292
+ onSelect(event, {
293
+ value,
294
+ isSelected: true,
295
+ selectedOption: optionWithDefaultProps,
296
+ drilldown: this
297
+ });
298
+ }
299
+ }
300
+
301
+ // should prevent closing on page navigation
302
+ if (shouldHideOnSelect && !subPageId && id !== this._headerBackId) {
303
+ this.hide(event);
304
+ }
305
+ };
306
+ // Setting extra logic for keyboard navigation.
307
+ // Enter, Esc and up/down/home/end keys are handled by Selectable.
308
+ this.handleKeyDown = event => {
309
+ const id = event.target.id;
310
+ const option = this.getPageChildById(id);
311
+
312
+ // On Space...
313
+ if ([' ', 'space', 'Space'].includes(event.key)) {
314
+ // we need to preventDefault so the page doesn't scroll on Space
315
+ event.preventDefault();
316
+ event.stopPropagation();
317
+
318
+ // for options, Space it has to work as Enter (get selected)
319
+ if (option) {
320
+ this.handleOptionSelect(event, {
321
+ id
322
+ });
323
+ }
324
+ }
325
+
326
+ // On Right arrow...
327
+ if (event.key === 'ArrowRight') {
328
+ // if the option has subpage, we open it
329
+ if (option !== null && option !== void 0 && option.props.subPageId) {
330
+ this.handleOptionSelect(event, {
331
+ id
332
+ });
333
+ }
334
+ }
335
+
336
+ // On Left arrow...
337
+ if (event.key === 'ArrowLeft') {
338
+ var _this$_popover;
339
+ // if it is possible, we go a level up in the history
340
+ if (this._pageHistory.length > 1) {
341
+ this.handleBackButtonClick();
342
+ }
343
+
344
+ // if on root page and popover is open, we close it
345
+ if (this.isOnRootPage && (_this$_popover = this._popover) !== null && _this$_popover !== void 0 && _this$_popover.shown) {
346
+ this._popover.hide(event);
347
+ }
348
+ }
349
+ };
350
+ this.handleToggle = (event, shown) => {
351
+ const _this$props2 = this.props,
352
+ onToggle = _this$props2.onToggle,
353
+ trigger = _this$props2.trigger;
354
+ if (trigger && shown && this.currentPage) {
355
+ var _this$getFirstOption;
356
+ const actionLabel = (0, _callRenderProp.callRenderProp)(this.currentPage.renderActionLabel);
357
+ // Use action ID if exists, otherwise first non-action option's ID
358
+ const targetId = actionLabel ? this._headerActionId : (_this$getFirstOption = this.getFirstOption()) === null || _this$getFirstOption === void 0 ? void 0 : _this$getFirstOption.props.id;
359
+ setTimeout(() => {
360
+ this.setState({
361
+ highlightedOptionId: targetId
362
+ });
363
+ }, 10);
364
+ }
365
+ this.setState({
366
+ isShowingPopover: shown
367
+ });
368
+ if (typeof onToggle === 'function') {
369
+ onToggle(event, {
370
+ shown,
371
+ drilldown: this,
372
+ ...this.exposedNavigationProps
373
+ });
374
+ }
375
+ };
376
+ this.getFirstOption = () => {
377
+ var _this$currentPage2;
378
+ const children = _react.Children.toArray((_this$currentPage2 = this.currentPage) === null || _this$currentPage2 === void 0 ? void 0 : _this$currentPage2.children);
379
+ const child = children[0];
380
+ if (!child) return void 0;
381
+
382
+ // If it's a regular option, return it
383
+ if ((0, _matchComponentTypes.matchComponentTypes)(child, [_DrilldownOption.DrilldownOption])) {
384
+ return child;
385
+ }
386
+ // If it's a group, get its options
387
+ if ((0, _matchComponentTypes.matchComponentTypes)(child, [Drilldown.Group])) {
388
+ const groupOptions = _react.Children.toArray(child.props.children);
389
+ return groupOptions[0];
390
+ }
391
+ return void 0;
392
+ };
393
+ this.state = {
394
+ isShowingPopover: props.trigger ? !!props.show : false,
395
+ activePageId: props.rootPageId,
396
+ highlightedOptionId: void 0,
397
+ lastSelectedId: void 0,
398
+ selectedGroupOptionsMap: this.getSelectedGroupOptionsMap()
399
+ };
400
+ this._pageHistory = [props.rootPageId];
401
+ this._id = props.id || props.deterministicId();
402
+ this._triggerId = props.deterministicId('Drilldown-Trigger');
403
+ this._headerBackId = props.deterministicId('DrilldownHeader-Back');
404
+ this._headerTitleId = props.deterministicId('DrilldownHeader-Title');
405
+ this._headerTitleLabelId = props.deterministicId('DrilldownHeader-Title-Label');
406
+ this._headerActionId = props.deterministicId('DrilldownHeader-Action');
407
+ }
408
+ componentDidMount() {
409
+ var _this$props$makeStyle, _this$props3;
410
+ (_this$props$makeStyle = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props3, this.makeStylesVariables);
411
+ }
412
+ componentDidUpdate(_prevProps, prevState) {
413
+ var _this$props$makeStyle2, _this$props4;
414
+ (_this$props$makeStyle2 = (_this$props4 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props4, this.makeStylesVariables);
415
+ if (prevState.activePageId !== this.state.activePageId) {
416
+ // on page change with mouse navigation, some option can get rendered
417
+ // under the cursor and get focused, so we need to wait a tick to see
418
+ // if anything gets focused, otherwise we focus the whole drilldown
419
+ setTimeout(() => {
420
+ if (!this.focused()) {
421
+ this.focus();
422
+ }
423
+ }, 0);
424
+ }
425
+
426
+ // if the current page was removed
427
+ if (!this.currentPage) {
428
+ if (this.previousPage) {
429
+ this.goToPreviousPage();
430
+ } else {
431
+ this.goToPage(this.props.rootPageId);
432
+ }
433
+ }
434
+ if (this.state.highlightedOptionId && !this.getPageChildById(this.state.highlightedOptionId)) {
435
+ this.setState({
436
+ highlightedOptionId: void 0
437
+ });
438
+ }
439
+
440
+ // This block syncs the internal state if the selectedOptions prop changes
441
+ // selectedOptions prop values always win over internal state.
442
+ let shouldUpdateState = false;
443
+ const nextSelectionMap = {
444
+ ...this.state.selectedGroupOptionsMap
445
+ };
446
+ this.pages.forEach(page => {
447
+ this.getChildrenArray(page.props.children).forEach(child => {
448
+ if ((0, _matchComponentTypes.matchComponentTypes)(child, [_DrilldownGroup.DrilldownGroup])) {
449
+ var _this$getChildrenArra;
450
+ const _child$props = child.props,
451
+ groupId = _child$props.id,
452
+ selectableType = _child$props.selectableType,
453
+ selectedOptions = _child$props.selectedOptions,
454
+ groupChildren = _child$props.children;
455
+ if (!selectableType || !Array.isArray(selectedOptions)) return;
456
+ const newGroupMap = new Map();
457
+ (_this$getChildrenArra = this.getChildrenArray(groupChildren)) === null || _this$getChildrenArra === void 0 ? void 0 : _this$getChildrenArra.forEach(groupChild => {
458
+ if ((0, _matchComponentTypes.matchComponentTypes)(groupChild, [_DrilldownOption.DrilldownOption])) {
459
+ const _groupChild$props = groupChild.props,
460
+ optionId = _groupChild$props.id,
461
+ optionValue = _groupChild$props.value;
462
+ if (selectedOptions.includes(optionValue)) {
463
+ newGroupMap.set(optionId, optionValue);
464
+ }
465
+ }
466
+ });
467
+ const currentGroupMapInState = this.state.selectedGroupOptionsMap[groupId] || new Map();
468
+ if (!(0, _deepEqual.deepEqual)(this.getNormalizedMap(newGroupMap), this.getNormalizedMap(currentGroupMapInState))) {
469
+ nextSelectionMap[groupId] = newGroupMap;
470
+ shouldUpdateState = true;
471
+ }
472
+ }
473
+ });
474
+ });
475
+ if (shouldUpdateState) {
476
+ this.setState({
477
+ selectedGroupOptionsMap: nextSelectionMap
478
+ });
479
+ }
480
+ }
481
+ get makeStylesVariables() {
482
+ return {
483
+ hasHighlightedOption: !!this.state.highlightedOptionId
484
+ };
485
+ }
486
+ get activeOptionIds() {
487
+ const orderedKeys = Object.keys(this._activeOptionsMap).sort((a, b) => {
488
+ return this._activeOptionsMap[a].index - this._activeOptionsMap[b].index;
489
+ });
490
+ return orderedKeys;
491
+ }
492
+ get activeOptions() {
493
+ return Object.values(this._activeOptionsMap);
494
+ }
495
+ get pages() {
496
+ const children = this.props.children;
497
+ return _react.Children.toArray(children || []);
498
+ }
499
+ get pageMap() {
500
+ const children = this.props.children;
501
+ if (!children) {
502
+ return void 0;
503
+ }
504
+ const map = {};
505
+ this.pages.forEach(page => {
506
+ const props = page.props;
507
+ const children = props.children;
508
+ map[props.id] = {
509
+ ...props,
510
+ children: _react.Children.toArray(children || [])
511
+ };
512
+ });
513
+ return map;
514
+ }
515
+ get isOnRootPage() {
516
+ return this.state.activePageId === this.props.rootPageId;
517
+ }
518
+ get currentPage() {
519
+ return this.getPageById(this.state.activePageId);
520
+ }
521
+ get previousPage() {
522
+ const previousPageId = this._pageHistory[this._pageHistory.length - 2];
523
+ return this.getPageById(previousPageId);
524
+ }
525
+
526
+ // Returns the navigation methods and the page history.
527
+ // These are used in some callbacks to expose the navigation logic.
528
+ get exposedNavigationProps() {
529
+ const goToPage = this.goToPage,
530
+ goToPreviousPage = this.goToPreviousPage;
531
+
532
+ // we make a copy of the array so the original history
533
+ // cannot be modified from the outside
534
+ const pageHistory = [...this._pageHistory];
535
+ return {
536
+ pageHistory,
537
+ goToPage,
538
+ goToPreviousPage
539
+ };
540
+ }
541
+ get currentPageAriaLabel() {
542
+ var _this$currentPage3;
543
+ // return, if explicitly set
544
+ if (this.props['aria-labelledby']) {
545
+ return this.props['aria-labelledby'];
546
+ }
547
+
548
+ // if it has title, point to the title label content
549
+ if ((_this$currentPage3 = this.currentPage) !== null && _this$currentPage3 !== void 0 && _this$currentPage3.renderTitle) {
550
+ return this._headerTitleLabelId;
551
+ }
552
+
553
+ // if root page has no title, try the trigger, if exists
554
+ if (this.isOnRootPage && this.props.trigger) {
555
+ return this._triggerId;
556
+ }
557
+ return void 0;
558
+ }
559
+ getChildrenArray(children) {
560
+ if (!children) {
561
+ return [];
562
+ }
563
+ return Array.isArray(children) ? children : [children];
564
+ }
565
+ getPageById(id) {
566
+ return this.pageMap && id ? this.pageMap[id] : void 0;
567
+ }
568
+ getPageChildById(id) {
569
+ return id ? this._activeOptionsMap[id] : void 0;
570
+ }
571
+ getNormalizedMap(map) {
572
+ return Array.from(map.entries());
573
+ }
574
+
575
+ /**
576
+ * Initializes the map of selected options for each group on initial render.
577
+ *
578
+ * This function establishes the selection state based on a clear precedence:
579
+ * 1. **Controlled Mode**: If a `Drilldown.Group` has the `selectedOptions` prop
580
+ * (as an array), it is treated as the absolute source of truth.
581
+ *
582
+ * 2. **Uncontrolled Mode**: If `selectedOptions` is not provided, the selection
583
+ * is determined by `defaultSelected` props, with the following priority:
584
+ * a. The `defaultSelected` boolean on an individual `Drilldown.Option`.
585
+ * b. The `defaultSelected` array of values on the `Drilldown.Group`.
586
+ *
587
+ * It also validates that 'single' selection groups do not mistakenly receive
588
+ * multiple selected or default values.
589
+ *
590
+ * @returns {SelectedGroupOptionsMap} An object where keys are group IDs and
591
+ * values are Maps of the selected { optionId: optionValue } pairs for that group.
592
+ */
593
+ getSelectedGroupOptionsMap() {
594
+ const selectedGroupOptionsMap = {};
595
+ this.pages.forEach(page => {
596
+ const children = page.props.children;
597
+ this.getChildrenArray(children).forEach(child => {
598
+ if ((0, _matchComponentTypes.matchComponentTypes)(child, [_DrilldownGroup.DrilldownGroup])) {
599
+ var _this$getChildrenArra2;
600
+ const _child$props2 = child.props,
601
+ groupId = _child$props2.id,
602
+ selectableType = _child$props2.selectableType,
603
+ selectedOptions = _child$props2.selectedOptions,
604
+ _child$props2$default = _child$props2.defaultSelected,
605
+ defaultSelected = _child$props2$default === void 0 ? [] : _child$props2$default,
606
+ groupChildren = _child$props2.children;
607
+ if (!selectableType) return;
608
+ selectedGroupOptionsMap[groupId] = new Map();
609
+ if (selectableType === 'single') {
610
+ if (Array.isArray(selectedOptions) && selectedOptions.length > 1) {
611
+ (0, _console.error)(false, `Radio type selectable groups can have only one item selected! Group "${groupId}" has multiple values: [${selectedOptions.join(', ')}]!`);
612
+ return;
613
+ }
614
+ if (defaultSelected.length > 1) {
615
+ (0, _console.error)(false, `Radio type selectable groups can have only one default item selected! Group "${groupId}" has multiple values: [${defaultSelected.join(', ')}]!`);
616
+ return;
617
+ }
618
+ }
619
+ (_this$getChildrenArra2 = this.getChildrenArray(groupChildren)) === null || _this$getChildrenArra2 === void 0 ? void 0 : _this$getChildrenArra2.forEach(groupChild => {
620
+ if ((0, _matchComponentTypes.matchComponentTypes)(groupChild, [_DrilldownOption.DrilldownOption])) {
621
+ const _groupChild$props2 = groupChild.props,
622
+ optionId = _groupChild$props2.id,
623
+ optionValue = _groupChild$props2.value,
624
+ optionDefaultSelected = _groupChild$props2.defaultSelected;
625
+ if (optionValue == null) return;
626
+ let isSelected = false;
627
+ // If the group is controlled via the `selectedOptions` prop, it is the source of truth.
628
+ // `defaultSelected` values are ignored.
629
+ if (Array.isArray(selectedOptions)) {
630
+ isSelected = selectedOptions.includes(optionValue);
631
+ // Second strongest is the `defaultSelected` value on the option itself.
632
+ } else if (optionDefaultSelected === false) {
633
+ isSelected = false;
634
+ } else {
635
+ // Last is the `defaultSelected` array on the group.
636
+ const isGroupDefaultSelected = defaultSelected.includes(optionValue);
637
+ isSelected = optionDefaultSelected || isGroupDefaultSelected;
638
+ }
639
+ if (isSelected) {
640
+ selectedGroupOptionsMap[groupId].set(optionId, optionValue);
641
+ }
642
+ }
643
+ });
644
+ }
645
+ });
646
+ });
647
+ return selectedGroupOptionsMap;
648
+ }
649
+ get selectedGroupOptionIdsArray() {
650
+ return Object.values(this.state.selectedGroupOptionsMap).map(groupIdMap => Array.from(groupIdMap.keys())).flat();
651
+ }
652
+ get headerChildren() {
653
+ const currentPage = this.currentPage;
654
+ const _this$props5 = this.props,
655
+ styles = _this$props5.styles,
656
+ deterministicId = _this$props5.deterministicId;
657
+ const headerChildren = [];
658
+ if (!currentPage) {
659
+ return headerChildren;
660
+ }
661
+ const children = currentPage.children,
662
+ renderBackButtonLabel = currentPage.renderBackButtonLabel,
663
+ renderTitle = currentPage.renderTitle,
664
+ renderActionLabel = currentPage.renderActionLabel,
665
+ onHeaderActionClicked = currentPage.onHeaderActionClicked,
666
+ withoutHeaderSeparator = currentPage.withoutHeaderSeparator;
667
+
668
+ // Back navigation option
669
+ if (this.previousPage) {
670
+ const prevPageTitle = (0, _callRenderProp.callRenderProp)(this.previousPage.renderTitle);
671
+ const backButtonLabel = (0, _callRenderProp.callRenderProp)(renderBackButtonLabel, prevPageTitle);
672
+ headerChildren.push((0, _jsxRuntime.jsx)(_DrilldownOption.DrilldownOption, {
673
+ id: this._headerBackId,
674
+ onOptionClick: this.handleBackButtonClick,
675
+ children: (0, _jsxRuntime.jsx)("div", {
676
+ css: styles === null || styles === void 0 ? void 0 : styles.headerBack,
677
+ role: "presentation",
678
+ children: backButtonLabel
679
+ })
680
+ }));
681
+ }
682
+
683
+ // Header title
684
+ if (renderTitle) {
685
+ const title = (0, _callRenderProp.callRenderProp)(renderTitle);
686
+ if (title) {
687
+ headerChildren.push((0, _jsxRuntime.jsx)(_DrilldownOption.DrilldownOption, {
688
+ id: this._headerTitleId,
689
+ role: "presentation",
690
+ "aria-hidden": "true",
691
+ children: (0, _jsxRuntime.jsx)("div", {
692
+ css: styles === null || styles === void 0 ? void 0 : styles.headerTitle,
693
+ id: this._headerTitleLabelId,
694
+ children: title
695
+ })
696
+ }));
697
+ }
698
+ }
699
+
700
+ // Action label
701
+ if (renderActionLabel) {
702
+ const actionLabel = (0, _callRenderProp.callRenderProp)(renderActionLabel);
703
+ if (actionLabel) {
704
+ headerChildren.push((0, _jsxRuntime.jsx)(_DrilldownOption.DrilldownOption, {
705
+ id: this._headerActionId,
706
+ themeOverride: {
707
+ color: styles === null || styles === void 0 ? void 0 : styles.headerActionColor
708
+ },
709
+ onOptionClick: event => {
710
+ if (typeof onHeaderActionClicked === 'function') {
711
+ onHeaderActionClicked(event);
712
+ }
713
+ },
714
+ children: actionLabel
715
+ }));
716
+ }
717
+ }
718
+
719
+ // header separator
720
+ if (headerChildren.length > 0 && children.length > 0 && !withoutHeaderSeparator) {
721
+ headerChildren.push((0, _jsxRuntime.jsx)(_DrilldownSeparator.DrilldownSeparator, {
722
+ id: deterministicId('DrilldownHeader-Separator')
723
+ }));
724
+ }
725
+ return headerChildren;
726
+ }
727
+ get shown() {
728
+ return this.props.trigger ? this.state.isShowingPopover : true;
729
+ }
730
+ containsDuplicateChild(children) {
731
+ let containsDuplicate = false;
732
+ const childMap = new Map();
733
+ for (const child of children) {
734
+ var _child$props3;
735
+ if (child && typeof child === 'object' && (_child$props3 = child.props) !== null && _child$props3 !== void 0 && _child$props3.id) {
736
+ if (!childMap.has(child.props.id)) {
737
+ childMap.set(child.props.id, true);
738
+ } else {
739
+ (0, _console.warn)(false, `Duplicate id: "${child.props.id}"! Make sure all options have unique ids, otherwise they won't be rendered.`);
740
+ return containsDuplicate = true;
741
+ }
742
+ }
743
+ }
744
+ return containsDuplicate;
745
+ }
746
+ reset() {
747
+ this._activeOptionsMap = {};
748
+ this.setState({
749
+ highlightedOptionId: void 0
750
+ });
751
+ }
752
+ focus() {
753
+ if (this.shown) {
754
+ var _this$_drilldownRef2, _this$_drilldownRef3;
755
+ (0, _console.error)(!!((_this$_drilldownRef2 = this._drilldownRef) !== null && _this$_drilldownRef2 !== void 0 && _this$_drilldownRef2.focus), '[Drilldown] Could not focus the drilldown.');
756
+ (_this$_drilldownRef3 = this._drilldownRef) === null || _this$_drilldownRef3 === void 0 ? void 0 : _this$_drilldownRef3.focus();
757
+ } else {
758
+ var _this$_trigger;
759
+ (0, _console.error)(!!((_this$_trigger = this._trigger) !== null && _this$_trigger !== void 0 && _this$_trigger.focus), '[Drilldown] Could not focus the trigger.');
760
+ this._trigger.focus();
761
+ }
762
+ }
763
+ focused() {
764
+ if (this.shown) {
765
+ return (0, _containsActiveElement.containsActiveElement)(this._drilldownRef);
766
+ } else {
767
+ return (0, _containsActiveElement.containsActiveElement)(this._trigger);
768
+ }
769
+ }
770
+ focusOption(id) {
771
+ const container = this._containerElement;
772
+ const optionElement = container === null || container === void 0 ? void 0 : container.querySelector(`[id="${CSS.escape(id)}"]`);
773
+ optionElement === null || optionElement === void 0 ? void 0 : optionElement.focus();
774
+ }
775
+ handleGroupOptionSelected(event, selectedOption) {
776
+ this.setState(oldState => {
777
+ var _oldState$selectedGro;
778
+ const _selectedOption$props = selectedOption.props,
779
+ optionId = _selectedOption$props.id,
780
+ value = _selectedOption$props.value;
781
+ const _ref4 = selectedOption.groupProps,
782
+ groupId = _ref4.id,
783
+ selectableType = _ref4.selectableType;
784
+ let newState = new Map(oldState.selectedGroupOptionsMap[groupId]);
785
+ if (selectableType === 'multiple' && Boolean((_oldState$selectedGro = oldState.selectedGroupOptionsMap[groupId]) === null || _oldState$selectedGro === void 0 ? void 0 : _oldState$selectedGro.has(optionId))) {
786
+ // toggle off, if already selected
787
+ newState.delete(optionId);
788
+ } else {
789
+ if (selectableType === 'multiple') {
790
+ // "checkbox"
791
+ newState.set(optionId, value);
792
+ } else if (selectableType === 'single') {
793
+ // "radio"
794
+ newState = new Map();
795
+ newState.set(optionId, value);
796
+ }
797
+ }
798
+ return {
799
+ ...oldState,
800
+ selectedGroupOptionsMap: {
801
+ ...oldState.selectedGroupOptionsMap,
802
+ [groupId]: newState
803
+ }
804
+ };
805
+ }, () => {
806
+ const value = selectedOption.props.value;
807
+ const _ref5 = selectedOption.groupProps,
808
+ groupId = _ref5.id,
809
+ groupOnSelect = _ref5.onSelect;
810
+ const onSelect = this.props.onSelect;
811
+ const groupProps = selectedOption.groupProps,
812
+ option = (0, _objectWithoutProperties2.default)(selectedOption, _excluded2);
813
+ const selectedOptionValuesInGroup = [...this.state.selectedGroupOptionsMap[groupId].values()];
814
+ if (typeof groupOnSelect === 'function') {
815
+ groupOnSelect(event, {
816
+ value: selectedOptionValuesInGroup,
817
+ isSelected: selectedOptionValuesInGroup.includes(value),
818
+ selectedOption: option,
819
+ drilldown: this
820
+ });
821
+ }
822
+ if (typeof onSelect === 'function') {
823
+ onSelect(event, {
824
+ value: selectedOptionValuesInGroup,
825
+ isSelected: selectedOptionValuesInGroup.includes(value),
826
+ selectedOption: option,
827
+ drilldown: this
828
+ });
829
+ }
830
+ });
831
+ }
832
+ renderList(getOptionProps, getDisabledOptionProps) {
833
+ const currentPage = this.currentPage,
834
+ headerChildren = this.headerChildren;
835
+ if (!currentPage || this.containsDuplicateChild(currentPage.children)) {
836
+ return null;
837
+ }
838
+ const pageChildren = [...headerChildren, ...currentPage.children];
839
+
840
+ // for tracking if the last item was a Separator or not
841
+ let lastItemWasSeparator = false;
842
+ return pageChildren.map((child, index) => {
843
+ /**
844
+ * --- RENDER GROUP ---
845
+ */
846
+ if ((0, _matchComponentTypes.matchComponentTypes)(child, [_DrilldownGroup.DrilldownGroup])) {
847
+ const isFirstChild = index === 0;
848
+ const isLastChild = index === pageChildren.length - 1;
849
+ const afterSeparator = lastItemWasSeparator;
850
+ const needsFirstSeparator = !child.props.withoutSeparators && !isFirstChild && !afterSeparator;
851
+ const needsLastSeparator = !child.props.withoutSeparators && !isLastChild;
852
+ lastItemWasSeparator = needsLastSeparator;
853
+ return this.renderGroup(child, getOptionProps, getDisabledOptionProps,
854
+ // for rendering separators appropriately
855
+ needsFirstSeparator, needsLastSeparator);
856
+
857
+ /**
858
+ * --- RENDER SEPARATOR ---
859
+ */
860
+ } else if ((0, _matchComponentTypes.matchComponentTypes)(child, [_DrilldownSeparator.DrilldownSeparator])) {
861
+ // if the last item was separator, we don't want to duplicate it
862
+ if (lastItemWasSeparator) {
863
+ return null;
864
+ }
865
+ lastItemWasSeparator = true;
866
+ return this.renderSeparator(child);
867
+
868
+ /**
869
+ * --- RENDER OPTION ---
870
+ */
871
+ } else if ((0, _matchComponentTypes.matchComponentTypes)(child, [_DrilldownOption.DrilldownOption])) {
872
+ lastItemWasSeparator = false;
873
+ return this.renderOption(child, getOptionProps, getDisabledOptionProps);
874
+ } else {
875
+ return null;
876
+ }
877
+ });
878
+ }
879
+ renderSeparator(separator) {
880
+ const _separator$props = separator.props,
881
+ id = _separator$props.id,
882
+ themeOverride = _separator$props.themeOverride,
883
+ props = (0, _objectWithoutProperties2.default)(_separator$props, _excluded3);
884
+ return (0, _react2.createElement)(_latest2.Options.Separator, {
885
+ ...props,
886
+ id: id,
887
+ key: id,
888
+ role: "separator"
889
+ // we pass the themeOverride to Options.Separator
890
+ ,
891
+ themeOverride: themeOverride
892
+ });
893
+ }
894
+ renderOption(option, getOptionProps, getDisabledOptionProps, groupProps) {
895
+ var _this$currentPage4, _optionProps$renderBe, _optionProps$renderBe2, _optionProps$renderAf, _optionProps$renderAf2;
896
+ const styles = this.props.styles;
897
+ let isSelected = false;
898
+ const _option$props = option.props,
899
+ id = _option$props.id,
900
+ children = _option$props.children,
901
+ href = _option$props.href,
902
+ _option$props$as = _option$props.as,
903
+ as = _option$props$as === void 0 ? 'li' : _option$props$as,
904
+ _option$props$role = _option$props.role,
905
+ role = _option$props$role === void 0 ? 'menuitem' : _option$props$role,
906
+ subPageId = _option$props.subPageId,
907
+ _option$props$disable = _option$props.disabled,
908
+ disabled = _option$props$disable === void 0 ? false : _option$props$disable,
909
+ renderLabelInfo = _option$props.renderLabelInfo,
910
+ renderBeforeLabel = _option$props.renderBeforeLabel,
911
+ renderAfterLabel = _option$props.renderAfterLabel,
912
+ _option$props$beforeL = _option$props.beforeLabelContentVAlign,
913
+ beforeLabelContentVAlign = _option$props$beforeL === void 0 ? 'start' : _option$props$beforeL,
914
+ _option$props$afterLa = _option$props.afterLabelContentVAlign,
915
+ afterLabelContentVAlign = _option$props$afterLa === void 0 ? 'start' : _option$props$afterLa,
916
+ description = _option$props.description,
917
+ descriptionRole = _option$props.descriptionRole,
918
+ elementRef = _option$props.elementRef,
919
+ themeOverride = _option$props.themeOverride;
920
+ if (!id) {
921
+ (0, _console.warn)(false, `Drilldown.Option without id won't be rendered. It is needed to internally track the options.`);
922
+ return null;
923
+ }
924
+
925
+ // Props passed to the Option.Item
926
+ let optionProps = {
927
+ // passthrough props
928
+ ...(0, _omitProps.omitProps)(option.props, [..._DrilldownOption.DrilldownOption.allowedProps, ..._latest2.Options.Item.allowedProps]),
929
+ // props from selectable
930
+ ...getOptionProps({
931
+ id,
932
+ // aria-selected is only valid for these roles, otherwise we need to unset it
933
+ ...(role && !['gridcell', 'option', 'row', 'tab', 'columnheader', 'rowheader', 'treeitem'].includes(role) && {
934
+ 'aria-selected': void 0
935
+ })
936
+ }),
937
+ // we pass the themeOverride to Options.Item
938
+ themeOverride,
939
+ // directly passed props
940
+ renderBeforeLabel,
941
+ renderAfterLabel,
942
+ beforeLabelContentVAlign,
943
+ afterLabelContentVAlign,
944
+ description,
945
+ descriptionRole,
946
+ as,
947
+ role,
948
+ elementRef,
949
+ variant: 'default',
950
+ tabIndex: -1
951
+ };
952
+
953
+ // extra data we need track on the option,
954
+ // but don't want to expose as props
955
+ const optionData = {
956
+ groupProps: groupProps
957
+ };
958
+ const isOptionDisabled = id !== this._headerBackId && (
959
+ // Back nav is never disabled
960
+ this.props.disabled || ((_this$currentPage4 = this.currentPage) === null || _this$currentPage4 === void 0 ? void 0 : _this$currentPage4.disabled) || (groupProps === null || groupProps === void 0 ? void 0 : groupProps.disabled) || disabled);
961
+
962
+ // display option as disabled
963
+ if (isOptionDisabled) {
964
+ optionProps.variant = 'disabled';
965
+ optionProps = {
966
+ ...optionProps,
967
+ ...getDisabledOptionProps()
968
+ };
969
+ }
970
+
971
+ // track as valid active option if not the title and the map doesn't already contain the id
972
+ if (id !== this._headerTitleId && !this._activeOptionsMap[id]) {
973
+ // store index to know the order of ids later; js objects doesn't preserve order
974
+ this._activeOptionsMap[id] = {
975
+ ...option,
976
+ ...optionData,
977
+ index: Object.keys(this._activeOptionsMap).length + 1
978
+ };
979
+ }
980
+ const customRole = role !== _DrilldownOption.DrilldownOption.defaultProps.role ? role : void 0;
981
+
982
+ // BEFORE/AFTER elements:
983
+ // we set a few manually on Options.Item,
984
+ // the rest are passed directly
985
+ if (subPageId) {
986
+ optionProps.renderAfterLabel = _ChevronRightInstUIIc || (_ChevronRightInstUIIc = (0, _jsxRuntime.jsx)(_uiIcons.ChevronRightInstUIIcon, {}));
987
+ optionProps['aria-haspopup'] = true;
988
+ optionProps.role = customRole || 'menuitem';
989
+ (0, _console.warn)(!renderAfterLabel, `The prop "renderAfterLabel" is reserved on item with id: "${id}". When it has "subPageId" provided, a navigation arrow will render after the label.`);
990
+ }
991
+ if (id === this._headerBackId) {
992
+ optionProps.renderBeforeLabel = _ChevronLeftInstUIIco || (_ChevronLeftInstUIIco = (0, _jsxRuntime.jsx)(_uiIcons.ChevronLeftInstUIIcon, {}));
993
+ }
994
+ const isOptionControlled = typeof option.props.selected === 'boolean';
995
+ if ((groupProps !== null && groupProps !== void 0 && groupProps.selectableType || isOptionControlled) && groupProps) {
996
+ if (!isOptionControlled) {
997
+ var _this$state$selectedG;
998
+ isSelected = Boolean((_this$state$selectedG = this.state.selectedGroupOptionsMap[groupProps.id]) === null || _this$state$selectedG === void 0 ? void 0 : _this$state$selectedG.has(id));
999
+ } else {
1000
+ isSelected = Boolean(option.props.selected);
1001
+ }
1002
+ optionProps['aria-checked'] = isSelected;
1003
+ optionProps.renderBeforeLabel = (0, _jsxRuntime.jsx)("span", {
1004
+ style: {
1005
+ visibility: isSelected ? 'visible' : 'hidden'
1006
+ },
1007
+ children: _CheckInstUIIcon || (_CheckInstUIIcon = (0, _jsxRuntime.jsx)(_uiIcons.CheckInstUIIcon, {}))
1008
+ });
1009
+ (0, _console.warn)(!renderBeforeLabel, `The prop "renderBeforeLabel" is reserved on item with id: "${id}". When this option is a selectable member of a Drilldown.Group, selection indicator will render before the label.`);
1010
+
1011
+ // setting aria roles and attributes for selectable group items
1012
+ if (groupProps.selectableType === 'single') {
1013
+ optionProps.role = customRole || 'menuitemradio';
1014
+ }
1015
+ if (groupProps.selectableType === 'multiple') {
1016
+ optionProps.role = customRole || 'menuitemcheckbox';
1017
+ }
1018
+ }
1019
+ // display option as highlighted
1020
+ if (id === this.state.highlightedOptionId) {
1021
+ optionProps.variant = 'highlighted';
1022
+ if (isOptionDisabled) {
1023
+ optionProps.variant = 'highlighted-disabled';
1024
+ }
1025
+ }
1026
+ if (href) {
1027
+ if (subPageId) {
1028
+ (0, _console.warn)(false, `Drilldown.Option with id "${id}" has subPageId, so it will ignore the "href" property.`);
1029
+ } else if (groupProps !== null && groupProps !== void 0 && groupProps.selectableType) {
1030
+ (0, _console.warn)(false, `Drilldown.Option with id "${id}" is in a selectable group, so it will ignore the "href" property.`);
1031
+ } else {
1032
+ optionProps.href = href;
1033
+ }
1034
+ }
1035
+ const optionLabel = (0, _callRenderProp.callRenderProp)(children, {
1036
+ id,
1037
+ variant: optionProps.variant,
1038
+ isSelected
1039
+ });
1040
+ if (!optionLabel) {
1041
+ (0, _console.warn)(false, `There are no "children" prop provided for option with id: "${id}", so it won't be rendered.`);
1042
+ return null;
1043
+ }
1044
+ const renderLabelProps = {
1045
+ variant: optionProps.variant,
1046
+ vAlign: afterLabelContentVAlign,
1047
+ as,
1048
+ role: optionProps.role,
1049
+ isSelected
1050
+ };
1051
+
1052
+ // we need to bind our own option props the render functions
1053
+ if (typeof optionProps.renderBeforeLabel === 'function' && !((_optionProps$renderBe = optionProps.renderBeforeLabel) !== null && _optionProps$renderBe !== void 0 && (_optionProps$renderBe2 = _optionProps$renderBe.prototype) !== null && _optionProps$renderBe2 !== void 0 && _optionProps$renderBe2.isReactComponent)) {
1054
+ optionProps.renderBeforeLabel = optionProps.renderBeforeLabel.bind(null, renderLabelProps);
1055
+ }
1056
+ if (typeof optionProps.renderAfterLabel === 'function' && !((_optionProps$renderAf = optionProps.renderAfterLabel) !== null && _optionProps$renderAf !== void 0 && (_optionProps$renderAf2 = _optionProps$renderAf.prototype) !== null && _optionProps$renderAf2 !== void 0 && _optionProps$renderAf2.isReactComponent)) {
1057
+ optionProps.renderAfterLabel = optionProps.renderAfterLabel.bind(null, renderLabelProps);
1058
+ }
1059
+ const labelInfo = renderLabelInfo && (0, _callRenderProp.callRenderProp)(renderLabelInfo, renderLabelProps);
1060
+ const vAlignMap = {
1061
+ start: 'flex-start',
1062
+ center: 'center',
1063
+ end: 'flex-end'
1064
+ };
1065
+ const labelAriaId = `${id}__label`;
1066
+ const infoAriaId = `${id}__info`;
1067
+ const labelledby = option.props['aria-labelledby'] || labelAriaId;
1068
+ const describedby = option.props['aria-describedby'] || (labelInfo ? infoAriaId : void 0);
1069
+ return (0, _react2.createElement)(_latest2.Options.Item, {
1070
+ ...optionProps,
1071
+ key: id,
1072
+ "aria-labelledby": labelledby,
1073
+ "aria-describedby": describedby
1074
+ }, (0, _jsxRuntime.jsxs)("div", {
1075
+ css: styles === null || styles === void 0 ? void 0 : styles.optionContainer,
1076
+ role: "none",
1077
+ children: [(0, _jsxRuntime.jsx)("span", {
1078
+ css: styles === null || styles === void 0 ? void 0 : styles.optionContent,
1079
+ role: "none",
1080
+ id: labelAriaId,
1081
+ children: optionLabel
1082
+ }), labelInfo ? (0, _jsxRuntime.jsx)("span", {
1083
+ css: styles === null || styles === void 0 ? void 0 : styles.optionLabelInfo,
1084
+ role: "presentation",
1085
+ style: {
1086
+ alignSelf: vAlignMap[afterLabelContentVAlign]
1087
+ },
1088
+ children: (0, _jsxRuntime.jsx)("span", {
1089
+ id: infoAriaId,
1090
+ children: labelInfo
1091
+ })
1092
+ }) : null]
1093
+ }));
1094
+ }
1095
+ renderGroup(group, getOptionProps, getDisabledOptionProps, needsFirstSeparator, needsLastSeparator) {
1096
+ const _group$props = group.props,
1097
+ id = _group$props.id,
1098
+ children = _group$props.children,
1099
+ renderGroupTitle = _group$props.renderGroupTitle,
1100
+ themeOverride = _group$props.themeOverride,
1101
+ _group$props$role = _group$props.role,
1102
+ role = _group$props$role === void 0 ? 'group' : _group$props$role,
1103
+ as = _group$props.as,
1104
+ elementRef = _group$props.elementRef;
1105
+ if (!children) {
1106
+ return null;
1107
+ }
1108
+ const groupChildren = [];
1109
+
1110
+ // add a separator above
1111
+ if (needsFirstSeparator) {
1112
+ groupChildren.push(_Options$Separator || (_Options$Separator = (0, _jsxRuntime.jsx)(_latest2.Options.Separator, {}, "drilldown-options-separator")));
1113
+ }
1114
+
1115
+ // create a sublist as a group
1116
+ // (a wrapping list item will be created by Options)
1117
+ groupChildren.push((0, _jsxRuntime.jsx)(_latest2.Options, {
1118
+ id: id,
1119
+ role: role,
1120
+ as: as || this.props.as,
1121
+ renderLabel: renderGroupTitle,
1122
+ elementRef: elementRef
1123
+ // we pass the themeOverride to Options
1124
+ ,
1125
+ themeOverride: themeOverride,
1126
+ children: this.getChildrenArray(children).map(child => {
1127
+ if ((0, _matchComponentTypes.matchComponentTypes)(child, [_DrilldownSeparator.DrilldownSeparator])) {
1128
+ return this.renderSeparator(child);
1129
+ } else if ((0, _matchComponentTypes.matchComponentTypes)(child, [_DrilldownOption.DrilldownOption])) {
1130
+ return this.renderOption(child, getOptionProps, getDisabledOptionProps, group.props);
1131
+ } else {
1132
+ return null;
1133
+ }
1134
+ })
1135
+ }, id));
1136
+
1137
+ // add a separator below
1138
+ if (needsLastSeparator) {
1139
+ groupChildren.push(_Options$Separator2 || (_Options$Separator2 = (0, _jsxRuntime.jsx)(_latest2.Options.Separator, {}, "drilldown-options-separator-2")));
1140
+ }
1141
+ return groupChildren;
1142
+ }
1143
+ renderPage() {
1144
+ const _this$props6 = this.props,
1145
+ styles = _this$props6.styles,
1146
+ overflowY = _this$props6.overflowY,
1147
+ overflowX = _this$props6.overflowX,
1148
+ height = _this$props6.height,
1149
+ width = _this$props6.width,
1150
+ minHeight = _this$props6.minHeight,
1151
+ minWidth = _this$props6.minWidth,
1152
+ maxHeight = _this$props6.maxHeight,
1153
+ maxWidth = _this$props6.maxWidth,
1154
+ role = _this$props6.role,
1155
+ as = _this$props6.as,
1156
+ label = _this$props6.label,
1157
+ trigger = _this$props6.trigger;
1158
+ if (!this.currentPage) {
1159
+ return null;
1160
+ }
1161
+ return (0, _jsxRuntime.jsx)(_Selectable.Selectable, {
1162
+ isShowingOptions: this.shown,
1163
+ highlightedOptionId: this.state.highlightedOptionId,
1164
+ selectedOptionId: this.selectedGroupOptionIdsArray,
1165
+ onRequestShowOptions: this.show,
1166
+ onRequestHideOptions: this.hide,
1167
+ onRequestSelectOption: this.handleOptionSelect,
1168
+ onRequestHighlightOption: this.handleOptionHighlight,
1169
+ onRequestHighlightFirstOption: event => {
1170
+ const firstOptionId = this.activeOptionIds[0];
1171
+ this.handleOptionHighlight(event, {
1172
+ id: firstOptionId
1173
+ });
1174
+ },
1175
+ onRequestHighlightLastOption: event => {
1176
+ const lastOptionId = this.activeOptionIds[this.activeOptionIds.length - 1];
1177
+ this.handleOptionHighlight(event, {
1178
+ id: lastOptionId
1179
+ });
1180
+ },
1181
+ children: ({
1182
+ // TODO: figure out what other Selectable props we need, if we want to add a Select version for drilldown:
1183
+ // getRootProps, - we probably don't need this
1184
+ // getLabelProps, - do we need label?
1185
+ // getDescriptionProps, - might be nice for assistiveText like in Select
1186
+ // getInputProps, - hidden input for a11y? role="combobox" might be needed
1187
+ getTriggerProps,
1188
+ getListProps,
1189
+ getOptionProps,
1190
+ getDisabledOptionProps
1191
+ }) => (0, _jsxRuntime.jsx)(_latest.View
1192
+ // if there is a trigger the border needs to be rendered by the <Popover>
1193
+ // (because it has an arrow)
1194
+ , {
1195
+ ...(trigger ? {} : {
1196
+ borderWidth: 'small'
1197
+ }),
1198
+ as: "div",
1199
+ "data-cid": "Drilldown",
1200
+ elementRef: this.handleDrilldownRef,
1201
+ tabIndex: 0,
1202
+ css: styles === null || styles === void 0 ? void 0 : styles.drilldown,
1203
+ position: "relative",
1204
+ borderRadius: "small",
1205
+ width: width,
1206
+ minWidth: maxWidth,
1207
+ maxWidth: maxWidth,
1208
+ role: role,
1209
+ "aria-label": label,
1210
+ "aria-labelledby": this.currentPageAriaLabel,
1211
+ ...getTriggerProps({
1212
+ id: this._id,
1213
+ // We need to override these aria attributes added by Selectable,
1214
+ // since Drilldown is not a combobox and has no popup
1215
+ 'aria-haspopup': false,
1216
+ 'aria-expanded': void 0,
1217
+ onKeyDown: this.handleKeyDown,
1218
+ onBlur: event => {
1219
+ const target = event.currentTarget;
1220
+ const related = event.relatedTarget;
1221
+ const containsRelated = (0, _contains.contains)(target, related);
1222
+ if (!related || related === this._drilldownRef || related !== target && !containsRelated) {
1223
+ this.setState({
1224
+ highlightedOptionId: void 0
1225
+ });
1226
+ }
1227
+ },
1228
+ onMouseLeave: () => {
1229
+ this.setState({
1230
+ highlightedOptionId: void 0
1231
+ });
1232
+ }
1233
+ }),
1234
+ children: (0, _jsxRuntime.jsx)(_latest.View, {
1235
+ as: "div",
1236
+ overflowY: overflowY,
1237
+ overflowX: overflowX,
1238
+ height: height,
1239
+ width: width,
1240
+ minHeight: minHeight,
1241
+ minWidth: minWidth,
1242
+ maxHeight: maxHeight,
1243
+ maxWidth: maxWidth,
1244
+ css: styles === null || styles === void 0 ? void 0 : styles.container,
1245
+ borderRadius: "small",
1246
+ role: "presentation",
1247
+ elementRef: element => {
1248
+ this._containerElement = element;
1249
+ },
1250
+ children: (0, _jsxRuntime.jsx)(_latest2.Options, {
1251
+ ...getListProps(),
1252
+ role: "presentation",
1253
+ as: as,
1254
+ children: this.renderList(getOptionProps, getDisabledOptionProps)
1255
+ })
1256
+ })
1257
+ })
1258
+ });
1259
+ }
1260
+ render() {
1261
+ var _styles$drilldown;
1262
+ // clear temporary option store
1263
+ this._activeOptionsMap = {};
1264
+ const _this$props7 = this.props,
1265
+ show = _this$props7.show,
1266
+ defaultShow = _this$props7.defaultShow,
1267
+ placement = _this$props7.placement,
1268
+ withArrow = _this$props7.withArrow,
1269
+ shouldContainFocus = _this$props7.shouldContainFocus,
1270
+ shouldReturnFocus = _this$props7.shouldReturnFocus,
1271
+ trigger = _this$props7.trigger,
1272
+ mountNode = _this$props7.mountNode,
1273
+ constrain = _this$props7.constrain,
1274
+ positionTarget = _this$props7.positionTarget,
1275
+ positionContainerDisplay = _this$props7.positionContainerDisplay,
1276
+ popoverRef = _this$props7.popoverRef,
1277
+ disabled = _this$props7.disabled,
1278
+ onDismiss = _this$props7.onDismiss,
1279
+ onFocus = _this$props7.onFocus,
1280
+ onMouseOver = _this$props7.onMouseOver,
1281
+ offsetX = _this$props7.offsetX,
1282
+ offsetY = _this$props7.offsetY,
1283
+ shouldSetAriaExpanded = _this$props7.shouldSetAriaExpanded,
1284
+ styles = _this$props7.styles;
1285
+ const borderColor = styles === null || styles === void 0 ? void 0 : (_styles$drilldown = styles.drilldown) === null || _styles$drilldown === void 0 ? void 0 : _styles$drilldown.borderColor;
1286
+ return trigger ? (0, _jsxRuntime.jsx)(_latest3.Popover, {
1287
+ "data-cid": "Drilldown",
1288
+ themeOverride: {
1289
+ // use here own theme's color
1290
+ borderColor: borderColor
1291
+ },
1292
+ shouldSetAriaExpanded: shouldSetAriaExpanded,
1293
+ isShowingContent: show,
1294
+ defaultIsShowingContent: defaultShow,
1295
+ shouldCloseOnDocumentClick: true,
1296
+ onHideContent: (event, {
1297
+ documentClick
1298
+ }) => {
1299
+ if (typeof onDismiss === 'function') {
1300
+ onDismiss(event, documentClick);
1301
+ }
1302
+ this.reset();
1303
+ this.handleToggle(event, false);
1304
+ },
1305
+ onShowContent: event => this.handleToggle(event, true),
1306
+ mountNode: mountNode || this.ref,
1307
+ placement: placement,
1308
+ withArrow: withArrow,
1309
+ positionTarget: positionTarget,
1310
+ positionContainerDisplay: positionContainerDisplay,
1311
+ constrain: constrain,
1312
+ shouldContainFocus: shouldContainFocus,
1313
+ shouldReturnFocus: shouldReturnFocus,
1314
+ id: this._id,
1315
+ on: ['click'],
1316
+ onFocus: onFocus,
1317
+ onMouseOver: onMouseOver,
1318
+ offsetX: offsetX,
1319
+ offsetY: offsetY,
1320
+ defaultFocusElement: () => {
1321
+ var _this$getFirstOption2, _this$_popover2, _this$_popover2$_cont;
1322
+ if (!this.currentPage) return null;
1323
+ const actionLabel = (0, _callRenderProp.callRenderProp)(this.currentPage.renderActionLabel);
1324
+ // Use action ID if exists, otherwise first non-action option's ID
1325
+ const targetId = actionLabel ? this._headerActionId : (_this$getFirstOption2 = this.getFirstOption()) === null || _this$getFirstOption2 === void 0 ? void 0 : _this$getFirstOption2.props.id;
1326
+ if (!targetId) return null;
1327
+ return (_this$_popover2 = this._popover) === null || _this$_popover2 === void 0 ? void 0 : (_this$_popover2$_cont = _this$_popover2._contentElement) === null || _this$_popover2$_cont === void 0 ? void 0 : _this$_popover2$_cont.querySelector(`#${CSS.escape(targetId)}`);
1328
+ },
1329
+ elementRef: element => {
1330
+ // setting ref for "Popover" version, the popover root
1331
+ // (if there is no trigger, we set it in handleDrilldownRef)
1332
+ this.handleRef(element);
1333
+ },
1334
+ ref: el => {
1335
+ this._popover = el;
1336
+ if (typeof popoverRef === 'function') {
1337
+ popoverRef(el);
1338
+ }
1339
+ },
1340
+ renderTrigger: (0, _safeCloneElement.safeCloneElement)(trigger, {
1341
+ ref: el => {
1342
+ this._trigger = el;
1343
+ },
1344
+ 'aria-haspopup': this.props.role,
1345
+ id: this._triggerId,
1346
+ disabled: !!(trigger.props.disabled || disabled),
1347
+ 'aria-disabled': trigger.props.disabled || disabled ? 'true' : void 0
1348
+ }),
1349
+ children: this.renderPage()
1350
+ }) : this.renderPage();
1351
+ }
1352
+ }, _Drilldown.displayName = "Drilldown", _Drilldown.componentId = 'Drilldown', _Drilldown.allowedProps = _props.allowedProps, _Drilldown.defaultProps = {
1353
+ disabled: false,
1354
+ rotateFocus: true,
1355
+ as: 'ul',
1356
+ role: 'menu',
1357
+ overflowX: 'auto',
1358
+ overflowY: 'auto',
1359
+ placement: 'bottom center',
1360
+ defaultShow: false,
1361
+ shouldHideOnSelect: true,
1362
+ shouldContainFocus: false,
1363
+ shouldReturnFocus: true,
1364
+ withArrow: true,
1365
+ offsetX: 0,
1366
+ offsetY: 0,
1367
+ shouldSetAriaExpanded: true
1368
+ }, _Drilldown.Group = _DrilldownGroup.DrilldownGroup, _Drilldown.Option = _DrilldownOption.DrilldownOption, _Drilldown.Page = _DrilldownPage.DrilldownPage, _Drilldown.Separator = _DrilldownSeparator.DrilldownSeparator, _Drilldown)) || _class) || _class);
1369
+ var _default = exports.default = Drilldown;