@tamagui/popover 1.130.8 → 1.131.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.
@@ -61,34 +61,35 @@ var import_polyfill_dev = require("@tamagui/polyfill-dev"),
61
61
  import_use_controllable_state = require("@tamagui/use-controllable-state"),
62
62
  import_z_index_stack = require("@tamagui/z-index-stack"),
63
63
  React = __toESM(require("react")),
64
- import_useFloatingContext = require("./useFloatingContext"),
64
+ import_useFloatingContext = require("./useFloatingContext.cjs"),
65
65
  import_jsx_runtime = require("react/jsx-runtime");
66
66
  const needsRepropagation = import_constants.isAndroid || import_constants.isIos && !import_portal.USE_NATIVE_PORTAL,
67
- POPOVER_SCOPE = "PopoverScope",
68
- PopoverContext = (0, import_core.createStyledContext)({}),
67
+ PopoverContext = (0, import_core.createStyledContext)(
68
+ // since we always provide this we can avoid setting here
69
+ {}, "Popover__"),
69
70
  usePopoverContext = PopoverContext.useStyledContext,
70
71
  PopoverAnchor = React.forwardRef(function (props, forwardedRef) {
71
72
  const {
72
- __scopePopover,
73
+ scope,
73
74
  ...rest
74
75
  } = props,
75
- context = usePopoverContext(__scopePopover || POPOVER_SCOPE),
76
+ context = usePopoverContext(scope),
76
77
  {
77
78
  onCustomAnchorAdd,
78
79
  onCustomAnchorRemove
79
80
  } = context || {};
80
81
  return React.useEffect(() => (onCustomAnchorAdd(), () => onCustomAnchorRemove()), [onCustomAnchorAdd, onCustomAnchorRemove]), /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_popper.PopperAnchor, {
81
- __scopePopper: __scopePopover || POPOVER_SCOPE,
82
+ scope,
82
83
  ...rest,
83
84
  ref: forwardedRef
84
85
  });
85
86
  }),
86
87
  PopoverTrigger = React.forwardRef(function (props, forwardedRef) {
87
88
  const {
88
- __scopePopover,
89
+ scope,
89
90
  ...rest
90
91
  } = props,
91
- context = usePopoverContext(__scopePopover || POPOVER_SCOPE),
92
+ context = usePopoverContext(scope),
92
93
  anchorTo = context.anchorTo,
93
94
  composedTriggerRef = (0, import_compose_refs.useComposedRefs)(forwardedRef, context.triggerRef);
94
95
  if (!props.children) return null;
@@ -112,20 +113,23 @@ const needsRepropagation = import_constants.isAndroid || import_constants.isIos
112
113
  ...(virtualRef && {
113
114
  virtualRef
114
115
  }),
115
- __scopePopper: __scopePopover || POPOVER_SCOPE,
116
+ scope,
116
117
  asChild: rest.asChild,
117
118
  children: trigger
118
119
  });
119
120
  }),
