@qualtrics/ui-react 2.85.2 → 2.85.5

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 (122) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/__node_modules/@radix-ui/primitive/dist/index.js +14 -3
  3. package/dist/__node_modules/@radix-ui/primitive/dist/internal/is-development.false.js +4 -0
  4. package/dist/__node_modules/@radix-ui/react-arrow/dist/index.js +9 -6
  5. package/dist/__node_modules/@radix-ui/react-collection/dist/index.js +263 -153
  6. package/dist/__node_modules/@radix-ui/react-compose-refs/dist/index.js +8 -1
  7. package/dist/__node_modules/@radix-ui/react-context/dist/index.js +35 -12
  8. package/dist/__node_modules/@radix-ui/react-direction/dist/index.js +16 -6
  9. package/dist/__node_modules/@radix-ui/react-dismissable-layer/dist/index.js +172 -43
  10. package/dist/__node_modules/@radix-ui/react-dropdown-menu/dist/index.js +76 -95
  11. package/dist/__node_modules/@radix-ui/react-focus-guards/dist/index.js +30 -6
  12. package/dist/__node_modules/@radix-ui/react-focus-scope/dist/index.js +111 -30
  13. package/dist/__node_modules/@radix-ui/react-id/dist/index.js +6 -0
  14. package/dist/__node_modules/@radix-ui/react-menu/dist/index.js +232 -197
  15. package/dist/__node_modules/@radix-ui/react-popper/dist/index.js +104 -49
  16. package/dist/__node_modules/@radix-ui/react-portal/dist/index.js +10 -8
  17. package/dist/__node_modules/@radix-ui/react-presence/dist/index.js +72 -14
  18. package/dist/__node_modules/@radix-ui/react-primitive/dist/index.js +8 -2
  19. package/dist/__node_modules/@radix-ui/react-roving-focus/dist/index.js +52 -18
  20. package/dist/__node_modules/@radix-ui/react-slot/dist/index.js +106 -54
  21. package/dist/__node_modules/@radix-ui/react-use-callback-ref/dist/index.js +17 -4
  22. package/dist/__node_modules/@radix-ui/react-use-controllable-state/dist/index.js +14 -4
  23. package/dist/__node_modules/@radix-ui/react-use-effect-event/dist/index.js +6 -1
  24. package/dist/__node_modules/@radix-ui/react-use-is-hydrated/dist/index.js +37 -0
  25. package/dist/__node_modules/@radix-ui/react-use-layout-effect/dist/index.js +1 -1
  26. package/dist/__node_modules/@radix-ui/react-use-size/dist/index.js +28 -15
  27. package/dist/__shared/cjs/{index-e03dac36.js → index-bd03241f.js} +213 -208
  28. package/dist/__shared/cjs/{index-507024ee.js → index-ccb5282a.js} +12 -3
  29. package/dist/components/Accordion/Accordion2.js +3 -3
  30. package/dist/components/Button/Button.js +52 -6
  31. package/dist/components/Button/Button2.js +6 -52
  32. package/dist/components/Button/index.js +1 -1
  33. package/dist/components/ButtonGroup/ButtonGroup2.js +3 -3
  34. package/dist/components/Checkbox/Checkbox2.js +3 -3
  35. package/dist/components/ColorPicker/ColorPicker2.js +3 -3
  36. package/dist/components/ColorPicker/ColorPickerFlyout.js +1 -1
  37. package/dist/components/Combobox/Combobox2.js +3 -3
  38. package/dist/components/ConfigPane/ConfigPane.js +6 -2
  39. package/dist/components/ConfigPane/ConfigPane2.js +3 -3
  40. package/dist/components/Divider/Divider2.js +3 -3
  41. package/dist/components/Dropdown/ChildIndexContext/reach-descendants.js +1 -1
  42. package/dist/components/Dropdown/Dropdown2.js +3 -3
  43. package/dist/components/FilePicker/FilePicker.js +1 -1
  44. package/dist/components/FilePicker/FilePicker2.js +3 -3
  45. package/dist/components/FormField/Caption.js +3 -3
  46. package/dist/components/FormField/FormField2.js +3 -3
  47. package/dist/components/FullScreenTakeover/FullScreenTakeover2.js +3 -3
  48. package/dist/components/Icon/IconTypes.js +1 -0
  49. package/dist/components/IconButton/IconButton2.js +3 -3
  50. package/dist/components/InlineInput/InlineInput2.js +3 -3
  51. package/dist/components/Input/Input2.js +3 -3
  52. package/dist/components/InputGroup/InputGroup2.js +3 -3
  53. package/dist/components/Label/Label2.js +3 -3
  54. package/dist/components/Link/Link2.js +3 -3
  55. package/dist/components/LoadingSpinner/LoadingSpinner2.js +3 -3
  56. package/dist/components/LogicEditor/LogicEditor2.js +3 -3
  57. package/dist/components/Modal/Modal2.js +3 -3
  58. package/dist/components/NewMenu/NewMenu.js +3 -3
  59. package/dist/components/NumberStepper/NumberStepper2.js +3 -3
  60. package/dist/components/PageLayout/PageLayout.js +3 -3
  61. package/dist/components/Pagination/Pagination2.js +3 -3
  62. package/dist/components/Pagination/PaginationNextButton.js +1 -1
  63. package/dist/components/Pagination/PaginationPreviousButton.js +1 -1
  64. package/dist/components/Popover/Popover2.js +3 -3
  65. package/dist/components/QuickSearch/QuickSearch.js +1 -1
  66. package/dist/components/QuickSearch/QuickSearch2.js +3 -3
  67. package/dist/components/Radio/Radio2.js +3 -3
  68. package/dist/components/SearchInput/SearchInput2.js +3 -3
  69. package/dist/components/SidebarNav/SidebarNav2.js +3 -3
  70. package/dist/components/Slider/Slider2.js +3 -3
  71. package/dist/components/Switch/Switch2.js +3 -3
  72. package/dist/components/Table/Table2.js +3 -3
  73. package/dist/components/Tabs/Tabs2.js +3 -3
  74. package/dist/components/Tooltip/Tooltip2.js +3 -3
  75. package/dist/components/deprecated_ColorPicker/ColorPicker.js +1 -1
  76. package/dist/components/deprecated_ColorPicker/ColorPicker2.js +3 -3
  77. package/dist/components/deprecated_NumberStepper/NumberStepper2.js +3 -3
  78. package/dist/components/deprecated_Tabs/Tabs2.js +3 -3
  79. package/dist/components/deprecated_Toolbar/Toolbar2.js +3 -3
  80. package/dist/design-tokens/less/typography.js +3 -3
  81. package/dist/hooks/useOverlay/useOverlay2.js +3 -3
  82. package/dist/hooks/useScreenReaderAnnouncement/useScreenReaderAnnouncement2.js +3 -3
  83. package/dist/icons/Icon.js +3 -3
  84. package/dist/icons/components/PulseIcon.js +11 -0
  85. package/dist/icons/index.d.ts +2 -0
  86. package/dist/icons/index.es.js +1 -0
  87. package/dist/icons/index.js +2 -1
  88. package/dist/index.d.ts +72 -71
  89. package/dist/index.es.js +2 -2
  90. package/dist/index.js +3 -3
  91. package/dist/next/AdvancedTable/AdvancedTable2.js +3 -3
  92. package/dist/next/Chat/Loader.js +1 -1
  93. package/dist/next/CollapsibleSearchInput/CollapsibleSearchInput2.js +3 -3
  94. package/dist/next/Combobox/Combobox2.js +3 -3
  95. package/dist/next/Drawer/Drawer2.js +3 -3
  96. package/dist/next/FilterAnchor/FilterAnchor2.js +3 -3
  97. package/dist/next/Form/FormFields/InputField.js +3 -3
  98. package/dist/next/Indicator/Indicator2.js +3 -3
  99. package/dist/next/Input/Input2.js +3 -3
  100. package/dist/next/LoadingSpinner/LoadingSpinner2.js +3 -3
  101. package/dist/next/Menu/Hooks/useFlyoutNode.js +48 -0
  102. package/dist/next/Menu/Menu.js +2 -2
  103. package/dist/next/Menu/Menu2.js +3 -3
  104. package/dist/next/Menu/MenuButton.js +6 -5
  105. package/dist/next/Menu/MenuItem.js +5 -4
  106. package/dist/next/Menu/MenuPane.js +20 -19
  107. package/dist/next/Menu/PaneChildren.js +15 -10
  108. package/dist/next/Menu/SubMenu.js +22 -21
  109. package/dist/next/PhoneNumberInput/PhoneNumberInput2.js +3 -3
  110. package/dist/next/Select/Select2.js +3 -3
  111. package/dist/next/SplitButton/SplitButton.js +1 -1
  112. package/dist/next/SplitButton/SplitButton2.js +3 -3
  113. package/dist/next/TimePicker/TimePicker2.js +3 -3
  114. package/dist/next/ToggleButton/ToggleButton.js +1 -1
  115. package/dist/next/ToggleButton/styles.js +3 -3
  116. package/dist/next/index.js +1581 -850
  117. package/dist/translations-en.js +71 -71
  118. package/dist/utils/Flyout/Flyout2.js +3 -3
  119. package/icons/package.json +4 -4
  120. package/next/package.json +5 -5
  121. package/package.json +16 -16
  122. package/dist/__node_modules/@radix-ui/react-use-escape-keydown/dist/index.js +0 -23
