@tamagui/popover 2.7.7 → 3.0.0-beta.637.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 (48) hide show
  1. package/dist/cjs/Popover.cjs +509 -664
  2. package/dist/cjs/Popover.native.cjs +603 -0
  3. package/dist/cjs/Popover.native.js +536 -691
  4. package/dist/cjs/Popover.native.js.map +1 -1
  5. package/dist/cjs/index.cjs +10 -11
  6. package/dist/cjs/index.native.cjs +22 -0
  7. package/dist/cjs/index.native.js +10 -10
  8. package/dist/cjs/index.native.js.map +1 -1
  9. package/dist/cjs/useFloatingContext.cjs +202 -234
  10. package/dist/cjs/useFloatingContext.native.cjs +36 -0
  11. package/dist/cjs/useFloatingContext.native.js +20 -27
  12. package/dist/cjs/useFloatingContext.native.js.map +1 -1
  13. package/dist/esm/Popover.mjs +473 -617
  14. package/dist/esm/Popover.mjs.map +1 -1
  15. package/dist/esm/Popover.native.js +499 -644
  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 +186 -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 +473 -617
  25. package/dist/jsx/Popover.mjs.map +1 -1
  26. package/dist/jsx/Popover.native.cjs +603 -0
  27. package/dist/jsx/Popover.native.js +536 -691
  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 +22 -0
  32. package/dist/jsx/index.native.js +10 -10
  33. package/dist/jsx/index.native.js.map +1 -1
  34. package/dist/jsx/useFloatingContext.mjs +186 -208
  35. package/dist/jsx/useFloatingContext.mjs.map +1 -1
  36. package/dist/jsx/useFloatingContext.native.cjs +36 -0
  37. package/dist/jsx/useFloatingContext.native.js +20 -27
  38. package/dist/jsx/useFloatingContext.native.js.map +1 -1
  39. package/package.json +22 -22
  40. package/src/Popover.tsx +115 -147
  41. package/types/Popover.d.ts +33 -109
  42. package/types/Popover.d.ts.map +1 -1
  43. package/types/useFloatingContext.d.ts.map +1 -1
  44. package/dist/esm/index.js.map +0 -1
  45. package/dist/esm/index.mjs.map +0 -1
  46. package/dist/esm/index.native.js.map +0 -1
  47. package/dist/jsx/index.js.map +0 -1
  48. 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,539 @@ 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 } = 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
