tfy-web-components 0.0.34 → 0.0.35

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 (225) hide show
  1. package/README.md +49 -58
  2. package/dist/Button-C77b7jpW.js +284 -0
  3. package/dist/Button-C77b7jpW.js.map +1 -0
  4. package/dist/CompositeItem-BGwD51jI.js +33 -0
  5. package/dist/CompositeItem-BGwD51jI.js.map +1 -0
  6. package/dist/CompositeList-D4xmSZ5V.js +291 -0
  7. package/dist/CompositeList-D4xmSZ5V.js.map +1 -0
  8. package/dist/CompositeRoot-BxrPc7F6.js +351 -0
  9. package/dist/CompositeRoot-BxrPc7F6.js.map +1 -0
  10. package/dist/DirectionContext-Pb9yafF5.js +11 -0
  11. package/dist/DirectionContext-Pb9yafF5.js.map +1 -0
  12. package/dist/FieldItemContext-DRVgx-D1.js +13 -0
  13. package/dist/FieldItemContext-DRVgx-D1.js.map +1 -0
  14. package/dist/{Input-BvwIpntS.js → Input-Dhmo6L2n.js} +100 -78
  15. package/dist/Input-Dhmo6L2n.js.map +1 -0
  16. package/dist/Modal-C4MUy9GD.js +696 -0
  17. package/dist/Modal-C4MUy9GD.js.map +1 -0
  18. package/dist/{MonacoEditorCore-xfpJ6z-E.js → MonacoEditorCore-n-df5f7I.js} +2 -2
  19. package/dist/{MonacoEditorCore-xfpJ6z-E.js.map → MonacoEditorCore-n-df5f7I.js.map} +1 -1
  20. package/dist/Popover-eC_vX5By.js +1074 -0
  21. package/dist/Popover-eC_vX5By.js.map +1 -0
  22. package/dist/ToolbarRootContext-B_HxjkNI.js +11 -0
  23. package/dist/ToolbarRootContext-B_HxjkNI.js.map +1 -0
  24. package/dist/Tooltip-BuGLP-PU.js +4096 -0
  25. package/dist/Tooltip-BuGLP-PU.js.map +1 -0
  26. package/dist/classNames-B1XpQHle.js +44 -0
  27. package/dist/classNames-B1XpQHle.js.map +1 -0
  28. package/dist/components/atoms/Accordion.d.ts +19 -37
  29. package/dist/components/atoms/Accordion.es.js +847 -78
  30. package/dist/components/atoms/Accordion.es.js.map +1 -1
  31. package/dist/components/atoms/AudioPlayer.es.js +9 -9
  32. package/dist/components/atoms/AudioPlayer.es.js.map +1 -1
  33. package/dist/components/atoms/Avatar.d.ts +42 -9
  34. package/dist/components/atoms/Avatar.es.js +491 -36
  35. package/dist/components/atoms/Avatar.es.js.map +1 -1
  36. package/dist/components/atoms/Badge.d.ts +40 -35
  37. package/dist/components/atoms/Badge.es.js +163 -53
  38. package/dist/components/atoms/Badge.es.js.map +1 -1
  39. package/dist/components/atoms/Button.d.ts +37 -16
  40. package/dist/components/atoms/Button.es.js +16 -221
  41. package/dist/components/atoms/Button.es.js.map +1 -1
  42. package/dist/components/atoms/ButtonGroup.d.ts +53 -0
  43. package/dist/components/atoms/ButtonGroup.es.js +349 -0
  44. package/dist/components/atoms/ButtonGroup.es.js.map +1 -0
  45. package/dist/components/atoms/IconButton.d.ts +23 -9
  46. package/dist/components/atoms/IconButton.es.js +82 -16
  47. package/dist/components/atoms/IconButton.es.js.map +1 -1
  48. package/dist/components/atoms/IconProvider.d.ts +1 -1
  49. package/dist/components/atoms/IconProvider.es.js +48 -7
  50. package/dist/components/atoms/IconProvider.es.js.map +1 -1
  51. package/dist/components/atoms/Modal.d.ts +27 -3
  52. package/dist/components/atoms/Modal.es.js +15 -16
  53. package/dist/components/atoms/Modal.es.js.map +1 -1
  54. package/dist/components/atoms/Notification.d.ts +1 -1
  55. package/dist/components/atoms/Notification.es.js +26 -3
  56. package/dist/components/atoms/Notification.es.js.map +1 -1
  57. package/dist/components/atoms/OutlinedRadio.d.ts +6 -2
  58. package/dist/components/atoms/OutlinedRadio.es.js +12 -25
  59. package/dist/components/atoms/OutlinedRadio.es.js.map +1 -1
  60. package/dist/components/atoms/Progress.d.ts +48 -0
  61. package/dist/components/atoms/Progress.es.js +279 -0
  62. package/dist/components/atoms/Progress.es.js.map +1 -0
  63. package/dist/components/atoms/Skeleton.d.ts +9 -3
  64. package/dist/components/atoms/Skeleton.es.js +33 -3
  65. package/dist/components/atoms/Skeleton.es.js.map +1 -1
  66. package/dist/components/atoms/Spinner.d.ts +15 -4
  67. package/dist/components/atoms/Spinner.es.js +86 -22
  68. package/dist/components/atoms/Spinner.es.js.map +1 -1
  69. package/dist/components/atoms/Switch.d.ts +19 -7
  70. package/dist/components/atoms/Switch.es.js +288 -50
  71. package/dist/components/atoms/Switch.es.js.map +1 -1
  72. package/dist/components/atoms/TabButton.d.ts +17 -3
  73. package/dist/components/atoms/TabButton.es.js +647 -25
  74. package/dist/components/atoms/TabButton.es.js.map +1 -1
  75. package/dist/components/atoms/TabPanel.es.js +1 -1
  76. package/dist/components/atoms/Tag.d.ts +43 -0
  77. package/dist/components/atoms/Tag.es.js +219 -0
  78. package/dist/components/atoms/Tag.es.js.map +1 -0
  79. package/dist/components/atoms/Tooltip.d.ts +36 -14
  80. package/dist/components/atoms/Tooltip.es.js +7 -114
  81. package/dist/components/atoms/Tooltip.es.js.map +1 -1
  82. package/dist/components/molecules/Alert.d.ts +1 -1
  83. package/dist/components/molecules/Alert.es.js +13 -9
  84. package/dist/components/molecules/Alert.es.js.map +1 -1
  85. package/dist/components/molecules/CopyField.d.ts +2 -2
  86. package/dist/components/molecules/CopyField.es.js +3 -4
  87. package/dist/components/molecules/CopyField.es.js.map +1 -1
  88. package/dist/components/molecules/CustomDrawer.d.ts +5 -4
  89. package/dist/components/molecules/CustomDrawer.es.js +141 -82
  90. package/dist/components/molecules/CustomDrawer.es.js.map +1 -1
  91. package/dist/components/molecules/Dialog.d.ts +16 -8
  92. package/dist/components/molecules/Dialog.es.js +33 -31
  93. package/dist/components/molecules/Dialog.es.js.map +1 -1
  94. package/dist/components/molecules/ImagesPreview.es.js +15 -11
  95. package/dist/components/molecules/ImagesPreview.es.js.map +1 -1
  96. package/dist/components/molecules/Input.d.ts +1 -1
  97. package/dist/components/molecules/Input.es.js +3 -5
  98. package/dist/components/molecules/Input.es.js.map +1 -1
  99. package/dist/components/molecules/Markdown/ExpandableMarkdown.d.ts +8 -8
  100. package/dist/components/molecules/Markdown/components.d.ts +12 -11
  101. package/dist/components/molecules/Markdown.es.js +26 -49
  102. package/dist/components/molecules/Markdown.es.js.map +1 -1
  103. package/dist/components/molecules/Notify.d.ts +30 -1
  104. package/dist/components/molecules/Notify.es.js +91 -36
  105. package/dist/components/molecules/Notify.es.js.map +1 -1
  106. package/dist/components/molecules/SimpleCodeEditor.es.js +32 -19
  107. package/dist/components/molecules/SimpleCodeEditor.es.js.map +1 -1
  108. package/dist/components/molecules/ToggleButton.d.ts +3 -2
  109. package/dist/components/molecules/ToggleButton.es.js +155 -57
  110. package/dist/components/molecules/ToggleButton.es.js.map +1 -1
  111. package/dist/components/molecules/agent-chat/UserMessage.es.js +2 -2
  112. package/dist/components/molecules/agent-chat/UserMessage.es.js.map +1 -1
  113. package/dist/components/molecules/agent-chat/UserMessageEdit.es.js +5 -5
  114. package/dist/components/molecules/agent-chat/UserMessageEdit.es.js.map +1 -1
  115. package/dist/components/molecules/agent-chat/index.d.ts +0 -6
  116. package/dist/components/molecules/agent-chat.es.js +76 -407
  117. package/dist/components/molecules/agent-chat.es.js.map +1 -1
  118. package/dist/components/molecules/monacoEditorCore/MonacoEditorCore.d.ts +0 -1
  119. package/dist/components/theme/colors.d.ts +17 -53
  120. package/dist/components/theme/colors.es.js +384 -180
  121. package/dist/components/theme/colors.es.js.map +1 -1
  122. package/dist/components/theme/theme.d.ts +14 -11
  123. package/dist/components/theme/theme.es.js +3 -64
  124. package/dist/components/theme/theme.es.js.map +1 -1
  125. package/dist/components/theme/useTheme.es.js +1 -4
  126. package/dist/components/theme/useTheme.es.js.map +1 -1
  127. package/dist/composite-CrCQWAKA.js +108 -0
  128. package/dist/composite-CrCQWAKA.js.map +1 -0
  129. package/dist/composite-DCpXNxz9.js +66 -0
  130. package/dist/composite-DCpXNxz9.js.map +1 -0
  131. package/dist/conversions-CbWPvHRE.js +14 -0
  132. package/dist/conversions-CbWPvHRE.js.map +1 -0
  133. package/dist/error-FX4R42W-.js +6 -0
  134. package/dist/error-FX4R42W-.js.map +1 -0
  135. package/dist/fonts.css +7 -0
  136. package/dist/hooks/useContainerDimensions.d.ts +1 -1
  137. package/dist/index-B806bfA-.js +257 -0
  138. package/dist/index-B806bfA-.js.map +1 -0
  139. package/dist/index-DSVg79g-.js +45 -0
  140. package/dist/index-DSVg79g-.js.map +1 -0
  141. package/dist/index.d.ts +19 -4
  142. package/dist/index.es.js +56 -9
  143. package/dist/index.es.js.map +1 -1
  144. package/dist/inertValue-IJM5NA30.js +11 -0
  145. package/dist/inertValue-IJM5NA30.js.map +1 -0
  146. package/dist/lib/utils.d.ts +1 -0
  147. package/dist/markdown.css +13 -14
  148. package/dist/new-components/atoms/Checkbox.d.ts +6 -0
  149. package/dist/new-components/atoms/Checkbox.es.js +423 -0
  150. package/dist/new-components/atoms/Checkbox.es.js.map +1 -0
  151. package/dist/new-components/atoms/Chip.d.ts +38 -0
  152. package/dist/new-components/atoms/Chip.es.js +269 -0
  153. package/dist/new-components/atoms/Chip.es.js.map +1 -0
  154. package/dist/new-components/atoms/Popover.d.ts +87 -0
  155. package/dist/new-components/atoms/Popover.es.js +21 -0
  156. package/dist/new-components/atoms/Popover.es.js.map +1 -0
  157. package/dist/new-components/atoms/Radio.d.ts +14 -0
  158. package/dist/new-components/atoms/Radio.es.js +536 -0
  159. package/dist/new-components/atoms/Radio.es.js.map +1 -0
  160. package/dist/new-components/atoms/SegmentedControl.d.ts +28 -0
  161. package/dist/new-components/atoms/SegmentedControl.es.js +326 -0
  162. package/dist/new-components/atoms/SegmentedControl.es.js.map +1 -0
  163. package/dist/new-components/atoms/Slider.d.ts +8 -0
  164. package/dist/new-components/atoms/Slider.es.js +1415 -0
  165. package/dist/new-components/atoms/Slider.es.js.map +1 -0
  166. package/dist/new-components/atoms/Toggletip.d.ts +43 -0
  167. package/dist/new-components/atoms/Toggletip.es.js +216 -0
  168. package/dist/new-components/atoms/Toggletip.es.js.map +1 -0
  169. package/dist/new-components/atoms/stories/ThemeComparison.d.ts +8 -0
  170. package/dist/shadowDom-Bq4g0Qeu.js +52 -0
  171. package/dist/shadowDom-Bq4g0Qeu.js.map +1 -0
  172. package/dist/style.css +1 -1
  173. package/dist/theme.css +9 -154
  174. package/dist/tokens.css +1136 -0
  175. package/dist/useAnimationFrame-DwhymJoW.js +108 -0
  176. package/dist/useAnimationFrame-DwhymJoW.js.map +1 -0
  177. package/dist/useAriaLabelledBy-B6n92QBS.js +49 -0
  178. package/dist/useAriaLabelledBy-B6n92QBS.js.map +1 -0
  179. package/dist/useBaseUiId-Ch7ujXpo.js +281 -0
  180. package/dist/useBaseUiId-Ch7ujXpo.js.map +1 -0
  181. package/dist/useButton-PUBhT4Vo.js +235 -0
  182. package/dist/useButton-PUBhT4Vo.js.map +1 -0
  183. package/dist/useControlled-BSyYkg5C.js +65 -0
  184. package/dist/useControlled-BSyYkg5C.js.map +1 -0
  185. package/dist/useIsoLayoutEffect-e9VA-ICd.js +499 -0
  186. package/dist/useIsoLayoutEffect-e9VA-ICd.js.map +1 -0
  187. package/dist/useLabelableId-DCLzrdD-.js +241 -0
  188. package/dist/useLabelableId-DCLzrdD-.js.map +1 -0
  189. package/dist/useOpenInteractionType-DGWLoAqp.js +1086 -0
  190. package/dist/useOpenInteractionType-DGWLoAqp.js.map +1 -0
  191. package/dist/usePopupHandleStore-BdS-xYID.js +2372 -0
  192. package/dist/usePopupHandleStore-BdS-xYID.js.map +1 -0
  193. package/dist/useTimeout-BXf1hDIL.js +46 -0
  194. package/dist/useTimeout-BXf1hDIL.js.map +1 -0
  195. package/dist/useTransitionStatus-C9gg_XJ-.js +202 -0
  196. package/dist/useTransitionStatus-C9gg_XJ-.js.map +1 -0
  197. package/dist/useValueAsRef-BfFRcMg6.js +28 -0
  198. package/dist/useValueAsRef-BfFRcMg6.js.map +1 -0
  199. package/dist/utils/classNames.d.ts +3 -2
  200. package/dist/visuallyHidden-B6H2X3_Y.js +26 -0
  201. package/dist/visuallyHidden-B6H2X3_Y.js.map +1 -0
  202. package/dist/vite-env.d.ts +18 -0
  203. package/package.json +30 -22
  204. package/dist/Input-BvwIpntS.js.map +0 -1
  205. package/dist/Notification-BT4CZ69U.js +0 -39
  206. package/dist/Notification-BT4CZ69U.js.map +0 -1
  207. package/dist/RootFontSizeContext-7vgn7Y_k.js +0 -22
  208. package/dist/RootFontSizeContext-7vgn7Y_k.js.map +0 -1
  209. package/dist/classNames-Dy-RXSjS.js +0 -9
  210. package/dist/classNames-Dy-RXSjS.js.map +0 -1
  211. package/dist/components/molecules/DropdownMenu.d.ts +0 -18
  212. package/dist/components/molecules/DropdownMenu.es.js +0 -104
  213. package/dist/components/molecules/DropdownMenu.es.js.map +0 -1
  214. package/dist/components/molecules/ThumbsFeedback.d.ts +0 -13
  215. package/dist/components/molecules/ThumbsFeedback.es.js +0 -98
  216. package/dist/components/molecules/ThumbsFeedback.es.js.map +0 -1
  217. package/dist/components/molecules/agent-chat/SandboxToolCall.d.ts +0 -15
  218. package/dist/components/molecules/agent-chat/ToolCallCard.d.ts +0 -26
  219. package/dist/components/molecules/agent-chat/ToolCallContentBlock.d.ts +0 -17
  220. package/dist/components/theme/lightColorPlugin.d.ts +0 -1
  221. package/dist/components/theme/lightColorPlugin.es.js +0 -92
  222. package/dist/components/theme/lightColorPlugin.es.js.map +0 -1
  223. package/dist/tailwindPreset.d.ts +0 -144
  224. package/dist/tailwindPreset.es.js +0 -100
  225. package/dist/tailwindPreset.es.js.map +0 -1
