@tamagui/floating 2.7.6 → 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
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var useTypeahead_exports = {};
|
|
25
|
+
__export(useTypeahead_exports, { useTypeahead: () => useTypeahead });
|
|
26
|
+
module.exports = __toCommonJS(useTypeahead_exports);
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
var import_use_event = require("@tamagui/use-event");
|
|
29
|
+
var import_utils = require("./utils.native.js");
|
|
30
|
+
function useTypeahead(context, props) {
|
|
31
|
+
var { open, dataRef } = context;
|
|
32
|
+
var { listRef, activeIndex, onMatch: unstable_onMatch, onTypingChange: unstable_onTypingChange, enabled = true, findMatch = null, resetMs = 750, ignoreKeys = [], selectedIndex = null } = props;
|
|
33
|
+
var timeoutIdRef = (0, import_react.useRef)(-1);
|
|
34
|
+
var stringRef = (0, import_react.useRef)("");
|
|
35
|
+
var _ref;
|
|
36
|
+
var prevIndexRef = (0, import_react.useRef)((_ref = selectedIndex !== null && selectedIndex !== void 0 ? selectedIndex : activeIndex) !== null && _ref !== void 0 ? _ref : -1);
|
|
37
|
+
var matchIndexRef = (0, import_react.useRef)(null);
|
|
38
|
+
var onMatch = (0, import_use_event.useEvent)(unstable_onMatch || function() {});
|
|
39
|
+
var onTypingChange = (0, import_use_event.useEvent)(unstable_onTypingChange || function() {});
|
|
40
|
+
var findMatchRef = (0, import_react.useRef)(findMatch);
|
|
41
|
+
findMatchRef.current = findMatch;
|
|
42
|
+
var ignoreKeysRef = (0, import_react.useRef)(ignoreKeys);
|
|
43
|
+
ignoreKeysRef.current = ignoreKeys;
|
|
44
|
+
(0, import_react.useLayoutEffect)(function() {
|
|
45
|
+
if (open) {
|
|
46
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutIdRef);
|
|
47
|
+
matchIndexRef.current = null;
|
|
48
|
+
stringRef.current = "";
|
|
49
|
+
}
|
|
50
|
+
}, [open]);
|
|
51
|
+
(0, import_react.useLayoutEffect)(function() {
|
|
52
|
+
if (open && stringRef.current === "") {
|
|
53
|
+
var _ref2;
|
|
54
|
+
prevIndexRef.current = (_ref2 = selectedIndex !== null && selectedIndex !== void 0 ? selectedIndex : activeIndex) !== null && _ref2 !== void 0 ? _ref2 : -1;
|
|
55
|
+
}
|
|
56
|
+
}, [
|
|
57
|
+
open,
|
|
58
|
+
selectedIndex,
|
|
59
|
+
activeIndex
|
|
60
|
+
]);
|
|
61
|
+
var setTypingChange = function(value) {
|
|
62
|
+
if (value) {
|
|
63
|
+
if (!dataRef.current.typing) {
|
|
64
|
+
dataRef.current.typing = value;
|
|
65
|
+
onTypingChange(value);
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
if (dataRef.current.typing) {
|
|
69
|
+
dataRef.current.typing = value;
|
|
70
|
+
onTypingChange(value);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var onKeyDown = function(event) {
|
|
75
|
+
function getMatchingIndex(list, orderedList, string) {
|
|
76
|
+
var str = findMatchRef.current ? findMatchRef.current(orderedList, string) : orderedList.find(function(text) {
|
|
77
|
+
return (text === null || text === void 0 ? void 0 : text.toLocaleLowerCase().indexOf(string.toLocaleLowerCase())) === 0;
|
|
78
|
+
});
|
|
79
|
+
return str ? list.indexOf(str) : -1;
|
|
80
|
+
}
|
|
81
|
+
var listContent = listRef.current;
|
|
82
|
+
if (stringRef.current.length > 0 && stringRef.current[0] !== " ") {
|
|
83
|
+
if (getMatchingIndex(listContent, listContent, stringRef.current) === -1) {
|
|
84
|
+
setTypingChange(false);
|
|
85
|
+
} else if (event.key === " ") {
|
|
86
|
+
(0, import_utils.stopEvent)(event);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (listContent == null || ignoreKeysRef.current.includes(event.key) || event.key.length !== 1 || event.ctrlKey || event.metaKey || event.altKey) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (open && event.key !== " ") {
|
|
93
|
+
(0, import_utils.stopEvent)(event);
|
|
94
|
+
setTypingChange(true);
|
|
95
|
+
}
|
|
96
|
+
var allowRapidSuccessionOfFirstLetter = listContent.every(function(text) {
|
|
97
|
+
var _text_, _text_1;
|
|
98
|
+
return text ? ((_text_ = text[0]) === null || _text_ === void 0 ? void 0 : _text_.toLocaleLowerCase()) !== ((_text_1 = text[1]) === null || _text_1 === void 0 ? void 0 : _text_1.toLocaleLowerCase()) : true;
|
|
99
|
+
});
|
|
100
|
+
if (allowRapidSuccessionOfFirstLetter && stringRef.current === event.key) {
|
|
101
|
+
stringRef.current = "";
|
|
102
|
+
prevIndexRef.current = matchIndexRef.current;
|
|
103
|
+
}
|
|
104
|
+
stringRef.current += event.key;
|
|
105
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutIdRef);
|
|
106
|
+
timeoutIdRef.current = window.setTimeout(function() {
|
|
107
|
+
stringRef.current = "";
|
|
108
|
+
prevIndexRef.current = matchIndexRef.current;
|
|
109
|
+
setTypingChange(false);
|
|
110
|
+
}, resetMs);
|
|
111
|
+
var prevIndex = prevIndexRef.current;
|
|
112
|
+
var index = getMatchingIndex(listContent, [...listContent.slice((prevIndex || 0) + 1), ...listContent.slice(0, (prevIndex || 0) + 1)], stringRef.current);
|
|
113
|
+
if (index !== -1) {
|
|
114
|
+
onMatch(index);
|
|
115
|
+
matchIndexRef.current = index;
|
|
116
|
+
} else if (event.key !== " ") {
|
|
117
|
+
stringRef.current = "";
|
|
118
|
+
setTypingChange(false);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
var reference = (0, import_react.useMemo)(function() {
|
|
122
|
+
return { onKeyDown };
|
|
123
|
+
}, [open, enabled]);
|
|
124
|
+
var floating = (0, import_react.useMemo)(function() {
|
|
125
|
+
return {
|
|
126
|
+
onKeyDown,
|
|
127
|
+
onKeyUp(event) {
|
|
128
|
+
if (event.key === " ") {
|
|
129
|
+
setTypingChange(false);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}, [open, enabled]);
|
|
134
|
+
return (0, import_react.useMemo)(function() {
|
|
135
|
+
return enabled ? {
|
|
136
|
+
reference,
|
|
137
|
+
floating
|
|
138
|
+
} : {};
|
|
139
|
+
}, [
|
|
140
|
+
enabled,
|
|
141
|
+
reference,
|
|
142
|
+
floating
|
|
143
|
+
]);
|
|
144
|
+
}
|
|
@@ -1,159 +1,146 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
8
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
12
13
|
};
|
|
13
14
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
21
22
|
};
|
|
22
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
-
value: true
|
|
24
|
-
}), mod);
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
24
|
var useTypeahead_exports = {};
|
|
26
|
-
__export(useTypeahead_exports, {
|
|
27
|
-
useTypeahead: () => useTypeahead
|
|
28
|
-
});
|
|
25
|
+
__export(useTypeahead_exports, { useTypeahead: () => useTypeahead });
|
|
29
26
|
module.exports = __toCommonJS(useTypeahead_exports);
|
|
30
27
|
var import_react = require("react");
|
|
31
28
|
var import_use_event = require("@tamagui/use-event");
|
|
32
29
|
var import_utils = require("./utils.native.js");
|
|
33
30
|
function useTypeahead(context, props) {
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
setTypingChange(false);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
}, [open, enabled]);
|
|
152
|
-
return (0, import_react.useMemo)(function () {
|
|
153
|
-
return enabled ? {
|
|
154
|
-
reference,
|
|
155
|
-
floating
|
|
156
|
-
} : {};
|
|
157
|
-
}, [enabled, reference, floating]);
|
|
31
|
+
var { open, dataRef } = context;
|
|
32
|
+
var { listRef, activeIndex, onMatch: unstable_onMatch, onTypingChange: unstable_onTypingChange, enabled = true, findMatch = null, resetMs = 750, ignoreKeys = [], selectedIndex = null } = props;
|
|
33
|
+
var timeoutIdRef = (0, import_react.useRef)(-1);
|
|
34
|
+
var stringRef = (0, import_react.useRef)("");
|
|
35
|
+
var _ref;
|
|
36
|
+
var prevIndexRef = (0, import_react.useRef)((_ref = selectedIndex !== null && selectedIndex !== void 0 ? selectedIndex : activeIndex) !== null && _ref !== void 0 ? _ref : -1);
|
|
37
|
+
var matchIndexRef = (0, import_react.useRef)(null);
|
|
38
|
+
var onMatch = (0, import_use_event.useEvent)(unstable_onMatch || function() {});
|
|
39
|
+
var onTypingChange = (0, import_use_event.useEvent)(unstable_onTypingChange || function() {});
|
|
40
|
+
var findMatchRef = (0, import_react.useRef)(findMatch);
|
|
41
|
+
findMatchRef.current = findMatch;
|
|
42
|
+
var ignoreKeysRef = (0, import_react.useRef)(ignoreKeys);
|
|
43
|
+
ignoreKeysRef.current = ignoreKeys;
|
|
44
|
+
(0, import_react.useLayoutEffect)(function() {
|
|
45
|
+
if (open) {
|
|
46
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutIdRef);
|
|
47
|
+
matchIndexRef.current = null;
|
|
48
|
+
stringRef.current = "";
|
|
49
|
+
}
|
|
50
|
+
}, [open]);
|
|
51
|
+
(0, import_react.useLayoutEffect)(function() {
|
|
52
|
+
if (open && stringRef.current === "") {
|
|
53
|
+
var _ref2;
|
|
54
|
+
prevIndexRef.current = (_ref2 = selectedIndex !== null && selectedIndex !== void 0 ? selectedIndex : activeIndex) !== null && _ref2 !== void 0 ? _ref2 : -1;
|
|
55
|
+
}
|
|
56
|
+
}, [
|
|
57
|
+
open,
|
|
58
|
+
selectedIndex,
|
|
59
|
+
activeIndex
|
|
60
|
+
]);
|
|
61
|
+
var setTypingChange = function(value) {
|
|
62
|
+
if (value) {
|
|
63
|
+
if (!dataRef.current.typing) {
|
|
64
|
+
dataRef.current.typing = value;
|
|
65
|
+
onTypingChange(value);
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
if (dataRef.current.typing) {
|
|
69
|
+
dataRef.current.typing = value;
|
|
70
|
+
onTypingChange(value);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
var onKeyDown = function(event) {
|
|
75
|
+
function getMatchingIndex(list, orderedList, string) {
|
|
76
|
+
var str = findMatchRef.current ? findMatchRef.current(orderedList, string) : orderedList.find(function(text) {
|
|
77
|
+
return (text === null || text === void 0 ? void 0 : text.toLocaleLowerCase().indexOf(string.toLocaleLowerCase())) === 0;
|
|
78
|
+
});
|
|
79
|
+
return str ? list.indexOf(str) : -1;
|
|
80
|
+
}
|
|
81
|
+
var listContent = listRef.current;
|
|
82
|
+
if (stringRef.current.length > 0 && stringRef.current[0] !== " ") {
|
|
83
|
+
if (getMatchingIndex(listContent, listContent, stringRef.current) === -1) {
|
|
84
|
+
setTypingChange(false);
|
|
85
|
+
} else if (event.key === " ") {
|
|
86
|
+
(0, import_utils.stopEvent)(event);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (listContent == null || ignoreKeysRef.current.includes(event.key) || event.key.length !== 1 || event.ctrlKey || event.metaKey || event.altKey) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (open && event.key !== " ") {
|
|
93
|
+
(0, import_utils.stopEvent)(event);
|
|
94
|
+
setTypingChange(true);
|
|
95
|
+
}
|
|
96
|
+
var allowRapidSuccessionOfFirstLetter = listContent.every(function(text) {
|
|
97
|
+
var _text_, _text_1;
|
|
98
|
+
return text ? ((_text_ = text[0]) === null || _text_ === void 0 ? void 0 : _text_.toLocaleLowerCase()) !== ((_text_1 = text[1]) === null || _text_1 === void 0 ? void 0 : _text_1.toLocaleLowerCase()) : true;
|
|
99
|
+
});
|
|
100
|
+
if (allowRapidSuccessionOfFirstLetter && stringRef.current === event.key) {
|
|
101
|
+
stringRef.current = "";
|
|
102
|
+
prevIndexRef.current = matchIndexRef.current;
|
|
103
|
+
}
|
|
104
|
+
stringRef.current += event.key;
|
|
105
|
+
(0, import_utils.clearTimeoutIfSet)(timeoutIdRef);
|
|
106
|
+
timeoutIdRef.current = window.setTimeout(function() {
|
|
107
|
+
stringRef.current = "";
|
|
108
|
+
prevIndexRef.current = matchIndexRef.current;
|
|
109
|
+
setTypingChange(false);
|
|
110
|
+
}, resetMs);
|
|
111
|
+
var prevIndex = prevIndexRef.current;
|
|
112
|
+
var index = getMatchingIndex(listContent, [...listContent.slice((prevIndex || 0) + 1), ...listContent.slice(0, (prevIndex || 0) + 1)], stringRef.current);
|
|
113
|
+
if (index !== -1) {
|
|
114
|
+
onMatch(index);
|
|
115
|
+
matchIndexRef.current = index;
|
|
116
|
+
} else if (event.key !== " ") {
|
|
117
|
+
stringRef.current = "";
|
|
118
|
+
setTypingChange(false);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
var reference = (0, import_react.useMemo)(function() {
|
|
122
|
+
return { onKeyDown };
|
|
123
|
+
}, [open, enabled]);
|
|
124
|
+
var floating = (0, import_react.useMemo)(function() {
|
|
125
|
+
return {
|
|
126
|
+
onKeyDown,
|
|
127
|
+
onKeyUp(event) {
|
|
128
|
+
if (event.key === " ") {
|
|
129
|
+
setTypingChange(false);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}, [open, enabled]);
|
|
134
|
+
return (0, import_react.useMemo)(function() {
|
|
135
|
+
return enabled ? {
|
|
136
|
+
reference,
|
|
137
|
+
floating
|
|
138
|
+
} : {};
|
|
139
|
+
}, [
|
|
140
|
+
enabled,
|
|
141
|
+
reference,
|
|
142
|
+
floating
|
|
143
|
+
]);
|
|
158
144
|
}
|
|
145
|
+
|
|
159
146
|
//# sourceMappingURL=useTypeahead.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"useTypeahead.native.js","names":[],"sources":["cjs/interactions/useTypeahead.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\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 __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useTypeahead_exports = {};\n__export(useTypeahead_exports, {\n useTypeahead: () => useTypeahead\n});\nmodule.exports = __toCommonJS(useTypeahead_exports);\nvar import_react = require(\"react\");\nvar import_use_event = require(\"@tamagui/use-event\");\nvar import_utils = require(\"./utils\");\nfunction useTypeahead(context, props) {\n var { open, dataRef } = context;\n var { listRef, activeIndex, onMatch: unstable_onMatch, onTypingChange: unstable_onTypingChange, enabled = true, findMatch = null, resetMs = 750, ignoreKeys = [], selectedIndex = null } = props;\n var timeoutIdRef = (0, import_react.useRef)(-1);\n var stringRef = (0, import_react.useRef)(\"\");\n var _ref;\n var prevIndexRef = (0, import_react.useRef)((_ref = selectedIndex !== null && selectedIndex !== void 0 ? selectedIndex : activeIndex) !== null && _ref !== void 0 ? _ref : -1);\n var matchIndexRef = (0, import_react.useRef)(null);\n var onMatch = (0, import_use_event.useEvent)(unstable_onMatch || function() {\n });\n var onTypingChange = (0, import_use_event.useEvent)(unstable_onTypingChange || function() {\n });\n var findMatchRef = (0, import_react.useRef)(findMatch);\n findMatchRef.current = findMatch;\n var ignoreKeysRef = (0, import_react.useRef)(ignoreKeys);\n ignoreKeysRef.current = ignoreKeys;\n (0, import_react.useLayoutEffect)(function() {\n if (open) {\n (0, import_utils.clearTimeoutIfSet)(timeoutIdRef);\n matchIndexRef.current = null;\n stringRef.current = \"\";\n }\n }, [\n open\n ]);\n (0, import_react.useLayoutEffect)(function() {\n if (open && stringRef.current === \"\") {\n var _ref2;\n prevIndexRef.current = (_ref2 = selectedIndex !== null && selectedIndex !== void 0 ? selectedIndex : activeIndex) !== null && _ref2 !== void 0 ? _ref2 : -1;\n }\n }, [\n open,\n selectedIndex,\n activeIndex\n ]);\n var setTypingChange = function(value) {\n if (value) {\n if (!dataRef.current.typing) {\n dataRef.current.typing = value;\n onTypingChange(value);\n }\n } else {\n if (dataRef.current.typing) {\n dataRef.current.typing = value;\n onTypingChange(value);\n }\n }\n };\n var onKeyDown = function(event) {\n function getMatchingIndex(list, orderedList, string) {\n var str = findMatchRef.current ? findMatchRef.current(orderedList, string) : orderedList.find(function(text) {\n return (text === null || text === void 0 ? void 0 : text.toLocaleLowerCase().indexOf(string.toLocaleLowerCase())) === 0;\n });\n return str ? list.indexOf(str) : -1;\n }\n var listContent = listRef.current;\n if (stringRef.current.length > 0 && stringRef.current[0] !== \" \") {\n if (getMatchingIndex(listContent, listContent, stringRef.current) === -1) {\n setTypingChange(false);\n } else if (event.key === \" \") {\n (0, import_utils.stopEvent)(event);\n }\n }\n if (listContent == null || ignoreKeysRef.current.includes(event.key) || // character key\n event.key.length !== 1 || // modifier key\n event.ctrlKey || event.metaKey || event.altKey) {\n return;\n }\n if (open && event.key !== \" \") {\n (0, import_utils.stopEvent)(event);\n setTypingChange(true);\n }\n var allowRapidSuccessionOfFirstLetter = listContent.every(function(text) {\n var _text_, _text_1;\n return text ? ((_text_ = text[0]) === null || _text_ === void 0 ? void 0 : _text_.toLocaleLowerCase()) !== ((_text_1 = text[1]) === null || _text_1 === void 0 ? void 0 : _text_1.toLocaleLowerCase()) : true;\n });\n if (allowRapidSuccessionOfFirstLetter && stringRef.current === event.key) {\n stringRef.current = \"\";\n prevIndexRef.current = matchIndexRef.current;\n }\n stringRef.current += event.key;\n (0, import_utils.clearTimeoutIfSet)(timeoutIdRef);\n timeoutIdRef.current = window.setTimeout(function() {\n stringRef.current = \"\";\n prevIndexRef.current = matchIndexRef.current;\n setTypingChange(false);\n }, resetMs);\n var prevIndex = prevIndexRef.current;\n var index = getMatchingIndex(listContent, [\n ...listContent.slice((prevIndex || 0) + 1),\n ...listContent.slice(0, (prevIndex || 0) + 1)\n ], stringRef.current);\n if (index !== -1) {\n onMatch(index);\n matchIndexRef.current = index;\n } else if (event.key !== \" \") {\n stringRef.current = \"\";\n setTypingChange(false);\n }\n };\n var reference = (0, import_react.useMemo)(function() {\n return {\n onKeyDown\n };\n }, [\n open,\n enabled\n ]);\n var floating = (0, import_react.useMemo)(function() {\n return {\n onKeyDown,\n onKeyUp(event) {\n if (event.key === \" \") {\n setTypingChange(false);\n }\n }\n };\n }, [\n open,\n enabled\n ]);\n return (0, import_react.useMemo)(function() {\n return enabled ? {\n reference,\n floating\n } : {};\n }, [\n enabled,\n reference,\n floating\n ]);\n}\n//# sourceMappingURL=useTypeahead.js.map\n"],"mappings":";;;;AACA,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,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,I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