+ children: /* @__PURE__ */ jsx(PopoverTriggerContext.Provider, {
116
+ scope,
117
+ triggerRef,
118
+ hasCustomAnchor,
119
+ anchorTo,
120
+ branches,
121
+ onOpenToggle,
122
+ setActiveTrigger,
123
+ registerTrigger,
124
+ unregisterTrigger,
125
+ children
126
+ })
127
+ });
151
128
  });
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
- });
129
+ var voidFn = function() {};
130
+ var PopoverAnchor = /* @__PURE__ */ React.memo(createRefComponent(function PopoverAnchor2(props, forwardedRef) {
131
+ var { scope, ...rest } = props;
132
+ var { onCustomAnchorAdd, onCustomAnchorRemove } = usePopoverContext(scope) || {};
133
+ React.useEffect(function() {
134
+ onCustomAnchorAdd();
135
+ return function() {
136
+ return onCustomAnchorRemove();
137
+ };
138
+ }, [onCustomAnchorAdd, onCustomAnchorRemove]);
139
+ return /* @__PURE__ */ jsx(PopperAnchor, {
140
+ scope,
141
+ ...rest,
142
+ ref: forwardedRef
143
+ });
173
144
  }));
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
- });
145
+ var PopoverTrigger = /* @__PURE__ */ React.memo(createRefComponent(function PopoverTrigger2(props, forwardedRef) {
146
+ var { scope, disablePressTrigger, ...rest } = props;
147
+ var triggerContext = usePopoverTriggerContext(scope);
148
+ var triggerId = React.useId();
149
+ var [open, setOpen] = React.useState(false);
150
+ var anchorTo = triggerContext.anchorTo;
151
+ var triggerElRef = React.useRef(null);
152
+ var composedTriggerRef = useComposedRefs(forwardedRef, triggerElRef);
153
+ var { registerTrigger, unregisterTrigger } = triggerContext;
154
+ React.useEffect(function() {
155
+ registerTrigger(triggerId, setOpen);
156
+ return function() {
157
+ unregisterTrigger(triggerId);
158
+ };
159
+ }, [
160
+ registerTrigger,
161
+ unregisterTrigger,
162
+ triggerId
163
+ ]);
164
+ if (!rest.children) return null;
165
+ var activateSelf = function() {
166
+ triggerContext.setActiveTrigger(triggerId);
167
+ var el = triggerElRef.current;
168
+ if (el) triggerContext.triggerRef.current = el;
169
+ };
170
+ var trigger = /* @__PURE__ */ jsx(View, {
171
+ "aria-expanded": open,
172
+ "data-state": getState(open),
173
+ ...rest,
174
+ ref: composedTriggerRef,
175
+ onPress: composeEventHandlers(rest.onPress, function() {
176
+ if (disablePressTrigger) return;
177
+ triggerContext.setActiveTrigger(open ? null : triggerId);
178
+ triggerContext.onOpenToggle();
179
+ }),
180
+ onMouseEnter: composeEventHandlers(rest.onMouseEnter, activateSelf),
181
+ onPressIn: composeEventHandlers(rest.onPressIn, activateSelf),
182
+ onFocus: composeEventHandlers(rest.onFocus, activateSelf)
183
+ });
184
+ var virtualRef = React.useMemo(function() {
185
+ if (!anchorTo) return null;
186
+ return { current: {
187
+ getBoundingClientRect: function() {
188
+ return isWeb ? DOMRect.fromRect(anchorTo) : anchorTo;
189
+ },
190
+ ...!isWeb && {
191
+ measure: function(c) {
192
+ 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);
193
+ },
194
+ measureInWindow: function(c) {
195
+ 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);
196
+ }
197
+ }
198
+ } };
199
+ }, [
200
+ triggerContext.anchorTo,
201
+ anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.x,
202
+ anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.y,
203
+ anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.height,
204
+ anchorTo === null || anchorTo === void 0 ? void 0 : anchorTo.width
205
+ ]);
206
+ var wrappedTrigger = isWeb ? /* @__PURE__ */ jsx(DismissableBranch, {
207
+ branches: triggerContext.branches,
208
+ children: trigger
209
+ }) : trigger;
210
+ return triggerContext.hasCustomAnchor ? wrappedTrigger : /* @__PURE__ */ jsx(PopperAnchor, {
211
+ ...virtualRef && { virtualRef },
212
+ scope,
213
+ asChild: true,
214
+ children: wrappedTrigger
215
+ });
246
216
  }));
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
- });
217
+ var PopoverContent = createStyledHOC(PopperContentFrame, function PopoverContent2(props, forwardedRef) {
218
+ var { trapFocus, enableRemoveScroll = false, zIndex: zIndexProp, scope, forceMount, ...contentImplProps } = props;
219
+ var context = usePopoverContext(scope);
220
+ var adaptContext = useAdaptContext(context.adaptScope);
221
+ var zIndexFromContext = React.useContext(PopoverZIndexContext);
222
+ var zIndex = zIndexProp !== null && zIndexProp !== void 0 ? zIndexProp : zIndexFromContext;
223
+ var open = usePopoverOpen(scope);
224
+ var composedRefs = useComposedRefs(forwardedRef, React.useRef(null));
225
+ var isRightClickOutsideRef = React.useRef(false);
226
+ var [isFullyHidden, setIsFullyHidden] = React.useState(!open);
227
+ useIsomorphicLayoutEffect(function() {
228
+ if (open && isFullyHidden) setIsFullyHidden(false);
229
+ }, [open, isFullyHidden]);
230
+ if (!forceMount && !context.keepChildrenMounted) {
231
+ if (context.breakpointActive) {
232
+ if (!open && adaptContext.targetFullyHidden) return null;
233
+ } else if (isFullyHidden && !open) return null;
234
+ }
235
+ var _contentImplProps_pointerEvents;
236
+ return /* @__PURE__ */ jsx(PopoverPortal, {
237
+ passThrough: context.breakpointActive,
238
+ context,
239
+ open,
240
+ visuallyActive: open || !isFullyHidden,
241
+ zIndex,
242
+ children: /* @__PURE__ */ jsx(View, {
243
+ passThrough: context.breakpointActive,
244
+ pointerEvents: open ? (_contentImplProps_pointerEvents = contentImplProps.pointerEvents) !== null && _contentImplProps_pointerEvents !== void 0 ? _contentImplProps_pointerEvents : "auto" : "none",
245
+ children: /* @__PURE__ */ jsx(PopoverContentImpl, {
246
+ ...contentImplProps,
247
+ context,
248
+ open,
249
+ forceMount,
250
+ enableRemoveScroll,
251
+ ref: composedRefs,
252
+ setIsFullyHidden,
253
+ scope,
254
+ trapFocus: trapFocus !== null && trapFocus !== void 0 ? trapFocus : open,
255
+ disableOutsidePointerEvents: true,
256
+ onCloseAutoFocus: props.onCloseAutoFocus === false ? void 0 : composeEventHandlers(props.onCloseAutoFocus, function(event) {
257
+ var _context_triggerRef_current;
258
+ if (event.isCanceled) return;
259
+ event.cancel();
260
+ if (!isRightClickOutsideRef.current) (_context_triggerRef_current = context.triggerRef.current) === null || _context_triggerRef_current === void 0 || _context_triggerRef_current.focus();
261
+ }),
262
+ onPointerDownOutside: composeEventHandlers(props.onPointerDownOutside, function(event) {
263
+ var originalEvent = event.event;
264
+ if (!originalEvent) return;
265
+ var ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
266
+ isRightClickOutsideRef.current = originalEvent.button === 2 || ctrlLeftClick;
267
+ }, { checkDefaultPrevented: false }),
268
+ onFocusOutside: composeEventHandlers(props.onFocusOutside, function(event) {
269
+ if (trapFocus !== null && trapFocus !== void 0 ? trapFocus : open) event.cancel();
270
+ }, { checkDefaultPrevented: false })
271
+ })
272
+ })
273
+ });
311
274
  });
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
- };
275
+ var useParentContexts = function(scope) {
276
+ var context = usePopoverContext(scope);
277
+ var triggerContext = usePopoverTriggerContext(scope);
278
+ return {
279
+ popperContext: usePopperContext(scope),
280
+ adaptContext: useAdaptContext(context.adaptScope),
281
+ context,
282
+ triggerContext
283
+ };
321
284
  };