@@ -1,6 +1,10 @@
1
1
  import * as React from 'react';
2
2
 
3
- // packages/react/compose-refs/src/compose-refs.tsx
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", {
5
+ value,
6
+ configurable: true
7
+ });
4
8
  function setRef(ref, value) {
5
9
  if (typeof ref === "function") {
6
10
  return ref(value);
@@ -8,6 +12,7 @@ function setRef(ref, value) {
8
12
  ref.current = value;
9
13
  }
10
14
  }
15
+ __name(setRef, "setRef");
11
16
  function composeRefs() {
12
17
  for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
13
18
  refs[_key] = arguments[_key];
@@ -35,11 +40,13 @@ function composeRefs() {
35
40
  }
36
41
  };
37
42
  }
43
+ __name(composeRefs, "composeRefs");
38
44
  function useComposedRefs() {
39
45
  for (var _len2 = arguments.length, refs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
40
46
  refs[_key2] = arguments[_key2];
41
47
  }
42
48
  return React.useCallback(composeRefs(...refs), refs);
43
49
  }
50
+ __name(useComposedRefs, "useComposedRefs");
44
51
 
45
52
  export { composeRefs, useComposedRefs };
@@ -3,9 +3,16 @@ import * as React from 'react';
3
3
 
4
4
  const _excluded = ["children"],