120
- PopoverContent = import_popper.PopperContentFrame.extractable(React.forwardRef(function (props, forwardedRef) {
121
+ PopoverContentFrame = (0, import_core.styled)(import_popper.PopperContentFrame, {
122
+ name: "Popover"
123
+ }),
124
+ PopoverContent = PopoverContentFrame.extractable(React.forwardRef(function (props, forwardedRef) {
121
125
  const {
122
126
  trapFocus,
123
127
  enableRemoveScroll = !1,
124
128
  zIndex,
125
- __scopePopover,
129
+ scope,
126
130
  ...contentImplProps
127
131
  } = props,
128
- context = usePopoverContext(__scopePopover || POPOVER_SCOPE),
132
+ context = usePopoverContext(scope),
129
133
  contentRef = React.useRef(null),
130
134
  composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, contentRef),
131
135
  isRightClickOutsideRef = React.useRef(!1),
@@ -136,17 +140,18 @@ const needsRepropagation = import_constants.isAndroid || import_constants.isIos
136
140
  if (content) return (0, import_aria_hidden.hideOthers)(content);
137
141
  }, [context.open]), !context.keepChildrenMounted && isFullyHidden ? null : /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopoverPortal, {
138
142
  passThrough: context.breakpointActive,
139
- __scopePopover: __scopePopover || POPOVER_SCOPE,
143
+ context,
140
144
  zIndex,
141
145
  children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Stack, {
142
146
  passThrough: context.breakpointActive,
143
147
  pointerEvents: context.open ? contentImplProps.pointerEvents ?? "auto" : "none",
144
148
  children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopoverContentImpl, {
145
149
  ...contentImplProps,
150
+ context,
146
151
  enableRemoveScroll,
147
152
  ref: composedRefs,
148
153
  setIsFullyHidden,
149
- __scopePopover: __scopePopover || POPOVER_SCOPE,
154
+ scope,
150
155
  trapFocus: trapFocus ?? context.open,
151
156
  disableOutsidePointerEvents: !0,
152
157
  onCloseAutoFocus: props.onCloseAutoFocus === !1 ? void 0 : (0, import_helpers.composeEventHandlers)(props.onCloseAutoFocus, event => {
@@ -168,9 +173,9 @@ const needsRepropagation = import_constants.isAndroid || import_constants.isIos
168
173
  });
169
174
  })),
170
175
  useParentContexts = scope => {
171
- const popperContext = (0, import_popper.usePopperContext)(scope || POPOVER_SCOPE),
172
- adaptContext = (0, import_adapt.useAdaptContext)(),
173
- context = usePopoverContext(scope || POPOVER_SCOPE);
176
+ const context = usePopoverContext(scope),
177
+ popperContext = (0, import_popper.usePopperContext)(scope),
178
+ adaptContext = (0, import_adapt.useAdaptContext)(context.adaptScope);
174
179
  return {
175
180
  popperContext,
176
181
  adaptContext,
@@ -181,11 +186,10 @@ function RepropagateParentContexts({
181
186
  adaptContext,
182
187
  children,
183
188
  context,
184
- popperContext,
185
- scope
189
+ popperContext
186
190
  }) {
187
- return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_popper.PopperContext.Provider, {
188
- scope,
191
+ return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_popper.PopperProvider, {
192
+ scope: context.popoverScope,
189
193
  ...popperContext,
190
194
  children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopoverContext.Provider, {
191
195
  ...context,
@@ -198,42 +202,44 @@ function RepropagateParentContexts({
198
202
  }
199
203
  const PortalAdaptSafe = ({
200
204
  children,
201
- __scopePopover
205
+ context
202
206
  }) => {
203
207
  if (needsRepropagation) {
204
- const scope = __scopePopover || POPOVER_SCOPE,
205
- parentContexts = useParentContexts(scope);
208
+ const parentContexts = useParentContexts(context.popoverScope);
206
209
  return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_adapt.AdaptPortalContents, {
210
+ scope: context.adaptScope,
207
211
  children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(RepropagateParentContexts, {
208
- scope,
209
212
  ...parentContexts,
210
213
  children
211
214
  })
212
215
  });
213
216
  }
214
217
  return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_adapt.AdaptPortalContents, {
218
+ scope: context.adaptScope,
215
219
  children
216
220
  });
217
221
  };
218
- function PopoverPortal(props) {
219
- const scope = props.__scopePopover || POPOVER_SCOPE,
220
- zIndex = props.zIndex,
221
- themeName = (0, import_core.useThemeName)();
222
- let content = props.children;
222
+ function PopoverPortal({
223
+ context,
224
+ zIndex,
225
+ passThrough,
226
+ children
227
+ }) {
228
+ const themeName = (0, import_core.useThemeName)();
229
+ let content = children;
223
230
  if (needsRepropagation) {
224
- const parentContexts = useParentContexts(scope);
231
+ const parentContexts = useParentContexts(context.popoverScope);
225
232
  content = /* @__PURE__ */(0, import_jsx_runtime.jsx)(RepropagateParentContexts, {
226
- scope,
227
233
  ...parentContexts,
228
234
  children: content
229
235
  });
230
236
  }
231
237
  return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_portal.Portal, {
232
- passThrough: props.passThrough,
238
+ passThrough,
233
239
  stackZIndex: !0,
234
240
  zIndex,
235
241
  children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Theme, {
236
- passThrough: props.passThrough,
242
+ passThrough,
237
243
  contain: !0,
238
244
  forceClassName: !0,
239
245
  name: themeName,
@@ -247,7 +253,7 @@ function PopoverPortal(props) {
247
253
  const PopoverContentImpl = React.forwardRef(function (props, forwardedRef) {
248
254
  const {
249
255
  trapFocus,
250
- __scopePopover,
256
+ scope,
251
257
  onOpenAutoFocus,
252
258
  onCloseAutoFocus,
253
259
  disableOutsidePointerEvents,
@@ -261,9 +267,9 @@ const PopoverContentImpl = React.forwardRef(function (props, forwardedRef) {
261
267
  freezeContentsWhenHidden,
262
268
  setIsFullyHidden,
263
269
  lazyMount,
270
+ context,
264
271
  ...contentProps
265
272
  } = props,
266
- context = usePopoverContext(__scopePopover || POPOVER_SCOPE),
267
273
  {
268
274
  open,
269
275
  keepChildrenMounted
@@ -296,13 +302,14 @@ const PopoverContentImpl = React.forwardRef(function (props, forwardedRef) {
296
302
  lazyMount,
297
303
  passThrough: context.breakpointActive,
298
304
  children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_popper.PopperContent, {
299
- __scopePopper: __scopePopover || POPOVER_SCOPE,
305
+ scope,
300
306
  "data-state": getState(open),
301
307
  id: context.contentId,
302
308
  ref: forwardedRef,
303
309
  passThrough: context.breakpointActive,
304
310
  ...contentProps,
305
311
  children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(PortalAdaptSafe, {
312
+ context,
306
313
  children: contents
307
314
  })
308
315
  }, context.contentId)
@@ -313,10 +320,10 @@ const PopoverContentImpl = React.forwardRef(function (props, forwardedRef) {
313
320
  },
314
321
  PopoverClose = React.forwardRef(function (props, forwardedRef) {
315
322
  const {
316
- __scopePopover,
323
+ scope,
317
324
  ...rest
318
325
  } = props,
319
- context = usePopoverContext(__scopePopover || POPOVER_SCOPE);
326
+ context = usePopoverContext(scope);
320
327
  return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_stacks.YStack, {
321
328
  ...rest,
322
329
  ref: forwardedRef,
@@ -324,20 +331,24 @@ const PopoverContentImpl = React.forwardRef(function (props, forwardedRef) {
324
331
  onPress: (0, import_helpers.composeEventHandlers)(props.onPress, () => context?.onOpenChange?.(!1, "press"))
325
332
  });
326
333
  }),
327
- PopoverArrow = import_popper.PopperArrow.styleable(function (props, forwardedRef) {
334
+ PopoverArrow = import_popper.PopperArrowFrame.styleable(function (props, forwardedRef) {
328
335
  const {
329
- __scopePopover,
330
- ...rest
331
- } = props;
332
- return (0, import_adapt.useAdaptIsActive)() ? null : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_popper.PopperArrow, {
333
- __scopePopper: __scopePopover || POPOVER_SCOPE,
336
+ scope,
337
+ ...rest
338
+ } = props,
339
+ context = usePopoverContext(scope);
340
+ return (0, import_adapt.useAdaptIsActive)(context.adaptScope) ? null : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_popper.PopperArrow, {
341
+ scope,
334
342
  componentName: "PopoverArrow",
335
343
  ...rest,
336
344
  ref: forwardedRef
337
345
  });
338
346
  }),
339
- PopoverScrollView = React.forwardRef((props, ref) => {
340
- const context = usePopoverContext(POPOVER_SCOPE);
347
+ PopoverScrollView = React.forwardRef(({
348
+ scope,
349
+ ...props
350
+ }, ref) => {
351
+ const context = usePopoverContext(scope);
341
352
  return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_scroll_view.ScrollView, {
342
353
  ref,
343
354
  pointerEvents: context.breakpointActive ? "none" : void 0,
@@ -346,14 +357,21 @@ const PopoverContentImpl = React.forwardRef(function (props, forwardedRef) {
346
357
  ...props
347
358
  });
348
359
  }),
349
- Popover = (0, import_helpers.withStaticProperties)(React.forwardRef(function (props, ref) {
350
- const id = React.useId();
360
+ DEFAULT_SCOPE = "",
361
+ Popover = (0, import_helpers.withStaticProperties)(React.forwardRef(function ({
362
+ scope = DEFAULT_SCOPE,
363
+ ...props
364
+ }, ref) {
365
+ const id = React.useId(),
366
+ adaptScope = `PopoverAdapt${scope}`;
351
367
  return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_adapt.AdaptParent, {
352
- scope: `${id}PopoverContents`,
368
+ scope: adaptScope,
353
369
  portal: !0,
354
370
  children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopoverInner, {
371
+ adaptScope,
355
372
  ref,
356
373
  id,
374
+ scope,
357
375
  ...props
358
376
  })
359
377
  });
@@ -374,11 +392,12 @@ const PopoverContentImpl = React.forwardRef(function (props, forwardedRef) {
374
392
  open: openProp,
375
393
  defaultOpen,
376
394
  onOpenChange,
377
- __scopePopover,
395
+ scope = DEFAULT_SCOPE,
378
396
  keepChildrenMounted: keepChildrenMountedProp,
379
397
  hoverable,
380
398
  disableFocus,
381
399
  id,
400
+ adaptScope,
382
401
  ...restProps
383
402
  } = props,
384
403
  triggerRef = React.useRef(null),
@@ -399,7 +418,7 @@ const PopoverContentImpl = React.forwardRef(function (props, forwardedRef) {
399
418
  handleOpenChange = (0, import_core.useEvent)((val, via) => {
400
419
  viaRef.current = via, setOpen(val);
401
420
  }),
402
- isAdapted = (0, import_adapt.useAdaptIsActive)(),
421
+ isAdapted = (0, import_adapt.useAdaptIsActive)(adaptScope),
403
422
  floatingContext = (0, import_useFloatingContext.useFloatingContext)({
404
423
  open,
405
424
  setOpen: handleOpenChange,
@@ -417,6 +436,8 @@ const PopoverContentImpl = React.forwardRef(function (props, forwardedRef) {
417
436
  setOpen
418
437
  }));
419
438
  const popoverContext = {
439
+ popoverScope: scope,
440
+ adaptScope,
420
441
  id,
421
442
  contentId: React.useId(),
422
443
  triggerRef,
@@ -433,17 +454,18 @@ const PopoverContentImpl = React.forwardRef(function (props, forwardedRef) {
433
454
  keepChildrenMounted
434
455
  },
435
456
  memoizedChildren = React.useMemo(() => /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopoverContext.Provider, {
436
- scope: __scopePopover || POPOVER_SCOPE,
457
+ scope,
437
458
  ...popoverContext,
438
459
  children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopoverSheetController, {
460
+ context: popoverContext,
439
461
  onOpenChange: setOpen,
440
462
  children
441
463
  })
442
- }), [__scopePopover, setOpen, children, ...Object.values(popoverContext)]),
464
+ }), [scope, setOpen, children, ...Object.values(popoverContext)]),
443
465
  contents = /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_popper.Popper, {
444
466
  open,
445
467
  passThrough: isAdapted,
446
- __scopePopper: __scopePopover || POPOVER_SCOPE,
468
+ scope,
447
469
  stayInFrame: !0,
448
470
  ...restProps,
449
471
  children: memoizedChildren
@@ -459,11 +481,10 @@ function getState(open) {
459
481
  return open ? "open" : "closed";
460
482
  }
461
483
  const PopoverSheetController = ({
462
- __scopePopover,
484
+ context,
463
485
  ...props
464
486
  }) => {
465
- const context = usePopoverContext(__scopePopover || POPOVER_SCOPE),
466
- showSheet = useShowPopoverSheet(context),
487
+ const showSheet = useShowPopoverSheet(context),
467
488
  breakpointActive = context.breakpointActive,
468
489
  getShowSheet = (0, import_core.useGet)(showSheet);
469
490
  return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_sheet.SheetController, {
@@ -476,6 +497,6 @@ const PopoverSheetController = ({
476
497
  });
477
498
  },
478
499
  useShowPopoverSheet = context => {
479
- const isAdapted = (0, import_adapt.useAdaptIsActive)();
500
+ const isAdapted = (0, import_adapt.useAdaptIsActive)(context.adaptScope);
480
501
  return context.open === !1 ? !1 : isAdapted;
481
502
  };