@snack-uikit/list 0.5.0 → 0.6.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/CHANGELOG.md CHANGED
@@ -3,6 +3,31 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 0.6.1 (2024-02-28)
7
+
8
+ ### Only dependencies have been changed
9
+ * [@snack-uikit/info-block@0.3.1](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/info-block/CHANGELOG.md)
10
+
11
+
12
+
13
+
14
+
15
+ # 0.6.0 (2024-02-27)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * **FF-4324:** fix onChange selection value in controlled ([0be6178](https://github.com/cloud-ru-tech/snack-uikit/commit/0be6178e51dc24ff4c367a420d61065d00d695fd))
21
+
22
+
23
+ ### Features
24
+
25
+ * **FF-4324:** add some exports ([7a62446](https://github.com/cloud-ru-tech/snack-uikit/commit/7a6244690288d279bbd4746280029f8f5ecda0b0))
26
+
27
+
28
+
29
+
30
+
6
31
  # 0.5.0 (2024-02-27)
7
32
 
8
33
 
package/README.md CHANGED
@@ -8,11 +8,36 @@
8
8
 
9
9
  [//]: DOCUMENTATION_SECTION_START
10
10
  [//]: THIS_SECTION_IS_AUTOGENERATED_PLEASE_DONT_EDIT_IT
11
+ ## useFuzzySearch
12
+ Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
13
+ ### Props
14
+ | name | type | default value | description |
15
+ |------|------|---------------|-------------|
11
16
  ## extractChildIds
12
17
  ### Props
13
18
  | name | type | default value | description |
14
19
  |------|------|---------------|-------------|
15
20
  | items* | `ItemProps[]` | - | |
21
+ ## flattenItems
22
+ `flattenItems`
23
+
24
+ Функция разворачивает массив айтемов в плоский список
25
+ ## isAccordionItemProps
26
+ ### Props
27
+ | name | type | default value | description |
28
+ |------|------|---------------|-------------|
29
+ ## isBaseItemProps
30
+ ### Props
31
+ | name | type | default value | description |
32
+ |------|------|---------------|-------------|
33
+ ## isGroupItemProps
34
+ ### Props
35
+ | name | type | default value | description |
36
+ |------|------|---------------|-------------|
37
+ ## isNextListItemProps
38
+ ### Props
39
+ | name | type | default value | description |
40
+ |------|------|---------------|-------------|
16
41
  ## useGroupItemSelection
17
42
  ### Props
18
43
  | name | type | default value | description |
@@ -26,8 +26,9 @@ export function isSelectionSingleProps(props) {
26
26
  return 'mode' in props && props['mode'] === 'single';
27
27
  }
28
28
  function SelectionSingleProvider({ value: valueProp, defaultValue, onChange: onChangeProp, children, }) {
29
- const [value, setValue] = useUncontrolledProp(valueProp, defaultValue, cb => {
30
- onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp(cb(value));
29
+ const [value, setValue] = useUncontrolledProp(valueProp, defaultValue, newValue => {
30
+ const result = typeof newValue === 'function' ? newValue(value) : newValue;
31
+ onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp(result);
31
32
  });
32
33
  const onChange = useCallback((newValue) => setValue((oldValue) => {
33
34
  if (newValue !== oldValue) {
@@ -45,7 +46,10 @@ function SelectionSingleProvider({ value: valueProp, defaultValue, onChange: onC
45
46
  }, children: children }));
46
47
  }
47
48
  function SelectionMultipleProvider({ value: valueProp, defaultValue, onChange: onChangeProp, children, }) {
48
- const [value, setValue] = useUncontrolledProp(valueProp, defaultValue, onChangeProp);
49
+ const [value, setValue] = useUncontrolledProp(valueProp, defaultValue, newValue => {
50
+ const result = typeof newValue === 'function' ? newValue(value) : newValue;
51
+ onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp(result);
52
+ });
49
53
  const onChange = useCallback((newValue) => {
50
54
  setValue((oldValues) => {
51
55
  if (Array.isArray(oldValues)) {
@@ -1,3 +1,4 @@
1
1
  export * from './Lists';
2
- export type { AccordionItemProps, NextListItemProps, BaseItemProps, GroupItemProps, ItemProps } from './Items/types';
2
+ export type { AccordionItemProps, NextListItemProps, BaseItemProps, GroupItemProps, ItemProps } from './Items';
3
+ export { isAccordionItemProps, isBaseItemProps, isGroupItemProps, isNextListItemProps } from './Items';
3
4
  export { useGroupItemSelection } from './Items/hooks';
@@ -1,2 +1,3 @@
1
1
  export * from './Lists';
2
+ export { isAccordionItemProps, isBaseItemProps, isGroupItemProps, isNextListItemProps } from './Items';
2
3
  export { useGroupItemSelection } from './Items/hooks';
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
@@ -1,24 +1,10 @@
1
1
  import FuzzySearch from 'fuzzy-search';
2
2
  import { useCallback } from 'react';
3
- import { isGroupItemProps } from './components/Items';
4
- function flattenItems(items) {
5
- const flattenedItems = [];
6
- function flatten(item) {
7
- if (!isGroupItemProps(item)) {
8
- flattenedItems.push(item);
9
- }
10
- if ('items' in item) {
11
- for (const nestedItem of item.items) {
12
- flatten(nestedItem);
13
- }
14
- }
15
- }
16
- for (const item of items) {
17
- flatten(item);
18
- }
19
- return flattenedItems;
20
- }
3
+ import { flattenItems } from './utils';
21
4
  const DEFAULT_MIN_SEARCH_INPUT_LENGTH = 2;
5
+ /**
6
+ * Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
7
+ */
22
8
  export function useFuzzySearch(items, minSearchInputLength) {
23
9
  return useCallback((search) => {
24
10
  const searcher = new FuzzySearch(flattenItems(items), ['content.option', 'content.caption', 'content.description', 'label'], {});
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './components';
2
2
  export { useFuzzySearch } from './hooks';
3
3
  export type { SearchState } from './types';
4
- export { extractChildIds } from './utils';
4
+ export { extractChildIds, flattenItems } from './utils';
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export * from './components';
2
2
  export { useFuzzySearch } from './hooks';
3
- export { extractChildIds } from './utils';
3
+ export { extractChildIds, flattenItems } from './utils';
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { RefObject } from 'react';
2
- import { ItemProps } from './components/Items';
2
+ import { AccordionItemProps, BaseItemProps, ItemProps, NextListItemProps } from './components/Items';
3
3
  type WithCollapsedItemsProps = {
4
4
  items: ItemProps[];
5
5
  openCollapsedItems: Array<number | string>;
@@ -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,4 +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
+ */
29
+ export declare function flattenItems(items: ItemProps[]): (BaseItemProps | AccordionItemProps | NextListItemProps)[];
21
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,3 +92,24 @@ 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
+ */
99
+ export function flattenItems(items) {
100
+ const flattenedItems = [];
101
+ function flatten(item) {
102
+ if (!isGroupItemProps(item)) {
103
+ flattenedItems.push(item);
104
+ }
105
+ if ('items' in item) {
106
+ for (const nestedItem of item.items) {
107
+ flatten(nestedItem);
108
+ }
109
+ }
110
+ }
111
+ for (const item of items) {
112
+ flatten(item);
113
+ }
114
+ return flattenedItems;
115
+ }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "List",
7
- "version": "0.5.0",
7
+ "version": "0.6.1",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -32,10 +32,10 @@
32
32
  "license": "Apache-2.0",
33
33
  "scripts": {},
34
34
  "dependencies": {
35
- "@snack-uikit/divider": "3.0.1",
35
+ "@snack-uikit/divider": "3.0.2",
36
36
  "@snack-uikit/dropdown": "0.2.0",
37
37
  "@snack-uikit/icons": "0.20.1",
38
- "@snack-uikit/info-block": "0.3.0",
38
+ "@snack-uikit/info-block": "0.3.1",
39
39
  "@snack-uikit/loaders": "0.5.1",
40
40
  "@snack-uikit/locale": "0.6.0",
41
41
  "@snack-uikit/scroll": "0.5.2",
@@ -54,5 +54,5 @@
54
54
  "peerDependencies": {
55
55
  "@snack-uikit/locale": "*"
56
56
  },
57
- "gitHead": "bfdd4a8e3c077eab0d45e177172a62b6dcbda06b"
57
+ "gitHead": "0054db0a5550fb69d388335d844017bca31fffe7"
58
58
  }
@@ -90,8 +90,10 @@ function SelectionSingleProvider({
90
90
  onChange: onChangeProp,
91
91
  children,
92
92
  }: SelectionSingleProps & Child) {
93
- const [value, setValue] = useUncontrolledProp<SelectionSingleValueType>(valueProp, defaultValue, cb => {
94
- onChangeProp?.(cb(value));
93
+ const [value, setValue] = useUncontrolledProp<SelectionSingleValueType>(valueProp, defaultValue, newValue => {
94
+ const result = typeof newValue === 'function' ? newValue(value) : newValue;
95
+
96
+ onChangeProp?.(result);
95
97
  });
96
98
 
97
99
  const onChange = useCallback(
@@ -128,7 +130,11 @@ function SelectionMultipleProvider({
128
130
  onChange: onChangeProp,
129
131
  children,
130
132
  }: SelectionMultipleProps & Child) {
131
- const [value, setValue] = useUncontrolledProp<SelectionSingleValueType[]>(valueProp, defaultValue, onChangeProp);
133
+ const [value, setValue] = useUncontrolledProp<SelectionSingleValueType[]>(valueProp, defaultValue, newValue => {
134
+ const result = typeof newValue === 'function' ? newValue(value) : newValue;
135
+
136
+ onChangeProp?.(result);
137
+ });
132
138
 
133
139
  const onChange = useCallback(
134
140
  (newValue: SelectionSingleValueType) => {
@@ -1,5 +1,6 @@
1
1
  export * from './Lists';
2
2
 
3
- export type { AccordionItemProps, NextListItemProps, BaseItemProps, GroupItemProps, ItemProps } from './Items/types';
3
+ export type { AccordionItemProps, NextListItemProps, BaseItemProps, GroupItemProps, ItemProps } from './Items';
4
+ export { isAccordionItemProps, isBaseItemProps, isGroupItemProps, isNextListItemProps } from './Items';
4
5
 
5
6
  export { useGroupItemSelection } from './Items/hooks';
package/src/hooks.ts CHANGED
@@ -1,32 +1,14 @@
1
1
  import FuzzySearch from 'fuzzy-search';
2
2
  import { useCallback } from 'react';
3
3
 
4
- import { isGroupItemProps, ItemProps } from './components/Items';
5
-
6
- function flattenItems(items: ItemProps[]): ItemProps[] {
7
- const flattenedItems: ItemProps[] = [];
8
-
9
- function flatten(item: ItemProps) {
10
- if (!isGroupItemProps(item)) {
11
- flattenedItems.push(item);
12
- }
13
-
14
- if ('items' in item) {
15
- for (const nestedItem of item.items) {
16
- flatten(nestedItem);
17
- }
18
- }
19
- }
20
-
21
- for (const item of items) {
22
- flatten(item);
23
- }
24
-
25
- return flattenedItems;
26
- }
4
+ import { ItemProps } from './components/Items';
5
+ import { flattenItems } from './utils';
27
6
 
28
7
  const DEFAULT_MIN_SEARCH_INPUT_LENGTH = 2;
29
8
 
9
+ /**
10
+ * Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
11
+ */
30
12
  export function useFuzzySearch(items: ItemProps[], minSearchInputLength?: number) {
31
13
  return useCallback(
32
14
  (search: string) => {
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './components';
2
2
  export { useFuzzySearch } from './hooks';
3
3
  export type { SearchState } from './types';
4
- export { extractChildIds } from './utils';
4
+ export { extractChildIds, flattenItems } from './utils';
package/src/utils.ts CHANGED
@@ -1,11 +1,14 @@
1
1
  import { RefObject } from 'react';
2
2
 
3
3
  import {
4
+ AccordionItemProps,
5
+ BaseItemProps,
4
6
  isAccordionItemProps,
5
7
  isBaseItemProps,
6
8
  isGroupItemProps,
7
9
  isNextListItemProps,
8
10
  ItemProps,
11
+ NextListItemProps,
9
12
  } from './components/Items';
10
13
 
11
14
  type WithCollapsedItemsProps = {
@@ -77,6 +80,11 @@ export function extractItemRefs(items: ItemProps[]): RefObject<HTMLElement>[] {
77
80
  }, [] as RefObject<HTMLElement>[]);
78
81
  }
79
82
 
83
+ /**
84
+ * Функция возвращает массив id дочерних items
85
+ * @function extractItemIds
86
+ */
87
+
80
88
  export function extractItemIds(items: ItemProps[]): Array<string | number> {
81
89
  return items.reduce(
82
90
  (prev: Array<string | number>, item: ItemProps) => {
@@ -138,3 +146,30 @@ export function extractAllChildIds({ items }: { items: ItemProps[] }): Array<str
138
146
  [] as Array<string | number>,
139
147
  );
140
148
  }
149
+
150
+ /**
151
+ *  Функция разворачивает массив айтемов в плоский список
152
+ * @function flattenItems
153
+ */
154
+
155
+ export function flattenItems(items: ItemProps[]): (BaseItemProps | AccordionItemProps | NextListItemProps)[] {
156
+ const flattenedItems: (BaseItemProps | AccordionItemProps | NextListItemProps)[] = [];
157
+
158
+ function flatten(item: ItemProps) {
159
+ if (!isGroupItemProps(item)) {
160
+ flattenedItems.push(item);
161
+ }
162
+
163
+ if ('items' in item) {
164
+ for (const nestedItem of item.items) {
165
+ flatten(nestedItem);
166
+ }
167
+ }
168
+ }
169
+
170
+ for (const item of items) {
171
+ flatten(item);
172
+ }
173
+
174
+ return flattenedItems;
175
+ }