5
5
  _excluded2 = ["scope", "children"];
6
+ var __defProp = Object.defineProperty;
7
+ var __name = (target, value) => __defProp(target, "name", {
8
+ value,
9
+ configurable: true
10
+ });
11
+ // @__NO_SIDE_EFFECTS__
6
12
  function createContext2(rootComponentName, defaultContext) {
7
13
  const Context = /*#__PURE__*/React.createContext(defaultContext);
8
- const Provider = props => {
14
+ Context.displayName = rootComponentName + "Context";
15
+ const Provider = /* @__PURE__ */__name(props => {
9
16
  const children = props.children,
10
17
  context = _objectWithoutProperties(props, _excluded);
11
18
  const value = React.useMemo(() => context, Object.values(context));
@@ -13,24 +20,32 @@ function createContext2(rootComponentName, defaultContext) {
13
20
  value,
14
21
  children
15
22
  });
16
- };
23
+ }, "Provider");
17
24
  Provider.displayName = rootComponentName + "Provider";
18
25
  function useContext2(consumerName) {
26
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
27
+ const _options$optional = options.optional,
28
+ optional = _options$optional === void 0 ? false : _options$optional;
19
29
  const context = React.useContext(Context);
20
30
  if (context) return context;
21
31
  if (defaultContext !== void 0) return defaultContext;
32
+ if (optional) return void 0;
22
33
  throw new Error("`".concat(consumerName, "` must be used within `").concat(rootComponentName, "`"));
23
34
  }
35
+ __name(useContext2, "useContext");
24
36
  return [Provider, useContext2];
25
37
  }
38
+ __name(createContext2, "createContext");
39
+ // @__NO_SIDE_EFFECTS__
26
40
  function createContextScope(scopeName) {
27
41
  let createContextScopeDeps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
28
42
  let defaultContexts = [];
29
43
  function createContext3(rootComponentName, defaultContext) {
30
44
  const BaseContext = /*#__PURE__*/React.createContext(defaultContext);
45
+ BaseContext.displayName = rootComponentName + "Context";
31
46
  const index = defaultContexts.length;
32
47
  defaultContexts = [...defaultContexts, defaultContext];
33
- const Provider = props => {
48
+ const Provider = /* @__PURE__ */__name(props => {
34
49
  var _scope$scopeName;
35
50
  const scope = props.scope,
36
51
  children = props.children,
@@ -41,23 +56,29 @@ function createContextScope(scopeName) {
41
56
  value,
42
57
  children
43
58
  });
44
- };
59
+ }, "Provider");
45
60
  Provider.displayName = rootComponentName + "Provider";
46
61
  function useContext2(consumerName, scope) {
47
62
  var _scope$scopeName2;
63
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
64
+ const _options$optional2 = options.optional,
65
+ optional = _options$optional2 === void 0 ? false : _options$optional2;
48
66
  const Context = (scope === null || scope === void 0 || (_scope$scopeName2 = scope[scopeName]) === null || _scope$scopeName2 === void 0 ? void 0 : _scope$scopeName2[index]) || BaseContext;
49
67
  const context = React.useContext(Context);
50
68
  if (context) return context;
51
69
  if (defaultContext !== void 0) return defaultContext;
70
+ if (optional) return void 0;
52
71
  throw new Error("`".concat(consumerName, "` must be used within `").concat(rootComponentName, "`"));
53
72
  }
73
+ __name(useContext2, "useContext");
54
74
  return [Provider, useContext2];
55
75
  }
