@tamagui/popover 2.7.7 → 3.0.0-beta.1091.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/cjs/Popover.cjs +522 -665
  2. package/dist/cjs/Popover.native.cjs +615 -0
  3. package/dist/cjs/Popover.native.js +549 -692
  4. package/dist/cjs/Popover.native.js.map +1 -1
  5. package/dist/cjs/index.cjs +9 -11
  6. package/dist/cjs/index.native.cjs +21 -0
  7. package/dist/cjs/index.native.js +9 -10
  8. package/dist/cjs/index.native.js.map +1 -1
  9. package/dist/cjs/useFloatingContext.cjs +213 -234
  10. package/dist/cjs/useFloatingContext.native.cjs +35 -0
  11. package/dist/cjs/useFloatingContext.native.js +19 -27
  12. package/dist/cjs/useFloatingContext.native.js.map +1 -1
  13. package/dist/esm/Popover.mjs +487 -618
  14. package/dist/esm/Popover.mjs.map +1 -1
  15. package/dist/esm/Popover.native.js +513 -645
  16. package/dist/esm/Popover.native.js.map +1 -1
  17. package/dist/esm/index.js +3 -3
  18. package/dist/esm/index.mjs +3 -3
  19. package/dist/esm/index.native.js +3 -3
  20. package/dist/esm/useFloatingContext.mjs +198 -208
  21. package/dist/esm/useFloatingContext.mjs.map +1 -1
  22. package/dist/esm/useFloatingContext.native.js +4 -2
  23. package/dist/esm/useFloatingContext.native.js.map +1 -1
  24. package/dist/jsx/Popover.mjs +487 -618
  25. package/dist/jsx/Popover.mjs.map +1 -1
  26. package/dist/jsx/Popover.native.cjs +615 -0
  27. package/dist/jsx/Popover.native.js +549 -692
  28. package/dist/jsx/Popover.native.js.map +1 -1
  29. package/dist/jsx/index.js +3 -3
  30. package/dist/jsx/index.mjs +3 -3
  31. package/dist/jsx/index.native.cjs +21 -0
  32. package/dist/jsx/index.native.js +9 -10
  33. package/dist/jsx/index.native.js.map +1 -1
  34. package/dist/jsx/useFloatingContext.mjs +198 -208
  35. package/dist/jsx/useFloatingContext.mjs.map +1 -1
  36. package/dist/jsx/useFloatingContext.native.cjs +35 -0
  37. package/dist/jsx/useFloatingContext.native.js +19 -27
  38. package/dist/jsx/useFloatingContext.native.js.map +1 -1
  39. package/package.json +24 -23
  40. package/src/Popover.tsx +157 -154
  41. package/src/useFloatingContext.tsx +15 -7
  42. package/types/Popover.d.ts +40 -112
  43. package/types/Popover.d.ts.map +1 -1
  44. package/types/useFloatingContext.d.ts +5 -2
  45. package/types/useFloatingContext.d.ts.map +1 -1
  46. package/dist/esm/index.js.map +0 -1
  47. package/dist/esm/index.mjs.map +0 -1
  48. package/dist/esm/index.native.js.map +0 -1
  49. package/dist/jsx/index.js.map +0 -1
  50. package/dist/jsx/index.mjs.map +0 -1
@@ -4,7 +4,7 @@ import { Animate } from "@tamagui/animate";
4
4
  import { ResetPresence } from "@tamagui/animate-presence";
5
5
  import { useComposedRefs } from "@tamagui/compose-refs";
