@digdir/designsystemet-react 0.59.0 → 0.59.1-alpha.1

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 (121) hide show
  1. package/dist/cjs/components/Accordion/Accordion.js +1 -4
  2. package/dist/cjs/components/Accordion/AccordionContent/AccordionContent.js +1 -2
  3. package/dist/cjs/components/Accordion/AccordionHeader/AccordionHeader.js +1 -2
  4. package/dist/cjs/components/Accordion/AccordionItem/AccordionItem.js +1 -4
  5. package/dist/cjs/components/Button/Button.js +2 -2
  6. package/dist/cjs/components/DropdownMenu/DropdownMenuContent.js +4 -4
  7. package/dist/cjs/components/DropdownMenu/DropdownMenuTrigger.js +1 -1
  8. package/dist/cjs/components/Modal/ModalDialog.js +1 -1
  9. package/dist/cjs/components/Modal/ModalHeader/ModalHeader.js +1 -1
  10. package/dist/cjs/components/Modal/ModalHeader/ModalHeader.module.css.js +1 -1
  11. package/dist/cjs/components/Popover/PopoverContent.js +6 -6
  12. package/dist/cjs/components/Popover/PopoverTrigger.js +1 -1
  13. package/dist/cjs/components/Tooltip/Tooltip.js +6 -6
  14. package/dist/cjs/components/form/Checkbox/Checkbox.js +1 -1
  15. package/dist/cjs/components/form/Combobox/Combobox.js +72 -199
  16. package/dist/cjs/components/form/Combobox/Combobox.module.css.js +1 -1
  17. package/dist/cjs/components/form/Combobox/ComboboxContext.js +8 -0
  18. package/dist/cjs/components/form/Combobox/ComboboxIdContext.js +42 -0
  19. package/dist/cjs/components/form/Combobox/Custom/Custom.js +14 -9
  20. package/dist/cjs/components/form/Combobox/Empty/Empty.js +4 -4
  21. package/dist/cjs/components/form/Combobox/Option/Option.js +15 -33
  22. package/dist/cjs/components/form/Combobox/Option/useComboboxOption.js +47 -0
  23. package/dist/cjs/components/form/Combobox/internal/ComboboxChips.js +13 -10
  24. package/dist/cjs/components/form/Combobox/internal/ComboboxClearButton.js +5 -8
  25. package/dist/cjs/components/form/Combobox/internal/ComboboxInput.js +40 -69
  26. package/dist/cjs/components/form/Combobox/internal/ComboboxNative.js +2 -2
  27. package/dist/cjs/components/form/Combobox/useCombobox.js +77 -75
  28. package/dist/cjs/components/form/Combobox/useComboboxKeyboard.js +76 -0
  29. package/dist/cjs/components/form/Combobox/useFloatingCombobox.js +78 -0
  30. package/dist/cjs/components/form/Search/Search.js +1 -1
  31. package/dist/cjs/node_modules/@floating-ui/utils/{dom/dist → dist}/floating-ui.utils.dom.js +7 -4
  32. package/dist/cjs/node_modules/@floating-ui/utils/dist/floating-ui.utils.js +5 -0
  33. package/dist/cjs/node_modules/clsx/dist/clsx.js +1 -1
  34. package/dist/cjs/node_modules/clsx/dist/lite.js +9 -0
  35. package/dist/cjs/{node_modules → packages/react/node_modules}/@floating-ui/core/dist/floating-ui.core.js +40 -16
  36. package/dist/cjs/{node_modules → packages/react/node_modules}/@floating-ui/dom/dist/floating-ui.dom.js +83 -31
  37. package/dist/cjs/{node_modules → packages/react/node_modules}/@floating-ui/react/dist/floating-ui.react.js +307 -157
  38. package/dist/cjs/{node_modules/@floating-ui/react/utils → packages/react/node_modules/@floating-ui/react}/dist/floating-ui.react.utils.js +9 -4
  39. package/dist/cjs/{node_modules → packages/react/node_modules}/@floating-ui/react-dom/dist/floating-ui.react-dom.js +22 -18
  40. package/dist/{esm → cjs/packages/react}/node_modules/tabbable/dist/index.esm.js +59 -13
  41. package/dist/cjs/react-css-modules.css +2 -136
  42. package/dist/cjs/utilities/RovingTabIndex/RovingTabindexItem.js +1 -1
  43. package/dist/cjs/utilities/RovingTabIndex/RovingTabindexRoot.js +1 -1
  44. package/dist/esm/components/Accordion/Accordion.js +1 -4
  45. package/dist/esm/components/Accordion/AccordionContent/AccordionContent.js +1 -2
  46. package/dist/esm/components/Accordion/AccordionHeader/AccordionHeader.js +1 -2
  47. package/dist/esm/components/Accordion/AccordionItem/AccordionItem.js +1 -4
  48. package/dist/esm/components/Button/Button.js +2 -2
  49. package/dist/esm/components/DropdownMenu/DropdownMenuContent.js +3 -3
  50. package/dist/esm/components/DropdownMenu/DropdownMenuTrigger.js +1 -1
  51. package/dist/esm/components/Modal/ModalDialog.js +1 -1
  52. package/dist/esm/components/Modal/ModalHeader/ModalHeader.js +1 -1
  53. package/dist/esm/components/Modal/ModalHeader/ModalHeader.module.css.js +1 -1
  54. package/dist/esm/components/Popover/PopoverContent.js +4 -4
  55. package/dist/esm/components/Popover/PopoverTrigger.js +1 -1
  56. package/dist/esm/components/Tooltip/Tooltip.js +4 -4
  57. package/dist/esm/components/form/Checkbox/Checkbox.js +1 -1
  58. package/dist/esm/components/form/Combobox/Combobox.js +76 -203
  59. package/dist/esm/components/form/Combobox/Combobox.module.css.js +1 -1
  60. package/dist/esm/components/form/Combobox/ComboboxContext.js +6 -0
  61. package/dist/esm/components/form/Combobox/ComboboxIdContext.js +35 -0
  62. package/dist/esm/components/form/Combobox/Custom/Custom.js +13 -8
  63. package/dist/esm/components/form/Combobox/Empty/Empty.js +3 -3
  64. package/dist/esm/components/form/Combobox/Option/Option.js +15 -33
  65. package/dist/esm/components/form/Combobox/Option/useComboboxOption.js +45 -0
  66. package/dist/esm/components/form/Combobox/internal/ComboboxChips.js +12 -9
  67. package/dist/esm/components/form/Combobox/internal/ComboboxClearButton.js +4 -7
  68. package/dist/esm/components/form/Combobox/internal/ComboboxInput.js +40 -69
  69. package/dist/esm/components/form/Combobox/internal/ComboboxNative.js +2 -2
  70. package/dist/esm/components/form/Combobox/useCombobox.js +77 -75
  71. package/dist/esm/components/form/Combobox/useComboboxKeyboard.js +74 -0
  72. package/dist/esm/components/form/Combobox/useFloatingCombobox.js +76 -0
  73. package/dist/esm/components/form/Search/Search.js +1 -1
  74. package/dist/esm/node_modules/@floating-ui/utils/{dom/dist → dist}/floating-ui.utils.dom.js +7 -4
  75. package/dist/esm/node_modules/@floating-ui/utils/dist/floating-ui.utils.js +5 -0
  76. package/dist/esm/node_modules/clsx/dist/clsx.js +1 -1
  77. package/dist/esm/node_modules/clsx/dist/lite.js +4 -0
  78. package/dist/esm/{node_modules → packages/react/node_modules}/@floating-ui/core/dist/floating-ui.core.js +40 -16
  79. package/dist/esm/{node_modules → packages/react/node_modules}/@floating-ui/dom/dist/floating-ui.dom.js +82 -30
  80. package/dist/esm/{node_modules → packages/react/node_modules}/@floating-ui/react/dist/floating-ui.react.js +282 -135
  81. package/dist/esm/{node_modules/@floating-ui/react/utils → packages/react/node_modules/@floating-ui/react}/dist/floating-ui.react.utils.js +9 -5
  82. package/dist/esm/{node_modules → packages/react/node_modules}/@floating-ui/react-dom/dist/floating-ui.react-dom.js +19 -14
  83. package/dist/{cjs → esm/packages/react}/node_modules/tabbable/dist/index.esm.js +55 -15
  84. package/dist/esm/react-css-modules.css +2 -136
  85. package/dist/esm/utilities/RovingTabIndex/RovingTabindexItem.js +1 -1
  86. package/dist/esm/utilities/RovingTabIndex/RovingTabindexRoot.js +1 -1
  87. package/dist/types/components/Accordion/Accordion.d.ts.map +1 -1
  88. package/dist/types/components/Accordion/AccordionContent/AccordionContent.d.ts.map +1 -1
  89. package/dist/types/components/Accordion/AccordionHeader/AccordionHeader.d.ts.map +1 -1
  90. package/dist/types/components/Accordion/AccordionItem/AccordionItem.d.ts.map +1 -1
  91. package/dist/types/components/Modal/ModalHeader/ModalHeader.d.ts.map +1 -1
  92. package/dist/types/components/form/Combobox/Combobox.d.ts +95 -48
  93. package/dist/types/components/form/Combobox/Combobox.d.ts.map +1 -1
  94. package/dist/types/components/form/Combobox/ComboboxContext.d.ts +41 -0
  95. package/dist/types/components/form/Combobox/ComboboxContext.d.ts.map +1 -0
  96. package/dist/types/components/form/Combobox/ComboboxIdContext.d.ts +19 -0
  97. package/dist/types/components/form/Combobox/ComboboxIdContext.d.ts.map +1 -0
  98. package/dist/types/components/form/Combobox/Custom/Custom.d.ts.map +1 -1
  99. package/dist/types/components/form/Combobox/Option/Option.d.ts +2 -2
  100. package/dist/types/components/form/Combobox/Option/Option.d.ts.map +1 -1
  101. package/dist/types/components/form/Combobox/Option/useComboboxOption.d.ts +14 -0
  102. package/dist/types/components/form/Combobox/Option/useComboboxOption.d.ts.map +1 -0
  103. package/dist/types/components/form/Combobox/internal/ComboboxChips.d.ts.map +1 -1
  104. package/dist/types/components/form/Combobox/internal/ComboboxClearButton.d.ts.map +1 -1
  105. package/dist/types/components/form/Combobox/internal/ComboboxInput.d.ts +9 -2
  106. package/dist/types/components/form/Combobox/internal/ComboboxInput.d.ts.map +1 -1
  107. package/dist/types/components/form/Combobox/internal/ComboboxNative.d.ts +3 -1
  108. package/dist/types/components/form/Combobox/internal/ComboboxNative.d.ts.map +1 -1
  109. package/dist/types/components/form/Combobox/useCombobox.d.ts +14 -9
  110. package/dist/types/components/form/Combobox/useCombobox.d.ts.map +1 -1
  111. package/dist/types/components/form/Combobox/useComboboxKeyboard.d.ts +19 -0
  112. package/dist/types/components/form/Combobox/useComboboxKeyboard.d.ts.map +1 -0
  113. package/dist/types/components/form/Combobox/useFloatingCombobox.d.ts +41 -0
  114. package/dist/types/components/form/Combobox/useFloatingCombobox.d.ts.map +1 -0
  115. package/package.json +3 -3
  116. package/dist/cjs/components/Accordion/Accordion.module.css.js +0 -6
  117. package/dist/cjs/node_modules/@floating-ui/react/node_modules/@floating-ui/utils/dist/floating-ui.utils.js +0 -6
  118. package/dist/cjs/node_modules/@floating-ui/react/node_modules/@floating-ui/utils/dom/dist/floating-ui.utils.dom.js +0 -68
  119. package/dist/esm/components/Accordion/Accordion.module.css.js +0 -4
  120. package/dist/esm/node_modules/@floating-ui/react/node_modules/@floating-ui/utils/dist/floating-ui.utils.js +0 -4
  121. package/dist/esm/node_modules/@floating-ui/react/node_modules/@floating-ui/utils/dom/dist/floating-ui.utils.dom.js +0 -57