56
- const createScope = () => {
76
+ __name(createContext3, "createContext");
77
+ const createScope = /* @__PURE__ */__name(() => {
57
78
  const scopeContexts = defaultContexts.map(defaultContext => {
58
79
  return /*#__PURE__*/React.createContext(defaultContext);
59
80
  });
60
- return function useScope(scope) {
81
+ return /* @__PURE__ */__name(function useScope(scope) {
61
82
  const contexts = (scope === null || scope === void 0 ? void 0 : scope[scopeName]) || scopeContexts;
62
83
  return React.useMemo(() => ({
63
84
  ["__scope".concat(scopeName)]: {
@@ -65,23 +86,24 @@ function createContextScope(scopeName) {
65
86
  [scopeName]: contexts
66
87
  }
67
88
  }), [scope, contexts]);
68
- };
69
- };
89
+ }, "useScope");
90
+ }, "createScope");
70
91
  createScope.scopeName = scopeName;
71
92
  return [createContext3, composeContextScopes(createScope, ...createContextScopeDeps)];
72
93
  }
94
+ __name(createContextScope, "createContextScope");
73
95
  function composeContextScopes() {
74
96
  for (var _len = arguments.length, scopes = new Array(_len), _key = 0; _key < _len; _key++) {
75
97
  scopes[_key] = arguments[_key];
76
98
  }
77
99
  const baseScope = scopes[0];
78
100
  if (scopes.length === 1) return baseScope;
79
- const createScope = () => {
101
+ const createScope = /* @__PURE__ */__name(() => {
80
102
  const scopeHooks = scopes.map(createScope2 => ({
81
103
  useScope: createScope2(),
82
104
  scopeName: createScope2.scopeName
83
105
  }));
84
- return function useComposedScopes(overrideScopes) {
106
+ return /* @__PURE__ */__name(function useComposedScopes(overrideScopes) {
85
107
  const nextScopes = scopeHooks.reduce((nextScopes2, _ref) => {
86
108
  let useScope = _ref.useScope,
87
109
  scopeName = _ref.scopeName;
@@ -95,10 +117,11 @@ function composeContextScopes() {
95
117
  return React.useMemo(() => ({
96
118
  ["__scope".concat(baseScope.scopeName)]: nextScopes
97
119
  }), [nextScopes]);
98
- };
99
- };
120
+ }, "useComposedScopes");
121
+ }, "createScope");
100
122
  createScope.scopeName = baseScope.scopeName;
101
123
  return createScope;
102
124
  }
125
+ __name(composeContextScopes, "composeContextScopes");
103
126
 
104
127
  export { createContext2 as createContext, createContextScope };
@@ -1,19 +1,29 @@
1
1
  import * as React from 'react';
2
2
 
3
- // packages/react/direction/src/direction.tsx
3
+ "use client";
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", {
7
+ value,
8
+ configurable: true
9
+ });
10
+ var Direction = {
11
+ LTR: "ltr",
12
+ RTL: "rtl"
13
+ };
4
14
  var DirectionContext = /*#__PURE__*/React.createContext(void 0);
5
- var DirectionProvider = props => {
15
+ var DirectionProvider = /* @__PURE__ */__name(props => {
6
16
  const dir = props.dir,
7
17
  children = props.children;
8
18
  return /* @__PURE__ */React.createElement(DirectionContext.Provider, {
9
19
  value: dir,
10
20
  children
11
21
  });
12
- };
22
+ }, "DirectionProvider");
13
23
  function useDirection(localDir) {
14
24
  const globalDir = React.useContext(DirectionContext);
15
- return localDir || globalDir || "ltr";
25
+ return localDir || globalDir || Direction.LTR;
16
26
  }
17
- var Provider = DirectionProvider;
27
+ __name(useDirection, "useDirection");
18
28
 
19
- export { DirectionProvider, Provider, useDirection };
29
+ export { DirectionProvider, DirectionProvider as Provider, useDirection };
@@ -5,11 +5,14 @@ import { composeEventHandlers } from '../../primitive/dist/index.js';
5
5
  import { Primitive, dispatchDiscreteCustomEvent } from '../../react-primitive/dist/index.js';
6
6
  import { useComposedRefs } from '../../react-compose-refs/dist/index.js';
7
7
  import { useCallbackRef } from '../../react-use-callback-ref/dist/index.js';
8
- import { useEscapeKeydown } from '../../react-use-escape-keydown/dist/index.js';
9
8
 
10
9
  "use client";
11
- const _excluded = ["disableOutsidePointerEvents", "onEscapeKeyDown", "onPointerDownOutside", "onFocusOutside", "onInteractOutside", "onDismiss"];
12
- var DISMISSABLE_LAYER_NAME = "DismissableLayer";
10
+ const _excluded = ["disableOutsidePointerEvents", "deferPointerDownOutside", "onEscapeKeyDown", "onPointerDownOutside", "onFocusOutside", "onInteractOutside", "onDismiss"];
11
+ var __defProp = Object.defineProperty;
12
+ var __name = (target, value) => __defProp(target, "name", {
13
+ value,
14
+ configurable: true
15
+ });
13
16
  var CONTEXT_UPDATE = "dismissableLayer.update";
14
17
  var POINTER_DOWN_OUTSIDE = "dismissableLayer.pointerDownOutside";
15
18
  var FOCUS_OUTSIDE = "dismissableLayer.focusOutside";
@@ -17,12 +20,23 @@ var originalBodyPointerEvents;
17
20
  var DismissableLayerContext = /*#__PURE__*/React.createContext({
18
21
  layers: /* @__PURE__ */new Set(),
19
22
  layersWithOutsidePointerEventsDisabled: /* @__PURE__ */new Set(),
20
- branches: /* @__PURE__ */new Set()
23
+ branches: /* @__PURE__ */new Set(),
24
+ // Outside elements that belong to a layer's own dismiss affordance (eg, a
25
+ // dialog overlay). Pressing them should dismiss the layer regardless of
26
+ // whether or not they stop propagation.
27
+ //
28
+ // See https://github.com/radix-ui/primitives/issues/3346
29
+ dismissableSurfaces: /* @__PURE__ */new Set()
21
30
  });
22
- var DismissableLayer = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
31
+ var DismissableLayer = /* @__PURE__ */React.forwardRef(
32
+ // blank line to reduce diff noise
33
+ /* @__PURE__ */
34
+ __name(function DismissableLayer2(props, forwardedRef) {
23
35
  var _node$ownerDocument;
24
36
  const _props$disableOutside = props.disableOutsidePointerEvents,
25
37
  disableOutsidePointerEvents = _props$disableOutside === void 0 ? false : _props$disableOutside,
38
+ _props$deferPointerDo = props.deferPointerDownOutside,
39
+ deferPointerDownOutside = _props$deferPointerDo === void 0 ? false : _props$deferPointerDo,
26
40
  onEscapeKeyDown = props.onEscapeKeyDown,
27
41
  onPointerDownOutside = props.onPointerDownOutside,
28
42
  onFocusOutside = props.onFocusOutside,
@@ -38,24 +52,37 @@ var DismissableLayer = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
38
52
  const _React$useState3 = React.useState({}),
39
53
  _React$useState4 = _slicedToArray(_React$useState3, 2),
40
54
  force = _React$useState4[1];
41
- const composedRefs = useComposedRefs(forwardedRef, node2 => setNode(node2));
55
+ const composedRefs = useComposedRefs(forwardedRef, setNode);
42
56
  const layers = Array.from(context.layers);
43
57
  const _slice = [...context.layersWithOutsidePointerEventsDisabled].slice(-1),
44
58
  _slice2 = _slicedToArray(_slice, 1),
45
59
  highestLayerWithOutsidePointerEventsDisabled = _slice2[0];
46
- const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled);
60
+ const highestLayerWithOutsidePointerEventsDisabledIndex = highestLayerWithOutsidePointerEventsDisabled ? layers.indexOf(highestLayerWithOutsidePointerEventsDisabled) : -1;
47
61
  const index = node ? layers.indexOf(node) : -1;
48
62
  const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;
49
63
  const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;
64
+ const isDeferredPointerDownOutsideRef = React.useRef(false);
50
65
  const pointerDownOutside = usePointerDownOutside(event => {
51
- const target = event.target;
52
- const isPointerDownOnBranch = [...context.branches].some(branch => branch.contains(target));
53
- if (!isPointerEventsEnabled || isPointerDownOnBranch) return;
54
66
  onPointerDownOutside === null || onPointerDownOutside === void 0 || onPointerDownOutside(event);
55
67
  onInteractOutside === null || onInteractOutside === void 0 || onInteractOutside(event);
56
68
  if (!event.defaultPrevented) onDismiss === null || onDismiss === void 0 || onDismiss();
57
- }, ownerDocument);
69
+ }, {
70
+ ownerDocument,
71
+ deferPointerDownOutside,
72
+ isDeferredPointerDownOutsideRef,
73
+ dismissableSurfaces: context.dismissableSurfaces,
74
+ shouldHandlePointerDownOutside: React.useCallback(target => {
75
+ if (!(target instanceof Node)) {
76
+ return false;
77
+ }
78
+ const isPointerDownOnBranch = [...context.branches].some(branch => branch.contains(target));
79
+ return isPointerEventsEnabled && !isPointerDownOnBranch;
80
+ }, [context.branches, isPointerEventsEnabled])
81
+ });
58
82
  const focusOutside = useFocusOutside(event => {
83
+ if (deferPointerDownOutside && isDeferredPointerDownOutsideRef.current) {
84
+ return;
85
+ }
59
86
  const target = event.target;
60
87
  const isFocusInBranch = [...context.branches].some(branch => branch.contains(target));
61
88
  if (isFocusInBranch) return;
@@ -63,15 +90,28 @@ var DismissableLayer = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
63
90
  onInteractOutside === null || onInteractOutside === void 0 || onInteractOutside(event);
64
91
  if (!event.defaultPrevented) onDismiss === null || onDismiss === void 0 || onDismiss();
65
92
  }, ownerDocument);
66
- useEscapeKeydown(event => {
67
- const isHighestLayer = index === context.layers.size - 1;
68
- if (!isHighestLayer) return;
93
+ const isHighestLayer = node ? index === layers.length - 1 : false;
94
+ const handleKeyDown = useCallbackRef(event => {
95
+ if (event.key !== "Escape") {
96
+ return;
97
+ }
69
98
  onEscapeKeyDown === null || onEscapeKeyDown === void 0 || onEscapeKeyDown(event);
70
99
  if (!event.defaultPrevented && onDismiss) {
71
100
  event.preventDefault();
72
101
  onDismiss();
73
102
  }
74
- }, ownerDocument);
103
+ });
104
+ React.useEffect(() => {
105
+ if (!isHighestLayer) {
106
+ return;
107
+ }
108
+ ownerDocument.addEventListener("keydown", handleKeyDown, {
109
+ capture: true
110
+ });
111
+ return () => ownerDocument.removeEventListener("keydown", handleKeyDown, {
112
+ capture: true
113
+ });
114
+ }, [ownerDocument, isHighestLayer, handleKeyDown]);
75
115
  React.useEffect(() => {
76
116
  if (!node) return;
77
117
  if (disableOutsidePointerEvents) {
@@ -84,8 +124,11 @@ var DismissableLayer = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
84
124
  context.layers.add(node);
85
125
  dispatchUpdate();
86
126
  return () => {
87
- if (disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1) {
88
- ownerDocument.body.style.pointerEvents = originalBodyPointerEvents;
127
+ if (disableOutsidePointerEvents) {
128
+ context.layersWithOutsidePointerEventsDisabled.delete(node);
129
+ if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
130
+ ownerDocument.body.style.pointerEvents = originalBodyPointerEvents;
131
+ }
89
132
  }
90
133
  };
91
134
  }, [node, ownerDocument, disableOutsidePointerEvents, context]);
@@ -98,7 +141,7 @@ var DismissableLayer = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
98
141
  };
99
142
  }, [node, context]);
