@hanzogui/popper 8.3.0 → 8.3.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.
- package/dist/cjs/Popper.js +644 -0
- package/dist/cjs/Popper.js.map +1 -0
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/Popper.js +637 -0
- package/dist/esm/Popper.js.map +1 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.js.map +1 -1
- package/package.json +23 -23
- package/src/Popper.tsx +16 -18
- package/src/index.ts +1 -1
- package/types/Popper.d.ts +27 -27
- package/types/Popper.d.ts.map +1 -1
- package/types/index.d.ts +1 -1
- package/types/index.d.ts.map +1 -1
- package/dist/cjs/Popper.cjs +0 -627
- package/dist/cjs/Popper.native.js +0 -631
- package/dist/cjs/Popper.native.js.map +0 -1
- package/dist/cjs/index.cjs +0 -20
- package/dist/cjs/index.native.js +0 -23
- package/dist/cjs/index.native.js.map +0 -1
- package/dist/esm/Popper.mjs +0 -566
- package/dist/esm/Popper.mjs.map +0 -1
- package/dist/esm/Popper.native.js +0 -563
- package/dist/esm/Popper.native.js.map +0 -1
- package/dist/esm/index.mjs +0 -2
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js +0 -2
- package/dist/esm/index.native.js.map +0 -1
- package/dist/jsx/Popper.mjs +0 -566
- package/dist/jsx/Popper.mjs.map +0 -1
- package/dist/jsx/Popper.native.js +0 -631
- package/dist/jsx/Popper.native.js.map +0 -1
- package/dist/jsx/index.js +0 -2
- package/dist/jsx/index.js.map +0 -1
- package/dist/jsx/index.mjs +0 -2
- package/dist/jsx/index.mjs.map +0 -1
- package/dist/jsx/index.native.js +0 -23
- package/dist/jsx/index.native.js.map +0 -1
package/dist/cjs/Popper.cjs
DELETED
|
@@ -1,627 +0,0 @@
|
|
|
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;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
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, {
|
|
16
|
-
get: () => from[key],
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
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: true
|
|
30
|
-
}) : target, mod));
|
|
31
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
-
value: true
|
|
33
|
-
}), mod);
|
|
34
|
-
var Popper_exports = {};
|
|
35
|
-
__export(Popper_exports, {
|
|
36
|
-
Popper: () => Popper,
|
|
37
|
-
PopperAnchor: () => PopperAnchor,
|
|
38
|
-
PopperArrow: () => PopperArrow,
|
|
39
|
-
PopperArrowFrame: () => PopperArrowFrame,
|
|
40
|
-
PopperContent: () => PopperContent,
|
|
41
|
-
PopperContentFrame: () => PopperContentFrame,
|
|
42
|
-
PopperContextFast: () => PopperContextFast,
|
|
43
|
-
PopperContextSlow: () => PopperContextSlow,
|
|
44
|
-
PopperPositionContext: () => PopperPositionContext,
|
|
45
|
-
PopperProvider: () => PopperProvider,
|
|
46
|
-
PopperProviderFast: () => PopperProviderFast,
|
|
47
|
-
PopperProviderSlow: () => PopperProviderSlow,
|
|
48
|
-
setupPopper: () => setupPopper,
|
|
49
|
-
usePopperContext: () => usePopperContext,
|
|
50
|
-
usePopperContextSlow: () => usePopperContextSlow
|
|
51
|
-
});
|
|
52
|
-
module.exports = __toCommonJS(Popper_exports);
|
|
53
|
-
var import_react_dom = require("react-dom");
|
|
54
|
-
var import_compose_refs = require("@hanzogui/compose-refs");
|
|
55
|
-
var import_constants = require("@hanzogui/constants");
|
|
56
|
-
var import_core = require("@hanzogui/core");
|
|
57
|
-
var import_floating = require("@hanzogui/floating");
|
|
58
|
-
var import_floating2 = require("@hanzogui/floating");
|
|
59
|
-
var import_get_token = require("@hanzogui/get-token");
|
|
60
|
-
var import_stacks = require("@hanzogui/stacks");
|
|
61
|
-
var import_start_transition = require("@hanzogui/start-transition");
|
|
62
|
-
var React = __toESM(require("react"), 1);
|
|
63
|
-
require("react-native-web");
|
|
64
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
65
|
-
const PopperContextFast = (0, import_core.createStyledContext)(
|
|
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, {
|
|
104
|
-
scope,
|
|
105
|
-
...context,
|
|
106
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperProviderSlow, {
|
|
107
|
-
scope,
|
|
108
|
-
...slowContext,
|
|
109
|
-
children
|
|
110
|
-
})
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
const checkFloating = void 0;
|
|
114
|
-
const setupOptions = {};
|
|
115
|
-
function setupPopper(options) {
|
|
116
|
-
Object.assign(setupOptions, options);
|
|
117
|
-
}
|
|
118
|
-
function getSideAndAlignFromPlacement(placement) {
|
|
119
|
-
const [side, align = "center"] = placement.split("-");
|
|
120
|
-
return [side, align];
|
|
121
|
-
}
|
|
122
|
-
const transformOriginMiddleware = options => ({
|
|
123
|
-
name: "transformOrigin",
|
|
124
|
-
options,
|
|
125
|
-
fn(data) {
|
|
126
|
-
const {
|
|
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 {
|
|
158
|
-
data: {
|
|
159
|
-
x,
|
|
160
|
-
y
|
|
161
|
-
}
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
function hanzoguiAutoUpdate(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
|
-
}
|
|
187
|
-
function Popper(props) {
|
|
188
|
-
const {
|
|
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("--hanzogui-popper-available-width", `${availableWidth}px`);
|
|
243
|
-
contentStyle.setProperty("--hanzogui-popper-available-height", `${availableHeight}px`);
|
|
244
|
-
contentStyle.setProperty("--hanzogui-popper-anchor-width", `${anchorWidth}px`);
|
|
245
|
-
contentStyle.setProperty("--hanzogui-popper-anchor-height", `${anchorHeight}px`);
|
|
246
|
-
}
|
|
247
|
-
}), transformOriginMiddleware({
|
|
248
|
-
arrowHeight: arrowSize,
|
|
249
|
-
arrowWidth: arrowSize
|
|
250
|
-
})].filter(Boolean);
|
|
251
|
-
let floating = (0, import_floating2.useFloating)({
|
|
252
|
-
open: isOpen,
|
|
253
|
-
strategy,
|
|
254
|
-
placement,
|
|
255
|
-
sameScrollView: false,
|
|
256
|
-
whileElementsMounted: !isOpen ? void 0 : hanzoguiAutoUpdate,
|
|
257
|
-
platform: disableRTL ?? setupOptions.disableRTL ? {
|
|
258
|
-
...import_floating2.platform,
|
|
259
|
-
isRTL(element) {
|
|
260
|
-
return false;
|
|
261
|
-
}
|
|
262
|
-
} : import_floating2.platform,
|
|
263
|
-
middleware: middlewareRef.current
|
|
264
|
-
});
|
|
265
|
-
floating = React.useMemo(() => {
|
|
266
|
-
const og = floating.getFloatingProps;
|
|
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;
|
|
277
|
-
}, [floating, resize ? JSON.stringify(resize) : null]);
|
|
278
|
-
const {
|
|
279
|
-
middlewareData
|
|
280
|
-
} = floating;
|
|
281
|
-
const popperContext = React.useMemo(() => {
|
|
282
|
-
return {
|
|
283
|
-
size,
|
|
284
|
-
arrowRef: setArrow,
|
|
285
|
-
arrowStyle: middlewareData.arrow,
|
|
286
|
-
onArrowSize: setArrowSize,
|
|
287
|
-
hasFloating: middlewareData.checkFloating?.hasFloating,
|
|
288
|
-
transformOrigin: middlewareData.transformOrigin,
|
|
289
|
-
open: !!open,
|
|
290
|
-
...floating
|
|
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,
|
|
298
|
-
children
|
|
299
|
-
})
|
|
300
|
-
});
|
|
301
|
-
}
|
|
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);
|
|
338
|
-
});
|
|
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);
|
|
359
|
-
}
|
|
360
|
-
},
|
|
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 {
|
|
379
|
-
padding: tokens.space[val],
|
|
380
|
-
borderRadius: tokens.radius[val]
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
});
|
|
386
|
-
const PopperContent = React.forwardRef(function PopperContent2(props, forwardedRef) {
|
|
387
|
-
const isAnimatePosControlled = "animatePosition" in props || "enableAnimationForPositionChange" in props;
|
|
388
|
-
const {
|
|
389
|
-
scope,
|
|
390
|
-
animatePosition,
|
|
391
|
-
enableAnimationForPositionChange,
|
|
392
|
-
children,
|
|
393
|
-
passThrough,
|
|
394
|
-
unstyled,
|
|
395
|
-
...rest
|
|
396
|
-
} = props;
|
|
397
|
-
const animatePos = animatePosition ?? enableAnimationForPositionChange;
|
|
398
|
-
const context = usePopperContext(scope);
|
|
399
|
-
const {
|
|
400
|
-
strategy,
|
|
401
|
-
placement,
|
|
402
|
-
refs,
|
|
403
|
-
x,
|
|
404
|
-
y,
|
|
405
|
-
getFloatingProps,
|
|
406
|
-
size,
|
|
407
|
-
isPositioned,
|
|
408
|
-
transformOrigin,
|
|
409
|
-
update
|
|
410
|
-
} = context;
|
|
411
|
-
const updateRef = React.useRef(update);
|
|
412
|
-
updateRef.current = update;
|
|
413
|
-
const lastNodeRef = React.useRef(null);
|
|
414
|
-
const safeSetFloating = React.useCallback(node => {
|
|
415
|
-
const isNewNode = node !== lastNodeRef.current;
|
|
416
|
-
if (node) {
|
|
417
|
-
lastNodeRef.current = node;
|
|
418
|
-
refs.setFloating(node);
|
|
419
|
-
if (!isNewNode) updateRef.current?.();
|
|
420
|
-
}
|
|
421
|
-
}, [refs.setFloating]);
|
|
422
|
-
React.useEffect(() => {
|
|
423
|
-
return () => {
|
|
424
|
-
const ourNode = lastNodeRef.current;
|
|
425
|
-
if (ourNode && refs.floating.current === ourNode) refs.setFloating(null);
|
|
426
|
-
lastNodeRef.current = null;
|
|
427
|
-
};
|
|
428
|
-
}, []);
|
|
429
|
-
const contentRefs = (0, import_compose_refs.useComposedRefs)(safeSetFloating, forwardedRef);
|
|
430
|
-
const [needsMeasure, setNeedsMeasure] = React.useState(animatePos);
|
|
431
|
-
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
432
|
-
if (needsMeasure && x && y) setNeedsMeasure(false);
|
|
433
|
-
}, [needsMeasure, animatePos, x, y]);
|
|
434
|
-
const hasBeenPositioned = React.useRef(false);
|
|
435
|
-
const lastGoodPosition = React.useRef({
|
|
436
|
-
x: 0,
|
|
437
|
-
y: 0
|
|
438
|
-
});
|
|
439
|
-
if (x !== 0 || y !== 0) {
|
|
440
|
-
lastGoodPosition.current = {
|
|
441
|
-
x,
|
|
442
|
-
y
|
|
443
|
-
};
|
|
444
|
-
if (isPositioned) hasBeenPositioned.current = true;
|
|
445
|
-
}
|
|
446
|
-
const brieflyZero = hasBeenPositioned.current && x === 0 && y === 0;
|
|
447
|
-
const effectiveX = brieflyZero ? lastGoodPosition.current.x : x;
|
|
448
|
-
const effectiveY = brieflyZero ? lastGoodPosition.current.y : y;
|
|
449
|
-
const hide = !hasBeenPositioned.current && effectiveX === 0 && effectiveY === 0;
|
|
450
|
-
const disableAnimationProp = animatePos === "even-when-repositioning" ? needsMeasure : !hasBeenPositioned.current && !isPositioned || needsMeasure;
|
|
451
|
-
const [disableAnimation, setDisableAnimation] = React.useState(disableAnimationProp);
|
|
452
|
-
React.useEffect(() => {
|
|
453
|
-
setDisableAnimation(disableAnimationProp);
|
|
454
|
-
}, [disableAnimationProp]);
|
|
455
|
-
const frameProps = {
|
|
456
|
-
ref: contentRefs,
|
|
457
|
-
...(hide ? {} : {
|
|
458
|
-
x: effectiveX || 0,
|
|
459
|
-
y: effectiveY || 0
|
|
460
|
-
}),
|
|
461
|
-
top: 0,
|
|
462
|
-
left: 0,
|
|
463
|
-
position: strategy,
|
|
464
|
-
opacity: hide ? 0 : 1,
|
|
465
|
-
...(isAnimatePosControlled && {
|
|
466
|
-
transition: animatePos ? rest.transition : void 0,
|
|
467
|
-
animateOnly: animatePos && !disableAnimation ? rest.animateOnly : [],
|
|
468
|
-
animatePresence: false
|
|
469
|
-
})
|
|
470
|
-
};
|
|
471
|
-
const {
|
|
472
|
-
style,
|
|
473
|
-
...floatingProps
|
|
474
|
-
} = getFloatingProps ? getFloatingProps(frameProps) : frameProps;
|
|
475
|
-
const transformOriginStyle = import_constants.isWeb && transformOrigin ? {
|
|
476
|
-
transformOrigin: `${transformOrigin.x} ${transformOrigin.y}`
|
|
477
|
-
} : void 0;
|
|
478
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.LayoutMeasurementController, {
|
|
479
|
-
disable: !context.open,
|
|
480
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.View, {
|
|
481
|
-
passThrough,
|
|
482
|
-
ref: contentRefs,
|
|
483
|
-
direction: rest.direction,
|
|
484
|
-
...(passThrough ? null : floatingProps),
|
|
485
|
-
...(!passThrough && animatePos && {
|
|
486
|
-
"data-popper-animate-position": "true"
|
|
487
|
-
}),
|
|
488
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperContentFrame, {
|
|
489
|
-
passThrough,
|
|
490
|
-
unstyled,
|
|
491
|
-
...(!passThrough && {
|
|
492
|
-
"data-placement": placement,
|
|
493
|
-
"data-strategy": strategy,
|
|
494
|
-
size,
|
|
495
|
-
...style,
|
|
496
|
-
...transformOriginStyle,
|
|
497
|
-
...rest
|
|
498
|
-
}),
|
|
499
|
-
children
|
|
500
|
-
}, "popper-content-frame")
|
|
501
|
-
})
|
|
502
|
-
});
|
|
503
|
-
});
|
|
504
|
-
const PopperArrowFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
505
|
-
name: "PopperArrow",
|
|
506
|
-
variants: {
|
|
507
|
-
unstyled: {
|
|
508
|
-
false: {
|
|
509
|
-
borderColor: "$borderColor",
|
|
510
|
-
backgroundColor: "$background",
|
|
511
|
-
position: "relative"
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
},
|
|
515
|
-
defaultVariants: {
|
|
516
|
-
unstyled: process.env.GUI_HEADLESS === "1"
|
|
517
|
-
}
|
|
518
|
-
});
|
|
519
|
-
const PopperArrowOuterFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
520
|
-
name: "PopperArrowOuter",
|
|
521
|
-
variants: {
|
|
522
|
-
unstyled: {
|
|
523
|
-
false: {
|
|
524
|
-
position: "absolute",
|
|
525
|
-
zIndex: 1e6,
|
|
526
|
-
pointerEvents: "none",
|
|
527
|
-
overflow: "hidden",
|
|
528
|
-
alignItems: "center",
|
|
529
|
-
justifyContent: "center"
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
},
|
|
533
|
-
defaultVariants: {
|
|
534
|
-
unstyled: process.env.GUI_HEADLESS === "1"
|
|
535
|
-
}
|
|
536
|
-
});
|
|
537
|
-
const opposites = {
|
|
538
|
-
top: "bottom",
|
|
539
|
-
right: "left",
|
|
540
|
-
bottom: "top",
|
|
541
|
-
left: "right"
|
|
542
|
-
};
|
|
543
|
-
const PopperArrow = React.forwardRef(function PopperArrow2(propsIn, forwardedRef) {
|
|
544
|
-
const isAnimatePosControlled = "animatePosition" in propsIn;
|
|
545
|
-
const {
|
|
546
|
-
scope,
|
|
547
|
-
animatePosition,
|
|
548
|
-
transition,
|
|
549
|
-
...rest
|
|
550
|
-
} = propsIn;
|
|
551
|
-
const {
|
|
552
|
-
offset,
|
|
553
|
-
size: sizeProp,
|
|
554
|
-
borderWidth = 0,
|
|
555
|
-
...arrowProps
|
|
556
|
-
} = rest;
|
|
557
|
-
const context = usePopperContext(scope);
|
|
558
|
-
const sizeVal = typeof sizeProp === "number" ? sizeProp : (0, import_core.getVariableValue)((0, import_get_token.getSpace)(sizeProp ?? context.size, {
|
|
559
|
-
shift: -2,
|
|
560
|
-
bounds: [2]
|
|
561
|
-
}));
|
|
562
|
-
const size = Math.max(0, +sizeVal);
|
|
563
|
-
const {
|
|
564
|
-
placement
|
|
565
|
-
} = context;
|
|
566
|
-
const refs = (0, import_compose_refs.useComposedRefs)(context.arrowRef, forwardedRef);
|
|
567
|
-
const x = context.arrowStyle?.x || 0;
|
|
568
|
-
const y = context.arrowStyle?.y || 0;
|
|
569
|
-
const arrowPositioned = context.arrowStyle != null;
|
|
570
|
-
const primaryPlacement = placement ? placement.split("-")[0] : "top";
|
|
571
|
-
const arrowStyle = {
|
|
572
|
-
x,
|
|
573
|
-
y,
|
|
574
|
-
width: size,
|
|
575
|
-
height: size
|
|
576
|
-
};
|
|
577
|
-
const innerArrowStyle = {};
|
|
578
|
-
const isVertical = primaryPlacement === "bottom" || primaryPlacement === "top";
|
|
579
|
-
if (primaryPlacement) {
|
|
580
|
-
arrowStyle[isVertical ? "width" : "height"] = size * 2;
|
|
581
|
-
const oppSide = opposites[primaryPlacement];
|
|
582
|
-
if (oppSide) {
|
|
583
|
-
arrowStyle[oppSide] = -size;
|
|
584
|
-
innerArrowStyle[oppSide] = size / 2;
|
|
585
|
-
}
|
|
586
|
-
if (oppSide === "top" || oppSide === "bottom") arrowStyle.left = 0;
|
|
587
|
-
if (oppSide === "left" || oppSide === "right") arrowStyle.top = 0;
|
|
588
|
-
(0, import_constants.useIsomorphicLayoutEffect)(() => {
|
|
589
|
-
context.onArrowSize?.(size);
|
|
590
|
-
}, [size, context.onArrowSize]);
|
|
591
|
-
}
|
|
592
|
-
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperArrowOuterFrame, {
|
|
593
|
-
ref: refs,
|
|
594
|
-
...arrowStyle,
|
|
595
|
-
...(!arrowPositioned && {
|
|
596
|
-
opacity: 0
|
|
597
|
-
}),
|
|
598
|
-
...(isAnimatePosControlled && {
|
|
599
|
-
transition: animatePosition ? transition : void 0,
|
|
600
|
-
animateOnly: animatePosition ? ["transform"] : [],
|
|
601
|
-
animatePresence: false
|
|
602
|
-
}),
|
|
603
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperArrowFrame, {
|
|
604
|
-
width: size,
|
|
605
|
-
height: size,
|
|
606
|
-
...arrowProps,
|
|
607
|
-
...innerArrowStyle,
|
|
608
|
-
rotate: "45deg",
|
|
609
|
-
...(primaryPlacement === "bottom" && {
|
|
610
|
-
borderLeftWidth: borderWidth,
|
|
611
|
-
borderTopWidth: borderWidth
|
|
612
|
-
}),
|
|
613
|
-
...(primaryPlacement === "top" && {
|
|
614
|
-
borderBottomWidth: borderWidth,
|
|
615
|
-
borderRightWidth: borderWidth
|
|
616
|
-
}),
|
|
617
|
-
...(primaryPlacement === "right" && {
|
|
618
|
-
borderLeftWidth: borderWidth,
|
|
619
|
-
borderBottomWidth: borderWidth
|
|
620
|
-
}),
|
|
621
|
-
...(primaryPlacement === "left" && {
|
|
622
|
-
borderTopWidth: borderWidth,
|
|
623
|
-
borderRightWidth: borderWidth
|
|
624
|
-
})
|
|
625
|
-
})
|
|
626
|
-
});
|
|
627
|
-
});
|