@@ -1,20 +1,19 @@
1
1
  'use client';
2
2
  import * as React from 'react';
3
3
  import { useLayoutEffect, useEffect, useRef } from 'react';
4
- import { getDocument, isTypeableCombobox, activeElement, contains, isVirtualClick, isVirtualPointerEvent, isMouseLikePointerType, getTarget, isSafari, isMac, isTypeableElement, stopEvent, isReactEvent, isRootElement, isEventTargetWithin } from '../utils/dist/floating-ui.react.utils.js';
5
- import { floor } from '../node_modules/@floating-ui/utils/dist/floating-ui.utils.js';
4
+ import { getDocument, isMouseLikePointerType, isTypeableCombobox, activeElement, contains, isVirtualClick, isVirtualPointerEvent, getTarget, isSafari, isMac, isTypeableElement, stopEvent, isReactEvent, isRootElement, isEventTargetWithin } from './floating-ui.react.utils.js';
5
+ import { floor } from '../../../../../../node_modules/@floating-ui/utils/dist/floating-ui.utils.js';
6
6
  import { useFloating as useFloating$1 } from '../../react-dom/dist/floating-ui.react-dom.js';
7
7
  export { arrow } from '../../react-dom/dist/floating-ui.react-dom.js';
8
- import { isElement, isHTMLElement, getWindow, getNodeName, isLastTraversableNode, getParentNode, getComputedStyle } from '../node_modules/@floating-ui/utils/dom/dist/floating-ui.utils.dom.js';
9
- import { tabbable } from '../../../tabbable/dist/index.esm.js';
8
+ import { isElement, isHTMLElement, getOverflowAncestors, getWindow, getNodeName, isLastTraversableNode, getParentNode, getComputedStyle } from '../../../../../../node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.js';
9
+ import { tabbable, isTabbable } from '../../../tabbable/dist/index.esm.js';
10
10
  import { createPortal } from 'react-dom';
