@tamagui/popper 2.0.0-rc.4 → 2.0.0-rc.40

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