@tamagui/popover 2.0.0-rc.9 → 2.1.0

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