@tamagui/popper 1.116.0 → 1.116.2

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.
@@ -0,0 +1,265 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: !0 });
9
+ }, __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from == "object" || typeof from == "function")
11
+ for (let key of __getOwnPropNames(from))
12
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ return to;
14
+ };
15
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
+ // If the importer is in node compatibility mode or this is not an ESM
17
+ // file that has been converted to a CommonJS file using a Babel-
18
+ // compatible transform (i.e. "__esModule" has not been set), then set
19
+ // "default" to the CommonJS "module.exports" for node compatibility.
20
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
+ mod
22
+ )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
+ var Popper_exports = {};
24
+ __export(Popper_exports, {
25
+ Popper: () => Popper,
26
+ PopperAnchor: () => PopperAnchor,
27
+ PopperArrow: () => PopperArrow,
28
+ PopperContent: () => PopperContent,
29
+ PopperContentFrame: () => PopperContentFrame,
30
+ PopperContext: () => PopperContext,
31
+ PopperProvider: () => PopperProvider,
32
+ setupPopper: () => setupPopper,
33
+ usePopperContext: () => usePopperContext
34
+ });
35
+ module.exports = __toCommonJS(Popper_exports);
36
+ var import_compose_refs = require("@tamagui/compose-refs"), import_constants = require("@tamagui/constants"), import_core = require("@tamagui/core"), import_floating = require("@tamagui/floating"), import_get_token = require("@tamagui/get-token"), import_stacks = require("@tamagui/stacks"), import_start_transition = require("@tamagui/start-transition"), React = __toESM(require("react")), import_react_native = require("react-native-web"), import_jsx_runtime = require("react/jsx-runtime");
37
+ const PopperContext = (0, import_core.createStyledContext)({}), { useStyledContext: usePopperContext, Provider: PopperProvider } = PopperContext, checkFloating = void 0, setupOptions = {};
38
+ function setupPopper(options) {
39
+ Object.assign(setupOptions, options);
40
+ }
41
+ function Popper(props) {
42
+ const {
43
+ children,
44
+ size,
45
+ strategy = "absolute",
46
+ placement = "bottom",
47
+ stayInFrame,
48
+ allowFlip,
49
+ offset,
50
+ disableRTL,
51
+ __scopePopper
52
+ } = props, [arrowEl, setArrow] = React.useState(null), [arrowSize, setArrowSize] = React.useState(0), offsetOptions = offset ?? arrowSize, floating = (0, import_floating.useFloating)({
53
+ strategy,
54
+ placement,
55
+ sameScrollView: !1,
56
+ // this only takes effect on native
57
+ platform: disableRTL ?? setupOptions.disableRTL ? {
58
+ ...import_floating.platform,
59
+ isRTL(element) {
60
+ return !1;
61
+ }
62
+ } : import_floating.platform,
63
+ middleware: [
64
+ stayInFrame ? (0, import_floating.shift)(typeof stayInFrame == "boolean" ? {} : stayInFrame) : null,
65
+ allowFlip ? (0, import_floating.flip)(typeof allowFlip == "boolean" ? {} : allowFlip) : null,
66
+ arrowEl ? (0, import_floating.arrow)({ element: arrowEl }) : null,
67
+ typeof offsetOptions < "u" ? (0, import_floating.offset)(offsetOptions) : null,
68
+ checkFloating
69
+ ].filter(Boolean)
70
+ }), {
71
+ refs,
72
+ middlewareData,
73
+ // @ts-expect-error this comes from Tooltip for example
74
+ open
75
+ } = floating;
76
+ (0, import_constants.useIsomorphicLayoutEffect)(() => {
77
+ if (open && refs.reference.current && refs.floating.current)
78
+ return floating.update(), (0, import_floating.autoUpdate)(refs.reference.current, refs.floating.current, floating.update);
79
+ }, [open, floating.update, refs.floating, refs.reference]);
80
+ const popperContext = {
81
+ size,
82
+ arrowRef: setArrow,
83
+ arrowStyle: middlewareData.arrow,
84
+ onArrowSize: setArrowSize,
85
+ scope: __scopePopper,
86
+ hasFloating: middlewareData.checkFloating?.hasFloating,
87
+ ...floating
88
+ };
89
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperProvider, { ...popperContext, children });
90
+ }
91
+ const PopperAnchor = import_stacks.YStack.extractable(
92
+ React.forwardRef(
93
+ function(props, forwardedRef) {
94
+ const { virtualRef, __scopePopper, ...anchorProps } = props, { getReferenceProps, refs } = usePopperContext(__scopePopper), ref = React.useRef(null), composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref, refs.setReference);
95
+ React.useEffect(() => {
96
+ virtualRef && refs.setReference(virtualRef.current);
97
+ }, [virtualRef]);
98
+ const stackProps = {
99
+ ref: composedRefs,
100
+ ...anchorProps
101
+ };
102
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
103
+ import_core.View,
104
+ {
105
+ ...getReferenceProps ? getReferenceProps(stackProps) : stackProps
106
+ }
107
+ );
108
+ }
109
+ )
110
+ ), PopperContentFrame = (0, import_core.styled)(import_stacks.ThemeableStack, {
111
+ name: "PopperContent",
112
+ variants: {
113
+ unstyled: {
114
+ false: {
115
+ size: "$true",
116
+ backgroundColor: "$background",
117
+ alignItems: "center",
118
+ radiused: !0
119
+ }
120
+ },
121
+ size: {
122
+ "...size": (val, { tokens }) => ({
123
+ padding: tokens.space[val],
124
+ borderRadius: tokens.radius[val]
125
+ })
126
+ }
127
+ },
128
+ defaultVariants: {
129
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
130
+ }
131
+ }), PopperContent = React.forwardRef(function(props, forwardedRef) {
132
+ const { __scopePopper, enableAnimationForPositionChange, ...rest } = props, {
133
+ strategy,
134
+ placement,
135
+ refs,
136
+ x,
137
+ y,
138
+ getFloatingProps,
139
+ size,
140
+ update,
141
+ floatingStyles,
142
+ hasFloating
143
+ } = usePopperContext(__scopePopper), contentRefs = (0, import_compose_refs.useComposedRefs)(refs.setFloating, forwardedRef);
144
+ let finalHasFloatingValue = !1;
145
+ if (import_constants.isAndroid) {
146
+ const initialRender = React.useRef(!0), finalHasFloating = React.useRef(!1);
147
+ hasFloating === !1 && (initialRender.current = !1), initialRender.current || (finalHasFloating.current = hasFloating), finalHasFloatingValue = finalHasFloating.current;
148
+ }
149
+ const contents = React.useMemo(() => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
150
+ PopperContentFrame,
151
+ {
152
+ "data-placement": placement,
153
+ "data-strategy": strategy,
154
+ contain: "layout",
155
+ size,
156
+ ...rest
157
+ },
158
+ "popper-content-frame"
159
+ ), [placement, strategy, props]), [needsMeasure, setNeedsMeasure] = React.useState(!0);
160
+ React.useEffect(() => {
161
+ enableAnimationForPositionChange && (x || y) && setNeedsMeasure(!1);
162
+ }, [enableAnimationForPositionChange, x, y]);
163
+ let show = !0;
164
+ if (import_constants.isAndroid) {
165
+ const [show_, setShow] = React.useState(!1);
166
+ show = show_, React.useEffect(() => {
167
+ finalHasFloatingValue && setShow(!0);
168
+ }, [finalHasFloatingValue, x, y]);
169
+ }
170
+ const frameProps = {
171
+ ref: contentRefs,
172
+ x: x || 0,
173
+ y: y || 0,
174
+ top: 0,
175
+ left: 0,
176
+ position: strategy,
177
+ opacity: show ? 1 : 0,
178
+ ...enableAnimationForPositionChange && {
179
+ // apply animation but disable it on initial render to avoid animating from 0 to the first position
180
+ animation: rest.animation,
181
+ animateOnly: needsMeasure ? ["none"] : rest.animateOnly,
182
+ animatePresence: !1
183
+ }
184
+ };
185
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.Stack, { ...getFloatingProps ? getFloatingProps(frameProps) : frameProps, children: contents });
186
+ }), PopperArrowFrame = (0, import_core.styled)(import_stacks.YStack, {
187
+ name: "PopperArrow",
188
+ variants: {
189
+ unstyled: {
190
+ false: {
191
+ borderColor: "$borderColor",
192
+ backgroundColor: "$background",
193
+ position: "relative"
194
+ }
195
+ }
196
+ },
197
+ defaultVariants: {
198
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
199
+ }
200
+ }), PopperArrowOuterFrame = (0, import_core.styled)(import_stacks.YStack, {
201
+ name: "PopperArrowOuter",
202
+ variants: {
203
+ unstyled: {
204
+ false: {
205
+ position: "absolute",
206
+ zIndex: 1e6,
207
+ pointerEvents: "none",
208
+ overflow: "hidden",
209
+ alignItems: "center",
210
+ justifyContent: "center"
211
+ }
212
+ }
213
+ },
214
+ defaultVariants: {
215
+ unstyled: process.env.TAMAGUI_HEADLESS === "1"
216
+ }
217
+ }), opposites = {
218
+ top: "bottom",
219
+ right: "left",
220
+ bottom: "top",
221
+ left: "right"
222
+ }, PopperArrow = PopperArrowFrame.styleable(
223
+ function(propsIn, forwardedRef) {
224
+ const { __scopePopper, ...rest } = propsIn, props = (0, import_core.useProps)(rest), { offset, size: sizeProp, borderWidth = 0, ...arrowProps } = props, context = usePopperContext(__scopePopper), sizeVal = typeof sizeProp == "number" ? sizeProp : (0, import_core.getVariableValue)(
225
+ (0, import_get_token.getSpace)(sizeProp ?? context.size, {
226
+ shift: -2,
227
+ bounds: [2]
228
+ })
229
+ ), size = Math.max(0, +sizeVal), { placement } = context, refs = (0, import_compose_refs.useComposedRefs)(context.arrowRef, forwardedRef), x = context.arrowStyle?.x || 0, y = context.arrowStyle?.y || 0, primaryPlacement = placement ? placement.split("-")[0] : "top", arrowStyle = { x, y, width: size, height: size }, innerArrowStyle = {}, isVertical = primaryPlacement === "bottom" || primaryPlacement === "top";
230
+ if (primaryPlacement) {
231
+ arrowStyle[isVertical ? "width" : "height"] = size * 2;
232
+ const oppSide = opposites[primaryPlacement];
233
+ 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)(() => {
234
+ context.onArrowSize?.(size);
235
+ }, [size, context.onArrowSize]);
236
+ }
237
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperArrowOuterFrame, { ref: refs, ...arrowStyle, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
238
+ PopperArrowFrame,
239
+ {
240
+ width: size,
241
+ height: size,
242
+ ...arrowProps,
243
+ ...innerArrowStyle,
244
+ rotate: "45deg",
245
+ ...primaryPlacement === "bottom" && {
246
+ borderLeftWidth: borderWidth,
247
+ borderTopWidth: borderWidth
248
+ },
249
+ ...primaryPlacement === "top" && {
250
+ borderBottomWidth: borderWidth,
251
+ borderRightWidth: borderWidth
252
+ },
253
+ ...primaryPlacement === "right" && {
254
+ borderLeftWidth: borderWidth,
255
+ borderBottomWidth: borderWidth
256
+ },
257
+ ...primaryPlacement === "left" && {
258
+ borderTopWidth: borderWidth,
259
+ borderRightWidth: borderWidth
260
+ }
261
+ }
262
+ ) });
263
+ }
264
+ );
265
+ //# sourceMappingURL=Popper.js.map
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from == "object" || typeof from == "function")
7
+ for (let key of __getOwnPropNames(from))
8
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
+ return to;
10
+ }, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
11
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
12
+ var src_exports = {};
13
+ module.exports = __toCommonJS(src_exports);
14
+ __reExport(src_exports, require("./Popper"), module.exports);
15
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/popper",
3
- "version": "1.116.0",
3
+ "version": "1.116.2",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -34,20 +34,20 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@tamagui/compose-refs": "1.116.0",
38
- "@tamagui/constants": "1.116.0",
39
- "@tamagui/core": "1.116.0",
40
- "@tamagui/floating": "1.116.0",
41
- "@tamagui/get-token": "1.116.0",
42
- "@tamagui/stacks": "1.116.0",
43
- "@tamagui/start-transition": "1.116.0",
44
- "@tamagui/use-controllable-state": "1.116.0"
37
+ "@tamagui/compose-refs": "1.116.2",
38
+ "@tamagui/constants": "1.116.2",
39
+ "@tamagui/core": "1.116.2",
40
+ "@tamagui/floating": "1.116.2",
41
+ "@tamagui/get-token": "1.116.2",
42
+ "@tamagui/stacks": "1.116.2",
43
+ "@tamagui/start-transition": "1.116.2",
44
+ "@tamagui/use-controllable-state": "1.116.2"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": "*"
48
48
  },
49
49
  "devDependencies": {
50
- "@tamagui/build": "1.116.0",
50
+ "@tamagui/build": "1.116.2",
51
51
  "react": "^18.2.0 || ^19.0.0",
52
52
  "react-native": "0.74.1"
53
53
  },
File without changes
File without changes