@hanzogui/popper 2.0.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 +21 -0
- package/dist/cjs/Popper.cjs +593 -0
- package/dist/cjs/Popper.native.js +632 -0
- package/dist/cjs/Popper.native.js.map +1 -0
- package/dist/cjs/index.cjs +18 -0
- package/dist/cjs/index.native.js +21 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/esm/Popper.mjs +544 -0
- package/dist/esm/Popper.mjs.map +1 -0
- package/dist/esm/Popper.native.js +581 -0
- package/dist/esm/Popper.native.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +2 -0
- package/dist/esm/index.native.js.map +1 -0
- package/dist/jsx/Popper.mjs +544 -0
- package/dist/jsx/Popper.mjs.map +1 -0
- package/dist/jsx/Popper.native.js +632 -0
- package/dist/jsx/Popper.native.js.map +1 -0
- package/dist/jsx/index.js +2 -0
- package/dist/jsx/index.js.map +1 -0
- package/dist/jsx/index.mjs +2 -0
- package/dist/jsx/index.mjs.map +1 -0
- package/dist/jsx/index.native.js +21 -0
- package/dist/jsx/index.native.js.map +1 -0
- package/package.json +58 -0
- package/src/Popper.tsx +1022 -0
- package/src/index.ts +1 -0
- package/types/Popper.d.ts +183 -0
- package/types/index.d.ts +2 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nate Wienert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,593 @@
|
|
|
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
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var Popper_exports = {};
|
|
33
|
+
__export(Popper_exports, {
|
|
34
|
+
Popper: () => Popper,
|
|
35
|
+
PopperAnchor: () => PopperAnchor,
|
|
36
|
+
PopperArrow: () => PopperArrow,
|
|
37
|
+
PopperArrowFrame: () => PopperArrowFrame,
|
|
38
|
+
PopperContent: () => PopperContent,
|
|
39
|
+
PopperContentFrame: () => PopperContentFrame,
|
|
40
|
+
PopperContextFast: () => PopperContextFast,
|
|
41
|
+
PopperContextSlow: () => PopperContextSlow,
|
|
42
|
+
PopperPositionContext: () => PopperPositionContext,
|
|
43
|
+
PopperProvider: () => PopperProvider,
|
|
44
|
+
PopperProviderFast: () => PopperProviderFast,
|
|
45
|
+
PopperProviderSlow: () => PopperProviderSlow,
|
|
46
|
+
setupPopper: () => setupPopper,
|
|
47
|
+
usePopperContext: () => usePopperContext,
|
|
48
|
+
usePopperContextSlow: () => usePopperContextSlow
|
|
49
|
+
});
|
|
50
|
+
module.exports = __toCommonJS(Popper_exports);
|
|
51
|
+
var import_react_dom = require("react-dom"),
|
|
52
|
+
import_gui_compose_refs = require("@hanzo/gui-compose-refs"),
|
|
53
|
+
import_gui_constants = require("@hanzo/gui-constants"),
|
|
54
|
+
import_gui_core = require("@hanzo/gui-core"),
|
|
55
|
+
import_gui_floating = require("@hanzo/gui-floating"),
|
|
56
|
+
import_gui_floating2 = require("@hanzo/gui-floating"),
|
|
57
|
+
import_gui_get_token = require("@hanzo/gui-get-token"),
|
|
58
|
+
import_gui_stacks = require("@hanzo/gui-stacks"),
|
|
59
|
+
import_gui_start_transition = require("@hanzo/gui-start-transition"),
|
|
60
|
+
React = __toESM(require("react"), 1),
|
|
61
|
+
import_react_native = require("react-native-web"),
|
|
62
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
63
|
+
const PopperContextFast = (0, import_gui_core.createStyledContext)(
|
|
64
|
+
// since we always provide this we can avoid setting here
|
|
65
|
+
{}, "Popper__"),
|
|
66
|
+
PopperPositionContext = import_gui_core.createStyledContext,
|
|
67
|
+
{
|
|
68
|
+
useStyledContext: usePopperContext,
|
|
69
|
+
Provider: PopperProviderFast
|
|
70
|
+
} = PopperContextFast,
|
|
71
|
+
PopperContextSlow = (0, import_gui_core.createStyledContext)(
|
|
72
|
+
// since we always provide this we can avoid setting here
|
|
73
|
+
{}, "PopperSlow__"),
|
|
74
|
+
{
|
|
75
|
+
useStyledContext: usePopperContextSlow,
|
|
76
|
+
Provider: PopperProviderSlow
|
|
77
|
+
} = PopperContextSlow,
|
|
78
|
+
PopperProvider = ({
|
|
79
|
+
scope,
|
|
80
|
+
children,
|
|
81
|
+
...context
|
|
82
|
+
}) => {
|
|
83
|
+
const fns = React.useRef(context);
|
|
84
|
+
fns.current = context;
|
|
85
|
+
const [slowContext] = React.useState(() => ({
|
|
86
|
+
refs: context.refs,
|
|
87
|
+
triggerElements: context.triggerElements,
|
|
88
|
+
update(...a) {
|
|
89
|
+
fns.current.update(...a);
|
|
90
|
+
},
|
|
91
|
+
getReferenceProps(p) {
|
|
92
|
+
return fns.current.getReferenceProps?.(p);
|
|
93
|
+
},
|
|
94
|
+
onHoverReference(e) {
|
|
95
|
+
fns.current.onHoverReference?.(e);
|
|
96
|
+
},
|
|
97
|
+
onLeaveReference() {
|
|
98
|
+
fns.current.onLeaveReference?.();
|
|
99
|
+
}
|
|
100
|
+
}));
|
|
101
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperProviderFast, {
|
|
102
|
+
scope,
|
|
103
|
+
...context,
|
|
104
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperProviderSlow, {
|
|
105
|
+
scope,
|
|
106
|
+
...slowContext,
|
|
107
|
+
children
|
|
108
|
+
})
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
checkFloating = void 0,
|
|
112
|
+
setupOptions = {};
|
|
113
|
+
function setupPopper(options) {
|
|
114
|
+
Object.assign(setupOptions, options);
|
|
115
|
+
}
|
|
116
|
+
function getSideAndAlignFromPlacement(placement) {
|
|
117
|
+
const [side, align = "center"] = placement.split("-");
|
|
118
|
+
return [side, align];
|
|
119
|
+
}
|
|
120
|
+
const transformOriginMiddleware = options => ({
|
|
121
|
+
name: "transformOrigin",
|
|
122
|
+
options,
|
|
123
|
+
fn(data) {
|
|
124
|
+
const {
|
|
125
|
+
placement,
|
|
126
|
+
rects,
|
|
127
|
+
middlewareData
|
|
128
|
+
} = data,
|
|
129
|
+
isArrowHidden = middlewareData.arrow?.centerOffset !== 0,
|
|
130
|
+
arrowWidth = isArrowHidden ? 0 : options.arrowWidth,
|
|
131
|
+
arrowHeight = isArrowHidden ? 0 : options.arrowHeight,
|
|
132
|
+
[placedSide, placedAlign] = getSideAndAlignFromPlacement(placement),
|
|
133
|
+
noArrowAlign = {
|
|
134
|
+
start: "0%",
|
|
135
|
+
center: "50%",
|
|
136
|
+
end: "100%"
|
|
137
|
+
}[placedAlign],
|
|
138
|
+
arrowXCenter = (middlewareData.arrow?.x ?? 0) + arrowWidth / 2,
|
|
139
|
+
arrowYCenter = (middlewareData.arrow?.y ?? 0) + arrowHeight / 2;
|
|
140
|
+
let x = "",
|
|
141
|
+
y = "";
|
|
142
|
+
return placedSide === "bottom" ? (x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`, y = `${-arrowHeight}px`) : placedSide === "top" ? (x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`, y = `${rects.floating.height + arrowHeight}px`) : placedSide === "right" ? (x = `${-arrowHeight}px`, y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`) : placedSide === "left" && (x = `${rects.floating.width + arrowHeight}px`, y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`), {
|
|
143
|
+
data: {
|
|
144
|
+
x,
|
|
145
|
+
y
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
function tamaguiAutoUpdate(reference, floating, update) {
|
|
151
|
+
update();
|
|
152
|
+
let rafId = requestAnimationFrame(() => {
|
|
153
|
+
update(), rafId = 0;
|
|
154
|
+
});
|
|
155
|
+
const cleanups = [() => {
|
|
156
|
+
rafId && cancelAnimationFrame(rafId);
|
|
157
|
+
}];
|
|
158
|
+
reference instanceof HTMLElement && cleanups.push((0, import_gui_core.registerLayoutNode)(reference, update));
|
|
159
|
+
const ancestors = [...(reference instanceof Element ? (0, import_gui_floating2.getOverflowAncestors)(reference) : []), ...(0, import_gui_floating2.getOverflowAncestors)(floating)],
|
|
160
|
+
uniqueAncestors = [...new Set(ancestors)];
|
|
161
|
+
for (const ancestor of uniqueAncestors) ancestor.addEventListener("scroll", update, {
|
|
162
|
+
passive: !0
|
|
163
|
+
});
|
|
164
|
+
return window.addEventListener("resize", update), cleanups.push(() => {
|
|
165
|
+
for (const ancestor of uniqueAncestors) ancestor.removeEventListener("scroll", update);
|
|
166
|
+
window.removeEventListener("resize", update);
|
|
167
|
+
}), () => cleanups.forEach(fn => fn());
|
|
168
|
+
}
|
|
169
|
+
function Popper(props) {
|
|
170
|
+
const {
|
|
171
|
+
children,
|
|
172
|
+
size,
|
|
173
|
+
strategy = "absolute",
|
|
174
|
+
placement = "bottom",
|
|
175
|
+
stayInFrame,
|
|
176
|
+
allowFlip,
|
|
177
|
+
offset,
|
|
178
|
+
disableRTL,
|
|
179
|
+
resize,
|
|
180
|
+
passThrough,
|
|
181
|
+
open,
|
|
182
|
+
scope
|
|
183
|
+
} = props,
|
|
184
|
+
[arrowEl, setArrow] = React.useState(null),
|
|
185
|
+
[arrowSize, setArrowSize] = React.useState(0),
|
|
186
|
+
offsetOptions = offset ?? arrowSize,
|
|
187
|
+
floatingStyle = React.useRef({}),
|
|
188
|
+
isOpen = passThrough ? !1 : open ?? !0,
|
|
189
|
+
middlewareRef = React.useRef([]);
|
|
190
|
+
isOpen && (middlewareRef.current = [
|
|
191
|
+
// order matters: offset first, then flip, then shift, then arrow
|
|
192
|
+
typeof offsetOptions < "u" ? (0, import_gui_floating2.offset)(offsetOptions) : null, allowFlip ? (0, import_gui_floating2.flip)(typeof allowFlip == "boolean" ? {} : allowFlip) : null,
|
|
193
|
+
// NOTE: shift's axis terminology is reversed vs flip/offset:
|
|
194
|
+
// for top/bottom placements: mainAxis = horizontal, crossAxis = vertical
|
|
195
|
+
// for left/right placements: mainAxis = vertical, crossAxis = horizontal
|
|
196
|
+
// default to horizontal shift only (mainAxis: true, crossAxis: false)
|
|
197
|
+
stayInFrame ? (0, import_gui_floating2.shift)({
|
|
198
|
+
padding: 10,
|
|
199
|
+
mainAxis: !0,
|
|
200
|
+
crossAxis: !1,
|
|
201
|
+
...(typeof stayInFrame == "object" ? stayInFrame : null)
|
|
202
|
+
}) : null, arrowEl ? (0, import_gui_floating2.arrow)({
|
|
203
|
+
element: arrowEl
|
|
204
|
+
}) : null, checkFloating, resize ? (0, import_gui_floating2.size)({
|
|
205
|
+
padding: typeof stayInFrame == "object" ? stayInFrame.padding : 10,
|
|
206
|
+
apply({
|
|
207
|
+
availableHeight,
|
|
208
|
+
availableWidth
|
|
209
|
+
}) {
|
|
210
|
+
if (passThrough) return;
|
|
211
|
+
Object.assign(floatingStyle.current, {
|
|
212
|
+
maxHeight: `${availableHeight}px`,
|
|
213
|
+
maxWidth: `${availableWidth}px`
|
|
214
|
+
});
|
|
215
|
+
const floatingChild = floating.refs.floating.current?.firstChild;
|
|
216
|
+
floatingChild && floatingChild instanceof HTMLElement && Object.assign(floatingChild.style, floatingStyle.current);
|
|
217
|
+
},
|
|
218
|
+
...(typeof resize == "object" && resize)
|
|
219
|
+
}) : null, (0, import_gui_floating2.size)({
|
|
220
|
+
apply({
|
|
221
|
+
elements,
|
|
222
|
+
rects,
|
|
223
|
+
availableWidth,
|
|
224
|
+
availableHeight
|
|
225
|
+
}) {
|
|
226
|
+
const {
|
|
227
|
+
width: anchorWidth,
|
|
228
|
+
height: anchorHeight
|
|
229
|
+
} = rects.reference,
|
|
230
|
+
contentStyle = elements.floating.style;
|
|
231
|
+
contentStyle.setProperty("--tamagui-popper-available-width", `${availableWidth}px`), contentStyle.setProperty("--tamagui-popper-available-height", `${availableHeight}px`), contentStyle.setProperty("--tamagui-popper-anchor-width", `${anchorWidth}px`), contentStyle.setProperty("--tamagui-popper-anchor-height", `${anchorHeight}px`);
|
|
232
|
+
}
|
|
233
|
+
}), transformOriginMiddleware({
|
|
234
|
+
arrowHeight: arrowSize,
|
|
235
|
+
arrowWidth: arrowSize
|
|
236
|
+
})].filter(Boolean));
|
|
237
|
+
let floating = (0, import_gui_floating2.useFloating)({
|
|
238
|
+
open: isOpen,
|
|
239
|
+
strategy,
|
|
240
|
+
placement,
|
|
241
|
+
sameScrollView: !1,
|
|
242
|
+
// this only takes effect on native
|
|
243
|
+
whileElementsMounted: isOpen ? tamaguiAutoUpdate : void 0,
|
|
244
|
+
platform: disableRTL ?? setupOptions.disableRTL ? {
|
|
245
|
+
...import_gui_floating2.platform,
|
|
246
|
+
isRTL(element) {
|
|
247
|
+
return !1;
|
|
248
|
+
}
|
|
249
|
+
} : import_gui_floating2.platform,
|
|
250
|
+
middleware: middlewareRef.current
|
|
251
|
+
});
|
|
252
|
+
floating = React.useMemo(() => {
|
|
253
|
+
const og = floating.getFloatingProps;
|
|
254
|
+
return resize && og && (floating.getFloatingProps = props2 => og({
|
|
255
|
+
...props2,
|
|
256
|
+
style: {
|
|
257
|
+
...props2.style,
|
|
258
|
+
...floatingStyle.current
|
|
259
|
+
}
|
|
260
|
+
})), floating;
|
|
261
|
+
}, [floating, resize ? JSON.stringify(resize) : null]);
|
|
262
|
+
const {
|
|
263
|
+
middlewareData
|
|
264
|
+
} = floating,
|
|
265
|
+
popperContext = React.useMemo(() => ({
|
|
266
|
+
size,
|
|
267
|
+
arrowRef: setArrow,
|
|
268
|
+
arrowStyle: middlewareData.arrow,
|
|
269
|
+
onArrowSize: setArrowSize,
|
|
270
|
+
hasFloating: middlewareData.checkFloating?.hasFloating,
|
|
271
|
+
transformOrigin: middlewareData.transformOrigin,
|
|
272
|
+
open: !!open,
|
|
273
|
+
...floating
|
|
274
|
+
}), [open, size, floating, JSON.stringify(middlewareData.arrow || null), JSON.stringify(middlewareData.transformOrigin || null)]);
|
|
275
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperProvider, {
|
|
276
|
+
scope,
|
|
277
|
+
...popperContext,
|
|
278
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_floating.FloatingOverrideContext.Provider, {
|
|
279
|
+
value: null,
|
|
280
|
+
children
|
|
281
|
+
})
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
const PopperAnchor = import_gui_stacks.YStack.styleable(function (props, forwardedRef) {
|
|
285
|
+
const {
|
|
286
|
+
virtualRef,
|
|
287
|
+
scope,
|
|
288
|
+
...rest
|
|
289
|
+
} = props,
|
|
290
|
+
context = usePopperContextSlow(scope),
|
|
291
|
+
{
|
|
292
|
+
getReferenceProps,
|
|
293
|
+
refs,
|
|
294
|
+
update
|
|
295
|
+
} = context,
|
|
296
|
+
ref = React.useRef(null),
|
|
297
|
+
triggerId = React.useId();
|
|
298
|
+
React.useEffect(() => {
|
|
299
|
+
if (!scope || !context.triggerElements || !ref.current || !(ref.current instanceof Element)) return;
|
|
300
|
+
const el = ref.current;
|
|
301
|
+
return context.triggerElements.add(triggerId, el), () => {
|
|
302
|
+
context.triggerElements?.delete(triggerId);
|
|
303
|
+
};
|
|
304
|
+
}, [scope, triggerId, context.triggerElements]), React.useEffect(() => {
|
|
305
|
+
virtualRef && (refs.setReference(virtualRef.current), update());
|
|
306
|
+
}, [virtualRef]);
|
|
307
|
+
const refProps = getReferenceProps?.({
|
|
308
|
+
...rest,
|
|
309
|
+
ref
|
|
310
|
+
}) || null,
|
|
311
|
+
safeSetReference = React.useCallback(node => {
|
|
312
|
+
(0, import_gui_start_transition.startTransition)(() => {
|
|
313
|
+
refs.setReference(node);
|
|
314
|
+
});
|
|
315
|
+
},
|
|
316
|
+
// it was refs.setRefernce but its stable and refs is undefined on server
|
|
317
|
+
[refs]),
|
|
318
|
+
shouldHandleInHover = import_gui_constants.isWeb && scope,
|
|
319
|
+
composedRefs = (0, import_gui_compose_refs.useComposedRefs)(forwardedRef, ref,
|
|
320
|
+
// web handles this onMouseEnter below so it can support multiple targets + hovering
|
|
321
|
+
shouldHandleInHover ? void 0 : safeSetReference);
|
|
322
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_core.View, {
|
|
323
|
+
...rest,
|
|
324
|
+
...refProps,
|
|
325
|
+
ref: composedRefs,
|
|
326
|
+
...(shouldHandleInHover && {
|
|
327
|
+
// scoped poppers with multiple triggers: set the reference on
|
|
328
|
+
// mouseEnter so floating-ui positions relative to the hovered
|
|
329
|
+
// trigger, not the last one rendered.
|
|
330
|
+
//
|
|
331
|
+
// flushSync is critical here: without it, setReference batches
|
|
332
|
+
// with React's async state updates and the arrow/content position
|
|
333
|
+
// computes against the OLD reference element. this causes the
|
|
334
|
+
// arrow to flash at x=0 (top-left) during trigger switches.
|
|
335
|
+
// flushSync forces synchronous commit so update() below reads
|
|
336
|
+
// the correct reference element immediately.
|
|
337
|
+
onMouseEnter: e => {
|
|
338
|
+
const el = e.currentTarget ?? ref.current;
|
|
339
|
+
if (el instanceof HTMLElement) {
|
|
340
|
+
if ((0, import_react_dom.flushSync)(() => refs.setReference(el)), update(), !refProps) return;
|
|
341
|
+
refProps.onPointerEnter?.(e), context.onHoverReference?.(e.nativeEvent);
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
onMouseLeave: e => {
|
|
345
|
+
context.onLeaveReference?.(), refProps?.onMouseLeave?.(e);
|
|
346
|
+
}
|
|
347
|
+
})
|
|
348
|
+
});
|
|
349
|
+
}),
|
|
350
|
+
PopperContentFrame = (0, import_gui_core.styled)(import_gui_stacks.YStack, {
|
|
351
|
+
name: "PopperContent",
|
|
352
|
+
variants: {
|
|
353
|
+
unstyled: {
|
|
354
|
+
true: {}
|
|
355
|
+
},
|
|
356
|
+
size: {
|
|
357
|
+
"...size": (val, {
|
|
358
|
+
tokens
|
|
359
|
+
}) => ({
|
|
360
|
+
padding: tokens.space[val],
|
|
361
|
+
borderRadius: tokens.radius[val]
|
|
362
|
+
})
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}),
|
|
366
|
+
PopperContent = React.forwardRef(function (props, forwardedRef) {
|
|
367
|
+
const {
|
|
368
|
+
scope,
|
|
369
|
+
animatePosition,
|
|
370
|
+
enableAnimationForPositionChange,
|
|
371
|
+
children,
|
|
372
|
+
passThrough,
|
|
373
|
+
unstyled,
|
|
374
|
+
...rest
|
|
375
|
+
} = props,
|
|
376
|
+
animatePos = animatePosition ?? enableAnimationForPositionChange,
|
|
377
|
+
context = usePopperContext(scope),
|
|
378
|
+
{
|
|
379
|
+
strategy,
|
|
380
|
+
placement,
|
|
381
|
+
refs,
|
|
382
|
+
x,
|
|
383
|
+
y,
|
|
384
|
+
getFloatingProps,
|
|
385
|
+
size,
|
|
386
|
+
isPositioned,
|
|
387
|
+
transformOrigin,
|
|
388
|
+
update
|
|
389
|
+
} = context,
|
|
390
|
+
updateRef = React.useRef(update);
|
|
391
|
+
updateRef.current = update;
|
|
392
|
+
const lastNodeRef = React.useRef(null),
|
|
393
|
+
safeSetFloating = React.useCallback(node => {
|
|
394
|
+
const isNewNode = node !== lastNodeRef.current;
|
|
395
|
+
node && (lastNodeRef.current = node, refs.setFloating(node), isNewNode || updateRef.current?.());
|
|
396
|
+
}, [refs.setFloating]);
|
|
397
|
+
React.useEffect(() => () => {
|
|
398
|
+
const ourNode = lastNodeRef.current;
|
|
399
|
+
ourNode && refs.floating.current === ourNode && refs.setFloating(null), lastNodeRef.current = null;
|
|
400
|
+
}, []);
|
|
401
|
+
const contentRefs = (0, import_gui_compose_refs.useComposedRefs)(safeSetFloating, forwardedRef),
|
|
402
|
+
[needsMeasure, setNeedsMeasure] = React.useState(animatePos);
|
|
403
|
+
(0, import_gui_constants.useIsomorphicLayoutEffect)(() => {
|
|
404
|
+
needsMeasure && x && y && setNeedsMeasure(!1);
|
|
405
|
+
}, [needsMeasure, animatePos, x, y]);
|
|
406
|
+
const hasBeenPositioned = React.useRef(!1),
|
|
407
|
+
lastGoodPosition = React.useRef({
|
|
408
|
+
x: 0,
|
|
409
|
+
y: 0
|
|
410
|
+
});
|
|
411
|
+
(x !== 0 || y !== 0) && (lastGoodPosition.current = {
|
|
412
|
+
x,
|
|
413
|
+
y
|
|
414
|
+
}, isPositioned && (hasBeenPositioned.current = !0));
|
|
415
|
+
const brieflyZero = hasBeenPositioned.current && x === 0 && y === 0,
|
|
416
|
+
effectiveX = brieflyZero ? lastGoodPosition.current.x : x,
|
|
417
|
+
effectiveY = brieflyZero ? lastGoodPosition.current.y : y,
|
|
418
|
+
hide = !hasBeenPositioned.current && effectiveX === 0 && effectiveY === 0,
|
|
419
|
+
disableAnimationProp =
|
|
420
|
+
// if they want to animate also when re-positioning allow it
|
|
421
|
+
animatePos === "even-when-repositioning" ? needsMeasure : !hasBeenPositioned.current && !isPositioned || needsMeasure,
|
|
422
|
+
[disableAnimation, setDisableAnimation] = React.useState(disableAnimationProp);
|
|
423
|
+
React.useEffect(() => {
|
|
424
|
+
setDisableAnimation(disableAnimationProp);
|
|
425
|
+
}, [disableAnimationProp]);
|
|
426
|
+
const frameProps = {
|
|
427
|
+
ref: contentRefs,
|
|
428
|
+
...(hide ? {} : {
|
|
429
|
+
x: effectiveX || 0,
|
|
430
|
+
y: effectiveY || 0
|
|
431
|
+
}),
|
|
432
|
+
top: 0,
|
|
433
|
+
left: 0,
|
|
434
|
+
position: strategy,
|
|
435
|
+
opacity: hide ? 0 : 1,
|
|
436
|
+
...(animatePos && {
|
|
437
|
+
transition: rest.transition,
|
|
438
|
+
// animateOnly: [] turns off transitions while keeping styles applied,
|
|
439
|
+
// letting the element move to its position silently before animations start
|
|
440
|
+
animateOnly: disableAnimation ? [] : rest.animateOnly,
|
|
441
|
+
animatePresence: !1
|
|
442
|
+
})
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
style,
|
|
446
|
+
...floatingProps
|
|
447
|
+
} = getFloatingProps ? getFloatingProps(frameProps) : frameProps,
|
|
448
|
+
transformOriginStyle = import_gui_constants.isWeb && transformOrigin ? {
|
|
449
|
+
transformOrigin: `${transformOrigin.x} ${transformOrigin.y}`
|
|
450
|
+
} : void 0;
|
|
451
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_core.LayoutMeasurementController, {
|
|
452
|
+
disable: !context.open,
|
|
453
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_gui_core.View, {
|
|
454
|
+
passThrough,
|
|
455
|
+
ref: contentRefs,
|
|
456
|
+
direction: rest.direction,
|
|
457
|
+
...(passThrough ? null : floatingProps),
|
|
458
|
+
...(!passThrough && animatePos && {
|
|
459
|
+
"data-popper-animate-position": "true"
|
|
460
|
+
}),
|
|
461
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperContentFrame, {
|
|
462
|
+
passThrough,
|
|
463
|
+
unstyled,
|
|
464
|
+
...(!passThrough && {
|
|
465
|
+
"data-placement": placement,
|
|
466
|
+
"data-strategy": strategy,
|
|
467
|
+
size,
|
|
468
|
+
...style,
|
|
469
|
+
...transformOriginStyle,
|
|
470
|
+
...rest
|
|
471
|
+
}),
|
|
472
|
+
children
|
|
473
|
+
}, "popper-content-frame")
|
|
474
|
+
})
|
|
475
|
+
});
|
|
476
|
+
}),
|
|
477
|
+
PopperArrowFrame = (0, import_gui_core.styled)(import_gui_stacks.YStack, {
|
|
478
|
+
name: "PopperArrow",
|
|
479
|
+
variants: {
|
|
480
|
+
unstyled: {
|
|
481
|
+
false: {
|
|
482
|
+
borderColor: "$borderColor",
|
|
483
|
+
backgroundColor: "$background",
|
|
484
|
+
position: "relative"
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
},
|
|
488
|
+
defaultVariants: {
|
|
489
|
+
unstyled: process.env.HANZO_GUI_HEADLESS === "1"
|
|
490
|
+
}
|
|
491
|
+
}),
|
|
492
|
+
PopperArrowOuterFrame = (0, import_gui_core.styled)(import_gui_stacks.YStack, {
|
|
493
|
+
name: "PopperArrowOuter",
|
|
494
|
+
variants: {
|
|
495
|
+
unstyled: {
|
|
496
|
+
false: {
|
|
497
|
+
position: "absolute",
|
|
498
|
+
zIndex: 1e6,
|
|
499
|
+
pointerEvents: "none",
|
|
500
|
+
overflow: "hidden",
|
|
501
|
+
alignItems: "center",
|
|
502
|
+
justifyContent: "center"
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
},
|
|
506
|
+
defaultVariants: {
|
|
507
|
+
unstyled: process.env.HANZO_GUI_HEADLESS === "1"
|
|
508
|
+
}
|
|
509
|
+
}),
|
|
510
|
+
opposites = {
|
|
511
|
+
top: "bottom",
|
|
512
|
+
right: "left",
|
|
513
|
+
bottom: "top",
|
|
514
|
+
left: "right"
|
|
515
|
+
},
|
|
516
|
+
PopperArrow = React.forwardRef(function (propsIn, forwardedRef) {
|
|
517
|
+
const {
|
|
518
|
+
scope,
|
|
519
|
+
animatePosition,
|
|
520
|
+
transition,
|
|
521
|
+
...rest
|
|
522
|
+
} = propsIn,
|
|
523
|
+
{
|
|
524
|
+
offset,
|
|
525
|
+
size: sizeProp,
|
|
526
|
+
borderWidth = 0,
|
|
527
|
+
...arrowProps
|
|
528
|
+
} = rest,
|
|
529
|
+
context = usePopperContext(scope),
|
|
530
|
+
sizeVal = typeof sizeProp == "number" ? sizeProp : (0, import_gui_core.getVariableValue)((0, import_gui_get_token.getSpace)(sizeProp ?? context.size, {
|
|
531
|
+
shift: -2,
|
|
532
|
+
bounds: [2]
|
|
533
|
+
})),
|
|
534
|
+
size = Math.max(0, +sizeVal),
|
|
535
|
+
{
|
|
536
|
+
placement
|
|
537
|
+
} = context,
|
|
538
|
+
refs = (0, import_gui_compose_refs.useComposedRefs)(context.arrowRef, forwardedRef),
|
|
539
|
+
x = context.arrowStyle?.x || 0,
|
|
540
|
+
y = context.arrowStyle?.y || 0,
|
|
541
|
+
arrowPositioned = context.arrowStyle != null,
|
|
542
|
+
primaryPlacement = placement ? placement.split("-")[0] : "top",
|
|
543
|
+
arrowStyle = {
|
|
544
|
+
x,
|
|
545
|
+
y,
|
|
546
|
+
width: size,
|
|
547
|
+
height: size
|
|
548
|
+
},
|
|
549
|
+
innerArrowStyle = {},
|
|
550
|
+
isVertical = primaryPlacement === "bottom" || primaryPlacement === "top";
|
|
551
|
+
if (primaryPlacement) {
|
|
552
|
+
arrowStyle[isVertical ? "width" : "height"] = size * 2;
|
|
553
|
+
const oppSide = opposites[primaryPlacement];
|
|
554
|
+
oppSide && (arrowStyle[oppSide] = -size, innerArrowStyle[oppSide] = size / 2), (oppSide === "top" || oppSide === "bottom") && (arrowStyle.left = 0), (oppSide === "left" || oppSide === "right") && (arrowStyle.top = 0), (0, import_gui_constants.useIsomorphicLayoutEffect)(() => {
|
|
555
|
+
context.onArrowSize?.(size);
|
|
556
|
+
}, [size, context.onArrowSize]);
|
|
557
|
+
}
|
|
558
|
+
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperArrowOuterFrame, {
|
|
559
|
+
ref: refs,
|
|
560
|
+
...arrowStyle,
|
|
561
|
+
...(!arrowPositioned && {
|
|
562
|
+
opacity: 0
|
|
563
|
+
}),
|
|
564
|
+
...(animatePosition && {
|
|
565
|
+
transition,
|
|
566
|
+
animateOnly: ["transform"],
|
|
567
|
+
animatePresence: !1
|
|
568
|
+
}),
|
|
569
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(PopperArrowFrame, {
|
|
570
|
+
width: size,
|
|
571
|
+
height: size,
|
|
572
|
+
...arrowProps,
|
|
573
|
+
...innerArrowStyle,
|
|
574
|
+
rotate: "45deg",
|
|
575
|
+
...(primaryPlacement === "bottom" && {
|
|
576
|
+
borderLeftWidth: borderWidth,
|
|
577
|
+
borderTopWidth: borderWidth
|
|
578
|
+
}),
|
|
579
|
+
...(primaryPlacement === "top" && {
|
|
580
|
+
borderBottomWidth: borderWidth,
|
|
581
|
+
borderRightWidth: borderWidth
|
|
582
|
+
}),
|
|
583
|
+
...(primaryPlacement === "right" && {
|
|
584
|
+
borderLeftWidth: borderWidth,
|
|
585
|
+
borderBottomWidth: borderWidth
|
|
586
|
+
}),
|
|
587
|
+
...(primaryPlacement === "left" && {
|
|
588
|
+
borderTopWidth: borderWidth,
|
|
589
|
+
borderRightWidth: borderWidth
|
|
590
|
+
})
|
|
591
|
+
})
|
|
592
|
+
});
|
|
593
|
+
});
|