svelte-typeahead 4.1.0 → 4.2.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/CHANGELOG.md +26 -0
- package/README.md +47 -62
- package/lib/index.js +134 -98
- package/lib/index.mjs +130 -94
- package/package.json +5 -5
- package/src/Typeahead.svelte +32 -18
- package/types/Typeahead.svelte.d.ts +24 -20
|
@@ -2,16 +2,7 @@
|
|
|
2
2
|
import { SvelteComponentTyped } from "svelte";
|
|
3
3
|
import { SearchProps } from "svelte-search/types/Search";
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
export interface FuzzyResult {
|
|
8
|
-
original: Item;
|
|
9
|
-
index: number;
|
|
10
|
-
score: number;
|
|
11
|
-
string: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface TypeaheadProps extends SearchProps {
|
|
5
|
+
export interface TypeaheadProps<TItem> extends SearchProps {
|
|
15
6
|
/**
|
|
16
7
|
* @default "typeahead-" + Math.random().toString(36)
|
|
17
8
|
*/
|
|
@@ -25,22 +16,22 @@ export interface TypeaheadProps extends SearchProps {
|
|
|
25
16
|
/**
|
|
26
17
|
* @default []
|
|
27
18
|
*/
|
|
28
|
-
data?:
|
|
19
|
+
data?: TItem[];
|
|
29
20
|
|
|
30
21
|
/**
|
|
31
22
|
* @default (item) => item
|
|
32
23
|
*/
|
|
33
|
-
extract?: (item:
|
|
24
|
+
extract?: (item: TItem) => any;
|
|
34
25
|
|
|
35
26
|
/**
|
|
36
27
|
* @default (item) => false
|
|
37
28
|
*/
|
|
38
|
-
disable?: (item:
|
|
29
|
+
disable?: (item: TItem) => boolean;
|
|
39
30
|
|
|
40
31
|
/**
|
|
41
32
|
* @default (item) => false
|
|
42
33
|
*/
|
|
43
|
-
filter?: (item:
|
|
34
|
+
filter?: (item: TItem) => boolean;
|
|
44
35
|
|
|
45
36
|
/**
|
|
46
37
|
* Set to `false` to prevent the first result from being selected
|
|
@@ -57,7 +48,13 @@ export interface TypeaheadProps extends SearchProps {
|
|
|
57
48
|
/**
|
|
58
49
|
* @default []
|
|
59
50
|
*/
|
|
60
|
-
results?:
|
|
51
|
+
results?: {
|
|
52
|
+
original: TItem;
|
|
53
|
+
index: number;
|
|
54
|
+
score: number;
|
|
55
|
+
string: string;
|
|
56
|
+
disabled?: boolean;
|
|
57
|
+
}[];
|
|
61
58
|
|
|
62
59
|
/**
|
|
63
60
|
* Set to `true` to re-focus the input after selecting a result
|
|
@@ -72,14 +69,16 @@ export interface TypeaheadProps extends SearchProps {
|
|
|
72
69
|
limit?: number;
|
|
73
70
|
}
|
|
74
71
|
|
|
75
|
-
export default class Typeahead
|
|
76
|
-
|
|
72
|
+
export default class Typeahead<
|
|
73
|
+
TItem = string | number | Record<string, any>
|
|
74
|
+
> extends SvelteComponentTyped<
|
|
75
|
+
TypeaheadProps<TItem>,
|
|
77
76
|
{
|
|
78
77
|
select: CustomEvent<{
|
|
79
78
|
searched: string;
|
|
80
|
-
selected:
|
|
79
|
+
selected: TItem;
|
|
81
80
|
selectedIndex: number;
|
|
82
|
-
original:
|
|
81
|
+
original: TItem;
|
|
83
82
|
originalIndex: number;
|
|
84
83
|
}>;
|
|
85
84
|
type: CustomEvent<string>;
|
|
@@ -92,7 +91,12 @@ export default class Typeahead extends SvelteComponentTyped<
|
|
|
92
91
|
},
|
|
93
92
|
{
|
|
94
93
|
default: {
|
|
95
|
-
result:
|
|
94
|
+
result: {
|
|
95
|
+
original: TItem;
|
|
96
|
+
index: number;
|
|
97
|
+
score: number;
|
|
98
|
+
string: string;
|
|
99
|
+
};
|
|
96
100
|
index: number;
|
|
97
101
|
value: string;
|
|
98
102
|
};
|