@primer/react 38.46.0-rc.18db27ff8 → 38.46.0-rc.3e370923f

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 (36) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/ActionList/LinkItem.js +97 -30
  3. package/dist/Breadcrumbs/{Breadcrumbs-16d81430.css → Breadcrumbs-6c9aadcf.css} +2 -2
  4. package/dist/Breadcrumbs/Breadcrumbs-6c9aadcf.css.map +1 -0
  5. package/dist/Breadcrumbs/Breadcrumbs.js +403 -391
  6. package/dist/Breadcrumbs/Breadcrumbs.module.css.js +1 -1
  7. package/dist/Card/Card-0e84ee3c.css +2 -0
  8. package/dist/Card/Card-0e84ee3c.css.map +1 -0
  9. package/dist/Card/Card.d.ts +13 -3
  10. package/dist/Card/Card.js +286 -161
  11. package/dist/Card/Card.module.css.js +2 -1
  12. package/dist/Card/index.d.ts +13 -3
  13. package/dist/Card/index.js +3 -1
  14. package/dist/ProgressBar/ProgressBar-3d1db6c7.css +2 -0
  15. package/dist/ProgressBar/ProgressBar-3d1db6c7.css.map +1 -0
  16. package/dist/ProgressBar/ProgressBar.module.css.js +1 -1
  17. package/dist/Skeleton/skeleton-bdbe6bf2.css +2 -0
  18. package/dist/Skeleton/skeleton-bdbe6bf2.css.map +1 -0
  19. package/dist/Skeleton/skeleton.module.css.js +1 -1
  20. package/dist/TooltipV2/Tooltip.js +55 -51
  21. package/dist/TreeView/TreeView.js +29 -15
  22. package/dist/TreeView/useTreeRovingTabIndex.js +155 -0
  23. package/dist/experimental/index.d.ts +2 -2
  24. package/dist/hooks/useOnEscapePress.d.ts +2 -0
  25. package/dist/hooks/useOnEscapePress.js +11 -4
  26. package/dist/hooks/useOnOutsideClick.js +2 -1
  27. package/dist/index.js +1 -1
  28. package/generated/components.json +82 -3
  29. package/package.json +8 -8
  30. package/dist/Breadcrumbs/Breadcrumbs-16d81430.css.map +0 -1
  31. package/dist/Card/Card-59b77d05.css +0 -2
  32. package/dist/Card/Card-59b77d05.css.map +0 -1
  33. package/dist/ProgressBar/ProgressBar-e403d83d.css +0 -2
  34. package/dist/ProgressBar/ProgressBar-e403d83d.css.map +0 -1
  35. package/dist/Skeleton/skeleton-27888827.css +0 -2
  36. package/dist/Skeleton/skeleton-27888827.css.map +0 -1
@@ -7,446 +7,467 @@ import { fixedForwardRef } from "../utils/modern-polymorphic.js";
7
7
  import { IconButton } from "../Button/IconButton.js";
8
8
  import { ActionList } from "../ActionList/index.js";
9
9
  import Breadcrumbs_module_css_default from "./Breadcrumbs.module.css.js";
10
- import Details from "../Details/Details.js";
11
10
  import React, { useRef, useState } from "react";
12
11
  import { jsx, jsxs } from "react/jsx-runtime";
13
12
  import { clsx } from "clsx";
14
13
  import { KebabHorizontalIcon } from "@primer/octicons-react";
15
14
  //#region src/Breadcrumbs/Breadcrumbs.tsx