322
285
  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
- });
286
+ var { adaptContext, children, context, triggerContext, popperContext } = param;
287
+ return /* @__PURE__ */ jsx(PopperProvider, {
288
+ scope: context.popoverScope,
289
+ ...popperContext,
290
+ children: /* @__PURE__ */ jsx(PopoverContext.Provider, {
291
+ scope: context.popoverScope,
292
+ ...context,
293
+ children: /* @__PURE__ */ jsx(PopoverTriggerContext.Provider, {
294
+ scope: context.popoverScope,
295
+ ...triggerContext,
296
+ children: /* @__PURE__ */ jsx(ProvideAdaptContext, {
297
+ ...adaptContext,
298
+ children
299
+ })
300
+ })
301
+ })
302
+ });
346
303
  }
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
- });
304
+ var PortalAdaptSafe = function(param) {
305
+ "use no memo";
306
+ var { children, context } = param;
307
+ if (needsRepropagation) {
308
+ var parentContexts = useParentContexts(context.popoverScope);
309
+ return /* @__PURE__ */ jsx(AdaptPortalContents, {
310
+ scope: context.adaptScope,
311
+ children: /* @__PURE__ */ jsx(RepropagateParentContexts, {
312
+ ...parentContexts,
313
+ children
314
+ })
315
+ });
316
+ }
317
+ return /* @__PURE__ */ jsx(AdaptPortalContents, {
318
+ scope: context.adaptScope,
319
+ children
320
+ });
368
321
  };
