lizaui 9.0.10 → 9.0.12

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.
Files changed (80) hide show
  1. package/dist/button/index.es.js +1 -1
  2. package/dist/calendar/index.cjs.js +11 -8
  3. package/dist/calendar/index.cjs.js.map +1 -1
  4. package/dist/calendar/index.es.js +12 -9
  5. package/dist/calendar/index.es.js.map +1 -1
  6. package/dist/checkbox/index.es.js +1 -1
  7. package/dist/chunks/{button-B0fpJrMg.js → button-CA3Y2GZ1.js} +2 -2
  8. package/dist/chunks/{button-B0fpJrMg.js.map → button-CA3Y2GZ1.js.map} +1 -1
  9. package/dist/chunks/{checkbox-C1Sssumg.js → checkbox-qzZKMLRN.js} +2 -2
  10. package/dist/chunks/{checkbox-C1Sssumg.js.map → checkbox-qzZKMLRN.js.map} +1 -1
  11. package/dist/chunks/{floating-ui.dom-DsMDyTcd.js → floating-ui.dom-N5ROFCJy.js} +1 -10
  12. package/dist/chunks/{floating-ui.dom-DsMDyTcd.js.map → floating-ui.dom-N5ROFCJy.js.map} +1 -1
  13. package/dist/chunks/{floating-ui.dom-Bd-QJw02.js → floating-ui.dom-NqZWWqNg.js} +4 -13
  14. package/dist/chunks/{floating-ui.dom-Bd-QJw02.js.map → floating-ui.dom-NqZWWqNg.js.map} +1 -1
  15. package/dist/chunks/index-CuySPbdY.js +559 -0
  16. package/dist/chunks/index-CuySPbdY.js.map +1 -0
  17. package/dist/chunks/index-DBDBh58Q.js +575 -0
  18. package/dist/chunks/index-DBDBh58Q.js.map +1 -0
  19. package/dist/chunks/index-DNSql2gU.js +662 -0
  20. package/dist/chunks/index-DNSql2gU.js.map +1 -0
  21. package/dist/chunks/{index-B4RTH1-D.js → index-DiC9dI6_.js} +4 -4
  22. package/dist/chunks/{index-B4RTH1-D.js.map → index-DiC9dI6_.js.map} +1 -1
  23. package/dist/chunks/index-DlZi5TkN.js +646 -0
  24. package/dist/chunks/index-DlZi5TkN.js.map +1 -0
  25. package/dist/chunks/{scroll-area-C0NhSIO2.js → scroll-area-BboZbU1u.js} +27 -27
  26. package/dist/chunks/{scroll-area-C0NhSIO2.js.map → scroll-area-BboZbU1u.js.map} +1 -1
  27. package/dist/chunks/{scroll-area-JgKF61tc.js → scroll-area-DKkgpH-S.js} +3 -3
  28. package/dist/chunks/{scroll-area-JgKF61tc.js.map → scroll-area-DKkgpH-S.js.map} +1 -1
  29. package/dist/chunks/{select-DGnc8VJi.js → select-MSYUKpRI.js} +83 -439
  30. package/dist/chunks/select-MSYUKpRI.js.map +1 -0
  31. package/dist/chunks/{select-Dpyj5dUk.js → select-s-z596Y4.js} +10 -366
  32. package/dist/chunks/select-s-z596Y4.js.map +1 -0
  33. package/dist/chunks/{textarea-D2_KC-J4.js → textarea-By2Vv44z.js} +36 -587
  34. package/dist/chunks/textarea-By2Vv44z.js.map +1 -0
  35. package/dist/chunks/{textarea-_HQpXiCX.js → textarea-ClJsk9Gp.js} +35 -586
  36. package/dist/chunks/textarea-ClJsk9Gp.js.map +1 -0
  37. package/dist/chunks/tooltip-BP--5Wj2.js +525 -0
  38. package/dist/chunks/tooltip-BP--5Wj2.js.map +1 -0
  39. package/dist/chunks/tooltip-KggPQa5m.js +541 -0
  40. package/dist/chunks/tooltip-KggPQa5m.js.map +1 -0
  41. package/dist/components/calendar/date-picker/date-picker.d.ts +1 -1
  42. package/dist/components/calendar/date-picker/date-picker.d.ts.map +1 -1
  43. package/dist/components/calendar/date-picker/interface/date-picker.interface.d.ts +3 -0
  44. package/dist/components/calendar/date-picker/interface/date-picker.interface.d.ts.map +1 -1
  45. package/dist/components/tooltip/tooltip-nice.d.ts +11 -0
  46. package/dist/components/tooltip/tooltip-nice.d.ts.map +1 -0
  47. package/dist/components/tooltip/tooltip.d.ts.map +1 -1
  48. package/dist/components/ui/tooltip.d.ts +8 -0
  49. package/dist/components/ui/tooltip.d.ts.map +1 -0
  50. package/dist/divider/index.es.js +1 -1
  51. package/dist/modal/index.es.js +1 -1
  52. package/dist/pagination/index.cjs.js +2 -2
  53. package/dist/pagination/index.es.js +3 -3
  54. package/dist/phone-input/index.cjs.js +2 -2
  55. package/dist/phone-input/index.es.js +3 -3
  56. package/dist/select-input/index.cjs.js +1 -1
  57. package/dist/select-input/index.es.js +2 -2
  58. package/dist/table/index.cjs.js +1 -1
  59. package/dist/table/index.es.js +2 -2
  60. package/dist/time-input/index.cjs.js +1 -1
  61. package/dist/time-input/index.es.js +2 -2
  62. package/dist/tooltip/index.cjs.js +1 -1
  63. package/dist/tooltip/index.es.js +1 -1
  64. package/dist/ui/index.cjs.js +292 -290
  65. package/dist/ui/index.cjs.js.map +1 -1
  66. package/dist/ui/index.es.js +182 -180
  67. package/dist/ui/index.es.js.map +1 -1
  68. package/package.json +10 -9
  69. package/dist/chunks/floating-ui.react-dom-CjlUwp8V.js +0 -294
  70. package/dist/chunks/floating-ui.react-dom-CjlUwp8V.js.map +0 -1
  71. package/dist/chunks/floating-ui.react-dom-D5BI9L2i.js +0 -310
  72. package/dist/chunks/floating-ui.react-dom-D5BI9L2i.js.map +0 -1
  73. package/dist/chunks/select-DGnc8VJi.js.map +0 -1
  74. package/dist/chunks/select-Dpyj5dUk.js.map +0 -1
  75. package/dist/chunks/textarea-D2_KC-J4.js.map +0 -1
  76. package/dist/chunks/textarea-_HQpXiCX.js.map +0 -1
  77. package/dist/chunks/tooltip-GGFk8ALK.js +0 -1402
  78. package/dist/chunks/tooltip-GGFk8ALK.js.map +0 -1
  79. package/dist/chunks/tooltip-JwIbppjO.js +0 -1387
  80. package/dist/chunks/tooltip-JwIbppjO.js.map +0 -1