100
143
  React.useEffect(() => {
101
- const handleUpdate = () => force({});
144
+ const handleUpdate = /* @__PURE__ */__name(() => force({}), "handleUpdate");
102
145
  document.addEventListener(CONTEXT_UPDATE, handleUpdate);
103
146
  return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);
104
147
  }, []);
@@ -113,10 +156,8 @@ var DismissableLayer = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
113
156
  onBlurCapture: composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture),
114
157
  onPointerDownCapture: composeEventHandlers(props.onPointerDownCapture, pointerDownOutside.onPointerDownCapture)
115
158
  });
116
- });
117
- DismissableLayer.displayName = DISMISSABLE_LAYER_NAME;
118
- var BRANCH_NAME = "DismissableLayerBranch";
119
- var DismissableLayerBranch = /*#__PURE__*/React.forwardRef((props, forwardedRef) => {
159
+ }, "DismissableLayer"));
160
+ var DismissableLayerBranch = /* @__PURE__ */React.forwardRef(/* @__PURE__ */__name(function DismissableLayerBranch2(props, forwardedRef) {
120
161
  const context = React.useContext(DismissableLayerContext);
121
162
  const ref = React.useRef(null);
122
163
  const composedRefs = useComposedRefs(forwardedRef, ref);
@@ -133,39 +174,121 @@ var DismissableLayerBranch = /*#__PURE__*/React.forwardRef((props, forwardedRef)
133
174
  ...props,
134
175
  ref: composedRefs
135
176
  });
136
- });
137
- DismissableLayerBranch.displayName = BRANCH_NAME;
138
- function usePointerDownOutside(onPointerDownOutside) {
139
- let ownerDocument = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : globalThis === null || globalThis === void 0 ? void 0 : globalThis.document;
177
+ }, "DismissableLayerBranch"));
178
+ function useDismissableLayerSurface() {
179
+ const context = React.useContext(DismissableLayerContext);
180
+ const _React$useState5 = React.useState(null),
181
+ _React$useState6 = _slicedToArray(_React$useState5, 2),
182
+ node = _React$useState6[0],
183
+ setNode = _React$useState6[1];
184
+ React.useEffect(() => {
185
+ if (!node) {
186
+ return;
187
+ }
188
+ context.dismissableSurfaces.add(node);
189
+ return () => {
190
+ context.dismissableSurfaces.delete(node);
191
+ };
192
+ }, [node, context.dismissableSurfaces]);
193
+ return setNode;
194
+ }
195
+ __name(useDismissableLayerSurface, "useDismissableLayerSurface");
196
+ var IS_TRUE = /* @__PURE__ */__name(() => true, "IS_TRUE");
197
+ function usePointerDownOutside(onPointerDownOutside, args) {
198
+ const _args$ownerDocument = args.ownerDocument,
199
+ ownerDocument = _args$ownerDocument === void 0 ? globalThis === null || globalThis === void 0 ? void 0 : globalThis.document : _args$ownerDocument,
200
+ _args$deferPointerDow = args.deferPointerDownOutside,
201
+ deferPointerDownOutside = _args$deferPointerDow === void 0 ? false : _args$deferPointerDow,
202
+ isDeferredPointerDownOutsideRef = args.isDeferredPointerDownOutsideRef,
203
+ dismissableSurfaces = args.dismissableSurfaces,
204
+ _args$shouldHandlePoi = args.shouldHandlePointerDownOutside,
205
+ shouldHandlePointerDownOutside = _args$shouldHandlePoi === void 0 ? IS_TRUE : _args$shouldHandlePoi;
140
206
  const handlePointerDownOutside = useCallbackRef(onPointerDownOutside);
141
207
  const isPointerInsideReactTreeRef = React.useRef(false);
208
+ const isPointerDownOutsideRef = React.useRef(false);
209
+ const interceptedOutsideInteractionEventsRef = React.useRef(/* @__PURE__ */new Map());
142
210
  const handleClickRef = React.useRef(() => {});
143
211
  React.useEffect(() => {
144
- const handlePointerDown = event => {
212
+ function resetOutsideInteraction() {
213
+ isPointerDownOutsideRef.current = false;
214
+ isDeferredPointerDownOutsideRef.current = false;
215
+ interceptedOutsideInteractionEventsRef.current.clear();
216
+ }
217
+ __name(resetOutsideInteraction, "resetOutsideInteraction");
218
+ function isOutsideInteractionIntercepted() {
219
+ return Array.from(interceptedOutsideInteractionEventsRef.current.values()).some(Boolean);
220
+ }
221
+ __name(isOutsideInteractionIntercepted, "isOutsideInteractionIntercepted");
222
+ function handleInteractionCapture(event) {
223
+ if (!isPointerDownOutsideRef.current) {
224
+ return;
225
+ }
226
+ const target = event.target;
227
+ const isDismissableSurface = target instanceof Node && [...dismissableSurfaces].some(surface => surface.contains(target));
228
+ if (!isDismissableSurface) {
229
+ interceptedOutsideInteractionEventsRef.current.set(event.type, true);
230
+ }
231
+ if (event.type === "click") {
232
+ window.setTimeout(() => {
233
+ if (isPointerDownOutsideRef.current) {
234
+ handleClickRef.current();
235
+ }
236
+ }, 0);
237
+ }
238
+ }
239
+ __name(handleInteractionCapture, "handleInteractionCapture");
240
+ function handleInteractionBubble(event) {
241
+ if (isPointerDownOutsideRef.current) {
242
+ interceptedOutsideInteractionEventsRef.current.set(event.type, false);
243
+ }
244
+ }
245
+ __name(handleInteractionBubble, "handleInteractionBubble");
246
+ const handlePointerDown = /* @__PURE__ */__name(event => {
145
247
  if (event.target && !isPointerInsideReactTreeRef.current) {
146
248
  let handleAndDispatchPointerDownOutsideEvent2 = function () {
147
- handleAndDispatchCustomEvent(POINTER_DOWN_OUTSIDE, handlePointerDownOutside, eventDetail, {
148
- discrete: true
149
- });
249
+ ownerDocument.removeEventListener("click", handleClickRef.current);
250
+ const wasOutsideInteractionIntercepted = isOutsideInteractionIntercepted();
251
+ resetOutsideInteraction();
252
+ if (!wasOutsideInteractionIntercepted) {
253
+ handleAndDispatchCustomEvent(POINTER_DOWN_OUTSIDE, handlePointerDownOutside, eventDetail, {
254
+ discrete: true
255
+ });
256
+ }
150
257
  };
151
258
  var handleAndDispatchPointerDownOutsideEvent = handleAndDispatchPointerDownOutsideEvent2;
259
+ __name(handleAndDispatchPointerDownOutsideEvent2, "handleAndDispatchPointerDownOutsideEvent");
260
+ if (!shouldHandlePointerDownOutside(event.target)) {
261
+ ownerDocument.removeEventListener("click", handleClickRef.current);
262
+ resetOutsideInteraction();
263
+ isPointerInsideReactTreeRef.current = false;
264
+ return;
265
+ }
152
266
  const eventDetail = {
153
267
  originalEvent: event
154
268
  };
155
- if (event.pointerType === "touch") {
269
+ isPointerDownOutsideRef.current = true;
270
+ isDeferredPointerDownOutsideRef.current = deferPointerDownOutside && event.button === 0;
271
+ interceptedOutsideInteractionEventsRef.current.clear();
272
+ if (!deferPointerDownOutside || event.button !== 0) {
273
+ handleAndDispatchPointerDownOutsideEvent2();
274
+ } else {
156
275
  ownerDocument.removeEventListener("click", handleClickRef.current);
157
276
  handleClickRef.current = handleAndDispatchPointerDownOutsideEvent2;
158
277
  ownerDocument.addEventListener("click", handleClickRef.current, {
159
278
  once: true
160
279
  });
161
- } else {
162
- handleAndDispatchPointerDownOutsideEvent2();
163
280
  }
164
281
  } else {
165
282
  ownerDocument.removeEventListener("click", handleClickRef.current);
283
+ resetOutsideInteraction();
166
284
  }
167
285
  isPointerInsideReactTreeRef.current = false;
168
- };
286
+ }, "handlePointerDown");
287
+ const outsideInteractionEvents = ["pointerup", "mousedown", "mouseup", "touchstart", "touchend", "click"];
288
+ for (const eventName of outsideInteractionEvents) {
289
+ ownerDocument.addEventListener(eventName, handleInteractionCapture, true);
290
+ ownerDocument.addEventListener(eventName, handleInteractionBubble);
291
+ }
169
292
  const timerId = window.setTimeout(() => {
170
293
  ownerDocument.addEventListener("pointerdown", handlePointerDown);
171
294
  }, 0);
@@ -173,19 +296,24 @@ function usePointerDownOutside(onPointerDownOutside) {
173
296
  window.clearTimeout(timerId);
174
297
  ownerDocument.removeEventListener("pointerdown", handlePointerDown);
175
298
  ownerDocument.removeEventListener("click", handleClickRef.current);
299
+ for (const eventName of outsideInteractionEvents) {
300
+ ownerDocument.removeEventListener(eventName, handleInteractionCapture, true);
301
+ ownerDocument.removeEventListener(eventName, handleInteractionBubble);
302
+ }
176
303
  };
177
- }, [ownerDocument, handlePointerDownOutside]);
304
+ }, [ownerDocument, handlePointerDownOutside, deferPointerDownOutside, isDeferredPointerDownOutsideRef, dismissableSurfaces, shouldHandlePointerDownOutside]);
178
305
  return {
179
306
  // ensures we check React component tree (not just DOM tree)
180
- onPointerDownCapture: () => isPointerInsideReactTreeRef.current = true
307
+ onPointerDownCapture: /* @__PURE__ */__name(() => isPointerInsideReactTreeRef.current = true, "onPointerDownCapture")
181
308
  };
