@tamagui/popper 2.0.0-rc.8 → 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.
@@ -1,319 +1,439 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { flushSync } from "react-dom";
2
3
  import { useComposedRefs } from "@tamagui/compose-refs";
3
4
  import { isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
4
- import { LayoutMeasurementController, View as TamaguiView, createStyledContext, getVariableValue, styled, useProps } from "@tamagui/core";
5
- import { arrow, autoUpdate, flip, offset as offsetFn, platform, shift, useFloating } from "@tamagui/floating";
5
+ import { LayoutMeasurementController, View as TamaguiView, createStyledContext, getVariableValue, registerLayoutNode, styled } from "@tamagui/core";
6
+ import { FloatingOverrideContext } from "@tamagui/floating";
7
+ import { arrow, flip, getOverflowAncestors, offset as offsetFn, platform, shift, size as sizeMiddleware, useFloating } from "@tamagui/floating";
6
8
  import { getSpace } from "@tamagui/get-token";
7
9
  import { YStack } from "@tamagui/stacks";
8
10
  import { startTransition } from "@tamagui/start-transition";
9
11
  import * as React from "react";
10
12
  import { Keyboard, useWindowDimensions } from "react-native";
11
13
  function _instanceof(left, right) {
12
- return right != null && typeof Symbol < "u" && right[Symbol.hasInstance] ? !!right[Symbol.hasInstance](left) : left instanceof right;
14
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) return !!right[Symbol.hasInstance](left);else return left instanceof right;
15
+ }
16
+ function _type_of(obj) {
17
+ "@swc/helpers - typeof";
18
+
19
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
13
20
  }
14
21
  var PopperContextFast = createStyledContext(
15
- // since we always provide this we can avoid setting here
16
- {}, "Popper__"),
17
- PopperPositionContext = createStyledContext,
18
- {
19
- useStyledContext: usePopperContext,
20
- Provider: PopperProviderFast
21
- } = PopperContextFast,
22
- PopperContextSlow = createStyledContext(
23
- // since we always provide this we can avoid setting here
24
- {}, "PopperSlow__"),
25
- {
26
- useStyledContext: usePopperContextSlow,
27
- Provider: PopperProviderSlow
28
- } = PopperContextSlow,
29
- PopperProvider = function (param) {
30
- var {
31
- scope,
32
- children,
33
- ...context
34
- } = param,
35
- slowContext = getContextSlow(context);
36
- return /* @__PURE__ */_jsx(PopperProviderFast, {
22
+ // since we always provide this we can avoid setting here
23
+ {}, "Popper__");
24
+ var PopperPositionContext = createStyledContext;
25
+ var {
26
+ useStyledContext: usePopperContext,
27
+ Provider: PopperProviderFast
28
+ } = PopperContextFast;
29
+ var PopperContextSlow = createStyledContext(
30
+ // since we always provide this we can avoid setting here
31
+ {}, "PopperSlow__");
32
+ var {
33
+ useStyledContext: usePopperContextSlow,
34
+ Provider: PopperProviderSlow
35
+ } = PopperContextSlow;
36
+ var PopperProvider = function (param) {
37
+ var {
38
+ scope,
39
+ children,
40
+ ...context
41
+ } = param;
42
+ var fns = React.useRef(context);
43
+ fns.current = context;
44
+ var [slowContext] = React.useState(function () {
45
+ return {
46
+ refs: context.refs,
47
+ triggerElements: context.triggerElements,
48
+ update() {
49
+ for (var _len = arguments.length, a = new Array(_len), _key = 0; _key < _len; _key++) a[_key] = arguments[_key];
50
+ fns.current.update(...a);
51
+ },
52
+ getReferenceProps(p) {
53
+ var _fns_current_getReferenceProps, _fns_current;
54
+ return (_fns_current_getReferenceProps = (_fns_current = fns.current).getReferenceProps) === null || _fns_current_getReferenceProps === void 0 ? void 0 : _fns_current_getReferenceProps.call(_fns_current, p);
55
+ },
56
+ onHoverReference(e) {
57
+ var _fns_current_onHoverReference, _fns_current;
58
+ (_fns_current_onHoverReference = (_fns_current = fns.current).onHoverReference) === null || _fns_current_onHoverReference === void 0 || _fns_current_onHoverReference.call(_fns_current, e);
59
+ },
60
+ onLeaveReference() {
61
+ var _fns_current_onLeaveReference, _fns_current;
62
+ (_fns_current_onLeaveReference = (_fns_current = fns.current).onLeaveReference) === null || _fns_current_onLeaveReference === void 0 || _fns_current_onLeaveReference.call(_fns_current);
63
+ }
64
+ };
65
+ });
66
+ return /* @__PURE__ */_jsx(PopperProviderFast, {
67
+ scope,
68
+ ...context,
69
+ children: /* @__PURE__ */_jsx(PopperProviderSlow, {
37
70
  scope,
38
- ...context,
39
- children: /* @__PURE__ */_jsx(PopperProviderSlow, {
40
- scope,
41
- ...slowContext,
42
- children
43
- })
44
- });
45
- };
46
- function getContextSlow(context) {
47
- return {
48
- refs: context.refs,
49
- size: context.size,
50
- arrowRef: context.arrowRef,
51
- arrowStyle: context.arrowStyle,
52
- onArrowSize: context.onArrowSize,
53
- hasFloating: context.hasFloating,
54
- strategy: context.strategy,
55
- update: context.update,
56
- context: context.context,
57
- getFloatingProps: context.getFloatingProps,
58
- getReferenceProps: context.getReferenceProps,
59
- open: context.open
60
- };
61
- }
71
+ ...slowContext,
72
+ children
73
+ })
74
+ });
75
+ };
62
76
  var checkFloating = {
63
- name: "checkFloating",
64
- fn(data) {
65
- return {
66
- data: {
67
- hasFloating: !!data.rects.floating.width
68
- }
69
- };
70
- }
71
- },
72
- setupOptions = {};
77
+ name: "checkFloating",
78
+ fn(data) {
79
+ return {
80
+ data: {
81
+ hasFloating: !!data.rects.floating.width
82
+ }
83
+ };
84
+ }
85
+ };
86
+ var setupOptions = {};
73
87
  function setupPopper(options) {
74
88
  Object.assign(setupOptions, options);
75
89
  }