16
- const BreadcrumbsList = (t0) => {
17
- const $ = c(2);
18
- const { children } = t0;
15
+ const MENU_BUTTON_WIDTH = 32;
16
+ const SEPARATOR_ICON_WIDTH = 16;
17
+ const NARROW_WIDTH = 544;
18
+ const INITIAL_FIT = {
19
+ extra: 0,
20
+ rootCollapsed: false,
21
+ narrow: false
22
+ };
23
+ function minVisible(withRoot, narrow, itemCount) {
24
+ if (withRoot) return 3;
25
+ return narrow && itemCount > 2 ? 1 : 4;
26
+ }
27
+ function countRule(withRoot, narrow, itemCount) {
28
+ return Math.max(0, itemCount - minVisible(withRoot, narrow, itemCount));
29
+ }
30
+ const INITIAL_SEPARATORS = {
31
+ plain: SEPARATOR_ICON_WIDTH,
32
+ collapsed: SEPARATOR_ICON_WIDTH
33
+ };
34
+ function computeFit(widths, separators, available, withRoot) {
35
+ const itemCount = widths.length;
36
+ if (available <= 0 || itemCount === 0) return INITIAL_FIT;
37
+ const narrow = available < NARROW_WIDTH;
38
+ const min = minVisible(withRoot, narrow, itemCount);
39
+ const rootWidth = withRoot ? widths[0] + separators.collapsed : 0;
40
+ const menuCount = (collapsed) => Math.max(0, collapsed - (withRoot ? 1 : 0));
41
+ let tailWidth = widths.reduce((sum, width) => sum + width + separators.collapsed, 0);
42
+ const total = widths.reduce((sum, width) => sum + width, 0);
43
+ const width = (collapsed) => menuCount(collapsed) === 0 ? total + separators.plain * (itemCount - 1) : rootWidth + tailWidth + MENU_BUTTON_WIDTH;
44
+ let collapsed = 0;
45
+ let rootCollapsed = false;
46
+ while (width(collapsed) > available || itemCount - collapsed > min) {
47
+ tailWidth -= widths[collapsed] + separators.collapsed;
48
+ collapsed += 1;
49
+ if (itemCount - collapsed === 1 && width(collapsed) > available) {
50
+ rootCollapsed = withRoot;
51
+ break;
52
+ }
53
+ }
54
+ return {
55
+ extra: collapsed - countRule(withRoot, narrow, itemCount),
56
+ rootCollapsed,
57
+ narrow
58
+ };
59
+ }
60
+ function getContentWidth(nav) {
61
+ const { paddingLeft, paddingRight } = getComputedStyle(nav);
62
+ return nav.clientWidth - parseFloat(paddingLeft) - parseFloat(paddingRight);
63
+ }
64
+ const sameFit = (a, b) => a.extra === b.extra && a.rootCollapsed === b.rootCollapsed && a.narrow === b.narrow;
65
+ function getValidChildren(children) {
66
+ return React.Children.toArray(children).filter((child) => /*#__PURE__*/ React.isValidElement(child));
67
+ }
68
+ function OverflowMenu(t0) {
69
+ const $ = c(15);
70
+ const { items, open, setOpen } = t0;
71
+ const buttonRef = useRef(null);
19
72
  let t1;
20
- if ($[0] !== children) {
21
- t1 = /* @__PURE__ */ jsx("ol", {
22
- className: Breadcrumbs_module_css_default.BreadcrumbsList,
23
- children
24
- });
25
- $[0] = children;
73
+ if ($[0] !== setOpen) {
74
+ t1 = () => setOpen(false);
75
+ $[0] = setOpen;
26
76
  $[1] = t1;
27
77
  } else t1 = $[1];
28
- return t1;
29
- };
30
- const BreadcrumbsMenuItem = /*#__PURE__*/ React.forwardRef((t0, menuRefCallback) => {
31
- const $ = c(25);
32
- let ariaLabel;
33
- let items;
34
- let rest;
35
- if ($[0] !== t0) {
36
- ({items, "aria-label": ariaLabel, ...rest} = t0);
37
- $[0] = t0;
38
- $[1] = ariaLabel;
39
- $[2] = items;
40
- $[3] = rest;
41
- } else {
42
- ariaLabel = $[1];
43
- items = $[2];
44
- rest = $[3];
45
- }
46
- const [isOpen, setIsOpen] = useState(false);
47
- const detailsRef = useRef(null);
48
- const menuButtonRef = useRef(null);
49
- const menuContainerRef = useRef(null);
78
+ const close = t1;
79
+ const t2 = `${items.length} more breadcrumb items`;
80
+ let t3;
81
+ if ($[2] !== setOpen) {
82
+ t3 = () => setOpen(_temp);
83
+ $[2] = setOpen;
84
+ $[3] = t3;
85
+ } else t3 = $[3];
86
+ let t4;
87
+ if ($[4] !== open || $[5] !== t2 || $[6] !== t3) {
88
+ t4 = /* @__PURE__ */ jsx(IconButton, {
89
+ ref: buttonRef,
90
+ "aria-label": t2,
91
+ "aria-haspopup": "true",
92
+ "aria-expanded": open,
93
+ onClick: t3,
94
+ variant: "invisible",
95
+ size: "small",
96
+ icon: KebabHorizontalIcon,
97
+ tooltipDirection: "e"
98
+ });
99
+ $[4] = open;
100
+ $[5] = t2;
101
+ $[6] = t3;
102
+ $[7] = t4;
103
+ } else t4 = $[7];
104
+ let t5;
105
+ if ($[8] !== close || $[9] !== items || $[10] !== open) {
106
+ t5 = open ? /* @__PURE__ */ jsx(OverflowMenuOverlay, {
107
+ items,
108
+ close,
109
+ buttonRef
110
+ }) : null;
111
+ $[8] = close;
112
+ $[9] = items;
113
+ $[10] = open;
114
+ $[11] = t5;
115
+ } else t5 = $[11];
116
+ let t6;
117
+ if ($[12] !== t4 || $[13] !== t5) {
118
+ t6 = /* @__PURE__ */ jsxs("div", {
119
+ className: Breadcrumbs_module_css_default.MenuDetails,
120
+ "data-component": "Breadcrumbs.MenuItem",
121
+ children: [t4, t5]
122
+ });
123
+ $[12] = t4;
124
+ $[13] = t5;
125
+ $[14] = t6;
126
+ } else t6 = $[14];
127
+ return t6;
128
+ }
129
+ function _temp(value) {
130
+ return !value;
131
+ }
132
+ function OverflowMenuOverlay(t0) {
133
+ const $ = c(13);
134
+ const { items, close, buttonRef } = t0;
135
+ const containerRef = useRef(null);
50
136
  let t1;
51
- if ($[4] !== menuRefCallback) {
52
- t1 = (element) => {
53
- detailsRef.current = element;
54
- if (typeof menuRefCallback === "function") menuRefCallback(element);
55
- };
56
- $[4] = menuRefCallback;
57
- $[5] = t1;
58
- } else t1 = $[5];
59
- const detailsRefCallback = t1;
60
137
  let t2;
61
- if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
62
- t2 = (event) => {
138
+ if ($[0] !== buttonRef || $[1] !== close) {
139
+ t1 = (event) => {
140
+ var _buttonRef$current;
63
141
  event.preventDefault();
64
- if (detailsRef.current) {
65
- const newOpenState = !detailsRef.current.open;
66
- detailsRef.current.open = newOpenState;
67
- setIsOpen(newOpenState);
68
- }
142
+ close();
143
+ (_buttonRef$current = buttonRef.current) === null || _buttonRef$current === void 0 || _buttonRef$current.focus();
69
144
  };
70
- $[6] = t2;
71
- } else t2 = $[6];
72
- const handleSummaryClick = t2;
145
+ t2 = [close, buttonRef];
146
+ $[0] = buttonRef;
147
+ $[1] = close;
148
+ $[2] = t1;
149
+ $[3] = t2;
150
+ } else {
151
+ t1 = $[2];
152
+ t2 = $[3];
153
+ }
154
+ useOnEscapePress(t1, t2);
73
155
  let t3;
74
- if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
75
- t3 = () => {
76
- if (detailsRef.current) {
77
- detailsRef.current.open = false;
78
- setIsOpen(false);
79
- }
80
- };
81
- $[7] = t3;
82
- } else t3 = $[7];
83
- const closeOverlay = t3;
156
+ if ($[4] !== buttonRef) {
157
+ t3 = [buttonRef];
158
+ $[4] = buttonRef;
159
+ $[5] = t3;
160
+ } else t3 = $[5];
84
161
  let t4;
85
- if ($[8] === Symbol.for("react.memo_cache_sentinel")) {
86
- t4 = () => {
87
- var _menuButtonRef$curren;
88
- (_menuButtonRef$curren = menuButtonRef.current) === null || _menuButtonRef$curren === void 0 || _menuButtonRef$curren.focus();
162
+ if ($[6] !== close || $[7] !== t3) {
163
+ t4 = {
164
+ onClickOutside: close,
165
+ containerRef,
166
+ ignoreClickRefs: t3
89
167
  };
168
+ $[6] = close;
169
+ $[7] = t3;
90
170
  $[8] = t4;
91
171
  } else t4 = $[8];
92
- const focusOnMenuButton = t4;
172
+ useOnOutsideClick(t4);
93
173
  let t5;
94
- let t6;
95
- if ($[9] !== isOpen) {
96
- t5 = (event_0) => {
97
- if (isOpen) {
98
- event_0.preventDefault();
99
- closeOverlay();
100
- focusOnMenuButton();
101
- }
102
- };
103
- t6 = [isOpen];
104
- $[9] = isOpen;
174
+ if ($[9] !== items) {
175
+ t5 = items.map(_temp2);
176
+ $[9] = items;
105
177
  $[10] = t5;
106
- $[11] = t6;
107
- } else {
108
- t5 = $[10];
109
- t6 = $[11];
110
- }
111
- useOnEscapePress(t5, t6);
112
- let t7;
113
- if ($[12] === Symbol.for("react.memo_cache_sentinel")) {
114
- t7 = {
115
- onClickOutside: closeOverlay,
116
- containerRef: menuContainerRef,
117
- ignoreClickRefs: [menuButtonRef]
118
- };
119
- $[12] = t7;
120
- } else t7 = $[12];
121
- useOnOutsideClick(t7);
122
- const t8 = ariaLabel || `${items.length} more breadcrumb items`;
123
- const t9 = isOpen ? "true" : "false";
124
- let t10;
125
- if ($[13] !== rest || $[14] !== t8 || $[15] !== t9) {
126
- t10 = /* @__PURE__ */ jsx(IconButton, {
127
- as: "summary",
128
- role: "button",
129
- ref: menuButtonRef,
130
- "aria-label": t8,
131
- "aria-expanded": t9,
132
- onClick: handleSummaryClick,
133
- variant: "invisible",
134
- size: "small",
135
- icon: KebabHorizontalIcon,
136
- tooltipDirection: "e",
137
- ...rest
138
- });
139
- $[13] = rest;
140
- $[14] = t8;
141
- $[15] = t9;
142
- $[16] = t10;
143
- } else t10 = $[16];
144
- let t11;
145
- if ($[17] !== items) {
146
- t11 = items.map(_temp);
147
- $[17] = items;
148
- $[18] = t11;
149
- } else t11 = $[18];
150
- let t12;
151
- if ($[19] !== t11) {
152
- t12 = /* @__PURE__ */ jsx("div", {
153
- ref: menuContainerRef,
178
+ } else t5 = $[10];
179
+ let t6;
180
+ if ($[11] !== t5) {
181
+ t6 = /* @__PURE__ */ jsx("div", {
182
+ ref: containerRef,
154
183
  className: Breadcrumbs_module_css_default.MenuOverlay,
155
- children: /* @__PURE__ */ jsx(ActionList, { children: t11 })
184
+ children: /* @__PURE__ */ jsx(ActionList, { children: t5 })
156
185
  });
157
- $[19] = t11;
158
- $[20] = t12;
159
- } else t12 = $[20];
160
- let t13;
161
- if ($[21] !== detailsRefCallback || $[22] !== t10 || $[23] !== t12) {
162
- t13 = /* @__PURE__ */ jsxs(Details, {
163
- ref: detailsRefCallback,
164
- className: Breadcrumbs_module_css_default.MenuDetails,
165
- "data-component": "Breadcrumbs.MenuItem",
166
- children: [t10, t12]
167
- });
168
- $[21] = detailsRefCallback;
169
- $[22] = t10;
170
- $[23] = t12;
171
- $[24] = t13;
172
- } else t13 = $[24];
173
- return t13;
174
- });
175
- BreadcrumbsMenuItem.displayName = "Breadcrumbs.MenuItem";
176
- const getValidChildren = (children) => {
177
- return React.Children.toArray(children).filter((child) => /*#__PURE__*/ React.isValidElement(child));
178
- };
179
- const MENU_BUTTON_FALLBACK_WIDTH = 32;
180
- const CONTAINER_FALLBACK_WIDTH = 800;
181
- function calculateOverflow({ availableWidth, itemCount, childArrayWidths, menuButtonWidth, overflow, hideRoot }) {
182
- var _childArrayWidths$;
183
- let eHideRoot = hideRoot;
184
- const rootItemWidth = (_childArrayWidths$ = childArrayWidths[0]) !== null && _childArrayWidths$ !== void 0 ? _childArrayWidths$ : 0;
185
- const isNarrow = availableWidth < 544;
186
- let MIN_VISIBLE_ITEMS = 4;
187
- if (!eHideRoot) MIN_VISIBLE_ITEMS = 3;
188
- else if (isNarrow && itemCount > 2) MIN_VISIBLE_ITEMS = 1;
189
- const calculateVisibleItemsWidth = (w) => {
190
- const widths = w.reduce((sum, width) => sum + width + 16, 0);
191
- return !eHideRoot ? rootItemWidth + widths : widths;
192
- };
193
- let currentVisibleItemWidths = [...childArrayWidths];
194
- let menuItemCount = 0;
195
- if (availableWidth > 0 && currentVisibleItemWidths.length > 0) {
196
- let visibleItemsWidthTotal = calculateVisibleItemsWidth(currentVisibleItemWidths);
197
- while ((overflow === "menu" || overflow === "menu-with-root") && (visibleItemsWidthTotal > availableWidth || currentVisibleItemWidths.length > MIN_VISIBLE_ITEMS)) {
198
- menuItemCount += 1;
199
- currentVisibleItemWidths = currentVisibleItemWidths.slice(1);
200
- visibleItemsWidthTotal = calculateVisibleItemsWidth(currentVisibleItemWidths) + menuButtonWidth;
201
- if (currentVisibleItemWidths.length === 1 && visibleItemsWidthTotal > availableWidth) {
202
- eHideRoot = true;
203
- break;
204
- } else eHideRoot = hideRoot;
205
- }
206
- }
207
- return {
208
- menuItemCount,
209
- effectiveHideRoot: eHideRoot
210
- };
186
+ $[11] = t5;
187
+ $[12] = t6;
188
+ } else t6 = $[12];
189
+ return t6;
190
+ }
191
+ function _temp2(item) {
192
+ const { children, selected, as: Component, ...itemProps } = item.props;
193
+ return /* @__PURE__ */ jsx(ActionList.LinkItem, {
194
+ as: Component,
195
+ ...itemProps,
196
+ "aria-current": selected ? "page" : void 0,
197
+ children
198
+ }, item.key);
211
199
  }
212
200
  function Breadcrumbs(t0) {
213
- const $ = c(48);
201
+ const $ = c(60);
214
202
  const { className, children, style, overflow: t1, variant: t2 } = t0;
215
203
  const overflow = t1 === void 0 ? "wrap" : t1;
216
204
  const variant = t2 === void 0 ? "normal" : t2;
217
- const containerRef = useRef(null);
218
- const hideRoot = !(overflow === "menu-with-root");
205
+ const navRef = useRef(null);
219
206
  let t3;
220
- if ($[0] !== children) {
221
- t3 = getValidChildren(children);
222
- $[0] = children;
223
- $[1] = t3;
224
- } else t3 = $[1];
225
- const childArray = t3;
226
- const rootItem = childArray[0];
227
- const [childArrayWidths, setChildArrayWidths] = useState(_temp2);
228
- const [containerWidth, setContainerWidth] = useState(null);
229
- const [menuButtonWidth, setMenuButtonWidth] = useState(MENU_BUTTON_FALLBACK_WIDTH);
207
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
208
+ t3 = /* @__PURE__ */ new Map();
209
+ $[0] = t3;
210
+ } else t3 = $[0];
211
+ const widthsRef = useRef(t3);
212
+ const [fit, setFit] = useState(INITIAL_FIT);
213
+ const fitRef = useRef(INITIAL_FIT);
214
+ const separatorsRef = useRef(INITIAL_SEPARATORS);
215
+ const [menuOpen, setMenuOpen] = useState(false);
216
+ const collapsible = overflow !== "wrap";
217
+ const withRoot = overflow === "menu-with-root";
230
218
  let t4;
231
- if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
232
- t4 = (element) => {
233
- if (element) {
234
- const iconButtonElement = element.querySelector("button[data-component=\"IconButton\"]");
235
- if (iconButtonElement) {
236
- const measuredWidth = iconButtonElement.offsetWidth;
237
- setMenuButtonWidth((prev) => prev === measuredWidth ? prev : measuredWidth);
238
- }
239
- }
240
- };
219
+ if ($[1] !== children) {
220
+ t4 = getValidChildren(children);
221
+ $[1] = children;
241
222
  $[2] = t4;
242
223
  } else t4 = $[2];
243
- const measureMenuButton = t4;
224
+ const items = t4;
225
+ const itemCount = items.length;
244
226
  let t5;
245
- if ($[3] !== childArray.length || $[4] !== overflow) {
246
- t5 = () => {
247
- if (overflow === "wrap") return;
248
- const containerElement = containerRef.current;
249
- if (!containerElement) return;
250
- const measuredContainerWidth = containerElement.offsetWidth;
251
- setContainerWidth((prev_0) => prev_0 === measuredContainerWidth ? prev_0 : measuredContainerWidth);
252
- const listElement = containerElement.querySelector("ol");
253
- if (listElement && listElement.children.length > 0 && listElement.children.length === childArray.length) {
254
- const widths = Array.from(listElement.children).map(_temp3);
255
- setChildArrayWidths(widths);
256
- }
227
+ if ($[3] !== items || $[4] !== withRoot) {
228
+ t5 = (available) => {
229
+ const next = computeFit(items.map((item) => {
230
+ var _widthsRef$current$ge, _item$key;
231
+ return (_widthsRef$current$ge = widthsRef.current.get((_item$key = item.key) !== null && _item$key !== void 0 ? _item$key : "")) !== null && _widthsRef$current$ge !== void 0 ? _widthsRef$current$ge : 0;
232
+ }), separatorsRef.current, available, withRoot);
233
+ if (sameFit(fitRef.current, next)) return;
234
+ fitRef.current = next;
235
+ setFit(next);
257
236
  };
258
- $[3] = childArray.length;
259
- $[4] = overflow;
237
+ $[3] = items;
238
+ $[4] = withRoot;
260
239
  $[5] = t5;
261
240
  } else t5 = $[5];
241
+ const updateFit = t5;
262
242
  let t6;
263
- if ($[6] !== childArray || $[7] !== overflow) {
264
- t6 = [childArray, overflow];
265
- $[6] = childArray;
266
- $[7] = overflow;
243
+ if ($[6] !== items || $[7] !== updateFit) {
244
+ t6 = (nav, available_0) => {
245
+ const previous = widthsRef.current;
246
+ const widths_0 = /* @__PURE__ */ new Map();
247
+ let separators = separatorsRef.current;
248
+ for (const item_0 of items) {
249
+ var _item_0$key;
250
+ const width = previous.get((_item_0$key = item_0.key) !== null && _item_0$key !== void 0 ? _item_0$key : "");
251
+ if (width !== void 0) {
252
+ var _item_0$key2;
253
+ widths_0.set((_item_0$key2 = item_0.key) !== null && _item_0$key2 !== void 0 ? _item_0$key2 : "", width);
254
+ }
255
+ }
256
+ for (const li of nav.querySelectorAll(":scope > ol > li[data-index]")) {
257
+ var _items$Number;
258
+ const key = (_items$Number = items[Number(li.getAttribute("data-index"))]) === null || _items$Number === void 0 ? void 0 : _items$Number.key;
259
+ const crumb = li.firstElementChild;
260
+ if (key == null || !crumb) continue;
261
+ const crumbWidth = crumb.getBoundingClientRect().width;
262
+ widths_0.set(key, crumbWidth);
263
+ if (li.nextElementSibling && !li.hasAttribute("data-collapsed")) {
264
+ const separator = li.getBoundingClientRect().width - crumbWidth;
265
+ const kind = li.classList.contains(Breadcrumbs_module_css_default.ItemWrapper) ? "plain" : "collapsed";
266
+ if (separators[kind] !== separator) separators = {
267
+ ...separators,
268
+ [kind]: separator
269
+ };
270
+ }
271
+ }
272
+ separatorsRef.current = separators;
273
+ widthsRef.current = widths_0;
274
+ updateFit(available_0);
275
+ };
276
+ $[6] = items;
277
+ $[7] = updateFit;
267
278
  $[8] = t6;
268
279
  } else t6 = $[8];
269
- useIsomorphicLayoutEffect(t5, t6);
280
+ const measure = t6;
281
+ const hiddenRef = useRef(false);
270
282
  let t7;
271
- if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
272
- t7 = (entries) => {
273
- if (entries[0]) {
274
- const width = Math.round(entries[0].contentRect.width);
275
- setContainerWidth((prev_1) => prev_1 === width ? prev_1 : width);
276
- }
283
+ if ($[9] !== collapsible || $[10] !== measure) {
284
+ t7 = () => {
285
+ const nav_0 = navRef.current;
286
+ if (!collapsible || !nav_0) return;
287
+ if (!nav_0.hasAttribute("data-hydrated")) nav_0.setAttribute("data-hydrated", "");
288
+ const available_1 = getContentWidth(nav_0);
289
+ hiddenRef.current = available_1 <= 0;
290
+ if (!hiddenRef.current) measure(nav_0, available_1);
277
291
  };
278
- $[9] = t7;
279
- } else t7 = $[9];
292
+ $[9] = collapsible;
293
+ $[10] = measure;
294
+ $[11] = t7;
295
+ } else t7 = $[11];
280
296
  let t8;
281
- if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
282
- t8 = [];
283
- $[10] = t8;
284
- } else t8 = $[10];
285
- useResizeObserver(t7, containerRef, t8, overflow !== "wrap");
297
+ if ($[12] !== collapsible || $[13] !== fit || $[14] !== measure || $[15] !== menuOpen) {
298
+ t8 = [
299
+ collapsible,
300
+ fit,
301
+ menuOpen,
302
+ measure
303
+ ];
304
+ $[12] = collapsible;
305
+ $[13] = fit;
306
+ $[14] = measure;
307
+ $[15] = menuOpen;
308
+ $[16] = t8;
309
+ } else t8 = $[16];
310
+ useIsomorphicLayoutEffect(t7, t8);
286
311
  let t9;
287
- bb0: {
288
- if (overflow === "wrap" || childArrayWidths.length !== childArray.length) {
289
- let t10;
290
- if ($[11] !== hideRoot) {
291
- t10 = {
292
- menuItemCount: 0,
293
- effectiveHideRoot: hideRoot
294
- };
295
- $[11] = hideRoot;
296
- $[12] = t10;
297
- } else t10 = $[12];
298
- t9 = t10;
299
- break bb0;
300
- }
301
- const t10 = containerWidth !== null && containerWidth !== void 0 ? containerWidth : CONTAINER_FALLBACK_WIDTH;
302
- let t11;
303
- if ($[13] !== childArray.length || $[14] !== childArrayWidths || $[15] !== hideRoot || $[16] !== menuButtonWidth || $[17] !== overflow || $[18] !== t10) {
304
- t11 = calculateOverflow({
305
- availableWidth: t10,
306
- itemCount: childArray.length,
307
- childArrayWidths,
308
- menuButtonWidth,
309
- overflow,
310
- hideRoot
311
- });
312
- $[13] = childArray.length;
313
- $[14] = childArrayWidths;
314
- $[15] = hideRoot;
315
- $[16] = menuButtonWidth;
316
- $[17] = overflow;
317
- $[18] = t10;
318
- $[19] = t11;
319
- } else t11 = $[19];
320
- t9 = t11;
321
- }
322
- const { menuItemCount, effectiveHideRoot } = t9;
312
+ if ($[17] !== measure || $[18] !== updateFit) {
313
+ t9 = () => {
314
+ const nav_1 = navRef.current;
315
+ if (!nav_1) return;
316
+ const available_2 = getContentWidth(nav_1);
317
+ if (available_2 <= 0) hiddenRef.current = true;
318
+ else if (hiddenRef.current) {
319
+ hiddenRef.current = false;
320
+ measure(nav_1, available_2);
321
+ } else updateFit(available_2);
322
+ };
323
+ $[17] = measure;
324
+ $[18] = updateFit;
325
+ $[19] = t9;
326
+ } else t9 = $[19];
323
327
  let t10;
324
- if ($[20] !== childArray || $[21] !== children || $[22] !== effectiveHideRoot || $[23] !== menuItemCount || $[24] !== overflow || $[25] !== rootItem) {
325
- bb1: {
326
- if (overflow === "wrap" || menuItemCount === 0) {
327
- let t11;
328
- if ($[27] !== children) {
329
- t11 = React.Children.map(children, _temp4);
330
- $[27] = children;
331
- $[28] = t11;
332
- } else t11 = $[28];
333
- t10 = t11;
334
- break bb1;
328
+ if ($[20] === Symbol.for("react.memo_cache_sentinel")) {
329
+ t10 = [];
330
+ $[20] = t10;
331
+ } else t10 = $[20];
332
+ useResizeObserver(t9, navRef, t10, collapsible);
333
+ let content;
334
+ if (!collapsible) {
335
+ if (menuOpen) setMenuOpen(false);
336
+ let t11;
337
+ if ($[21] !== children) {
338
+ t11 = React.Children.map(children, _temp3);
339
+ $[21] = children;
340
+ $[22] = t11;
341
+ } else t11 = $[22];
342
+ content = t11;
343
+ } else {
344
+ const collapsed = Math.min(Math.max(itemCount - 1, 0), countRule(withRoot, fit.narrow, itemCount) + fit.extra);
345
+ const rootVisible = withRoot && !(collapsed > 0 && fit.rootCollapsed);
346
+ let t11;
347
+ if ($[23] !== collapsed || $[24] !== items || $[25] !== rootVisible) {
348
+ t11 = items.slice(rootVisible ? 1 : 0, collapsed);
349
+ $[23] = collapsed;
350
+ $[24] = items;
351
+ $[25] = rootVisible;
352
+ $[26] = t11;
353
+ } else t11 = $[26];
354
+ const menuItems = t11;
355
+ if (menuOpen && menuItems.length === 0) setMenuOpen(false);
356
+ const plain = menuItems.length === 0;
357
+ const alwaysCollapsed = countRule(withRoot, false, itemCount);
358
+ let listItems;
359
+ if ($[27] !== alwaysCollapsed || $[28] !== collapsed || $[29] !== itemCount || $[30] !== items || $[31] !== menuItems || $[32] !== menuOpen || $[33] !== plain || $[34] !== rootVisible || $[35] !== withRoot) {
360
+ listItems = [];
361
+ for (const [index, item_1] of items.entries()) {
362
+ const isRoot = withRoot && index === 0;
363
+ const isCollapsed = index < collapsed && !(isRoot && rootVisible);
364
+ if (isCollapsed && index < alwaysCollapsed && !isRoot) continue;
365
+ const rendered = !isCollapsed || !menuOpen;
366
+ listItems.push(/* @__PURE__ */ jsxs("li", {
367
+ className: plain ? Breadcrumbs_module_css_default.ItemWrapper : Breadcrumbs_module_css_default.BreadcrumbsItem,
368
+ "data-index": rendered ? index : void 0,
369
+ "data-collapsed": isCollapsed ? "" : void 0,
370
+ children: [rendered ? item_1 : null, plain ? null : /* @__PURE__ */ jsx(ItemSeparator, {})]
371
+ }, item_1.key));
335
372
  }
336
- const menuItems = childArray.slice(0, menuItemCount);
337
- const visibleItems = childArray.slice(menuItemCount);
338
- const effectiveMenuItems = effectiveHideRoot ? menuItems : menuItems.slice(1);
339
- const t11 = `${effectiveMenuItems.length} more breadcrumb items`;
340
- let t12;
341
- if ($[29] !== effectiveMenuItems || $[30] !== t11) {
342
- t12 = /* @__PURE__ */ jsx(BreadcrumbsMenuItem, {
343
- ref: measureMenuButton,
344
- items: effectiveMenuItems,
345
- "aria-label": t11
346
- });
347
- $[29] = effectiveMenuItems;
348
- $[30] = t11;
349
- $[31] = t12;
350
- } else t12 = $[31];
351
- let t13;
352
- if ($[32] === Symbol.for("react.memo_cache_sentinel")) {
353
- t13 = /* @__PURE__ */ jsx(ItemSeparator, {});
354
- $[32] = t13;
355
- } else t13 = $[32];
356
- let t14;
357
- if ($[33] !== t12) {
358
- t14 = /* @__PURE__ */ jsxs("li", {
359
- className: Breadcrumbs_module_css_default.BreadcrumbsItem,
360
- "data-overflow-menu": "",
361
- children: [t12, t13]
362
- }, "breadcrumbs-menu");
363
- $[33] = t12;
364
- $[34] = t14;
365
- } else t14 = $[34];
366
- const menuElement = t14;
367
- const visibleElements = visibleItems.map(_temp5);
368
- let t15;
369
- if ($[35] === Symbol.for("react.memo_cache_sentinel")) {
370
- t15 = /* @__PURE__ */ jsx(ItemSeparator, {});
371
- $[35] = t15;
372
- } else t15 = $[35];
373
- let t16;
374
- if ($[36] !== rootItem) {
375
- t16 = /* @__PURE__ */ jsxs("li", {
376
- className: Breadcrumbs_module_css_default.BreadcrumbsItem,
377
- children: [rootItem, t15]
378
- }, "rootElement");
379
- $[36] = rootItem;
380
- $[37] = t16;
381
- } else t16 = $[37];
382
- const rootElement = t16;
383
- if (effectiveHideRoot) t10 = [menuElement, ...visibleElements];
384
- else t10 = [
385
- rootElement,
386
- menuElement,
387
- ...visibleElements
388
- ];
389
- }
390
- $[20] = childArray;
391
- $[21] = children;
392
- $[22] = effectiveHideRoot;
393
- $[23] = menuItemCount;
394
- $[24] = overflow;
395
- $[25] = rootItem;
396
- $[26] = t10;
397
- } else t10 = $[26];
398
- const finalChildren = t10;
373
+ if (!plain || !withRoot && itemCount > 2) {
374
+ let t12;
375
+ if ($[37] !== itemCount || $[38] !== items || $[39] !== menuItems || $[40] !== plain) {
376
+ t12 = plain ? items.slice(0, itemCount - 1) : menuItems;
377
+ $[37] = itemCount;
378
+ $[38] = items;
379
+ $[39] = menuItems;
380
+ $[40] = plain;
381
+ $[41] = t12;
382
+ } else t12 = $[41];
383
+ let t13;
384
+ if ($[42] !== menuOpen || $[43] !== t12) {
385
+ t13 = /* @__PURE__ */ jsx(OverflowMenu, {
386
+ items: t12,
387
+ open: menuOpen,
388
+ setOpen: setMenuOpen
389
+ });
390
+ $[42] = menuOpen;
391
+ $[43] = t12;
392
+ $[44] = t13;
393
+ } else t13 = $[44];
394
+ let t14;
395
+ if ($[45] === Symbol.for("react.memo_cache_sentinel")) {
396
+ t14 = /* @__PURE__ */ jsx(ItemSeparator, {});
397
+ $[45] = t14;
398
+ } else t14 = $[45];
399
+ let t15;
400
+ if ($[46] !== plain || $[47] !== t13) {
401
+ t15 = /* @__PURE__ */ jsxs("li", {
402
+ className: Breadcrumbs_module_css_default.BreadcrumbsItem,
403
+ "data-overflow-menu": "",
404
+ hidden: plain,
405
+ children: [t13, t14]
406
+ }, "breadcrumbs-menu");
407
+ $[46] = plain;
408
+ $[47] = t13;
409
+ $[48] = t15;
410
+ } else t15 = $[48];
411
+ listItems.splice(withRoot && rootVisible ? 1 : 0, 0, t15);
412
+ }
413
+ $[27] = alwaysCollapsed;
414
+ $[28] = collapsed;
415
+ $[29] = itemCount;
416
+ $[30] = items;
417
+ $[31] = menuItems;
418
+ $[32] = menuOpen;
419
+ $[33] = plain;
420
+ $[34] = rootVisible;
421
+ $[35] = withRoot;
422
+ $[36] = listItems;
423
+ } else listItems = $[36];
424
+ content = listItems;
425
+ }
399
426
  let t11;
400
- if ($[38] !== className) {
427
+ if ($[49] !== className) {
401
428
  t11 = clsx(className, Breadcrumbs_module_css_default.BreadcrumbsBase);
402
- $[38] = className;
403
- $[39] = t11;
404
- } else t11 = $[39];
405
- let t12;
406
- if ($[40] !== finalChildren) {
407
- t12 = /* @__PURE__ */ jsx(BreadcrumbsList, { children: finalChildren });
408
- $[40] = finalChildren;
409
- $[41] = t12;
410
- } else t12 = $[41];
429
+ $[49] = className;
430
+ $[50] = t11;
431
+ } else t11 = $[50];
432
+ const t12 = collapsible && overflow === "menu" && itemCount > 2 ? "" : void 0;
411
433
  let t13;
412
- if ($[42] !== overflow || $[43] !== style || $[44] !== t11 || $[45] !== t12 || $[46] !== variant) {
413
- t13 = /* @__PURE__ */ jsx("nav", {
434
+ if ($[51] !== content || $[52] !== t12) {
435
+ t13 = /* @__PURE__ */ jsx("ol", {
436
+ className: Breadcrumbs_module_css_default.BreadcrumbsList,
437
+ "data-narrow-collapse": t12,
438
+ children: content
439
+ });
440
+ $[51] = content;
441
+ $[52] = t12;
442
+ $[53] = t13;
443
+ } else t13 = $[53];
444
+ let t14;
445
+ if ($[54] !== overflow || $[55] !== style || $[56] !== t11 || $[57] !== t13 || $[58] !== variant) {
446
+ t14 = /* @__PURE__ */ jsx("nav", {
414
447
  className: t11,
415
448
  "aria-label": "Breadcrumbs",
416
449
  style,
417
- ref: containerRef,
450
+ ref: navRef,
418
451
  "data-overflow": overflow,
419
452
  "data-variant": variant,
420
453
  "data-component": "Breadcrumbs",
421
- children: t12
454
+ children: t13
422
455
  });
423
- $[42] = overflow;
424
- $[43] = style;
425
- $[44] = t11;
426
- $[45] = t12;
427
- $[46] = variant;
428
- $[47] = t13;
429
- } else t13 = $[47];
430
- return t13;
431
- }
432
- function _temp5(child_1, index) {
433
- return /* @__PURE__ */ jsxs("li", {
434
- className: Breadcrumbs_module_css_default.BreadcrumbsItem,
435
- children: [child_1, /* @__PURE__ */ jsx(ItemSeparator, {})]
436
- }, `visible + ${index}`);
456
+ $[54] = overflow;
457
+ $[55] = style;
458
+ $[56] = t11;
459
+ $[57] = t13;
460
+ $[58] = variant;
461
+ $[59] = t14;
462
+ } else t14 = $[59];
463
+ return t14;
437
464
  }
438
- function _temp4(child_0) {
465
+ function _temp3(child) {
439
466
  return /* @__PURE__ */ jsx("li", {
440
467
  className: Breadcrumbs_module_css_default.ItemWrapper,
441
- children: child_0
468
+ children: child
442
469
  });
443
470
  }
444
- function _temp3(child) {
445
- return child.offsetWidth;
446
- }
447
- function _temp2() {
448
- return [];
449
- }
450
471
  const ItemSeparator = () => {
451
472
  const $ = c(1);
452
473
  let t0;
@@ -486,14 +507,5 @@ var Breadcrumbs_default = Object.assign(Breadcrumbs, { Item: BreadcrumbsItemWith
486
507
  * @deprecated Use the `Breadcrumbs` component instead (i.e. `<Breadcrumb>` → `<Breadcrumbs>`)
487
508
  */
488
509
  const Breadcrumb = Object.assign(Breadcrumbs, { Item: BreadcrumbsItem });
489
- function _temp(item, index) {
490
- const { children, selected, as: Component, ...itemProps } = item.props;
491
- return /* @__PURE__ */ jsx(ActionList.LinkItem, {
492
- as: Component,
493
- ...itemProps,
494
- "aria-current": selected ? "page" : void 0,
495
- children
496
- }, index);
497
- }
498
510
  //#endregion
499
511
  export { Breadcrumb, Breadcrumbs_default as default };