@itwin/itwinui-react 3.15.4 → 3.16.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 (137) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/DEV-cjs/core/Breadcrumbs/Breadcrumbs.js +2 -2
  3. package/DEV-cjs/core/Checkbox/Checkbox.js +4 -6
  4. package/DEV-cjs/core/ComboBox/ComboBox.js +10 -6
  5. package/DEV-cjs/core/DatePicker/DatePicker.js +9 -1
  6. package/DEV-cjs/core/Dialog/Dialog.js +1 -1
  7. package/DEV-cjs/core/Panels/Panels.js +319 -0
  8. package/DEV-cjs/core/Panels/helpers.js +62 -0
  9. package/DEV-cjs/core/Radio/Radio.js +4 -6
  10. package/DEV-cjs/core/RadioTiles/RadioTileGroup.js +9 -2
  11. package/DEV-cjs/core/Select/SelectTag.js +9 -11
  12. package/DEV-cjs/core/Select/SelectTagContainer.js +2 -2
  13. package/DEV-cjs/core/Stepper/Stepper.js +1 -0
  14. package/DEV-cjs/core/Stepper/StepperStep.js +2 -1
  15. package/DEV-cjs/core/Table/Table.js +64 -47
  16. package/DEV-cjs/core/Table/TablePaginator.js +15 -3
  17. package/DEV-cjs/core/Table/actionHandlers/selectHandler.js +10 -7
  18. package/DEV-cjs/core/Table/columns/selectionColumn.js +6 -1
  19. package/DEV-cjs/core/Tree/Tree.js +1 -0
  20. package/DEV-cjs/index.js +4 -0
  21. package/DEV-cjs/styles.js +1 -1
  22. package/DEV-cjs/utils/components/MiddleTextTruncation.js +22 -4
  23. package/DEV-cjs/utils/components/OverflowContainer.js +170 -27
  24. package/DEV-cjs/utils/hooks/index.js +1 -1
  25. package/DEV-cjs/utils/hooks/useInstance.js +38 -0
  26. package/DEV-esm/core/Breadcrumbs/Breadcrumbs.js +2 -2
  27. package/DEV-esm/core/Checkbox/Checkbox.js +5 -10
  28. package/DEV-esm/core/ComboBox/ComboBox.js +10 -6
  29. package/DEV-esm/core/DatePicker/DatePicker.js +11 -1
  30. package/DEV-esm/core/Dialog/Dialog.js +1 -1
  31. package/DEV-esm/core/Panels/Panels.js +301 -0
  32. package/DEV-esm/core/Panels/helpers.js +42 -0
  33. package/DEV-esm/core/Radio/Radio.js +4 -9
  34. package/DEV-esm/core/RadioTiles/RadioTileGroup.js +8 -2
  35. package/DEV-esm/core/Select/SelectTag.js +9 -11
  36. package/DEV-esm/core/Select/SelectTagContainer.js +2 -2
  37. package/DEV-esm/core/Stepper/Stepper.js +1 -0
  38. package/DEV-esm/core/Stepper/StepperStep.js +2 -1
  39. package/DEV-esm/core/Table/Table.js +61 -47
  40. package/DEV-esm/core/Table/TablePaginator.js +16 -3
  41. package/DEV-esm/core/Table/actionHandlers/selectHandler.js +10 -7
  42. package/DEV-esm/core/Table/columns/selectionColumn.js +6 -1
  43. package/DEV-esm/core/Tree/Tree.js +1 -0
  44. package/DEV-esm/index.js +1 -0
  45. package/DEV-esm/styles.js +1 -1
  46. package/DEV-esm/utils/components/MiddleTextTruncation.js +22 -4
  47. package/DEV-esm/utils/components/OverflowContainer.js +143 -4
  48. package/DEV-esm/utils/hooks/index.js +1 -1
  49. package/DEV-esm/utils/hooks/useInstance.js +18 -0
  50. package/cjs/core/Breadcrumbs/Breadcrumbs.js +2 -2
  51. package/cjs/core/Checkbox/Checkbox.js +4 -6
  52. package/cjs/core/ComboBox/ComboBox.d.ts +13 -0
  53. package/cjs/core/ComboBox/ComboBox.js +10 -6
  54. package/cjs/core/DatePicker/DatePicker.d.ts +2 -2
  55. package/cjs/core/DatePicker/DatePicker.js +2 -1
  56. package/cjs/core/Dialog/Dialog.js +1 -1
  57. package/cjs/core/Dialog/DialogContext.d.ts +6 -2
  58. package/cjs/core/NonIdealState/NonIdealState.d.ts +15 -11
  59. package/cjs/core/Panels/Panels.d.ts +174 -0
  60. package/cjs/core/Panels/Panels.js +312 -0
  61. package/cjs/core/Panels/helpers.d.ts +23 -0
  62. package/cjs/core/Panels/helpers.js +61 -0
  63. package/cjs/core/Radio/Radio.js +4 -6
  64. package/cjs/core/RadioTiles/RadioTileGroup.d.ts +3 -1
  65. package/cjs/core/RadioTiles/RadioTileGroup.js +9 -2
  66. package/cjs/core/Select/SelectTag.d.ts +3 -1
  67. package/cjs/core/Select/SelectTag.js +9 -11
  68. package/cjs/core/Select/SelectTagContainer.js +2 -2
  69. package/cjs/core/Stepper/Stepper.d.ts +4 -0
  70. package/cjs/core/Stepper/Stepper.js +1 -0
  71. package/cjs/core/Stepper/StepperStep.d.ts +4 -0
  72. package/cjs/core/Stepper/StepperStep.js +2 -1
  73. package/cjs/core/Table/Table.d.ts +1 -0
  74. package/cjs/core/Table/Table.js +64 -47
  75. package/cjs/core/Table/TablePaginator.js +15 -3
  76. package/cjs/core/Table/actionHandlers/selectHandler.js +10 -7
  77. package/cjs/core/Table/columns/selectionColumn.js +6 -1
  78. package/cjs/core/Tree/Tree.js +1 -0
  79. package/cjs/index.d.ts +1 -0
  80. package/cjs/index.js +4 -0
  81. package/cjs/styles.js +1 -1
  82. package/cjs/utils/components/MiddleTextTruncation.d.ts +5 -7
  83. package/cjs/utils/components/MiddleTextTruncation.js +22 -4
  84. package/cjs/utils/components/OverflowContainer.d.ts +1 -0
  85. package/cjs/utils/components/OverflowContainer.js +170 -27
  86. package/cjs/utils/hooks/index.d.ts +1 -1
  87. package/cjs/utils/hooks/index.js +1 -1
  88. package/cjs/utils/hooks/useInstance.d.ts +22 -0
  89. package/cjs/utils/hooks/useInstance.js +38 -0
  90. package/esm/core/Breadcrumbs/Breadcrumbs.js +2 -2
  91. package/esm/core/Checkbox/Checkbox.js +5 -10
  92. package/esm/core/ComboBox/ComboBox.d.ts +13 -0
  93. package/esm/core/ComboBox/ComboBox.js +10 -6
  94. package/esm/core/DatePicker/DatePicker.d.ts +2 -2
  95. package/esm/core/DatePicker/DatePicker.js +4 -1
  96. package/esm/core/Dialog/Dialog.js +1 -1
  97. package/esm/core/Dialog/DialogContext.d.ts +6 -2
  98. package/esm/core/NonIdealState/NonIdealState.d.ts +15 -11
  99. package/esm/core/Panels/Panels.d.ts +174 -0
  100. package/esm/core/Panels/Panels.js +294 -0
  101. package/esm/core/Panels/helpers.d.ts +23 -0
  102. package/esm/core/Panels/helpers.js +41 -0
  103. package/esm/core/Radio/Radio.js +4 -9
  104. package/esm/core/RadioTiles/RadioTileGroup.d.ts +3 -1
  105. package/esm/core/RadioTiles/RadioTileGroup.js +8 -2
  106. package/esm/core/Select/SelectTag.d.ts +3 -1
  107. package/esm/core/Select/SelectTag.js +9 -11
  108. package/esm/core/Select/SelectTagContainer.js +2 -2
  109. package/esm/core/Stepper/Stepper.d.ts +4 -0
  110. package/esm/core/Stepper/Stepper.js +1 -0
  111. package/esm/core/Stepper/StepperStep.d.ts +4 -0
  112. package/esm/core/Stepper/StepperStep.js +2 -1
  113. package/esm/core/Table/Table.d.ts +1 -0
  114. package/esm/core/Table/Table.js +61 -47
  115. package/esm/core/Table/TablePaginator.js +16 -3
  116. package/esm/core/Table/actionHandlers/selectHandler.js +10 -7
  117. package/esm/core/Table/columns/selectionColumn.js +6 -1
  118. package/esm/core/Tree/Tree.js +1 -0
  119. package/esm/index.d.ts +1 -0
  120. package/esm/index.js +1 -0
  121. package/esm/styles.js +1 -1
  122. package/esm/utils/components/MiddleTextTruncation.d.ts +5 -7
  123. package/esm/utils/components/MiddleTextTruncation.js +22 -4
  124. package/esm/utils/components/OverflowContainer.d.ts +1 -0
  125. package/esm/utils/components/OverflowContainer.js +143 -4
  126. package/esm/utils/hooks/index.d.ts +1 -1
  127. package/esm/utils/hooks/index.js +1 -1
  128. package/esm/utils/hooks/useInstance.d.ts +22 -0
  129. package/esm/utils/hooks/useInstance.js +18 -0
  130. package/package.json +2 -2
  131. package/styles.css +8 -8
  132. package/DEV-cjs/utils/hooks/useOverflow.js +0 -76
  133. package/DEV-esm/utils/hooks/useOverflow.js +0 -63
  134. package/cjs/utils/hooks/useOverflow.d.ts +0 -23
  135. package/cjs/utils/hooks/useOverflow.js +0 -76
  136. package/esm/utils/hooks/useOverflow.d.ts +0 -23
  137. package/esm/utils/hooks/useOverflow.js +0 -63
