@hanzogui/popper 3.0.2 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +40 -19
- package/dist/cjs/Popper.cjs +492 -460
- package/dist/cjs/Popper.native.js +514 -517
- package/dist/cjs/Popper.native.js.map +1 -1
- package/dist/cjs/index.cjs +7 -5
- package/dist/cjs/index.native.js +8 -6
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/Popper.mjs +456 -426
- package/dist/esm/Popper.mjs.map +1 -1
- package/dist/esm/Popper.native.js +489 -495
- package/dist/esm/Popper.native.js.map +1 -1
- package/dist/jsx/Popper.mjs +456 -426
- package/dist/jsx/Popper.mjs.map +1 -1
- package/dist/jsx/Popper.native.js +514 -517
- package/dist/jsx/Popper.native.js.map +1 -1
- package/dist/jsx/index.native.js +7 -5
- package/package.json +18 -15
- package/src/Popper.tsx +8 -8
- package/types/Popper.d.ts +28 -28
- package/types/Popper.d.ts.map +1 -0
- package/types/index.d.ts.map +1 -0
package/dist/jsx/Popper.mjs
CHANGED
|
@@ -8,57 +8,58 @@ import { getSpace } from "@hanzogui/get-token";
|
|
|
8
8
|
import { YStack } from "@hanzogui/stacks";
|
|
9
9
|
import { startTransition } from "@hanzogui/start-transition";
|
|
10
10
|
import * as React from "react";
|
|
11
|
+
import { Keyboard, useWindowDimensions } from "react-native-web";
|
|
11
12
|
import { jsx } from "react/jsx-runtime";
|
|
12
13
|
const PopperContextFast = createStyledContext(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
14
|
+
// since we always provide this we can avoid setting here
|
|
15
|
+
{}, "Popper__");
|
|
16
|
+
const PopperPositionContext = createStyledContext;
|
|
17
|
+
const {
|
|
18
|
+
useStyledContext: usePopperContext,
|
|
19
|
+
Provider: PopperProviderFast
|
|
20
|
+
} = PopperContextFast;
|
|
21
|
+
const PopperContextSlow = createStyledContext(
|
|
22
|
+
// since we always provide this we can avoid setting here
|
|
23
|
+
{}, "PopperSlow__");
|
|
24
|
+
const {
|
|
25
|
+
useStyledContext: usePopperContextSlow,
|
|
26
|
+
Provider: PopperProviderSlow
|
|
27
|
+
} = PopperContextSlow;
|
|
28
|
+
const PopperProvider = ({
|
|
29
|
+
scope,
|
|
30
|
+
children,
|
|
31
|
+
...context
|
|
32
|
+
}) => {
|
|
33
|
+
const fns = React.useRef(context);
|
|
34
|
+
fns.current = context;
|
|
35
|
+
const [slowContext] = React.useState(() => ({
|
|
36
|
+
refs: context.refs,
|
|
37
|
+
triggerElements: context.triggerElements,
|
|
38
|
+
update(...a) {
|
|
39
|
+
fns.current.update(...a);
|
|
40
|
+
},
|
|
41
|
+
getReferenceProps(p) {
|
|
42
|
+
return fns.current.getReferenceProps?.(p);
|
|
43
|
+
},
|
|
44
|
+
onHoverReference(e) {
|
|
45
|
+
fns.current.onHoverReference?.(e);
|
|
46
|
+
},
|
|
47
|
+
onLeaveReference() {
|
|
48
|
+
fns.current.onLeaveReference?.();
|
|
49
|
+
}
|
|
50
|
+
}));
|
|
51
|
+
return /* @__PURE__ */jsx(PopperProviderFast, {
|
|
28
52
|
scope,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}) => {
|
|
32
|
-
const fns = React.useRef(context);
|
|
33
|
-
fns.current = context;
|
|
34
|
-
const [slowContext] = React.useState(() => ({
|
|
35
|
-
refs: context.refs,
|
|
36
|
-
triggerElements: context.triggerElements,
|
|
37
|
-
update(...a) {
|
|
38
|
-
fns.current.update(...a);
|
|
39
|
-
},
|
|
40
|
-
getReferenceProps(p) {
|
|
41
|
-
return fns.current.getReferenceProps?.(p);
|
|
42
|
-
},
|
|
43
|
-
onHoverReference(e) {
|
|
44
|
-
fns.current.onHoverReference?.(e);
|
|
45
|
-
},
|
|
46
|
-
onLeaveReference() {
|
|
47
|
-
fns.current.onLeaveReference?.();
|
|
48
|
-
}
|
|
49
|
-
}));
|
|
50
|
-
return /* @__PURE__ */jsx(PopperProviderFast, {
|
|
53
|
+
...context,
|
|
54
|
+
children: /* @__PURE__ */jsx(PopperProviderSlow, {
|
|
51
55
|
scope,
|
|
52
|
-
...
|
|
53
|
-
children
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
},
|
|
60
|
-
checkFloating = void 0,
|
|
61
|
-
setupOptions = {};
|
|
56
|
+
...slowContext,
|
|
57
|
+
children
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
const checkFloating = void 0;
|
|
62
|
+
const setupOptions = {};
|
|
62
63
|
function setupPopper(options) {
|
|
63
64
|
Object.assign(setupOptions, options);
|
|
64
65
|
}
|
|
@@ -71,24 +72,37 @@ const transformOriginMiddleware = options => ({
|
|
|
71
72
|
options,
|
|
72
73
|
fn(data) {
|
|
73
74
|
const {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
let x = ""
|
|
90
|
-
|
|
91
|
-
|
|
75
|
+
placement,
|
|
76
|
+
rects,
|
|
77
|
+
middlewareData
|
|
78
|
+
} = data;
|
|
79
|
+
const isArrowHidden = middlewareData.arrow?.centerOffset !== 0;
|
|
80
|
+
const arrowWidth = isArrowHidden ? 0 : options.arrowWidth;
|
|
81
|
+
const arrowHeight = isArrowHidden ? 0 : options.arrowHeight;
|
|
82
|
+
const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);
|
|
83
|
+
const noArrowAlign = {
|
|
84
|
+
start: "0%",
|
|
85
|
+
center: "50%",
|
|
86
|
+
end: "100%"
|
|
87
|
+
}[placedAlign];
|
|
88
|
+
const arrowXCenter = (middlewareData.arrow?.x ?? 0) + arrowWidth / 2;
|
|
89
|
+
const arrowYCenter = (middlewareData.arrow?.y ?? 0) + arrowHeight / 2;
|
|
90
|
+
let x = "";
|
|
91
|
+
let y = "";
|
|
92
|
+
if (placedSide === "bottom") {
|
|
93
|
+
x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
|
|
94
|
+
y = `${-arrowHeight}px`;
|
|
95
|
+
} else if (placedSide === "top") {
|
|
96
|
+
x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
|
|
97
|
+
y = `${rects.floating.height + arrowHeight}px`;
|
|
98
|
+
} else if (placedSide === "right") {
|
|
99
|
+
x = `${-arrowHeight}px`;
|
|
100
|
+
y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
|
|
101
|
+
} else if (placedSide === "left") {
|
|
102
|
+
x = `${rects.floating.width + arrowHeight}px`;
|
|
103
|
+
y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
92
106
|
data: {
|
|
93
107
|
x,
|
|
94
108
|
y
|
|
@@ -96,62 +110,58 @@ const transformOriginMiddleware = options => ({
|
|
|
96
110
|
};
|
|
97
111
|
}
|
|
98
112
|
});
|
|
99
|
-
function
|
|
113
|
+
function guiAutoUpdate(reference, floating, update) {
|
|
100
114
|
update();
|
|
101
115
|
let rafId = requestAnimationFrame(() => {
|
|
102
|
-
update()
|
|
116
|
+
update();
|
|
117
|
+
rafId = 0;
|
|
103
118
|
});
|
|
104
119
|
const cleanups = [() => {
|
|
105
|
-
rafId
|
|
120
|
+
if (rafId) cancelAnimationFrame(rafId);
|
|
106
121
|
}];
|
|
107
|
-
reference instanceof HTMLElement
|
|
108
|
-
const ancestors = [...(reference instanceof Element ? getOverflowAncestors(reference) : []), ...getOverflowAncestors(floating)]
|
|
109
|
-
|
|
122
|
+
if (reference instanceof HTMLElement) cleanups.push(registerLayoutNode(reference, update));
|
|
123
|
+
const ancestors = [...(reference instanceof Element ? getOverflowAncestors(reference) : []), ...getOverflowAncestors(floating)];
|
|
124
|
+
const uniqueAncestors = [...new Set(ancestors)];
|
|
110
125
|
for (const ancestor of uniqueAncestors) ancestor.addEventListener("scroll", update, {
|
|
111
|
-
passive:
|
|
126
|
+
passive: true
|
|
112
127
|
});
|
|
113
|
-
|
|
128
|
+
window.addEventListener("resize", update);
|
|
129
|
+
cleanups.push(() => {
|
|
114
130
|
for (const ancestor of uniqueAncestors) ancestor.removeEventListener("scroll", update);
|
|
115
131
|
window.removeEventListener("resize", update);
|
|
116
|
-
})
|
|
132
|
+
});
|
|
133
|
+
return () => cleanups.forEach(fn => fn());
|
|
117
134
|
}
|
|
118
135
|
function Popper(props) {
|
|
119
136
|
const {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
isOpen
|
|
140
|
-
// order matters: offset first, then flip, then shift, then arrow
|
|
141
|
-
typeof offsetOptions < "u" ? offsetFn(offsetOptions) : null, allowFlip ? flip(typeof allowFlip == "boolean" ? {} : allowFlip) : null,
|
|
142
|
-
// NOTE: shift's axis terminology is reversed vs flip/offset:
|
|
143
|
-
// for top/bottom placements: mainAxis = horizontal, crossAxis = vertical
|
|
144
|
-
// for left/right placements: mainAxis = vertical, crossAxis = horizontal
|
|
145
|
-
// default to horizontal shift only (mainAxis: true, crossAxis: false)
|
|
146
|
-
stayInFrame ? shift({
|
|
137
|
+
children,
|
|
138
|
+
size,
|
|
139
|
+
strategy = "absolute",
|
|
140
|
+
placement = "bottom",
|
|
141
|
+
stayInFrame,
|
|
142
|
+
allowFlip,
|
|
143
|
+
offset,
|
|
144
|
+
disableRTL,
|
|
145
|
+
resize,
|
|
146
|
+
passThrough,
|
|
147
|
+
open,
|
|
148
|
+
scope
|
|
149
|
+
} = props;
|
|
150
|
+
const [arrowEl, setArrow] = React.useState(null);
|
|
151
|
+
const [arrowSize, setArrowSize] = React.useState(0);
|
|
152
|
+
const offsetOptions = offset ?? arrowSize;
|
|
153
|
+
const floatingStyle = React.useRef({});
|
|
154
|
+
const isOpen = passThrough ? false : open ?? true;
|
|
155
|
+
const middlewareRef = React.useRef([]);
|
|
156
|
+
if (isOpen) middlewareRef.current = [typeof offsetOptions !== "undefined" ? offsetFn(offsetOptions) : null, allowFlip ? flip(typeof allowFlip === "boolean" ? {} : allowFlip) : null, stayInFrame ? shift({
|
|
147
157
|
padding: 10,
|
|
148
|
-
mainAxis:
|
|
149
|
-
crossAxis:
|
|
150
|
-
...(typeof stayInFrame
|
|
158
|
+
mainAxis: true,
|
|
159
|
+
crossAxis: false,
|
|
160
|
+
...(typeof stayInFrame === "object" ? stayInFrame : null)
|
|
151
161
|
}) : null, arrowEl ? arrow({
|
|
152
162
|
element: arrowEl
|
|
153
163
|
}) : null, checkFloating, resize ? sizeMiddleware({
|
|
154
|
-
padding: typeof stayInFrame
|
|
164
|
+
padding: typeof stayInFrame === "object" ? stayInFrame.padding : 10,
|
|
155
165
|
apply({
|
|
156
166
|
availableHeight,
|
|
157
167
|
availableWidth
|
|
@@ -162,9 +172,9 @@ function Popper(props) {
|
|
|
162
172
|
maxWidth: `${availableWidth}px`
|
|
163
173
|
});
|
|
164
174
|
const floatingChild = floating.refs.floating.current?.firstChild;
|
|
165
|
-
floatingChild && floatingChild instanceof HTMLElement
|
|
175
|
+
if (floatingChild && floatingChild instanceof HTMLElement) Object.assign(floatingChild.style, floatingStyle.current);
|
|
166
176
|
},
|
|
167
|
-
...(typeof resize
|
|
177
|
+
...(typeof resize === "object" && resize)
|
|
168
178
|
}) : null, sizeMiddleware({
|
|
169
179
|
apply({
|
|
170
180
|
elements,
|
|
@@ -173,372 +183,392 @@ function Popper(props) {
|
|
|
173
183
|
availableHeight
|
|
174
184
|
}) {
|
|
175
185
|
const {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
contentStyle.setProperty("--
|
|
186
|
+
width: anchorWidth,
|
|
187
|
+
height: anchorHeight
|
|
188
|
+
} = rects.reference;
|
|
189
|
+
const contentStyle = elements.floating.style;
|
|
190
|
+
contentStyle.setProperty("--gui-popper-available-width", `${availableWidth}px`);
|
|
191
|
+
contentStyle.setProperty("--gui-popper-available-height", `${availableHeight}px`);
|
|
192
|
+
contentStyle.setProperty("--gui-popper-anchor-width", `${anchorWidth}px`);
|
|
193
|
+
contentStyle.setProperty("--gui-popper-anchor-height", `${anchorHeight}px`);
|
|
181
194
|
}
|
|
182
195
|
}), transformOriginMiddleware({
|
|
183
196
|
arrowHeight: arrowSize,
|
|
184
197
|
arrowWidth: arrowSize
|
|
185
|
-
})].filter(Boolean)
|
|
198
|
+
})].filter(Boolean);
|
|
186
199
|
let floating = useFloating({
|
|
187
200
|
open: isOpen,
|
|
188
201
|
strategy,
|
|
189
202
|
placement,
|
|
190
|
-
sameScrollView:
|
|
191
|
-
|
|
192
|
-
whileElementsMounted: isOpen ? tamaguiAutoUpdate : void 0,
|
|
203
|
+
sameScrollView: false,
|
|
204
|
+
whileElementsMounted: !isOpen ? void 0 : guiAutoUpdate,
|
|
193
205
|
platform: disableRTL ?? setupOptions.disableRTL ? {
|
|
194
206
|
...platform,
|
|
195
207
|
isRTL(element) {
|
|
196
|
-
return
|
|
208
|
+
return false;
|
|
197
209
|
}
|
|
198
210
|
} : platform,
|
|
199
211
|
middleware: middlewareRef.current
|
|
200
212
|
});
|
|
201
213
|
floating = React.useMemo(() => {
|
|
202
214
|
const og = floating.getFloatingProps;
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
215
|
+
if (resize && og) floating.getFloatingProps = props2 => {
|
|
216
|
+
return og({
|
|
217
|
+
...props2,
|
|
218
|
+
style: {
|
|
219
|
+
...props2.style,
|
|
220
|
+
...floatingStyle.current
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
return floating;
|
|
210
225
|
}, [floating, resize ? JSON.stringify(resize) : null]);
|
|
211
226
|
const {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
popperContext = React.useMemo(() => ({
|
|
215
|
-
size,
|
|
216
|
-
arrowRef: setArrow,
|
|
217
|
-
arrowStyle: middlewareData.arrow,
|
|
218
|
-
onArrowSize: setArrowSize,
|
|
219
|
-
hasFloating: middlewareData.checkFloating?.hasFloating,
|
|
220
|
-
transformOrigin: middlewareData.transformOrigin,
|
|
221
|
-
open: !!open,
|
|
222
|
-
...floating
|
|
223
|
-
}), [open, size, floating, JSON.stringify(middlewareData.arrow || null), JSON.stringify(middlewareData.transformOrigin || null)]);
|
|
227
|
+
middlewareData
|
|
228
|
+
} = floating;
|
|
224
229
|
return /* @__PURE__ */jsx(PopperProvider, {
|
|
225
230
|
scope,
|
|
226
|
-
...
|
|
231
|
+
...React.useMemo(() => {
|
|
232
|
+
return {
|
|
233
|
+
size,
|
|
234
|
+
arrowRef: setArrow,
|
|
235
|
+
arrowStyle: middlewareData.arrow,
|
|
236
|
+
onArrowSize: setArrowSize,
|
|
237
|
+
hasFloating: middlewareData.checkFloating?.hasFloating,
|
|
238
|
+
transformOrigin: middlewareData.transformOrigin,
|
|
239
|
+
open: !!open,
|
|
240
|
+
...floating
|
|
241
|
+
};
|
|
242
|
+
}, [open, size, floating, JSON.stringify(middlewareData.arrow || null), JSON.stringify(middlewareData.transformOrigin || null)]),
|
|
227
243
|
children: /* @__PURE__ */jsx(FloatingOverrideContext.Provider, {
|
|
228
244
|
value: null,
|
|
229
245
|
children
|
|
230
246
|
})
|
|
231
247
|
});
|
|
232
248
|
}
|
|
233
|
-
const PopperAnchor = YStack.styleable(function (props, forwardedRef) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
// web handles this onMouseEnter below so it can support multiple targets + hovering
|
|
270
|
-
shouldHandleInHover ? void 0 : safeSetReference);
|
|
271
|
-
return /* @__PURE__ */jsx(GuiView, {
|
|
272
|
-
...rest,
|
|
273
|
-
...refProps,
|
|
274
|
-
ref: composedRefs,
|
|
275
|
-
...(shouldHandleInHover && {
|
|
276
|
-
// scoped poppers with multiple triggers: set the reference on
|
|
277
|
-
// mouseEnter so floating-ui positions relative to the hovered
|
|
278
|
-
// trigger, not the last one rendered.
|
|
279
|
-
//
|
|
280
|
-
// flushSync is critical here: without it, setReference batches
|
|
281
|
-
// with React's async state updates and the arrow/content position
|
|
282
|
-
// computes against the OLD reference element. this causes the
|
|
283
|
-
// arrow to flash at x=0 (top-left) during trigger switches.
|
|
284
|
-
// flushSync forces synchronous commit so update() below reads
|
|
285
|
-
// the correct reference element immediately.
|
|
286
|
-
onMouseEnter: e => {
|
|
287
|
-
const el = e.currentTarget ?? ref.current;
|
|
288
|
-
if (el instanceof HTMLElement) {
|
|
289
|
-
if (flushSync(() => refs.setReference(el)), update(), !refProps) return;
|
|
290
|
-
refProps.onPointerEnter?.(e), context.onHoverReference?.(e.nativeEvent);
|
|
291
|
-
}
|
|
292
|
-
},
|
|
293
|
-
onMouseLeave: e => {
|
|
294
|
-
context.onLeaveReference?.(), refProps?.onMouseLeave?.(e);
|
|
295
|
-
}
|
|
296
|
-
})
|
|
249
|
+
const PopperAnchor = YStack.styleable(function PopperAnchor2(props, forwardedRef) {
|
|
250
|
+
const {
|
|
251
|
+
virtualRef,
|
|
252
|
+
scope,
|
|
253
|
+
...rest
|
|
254
|
+
} = props;
|
|
255
|
+
const context = usePopperContextSlow(scope);
|
|
256
|
+
const {
|
|
257
|
+
getReferenceProps,
|
|
258
|
+
refs,
|
|
259
|
+
update
|
|
260
|
+
} = context;
|
|
261
|
+
const ref = React.useRef(null);
|
|
262
|
+
const triggerId = React.useId();
|
|
263
|
+
React.useEffect(() => {
|
|
264
|
+
if (!scope || !context.triggerElements || !ref.current) return;
|
|
265
|
+
if (!(ref.current instanceof Element)) return;
|
|
266
|
+
const el = ref.current;
|
|
267
|
+
context.triggerElements.add(triggerId, el);
|
|
268
|
+
return () => {
|
|
269
|
+
context.triggerElements?.delete(triggerId);
|
|
270
|
+
};
|
|
271
|
+
}, [scope, triggerId, context.triggerElements]);
|
|
272
|
+
React.useEffect(() => {
|
|
273
|
+
if (virtualRef) {
|
|
274
|
+
refs.setReference(virtualRef.current);
|
|
275
|
+
update();
|
|
276
|
+
}
|
|
277
|
+
}, [virtualRef]);
|
|
278
|
+
const refProps = getReferenceProps?.({
|
|
279
|
+
...rest,
|
|
280
|
+
ref
|
|
281
|
+
}) || null;
|
|
282
|
+
const safeSetReference = React.useCallback(node => {
|
|
283
|
+
startTransition(() => {
|
|
284
|
+
refs.setReference(node);
|
|
297
285
|
});
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
286
|
+
},
|
|
287
|
+
// it was refs.setRefernce but its stable and refs is undefined on server
|
|
288
|
+
[refs]);
|
|
289
|
+
const shouldHandleInHover = isWeb && scope;
|
|
290
|
+
const composedRefs = useComposedRefs(forwardedRef, ref,
|
|
291
|
+
// web handles this onMouseEnter below so it can support multiple targets + hovering
|
|
292
|
+
shouldHandleInHover ? void 0 : safeSetReference);
|
|
293
|
+
return /* @__PURE__ */jsx(GuiView, {
|
|
294
|
+
...rest,
|
|
295
|
+
...refProps,
|
|
296
|
+
ref: composedRefs,
|
|
297
|
+
...(shouldHandleInHover && {
|
|
298
|
+
onMouseEnter: e => {
|
|
299
|
+
const el = e.currentTarget ?? ref.current;
|
|
300
|
+
if (el instanceof HTMLElement) {
|
|
301
|
+
flushSync(() => refs.setReference(el));
|
|
302
|
+
update();
|
|
303
|
+
if (!refProps) return;
|
|
304
|
+
refProps.onPointerEnter?.(e);
|
|
305
|
+
context.onHoverReference?.(e.nativeEvent);
|
|
306
|
+
}
|
|
304
307
|
},
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
308
|
+
onMouseLeave: e => {
|
|
309
|
+
context.onLeaveReference?.();
|
|
310
|
+
refProps?.onMouseLeave?.(e);
|
|
311
|
+
}
|
|
312
|
+
})
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
const PopperContentFrame = styled(YStack, {
|
|
316
|
+
name: "PopperContent",
|
|
317
|
+
variants: {
|
|
318
|
+
unstyled: {
|
|
319
|
+
true: {}
|
|
320
|
+
},
|
|
321
|
+
size: {
|
|
322
|
+
"...size": (val, {
|
|
323
|
+
tokens
|
|
324
|
+
}) => {
|
|
325
|
+
return {
|
|
309
326
|
padding: tokens.space[val],
|
|
310
327
|
borderRadius: tokens.radius[val]
|
|
311
|
-
}
|
|
328
|
+
};
|
|
312
329
|
}
|
|
313
330
|
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
const PopperContent = React.forwardRef(function PopperContent2(props, forwardedRef) {
|
|
334
|
+
const {
|
|
335
|
+
scope,
|
|
336
|
+
animatePosition,
|
|
337
|
+
enableAnimationForPositionChange,
|
|
338
|
+
children,
|
|
339
|
+
passThrough,
|
|
340
|
+
unstyled,
|
|
341
|
+
...rest
|
|
342
|
+
} = props;
|
|
343
|
+
const animatePos = animatePosition ?? enableAnimationForPositionChange;
|
|
344
|
+
const context = usePopperContext(scope);
|
|
345
|
+
const {
|
|
346
|
+
strategy,
|
|
347
|
+
placement,
|
|
348
|
+
refs,
|
|
349
|
+
x,
|
|
350
|
+
y,
|
|
351
|
+
getFloatingProps,
|
|
352
|
+
size,
|
|
353
|
+
isPositioned,
|
|
354
|
+
transformOrigin,
|
|
355
|
+
update
|
|
356
|
+
} = context;
|
|
357
|
+
const updateRef = React.useRef(update);
|
|
358
|
+
updateRef.current = update;
|
|
359
|
+
const lastNodeRef = React.useRef(null);
|
|
360
|
+
const safeSetFloating = React.useCallback(node => {
|
|
361
|
+
const isNewNode = node !== lastNodeRef.current;
|
|
362
|
+
if (node) {
|
|
363
|
+
lastNodeRef.current = node;
|
|
364
|
+
refs.setFloating(node);
|
|
365
|
+
if (!isNewNode) updateRef.current?.();
|
|
366
|
+
}
|
|
367
|
+
}, [refs.setFloating]);
|
|
368
|
+
React.useEffect(() => {
|
|
369
|
+
return () => {
|
|
347
370
|
const ourNode = lastNodeRef.current;
|
|
348
|
-
ourNode && refs.floating.current === ourNode
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
371
|
+
if (ourNode && refs.floating.current === ourNode) refs.setFloating(null);
|
|
372
|
+
lastNodeRef.current = null;
|
|
373
|
+
};
|
|
374
|
+
}, []);
|
|
375
|
+
const contentRefs = useComposedRefs(safeSetFloating, forwardedRef);
|
|
376
|
+
const [needsMeasure, setNeedsMeasure] = React.useState(animatePos);
|
|
377
|
+
useIsomorphicLayoutEffect(() => {
|
|
378
|
+
if (needsMeasure && x && y) setNeedsMeasure(false);
|
|
379
|
+
}, [needsMeasure, animatePos, x, y]);
|
|
380
|
+
const hasBeenPositioned = React.useRef(false);
|
|
381
|
+
const lastGoodPosition = React.useRef({
|
|
382
|
+
x: 0,
|
|
383
|
+
y: 0
|
|
384
|
+
});
|
|
385
|
+
if (x !== 0 || y !== 0) {
|
|
386
|
+
lastGoodPosition.current = {
|
|
361
387
|
x,
|
|
362
388
|
y
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
389
|
+
};
|
|
390
|
+
if (isPositioned) hasBeenPositioned.current = true;
|
|
391
|
+
}
|
|
392
|
+
const brieflyZero = hasBeenPositioned.current && x === 0 && y === 0;
|
|
393
|
+
const effectiveX = brieflyZero ? lastGoodPosition.current.x : x;
|
|
394
|
+
const effectiveY = brieflyZero ? lastGoodPosition.current.y : y;
|
|
395
|
+
const hide = !hasBeenPositioned.current && effectiveX === 0 && effectiveY === 0;
|
|
396
|
+
const disableAnimationProp = animatePos === "even-when-repositioning" ? needsMeasure : !hasBeenPositioned.current && !isPositioned || needsMeasure;
|
|
397
|
+
const [disableAnimation, setDisableAnimation] = React.useState(disableAnimationProp);
|
|
398
|
+
React.useEffect(() => {
|
|
399
|
+
setDisableAnimation(disableAnimationProp);
|
|
400
|
+
}, [disableAnimationProp]);
|
|
401
|
+
const frameProps = {
|
|
402
|
+
ref: contentRefs,
|
|
403
|
+
...(hide ? {} : {
|
|
404
|
+
x: effectiveX || 0,
|
|
405
|
+
y: effectiveY || 0
|
|
406
|
+
}),
|
|
407
|
+
top: 0,
|
|
408
|
+
left: 0,
|
|
409
|
+
position: strategy,
|
|
410
|
+
opacity: hide ? 0 : 1,
|
|
411
|
+
...(animatePos && {
|
|
412
|
+
transition: rest.transition,
|
|
413
|
+
animateOnly: disableAnimation ? [] : rest.animateOnly,
|
|
414
|
+
animatePresence: false
|
|
415
|
+
})
|
|
416
|
+
};
|
|
417
|
+
const {
|
|
418
|
+
style,
|
|
419
|
+
...floatingProps
|
|
420
|
+
} = getFloatingProps ? getFloatingProps(frameProps) : frameProps;
|
|
421
|
+
const transformOriginStyle = isWeb && transformOrigin ? {
|
|
422
|
+
transformOrigin: `${transformOrigin.x} ${transformOrigin.y}`
|
|
423
|
+
} : void 0;
|
|
424
|
+
return /* @__PURE__ */jsx(LayoutMeasurementController, {
|
|
425
|
+
disable: !context.open,
|
|
426
|
+
children: /* @__PURE__ */jsx(GuiView, {
|
|
427
|
+
passThrough,
|
|
428
|
+
ref: contentRefs,
|
|
429
|
+
direction: rest.direction,
|
|
430
|
+
...(passThrough ? null : floatingProps),
|
|
431
|
+
...(!passThrough && animatePos && {
|
|
432
|
+
"data-popper-animate-position": "true"
|
|
433
|
+
}),
|
|
434
|
+
children: /* @__PURE__ */jsx(PopperContentFrame, {
|
|
403
435
|
passThrough,
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
436
|
+
unstyled,
|
|
437
|
+
...(!passThrough && {
|
|
438
|
+
"data-placement": placement,
|
|
439
|
+
"data-strategy": strategy,
|
|
440
|
+
size,
|
|
441
|
+
...style,
|
|
442
|
+
...transformOriginStyle,
|
|
443
|
+
...rest
|
|
409
444
|
}),
|
|
410
|
-
children
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
})
|
|
424
|
-
});
|
|
425
|
-
}),
|
|
426
|
-
PopperArrowFrame = styled(YStack, {
|
|
427
|
-
name: "PopperArrow",
|
|
428
|
-
variants: {
|
|
429
|
-
unstyled: {
|
|
430
|
-
false: {
|
|
431
|
-
borderColor: "$borderColor",
|
|
432
|
-
backgroundColor: "$background",
|
|
433
|
-
position: "relative"
|
|
434
|
-
}
|
|
445
|
+
children
|
|
446
|
+
}, "popper-content-frame")
|
|
447
|
+
})
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
const PopperArrowFrame = styled(YStack, {
|
|
451
|
+
name: "PopperArrow",
|
|
452
|
+
variants: {
|
|
453
|
+
unstyled: {
|
|
454
|
+
false: {
|
|
455
|
+
borderColor: "$borderColor",
|
|
456
|
+
backgroundColor: "$background",
|
|
457
|
+
position: "relative"
|
|
435
458
|
}
|
|
436
|
-
},
|
|
437
|
-
defaultVariants: {
|
|
438
|
-
unstyled: process.env.HANZO_GUI_HEADLESS === "1"
|
|
439
459
|
}
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
460
|
+
},
|
|
461
|
+
defaultVariants: {
|
|
462
|
+
unstyled: process.env.GUI_HEADLESS === "1"
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
const PopperArrowOuterFrame = styled(YStack, {
|
|
466
|
+
name: "PopperArrowOuter",
|
|
467
|
+
variants: {
|
|
468
|
+
unstyled: {
|
|
469
|
+
false: {
|
|
470
|
+
position: "absolute",
|
|
471
|
+
zIndex: 1e6,
|
|
472
|
+
pointerEvents: "none",
|
|
473
|
+
overflow: "hidden",
|
|
474
|
+
alignItems: "center",
|
|
475
|
+
justifyContent: "center"
|
|
453
476
|
}
|
|
454
|
-
},
|
|
455
|
-
defaultVariants: {
|
|
456
|
-
unstyled: process.env.HANZO_GUI_HEADLESS === "1"
|
|
457
477
|
}
|
|
458
|
-
}),
|
|
459
|
-
opposites = {
|
|
460
|
-
top: "bottom",
|
|
461
|
-
right: "left",
|
|
462
|
-
bottom: "top",
|
|
463
|
-
left: "right"
|
|
464
478
|
},
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
479
|
+
defaultVariants: {
|
|
480
|
+
unstyled: process.env.GUI_HEADLESS === "1"
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
const opposites = {
|
|
484
|
+
top: "bottom",
|
|
485
|
+
right: "left",
|
|
486
|
+
bottom: "top",
|
|
487
|
+
left: "right"
|
|
488
|
+
};
|
|
489
|
+
const PopperArrow = React.forwardRef(function PopperArrow2(propsIn, forwardedRef) {
|
|
490
|
+
const {
|
|
491
|
+
scope,
|
|
492
|
+
animatePosition,
|
|
493
|
+
transition,
|
|
494
|
+
...rest
|
|
495
|
+
} = propsIn;
|
|
496
|
+
const {
|
|
497
|
+
offset,
|
|
498
|
+
size: sizeProp,
|
|
499
|
+
borderWidth = 0,
|
|
500
|
+
...arrowProps
|
|
501
|
+
} = rest;
|
|
502
|
+
const context = usePopperContext(scope);
|
|
503
|
+
const sizeVal = typeof sizeProp === "number" ? sizeProp : getVariableValue(getSpace(sizeProp ?? context.size, {
|
|
504
|
+
shift: -2,
|
|
505
|
+
bounds: [2]
|
|
506
|
+
}));
|
|
507
|
+
const size = Math.max(0, +sizeVal);
|
|
508
|
+
const {
|
|
509
|
+
placement
|
|
510
|
+
} = context;
|
|
511
|
+
const refs = useComposedRefs(context.arrowRef, forwardedRef);
|
|
512
|
+
const x = context.arrowStyle?.x || 0;
|
|
513
|
+
const y = context.arrowStyle?.y || 0;
|
|
514
|
+
const arrowPositioned = context.arrowStyle != null;
|
|
515
|
+
const primaryPlacement = placement ? placement.split("-")[0] : "top";
|
|
516
|
+
const arrowStyle = {
|
|
517
|
+
x,
|
|
518
|
+
y,
|
|
519
|
+
width: size,
|
|
520
|
+
height: size
|
|
521
|
+
};
|
|
522
|
+
const innerArrowStyle = {};
|
|
523
|
+
const isVertical = primaryPlacement === "bottom" || primaryPlacement === "top";
|
|
524
|
+
if (primaryPlacement) {
|
|
525
|
+
arrowStyle[isVertical ? "width" : "height"] = size * 2;
|
|
526
|
+
const oppSide = opposites[primaryPlacement];
|
|
527
|
+
if (oppSide) {
|
|
528
|
+
arrowStyle[oppSide] = -size;
|
|
529
|
+
innerArrowStyle[oppSide] = size / 2;
|
|
506
530
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
531
|
+
if (oppSide === "top" || oppSide === "bottom") arrowStyle.left = 0;
|
|
532
|
+
if (oppSide === "left" || oppSide === "right") arrowStyle.top = 0;
|
|
533
|
+
useIsomorphicLayoutEffect(() => {
|
|
534
|
+
context.onArrowSize?.(size);
|
|
535
|
+
}, [size, context.onArrowSize]);
|
|
536
|
+
}
|
|
537
|
+
return /* @__PURE__ */jsx(PopperArrowOuterFrame, {
|
|
538
|
+
ref: refs,
|
|
539
|
+
...arrowStyle,
|
|
540
|
+
...(!arrowPositioned && {
|
|
541
|
+
opacity: 0
|
|
542
|
+
}),
|
|
543
|
+
...(animatePosition && {
|
|
544
|
+
transition,
|
|
545
|
+
animateOnly: ["transform"],
|
|
546
|
+
animatePresence: false
|
|
547
|
+
}),
|
|
548
|
+
children: /* @__PURE__ */jsx(PopperArrowFrame, {
|
|
549
|
+
width: size,
|
|
550
|
+
height: size,
|
|
551
|
+
...arrowProps,
|
|
552
|
+
...innerArrowStyle,
|
|
553
|
+
rotate: "45deg",
|
|
554
|
+
...(primaryPlacement === "bottom" && {
|
|
555
|
+
borderLeftWidth: borderWidth,
|
|
556
|
+
borderTopWidth: borderWidth
|
|
512
557
|
}),
|
|
513
|
-
...(
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
animatePresence: !1
|
|
558
|
+
...(primaryPlacement === "top" && {
|
|
559
|
+
borderBottomWidth: borderWidth,
|
|
560
|
+
borderRightWidth: borderWidth
|
|
517
561
|
}),
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
borderLeftWidth: borderWidth,
|
|
526
|
-
borderTopWidth: borderWidth
|
|
527
|
-
}),
|
|
528
|
-
...(primaryPlacement === "top" && {
|
|
529
|
-
borderBottomWidth: borderWidth,
|
|
530
|
-
borderRightWidth: borderWidth
|
|
531
|
-
}),
|
|
532
|
-
...(primaryPlacement === "right" && {
|
|
533
|
-
borderLeftWidth: borderWidth,
|
|
534
|
-
borderBottomWidth: borderWidth
|
|
535
|
-
}),
|
|
536
|
-
...(primaryPlacement === "left" && {
|
|
537
|
-
borderTopWidth: borderWidth,
|
|
538
|
-
borderRightWidth: borderWidth
|
|
539
|
-
})
|
|
562
|
+
...(primaryPlacement === "right" && {
|
|
563
|
+
borderLeftWidth: borderWidth,
|
|
564
|
+
borderBottomWidth: borderWidth
|
|
565
|
+
}),
|
|
566
|
+
...(primaryPlacement === "left" && {
|
|
567
|
+
borderTopWidth: borderWidth,
|
|
568
|
+
borderRightWidth: borderWidth
|
|
540
569
|
})
|
|
541
|
-
})
|
|
570
|
+
})
|
|
542
571
|
});
|
|
572
|
+
});
|
|
543
573
|
export { Popper, PopperAnchor, PopperArrow, PopperArrowFrame, PopperContent, PopperContentFrame, PopperContextFast, PopperContextSlow, PopperPositionContext, PopperProvider, PopperProviderFast, PopperProviderSlow, setupPopper, usePopperContext, usePopperContextSlow };
|
|
544
574
|
//# sourceMappingURL=Popper.mjs.map
|