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