@snack-uikit/fields 0.18.2-preview-cb79db34.0 → 0.18.2-preview-01f09206.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 +5 -5
- package/dist/components/FieldDate/FieldDate.js +1 -1
- package/dist/components/FieldSelect/FieldSelectMultiple.d.ts +1 -3
- package/dist/components/FieldSelect/FieldSelectMultiple.js +2 -6
- package/dist/components/FieldSelect/FieldSelectSingle.d.ts +1 -3
- package/dist/components/FieldSelect/FieldSelectSingle.js +3 -12
- package/dist/components/FieldSelect/hooks.js +2 -8
- package/dist/components/FieldSelect/types.d.ts +3 -6
- package/dist/components/FieldSelect/utils/extractListProps.d.ts +1 -1
- package/dist/components/FieldSelect/utils/extractListProps.js +3 -1
- package/dist/components/FieldSelect/utils/options.js +1 -1
- package/dist/components/FieldSelect/utils/typeGuards.js +1 -1
- package/dist/components/FieldSelect/utils/updateItems.d.ts +6 -6
- package/dist/components/FieldSelect/utils/updateItems.js +3 -12
- package/dist/helperComponents/FieldContainerPrivate/styles.module.css +1 -1
- package/package.json +13 -15
- package/src/components/FieldDate/FieldDate.tsx +1 -1
- package/src/components/FieldSelect/FieldSelectMultiple.tsx +2 -6
- package/src/components/FieldSelect/FieldSelectSingle.tsx +2 -10
- package/src/components/FieldSelect/hooks.ts +2 -11
- package/src/components/FieldSelect/types.ts +12 -29
- package/src/components/FieldSelect/utils/extractListProps.ts +4 -0
- package/src/components/FieldSelect/utils/options.ts +1 -2
- package/src/components/FieldSelect/utils/typeGuards.ts +1 -1
- package/src/components/FieldSelect/utils/updateItems.ts +4 -14
- package/dist/components/FieldSelect/legacy/components/Items/hooks.d.ts +0 -12
- package/dist/components/FieldSelect/legacy/components/Items/hooks.js +0 -33
- package/dist/components/FieldSelect/legacy/components/index.d.ts +0 -1
- package/dist/components/FieldSelect/legacy/components/index.js +0 -1
- package/dist/components/FieldSelect/legacy/hooks.d.ts +0 -5
- package/dist/components/FieldSelect/legacy/hooks.js +0 -19
- package/dist/components/FieldSelect/legacy/index.d.ts +0 -3
- package/dist/components/FieldSelect/legacy/index.js +0 -3
- package/dist/components/FieldSelect/legacy/utils.d.ts +0 -29
- package/dist/components/FieldSelect/legacy/utils.js +0 -107
- package/src/components/FieldSelect/legacy/components/Items/hooks.tsx +0 -53
- package/src/components/FieldSelect/legacy/components/index.ts +0 -1
- package/src/components/FieldSelect/legacy/hooks.ts +0 -32
- package/src/components/FieldSelect/legacy/index.ts +0 -3
- package/src/components/FieldSelect/legacy/utils.ts +0 -166
package/README.md
CHANGED
|
@@ -312,8 +312,6 @@ const [isOpen, setIsOpen] = useState(false);
|
|
|
312
312
|
### Props
|
|
313
313
|
| name | type | default value | description |
|
|
314
314
|
|------|------|---------------|-------------|
|
|
315
|
-
| pinBottom* | `OptionProps[]` | - | |
|
|
316
|
-
| pinTop* | `OptionProps[]` | - | |
|
|
317
315
|
| options* | `OptionProps[]` | - | |
|
|
318
316
|
| disabled | `boolean` | false | Является ли поле деактивированным |
|
|
319
317
|
| readonly | `boolean` | false false | Является ли поле доступным только для чтения |
|
|
@@ -334,9 +332,9 @@ const [isOpen, setIsOpen] = useState(false);
|
|
|
334
332
|
| validationState | enum ValidationState: `"default"`, `"error"`, `"warning"`, `"success"` | - | Состояние валидации |
|
|
335
333
|
| showHintIcon | `boolean` | - | Отображать иконку подсказки |
|
|
336
334
|
| loading | `boolean` | - | |
|
|
337
|
-
| value | `
|
|
338
|
-
| onChange | `
|
|
339
|
-
| defaultValue | `
|
|
335
|
+
| value | `SelectionSingleValueType \| SelectionSingleValueType[]` | - | Controlled состояние |
|
|
336
|
+
| onChange | `((value: any) => void) \| ((value: any) => void)` | - | Controlled обработчик измения состояния |
|
|
337
|
+
| defaultValue | `SelectionSingleValueType \| SelectionSingleValueType[]` | - | Начальное состояние |
|
|
340
338
|
| searchable | `boolean` | - | |
|
|
341
339
|
| showCopyButton | `boolean` | - | Отображение кнопки Копировать для поля (актуально только для `readonly = true`) |
|
|
342
340
|
| showClearButton | `boolean` | true | Отображение кнопки очистки поля |
|
|
@@ -352,6 +350,8 @@ const [isOpen, setIsOpen] = useState(false);
|
|
|
352
350
|
| noDataState | `EmptyStateProps` | - | Экран при отстутствии данных |
|
|
353
351
|
| noResultsState | `EmptyStateProps` | - | Экран при отстутствии результатов поиска или фильтров |
|
|
354
352
|
| errorDataState | `EmptyStateProps` | - | Экран при ошибке запроса |
|
|
353
|
+
| pinTop | `ItemProps[]` | - | Элементы списка, закрепленные сверху |
|
|
354
|
+
| pinBottom | `ItemProps[]` | - | Элементы списка, закрепленные снизу |
|
|
355
355
|
| dataFiltered | `boolean` | - | |
|
|
356
356
|
| selection | "single" \| "multiple" | - | |
|
|
357
357
|
| ref | `Ref<HTMLInputElement>` | - | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom |
|
|
@@ -14,7 +14,7 @@ import mergeRefs from 'merge-refs';
|
|
|
14
14
|
import { forwardRef, useCallback, useEffect, useMemo, useRef, useState, } from 'react';
|
|
15
15
|
import { useUncontrolledProp } from 'uncontrollable';
|
|
16
16
|
import { Calendar } from '@snack-uikit/calendar';
|
|
17
|
-
import { Dropdown } from '@snack-uikit/
|
|
17
|
+
import { Dropdown } from '@snack-uikit/droplist';
|
|
18
18
|
import { CalendarSVG } from '@snack-uikit/icons';
|
|
19
19
|
import { ICON_SIZE, InputPrivate, runAfterRerender, SIZE, useButtonNavigation, useClearButton, } from '@snack-uikit/input-private';
|
|
20
20
|
import { extractSupportProps } from '@snack-uikit/utils';
|
|
@@ -9,8 +9,6 @@ export declare const FieldSelectMultiple: import("react").ForwardRefExoticCompon
|
|
|
9
9
|
'data-test-id'?: string | undefined;
|
|
10
10
|
} & import("react").AriaAttributes & {
|
|
11
11
|
options: import("./types").OptionProps[];
|
|
12
|
-
pinTop: import("./types").OptionProps[];
|
|
13
|
-
pinBottom: import("./types").OptionProps[];
|
|
14
12
|
searchable?: boolean | undefined;
|
|
15
13
|
showCopyButton?: boolean | undefined;
|
|
16
14
|
showClearButton?: boolean | undefined;
|
|
@@ -23,4 +21,4 @@ export declare const FieldSelectMultiple: import("react").ForwardRefExoticCompon
|
|
|
23
21
|
open?: boolean | undefined;
|
|
24
22
|
onOpenChange?(open: boolean): void;
|
|
25
23
|
selectedOptionFormatter?: SelectedOptionFormatter | undefined;
|
|
26
|
-
} & Pick<import("@snack-uikit/list").ListProps, "dataError" | "
|
|
24
|
+
} & Pick<import("@snack-uikit/list").ListProps, "dataError" | "noDataState" | "noResultsState" | "errorDataState" | "pinTop" | "pinBottom" | "dataFiltered">, "showCopyButton"> & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -14,7 +14,7 @@ import cn from 'classnames';
|
|
|
14
14
|
import mergeRefs from 'merge-refs';
|
|
15
15
|
import { forwardRef, useLayoutEffect, useRef, useState } from 'react';
|
|
16
16
|
import { InputPrivate } from '@snack-uikit/input-private';
|
|
17
|
-
import { Droplist } from '@snack-uikit/list';
|
|
17
|
+
import { Droplist, useFuzzySearch } from '@snack-uikit/list';
|
|
18
18
|
import { Tag } from '@snack-uikit/tag';
|
|
19
19
|
import { extractSupportProps } from '@snack-uikit/utils';
|
|
20
20
|
import { FieldContainerPrivate } from '../../helperComponents';
|
|
@@ -22,14 +22,10 @@ import { useValueControl } from '../../hooks';
|
|
|
22
22
|
import { FieldDecorator } from '../FieldDecorator';
|
|
23
23
|
import { extractFieldDecoratorProps } from '../FieldDecorator/utils';
|
|
24
24
|
import { useButtons, useHandleDeleteItem, useHandleOnKeyDown, useSearchInput } from './hooks';
|
|
25
|
-
import { useFuzzySearch } from './legacy';
|
|
26
25
|
import styles from './styles.module.css';
|
|
27
26
|
import { extractListProps, getArrowIcon, updateMultipleItems } from './utils';
|
|
28
27
|
const BASE_MIN_WIDTH = 4;
|
|
29
|
-
const defaultSelectedOptionFormatter = item =>
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
31
|
-
// @ts-expect-error
|
|
32
|
-
(item === null || item === void 0 ? void 0 : item.content.option) || '';
|
|
28
|
+
const defaultSelectedOptionFormatter = item => (item === null || item === void 0 ? void 0 : item.content.option) || '';
|
|
33
29
|
export const FieldSelectMultiple = forwardRef((_a, ref) => {
|
|
34
30
|
var _b;
|
|
35
31
|
var { id, name, placeholder, size = 's', options, value: valueProp, defaultValue, onChange: onChangeProp, disabled = false, readonly = false, searchable = true, showClearButton = true, onKeyDown: onInputKeyDownProp, validationState = 'default', search, autocomplete = false, prefixIcon, removeByBackspace = false, addOptionByEnter = false, open: openProp, onOpenChange, selectedOptionFormatter = defaultSelectedOptionFormatter } = _a, rest = __rest(_a, ["id", "name", "placeholder", "size", "options", "value", "defaultValue", "onChange", "disabled", "readonly", "searchable", "showClearButton", "onKeyDown", "validationState", "search", "autocomplete", "prefixIcon", "removeByBackspace", "addOptionByEnter", "open", "onOpenChange", "selectedOptionFormatter"]);
|
|
@@ -7,8 +7,6 @@ export declare const FieldSelectSingle: import("react").ForwardRefExoticComponen
|
|
|
7
7
|
'data-test-id'?: string | undefined;
|
|
8
8
|
} & import("react").AriaAttributes & {
|
|
9
9
|
options: import("./types").OptionProps[];
|
|
10
|
-
pinTop: import("./types").OptionProps[];
|
|
11
|
-
pinBottom: import("./types").OptionProps[];
|
|
12
10
|
searchable?: boolean | undefined;
|
|
13
11
|
showCopyButton?: boolean | undefined;
|
|
14
12
|
showClearButton?: boolean | undefined;
|
|
@@ -21,4 +19,4 @@ export declare const FieldSelectSingle: import("react").ForwardRefExoticComponen
|
|
|
21
19
|
open?: boolean | undefined;
|
|
22
20
|
onOpenChange?(open: boolean): void;
|
|
23
21
|
selectedOptionFormatter?: SelectedOptionFormatter | undefined;
|
|
24
|
-
} & Pick<import("@snack-uikit/list").ListProps, "dataError" | "
|
|
22
|
+
} & Pick<import("@snack-uikit/list").ListProps, "dataError" | "noDataState" | "noResultsState" | "errorDataState" | "pinTop" | "pinBottom" | "dataFiltered"> & import("react").RefAttributes<HTMLInputElement>>;
|
|
@@ -14,20 +14,16 @@ import cn from 'classnames';
|
|
|
14
14
|
import mergeRefs from 'merge-refs';
|
|
15
15
|
import { forwardRef, useCallback, useEffect, useLayoutEffect, useRef, useState, } from 'react';
|
|
16
16
|
import { InputPrivate } from '@snack-uikit/input-private';
|
|
17
|
-
import { Droplist } from '@snack-uikit/list';
|
|
17
|
+
import { Droplist, useFuzzySearch } from '@snack-uikit/list';
|
|
18
18
|
import { extractSupportProps } from '@snack-uikit/utils';
|
|
19
19
|
import { FieldContainerPrivate } from '../../helperComponents';
|
|
20
20
|
import { useValueControl } from '../../hooks';
|
|
21
21
|
import { FieldDecorator } from '../FieldDecorator';
|
|
22
22
|
import { extractFieldDecoratorProps } from '../FieldDecorator/utils';
|
|
23
23
|
import { useButtons, useHandleOnKeyDown, useSearchInput } from './hooks';
|
|
24
|
-
import { useFuzzySearch } from './legacy';
|
|
25
24
|
import styles from './styles.module.css';
|
|
26
25
|
import { extractListProps, getArrowIcon, updateItems } from './utils';
|
|
27
|
-
const defaultSelectedOptionFormatter = item =>
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
29
|
-
// @ts-expect-error
|
|
30
|
-
(item === null || item === void 0 ? void 0 : item.content.option) || '';
|
|
26
|
+
const defaultSelectedOptionFormatter = item => (item === null || item === void 0 ? void 0 : item.content.option) || '';
|
|
31
27
|
export const FieldSelectSingle = forwardRef((_a, ref) => {
|
|
32
28
|
var _b;
|
|
33
29
|
var { id, name, placeholder, size = 's', options, value: valueProp, defaultValue, onChange: onChangeProp, disabled = false, readonly = false, searchable = true, showCopyButton = true, showClearButton = true, onKeyDown: onInputKeyDownProp, required = false, validationState = 'default', search, autocomplete = false, prefixIcon, addOptionByEnter = false, open: openProp, onOpenChange, selectedOptionFormatter = defaultSelectedOptionFormatter } = _a, rest = __rest(_a, ["id", "name", "placeholder", "size", "options", "value", "defaultValue", "onChange", "disabled", "readonly", "searchable", "showCopyButton", "showClearButton", "onKeyDown", "required", "validationState", "search", "autocomplete", "prefixIcon", "addOptionByEnter", "open", "onOpenChange", "selectedOptionFormatter"]);
|
|
@@ -39,10 +35,7 @@ export const FieldSelectSingle = forwardRef((_a, ref) => {
|
|
|
39
35
|
onChange: onChangeProp,
|
|
40
36
|
});
|
|
41
37
|
const [{ selectedItem, items = [] }, setItems] = useState(() => updateItems({ options, value, currentItems: [], selectedItem: undefined }));
|
|
42
|
-
const { inputValue, setInputValue, prevInputValue, updateInputValue } = useSearchInput(Object.assign(Object.assign({}, search), {
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
44
|
-
// @ts-expect-error
|
|
45
|
-
defaultValue: (_b = selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.content.option) !== null && _b !== void 0 ? _b : '', selectedOptionFormatter }));
|
|
38
|
+
const { inputValue, setInputValue, prevInputValue, updateInputValue } = useSearchInput(Object.assign(Object.assign({}, search), { defaultValue: (_b = selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.content.option) !== null && _b !== void 0 ? _b : '', selectedOptionFormatter }));
|
|
46
39
|
const prevSelectedItem = useRef(selectedItem);
|
|
47
40
|
useLayoutEffect(() => {
|
|
48
41
|
setItems(({ selectedItem }) => updateItems({ options, value, selectedItem }));
|
|
@@ -50,8 +43,6 @@ export const FieldSelectSingle = forwardRef((_a, ref) => {
|
|
|
50
43
|
useEffect(() => {
|
|
51
44
|
if (prevSelectedItem.current &&
|
|
52
45
|
prevSelectedItem.current.id === (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.id) &&
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
54
|
-
// @ts-expect-error
|
|
55
46
|
prevSelectedItem.current.content.option === (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.content.option)) {
|
|
56
47
|
return;
|
|
57
48
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { useCallback, useMemo, useRef } from 'react';
|
|
2
2
|
import { useButtonNavigation, useClearButton } from '@snack-uikit/input-private';
|
|
3
|
-
import {
|
|
4
|
-
// extractChildIds,
|
|
5
|
-
isAccordionItemProps, isNextListItemProps, } from '@snack-uikit/list';
|
|
3
|
+
import { extractChildIds, isAccordionItemProps, isNextListItemProps, } from '@snack-uikit/list';
|
|
6
4
|
import { useCopyButton, useValueControl } from '../../hooks';
|
|
7
|
-
import { extractChildIds } from './legacy';
|
|
8
5
|
import { isBaseOptionProps } from './utils';
|
|
9
6
|
export function useHandleOnKeyDown({ setOpen, inputKeyDownNavigationHandler, onInputKeyDownProp, }) {
|
|
10
7
|
return useCallback((onKeyDown) => (e) => {
|
|
@@ -77,10 +74,7 @@ export function useHandleDeleteItem(setValue) {
|
|
|
77
74
|
return;
|
|
78
75
|
}
|
|
79
76
|
if (isBaseOptionProps(item)) {
|
|
80
|
-
setValue((value) => value === null || value === void 0 ? void 0 : value.filter(v =>
|
|
81
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
82
|
-
// @ts-expect-error
|
|
83
|
-
v !== item.id));
|
|
77
|
+
setValue((value) => value === null || value === void 0 ? void 0 : value.filter(v => v !== item.id));
|
|
84
78
|
}
|
|
85
79
|
}, [setValue]);
|
|
86
80
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
2
|
import { InputPrivateProps } from '@snack-uikit/input-private';
|
|
3
|
-
import { AccordionItemProps, BaseItemProps, GroupItemProps,
|
|
3
|
+
import { AccordionItemProps, BaseItemProps, GroupItemProps, ListProps, NextListItemProps, SelectionMultipleState, SelectionSingleState } from '@snack-uikit/list';
|
|
4
4
|
import { TagProps } from '@snack-uikit/tag';
|
|
5
5
|
import { WithSupportProps } from '@snack-uikit/utils';
|
|
6
6
|
import { FieldDecoratorProps } from '../FieldDecorator';
|
|
7
|
-
export type AnyType = any;
|
|
8
7
|
export type OptionProps = BaseOptionProps | AccordionOptionProps | GroupOptionProps | NestListOptionProps;
|
|
9
8
|
export type OptionWithoutGroup = BaseOptionProps | AccordionOptionProps | NestListOptionProps;
|
|
10
|
-
export type BaseOptionProps = Pick<BaseItemProps, 'beforeContent' | 'afterContent' | 'disabled'> &
|
|
9
|
+
export type BaseOptionProps = Pick<BaseItemProps, 'beforeContent' | 'afterContent' | 'disabled'> & BaseItemProps['content'] & {
|
|
11
10
|
value: string | number;
|
|
12
11
|
} & Pick<TagProps, 'appearance'>;
|
|
13
12
|
export type AccordionOptionProps = Pick<AccordionItemProps, 'type'> & BaseOptionProps & {
|
|
@@ -37,8 +36,6 @@ export type FieldSelectPrivateProps = InputProps & WrapperProps & {
|
|
|
37
36
|
};
|
|
38
37
|
type FiledSelectCommonProps = WithSupportProps<{
|
|
39
38
|
options: OptionProps[];
|
|
40
|
-
pinTop: OptionProps[];
|
|
41
|
-
pinBottom: OptionProps[];
|
|
42
39
|
searchable?: boolean;
|
|
43
40
|
/** Отображение кнопки Копировать для поля (актуально только для `readonly = true`) */
|
|
44
41
|
showCopyButton?: boolean;
|
|
@@ -61,7 +58,7 @@ type FiledSelectCommonProps = WithSupportProps<{
|
|
|
61
58
|
open?: boolean;
|
|
62
59
|
onOpenChange?(open: boolean): void;
|
|
63
60
|
selectedOptionFormatter?: SelectedOptionFormatter;
|
|
64
|
-
}> & Pick<ListProps, 'dataError' | 'noDataState' | 'noResultsState' | 'errorDataState' | 'dataFiltered'>;
|
|
61
|
+
}> & Pick<ListProps, 'dataError' | 'noDataState' | 'noResultsState' | 'errorDataState' | 'pinTop' | 'pinBottom' | 'dataFiltered'>;
|
|
65
62
|
export type FieldSelectSingleProps = FieldSelectPrivateProps & Omit<SelectionSingleState, 'mode'> & WrapperProps & FiledSelectCommonProps;
|
|
66
63
|
export type FieldSelectMultipleProps = FieldSelectPrivateProps & {
|
|
67
64
|
removeByBackspace?: boolean;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { DroplistProps } from '@snack-uikit/list';
|
|
2
2
|
import { FieldSelectProps } from '../types';
|
|
3
|
-
export declare function extractListProps({ dataError, noDataState, noResultsState, errorDataState, dataFiltered, loading, }: Partial<FieldSelectProps>): Partial<DroplistProps>;
|
|
3
|
+
export declare function extractListProps({ dataError, noDataState, noResultsState, errorDataState, pinTop, pinBottom, dataFiltered, loading, }: Partial<FieldSelectProps>): Partial<DroplistProps>;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
export function extractListProps({ dataError, noDataState, noResultsState, errorDataState, dataFiltered, loading, }) {
|
|
1
|
+
export function extractListProps({ dataError, noDataState, noResultsState, errorDataState, pinTop, pinBottom, dataFiltered, loading, }) {
|
|
2
2
|
return {
|
|
3
3
|
dataError,
|
|
4
4
|
noDataState,
|
|
5
5
|
noResultsState,
|
|
6
6
|
errorDataState,
|
|
7
|
+
pinTop,
|
|
8
|
+
pinBottom,
|
|
7
9
|
dataFiltered,
|
|
8
10
|
loading,
|
|
9
11
|
trigger: 'clickAndFocusVisible',
|
|
@@ -9,7 +9,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import { flattenItems } from '
|
|
12
|
+
import { flattenItems } from '@snack-uikit/list';
|
|
13
13
|
import { isAccordionOptionProps, isGroupOptionProps, isNextListOptionProps } from './typeGuards';
|
|
14
14
|
export function transformOptionsToItems(options) {
|
|
15
15
|
return options.map(option => {
|
|
@@ -12,7 +12,7 @@ export function isNextListOptionProps(option) {
|
|
|
12
12
|
}
|
|
13
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
14
|
export function isGroupOptionProps(option) {
|
|
15
|
-
return 'options' in option && option['type'] ===
|
|
15
|
+
return 'options' in option && option['type'] === undefined;
|
|
16
16
|
}
|
|
17
17
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
18
|
export function isFieldSelectMultipleProps(props) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ItemProps, SelectionSingleValueType } from '@snack-uikit/list';
|
|
2
2
|
import { ItemWithId, OptionProps } from '../types';
|
|
3
3
|
export declare function createPlaceholderItem(value: SelectionSingleValueType): {
|
|
4
|
-
id:
|
|
4
|
+
id: SelectionSingleValueType;
|
|
5
5
|
content: {
|
|
6
6
|
option: string;
|
|
7
7
|
};
|
|
@@ -9,12 +9,12 @@ export declare function createPlaceholderItem(value: SelectionSingleValueType):
|
|
|
9
9
|
};
|
|
10
10
|
export declare function updateItems({ options, value, selectedItem, }: {
|
|
11
11
|
options: OptionProps[];
|
|
12
|
-
value
|
|
12
|
+
value: SelectionSingleValueType;
|
|
13
13
|
selectedItem?: ItemWithId;
|
|
14
14
|
currentItems?: ItemProps[];
|
|
15
15
|
}): {
|
|
16
16
|
selectedItem: ItemWithId | undefined;
|
|
17
|
-
items:
|
|
17
|
+
items: ItemProps[];
|
|
18
18
|
};
|
|
19
19
|
export declare function updateMultipleItems({ options, value, selectedItems, }: {
|
|
20
20
|
options: OptionProps[];
|
|
@@ -23,10 +23,10 @@ export declare function updateMultipleItems({ options, value, selectedItems, }:
|
|
|
23
23
|
currentItems?: ItemProps[];
|
|
24
24
|
}): {
|
|
25
25
|
selectedItems: undefined;
|
|
26
|
-
items: (
|
|
26
|
+
items: (ItemProps & {
|
|
27
27
|
appearance?: import("@snack-uikit/tag/dist/types").Appearance | undefined;
|
|
28
28
|
})[];
|
|
29
29
|
} | {
|
|
30
30
|
selectedItems: ItemWithId[];
|
|
31
|
-
items:
|
|
31
|
+
items: ItemProps[];
|
|
32
32
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { flattenItems } from '
|
|
1
|
+
import { flattenItems } from '@snack-uikit/list';
|
|
2
2
|
import { transformOptionsToItems } from './options';
|
|
3
3
|
export function createPlaceholderItem(value) {
|
|
4
4
|
return { id: value, content: { option: String(value) }, placeholder: true };
|
|
@@ -39,20 +39,11 @@ export function updateMultipleItems({ options, value, selectedItems, }) {
|
|
|
39
39
|
items: originalItems,
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
const foundedValue = [];
|
|
43
42
|
let newItems = originalItems;
|
|
44
43
|
let newSelectedItems = selectedItems;
|
|
45
44
|
const flattenOriginalItems = flattenItems(originalItems);
|
|
46
|
-
|
|
47
|
-
const
|
|
48
|
-
if (value.includes(item.id) && !foundedValue.includes(item.id)) {
|
|
49
|
-
foundedValue.push(item.id);
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
const nonFoundValues = value.filter(
|
|
54
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
|
-
value => !flattenOriginalItems.find((item) => item.id === value));
|
|
45
|
+
const foundItems = flattenOriginalItems.filter(item => value.includes(item.id));
|
|
46
|
+
const nonFoundValues = value.filter(value => !flattenOriginalItems.find(item => item.id === value));
|
|
56
47
|
if (nonFoundValues.length) {
|
|
57
48
|
const nonFoundItems = nonFoundValues.map(value => (selectedItems === null || selectedItems === void 0 ? void 0 : selectedItems.find(selectedItem => selectedItem.id === value)) || createPlaceholderItem(value));
|
|
58
49
|
newSelectedItems = [...foundItems, ...nonFoundItems];
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
border-style:solid;
|
|
8
8
|
}
|
|
9
9
|
.container[data-validation=default]{
|
|
10
|
-
background-color:var(--sys-neutral-background1-level, #
|
|
10
|
+
background-color:var(--sys-neutral-background1-level, #fafafc);
|
|
11
11
|
border-color:var(--sys-neutral-decor-default, #dfe2ec);
|
|
12
12
|
}
|
|
13
13
|
.container[data-validation=default]:hover{
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Fields",
|
|
7
|
-
"version": "0.18.2-preview-
|
|
7
|
+
"version": "0.18.2-preview-01f09206.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -32,31 +32,29 @@
|
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
33
|
"scripts": {},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@snack-uikit/button": "0.17.
|
|
36
|
-
"@snack-uikit/calendar": "0.7.
|
|
37
|
-
"@snack-uikit/
|
|
35
|
+
"@snack-uikit/button": "0.17.0",
|
|
36
|
+
"@snack-uikit/calendar": "0.7.6",
|
|
37
|
+
"@snack-uikit/droplist": "0.13.14",
|
|
38
38
|
"@snack-uikit/icons": "0.20.1",
|
|
39
|
-
"@snack-uikit/input-private": "3.1.
|
|
40
|
-
"@snack-uikit/list": "0.10.1-preview-
|
|
41
|
-
"@snack-uikit/scroll": "0.5.
|
|
42
|
-
"@snack-uikit/slider": "0.1.
|
|
43
|
-
"@snack-uikit/tag": "0.8.
|
|
44
|
-
"@snack-uikit/tooltip": "0.13.
|
|
45
|
-
"@snack-uikit/truncate-string": "0.4.
|
|
46
|
-
"@snack-uikit/utils": "3.2.
|
|
39
|
+
"@snack-uikit/input-private": "3.1.1",
|
|
40
|
+
"@snack-uikit/list": "0.10.1-preview-01f09206.0",
|
|
41
|
+
"@snack-uikit/scroll": "0.5.2",
|
|
42
|
+
"@snack-uikit/slider": "0.1.7",
|
|
43
|
+
"@snack-uikit/tag": "0.8.2",
|
|
44
|
+
"@snack-uikit/tooltip": "0.13.1",
|
|
45
|
+
"@snack-uikit/truncate-string": "0.4.12",
|
|
46
|
+
"@snack-uikit/utils": "3.2.0",
|
|
47
47
|
"classnames": "2.3.2",
|
|
48
48
|
"copy-to-clipboard": "3.3.3",
|
|
49
|
-
"fuzzy-search": "3.2.1",
|
|
50
49
|
"merge-refs": "1.2.2",
|
|
51
50
|
"react-textarea-autosize": "8.5.3",
|
|
52
51
|
"uncontrollable": "8.0.4"
|
|
53
52
|
},
|
|
54
53
|
"devDependencies": {
|
|
55
|
-
"@types/fuzzy-search": "2.1.5",
|
|
56
54
|
"@types/merge-refs": "1.0.0"
|
|
57
55
|
},
|
|
58
56
|
"peerDependencies": {
|
|
59
57
|
"@snack-uikit/locale": "*"
|
|
60
58
|
},
|
|
61
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "83d9838d9512ed93692593a24cbd05a68d622281"
|
|
62
60
|
}
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
import { useUncontrolledProp } from 'uncontrollable';
|
|
14
14
|
|
|
15
15
|
import { Calendar, CalendarProps } from '@snack-uikit/calendar';
|
|
16
|
-
import { Dropdown } from '@snack-uikit/
|
|
16
|
+
import { Dropdown } from '@snack-uikit/droplist';
|
|
17
17
|
import { CalendarSVG } from '@snack-uikit/icons';
|
|
18
18
|
import {
|
|
19
19
|
ICON_SIZE,
|
|
@@ -3,7 +3,7 @@ import mergeRefs from 'merge-refs';
|
|
|
3
3
|
import { FocusEvent, forwardRef, KeyboardEvent, KeyboardEventHandler, useLayoutEffect, useRef, useState } from 'react';
|
|
4
4
|
|
|
5
5
|
import { InputPrivate } from '@snack-uikit/input-private';
|
|
6
|
-
import { BaseItemProps, Droplist, ItemProps, SelectionSingleValueType } from '@snack-uikit/list';
|
|
6
|
+
import { BaseItemProps, Droplist, ItemProps, SelectionSingleValueType, useFuzzySearch } from '@snack-uikit/list';
|
|
7
7
|
import { Tag } from '@snack-uikit/tag';
|
|
8
8
|
import { extractSupportProps } from '@snack-uikit/utils';
|
|
9
9
|
|
|
@@ -12,17 +12,13 @@ import { useValueControl } from '../../hooks';
|
|
|
12
12
|
import { FieldDecorator } from '../FieldDecorator';
|
|
13
13
|
import { extractFieldDecoratorProps } from '../FieldDecorator/utils';
|
|
14
14
|
import { useButtons, useHandleDeleteItem, useHandleOnKeyDown, useSearchInput } from './hooks';
|
|
15
|
-
import { useFuzzySearch } from './legacy';
|
|
16
15
|
import styles from './styles.module.scss';
|
|
17
16
|
import { FieldSelectMultipleProps, ItemWithId, SelectedOptionFormatter } from './types';
|
|
18
17
|
import { extractListProps, getArrowIcon, updateMultipleItems } from './utils';
|
|
19
18
|
|
|
20
19
|
const BASE_MIN_WIDTH = 4;
|
|
21
20
|
|
|
22
|
-
const defaultSelectedOptionFormatter: SelectedOptionFormatter = item =>
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
24
|
-
// @ts-expect-error
|
|
25
|
-
item?.content.option || '';
|
|
21
|
+
const defaultSelectedOptionFormatter: SelectedOptionFormatter = item => item?.content.option || '';
|
|
26
22
|
|
|
27
23
|
export const FieldSelectMultiple = forwardRef<HTMLInputElement, FieldSelectMultipleProps>(
|
|
28
24
|
(
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from 'react';
|
|
14
14
|
|
|
15
15
|
import { InputPrivate } from '@snack-uikit/input-private';
|
|
16
|
-
import { Droplist, ItemProps, SelectionSingleValueType } from '@snack-uikit/list';
|
|
16
|
+
import { Droplist, ItemProps, SelectionSingleValueType, useFuzzySearch } from '@snack-uikit/list';
|
|
17
17
|
import { extractSupportProps } from '@snack-uikit/utils';
|
|
18
18
|
|
|
19
19
|
import { FieldContainerPrivate } from '../../helperComponents';
|
|
@@ -21,15 +21,11 @@ import { useValueControl } from '../../hooks';
|
|
|
21
21
|
import { FieldDecorator } from '../FieldDecorator';
|
|
22
22
|
import { extractFieldDecoratorProps } from '../FieldDecorator/utils';
|
|
23
23
|
import { useButtons, useHandleOnKeyDown, useSearchInput } from './hooks';
|
|
24
|
-
import { useFuzzySearch } from './legacy';
|
|
25
24
|
import styles from './styles.module.scss';
|
|
26
25
|
import { FieldSelectSingleProps, ItemWithId, SelectedOptionFormatter } from './types';
|
|
27
26
|
import { extractListProps, getArrowIcon, updateItems } from './utils';
|
|
28
27
|
|
|
29
|
-
const defaultSelectedOptionFormatter: SelectedOptionFormatter = item =>
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
31
|
-
// @ts-expect-error
|
|
32
|
-
item?.content.option || '';
|
|
28
|
+
const defaultSelectedOptionFormatter: SelectedOptionFormatter = item => item?.content.option || '';
|
|
33
29
|
|
|
34
30
|
export const FieldSelectSingle = forwardRef<HTMLInputElement, FieldSelectSingleProps>(
|
|
35
31
|
(
|
|
@@ -76,8 +72,6 @@ export const FieldSelectSingle = forwardRef<HTMLInputElement, FieldSelectSingleP
|
|
|
76
72
|
|
|
77
73
|
const { inputValue, setInputValue, prevInputValue, updateInputValue } = useSearchInput({
|
|
78
74
|
...search,
|
|
79
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
80
|
-
// @ts-expect-error
|
|
81
75
|
defaultValue: selectedItem?.content.option ?? '',
|
|
82
76
|
selectedOptionFormatter,
|
|
83
77
|
});
|
|
@@ -92,8 +86,6 @@ export const FieldSelectSingle = forwardRef<HTMLInputElement, FieldSelectSingleP
|
|
|
92
86
|
if (
|
|
93
87
|
prevSelectedItem.current &&
|
|
94
88
|
prevSelectedItem.current.id === selectedItem?.id &&
|
|
95
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
96
|
-
// @ts-expect-error
|
|
97
89
|
prevSelectedItem.current.content.option === selectedItem?.content.option
|
|
98
90
|
) {
|
|
99
91
|
return;
|
|
@@ -3,14 +3,13 @@ import { Handler } from 'uncontrollable';
|
|
|
3
3
|
|
|
4
4
|
import { useButtonNavigation, useClearButton } from '@snack-uikit/input-private';
|
|
5
5
|
import {
|
|
6
|
-
|
|
6
|
+
extractChildIds,
|
|
7
7
|
isAccordionItemProps,
|
|
8
8
|
isNextListItemProps,
|
|
9
9
|
SelectionSingleValueType,
|
|
10
10
|
} from '@snack-uikit/list';
|
|
11
11
|
|
|
12
12
|
import { useCopyButton, useValueControl } from '../../hooks';
|
|
13
|
-
import { extractChildIds } from './legacy';
|
|
14
13
|
import { ItemWithId, SearchState, SelectedOptionFormatter } from './types';
|
|
15
14
|
import { isBaseOptionProps } from './utils';
|
|
16
15
|
|
|
@@ -142,15 +141,7 @@ export function useHandleDeleteItem(setValue: Handler) {
|
|
|
142
141
|
}
|
|
143
142
|
|
|
144
143
|
if (isBaseOptionProps(item)) {
|
|
145
|
-
setValue(
|
|
146
|
-
(value: SelectionSingleValueType[]) =>
|
|
147
|
-
value?.filter(
|
|
148
|
-
v =>
|
|
149
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
150
|
-
// @ts-expect-error
|
|
151
|
-
v !== item.id,
|
|
152
|
-
),
|
|
153
|
-
);
|
|
144
|
+
setValue((value: SelectionSingleValueType[]) => value?.filter(v => v !== item.id));
|
|
154
145
|
}
|
|
155
146
|
},
|
|
156
147
|
[setValue],
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
AccordionItemProps,
|
|
6
6
|
BaseItemProps,
|
|
7
7
|
GroupItemProps,
|
|
8
|
-
ItemContentProps,
|
|
9
8
|
ListProps,
|
|
10
9
|
NextListItemProps,
|
|
11
10
|
SelectionMultipleState,
|
|
@@ -16,33 +15,17 @@ import { WithSupportProps } from '@snack-uikit/utils';
|
|
|
16
15
|
|
|
17
16
|
import { FieldDecoratorProps } from '../FieldDecorator';
|
|
18
17
|
|
|
19
|
-
// eslint-disable-next-line
|
|
20
|
-
export type
|
|
21
|
-
|
|
22
|
-
export type OptionProps =
|
|
23
|
-
// eslint-disable-next-line no-use-before-define
|
|
24
|
-
| BaseOptionProps
|
|
25
|
-
// eslint-disable-next-line no-use-before-define
|
|
26
|
-
| AccordionOptionProps
|
|
27
|
-
// eslint-disable-next-line no-use-before-define
|
|
28
|
-
| GroupOptionProps
|
|
29
|
-
// eslint-disable-next-line no-use-before-define
|
|
30
|
-
| NestListOptionProps;
|
|
18
|
+
// eslint-disable-next-line no-use-before-define
|
|
19
|
+
export type OptionProps = BaseOptionProps | AccordionOptionProps | GroupOptionProps | NestListOptionProps;
|
|
31
20
|
|
|
32
21
|
// eslint-disable-next-line no-use-before-define
|
|
33
22
|
export type OptionWithoutGroup = BaseOptionProps | AccordionOptionProps | NestListOptionProps;
|
|
34
23
|
|
|
35
24
|
export type BaseOptionProps = Pick<BaseItemProps, 'beforeContent' | 'afterContent' | 'disabled'> &
|
|
36
|
-
|
|
37
|
-
TagProps,
|
|
38
|
-
'appearance'
|
|
39
|
-
>;
|
|
25
|
+
BaseItemProps['content'] & { value: string | number } & Pick<TagProps, 'appearance'>;
|
|
40
26
|
|
|
41
27
|
export type AccordionOptionProps = Pick<AccordionItemProps, 'type'> & BaseOptionProps & { options: OptionProps[] };
|
|
42
|
-
|
|
43
|
-
export type GroupOptionProps = Omit<GroupItemProps, 'items' | 'id'> & {
|
|
44
|
-
options: OptionProps[];
|
|
45
|
-
};
|
|
28
|
+
export type GroupOptionProps = Omit<GroupItemProps, 'items' | 'id'> & { options: OptionProps[] };
|
|
46
29
|
export type NestListOptionProps = Pick<NextListItemProps, 'type' | 'onSublistOpenChanged' | 'id'> &
|
|
47
30
|
BaseOptionProps & { options: OptionProps[] };
|
|
48
31
|
|
|
@@ -82,10 +65,6 @@ export type FieldSelectPrivateProps = InputProps & WrapperProps & { options: Opt
|
|
|
82
65
|
|
|
83
66
|
type FiledSelectCommonProps = WithSupportProps<{
|
|
84
67
|
options: OptionProps[];
|
|
85
|
-
|
|
86
|
-
pinTop: OptionProps[];
|
|
87
|
-
pinBottom: OptionProps[];
|
|
88
|
-
|
|
89
68
|
searchable?: boolean;
|
|
90
69
|
/** Отображение кнопки Копировать для поля (актуально только для `readonly = true`) */
|
|
91
70
|
showCopyButton?: boolean;
|
|
@@ -117,16 +96,20 @@ type FiledSelectCommonProps = WithSupportProps<{
|
|
|
117
96
|
|
|
118
97
|
selectedOptionFormatter?: SelectedOptionFormatter;
|
|
119
98
|
}> &
|
|
120
|
-
Pick<
|
|
99
|
+
Pick<
|
|
100
|
+
ListProps,
|
|
101
|
+
'dataError' | 'noDataState' | 'noResultsState' | 'errorDataState' | 'pinTop' | 'pinBottom' | 'dataFiltered'
|
|
102
|
+
>;
|
|
121
103
|
|
|
122
104
|
export type FieldSelectSingleProps = FieldSelectPrivateProps &
|
|
123
105
|
Omit<SelectionSingleState, 'mode'> &
|
|
124
106
|
WrapperProps &
|
|
125
107
|
FiledSelectCommonProps;
|
|
126
108
|
|
|
127
|
-
export type FieldSelectMultipleProps = FieldSelectPrivateProps & {
|
|
128
|
-
|
|
129
|
-
|
|
109
|
+
export type FieldSelectMultipleProps = FieldSelectPrivateProps & { removeByBackspace?: boolean } & Omit<
|
|
110
|
+
SelectionMultipleState,
|
|
111
|
+
'mode'
|
|
112
|
+
> &
|
|
130
113
|
Omit<FiledSelectCommonProps, 'showCopyButton'>;
|
|
131
114
|
|
|
132
115
|
export type FieldSelectProps =
|
|
@@ -7,6 +7,8 @@ export function extractListProps({
|
|
|
7
7
|
noDataState,
|
|
8
8
|
noResultsState,
|
|
9
9
|
errorDataState,
|
|
10
|
+
pinTop,
|
|
11
|
+
pinBottom,
|
|
10
12
|
dataFiltered,
|
|
11
13
|
loading,
|
|
12
14
|
}: Partial<FieldSelectProps>): Partial<DroplistProps> {
|
|
@@ -15,6 +17,8 @@ export function extractListProps({
|
|
|
15
17
|
noDataState,
|
|
16
18
|
noResultsState,
|
|
17
19
|
errorDataState,
|
|
20
|
+
pinTop,
|
|
21
|
+
pinBottom,
|
|
18
22
|
dataFiltered,
|
|
19
23
|
loading,
|
|
20
24
|
trigger: 'clickAndFocusVisible',
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { ItemProps, SelectionSingleValueType } from '@snack-uikit/list';
|
|
1
|
+
import { flattenItems, ItemProps, SelectionSingleValueType } from '@snack-uikit/list';
|
|
2
2
|
import { TagProps } from '@snack-uikit/tag';
|
|
3
3
|
|
|
4
|
-
import { flattenItems } from '../legacy';
|
|
5
4
|
import { BaseOptionProps, ItemWithId, OptionProps } from '../types';
|
|
6
5
|
import { isAccordionOptionProps, isGroupOptionProps, isNextListOptionProps } from './typeGuards';
|
|
7
6
|
|
|
@@ -24,7 +24,7 @@ export function isNextListOptionProps(option: any): option is NestListOptionProp
|
|
|
24
24
|
|
|
25
25
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
26
|
export function isGroupOptionProps(option: any): option is GroupOptionProps {
|
|
27
|
-
return 'options' in option && option['type'] ===
|
|
27
|
+
return 'options' in option && option['type'] === undefined;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { flattenItems, ItemProps, SelectionSingleValueType } from '@snack-uikit/list';
|
|
2
2
|
|
|
3
|
-
import { flattenItems } from '../legacy';
|
|
4
3
|
import { ItemWithId, OptionProps } from '../types';
|
|
5
4
|
import { transformOptionsToItems } from './options';
|
|
6
5
|
|
|
@@ -14,7 +13,7 @@ export function updateItems({
|
|
|
14
13
|
selectedItem,
|
|
15
14
|
}: {
|
|
16
15
|
options: OptionProps[];
|
|
17
|
-
value
|
|
16
|
+
value: SelectionSingleValueType;
|
|
18
17
|
selectedItem?: ItemWithId;
|
|
19
18
|
currentItems?: ItemProps[];
|
|
20
19
|
}) {
|
|
@@ -68,23 +67,14 @@ export function updateMultipleItems({
|
|
|
68
67
|
};
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
const foundedValue: (number | string)[] = [];
|
|
72
|
-
|
|
73
70
|
let newItems: ItemProps[] = originalItems;
|
|
74
71
|
let newSelectedItems = selectedItems;
|
|
75
72
|
|
|
76
73
|
const flattenOriginalItems = flattenItems(originalItems);
|
|
77
74
|
|
|
78
|
-
|
|
79
|
-
const foundItems: ItemWithId[] = flattenOriginalItems.filter((item: any) => {
|
|
80
|
-
if (value.includes(item.id) && !foundedValue.includes(item.id)) {
|
|
81
|
-
foundedValue.push(item.id);
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
});
|
|
75
|
+
const foundItems: ItemWithId[] = flattenOriginalItems.filter(item => value.includes(item.id));
|
|
85
76
|
const nonFoundValues: SelectionSingleValueType[] = value.filter(
|
|
86
|
-
|
|
87
|
-
value => !flattenOriginalItems.find((item: any) => item.id === value),
|
|
77
|
+
value => !flattenOriginalItems.find(item => item.id === value),
|
|
88
78
|
);
|
|
89
79
|
|
|
90
80
|
if (nonFoundValues.length) {
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ItemProps } from '@snack-uikit/list';
|
|
2
|
-
type UseGroupItemSelectionProps = {
|
|
3
|
-
items: ItemProps[];
|
|
4
|
-
id?: string | number;
|
|
5
|
-
disabled?: boolean;
|
|
6
|
-
};
|
|
7
|
-
export declare function useLegacyGroupItemSelection({ id, items, disabled }: UseGroupItemSelectionProps): {
|
|
8
|
-
checked: boolean | undefined;
|
|
9
|
-
isIndeterminate: boolean;
|
|
10
|
-
handleOnSelect: () => void;
|
|
11
|
-
};
|
|
12
|
-
export {};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo } from 'react';
|
|
2
|
-
import { useSelectionContext } from '@snack-uikit/list';
|
|
3
|
-
import { extractAllChildIds, extractChildIds } from '../../utils';
|
|
4
|
-
export function useLegacyGroupItemSelection({ id = '', items, disabled }) {
|
|
5
|
-
const { value, setValue, isSelectionMultiple } = useSelectionContext();
|
|
6
|
-
const { childIds, allChildIds } = useMemo(() => ({ childIds: extractChildIds({ items }), allChildIds: extractAllChildIds({ items }) }), [items]);
|
|
7
|
-
const isIndeterminate = isSelectionMultiple
|
|
8
|
-
? allChildIds.some(childId => value === null || value === void 0 ? void 0 : value.includes(childId))
|
|
9
|
-
: allChildIds.includes(value !== null && value !== void 0 ? value : '');
|
|
10
|
-
const checked = isSelectionMultiple ? allChildIds.every(childId => value === null || value === void 0 ? void 0 : value.includes(childId)) : undefined;
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
if (isSelectionMultiple) {
|
|
13
|
-
if (checked && !(value === null || value === void 0 ? void 0 : value.includes(id))) {
|
|
14
|
-
setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).concat([id !== null && id !== void 0 ? id : '']));
|
|
15
|
-
}
|
|
16
|
-
if (!checked && (value === null || value === void 0 ? void 0 : value.includes(id))) {
|
|
17
|
-
setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).filter(itemId => itemId !== id));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}, [checked, disabled, id, isSelectionMultiple, setValue, value]);
|
|
21
|
-
const handleOnSelect = () => {
|
|
22
|
-
if (checked) {
|
|
23
|
-
setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).filter(itemId => itemId !== id && !childIds.includes(itemId)));
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (isIndeterminate) {
|
|
27
|
-
setValue === null || setValue === void 0 ? void 0 : setValue((value) => Array.from(new Set([...(value !== null && value !== void 0 ? value : []), ...childIds, id])));
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
setValue === null || setValue === void 0 ? void 0 : setValue((value) => (value !== null && value !== void 0 ? value : []).concat([...childIds, id !== null && id !== void 0 ? id : '']));
|
|
31
|
-
};
|
|
32
|
-
return { checked, isIndeterminate, handleOnSelect };
|
|
33
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useLegacyGroupItemSelection } from './Items/hooks';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useLegacyGroupItemSelection } from './Items/hooks';
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { ItemProps } from '@snack-uikit/list';
|
|
2
|
-
/**
|
|
3
|
-
* Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
|
|
4
|
-
*/
|
|
5
|
-
export declare function useFuzzySearch(items: ItemProps[], minSearchInputLength?: number): (search: string) => import("@snack-uikit/list/dist/components/Items").Item[] | import("@snack-uikit/list/dist/components/Items").FlattenItem[];
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import FuzzySearch from 'fuzzy-search';
|
|
2
|
-
import { useCallback, useMemo } from 'react';
|
|
3
|
-
import { kindFlattenItems } from '@snack-uikit/list';
|
|
4
|
-
const DEFAULT_MIN_SEARCH_INPUT_LENGTH = 2;
|
|
5
|
-
/**
|
|
6
|
-
* Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
|
|
7
|
-
*/
|
|
8
|
-
export function useFuzzySearch(items, minSearchInputLength) {
|
|
9
|
-
const flattenItems = useMemo(() => {
|
|
10
|
-
const { flattenItems } = kindFlattenItems({ items });
|
|
11
|
-
return Object.values(flattenItems);
|
|
12
|
-
}, [items]);
|
|
13
|
-
return useCallback((search) => {
|
|
14
|
-
const searcher = new FuzzySearch(flattenItems, ['content.option', 'content.caption', 'content.description', 'label'], {});
|
|
15
|
-
return search.length > (minSearchInputLength !== null && minSearchInputLength !== void 0 ? minSearchInputLength : DEFAULT_MIN_SEARCH_INPUT_LENGTH)
|
|
16
|
-
? searcher.search(search)
|
|
17
|
-
: items;
|
|
18
|
-
}, [flattenItems, items, minSearchInputLength]);
|
|
19
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
2
|
-
import { AccordionItemProps, BaseItemProps, ItemProps, NextListItemProps } from '@snack-uikit/list';
|
|
3
|
-
type WithCollapsedItemsProps = {
|
|
4
|
-
items: ItemProps[];
|
|
5
|
-
openCollapsedItems: Array<number | string>;
|
|
6
|
-
};
|
|
7
|
-
export declare function withCollapsedItems({ items, openCollapsedItems }: WithCollapsedItemsProps): {
|
|
8
|
-
items: import("@snack-uikit/list/dist/components/Items").Item[];
|
|
9
|
-
itemRefs: RefObject<HTMLElement>[];
|
|
10
|
-
ids: (string | number)[];
|
|
11
|
-
expandedIds: (string | number)[];
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Функция возвращает массив id дочерних items
|
|
15
|
-
* @function extractItemIds
|
|
16
|
-
*/
|
|
17
|
-
export declare function extractItemIds(items: ItemProps[]): Array<string | number>;
|
|
18
|
-
export declare function extractChildIds({ items }: {
|
|
19
|
-
items: ItemProps[];
|
|
20
|
-
}): Array<string | number>;
|
|
21
|
-
export declare function extractAllChildIds({ items }: {
|
|
22
|
-
items: ItemProps[];
|
|
23
|
-
}): Array<string | number>;
|
|
24
|
-
/**
|
|
25
|
-
* Функция разворачивает массив айтемов в плоский список
|
|
26
|
-
* @function flattenItems
|
|
27
|
-
*/
|
|
28
|
-
export declare function flattenItems(items: ItemProps[]): (BaseItemProps | AccordionItemProps | NextListItemProps)[];
|
|
29
|
-
export {};
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { isAccordionItemProps, isBaseItemProps, isGroupItemProps, isNextListItemProps, } from '@snack-uikit/list';
|
|
2
|
-
export function withCollapsedItems({ items, openCollapsedItems }) {
|
|
3
|
-
let itemRefs = [];
|
|
4
|
-
let newItems = [];
|
|
5
|
-
let ids = [];
|
|
6
|
-
let expandedIds = [];
|
|
7
|
-
items.forEach(item => {
|
|
8
|
-
var _a;
|
|
9
|
-
if (((isBaseItemProps(item) && !item.inactive) || isNextListItemProps(item) || isAccordionItemProps(item)) &&
|
|
10
|
-
!item.disabled) {
|
|
11
|
-
newItems = newItems.concat([item]);
|
|
12
|
-
ids = ids.concat([(_a = item.id) !== null && _a !== void 0 ? _a : '']);
|
|
13
|
-
if (item.itemRef) {
|
|
14
|
-
itemRefs = itemRefs.concat([item.itemRef]);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
if (isNextListItemProps(item) && item.id && !item.disabled) {
|
|
18
|
-
expandedIds = expandedIds.concat(item.id);
|
|
19
|
-
}
|
|
20
|
-
if (isGroupItemProps(item)) {
|
|
21
|
-
const { itemRefs: nestedItemsRefs, ids: nestedIds } = withCollapsedItems({
|
|
22
|
-
items: item.items,
|
|
23
|
-
openCollapsedItems,
|
|
24
|
-
});
|
|
25
|
-
ids = ids.concat(nestedIds);
|
|
26
|
-
itemRefs = itemRefs.concat(nestedItemsRefs);
|
|
27
|
-
}
|
|
28
|
-
if (isAccordionItemProps(item) && item.id && openCollapsedItems.includes(item.id)) {
|
|
29
|
-
const { itemRefs: nestedItemsRefs, ids: nestedIds, items: nestedItems, expandedIds: nestedExpandedIds, } = withCollapsedItems({
|
|
30
|
-
items: item.items,
|
|
31
|
-
openCollapsedItems,
|
|
32
|
-
});
|
|
33
|
-
ids = ids.concat(nestedIds);
|
|
34
|
-
newItems = newItems.concat(nestedItems);
|
|
35
|
-
itemRefs = itemRefs.concat(nestedItemsRefs);
|
|
36
|
-
expandedIds = expandedIds.concat(nestedExpandedIds);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
return { items, itemRefs, ids, expandedIds };
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Функция возвращает массив id дочерних items
|
|
43
|
-
* @function extractItemIds
|
|
44
|
-
*/
|
|
45
|
-
export function extractItemIds(items) {
|
|
46
|
-
return items.reduce((prev, item) => {
|
|
47
|
-
if (isGroupItemProps(item)) {
|
|
48
|
-
return prev.concat(extractItemIds(item.items));
|
|
49
|
-
}
|
|
50
|
-
return item.id ? prev.concat([item.id]) : prev;
|
|
51
|
-
}, []);
|
|
52
|
-
}
|
|
53
|
-
export function extractChildIds({ items }) {
|
|
54
|
-
return items
|
|
55
|
-
.filter(item => isAccordionItemProps(item) ||
|
|
56
|
-
isNextListItemProps(item) ||
|
|
57
|
-
isGroupItemProps(item) ||
|
|
58
|
-
(isBaseItemProps(item) && !item.disabled && !item.inactive))
|
|
59
|
-
.reduce((prev, item) => {
|
|
60
|
-
var _a;
|
|
61
|
-
if (isAccordionItemProps(item) || isNextListItemProps(item)) {
|
|
62
|
-
return prev.concat([(_a = item.id) !== null && _a !== void 0 ? _a : '']).concat(extractChildIds({ items: item.items }));
|
|
63
|
-
}
|
|
64
|
-
if (isGroupItemProps(item)) {
|
|
65
|
-
return prev.concat(extractChildIds({ items: item.items }));
|
|
66
|
-
}
|
|
67
|
-
return item.id && !isGroupItemProps(item) ? prev.concat([item.id]) : prev;
|
|
68
|
-
}, []);
|
|
69
|
-
}
|
|
70
|
-
export function extractAllChildIds({ items }) {
|
|
71
|
-
return items
|
|
72
|
-
.filter(item => isAccordionItemProps(item) ||
|
|
73
|
-
isNextListItemProps(item) ||
|
|
74
|
-
isGroupItemProps(item) ||
|
|
75
|
-
(isBaseItemProps(item) && !item.inactive))
|
|
76
|
-
.reduce((prev, item) => {
|
|
77
|
-
var _a;
|
|
78
|
-
if (isAccordionItemProps(item) || isNextListItemProps(item)) {
|
|
79
|
-
return prev.concat([(_a = item.id) !== null && _a !== void 0 ? _a : '']).concat(extractAllChildIds({ items: item.items }));
|
|
80
|
-
}
|
|
81
|
-
if (isGroupItemProps(item)) {
|
|
82
|
-
return prev.concat(extractAllChildIds({ items: item.items }));
|
|
83
|
-
}
|
|
84
|
-
return item.id && !isGroupItemProps(item) ? prev.concat([item.id]) : prev;
|
|
85
|
-
}, []);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Функция разворачивает массив айтемов в плоский список
|
|
89
|
-
* @function flattenItems
|
|
90
|
-
*/
|
|
91
|
-
export function flattenItems(items) {
|
|
92
|
-
const flattenItems = [];
|
|
93
|
-
function flatten(item) {
|
|
94
|
-
if (!isGroupItemProps(item)) {
|
|
95
|
-
flattenItems.push(item);
|
|
96
|
-
}
|
|
97
|
-
if ('items' in item) {
|
|
98
|
-
for (const nestedItem of item.items) {
|
|
99
|
-
flatten(nestedItem);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
for (const item of items) {
|
|
104
|
-
flatten(item);
|
|
105
|
-
}
|
|
106
|
-
return flattenItems;
|
|
107
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo } from 'react';
|
|
2
|
-
|
|
3
|
-
import { ItemProps, useSelectionContext } from '@snack-uikit/list';
|
|
4
|
-
|
|
5
|
-
import { extractAllChildIds, extractChildIds } from '../../utils';
|
|
6
|
-
|
|
7
|
-
type UseGroupItemSelectionProps = {
|
|
8
|
-
items: ItemProps[];
|
|
9
|
-
id?: string | number;
|
|
10
|
-
disabled?: boolean;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export function useLegacyGroupItemSelection({ id = '', items, disabled }: UseGroupItemSelectionProps) {
|
|
14
|
-
const { value, setValue, isSelectionMultiple } = useSelectionContext();
|
|
15
|
-
const { childIds, allChildIds } = useMemo(
|
|
16
|
-
() => ({ childIds: extractChildIds({ items }), allChildIds: extractAllChildIds({ items }) }),
|
|
17
|
-
[items],
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
const isIndeterminate = isSelectionMultiple
|
|
21
|
-
? allChildIds.some(childId => value?.includes(childId))
|
|
22
|
-
: allChildIds.includes(value ?? '');
|
|
23
|
-
const checked = isSelectionMultiple ? allChildIds.every(childId => value?.includes(childId)) : undefined;
|
|
24
|
-
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
if (isSelectionMultiple) {
|
|
27
|
-
if (checked && !value?.includes(id)) {
|
|
28
|
-
setValue?.((value: Array<number | string>) => (value ?? []).concat([id ?? '']));
|
|
29
|
-
}
|
|
30
|
-
if (!checked && value?.includes(id)) {
|
|
31
|
-
setValue?.((value: Array<number | string>) => (value ?? []).filter(itemId => itemId !== id));
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}, [checked, disabled, id, isSelectionMultiple, setValue, value]);
|
|
35
|
-
|
|
36
|
-
const handleOnSelect = () => {
|
|
37
|
-
if (checked) {
|
|
38
|
-
setValue?.((value: Array<string | number>) =>
|
|
39
|
-
(value ?? []).filter(itemId => itemId !== id && !childIds.includes(itemId)),
|
|
40
|
-
);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (isIndeterminate) {
|
|
45
|
-
setValue?.((value: Array<string | number>) => Array.from(new Set([...(value ?? []), ...childIds, id])));
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
setValue?.((value: Array<string | number>) => (value ?? []).concat([...childIds, id ?? '']));
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
return { checked, isIndeterminate, handleOnSelect };
|
|
53
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useLegacyGroupItemSelection } from './Items/hooks';
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import FuzzySearch from 'fuzzy-search';
|
|
2
|
-
import { useCallback, useMemo } from 'react';
|
|
3
|
-
|
|
4
|
-
import { ItemProps, kindFlattenItems } from '@snack-uikit/list';
|
|
5
|
-
|
|
6
|
-
const DEFAULT_MIN_SEARCH_INPUT_LENGTH = 2;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
|
|
10
|
-
*/
|
|
11
|
-
export function useFuzzySearch(items: ItemProps[], minSearchInputLength?: number) {
|
|
12
|
-
const flattenItems = useMemo(() => {
|
|
13
|
-
const { flattenItems } = kindFlattenItems({ items });
|
|
14
|
-
|
|
15
|
-
return Object.values(flattenItems);
|
|
16
|
-
}, [items]);
|
|
17
|
-
|
|
18
|
-
return useCallback(
|
|
19
|
-
(search: string) => {
|
|
20
|
-
const searcher = new FuzzySearch(
|
|
21
|
-
flattenItems,
|
|
22
|
-
['content.option', 'content.caption', 'content.description', 'label'],
|
|
23
|
-
{},
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
return search.length > (minSearchInputLength ?? DEFAULT_MIN_SEARCH_INPUT_LENGTH)
|
|
27
|
-
? searcher.search(search)
|
|
28
|
-
: items;
|
|
29
|
-
},
|
|
30
|
-
[flattenItems, items, minSearchInputLength],
|
|
31
|
-
);
|
|
32
|
-
}
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import { RefObject } from 'react';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
AccordionItemProps,
|
|
5
|
-
BaseItemProps,
|
|
6
|
-
isAccordionItemProps,
|
|
7
|
-
isBaseItemProps,
|
|
8
|
-
isGroupItemProps,
|
|
9
|
-
isNextListItemProps,
|
|
10
|
-
ItemProps,
|
|
11
|
-
NextListItemProps,
|
|
12
|
-
} from '@snack-uikit/list';
|
|
13
|
-
|
|
14
|
-
type WithCollapsedItemsProps = {
|
|
15
|
-
items: ItemProps[];
|
|
16
|
-
openCollapsedItems: Array<number | string>;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export function withCollapsedItems({ items, openCollapsedItems }: WithCollapsedItemsProps) {
|
|
20
|
-
let itemRefs: RefObject<HTMLElement>[] = [];
|
|
21
|
-
let newItems: ItemProps[] = [];
|
|
22
|
-
let ids: Array<string | number> = [];
|
|
23
|
-
let expandedIds: Array<string | number> = [];
|
|
24
|
-
|
|
25
|
-
items.forEach(item => {
|
|
26
|
-
if (
|
|
27
|
-
((isBaseItemProps(item) && !item.inactive) || isNextListItemProps(item) || isAccordionItemProps(item)) &&
|
|
28
|
-
!item.disabled
|
|
29
|
-
) {
|
|
30
|
-
newItems = newItems.concat([item]);
|
|
31
|
-
ids = ids.concat([item.id ?? '']);
|
|
32
|
-
|
|
33
|
-
if (item.itemRef) {
|
|
34
|
-
itemRefs = itemRefs.concat([item.itemRef]);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (isNextListItemProps(item) && item.id && !item.disabled) {
|
|
39
|
-
expandedIds = expandedIds.concat(item.id);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (isGroupItemProps(item)) {
|
|
43
|
-
const { itemRefs: nestedItemsRefs, ids: nestedIds } = withCollapsedItems({
|
|
44
|
-
items: item.items,
|
|
45
|
-
openCollapsedItems,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
ids = ids.concat(nestedIds);
|
|
49
|
-
|
|
50
|
-
itemRefs = itemRefs.concat(nestedItemsRefs);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (isAccordionItemProps(item) && item.id && openCollapsedItems.includes(item.id)) {
|
|
54
|
-
const {
|
|
55
|
-
itemRefs: nestedItemsRefs,
|
|
56
|
-
ids: nestedIds,
|
|
57
|
-
items: nestedItems,
|
|
58
|
-
expandedIds: nestedExpandedIds,
|
|
59
|
-
} = withCollapsedItems({
|
|
60
|
-
items: item.items,
|
|
61
|
-
openCollapsedItems,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
ids = ids.concat(nestedIds);
|
|
65
|
-
newItems = newItems.concat(nestedItems);
|
|
66
|
-
itemRefs = itemRefs.concat(nestedItemsRefs);
|
|
67
|
-
expandedIds = expandedIds.concat(nestedExpandedIds);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
return { items, itemRefs, ids, expandedIds };
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Функция возвращает массив id дочерних items
|
|
76
|
-
* @function extractItemIds
|
|
77
|
-
*/
|
|
78
|
-
|
|
79
|
-
export function extractItemIds(items: ItemProps[]): Array<string | number> {
|
|
80
|
-
return items.reduce(
|
|
81
|
-
(prev: Array<string | number>, item: ItemProps) => {
|
|
82
|
-
if (isGroupItemProps(item)) {
|
|
83
|
-
return prev.concat(extractItemIds(item.items));
|
|
84
|
-
}
|
|
85
|
-
return item.id ? prev.concat([item.id]) : prev;
|
|
86
|
-
},
|
|
87
|
-
[] as Array<string | number>,
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export function extractChildIds({ items }: { items: ItemProps[] }): Array<string | number> {
|
|
92
|
-
return items
|
|
93
|
-
.filter(
|
|
94
|
-
item =>
|
|
95
|
-
isAccordionItemProps(item) ||
|
|
96
|
-
isNextListItemProps(item) ||
|
|
97
|
-
isGroupItemProps(item) ||
|
|
98
|
-
(isBaseItemProps(item) && !item.disabled && !item.inactive),
|
|
99
|
-
)
|
|
100
|
-
.reduce(
|
|
101
|
-
(prev: Array<string | number>, item: ItemProps) => {
|
|
102
|
-
if (isAccordionItemProps(item) || isNextListItemProps(item)) {
|
|
103
|
-
return prev.concat([item.id ?? '']).concat(extractChildIds({ items: item.items }));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (isGroupItemProps(item)) {
|
|
107
|
-
return prev.concat(extractChildIds({ items: item.items }));
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return item.id && !isGroupItemProps(item) ? prev.concat([item.id]) : prev;
|
|
111
|
-
},
|
|
112
|
-
[] as Array<string | number>,
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export function extractAllChildIds({ items }: { items: ItemProps[] }): Array<string | number> {
|
|
117
|
-
return items
|
|
118
|
-
.filter(
|
|
119
|
-
item =>
|
|
120
|
-
isAccordionItemProps(item) ||
|
|
121
|
-
isNextListItemProps(item) ||
|
|
122
|
-
isGroupItemProps(item) ||
|
|
123
|
-
(isBaseItemProps(item) && !item.inactive),
|
|
124
|
-
)
|
|
125
|
-
.reduce(
|
|
126
|
-
(prev: Array<string | number>, item: ItemProps) => {
|
|
127
|
-
if (isAccordionItemProps(item) || isNextListItemProps(item)) {
|
|
128
|
-
return prev.concat([item.id ?? '']).concat(extractAllChildIds({ items: item.items }));
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (isGroupItemProps(item)) {
|
|
132
|
-
return prev.concat(extractAllChildIds({ items: item.items }));
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return item.id && !isGroupItemProps(item) ? prev.concat([item.id]) : prev;
|
|
136
|
-
},
|
|
137
|
-
[] as Array<string | number>,
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Функция разворачивает массив айтемов в плоский список
|
|
143
|
-
* @function flattenItems
|
|
144
|
-
*/
|
|
145
|
-
|
|
146
|
-
export function flattenItems(items: ItemProps[]): (BaseItemProps | AccordionItemProps | NextListItemProps)[] {
|
|
147
|
-
const flattenItems: (BaseItemProps | AccordionItemProps | NextListItemProps)[] = [];
|
|
148
|
-
|
|
149
|
-
function flatten(item: ItemProps) {
|
|
150
|
-
if (!isGroupItemProps(item)) {
|
|
151
|
-
flattenItems.push(item);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if ('items' in item) {
|
|
155
|
-
for (const nestedItem of item.items) {
|
|
156
|
-
flatten(nestedItem);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
for (const item of items) {
|
|
162
|
-
flatten(item);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return flattenItems;
|
|
166
|
-
}
|