@octanejs/floating-ui 0.1.32 → 0.1.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Composite.cjs +235 -0
- package/dist/cjs/FloatingArrow.cjs +143 -0
- package/dist/cjs/FloatingFocusManager.cjs +701 -0
- package/dist/cjs/FloatingList.cjs +145 -0
- package/dist/cjs/FloatingOverlay.cjs +100 -0
- package/dist/cjs/FloatingPortal.cjs +241 -0
- package/dist/cjs/context.cjs +184 -0
- package/dist/cjs/delayGroup.cjs +154 -0
- package/dist/cjs/index.cjs +166 -0
- package/dist/cjs/internal.cjs +51 -0
- package/dist/cjs/pubsub.cjs +44 -0
- package/dist/cjs/safePolygon.cjs +269 -0
- package/dist/cjs/transitions.cjs +150 -0
- package/dist/cjs/tree.cjs +105 -0
- package/dist/cjs/types.cjs +16 -0
- package/dist/cjs/useClick.cjs +139 -0
- package/dist/cjs/useClientPoint.cjs +201 -0
- package/dist/cjs/useDismiss.cjs +337 -0
- package/dist/cjs/useFloating.cjs +224 -0
- package/dist/cjs/useFocus.cjs +146 -0
- package/dist/cjs/useHover.cjs +393 -0
- package/dist/cjs/useId.cjs +31 -0
- package/dist/cjs/useInteractions.cjs +106 -0
- package/dist/cjs/useListNavigation.cjs +633 -0
- package/dist/cjs/useMergeRefs.cjs +77 -0
- package/dist/cjs/useRole.cjs +118 -0
- package/dist/cjs/useTypeahead.cjs +164 -0
- package/dist/cjs/utils/index.cjs +709 -0
- package/package.json +13 -6
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useFocus_exports = {};
|
|
20
|
+
__export(useFocus_exports, {
|
|
21
|
+
useFocus: () => useFocus
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useFocus_exports);
|
|
24
|
+
var import_dom = require("@floating-ui/utils/dom");
|
|
25
|
+
var import_octane = require("octane");
|
|
26
|
+
var import_internal = require("./internal.cjs");
|
|
27
|
+
var import_utils = require("./utils/index.cjs");
|
|
28
|
+
function useFocus(...args) {
|
|
29
|
+
const [user, slot] = (0, import_internal.splitSlot)(args);
|
|
30
|
+
const context = user[0];
|
|
31
|
+
const props = user[1] ?? {};
|
|
32
|
+
const open = context.open;
|
|
33
|
+
const onOpenChange = context.onOpenChange;
|
|
34
|
+
const events = context.events;
|
|
35
|
+
const dataRef = context.dataRef;
|
|
36
|
+
const elements = context.elements;
|
|
37
|
+
const enabled = props.enabled ?? true;
|
|
38
|
+
const visibleOnly = props.visibleOnly ?? true;
|
|
39
|
+
const blockFocusRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "block"));
|
|
40
|
+
const timeoutRef = (0, import_octane.useRef)(-1, (0, import_internal.subSlot)(slot, "timeout"));
|
|
41
|
+
const keyboardModalityRef = (0, import_octane.useRef)(true, (0, import_internal.subSlot)(slot, "kbd"));
|
|
42
|
+
(0, import_octane.useEffect)(
|
|
43
|
+
() => {
|
|
44
|
+
if (!enabled) return;
|
|
45
|
+
const win = (0, import_dom.getWindow)(elements.domReference);
|
|
46
|
+
function onBlur() {
|
|
47
|
+
if (!open && (0, import_dom.isHTMLElement)(elements.domReference) && elements.domReference === (0, import_utils.activeElement)((0, import_utils.getDocument)(elements.domReference))) {
|
|
48
|
+
blockFocusRef.current = true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function onKeyDown() {
|
|
52
|
+
keyboardModalityRef.current = true;
|
|
53
|
+
}
|
|
54
|
+
function onPointerDown() {
|
|
55
|
+
keyboardModalityRef.current = false;
|
|
56
|
+
}
|
|
57
|
+
win.addEventListener("blur", onBlur);
|
|
58
|
+
if ((0, import_utils.isMacSafari)()) {
|
|
59
|
+
win.addEventListener("keydown", onKeyDown, true);
|
|
60
|
+
win.addEventListener("pointerdown", onPointerDown, true);
|
|
61
|
+
}
|
|
62
|
+
return () => {
|
|
63
|
+
win.removeEventListener("blur", onBlur);
|
|
64
|
+
if ((0, import_utils.isMacSafari)()) {
|
|
65
|
+
win.removeEventListener("keydown", onKeyDown, true);
|
|
66
|
+
win.removeEventListener("pointerdown", onPointerDown, true);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
[elements.domReference, open, enabled],
|
|
71
|
+
(0, import_internal.subSlot)(slot, "e:win")
|
|
72
|
+
);
|
|
73
|
+
(0, import_octane.useEffect)(
|
|
74
|
+
() => {
|
|
75
|
+
if (!enabled) return;
|
|
76
|
+
function onOpenChangeLocal(_ref) {
|
|
77
|
+
const { reason } = _ref;
|
|
78
|
+
if (reason === "reference-press" || reason === "escape-key") {
|
|
79
|
+
blockFocusRef.current = true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
events.on("openchange", onOpenChangeLocal);
|
|
83
|
+
return () => {
|
|
84
|
+
events.off("openchange", onOpenChangeLocal);
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
[events, enabled],
|
|
88
|
+
(0, import_internal.subSlot)(slot, "e:oc")
|
|
89
|
+
);
|
|
90
|
+
(0, import_octane.useEffect)(
|
|
91
|
+
() => {
|
|
92
|
+
return () => {
|
|
93
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutRef);
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
[],
|
|
97
|
+
(0, import_internal.subSlot)(slot, "e:cleanup")
|
|
98
|
+
);
|
|
99
|
+
const reference = (0, import_octane.useMemo)(
|
|
100
|
+
() => ({
|
|
101
|
+
onMouseLeave() {
|
|
102
|
+
blockFocusRef.current = false;
|
|
103
|
+
},
|
|
104
|
+
onFocus(event) {
|
|
105
|
+
if (blockFocusRef.current) return;
|
|
106
|
+
const target = (0, import_utils.getTarget)(event);
|
|
107
|
+
if (visibleOnly && (0, import_dom.isElement)(target)) {
|
|
108
|
+
if ((0, import_utils.isMacSafari)() && !event.relatedTarget) {
|
|
109
|
+
if (!keyboardModalityRef.current && !(0, import_utils.isTypeableElement)(target)) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
} else if (!(0, import_utils.matchesFocusVisible)(target)) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
onOpenChange(true, event, "focus");
|
|
117
|
+
},
|
|
118
|
+
onBlur(event) {
|
|
119
|
+
blockFocusRef.current = false;
|
|
120
|
+
const relatedTarget = event.relatedTarget;
|
|
121
|
+
const movedToFocusGuard = (0, import_dom.isElement)(relatedTarget) && relatedTarget.hasAttribute((0, import_utils.createAttribute)("focus-guard")) && relatedTarget.getAttribute("data-type") === "outside";
|
|
122
|
+
timeoutRef.current = window.setTimeout(() => {
|
|
123
|
+
const activeEl = (0, import_utils.activeElement)(
|
|
124
|
+
elements.domReference ? elements.domReference.ownerDocument : document
|
|
125
|
+
);
|
|
126
|
+
if (!relatedTarget && activeEl === elements.domReference) return;
|
|
127
|
+
if ((0, import_utils.contains)(dataRef.current.floatingContext?.refs.floating.current, activeEl) || (0, import_utils.contains)(elements.domReference, activeEl) || movedToFocusGuard) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
onOpenChange(false, event, "focus");
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}),
|
|
134
|
+
[dataRef, elements.domReference, onOpenChange, visibleOnly],
|
|
135
|
+
(0, import_internal.subSlot)(slot, "m:ref")
|
|
136
|
+
);
|
|
137
|
+
return (0, import_octane.useMemo)(
|
|
138
|
+
() => enabled ? { reference } : {},
|
|
139
|
+
[enabled, reference],
|
|
140
|
+
(0, import_internal.subSlot)(slot, "m:ret")
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
144
|
+
0 && (module.exports = {
|
|
145
|
+
useFocus
|
|
146
|
+
});
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useHover_exports = {};
|
|
20
|
+
__export(useHover_exports, {
|
|
21
|
+
useHover: () => useHover
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useHover_exports);
|
|
24
|
+
var import_dom = require("@floating-ui/utils/dom");
|
|
25
|
+
var import_octane = require("octane");
|
|
26
|
+
var import_internal = require("./internal.cjs");
|
|
27
|
+
var import_tree = require("./tree.cjs");
|
|
28
|
+
var import_utils = require("./utils/index.cjs");
|
|
29
|
+
const safePolygonIdentifier = (0, import_utils.createAttribute)("safe-polygon");
|
|
30
|
+
function getRestMs(value) {
|
|
31
|
+
if (typeof value === "function") {
|
|
32
|
+
return value();
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
function useHover(...args) {
|
|
37
|
+
const [user, slot] = (0, import_internal.splitSlot)(args);
|
|
38
|
+
const context = user[0];
|
|
39
|
+
const props = user[1] ?? {};
|
|
40
|
+
const open = context.open;
|
|
41
|
+
const onOpenChange = context.onOpenChange;
|
|
42
|
+
const dataRef = context.dataRef;
|
|
43
|
+
const events = context.events;
|
|
44
|
+
const elements = context.elements;
|
|
45
|
+
const enabled = props.enabled ?? true;
|
|
46
|
+
const delay = props.delay ?? 0;
|
|
47
|
+
const handleClose = props.handleClose ?? null;
|
|
48
|
+
const mouseOnly = props.mouseOnly ?? false;
|
|
49
|
+
const restMs = props.restMs ?? 0;
|
|
50
|
+
const move = props.move ?? true;
|
|
51
|
+
const tree = (0, import_tree.useFloatingTree)();
|
|
52
|
+
const parentId = (0, import_tree.useFloatingParentNodeId)();
|
|
53
|
+
const handleCloseRef = (0, import_utils.useLatestRef)(handleClose, (0, import_internal.subSlot)(slot, "hc"));
|
|
54
|
+
const delayRef = (0, import_utils.useLatestRef)(delay, (0, import_internal.subSlot)(slot, "delay"));
|
|
55
|
+
const openRef = (0, import_utils.useLatestRef)(open, (0, import_internal.subSlot)(slot, "open"));
|
|
56
|
+
const restMsRef = (0, import_utils.useLatestRef)(restMs, (0, import_internal.subSlot)(slot, "restms"));
|
|
57
|
+
const pointerTypeRef = (0, import_octane.useRef)(void 0, (0, import_internal.subSlot)(slot, "ptype"));
|
|
58
|
+
const timeoutRef = (0, import_octane.useRef)(-1, (0, import_internal.subSlot)(slot, "timeout"));
|
|
59
|
+
const handlerRef = (0, import_octane.useRef)(
|
|
60
|
+
void 0,
|
|
61
|
+
(0, import_internal.subSlot)(slot, "handler")
|
|
62
|
+
);
|
|
63
|
+
const restTimeoutRef = (0, import_octane.useRef)(-1, (0, import_internal.subSlot)(slot, "resttimeout"));
|
|
64
|
+
const blockMouseMoveRef = (0, import_octane.useRef)(true, (0, import_internal.subSlot)(slot, "block"));
|
|
65
|
+
const performedPointerEventsMutationRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "ppem"));
|
|
66
|
+
const unbindMouseMoveRef = (0, import_octane.useRef)(() => {
|
|
67
|
+
}, (0, import_internal.subSlot)(slot, "unbind"));
|
|
68
|
+
const restTimeoutPendingRef = (0, import_octane.useRef)(false, (0, import_internal.subSlot)(slot, "rtp"));
|
|
69
|
+
const isHoverOpen = (0, import_utils.useEffectEvent)(
|
|
70
|
+
() => {
|
|
71
|
+
const type = dataRef.current.openEvent?.type;
|
|
72
|
+
return type?.includes("mouse") && type !== "mousedown";
|
|
73
|
+
},
|
|
74
|
+
(0, import_internal.subSlot)(slot, "ishover")
|
|
75
|
+
);
|
|
76
|
+
(0, import_octane.useEffect)(
|
|
77
|
+
() => {
|
|
78
|
+
if (!enabled) return;
|
|
79
|
+
function onOpenChangeLocal(_ref) {
|
|
80
|
+
const { open: o } = _ref;
|
|
81
|
+
if (!o) {
|
|
82
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutRef);
|
|
83
|
+
(0, import_utils.clearTimeoutIfSet)(restTimeoutRef);
|
|
84
|
+
blockMouseMoveRef.current = true;
|
|
85
|
+
restTimeoutPendingRef.current = false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
events.on("openchange", onOpenChangeLocal);
|
|
89
|
+
return () => {
|
|
90
|
+
events.off("openchange", onOpenChangeLocal);
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
[enabled, events],
|
|
94
|
+
(0, import_internal.subSlot)(slot, "e:oc")
|
|
95
|
+
);
|
|
96
|
+
(0, import_octane.useEffect)(
|
|
97
|
+
() => {
|
|
98
|
+
if (!enabled) return;
|
|
99
|
+
if (!handleCloseRef.current) return;
|
|
100
|
+
if (!open) return;
|
|
101
|
+
function onLeave(event) {
|
|
102
|
+
if (isHoverOpen()) {
|
|
103
|
+
onOpenChange(false, event, "hover");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const html = (0, import_utils.getDocument)(elements.floating).documentElement;
|
|
107
|
+
html.addEventListener("mouseleave", onLeave);
|
|
108
|
+
return () => {
|
|
109
|
+
html.removeEventListener("mouseleave", onLeave);
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
[elements.floating, open, onOpenChange, enabled, handleCloseRef, isHoverOpen],
|
|
113
|
+
(0, import_internal.subSlot)(slot, "e:leave")
|
|
114
|
+
);
|
|
115
|
+
const closeWithDelay = (0, import_octane.useCallback)(
|
|
116
|
+
(event, runElseBranch = true, reason = "hover") => {
|
|
117
|
+
const closeDelay = (0, import_utils.getDelay)(delayRef.current, "close", pointerTypeRef.current);
|
|
118
|
+
if (closeDelay && !handlerRef.current) {
|
|
119
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutRef);
|
|
120
|
+
timeoutRef.current = window.setTimeout(
|
|
121
|
+
() => onOpenChange(false, event, reason),
|
|
122
|
+
closeDelay
|
|
123
|
+
);
|
|
124
|
+
} else if (runElseBranch) {
|
|
125
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutRef);
|
|
126
|
+
onOpenChange(false, event, reason);
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
[delayRef, onOpenChange],
|
|
130
|
+
(0, import_internal.subSlot)(slot, "cwd")
|
|
131
|
+
);
|
|
132
|
+
const cleanupMouseMoveHandler = (0, import_utils.useEffectEvent)(
|
|
133
|
+
() => {
|
|
134
|
+
unbindMouseMoveRef.current();
|
|
135
|
+
handlerRef.current = void 0;
|
|
136
|
+
},
|
|
137
|
+
(0, import_internal.subSlot)(slot, "cleanupmm")
|
|
138
|
+
);
|
|
139
|
+
const clearPointerEvents = (0, import_utils.useEffectEvent)(
|
|
140
|
+
() => {
|
|
141
|
+
if (performedPointerEventsMutationRef.current) {
|
|
142
|
+
const body = (0, import_utils.getDocument)(elements.floating).body;
|
|
143
|
+
body.style.pointerEvents = "";
|
|
144
|
+
body.removeAttribute(safePolygonIdentifier);
|
|
145
|
+
performedPointerEventsMutationRef.current = false;
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
(0, import_internal.subSlot)(slot, "clearpe")
|
|
149
|
+
);
|
|
150
|
+
const isClickLikeOpenEvent = (0, import_utils.useEffectEvent)(
|
|
151
|
+
() => {
|
|
152
|
+
return dataRef.current.openEvent ? ["click", "mousedown"].includes(dataRef.current.openEvent.type) : false;
|
|
153
|
+
},
|
|
154
|
+
(0, import_internal.subSlot)(slot, "isclick")
|
|
155
|
+
);
|
|
156
|
+
(0, import_octane.useEffect)(
|
|
157
|
+
() => {
|
|
158
|
+
if (!enabled) return;
|
|
159
|
+
function onReferenceMouseEnter(event) {
|
|
160
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutRef);
|
|
161
|
+
blockMouseMoveRef.current = false;
|
|
162
|
+
if (mouseOnly && !(0, import_utils.isMouseLikePointerType)(pointerTypeRef.current) || getRestMs(restMsRef.current) > 0 && !(0, import_utils.getDelay)(delayRef.current, "open")) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const openDelay = (0, import_utils.getDelay)(delayRef.current, "open", pointerTypeRef.current);
|
|
166
|
+
if (openDelay) {
|
|
167
|
+
timeoutRef.current = window.setTimeout(() => {
|
|
168
|
+
if (!openRef.current) {
|
|
169
|
+
onOpenChange(true, event, "hover");
|
|
170
|
+
}
|
|
171
|
+
}, openDelay);
|
|
172
|
+
} else if (!open) {
|
|
173
|
+
onOpenChange(true, event, "hover");
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function onReferenceMouseLeave(event) {
|
|
177
|
+
if (isClickLikeOpenEvent()) {
|
|
178
|
+
clearPointerEvents();
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
unbindMouseMoveRef.current();
|
|
182
|
+
const doc = (0, import_utils.getDocument)(elements.floating);
|
|
183
|
+
(0, import_utils.clearTimeoutIfSet)(restTimeoutRef);
|
|
184
|
+
restTimeoutPendingRef.current = false;
|
|
185
|
+
if (handleCloseRef.current && dataRef.current.floatingContext) {
|
|
186
|
+
if (!open) {
|
|
187
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutRef);
|
|
188
|
+
}
|
|
189
|
+
handlerRef.current = handleCloseRef.current({
|
|
190
|
+
...dataRef.current.floatingContext,
|
|
191
|
+
tree,
|
|
192
|
+
x: event.clientX,
|
|
193
|
+
y: event.clientY,
|
|
194
|
+
onClose() {
|
|
195
|
+
clearPointerEvents();
|
|
196
|
+
cleanupMouseMoveHandler();
|
|
197
|
+
if (!isClickLikeOpenEvent()) {
|
|
198
|
+
closeWithDelay(event, true, "safe-polygon");
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
const handler = handlerRef.current;
|
|
203
|
+
doc.addEventListener("mousemove", handler);
|
|
204
|
+
unbindMouseMoveRef.current = () => {
|
|
205
|
+
doc.removeEventListener("mousemove", handler);
|
|
206
|
+
};
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
const shouldClose = pointerTypeRef.current === "touch" ? !(0, import_utils.contains)(elements.floating, event.relatedTarget) : true;
|
|
210
|
+
if (shouldClose) {
|
|
211
|
+
closeWithDelay(event);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function onScrollMouseLeave(event) {
|
|
215
|
+
if (isClickLikeOpenEvent()) return;
|
|
216
|
+
if (!dataRef.current.floatingContext) return;
|
|
217
|
+
handleCloseRef.current?.({
|
|
218
|
+
...dataRef.current.floatingContext,
|
|
219
|
+
tree,
|
|
220
|
+
x: event.clientX,
|
|
221
|
+
y: event.clientY,
|
|
222
|
+
onClose() {
|
|
223
|
+
clearPointerEvents();
|
|
224
|
+
cleanupMouseMoveHandler();
|
|
225
|
+
if (!isClickLikeOpenEvent()) {
|
|
226
|
+
closeWithDelay(event);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
})(event);
|
|
230
|
+
}
|
|
231
|
+
function onFloatingMouseEnter() {
|
|
232
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutRef);
|
|
233
|
+
}
|
|
234
|
+
function onFloatingMouseLeave(event) {
|
|
235
|
+
if (!isClickLikeOpenEvent()) {
|
|
236
|
+
closeWithDelay(event, false);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if ((0, import_dom.isElement)(elements.domReference)) {
|
|
240
|
+
const reference2 = elements.domReference;
|
|
241
|
+
const floating = elements.floating;
|
|
242
|
+
if (open) {
|
|
243
|
+
reference2.addEventListener("mouseleave", onScrollMouseLeave);
|
|
244
|
+
}
|
|
245
|
+
if (move) {
|
|
246
|
+
reference2.addEventListener("mousemove", onReferenceMouseEnter, { once: true });
|
|
247
|
+
}
|
|
248
|
+
reference2.addEventListener("mouseenter", onReferenceMouseEnter);
|
|
249
|
+
reference2.addEventListener("mouseleave", onReferenceMouseLeave);
|
|
250
|
+
if (floating) {
|
|
251
|
+
floating.addEventListener("mouseleave", onScrollMouseLeave);
|
|
252
|
+
floating.addEventListener("mouseenter", onFloatingMouseEnter);
|
|
253
|
+
floating.addEventListener("mouseleave", onFloatingMouseLeave);
|
|
254
|
+
}
|
|
255
|
+
return () => {
|
|
256
|
+
if (open) {
|
|
257
|
+
reference2.removeEventListener("mouseleave", onScrollMouseLeave);
|
|
258
|
+
}
|
|
259
|
+
if (move) {
|
|
260
|
+
reference2.removeEventListener("mousemove", onReferenceMouseEnter);
|
|
261
|
+
}
|
|
262
|
+
reference2.removeEventListener("mouseenter", onReferenceMouseEnter);
|
|
263
|
+
reference2.removeEventListener("mouseleave", onReferenceMouseLeave);
|
|
264
|
+
if (floating) {
|
|
265
|
+
floating.removeEventListener("mouseleave", onScrollMouseLeave);
|
|
266
|
+
floating.removeEventListener("mouseenter", onFloatingMouseEnter);
|
|
267
|
+
floating.removeEventListener("mouseleave", onFloatingMouseLeave);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
[
|
|
273
|
+
elements,
|
|
274
|
+
enabled,
|
|
275
|
+
context,
|
|
276
|
+
mouseOnly,
|
|
277
|
+
move,
|
|
278
|
+
closeWithDelay,
|
|
279
|
+
cleanupMouseMoveHandler,
|
|
280
|
+
clearPointerEvents,
|
|
281
|
+
onOpenChange,
|
|
282
|
+
open,
|
|
283
|
+
openRef,
|
|
284
|
+
tree,
|
|
285
|
+
delayRef,
|
|
286
|
+
handleCloseRef,
|
|
287
|
+
dataRef,
|
|
288
|
+
isClickLikeOpenEvent,
|
|
289
|
+
restMsRef
|
|
290
|
+
],
|
|
291
|
+
(0, import_internal.subSlot)(slot, "e:refevents")
|
|
292
|
+
);
|
|
293
|
+
(0, import_utils.useModernLayoutEffect)(
|
|
294
|
+
() => {
|
|
295
|
+
if (!enabled) return;
|
|
296
|
+
if (open && handleCloseRef.current?.__options?.blockPointerEvents && isHoverOpen()) {
|
|
297
|
+
performedPointerEventsMutationRef.current = true;
|
|
298
|
+
const floatingEl = elements.floating;
|
|
299
|
+
if ((0, import_dom.isElement)(elements.domReference) && floatingEl) {
|
|
300
|
+
const body = (0, import_utils.getDocument)(elements.floating).body;
|
|
301
|
+
body.setAttribute(safePolygonIdentifier, "");
|
|
302
|
+
const ref = elements.domReference;
|
|
303
|
+
const parentFloating = tree?.nodesRef.current.find((node) => node.id === parentId)?.context?.elements.floating;
|
|
304
|
+
if (parentFloating) {
|
|
305
|
+
parentFloating.style.pointerEvents = "";
|
|
306
|
+
}
|
|
307
|
+
body.style.pointerEvents = "none";
|
|
308
|
+
ref.style.pointerEvents = "auto";
|
|
309
|
+
floatingEl.style.pointerEvents = "auto";
|
|
310
|
+
return () => {
|
|
311
|
+
body.style.pointerEvents = "";
|
|
312
|
+
ref.style.pointerEvents = "";
|
|
313
|
+
floatingEl.style.pointerEvents = "";
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
[enabled, open, parentId, elements, tree, handleCloseRef, isHoverOpen],
|
|
319
|
+
(0, import_internal.subSlot)(slot, "e:blockpe")
|
|
320
|
+
);
|
|
321
|
+
(0, import_utils.useModernLayoutEffect)(
|
|
322
|
+
() => {
|
|
323
|
+
if (!open) {
|
|
324
|
+
pointerTypeRef.current = void 0;
|
|
325
|
+
restTimeoutPendingRef.current = false;
|
|
326
|
+
cleanupMouseMoveHandler();
|
|
327
|
+
clearPointerEvents();
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
[open, cleanupMouseMoveHandler, clearPointerEvents],
|
|
331
|
+
(0, import_internal.subSlot)(slot, "e:reset")
|
|
332
|
+
);
|
|
333
|
+
(0, import_octane.useEffect)(
|
|
334
|
+
() => {
|
|
335
|
+
return () => {
|
|
336
|
+
cleanupMouseMoveHandler();
|
|
337
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutRef);
|
|
338
|
+
(0, import_utils.clearTimeoutIfSet)(restTimeoutRef);
|
|
339
|
+
clearPointerEvents();
|
|
340
|
+
};
|
|
341
|
+
},
|
|
342
|
+
[enabled, elements.domReference, cleanupMouseMoveHandler, clearPointerEvents],
|
|
343
|
+
(0, import_internal.subSlot)(slot, "e:cleanup")
|
|
344
|
+
);
|
|
345
|
+
const reference = (0, import_octane.useMemo)(
|
|
346
|
+
() => {
|
|
347
|
+
function setPointerRef(event) {
|
|
348
|
+
pointerTypeRef.current = event.pointerType;
|
|
349
|
+
}
|
|
350
|
+
return {
|
|
351
|
+
onPointerDown: setPointerRef,
|
|
352
|
+
onPointerEnter: setPointerRef,
|
|
353
|
+
onMouseMove(event) {
|
|
354
|
+
function handleMouseMove() {
|
|
355
|
+
if (!blockMouseMoveRef.current && !openRef.current) {
|
|
356
|
+
onOpenChange(true, event, "hover");
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
if (mouseOnly && !(0, import_utils.isMouseLikePointerType)(pointerTypeRef.current)) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
if (open || getRestMs(restMsRef.current) === 0) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
if (restTimeoutPendingRef.current && event.movementX ** 2 + event.movementY ** 2 < 2) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
(0, import_utils.clearTimeoutIfSet)(restTimeoutRef);
|
|
369
|
+
if (pointerTypeRef.current === "touch") {
|
|
370
|
+
handleMouseMove();
|
|
371
|
+
} else {
|
|
372
|
+
restTimeoutPendingRef.current = true;
|
|
373
|
+
restTimeoutRef.current = window.setTimeout(
|
|
374
|
+
handleMouseMove,
|
|
375
|
+
getRestMs(restMsRef.current)
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
},
|
|
381
|
+
[mouseOnly, onOpenChange, open, openRef, restMsRef],
|
|
382
|
+
(0, import_internal.subSlot)(slot, "m:ref")
|
|
383
|
+
);
|
|
384
|
+
return (0, import_octane.useMemo)(
|
|
385
|
+
() => enabled ? { reference } : {},
|
|
386
|
+
[enabled, reference],
|
|
387
|
+
(0, import_internal.subSlot)(slot, "m:ret")
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
391
|
+
0 && (module.exports = {
|
|
392
|
+
useHover
|
|
393
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useId_exports = {};
|
|
20
|
+
__export(useId_exports, {
|
|
21
|
+
useId: () => useId
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useId_exports);
|
|
24
|
+
var import_octane = require("octane");
|
|
25
|
+
function useId(slot) {
|
|
26
|
+
return (0, import_octane.useId)(slot);
|
|
27
|
+
}
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
useId
|
|
31
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var useInteractions_exports = {};
|
|
20
|
+
__export(useInteractions_exports, {
|
|
21
|
+
useInteractions: () => useInteractions
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(useInteractions_exports);
|
|
24
|
+
var import_octane = require("octane");
|
|
25
|
+
var import_internal = require("./internal.cjs");
|
|
26
|
+
var import_utils = require("./utils/index.cjs");
|
|
27
|
+
const ACTIVE_KEY = "active";
|
|
28
|
+
const SELECTED_KEY = "selected";
|
|
29
|
+
function mergeProps(userProps, propsList, elementKey) {
|
|
30
|
+
const map = /* @__PURE__ */ new Map();
|
|
31
|
+
const isItem = elementKey === "item";
|
|
32
|
+
let domUserProps = userProps;
|
|
33
|
+
if (isItem && userProps) {
|
|
34
|
+
const { [ACTIVE_KEY]: _a, [SELECTED_KEY]: _s, ...validProps } = userProps;
|
|
35
|
+
domUserProps = validProps;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
...elementKey === "floating" && {
|
|
39
|
+
tabIndex: -1,
|
|
40
|
+
[import_utils.FOCUSABLE_ATTRIBUTE]: ""
|
|
41
|
+
},
|
|
42
|
+
...domUserProps,
|
|
43
|
+
...propsList.map((value) => {
|
|
44
|
+
const propsOrGetProps = value ? value[elementKey] : null;
|
|
45
|
+
if (typeof propsOrGetProps === "function") {
|
|
46
|
+
return userProps ? propsOrGetProps(userProps) : null;
|
|
47
|
+
}
|
|
48
|
+
return propsOrGetProps;
|
|
49
|
+
}).concat(userProps).reduce((acc, props) => {
|
|
50
|
+
if (!props) {
|
|
51
|
+
return acc;
|
|
52
|
+
}
|
|
53
|
+
Object.entries(props).forEach((_ref) => {
|
|
54
|
+
const [key, value] = _ref;
|
|
55
|
+
if (isItem && [ACTIVE_KEY, SELECTED_KEY].includes(key)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (key.indexOf("on") === 0) {
|
|
59
|
+
if (!map.has(key)) {
|
|
60
|
+
map.set(key, []);
|
|
61
|
+
}
|
|
62
|
+
if (typeof value === "function") {
|
|
63
|
+
map.get(key)?.push(value);
|
|
64
|
+
acc[key] = function(...args) {
|
|
65
|
+
return map.get(key)?.map((fn) => fn(...args)).find((val) => val !== void 0);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
acc[key] = value;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return acc;
|
|
73
|
+
}, {})
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function useInteractions(...args) {
|
|
77
|
+
const [user, slot] = (0, import_internal.splitSlot)(args);
|
|
78
|
+
const propsList = user[0] ?? [];
|
|
79
|
+
const referenceDeps = propsList.map((key) => key == null ? void 0 : key.reference);
|
|
80
|
+
const floatingDeps = propsList.map((key) => key == null ? void 0 : key.floating);
|
|
81
|
+
const itemDeps = propsList.map((key) => key == null ? void 0 : key.item);
|
|
82
|
+
const getReferenceProps = (0, import_octane.useCallback)(
|
|
83
|
+
(userProps) => mergeProps(userProps, propsList, "reference"),
|
|
84
|
+
referenceDeps,
|
|
85
|
+
(0, import_internal.subSlot)(slot, "ref")
|
|
86
|
+
);
|
|
87
|
+
const getFloatingProps = (0, import_octane.useCallback)(
|
|
88
|
+
(userProps) => mergeProps(userProps, propsList, "floating"),
|
|
89
|
+
floatingDeps,
|
|
90
|
+
(0, import_internal.subSlot)(slot, "flo")
|
|
91
|
+
);
|
|
92
|
+
const getItemProps = (0, import_octane.useCallback)(
|
|
93
|
+
(userProps) => mergeProps(userProps, propsList, "item"),
|
|
94
|
+
itemDeps,
|
|
95
|
+
(0, import_internal.subSlot)(slot, "item")
|
|
96
|
+
);
|
|
97
|
+
return (0, import_octane.useMemo)(
|
|
98
|
+
() => ({ getReferenceProps, getFloatingProps, getItemProps }),
|
|
99
|
+
[getReferenceProps, getFloatingProps, getItemProps],
|
|
100
|
+
(0, import_internal.subSlot)(slot, "ret")
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
104
|
+
0 && (module.exports = {
|
|
105
|
+
useInteractions
|
|
106
|
+
});
|