@tamagui/floating 2.0.0-rc.4 → 2.0.0-rc.40
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/Floating.cjs +7 -5
- package/dist/cjs/Floating.native.js +19 -13
- package/dist/cjs/Floating.native.js.map +1 -1
- package/dist/cjs/index.cjs +46 -13
- package/dist/cjs/index.native.js +46 -13
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/interactions/PopupTriggerMap.cjs +49 -0
- package/dist/cjs/interactions/PopupTriggerMap.native.js +97 -0
- package/dist/cjs/interactions/PopupTriggerMap.native.js.map +1 -0
- package/dist/cjs/interactions/createFloatingEvents.cjs +50 -0
- package/dist/cjs/interactions/createFloatingEvents.native.js +56 -0
- package/dist/cjs/interactions/createFloatingEvents.native.js.map +1 -0
- package/dist/cjs/interactions/safePolygon.cjs +273 -0
- package/dist/cjs/interactions/safePolygon.native.js +284 -0
- package/dist/cjs/interactions/safePolygon.native.js.map +1 -0
- package/dist/cjs/interactions/types.cjs +18 -0
- package/dist/cjs/interactions/types.native.js +21 -0
- package/dist/cjs/interactions/types.native.js.map +1 -0
- package/dist/cjs/interactions/useClick.cjs +124 -0
- package/dist/cjs/interactions/useClick.native.js +132 -0
- package/dist/cjs/interactions/useClick.native.js.map +1 -0
- package/dist/cjs/interactions/useDelayGroup.cjs +115 -0
- package/dist/cjs/interactions/useDelayGroup.native.js +125 -0
- package/dist/cjs/interactions/useDelayGroup.native.js.map +1 -0
- package/dist/cjs/interactions/useFocus.cjs +130 -0
- package/dist/cjs/interactions/useFocus.native.js +139 -0
- package/dist/cjs/interactions/useFocus.native.js.map +1 -0
- package/dist/cjs/interactions/useHover.cjs +357 -0
- package/dist/cjs/interactions/useHover.native.js +373 -0
- package/dist/cjs/interactions/useHover.native.js.map +1 -0
- package/dist/cjs/interactions/useInnerOffset.cjs +128 -0
- package/dist/cjs/interactions/useInnerOffset.native.js +141 -0
- package/dist/cjs/interactions/useInnerOffset.native.js.map +1 -0
- package/dist/cjs/interactions/useInteractions.cjs +105 -0
- package/dist/cjs/interactions/useInteractions.native.js +216 -0
- package/dist/cjs/interactions/useInteractions.native.js.map +1 -0
- package/dist/cjs/interactions/useListNavigation.cjs +418 -0
- package/dist/cjs/interactions/useListNavigation.native.js +433 -0
- package/dist/cjs/interactions/useListNavigation.native.js.map +1 -0
- package/dist/cjs/interactions/useRole.cjs +122 -0
- package/dist/cjs/interactions/useRole.native.js +136 -0
- package/dist/cjs/interactions/useRole.native.js.map +1 -0
- package/dist/cjs/interactions/useTypeahead.cjs +143 -0
- package/dist/cjs/interactions/useTypeahead.native.js +159 -0
- package/dist/cjs/interactions/useTypeahead.native.js.map +1 -0
- package/dist/cjs/interactions/utils.cjs +208 -0
- package/dist/cjs/interactions/utils.native.js +227 -0
- package/dist/cjs/interactions/utils.native.js.map +1 -0
- package/dist/cjs/middleware/inner.cjs +118 -0
- package/dist/cjs/middleware/inner.native.js +130 -0
- package/dist/cjs/middleware/inner.native.js.map +1 -0
- package/dist/cjs/useFloating.cjs +35 -28
- package/dist/cjs/useFloating.native.js +51 -47
- package/dist/cjs/useFloating.native.js.map +1 -1
- package/dist/esm/Floating.native.js +6 -3
- package/dist/esm/Floating.native.js.map +1 -1
- package/dist/esm/index.js +17 -34
- package/dist/esm/index.js.map +1 -6
- package/dist/esm/index.mjs +16 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +16 -2
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/interactions/PopupTriggerMap.mjs +24 -0
- package/dist/esm/interactions/PopupTriggerMap.mjs.map +1 -0
- package/dist/esm/interactions/PopupTriggerMap.native.js +69 -0
- package/dist/esm/interactions/PopupTriggerMap.native.js.map +1 -0
- package/dist/esm/interactions/createFloatingEvents.mjs +25 -0
- package/dist/esm/interactions/createFloatingEvents.mjs.map +1 -0
- package/dist/esm/interactions/createFloatingEvents.native.js +28 -0
- package/dist/esm/interactions/createFloatingEvents.native.js.map +1 -0
- package/dist/esm/interactions/safePolygon.mjs +248 -0
- package/dist/esm/interactions/safePolygon.mjs.map +1 -0
- package/dist/esm/interactions/safePolygon.native.js +256 -0
- package/dist/esm/interactions/safePolygon.native.js.map +1 -0
- package/dist/esm/interactions/types.mjs +2 -0
- package/dist/esm/interactions/types.mjs.map +1 -0
- package/dist/esm/interactions/types.native.js +2 -0
- package/dist/esm/interactions/types.native.js.map +1 -0
- package/dist/esm/interactions/useClick.mjs +99 -0
- package/dist/esm/interactions/useClick.mjs.map +1 -0
- package/dist/esm/interactions/useClick.native.js +104 -0
- package/dist/esm/interactions/useClick.native.js.map +1 -0
- package/dist/esm/interactions/useDelayGroup.mjs +77 -0
- package/dist/esm/interactions/useDelayGroup.mjs.map +1 -0
- package/dist/esm/interactions/useDelayGroup.native.js +84 -0
- package/dist/esm/interactions/useDelayGroup.native.js.map +1 -0
- package/dist/esm/interactions/useFocus.mjs +105 -0
- package/dist/esm/interactions/useFocus.mjs.map +1 -0
- package/dist/esm/interactions/useFocus.native.js +111 -0
- package/dist/esm/interactions/useFocus.native.js.map +1 -0
- package/dist/esm/interactions/useHover.mjs +320 -0
- package/dist/esm/interactions/useHover.mjs.map +1 -0
- package/dist/esm/interactions/useHover.native.js +333 -0
- package/dist/esm/interactions/useHover.native.js.map +1 -0
- package/dist/esm/interactions/useInnerOffset.mjs +92 -0
- package/dist/esm/interactions/useInnerOffset.mjs.map +1 -0
- package/dist/esm/interactions/useInnerOffset.native.js +102 -0
- package/dist/esm/interactions/useInnerOffset.native.js.map +1 -0
- package/dist/esm/interactions/useInteractions.mjs +80 -0
- package/dist/esm/interactions/useInteractions.mjs.map +1 -0
- package/dist/esm/interactions/useInteractions.native.js +188 -0
- package/dist/esm/interactions/useInteractions.native.js.map +1 -0
- package/dist/esm/interactions/useListNavigation.mjs +393 -0
- package/dist/esm/interactions/useListNavigation.mjs.map +1 -0
- package/dist/esm/interactions/useListNavigation.native.js +405 -0
- package/dist/esm/interactions/useListNavigation.native.js.map +1 -0
- package/dist/esm/interactions/useRole.mjs +86 -0
- package/dist/esm/interactions/useRole.mjs.map +1 -0
- package/dist/esm/interactions/useRole.native.js +97 -0
- package/dist/esm/interactions/useRole.native.js.map +1 -0
- package/dist/esm/interactions/useTypeahead.mjs +118 -0
- package/dist/esm/interactions/useTypeahead.mjs.map +1 -0
- package/dist/esm/interactions/useTypeahead.native.js +131 -0
- package/dist/esm/interactions/useTypeahead.native.js.map +1 -0
- package/dist/esm/interactions/utils.mjs +162 -0
- package/dist/esm/interactions/utils.mjs.map +1 -0
- package/dist/esm/interactions/utils.native.js +178 -0
- package/dist/esm/interactions/utils.native.js.map +1 -0
- package/dist/esm/middleware/inner.mjs +82 -0
- package/dist/esm/middleware/inner.mjs.map +1 -0
- package/dist/esm/middleware/inner.native.js +91 -0
- package/dist/esm/middleware/inner.native.js.map +1 -0
- package/dist/esm/useFloating.mjs +8 -3
- package/dist/esm/useFloating.mjs.map +1 -1
- package/dist/esm/useFloating.native.js +25 -23
- package/dist/esm/useFloating.native.js.map +1 -1
- package/package.json +8 -10
- package/src/Floating.native.tsx +1 -0
- package/src/index.ts +49 -0
- package/src/interactions/PopupTriggerMap.ts +30 -0
- package/src/interactions/createFloatingEvents.ts +34 -0
- package/src/interactions/safePolygon.ts +500 -0
- package/src/interactions/types.ts +165 -0
- package/src/interactions/useClick.ts +148 -0
- package/src/interactions/useDelayGroup.ts +114 -0
- package/src/interactions/useFocus.ts +164 -0
- package/src/interactions/useHover.ts +453 -0
- package/src/interactions/useInnerOffset.ts +116 -0
- package/src/interactions/useInteractions.ts +101 -0
- package/src/interactions/useListNavigation.ts +578 -0
- package/src/interactions/useRole.ts +103 -0
- package/src/interactions/useTypeahead.ts +173 -0
- package/src/interactions/utils.ts +234 -0
- package/src/middleware/inner.ts +141 -0
- package/src/useFloating.tsx +13 -1
- package/types/Floating.native.d.ts +1 -0
- package/types/Floating.native.d.ts.map +1 -1
- package/types/index.d.ts +17 -2
- package/types/index.d.ts.map +1 -1
- package/types/interactions/PopupTriggerMap.d.ts +8 -0
- package/types/interactions/PopupTriggerMap.d.ts.map +1 -0
- package/types/interactions/createFloatingEvents.d.ts +7 -0
- package/types/interactions/createFloatingEvents.d.ts.map +1 -0
- package/types/interactions/safePolygon.d.ts +4 -0
- package/types/interactions/safePolygon.d.ts.map +1 -0
- package/types/interactions/types.d.ts +123 -0
- package/types/interactions/types.d.ts.map +1 -0
- package/types/interactions/useClick.d.ts +3 -0
- package/types/interactions/useClick.d.ts.map +1 -0
- package/types/interactions/useDelayGroup.d.ts +23 -0
- package/types/interactions/useDelayGroup.d.ts.map +1 -0
- package/types/interactions/useFocus.d.ts +3 -0
- package/types/interactions/useFocus.d.ts.map +1 -0
- package/types/interactions/useHover.d.ts +6 -0
- package/types/interactions/useHover.d.ts.map +1 -0
- package/types/interactions/useInnerOffset.d.ts +3 -0
- package/types/interactions/useInnerOffset.d.ts.map +1 -0
- package/types/interactions/useInteractions.d.ts +8 -0
- package/types/interactions/useInteractions.d.ts.map +1 -0
- package/types/interactions/useListNavigation.d.ts +3 -0
- package/types/interactions/useListNavigation.d.ts.map +1 -0
- package/types/interactions/useRole.d.ts +3 -0
- package/types/interactions/useRole.d.ts.map +1 -0
- package/types/interactions/useTypeahead.d.ts +3 -0
- package/types/interactions/useTypeahead.d.ts.map +1 -0
- package/types/interactions/utils.d.ts +46 -0
- package/types/interactions/utils.d.ts.map +1 -0
- package/types/middleware/inner.d.ts +14 -0
- package/types/middleware/inner.d.ts.map +1 -0
- package/types/useFloating.d.ts +7 -1
- package/types/useFloating.d.ts.map +1 -1
- package/dist/cjs/Floating.js +0 -15
- package/dist/cjs/Floating.js.map +0 -6
- package/dist/cjs/index.js +0 -34
- package/dist/cjs/index.js.map +0 -6
- package/dist/cjs/useFloating.js +0 -46
- package/dist/cjs/useFloating.js.map +0 -6
- package/dist/esm/Floating.js +0 -2
- package/dist/esm/Floating.js.map +0 -6
- package/dist/esm/useFloating.js +0 -23
- package/dist/esm/useFloating.js.map +0 -6
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: true
|
|
22
|
+
}), mod);
|
|
23
|
+
var useClick_exports = {};
|
|
24
|
+
__export(useClick_exports, {
|
|
25
|
+
useClick: () => useClick
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(useClick_exports);
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_utils = require("./utils.cjs");
|
|
30
|
+
function isButtonTarget(event) {
|
|
31
|
+
return (0, import_utils.isHTMLElement)(event.target) && event.target.tagName === "BUTTON";
|
|
32
|
+
}
|
|
33
|
+
function isAnchorTarget(event) {
|
|
34
|
+
return (0, import_utils.isHTMLElement)(event.target) && event.target.tagName === "A";
|
|
35
|
+
}
|
|
36
|
+
function isSpaceIgnored(element) {
|
|
37
|
+
return (0, import_utils.isTypeableElement)(element);
|
|
38
|
+
}
|
|
39
|
+
function useClick(context, props = {}) {
|
|
40
|
+
const {
|
|
41
|
+
open,
|
|
42
|
+
onOpenChange,
|
|
43
|
+
dataRef,
|
|
44
|
+
elements: {
|
|
45
|
+
domReference
|
|
46
|
+
}
|
|
47
|
+
} = context;
|
|
48
|
+
const {
|
|
49
|
+
enabled = true,
|
|
50
|
+
event: eventOption = "click",
|
|
51
|
+
toggle = true,
|
|
52
|
+
ignoreMouse = false,
|
|
53
|
+
keyboardHandlers = true,
|
|
54
|
+
stickIfOpen = true
|
|
55
|
+
} = props;
|
|
56
|
+
const pointerTypeRef = (0, import_react.useRef)(void 0);
|
|
57
|
+
const didKeyDownRef = (0, import_react.useRef)(false);
|
|
58
|
+
const reference = (0, import_react.useMemo)(() => ({
|
|
59
|
+
onPointerDown(event) {
|
|
60
|
+
pointerTypeRef.current = event.pointerType;
|
|
61
|
+
},
|
|
62
|
+
onMouseDown(event) {
|
|
63
|
+
const pointerType = pointerTypeRef.current;
|
|
64
|
+
if (event.button !== 0) return;
|
|
65
|
+
if (eventOption === "click") return;
|
|
66
|
+
if ((0, import_utils.isMouseLikePointerType)(pointerType, true) && ignoreMouse) return;
|
|
67
|
+
if (open && toggle && (dataRef.current.openEvent && stickIfOpen ? dataRef.current.openEvent.type === "mousedown" : true)) {
|
|
68
|
+
onOpenChange(false, event.nativeEvent || event, "click");
|
|
69
|
+
} else {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
onOpenChange(true, event.nativeEvent || event, "click");
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
onClick(event) {
|
|
75
|
+
const pointerType = pointerTypeRef.current;
|
|
76
|
+
if (eventOption === "mousedown" && pointerTypeRef.current) {
|
|
77
|
+
pointerTypeRef.current = void 0;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if ((0, import_utils.isMouseLikePointerType)(pointerType, true) && ignoreMouse) return;
|
|
81
|
+
if (open && toggle && (dataRef.current.openEvent && stickIfOpen ? dataRef.current.openEvent.type === "click" : true)) {
|
|
82
|
+
onOpenChange(false, event.nativeEvent || event, "click");
|
|
83
|
+
} else {
|
|
84
|
+
onOpenChange(true, event.nativeEvent || event, "click");
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
onKeyDown(event) {
|
|
88
|
+
pointerTypeRef.current = void 0;
|
|
89
|
+
if (event.defaultPrevented || !keyboardHandlers || isButtonTarget(event)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (event.key === " " && !isSpaceIgnored(domReference)) {
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
didKeyDownRef.current = true;
|
|
95
|
+
}
|
|
96
|
+
if (isAnchorTarget(event)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (event.key === "Enter") {
|
|
100
|
+
if (open && toggle) {
|
|
101
|
+
onOpenChange(false, event.nativeEvent || event, "click");
|
|
102
|
+
} else {
|
|
103
|
+
onOpenChange(true, event.nativeEvent || event, "click");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
onKeyUp(event) {
|
|
108
|
+
if (event.defaultPrevented || !keyboardHandlers || isButtonTarget(event) || isSpaceIgnored(domReference)) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
if (event.key === " " && didKeyDownRef.current) {
|
|
112
|
+
didKeyDownRef.current = false;
|
|
113
|
+
if (open && toggle) {
|
|
114
|
+
onOpenChange(false, event.nativeEvent || event, "click");
|
|
115
|
+
} else {
|
|
116
|
+
onOpenChange(true, event.nativeEvent || event, "click");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}), [dataRef, domReference, eventOption, ignoreMouse, keyboardHandlers, onOpenChange, open, stickIfOpen, toggle]);
|
|
121
|
+
return (0, import_react.useMemo)(() => enabled ? {
|
|
122
|
+
reference
|
|
123
|
+
} : {}, [enabled, reference]);
|
|
124
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
}), mod);
|
|
25
|
+
var useClick_exports = {};
|
|
26
|
+
__export(useClick_exports, {
|
|
27
|
+
useClick: () => useClick
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(useClick_exports);
|
|
30
|
+
var import_react = require("react");
|
|
31
|
+
var import_utils = require("./utils.native.js");
|
|
32
|
+
function isButtonTarget(event) {
|
|
33
|
+
return (0, import_utils.isHTMLElement)(event.target) && event.target.tagName === "BUTTON";
|
|
34
|
+
}
|
|
35
|
+
function isAnchorTarget(event) {
|
|
36
|
+
return (0, import_utils.isHTMLElement)(event.target) && event.target.tagName === "A";
|
|
37
|
+
}
|
|
38
|
+
function isSpaceIgnored(element) {
|
|
39
|
+
return (0, import_utils.isTypeableElement)(element);
|
|
40
|
+
}
|
|
41
|
+
function useClick(context) {
|
|
42
|
+
var props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
43
|
+
var {
|
|
44
|
+
open,
|
|
45
|
+
onOpenChange,
|
|
46
|
+
dataRef,
|
|
47
|
+
elements: {
|
|
48
|
+
domReference
|
|
49
|
+
}
|
|
50
|
+
} = context;
|
|
51
|
+
var {
|
|
52
|
+
enabled = true,
|
|
53
|
+
event: eventOption = "click",
|
|
54
|
+
toggle = true,
|
|
55
|
+
ignoreMouse = false,
|
|
56
|
+
keyboardHandlers = true,
|
|
57
|
+
stickIfOpen = true
|
|
58
|
+
} = props;
|
|
59
|
+
var pointerTypeRef = (0, import_react.useRef)(void 0);
|
|
60
|
+
var didKeyDownRef = (0, import_react.useRef)(false);
|
|
61
|
+
var reference = (0, import_react.useMemo)(function () {
|
|
62
|
+
return {
|
|
63
|
+
onPointerDown(event) {
|
|
64
|
+
pointerTypeRef.current = event.pointerType;
|
|
65
|
+
},
|
|
66
|
+
onMouseDown(event) {
|
|
67
|
+
var pointerType = pointerTypeRef.current;
|
|
68
|
+
if (event.button !== 0) return;
|
|
69
|
+
if (eventOption === "click") return;
|
|
70
|
+
if ((0, import_utils.isMouseLikePointerType)(pointerType, true) && ignoreMouse) return;
|
|
71
|
+
if (open && toggle && (dataRef.current.openEvent && stickIfOpen ? dataRef.current.openEvent.type === "mousedown" : true)) {
|
|
72
|
+
onOpenChange(false, event.nativeEvent || event, "click");
|
|
73
|
+
} else {
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
onOpenChange(true, event.nativeEvent || event, "click");
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
onClick(event) {
|
|
79
|
+
var pointerType = pointerTypeRef.current;
|
|
80
|
+
if (eventOption === "mousedown" && pointerTypeRef.current) {
|
|
81
|
+
pointerTypeRef.current = void 0;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if ((0, import_utils.isMouseLikePointerType)(pointerType, true) && ignoreMouse) return;
|
|
85
|
+
if (open && toggle && (dataRef.current.openEvent && stickIfOpen ? dataRef.current.openEvent.type === "click" : true)) {
|
|
86
|
+
onOpenChange(false, event.nativeEvent || event, "click");
|
|
87
|
+
} else {
|
|
88
|
+
onOpenChange(true, event.nativeEvent || event, "click");
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
onKeyDown(event) {
|
|
92
|
+
pointerTypeRef.current = void 0;
|
|
93
|
+
if (event.defaultPrevented || !keyboardHandlers || isButtonTarget(event)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (event.key === " " && !isSpaceIgnored(domReference)) {
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
didKeyDownRef.current = true;
|
|
99
|
+
}
|
|
100
|
+
if (isAnchorTarget(event)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (event.key === "Enter") {
|
|
104
|
+
if (open && toggle) {
|
|
105
|
+
onOpenChange(false, event.nativeEvent || event, "click");
|
|
106
|
+
} else {
|
|
107
|
+
onOpenChange(true, event.nativeEvent || event, "click");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
onKeyUp(event) {
|
|
112
|
+
if (event.defaultPrevented || !keyboardHandlers || isButtonTarget(event) || isSpaceIgnored(domReference)) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (event.key === " " && didKeyDownRef.current) {
|
|
116
|
+
didKeyDownRef.current = false;
|
|
117
|
+
if (open && toggle) {
|
|
118
|
+
onOpenChange(false, event.nativeEvent || event, "click");
|
|
119
|
+
} else {
|
|
120
|
+
onOpenChange(true, event.nativeEvent || event, "click");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}, [dataRef, domReference, eventOption, ignoreMouse, keyboardHandlers, onOpenChange, open, stickIfOpen, toggle]);
|
|
126
|
+
return (0, import_react.useMemo)(function () {
|
|
127
|
+
return enabled ? {
|
|
128
|
+
reference
|
|
129
|
+
} : {};
|
|
130
|
+
}, [enabled, reference]);
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=useClick.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useClick_exports","__export","useClick","module","exports","import_react","require","import_utils","isButtonTarget","event","isHTMLElement","target","tagName","isAnchorTarget","isSpaceIgnored","element","isTypeableElement","context","props","arguments","length","open","onOpenChange","dataRef","elements","domReference","enabled","eventOption","toggle","ignoreMouse","keyboardHandlers","stickIfOpen","pointerTypeRef","useRef","didKeyDownRef","reference","useMemo","onPointerDown","current","pointerType","onMouseDown","button","isMouseLikePointerType","openEvent","type","nativeEvent","preventDefault","onClick","onKeyDown","defaultPrevented","key","onKeyUp"],"sources":["../../../src/interactions/useClick.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,gBAAA;AAAAC,QAAA,CAAAD,gBAAA;EAAAE,QAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAAgC,CAAAK,gBAAA;AAChC,IAAAK,YAAA,GAAyEC,OAAA;AAGzE,IAAAC,YAAS,GAAAD,OAAe,oBAAqC;AAC3D,SAAAE,cAAOA,CAAAC,KAAA;EACT,WAAAF,YAAA,CAAAG,aAAA,EAAAD,KAAA,CAAAE,MAAA,KAAAF,KAAA,CAAAE,MAAA,CAAAC,OAAA;AAEA;AACE,SAAAC,cAAOA,CAAAJ,KAAA;EACT,WAAAF,YAAA,CAAAG,aAAA,EAAAD,KAAA,CAAAE,MAAA,KAAAF,KAAA,CAAAE,MAAA,CAAAC,OAAA;AAEA;AACE,SAAAE,cAAOA,CAAAC,OAAA;EACT,WAAAR,YAAA,CAAAS,iBAAA,EAAAD,OAAA;AAGO;AAIL,SAAMb,SAAAe,OAAA;EAAA,IACJC,KAAA,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,iBAAAA,SAAA;EAAA,IACA;IA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WACF,EACFH,MAAA,EACA;EAAA,OACE,IAAAvB,YAAA,CAAA+B,OAAA;IAAA,OACAV,OAAA;MACAS;IAAA,IACA;EAAA,IACAT,OACA,EAAAS,SACA;AACA","ignoreList":[]}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
34
|
+
var useDelayGroup_exports = {};
|
|
35
|
+
__export(useDelayGroup_exports, {
|
|
36
|
+
FloatingDelayGroup: () => FloatingDelayGroup,
|
|
37
|
+
useDelayGroup: () => useDelayGroup,
|
|
38
|
+
useDelayGroupContext: () => useDelayGroupContext
|
|
39
|
+
});
|
|
40
|
+
module.exports = __toCommonJS(useDelayGroup_exports);
|
|
41
|
+
var React = __toESM(require("react"), 1);
|
|
42
|
+
const DelayGroupContext = React.createContext({
|
|
43
|
+
currentId: null,
|
|
44
|
+
setCurrentId: () => {},
|
|
45
|
+
delay: 0,
|
|
46
|
+
timeoutMs: 0,
|
|
47
|
+
initialDelay: 0
|
|
48
|
+
});
|
|
49
|
+
function useDelayGroupContext() {
|
|
50
|
+
return React.useContext(DelayGroupContext);
|
|
51
|
+
}
|
|
52
|
+
function FloatingDelayGroup({
|
|
53
|
+
children,
|
|
54
|
+
delay,
|
|
55
|
+
timeoutMs = 0
|
|
56
|
+
}) {
|
|
57
|
+
const [currentId, setCurrentIdRaw] = React.useState(null);
|
|
58
|
+
const timeoutRef = React.useRef(void 0);
|
|
59
|
+
const setCurrentId = React.useCallback(id => {
|
|
60
|
+
clearTimeout(timeoutRef.current);
|
|
61
|
+
if (id == null && timeoutMs > 0) {
|
|
62
|
+
timeoutRef.current = setTimeout(() => {
|
|
63
|
+
setCurrentIdRaw(null);
|
|
64
|
+
}, timeoutMs);
|
|
65
|
+
} else {
|
|
66
|
+
setCurrentIdRaw(id);
|
|
67
|
+
}
|
|
68
|
+
}, [timeoutMs]);
|
|
69
|
+
React.useEffect(() => {
|
|
70
|
+
return () => clearTimeout(timeoutRef.current);
|
|
71
|
+
}, []);
|
|
72
|
+
const value = React.useMemo(() => ({
|
|
73
|
+
currentId,
|
|
74
|
+
setCurrentId,
|
|
75
|
+
delay,
|
|
76
|
+
timeoutMs,
|
|
77
|
+
initialDelay: delay
|
|
78
|
+
}), [currentId, setCurrentId, delay, timeoutMs]);
|
|
79
|
+
return React.createElement(DelayGroupContext.Provider, {
|
|
80
|
+
value
|
|
81
|
+
}, children);
|
|
82
|
+
}
|
|
83
|
+
function useDelayGroup(context, options = {}) {
|
|
84
|
+
const {
|
|
85
|
+
id
|
|
86
|
+
} = options;
|
|
87
|
+
const groupContext = React.useContext(DelayGroupContext);
|
|
88
|
+
React.useEffect(() => {
|
|
89
|
+
if (!context.open && groupContext.currentId === id) {
|
|
90
|
+
groupContext.setCurrentId(null);
|
|
91
|
+
}
|
|
92
|
+
}, [context.open, id]);
|
|
93
|
+
React.useEffect(() => {
|
|
94
|
+
if (groupContext.currentId != null && groupContext.currentId !== id && context.open) {
|
|
95
|
+
context.onOpenChange(false);
|
|
96
|
+
}
|
|
97
|
+
}, [groupContext.currentId, id, context.open]);
|
|
98
|
+
if (groupContext.currentId != null) {
|
|
99
|
+
return {
|
|
100
|
+
delay: {
|
|
101
|
+
open: 1,
|
|
102
|
+
close: getClose(groupContext.initialDelay)
|
|
103
|
+
},
|
|
104
|
+
currentId: groupContext.currentId
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
delay: groupContext.initialDelay,
|
|
109
|
+
currentId: groupContext.currentId
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function getClose(delay) {
|
|
113
|
+
if (typeof delay === "number") return delay;
|
|
114
|
+
return delay?.close ?? 0;
|
|
115
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
+
get: () => from[key],
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
+
value: mod,
|
|
31
|
+
enumerable: true
|
|
32
|
+
}) : target, mod));
|
|
33
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
+
value: true
|
|
35
|
+
}), mod);
|
|
36
|
+
var useDelayGroup_exports = {};
|
|
37
|
+
__export(useDelayGroup_exports, {
|
|
38
|
+
FloatingDelayGroup: () => FloatingDelayGroup,
|
|
39
|
+
useDelayGroup: () => useDelayGroup,
|
|
40
|
+
useDelayGroupContext: () => useDelayGroupContext
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(useDelayGroup_exports);
|
|
43
|
+
var React = __toESM(require("react"), 1);
|
|
44
|
+
var DelayGroupContext = React.createContext({
|
|
45
|
+
currentId: null,
|
|
46
|
+
setCurrentId: function () {},
|
|
47
|
+
delay: 0,
|
|
48
|
+
timeoutMs: 0,
|
|
49
|
+
initialDelay: 0
|
|
50
|
+
});
|
|
51
|
+
function useDelayGroupContext() {
|
|
52
|
+
return React.useContext(DelayGroupContext);
|
|
53
|
+
}
|
|
54
|
+
function FloatingDelayGroup(param) {
|
|
55
|
+
var {
|
|
56
|
+
children,
|
|
57
|
+
delay,
|
|
58
|
+
timeoutMs = 0
|
|
59
|
+
} = param;
|
|
60
|
+
var [currentId, setCurrentIdRaw] = React.useState(null);
|
|
61
|
+
var timeoutRef = React.useRef(void 0);
|
|
62
|
+
var setCurrentId = React.useCallback(function (id) {
|
|
63
|
+
clearTimeout(timeoutRef.current);
|
|
64
|
+
if (id == null && timeoutMs > 0) {
|
|
65
|
+
timeoutRef.current = setTimeout(function () {
|
|
66
|
+
setCurrentIdRaw(null);
|
|
67
|
+
}, timeoutMs);
|
|
68
|
+
} else {
|
|
69
|
+
setCurrentIdRaw(id);
|
|
70
|
+
}
|
|
71
|
+
}, [timeoutMs]);
|
|
72
|
+
React.useEffect(function () {
|
|
73
|
+
return function () {
|
|
74
|
+
return clearTimeout(timeoutRef.current);
|
|
75
|
+
};
|
|
76
|
+
}, []);
|
|
77
|
+
var value = React.useMemo(function () {
|
|
78
|
+
return {
|
|
79
|
+
currentId,
|
|
80
|
+
setCurrentId,
|
|
81
|
+
delay,
|
|
82
|
+
timeoutMs,
|
|
83
|
+
initialDelay: delay
|
|
84
|
+
};
|
|
85
|
+
}, [currentId, setCurrentId, delay, timeoutMs]);
|
|
86
|
+
return React.createElement(DelayGroupContext.Provider, {
|
|
87
|
+
value
|
|
88
|
+
}, children);
|
|
89
|
+
}
|
|
90
|
+
function useDelayGroup(context) {
|
|
91
|
+
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
92
|
+
var {
|
|
93
|
+
id
|
|
94
|
+
} = options;
|
|
95
|
+
var groupContext = React.useContext(DelayGroupContext);
|
|
96
|
+
React.useEffect(function () {
|
|
97
|
+
if (!context.open && groupContext.currentId === id) {
|
|
98
|
+
groupContext.setCurrentId(null);
|
|
99
|
+
}
|
|
100
|
+
}, [context.open, id]);
|
|
101
|
+
React.useEffect(function () {
|
|
102
|
+
if (groupContext.currentId != null && groupContext.currentId !== id && context.open) {
|
|
103
|
+
context.onOpenChange(false);
|
|
104
|
+
}
|
|
105
|
+
}, [groupContext.currentId, id, context.open]);
|
|
106
|
+
if (groupContext.currentId != null) {
|
|
107
|
+
return {
|
|
108
|
+
delay: {
|
|
109
|
+
open: 1,
|
|
110
|
+
close: getClose(groupContext.initialDelay)
|
|
111
|
+
},
|
|
112
|
+
currentId: groupContext.currentId
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
delay: groupContext.initialDelay,
|
|
117
|
+
currentId: groupContext.currentId
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function getClose(delay) {
|
|
121
|
+
if (typeof delay === "number") return delay;
|
|
122
|
+
var _delay_close;
|
|
123
|
+
return (_delay_close = delay === null || delay === void 0 ? void 0 : delay.close) !== null && _delay_close !== void 0 ? _delay_close : 0;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=useDelayGroup.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useDelayGroup_exports","__export","FloatingDelayGroup","useDelayGroup","useDelayGroupContext","module","exports","React","__toESM","require","DelayGroupContext","createContext","currentId","setCurrentId","delay","timeoutMs","initialDelay","useContext","param","children","setCurrentIdRaw","useState","timeoutRef","useRef","useCallback","id","clearTimeout","current","setTimeout","useEffect","useMemo","createElement","Provider","context","options","arguments","length","groupContext","open","onOpenChange"],"sources":["../../../src/interactions/useDelayGroup.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,qBAAA;AAAAC,QAAA,CAAAD,qBAAA;EAAAE,kBAAA,EA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KAAK,CAAAwB,aAAI,CAAArB,iBAAA,CAAAsB,QAAA;IACfjC;EAGA,GAAAoB,QAAM;AACJ;AACE,SAAAhB,aAAaA,CAAA8B,OAAA,EAAa;EAAI,IAChCC,OAAA,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,iBAAAA,SAAA;EACF,IAAI;IAAAV;EAAA,IAAQS,OAAQ;EAIpB,IAAAG,YAAgB,GAAA9B,KAAM,CAAAU,UAAA,CAAAP,iBAAA;EACpBH,KAAA,CAAIsB,SAAA,aAAa;IACf,KAAAI,OAAQ,CAAAK,IAAA,IAAAD,YAAkB,CAAAzB,SAAA,KAAAa,EAAA;MAC5BY,YAAA,CAAAxB,YAAA;IACF;EAIA,IACEoB,OAAO,CAAAK,IAAA,EAAAb,EACL,CAA6D;EACrClB,KAC1B,CAAAsB,SAAA;IACF,IAAAQ,YAAA,CAAAzB,SAAA,YAAAyB,YAAA,CAAAzB,SAAA,KAAAa,EAAA,IAAAQ,OAAA,CAAAK,IAAA;MAEAL,OAAO,CAAAM,YAAA;IACL;EAAoB,GACpB,CACFF,YAAA,CAAAzB,SAAA,EACFa,EAAA,EAEAQ,OAAS,CAAAK,IAAA,CACP;EACA,IAAAD,YAAc,CAAAzB,SAAS;IACzB","ignoreList":[]}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: true
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: () => from[key],
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: true
|
|
22
|
+
}), mod);
|
|
23
|
+
var useFocus_exports = {};
|
|
24
|
+
__export(useFocus_exports, {
|
|
25
|
+
useFocus: () => useFocus
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(useFocus_exports);
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_utils = require("./utils.cjs");
|
|
30
|
+
function isMacSafari() {
|
|
31
|
+
return (0, import_utils.isMac)() && (0, import_utils.isSafari)();
|
|
32
|
+
}
|
|
33
|
+
function useFocus(context, props = {}) {
|
|
34
|
+
const {
|
|
35
|
+
open,
|
|
36
|
+
onOpenChange,
|
|
37
|
+
events,
|
|
38
|
+
dataRef,
|
|
39
|
+
elements
|
|
40
|
+
} = context;
|
|
41
|
+
const {
|
|
42
|
+
enabled = true,
|
|
43
|
+
visibleOnly = true
|
|
44
|
+
} = props;
|
|
45
|
+
const blockFocusRef = (0, import_react.useRef)(false);
|
|
46
|
+
const timeoutRef = (0, import_react.useRef)(-1);
|
|
47
|
+
const keyboardModalityRef = (0, import_react.useRef)(true);
|
|
48
|
+
(0, import_react.useEffect)(() => {
|
|
49
|
+
if (!enabled) return;
|
|
50
|
+
const win = (0, import_utils.getDocument)(elements.domReference).defaultView || window;
|
|
51
|
+
function onBlur() {
|
|
52
|
+
if (!open && (0, import_utils.isHTMLElement)(elements.domReference) && elements.domReference === (0, import_utils.activeElement)((0, import_utils.getDocument)(elements.domReference))) {
|
|
53
|
+
blockFocusRef.current = true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function onKeyDown() {
|
|
57
|
+
keyboardModalityRef.current = true;
|
|
58
|
+
}
|
|
59
|
+
function onPointerDown() {
|
|
60
|
+
keyboardModalityRef.current = false;
|
|
61
|
+
}
|
|
62
|
+
win.addEventListener("blur", onBlur);
|
|
63
|
+
if (isMacSafari()) {
|
|
64
|
+
win.addEventListener("keydown", onKeyDown, true);
|
|
65
|
+
win.addEventListener("pointerdown", onPointerDown, true);
|
|
66
|
+
}
|
|
67
|
+
return () => {
|
|
68
|
+
win.removeEventListener("blur", onBlur);
|
|
69
|
+
if (isMacSafari()) {
|
|
70
|
+
win.removeEventListener("keydown", onKeyDown, true);
|
|
71
|
+
win.removeEventListener("pointerdown", onPointerDown, true);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}, [elements.domReference, open, enabled]);
|
|
75
|
+
(0, import_react.useEffect)(() => {
|
|
76
|
+
if (!enabled) return;
|
|
77
|
+
if (!events) return;
|
|
78
|
+
function handleOpenChange({
|
|
79
|
+
reason
|
|
80
|
+
}) {
|
|
81
|
+
if (reason === "reference-press" || reason === "escape-key") {
|
|
82
|
+
blockFocusRef.current = true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
events.on("openchange", handleOpenChange);
|
|
86
|
+
return () => {
|
|
87
|
+
events.off("openchange", handleOpenChange);
|
|
88
|
+
};
|
|
89
|
+
}, [events, enabled]);
|
|
90
|
+
(0, import_react.useEffect)(() => {
|
|
91
|
+
return () => {
|
|
92
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutRef);
|
|
93
|
+
};
|
|
94
|
+
}, []);
|
|
95
|
+
const reference = (0, import_react.useMemo)(() => ({
|
|
96
|
+
onMouseLeave() {
|
|
97
|
+
blockFocusRef.current = false;
|
|
98
|
+
},
|
|
99
|
+
onFocus(event) {
|
|
100
|
+
if (blockFocusRef.current) return;
|
|
101
|
+
const target = (0, import_utils.getTarget)(event.nativeEvent);
|
|
102
|
+
if (visibleOnly && (0, import_utils.isElement)(target)) {
|
|
103
|
+
if (isMacSafari() && !event.relatedTarget) {
|
|
104
|
+
if (!keyboardModalityRef.current && !(0, import_utils.isTypeableElement)(target)) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
} else if (!(0, import_utils.matchesFocusVisible)(target)) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
onOpenChange(true, event.nativeEvent, "focus");
|
|
112
|
+
},
|
|
113
|
+
onBlur(event) {
|
|
114
|
+
blockFocusRef.current = false;
|
|
115
|
+
const relatedTarget = event.relatedTarget;
|
|
116
|
+
const nativeEvent = event.nativeEvent;
|
|
117
|
+
timeoutRef.current = window.setTimeout(() => {
|
|
118
|
+
const activeEl = (0, import_utils.activeElement)(elements.domReference ? elements.domReference.ownerDocument : document);
|
|
119
|
+
if (!relatedTarget && activeEl === elements.domReference) return;
|
|
120
|
+
if ((0, import_utils.contains)(context.refs.floating.current, activeEl) || (0, import_utils.contains)(elements.domReference, activeEl)) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
onOpenChange(false, nativeEvent, "focus");
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}), [context.refs.floating, elements.domReference, onOpenChange, visibleOnly]);
|
|
127
|
+
return (0, import_react.useMemo)(() => enabled ? {
|
|
128
|
+
reference
|
|
129
|
+
} : {}, [enabled, reference]);
|
|
130
|
+
}
|