6
6
  import { isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
7
- import { View, createStyledContext, useCreateShallowSetState, useEvent, useGet } from "@tamagui/core";
7
+ import { View, createRefComponent, createStyledContext, createStyledHOC, useCreateShallowSetState, useEvent } from "@tamagui/core";
8
8
  import { DismissableBranch } from "@tamagui/dismissable";
9
9
  import { FloatingOverrideContext } from "@tamagui/floating";
10
10
  import { FocusScopeController } from "@tamagui/focus-scope";
@@ -12,684 +12,552 @@ import { composeEventHandlers, withStaticProperties } from "@tamagui/helpers";
12
12
  import { Popper, PopperAnchor, PopperArrow, PopperArrowFrame, PopperContent, PopperContentFrame, PopperProvider, usePopperContext } from "@tamagui/popper";
13
13
  import { Portal, needsPortalRepropagation } from "@tamagui/portal";
14
14
  import { ScrollView } from "@tamagui/scroll-view";
15
- import { SheetController } from "@tamagui/sheet/controller";
16
15
  import { YStack } from "@tamagui/stacks";
17
16
  import { useControllableState } from "@tamagui/use-controllable-state";
18
17
  import * as React from "react";
19
18
  import { useFloatingContext } from "./useFloatingContext.native.js";
19
+
20
20
  var needsRepropagation = needsPortalRepropagation();
21
- var openPopovers = /* @__PURE__ */new Set();
22
- var hasOpenPopovers = function () {
23
- return openPopovers.size > 0;
21
+ var openPopovers = /* @__PURE__ */ new Set();
22
+ var hasOpenPopovers = function() {
23
+ return openPopovers.size > 0;
24
24
  };
25
- var closeOpenPopovers = function () {
26
- if (openPopovers.size === 0) return false;
27
- openPopovers.forEach(function (setOpen) {
28
- return setOpen(false);
29
- });
30
- return true;
25
+ var closeOpenPopovers = function() {
26
+ if (openPopovers.size === 0) return false;
27
+ openPopovers.forEach(function(setOpen) {
28
+ return setOpen(false);
29
+ });
30
+ return true;
31
31
  };
32
- var closeLastOpenedPopover = function () {
33
- if (openPopovers.size === 0) return false;
34
- var last = Array.from(openPopovers).pop();
35
- if (last) {
36
- last(false);
37
- return true;
38
- }
39
- return false;
32
+ var closeLastOpenedPopover = function() {
33
+ if (openPopovers.size === 0) return false;
34
+ var last = Array.from(openPopovers).pop();
35
+ if (last) {
36
+ last(false);
37
+ return true;
38
+ }
39
+ return false;
40
40
  };
41
41
  var PopoverContext = createStyledContext({}, "Popover__");
42
- var PopoverZIndexContext = /* @__PURE__ */React.createContext(void 0);
43
- var PopoverAdaptHiddenContext = /* @__PURE__ */React.createContext(true);
42
+ var PopoverZIndexContext = /* @__PURE__ */ React.createContext(void 0);
44
43
  var PopoverTriggerContext = createStyledContext({}, "PopoverTrigger__");
45
44
  var usePopoverContext = PopoverContext.useStyledContext;
46
45
  var usePopoverTriggerContext = PopoverTriggerContext.useStyledContext;
47
46
  function usePopoverOpen(scope) {
48
- return usePopoverContext(scope).open;
47
+ return usePopoverContext(scope).open;
49
48
  }
50
49
  function usePopoverTriggerSetup(open) {
51
- var triggerStateSettersRef = React.useRef(/* @__PURE__ */new Map());
52
- var activeTriggerIdRef = React.useRef(null);
53
- var setActiveTrigger = useEvent(function (id) {
54
- var prevId = activeTriggerIdRef.current;
55
- if (prevId === id) return;
56
- if (prevId) {
57
- var _triggerStateSettersRef_current_get;
58
- (_triggerStateSettersRef_current_get = triggerStateSettersRef.current.get(prevId)) === null || _triggerStateSettersRef_current_get === void 0 || _triggerStateSettersRef_current_get(false);
59
- }
60
- activeTriggerIdRef.current = id;
61
- if (id && open) {
62
- var _triggerStateSettersRef_current_get1;
63
- (_triggerStateSettersRef_current_get1 = triggerStateSettersRef.current.get(id)) === null || _triggerStateSettersRef_current_get1 === void 0 || _triggerStateSettersRef_current_get1(true);
64
- }
65
- });
66
- var registerTrigger = useEvent(function (id, setOpenState) {
67
- triggerStateSettersRef.current.set(id, setOpenState);
68
- setOpenState(activeTriggerIdRef.current === id && open);
69
- });
70
- var unregisterTrigger = useEvent(function (id) {
71
- triggerStateSettersRef.current.delete(id);
72
- if (activeTriggerIdRef.current === id) activeTriggerIdRef.current = null;
73
- });
74
- React.useEffect(function () {
75
- if (!open) {
76
- setActiveTrigger(null);
77
- return;
78
- }
79
- var activeId = activeTriggerIdRef.current;
80
- if (activeId) {
81
- var _triggerStateSettersRef_current_get;
82
- (_triggerStateSettersRef_current_get = triggerStateSettersRef.current.get(activeId)) === null || _triggerStateSettersRef_current_get === void 0 || _triggerStateSettersRef_current_get(true);
83
- }
84
- }, [open, setActiveTrigger]);
85
- return {
86
- setActiveTrigger,
87
- registerTrigger,
88
- unregisterTrigger
89
- };
50
+ var triggerStateSettersRef = React.useRef(/* @__PURE__ */ new Map());
51
+ var activeTriggerIdRef = React.useRef(null);
52
+ var setActiveTrigger = useEvent(function(id) {
53
+ var prevId = activeTriggerIdRef.current;
54
+ if (prevId === id) return;
55
+ if (prevId) {
56
+ var _triggerStateSettersRef_current_get;
57
+ (_triggerStateSettersRef_current_get = triggerStateSettersRef.current.get(prevId)) === null || _triggerStateSettersRef_current_get === void 0 || _triggerStateSettersRef_current_get(false);
58
+ }
59
+ activeTriggerIdRef.current = id;
60
+ if (id && open) {
61
+ var _triggerStateSettersRef_current_get1;
62
+ (_triggerStateSettersRef_current_get1 = triggerStateSettersRef.current.get(id)) === null || _triggerStateSettersRef_current_get1 === void 0 || _triggerStateSettersRef_current_get1(true);
63
+ }
64
+ });
65
+ var registerTrigger = useEvent(function(id, setOpenState) {
66
+ triggerStateSettersRef.current.set(id, setOpenState);
67
+ setOpenState(activeTriggerIdRef.current === id && open);
68
+ });
69
+ var unregisterTrigger = useEvent(function(id) {
70
+ triggerStateSettersRef.current.delete(id);
71
+ if (activeTriggerIdRef.current === id) activeTriggerIdRef.current = null;
72
+ });
73
+ React.useEffect(function() {
74
+ if (!open) {
75
+ setActiveTrigger(null);
76
+ return;
77
+ }
78
+ var activeId = activeTriggerIdRef.current;
79
+ if (activeId) {
80
+ var _triggerStateSettersRef_current_get;
81
+ (_triggerStateSettersRef_current_get = triggerStateSettersRef.current.get(activeId)) === null || _triggerStateSettersRef_current_get === void 0 || _triggerStateSettersRef_current_get(true);
82
+ }
83
+ }, [open, setActiveTrigger]);
84
+ return {
85
+ setActiveTrigger,
86
+ registerTrigger,
87
+ unregisterTrigger
88
+ };
90
89
  }
91
- var PopoverContextProvider = /* @__PURE__ */React.memo(function (param) {
92
- var {
93
- scope,
94
- children,
95
- open,
96
- onOpenChange,
97
- onOpenToggle,
98
- triggerRef,
99
- id = "",
100
- contentId,
101
- hasCustomAnchor = false,
102
- onCustomAnchorAdd = voidFn,
103
- onCustomAnchorRemove = voidFn,
104
- anchorTo,
105
- adaptScope,
106
- breakpointActive,
107
- keepChildrenMounted,
108
- disableDismissable,
109
- hoverable
110
- } = param;
111
- var [branches] = React.useState(function () {
112
- return /* @__PURE__ */new Set();
113
- });
114
- var {
115
- setActiveTrigger,
116
- registerTrigger,
117
- unregisterTrigger
118
- } = usePopoverTriggerSetup(open);
119
- return /* @__PURE__ */jsx(PopoverContext.Provider, {
120
- scope,
121
- popoverScope: scope,
122
- adaptScope,
123
- id,
124
- contentId,
125
- triggerRef,
126
- open,
127
- onOpenChange,
128
- onOpenToggle,
129
- hasCustomAnchor,
130
- onCustomAnchorAdd,
131
- onCustomAnchorRemove,
132
- anchorTo,
133
- branches,
134
- breakpointActive,
135
- keepChildrenMounted,
136
- disableDismissable,
137
- hoverable,
138
- children: /* @__PURE__ */jsx(PopoverTriggerContext.Provider, {
139
- scope,
140
- triggerRef,
141
- hasCustomAnchor,
142
- anchorTo,
143
- branches,
144
- onOpenToggle,
145
- setActiveTrigger,
146
- registerTrigger,
147
- unregisterTrigger,
148
- children
149
- })
150
- });
90
+ var PopoverContextProvider = /* @__PURE__ */ React.memo(function(param) {
91
+ var { scope, children, open, onOpenChange, onOpenToggle, triggerRef, id = "", contentId, hasCustomAnchor = false, onCustomAnchorAdd = voidFn, onCustomAnchorRemove = voidFn, anchorTo, adaptScope, breakpointActive, keepChildrenMounted, disableDismissable, hoverable, closeReasonRef } = param;
92
+ var [branches] = React.useState(function() {
93
+ return /* @__PURE__ */ new Set();
94
+ });
95
+ var { setActiveTrigger, registerTrigger, unregisterTrigger } = usePopoverTriggerSetup(open);
96
+ return /* @__PURE__ */ jsx(PopoverContext.Provider, {
97
+ scope,
98
+ popoverScope: scope,
99
+ adaptScope,
100
+ id,
101
+ contentId,
102
+ triggerRef,
103
+ open,
104
+ onOpenChange,
105
+ onOpenToggle,
106
+ hasCustomAnchor,
107
+ onCustomAnchorAdd,
108
+ onCustomAnchorRemove,
109
+ anchorTo,
110
+ branches,
111
+ breakpointActive,
112
+ keepChildrenMounted,
113
+ disableDismissable,
114
+ hoverable,
115
+ closeReasonRef,
116
+ children: /* @__PURE__ */ jsx(PopoverTriggerContext.Provider, {
117
+ scope,
118
+ triggerRef,
119
+ hasCustomAnchor,
120
+ anchorTo,
121
+ branches,
122
+ onOpenToggle,
123
+ setActiveTrigger,
124
+ registerTrigger,
125
+ unregisterTrigger,
126
+ children
127
+ })
128
+ });
151
129
  });
152
- var voidFn = function () {};
153
- var PopoverAnchor = /* @__PURE__ */React.memo(/* @__PURE__ */React.forwardRef(function PopoverAnchor2(props, forwardedRef) {
154
- var {
155
- scope,
156
- ...rest
157
- } = props;
158
- var {
159
- onCustomAnchorAdd,
160
- onCustomAnchorRemove
161
- } = usePopoverContext(scope) || {};
162
- React.useEffect(function () {
163
- onCustomAnchorAdd();
164
- return function () {
165
- return onCustomAnchorRemove();
166
- };
167
- }, [onCustomAnchorAdd, onCustomAnchorRemove]);
168
- return /* @__PURE__ */jsx(PopperAnchor, {
169
- scope,
170
- ...rest,
171
- ref: forwardedRef
172
- });
130
+ var voidFn = function() {};
131
+ var PopoverAnchor = /* @__PURE__ */ React.memo(createRefComponent(function PopoverAnchor2(props, forwardedRef) {
132
+ var { scope, ...rest } = props;
133
+ var { onCustomAnchorAdd, onCustomAnchorRemove } = usePopoverContext(scope) || {};
134
+ React.useEffect(function() {
135
+ onCustomAnchorAdd();
136
+ return function() {
137
+ return onCustomAnchorRemove();
138
+ };
139
+ }, [onCustomAnchorAdd, onCustomAnchorRemove]);
140
+ return /* @__PURE__ */ jsx(PopperAnchor, {
141
+ scope,
142
+ ...rest,
143
+ ref: forwardedRef
144
+ });
173
145
  }));
174
- var PopoverTrigger = /* @__PURE__ */React.memo(/* @__PURE__ */React.forwardRef(function PopoverTrigger2(props, forwardedRef) {
175
- var {
176
- scope,
177
- disablePressTrigger,
178
- ...rest
179
- } = props;
180
- var triggerContext = usePopoverTriggerContext(scope);
181
- var triggerId = React.useId();
182
- var [open, setOpen] = React.useState(false);
183
- var anchorTo = triggerContext.anchorTo;
184
- var triggerElRef = React.useRef(null);
185
- var composedTriggerRef = useComposedRefs(forwardedRef, triggerElRef);
186
- var {
187
- registerTrigger,
188
- unregisterTrigger
189
- } = triggerContext;
190
- React.useEffect(function () {
191
- registerTrigger(triggerId, setOpen);
192
- return function () {
193
- unregisterTrigger(triggerId);
194
- };
195
- }, [registerTrigger, unregisterTrigger, triggerId]);
196
- if (!rest.children) return null;
197
- var activateSelf = function () {
198
- triggerContext.setActiveTrigger(triggerId);
199
- var el = triggerElRef.current;
200
- if (el) triggerContext.triggerRef.current = el;
201
- };
202
- var trigger = /* @__PURE__ */jsx(View, {
203
- "aria-expanded": open,
204
- "data-state": getState(open),
205
- ...rest,
206
- ref: composedTriggerRef,
207
- onPress: composeEventHandlers(rest.onPress, function () {
208
- if (disablePressTrigger) return;
209
- triggerContext.setActiveTrigger(open ? null : triggerId);
210
- triggerContext.onOpenToggle();
211
- }),
212
- onMouseEnter: composeEventHandlers(rest.onMouseEnter, activateSelf),
213
- onPressIn: composeEventHandlers(rest.onPressIn, activateSelf),
214
- onFocus: composeEventHandlers(rest.onFocus, activateSelf)
215
- });
216
- var virtualRef = React.useMemo(function () {
217
- if (!anchorTo) return null;
218
- return {
219
- current: {
220
- getBoundingClientRect: function () {
221
- return isWeb ? DOMRect.fromRect(anchorTo) : anchorTo;
222
- },
223
- ...(!isWeb && {
224
- measure: function (c) {
225
- return c(anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.x, anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.y, anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.width, anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.height);
226
- },
227
- measureInWindow: function (c) {
228
- return c(anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.x, anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.y, anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.width, anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.height);
229
- }
230
- })
231
- }
232
- };
233
- }, [triggerContext.anchorTo, anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.x, anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.y, anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.height, anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.width]);
234
- var wrappedTrigger = isWeb ? /* @__PURE__ */jsx(DismissableBranch, {
235
- branches: triggerContext.branches,
236
- children: trigger
237
- }) : trigger;
238
- return triggerContext.hasCustomAnchor ? wrappedTrigger : /* @__PURE__ */jsx(PopperAnchor, {
239
- ...(virtualRef && {
240
- virtualRef
241
- }),
242
- scope,
243
- asChild: true,
244
- children: wrappedTrigger
245
- });
146
+ var PopoverTrigger = /* @__PURE__ */ React.memo(createRefComponent(function PopoverTrigger2(props, forwardedRef) {
147
+ var { scope, disablePressTrigger, ...rest } = props;
148
+ var triggerContext = usePopoverTriggerContext(scope);
149
+ var triggerId = React.useId();
150
+ var [open, setOpen] = React.useState(false);
151
+ var anchorTo = triggerContext.anchorTo;
152
+ var triggerElRef = React.useRef(null);
153
+ var composedTriggerRef = useComposedRefs(forwardedRef, triggerElRef);
154
+ var { registerTrigger, unregisterTrigger } = triggerContext;
155
+ React.useEffect(function() {
156
+ registerTrigger(triggerId, setOpen);
157
+ return function() {
158
+ unregisterTrigger(triggerId);
159
+ };
160
+ }, [
161
+ registerTrigger,
162
+ unregisterTrigger,
163
+ triggerId
164
+ ]);
165
+ if (!rest.children) return null;
166
+ var activateSelf = function() {
167
+ triggerContext.setActiveTrigger(triggerId);
168
+ var el = triggerElRef.current;
169
+ if (el) triggerContext.triggerRef.current = el;
170
+ };
171
+ var trigger = /* @__PURE__ */ jsx(View, {
172
+ "aria-expanded": open,
173
+ "data-state": getState(open),
174
+ ...rest,
175
+ ref: composedTriggerRef,
176
+ onPress: composeEventHandlers(rest.onPress, function() {
177
+ if (disablePressTrigger) return;
178
+ triggerContext.setActiveTrigger(open ? null : triggerId);
179
+ triggerContext.onOpenToggle();
180
+ }),
181
+ onMouseEnter: composeEventHandlers(rest.onMouseEnter, activateSelf),
182
+ onPressIn: composeEventHandlers(rest.onPressIn, activateSelf),
183
+ onFocus: composeEventHandlers(rest.onFocus, activateSelf)
184
+ });
185
+ var virtualRef = React.useMemo(function() {
186
+ if (!anchorTo) return null;
187
+ return { current: {
188
+ getBoundingClientRect: function() {
189
+ return isWeb ? DOMRect.fromRect(anchorTo) : anchorTo;
190
+ },
191
+ ...!isWeb && {
192
+ measure: function(c) {
193
+ return c(anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.x, anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.y, anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.width, anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.height);
194
+ },
195
+ measureInWindow: function(c) {
196
+ return c(anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.x, anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.y, anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.width, anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.height);
197
+ }
198
+ }
199
+ } };
200
+ }, [
201
+ triggerContext.anchorTo,
202
+ anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.x,
203
+ anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.y,
204
+ anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.height,
205
+ anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.width
206
+ ]);
207
+ var wrappedTrigger = isWeb ? /* @__PURE__ */ jsx(DismissableBranch, {
208
+ branches: triggerContext.branches,
209
+ children: trigger
210
+ }) : trigger;
211
+ return triggerContext.hasCustomAnchor ? wrappedTrigger : /* @__PURE__ */ jsx(PopperAnchor, {
212
+ ...virtualRef && { virtualRef },
213
+ scope,
214
+ asChild: true,
215
+ children: wrappedTrigger
216
+ });
246
217
  }));
247
- var PopoverContent = PopperContentFrame.styleable(function PopoverContent2(props, forwardedRef) {
248
- var {
249
- trapFocus,
250
- enableRemoveScroll = false,
251
- zIndex: zIndexProp,
252
- scope,
253
- ...contentImplProps
254
- } = props;
255
- var context = usePopoverContext(scope);
256
- var zIndexFromContext = React.useContext(PopoverZIndexContext);
257
- var zIndex = zIndexProp !== null && zIndexProp !== void 0 ? zIndexProp : zIndexFromContext;
258
- var open = usePopoverOpen(scope);
259
- var composedRefs = useComposedRefs(forwardedRef, React.useRef(null));
260
- var isRightClickOutsideRef = React.useRef(false);
261
- var [isFullyHidden, setIsFullyHidden] = React.useState(!open);
262
- useIsomorphicLayoutEffect(function () {
263
- if (open && isFullyHidden) setIsFullyHidden(false);
264
- }, [open, isFullyHidden]);
265
- var isAdaptFullyHidden = React.useContext(PopoverAdaptHiddenContext);
266
- if (!context.keepChildrenMounted) {
267
- if (context.breakpointActive) {
268
- if (!open && isAdaptFullyHidden) return null;
269
- } else if (isFullyHidden && !open) return null;
270
- }
271
- var _contentImplProps_pointerEvents;
272
- return /* @__PURE__ */jsx(PopoverPortal, {
273
- passThrough: context.breakpointActive,
274
- context,
275
- open,
276
- zIndex,
277
- children: /* @__PURE__ */jsx(View, {
278
- passThrough: context.breakpointActive,
279
- pointerEvents: open ? (_contentImplProps_pointerEvents = contentImplProps.pointerEvents) !== null && _contentImplProps_pointerEvents !== void 0 ? _contentImplProps_pointerEvents : "auto" : "none",
280
- children: /* @__PURE__ */jsx(PopoverContentImpl, {
281
- ...contentImplProps,
282
- context,
283
- open,
284
- enableRemoveScroll,
285
- ref: composedRefs,
286
- setIsFullyHidden,
287
- scope,
288
- trapFocus: trapFocus !== null && trapFocus !== void 0 ? trapFocus : open,
289
- disableOutsidePointerEvents: true,
290
- onCloseAutoFocus: props.onCloseAutoFocus === false ? void 0 : composeEventHandlers(props.onCloseAutoFocus, function (event) {
291
- var _context_triggerRef_current;
292
- if (event.defaultPrevented) return;
293
- event.preventDefault();
294
- if (!isRightClickOutsideRef.current) (_context_triggerRef_current = context.triggerRef.current) === null || _context_triggerRef_current === void 0 || _context_triggerRef_current.focus();
295
- }),
296
- onPointerDownOutside: composeEventHandlers(props.onPointerDownOutside, function (event) {
297
- var originalEvent = event.detail.originalEvent;
298
- var ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
299
- isRightClickOutsideRef.current = originalEvent.button === 2 || ctrlLeftClick;
300
- }, {
301
- checkDefaultPrevented: false
302
- }),
303
- onFocusOutside: composeEventHandlers(props.onFocusOutside, function (event) {
304
- return event.preventDefault();
305
- }, {
306
- checkDefaultPrevented: false
307
- })
308
- })
309
- })
310
- });
311
- });
312
- var useParentContexts = function (scope) {
313
- var context = usePopoverContext(scope);
314
- var triggerContext = usePopoverTriggerContext(scope);
315
- return {
316
- popperContext: usePopperContext(scope),
317
- adaptContext: useAdaptContext(context.adaptScope),
318
- context,
319
- triggerContext
320
- };
218
+ var PopoverContent = createStyledHOC(PopperContentFrame, function PopoverContent2(props, forwardedRef) {
219
+ var { trapFocus, enableRemoveScroll = false, zIndex: zIndexProp, scope, forceMount, ...contentImplProps } = props;
220
+ var context = usePopoverContext(scope);
221
+ var adaptContext = useAdaptContext(context.adaptScope);
222
+ var zIndexFromContext = React.useContext(PopoverZIndexContext);
223
+ var zIndex = zIndexProp !== null && zIndexProp !== void 0 ? zIndexProp : zIndexFromContext;
224
+ var open = usePopoverOpen(scope);
225
+ var composedRefs = useComposedRefs(forwardedRef, React.useRef(null));
226
+ var isRightClickOutsideRef = React.useRef(false);
227
+ var [isFullyHidden, setIsFullyHidden] = React.useState(!open);
228
+ useIsomorphicLayoutEffect(function() {
229
+ if (open && isFullyHidden) setIsFullyHidden(false);
230
+ }, [open, isFullyHidden]);
231
+ if (!forceMount && !context.keepChildrenMounted) {
232
+ if (context.breakpointActive) {
233
+ if (!open && adaptContext.targetFullyHidden) return null;
234
+ } else if (isFullyHidden && !open) return null;
235
+ }
236
+ var _contentImplProps_pointerEvents;
237
+ return /* @__PURE__ */ jsx(PopoverPortal, {
238
+ passThrough: context.breakpointActive,
239
+ context,
240
+ open,
241
+ visuallyActive: open || !isFullyHidden,
242
+ zIndex,
243
+ children: /* @__PURE__ */ jsx(View, {
244
+ passThrough: context.breakpointActive,
245
+ pointerEvents: open ? (_contentImplProps_pointerEvents = contentImplProps.pointerEvents) !== null && _contentImplProps_pointerEvents !== void 0 ? _contentImplProps_pointerEvents : "auto" : "none",
246
+ children: /* @__PURE__ */ jsx(PopoverContentImpl, {
247
+ ...contentImplProps,
248
+ context,
249
+ open,
250
+ forceMount,
251
+ enableRemoveScroll,
252
+ ref: composedRefs,
253
+ setIsFullyHidden,
254
+ scope,
255
+ trapFocus: trapFocus !== null && trapFocus !== void 0 ? trapFocus : open,
256
+ disableOutsidePointerEvents: true,
257
+ onCloseAutoFocus: props.onCloseAutoFocus === false ? void 0 : composeEventHandlers(props.onCloseAutoFocus, function(event) {
258
+ var _context_triggerRef_current;
259
+ if (event.isCanceled) return;
260
+ event.cancel();
261
+ if (!isRightClickOutsideRef.current) (_context_triggerRef_current = context.triggerRef.current) === null || _context_triggerRef_current === void 0 || _context_triggerRef_current.focus();
262
+ }),
263
+ onPointerDownOutside: composeEventHandlers(props.onPointerDownOutside, function(event) {
264
+ var originalEvent = event.event;
265
+ if (!originalEvent) return;
266
+ var ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
267
+ isRightClickOutsideRef.current = originalEvent.button === 2 || ctrlLeftClick;
268
+ }, { checkDefaultPrevented: false }),
269
+ onFocusOutside: composeEventHandlers(props.onFocusOutside, function(event) {
270
+ if (trapFocus !== null && trapFocus !== void 0 ? trapFocus : open) event.cancel();
271
+ }, { checkDefaultPrevented: false })
272
+ })
273
+ })
274
+ });
275
+ }, { staticConfig: { inlineProps: /* @__PURE__ */ new Set([
276
+ ...PopperContentFrame.staticConfig.inlineProps || [],
277
+ "zIndex",
278
+ "opacity",
279
+ "y"
280
+ ]) } });
281
+ var useParentContexts = function(scope) {
282
+ var context = usePopoverContext(scope);
283
+ var triggerContext = usePopoverTriggerContext(scope);
284
+ return {
285
+ popperContext: usePopperContext(scope),
286
+ adaptContext: useAdaptContext(context.adaptScope),
287
+ context,
288
+ triggerContext
289
+ };
321
290
  };
322
291
  function RepropagateParentContexts(param) {
323
- var {
324
- adaptContext,
325
- children,
326
- context,
327
- triggerContext,
328
- popperContext
329
- } = param;
330
- return /* @__PURE__ */jsx(PopperProvider, {
331
- scope: context.popoverScope,
332
- ...popperContext,
333
- children: /* @__PURE__ */jsx(PopoverContext.Provider, {
334
- scope: context.popoverScope,
335
- ...context,
336
- children: /* @__PURE__ */jsx(PopoverTriggerContext.Provider, {
337
- scope: context.popoverScope,
338
- ...triggerContext,
339
- children: /* @__PURE__ */jsx(ProvideAdaptContext, {
340
- ...adaptContext,
341
- children
342
- })
343
- })
344
- })
345
- });
292
+ var { adaptContext, children, context, triggerContext, popperContext } = param;
293
+ return /* @__PURE__ */ jsx(PopperProvider, {
294
+ scope: context.popoverScope,
295
+ ...popperContext,
296
+ children: /* @__PURE__ */ jsx(PopoverContext.Provider, {
297
+ scope: context.popoverScope,
298
+ ...context,
299
+ children: /* @__PURE__ */ jsx(PopoverTriggerContext.Provider, {
300
+ scope: context.popoverScope,
301
+ ...triggerContext,
302
+ children: /* @__PURE__ */ jsx(ProvideAdaptContext, {
303
+ ...adaptContext,
304
+ children
305
+ })
306
+ })
307
+ })
308
+ });
346
309
  }
347
- var PortalAdaptSafe = function (param) {
348
- "use no memo";
349
-
350
- var {
351
- children,
352
- context
353
- } = param;
354
- if (needsRepropagation) {
355
- var parentContexts = useParentContexts(context.popoverScope);
356
- return /* @__PURE__ */jsx(AdaptPortalContents, {
357
- scope: context.adaptScope,
358
- children: /* @__PURE__ */jsx(RepropagateParentContexts, {
359
- ...parentContexts,
360
- children
361
- })
362
- });
363
- }
364
- return /* @__PURE__ */jsx(AdaptPortalContents, {
365
- scope: context.adaptScope,
366
- children
367
- });
310
+ var PortalAdaptSafe = function(param) {
311
+ "use no memo";
312
+ var { children, context } = param;
313
+ if (needsRepropagation) {
314
+ var parentContexts = useParentContexts(context.popoverScope);
315
+ return /* @__PURE__ */ jsx(AdaptPortalContents, {
316
+ scope: context.adaptScope,
317
+ children: /* @__PURE__ */ jsx(RepropagateParentContexts, {
318
+ ...parentContexts,
319
+ children
320
+ })
321
+ });
322
+ }
323
+ return /* @__PURE__ */ jsx(AdaptPortalContents, {
324
+ scope: context.adaptScope,
325
+ children
326
+ });
368
327
  };
369
328
  function PopoverPortal(param) {
370
- "use no memo";
371
-
372
- var {
373
- context,
374
- open,
375
- zIndex,
376
- passThrough,
377
- children,
378
- onPress
379
- } = param;
380
- var content = children;
381
- if (needsRepropagation) content = /* @__PURE__ */jsx(RepropagateParentContexts, {
382
- ...useParentContexts(context.popoverScope),
383
- children: content
384
- });
385
- return /* @__PURE__ */jsxs(Portal, {
386
- passThrough,
387
- stackZIndex: true,
388
- zIndex,
389
- children: [!!open && !context.breakpointActive && !context.hoverable && /* @__PURE__ */jsx(YStack, {
390
- fullscreen: true,
391
- onPress: composeEventHandlers(onPress, context.onOpenToggle)
392
- }), content]
393
- });
329
+ "use no memo";
330
+ var { context, open, visuallyActive, zIndex, passThrough, children, onPress } = param;
331
+ var content = children;
332
+ if (needsRepropagation) content = /* @__PURE__ */ jsx(RepropagateParentContexts, {
333
+ ...useParentContexts(context.popoverScope),
334
+ children: content
335
+ });
336
+ return /* @__PURE__ */ jsxs(Portal, {
337
+ passThrough,
338
+ stackZIndex: true,
339
+ zIndex,
340
+ hidden: !visuallyActive,
341
+ children: [!!open && !context.breakpointActive && !context.hoverable && /* @__PURE__ */ jsx(YStack, {
342
+ position: "absolute",
343
+ inset: 0,
344
+ onPress: composeEventHandlers(onPress, context.onOpenToggle)
345
+ }), content]
346
+ });
394
347
  }
395
- var PopoverContentImpl = /* @__PURE__ */React.forwardRef(function PopoverContentImpl2(props, forwardedRef) {
396
- var {
397
- trapFocus,
398
- scope,
399
- onOpenAutoFocus,
400
- onCloseAutoFocus,
401
- disableOutsidePointerEvents,
402
- disableFocusScope,
403
- onEscapeKeyDown,
404
- onPointerDownOutside,
405
- onFocusOutside,
406
- onInteractOutside,
407
- children,
408
- enableRemoveScroll,
409
- freezeContentsWhenHidden,
410
- setIsFullyHidden,
411
- lazyMount,
412
- forceUnmount,
413
- context,
414
- open,
415
- alwaysDisable,
416
- ...contentProps
417
- } = props;
418
- var {
419
- keepChildrenMounted,
420
- disableDismissable
421
- } = context;
422
- var handleExitComplete = React.useCallback(function () {
423
- setIsFullyHidden === null || setIsFullyHidden === void 0 || setIsFullyHidden(true);
424
- }, [setIsFullyHidden]);
425
- var contents = /* @__PURE__ */jsx(ResetPresence, {
426
- disable: context.breakpointActive,
427
- children
428
- });
429
- React.useCallback(function () {
430
- context.onOpenChange(false, "press");
431
- }, [context]);
432
- if (!context.breakpointActive) {}
433
- return /* @__PURE__ */jsx(Animate, {
434
- type: "presence",
435
- present: Boolean(open),
436
- keepChildrenMounted: Boolean(keepChildrenMounted),
437
- onExitComplete: handleExitComplete,
438
- lazyMount,
439
- passThrough: context.breakpointActive,
440
- children: /* @__PURE__ */jsx(PopperContent, {
441
- scope,
442
- "data-state": getState(open),
443
- id: context.contentId,
444
- ref: forwardedRef,
445
- passThrough: context.breakpointActive,
446
- ...(!contentProps.unstyled && {
447
- size: "$true",
448
- backgroundColor: "$background",
449
- alignItems: "center"
450
- }),
451
- ...contentProps,
452
- children: /* @__PURE__ */jsx(PortalAdaptSafe, {
453
- context,
454
- children: contents
455
- })
456
- }, context.contentId)
457
- });
348
+ var PopoverContentImpl = createRefComponent(function PopoverContentImpl2(props, forwardedRef) {
349
+ var { trapFocus, scope, onOpenAutoFocus, onCloseAutoFocus, disableOutsidePointerEvents, disableFocusScope, onEscapeKeyDown, onPointerDownOutside, onFocusOutside, onInteractOutside, children, enableRemoveScroll, freezeContentsWhenHidden, setIsFullyHidden, lazyMount, forceUnmount, forceMount, context, open, alwaysDisable, ...contentProps } = props;
350
+ var { disableDismissable } = context;
351
+ var keepChildrenMounted = context.keepChildrenMounted || forceMount;
352
+ var handleExitComplete = React.useCallback(function() {
353
+ setIsFullyHidden === null || setIsFullyHidden === void 0 || setIsFullyHidden(true);
354
+ }, [setIsFullyHidden]);
355
+ var contents = /* @__PURE__ */ jsx(ResetPresence, {
356
+ disable: context.breakpointActive,
357
+ children
358
+ });
359
+ React.useCallback(function(details) {
360
+ if (context.closeReasonRef) context.closeReasonRef.current = details.reason === "escape-key" ? "escape-key" : "dismiss";
361
+ context.onOpenChange(false, "press");
362
+ }, [context]);
363
+ if (!context.breakpointActive) {}
364
+ return /* @__PURE__ */ jsx(Animate, {
365
+ type: "presence",
366
+ present: Boolean(open),
367
+ keepChildrenMounted: Boolean(keepChildrenMounted),
368
+ onExitComplete: handleExitComplete,
369
+ lazyMount,
370
+ passThrough: context.breakpointActive,
371
+ children: /* @__PURE__ */ jsx(PopperContent, {
372
+ scope,
373
+ "data-state": getState(open),
374
+ id: context.contentId,
375
+ ref: forwardedRef,
376
+ passThrough: context.breakpointActive,
377
+ ...contentProps,
378
+ children: /* @__PURE__ */ jsx(PortalAdaptSafe, {
379
+ context,
380
+ children: contents
381
+ })
382
+ }, context.contentId)
383
+ });
458
384
  });
459
- var PopoverClose = /* @__PURE__ */React.forwardRef(function PopoverClose2(props, forwardedRef) {
460
- var {
461
- scope,
462
- ...rest
463
- } = props;
464
- var context = usePopoverContext(scope);
465
- return /* @__PURE__ */jsx(YStack, {
466
- ...rest,
467
- ref: forwardedRef,
468
- componentName: "PopoverClose",
469
- onPress: composeEventHandlers(props.onPress, function () {
470
- var _context_onOpenChange;
471
- return context === null || context === void 0 ? void 0 : (_context_onOpenChange = context.onOpenChange) === null || _context_onOpenChange === void 0 ? void 0 : _context_onOpenChange.call(context, false, "press");
472
- })
473
- });
385
+ var PopoverClose = createRefComponent(function PopoverClose2(props, forwardedRef) {
386
+ var { scope, className, ...rest } = props;
387
+ var context = usePopoverContext(scope);
388
+ return /* @__PURE__ */ jsx(YStack, {
389
+ ...rest,
390
+ ref: forwardedRef,
391
+ className: `is_PopoverClose ${className || ""}`.trim(),
392
+ onPress: composeEventHandlers(props.onPress, function() {
393
+ var _context_onOpenChange;
394
+ return context === null || context === void 0 ? void 0 : (_context_onOpenChange = context.onOpenChange) === null || _context_onOpenChange === void 0 ? void 0 : _context_onOpenChange.call(context, false, "press");
395
+ })
396
+ });
474
397
  });
475
- var PopoverArrow = PopperArrowFrame.styleable(function PopoverArrow2(props, forwardedRef) {
476
- var {
477
- scope,
478
- ...rest
479
- } = props;
480
- if (useAdaptIsActive(usePopoverContext(scope).adaptScope)) return null;
481
- return /* @__PURE__ */jsx(PopperArrow, {
482
- scope,
483
- componentName: "PopoverArrow",
484
- ...rest,
485
- ref: forwardedRef
486
- });
398
+ var PopoverArrow = createStyledHOC(PopperArrowFrame, function PopoverArrow2(props, forwardedRef) {
399
+ var { scope, className, ...rest } = props;
400
+ if (useAdaptIsActive(usePopoverContext(scope).adaptScope)) return null;
401
+ return /* @__PURE__ */ jsx(PopperArrow, {
402
+ scope,
403
+ className: `is_PopoverArrow ${className || ""}`.trim(),
404
+ ...rest,
405
+ ref: forwardedRef
406
+ });
487
407
  });
488
- var PopoverScrollView = /* @__PURE__ */React.forwardRef(function (param, ref) {
489
- var {
490
- scope,
491
- ...props
492
- } = param;
493
- var context = usePopoverContext(scope);
494
- return /* @__PURE__ */jsx(ScrollView, {
495
- ref,
496
- pointerEvents: context.breakpointActive ? "none" : void 0,
497
- scrollEnabled: !context.breakpointActive,
498
- passThrough: context.breakpointActive,
499
- ...props
500
- });
408
+ var PopoverScrollView = createRefComponent(function(param, ref) {
409
+ var { scope, ...props } = param;
410
+ var context = usePopoverContext(scope);
411
+ return /* @__PURE__ */ jsx(ScrollView, {
412
+ ref,
413
+ pointerEvents: context.breakpointActive ? "none" : void 0,
414
+ scrollEnabled: !context.breakpointActive,
415
+ passThrough: context.breakpointActive,
416
+ ...props
417
+ });
501
418
  });
502
419
  var DEFAULT_SCOPE = "";
503
- var Popover = withStaticProperties(/* @__PURE__ */React.forwardRef(function Popover2(param, ref) {
504
- var {
505
- scope = DEFAULT_SCOPE,
506
- ...props
507
- } = param;
508
- var id = React.useId();
509
- var adaptScope = `PopoverAdapt${scope}`;
510
- return /* @__PURE__ */jsx(AdaptParent, {
511
- scope: adaptScope,
512
- portal: true,
513
- children: /* @__PURE__ */jsx(PopoverInner, {
514
- adaptScope,
515
- ref,
516
- id,
517
- scope,
518
- ...props
519
- })
520
- });
420
+ var Popover = withStaticProperties(createRefComponent(function Popover2(param, ref) {
421
+ var { scope = DEFAULT_SCOPE, ...props } = param;
422
+ var id = React.useId();
423
+ var adaptScope = `PopoverAdapt${scope}`;
424
+ var { open: openProp, defaultOpen, onOpenChange } = props;
425
+ var viaRef = React.useRef(void 0);
426
+ var closeReasonRef = React.useRef(void 0);
427
+ var [open, setOpen] = useControllableState({
428
+ prop: openProp,
429
+ defaultProp: defaultOpen || false,
430
+ onChange: function(val) {
431
+ onOpenChange === null || onOpenChange === void 0 || onOpenChange(val, viaRef.current);
432
+ }
433
+ });
434
+ var handleOpenChange = useEvent(function(val, via) {
435
+ viaRef.current = via;
436
+ setOpen(val);
437
+ });
438
+ React.useEffect(function() {
439
+ if (!open) return;
440
+ openPopovers.add(setOpen);
441
+ return function() {
442
+ openPopovers.delete(setOpen);
443
+ };
444
+ }, [open, setOpen]);
445
+ return /* @__PURE__ */ jsx(AdaptParent, {
446
+ scope: adaptScope,
447
+ adaptChildren: props.children,
448
+ open,
449
+ onOpenChange: setOpen,
450
+ children: /* @__PURE__ */ jsx(PopoverInner, {
451
+ adaptScope,
452
+ ref,
453
+ id,
454
+ scope,
455
+ open,
456
+ setOpen,
457
+ handleOpenChange,
458
+ closeReasonRef,
459
+ ...props
460
+ })
461
+ });
521
462
  }), {
522
- Anchor: PopoverAnchor,
523
- Arrow: PopoverArrow,
524
- Trigger: PopoverTrigger,
525
- Content: PopoverContent,
526
- Close: PopoverClose,
527
- Adapt,
528
- ScrollView: PopoverScrollView,
529
- FocusScope: FocusScopeController
463
+ Anchor: PopoverAnchor,
464
+ Arrow: PopoverArrow,
465
+ Trigger: PopoverTrigger,
466
+ Content: PopoverContent,
467
+ Close: PopoverClose,
468
+ Adapt,
469
+ ScrollView: PopoverScrollView,
470
+ FocusScope: FocusScopeController
530
471
  });
531
- var PopoverInner = /* @__PURE__ */React.forwardRef(function PopoverInner2(props, forwardedRef) {
532
- var {
533
- children,
534
- open: openProp,
535
- defaultOpen,
536
- onOpenChange,
537
- scope = DEFAULT_SCOPE,
538
- keepChildrenMounted: keepChildrenMountedProp,
539
- hoverable,
540
- disableFocus,
541
- disableDismissable,
542
- zIndex,
543
- id,
544
- adaptScope,
545
- ...restProps
546
- } = props;
547
- var triggerRef = React.useRef(null);
548
- var [hasCustomAnchor, setHasCustomAnchor] = React.useState(false);
549
- var viaRef = React.useRef(void 0);
550
- var [keepChildrenMounted] = useControllableState({
551
- prop: keepChildrenMountedProp,
552
- defaultProp: false,
553
- transition: keepChildrenMountedProp === "lazy"
554
- });
555
- var [open, setOpen] = useControllableState({
556
- prop: openProp,
557
- defaultProp: defaultOpen || false,
558
- onChange: function (val) {
559
- onOpenChange === null || onOpenChange === void 0 || onOpenChange(val, viaRef.current);
560
- }
561
- });
562
- React.useEffect(function () {
563
- if (!open) return;
564
- openPopovers.add(setOpen);
565
- return function () {
566
- openPopovers.delete(setOpen);
567
- };
568
- }, [open, setOpen]);
569
- var handleOpenChange = useEvent(function (val, via) {
570
- viaRef.current = via;
571
- setOpen(val);
572
- });
573
- var isAdapted = useAdaptIsActive(adaptScope);
574
- var floatingContext = useFloatingContext({
575
- open,
576
- setOpen: handleOpenChange,
577
- disable: isAdapted,
578
- hoverable,
579
- disableFocus
580
- });
581
- var [anchorTo, setAnchorToRaw] = React.useState();
582
- var setAnchorTo = useCreateShallowSetState(setAnchorToRaw);
583
- React.useImperativeHandle(forwardedRef, function () {
584
- return {
585
- anchorTo: setAnchorTo,
586
- toggle: function () {
587
- return setOpen(function (prev) {
588
- return !prev;
589
- });
590
- },
591
- open: function () {
592
- return setOpen(true);
593
- },
594
- close: function () {
595
- return setOpen(false);
596
- },
597
- setOpen
598
- };
599
- });
600
- var contentId = React.useId();
601
- var onOpenToggle = useEvent(function () {
602
- if (open && isAdapted) return;
603
- setOpen(!open);
604
- });
605
- var onCustomAnchorAdd = React.useCallback(function () {
606
- return setHasCustomAnchor(true);
607
- }, []);
608
- var onCustomAnchorRemove = React.useCallback(function () {
609
- return setHasCustomAnchor(false);
610
- }, []);
611
- var contents = /* @__PURE__ */jsx(Popper, {
612
- open,
613
- passThrough: isAdapted,
614
- scope,
615
- stayInFrame: true,
616
- ...restProps,
617
- children: /* @__PURE__ */jsx(PopoverContextProvider, {
618
- scope,
619
- open,
620
- onOpenChange: handleOpenChange,
621
- onOpenToggle,
622
- triggerRef,
623
- id,
624
- contentId,
625
- hasCustomAnchor,
626
- onCustomAnchorAdd,
627
- onCustomAnchorRemove,
628
- anchorTo,
629
- adaptScope,
630
- breakpointActive: isAdapted,
631
- keepChildrenMounted,
632
- disableDismissable,
633
- hoverable,
634
- children: /* @__PURE__ */jsx(PopoverSheetController, {
635
- onOpenChange: setOpen,
636
- open,
637
- scope,
638
- children
639
- })
640
- })
641
- });
642
- var result = /* @__PURE__ */jsx(Fragment, {
643
- children: isWeb ? /* @__PURE__ */jsx(FloatingOverrideContext.Provider, {
644
- value: floatingContext,
645
- children: contents
646
- }) : contents
647
- });
648
- if (zIndex !== void 0) return /* @__PURE__ */jsx(PopoverZIndexContext.Provider, {
649
- value: zIndex,
650
- children: result
651
- });
652
- return result;
472
+ var PopoverInner = createRefComponent(function PopoverInner2(props, forwardedRef) {
473
+ var { children, open: _openProp, defaultOpen: _defaultOpen, onOpenChange: _onOpenChange, scope = DEFAULT_SCOPE, keepChildrenMounted: keepChildrenMountedProp, hoverable, disableFocus = !hoverable, disableDismissable, zIndex, id, adaptScope, open, setOpen, handleOpenChange, closeReasonRef, ...restProps } = props;
474
+ var triggerRef = React.useRef(null);
475
+ var [hasCustomAnchor, setHasCustomAnchor] = React.useState(false);
476
+ var [keepChildrenMounted] = useControllableState({
477
+ prop: keepChildrenMountedProp,
478
+ defaultProp: false,
479
+ transition: keepChildrenMountedProp === "lazy"
480
+ });
481
+ var isAdapted = useAdaptIsActive(adaptScope);
482
+ var floatingContext = useFloatingContext({
483
+ open,
484
+ setOpen: handleOpenChange,
485
+ closeReasonRef,
486
+ disable: isAdapted,
487
+ hoverable,
488
+ disableFocus
489
+ });
490
+ var [anchorTo, setAnchorToRaw] = React.useState();
491
+ var setAnchorTo = useCreateShallowSetState(setAnchorToRaw);
492
+ React.useImperativeHandle(forwardedRef, function() {
493
+ return {
494
+ anchorTo: setAnchorTo,
495
+ toggle: function() {
496
+ return setOpen(function(prev) {
497
+ return !prev;
498
+ });
499
+ },
500
+ open: function() {
501
+ return setOpen(true);
502
+ },
503
+ close: function() {
504
+ return setOpen(false);
505
+ },
506
+ setOpen
507
+ };
508
+ });
509
+ var contentId = React.useId();
510
+ var onOpenToggle = useEvent(function() {
511
+ if (open && isAdapted) return;
512
+ closeReasonRef.current = open ? "reference-press" : void 0;
513
+ setOpen(!open);
514
+ });
515
+ var onCustomAnchorAdd = React.useCallback(function() {
516
+ return setHasCustomAnchor(true);
517
+ }, []);
518
+ var onCustomAnchorRemove = React.useCallback(function() {
519
+ return setHasCustomAnchor(false);
520
+ }, []);
521
+ var contents = /* @__PURE__ */ jsx(Popper, {
522
+ open,
523
+ passThrough: isAdapted,
524
+ scope,
525
+ stayInFrame: true,
526
+ ...restProps,
527
+ children: /* @__PURE__ */ jsx(PopoverContextProvider, {
528
+ scope,
529
+ open,
530
+ onOpenChange: handleOpenChange,
531
+ onOpenToggle,
532
+ triggerRef,
533
+ id,
534
+ contentId,
535
+ hasCustomAnchor,
536
+ onCustomAnchorAdd,
537
+ onCustomAnchorRemove,
538
+ anchorTo,
539
+ adaptScope,
540
+ breakpointActive: isAdapted,
541
+ keepChildrenMounted,
542
+ disableDismissable,
543
+ hoverable,
544
+ closeReasonRef,
545
+ children
546
+ })
547
+ });
548
+ var result = /* @__PURE__ */ jsx(Fragment, { children: isWeb ? /* @__PURE__ */ jsx(FloatingOverrideContext.Provider, {
549
+ value: floatingContext,
550
+ children: contents
551
+ }) : contents });
552
+ if (zIndex !== void 0) return /* @__PURE__ */ jsx(PopoverZIndexContext.Provider, {
553
+ value: zIndex,
554
+ children: result
555
+ });
556
+ return result;
653
557
  });
654
558
  function getState(open) {
655
- return open ? "open" : "closed";
559
+ return open ? "open" : "closed";
656
560
  }
657
- var PopoverSheetController = function (param) {
658
- var {
659
- open,
660
- scope,
661
- ...props
662
- } = param;
663
- var context = usePopoverContext(scope);
664
- var showSheet = useShowPopoverSheet(context, open);
665
- var breakpointActive = context === null || context === void 0 ? void 0 : context.breakpointActive;
666
- var getShowSheet = useGet(showSheet);
667
- var [isAdaptFullyHidden, setIsAdaptFullyHidden] = React.useState(!open);
668
- if (open && isAdaptFullyHidden) setIsAdaptFullyHidden(false);
669
- return /* @__PURE__ */jsx(SheetController, {
670
- onOpenChange: function (val) {
671
- if (getShowSheet()) {
672
- var _props_onOpenChange;
673
- (_props_onOpenChange = props.onOpenChange) === null || _props_onOpenChange === void 0 || _props_onOpenChange.call(props, val);
674
- }
675
- },
676
- onAnimationComplete: React.useCallback(function (param2) {
677
- var {
678
- open: isOpen
679
- } = param2;
680
- if (!isOpen) setIsAdaptFullyHidden(true);
681
- }, []),
682
- open,
683
- hidden: !breakpointActive,
684
- children: /* @__PURE__ */jsx(PopoverAdaptHiddenContext.Provider, {
685
- value: isAdaptFullyHidden,
686
- children: props.children
687
- })
688
- });
689
- };
690
- var useShowPopoverSheet = function (context, open) {
691
- var isAdapted = useAdaptIsActive(context.adaptScope);
692
- return open === false ? false : isAdapted;
693
- };
561
+
694
562
  export { Popover, PopoverAnchor, PopoverArrow, PopoverClose, PopoverContent, PopoverContext, PopoverContextProvider, PopoverTrigger, PopoverTriggerContext, PopoverZIndexContext, closeLastOpenedPopover, closeOpenPopovers, hasOpenPopovers, usePopoverContext, usePopoverOpen, usePopoverTriggerContext, usePopoverTriggerSetup };
695
563
  //# sourceMappingURL=Popover.native.js.map