@tamagui/floating 2.7.7 → 3.0.0-beta.637.1
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 +10 -11
- package/dist/cjs/Floating.native.cjs +37 -0
- package/dist/cjs/Floating.native.js +20 -20
- package/dist/cjs/Floating.native.js.map +1 -1
- package/dist/cjs/index.cjs +45 -46
- package/dist/cjs/index.native.cjs +74 -0
- package/dist/cjs/index.native.js +45 -45
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/interactions/PopupTriggerMap.cjs +36 -39
- package/dist/cjs/interactions/PopupTriggerMap.native.cjs +96 -0
- package/dist/cjs/interactions/PopupTriggerMap.native.js +76 -75
- package/dist/cjs/interactions/PopupTriggerMap.native.js.map +1 -1
- package/dist/cjs/interactions/createFloatingEvents.cjs +36 -39
- package/dist/cjs/interactions/createFloatingEvents.native.cjs +52 -0
- package/dist/cjs/interactions/createFloatingEvents.native.js +39 -41
- package/dist/cjs/interactions/createFloatingEvents.native.js.map +1 -1
- package/dist/cjs/interactions/safePolygon.cjs +263 -252
- package/dist/cjs/interactions/safePolygon.native.cjs +294 -0
- package/dist/cjs/interactions/safePolygon.native.js +271 -259
- package/dist/cjs/interactions/safePolygon.native.js.map +1 -1
- package/dist/cjs/interactions/types.cjs +10 -11
- package/dist/cjs/interactions/types.native.cjs +19 -0
- package/dist/cjs/interactions/types.native.js +10 -10
- package/dist/cjs/interactions/types.native.js.map +1 -1
- package/dist/cjs/interactions/useClick.cjs +96 -105
- package/dist/cjs/interactions/useClick.native.cjs +122 -0
- package/dist/cjs/interactions/useClick.native.js +101 -109
- package/dist/cjs/interactions/useClick.native.js.map +1 -1
- package/dist/cjs/interactions/useDelayGroup.cjs +86 -91
- package/dist/cjs/interactions/useDelayGroup.native.cjs +119 -0
- package/dist/cjs/interactions/useDelayGroup.native.js +92 -96
- package/dist/cjs/interactions/useDelayGroup.native.js.map +1 -1
- package/dist/cjs/interactions/useFocus.cjs +108 -115
- package/dist/cjs/interactions/useFocus.native.cjs +131 -0
- package/dist/cjs/interactions/useFocus.native.js +114 -120
- package/dist/cjs/interactions/useFocus.native.js.map +1 -1
- package/dist/cjs/interactions/useHover.cjs +321 -335
- package/dist/cjs/interactions/useHover.native.cjs +357 -0
- package/dist/cjs/interactions/useHover.native.js +333 -347
- package/dist/cjs/interactions/useHover.native.js.map +1 -1
- package/dist/cjs/interactions/useInnerOffset.cjs +103 -111
- package/dist/cjs/interactions/useInnerOffset.native.cjs +132 -0
- package/dist/cjs/interactions/useInnerOffset.native.js +113 -120
- package/dist/cjs/interactions/useInnerOffset.native.js.map +1 -1
- package/dist/cjs/interactions/useInteractions.cjs +85 -90
- package/dist/cjs/interactions/useInteractions.native.cjs +199 -0
- package/dist/cjs/interactions/useInteractions.native.js +180 -195
- package/dist/cjs/interactions/useInteractions.native.js.map +1 -1
- package/dist/cjs/interactions/useListNavigation.cjs +404 -390
- package/dist/cjs/interactions/useListNavigation.native.cjs +446 -0
- package/dist/cjs/interactions/useListNavigation.native.js +416 -401
- package/dist/cjs/interactions/useListNavigation.native.js.map +1 -1
- package/dist/cjs/interactions/useRole.cjs +92 -106
- package/dist/cjs/interactions/useRole.native.cjs +121 -0
- package/dist/cjs/interactions/useRole.native.js +103 -116
- package/dist/cjs/interactions/useRole.native.js.map +1 -1
- package/dist/cjs/interactions/useTypeahead.cjs +115 -129
- package/dist/cjs/interactions/useTypeahead.native.cjs +144 -0
- package/dist/cjs/interactions/useTypeahead.native.js +128 -141
- package/dist/cjs/interactions/useTypeahead.native.js.map +1 -1
- package/dist/cjs/interactions/utils.cjs +126 -143
- package/dist/cjs/interactions/utils.native.cjs +209 -0
- package/dist/cjs/interactions/utils.native.js +138 -154
- package/dist/cjs/interactions/utils.native.js.map +1 -1
- package/dist/cjs/middleware/inner.cjs +74 -101
- package/dist/cjs/middleware/inner.native.cjs +102 -0
- package/dist/cjs/middleware/inner.native.js +83 -109
- package/dist/cjs/middleware/inner.native.js.map +1 -1
- package/dist/cjs/useFloating.cjs +34 -46
- package/dist/cjs/useFloating.native.cjs +56 -0
- package/dist/cjs/useFloating.native.js +37 -48
- package/dist/cjs/useFloating.native.js.map +1 -1
- package/dist/esm/Floating.mjs +1 -2
- package/dist/esm/Floating.native.js +6 -4
- package/dist/esm/Floating.native.js.map +1 -1
- package/dist/esm/index.js +4 -5
- package/dist/esm/index.mjs +4 -5
- package/dist/esm/index.native.js +4 -5
- package/dist/esm/interactions/PopupTriggerMap.mjs +23 -22
- package/dist/esm/interactions/PopupTriggerMap.mjs.map +1 -1
- package/dist/esm/interactions/PopupTriggerMap.native.js +62 -58
- package/dist/esm/interactions/PopupTriggerMap.native.js.map +1 -1
- package/dist/esm/interactions/createFloatingEvents.mjs +22 -21
- package/dist/esm/interactions/createFloatingEvents.mjs.map +1 -1
- package/dist/esm/interactions/createFloatingEvents.native.js +25 -24
- package/dist/esm/interactions/createFloatingEvents.native.js.map +1 -1
- package/dist/esm/interactions/safePolygon.mjs +250 -234
- package/dist/esm/interactions/safePolygon.mjs.map +1 -1
- package/dist/esm/interactions/safePolygon.native.js +258 -242
- package/dist/esm/interactions/safePolygon.native.js.map +1 -1
- package/dist/esm/interactions/types.mjs +0 -2
- package/dist/esm/interactions/types.native.js +0 -2
- package/dist/esm/interactions/useClick.mjs +83 -87
- package/dist/esm/interactions/useClick.mjs.map +1 -1
- package/dist/esm/interactions/useClick.native.js +88 -92
- package/dist/esm/interactions/useClick.native.js.map +1 -1
- package/dist/esm/interactions/useDelayGroup.mjs +68 -65
- package/dist/esm/interactions/useDelayGroup.mjs.map +1 -1
- package/dist/esm/interactions/useDelayGroup.native.js +74 -71
- package/dist/esm/interactions/useDelayGroup.native.js.map +1 -1
- package/dist/esm/interactions/useFocus.mjs +95 -97
- package/dist/esm/interactions/useFocus.mjs.map +1 -1
- package/dist/esm/interactions/useFocus.native.js +101 -103
- package/dist/esm/interactions/useFocus.native.js.map +1 -1
- package/dist/esm/interactions/useHover.mjs +304 -310
- package/dist/esm/interactions/useHover.mjs.map +1 -1
- package/dist/esm/interactions/useHover.native.js +316 -323
- package/dist/esm/interactions/useHover.native.js.map +1 -1
- package/dist/esm/interactions/useInnerOffset.mjs +87 -85
- package/dist/esm/interactions/useInnerOffset.mjs.map +1 -1
- package/dist/esm/interactions/useInnerOffset.native.js +97 -95
- package/dist/esm/interactions/useInnerOffset.native.js.map +1 -1
- package/dist/esm/interactions/useInteractions.mjs +71 -72
- package/dist/esm/interactions/useInteractions.mjs.map +1 -1
- package/dist/esm/interactions/useInteractions.native.js +166 -178
- package/dist/esm/interactions/useInteractions.native.js.map +1 -1
- package/dist/esm/interactions/useListNavigation.mjs +392 -373
- package/dist/esm/interactions/useListNavigation.mjs.map +1 -1
- package/dist/esm/interactions/useListNavigation.native.js +404 -385
- package/dist/esm/interactions/useListNavigation.native.js.map +1 -1
- package/dist/esm/interactions/useRole.mjs +76 -80
- package/dist/esm/interactions/useRole.mjs.map +1 -1
- package/dist/esm/interactions/useRole.native.js +87 -91
- package/dist/esm/interactions/useRole.native.js.map +1 -1
- package/dist/esm/interactions/useTypeahead.mjs +102 -111
- package/dist/esm/interactions/useTypeahead.mjs.map +1 -1
- package/dist/esm/interactions/useTypeahead.native.js +115 -124
- package/dist/esm/interactions/useTypeahead.native.js.map +1 -1
- package/dist/esm/interactions/utils.mjs +91 -106
- package/dist/esm/interactions/utils.mjs.map +1 -1
- package/dist/esm/interactions/utils.native.js +103 -118
- package/dist/esm/interactions/utils.native.js.map +1 -1
- package/dist/esm/middleware/inner.mjs +58 -75
- package/dist/esm/middleware/inner.mjs.map +1 -1
- package/dist/esm/middleware/inner.native.js +67 -84
- package/dist/esm/middleware/inner.native.js.map +1 -1
- package/dist/esm/useFloating.mjs +17 -21
- package/dist/esm/useFloating.mjs.map +1 -1
- package/dist/esm/useFloating.native.js +19 -23
- package/dist/esm/useFloating.native.js.map +1 -1
- package/package.json +6 -5
- package/types/interactions/PopupTriggerMap.d.ts.map +1 -1
- package/types/interactions/useInteractions.d.ts.map +1 -1
- package/types/middleware/inner.d.ts.map +1 -1
- package/types/useFloating.d.ts.map +1 -1
- package/dist/esm/Floating.mjs.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
- package/dist/esm/interactions/types.mjs.map +0 -1
- package/dist/esm/interactions/types.native.js.map +0 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
var __create = Object.create;
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
5
6
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -7,130 +8,116 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
7
8
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
10
|
var __export = (target, all) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
14
15
|
};
|
|
15
16
|
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: () => from[key],
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
23
24
|
};
|
|
24
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
-
|
|
26
|
-
|
|
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
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
32
28
|
}) : target, mod));
|
|
33
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
-
value: true
|
|
35
|
-
}), mod);
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
30
|
var useRole_exports = {};
|
|
37
|
-
__export(useRole_exports, {
|
|
38
|
-
useRole: () => useRole
|
|
39
|
-
});
|
|
31
|
+
__export(useRole_exports, { useRole: () => useRole });
|
|
40
32
|
module.exports = __toCommonJS(useRole_exports);
|
|
41
33
|
var React = __toESM(require("react"), 1);
|
|
42
|
-
var componentRoleToAriaRoleMap = /* @__PURE__ */new Map([
|
|
34
|
+
var componentRoleToAriaRoleMap = /* @__PURE__ */ new Map([
|
|
35
|
+
["select", "listbox"],
|
|
36
|
+
["combobox", "listbox"],
|
|
37
|
+
["label", false]
|
|
38
|
+
]);
|
|
43
39
|
var idCounter = 0;
|
|
44
40
|
function useRole(context) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
return {};
|
|
127
|
-
}, [floatingId, role]);
|
|
128
|
-
return React.useMemo(function () {
|
|
129
|
-
return enabled ? {
|
|
130
|
-
reference,
|
|
131
|
-
floating,
|
|
132
|
-
item
|
|
133
|
-
} : {};
|
|
134
|
-
}, [enabled, reference, floating, item]);
|
|
41
|
+
var props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
42
|
+
var _elements_domReference;
|
|
43
|
+
var { open, elements } = context;
|
|
44
|
+
var { enabled = true, role = "dialog" } = props;
|
|
45
|
+
var defaultReferenceId = React.useId();
|
|
46
|
+
var referenceId = ((_elements_domReference = elements.domReference) === null || _elements_domReference === void 0 ? void 0 : _elements_domReference.id) || defaultReferenceId;
|
|
47
|
+
var defaultFloatingId = React.useMemo(function() {
|
|
48
|
+
return `floating-${idCounter++}`;
|
|
49
|
+
}, []);
|
|
50
|
+
var floatingId = React.useMemo(function() {
|
|
51
|
+
var _elements_floating;
|
|
52
|
+
return ((_elements_floating = elements.floating) === null || _elements_floating === void 0 ? void 0 : _elements_floating.id) || defaultFloatingId;
|
|
53
|
+
}, [elements.floating, defaultFloatingId]);
|
|
54
|
+
var _componentRoleToAriaRoleMap_get;
|
|
55
|
+
var ariaRole = (_componentRoleToAriaRoleMap_get = componentRoleToAriaRoleMap.get(role)) !== null && _componentRoleToAriaRoleMap_get !== void 0 ? _componentRoleToAriaRoleMap_get : role;
|
|
56
|
+
var reference = React.useMemo(function() {
|
|
57
|
+
if (ariaRole === "tooltip" || role === "label") {
|
|
58
|
+
return { [`aria-${role === "label" ? "labelledby" : "describedby"}`]: open ? floatingId : void 0 };
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
"aria-expanded": open ? "true" : "false",
|
|
62
|
+
"aria-haspopup": ariaRole === "alertdialog" ? "dialog" : ariaRole,
|
|
63
|
+
"aria-controls": open ? floatingId : void 0,
|
|
64
|
+
...ariaRole === "listbox" && { role: "combobox" },
|
|
65
|
+
...ariaRole === "menu" && { id: referenceId },
|
|
66
|
+
...role === "select" && { "aria-autocomplete": "none" },
|
|
67
|
+
...role === "combobox" && { "aria-autocomplete": "list" }
|
|
68
|
+
};
|
|
69
|
+
}, [
|
|
70
|
+
ariaRole,
|
|
71
|
+
floatingId,
|
|
72
|
+
open,
|
|
73
|
+
referenceId,
|
|
74
|
+
role
|
|
75
|
+
]);
|
|
76
|
+
var floating = React.useMemo(function() {
|
|
77
|
+
var floatingProps = {
|
|
78
|
+
id: floatingId,
|
|
79
|
+
...ariaRole && { role: ariaRole }
|
|
80
|
+
};
|
|
81
|
+
if (ariaRole === "tooltip" || role === "label") {
|
|
82
|
+
return floatingProps;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
...floatingProps,
|
|
86
|
+
...ariaRole === "menu" && { "aria-labelledby": referenceId }
|
|
87
|
+
};
|
|
88
|
+
}, [
|
|
89
|
+
ariaRole,
|
|
90
|
+
floatingId,
|
|
91
|
+
referenceId,
|
|
92
|
+
role
|
|
93
|
+
]);
|
|
94
|
+
var item = React.useCallback(function(param) {
|
|
95
|
+
var { active, selected } = param;
|
|
96
|
+
var commonProps = {
|
|
97
|
+
role: "option",
|
|
98
|
+
...active && { id: `${floatingId}-fui-option` }
|
|
99
|
+
};
|
|
100
|
+
switch (role) {
|
|
101
|
+
case "select":
|
|
102
|
+
case "combobox": return {
|
|
103
|
+
...commonProps,
|
|
104
|
+
"aria-selected": selected
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
return {};
|
|
108
|
+
}, [floatingId, role]);
|
|
109
|
+
return React.useMemo(function() {
|
|
110
|
+
return enabled ? {
|
|
111
|
+
reference,
|
|
112
|
+
floating,
|
|
113
|
+
item
|
|
114
|
+
} : {};
|
|
115
|
+
}, [
|
|
116
|
+
enabled,
|
|
117
|
+
reference,
|
|
118
|
+
floating,
|
|
119
|
+
item
|
|
120
|
+
]);
|
|
135
121
|
}
|
|
122
|
+
|
|
136
123
|
//# sourceMappingURL=useRole.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"useRole.native.js","names":[],"sources":["cjs/interactions/useRole.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useRole_exports = {};\n__export(useRole_exports, {\n useRole: () => useRole\n});\nmodule.exports = __toCommonJS(useRole_exports);\nvar React = __toESM(require(\"react\"), 1);\nvar componentRoleToAriaRoleMap = /* @__PURE__ */ new Map([\n [\n \"select\",\n \"listbox\"\n ],\n [\n \"combobox\",\n \"listbox\"\n ],\n [\n \"label\",\n false\n ]\n]);\nvar idCounter = 0;\nfunction useRole(context) {\n var props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};\n var _elements_domReference;\n var { open, elements } = context;\n var { enabled = true, role = \"dialog\" } = props;\n var defaultReferenceId = React.useId();\n var referenceId = ((_elements_domReference = elements.domReference) === null || _elements_domReference === void 0 ? void 0 : _elements_domReference.id) || defaultReferenceId;\n var defaultFloatingId = React.useMemo(function() {\n return `floating-${idCounter++}`;\n }, []);\n var floatingId = React.useMemo(function() {\n var _elements_floating;\n return ((_elements_floating = elements.floating) === null || _elements_floating === void 0 ? void 0 : _elements_floating.id) || defaultFloatingId;\n }, [\n elements.floating,\n defaultFloatingId\n ]);\n var _componentRoleToAriaRoleMap_get;\n var ariaRole = (_componentRoleToAriaRoleMap_get = componentRoleToAriaRoleMap.get(role)) !== null && _componentRoleToAriaRoleMap_get !== void 0 ? _componentRoleToAriaRoleMap_get : role;\n var reference = React.useMemo(function() {\n if (ariaRole === \"tooltip\" || role === \"label\") {\n return {\n [`aria-${role === \"label\" ? \"labelledby\" : \"describedby\"}`]: open ? floatingId : void 0\n };\n }\n return {\n \"aria-expanded\": open ? \"true\" : \"false\",\n \"aria-haspopup\": ariaRole === \"alertdialog\" ? \"dialog\" : ariaRole,\n \"aria-controls\": open ? floatingId : void 0,\n ...ariaRole === \"listbox\" && {\n role: \"combobox\"\n },\n ...ariaRole === \"menu\" && {\n id: referenceId\n },\n ...role === \"select\" && {\n \"aria-autocomplete\": \"none\"\n },\n ...role === \"combobox\" && {\n \"aria-autocomplete\": \"list\"\n }\n };\n }, [\n ariaRole,\n floatingId,\n open,\n referenceId,\n role\n ]);\n var floating = React.useMemo(function() {\n var floatingProps = {\n id: floatingId,\n ...ariaRole && {\n role: ariaRole\n }\n };\n if (ariaRole === \"tooltip\" || role === \"label\") {\n return floatingProps;\n }\n return {\n ...floatingProps,\n ...ariaRole === \"menu\" && {\n \"aria-labelledby\": referenceId\n }\n };\n }, [\n ariaRole,\n floatingId,\n referenceId,\n role\n ]);\n var item = React.useCallback(function(param) {\n var { active, selected } = param;\n var commonProps = {\n role: \"option\",\n ...active && {\n id: `${floatingId}-fui-option`\n }\n };\n switch (role) {\n case \"select\":\n case \"combobox\":\n return {\n ...commonProps,\n \"aria-selected\": selected\n };\n }\n return {};\n }, [\n floatingId,\n role\n ]);\n return React.useMemo(function() {\n return enabled ? {\n reference,\n floating,\n item\n } : {};\n }, [\n enabled,\n reference,\n floating,\n item\n ]);\n}\n//# sourceMappingURL=useRole.js.map\n"],"mappings":";;;;AACA,IAAI,WAAW,OAAO;AACtB,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO;AAC1B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QA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K,YACH,OAAO;IACL,GAAG;IACH,iBAAiB;GACnB;EACJ;EACA,OAAO,CAAC;CACV,GAAG,CACD,YACA,IACF,CAAC;CACD,OAAO,MAAM,QAAQ,WAAW;EAC9B,OAAO,UAAU;GACf;GACA;GACA;EACF,IAAI,CAAC;CACP,GAAG;EACD;EACA;EACA;EACA;CACF,CAAC;AACH"}
|
|
@@ -1,143 +1,129 @@
|
|
|
1
|
+
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
6
|
var __export = (target, all) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
for (var name in all) __defProp(target, name, {
|
|
8
|
+
get: all[name],
|
|
9
|
+
enumerable: true
|
|
10
|
+
});
|
|
10
11
|
};
|
|
11
12
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
19
20
|
};
|
|
20
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
-
value: true
|
|
22
|
-
}), mod);
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
22
|
var useTypeahead_exports = {};
|
|
24
|
-
__export(useTypeahead_exports, {
|
|
25
|
-
useTypeahead: () => useTypeahead
|
|
26
|
-
});
|
|
23
|
+
__export(useTypeahead_exports, { useTypeahead: () => useTypeahead });
|
|
27
24
|
module.exports = __toCommonJS(useTypeahead_exports);
|
|
28
25
|
var import_react = require("react");
|
|
29
26
|
var import_use_event = require("@tamagui/use-event");
|
|
30
27
|
var import_utils = require("./utils.cjs");
|
|
31
28
|
function useTypeahead(context, props) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
onKeyUp(event) {
|
|
134
|
-
if (event.key === " ") {
|
|
135
|
-
setTypingChange(false);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}), [open, enabled]);
|
|
139
|
-
return (0, import_react.useMemo)(() => enabled ? {
|
|
140
|
-
reference,
|
|
141
|
-
floating
|
|
142
|
-
} : {}, [enabled, reference, floating]);
|
|
143
|
-
}
|
|
29
|
+
const { open, dataRef } = context;
|
|
30
|
+
const { listRef, activeIndex, onMatch: unstable_onMatch, onTypingChange: unstable_onTypingChange, enabled = true, findMatch = null, resetMs = 750, ignoreKeys = [], selectedIndex = null } = props;
|
|
31
|
+
const timeoutIdRef = (0, import_react.useRef)(-1);
|
|
32
|
+
const stringRef = (0, import_react.useRef)("");
|
|
33
|
+
const prevIndexRef = (0, import_react.useRef)(selectedIndex ?? activeIndex ?? -1);
|
|
34
|
+
const matchIndexRef = (0, import_react.useRef)(null);
|
|
35
|
+
const onMatch = (0, import_use_event.useEvent)(unstable_onMatch || (() => {}));
|
|
36
|
+
const onTypingChange = (0, import_use_event.useEvent)(unstable_onTypingChange || (() => {}));
|
|
37
|
+
const findMatchRef = (0, import_react.useRef)(findMatch);
|
|
38
|
+
findMatchRef.current = findMatch;
|
|
39
|
+
const ignoreKeysRef = (0, import_react.useRef)(ignoreKeys);
|
|
40
|
+
ignoreKeysRef.current = ignoreKeys;
|
|
41
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
42
|
+
if (open) {
|
|
43
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutIdRef);
|
|
44
|
+
matchIndexRef.current = null;
|
|
45
|
+
stringRef.current = "";
|
|
46
|
+
}
|
|
47
|
+
}, [open]);
|
|
48
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
49
|
+
if (open && stringRef.current === "") {
|
|
50
|
+
prevIndexRef.current = selectedIndex ?? activeIndex ?? -1;
|
|
51
|
+
}
|
|
52
|
+
}, [
|
|
53
|
+
open,
|
|
54
|
+
selectedIndex,
|
|
55
|
+
activeIndex
|
|
56
|
+
]);
|
|
57
|
+
const setTypingChange = (value) => {
|
|
58
|
+
if (value) {
|
|
59
|
+
if (!dataRef.current.typing) {
|
|
60
|
+
dataRef.current.typing = value;
|
|
61
|
+
onTypingChange(value);
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
if (dataRef.current.typing) {
|
|
65
|
+
dataRef.current.typing = value;
|
|
66
|
+
onTypingChange(value);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const onKeyDown = (event) => {
|
|
71
|
+
function getMatchingIndex(list, orderedList, string) {
|
|
72
|
+
const str = findMatchRef.current ? findMatchRef.current(orderedList, string) : orderedList.find((text) => text?.toLocaleLowerCase().indexOf(string.toLocaleLowerCase()) === 0);
|
|
73
|
+
return str ? list.indexOf(str) : -1;
|
|
74
|
+
}
|
|
75
|
+
const listContent = listRef.current;
|
|
76
|
+
if (stringRef.current.length > 0 && stringRef.current[0] !== " ") {
|
|
77
|
+
if (getMatchingIndex(listContent, listContent, stringRef.current) === -1) {
|
|
78
|
+
setTypingChange(false);
|
|
79
|
+
} else if (event.key === " ") {
|
|
80
|
+
(0, import_utils.stopEvent)(event);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (listContent == null || ignoreKeysRef.current.includes(event.key) || event.key.length !== 1 || event.ctrlKey || event.metaKey || event.altKey) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (open && event.key !== " ") {
|
|
87
|
+
(0, import_utils.stopEvent)(event);
|
|
88
|
+
setTypingChange(true);
|
|
89
|
+
}
|
|
90
|
+
const allowRapidSuccessionOfFirstLetter = listContent.every((text) => text ? text[0]?.toLocaleLowerCase() !== text[1]?.toLocaleLowerCase() : true);
|
|
91
|
+
if (allowRapidSuccessionOfFirstLetter && stringRef.current === event.key) {
|
|
92
|
+
stringRef.current = "";
|
|
93
|
+
prevIndexRef.current = matchIndexRef.current;
|
|
94
|
+
}
|
|
95
|
+
stringRef.current += event.key;
|
|
96
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutIdRef);
|
|
97
|
+
timeoutIdRef.current = window.setTimeout(() => {
|
|
98
|
+
stringRef.current = "";
|
|
99
|
+
prevIndexRef.current = matchIndexRef.current;
|
|
100
|
+
setTypingChange(false);
|
|
101
|
+
}, resetMs);
|
|
102
|
+
const prevIndex = prevIndexRef.current;
|
|
103
|
+
const index = getMatchingIndex(listContent, [...listContent.slice((prevIndex || 0) + 1), ...listContent.slice(0, (prevIndex || 0) + 1)], stringRef.current);
|
|
104
|
+
if (index !== -1) {
|
|
105
|
+
onMatch(index);
|
|
106
|
+
matchIndexRef.current = index;
|
|
107
|
+
} else if (event.key !== " ") {
|
|
108
|
+
stringRef.current = "";
|
|
109
|
+
setTypingChange(false);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const reference = (0, import_react.useMemo)(() => ({ onKeyDown }), [open, enabled]);
|
|
113
|
+
const floating = (0, import_react.useMemo)(() => ({
|
|
114
|
+
onKeyDown,
|
|
115
|
+
onKeyUp(event) {
|
|
116
|
+
if (event.key === " ") {
|
|
117
|
+
setTypingChange(false);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}), [open, enabled]);
|
|
121
|
+
return (0, import_react.useMemo)(() => enabled ? {
|
|
122
|
+
reference,
|
|
123
|
+
floating
|
|
124
|
+
} : {}, [
|
|
125
|
+
enabled,
|
|
126
|
+
reference,
|
|
127
|
+
floating
|
|
128
|
+
]);
|
|
129
|
+
}
|