90
+ function tamaguiAutoUpdate(reference, floating, update) {
91
+ update();
92
+ var rafId = requestAnimationFrame(function () {
93
+ update();
94
+ rafId = 0;
95
+ });
96
+ var cleanups = [function () {
97
+ if (rafId) cancelAnimationFrame(rafId);
98
+ }];
99
+ if (_instanceof(reference, HTMLElement)) cleanups.push(registerLayoutNode(reference, update));
100
+ var ancestors = [...(_instanceof(reference, Element) ? getOverflowAncestors(reference) : []), ...getOverflowAncestors(floating)];
101
+ var uniqueAncestors = [...new Set(ancestors)];
102
+ var _iteratorNormalCompletion = true,
103
+ _didIteratorError = false,
104
+ _iteratorError = void 0;
105
+ try {
106
+ for (var _iterator = uniqueAncestors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) _step.value.addEventListener("scroll", update, {
107
+ passive: true
108
+ });
109
+ } catch (err) {
110
+ _didIteratorError = true;
111
+ _iteratorError = err;
112
+ } finally {
113
+ try {
114
+ if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
115
+ } finally {
116
+ if (_didIteratorError) throw _iteratorError;
117
+ }
118
+ }
119
+ window.addEventListener("resize", update);
120
+ cleanups.push(function () {
121
+ var _iteratorNormalCompletion2 = true,
122
+ _didIteratorError2 = false,
123
+ _iteratorError2 = void 0;
124
+ try {
125
+ for (var _iterator2 = uniqueAncestors[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) _step2.value.removeEventListener("scroll", update);
126
+ } catch (err) {
127
+ _didIteratorError2 = true;
128
+ _iteratorError2 = err;
129
+ } finally {
130
+ try {
131
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) _iterator2.return();
132
+ } finally {
133
+ if (_didIteratorError2) throw _iteratorError2;
134
+ }
135
+ }
136
+ window.removeEventListener("resize", update);
137
+ });
138
+ return function () {
139
+ return cleanups.forEach(function (fn) {
140
+ return fn();
141
+ });
142
+ };
143
+ }
76
144
  function Popper(props) {
77
145
  var {
78
- children,
79
- size,
80
- strategy = "absolute",
81
- placement = "bottom",
82
- stayInFrame,
83
- allowFlip,
84
- offset,
85
- disableRTL,
86
- resize,
87
- passThrough,
88
- open,
89
- scope
90
- } = props,
91
- [arrowEl, setArrow] = React.useState(null),
92
- [arrowSize, setArrowSize] = React.useState(0),
93
- offsetOptions = offset ?? arrowSize,
94
- floatingStyle = React.useRef({}),
95
- isOpen = passThrough ? !1 : open || !0,
96
- floating = useFloating({
97
- open: isOpen,
98
- strategy,
99
- placement,
100
- sameScrollView: !1,
101
- // this only takes effect on native
102
- whileElementsMounted: isOpen ? autoUpdate : void 0,
103
- platform: disableRTL ?? setupOptions.disableRTL ? {
104
- ...platform,
105
- isRTL(element) {
106
- return !1;
107
- }
108
- } : platform,
109
- middleware: [stayInFrame ? shift(typeof stayInFrame == "boolean" ? {} : stayInFrame) : null, allowFlip ? flip(typeof allowFlip == "boolean" ? {} : allowFlip) : null, arrowEl ? arrow({
110
- element: arrowEl
111
- }) : null, typeof offsetOptions < "u" ? offsetFn(offsetOptions) : null, checkFloating, null, null, null].filter(Boolean)
112
- }),
113
- {
114
- middlewareData
115
- } = floating,
116
- dimensions = useWindowDimensions(),
117
- [keyboardOpen, setKeyboardOpen] = React.useState(!1);
146
+ children,
147
+ size,
148
+ strategy = "absolute",
149
+ placement = "bottom",
150
+ stayInFrame,
151
+ allowFlip,
152
+ offset,
153
+ disableRTL,
154
+ resize,
155
+ passThrough,
156
+ open,
157
+ scope
158
+ } = props;
159
+ var [arrowEl, setArrow] = React.useState(null);
160
+ var [arrowSize, setArrowSize] = React.useState(0);
161
+ var offsetOptions = offset !== null && offset !== void 0 ? offset : arrowSize;
162
+ React.useRef({});
163
+ var isOpen = passThrough ? false : open !== null && open !== void 0 ? open : true;
164
+ var middlewareRef = React.useRef([]);
165
+ if (isOpen) middlewareRef.current = [typeof offsetOptions !== "undefined" ? offsetFn(offsetOptions) : null, allowFlip ? flip(typeof allowFlip === "boolean" ? {} : allowFlip) : null, stayInFrame ? shift({
166
+ padding: 10,
167
+ mainAxis: true,
168
+ crossAxis: false,
169
+ ...((typeof stayInFrame === "undefined" ? "undefined" : _type_of(stayInFrame)) === "object" ? stayInFrame : null)
170
+ }) : null, arrowEl ? arrow({
171
+ element: arrowEl
172
+ }) : null, checkFloating, null, null, null].filter(Boolean);
173
+ var floating = useFloating({
174
+ open: isOpen,
175
+ strategy,
176
+ placement,
177
+ sameScrollView: false,
178
+ whileElementsMounted: !isOpen ? void 0 : tamaguiAutoUpdate,
179
+ platform: (disableRTL !== null && disableRTL !== void 0 ? disableRTL : setupOptions.disableRTL) ? {
180
+ ...platform,
181
+ isRTL(element) {
182
+ return false;
183
+ }
184
+ } : platform,
185
+ middleware: middlewareRef.current
186
+ });
187
+ var {
188
+ middlewareData
189
+ } = floating;
190
+ var dimensions = useWindowDimensions();
191
+ var [keyboardOpen, setKeyboardOpen] = React.useState(false);
118
192
  React.useEffect(function () {
119
193
  var showSubscription = Keyboard.addListener("keyboardDidShow", function () {
120
- startTransition(function () {
121
- setKeyboardOpen(!0);
122
- });
123
- }),
124
- hideSubscription = Keyboard.addListener("keyboardDidHide", function () {
125
- startTransition(function () {
126
- setKeyboardOpen(!1);
127
- });
194
+ startTransition(function () {
195
+ setKeyboardOpen(true);
128
196
  });
197
+ });
198
+ var hideSubscription = Keyboard.addListener("keyboardDidHide", function () {
199
+ startTransition(function () {
200
+ setKeyboardOpen(false);
201
+ });
202
+ });
129
203
  return function () {
130
- showSubscription.remove(), hideSubscription.remove();
204
+ showSubscription.remove();
205
+ hideSubscription.remove();
131
206
  };
132
- }, []), useIsomorphicLayoutEffect(function () {
133
- passThrough || floating.update();
207
+ }, []);
208
+ useIsomorphicLayoutEffect(function () {
209
+ if (passThrough) return;
210
+ floating.update();
134
211
  }, [passThrough, dimensions, keyboardOpen]);
