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