@@ -13,6 +13,9 @@ _export(exports, {
13
13
  Table: function () {
14
14
  return Table;
15
15
  },
16
+ iuiId: function () {
17
+ return iuiId;
18
+ },
16
19
  tableResizeStartAction: function () {
17
20
  return tableResizeStartAction;
18
21
  },
@@ -36,6 +39,7 @@ const singleRowSelectedAction = 'singleRowSelected';
36
39
  const shiftRowSelectedAction = 'shiftRowSelected';
37
40
  const tableResizeStartAction = 'tableResizeStart';
38
41
  const tableResizeEndAction = 'tableResizeEnd';
42
+ const iuiId = Symbol('iui-id');
39
43
  const flattenColumns = (columns) => {
40
44
  let flatColumns = [];
41
45
  columns.forEach((column) => {
@@ -88,6 +92,7 @@ const Table = (props) => {
88
92
  headerProps,
89
93
  bodyProps,
90
94
  emptyTableContentProps,
95
+ getRowId,
91
96
  ...rest
92
97
  } = props;
93
98
  (0, _index.useGlobals)();
@@ -225,16 +230,30 @@ const Table = (props) => {
225
230
  ),
226
231
  [data, getSubRows],
227
232
  );
228
- let [rowHasParent] = _react.useState(() => new WeakSet());
229
233
  let getSubRowsWithSubComponents = _react.useCallback(
230
- (originalRow) => {
231
- if (!rowHasParent.has(originalRow)) {
232
- rowHasParent.add(originalRow);
233
- return [originalRow];
234
- }
235
- return originalRow.subRows || [];
234
+ (originalRow, relativeIndex) => {
235
+ if (originalRow[iuiId]) return [];
236
+ if (originalRow.subRows) return originalRow.subRows;
237
+ return [
238
+ {
239
+ [iuiId]: `subcomponent-${relativeIndex}`,
240
+ ...originalRow,
241
+ },
242
+ ];
236
243
  },
237
- [rowHasParent],
244
+ [],
245
+ );
246
+ let getRowIdWithSubComponents = _react.useCallback(
247
+ (originalRow, relativeIndex, parent) => {
248
+ let defaultRowId = parent
249
+ ? `${parent.id}.${relativeIndex}`
250
+ : `${relativeIndex}`;
251
+ let rowIdFromUser = getRowId?.(originalRow, relativeIndex, parent);
252
+ if (void 0 !== rowIdFromUser && originalRow[iuiId])
253
+ return `${rowIdFromUser}-${defaultRowId}`;
254
+ return rowIdFromUser ?? defaultRowId;
255
+ },
256
+ [getRowId],
238
257
  );
239
258
  let instance = (0, _reacttable.useTable)(
240
259
  {
@@ -254,6 +273,7 @@ const Table = (props) => {
254
273
  ...props.initialState,
255
274
  },
256
275
  columnResizeMode,
276
+ getRowId: subComponent ? getRowIdWithSubComponents : getRowId,
257
277
  },
258
278
  _reacttable.useFlexLayout,
259
279
  (0, _index1.useResizeColumns)(ownerDocument),
@@ -459,51 +479,52 @@ const Table = (props) => {
459
479
  (index, virtualItem, virtualizer) => {
460
480
  let row = page[index];
461
481
  prepareRow(row);
462
- if (row.subRows.length > 0 || !subComponent)
463
- return _react.createElement(_TableRowMemoized.TableRowMemoized, {
464
- row: row,
465
- rowProps: rowProps,
466
- isLast: index === page.length - 1,
467
- onRowInViewport: onRowInViewportRef,
468
- onBottomReached: onBottomReachedRef,
469
- intersectionMargin: intersectionMargin,
470
- state: state,
471
- key: row.getRowProps().key,
472
- onClick: onRowClickHandler,
473
- subComponent: subComponent,
474
- isDisabled: !!isRowDisabled?.(row.original),
475
- tableHasSubRows: hasAnySubRows,
476
- tableInstance: instance,
477
- expanderCell: expanderCell,
478
- scrollContainerRef: tableRef.current,
479
- tableRowRef: enableVirtualization ? void 0 : tableRowRef(row),
480
- density: density,
481
- virtualItem: virtualItem,
482
- virtualizer: virtualizer,
483
- });
484
- return _react.createElement(
485
- _TableExpandableContentMemoized.TableExpandableContentMemoized,
486
- {
487
- key: row.getRowProps().key,
488
- virtualItem: virtualItem,
489
- ref: enableVirtualization
490
- ? virtualizer?.measureElement
491
- : tableRowRef(row),
492
- isDisabled: !!isRowDisabled?.(row.original),
493
- },
494
- subComponent(row),
495
- );
482
+ let isRowASubComponent = !!row.original[iuiId] && !!subComponent;
483
+ if (isRowASubComponent)
484
+ return _react.createElement(
485
+ _TableExpandableContentMemoized.TableExpandableContentMemoized,
486
+ {
487
+ key: row.getRowProps().key,
488
+ virtualItem: virtualItem,
489
+ ref: enableVirtualization
490
+ ? virtualizer?.measureElement
491
+ : tableRowRef(row),
492
+ isDisabled: !!isRowDisabled?.(row.original),
493
+ },
494
+ subComponent(row),
495
+ );
496
+ return _react.createElement(_TableRowMemoized.TableRowMemoized, {
497
+ row: row,
498
+ rowProps: rowProps,
499
+ isLast: index === page.length - 1,
500
+ onRowInViewport: onRowInViewportRef,
501
+ onBottomReached: onBottomReachedRef,
502
+ intersectionMargin: intersectionMargin,
503
+ state: state,
504
+ key: row.getRowProps().key,
505
+ onClick: onRowClickHandler,
506
+ subComponent: subComponent,
507
+ isDisabled: !!isRowDisabled?.(row.original),
508
+ tableHasSubRows: hasAnySubRows,
509
+ tableInstance: instance,
510
+ expanderCell: expanderCell,
511
+ scrollContainerRef: tableRef.current,
512
+ tableRowRef: enableVirtualization ? void 0 : tableRowRef(row),
513
+ density: density,
514
+ virtualItem: virtualItem,
515
+ virtualizer: virtualizer,
516
+ });
496
517
  },
497
518
  [
498
519
  page,
499
520
  prepareRow,
521
+ subComponent,
500
522
  rowProps,
501
523
  onRowInViewportRef,
502
524
  onBottomReachedRef,
503
525
  intersectionMargin,
504
526
  state,
505
527
  onRowClickHandler,
506
- subComponent,
507
528
  isRowDisabled,
508
529
  hasAnySubRows,
509
530
  instance,
@@ -640,11 +661,7 @@ const Table = (props) => {
640
661
  },
641
662
  bodyProps?.className,
642
663
  ),
643
- style: {
644
- outline: 0,
645
- },
646
664
  }),
647
- tabIndex: -1,
648
665
  'aria-multiselectable':
649
666
  (isSelectable && 'multi' === selectionMode) || void 0,
650
667
  },
@@ -60,7 +60,7 @@ const TablePaginator = (props) => {
60
60
  );
61
61
  let pageListRef = _react.useRef(null);
62
62
  let [focusedIndex, setFocusedIndex] = _react.useState(currentPage);
63
- _react.useLayoutEffect(() => {
63
+ (0, _index.useLayoutEffect)(() => {
64
64
  setFocusedIndex(currentPage);
65
65
  }, [currentPage]);
66
66
  let needFocus = _react.useRef(false);
@@ -182,6 +182,7 @@ const TablePaginator = (props) => {
182
182
  : _react.createElement(TablePaginatorPageButtons, {
183
183
  size: size,
184
184
  focusedIndex: focusedIndex,
185
+ setFocusedIndex: setFocusedIndex,
185
186
  totalPagesCount: totalPagesCount,
186
187
  onPageChange: onPageChange,
187
188
  currentPage: currentPage,
@@ -255,6 +256,7 @@ const TablePaginator = (props) => {
255
256
  const TablePaginatorPageButtons = (props) => {
256
257
  let {
257
258
  focusedIndex,
259
+ setFocusedIndex,
258
260
  totalPagesCount,
259
261
  onPageChange,
260
262
  currentPage,
@@ -274,14 +276,24 @@ const TablePaginatorPageButtons = (props) => {
274
276
  styleType: 'borderless',
275
277
  size: buttonSize,
276
278
  'data-iui-active': index === currentPage,
277
- onClick: () => onPageChange(index),
279
+ onClick: () => {
280
+ setFocusedIndex(index);
281
+ onPageChange(index);
282
+ },
278
283
  'aria-current': index === currentPage,
279
284
  'aria-label': localization.goToPageLabel?.(index + 1),
280
285
  tabIndex: tabIndex,
281
286
  },
282
287
  index + 1,
283
288
  ),
284
- [focusedIndex, currentPage, localization, buttonSize, onPageChange],
289
+ [
290
+ focusedIndex,
291
+ buttonSize,
292
+ currentPage,
293
+ localization,
294
+ setFocusedIndex,
295
+ onPageChange,
296
+ ],
285
297
  );
286
298
  let pageList = _react.useMemo(
287
299
  () =>
@@ -20,6 +20,7 @@ _export(exports, {
20
20
  return onToggleHandler;
21
21
  },
22
22
  });
23
+ const _Table = require('../Table.js');
23
24
  const onSelectHandler = (newState, instance, onSelect, isRowDisabled) => {
24
25
  if (!instance?.rows.length) {
25
26
  onSelect?.([], newState);
@@ -29,14 +30,16 @@ const onSelectHandler = (newState, instance, onSelect, isRowDisabled) => {
29
30
  let handleRow = (row) => {
30
31
  if (isRowDisabled?.(row.original)) return false;
31
32
  let isAllSubSelected = true;
32
- row.initialSubRows.forEach((subRow) => {
33
- let result = handleRow(subRow);
34
- if (!result) isAllSubSelected = false;
35
- });
33
+ if (row.initialSubRows[0]?.original[_Table.iuiId] === void 0)
34
+ row.initialSubRows.forEach((subRow) => {
35
+ let result = handleRow(subRow);
36
+ if (!result) isAllSubSelected = false;
37
+ });
36
38
  if (
37
- (!instance.selectSubRows && newState.selectedRowIds[row.id]) ||
38
- (!row.initialSubRows.length && newState.selectedRowIds[row.id]) ||
39
- (row.initialSubRows.length && isAllSubSelected)
39
+ newState.selectedRowIds[row.id] &&
40
+ (!instance.selectSubRows ||
41
+ !row.initialSubRows.length ||
42
+ isAllSubSelected)
40
43
  )
41
44
  newSelectedRowIds[row.id] = true;
42
45
  return !!newSelectedRowIds[row.id];
@@ -21,6 +21,7 @@ const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildc
21
21
  const _react = _interop_require_wildcard._(require('react'));
22
22
  const _Checkbox = require('../../Checkbox/Checkbox.js');
23
23
  const _index = require('../cells/index.js');
24
+ const _Table = require('../Table.js');
24
25
  const SELECTION_CELL_ID = 'iui-table-checkbox-selector';
25
26
  const SelectionColumn = (props = {}) => {
26
27
  let { isDisabled, density } = props;
@@ -70,7 +71,11 @@ const SelectionColumn = (props = {}) => {
70
71
  disabled: isDisabled?.(row.original),
71
72
  onClick: (e) => e.stopPropagation(),
72
73
  onChange: () => {
73
- if (row.subRows.length > 0 && selectSubRows)
74
+ if (
75
+ row.subRows.length > 0 &&
76
+ selectSubRows &&
77
+ void 0 === row.initialSubRows[0].original[_Table.iuiId]
78
+ )
74
79
  row.toggleRowSelected(
75
80
  !row.subRows.every(
76
81
  (subRow) => subRow.isSelected || isDisabled?.(subRow.original),
@@ -170,6 +170,7 @@ const Tree = (props) => {
170
170
  onKeyDown: handleKeyDown,
171
171
  ref: treeRef,
172
172
  className: className,
173
+ 'data-iui-size': 'small' === size ? 'small' : void 0,
173
174
  style: style,
174
175
  ...rest,
175
176
  })
package/DEV-cjs/index.js CHANGED
@@ -371,6 +371,9 @@ _export(exports, {
371
371
  tableFilters: function () {
372
372
  return _index.tableFilters;
373
373
  },
374
+ unstable_Panels: function () {
375
+ return _Panels.Panels;
376
+ },
374
377
  useToaster: function () {
375
378
  return _Toaster.useToaster;
376
379
  },
@@ -437,6 +440,7 @@ const _ModalContent = require('./core/Modal/ModalContent.js');
437
440
  const _ModalButtonBar = require('./core/Modal/ModalButtonBar.js');
438
441
  const _NotificationMarker = require('./core/NotificationMarker/NotificationMarker.js');
439
442
  const _Overlay = require('./core/Overlay/Overlay.js');
443
+ const _Panels = require('./core/Panels/Panels.js');
440
444
  const _ProgressLinear = require('./core/ProgressIndicators/ProgressLinear.js');
441
445
  const _ProgressRadial = require('./core/ProgressIndicators/ProgressRadial.js');
442
446
  const _Radio = require('./core/Radio/Radio.js');
package/DEV-cjs/styles.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
- const e = '3.15.4';
3
+ const e = '3.16.0';
4
4
  const u = new Proxy(
5
5
  {},
6
6
  {
@@ -11,9 +11,11 @@ Object.defineProperty(exports, 'MiddleTextTruncation', {
11
11
  const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard');
12
12
  const _react = _interop_require_wildcard._(require('react'));
13
13
  const _OverflowContainer = require('./OverflowContainer.js');
14
+ const _VisuallyHidden = require('../../core/VisuallyHidden/VisuallyHidden.js');
15
+ const _ShadowRoot = require('./ShadowRoot.js');
14
16
  const ELLIPSIS_CHAR = '…';
15
- const MiddleTextTruncation = (props) => {
16
- let { text, style, ...rest } = props;
17
+ const MiddleTextTruncation = _react.forwardRef((props, forwardedRef) => {
18
+ let { text, endCharsCount, textRenderer, style, ...rest } = props;
17
19
  return _react.createElement(
18
20
  _OverflowContainer.OverflowContainer,
19
21
  {
@@ -27,10 +29,26 @@ const MiddleTextTruncation = (props) => {
27
29
  },
28
30
  itemsCount: text.length,
29
31
  ...rest,
32
+ ref: forwardedRef,
30
33
  },
31
- _react.createElement(MiddleTextTruncationContent, props),
34
+ _react.createElement(
35
+ _ShadowRoot.ShadowRoot,
36
+ null,
37
+ _react.createElement(_VisuallyHidden.VisuallyHidden, null, text),
38
+ _react.createElement('slot', {
39
+ 'aria-hidden': true,
40
+ style: {
41
+ pointerEvents: 'none',
42
+ },
43
+ }),
44
+ ),
45
+ _react.createElement(MiddleTextTruncationContent, {
46
+ text: text,
47
+ endCharsCount: endCharsCount,
48
+ textRenderer: textRenderer,
49
+ }),
32
50
  );
33
- };
51
+ });
34
52
  MiddleTextTruncation.displayName = 'MiddleTextTruncation';
35
53
  const MiddleTextTruncationContent = (props) => {
36
54
  let { text, endCharsCount = 6, textRenderer } = props;
@@ -12,49 +12,192 @@ const _interop_require_default = require('@swc/helpers/_/_interop_require_defaul
12
12
  const _react = _interop_require_default._(require('react'));
13
13
  const _useMergedRefs = require('../hooks/useMergedRefs.js');
14
14
  const _Box = require('./Box.js');
15
- const _useOverflow = require('../hooks/useOverflow.js');
15
+ const _useIsomorphicLayoutEffect = require('../hooks/useIsomorphicLayoutEffect.js');
16
16
  const _useSafeContext = require('../hooks/useSafeContext.js');
17
- const OverflowContainerComponent = _react.default.forwardRef((props, ref) => {
18
- let { itemsCount, children, overflowOrientation, ...rest } = props;
19
- let [containerRef, visibleCount] = (0, _useOverflow.useOverflow)(
20
- itemsCount,
21
- false,
22
- overflowOrientation,
23
- );
24
- let overflowContainerContextValue = _react.default.useMemo(
25
- () => ({
26
- visibleCount,
17
+ const _dev = require('../functions/dev.js');
18
+ const _useResizeObserver = require('../hooks/useResizeObserver.js');
19
+ const OverflowContainerMain = _react.default.forwardRef(
20
+ (props, forwardedRef) => {
21
+ let { itemsCount, children, overflowOrientation, ...rest } = props;
22
+ let [containerRef, visibleCount] = useOverflow(
27
23
  itemsCount,
28
- }),
29
- [itemsCount, visibleCount],
30
- );
31
- return _react.default.createElement(
32
- OverflowContainerContext.Provider,
33
- {
34
- value: overflowContainerContextValue,
35
- },
36
- _react.default.createElement(
37
- _Box.Box,
24
+ overflowOrientation,
25
+ );
26
+ let overflowContainerContextValue = _react.default.useMemo(
27
+ () => ({
28
+ visibleCount,
29
+ itemsCount,
30
+ }),
31
+ [itemsCount, visibleCount],
32
+ );
33
+ return _react.default.createElement(
34
+ OverflowContainerContext.Provider,
38
35
  {
39
- ref: (0, _useMergedRefs.useMergedRefs)(ref, containerRef),
40
- ...rest,
36
+ value: overflowContainerContextValue,
41
37
  },
42
- children,
43
- ),
44
- );
45
- });
38
+ _react.default.createElement(
39
+ _Box.Box,
40
+ {
41
+ ref: (0, _useMergedRefs.useMergedRefs)(forwardedRef, containerRef),
42
+ ...rest,
43
+ },
44
+ children,
45
+ ),
46
+ );
47
+ },
48
+ );
46
49
  const OverflowContainerOverflowNode = (props) => {
47
50
  let { children } = props;
48
51
  let { visibleCount, itemsCount } = useOverflowContainerContext();
49
52
  let isOverflowing = visibleCount < itemsCount;
50
53
  return isOverflowing ? children : null;
51
54
  };
55
+ const OverflowContainerComponent = _react.default.forwardRef(
56
+ (props, forwardedRef) => {
57
+ let { itemsCount, overflowOrientation = 'horizontal', ...rest } = props;
58
+ let [size, setSize] = _react.default.useState(null);
59
+ let [resizeRef] = (0, _useResizeObserver.useResizeObserver)(setSize);
60
+ let ref = (0, _useMergedRefs.useMergedRefs)(resizeRef, forwardedRef);
61
+ let key = `${itemsCount}${
62
+ 'vertical' === overflowOrientation ? size?.height : size?.width
63
+ }`;
64
+ return _react.default.createElement(OverflowContainerMain, {
65
+ ...rest,
66
+ key: key,
67
+ ref: ref,
68
+ itemsCount: itemsCount,
69
+ overflowOrientation: overflowOrientation,
70
+ });
71
+ },
72
+ );
52
73
  const OverflowContainer = Object.assign(OverflowContainerComponent, {
53
74
  OverflowNode: OverflowContainerOverflowNode,
54
75
  useContext: useOverflowContainerContext,
55
76
  });
56
77
  const OverflowContainerContext = _react.default.createContext(void 0);
57
78
  OverflowContainerContext.displayName = 'OverflowContainerContext';
79
+ const useOverflow = (itemsCount, orientation = 'horizontal') => {
80
+ let [guessState, dispatch] = _react.default.useReducer(
81
+ overflowGuessReducer,
82
+ {
83
+ itemsCount,
84
+ },
85
+ overflowGuessReducerInitialState,
86
+ );
87
+ let containerRef = _react.default.useRef(null);
88
+ let isGuessing = _react.default.useRef(false);
89
+ (0, _useIsomorphicLayoutEffect.useLayoutEffect)(() => {
90
+ let { minGuess, maxGuess, isStabilized, visibleCount } = guessState;
91
+ if (isStabilized) return;
92
+ guessVisibleCount();
93
+ function guessVisibleCount() {
94
+ if (isStabilized || isGuessing.current || _dev.isUnitTest) return;
95
+ try {
96
+ isGuessing.current = true;
97
+ if (null == containerRef.current) return;
98
+ let dimension = 'horizontal' === orientation ? 'Width' : 'Height';
99
+ let availableSize = containerRef.current[`offset${dimension}`];
100
+ let requiredSize = containerRef.current[`scroll${dimension}`];
101
+ let isOverflowing = availableSize < requiredSize;
102
+ if (
103
+ 0 === itemsCount ||
104
+ (1 === visibleCount && isOverflowing) ||
105
+ (visibleCount === itemsCount && !isOverflowing) ||
106
+ (maxGuess - minGuess === 1 && visibleCount === minGuess)
107
+ ) {
108
+ dispatch({
109
+ type: 'stabilize',
110
+ });
111
+ return;
112
+ }
113
+ if (maxGuess === visibleCount && !isOverflowing) {
114
+ dispatch({
115
+ type: 'shiftGuessRangeForward',
116
+ });
117
+ return;
118
+ }
119
+ isOverflowing
120
+ ? dispatch({
121
+ type: 'decreaseMaxGuess',
122
+ currentState: guessState,
123
+ })
124
+ : dispatch({
125
+ type: 'increaseMinGuess',
126
+ currentState: guessState,
127
+ });
128
+ } finally {
129
+ isGuessing.current = false;
130
+ }
131
+ }
132
+ }, [guessState, itemsCount, orientation]);
133
+ return [containerRef, guessState.visibleCount];
134
+ };
135
+ const STARTING_MAX_ITEMS_COUNT = 32;
136
+ const overflowGuessReducerInitialState = ({ itemsCount }) => {
137
+ let initialVisibleCount = Math.min(itemsCount, STARTING_MAX_ITEMS_COUNT);
138
+ return _dev.isUnitTest
139
+ ? {
140
+ isStabilized: true,
141
+ minGuess: null,
142
+ maxGuess: null,
143
+ itemsCount,
144
+ visibleCount: itemsCount,
145
+ }
146
+ : {
147
+ isStabilized: false,
148
+ minGuess: 0,
149
+ maxGuess: initialVisibleCount,
150
+ itemsCount,
151
+ visibleCount: initialVisibleCount,
152
+ };
153
+ };
154
+ const overflowGuessReducer = (state, action) => {
155
+ let getSafeVisibleCount = ({ visibleCount, itemsCount }) =>
156
+ Math.min(itemsCount, visibleCount);
157
+ switch (action.type) {
158
+ case 'decreaseMaxGuess':
159
+ case 'increaseMinGuess':
160
+ if (state.isStabilized) return state;
161
+ let newMinGuess = state.minGuess;
162
+ let newMaxGuess = state.maxGuess;
163
+ if ('decreaseMaxGuess' === action.type)
164
+ newMaxGuess = action.currentState.visibleCount;
165
+ else newMinGuess = action.currentState.visibleCount;
166
+ let newVisibleCount = Math.floor((newMinGuess + newMaxGuess) / 2);
167
+ return {
168
+ ...state,
169
+ isStabilized: false,
170
+ minGuess: newMinGuess,
171
+ maxGuess: newMaxGuess,
172
+ visibleCount: getSafeVisibleCount({
173
+ visibleCount: newVisibleCount,
174
+ itemsCount: state.itemsCount,
175
+ }),
176
+ };
177
+ case 'shiftGuessRangeForward':
178
+ if (state.isStabilized) return state;
179
+ let doubleOfMaxGuess = 2 * state.maxGuess;
180
+ return {
181
+ ...state,
182
+ isStabilized: false,
183
+ minGuess: state.maxGuess,
184
+ maxGuess: doubleOfMaxGuess,
185
+ visibleCount: getSafeVisibleCount({
186
+ visibleCount: doubleOfMaxGuess,
187
+ itemsCount: state.itemsCount,
188
+ }),
189
+ };
190
+ case 'stabilize':
191
+ return {
192
+ ...state,
193
+ isStabilized: true,
194
+ minGuess: null,
195
+ maxGuess: null,
196
+ };
197
+ default:
198
+ return state;
199
+ }
200
+ };
58
201
  function useOverflowContainerContext() {
59
202
  let overflowContainerContext = (0, _useSafeContext.useSafeContext)(
60
203
  OverflowContainerContext,
@@ -5,7 +5,6 @@ Object.defineProperty(exports, '__esModule', {
5
5
  const _export_star = require('@swc/helpers/_/_export_star');
6
6
  _export_star._(require('./useEventListener.js'), exports);
7
7
  _export_star._(require('./useMergedRefs.js'), exports);
8
- _export_star._(require('./useOverflow.js'), exports);
9
8
  _export_star._(require('./useResizeObserver.js'), exports);
10
9
  _export_star._(require('./useContainerWidth.js'), exports);
11
10
  _export_star._(require('./useGlobals.js'), exports);
@@ -19,4 +18,5 @@ _export_star._(require('./useId.js'), exports);
19
18
  _export_star._(require('./useControlledState.js'), exports);
20
19
  _export_star._(require('./useSyncExternalStore.js'), exports);
21
20
  _export_star._(require('./useVirtualScroll.js'), exports);
21
+ _export_star._(require('./useInstance.js'), exports);
22
22
  _export_star._(require('./useWarningLogger.js'), exports);
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+ Object.defineProperty(exports, '__esModule', {
3
+ value: true,
4
+ });
5
+ function _export(target, all) {
6
+ for (var name in all)
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name],
10
+ });
11
+ }
12
+ _export(exports, {
13
+ useInstance: function () {
14
+ return useInstance;
15
+ },
16
+ useSynchronizeInstance: function () {
17
+ return useSynchronizeInstance;
18
+ },
19
+ });
20
+ const _interop_require_wildcard = require('@swc/helpers/_/_interop_require_wildcard');
21
+ const _react = _interop_require_wildcard._(require('react'));
22
+ const _useSyncExternalStore = require('./useSyncExternalStore.js');
23
+ class Instance {}
24
+ const useInstance = () => _react.useMemo(() => new Instance(), []);
25
+ const useSynchronizeInstance = (instance, properties) => {
26
+ let synchronize = _react.useCallback(() => {
27
+ if (!(instance instanceof Instance)) return () => {};
28
+ Object.assign(instance, properties);
29
+ return () => {
30
+ for (let key in properties) delete instance[key];
31
+ };
32
+ }, [instance, properties]);
33
+ return (0, _useSyncExternalStore.useSyncExternalStore)(
34
+ synchronize,
35
+ () => instance,
36
+ () => instance,
37
+ );
38
+ };
@@ -8,7 +8,7 @@ import {
8
8
  } from '../../utils/index.js';
9
9
  import { Button } from '../Buttons/Button.js';
10
10
  import { Anchor } from '../Typography/Anchor.js';
11
- let BreadcrumbsComponent = React.forwardRef((props, ref) => {
11
+ let BreadcrumbsComponent = React.forwardRef((props, forwardedRef) => {
12
12
  let {
13
13
  children: childrenProp,
14
14
  currentIndex = React.Children.count(childrenProp) - 1,
@@ -26,7 +26,7 @@ let BreadcrumbsComponent = React.forwardRef((props, ref) => {
26
26
  {
27
27
  as: 'nav',
28
28
  className: cx('iui-breadcrumbs', className),
29
- ref: ref,
29
+ ref: forwardedRef,
30
30
  'aria-label': 'Breadcrumb',
31
31
  ...rest,
32
32
  },