@tamagui/popper 2.7.7 → 3.0.0-beta.643.1
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.
- package/dist/cjs/Popper.cjs +474 -606
- package/dist/cjs/Popper.native.cjs +533 -0
- package/dist/cjs/Popper.native.js +484 -606
- package/dist/cjs/Popper.native.js.map +1 -1
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.native.cjs +21 -0
- package/dist/cjs/index.native.js +10 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/Popper.mjs +443 -559
- package/dist/esm/Popper.mjs.map +1 -1
- package/dist/esm/Popper.native.js +453 -555
- package/dist/esm/Popper.native.js.map +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/index.native.js +1 -2
- package/dist/jsx/Popper.mjs +443 -559
- package/dist/jsx/Popper.mjs.map +1 -1
- package/dist/jsx/Popper.native.cjs +533 -0
- package/dist/jsx/Popper.native.js +484 -606
- package/dist/jsx/Popper.native.js.map +1 -1
- package/dist/jsx/index.js +1 -2
- package/dist/jsx/index.mjs +1 -2
- package/dist/jsx/index.native.cjs +21 -0
- package/dist/jsx/index.native.js +10 -10
- package/dist/jsx/index.native.js.map +1 -1
- package/package.json +13 -12
- package/src/Popper.tsx +30 -87
- package/types/Popper.d.ts +42 -74
- package/types/Popper.d.ts.map +1 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
- package/dist/jsx/index.js.map +0 -1
- package/dist/jsx/index.mjs.map +0 -1
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: () => from[key],
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
28
|
+
}) : target, mod));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var Popper_exports = {};
|
|
31
|
+
__export(Popper_exports, {
|
|
32
|
+
Popper: () => Popper,
|
|
33
|
+
PopperAnchor: () => PopperAnchor,
|
|
34
|
+
PopperArrow: () => PopperArrow,
|
|
35
|
+
PopperArrowFrame: () => PopperArrowFrame,
|
|
36
|
+
PopperContent: () => PopperContent,
|
|
37
|
+
PopperContentFrame: () => PopperContentFrame,
|
|
38
|
+
PopperContextFast: () => PopperContextFast,
|
|
39
|
+
PopperContextSlow: () => PopperContextSlow,
|
|
40
|
+
PopperPositionContext: () => PopperPositionContext,
|
|
41
|
+
PopperProvider: () => PopperProvider,
|
|
42
|
+
PopperProviderFast: () => PopperProviderFast,
|
|
43
|
+
PopperProviderSlow: () => PopperProviderSlow,
|
|
44
|
+
setupPopper: () => setupPopper,
|
|
45
|
+
usePopperContext: () => usePopperContext,
|
|
46
|
+
usePopperContextSlow: () => usePopperContextSlow
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(Popper_exports);
|
|
49
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
50
|
+
var import_react_dom = require("react-dom");
|
|
51
|
+
var import_compose_refs = require("@tamagui/compose-refs");
|
|
52
|
+
var import_constants = require("@tamagui/constants");
|
|
53
|
+
var import_core = require("@tamagui/core");
|
|
54
|
+
var import_floating = require("@tamagui/floating");
|
|
55
|
+
var import_floating2 = require("@tamagui/floating");
|
|
56
|
+
var import_get_token = require("@tamagui/get-token");
|
|
57
|
+
var import_start_transition = require("@tamagui/start-transition");
|
|
58
|
+
var React = __toESM(require("react"), 1);
|
|
59
|
+
var import_react_native = require("react-native");
|
|
60
|
+
function _instanceof(left, right) {
|
|
61
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) return !!right[Symbol.hasInstance](left);
|
|
62
|
+
else return left instanceof right;
|
|
63
|
+
}
|
|
64
|
+
function _type_of(obj) {
|
|
65
|
+
"@swc/helpers - typeof";
|
|
66
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
67
|
+
}
|
|
68
|
+
var PopperContextFast = (0, import_core.createStyledContext)({}, "Popper__");
|
|
69
|
+
var PopperPositionContext = import_core.createStyledContext;
|
|
70
|
+
var { useStyledContext: usePopperContext, Provider: PopperProviderFast } = PopperContextFast;
|
|
71
|
+
var PopperContextSlow = (0, import_core.createStyledContext)({}, "PopperSlow__");
|
|
72
|
+
var { useStyledContext: usePopperContextSlow, Provider: PopperProviderSlow } = PopperContextSlow;
|
|
73
|
+
var PopperProvider = function(param) {
|
|
74
|
+
var { scope, children, ...context } = param;
|
|
75
|
+
var fns = React.useRef(context);
|
|
76
|
+
fns.current = context;
|
|
77
|
+
var [slowContext] = React.useState(function() {
|
|
78
|
+
return {
|
|
79
|
+
refs: context.refs,
|
|
80
|
+
triggerElements: context.triggerElements,
|
|
81
|
+
update() {
|
|
82
|
+
for (var _len = arguments.length, a = new Array(_len), _key = 0; _key < _len; _key++) a[_key] = arguments[_key];
|
|
83
|
+
fns.current.update(...a);
|
|
84
|
+
},
|
|
85
|
+
getReferenceProps(p) {
|
|
86
|
+
var _fns_current_getReferenceProps, _fns_current;
|
|
87
|
+
return (_fns_current_getReferenceProps = (_fns_current = fns.current).getReferenceProps) === null || _fns_current_getReferenceProps === void 0 ? void 0 : _fns_current_getReferenceProps.call(_fns_current, p);
|
|
88
|
+
},
|
|
89
|
+
onHoverReference(e) {
|
|
90
|
+
var _fns_current_onHoverReference, _fns_current;
|
|
91
|
+
(_fns_current_onHoverReference = (_fns_current = fns.current).onHoverReference) === null || _fns_current_onHoverReference === void 0 || _fns_current_onHoverReference.call(_fns_current, e);
|
|
92
|
+
},
|
|
93
|
+
onLeaveReference() {
|
|
94
|
+
var _fns_current_onLeaveReference, _fns_current;
|
|
95
|
+
(_fns_current_onLeaveReference = (_fns_current = fns.current).onLeaveReference) === null || _fns_current_onLeaveReference === void 0 || _fns_current_onLeaveReference.call(_fns_current);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperProviderFast, {
|
|
100
|
+
scope,
|
|
101
|
+
...context,
|
|
102
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperProviderSlow, {
|
|
103
|
+
scope,
|
|
104
|
+
...slowContext,
|
|
105
|
+
children
|
|
106
|
+
})
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
var checkFloating = {
|
|
110
|
+
name: "checkFloating",
|
|
111
|
+
fn(data) {
|
|
112
|
+
return { data: { hasFloating: !!data.rects.floating.width } };
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
var setupOptions = {};
|
|
116
|
+
function setupPopper(options) {
|
|
117
|
+
Object.assign(setupOptions, options);
|
|
118
|
+
}
|
|
119
|
+
function tamaguiAutoUpdate(reference, floating, update) {
|
|
120
|
+
update();
|
|
121
|
+
var rafId = requestAnimationFrame(function() {
|
|
122
|
+
update();
|
|
123
|
+
rafId = 0;
|
|
124
|
+
});
|
|
125
|
+
var cleanups = [function() {
|
|
126
|
+
if (rafId) cancelAnimationFrame(rafId);
|
|
127
|
+
}];
|
|
128
|
+
if (_instanceof(reference, HTMLElement)) cleanups.push((0, import_core.registerLayoutNode)(reference, update));
|
|
129
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
130
|
+
var lastWidth = -1;
|
|
131
|
+
var lastHeight = -1;
|
|
132
|
+
var ro = new ResizeObserver(function(entries) {
|
|
133
|
+
var entry = entries[entries.length - 1];
|
|
134
|
+
if (!entry) return;
|
|
135
|
+
var { width, height } = entry.contentRect;
|
|
136
|
+
if (lastWidth === -1) {
|
|
137
|
+
lastWidth = width;
|
|
138
|
+
lastHeight = height;
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (width !== lastWidth || height !== lastHeight) {
|
|
142
|
+
lastWidth = width;
|
|
143
|
+
lastHeight = height;
|
|
144
|
+
update();
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
ro.observe(floating);
|
|
148
|
+
cleanups.push(function() {
|
|
149
|
+
return ro.disconnect();
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
var ancestors = [..._instanceof(reference, Element) ? (0, import_floating2.getOverflowAncestors)(reference) : [], ...(0, import_floating2.getOverflowAncestors)(floating)];
|
|
153
|
+
var uniqueAncestors = [...new Set(ancestors)];
|
|
154
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
155
|
+
try {
|
|
156
|
+
for (var _iterator = uniqueAncestors[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) _step.value.addEventListener("scroll", update, { passive: true });
|
|
157
|
+
} catch (err) {
|
|
158
|
+
_didIteratorError = true;
|
|
159
|
+
_iteratorError = err;
|
|
160
|
+
} finally {
|
|
161
|
+
try {
|
|
162
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) _iterator.return();
|
|
163
|
+
} finally {
|
|
164
|
+
if (_didIteratorError) throw _iteratorError;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
window.addEventListener("resize", update);
|
|
168
|
+
cleanups.push(function() {
|
|
169
|
+
var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
|
|
170
|
+
try {
|
|
171
|
+
for (var _iterator2 = uniqueAncestors[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) _step2.value.removeEventListener("scroll", update);
|
|
172
|
+
} catch (err) {
|
|
173
|
+
_didIteratorError2 = true;
|
|
174
|
+
_iteratorError2 = err;
|
|
175
|
+
} finally {
|
|
176
|
+
try {
|
|
177
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) _iterator2.return();
|
|
178
|
+
} finally {
|
|
179
|
+
if (_didIteratorError2) throw _iteratorError2;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
window.removeEventListener("resize", update);
|
|
183
|
+
});
|
|
184
|
+
return function() {
|
|
185
|
+
return cleanups.forEach(function(fn) {
|
|
186
|
+
return fn();
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function Popper(props) {
|
|
191
|
+
var { children, size, strategy = "absolute", placement = "bottom", stayInFrame, allowFlip, offset, disableRTL, resize, passThrough, open, scope } = props;
|
|
192
|
+
var [arrowEl, setArrow] = React.useState(null);
|
|
193
|
+
var [arrowSize, setArrowSize] = React.useState(0);
|
|
194
|
+
var offsetOptions = offset !== null && offset !== void 0 ? offset : arrowSize;
|
|
195
|
+
React.useRef({});
|
|
196
|
+
var isOpen = passThrough ? false : open !== null && open !== void 0 ? open : true;
|
|
197
|
+
var middlewareRef = React.useRef([]);
|
|
198
|
+
if (isOpen) middlewareRef.current = [
|
|
199
|
+
typeof offsetOptions !== "undefined" ? (0, import_floating2.offset)(offsetOptions) : null,
|
|
200
|
+
allowFlip ? (0, import_floating2.flip)(typeof allowFlip === "boolean" ? {} : allowFlip) : null,
|
|
201
|
+
stayInFrame ? (0, import_floating2.shift)({
|
|
202
|
+
padding: 10,
|
|
203
|
+
mainAxis: true,
|
|
204
|
+
crossAxis: false,
|
|
205
|
+
...(typeof stayInFrame === "undefined" ? "undefined" : _type_of(stayInFrame)) === "object" ? stayInFrame : null
|
|
206
|
+
}) : null,
|
|
207
|
+
arrowEl ? (0, import_floating2.arrow)({ element: arrowEl }) : null,
|
|
208
|
+
checkFloating,
|
|
209
|
+
null,
|
|
210
|
+
null,
|
|
211
|
+
null
|
|
212
|
+
].filter(Boolean);
|
|
213
|
+
var floating = (0, import_floating2.useFloating)({
|
|
214
|
+
open: isOpen,
|
|
215
|
+
strategy,
|
|
216
|
+
placement,
|
|
217
|
+
sameScrollView: false,
|
|
218
|
+
whileElementsMounted: !isOpen ? void 0 : tamaguiAutoUpdate,
|
|
219
|
+
platform: (disableRTL !== null && disableRTL !== void 0 ? disableRTL : setupOptions.disableRTL) ? {
|
|
220
|
+
...import_floating2.platform,
|
|
221
|
+
isRTL(element) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
} : import_floating2.platform,
|
|
225
|
+
middleware: middlewareRef.current
|
|
226
|
+
});
|
|
227
|
+
var { middlewareData } = floating;
|
|
228
|
+
var dimensions = (0, import_react_native.useWindowDimensions)();
|
|
229
|
+
var [keyboardOpen, setKeyboardOpen] = React.useState(false);
|
|
230
|
+
React.useEffect(function() {
|
|
231
|
+
var showSubscription = import_react_native.Keyboard.addListener("keyboardDidShow", function() {
|
|
232
|
+
(0, import_start_transition.startTransition)(function() {
|
|
233
|
+
setKeyboardOpen(true);
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
var hideSubscription = import_react_native.Keyboard.addListener("keyboardDidHide", function() {
|
|
237
|
+
(0, import_start_transition.startTransition)(function() {
|
|
238
|
+
setKeyboardOpen(false);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
return function() {
|
|
242
|
+
showSubscription.remove();
|
|
243
|
+
hideSubscription.remove();
|
|
244
|
+
};
|
|
245
|
+
}, []);
|
|
246
|
+
(0, import_constants.useIsomorphicLayoutEffect)(function() {
|
|
247
|
+
if (passThrough) return;
|
|
248
|
+
floating.update();
|
|
249
|
+
}, [
|
|
250
|
+
passThrough,
|
|
251
|
+
dimensions,
|
|
252
|
+
keyboardOpen
|
|
253
|
+
]);
|
|
254
|
+
var popperContext = React.useMemo(function() {
|
|
255
|
+
var _middlewareData_checkFloating;
|
|
256
|
+
return {
|
|
257
|
+
size,
|
|
258
|
+
arrowRef: setArrow,
|
|
259
|
+
arrowStyle: middlewareData.arrow,
|
|
260
|
+
onArrowSize: setArrowSize,
|
|
261
|
+
hasFloating: (_middlewareData_checkFloating = middlewareData.checkFloating) === null || _middlewareData_checkFloating === void 0 ? void 0 : _middlewareData_checkFloating.hasFloating,
|
|
262
|
+
transformOrigin: middlewareData.transformOrigin,
|
|
263
|
+
open: !!open,
|
|
264
|
+
...floating
|
|
265
|
+
};
|
|
266
|
+
}, [
|
|
267
|
+
open,
|
|
268
|
+
size,
|
|
269
|
+
floating,
|
|
270
|
+
JSON.stringify(middlewareData.arrow || null),
|
|
271
|
+
JSON.stringify(middlewareData.transformOrigin || null)
|
|
272
|
+
]);
|
|
273
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperProvider, {
|
|
274
|
+
scope,
|
|
275
|
+
...popperContext,
|
|
276
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_floating.FloatingOverrideContext.Provider, {
|
|
277
|
+
value: null,
|
|
278
|
+
children
|
|
279
|
+
})
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
var PopperAnchor = (0, import_core.createStyledHOC)(import_core.View, function PopperAnchor2(props, forwardedRef) {
|
|
283
|
+
var { virtualRef, scope, ...rest } = props;
|
|
284
|
+
var context = usePopperContextSlow(scope);
|
|
285
|
+
var { getReferenceProps, refs, update } = context;
|
|
286
|
+
var ref = React.useRef(null);
|
|
287
|
+
var triggerId = React.useId();
|
|
288
|
+
React.useEffect(function() {
|
|
289
|
+
if (!scope || !context.triggerElements || !ref.current) return;
|
|
290
|
+
if (!_instanceof(ref.current, Element)) return;
|
|
291
|
+
var el = ref.current;
|
|
292
|
+
context.triggerElements.add(triggerId, el);
|
|
293
|
+
return function() {
|
|
294
|
+
var _context_triggerElements;
|
|
295
|
+
(_context_triggerElements = context.triggerElements) === null || _context_triggerElements === void 0 || _context_triggerElements.delete(triggerId);
|
|
296
|
+
};
|
|
297
|
+
}, [
|
|
298
|
+
scope,
|
|
299
|
+
triggerId,
|
|
300
|
+
context.triggerElements
|
|
301
|
+
]);
|
|
302
|
+
React.useEffect(function() {
|
|
303
|
+
if (virtualRef) {
|
|
304
|
+
refs.setReference(virtualRef.current);
|
|
305
|
+
update();
|
|
306
|
+
}
|
|
307
|
+
}, [virtualRef]);
|
|
308
|
+
var refProps = (getReferenceProps === null || getReferenceProps === void 0 ? void 0 : getReferenceProps({
|
|
309
|
+
...rest,
|
|
310
|
+
ref
|
|
311
|
+
})) || null;
|
|
312
|
+
var safeSetReference = React.useCallback(function(node) {
|
|
313
|
+
(0, import_start_transition.startTransition)(function() {
|
|
314
|
+
refs.setReference(node);
|
|
315
|
+
});
|
|
316
|
+
}, [refs]);
|
|
317
|
+
var shouldHandleInHover = import_constants.isWeb && scope;
|
|
318
|
+
var composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref, shouldHandleInHover ? void 0 : safeSetReference);
|
|
319
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
|
|
320
|
+
...rest,
|
|
321
|
+
...refProps,
|
|
322
|
+
ref: composedRefs,
|
|
323
|
+
...shouldHandleInHover && {
|
|
324
|
+
onMouseEnter: function(e) {
|
|
325
|
+
var _e_currentTarget;
|
|
326
|
+
var el = (_e_currentTarget = e.currentTarget) !== null && _e_currentTarget !== void 0 ? _e_currentTarget : ref.current;
|
|
327
|
+
if (_instanceof(el, HTMLElement)) {
|
|
328
|
+
var _refProps_onPointerEnter, _context_onHoverReference;
|
|
329
|
+
(0, import_react_dom.flushSync)(function() {
|
|
330
|
+
return refs.setReference(el);
|
|
331
|
+
});
|
|
332
|
+
update();
|
|
333
|
+
if (!refProps) return;
|
|
334
|
+
(_refProps_onPointerEnter = refProps.onPointerEnter) === null || _refProps_onPointerEnter === void 0 || _refProps_onPointerEnter.call(refProps, e);
|
|
335
|
+
(_context_onHoverReference = context.onHoverReference) === null || _context_onHoverReference === void 0 || _context_onHoverReference.call(context, e.nativeEvent);
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
onMouseLeave: function(e) {
|
|
339
|
+
var _context_onLeaveReference, _refProps_onMouseLeave;
|
|
340
|
+
(_context_onLeaveReference = context.onLeaveReference) === null || _context_onLeaveReference === void 0 || _context_onLeaveReference.call(context);
|
|
341
|
+
refProps === null || refProps === void 0 || (_refProps_onMouseLeave = refProps.onMouseLeave) == null || _refProps_onMouseLeave.call(refProps, e);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
var PopperContentFrame = (0, import_core.styled)(import_core.View, { displayName: "PopperContent" });
|
|
347
|
+
var PopperContent = (0, import_core.createRefComponent)(function PopperContent2(props, forwardedRef) {
|
|
348
|
+
var isAnimatePosControlled = "animatePosition" in props;
|
|
349
|
+
var { scope, animatePosition, children, passThrough, ...rest } = props;
|
|
350
|
+
var animatePos = animatePosition;
|
|
351
|
+
var context = usePopperContext(scope);
|
|
352
|
+
var { strategy, placement, refs, x, y, getFloatingProps, isPositioned, transformOrigin, update } = context;
|
|
353
|
+
var updateRef = React.useRef(update);
|
|
354
|
+
updateRef.current = update;
|
|
355
|
+
var lastNodeRef = React.useRef(null);
|
|
356
|
+
var safeSetFloating = React.useCallback(function(node) {
|
|
357
|
+
var isNewNode = node !== lastNodeRef.current;
|
|
358
|
+
if (node) {
|
|
359
|
+
lastNodeRef.current = node;
|
|
360
|
+
refs.setFloating(node);
|
|
361
|
+
if (!isNewNode) {
|
|
362
|
+
var _updateRef_current;
|
|
363
|
+
(_updateRef_current = updateRef.current) === null || _updateRef_current === void 0 || _updateRef_current.call(updateRef);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}, [refs.setFloating]);
|
|
367
|
+
React.useEffect(function() {
|
|
368
|
+
return function() {
|
|
369
|
+
var ourNode = lastNodeRef.current;
|
|
370
|
+
if (ourNode && refs.floating.current === ourNode) refs.setFloating(null);
|
|
371
|
+
lastNodeRef.current = null;
|
|
372
|
+
};
|
|
373
|
+
}, []);
|
|
374
|
+
var contentRefs = (0, import_compose_refs.useComposedRefs)(safeSetFloating, forwardedRef);
|
|
375
|
+
var [needsMeasure, setNeedsMeasure] = React.useState(animatePos);
|
|
376
|
+
(0, import_constants.useIsomorphicLayoutEffect)(function() {
|
|
377
|
+
if (needsMeasure && x && y) setNeedsMeasure(false);
|
|
378
|
+
}, [
|
|
379
|
+
needsMeasure,
|
|
380
|
+
animatePos,
|
|
381
|
+
x,
|
|
382
|
+
y
|
|
383
|
+
]);
|
|
384
|
+
var hasBeenPositioned = React.useRef(false);
|
|
385
|
+
var lastGoodPosition = React.useRef({
|
|
386
|
+
x: 0,
|
|
387
|
+
y: 0
|
|
388
|
+
});
|
|
389
|
+
if (x !== 0 || y !== 0) {
|
|
390
|
+
lastGoodPosition.current = {
|
|
391
|
+
x,
|
|
392
|
+
y
|
|
393
|
+
};
|
|
394
|
+
if (isPositioned) hasBeenPositioned.current = true;
|
|
395
|
+
}
|
|
396
|
+
var brieflyZero = hasBeenPositioned.current && x === 0 && y === 0;
|
|
397
|
+
var effectiveX = brieflyZero ? lastGoodPosition.current.x : x;
|
|
398
|
+
var effectiveY = brieflyZero ? lastGoodPosition.current.y : y;
|
|
399
|
+
var hide = !hasBeenPositioned.current && effectiveX === 0 && effectiveY === 0;
|
|
400
|
+
var disableAnimationProp = animatePos === "even-when-repositioning" ? needsMeasure : !hasBeenPositioned.current && !isPositioned || needsMeasure;
|
|
401
|
+
var [disableAnimation, setDisableAnimation] = React.useState(disableAnimationProp);
|
|
402
|
+
React.useEffect(function() {
|
|
403
|
+
setDisableAnimation(disableAnimationProp);
|
|
404
|
+
}, [disableAnimationProp]);
|
|
405
|
+
var frameProps = {
|
|
406
|
+
ref: contentRefs,
|
|
407
|
+
...hide ? {} : {
|
|
408
|
+
x: effectiveX || 0,
|
|
409
|
+
y: effectiveY || 0
|
|
410
|
+
},
|
|
411
|
+
top: 0,
|
|
412
|
+
left: 0,
|
|
413
|
+
position: strategy,
|
|
414
|
+
opacity: hide ? 0 : 1,
|
|
415
|
+
...isAnimatePosControlled && {
|
|
416
|
+
transition: animatePos ? rest.transition : void 0,
|
|
417
|
+
animateOnly: animatePos && !disableAnimation ? rest.animateOnly : [],
|
|
418
|
+
animatePresence: false
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
var { style, ...floatingProps } = getFloatingProps ? getFloatingProps(frameProps) : frameProps;
|
|
422
|
+
var transformOriginStyle = import_constants.isWeb && transformOrigin ? { transformOrigin: `${transformOrigin.x} ${transformOrigin.y}` } : void 0;
|
|
423
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.LayoutMeasurementController, {
|
|
424
|
+
disable: !context.open,
|
|
425
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.View, {
|
|
426
|
+
passThrough,
|
|
427
|
+
ref: contentRefs,
|
|
428
|
+
direction: rest.direction,
|
|
429
|
+
...passThrough ? null : floatingProps,
|
|
430
|
+
...!passThrough && animatePos && { "data-popper-animate-position": "true" },
|
|
431
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperContentFrame, {
|
|
432
|
+
passThrough,
|
|
433
|
+
...!passThrough && {
|
|
434
|
+
"data-placement": placement,
|
|
435
|
+
"data-strategy": strategy,
|
|
436
|
+
...style,
|
|
437
|
+
...transformOriginStyle,
|
|
438
|
+
...rest
|
|
439
|
+
},
|
|
440
|
+
children
|
|
441
|
+
}, "popper-content-frame")
|
|
442
|
+
})
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
var PopperArrowFrame = (0, import_core.styled)(import_core.View, {
|
|
446
|
+
displayName: "PopperArrow",
|
|
447
|
+
position: "relative"
|
|
448
|
+
});
|
|
449
|
+
var PopperArrowOuterFrame = (0, import_core.styled)(import_core.View, {
|
|
450
|
+
displayName: "PopperArrowOuter",
|
|
451
|
+
position: "absolute",
|
|
452
|
+
zIndex: 1e6,
|
|
453
|
+
pointerEvents: "none",
|
|
454
|
+
overflow: "hidden",
|
|
455
|
+
alignItems: "center",
|
|
456
|
+
justifyContent: "center"
|
|
457
|
+
});
|
|
458
|
+
var opposites = {
|
|
459
|
+
top: "bottom",
|
|
460
|
+
right: "left",
|
|
461
|
+
bottom: "top",
|
|
462
|
+
left: "right"
|
|
463
|
+
};
|
|
464
|
+
var PopperArrow = (0, import_core.createRefComponent)(function PopperArrow2(propsIn, forwardedRef) {
|
|
465
|
+
var _context_arrowStyle, _context_arrowStyle1;
|
|
466
|
+
var isAnimatePosControlled = "animatePosition" in propsIn;
|
|
467
|
+
var { scope, animatePosition, transition, ...rest } = propsIn;
|
|
468
|
+
var { offset, size: sizeProp, borderWidth = 0, ...arrowProps } = rest;
|
|
469
|
+
var context = usePopperContext(scope);
|
|
470
|
+
var sizeVal = typeof sizeProp === "number" ? sizeProp : (0, import_core.getVariableValue)((0, import_get_token.getSize)(sizeProp !== null && sizeProp !== void 0 ? sizeProp : context.size)) * .52 - 11.5;
|
|
471
|
+
var size = Math.max(0, +sizeVal);
|
|
472
|
+
var { placement } = context;
|
|
473
|
+
var refs = (0, import_compose_refs.useComposedRefs)(context.arrowRef, forwardedRef);
|
|
474
|
+
var x = ((_context_arrowStyle = context.arrowStyle) === null || _context_arrowStyle === void 0 ? void 0 : _context_arrowStyle.x) || 0;
|
|
475
|
+
var y = ((_context_arrowStyle1 = context.arrowStyle) === null || _context_arrowStyle1 === void 0 ? void 0 : _context_arrowStyle1.y) || 0;
|
|
476
|
+
var arrowPositioned = context.arrowStyle != null;
|
|
477
|
+
var primaryPlacement = placement ? placement.split("-")[0] : "top";
|
|
478
|
+
var arrowStyle = {
|
|
479
|
+
x,
|
|
480
|
+
y,
|
|
481
|
+
width: size,
|
|
482
|
+
height: size
|
|
483
|
+
};
|
|
484
|
+
var innerArrowStyle = {};
|
|
485
|
+
var isVertical = primaryPlacement === "bottom" || primaryPlacement === "top";
|
|
486
|
+
if (primaryPlacement) {
|
|
487
|
+
arrowStyle[isVertical ? "width" : "height"] = size * 2;
|
|
488
|
+
var oppSide = opposites[primaryPlacement];
|
|
489
|
+
if (oppSide) {
|
|
490
|
+
arrowStyle[oppSide] = -size;
|
|
491
|
+
innerArrowStyle[oppSide] = size / 2;
|
|
492
|
+
}
|
|
493
|
+
if (oppSide === "top" || oppSide === "bottom") arrowStyle.left = 0;
|
|
494
|
+
if (oppSide === "left" || oppSide === "right") arrowStyle.top = 0;
|
|
495
|
+
(0, import_constants.useIsomorphicLayoutEffect)(function() {
|
|
496
|
+
var _context_onArrowSize;
|
|
497
|
+
(_context_onArrowSize = context.onArrowSize) === null || _context_onArrowSize === void 0 || _context_onArrowSize.call(context, size);
|
|
498
|
+
}, [size, context.onArrowSize]);
|
|
499
|
+
}
|
|
500
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperArrowOuterFrame, {
|
|
501
|
+
ref: refs,
|
|
502
|
+
...arrowStyle,
|
|
503
|
+
...!arrowPositioned && { opacity: 0 },
|
|
504
|
+
...isAnimatePosControlled && {
|
|
505
|
+
transition: animatePosition ? transition : void 0,
|
|
506
|
+
animateOnly: animatePosition ? ["transform"] : [],
|
|
507
|
+
animatePresence: false
|
|
508
|
+
},
|
|
509
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PopperArrowFrame, {
|
|
510
|
+
width: size,
|
|
511
|
+
height: size,
|
|
512
|
+
...arrowProps,
|
|
513
|
+
...innerArrowStyle,
|
|
514
|
+
rotate: "45deg",
|
|
515
|
+
...primaryPlacement === "bottom" && {
|
|
516
|
+
borderLeftWidth: borderWidth,
|
|
517
|
+
borderTopWidth: borderWidth
|
|
518
|
+
},
|
|
519
|
+
...primaryPlacement === "top" && {
|
|
520
|
+
borderBottomWidth: borderWidth,
|
|
521
|
+
borderRightWidth: borderWidth
|
|
522
|
+
},
|
|
523
|
+
...primaryPlacement === "right" && {
|
|
524
|
+
borderLeftWidth: borderWidth,
|
|
525
|
+
borderBottomWidth: borderWidth
|
|
526
|
+
},
|
|
527
|
+
...primaryPlacement === "left" && {
|
|
528
|
+
borderTopWidth: borderWidth,
|
|
529
|
+
borderRightWidth: borderWidth
|
|
530
|
+
}
|
|
531
|
+
})
|
|
532
|
+
});
|
|
533
|
+
});
|