@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
@@ -17,94 +17,96 @@ function isComboboxCustom(child) {
17
17
  function isInteractiveComboboxCustom(child) {
18
18
  return isComboboxCustom(child) && child.props.interactive === true;
19
19
  }
20
- function useCombobox({ children, inputValue, multiple, filter, initialValue, }) {
21
- const options = React.useMemo(() => {
22
- const allOptions = [];
23
- React.Children.forEach(children, (child) => {
20
+ function useCombobox({ children, inputValue, multiple, filter = (inputValue, option) => {
21
+ return option.label.toLowerCase().startsWith(inputValue.toLowerCase());
22
+ }, initialValue, }) {
23
+ const { optionsChildren, customIds, restChildren, interactiveChildren } = React.useMemo(() => {
24
+ const allChildren = React.Children.toArray(children);
25
+ const result = allChildren.reduce((acc, child) => {
24
26
  if (isComboboxOption(child)) {
25
- const props = child.props;
26
- let label = props.displayValue || '';
27
- if (!props.displayValue) {
28
- let childrenLabel = '';
29
- // go over children and find all strings
30
- React.Children.forEach(props.children, (child) => {
31
- if (typeof child === 'string') {
32
- childrenLabel += child;
33
- }
34
- else {
35
- throw new Error('If ComboboxOption is not a string, it must have a displayValue prop');
36
- }
37
- });
38
- label = childrenLabel;
27
+ acc.optionsChildren.push(child);
28
+ }
29
+ else {
30
+ acc.restChildren.push(child);
31
+ if (isInteractiveComboboxCustom(child)) {
32
+ const childElement = child;
33
+ acc.interactiveChildren.push(childElement);
34
+ if (!childElement.props.id) {
35
+ throw new Error('If ComboboxCustom is interactive, it must have an id');
36
+ }
37
+ acc.customIds.push(childElement.props.id);
39
38
  }
40
- allOptions.push({
41
- value: props.value,
42
- label,
43
- displayValue: props.displayValue,
44
- description: props.description,
39
+ }
40
+ return acc;
41
+ }, {
42
+ optionsChildren: [],
43
+ customIds: [],
44
+ restChildren: [],
45
+ interactiveChildren: [],
46
+ });
47
+ return result;
48
+ }, [children]);
49
+ const options = React.useMemo(() => {
50
+ const allOptions = {};
51
+ optionsChildren.map((child) => {
52
+ const props = child.props;
53
+ let label = props.displayValue || '';
54
+ if (!props.displayValue) {
55
+ let childrenLabel = '';
56
+ // go over children and find all strings
57
+ React.Children.forEach(props.children, (child) => {
58
+ if (typeof child === 'string') {
59
+ childrenLabel += child;
60
+ }
61
+ else {
62
+ throw new Error('If ComboboxOption is not a string, it must have a displayValue prop');
63
+ }
45
64
  });
65
+ label = childrenLabel;
46
66
  }
67
+ allOptions[props.value] = {
68
+ value: props.value,
69
+ label,
70
+ displayValue: props.displayValue,
71
+ description: props.description,
72
+ };
47
73
  });
48
74
  return allOptions;
49
- }, [children]);
50
- const preSelectedOptions = (initialValue || [])
51
- .map((value) => options.find((option) => option.value === value))
52
- .filter(isOption);
75
+ }, [optionsChildren]);
76
+ const preSelectedOptions = React.useMemo(() => (initialValue || []).reduce((acc, value) => {
77
+ const option = options[value];
78
+ if (isOption(option)) {
79
+ acc[value] = option;
80
+ }
81
+ return acc;
82
+ }, {}), [initialValue, options]);
53
83
  const [selectedOptions, setSelectedOptions] = React.useState(preSelectedOptions);
54
- const [prevSelectedHash, setPrevSelectedHash] = React.useState(JSON.stringify(selectedOptions));
55
- const optionsChildren = React.useMemo(() => {
56
- const valuesArray = Array.from(options);
57
- const children_ = React.Children.toArray(children).filter((child) => isComboboxOption(child));
58
- const activeValue = valuesArray.find((item) => item.label === inputValue);
59
- if (activeValue && !multiple)
60
- return children_;
61
- if (inputValue === '' && !multiple)
62
- return children_;
63
- return children_.filter((child) => {
64
- const { value } = child.props;
65
- const option = valuesArray.find((item) => item.value === value);
66
- if (!option)
67
- return false;
68
- const isSelected = selectedOptions.some((selectedOption) => selectedOption.value === value);
69
- // show what we search for, and all selected options
70
- return filter(inputValue, { ...option }) || isSelected;
71
- });
72
- }, [options, children, multiple, inputValue, selectedOptions, filter]);
73
- const customIds = React.useMemo(() => {
74
- // find all custom components with `interactive=true` and generate random values for them
75
- const children_ = React.Children.toArray(children).filter((child) => {
76
- return isInteractiveComboboxCustom(child);
77
- });
78
- // return all ids
79
- return children_.map((child) => {
80
- if (!child.props.id)
81
- throw new Error('If ComboboxCustom is interactive, it must have an id');
82
- return child.props.id;
83
- });
84
- }, [children]);
85
- const optionValues = React.useMemo(() => {
86
- // create an index map of values from optionsChildren
87
- const options = optionsChildren.map((child) => {
88
- const { value } = child.props;
89
- return value;
90
- });
91
- return [...customIds, ...options];
92
- }, [customIds, optionsChildren]);
93
- const restChildren = React.useMemo(() => {
94
- return React.Children.toArray(children).filter((child) => {
95
- return !isComboboxOption(child);
96
- });
97
- }, [children]);
84
+ const { filteredOptions, filteredOptionsChildren } = React.useMemo(() => {
85
+ const filteredOptions = [];
86
+ const filteredOptionsChildren = Object.keys(options)
87
+ .map((option, index) => {
88
+ if (multiple && selectedOptions[option]) {
89
+ filteredOptions.push(options[option].value);
90
+ return optionsChildren[index];
91
+ }
92
+ if (filter(inputValue, options[option])) {
93
+ filteredOptions.push(options[option].value);
94
+ return optionsChildren[index];
95
+ }
96
+ })
97
+ .filter((child) => child);
98
+ return { filteredOptions, filteredOptionsChildren };
99
+ // eslint-disable-next-line react-hooks/exhaustive-deps
100
+ }, [inputValue, multiple, options, optionsChildren, selectedOptions]);
98
101
  return {
99
- optionsChildren,
100
- optionValues,
102
+ filteredOptionsChildren,
103
+ filteredOptions,
101
104
  restChildren,
102
105
  options,
103
106
  customIds,
104
107
  selectedOptions,
108
+ interactiveChildren,
105
109
  setSelectedOptions,
106
- prevSelectedHash,
107
- setPrevSelectedHash,
108
110
  };
109
111
  }
110
112
 
@@ -0,0 +1,76 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ var useDebounce = require('../../../utilities/useDebounce.js');
5
+ var ComboboxIdContext = require('./ComboboxIdContext.js');
6
+
7
+ const useComboboxKeyboard = ({ readOnly, disabled, interactiveChildren, filteredOptions, inputValue, selectedOptions, multiple, open, options, setOpen, handleSelectOption, }) => {
8
+ const { activeIndex } = ComboboxIdContext.useComboboxId();
9
+ // handle keyboard navigation in the list
10
+ const handleKeyDownFunc = (event) => {
11
+ if (readOnly || disabled)
12
+ return;
13
+ if (!event)
14
+ return;
15
+ switch (event.key) {
16
+ case 'ArrowDown':
17
+ event.preventDefault();
18
+ if (open)
19
+ break;
20
+ setOpen(true);
21
+ break;
22
+ case 'ArrowUp':
23
+ event.preventDefault();
24
+ /* If we are on the first item, close */
25
+ if (activeIndex !== 0)
26
+ break;
27
+ setOpen(false);
28
+ break;
29
+ case 'Enter':
30
+ event.preventDefault();
31
+ // ignore if it is closed
32
+ if (!open)
33
+ break;
34
+ // check if we are in the custom components
35
+ if (activeIndex <= interactiveChildren.length - 1) {
36
+ const selectedComponent = interactiveChildren[activeIndex];
37
+ if (selectedComponent.props.onSelect) {
38
+ selectedComponent?.props.onSelect();
39
+ return;
40
+ }
41
+ }
42
+ // if we are in the options, find the actual index
43
+ // eslint-disable-next-line no-case-declarations
44
+ const valueIndex = activeIndex - interactiveChildren.length;
45
+ // eslint-disable-next-line no-case-declarations
46
+ const option = filteredOptions[valueIndex];
47
+ handleSelectOption({ option: options[option] });
48
+ break;
49
+ case 'Backspace':
50
+ // if we are in single mode, we need to set selectedOptions to empty
51
+ if (!multiple) {
52
+ const lastOption = Object.keys(selectedOptions).pop();
53
+ lastOption &&
54
+ handleSelectOption({
55
+ option: selectedOptions[lastOption],
56
+ remove: true,
57
+ });
58
+ break;
59
+ }
60
+ if (inputValue === '' && multiple) {
61
+ const lastOption = Object.keys(selectedOptions).pop();
62
+ /* Remove last option, and use handleSelectOption */
63
+ lastOption &&
64
+ handleSelectOption({
65
+ option: selectedOptions[lastOption],
66
+ remove: true,
67
+ });
68
+ }
69
+ break;
70
+ }
71
+ };
72
+ const handleKeyDown = useDebounce(handleKeyDownFunc, 20);
73
+ return handleKeyDown;
74
+ };
75
+
76
+ exports.useComboboxKeyboard = useComboboxKeyboard;
@@ -0,0 +1,78 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ var floatingUi_react = require('../../../packages/react/node_modules/@floating-ui/react/dist/floating-ui.react.js');
5
+ var React = require('react');
6
+ var ReactDOM = require('react-dom');
7
+ var ComboboxIdContext = require('./ComboboxIdContext.js');
8
+ var floatingUi_dom = require('../../../packages/react/node_modules/@floating-ui/dom/dist/floating-ui.dom.js');
9
+ var floatingUi_core = require('../../../packages/react/node_modules/@floating-ui/core/dist/floating-ui.core.js');
10
+
11
+ const useFloatingCombobox = ({ listRef }) => {
12
+ const [open, setOpen] = React.useState(false);
13
+ const { activeIndex } = ComboboxIdContext.useComboboxId();
14
+ const dispatch = ComboboxIdContext.useComboboxIdDispatch();
15
+ // floating UI
16
+ const { refs, floatingStyles, context } = floatingUi_react.useFloating({
17
+ open,
18
+ onOpenChange: (newOpen) => {
19
+ if (!newOpen)
20
+ dispatch?.({ type: 'SET_ACTIVE_INDEX', payload: 0 });
21
+ ReactDOM.flushSync(() => {
22
+ if (refs.floating.current && !newOpen) {
23
+ refs.floating.current.scrollTop = 0;
24
+ }
25
+ setTimeout(() => {
26
+ setOpen(newOpen);
27
+ }, 1);
28
+ });
29
+ },
30
+ whileElementsMounted: (reference, floating, update) => {
31
+ floatingUi_dom.autoUpdate(reference, floating, update);
32
+ return () => {
33
+ floating.scrollTop = 0;
34
+ };
35
+ },
36
+ middleware: [
37
+ floatingUi_dom.flip({ padding: 10 }),
38
+ floatingUi_dom.size({
39
+ apply({ rects, elements }) {
40
+ requestAnimationFrame(() => {
41
+ Object.assign(elements.floating.style, {
42
+ width: `calc(${rects.reference.width}px - calc(var(--fds-spacing-2) * 2))`,
43
+ maxHeight: `200px`,
44
+ });
45
+ });
46
+ },
47
+ }),
48
+ floatingUi_core.offset(10),
49
+ ],
50
+ });
51
+ const role = floatingUi_react.useRole(context, { role: 'listbox' });
52
+ const dismiss = floatingUi_react.useDismiss(context);
53
+ const listNav = floatingUi_react.useListNavigation(context, {
54
+ listRef,
55
+ activeIndex,
56
+ virtual: true,
57
+ scrollItemIntoView: true,
58
+ enabled: open,
59
+ focusItemOnHover: true,
60
+ onNavigate: (index) => {
61
+ dispatch?.({ type: 'SET_ACTIVE_INDEX', payload: index || 0 });
62
+ },
63
+ });
64
+ const { getReferenceProps, getFloatingProps, getItemProps } = floatingUi_react.useInteractions([role, dismiss, listNav]);
65
+ return {
66
+ open,
67
+ setOpen,
68
+ activeIndex,
69
+ refs,
70
+ floatingStyles,
71
+ context,
72
+ getReferenceProps,
73
+ getFloatingProps,
74
+ getItemProps,
75
+ };
76
+ };
77
+
78
+ exports.useFloatingCombobox = useFloatingCombobox;
@@ -5,7 +5,7 @@ var jsxRuntime = require('react/jsx-runtime');
5
5
  var React = require('react');
6
6
  var clsx = require('../../../node_modules/clsx/dist/clsx.js');
7
7
  var akselIcons = require('@navikt/aksel-icons');
8
- var floatingUi_react = require('../../../node_modules/@floating-ui/react/dist/floating-ui.react.js');
8
+ var floatingUi_react = require('../../../packages/react/node_modules/@floating-ui/react/dist/floating-ui.react.js');
9
9
  var useSearch = require('./useSearch.js');
10
10
  var Search_module = require('./Search.module.css.js');
11
11
  var Button = require('../../Button/Button.js');
@@ -12,7 +12,7 @@ function getNodeName(node) {
12
12
  }
13
13
  function getWindow(node) {
14
14
  var _node$ownerDocument;
15
- return (node == null ? void 0 : (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
15
+ return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
16
16
  }
17
17
  function getDocumentElement(node) {
18
18
  var _ref;
@@ -111,18 +111,21 @@ function getNearestOverflowAncestor(node) {
111
111
  }
112
112
  return getNearestOverflowAncestor(parentNode);
113
113
  }
114
- function getOverflowAncestors(node, list) {
114
+ function getOverflowAncestors(node, list, traverseIframes) {
115
115
  var _node$ownerDocument2;
116
116
  if (list === void 0) {
117
117
  list = [];
118
118
  }
119
+ if (traverseIframes === void 0) {
120
+ traverseIframes = true;
121
+ }
119
122
  const scrollableAncestor = getNearestOverflowAncestor(node);
120
123
  const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
121
124
  const win = getWindow(scrollableAncestor);
122
125
  if (isBody) {
123
- return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : []);
126
+ return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], win.frameElement && traverseIframes ? getOverflowAncestors(win.frameElement) : []);
124
127
  }
125
- return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor));
128
+ return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
126
129
  }
127
130
 
128
131
  exports.getComputedStyle = getComputedStyle;
@@ -1,6 +1,11 @@
1
1
  'use client';
2
2
  'use strict';
3
3
 
4
+ /**
5
+ * Custom positioning reference element.
6
+ * @see https://floating-ui.com/docs/virtual-elements
7
+ */
8
+
4
9
  const min = Math.min;
5
10
  const max = Math.max;
6
11
  const round = Math.round;
@@ -3,7 +3,7 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e))for(t=0;t<e.length;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);else for(t in e)e[t]&&(n&&(n+=" "),n+=t);return n}function clsx(){for(var e,t,f=0,n="";f<arguments.length;)(e=arguments[f++])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
6
+ function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
7
7
 
8
8
  exports.clsx = clsx;
9
9
  exports.default = clsx;
@@ -0,0 +1,9 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ function clsx(){for(var t,r=0,e="",n=arguments.length;r<n;r++)(t=arguments[r])&&"string"==typeof t&&(e+=(e&&" ")+t);return e}
7
+
8
+ exports.clsx = clsx;
9
+ exports.default = clsx;
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  'use strict';
3
3
 
4
- var floatingUi_utils = require('../../utils/dist/floating-ui.utils.js');
4
+ var floatingUi_utils = require('../../../../../../node_modules/@floating-ui/utils/dist/floating-ui.utils.js');
5
5
 
6
6
  function computeCoordsFromPlacement(_ref, placement, rtl) {
7
7
  let {
@@ -61,7 +61,7 @@ function computeCoordsFromPlacement(_ref, placement, rtl) {
61
61
 
62
62
  /**
63
63
  * Computes the `x` and `y` coordinates that will place the floating element
64
- * next to a reference element when it is given a certain positioning strategy.
64
+ * next to a given reference element.
65
65
  *
66
66
  * This export does not have any `platform` interface logic. You will need to
67
67
  * write one for the platform you are using Floating UI with.
@@ -139,7 +139,6 @@ const computePosition = async (reference, floating, config) => {
139
139
  } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
140
140
  }
141
141
  i = -1;
142
- continue;
143
142
  }
144
143
  }
145
144
  return {
@@ -202,6 +201,7 @@ async function detectOverflow(state, options) {
202
201
  y: 1
203
202
  };
204
203
  const elementClientRect = floatingUi_utils.rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
204
+ elements,
205
205
  rect,
206
206
  offsetParent,
207
207
  strategy
@@ -229,7 +229,8 @@ const arrow = options => ({
229
229
  placement,
230
230
  rects,
231
231
  platform,
232
- elements
232
+ elements,
233
+ middlewareData
233
234
  } = state;
234
235
  // Since `element` is required, we don't Partial<> the type.
235
236
  const {
@@ -277,16 +278,20 @@ const arrow = options => ({
277
278
 
278
279
  // If the reference is small enough that the arrow's padding causes it to
279
280
  // to point to nothing for an aligned placement, adjust the offset of the
280
- // floating element itself. This stops `shift()` from taking action, but can
281
- // be worked around by calling it again after the `arrow()` if desired.
282
- const shouldAddOffset = floatingUi_utils.getAlignment(placement) != null && center != offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
283
- const alignmentOffset = shouldAddOffset ? center < min$1 ? min$1 - center : max - center : 0;
281
+ // floating element itself. To ensure `shift()` continues to take action,
282
+ // a single reset is performed when this is true.
283
+ const shouldAddOffset = !middlewareData.arrow && floatingUi_utils.getAlignment(placement) != null && center !== offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
284
+ const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max : 0;
284
285
  return {
285
- [axis]: coords[axis] - alignmentOffset,
286
+ [axis]: coords[axis] + alignmentOffset,
286
287
  data: {
287
288
  [axis]: offset,
288
- centerOffset: center - offset + alignmentOffset
289
- }
289
+ centerOffset: center - offset - alignmentOffset,
290
+ ...(shouldAddOffset && {
291
+ alignmentOffset
292
+ })
293
+ },
294
+ reset: shouldAddOffset
290
295
  };
291
296
  }
292
297
  });
@@ -305,7 +310,7 @@ const flip = function (options) {
305
310
  name: 'flip',
306
311
  options,
307
312
  async fn(state) {
308
- var _middlewareData$flip;
313
+ var _middlewareData$arrow, _middlewareData$flip;
309
314
  const {
310
315
  placement,
311
316
  middlewareData,
@@ -323,6 +328,14 @@ const flip = function (options) {
323
328
  flipAlignment = true,
324
329
  ...detectOverflowOptions
325
330
  } = floatingUi_utils.evaluate(options, state);
331
+
332
+ // If a reset by the arrow was caused due to an alignment offset being
333
+ // added, we should skip any logic now since `flip()` has already done its
334
+ // work.
335
+ // https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643
336
+ if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
337
+ return {};
338
+ }
326
339
  const side = floatingUi_utils.getSide(placement);
327
340
  const isBasePlacement = floatingUi_utils.getSide(initialPlacement) === initialPlacement;
328
341
  const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
@@ -400,6 +413,7 @@ const flip = function (options) {
400
413
 
401
414
  // For type backwards-compatibility, the `OffsetOptions` type was also
402
415
  // Derivable.
416
+
403
417
  async function convertValueToCoords(state, options) {
404
418
  const {
405
419
  placement,
@@ -413,8 +427,6 @@ async function convertValueToCoords(state, options) {
413
427
  const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;
414
428
  const crossAxisMulti = rtl && isVertical ? -1 : 1;
415
429
  const rawValue = floatingUi_utils.evaluate(options, state);
416
-
417
- // eslint-disable-next-line prefer-const
418
430
  let {
419
431
  mainAxis,
420
432
  crossAxis,
@@ -456,15 +468,27 @@ const offset = function (options) {
456
468
  name: 'offset',
457
469
  options,
458
470
  async fn(state) {
471
+ var _middlewareData$offse, _middlewareData$arrow;
459
472
  const {
460
473
  x,
461
- y
474
+ y,
475
+ placement,
476
+ middlewareData
462
477
  } = state;
463
478
  const diffCoords = await convertValueToCoords(state, options);
479
+
480
+ // If the placement is the same and the arrow caused an alignment offset
481
+ // then we don't need to change the positioning coordinates.
482
+ if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
483
+ return {};
484
+ }
464
485
  return {
465
486
  x: x + diffCoords.x,
466
487
  y: y + diffCoords.y,
467
- data: diffCoords
488
+ data: {
489
+ ...diffCoords,
490
+ placement
491
+ }
468
492
  };
469
493
  }
470
494
  };