@comp0/core 0.1.0-next.18 → 0.1.0-next.2
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/typeahead.js +15 -39
- package/package.json +1 -1
package/dist/typeahead.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { useRef } from "react";
|
|
3
3
|
/** Finds the next enabled item whose text begins with the search string. */
|
|
4
4
|
export function findTypeaheadMatch(items, search, currentKey) {
|
|
5
5
|
const enabled = items.filter((item) => !item.disabled);
|
|
@@ -15,25 +15,13 @@ export function findTypeaheadMatch(items, search, currentKey) {
|
|
|
15
15
|
* "Copy" instead of jumping between "c" and "o" items.
|
|
16
16
|
*/
|
|
17
17
|
export function useTypeaheadSearch(t0) {
|
|
18
|
-
const $ = _c(
|
|
18
|
+
const $ = _c(2);
|
|
19
19
|
const timeout = t0 === undefined ? 700 : t0;
|
|
20
20
|
const bufferRef = useRef("");
|
|
21
21
|
const timeoutRef = useRef(undefined);
|
|
22
22
|
let t1;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
t1 = () => () => window.clearTimeout(timeoutRef.current);
|
|
26
|
-
t2 = [];
|
|
27
|
-
$[0] = t1;
|
|
28
|
-
$[1] = t2;
|
|
29
|
-
} else {
|
|
30
|
-
t1 = $[0];
|
|
31
|
-
t2 = $[1];
|
|
32
|
-
}
|
|
33
|
-
useEffect(t1, t2);
|
|
34
|
-
let t3;
|
|
35
|
-
if ($[2] !== timeout) {
|
|
36
|
-
t3 = (key) => {
|
|
23
|
+
if ($[0] !== timeout) {
|
|
24
|
+
t1 = (key) => {
|
|
37
25
|
window.clearTimeout(timeoutRef.current);
|
|
38
26
|
timeoutRef.current = window.setTimeout(() => {
|
|
39
27
|
bufferRef.current = "";
|
|
@@ -41,33 +29,21 @@ export function useTypeaheadSearch(t0) {
|
|
|
41
29
|
bufferRef.current = bufferRef.current + key;
|
|
42
30
|
return bufferRef.current;
|
|
43
31
|
};
|
|
44
|
-
$[
|
|
45
|
-
$[
|
|
32
|
+
$[0] = timeout;
|
|
33
|
+
$[1] = t1;
|
|
46
34
|
} else {
|
|
47
|
-
|
|
35
|
+
t1 = $[1];
|
|
48
36
|
}
|
|
49
|
-
return
|
|
37
|
+
return t1;
|
|
50
38
|
}
|
|
51
39
|
/** Returns a keyboard handler that buffers printable characters for typeahead navigation. */
|
|
52
40
|
export function useTypeahead(options) {
|
|
53
|
-
const $ = _c(
|
|
41
|
+
const $ = _c(2);
|
|
54
42
|
const bufferRef = useRef("");
|
|
55
43
|
const timeoutRef = useRef(undefined);
|
|
56
44
|
let t0;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
t0 = () => () => window.clearTimeout(timeoutRef.current);
|
|
60
|
-
t1 = [];
|
|
61
|
-
$[0] = t0;
|
|
62
|
-
$[1] = t1;
|
|
63
|
-
} else {
|
|
64
|
-
t0 = $[0];
|
|
65
|
-
t1 = $[1];
|
|
66
|
-
}
|
|
67
|
-
useEffect(t0, t1);
|
|
68
|
-
let t2;
|
|
69
|
-
if ($[2] !== options) {
|
|
70
|
-
t2 = (event) => {
|
|
45
|
+
if ($[0] !== options) {
|
|
46
|
+
t0 = (event) => {
|
|
71
47
|
if (event.key.length !== 1 || event.key.trim() === "") {
|
|
72
48
|
return;
|
|
73
49
|
}
|
|
@@ -82,10 +58,10 @@ export function useTypeahead(options) {
|
|
|
82
58
|
options.onMatch(match);
|
|
83
59
|
}
|
|
84
60
|
};
|
|
85
|
-
$[
|
|
86
|
-
$[
|
|
61
|
+
$[0] = options;
|
|
62
|
+
$[1] = t0;
|
|
87
63
|
} else {
|
|
88
|
-
|
|
64
|
+
t0 = $[1];
|
|
89
65
|
}
|
|
90
|
-
return
|
|
66
|
+
return t0;
|
|
91
67
|
}
|