@snack-uikit/list 0.4.2-preview-4dc69f78.0 → 0.4.2-preview-3bc93fc3.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/README.md +8 -44
- package/dist/hooks.d.ts +3 -0
- package/dist/hooks.js +3 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.js +8 -0
- package/package.json +3 -3
- package/src/hooks.ts +3 -0
- package/src/utils.ts +10 -0
package/README.md
CHANGED
|
@@ -8,56 +8,20 @@
|
|
|
8
8
|
|
|
9
9
|
[//]: DOCUMENTATION_SECTION_START
|
|
10
10
|
[//]: THIS_SECTION_IS_AUTOGENERATED_PLEASE_DONT_EDIT_IT
|
|
11
|
-
##
|
|
11
|
+
## useFuzzySearch
|
|
12
|
+
Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
|
|
12
13
|
### Props
|
|
13
14
|
| name | type | default value | description |
|
|
14
15
|
|------|------|---------------|-------------|
|
|
15
|
-
|
|
16
|
-
## flattenItems
|
|
16
|
+
## extractChildIds
|
|
17
17
|
### Props
|
|
18
18
|
| name | type | default value | description |
|
|
19
19
|
|------|------|---------------|-------------|
|
|
20
|
-
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
| toReversed* | `() => ItemProps[]` | - | Returns a copy of an array with its elements reversed. |
|
|
26
|
-
| findLastIndex* | `(predicate: (value: ItemProps, index: number, array: ItemProps[]) => unknown, thisArg?: any) => number` | - | Returns the index of the last element in the array where predicate is true, and -1 otherwise. @param predicate findLastIndex calls predicate once for each element of the array, in descending order, until it finds one where predicate returns true. If such an element is found, findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1. @param thisArg If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead. |
|
|
27
|
-
| findLast* | `{ <S extends ItemProps>(predicate: (value: ItemProps, index: number, array: ItemProps[]) => value is S, thisArg?: any): S; (predicate: (value: ItemProps, index: number, array: ItemProps[]) => unknown, thisArg?: any): ItemProps; }` | - | Returns the value of the last element in the array where predicate is true, and undefined otherwise. @param predicate findLast calls predicate once for each element of the array, in descending order, until it finds one where predicate returns true. If such an element is found, findLast immediately returns that element value. Otherwise, findLast returns undefined. @param thisArg If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead. |
|
|
28
|
-
| at* | `(index: number) => ItemProps` | - | Returns the item located at the specified index. @param index The zero-based index of the desired code unit. A negative index will count back from the last item. |
|
|
29
|
-
| flat* | `<A, D extends number = 1>(this: A, depth?: D) => FlatArray<A, D>[]` | - | Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth. @param depth The maximum recursion depth |
|
|
30
|
-
| flatMap* | `<U, This = undefined>(callback: (this: This, value: ItemProps, index: number, array: ItemProps[]) => U \| readonly U[], thisArg?: This) => U[]` | - | Calls a defined callback function on each element of an array. Then, flattens the result into a new array. This is identical to a map followed by flat with depth 1. @param callback A function that accepts up to three arguments. The flatMap method calls the callback function one time for each element in the array. @param thisArg An object to which the this keyword can refer in the callback function. If thisArg is omitted, undefined is used as the this value. |
|
|
31
|
-
| includes* | `(searchElement: ItemProps, fromIndex?: number) => boolean` | - | Determines whether an array includes a certain element, returning true or false as appropriate. @param searchElement The element to search for. @param fromIndex The position in this array at which to begin searching for searchElement. |
|
|
32
|
-
| values* | `() => IterableIterator<ItemProps>` | - | Returns an iterable of values in the array |
|
|
33
|
-
| keys* | `() => IterableIterator<number>` | - | Returns an iterable of keys in the array |
|
|
34
|
-
| entries* | `() => IterableIterator<[number, ItemProps]>` | - | Returns an iterable of key, value pairs for every entry in the array |
|
|
35
|
-
| copyWithin* | `(target: number, start: number, end?: number) => ItemProps[]` | - | Returns the this object after copying a section of the array identified by start and end to the same array starting at position target @param target If target is negative, it is treated as length+target where length is the length of the array. @param start If start is negative, it is treated as length+start. If end is negative, it is treated as length+end. @param end If not specified, length of the this object is used as its default value. |
|
|
36
|
-
| fill* | `(value: ItemProps, start?: number, end?: number) => ItemProps[]` | - | Changes all array elements from `start` to `end` index to a static `value` and returns the modified array @param value value to fill array section with @param start index to start filling the array at. If start is negative, it is treated as length+start where length is the length of the array. @param end index to stop filling the array at. If end is negative, it is treated as length+end. |
|
|
37
|
-
| findIndex* | `(predicate: (value: ItemProps, index: number, obj: ItemProps[]) => unknown, thisArg?: any) => number` | - | Returns the index of the first element in the array where predicate is true, and -1 otherwise. @param predicate find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1. @param thisArg If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead. |
|
|
38
|
-
| find* | `{ <S extends ItemProps>(predicate: (value: ItemProps, index: number, obj: ItemProps[]) => value is S, thisArg?: any): S; (predicate: (value: ItemProps, index: number, obj: ItemProps[]) => unknown, thisArg?: any): ItemProps; }` | - | Returns the value of the first element in the array where predicate is true, and undefined otherwise. @param predicate find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns undefined. @param thisArg If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead. |
|
|
39
|
-
| reduceRight* | `{ (callbackfn: (previousValue: ItemProps, currentValue: ItemProps, currentIndex: number, array: ItemProps[]) => ItemProps): ItemProps; (callbackfn: (previousValue: ItemProps, currentValue: ItemProps, currentIndex: number, array: ItemProps[]) => ItemProps, initialValue: ItemProps): ItemProps; <U>(callbackfn: (previou...` | - | Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. @param callbackfn A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array. @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. |
|
|
40
|
-
| reduce* | `{ (callbackfn: (previousValue: ItemProps, currentValue: ItemProps, currentIndex: number, array: ItemProps[]) => ItemProps): ItemProps; (callbackfn: (previousValue: ItemProps, currentValue: ItemProps, currentIndex: number, array: ItemProps[]) => ItemProps, initialValue: ItemProps): ItemProps; <U>(callbackfn: (previou...` | - | Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function. @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. @param callbackfn A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array. @param initialValue If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value. |
|
|
41
|
-
| filter* | `{ <S extends ItemProps>(predicate: (value: ItemProps, index: number, array: ItemProps[]) => value is S, thisArg?: any): S[]; (predicate: (value: ItemProps, index: number, array: ItemProps[]) => unknown, thisArg?: any): ItemProps[]; }` | - | Returns the elements of an array that meet the condition specified in a callback function. @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array. @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value. @param predicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array. @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value. |
|
|
42
|
-
| map* | `<U>(callbackfn: (value: ItemProps, index: number, array: ItemProps[]) => U, thisArg?: any) => U[]` | - | Calls a defined callback function on each element of an array, and returns an array that contains the results. @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. |
|
|
43
|
-
| forEach* | `(callbackfn: (value: ItemProps, index: number, array: ItemProps[]) => void, thisArg?: any) => void` | - | Performs the specified action for each element in an array. @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array. @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. |
|
|
44
|
-
| some* | `(predicate: (value: ItemProps, index: number, array: ItemProps[]) => unknown, thisArg?: any) => boolean` | - | Determines whether the specified callback function returns true for any element of an array. @param predicate A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array. @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value. |
|
|
45
|
-
| every* | `{ <S extends ItemProps>(predicate: (value: ItemProps, index: number, array: ItemProps[]) => value is S, thisArg?: any): this is S[]; (predicate: (value: ItemProps, index: number, array: ItemProps[]) => unknown, thisArg?: any): boolean; }` | - | Determines whether all the members of an array satisfy the specified test. @param predicate A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array. @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value. @param predicate A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array. @param thisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value. |
|
|
46
|
-
| lastIndexOf* | `(searchElement: ItemProps, fromIndex?: number) => number` | - | Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present. @param searchElement The value to locate in the array. @param fromIndex The array index at which to begin searching backward. If fromIndex is omitted, the search starts at the last index in the array. |
|
|
47
|
-
| indexOf* | `(searchElement: ItemProps, fromIndex?: number) => number` | - | Returns the index of the first occurrence of a value in an array, or -1 if it is not present. @param searchElement The value to locate in the array. @param fromIndex The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0. |
|
|
48
|
-
| unshift* | `(...items: ItemProps[]) => number` | - | Inserts new elements at the start of an array, and returns the new length of the array. @param items Elements to insert at the start of the array. |
|
|
49
|
-
| splice* | `{ (start: number, deleteCount?: number): ItemProps[]; (start: number, deleteCount: number, ...items: ItemProps[]): ItemProps[]; }` | - | Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. @param start The zero-based location in the array from which to start removing elements. @param deleteCount The number of elements to remove. @returns An array containing the elements that were deleted. @param start The zero-based location in the array from which to start removing elements. @param deleteCount The number of elements to remove. @param items Elements to insert into the array in place of the deleted elements. @returns An array containing the elements that were deleted. |
|
|
50
|
-
| sort* | `(compareFn?: (a: ItemProps, b: ItemProps) => number) => ItemProps[]` | - | Sorts an array in place. This method mutates the array and returns a reference to the same array. @param compareFn Function used to determine the order of the elements. It is expected to return a negative value if the first argument is less than the second argument, zero if they're equal, and a positive value otherwise. If omitted, the elements are sorted in ascending, ASCII character order. ```ts [11,2,22,1].sort((a, b) => a - b) ``` |
|
|
51
|
-
| slice* | `(start?: number, end?: number) => ItemProps[]` | - | Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. For example, -2 refers to the second to last element of the array. @param start The beginning index of the specified portion of the array. If start is undefined, then the slice begins at index 0. @param end The end index of the specified portion of the array. This is exclusive of the element at the index 'end'. If end is undefined, then the slice extends to the end of the array. |
|
|
52
|
-
| shift* | `() => ItemProps` | - | Removes the first element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. |
|
|
53
|
-
| reverse* | `() => ItemProps[]` | - | Reverses the elements in an array in place. This method mutates the array and returns a reference to the same array. |
|
|
54
|
-
| join* | `(separator?: string) => string` | - | Adds all the elements of an array into a string, separated by the specified separator string. @param separator A string used to separate one element of the array from the next in the resulting string. If omitted, the array elements are separated with a comma. |
|
|
55
|
-
| concat* | `{ (...items: ConcatArray<ItemProps>[]): ItemProps[]; (...items: (ItemProps \| ConcatArray<ItemProps>)[]): ItemProps[]; }` | - | Combines two or more arrays. This method returns a new array without modifying any existing arrays. @param items Additional arrays and/or items to add to the end of the array. @param items Additional arrays and/or items to add to the end of the array. |
|
|
56
|
-
| push* | `(...items: ItemProps[]) => number` | - | Appends new elements to the end of an array, and returns the new length of the array. @param items New elements to add to the array. |
|
|
57
|
-
| pop* | `() => ItemProps` | - | Removes the last element from an array and returns it. If the array is empty, undefined is returned and the array is not modified. |
|
|
58
|
-
| length* | `number` | - | Gets or sets the length of the array. This is a number one higher than the highest index in the array. |
|
|
59
|
-
| toString | `() => string` | function toString() { [native code] } | Returns a string representation of an array. |
|
|
60
|
-
| toLocaleString | `() => string` | function toLocaleString() { [native code] } | Returns a string representation of an array. The elements are converted to string using their toLocaleString methods. |
|
|
20
|
+
| items* | `ItemProps[]` | - | |
|
|
21
|
+
## flattenItems
|
|
22
|
+
`flattenItems`
|
|
23
|
+
|
|
24
|
+
Функция разворачивает массив айтемов в плоский список
|
|
61
25
|
## isAccordionItemProps
|
|
62
26
|
### Props
|
|
63
27
|
| name | type | default value | description |
|
package/dist/hooks.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { ItemProps } from './components/Items';
|
|
2
|
+
/**
|
|
3
|
+
* Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
|
|
4
|
+
*/
|
|
2
5
|
export declare function useFuzzySearch(items: ItemProps[], minSearchInputLength?: number): (search: string) => ItemProps[];
|
package/dist/hooks.js
CHANGED
|
@@ -2,6 +2,9 @@ import FuzzySearch from 'fuzzy-search';
|
|
|
2
2
|
import { useCallback } from 'react';
|
|
3
3
|
import { flattenItems } from './utils';
|
|
4
4
|
const DEFAULT_MIN_SEARCH_INPUT_LENGTH = 2;
|
|
5
|
+
/**
|
|
6
|
+
* Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
|
|
7
|
+
*/
|
|
5
8
|
export function useFuzzySearch(items, minSearchInputLength) {
|
|
6
9
|
return useCallback((search) => {
|
|
7
10
|
const searcher = new FuzzySearch(flattenItems(items), ['content.option', 'content.caption', 'content.description', 'label'], {});
|
package/dist/utils.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ export declare function withCollapsedItems({ items, openCollapsedItems }: WithCo
|
|
|
11
11
|
expandedIds: (string | number)[];
|
|
12
12
|
};
|
|
13
13
|
export declare function extractItemRefs(items: ItemProps[]): RefObject<HTMLElement>[];
|
|
14
|
+
/**
|
|
15
|
+
* Функция возвращает массив id дочерних items
|
|
16
|
+
* @function extractItemIds
|
|
17
|
+
*/
|
|
14
18
|
export declare function extractItemIds(items: ItemProps[]): Array<string | number>;
|
|
15
19
|
export declare function extractChildIds({ items }: {
|
|
16
20
|
items: ItemProps[];
|
|
@@ -18,5 +22,9 @@ export declare function extractChildIds({ items }: {
|
|
|
18
22
|
export declare function extractAllChildIds({ items }: {
|
|
19
23
|
items: ItemProps[];
|
|
20
24
|
}): Array<string | number>;
|
|
25
|
+
/**
|
|
26
|
+
* Функция разворачивает массив айтемов в плоский список
|
|
27
|
+
* @function flattenItems
|
|
28
|
+
*/
|
|
21
29
|
export declare function flattenItems(items: ItemProps[]): (BaseItemProps | AccordionItemProps | NextListItemProps)[];
|
|
22
30
|
export {};
|
package/dist/utils.js
CHANGED
|
@@ -46,6 +46,10 @@ export function extractItemRefs(items) {
|
|
|
46
46
|
return item.itemRef ? prev.concat([item.itemRef]) : prev;
|
|
47
47
|
}, []);
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Функция возвращает массив id дочерних items
|
|
51
|
+
* @function extractItemIds
|
|
52
|
+
*/
|
|
49
53
|
export function extractItemIds(items) {
|
|
50
54
|
return items.reduce((prev, item) => {
|
|
51
55
|
if (isGroupItemProps(item)) {
|
|
@@ -88,6 +92,10 @@ export function extractAllChildIds({ items }) {
|
|
|
88
92
|
return item.id && !isGroupItemProps(item) ? prev.concat([item.id]) : prev;
|
|
89
93
|
}, []);
|
|
90
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Функция разворачивает массив айтемов в плоский список
|
|
97
|
+
* @function flattenItems
|
|
98
|
+
*/
|
|
91
99
|
export function flattenItems(items) {
|
|
92
100
|
const flattenedItems = [];
|
|
93
101
|
function flatten(item) {
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "List",
|
|
7
|
-
"version": "0.4.2-preview-
|
|
7
|
+
"version": "0.4.2-preview-3bc93fc3.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
33
|
"scripts": {},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@snack-uikit/divider": "3.0.
|
|
35
|
+
"@snack-uikit/divider": "3.0.2-preview-3bc93fc3.0",
|
|
36
36
|
"@snack-uikit/dropdown": "0.2.0",
|
|
37
37
|
"@snack-uikit/icons": "0.20.1",
|
|
38
38
|
"@snack-uikit/info-block": "0.3.0",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@snack-uikit/locale": "*"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "a2fa7717157c8a23fa1fc6b64c67c7b2d9dfc39c"
|
|
58
58
|
}
|
package/src/hooks.ts
CHANGED
|
@@ -6,6 +6,9 @@ import { flattenItems } from './utils';
|
|
|
6
6
|
|
|
7
7
|
const DEFAULT_MIN_SEARCH_INPUT_LENGTH = 2;
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
|
|
11
|
+
*/
|
|
9
12
|
export function useFuzzySearch(items: ItemProps[], minSearchInputLength?: number) {
|
|
10
13
|
return useCallback(
|
|
11
14
|
(search: string) => {
|
package/src/utils.ts
CHANGED
|
@@ -80,6 +80,11 @@ export function extractItemRefs(items: ItemProps[]): RefObject<HTMLElement>[] {
|
|
|
80
80
|
}, [] as RefObject<HTMLElement>[]);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/**
|
|
84
|
+
* Функция возвращает массив id дочерних items
|
|
85
|
+
* @function extractItemIds
|
|
86
|
+
*/
|
|
87
|
+
|
|
83
88
|
export function extractItemIds(items: ItemProps[]): Array<string | number> {
|
|
84
89
|
return items.reduce(
|
|
85
90
|
(prev: Array<string | number>, item: ItemProps) => {
|
|
@@ -142,6 +147,11 @@ export function extractAllChildIds({ items }: { items: ItemProps[] }): Array<str
|
|
|
142
147
|
);
|
|
143
148
|
}
|
|
144
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Функция разворачивает массив айтемов в плоский список
|
|
152
|
+
* @function flattenItems
|
|
153
|
+
*/
|
|
154
|
+
|
|
145
155
|
export function flattenItems(items: ItemProps[]): (BaseItemProps | AccordionItemProps | NextListItemProps)[] {
|
|
146
156
|
const flattenedItems: (BaseItemProps | AccordionItemProps | NextListItemProps)[] = [];
|
|
147
157
|
|