@@ -1,1387 +0,0 @@
1
- import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
- import * as React from "react";
3
- import { useLayoutEffect, useState, useRef } from "react";
4
- import { i as isShadowRoot, d as isHTMLElement, e as isElement, g as getWindow, j as getOverflowAncestors, k as getComputedStyle, m as isWebKit, n as isLastTraversableNode, p as getParentNode, q as autoUpdate } from "./floating-ui.dom-Bd-QJw02.js";
5
- import "react-dom";
6
- import { u as useFloating$1, o as offset, f as flip, s as shift, a as arrow } from "./floating-ui.react-dom-CjlUwp8V.js";
7
- import { twMerge } from "tailwind-merge";
8
- import clsx from "clsx";
9
- function getPlatform() {
10
- const uaData = navigator.userAgentData;
11
- if (uaData != null && uaData.platform) {
12
- return uaData.platform;
13
- }
14
- return navigator.platform;
15
- }
16
- function getUserAgent() {
17
- const uaData = navigator.userAgentData;
18
- if (uaData && Array.isArray(uaData.brands)) {
19
- return uaData.brands.map((_ref) => {
20
- let {
21
- brand,
22
- version
23
- } = _ref;
24
- return brand + "/" + version;
25
- }).join(" ");
26
- }
27
- return navigator.userAgent;
28
- }
29
- function isSafari() {
30
- return /apple/i.test(navigator.vendor);
31
- }
32
- function isMac() {
33
- return getPlatform().toLowerCase().startsWith("mac") && !navigator.maxTouchPoints;
34
- }
35
- function isJSDOM() {
36
- return getUserAgent().includes("jsdom/");
37
- }
38
- const FOCUSABLE_ATTRIBUTE$1 = "data-floating-ui-focusable";
39
- const TYPEABLE_SELECTOR = "input:not([type='hidden']):not([disabled]),[contenteditable]:not([contenteditable='false']),textarea:not([disabled])";
40
- function activeElement(doc) {
41
- let activeElement2 = doc.activeElement;
42
- while (((_activeElement = activeElement2) == null || (_activeElement = _activeElement.shadowRoot) == null ? void 0 : _activeElement.activeElement) != null) {
43
- var _activeElement;
44
- activeElement2 = activeElement2.shadowRoot.activeElement;
45
- }
46
- return activeElement2;
47
- }
48
- function contains(parent, child) {
49
- if (!parent || !child) {
50
- return false;
51
- }
52
- const rootNode = child.getRootNode == null ? void 0 : child.getRootNode();
53
- if (parent.contains(child)) {
54
- return true;
55
- }
56
- if (rootNode && isShadowRoot(rootNode)) {
57
- let next = child;
58
- while (next) {
59
- if (parent === next) {
60
- return true;
61
- }
62
- next = next.parentNode || next.host;
63
- }
64
- }
65
- return false;
66
- }
67
- function getTarget(event) {
68
- if ("composedPath" in event) {
69
- return event.composedPath()[0];
70
- }
71
- return event.target;
72
- }
73
- function isEventTargetWithin(event, node) {
74
- if (node == null) {
75
- return false;
76
- }
77
- if ("composedPath" in event) {
78
- return event.composedPath().includes(node);
79
- }
80
- const e = event;
81
- return e.target != null && node.contains(e.target);
82
- }
83
- function isRootElement(element) {
84
- return element.matches("html,body");
85
- }
86
- function getDocument(node) {
87
- return (node == null ? void 0 : node.ownerDocument) || document;
88
- }
89
- function isTypeableElement(element) {
90
- return isHTMLElement(element) && element.matches(TYPEABLE_SELECTOR);
91
- }
92
- function matchesFocusVisible(element) {
93
- if (!element || isJSDOM()) return true;
94
- try {
95
- return element.matches(":focus-visible");
96
- } catch (_e) {
97
- return true;
98
- }
99
- }
100
- function getFloatingFocusElement(floatingElement) {
101
- if (!floatingElement) {
102
- return null;
103
- }
104
- return floatingElement.hasAttribute(FOCUSABLE_ATTRIBUTE$1) ? floatingElement : floatingElement.querySelector("[" + FOCUSABLE_ATTRIBUTE$1 + "]") || floatingElement;
105
- }
106
- function getNodeChildren(nodes, id, onlyOpenChildren) {
107
- if (onlyOpenChildren === void 0) {
108
- onlyOpenChildren = true;
109
- }
110
- const directChildren = nodes.filter((node) => {
111
- var _node$context;
112
- return node.parentId === id && (!onlyOpenChildren || ((_node$context = node.context) == null ? void 0 : _node$context.open));
113
- });
114
- return directChildren.flatMap((child) => [child, ...getNodeChildren(nodes, child.id, onlyOpenChildren)]);
115
- }
116
- function isReactEvent(event) {
117
- return "nativeEvent" in event;
118
- }
119
- function isMouseLikePointerType(pointerType, strict) {
120
- const values = ["mouse", "pen"];
121
- {
122
- values.push("", void 0);
123
- }
124
- return values.includes(pointerType);
125
- }
126
- var isClient = typeof document !== "undefined";
127
- var noop = function noop2() {
128
- };
129
- var index = isClient ? useLayoutEffect : noop;
130
- const SafeReact$1 = {
131
- ...React
132
- };
133
- function useLatestRef(value) {
134
- const ref = React.useRef(value);
135
- index(() => {
136
- ref.current = value;
137
- });
138
- return ref;
139
- }
140
- const useInsertionEffect = SafeReact$1.useInsertionEffect;
141
- const useSafeInsertionEffect = useInsertionEffect || ((fn) => fn());
142
- function useEffectEvent(callback) {
143
- const ref = React.useRef(() => {
144
- if (process.env.NODE_ENV !== "production") {
145
- throw new Error("Cannot call an event handler while rendering.");
146
- }
147
- });
148
- useSafeInsertionEffect(() => {
149
- ref.current = callback;
150
- });
151
- return React.useCallback(function() {
152
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
153
- args[_key] = arguments[_key];
154
- }
155
- return ref.current == null ? void 0 : ref.current(...args);
156
- }, []);
157
- }
158
- const FOCUSABLE_ATTRIBUTE = "data-floating-ui-focusable";
159
- const ACTIVE_KEY = "active";
160
- const SELECTED_KEY = "selected";
161
- const SafeReact = {
162
- ...React
163
- };
164
- let serverHandoffComplete = false;
165
- let count = 0;
166
- const genId = () => (
167
- // Ensure the id is unique with multiple independent versions of Floating UI
168
- // on <React 18
169
- "floating-ui-" + Math.random().toString(36).slice(2, 6) + count++
170
- );
171
- function useFloatingId() {
172
- const [id, setId] = React.useState(() => serverHandoffComplete ? genId() : void 0);
173
- index(() => {
174
- if (id == null) {
175
- setId(genId());
176
- }
177
- }, []);
178
- React.useEffect(() => {
179
- serverHandoffComplete = true;
180
- }, []);
181
- return id;
182
- }
183
- const useReactId = SafeReact.useId;
184
- const useId = useReactId || useFloatingId;
185
- let devMessageSet;
186
- if (process.env.NODE_ENV !== "production") {
187
- devMessageSet = /* @__PURE__ */ new Set();
188
- }
189
- function warn() {
190
- var _devMessageSet;
191
- for (var _len = arguments.length, messages = new Array(_len), _key = 0; _key < _len; _key++) {
192
- messages[_key] = arguments[_key];
193
- }
194
- const message = "Floating UI: " + messages.join(" ");
195
- if (!((_devMessageSet = devMessageSet) != null && _devMessageSet.has(message))) {
196
- var _devMessageSet2;
197
- (_devMessageSet2 = devMessageSet) == null || _devMessageSet2.add(message);
198
- }
199
- }
200
- function error() {
201
- var _devMessageSet3;
202
- for (var _len2 = arguments.length, messages = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
203
- messages[_key2] = arguments[_key2];
204
- }
205
- const message = "Floating UI: " + messages.join(" ");
206
- if (!((_devMessageSet3 = devMessageSet) != null && _devMessageSet3.has(message))) {
207
- var _devMessageSet4;
208
- (_devMessageSet4 = devMessageSet) == null || _devMessageSet4.add(message);
209
- }
210
- }
211
- const FloatingArrow = /* @__PURE__ */ React.forwardRef(function FloatingArrow2(props, ref) {
212
- const {
213
- context: {
214
- placement,
215
- elements: {
216
- floating
217
- },
218
- middlewareData: {
219
- arrow: arrow2,
220
- shift: shift2
221
- }
222
- },
223
- width = 14,
224
- height = 7,
225
- tipRadius = 0,
226
- strokeWidth = 0,
227
- staticOffset,
228
- stroke,
229
- d,
230
- style: {
231
- transform,
232
- ...restStyle
233
- } = {},
234
- ...rest
235
- } = props;
236
- if (process.env.NODE_ENV !== "production") {
237
- if (!ref) {
238
- warn("The `ref` prop is required for `FloatingArrow`.");
239
- }
240
- }
241
- const clipPathId = useId();
242
- const [isRTL, setIsRTL] = React.useState(false);
243
- index(() => {
244
- if (!floating) return;
245
- const isRTL2 = getComputedStyle(floating).direction === "rtl";
246
- if (isRTL2) {
247
- setIsRTL(true);
248
- }
249
- }, [floating]);
250
- if (!floating) {
251
- return null;
252
- }
253
- const [side, alignment] = placement.split("-");
254
- const isVerticalSide = side === "top" || side === "bottom";
255
- let computedStaticOffset = staticOffset;
256
- if (isVerticalSide && shift2 != null && shift2.x || !isVerticalSide && shift2 != null && shift2.y) {
257
- computedStaticOffset = null;
258
- }
259
- const computedStrokeWidth = strokeWidth * 2;
260
- const halfStrokeWidth = computedStrokeWidth / 2;
261
- const svgX = width / 2 * (tipRadius / -8 + 1);
262
- const svgY = height / 2 * tipRadius / 4;
263
- const isCustomShape = !!d;
264
- const yOffsetProp = computedStaticOffset && alignment === "end" ? "bottom" : "top";
265
- let xOffsetProp = computedStaticOffset && alignment === "end" ? "right" : "left";
266
- if (computedStaticOffset && isRTL) {
267
- xOffsetProp = alignment === "end" ? "left" : "right";
268
- }
269
- const arrowX = (arrow2 == null ? void 0 : arrow2.x) != null ? computedStaticOffset || arrow2.x : "";
270
- const arrowY = (arrow2 == null ? void 0 : arrow2.y) != null ? computedStaticOffset || arrow2.y : "";
271
- const dValue = d || "M0,0" + (" H" + width) + (" L" + (width - svgX) + "," + (height - svgY)) + (" Q" + width / 2 + "," + height + " " + svgX + "," + (height - svgY)) + " Z";
272
- const rotation = {
273
- top: isCustomShape ? "rotate(180deg)" : "",
274
- left: isCustomShape ? "rotate(90deg)" : "rotate(-90deg)",
275
- bottom: isCustomShape ? "" : "rotate(180deg)",
276
- right: isCustomShape ? "rotate(-90deg)" : "rotate(90deg)"
277
- }[side];
278
- return /* @__PURE__ */ jsxs("svg", {
279
- ...rest,
280
- "aria-hidden": true,
281
- ref,
282
- width: isCustomShape ? width : width + computedStrokeWidth,
283
- height: width,
284
- viewBox: "0 0 " + width + " " + (height > width ? height : width),
285
- style: {
286
- position: "absolute",
287
- pointerEvents: "none",
288
- [xOffsetProp]: arrowX,
289
- [yOffsetProp]: arrowY,
290
- [side]: isVerticalSide || isCustomShape ? "100%" : "calc(100% - " + computedStrokeWidth / 2 + "px)",
291
- transform: [rotation, transform].filter((t) => !!t).join(" "),
292
- ...restStyle
293
- },
294
- children: [computedStrokeWidth > 0 && /* @__PURE__ */ jsx("path", {
295
- clipPath: "url(#" + clipPathId + ")",
296
- fill: "none",
297
- stroke,
298
- strokeWidth: computedStrokeWidth + (d ? 0 : 1),
299
- d: dValue
300
- }), /* @__PURE__ */ jsx("path", {
301
- stroke: computedStrokeWidth && !d ? rest.fill : "none",
302
- d: dValue
303
- }), /* @__PURE__ */ jsx("clipPath", {
304
- id: clipPathId,
305
- children: /* @__PURE__ */ jsx("rect", {
306
- x: -halfStrokeWidth,
307
- y: halfStrokeWidth * (isCustomShape ? -1 : 1),
308
- width: width + computedStrokeWidth,
309
- height: width
310
- })
311
- })]
312
- });
313
- });
314
- function createEventEmitter() {
315
- const map = /* @__PURE__ */ new Map();
316
- return {
317
- emit(event, data) {
318
- var _map$get;
319
- (_map$get = map.get(event)) == null || _map$get.forEach((listener) => listener(data));
320
- },
321
- on(event, listener) {
322
- if (!map.has(event)) {
323
- map.set(event, /* @__PURE__ */ new Set());
324
- }
325
- map.get(event).add(listener);
326
- },
327
- off(event, listener) {
328
- var _map$get2;
329
- (_map$get2 = map.get(event)) == null || _map$get2.delete(listener);
330
- }
331
- };
332
- }
333
- const FloatingNodeContext = /* @__PURE__ */ React.createContext(null);
334
- const FloatingTreeContext = /* @__PURE__ */ React.createContext(null);
335
- const useFloatingParentNodeId = () => {
336
- var _React$useContext;
337
- return ((_React$useContext = React.useContext(FloatingNodeContext)) == null ? void 0 : _React$useContext.id) || null;
338
- };
339
- const useFloatingTree = () => React.useContext(FloatingTreeContext);
340
- function createAttribute(name) {
341
- return "data-floating-ui-" + name;
342
- }
343
- function clearTimeoutIfSet(timeoutRef) {
344
- if (timeoutRef.current !== -1) {
345
- clearTimeout(timeoutRef.current);
346
- timeoutRef.current = -1;
347
- }
348
- }
349
- const safePolygonIdentifier = /* @__PURE__ */ createAttribute("safe-polygon");
350
- function getDelay(value, prop, pointerType) {
351
- if (pointerType && !isMouseLikePointerType(pointerType)) {
352
- return 0;
353
- }
354
- if (typeof value === "number") {
355
- return value;
356
- }
357
- if (typeof value === "function") {
358
- const result = value();
359
- if (typeof result === "number") {
360
- return result;
361
- }
362
- return result == null ? void 0 : result[prop];
363
- }
364
- return value == null ? void 0 : value[prop];
365
- }
366
- function getRestMs(value) {
367
- if (typeof value === "function") {
368
- return value();
369
- }
370
- return value;
371
- }
372
- function useHover(context, props) {
373
- if (props === void 0) {
374
- props = {};
375
- }
376
- const {
377
- open,
378
- onOpenChange,
379
- dataRef,
380
- events,
381
- elements
382
- } = context;
383
- const {
384
- enabled = true,
385
- delay = 0,
386
- handleClose = null,
387
- mouseOnly = false,
388
- restMs = 0,
389
- move = true
390
- } = props;
391
- const tree = useFloatingTree();
392
- const parentId = useFloatingParentNodeId();
393
- const handleCloseRef = useLatestRef(handleClose);
394
- const delayRef = useLatestRef(delay);
395
- const openRef = useLatestRef(open);
396
- const restMsRef = useLatestRef(restMs);
397
- const pointerTypeRef = React.useRef();
398
- const timeoutRef = React.useRef(-1);
399
- const handlerRef = React.useRef();
400
- const restTimeoutRef = React.useRef(-1);
401
- const blockMouseMoveRef = React.useRef(true);
402
- const performedPointerEventsMutationRef = React.useRef(false);
403
- const unbindMouseMoveRef = React.useRef(() => {
404
- });
405
- const restTimeoutPendingRef = React.useRef(false);
406
- const isHoverOpen = useEffectEvent(() => {
407
- var _dataRef$current$open;
408
- const type = (_dataRef$current$open = dataRef.current.openEvent) == null ? void 0 : _dataRef$current$open.type;
409
- return (type == null ? void 0 : type.includes("mouse")) && type !== "mousedown";
410
- });
411
- React.useEffect(() => {
412
- if (!enabled) return;
413
- function onOpenChange2(_ref) {
414
- let {
415
- open: open2
416
- } = _ref;
417
- if (!open2) {
418
- clearTimeoutIfSet(timeoutRef);
419
- clearTimeoutIfSet(restTimeoutRef);
420
- blockMouseMoveRef.current = true;
421
- restTimeoutPendingRef.current = false;
422
- }
423
- }
424
- events.on("openchange", onOpenChange2);
425
- return () => {
426
- events.off("openchange", onOpenChange2);
427
- };
428
- }, [enabled, events]);
429
- React.useEffect(() => {
430
- if (!enabled) return;
431
- if (!handleCloseRef.current) return;
432
- if (!open) return;
433
- function onLeave(event) {
434
- if (isHoverOpen()) {
435
- onOpenChange(false, event, "hover");
436
- }
437
- }
438
- const html = getDocument(elements.floating).documentElement;
439
- html.addEventListener("mouseleave", onLeave);
440
- return () => {
441
- html.removeEventListener("mouseleave", onLeave);
442
- };
443
- }, [elements.floating, open, onOpenChange, enabled, handleCloseRef, isHoverOpen]);
444
- const closeWithDelay = React.useCallback(function(event, runElseBranch, reason) {
445
- if (runElseBranch === void 0) {
446
- runElseBranch = true;
447
- }
448
- if (reason === void 0) {
449
- reason = "hover";
450
- }
451
- const closeDelay = getDelay(delayRef.current, "close", pointerTypeRef.current);
452
- if (closeDelay && !handlerRef.current) {
453
- clearTimeoutIfSet(timeoutRef);
454
- timeoutRef.current = window.setTimeout(() => onOpenChange(false, event, reason), closeDelay);
455
- } else if (runElseBranch) {
456
- clearTimeoutIfSet(timeoutRef);
457
- onOpenChange(false, event, reason);
458
- }
459
- }, [delayRef, onOpenChange]);
460
- const cleanupMouseMoveHandler = useEffectEvent(() => {
461
- unbindMouseMoveRef.current();
462
- handlerRef.current = void 0;
463
- });
464
- const clearPointerEvents = useEffectEvent(() => {
465
- if (performedPointerEventsMutationRef.current) {
466
- const body = getDocument(elements.floating).body;
467
- body.style.pointerEvents = "";
468
- body.removeAttribute(safePolygonIdentifier);
469
- performedPointerEventsMutationRef.current = false;
470
- }
471
- });
472
- const isClickLikeOpenEvent = useEffectEvent(() => {
473
- return dataRef.current.openEvent ? ["click", "mousedown"].includes(dataRef.current.openEvent.type) : false;
474
- });
475
- React.useEffect(() => {
476
- if (!enabled) return;
477
- function onReferenceMouseEnter(event) {
478
- clearTimeoutIfSet(timeoutRef);
479
- blockMouseMoveRef.current = false;
480
- if (mouseOnly && !isMouseLikePointerType(pointerTypeRef.current) || getRestMs(restMsRef.current) > 0 && !getDelay(delayRef.current, "open")) {
481
- return;
482
- }
483
- const openDelay = getDelay(delayRef.current, "open", pointerTypeRef.current);
484
- if (openDelay) {
485
- timeoutRef.current = window.setTimeout(() => {
486
- if (!openRef.current) {
487
- onOpenChange(true, event, "hover");
488
- }
489
- }, openDelay);
490
- } else if (!open) {
491
- onOpenChange(true, event, "hover");
492
- }
493
- }
494
- function onReferenceMouseLeave(event) {
495
- if (isClickLikeOpenEvent()) {
496
- clearPointerEvents();
497
- return;
498
- }
499
- unbindMouseMoveRef.current();
500
- const doc = getDocument(elements.floating);
501
- clearTimeoutIfSet(restTimeoutRef);
502
- restTimeoutPendingRef.current = false;
503
- if (handleCloseRef.current && dataRef.current.floatingContext) {
504
- if (!open) {
505
- clearTimeoutIfSet(timeoutRef);
506
- }
507
- handlerRef.current = handleCloseRef.current({
508
- ...dataRef.current.floatingContext,
509
- tree,
510
- x: event.clientX,
511
- y: event.clientY,
512
- onClose() {
513
- clearPointerEvents();
514
- cleanupMouseMoveHandler();
515
- if (!isClickLikeOpenEvent()) {
516
- closeWithDelay(event, true, "safe-polygon");
517
- }
518
- }
519
- });
520
- const handler = handlerRef.current;
521
- doc.addEventListener("mousemove", handler);
522
- unbindMouseMoveRef.current = () => {
523
- doc.removeEventListener("mousemove", handler);
524
- };
525
- return;
526
- }
527
- const shouldClose = pointerTypeRef.current === "touch" ? !contains(elements.floating, event.relatedTarget) : true;
528
- if (shouldClose) {
529
- closeWithDelay(event);
530
- }
531
- }
532
- function onScrollMouseLeave(event) {
533
- if (isClickLikeOpenEvent()) return;
534
- if (!dataRef.current.floatingContext) return;
535
- handleCloseRef.current == null || handleCloseRef.current({
536
- ...dataRef.current.floatingContext,
537
- tree,
538
- x: event.clientX,
539
- y: event.clientY,
540
- onClose() {
541
- clearPointerEvents();
542
- cleanupMouseMoveHandler();
543
- if (!isClickLikeOpenEvent()) {
544
- closeWithDelay(event);
545
- }
546
- }
547
- })(event);
548
- }
549
- function onFloatingMouseEnter() {
550
- clearTimeoutIfSet(timeoutRef);
551
- }
552
- function onFloatingMouseLeave(event) {
553
- if (!isClickLikeOpenEvent()) {
554
- closeWithDelay(event, false);
555
- }
556
- }
557
- if (isElement(elements.domReference)) {
558
- const reference2 = elements.domReference;
559
- const floating = elements.floating;
560
- if (open) {
561
- reference2.addEventListener("mouseleave", onScrollMouseLeave);
562
- }
563
- if (move) {
564
- reference2.addEventListener("mousemove", onReferenceMouseEnter, {
565
- once: true
566
- });
567
- }
568
- reference2.addEventListener("mouseenter", onReferenceMouseEnter);
569
- reference2.addEventListener("mouseleave", onReferenceMouseLeave);
570
- if (floating) {
571
- floating.addEventListener("mouseleave", onScrollMouseLeave);
572
- floating.addEventListener("mouseenter", onFloatingMouseEnter);
573
- floating.addEventListener("mouseleave", onFloatingMouseLeave);
574
- }
575
- return () => {
576
- if (open) {
577
- reference2.removeEventListener("mouseleave", onScrollMouseLeave);
578
- }
579
- if (move) {
580
- reference2.removeEventListener("mousemove", onReferenceMouseEnter);
581
- }
582
- reference2.removeEventListener("mouseenter", onReferenceMouseEnter);
583
- reference2.removeEventListener("mouseleave", onReferenceMouseLeave);
584
- if (floating) {
585
- floating.removeEventListener("mouseleave", onScrollMouseLeave);
586
- floating.removeEventListener("mouseenter", onFloatingMouseEnter);
587
- floating.removeEventListener("mouseleave", onFloatingMouseLeave);
588
- }
589
- };
590
- }
591
- }, [elements, enabled, context, mouseOnly, move, closeWithDelay, cleanupMouseMoveHandler, clearPointerEvents, onOpenChange, open, openRef, tree, delayRef, handleCloseRef, dataRef, isClickLikeOpenEvent, restMsRef]);
592
- index(() => {
593
- var _handleCloseRef$curre;
594
- if (!enabled) return;
595
- if (open && (_handleCloseRef$curre = handleCloseRef.current) != null && (_handleCloseRef$curre = _handleCloseRef$curre.__options) != null && _handleCloseRef$curre.blockPointerEvents && isHoverOpen()) {
596
- performedPointerEventsMutationRef.current = true;
597
- const floatingEl = elements.floating;
598
- if (isElement(elements.domReference) && floatingEl) {
599
- var _tree$nodesRef$curren;
600
- const body = getDocument(elements.floating).body;
601
- body.setAttribute(safePolygonIdentifier, "");
602
- const ref = elements.domReference;
603
- const parentFloating = tree == null || (_tree$nodesRef$curren = tree.nodesRef.current.find((node) => node.id === parentId)) == null || (_tree$nodesRef$curren = _tree$nodesRef$curren.context) == null ? void 0 : _tree$nodesRef$curren.elements.floating;
604
- if (parentFloating) {
605
- parentFloating.style.pointerEvents = "";
606
- }
607
- body.style.pointerEvents = "none";
608
- ref.style.pointerEvents = "auto";
609
- floatingEl.style.pointerEvents = "auto";
610
- return () => {
611
- body.style.pointerEvents = "";
612
- ref.style.pointerEvents = "";
613
- floatingEl.style.pointerEvents = "";
614
- };
615
- }
616
- }
617
- }, [enabled, open, parentId, elements, tree, handleCloseRef, isHoverOpen]);
618
- index(() => {
619
- if (!open) {
620
- pointerTypeRef.current = void 0;
621
- restTimeoutPendingRef.current = false;
622
- cleanupMouseMoveHandler();
623
- clearPointerEvents();
624
- }
625
- }, [open, cleanupMouseMoveHandler, clearPointerEvents]);
626
- React.useEffect(() => {
627
- return () => {
628
- cleanupMouseMoveHandler();
629
- clearTimeoutIfSet(timeoutRef);
630
- clearTimeoutIfSet(restTimeoutRef);
631
- clearPointerEvents();
632
- };
633
- }, [enabled, elements.domReference, cleanupMouseMoveHandler, clearPointerEvents]);
634
- const reference = React.useMemo(() => {
635
- function setPointerRef(event) {
636
- pointerTypeRef.current = event.pointerType;
637
- }
638
- return {
639
- onPointerDown: setPointerRef,
640
- onPointerEnter: setPointerRef,
641
- onMouseMove(event) {
642
- const {
643
- nativeEvent
644
- } = event;
645
- function handleMouseMove() {
646
- if (!blockMouseMoveRef.current && !openRef.current) {
647
- onOpenChange(true, nativeEvent, "hover");
648
- }
649
- }
650
- if (mouseOnly && !isMouseLikePointerType(pointerTypeRef.current)) {
651
- return;
652
- }
653
- if (open || getRestMs(restMsRef.current) === 0) {
654
- return;
655
- }
656
- if (restTimeoutPendingRef.current && event.movementX ** 2 + event.movementY ** 2 < 2) {
657
- return;
658
- }
659
- clearTimeoutIfSet(restTimeoutRef);
660
- if (pointerTypeRef.current === "touch") {
661
- handleMouseMove();
662
- } else {
663
- restTimeoutPendingRef.current = true;
664
- restTimeoutRef.current = window.setTimeout(handleMouseMove, getRestMs(restMsRef.current));
665
- }
666
- }
667
- };
668
- }, [mouseOnly, onOpenChange, open, openRef, restMsRef]);
669
- return React.useMemo(() => enabled ? {
670
- reference
671
- } : {}, [enabled, reference]);
672
- }
673
- const bubbleHandlerKeys = {
674
- pointerdown: "onPointerDown",
675
- mousedown: "onMouseDown",
676
- click: "onClick"
677
- };
678
- const captureHandlerKeys = {
679
- pointerdown: "onPointerDownCapture",
680
- mousedown: "onMouseDownCapture",
681
- click: "onClickCapture"
682
- };
683
- const normalizeProp = (normalizable) => {
684
- var _normalizable$escapeK, _normalizable$outside;
685
- return {
686
- escapeKey: typeof normalizable === "boolean" ? normalizable : (_normalizable$escapeK = normalizable == null ? void 0 : normalizable.escapeKey) != null ? _normalizable$escapeK : false,
687
- outsidePress: typeof normalizable === "boolean" ? normalizable : (_normalizable$outside = normalizable == null ? void 0 : normalizable.outsidePress) != null ? _normalizable$outside : true
688
- };
689
- };
690
- function useDismiss(context, props) {
691
- if (props === void 0) {
692
- props = {};
693
- }
694
- const {
695
- open,
696
- onOpenChange,
697
- elements,
698
- dataRef
699
- } = context;
700
- const {
701
- enabled = true,
702
- escapeKey = true,
703
- outsidePress: unstable_outsidePress = true,
704
- outsidePressEvent = "pointerdown",
705
- referencePress = false,
706
- referencePressEvent = "pointerdown",
707
- ancestorScroll = false,
708
- bubbles,
709
- capture
710
- } = props;
711
- const tree = useFloatingTree();
712
- const outsidePressFn = useEffectEvent(typeof unstable_outsidePress === "function" ? unstable_outsidePress : () => false);
713
- const outsidePress = typeof unstable_outsidePress === "function" ? outsidePressFn : unstable_outsidePress;
714
- const endedOrStartedInsideRef = React.useRef(false);
715
- const {
716
- escapeKey: escapeKeyBubbles,
717
- outsidePress: outsidePressBubbles
718
- } = normalizeProp(bubbles);
719
- const {
720
- escapeKey: escapeKeyCapture,
721
- outsidePress: outsidePressCapture
722
- } = normalizeProp(capture);
723
- const isComposingRef = React.useRef(false);
724
- const closeOnEscapeKeyDown = useEffectEvent((event) => {
725
- var _dataRef$current$floa;
726
- if (!open || !enabled || !escapeKey || event.key !== "Escape") {
727
- return;
728
- }
729
- if (isComposingRef.current) {
730
- return;
731
- }
732
- const nodeId = (_dataRef$current$floa = dataRef.current.floatingContext) == null ? void 0 : _dataRef$current$floa.nodeId;
733
- const children = tree ? getNodeChildren(tree.nodesRef.current, nodeId) : [];
734
- if (!escapeKeyBubbles) {
735
- event.stopPropagation();
736
- if (children.length > 0) {
737
- let shouldDismiss = true;
738
- children.forEach((child) => {
739
- var _child$context;
740
- if ((_child$context = child.context) != null && _child$context.open && !child.context.dataRef.current.__escapeKeyBubbles) {
741
- shouldDismiss = false;
742
- return;
743
- }
744
- });
745
- if (!shouldDismiss) {
746
- return;
747
- }
748
- }
749
- }
750
- onOpenChange(false, isReactEvent(event) ? event.nativeEvent : event, "escape-key");
751
- });
752
- const closeOnEscapeKeyDownCapture = useEffectEvent((event) => {
753
- var _getTarget2;
754
- const callback = () => {
755
- var _getTarget;
756
- closeOnEscapeKeyDown(event);
757
- (_getTarget = getTarget(event)) == null || _getTarget.removeEventListener("keydown", callback);
758
- };
759
- (_getTarget2 = getTarget(event)) == null || _getTarget2.addEventListener("keydown", callback);
760
- });
761
- const closeOnPressOutside = useEffectEvent((event) => {
762
- var _dataRef$current$floa2;
763
- const insideReactTree = dataRef.current.insideReactTree;
764
- dataRef.current.insideReactTree = false;
765
- const endedOrStartedInside = endedOrStartedInsideRef.current;
766
- endedOrStartedInsideRef.current = false;
767
- if (outsidePressEvent === "click" && endedOrStartedInside) {
768
- return;
769
- }
770
- if (insideReactTree) {
771
- return;
772
- }
773
- if (typeof outsidePress === "function" && !outsidePress(event)) {
774
- return;
775
- }
776
- const target = getTarget(event);
777
- const inertSelector = "[" + createAttribute("inert") + "]";
778
- const markers = getDocument(elements.floating).querySelectorAll(inertSelector);
779
- let targetRootAncestor = isElement(target) ? target : null;
780
- while (targetRootAncestor && !isLastTraversableNode(targetRootAncestor)) {
781
- const nextParent = getParentNode(targetRootAncestor);
782
- if (isLastTraversableNode(nextParent) || !isElement(nextParent)) {
783
- break;
784
- }
785
- targetRootAncestor = nextParent;
786
- }
787
- if (markers.length && isElement(target) && !isRootElement(target) && // Clicked on a direct ancestor (e.g. FloatingOverlay).
788
- !contains(target, elements.floating) && // If the target root element contains none of the markers, then the
789
- // element was injected after the floating element rendered.
790
- Array.from(markers).every((marker) => !contains(targetRootAncestor, marker))) {
791
- return;
792
- }
793
- if (isHTMLElement(target) && floating) {
794
- const lastTraversableNode = isLastTraversableNode(target);
795
- const style = getComputedStyle(target);
796
- const scrollRe = /auto|scroll/;
797
- const isScrollableX = lastTraversableNode || scrollRe.test(style.overflowX);
798
- const isScrollableY = lastTraversableNode || scrollRe.test(style.overflowY);
799
- const canScrollX = isScrollableX && target.clientWidth > 0 && target.scrollWidth > target.clientWidth;
800
- const canScrollY = isScrollableY && target.clientHeight > 0 && target.scrollHeight > target.clientHeight;
801
- const isRTL = style.direction === "rtl";
802
- const pressedVerticalScrollbar = canScrollY && (isRTL ? event.offsetX <= target.offsetWidth - target.clientWidth : event.offsetX > target.clientWidth);
803
- const pressedHorizontalScrollbar = canScrollX && event.offsetY > target.clientHeight;
804
- if (pressedVerticalScrollbar || pressedHorizontalScrollbar) {
805
- return;
806
- }
807
- }
808
- const nodeId = (_dataRef$current$floa2 = dataRef.current.floatingContext) == null ? void 0 : _dataRef$current$floa2.nodeId;
809
- const targetIsInsideChildren = tree && getNodeChildren(tree.nodesRef.current, nodeId).some((node) => {
810
- var _node$context;
811
- return isEventTargetWithin(event, (_node$context = node.context) == null ? void 0 : _node$context.elements.floating);
812
- });
813
- if (isEventTargetWithin(event, elements.floating) || isEventTargetWithin(event, elements.domReference) || targetIsInsideChildren) {
814
- return;
815
- }
816
- const children = tree ? getNodeChildren(tree.nodesRef.current, nodeId) : [];
817
- if (children.length > 0) {
818
- let shouldDismiss = true;
819
- children.forEach((child) => {
820
- var _child$context2;
821
- if ((_child$context2 = child.context) != null && _child$context2.open && !child.context.dataRef.current.__outsidePressBubbles) {
822
- shouldDismiss = false;
823
- return;
824
- }
825
- });
826
- if (!shouldDismiss) {
827
- return;
828
- }
829
- }
830
- onOpenChange(false, event, "outside-press");
831
- });
832
- const closeOnPressOutsideCapture = useEffectEvent((event) => {
833
- var _getTarget4;
834
- const callback = () => {
835
- var _getTarget3;
836
- closeOnPressOutside(event);
837
- (_getTarget3 = getTarget(event)) == null || _getTarget3.removeEventListener(outsidePressEvent, callback);
838
- };
839
- (_getTarget4 = getTarget(event)) == null || _getTarget4.addEventListener(outsidePressEvent, callback);
840
- });
841
- React.useEffect(() => {
842
- if (!open || !enabled) {
843
- return;
844
- }
845
- dataRef.current.__escapeKeyBubbles = escapeKeyBubbles;
846
- dataRef.current.__outsidePressBubbles = outsidePressBubbles;
847
- let compositionTimeout = -1;
848
- function onScroll(event) {
849
- onOpenChange(false, event, "ancestor-scroll");
850
- }
851
- function handleCompositionStart() {
852
- window.clearTimeout(compositionTimeout);
853
- isComposingRef.current = true;
854
- }
855
- function handleCompositionEnd() {
856
- compositionTimeout = window.setTimeout(
857
- () => {
858
- isComposingRef.current = false;
859
- },
860
- // 0ms or 1ms don't work in Safari. 5ms appears to consistently work.
861
- // Only apply to WebKit for the test to remain 0ms.
862
- isWebKit() ? 5 : 0
863
- );
864
- }
865
- const doc = getDocument(elements.floating);
866
- if (escapeKey) {
867
- doc.addEventListener("keydown", escapeKeyCapture ? closeOnEscapeKeyDownCapture : closeOnEscapeKeyDown, escapeKeyCapture);
868
- doc.addEventListener("compositionstart", handleCompositionStart);
869
- doc.addEventListener("compositionend", handleCompositionEnd);
870
- }
871
- outsidePress && doc.addEventListener(outsidePressEvent, outsidePressCapture ? closeOnPressOutsideCapture : closeOnPressOutside, outsidePressCapture);
872
- let ancestors = [];
873
- if (ancestorScroll) {
874
- if (isElement(elements.domReference)) {
875
- ancestors = getOverflowAncestors(elements.domReference);
876
- }
877
- if (isElement(elements.floating)) {
878
- ancestors = ancestors.concat(getOverflowAncestors(elements.floating));
879
- }
880
- if (!isElement(elements.reference) && elements.reference && elements.reference.contextElement) {
881
- ancestors = ancestors.concat(getOverflowAncestors(elements.reference.contextElement));
882
- }
883
- }
884
- ancestors = ancestors.filter((ancestor) => {
885
- var _doc$defaultView;
886
- return ancestor !== ((_doc$defaultView = doc.defaultView) == null ? void 0 : _doc$defaultView.visualViewport);
887
- });
888
- ancestors.forEach((ancestor) => {
889
- ancestor.addEventListener("scroll", onScroll, {
890
- passive: true
891
- });
892
- });
893
- return () => {
894
- if (escapeKey) {
895
- doc.removeEventListener("keydown", escapeKeyCapture ? closeOnEscapeKeyDownCapture : closeOnEscapeKeyDown, escapeKeyCapture);
896
- doc.removeEventListener("compositionstart", handleCompositionStart);
897
- doc.removeEventListener("compositionend", handleCompositionEnd);
898
- }
899
- outsidePress && doc.removeEventListener(outsidePressEvent, outsidePressCapture ? closeOnPressOutsideCapture : closeOnPressOutside, outsidePressCapture);
900
- ancestors.forEach((ancestor) => {
901
- ancestor.removeEventListener("scroll", onScroll);
902
- });
903
- window.clearTimeout(compositionTimeout);
904
- };
905
- }, [dataRef, elements, escapeKey, outsidePress, outsidePressEvent, open, onOpenChange, ancestorScroll, enabled, escapeKeyBubbles, outsidePressBubbles, closeOnEscapeKeyDown, escapeKeyCapture, closeOnEscapeKeyDownCapture, closeOnPressOutside, outsidePressCapture, closeOnPressOutsideCapture]);
906
- React.useEffect(() => {
907
- dataRef.current.insideReactTree = false;
908
- }, [dataRef, outsidePress, outsidePressEvent]);
909
- const reference = React.useMemo(() => ({
910
- onKeyDown: closeOnEscapeKeyDown,
911
- ...referencePress && {
912
- [bubbleHandlerKeys[referencePressEvent]]: (event) => {
913
- onOpenChange(false, event.nativeEvent, "reference-press");
914
- },
915
- ...referencePressEvent !== "click" && {
916
- onClick(event) {
917
- onOpenChange(false, event.nativeEvent, "reference-press");
918
- }
919
- }
920
- }
921
- }), [closeOnEscapeKeyDown, onOpenChange, referencePress, referencePressEvent]);
922
- const floating = React.useMemo(() => ({
923
- onKeyDown: closeOnEscapeKeyDown,
924
- onMouseDown() {
925
- endedOrStartedInsideRef.current = true;
926
- },
927
- onMouseUp() {
928
- endedOrStartedInsideRef.current = true;
929
- },
930
- [captureHandlerKeys[outsidePressEvent]]: () => {
931
- dataRef.current.insideReactTree = true;
932
- }
933
- }), [closeOnEscapeKeyDown, outsidePressEvent, dataRef]);
934
- return React.useMemo(() => enabled ? {
935
- reference,
936
- floating
937
- } : {}, [enabled, reference, floating]);
938
- }
939
- function useFloatingRootContext(options) {
940
- const {
941
- open = false,
942
- onOpenChange: onOpenChangeProp,
943
- elements: elementsProp
944
- } = options;
945
- const floatingId = useId();
946
- const dataRef = React.useRef({});
947
- const [events] = React.useState(() => createEventEmitter());
948
- const nested = useFloatingParentNodeId() != null;
949
- if (process.env.NODE_ENV !== "production") {
950
- const optionDomReference = elementsProp.reference;
951
- if (optionDomReference && !isElement(optionDomReference)) {
952
- error("Cannot pass a virtual element to the `elements.reference` option,", "as it must be a real DOM element. Use `refs.setPositionReference()`", "instead.");
953
- }
954
- }
955
- const [positionReference, setPositionReference] = React.useState(elementsProp.reference);
956
- const onOpenChange = useEffectEvent((open2, event, reason) => {
957
- dataRef.current.openEvent = open2 ? event : void 0;
958
- events.emit("openchange", {
959
- open: open2,
960
- event,
961
- reason,
962
- nested
963
- });
964
- onOpenChangeProp == null || onOpenChangeProp(open2, event, reason);
965
- });
966
- const refs = React.useMemo(() => ({
967
- setPositionReference
968
- }), []);
969
- const elements = React.useMemo(() => ({
970
- reference: positionReference || elementsProp.reference || null,
971
- floating: elementsProp.floating || null,
972
- domReference: elementsProp.reference
973
- }), [positionReference, elementsProp.reference, elementsProp.floating]);
974
- return React.useMemo(() => ({
975
- dataRef,
976
- open,
977
- onOpenChange,
978
- elements,
979
- events,
980
- floatingId,
981
- refs
982
- }), [open, onOpenChange, elements, events, floatingId, refs]);
983
- }
984
- function useFloating(options) {
985
- if (options === void 0) {
986
- options = {};
987
- }
988
- const {
989
- nodeId
990
- } = options;
991
- const internalRootContext = useFloatingRootContext({
992
- ...options,
993
- elements: {
994
- reference: null,
995
- floating: null,
996
- ...options.elements
997
- }
998
- });
999
- const rootContext = options.rootContext || internalRootContext;
1000
- const computedElements = rootContext.elements;
1001
- const [_domReference, setDomReference] = React.useState(null);
1002
- const [positionReference, _setPositionReference] = React.useState(null);
1003
- const optionDomReference = computedElements == null ? void 0 : computedElements.domReference;
1004
- const domReference = optionDomReference || _domReference;
1005
- const domReferenceRef = React.useRef(null);
1006
- const tree = useFloatingTree();
1007
- index(() => {
1008
- if (domReference) {
1009
- domReferenceRef.current = domReference;
1010
- }
1011
- }, [domReference]);
1012
- const position = useFloating$1({
1013
- ...options,
1014
- elements: {
1015
- ...computedElements,
1016
- ...positionReference && {
1017
- reference: positionReference
1018
- }
1019
- }
1020
- });
1021
- const setPositionReference = React.useCallback((node) => {
1022
- const computedPositionReference = isElement(node) ? {
1023
- getBoundingClientRect: () => node.getBoundingClientRect(),
1024
- getClientRects: () => node.getClientRects(),
1025
- contextElement: node
1026
- } : node;
1027
- _setPositionReference(computedPositionReference);
1028
- position.refs.setReference(computedPositionReference);
1029
- }, [position.refs]);
1030
- const setReference = React.useCallback((node) => {
1031
- if (isElement(node) || node === null) {
1032
- domReferenceRef.current = node;
1033
- setDomReference(node);
1034
- }
1035
- if (isElement(position.refs.reference.current) || position.refs.reference.current === null || // Don't allow setting virtual elements using the old technique back to
1036
- // `null` to support `positionReference` + an unstable `reference`
1037
- // callback ref.
1038
- node !== null && !isElement(node)) {
1039
- position.refs.setReference(node);
1040
- }
1041
- }, [position.refs]);
1042
- const refs = React.useMemo(() => ({
1043
- ...position.refs,
1044
- setReference,
1045
- setPositionReference,
1046
- domReference: domReferenceRef
1047
- }), [position.refs, setReference, setPositionReference]);
1048
- const elements = React.useMemo(() => ({
1049
- ...position.elements,
1050
- domReference
1051
- }), [position.elements, domReference]);
1052
- const context = React.useMemo(() => ({
1053
- ...position,
1054
- ...rootContext,
1055
- refs,
1056
- elements,
1057
- nodeId
1058
- }), [position, refs, elements, nodeId, rootContext]);
1059
- index(() => {
1060
- rootContext.dataRef.current.floatingContext = context;
1061
- const node = tree == null ? void 0 : tree.nodesRef.current.find((node2) => node2.id === nodeId);
1062
- if (node) {
1063
- node.context = context;
1064
- }
1065
- });
1066
- return React.useMemo(() => ({
1067
- ...position,
1068
- context,
1069
- refs,
1070
- elements
1071
- }), [position, refs, elements, context]);
1072
- }
1073
- function isMacSafari() {
1074
- return isMac() && isSafari();
1075
- }
1076
- function useFocus(context, props) {
1077
- if (props === void 0) {
1078
- props = {};
1079
- }
1080
- const {
1081
- open,
1082
- onOpenChange,
1083
- events,
1084
- dataRef,
1085
- elements
1086
- } = context;
1087
- const {
1088
- enabled = true,
1089
- visibleOnly = true
1090
- } = props;
1091
- const blockFocusRef = React.useRef(false);
1092
- const timeoutRef = React.useRef(-1);
1093
- const keyboardModalityRef = React.useRef(true);
1094
- React.useEffect(() => {
1095
- if (!enabled) return;
1096
- const win = getWindow(elements.domReference);
1097
- function onBlur() {
1098
- if (!open && isHTMLElement(elements.domReference) && elements.domReference === activeElement(getDocument(elements.domReference))) {
1099
- blockFocusRef.current = true;
1100
- }
1101
- }
1102
- function onKeyDown() {
1103
- keyboardModalityRef.current = true;
1104
- }
1105
- function onPointerDown() {
1106
- keyboardModalityRef.current = false;
1107
- }
1108
- win.addEventListener("blur", onBlur);
1109
- if (isMacSafari()) {
1110
- win.addEventListener("keydown", onKeyDown, true);
1111
- win.addEventListener("pointerdown", onPointerDown, true);
1112
- }
1113
- return () => {
1114
- win.removeEventListener("blur", onBlur);
1115
- if (isMacSafari()) {
1116
- win.removeEventListener("keydown", onKeyDown, true);
1117
- win.removeEventListener("pointerdown", onPointerDown, true);
1118
- }
1119
- };
1120
- }, [elements.domReference, open, enabled]);
1121
- React.useEffect(() => {
1122
- if (!enabled) return;
1123
- function onOpenChange2(_ref) {
1124
- let {
1125
- reason
1126
- } = _ref;
1127
- if (reason === "reference-press" || reason === "escape-key") {
1128
- blockFocusRef.current = true;
1129
- }
1130
- }
1131
- events.on("openchange", onOpenChange2);
1132
- return () => {
1133
- events.off("openchange", onOpenChange2);
1134
- };
1135
- }, [events, enabled]);
1136
- React.useEffect(() => {
1137
- return () => {
1138
- clearTimeoutIfSet(timeoutRef);
1139
- };
1140
- }, []);
1141
- const reference = React.useMemo(() => ({
1142
- onMouseLeave() {
1143
- blockFocusRef.current = false;
1144
- },
1145
- onFocus(event) {
1146
- if (blockFocusRef.current) return;
1147
- const target = getTarget(event.nativeEvent);
1148
- if (visibleOnly && isElement(target)) {
1149
- if (isMacSafari() && !event.relatedTarget) {
1150
- if (!keyboardModalityRef.current && !isTypeableElement(target)) {
1151
- return;
1152
- }
1153
- } else if (!matchesFocusVisible(target)) {
1154
- return;
1155
- }
1156
- }
1157
- onOpenChange(true, event.nativeEvent, "focus");
1158
- },
1159
- onBlur(event) {
1160
- blockFocusRef.current = false;
1161
- const relatedTarget = event.relatedTarget;
1162
- const nativeEvent = event.nativeEvent;
1163
- const movedToFocusGuard = isElement(relatedTarget) && relatedTarget.hasAttribute(createAttribute("focus-guard")) && relatedTarget.getAttribute("data-type") === "outside";
1164
- timeoutRef.current = window.setTimeout(() => {
1165
- var _dataRef$current$floa;
1166
- const activeEl = activeElement(elements.domReference ? elements.domReference.ownerDocument : document);
1167
- if (!relatedTarget && activeEl === elements.domReference) return;
1168
- if (contains((_dataRef$current$floa = dataRef.current.floatingContext) == null ? void 0 : _dataRef$current$floa.refs.floating.current, activeEl) || contains(elements.domReference, activeEl) || movedToFocusGuard) {
1169
- return;
1170
- }
1171
- onOpenChange(false, nativeEvent, "focus");
1172
- });
1173
- }
1174
- }), [dataRef, elements.domReference, onOpenChange, visibleOnly]);
1175
- return React.useMemo(() => enabled ? {
1176
- reference
1177
- } : {}, [enabled, reference]);
1178
- }
1179
- function mergeProps(userProps, propsList, elementKey) {
1180
- const map = /* @__PURE__ */ new Map();
1181
- const isItem = elementKey === "item";
1182
- let domUserProps = userProps;
1183
- if (isItem && userProps) {
1184
- const {
1185
- [ACTIVE_KEY]: _,
1186
- [SELECTED_KEY]: __,
1187
- ...validProps
1188
- } = userProps;
1189
- domUserProps = validProps;
1190
- }
1191
- return {
1192
- ...elementKey === "floating" && {
1193
- tabIndex: -1,
1194
- [FOCUSABLE_ATTRIBUTE]: ""
1195
- },
1196
- ...domUserProps,
1197
- ...propsList.map((value) => {
1198
- const propsOrGetProps = value ? value[elementKey] : null;
1199
- if (typeof propsOrGetProps === "function") {
1200
- return userProps ? propsOrGetProps(userProps) : null;
1201
- }
1202
- return propsOrGetProps;
1203
- }).concat(userProps).reduce((acc, props) => {
1204
- if (!props) {
1205
- return acc;
1206
- }
1207
- Object.entries(props).forEach((_ref) => {
1208
- let [key, value] = _ref;
1209
- if (isItem && [ACTIVE_KEY, SELECTED_KEY].includes(key)) {
1210
- return;
1211
- }
1212
- if (key.indexOf("on") === 0) {
1213
- if (!map.has(key)) {
1214
- map.set(key, []);
1215
- }
1216
- if (typeof value === "function") {
1217
- var _map$get;
1218
- (_map$get = map.get(key)) == null || _map$get.push(value);
1219
- acc[key] = function() {
1220
- var _map$get2;
1221
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1222
- args[_key] = arguments[_key];
1223
- }
1224
- return (_map$get2 = map.get(key)) == null ? void 0 : _map$get2.map((fn) => fn(...args)).find((val) => val !== void 0);
1225
- };
1226
- }
1227
- } else {
1228
- acc[key] = value;
1229
- }
1230
- });
1231
- return acc;
1232
- }, {})
1233
- };
1234
- }
1235
- function useInteractions(propsList) {
1236
- if (propsList === void 0) {
1237
- propsList = [];
1238
- }
1239
- const referenceDeps = propsList.map((key) => key == null ? void 0 : key.reference);
1240
- const floatingDeps = propsList.map((key) => key == null ? void 0 : key.floating);
1241
- const itemDeps = propsList.map((key) => key == null ? void 0 : key.item);
1242
- const getReferenceProps = React.useCallback(
1243
- (userProps) => mergeProps(userProps, propsList, "reference"),
1244
- // eslint-disable-next-line react-hooks/exhaustive-deps
1245
- referenceDeps
1246
- );
1247
- const getFloatingProps = React.useCallback(
1248
- (userProps) => mergeProps(userProps, propsList, "floating"),
1249
- // eslint-disable-next-line react-hooks/exhaustive-deps
1250
- floatingDeps
1251
- );
1252
- const getItemProps = React.useCallback(
1253
- (userProps) => mergeProps(userProps, propsList, "item"),
1254
- // eslint-disable-next-line react-hooks/exhaustive-deps
1255
- itemDeps
1256
- );
1257
- return React.useMemo(() => ({
1258
- getReferenceProps,
1259
- getFloatingProps,
1260
- getItemProps
1261
- }), [getReferenceProps, getFloatingProps, getItemProps]);
1262
- }
1263
- const componentRoleToAriaRoleMap = /* @__PURE__ */ new Map([["select", "listbox"], ["combobox", "listbox"], ["label", false]]);
1264
- function useRole(context, props) {
1265
- var _elements$domReferenc, _componentRoleToAriaR;
1266
- if (props === void 0) {
1267
- props = {};
1268
- }
1269
- const {
1270
- open,
1271
- elements,
1272
- floatingId: defaultFloatingId
1273
- } = context;
1274
- const {
1275
- enabled = true,
1276
- role = "dialog"
1277
- } = props;
1278
- const defaultReferenceId = useId();
1279
- const referenceId = ((_elements$domReferenc = elements.domReference) == null ? void 0 : _elements$domReferenc.id) || defaultReferenceId;
1280
- const floatingId = React.useMemo(() => {
1281
- var _getFloatingFocusElem;
1282
- return ((_getFloatingFocusElem = getFloatingFocusElement(elements.floating)) == null ? void 0 : _getFloatingFocusElem.id) || defaultFloatingId;
1283
- }, [elements.floating, defaultFloatingId]);
1284
- const ariaRole = (_componentRoleToAriaR = componentRoleToAriaRoleMap.get(role)) != null ? _componentRoleToAriaR : role;
1285
- const parentId = useFloatingParentNodeId();
1286
- const isNested = parentId != null;
1287
- const reference = React.useMemo(() => {
1288
- if (ariaRole === "tooltip" || role === "label") {
1289
- return {
1290
- ["aria-" + (role === "label" ? "labelledby" : "describedby")]: open ? floatingId : void 0
1291
- };
1292
- }
1293
- return {
1294
- "aria-expanded": open ? "true" : "false",
1295
- "aria-haspopup": ariaRole === "alertdialog" ? "dialog" : ariaRole,
1296
- "aria-controls": open ? floatingId : void 0,
1297
- ...ariaRole === "listbox" && {
1298
- role: "combobox"
1299
- },
1300
- ...ariaRole === "menu" && {
1301
- id: referenceId
1302
- },
1303
- ...ariaRole === "menu" && isNested && {
1304
- role: "menuitem"
1305
- },
1306
- ...role === "select" && {
1307
- "aria-autocomplete": "none"
1308
- },
1309
- ...role === "combobox" && {
1310
- "aria-autocomplete": "list"
1311
- }
1312
- };
1313
- }, [ariaRole, floatingId, isNested, open, referenceId, role]);
1314
- const floating = React.useMemo(() => {
1315
- const floatingProps = {
1316
- id: floatingId,
1317
- ...ariaRole && {
1318
- role: ariaRole
1319
- }
1320
- };
1321
- if (ariaRole === "tooltip" || role === "label") {
1322
- return floatingProps;
1323
- }
1324
- return {
1325
- ...floatingProps,
1326
- ...ariaRole === "menu" && {
1327
- "aria-labelledby": referenceId
1328
- }
1329
- };
1330
- }, [ariaRole, floatingId, referenceId, role]);
1331
- const item = React.useCallback((_ref) => {
1332
- let {
1333
- active,
1334
- selected
1335
- } = _ref;
1336
- const commonProps = {
1337
- role: "option",
1338
- ...active && {
1339
- id: floatingId + "-fui-option"
1340
- }
1341
- };
1342
- switch (role) {
1343
- case "select":
1344
- case "combobox":
1345
- return {
1346
- ...commonProps,
1347
- "aria-selected": selected
1348
- };
1349
- }
1350
- return {};
1351
- }, [floatingId, role]);
1352
- return React.useMemo(() => enabled ? {
1353
- reference,
1354
- floating,
1355
- item
1356
- } : {}, [enabled, reference, floating, item]);
1357
- }
1358
- const Tooltip = ({ children, content, className, placement = "top", showArrow = true }) => {
1359
- const [isOpen, setIsOpen] = useState(false);
1360
- const arrowRef = useRef(null);
1361
- const { refs, floatingStyles, context } = useFloating({
1362
- open: isOpen,
1363
- onOpenChange: setIsOpen,
1364
- placement,
1365
- middleware: [offset(8), flip(), shift(), arrow({ element: arrowRef })],
1366
- whileElementsMounted: autoUpdate
1367
- });
1368
- const hover = useHover(context);
1369
- const focus = useFocus(context);
1370
- const dismiss = useDismiss(context);
1371
- const role = useRole(context);
1372
- const { getReferenceProps, getFloatingProps } = useInteractions([hover, focus, dismiss, role]);
1373
- const mergedClass = twMerge(
1374
- clsx("bg-content1 font-normal text-sm rounded-md filter-(--filter-drop-shadow-small) flex justify-center items-center z-10 px-2.5 py-1 outline-none box-border subpixel-antialiased normal-case", className)
1375
- );
1376
- return /* @__PURE__ */ jsxs(Fragment, { children: [
1377
- /* @__PURE__ */ jsx("div", { ref: refs.setReference, ...getReferenceProps(), children }),
1378
- isOpen && /* @__PURE__ */ jsxs("div", { ref: refs.setFloating, style: floatingStyles, ...getFloatingProps(), className: mergedClass, children: [
1379
- content,
1380
- showArrow && /* @__PURE__ */ jsx(FloatingArrow, { ref: arrowRef, context, className: "text-content1", fill: "currentColor" })
1381
- ] })
1382
- ] });
1383
- };
1384
- export {
1385
- Tooltip as T
1386
- };
1387
- //# sourceMappingURL=tooltip-JwIbppjO.js.map