369
322
  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
- });
323
+ "use no memo";
324
+ var { context, open, visuallyActive, zIndex, passThrough, children, onPress } = param;
325
+ var content = children;
326
+ if (needsRepropagation) content = /* @__PURE__ */ jsx(RepropagateParentContexts, {
327
+ ...useParentContexts(context.popoverScope),
328
+ children: content
329
+ });
330
+ return /* @__PURE__ */ jsxs(Portal, {
331
+ passThrough,
332
+ stackZIndex: true,
333
+ zIndex,
334
+ hidden: !visuallyActive,
335
+ children: [!!open && !context.breakpointActive && !context.hoverable && /* @__PURE__ */ jsx(YStack, {
336
+ position: "absolute",
337
+ inset: 0,
338
+ onPress: composeEventHandlers(onPress, context.onOpenToggle)
339
+ }), content]
340
+ });
394
341
  }
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
- });
342
+ var PopoverContentImpl = createRefComponent(function PopoverContentImpl2(props, forwardedRef) {
343
+ var { trapFocus, scope, onOpenAutoFocus, onCloseAutoFocus, disableOutsidePointerEvents, disableFocusScope, onEscapeKeyDown, onPointerDownOutside, onFocusOutside, onInteractOutside, children, enableRemoveScroll, freezeContentsWhenHidden, setIsFullyHidden, lazyMount, forceUnmount, forceMount, context, open, alwaysDisable, ...contentProps } = props;
344
+ var { disableDismissable } = context;
345
+ var keepChildrenMounted = context.keepChildrenMounted || forceMount;
346
+ var handleExitComplete = React.useCallback(function() {
347
+ setIsFullyHidden === null || setIsFullyHidden === void 0 || setIsFullyHidden(true);
348
+ }, [setIsFullyHidden]);
349
+ var contents = /* @__PURE__ */ jsx(ResetPresence, {
350
+ disable: context.breakpointActive,
351
+ children
352
+ });
353
+ React.useCallback(function() {
354
+ context.onOpenChange(false, "press");
355
+ }, [context]);
356
+ if (!context.breakpointActive) {}
357
+ return /* @__PURE__ */ jsx(Animate, {
358
+ type: "presence",
359
+ present: Boolean(open),
360
+ keepChildrenMounted: Boolean(keepChildrenMounted),
361
+ onExitComplete: handleExitComplete,
362
+ lazyMount,
363
+ passThrough: context.breakpointActive,
364
+ children: /* @__PURE__ */ jsx(PopperContent, {
365
+ scope,
366
+ "data-state": getState(open),
367
+ id: context.contentId,
368
+ ref: forwardedRef,
369
+ passThrough: context.breakpointActive,
370
+ ...contentProps,
371
+ children: /* @__PURE__ */ jsx(PortalAdaptSafe, {
372
+ context,
373
+ children: contents
374
+ })
375
+ }, context.contentId)
376
+ });
458
377
  });
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
- });
378
+ var PopoverClose = createRefComponent(function PopoverClose2(props, forwardedRef) {
379
+ var { scope, className, ...rest } = props;
380
+ var context = usePopoverContext(scope);
381
+ return /* @__PURE__ */ jsx(YStack, {
382
+ ...rest,
383
+ ref: forwardedRef,
384
+ className: `is_PopoverClose ${className || ""}`.trim(),
385
+ onPress: composeEventHandlers(props.onPress, function() {
386
+ var _context_onOpenChange;
387
+ 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");
388
+ })
389
+ });
474
390
  });
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
- });
391
+ var PopoverArrow = createStyledHOC(PopperArrowFrame, function PopoverArrow2(props, forwardedRef) {
392
+ var { scope, className, ...rest } = props;
393
+ if (useAdaptIsActive(usePopoverContext(scope).adaptScope)) return null;
394
+ return /* @__PURE__ */ jsx(PopperArrow, {
395
+ scope,
396
+ className: `is_PopoverArrow ${className || ""}`.trim(),
397
+ ...rest,
398
+ ref: forwardedRef
399
+ });
487
400
  });
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
- });
401
+ var PopoverScrollView = createRefComponent(function(param, ref) {
402
+ var { scope, ...props } = param;
403
+ var context = usePopoverContext(scope);
404
+ return /* @__PURE__ */ jsx(ScrollView, {
405
+ ref,
406
+ pointerEvents: context.breakpointActive ? "none" : void 0,
407
+ scrollEnabled: !context.breakpointActive,
408
+ passThrough: context.breakpointActive,
409
+ ...props
410
+ });
501
411
  });