135
- var popperContext = React.useMemo(function () {
136
- var _middlewareData_checkFloating;
137
- return {
138
- size,
139
- arrowRef: setArrow,
140
- arrowStyle: middlewareData.arrow,
141
- onArrowSize: setArrowSize,
142
- hasFloating: (_middlewareData_checkFloating = middlewareData.checkFloating) === null || _middlewareData_checkFloating === void 0 ? void 0 : _middlewareData_checkFloating.hasFloating,
143
- transformOrigin: middlewareData.transformOrigin,
144
- open: !!open,
145
- ...floating
146
- };
147
- }, [open, size, floating.x, floating.y, floating.placement, JSON.stringify(middlewareData.arrow || null), JSON.stringify(middlewareData.transformOrigin || null), floating.isPositioned]);
148
- return /* @__PURE__ */_jsx(LayoutMeasurementController, {
149
- disable: !isOpen,
150
- children: /* @__PURE__ */_jsx(PopperProvider, {
151
- scope,
152
- ...popperContext,
212
+ return /* @__PURE__ */_jsx(PopperProvider, {
213
+ scope,
214
+ ...React.useMemo(function () {
215
+ var _middlewareData_checkFloating;
216
+ return {
217
+ size,
218
+ arrowRef: setArrow,
219
+ arrowStyle: middlewareData.arrow,
220
+ onArrowSize: setArrowSize,
221
+ hasFloating: (_middlewareData_checkFloating = middlewareData.checkFloating) === null || _middlewareData_checkFloating === void 0 ? void 0 : _middlewareData_checkFloating.hasFloating,
222
+ transformOrigin: middlewareData.transformOrigin,
223
+ open: !!open,
224
+ ...floating
225
+ };
226
+ }, [open, size, floating, JSON.stringify(middlewareData.arrow || null), JSON.stringify(middlewareData.transformOrigin || null)]),
227
+ children: /* @__PURE__ */_jsx(FloatingOverrideContext.Provider, {
228
+ value: null,
153
229
  children
154
230
  })
155
231
  });
156
232
  }
157
- var PopperAnchor = YStack.styleable(function (props, forwardedRef) {
158
- var {
159
- virtualRef,
160
- scope,
161
- ...rest
162
- } = props,
163
- context = usePopperContextSlow(scope),
164
- {
165
- getReferenceProps,
166
- refs,
167
- update
168
- } = context,
169
- ref = React.useRef(null);
170
- React.useEffect(function () {
171
- virtualRef && refs.setReference(virtualRef.current);
172
- }, [virtualRef]);
173
- var refProps = getReferenceProps?.({
174
- ...rest,
175
- ref
176
- }) || null,
177
- safeSetReference = React.useCallback(function (node) {
178
- startTransition(function () {
179
- refs.setReference(node);
180
- });
181
- }, [refs.setReference]),
182
- shouldHandleInHover = isWeb && scope,
183
- composedRefs = useComposedRefs(forwardedRef, ref,
184
- // web handles this onMouseEnter below so it can support multiple targets + hovering
185
- shouldHandleInHover ? void 0 : safeSetReference);
186
- return /* @__PURE__ */_jsx(TamaguiView, {
187
- ...rest,
188
- ...refProps,
189
- ref: composedRefs,
190
- ...(shouldHandleInHover && {
191
- // this helps us with handling scoped poppers with many different targets
192
- // basically we wait for mouseEnter to ever set a reference and remove it on leave
193
- // otherwise floating ui gets confused by having >1 reference
194
- onMouseEnter: function (e) {
195
- if (_instanceof(ref.current, HTMLElement)) {
196
- var _refProps_onPointerEnter;
197
- if (refs.setReference(ref.current), !refProps) return;
198
- (_refProps_onPointerEnter = refProps.onPointerEnter) === null || _refProps_onPointerEnter === void 0 || _refProps_onPointerEnter.call(refProps, e), update();
199
- }
200
- },
201
- onMouseLeave: function (e) {
202
- var _refProps_onMouseLeave;
203
- refProps == null || (_refProps_onMouseLeave = refProps.onMouseLeave) === null || _refProps_onMouseLeave === void 0 || _refProps_onMouseLeave.call(refProps, e);
204
- }
205
- })
233
+ var PopperAnchor = YStack.styleable(function PopperAnchor2(props, forwardedRef) {
234
+ var {
235
+ virtualRef,
236
+ scope,
237
+ ...rest
238
+ } = props;
239
+ var context = usePopperContextSlow(scope);
240
+ var {
241
+ getReferenceProps,
242
+ refs,
243
+ update
244
+ } = context;
245
+ var ref = React.useRef(null);
246
+ var triggerId = React.useId();
247
+ React.useEffect(function () {
248
+ if (!scope || !context.triggerElements || !ref.current) return;
249
+ if (!_instanceof(ref.current, Element)) return;
250
+ var el = ref.current;
251
+ context.triggerElements.add(triggerId, el);
252
+ return function () {
253
+ var _context_triggerElements;
254
+ (_context_triggerElements = context.triggerElements) === null || _context_triggerElements === void 0 || _context_triggerElements.delete(triggerId);
255
+ };
256
+ }, [scope, triggerId, context.triggerElements]);
257
+ React.useEffect(function () {
258
+ if (virtualRef) {
259
+ refs.setReference(virtualRef.current);
260
+ update();
261
+ }
262
+ }, [virtualRef]);
263
+ var refProps = (getReferenceProps === null || getReferenceProps === void 0 ? void 0 : getReferenceProps({
264
+ ...rest,
265
+ ref
266
+ })) || null;
267
+ var safeSetReference = React.useCallback(function (node) {
268
+ startTransition(function () {
269
+ refs.setReference(node);
206
270
  });
207
- }),
208
- PopperContentFrame = styled(YStack, {
209
- name: "PopperContent",
210
- variants: {
211
- unstyled: {
212
- false: {
213
- size: "$true",
214
- backgroundColor: "$background",
215
- alignItems: "center"
271
+ },
272
+ // it was refs.setRefernce but its stable and refs is undefined on server
273
+ [refs]);
274
+ var shouldHandleInHover = isWeb && scope;
275
+ var composedRefs = useComposedRefs(forwardedRef, ref,
276
+ // web handles this onMouseEnter below so it can support multiple targets + hovering
277
+ shouldHandleInHover ? void 0 : safeSetReference);
278
+ return /* @__PURE__ */_jsx(TamaguiView, {
279
+ ...rest,
280
+ ...refProps,
281
+ ref: composedRefs,
282
+ ...(shouldHandleInHover && {
283
+ onMouseEnter: function (e) {
284
+ var _e_currentTarget;
285
+ var el = (_e_currentTarget = e.currentTarget) !== null && _e_currentTarget !== void 0 ? _e_currentTarget : ref.current;
286
+ if (_instanceof(el, HTMLElement)) {
287
+ var _refProps_onPointerEnter, _context_onHoverReference;
288
+ flushSync(function () {
289
+ return refs.setReference(el);
290
+ });
291
+ update();
292
+ if (!refProps) return;
293
+ (_refProps_onPointerEnter = refProps.onPointerEnter) === null || _refProps_onPointerEnter === void 0 || _refProps_onPointerEnter.call(refProps, e);
294
+ (_context_onHoverReference = context.onHoverReference) === null || _context_onHoverReference === void 0 || _context_onHoverReference.call(context, e.nativeEvent);
216
295
  }
217
296
  },
218
- size: {
219
- "...size": function (val, param) {
220
- var {
221
- tokens
222
- } = param;
223
- return {
224
- padding: tokens.space[val],
225
- borderRadius: tokens.radius[val]
226
- };
227
- }
297
+ onMouseLeave: function (e) {
298
+ var _context_onLeaveReference, _refProps_onMouseLeave;
299
+ (_context_onLeaveReference = context.onLeaveReference) === null || _context_onLeaveReference === void 0 || _context_onLeaveReference.call(context);
300
+ refProps === null || refProps === void 0 || (_refProps_onMouseLeave = refProps.onMouseLeave) == null || _refProps_onMouseLeave.call(refProps, e);
228
301
  }
302
+ })
303
+ });
304
+ });
305
+ var PopperContentFrame = styled(YStack, {
306
+ name: "PopperContent",
307
+ variants: {
308
+ unstyled: {
309
+ true: {}
229
310
  },
230
- defaultVariants: {
231
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
311
+ size: {
312
+ "...size": function (val, param) {
313
+ var {
314
+ tokens
315
+ } = param;
316
+ return {
317
+ padding: tokens.space[val],
318
+ borderRadius: tokens.radius[val]
319
+ };
320
+ }
232
321
  }
233
- }),
234
- PopperContent = /* @__PURE__ */React.forwardRef(function (props, forwardedRef) {
235
- var {
236
- scope,
237
- animatePosition,
238
- enableAnimationForPositionChange,
239
- children,
240
- passThrough,
241
- ...rest
242
- } = props,
243
- animatePos = animatePosition ?? enableAnimationForPositionChange,
244
- context = usePopperContext(scope),
245
- {
246
- strategy,
247
- placement,
248
- refs,
249
- x,
250
- y,
251
- getFloatingProps,
252
- size,
253
- isPositioned,
254
- transformOrigin
255
- } = context,
256
- safeSetFloating = React.useCallback(function (node) {
257
- startTransition(function () {
258
- refs.setFloating(node);
259
- });
260
- }, [refs.setFloating]),
261
- contentRefs = useComposedRefs(safeSetFloating, forwardedRef),
262
- [needsMeasure, setNeedsMeasure] = React.useState(animatePos);
263
- useIsomorphicLayoutEffect(function () {
264
- needsMeasure && x && y && setNeedsMeasure(!1);
265
- }, [needsMeasure, animatePos, x, y]);
266
- var hide = x === 0 && y === 0,
267
- disableAnimationProp =
268
- // if they want to animate also when re-positioning allow it
269
- animatePos === "even-when-repositioning" ? needsMeasure : !isPositioned || needsMeasure,
270
- [disableAnimation, setDisableAnimation] = React.useState(disableAnimationProp);
271
- React.useEffect(function () {
272
- setDisableAnimation(disableAnimationProp);
273
- }, [disableAnimationProp]);
274
- var positionProps = hide ? {} :
275
- // omit x/y when hiding - prevents motion from animating from origin
276
- {
277
- x: x || 0,
278
- y: y || 0
279
- },
280
- frameProps = {
281
- ref: contentRefs,
282
- ...positionProps,
283
- top: 0,
284
- left: 0,
285
- position: strategy,
286
- opacity: 1,
287
- ...(animatePos && {
288
- transition: rest.transition,
289
- animateOnly: disableAnimation ? [] : rest.animateOnly,
290
- // apply animation but disable it on initial render to avoid animating from 0 to the first position
291
- animatePresence: !1
292
- }),
293
- ...(hide && {
294
- opacity: 0,
295
- animateOnly: []
296
- })
297
- },
298
- {
299
- style,
300
- ...floatingProps
301
- } = getFloatingProps ? getFloatingProps(frameProps) : frameProps,
302
- transformOriginStyle = isWeb && transformOrigin ? {
303
- transformOrigin: `${transformOrigin.x} ${transformOrigin.y}`
304
- } : void 0;
305
- return /* @__PURE__ */_jsx(TamaguiView, {
322
+ }
323
+ });
324
+ var PopperContent = /* @__PURE__ */React.forwardRef(function PopperContent2(props, forwardedRef) {
325
+ var isAnimatePosControlled = "animatePosition" in props || "enableAnimationForPositionChange" in props;
326
+ var {
327
+ scope,
328
+ animatePosition,
329
+ enableAnimationForPositionChange,
330
+ children,
331
+ passThrough,
332
+ unstyled,
333
+ ...rest
334
+ } = props;
335
+ var animatePos = animatePosition !== null && animatePosition !== void 0 ? animatePosition : enableAnimationForPositionChange;
336
+ var context = usePopperContext(scope);
337
+ var {
338
+ strategy,
339
+ placement,
340
+ refs,
341
+ x,
342
+ y,
343
+ getFloatingProps,
344
+ size,
345
+ isPositioned,
346
+ transformOrigin,
347
+ update
348
+ } = context;
349
+ var updateRef = React.useRef(update);
350
+ updateRef.current = update;
351
+ var lastNodeRef = React.useRef(null);
352
+ var safeSetFloating = React.useCallback(function (node) {
353
+ var isNewNode = node !== lastNodeRef.current;
354
+ if (node) {
355
+ lastNodeRef.current = node;
356
+ refs.setFloating(node);
357
+ if (!isNewNode) {
358
+ var _updateRef_current;
359
+ (_updateRef_current = updateRef.current) === null || _updateRef_current === void 0 || _updateRef_current.call(updateRef);
360
+ }
361
+ }
362
+ },
363
+ // null calls are blocked: cycling nulls are transient, genuine unmount
364
+ // is handled by the useEffect cleanup below
365
+ [refs.setFloating]);
366
+ React.useEffect(function () {
367
+ return function () {
368
+ var ourNode = lastNodeRef.current;
369
+ if (ourNode && refs.floating.current === ourNode) refs.setFloating(null);
370
+ lastNodeRef.current = null;
371
+ };
372
+ }, []);
373
+ var contentRefs = useComposedRefs(safeSetFloating, forwardedRef);
374
+ var [needsMeasure, setNeedsMeasure] = React.useState(animatePos);
375
+ useIsomorphicLayoutEffect(function () {
376
+ if (needsMeasure && x && y) setNeedsMeasure(false);
377
+ }, [needsMeasure, animatePos, x, y]);
378
+ var hasBeenPositioned = React.useRef(false);
379
+ var lastGoodPosition = React.useRef({
380
+ x: 0,
381
+ y: 0
382
+ });
383
+ if (x !== 0 || y !== 0) {
384
+ lastGoodPosition.current = {
385
+ x,
386
+ y
387
+ };
388
+ if (isPositioned) hasBeenPositioned.current = true;
389
+ }
390
+ var brieflyZero = hasBeenPositioned.current && x === 0 && y === 0;
391
+ var effectiveX = brieflyZero ? lastGoodPosition.current.x : x;
392
+ var effectiveY = brieflyZero ? lastGoodPosition.current.y : y;
393
+ var hide = !hasBeenPositioned.current && effectiveX === 0 && effectiveY === 0;
394
+ var disableAnimationProp = animatePos === "even-when-repositioning" ? needsMeasure : !hasBeenPositioned.current && !isPositioned || needsMeasure;
395
+ var [disableAnimation, setDisableAnimation] = React.useState(disableAnimationProp);
396
+ React.useEffect(function () {
397
+ setDisableAnimation(disableAnimationProp);
398
+ }, [disableAnimationProp]);
399
+ var frameProps = {
400
+ ref: contentRefs,
401
+ ...(hide ? {} :
402
+ // omit x/y when hiding - prevents motion driver from animating from origin
403
+ {
404
+ x: effectiveX || 0,
405
+ y: effectiveY || 0
406
+ }),
407
+ top: 0,
408
+ left: 0,
409
+ position: strategy,
410
+ opacity: hide ? 0 : 1,
411
+ ...(isAnimatePosControlled && {
412
+ transition: animatePos ? rest.transition : void 0,
413
+ animateOnly: animatePos && !disableAnimation ? rest.animateOnly : [],
414
+ animatePresence: false
415
+ })
416
+ };
417
+ var {
418
+ style,
419
+ ...floatingProps
420
+ } = getFloatingProps ? getFloatingProps(frameProps) : frameProps;
421
+ var transformOriginStyle = isWeb && transformOrigin ? {
422
+ transformOrigin: `${transformOrigin.x} ${transformOrigin.y}`
423
+ } : void 0;
424
+ return /* @__PURE__ */_jsx(LayoutMeasurementController, {
425
+ disable: !context.open,
426
+ children: /* @__PURE__ */_jsx(TamaguiView, {
306
427
  passThrough,
307
428
  ref: contentRefs,
308
- contain: "layout style",
429
+ direction: rest.direction,
309
430
  ...(passThrough ? null : floatingProps),
310
431
  ...(!passThrough && animatePos && {
311
- // marker for animation driver to know this is a popper element
312
- // that needs special handling for position animation interruption
313
432
  "data-popper-animate-position": "true"
314
433
  }),
315
434
  children: /* @__PURE__ */_jsx(PopperContentFrame, {
316
435
  passThrough,
436
+ unstyled,
317
437
  ...(!passThrough && {
318
438
  "data-placement": placement,
319
439
  "data-strategy": strategy,
@@ -324,124 +444,134 @@ var PopperAnchor = YStack.styleable(function (props, forwardedRef) {
324
444
  }),
325
445
  children
326
446
  }, "popper-content-frame")
327
- });
328
- }),
329
- PopperArrowFrame = styled(YStack, {
330
- name: "PopperArrow",
331
- variants: {
332
- unstyled: {
333
- false: {
334
- borderColor: "$borderColor",
335
- backgroundColor: "$background",
336
- position: "relative"
337
- }
447
+ })
448
+ });
449
+ });
450
+ var PopperArrowFrame = styled(YStack, {
451
+ name: "PopperArrow",
452
+ variants: {
453
+ unstyled: {
454
+ false: {
455
+ borderColor: "$borderColor",
456
+ backgroundColor: "$background",
457
+ position: "relative"
338
458
  }
339
- },
340
- defaultVariants: {
341
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
342
459
  }
343
- }),
344
- PopperArrowOuterFrame = styled(YStack, {
345
- name: "PopperArrowOuter",
346
- variants: {
347
- unstyled: {
348
- false: {
349
- position: "absolute",
350
- zIndex: 1e6,
351
- pointerEvents: "none",
352
- overflow: "hidden",
353
- alignItems: "center",
354
- justifyContent: "center"
355
- }
460
+ },
461
+ defaultVariants: {
462
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
463
+ }
464
+ });
465
+ var PopperArrowOuterFrame = styled(YStack, {
466
+ name: "PopperArrowOuter",
467
+ variants: {
468
+ unstyled: {
469
+ false: {
470
+ position: "absolute",
471
+ zIndex: 1e6,
472
+ pointerEvents: "none",
473
+ overflow: "hidden",
474
+ alignItems: "center",
475
+ justifyContent: "center"
356
476
  }
357
- },
358
- defaultVariants: {
359
- unstyled: process.env.TAMAGUI_HEADLESS === "1"
360
477
  }
361
- }),
362
- opposites = {
363
- top: "bottom",
364
- right: "left",
365
- bottom: "top",
366
- left: "right"
367
478
  },
368
- PopperArrow = /* @__PURE__ */React.forwardRef(function (propsIn, forwardedRef) {
369
- var _context_arrowStyle,
370
- _context_arrowStyle1,
371
- {
372
- scope,
373
- animatePosition,
374
- transition,
375
- ...rest
376
- } = propsIn,
377
- props = useProps(rest),
378
- {
379
- offset,
380
- size: sizeProp,
381
- borderWidth = 0,
382
- ...arrowProps
383
- } = props,
384
- context = usePopperContext(scope),
385
- sizeVal = typeof sizeProp == "number" ? sizeProp : getVariableValue(getSpace(sizeProp ?? context.size, {
386
- shift: -2,
387
- bounds: [2]
388
- })),
389
- size = Math.max(0, +sizeVal),
390
- {
391
- placement
392
- } = context,
393
- refs = useComposedRefs(context.arrowRef, forwardedRef),
394
- x = ((_context_arrowStyle = context.arrowStyle) === null || _context_arrowStyle === void 0 ? void 0 : _context_arrowStyle.x) || 0,
395
- y = ((_context_arrowStyle1 = context.arrowStyle) === null || _context_arrowStyle1 === void 0 ? void 0 : _context_arrowStyle1.y) || 0,
396
- primaryPlacement = placement ? placement.split("-")[0] : "top",
397
- arrowStyle = {
398
- x,
399
- y,
400
- width: size,
401
- height: size
402
- },
403
- innerArrowStyle = {},
404
- isVertical = primaryPlacement === "bottom" || primaryPlacement === "top";
405
- if (primaryPlacement) {
406
- arrowStyle[isVertical ? "width" : "height"] = size * 2;
407
- var oppSide = opposites[primaryPlacement];
408
- oppSide && (arrowStyle[oppSide] = -size, innerArrowStyle[oppSide] = size / 2), (oppSide === "top" || oppSide === "bottom") && (arrowStyle.left = 0), (oppSide === "left" || oppSide === "right") && (arrowStyle.top = 0), useIsomorphicLayoutEffect(function () {
409
- var _context_onArrowSize;
410
- (_context_onArrowSize = context.onArrowSize) === null || _context_onArrowSize === void 0 || _context_onArrowSize.call(context, size);
411
- }, [size, context.onArrowSize]);
479
+ defaultVariants: {
480
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
481
+ }
482
+ });
483
+ var opposites = {
484
+ top: "bottom",
485
+ right: "left",
486
+ bottom: "top",
487
+ left: "right"
488
+ };
489
+ var PopperArrow = /* @__PURE__ */React.forwardRef(function PopperArrow2(propsIn, forwardedRef) {
490
+ var _context_arrowStyle, _context_arrowStyle1;
491
+ var isAnimatePosControlled = "animatePosition" in propsIn;
492
+ var {
493
+ scope,
494
+ animatePosition,
495
+ transition,
496
+ ...rest
497
+ } = propsIn;
498
+ var {
499
+ offset,
500
+ size: sizeProp,
501
+ borderWidth = 0,
502
+ ...arrowProps
503
+ } = rest;
504
+ var context = usePopperContext(scope);
505
+ var sizeVal = typeof sizeProp === "number" ? sizeProp : getVariableValue(getSpace(sizeProp !== null && sizeProp !== void 0 ? sizeProp : context.size, {
506
+ shift: -2,
507
+ bounds: [2]
508
+ }));
509
+ var size = Math.max(0, +sizeVal);
510
+ var {
511
+ placement
512
+ } = context;
513
+ var refs = useComposedRefs(context.arrowRef, forwardedRef);
514
+ var x = ((_context_arrowStyle = context.arrowStyle) === null || _context_arrowStyle === void 0 ? void 0 : _context_arrowStyle.x) || 0;
515
+ var y = ((_context_arrowStyle1 = context.arrowStyle) === null || _context_arrowStyle1 === void 0 ? void 0 : _context_arrowStyle1.y) || 0;
516
+ var arrowPositioned = context.arrowStyle != null;
517
+ var primaryPlacement = placement ? placement.split("-")[0] : "top";
518
+ var arrowStyle = {
519
+ x,
520
+ y,
521
+ width: size,
522
+ height: size
523
+ };
524
+ var innerArrowStyle = {};
525
+ var isVertical = primaryPlacement === "bottom" || primaryPlacement === "top";
526
+ if (primaryPlacement) {
527
+ arrowStyle[isVertical ? "width" : "height"] = size * 2;
528
+ var oppSide = opposites[primaryPlacement];
529
+ if (oppSide) {
530
+ arrowStyle[oppSide] = -size;
531
+ innerArrowStyle[oppSide] = size / 2;
412
532
  }
413
- return /* @__PURE__ */_jsx(PopperArrowOuterFrame, {
414
- ref: refs,
415
- ...arrowStyle,
416
- ...(animatePosition && {
417
- transition,
418
- animateOnly: ["transform"],
419
- animatePresence: !1
533
+ if (oppSide === "top" || oppSide === "bottom") arrowStyle.left = 0;
534
+ if (oppSide === "left" || oppSide === "right") arrowStyle.top = 0;
535
+ useIsomorphicLayoutEffect(function () {
536
+ var _context_onArrowSize;
537
+ (_context_onArrowSize = context.onArrowSize) === null || _context_onArrowSize === void 0 || _context_onArrowSize.call(context, size);
538
+ }, [size, context.onArrowSize]);
539
+ }
540
+ return /* @__PURE__ */_jsx(PopperArrowOuterFrame, {
541
+ ref: refs,
542
+ ...arrowStyle,
543
+ ...(!arrowPositioned && {
544
+ opacity: 0
545
+ }),
546
+ ...(isAnimatePosControlled && {
547
+ transition: animatePosition ? transition : void 0,
548
+ animateOnly: animatePosition ? ["transform"] : [],
549
+ animatePresence: false
550
+ }),
551
+ children: /* @__PURE__ */_jsx(PopperArrowFrame, {
552
+ width: size,
553
+ height: size,
554
+ ...arrowProps,
555
+ ...innerArrowStyle,
556
+ rotate: "45deg",
557
+ ...(primaryPlacement === "bottom" && {
558
+ borderLeftWidth: borderWidth,
559
+ borderTopWidth: borderWidth
420
560
  }),
421
- children: /* @__PURE__ */_jsx(PopperArrowFrame, {
422
- width: size,
423
- height: size,
424
- ...arrowProps,
425
- ...innerArrowStyle,
426
- rotate: "45deg",
427
- ...(primaryPlacement === "bottom" && {
428
- borderLeftWidth: borderWidth,
429
- borderTopWidth: borderWidth
430
- }),
431
- ...(primaryPlacement === "top" && {
432
- borderBottomWidth: borderWidth,
433
- borderRightWidth: borderWidth
434
- }),
435
- ...(primaryPlacement === "right" && {
436
- borderLeftWidth: borderWidth,
437
- borderBottomWidth: borderWidth
438
- }),
439
- ...(primaryPlacement === "left" && {
440
- borderTopWidth: borderWidth,
441
- borderRightWidth: borderWidth
442
- })
561
+ ...(primaryPlacement === "top" && {
562
+ borderBottomWidth: borderWidth,
563
+ borderRightWidth: borderWidth
564
+ }),
565
+ ...(primaryPlacement === "right" && {
566
+ borderLeftWidth: borderWidth,
567
+ borderBottomWidth: borderWidth
568
+ }),
569
+ ...(primaryPlacement === "left" && {
570
+ borderTopWidth: borderWidth,
571
+ borderRightWidth: borderWidth
443
572
  })
444
- });
573
+ })
445
574
  });
575
+ });
446
576
  export { Popper, PopperAnchor, PopperArrow, PopperArrowFrame, PopperContent, PopperContentFrame, PopperContextFast, PopperContextSlow, PopperPositionContext, PopperProvider, PopperProviderFast, PopperProviderSlow, setupPopper, usePopperContext, usePopperContextSlow };
447
577
  //# sourceMappingURL=Popper.native.js.map