182
309
  }
310
+ __name(usePointerDownOutside, "usePointerDownOutside");
183
311
  function useFocusOutside(onFocusOutside) {
184
312
  let ownerDocument = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : globalThis === null || globalThis === void 0 ? void 0 : globalThis.document;
185
313
  const handleFocusOutside = useCallbackRef(onFocusOutside);
186
314
  const isFocusInsideReactTreeRef = React.useRef(false);
187
315
  React.useEffect(() => {
188
- const handleFocus = event => {
316
+ const handleFocus = /* @__PURE__ */__name(event => {
189
317
  if (event.target && !isFocusInsideReactTreeRef.current) {
190
318
  const eventDetail = {
191
319
  originalEvent: event
@@ -194,19 +322,21 @@ function useFocusOutside(onFocusOutside) {
194
322
  discrete: false
195
323
  });
196
324
  }
197
- };
325
+ }, "handleFocus");
198
326
  ownerDocument.addEventListener("focusin", handleFocus);
199
327
  return () => ownerDocument.removeEventListener("focusin", handleFocus);
200
328
  }, [ownerDocument, handleFocusOutside]);
201
329
  return {
202
- onFocusCapture: () => isFocusInsideReactTreeRef.current = true,
203
- onBlurCapture: () => isFocusInsideReactTreeRef.current = false
330
+ onFocusCapture: /* @__PURE__ */__name(() => isFocusInsideReactTreeRef.current = true, "onFocusCapture"),
331
+ onBlurCapture: /* @__PURE__ */__name(() => isFocusInsideReactTreeRef.current = false, "onBlurCapture")
204
332
  };
205
333
  }
334
+ __name(useFocusOutside, "useFocusOutside");
206
335
  function dispatchUpdate() {
207
336
  const event = new CustomEvent(CONTEXT_UPDATE);
208
337
  document.dispatchEvent(event);
209
338
  }
339
+ __name(dispatchUpdate, "dispatchUpdate");
210
340
  function handleAndDispatchCustomEvent(name, handler, detail, _ref) {
211
341
  let discrete = _ref.discrete;
212
342
  const target = detail.originalEvent.target;
@@ -224,7 +354,6 @@ function handleAndDispatchCustomEvent(name, handler, detail, _ref) {
224
354
  target.dispatchEvent(event);
225
355
  }
226
356
  }
227
- var Root = DismissableLayer;
228
- var Branch = DismissableLayerBranch;
357
+ __name(handleAndDispatchCustomEvent, "handleAndDispatchCustomEvent");
229
358
 
230
- export { Branch, DismissableLayer, DismissableLayerBranch, Root };
359
+ export { DismissableLayerBranch as Branch, DismissableLayer, DismissableLayerBranch, DismissableLayer as Root, useDismissableLayerSurface };