502
412
  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
- });
413
+ var Popover = withStaticProperties(createRefComponent(function Popover2(param, ref) {
414
+ var { scope = DEFAULT_SCOPE, ...props } = param;
415
+ var id = React.useId();
416
+ var adaptScope = `PopoverAdapt${scope}`;
417
+ var { open: openProp, defaultOpen, onOpenChange } = props;
418
+ var viaRef = React.useRef(void 0);
419
+ var [open, setOpen] = useControllableState({
420
+ prop: openProp,
421
+ defaultProp: defaultOpen || false,
422
+ onChange: function(val) {
423
+ onOpenChange === null || onOpenChange === void 0 || onOpenChange(val, viaRef.current);
424
+ }
425
+ });
426
+ var handleOpenChange = useEvent(function(val, via) {
427
+ viaRef.current = via;
428
+ setOpen(val);
429
+ });
430
+ React.useEffect(function() {
431
+ if (!open) return;
432
+ openPopovers.add(setOpen);
433
+ return function() {
434
+ openPopovers.delete(setOpen);
435
+ };
436
+ }, [open, setOpen]);
437
+ return /* @__PURE__ */ jsx(AdaptParent, {
438
+ scope: adaptScope,
439
+ open,
440
+ onOpenChange: setOpen,
441
+ children: /* @__PURE__ */ jsx(PopoverInner, {
442
+ adaptScope,
443
+ ref,
444
+ id,
445
+ scope,
446
+ open,
447
+ setOpen,
448
+ handleOpenChange,
449
+ ...props
450
+ })
451
+ });
521
452
  }), {
522
- Anchor: PopoverAnchor,
523
- Arrow: PopoverArrow,
524
- Trigger: PopoverTrigger,
525
- Content: PopoverContent,
526
- Close: PopoverClose,
527
- Adapt,
528
- ScrollView: PopoverScrollView,
529
- FocusScope: FocusScopeController
453
+ Anchor: PopoverAnchor,
454
+ Arrow: PopoverArrow,
455
+ Trigger: PopoverTrigger,
456
+ Content: PopoverContent,
457
+ Close: PopoverClose,
458
+ Adapt,
459
+ ScrollView: PopoverScrollView,
460
+ FocusScope: FocusScopeController
530
461
  });
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;
462
+ var PopoverInner = createRefComponent(function PopoverInner2(props, forwardedRef) {
463
+ var { children, open: _openProp, defaultOpen: _defaultOpen, onOpenChange: _onOpenChange, scope = DEFAULT_SCOPE, keepChildrenMounted: keepChildrenMountedProp, hoverable, disableFocus, disableDismissable, zIndex, id, adaptScope, open, setOpen, handleOpenChange, ...restProps } = props;
464
+ var triggerRef = React.useRef(null);
465
+ var [hasCustomAnchor, setHasCustomAnchor] = React.useState(false);
466
+ var [keepChildrenMounted] = useControllableState({
467
+ prop: keepChildrenMountedProp,
468
+ defaultProp: false,
469
+ transition: keepChildrenMountedProp === "lazy"
470
+ });
471
+ var isAdapted = useAdaptIsActive(adaptScope);
472
+ var floatingContext = useFloatingContext({
473
+ open,
474
+ setOpen: handleOpenChange,
475
+ disable: isAdapted,
476
+ hoverable,
477
+ disableFocus
478
+ });
479
+ var [anchorTo, setAnchorToRaw] = React.useState();
480
+ var setAnchorTo = useCreateShallowSetState(setAnchorToRaw);
481
+ React.useImperativeHandle(forwardedRef, function() {
482
+ return {
483
+ anchorTo: setAnchorTo,
484
+ toggle: function() {
485
+ return setOpen(function(prev) {
486
+ return !prev;
487
+ });
488
+ },
489
+ open: function() {
490
+ return setOpen(true);
491
+ },
492
+ close: function() {
493
+ return setOpen(false);
494
+ },
495
+ setOpen
496
+ };
497
+ });
498
+ var contentId = React.useId();
499
+ var onOpenToggle = useEvent(function() {
500
+ if (open && isAdapted) return;
501
+ setOpen(!open);
502
+ });
503
+ var onCustomAnchorAdd = React.useCallback(function() {
504
+ return setHasCustomAnchor(true);
505
+ }, []);
506
+ var onCustomAnchorRemove = React.useCallback(function() {
507
+ return setHasCustomAnchor(false);
508
+ }, []);
509
+ var contents = /* @__PURE__ */ jsx(Popper, {
510
+ open,
511
+ passThrough: isAdapted,
512
+ scope,
513
+ stayInFrame: true,
514
+ ...restProps,
515
+ children: /* @__PURE__ */ jsx(PopoverContextProvider, {
516
+ scope,
517
+ open,
518
+ onOpenChange: handleOpenChange,
519
+ onOpenToggle,
520
+ triggerRef,
521
+ id,
522
+ contentId,
523
+ hasCustomAnchor,
524
+ onCustomAnchorAdd,
525
+ onCustomAnchorRemove,
526
+ anchorTo,
527
+ adaptScope,
528
+ breakpointActive: isAdapted,
529
+ keepChildrenMounted,
530
+ disableDismissable,
531
+ hoverable,
532
+ children
533
+ })
534
+ });
535
+ var result = /* @__PURE__ */ jsx(Fragment, { children: isWeb ? /* @__PURE__ */ jsx(FloatingOverrideContext.Provider, {
536
+ value: floatingContext,
537
+ children: contents
538
+ }) : contents });
539
+ if (zIndex !== void 0) return /* @__PURE__ */ jsx(PopoverZIndexContext.Provider, {
540
+ value: zIndex,
541
+ children: result
542
+ });
543
+ return result;
653
544
  });
654
545
  function getState(open) {
655
- return open ? "open" : "closed";
546
+ return open ? "open" : "closed";
656
547
  }
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
- };
548
+
694
549
  export { Popover, PopoverAnchor, PopoverArrow, PopoverClose, PopoverContent, PopoverContext, PopoverContextProvider, PopoverTrigger, PopoverTriggerContext, PopoverZIndexContext, closeLastOpenedPopover, closeOpenPopovers, hasOpenPopovers, usePopoverContext, usePopoverOpen, usePopoverTriggerContext, usePopoverTriggerSetup };
695
550
  //# sourceMappingURL=Popover.native.js.map