11
11
  import { platform } from '../../dom/dist/floating-ui.dom.js';
12
- export { autoUpdate, computePosition } from '../../dom/dist/floating-ui.dom.js';
13
- import { getOverflowAncestors } from '../../utils/dom/dist/floating-ui.utils.dom.js';
12
+ export { autoUpdate, computePosition, flip, shift, size } from '../../dom/dist/floating-ui.dom.js';
14
13
 
15
14
  /**
16
15
  * Merges an array of refs into a single memoized callback ref or `null`.
17
- * @see https://floating-ui.com/docs/useMergeRefs
16
+ * @see https://floating-ui.com/docs/react-utils#usemergerefs
18
17
  */
19
18
  function useMergeRefs(refs) {
20
19
  return React.useMemo(() => {
@@ -34,8 +33,12 @@ function useMergeRefs(refs) {
34
33
  }, refs);
35
34
  }
36
35
 
37
- // `toString()` prevents bundlers from trying to `import { useInsertionEffect } from 'react'`
38
- const useInsertionEffect = React[/*#__PURE__*/'useInsertionEffect'.toString()];
36
+ // https://github.com/mui/material-ui/issues/41190#issuecomment-2040873379
37
+ const SafeReact = {
38
+ ...React
39
+ };
40
+
41
+ const useInsertionEffect = SafeReact.useInsertionEffect;
39
42
  const useSafeInsertionEffect = useInsertionEffect || (fn => fn());
40
43
  function useEffectEvent(callback) {
41
44
  const ref = React.useRef(() => {
@@ -223,6 +226,67 @@ function getGridNavigatedIndex(elementsRef, _ref) {
223
226
  return nextIndex;
224
227
  }
225
228
 
229
+ /** For each cell index, gets the item index that occupies that cell */
230
+ function buildCellMap(sizes, cols, dense) {
231
+ const cellMap = [];
232
+ let startIndex = 0;
233
+ sizes.forEach((_ref2, index) => {
234
+ let {
235
+ width,
236
+ height
237
+ } = _ref2;
238
+ if (width > cols) {
239
+ if (process.env.NODE_ENV !== "production") {
240
+ throw new Error("[Floating UI]: Invalid grid - item width at index " + index + " is greater than grid columns");
241
+ }
242
+ }
243
+ let itemPlaced = false;
244
+ if (dense) {
245
+ startIndex = 0;
246
+ }
247
+ while (!itemPlaced) {
248
+ const targetCells = [];
249
+ for (let i = 0; i < width; i++) {
250
+ for (let j = 0; j < height; j++) {
251
+ targetCells.push(startIndex + i + j * cols);
252
+ }
253
+ }
254
+ if (startIndex % cols + width <= cols && targetCells.every(cell => cellMap[cell] == null)) {
255
+ targetCells.forEach(cell => {
256
+ cellMap[cell] = index;
257
+ });
258
+ itemPlaced = true;
259
+ } else {
260
+ startIndex++;
261
+ }
262
+ }
263
+ });
264
+
265
+ // convert into a non-sparse array
266
+ return [...cellMap];
267
+ }
268
+
269
+ /** Gets cell index of an item's corner or -1 when index is -1. */
270
+ function getCellIndexOfCorner(index, sizes, cellMap, cols, corner) {
271
+ if (index === -1) return -1;
272
+ const firstCellIndex = cellMap.indexOf(index);
273
+ switch (corner) {
274
+ case 'tl':
275
+ return firstCellIndex;
276
+ case 'tr':
277
+ return firstCellIndex + sizes[index].width - 1;
278
+ case 'bl':
279
+ return firstCellIndex + (sizes[index].height - 1) * cols;
280
+ case 'br':
281
+ return cellMap.lastIndexOf(index);
282
+ }
283
+ }
284
+
285
+ /** Gets all cell indices that correspond to the specified indices */
286
+ function getCellIndices(indices, cellMap) {
287
+ return cellMap.flatMap((index, cellIndex) => indices.includes(index) ? [cellIndex] : []);
288
+ }
289
+
226
290
  let rafId = 0;
227
291
  function enqueueFocus(el, options) {
228
292
  if (options === void 0) {
@@ -263,7 +327,9 @@ function _extends() {
263
327
 
264
328
  let serverHandoffComplete = false;
265
329
  let count = 0;
266
- const genId = () => "floating-ui-" + count++;
330
+ const genId = () => // Ensure the id is unique with multiple independent versions of Floating UI
331
+ // on <React 18
332
+ "floating-ui-" + Math.random().toString(36).slice(2, 6) + count++;
267
333
  function useFloatingId() {
268
334
  const [id, setId] = React.useState(() => serverHandoffComplete ? genId() : undefined);
269
335
  index(() => {
@@ -273,30 +339,55 @@ function useFloatingId() {
273
339
  // eslint-disable-next-line react-hooks/exhaustive-deps
274
340
  }, []);
275
341
  React.useEffect(() => {
276
- if (!serverHandoffComplete) {
277
- serverHandoffComplete = true;
278
- }
342
+ serverHandoffComplete = true;
279
343
  }, []);
280
344
  return id;
281
345
  }
282
-
283
- // `toString()` prevents bundlers from trying to `import { useId } from 'react'`
284
- const useReactId = React[/*#__PURE__*/'useId'.toString()];
346
+ const useReactId = SafeReact.useId;
285
347
 
286
348
  /**
287
349
  * Uses React 18's built-in `useId()` when available, or falls back to a
288
350
  * slightly less performant (requiring a double render) implementation for
289
351
  * earlier React versions.
290
- * @see https://floating-ui.com/docs/useId
352
+ * @see https://floating-ui.com/docs/react-utils#useid
291
353
  */
292
354
  const useId = useReactId || useFloatingId;
293
355
 
356
+ let devMessageSet;
357
+ if (process.env.NODE_ENV !== "production") {
358
+ devMessageSet = /*#__PURE__*/new Set();
359
+ }
360
+ function warn() {
361
+ var _devMessageSet;
362
+ for (var _len = arguments.length, messages = new Array(_len), _key = 0; _key < _len; _key++) {
363
+ messages[_key] = arguments[_key];
364
+ }
365
+ const message = "Floating UI: " + messages.join(' ');
366
+ if (!((_devMessageSet = devMessageSet) != null && _devMessageSet.has(message))) {
367
+ var _devMessageSet2;
368
+ (_devMessageSet2 = devMessageSet) == null || _devMessageSet2.add(message);
369
+ console.warn(message);
370
+ }
371
+ }
372
+ function error() {
373
+ var _devMessageSet3;
374
+ for (var _len2 = arguments.length, messages = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
375
+ messages[_key2] = arguments[_key2];
376
+ }
377
+ const message = "Floating UI: " + messages.join(' ');
378
+ if (!((_devMessageSet3 = devMessageSet) != null && _devMessageSet3.has(message))) {
379
+ var _devMessageSet4;
380
+ (_devMessageSet4 = devMessageSet) == null || _devMessageSet4.add(message);
381
+ console.error(message);
382
+ }
383
+ }
384
+
294
385
  /**
295
386
  * Renders a pointing arrow triangle.
296
387
  * @see https://floating-ui.com/docs/FloatingArrow
297
388
  */
298
- const FloatingArrow = /*#__PURE__*/React.forwardRef(function FloatingArrow(_ref, ref) {
299
- let {
389
+ const FloatingArrow = /*#__PURE__*/React.forwardRef(function FloatingArrow(props, ref) {
390
+ const {
300
391
  context: {
301
392
  placement,
302
393
  elements: {
@@ -318,10 +409,10 @@ const FloatingArrow = /*#__PURE__*/React.forwardRef(function FloatingArrow(_ref,
318
409
  ...restStyle
319
410
  } = {},
320
411
  ...rest
321
- } = _ref;
412
+ } = props;
322
413
  if (process.env.NODE_ENV !== "production") {
323
414
  if (!ref) {
324
- console.warn('Floating UI: The `ref` prop is required for the `FloatingArrow`', 'component.');
415
+ warn('The `ref` prop is required for `FloatingArrow`.');
325
416
  }
326
417
  }
327
418
  const clipPathId = useId();
@@ -331,8 +422,8 @@ const FloatingArrow = /*#__PURE__*/React.forwardRef(function FloatingArrow(_ref,
331
422
 
332
423
  // Strokes must be double the border width, this ensures the stroke's width
333
424
  // works as you'd expect.
334
- strokeWidth *= 2;
335
- const halfStrokeWidth = strokeWidth / 2;
425
+ const computedStrokeWidth = strokeWidth * 2;
426
+ const halfStrokeWidth = computedStrokeWidth / 2;
336
427
  const svgX = width / 2 * (tipRadius / -8 + 1);
337
428
  const svgY = height / 2 * tipRadius / 4;
338
429
  const [side, alignment] = placement.split('-');
@@ -356,7 +447,7 @@ const FloatingArrow = /*#__PURE__*/React.forwardRef(function FloatingArrow(_ref,
356
447
  return /*#__PURE__*/React.createElement("svg", _extends({}, rest, {
357
448
  "aria-hidden": true,
358
449
  ref: ref,
359
- width: isCustomShape ? width : width + strokeWidth,
450
+ width: isCustomShape ? width : width + computedStrokeWidth,
360
451
  height: width,
361
452
  viewBox: "0 0 " + width + " " + (height > width ? height : width),
362
453
  style: {
@@ -364,27 +455,27 @@ const FloatingArrow = /*#__PURE__*/React.forwardRef(function FloatingArrow(_ref,
364
455
  pointerEvents: 'none',
365
456
  [xOffsetProp]: arrowX,
366
457
  [yOffsetProp]: arrowY,
367
- [side]: isVerticalSide || isCustomShape ? '100%' : "calc(100% - " + strokeWidth / 2 + "px)",
458
+ [side]: isVerticalSide || isCustomShape ? '100%' : "calc(100% - " + computedStrokeWidth / 2 + "px)",
368
459
  transform: "" + rotation + (transform != null ? transform : ''),
369
460
  ...restStyle
370
461
  }
371
- }), strokeWidth > 0 && /*#__PURE__*/React.createElement("path", {
462
+ }), computedStrokeWidth > 0 && /*#__PURE__*/React.createElement("path", {
372
463
  clipPath: "url(#" + clipPathId + ")",
373
464
  fill: "none",
374
465
  stroke: stroke
375
466
  // Account for the stroke on the fill path rendered below.
376
467
  ,
377
- strokeWidth: strokeWidth + (d ? 0 : 1),
468
+ strokeWidth: computedStrokeWidth + (d ? 0 : 1),
378
469
  d: dValue
379
470
  }), /*#__PURE__*/React.createElement("path", {
380
- stroke: strokeWidth && !d ? rest.fill : 'none',
471
+ stroke: computedStrokeWidth && !d ? rest.fill : 'none',
381
472
  d: dValue
382
473
  }), /*#__PURE__*/React.createElement("clipPath", {
383
474
  id: clipPathId
384
475
  }, /*#__PURE__*/React.createElement("rect", {
385
476
  x: -halfStrokeWidth,
386
477
  y: halfStrokeWidth * (isCustomShape ? -1 : 1),
387
- width: width + strokeWidth,
478
+ width: width + computedStrokeWidth,
388
479
  height: width
389
480
  })));
390
481
  });
@@ -408,10 +499,19 @@ function createPubSub() {
408
499
 
409
500
  const FloatingNodeContext = /*#__PURE__*/React.createContext(null);
410
501
  const FloatingTreeContext = /*#__PURE__*/React.createContext(null);
502
+
503
+ /**
504
+ * Returns the parent node id for nested floating elements, if available.
505
+ * Returns `null` for top-level floating elements.
506
+ */
411
507
  const useFloatingParentNodeId = () => {
412
508
  var _React$useContext;
413
509
  return ((_React$useContext = React.useContext(FloatingNodeContext)) == null ? void 0 : _React$useContext.id) || null;
414
510
  };
511
+
512
+ /**
513
+ * Returns the nearest floating tree context, if available.
514
+ */
415
515
  const useFloatingTree = () => React.useContext(FloatingTreeContext);
416
516
 
417
517
  function createAttribute(name) {
@@ -516,7 +616,7 @@ function useHover(context, props) {
516
616
  return () => {
517
617
  html.removeEventListener('mouseleave', onLeave);
518
618
  };
519
- }, [floating, open, onOpenChange, enabled, handleCloseRef, dataRef, isHoverOpen]);
619
+ }, [floating, open, onOpenChange, enabled, handleCloseRef, isHoverOpen]);
520
620
  const closeWithDelay = React.useCallback(function (event, runElseBranch, reason) {
521
621
  if (runElseBranch === void 0) {
522
622
  runElseBranch = true;
@@ -678,7 +778,7 @@ function useHover(context, props) {
678
778
  };
679
779
  }
680
780
  }
681
- }, [enabled, open, parentId, floating, domReference, tree, handleCloseRef, dataRef, isHoverOpen]);
781
+ }, [enabled, open, parentId, floating, domReference, tree, handleCloseRef, isHoverOpen]);
682
782
  index(() => {
683
783
  if (!open) {
684
784
  pointerTypeRef.current = undefined;
@@ -706,15 +806,23 @@ function useHover(context, props) {
706
806
  onPointerDown: setPointerRef,
707
807
  onPointerEnter: setPointerRef,
708
808
  onMouseMove(event) {
809
+ function handleMouseMove() {
810
+ if (!blockMouseMoveRef.current) {
811
+ onOpenChange(true, event.nativeEvent, 'hover');
812
+ }
813
+ }
814
+ if (mouseOnly && !isMouseLikePointerType(pointerTypeRef.current)) {
815
+ return;
816
+ }
709
817
  if (open || restMs === 0) {
710
818
  return;
711
819
  }
712
820
  clearTimeout(restTimeoutRef.current);
713
- restTimeoutRef.current = setTimeout(() => {
714
- if (!blockMouseMoveRef.current) {
715
- onOpenChange(true, event.nativeEvent, 'hover');
716
- }
717
- }, restMs);
821
+ if (pointerTypeRef.current === 'touch') {
822
+ handleMouseMove();
823
+ } else {
824
+ restTimeoutRef.current = setTimeout(handleMouseMove, restMs);
825
+ }
718
826
  }
719
827
  },
720
828
  floating: {
@@ -726,7 +834,7 @@ function useHover(context, props) {
726
834
  }
727
835
  }
728
836
  };
729
- }, [enabled, restMs, open, onOpenChange, closeWithDelay]);
837
+ }, [enabled, mouseOnly, open, restMs, onOpenChange, closeWithDelay]);
730
838
  }
731
839
 
732
840
  function getAncestors(nodes, id) {
@@ -981,75 +1089,81 @@ const FocusGuard = /*#__PURE__*/React.forwardRef(function FocusGuard(props, ref)
981
1089
  });
982
1090
 
983
1091
  const PortalContext = /*#__PURE__*/React.createContext(null);
984
- function useFloatingPortalNode(_temp) {
985
- let {
1092
+ const attr = /*#__PURE__*/createAttribute('portal');
1093
+
1094
+ /**
1095
+ * @see https://floating-ui.com/docs/FloatingPortal#usefloatingportalnode
1096
+ */
1097
+ function useFloatingPortalNode(props) {
1098
+ if (props === void 0) {
1099
+ props = {};
1100
+ }
1101
+ const {
986
1102
  id,
987
1103
  root
988
- } = _temp === void 0 ? {} : _temp;
989
- const [portalNode, setPortalNode] = React.useState(null);
1104
+ } = props;
990
1105
  const uniqueId = useId();
991
1106
  const portalContext = usePortalContext();
992
- const data = React.useMemo(() => ({
993
- id,
994
- root,
995
- portalContext,
996
- uniqueId
997
- }), [id, root, portalContext, uniqueId]);
998
- const dataRef = React.useRef();
1107
+ const [portalNode, setPortalNode] = React.useState(null);
1108
+ const portalNodeRef = React.useRef(null);
999
1109
  index(() => {
1000
1110
  return () => {
1001
1111
  portalNode == null || portalNode.remove();
1112
+ // Allow the subsequent layout effects to create a new node on updates.
1113
+ // The portal node will still be cleaned up on unmount.
1114
+ // https://github.com/floating-ui/floating-ui/issues/2454
1115
+ queueMicrotask(() => {
1116
+ portalNodeRef.current = null;
1117
+ });
1002
1118
  };
1003
- }, [portalNode, data]);
1119
+ }, [portalNode]);
1004
1120
  index(() => {
1005
- if (dataRef.current === data) return;
1006
- dataRef.current = data;
1007
- const {
1008
- id,
1009
- root,
1010
- portalContext,
1011
- uniqueId
1012
- } = data;
1121
+ if (portalNodeRef.current) return;
1013
1122
  const existingIdRoot = id ? document.getElementById(id) : null;
1014
- const attr = createAttribute('portal');
1015
- if (existingIdRoot) {
1016
- const subRoot = document.createElement('div');
1017
- subRoot.id = uniqueId;
1018
- subRoot.setAttribute(attr, '');
1019
- existingIdRoot.appendChild(subRoot);
1020
- setPortalNode(subRoot);
1021
- } else {
1022
- let container = root || (portalContext == null ? void 0 : portalContext.portalNode);
1023
- if (container && !isElement(container)) container = container.current;
1024
- container = container || document.body;
1025
- let idWrapper = null;
1026
- if (id) {
1027
- idWrapper = document.createElement('div');
1028
- idWrapper.id = id;
1029
- container.appendChild(idWrapper);
1030
- }
1031
- const subRoot = document.createElement('div');
1032
- subRoot.id = uniqueId;
1033
- subRoot.setAttribute(attr, '');
1034
- container = idWrapper || container;
1035
- container.appendChild(subRoot);
1036
- setPortalNode(subRoot);
1037
- }
1038
- }, [data]);
1123
+ if (!existingIdRoot) return;
1124
+ const subRoot = document.createElement('div');
1125
+ subRoot.id = uniqueId;
1126
+ subRoot.setAttribute(attr, '');
1127
+ existingIdRoot.appendChild(subRoot);
1128
+ portalNodeRef.current = subRoot;
1129
+ setPortalNode(subRoot);
1130
+ }, [id, uniqueId]);
1131
+ index(() => {
1132
+ if (portalNodeRef.current) return;
1133
+ let container = root || (portalContext == null ? void 0 : portalContext.portalNode);
1134
+ if (container && !isElement(container)) container = container.current;
1135
+ container = container || document.body;
1136
+ let idWrapper = null;
1137
+ if (id) {
1138
+ idWrapper = document.createElement('div');
1139
+ idWrapper.id = id;
1140
+ container.appendChild(idWrapper);
1141
+ }
1142
+ const subRoot = document.createElement('div');
1143
+ subRoot.id = uniqueId;
1144
+ subRoot.setAttribute(attr, '');
1145
+ container = idWrapper || container;
1146
+ container.appendChild(subRoot);
1147
+ portalNodeRef.current = subRoot;
1148
+ setPortalNode(subRoot);
1149
+ }, [id, root, uniqueId, portalContext]);
1039
1150
  return portalNode;
1040
1151
  }
1041
1152
  /**
1042
1153
  * Portals the floating element into a given container element — by default,
1043
1154
  * outside of the app root and into the body.
1155
+ * This is necessary to ensure the floating element can appear outside any
1156
+ * potential parent containers that cause clipping (such as `overflow: hidden`),
1157
+ * while retaining its location in the React tree.
1044
1158
  * @see https://floating-ui.com/docs/FloatingPortal
1045
1159
  */
1046
- function FloatingPortal(_ref) {
1047
- let {
1160
+ function FloatingPortal(props) {
1161
+ const {
1048
1162
  children,
1049
1163
  id,
1050
1164
  root = null,
1051
1165
  preserveTabOrder = true
1052
- } = _ref;
1166
+ } = props;
1053
1167
  const portalNode = useFloatingPortalNode({
1054
1168
  id,
1055
1169
  root
@@ -1139,11 +1253,16 @@ const LIST_LIMIT = 20;
1139
1253
  let previouslyFocusedElements = [];
1140
1254
  function addPreviouslyFocusedElement(element) {
1141
1255
  previouslyFocusedElements = previouslyFocusedElements.filter(el => el.isConnected);
1142
- if (element && getNodeName(element) !== 'body') {
1143
- previouslyFocusedElements.push(element);
1144
- if (previouslyFocusedElements.length > LIST_LIMIT) {
1145
- previouslyFocusedElements = previouslyFocusedElements.slice(-LIST_LIMIT);
1146
- }
1256
+ let tabbableEl = element;
1257
+ if (!tabbableEl || getNodeName(tabbableEl) === 'body') return;
1258
+ if (!isTabbable(tabbableEl, getTabbableOptions())) {
1259
+ const tabbableChild = tabbable(tabbableEl, getTabbableOptions())[0];
1260
+ if (!tabbableChild) return;
1261
+ tabbableEl = tabbableChild;
1262
+ }
1263
+ previouslyFocusedElements.push(tabbableEl);
1264
+ if (previouslyFocusedElements.length > LIST_LIMIT) {
1265
+ previouslyFocusedElements = previouslyFocusedElements.slice(-LIST_LIMIT);
1147
1266
  }
1148
1267
  }
1149
1268
  function getPreviouslyFocusedElement() {
@@ -1253,7 +1372,7 @@ function FloatingFocusManager(props) {
1253
1372
  return () => {
1254
1373
  doc.removeEventListener('keydown', onKeyDown);
1255
1374
  };
1256
- }, [disabled, domReference, floating, modal, orderRef, refs, isUntrappedTypeableCombobox, getTabbableContent, getTabbableElements]);
1375
+ }, [disabled, domReference, floating, modal, orderRef, isUntrappedTypeableCombobox, getTabbableContent, getTabbableElements]);
1257
1376
  React.useEffect(() => {
1258
1377
  if (disabled || !closeOnFocusOut) return;
1259
1378
 
@@ -1710,9 +1829,8 @@ function useDismiss(context, props) {
1710
1829
  const nextParent = getParentNode(targetRootAncestor);
1711
1830
  if (isLastTraversableNode(nextParent) || !isElement(nextParent)) {
1712
1831
  break;
1713
- } else {
1714
- targetRootAncestor = nextParent;
1715
1832
  }
1833
+ targetRootAncestor = nextParent;
1716
1834
  }
1717
1835
 
1718
1836
  // Check if the click occurred on a third-party element injected after the
@@ -1855,17 +1973,12 @@ function useDismiss(context, props) {
1855
1973
  }, [enabled, referencePress, outsidePressEvent, referencePressEvent, onOpenChange, closeOnEscapeKeyDown]);
1856
1974
  }
1857
1975
 
1858
- let devMessageSet;
1859
- if (process.env.NODE_ENV !== "production") {
1860
- devMessageSet = /*#__PURE__*/new Set();
1861
- }
1862
-
1863
1976
  /**
1864
1977
  * Provides data to position a floating element and context to add interactions.
1865
1978
  * @see https://floating-ui.com/docs/useFloating
1866
1979
  */
1867
1980
  function useFloating(options) {
1868
- var _options$elements2;
1981
+ var _options$elements;
1869
1982
  if (options === void 0) {
1870
1983
  options = {};
1871
1984
  }
@@ -1874,27 +1987,33 @@ function useFloating(options) {
1874
1987
  onOpenChange: unstable_onOpenChange,
1875
1988
  nodeId
1876
1989
  } = options;
1990
+ const [_domReference, setDomReference] = React.useState(null);
1991
+ const [positionReference, _setPositionReference] = React.useState(null);
1992
+ const optionDomReference = (_options$elements = options.elements) == null ? void 0 : _options$elements.reference;
1993
+ const domReference = optionDomReference || _domReference;
1877
1994
  if (process.env.NODE_ENV !== "production") {
1878
- var _options$elements;
1879
- const err = 'Floating UI: Cannot pass a virtual element to the ' + '`elements.reference` option, as it must be a real DOM element. ' + 'Use `refs.setPositionReference` instead.';
1880
- if ((_options$elements = options.elements) != null && _options$elements.reference && !isElement(options.elements.reference)) {
1881
- var _devMessageSet;
1882
- if (!((_devMessageSet = devMessageSet) != null && _devMessageSet.has(err))) {
1883
- var _devMessageSet2;
1884
- (_devMessageSet2 = devMessageSet) == null || _devMessageSet2.add(err);
1885
- console.error(err);
1886
- }
1995
+ if (optionDomReference && !isElement(optionDomReference)) {
1996
+ error('Cannot pass a virtual element to the `elements.reference` option,', 'as it must be a real DOM element. Use `refs.setPositionReference()`', 'instead.');
1887
1997
  }
1888
1998
  }
1889
- const [_domReference, setDomReference] = React.useState(null);
1890
- const domReference = ((_options$elements2 = options.elements) == null ? void 0 : _options$elements2.reference) || _domReference;
1891
- const position = useFloating$1(options);
1999
+ index(() => {
2000
+ if (domReference) {
2001
+ domReferenceRef.current = domReference;
2002
+ }
2003
+ }, [domReference]);
2004
+ const position = useFloating$1({
2005
+ ...options,
2006
+ elements: {
2007
+ ...options.elements,
2008
+ ...(positionReference && {
2009
+ reference: positionReference
2010
+ })
2011
+ }
2012
+ });
1892
2013
  const tree = useFloatingTree();
1893
2014
  const nested = useFloatingParentNodeId() != null;
1894
2015
  const onOpenChange = useEffectEvent((open, event, reason) => {
1895
- if (open) {
1896
- dataRef.current.openEvent = event;
1897
- }
2016
+ dataRef.current.openEvent = open ? event : undefined;
1898
2017
  events.emit('openchange', {
1899
2018
  open,
1900
2019
  event,
@@ -1908,11 +2027,14 @@ function useFloating(options) {
1908
2027
  const events = React.useState(() => createPubSub())[0];
1909
2028
  const floatingId = useId();
1910
2029
  const setPositionReference = React.useCallback(node => {
1911
- const positionReference = isElement(node) ? {
2030
+ const computedPositionReference = isElement(node) ? {
1912
2031
  getBoundingClientRect: () => node.getBoundingClientRect(),
1913
2032
  contextElement: node
1914
2033
  } : node;
1915
- position.refs.setReference(positionReference);
2034
+ // Store the positionReference in state if the DOM reference is specified externally via the
2035
+ // `elements.reference` option. This ensures that it won't be overridden on future renders.
2036
+ _setPositionReference(computedPositionReference);
2037
+ position.refs.setReference(computedPositionReference);
1916
2038
  }, [position.refs]);
1917
2039
  const setReference = React.useCallback(node => {
1918
2040
  if (isElement(node) || node === null) {
@@ -1980,7 +2102,6 @@ function useFocus(context, props) {
1980
2102
  events,
1981
2103
  refs,
1982
2104
  elements: {
1983
- floating,
1984
2105
  domReference
1985
2106
  }
1986
2107
  } = context;
@@ -2014,7 +2135,7 @@ function useFocus(context, props) {
2014
2135
  win.removeEventListener('blur', onBlur);
2015
2136
  win.removeEventListener('keydown', onKeyDown, true);
2016
2137
  };
2017
- }, [floating, domReference, open, enabled]);
2138
+ }, [domReference, open, enabled]);
2018
2139
  React.useEffect(() => {
2019
2140
  if (!enabled) {
2020
2141
  return;
@@ -2087,7 +2208,11 @@ function useFocus(context, props) {
2087
2208
  // When focusing the reference element (e.g. regular click), then
2088
2209
  // clicking into the floating element, prevent it from hiding.
2089
2210
  // Note: it must be focusable, e.g. `tabindex="-1"`.
2090
- if (contains(refs.floating.current, relatedTarget) || contains(domReference, relatedTarget) || movedToFocusGuard) {
2211
+ // We can not rely on relatedTarget to point to the correct element
2212
+ // as it will only point to the shadow host of the newly focused element
2213
+ // and not the element that actually has received focus if it is located
2214
+ // inside a shadow root.
2215
+ if (contains(refs.floating.current, activeEl) || contains(domReference, activeEl) || movedToFocusGuard) {
2091
2216
  return;
2092
2217
  }
2093
2218
  onOpenChange(false, event.nativeEvent, 'focus');
@@ -2105,7 +2230,6 @@ function mergeProps(userProps, propsList, elementKey) {
2105
2230
  const isItem = elementKey === 'item';
2106
2231
  let domUserProps = userProps;
2107
2232
  if (isItem && userProps) {
2108
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2109
2233
  const {
2110
2234
  [ACTIVE_KEY]: _,
2111
2235
  [SELECTED_KEY]: __,
@@ -2209,7 +2333,7 @@ function isMainOrientationKey(key, orientation) {
2209
2333
  function isMainOrientationToEndKey(key, orientation, rtl) {
2210
2334
  const vertical = key === ARROW_DOWN;
2211
2335
  const horizontal = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT;
2212
- return doSwitch(orientation, vertical, horizontal) || key === 'Enter' || key == ' ' || key === '';
2336
+ return doSwitch(orientation, vertical, horizontal) || key === 'Enter' || key === ' ' || key === '';
2213
2337
  }
2214
2338
  function isCrossOrientationOpenKey(key, orientation, rtl) {
2215
2339
  const vertical = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT;
@@ -2254,19 +2378,21 @@ function useListNavigation(context, props) {
2254
2378
  orientation = 'vertical',
2255
2379
  cols = 1,
2256
2380
  scrollItemIntoView = true,
2257
- virtualItemRef
2381
+ virtualItemRef,
2382
+ itemSizes,
2383
+ dense = false
2258
2384
  } = props;
2259
2385
  if (process.env.NODE_ENV !== "production") {
2260
2386
  if (allowEscape) {
2261
2387
  if (!loop) {
2262
- console.warn(['Floating UI: `useListNavigation` looping must be enabled to allow', 'escaping.'].join(' '));
2388
+ warn('`useListNavigation` looping must be enabled to allow escaping.');
2263
2389
  }
2264
2390
  if (!virtual) {
2265
- console.warn(['Floating UI: `useListNavigation` must be virtual to allow', 'escaping.'].join(' '));
2391
+ warn('`useListNavigation` must be virtual to allow escaping.');
2266
2392
  }
2267
2393
  }
2268
2394
  if (orientation === 'vertical' && cols > 1) {
2269
- console.warn(['Floating UI: In grid list navigation mode (`cols` > 1), the', '`orientation` should be either "horizontal" or "both".'].join(' '));
2395
+ warn('In grid list navigation mode (`cols` > 1), the `orientation` should', 'be either "horizontal" or "both".');
2270
2396
  }
2271
2397
  }
2272
2398
  const parentId = useFloatingParentNodeId();
@@ -2344,6 +2470,7 @@ function useListNavigation(context, props) {
2344
2470
  // Regardless of the pointer modality, we want to ensure the selected
2345
2471
  // item comes into view when the floating element is opened.
2346
2472
  forceScrollIntoViewRef.current = true;
2473
+ indexRef.current = selectedIndex;
2347
2474
  onNavigate(selectedIndex);
2348
2475
  }
2349
2476
  } else if (previousMountedRef.current) {
@@ -2533,17 +2660,38 @@ function useListNavigation(context, props) {
2533
2660
 
2534
2661
  // Grid navigation.
2535
2662
  if (cols > 1) {
2536
- indexRef.current = getGridNavigatedIndex(listRef, {
2663
+ const sizes = itemSizes || Array.from({
2664
+ length: listRef.current.length
2665
+ }, () => ({
2666
+ width: 1,
2667
+ height: 1
2668
+ }));
2669
+ // To calculate movements on the grid, we use hypothetical cell indices
2670
+ // as if every item was 1x1, then convert back to real indices.
2671
+ const cellMap = buildCellMap(sizes, cols, dense);
2672
+ const minGridIndex = cellMap.findIndex(index => index != null && !(disabledIndices != null && disabledIndices.includes(index)));
2673
+ // last enabled index
2674
+ const maxGridIndex = cellMap.reduce((foundIndex, index, cellIndex) => index != null && !(disabledIndices != null && disabledIndices.includes(index)) ? cellIndex : foundIndex, -1);
2675
+ indexRef.current = cellMap[getGridNavigatedIndex({
2676
+ current: cellMap.map(itemIndex => itemIndex != null ? listRef.current[itemIndex] : null)
2677
+ }, {
2537
2678
  event,
2538
2679
  orientation,
2539
2680
  loop,
2540
2681
  cols,
2541
- disabledIndices,
2542
- minIndex,
2543
- maxIndex,
2544
- prevIndex: indexRef.current,
2682
+ // treat undefined (empty grid spaces) as disabled indices so we
2683
+ // don't end up in them
2684
+ disabledIndices: getCellIndices([...(disabledIndices || []), undefined], cellMap),
2685
+ minIndex: minGridIndex,
2686
+ maxIndex: maxGridIndex,
2687
+ prevIndex: getCellIndexOfCorner(indexRef.current, sizes, cellMap, cols,
2688
+ // use a corner matching the edge closest to the direction
2689
+ // we're moving in so we don't end up in the same item. Prefer
2690
+ // top/left over bottom/right.
2691
+ event.key === ARROW_DOWN ? 'bl' : event.key === ARROW_RIGHT ? 'tr' : 'tl'),
2545
2692
  stopEvent: true
2546
- });
2693
+ })]; // navigated cell will never be nullish
2694
+
2547
2695
  onNavigate(indexRef.current);
2548
2696
  if (orientation === 'both') {
2549
2697
  return;
@@ -2702,7 +2850,7 @@ function useListNavigation(context, props) {
2702
2850
  },
2703
2851
  item
2704
2852
  };
2705
- }, [domReference, refs, activeId, virtualId, disabledIndicesRef, latestOpenRef, listRef, enabled, orientation, rtl, virtual, open, hasActiveIndex, nested, selectedIndex, openOnArrowKeyDown, allowEscape, cols, loop, focusItemOnOpen, onNavigate, onOpenChange, item, tree, virtualItemRef]);
2853
+ }, [domReference, refs, activeId, virtualId, disabledIndicesRef, latestOpenRef, listRef, enabled, orientation, rtl, virtual, open, hasActiveIndex, nested, selectedIndex, openOnArrowKeyDown, allowEscape, cols, loop, focusItemOnOpen, onNavigate, onOpenChange, item, tree, virtualItemRef, itemSizes, dense]);
2706
2854
  }
2707
2855
 
2708
2856
  const componentRoleToAriaRoleMap = /*#__PURE__*/new Map([['select', 'listbox'], ['combobox', 'listbox'], ['label', false]]);
@@ -2871,10 +3019,9 @@ function useTransitionStatus(context, props) {
2871
3019
  return () => {
2872
3020
  cancelAnimationFrame(frame);
2873
3021
  };
2874
- } else {
2875
- setInitiated(true);
2876
- setStatus('close');
2877
3022
  }
3023
+ setInitiated(true);
3024
+ setStatus('close');
2878
3025
  }, [open, floating]);
2879
3026
  return {
2880
3027
  isMounted,