@hanzogui/floating 3.0.6 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Floating.cjs +7 -5
- package/dist/cjs/Floating.native.js +18 -16
- package/dist/cjs/Floating.native.js.map +1 -1
- package/dist/cjs/index.cjs +28 -26
- package/dist/cjs/index.native.js +28 -26
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/interactions/PopupTriggerMap.cjs +21 -12
- package/dist/cjs/interactions/PopupTriggerMap.native.js +51 -27
- package/dist/cjs/interactions/PopupTriggerMap.native.js.map +1 -1
- package/dist/cjs/interactions/createFloatingEvents.cjs +21 -12
- package/dist/cjs/interactions/createFloatingEvents.native.js +22 -13
- package/dist/cjs/interactions/createFloatingEvents.native.js.map +1 -1
- package/dist/cjs/interactions/safePolygon.cjs +213 -131
- package/dist/cjs/interactions/safePolygon.native.js +182 -103
- package/dist/cjs/interactions/safePolygon.native.js.map +1 -1
- package/dist/cjs/interactions/types.cjs +7 -5
- package/dist/cjs/interactions/types.native.js +7 -5
- package/dist/cjs/interactions/types.native.js.map +1 -1
- package/dist/cjs/interactions/useClick.cjs +91 -49
- package/dist/cjs/interactions/useClick.native.js +96 -54
- package/dist/cjs/interactions/useClick.native.js.map +1 -1
- package/dist/cjs/interactions/useDelayGroup.cjs +63 -44
- package/dist/cjs/interactions/useDelayGroup.native.js +74 -58
- package/dist/cjs/interactions/useDelayGroup.native.js.map +1 -1
- package/dist/cjs/interactions/useFocus.cjs +73 -44
- package/dist/cjs/interactions/useFocus.native.js +75 -49
- package/dist/cjs/interactions/useFocus.native.js.map +1 -1
- package/dist/cjs/interactions/useHover.cjs +242 -109
- package/dist/cjs/interactions/useHover.native.js +268 -143
- package/dist/cjs/interactions/useHover.native.js.map +1 -1
- package/dist/cjs/interactions/useInnerOffset.cjs +88 -64
- package/dist/cjs/interactions/useInnerOffset.native.js +88 -65
- package/dist/cjs/interactions/useInnerOffset.native.js.map +1 -1
- package/dist/cjs/interactions/useInteractions.cjs +60 -31
- package/dist/cjs/interactions/useInteractions.native.js +133 -81
- package/dist/cjs/interactions/useInteractions.native.js.map +1 -1
- package/dist/cjs/interactions/useListNavigation.cjs +346 -181
- package/dist/cjs/interactions/useListNavigation.native.js +350 -214
- package/dist/cjs/interactions/useListNavigation.native.js.map +1 -1
- package/dist/cjs/interactions/useRole.cjs +83 -73
- package/dist/cjs/interactions/useRole.native.js +107 -99
- package/dist/cjs/interactions/useRole.native.js.map +1 -1
- package/dist/cjs/interactions/useTypeahead.cjs +115 -65
- package/dist/cjs/interactions/useTypeahead.native.js +122 -77
- package/dist/cjs/interactions/useTypeahead.native.js.map +1 -1
- package/dist/cjs/interactions/utils.cjs +68 -38
- package/dist/cjs/interactions/utils.native.js +93 -54
- package/dist/cjs/interactions/utils.native.js.map +1 -1
- package/dist/cjs/middleware/inner.cjs +79 -67
- package/dist/cjs/middleware/inner.native.js +86 -76
- package/dist/cjs/middleware/inner.native.js.map +1 -1
- package/dist/cjs/useFloating.cjs +48 -45
- package/dist/cjs/useFloating.native.js +50 -48
- package/dist/cjs/useFloating.native.js.map +1 -1
- package/dist/esm/Floating.native.js +5 -5
- package/dist/esm/Floating.native.js.map +1 -1
- package/dist/esm/interactions/PopupTriggerMap.mjs +9 -2
- package/dist/esm/interactions/PopupTriggerMap.mjs.map +1 -1
- package/dist/esm/interactions/PopupTriggerMap.native.js +39 -17
- package/dist/esm/interactions/PopupTriggerMap.native.js.map +1 -1
- package/dist/esm/interactions/createFloatingEvents.mjs +9 -2
- package/dist/esm/interactions/createFloatingEvents.mjs.map +1 -1
- package/dist/esm/interactions/createFloatingEvents.native.js +10 -3
- package/dist/esm/interactions/createFloatingEvents.native.js.map +1 -1
- package/dist/esm/interactions/safePolygon.mjs +201 -121
- package/dist/esm/interactions/safePolygon.mjs.map +1 -1
- package/dist/esm/interactions/safePolygon.native.js +170 -93
- package/dist/esm/interactions/safePolygon.native.js.map +1 -1
- package/dist/esm/interactions/useClick.mjs +79 -39
- package/dist/esm/interactions/useClick.mjs.map +1 -1
- package/dist/esm/interactions/useClick.native.js +82 -42
- package/dist/esm/interactions/useClick.native.js.map +1 -1
- package/dist/esm/interactions/useDelayGroup.mjs +39 -22
- package/dist/esm/interactions/useDelayGroup.mjs.map +1 -1
- package/dist/esm/interactions/useDelayGroup.native.js +42 -28
- package/dist/esm/interactions/useDelayGroup.native.js.map +1 -1
- package/dist/esm/interactions/useFocus.mjs +59 -32
- package/dist/esm/interactions/useFocus.mjs.map +1 -1
- package/dist/esm/interactions/useFocus.native.js +61 -37
- package/dist/esm/interactions/useFocus.native.js.map +1 -1
- package/dist/esm/interactions/useHover.mjs +215 -84
- package/dist/esm/interactions/useHover.mjs.map +1 -1
- package/dist/esm/interactions/useHover.native.js +240 -117
- package/dist/esm/interactions/useHover.native.js.map +1 -1
- package/dist/esm/interactions/useInnerOffset.mjs +61 -39
- package/dist/esm/interactions/useInnerOffset.mjs.map +1 -1
- package/dist/esm/interactions/useInnerOffset.native.js +61 -40
- package/dist/esm/interactions/useInnerOffset.native.js.map +1 -1
- package/dist/esm/interactions/useInteractions.mjs +48 -21
- package/dist/esm/interactions/useInteractions.mjs.map +1 -1
- package/dist/esm/interactions/useInteractions.native.js +121 -71
- package/dist/esm/interactions/useInteractions.native.js.map +1 -1
- package/dist/esm/interactions/useListNavigation.mjs +331 -168
- package/dist/esm/interactions/useListNavigation.mjs.map +1 -1
- package/dist/esm/interactions/useListNavigation.native.js +335 -201
- package/dist/esm/interactions/useListNavigation.native.js.map +1 -1
- package/dist/esm/interactions/useRole.mjs +59 -51
- package/dist/esm/interactions/useRole.mjs.map +1 -1
- package/dist/esm/interactions/useRole.native.js +82 -76
- package/dist/esm/interactions/useRole.native.js.map +1 -1
- package/dist/esm/interactions/useTypeahead.mjs +100 -52
- package/dist/esm/interactions/useTypeahead.mjs.map +1 -1
- package/dist/esm/interactions/useTypeahead.native.js +107 -64
- package/dist/esm/interactions/useTypeahead.native.js.map +1 -1
- package/dist/esm/interactions/utils.mjs +56 -28
- package/dist/esm/interactions/utils.mjs.map +1 -1
- package/dist/esm/interactions/utils.native.js +81 -44
- package/dist/esm/interactions/utils.native.js.map +1 -1
- package/dist/esm/middleware/inner.mjs +54 -44
- package/dist/esm/middleware/inner.mjs.map +1 -1
- package/dist/esm/middleware/inner.native.js +61 -53
- package/dist/esm/middleware/inner.native.js.map +1 -1
- package/dist/esm/useFloating.mjs +22 -21
- package/dist/esm/useFloating.mjs.map +1 -1
- package/dist/esm/useFloating.native.js +24 -24
- package/dist/esm/useFloating.native.js.map +1 -1
- package/package.json +3 -3
- package/src/middleware/inner.ts +4 -5
- package/types/middleware/inner.d.ts.map +1 -1
|
@@ -4,33 +4,35 @@ var __create = Object.create;
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
8
|
-
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
9
|
var __export = (target, all) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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, {
|
|
17
18
|
get: () => from[key],
|
|
18
19
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
20
|
});
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
22
24
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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);
|
|
34
36
|
var useDelayGroup_exports = {};
|
|
35
37
|
__export(useDelayGroup_exports, {
|
|
36
38
|
FloatingDelayGroup: () => FloatingDelayGroup,
|
|
@@ -38,30 +40,35 @@ __export(useDelayGroup_exports, {
|
|
|
38
40
|
useDelayGroupContext: () => useDelayGroupContext
|
|
39
41
|
});
|
|
40
42
|
module.exports = __toCommonJS(useDelayGroup_exports);
|
|
41
|
-
var React = __toESM(require("react"), 1)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
+
});
|
|
49
51
|
function useDelayGroupContext() {
|
|
50
52
|
return React.useContext(DelayGroupContext);
|
|
51
53
|
}
|
|
52
54
|
function FloatingDelayGroup(param) {
|
|
53
55
|
var {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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 () {
|
|
62
66
|
setCurrentIdRaw(null);
|
|
63
|
-
}, timeoutMs)
|
|
64
|
-
}
|
|
67
|
+
}, timeoutMs);
|
|
68
|
+
} else {
|
|
69
|
+
setCurrentIdRaw(id);
|
|
70
|
+
}
|
|
71
|
+
}, [timeoutMs]);
|
|
65
72
|
React.useEffect(function () {
|
|
66
73
|
return function () {
|
|
67
74
|
return clearTimeout(timeoutRef.current);
|
|
@@ -81,29 +88,38 @@ function FloatingDelayGroup(param) {
|
|
|
81
88
|
}, children);
|
|
82
89
|
}
|
|
83
90
|
function useDelayGroup(context) {
|
|
84
|
-
var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
!context.open && groupContext.currentId === id
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}, [
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
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 {
|
|
100
116
|
delay: groupContext.initialDelay,
|
|
101
117
|
currentId: groupContext.currentId
|
|
102
118
|
};
|
|
103
119
|
}
|
|
104
120
|
function getClose(delay) {
|
|
105
|
-
if (typeof delay
|
|
121
|
+
if (typeof delay === "number") return delay;
|
|
106
122
|
var _delay_close;
|
|
107
|
-
return (_delay_close = delay
|
|
123
|
+
return (_delay_close = delay === null || delay === void 0 ? void 0 : delay.close) !== null && _delay_close !== void 0 ? _delay_close : 0;
|
|
108
124
|
}
|
|
109
125
|
//# sourceMappingURL=useDelayGroup.native.js.map
|
|
@@ -1 +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":"
|
|
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,EAAAA,CAAA,KAAAA,kBAAA;EAAAC,aAAA,EAAAA,CAAA,KAAAA,aAAA;EAAAC,oBAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAuB,GAAAX,YAAA,CAAAK,qBAAA;AAWvB,IAAAO,KAAM,GAAAC,OAAA,CAAAC,OAAoB,QAAM;AAAsC,IACpEC,iBAAW,GAAAH,KAAA,CAAAI,aAAA;EACXC,SAAA,MAAc;EAAOC,YAAA,WAAAA,CAAA,GACrB;EACAC,KAAA;EACAC,SAAA;EACDC,YAAA;AAEM;AACL,SAAOZ,oBAAiBA,CAAA;EAC1B,OAAAG,KAAA,CAAAU,UAAA,CAAAP,iBAAA;AAKO;AAA4B,SACjCR,mBAAAgB,KAAA;EACA;IAAAC,QAAA;IAAAL,KAAA;IAAAC,SAAA;EAAA,IAAAG,KAAA;EACA,KAAAN,SAAY,EAAAQ,eAAA,IAAAb,KAAA,CAAAc,QAAA;EACd,IAIGC,UAAA,GAAAf,KAAA,CAAAgB,MAAA;EACD,IAAAV,YAAO,GAAWN,KAAA,CAAAiB,WAAe,CAAI,UAAMC,EAAA;IAC3CC,YAAM,CAAAJ,UAAmB,CAAAK,OAAsC;IAE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D,YAAc,CAAAzB,SAAS;IACzB","ignoreList":[]}
|
|
@@ -3,95 +3,124 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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, {
|
|
13
14
|
get: () => from[key],
|
|
14
15
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
16
|
});
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
18
20
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
-
value:
|
|
21
|
+
value: true
|
|
20
22
|
}), mod);
|
|
21
23
|
var useFocus_exports = {};
|
|
22
24
|
__export(useFocus_exports, {
|
|
23
25
|
useFocus: () => useFocus
|
|
24
26
|
});
|
|
25
27
|
module.exports = __toCommonJS(useFocus_exports);
|
|
26
|
-
var import_react = require("react")
|
|
27
|
-
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_utils = require("./utils.cjs");
|
|
28
30
|
function isMacSafari() {
|
|
29
31
|
return (0, import_utils.isMac)() && (0, import_utils.isSafari)();
|
|
30
32
|
}
|
|
31
33
|
function useFocus(context, props = {}) {
|
|
32
34
|
const {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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);
|
|
46
48
|
(0, import_react.useEffect)(() => {
|
|
47
49
|
if (!enabled) return;
|
|
48
50
|
const win = (0, import_utils.getDocument)(elements.domReference).defaultView || window;
|
|
49
51
|
function onBlur() {
|
|
50
|
-
!open && (0, import_utils.isHTMLElement)(elements.domReference) && elements.domReference === (0, import_utils.activeElement)((0, import_utils.getDocument)(elements.domReference))
|
|
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
|
+
}
|
|
51
55
|
}
|
|
52
56
|
function onKeyDown() {
|
|
53
|
-
keyboardModalityRef.current =
|
|
57
|
+
keyboardModalityRef.current = true;
|
|
54
58
|
}
|
|
55
59
|
function onPointerDown() {
|
|
56
|
-
keyboardModalityRef.current =
|
|
60
|
+
keyboardModalityRef.current = false;
|
|
57
61
|
}
|
|
58
|
-
|
|
59
|
-
|
|
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
|
+
}
|
|
60
73
|
};
|
|
61
|
-
}, [elements.domReference, open, enabled])
|
|
62
|
-
|
|
74
|
+
}, [elements.domReference, open, enabled]);
|
|
75
|
+
(0, import_react.useEffect)(() => {
|
|
76
|
+
if (!enabled) return;
|
|
77
|
+
if (!events) return;
|
|
63
78
|
function handleOpenChange({
|
|
64
79
|
reason
|
|
65
80
|
}) {
|
|
66
|
-
(reason === "reference-press" || reason === "escape-key")
|
|
81
|
+
if (reason === "reference-press" || reason === "escape-key") {
|
|
82
|
+
blockFocusRef.current = true;
|
|
83
|
+
}
|
|
67
84
|
}
|
|
68
|
-
|
|
85
|
+
events.on("openchange", handleOpenChange);
|
|
86
|
+
return () => {
|
|
69
87
|
events.off("openchange", handleOpenChange);
|
|
70
88
|
};
|
|
71
|
-
}, [events, enabled])
|
|
72
|
-
|
|
89
|
+
}, [events, enabled]);
|
|
90
|
+
(0, import_react.useEffect)(() => {
|
|
91
|
+
return () => {
|
|
92
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutRef);
|
|
93
|
+
};
|
|
73
94
|
}, []);
|
|
74
95
|
const reference = (0, import_react.useMemo)(() => ({
|
|
75
96
|
onMouseLeave() {
|
|
76
|
-
blockFocusRef.current =
|
|
97
|
+
blockFocusRef.current = false;
|
|
77
98
|
},
|
|
78
99
|
onFocus(event) {
|
|
79
100
|
if (blockFocusRef.current) return;
|
|
80
101
|
const target = (0, import_utils.getTarget)(event.nativeEvent);
|
|
81
102
|
if (visibleOnly && (0, import_utils.isElement)(target)) {
|
|
82
103
|
if (isMacSafari() && !event.relatedTarget) {
|
|
83
|
-
if (!keyboardModalityRef.current && !(0, import_utils.isTypeableElement)(target))
|
|
84
|
-
|
|
104
|
+
if (!keyboardModalityRef.current && !(0, import_utils.isTypeableElement)(target)) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
} else if (!(0, import_utils.matchesFocusVisible)(target)) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
85
110
|
}
|
|
86
|
-
onOpenChange(
|
|
111
|
+
onOpenChange(true, event.nativeEvent, "focus");
|
|
87
112
|
},
|
|
88
113
|
onBlur(event) {
|
|
89
|
-
blockFocusRef.current =
|
|
90
|
-
const relatedTarget = event.relatedTarget
|
|
91
|
-
|
|
114
|
+
blockFocusRef.current = false;
|
|
115
|
+
const relatedTarget = event.relatedTarget;
|
|
116
|
+
const nativeEvent = event.nativeEvent;
|
|
92
117
|
timeoutRef.current = window.setTimeout(() => {
|
|
93
118
|
const activeEl = (0, import_utils.activeElement)(elements.domReference ? elements.domReference.ownerDocument : document);
|
|
94
|
-
!relatedTarget && activeEl === elements.domReference
|
|
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");
|
|
95
124
|
});
|
|
96
125
|
}
|
|
97
126
|
}), [context.refs.floating, elements.domReference, onOpenChange, visibleOnly]);
|
|
@@ -5,74 +5,93 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value:
|
|
23
|
+
value: true
|
|
22
24
|
}), mod);
|
|
23
25
|
var useFocus_exports = {};
|
|
24
26
|
__export(useFocus_exports, {
|
|
25
27
|
useFocus: () => useFocus
|
|
26
28
|
});
|
|
27
29
|
module.exports = __toCommonJS(useFocus_exports);
|
|
28
|
-
var import_react = require("react")
|
|
29
|
-
|
|
30
|
+
var import_react = require("react");
|
|
31
|
+
var import_utils = require("./utils.native.js");
|
|
30
32
|
function isMacSafari() {
|
|
31
33
|
return (0, import_utils.isMac)() && (0, import_utils.isSafari)();
|
|
32
34
|
}
|
|
33
35
|
function useFocus(context) {
|
|
34
|
-
var props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
var props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
37
|
+
var {
|
|
38
|
+
open,
|
|
39
|
+
onOpenChange,
|
|
40
|
+
events,
|
|
41
|
+
dataRef,
|
|
42
|
+
elements
|
|
43
|
+
} = context;
|
|
44
|
+
var {
|
|
45
|
+
enabled = true,
|
|
46
|
+
visibleOnly = true
|
|
47
|
+
} = props;
|
|
48
|
+
var blockFocusRef = (0, import_react.useRef)(false);
|
|
49
|
+
var timeoutRef = (0, import_react.useRef)(-1);
|
|
50
|
+
var keyboardModalityRef = (0, import_react.useRef)(true);
|
|
49
51
|
(0, import_react.useEffect)(function () {
|
|
50
52
|
if (!enabled) return;
|
|
51
53
|
var win = (0, import_utils.getDocument)(elements.domReference).defaultView || window;
|
|
52
54
|
function onBlur() {
|
|
53
|
-
!open && (0, import_utils.isHTMLElement)(elements.domReference) && elements.domReference === (0, import_utils.activeElement)((0, import_utils.getDocument)(elements.domReference))
|
|
55
|
+
if (!open && (0, import_utils.isHTMLElement)(elements.domReference) && elements.domReference === (0, import_utils.activeElement)((0, import_utils.getDocument)(elements.domReference))) {
|
|
56
|
+
blockFocusRef.current = true;
|
|
57
|
+
}
|
|
54
58
|
}
|
|
55
59
|
function onKeyDown() {
|
|
56
|
-
keyboardModalityRef.current =
|
|
60
|
+
keyboardModalityRef.current = true;
|
|
57
61
|
}
|
|
58
62
|
function onPointerDown() {
|
|
59
|
-
keyboardModalityRef.current =
|
|
63
|
+
keyboardModalityRef.current = false;
|
|
64
|
+
}
|
|
65
|
+
win.addEventListener("blur", onBlur);
|
|
66
|
+
if (isMacSafari()) {
|
|
67
|
+
win.addEventListener("keydown", onKeyDown, true);
|
|
68
|
+
win.addEventListener("pointerdown", onPointerDown, true);
|
|
60
69
|
}
|
|
61
|
-
return
|
|
62
|
-
win.removeEventListener("blur", onBlur)
|
|
70
|
+
return function () {
|
|
71
|
+
win.removeEventListener("blur", onBlur);
|
|
72
|
+
if (isMacSafari()) {
|
|
73
|
+
win.removeEventListener("keydown", onKeyDown, true);
|
|
74
|
+
win.removeEventListener("pointerdown", onPointerDown, true);
|
|
75
|
+
}
|
|
63
76
|
};
|
|
64
|
-
}, [elements.domReference, open, enabled])
|
|
65
|
-
|
|
77
|
+
}, [elements.domReference, open, enabled]);
|
|
78
|
+
(0, import_react.useEffect)(function () {
|
|
79
|
+
if (!enabled) return;
|
|
80
|
+
if (!events) return;
|
|
66
81
|
function handleOpenChange(param) {
|
|
67
82
|
var {
|
|
68
83
|
reason
|
|
69
84
|
} = param;
|
|
70
|
-
(reason === "reference-press" || reason === "escape-key")
|
|
85
|
+
if (reason === "reference-press" || reason === "escape-key") {
|
|
86
|
+
blockFocusRef.current = true;
|
|
87
|
+
}
|
|
71
88
|
}
|
|
72
|
-
|
|
89
|
+
events.on("openchange", handleOpenChange);
|
|
90
|
+
return function () {
|
|
73
91
|
events.off("openchange", handleOpenChange);
|
|
74
92
|
};
|
|
75
|
-
}, [events, enabled])
|
|
93
|
+
}, [events, enabled]);
|
|
94
|
+
(0, import_react.useEffect)(function () {
|
|
76
95
|
return function () {
|
|
77
96
|
(0, import_utils.clearTimeoutIfSet)(timeoutRef);
|
|
78
97
|
};
|
|
@@ -80,26 +99,33 @@ function useFocus(context) {
|
|
|
80
99
|
var reference = (0, import_react.useMemo)(function () {
|
|
81
100
|
return {
|
|
82
101
|
onMouseLeave() {
|
|
83
|
-
blockFocusRef.current =
|
|
102
|
+
blockFocusRef.current = false;
|
|
84
103
|
},
|
|
85
104
|
onFocus(event) {
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
105
|
+
if (blockFocusRef.current) return;
|
|
106
|
+
var target = (0, import_utils.getTarget)(event.nativeEvent);
|
|
107
|
+
if (visibleOnly && (0, import_utils.isElement)(target)) {
|
|
108
|
+
if (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;
|
|
92
114
|
}
|
|
93
|
-
onOpenChange(!0, event.nativeEvent, "focus");
|
|
94
115
|
}
|
|
116
|
+
onOpenChange(true, event.nativeEvent, "focus");
|
|
95
117
|
},
|
|
96
118
|
onBlur(event) {
|
|
97
|
-
blockFocusRef.current =
|
|
98
|
-
var relatedTarget = event.relatedTarget
|
|
99
|
-
|
|
119
|
+
blockFocusRef.current = false;
|
|
120
|
+
var relatedTarget = event.relatedTarget;
|
|
121
|
+
var nativeEvent = event.nativeEvent;
|
|
100
122
|
timeoutRef.current = window.setTimeout(function () {
|
|
101
123
|
var activeEl = (0, import_utils.activeElement)(elements.domReference ? elements.domReference.ownerDocument : document);
|
|
102
|
-
!relatedTarget && activeEl === elements.domReference
|
|
124
|
+
if (!relatedTarget && activeEl === elements.domReference) return;
|
|
125
|
+
if ((0, import_utils.contains)(context.refs.floating.current, activeEl) || (0, import_utils.contains)(elements.domReference, activeEl)) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
onOpenChange(false, nativeEvent, "focus");
|
|
103
129
|
});
|
|
104
130
|
}
|
|
105
131
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useFocus_exports","__export","useFocus","module","exports","import_react","require","import_utils","isMacSafari","isMac","isSafari","context","props","arguments","length","open","onOpenChange","events","dataRef","elements","enabled","visibleOnly","blockFocusRef","useRef","timeoutRef","keyboardModalityRef","useEffect","win","getDocument","domReference","defaultView","window","onBlur","isHTMLElement","activeElement","current","onKeyDown","onPointerDown","addEventListener","removeEventListener","handleOpenChange","param","reason","on","off","clearTimeoutIfSet","reference","useMemo","onMouseLeave","onFocus","event","target","getTarget","nativeEvent","isElement","relatedTarget","isTypeableElement","matchesFocusVisible"],"sources":["../../../src/interactions/useFocus.ts"],"sourcesContent":[null],"mappings":"
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useFocus_exports","__export","useFocus","module","exports","import_react","require","import_utils","isMacSafari","isMac","isSafari","context","props","arguments","length","open","onOpenChange","events","dataRef","elements","enabled","visibleOnly","blockFocusRef","useRef","timeoutRef","keyboardModalityRef","useEffect","win","getDocument","domReference","defaultView","window","onBlur","isHTMLElement","activeElement","current","onKeyDown","onPointerDown","addEventListener","removeEventListener","handleOpenChange","param","reason","on","off","clearTimeoutIfSet","reference","useMemo","onMouseLeave","onFocus","event","target","getTarget","nativeEvent","isElement","relatedTarget","isTypeableElement","matchesFocusVisible","setTimeout","activeEl","ownerDocument","document","contains","refs","floating"],"sources":["../../../src/interactions/useFocus.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,YAA2C,CAAAK,gBAAA;AAQ3C,IAAAK,YAAA,GAYOC,OAAA;AAEP,IAAAC,YAAS,GAAAD,OAAc;AACrB,SAAAE,WAAOA,CAAA;EACT,WAAAD,YAAA,CAAAE,KAAA,WAAAF,YAAA,CAAAG,QAAA;AAIO;AAIL,SAAMR,QAAQA,CAAAS,OAAA;EACd,IAAAC,KAAQ,GAAAC,SAAU,CAAAC,MAAM,QAAAD,SAAmB,EAAI,eAAAA,SAAA;EAE/C;IAAME,IAAA;IAAAC,YAAA;IAAgBC,MAAA;IAAAC,OAAA;IAAAC;EAAY,IAAAR,OAAA;EAClC;IAAMS,OAAA;IAAAC,WAAa;EAAA,IAAOT,KAAE;EAC5B,IAAAU,aAAM,OAAAjB,YAAsB,CAAAkB,MAAA;EAK5B,IAAAC,UAAA,OAAAnB,YAAU,CAAMkB,MAAA;EACd,IAAAE,mBAAc,OAAApB,YAAA,CAAAkB,MAAA;EAEd,IAAAlB,YAAM,CAAAqB,SAAM;IAEZ,KAAAN,OAAS;IACP,IAAAO,GACG,OAAApB,YACD,CAAAqB,WAAA,EAAAT,QAAc,CAAAU,YAAS,EAAAC,WACvB,IAAAC,MAAS;IAET,SAAAC,OAAA,EAAc;MAChB,KAAAjB,IAAA,QAAAR,YAAA,CAAA0B,aAAA,EAAAd,QAAA,CAAAU,YAAA,KAAAV,QAAA,CAAA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