@@ -0,0 +1,2372 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ var _a;
5
+ import { t as transitionStatusMapping, u as useTransitionStatus, a as useOpenChangeComplete } from "./useTransitionStatus-C9gg_XJ-.js";
6
+ import * as React from "react";
7
+ import React__default from "react";
8
+ import * as ReactDOM from "react-dom";
9
+ import { j as isHTMLElement, s as getNodeName, v as isShadowRoot, w as getComputedStyle, x as useId, y as isNode, c as createChangeEventDetails, f as focusOut, e as triggerPress, h as escapeKey, p as isElement, z as isLastTraversableNode, A as getParentNode, B as outsidePress, C as useForcedRerendering, n as none, t as triggerHover, D as triggerFocus } from "./useBaseUiId-Ch7ujXpo.js";
10
+ import { a as addEventListener } from "./useValueAsRef-BfFRcMg6.js";
11
+ import { u as useIsoLayoutEffect, a as useStableCallback, b as useRenderElement, d as EMPTY_OBJECT, e as useRefWithInit, i as isReactVersionAtLeast, N as NOOP } from "./useIsoLayoutEffect-e9VA-ICd.js";
12
+ import { a as visuallyHidden } from "./visuallyHidden-B6H2X3_Y.js";
13
+ import { jsx, jsxs } from "react/jsx-runtime";
14
+ import { l as lowerUserAgent, a as lowerPlatform, b as maxTouchPoints, j as jsdom, o as ownerDocument, i as isEventTargetWithin, c as isRootElement, F as FOCUSABLE_ATTRIBUTE, s as shimExports } from "./index-B806bfA-.js";
15
+ import { c as contains, a as activeElement, g as getTarget } from "./shadowDom-Bq4g0Qeu.js";
16
+ import { i as isElementVisible } from "./composite-DCpXNxz9.js";
17
+ import { u as useTimeout, T as Timeout } from "./useTimeout-BXf1hDIL.js";
18
+ const open = "data-open";
19
+ const closed = "data-closed";
20
+ const anchorHidden = "data-anchor-hidden";
21
+ const popupOpen = "data-popup-open";
22
+ const pressed = "data-pressed";
23
+ const TRIGGER_HOOK = {
24
+ [popupOpen]: ""
25
+ };
26
+ const PRESSABLE_TRIGGER_HOOK = {
27
+ [popupOpen]: "",
28
+ [pressed]: ""
29
+ };
30
+ const POPUP_OPEN_HOOK = {
31
+ [open]: ""
32
+ };
33
+ const POPUP_CLOSED_HOOK = {
34
+ [closed]: ""
35
+ };
36
+ const ANCHOR_HIDDEN_HOOK = {
37
+ [anchorHidden]: ""
38
+ };
39
+ const triggerOpenStateMapping = {
40
+ open(value) {
41
+ if (value) {
42
+ return TRIGGER_HOOK;
43
+ }
44
+ return null;
45
+ }
46
+ };
47
+ const pressableTriggerOpenStateMapping = {
48
+ open(value) {
49
+ if (value) {
50
+ return PRESSABLE_TRIGGER_HOOK;
51
+ }
52
+ return null;
53
+ }
54
+ };
55
+ const popupStateMapping = {
56
+ open(value) {
57
+ if (value) {
58
+ return POPUP_OPEN_HOOK;
59
+ }
60
+ return POPUP_CLOSED_HOOK;
61
+ },
62
+ anchorHidden(value) {
63
+ if (value) {
64
+ return ANCHOR_HIDDEN_HOOK;
65
+ }
66
+ return null;
67
+ }
68
+ };
69
+ const popupTransitionStateMapping = {
70
+ ...popupStateMapping,
71
+ ...transitionStatusMapping
72
+ };
73
+ const ios = /^i(os$|p)/.test(lowerPlatform) || lowerPlatform === "macintel" && maxTouchPoints > 1;
74
+ const ANDROID_STRING = "android";
75
+ const android = lowerPlatform === ANDROID_STRING || lowerUserAgent.includes(ANDROID_STRING);
76
+ const mac = !ios && lowerPlatform.startsWith("mac");
77
+ lowerPlatform.startsWith("win");
78
+ const apple = mac || ios;
79
+ const webkit = typeof CSS !== "undefined" && !!((_a = CSS.supports) == null ? void 0 : _a.call(CSS, "-webkit-backdrop-filter:none"));
80
+ !webkit && lowerUserAgent.includes("firefox");
81
+ !webkit && lowerUserAgent.includes("chrom");
82
+ const voiceOver = apple;
83
+ function stopEvent(event) {
84
+ event.preventDefault();
85
+ event.stopPropagation();
86
+ }
87
+ function isReactEvent(event) {
88
+ return "nativeEvent" in event;
89
+ }
90
+ function isVirtualClick(event) {
91
+ if (event.pointerType === "" && event.isTrusted) {
92
+ return true;
93
+ }
94
+ if (android && event.pointerType) {
95
+ return event.type === "click" && event.buttons === 1;
96
+ }
97
+ return event.detail === 0 && !event.pointerType;
98
+ }
99
+ function isVirtualPointerEvent(event) {
100
+ if (jsdom) {
101
+ return false;
102
+ }
103
+ return !android && event.width === 0 && event.height === 0 || // Chrome synthesizes a screen reader press (TalkBack, VoiceOver, NVDA) as a 1x1 mouse
104
+ // `pointerdown` with no pressure. TalkBack can report a pressed button, while desktop
105
+ // mouse presses can report no pressure, so only require no pressed button off Android.
106
+ event.type === "pointerdown" && event.width === 1 && event.height === 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === "mouse" && (android || event.buttons === 0) || // iOS VoiceOver returns 0.333• for width/height.
107
+ event.width < 1 && event.height < 1 && event.pressure === 0 && event.detail === 0 && event.pointerType === "touch";
108
+ }
109
+ function isMouseLikePointerType(pointerType, strict) {
110
+ const values = ["mouse", "pen"];
111
+ if (!strict) {
112
+ values.push("", void 0);
113
+ }
114
+ return values.includes(pointerType);
115
+ }
116
+ function isClickLikeEvent(event) {
117
+ const type = event.type;
118
+ return type === "click" || type === "mousedown" || type === "keydown" || type === "keyup";
119
+ }
120
+ function mergeCleanups(...cleanups) {
121
+ return () => {
122
+ for (let i = 0; i < cleanups.length; i += 1) {
123
+ const cleanup = cleanups[i];
124
+ if (cleanup) {
125
+ cleanup();
126
+ }
127
+ }
128
+ };
129
+ }
130
+ const FocusGuard = /* @__PURE__ */ React.forwardRef(function FocusGuard2(props, ref) {
131
+ const [role, setRole] = React.useState();
132
+ useIsoLayoutEffect(() => {
133
+ if (voiceOver && webkit) {
134
+ setRole("button");
135
+ }
136
+ }, []);
137
+ const restProps = {
138
+ tabIndex: 0,
139
+ // Role is only for VoiceOver
140
+ role
141
+ };
142
+ return /* @__PURE__ */ jsx("span", {
143
+ ...props,
144
+ ref,
145
+ style: visuallyHidden,
146
+ "aria-hidden": role ? void 0 : true,
147
+ ...restProps,
148
+ "data-base-ui-focus-guard": ""
149
+ });
150
+ });
151
+ if (process.env.NODE_ENV !== "production") FocusGuard.displayName = "FocusGuard";
152
+ const CANDIDATE_SELECTOR = 'a[href],button,input,select,textarea,summary,details,iframe,object,embed,[tabindex],[contenteditable]:not([contenteditable="false"]),audio[controls],video[controls]';
153
+ function getParentElement(element) {
154
+ const assignedSlot = element.assignedSlot;
155
+ if (assignedSlot) {
156
+ return assignedSlot;
157
+ }
158
+ if (element.parentElement) {
159
+ return element.parentElement;
160
+ }
161
+ const rootNode = element.getRootNode();
162
+ return isShadowRoot(rootNode) ? rootNode.host : null;
163
+ }
164
+ function getDetailsSummary(details) {
165
+ for (const child of Array.from(details.children)) {
166
+ if (getNodeName(child) === "summary") {
167
+ return child;
168
+ }
169
+ }
170
+ return null;
171
+ }
172
+ function isWithinOpenDetailsSummary(element, details) {
173
+ const summary = getDetailsSummary(details);
174
+ return !!summary && (element === summary || contains(summary, element));
175
+ }
176
+ function isFocusableCandidate(element) {
177
+ const nodeName = element ? getNodeName(element) : "";
178
+ return element != null && element.matches(CANDIDATE_SELECTOR) && (nodeName !== "summary" || element.parentElement != null && getNodeName(element.parentElement) === "details" && getDetailsSummary(element.parentElement) === element) && (nodeName !== "details" || getDetailsSummary(element) == null) && (nodeName !== "input" || element.type !== "hidden");
179
+ }
180
+ function isFocusableElement(element) {
181
+ if (!isFocusableCandidate(element) || !element.isConnected || element.matches(":disabled")) {
182
+ return false;
183
+ }
184
+ for (let current = element; current; current = getParentElement(current)) {
185
+ const isAncestor = current !== element;
186
+ const isSlot = getNodeName(current) === "slot";
187
+ if (current.hasAttribute("inert")) {
188
+ return false;
189
+ }
190
+ if (isAncestor && getNodeName(current) === "details" && !current.open && !isWithinOpenDetailsSummary(element, current) || current.hasAttribute("hidden") || !isSlot && !isVisibleInTabbableTree(current, isAncestor)) {
191
+ return false;
192
+ }
193
+ }
194
+ return true;
195
+ }
196
+ function isVisibleInTabbableTree(element, isAncestor) {
197
+ const styles = getComputedStyle(element);
198
+ if (!isAncestor) {
199
+ return isElementVisible(element, styles);
200
+ }
201
+ return styles.display !== "none";
202
+ }
203
+ function getTabIndex(element) {
204
+ const tabIndex = element.tabIndex;
205
+ if (tabIndex < 0) {
206
+ const nodeName = getNodeName(element);
207
+ if (nodeName === "details" || nodeName === "audio" || nodeName === "video" || isHTMLElement(element) && element.isContentEditable) {
208
+ return 0;
209
+ }
210
+ }
211
+ return tabIndex;
212
+ }
213
+ function getNamedRadioInput(element) {
214
+ if (getNodeName(element) !== "input") {
215
+ return null;
216
+ }
217
+ const input = element;
218
+ return input.type === "radio" && input.name !== "" ? input : null;
219
+ }
220
+ function isTabbableRadio(element, candidates) {
221
+ const input = getNamedRadioInput(element);
222
+ if (!input) {
223
+ return true;
224
+ }
225
+ const checkedRadio = candidates.find((candidate) => {
226
+ const radio = getNamedRadioInput(candidate);
227
+ return (radio == null ? void 0 : radio.name) === input.name && radio.form === input.form && radio.checked;
228
+ });
229
+ if (checkedRadio) {
230
+ return checkedRadio === input;
231
+ }
232
+ return candidates.find((candidate) => {
233
+ const radio = getNamedRadioInput(candidate);
234
+ return (radio == null ? void 0 : radio.name) === input.name && radio.form === input.form;
235
+ }) === input;
236
+ }
237
+ function getComposedChildren(container) {
238
+ if (isHTMLElement(container) && getNodeName(container) === "slot") {
239
+ const assignedElements = container.assignedElements({
240
+ flatten: true
241
+ });
242
+ if (assignedElements.length > 0) {
243
+ return assignedElements;
244
+ }
245
+ }
246
+ if (isHTMLElement(container) && container.shadowRoot) {
247
+ return Array.from(container.shadowRoot.children);
248
+ }
249
+ return Array.from(container.children);
250
+ }
251
+ function appendCandidates(container, list) {
252
+ getComposedChildren(container).forEach((child) => {
253
+ if (isFocusableCandidate(child)) {
254
+ list.push(child);
255
+ }
256
+ appendCandidates(child, list);
257
+ });
258
+ }
259
+ function appendMatchingElements(container, selector, list) {
260
+ getComposedChildren(container).forEach((child) => {
261
+ if (isHTMLElement(child) && child.matches(selector)) {
262
+ list.push(child);
263
+ }
264
+ appendMatchingElements(child, selector, list);
265
+ });
266
+ }
267
+ function isTabbable(element) {
268
+ return isFocusableElement(element) && getTabIndex(element) >= 0;
269
+ }
270
+ function focusable(container) {
271
+ const candidates = [];
272
+ appendCandidates(container, candidates);
273
+ return candidates.filter(isFocusableElement);
274
+ }
275
+ function tabbable(container) {
276
+ const candidates = focusable(container);
277
+ return candidates.filter((element) => getTabIndex(element) >= 0 && isTabbableRadio(element, candidates));
278
+ }
279
+ function getTabbableIn(container, dir) {
280
+ const list = tabbable(container);
281
+ const len = list.length;
282
+ if (len === 0) {
283
+ return void 0;
284
+ }
285
+ const active = activeElement(ownerDocument(container));
286
+ const index = list.indexOf(active);
287
+ const nextIndex = index === -1 ? dir === 1 ? 0 : len - 1 : index + dir;
288
+ return list[nextIndex];
289
+ }
290
+ function getNextTabbable(referenceElement) {
291
+ return getTabbableIn(ownerDocument(referenceElement).body, 1) || referenceElement;
292
+ }
293
+ function getPreviousTabbable(referenceElement) {
294
+ return getTabbableIn(ownerDocument(referenceElement).body, -1) || referenceElement;
295
+ }
296
+ function getTabbableNearElement(referenceElement, direction, exclude) {
297
+ if (!referenceElement) {
298
+ return null;
299
+ }
300
+ const list = [];
301
+ appendCandidates(ownerDocument(referenceElement).body, list);
302
+ const index = list.indexOf(referenceElement);
303
+ if (index === -1) {
304
+ return null;
305
+ }
306
+ const candidates = list.filter(isFocusableElement);
307
+ for (let offset = 1; offset < list.length; offset += 1) {
308
+ const element = list[(index + direction * offset + list.length) % list.length];
309
+ if (!contains(exclude, element) && isTabbable(element) && isTabbableRadio(element, candidates)) {
310
+ return element;
311
+ }
312
+ }
313
+ return list[index];
314
+ }
315
+ function isOutsideEvent(event, container) {
316
+ const containerElement = container || event.currentTarget;
317
+ const relatedTarget = event.relatedTarget;
318
+ return !relatedTarget || !contains(containerElement, relatedTarget);
319
+ }
320
+ function disableFocusInside(container) {
321
+ const tabbableElements = tabbable(container);
322
+ tabbableElements.forEach((element) => {
323
+ element.dataset.tabindex = element.getAttribute("tabindex") || "";
324
+ element.setAttribute("tabindex", "-1");
325
+ });
326
+ }
327
+ function enableFocusInside(container) {
328
+ const elements = [];
329
+ appendMatchingElements(container, "[data-tabindex]", elements);
330
+ elements.forEach((element) => {
331
+ const tabindex = element.dataset.tabindex;
332
+ delete element.dataset.tabindex;
333
+ if (tabindex) {
334
+ element.setAttribute("tabindex", tabindex);
335
+ } else {
336
+ element.removeAttribute("tabindex");
337
+ }
338
+ });
339
+ }
340
+ function getNodeChildren(nodes, id, onlyOpenChildren = true) {
341
+ const directChildren = nodes.filter((node) => node.parentId === id);
342
+ return directChildren.flatMap((child) => {
343
+ var _a2;
344
+ return [...!onlyOpenChildren || ((_a2 = child.context) == null ? void 0 : _a2.open) ? [child] : [], ...getNodeChildren(nodes, child.id, onlyOpenChildren)];
345
+ });
346
+ }
347
+ function getNodeAncestors(nodes, id) {
348
+ var _a2;
349
+ let allAncestors = [];
350
+ let currentParentId = (_a2 = nodes.find((node) => node.id === id)) == null ? void 0 : _a2.parentId;
351
+ while (currentParentId) {
352
+ const currentNode = nodes.find((node) => node.id === currentParentId);
353
+ currentParentId = currentNode == null ? void 0 : currentNode.parentId;
354
+ if (currentNode) {
355
+ allAncestors = allAncestors.concat(currentNode);
356
+ }
357
+ }
358
+ return allAncestors;
359
+ }
360
+ function createAttribute(name) {
361
+ return `data-base-ui-${name}`;
362
+ }
363
+ const PATIENT_CLICK_THRESHOLD = 500;
364
+ const DISABLED_TRANSITIONS_STYLE = {
365
+ style: {
366
+ transition: "none"
367
+ }
368
+ };
369
+ const CLICK_TRIGGER_IDENTIFIER = "data-base-ui-click-trigger";
370
+ const POPUP_COLLISION_AVOIDANCE = {
371
+ fallbackAxisSide: "end"
372
+ };
373
+ const ownerVisuallyHidden = {
374
+ clipPath: "inset(50%)",
375
+ position: "fixed",
376
+ top: 0,
377
+ left: 0
378
+ };
379
+ const PortalContext = /* @__PURE__ */ React.createContext(null);
380
+ if (process.env.NODE_ENV !== "production") PortalContext.displayName = "PortalContext";
381
+ const usePortalContext = () => React.useContext(PortalContext);
382
+ const attr = createAttribute("portal");
383
+ function useFloatingPortalNode(props = {}) {
384
+ const {
385
+ ref,
386
+ container: containerProp,
387
+ componentProps = EMPTY_OBJECT,
388
+ elementProps
389
+ } = props;
390
+ const uniqueId = useId();
391
+ const portalContext = usePortalContext();
392
+ const parentPortalNode = portalContext == null ? void 0 : portalContext.portalNode;
393
+ const [containerElement, setContainerElement] = React.useState(null);
394
+ const [portalNode, setPortalNode] = React.useState(null);
395
+ const setPortalNodeRef = useStableCallback((node) => {
396
+ if (node !== null) {
397
+ setPortalNode(node);
398
+ }
399
+ });
400
+ const containerRef = React.useRef(null);
401
+ useIsoLayoutEffect(() => {
402
+ if (containerProp === null) {
403
+ if (containerRef.current) {
404
+ containerRef.current = null;
405
+ setPortalNode(null);
406
+ setContainerElement(null);
407
+ }
408
+ return;
409
+ }
410
+ const resolvedContainer = (containerProp && (isNode(containerProp) ? containerProp : containerProp.current)) ?? parentPortalNode ?? document.body;
411
+ if (resolvedContainer == null) {
412
+ if (containerRef.current) {
413
+ containerRef.current = null;
414
+ setPortalNode(null);
415
+ setContainerElement(null);
416
+ }
417
+ return;
418
+ }
419
+ if (containerRef.current !== resolvedContainer) {
420
+ containerRef.current = resolvedContainer;
421
+ setPortalNode(null);
422
+ setContainerElement(resolvedContainer);
423
+ }
424
+ }, [containerProp, parentPortalNode]);
425
+ const portalElement = useRenderElement("div", componentProps, {
426
+ ref: [ref, setPortalNodeRef],
427
+ props: [{
428
+ id: uniqueId,
429
+ [attr]: ""
430
+ }, elementProps]
431
+ });
432
+ const portalSubtree = containerElement && portalElement ? /* @__PURE__ */ ReactDOM.createPortal(portalElement, containerElement) : null;
433
+ return {
434
+ node: portalNode,
435
+ // `id` and `render` props can override or remove the generated ID. Use the exact
436
+ // rendered value so `aria-owns` never points at an ID absent from the DOM.
437
+ nodeId: /* @__PURE__ */ React.isValidElement(portalElement) ? portalElement.props.id : void 0,
438
+ subtree: portalSubtree
439
+ };
440
+ }
441
+ const FloatingPortal = /* @__PURE__ */ React.forwardRef(function FloatingPortal2(componentProps, forwardedRef) {
442
+ const {
443
+ render,
444
+ className,
445
+ style,
446
+ children,
447
+ container,
448
+ portalOwnerRole,
449
+ ...elementProps
450
+ } = componentProps;
451
+ const {
452
+ node: portalNode,
453
+ nodeId: portalNodeId,
454
+ subtree: portalSubtree
455
+ } = useFloatingPortalNode({
456
+ container,
457
+ ref: forwardedRef,
458
+ componentProps,
459
+ elementProps
460
+ });
461
+ const beforeOutsideRef = React.useRef(null);
462
+ const afterOutsideRef = React.useRef(null);
463
+ const beforeInsideRef = React.useRef(null);
464
+ const afterInsideRef = React.useRef(null);
465
+ const [focusManagerState, setFocusManagerState] = React.useState(null);
466
+ const focusInsideDisabledRef = React.useRef(false);
467
+ const modal = focusManagerState == null ? void 0 : focusManagerState.modal;
468
+ const open2 = focusManagerState == null ? void 0 : focusManagerState.open;
469
+ const shouldRenderGuards = !!focusManagerState && !focusManagerState.modal && focusManagerState.open && !!portalNode;
470
+ React.useEffect(() => {
471
+ if (!portalNode || modal) {
472
+ return void 0;
473
+ }
474
+ function onFocus(event) {
475
+ if (portalNode && event.relatedTarget && isOutsideEvent(event)) {
476
+ if (event.type === "focusin") {
477
+ if (focusInsideDisabledRef.current) {
478
+ enableFocusInside(portalNode);
479
+ focusInsideDisabledRef.current = false;
480
+ }
481
+ } else {
482
+ disableFocusInside(portalNode);
483
+ focusInsideDisabledRef.current = true;
484
+ }
485
+ }
486
+ }
487
+ return mergeCleanups(addEventListener(portalNode, "focusin", onFocus, true), addEventListener(portalNode, "focusout", onFocus, true));
488
+ }, [portalNode, modal]);
489
+ useIsoLayoutEffect(() => {
490
+ if (!portalNode || open2 !== true || !focusInsideDisabledRef.current) {
491
+ return;
492
+ }
493
+ enableFocusInside(portalNode);
494
+ focusInsideDisabledRef.current = false;
495
+ }, [open2, portalNode]);
496
+ const portalContextValue = React.useMemo(() => ({
497
+ beforeOutsideRef,
498
+ afterOutsideRef,
499
+ beforeInsideRef,
500
+ afterInsideRef,
501
+ portalNode,
502
+ setFocusManagerState
503
+ }), [portalNode]);
504
+ return /* @__PURE__ */ jsxs(React.Fragment, {
505
+ children: [portalSubtree, /* @__PURE__ */ jsxs(PortalContext.Provider, {
506
+ value: portalContextValue,
507
+ children: [shouldRenderGuards && portalNode && /* @__PURE__ */ jsx(FocusGuard, {
508
+ "data-type": "outside",
509
+ ref: beforeOutsideRef,
510
+ onFocus: (event) => {
511
+ var _a2;
512
+ if (isOutsideEvent(event, portalNode)) {
513
+ (_a2 = beforeInsideRef.current) == null ? void 0 : _a2.focus();
514
+ } else {
515
+ const domReference = focusManagerState ? focusManagerState.domReference : null;
516
+ const prevTabbable = getPreviousTabbable(domReference);
517
+ prevTabbable == null ? void 0 : prevTabbable.focus();
518
+ }
519
+ }
520
+ }), shouldRenderGuards && portalNode && /* @__PURE__ */ jsx("span", {
521
+ role: portalOwnerRole,
522
+ "aria-owns": portalNodeId,
523
+ style: ownerVisuallyHidden
524
+ }), portalNode && /* @__PURE__ */ ReactDOM.createPortal(children, portalNode), shouldRenderGuards && portalNode && /* @__PURE__ */ jsx(FocusGuard, {
525
+ "data-type": "outside",
526
+ ref: afterOutsideRef,
527
+ onFocus: (event) => {
528
+ var _a2;
529
+ if (isOutsideEvent(event, portalNode)) {
530
+ (_a2 = afterInsideRef.current) == null ? void 0 : _a2.focus();
531
+ } else {
532
+ const domReference = focusManagerState ? focusManagerState.domReference : null;
533
+ const nextTabbable = getNextTabbable(domReference);
534
+ nextTabbable == null ? void 0 : nextTabbable.focus();
535
+ if (focusManagerState == null ? void 0 : focusManagerState.closeOnFocusOut) {
536
+ focusManagerState == null ? void 0 : focusManagerState.onOpenChange(false, createChangeEventDetails(focusOut, event.nativeEvent));
537
+ }
538
+ }
539
+ }
540
+ })]
541
+ })]
542
+ });
543
+ });
544
+ if (process.env.NODE_ENV !== "production") FloatingPortal.displayName = "FloatingPortal";
545
+ function createEventEmitter() {
546
+ const map = /* @__PURE__ */ new Map();
547
+ return {
548
+ emit(event, data) {
549
+ var _a2;
550
+ (_a2 = map.get(event)) == null ? void 0 : _a2.forEach((listener) => listener(data));
551
+ },
552
+ on(event, listener) {
553
+ if (!map.has(event)) {
554
+ map.set(event, /* @__PURE__ */ new Set());
555
+ }
556
+ map.get(event).add(listener);
557
+ },
558
+ off(event, listener) {
559
+ var _a2;
560
+ (_a2 = map.get(event)) == null ? void 0 : _a2.delete(listener);
561
+ }
562
+ };
563
+ }
564
+ class FloatingTreeStore {
565
+ constructor() {
566
+ __publicField(this, "nodesRef", {
567
+ current: []
568
+ });
569
+ __publicField(this, "events", createEventEmitter());
570
+ }
571
+ addNode(node) {
572
+ this.nodesRef.current.push(node);
573
+ }
574
+ removeNode(node) {
575
+ const index = this.nodesRef.current.findIndex((n) => n === node);
576
+ if (index !== -1) {
577
+ this.nodesRef.current.splice(index, 1);
578
+ }
579
+ }
580
+ }
581
+ const FloatingNodeContext = /* @__PURE__ */ React.createContext(null);
582
+ if (process.env.NODE_ENV !== "production") FloatingNodeContext.displayName = "FloatingNodeContext";
583
+ const FloatingTreeContext = /* @__PURE__ */ React.createContext(null);
584
+ if (process.env.NODE_ENV !== "production") FloatingTreeContext.displayName = "FloatingTreeContext";
585
+ const useFloatingParentNodeId = () => {
586
+ var _a2;
587
+ return ((_a2 = React.useContext(FloatingNodeContext)) == null ? void 0 : _a2.id) || null;
588
+ };
589
+ const useFloatingTree = (externalTree) => {
590
+ const contextTree = React.useContext(FloatingTreeContext);
591
+ return externalTree ?? contextTree;
592
+ };
593
+ function useFloatingNodeId(externalTree) {
594
+ const id = useId();
595
+ const tree = useFloatingTree(externalTree);
596
+ const parentId = useFloatingParentNodeId();
597
+ useIsoLayoutEffect(() => {
598
+ if (!id) {
599
+ return void 0;
600
+ }
601
+ const node = {
602
+ id,
603
+ parentId
604
+ };
605
+ tree == null ? void 0 : tree.addNode(node);
606
+ return () => {
607
+ tree == null ? void 0 : tree.removeNode(node);
608
+ };
609
+ }, [tree, id, parentId]);
610
+ return id;
611
+ }
612
+ function FloatingNode(props) {
613
+ const {
614
+ children,
615
+ id
616
+ } = props;
617
+ const parentId = useFloatingParentNodeId();
618
+ return /* @__PURE__ */ jsx(FloatingNodeContext.Provider, {
619
+ value: React.useMemo(() => ({
620
+ id,
621
+ parentId
622
+ }), [id, parentId]),
623
+ children
624
+ });
625
+ }
626
+ function FloatingTree(props) {
627
+ const {
628
+ children,
629
+ externalTree
630
+ } = props;
631
+ const tree = useRefWithInit(() => externalTree ?? new FloatingTreeStore()).current;
632
+ return /* @__PURE__ */ jsx(FloatingTreeContext.Provider, {
633
+ value: tree,
634
+ children
635
+ });
636
+ }
637
+ function alwaysFalse() {
638
+ return false;
639
+ }
640
+ function normalizeProp(normalizable) {
641
+ return {
642
+ escapeKey: typeof normalizable === "boolean" ? normalizable : (normalizable == null ? void 0 : normalizable.escapeKey) ?? false,
643
+ outsidePress: typeof normalizable === "boolean" ? normalizable : (normalizable == null ? void 0 : normalizable.outsidePress) ?? true
644
+ };
645
+ }
646
+ function useDismiss(store, props = {}) {
647
+ const {
648
+ enabled = true,
649
+ escapeKey: escapeKey$1 = true,
650
+ outsidePress: outsidePressProp = true,
651
+ outsidePressEvent = "sloppy",
652
+ referencePress = alwaysFalse,
653
+ bubbles,
654
+ externalTree
655
+ } = props;
656
+ const open2 = store.useState("open");
657
+ const floatingElement = store.useState("floatingElement");
658
+ const {
659
+ dataRef,
660
+ events
661
+ } = store.context;
662
+ const tree = useFloatingTree(externalTree);
663
+ const outsidePressFn = useStableCallback(typeof outsidePressProp === "function" ? outsidePressProp : () => false);
664
+ const outsidePress$1 = typeof outsidePressProp === "function" ? outsidePressFn : outsidePressProp;
665
+ const outsidePressEnabled = outsidePress$1 !== false;
666
+ const getOutsidePressEventProp = useStableCallback(() => outsidePressEvent);
667
+ const {
668
+ escapeKey: escapeKeyBubbles,
669
+ outsidePress: outsidePressBubbles
670
+ } = normalizeProp(bubbles);
671
+ const pressStartedInsideRef = React.useRef(false);
672
+ const pressStartPreventedRef = React.useRef(false);
673
+ const suppressNextOutsideClickRef = React.useRef(false);
674
+ const sawPressWhileOpenRef = React.useRef(false);
675
+ const isComposingRef = React.useRef(false);
676
+ const currentPointerTypeRef = React.useRef("");
677
+ const touchStateRef = React.useRef(null);
678
+ const cancelDismissOnEndTimeout = useTimeout();
679
+ const clearInsideReactTreeTimeout = useTimeout();
680
+ const compositionTimeout = useTimeout();
681
+ const clearInsideReactTree = useStableCallback(() => {
682
+ clearInsideReactTreeTimeout.clear();
683
+ dataRef.current.insideReactTree = false;
684
+ });
685
+ const hasBlockingChild = useStableCallback((bubbleKey) => {
686
+ var _a2;
687
+ const nodeId = (_a2 = dataRef.current.floatingContext) == null ? void 0 : _a2.nodeId;
688
+ const children = tree ? getNodeChildren(tree.nodesRef.current, nodeId) : [];
689
+ return children.some((child) => {
690
+ var _a3;
691
+ return ((_a3 = child.context) == null ? void 0 : _a3.open) && !child.context.dataRef.current[bubbleKey];
692
+ });
693
+ });
694
+ const isEventWithinOwnElements = useStableCallback((event) => {
695
+ return isEventTargetWithin(event, store.select("floatingElement")) || isEventTargetWithin(event, store.select("domReferenceElement"));
696
+ });
697
+ const closeOnReferencePress = useStableCallback((event) => {
698
+ if (!referencePress()) {
699
+ return;
700
+ }
701
+ store.setOpen(false, createChangeEventDetails(triggerPress, event.nativeEvent));
702
+ });
703
+ const closeOnEscapeKeyDown = useStableCallback((event) => {
704
+ if (!open2 || !enabled || !escapeKey$1 || event.key !== "Escape") {
705
+ return;
706
+ }
707
+ const native = isReactEvent(event) ? event.nativeEvent : event;
708
+ if (isComposingRef.current || native.isComposing) {
709
+ return;
710
+ }
711
+ if (!escapeKeyBubbles && hasBlockingChild("__escapeKeyBubbles")) {
712
+ return;
713
+ }
714
+ const eventDetails = createChangeEventDetails(escapeKey, native);
715
+ store.setOpen(false, eventDetails);
716
+ if (!eventDetails.isCanceled) {
717
+ event.preventDefault();
718
+ }
719
+ if (!escapeKeyBubbles && !eventDetails.isPropagationAllowed) {
720
+ event.stopPropagation();
721
+ }
722
+ });
723
+ const markInsideReactTree = useStableCallback(() => {
724
+ dataRef.current.insideReactTree = true;
725
+ clearInsideReactTreeTimeout.start(0, clearInsideReactTree);
726
+ });
727
+ const markPressStartedInsideReactTree = useStableCallback((event) => {
728
+ if (!open2 || !enabled || event.button !== 0) {
729
+ return;
730
+ }
731
+ const target = getTarget(event.nativeEvent);
732
+ if (!contains(store.select("floatingElement"), target)) {
733
+ return;
734
+ }
735
+ if (!pressStartedInsideRef.current) {
736
+ pressStartedInsideRef.current = true;
737
+ pressStartPreventedRef.current = false;
738
+ }
739
+ });
740
+ const markInsidePressStartPrevented = useStableCallback((event) => {
741
+ if (!open2 || !enabled) {
742
+ return;
743
+ }
744
+ if (!(event.defaultPrevented || event.nativeEvent.defaultPrevented)) {
745
+ return;
746
+ }
747
+ if (pressStartedInsideRef.current) {
748
+ pressStartPreventedRef.current = true;
749
+ }
750
+ });
751
+ React.useEffect(() => {
752
+ function handleOpenChange(details) {
753
+ if (!details.open) {
754
+ sawPressWhileOpenRef.current = false;
755
+ }
756
+ }
757
+ events.on("openchange", handleOpenChange);
758
+ return () => {
759
+ events.off("openchange", handleOpenChange);
760
+ };
761
+ }, [events]);
762
+ React.useEffect(() => clearInsideReactTree, [clearInsideReactTree]);
763
+ React.useEffect(() => {
764
+ if (!open2 || !enabled) {
765
+ if (!open2) {
766
+ sawPressWhileOpenRef.current = false;
767
+ isComposingRef.current = false;
768
+ currentPointerTypeRef.current = "";
769
+ touchStateRef.current = null;
770
+ }
771
+ return clearInsideReactTree;
772
+ }
773
+ dataRef.current.__escapeKeyBubbles = escapeKeyBubbles;
774
+ dataRef.current.__outsidePressBubbles = outsidePressBubbles;
775
+ const preventedPressSuppressionTimeout = new Timeout();
776
+ const doc = ownerDocument(floatingElement);
777
+ function handleCompositionStart() {
778
+ compositionTimeout.clear();
779
+ isComposingRef.current = true;
780
+ }
781
+ function handleCompositionEnd() {
782
+ isComposingRef.current = true;
783
+ compositionTimeout.start(
784
+ // 0ms or 1ms don't work in Safari. 5ms appears to consistently work.
785
+ // Only apply to WebKit for the test to remain 0ms.
786
+ webkit ? 5 : 0,
787
+ () => {
788
+ isComposingRef.current = false;
789
+ }
790
+ );
791
+ }
792
+ function suppressImmediateOutsideClickAfterPreventedStart() {
793
+ suppressNextOutsideClickRef.current = true;
794
+ preventedPressSuppressionTimeout.start(0, () => {
795
+ suppressNextOutsideClickRef.current = false;
796
+ });
797
+ }
798
+ function resetPressStartState() {
799
+ pressStartedInsideRef.current = false;
800
+ pressStartPreventedRef.current = false;
801
+ }
802
+ function getOutsidePressEvent() {
803
+ const type = currentPointerTypeRef.current;
804
+ const computedType = type === "pen" || !type ? "mouse" : type;
805
+ const outsidePressEventValue = getOutsidePressEventProp();
806
+ const resolved = typeof outsidePressEventValue === "function" ? outsidePressEventValue() : outsidePressEventValue;
807
+ if (typeof resolved === "string") {
808
+ return resolved;
809
+ }
810
+ return resolved[computedType];
811
+ }
812
+ function shouldIgnoreEvent(event) {
813
+ const computedOutsidePressEvent = getOutsidePressEvent();
814
+ return computedOutsidePressEvent === "intentional" && event.type !== "click" || computedOutsidePressEvent === "sloppy" && event.type === "click";
815
+ }
816
+ function isEventWithinFloatingTree(event) {
817
+ var _a2;
818
+ const nodeId = (_a2 = dataRef.current.floatingContext) == null ? void 0 : _a2.nodeId;
819
+ const targetIsInsideChildren = tree && getNodeChildren(tree.nodesRef.current, nodeId).some((node) => {
820
+ var _a3;
821
+ return isEventTargetWithin(event, (_a3 = node.context) == null ? void 0 : _a3.elements.floating);
822
+ });
823
+ return isEventWithinOwnElements(event) || targetIsInsideChildren;
824
+ }
825
+ function closeOnPressOutside(event) {
826
+ if (shouldIgnoreEvent(event)) {
827
+ if (event.type !== "click" && !isEventWithinOwnElements(event)) {
828
+ preventedPressSuppressionTimeout.clear();
829
+ suppressNextOutsideClickRef.current = false;
830
+ }
831
+ clearInsideReactTree();
832
+ return;
833
+ }
834
+ if (dataRef.current.insideReactTree) {
835
+ clearInsideReactTree();
836
+ return;
837
+ }
838
+ const target = getTarget(event);
839
+ const inertSelector = `[${createAttribute("inert")}]`;
840
+ const targetRoot = isElement(target) ? target.getRootNode() : null;
841
+ const markers = Array.from((isShadowRoot(targetRoot) ? targetRoot : ownerDocument(store.select("floatingElement"))).querySelectorAll(inertSelector));
842
+ const triggers = store.context.triggerElements;
843
+ if (target && (triggers.hasElement(target) || triggers.hasMatchingElement((trigger) => contains(trigger, target)))) {
844
+ return;
845
+ }
846
+ let targetRootAncestor = isElement(target) ? target : null;
847
+ while (targetRootAncestor && !isLastTraversableNode(targetRootAncestor)) {
848
+ const nextParent = getParentNode(targetRootAncestor);
849
+ if (isLastTraversableNode(nextParent) || !isElement(nextParent)) {
850
+ break;
851
+ }
852
+ targetRootAncestor = nextParent;
853
+ }
854
+ if (markers.length && isElement(target) && !isRootElement(target) && // Clicked on a direct ancestor (e.g. FloatingOverlay).
855
+ !contains(target, store.select("floatingElement")) && // If the target root element contains none of the markers, then the
856
+ // element was injected after the floating element rendered.
857
+ markers.every((marker) => !contains(targetRootAncestor, marker))) {
858
+ return;
859
+ }
860
+ if (isHTMLElement(target) && !("touches" in event)) {
861
+ const lastTraversableNode = isLastTraversableNode(target);
862
+ const style = getComputedStyle(target);
863
+ const scrollRe = /auto|scroll/;
864
+ const isScrollableX = lastTraversableNode || scrollRe.test(style.overflowX);
865
+ const isScrollableY = lastTraversableNode || scrollRe.test(style.overflowY);
866
+ const canScrollX = isScrollableX && target.clientWidth > 0 && target.scrollWidth > target.clientWidth;
867
+ const canScrollY = isScrollableY && target.clientHeight > 0 && target.scrollHeight > target.clientHeight;
868
+ const isRTL = style.direction === "rtl";
869
+ const pressedVerticalScrollbar = canScrollY && (isRTL ? event.offsetX <= target.offsetWidth - target.clientWidth : event.offsetX > target.clientWidth);
870
+ const pressedHorizontalScrollbar = canScrollX && event.offsetY > target.clientHeight;
871
+ if (pressedVerticalScrollbar || pressedHorizontalScrollbar) {
872
+ return;
873
+ }
874
+ }
875
+ if (isEventWithinFloatingTree(event)) {
876
+ return;
877
+ }
878
+ if (getOutsidePressEvent() === "intentional") {
879
+ if (event.detail !== 0 && !isVirtualClick(event) && !sawPressWhileOpenRef.current) {
880
+ return;
881
+ }
882
+ if (suppressNextOutsideClickRef.current) {
883
+ preventedPressSuppressionTimeout.clear();
884
+ suppressNextOutsideClickRef.current = false;
885
+ return;
886
+ }
887
+ }
888
+ if (typeof outsidePress$1 === "function" && !outsidePress$1(event)) {
889
+ return;
890
+ }
891
+ if (hasBlockingChild("__outsidePressBubbles")) {
892
+ return;
893
+ }
894
+ store.setOpen(false, createChangeEventDetails(outsidePress, event));
895
+ clearInsideReactTree();
896
+ }
897
+ function handlePointerDown(event) {
898
+ if (getOutsidePressEvent() !== "sloppy" || event.pointerType === "touch" || !store.select("open") || !enabled || isEventWithinOwnElements(event)) {
899
+ return;
900
+ }
901
+ closeOnPressOutside(event);
902
+ }
903
+ function handleTouchStart(event) {
904
+ if (getOutsidePressEvent() !== "sloppy" || !store.select("open") || !enabled || isEventWithinOwnElements(event)) {
905
+ return;
906
+ }
907
+ const touch = event.touches[0];
908
+ if (touch) {
909
+ touchStateRef.current = {
910
+ startTime: Date.now(),
911
+ startX: touch.clientX,
912
+ startY: touch.clientY,
913
+ dismissOnTouchEnd: false,
914
+ dismissOnMouseDown: true
915
+ };
916
+ cancelDismissOnEndTimeout.start(1e3, () => {
917
+ if (touchStateRef.current) {
918
+ touchStateRef.current.dismissOnTouchEnd = false;
919
+ touchStateRef.current.dismissOnMouseDown = false;
920
+ }
921
+ });
922
+ }
923
+ }
924
+ function addTargetEventListenerOnce(event, listener) {
925
+ const target = getTarget(event);
926
+ if (!target) {
927
+ return;
928
+ }
929
+ const unsubscribe2 = addEventListener(target, event.type, () => {
930
+ listener(event);
931
+ unsubscribe2();
932
+ });
933
+ }
934
+ function handleTouchStartCapture(event) {
935
+ currentPointerTypeRef.current = "touch";
936
+ addTargetEventListenerOnce(event, handleTouchStart);
937
+ }
938
+ function closeOnPressOutsideCapture(event) {
939
+ cancelDismissOnEndTimeout.clear();
940
+ if (event.type === "pointerdown") {
941
+ if (event.button === 0) {
942
+ sawPressWhileOpenRef.current = true;
943
+ }
944
+ currentPointerTypeRef.current = event.pointerType;
945
+ }
946
+ if (event.type === "mousedown" && touchStateRef.current && !touchStateRef.current.dismissOnMouseDown) {
947
+ return;
948
+ }
949
+ addTargetEventListenerOnce(event, (targetEvent) => {
950
+ if (targetEvent.type === "pointerdown") {
951
+ handlePointerDown(targetEvent);
952
+ } else {
953
+ closeOnPressOutside(targetEvent);
954
+ }
955
+ });
956
+ }
957
+ function handlePressEndCapture(event) {
958
+ if (event.type === "pointercancel") {
959
+ sawPressWhileOpenRef.current = false;
960
+ }
961
+ if (!pressStartedInsideRef.current) {
962
+ return;
963
+ }
964
+ const pressStartedInsideDefaultPrevented = pressStartPreventedRef.current;
965
+ resetPressStartState();
966
+ if (getOutsidePressEvent() !== "intentional") {
967
+ return;
968
+ }
969
+ if (event.type === "pointercancel") {
970
+ if (pressStartedInsideDefaultPrevented) {
971
+ suppressImmediateOutsideClickAfterPreventedStart();
972
+ }
973
+ return;
974
+ }
975
+ if (isEventWithinFloatingTree(event)) {
976
+ return;
977
+ }
978
+ if (pressStartedInsideDefaultPrevented) {
979
+ suppressImmediateOutsideClickAfterPreventedStart();
980
+ return;
981
+ }
982
+ if (typeof outsidePress$1 === "function" && !outsidePress$1(event)) {
983
+ return;
984
+ }
985
+ preventedPressSuppressionTimeout.clear();
986
+ suppressNextOutsideClickRef.current = true;
987
+ clearInsideReactTree();
988
+ }
989
+ function handleTouchMove(event) {
990
+ if (getOutsidePressEvent() !== "sloppy" || !touchStateRef.current || isEventWithinOwnElements(event)) {
991
+ return;
992
+ }
993
+ const touch = event.touches[0];
994
+ if (!touch) {
995
+ return;
996
+ }
997
+ const deltaX = Math.abs(touch.clientX - touchStateRef.current.startX);
998
+ const deltaY = Math.abs(touch.clientY - touchStateRef.current.startY);
999
+ const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
1000
+ if (distance > 5) {
1001
+ touchStateRef.current.dismissOnTouchEnd = true;
1002
+ }
1003
+ if (distance > 10) {
1004
+ closeOnPressOutside(event);
1005
+ cancelDismissOnEndTimeout.clear();
1006
+ touchStateRef.current = null;
1007
+ }
1008
+ }
1009
+ function handleTouchMoveCapture(event) {
1010
+ addTargetEventListenerOnce(event, handleTouchMove);
1011
+ }
1012
+ function handleTouchEnd(event) {
1013
+ if (getOutsidePressEvent() !== "sloppy" || !touchStateRef.current || isEventWithinOwnElements(event)) {
1014
+ return;
1015
+ }
1016
+ if (touchStateRef.current.dismissOnTouchEnd) {
1017
+ closeOnPressOutside(event);
1018
+ }
1019
+ cancelDismissOnEndTimeout.clear();
1020
+ touchStateRef.current = null;
1021
+ }
1022
+ function handleTouchEndCapture(event) {
1023
+ addTargetEventListenerOnce(event, handleTouchEnd);
1024
+ }
1025
+ const unsubscribe = mergeCleanups(escapeKey$1 && mergeCleanups(addEventListener(doc, "keydown", closeOnEscapeKeyDown), addEventListener(doc, "compositionstart", handleCompositionStart), addEventListener(doc, "compositionend", handleCompositionEnd)), outsidePressEnabled && mergeCleanups(addEventListener(doc, "click", closeOnPressOutsideCapture, true), addEventListener(doc, "pointerdown", closeOnPressOutsideCapture, true), addEventListener(doc, "pointerup", handlePressEndCapture, true), addEventListener(doc, "pointercancel", handlePressEndCapture, true), addEventListener(doc, "mousedown", closeOnPressOutsideCapture, true), addEventListener(doc, "mouseup", handlePressEndCapture, true), addEventListener(doc, "touchstart", handleTouchStartCapture, {
1026
+ capture: true,
1027
+ passive: true
1028
+ }), addEventListener(doc, "touchmove", handleTouchMoveCapture, {
1029
+ capture: true,
1030
+ passive: true
1031
+ }), addEventListener(doc, "touchend", handleTouchEndCapture, {
1032
+ capture: true,
1033
+ passive: true
1034
+ })));
1035
+ return () => {
1036
+ unsubscribe();
1037
+ preventedPressSuppressionTimeout.clear();
1038
+ resetPressStartState();
1039
+ suppressNextOutsideClickRef.current = false;
1040
+ };
1041
+ }, [dataRef, floatingElement, escapeKey$1, outsidePressEnabled, outsidePress$1, open2, enabled, escapeKeyBubbles, outsidePressBubbles, closeOnEscapeKeyDown, clearInsideReactTree, getOutsidePressEventProp, hasBlockingChild, isEventWithinOwnElements, tree, store, cancelDismissOnEndTimeout, compositionTimeout]);
1042
+ const reference = React.useMemo(() => ({
1043
+ onKeyDown: closeOnEscapeKeyDown,
1044
+ onPointerDown: closeOnReferencePress,
1045
+ onClick: closeOnReferencePress
1046
+ }), [closeOnEscapeKeyDown, closeOnReferencePress]);
1047
+ const floating = React.useMemo(() => ({
1048
+ onKeyDown: closeOnEscapeKeyDown,
1049
+ // `onMouseDown` may be blocked if `event.preventDefault()` is called in
1050
+ // `onPointerDown`, such as with <NumberField.ScrubArea>.
1051
+ // See https://github.com/mui/base-ui/pull/3379
1052
+ onPointerDown: markInsidePressStartPrevented,
1053
+ onMouseDown: markInsidePressStartPrevented,
1054
+ onClickCapture: markInsideReactTree,
1055
+ onMouseDownCapture(event) {
1056
+ markInsideReactTree();
1057
+ markPressStartedInsideReactTree(event);
1058
+ },
1059
+ onPointerDownCapture(event) {
1060
+ markInsideReactTree();
1061
+ markPressStartedInsideReactTree(event);
1062
+ },
1063
+ onMouseUpCapture: markInsideReactTree,
1064
+ onTouchEndCapture: markInsideReactTree,
1065
+ onTouchMoveCapture: markInsideReactTree
1066
+ }), [closeOnEscapeKeyDown, markInsideReactTree, markPressStartedInsideReactTree, markInsidePressStartPrevented]);
1067
+ return React.useMemo(() => enabled ? {
1068
+ reference,
1069
+ floating,
1070
+ trigger: reference
1071
+ } : {}, [enabled, reference, floating]);
1072
+ }
1073
+ function useSyncedFloatingRootContext(options) {
1074
+ const {
1075
+ popupStore,
1076
+ treatPopupAsFloatingElement = false,
1077
+ floatingRootContext: store,
1078
+ floatingId,
1079
+ nested,
1080
+ onOpenChange
1081
+ } = options;
1082
+ const open2 = popupStore.useState("open");
1083
+ const referenceElement = popupStore.useState("activeTriggerElement");
1084
+ const floatingElement = popupStore.useState(treatPopupAsFloatingElement ? "popupElement" : "positionerElement");
1085
+ const handleOpenChange = onOpenChange;
1086
+ popupStore.useSyncedValue("floatingId", floatingId);
1087
+ useIsoLayoutEffect(() => {
1088
+ const valuesToSync = {
1089
+ open: open2,
1090
+ floatingId,
1091
+ referenceElement,
1092
+ floatingElement
1093
+ };
1094
+ if (isElement(referenceElement)) {
1095
+ valuesToSync.domReferenceElement = referenceElement;
1096
+ }
1097
+ if (store.state.positionReference === store.state.referenceElement) {
1098
+ valuesToSync.positionReference = referenceElement;
1099
+ }
1100
+ store.update(valuesToSync);
1101
+ }, [open2, floatingId, referenceElement, floatingElement, store]);
1102
+ store.context.onOpenChange = handleOpenChange;
1103
+ store.context.nested = nested;
1104
+ return store;
1105
+ }
1106
+ function useUnmountAfterClose(parameters) {
1107
+ const {
1108
+ open: open2,
1109
+ ref,
1110
+ preventUnmountOnClose,
1111
+ setPreventUnmountOnClose: setPreventUnmountOnCloseParam,
1112
+ onUnmount,
1113
+ animateInitialOpen
1114
+ } = parameters;
1115
+ const setPreventUnmountOnClose = useStableCallback(setPreventUnmountOnCloseParam);
1116
+ const {
1117
+ mounted,
1118
+ setMounted,
1119
+ transitionStatus
1120
+ } = useTransitionStatus(open2, false, false, animateInitialOpen);
1121
+ const preventUnmountingOnClose = open2 ? false : preventUnmountOnClose;
1122
+ useIsoLayoutEffect(() => {
1123
+ if (open2) {
1124
+ setPreventUnmountOnClose(false);
1125
+ }
1126
+ }, [open2, setPreventUnmountOnClose]);
1127
+ const mountedRef = React.useRef(mounted);
1128
+ const pendingUnmountRef = React.useRef(false);
1129
+ const rerender = useForcedRerendering();
1130
+ const unmount = () => {
1131
+ mountedRef.current = false;
1132
+ setMounted(false);
1133
+ onUnmount();
1134
+ };
1135
+ useIsoLayoutEffect(() => {
1136
+ mountedRef.current = mounted;
1137
+ if (pendingUnmountRef.current) {
1138
+ pendingUnmountRef.current = false;
1139
+ if (!open2 && mounted) {
1140
+ unmount();
1141
+ }
1142
+ }
1143
+ });
1144
+ const forceUnmount = useStableCallback(() => {
1145
+ if (!mountedRef.current) {
1146
+ return;
1147
+ }
1148
+ if (open2) {
1149
+ pendingUnmountRef.current = true;
1150
+ rerender();
1151
+ return;
1152
+ }
1153
+ unmount();
1154
+ });
1155
+ useOpenChangeComplete({
1156
+ enabled: mounted && !open2 && !preventUnmountingOnClose,
1157
+ open: open2,
1158
+ ref,
1159
+ onComplete() {
1160
+ if (!open2) {
1161
+ forceUnmount();
1162
+ }
1163
+ }
1164
+ });
1165
+ return {
1166
+ mounted,
1167
+ transitionStatus,
1168
+ preventUnmountingOnClose,
1169
+ forceUnmount
1170
+ };
1171
+ }
1172
+ const FOCUSABLE_POPUP_PROPS = {
1173
+ tabIndex: -1,
1174
+ [FOCUSABLE_ATTRIBUTE]: ""
1175
+ };
1176
+ function createDefaultInitialFocus(popupRef) {
1177
+ return (interactionType) => interactionType === "touch" ? popupRef.current : true;
1178
+ }
1179
+ function usePopupRootStore(createStore, treatPopupAsFloatingElement = false) {
1180
+ const floatingId = useId();
1181
+ const nested = useFloatingParentNodeId() != null;
1182
+ const store = useRefWithInit(() => createStore(floatingId, nested)).current;
1183
+ useSyncedFloatingRootContext({
1184
+ popupStore: store,
1185
+ treatPopupAsFloatingElement,
1186
+ floatingRootContext: store.state.floatingRootContext,
1187
+ floatingId,
1188
+ nested,
1189
+ onOpenChange: store.setOpen
1190
+ });
1191
+ return store;
1192
+ }
1193
+ function PopupHandleAttachment({
1194
+ handle,
1195
+ store
1196
+ }) {
1197
+ useIsoLayoutEffect(() => {
1198
+ return handle.attachStore(store);
1199
+ }, [handle, store]);
1200
+ return null;
1201
+ }
1202
+ function syncTriggerCount(store) {
1203
+ const triggerCount = store.context.triggerElements.size;
1204
+ if (store.select("open") && store.state.triggerCount !== triggerCount) {
1205
+ store.set("triggerCount", triggerCount);
1206
+ }
1207
+ }
1208
+ function useTriggerRegistration(id, store) {
1209
+ const registrationRef = React.useRef(null);
1210
+ return useStableCallback((element) => {
1211
+ const registration = registrationRef.current;
1212
+ if (registration !== null) {
1213
+ if (registration.element === element && registration.store === store && registration.id === id) {
1214
+ return;
1215
+ }
1216
+ registrationRef.current = null;
1217
+ const registeredStore = registration.store;
1218
+ if (registeredStore.context.triggerElements.getById(registration.id) === registration.element) {
1219
+ registeredStore.context.triggerElements.delete(registration.id);
1220
+ syncTriggerCount(registeredStore);
1221
+ }
1222
+ }
1223
+ if (element !== null && id !== void 0) {
1224
+ registrationRef.current = {
1225
+ store,
1226
+ id,
1227
+ element
1228
+ };
1229
+ store.context.triggerElements.add(id, element);
1230
+ syncTriggerCount(store);
1231
+ }
1232
+ });
1233
+ }
1234
+ function createPopupOpenState(state, open2, trigger, preventUnmountOnClose = false) {
1235
+ let preventUnmountingOnClose = state.preventUnmountingOnClose;
1236
+ if (open2) {
1237
+ preventUnmountingOnClose = false;
1238
+ } else if (preventUnmountOnClose) {
1239
+ preventUnmountingOnClose = true;
1240
+ }
1241
+ const triggerId = (trigger == null ? void 0 : trigger.id) ?? null;
1242
+ let activeTriggerId = state.activeTriggerId;
1243
+ let activeTriggerElement = state.activeTriggerElement;
1244
+ if (triggerId || open2) {
1245
+ activeTriggerId = triggerId;
1246
+ activeTriggerElement = trigger ?? null;
1247
+ }
1248
+ return {
1249
+ open: open2,
1250
+ preventUnmountingOnClose,
1251
+ activeTriggerId,
1252
+ activeTriggerElement,
1253
+ // An open request without a trigger (a handle's `open(null)` or `openWithPayload()`) must not
1254
+ // be reassociated with a lone registered trigger later on. Controlled and default opens never
1255
+ // pass through here, so they keep claiming a lone trigger. A close request keeps the flag: a
1256
+ // controlled root may decline it and stay open, so the Root clears the flag only once the
1257
+ // popup is effectively closed.
1258
+ openedWithoutTrigger: open2 ? trigger == null : state.openedWithoutTrigger
1259
+ };
1260
+ }
1261
+ function attachPreventUnmountOnClose(eventDetails) {
1262
+ let preventUnmountOnClose = false;
1263
+ eventDetails.preventUnmountOnClose = () => {
1264
+ preventUnmountOnClose = true;
1265
+ };
1266
+ return () => preventUnmountOnClose;
1267
+ }
1268
+ function applyPopupOpenChange(store, nextOpen, eventDetails, options = {}) {
1269
+ var _a2, _b, _c;
1270
+ const reason = eventDetails.reason;
1271
+ const isHover = reason === triggerHover;
1272
+ const isFocusOpen = nextOpen && reason === triggerFocus;
1273
+ const isDismissClose = !nextOpen && (reason === triggerPress || reason === escapeKey);
1274
+ const shouldPreventUnmountOnClose = attachPreventUnmountOnClose(eventDetails);
1275
+ (_b = (_a2 = store.context).onOpenChange) == null ? void 0 : _b.call(_a2, nextOpen, eventDetails);
1276
+ if (eventDetails.isCanceled) {
1277
+ return;
1278
+ }
1279
+ (_c = options.onBeforeDispatch) == null ? void 0 : _c.call(options);
1280
+ store.state.floatingRootContext.dispatchOpenChange(nextOpen, eventDetails);
1281
+ const changeState = () => {
1282
+ const popupOpenState = createPopupOpenState(store.state, nextOpen, eventDetails.trigger, shouldPreventUnmountOnClose());
1283
+ const updatedState = {
1284
+ ...options.extraState,
1285
+ ...popupOpenState
1286
+ };
1287
+ if (isFocusOpen) {
1288
+ updatedState.instantType = "focus";
1289
+ } else if (isDismissClose) {
1290
+ updatedState.instantType = "dismiss";
1291
+ } else if (isHover) {
1292
+ updatedState.instantType = void 0;
1293
+ }
1294
+ store.update(updatedState);
1295
+ };
1296
+ if (isHover) {
1297
+ ReactDOM.flushSync(changeState);
1298
+ } else {
1299
+ changeState();
1300
+ }
1301
+ }
1302
+ function useTriggerDataForwarding(triggerId, triggerElementRef, store, stateUpdates) {
1303
+ const isMountedByThisTrigger = store.useState("isMountedByTrigger", triggerId);
1304
+ const baseRegisterTrigger = useTriggerRegistration(triggerId, store);
1305
+ const applyTriggerData = useStableCallback((element) => {
1306
+ const open2 = store.select("open");
1307
+ const activeTriggerId = store.select("activeTriggerId");
1308
+ if (activeTriggerId === triggerId) {
1309
+ const changes = {
1310
+ activeTriggerElement: element,
1311
+ ...open2 ? stateUpdates : null
1312
+ };
1313
+ store.update(changes);
1314
+ return;
1315
+ }
1316
+ if (activeTriggerId == null && open2 && !store.state.openedWithoutTrigger) {
1317
+ const changes = {
1318
+ activeTriggerId: triggerId ?? null,
1319
+ activeTriggerElement: element,
1320
+ ...stateUpdates
1321
+ };
1322
+ store.update(changes);
1323
+ }
1324
+ });
1325
+ const registerTrigger = useStableCallback((element) => {
1326
+ baseRegisterTrigger(element);
1327
+ if (element) {
1328
+ applyTriggerData(element);
1329
+ }
1330
+ });
1331
+ useIsoLayoutEffect(() => {
1332
+ registerTrigger(triggerElementRef.current);
1333
+ return () => registerTrigger(null);
1334
+ }, [registerTrigger, triggerElementRef, store, triggerId]);
1335
+ useIsoLayoutEffect(() => {
1336
+ if (isMountedByThisTrigger) {
1337
+ const changes = {
1338
+ activeTriggerElement: triggerElementRef.current,
1339
+ ...stateUpdates
1340
+ };
1341
+ store.update(changes);
1342
+ }
1343
+ }, [isMountedByThisTrigger, store, triggerElementRef, ...Object.values(stateUpdates)]);
1344
+ return {
1345
+ registerTrigger,
1346
+ isMountedByThisTrigger
1347
+ };
1348
+ }
1349
+ function useImplicitActiveTrigger(store, options = {}) {
1350
+ const {
1351
+ closeOnActiveTriggerUnmount = false
1352
+ } = options;
1353
+ const resolvedActiveTriggerIdRef = React.useRef(null);
1354
+ const open2 = store.useState("open");
1355
+ const reactiveTriggerCount = store.useState("triggerCount");
1356
+ const activeTriggerId = store.useState("activeTriggerId");
1357
+ const reactiveActiveTriggerElement = store.useState("activeTriggerElement");
1358
+ useIsoLayoutEffect(() => {
1359
+ if (!open2) {
1360
+ resolvedActiveTriggerIdRef.current = null;
1361
+ if (store.state.triggerCount !== 0) {
1362
+ store.set("triggerCount", 0);
1363
+ }
1364
+ if (store.state.openedWithoutTrigger) {
1365
+ store.set("openedWithoutTrigger", false);
1366
+ }
1367
+ return;
1368
+ }
1369
+ const triggerCount = store.context.triggerElements.size;
1370
+ const stateUpdates = {};
1371
+ if (store.state.triggerCount !== triggerCount) {
1372
+ stateUpdates.triggerCount = triggerCount;
1373
+ }
1374
+ const currentActiveTriggerId = store.select("activeTriggerId");
1375
+ let lostActiveTriggerId = null;
1376
+ if (currentActiveTriggerId) {
1377
+ const activeTriggerElement = store.context.triggerElements.getById(currentActiveTriggerId);
1378
+ if (!activeTriggerElement) {
1379
+ for (const [triggerId, triggerElement] of store.context.triggerElements.entries()) {
1380
+ if (triggerElement === store.state.activeTriggerElement) {
1381
+ stateUpdates.activeTriggerId = triggerId;
1382
+ stateUpdates.activeTriggerElement = triggerElement;
1383
+ resolvedActiveTriggerIdRef.current = triggerId;
1384
+ break;
1385
+ }
1386
+ }
1387
+ if (stateUpdates.activeTriggerId === void 0) {
1388
+ if (resolvedActiveTriggerIdRef.current === currentActiveTriggerId) {
1389
+ lostActiveTriggerId = currentActiveTriggerId;
1390
+ } else {
1391
+ resolvedActiveTriggerIdRef.current = null;
1392
+ }
1393
+ }
1394
+ } else {
1395
+ resolvedActiveTriggerIdRef.current = currentActiveTriggerId;
1396
+ if (activeTriggerElement !== store.state.activeTriggerElement) {
1397
+ stateUpdates.activeTriggerElement = activeTriggerElement;
1398
+ }
1399
+ }
1400
+ } else {
1401
+ resolvedActiveTriggerIdRef.current = null;
1402
+ }
1403
+ if (!lostActiveTriggerId && !currentActiveTriggerId && !store.state.openedWithoutTrigger && triggerCount === 1) {
1404
+ const iteratorResult = store.context.triggerElements.entries().next();
1405
+ if (!iteratorResult.done) {
1406
+ const [implicitTriggerId, implicitTriggerElement] = iteratorResult.value;
1407
+ stateUpdates.activeTriggerId = implicitTriggerId;
1408
+ stateUpdates.activeTriggerElement = implicitTriggerElement;
1409
+ resolvedActiveTriggerIdRef.current = implicitTriggerId;
1410
+ }
1411
+ }
1412
+ if (stateUpdates.triggerCount !== void 0 || stateUpdates.activeTriggerId !== void 0 || stateUpdates.activeTriggerElement !== void 0) {
1413
+ store.update(stateUpdates);
1414
+ }
1415
+ if (lostActiveTriggerId) {
1416
+ if (closeOnActiveTriggerUnmount) {
1417
+ queueMicrotask(() => {
1418
+ if (store.select("open") && store.select("activeTriggerId") === lostActiveTriggerId && !store.context.triggerElements.getById(lostActiveTriggerId)) {
1419
+ const eventDetails = createChangeEventDetails(none);
1420
+ store.setOpen(false, eventDetails);
1421
+ if (!eventDetails.isCanceled) {
1422
+ store.update({
1423
+ activeTriggerId: null,
1424
+ activeTriggerElement: null
1425
+ });
1426
+ }
1427
+ }
1428
+ });
1429
+ }
1430
+ }
1431
+ }, [open2, store, reactiveTriggerCount, activeTriggerId, reactiveActiveTriggerElement, closeOnActiveTriggerUnmount]);
1432
+ }
1433
+ function useOpenStateTransitions(open2, store, onUnmount, animateInitialOpen) {
1434
+ const {
1435
+ mounted,
1436
+ transitionStatus,
1437
+ forceUnmount
1438
+ } = useUnmountAfterClose({
1439
+ open: open2,
1440
+ ref: store.context.popupRef,
1441
+ preventUnmountOnClose: store.useState("preventUnmountingOnClose"),
1442
+ setPreventUnmountOnClose: (preventUnmountOnClose) => store.set("preventUnmountingOnClose", preventUnmountOnClose),
1443
+ animateInitialOpen,
1444
+ onUnmount() {
1445
+ var _a2, _b;
1446
+ store.update({
1447
+ activeTriggerId: null,
1448
+ activeTriggerElement: null,
1449
+ mounted: false,
1450
+ preventUnmountingOnClose: false
1451
+ });
1452
+ onUnmount == null ? void 0 : onUnmount();
1453
+ (_b = (_a2 = store.context).onOpenChangeComplete) == null ? void 0 : _b.call(_a2, false);
1454
+ }
1455
+ });
1456
+ useRefWithInit(() => {
1457
+ store.set("mounted", mounted);
1458
+ return null;
1459
+ });
1460
+ store.useSyncedValues({
1461
+ mounted,
1462
+ transitionStatus
1463
+ });
1464
+ return {
1465
+ forceUnmount,
1466
+ transitionStatus
1467
+ };
1468
+ }
1469
+ function usePopupInteractionProps(store, statePart) {
1470
+ store.useSyncedValues(statePart);
1471
+ useIsoLayoutEffect(() => () => {
1472
+ store.update({
1473
+ activeTriggerProps: EMPTY_OBJECT,
1474
+ inactiveTriggerProps: EMPTY_OBJECT,
1475
+ popupProps: EMPTY_OBJECT
1476
+ });
1477
+ }, [store]);
1478
+ }
1479
+ function usePopupRootSync(store, open2) {
1480
+ useIsoLayoutEffect(() => {
1481
+ if (!open2 && store.state.openMethod !== null) {
1482
+ store.set("openMethod", null);
1483
+ }
1484
+ }, [open2, store]);
1485
+ useIsoLayoutEffect(() => () => {
1486
+ if (store.state.openMethod !== null) {
1487
+ store.set("openMethod", null);
1488
+ }
1489
+ }, [store]);
1490
+ }
1491
+ let devElementIdsByMap;
1492
+ function getDevElementIds(map) {
1493
+ devElementIdsByMap ?? (devElementIdsByMap = /* @__PURE__ */ new WeakMap());
1494
+ let elementIds = devElementIdsByMap.get(map);
1495
+ if (!elementIds) {
1496
+ elementIds = /* @__PURE__ */ new WeakMap();
1497
+ devElementIdsByMap.set(map, elementIds);
1498
+ }
1499
+ return elementIds;
1500
+ }
1501
+ class PopupTriggerMap {
1502
+ constructor() {
1503
+ __publicField(this, "idMap", /* @__PURE__ */ new Map());
1504
+ }
1505
+ /**
1506
+ * Adds a trigger element with the given ID.
1507
+ *
1508
+ * Note: The provided element is assumed to not be registered under multiple IDs.
1509
+ */
1510
+ add(id, element) {
1511
+ if (process.env.NODE_ENV !== "production") {
1512
+ const elementIds = getDevElementIds(this);
1513
+ const existingId = elementIds.get(element);
1514
+ if (existingId !== void 0 && existingId !== id) {
1515
+ throw new Error("Base UI: A trigger element cannot be registered under multiple IDs in PopupTriggerMap.");
1516
+ }
1517
+ const previousElement = this.idMap.get(id);
1518
+ if (previousElement !== void 0 && previousElement !== element) {
1519
+ elementIds.delete(previousElement);
1520
+ }
1521
+ elementIds.set(element, id);
1522
+ }
1523
+ this.idMap.set(id, element);
1524
+ }
1525
+ /**
1526
+ * Removes the trigger element with the given ID.
1527
+ */
1528
+ delete(id) {
1529
+ var _a2;
1530
+ if (process.env.NODE_ENV !== "production") {
1531
+ const element = this.idMap.get(id);
1532
+ if (element !== void 0) {
1533
+ (_a2 = devElementIdsByMap == null ? void 0 : devElementIdsByMap.get(this)) == null ? void 0 : _a2.delete(element);
1534
+ }
1535
+ }
1536
+ this.idMap.delete(id);
1537
+ }
1538
+ /**
1539
+ * Whether the given element is registered as a trigger.
1540
+ */
1541
+ hasElement(element) {
1542
+ for (const registered of this.idMap.values()) {
1543
+ if (registered === element) {
1544
+ return true;
1545
+ }
1546
+ }
1547
+ return false;
1548
+ }
1549
+ /**
1550
+ * Whether there is a registered trigger element matching the given predicate.
1551
+ */
1552
+ hasMatchingElement(predicate) {
1553
+ for (const element of this.idMap.values()) {
1554
+ if (predicate(element)) {
1555
+ return true;
1556
+ }
1557
+ }
1558
+ return false;
1559
+ }
1560
+ /**
1561
+ * Returns the trigger element associated with the given ID, or undefined if no such element exists.
1562
+ */
1563
+ getById(id) {
1564
+ return this.idMap.get(id);
1565
+ }
1566
+ /**
1567
+ * Returns an iterable of all registered trigger entries, where each entry is a tuple of [id, element].
1568
+ */
1569
+ entries() {
1570
+ return this.idMap.entries();
1571
+ }
1572
+ /**
1573
+ * Returns an iterable of all registered trigger elements.
1574
+ */
1575
+ elements() {
1576
+ return this.idMap.values();
1577
+ }
1578
+ /**
1579
+ * Returns the number of registered trigger elements.
1580
+ */
1581
+ get size() {
1582
+ return this.idMap.size;
1583
+ }
1584
+ }
1585
+ var withSelector = { exports: {} };
1586
+ var withSelector_production = {};
1587
+ /**
1588
+ * @license React
1589
+ * use-sync-external-store-shim/with-selector.production.js
1590
+ *
1591
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
1592
+ *
1593
+ * This source code is licensed under the MIT license found in the
1594
+ * LICENSE file in the root directory of this source tree.
1595
+ */
1596
+ var hasRequiredWithSelector_production;
1597
+ function requireWithSelector_production() {
1598
+ if (hasRequiredWithSelector_production) return withSelector_production;
1599
+ hasRequiredWithSelector_production = 1;
1600
+ var React2 = React__default, shim = shimExports;
1601
+ function is(x, y) {
1602
+ return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
1603
+ }
1604
+ var objectIs = "function" === typeof Object.is ? Object.is : is, useSyncExternalStore = shim.useSyncExternalStore, useRef = React2.useRef, useEffect = React2.useEffect, useMemo = React2.useMemo, useDebugValue = React2.useDebugValue;
1605
+ withSelector_production.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
1606
+ var instRef = useRef(null);
1607
+ if (null === instRef.current) {
1608
+ var inst = { hasValue: false, value: null };
1609
+ instRef.current = inst;
1610
+ } else inst = instRef.current;
1611
+ instRef = useMemo(
1612
+ function() {
1613
+ function memoizedSelector(nextSnapshot) {
1614
+ if (!hasMemo) {
1615
+ hasMemo = true;
1616
+ memoizedSnapshot = nextSnapshot;
1617
+ nextSnapshot = selector(nextSnapshot);
1618
+ if (void 0 !== isEqual && inst.hasValue) {
1619
+ var currentSelection = inst.value;
1620
+ if (isEqual(currentSelection, nextSnapshot))
1621
+ return memoizedSelection = currentSelection;
1622
+ }
1623
+ return memoizedSelection = nextSnapshot;
1624
+ }
1625
+ currentSelection = memoizedSelection;
1626
+ if (objectIs(memoizedSnapshot, nextSnapshot)) return currentSelection;
1627
+ var nextSelection = selector(nextSnapshot);
1628
+ if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
1629
+ return memoizedSnapshot = nextSnapshot, currentSelection;
1630
+ memoizedSnapshot = nextSnapshot;
1631
+ return memoizedSelection = nextSelection;
1632
+ }
1633
+ var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot;
1634
+ return [
1635
+ function() {
1636
+ return memoizedSelector(getSnapshot());
1637
+ },
1638
+ null === maybeGetServerSnapshot ? void 0 : function() {
1639
+ return memoizedSelector(maybeGetServerSnapshot());
1640
+ }
1641
+ ];
1642
+ },
1643
+ [getSnapshot, getServerSnapshot, selector, isEqual]
1644
+ );
1645
+ var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
1646
+ useEffect(
1647
+ function() {
1648
+ inst.hasValue = true;
1649
+ inst.value = value;
1650
+ },
1651
+ [value]
1652
+ );
1653
+ useDebugValue(value);
1654
+ return value;
1655
+ };
1656
+ return withSelector_production;
1657
+ }
1658
+ var withSelector_development = {};
1659
+ /**
1660
+ * @license React
1661
+ * use-sync-external-store-shim/with-selector.development.js
1662
+ *
1663
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
1664
+ *
1665
+ * This source code is licensed under the MIT license found in the
1666
+ * LICENSE file in the root directory of this source tree.
1667
+ */
1668
+ var hasRequiredWithSelector_development;
1669
+ function requireWithSelector_development() {
1670
+ if (hasRequiredWithSelector_development) return withSelector_development;
1671
+ hasRequiredWithSelector_development = 1;
1672
+ "production" !== process.env.NODE_ENV && function() {
1673
+ function is(x, y) {
1674
+ return x === y && (0 !== x || 1 / x === 1 / y) || x !== x && y !== y;
1675
+ }
1676
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
1677
+ var React2 = React__default, shim = shimExports, objectIs = "function" === typeof Object.is ? Object.is : is, useSyncExternalStore = shim.useSyncExternalStore, useRef = React2.useRef, useEffect = React2.useEffect, useMemo = React2.useMemo, useDebugValue = React2.useDebugValue;
1678
+ withSelector_development.useSyncExternalStoreWithSelector = function(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
1679
+ var instRef = useRef(null);
1680
+ if (null === instRef.current) {
1681
+ var inst = { hasValue: false, value: null };
1682
+ instRef.current = inst;
1683
+ } else inst = instRef.current;
1684
+ instRef = useMemo(
1685
+ function() {
1686
+ function memoizedSelector(nextSnapshot) {
1687
+ if (!hasMemo) {
1688
+ hasMemo = true;
1689
+ memoizedSnapshot = nextSnapshot;
1690
+ nextSnapshot = selector(nextSnapshot);
1691
+ if (void 0 !== isEqual && inst.hasValue) {
1692
+ var currentSelection = inst.value;
1693
+ if (isEqual(currentSelection, nextSnapshot))
1694
+ return memoizedSelection = currentSelection;
1695
+ }
1696
+ return memoizedSelection = nextSnapshot;
1697
+ }
1698
+ currentSelection = memoizedSelection;
1699
+ if (objectIs(memoizedSnapshot, nextSnapshot))
1700
+ return currentSelection;
1701
+ var nextSelection = selector(nextSnapshot);
1702
+ if (void 0 !== isEqual && isEqual(currentSelection, nextSelection))
1703
+ return memoizedSnapshot = nextSnapshot, currentSelection;
1704
+ memoizedSnapshot = nextSnapshot;
1705
+ return memoizedSelection = nextSelection;
1706
+ }
1707
+ var hasMemo = false, memoizedSnapshot, memoizedSelection, maybeGetServerSnapshot = void 0 === getServerSnapshot ? null : getServerSnapshot;
1708
+ return [
1709
+ function() {
1710
+ return memoizedSelector(getSnapshot());
1711
+ },
1712
+ null === maybeGetServerSnapshot ? void 0 : function() {
1713
+ return memoizedSelector(maybeGetServerSnapshot());
1714
+ }
1715
+ ];
1716
+ },
1717
+ [getSnapshot, getServerSnapshot, selector, isEqual]
1718
+ );
1719
+ var value = useSyncExternalStore(subscribe, instRef[0], instRef[1]);
1720
+ useEffect(
1721
+ function() {
1722
+ inst.hasValue = true;
1723
+ inst.value = value;
1724
+ },
1725
+ [value]
1726
+ );
1727
+ useDebugValue(value);
1728
+ return value;
1729
+ };
1730
+ "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
1731
+ }();
1732
+ return withSelector_development;
1733
+ }
1734
+ if (process.env.NODE_ENV === "production") {
1735
+ withSelector.exports = requireWithSelector_production();
1736
+ } else {
1737
+ withSelector.exports = requireWithSelector_development();
1738
+ }
1739
+ var withSelectorExports = withSelector.exports;
1740
+ const hooks = [];
1741
+ let currentInstance = void 0;
1742
+ function getInstance() {
1743
+ return currentInstance;
1744
+ }
1745
+ function register(hook) {
1746
+ hooks.push(hook);
1747
+ }
1748
+ function fastComponent(fn) {
1749
+ const FastComponent = (props, forwardedRef) => {
1750
+ const instance = useRefWithInit(createInstance).current;
1751
+ let result;
1752
+ try {
1753
+ currentInstance = instance;
1754
+ for (const hook of hooks) {
1755
+ hook.before(instance);
1756
+ }
1757
+ result = fn(props, forwardedRef);
1758
+ for (const hook of hooks) {
1759
+ hook.after(instance);
1760
+ }
1761
+ instance.didInitialize = true;
1762
+ } finally {
1763
+ currentInstance = void 0;
1764
+ }
1765
+ return result;
1766
+ };
1767
+ FastComponent.displayName = fn.displayName || fn.name;
1768
+ return FastComponent;
1769
+ }
1770
+ function fastComponentRef(fn) {
1771
+ return /* @__PURE__ */ React.forwardRef(fastComponent(fn));
1772
+ }
1773
+ function createInstance() {
1774
+ return {
1775
+ didInitialize: false
1776
+ };
1777
+ }
1778
+ const canUseRawUseSyncExternalStore = isReactVersionAtLeast(19);
1779
+ const useStoreImplementation = canUseRawUseSyncExternalStore ? useStoreFast : useStoreLegacy;
1780
+ function useStore(store, selector, a1, a2, a3) {
1781
+ return useStoreImplementation(store, selector, a1, a2, a3);
1782
+ }
1783
+ function useStoreR19(store, selector, a1, a2, a3) {
1784
+ const getSelection = React.useCallback(() => selector(store.getSnapshot(), a1, a2, a3), [store, selector, a1, a2, a3]);
1785
+ return shimExports.useSyncExternalStore(store.subscribe, getSelection, getSelection);
1786
+ }
1787
+ register({
1788
+ before(instance) {
1789
+ instance.syncIndex = 0;
1790
+ if (!instance.didInitialize) {
1791
+ instance.syncTick = 1;
1792
+ instance.syncHooks = [];
1793
+ instance.didChangeStore = true;
1794
+ instance.getSnapshot = () => {
1795
+ let didChange = false;
1796
+ for (let i = 0; i < instance.syncHooks.length; i += 1) {
1797
+ const hook = instance.syncHooks[i];
1798
+ const value = hook.selector(hook.store.state, hook.a1, hook.a2, hook.a3);
1799
+ if (!Object.is(hook.value, value)) {
1800
+ didChange = true;
1801
+ hook.value = value;
1802
+ }
1803
+ }
1804
+ if (didChange) {
1805
+ instance.syncTick += 1;
1806
+ }
1807
+ return instance.syncTick;
1808
+ };
1809
+ }
1810
+ },
1811
+ after(instance) {
1812
+ if (instance.syncHooks.length > 0) {
1813
+ if (instance.didChangeStore) {
1814
+ instance.didChangeStore = false;
1815
+ instance.subscribe = (onStoreChange) => {
1816
+ const stores = /* @__PURE__ */ new Set();
1817
+ for (const hook of instance.syncHooks) {
1818
+ stores.add(hook.store);
1819
+ }
1820
+ const unsubscribes = [];
1821
+ for (const store of stores) {
1822
+ unsubscribes.push(store.subscribe(onStoreChange));
1823
+ }
1824
+ return () => {
1825
+ for (const unsubscribe of unsubscribes) {
1826
+ unsubscribe();
1827
+ }
1828
+ };
1829
+ };
1830
+ }
1831
+ shimExports.useSyncExternalStore(instance.subscribe, instance.getSnapshot, instance.getSnapshot);
1832
+ }
1833
+ }
1834
+ });
1835
+ function useStoreFast(store, selector, a1, a2, a3) {
1836
+ const instance = getInstance();
1837
+ if (!instance) {
1838
+ return useStoreR19(store, selector, a1, a2, a3);
1839
+ }
1840
+ const index = instance.syncIndex;
1841
+ instance.syncIndex += 1;
1842
+ let hook;
1843
+ if (!instance.didInitialize) {
1844
+ hook = {
1845
+ store,
1846
+ selector,
1847
+ a1,
1848
+ a2,
1849
+ a3,
1850
+ value: selector(store.getSnapshot(), a1, a2, a3)
1851
+ };
1852
+ instance.syncHooks.push(hook);
1853
+ } else {
1854
+ hook = instance.syncHooks[index];
1855
+ if (hook.store !== store || hook.selector !== selector || !Object.is(hook.a1, a1) || !Object.is(hook.a2, a2) || !Object.is(hook.a3, a3)) {
1856
+ if (hook.store !== store) {
1857
+ instance.didChangeStore = true;
1858
+ }
1859
+ hook.store = store;
1860
+ hook.selector = selector;
1861
+ hook.a1 = a1;
1862
+ hook.a2 = a2;
1863
+ hook.a3 = a3;
1864
+ hook.value = selector(store.getSnapshot(), a1, a2, a3);
1865
+ }
1866
+ }
1867
+ return hook.value;
1868
+ }
1869
+ function useStoreLegacy(store, selector, a1, a2, a3) {
1870
+ return withSelectorExports.useSyncExternalStoreWithSelector(store.subscribe, store.getSnapshot, store.getSnapshot, (state) => selector(state, a1, a2, a3));
1871
+ }
1872
+ class Store {
1873
+ /**
1874
+ * The current state of the store.
1875
+ * This property is updated immediately when the state changes as a result of calling {@link setState}, {@link update}, or {@link set}.
1876
+ * To subscribe to state changes, use the {@link useState} method. The value returned by {@link useState} is updated after the component renders (similarly to React's useState).
1877
+ * The values can be used directly (to avoid subscribing to the store) in effects or event handlers.
1878
+ *
1879
+ * Do not modify properties in state directly. Instead, use the provided methods to ensure proper state management and listener notification.
1880
+ */
1881
+ // Internal state to handle recursive `setState()` calls
1882
+ constructor(state) {
1883
+ /**
1884
+ * Registers a listener that will be called whenever the store's state changes.
1885
+ *
1886
+ * @param fn The listener function to be called on state changes.
1887
+ * @returns A function to unsubscribe the listener.
1888
+ */
1889
+ __publicField(this, "subscribe", (fn) => {
1890
+ this.listeners.add(fn);
1891
+ return () => {
1892
+ this.listeners.delete(fn);
1893
+ };
1894
+ });
1895
+ /**
1896
+ * Returns the current state of the store.
1897
+ */
1898
+ __publicField(this, "getSnapshot", () => {
1899
+ return this.state;
1900
+ });
1901
+ this.state = state;
1902
+ this.listeners = /* @__PURE__ */ new Set();
1903
+ this.updateTick = 0;
1904
+ }
1905
+ /**
1906
+ * Creates a store with the given initial state, constructing the class it is called on.
1907
+ * Calling it on a generic base class (e.g. `ReactStore.create(...)`) constructs that
1908
+ * class but degrades the inferred instance type to `Store`; use `new` there instead.
1909
+ */
1910
+ static create(state) {
1911
+ return new this(state);
1912
+ }
1913
+ /**
1914
+ * Updates the entire store's state and notifies all registered listeners.
1915
+ *
1916
+ * @param newState The new state to set for the store.
1917
+ */
1918
+ setState(newState) {
1919
+ if (this.state === newState) {
1920
+ return;
1921
+ }
1922
+ this.state = newState;
1923
+ this.updateTick += 1;
1924
+ const currentTick = this.updateTick;
1925
+ for (const listener of this.listeners) {
1926
+ if (currentTick !== this.updateTick) {
1927
+ return;
1928
+ }
1929
+ listener(newState);
1930
+ }
1931
+ }
1932
+ /**
1933
+ * Merges the provided changes into the current state and notifies listeners if there are changes.
1934
+ * Each value must match its state key. Pass an exact known subset rather than a broad
1935
+ * `Partial<State>`, which may contain `undefined` for required state fields.
1936
+ *
1937
+ * @param changes An object containing the changes to apply to the current state.
1938
+ */
1939
+ update(changes) {
1940
+ for (const key in changes) {
1941
+ if (!Object.is(this.state[key], changes[key])) {
1942
+ this.setState({
1943
+ ...this.state,
1944
+ ...changes
1945
+ });
1946
+ return;
1947
+ }
1948
+ }
1949
+ }
1950
+ /**
1951
+ * Sets a specific key in the store's state to a new value and notifies listeners if the value has changed.
1952
+ *
1953
+ * @param key The key in the store's state to update.
1954
+ * @param value The new value to set for the specified key.
1955
+ */
1956
+ set(key, value) {
1957
+ if (!Object.is(this.state[key], value)) {
1958
+ this.setState({
1959
+ ...this.state,
1960
+ [key]: value
1961
+ });
1962
+ }
1963
+ }
1964
+ /**
1965
+ * Gives the state a new reference and updates all registered listeners.
1966
+ */
1967
+ notifyAll() {
1968
+ const newState = {
1969
+ ...this.state
1970
+ };
1971
+ this.setState(newState);
1972
+ }
1973
+ use(selector, a1, a2, a3) {
1974
+ return useStore(this, selector, a1, a2, a3);
1975
+ }
1976
+ }
1977
+ class ReactStore extends Store {
1978
+ /**
1979
+ * Creates a new ReactStore instance.
1980
+ *
1981
+ * @param state Initial state of the store.
1982
+ * @param context Non-reactive context values.
1983
+ * @param selectors Optional selectors for use with `useState`.
1984
+ */
1985
+ constructor(state, context = {}, selectors2) {
1986
+ super(state);
1987
+ this.context = context;
1988
+ this.selectors = selectors2;
1989
+ }
1990
+ /**
1991
+ * Non-reactive values such as refs, callbacks, etc.
1992
+ */
1993
+ /**
1994
+ * Synchronizes a single external value into the store.
1995
+ *
1996
+ * Note that the while the value in `state` is updated immediately, the value returned
1997
+ * by `useState` is updated before the next render (similarly to React's `useState`).
1998
+ */
1999
+ useSyncedValue(key, value) {
2000
+ React.useDebugValue(key);
2001
+ const store = this;
2002
+ useIsoLayoutEffect(() => {
2003
+ if (store.state[key] !== value) {
2004
+ store.set(key, value);
2005
+ }
2006
+ }, [store, key, value]);
2007
+ }
2008
+ /**
2009
+ * Synchronizes a single external value into the store and
2010
+ * cleans it up (sets to `undefined`) on unmount.
2011
+ *
2012
+ * Note that the while the value in `state` is updated immediately, the value returned
2013
+ * by `useState` is updated before the next render (similarly to React's `useState`).
2014
+ */
2015
+ useSyncedValueWithCleanup(key, value) {
2016
+ const store = this;
2017
+ useIsoLayoutEffect(() => {
2018
+ if (store.state[key] !== value) {
2019
+ store.set(key, value);
2020
+ }
2021
+ return () => {
2022
+ store.set(key, void 0);
2023
+ };
2024
+ }, [store, key, value]);
2025
+ }
2026
+ /**
2027
+ * Synchronizes multiple external values into the store.
2028
+ * Each value must match its state key. Pass an exact known subset rather than a broad
2029
+ * `Partial<State>`, which may contain `undefined` for required state fields.
2030
+ *
2031
+ * Note that the while the values in `state` are updated immediately, the values returned
2032
+ * by `useState` are updated before the next render (similarly to React's `useState`).
2033
+ *
2034
+ * @param statePart An exact subset of state fields to synchronize. Unknown keys are not accepted.
2035
+ */
2036
+ useSyncedValues(statePart) {
2037
+ const store = this;
2038
+ if (process.env.NODE_ENV !== "production") {
2039
+ React.useDebugValue(statePart, (p) => Object.keys(p));
2040
+ const keys = React.useRef(Object.keys(statePart)).current;
2041
+ const nextKeys = Object.keys(statePart);
2042
+ if (keys.length !== nextKeys.length || keys.some((key, index) => key !== nextKeys[index])) {
2043
+ console.error("ReactStore.useSyncedValues expects the same prop keys on every render. Keys should be stable.");
2044
+ }
2045
+ }
2046
+ const dependencies = Object.values(statePart);
2047
+ useIsoLayoutEffect(() => {
2048
+ store.update(statePart);
2049
+ }, [store, ...dependencies]);
2050
+ }
2051
+ /**
2052
+ * Registers a controllable prop pair (`controlled`, `defaultValue`) for a specific key. If `controlled`
2053
+ * is non-undefined, the store's state at `key` is updated to match `controlled`.
2054
+ */
2055
+ useControlledProp(key, controlled) {
2056
+ React.useDebugValue(key);
2057
+ const store = this;
2058
+ const isControlled = controlled !== void 0;
2059
+ useIsoLayoutEffect(() => {
2060
+ if (isControlled && !Object.is(store.state[key], controlled)) {
2061
+ store.setState({
2062
+ ...store.state,
2063
+ [key]: controlled
2064
+ });
2065
+ }
2066
+ }, [store, key, controlled, isControlled]);
2067
+ if (process.env.NODE_ENV !== "production") {
2068
+ const cache = this.controlledValues ?? (this.controlledValues = /* @__PURE__ */ new Map());
2069
+ if (!cache.has(key)) {
2070
+ cache.set(key, isControlled);
2071
+ }
2072
+ const previouslyControlled = cache.get(key);
2073
+ if (previouslyControlled !== void 0 && previouslyControlled !== isControlled) {
2074
+ console.error(`A component is changing the ${previouslyControlled ? "" : "un"}controlled state of ${key.toString()} to be ${previouslyControlled ? "un" : ""}controlled. Elements should not switch from uncontrolled to controlled (or vice versa).`);
2075
+ }
2076
+ }
2077
+ }
2078
+ /** Gets the current value from the store using a selector with the provided key.
2079
+ *
2080
+ * @param key Key of the selector to use.
2081
+ */
2082
+ select(key, a1, a2, a3) {
2083
+ const selector = this.selectors[key];
2084
+ return selector(this.state, a1, a2, a3);
2085
+ }
2086
+ /**
2087
+ * Returns a value from the store's state using a selector function.
2088
+ * Used to subscribe to specific parts of the state.
2089
+ * This methods causes a rerender whenever the selected state changes.
2090
+ *
2091
+ * @param key Key of the selector to use.
2092
+ */
2093
+ useState(key, a1, a2, a3) {
2094
+ React.useDebugValue(key);
2095
+ return useStore(this, this.selectors[key], a1, a2, a3);
2096
+ }
2097
+ /**
2098
+ * Wraps a function with `useStableCallback` to ensure it has a stable reference
2099
+ * and assigns it to the context.
2100
+ *
2101
+ * @param key Key of the event callback. Must be a function in the context.
2102
+ * @param fn Function to assign.
2103
+ */
2104
+ useContextCallback(key, fn) {
2105
+ React.useDebugValue(key);
2106
+ const stableFunction = useStableCallback(fn ?? NOOP);
2107
+ this.context[key] = stableFunction;
2108
+ }
2109
+ /**
2110
+ * Returns a stable setter function for a specific key in the store's state.
2111
+ * It's commonly used to pass as a ref callback to React elements.
2112
+ *
2113
+ * @param key Key of the state to set.
2114
+ */
2115
+ useStateSetter(key) {
2116
+ const ref = React.useRef(void 0);
2117
+ if (ref.current === void 0) {
2118
+ ref.current = (value) => {
2119
+ this.set(key, value);
2120
+ };
2121
+ }
2122
+ return ref.current;
2123
+ }
2124
+ /**
2125
+ * Observes changes derived from the store's selectors and calls the listener when the selected value changes.
2126
+ *
2127
+ * @param key Key of the selector to observe.
2128
+ * @param listener Listener function called when the selector result changes.
2129
+ */
2130
+ observe(selector, listener) {
2131
+ let selectFn;
2132
+ if (typeof selector === "function") {
2133
+ selectFn = selector;
2134
+ } else {
2135
+ selectFn = this.selectors[selector];
2136
+ }
2137
+ let prevValue = selectFn(this.state);
2138
+ listener(prevValue, prevValue, this);
2139
+ return this.subscribe((nextState) => {
2140
+ const nextValue = selectFn(nextState);
2141
+ if (!Object.is(prevValue, nextValue)) {
2142
+ const oldValue = prevValue;
2143
+ prevValue = nextValue;
2144
+ listener(nextValue, oldValue, this);
2145
+ }
2146
+ });
2147
+ }
2148
+ }
2149
+ const selectors = {
2150
+ open: (state) => state.open,
2151
+ transitionStatus: (state) => state.transitionStatus,
2152
+ domReferenceElement: (state) => state.domReferenceElement,
2153
+ referenceElement: (state) => state.positionReference ?? state.referenceElement,
2154
+ floatingElement: (state) => state.floatingElement,
2155
+ floatingId: (state) => state.floatingId
2156
+ };
2157
+ class FloatingRootStore extends ReactStore {
2158
+ constructor(options) {
2159
+ const {
2160
+ syncOnly,
2161
+ nested,
2162
+ onOpenChange,
2163
+ triggerElements,
2164
+ ...initialState
2165
+ } = options;
2166
+ super({
2167
+ ...initialState,
2168
+ positionReference: initialState.referenceElement,
2169
+ domReferenceElement: initialState.referenceElement
2170
+ }, {
2171
+ onOpenChange,
2172
+ dataRef: {
2173
+ current: {}
2174
+ },
2175
+ events: createEventEmitter(),
2176
+ nested,
2177
+ triggerElements
2178
+ }, selectors);
2179
+ /**
2180
+ * Syncs the event used by hover logic to distinguish hover-open from click-like interaction.
2181
+ */
2182
+ __publicField(this, "syncOpenEvent", (newOpen, event) => {
2183
+ if (!newOpen || !this.state.open || // Prevent a pending hover-open from overwriting a click-open event, while allowing
2184
+ // click events to upgrade a hover-open.
2185
+ event != null && isClickLikeEvent(event)) {
2186
+ this.context.dataRef.current.openEvent = newOpen ? event : void 0;
2187
+ }
2188
+ });
2189
+ /**
2190
+ * Runs the root-owned side effects for an open state change.
2191
+ */
2192
+ __publicField(this, "dispatchOpenChange", (newOpen, eventDetails) => {
2193
+ this.syncOpenEvent(newOpen, eventDetails.event);
2194
+ const details = {
2195
+ open: newOpen,
2196
+ reason: eventDetails.reason,
2197
+ nativeEvent: eventDetails.event,
2198
+ nested: this.context.nested,
2199
+ triggerElement: eventDetails.trigger
2200
+ };
2201
+ this.context.events.emit("openchange", details);
2202
+ });
2203
+ /**
2204
+ * Emits the `openchange` event through the internal event emitter and calls the `onOpenChange` handler with the provided arguments.
2205
+ *
2206
+ * @param newOpen The new open state.
2207
+ * @param eventDetails Details about the event that triggered the open state change.
2208
+ */
2209
+ __publicField(this, "setOpen", (newOpen, eventDetails) => {
2210
+ var _a2, _b, _c, _d;
2211
+ if (this.syncOnly) {
2212
+ (_b = (_a2 = this.context).onOpenChange) == null ? void 0 : _b.call(_a2, newOpen, eventDetails);
2213
+ return;
2214
+ }
2215
+ this.dispatchOpenChange(newOpen, eventDetails);
2216
+ (_d = (_c = this.context).onOpenChange) == null ? void 0 : _d.call(_c, newOpen, eventDetails);
2217
+ });
2218
+ this.syncOnly = syncOnly;
2219
+ }
2220
+ }
2221
+ function createInitialPopupStoreState(triggerElements, floatingId, nested = false) {
2222
+ return {
2223
+ open: false,
2224
+ openProp: void 0,
2225
+ mounted: false,
2226
+ transitionStatus: void 0,
2227
+ floatingRootContext: new FloatingRootStore({
2228
+ open: false,
2229
+ transitionStatus: void 0,
2230
+ floatingElement: null,
2231
+ referenceElement: null,
2232
+ triggerElements,
2233
+ floatingId,
2234
+ syncOnly: true,
2235
+ nested,
2236
+ onOpenChange: void 0
2237
+ }),
2238
+ floatingId,
2239
+ triggerCount: 0,
2240
+ preventUnmountingOnClose: false,
2241
+ payload: void 0,
2242
+ activeTriggerId: null,
2243
+ activeTriggerElement: null,
2244
+ openedWithoutTrigger: false,
2245
+ triggerIdProp: void 0,
2246
+ popupElement: null,
2247
+ positionerElement: null,
2248
+ activeTriggerProps: EMPTY_OBJECT,
2249
+ inactiveTriggerProps: EMPTY_OBJECT,
2250
+ popupProps: EMPTY_OBJECT
2251
+ };
2252
+ }
2253
+ const activeTriggerIdSelector = (state) => state.triggerIdProp ?? state.activeTriggerId;
2254
+ const openSelector = (state) => state.openProp ?? state.open;
2255
+ const popupIdSelector = (state) => {
2256
+ var _a2;
2257
+ const popupId = ((_a2 = state.popupElement) == null ? void 0 : _a2.id) ?? state.floatingId;
2258
+ return popupId || void 0;
2259
+ };
2260
+ function triggerOwnsOpenPopup(state, triggerId) {
2261
+ return triggerId !== void 0 && openSelector(state) && activeTriggerIdSelector(state) === triggerId;
2262
+ }
2263
+ function triggerOwnsOpenPopupOrIsOnlyTrigger(state, triggerId) {
2264
+ if (triggerOwnsOpenPopup(state, triggerId)) {
2265
+ return true;
2266
+ }
2267
+ return triggerId !== void 0 && openSelector(state) && activeTriggerIdSelector(state) == null && !state.openedWithoutTrigger && state.triggerCount === 1;
2268
+ }
2269
+ const popupStoreSelectors = {
2270
+ open: openSelector,
2271
+ mounted: (state) => state.mounted,
2272
+ // `open` is written synchronously on an open change; `mounted`/`transitionStatus` sync in a
2273
+ // layout effect. Match useTransitionStatus so a retained popup does not miss its starting phase.
2274
+ transitionStatus: (state) => openSelector(state) && !state.mounted ? "starting" : state.transitionStatus,
2275
+ floatingRootContext: (state) => state.floatingRootContext,
2276
+ triggerCount: (state) => state.triggerCount,
2277
+ preventUnmountingOnClose: (state) => state.preventUnmountingOnClose,
2278
+ payload: (state) => state.payload,
2279
+ activeTriggerId: activeTriggerIdSelector,
2280
+ activeTriggerElement: (state) => state.mounted ? state.activeTriggerElement : null,
2281
+ popupId: popupIdSelector,
2282
+ /**
2283
+ * Whether the trigger with the given ID was used to open the popup.
2284
+ */
2285
+ isTriggerActive: (state, triggerId) => triggerId !== void 0 && activeTriggerIdSelector(state) === triggerId,
2286
+ /**
2287
+ * Whether the popup is open and was activated by a trigger with the given ID.
2288
+ */
2289
+ isOpenedByTrigger: (state, triggerId) => triggerOwnsOpenPopup(state, triggerId),
2290
+ /**
2291
+ * Whether the popup is mounted and was activated by a trigger with the given ID.
2292
+ */
2293
+ isMountedByTrigger: (state, triggerId) => triggerId !== void 0 && activeTriggerIdSelector(state) === triggerId && state.mounted,
2294
+ triggerProps: (state, isActive) => isActive ? state.activeTriggerProps : state.inactiveTriggerProps,
2295
+ /**
2296
+ * Popup id for the trigger that currently owns the open popup.
2297
+ */
2298
+ triggerPopupId: (state, triggerId) => triggerOwnsOpenPopupOrIsOnlyTrigger(state, triggerId) ? popupIdSelector(state) : void 0,
2299
+ popupProps: (state) => state.popupProps,
2300
+ popupElement: (state) => state.popupElement,
2301
+ positionerElement: (state) => state.positionerElement
2302
+ };
2303
+ function usePopupHandleStore(handle) {
2304
+ const subscribe = React.useCallback((listener) => {
2305
+ if (handle === void 0) {
2306
+ return NOOP;
2307
+ }
2308
+ return handle.subscribeStore(listener);
2309
+ }, [handle]);
2310
+ const getSnapshot = React.useCallback(() => {
2311
+ return handle === void 0 ? void 0 : handle.store;
2312
+ }, [handle]);
2313
+ return shimExports.useSyncExternalStore(subscribe, getSnapshot, () => handle == null ? void 0 : handle.serverStore);
2314
+ }
2315
+ export {
2316
+ useFloatingPortalNode as $,
2317
+ useFloatingNodeId as A,
2318
+ FloatingNode as B,
2319
+ CLICK_TRIGGER_IDENTIFIER as C,
2320
+ POPUP_COLLISION_AVOIDANCE as D,
2321
+ useFloatingTree as E,
2322
+ FOCUSABLE_POPUP_PROPS as F,
2323
+ usePortalContext as G,
2324
+ tabbable as H,
2325
+ mergeCleanups as I,
2326
+ createAttribute as J,
2327
+ getNodeAncestors as K,
2328
+ getNodeChildren as L,
2329
+ isVirtualClick as M,
2330
+ isVirtualPointerEvent as N,
2331
+ webkit as O,
2332
+ PopupTriggerMap as P,
2333
+ getNextTabbable as Q,
2334
+ ReactStore as R,
2335
+ getPreviousTabbable as S,
2336
+ stopEvent as T,
2337
+ isTabbable as U,
2338
+ focusable as V,
2339
+ isMouseLikePointerType as W,
2340
+ ios as X,
2341
+ mac as Y,
2342
+ useFloatingParentNodeId as Z,
2343
+ applyPopupOpenChange as _,
2344
+ popupStateMapping as a,
2345
+ DISABLED_TRANSITIONS_STYLE as a0,
2346
+ FloatingPortal as b,
2347
+ createDefaultInitialFocus as c,
2348
+ usePopupInteractionProps as d,
2349
+ popupStoreSelectors as e,
2350
+ createPopupOpenState as f,
2351
+ createInitialPopupStoreState as g,
2352
+ usePopupRootStore as h,
2353
+ usePopupRootSync as i,
2354
+ useImplicitActiveTrigger as j,
2355
+ useOpenStateTransitions as k,
2356
+ PopupHandleAttachment as l,
2357
+ fastComponent as m,
2358
+ fastComponentRef as n,
2359
+ usePopupHandleStore as o,
2360
+ popupTransitionStateMapping as p,
2361
+ useTriggerDataForwarding as q,
2362
+ attachPreventUnmountOnClose as r,
2363
+ PATIENT_CLICK_THRESHOLD as s,
2364
+ triggerOpenStateMapping as t,
2365
+ useDismiss as u,
2366
+ FloatingTree as v,
2367
+ isOutsideEvent as w,
2368
+ getTabbableNearElement as x,
2369
+ FocusGuard as y,
2370
+ pressableTriggerOpenStateMapping as z
2371
+ };
2372
+ //# sourceMappingURL=usePopupHandleStore-BdS-xYID.js.map